user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u548303713
p02756
python
s873087805
s781409681
763
419
56,436
8,564
Accepted
Accepted
45.09
from collections import deque ss=deque() s=list(eval(input())) l=len(s) for i in range(l): ss.append(s[i]) q=int(eval(input())) info=[] rev=[] #i回までに何回反転があるか num=0 for i in range(q): info.append(list(input().split())) moji=0 #文字の追加数 for i in range(q): if info[i][0]=="1": num+=1 else: if info[i][1]=="2": rev.append([info[i][2],2,num]) #末尾 else: rev.append([info[i][2],1,num]) moji+=1 if num%2==1: ss.reverse() #print(rev) #print(num) for i in range(moji): now=rev[i][1] if (num-rev[i][2])%2==1: #これが奇数だと2なら先頭になる #print("change") if rev[i][1]==2: rev[i][1]=1 else: rev[i][1]=2 if rev[i][1]==2: ss.append(rev[i][0]) else: ss.appendleft(rev[i][0]) print(("".join(ss))) #print(rev)
from collections import deque s=eval(input()) q=int(eval(input())) count=0 #何回反転があるか ss=deque(s) flag=True #通常状態 for i in range(q): info=eval(input()) if info[0]=="1": count+=1 if flag: flag=False else: flag=True else: _,f,c=info.split() if flag: if f=="1": ss.appendleft(c) else: ss.append(c) else: #反転状態 if f=="1": ss.append(c) else: ss.appendleft(c) ans="".join(ss) print((ans if count%2==0 else ans[::-1]))
40
29
859
615
from collections import deque ss = deque() s = list(eval(input())) l = len(s) for i in range(l): ss.append(s[i]) q = int(eval(input())) info = [] rev = [] # i回までに何回反転があるか num = 0 for i in range(q): info.append(list(input().split())) moji = 0 # 文字の追加数 for i in range(q): if info[i][0] == "1": num += 1 else: if info[i][1] == "2": rev.append([info[i][2], 2, num]) # 末尾 else: rev.append([info[i][2], 1, num]) moji += 1 if num % 2 == 1: ss.reverse() # print(rev) # print(num) for i in range(moji): now = rev[i][1] if (num - rev[i][2]) % 2 == 1: # これが奇数だと2なら先頭になる # print("change") if rev[i][1] == 2: rev[i][1] = 1 else: rev[i][1] = 2 if rev[i][1] == 2: ss.append(rev[i][0]) else: ss.appendleft(rev[i][0]) print(("".join(ss))) # print(rev)
from collections import deque s = eval(input()) q = int(eval(input())) count = 0 # 何回反転があるか ss = deque(s) flag = True # 通常状態 for i in range(q): info = eval(input()) if info[0] == "1": count += 1 if flag: flag = False else: flag = True else: _, f, c = info.split() if flag: if f == "1": ss.appendleft(c) else: ss.append(c) else: # 反転状態 if f == "1": ss.append(c) else: ss.appendleft(c) ans = "".join(ss) print((ans if count % 2 == 0 else ans[::-1]))
false
27.5
[ "-ss = deque()", "-s = list(eval(input()))", "-l = len(s)", "-for i in range(l):", "- ss.append(s[i])", "+s = eval(input())", "-info = []", "-rev = [] # i回までに何回反転があるか", "-num = 0", "+count = 0 # 何回反転があるか", "+ss = deque(s)", "+flag = True # 通常状態", "- info.append(list(input().split()))", "-moji = 0 # 文字の追加数", "-for i in range(q):", "- if info[i][0] == \"1\":", "- num += 1", "+ info = eval(input())", "+ if info[0] == \"1\":", "+ count += 1", "+ if flag:", "+ flag = False", "+ else:", "+ flag = True", "- if info[i][1] == \"2\":", "- rev.append([info[i][2], 2, num]) # 末尾", "- else:", "- rev.append([info[i][2], 1, num])", "- moji += 1", "-if num % 2 == 1:", "- ss.reverse()", "-# print(rev)", "-# print(num)", "-for i in range(moji):", "- now = rev[i][1]", "- if (num - rev[i][2]) % 2 == 1: # これが奇数だと2なら先頭になる", "- # print(\"change\")", "- if rev[i][1] == 2:", "- rev[i][1] = 1", "- else:", "- rev[i][1] = 2", "- if rev[i][1] == 2:", "- ss.append(rev[i][0])", "- else:", "- ss.appendleft(rev[i][0])", "-print((\"\".join(ss)))", "-# print(rev)", "+ _, f, c = info.split()", "+ if flag:", "+ if f == \"1\":", "+ ss.appendleft(c)", "+ else:", "+ ss.append(c)", "+ else: # 反転状態", "+ if f == \"1\":", "+ ss.append(c)", "+ else:", "+ ss.appendleft(c)", "+ans = \"\".join(ss)", "+print((ans if count % 2 == 0 else ans[::-1]))" ]
false
0.038914
0.060718
0.640889
[ "s873087805", "s781409681" ]
u763209508
p03448
python
s368010908
s593240226
57
52
8,404
3,060
Accepted
Accepted
8.77
import itertools A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) available_prices = [500 * a + 100 * b + 50 * c for a, b, c in itertools.product(list(range(A+1)), list(range(B+1)), list(range(C+1)))] cnt = 0 for p in available_prices: if p == X: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*i + 100*j + 50*k == X: count += 1 print(count)
15
15
298
252
import itertools A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) available_prices = [ 500 * a + 100 * b + 50 * c for a, b, c in itertools.product( list(range(A + 1)), list(range(B + 1)), list(range(C + 1)) ) ] cnt = 0 for p in available_prices: if p == X: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) count = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if 500 * i + 100 * j + 50 * k == X: count += 1 print(count)
false
0
[ "-import itertools", "-", "-available_prices = [", "- 500 * a + 100 * b + 50 * c", "- for a, b, c in itertools.product(", "- list(range(A + 1)), list(range(B + 1)), list(range(C + 1))", "- )", "-]", "-cnt = 0", "-for p in available_prices:", "- if p == X:", "- cnt += 1", "-print(cnt)", "+count = 0", "+for i in range(A + 1):", "+ for j in range(B + 1):", "+ for k in range(C + 1):", "+ if 500 * i + 100 * j + 50 * k == X:", "+ count += 1", "+print(count)" ]
false
0.205977
0.062686
3.285846
[ "s368010908", "s593240226" ]
u442396147
p03163
python
s619628357
s232461219
811
701
171,656
171,656
Accepted
Accepted
13.56
N, W = list(map(int, input().split())) Ws = [] Vs = [] for _ in range(N): w, v = list(map(int, input().split())) Ws.append(w) Vs.append(v) S = [ [0 for _ in range(W+1)] for _ in range(N)] if Ws[0] <= W: for i in range(Ws[0], W+1): S[0][i] = Vs[0] for weight in range(W+1): for item_num in range(N-1): if weight - Ws[item_num+1] < 0: S[item_num+1][weight] = max(S[item_num+1][weight], S[item_num][weight]) else: S[item_num+1][weight] = max(S[item_num+1][weight], S[item_num][weight-Ws[item_num+1]] + Vs[item_num+1], S[item_num][weight]) print((max(S[N-1])))
N, W = list(map(int, input().split())) Ws = [] Vs = [] for _ in range(N): w, v = list(map(int, input().split())) Ws.append(w) Vs.append(v) Ans = [[0 for _ in range(W+1)] for _ in range(N)] for i in range(W+1): if i >= Ws[0]: Ans[0][i] = Vs[0] for i in range(1, N): for w in range(W+1): if w - Ws[i] >= 0: Ans[i][w] = max(Ans[i-1][w-Ws[i]] + Vs[i], Ans[i-1][w], Ans[i][w]) else: Ans[i][w] = max(Ans[i-1][w], Ans[i][w]) print((max(Ans[N-1])))
25
23
608
488
N, W = list(map(int, input().split())) Ws = [] Vs = [] for _ in range(N): w, v = list(map(int, input().split())) Ws.append(w) Vs.append(v) S = [[0 for _ in range(W + 1)] for _ in range(N)] if Ws[0] <= W: for i in range(Ws[0], W + 1): S[0][i] = Vs[0] for weight in range(W + 1): for item_num in range(N - 1): if weight - Ws[item_num + 1] < 0: S[item_num + 1][weight] = max(S[item_num + 1][weight], S[item_num][weight]) else: S[item_num + 1][weight] = max( S[item_num + 1][weight], S[item_num][weight - Ws[item_num + 1]] + Vs[item_num + 1], S[item_num][weight], ) print((max(S[N - 1])))
N, W = list(map(int, input().split())) Ws = [] Vs = [] for _ in range(N): w, v = list(map(int, input().split())) Ws.append(w) Vs.append(v) Ans = [[0 for _ in range(W + 1)] for _ in range(N)] for i in range(W + 1): if i >= Ws[0]: Ans[0][i] = Vs[0] for i in range(1, N): for w in range(W + 1): if w - Ws[i] >= 0: Ans[i][w] = max(Ans[i - 1][w - Ws[i]] + Vs[i], Ans[i - 1][w], Ans[i][w]) else: Ans[i][w] = max(Ans[i - 1][w], Ans[i][w]) print((max(Ans[N - 1])))
false
8
[ "-S = [[0 for _ in range(W + 1)] for _ in range(N)]", "-if Ws[0] <= W:", "- for i in range(Ws[0], W + 1):", "- S[0][i] = Vs[0]", "-for weight in range(W + 1):", "- for item_num in range(N - 1):", "- if weight - Ws[item_num + 1] < 0:", "- S[item_num + 1][weight] = max(S[item_num + 1][weight], S[item_num][weight])", "+Ans = [[0 for _ in range(W + 1)] for _ in range(N)]", "+for i in range(W + 1):", "+ if i >= Ws[0]:", "+ Ans[0][i] = Vs[0]", "+for i in range(1, N):", "+ for w in range(W + 1):", "+ if w - Ws[i] >= 0:", "+ Ans[i][w] = max(Ans[i - 1][w - Ws[i]] + Vs[i], Ans[i - 1][w], Ans[i][w])", "- S[item_num + 1][weight] = max(", "- S[item_num + 1][weight],", "- S[item_num][weight - Ws[item_num + 1]] + Vs[item_num + 1],", "- S[item_num][weight],", "- )", "-print((max(S[N - 1])))", "+ Ans[i][w] = max(Ans[i - 1][w], Ans[i][w])", "+print((max(Ans[N - 1])))" ]
false
0.041487
0.040433
1.026076
[ "s619628357", "s232461219" ]
u744034042
p03607
python
s563617404
s448895260
244
194
20,200
16,636
Accepted
Accepted
20.49
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] import collections b = collections.Counter(a) set_a = list(set(a)) cnt = 0 for i in range(len(set_a)): if b[set_a[i]]%2 == 1: cnt += 1 print(cnt)
from collections import Counter n = int(eval(input())) a = Counter([int(eval(input())) for i in range(n)]) print((sum([v%2 == 1 for v in list(a.values())])))
10
4
220
140
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] import collections b = collections.Counter(a) set_a = list(set(a)) cnt = 0 for i in range(len(set_a)): if b[set_a[i]] % 2 == 1: cnt += 1 print(cnt)
from collections import Counter n = int(eval(input())) a = Counter([int(eval(input())) for i in range(n)]) print((sum([v % 2 == 1 for v in list(a.values())])))
false
60
[ "+from collections import Counter", "+", "-a = [int(eval(input())) for i in range(n)]", "-import collections", "-", "-b = collections.Counter(a)", "-set_a = list(set(a))", "-cnt = 0", "-for i in range(len(set_a)):", "- if b[set_a[i]] % 2 == 1:", "- cnt += 1", "-print(cnt)", "+a = Counter([int(eval(input())) for i in range(n)])", "+print((sum([v % 2 == 1 for v in list(a.values())])))" ]
false
0.097409
0.093643
1.040226
[ "s563617404", "s448895260" ]
u691018832
p02687
python
s741389198
s431592711
62
26
61,856
9,160
Accepted
Accepted
58.06
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) s = readline().rstrip().decode() ans = {'ABC': 'ARC', 'ARC': 'ABC'} print((ans[s]))
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) s = readline().rstrip().decode() check = {'ABC': 'ARC', 'ARC': 'ABC'} print((check[s])) if __name__ == '__main__': main()
9
14
238
331
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) s = readline().rstrip().decode() ans = {"ABC": "ARC", "ARC": "ABC"} print((ans[s]))
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) s = readline().rstrip().decode() check = {"ABC": "ARC", "ARC": "ABC"} print((check[s])) if __name__ == "__main__": main()
false
35.714286
[ "-import sys", "+def main():", "+ import sys", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "-sys.setrecursionlimit(10**7)", "-s = readline().rstrip().decode()", "-ans = {\"ABC\": \"ARC\", \"ARC\": \"ABC\"}", "-print((ans[s]))", "+ read = sys.stdin.buffer.read", "+ readline = sys.stdin.buffer.readline", "+ readlines = sys.stdin.buffer.readlines", "+ sys.setrecursionlimit(10**7)", "+ s = readline().rstrip().decode()", "+ check = {\"ABC\": \"ARC\", \"ARC\": \"ABC\"}", "+ print((check[s]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.226153
0.046427
4.871124
[ "s741389198", "s431592711" ]
u690536347
p02936
python
s984452018
s422334969
1,873
1,237
118,744
66,692
Accepted
Accepted
33.96
from collections import defaultdict N, Q = list(map(int ,input().split())) d = defaultdict(list) for _ in range(N-1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) dp = [0]*N used = [False]*N for _ in range(Q): p, x = list(map(int, input().split())) dp[p-1] += x q = [1] used[0] = True while q: x = q.pop() for i in d[x]: if used[i-1]==True: continue dp[i-1] += dp[x-1] used[i-1] = True q.append(i) print((*dp))
from collections import defaultdict N, Q = list(map(int, input().split())) d = defaultdict(list) for _ in range(N-1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) ans = [0]*(N+1) for _ in range(Q): p, x = list(map(int, input().split())) ans[p] += x q = [1] used = [False]*(N+1) used[1] = True while q: s = q.pop() for t in d[s]: if used[t]:continue used[t] = True ans[t]+=ans[s] q.append(t) print((*ans[1:]))
30
25
527
499
from collections import defaultdict N, Q = list(map(int, input().split())) d = defaultdict(list) for _ in range(N - 1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) dp = [0] * N used = [False] * N for _ in range(Q): p, x = list(map(int, input().split())) dp[p - 1] += x q = [1] used[0] = True while q: x = q.pop() for i in d[x]: if used[i - 1] == True: continue dp[i - 1] += dp[x - 1] used[i - 1] = True q.append(i) print((*dp))
from collections import defaultdict N, Q = list(map(int, input().split())) d = defaultdict(list) for _ in range(N - 1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) ans = [0] * (N + 1) for _ in range(Q): p, x = list(map(int, input().split())) ans[p] += x q = [1] used = [False] * (N + 1) used[1] = True while q: s = q.pop() for t in d[s]: if used[t]: continue used[t] = True ans[t] += ans[s] q.append(t) print((*ans[1:]))
false
16.666667
[ "-dp = [0] * N", "-used = [False] * N", "+ans = [0] * (N + 1)", "- dp[p - 1] += x", "+ ans[p] += x", "-used[0] = True", "+used = [False] * (N + 1)", "+used[1] = True", "- x = q.pop()", "- for i in d[x]:", "- if used[i - 1] == True:", "+ s = q.pop()", "+ for t in d[s]:", "+ if used[t]:", "- dp[i - 1] += dp[x - 1]", "- used[i - 1] = True", "- q.append(i)", "-print((*dp))", "+ used[t] = True", "+ ans[t] += ans[s]", "+ q.append(t)", "+print((*ans[1:]))" ]
false
0.044491
0.11364
0.39151
[ "s984452018", "s422334969" ]
u677121387
p02685
python
s603835671
s682232844
1,424
1,117
24,512
32,408
Accepted
Accepted
21.56
n,m,k = list(map(int,input().split())) mod = 998244353 def comb(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n]*finv[k]%mod*finv[n-k]%mod fac = [0]*(n+1) finv = [0]*(n+1) fac[0] = finv[0] = 1 for i in range(1,n+1): fac[i] = fac[i-1]*i%mod finv[i] = pow(fac[i],mod-2,mod) ans = 0 for i in range(k+1): ans = (ans + m*comb(n-1,i)%mod*pow(m-1,n-1-i,mod)%mod)%mod print(ans)
n,m,k = list(map(int,input().split())) mod = 998244353 def comb(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n]*finv[k]%mod*finv[n-k]%mod fac = [1]*(n+1) finv = [1]*(n+1) for i in range(1,n+1): fac[i] = fac[i-1]*i%mod finv[i] = pow(fac[i],mod-2,mod) p = [1]*(n+1) for i in range(1,n+1): p[i] = p[i-1]*(m-1)%mod ans = 0 for i in range(k+1): ans += m*comb(n-1,i)%mod*p[n-1-i]%mod ans %= mod print(ans)
17
19
423
460
n, m, k = list(map(int, input().split())) mod = 998244353 def comb(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * finv[k] % mod * finv[n - k] % mod fac = [0] * (n + 1) finv = [0] * (n + 1) fac[0] = finv[0] = 1 for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod finv[i] = pow(fac[i], mod - 2, mod) ans = 0 for i in range(k + 1): ans = (ans + m * comb(n - 1, i) % mod * pow(m - 1, n - 1 - i, mod) % mod) % mod print(ans)
n, m, k = list(map(int, input().split())) mod = 998244353 def comb(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * finv[k] % mod * finv[n - k] % mod fac = [1] * (n + 1) finv = [1] * (n + 1) for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod finv[i] = pow(fac[i], mod - 2, mod) p = [1] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] * (m - 1) % mod ans = 0 for i in range(k + 1): ans += m * comb(n - 1, i) % mod * p[n - 1 - i] % mod ans %= mod print(ans)
false
10.526316
[ "-fac = [0] * (n + 1)", "-finv = [0] * (n + 1)", "-fac[0] = finv[0] = 1", "+fac = [1] * (n + 1)", "+finv = [1] * (n + 1)", "+p = [1] * (n + 1)", "+for i in range(1, n + 1):", "+ p[i] = p[i - 1] * (m - 1) % mod", "- ans = (ans + m * comb(n - 1, i) % mod * pow(m - 1, n - 1 - i, mod) % mod) % mod", "+ ans += m * comb(n - 1, i) % mod * p[n - 1 - i] % mod", "+ ans %= mod" ]
false
0.155828
0.16156
0.964522
[ "s603835671", "s682232844" ]
u816631826
p02996
python
s166582058
s705638551
845
512
29,456
33,480
Accepted
Accepted
39.41
n=int(eval(input())) l=[];t=0;flg=0 for i in range(1,n+1,1): a,b=list(map(int,input().split())) c=(b,a) l.append(c) l.sort() for x,y in l: t+=y if t>x: flg=1 if flg==0:print("Yes") else:print("No")
import sys from math import ceil from operator import itemgetter as get def input(): return sys.stdin.readline().strip() def iinput(): return int(eval(input())) def finput(): return float(eval(input())) def tinput(): return input().split() def rinput(): return list(map(int, tinput())) def rlinput(): return list(rinput()) def nok(a, b): m = a * b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a + b) def main(): n = iinput() q, res = [], 0 for i in range(n): q.append(tuple(rinput())) q = sorted(q, key = get(1)) for i, v in q: res += i if res > v: print("No") return 0 print("Yes") main()
14
45
228
800
n = int(eval(input())) l = [] t = 0 flg = 0 for i in range(1, n + 1, 1): a, b = list(map(int, input().split())) c = (b, a) l.append(c) l.sort() for x, y in l: t += y if t > x: flg = 1 if flg == 0: print("Yes") else: print("No")
import sys from math import ceil from operator import itemgetter as get def input(): return sys.stdin.readline().strip() def iinput(): return int(eval(input())) def finput(): return float(eval(input())) def tinput(): return input().split() def rinput(): return list(map(int, tinput())) def rlinput(): return list(rinput()) def nok(a, b): m = a * b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a + b) def main(): n = iinput() q, res = [], 0 for i in range(n): q.append(tuple(rinput())) q = sorted(q, key=get(1)) for i, v in q: res += i if res > v: print("No") return 0 print("Yes") main()
false
68.888889
[ "-n = int(eval(input()))", "-l = []", "-t = 0", "-flg = 0", "-for i in range(1, n + 1, 1):", "- a, b = list(map(int, input().split()))", "- c = (b, a)", "- l.append(c)", "-l.sort()", "-for x, y in l:", "- t += y", "- if t > x:", "- flg = 1", "-if flg == 0:", "+import sys", "+from math import ceil", "+from operator import itemgetter as get", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def iinput():", "+ return int(eval(input()))", "+", "+", "+def finput():", "+ return float(eval(input()))", "+", "+", "+def tinput():", "+ return input().split()", "+", "+", "+def rinput():", "+ return list(map(int, tinput()))", "+", "+", "+def rlinput():", "+ return list(rinput())", "+", "+", "+def nok(a, b):", "+ m = a * b", "+ while a != 0 and b != 0:", "+ if a > b:", "+ a %= b", "+ else:", "+ b %= a", "+ return m // (a + b)", "+", "+", "+def main():", "+ n = iinput()", "+ q, res = [], 0", "+ for i in range(n):", "+ q.append(tuple(rinput()))", "+ q = sorted(q, key=get(1))", "+ for i, v in q:", "+ res += i", "+ if res > v:", "+ print(\"No\")", "+ return 0", "-else:", "- print(\"No\")", "+", "+", "+main()" ]
false
0.059653
0.042568
1.401377
[ "s166582058", "s705638551" ]
u970899068
p03283
python
s624179312
s579424723
2,289
637
80,012
97,500
Accepted
Accepted
72.17
import itertools import numpy as np n,m,q=list(map(int, input().split())) a=[list(map(int, input().split())) for i in range(m)] b=[list(map(int, input().split())) for i in range(q)] x=[[0]*(501) for i in range(501)] x=np.array(x) for i in range(m): x[a[i][0],a[i][1]]+=1 for i in range(501): x[i] = list(itertools.accumulate(x[i])) for i in range(501): x[:,i] = list(itertools.accumulate(x[:,i])) for i in range(q): print((x[b[i][1],b[i][1]]-x[b[i][1],b[i][0]-1]-x[b[i][0]-1,b[i][1]]+x[b[i][0]-1,b[i][0]-1]))
import sys input = sys.stdin.readline n,m,q= list(map(int, input().split())) a= [list(map(int, input().split())) for i in range(m)] b= [list(map(int, input().split())) for i in range(q)] # 2次元累積和 c=[[0]*(n+1) for i in range(n+1)] for i,j in a: c[i][j]+=1 for i in range(1,n+1): for j in range(1,n+1): c[i][j] += c[i - 1][j]+c[i][j - 1]-c[i-1][j-1] for i,j in b: ans=c[j][j]-c[i-1][j]-c[j][i-1]+c[i-1][i-1] print(ans)
32
20
570
458
import itertools import numpy as np n, m, q = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(m)] b = [list(map(int, input().split())) for i in range(q)] x = [[0] * (501) for i in range(501)] x = np.array(x) for i in range(m): x[a[i][0], a[i][1]] += 1 for i in range(501): x[i] = list(itertools.accumulate(x[i])) for i in range(501): x[:, i] = list(itertools.accumulate(x[:, i])) for i in range(q): print( ( x[b[i][1], b[i][1]] - x[b[i][1], b[i][0] - 1] - x[b[i][0] - 1, b[i][1]] + x[b[i][0] - 1, b[i][0] - 1] ) )
import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(m)] b = [list(map(int, input().split())) for i in range(q)] # 2次元累積和 c = [[0] * (n + 1) for i in range(n + 1)] for i, j in a: c[i][j] += 1 for i in range(1, n + 1): for j in range(1, n + 1): c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] for i, j in b: ans = c[j][j] - c[i - 1][j] - c[j][i - 1] + c[i - 1][i - 1] print(ans)
false
37.5
[ "-import itertools", "-import numpy as np", "+import sys", "+input = sys.stdin.readline", "-x = [[0] * (501) for i in range(501)]", "-x = np.array(x)", "-for i in range(m):", "- x[a[i][0], a[i][1]] += 1", "-for i in range(501):", "- x[i] = list(itertools.accumulate(x[i]))", "-for i in range(501):", "- x[:, i] = list(itertools.accumulate(x[:, i]))", "-for i in range(q):", "- print(", "- (", "- x[b[i][1], b[i][1]]", "- - x[b[i][1], b[i][0] - 1]", "- - x[b[i][0] - 1, b[i][1]]", "- + x[b[i][0] - 1, b[i][0] - 1]", "- )", "- )", "+# 2次元累積和", "+c = [[0] * (n + 1) for i in range(n + 1)]", "+for i, j in a:", "+ c[i][j] += 1", "+for i in range(1, n + 1):", "+ for j in range(1, n + 1):", "+ c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1]", "+for i, j in b:", "+ ans = c[j][j] - c[i - 1][j] - c[j][i - 1] + c[i - 1][i - 1]", "+ print(ans)" ]
false
0.282414
0.036024
7.839692
[ "s624179312", "s579424723" ]
u562935282
p03013
python
s845488157
s095119300
492
187
53,144
9,600
Accepted
Accepted
61.99
MOD = 10 ** 9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] broken = [False] * (N + 1) for aa in a: broken[aa] = True dp = [0] * (N + 1) dp[0] = 1 for i in range(1, N + 1): if broken[i]: continue if i >= 2: dp[i] = dp[i - 1] + dp[i - 2] else: dp[i] = dp[i - 1] dp[i] %= MOD print((dp[N]))
mod = 10 ** 9 + 7 n, m = list(map(int, input().split())) a = tuple(int(eval(input())) for _ in range(m)) b = [False] * (n + 1) for aa in a: b[aa] = True dp = [0] * (n + 5) dp[0] = 1 for i in range(n): if not b[i]: dp[i + 1] += dp[i] dp[i + 1] %= mod dp[i + 2] += dp[i] dp[i + 2] %= mod print((dp[n]))
20
18
381
347
MOD = 10**9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] broken = [False] * (N + 1) for aa in a: broken[aa] = True dp = [0] * (N + 1) dp[0] = 1 for i in range(1, N + 1): if broken[i]: continue if i >= 2: dp[i] = dp[i - 1] + dp[i - 2] else: dp[i] = dp[i - 1] dp[i] %= MOD print((dp[N]))
mod = 10**9 + 7 n, m = list(map(int, input().split())) a = tuple(int(eval(input())) for _ in range(m)) b = [False] * (n + 1) for aa in a: b[aa] = True dp = [0] * (n + 5) dp[0] = 1 for i in range(n): if not b[i]: dp[i + 1] += dp[i] dp[i + 1] %= mod dp[i + 2] += dp[i] dp[i + 2] %= mod print((dp[n]))
false
10
[ "-MOD = 10**9 + 7", "-N, M = list(map(int, input().split()))", "-a = [int(eval(input())) for _ in range(M)]", "-broken = [False] * (N + 1)", "+mod = 10**9 + 7", "+n, m = list(map(int, input().split()))", "+a = tuple(int(eval(input())) for _ in range(m))", "+b = [False] * (n + 1)", "- broken[aa] = True", "-dp = [0] * (N + 1)", "+ b[aa] = True", "+dp = [0] * (n + 5)", "-for i in range(1, N + 1):", "- if broken[i]:", "- continue", "- if i >= 2:", "- dp[i] = dp[i - 1] + dp[i - 2]", "- else:", "- dp[i] = dp[i - 1]", "- dp[i] %= MOD", "-print((dp[N]))", "+for i in range(n):", "+ if not b[i]:", "+ dp[i + 1] += dp[i]", "+ dp[i + 1] %= mod", "+ dp[i + 2] += dp[i]", "+ dp[i + 2] %= mod", "+print((dp[n]))" ]
false
0.037052
0.164133
0.225743
[ "s845488157", "s095119300" ]
u844789719
p03576
python
s493466564
s835192624
1,113
34
116,120
9,204
Accepted
Accepted
96.95
import numpy as np from numba import njit N, K, *XY = [int(_) for _ in open(0).read().split()] XY = np.array(XY, dtype=np.int64).reshape((N, 2)).T X = np.sort(XY[0]) Y = np.sort(XY[1]) @njit def solve(XY, X, Y): v = 4 * 10**18 + 1 ans = np.array([0, 0, 0, 0], dtype=np.int64) for i1 in range(N - 1): x1=X[i1] for i2 in range(i1 + 1, N): x2=X[i2] for j1 in range(N - 1): y1=Y[j1] for j2 in range(j1 + 1, N): y2 = Y[j2] if np.sum((x1 <= XY[0]) * (XY[0] <= x2) * (y1 <= XY[1]) * (XY[1] <= y2)) < K: continue v2 = (x2 - x1) * (y2 - y1) v = min(v, v2) return v ans = solve(XY, X, Y) print(ans)
N, K, *XY = [int(_) for _ in open(0).read().split()] XY = sorted(zip(XY[::2], XY[1::2])) ans = float('inf') for i in range(N): for j in range(i + K - 1, N): xlen = XY[j][0] - XY[i][0] Y = sorted(y for x, y in XY[i:j + 1]) ylen = min(y2 - y1 for y1, y2 in zip(Y, Y[K - 1:])) ans = min(ans, xlen * ylen) print(ans)
27
10
809
358
import numpy as np from numba import njit N, K, *XY = [int(_) for _ in open(0).read().split()] XY = np.array(XY, dtype=np.int64).reshape((N, 2)).T X = np.sort(XY[0]) Y = np.sort(XY[1]) @njit def solve(XY, X, Y): v = 4 * 10**18 + 1 ans = np.array([0, 0, 0, 0], dtype=np.int64) for i1 in range(N - 1): x1 = X[i1] for i2 in range(i1 + 1, N): x2 = X[i2] for j1 in range(N - 1): y1 = Y[j1] for j2 in range(j1 + 1, N): y2 = Y[j2] if ( np.sum( (x1 <= XY[0]) * (XY[0] <= x2) * (y1 <= XY[1]) * (XY[1] <= y2) ) < K ): continue v2 = (x2 - x1) * (y2 - y1) v = min(v, v2) return v ans = solve(XY, X, Y) print(ans)
N, K, *XY = [int(_) for _ in open(0).read().split()] XY = sorted(zip(XY[::2], XY[1::2])) ans = float("inf") for i in range(N): for j in range(i + K - 1, N): xlen = XY[j][0] - XY[i][0] Y = sorted(y for x, y in XY[i : j + 1]) ylen = min(y2 - y1 for y1, y2 in zip(Y, Y[K - 1 :])) ans = min(ans, xlen * ylen) print(ans)
false
62.962963
[ "-import numpy as np", "-from numba import njit", "-", "-XY = np.array(XY, dtype=np.int64).reshape((N, 2)).T", "-X = np.sort(XY[0])", "-Y = np.sort(XY[1])", "-", "-", "-@njit", "-def solve(XY, X, Y):", "- v = 4 * 10**18 + 1", "- ans = np.array([0, 0, 0, 0], dtype=np.int64)", "- for i1 in range(N - 1):", "- x1 = X[i1]", "- for i2 in range(i1 + 1, N):", "- x2 = X[i2]", "- for j1 in range(N - 1):", "- y1 = Y[j1]", "- for j2 in range(j1 + 1, N):", "- y2 = Y[j2]", "- if (", "- np.sum(", "- (x1 <= XY[0])", "- * (XY[0] <= x2)", "- * (y1 <= XY[1])", "- * (XY[1] <= y2)", "- )", "- < K", "- ):", "- continue", "- v2 = (x2 - x1) * (y2 - y1)", "- v = min(v, v2)", "- return v", "-", "-", "-ans = solve(XY, X, Y)", "+XY = sorted(zip(XY[::2], XY[1::2]))", "+ans = float(\"inf\")", "+for i in range(N):", "+ for j in range(i + K - 1, N):", "+ xlen = XY[j][0] - XY[i][0]", "+ Y = sorted(y for x, y in XY[i : j + 1])", "+ ylen = min(y2 - y1 for y1, y2 in zip(Y, Y[K - 1 :]))", "+ ans = min(ans, xlen * ylen)" ]
false
0.354012
0.036634
9.663383
[ "s493466564", "s835192624" ]
u745554846
p03072
python
s218289591
s248015422
19
17
2,940
2,940
Accepted
Accepted
10.53
a = int(eval(input())) b = [int(i) for i in input().split()] numbers = 1 for i in range(1, len(b)): if b[i] >= max(b[0:i]): numbers += 1 print(numbers)
n = int(eval(input())) mountains = [int(i) for i in input().split()] res = 0 for i in range(n): temp = 1 for j in range(i): if mountains[j] > mountains[i]: temp -= 1 break res += temp print(res)
9
14
167
248
a = int(eval(input())) b = [int(i) for i in input().split()] numbers = 1 for i in range(1, len(b)): if b[i] >= max(b[0:i]): numbers += 1 print(numbers)
n = int(eval(input())) mountains = [int(i) for i in input().split()] res = 0 for i in range(n): temp = 1 for j in range(i): if mountains[j] > mountains[i]: temp -= 1 break res += temp print(res)
false
35.714286
[ "-a = int(eval(input()))", "-b = [int(i) for i in input().split()]", "-numbers = 1", "-for i in range(1, len(b)):", "- if b[i] >= max(b[0:i]):", "- numbers += 1", "-print(numbers)", "+n = int(eval(input()))", "+mountains = [int(i) for i in input().split()]", "+res = 0", "+for i in range(n):", "+ temp = 1", "+ for j in range(i):", "+ if mountains[j] > mountains[i]:", "+ temp -= 1", "+ break", "+ res += temp", "+print(res)" ]
false
0.043849
0.118679
0.369478
[ "s218289591", "s248015422" ]
u808427016
p03290
python
s664347436
s675022817
1,275
21
28,004
3,064
Accepted
Accepted
98.35
D, G = [int(_) for _ in input().split()] PC = [[int(_) for _ in input().split()] for i in range(D)] P = [p for p, c in PC] C = [c for p, c in PC] from heapq import * h = [] heappush(h, (0, 0, (0,)*D)) result = 0 ef = {} while h: t, score, pat = heappop(h) # print(t, score, pat) if score >= G: result = t break def add(i, pat, d): pat1 = list(pat) if pat1[i] +d <= P[i]: pat1[i] += d pat1 = tuple(pat1) if not pat1 in ef: t1 = t + d score1 = score + (i+1)*100*d if pat1[i] == P[i]: score1 += C[i] ef[pat1] = t heappush(h, (t1, score1, pat1)) for i in range(D-1, -1, -1): if pat[i] < P[i]: add(i, pat, 1) break for i in range(D): if pat[i] + 1 < P[i]: add(i, pat, P[i] - pat[i]) print(result)
D, G = [int(_) for _ in input().split()] PC = [tuple(int(_) for _ in input().split()) for i in range(D)] from itertools import product def calc(D, G, PC, es): r = 0 k = None result = 0 for i, e, pc in zip(list(range(D)), es, PC): if e: r += (i+1) * 100 * pc[0] + pc[1] result += pc[0] else: k = i if r >= G: return result, r if not k is None: d = (k+1)*100 p = PC[k][0] if r + d * (p - 1) >= G: n = (G - r + d - 1) // d result += n r += n * d return result, r return None, None result = 10**20 for es in product((0, 1), repeat=D): r, score = calc(D, G, PC, es) #print(D, G, PC, es, r, score) if not r is None: result = min(result, r) print(result)
45
36
990
862
D, G = [int(_) for _ in input().split()] PC = [[int(_) for _ in input().split()] for i in range(D)] P = [p for p, c in PC] C = [c for p, c in PC] from heapq import * h = [] heappush(h, (0, 0, (0,) * D)) result = 0 ef = {} while h: t, score, pat = heappop(h) # print(t, score, pat) if score >= G: result = t break def add(i, pat, d): pat1 = list(pat) if pat1[i] + d <= P[i]: pat1[i] += d pat1 = tuple(pat1) if not pat1 in ef: t1 = t + d score1 = score + (i + 1) * 100 * d if pat1[i] == P[i]: score1 += C[i] ef[pat1] = t heappush(h, (t1, score1, pat1)) for i in range(D - 1, -1, -1): if pat[i] < P[i]: add(i, pat, 1) break for i in range(D): if pat[i] + 1 < P[i]: add(i, pat, P[i] - pat[i]) print(result)
D, G = [int(_) for _ in input().split()] PC = [tuple(int(_) for _ in input().split()) for i in range(D)] from itertools import product def calc(D, G, PC, es): r = 0 k = None result = 0 for i, e, pc in zip(list(range(D)), es, PC): if e: r += (i + 1) * 100 * pc[0] + pc[1] result += pc[0] else: k = i if r >= G: return result, r if not k is None: d = (k + 1) * 100 p = PC[k][0] if r + d * (p - 1) >= G: n = (G - r + d - 1) // d result += n r += n * d return result, r return None, None result = 10**20 for es in product((0, 1), repeat=D): r, score = calc(D, G, PC, es) # print(D, G, PC, es, r, score) if not r is None: result = min(result, r) print(result)
false
20
[ "-PC = [[int(_) for _ in input().split()] for i in range(D)]", "-P = [p for p, c in PC]", "-C = [c for p, c in PC]", "-from heapq import *", "+PC = [tuple(int(_) for _ in input().split()) for i in range(D)]", "+from itertools import product", "-h = []", "-heappush(h, (0, 0, (0,) * D))", "-result = 0", "-ef = {}", "-while h:", "- t, score, pat = heappop(h)", "- # print(t, score, pat)", "- if score >= G:", "- result = t", "- break", "- def add(i, pat, d):", "- pat1 = list(pat)", "- if pat1[i] + d <= P[i]:", "- pat1[i] += d", "- pat1 = tuple(pat1)", "- if not pat1 in ef:", "- t1 = t + d", "- score1 = score + (i + 1) * 100 * d", "- if pat1[i] == P[i]:", "- score1 += C[i]", "- ef[pat1] = t", "- heappush(h, (t1, score1, pat1))", "+def calc(D, G, PC, es):", "+ r = 0", "+ k = None", "+ result = 0", "+ for i, e, pc in zip(list(range(D)), es, PC):", "+ if e:", "+ r += (i + 1) * 100 * pc[0] + pc[1]", "+ result += pc[0]", "+ else:", "+ k = i", "+ if r >= G:", "+ return result, r", "+ if not k is None:", "+ d = (k + 1) * 100", "+ p = PC[k][0]", "+ if r + d * (p - 1) >= G:", "+ n = (G - r + d - 1) // d", "+ result += n", "+ r += n * d", "+ return result, r", "+ return None, None", "- for i in range(D - 1, -1, -1):", "- if pat[i] < P[i]:", "- add(i, pat, 1)", "- break", "- for i in range(D):", "- if pat[i] + 1 < P[i]:", "- add(i, pat, P[i] - pat[i])", "+", "+result = 10**20", "+for es in product((0, 1), repeat=D):", "+ r, score = calc(D, G, PC, es)", "+ # print(D, G, PC, es, r, score)", "+ if not r is None:", "+ result = min(result, r)" ]
false
0.138769
0.048494
2.861538
[ "s664347436", "s675022817" ]
u724844363
p03043
python
s109800048
s158056833
346
91
14,292
3,060
Accepted
Accepted
73.7
import numpy as np n, k = list(map(int, input().split())) e = 0 for i in range(1, n + 1): if i < k: if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)): sh = int(np.log2(k) - np.log2(i)) # 何回コインを投げるか else: sh = int(np.log2(k) - np.log2(i) + 1) e += (1 / n) * 0.5 ** sh else: e += (1 / n) print(e)
import math n, k = list(map(int, input().split())) ans = 0 ma = 10**9 for i in range(1, n+1): p = math.ceil(math.log2(k) - math.log2(i)) if p >= 1: ans += 1/(n*2**p) else: ans += 1/n print(ans)
14
13
378
229
import numpy as np n, k = list(map(int, input().split())) e = 0 for i in range(1, n + 1): if i < k: if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)): sh = int(np.log2(k) - np.log2(i)) # 何回コインを投げるか else: sh = int(np.log2(k) - np.log2(i) + 1) e += (1 / n) * 0.5**sh else: e += 1 / n print(e)
import math n, k = list(map(int, input().split())) ans = 0 ma = 10**9 for i in range(1, n + 1): p = math.ceil(math.log2(k) - math.log2(i)) if p >= 1: ans += 1 / (n * 2**p) else: ans += 1 / n print(ans)
false
7.142857
[ "-import numpy as np", "+import math", "-e = 0", "+ans = 0", "+ma = 10**9", "- if i < k:", "- if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)):", "- sh = int(np.log2(k) - np.log2(i)) # 何回コインを投げるか", "- else:", "- sh = int(np.log2(k) - np.log2(i) + 1)", "- e += (1 / n) * 0.5**sh", "+ p = math.ceil(math.log2(k) - math.log2(i))", "+ if p >= 1:", "+ ans += 1 / (n * 2**p)", "- e += 1 / n", "-print(e)", "+ ans += 1 / n", "+print(ans)" ]
false
0.29856
0.096739
3.086242
[ "s109800048", "s158056833" ]
u970133396
p02647
python
s588337033
s544160090
1,995
933
34,700
131,736
Accepted
Accepted
53.23
import sys from itertools import accumulate input=sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] # for _ in range(min(k,int(math.log(n,2)))): for _ in "_"*k: b=[0]*(n) for i,v in enumerate(A): if i>v: # b[max(0,i-v)]+=1 b[i-v]+=1 else: b[0]+=1 j=i-~v # if i+v+1<n: # b[i+v+1]-=1 if j<n: b[j]-=1 # update ans # cnt=0 # for i in range(1,n): # b[i]+=b[i-1] A=[*accumulate(b)] if min(A)==n: break print((" ".join(map(str,A)))) if '__main__' == __name__: main()
from numba import jit import numpy as np n, k = list(map(int, input().split())) A = np.array([*list(map(int, input().split()))],dtype=np.int64) # for _ in range(min(k,int(math.log(n,2)))): @jit def loop(A): for _ in range(k): b=np.zeros(n,dtype=np.int64) for i,v in enumerate(A): # if i>v: b[max(0,i-v)]+=1 # b[i-v]+=1 # else: # b[0]+=1 # j=i-~v if i+v+1<n: b[i+v+1]-=1 # if j<n: # b[j]-=1 # update ans # cnt=0 # for i in range(1,n): # b[i]+=b[i-1] A=np.cumsum(b) if min(A)==n: break return A print((" ".join(map(str,loop(A)))))
37
36
826
804
import sys from itertools import accumulate input = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] # for _ in range(min(k,int(math.log(n,2)))): for _ in "_" * k: b = [0] * (n) for i, v in enumerate(A): if i > v: # b[max(0,i-v)]+=1 b[i - v] += 1 else: b[0] += 1 j = i - ~v # if i+v+1<n: # b[i+v+1]-=1 if j < n: b[j] -= 1 # update ans # cnt=0 # for i in range(1,n): # b[i]+=b[i-1] A = [*accumulate(b)] if min(A) == n: break print((" ".join(map(str, A)))) if "__main__" == __name__: main()
from numba import jit import numpy as np n, k = list(map(int, input().split())) A = np.array([*list(map(int, input().split()))], dtype=np.int64) # for _ in range(min(k,int(math.log(n,2)))): @jit def loop(A): for _ in range(k): b = np.zeros(n, dtype=np.int64) for i, v in enumerate(A): # if i>v: b[max(0, i - v)] += 1 # b[i-v]+=1 # else: # b[0]+=1 # j=i-~v if i + v + 1 < n: b[i + v + 1] -= 1 # if j<n: # b[j]-=1 # update ans # cnt=0 # for i in range(1,n): # b[i]+=b[i-1] A = np.cumsum(b) if min(A) == n: break return A print((" ".join(map(str, loop(A)))))
false
2.702703
[ "-import sys", "-from itertools import accumulate", "+from numba import jit", "+import numpy as np", "-input = sys.stdin.buffer.readline", "-", "-", "-def main():", "- n, k = list(map(int, input().split()))", "- A = [*list(map(int, input().split()))]", "- # for _ in range(min(k,int(math.log(n,2)))):", "- for _ in \"_\" * k:", "- b = [0] * (n)", "+n, k = list(map(int, input().split()))", "+A = np.array([*list(map(int, input().split()))], dtype=np.int64)", "+# for _ in range(min(k,int(math.log(n,2)))):", "+@jit", "+def loop(A):", "+ for _ in range(k):", "+ b = np.zeros(n, dtype=np.int64)", "- if i > v:", "- # b[max(0,i-v)]+=1", "- b[i - v] += 1", "- else:", "- b[0] += 1", "- j = i - ~v", "- # if i+v+1<n:", "- # b[i+v+1]-=1", "- if j < n:", "- b[j] -= 1", "+ # if i>v:", "+ b[max(0, i - v)] += 1", "+ # b[i-v]+=1", "+ # else:", "+ # b[0]+=1", "+ # j=i-~v", "+ if i + v + 1 < n:", "+ b[i + v + 1] -= 1", "+ # if j<n:", "+ # b[j]-=1", "- A = [*accumulate(b)]", "+ A = np.cumsum(b)", "- print((\" \".join(map(str, A))))", "+ return A", "-if \"__main__\" == __name__:", "- main()", "+print((\" \".join(map(str, loop(A)))))" ]
false
0.079502
0.111681
0.711868
[ "s588337033", "s544160090" ]
u297574184
p03003
python
s685771874
s022062400
383
351
72,796
72,540
Accepted
Accepted
8.36
MOD = 10**9 + 7 N, M = list(map(int, input().split())) Ss = list(map(int, input().split())) Ts = list(map(int, input().split())) dp = [[1]*(M+1) for _ in range(N+1)] for i, S in enumerate(Ss, 1): for j, T in enumerate(Ts, 1): dp[i][j] = dp[i-1][j] + dp[i][j-1] if S != T: dp[i][j] -= dp[i-1][j-1] dp[i][j] %= MOD print((dp[-1][-1]))
def solve(): MOD = 10**9 + 7 N, M = list(map(int, input().split())) Ss = list(map(int, input().split())) Ts = list(map(int, input().split())) dp = [[0]*(M+1) for _ in range(N+1)] for i in range(N+1): dp[i][0] = 1 for j in range(M+1): dp[0][j] = 1 for i, S in enumerate(Ss, start=1): for j, T in enumerate(Ts, start=1): dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] if S == T: dp[i][j] += dp[i-1][j-1] dp[i][j] %= MOD print((dp[N][M])) solve()
15
24
382
580
MOD = 10**9 + 7 N, M = list(map(int, input().split())) Ss = list(map(int, input().split())) Ts = list(map(int, input().split())) dp = [[1] * (M + 1) for _ in range(N + 1)] for i, S in enumerate(Ss, 1): for j, T in enumerate(Ts, 1): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] if S != T: dp[i][j] -= dp[i - 1][j - 1] dp[i][j] %= MOD print((dp[-1][-1]))
def solve(): MOD = 10**9 + 7 N, M = list(map(int, input().split())) Ss = list(map(int, input().split())) Ts = list(map(int, input().split())) dp = [[0] * (M + 1) for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 1 for j in range(M + 1): dp[0][j] = 1 for i, S in enumerate(Ss, start=1): for j, T in enumerate(Ts, start=1): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] if S == T: dp[i][j] += dp[i - 1][j - 1] dp[i][j] %= MOD print((dp[N][M])) solve()
false
37.5
[ "-MOD = 10**9 + 7", "-N, M = list(map(int, input().split()))", "-Ss = list(map(int, input().split()))", "-Ts = list(map(int, input().split()))", "-dp = [[1] * (M + 1) for _ in range(N + 1)]", "-for i, S in enumerate(Ss, 1):", "- for j, T in enumerate(Ts, 1):", "- dp[i][j] = dp[i - 1][j] + dp[i][j - 1]", "- if S != T:", "- dp[i][j] -= dp[i - 1][j - 1]", "- dp[i][j] %= MOD", "-print((dp[-1][-1]))", "+def solve():", "+ MOD = 10**9 + 7", "+ N, M = list(map(int, input().split()))", "+ Ss = list(map(int, input().split()))", "+ Ts = list(map(int, input().split()))", "+ dp = [[0] * (M + 1) for _ in range(N + 1)]", "+ for i in range(N + 1):", "+ dp[i][0] = 1", "+ for j in range(M + 1):", "+ dp[0][j] = 1", "+ for i, S in enumerate(Ss, start=1):", "+ for j, T in enumerate(Ts, start=1):", "+ dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]", "+ if S == T:", "+ dp[i][j] += dp[i - 1][j - 1]", "+ dp[i][j] %= MOD", "+ print((dp[N][M]))", "+", "+", "+solve()" ]
false
0.120739
0.154376
0.782113
[ "s685771874", "s022062400" ]
u644907318
p02787
python
s843753961
s982763543
665
450
125,404
161,064
Accepted
Accepted
32.33
H,N = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(N)] A.insert(0,[0,0]) INFTY = 10**9 dp = [[INFTY for _ in range(H+1)] for _ in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(1,N+1): for j in range(1,H+1): dp[i][j] = dp[i-1][j] dp[i][j] = min(dp[i][j],dp[i][max(0,j-A[i][0])]+A[i][1]) print((dp[N][H]))
H,N = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(N)] INFTY = 10**8 dp = [[INFTY for _ in range(H+1)] for _ in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(1,N+1): for j in range(1,H+1): dp[i][j] = dp[i-1][j] if j>=A[i-1][0]: dp[i][j] = min(dp[i][j],dp[i][j-A[i-1][0]]+A[i-1][1]) else: dp[i][j] = min(dp[i][j],A[i-1][1]) print((dp[N][H]))
12
14
382
453
H, N = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] A.insert(0, [0, 0]) INFTY = 10**9 dp = [[INFTY for _ in range(H + 1)] for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for i in range(1, N + 1): for j in range(1, H + 1): dp[i][j] = dp[i - 1][j] dp[i][j] = min(dp[i][j], dp[i][max(0, j - A[i][0])] + A[i][1]) print((dp[N][H]))
H, N = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] INFTY = 10**8 dp = [[INFTY for _ in range(H + 1)] for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for i in range(1, N + 1): for j in range(1, H + 1): dp[i][j] = dp[i - 1][j] if j >= A[i - 1][0]: dp[i][j] = min(dp[i][j], dp[i][j - A[i - 1][0]] + A[i - 1][1]) else: dp[i][j] = min(dp[i][j], A[i - 1][1]) print((dp[N][H]))
false
14.285714
[ "-A.insert(0, [0, 0])", "-INFTY = 10**9", "+INFTY = 10**8", "- dp[i][j] = min(dp[i][j], dp[i][max(0, j - A[i][0])] + A[i][1])", "+ if j >= A[i - 1][0]:", "+ dp[i][j] = min(dp[i][j], dp[i][j - A[i - 1][0]] + A[i - 1][1])", "+ else:", "+ dp[i][j] = min(dp[i][j], A[i - 1][1])" ]
false
0.245733
0.325449
0.755057
[ "s843753961", "s982763543" ]
u384124931
p03014
python
s761110120
s422255713
509
458
68,696
109,952
Accepted
Accepted
10.02
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] sy = [0] * w ret = 0 for y in range(h): seqx = 0 seqy = 0 for x in range(w): if s[y][x] == '.': if sy[x] == 0: yy = y while yy < h and s[yy][x] != '#': yy += 1 sy[x] = yy - y seqx += 1 seqy = max(seqy, sy[x]) ret = max(ret, seqx + seqy - 1) else: seqx = 0 seqy = 0 sy[x] = 0 print(ret)
import numpy as np import sys def main(): sin = sys.stdin.buffer H, W = list(map(int, sin.readline().split())) grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".") grid = grid.reshape((H, W + 1))[:, :-1] L = np.empty((H, W), dtype="i4") R = np.empty((H, W), dtype="i4") T = np.empty((H, W), dtype="i4") B = np.empty((H, W), dtype="i4") T[0] = grid[0] for i in range(1, H): T[i] = (T[i - 1] + 1) * grid[i] B[-1] = grid[-1] for i in range(H - 2, -1, -1): B[i] = (B[i + 1] + 1) * grid[i] L[:, 0] = grid[:, 0] for i in range(1, W): L[:, i] = (L[:, i - 1] + 1) * grid[:, i] R[:, -1] = grid[:, -1] for i in range(W - 2, -1, -1): R[:, i] = (R[:, i + 1] + 1) * grid[:, i] ans = (T + B + L + R - 3).max() print(ans) main()
22
34
552
874
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] sy = [0] * w ret = 0 for y in range(h): seqx = 0 seqy = 0 for x in range(w): if s[y][x] == ".": if sy[x] == 0: yy = y while yy < h and s[yy][x] != "#": yy += 1 sy[x] = yy - y seqx += 1 seqy = max(seqy, sy[x]) ret = max(ret, seqx + seqy - 1) else: seqx = 0 seqy = 0 sy[x] = 0 print(ret)
import numpy as np import sys def main(): sin = sys.stdin.buffer H, W = list(map(int, sin.readline().split())) grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".") grid = grid.reshape((H, W + 1))[:, :-1] L = np.empty((H, W), dtype="i4") R = np.empty((H, W), dtype="i4") T = np.empty((H, W), dtype="i4") B = np.empty((H, W), dtype="i4") T[0] = grid[0] for i in range(1, H): T[i] = (T[i - 1] + 1) * grid[i] B[-1] = grid[-1] for i in range(H - 2, -1, -1): B[i] = (B[i + 1] + 1) * grid[i] L[:, 0] = grid[:, 0] for i in range(1, W): L[:, i] = (L[:, i - 1] + 1) * grid[:, i] R[:, -1] = grid[:, -1] for i in range(W - 2, -1, -1): R[:, i] = (R[:, i + 1] + 1) * grid[:, i] ans = (T + B + L + R - 3).max() print(ans) main()
false
35.294118
[ "-h, w = list(map(int, input().split()))", "-s = [eval(input()) for _ in range(h)]", "-sy = [0] * w", "-ret = 0", "-for y in range(h):", "- seqx = 0", "- seqy = 0", "- for x in range(w):", "- if s[y][x] == \".\":", "- if sy[x] == 0:", "- yy = y", "- while yy < h and s[yy][x] != \"#\":", "- yy += 1", "- sy[x] = yy - y", "- seqx += 1", "- seqy = max(seqy, sy[x])", "- ret = max(ret, seqx + seqy - 1)", "- else:", "- seqx = 0", "- seqy = 0", "- sy[x] = 0", "-print(ret)", "+import numpy as np", "+import sys", "+", "+", "+def main():", "+ sin = sys.stdin.buffer", "+ H, W = list(map(int, sin.readline().split()))", "+ grid = np.frombuffer(sin.read(H * (W + 1)), dtype=\"B\") == ord(\".\")", "+ grid = grid.reshape((H, W + 1))[:, :-1]", "+ L = np.empty((H, W), dtype=\"i4\")", "+ R = np.empty((H, W), dtype=\"i4\")", "+ T = np.empty((H, W), dtype=\"i4\")", "+ B = np.empty((H, W), dtype=\"i4\")", "+ T[0] = grid[0]", "+ for i in range(1, H):", "+ T[i] = (T[i - 1] + 1) * grid[i]", "+ B[-1] = grid[-1]", "+ for i in range(H - 2, -1, -1):", "+ B[i] = (B[i + 1] + 1) * grid[i]", "+ L[:, 0] = grid[:, 0]", "+ for i in range(1, W):", "+ L[:, i] = (L[:, i - 1] + 1) * grid[:, i]", "+ R[:, -1] = grid[:, -1]", "+ for i in range(W - 2, -1, -1):", "+ R[:, i] = (R[:, i + 1] + 1) * grid[:, i]", "+ ans = (T + B + L + R - 3).max()", "+ print(ans)", "+", "+", "+main()" ]
false
0.082488
0.170137
0.484833
[ "s761110120", "s422255713" ]
u491550356
p02711
python
s522373159
s400826546
22
20
8,952
9,092
Accepted
Accepted
9.09
N = eval(input()) print(("Yes" if N.find("7") >= 0 else "No"))
N = eval(input()) print(("Yes" if "7" in N else "No"))
2
2
55
47
N = eval(input()) print(("Yes" if N.find("7") >= 0 else "No"))
N = eval(input()) print(("Yes" if "7" in N else "No"))
false
0
[ "-print((\"Yes\" if N.find(\"7\") >= 0 else \"No\"))", "+print((\"Yes\" if \"7\" in N else \"No\"))" ]
false
0.106102
0.04477
2.369944
[ "s522373159", "s400826546" ]
u094155508
p02713
python
s612639461
s587206027
936
478
72,348
68,740
Accepted
Accepted
48.93
import math from functools import reduce from itertools import product def resolve(): K = int(eval(input())) gcd = math.gcd step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K+1)), list(range(1, K+1))) ] result = sum([ gcd(x[0], x[1]) for x in product(step1, list(range(1, K+1))) ]) print(result) if __name__ == "__main__": resolve()
import math k = int(eval(input())) ans = 0 for i in range(1, k+1): for j in range(1, k+1): for l in range(1, k+1): ans += math.gcd(math.gcd(i,j), l) print(ans)
13
11
345
191
import math from functools import reduce from itertools import product def resolve(): K = int(eval(input())) gcd = math.gcd step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K + 1)), list(range(1, K + 1))) ] result = sum([gcd(x[0], x[1]) for x in product(step1, list(range(1, K + 1)))]) print(result) if __name__ == "__main__": resolve()
import math k = int(eval(input())) ans = 0 for i in range(1, k + 1): for j in range(1, k + 1): for l in range(1, k + 1): ans += math.gcd(math.gcd(i, j), l) print(ans)
false
15.384615
[ "-from functools import reduce", "-from itertools import product", "-", "-def resolve():", "- K = int(eval(input()))", "- gcd = math.gcd", "- step1 = [", "- gcd(x[0], x[1]) for x in product(list(range(1, K + 1)), list(range(1, K + 1)))", "- ]", "- result = sum([gcd(x[0], x[1]) for x in product(step1, list(range(1, K + 1)))])", "- print(result)", "-", "-", "-if __name__ == \"__main__\":", "- resolve()", "+k = int(eval(input()))", "+ans = 0", "+for i in range(1, k + 1):", "+ for j in range(1, k + 1):", "+ for l in range(1, k + 1):", "+ ans += math.gcd(math.gcd(i, j), l)", "+print(ans)" ]
false
0.143651
0.086559
1.659577
[ "s612639461", "s587206027" ]
u729133443
p03808
python
s091879334
s026916624
256
66
69,920
14,068
Accepted
Accepted
74.22
n,*a=list(map(int,open(0).read().split())) b,m=sum(a),n*-~n//2 n-=1 c=b//m f=b%m>0 for i,j in zip(*[iter([a[-1]]+a*2)]*2): j-=i if n: t=min(0,j//n) f|=c!=j+n*-t-t print(('YNEOS'[f::2]))
n,*a=list(map(int,open(0).read().split())) q,m=divmod(sum(a),n*-~n//2) print(('YNEOS'[any((y-x-q)%n+m or y-x>q for x,y in zip(a,a[1:]))::2]))
11
3
199
135
n, *a = list(map(int, open(0).read().split())) b, m = sum(a), n * -~n // 2 n -= 1 c = b // m f = b % m > 0 for i, j in zip(*[iter([a[-1]] + a * 2)] * 2): j -= i if n: t = min(0, j // n) f |= c != j + n * -t - t print(("YNEOS"[f::2]))
n, *a = list(map(int, open(0).read().split())) q, m = divmod(sum(a), n * -~n // 2) print(("YNEOS"[any((y - x - q) % n + m or y - x > q for x, y in zip(a, a[1:])) :: 2]))
false
72.727273
[ "-b, m = sum(a), n * -~n // 2", "-n -= 1", "-c = b // m", "-f = b % m > 0", "-for i, j in zip(*[iter([a[-1]] + a * 2)] * 2):", "- j -= i", "- if n:", "- t = min(0, j // n)", "- f |= c != j + n * -t - t", "-print((\"YNEOS\"[f::2]))", "+q, m = divmod(sum(a), n * -~n // 2)", "+print((\"YNEOS\"[any((y - x - q) % n + m or y - x > q for x, y in zip(a, a[1:])) :: 2]))" ]
false
0.036338
0.034667
1.048185
[ "s091879334", "s026916624" ]
u724687935
p03682
python
s570306901
s977945850
1,994
1,232
144,464
50,788
Accepted
Accepted
38.21
import sys class UnionFind(): def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N = int(eval(input())) Px = [] Py = [] for k, s in enumerate(sys.stdin.readlines()): x, y = list(map(int, s.split())) Px.append((x, k)) Py.append((y, k)) edge = [] Px.sort() Py.sort() for i in range(N - 1): x0, k0 = Px[i] x1, k1 = Px[i + 1] d = abs(x0 - x1) edge.append((d, k0, k1)) y0, k0 = Py[i] y1, k1 = Py[i + 1] d = abs(y0 - y1) edge.append((d, k0, k1)) edge.sort() uf = UnionFind(N) cnt = 0 for d, k0, k1 in edge: if uf.find(k0) != uf.find(k1): uf.union(k0, k1) cnt += d if uf.parents[uf.find(0)] == -N: break print(cnt)
import sys class UnionFind(): def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N = int(eval(input())) Px = [] Py = [] for k, s in enumerate(sys.stdin.readlines()): x, y = list(map(int, s.split())) Px.append((x, k)) Py.append((y, k)) edge = [] Px.sort() Py.sort() for i in range(N - 1): x0, k0 = Px[i] x1, k1 = Px[i + 1] d = abs(x0 - x1) edge.append((d, k0, k1)) y0, k0 = Py[i] y1, k1 = Py[i + 1] d = abs(y0 - y1) edge.append((d, k0, k1)) edge.sort() uf = UnionFind(N) cnt = 0 for d, k0, k1 in edge: if uf.find(k0) != uf.find(k1): uf.union(k0, k1) cnt += d print(cnt)
63
60
1,199
1,140
import sys class UnionFind: def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N = int(eval(input())) Px = [] Py = [] for k, s in enumerate(sys.stdin.readlines()): x, y = list(map(int, s.split())) Px.append((x, k)) Py.append((y, k)) edge = [] Px.sort() Py.sort() for i in range(N - 1): x0, k0 = Px[i] x1, k1 = Px[i + 1] d = abs(x0 - x1) edge.append((d, k0, k1)) y0, k0 = Py[i] y1, k1 = Py[i + 1] d = abs(y0 - y1) edge.append((d, k0, k1)) edge.sort() uf = UnionFind(N) cnt = 0 for d, k0, k1 in edge: if uf.find(k0) != uf.find(k1): uf.union(k0, k1) cnt += d if uf.parents[uf.find(0)] == -N: break print(cnt)
import sys class UnionFind: def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N = int(eval(input())) Px = [] Py = [] for k, s in enumerate(sys.stdin.readlines()): x, y = list(map(int, s.split())) Px.append((x, k)) Py.append((y, k)) edge = [] Px.sort() Py.sort() for i in range(N - 1): x0, k0 = Px[i] x1, k1 = Px[i + 1] d = abs(x0 - x1) edge.append((d, k0, k1)) y0, k0 = Py[i] y1, k1 = Py[i + 1] d = abs(y0 - y1) edge.append((d, k0, k1)) edge.sort() uf = UnionFind(N) cnt = 0 for d, k0, k1 in edge: if uf.find(k0) != uf.find(k1): uf.union(k0, k1) cnt += d print(cnt)
false
4.761905
[ "- if uf.parents[uf.find(0)] == -N:", "- break" ]
false
0.040964
0.039529
1.036304
[ "s570306901", "s977945850" ]
u941438707
p03380
python
s624136426
s440162667
111
68
14,028
14,028
Accepted
Accepted
38.74
n,*a=list(map(int,open(0).read().split())) a.sort() b=a[-1] c=a[0] d=b/2-c for i in a: if d>abs(b/2-i): c=i d=abs(b/2-i) print((b,c))
n,*a=list(map(int,open(0).read().split())) n=max(a) print((n,min((abs(n/2-i),i)for i in a)[1]))
10
3
154
89
n, *a = list(map(int, open(0).read().split())) a.sort() b = a[-1] c = a[0] d = b / 2 - c for i in a: if d > abs(b / 2 - i): c = i d = abs(b / 2 - i) print((b, c))
n, *a = list(map(int, open(0).read().split())) n = max(a) print((n, min((abs(n / 2 - i), i) for i in a)[1]))
false
70
[ "-a.sort()", "-b = a[-1]", "-c = a[0]", "-d = b / 2 - c", "-for i in a:", "- if d > abs(b / 2 - i):", "- c = i", "- d = abs(b / 2 - i)", "-print((b, c))", "+n = max(a)", "+print((n, min((abs(n / 2 - i), i) for i in a)[1]))" ]
false
0.034386
0.034699
0.990988
[ "s624136426", "s440162667" ]
u366959492
p03161
python
s432292064
s340240009
1,940
383
13,928
52,448
Accepted
Accepted
80.26
n,k=list(map(int,input().split())) h=list(map(int,input().split())) dp=[0]*n def calc(n,k,h,dp): for i in range(1,n): dp[i]=min([dp[j] + abs(h[i]-h[j]) for j in range(max(i-k,0),i)]) calc(n,k,h,dp) print((dp[-1]))
n,k=list(map(int,input().split())) h=list(map(int,input().split())) h+=[0]*k inf=10**9 dp=[inf]*(n+k) dp[0]=0 for i in range(n): for j in range(1,k+1): dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j]) print((dp[n-1]))
10
10
229
226
n, k = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * n def calc(n, k, h, dp): for i in range(1, n): dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)]) calc(n, k, h, dp) print((dp[-1]))
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h += [0] * k inf = 10**9 dp = [inf] * (n + k) dp[0] = 0 for i in range(n): for j in range(1, k + 1): dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]) print((dp[n - 1]))
false
0
[ "-dp = [0] * n", "-", "-", "-def calc(n, k, h, dp):", "- for i in range(1, n):", "- dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)])", "-", "-", "-calc(n, k, h, dp)", "-print((dp[-1]))", "+h += [0] * k", "+inf = 10**9", "+dp = [inf] * (n + k)", "+dp[0] = 0", "+for i in range(n):", "+ for j in range(1, k + 1):", "+ dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])", "+print((dp[n - 1]))" ]
false
0.279711
0.037143
7.530554
[ "s432292064", "s340240009" ]
u588341295
p03172
python
s983133600
s574411317
777
321
135,768
90,576
Accepted
Accepted
58.69
# -*- coding: utf-8 -*- import sys from functools import reduce def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N, K = MAP() aN = LIST() # dp[この子までの範囲で][飴を配る総数] = 場合の数 dp = [[0] * (K+1) for i in range(N+1)] # 0番目まで(誰もいない)の範囲で0個配る場合の数は1通り dp[0][0] = 1 for i in range(N): sm = [0] * (K+2) # 今回送るi行について累積和を取る for j in range(1, K+2): sm[j] = sm[j-1] + dp[i][j-1] sm[j] %= MOD for j in range(K+1): # iが送る予定の長さに応じた区間和を取る dp[i+1][j] = sm[j+1] - sm[max(j-aN[i], 0)] dp[i+1][j] %= MOD # for k in range(aN[i]+1): # dp[i+1][j+k] += dp[i][j] print((dp[N][K]))
# -*- coding: utf-8 -*- import sys import numpy as np from functools import reduce def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N, K = MAP() A = LIST() # dp[この子までの範囲で][飴を配る総数] = 場合の数 dp = np.zeros((N+1, K+1), dtype=np.int64) # 0番目まで(誰もいない)の範囲で0個配る場合の数は1通り dp[0,0] = 1 for i, a in enumerate(A): # 今回のiを次の遷移させる区間の始点としてまとめて追加 dp[i+1] = dp[i] # 今回のiをa+1個ずらして、遷移させる区間の終点としてまとめて追加 dp[i+1,a+1:] -= dp[i,:-(a+1)] # 累積和すれば、元の状態からそれぞれa個先まで遷移させた状態になる # (区間の始点・終点の記録→累積和の流れはimos的な感じ) np.cumsum(dp[i+1], out=dp[i+1]) dp[i+1] %= MOD print((dp[N][K]))
39
38
1,115
1,063
# -*- coding: utf-8 -*- import sys from functools import reduce def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, K = MAP() aN = LIST() # dp[この子までの範囲で][飴を配る総数] = 場合の数 dp = [[0] * (K + 1) for i in range(N + 1)] # 0番目まで(誰もいない)の範囲で0個配る場合の数は1通り dp[0][0] = 1 for i in range(N): sm = [0] * (K + 2) # 今回送るi行について累積和を取る for j in range(1, K + 2): sm[j] = sm[j - 1] + dp[i][j - 1] sm[j] %= MOD for j in range(K + 1): # iが送る予定の長さに応じた区間和を取る dp[i + 1][j] = sm[j + 1] - sm[max(j - aN[i], 0)] dp[i + 1][j] %= MOD # for k in range(aN[i]+1): # dp[i+1][j+k] += dp[i][j] print((dp[N][K]))
# -*- coding: utf-8 -*- import sys import numpy as np from functools import reduce def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, K = MAP() A = LIST() # dp[この子までの範囲で][飴を配る総数] = 場合の数 dp = np.zeros((N + 1, K + 1), dtype=np.int64) # 0番目まで(誰もいない)の範囲で0個配る場合の数は1通り dp[0, 0] = 1 for i, a in enumerate(A): # 今回のiを次の遷移させる区間の始点としてまとめて追加 dp[i + 1] = dp[i] # 今回のiをa+1個ずらして、遷移させる区間の終点としてまとめて追加 dp[i + 1, a + 1 :] -= dp[i, : -(a + 1)] # 累積和すれば、元の状態からそれぞれa個先まで遷移させた状態になる # (区間の始点・終点の記録→累積和の流れはimos的な感じ) np.cumsum(dp[i + 1], out=dp[i + 1]) dp[i + 1] %= MOD print((dp[N][K]))
false
2.564103
[ "+import numpy as np", "-aN = LIST()", "+A = LIST()", "-dp = [[0] * (K + 1) for i in range(N + 1)]", "+dp = np.zeros((N + 1, K + 1), dtype=np.int64)", "-dp[0][0] = 1", "-for i in range(N):", "- sm = [0] * (K + 2)", "- # 今回送るi行について累積和を取る", "- for j in range(1, K + 2):", "- sm[j] = sm[j - 1] + dp[i][j - 1]", "- sm[j] %= MOD", "- for j in range(K + 1):", "- # iが送る予定の長さに応じた区間和を取る", "- dp[i + 1][j] = sm[j + 1] - sm[max(j - aN[i], 0)]", "- dp[i + 1][j] %= MOD", "- # for k in range(aN[i]+1):", "- # dp[i+1][j+k] += dp[i][j]", "+dp[0, 0] = 1", "+for i, a in enumerate(A):", "+ # 今回のiを次の遷移させる区間の始点としてまとめて追加", "+ dp[i + 1] = dp[i]", "+ # 今回のiをa+1個ずらして、遷移させる区間の終点としてまとめて追加", "+ dp[i + 1, a + 1 :] -= dp[i, : -(a + 1)]", "+ # 累積和すれば、元の状態からそれぞれa個先まで遷移させた状態になる", "+ # (区間の始点・終点の記録→累積和の流れはimos的な感じ)", "+ np.cumsum(dp[i + 1], out=dp[i + 1])", "+ dp[i + 1] %= MOD" ]
false
0.940022
0.852928
1.102112
[ "s983133600", "s574411317" ]
u353919145
p02909
python
s314160696
s032224356
19
17
3,060
2,940
Accepted
Accepted
10.53
x=eval(input()) if x=="Sunny" : print("Cloudy") if x=="Cloudy" : print("Rainy") if x=="Rainy" : print("Sunny")
S = eval(input()) sun = "Sunny" clo = "Cloudy" rai = "Rainy" if S == sun: S = clo print(S) elif S == rai: S = sun print(S) elif S == clo: S = rai print(S)
7
13
114
184
x = eval(input()) if x == "Sunny": print("Cloudy") if x == "Cloudy": print("Rainy") if x == "Rainy": print("Sunny")
S = eval(input()) sun = "Sunny" clo = "Cloudy" rai = "Rainy" if S == sun: S = clo print(S) elif S == rai: S = sun print(S) elif S == clo: S = rai print(S)
false
46.153846
[ "-x = eval(input())", "-if x == \"Sunny\":", "- print(\"Cloudy\")", "-if x == \"Cloudy\":", "- print(\"Rainy\")", "-if x == \"Rainy\":", "- print(\"Sunny\")", "+S = eval(input())", "+sun = \"Sunny\"", "+clo = \"Cloudy\"", "+rai = \"Rainy\"", "+if S == sun:", "+ S = clo", "+ print(S)", "+elif S == rai:", "+ S = sun", "+ print(S)", "+elif S == clo:", "+ S = rai", "+ print(S)" ]
false
0.078097
0.104645
0.746305
[ "s314160696", "s032224356" ]
u714878632
p02929
python
s057952688
s332980553
115
86
4,916
3,516
Accepted
Accepted
25.22
def main(): n = int(eval(input())) s = eval(input()) divider = pow(10, 9) + 7 if s[0] == "W" or s[2 * n - 1] == "W": print((0)) return lr = [True] for i in range(1, 2 * n - 1): if s[i - 1] == s[i]: lr.append(not lr[i - 1]) else: lr.append(lr[i - 1]) lr.append(False) ret = 1 cnt = 0 for i in range(2 * n): if lr[i]: cnt += 1 else: ret *= cnt ret %= divider cnt -= 1 if not cnt == 0: print((0)) return for i in range(n): ret *= i + 1 ret %= divider print(ret) return if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = eval(input()) divider = pow(10, 9) + 7 if s[0] == "W" or s[2 * n - 1] == "W": print((0)) return flag = True cnt = 1 ret = 1 for i in range(1, 2 * n): if s[i - 1] == s[i]: flag = not flag if flag: cnt += 1 else: ret *= cnt ret %= divider cnt -= 1 if not cnt == 0: print((0)) return for i in range(n): ret *= i + 1 ret %= divider print(ret) return if __name__ == "__main__": main()
35
31
732
619
def main(): n = int(eval(input())) s = eval(input()) divider = pow(10, 9) + 7 if s[0] == "W" or s[2 * n - 1] == "W": print((0)) return lr = [True] for i in range(1, 2 * n - 1): if s[i - 1] == s[i]: lr.append(not lr[i - 1]) else: lr.append(lr[i - 1]) lr.append(False) ret = 1 cnt = 0 for i in range(2 * n): if lr[i]: cnt += 1 else: ret *= cnt ret %= divider cnt -= 1 if not cnt == 0: print((0)) return for i in range(n): ret *= i + 1 ret %= divider print(ret) return if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = eval(input()) divider = pow(10, 9) + 7 if s[0] == "W" or s[2 * n - 1] == "W": print((0)) return flag = True cnt = 1 ret = 1 for i in range(1, 2 * n): if s[i - 1] == s[i]: flag = not flag if flag: cnt += 1 else: ret *= cnt ret %= divider cnt -= 1 if not cnt == 0: print((0)) return for i in range(n): ret *= i + 1 ret %= divider print(ret) return if __name__ == "__main__": main()
false
11.428571
[ "- lr = [True]", "- for i in range(1, 2 * n - 1):", "+ flag = True", "+ cnt = 1", "+ ret = 1", "+ for i in range(1, 2 * n):", "- lr.append(not lr[i - 1])", "- else:", "- lr.append(lr[i - 1])", "- lr.append(False)", "- ret = 1", "- cnt = 0", "- for i in range(2 * n):", "- if lr[i]:", "+ flag = not flag", "+ if flag:" ]
false
0.047734
0.047162
1.012126
[ "s057952688", "s332980553" ]
u423585790
p02819
python
s174584794
s816585059
248
174
48,624
39,152
Accepted
Accepted
29.84
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x)-1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') def primes(n): """ Input n>=6, Returns a list of primes, 2 <= p < n 6以上の数であれば p (素数) <= n のlistを返す :param int n: :rytpe list: """ n, correction = n-n%6+6, 2-(n%6>1) sieve = [True] * (n//3) for i in range(1,int(n**0.5)//3+1): if sieve[i]: k=3*i+1|1 sieve[ k*k//3 ::2*k] = [False] * ((n//6-k*k//6-1)//k+1) sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1) return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]] #solve def solve(): x = II() p = primes(10 ** 6) print((p[bisect_left(p, x)])) return #main if __name__ == '__main__': solve()
n = int(eval(input())) def f(x): for k in range(2, int(x**0.5) + 1): if x % k != 0: continue return False return True i = n while 1: if f(i): print(i) break i += 1
53
13
1,665
229
#!/usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") def primes(n): """ Input n>=6, Returns a list of primes, 2 <= p < n 6以上の数であれば p (素数) <= n のlistを返す :param int n: :rytpe list: """ n, correction = n - n % 6 + 6, 2 - (n % 6 > 1) sieve = [True] * (n // 3) for i in range(1, int(n**0.5) // 3 + 1): if sieve[i]: k = 3 * i + 1 | 1 sieve[k * k // 3 :: 2 * k] = [False] * ((n // 6 - k * k // 6 - 1) // k + 1) sieve[k * (k - 2 * (i & 1) + 4) // 3 :: 2 * k] = [False] * ( (n // 6 - k * (k - 2 * (i & 1) + 4) // 6 - 1) // k + 1 ) return [2, 3] + [3 * i + 1 | 1 for i in range(1, n // 3 - correction) if sieve[i]] # solve def solve(): x = II() p = primes(10**6) print((p[bisect_left(p, x)])) return # main if __name__ == "__main__": solve()
n = int(eval(input())) def f(x): for k in range(2, int(x**0.5) + 1): if x % k != 0: continue return False return True i = n while 1: if f(i): print(i) break i += 1
false
75.471698
[ "-#!/usr/bin/env python3", "-from collections import defaultdict, deque", "-from heapq import heappush, heappop", "-from bisect import bisect_left, bisect_right", "-import sys, random, itertools, math", "-", "-sys.setrecursionlimit(10**5)", "-input = sys.stdin.readline", "-sqrt = math.sqrt", "+n = int(eval(input()))", "-def LI():", "- return list(map(int, input().split()))", "+def f(x):", "+ for k in range(2, int(x**0.5) + 1):", "+ if x % k != 0:", "+ continue", "+ return False", "+ return True", "-def LF():", "- return list(map(float, input().split()))", "-", "-", "-def LI_():", "- return list([int(x) - 1 for x in input().split()])", "-", "-", "-def II():", "- return int(eval(input()))", "-", "-", "-def IF():", "- return float(eval(input()))", "-", "-", "-def LS():", "- return list(map(list, input().split()))", "-", "-", "-def S():", "- return list(input().rstrip())", "-", "-", "-def IR(n):", "- return [II() for _ in range(n)]", "-", "-", "-def LIR(n):", "- return [LI() for _ in range(n)]", "-", "-", "-def FR(n):", "- return [IF() for _ in range(n)]", "-", "-", "-def LFR(n):", "- return [LI() for _ in range(n)]", "-", "-", "-def LIR_(n):", "- return [LI_() for _ in range(n)]", "-", "-", "-def SR(n):", "- return [S() for _ in range(n)]", "-", "-", "-def LSR(n):", "- return [LS() for _ in range(n)]", "-", "-", "-mod = 1000000007", "-inf = float(\"INF\")", "-", "-", "-def primes(n):", "- \"\"\"", "- Input n>=6, Returns a list of primes, 2 <= p < n", "- 6以上の数であれば p (素数) <= n のlistを返す", "- :param int n:", "- :rytpe list:", "- \"\"\"", "- n, correction = n - n % 6 + 6, 2 - (n % 6 > 1)", "- sieve = [True] * (n // 3)", "- for i in range(1, int(n**0.5) // 3 + 1):", "- if sieve[i]:", "- k = 3 * i + 1 | 1", "- sieve[k * k // 3 :: 2 * k] = [False] * ((n // 6 - k * k // 6 - 1) // k + 1)", "- sieve[k * (k - 2 * (i & 1) + 4) // 3 :: 2 * k] = [False] * (", "- (n // 6 - k * (k - 2 * (i & 1) + 4) // 6 - 1) // k + 1", "- )", "- return [2, 3] + [3 * i + 1 | 1 for i in range(1, n // 3 - correction) if sieve[i]]", "-", "-", "-# solve", "-def solve():", "- x = II()", "- p = primes(10**6)", "- print((p[bisect_left(p, x)]))", "- return", "-", "-", "-# main", "-if __name__ == \"__main__\":", "- solve()", "+i = n", "+while 1:", "+ if f(i):", "+ print(i)", "+ break", "+ i += 1" ]
false
0.073303
0.034139
2.147191
[ "s174584794", "s816585059" ]
u462434199
p03283
python
s250792567
s060100330
1,857
1,508
57,540
66,896
Accepted
Accepted
18.79
import numpy as np n,m,q=list(map(int, input().split())) a=np.array([list(map(int, input().split())) for i in range(m)]) b=[list(map(int, input().split())) for i in range(q)] x=np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1=b[i][0] v2=b[i][1] a1=x[v2, v2] a2=x[v2, v1-1] a3=x[v1-1, v2] a4=x[v1-1, v1-1] print((a1-a2-a3+a4))
import numpy as np import sys n, m, q = list(map(int, input().split())) ab = np.array(sys.stdin.read().split(), np.int) a = ab[:m*2].reshape(m, 2) b = ab[m*2:].reshape(q, 2) x=np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1=b[i][0] v2=b[i][1] a1=x[v2, v2] a2=x[v2, v1-1] a3=x[v1-1, v2] a4=x[v1-1, v1-1] print((a1-a2-a3+a4))
22
24
479
478
import numpy as np n, m, q = list(map(int, input().split())) a = np.array([list(map(int, input().split())) for i in range(m)]) b = [list(map(int, input().split())) for i in range(q)] x = np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1 = b[i][0] v2 = b[i][1] a1 = x[v2, v2] a2 = x[v2, v1 - 1] a3 = x[v1 - 1, v2] a4 = x[v1 - 1, v1 - 1] print((a1 - a2 - a3 + a4))
import numpy as np import sys n, m, q = list(map(int, input().split())) ab = np.array(sys.stdin.read().split(), np.int) a = ab[: m * 2].reshape(m, 2) b = ab[m * 2 :].reshape(q, 2) x = np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1 = b[i][0] v2 = b[i][1] a1 = x[v2, v2] a2 = x[v2, v1 - 1] a3 = x[v1 - 1, v2] a4 = x[v1 - 1, v1 - 1] print((a1 - a2 - a3 + a4))
false
8.333333
[ "+import sys", "-a = np.array([list(map(int, input().split())) for i in range(m)])", "-b = [list(map(int, input().split())) for i in range(q)]", "+ab = np.array(sys.stdin.read().split(), np.int)", "+a = ab[: m * 2].reshape(m, 2)", "+b = ab[m * 2 :].reshape(q, 2)" ]
false
0.270614
0.560264
0.483011
[ "s250792567", "s060100330" ]
u218843509
p02589
python
s144931499
s276489178
2,970
2,584
597,876
598,252
Accepted
Accepted
13
import sys def input(): return sys.stdin.readline()[:-1] BASE, MOD = 1999849216943526259, (1<<61)-1 d = dict() ans = 0 ss = [str(eval(input()))[::-1] for _ in range(int(eval(input())))] zero = [0 for _ in range(26)] ss.sort(key=lambda x: -len(x)) for s in ss: n = len(s) if n == 1: ans += zero[ord(s[n-1])-97] else: hashes = [0 for _ in range(n-1)] hashes[0] = ord(s[0]) for i in range(1, n-1): hashes[i] = (hashes[i-1] * BASE + ord(s[i])) % MOD if hashes[n-2] in d: ans += d[hashes[n-2]][ord(s[n-1])-97] alph = [0 for _ in range(26)] alph[ord(s[n-1])-97] = 1 for i in range(n-2, 0, -1): alph[ord(s[i])-97] = 1 if hashes[i-1] not in d: d[hashes[i-1]] = [0 for _ in range(26)] for j, a in enumerate(alph): d[hashes[i-1]][j] += a alph[ord(s[0])-97] = 1 for j, a in enumerate(alph): zero[j] += a print(ans)
import sys def input(): return sys.stdin.readline()[:-1] BASE, MOD = 1999849216943526259, (1<<61)-1 d = dict() ans = 0 ss = [input()[::-1] for _ in range(int(eval(input())))] zero = [0 for _ in range(26)] ss.sort(key=lambda x: -len(x)) for s in ss: n = len(s) if n == 1: ans += zero[ord(s[n-1])-97] else: hashes = [0 for _ in range(n-1)] hashes[0] = ord(s[0]) for i in range(1, n-1): hashes[i] = (hashes[i-1] * BASE + ord(s[i])) % MOD if hashes[n-2] in d: ans += d[hashes[n-2]][ord(s[n-1])-97] alph = [0 for _ in range(26)] alph[ord(s[n-1])-97] = 1 for i in range(n-2, 0, -1): alph[ord(s[i])-97] = 1 if hashes[i-1] not in d: d[hashes[i-1]] = [0 for _ in range(26)] for j, a in enumerate(alph): d[hashes[i-1]][j] += a alph[ord(s[0])-97] = 1 for j, a in enumerate(alph): zero[j] += a print(ans)
34
34
876
871
import sys def input(): return sys.stdin.readline()[:-1] BASE, MOD = 1999849216943526259, (1 << 61) - 1 d = dict() ans = 0 ss = [str(eval(input()))[::-1] for _ in range(int(eval(input())))] zero = [0 for _ in range(26)] ss.sort(key=lambda x: -len(x)) for s in ss: n = len(s) if n == 1: ans += zero[ord(s[n - 1]) - 97] else: hashes = [0 for _ in range(n - 1)] hashes[0] = ord(s[0]) for i in range(1, n - 1): hashes[i] = (hashes[i - 1] * BASE + ord(s[i])) % MOD if hashes[n - 2] in d: ans += d[hashes[n - 2]][ord(s[n - 1]) - 97] alph = [0 for _ in range(26)] alph[ord(s[n - 1]) - 97] = 1 for i in range(n - 2, 0, -1): alph[ord(s[i]) - 97] = 1 if hashes[i - 1] not in d: d[hashes[i - 1]] = [0 for _ in range(26)] for j, a in enumerate(alph): d[hashes[i - 1]][j] += a alph[ord(s[0]) - 97] = 1 for j, a in enumerate(alph): zero[j] += a print(ans)
import sys def input(): return sys.stdin.readline()[:-1] BASE, MOD = 1999849216943526259, (1 << 61) - 1 d = dict() ans = 0 ss = [input()[::-1] for _ in range(int(eval(input())))] zero = [0 for _ in range(26)] ss.sort(key=lambda x: -len(x)) for s in ss: n = len(s) if n == 1: ans += zero[ord(s[n - 1]) - 97] else: hashes = [0 for _ in range(n - 1)] hashes[0] = ord(s[0]) for i in range(1, n - 1): hashes[i] = (hashes[i - 1] * BASE + ord(s[i])) % MOD if hashes[n - 2] in d: ans += d[hashes[n - 2]][ord(s[n - 1]) - 97] alph = [0 for _ in range(26)] alph[ord(s[n - 1]) - 97] = 1 for i in range(n - 2, 0, -1): alph[ord(s[i]) - 97] = 1 if hashes[i - 1] not in d: d[hashes[i - 1]] = [0 for _ in range(26)] for j, a in enumerate(alph): d[hashes[i - 1]][j] += a alph[ord(s[0]) - 97] = 1 for j, a in enumerate(alph): zero[j] += a print(ans)
false
0
[ "-ss = [str(eval(input()))[::-1] for _ in range(int(eval(input())))]", "+ss = [input()[::-1] for _ in range(int(eval(input())))]" ]
false
0.048478
0.048103
1.007802
[ "s144931499", "s276489178" ]
u300645821
p00760
python
s802308022
s996697758
30
20
6,724
4,208
Accepted
Accepted
33.33
import sys if sys.version_info[0]>=3: raw_input=input n=int(input()) for i in range(0,n): a=[int(e) for e in input().split()] a[0]-=1;a[1]-=1 print((196471-a[0]*195-a[0]//3*5-a[1]*20+(a[1]//2 if a[0]%3!=2 else 0)-a[2]))
n=int(input()) for i in range(0,n): y,m,d=[int(e) for e in input().split()] y-=1;m-=1 print((196471-y*195-y//3*5-m*20+(m//2 if y%3!=2 else 0)-d))
8
5
236
158
import sys if sys.version_info[0] >= 3: raw_input = input n = int(input()) for i in range(0, n): a = [int(e) for e in input().split()] a[0] -= 1 a[1] -= 1 print( ( 196471 - a[0] * 195 - a[0] // 3 * 5 - a[1] * 20 + (a[1] // 2 if a[0] % 3 != 2 else 0) - a[2] ) )
n = int(input()) for i in range(0, n): y, m, d = [int(e) for e in input().split()] y -= 1 m -= 1 print((196471 - y * 195 - y // 3 * 5 - m * 20 + (m // 2 if y % 3 != 2 else 0) - d))
false
37.5
[ "-import sys", "-", "-if sys.version_info[0] >= 3:", "- raw_input = input", "- a = [int(e) for e in input().split()]", "- a[0] -= 1", "- a[1] -= 1", "- print(", "- (", "- 196471", "- - a[0] * 195", "- - a[0] // 3 * 5", "- - a[1] * 20", "- + (a[1] // 2 if a[0] % 3 != 2 else 0)", "- - a[2]", "- )", "- )", "+ y, m, d = [int(e) for e in input().split()]", "+ y -= 1", "+ m -= 1", "+ print((196471 - y * 195 - y // 3 * 5 - m * 20 + (m // 2 if y % 3 != 2 else 0) - d))" ]
false
0.056197
0.034649
1.621905
[ "s802308022", "s996697758" ]
u562935282
p03309
python
s391011696
s958113137
224
195
26,180
26,836
Accepted
Accepted
12.95
N = int(eval(input())) A = list(map(int, input().split())) B = list(A_i - (i + 1) for i, A_i in enumerate(A)) B_sorted = sorted(B) ans = [] ##中央値のインデックスmを求める if N % 2 == 1: ##Nが奇数: 中央値のインデックスを求める m = int((N - 1) / 2 + 1) - 1 b = B_sorted[m] ans += [sum(abs(x - b) for x in B_sorted)] else: ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める for m in range(int(N / 2) - 1, int(N / 2) + 1): b = B_sorted[m] ans += [sum(abs(x - b) for x in B_sorted)] print((min(ans)))
N = int(eval(input())) a = list(map(int, input().split())) a = [a[i] - (i + 1) for i in range(N)] a = sorted(a) if N % 2 == 0: t = (a[N // 2 - 1] + a[N // 2]) // 2 else: t = a[N // 2] ans = sum(abs(aa - t) for aa in a) print(ans)
18
12
496
245
N = int(eval(input())) A = list(map(int, input().split())) B = list(A_i - (i + 1) for i, A_i in enumerate(A)) B_sorted = sorted(B) ans = [] ##中央値のインデックスmを求める if N % 2 == 1: ##Nが奇数: 中央値のインデックスを求める m = int((N - 1) / 2 + 1) - 1 b = B_sorted[m] ans += [sum(abs(x - b) for x in B_sorted)] else: ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める for m in range(int(N / 2) - 1, int(N / 2) + 1): b = B_sorted[m] ans += [sum(abs(x - b) for x in B_sorted)] print((min(ans)))
N = int(eval(input())) a = list(map(int, input().split())) a = [a[i] - (i + 1) for i in range(N)] a = sorted(a) if N % 2 == 0: t = (a[N // 2 - 1] + a[N // 2]) // 2 else: t = a[N // 2] ans = sum(abs(aa - t) for aa in a) print(ans)
false
33.333333
[ "-A = list(map(int, input().split()))", "-B = list(A_i - (i + 1) for i, A_i in enumerate(A))", "-B_sorted = sorted(B)", "-ans = []", "-##中央値のインデックスmを求める", "-if N % 2 == 1:", "- ##Nが奇数: 中央値のインデックスを求める", "- m = int((N - 1) / 2 + 1) - 1", "- b = B_sorted[m]", "- ans += [sum(abs(x - b) for x in B_sorted)]", "+a = list(map(int, input().split()))", "+a = [a[i] - (i + 1) for i in range(N)]", "+a = sorted(a)", "+if N % 2 == 0:", "+ t = (a[N // 2 - 1] + a[N // 2]) // 2", "- ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める", "- for m in range(int(N / 2) - 1, int(N / 2) + 1):", "- b = B_sorted[m]", "- ans += [sum(abs(x - b) for x in B_sorted)]", "-print((min(ans)))", "+ t = a[N // 2]", "+ans = sum(abs(aa - t) for aa in a)", "+print(ans)" ]
false
0.096739
0.090426
1.069811
[ "s391011696", "s958113137" ]
u434966508
p03102
python
s089248054
s983562124
74
60
62,052
62,208
Accepted
Accepted
18.92
N,M,C=list(map(int,input().split())) B=list(map(int,input().split())) A=[list(map(int,input().split())) for _ in range(N)] cnt=0 for i in range(N): ans=0 for j in range(M): ans += B[j]*A[i][j] if ans+C>0: cnt+=1 print(cnt)
N,M,C=list(map(int,input().split())) B=list(map(int,input().split())) cnt=0 for i in range(N): am=0 A=list(map(int,input().split())) for j in range(M): am+=B[j]*A[j] if am+C>0: cnt+=1 print(cnt)
13
11
258
230
N, M, C = list(map(int, input().split())) B = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] cnt = 0 for i in range(N): ans = 0 for j in range(M): ans += B[j] * A[i][j] if ans + C > 0: cnt += 1 print(cnt)
N, M, C = list(map(int, input().split())) B = list(map(int, input().split())) cnt = 0 for i in range(N): am = 0 A = list(map(int, input().split())) for j in range(M): am += B[j] * A[j] if am + C > 0: cnt += 1 print(cnt)
false
15.384615
[ "-A = [list(map(int, input().split())) for _ in range(N)]", "- ans = 0", "+ am = 0", "+ A = list(map(int, input().split()))", "- ans += B[j] * A[i][j]", "- if ans + C > 0:", "+ am += B[j] * A[j]", "+ if am + C > 0:" ]
false
0.093643
0.06824
1.372262
[ "s089248054", "s983562124" ]
u145950990
p03145
python
s790647980
s645276892
170
18
38,256
2,940
Accepted
Accepted
89.41
a,b,c = list(map(int,input().split())) print((a*b//2))
a,b,c = sorted(map(int,input().split())) print((a*b//2))
2
2
47
55
a, b, c = list(map(int, input().split())) print((a * b // 2))
a, b, c = sorted(map(int, input().split())) print((a * b // 2))
false
0
[ "-a, b, c = list(map(int, input().split()))", "+a, b, c = sorted(map(int, input().split()))" ]
false
0.088041
0.04313
2.04129
[ "s790647980", "s645276892" ]
u947883560
p02881
python
s694648783
s950311474
293
182
3,440
28,984
Accepted
Accepted
37.88
#!/usr/bin/env python3 import sys INF = float("inf") import math import collections def divisors_kai(n): ret = 1 for i in range(1, int(n ** 0.5) + 1): d, m = divmod(n, i) if m == 0: ret = i # ret.add(d) return ret def solve(N: int): a = divisors_kai(N) b = N/a print((int(a + b - 2))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys import numpy as np import math def solve(N: int): x = np.arange(1, np.sqrt(N)+1, dtype=np.int) div = x[N % x == 0] print(((N/div + div - 2).min().astype(np.int))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == '__main__': main()
38
27
659
506
#!/usr/bin/env python3 import sys INF = float("inf") import math import collections def divisors_kai(n): ret = 1 for i in range(1, int(n**0.5) + 1): d, m = divmod(n, i) if m == 0: ret = i # ret.add(d) return ret def solve(N: int): a = divisors_kai(N) b = N / a print((int(a + b - 2))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys import numpy as np import math def solve(N: int): x = np.arange(1, np.sqrt(N) + 1, dtype=np.int) div = x[N % x == 0] print(((N / div + div - 2).min().astype(np.int))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
false
28.947368
[ "-", "-INF = float(\"inf\")", "+import numpy as np", "-import collections", "-", "-", "-def divisors_kai(n):", "- ret = 1", "- for i in range(1, int(n**0.5) + 1):", "- d, m = divmod(n, i)", "- if m == 0:", "- ret = i", "- # ret.add(d)", "- return ret", "- a = divisors_kai(N)", "- b = N / a", "- print((int(a + b - 2)))", "+ x = np.arange(1, np.sqrt(N) + 1, dtype=np.int)", "+ div = x[N % x == 0]", "+ print(((N / div + div - 2).min().astype(np.int)))" ]
false
0.04476
0.34393
0.130143
[ "s694648783", "s950311474" ]
u894934980
p03162
python
s823480165
s199056850
1,464
704
14,772
31,732
Accepted
Accepted
51.91
import numpy as np N = int(eval(input())) dp = np.zeros((N+1, 3), dtype=int) for i in range(1, N+1): a, b, c = list(map(int, input().split(' '))) dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c print((np.max(dp[-1])))
import numpy as np N = int(eval(input())) dp = [[0, 0, 0] for i in range(N+1)] for i in range(1, N+1): a, b, c = list(map(int, input().split(' '))) dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c print((np.max(dp[-1])))
9
9
314
316
import numpy as np N = int(eval(input())) dp = np.zeros((N + 1, 3), dtype=int) for i in range(1, N + 1): a, b, c = list(map(int, input().split(" "))) dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c print((np.max(dp[-1])))
import numpy as np N = int(eval(input())) dp = [[0, 0, 0] for i in range(N + 1)] for i in range(1, N + 1): a, b, c = list(map(int, input().split(" "))) dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c print((np.max(dp[-1])))
false
0
[ "-dp = np.zeros((N + 1, 3), dtype=int)", "+dp = [[0, 0, 0] for i in range(N + 1)]" ]
false
0.43276
0.276558
1.564809
[ "s823480165", "s199056850" ]
u691018832
p03497
python
s943408187
s688647989
228
114
50,528
34,148
Accepted
Accepted
50
import collections import sys input = sys.stdin.readline n, k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 set_a = set(a) count_a = collections.Counter(a).most_common()[::-1] if len(set_a)-k > 0: for i in range(len(set_a)-k): ans += count_a[i][1] print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import Counter n, k, *a = list(map(int, read().split())) counter = sorted(Counter(a).values()) ans = 0 for i in range(len(counter) - k): ans += counter[i] print(ans)
13
14
309
343
import collections import sys input = sys.stdin.readline n, k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 set_a = set(a) count_a = collections.Counter(a).most_common()[::-1] if len(set_a) - k > 0: for i in range(len(set_a) - k): ans += count_a[i][1] print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import Counter n, k, *a = list(map(int, read().split())) counter = sorted(Counter(a).values()) ans = 0 for i in range(len(counter) - k): ans += counter[i] print(ans)
false
7.142857
[ "-import collections", "-input = sys.stdin.readline", "-n, k = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+sys.setrecursionlimit(10**7)", "+from collections import Counter", "+", "+n, k, *a = list(map(int, read().split()))", "+counter = sorted(Counter(a).values())", "-set_a = set(a)", "-count_a = collections.Counter(a).most_common()[::-1]", "-if len(set_a) - k > 0:", "- for i in range(len(set_a) - k):", "- ans += count_a[i][1]", "+for i in range(len(counter) - k):", "+ ans += counter[i]" ]
false
0.0366
0.079587
0.459868
[ "s943408187", "s688647989" ]
u867320886
p03798
python
s537811383
s021155026
342
242
5,620
3,444
Accepted
Accepted
29.24
def get_next(sw_prev2,sw_prev1,ox_prev1): rev_ox = {"o":"x", "x":"o"} rev_sw = {"S":"W", "W":"S"} sw = sw_prev2 if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1] if ox_prev1 == "x": sw = rev_sw[sw] return sw n = int(eval(input())) ox = eval(input()) ans = [None] * (n+2) for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]: ans[0] = sw0 ans[1] = sw1 for i,oxi in enumerate(ox[1:]+ox[0],1): ans[i+1] = get_next(ans[i-1],ans[i],oxi) if ans[0] == ans[-2] and ans[1] == ans[-1]: break else: ans = [-1] print(("".join(map(str,ans[:n]))))
rev_ox = {"o":"x", "x":"o"} rev_sw = {"S":"W", "W":"S"} def get_next(sw_prev2,sw_prev1,ox_prev1): sw = sw_prev2 if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1] if ox_prev1 == "x": sw = rev_sw[sw] return sw n = int(eval(input())) ox = eval(input()) for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]: ans = "" ans = sw0+sw1 for i,oxi in enumerate(ox[1:]+ox[0],1): ans += get_next(ans[i-1],ans[i],oxi) if ans[0] == ans[-2] and ans[1] == ans[-1]: ans = ans[:-2] break else: ans = -1 print(ans)
29
27
643
593
def get_next(sw_prev2, sw_prev1, ox_prev1): rev_ox = {"o": "x", "x": "o"} rev_sw = {"S": "W", "W": "S"} sw = sw_prev2 if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1] if ox_prev1 == "x": sw = rev_sw[sw] return sw n = int(eval(input())) ox = eval(input()) ans = [None] * (n + 2) for sw0, sw1 in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")]: ans[0] = sw0 ans[1] = sw1 for i, oxi in enumerate(ox[1:] + ox[0], 1): ans[i + 1] = get_next(ans[i - 1], ans[i], oxi) if ans[0] == ans[-2] and ans[1] == ans[-1]: break else: ans = [-1] print(("".join(map(str, ans[:n]))))
rev_ox = {"o": "x", "x": "o"} rev_sw = {"S": "W", "W": "S"} def get_next(sw_prev2, sw_prev1, ox_prev1): sw = sw_prev2 if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1] if ox_prev1 == "x": sw = rev_sw[sw] return sw n = int(eval(input())) ox = eval(input()) for sw0, sw1 in [("S", "S"), ("S", "W"), ("W", "S"), ("W", "W")]: ans = "" ans = sw0 + sw1 for i, oxi in enumerate(ox[1:] + ox[0], 1): ans += get_next(ans[i - 1], ans[i], oxi) if ans[0] == ans[-2] and ans[1] == ans[-1]: ans = ans[:-2] break else: ans = -1 print(ans)
false
6.896552
[ "+rev_ox = {\"o\": \"x\", \"x\": \"o\"}", "+rev_sw = {\"S\": \"W\", \"W\": \"S\"}", "+", "+", "- rev_ox = {\"o\": \"x\", \"x\": \"o\"}", "- rev_sw = {\"S\": \"W\", \"W\": \"S\"}", "-ans = [None] * (n + 2)", "- ans[0] = sw0", "- ans[1] = sw1", "+ ans = \"\"", "+ ans = sw0 + sw1", "- ans[i + 1] = get_next(ans[i - 1], ans[i], oxi)", "+ ans += get_next(ans[i - 1], ans[i], oxi)", "+ ans = ans[:-2]", "- ans = [-1]", "-print((\"\".join(map(str, ans[:n]))))", "+ ans = -1", "+print(ans)" ]
false
0.077468
0.082295
0.941352
[ "s537811383", "s021155026" ]
u767664985
p03262
python
s762679822
s657377772
107
98
16,280
16,240
Accepted
Accepted
8.41
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) y = list([abs(X - i) for i in x]) ans = y[0] for i in range(1, N): ans = gcd(ans, y[i]) print(ans)
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) ans = abs(x[0] - X) for i in range(1, N): ans = gcd(ans, abs(x[i] - X)) print(ans)
9
10
209
194
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) y = list([abs(X - i) for i in x]) ans = y[0] for i in range(1, N): ans = gcd(ans, y[i]) print(ans)
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) ans = abs(x[0] - X) for i in range(1, N): ans = gcd(ans, abs(x[i] - X)) print(ans)
false
10
[ "-y = list([abs(X - i) for i in x])", "-ans = y[0]", "+ans = abs(x[0] - X)", "- ans = gcd(ans, y[i])", "+ ans = gcd(ans, abs(x[i] - X))" ]
false
0.043884
0.043091
1.018409
[ "s762679822", "s657377772" ]
u389910364
p03221
python
s330656930
s020718459
700
632
68,976
69,056
Accepted
Accepted
9.71
import bisect import operator import os from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") N, M = list(map(int, sys.stdin.readline().split())) P, Y = list(zip(*[list(map(int, sys.stdin.readline().split())) for _ in range(M)])) P = np.array(P) Y = np.array(Y) order = np.lexsort((Y, P)) P = P[order] Y = Y[order] ans = [] cnt = 1 prev = None for p, y in zip(P, Y): if p == prev: cnt += 1 else: cnt = 1 ans.append('{:06d}{:06d}'.format(p, cnt)) prev = p print(('\n'.join(map(str, np.array(ans)[order.argsort()]))))
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = list(map(int, sys.stdin.readline().split())) P, Y = list(zip(*[list(map(int, sys.stdin.readline().split())) for _ in range(M)])) nums = defaultdict(int) ans = [''] * M for i in np.lexsort((Y, P)): nums[P[i]] += 1 ans[i] = '{:06d}{:06d}'.format(P[i], nums[P[i]]) print(('\n'.join(map(str, ans))))
41
33
869
785
import bisect import operator import os from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") N, M = list(map(int, sys.stdin.readline().split())) P, Y = list(zip(*[list(map(int, sys.stdin.readline().split())) for _ in range(M)])) P = np.array(P) Y = np.array(Y) order = np.lexsort((Y, P)) P = P[order] Y = Y[order] ans = [] cnt = 1 prev = None for p, y in zip(P, Y): if p == prev: cnt += 1 else: cnt = 1 ans.append("{:06d}{:06d}".format(p, cnt)) prev = p print(("\n".join(map(str, np.array(ans)[order.argsort()]))))
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 N, M = list(map(int, sys.stdin.readline().split())) P, Y = list(zip(*[list(map(int, sys.stdin.readline().split())) for _ in range(M)])) nums = defaultdict(int) ans = [""] * M for i in np.lexsort((Y, P)): nums[P[i]] += 1 ans[i] = "{:06d}{:06d}".format(P[i], nums[P[i]]) print(("\n".join(map(str, ans))))
false
19.512195
[ "-import operator", "-import os", "-from collections import Counter, deque", "-from fractions import gcd", "-from functools import lru_cache", "-from functools import reduce", "-import functools", "+import os", "+import re", "+import string", "+import sys", "+from collections import Counter, deque, defaultdict", "+from decimal import Decimal", "+from fractions import gcd", "+from functools import lru_cache, reduce", "+from operator import itemgetter", "-import re", "-import sys", "+IINF = 10**18", "+MOD = 10**9 + 7", "-P = np.array(P)", "-Y = np.array(Y)", "-order = np.lexsort((Y, P))", "-P = P[order]", "-Y = Y[order]", "-ans = []", "-cnt = 1", "-prev = None", "-for p, y in zip(P, Y):", "- if p == prev:", "- cnt += 1", "- else:", "- cnt = 1", "- ans.append(\"{:06d}{:06d}\".format(p, cnt))", "- prev = p", "-print((\"\\n\".join(map(str, np.array(ans)[order.argsort()]))))", "+nums = defaultdict(int)", "+ans = [\"\"] * M", "+for i in np.lexsort((Y, P)):", "+ nums[P[i]] += 1", "+ ans[i] = \"{:06d}{:06d}\".format(P[i], nums[P[i]])", "+print((\"\\n\".join(map(str, ans))))" ]
false
0.485688
0.726445
0.668582
[ "s330656930", "s020718459" ]
u936985471
p03796
python
s982046140
s116965933
47
41
2,940
2,940
Accepted
Accepted
12.77
N=int(eval(input())) ans=1 DIV=10**9+7 while N>1: ans=(ans*(N%DIV))%DIV N-=1 print(ans)
N=int(eval(input())) p=1 DIV=10**9+7 for i in range(1,N+1): p = (p%DIV * i%DIV) % DIV print(p)
7
7
91
99
N = int(eval(input())) ans = 1 DIV = 10**9 + 7 while N > 1: ans = (ans * (N % DIV)) % DIV N -= 1 print(ans)
N = int(eval(input())) p = 1 DIV = 10**9 + 7 for i in range(1, N + 1): p = (p % DIV * i % DIV) % DIV print(p)
false
0
[ "-ans = 1", "+p = 1", "-while N > 1:", "- ans = (ans * (N % DIV)) % DIV", "- N -= 1", "-print(ans)", "+for i in range(1, N + 1):", "+ p = (p % DIV * i % DIV) % DIV", "+print(p)" ]
false
0.052859
0.052304
1.010612
[ "s982046140", "s116965933" ]
u816631826
p03325
python
s095614769
s717522174
76
56
3,460
33,132
Accepted
Accepted
26.32
n = int(input()) m = list(map(int, input().split())) total = 0 for i in range(n): x = m[i] while True: if x % 2 == 1: break total += 1 x = x // 2 print(total)
def meu_map(l): for i in range(len(l)): l[i] = int(l[i]) n = int(input()) array = input().split() meu_map(array) fatores = 0 for e in array: while e != 1: if e % 2 == 0: e /= 2 fatores += 1 else: break print(fatores)
12
20
222
316
n = int(input()) m = list(map(int, input().split())) total = 0 for i in range(n): x = m[i] while True: if x % 2 == 1: break total += 1 x = x // 2 print(total)
def meu_map(l): for i in range(len(l)): l[i] = int(l[i]) n = int(input()) array = input().split() meu_map(array) fatores = 0 for e in array: while e != 1: if e % 2 == 0: e /= 2 fatores += 1 else: break print(fatores)
false
40
[ "+def meu_map(l):", "+ for i in range(len(l)):", "+ l[i] = int(l[i])", "+", "+", "-m = list(map(int, input().split()))", "-total = 0", "-for i in range(n):", "- x = m[i]", "- while True:", "- if x % 2 == 1:", "+array = input().split()", "+meu_map(array)", "+fatores = 0", "+for e in array:", "+ while e != 1:", "+ if e % 2 == 0:", "+ e /= 2", "+ fatores += 1", "+ else:", "- total += 1", "- x = x // 2", "-print(total)", "+print(fatores)" ]
false
0.034876
0.035037
0.995398
[ "s095614769", "s717522174" ]
u290563917
p03106
python
s992295196
s432304551
175
66
38,384
61,848
Accepted
Accepted
62.29
a, b, k = list(map(int, input().split())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors a_divs = make_divisors(a) b_divs = make_divisors(b) common_divs = [] for i in range(len(a_divs)): a_div = a_divs[i] if a_div in b_divs: common_divs.append(a_div) print((common_divs[-k]))
a, b, k = list(map(int, input().split())) m = b if a > b else a ans = [] for i in range(1, m+1): if a % i == 0 and b % i == 0: ans.append(i) print((ans[-k]))
21
7
459
161
a, b, k = list(map(int, input().split())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors a_divs = make_divisors(a) b_divs = make_divisors(b) common_divs = [] for i in range(len(a_divs)): a_div = a_divs[i] if a_div in b_divs: common_divs.append(a_div) print((common_divs[-k]))
a, b, k = list(map(int, input().split())) m = b if a > b else a ans = [] for i in range(1, m + 1): if a % i == 0 and b % i == 0: ans.append(i) print((ans[-k]))
false
66.666667
[ "-", "-", "-def make_divisors(n):", "- divisors = []", "- for i in range(1, int(n**0.5) + 1):", "- if n % i == 0:", "- divisors.append(i)", "- if i != n // i:", "- divisors.append(n // i)", "- divisors.sort()", "- return divisors", "-", "-", "-a_divs = make_divisors(a)", "-b_divs = make_divisors(b)", "-common_divs = []", "-for i in range(len(a_divs)):", "- a_div = a_divs[i]", "- if a_div in b_divs:", "- common_divs.append(a_div)", "-print((common_divs[-k]))", "+m = b if a > b else a", "+ans = []", "+for i in range(1, m + 1):", "+ if a % i == 0 and b % i == 0:", "+ ans.append(i)", "+print((ans[-k]))" ]
false
0.064333
0.066155
0.972457
[ "s992295196", "s432304551" ]
u046158516
p03610
python
s129088710
s043513512
1,064
181
133,912
42,224
Accepted
Accepted
82.99
s=eval(input()) a=[] def convert(s): # initialization of string to "" new = "" # traverse in the string for x in s: new += x # return string return new for i in range(len(s)): if i%2==0: a.append(s[i]) print((convert(a)))
s=eval(input()) ans=[] for i in range(len(s)): if i%2==0: ans.append(s[i]) print((''.join(ans)))
18
6
291
99
s = eval(input()) a = [] def convert(s): # initialization of string to "" new = "" # traverse in the string for x in s: new += x # return string return new for i in range(len(s)): if i % 2 == 0: a.append(s[i]) print((convert(a)))
s = eval(input()) ans = [] for i in range(len(s)): if i % 2 == 0: ans.append(s[i]) print(("".join(ans)))
false
66.666667
[ "-a = []", "-", "-", "-def convert(s):", "- # initialization of string to \"\"", "- new = \"\"", "- # traverse in the string", "- for x in s:", "- new += x", "- # return string", "- return new", "-", "-", "+ans = []", "- a.append(s[i])", "-print((convert(a)))", "+ ans.append(s[i])", "+print((\"\".join(ans)))" ]
false
0.038409
0.039037
0.983914
[ "s129088710", "s043513512" ]
u072717685
p02678
python
s977940732
s462554673
1,599
702
110,420
44,264
Accepted
Accepted
56.1
from copy import deepcopy def main(): global flags, edges n, m = list(map(int, input().split())) flags = {e:[n+1, n+1] for e in range(1, n + 1)} flags[1][1] = 0 edges = {e:set() for e in range(1, n + 1)} edge_list = [] for _ in range(m): a, b = list(map(int, input().split())) edges[a].add(b) edges[b].add(a) edge_list.append((a, b)) distance = 1 node_next = list(edges[1]) node_next_next = [] while node_next: for next in node_next: if flags[next][1] > distance: flags[next][1] = distance node_next_next += edges[next] node_next = deepcopy(node_next_next) node_next_next = [] distance += 1 for edge in edge_list: e1 = edge[0] e2 = edge[1] if flags[e1][1] == flags[e2][1]: pass elif flags[e1][1] > flags[e2][1]: flags[e1][0] = min(flags[e1][0], e2) else: flags[e2][0] = min(flags[e2][0], e1) result = [flags[f][1] < (n + 1) for f in flags if f > 1] if not all(result): print('No') else: print('Yes') for i1 in range(2, n + 1): print((flags[i1][0])) if __name__ == '__main__': main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import deque from copy import deepcopy def main(): n, m = map(int, input().split()) edges = {e:[] for e in range(n + 1)} for _ in range(m): a, b = map(int, input().split()) edges[a].append(b) edges[b].append(a) res = [0] * (n + 1) dist = 1 distroom = [n + 1] * (n + 1) distroom[1] = 0 q1 = deque() q2 = deque() q1.append(1) while q1: for q1e in q1: for adj in edges[q1e]: if distroom[adj] > dist: res[adj] = q1e distroom[adj] = dist q2.append(adj) dist += 1 q1 = deepcopy(q2) q2 = deque() print('Yes') print(*res[2:],sep='\n') if __name__ == '__main__': main()
45
35
1,312
878
from copy import deepcopy def main(): global flags, edges n, m = list(map(int, input().split())) flags = {e: [n + 1, n + 1] for e in range(1, n + 1)} flags[1][1] = 0 edges = {e: set() for e in range(1, n + 1)} edge_list = [] for _ in range(m): a, b = list(map(int, input().split())) edges[a].add(b) edges[b].add(a) edge_list.append((a, b)) distance = 1 node_next = list(edges[1]) node_next_next = [] while node_next: for next in node_next: if flags[next][1] > distance: flags[next][1] = distance node_next_next += edges[next] node_next = deepcopy(node_next_next) node_next_next = [] distance += 1 for edge in edge_list: e1 = edge[0] e2 = edge[1] if flags[e1][1] == flags[e2][1]: pass elif flags[e1][1] > flags[e2][1]: flags[e1][0] = min(flags[e1][0], e2) else: flags[e2][0] = min(flags[e2][0], e1) result = [flags[f][1] < (n + 1) for f in flags if f > 1] if not all(result): print("No") else: print("Yes") for i1 in range(2, n + 1): print((flags[i1][0])) if __name__ == "__main__": main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import deque from copy import deepcopy def main(): n, m = map(int, input().split()) edges = {e: [] for e in range(n + 1)} for _ in range(m): a, b = map(int, input().split()) edges[a].append(b) edges[b].append(a) res = [0] * (n + 1) dist = 1 distroom = [n + 1] * (n + 1) distroom[1] = 0 q1 = deque() q2 = deque() q1.append(1) while q1: for q1e in q1: for adj in edges[q1e]: if distroom[adj] > dist: res[adj] = q1e distroom[adj] = dist q2.append(adj) dist += 1 q1 = deepcopy(q2) q2 = deque() print("Yes") print(*res[2:], sep="\n") if __name__ == "__main__": main()
false
22.222222
[ "+import sys", "+", "+read = sys.stdin.read", "+readlines = sys.stdin.readlines", "+from collections import deque", "- global flags, edges", "- n, m = list(map(int, input().split()))", "- flags = {e: [n + 1, n + 1] for e in range(1, n + 1)}", "- flags[1][1] = 0", "- edges = {e: set() for e in range(1, n + 1)}", "- edge_list = []", "+ n, m = map(int, input().split())", "+ edges = {e: [] for e in range(n + 1)}", "- a, b = list(map(int, input().split()))", "- edges[a].add(b)", "- edges[b].add(a)", "- edge_list.append((a, b))", "- distance = 1", "- node_next = list(edges[1])", "- node_next_next = []", "- while node_next:", "- for next in node_next:", "- if flags[next][1] > distance:", "- flags[next][1] = distance", "- node_next_next += edges[next]", "- node_next = deepcopy(node_next_next)", "- node_next_next = []", "- distance += 1", "- for edge in edge_list:", "- e1 = edge[0]", "- e2 = edge[1]", "- if flags[e1][1] == flags[e2][1]:", "- pass", "- elif flags[e1][1] > flags[e2][1]:", "- flags[e1][0] = min(flags[e1][0], e2)", "- else:", "- flags[e2][0] = min(flags[e2][0], e1)", "- result = [flags[f][1] < (n + 1) for f in flags if f > 1]", "- if not all(result):", "- print(\"No\")", "- else:", "- print(\"Yes\")", "- for i1 in range(2, n + 1):", "- print((flags[i1][0]))", "+ a, b = map(int, input().split())", "+ edges[a].append(b)", "+ edges[b].append(a)", "+ res = [0] * (n + 1)", "+ dist = 1", "+ distroom = [n + 1] * (n + 1)", "+ distroom[1] = 0", "+ q1 = deque()", "+ q2 = deque()", "+ q1.append(1)", "+ while q1:", "+ for q1e in q1:", "+ for adj in edges[q1e]:", "+ if distroom[adj] > dist:", "+ res[adj] = q1e", "+ distroom[adj] = dist", "+ q2.append(adj)", "+ dist += 1", "+ q1 = deepcopy(q2)", "+ q2 = deque()", "+ print(\"Yes\")", "+ print(*res[2:], sep=\"\\n\")" ]
false
0.049637
0.03849
1.289621
[ "s977940732", "s462554673" ]
u058240079
p03557
python
s714860079
s643680102
352
300
24,024
17,708
Accepted
Accepted
14.77
n = int(input()) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al.sort() bl.sort() cl.sort() l = [(0,0) for _ in range(n)] p = 0 for i, b in enumerate(bl): while p < n and cl[p] <= b: p += 1 l[i] = (b, n-p) p = n-1 s = 0 t = 0 for a in al[::-1]: while p >= 0 and l[p][0] > a: s += l[p][1] p -= 1 t += s print(t)
n = int(input()) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al.sort() bl.sort() cl.sort() ap = 0 cp = 0 t = 0 for b in bl: while ap < n and al[ap] < b: ap += 1 while cp < n and cl[cp] <= b: cp += 1 t += ap * (n - cp) print(t)
22
17
435
335
n = int(input()) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al.sort() bl.sort() cl.sort() l = [(0, 0) for _ in range(n)] p = 0 for i, b in enumerate(bl): while p < n and cl[p] <= b: p += 1 l[i] = (b, n - p) p = n - 1 s = 0 t = 0 for a in al[::-1]: while p >= 0 and l[p][0] > a: s += l[p][1] p -= 1 t += s print(t)
n = int(input()) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al.sort() bl.sort() cl.sort() ap = 0 cp = 0 t = 0 for b in bl: while ap < n and al[ap] < b: ap += 1 while cp < n and cl[cp] <= b: cp += 1 t += ap * (n - cp) print(t)
false
22.727273
[ "-l = [(0, 0) for _ in range(n)]", "-p = 0", "-for i, b in enumerate(bl):", "- while p < n and cl[p] <= b:", "- p += 1", "- l[i] = (b, n - p)", "-p = n - 1", "-s = 0", "+ap = 0", "+cp = 0", "-for a in al[::-1]:", "- while p >= 0 and l[p][0] > a:", "- s += l[p][1]", "- p -= 1", "- t += s", "+for b in bl:", "+ while ap < n and al[ap] < b:", "+ ap += 1", "+ while cp < n and cl[cp] <= b:", "+ cp += 1", "+ t += ap * (n - cp)" ]
false
0.038675
0.038384
1.007583
[ "s714860079", "s643680102" ]
u312025627
p02714
python
s857295388
s577637206
219
176
74,156
68,196
Accepted
Accepted
19.63
def main(): N = int(input()) S = input() from collections import Counter c = Counter(S) ans = c["R"]*c["G"]*c["B"] less = 0 for d in range(1, N+1): for i in range(N): # 差dで三つが異なるなら条件を満たさないので取り除く if i+d < N and i+2*d < N and \ S[i] != S[i+d] and S[i] != S[i+2*d] and S[i+d] != S[i+2*d]: less += 1 print(ans - less) if __name__ == '__main__': main()
def main(): N = int(eval(input())) S = eval(input()) RGB = [0]*3 for s in S: if s == "R": RGB[0] += 1 elif s == "G": RGB[1] += 1 else: RGB[2] += 1 ans = RGB[0] * RGB[1] * RGB[2] for d in range(1, N): for i in range(N-d+1): if N <= i + 2*d: break if S[i] != S[i+d] and S[i] != S[i+2*d] and S[i+d] != S[i+2*d]: ans -= 1 print(ans) if __name__ == '__main__': main()
18
23
471
531
def main(): N = int(input()) S = input() from collections import Counter c = Counter(S) ans = c["R"] * c["G"] * c["B"] less = 0 for d in range(1, N + 1): for i in range(N): # 差dで三つが異なるなら条件を満たさないので取り除く if ( i + d < N and i + 2 * d < N and S[i] != S[i + d] and S[i] != S[i + 2 * d] and S[i + d] != S[i + 2 * d] ): less += 1 print(ans - less) if __name__ == "__main__": main()
def main(): N = int(eval(input())) S = eval(input()) RGB = [0] * 3 for s in S: if s == "R": RGB[0] += 1 elif s == "G": RGB[1] += 1 else: RGB[2] += 1 ans = RGB[0] * RGB[1] * RGB[2] for d in range(1, N): for i in range(N - d + 1): if N <= i + 2 * d: break if S[i] != S[i + d] and S[i] != S[i + 2 * d] and S[i + d] != S[i + 2 * d]: ans -= 1 print(ans) if __name__ == "__main__": main()
false
21.73913
[ "- N = int(input())", "- S = input()", "- from collections import Counter", "-", "- c = Counter(S)", "- ans = c[\"R\"] * c[\"G\"] * c[\"B\"]", "- less = 0", "- for d in range(1, N + 1):", "- for i in range(N):", "- # 差dで三つが異なるなら条件を満たさないので取り除く", "- if (", "- i + d < N", "- and i + 2 * d < N", "- and S[i] != S[i + d]", "- and S[i] != S[i + 2 * d]", "- and S[i + d] != S[i + 2 * d]", "- ):", "- less += 1", "- print(ans - less)", "+ N = int(eval(input()))", "+ S = eval(input())", "+ RGB = [0] * 3", "+ for s in S:", "+ if s == \"R\":", "+ RGB[0] += 1", "+ elif s == \"G\":", "+ RGB[1] += 1", "+ else:", "+ RGB[2] += 1", "+ ans = RGB[0] * RGB[1] * RGB[2]", "+ for d in range(1, N):", "+ for i in range(N - d + 1):", "+ if N <= i + 2 * d:", "+ break", "+ if S[i] != S[i + d] and S[i] != S[i + 2 * d] and S[i + d] != S[i + 2 * d]:", "+ ans -= 1", "+ print(ans)" ]
false
0.039107
0.041276
0.947433
[ "s857295388", "s577637206" ]
u002459665
p03835
python
s511720936
s284354670
1,852
1,578
2,940
2,940
Accepted
Accepted
14.79
K, S = list(map(int, input().split())) ans = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if z >= 0 and z <= K: ans += 1 print(ans)
K, S = list(map(int, input().split())) cnt = 0 for i in range(K+1): for j in range(K+1): x = S - i - j if 0 <= x <= K: cnt += 1 print(cnt)
10
9
186
174
K, S = list(map(int, input().split())) ans = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if z >= 0 and z <= K: ans += 1 print(ans)
K, S = list(map(int, input().split())) cnt = 0 for i in range(K + 1): for j in range(K + 1): x = S - i - j if 0 <= x <= K: cnt += 1 print(cnt)
false
10
[ "-ans = 0", "-for x in range(K + 1):", "- for y in range(K + 1):", "- z = S - x - y", "- if z >= 0 and z <= K:", "- ans += 1", "-print(ans)", "+cnt = 0", "+for i in range(K + 1):", "+ for j in range(K + 1):", "+ x = S - i - j", "+ if 0 <= x <= K:", "+ cnt += 1", "+print(cnt)" ]
false
0.05049
0.047518
1.062536
[ "s511720936", "s284354670" ]
u185486509
p02258
python
s609194344
s139783183
890
210
13,584
19,828
Accepted
Accepted
76.4
N =int(eval(input())) R = [] for i in range(N): R.append(int(eval(input()))) maxv=-2000000000 minv=R[0] for i in range(1,N): maxv=max(maxv,R[i]-minv) minv=min(minv,R[i]) print(maxv)
import sys i=input n =int(i()) r0=int(i()) r1=int(i()) maxv=r1-r0 minv=min(r1,r0) for i in map(int,sys.stdin.readlines()): maxv=max(maxv,i-minv) minv=min(minv,i) print(maxv)
10
11
194
191
N = int(eval(input())) R = [] for i in range(N): R.append(int(eval(input()))) maxv = -2000000000 minv = R[0] for i in range(1, N): maxv = max(maxv, R[i] - minv) minv = min(minv, R[i]) print(maxv)
import sys i = input n = int(i()) r0 = int(i()) r1 = int(i()) maxv = r1 - r0 minv = min(r1, r0) for i in map(int, sys.stdin.readlines()): maxv = max(maxv, i - minv) minv = min(minv, i) print(maxv)
false
9.090909
[ "-N = int(eval(input()))", "-R = []", "-for i in range(N):", "- R.append(int(eval(input())))", "-maxv = -2000000000", "-minv = R[0]", "-for i in range(1, N):", "- maxv = max(maxv, R[i] - minv)", "- minv = min(minv, R[i])", "+import sys", "+", "+i = input", "+n = int(i())", "+r0 = int(i())", "+r1 = int(i())", "+maxv = r1 - r0", "+minv = min(r1, r0)", "+for i in map(int, sys.stdin.readlines()):", "+ maxv = max(maxv, i - minv)", "+ minv = min(minv, i)" ]
false
0.04047
0.044637
0.906645
[ "s609194344", "s139783183" ]
u743383679
p03457
python
s513064516
s916899402
305
252
22,580
9,128
Accepted
Accepted
17.38
# coding: utf-8 import math n = int(eval(input())) t = 0 x = 0 y = 0 txy = [] for i in range(n): ti, xi, yi = list(map(int, input().split())) txy.append((ti, xi, yi)) for ti, xi, yi in txy: if abs(xi - x) + abs(yi - y) > abs(ti - t): print("No") exit() elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0: print("No") exit() else: t = ti x = xi y = yi print("Yes")
# coding: utf-8 import math n = int(eval(input())) t = 0 x = 0 y = 0 # txy = [] # for i in range(n): # ti, xi, yi = list(map(int, input().split())) # txy.append((ti, xi, yi)) for i in range(n): ti, xi, yi = list(map(int, input().split())) if abs(xi - x) + abs(yi - y) > abs(ti - t): print("No") exit() elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0: print("No") exit() else: t = ti x = xi y = yi print("Yes")
23
23
462
508
# coding: utf-8 import math n = int(eval(input())) t = 0 x = 0 y = 0 txy = [] for i in range(n): ti, xi, yi = list(map(int, input().split())) txy.append((ti, xi, yi)) for ti, xi, yi in txy: if abs(xi - x) + abs(yi - y) > abs(ti - t): print("No") exit() elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0: print("No") exit() else: t = ti x = xi y = yi print("Yes")
# coding: utf-8 import math n = int(eval(input())) t = 0 x = 0 y = 0 # txy = [] # for i in range(n): # ti, xi, yi = list(map(int, input().split())) # txy.append((ti, xi, yi)) for i in range(n): ti, xi, yi = list(map(int, input().split())) if abs(xi - x) + abs(yi - y) > abs(ti - t): print("No") exit() elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0: print("No") exit() else: t = ti x = xi y = yi print("Yes")
false
0
[ "-txy = []", "+# txy = []", "+# for i in range(n):", "+# ti, xi, yi = list(map(int, input().split()))", "+# txy.append((ti, xi, yi))", "- txy.append((ti, xi, yi))", "-for ti, xi, yi in txy:" ]
false
0.048138
0.057671
0.834699
[ "s513064516", "s916899402" ]
u186838327
p03457
python
s335507635
s331994699
536
377
44,904
3,064
Accepted
Accepted
29.66
n = int(eval(input())) t0 = 0 x0 = 0 y0 = 0 for i in range(n): t, x, y = list(map(int, input().split())) if (x-x0)+(y-y0) <= t-t0 and(t-t0)%2 == ((x-x0)+(y-y0))%2: t0 = t x0 = x y0 = y else: print('No') exit() else: print('Yes')
n = int(eval(input())) t_ = 0 x_ = 0 y_ = 0 for i in range(n): t, x, y = list(map(int, input().split())) if abs(x-x_)+abs(y-y_) > t-t_: print('No') exit() else: r = (t-t_) - abs(x-x_)-abs(y-y_) if r%2 == 0: t_ = t x_ = x y_ = y else: print('No') exit() else: print('Yes')
18
20
266
394
n = int(eval(input())) t0 = 0 x0 = 0 y0 = 0 for i in range(n): t, x, y = list(map(int, input().split())) if (x - x0) + (y - y0) <= t - t0 and (t - t0) % 2 == ((x - x0) + (y - y0)) % 2: t0 = t x0 = x y0 = y else: print("No") exit() else: print("Yes")
n = int(eval(input())) t_ = 0 x_ = 0 y_ = 0 for i in range(n): t, x, y = list(map(int, input().split())) if abs(x - x_) + abs(y - y_) > t - t_: print("No") exit() else: r = (t - t_) - abs(x - x_) - abs(y - y_) if r % 2 == 0: t_ = t x_ = x y_ = y else: print("No") exit() else: print("Yes")
false
10
[ "-t0 = 0", "-x0 = 0", "-y0 = 0", "+t_ = 0", "+x_ = 0", "+y_ = 0", "- if (x - x0) + (y - y0) <= t - t0 and (t - t0) % 2 == ((x - x0) + (y - y0)) % 2:", "- t0 = t", "- x0 = x", "- y0 = y", "- else:", "+ if abs(x - x_) + abs(y - y_) > t - t_:", "+ else:", "+ r = (t - t_) - abs(x - x_) - abs(y - y_)", "+ if r % 2 == 0:", "+ t_ = t", "+ x_ = x", "+ y_ = y", "+ else:", "+ print(\"No\")", "+ exit()" ]
false
0.074132
0.07705
0.962134
[ "s335507635", "s331994699" ]
u141610915
p03305
python
s015345635
s832165292
1,996
1,838
143,364
132,336
Accepted
Accepted
7.92
import sys from collections import defaultdict as dd import heapq input = sys.stdin.readline n, m, s, t = list(map(int, input().split())) e = dd(list) money = 10 ** 15 for _ in range(m): u, v, a, b = list(map(int, input().split())) e[u].append((v, a)) e[v].append((u, a)) e[u + n].append((v + n, b)) e[v + n].append((u + n, b)) """ for i in range(1, n + 1): e[i].append((i + n, 0)) """ class dijkstra: def __init__(self, n, e): self.e = e self.n = n def path(self, s, t): d = [float("inf")] * (self.n + 1) vis = set() d[s] = 0 h = [s] while not t in vis and len(h): v = heapq.heappop(h) v1 = v % (10 ** 15) v0 = v // (10 ** 15) if v1 in vis: continue vis.add(v1) for p in self.e[v1]: d[p[0]] = min(d[p[0]], d[v1] + p[1]) if p[0] in vis: continue heapq.heappush(h, d[p[0]] * (10 ** 15) + p[0]) return d d = dijkstra(2 * n + 1, e) x = d.path(s, 2 * n + 1) y = d.path(t + n, 2 * n + 1) #print(x) #print(y) paths = [float("inf")] * (n + 1) minpaths = [float("inf")] * (n + 1) for i in range(1, n + 1): paths[i] = x[i] + y[n + i] #print(paths) minpaths[-1] = paths[-1] for i in range(n - 1, -1, -1): minpaths[i] = min(minpaths[i + 1], paths[i]) #print(minpaths) for i in range(1, n + 1): print((money - minpaths[i]))
import sys from collections import defaultdict as dd input = sys.stdin.readline N, M, s, t = list(map(int, input().split())) e = dd(list) ee = dd(list) for i in range(M): u, v, a, b = list(map(int, input().split())) e[u].append((v, a)) e[v].append((u, a)) ee[u].append((v, b)) ee[v].append((u, b)) import heapq class dijkstra: def __init__(self, n, e): self.e = e self.n = n def path(self, s, t): d = [float("inf")] * (self.n + 1) vis = set() d[s] = 0 h = [s] while not t in vis and len(h): v = heapq.heappop(h) v1 = v % (10 ** 10) v0 = v // (10 ** 10) if v1 in vis: continue vis.add(v1) for p in self.e[v1]: d[p[0]] = min(d[p[0]], d[v1] + p[1]) if p[0] in vis: continue heapq.heappush(h, d[p[0]] * (10 ** 10) + p[0]) return d dij = dijkstra(N, e) edij = dijkstra(N, ee) p = dij.path(s, 0) revp = edij.path(t, 0) mny = pow(10, 15) table = [0] * (N + 1) for x in range(1, N + 1): table[x] = mny - p[x] - revp[x] csmx = [0] * (N + 1) for i in range(N, 0, -1): csmx[i - 1] = max(csmx[i - 1], table[i], csmx[i]) for i in range(N): print((csmx[i]))
53
46
1,363
1,184
import sys from collections import defaultdict as dd import heapq input = sys.stdin.readline n, m, s, t = list(map(int, input().split())) e = dd(list) money = 10**15 for _ in range(m): u, v, a, b = list(map(int, input().split())) e[u].append((v, a)) e[v].append((u, a)) e[u + n].append((v + n, b)) e[v + n].append((u + n, b)) """ for i in range(1, n + 1): e[i].append((i + n, 0)) """ class dijkstra: def __init__(self, n, e): self.e = e self.n = n def path(self, s, t): d = [float("inf")] * (self.n + 1) vis = set() d[s] = 0 h = [s] while not t in vis and len(h): v = heapq.heappop(h) v1 = v % (10**15) v0 = v // (10**15) if v1 in vis: continue vis.add(v1) for p in self.e[v1]: d[p[0]] = min(d[p[0]], d[v1] + p[1]) if p[0] in vis: continue heapq.heappush(h, d[p[0]] * (10**15) + p[0]) return d d = dijkstra(2 * n + 1, e) x = d.path(s, 2 * n + 1) y = d.path(t + n, 2 * n + 1) # print(x) # print(y) paths = [float("inf")] * (n + 1) minpaths = [float("inf")] * (n + 1) for i in range(1, n + 1): paths[i] = x[i] + y[n + i] # print(paths) minpaths[-1] = paths[-1] for i in range(n - 1, -1, -1): minpaths[i] = min(minpaths[i + 1], paths[i]) # print(minpaths) for i in range(1, n + 1): print((money - minpaths[i]))
import sys from collections import defaultdict as dd input = sys.stdin.readline N, M, s, t = list(map(int, input().split())) e = dd(list) ee = dd(list) for i in range(M): u, v, a, b = list(map(int, input().split())) e[u].append((v, a)) e[v].append((u, a)) ee[u].append((v, b)) ee[v].append((u, b)) import heapq class dijkstra: def __init__(self, n, e): self.e = e self.n = n def path(self, s, t): d = [float("inf")] * (self.n + 1) vis = set() d[s] = 0 h = [s] while not t in vis and len(h): v = heapq.heappop(h) v1 = v % (10**10) v0 = v // (10**10) if v1 in vis: continue vis.add(v1) for p in self.e[v1]: d[p[0]] = min(d[p[0]], d[v1] + p[1]) if p[0] in vis: continue heapq.heappush(h, d[p[0]] * (10**10) + p[0]) return d dij = dijkstra(N, e) edij = dijkstra(N, ee) p = dij.path(s, 0) revp = edij.path(t, 0) mny = pow(10, 15) table = [0] * (N + 1) for x in range(1, N + 1): table[x] = mny - p[x] - revp[x] csmx = [0] * (N + 1) for i in range(N, 0, -1): csmx[i - 1] = max(csmx[i - 1], table[i], csmx[i]) for i in range(N): print((csmx[i]))
false
13.207547
[ "-import heapq", "-n, m, s, t = list(map(int, input().split()))", "+N, M, s, t = list(map(int, input().split()))", "-money = 10**15", "-for _ in range(m):", "+ee = dd(list)", "+for i in range(M):", "- e[u + n].append((v + n, b))", "- e[v + n].append((u + n, b))", "-\"\"\"", "-for i in range(1, n + 1):", "- e[i].append((i + n, 0))", "-\"\"\"", "+ ee[u].append((v, b))", "+ ee[v].append((u, b))", "+import heapq", "- v1 = v % (10**15)", "- v0 = v // (10**15)", "+ v1 = v % (10**10)", "+ v0 = v // (10**10)", "- heapq.heappush(h, d[p[0]] * (10**15) + p[0])", "+ heapq.heappush(h, d[p[0]] * (10**10) + p[0])", "-d = dijkstra(2 * n + 1, e)", "-x = d.path(s, 2 * n + 1)", "-y = d.path(t + n, 2 * n + 1)", "-# print(x)", "-# print(y)", "-paths = [float(\"inf\")] * (n + 1)", "-minpaths = [float(\"inf\")] * (n + 1)", "-for i in range(1, n + 1):", "- paths[i] = x[i] + y[n + i]", "-# print(paths)", "-minpaths[-1] = paths[-1]", "-for i in range(n - 1, -1, -1):", "- minpaths[i] = min(minpaths[i + 1], paths[i])", "-# print(minpaths)", "-for i in range(1, n + 1):", "- print((money - minpaths[i]))", "+dij = dijkstra(N, e)", "+edij = dijkstra(N, ee)", "+p = dij.path(s, 0)", "+revp = edij.path(t, 0)", "+mny = pow(10, 15)", "+table = [0] * (N + 1)", "+for x in range(1, N + 1):", "+ table[x] = mny - p[x] - revp[x]", "+csmx = [0] * (N + 1)", "+for i in range(N, 0, -1):", "+ csmx[i - 1] = max(csmx[i - 1], table[i], csmx[i])", "+for i in range(N):", "+ print((csmx[i]))" ]
false
0.078768
0.079521
0.990534
[ "s015345635", "s832165292" ]
u600402037
p03076
python
s124328021
s178851257
165
17
13,092
3,060
Accepted
Accepted
89.7
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A = np.zeros(5, np.int32) for i in range(5): A[i] = ir() remain = A % 10 remain = remain[remain>0] ceil10 = (np.ceil(A/10) * 10).astype(np.int32) answer = ceil10.sum() if len(remain) != 0: minus = 10 - remain.min() answer -= minus print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A = [ir() for _ in range(5)] ceil_time = [(x+9)//10*10 for x in A] can_save = [y - x for y, x in zip(ceil_time, A)] answer = sum(ceil_time) - max(can_save) print(answer)
20
12
433
318
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A = np.zeros(5, np.int32) for i in range(5): A[i] = ir() remain = A % 10 remain = remain[remain > 0] ceil10 = (np.ceil(A / 10) * 10).astype(np.int32) answer = ceil10.sum() if len(remain) != 0: minus = 10 - remain.min() answer -= minus print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A = [ir() for _ in range(5)] ceil_time = [(x + 9) // 10 * 10 for x in A] can_save = [y - x for y, x in zip(ceil_time, A)] answer = sum(ceil_time) - max(can_save) print(answer)
false
40
[ "-import numpy as np", "-A = np.zeros(5, np.int32)", "-for i in range(5):", "- A[i] = ir()", "-remain = A % 10", "-remain = remain[remain > 0]", "-ceil10 = (np.ceil(A / 10) * 10).astype(np.int32)", "-answer = ceil10.sum()", "-if len(remain) != 0:", "- minus = 10 - remain.min()", "- answer -= minus", "+A = [ir() for _ in range(5)]", "+ceil_time = [(x + 9) // 10 * 10 for x in A]", "+can_save = [y - x for y, x in zip(ceil_time, A)]", "+answer = sum(ceil_time) - max(can_save)" ]
false
0.411475
0.03632
11.329202
[ "s124328021", "s178851257" ]
u677312543
p03239
python
s819400426
s629101128
24
18
2,940
2,940
Accepted
Accepted
25
import math N, T = list(map(int, input().split())) c_list = [] for i in range(N): c1, t1=[int(i) for i in input().split()] if t1 <= T: c_list.append(c1) if not c_list: print('TLE') else: print((min(c_list)))
n, T = list(map(int, input().split())) ans = 1003 for _ in range(n): c, t = list(map(int, input().split())) if t <= T: ans = min(ans, c) print(('TLE' if ans == 1003 else ans))
14
8
240
186
import math N, T = list(map(int, input().split())) c_list = [] for i in range(N): c1, t1 = [int(i) for i in input().split()] if t1 <= T: c_list.append(c1) if not c_list: print("TLE") else: print((min(c_list)))
n, T = list(map(int, input().split())) ans = 1003 for _ in range(n): c, t = list(map(int, input().split())) if t <= T: ans = min(ans, c) print(("TLE" if ans == 1003 else ans))
false
42.857143
[ "-import math", "-", "-N, T = list(map(int, input().split()))", "-c_list = []", "-for i in range(N):", "- c1, t1 = [int(i) for i in input().split()]", "- if t1 <= T:", "- c_list.append(c1)", "-if not c_list:", "- print(\"TLE\")", "-else:", "- print((min(c_list)))", "+n, T = list(map(int, input().split()))", "+ans = 1003", "+for _ in range(n):", "+ c, t = list(map(int, input().split()))", "+ if t <= T:", "+ ans = min(ans, c)", "+print((\"TLE\" if ans == 1003 else ans))" ]
false
0.082716
0.060383
1.369844
[ "s819400426", "s629101128" ]
u278356323
p02952
python
s532769231
s078551421
55
47
2,940
2,940
Accepted
Accepted
14.55
# ABC136b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) n = int(eval(input())) c = 0 for i in range(1, n+1): if (len(str(i)) % 2 == 1): c += 1 print(c)
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) # map(int, input().split()) n = int(eval(input())) ans = 0 for i in range(1, n + 1): if len(str(i)) % 2 == 1: ans += 1 print(ans) if __name__ == '__main__': main()
12
16
191
311
# ABC136b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) n = int(eval(input())) c = 0 for i in range(1, n + 1): if len(str(i)) % 2 == 1: c += 1 print(c)
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) # map(int, input().split()) n = int(eval(input())) ans = 0 for i in range(1, n + 1): if len(str(i)) % 2 == 1: ans += 1 print(ans) if __name__ == "__main__": main()
false
25
[ "-# ABC136b", "-import sys", "+def main():", "+ import sys", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**6)", "-n = int(eval(input()))", "-c = 0", "-for i in range(1, n + 1):", "- if len(str(i)) % 2 == 1:", "- c += 1", "-print(c)", "+ input = sys.stdin.readline", "+ sys.setrecursionlimit(10**6)", "+ # map(int, input().split())", "+ n = int(eval(input()))", "+ ans = 0", "+ for i in range(1, n + 1):", "+ if len(str(i)) % 2 == 1:", "+ ans += 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.055377
0.108226
0.511678
[ "s532769231", "s078551421" ]
u076917070
p04020
python
s784826215
s904652193
91
73
3,060
3,060
Accepted
Accepted
19.78
import sys input = sys.stdin.readline def main(): N = int(eval(input())) carry = 0 ans = 0 for i in range(N): x = int(eval(input())) if carry and x > 0: ans += 1 # carry を優先して処理 d, m = divmod(x - 1, 2) ans += d carry = m else: d, m = divmod(x, 2) ans += d carry = m print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline # 解説AC def main(): N = int(eval(input())) ans = 0 x = 0 for i in range(N): a = int(eval(input())) if a == 0: ans += x//2 x = 0 else: x += a ans += x//2 print(ans) if __name__ == '__main__': main()
24
22
459
336
import sys input = sys.stdin.readline def main(): N = int(eval(input())) carry = 0 ans = 0 for i in range(N): x = int(eval(input())) if carry and x > 0: ans += 1 # carry を優先して処理 d, m = divmod(x - 1, 2) ans += d carry = m else: d, m = divmod(x, 2) ans += d carry = m print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # 解説AC def main(): N = int(eval(input())) ans = 0 x = 0 for i in range(N): a = int(eval(input())) if a == 0: ans += x // 2 x = 0 else: x += a ans += x // 2 print(ans) if __name__ == "__main__": main()
false
8.333333
[ "-", "-", "+# 解説AC", "- carry = 0", "+ x = 0", "- x = int(eval(input()))", "- if carry and x > 0:", "- ans += 1 # carry を優先して処理", "- d, m = divmod(x - 1, 2)", "- ans += d", "- carry = m", "+ a = int(eval(input()))", "+ if a == 0:", "+ ans += x // 2", "+ x = 0", "- d, m = divmod(x, 2)", "- ans += d", "- carry = m", "+ x += a", "+ ans += x // 2" ]
false
0.046017
0.046793
0.983416
[ "s784826215", "s904652193" ]
u323680411
p03288
python
s121382791
s031486305
19
17
2,940
2,940
Accepted
Accepted
10.53
R = int(eval(input())) if R < 1200: print("ABC") elif R < 2800: print("ARC") else: print("AGC")
R = int(eval(input())) print(( "ABC" if R < 1200 else "ARC" if R < 2800 else "AGC" ))
8
5
109
90
R = int(eval(input())) if R < 1200: print("ABC") elif R < 2800: print("ARC") else: print("AGC")
R = int(eval(input())) print(("ABC" if R < 1200 else "ARC" if R < 2800 else "AGC"))
false
37.5
[ "-if R < 1200:", "- print(\"ABC\")", "-elif R < 2800:", "- print(\"ARC\")", "-else:", "- print(\"AGC\")", "+print((\"ABC\" if R < 1200 else \"ARC\" if R < 2800 else \"AGC\"))" ]
false
0.129985
0.053566
2.426635
[ "s121382791", "s031486305" ]
u556589653
p02779
python
s419619402
s496855320
177
94
26,808
31,036
Accepted
Accepted
46.89
N = int(eval(input())) A = list(map(int,input().split())) flag = 0 A.sort() for i in range(len(A)-1): if A[i] == A[i+1]: flag += 1 print("NO") break else: continue if flag == 0: print("YES")
N = int(eval(input())) A = list(map(int,input().split())) S = set(A) if len(A) == len(S): print("YES") else: print("NO")
13
7
240
124
N = int(eval(input())) A = list(map(int, input().split())) flag = 0 A.sort() for i in range(len(A) - 1): if A[i] == A[i + 1]: flag += 1 print("NO") break else: continue if flag == 0: print("YES")
N = int(eval(input())) A = list(map(int, input().split())) S = set(A) if len(A) == len(S): print("YES") else: print("NO")
false
46.153846
[ "-flag = 0", "-A.sort()", "-for i in range(len(A) - 1):", "- if A[i] == A[i + 1]:", "- flag += 1", "- print(\"NO\")", "- break", "- else:", "- continue", "-if flag == 0:", "+S = set(A)", "+if len(A) == len(S):", "+else:", "+ print(\"NO\")" ]
false
0.045659
0.044938
1.016037
[ "s419619402", "s496855320" ]
u488127128
p02971
python
s953676719
s015711180
458
296
26,620
14,100
Accepted
Accepted
35.37
n = int(eval(input())) data = [int(eval(input())) for k in range(n)] m1,m2 = sorted(data, reverse=1)[:2] b = [m2 if x==m1 else m1 for x in data] print(('\n'.join(map(str,b))))
import sys input = sys.stdin.readline n = int(eval(input())) numbers = [int(eval(input())) for i in range(n)] m1,m2 = sorted(numbers, reverse=1)[:2] b = [m2 if x==m1 else m1 for x in numbers] for s in b: print(s)
5
12
165
219
n = int(eval(input())) data = [int(eval(input())) for k in range(n)] m1, m2 = sorted(data, reverse=1)[:2] b = [m2 if x == m1 else m1 for x in data] print(("\n".join(map(str, b))))
import sys input = sys.stdin.readline n = int(eval(input())) numbers = [int(eval(input())) for i in range(n)] m1, m2 = sorted(numbers, reverse=1)[:2] b = [m2 if x == m1 else m1 for x in numbers] for s in b: print(s)
false
58.333333
[ "+import sys", "+", "+input = sys.stdin.readline", "-data = [int(eval(input())) for k in range(n)]", "-m1, m2 = sorted(data, reverse=1)[:2]", "-b = [m2 if x == m1 else m1 for x in data]", "-print((\"\\n\".join(map(str, b))))", "+numbers = [int(eval(input())) for i in range(n)]", "+m1, m2 = sorted(numbers, reverse=1)[:2]", "+b = [m2 if x == m1 else m1 for x in numbers]", "+for s in b:", "+ print(s)" ]
false
0.04348
0.127533
0.340928
[ "s953676719", "s015711180" ]
u670567845
p04044
python
s310151472
s662286231
71
63
62,192
62,328
Accepted
Accepted
11.27
N, L = list(map(int, input().split())) d = [eval(input()) for _ in range(N)] print(("".join(sorted(d))))
n, l = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print(("".join(s)))
3
4
92
94
N, L = list(map(int, input().split())) d = [eval(input()) for _ in range(N)] print(("".join(sorted(d))))
n, l = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print(("".join(s)))
false
25
[ "-N, L = list(map(int, input().split()))", "-d = [eval(input()) for _ in range(N)]", "-print((\"\".join(sorted(d))))", "+n, l = list(map(int, input().split()))", "+s = [eval(input()) for _ in range(n)]", "+s.sort()", "+print((\"\".join(s)))" ]
false
0.0803
0.069075
1.162507
[ "s310151472", "s662286231" ]
u077291787
p02630
python
s778457441
s400215373
210
143
43,936
43,852
Accepted
Accepted
31.9
# D - Replacing from collections import defaultdict def main(): N, *X = list(map(int, open(0).read().split())) A, BC = X[:N], X[N + 1 :] cnt = defaultdict(int) for a in A: cnt[a] += 1 total = sum(A) res = [] for b, c in zip(*[iter(BC)] * 2): total += (c - b) * cnt[b] res.append(total) cnt[c] += cnt[b] cnt[b] = 0 print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
# D - Replacing def main(): N, *X = list(map(int, open(0).read().split())) A, BC = X[:N], X[N + 1 :] cnt = [0] * (10 ** 5 + 1) for a in A: cnt[a] += 1 total = sum(A) res = [] for b, c in zip(*[iter(BC)] * 2): total += (c - b) * cnt[b] res.append(total) cnt[c] += cnt[b] cnt[b] = 0 print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
22
19
475
437
# D - Replacing from collections import defaultdict def main(): N, *X = list(map(int, open(0).read().split())) A, BC = X[:N], X[N + 1 :] cnt = defaultdict(int) for a in A: cnt[a] += 1 total = sum(A) res = [] for b, c in zip(*[iter(BC)] * 2): total += (c - b) * cnt[b] res.append(total) cnt[c] += cnt[b] cnt[b] = 0 print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
# D - Replacing def main(): N, *X = list(map(int, open(0).read().split())) A, BC = X[:N], X[N + 1 :] cnt = [0] * (10**5 + 1) for a in A: cnt[a] += 1 total = sum(A) res = [] for b, c in zip(*[iter(BC)] * 2): total += (c - b) * cnt[b] res.append(total) cnt[c] += cnt[b] cnt[b] = 0 print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
false
13.636364
[ "-from collections import defaultdict", "-", "-", "- cnt = defaultdict(int)", "+ cnt = [0] * (10**5 + 1)" ]
false
0.044927
0.037217
1.207167
[ "s778457441", "s400215373" ]
u387774811
p02788
python
s863618571
s882605081
1,728
1,174
72,784
69,772
Accepted
Accepted
32.06
def nibun_right(a, x): lo, hi = 0, len(a) while lo < hi: mid = (lo+hi)//2 if x < a[mid][0]: hi = mid else: lo = mid+1 return lo N,D,A=list(map(int,input().split())) lst=[0]*N for i in range(N): lst[i]=list(map(int,input().split())) lst[i][1]=int((lst[i][1]-1)/A)+1 lst.sort() DMG=[0]*(N+1) ans=0 for i in range(N): renji=nibun_right(lst,lst[i][0]+2*D) Z=max(lst[i][1]-DMG[i],0) DMG[i]+=Z DMG[renji]-=Z ans+=Z DMG[i+1]+=DMG[i] print(ans)
import sys input = sys.stdin.readline def nibun_right(a, x): lo, hi = 0, len(a) while lo < hi: mid = (lo+hi)//2 if x < a[mid][0]: hi = mid else: lo = mid+1 return lo N,D,A=list(map(int,input().split())) lst=[0]*N for i in range(N): lst[i]=list(map(int,input().split())) lst[i][1]=int((lst[i][1]-1)/A)+1 lst.sort() DMG=[0]*(N+1) ans=0 for i in range(N): renji=nibun_right(lst,lst[i][0]+2*D) Z=max(lst[i][1]-DMG[i],0) DMG[i]+=Z DMG[renji]-=Z ans+=Z DMG[i+1]+=DMG[i] print(ans)
23
25
470
510
def nibun_right(a, x): lo, hi = 0, len(a) while lo < hi: mid = (lo + hi) // 2 if x < a[mid][0]: hi = mid else: lo = mid + 1 return lo N, D, A = list(map(int, input().split())) lst = [0] * N for i in range(N): lst[i] = list(map(int, input().split())) lst[i][1] = int((lst[i][1] - 1) / A) + 1 lst.sort() DMG = [0] * (N + 1) ans = 0 for i in range(N): renji = nibun_right(lst, lst[i][0] + 2 * D) Z = max(lst[i][1] - DMG[i], 0) DMG[i] += Z DMG[renji] -= Z ans += Z DMG[i + 1] += DMG[i] print(ans)
import sys input = sys.stdin.readline def nibun_right(a, x): lo, hi = 0, len(a) while lo < hi: mid = (lo + hi) // 2 if x < a[mid][0]: hi = mid else: lo = mid + 1 return lo N, D, A = list(map(int, input().split())) lst = [0] * N for i in range(N): lst[i] = list(map(int, input().split())) lst[i][1] = int((lst[i][1] - 1) / A) + 1 lst.sort() DMG = [0] * (N + 1) ans = 0 for i in range(N): renji = nibun_right(lst, lst[i][0] + 2 * D) Z = max(lst[i][1] - DMG[i], 0) DMG[i] += Z DMG[renji] -= Z ans += Z DMG[i + 1] += DMG[i] print(ans)
false
8
[ "+import sys", "+", "+input = sys.stdin.readline", "+", "+" ]
false
0.043038
0.110197
0.390551
[ "s863618571", "s882605081" ]
u863370423
p03945
python
s027573322
s827850169
44
35
3,188
5,892
Accepted
Accepted
20.45
board = eval(input()) changes = 1 currSeq = board[0] for i in range(1, len(board)): current = board[i] if current != currSeq: changes += 1 currSeq = current print((changes - 1))
x = input() out = 0 curchar = x[0] for d in range(0, len(x)): if curchar != x[d]: curchar = x[d] out += 1 print(out)
12
8
189
132
board = eval(input()) changes = 1 currSeq = board[0] for i in range(1, len(board)): current = board[i] if current != currSeq: changes += 1 currSeq = current print((changes - 1))
x = input() out = 0 curchar = x[0] for d in range(0, len(x)): if curchar != x[d]: curchar = x[d] out += 1 print(out)
false
33.333333
[ "-board = eval(input())", "-changes = 1", "-currSeq = board[0]", "-for i in range(1, len(board)):", "- current = board[i]", "- if current != currSeq:", "- changes += 1", "- currSeq = current", "-print((changes - 1))", "+x = input()", "+out = 0", "+curchar = x[0]", "+for d in range(0, len(x)):", "+ if curchar != x[d]:", "+ curchar = x[d]", "+ out += 1", "+print(out)" ]
false
0.036919
0.03606
1.023837
[ "s027573322", "s827850169" ]
u619144316
p02837
python
s247644949
s222033093
1,489
719
3,064
3,064
Accepted
Accepted
51.71
N = int(eval(input())) honest = [[] for _ in range(N)] unkind = [[] for _ in range(N)] MAX = 0 for i in range(0,N): A = int(eval(input())) for _ in range(A): x, y =list(map(int,input().split(' '))) if y == 0: unkind[i].append(x-1) else: honest[i].append(x-1) for i in range(2**N): flg = 1 for j in range(N): if ((i>>j) & 1): bool1 = all([(i>>k) & 1 for k in honest[j]]) bool2 = all([~(i>>k) & 1 for k in unkind[j]]) if not all([(i>>k) & 1 for k in honest[j]]) or not all([~(i>>k) & 1 for k in unkind[j]]): flg =0 if flg: cnt = 0 num = i while num: num &= num -1 cnt += 1 MAX = max(cnt,MAX) print(MAX)
def main(): N = int(eval(input())) A = [] for i in range(N): a = int(eval(input())) XY = [] for _ in range(a): x,y = list(map(int,input().split())) XY.append((x-1,y)) A.append(XY) # print(A) MAX = 0 for i in range(2**N): # print(i) flg = 1 for j in range(N): if (i >>j) & 1: # print('b') for ch in A[j]: # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1]) if ((i >> ch[0])^ ch[1])%2 == 1: # print('a',ch[0]) flg = 0 if flg == 1: t = bin(i).count('1') MAX = max(t,MAX) print(MAX) main()
31
37
800
799
N = int(eval(input())) honest = [[] for _ in range(N)] unkind = [[] for _ in range(N)] MAX = 0 for i in range(0, N): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split(" "))) if y == 0: unkind[i].append(x - 1) else: honest[i].append(x - 1) for i in range(2**N): flg = 1 for j in range(N): if (i >> j) & 1: bool1 = all([(i >> k) & 1 for k in honest[j]]) bool2 = all([~(i >> k) & 1 for k in unkind[j]]) if not all([(i >> k) & 1 for k in honest[j]]) or not all( [~(i >> k) & 1 for k in unkind[j]] ): flg = 0 if flg: cnt = 0 num = i while num: num &= num - 1 cnt += 1 MAX = max(cnt, MAX) print(MAX)
def main(): N = int(eval(input())) A = [] for i in range(N): a = int(eval(input())) XY = [] for _ in range(a): x, y = list(map(int, input().split())) XY.append((x - 1, y)) A.append(XY) # print(A) MAX = 0 for i in range(2**N): # print(i) flg = 1 for j in range(N): if (i >> j) & 1: # print('b') for ch in A[j]: # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1]) if ((i >> ch[0]) ^ ch[1]) % 2 == 1: # print('a',ch[0]) flg = 0 if flg == 1: t = bin(i).count("1") MAX = max(t, MAX) print(MAX) main()
false
16.216216
[ "-N = int(eval(input()))", "-honest = [[] for _ in range(N)]", "-unkind = [[] for _ in range(N)]", "-MAX = 0", "-for i in range(0, N):", "- A = int(eval(input()))", "- for _ in range(A):", "- x, y = list(map(int, input().split(\" \")))", "- if y == 0:", "- unkind[i].append(x - 1)", "- else:", "- honest[i].append(x - 1)", "-for i in range(2**N):", "- flg = 1", "- for j in range(N):", "- if (i >> j) & 1:", "- bool1 = all([(i >> k) & 1 for k in honest[j]])", "- bool2 = all([~(i >> k) & 1 for k in unkind[j]])", "- if not all([(i >> k) & 1 for k in honest[j]]) or not all(", "- [~(i >> k) & 1 for k in unkind[j]]", "- ):", "- flg = 0", "- if flg:", "- cnt = 0", "- num = i", "- while num:", "- num &= num - 1", "- cnt += 1", "- MAX = max(cnt, MAX)", "-print(MAX)", "+def main():", "+ N = int(eval(input()))", "+ A = []", "+ for i in range(N):", "+ a = int(eval(input()))", "+ XY = []", "+ for _ in range(a):", "+ x, y = list(map(int, input().split()))", "+ XY.append((x - 1, y))", "+ A.append(XY)", "+ # print(A)", "+ MAX = 0", "+ for i in range(2**N):", "+ # print(i)", "+ flg = 1", "+ for j in range(N):", "+ if (i >> j) & 1:", "+ # print('b')", "+ for ch in A[j]:", "+ # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1])", "+ if ((i >> ch[0]) ^ ch[1]) % 2 == 1:", "+ # print('a',ch[0])", "+ flg = 0", "+ if flg == 1:", "+ t = bin(i).count(\"1\")", "+ MAX = max(t, MAX)", "+ print(MAX)", "+", "+", "+main()" ]
false
0.054355
0.047381
1.147175
[ "s247644949", "s222033093" ]
u143051858
p03937
python
s253486255
s812408827
29
26
9,076
8,992
Accepted
Accepted
10.34
H,W = list(map(int,input().split())) res = '' for i in range(H): res += eval(input()) if res.count('#') == H+W-1: print('Possible') else: print('Impossible')
H,W = list(map(int,input().split())) res = 0 for i in range(H): res += input().count('#') if res == H+W-1: print('Possible') else: print('Impossible')
8
11
165
169
H, W = list(map(int, input().split())) res = "" for i in range(H): res += eval(input()) if res.count("#") == H + W - 1: print("Possible") else: print("Impossible")
H, W = list(map(int, input().split())) res = 0 for i in range(H): res += input().count("#") if res == H + W - 1: print("Possible") else: print("Impossible")
false
27.272727
[ "-res = \"\"", "+res = 0", "- res += eval(input())", "-if res.count(\"#\") == H + W - 1:", "+ res += input().count(\"#\")", "+if res == H + W - 1:" ]
false
0.049349
0.049036
1.006383
[ "s253486255", "s812408827" ]
u969850098
p03457
python
s314788665
s213008562
378
175
3,064
3,064
Accepted
Accepted
53.7
N = int(eval(input())) t, x, y = 0, 0, 0 for _ in range(N): ti, xi, yi = list(map(int, input().split())) dt, dx, dy = ti - t, abs(xi - x), abs(yi - y) t, x, y = ti, xi, yi # print(dt, dx, dy) # print((dt - (dx + dy)) % 2) if ((dt - (dx + dy)) % 2 != 0) or (dx + dy > dt): print('No') exit() print('Yes')
import sys readline = sys.stdin.readline def main(): N = int(readline()) res = 'Yes' pre_x, pre_y = 0, 0 pre = 0 for _ in range(N): t, x, y = list(map(int, readline().rstrip().split())) cost = abs(x - pre_x) + abs(y - pre_y) if (t - pre) - cost >= 0 and ((t - pre) - cost) % 2 == 0: pre, pre_x, pre_y = t, x, y else: res = 'No' break print(res) if __name__ == '__main__': main()
14
21
346
491
N = int(eval(input())) t, x, y = 0, 0, 0 for _ in range(N): ti, xi, yi = list(map(int, input().split())) dt, dx, dy = ti - t, abs(xi - x), abs(yi - y) t, x, y = ti, xi, yi # print(dt, dx, dy) # print((dt - (dx + dy)) % 2) if ((dt - (dx + dy)) % 2 != 0) or (dx + dy > dt): print("No") exit() print("Yes")
import sys readline = sys.stdin.readline def main(): N = int(readline()) res = "Yes" pre_x, pre_y = 0, 0 pre = 0 for _ in range(N): t, x, y = list(map(int, readline().rstrip().split())) cost = abs(x - pre_x) + abs(y - pre_y) if (t - pre) - cost >= 0 and ((t - pre) - cost) % 2 == 0: pre, pre_x, pre_y = t, x, y else: res = "No" break print(res) if __name__ == "__main__": main()
false
33.333333
[ "-N = int(eval(input()))", "-t, x, y = 0, 0, 0", "-for _ in range(N):", "- ti, xi, yi = list(map(int, input().split()))", "- dt, dx, dy = ti - t, abs(xi - x), abs(yi - y)", "- t, x, y = ti, xi, yi", "- # print(dt, dx, dy)", "- # print((dt - (dx + dy)) % 2)", "- if ((dt - (dx + dy)) % 2 != 0) or (dx + dy > dt):", "- print(\"No\")", "- exit()", "-print(\"Yes\")", "+import sys", "+", "+readline = sys.stdin.readline", "+", "+", "+def main():", "+ N = int(readline())", "+ res = \"Yes\"", "+ pre_x, pre_y = 0, 0", "+ pre = 0", "+ for _ in range(N):", "+ t, x, y = list(map(int, readline().rstrip().split()))", "+ cost = abs(x - pre_x) + abs(y - pre_y)", "+ if (t - pre) - cost >= 0 and ((t - pre) - cost) % 2 == 0:", "+ pre, pre_x, pre_y = t, x, y", "+ else:", "+ res = \"No\"", "+ break", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.064067
0.037712
1.698839
[ "s314788665", "s213008562" ]
u816872429
p02960
python
s280094293
s928157983
896
487
44,524
44,396
Accepted
Accepted
45.65
s = eval(input()) frommap = [] for d in range(10): frommap.append([0] * 13) for m in range(13): m2 = (m * 10 + d) % 13 frommap[d][m2] = m dp = [1] + [0] * 12 for c in s: if c == '?': dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)] else: dp = [dp[f] for f in frommap[int(c)]] print((dp[5]))
s = eval(input()) frommap = [] for d in range(10): frommap.append([0] * 13) for m in range(13): m2 = (m * 10 + d) % 13 frommap[d][m2] = m transmap = list(zip(*frommap)) dp = [1] + [0] * 12 for c in s: if c == '?': dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in transmap] else: dp = [dp[f] for f in frommap[int(c)]] print((dp[5]))
17
18
379
406
s = eval(input()) frommap = [] for d in range(10): frommap.append([0] * 13) for m in range(13): m2 = (m * 10 + d) % 13 frommap[d][m2] = m dp = [1] + [0] * 12 for c in s: if c == "?": dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)] else: dp = [dp[f] for f in frommap[int(c)]] print((dp[5]))
s = eval(input()) frommap = [] for d in range(10): frommap.append([0] * 13) for m in range(13): m2 = (m * 10 + d) % 13 frommap[d][m2] = m transmap = list(zip(*frommap)) dp = [1] + [0] * 12 for c in s: if c == "?": dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in transmap] else: dp = [dp[f] for f in frommap[int(c)]] print((dp[5]))
false
5.555556
[ "+transmap = list(zip(*frommap))", "- dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)]", "+ dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in transmap]" ]
false
0.036723
0.099976
0.367319
[ "s280094293", "s928157983" ]
u385792265
p03163
python
s321323561
s354911258
1,778
1,632
7,736
7,736
Accepted
Accepted
8.21
import sys n, we = list(map(int, input().split())) cf=[(0, 0)]*n cf = sorted(tuple( int(x) for x in sys.stdin.readline().split()) for _ in range(n)) dp=[0]*(we+1) best=0 cnt=1 lim=0 for w,c in cf: cnt=cnt+w lim=min(cnt, we-w) for j in range(lim, -1, -1): if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c print((max(dp)))
import sys n, we = list(map(int, input().split())) cf=[(0, 0)]*n cf = sorted( [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] ) dp=[0]*(we+1) best=0 cnt=1 lim=0 for w,c in cf: cnt=cnt+w lim=min(cnt, we-w) for j in range(lim, -1, -1): if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c print((max(dp)))
21
21
353
351
import sys n, we = list(map(int, input().split())) cf = [(0, 0)] * n cf = sorted(tuple(int(x) for x in sys.stdin.readline().split()) for _ in range(n)) dp = [0] * (we + 1) best = 0 cnt = 1 lim = 0 for w, c in cf: cnt = cnt + w lim = min(cnt, we - w) for j in range(lim, -1, -1): if dp[j + w] < (dp[j] + c): dp[j + w] = dp[j] + c print((max(dp)))
import sys n, we = list(map(int, input().split())) cf = [(0, 0)] * n cf = sorted([[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]) dp = [0] * (we + 1) best = 0 cnt = 1 lim = 0 for w, c in cf: cnt = cnt + w lim = min(cnt, we - w) for j in range(lim, -1, -1): if dp[j + w] < (dp[j] + c): dp[j + w] = dp[j] + c print((max(dp)))
false
0
[ "-cf = sorted(tuple(int(x) for x in sys.stdin.readline().split()) for _ in range(n))", "+cf = sorted([[int(x) for x in sys.stdin.readline().split()] for _ in range(n)])" ]
false
0.044665
0.044781
0.997404
[ "s321323561", "s354911258" ]
u165318982
p02570
python
s537879103
s239952309
35
28
9,152
9,076
Accepted
Accepted
20
D, T, S = list(map(int, input().split())) distance = T * S if D > distance: print('No') else: print('Yes')
D, T, S = list(map(int, input().split())) distance = T * S if D <= distance: print('Yes') else: print('No')
8
8
119
120
D, T, S = list(map(int, input().split())) distance = T * S if D > distance: print("No") else: print("Yes")
D, T, S = list(map(int, input().split())) distance = T * S if D <= distance: print("Yes") else: print("No")
false
0
[ "-if D > distance:", "+if D <= distance:", "+ print(\"Yes\")", "+else:", "-else:", "- print(\"Yes\")" ]
false
0.086099
0.107757
0.799013
[ "s537879103", "s239952309" ]
u124498235
p03424
python
s039152012
s913340921
21
17
3,316
2,940
Accepted
Accepted
19.05
from collections import Counter n = int(eval(input())) s = list(map(str, input().split())) if len(Counter(s)) == 4: print ("Four") else: print ("Three")
n = int(eval(input())) s = list(map(str, input().split())) ss = set(s) if len(ss) == 3: print ("Three") else: print ("Four")
7
7
154
126
from collections import Counter n = int(eval(input())) s = list(map(str, input().split())) if len(Counter(s)) == 4: print("Four") else: print("Three")
n = int(eval(input())) s = list(map(str, input().split())) ss = set(s) if len(ss) == 3: print("Three") else: print("Four")
false
0
[ "-from collections import Counter", "-", "-if len(Counter(s)) == 4:", "+ss = set(s)", "+if len(ss) == 3:", "+ print(\"Three\")", "+else:", "-else:", "- print(\"Three\")" ]
false
0.046647
0.046652
0.999888
[ "s039152012", "s913340921" ]
u143492911
p03478
python
s833376801
s470565914
37
33
3,060
3,060
Accepted
Accepted
10.81
n,a,b=list(map(int,input().split())) ans=0 for i in range(n+1): l=[int(x) for x in list(str(i))] if a<=sum(l)<=b: ans+=i print(ans)
n,a,b=list(map(int,input().split())) total=0 for i in range(n+1): ans=list(str(i)) ans_2=sum(map(int,ans)) if a<=ans_2<=b: total+=i print(total)
7
8
151
165
n, a, b = list(map(int, input().split())) ans = 0 for i in range(n + 1): l = [int(x) for x in list(str(i))] if a <= sum(l) <= b: ans += i print(ans)
n, a, b = list(map(int, input().split())) total = 0 for i in range(n + 1): ans = list(str(i)) ans_2 = sum(map(int, ans)) if a <= ans_2 <= b: total += i print(total)
false
12.5
[ "-ans = 0", "+total = 0", "- l = [int(x) for x in list(str(i))]", "- if a <= sum(l) <= b:", "- ans += i", "-print(ans)", "+ ans = list(str(i))", "+ ans_2 = sum(map(int, ans))", "+ if a <= ans_2 <= b:", "+ total += i", "+print(total)" ]
false
0.036114
0.082562
0.437423
[ "s833376801", "s470565914" ]
u541610817
p03624
python
s565859352
s934996842
20
17
3,188
3,188
Accepted
Accepted
15
s_in = eval(input()) s = set(s_in) lst = [ord(i) - ord('a') for i in s] lst.sort() for i in range(26): if not i in lst: print((chr(i + ord('a')))) break elif i == 25: print('None')
s = eval(input()) for i in range(ord('a'), ord('z') + 1): if not chr(i) in s: print((chr(i))) break if i == ord('z'): print('None')
10
7
214
146
s_in = eval(input()) s = set(s_in) lst = [ord(i) - ord("a") for i in s] lst.sort() for i in range(26): if not i in lst: print((chr(i + ord("a")))) break elif i == 25: print("None")
s = eval(input()) for i in range(ord("a"), ord("z") + 1): if not chr(i) in s: print((chr(i))) break if i == ord("z"): print("None")
false
30
[ "-s_in = eval(input())", "-s = set(s_in)", "-lst = [ord(i) - ord(\"a\") for i in s]", "-lst.sort()", "-for i in range(26):", "- if not i in lst:", "- print((chr(i + ord(\"a\"))))", "+s = eval(input())", "+for i in range(ord(\"a\"), ord(\"z\") + 1):", "+ if not chr(i) in s:", "+ print((chr(i)))", "- elif i == 25:", "+ if i == ord(\"z\"):" ]
false
0.086574
0.008518
10.163419
[ "s565859352", "s934996842" ]
u373047809
p03078
python
s784878275
s703068507
48
42
10,836
10,448
Accepted
Accepted
12.5
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort(); b.sort(); c.sort() p = a[-1] + b[-1] + c[-1] s, h = {(p, -1, -1, -1)}, [(-p, -1, -1, -1)] from heapq import* def push(i, j, k): global s, h try: t = a[i] + b[j] + c[k] except IndexError: return if (t, i, j, k) not in s: heappush(h, (-t, i, j, k)) s |= {(t, i, j, k)} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort(); b.sort(); c.sort() h = [(-(a[-1] + b[-1] + c[-1]), -1, -1, -1)] s = set(h) from heapq import* def push(i, j, k): global s, h try: t = (- (a[i] + b[j] + c[k]), i, j, k) except IndexError: return if t not in s: heappush(h, t) s |= {t} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
24
24
565
531
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort() b.sort() c.sort() p = a[-1] + b[-1] + c[-1] s, h = {(p, -1, -1, -1)}, [(-p, -1, -1, -1)] from heapq import * def push(i, j, k): global s, h try: t = a[i] + b[j] + c[k] except IndexError: return if (t, i, j, k) not in s: heappush(h, (-t, i, j, k)) s |= {(t, i, j, k)} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort() b.sort() c.sort() h = [(-(a[-1] + b[-1] + c[-1]), -1, -1, -1)] s = set(h) from heapq import * def push(i, j, k): global s, h try: t = (-(a[i] + b[j] + c[k]), i, j, k) except IndexError: return if t not in s: heappush(h, t) s |= {t} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
false
0
[ "-p = a[-1] + b[-1] + c[-1]", "-s, h = {(p, -1, -1, -1)}, [(-p, -1, -1, -1)]", "+h = [(-(a[-1] + b[-1] + c[-1]), -1, -1, -1)]", "+s = set(h)", "- t = a[i] + b[j] + c[k]", "+ t = (-(a[i] + b[j] + c[k]), i, j, k)", "- if (t, i, j, k) not in s:", "- heappush(h, (-t, i, j, k))", "- s |= {(t, i, j, k)}", "+ if t not in s:", "+ heappush(h, t)", "+ s |= {t}" ]
false
0.033349
0.033997
0.980931
[ "s784878275", "s703068507" ]
u944325914
p02681
python
s128733823
s727884202
22
20
8,960
8,972
Accepted
Accepted
9.09
s=eval(input()) t=eval(input()) if t[:-1]==s: print("Yes") else: print("No")
s=list(eval(input())) t=list(eval(input())) if s==t[:-1]: print("Yes") else: print("No")
6
6
73
85
s = eval(input()) t = eval(input()) if t[:-1] == s: print("Yes") else: print("No")
s = list(eval(input())) t = list(eval(input())) if s == t[:-1]: print("Yes") else: print("No")
false
0
[ "-s = eval(input())", "-t = eval(input())", "-if t[:-1] == s:", "+s = list(eval(input()))", "+t = list(eval(input()))", "+if s == t[:-1]:" ]
false
0.035548
0.035224
1.009181
[ "s128733823", "s727884202" ]
u761320129
p03806
python
s319001790
s128261336
597
493
25,092
4,852
Accepted
Accepted
17.42
N,MA,MB = list(map(int,input().split())) src = [] sum_a = sum_b = 0 for i in range(N): a,b,c = list(map(int,input().split())) src.append((a,b,c)) sum_a += a sum_b += b INF = 10**9 dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)] dp[0][0][0] = 0 for i in range(N): ai,bi,ci = src[i] for a in range(sum_a+1 - ai): for b in range(sum_b+1 - bi): if dp[i][a][b] == INF: continue dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b]) dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci) ans = INF n = 1 while True: a,b = n*MA,n*MB if a > sum_a or b > sum_b: break ans = min(ans, dp[N][a][b]) n += 1 print((ans if ans != INF else -1))
N,MA,MB = list(map(int,input().split())) src = [tuple(map(int,input().split())) for i in range(N)] INF = 10**9 dp = [[INF for j in range(401)] for i in range(401)] dp[0][0] = 0 maxa = maxb = 0 for a,b,c in src: for ai in range(maxa,-1,-1): for bi in range(maxb,-1,-1): dp[ai+a][bi+b] = min(dp[ai+a][bi+b], dp[ai][bi] + c) maxa += a maxb += b ans = INF for i in range(1,401): if MA*i > 400 or MB*i > 400: break ans = min(ans, dp[MA*i][MB*i]) print((-1 if ans == INF else ans))
30
19
734
527
N, MA, MB = list(map(int, input().split())) src = [] sum_a = sum_b = 0 for i in range(N): a, b, c = list(map(int, input().split())) src.append((a, b, c)) sum_a += a sum_b += b INF = 10**9 dp = [[[INF for b in range(sum_b + 1)] for a in range(sum_a + 1)] for i in range(N + 1)] dp[0][0][0] = 0 for i in range(N): ai, bi, ci = src[i] for a in range(sum_a + 1 - ai): for b in range(sum_b + 1 - bi): if dp[i][a][b] == INF: continue dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b]) dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci) ans = INF n = 1 while True: a, b = n * MA, n * MB if a > sum_a or b > sum_b: break ans = min(ans, dp[N][a][b]) n += 1 print((ans if ans != INF else -1))
N, MA, MB = list(map(int, input().split())) src = [tuple(map(int, input().split())) for i in range(N)] INF = 10**9 dp = [[INF for j in range(401)] for i in range(401)] dp[0][0] = 0 maxa = maxb = 0 for a, b, c in src: for ai in range(maxa, -1, -1): for bi in range(maxb, -1, -1): dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c) maxa += a maxb += b ans = INF for i in range(1, 401): if MA * i > 400 or MB * i > 400: break ans = min(ans, dp[MA * i][MB * i]) print((-1 if ans == INF else ans))
false
36.666667
[ "-src = []", "-sum_a = sum_b = 0", "-for i in range(N):", "- a, b, c = list(map(int, input().split()))", "- src.append((a, b, c))", "- sum_a += a", "- sum_b += b", "+src = [tuple(map(int, input().split())) for i in range(N)]", "-dp = [[[INF for b in range(sum_b + 1)] for a in range(sum_a + 1)] for i in range(N + 1)]", "-dp[0][0][0] = 0", "-for i in range(N):", "- ai, bi, ci = src[i]", "- for a in range(sum_a + 1 - ai):", "- for b in range(sum_b + 1 - bi):", "- if dp[i][a][b] == INF:", "- continue", "- dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])", "- dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)", "+dp = [[INF for j in range(401)] for i in range(401)]", "+dp[0][0] = 0", "+maxa = maxb = 0", "+for a, b, c in src:", "+ for ai in range(maxa, -1, -1):", "+ for bi in range(maxb, -1, -1):", "+ dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c)", "+ maxa += a", "+ maxb += b", "-n = 1", "-while True:", "- a, b = n * MA, n * MB", "- if a > sum_a or b > sum_b:", "+for i in range(1, 401):", "+ if MA * i > 400 or MB * i > 400:", "- ans = min(ans, dp[N][a][b])", "- n += 1", "-print((ans if ans != INF else -1))", "+ ans = min(ans, dp[MA * i][MB * i])", "+print((-1 if ans == INF else ans))" ]
false
0.04367
0.049511
0.882026
[ "s319001790", "s128261336" ]
u352394527
p00336
python
s231710266
s454837386
860
640
29,296
5,568
Accepted
Accepted
25.58
""" dp[x][y] ... tのx文字目までで, y文字一致した場合の数 dp[x][y] = dp[x - 1][y] + dp[x - 1][y - 1] * (t[x] == b[y]) """ MOD = 1000000007 t = eval(input()) b = eval(input()) lent = len(t) lenb = len(b) dp = [[0] * (lenb + 1) for _ in range(lent + 1)] for i in range(lent + 1): dp[i][0] = 1 for x in range(1, lent + 1): for y in range(1, lenb + 1): dp[x][y] = (dp[x - 1][y] + dp[x - 1][y - 1] * (t[x - 1] == b[y - 1])) % MOD print((dp[lent][lenb]))
MOD = 1000000007 t = eval(input()) b = eval(input()) lent = len(t) lenb = len(b) dp = [0] * (lenb + 1) dp[0] = 1 for x in range(1, lent + 1): ct = t[x - 1] for y in range(lenb, 0, -1): if ct == b[y - 1]: dp[y] += dp[y - 1] dp[y] %= MOD print((dp[lenb]))
17
14
443
273
""" dp[x][y] ... tのx文字目までで, y文字一致した場合の数 dp[x][y] = dp[x - 1][y] + dp[x - 1][y - 1] * (t[x] == b[y]) """ MOD = 1000000007 t = eval(input()) b = eval(input()) lent = len(t) lenb = len(b) dp = [[0] * (lenb + 1) for _ in range(lent + 1)] for i in range(lent + 1): dp[i][0] = 1 for x in range(1, lent + 1): for y in range(1, lenb + 1): dp[x][y] = (dp[x - 1][y] + dp[x - 1][y - 1] * (t[x - 1] == b[y - 1])) % MOD print((dp[lent][lenb]))
MOD = 1000000007 t = eval(input()) b = eval(input()) lent = len(t) lenb = len(b) dp = [0] * (lenb + 1) dp[0] = 1 for x in range(1, lent + 1): ct = t[x - 1] for y in range(lenb, 0, -1): if ct == b[y - 1]: dp[y] += dp[y - 1] dp[y] %= MOD print((dp[lenb]))
false
17.647059
[ "-\"\"\"", "-dp[x][y] ... tのx文字目までで, y文字一致した場合の数", "-dp[x][y] = dp[x - 1][y] + dp[x - 1][y - 1] * (t[x] == b[y])", "-\"\"\"", "-dp = [[0] * (lenb + 1) for _ in range(lent + 1)]", "-for i in range(lent + 1):", "- dp[i][0] = 1", "+dp = [0] * (lenb + 1)", "+dp[0] = 1", "- for y in range(1, lenb + 1):", "- dp[x][y] = (dp[x - 1][y] + dp[x - 1][y - 1] * (t[x - 1] == b[y - 1])) % MOD", "-print((dp[lent][lenb]))", "+ ct = t[x - 1]", "+ for y in range(lenb, 0, -1):", "+ if ct == b[y - 1]:", "+ dp[y] += dp[y - 1]", "+ dp[y] %= MOD", "+print((dp[lenb]))" ]
false
0.036557
0.035982
1.01597
[ "s231710266", "s454837386" ]
u983918956
p03219
python
s742536578
s012497161
19
17
2,940
2,940
Accepted
Accepted
10.53
X,Y = list(map(int,input().split())) print((int(X + Y/2)))
X, Y = list(map(int,input().split())) ans = X + Y//2 print(ans)
2
3
51
59
X, Y = list(map(int, input().split())) print((int(X + Y / 2)))
X, Y = list(map(int, input().split())) ans = X + Y // 2 print(ans)
false
33.333333
[ "-print((int(X + Y / 2)))", "+ans = X + Y // 2", "+print(ans)" ]
false
0.074062
0.062902
1.177422
[ "s742536578", "s012497161" ]
u359358631
p03814
python
s468838145
s147667871
33
30
9,256
9,128
Accepted
Accepted
9.09
def main(): s = eval(input()) n = len(s) start = -1 end = n for i in range(0, n, 1): if s[i] == "A": start = i break for i in range(n - 1, -1, -1): if s[i] == "Z": end = i break print((end - start + 1)) if __name__ == "__main__": main()
def main(): s = eval(input()) n = len(s) start = -1 end = n start = s.index("A") end = s.rindex("Z") print((end - start + 1)) if __name__ == "__main__": main()
24
17
288
187
def main(): s = eval(input()) n = len(s) start = -1 end = n for i in range(0, n, 1): if s[i] == "A": start = i break for i in range(n - 1, -1, -1): if s[i] == "Z": end = i break print((end - start + 1)) if __name__ == "__main__": main()
def main(): s = eval(input()) n = len(s) start = -1 end = n start = s.index("A") end = s.rindex("Z") print((end - start + 1)) if __name__ == "__main__": main()
false
29.166667
[ "- for i in range(0, n, 1):", "- if s[i] == \"A\":", "- start = i", "- break", "- for i in range(n - 1, -1, -1):", "- if s[i] == \"Z\":", "- end = i", "- break", "+ start = s.index(\"A\")", "+ end = s.rindex(\"Z\")" ]
false
0.048496
0.048732
0.995159
[ "s468838145", "s147667871" ]
u888092736
p03074
python
s016324890
s410187179
164
149
18,236
17,796
Accepted
Accepted
9.15
def compress(S): res = [] prev = "aa" for c in S: if c != prev: res.append([c, 1]) else: res[-1][1] += 1 prev = c return res N, K = list(map(int, input().split())) S = list(map(int, eval(input()))) S_comp = compress(S) M = len(S_comp) ans = 0 total = 0 right = 0 zero_chunks_cnt = 0 for left in range(M): while right < M and zero_chunks_cnt + 1 - S_comp[right][0] <= K: zero_chunks_cnt += 1 - S_comp[right][0] total += S_comp[right][1] right += 1 ans = max(ans, total) if right == left: right += 1 else: zero_chunks_cnt -= 1 - S_comp[left][0] total -= S_comp[left][1] print(ans)
def run_length_compress(S): res = [[S[0], 1]] for c in S[1:]: if c == res[-1][0]: res[-1][1] += 1 else: res.append([c, 1]) return res N, K = list(map(int, input().split())) S = eval(input()) cs = run_length_compress(S) M = len(cs) ans = 0 tot = 0 right = 0 zeros = 0 for left in range(M): while right < M and zeros + (cs[right][0] == "0") <= K: if cs[right][0] == "0": zeros += 1 tot += cs[right][1] right += 1 ans = max(ans, tot) if left == right: right += 1 else: if cs[left][0] == "0": zeros -= 1 tot -= cs[left][1] print(ans)
32
36
728
699
def compress(S): res = [] prev = "aa" for c in S: if c != prev: res.append([c, 1]) else: res[-1][1] += 1 prev = c return res N, K = list(map(int, input().split())) S = list(map(int, eval(input()))) S_comp = compress(S) M = len(S_comp) ans = 0 total = 0 right = 0 zero_chunks_cnt = 0 for left in range(M): while right < M and zero_chunks_cnt + 1 - S_comp[right][0] <= K: zero_chunks_cnt += 1 - S_comp[right][0] total += S_comp[right][1] right += 1 ans = max(ans, total) if right == left: right += 1 else: zero_chunks_cnt -= 1 - S_comp[left][0] total -= S_comp[left][1] print(ans)
def run_length_compress(S): res = [[S[0], 1]] for c in S[1:]: if c == res[-1][0]: res[-1][1] += 1 else: res.append([c, 1]) return res N, K = list(map(int, input().split())) S = eval(input()) cs = run_length_compress(S) M = len(cs) ans = 0 tot = 0 right = 0 zeros = 0 for left in range(M): while right < M and zeros + (cs[right][0] == "0") <= K: if cs[right][0] == "0": zeros += 1 tot += cs[right][1] right += 1 ans = max(ans, tot) if left == right: right += 1 else: if cs[left][0] == "0": zeros -= 1 tot -= cs[left][1] print(ans)
false
11.111111
[ "-def compress(S):", "- res = []", "- prev = \"aa\"", "- for c in S:", "- if c != prev:", "+def run_length_compress(S):", "+ res = [[S[0], 1]]", "+ for c in S[1:]:", "+ if c == res[-1][0]:", "+ res[-1][1] += 1", "+ else:", "- else:", "- res[-1][1] += 1", "- prev = c", "-S = list(map(int, eval(input())))", "-S_comp = compress(S)", "-M = len(S_comp)", "+S = eval(input())", "+cs = run_length_compress(S)", "+M = len(cs)", "-total = 0", "+tot = 0", "-zero_chunks_cnt = 0", "+zeros = 0", "- while right < M and zero_chunks_cnt + 1 - S_comp[right][0] <= K:", "- zero_chunks_cnt += 1 - S_comp[right][0]", "- total += S_comp[right][1]", "+ while right < M and zeros + (cs[right][0] == \"0\") <= K:", "+ if cs[right][0] == \"0\":", "+ zeros += 1", "+ tot += cs[right][1]", "- ans = max(ans, total)", "- if right == left:", "+ ans = max(ans, tot)", "+ if left == right:", "- zero_chunks_cnt -= 1 - S_comp[left][0]", "- total -= S_comp[left][1]", "+ if cs[left][0] == \"0\":", "+ zeros -= 1", "+ tot -= cs[left][1]" ]
false
0.037656
0.166447
0.226236
[ "s016324890", "s410187179" ]
u696805736
p03436
python
s965345679
s954065706
311
27
43,500
3,440
Accepted
Accepted
91.32
from collections import deque INF = 10101010 def main(): h,w = list(map(int,input().split())) s = [] for i in range(h): s.append(eval(input())) d = [[INF for j in range(w)] for i in range(h)] d[0][0] = 0 que = deque() que.append((0,0)) while len(que): y,x = que.pop() for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]: nx,ny = x+dx, y+dy if 0 <= nx < w and 0 <= ny < h: if s[ny][nx] != '#' and d[ny][nx]>d[y][x]+1: d[ny][nx] = d[y][x]+1 que.append((ny,nx)) if d[h-1][w-1] == INF: return -1 ans = -(d[h-1][w-1]+1) for i in range(h): for j in range(w): if s[i][j] == '.': ans += 1 return ans if __name__ == '__main__': print((main()))
from collections import deque INF = 10101010 def main(): h,w = list(map(int,input().split())) s = [] for i in range(h): s.append(eval(input())) ans = 0 for i in range(h): ans += s[i].count('.') d = [[INF for j in range(w)] for i in range(h)] d[0][0] = 0 que = deque() que.append((0,0)) while que: y,x = que.pop() if (y,x) == (h-1,w-1): return ans - (d[h-1][w-1]+1) for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]: nx,ny = x+dx, y+dy if 0 <= nx < w and 0 <= ny < h: if s[ny][nx] != '#' and d[ny][nx]>d[y][x]+1: d[ny][nx] = d[y][x]+1 que.appendleft((ny,nx)) return -1 if __name__ == '__main__': print((main()))
35
34
850
808
from collections import deque INF = 10101010 def main(): h, w = list(map(int, input().split())) s = [] for i in range(h): s.append(eval(input())) d = [[INF for j in range(w)] for i in range(h)] d[0][0] = 0 que = deque() que.append((0, 0)) while len(que): y, x = que.pop() for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h: if s[ny][nx] != "#" and d[ny][nx] > d[y][x] + 1: d[ny][nx] = d[y][x] + 1 que.append((ny, nx)) if d[h - 1][w - 1] == INF: return -1 ans = -(d[h - 1][w - 1] + 1) for i in range(h): for j in range(w): if s[i][j] == ".": ans += 1 return ans if __name__ == "__main__": print((main()))
from collections import deque INF = 10101010 def main(): h, w = list(map(int, input().split())) s = [] for i in range(h): s.append(eval(input())) ans = 0 for i in range(h): ans += s[i].count(".") d = [[INF for j in range(w)] for i in range(h)] d[0][0] = 0 que = deque() que.append((0, 0)) while que: y, x = que.pop() if (y, x) == (h - 1, w - 1): return ans - (d[h - 1][w - 1] + 1) for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h: if s[ny][nx] != "#" and d[ny][nx] > d[y][x] + 1: d[ny][nx] = d[y][x] + 1 que.appendleft((ny, nx)) return -1 if __name__ == "__main__": print((main()))
false
2.857143
[ "+ ans = 0", "+ for i in range(h):", "+ ans += s[i].count(\".\")", "- while len(que):", "+ while que:", "+ if (y, x) == (h - 1, w - 1):", "+ return ans - (d[h - 1][w - 1] + 1)", "- que.append((ny, nx))", "- if d[h - 1][w - 1] == INF:", "- return -1", "- ans = -(d[h - 1][w - 1] + 1)", "- for i in range(h):", "- for j in range(w):", "- if s[i][j] == \".\":", "- ans += 1", "- return ans", "+ que.appendleft((ny, nx))", "+ return -1" ]
false
0.036593
0.034571
1.058483
[ "s965345679", "s954065706" ]
u392319141
p03330
python
s796591381
s020803380
1,002
197
5,620
3,436
Accepted
Accepted
80.34
N, C = list(map(int, input().split())) D = [] c = [] for i in range(C) : line = list(map(int, input().split())) D.append(line) for i in range(N) : line = list(map(int, input().split())) c.append(line) colorCount = [[0 for _ in range(C + 1)] for _ in range(3)] # colorCount[index][color] for i in range(N) : for j in range(N) : colorCount[(i + j + 2) % 3][c[i][j]] += 1 ans = float('inf') for firstColor in range(1, C + 1) : for secondColor in range(1, C + 1) : for thirdColor in range(1, C + 1) : if firstColor == secondColor or secondColor == thirdColor or thirdColor == firstColor : continue cost = 0 for dist, toColor in enumerate([secondColor, thirdColor, firstColor]) : for fromColor in range(1, C + 1) : if toColor == fromColor : continue cost += colorCount[dist][fromColor] * D[fromColor - 1][toColor - 1] ans = min(ans, cost) print(ans)
from collections import defaultdict from itertools import product N, C = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(C)] colors = defaultdict(lambda : defaultdict(int)) for h in range(1, N + 1): for w, c in enumerate(map(int, input().split()), start=1): colors[(h + w) % 3][c] += 1 cost = [[None] * C for _ in range(3)] for i in range(3): for color in range(1, C + 1): cnt = 0 for c, k in list(colors[i].items()): cnt += D[c - 1][color - 1] * k cost[i][color - 1] = cnt ans = 10**10 for cs in product(list(range(C)), repeat=3): if len(set(cs)) == 3: cnt = 0 for i, c in enumerate(cs): cnt += cost[i][c] ans = min(ans, cnt) print(ans)
32
30
1,059
785
N, C = list(map(int, input().split())) D = [] c = [] for i in range(C): line = list(map(int, input().split())) D.append(line) for i in range(N): line = list(map(int, input().split())) c.append(line) colorCount = [[0 for _ in range(C + 1)] for _ in range(3)] # colorCount[index][color] for i in range(N): for j in range(N): colorCount[(i + j + 2) % 3][c[i][j]] += 1 ans = float("inf") for firstColor in range(1, C + 1): for secondColor in range(1, C + 1): for thirdColor in range(1, C + 1): if ( firstColor == secondColor or secondColor == thirdColor or thirdColor == firstColor ): continue cost = 0 for dist, toColor in enumerate([secondColor, thirdColor, firstColor]): for fromColor in range(1, C + 1): if toColor == fromColor: continue cost += colorCount[dist][fromColor] * D[fromColor - 1][toColor - 1] ans = min(ans, cost) print(ans)
from collections import defaultdict from itertools import product N, C = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(C)] colors = defaultdict(lambda: defaultdict(int)) for h in range(1, N + 1): for w, c in enumerate(map(int, input().split()), start=1): colors[(h + w) % 3][c] += 1 cost = [[None] * C for _ in range(3)] for i in range(3): for color in range(1, C + 1): cnt = 0 for c, k in list(colors[i].items()): cnt += D[c - 1][color - 1] * k cost[i][color - 1] = cnt ans = 10**10 for cs in product(list(range(C)), repeat=3): if len(set(cs)) == 3: cnt = 0 for i, c in enumerate(cs): cnt += cost[i][c] ans = min(ans, cnt) print(ans)
false
6.25
[ "+from collections import defaultdict", "+from itertools import product", "+", "-D = []", "-c = []", "-for i in range(C):", "- line = list(map(int, input().split()))", "- D.append(line)", "-for i in range(N):", "- line = list(map(int, input().split()))", "- c.append(line)", "-colorCount = [[0 for _ in range(C + 1)] for _ in range(3)] # colorCount[index][color]", "-for i in range(N):", "- for j in range(N):", "- colorCount[(i + j + 2) % 3][c[i][j]] += 1", "-ans = float(\"inf\")", "-for firstColor in range(1, C + 1):", "- for secondColor in range(1, C + 1):", "- for thirdColor in range(1, C + 1):", "- if (", "- firstColor == secondColor", "- or secondColor == thirdColor", "- or thirdColor == firstColor", "- ):", "- continue", "- cost = 0", "- for dist, toColor in enumerate([secondColor, thirdColor, firstColor]):", "- for fromColor in range(1, C + 1):", "- if toColor == fromColor:", "- continue", "- cost += colorCount[dist][fromColor] * D[fromColor - 1][toColor - 1]", "- ans = min(ans, cost)", "+D = [tuple(map(int, input().split())) for _ in range(C)]", "+colors = defaultdict(lambda: defaultdict(int))", "+for h in range(1, N + 1):", "+ for w, c in enumerate(map(int, input().split()), start=1):", "+ colors[(h + w) % 3][c] += 1", "+cost = [[None] * C for _ in range(3)]", "+for i in range(3):", "+ for color in range(1, C + 1):", "+ cnt = 0", "+ for c, k in list(colors[i].items()):", "+ cnt += D[c - 1][color - 1] * k", "+ cost[i][color - 1] = cnt", "+ans = 10**10", "+for cs in product(list(range(C)), repeat=3):", "+ if len(set(cs)) == 3:", "+ cnt = 0", "+ for i, c in enumerate(cs):", "+ cnt += cost[i][c]", "+ ans = min(ans, cnt)" ]
false
0.087419
0.0353
2.476468
[ "s796591381", "s020803380" ]
u970197315
p03331
python
s886573680
s914187097
370
282
3,064
9,080
Accepted
Accepted
23.78
# B si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def calc(a,b): sa=list(str(a)) sb=list(str(b)) res=0 for aa in sa: res+=int(aa) for bb in sb: res+=int(bb) return res n=ni() ans=10**6 for i in range(1,n): a=i b=n-i t=calc(a,b) ans=min(ans,t) print(ans)
n=int(eval(input())) ans=10**18 for a in range(1,n): b=n-a tmp=0 for aa in str(a): tmp+=int(aa) for bb in str(b): tmp+=int(bb) ans=min(ans,tmp) print(ans)
24
11
421
176
# B si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def calc(a, b): sa = list(str(a)) sb = list(str(b)) res = 0 for aa in sa: res += int(aa) for bb in sb: res += int(bb) return res n = ni() ans = 10**6 for i in range(1, n): a = i b = n - i t = calc(a, b) ans = min(ans, t) print(ans)
n = int(eval(input())) ans = 10**18 for a in range(1, n): b = n - a tmp = 0 for aa in str(a): tmp += int(aa) for bb in str(b): tmp += int(bb) ans = min(ans, tmp) print(ans)
false
54.166667
[ "-# B", "-si = lambda: eval(input())", "-ni = lambda: int(eval(input()))", "-nm = lambda: list(map(int, input().split()))", "-nl = lambda: list(map(int, input().split()))", "-", "-", "-def calc(a, b):", "- sa = list(str(a))", "- sb = list(str(b))", "- res = 0", "- for aa in sa:", "- res += int(aa)", "- for bb in sb:", "- res += int(bb)", "- return res", "-", "-", "-n = ni()", "-ans = 10**6", "-for i in range(1, n):", "- a = i", "- b = n - i", "- t = calc(a, b)", "- ans = min(ans, t)", "+n = int(eval(input()))", "+ans = 10**18", "+for a in range(1, n):", "+ b = n - a", "+ tmp = 0", "+ for aa in str(a):", "+ tmp += int(aa)", "+ for bb in str(b):", "+ tmp += int(bb)", "+ ans = min(ans, tmp)" ]
false
0.133382
0.190133
0.701522
[ "s886573680", "s914187097" ]
u494927057
p04031
python
s345562926
s444729271
23
19
2,940
2,940
Accepted
Accepted
17.39
N = int(eval(input())) a = list(map(int, input().split())) def get_cost(now, target): return (now - target) * (now - target) ans = 10000000 for i in range(min(a), max(a) + 1): cost_sum = 0 for j in a: cost_sum += get_cost(j, i) if cost_sum < ans: ans = cost_sum print(ans)
N = int(eval(input())) a = list(map(int, input().split())) mean = int(round(sum(a) / len(a))) ans = 0 for i in range(len(a)): ans += (a[i] - mean) ** 2 print(ans)
16
9
318
171
N = int(eval(input())) a = list(map(int, input().split())) def get_cost(now, target): return (now - target) * (now - target) ans = 10000000 for i in range(min(a), max(a) + 1): cost_sum = 0 for j in a: cost_sum += get_cost(j, i) if cost_sum < ans: ans = cost_sum print(ans)
N = int(eval(input())) a = list(map(int, input().split())) mean = int(round(sum(a) / len(a))) ans = 0 for i in range(len(a)): ans += (a[i] - mean) ** 2 print(ans)
false
43.75
[ "-", "-", "-def get_cost(now, target):", "- return (now - target) * (now - target)", "-", "-", "-ans = 10000000", "-for i in range(min(a), max(a) + 1):", "- cost_sum = 0", "- for j in a:", "- cost_sum += get_cost(j, i)", "- if cost_sum < ans:", "- ans = cost_sum", "+mean = int(round(sum(a) / len(a)))", "+ans = 0", "+for i in range(len(a)):", "+ ans += (a[i] - mean) ** 2" ]
false
0.105518
0.034276
3.07851
[ "s345562926", "s444729271" ]
u608088992
p02887
python
s227621894
s303095409
41
32
3,316
3,316
Accepted
Accepted
21.95
N = int(eval(input())) S = eval(input()) now = "" ans = 0 for i in range(N): if S[i] != now: ans += 1 now = S[i] print(ans)
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) S = input().strip("\n") S += "0" count = 0 nowCol = S[0] for i in range(1, N + 1): if S[i] != nowCol: count += 1 nowCol = S[i] print(count) return 0 if __name__ == "__main__": solve()
9
19
140
344
N = int(eval(input())) S = eval(input()) now = "" ans = 0 for i in range(N): if S[i] != now: ans += 1 now = S[i] print(ans)
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) S = input().strip("\n") S += "0" count = 0 nowCol = S[0] for i in range(1, N + 1): if S[i] != nowCol: count += 1 nowCol = S[i] print(count) return 0 if __name__ == "__main__": solve()
false
52.631579
[ "-N = int(eval(input()))", "-S = eval(input())", "-now = \"\"", "-ans = 0", "-for i in range(N):", "- if S[i] != now:", "- ans += 1", "- now = S[i]", "-print(ans)", "+import sys", "+", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ S = input().strip(\"\\n\")", "+ S += \"0\"", "+ count = 0", "+ nowCol = S[0]", "+ for i in range(1, N + 1):", "+ if S[i] != nowCol:", "+ count += 1", "+ nowCol = S[i]", "+ print(count)", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.038534
0.042514
0.906388
[ "s227621894", "s303095409" ]
u633068244
p01283
python
s349945055
s978007725
17,590
15,600
4,452
4,448
Accepted
Accepted
11.31
import math M = 256 while 1: N = int(input()) if N == 0: break H = 1e10 l = list(map(int,input().split())) ans = [0,0,0] for S in range(16): for A in range(16): for C in range(16): R = S O = [0]*N for i in range(N): R = (A*R+C)%M O[i] = (l[i]+R)%M L = [0]*256 for i in O: L[i] += 1 tmp = -sum(float(i)/N*math.log(float(i)/N,2) for i in L if i != 0) if tmp < H: H = tmp ans = [S,A,C] print(" ".join(map(str,ans)))
import math M = 256 while 1: N = int(input()) if N == 0: break H = 1e10 l = list(map(int,input().split())) ans = [0,0,0] for S in range(16): for A in range(16): for C in range(16): R = S O = [0]*256 for i in range(N): R = (A*R+C)%M O[(l[i]+R)%M] += 1 tmp = -sum(float(x)/N*math.log(float(x)/N,2) for x in O if x != 0) if tmp < H: H = tmp ans = [S,A,C] print(" ".join(map(str,ans)))
23
21
675
610
import math M = 256 while 1: N = int(input()) if N == 0: break H = 1e10 l = list(map(int, input().split())) ans = [0, 0, 0] for S in range(16): for A in range(16): for C in range(16): R = S O = [0] * N for i in range(N): R = (A * R + C) % M O[i] = (l[i] + R) % M L = [0] * 256 for i in O: L[i] += 1 tmp = -sum( float(i) / N * math.log(float(i) / N, 2) for i in L if i != 0 ) if tmp < H: H = tmp ans = [S, A, C] print(" ".join(map(str, ans)))
import math M = 256 while 1: N = int(input()) if N == 0: break H = 1e10 l = list(map(int, input().split())) ans = [0, 0, 0] for S in range(16): for A in range(16): for C in range(16): R = S O = [0] * 256 for i in range(N): R = (A * R + C) % M O[(l[i] + R) % M] += 1 tmp = -sum( float(x) / N * math.log(float(x) / N, 2) for x in O if x != 0 ) if tmp < H: H = tmp ans = [S, A, C] print(" ".join(map(str, ans)))
false
8.695652
[ "- O = [0] * N", "+ O = [0] * 256", "- O[i] = (l[i] + R) % M", "- L = [0] * 256", "- for i in O:", "- L[i] += 1", "+ O[(l[i] + R) % M] += 1", "- float(i) / N * math.log(float(i) / N, 2) for i in L if i != 0", "+ float(x) / N * math.log(float(x) / N, 2) for x in O if x != 0" ]
false
0.41385
0.365265
1.133014
[ "s349945055", "s978007725" ]
u934442292
p03240
python
s837940819
s048835635
317
38
9,156
9,036
Accepted
Accepted
88.01
import sys from itertools import product input = sys.stdin.readline def main(): N = int(eval(input())) X = [0] * N Y = [0] * N H = [0] * N for i in range(N): X[i], Y[i], H[i] = list(map(int, input().split())) for Cx, Cy in product(list(range(101)), repeat=2): Ch = set() Ch_upper = float("inf") for x, y, h in zip(X, Y, H): a = abs(x - Cx) + abs(y - Cy) if h == 0: Ch_upper = min(Ch_upper, a) else: Ch.add(h + a) if len(Ch) != 1: continue else: Ch = Ch.pop() if Ch <= Ch_upper: ans = f"{Cx} {Cy} {Ch}" break print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N = int(eval(input())) xyh = [None] * N for i in range(N): xyh[i] = tuple(map(int, input().split())) for i in range(N): if xyh[i][2] > 0: Bx, By, Bh = xyh[i] break for Cx in range(0, 101): for Cy in range(0, 101): H = Bh + abs(Bx - Cx) + abs(By - Cy) is_ok = True for x, y, h in xyh: if max(H - abs(x - Cx) - abs(y - Cy), 0) != h: is_ok = False break if is_ok: print((Cx, Cy, H)) exit() if __name__ == "__main__": main()
36
31
793
708
import sys from itertools import product input = sys.stdin.readline def main(): N = int(eval(input())) X = [0] * N Y = [0] * N H = [0] * N for i in range(N): X[i], Y[i], H[i] = list(map(int, input().split())) for Cx, Cy in product(list(range(101)), repeat=2): Ch = set() Ch_upper = float("inf") for x, y, h in zip(X, Y, H): a = abs(x - Cx) + abs(y - Cy) if h == 0: Ch_upper = min(Ch_upper, a) else: Ch.add(h + a) if len(Ch) != 1: continue else: Ch = Ch.pop() if Ch <= Ch_upper: ans = f"{Cx} {Cy} {Ch}" break print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N = int(eval(input())) xyh = [None] * N for i in range(N): xyh[i] = tuple(map(int, input().split())) for i in range(N): if xyh[i][2] > 0: Bx, By, Bh = xyh[i] break for Cx in range(0, 101): for Cy in range(0, 101): H = Bh + abs(Bx - Cx) + abs(By - Cy) is_ok = True for x, y, h in xyh: if max(H - abs(x - Cx) - abs(y - Cy), 0) != h: is_ok = False break if is_ok: print((Cx, Cy, H)) exit() if __name__ == "__main__": main()
false
13.888889
[ "-from itertools import product", "- X = [0] * N", "- Y = [0] * N", "- H = [0] * N", "+ xyh = [None] * N", "- X[i], Y[i], H[i] = list(map(int, input().split()))", "- for Cx, Cy in product(list(range(101)), repeat=2):", "- Ch = set()", "- Ch_upper = float(\"inf\")", "- for x, y, h in zip(X, Y, H):", "- a = abs(x - Cx) + abs(y - Cy)", "- if h == 0:", "- Ch_upper = min(Ch_upper, a)", "- else:", "- Ch.add(h + a)", "- if len(Ch) != 1:", "- continue", "- else:", "- Ch = Ch.pop()", "- if Ch <= Ch_upper:", "- ans = f\"{Cx} {Cy} {Ch}\"", "- break", "- print(ans)", "+ xyh[i] = tuple(map(int, input().split()))", "+ for i in range(N):", "+ if xyh[i][2] > 0:", "+ Bx, By, Bh = xyh[i]", "+ break", "+ for Cx in range(0, 101):", "+ for Cy in range(0, 101):", "+ H = Bh + abs(Bx - Cx) + abs(By - Cy)", "+ is_ok = True", "+ for x, y, h in xyh:", "+ if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:", "+ is_ok = False", "+ break", "+ if is_ok:", "+ print((Cx, Cy, H))", "+ exit()" ]
false
0.100299
0.048015
2.088896
[ "s837940819", "s048835635" ]
u191874006
p03045
python
s958722150
s225482844
804
643
123,664
90,160
Accepted
Accepted
20.02
#!/usr/bin/env python3 #abc126 e import sys sys.setrecursionlimit(1000000) N,M = list(map(int,input().split())) XYZ = [list(map(int,input().split())) for _ in range(M)] G = [[] for _ in range(N)] for i in XYZ: G[i[0]-1].append(i[1]) G[i[1]-1].append(i[0]) check = [False for _ in range(N)]#各頂点を訪問したかどうか def DFS(G,s): check[s-1] = True for i in G[s-1]: if not check[i-1]: DFS(G,i) ans = 0 for i in range(N): if not check[i]: DFS(G,i+1) ans += 1 print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n,m = LI() def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def same(x,y): return root(x) == root(y) def union(x,y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 par = [i for i in range(n)] rank = [0 for _ in range(n)] xyz = [LI() for _ in range(m)] for x,y,z in xyz: if root(x-1) != root(y-1): union(x-1,y-1) f = defaultdict(int) for i in range(n): f[root(i)] = 1 ans = 0 for i,j in list(f.items()): if j != 1: continue ans += 1 print(ans)
27
60
542
1,239
#!/usr/bin/env python3 # abc126 e import sys sys.setrecursionlimit(1000000) N, M = list(map(int, input().split())) XYZ = [list(map(int, input().split())) for _ in range(M)] G = [[] for _ in range(N)] for i in XYZ: G[i[0] - 1].append(i[1]) G[i[1] - 1].append(i[0]) check = [False for _ in range(N)] # 各頂点を訪問したかどうか def DFS(G, s): check[s - 1] = True for i in G[s - 1]: if not check[i - 1]: DFS(G, i) ans = 0 for i in range(N): if not check[i]: DFS(G, i + 1) ans += 1 print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n, m = LI() def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def same(x, y): return root(x) == root(y) def union(x, y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 par = [i for i in range(n)] rank = [0 for _ in range(n)] xyz = [LI() for _ in range(m)] for x, y, z in xyz: if root(x - 1) != root(y - 1): union(x - 1, y - 1) f = defaultdict(int) for i in range(n): f[root(i)] = 1 ans = 0 for i, j in list(f.items()): if j != 1: continue ans += 1 print(ans)
false
55
[ "-# abc126 e", "+import math", "+from bisect import bisect_right as br", "+from bisect import bisect_left as bl", "-N, M = list(map(int, input().split()))", "-XYZ = [list(map(int, input().split())) for _ in range(M)]", "-G = [[] for _ in range(N)]", "-for i in XYZ:", "- G[i[0] - 1].append(i[1])", "- G[i[1] - 1].append(i[0])", "-check = [False for _ in range(N)] # 各頂点を訪問したかどうか", "+from heapq import heappush, heappop, heappushpop", "+from collections import defaultdict", "+from itertools import accumulate", "+from collections import Counter", "+from collections import deque", "+from operator import itemgetter", "+from itertools import permutations", "+", "+mod = 10**9 + 7", "+inf = float(\"inf\")", "-def DFS(G, s):", "- check[s - 1] = True", "- for i in G[s - 1]:", "- if not check[i - 1]:", "- DFS(G, i)", "+def I():", "+ return int(sys.stdin.readline())", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+n, m = LI()", "+", "+", "+def root(x):", "+ if par[x] == x:", "+ return x", "+ par[x] = root(par[x])", "+ return par[x]", "+", "+", "+def same(x, y):", "+ return root(x) == root(y)", "+", "+", "+def union(x, y):", "+ x = root(x)", "+ y = root(y)", "+ if rank[x] < rank[y]:", "+ par[x] = y", "+ else:", "+ par[y] = x", "+ if rank[x] == rank[y]:", "+ rank[x] += 1", "+", "+", "+par = [i for i in range(n)]", "+rank = [0 for _ in range(n)]", "+xyz = [LI() for _ in range(m)]", "+for x, y, z in xyz:", "+ if root(x - 1) != root(y - 1):", "+ union(x - 1, y - 1)", "+f = defaultdict(int)", "+for i in range(n):", "+ f[root(i)] = 1", "-for i in range(N):", "- if not check[i]:", "- DFS(G, i + 1)", "- ans += 1", "+for i, j in list(f.items()):", "+ if j != 1:", "+ continue", "+ ans += 1" ]
false
0.058289
0.153817
0.378954
[ "s958722150", "s225482844" ]
u970197315
p03329
python
s544731047
s305253995
614
439
3,864
9,380
Accepted
Accepted
28.5
n=int(eval(input())) m=[int(pow(6,i)) for i in range(7)] m9=[int(pow(9,i)) for i in range(1,6)] m+=m9 m.sort(reverse=True) # print(m) dp=[10**18 for i in range(n+1)] dp[0]=0 for i in range(1,n+1): for j in m: if i-j>=0: dp[i]=min(dp[i],dp[i-j]+1) # print(dp) print((dp[n]))
n=int(eval(input())) l6=[6**i for i in range(7)] l9=[9**i for i in range(1,6)] m=l6+l9 m.sort() inf=float("inf") dp=[inf]*(10**5+1) dp[0]=0 dp[1]=1 for i in range(1,n+1): for mi in m: if i-mi>=0: dp[i]=min(dp[i-mi]+1,dp[i]) print((dp[n]))
14
14
290
256
n = int(eval(input())) m = [int(pow(6, i)) for i in range(7)] m9 = [int(pow(9, i)) for i in range(1, 6)] m += m9 m.sort(reverse=True) # print(m) dp = [10**18 for i in range(n + 1)] dp[0] = 0 for i in range(1, n + 1): for j in m: if i - j >= 0: dp[i] = min(dp[i], dp[i - j] + 1) # print(dp) print((dp[n]))
n = int(eval(input())) l6 = [6**i for i in range(7)] l9 = [9**i for i in range(1, 6)] m = l6 + l9 m.sort() inf = float("inf") dp = [inf] * (10**5 + 1) dp[0] = 0 dp[1] = 1 for i in range(1, n + 1): for mi in m: if i - mi >= 0: dp[i] = min(dp[i - mi] + 1, dp[i]) print((dp[n]))
false
0
[ "-m = [int(pow(6, i)) for i in range(7)]", "-m9 = [int(pow(9, i)) for i in range(1, 6)]", "-m += m9", "-m.sort(reverse=True)", "-# print(m)", "-dp = [10**18 for i in range(n + 1)]", "+l6 = [6**i for i in range(7)]", "+l9 = [9**i for i in range(1, 6)]", "+m = l6 + l9", "+m.sort()", "+inf = float(\"inf\")", "+dp = [inf] * (10**5 + 1)", "+dp[1] = 1", "- for j in m:", "- if i - j >= 0:", "- dp[i] = min(dp[i], dp[i - j] + 1)", "-# print(dp)", "+ for mi in m:", "+ if i - mi >= 0:", "+ dp[i] = min(dp[i - mi] + 1, dp[i])" ]
false
0.092493
0.090876
1.017798
[ "s544731047", "s305253995" ]
u033524082
p02768
python
s497142329
s063186467
1,508
142
3,060
3,064
Accepted
Accepted
90.58
def cmb(n, r, mod): c=1 for i in range(1, r+1): c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod return c n, a, b = list(map(int, input().split())) MOD = 10**9 + 7 print(((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD))
n,a,b=list(map(int,input().split())) mod=10**9+7 def comb(n,r): P=1 R=1 for i in range(r): P=P*(n-i)%mod R=R*(r-i)%mod return P*pow(R,mod-2,mod)%mod combN=pow(2,n,mod)-1 print(((combN-comb(n,a)-comb(n,b))%mod))
9
13
250
248
def cmb(n, r, mod): c = 1 for i in range(1, r + 1): c = (c * (n - i + 1) * pow(i, mod - 2, mod)) % mod return c n, a, b = list(map(int, input().split())) MOD = 10**9 + 7 print(((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD))
n, a, b = list(map(int, input().split())) mod = 10**9 + 7 def comb(n, r): P = 1 R = 1 for i in range(r): P = P * (n - i) % mod R = R * (r - i) % mod return P * pow(R, mod - 2, mod) % mod combN = pow(2, n, mod) - 1 print(((combN - comb(n, a) - comb(n, b)) % mod))
false
30.769231
[ "-def cmb(n, r, mod):", "- c = 1", "- for i in range(1, r + 1):", "- c = (c * (n - i + 1) * pow(i, mod - 2, mod)) % mod", "- return c", "+n, a, b = list(map(int, input().split()))", "+mod = 10**9 + 7", "-n, a, b = list(map(int, input().split()))", "-MOD = 10**9 + 7", "-print(((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD))", "+def comb(n, r):", "+ P = 1", "+ R = 1", "+ for i in range(r):", "+ P = P * (n - i) % mod", "+ R = R * (r - i) % mod", "+ return P * pow(R, mod - 2, mod) % mod", "+", "+", "+combN = pow(2, n, mod) - 1", "+print(((combN - comb(n, a) - comb(n, b)) % mod))" ]
false
1.010849
0.148882
6.789591
[ "s497142329", "s063186467" ]
u502731482
p02743
python
s055895983
s422802372
35
17
5,076
2,940
Accepted
Accepted
51.43
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) """ print(sqrt(a), sqrt(b)) print(Decimal(sqrt(a)), sqrt(b)) """ print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
from math import sqrt a, b, c = list(map(int, input().split())) print(("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No"))
10
4
239
134
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) """ print(sqrt(a), sqrt(b)) print(Decimal(sqrt(a)), sqrt(b)) """ print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
from math import sqrt a, b, c = list(map(int, input().split())) print(("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No"))
false
60
[ "-from decimal import *", "-\"\"\"", "-print(sqrt(a), sqrt(b))", "-print(Decimal(sqrt(a)), sqrt(b))", "-\"\"\"", "-print((\"Yes\" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else \"No\"))", "+print((\"Yes\" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else \"No\"))" ]
false
0.057586
0.052174
1.103722
[ "s055895983", "s422802372" ]
u968166680
p02947
python
s509178663
s080735300
239
145
162,316
29,544
Accepted
Accepted
39.33
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = [0] * N for i in range(N): S[i] = readline().strip() d = defaultdict(int) for s in S: c = [0] * 26 for l in s: c[ord(l) - 97] += 1 d[tuple(c)] += 1 ans = 0 for n in list(d.values()): if n > 1: ans += n * (n - 1) // 2 print(ans) return if __name__ == '__main__': main()
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = [0] * N for i in range(N): S[i] = readline().strip() d = defaultdict(int) for s in S: d[''.join(sorted(s))] += 1 ans = 0 for n in list(d.values()): if n > 1: ans += n * (n - 1) // 2 print(ans) return if __name__ == '__main__': main()
35
32
638
572
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = [0] * N for i in range(N): S[i] = readline().strip() d = defaultdict(int) for s in S: c = [0] * 26 for l in s: c[ord(l) - 97] += 1 d[tuple(c)] += 1 ans = 0 for n in list(d.values()): if n > 1: ans += n * (n - 1) // 2 print(ans) return if __name__ == "__main__": main()
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = [0] * N for i in range(N): S[i] = readline().strip() d = defaultdict(int) for s in S: d["".join(sorted(s))] += 1 ans = 0 for n in list(d.values()): if n > 1: ans += n * (n - 1) // 2 print(ans) return if __name__ == "__main__": main()
false
8.571429
[ "- c = [0] * 26", "- for l in s:", "- c[ord(l) - 97] += 1", "- d[tuple(c)] += 1", "+ d[\"\".join(sorted(s))] += 1" ]
false
0.006812
0.041231
0.165208
[ "s509178663", "s080735300" ]
u037430802
p03157
python
s331992792
s982727776
1,178
921
86,712
22,192
Accepted
Accepted
21.82
from collections import defaultdict H,W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] es = defaultdict(list) for i in range(H): for j in range(W): # 横 if j != W-1 and S[i][j] != S[i][j+1]: es[(i,j)].append((i,j+1)) es[(i,j+1)].append((i,j)) # 縦 if i != H-1 and S[i][j] != S[i+1][j]: es[(i,j)].append((i+1,j)) es[(i+1,j)].append((i,j)) ans = 0 checked = [[False for _ in range(W)] for _ in range(H)] stack = list(es.keys()) for i,j in stack: # 開始位置 if checked[i][j]: continue if S[i][j] == "#": cnt_b = 1 cnt_w = 0 else: cnt_b = 0 cnt_w = 1 checked[i][j] = True ns = es[(i,j)] #tmp = [] while ns: tmp = [] for a,b in ns: if checked[a][b] == True: continue checked[a][b] = True if S[a][b] == "#": cnt_b += 1 else: cnt_w += 1 for c,d in es[(a,b)]: if not checked[c][d]: tmp.append((c,d)) if len(tmp) > 0: ns = tmp else: ns = [] ans += cnt_b * cnt_w print(ans)
from collections import Counter H,W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] class UnionFind: def __init__(self,N): self.parent = [i for i in range(N)] self.rank = [0] * N self.count = 0 def root(self,a): if self.parent[a] == a: return a else: self.parent[a] = self.root(self.parent[a]) return self.parent[a] def is_same(self,a,b): return self.root(a) == self.root(b) def unite(self,a,b): ra = self.root(a) rb = self.root(b) if ra == rb: return if self.rank[ra] < self.rank[rb]: self.parent[ra] = rb else: self.parent[rb] = ra if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1 self.count += 1 uf = UnionFind(H*W) for i in range(H): for j in range(W): # 横 if j != W-1 and S[i][j] != S[i][j+1]: uf.unite(i*W+j, i*W+j+1) # 縦 if i != H-1 and S[i][j] != S[i+1][j]: uf.unite(i*W+j, (i+1)*W+j) for i in range(H*W): uf.root(i) black = Counter() white = Counter() #あるユニオンに所属(#.#.の移動できる塊)の#と.の数を数える for i in range(H): for j in range(W): k = i*W+j if S[i][j] == "#": black[uf.root(k)] += 1 else: white[uf.root(k)] += 1 #ユニオンごとに足し合わせ ans = 0 for k in list(black.keys()): ans += black[k] * white[k] print(ans)
61
65
1,299
1,511
from collections import defaultdict H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] es = defaultdict(list) for i in range(H): for j in range(W): # 横 if j != W - 1 and S[i][j] != S[i][j + 1]: es[(i, j)].append((i, j + 1)) es[(i, j + 1)].append((i, j)) # 縦 if i != H - 1 and S[i][j] != S[i + 1][j]: es[(i, j)].append((i + 1, j)) es[(i + 1, j)].append((i, j)) ans = 0 checked = [[False for _ in range(W)] for _ in range(H)] stack = list(es.keys()) for i, j in stack: # 開始位置 if checked[i][j]: continue if S[i][j] == "#": cnt_b = 1 cnt_w = 0 else: cnt_b = 0 cnt_w = 1 checked[i][j] = True ns = es[(i, j)] # tmp = [] while ns: tmp = [] for a, b in ns: if checked[a][b] == True: continue checked[a][b] = True if S[a][b] == "#": cnt_b += 1 else: cnt_w += 1 for c, d in es[(a, b)]: if not checked[c][d]: tmp.append((c, d)) if len(tmp) > 0: ns = tmp else: ns = [] ans += cnt_b * cnt_w print(ans)
from collections import Counter H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] class UnionFind: def __init__(self, N): self.parent = [i for i in range(N)] self.rank = [0] * N self.count = 0 def root(self, a): if self.parent[a] == a: return a else: self.parent[a] = self.root(self.parent[a]) return self.parent[a] def is_same(self, a, b): return self.root(a) == self.root(b) def unite(self, a, b): ra = self.root(a) rb = self.root(b) if ra == rb: return if self.rank[ra] < self.rank[rb]: self.parent[ra] = rb else: self.parent[rb] = ra if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1 self.count += 1 uf = UnionFind(H * W) for i in range(H): for j in range(W): # 横 if j != W - 1 and S[i][j] != S[i][j + 1]: uf.unite(i * W + j, i * W + j + 1) # 縦 if i != H - 1 and S[i][j] != S[i + 1][j]: uf.unite(i * W + j, (i + 1) * W + j) for i in range(H * W): uf.root(i) black = Counter() white = Counter() # あるユニオンに所属(#.#.の移動できる塊)の#と.の数を数える for i in range(H): for j in range(W): k = i * W + j if S[i][j] == "#": black[uf.root(k)] += 1 else: white[uf.root(k)] += 1 # ユニオンごとに足し合わせ ans = 0 for k in list(black.keys()): ans += black[k] * white[k] print(ans)
false
6.153846
[ "-from collections import defaultdict", "+from collections import Counter", "-es = defaultdict(list)", "+", "+", "+class UnionFind:", "+ def __init__(self, N):", "+ self.parent = [i for i in range(N)]", "+ self.rank = [0] * N", "+ self.count = 0", "+", "+ def root(self, a):", "+ if self.parent[a] == a:", "+ return a", "+ else:", "+ self.parent[a] = self.root(self.parent[a])", "+ return self.parent[a]", "+", "+ def is_same(self, a, b):", "+ return self.root(a) == self.root(b)", "+", "+ def unite(self, a, b):", "+ ra = self.root(a)", "+ rb = self.root(b)", "+ if ra == rb:", "+ return", "+ if self.rank[ra] < self.rank[rb]:", "+ self.parent[ra] = rb", "+ else:", "+ self.parent[rb] = ra", "+ if self.rank[ra] == self.rank[rb]:", "+ self.rank[ra] += 1", "+ self.count += 1", "+", "+", "+uf = UnionFind(H * W)", "- es[(i, j)].append((i, j + 1))", "- es[(i, j + 1)].append((i, j))", "+ uf.unite(i * W + j, i * W + j + 1)", "- es[(i, j)].append((i + 1, j))", "- es[(i + 1, j)].append((i, j))", "+ uf.unite(i * W + j, (i + 1) * W + j)", "+for i in range(H * W):", "+ uf.root(i)", "+black = Counter()", "+white = Counter()", "+# あるユニオンに所属(#.#.の移動できる塊)の#と.の数を数える", "+for i in range(H):", "+ for j in range(W):", "+ k = i * W + j", "+ if S[i][j] == \"#\":", "+ black[uf.root(k)] += 1", "+ else:", "+ white[uf.root(k)] += 1", "+# ユニオンごとに足し合わせ", "-checked = [[False for _ in range(W)] for _ in range(H)]", "-stack = list(es.keys())", "-for i, j in stack:", "- # 開始位置", "- if checked[i][j]:", "- continue", "- if S[i][j] == \"#\":", "- cnt_b = 1", "- cnt_w = 0", "- else:", "- cnt_b = 0", "- cnt_w = 1", "- checked[i][j] = True", "- ns = es[(i, j)]", "- # tmp = []", "- while ns:", "- tmp = []", "- for a, b in ns:", "- if checked[a][b] == True:", "- continue", "- checked[a][b] = True", "- if S[a][b] == \"#\":", "- cnt_b += 1", "- else:", "- cnt_w += 1", "- for c, d in es[(a, b)]:", "- if not checked[c][d]:", "- tmp.append((c, d))", "- if len(tmp) > 0:", "- ns = tmp", "- else:", "- ns = []", "- ans += cnt_b * cnt_w", "+for k in list(black.keys()):", "+ ans += black[k] * white[k]" ]
false
0.04591
0.045958
0.998944
[ "s331992792", "s982727776" ]
u531603069
p02803
python
s267681124
s097533599
632
427
12,048
3,316
Accepted
Accepted
32.44
import sys import numpy as np from collections import deque h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] direction = [(1, 0), (0, 1), (-1, 0), (0, -1)] max_step = 0 for i in range(h): for j in range(w): largest_step = 0 # print("start: ", i, j) if maze[i][j] == "#": continue visited = [[False] * w for _ in range(h)] distance = [[-1] * w for _ in range(h)] plan = deque() step = 0 plan.appendleft((i, j, step)) distance[i][j] = step visited[i][j] = True while plan: y, x, step = plan.pop() # print(" ", x, y, step) # if step > largest_step: # largest_step = step for next_direction in direction: next_y = y + next_direction[0] next_x = x + next_direction[1] if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]: continue distance[next_y][next_x] = distance[y][x] + 1 visited[next_y][next_x] = True plan.appendleft((next_y, next_x, step + 1)) # print(largest_step) # if largest_step > max_step: # max_step = largest_step max_step = max(max_step, np.max(np.array(distance))) print(max_step)
from collections import deque h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] direction = [(1, 0), (0, 1), (-1, 0), (0, -1)] max_step = 0 for i in range(h): for j in range(w): largest_step = 0 # print("start: ", i, j) if maze[i][j] == "#": continue visited = [[False] * w for _ in range(h)] plan = deque() step = 1 plan.appendleft((i, j, step)) visited[i][j] = True while plan: y, x, step = plan.pop() for next_direction in direction: next_y = y + next_direction[0] next_x = x + next_direction[1] if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]: continue visited[next_y][next_x] = True if step > largest_step: largest_step = step plan.appendleft((next_y, next_x, step + 1)) if largest_step > max_step: max_step = largest_step print(max_step)
41
33
1,446
1,142
import sys import numpy as np from collections import deque h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] direction = [(1, 0), (0, 1), (-1, 0), (0, -1)] max_step = 0 for i in range(h): for j in range(w): largest_step = 0 # print("start: ", i, j) if maze[i][j] == "#": continue visited = [[False] * w for _ in range(h)] distance = [[-1] * w for _ in range(h)] plan = deque() step = 0 plan.appendleft((i, j, step)) distance[i][j] = step visited[i][j] = True while plan: y, x, step = plan.pop() # print(" ", x, y, step) # if step > largest_step: # largest_step = step for next_direction in direction: next_y = y + next_direction[0] next_x = x + next_direction[1] if ( -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x] ): continue distance[next_y][next_x] = distance[y][x] + 1 visited[next_y][next_x] = True plan.appendleft((next_y, next_x, step + 1)) # print(largest_step) # if largest_step > max_step: # max_step = largest_step max_step = max(max_step, np.max(np.array(distance))) print(max_step)
from collections import deque h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] direction = [(1, 0), (0, 1), (-1, 0), (0, -1)] max_step = 0 for i in range(h): for j in range(w): largest_step = 0 # print("start: ", i, j) if maze[i][j] == "#": continue visited = [[False] * w for _ in range(h)] plan = deque() step = 1 plan.appendleft((i, j, step)) visited[i][j] = True while plan: y, x, step = plan.pop() for next_direction in direction: next_y = y + next_direction[0] next_x = x + next_direction[1] if ( -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x] ): continue visited[next_y][next_x] = True if step > largest_step: largest_step = step plan.appendleft((next_y, next_x, step + 1)) if largest_step > max_step: max_step = largest_step print(max_step)
false
19.512195
[ "-import sys", "-import numpy as np", "- distance = [[-1] * w for _ in range(h)]", "- step = 0", "+ step = 1", "- distance[i][j] = step", "- # print(\" \", x, y, step)", "- # if step > largest_step:", "- # largest_step = step", "- distance[next_y][next_x] = distance[y][x] + 1", "+ if step > largest_step:", "+ largest_step = step", "- # print(largest_step)", "- # if largest_step > max_step:", "- # max_step = largest_step", "- max_step = max(max_step, np.max(np.array(distance)))", "+ if largest_step > max_step:", "+ max_step = largest_step" ]
false
0.298856
0.091651
3.260798
[ "s267681124", "s097533599" ]
u083960235
p03612
python
s150331056
s565067006
84
74
15,928
14,568
Accepted
Accepted
11.9
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from heapq import heappop, heapify, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = LIST() ans = 0 i = 0 while i < N: if A[i] == i + 1: ans += 1 i += 1 i += 1 print(ans) # for i in range(N): # if A[i] == i + 1: # ans += 1 # if i < N - 1: # if A[i + 1] == i + 2: # tmp += 1 # ans -= 1 # print(ans) # print(tmp)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = LIST() ans = 0 cnt = 0 i = 0 while i < N: if A[i] == i + 1: ans += 1 i += 1 i += 1 print(ans) # for i in range(N): # if i + 1 == A[i]: # ans += 1 # cnt += 1 # else: # # print(cnt) # if cnt > 1: # ans -= 1 # cnt = 0 # if cnt > 1: # ans -= 1 # print(ans)
43
46
1,122
1,086
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from heapq import heappop, heapify, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = LIST() ans = 0 i = 0 while i < N: if A[i] == i + 1: ans += 1 i += 1 i += 1 print(ans) # for i in range(N): # if A[i] == i + 1: # ans += 1 # if i < N - 1: # if A[i + 1] == i + 2: # tmp += 1 # ans -= 1 # print(ans) # print(tmp)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = LIST() ans = 0 cnt = 0 i = 0 while i < N: if A[i] == i + 1: ans += 1 i += 1 i += 1 print(ans) # for i in range(N): # if i + 1 == A[i]: # ans += 1 # cnt += 1 # else: # # print(cnt) # if cnt > 1: # ans -= 1 # cnt = 0 # if cnt > 1: # ans -= 1 # print(ans)
false
6.521739
[ "-from fractions import gcd", "-from heapq import heappop, heapify, heappush", "+cnt = 0", "-# if A[i] == i + 1:", "+# if i + 1 == A[i]:", "-# if i < N - 1:", "-# if A[i + 1] == i + 2:", "-# tmp += 1", "-# ans -= 1", "+# cnt += 1", "+# else:", "+# # print(cnt)", "+# if cnt > 1:", "+# ans -= 1", "+# cnt = 0", "+# if cnt > 1:", "+# ans -= 1", "-# print(tmp)" ]
false
0.078392
0.120708
0.649437
[ "s150331056", "s565067006" ]
u340500592
p02393
python
s086613226
s487506227
30
20
7,672
7,612
Accepted
Accepted
33.33
a, b, c = list(map(int, input().split())) if a <= b <= c: print((a, b, c)) elif a <= c <= b: print((a, c, b)) elif b <= a <= c: print((b, a, c)) elif b <= c <= a: print((b, c, a)) elif c <= a <= b: print((c, a, b)) elif c <= b <= a: print((c, b, a))
a, b, c = list(map(int, input().split())) [x, y, z] = sorted([a, b, c]) print((x, y, z))
14
3
251
82
a, b, c = list(map(int, input().split())) if a <= b <= c: print((a, b, c)) elif a <= c <= b: print((a, c, b)) elif b <= a <= c: print((b, a, c)) elif b <= c <= a: print((b, c, a)) elif c <= a <= b: print((c, a, b)) elif c <= b <= a: print((c, b, a))
a, b, c = list(map(int, input().split())) [x, y, z] = sorted([a, b, c]) print((x, y, z))
false
78.571429
[ "-if a <= b <= c:", "- print((a, b, c))", "-elif a <= c <= b:", "- print((a, c, b))", "-elif b <= a <= c:", "- print((b, a, c))", "-elif b <= c <= a:", "- print((b, c, a))", "-elif c <= a <= b:", "- print((c, a, b))", "-elif c <= b <= a:", "- print((c, b, a))", "+[x, y, z] = sorted([a, b, c])", "+print((x, y, z))" ]
false
0.155349
0.046878
3.313878
[ "s086613226", "s487506227" ]
u437351386
p02573
python
s370642288
s567829685
764
648
83,692
20,112
Accepted
Accepted
15.18
n,m=list(map(int,input().split())) par=[i for i in range(n)] #親 rank=[1]*n #深さ size=[1]*n #iを根とするグループのサイズ #親を見つける def find(x): if par[x]==x: return x else: return find(par[x]) #xの属するグループとyの属するグループを併合 def unite(x,y): x=find(x) y=find(y) if x==y: return if rank[x]<rank[y]: par[x]=y size[y]=size[y]+size[x] else: par[y]=x size[x]=size[x]+size[y] if rank[x]==rank[y]: rank[x]+=1 #xとyが同じグループに属するかどうか def same(x,y): return find(x)==find(y) #check=set() for i in range(m): a,b=list(map(int,input().split())) unite(a-1,b-1) ans=0 for i in range(n): ans=max(ans,size[find(i)]) print(ans)
n,m=list(map(int,input().split())) #Union-Find木 #par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ par=[i for i in range(n)] deep=[1]*n size=[1]*n #親を見つける def find(x): if par[x]==x: return x else: return find(par[x]) #二つのグループを統合する def unite(x,y): x=find(x) y=find(y) if x==y: return if deep[x]<deep[y]: par[x]=y size[y]+=size[x] else: par[y]=x size[x]+=size[y] if deep[x]==deep[y]: deep[x]+=1 #xとyが同じグループに属するかどうか def same(x,y): return find(x)==find(y) for i in range(m): a,b=list(map(int,input().split())) unite(a-1,b-1) print((max(size)))
41
47
684
641
n, m = list(map(int, input().split())) par = [i for i in range(n)] # 親 rank = [1] * n # 深さ size = [1] * n # iを根とするグループのサイズ # 親を見つける def find(x): if par[x] == x: return x else: return find(par[x]) # xの属するグループとyの属するグループを併合 def unite(x, y): x = find(x) y = find(y) if x == y: return if rank[x] < rank[y]: par[x] = y size[y] = size[y] + size[x] else: par[y] = x size[x] = size[x] + size[y] if rank[x] == rank[y]: rank[x] += 1 # xとyが同じグループに属するかどうか def same(x, y): return find(x) == find(y) # check=set() for i in range(m): a, b = list(map(int, input().split())) unite(a - 1, b - 1) ans = 0 for i in range(n): ans = max(ans, size[find(i)]) print(ans)
n, m = list(map(int, input().split())) # Union-Find木 # par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ par = [i for i in range(n)] deep = [1] * n size = [1] * n # 親を見つける def find(x): if par[x] == x: return x else: return find(par[x]) # 二つのグループを統合する def unite(x, y): x = find(x) y = find(y) if x == y: return if deep[x] < deep[y]: par[x] = y size[y] += size[x] else: par[y] = x size[x] += size[y] if deep[x] == deep[y]: deep[x] += 1 # xとyが同じグループに属するかどうか def same(x, y): return find(x) == find(y) for i in range(m): a, b = list(map(int, input().split())) unite(a - 1, b - 1) print((max(size)))
false
12.765957
[ "-par = [i for i in range(n)] # 親", "-rank = [1] * n # 深さ", "-size = [1] * n # iを根とするグループのサイズ", "+# Union-Find木", "+# par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ", "+par = [i for i in range(n)]", "+deep = [1] * n", "+size = [1] * n", "-# xの属するグループとyの属するグループを併合", "+# 二つのグループを統合する", "- if rank[x] < rank[y]:", "+ if deep[x] < deep[y]:", "- size[y] = size[y] + size[x]", "+ size[y] += size[x]", "- size[x] = size[x] + size[y]", "- if rank[x] == rank[y]:", "- rank[x] += 1", "+ size[x] += size[y]", "+ if deep[x] == deep[y]:", "+ deep[x] += 1", "-# check=set()", "-ans = 0", "-for i in range(n):", "- ans = max(ans, size[find(i)])", "-print(ans)", "+print((max(size)))" ]
false
0.032117
0.033508
0.958493
[ "s370642288", "s567829685" ]
u679439110
p02947
python
s615902348
s637657792
712
299
24,968
25,036
Accepted
Accepted
58.01
import math as m qt = int(eval(input())) sl = [eval(input()) for i in range(qt)] d = {} count = 0 for s in sl: s = "".join(sorted(s)) if s in d: d[s] += 1 else: d[s] = 1 for e in list(d.values()): if e > 1: count += m.factorial(e) // (m.factorial(e - 2) * 2) print(count)
qt = int(eval(input())) sl = [eval(input()) for i in range(qt)] d = {} count = 0 for s in sl: s = "".join(sorted(s)) if s in d: d[s] += 1 else: d[s] = 1 for e in list(d.values()): if e > 1: count += e * (e - 1) // 2 print(count)
20
18
318
272
import math as m qt = int(eval(input())) sl = [eval(input()) for i in range(qt)] d = {} count = 0 for s in sl: s = "".join(sorted(s)) if s in d: d[s] += 1 else: d[s] = 1 for e in list(d.values()): if e > 1: count += m.factorial(e) // (m.factorial(e - 2) * 2) print(count)
qt = int(eval(input())) sl = [eval(input()) for i in range(qt)] d = {} count = 0 for s in sl: s = "".join(sorted(s)) if s in d: d[s] += 1 else: d[s] = 1 for e in list(d.values()): if e > 1: count += e * (e - 1) // 2 print(count)
false
10
[ "-import math as m", "-", "- count += m.factorial(e) // (m.factorial(e - 2) * 2)", "+ count += e * (e - 1) // 2" ]
false
0.039487
0.068721
0.574596
[ "s615902348", "s637657792" ]
u527993431
p02983
python
s861137037
s615526808
512
42
3,060
3,060
Accepted
Accepted
91.8
L,R = list(map(int,input().split())) sa = R - L ans = 2020 if sa > 2019: print("0") else: for i in range (L,R): for j in range (i+1,R+1): tmp = (i * j) % 2019 if ans > tmp: ans = tmp print(ans)
L,R = list(map(int,input().split())) sa = R - L ans = 2020 if sa > 673: print("0") else: for i in range (L,R): for j in range (i+1,R+1): tmp = (i * j) % 2019 if ans > tmp: ans = tmp print(ans)
12
12
213
212
L, R = list(map(int, input().split())) sa = R - L ans = 2020 if sa > 2019: print("0") else: for i in range(L, R): for j in range(i + 1, R + 1): tmp = (i * j) % 2019 if ans > tmp: ans = tmp print(ans)
L, R = list(map(int, input().split())) sa = R - L ans = 2020 if sa > 673: print("0") else: for i in range(L, R): for j in range(i + 1, R + 1): tmp = (i * j) % 2019 if ans > tmp: ans = tmp print(ans)
false
0
[ "-if sa > 2019:", "+if sa > 673:" ]
false
0.09286
0.039822
2.331858
[ "s861137037", "s615526808" ]
u531436689
p02735
python
s571821714
s086594274
363
330
69,740
69,740
Accepted
Accepted
9.09
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) def main(): H, W = LI() g = [] for _ in range(H): g.append(S()) dp = [[inf for _ in range(W)] for __ in range(H)] if g[0][0] == '#': dp[0][0] = 1 else: dp[0][0] = 0 for r in range(H): for c in range(W): cand1, cand2 = inf, inf if r-1 >= 0: if g[r-1][c] == '.' and g[r][c] == '#': dp[r][c] = min(dp[r][c], dp[r-1][c] + 1) else: dp[r][c] = min(dp[r][c], dp[r-1][c]) if c-1 >= 0: if g[r][c-1] == '.' and g[r][c] == '#': dp[r][c] = min(dp[r][c], dp[r][c-1] + 1) else: dp[r][c] = min(dp[r][c], dp[r][c-1]) print((dp[-1][-1])) main()
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) def main(): H, W = LI() g = [] for _ in range(H): g.append(S()) dp = [[inf for _ in range(W)] for __ in range(H)] if g[0][0] == '#': dp[0][0] = 1 else: dp[0][0] = 0 for r in range(H): for c in range(W): if r == 0 and c == 0: if g[r][c] == '#': dp[r][c] = 1 else: dp[r][c] = 0 cand1, cand2 = inf, inf if r-1 >= 0: if g[r-1][c] == '.' and g[r][c] == '#': dp[r][c] = min(dp[r][c], dp[r-1][c] + 1) else: dp[r][c] = min(dp[r][c], dp[r-1][c]) if c-1 >= 0: if g[r][c-1] == '.' and g[r][c] == '#': dp[r][c] = min(dp[r][c], dp[r][c-1] + 1) else: dp[r][c] = min(dp[r][c], dp[r][c-1]) print((dp[-1][-1])) main()
47
53
1,407
1,572
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) def main(): H, W = LI() g = [] for _ in range(H): g.append(S()) dp = [[inf for _ in range(W)] for __ in range(H)] if g[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for r in range(H): for c in range(W): cand1, cand2 = inf, inf if r - 1 >= 0: if g[r - 1][c] == "." and g[r][c] == "#": dp[r][c] = min(dp[r][c], dp[r - 1][c] + 1) else: dp[r][c] = min(dp[r][c], dp[r - 1][c]) if c - 1 >= 0: if g[r][c - 1] == "." and g[r][c] == "#": dp[r][c] = min(dp[r][c], dp[r][c - 1] + 1) else: dp[r][c] = min(dp[r][c], dp[r][c - 1]) print((dp[-1][-1])) main()
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) def main(): H, W = LI() g = [] for _ in range(H): g.append(S()) dp = [[inf for _ in range(W)] for __ in range(H)] if g[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for r in range(H): for c in range(W): if r == 0 and c == 0: if g[r][c] == "#": dp[r][c] = 1 else: dp[r][c] = 0 cand1, cand2 = inf, inf if r - 1 >= 0: if g[r - 1][c] == "." and g[r][c] == "#": dp[r][c] = min(dp[r][c], dp[r - 1][c] + 1) else: dp[r][c] = min(dp[r][c], dp[r - 1][c]) if c - 1 >= 0: if g[r][c - 1] == "." and g[r][c] == "#": dp[r][c] = min(dp[r][c], dp[r][c - 1] + 1) else: dp[r][c] = min(dp[r][c], dp[r][c - 1]) print((dp[-1][-1])) main()
false
11.320755
[ "+ if r == 0 and c == 0:", "+ if g[r][c] == \"#\":", "+ dp[r][c] = 1", "+ else:", "+ dp[r][c] = 0" ]
false
0.049679
0.050671
0.980431
[ "s571821714", "s086594274" ]
u593567568
p02769
python
s991159864
s239557433
1,660
576
28,044
56,144
Accepted
Accepted
65.3
import sys import numpy as np sys.setrecursionlimit(10 ** 7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N*2+10, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD ''' a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD ''' print(ans)
import sys import numpy as np sys.setrecursionlimit(10 ** 7) N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N * 2 + 10, MOD) fact, fact_inv = fact.tolist(), fact_inv.tolist() def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD ''' a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD ''' print(ans)
71
68
1,469
1,498
import sys import numpy as np sys.setrecursionlimit(10**7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10**9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N * 2 + 10, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD """ a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD """ print(ans)
import sys import numpy as np sys.setrecursionlimit(10**7) N, K = list(map(int, input().split())) MOD = 10**9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N * 2 + 10, MOD) fact, fact_inv = fact.tolist(), fact_inv.tolist() def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD """ a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD """ print(ans)
false
4.225352
[ "-# Wrong Answer", "-# WA", "+fact, fact_inv = fact.tolist(), fact_inv.tolist()" ]
false
0.452686
0.272456
1.661501
[ "s991159864", "s239557433" ]