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
list
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
list
u970197315
p03038
python
s093895382
s989608938
605
514
23,996
32,968
Accepted
Accepted
15.04
n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[] for i in range(m): bb,cc=list(map(int,input().split())) b.append([cc,bb]) a.sort() b.sort(reverse=True) i=0 j=0 while i<n: if j==m: break if b[j][1]>0: if a[i]<b[j][0]: a[i]=b[j][0] b[j][1]-=1 i+=1 elif a[i]>=b[j][0]: break else: j+=1 print((sum(a)))
n,m=list(map(int,input().split())) a=list(map(int,input().split())) bc=[list(map(int,input().split())) for i in range(m)] a.sort() bc.sort(key=lambda x: x[1],reverse=True) # print(a) # print(bc) i=0 for b,c in bc: tb=b while tb>0: if n==i: break if a[i]>=c: break a[i]=c tb-=1 i+=1 if n==i:break if a[i]>=c : break print((sum(a)))
24
22
433
387
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = [] for i in range(m): bb, cc = list(map(int, input().split())) b.append([cc, bb]) a.sort() b.sort(reverse=True) i = 0 j = 0 while i < n: if j == m: break if b[j][1] > 0: if a[i] < b[j][0]: a[i] = b[j][0] b[j][1] -= 1 i += 1 elif a[i] >= b[j][0]: break else: j += 1 print((sum(a)))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) bc = [list(map(int, input().split())) for i in range(m)] a.sort() bc.sort(key=lambda x: x[1], reverse=True) # print(a) # print(bc) i = 0 for b, c in bc: tb = b while tb > 0: if n == i: break if a[i] >= c: break a[i] = c tb -= 1 i += 1 if n == i: break if a[i] >= c: break print((sum(a)))
false
8.333333
[ "-b = []", "-for i in range(m):", "- bb, cc = list(map(int, input().split()))", "- b.append([cc, bb])", "+bc = [list(map(int, input().split())) for i in range(m)]", "-b.sort(reverse=True)", "+bc.sort(key=lambda x: x[1], reverse=True)", "+# print(a)", "+# print(bc)", "-j = 0", "-while i < n:", "- if j == m:", "+for b, c in bc:", "+ tb = b", "+ while tb > 0:", "+ if n == i:", "+ break", "+ if a[i] >= c:", "+ break", "+ a[i] = c", "+ tb -= 1", "+ i += 1", "+ if n == i:", "- if b[j][1] > 0:", "- if a[i] < b[j][0]:", "- a[i] = b[j][0]", "- b[j][1] -= 1", "- i += 1", "- elif a[i] >= b[j][0]:", "- break", "- else:", "- j += 1", "+ if a[i] >= c:", "+ break" ]
false
0.045055
0.04613
0.976714
[ "s093895382", "s989608938" ]
u922449550
p02556
python
s906023781
s206397145
747
454
37,424
51,912
Accepted
Accepted
39.22
N = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(N)] xy.sort(reverse=True) ans = 0 M = xy[0][0] + xy[0][1] m = xy[0][0] - xy[0][1] for x, y in xy[1:]: ans = max(ans, M-x-y, m-x+y) M = max(M, x+y) m = max(m, x-y) print(ans)
N = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(N)] z = []; w = [] for x, y in xy: z.append(x + y) w.append(x - y) print((max(max(z)-min(z), max(w)-min(w))))
13
8
270
194
N = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(N)] xy.sort(reverse=True) ans = 0 M = xy[0][0] + xy[0][1] m = xy[0][0] - xy[0][1] for x, y in xy[1:]: ans = max(ans, M - x - y, m - x + y) M = max(M, x + y) m = max(m, x - y) print(ans)
N = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(N)] z = [] w = [] for x, y in xy: z.append(x + y) w.append(x - y) print((max(max(z) - min(z), max(w) - min(w))))
false
38.461538
[ "-xy.sort(reverse=True)", "-ans = 0", "-M = xy[0][0] + xy[0][1]", "-m = xy[0][0] - xy[0][1]", "-for x, y in xy[1:]:", "- ans = max(ans, M - x - y, m - x + y)", "- M = max(M, x + y)", "- m = max(m, x - y)", "-print(ans)", "+z = []", "+w = []", "+for x, y in xy:", "+ z.append(x + y)", "+ w.append(x - y)", "+print((max(max(z) - min(z), max(w) - min(w))))" ]
false
0.076799
0.039972
1.921292
[ "s906023781", "s206397145" ]
u706929073
p03127
python
s930402426
s164667225
1,621
136
14,224
14,252
Accepted
Accepted
91.61
n = int(eval(input())) a = list(map(int, input().split())) a.sort() while 1 < len(a): while 0 != a[0]: r = a[1] % a[0] a[1] = a[0] a[0] = r a.pop(0) print((a[0]))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() for i in range(1, len(a)): while 0 != a[i - 1]: r = a[i] % a[i - 1] a[i] = a[i - 1] a[i - 1] = r print((a[-1]))
11
10
197
210
n = int(eval(input())) a = list(map(int, input().split())) a.sort() while 1 < len(a): while 0 != a[0]: r = a[1] % a[0] a[1] = a[0] a[0] = r a.pop(0) print((a[0]))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() for i in range(1, len(a)): while 0 != a[i - 1]: r = a[i] % a[i - 1] a[i] = a[i - 1] a[i - 1] = r print((a[-1]))
false
9.090909
[ "-while 1 < len(a):", "- while 0 != a[0]:", "- r = a[1] % a[0]", "- a[1] = a[0]", "- a[0] = r", "- a.pop(0)", "-print((a[0]))", "+for i in range(1, len(a)):", "+ while 0 != a[i - 1]:", "+ r = a[i] % a[i - 1]", "+ a[i] = a[i - 1]", "+ a[i - 1] = r", "+print((a[-1]))" ]
false
0.042657
0.055265
0.771868
[ "s930402426", "s164667225" ]
u759412327
p02802
python
s985249797
s301263554
293
198
4,596
10,456
Accepted
Accepted
32.42
N,M = list(map(int,input().split())) AC = (N+1)*[0] WA = (N+1)*[0] wa=0 for m in range(M): p,s = input().split() p = int(p) if AC[p]==0 and s=="AC": AC[p]=1 wa+=WA[p] WA[p]+=1 print((sum(AC),wa))
N,M = list(map(int,input().split())) AC = N*[0] WA = N*[0] for m in range(M): P,S = input().split() P = int(P)-1 if AC[P]==1: continue if S=="WA": WA[P]+=1 else: AC[P]=1 wa = 0 for a,w in zip(AC,WA): wa+=w*a print((sum(AC),wa))
16
20
227
269
N, M = list(map(int, input().split())) AC = (N + 1) * [0] WA = (N + 1) * [0] wa = 0 for m in range(M): p, s = input().split() p = int(p) if AC[p] == 0 and s == "AC": AC[p] = 1 wa += WA[p] WA[p] += 1 print((sum(AC), wa))
N, M = list(map(int, input().split())) AC = N * [0] WA = N * [0] for m in range(M): P, S = input().split() P = int(P) - 1 if AC[P] == 1: continue if S == "WA": WA[P] += 1 else: AC[P] = 1 wa = 0 for a, w in zip(AC, WA): wa += w * a print((sum(AC), wa))
false
20
[ "-AC = (N + 1) * [0]", "-WA = (N + 1) * [0]", "+AC = N * [0]", "+WA = N * [0]", "+for m in range(M):", "+ P, S = input().split()", "+ P = int(P) - 1", "+ if AC[P] == 1:", "+ continue", "+ if S == \"WA\":", "+ WA[P] += 1", "+ else:", "+ AC[P] = 1", "-for m in range(M):", "- p, s = input().split()", "- p = int(p)", "- if AC[p] == 0 and s == \"AC\":", "- AC[p] = 1", "- wa += WA[p]", "- WA[p] += 1", "+for a, w in zip(AC, WA):", "+ wa += w * a" ]
false
0.095896
0.047005
2.040102
[ "s985249797", "s301263554" ]
u309141201
p03031
python
s449523486
s762621985
66
47
3,064
3,064
Accepted
Accepted
28.79
# import itertools n, m = list(map(int, input().split())) s = [] for i in range(m): s.append(list(map(int, input().split()))) p = list(map(int, input().split())) ans = 0 for i in range(2**n): b = list(str(bin(i))[2:].zfill(n)) # print(b) ok = True for j in range(m): Sum = 0 for k in range(s[j][0]): Sum += int(b[s[j][k+1] - 1]) # print(i, j, Sum) if Sum % 2 != p[j]: ok = False if ok: ans += 1 print(ans) # print(s, p)
N, M = list(map(int, input().split())) s = [] k = [] for _ in range(M): x = list(map(int, input().split())) k.append(x.pop(0)) s.append(x) p = list(map(int, input().split())) # print(s, k, p) ans = 0 for i in range(2**N): Switches = [0]*N for j in range(N): if (i >> j) & 1: Switches[j] = 1 # print(Switches) Lamps = [0]*M for j in range(M): for l in range(k[j]): if Switches[s[j][l] - 1] == 1: Lamps[j] += 1 # print(Lamps) ok = True for j in range(M): # if Lamps[j] == 0: # ok = False # break if Lamps[j] % 2 != p[j]: ok = False break if ok: ans += 1 print(ans)
23
37
532
777
# import itertools n, m = list(map(int, input().split())) s = [] for i in range(m): s.append(list(map(int, input().split()))) p = list(map(int, input().split())) ans = 0 for i in range(2**n): b = list(str(bin(i))[2:].zfill(n)) # print(b) ok = True for j in range(m): Sum = 0 for k in range(s[j][0]): Sum += int(b[s[j][k + 1] - 1]) # print(i, j, Sum) if Sum % 2 != p[j]: ok = False if ok: ans += 1 print(ans) # print(s, p)
N, M = list(map(int, input().split())) s = [] k = [] for _ in range(M): x = list(map(int, input().split())) k.append(x.pop(0)) s.append(x) p = list(map(int, input().split())) # print(s, k, p) ans = 0 for i in range(2**N): Switches = [0] * N for j in range(N): if (i >> j) & 1: Switches[j] = 1 # print(Switches) Lamps = [0] * M for j in range(M): for l in range(k[j]): if Switches[s[j][l] - 1] == 1: Lamps[j] += 1 # print(Lamps) ok = True for j in range(M): # if Lamps[j] == 0: # ok = False # break if Lamps[j] % 2 != p[j]: ok = False break if ok: ans += 1 print(ans)
false
37.837838
[ "-# import itertools", "-n, m = list(map(int, input().split()))", "+N, M = list(map(int, input().split()))", "-for i in range(m):", "- s.append(list(map(int, input().split())))", "+k = []", "+for _ in range(M):", "+ x = list(map(int, input().split()))", "+ k.append(x.pop(0))", "+ s.append(x)", "+# print(s, k, p)", "-for i in range(2**n):", "- b = list(str(bin(i))[2:].zfill(n))", "- # print(b)", "+for i in range(2**N):", "+ Switches = [0] * N", "+ for j in range(N):", "+ if (i >> j) & 1:", "+ Switches[j] = 1", "+ # print(Switches)", "+ Lamps = [0] * M", "+ for j in range(M):", "+ for l in range(k[j]):", "+ if Switches[s[j][l] - 1] == 1:", "+ Lamps[j] += 1", "+ # print(Lamps)", "- for j in range(m):", "- Sum = 0", "- for k in range(s[j][0]):", "- Sum += int(b[s[j][k + 1] - 1])", "- # print(i, j, Sum)", "- if Sum % 2 != p[j]:", "+ for j in range(M):", "+ # if Lamps[j] == 0:", "+ # ok = False", "+ # break", "+ if Lamps[j] % 2 != p[j]:", "+ break", "-# print(s, p)" ]
false
0.068824
0.10394
0.66215
[ "s449523486", "s762621985" ]
u620084012
p03945
python
s864442929
s999676110
201
182
39,408
39,280
Accepted
Accepted
9.45
S = eval(input()) t = S[0] ans = 0 for k in range(1,len(S)): if t != S[k]: ans += 1 t = S[k] print(ans)
S = eval(input()) ans = 0 for k in range(1,len(S)): if S[k-1] != S[k]: ans += 1 print(ans)
8
6
125
102
S = eval(input()) t = S[0] ans = 0 for k in range(1, len(S)): if t != S[k]: ans += 1 t = S[k] print(ans)
S = eval(input()) ans = 0 for k in range(1, len(S)): if S[k - 1] != S[k]: ans += 1 print(ans)
false
25
[ "-t = S[0]", "- if t != S[k]:", "+ if S[k - 1] != S[k]:", "- t = S[k]" ]
false
0.04979
0.050672
0.982598
[ "s864442929", "s999676110" ]
u013408661
p03361
python
s854184975
s462123555
20
18
3,064
3,064
Accepted
Accepted
10
h,w=list(map(int,input().split())) mapdata=[] re=0 for i in range(h): line=str(eval(input())) line2=list(line) mapdata.append(line2) def jugde(i,j): count=0 for x in (i-1,i+1): if 0<=x<=h-1: if mapdata[x][j]=='#': count+=1 for y in (j-1,j+1): if 0<=y<=w-1: if mapdata[i][y]=='#': count+=1 if count!=0: return True for i in range(h): for j in range(w): if mapdata[i][j]=='#': if jugde(i,j)==True: pass else: re+=1 if re==0: print('Yes') if re!=0: print('No')
# coding: utf-8 # Your code here! H,W=list(map(int, input().split())) S=["."+eval(input())+"." for i in range(H)] S=["."*(W+2)]+S+["."*(W+2)] flag = 0 for i in range(H): for j in range(W): if S[i][j]=="#": if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".": flag = 1 print(("Yes" if flag==0 else "No"))
30
13
566
365
h, w = list(map(int, input().split())) mapdata = [] re = 0 for i in range(h): line = str(eval(input())) line2 = list(line) mapdata.append(line2) def jugde(i, j): count = 0 for x in (i - 1, i + 1): if 0 <= x <= h - 1: if mapdata[x][j] == "#": count += 1 for y in (j - 1, j + 1): if 0 <= y <= w - 1: if mapdata[i][y] == "#": count += 1 if count != 0: return True for i in range(h): for j in range(w): if mapdata[i][j] == "#": if jugde(i, j) == True: pass else: re += 1 if re == 0: print("Yes") if re != 0: print("No")
# coding: utf-8 # Your code here! H, W = list(map(int, input().split())) S = ["." + eval(input()) + "." for i in range(H)] S = ["." * (W + 2)] + S + ["." * (W + 2)] flag = 0 for i in range(H): for j in range(W): if S[i][j] == "#": if ( S[i - 1][j] == "." and S[i + 1][j] == "." and S[i][j - 1] == "." and S[i][j + 1] == "." ): flag = 1 print(("Yes" if flag == 0 else "No"))
false
56.666667
[ "-h, w = list(map(int, input().split()))", "-mapdata = []", "-re = 0", "-for i in range(h):", "- line = str(eval(input()))", "- line2 = list(line)", "- mapdata.append(line2)", "-", "-", "-def jugde(i, j):", "- count = 0", "- for x in (i - 1, i + 1):", "- if 0 <= x <= h - 1:", "- if mapdata[x][j] == \"#\":", "- count += 1", "- for y in (j - 1, j + 1):", "- if 0 <= y <= w - 1:", "- if mapdata[i][y] == \"#\":", "- count += 1", "- if count != 0:", "- return True", "-", "-", "-for i in range(h):", "- for j in range(w):", "- if mapdata[i][j] == \"#\":", "- if jugde(i, j) == True:", "- pass", "- else:", "- re += 1", "-if re == 0:", "- print(\"Yes\")", "-if re != 0:", "- print(\"No\")", "+# coding: utf-8", "+# Your code here!", "+H, W = list(map(int, input().split()))", "+S = [\".\" + eval(input()) + \".\" for i in range(H)]", "+S = [\".\" * (W + 2)] + S + [\".\" * (W + 2)]", "+flag = 0", "+for i in range(H):", "+ for j in range(W):", "+ if S[i][j] == \"#\":", "+ if (", "+ S[i - 1][j] == \".\"", "+ and S[i + 1][j] == \".\"", "+ and S[i][j - 1] == \".\"", "+ and S[i][j + 1] == \".\"", "+ ):", "+ flag = 1", "+print((\"Yes\" if flag == 0 else \"No\"))" ]
false
0.041324
0.040187
1.028296
[ "s854184975", "s462123555" ]
u644907318
p02725
python
s209079793
s341824222
272
109
79,340
99,992
Accepted
Accepted
59.93
K,N = list(map(int,input().split())) A = list(map(int,input().split())) cnt = K+A[0]-A[N-1] for i in range(1,N): cnt = max(cnt,A[i]-A[i-1]) print((K-cnt))
K,N = list(map(int,input().split())) A = list(map(int,input().split())) tmin = 2*K for i in range(1,N): tmin = min(tmin,K-(A[i]-A[i-1])) tmin = min(tmin,A[N-1]-A[0]) print(tmin)
6
7
155
181
K, N = list(map(int, input().split())) A = list(map(int, input().split())) cnt = K + A[0] - A[N - 1] for i in range(1, N): cnt = max(cnt, A[i] - A[i - 1]) print((K - cnt))
K, N = list(map(int, input().split())) A = list(map(int, input().split())) tmin = 2 * K for i in range(1, N): tmin = min(tmin, K - (A[i] - A[i - 1])) tmin = min(tmin, A[N - 1] - A[0]) print(tmin)
false
14.285714
[ "-cnt = K + A[0] - A[N - 1]", "+tmin = 2 * K", "- cnt = max(cnt, A[i] - A[i - 1])", "-print((K - cnt))", "+ tmin = min(tmin, K - (A[i] - A[i - 1]))", "+tmin = min(tmin, A[N - 1] - A[0])", "+print(tmin)" ]
false
0.086792
0.157308
0.551733
[ "s209079793", "s341824222" ]
u585482323
p03575
python
s337838793
s720472611
212
166
42,476
38,384
Accepted
Accepted
21.7
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def unite(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 n,m = LI() v = LIR(m) for i in range(m): v[i][0] -= 1 v[i][1] -= 1 ans = 0 for i in range(m): par = [i for i in range(n)] rank = [0]*n s = 1 for j in range(m): if i == j: continue a,b = v[j] if root(a) != root(b): s += 1 if s >= n: break unite(a,b) else: ans += 1 print(ans) return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 cnt = 0 def solve(): def lowlink(v): global cnt def dfs(x): global cnt for y in v[x]: if pre[y] is None: cnt += 1 pre[y] = low[y] = cnt par[y] = x py = dfs(y) if py < low[x]: low[x] = py else: if par[x] != y and pre[y] < low[x]: low[x] = pre[y] if pre[x] < low[y]: res.append((x,y)) return low[x] pre = [None]*n low = [None]*n par = [None]*n res = [] for x in range(n): if pre[x] is None: pre[x] = low[x] = cnt dfs(x) return res n,m = LI() v = [[] for i in range(n)] for i in range(m): a,b = LI() a -= 1 b -= 1 v[a].append(b) v[b].append(a) ans = lowlink(v) print((len(ans))) return #Solve if __name__ == "__main__": solve()
69
72
1,656
1,850
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def unite(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 n, m = LI() v = LIR(m) for i in range(m): v[i][0] -= 1 v[i][1] -= 1 ans = 0 for i in range(m): par = [i for i in range(n)] rank = [0] * n s = 1 for j in range(m): if i == j: continue a, b = v[j] if root(a) != root(b): s += 1 if s >= n: break unite(a, b) else: ans += 1 print(ans) return # Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 cnt = 0 def solve(): def lowlink(v): global cnt def dfs(x): global cnt for y in v[x]: if pre[y] is None: cnt += 1 pre[y] = low[y] = cnt par[y] = x py = dfs(y) if py < low[x]: low[x] = py else: if par[x] != y and pre[y] < low[x]: low[x] = pre[y] if pre[x] < low[y]: res.append((x, y)) return low[x] pre = [None] * n low = [None] * n par = [None] * n res = [] for x in range(n): if pre[x] is None: pre[x] = low[x] = cnt dfs(x) return res n, m = LI() v = [[] for i in range(n)] for i in range(m): a, b = LI() a -= 1 b -= 1 v[a].append(b) v[b].append(a) ans = lowlink(v) print((len(ans))) return # Solve if __name__ == "__main__": solve()
false
4.166667
[ "+cnt = 0", "- def root(x):", "- if par[x] == x:", "- return x", "- par[x] = root(par[x])", "- return par[x]", "+ def lowlink(v):", "+ global cnt", "- def unite(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", "+ def dfs(x):", "+ global cnt", "+ for y in v[x]:", "+ if pre[y] is None:", "+ cnt += 1", "+ pre[y] = low[y] = cnt", "+ par[y] = x", "+ py = dfs(y)", "+ if py < low[x]:", "+ low[x] = py", "+ else:", "+ if par[x] != y and pre[y] < low[x]:", "+ low[x] = pre[y]", "+ if pre[x] < low[y]:", "+ res.append((x, y))", "+ return low[x]", "+", "+ pre = [None] * n", "+ low = [None] * n", "+ par = [None] * n", "+ res = []", "+ for x in range(n):", "+ if pre[x] is None:", "+ pre[x] = low[x] = cnt", "+ dfs(x)", "+ return res", "- v = LIR(m)", "+ v = [[] for i in range(n)]", "- v[i][0] -= 1", "- v[i][1] -= 1", "- ans = 0", "- for i in range(m):", "- par = [i for i in range(n)]", "- rank = [0] * n", "- s = 1", "- for j in range(m):", "- if i == j:", "- continue", "- a, b = v[j]", "- if root(a) != root(b):", "- s += 1", "- if s >= n:", "- break", "- unite(a, b)", "- else:", "- ans += 1", "- print(ans)", "+ a, b = LI()", "+ a -= 1", "+ b -= 1", "+ v[a].append(b)", "+ v[b].append(a)", "+ ans = lowlink(v)", "+ print((len(ans)))" ]
false
0.038011
0.038996
0.974722
[ "s337838793", "s720472611" ]
u083960235
p03607
python
s325547317
s818185168
214
131
16,604
28,288
Accepted
Accepted
38.79
from collections import Counter N=int(eval(input())) A=[] for i in range(N): A.append(int(eval(input()))) a=Counter(A) count=0 #for i in values for i in list(a.values()): if i%2!=0: count+=1 # print(i) print(count)
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 bisect import bisect, bisect_left, bisect_right 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 = [INT() for i in range(N)] S = set(A) C = Counter(A) cnt = 0 for s in S: if C[s] % 2 != 0: cnt += 1 print(cnt)
14
32
229
926
from collections import Counter N = int(eval(input())) A = [] for i in range(N): A.append(int(eval(input()))) a = Counter(A) count = 0 # for i in values for i in list(a.values()): if i % 2 != 0: count += 1 # print(i) print(count)
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 bisect import bisect, bisect_left, bisect_right 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 = [INT() for i in range(N)] S = set(A) C = Counter(A) cnt = 0 for s in S: if C[s] % 2 != 0: cnt += 1 print(cnt)
false
56.25
[ "-from collections import Counter", "+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 bisect import bisect, bisect_left, bisect_right", "-N = int(eval(input()))", "-A = []", "-for i in range(N):", "- A.append(int(eval(input())))", "-a = Counter(A)", "-count = 0", "-# for i in values", "-for i in list(a.values()):", "- if i % 2 != 0:", "- count += 1", "-# print(i)", "-print(count)", "+", "+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 = [INT() for i in range(N)]", "+S = set(A)", "+C = Counter(A)", "+cnt = 0", "+for s in S:", "+ if C[s] % 2 != 0:", "+ cnt += 1", "+print(cnt)" ]
false
0.088052
0.035311
2.493627
[ "s325547317", "s818185168" ]
u543954314
p03839
python
s610545928
s296591396
207
189
16,840
16,832
Accepted
Accepted
8.7
n,k = list(map(int, input().split())) a = list(map(int, input().split())) al = [0]*(n+1) pl = [0]*(n+1) ans = -10**10 for i in range(n): al[i+1] = al[i] + a[i] pl[i+1] = pl[i] + max(0,a[i]) for i in range(n-k+1): l,r = i,i+k-1 cur = max(0,al[r+1]-al[l]) + pl[l] + pl[-1] - pl[r+1] if cur > ans: ans = cur print(ans)
n,k = list(map(int,input().split())) a = list(map(int, input().split())) al = [0]*(n+1) pl = [0]*(n+1) ans = 0 for i in range(n): al[i+1] = al[i] + a[i] pl[i+1] = pl[i] if a[i] > 0: pl[i+1] += a[i] for r in range(k-1,n): l = r-k+1 cur = pl[l] + max(0, al[r+1] - al[l]) + pl[n] - pl[r+1] if ans < cur: ans = cur print(ans)
14
14
336
340
n, k = list(map(int, input().split())) a = list(map(int, input().split())) al = [0] * (n + 1) pl = [0] * (n + 1) ans = -(10**10) for i in range(n): al[i + 1] = al[i] + a[i] pl[i + 1] = pl[i] + max(0, a[i]) for i in range(n - k + 1): l, r = i, i + k - 1 cur = max(0, al[r + 1] - al[l]) + pl[l] + pl[-1] - pl[r + 1] if cur > ans: ans = cur print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) al = [0] * (n + 1) pl = [0] * (n + 1) ans = 0 for i in range(n): al[i + 1] = al[i] + a[i] pl[i + 1] = pl[i] if a[i] > 0: pl[i + 1] += a[i] for r in range(k - 1, n): l = r - k + 1 cur = pl[l] + max(0, al[r + 1] - al[l]) + pl[n] - pl[r + 1] if ans < cur: ans = cur print(ans)
false
0
[ "-ans = -(10**10)", "+ans = 0", "- pl[i + 1] = pl[i] + max(0, a[i])", "-for i in range(n - k + 1):", "- l, r = i, i + k - 1", "- cur = max(0, al[r + 1] - al[l]) + pl[l] + pl[-1] - pl[r + 1]", "- if cur > ans:", "+ pl[i + 1] = pl[i]", "+ if a[i] > 0:", "+ pl[i + 1] += a[i]", "+for r in range(k - 1, n):", "+ l = r - k + 1", "+ cur = pl[l] + max(0, al[r + 1] - al[l]) + pl[n] - pl[r + 1]", "+ if ans < cur:" ]
false
0.043378
0.046925
0.924413
[ "s610545928", "s296591396" ]
u634079249
p03112
python
s391780032
s362243278
815
510
17,680
17,884
Accepted
Accepted
37.42
import sys import os import math import bisect ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") A, B, Q = il() J = [-MAX] + [ii() for _ in range(A)] + [MAX] T = [-MAX] + [ii() for _ in range(B)] + [MAX] que = [ii() for _ in range(Q)] for q in que: a = bisect.bisect_left(J, q) b = bisect.bisect_left(T, q) ret = MAX for j in J[a - 1:a + 1]: for t in T[b - 1:b + 1]: ret = min(ret, abs(j - q) + abs(t - j), abs(t - q) + abs(j - t)) print(ret) if __name__ == '__main__': main()
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict, deque # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") A, B, Q = il() S = [-MAX, MAX] for _ in range(A): S.append(ii()) S.sort() T = [-MAX, MAX] for _ in range(B): T.append(ii()) T.sort() for _ in range(Q): q = ii() Srange = bisect.bisect_left(S, q) Trange = bisect.bisect_left(T, q) print((min(abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange]), abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange - 1]), abs(q - S[Srange]) + abs(S[Srange] - T[Trange - 1]), abs(q - S[Srange]) + abs(S[Srange] - T[Trange]), abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange]), abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange - 1]), abs(q - T[Trange]) + abs(T[Trange] - S[Srange - 1]), abs(q - T[Trange]) + abs(T[Trange] - S[Srange])))) if __name__ == '__main__': main()
40
55
1,209
1,946
import sys import os import math import bisect ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") A, B, Q = il() J = [-MAX] + [ii() for _ in range(A)] + [MAX] T = [-MAX] + [ii() for _ in range(B)] + [MAX] que = [ii() for _ in range(Q)] for q in que: a = bisect.bisect_left(J, q) b = bisect.bisect_left(T, q) ret = MAX for j in J[a - 1 : a + 1]: for t in T[b - 1 : b + 1]: ret = min(ret, abs(j - q) + abs(t - j), abs(t - q) + abs(j - t)) print(ret) if __name__ == "__main__": main()
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict, deque # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") A, B, Q = il() S = [-MAX, MAX] for _ in range(A): S.append(ii()) S.sort() T = [-MAX, MAX] for _ in range(B): T.append(ii()) T.sort() for _ in range(Q): q = ii() Srange = bisect.bisect_left(S, q) Trange = bisect.bisect_left(T, q) print( ( min( abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange]), abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange - 1]), abs(q - S[Srange]) + abs(S[Srange] - T[Trange - 1]), abs(q - S[Srange]) + abs(S[Srange] - T[Trange]), abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange]), abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange - 1]), abs(q - T[Trange]) + abs(T[Trange] - S[Srange - 1]), abs(q - T[Trange]) + abs(T[Trange] - S[Srange]), ) ) ) if __name__ == "__main__": main()
false
27.272727
[ "-import sys", "-import os", "-import math", "-import bisect", "+import sys, os, math, bisect, itertools, collections, heapq, queue", "+# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall", "+from decimal import Decimal", "+from collections import defaultdict, deque", "+", "+# import fractions", "+sys.setrecursionlimit(10000000)", "-lcm = lambda x, y: x * y / math.gcd(x, y)", "+lcm = lambda x, y: (x * y) // math.gcd(x, y)", "+# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)", "- J = [-MAX] + [ii() for _ in range(A)] + [MAX]", "- T = [-MAX] + [ii() for _ in range(B)] + [MAX]", "- que = [ii() for _ in range(Q)]", "- for q in que:", "- a = bisect.bisect_left(J, q)", "- b = bisect.bisect_left(T, q)", "- ret = MAX", "- for j in J[a - 1 : a + 1]:", "- for t in T[b - 1 : b + 1]:", "- ret = min(ret, abs(j - q) + abs(t - j), abs(t - q) + abs(j - t))", "- print(ret)", "+ S = [-MAX, MAX]", "+ for _ in range(A):", "+ S.append(ii())", "+ S.sort()", "+ T = [-MAX, MAX]", "+ for _ in range(B):", "+ T.append(ii())", "+ T.sort()", "+ for _ in range(Q):", "+ q = ii()", "+ Srange = bisect.bisect_left(S, q)", "+ Trange = bisect.bisect_left(T, q)", "+ print(", "+ (", "+ min(", "+ abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange]),", "+ abs(q - S[Srange - 1]) + abs(S[Srange - 1] - T[Trange - 1]),", "+ abs(q - S[Srange]) + abs(S[Srange] - T[Trange - 1]),", "+ abs(q - S[Srange]) + abs(S[Srange] - T[Trange]),", "+ abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange]),", "+ abs(q - T[Trange - 1]) + abs(T[Trange - 1] - S[Srange - 1]),", "+ abs(q - T[Trange]) + abs(T[Trange] - S[Srange - 1]),", "+ abs(q - T[Trange]) + abs(T[Trange] - S[Srange]),", "+ )", "+ )", "+ )" ]
false
0.039017
0.048936
0.797314
[ "s391780032", "s362243278" ]
u608088992
p03103
python
s959284945
s015125039
457
280
21,604
21,528
Accepted
Accepted
38.73
N, M = list(map(int, input().split())) Drink = [[int(i) for i in input().split()] for _ in range(N)] Drink.sort() Need = M Payment = 0 for i in range(N): if Need > Drink[i][1]: Payment += Drink[i][0] * Drink[i][1] Need -= Drink[i][1] else: Payment += Drink[i][0] * Need break print(Payment)
import sys def solve(): input = sys.stdin.readline N, M = list(map(int, input().split())) drink = [[int(a) for a in input().split()] for _ in range(N)] drink.sort() price = 0 for i in range(N): a, b = drink[i] if b <= M: price += a * b M -= b else: price += a * M break print(price) return 0 if __name__ == "__main__": solve()
14
22
339
453
N, M = list(map(int, input().split())) Drink = [[int(i) for i in input().split()] for _ in range(N)] Drink.sort() Need = M Payment = 0 for i in range(N): if Need > Drink[i][1]: Payment += Drink[i][0] * Drink[i][1] Need -= Drink[i][1] else: Payment += Drink[i][0] * Need break print(Payment)
import sys def solve(): input = sys.stdin.readline N, M = list(map(int, input().split())) drink = [[int(a) for a in input().split()] for _ in range(N)] drink.sort() price = 0 for i in range(N): a, b = drink[i] if b <= M: price += a * b M -= b else: price += a * M break print(price) return 0 if __name__ == "__main__": solve()
false
36.363636
[ "-N, M = list(map(int, input().split()))", "-Drink = [[int(i) for i in input().split()] for _ in range(N)]", "-Drink.sort()", "-Need = M", "-Payment = 0", "-for i in range(N):", "- if Need > Drink[i][1]:", "- Payment += Drink[i][0] * Drink[i][1]", "- Need -= Drink[i][1]", "- else:", "- Payment += Drink[i][0] * Need", "- break", "-print(Payment)", "+import sys", "+", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N, M = list(map(int, input().split()))", "+ drink = [[int(a) for a in input().split()] for _ in range(N)]", "+ drink.sort()", "+ price = 0", "+ for i in range(N):", "+ a, b = drink[i]", "+ if b <= M:", "+ price += a * b", "+ M -= b", "+ else:", "+ price += a * M", "+ break", "+ print(price)", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.036029
0.031251
1.152876
[ "s959284945", "s015125039" ]
u022979415
p03077
python
s648781794
s126081526
21
17
3,316
2,940
Accepted
Accepted
19.05
from math import ceil def main(): l = [int(eval(input())) for _ in range(6)] n, a, b, c, d, e = l group = ceil(n / min(a, b, c, d, e)) print((4 + group)) if __name__ == '__main__': main()
from math import ceil def main(): n = int(eval(input())) required_times = [int(eval(input())) for _ in range(5)] groups = ceil(n / min(required_times)) print((groups + 4)) if __name__ == '__main__': main()
13
13
217
229
from math import ceil def main(): l = [int(eval(input())) for _ in range(6)] n, a, b, c, d, e = l group = ceil(n / min(a, b, c, d, e)) print((4 + group)) if __name__ == "__main__": main()
from math import ceil def main(): n = int(eval(input())) required_times = [int(eval(input())) for _ in range(5)] groups = ceil(n / min(required_times)) print((groups + 4)) if __name__ == "__main__": main()
false
0
[ "- l = [int(eval(input())) for _ in range(6)]", "- n, a, b, c, d, e = l", "- group = ceil(n / min(a, b, c, d, e))", "- print((4 + group))", "+ n = int(eval(input()))", "+ required_times = [int(eval(input())) for _ in range(5)]", "+ groups = ceil(n / min(required_times))", "+ print((groups + 4))" ]
false
0.044064
0.044085
0.999504
[ "s648781794", "s126081526" ]
u077291787
p02558
python
s490098431
s015604642
329
283
146,700
145,256
Accepted
Accepted
13.98
from typing import List class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def unionfind(): # https://judge.yosupo.jp/problem/unionfind # https://atcoder.jp/contests/practice2/tasks/practice2_a N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res)))) if __name__ == "__main__": unionfind()
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, N): self._data_size = N self._roots = [-1] * N def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def unite(self, x, y): x = self[x] y = self[y] if x == y: return elif self._roots[y] < self._roots[x]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def is_connected(self, x, y): return self[x] == self[y] def main(): N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
53
40
1,626
952
from typing import List class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def unionfind(): # https://judge.yosupo.jp/problem/unionfind # https://atcoder.jp/contests/practice2/tasks/practice2_a N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res)))) if __name__ == "__main__": unionfind()
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, N): self._data_size = N self._roots = [-1] * N def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def unite(self, x, y): x = self[x] y = self[y] if x == y: return elif self._roots[y] < self._roots[x]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def is_connected(self, x, y): return self[x] == self[y] def main(): N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
false
24.528302
[ "-from typing import List", "-", "-", "- \"\"\"Union Find (Disjoint Set): O(α(N))", "- References:", "- https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp", "- https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html", "- \"\"\"", "-", "- def __init__(self, data_size: int) -> None:", "- self._data_size = data_size", "- self._roots = [-1] * data_size", "+ def __init__(self, N):", "+ self._data_size = N", "+ self._roots = [-1] * N", "- \"\"\"Find the group (root) of vertex x in O(α(n)) amortized.\"\"\"", "- def is_connected(self, x: int, y: int) -> bool:", "- \"\"\"Return whether two vertices x and y are connected in O(α(n)) amortized.\"\"\"", "- return self[x] == self[y]", "-", "- def unite(self, x: int, y: int) -> None:", "- \"\"\"Unite two groups of vertices x and y in O(α(n)) amortized.\"\"\"", "- x, y = self[x], self[y]", "+ def unite(self, x, y):", "+ x = self[x]", "+ y = self[y]", "- if self._roots[x] > self._roots[y]:", "+ elif self._roots[y] < self._roots[x]:", "+ def is_connected(self, x, y):", "+ return self[x] == self[y]", "-def unionfind():", "- # https://judge.yosupo.jp/problem/unionfind", "- # https://atcoder.jp/contests/practice2/tasks/practice2_a", "+", "+def main():", "- unionfind()", "+ main()" ]
false
0.055765
0.042734
1.304942
[ "s490098431", "s015604642" ]
u357335656
p02658
python
s511783102
s265570900
88
81
21,736
21,420
Accepted
Accepted
7.95
n = int(eval(input())) a = list(map(int,input().split())) a.sort() ans = 1 for i in range(n): ans *= a[i] if ans > 10 ** 18: ans = -1 break print(ans)
n = int(eval(input())) a = list(map(int,input().split())) a.sort() if a[0] == 0: print((0)) exit() a.sort(reverse=True) ans = 1 for i in range(n): ans *= a[i] if ans > 10 ** 18: ans = -1 break print(ans)
12
18
169
232
n = int(eval(input())) a = list(map(int, input().split())) a.sort() ans = 1 for i in range(n): ans *= a[i] if ans > 10**18: ans = -1 break print(ans)
n = int(eval(input())) a = list(map(int, input().split())) a.sort() if a[0] == 0: print((0)) exit() a.sort(reverse=True) ans = 1 for i in range(n): ans *= a[i] if ans > 10**18: ans = -1 break print(ans)
false
33.333333
[ "+if a[0] == 0:", "+ print((0))", "+ exit()", "+a.sort(reverse=True)" ]
false
0.110237
0.047014
2.344783
[ "s511783102", "s265570900" ]
u347640436
p02996
python
s891006650
s762919203
1,556
828
48,320
41,176
Accepted
Accepted
46.79
import sys from functools import cmp_to_key n = int(eval(input())) data = [[int(j) for j in input().split()] for i in range(n)] t = 0 data.sort(key = cmp_to_key(lambda x, y: x[1] - y[1])) for d in data: t += d[0] if t > d[1]: print('No') sys.exit() print('Yes')
from sys import exit n = int(eval(input())) data = [[int(j) for j in input().split()] for i in range(n)] t = 0 data.sort(key=lambda x: x[1]) for d in data: t += d[0] if t > d[1]: print('No') exit() print('Yes')
12
13
279
243
import sys from functools import cmp_to_key n = int(eval(input())) data = [[int(j) for j in input().split()] for i in range(n)] t = 0 data.sort(key=cmp_to_key(lambda x, y: x[1] - y[1])) for d in data: t += d[0] if t > d[1]: print("No") sys.exit() print("Yes")
from sys import exit n = int(eval(input())) data = [[int(j) for j in input().split()] for i in range(n)] t = 0 data.sort(key=lambda x: x[1]) for d in data: t += d[0] if t > d[1]: print("No") exit() print("Yes")
false
7.692308
[ "-import sys", "-from functools import cmp_to_key", "+from sys import exit", "-data.sort(key=cmp_to_key(lambda x, y: x[1] - y[1]))", "+data.sort(key=lambda x: x[1])", "- sys.exit()", "+ exit()" ]
false
0.037083
0.075821
0.489091
[ "s891006650", "s762919203" ]
u852613820
p02918
python
s845188592
s672261687
49
43
3,956
3,956
Accepted
Accepted
12.24
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): N, K = list(map(int, input().split())) S = list(eval(input())) rev = False rev_count = 0 for i in range(1,N): if S[i] == S[i-1]: rev = False else: if not rev and rev_count < K: rev_count += 1 rev = True if rev: S[i] = 'L' if S[i] == 'R' else 'R' ans = 0 for i in range(1,N): if S[i] == S[i-1]: ans += 1 print(ans) if __name__ == "__main__": main()
# 解説見た後に作ったやつ import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): N, K = list(map(int, input().split())) S = list(eval(input())) rev = False ans = 0 rev_count = 0 for i in range(1,N): if S[i] == S[i-1]: ans += 1 rev = False else: if not rev and rev_count < K: rev_count += 1 rev = True if rev: S[i] = 'L' if S[i] == 'R' else 'R' ans += 1 print(ans) if __name__ == "__main__": main()
32
31
612
597
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def main(): N, K = list(map(int, input().split())) S = list(eval(input())) rev = False rev_count = 0 for i in range(1, N): if S[i] == S[i - 1]: rev = False else: if not rev and rev_count < K: rev_count += 1 rev = True if rev: S[i] = "L" if S[i] == "R" else "R" ans = 0 for i in range(1, N): if S[i] == S[i - 1]: ans += 1 print(ans) if __name__ == "__main__": main()
# 解説見た後に作ったやつ import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def main(): N, K = list(map(int, input().split())) S = list(eval(input())) rev = False ans = 0 rev_count = 0 for i in range(1, N): if S[i] == S[i - 1]: ans += 1 rev = False else: if not rev and rev_count < K: rev_count += 1 rev = True if rev: S[i] = "L" if S[i] == "R" else "R" ans += 1 print(ans) if __name__ == "__main__": main()
false
3.125
[ "+# 解説見た後に作ったやつ", "+ ans = 0", "+ ans += 1", "- ans = 0", "- for i in range(1, N):", "- if S[i] == S[i - 1]:", "- ans += 1", "+ ans += 1" ]
false
0.036285
0.113857
0.318693
[ "s845188592", "s672261687" ]
u757117214
p03111
python
s929980729
s902658981
259
82
3,064
3,188
Accepted
Accepted
68.34
import itertools def diff(a,b,c): return abs(A-a)+abs(B-b)+abs(C-c) N,A,B,C,*l=list(map(int,open(0).read().split())) _min=10**6 for i in itertools.product([0,1,2,3],repeat=N): cnt=0 abc=[0,0,0] for j in range(N): if i[j] !=3: abc[i[j]]+=l[j] cnt+=1 if 0 in abc: continue _min=min(_min,10*cnt-30+diff(abc[0],abc[1],abc[2])) print(_min)
def dfs(cnt,a,b,c): if cnt == N: _sum = abs(A-a) + abs(B-b) + abs(C-c) - 30 return _sum if min(a,b,c) > 0 else 10**9 ret0 = dfs(cnt+1, a, b, c) ret1 = dfs(cnt+1, a+l[cnt] , b, c) + 10 ret2 = dfs(cnt+1, a, b+l[cnt], c) + 10 ret3 = dfs(cnt+1, a, b, c+l[cnt]) + 10 return min(ret0,ret1,ret2,ret3) N,A,B,C,*l = list(map(int,open(0).read().split())) print((dfs(0,0,0,0)))
18
12
424
415
import itertools def diff(a, b, c): return abs(A - a) + abs(B - b) + abs(C - c) N, A, B, C, *l = list(map(int, open(0).read().split())) _min = 10**6 for i in itertools.product([0, 1, 2, 3], repeat=N): cnt = 0 abc = [0, 0, 0] for j in range(N): if i[j] != 3: abc[i[j]] += l[j] cnt += 1 if 0 in abc: continue _min = min(_min, 10 * cnt - 30 + diff(abc[0], abc[1], abc[2])) print(_min)
def dfs(cnt, a, b, c): if cnt == N: _sum = abs(A - a) + abs(B - b) + abs(C - c) - 30 return _sum if min(a, b, c) > 0 else 10**9 ret0 = dfs(cnt + 1, a, b, c) ret1 = dfs(cnt + 1, a + l[cnt], b, c) + 10 ret2 = dfs(cnt + 1, a, b + l[cnt], c) + 10 ret3 = dfs(cnt + 1, a, b, c + l[cnt]) + 10 return min(ret0, ret1, ret2, ret3) N, A, B, C, *l = list(map(int, open(0).read().split())) print((dfs(0, 0, 0, 0)))
false
33.333333
[ "-import itertools", "-", "-", "-def diff(a, b, c):", "- return abs(A - a) + abs(B - b) + abs(C - c)", "+def dfs(cnt, a, b, c):", "+ if cnt == N:", "+ _sum = abs(A - a) + abs(B - b) + abs(C - c) - 30", "+ return _sum if min(a, b, c) > 0 else 10**9", "+ ret0 = dfs(cnt + 1, a, b, c)", "+ ret1 = dfs(cnt + 1, a + l[cnt], b, c) + 10", "+ ret2 = dfs(cnt + 1, a, b + l[cnt], c) + 10", "+ ret3 = dfs(cnt + 1, a, b, c + l[cnt]) + 10", "+ return min(ret0, ret1, ret2, ret3)", "-_min = 10**6", "-for i in itertools.product([0, 1, 2, 3], repeat=N):", "- cnt = 0", "- abc = [0, 0, 0]", "- for j in range(N):", "- if i[j] != 3:", "- abc[i[j]] += l[j]", "- cnt += 1", "- if 0 in abc:", "- continue", "- _min = min(_min, 10 * cnt - 30 + diff(abc[0], abc[1], abc[2]))", "-print(_min)", "+print((dfs(0, 0, 0, 0)))" ]
false
0.356906
0.15129
2.359079
[ "s929980729", "s902658981" ]
u566297428
p02641
python
s058755783
s711501876
30
27
9,112
9,152
Accepted
Accepted
10
X, N = list(map(int, input().split())) p = list(map(int, input().split())) for d in range(X + 1): for s in [-1, +1]: a = X + s * d if p.count(a) == 0: print(a) exit(0)
import sys X, N = list(map(int, input().split())) p = list(map(int, input().split())) for d in range(X + 1): for s in [-1, +1]: a = X + s * d if p.count(a) == 0: print(a) sys.exit(0)
8
9
212
228
X, N = list(map(int, input().split())) p = list(map(int, input().split())) for d in range(X + 1): for s in [-1, +1]: a = X + s * d if p.count(a) == 0: print(a) exit(0)
import sys X, N = list(map(int, input().split())) p = list(map(int, input().split())) for d in range(X + 1): for s in [-1, +1]: a = X + s * d if p.count(a) == 0: print(a) sys.exit(0)
false
11.111111
[ "+import sys", "+", "- exit(0)", "+ sys.exit(0)" ]
false
0.147124
0.269172
0.54658
[ "s058755783", "s711501876" ]
u312025627
p02995
python
s357557954
s471340990
162
65
38,384
62,232
Accepted
Accepted
59.88
def main(): a, b, c, d = (int(i) for i in input().split()) def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x def lcm(x, y): return x*y//gcd(x, y) def f(x): p = x//c q = x//d r = x//lcm(c, d) return x - p - q + r print((f(b) - f(a-1))) if __name__ == '__main__': main()
def main(): from math import gcd a, b, c, d = (int(i) for i in input().split()) L = c*d//gcd(c, d) ans = b - (b//c + b//d - b//L) ans -= (a-1) - ((a-1)//c + (a-1)//d - (a-1)//L) print(ans) if __name__ == '__main__': main()
24
11
432
263
def main(): a, b, c, d = (int(i) for i in input().split()) def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def f(x): p = x // c q = x // d r = x // lcm(c, d) return x - p - q + r print((f(b) - f(a - 1))) if __name__ == "__main__": main()
def main(): from math import gcd a, b, c, d = (int(i) for i in input().split()) L = c * d // gcd(c, d) ans = b - (b // c + b // d - b // L) ans -= (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // L) print(ans) if __name__ == "__main__": main()
false
54.166667
[ "+ from math import gcd", "+", "-", "- def gcd(x, y):", "- if y == 0:", "- return x", "- while y != 0:", "- x, y = y, x % y", "- return x", "-", "- def lcm(x, y):", "- return x * y // gcd(x, y)", "-", "- def f(x):", "- p = x // c", "- q = x // d", "- r = x // lcm(c, d)", "- return x - p - q + r", "-", "- print((f(b) - f(a - 1)))", "+ L = c * d // gcd(c, d)", "+ ans = b - (b // c + b // d - b // L)", "+ ans -= (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // L)", "+ print(ans)" ]
false
0.109788
0.038513
2.850681
[ "s357557954", "s471340990" ]
u488636998
p02934
python
s452229054
s925818634
151
18
12,444
2,940
Accepted
Accepted
88.08
import numpy as np N=int(eval(input())) str_list = input().split(' ') A = [int(x) for x in str_list] A = np.array(A) total = A.sum() prod = A.prod() #print( prod/( (prod/A).sum() ) ) print(( 1.0/np.sum(1.0/A) ))
N=int(eval(input())) A=list(map(int, input().split())) prod = 1 for ii in range(N): prod *= A[ii] sum = 0 for ii in range(N): sum += prod//A[ii] print((float(prod)/float(sum)))
10
10
213
187
import numpy as np N = int(eval(input())) str_list = input().split(" ") A = [int(x) for x in str_list] A = np.array(A) total = A.sum() prod = A.prod() # print( prod/( (prod/A).sum() ) ) print((1.0 / np.sum(1.0 / A)))
N = int(eval(input())) A = list(map(int, input().split())) prod = 1 for ii in range(N): prod *= A[ii] sum = 0 for ii in range(N): sum += prod // A[ii] print((float(prod) / float(sum)))
false
0
[ "-import numpy as np", "-", "-str_list = input().split(\" \")", "-A = [int(x) for x in str_list]", "-A = np.array(A)", "-total = A.sum()", "-prod = A.prod()", "-# print( prod/( (prod/A).sum() ) )", "-print((1.0 / np.sum(1.0 / A)))", "+A = list(map(int, input().split()))", "+prod = 1", "+for ii in range(N):", "+ prod *= A[ii]", "+sum = 0", "+for ii in range(N):", "+ sum += prod // A[ii]", "+print((float(prod) / float(sum)))" ]
false
0.17109
0.036079
4.742132
[ "s452229054", "s925818634" ]
u543954314
p02914
python
s338147295
s281795216
1,625
982
16,116
16,116
Accepted
Accepted
39.57
def maxSubarrayXOR(lis, n, INT_BITS = 60): idx = 0 for i in range(INT_BITS-1,-1,-1): Mele = -1 bit_i = 1 << i for j in range(idx, n): if lis[j] & bit_i and lis[j] > Mele: Midx, Mele = j, lis[j] if Mele < 0: continue lis[Midx], lis[idx] = lis[idx], lis[Midx] for j in range(n): if j != idx and lis[j] & bit_i: lis[j] ^= lis[idx] idx += 1 res = 0 for x in lis: res ^= x return res n = int(eval(input())) a = list(map(int, input().split())) t = 0 for x in a: t ^= x b = [x^(x&t) for x in a] print((t + maxSubarrayXOR(b, n)*2))
def maxSubarrayXOR(lis, n, INT_BITS = 60): idx = 0 for i in range(INT_BITS-1,-1,-1): Midx = -1 bit_i = 1 << i for j in range(idx, n): if lis[j] & bit_i: Midx = j break else: continue lis[Midx], lis[idx] = lis[idx], lis[Midx] for j in range(n): if j != idx and lis[j] & bit_i: lis[j] ^= lis[idx] idx += 1 res = 0 for x in lis: res ^= x return res n = int(eval(input())) a = list(map(int, input().split())) t = 0 for x in a: t ^= x b = [x^(x&t) for x in a] print((t + maxSubarrayXOR(b, n)*2))
24
25
671
656
def maxSubarrayXOR(lis, n, INT_BITS=60): idx = 0 for i in range(INT_BITS - 1, -1, -1): Mele = -1 bit_i = 1 << i for j in range(idx, n): if lis[j] & bit_i and lis[j] > Mele: Midx, Mele = j, lis[j] if Mele < 0: continue lis[Midx], lis[idx] = lis[idx], lis[Midx] for j in range(n): if j != idx and lis[j] & bit_i: lis[j] ^= lis[idx] idx += 1 res = 0 for x in lis: res ^= x return res n = int(eval(input())) a = list(map(int, input().split())) t = 0 for x in a: t ^= x b = [x ^ (x & t) for x in a] print((t + maxSubarrayXOR(b, n) * 2))
def maxSubarrayXOR(lis, n, INT_BITS=60): idx = 0 for i in range(INT_BITS - 1, -1, -1): Midx = -1 bit_i = 1 << i for j in range(idx, n): if lis[j] & bit_i: Midx = j break else: continue lis[Midx], lis[idx] = lis[idx], lis[Midx] for j in range(n): if j != idx and lis[j] & bit_i: lis[j] ^= lis[idx] idx += 1 res = 0 for x in lis: res ^= x return res n = int(eval(input())) a = list(map(int, input().split())) t = 0 for x in a: t ^= x b = [x ^ (x & t) for x in a] print((t + maxSubarrayXOR(b, n) * 2))
false
4
[ "- Mele = -1", "+ Midx = -1", "- if lis[j] & bit_i and lis[j] > Mele:", "- Midx, Mele = j, lis[j]", "- if Mele < 0:", "+ if lis[j] & bit_i:", "+ Midx = j", "+ break", "+ else:" ]
false
0.036731
0.067077
0.547594
[ "s338147295", "s281795216" ]
u580258754
p02900
python
s136901356
s099218999
197
163
5,048
5,048
Accepted
Accepted
17.26
import fractions a, b = list(map(int, input().split())) n = fractions.gcd(a, b) def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table print((len(set(prime_decomposition(n)))+1))
import fractions a, b = list(map(int, input().split())) common_num = fractions.gcd(a, b) ans = 1 for i in range(2,int(1+common_num**0.5)): if common_num % i == 0: ans += 1 while common_num % i == 0: common_num //= i if common_num > 1: ans += 1 print(ans)
17
14
352
288
import fractions a, b = list(map(int, input().split())) n = fractions.gcd(a, b) def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table print((len(set(prime_decomposition(n))) + 1))
import fractions a, b = list(map(int, input().split())) common_num = fractions.gcd(a, b) ans = 1 for i in range(2, int(1 + common_num**0.5)): if common_num % i == 0: ans += 1 while common_num % i == 0: common_num //= i if common_num > 1: ans += 1 print(ans)
false
17.647059
[ "-n = fractions.gcd(a, b)", "-", "-", "-def prime_decomposition(n):", "- i = 2", "- table = []", "- while i * i <= n:", "- while n % i == 0:", "- n //= i", "- table.append(i)", "- i += 1", "- if n > 1:", "- table.append(n)", "- return table", "-", "-", "-print((len(set(prime_decomposition(n))) + 1))", "+common_num = fractions.gcd(a, b)", "+ans = 1", "+for i in range(2, int(1 + common_num**0.5)):", "+ if common_num % i == 0:", "+ ans += 1", "+ while common_num % i == 0:", "+ common_num //= i", "+if common_num > 1:", "+ ans += 1", "+print(ans)" ]
false
0.053699
0.123862
0.433542
[ "s136901356", "s099218999" ]
u360116509
p03031
python
s120622450
s945565177
26
22
3,064
3,064
Accepted
Accepted
15.38
def main(): N, M = list(map(int, input().split())) switchs = [] for _ in range(M): ks = list(map(int, input().split())) switchs.append(ks[1:]) p = list(map(int, input().split())) ans = 0 for b in range(1 << N): f = True for i, s in enumerate(switchs): c = 0 for ss in s: if b & (1 << (ss - 1)): c += 1 if c % 2 != p[i]: f = False break if f: ans += 1 print(ans) main()
def main(): N, M = list(map(int, input().split())) switchs = [] for _ in range(M): ks = list(map(int, input().split())) switchs.append([1 << s - 1 for s in ks[1:]]) p = list(map(int, input().split())) ans = 0 for b in range(1 << N): f = True for i, s in enumerate(switchs): c = 0 for ss in s: if b & ss: c += 1 if c % 2 != p[i]: f = False break if f: ans += 1 print(ans) main()
23
23
569
578
def main(): N, M = list(map(int, input().split())) switchs = [] for _ in range(M): ks = list(map(int, input().split())) switchs.append(ks[1:]) p = list(map(int, input().split())) ans = 0 for b in range(1 << N): f = True for i, s in enumerate(switchs): c = 0 for ss in s: if b & (1 << (ss - 1)): c += 1 if c % 2 != p[i]: f = False break if f: ans += 1 print(ans) main()
def main(): N, M = list(map(int, input().split())) switchs = [] for _ in range(M): ks = list(map(int, input().split())) switchs.append([1 << s - 1 for s in ks[1:]]) p = list(map(int, input().split())) ans = 0 for b in range(1 << N): f = True for i, s in enumerate(switchs): c = 0 for ss in s: if b & ss: c += 1 if c % 2 != p[i]: f = False break if f: ans += 1 print(ans) main()
false
0
[ "- switchs.append(ks[1:])", "+ switchs.append([1 << s - 1 for s in ks[1:]])", "- if b & (1 << (ss - 1)):", "+ if b & ss:" ]
false
0.099069
0.044991
2.201989
[ "s120622450", "s945565177" ]
u153665391
p02268
python
s952918986
s391573632
1,110
520
18,820
16,716
Accepted
Accepted
53.15
def binary_search(S, n, index ): if S[index] == n: return 'eq' elif S[index] < n: return 'bt' elif S[index] > n: return 'lt' n = int(eval(input())) S = [int(i) for i in input().split()] q = int(eval(input())) T = [int(i) for i in input().split()] cnt = 0 for i in T: mini = 0 maxi = len(S) - 1 while int(maxi - mini) >= 0: index = int( (mini + maxi) / 2 ) rs = binary_search(S, i, index ) if rs == 'eq': cnt += 1 break elif rs == 'bt': mini = index + 1 elif rs == 'lt': maxi = index - 1 print(cnt)
N = int(eval(input())) S = list(map(int, input().split())) Q = int(eval(input())) T = list(map(int, input().split())) def binary_search(target_num, head, tail): idx = int((head+tail)/2) if target_num == S[idx]: return True elif target_num < S[idx]: if head == idx: return False return binary_search(target_num, head, idx-1) else: if tail == idx: return False return binary_search(target_num, idx+1, tail) match_count = 0 for target_num in T: if binary_search(target_num, 0, len(S)-1): match_count += 1 print((str(match_count)))
29
25
652
634
def binary_search(S, n, index): if S[index] == n: return "eq" elif S[index] < n: return "bt" elif S[index] > n: return "lt" n = int(eval(input())) S = [int(i) for i in input().split()] q = int(eval(input())) T = [int(i) for i in input().split()] cnt = 0 for i in T: mini = 0 maxi = len(S) - 1 while int(maxi - mini) >= 0: index = int((mini + maxi) / 2) rs = binary_search(S, i, index) if rs == "eq": cnt += 1 break elif rs == "bt": mini = index + 1 elif rs == "lt": maxi = index - 1 print(cnt)
N = int(eval(input())) S = list(map(int, input().split())) Q = int(eval(input())) T = list(map(int, input().split())) def binary_search(target_num, head, tail): idx = int((head + tail) / 2) if target_num == S[idx]: return True elif target_num < S[idx]: if head == idx: return False return binary_search(target_num, head, idx - 1) else: if tail == idx: return False return binary_search(target_num, idx + 1, tail) match_count = 0 for target_num in T: if binary_search(target_num, 0, len(S) - 1): match_count += 1 print((str(match_count)))
false
13.793103
[ "-def binary_search(S, n, index):", "- if S[index] == n:", "- return \"eq\"", "- elif S[index] < n:", "- return \"bt\"", "- elif S[index] > n:", "- return \"lt\"", "+N = int(eval(input()))", "+S = list(map(int, input().split()))", "+Q = int(eval(input()))", "+T = list(map(int, input().split()))", "-n = int(eval(input()))", "-S = [int(i) for i in input().split()]", "-q = int(eval(input()))", "-T = [int(i) for i in input().split()]", "-cnt = 0", "-for i in T:", "- mini = 0", "- maxi = len(S) - 1", "- while int(maxi - mini) >= 0:", "- index = int((mini + maxi) / 2)", "- rs = binary_search(S, i, index)", "- if rs == \"eq\":", "- cnt += 1", "- break", "- elif rs == \"bt\":", "- mini = index + 1", "- elif rs == \"lt\":", "- maxi = index - 1", "-print(cnt)", "+def binary_search(target_num, head, tail):", "+ idx = int((head + tail) / 2)", "+ if target_num == S[idx]:", "+ return True", "+ elif target_num < S[idx]:", "+ if head == idx:", "+ return False", "+ return binary_search(target_num, head, idx - 1)", "+ else:", "+ if tail == idx:", "+ return False", "+ return binary_search(target_num, idx + 1, tail)", "+", "+", "+match_count = 0", "+for target_num in T:", "+ if binary_search(target_num, 0, len(S) - 1):", "+ match_count += 1", "+print((str(match_count)))" ]
false
0.039766
0.043109
0.922448
[ "s952918986", "s391573632" ]
u476604182
p03142
python
s178212338
s948838246
352
297
31,600
37,140
Accepted
Accepted
15.62
from collections import defaultdict, deque N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [0]*(N+1) cnt = [0]*(N+1) for a,b in zip(*[iter(L)]*2): dic[a] += [b] cnt[b] += 1 for i in range(1,N+1): if cnt[i]==0: q = deque([i]) break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c]==0: par[c] = m q += [c] for i in range(1,N+1): print((par[i]))
from collections import defaultdict, deque N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [0]*N cnt = [0]*(N+1) for a,b in zip(*[iter(L)]*2): dic[a] += [b] cnt[b] += 1 for i in range(1,N+1): if cnt[i]==0: q = deque([i]) par[i-1] = '0' break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c]==0: par[c-1] = str(m) q += [c] ans = '\n'.join(par) print(ans)
24
25
450
466
from collections import defaultdict, deque N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [0] * (N + 1) cnt = [0] * (N + 1) for a, b in zip(*[iter(L)] * 2): dic[a] += [b] cnt[b] += 1 for i in range(1, N + 1): if cnt[i] == 0: q = deque([i]) break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c] == 0: par[c] = m q += [c] for i in range(1, N + 1): print((par[i]))
from collections import defaultdict, deque N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [0] * N cnt = [0] * (N + 1) for a, b in zip(*[iter(L)] * 2): dic[a] += [b] cnt[b] += 1 for i in range(1, N + 1): if cnt[i] == 0: q = deque([i]) par[i - 1] = "0" break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c] == 0: par[c - 1] = str(m) q += [c] ans = "\n".join(par) print(ans)
false
4
[ "-par = [0] * (N + 1)", "+par = [0] * N", "+ par[i - 1] = \"0\"", "- par[c] = m", "+ par[c - 1] = str(m)", "-for i in range(1, N + 1):", "- print((par[i]))", "+ans = \"\\n\".join(par)", "+print(ans)" ]
false
0.059025
0.035363
1.66914
[ "s178212338", "s948838246" ]
u279493135
p02804
python
s578472654
s807630002
878
419
90,096
92,316
Accepted
Accepted
52.28
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees 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 bisect import bisect import heapq def input(): return sys.stdin.readline().strip() 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() upper = 10**6 # 必要そうな階乗の限界を入れる factorial = [1] for i in range(1, upper): factorial.append(factorial[i-1] * i % mod) def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return power(x, int(y/2)) ** 2 % mod else: return power(x, int((y-1)/2)) ** 2 * x % mod def C(n, r): return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod x_inv = [0] * upper x_inv[-1] = power(factorial[-1], mod-2) for i in range(upper-2, -1, -1): x_inv[i] = x_inv[i+1] * (i+1) % mod A.sort() ma = 0 mi = 0 for i in range(N-K+1): ma = (ma + A[-i-1] * C(N-1-i, K-1)) # print("ma:", A[-i-1], "*", C(N-1-i, K-1)) mi = (mi + A[i] * C(N-1-i, K-1)) # print("mi", A[i], "*", C(N-1-i, K-1)) # print(ma, mi) print(((ma-mi)%mod))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() A = LIST() A.sort(reverse=True) ans = 0 lim = 10**6 # 必要そうな階乗の限界を入れる fact = [1] * (lim+1) fact_inv = [1] * (lim+1) for n in range(1, lim+1): fact[n] = (fact[n-1] * n) % mod fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = (n * fact_inv[n]) % mod def C(n, r): return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n-r]) % mod for i in range(N-K+1): ans += A[i] * C(N-i-1, K-1) ans %= mod for i in range(N-K+1): ans -= A[N-i-1] * C(N-i-1, K-1) ans %= mod print(ans)
57
44
1,537
1,329
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees 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 bisect import bisect import heapq def input(): return sys.stdin.readline().strip() 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() upper = 10**6 # 必要そうな階乗の限界を入れる factorial = [1] for i in range(1, upper): factorial.append(factorial[i - 1] * i % mod) def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return power(x, int(y / 2)) ** 2 % mod else: return power(x, int((y - 1) / 2)) ** 2 * x % mod def C(n, r): return (((factorial[n] * x_inv[r]) % mod) * x_inv[n - r]) % mod x_inv = [0] * upper x_inv[-1] = power(factorial[-1], mod - 2) for i in range(upper - 2, -1, -1): x_inv[i] = x_inv[i + 1] * (i + 1) % mod A.sort() ma = 0 mi = 0 for i in range(N - K + 1): ma = ma + A[-i - 1] * C(N - 1 - i, K - 1) # print("ma:", A[-i-1], "*", C(N-1-i, K-1)) mi = mi + A[i] * C(N - 1 - i, K - 1) # print("mi", A[i], "*", C(N-1-i, K-1)) # print(ma, mi) print(((ma - mi) % mod))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, K = MAP() A = LIST() A.sort(reverse=True) ans = 0 lim = 10**6 # 必要そうな階乗の限界を入れる fact = [1] * (lim + 1) fact_inv = [1] * (lim + 1) for n in range(1, lim + 1): fact[n] = (fact[n - 1] * n) % mod fact_inv[lim] = pow(fact[lim], mod - 2, mod) for n in range(lim, 0, -1): fact_inv[n - 1] = (n * fact_inv[n]) % mod def C(n, r): return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n - r]) % mod for i in range(N - K + 1): ans += A[i] * C(N - i - 1, K - 1) ans %= mod for i in range(N - K + 1): ans -= A[N - i - 1] * C(N - i - 1, K - 1) ans %= mod print(ans)
false
22.807018
[ "-from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees", "-from itertools import permutations, combinations, product, accumulate", "-", "-# とけてない", "+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians", "+from itertools import accumulate, permutations, combinations, product", "+from bisect import bisect, bisect_left", "-from bisect import bisect", "-import heapq", "+from heapq import heappush, heappop", "+from functools import reduce", "+def ZIP(n):", "+ return list(zip(*(MAP() for _ in range(n))))", "+", "+", "-upper = 10**6 # 必要そうな階乗の限界を入れる", "-factorial = [1]", "-for i in range(1, upper):", "- factorial.append(factorial[i - 1] * i % mod)", "-", "-", "-def power(x, y):", "- if y == 0:", "- return 1", "- elif y == 1:", "- return x % mod", "- elif y % 2 == 0:", "- return power(x, int(y / 2)) ** 2 % mod", "- else:", "- return power(x, int((y - 1) / 2)) ** 2 * x % mod", "+A.sort(reverse=True)", "+ans = 0", "+lim = 10**6 # 必要そうな階乗の限界を入れる", "+fact = [1] * (lim + 1)", "+fact_inv = [1] * (lim + 1)", "+for n in range(1, lim + 1):", "+ fact[n] = (fact[n - 1] * n) % mod", "+fact_inv[lim] = pow(fact[lim], mod - 2, mod)", "+for n in range(lim, 0, -1):", "+ fact_inv[n - 1] = (n * fact_inv[n]) % mod", "- return (((factorial[n] * x_inv[r]) % mod) * x_inv[n - r]) % mod", "+ return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n - r]) % mod", "-x_inv = [0] * upper", "-x_inv[-1] = power(factorial[-1], mod - 2)", "-for i in range(upper - 2, -1, -1):", "- x_inv[i] = x_inv[i + 1] * (i + 1) % mod", "-A.sort()", "-ma = 0", "-mi = 0", "- ma = ma + A[-i - 1] * C(N - 1 - i, K - 1)", "- # print(\"ma:\", A[-i-1], \"*\", C(N-1-i, K-1))", "- mi = mi + A[i] * C(N - 1 - i, K - 1)", "- # print(\"mi\", A[i], \"*\", C(N-1-i, K-1))", "-# print(ma, mi)", "-print(((ma - mi) % mod))", "+ ans += A[i] * C(N - i - 1, K - 1)", "+ ans %= mod", "+for i in range(N - K + 1):", "+ ans -= A[N - i - 1] * C(N - i - 1, K - 1)", "+ ans %= mod", "+print(ans)" ]
false
0.867527
1.437886
0.603335
[ "s578472654", "s807630002" ]
u214434454
p03680
python
s419669038
s141527706
238
204
15,992
7,084
Accepted
Accepted
14.29
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] ans = False used = set() i = 1 count = 0 while ans == False: count += 1 if a[i-1] == 2: ans = True elif i-1 in used: break else: used.add(i-1) i = a[i-1] if ans == True: print(count) else: print("-1")
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] count = 0 i = 0 ans = False while count < n: count += 1 if a[i] == 2: ans = True break else: i = a[i] - 1 if ans == True: print(count) else: print("-1")
20
16
338
265
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] ans = False used = set() i = 1 count = 0 while ans == False: count += 1 if a[i - 1] == 2: ans = True elif i - 1 in used: break else: used.add(i - 1) i = a[i - 1] if ans == True: print(count) else: print("-1")
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] count = 0 i = 0 ans = False while count < n: count += 1 if a[i] == 2: ans = True break else: i = a[i] - 1 if ans == True: print(count) else: print("-1")
false
20
[ "+count = 0", "+i = 0", "-used = set()", "-i = 1", "-count = 0", "-while ans == False:", "+while count < n:", "- if a[i - 1] == 2:", "+ if a[i] == 2:", "- elif i - 1 in used:", "- used.add(i - 1)", "- i = a[i - 1]", "+ i = a[i] - 1" ]
false
0.140149
0.085148
1.645948
[ "s419669038", "s141527706" ]
u291278680
p03013
python
s432591336
s932103450
329
188
21,076
11,884
Accepted
Accepted
42.86
import numpy as np from collections import defaultdict from functools import reduce MOD = 1000000007 A = set() # s = input() # n = int(input()) # A = list(map(int, input().split())) n, m = list(map(int, input().split())) for _ in range(m): a = int(eval(input())) A.add(a) res = [0]*(n+1) res[0] = 1 if 1 not in A: res[1] = 1 for i in range(2, n+1): if i in A: continue res[i] = (res[i-1] + res[i-2])%MOD print((res[n])) class Interval(): def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i-1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n-1, b-1)] if a > 0: res -= self.sum_li[a-1] return res
MOD = 1000000007 A = set() # s = input() # n = int(input()) # A = list(map(int, input().split())) n, m = list(map(int, input().split())) for _ in range(m): a = int(eval(input())) A.add(a) res = [0]*(n+1) res[0] = 1 if 1 not in A: res[1] = 1 for i in range(2, n+1): if i in A: continue res[i] = (res[i-1] + res[i-2])%MOD print((res[n]))
49
25
915
381
import numpy as np from collections import defaultdict from functools import reduce MOD = 1000000007 A = set() # s = input() # n = int(input()) # A = list(map(int, input().split())) n, m = list(map(int, input().split())) for _ in range(m): a = int(eval(input())) A.add(a) res = [0] * (n + 1) res[0] = 1 if 1 not in A: res[1] = 1 for i in range(2, n + 1): if i in A: continue res[i] = (res[i - 1] + res[i - 2]) % MOD print((res[n])) class Interval: def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i - 1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n - 1, b - 1)] if a > 0: res -= self.sum_li[a - 1] return res
MOD = 1000000007 A = set() # s = input() # n = int(input()) # A = list(map(int, input().split())) n, m = list(map(int, input().split())) for _ in range(m): a = int(eval(input())) A.add(a) res = [0] * (n + 1) res[0] = 1 if 1 not in A: res[1] = 1 for i in range(2, n + 1): if i in A: continue res[i] = (res[i - 1] + res[i - 2]) % MOD print((res[n]))
false
48.979592
[ "-import numpy as np", "-from collections import defaultdict", "-from functools import reduce", "-", "-", "-", "-class Interval:", "- def __init__(self, li):", "- self.li = li", "- self.n = len(li)", "- self.sum_li = [li[0]]", "- for i in range(1, self.n):", "- self.sum_li.append(self.sum_li[i - 1] + li[i])", "-", "- def sum(self, a, b=None):", "- if b is None:", "- return self.sum(0, a)", "- res = self.sum_li[min(self.n - 1, b - 1)]", "- if a > 0:", "- res -= self.sum_li[a - 1]", "- return res" ]
false
0.03868
0.037935
1.01965
[ "s432591336", "s932103450" ]
u382748202
p03070
python
s011865462
s906099103
2,933
1,382
328,896
329,152
Accepted
Accepted
52.88
import math import numpy as np N = int(eval(input())) a = np.array([int(eval(input())) for _ in range(N)]) s = np.sum(a) # Counts of (R >= s / 2) dp0 = np.zeros((N + 1, s + 1)) dp0[0, 0] = 1 # Counts of (R == s / 2 and G == s / 2) dp1 = np.zeros((N + 1, s // 2 + 1)) dp1[0, 0] = 1 mod = 998244353 for i, x in enumerate(a): dp0[i + 1, :] += dp0[i, :] * 2 % mod dp0[i + 1, x:] += dp0[i, :-x] % mod dp1[i + 1, :] += dp1[i, :] % mod dp1[i + 1, x:] += dp1[i, :-x] % mod c0 = int(np.sum(dp0[N][math.ceil(s / 2):])) c1 = int(dp1[N][s // 2]) if s % 2 == 0 else 0 ans = (3 ** N - 3 * c0 + 3 * c1) % mod print(ans)
import math import numpy as np N = int(eval(input())) a = np.array([int(eval(input())) for _ in range(N)]) s = np.sum(a) dp0 = np.zeros((N + 1, s + 1), dtype=np.int64) dp0[0, 0] = 1 dp1 = np.zeros((N + 1, s // 2 + 1), dtype=np.int64) dp1[0, 0] = 1 mod = 998244353 for i, x in enumerate(a): dp0[i + 1, :] += dp0[i, :] * 2 % mod dp0[i + 1, x:] += dp0[i, :-x] % mod dp1[i + 1, :] += dp1[i, :] % mod dp1[i + 1, x:] += dp1[i, :-x] % mod # Counts of (R >= s / 2) c0 = int(np.sum(dp0[N][math.ceil(s / 2):])) # Counts of (R == s / 2 and G == s / 2) c1 = int(dp1[N][s // 2]) if s % 2 == 0 else 0 ans = (3 ** N - 3 * c0 + 3 * c1) % mod print(ans)
26
26
638
670
import math import numpy as np N = int(eval(input())) a = np.array([int(eval(input())) for _ in range(N)]) s = np.sum(a) # Counts of (R >= s / 2) dp0 = np.zeros((N + 1, s + 1)) dp0[0, 0] = 1 # Counts of (R == s / 2 and G == s / 2) dp1 = np.zeros((N + 1, s // 2 + 1)) dp1[0, 0] = 1 mod = 998244353 for i, x in enumerate(a): dp0[i + 1, :] += dp0[i, :] * 2 % mod dp0[i + 1, x:] += dp0[i, :-x] % mod dp1[i + 1, :] += dp1[i, :] % mod dp1[i + 1, x:] += dp1[i, :-x] % mod c0 = int(np.sum(dp0[N][math.ceil(s / 2) :])) c1 = int(dp1[N][s // 2]) if s % 2 == 0 else 0 ans = (3**N - 3 * c0 + 3 * c1) % mod print(ans)
import math import numpy as np N = int(eval(input())) a = np.array([int(eval(input())) for _ in range(N)]) s = np.sum(a) dp0 = np.zeros((N + 1, s + 1), dtype=np.int64) dp0[0, 0] = 1 dp1 = np.zeros((N + 1, s // 2 + 1), dtype=np.int64) dp1[0, 0] = 1 mod = 998244353 for i, x in enumerate(a): dp0[i + 1, :] += dp0[i, :] * 2 % mod dp0[i + 1, x:] += dp0[i, :-x] % mod dp1[i + 1, :] += dp1[i, :] % mod dp1[i + 1, x:] += dp1[i, :-x] % mod # Counts of (R >= s / 2) c0 = int(np.sum(dp0[N][math.ceil(s / 2) :])) # Counts of (R == s / 2 and G == s / 2) c1 = int(dp1[N][s // 2]) if s % 2 == 0 else 0 ans = (3**N - 3 * c0 + 3 * c1) % mod print(ans)
false
0
[ "-# Counts of (R >= s / 2)", "-dp0 = np.zeros((N + 1, s + 1))", "+dp0 = np.zeros((N + 1, s + 1), dtype=np.int64)", "-# Counts of (R == s / 2 and G == s / 2)", "-dp1 = np.zeros((N + 1, s // 2 + 1))", "+dp1 = np.zeros((N + 1, s // 2 + 1), dtype=np.int64)", "+# Counts of (R >= s / 2)", "+# Counts of (R == s / 2 and G == s / 2)" ]
false
0.221761
0.652499
0.339865
[ "s011865462", "s906099103" ]
u528470578
p03162
python
s145884989
s031429517
698
639
74,968
51,416
Accepted
Accepted
8.45
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [] for i in range(N+1): dp.append([0] * 3) for j in range(1, N+1): for k in range(3): if j == 1: dp[j][k] = abc[0][k] else: box = [] for l in range(3): if l == k: continue else: box.append(dp[j-1][l] + abc[j-1][k]) dp[j][k] = max(dp[j][k], max(box)) print((max(dp[N])))
N = int(eval(input())) dpa = [0] * N dpb = [0] * N dpc = [0] * N a, b, c = list(map(int, input().split())) dpa[0] = a dpb[0] = b dpc[0] = c for i in range(1, N): a, b, c = list(map(int, input().split())) dpa[i] = max(dpb[i-1] + a, dpc[i-1] + a) dpb[i] = max(dpa[i-1] + b, dpc[i-1] + b) dpc[i] = max(dpa[i-1] + c, dpb[i-1] + c) print((max(dpa[N-1], dpb[N-1], dpc[N-1])))
20
16
513
382
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [] for i in range(N + 1): dp.append([0] * 3) for j in range(1, N + 1): for k in range(3): if j == 1: dp[j][k] = abc[0][k] else: box = [] for l in range(3): if l == k: continue else: box.append(dp[j - 1][l] + abc[j - 1][k]) dp[j][k] = max(dp[j][k], max(box)) print((max(dp[N])))
N = int(eval(input())) dpa = [0] * N dpb = [0] * N dpc = [0] * N a, b, c = list(map(int, input().split())) dpa[0] = a dpb[0] = b dpc[0] = c for i in range(1, N): a, b, c = list(map(int, input().split())) dpa[i] = max(dpb[i - 1] + a, dpc[i - 1] + a) dpb[i] = max(dpa[i - 1] + b, dpc[i - 1] + b) dpc[i] = max(dpa[i - 1] + c, dpb[i - 1] + c) print((max(dpa[N - 1], dpb[N - 1], dpc[N - 1])))
false
20
[ "-abc = [list(map(int, input().split())) for _ in range(N)]", "-dp = []", "-for i in range(N + 1):", "- dp.append([0] * 3)", "-for j in range(1, N + 1):", "- for k in range(3):", "- if j == 1:", "- dp[j][k] = abc[0][k]", "- else:", "- box = []", "- for l in range(3):", "- if l == k:", "- continue", "- else:", "- box.append(dp[j - 1][l] + abc[j - 1][k])", "- dp[j][k] = max(dp[j][k], max(box))", "-print((max(dp[N])))", "+dpa = [0] * N", "+dpb = [0] * N", "+dpc = [0] * N", "+a, b, c = list(map(int, input().split()))", "+dpa[0] = a", "+dpb[0] = b", "+dpc[0] = c", "+for i in range(1, N):", "+ a, b, c = list(map(int, input().split()))", "+ dpa[i] = max(dpb[i - 1] + a, dpc[i - 1] + a)", "+ dpb[i] = max(dpa[i - 1] + b, dpc[i - 1] + b)", "+ dpc[i] = max(dpa[i - 1] + c, dpb[i - 1] + c)", "+print((max(dpa[N - 1], dpb[N - 1], dpc[N - 1])))" ]
false
0.03567
0.062313
0.572432
[ "s145884989", "s031429517" ]
u670567845
p03030
python
s761920153
s421242181
59
23
62,744
9,116
Accepted
Accepted
61.02
N = int(eval(input())) sp = [list(input().split()) for i in range(N)] for i in range(N): sp[i].append(i+1) sorted_data = sorted(sp, key=lambda x:(x[0], -int(x[1]))) for i in range(N): print((sorted_data[i][2]))
N = int(eval(input())) D = [list(map(str,input().split())) for _ in range(N)] for i in range(N): D[i].append(i+1) sorted_d = sorted(D, key = lambda x: (x[0], -int(x[1]))) for i in range(N): print((sorted_d[i][2]))
7
7
212
215
N = int(eval(input())) sp = [list(input().split()) for i in range(N)] for i in range(N): sp[i].append(i + 1) sorted_data = sorted(sp, key=lambda x: (x[0], -int(x[1]))) for i in range(N): print((sorted_data[i][2]))
N = int(eval(input())) D = [list(map(str, input().split())) for _ in range(N)] for i in range(N): D[i].append(i + 1) sorted_d = sorted(D, key=lambda x: (x[0], -int(x[1]))) for i in range(N): print((sorted_d[i][2]))
false
0
[ "-sp = [list(input().split()) for i in range(N)]", "+D = [list(map(str, input().split())) for _ in range(N)]", "- sp[i].append(i + 1)", "-sorted_data = sorted(sp, key=lambda x: (x[0], -int(x[1])))", "+ D[i].append(i + 1)", "+sorted_d = sorted(D, key=lambda x: (x[0], -int(x[1])))", "- print((sorted_data[i][2]))", "+ print((sorted_d[i][2]))" ]
false
0.137173
0.053843
2.547627
[ "s761920153", "s421242181" ]
u150984829
p02271
python
s691527674
s677062504
1,050
20
5,656
5,652
Accepted
Accepted
98.1
n=int(eval(input())) A=list(map(int,input().split())) r=set() def f(s,k): if k>=0: global r r.add(s) f(s+A[k-1],k-1) f(s,k-1) f(0,n) eval(input()) for e in map(int,input().split()):print((['no','yes'][e in r]))
eval(input()) s = {0} for a in map(int,input().split()): for b in list(s): s.add(a+b) eval(input()) for e in map(int,input().split()): print(('yes' if e in s else 'no'))
12
8
244
179
n = int(eval(input())) A = list(map(int, input().split())) r = set() def f(s, k): if k >= 0: global r r.add(s) f(s + A[k - 1], k - 1) f(s, k - 1) f(0, n) eval(input()) for e in map(int, input().split()): print((["no", "yes"][e in r]))
eval(input()) s = {0} for a in map(int, input().split()): for b in list(s): s.add(a + b) eval(input()) for e in map(int, input().split()): print(("yes" if e in s else "no"))
false
33.333333
[ "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "-r = set()", "-", "-", "-def f(s, k):", "- if k >= 0:", "- global r", "- r.add(s)", "- f(s + A[k - 1], k - 1)", "- f(s, k - 1)", "-", "-", "-f(0, n)", "+eval(input())", "+s = {0}", "+for a in map(int, input().split()):", "+ for b in list(s):", "+ s.add(a + b)", "- print(([\"no\", \"yes\"][e in r]))", "+ print((\"yes\" if e in s else \"no\"))" ]
false
0.119752
0.04553
2.630184
[ "s691527674", "s677062504" ]
u691018832
p02845
python
s031688306
s623700318
136
106
13,876
12,408
Accepted
Accepted
22.06
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) rbg = [-1, -1, -1] ans = 1 mod = 10 ** 9 + 7 for A in a: ans *= rbg.count(A - 1) ans %= mod for i in range(3): if rbg[i] == A - 1: rbg[i] = A break print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, *a = list(map(int, read().split())) ans = 1 mod = 10 ** 9 + 7 memo = [0, 0, 0] for check in a: if check in memo: ans *= memo.count(check) ans %= mod memo[memo.index(check)] += 1 else: print((0)) exit() print(ans)
18
19
314
422
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) rbg = [-1, -1, -1] ans = 1 mod = 10**9 + 7 for A in a: ans *= rbg.count(A - 1) ans %= mod for i in range(3): if rbg[i] == A - 1: rbg[i] = A break print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, *a = list(map(int, read().split())) ans = 1 mod = 10**9 + 7 memo = [0, 0, 0] for check in a: if check in memo: ans *= memo.count(check) ans %= mod memo[memo.index(check)] += 1 else: print((0)) exit() print(ans)
false
5.263158
[ "-input = sys.stdin.readline", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-rbg = [-1, -1, -1]", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+sys.setrecursionlimit(10**7)", "+n, *a = list(map(int, read().split()))", "-for A in a:", "- ans *= rbg.count(A - 1)", "- ans %= mod", "- for i in range(3):", "- if rbg[i] == A - 1:", "- rbg[i] = A", "- break", "+memo = [0, 0, 0]", "+for check in a:", "+ if check in memo:", "+ ans *= memo.count(check)", "+ ans %= mod", "+ memo[memo.index(check)] += 1", "+ else:", "+ print((0))", "+ exit()" ]
false
0.11454
0.047418
2.415529
[ "s031688306", "s623700318" ]
u705621008
p03147
python
s847916349
s312669482
20
18
3,064
3,060
Accepted
Accepted
10
s = int(eval(input())) a = list(map(int, input().split())) incFlg = True #登る場合はTure, 降る場合はFalse before_height = 0 sum = 0 for i in range(len(a)-1): #降る場合 if a[i] > a[i+1]: #その前が登り if incFlg: sum += a[i] - before_height incFlg = False #その前が下り else: before_height = a[i] #登る場合 else: if not incFlg: before_height = a[i] incFlg = True if incFlg: sum += a[len(a)-1] - before_height print(sum)
s = int(eval(input())) a = list(map(int, input().split())) incFlg = True #登る場合はTure, 降る場合はFalse before_height = 0 sum = 0 for i in range(len(a)-1): #降る場合 if a[i] > a[i+1]: #その前が登り if incFlg: sum += a[i] - before_height incFlg = False #その前が下り # else: # # before_height = a[i] #登る場合 else: if not incFlg: before_height = a[i] incFlg = True if incFlg: sum += a[len(a)-1] - before_height print(sum)
27
27
530
536
s = int(eval(input())) a = list(map(int, input().split())) incFlg = True # 登る場合はTure, 降る場合はFalse before_height = 0 sum = 0 for i in range(len(a) - 1): # 降る場合 if a[i] > a[i + 1]: # その前が登り if incFlg: sum += a[i] - before_height incFlg = False # その前が下り else: before_height = a[i] # 登る場合 else: if not incFlg: before_height = a[i] incFlg = True if incFlg: sum += a[len(a) - 1] - before_height print(sum)
s = int(eval(input())) a = list(map(int, input().split())) incFlg = True # 登る場合はTure, 降る場合はFalse before_height = 0 sum = 0 for i in range(len(a) - 1): # 降る場合 if a[i] > a[i + 1]: # その前が登り if incFlg: sum += a[i] - before_height incFlg = False # その前が下り # else: # # before_height = a[i] # 登る場合 else: if not incFlg: before_height = a[i] incFlg = True if incFlg: sum += a[len(a) - 1] - before_height print(sum)
false
0
[ "- else:", "- before_height = a[i]", "+ # else:", "+ # # before_height = a[i]" ]
false
0.039426
0.03835
1.028054
[ "s847916349", "s312669482" ]
u434630332
p04029
python
s023264655
s150665520
24
22
9,076
9,100
Accepted
Accepted
8.33
n = int(eval(input())) answer = int((n + 1) * n / 2) print(answer)
n = int(eval(input())) print((int((n + 1) * n / 2)))
5
2
66
45
n = int(eval(input())) answer = int((n + 1) * n / 2) print(answer)
n = int(eval(input())) print((int((n + 1) * n / 2)))
false
60
[ "-answer = int((n + 1) * n / 2)", "-print(answer)", "+print((int((n + 1) * n / 2)))" ]
false
0.036436
0.042366
0.860024
[ "s023264655", "s150665520" ]
u246217175
p03575
python
s200049859
s747395186
257
209
46,572
42,992
Accepted
Accepted
18.68
from collections import Counter n , m = list(map(int, input().split())) err = 0 ans = 0 par = [0] * n rank = [0] * n #初期化 for i in range(n): par[i] = i rank[i] = 0 #判定(一番上野根を求める) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] #結合 def unite(x , y): rx = find(x) ry = find(y) if rx == ry: return if rank[rx] < rank[ry]: par[rx] = ry elif rank[rx] > rank[ry]: par[ry] = rx else: par[ry] = x rank[rx] += 1 a = [0] * m b = [0] * m for i in range(m): a[i] , b[i] = list(map(int, input().split())) ans = 0 for i in range(m): for v in range(n): par[v] = v rank[v] = 0 for j in range(m): if j == i: continue unite(a[j]-1 , b[j]-1) r = [find(k) for k in range(n)] if len(Counter(r)) != 1: ans += 1 print(ans)
from collections import Counter maxn = 100000 n , m = list(map(int, input().split())) par = [0] * n rank = [0] * n #初期化 for i in range(n): par[i] = i rank[i] = 0 #判定(一番上野根を求める) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] #結合 def unite(x , y): rx = find(x) ry = find(y) if rx == ry: return if rank[rx] < rank[ry]: par[rx] = ry elif rank[rx] > rank[ry]: par[ry] = rx else: par[ry] = x rank[rx] += 1 a = [0] * m b = [0] * m for i in range(m): a[i],b[i] = list(map(int,input().split())) a[i] -= 1 b[i] -= 1 ans = 0 for i in range(m): for j in range(n): par[j] = j rank[j] = 0 for j in range(m): if i == j: continue unite(a[j],b[j]) l = [find(k) for k in range(n)] fl = 1 for j in range(n-1): if l[j] != l[j+1]: fl = 0 if fl == 0: ans += 1 print(ans)
59
67
997
1,118
from collections import Counter n, m = list(map(int, input().split())) err = 0 ans = 0 par = [0] * n rank = [0] * n # 初期化 for i in range(n): par[i] = i rank[i] = 0 # 判定(一番上野根を求める) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] # 結合 def unite(x, y): rx = find(x) ry = find(y) if rx == ry: return if rank[rx] < rank[ry]: par[rx] = ry elif rank[rx] > rank[ry]: par[ry] = rx else: par[ry] = x rank[rx] += 1 a = [0] * m b = [0] * m for i in range(m): a[i], b[i] = list(map(int, input().split())) ans = 0 for i in range(m): for v in range(n): par[v] = v rank[v] = 0 for j in range(m): if j == i: continue unite(a[j] - 1, b[j] - 1) r = [find(k) for k in range(n)] if len(Counter(r)) != 1: ans += 1 print(ans)
from collections import Counter maxn = 100000 n, m = list(map(int, input().split())) par = [0] * n rank = [0] * n # 初期化 for i in range(n): par[i] = i rank[i] = 0 # 判定(一番上野根を求める) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] # 結合 def unite(x, y): rx = find(x) ry = find(y) if rx == ry: return if rank[rx] < rank[ry]: par[rx] = ry elif rank[rx] > rank[ry]: par[ry] = rx else: par[ry] = x rank[rx] += 1 a = [0] * m b = [0] * m for i in range(m): a[i], b[i] = list(map(int, input().split())) a[i] -= 1 b[i] -= 1 ans = 0 for i in range(m): for j in range(n): par[j] = j rank[j] = 0 for j in range(m): if i == j: continue unite(a[j], b[j]) l = [find(k) for k in range(n)] fl = 1 for j in range(n - 1): if l[j] != l[j + 1]: fl = 0 if fl == 0: ans += 1 print(ans)
false
11.940299
[ "+maxn = 100000", "-err = 0", "-ans = 0", "+ a[i] -= 1", "+ b[i] -= 1", "- for v in range(n):", "- par[v] = v", "- rank[v] = 0", "+ for j in range(n):", "+ par[j] = j", "+ rank[j] = 0", "- if j == i:", "+ if i == j:", "- unite(a[j] - 1, b[j] - 1)", "- r = [find(k) for k in range(n)]", "- if len(Counter(r)) != 1:", "+ unite(a[j], b[j])", "+ l = [find(k) for k in range(n)]", "+ fl = 1", "+ for j in range(n - 1):", "+ if l[j] != l[j + 1]:", "+ fl = 0", "+ if fl == 0:" ]
false
0.169137
0.206624
0.818572
[ "s200049859", "s747395186" ]
u678167152
p02714
python
s753341474
s512369032
775
160
74,996
74,176
Accepted
Accepted
79.35
N = int(eval(input())) S = eval(input()) R, G, B = [],[],[] for i,s in enumerate(S): if s=='R': R.append(i) elif s=='G': G.append(i) else: B.append(i) R.sort() G.sort() B.sort() from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort ans = len(R)*len(G)*len(B) if ans > 0: for r in R: for g in G: for p in [r*2-g,g*2-r,(r+g)/2]: if p<=B[-1] and p>=B[0]: ind = bisect_left(B,p) if p == B[ind]: ans -= 1 print(ans)
from collections import Counter def solve(): N = int(eval(input())) S = list(eval(input())) c = Counter(S) ans = c['R']*c['G']*c['B'] for i in range(N): for j in range(i+1,N): k = j*2-i if k>N-1: break if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]: ans -= 1 return ans print((solve()))
29
15
607
333
N = int(eval(input())) S = eval(input()) R, G, B = [], [], [] for i, s in enumerate(S): if s == "R": R.append(i) elif s == "G": G.append(i) else: B.append(i) R.sort() G.sort() B.sort() from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort ans = len(R) * len(G) * len(B) if ans > 0: for r in R: for g in G: for p in [r * 2 - g, g * 2 - r, (r + g) / 2]: if p <= B[-1] and p >= B[0]: ind = bisect_left(B, p) if p == B[ind]: ans -= 1 print(ans)
from collections import Counter def solve(): N = int(eval(input())) S = list(eval(input())) c = Counter(S) ans = c["R"] * c["G"] * c["B"] for i in range(N): for j in range(i + 1, N): k = j * 2 - i if k > N - 1: break if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]: ans -= 1 return ans print((solve()))
false
48.275862
[ "-N = int(eval(input()))", "-S = eval(input())", "-R, G, B = [], [], []", "-for i, s in enumerate(S):", "- if s == \"R\":", "- R.append(i)", "- elif s == \"G\":", "- G.append(i)", "- else:", "- B.append(i)", "-R.sort()", "-G.sort()", "-B.sort()", "-from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort", "+from collections import Counter", "-ans = len(R) * len(G) * len(B)", "-if ans > 0:", "- for r in R:", "- for g in G:", "- for p in [r * 2 - g, g * 2 - r, (r + g) / 2]:", "- if p <= B[-1] and p >= B[0]:", "- ind = bisect_left(B, p)", "- if p == B[ind]:", "- ans -= 1", "-print(ans)", "+", "+def solve():", "+ N = int(eval(input()))", "+ S = list(eval(input()))", "+ c = Counter(S)", "+ ans = c[\"R\"] * c[\"G\"] * c[\"B\"]", "+ for i in range(N):", "+ for j in range(i + 1, N):", "+ k = j * 2 - i", "+ if k > N - 1:", "+ break", "+ if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:", "+ ans -= 1", "+ return ans", "+", "+", "+print((solve()))" ]
false
0.088744
0.038907
2.280906
[ "s753341474", "s512369032" ]
u997641430
p02788
python
s261873022
s072244003
1,419
1,294
44,268
44,316
Accepted
Accepted
8.81
n, d, a = list(map(int, input().split())) XH = [] for i in range(n): x, h = list(map(int, input().split())) XH.append((x, h)) XH.sort() X = [x for x, h in XH] H = [h for x, h in XH] # n, d, a = 9, 2, 2 # X = [1, 3, 4, 6, 9, 10, 12, 13, 16] # H = [7, 6, 7, 5, 10, 3, 8, 9, 6] X.append(10**10) H.append(0) j = 0 c = 0 S = [0]*(n+1) for i in range(n): H[i] = max(0, H[i]-S[i]) c += -(-H[i]//a) while X[j] <= X[i] + 2*d: j += 1 S[i+1] += S[i] + -(-H[i]//a)*a S[j] -= -(-H[i]//a)*a # print(i) # print(H) # print(S) # print(H) # print(S) print(c)
n, d, a = list(map(int, input().split())) XH = [tuple(map(int, input().split())) for i in range(n)] XH.sort() X = [x for x, h in XH] H = [h for x, h in XH] X.append(10**10) H.append(0) j = 0 S = [0]*(n+1) ans = 0 for i in range(n): H[i] = max(0, H[i]-S[i]) c = -(-H[i]//a) while X[j] <= X[i] + 2*d: j += 1 S[i+1] += S[i] + a*c S[j] -= a*c ans += c print(ans)
29
19
605
403
n, d, a = list(map(int, input().split())) XH = [] for i in range(n): x, h = list(map(int, input().split())) XH.append((x, h)) XH.sort() X = [x for x, h in XH] H = [h for x, h in XH] # n, d, a = 9, 2, 2 # X = [1, 3, 4, 6, 9, 10, 12, 13, 16] # H = [7, 6, 7, 5, 10, 3, 8, 9, 6] X.append(10**10) H.append(0) j = 0 c = 0 S = [0] * (n + 1) for i in range(n): H[i] = max(0, H[i] - S[i]) c += -(-H[i] // a) while X[j] <= X[i] + 2 * d: j += 1 S[i + 1] += S[i] + -(-H[i] // a) * a S[j] -= -(-H[i] // a) * a # print(i) # print(H) # print(S) # print(H) # print(S) print(c)
n, d, a = list(map(int, input().split())) XH = [tuple(map(int, input().split())) for i in range(n)] XH.sort() X = [x for x, h in XH] H = [h for x, h in XH] X.append(10**10) H.append(0) j = 0 S = [0] * (n + 1) ans = 0 for i in range(n): H[i] = max(0, H[i] - S[i]) c = -(-H[i] // a) while X[j] <= X[i] + 2 * d: j += 1 S[i + 1] += S[i] + a * c S[j] -= a * c ans += c print(ans)
false
34.482759
[ "-XH = []", "-for i in range(n):", "- x, h = list(map(int, input().split()))", "- XH.append((x, h))", "+XH = [tuple(map(int, input().split())) for i in range(n)]", "-# n, d, a = 9, 2, 2", "-# X = [1, 3, 4, 6, 9, 10, 12, 13, 16]", "-# H = [7, 6, 7, 5, 10, 3, 8, 9, 6]", "-c = 0", "+ans = 0", "- c += -(-H[i] // a)", "+ c = -(-H[i] // a)", "- S[i + 1] += S[i] + -(-H[i] // a) * a", "- S[j] -= -(-H[i] // a) * a", "- # print(i)", "- # print(H)", "- # print(S)", "-# print(H)", "-# print(S)", "-print(c)", "+ S[i + 1] += S[i] + a * c", "+ S[j] -= a * c", "+ ans += c", "+print(ans)" ]
false
0.038276
0.062548
0.611947
[ "s261873022", "s072244003" ]
u743164083
p03127
python
s761194140
s795378289
178
107
14,596
85,148
Accepted
Accepted
39.89
from functools import reduce def gcd(a, b): if b > a: a, b = b, a dp = [a, b] for i, v in enumerate(dp, start=2): dp.append(dp[i - 2] % dp[i - 1]) if dp[i] == 0: break return dp[i - 1] N = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
import math n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: ans = math.gcd(ans, i) print(ans)
17
9
332
133
from functools import reduce def gcd(a, b): if b > a: a, b = b, a dp = [a, b] for i, v in enumerate(dp, start=2): dp.append(dp[i - 2] % dp[i - 1]) if dp[i] == 0: break return dp[i - 1] N = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
import math n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: ans = math.gcd(ans, i) print(ans)
false
47.058824
[ "-from functools import reduce", "+import math", "-", "-def gcd(a, b):", "- if b > a:", "- a, b = b, a", "- dp = [a, b]", "- for i, v in enumerate(dp, start=2):", "- dp.append(dp[i - 2] % dp[i - 1])", "- if dp[i] == 0:", "- break", "- return dp[i - 1]", "-", "-", "-N = int(eval(input()))", "+n = int(eval(input()))", "-print((reduce(gcd, a)))", "+ans = 0", "+for i in a:", "+ ans = math.gcd(ans, i)", "+print(ans)" ]
false
0.008053
0.064441
0.12496
[ "s761194140", "s795378289" ]
u294922877
p02393
python
s758646874
s428604004
30
20
7,616
5,592
Accepted
Accepted
33.33
nums=sorted(list(map(int, input().split()))) print(('%d %d %d' % (nums[0],nums[1],nums[2])))
def execute(a, b, c): return sorted([a, b, c]) if __name__ == '__main__': numbers = list(map(int, input().split(' '))) print((*execute(*numbers)))
2
7
91
159
nums = sorted(list(map(int, input().split()))) print(("%d %d %d" % (nums[0], nums[1], nums[2])))
def execute(a, b, c): return sorted([a, b, c]) if __name__ == "__main__": numbers = list(map(int, input().split(" "))) print((*execute(*numbers)))
false
71.428571
[ "-nums = sorted(list(map(int, input().split())))", "-print((\"%d %d %d\" % (nums[0], nums[1], nums[2])))", "+def execute(a, b, c):", "+ return sorted([a, b, c])", "+", "+", "+if __name__ == \"__main__\":", "+ numbers = list(map(int, input().split(\" \")))", "+ print((*execute(*numbers)))" ]
false
0.063289
0.104677
0.604614
[ "s758646874", "s428604004" ]
u599547273
p04001
python
s534855626
s313072591
29
20
3,060
3,188
Accepted
Accepted
31.03
# abc 045 c from itertools import zip_longest s = eval(input()) sum_num = 0 for i in range(0, 2**(len(s)-1)): sings = bin(i)[2:].zfill(len(s)-1).replace("1", "+").replace("0", " ") formula = ("".join("".join(t) for t in zip_longest(s, sings, fillvalue=" "))).replace(" ", "") sum_num += eval(formula) print(sum_num)
s = eval(input()) s_len = len(s) sum_num = 0 for i in range(1<<(s_len-1), 1<<s_len): n, a = 0, 0 for j in range(s_len): if (i>>j)%2 == 0: continue n += int(s[a:j+1]) a = j+1 sum_num += n print(sum_num)
12
15
326
224
# abc 045 c from itertools import zip_longest s = eval(input()) sum_num = 0 for i in range(0, 2 ** (len(s) - 1)): sings = bin(i)[2:].zfill(len(s) - 1).replace("1", "+").replace("0", " ") formula = ( "".join("".join(t) for t in zip_longest(s, sings, fillvalue=" ")) ).replace(" ", "") sum_num += eval(formula) print(sum_num)
s = eval(input()) s_len = len(s) sum_num = 0 for i in range(1 << (s_len - 1), 1 << s_len): n, a = 0, 0 for j in range(s_len): if (i >> j) % 2 == 0: continue n += int(s[a : j + 1]) a = j + 1 sum_num += n print(sum_num)
false
20
[ "-# abc 045 c", "-from itertools import zip_longest", "-", "+s_len = len(s)", "-for i in range(0, 2 ** (len(s) - 1)):", "- sings = bin(i)[2:].zfill(len(s) - 1).replace(\"1\", \"+\").replace(\"0\", \" \")", "- formula = (", "- \"\".join(\"\".join(t) for t in zip_longest(s, sings, fillvalue=\" \"))", "- ).replace(\" \", \"\")", "- sum_num += eval(formula)", "+for i in range(1 << (s_len - 1), 1 << s_len):", "+ n, a = 0, 0", "+ for j in range(s_len):", "+ if (i >> j) % 2 == 0:", "+ continue", "+ n += int(s[a : j + 1])", "+ a = j + 1", "+ sum_num += n" ]
false
0.040436
0.039716
1.018129
[ "s534855626", "s313072591" ]
u729133443
p03287
python
s047640165
s882456493
408
107
16,100
14,476
Accepted
Accepted
73.77
import math def f(x):return math.factorial(x) def g(x):return f(x)//(f(x-2)*f(2))if x>1else 0 n,m=list(map(int,input().split())) b=0 c={} for a in input().split(): b+=int(a) c[b%m]=c.get(b%m,0)+1 print((sum([g(x) for x in list(c.values())])+c.get(0,0)))
n,m,*c=list(map(int,open(0).read().split())) d={0:1} r=s=0 for i in c:s+=i;x=d.get(s%m,0);r+=x;d[s%m]=x+1 print(r)
10
5
255
112
import math def f(x): return math.factorial(x) def g(x): return f(x) // (f(x - 2) * f(2)) if x > 1 else 0 n, m = list(map(int, input().split())) b = 0 c = {} for a in input().split(): b += int(a) c[b % m] = c.get(b % m, 0) + 1 print((sum([g(x) for x in list(c.values())]) + c.get(0, 0)))
n, m, *c = list(map(int, open(0).read().split())) d = {0: 1} r = s = 0 for i in c: s += i x = d.get(s % m, 0) r += x d[s % m] = x + 1 print(r)
false
50
[ "-import math", "-", "-", "-def f(x):", "- return math.factorial(x)", "-", "-", "-def g(x):", "- return f(x) // (f(x - 2) * f(2)) if x > 1 else 0", "-", "-", "-n, m = list(map(int, input().split()))", "-b = 0", "-c = {}", "-for a in input().split():", "- b += int(a)", "- c[b % m] = c.get(b % m, 0) + 1", "-print((sum([g(x) for x in list(c.values())]) + c.get(0, 0)))", "+n, m, *c = list(map(int, open(0).read().split()))", "+d = {0: 1}", "+r = s = 0", "+for i in c:", "+ s += i", "+ x = d.get(s % m, 0)", "+ r += x", "+ d[s % m] = x + 1", "+print(r)" ]
false
0.036585
0.035475
1.031278
[ "s047640165", "s882456493" ]
u699089116
p02659
python
s736832453
s264659037
92
63
71,104
61,540
Accepted
Accepted
31.52
from decimal import Decimal, ROUND_DOWN a, b = list(map(str, input().split())) a = Decimal(a) b = Decimal(b) print(((a*b).quantize(Decimal("0"), rounding=ROUND_DOWN)))
a, b = list(map(str, input().split())) b = b.replace(".", "") print((int(a) * int(b) // 100))
6
3
165
87
from decimal import Decimal, ROUND_DOWN a, b = list(map(str, input().split())) a = Decimal(a) b = Decimal(b) print(((a * b).quantize(Decimal("0"), rounding=ROUND_DOWN)))
a, b = list(map(str, input().split())) b = b.replace(".", "") print((int(a) * int(b) // 100))
false
50
[ "-from decimal import Decimal, ROUND_DOWN", "-", "-a = Decimal(a)", "-b = Decimal(b)", "-print(((a * b).quantize(Decimal(\"0\"), rounding=ROUND_DOWN)))", "+b = b.replace(\".\", \"\")", "+print((int(a) * int(b) // 100))" ]
false
0.092774
0.038529
2.40792
[ "s736832453", "s264659037" ]
u628335443
p03127
python
s465784414
s973961787
106
92
20,076
20,056
Accepted
Accepted
13.21
n = int(eval(input())) a = list(map(int, input().split())) a.sort() i = 0 while i < n-1: x = a[i+1] % a[i] a[i+1] = a[i] a[i] = x if a[i] == 0: i += 1 print((a[i]))
n = int(eval(input())) a = list(map(int, input().split())) i = 0 while i < n-1: x = a[i+1] % a[i] a[i+1] = a[i] a[i] = x if a[i] == 0: i += 1 print((a[i]))
12
11
193
183
n = int(eval(input())) a = list(map(int, input().split())) a.sort() i = 0 while i < n - 1: x = a[i + 1] % a[i] a[i + 1] = a[i] a[i] = x if a[i] == 0: i += 1 print((a[i]))
n = int(eval(input())) a = list(map(int, input().split())) i = 0 while i < n - 1: x = a[i + 1] % a[i] a[i + 1] = a[i] a[i] = x if a[i] == 0: i += 1 print((a[i]))
false
8.333333
[ "-a.sort()" ]
false
0.033585
0.035548
0.944791
[ "s465784414", "s973961787" ]
u838644735
p02756
python
s808615231
s355158333
213
182
8,548
8,548
Accepted
Accepted
14.55
from collections import deque from sys import stdin def main(): S = deque([s for s in eval(input())]) Q = int(eval(input())) order = True for i in range(Q): query = stdin.readline().split() t = int(query[0]) if t == 1: order = not order else: f = int(query[1]) c = query[2] if not order: f = 3 - f # 2, 1 -> 1, 2 left = True if f == 1: S.appendleft(c) else: S.append(c) if not order: S.reverse() print((''.join(S))) if __name__ == '__main__': main()
from collections import deque from sys import stdin def main(): S = deque([s for s in eval(input())]) Q = int(eval(input())) order = True for i in range(Q): query = stdin.readline() t = int(query[0]) if t == 1: order = not order else: f = int(query[2]) c = query[4] if not order: f = 3 - f # 2, 1 -> 1, 2 left = True if f == 1: S.appendleft(c) else: S.append(c) if not order: S.reverse() print((''.join(S))) if __name__ == '__main__': main()
28
28
666
658
from collections import deque from sys import stdin def main(): S = deque([s for s in eval(input())]) Q = int(eval(input())) order = True for i in range(Q): query = stdin.readline().split() t = int(query[0]) if t == 1: order = not order else: f = int(query[1]) c = query[2] if not order: f = 3 - f # 2, 1 -> 1, 2 left = True if f == 1: S.appendleft(c) else: S.append(c) if not order: S.reverse() print(("".join(S))) if __name__ == "__main__": main()
from collections import deque from sys import stdin def main(): S = deque([s for s in eval(input())]) Q = int(eval(input())) order = True for i in range(Q): query = stdin.readline() t = int(query[0]) if t == 1: order = not order else: f = int(query[2]) c = query[4] if not order: f = 3 - f # 2, 1 -> 1, 2 left = True if f == 1: S.appendleft(c) else: S.append(c) if not order: S.reverse() print(("".join(S))) if __name__ == "__main__": main()
false
0
[ "- query = stdin.readline().split()", "+ query = stdin.readline()", "- f = int(query[1])", "- c = query[2]", "+ f = int(query[2])", "+ c = query[4]" ]
false
0.044705
0.094426
0.473438
[ "s808615231", "s355158333" ]
u247211039
p03086
python
s095869593
s497352260
34
28
9,032
9,068
Accepted
Accepted
17.65
S=eval(input()) T='ATCG' flag =0 ans =0 for i in range(len(S)): flag =0 for j in range(i,len(S)): if S[j] == 'A' or S[j] == 'G' or S[j] == 'T' or S[j] == 'C': flag +=1 ans = max(ans,flag) else: break print(ans)
S=eval(input()) A=['A','G','T','C'] ans=0 cnt=0 N=len(S) for i in range(N): cnt=0 for j in range(0,N-i): if S[i+j] in A: cnt+=1 else: break ans=max(ans,cnt) print(ans)
16
15
292
228
S = eval(input()) T = "ATCG" flag = 0 ans = 0 for i in range(len(S)): flag = 0 for j in range(i, len(S)): if S[j] == "A" or S[j] == "G" or S[j] == "T" or S[j] == "C": flag += 1 ans = max(ans, flag) else: break print(ans)
S = eval(input()) A = ["A", "G", "T", "C"] ans = 0 cnt = 0 N = len(S) for i in range(N): cnt = 0 for j in range(0, N - i): if S[i + j] in A: cnt += 1 else: break ans = max(ans, cnt) print(ans)
false
6.25
[ "-T = \"ATCG\"", "-flag = 0", "+A = [\"A\", \"G\", \"T\", \"C\"]", "-for i in range(len(S)):", "- flag = 0", "- for j in range(i, len(S)):", "- if S[j] == \"A\" or S[j] == \"G\" or S[j] == \"T\" or S[j] == \"C\":", "- flag += 1", "- ans = max(ans, flag)", "+cnt = 0", "+N = len(S)", "+for i in range(N):", "+ cnt = 0", "+ for j in range(0, N - i):", "+ if S[i + j] in A:", "+ cnt += 1", "+ ans = max(ans, cnt)" ]
false
0.036644
0.038096
0.961892
[ "s095869593", "s497352260" ]
u970197315
p03212
python
s201010816
s159425216
92
70
2,940
3,060
Accepted
Accepted
23.91
# ABC114 C - 755 N = int(eval(input())) def rep(s): if int(s) > N: return 0 ret = 1 if all(s.count(c) > 0 for c in '753') else 0 for c in '753': ret += rep(s + c) return ret print((rep('0')))
# C - 755 def dfs(n,s): if int(s)>n: return 0 res=0 if s.count('7')>0 and s.count('5')>0 and s.count('3')>0: res=1 for i in '753': res+=dfs(n,s+i) return res n=int(eval(input())) print((dfs(n,'0')))
12
15
230
255
# ABC114 C - 755 N = int(eval(input())) def rep(s): if int(s) > N: return 0 ret = 1 if all(s.count(c) > 0 for c in "753") else 0 for c in "753": ret += rep(s + c) return ret print((rep("0")))
# C - 755 def dfs(n, s): if int(s) > n: return 0 res = 0 if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0: res = 1 for i in "753": res += dfs(n, s + i) return res n = int(eval(input())) print((dfs(n, "0")))
false
20
[ "-# ABC114 C - 755", "-N = int(eval(input()))", "+# C - 755", "+def dfs(n, s):", "+ if int(s) > n:", "+ return 0", "+ res = 0", "+ if s.count(\"7\") > 0 and s.count(\"5\") > 0 and s.count(\"3\") > 0:", "+ res = 1", "+ for i in \"753\":", "+ res += dfs(n, s + i)", "+ return res", "-def rep(s):", "- if int(s) > N:", "- return 0", "- ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0", "- for c in \"753\":", "- ret += rep(s + c)", "- return ret", "-", "-", "-print((rep(\"0\")))", "+n = int(eval(input()))", "+print((dfs(n, \"0\")))" ]
false
0.138994
0.058364
2.381512
[ "s201010816", "s159425216" ]
u044964932
p02954
python
s999794125
s336241246
97
82
7,096
11,568
Accepted
Accepted
15.46
def main(): ss = list(eval(input())) n = len(ss) ans = [0]*n cnt = 0 for i, lr in enumerate(ss): if lr == "R": cnt += 1 continue else: even_num = cnt//2 odd_num = cnt - even_num ans[i] += even_num ans[i-1] += odd_num cnt = 0 for i in range(n-1, -1, -1): if ss[i] == "L": cnt += 1 continue else: even_num = cnt//2 odd_num = cnt - even_num ans[i] += even_num ans[i+1] += odd_num cnt = 0 print((*ans)) if __name__ == "__main__": main()
def main(): ss = list(eval(input())) n = len(ss) ans = [0] * n cnt = 0 for i in range(n): if ss[i] == "R": cnt += 1 else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i-1] += odd_num cnt = 0 cnt = 0 for i in range(n-1, -1, -1): if ss[i] == "L": cnt += 1 else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i+1] += odd_num cnt = 0 print((*ans)) if __name__ == "__main__": main()
31
29
690
657
def main(): ss = list(eval(input())) n = len(ss) ans = [0] * n cnt = 0 for i, lr in enumerate(ss): if lr == "R": cnt += 1 continue else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i - 1] += odd_num cnt = 0 for i in range(n - 1, -1, -1): if ss[i] == "L": cnt += 1 continue else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i + 1] += odd_num cnt = 0 print((*ans)) if __name__ == "__main__": main()
def main(): ss = list(eval(input())) n = len(ss) ans = [0] * n cnt = 0 for i in range(n): if ss[i] == "R": cnt += 1 else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i - 1] += odd_num cnt = 0 cnt = 0 for i in range(n - 1, -1, -1): if ss[i] == "L": cnt += 1 else: even_num = cnt // 2 odd_num = cnt - even_num ans[i] += even_num ans[i + 1] += odd_num cnt = 0 print((*ans)) if __name__ == "__main__": main()
false
6.451613
[ "- for i, lr in enumerate(ss):", "- if lr == \"R\":", "+ for i in range(n):", "+ if ss[i] == \"R\":", "- continue", "+ cnt = 0", "- continue" ]
false
0.036079
0.084838
0.425266
[ "s999794125", "s336241246" ]
u606045429
p02814
python
s520172681
s281008263
236
122
16,092
16,148
Accepted
Accepted
48.31
from fractions import gcd from functools import reduce N, M, *A = list(map(int, open(0).read().split())) Y = reduce(lambda a, b: a * b // gcd(a, b), A) print((M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0))
from fractions import gcd lcm = lambda a, b: a * b // gcd(a, b) N, M, *A = list(map(int, open(0).read().split())) Y = A[0] for a in A[1:]: Y = lcm(Y, a) if Y > 2 * M: print((0)) quit() print((M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0))
8
14
226
288
from fractions import gcd from functools import reduce N, M, *A = list(map(int, open(0).read().split())) Y = reduce(lambda a, b: a * b // gcd(a, b), A) print((M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0))
from fractions import gcd lcm = lambda a, b: a * b // gcd(a, b) N, M, *A = list(map(int, open(0).read().split())) Y = A[0] for a in A[1:]: Y = lcm(Y, a) if Y > 2 * M: print((0)) quit() print((M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0))
false
42.857143
[ "-from functools import reduce", "+lcm = lambda a, b: a * b // gcd(a, b)", "-Y = reduce(lambda a, b: a * b // gcd(a, b), A)", "+Y = A[0]", "+for a in A[1:]:", "+ Y = lcm(Y, a)", "+ if Y > 2 * M:", "+ print((0))", "+ quit()" ]
false
0.047949
0.048068
0.997534
[ "s520172681", "s281008263" ]
u150984829
p00096
python
s433879670
s207663890
30
20
5,636
5,636
Accepted
Accepted
33.33
import sys a=[0]*4001 for i in range(1999):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999) for e in sys.stdin:print((a[int(e)]))
import sys a=[0]*4001 for i in range(2001):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999) for e in sys.stdin:print((a[int(e)]))
4
4
138
138
import sys a = [0] * 4001 for i in range(1999): a[i] = a[4000 - i] = (i + 3) * (i + 2) * (i + 1) // 6 - a[i - 1001] * 4 * (i > 999) for e in sys.stdin: print((a[int(e)]))
import sys a = [0] * 4001 for i in range(2001): a[i] = a[4000 - i] = (i + 3) * (i + 2) * (i + 1) // 6 - a[i - 1001] * 4 * (i > 999) for e in sys.stdin: print((a[int(e)]))
false
0
[ "-for i in range(1999):", "+for i in range(2001):" ]
false
0.105735
0.051562
2.05064
[ "s433879670", "s207663890" ]
u644907318
p02862
python
s173020420
s606590702
831
250
223,920
91,152
Accepted
Accepted
69.92
p = 10**9+7 def pow(x,m): if m==0:return 1 if m%2==0: return (pow(x,m//2)**2)%p else: return (x*(pow(x,(m-1)//2)**2))%p X,Y = list(map(int,input().split())) K = X+Y A = [1 for _ in range(K)] for i in range(2,K): A[i] = (A[i-1]*i)%p B = [1 for _ in range(K)] B[K-1] = pow(A[K-1],p-2) for i in range(K-2,1,-1): B[i] = ((i+1)*B[i+1])%p if 2*Y-X>=0 and Y<=2*X and (X+Y)%3==0 and (2*Y-X)%3==0: k = (X+Y)//3 i = (2*Y-X)//3 cnt = (A[k]*B[i]*B[k-i])%p print(cnt) else: print((0))
def pow(x,m): if m==0: return 1 if m==1: return x if m%2==0: return (pow(x,m//2)**2)%p else: return (x*pow(x,m-1))%p p = 10**9+7 N = (2*10**6)//3 A = [1 for _ in range(N+1)] for i in range(2,N+1): A[i] = (A[i-1]*i)%p B = [1 for _ in range(N+1)] B[N] = pow(A[N],p-2) for i in range(N-1,1,-1): B[i] = ((i+1)*B[i+1])%p X,Y = list(map(int,input().split())) if (X+Y)%3==0 and (X+Y)//3<=X<=2*(X+Y)//3: n = (X+Y)//3 ans = (A[n]*B[X-n])%p ans = (ans*B[2*n-X])%p print(ans) else: print((0))
23
26
541
574
p = 10**9 + 7 def pow(x, m): if m == 0: return 1 if m % 2 == 0: return (pow(x, m // 2) ** 2) % p else: return (x * (pow(x, (m - 1) // 2) ** 2)) % p X, Y = list(map(int, input().split())) K = X + Y A = [1 for _ in range(K)] for i in range(2, K): A[i] = (A[i - 1] * i) % p B = [1 for _ in range(K)] B[K - 1] = pow(A[K - 1], p - 2) for i in range(K - 2, 1, -1): B[i] = ((i + 1) * B[i + 1]) % p if 2 * Y - X >= 0 and Y <= 2 * X and (X + Y) % 3 == 0 and (2 * Y - X) % 3 == 0: k = (X + Y) // 3 i = (2 * Y - X) // 3 cnt = (A[k] * B[i] * B[k - i]) % p print(cnt) else: print((0))
def pow(x, m): if m == 0: return 1 if m == 1: return x if m % 2 == 0: return (pow(x, m // 2) ** 2) % p else: return (x * pow(x, m - 1)) % p p = 10**9 + 7 N = (2 * 10**6) // 3 A = [1 for _ in range(N + 1)] for i in range(2, N + 1): A[i] = (A[i - 1] * i) % p B = [1 for _ in range(N + 1)] B[N] = pow(A[N], p - 2) for i in range(N - 1, 1, -1): B[i] = ((i + 1) * B[i + 1]) % p X, Y = list(map(int, input().split())) if (X + Y) % 3 == 0 and (X + Y) // 3 <= X <= 2 * (X + Y) // 3: n = (X + Y) // 3 ans = (A[n] * B[X - n]) % p ans = (ans * B[2 * n - X]) % p print(ans) else: print((0))
false
11.538462
[ "-p = 10**9 + 7", "-", "-", "+ if m == 1:", "+ return x", "- return (x * (pow(x, (m - 1) // 2) ** 2)) % p", "+ return (x * pow(x, m - 1)) % p", "+p = 10**9 + 7", "+N = (2 * 10**6) // 3", "+A = [1 for _ in range(N + 1)]", "+for i in range(2, N + 1):", "+ A[i] = (A[i - 1] * i) % p", "+B = [1 for _ in range(N + 1)]", "+B[N] = pow(A[N], p - 2)", "+for i in range(N - 1, 1, -1):", "+ B[i] = ((i + 1) * B[i + 1]) % p", "-K = X + Y", "-A = [1 for _ in range(K)]", "-for i in range(2, K):", "- A[i] = (A[i - 1] * i) % p", "-B = [1 for _ in range(K)]", "-B[K - 1] = pow(A[K - 1], p - 2)", "-for i in range(K - 2, 1, -1):", "- B[i] = ((i + 1) * B[i + 1]) % p", "-if 2 * Y - X >= 0 and Y <= 2 * X and (X + Y) % 3 == 0 and (2 * Y - X) % 3 == 0:", "- k = (X + Y) // 3", "- i = (2 * Y - X) // 3", "- cnt = (A[k] * B[i] * B[k - i]) % p", "- print(cnt)", "+if (X + Y) % 3 == 0 and (X + Y) // 3 <= X <= 2 * (X + Y) // 3:", "+ n = (X + Y) // 3", "+ ans = (A[n] * B[X - n]) % p", "+ ans = (ans * B[2 * n - X]) % p", "+ print(ans)" ]
false
0.730173
1.035194
0.705349
[ "s173020420", "s606590702" ]
u189023301
p03162
python
s905243897
s606852098
638
306
74,328
67,548
Accepted
Accepted
52.04
def main(): n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0] = a[0] for i in range(n - 1): dp[i + 1][0] = a[i + 1][0] + max(dp[i][1], dp[i][2]) dp[i + 1][1] = a[i + 1][1] + max(dp[i][2], dp[i][0]) dp[i + 1][2] = a[i + 1][2] + max(dp[i][0], dp[i][1]) print((max(dp[-1]))) if __name__ == '__main__': main()
import sys readline = sys.stdin.buffer.readline def main(): n = int(readline()) a = [list(map(int, readline().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0] = a[0] for i in range(n - 1): dp[i + 1][0] = a[i + 1][0] + max(dp[i][1], dp[i][2]) dp[i + 1][1] = a[i + 1][1] + max(dp[i][2], dp[i][0]) dp[i + 1][2] = a[i + 1][2] + max(dp[i][0], dp[i][1]) print((max(dp[-1]))) if __name__ == '__main__': main()
16
18
440
492
def main(): n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0] = a[0] for i in range(n - 1): dp[i + 1][0] = a[i + 1][0] + max(dp[i][1], dp[i][2]) dp[i + 1][1] = a[i + 1][1] + max(dp[i][2], dp[i][0]) dp[i + 1][2] = a[i + 1][2] + max(dp[i][0], dp[i][1]) print((max(dp[-1]))) if __name__ == "__main__": main()
import sys readline = sys.stdin.buffer.readline def main(): n = int(readline()) a = [list(map(int, readline().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0] = a[0] for i in range(n - 1): dp[i + 1][0] = a[i + 1][0] + max(dp[i][1], dp[i][2]) dp[i + 1][1] = a[i + 1][1] + max(dp[i][2], dp[i][0]) dp[i + 1][2] = a[i + 1][2] + max(dp[i][0], dp[i][1]) print((max(dp[-1]))) if __name__ == "__main__": main()
false
11.111111
[ "+import sys", "+", "+readline = sys.stdin.buffer.readline", "+", "+", "- n = int(eval(input()))", "- a = [list(map(int, input().split())) for _ in range(n)]", "+ n = int(readline())", "+ a = [list(map(int, readline().split())) for _ in range(n)]" ]
false
0.085838
0.087105
0.985452
[ "s905243897", "s606852098" ]
u968166680
p03088
python
s195971651
s699243894
47
39
9,972
9,920
Accepted
Accepted
17.02
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()) dp = [defaultdict(int) for _ in range(N)] for c in 'ACGT': dp[0][c + 'XX'] = 1 for i in range(1, N): for s, v in list(dp[i - 1].items()): for c in 'AT': dp[i][c + s[:2]] = (dp[i][c + s[:2]] + v) % MOD if not (s[1] == 'A' and s[0] == 'C'): dp[i]['G' + s[:2]] = (dp[i]['G' + s[:2]] + v) % MOD if ( not (s[1] == 'A' and s[0] == 'G') and not (s[1] == 'G' and s[0] == 'A') and not (s[2] == 'A' and s[1] == 'G') and not (s[2] == 'A' and s[0] == 'G') ): dp[i]['C' + s[:2]] = (dp[i]['C' + s[:2]] + v) % MOD ans = sum(dp[N - 1].values()) % MOD 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()) dp = [defaultdict(int) for _ in range(N)] for c in 'ACGT': dp[0][c + 'XX'] = 1 for i in range(1, N): for s, v in list(dp[i - 1].items()): t = s[:2] for c in 'AT': dp[i][c + t] = (dp[i][c + t] + v) % MOD if not (s[1] == 'A' and s[0] == 'C'): dp[i]['G' + t] = (dp[i]['G' + t] + v) % MOD if ( not (s[1] == 'A' and s[0] == 'G') and not (s[1] == 'G' and s[0] == 'A') and not (s[2] == 'A' and s[1] == 'G') and not (s[2] == 'A' and s[0] == 'G') ): dp[i]['C' + t] = (dp[i]['C' + t] + v) % MOD ans = sum(dp[N - 1].values()) % MOD print(ans) return if __name__ == '__main__': main()
40
41
1,062
1,061
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()) dp = [defaultdict(int) for _ in range(N)] for c in "ACGT": dp[0][c + "XX"] = 1 for i in range(1, N): for s, v in list(dp[i - 1].items()): for c in "AT": dp[i][c + s[:2]] = (dp[i][c + s[:2]] + v) % MOD if not (s[1] == "A" and s[0] == "C"): dp[i]["G" + s[:2]] = (dp[i]["G" + s[:2]] + v) % MOD if ( not (s[1] == "A" and s[0] == "G") and not (s[1] == "G" and s[0] == "A") and not (s[2] == "A" and s[1] == "G") and not (s[2] == "A" and s[0] == "G") ): dp[i]["C" + s[:2]] = (dp[i]["C" + s[:2]] + v) % MOD ans = sum(dp[N - 1].values()) % MOD 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()) dp = [defaultdict(int) for _ in range(N)] for c in "ACGT": dp[0][c + "XX"] = 1 for i in range(1, N): for s, v in list(dp[i - 1].items()): t = s[:2] for c in "AT": dp[i][c + t] = (dp[i][c + t] + v) % MOD if not (s[1] == "A" and s[0] == "C"): dp[i]["G" + t] = (dp[i]["G" + t] + v) % MOD if ( not (s[1] == "A" and s[0] == "G") and not (s[1] == "G" and s[0] == "A") and not (s[2] == "A" and s[1] == "G") and not (s[2] == "A" and s[0] == "G") ): dp[i]["C" + t] = (dp[i]["C" + t] + v) % MOD ans = sum(dp[N - 1].values()) % MOD print(ans) return if __name__ == "__main__": main()
false
2.439024
[ "+ t = s[:2]", "- dp[i][c + s[:2]] = (dp[i][c + s[:2]] + v) % MOD", "+ dp[i][c + t] = (dp[i][c + t] + v) % MOD", "- dp[i][\"G\" + s[:2]] = (dp[i][\"G\" + s[:2]] + v) % MOD", "+ dp[i][\"G\" + t] = (dp[i][\"G\" + t] + v) % MOD", "- dp[i][\"C\" + s[:2]] = (dp[i][\"C\" + s[:2]] + v) % MOD", "+ dp[i][\"C\" + t] = (dp[i][\"C\" + t] + v) % MOD" ]
false
0.046056
0.093155
0.494406
[ "s195971651", "s699243894" ]
u556594202
p02730
python
s187518718
s230968138
32
27
9,076
8,988
Accepted
Accepted
15.62
S = eval(input()) N = len(S) flag = [0,0,0] if S=="".join(reversed(list(S))): flag[0]=1 if S[:int((N-1)/2)]=="".join(reversed(list(S[:int((N-1)/2)]))): flag[1]=1 if S[int((N+3)/2)-1:]=="".join(reversed(list(S[int((N+3)/2)-1:]))): flag[2]=1 print(("Yes" if flag==[1,1,1] else "No"))
S = eval(input()) N = len(S) flag = True if S!="".join(reversed(list(S))): flag=False if S[:int((N-1)/2)]!="".join(reversed(list(S[:int((N-1)/2)]))): flag=False print(("Yes" if flag else "No"))
12
9
299
203
S = eval(input()) N = len(S) flag = [0, 0, 0] if S == "".join(reversed(list(S))): flag[0] = 1 if S[: int((N - 1) / 2)] == "".join(reversed(list(S[: int((N - 1) / 2)]))): flag[1] = 1 if S[int((N + 3) / 2) - 1 :] == "".join(reversed(list(S[int((N + 3) / 2) - 1 :]))): flag[2] = 1 print(("Yes" if flag == [1, 1, 1] else "No"))
S = eval(input()) N = len(S) flag = True if S != "".join(reversed(list(S))): flag = False if S[: int((N - 1) / 2)] != "".join(reversed(list(S[: int((N - 1) / 2)]))): flag = False print(("Yes" if flag else "No"))
false
25
[ "-flag = [0, 0, 0]", "-if S == \"\".join(reversed(list(S))):", "- flag[0] = 1", "-if S[: int((N - 1) / 2)] == \"\".join(reversed(list(S[: int((N - 1) / 2)]))):", "- flag[1] = 1", "-if S[int((N + 3) / 2) - 1 :] == \"\".join(reversed(list(S[int((N + 3) / 2) - 1 :]))):", "- flag[2] = 1", "-print((\"Yes\" if flag == [1, 1, 1] else \"No\"))", "+flag = True", "+if S != \"\".join(reversed(list(S))):", "+ flag = False", "+if S[: int((N - 1) / 2)] != \"\".join(reversed(list(S[: int((N - 1) / 2)]))):", "+ flag = False", "+print((\"Yes\" if flag else \"No\"))" ]
false
0.040699
0.084302
0.482775
[ "s187518718", "s230968138" ]
u353895424
p03137
python
s343378371
s419913140
1,562
115
13,968
13,968
Accepted
Accepted
92.64
n, m = list(map(int, input().split())) x = list(map(int, input().split())) if m <= n: print((0)) else: x.sort() diff = []#i番目とi+1番目の距離 for i in range(m-1): diff.append(x[i+1] - x[i]) diff.sort(reverse=True) # print(diff) if n > 1: for i in range(n-1): diff.pop(0) # print(diff) print((sum(diff)))
n, m = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() d = [] for i in range(m-1): d.append(x[i+1] - x[i]) d.sort(reverse=True) # print(d) print((sum(d[n-1:])))
17
12
367
199
n, m = list(map(int, input().split())) x = list(map(int, input().split())) if m <= n: print((0)) else: x.sort() diff = [] # i番目とi+1番目の距離 for i in range(m - 1): diff.append(x[i + 1] - x[i]) diff.sort(reverse=True) # print(diff) if n > 1: for i in range(n - 1): diff.pop(0) # print(diff) print((sum(diff)))
n, m = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() d = [] for i in range(m - 1): d.append(x[i + 1] - x[i]) d.sort(reverse=True) # print(d) print((sum(d[n - 1 :])))
false
29.411765
[ "-if m <= n:", "- print((0))", "-else:", "- x.sort()", "- diff = [] # i番目とi+1番目の距離", "- for i in range(m - 1):", "- diff.append(x[i + 1] - x[i])", "- diff.sort(reverse=True)", "- # print(diff)", "- if n > 1:", "- for i in range(n - 1):", "- diff.pop(0)", "- # print(diff)", "- print((sum(diff)))", "+x.sort()", "+d = []", "+for i in range(m - 1):", "+ d.append(x[i + 1] - x[i])", "+d.sort(reverse=True)", "+# print(d)", "+print((sum(d[n - 1 :])))" ]
false
0.034976
0.035865
0.975214
[ "s343378371", "s419913140" ]
u562935282
p03073
python
s669972200
s821748284
79
71
3,956
3,188
Accepted
Accepted
10.13
s = eval(input()) s = list(map(int, s)) ans = len(s) for i in range(2): cnt = 0 for j, ss in enumerate(s): if (j + i) % 2 != ss: cnt += 1 ans = min(ans, cnt) print(ans)
inf = float('inf') s = eval(input()) ans = inf for start_color in '01': cost = 0 for i, ss in enumerate(s): if i % 2 == 0: if ss != start_color: cost += 1 else: if ss == start_color: cost += 1 ans = min(ans, cost) print(ans)
9
16
191
320
s = eval(input()) s = list(map(int, s)) ans = len(s) for i in range(2): cnt = 0 for j, ss in enumerate(s): if (j + i) % 2 != ss: cnt += 1 ans = min(ans, cnt) print(ans)
inf = float("inf") s = eval(input()) ans = inf for start_color in "01": cost = 0 for i, ss in enumerate(s): if i % 2 == 0: if ss != start_color: cost += 1 else: if ss == start_color: cost += 1 ans = min(ans, cost) print(ans)
false
43.75
[ "+inf = float(\"inf\")", "-s = list(map(int, s))", "-ans = len(s)", "-for i in range(2):", "- cnt = 0", "- for j, ss in enumerate(s):", "- if (j + i) % 2 != ss:", "- cnt += 1", "- ans = min(ans, cnt)", "+ans = inf", "+for start_color in \"01\":", "+ cost = 0", "+ for i, ss in enumerate(s):", "+ if i % 2 == 0:", "+ if ss != start_color:", "+ cost += 1", "+ else:", "+ if ss == start_color:", "+ cost += 1", "+ ans = min(ans, cost)" ]
false
0.040849
0.033481
1.220071
[ "s669972200", "s821748284" ]
u667084803
p03634
python
s386928811
s288167938
1,570
767
49,928
69,296
Accepted
Accepted
51.15
def BFS(K,path,N): """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す""" from collections import deque dist=[-1]*N dist[K]=0 que=deque() que.append(K) while que: label=que.popleft() for i,c in path[label]: if dist[i]==-1: dist[i]=dist[label]+c que+=[i] return dist N=int(eval(input())) path=[ [] for i in range(N)] for i in range(N-1): a,b,c=list(map(int,input().split())) path[a-1]+=[[b-1,c]] path[b-1]+=[[a-1,c]] Q,K=list(map(int,input().split())) distance=BFS(K-1,path,N) for i in range(Q): x,y=list(map(int,input().split())) print((distance[x-1]+distance[y-1]))
from sys import stdin input = stdin.readline def BFS(K,path,N): """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す""" from collections import deque dist=[-1]*N dist[K]=0 que=deque() que.append(K) while que: label=que.popleft() for i,c in path[label]: if dist[i]==-1: dist[i]=dist[label]+c que+=[i] return dist N=int(eval(input())) path=[ [] for i in range(N)] for i in range(N-1): a,b,c=list(map(int,input().split())) path[a-1]+=[(b-1,c)] path[b-1]+=[(a-1,c)] Q,K=list(map(int,input().split())) xy=[list(map(int,input().split())) for i in range(Q)] distance=BFS(K-1,path,N) for i in range(Q): print((distance[xy[i][0]-1]+distance[xy[i][1]-1]))
26
28
626
710
def BFS(K, path, N): """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す""" from collections import deque dist = [-1] * N dist[K] = 0 que = deque() que.append(K) while que: label = que.popleft() for i, c in path[label]: if dist[i] == -1: dist[i] = dist[label] + c que += [i] return dist N = int(eval(input())) path = [[] for i in range(N)] for i in range(N - 1): a, b, c = list(map(int, input().split())) path[a - 1] += [[b - 1, c]] path[b - 1] += [[a - 1, c]] Q, K = list(map(int, input().split())) distance = BFS(K - 1, path, N) for i in range(Q): x, y = list(map(int, input().split())) print((distance[x - 1] + distance[y - 1]))
from sys import stdin input = stdin.readline def BFS(K, path, N): """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す""" from collections import deque dist = [-1] * N dist[K] = 0 que = deque() que.append(K) while que: label = que.popleft() for i, c in path[label]: if dist[i] == -1: dist[i] = dist[label] + c que += [i] return dist N = int(eval(input())) path = [[] for i in range(N)] for i in range(N - 1): a, b, c = list(map(int, input().split())) path[a - 1] += [(b - 1, c)] path[b - 1] += [(a - 1, c)] Q, K = list(map(int, input().split())) xy = [list(map(int, input().split())) for i in range(Q)] distance = BFS(K - 1, path, N) for i in range(Q): print((distance[xy[i][0] - 1] + distance[xy[i][1] - 1]))
false
7.142857
[ "+from sys import stdin", "+", "+input = stdin.readline", "+", "+", "- path[a - 1] += [[b - 1, c]]", "- path[b - 1] += [[a - 1, c]]", "+ path[a - 1] += [(b - 1, c)]", "+ path[b - 1] += [(a - 1, c)]", "+xy = [list(map(int, input().split())) for i in range(Q)]", "- x, y = list(map(int, input().split()))", "- print((distance[x - 1] + distance[y - 1]))", "+ print((distance[xy[i][0] - 1] + distance[xy[i][1] - 1]))" ]
false
0.03942
0.048628
0.810628
[ "s386928811", "s288167938" ]
u633068244
p01136
python
s876561421
s930807130
450
390
4,340
4,340
Accepted
Accepted
13.33
while 1: N = int(input()) if N == 0: break free = [list(map(int,input().split()))[1:] for i in range(N)] have = [set([i]) for i in range(N)] for day in range(1,31): gather = set([]) for i in range(N): if day in free[i]: gather |= have[i] if len(gather) == N: print(day) break for i in range(N): if day in free[i]: have[i] = gather.copy() else: print(-1)
while 1: N = int(input()) if N == 0: break free = [list(map(int,input().split()))[1:] for i in range(N)] have = [set([i]) for i in range(N)] for day in range(1,31): gather = set([]) come = [i for i in range(N) if day in free[i]] for i in come: gather |= have[i] if len(gather) == N: print(day) break for i in come: have[i] = gather.copy() else: print(-1)
19
18
525
500
while 1: N = int(input()) if N == 0: break free = [list(map(int, input().split()))[1:] for i in range(N)] have = [set([i]) for i in range(N)] for day in range(1, 31): gather = set([]) for i in range(N): if day in free[i]: gather |= have[i] if len(gather) == N: print(day) break for i in range(N): if day in free[i]: have[i] = gather.copy() else: print(-1)
while 1: N = int(input()) if N == 0: break free = [list(map(int, input().split()))[1:] for i in range(N)] have = [set([i]) for i in range(N)] for day in range(1, 31): gather = set([]) come = [i for i in range(N) if day in free[i]] for i in come: gather |= have[i] if len(gather) == N: print(day) break for i in come: have[i] = gather.copy() else: print(-1)
false
5.263158
[ "- for i in range(N):", "- if day in free[i]:", "- gather |= have[i]", "+ come = [i for i in range(N) if day in free[i]]", "+ for i in come:", "+ gather |= have[i]", "- for i in range(N):", "- if day in free[i]:", "- have[i] = gather.copy()", "+ for i in come:", "+ have[i] = gather.copy()" ]
false
0.034734
0.032228
1.07777
[ "s876561421", "s930807130" ]
u363421241
p02659
python
s800978101
s634865412
27
23
10,072
9,164
Accepted
Accepted
14.81
from decimal import Decimal a, b = input().split() a = Decimal(a) b = Decimal(b) print((int(a*b)))
a, b = input().split() a = int(a) b = int(b.replace('.','')) print((a*b//100))
5
4
100
79
from decimal import Decimal a, b = input().split() a = Decimal(a) b = Decimal(b) print((int(a * b)))
a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
false
20
[ "-from decimal import Decimal", "-", "-a = Decimal(a)", "-b = Decimal(b)", "-print((int(a * b)))", "+a = int(a)", "+b = int(b.replace(\".\", \"\"))", "+print((a * b // 100))" ]
false
0.051798
0.050187
1.032106
[ "s800978101", "s634865412" ]
u326775883
p02848
python
s831331450
s171455707
24
22
3,188
3,060
Accepted
Accepted
8.33
n = int(eval(input())) s = list(eval(input())) list = [] for i in range(len(s)): eng = ord(s[i]) + n if eng > 90: eng = eng - 26 eng2 = chr(eng) list += eng2 l = ''.join(list) print(l)
n = int(eval(input())) s = eval(input()) list = [] for i in range(len(s)): asc = ord(s[i])+n if asc > 90: asc = asc-26 list.append(chr(asc)) print((''.join(list)))
13
12
198
177
n = int(eval(input())) s = list(eval(input())) list = [] for i in range(len(s)): eng = ord(s[i]) + n if eng > 90: eng = eng - 26 eng2 = chr(eng) list += eng2 l = "".join(list) print(l)
n = int(eval(input())) s = eval(input()) list = [] for i in range(len(s)): asc = ord(s[i]) + n if asc > 90: asc = asc - 26 list.append(chr(asc)) print(("".join(list)))
false
7.692308
[ "-s = list(eval(input()))", "+s = eval(input())", "- eng = ord(s[i]) + n", "- if eng > 90:", "- eng = eng - 26", "- eng2 = chr(eng)", "- list += eng2", "-l = \"\".join(list)", "-print(l)", "+ asc = ord(s[i]) + n", "+ if asc > 90:", "+ asc = asc - 26", "+ list.append(chr(asc))", "+print((\"\".join(list)))" ]
false
0.038672
0.039544
0.977947
[ "s831331450", "s171455707" ]
u311379832
p03031
python
s149809992
s333678766
37
29
3,064
3,064
Accepted
Accepted
21.62
N, M = list(map(int, input().split())) ks = [list(map(int, input().split())) for _ in range(M)] p = list(map(int, input().split())) blst = [] cnt = 0 for i in range(2 ** N): slst = [] for j in range(N): if i >> j & 1: slst.append(j) blst.append(slst) for i in blst: ansF = False for j in range(M): ctmp1 = 0 for k in i: if ks[j][1:].count(k + 1) == 1: ctmp1 += 1 if ctmp1 % 2 == p[j]: ansF = True else: ansF = False break if ansF: cnt += 1 print(cnt)
def dfs(cnt): global ans if cnt == N: onF = True for i in range(M): tmp = 0 for j in range(ks[i][0]): if bit[ks[i][j + 1] - 1] == 1: tmp += 1 if tmp % 2 != p[i]: onF = False break if onF: ans += 1 return for i in range(2): bit[cnt] = i dfs(cnt + 1) N, M = list(map(int, input().split())) ks = [list(map(int, input().split())) for _ in range(M)] p = list(map(int, input().split())) bit = [0] * N ans = 0 dfs(0) print(ans)
28
28
621
620
N, M = list(map(int, input().split())) ks = [list(map(int, input().split())) for _ in range(M)] p = list(map(int, input().split())) blst = [] cnt = 0 for i in range(2**N): slst = [] for j in range(N): if i >> j & 1: slst.append(j) blst.append(slst) for i in blst: ansF = False for j in range(M): ctmp1 = 0 for k in i: if ks[j][1:].count(k + 1) == 1: ctmp1 += 1 if ctmp1 % 2 == p[j]: ansF = True else: ansF = False break if ansF: cnt += 1 print(cnt)
def dfs(cnt): global ans if cnt == N: onF = True for i in range(M): tmp = 0 for j in range(ks[i][0]): if bit[ks[i][j + 1] - 1] == 1: tmp += 1 if tmp % 2 != p[i]: onF = False break if onF: ans += 1 return for i in range(2): bit[cnt] = i dfs(cnt + 1) N, M = list(map(int, input().split())) ks = [list(map(int, input().split())) for _ in range(M)] p = list(map(int, input().split())) bit = [0] * N ans = 0 dfs(0) print(ans)
false
0
[ "+def dfs(cnt):", "+ global ans", "+ if cnt == N:", "+ onF = True", "+ for i in range(M):", "+ tmp = 0", "+ for j in range(ks[i][0]):", "+ if bit[ks[i][j + 1] - 1] == 1:", "+ tmp += 1", "+ if tmp % 2 != p[i]:", "+ onF = False", "+ break", "+ if onF:", "+ ans += 1", "+ return", "+ for i in range(2):", "+ bit[cnt] = i", "+ dfs(cnt + 1)", "+", "+", "-blst = []", "-cnt = 0", "-for i in range(2**N):", "- slst = []", "- for j in range(N):", "- if i >> j & 1:", "- slst.append(j)", "- blst.append(slst)", "-for i in blst:", "- ansF = False", "- for j in range(M):", "- ctmp1 = 0", "- for k in i:", "- if ks[j][1:].count(k + 1) == 1:", "- ctmp1 += 1", "- if ctmp1 % 2 == p[j]:", "- ansF = True", "- else:", "- ansF = False", "- break", "- if ansF:", "- cnt += 1", "-print(cnt)", "+bit = [0] * N", "+ans = 0", "+dfs(0)", "+print(ans)" ]
false
0.051465
0.008199
6.27676
[ "s149809992", "s333678766" ]
u532966492
p04001
python
s684961479
s151947972
38
21
3,572
3,188
Accepted
Accepted
44.74
from copy import deepcopy N=list(eval(input())) lenn=len(N)-1 cnt=0 for i in range(2**lenn): n=deepcopy(N) b=(("0"*lenn)+bin(i)[2:])[-lenn:] for i in range(lenn-1,-1,-1): if b[i]=="1": n.insert(i+1,"+") cnt+=eval("".join(n)) print(cnt)
a=eval(input()) l=len(a) ans=0 for i in range(2**(l-1)): i=("0"*l+bin(i)[2:])[-l+1:] cnt=a[0] for j in range(l-1): if i[j]=="0": cnt+=a[j+1] else: ans+=int(cnt) if j<l-1: cnt=a[j+1] else: cnt="" if cnt!="": ans+=int(cnt) print(ans)
12
19
276
364
from copy import deepcopy N = list(eval(input())) lenn = len(N) - 1 cnt = 0 for i in range(2**lenn): n = deepcopy(N) b = (("0" * lenn) + bin(i)[2:])[-lenn:] for i in range(lenn - 1, -1, -1): if b[i] == "1": n.insert(i + 1, "+") cnt += eval("".join(n)) print(cnt)
a = eval(input()) l = len(a) ans = 0 for i in range(2 ** (l - 1)): i = ("0" * l + bin(i)[2:])[-l + 1 :] cnt = a[0] for j in range(l - 1): if i[j] == "0": cnt += a[j + 1] else: ans += int(cnt) if j < l - 1: cnt = a[j + 1] else: cnt = "" if cnt != "": ans += int(cnt) print(ans)
false
36.842105
[ "-from copy import deepcopy", "-", "-N = list(eval(input()))", "-lenn = len(N) - 1", "-cnt = 0", "-for i in range(2**lenn):", "- n = deepcopy(N)", "- b = ((\"0\" * lenn) + bin(i)[2:])[-lenn:]", "- for i in range(lenn - 1, -1, -1):", "- if b[i] == \"1\":", "- n.insert(i + 1, \"+\")", "- cnt += eval(\"\".join(n))", "-print(cnt)", "+a = eval(input())", "+l = len(a)", "+ans = 0", "+for i in range(2 ** (l - 1)):", "+ i = (\"0\" * l + bin(i)[2:])[-l + 1 :]", "+ cnt = a[0]", "+ for j in range(l - 1):", "+ if i[j] == \"0\":", "+ cnt += a[j + 1]", "+ else:", "+ ans += int(cnt)", "+ if j < l - 1:", "+ cnt = a[j + 1]", "+ else:", "+ cnt = \"\"", "+ if cnt != \"\":", "+ ans += int(cnt)", "+print(ans)" ]
false
0.047075
0.040706
1.156459
[ "s684961479", "s151947972" ]
u353797797
p02901
python
s086089239
s908879134
1,245
858
3,188
3,572
Accepted
Accepted
31.08
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline def main(): inf = 10 ** 9 n, m = list(map(int, input().split())) dp = [inf] * (1 << n) dp[0] = 0 for _ in range(m): a, b = list(map(int, input().split())) cc = list(map(int, input().split())) mask = 0 for c in cc: mask += 1 << (c - 1) for i in range((1 << n) - 1, -1, -1): if dp[i] == inf: continue ni = i | mask if not 0 <= ni < (1 << n): continue dp[ni] = min(dp[ni], dp[i] + a) # print(dp) ans = dp[-1] if ans == inf: print((-1)) else: print(ans) main()
from itertools import permutations import sys sys.setrecursionlimit(10 ** 6) from bisect import * from collections import * from heapq import * def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): inf=10**9 n,m=MI() kk=[] aa=[] for _ in range(m): k=0 a,b=MI() aa.append(a) cc=LI1() for c in cc:k|=1<<c kk.append(k) dp=[inf]*(1<<n) dp[0]=0 for bit in range(1<<n): pre=dp[bit] if pre==inf:continue for a,k in zip(aa,kk): nb=bit|k dp[nb]=min(dp[nb],pre+a) ans=dp[-1] if ans==inf:print(-1) else:print(ans) main()
30
44
700
1,150
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline def main(): inf = 10**9 n, m = list(map(int, input().split())) dp = [inf] * (1 << n) dp[0] = 0 for _ in range(m): a, b = list(map(int, input().split())) cc = list(map(int, input().split())) mask = 0 for c in cc: mask += 1 << (c - 1) for i in range((1 << n) - 1, -1, -1): if dp[i] == inf: continue ni = i | mask if not 0 <= ni < (1 << n): continue dp[ni] = min(dp[ni], dp[i] + a) # print(dp) ans = dp[-1] if ans == inf: print((-1)) else: print(ans) main()
from itertools import permutations import sys sys.setrecursionlimit(10**6) from bisect import * from collections import * from heapq import * def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): inf = 10**9 n, m = MI() kk = [] aa = [] for _ in range(m): k = 0 a, b = MI() aa.append(a) cc = LI1() for c in cc: k |= 1 << c kk.append(k) dp = [inf] * (1 << n) dp[0] = 0 for bit in range(1 << n): pre = dp[bit] if pre == inf: continue for a, k in zip(aa, kk): nb = bit | k dp[nb] = min(dp[nb], pre + a) ans = dp[-1] if ans == inf: print(-1) else: print(ans) main()
false
31.818182
[ "+from itertools import permutations", "-input = sys.stdin.readline", "+from bisect import *", "+from collections import *", "+from heapq import *", "+", "+", "+def II():", "+ return int(sys.stdin.readline())", "+", "+", "+def MI():", "+ return map(int, sys.stdin.readline().split())", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+def SI():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def LLI(rows_number):", "+ return [LI() for _ in range(rows_number)]", "+", "+", "+int1 = lambda x: int(x) - 1", "+", "+", "+def MI1():", "+ return map(int1, sys.stdin.readline().split())", "+", "+", "+def LI1():", "+ return list(map(int1, sys.stdin.readline().split()))", "+", "+", "+p2D = lambda x: print(*x, sep=\"\\n\")", "+dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]", "- n, m = list(map(int, input().split()))", "+ n, m = MI()", "+ kk = []", "+ aa = []", "+ for _ in range(m):", "+ k = 0", "+ a, b = MI()", "+ aa.append(a)", "+ cc = LI1()", "+ for c in cc:", "+ k |= 1 << c", "+ kk.append(k)", "- for _ in range(m):", "- a, b = list(map(int, input().split()))", "- cc = list(map(int, input().split()))", "- mask = 0", "- for c in cc:", "- mask += 1 << (c - 1)", "- for i in range((1 << n) - 1, -1, -1):", "- if dp[i] == inf:", "- continue", "- ni = i | mask", "- if not 0 <= ni < (1 << n):", "- continue", "- dp[ni] = min(dp[ni], dp[i] + a)", "- # print(dp)", "+ for bit in range(1 << n):", "+ pre = dp[bit]", "+ if pre == inf:", "+ continue", "+ for a, k in zip(aa, kk):", "+ nb = bit | k", "+ dp[nb] = min(dp[nb], pre + a)", "- print((-1))", "+ print(-1)" ]
false
0.071019
0.036971
1.920953
[ "s086089239", "s908879134" ]
u628262476
p03611
python
s663476804
s726735441
320
83
22,396
11,476
Accepted
Accepted
74.06
import numpy as np;c=[0]*10**5;eval(input()) for i in map(int,input().split()): c[i]+=1 print((max([sum(c[i:i+3]) for i in range(10**5)])))
c=[0]*10**5;eval(input()) for i in map(int,input().split()): c[i]+=1 print((max([sum(c[i:i+3]) for i in range(10**5)])))
4
4
138
119
import numpy as np c = [0] * 10**5 eval(input()) for i in map(int, input().split()): c[i] += 1 print((max([sum(c[i : i + 3]) for i in range(10**5)])))
c = [0] * 10**5 eval(input()) for i in map(int, input().split()): c[i] += 1 print((max([sum(c[i : i + 3]) for i in range(10**5)])))
false
0
[ "-import numpy as np", "-" ]
false
0.283494
0.078855
3.595136
[ "s663476804", "s726735441" ]
u888092736
p03617
python
s191440843
s848969083
19
17
2,940
2,940
Accepted
Accepted
10.53
Q, H, S, D = list(map(int, input().split())) Q *= 4 H *= 2 N = int(eval(input())) print((N // 2 * min(Q * 2, H * 2, S * 2, D) + N % 2 * min(Q, H, S)))
Q, H, S, D = list(map(int, input().split())) N = int(eval(input())) Q *= 4 H *= 2 S = min(Q, H, S) print((N // 2 * min(2 * S, D) + N % 2 * S))
5
6
141
133
Q, H, S, D = list(map(int, input().split())) Q *= 4 H *= 2 N = int(eval(input())) print((N // 2 * min(Q * 2, H * 2, S * 2, D) + N % 2 * min(Q, H, S)))
Q, H, S, D = list(map(int, input().split())) N = int(eval(input())) Q *= 4 H *= 2 S = min(Q, H, S) print((N // 2 * min(2 * S, D) + N % 2 * S))
false
16.666667
[ "+N = int(eval(input()))", "-N = int(eval(input()))", "-print((N // 2 * min(Q * 2, H * 2, S * 2, D) + N % 2 * min(Q, H, S)))", "+S = min(Q, H, S)", "+print((N // 2 * min(2 * S, D) + N % 2 * S))" ]
false
0.037277
0.035879
1.038966
[ "s191440843", "s848969083" ]
u118211443
p02717
python
s216748998
s699517109
170
30
38,256
9,136
Accepted
Accepted
82.35
a, b, c = list(map(int, input().split())) print((c, a, b))
x, y, z = list(map(int, input().split())) print((z, x, y))
2
2
52
52
a, b, c = list(map(int, input().split())) print((c, a, b))
x, y, z = list(map(int, input().split())) print((z, x, y))
false
0
[ "-a, b, c = list(map(int, input().split()))", "-print((c, a, b))", "+x, y, z = list(map(int, input().split()))", "+print((z, x, y))" ]
false
0.036529
0.078316
0.466425
[ "s216748998", "s699517109" ]
u029000441
p02773
python
s157195803
s565145283
473
361
32,988
142,356
Accepted
Accepted
23.68
from sys import stdin n=int(stdin.readline().rstrip()) #print(n) dic={} for i in range(n): s=stdin.readline().rstrip() if s in list(dic.keys()): dic[s] +=1 else: dic[s]=1 #print(dic) #print(dic.keys()) sup=0 suc=[] for (i,number) in list(dic.items()): if number>sup: suc=[] sup=number suc.append(i) elif number==sup: suc.append(i) for k in (sorted(suc)): print(k)
# coding: utf-8 # hello worldと表示する #float型を許すな #numpyはpythonで import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 n=I() lis=[SI() for i in range(n)] c=Counter(lis) mx=0 for x in list(c.keys()): if c[x]>mx: mx=c[x] answers=[] for x in list(c.keys()): if c[x]==mx: answers.append(x) answers.sort() for x in answers: print(x)
23
39
445
1,075
from sys import stdin n = int(stdin.readline().rstrip()) # print(n) dic = {} for i in range(n): s = stdin.readline().rstrip() if s in list(dic.keys()): dic[s] += 1 else: dic[s] = 1 # print(dic) # print(dic.keys()) sup = 0 suc = [] for (i, number) in list(dic.items()): if number > sup: suc = [] sup = number suc.append(i) elif number == sup: suc.append(i) for k in sorted(suc): print(k)
# coding: utf-8 # hello worldと表示する # float型を許すな # numpyはpythonで import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi, factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 n = I() lis = [SI() for i in range(n)] c = Counter(lis) mx = 0 for x in list(c.keys()): if c[x] > mx: mx = c[x] answers = [] for x in list(c.keys()): if c[x] == mx: answers.append(x) answers.sort() for x in answers: print(x)
false
41.025641
[ "-from sys import stdin", "+# coding: utf-8", "+# hello worldと表示する", "+# float型を許すな", "+# numpyはpythonで", "+import sys", "-n = int(stdin.readline().rstrip())", "-# print(n)", "-dic = {}", "-for i in range(n):", "- s = stdin.readline().rstrip()", "- if s in list(dic.keys()):", "- dic[s] += 1", "- else:", "- dic[s] = 1", "-# print(dic)", "-# print(dic.keys())", "-sup = 0", "-suc = []", "-for (i, number) in list(dic.items()):", "- if number > sup:", "- suc = []", "- sup = number", "- suc.append(i)", "- elif number == sup:", "- suc.append(i)", "-for k in sorted(suc):", "- print(k)", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)", "+from collections import Counter, deque", "+from collections import defaultdict", "+from itertools import combinations, permutations, accumulate, groupby, product", "+from bisect import bisect_left, bisect_right", "+from heapq import heapify, heappop, heappush", "+from math import floor, ceil, pi, factorial", "+from operator import itemgetter", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI2():", "+ return [int(eval(input())) for i in range(n)]", "+", "+", "+def MXI():", "+ return [[LI()] for i in range(n)]", "+", "+", "+def SI():", "+ return input().rstrip()", "+", "+", "+def printns(x):", "+ print((\"\\n\".join(x)))", "+", "+", "+def printni(x):", "+ print((\"\\n\".join(list(map(str, x)))))", "+", "+", "+inf = 10**17", "+mod = 10**9 + 7", "+n = I()", "+lis = [SI() for i in range(n)]", "+c = Counter(lis)", "+mx = 0", "+for x in list(c.keys()):", "+ if c[x] > mx:", "+ mx = c[x]", "+answers = []", "+for x in list(c.keys()):", "+ if c[x] == mx:", "+ answers.append(x)", "+answers.sort()", "+for x in answers:", "+ print(x)" ]
false
0.04567
0.035502
1.286388
[ "s157195803", "s565145283" ]
u580920947
p03545
python
s160951500
s483963875
183
169
38,384
38,608
Accepted
Accepted
7.65
#/usr/bin/env python def main(): s = eval(input()) op_cnt = len(s) -1 for i in range(1<<op_cnt): op = ["-"] * op_cnt for j in range(op_cnt): if ((i >> j) & 1): op[op_cnt -1 -j] = "+" formula = "" for p_n, p_o in zip(s, op+[""]): formula += (p_n + p_o) if eval(formula) == 7: print((formula + "=7")) break if __name__ == '__main__': main()
#!/usr/bin/env python def main(): S = eval(input()) for i in range(1 << 3): operator = ["-", "-", "-"] for j in range(3): if ((i >> j) & 1): operator[j] = "+" formula = "" for s, op in zip(S, operator + [""]): formula += s + op if eval(formula) == 7: print((formula + "=7")) break if __name__ == '__main__': main()
20
19
472
445
# /usr/bin/env python def main(): s = eval(input()) op_cnt = len(s) - 1 for i in range(1 << op_cnt): op = ["-"] * op_cnt for j in range(op_cnt): if (i >> j) & 1: op[op_cnt - 1 - j] = "+" formula = "" for p_n, p_o in zip(s, op + [""]): formula += p_n + p_o if eval(formula) == 7: print((formula + "=7")) break if __name__ == "__main__": main()
#!/usr/bin/env python def main(): S = eval(input()) for i in range(1 << 3): operator = ["-", "-", "-"] for j in range(3): if (i >> j) & 1: operator[j] = "+" formula = "" for s, op in zip(S, operator + [""]): formula += s + op if eval(formula) == 7: print((formula + "=7")) break if __name__ == "__main__": main()
false
5
[ "-# /usr/bin/env python", "+#!/usr/bin/env python", "- s = eval(input())", "- op_cnt = len(s) - 1", "- for i in range(1 << op_cnt):", "- op = [\"-\"] * op_cnt", "- for j in range(op_cnt):", "+ S = eval(input())", "+ for i in range(1 << 3):", "+ operator = [\"-\", \"-\", \"-\"]", "+ for j in range(3):", "- op[op_cnt - 1 - j] = \"+\"", "+ operator[j] = \"+\"", "- for p_n, p_o in zip(s, op + [\"\"]):", "- formula += p_n + p_o", "+ for s, op in zip(S, operator + [\"\"]):", "+ formula += s + op" ]
false
0.039205
0.037245
1.052628
[ "s160951500", "s483963875" ]
u883048396
p03965
python
s099186073
s535839733
50
39
3,316
3,188
Accepted
Accepted
22
s = input().rstrip() iG = 0 iP = 0 iR = 0 for i in range(len(s)): if s[i] == "g": if iP < iG: iR += 1 iP += 1 else: iG += 1 elif s[i] == "p": if iP < iG: iP += 1 else: iR -= 1 iG += 1 print(iR)
#len(s)//2-s.count("p") iG = 0 iP = 0 iR = 0 for s in input().rstrip(): if s == "g": if iP < iG: iR += 1 iP += 1 else: iG += 1 else: if iP < iG: iP += 1 else: iR -= 1 iG += 1 print(iR)
20
20
327
318
s = input().rstrip() iG = 0 iP = 0 iR = 0 for i in range(len(s)): if s[i] == "g": if iP < iG: iR += 1 iP += 1 else: iG += 1 elif s[i] == "p": if iP < iG: iP += 1 else: iR -= 1 iG += 1 print(iR)
# len(s)//2-s.count("p") iG = 0 iP = 0 iR = 0 for s in input().rstrip(): if s == "g": if iP < iG: iR += 1 iP += 1 else: iG += 1 else: if iP < iG: iP += 1 else: iR -= 1 iG += 1 print(iR)
false
0
[ "-s = input().rstrip()", "+# len(s)//2-s.count(\"p\")", "-for i in range(len(s)):", "- if s[i] == \"g\":", "+for s in input().rstrip():", "+ if s == \"g\":", "- elif s[i] == \"p\":", "+ else:" ]
false
0.077687
0.043084
1.803156
[ "s099186073", "s535839733" ]
u191874006
p02684
python
s937883939
s782979441
121
107
90,104
90,056
Accepted
Accepted
11.57
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) 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,k = LI() a = LI() check = [-1]*n cntr = 0 tmp = 0 while 1: if check[tmp] != -1: break check[tmp] = cntr cntr += 1 tmp = a[tmp] - 1 c = check[tmp] if cntr > k: for i in range(n): if check[i] == k % cntr: ans = i+1 break else: for i in range(n): if check[i] - c == (k-c) % (cntr-c): ans = i+1 break 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(2147483647) 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, k = LI() a = LI() check_num = [-1] * n idx = 0 cnt = 1 while 1: idx = a[idx] - 1 if check_num[idx] != -1: s = check_num[idx] - 1 break check_num[idx] = cnt cnt += 1 cnt -= 1 if cnt >= k: for i in range(n): if check_num[i] == k: print((i+1)) break else: x = cnt - s y = (k - (s + 1)) % x for i in range(n): if check_num[i] == s + y + 1: print((i+1)) break
42
45
987
1,051
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) 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, k = LI() a = LI() check = [-1] * n cntr = 0 tmp = 0 while 1: if check[tmp] != -1: break check[tmp] = cntr cntr += 1 tmp = a[tmp] - 1 c = check[tmp] if cntr > k: for i in range(n): if check[i] == k % cntr: ans = i + 1 break else: for i in range(n): if check[i] - c == (k - c) % (cntr - c): ans = i + 1 break 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(2147483647) 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, k = LI() a = LI() check_num = [-1] * n idx = 0 cnt = 1 while 1: idx = a[idx] - 1 if check_num[idx] != -1: s = check_num[idx] - 1 break check_num[idx] = cnt cnt += 1 cnt -= 1 if cnt >= k: for i in range(n): if check_num[i] == k: print((i + 1)) break else: x = cnt - s y = (k - (s + 1)) % x for i in range(n): if check_num[i] == s + y + 1: print((i + 1)) break
false
6.666667
[ "-check = [-1] * n", "-cntr = 0", "-tmp = 0", "+check_num = [-1] * n", "+idx = 0", "+cnt = 1", "- if check[tmp] != -1:", "+ idx = a[idx] - 1", "+ if check_num[idx] != -1:", "+ s = check_num[idx] - 1", "- check[tmp] = cntr", "- cntr += 1", "- tmp = a[tmp] - 1", "-c = check[tmp]", "-if cntr > k:", "+ check_num[idx] = cnt", "+ cnt += 1", "+cnt -= 1", "+if cnt >= k:", "- if check[i] == k % cntr:", "- ans = i + 1", "+ if check_num[i] == k:", "+ print((i + 1))", "+ x = cnt - s", "+ y = (k - (s + 1)) % x", "- if check[i] - c == (k - c) % (cntr - c):", "- ans = i + 1", "+ if check_num[i] == s + y + 1:", "+ print((i + 1))", "-print(ans)" ]
false
0.037013
0.03658
1.011814
[ "s937883939", "s782979441" ]
u790710233
p03775
python
s994679721
s858256082
50
29
3,060
3,060
Accepted
Accepted
42
n = int(eval(input())) ans = 11 for i in range(1, int(-(-n**.5//1))+1): x, r = divmod(n, i) if r == 0: ans = min(ans, max([len(str(x)) for x in (i, x)])) print(ans)
n = int(eval(input())) INF = 10**18 ans = INF def F(a, b): return max(len(str(a)), len(str(b))) for i in range(1, int(n**.5)+1): if n % i == 0: x = F(i, n//i) if x < ans: ans = x print(ans)
7
15
185
237
n = int(eval(input())) ans = 11 for i in range(1, int(-(-(n**0.5) // 1)) + 1): x, r = divmod(n, i) if r == 0: ans = min(ans, max([len(str(x)) for x in (i, x)])) print(ans)
n = int(eval(input())) INF = 10**18 ans = INF def F(a, b): return max(len(str(a)), len(str(b))) for i in range(1, int(n**0.5) + 1): if n % i == 0: x = F(i, n // i) if x < ans: ans = x print(ans)
false
53.333333
[ "-ans = 11", "-for i in range(1, int(-(-(n**0.5) // 1)) + 1):", "- x, r = divmod(n, i)", "- if r == 0:", "- ans = min(ans, max([len(str(x)) for x in (i, x)]))", "+INF = 10**18", "+ans = INF", "+", "+", "+def F(a, b):", "+ return max(len(str(a)), len(str(b)))", "+", "+", "+for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ x = F(i, n // i)", "+ if x < ans:", "+ ans = x" ]
false
0.044229
0.050672
0.872844
[ "s994679721", "s858256082" ]
u408071652
p03212
python
s179743837
s497781194
168
48
70,436
13,492
Accepted
Accepted
71.43
import sys import math import itertools # \n def input(): return sys.stdin.readline().rstrip() def main(): N = int(eval(input())) A = int(math.log10(N)) flag=0 count =0 for a in range(3,A+2): for i in itertools.product([3,5,7],repeat=a): digit=0 if 3 in i and 5 in i and 7 in i: for s in range(a): digit+=10**(a-s-1)*i[s] if digit <=N: count+=1 else: break print(count) if __name__ == "__main__": main()
import sys import math import itertools # \n def input(): return sys.stdin.readline().rstrip() def main(): list = [[3, 5, 7]] N=int(eval(input())) for i in range(9): new = [] for j in list[-1]: a = 10 * j new.append(a + 3) new.append(a + 5) new.append(a + 7) list.append(new) pass count =0 for sub in list: for j in sub: s =str(j) if j>N: print(count) exit() if "3" in s and "7" in s and "5" in s: count +=1 if __name__ == "__main__": main()
34
40
614
682
import sys import math import itertools # \n def input(): return sys.stdin.readline().rstrip() def main(): N = int(eval(input())) A = int(math.log10(N)) flag = 0 count = 0 for a in range(3, A + 2): for i in itertools.product([3, 5, 7], repeat=a): digit = 0 if 3 in i and 5 in i and 7 in i: for s in range(a): digit += 10 ** (a - s - 1) * i[s] if digit <= N: count += 1 else: break print(count) if __name__ == "__main__": main()
import sys import math import itertools # \n def input(): return sys.stdin.readline().rstrip() def main(): list = [[3, 5, 7]] N = int(eval(input())) for i in range(9): new = [] for j in list[-1]: a = 10 * j new.append(a + 3) new.append(a + 5) new.append(a + 7) list.append(new) pass count = 0 for sub in list: for j in sub: s = str(j) if j > N: print(count) exit() if "3" in s and "7" in s and "5" in s: count += 1 if __name__ == "__main__": main()
false
15
[ "+ list = [[3, 5, 7]]", "- A = int(math.log10(N))", "- flag = 0", "+ for i in range(9):", "+ new = []", "+ for j in list[-1]:", "+ a = 10 * j", "+ new.append(a + 3)", "+ new.append(a + 5)", "+ new.append(a + 7)", "+ list.append(new)", "+ pass", "- for a in range(3, A + 2):", "- for i in itertools.product([3, 5, 7], repeat=a):", "- digit = 0", "- if 3 in i and 5 in i and 7 in i:", "- for s in range(a):", "- digit += 10 ** (a - s - 1) * i[s]", "- if digit <= N:", "- count += 1", "- else:", "- break", "- print(count)", "+ for sub in list:", "+ for j in sub:", "+ s = str(j)", "+ if j > N:", "+ print(count)", "+ exit()", "+ if \"3\" in s and \"7\" in s and \"5\" in s:", "+ count += 1" ]
false
0.087239
0.062439
1.397192
[ "s179743837", "s497781194" ]
u388927326
p03295
python
s601188143
s426170210
432
335
57,184
37,320
Accepted
Accepted
22.45
#!/usr/bin/env python3 import sys from collections import defaultdict def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = defaultdict(list) btoi = defaultdict(list) for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.append(aa - 1) b.append(bb - 1) atoi[aa - 1].append(i) btoi[bb - 1].append(i) achieved = [False for i in range(m)] res = 0 aptr = -1 # Already achieved for x in range(n - 1): tobreak = False for i in btoi[x + 1]: if not achieved[i]: tobreak = True if tobreak: res += 1 while aptr < x: aptr += 1 for j in atoi[aptr]: achieved[j] = True print(res) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = [[] for i in range(n)] btoi = [[] for i in range(n)] for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.append(aa - 1) b.append(bb - 1) atoi[aa - 1].append(i) btoi[bb - 1].append(i) achieved = [False for i in range(m)] res = 0 aptr = -1 # Already achieved for x in range(n - 1): tobreak = False for i in btoi[x + 1]: if not achieved[i]: tobreak = True if tobreak: res += 1 while aptr < x: aptr += 1 for j in atoi[aptr]: achieved[j] = True print(res) if __name__ == "__main__": main()
36
35
884
857
#!/usr/bin/env python3 import sys from collections import defaultdict def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = defaultdict(list) btoi = defaultdict(list) for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.append(aa - 1) b.append(bb - 1) atoi[aa - 1].append(i) btoi[bb - 1].append(i) achieved = [False for i in range(m)] res = 0 aptr = -1 # Already achieved for x in range(n - 1): tobreak = False for i in btoi[x + 1]: if not achieved[i]: tobreak = True if tobreak: res += 1 while aptr < x: aptr += 1 for j in atoi[aptr]: achieved[j] = True print(res) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = [[] for i in range(n)] btoi = [[] for i in range(n)] for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.append(aa - 1) b.append(bb - 1) atoi[aa - 1].append(i) btoi[bb - 1].append(i) achieved = [False for i in range(m)] res = 0 aptr = -1 # Already achieved for x in range(n - 1): tobreak = False for i in btoi[x + 1]: if not achieved[i]: tobreak = True if tobreak: res += 1 while aptr < x: aptr += 1 for j in atoi[aptr]: achieved[j] = True print(res) if __name__ == "__main__": main()
false
2.777778
[ "-from collections import defaultdict", "- atoi = defaultdict(list)", "- btoi = defaultdict(list)", "+ atoi = [[] for i in range(n)]", "+ btoi = [[] for i in range(n)]" ]
false
0.041593
0.041228
1.008851
[ "s601188143", "s426170210" ]
u350997995
p03145
python
s160082300
s149473626
19
17
3,060
2,940
Accepted
Accepted
10.53
a = list(map(int,input().split())) a.sort() print((int(a[0]*a[1]/2)))
l = list(map(int,input().split())) l.sort() print((int(l[0]*l[1]/2)))
3
3
69
69
a = list(map(int, input().split())) a.sort() print((int(a[0] * a[1] / 2)))
l = list(map(int, input().split())) l.sort() print((int(l[0] * l[1] / 2)))
false
0
[ "-a = list(map(int, input().split()))", "-a.sort()", "-print((int(a[0] * a[1] / 2)))", "+l = list(map(int, input().split()))", "+l.sort()", "+print((int(l[0] * l[1] / 2)))" ]
false
0.11156
0.104503
1.06753
[ "s160082300", "s149473626" ]
u687574784
p02629
python
s518189613
s040320914
43
38
9,964
9,992
Accepted
Accepted
11.63
n = int(eval(input())) #26進数 dim = [] while n>0: q,r = divmod(n-1, 26) dim.append(r) n=q import string dic = {i:l for i,l in enumerate(string.ascii_lowercase)} print((''.join([dic[d] for d in reversed(dim)])))
import string n = int(eval(input())) #26進数 ans = [] while n>0: q,r = divmod(n-1, 26) ans.append(r) n=q print((''.join([string.ascii_lowercase[bit] for bit in reversed(ans)])))
14
11
234
192
n = int(eval(input())) # 26進数 dim = [] while n > 0: q, r = divmod(n - 1, 26) dim.append(r) n = q import string dic = {i: l for i, l in enumerate(string.ascii_lowercase)} print(("".join([dic[d] for d in reversed(dim)])))
import string n = int(eval(input())) # 26進数 ans = [] while n > 0: q, r = divmod(n - 1, 26) ans.append(r) n = q print(("".join([string.ascii_lowercase[bit] for bit in reversed(ans)])))
false
21.428571
[ "+import string", "+", "-dim = []", "+ans = []", "- dim.append(r)", "+ ans.append(r)", "-import string", "-", "-dic = {i: l for i, l in enumerate(string.ascii_lowercase)}", "-print((\"\".join([dic[d] for d in reversed(dim)])))", "+print((\"\".join([string.ascii_lowercase[bit] for bit in reversed(ans)])))" ]
false
0.044468
0.05991
0.742241
[ "s518189613", "s040320914" ]
u400765446
p02257
python
s626415655
s770768538
210
60
5,676
6,312
Accepted
Accepted
71.43
def main(): n = int(eval(input())) count = 0 for _ in range(n): x = int(eval(input())) count += isprime(x) print(count) def isprime(x: int): if x == 2: return True if x % 2 == 0: return False for y in range(3, int(x**0.5)+1, 2): if x % y == 0: return False return True if __name__ == '__main__': main()
def main(): A = set() n_prime = 0 while True: try: x = int(eval(input())) A.add(x) except: break for x in A: n_prime += is_prime(x) print(n_prime) def is_prime(x): if x == 2: return 1 elif x % 2 == 0: return 0 else: return pow(2, x - 1, x) == 1 main()
21
25
402
396
def main(): n = int(eval(input())) count = 0 for _ in range(n): x = int(eval(input())) count += isprime(x) print(count) def isprime(x: int): if x == 2: return True if x % 2 == 0: return False for y in range(3, int(x**0.5) + 1, 2): if x % y == 0: return False return True if __name__ == "__main__": main()
def main(): A = set() n_prime = 0 while True: try: x = int(eval(input())) A.add(x) except: break for x in A: n_prime += is_prime(x) print(n_prime) def is_prime(x): if x == 2: return 1 elif x % 2 == 0: return 0 else: return pow(2, x - 1, x) == 1 main()
false
16
[ "- n = int(eval(input()))", "- count = 0", "- for _ in range(n):", "- x = int(eval(input()))", "- count += isprime(x)", "- print(count)", "+ A = set()", "+ n_prime = 0", "+ while True:", "+ try:", "+ x = int(eval(input()))", "+ A.add(x)", "+ except:", "+ break", "+ for x in A:", "+ n_prime += is_prime(x)", "+ print(n_prime)", "-def isprime(x: int):", "+def is_prime(x):", "- return True", "- if x % 2 == 0:", "- return False", "- for y in range(3, int(x**0.5) + 1, 2):", "- if x % y == 0:", "- return False", "- return True", "+ return 1", "+ elif x % 2 == 0:", "+ return 0", "+ else:", "+ return pow(2, x - 1, x) == 1", "-if __name__ == \"__main__\":", "- main()", "+main()" ]
false
0.044611
0.03666
1.216893
[ "s626415655", "s770768538" ]
u308684517
p03147
python
s116859392
s952140024
70
19
3,060
3,064
Accepted
Accepted
72.86
n = int(eval(input())) H = list(map(int, input().split())) T = [0 for _ in range(n)] c = 0 while True: f = False S = {0:1} for j in range(n): if H[j] > 0: S[1] = 1 H[j] -= 1 f = True elif len(S) > 1 and H[j] == 0: break if f: c += 1 if H == T: break print(c)
n = int(eval(input())) H = [0] + list(map(int, input().split())) + [0] T = [0 for _ in range(n+2)] c = 0 while True: s0 = 0; t1 = 0 for i in range(0, n+2): if H[i] > 0 and s0 == 1: H[i] -= 1 t1 = 1 elif H[i] == 0 and t1 == 1: c += 1 t1 = 0 elif H[i] == 0: s0 = 1 if H == T: break print(c)
17
17
311
322
n = int(eval(input())) H = list(map(int, input().split())) T = [0 for _ in range(n)] c = 0 while True: f = False S = {0: 1} for j in range(n): if H[j] > 0: S[1] = 1 H[j] -= 1 f = True elif len(S) > 1 and H[j] == 0: break if f: c += 1 if H == T: break print(c)
n = int(eval(input())) H = [0] + list(map(int, input().split())) + [0] T = [0 for _ in range(n + 2)] c = 0 while True: s0 = 0 t1 = 0 for i in range(0, n + 2): if H[i] > 0 and s0 == 1: H[i] -= 1 t1 = 1 elif H[i] == 0 and t1 == 1: c += 1 t1 = 0 elif H[i] == 0: s0 = 1 if H == T: break print(c)
false
0
[ "-H = list(map(int, input().split()))", "-T = [0 for _ in range(n)]", "+H = [0] + list(map(int, input().split())) + [0]", "+T = [0 for _ in range(n + 2)]", "- f = False", "- S = {0: 1}", "- for j in range(n):", "- if H[j] > 0:", "- S[1] = 1", "- H[j] -= 1", "- f = True", "- elif len(S) > 1 and H[j] == 0:", "- break", "- if f:", "- c += 1", "+ s0 = 0", "+ t1 = 0", "+ for i in range(0, n + 2):", "+ if H[i] > 0 and s0 == 1:", "+ H[i] -= 1", "+ t1 = 1", "+ elif H[i] == 0 and t1 == 1:", "+ c += 1", "+ t1 = 0", "+ elif H[i] == 0:", "+ s0 = 1" ]
false
0.03768
0.042138
0.894218
[ "s116859392", "s952140024" ]
u094999522
p02844
python
s858718808
s089529335
130
84
72,304
9,864
Accepted
Accepted
35.38
#!/usr/bin/env python3 n = int(eval(input())) s = eval(input()) c = 0 for i in range(10): i = str(i) for j in range(10): j = str(j) for k in range(10): k = str(k) if i in s: t = s[s.index(i)+1:] if j in t: u = t[t.index(j)+1:] if k in u: c+=1 print(c)
#!/usr/bin/env python3 n = int(eval(input())) s = eval(input()) s = [int(i) for i in s] c = 0 for i in range(10): for j in range(10): if i in s: t = s[s.index(i) + 1:] if j in t: c += len(set(t[t.index(j) + 1:])) print(c)
19
12
404
273
#!/usr/bin/env python3 n = int(eval(input())) s = eval(input()) c = 0 for i in range(10): i = str(i) for j in range(10): j = str(j) for k in range(10): k = str(k) if i in s: t = s[s.index(i) + 1 :] if j in t: u = t[t.index(j) + 1 :] if k in u: c += 1 print(c)
#!/usr/bin/env python3 n = int(eval(input())) s = eval(input()) s = [int(i) for i in s] c = 0 for i in range(10): for j in range(10): if i in s: t = s[s.index(i) + 1 :] if j in t: c += len(set(t[t.index(j) + 1 :])) print(c)
false
36.842105
[ "+s = [int(i) for i in s]", "- i = str(i)", "- j = str(j)", "- for k in range(10):", "- k = str(k)", "- if i in s:", "- t = s[s.index(i) + 1 :]", "- if j in t:", "- u = t[t.index(j) + 1 :]", "- if k in u:", "- c += 1", "+ if i in s:", "+ t = s[s.index(i) + 1 :]", "+ if j in t:", "+ c += len(set(t[t.index(j) + 1 :]))" ]
false
0.042607
0.042028
1.013769
[ "s858718808", "s089529335" ]
u729133443
p02665
python
s551813899
s443901482
104
94
20,160
20,128
Accepted
Accepted
9.62
*a,=list(map(int,[*open(0)][1].split())) c=[s:=0] for i in a[:0:-1]:c+=c[-1]+i, b=1 for a in a: if b<a: s=-1 break s+=b b=min(c.pop(),(b-a)*2) print(s)
*a,=list(map(int,[*open(s:=0)][1].split())) c=sum(a) b=1 for a in a: if b<a: s=-1 break s+=b c-=a b=min(c,(b-a)*2) print(s)
11
11
169
143
(*a,) = list(map(int, [*open(0)][1].split())) c = [s := 0] for i in a[:0:-1]: c += (c[-1] + i,) b = 1 for a in a: if b < a: s = -1 break s += b b = min(c.pop(), (b - a) * 2) print(s)
(*a,) = list(map(int, [*open(s := 0)][1].split())) c = sum(a) b = 1 for a in a: if b < a: s = -1 break s += b c -= a b = min(c, (b - a) * 2) print(s)
false
0
[ "-(*a,) = list(map(int, [*open(0)][1].split()))", "-c = [s := 0]", "-for i in a[:0:-1]:", "- c += (c[-1] + i,)", "+(*a,) = list(map(int, [*open(s := 0)][1].split()))", "+c = sum(a)", "- b = min(c.pop(), (b - a) * 2)", "+ c -= a", "+ b = min(c, (b - a) * 2)" ]
false
0.058758
0.173019
0.339606
[ "s551813899", "s443901482" ]
u380524497
p02862
python
s789232911
s938847824
1,327
121
124,232
3,064
Accepted
Accepted
90.88
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10 ** 9 + 7 # 出力の制限 N = 10 ** 6 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) x, y = list(map(int, input().split())) if (x+y) % 3 != 0: print((0)) exit() count = (x+y)//3 x -= count y -= count ans = cmb(x+y, min(x, y), mod) print(ans)
def nCr(n,r,mod = 10**9+7): r = min(n-r,r) numer = denom = 1 for i in range(1,r+1): numer = numer * (n+1-i) %mod denom = denom * i % mod return numer * pow(denom,mod-2,mod) %mod x, y = list(map(int, input().split())) if (x+y) % 3 != 0: print((0)) exit() count = (x+y)//3 x -= count y -= count if x<0 or y<0: print((0)) exit() ans = nCr(x+y, x) print(ans)
32
26
610
425
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 # 出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() count = (x + y) // 3 x -= count y -= count ans = cmb(x + y, min(x, y), mod) print(ans)
def nCr(n, r, mod=10**9 + 7): r = min(n - r, r) numer = denom = 1 for i in range(1, r + 1): numer = numer * (n + 1 - i) % mod denom = denom * i % mod return numer * pow(denom, mod - 2, mod) % mod x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() count = (x + y) // 3 x -= count y -= count if x < 0 or y < 0: print((0)) exit() ans = nCr(x + y, x) print(ans)
false
18.75
[ "-def cmb(n, r, mod):", "- if r < 0 or r > n:", "- return 0", "- r = min(r, n - r)", "- return g1[n] * g2[r] * g2[n - r] % mod", "+def nCr(n, r, mod=10**9 + 7):", "+ r = min(n - r, r)", "+ numer = denom = 1", "+ for i in range(1, r + 1):", "+ numer = numer * (n + 1 - i) % mod", "+ denom = denom * i % mod", "+ return numer * pow(denom, mod - 2, mod) % mod", "-mod = 10**9 + 7 # 出力の制限", "-N = 10**6", "-g1 = [1, 1] # 元テーブル", "-g2 = [1, 1] # 逆元テーブル", "-inverse = [0, 1] # 逆元テーブル計算用テーブル", "-for i in range(2, N + 1):", "- g1.append((g1[-1] * i) % mod)", "- inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "- g2.append((g2[-1] * inverse[-1]) % mod)", "-ans = cmb(x + y, min(x, y), mod)", "+if x < 0 or y < 0:", "+ print((0))", "+ exit()", "+ans = nCr(x + y, x)" ]
false
1.336053
0.049715
26.873998
[ "s789232911", "s938847824" ]
u844789719
p03569
python
s251416212
s894990129
315
65
3,316
3,316
Accepted
Accepted
79.37
s = eval(input()) ans = 0 while s: if s[0] == s[-1]: s = s[1:-1] elif s[0] == 'x': s = s[1:] ans += 1 elif s[-1] == 'x': s = s[:-1] ans += 1 else: ans = -1 break print(ans) # https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf
s = eval(input()) ans = 0 lb = 0 rb = len(s) - 1 while rb - lb > 0: if s[lb] == s[rb]: lb += 1 rb -= 1 elif s[lb] == 'x': lb += 1 ans += 1 elif s[rb] == 'x': rb -= 1 ans += 1 else: ans = -1 break print(ans) # https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf
16
19
318
363
s = eval(input()) ans = 0 while s: if s[0] == s[-1]: s = s[1:-1] elif s[0] == "x": s = s[1:] ans += 1 elif s[-1] == "x": s = s[:-1] ans += 1 else: ans = -1 break print(ans) # https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf
s = eval(input()) ans = 0 lb = 0 rb = len(s) - 1 while rb - lb > 0: if s[lb] == s[rb]: lb += 1 rb -= 1 elif s[lb] == "x": lb += 1 ans += 1 elif s[rb] == "x": rb -= 1 ans += 1 else: ans = -1 break print(ans) # https://img.atcoder.jp/code-festival-2017-qualc/editorial.pdf
false
15.789474
[ "-while s:", "- if s[0] == s[-1]:", "- s = s[1:-1]", "- elif s[0] == \"x\":", "- s = s[1:]", "+lb = 0", "+rb = len(s) - 1", "+while rb - lb > 0:", "+ if s[lb] == s[rb]:", "+ lb += 1", "+ rb -= 1", "+ elif s[lb] == \"x\":", "+ lb += 1", "- elif s[-1] == \"x\":", "- s = s[:-1]", "+ elif s[rb] == \"x\":", "+ rb -= 1" ]
false
0.037612
0.06611
0.568923
[ "s251416212", "s894990129" ]
u994988729
p03061
python
s234976323
s124657849
420
220
14,332
14,052
Accepted
Accepted
47.62
def gcd(x, y): x, y = max(x, y), min(x, y) if y == 0: return x return gcd(y, x % y) n = int(eval(input())) a = list(map(int, input().split())) l = [0]*n r = [0] * n for i in range(n): if i == 0: l[i] = a[i] continue l[i] = gcd(a[i], l[i-1]) for i in range(n - 1, -1, -1): if i == n - 1: r[i] = a[i] continue r[i] = gcd(a[i], r[i+1]) l = [0] + l[:-1] r = r[1:] + [0] ans = 0 for x, y in zip(l, r): ans = max(ans, gcd(x, y)) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) def gcd(x, y): if y == 0: return x return gcd(y, x % y) fromLeft = [0] fromRight = [0] for i, a in enumerate(A): if i == 0: fromLeft.append(a) continue fromLeft.append(gcd(a, fromLeft[-1])) for i, a in enumerate(A[::-1]): if i == 0: fromRight.append(a) continue fromRight.append(gcd(a, fromRight[-1])) fromRight = fromRight[::-1] fromLeft[0] = fromRight[1] fromRight[-1] = fromLeft[-2] ans = 1 for i in range(N): gl = fromLeft[i] gr = fromRight[i + 1] ans = max(ans, gcd(gl, gr)) print(ans)
31
35
536
662
def gcd(x, y): x, y = max(x, y), min(x, y) if y == 0: return x return gcd(y, x % y) n = int(eval(input())) a = list(map(int, input().split())) l = [0] * n r = [0] * n for i in range(n): if i == 0: l[i] = a[i] continue l[i] = gcd(a[i], l[i - 1]) for i in range(n - 1, -1, -1): if i == n - 1: r[i] = a[i] continue r[i] = gcd(a[i], r[i + 1]) l = [0] + l[:-1] r = r[1:] + [0] ans = 0 for x, y in zip(l, r): ans = max(ans, gcd(x, y)) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) def gcd(x, y): if y == 0: return x return gcd(y, x % y) fromLeft = [0] fromRight = [0] for i, a in enumerate(A): if i == 0: fromLeft.append(a) continue fromLeft.append(gcd(a, fromLeft[-1])) for i, a in enumerate(A[::-1]): if i == 0: fromRight.append(a) continue fromRight.append(gcd(a, fromRight[-1])) fromRight = fromRight[::-1] fromLeft[0] = fromRight[1] fromRight[-1] = fromLeft[-2] ans = 1 for i in range(N): gl = fromLeft[i] gr = fromRight[i + 1] ans = max(ans, gcd(gl, gr)) print(ans)
false
11.428571
[ "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+", "+", "- x, y = max(x, y), min(x, y)", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-l = [0] * n", "-r = [0] * n", "-for i in range(n):", "+fromLeft = [0]", "+fromRight = [0]", "+for i, a in enumerate(A):", "- l[i] = a[i]", "+ fromLeft.append(a)", "- l[i] = gcd(a[i], l[i - 1])", "-for i in range(n - 1, -1, -1):", "- if i == n - 1:", "- r[i] = a[i]", "+ fromLeft.append(gcd(a, fromLeft[-1]))", "+for i, a in enumerate(A[::-1]):", "+ if i == 0:", "+ fromRight.append(a)", "- r[i] = gcd(a[i], r[i + 1])", "-l = [0] + l[:-1]", "-r = r[1:] + [0]", "-ans = 0", "-for x, y in zip(l, r):", "- ans = max(ans, gcd(x, y))", "+ fromRight.append(gcd(a, fromRight[-1]))", "+fromRight = fromRight[::-1]", "+fromLeft[0] = fromRight[1]", "+fromRight[-1] = fromLeft[-2]", "+ans = 1", "+for i in range(N):", "+ gl = fromLeft[i]", "+ gr = fromRight[i + 1]", "+ ans = max(ans, gcd(gl, gr))" ]
false
0.072321
0.047734
1.515089
[ "s234976323", "s124657849" ]
u761320129
p02732
python
s011727820
s469930105
320
207
30,716
33,352
Accepted
Accepted
35.31
N = int(input()) A = list(map(int,input().split())) from collections import Counter ctr = Counter(A) al = 0 for v in ctr.values(): al += v*(v-1)//2 ans = [] for a in A: ans.append(al - ctr[a] + 1) print(*ans, sep='\n')
N = int(input()) A = list(map(int,input().split())) from collections import Counter ctr = Counter(A) full = sum(v*(v-1)//2 for v in ctr.values()) ans = [] for a in A: ans.append(full - ctr[a] + 1) print(*ans, sep='\n')
12
10
238
232
N = int(input()) A = list(map(int, input().split())) from collections import Counter ctr = Counter(A) al = 0 for v in ctr.values(): al += v * (v - 1) // 2 ans = [] for a in A: ans.append(al - ctr[a] + 1) print(*ans, sep="\n")
N = int(input()) A = list(map(int, input().split())) from collections import Counter ctr = Counter(A) full = sum(v * (v - 1) // 2 for v in ctr.values()) ans = [] for a in A: ans.append(full - ctr[a] + 1) print(*ans, sep="\n")
false
16.666667
[ "-al = 0", "-for v in ctr.values():", "- al += v * (v - 1) // 2", "+full = sum(v * (v - 1) // 2 for v in ctr.values())", "- ans.append(al - ctr[a] + 1)", "+ ans.append(full - ctr[a] + 1)" ]
false
0.036586
0.036954
0.990031
[ "s011727820", "s469930105" ]
u729133443
p03074
python
s532479642
s164738150
88
49
9,388
8,720
Accepted
Accepted
44.32
n,k=list(map(int,input().split())) *s,=eval(input()) g=[] t=1 for i in range(1,n): if s[i]==s[i-1]:t+=1 else:g.append(t);t=1 g.append(t) for i in range(1,len(g)):g[i]+=g[i-1] g=[0]+g+[g[-1]] print((max(g[i]-g[max(0,i-2*k-1)]for i in range(s[0]=='1',len(g),2))))
t,s=open(0) n,k=list(map(int,t.split())) l=2*k+1 x=[0]*(2+int(s[0]))+[i+1for i in range(n-1)if s[i]!=s[i+1]]+[n]*l print((max(x[i+l]-x[i]for i in range(0,len(x)-l,2))))
11
5
259
164
n, k = list(map(int, input().split())) (*s,) = eval(input()) g = [] t = 1 for i in range(1, n): if s[i] == s[i - 1]: t += 1 else: g.append(t) t = 1 g.append(t) for i in range(1, len(g)): g[i] += g[i - 1] g = [0] + g + [g[-1]] print((max(g[i] - g[max(0, i - 2 * k - 1)] for i in range(s[0] == "1", len(g), 2))))
t, s = open(0) n, k = list(map(int, t.split())) l = 2 * k + 1 x = [0] * (2 + int(s[0])) + [i + 1 for i in range(n - 1) if s[i] != s[i + 1]] + [n] * l print((max(x[i + l] - x[i] for i in range(0, len(x) - l, 2))))
false
54.545455
[ "-n, k = list(map(int, input().split()))", "-(*s,) = eval(input())", "-g = []", "-t = 1", "-for i in range(1, n):", "- if s[i] == s[i - 1]:", "- t += 1", "- else:", "- g.append(t)", "- t = 1", "-g.append(t)", "-for i in range(1, len(g)):", "- g[i] += g[i - 1]", "-g = [0] + g + [g[-1]]", "-print((max(g[i] - g[max(0, i - 2 * k - 1)] for i in range(s[0] == \"1\", len(g), 2))))", "+t, s = open(0)", "+n, k = list(map(int, t.split()))", "+l = 2 * k + 1", "+x = [0] * (2 + int(s[0])) + [i + 1 for i in range(n - 1) if s[i] != s[i + 1]] + [n] * l", "+print((max(x[i + l] - x[i] for i in range(0, len(x) - l, 2))))" ]
false
0.041018
0.040819
1.004895
[ "s532479642", "s164738150" ]
u625963200
p03503
python
s946338100
s958102747
278
75
3,064
3,064
Accepted
Accepted
73.02
N=int(eval(input())) F=[list(map(int,input().split())) for _ in range(N)] P=[list(map(int,input().split())) for _ in range(N)] ans=-10**18 for i in range(1,2**10): tmp=0 for j in range(N): cnt=0 for k in range(10): if i&(1<<k) and F[j][k]: cnt+=1 tmp+=P[j][cnt] ans=max(ans,tmp) print(ans)
import sys input=sys.stdin.readline N=int(eval(input())) F=[int(input().replace(' ',''),2) for _ in range(N)] P=[list(map(int,input().split())) for _ in range(N)] ans=-10**18 for i in range(1,2**10): cnt=0 for j in range(N): cnt+=P[j][bin(F[j] & i).count('1')] ans=max(ans,cnt) print(ans)
15
13
330
305
N = int(eval(input())) F = [list(map(int, input().split())) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] ans = -(10**18) for i in range(1, 2**10): tmp = 0 for j in range(N): cnt = 0 for k in range(10): if i & (1 << k) and F[j][k]: cnt += 1 tmp += P[j][cnt] ans = max(ans, tmp) print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) F = [int(input().replace(" ", ""), 2) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] ans = -(10**18) for i in range(1, 2**10): cnt = 0 for j in range(N): cnt += P[j][bin(F[j] & i).count("1")] ans = max(ans, cnt) print(ans)
false
13.333333
[ "+import sys", "+", "+input = sys.stdin.readline", "-F = [list(map(int, input().split())) for _ in range(N)]", "+F = [int(input().replace(\" \", \"\"), 2) for _ in range(N)]", "- tmp = 0", "+ cnt = 0", "- cnt = 0", "- for k in range(10):", "- if i & (1 << k) and F[j][k]:", "- cnt += 1", "- tmp += P[j][cnt]", "- ans = max(ans, tmp)", "+ cnt += P[j][bin(F[j] & i).count(\"1\")]", "+ ans = max(ans, cnt)" ]
false
0.043161
0.118496
0.364238
[ "s946338100", "s958102747" ]
u608088992
p02802
python
s873924229
s567496893
289
205
4,724
4,784
Accepted
Accepted
29.07
N, M = list(map(int, input().split())) pen = [0] * N AC = [False] * N for _ in range(M): p, s = input().split() if s == "AC": AC[int(p) - 1] = True else: if AC[int(p) - 1] == False : pen[int(p) - 1] += 1 ACcount = AC.count(True) Pcount = 0 for i in range(N): if AC[i]: Pcount += pen[i] print((ACcount, Pcount))
import sys def solve(): input = sys.stdin.readline N, M = list(map(int, input().split())) penalty = [0] * N accepted = [False for _ in range(N)] totalPenalty = 0 totalAccepted = 0 for _ in range(M): p, s = list(map(str, input().strip("\n").split())) if s == "WA" and not accepted[int(p) - 1]: penalty[int(p) - 1] += 1 else: if not accepted[int(p) - 1]: accepted[int(p) - 1] = True totalAccepted += 1 totalPenalty += penalty[int(p) - 1] print((totalAccepted, totalPenalty)) return 0 if __name__ == "__main__": solve()
13
23
338
652
N, M = list(map(int, input().split())) pen = [0] * N AC = [False] * N for _ in range(M): p, s = input().split() if s == "AC": AC[int(p) - 1] = True else: if AC[int(p) - 1] == False: pen[int(p) - 1] += 1 ACcount = AC.count(True) Pcount = 0 for i in range(N): if AC[i]: Pcount += pen[i] print((ACcount, Pcount))
import sys def solve(): input = sys.stdin.readline N, M = list(map(int, input().split())) penalty = [0] * N accepted = [False for _ in range(N)] totalPenalty = 0 totalAccepted = 0 for _ in range(M): p, s = list(map(str, input().strip("\n").split())) if s == "WA" and not accepted[int(p) - 1]: penalty[int(p) - 1] += 1 else: if not accepted[int(p) - 1]: accepted[int(p) - 1] = True totalAccepted += 1 totalPenalty += penalty[int(p) - 1] print((totalAccepted, totalPenalty)) return 0 if __name__ == "__main__": solve()
false
43.478261
[ "-N, M = list(map(int, input().split()))", "-pen = [0] * N", "-AC = [False] * N", "-for _ in range(M):", "- p, s = input().split()", "- if s == \"AC\":", "- AC[int(p) - 1] = True", "- else:", "- if AC[int(p) - 1] == False:", "- pen[int(p) - 1] += 1", "-ACcount = AC.count(True)", "-Pcount = 0", "-for i in range(N):", "- if AC[i]:", "- Pcount += pen[i]", "-print((ACcount, Pcount))", "+import sys", "+", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N, M = list(map(int, input().split()))", "+ penalty = [0] * N", "+ accepted = [False for _ in range(N)]", "+ totalPenalty = 0", "+ totalAccepted = 0", "+ for _ in range(M):", "+ p, s = list(map(str, input().strip(\"\\n\").split()))", "+ if s == \"WA\" and not accepted[int(p) - 1]:", "+ penalty[int(p) - 1] += 1", "+ else:", "+ if not accepted[int(p) - 1]:", "+ accepted[int(p) - 1] = True", "+ totalAccepted += 1", "+ totalPenalty += penalty[int(p) - 1]", "+ print((totalAccepted, totalPenalty))", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.0458
0.080018
0.572364
[ "s873924229", "s567496893" ]
u072717685
p03544
python
s156081685
s982513571
161
17
38,256
2,940
Accepted
Accepted
89.44
def return_Lucas(num1, num2): return num1 + num2 n = int(eval(input())) n1 = 2 n2 = 1 if n == 0: print(n1) elif n == 1: print(n2) else: for i in range(2, n+1): n1, n2 = n2, return_Lucas(n1,n2) if i == n: print(n2)
n = int(eval(input())) n1 = 2 n2 = 1 if n == 0: print(n1) elif n == 1: print(n2) else: for i in range(2, n+1): n1, n2 = n2, n1+n2 if i == n: print(n2)
17
14
256
188
def return_Lucas(num1, num2): return num1 + num2 n = int(eval(input())) n1 = 2 n2 = 1 if n == 0: print(n1) elif n == 1: print(n2) else: for i in range(2, n + 1): n1, n2 = n2, return_Lucas(n1, n2) if i == n: print(n2)
n = int(eval(input())) n1 = 2 n2 = 1 if n == 0: print(n1) elif n == 1: print(n2) else: for i in range(2, n + 1): n1, n2 = n2, n1 + n2 if i == n: print(n2)
false
17.647059
[ "-def return_Lucas(num1, num2):", "- return num1 + num2", "-", "-", "- n1, n2 = n2, return_Lucas(n1, n2)", "+ n1, n2 = n2, n1 + n2" ]
false
0.086409
0.035335
2.445421
[ "s156081685", "s982513571" ]
u186838327
p03163
python
s172266934
s362338523
286
263
92,056
148,312
Accepted
Accepted
8.04
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros((N+1, W+1), dtype='uint64') for i in range(N): w, v = list(map(int, input().split())) dp[i+1][:w] = dp[i][:w] dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v) print((np.max(dp[N, :])))
n, W = list(map(int, input().split())) WV = [] for i in range(n): w, v = list(map(int, input().split())) WV.append((w, v)) INF = 10**18 dp = [[-INF]*(W+1) for _ in range(n+1)] dp[0][0] = 0 for i in range(n): w, v = WV[i] for j in range(W+1): dp[i+1][j] = dp[i][j] for j in range(W+1): if j+w <= W: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v) print((max(dp[-1])))
12
18
266
417
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros((N + 1, W + 1), dtype="uint64") for i in range(N): w, v = list(map(int, input().split())) dp[i + 1][:w] = dp[i][:w] dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v) print((np.max(dp[N, :])))
n, W = list(map(int, input().split())) WV = [] for i in range(n): w, v = list(map(int, input().split())) WV.append((w, v)) INF = 10**18 dp = [[-INF] * (W + 1) for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): w, v = WV[i] for j in range(W + 1): dp[i + 1][j] = dp[i][j] for j in range(W + 1): if j + w <= W: dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v) print((max(dp[-1])))
false
33.333333
[ "-import numpy as np", "-", "-N, W = list(map(int, input().split()))", "-dp = np.zeros((N + 1, W + 1), dtype=\"uint64\")", "-for i in range(N):", "+n, W = list(map(int, input().split()))", "+WV = []", "+for i in range(n):", "- dp[i + 1][:w] = dp[i][:w]", "- dp[i + 1][w:] = np.maximum(dp[i][w:], dp[i][:-w] + v)", "-print((np.max(dp[N, :])))", "+ WV.append((w, v))", "+INF = 10**18", "+dp = [[-INF] * (W + 1) for _ in range(n + 1)]", "+dp[0][0] = 0", "+for i in range(n):", "+ w, v = WV[i]", "+ for j in range(W + 1):", "+ dp[i + 1][j] = dp[i][j]", "+ for j in range(W + 1):", "+ if j + w <= W:", "+ dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)", "+print((max(dp[-1])))" ]
false
0.464824
0.04579
10.15117
[ "s172266934", "s362338523" ]
u638456847
p02629
python
s411464493
s477300099
35
28
9,144
9,176
Accepted
Accepted
20
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) ans = '' while N: if N % 26 == 0: ans += "z" N -= 1 N //= 26 else: ans += chr((N % 26) -1 + 97) N //= 26 print((ans[::-1])) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) ans = '' while N: N -= 1 ans += chr((N % 26) + 97) N //= 26 print((ans[::-1])) if __name__ == "__main__": main()
22
18
409
307
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) ans = "" while N: if N % 26 == 0: ans += "z" N -= 1 N //= 26 else: ans += chr((N % 26) - 1 + 97) N //= 26 print((ans[::-1])) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) ans = "" while N: N -= 1 ans += chr((N % 26) + 97) N //= 26 print((ans[::-1])) if __name__ == "__main__": main()
false
18.181818
[ "- if N % 26 == 0:", "- ans += \"z\"", "- N -= 1", "- N //= 26", "- else:", "- ans += chr((N % 26) - 1 + 97)", "- N //= 26", "+ N -= 1", "+ ans += chr((N % 26) + 97)", "+ N //= 26" ]
false
0.041016
0.096684
0.424232
[ "s411464493", "s477300099" ]
u857759499
p02726
python
s753607557
s520442924
1,457
978
3,188
3,316
Accepted
Accepted
32.88
n,x,y = list(map(int,input().split())) a = [0 for _ in range(n-1)] for i in range(1,n): for j in range(i+1,n+1): l = min(j-i,abs(x-i)+1+abs(j-y)) a[l-1] += 1 print(("\n".join(map(str,a))))
def main(): n,x,y = list(map(int,input().split())) a = [0 for _ in range(n-1)] for i in range(1,n): for j in range(i+1,n+1): l = min(j-i,abs(x-i)+1+abs(j-y)) a[l-1] += 1 print(("\n".join(map(str,a)))) main()
7
10
196
233
n, x, y = list(map(int, input().split())) a = [0 for _ in range(n - 1)] for i in range(1, n): for j in range(i + 1, n + 1): l = min(j - i, abs(x - i) + 1 + abs(j - y)) a[l - 1] += 1 print(("\n".join(map(str, a))))
def main(): n, x, y = list(map(int, input().split())) a = [0 for _ in range(n - 1)] for i in range(1, n): for j in range(i + 1, n + 1): l = min(j - i, abs(x - i) + 1 + abs(j - y)) a[l - 1] += 1 print(("\n".join(map(str, a)))) main()
false
30
[ "-n, x, y = list(map(int, input().split()))", "-a = [0 for _ in range(n - 1)]", "-for i in range(1, n):", "- for j in range(i + 1, n + 1):", "- l = min(j - i, abs(x - i) + 1 + abs(j - y))", "- a[l - 1] += 1", "-print((\"\\n\".join(map(str, a))))", "+def main():", "+ n, x, y = list(map(int, input().split()))", "+ a = [0 for _ in range(n - 1)]", "+ for i in range(1, n):", "+ for j in range(i + 1, n + 1):", "+ l = min(j - i, abs(x - i) + 1 + abs(j - y))", "+ a[l - 1] += 1", "+ print((\"\\n\".join(map(str, a))))", "+", "+", "+main()" ]
false
0.04545
0.041946
1.083533
[ "s753607557", "s520442924" ]
u094191970
p02689
python
s398102377
s374372066
438
246
26,116
22,972
Accepted
Accepted
43.84
n,m=list(map(int,input().split())) h=list(map(int,input().split())) tree=[[0] for i in range(n)] for i in range(m): a,b=list(map(int,input().split())) tree[a-1].append(h[b-1]) tree[b-1].append(h[a-1]) cnt=0 for i in range(n): if h[i]>max(tree[i]): cnt+=1 print(cnt)
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) n,m=nii() h=lnii() tree=[[] for i in range(n)] for i in range(m): a,b=nii() a-=1 b-=1 tree[a].append(h[b]) tree[b].append(h[a]) ans=0 for i in range(n): if tree[i]: if h[i]>max(tree[i]): ans+=1 else: ans+=1 print(ans)
15
24
282
392
n, m = list(map(int, input().split())) h = list(map(int, input().split())) tree = [[0] for i in range(n)] for i in range(m): a, b = list(map(int, input().split())) tree[a - 1].append(h[b - 1]) tree[b - 1].append(h[a - 1]) cnt = 0 for i in range(n): if h[i] > max(tree[i]): cnt += 1 print(cnt)
from sys import stdin nii = lambda: list(map(int, stdin.readline().split())) lnii = lambda: list(map(int, stdin.readline().split())) n, m = nii() h = lnii() tree = [[] for i in range(n)] for i in range(m): a, b = nii() a -= 1 b -= 1 tree[a].append(h[b]) tree[b].append(h[a]) ans = 0 for i in range(n): if tree[i]: if h[i] > max(tree[i]): ans += 1 else: ans += 1 print(ans)
false
37.5
[ "-n, m = list(map(int, input().split()))", "-h = list(map(int, input().split()))", "-tree = [[0] for i in range(n)]", "+from sys import stdin", "+", "+nii = lambda: list(map(int, stdin.readline().split()))", "+lnii = lambda: list(map(int, stdin.readline().split()))", "+n, m = nii()", "+h = lnii()", "+tree = [[] for i in range(n)]", "- a, b = list(map(int, input().split()))", "- tree[a - 1].append(h[b - 1])", "- tree[b - 1].append(h[a - 1])", "-cnt = 0", "+ a, b = nii()", "+ a -= 1", "+ b -= 1", "+ tree[a].append(h[b])", "+ tree[b].append(h[a])", "+ans = 0", "- if h[i] > max(tree[i]):", "- cnt += 1", "-print(cnt)", "+ if tree[i]:", "+ if h[i] > max(tree[i]):", "+ ans += 1", "+ else:", "+ ans += 1", "+print(ans)" ]
false
0.075798
0.055905
1.355847
[ "s398102377", "s374372066" ]
u222668979
p03330
python
s959649494
s118689775
187
147
77,384
76,648
Accepted
Accepted
21.39
from collections import defaultdict from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [defaultdict(int) for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10 ** 9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[k][tgt] * cnt[k] for k in cnt) ans = min(ans, tmp) print(ans)
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10 ** 9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
20
19
597
556
from collections import defaultdict from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [defaultdict(int) for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10**9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[k][tgt] * cnt[k] for k in cnt) ans = min(ans, tmp) print(ans)
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10**9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
false
5
[ "-from collections import defaultdict", "-dcnt = [defaultdict(int) for _ in range(3)]", "+dcnt = [[0] * c for _ in range(3)]", "- tmp += sum(d[k][tgt] * cnt[k] for k in cnt)", "+ tmp += sum(d[i][tgt] * cnt[i] for i in range(c))" ]
false
0.035511
0.036621
0.969694
[ "s959649494", "s118689775" ]
u729133443
p03777
python
s102947415
s474202016
170
18
38,256
2,940
Accepted
Accepted
89.41
a,b=input().split();print(('DH'[a==b]))
print(('HD'[len(set(eval(input())))-2]))
1
1
37
32
a, b = input().split() print(("DH"[a == b]))
print(("HD"[len(set(eval(input()))) - 2]))
false
0
[ "-a, b = input().split()", "-print((\"DH\"[a == b]))", "+print((\"HD\"[len(set(eval(input()))) - 2]))" ]
false
0.040489
0.041851
0.967455
[ "s102947415", "s474202016" ]
u606045429
p02850
python
s749982356
s997186209
547
203
55,068
25,900
Accepted
Accepted
62.89
from collections import deque N, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] memo = {} for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)): E[a].append(b) E[b].append(a) memo[(a, b)] = i memo[(b, a)] = i K = max(len(e) for e in E) A = [0] * (N - 1) cand = {i for i in range(1, K + 1)} visited = [False] * (N + 1) Q = deque([(-1, 1)]) visited[1] = True while Q: p, v = Q.popleft() c = 0 for u in E[v]: if visited[u]: continue visited[u] = True c += 1 + (c + 1 == p) Q.append((c, u)) A[memo[(v, u)]] = c print(K) for a in A: print(a)
from collections import deque def main(): N, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] I = [] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) I.append(b) Q = deque([1]) C = [0] * (N + 1) while Q: v = Q.popleft() c = 0 for u in E[v]: c += 1 + (c + 1 == C[v]) C[u] = c Q.append(u) print((max(C))) for i in I: print((C[i])) main()
37
26
684
502
from collections import deque N, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] memo = {} for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)): E[a].append(b) E[b].append(a) memo[(a, b)] = i memo[(b, a)] = i K = max(len(e) for e in E) A = [0] * (N - 1) cand = {i for i in range(1, K + 1)} visited = [False] * (N + 1) Q = deque([(-1, 1)]) visited[1] = True while Q: p, v = Q.popleft() c = 0 for u in E[v]: if visited[u]: continue visited[u] = True c += 1 + (c + 1 == p) Q.append((c, u)) A[memo[(v, u)]] = c print(K) for a in A: print(a)
from collections import deque def main(): N, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] I = [] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) I.append(b) Q = deque([1]) C = [0] * (N + 1) while Q: v = Q.popleft() c = 0 for u in E[v]: c += 1 + (c + 1 == C[v]) C[u] = c Q.append(u) print((max(C))) for i in I: print((C[i])) main()
false
29.72973
[ "-N, *AB = list(map(int, open(0).read().split()))", "-E = [[] for _ in range(N + 1)]", "-memo = {}", "-for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):", "- E[a].append(b)", "- E[b].append(a)", "- memo[(a, b)] = i", "- memo[(b, a)] = i", "-K = max(len(e) for e in E)", "-A = [0] * (N - 1)", "-cand = {i for i in range(1, K + 1)}", "-visited = [False] * (N + 1)", "-Q = deque([(-1, 1)])", "-visited[1] = True", "-while Q:", "- p, v = Q.popleft()", "- c = 0", "- for u in E[v]:", "- if visited[u]:", "- continue", "- visited[u] = True", "- c += 1 + (c + 1 == p)", "- Q.append((c, u))", "- A[memo[(v, u)]] = c", "-print(K)", "-for a in A:", "- print(a)", "+", "+def main():", "+ N, *AB = list(map(int, open(0).read().split()))", "+ E = [[] for _ in range(N + 1)]", "+ I = []", "+ for a, b in zip(*[iter(AB)] * 2):", "+ E[a].append(b)", "+ I.append(b)", "+ Q = deque([1])", "+ C = [0] * (N + 1)", "+ while Q:", "+ v = Q.popleft()", "+ c = 0", "+ for u in E[v]:", "+ c += 1 + (c + 1 == C[v])", "+ C[u] = c", "+ Q.append(u)", "+ print((max(C)))", "+ for i in I:", "+ print((C[i]))", "+", "+", "+main()" ]
false
0.041331
0.04145
0.997126
[ "s749982356", "s997186209" ]
u970449052
p03807
python
s326093729
s861950717
60
43
14,108
11,104
Accepted
Accepted
28.33
n=int(eval(input())) al=list(map(int,input().split())) c=0 for a in al: c+=1 if a%2==1 else 0 print(('YES' if c%2==0 else 'NO'))
eval(input()) print(('YES' if sum(map(int,input().split()))%2==0 else 'NO'))
6
2
129
69
n = int(eval(input())) al = list(map(int, input().split())) c = 0 for a in al: c += 1 if a % 2 == 1 else 0 print(("YES" if c % 2 == 0 else "NO"))
eval(input()) print(("YES" if sum(map(int, input().split())) % 2 == 0 else "NO"))
false
66.666667
[ "-n = int(eval(input()))", "-al = list(map(int, input().split()))", "-c = 0", "-for a in al:", "- c += 1 if a % 2 == 1 else 0", "-print((\"YES\" if c % 2 == 0 else \"NO\"))", "+eval(input())", "+print((\"YES\" if sum(map(int, input().split())) % 2 == 0 else \"NO\"))" ]
false
0.117318
0.082285
1.425756
[ "s326093729", "s861950717" ]
u185249212
p03221
python
s167055009
s024994748
1,976
1,582
173,144
120,792
Accepted
Accepted
19.94
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def cmp_vec(u,v): # u < v なる必要条件を記す if u[1] < v[1]: return 1 elif u[1] == v[1]: if u[2] < v[2]: return 1 elif u[2]==v[2]: return 0 else: return -1 else: return -1 def main(): # n,m = list(map(int,input().strip().split())) # 市 in 県 # n個の県,m個の市 l=[] for i in range(m): p,y = list(map(int,input().strip().split())) # 市iは県piに属しyi年に誕生した p = str(p).zfill(6) # p-=1 # i (y,p) l.append(list((i,p,y))) l.sort(key=functools.cmp_to_key(cmp_vec),reverse = True) # eprint('l (i,p,y)',end=':\n') eprint(l) # cntr=1 for i in range(m): if i>0 and l[i][1] != l[i-1][1]: cntr=1 l[i][2] = str(cntr).zfill(6) cntr+=1 # l.sort(key=lambda x:x[0]) for xx in l: print(xx[1]+xx[2]) # # eprint('l (i,p,y)',end=':\n') # eprint(l) # aaa=["asdfa",32, 15.3, True] # eprint('aaa ',end=':\n') # eprint(aaa) if __name__ == '__main__': main()
from functools import reduce from operator import mul from collections import Counter from collections import deque from itertools import accumulate from queue import Queue from queue import PriorityQueue as pq from heapq import heapreplace from heapq import heapify from heapq import heappushpop from heapq import heappop from heapq import heappush import heapq import time import random import bisect import itertools import collections from fractions import Fraction import fractions import string import math import operator import functools import copy import array import re import sys sys.setrecursionlimit(500000) input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def cmp_vec(u, v): if u[1] < v[1]: return -1 elif u[1] == v[1]: if u[2] < v[2]: return -1 elif u[2] == v[2]: return 0 else: return 1 else: return 1 def main(): # n, m = list(map(int, input().strip().split())) l = [] for i in range(m): p, y = list(map(int, input().strip().split())) p = str(p).zfill(6) l.append(list((i, p, y))) l.sort(key=functools.cmp_to_key(cmp_vec)) # cntr = 1 for i in range(m): if i > 0 and l[i][1] != l[i-1][1]: cntr = 1 l[i][2] = str(cntr).zfill(6) cntr += 1 # l.sort(key=lambda x: x[0]) for xx in l: print(xx[1],end="") print(xx[2]) if __name__ == '__main__': main()
118
89
2,387
1,836
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def cmp_vec(u, v): # u < v なる必要条件を記す if u[1] < v[1]: return 1 elif u[1] == v[1]: if u[2] < v[2]: return 1 elif u[2] == v[2]: return 0 else: return -1 else: return -1 def main(): # n, m = list(map(int, input().strip().split())) # 市 in 県 # n個の県,m個の市 l = [] for i in range(m): p, y = list(map(int, input().strip().split())) # 市iは県piに属しyi年に誕生した p = str(p).zfill(6) # p-=1 # i (y,p) l.append(list((i, p, y))) l.sort(key=functools.cmp_to_key(cmp_vec), reverse=True) # eprint("l (i,p,y)", end=":\n") eprint(l) # cntr = 1 for i in range(m): if i > 0 and l[i][1] != l[i - 1][1]: cntr = 1 l[i][2] = str(cntr).zfill(6) cntr += 1 # l.sort(key=lambda x: x[0]) for xx in l: print(xx[1] + xx[2]) # # eprint('l (i,p,y)',end=':\n') # eprint(l) # aaa=["asdfa",32, 15.3, True] # eprint('aaa ',end=':\n') # eprint(aaa) if __name__ == "__main__": main()
from functools import reduce from operator import mul from collections import Counter from collections import deque from itertools import accumulate from queue import Queue from queue import PriorityQueue as pq from heapq import heapreplace from heapq import heapify from heapq import heappushpop from heapq import heappop from heapq import heappush import heapq import time import random import bisect import itertools import collections from fractions import Fraction import fractions import string import math import operator import functools import copy import array import re import sys sys.setrecursionlimit(500000) input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def cmp_vec(u, v): if u[1] < v[1]: return -1 elif u[1] == v[1]: if u[2] < v[2]: return -1 elif u[2] == v[2]: return 0 else: return 1 else: return 1 def main(): # n, m = list(map(int, input().strip().split())) l = [] for i in range(m): p, y = list(map(int, input().strip().split())) p = str(p).zfill(6) l.append(list((i, p, y))) l.sort(key=functools.cmp_to_key(cmp_vec)) # cntr = 1 for i in range(m): if i > 0 and l[i][1] != l[i - 1][1]: cntr = 1 l[i][2] = str(cntr).zfill(6) cntr += 1 # l.sort(key=lambda x: x[0]) for xx in l: print(xx[1], end="") print(xx[2]) if __name__ == "__main__": main()
false
24.576271
[ "+from functools import reduce", "+from operator import mul", "+from collections import Counter", "+from collections import deque", "+from itertools import accumulate", "+from queue import Queue", "+from queue import PriorityQueue as pq", "+from heapq import heapreplace", "+from heapq import heapify", "+from heapq import heappushpop", "+from heapq import heappop", "+from heapq import heappush", "+import heapq", "+import time", "+import random", "+import bisect", "+import itertools", "+import collections", "+from fractions import Fraction", "+import fractions", "+import string", "+import math", "+import operator", "+import functools", "+import copy", "+import array", "+import re", "-import re", "-import array", "-import copy", "-import functools", "-import operator", "-import math", "-import string", "-import fractions", "-from fractions import Fraction", "-import collections", "-import itertools", "-import bisect", "-import random", "-import time", "-import heapq", "-from heapq import heappush", "-from heapq import heappop", "-from heapq import heappushpop", "-from heapq import heapify", "-from heapq import heapreplace", "-from queue import PriorityQueue as pq", "-from queue import Queue", "-from itertools import accumulate", "-from collections import deque", "-from collections import Counter", "-from operator import mul", "-from functools import reduce", "-", "-# from fractions import gcd", "-# from math import gcd", "-# def lcm(n, m):", "-# return int(n * m / gcd(n, m))", "-# def coprimize(p, q):", "-# common = gcd(p, q)", "-# return (p // common, q // common)", "-# def find_gcd(list_l):", "-# x = reduce(gcd, list_l)", "-# return x", "-def cmp_vec(u, v): # u < v なる必要条件を記す", "+def cmp_vec(u, v):", "- return 1", "+ return -1", "- return 1", "+ return -1", "- return -1", "+ return 1", "- return -1", "+ return 1", "- n, m = list(map(int, input().strip().split())) # 市 in 県 # n個の県,m個の市", "+ n, m = list(map(int, input().strip().split()))", "- p, y = list(map(int, input().strip().split())) # 市iは県piに属しyi年に誕生した", "- p = str(p).zfill(6) # p-=1 # i (y,p)", "+ p, y = list(map(int, input().strip().split()))", "+ p = str(p).zfill(6)", "- l.sort(key=functools.cmp_to_key(cmp_vec), reverse=True)", "- #", "- eprint(\"l (i,p,y)\", end=\":\\n\")", "- eprint(l)", "+ l.sort(key=functools.cmp_to_key(cmp_vec))", "- print(xx[1] + xx[2])", "- #", "- # eprint('l (i,p,y)',end=':\\n')", "- # eprint(l)", "- # aaa=[\"asdfa\",32, 15.3, True]", "- # eprint('aaa ',end=':\\n')", "- # eprint(aaa)", "+ print(xx[1], end=\"\")", "+ print(xx[2])" ]
false
0.048679
0.04818
1.010366
[ "s167055009", "s024994748" ]
u871867619
p02658
python
s261996467
s508761665
85
50
21,464
21,504
Accepted
Accepted
41.18
N = int(eval(input())) A = list(map(int, input().split())) result = 1 A.sort() for i in A: result *= i if result > 10**18: result = -1 break print(result)
N = int(eval(input())) A = list(map(int, input().split())) result = 1 if 0 in A: result = 0 else: for i in A: result *= i if result > 10**18: result = -1 break print(result)
12
14
187
232
N = int(eval(input())) A = list(map(int, input().split())) result = 1 A.sort() for i in A: result *= i if result > 10**18: result = -1 break print(result)
N = int(eval(input())) A = list(map(int, input().split())) result = 1 if 0 in A: result = 0 else: for i in A: result *= i if result > 10**18: result = -1 break print(result)
false
14.285714
[ "-A.sort()", "-for i in A:", "- result *= i", "- if result > 10**18:", "- result = -1", "- break", "+if 0 in A:", "+ result = 0", "+else:", "+ for i in A:", "+ result *= i", "+ if result > 10**18:", "+ result = -1", "+ break" ]
false
0.043191
0.03696
1.168579
[ "s261996467", "s508761665" ]
u408071652
p02684
python
s635605846
s668640732
195
98
51,056
32,336
Accepted
Accepted
49.74
import sys import numpy as np from collections import defaultdict #input = sys.stdin.readline def main(): N, K = list(map(int,input().split())) A = list(map(int,input().split())) A = [0] +A #transporter visited = [0] * (N+1) town = 1 cycle = 0 for i in range(1,K+1): town = A[town] if visited[town] ==0: visited[town] = i else: cycle = i - visited[town] place = (K - visited[town]) % cycle + visited[town] print((visited.index(place))) exit() print(town) if __name__ == "__main__": main()
#input = sys.stdin.readline def main(): N, K = list(map(int,input().split())) A = list(map(int,input().split())) A = [0] +A #transporter visited = [0] * (N+1) town = 1 cycle = 0 for i in range(1,K+1): town = A[town] if visited[town] ==0: visited[town] = i else: cycle = i - visited[town] place = (K - visited[town]) % cycle + visited[town] print((visited.index(place))) exit() print(town) if __name__ == "__main__": main()
31
27
639
568
import sys import numpy as np from collections import defaultdict # input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = [0] + A # transporter visited = [0] * (N + 1) town = 1 cycle = 0 for i in range(1, K + 1): town = A[town] if visited[town] == 0: visited[town] = i else: cycle = i - visited[town] place = (K - visited[town]) % cycle + visited[town] print((visited.index(place))) exit() print(town) if __name__ == "__main__": main()
# input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = [0] + A # transporter visited = [0] * (N + 1) town = 1 cycle = 0 for i in range(1, K + 1): town = A[town] if visited[town] == 0: visited[town] = i else: cycle = i - visited[town] place = (K - visited[town]) % cycle + visited[town] print((visited.index(place))) exit() print(town) if __name__ == "__main__": main()
false
12.903226
[ "-import sys", "-import numpy as np", "-from collections import defaultdict", "-" ]
false
0.136514
0.074888
1.822902
[ "s635605846", "s668640732" ]