user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u744920373
p03221
python
s514789053
s622500921
741
544
44,696
81,372
Accepted
Accepted
26.59
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value def ume(x): x = str(x) if len(x) < 6: return '0'*(6-len(x)) + x return x def main(): N, M = mi() l = dp2(0, 3, M) cnt = [0]*(N+1) ans = dp2(0, 2, M) for i in range(M): p, y = mi() l[i][0], l[i][1], l[i][2] = p-1, y, i cnt[p] += 1 for i in range(N): cnt[i+1] += cnt[i] l.sort(key=lambda x: x[0]) for i in range(N): ichibu = l[cnt[i]:cnt[i+1]] ichibu.sort(key=lambda x: x[1]) for j in range(cnt[i+1]-cnt[i]): ans[ichibu[j][2]][0] =ichibu[j][0]+1 ans[ichibu[j][2]][1] =j+1 for x, y in ans: print((ume(x)+ume(y))) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value def ume(x): x = str(x) if len(x) < 6: return '0'*(6-len(x)) + x return x def main(): N, M = mi() ''' l = dp2(0, 3, M) cnt = [0]*(N+1) ans = dp2(0, 2, M) for i in range(M): p, y = mi() l[i][0], l[i][1], l[i][2] = p-1, y, i cnt[p] += 1 for i in range(N): cnt[i+1] += cnt[i] l.sort(key=lambda x: x[0]) for i in range(N): ichibu = l[cnt[i]:cnt[i+1]] ichibu.sort(key=lambda x: x[1]) for j in range(cnt[i+1]-cnt[i]): ans[ichibu[j][2]][0] = ichibu[j][0]+1 ans[ichibu[j][2]][1] = j+1 for x, y in ans: print(ume(x)+ume(y)) ''' l = li2(M) pos = [[] for _ in range(N+1)] ans = dp2(0, 2, M) for a, b in l: pos[a].append(b) for a in pos: a.sort() for i, a in enumerate(l): ind = bisect.bisect_left(pos[a[0]], a[1]) l[i][1] = ind+1 print((ume(l[i][0])+ume(l[i][1]))) if __name__ == "__main__": main()
44
57
1,277
1,604
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value def ume(x): x = str(x) if len(x) < 6: return "0" * (6 - len(x)) + x return x def main(): N, M = mi() l = dp2(0, 3, M) cnt = [0] * (N + 1) ans = dp2(0, 2, M) for i in range(M): p, y = mi() l[i][0], l[i][1], l[i][2] = p - 1, y, i cnt[p] += 1 for i in range(N): cnt[i + 1] += cnt[i] l.sort(key=lambda x: x[0]) for i in range(N): ichibu = l[cnt[i] : cnt[i + 1]] ichibu.sort(key=lambda x: x[1]) for j in range(cnt[i + 1] - cnt[i]): ans[ichibu[j][2]][0] = ichibu[j][0] + 1 ans[ichibu[j][2]][1] = j + 1 for x, y in ans: print((ume(x) + ume(y))) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] import bisect # bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value def ume(x): x = str(x) if len(x) < 6: return "0" * (6 - len(x)) + x return x def main(): N, M = mi() """ l = dp2(0, 3, M) cnt = [0]*(N+1) ans = dp2(0, 2, M) for i in range(M): p, y = mi() l[i][0], l[i][1], l[i][2] = p-1, y, i cnt[p] += 1 for i in range(N): cnt[i+1] += cnt[i] l.sort(key=lambda x: x[0]) for i in range(N): ichibu = l[cnt[i]:cnt[i+1]] ichibu.sort(key=lambda x: x[1]) for j in range(cnt[i+1]-cnt[i]): ans[ichibu[j][2]][0] = ichibu[j][0]+1 ans[ichibu[j][2]][1] = j+1 for x, y in ans: print(ume(x)+ume(y)) """ l = li2(M) pos = [[] for _ in range(N + 1)] ans = dp2(0, 2, M) for a, b in l: pos[a].append(b) for a in pos: a.sort() for i, a in enumerate(l): ind = bisect.bisect_left(pos[a[0]], a[1]) l[i][1] = ind + 1 print((ume(l[i][0]) + ume(l[i][1]))) if __name__ == "__main__": main()
false
22.807018
[ "-# import bisect #bisect.bisect_left(B, a)", "+import bisect # bisect.bisect_left(B, a)", "+", "+ \"\"\"", "- cnt = [0] * (N + 1)", "+ cnt = [0]*(N+1)", "- l[i][0], l[i][1], l[i][2] = p - 1, y, i", "+ l[i][0], l[i][1], l[i][2] = p-1, y, i", "- cnt[i + 1] += cnt[i]", "+ cnt[i+1] += cnt[i]", "- ichibu = l[cnt[i] : cnt[i + 1]]", "+ ichibu = l[cnt[i]:cnt[i+1]]", "- for j in range(cnt[i + 1] - cnt[i]):", "- ans[ichibu[j][2]][0] = ichibu[j][0] + 1", "- ans[ichibu[j][2]][1] = j + 1", "+ for j in range(cnt[i+1]-cnt[i]):", "+ ans[ichibu[j][2]][0] = ichibu[j][0]+1", "+ ans[ichibu[j][2]][1] = j+1", "- print((ume(x) + ume(y)))", "+ print(ume(x)+ume(y))", "+ \"\"\"", "+ l = li2(M)", "+ pos = [[] for _ in range(N + 1)]", "+ ans = dp2(0, 2, M)", "+ for a, b in l:", "+ pos[a].append(b)", "+ for a in pos:", "+ a.sort()", "+ for i, a in enumerate(l):", "+ ind = bisect.bisect_left(pos[a[0]], a[1])", "+ l[i][1] = ind + 1", "+ print((ume(l[i][0]) + ume(l[i][1])))" ]
false
0.042647
0.044646
0.955224
[ "s514789053", "s622500921" ]
u954858867
p02396
python
s063190204
s647202387
130
120
6,460
6,472
Accepted
Accepted
7.69
ret = [] while True: n = eval(input()) if n == 0: break ret += [n] for i, x in enumerate(ret): print('Case %d: %d' % (i+1, x))
ret = [] while True: n = eval(input()) if n == 0: break ret += [n] for i, x in enumerate(ret): print(('Case %d: %d' % (i+1, x)))
9
9
152
154
ret = [] while True: n = eval(input()) if n == 0: break ret += [n] for i, x in enumerate(ret): print("Case %d: %d" % (i + 1, x))
ret = [] while True: n = eval(input()) if n == 0: break ret += [n] for i, x in enumerate(ret): print(("Case %d: %d" % (i + 1, x)))
false
0
[ "- print(\"Case %d: %d\" % (i + 1, x))", "+ print((\"Case %d: %d\" % (i + 1, x)))" ]
false
0.037763
0.038666
0.97663
[ "s063190204", "s647202387" ]
u590825760
p03160
python
s855127390
s570182311
264
128
52,552
13,928
Accepted
Accepted
51.52
n = int(eval(input())) h = [int(x) for x in input().split()] dp = [float("inf")]*(n+10) dp[0] = 0 for i in range(n): if i<n-1: dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i])) if i<n-2: dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i])) print((dp[n-1]))
n = int(eval(input())) h = [int(x) for x in input().split()] dp = [float("inf")]*n dp[0] = 0 dp[1] = abs(h[0]-h[1]) for i in range(2,n): dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])) print((dp[-1]))
10
8
276
219
n = int(eval(input())) h = [int(x) for x in input().split()] dp = [float("inf")] * (n + 10) dp[0] = 0 for i in range(n): if i < n - 1: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) if i < n - 2: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print((dp[n - 1]))
n = int(eval(input())) h = [int(x) for x in input().split()] dp = [float("inf")] * n dp[0] = 0 dp[1] = abs(h[0] - h[1]) for i in range(2, n): dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) print((dp[-1]))
false
20
[ "-dp = [float(\"inf\")] * (n + 10)", "+dp = [float(\"inf\")] * n", "-for i in range(n):", "- if i < n - 1:", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))", "- if i < n - 2:", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))", "-print((dp[n - 1]))", "+dp[1] = abs(h[0] - h[1])", "+for i in range(2, n):", "+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))", "+print((dp[-1]))" ]
false
0.04652
0.036183
1.285678
[ "s855127390", "s570182311" ]
u623819879
p02735
python
s337740073
s354585108
237
214
42,732
41,324
Accepted
Accepted
9.7
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby import sys,bisect,string,math,time,functools,random def Golf():*a,=map(int,open(0)) def I():return int(input()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def GI(V,E,Directed=False,index=0): org_inp=[];g=[[] for i in range(n)] for i in range(E): inp=LI();org_inp.append(inp) if index==0:inp[0]-=1;inp[1]-=1 if len(inp)==2: a,b=inp;g[a].append(b) if not Directed:g[b].append(a) elif len(inp)==3: a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp=[1]*(w+2);found={} for i in range(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[1]+[mp_def[j] for j in s]+[1] mp+=[1]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)] def show(*inp,end='\n'): if show_flg:print(*inp,end=end) YN=['YES','NO'];Yn=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase #sys.setrecursionlimit(10**7) input=lambda: sys.stdin.readline().rstrip() def ran_input(): n=random.randint(4,16) rmin,rmax=1,10 a=[random.randint(rmin,rmax) for _ in range(n)] return n,a show_flg=False show_flg=True h,w=LI() h,w,g,sg=GGI(h,w) dp=[1e6]*(h*w) dp[w+1]=g[w+1] for j in range(h*w-w): for d in (1,w): dp[j+d]=min(dp[j]+1 if (g[j],g[j+d])==(0,1) else dp[j],dp[j+d]) print(dp[(h-2)*w+w-2])
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby import sys,bisect,string,math,time,functools,random def Golf():*a,=map(int,open(0)) def I():return int(input()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def GI(V,E,Directed=False,index=0): org_inp=[];g=[[] for i in range(n)] for i in range(E): inp=LI();org_inp.append(inp) if index==0:inp[0]-=1;inp[1]-=1 if len(inp)==2: a,b=inp;g[a].append(b) if not Directed:g[b].append(a) elif len(inp)==3: a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp=[1]*(w+2);found={} for i in range(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[1]+[mp_def[j] for j in s]+[1] mp+=[1]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)] def show(*inp,end='\n'): if show_flg:print(*inp,end=end) YN=['YES','NO'];Yn=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase #sys.setrecursionlimit(10**7) input=lambda: sys.stdin.readline().rstrip() def ran_input(): n=random.randint(4,16) rmin,rmax=1,10 a=[random.randint(rmin,rmax) for _ in range(n)] return n,a show_flg=False show_flg=True h,w=LI() h,w,g,sg=GGI(h,w) dp=[1e6]*(h*w) dp[w+1]=g[w+1] for j in range(h*w-w): for d in (1,w): dp[j+d]=min(dp[j]+(g[j]*2+g[j+d]==1),dp[j+d]) print(dp[-w-2])
71
71
2,404
2,379
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter from itertools import permutations, combinations, groupby import sys, bisect, string, math, time, functools, random def Golf(): (*a,) = map(int, open(0)) def I(): return int(input()) def S_(): return input() def IS(): return input().split() def LS(): return [i for i in input().split()] def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoLI(): return [ord(i) - 97 for i in input()] def ItoS(n): return chr(n + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def GGI(h, w, search=[], replacement_of_found=".", mp_def={"#": 1, ".": 0}): # h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp = [1] * (w + 2) found = {} for i in range(h): s = input() for char in search: if char in s: found[char] = (i + 1) * (w + 2) + s.index(char) + 1 mp_def[char] = mp_def[replacement_of_found] mp += [1] + [mp_def[j] for j in s] + [1] mp += [1] * (w + 2) return h + 2, w + 2, mp, found def TI(n): return GI(n, n - 1) def bit_combination(k, n=2): return [[tb // (n**bt) % n for bt in range(k)] for tb in range(n**k)] def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["YES", "NO"] Yn = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase # sys.setrecursionlimit(10**7) input = lambda: sys.stdin.readline().rstrip() def ran_input(): n = random.randint(4, 16) rmin, rmax = 1, 10 a = [random.randint(rmin, rmax) for _ in range(n)] return n, a show_flg = False show_flg = True h, w = LI() h, w, g, sg = GGI(h, w) dp = [1e6] * (h * w) dp[w + 1] = g[w + 1] for j in range(h * w - w): for d in (1, w): dp[j + d] = min(dp[j] + 1 if (g[j], g[j + d]) == (0, 1) else dp[j], dp[j + d]) print(dp[(h - 2) * w + w - 2])
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter from itertools import permutations, combinations, groupby import sys, bisect, string, math, time, functools, random def Golf(): (*a,) = map(int, open(0)) def I(): return int(input()) def S_(): return input() def IS(): return input().split() def LS(): return [i for i in input().split()] def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoLI(): return [ord(i) - 97 for i in input()] def ItoS(n): return chr(n + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def GGI(h, w, search=[], replacement_of_found=".", mp_def={"#": 1, ".": 0}): # h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp = [1] * (w + 2) found = {} for i in range(h): s = input() for char in search: if char in s: found[char] = (i + 1) * (w + 2) + s.index(char) + 1 mp_def[char] = mp_def[replacement_of_found] mp += [1] + [mp_def[j] for j in s] + [1] mp += [1] * (w + 2) return h + 2, w + 2, mp, found def TI(n): return GI(n, n - 1) def bit_combination(k, n=2): return [[tb // (n**bt) % n for bt in range(k)] for tb in range(n**k)] def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["YES", "NO"] Yn = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase # sys.setrecursionlimit(10**7) input = lambda: sys.stdin.readline().rstrip() def ran_input(): n = random.randint(4, 16) rmin, rmax = 1, 10 a = [random.randint(rmin, rmax) for _ in range(n)] return n, a show_flg = False show_flg = True h, w = LI() h, w, g, sg = GGI(h, w) dp = [1e6] * (h * w) dp[w + 1] = g[w + 1] for j in range(h * w - w): for d in (1, w): dp[j + d] = min(dp[j] + (g[j] * 2 + g[j + d] == 1), dp[j + d]) print(dp[-w - 2])
false
0
[ "- dp[j + d] = min(dp[j] + 1 if (g[j], g[j + d]) == (0, 1) else dp[j], dp[j + d])", "-print(dp[(h - 2) * w + w - 2])", "+ dp[j + d] = min(dp[j] + (g[j] * 2 + g[j + d] == 1), dp[j + d])", "+print(dp[-w - 2])" ]
false
0.047216
0.13603
0.347096
[ "s337740073", "s354585108" ]
u698064859
p03240
python
s039123013
s736049090
1,117
733
3,188
3,188
Accepted
Accepted
34.38
N = int(eval(input())) points = [None] * N for i in range(0, N): points[i] = list(map(int, input().split())) h_max = max([h for x, y, h in points]) for H in range(h_max + 100, h_max - 1, -1): for Cx in range(101): for Cy in range(101): ok = True for X, Y, h1 in points: h2 = max(H - abs(X - Cx) - abs(Y - Cy), 0) if h1 != h2: ok = False break if ok: print(('{} {} {}'.format(Cx, Cy, H))) exit()
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] h_max = max(h for x, y, h in points) for H in range(h_max, h_max + 1000): for Cx in range(101): for Cy in range(101): ok = True for x, y, h in points: h_calc = max(H - abs(x - Cx) - abs(y - Cy), 0) if h != h_calc: ok = False break if ok: print(('{} {} {}'.format(Cx, Cy, H))) exit()
20
16
565
529
N = int(eval(input())) points = [None] * N for i in range(0, N): points[i] = list(map(int, input().split())) h_max = max([h for x, y, h in points]) for H in range(h_max + 100, h_max - 1, -1): for Cx in range(101): for Cy in range(101): ok = True for X, Y, h1 in points: h2 = max(H - abs(X - Cx) - abs(Y - Cy), 0) if h1 != h2: ok = False break if ok: print(("{} {} {}".format(Cx, Cy, H))) exit()
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] h_max = max(h for x, y, h in points) for H in range(h_max, h_max + 1000): for Cx in range(101): for Cy in range(101): ok = True for x, y, h in points: h_calc = max(H - abs(x - Cx) - abs(y - Cy), 0) if h != h_calc: ok = False break if ok: print(("{} {} {}".format(Cx, Cy, H))) exit()
false
20
[ "-points = [None] * N", "-for i in range(0, N):", "- points[i] = list(map(int, input().split()))", "-h_max = max([h for x, y, h in points])", "-for H in range(h_max + 100, h_max - 1, -1):", "+points = [[int(s) for s in input().split()] for i in range(N)]", "+h_max = max(h for x, y, h in points)", "+for H in range(h_max, h_max + 1000):", "- for X, Y, h1 in points:", "- h2 = max(H - abs(X - Cx) - abs(Y - Cy), 0)", "- if h1 != h2:", "+ for x, y, h in points:", "+ h_calc = max(H - abs(x - Cx) - abs(y - Cy), 0)", "+ if h != h_calc:" ]
false
0.826252
0.412043
2.005257
[ "s039123013", "s736049090" ]
u644907318
p03734
python
s262635316
s464737129
335
218
67,932
77,284
Accepted
Accepted
34.93
INFTY = 10**10 N,W = list(map(int,input().split())) X = [list(map(int,input().split())) for _ in range(N)] dp = [[[-INFTY for _ in range(3*(N-1)+1)] for _ in range(N+1)] for _ in range(N+1)] for i in range(N+1): dp[i][0][0] = 0 for i in range(1,N+1): for j in range(1,i+1): for k in range(3*(N-1)+1): dp[i][j][k] = dp[i-1][j][k] if k>=X[i-1][0]-X[0][0]: dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-X[i-1][0]+X[0][0]]+X[i-1][1]) cmax = 0 for j in range(1,N+1): for k in range(3*(N-1)+1): if j*X[0][0]+k<=W: cmax = max(cmax,dp[N][j][k]) print(cmax)
N,W = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(N)] w1 = A[0][0] C = {0:[],1:[],2:[],3:[]} for i in range(N): w,v = A[i] C[w-w1].append(v) C[0] = sorted(C[0],reverse=True) C[1] = sorted(C[1],reverse=True) C[2] = sorted(C[2],reverse=True) C[3] = sorted(C[3],reverse=True) n0 = len(C[0]) n1 = len(C[1]) n2 = len(C[2]) n3 = len(C[3]) vmax = 0 for a0 in range(n0+1): for a1 in range(n1+1): for a2 in range(n2+1): for a3 in range(n3+1): if a0*w1+a1*(w1+1)+a2*(w1+2)+a3*(w1+3)<=W: v = sum(C[0][:a0])+sum(C[1][:a1])+sum(C[2][:a2])+sum(C[3][:a3]) vmax = max(vmax,v) print(vmax)
18
24
638
714
INFTY = 10**10 N, W = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] dp = [ [[-INFTY for _ in range(3 * (N - 1) + 1)] for _ in range(N + 1)] for _ in range(N + 1) ] for i in range(N + 1): dp[i][0][0] = 0 for i in range(1, N + 1): for j in range(1, i + 1): for k in range(3 * (N - 1) + 1): dp[i][j][k] = dp[i - 1][j][k] if k >= X[i - 1][0] - X[0][0]: dp[i][j][k] = max( dp[i][j][k], dp[i - 1][j - 1][k - X[i - 1][0] + X[0][0]] + X[i - 1][1], ) cmax = 0 for j in range(1, N + 1): for k in range(3 * (N - 1) + 1): if j * X[0][0] + k <= W: cmax = max(cmax, dp[N][j][k]) print(cmax)
N, W = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] w1 = A[0][0] C = {0: [], 1: [], 2: [], 3: []} for i in range(N): w, v = A[i] C[w - w1].append(v) C[0] = sorted(C[0], reverse=True) C[1] = sorted(C[1], reverse=True) C[2] = sorted(C[2], reverse=True) C[3] = sorted(C[3], reverse=True) n0 = len(C[0]) n1 = len(C[1]) n2 = len(C[2]) n3 = len(C[3]) vmax = 0 for a0 in range(n0 + 1): for a1 in range(n1 + 1): for a2 in range(n2 + 1): for a3 in range(n3 + 1): if a0 * w1 + a1 * (w1 + 1) + a2 * (w1 + 2) + a3 * (w1 + 3) <= W: v = ( sum(C[0][:a0]) + sum(C[1][:a1]) + sum(C[2][:a2]) + sum(C[3][:a3]) ) vmax = max(vmax, v) print(vmax)
false
25
[ "-INFTY = 10**10", "-X = [list(map(int, input().split())) for _ in range(N)]", "-dp = [", "- [[-INFTY for _ in range(3 * (N - 1) + 1)] for _ in range(N + 1)]", "- for _ in range(N + 1)", "-]", "-for i in range(N + 1):", "- dp[i][0][0] = 0", "-for i in range(1, N + 1):", "- for j in range(1, i + 1):", "- for k in range(3 * (N - 1) + 1):", "- dp[i][j][k] = dp[i - 1][j][k]", "- if k >= X[i - 1][0] - X[0][0]:", "- dp[i][j][k] = max(", "- dp[i][j][k],", "- dp[i - 1][j - 1][k - X[i - 1][0] + X[0][0]] + X[i - 1][1],", "- )", "-cmax = 0", "-for j in range(1, N + 1):", "- for k in range(3 * (N - 1) + 1):", "- if j * X[0][0] + k <= W:", "- cmax = max(cmax, dp[N][j][k])", "-print(cmax)", "+A = [list(map(int, input().split())) for _ in range(N)]", "+w1 = A[0][0]", "+C = {0: [], 1: [], 2: [], 3: []}", "+for i in range(N):", "+ w, v = A[i]", "+ C[w - w1].append(v)", "+C[0] = sorted(C[0], reverse=True)", "+C[1] = sorted(C[1], reverse=True)", "+C[2] = sorted(C[2], reverse=True)", "+C[3] = sorted(C[3], reverse=True)", "+n0 = len(C[0])", "+n1 = len(C[1])", "+n2 = len(C[2])", "+n3 = len(C[3])", "+vmax = 0", "+for a0 in range(n0 + 1):", "+ for a1 in range(n1 + 1):", "+ for a2 in range(n2 + 1):", "+ for a3 in range(n3 + 1):", "+ if a0 * w1 + a1 * (w1 + 1) + a2 * (w1 + 2) + a3 * (w1 + 3) <= W:", "+ v = (", "+ sum(C[0][:a0])", "+ + sum(C[1][:a1])", "+ + sum(C[2][:a2])", "+ + sum(C[3][:a3])", "+ )", "+ vmax = max(vmax, v)", "+print(vmax)" ]
false
0.035129
0.037942
0.925863
[ "s262635316", "s464737129" ]
u347640436
p02850
python
s000918573
s126967913
761
476
53,784
86,564
Accepted
Accepted
37.45
# 深さ優先探索 from sys import setrecursionlimit def genid(a, b): if b < a: a, b = b, a return a * 100000 + b N = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(N - 1)] edges = [[] for _ in range(N)] for a, b in ab: edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) colors = {} q = [(0, -1, -1)] while q: currentNode, usedColor, parentNode = q.pop() color = 1 for childNode in edges[currentNode]: if childNode == parentNode: continue if color == usedColor: color += 1 colors[genid(currentNode, childNode)] = color q.append((childNode, color, currentNode)) color += 1 print((max(len(e) for e in edges))) for a, b in ab: print((colors[genid(a - 1, b - 1)]))
# 深さ優先探索 from sys import setrecursionlimit def genid(a, b): if b < a: a, b = b, a return a * 100000 + b def paint(currentNode, usedColor, parentNode, edges, colors): color = 1 for childNode in edges[currentNode]: if childNode == parentNode: continue if color == usedColor: color += 1 colors[genid(currentNode, childNode)] = color paint(childNode, color, currentNode, edges, colors) color += 1 setrecursionlimit(10 ** 6) N = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(N - 1)] edges = [[] for _ in range(N)] for a, b in ab: edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) colors = {} paint(0, -1, -1, edges, colors) print((max(len(e) for e in edges))) for a, b in ab: print((colors[genid(a - 1, b - 1)]))
35
38
814
875
# 深さ優先探索 from sys import setrecursionlimit def genid(a, b): if b < a: a, b = b, a return a * 100000 + b N = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(N - 1)] edges = [[] for _ in range(N)] for a, b in ab: edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) colors = {} q = [(0, -1, -1)] while q: currentNode, usedColor, parentNode = q.pop() color = 1 for childNode in edges[currentNode]: if childNode == parentNode: continue if color == usedColor: color += 1 colors[genid(currentNode, childNode)] = color q.append((childNode, color, currentNode)) color += 1 print((max(len(e) for e in edges))) for a, b in ab: print((colors[genid(a - 1, b - 1)]))
# 深さ優先探索 from sys import setrecursionlimit def genid(a, b): if b < a: a, b = b, a return a * 100000 + b def paint(currentNode, usedColor, parentNode, edges, colors): color = 1 for childNode in edges[currentNode]: if childNode == parentNode: continue if color == usedColor: color += 1 colors[genid(currentNode, childNode)] = color paint(childNode, color, currentNode, edges, colors) color += 1 setrecursionlimit(10**6) N = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(N - 1)] edges = [[] for _ in range(N)] for a, b in ab: edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) colors = {} paint(0, -1, -1, edges, colors) print((max(len(e) for e in edges))) for a, b in ab: print((colors[genid(a - 1, b - 1)]))
false
7.894737
[ "+def paint(currentNode, usedColor, parentNode, edges, colors):", "+ color = 1", "+ for childNode in edges[currentNode]:", "+ if childNode == parentNode:", "+ continue", "+ if color == usedColor:", "+ color += 1", "+ colors[genid(currentNode, childNode)] = color", "+ paint(childNode, color, currentNode, edges, colors)", "+ color += 1", "+", "+", "+setrecursionlimit(10**6)", "-q = [(0, -1, -1)]", "-while q:", "- currentNode, usedColor, parentNode = q.pop()", "- color = 1", "- for childNode in edges[currentNode]:", "- if childNode == parentNode:", "- continue", "- if color == usedColor:", "- color += 1", "- colors[genid(currentNode, childNode)] = color", "- q.append((childNode, color, currentNode))", "- color += 1", "+paint(0, -1, -1, edges, colors)" ]
false
0.041786
0.060088
0.695408
[ "s000918573", "s126967913" ]
u608088992
p03329
python
s430534225
s472733423
334
202
7,064
41,072
Accepted
Accepted
39.52
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) DP = [int(i) for i in range(N + 1)] ni = 9 for i in range(N): if ni > N: break for j in range(N - ni + 1): DP[j + ni] = min(DP[j + ni], DP[j] + 1) ni *= 9 six = 6 for i in range(N): if six > N: break for j in range(N - six + 1): DP[j + six] = min(DP[j + six], DP[j] + 1) six *= 6 print((DP[N])) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) M = [1] for i in range(1, 12): if pow(6, i) > N: break M.append(pow(6, i)) for i in range(1, 10): if pow(9, i) > N: break M.append(pow(9, i)) M.sort() DP = [100000] * (N + 1) DP[N] = 0 for i in reversed(list(range(N + 1))): if DP[i] < 100000: for m in M: if i - m >= 0: DP[i-m] = min(DP[i-m], DP[i] + 1) print((DP[0])) return 0 if __name__ == "__main__": solve()
25
26
548
567
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) DP = [int(i) for i in range(N + 1)] ni = 9 for i in range(N): if ni > N: break for j in range(N - ni + 1): DP[j + ni] = min(DP[j + ni], DP[j] + 1) ni *= 9 six = 6 for i in range(N): if six > N: break for j in range(N - six + 1): DP[j + six] = min(DP[j + six], DP[j] + 1) six *= 6 print((DP[N])) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) M = [1] for i in range(1, 12): if pow(6, i) > N: break M.append(pow(6, i)) for i in range(1, 10): if pow(9, i) > N: break M.append(pow(9, i)) M.sort() DP = [100000] * (N + 1) DP[N] = 0 for i in reversed(list(range(N + 1))): if DP[i] < 100000: for m in M: if i - m >= 0: DP[i - m] = min(DP[i - m], DP[i] + 1) print((DP[0])) return 0 if __name__ == "__main__": solve()
false
3.846154
[ "- DP = [int(i) for i in range(N + 1)]", "- ni = 9", "- for i in range(N):", "- if ni > N:", "+ M = [1]", "+ for i in range(1, 12):", "+ if pow(6, i) > N:", "- for j in range(N - ni + 1):", "- DP[j + ni] = min(DP[j + ni], DP[j] + 1)", "- ni *= 9", "- six = 6", "- for i in range(N):", "- if six > N:", "+ M.append(pow(6, i))", "+ for i in range(1, 10):", "+ if pow(9, i) > N:", "- for j in range(N - six + 1):", "- DP[j + six] = min(DP[j + six], DP[j] + 1)", "- six *= 6", "- print((DP[N]))", "+ M.append(pow(9, i))", "+ M.sort()", "+ DP = [100000] * (N + 1)", "+ DP[N] = 0", "+ for i in reversed(list(range(N + 1))):", "+ if DP[i] < 100000:", "+ for m in M:", "+ if i - m >= 0:", "+ DP[i - m] = min(DP[i - m], DP[i] + 1)", "+ print((DP[0]))" ]
false
0.070413
0.083504
0.843231
[ "s430534225", "s472733423" ]
u888092736
p02845
python
s918133958
s564332100
163
148
20,624
20,160
Accepted
Accepted
9.2
N = int(eval(input())) A = list(map(int, input().split())) MOD = 1_000_000_007 cnt = [0, 0, 0] ans = 1 for i in range(N): ans *= sum(c == A[i] for c in cnt) ans %= MOD for j in range(3): if cnt[j] == A[i]: cnt[j] += 1 break print(ans)
N, *A = list(map(int, open(0).read().split())) MOD = 1_000_000_007 cnt = [0, 0, 0] ans = 1 for a in A: possible = sum(c == a for c in cnt) ans *= possible ans %= MOD for i in range(3): if cnt[i] == a: cnt[i] += 1 break print(ans)
14
13
287
284
N = int(eval(input())) A = list(map(int, input().split())) MOD = 1_000_000_007 cnt = [0, 0, 0] ans = 1 for i in range(N): ans *= sum(c == A[i] for c in cnt) ans %= MOD for j in range(3): if cnt[j] == A[i]: cnt[j] += 1 break print(ans)
N, *A = list(map(int, open(0).read().split())) MOD = 1_000_000_007 cnt = [0, 0, 0] ans = 1 for a in A: possible = sum(c == a for c in cnt) ans *= possible ans %= MOD for i in range(3): if cnt[i] == a: cnt[i] += 1 break print(ans)
false
7.142857
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "+N, *A = list(map(int, open(0).read().split()))", "-for i in range(N):", "- ans *= sum(c == A[i] for c in cnt)", "+for a in A:", "+ possible = sum(c == a for c in cnt)", "+ ans *= possible", "- for j in range(3):", "- if cnt[j] == A[i]:", "- cnt[j] += 1", "+ for i in range(3):", "+ if cnt[i] == a:", "+ cnt[i] += 1" ]
false
0.043948
0.043704
1.005595
[ "s918133958", "s564332100" ]
u326609687
p02889
python
s817229378
s274106859
413
303
22,440
39,344
Accepted
Accepted
26.63
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open('/dev/stdin') pin = np.fromstring(stdin.read(), i8, sep=' ') N = pin[0] M = pin[1] L = pin[2] ABC = pin[3: M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 for i in range(st.shape[0]): print((int(min_dist[st[i, 0], st[i, 1]] - 1.0))) if __name__ == '__main__': main()
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open('/dev/stdin') pin = np.fromstring(stdin.read(), i8, sep=' ') N = pin[0] M = pin[1] L = pin[2] ABC = pin[3: M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) s = st[:, 0] t = st[:, 1] graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 min_dist = (min_dist + .5).astype(int) x = min_dist[s, t] - 1 print(('\n'.join(x.astype(str)))) if __name__ == '__main__': main()
32
36
872
928
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open("/dev/stdin") pin = np.fromstring(stdin.read(), i8, sep=" ") N = pin[0] M = pin[1] L = pin[2] ABC = pin[3 : M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4 : 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 for i in range(st.shape[0]): print((int(min_dist[st[i, 0], st[i, 1]] - 1.0))) if __name__ == "__main__": main()
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open("/dev/stdin") pin = np.fromstring(stdin.read(), i8, sep=" ") N = pin[0] M = pin[1] L = pin[2] ABC = pin[3 : M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4 : 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) s = st[:, 0] t = st[:, 1] graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 min_dist = (min_dist + 0.5).astype(int) x = min_dist[s, t] - 1 print(("\n".join(x.astype(str)))) if __name__ == "__main__": main()
false
11.111111
[ "+ s = st[:, 0]", "+ t = st[:, 1]", "- for i in range(st.shape[0]):", "- print((int(min_dist[st[i, 0], st[i, 1]] - 1.0)))", "+ min_dist = (min_dist + 0.5).astype(int)", "+ x = min_dist[s, t] - 1", "+ print((\"\\n\".join(x.astype(str))))" ]
false
0.331359
0.273739
1.210495
[ "s817229378", "s274106859" ]
u414980766
p02579
python
s702596020
s727803676
1,703
1,351
29,048
29,044
Accepted
Accepted
20.67
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # ---------標準入力時-------------- h,w=list(map(int,readline().split())) ch, cw=list(map(int,readline().split())) dh, dw=list(map(int,readline().split())) m=list([list(x.decode()) for x in readlines()]) # ---------標準入力時-------------- ud=[(-1,0), (1,0)] # 上下 lr=[(0,-1), (0,1)] # 左右 warp = [(-2, -2),(-2, -1),(-2, 0),(-2, 1),(-2, 2), (-1, -2),(-1, -1),(-1, 1),(-1, 2), (0, -2),(0, 2), (1, -2),(1, -1),(1, 1),(1, 2), (2, -2),(2, -1),(2, 0),(2, 1),(2, 2)] def bfs5(): ''' bfs4から少し変更 あるマス(i,j)から上(i-1,j)下(i+1,j) もしくは 左(i,j-1)右(i,j+1)に歩いて行ける時、 (i,j)からwarpで行ける範囲は、その上下もしくは左右でカバーされるので、(i,jは考えなくていい) ''' que1=[] que2=[] # queueというよりはメモリ m[ch][cw]=str(0) que1.append((ch,cw)) while que1!=[]: l1=len(que1) r1=0 # que1における使用済みindex # que1の要素(座標)から歩いていけるマス while r1<l1: i, j=que1[r1] cnt_ud=0 # 隣接した上下のマスへの移動 for si, sj in ud: if m[i+si][j+sj]=='.': m[i+si][j+sj]=m[i][j] que1.append((i+si, j+sj)) cnt_ud+=1 cnt_lr=0 # 隣接した上下のマスへの移動 for si, sj in lr: if m[i+si][j+sj]=='.': m[i+si][j+sj]=m[i][j] que1.append((i+si, j+sj)) cnt_lr+=1 if cnt_ud==2 or cnt_lr==2: # que1[r1]は不要 que1.pop(r1); l1+=cnt_ud+cnt_lr-1 else: # que1[r1]は必要 r1+=1; l1+=cnt_ud+cnt_lr # 歩いていけないマス for i,j in que1: for si, sj in warp: if m[i+si][j+sj]=='.': m[i+si][j+sj]=str(int(m[i][j])+1) que2.append((i+si, j+sj)) que1=que2 que2=[] for i in range(h): m[i] = ['#']*2 + m[i] + ['#']*2 m = [['#']*(w+4)]*2 + m + [['#']*(w+4)]*2 ch+=1; cw+=1; dh+=1; dw+=1 bfs5() if m[dh][dw] == '.': print((-1)) else: print((m[dh][dw]))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # ---------標準入力時-------------- h,w=list(map(int,readline().split())) ch, cw=list(map(int,readline().split())) dh, dw=list(map(int,readline().split())) m=list([list(x.decode()) for x in readlines()]) # ---------標準入力時-------------- ad = [(-1,0), (0,-1), (1,0), (0,1)] warp = [(-2, -2),(-2, -1),(-2, 0),(-2, 1),(-2, 2), (-1, -2),(-1, -1),(-1, 1),(-1, 2), (0, -2),(0, 2), (1, -2),(1, -1),(1, 1),(1, 2), (2, -2),(2, -1),(2, 0),(2, 1),(2, 2)] def bfs6(): ''' bfs5から少し変更 あるマス(i,j)から上(i-1,j)下(i+1,j) もしくは 左(i,j-1)右(i,j+1)に歩いて行ける時、 (i,j)からwarpで行ける範囲は、その上下もしくは左右でカバーされるので、(i,jは考えなくていい) これをwarpを考えるときに処理する ''' que1=[] que2=[] # queueというよりはメモリ m[ch][cw]=str(0) que1.append((ch,cw)) while que1!=[]: l1=len(que1) r1=0 # que1における使用済みindex # que1の要素(座標)から歩いていけるマス while r1<l1: i, j=que1[r1] r1+=1 for si, sj in ad: if m[i+si][j+sj]=='.': m[i+si][j+sj]=m[i][j] que1.append((i+si, j+sj)) l1+=1 # 歩いていけないマス for i,j in que1: if (m[i][j]==m[i-1][j] and m[i][j]==m[i+1][j]) or (m[i][j]==m[i][j-1] and m[i][j]==m[i][j+1]): continue for si, sj in warp: if m[i+si][j+sj]=='.': m[i+si][j+sj]=str(int(m[i][j])+1) que2.append((i+si, j+sj)) que1=que2 que2=[] ###--------------------------------------- for i in range(h): m[i] = ['#']*2 + m[i] + ['#']*2 m = [['#']*(w+4)]*2 + m + [['#']*(w+4)]*2 ch+=1; cw+=1; dh+=1; dw+=1 bfs6() if m[dh][dw] == '.': print((-1)) else: print((m[dh][dw]))
79
70
2,153
1,873
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # ---------標準入力時-------------- h, w = list(map(int, readline().split())) ch, cw = list(map(int, readline().split())) dh, dw = list(map(int, readline().split())) m = list([list(x.decode()) for x in readlines()]) # ---------標準入力時-------------- ud = [(-1, 0), (1, 0)] # 上下 lr = [(0, -1), (0, 1)] # 左右 warp = [ (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), ] def bfs5(): """ bfs4から少し変更 あるマス(i,j)から上(i-1,j)下(i+1,j) もしくは 左(i,j-1)右(i,j+1)に歩いて行ける時、 (i,j)からwarpで行ける範囲は、その上下もしくは左右でカバーされるので、(i,jは考えなくていい) """ que1 = [] que2 = [] # queueというよりはメモリ m[ch][cw] = str(0) que1.append((ch, cw)) while que1 != []: l1 = len(que1) r1 = 0 # que1における使用済みindex # que1の要素(座標)から歩いていけるマス while r1 < l1: i, j = que1[r1] cnt_ud = 0 # 隣接した上下のマスへの移動 for si, sj in ud: if m[i + si][j + sj] == ".": m[i + si][j + sj] = m[i][j] que1.append((i + si, j + sj)) cnt_ud += 1 cnt_lr = 0 # 隣接した上下のマスへの移動 for si, sj in lr: if m[i + si][j + sj] == ".": m[i + si][j + sj] = m[i][j] que1.append((i + si, j + sj)) cnt_lr += 1 if cnt_ud == 2 or cnt_lr == 2: # que1[r1]は不要 que1.pop(r1) l1 += cnt_ud + cnt_lr - 1 else: # que1[r1]は必要 r1 += 1 l1 += cnt_ud + cnt_lr # 歩いていけないマス for i, j in que1: for si, sj in warp: if m[i + si][j + sj] == ".": m[i + si][j + sj] = str(int(m[i][j]) + 1) que2.append((i + si, j + sj)) que1 = que2 que2 = [] for i in range(h): m[i] = ["#"] * 2 + m[i] + ["#"] * 2 m = [["#"] * (w + 4)] * 2 + m + [["#"] * (w + 4)] * 2 ch += 1 cw += 1 dh += 1 dw += 1 bfs5() if m[dh][dw] == ".": print((-1)) else: print((m[dh][dw]))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # ---------標準入力時-------------- h, w = list(map(int, readline().split())) ch, cw = list(map(int, readline().split())) dh, dw = list(map(int, readline().split())) m = list([list(x.decode()) for x in readlines()]) # ---------標準入力時-------------- ad = [(-1, 0), (0, -1), (1, 0), (0, 1)] warp = [ (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), ] def bfs6(): """ bfs5から少し変更 あるマス(i,j)から上(i-1,j)下(i+1,j) もしくは 左(i,j-1)右(i,j+1)に歩いて行ける時、 (i,j)からwarpで行ける範囲は、その上下もしくは左右でカバーされるので、(i,jは考えなくていい) これをwarpを考えるときに処理する """ que1 = [] que2 = [] # queueというよりはメモリ m[ch][cw] = str(0) que1.append((ch, cw)) while que1 != []: l1 = len(que1) r1 = 0 # que1における使用済みindex # que1の要素(座標)から歩いていけるマス while r1 < l1: i, j = que1[r1] r1 += 1 for si, sj in ad: if m[i + si][j + sj] == ".": m[i + si][j + sj] = m[i][j] que1.append((i + si, j + sj)) l1 += 1 # 歩いていけないマス for i, j in que1: if (m[i][j] == m[i - 1][j] and m[i][j] == m[i + 1][j]) or ( m[i][j] == m[i][j - 1] and m[i][j] == m[i][j + 1] ): continue for si, sj in warp: if m[i + si][j + sj] == ".": m[i + si][j + sj] = str(int(m[i][j]) + 1) que2.append((i + si, j + sj)) que1 = que2 que2 = [] ###--------------------------------------- for i in range(h): m[i] = ["#"] * 2 + m[i] + ["#"] * 2 m = [["#"] * (w + 4)] * 2 + m + [["#"] * (w + 4)] * 2 ch += 1 cw += 1 dh += 1 dw += 1 bfs6() if m[dh][dw] == ".": print((-1)) else: print((m[dh][dw]))
false
11.392405
[ "-ud = [(-1, 0), (1, 0)] # 上下", "-lr = [(0, -1), (0, 1)] # 左右", "+ad = [(-1, 0), (0, -1), (1, 0), (0, 1)]", "-def bfs5():", "+def bfs6():", "- bfs4から少し変更", "+ bfs5から少し変更", "+ これをwarpを考えるときに処理する", "- cnt_ud = 0", "- # 隣接した上下のマスへの移動", "- for si, sj in ud:", "+ r1 += 1", "+ for si, sj in ad:", "- cnt_ud += 1", "- cnt_lr = 0", "- # 隣接した上下のマスへの移動", "- for si, sj in lr:", "- if m[i + si][j + sj] == \".\":", "- m[i + si][j + sj] = m[i][j]", "- que1.append((i + si, j + sj))", "- cnt_lr += 1", "- if cnt_ud == 2 or cnt_lr == 2: # que1[r1]は不要", "- que1.pop(r1)", "- l1 += cnt_ud + cnt_lr - 1", "- else: # que1[r1]は必要", "- r1 += 1", "- l1 += cnt_ud + cnt_lr", "+ l1 += 1", "+ if (m[i][j] == m[i - 1][j] and m[i][j] == m[i + 1][j]) or (", "+ m[i][j] == m[i][j - 1] and m[i][j] == m[i][j + 1]", "+ ):", "+ continue", "-bfs5()", "+bfs6()" ]
false
0.038871
0.042126
0.922729
[ "s702596020", "s727803676" ]
u670180528
p02940
python
s277326005
s707412230
371
279
47,704
43,224
Accepted
Accepted
24.8
import math n=int(eval(input())) a=1;c={"R":0,"G":0,"B":0} m=998244353 for i in eval(input()): s=sorted(c.values()) c[i]+=1 if c[i]>s[2]:pass elif c[i]>s[1]:a*=s[2]-s[1] else:a*=s[1]-s[0] a%=m print((math.factorial(n)*a%m))
n=int(eval(input())) a=1;c={"R":0,"G":0,"B":0} m=998244353 for i in eval(input()): s=sorted(c.values()) c[i]+=1 if c[i]>s[2]:pass elif c[i]>s[1]:a*=s[2]-s[1] else:a*=s[1]-s[0] a%=m for j in range(1,n+1): a*=j a%=m print(a)
12
14
226
231
import math n = int(eval(input())) a = 1 c = {"R": 0, "G": 0, "B": 0} m = 998244353 for i in eval(input()): s = sorted(c.values()) c[i] += 1 if c[i] > s[2]: pass elif c[i] > s[1]: a *= s[2] - s[1] else: a *= s[1] - s[0] a %= m print((math.factorial(n) * a % m))
n = int(eval(input())) a = 1 c = {"R": 0, "G": 0, "B": 0} m = 998244353 for i in eval(input()): s = sorted(c.values()) c[i] += 1 if c[i] > s[2]: pass elif c[i] > s[1]: a *= s[2] - s[1] else: a *= s[1] - s[0] a %= m for j in range(1, n + 1): a *= j a %= m print(a)
false
14.285714
[ "-import math", "-", "-print((math.factorial(n) * a % m))", "+for j in range(1, n + 1):", "+ a *= j", "+ a %= m", "+print(a)" ]
false
0.042177
0.042436
0.993897
[ "s277326005", "s707412230" ]
u941407962
p02852
python
s595387793
s017147942
263
224
56,284
52,896
Accepted
Accepted
14.83
from collections import deque INF = 10**18 def append_dq(i, x, dq, dp1): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > dp1[lxi]: dq.append(i) break dq.pop() return dq dq = deque() N,M = list(map(int, input().split())) S = input().strip() dp1 = [0] + [INF]*N dp2 = [-1 for _ in range(N+1)] dq.append(0) for i, c in enumerate(S[1:]): i+=1 dq = append_dq(i, dp1[i], dq, dp1) idx = dq[0] if c != "1" and dp1[idx] != INF: dp1[i] = dp1[idx] + 1 dp2[i] = idx if i >= M: sxi = dq[0] if sxi == (i - M): dq.popleft() if dp1[-1] == INF: print((-1)) else: r = [] s = N while True: if s == 0: break ns = dp2[s] r.append(s-ns) s = ns print((" ".join(map(str, r[::-1]))))
N,M=map(int,input().split()) S,r,s=input(),[],N for _ in range(2*N): if S[s]=='1': s += 1 else: r.append(str(N-s)) N,s=s,max(0,s-M) if N == 0: break print(*[-1] if s else r[1:][::-1])
43
11
927
237
from collections import deque INF = 10**18 def append_dq(i, x, dq, dp1): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > dp1[lxi]: dq.append(i) break dq.pop() return dq dq = deque() N, M = list(map(int, input().split())) S = input().strip() dp1 = [0] + [INF] * N dp2 = [-1 for _ in range(N + 1)] dq.append(0) for i, c in enumerate(S[1:]): i += 1 dq = append_dq(i, dp1[i], dq, dp1) idx = dq[0] if c != "1" and dp1[idx] != INF: dp1[i] = dp1[idx] + 1 dp2[i] = idx if i >= M: sxi = dq[0] if sxi == (i - M): dq.popleft() if dp1[-1] == INF: print((-1)) else: r = [] s = N while True: if s == 0: break ns = dp2[s] r.append(s - ns) s = ns print((" ".join(map(str, r[::-1]))))
N, M = map(int, input().split()) S, r, s = input(), [], N for _ in range(2 * N): if S[s] == "1": s += 1 else: r.append(str(N - s)) N, s = s, max(0, s - M) if N == 0: break print(*[-1] if s else r[1:][::-1])
false
74.418605
[ "-from collections import deque", "-", "-INF = 10**18", "-", "-", "-def append_dq(i, x, dq, dp1):", "- while True:", "- if not len(dq):", "- dq.append(i)", "- break", "- lxi = dq[-1]", "- if x > dp1[lxi]:", "- dq.append(i)", "- break", "- dq.pop()", "- return dq", "-", "-", "-dq = deque()", "-N, M = list(map(int, input().split()))", "-S = input().strip()", "-dp1 = [0] + [INF] * N", "-dp2 = [-1 for _ in range(N + 1)]", "-dq.append(0)", "-for i, c in enumerate(S[1:]):", "- i += 1", "- dq = append_dq(i, dp1[i], dq, dp1)", "- idx = dq[0]", "- if c != \"1\" and dp1[idx] != INF:", "- dp1[i] = dp1[idx] + 1", "- dp2[i] = idx", "- if i >= M:", "- sxi = dq[0]", "- if sxi == (i - M):", "- dq.popleft()", "-if dp1[-1] == INF:", "- print((-1))", "-else:", "- r = []", "- s = N", "- while True:", "- if s == 0:", "- break", "- ns = dp2[s]", "- r.append(s - ns)", "- s = ns", "- print((\" \".join(map(str, r[::-1]))))", "+N, M = map(int, input().split())", "+S, r, s = input(), [], N", "+for _ in range(2 * N):", "+ if S[s] == \"1\":", "+ s += 1", "+ else:", "+ r.append(str(N - s))", "+ N, s = s, max(0, s - M)", "+ if N == 0:", "+ break", "+print(*[-1] if s else r[1:][::-1])" ]
false
0.04052
0.04343
0.932987
[ "s595387793", "s017147942" ]
u894258749
p03006
python
s205780976
s272564758
252
186
48,240
39,024
Accepted
Accepted
26.19
from collections import defaultdict inpl = lambda: list(map(int,input().split())) N = int(eval(input())) xy = [] field = defaultdict(int) for _ in range(N): x, y = inpl() xy.append((x,y)) field[(x,y)] = 1 xy.sort() pq = set() for i in range(N): for j in range(i+1,N): x1, y1 = xy[i] x2, y2 = xy[j] p, q = x2-x1, y2-y1 pq.add((p,q)) ans = N for p, q in pq: removed = defaultdict(int) cost = 0 for x, y in xy: if removed[(x,y)]: continue else: removed[(x,y)] = 1 cost += 1 while True: x += p y += q if field[(x,y)]: removed[(x,y)] = 1 else: break if cost < ans: ans = cost print(ans)
from collections import defaultdict inpl = lambda: list(map(int,input().split())) N = int(eval(input())) xy = [] for _ in range(N): x, y = inpl() xy.append((x,y)) xy.sort() edges = defaultdict(int) edges[(0,0)] = 0 for i in range(N): for j in range(i+1,N): x1, y1 = xy[i] x2, y2 = xy[j] p, q = x2-x1, y2-y1 edges[(p,q)] += 1 print((N - max(edges.values())))
41
20
859
417
from collections import defaultdict inpl = lambda: list(map(int, input().split())) N = int(eval(input())) xy = [] field = defaultdict(int) for _ in range(N): x, y = inpl() xy.append((x, y)) field[(x, y)] = 1 xy.sort() pq = set() for i in range(N): for j in range(i + 1, N): x1, y1 = xy[i] x2, y2 = xy[j] p, q = x2 - x1, y2 - y1 pq.add((p, q)) ans = N for p, q in pq: removed = defaultdict(int) cost = 0 for x, y in xy: if removed[(x, y)]: continue else: removed[(x, y)] = 1 cost += 1 while True: x += p y += q if field[(x, y)]: removed[(x, y)] = 1 else: break if cost < ans: ans = cost print(ans)
from collections import defaultdict inpl = lambda: list(map(int, input().split())) N = int(eval(input())) xy = [] for _ in range(N): x, y = inpl() xy.append((x, y)) xy.sort() edges = defaultdict(int) edges[(0, 0)] = 0 for i in range(N): for j in range(i + 1, N): x1, y1 = xy[i] x2, y2 = xy[j] p, q = x2 - x1, y2 - y1 edges[(p, q)] += 1 print((N - max(edges.values())))
false
51.219512
[ "-field = defaultdict(int)", "- field[(x, y)] = 1", "-pq = set()", "+edges = defaultdict(int)", "+edges[(0, 0)] = 0", "- pq.add((p, q))", "-ans = N", "-for p, q in pq:", "- removed = defaultdict(int)", "- cost = 0", "- for x, y in xy:", "- if removed[(x, y)]:", "- continue", "- else:", "- removed[(x, y)] = 1", "- cost += 1", "- while True:", "- x += p", "- y += q", "- if field[(x, y)]:", "- removed[(x, y)] = 1", "- else:", "- break", "- if cost < ans:", "- ans = cost", "-print(ans)", "+ edges[(p, q)] += 1", "+print((N - max(edges.values())))" ]
false
0.038069
0.038512
0.98848
[ "s205780976", "s272564758" ]
u088552457
p02597
python
s532938722
s465731248
81
55
68,708
12,568
Accepted
Accepted
32.1
# import sys # input = sys.stdin.readline # import re import collections def main(): n = int(eval(input())) s = eval(input()) sc = collections.Counter(s) # 半分ずつの場合 if sc['W'] == sc['R']: # 右側のRをカウント print((s[n//2:].count('R'))) exit() print((s[:sc['R']].count('W'))) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == '__main__': main()
# import sys # input = sys.stdin.readline import collections def main(): n = int(eval(input())) s = eval(input()) a_list = [] for i in range(n): if s[i] == "W": a_list.append(0) else: a_list.append(1) r_count = sum(a_list) print((r_count - sum(a_list[0:r_count]))) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
28
27
498
512
# import sys # input = sys.stdin.readline # import re import collections def main(): n = int(eval(input())) s = eval(input()) sc = collections.Counter(s) # 半分ずつの場合 if sc["W"] == sc["R"]: # 右側のRをカウント print((s[n // 2 :].count("R"))) exit() print((s[: sc["R"]].count("W"))) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
# import sys # input = sys.stdin.readline import collections def main(): n = int(eval(input())) s = eval(input()) a_list = [] for i in range(n): if s[i] == "W": a_list.append(0) else: a_list.append(1) r_count = sum(a_list) print((r_count - sum(a_list[0:r_count]))) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
false
3.571429
[ "-# import re", "- sc = collections.Counter(s)", "- # 半分ずつの場合", "- if sc[\"W\"] == sc[\"R\"]:", "- # 右側のRをカウント", "- print((s[n // 2 :].count(\"R\")))", "- exit()", "- print((s[: sc[\"R\"]].count(\"W\")))", "+ a_list = []", "+ for i in range(n):", "+ if s[i] == \"W\":", "+ a_list.append(0)", "+ else:", "+ a_list.append(1)", "+ r_count = sum(a_list)", "+ print((r_count - sum(a_list[0:r_count])))" ]
false
0.036911
0.052517
0.702837
[ "s532938722", "s465731248" ]
u153499445
p02689
python
s079690298
s149690181
417
372
32,972
29,940
Accepted
Accepted
10.79
n,m=[int(x) for x in input().split()] h=[int(x) for x in input().split()] road=[[]*1 for i in range(n)] for i in range(m): a=[int(x) for x in input().split()] road[a[0]-1].append(a[1]-1) road[a[1]-1].append(a[0]-1) good=[] for i in range(n): if road[i]==[]: good.append(i) else: check=[] for j in road[i]: if h[i]<=h[j]: check.append(False) if check==[]: good.append(i) print((len(good)))
n,m=[int(x) for x in input().split()] h=[int(x) for x in input().split()] t=[[]for i in range(n)] ans=0 for i in range(m): a,b=[int(x) for x in input().split()] t[a-1].append(b-1) t[b-1].append(a-1) for i in range(n): if t[i]==[]: ans+=1 else: c=[] for j in t[i]: if h[i]<=h[j]: c.append(False) if c==[]: ans+=1 print(ans)
19
19
450
432
n, m = [int(x) for x in input().split()] h = [int(x) for x in input().split()] road = [[] * 1 for i in range(n)] for i in range(m): a = [int(x) for x in input().split()] road[a[0] - 1].append(a[1] - 1) road[a[1] - 1].append(a[0] - 1) good = [] for i in range(n): if road[i] == []: good.append(i) else: check = [] for j in road[i]: if h[i] <= h[j]: check.append(False) if check == []: good.append(i) print((len(good)))
n, m = [int(x) for x in input().split()] h = [int(x) for x in input().split()] t = [[] for i in range(n)] ans = 0 for i in range(m): a, b = [int(x) for x in input().split()] t[a - 1].append(b - 1) t[b - 1].append(a - 1) for i in range(n): if t[i] == []: ans += 1 else: c = [] for j in t[i]: if h[i] <= h[j]: c.append(False) if c == []: ans += 1 print(ans)
false
0
[ "-road = [[] * 1 for i in range(n)]", "+t = [[] for i in range(n)]", "+ans = 0", "- a = [int(x) for x in input().split()]", "- road[a[0] - 1].append(a[1] - 1)", "- road[a[1] - 1].append(a[0] - 1)", "-good = []", "+ a, b = [int(x) for x in input().split()]", "+ t[a - 1].append(b - 1)", "+ t[b - 1].append(a - 1)", "- if road[i] == []:", "- good.append(i)", "+ if t[i] == []:", "+ ans += 1", "- check = []", "- for j in road[i]:", "+ c = []", "+ for j in t[i]:", "- check.append(False)", "- if check == []:", "- good.append(i)", "-print((len(good)))", "+ c.append(False)", "+ if c == []:", "+ ans += 1", "+print(ans)" ]
false
0.035201
0.035737
0.985006
[ "s079690298", "s149690181" ]
u546285759
p00478
python
s938123939
s602167198
30
20
7,640
7,640
Accepted
Accepted
33.33
s=eval(input()) print((sum(1 for _ in range(int(eval(input())))if s in 2*eval(input()))))
s=eval(input()) print((sum(s in 2*eval(input())for _ in range(int(eval(input()))))))
2
2
70
65
s = eval(input()) print((sum(1 for _ in range(int(eval(input()))) if s in 2 * eval(input()))))
s = eval(input()) print((sum(s in 2 * eval(input()) for _ in range(int(eval(input()))))))
false
0
[ "-print((sum(1 for _ in range(int(eval(input()))) if s in 2 * eval(input()))))", "+print((sum(s in 2 * eval(input()) for _ in range(int(eval(input()))))))" ]
false
0.040484
0.040683
0.995112
[ "s938123939", "s602167198" ]
u282228874
p03014
python
s509760027
s605921657
1,467
915
244,872
123,096
Accepted
Accepted
37.63
H,W = list(map(int,input().split())) S = [list(eval(input())) for i in range(H)] dpyoko = [[1]*(W) for i in range(H)] for j in range(W): for i in range(H): if S[i][j] == '#': dpyoko[i][j] = 0 else: if j != 0: dpyoko[i][j] += dpyoko[i][j-1] for j in range(W-1,-1,-1): for i in range(H): if dpyoko[i][j] == 0: continue if j == W-1: continue dpyoko[i][j] = max(dpyoko[i][j],dpyoko[i][j+1]) dptate = [[1]*(W) for i in range(H)] for i in range(H): for j in range(W): if S[i][j] == '#': dptate[i][j] = 0 else: if i != 0: dptate[i][j] += dptate[i-1][j] for i in range(H-1,-1,-1): for j in range(W): if dptate[i][j] == 0: continue if i == H-1: continue dptate[i][j] = max(dptate[i][j],dptate[i+1][j]) res = 0 for i in range(H): for j in range(W): res = max(res,dptate[i][j]+dpyoko[i][j]-1) print(res)
h,w = list(map(int,input().split())) S = [eval(input()) for i in range(h)] yoko = [[1]*w for _ in range(h)] tate = [[1]*w for _ in range(h)] for i in range(h): for j in range(w): if S[i][j] == '#': yoko[i][j] = 0 else: if j != 0: yoko[i][j] += yoko[i][j-1] for i in range(h): for j in range(w-1,-1,-1): if yoko[i][j] == 0: continue else: if j != w-1: yoko[i][j] = max(yoko[i][j],yoko[i][j+1]) for j in range(w): for i in range(h): if S[i][j] == '#': tate[i][j] = 0 else: if i != 0: tate[i][j] += tate[i-1][j] for j in range(w): for i in range(h-1,-1,-1): if tate[i][j] == 0: continue else: if i != h-1: tate[i][j] = max(tate[i][j],tate[i+1][j]) res = 0 for i in range(h): for j in range(w): res = max(res,tate[i][j]+yoko[i][j]-1) print(res)
37
37
1,060
1,016
H, W = list(map(int, input().split())) S = [list(eval(input())) for i in range(H)] dpyoko = [[1] * (W) for i in range(H)] for j in range(W): for i in range(H): if S[i][j] == "#": dpyoko[i][j] = 0 else: if j != 0: dpyoko[i][j] += dpyoko[i][j - 1] for j in range(W - 1, -1, -1): for i in range(H): if dpyoko[i][j] == 0: continue if j == W - 1: continue dpyoko[i][j] = max(dpyoko[i][j], dpyoko[i][j + 1]) dptate = [[1] * (W) for i in range(H)] for i in range(H): for j in range(W): if S[i][j] == "#": dptate[i][j] = 0 else: if i != 0: dptate[i][j] += dptate[i - 1][j] for i in range(H - 1, -1, -1): for j in range(W): if dptate[i][j] == 0: continue if i == H - 1: continue dptate[i][j] = max(dptate[i][j], dptate[i + 1][j]) res = 0 for i in range(H): for j in range(W): res = max(res, dptate[i][j] + dpyoko[i][j] - 1) print(res)
h, w = list(map(int, input().split())) S = [eval(input()) for i in range(h)] yoko = [[1] * w for _ in range(h)] tate = [[1] * w for _ in range(h)] for i in range(h): for j in range(w): if S[i][j] == "#": yoko[i][j] = 0 else: if j != 0: yoko[i][j] += yoko[i][j - 1] for i in range(h): for j in range(w - 1, -1, -1): if yoko[i][j] == 0: continue else: if j != w - 1: yoko[i][j] = max(yoko[i][j], yoko[i][j + 1]) for j in range(w): for i in range(h): if S[i][j] == "#": tate[i][j] = 0 else: if i != 0: tate[i][j] += tate[i - 1][j] for j in range(w): for i in range(h - 1, -1, -1): if tate[i][j] == 0: continue else: if i != h - 1: tate[i][j] = max(tate[i][j], tate[i + 1][j]) res = 0 for i in range(h): for j in range(w): res = max(res, tate[i][j] + yoko[i][j] - 1) print(res)
false
0
[ "-H, W = list(map(int, input().split()))", "-S = [list(eval(input())) for i in range(H)]", "-dpyoko = [[1] * (W) for i in range(H)]", "-for j in range(W):", "- for i in range(H):", "+h, w = list(map(int, input().split()))", "+S = [eval(input()) for i in range(h)]", "+yoko = [[1] * w for _ in range(h)]", "+tate = [[1] * w for _ in range(h)]", "+for i in range(h):", "+ for j in range(w):", "- dpyoko[i][j] = 0", "+ yoko[i][j] = 0", "- dpyoko[i][j] += dpyoko[i][j - 1]", "-for j in range(W - 1, -1, -1):", "- for i in range(H):", "- if dpyoko[i][j] == 0:", "+ yoko[i][j] += yoko[i][j - 1]", "+for i in range(h):", "+ for j in range(w - 1, -1, -1):", "+ if yoko[i][j] == 0:", "- if j == W - 1:", "- continue", "- dpyoko[i][j] = max(dpyoko[i][j], dpyoko[i][j + 1])", "-dptate = [[1] * (W) for i in range(H)]", "-for i in range(H):", "- for j in range(W):", "+ else:", "+ if j != w - 1:", "+ yoko[i][j] = max(yoko[i][j], yoko[i][j + 1])", "+for j in range(w):", "+ for i in range(h):", "- dptate[i][j] = 0", "+ tate[i][j] = 0", "- dptate[i][j] += dptate[i - 1][j]", "-for i in range(H - 1, -1, -1):", "- for j in range(W):", "- if dptate[i][j] == 0:", "+ tate[i][j] += tate[i - 1][j]", "+for j in range(w):", "+ for i in range(h - 1, -1, -1):", "+ if tate[i][j] == 0:", "- if i == H - 1:", "- continue", "- dptate[i][j] = max(dptate[i][j], dptate[i + 1][j])", "+ else:", "+ if i != h - 1:", "+ tate[i][j] = max(tate[i][j], tate[i + 1][j])", "-for i in range(H):", "- for j in range(W):", "- res = max(res, dptate[i][j] + dpyoko[i][j] - 1)", "+for i in range(h):", "+ for j in range(w):", "+ res = max(res, tate[i][j] + yoko[i][j] - 1)" ]
false
0.035652
0.05197
0.686018
[ "s509760027", "s605921657" ]
u411353821
p02712
python
s382061220
s790727679
157
68
9,180
72,704
Accepted
Accepted
56.69
def main(): n = int(eval(input())) s = 0 for i in range(1, n+1): if i % 3 == 0 and i % 5 == 0: pass elif i%3 == 0: pass elif i%5 == 0: pass else: s += i print(s) if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = 0 for i in range(1, n+1): if not (i % 3 == 0 or i % 5 == 0): s += i print(s) if __name__ == "__main__": main()
16
11
306
196
def main(): n = int(eval(input())) s = 0 for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: s += i print(s) if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = 0 for i in range(1, n + 1): if not (i % 3 == 0 or i % 5 == 0): s += i print(s) if __name__ == "__main__": main()
false
31.25
[ "- if i % 3 == 0 and i % 5 == 0:", "- pass", "- elif i % 3 == 0:", "- pass", "- elif i % 5 == 0:", "- pass", "- else:", "+ if not (i % 3 == 0 or i % 5 == 0):" ]
false
0.101917
0.083609
1.218975
[ "s382061220", "s790727679" ]
u204800924
p03448
python
s322590124
s705747558
50
30
2,940
9,188
Accepted
Accepted
40
A, B, C, X = [int(eval(input())) for _ in range(4)] count = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if 500*a + 100*b + 50*c == X: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) a = min(x//500, a)+1 b = min(x//100, b)+1 c = min(x//50, c) cnt = 0 for i in range(a): for j in range(b): now = x-500*i-100*j if now>=0 and now//50 <= c: cnt +=1 print(cnt)
10
18
224
277
A, B, C, X = [int(eval(input())) for _ in range(4)] count = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) a = min(x // 500, a) + 1 b = min(x // 100, b) + 1 c = min(x // 50, c) cnt = 0 for i in range(a): for j in range(b): now = x - 500 * i - 100 * j if now >= 0 and now // 50 <= c: cnt += 1 print(cnt)
false
44.444444
[ "-A, B, C, X = [int(eval(input())) for _ in range(4)]", "-count = 0", "-for a in range(A + 1):", "- for b in range(B + 1):", "- for c in range(C + 1):", "- if 500 * a + 100 * b + 50 * c == X:", "- count += 1", "-print(count)", "+a = int(eval(input()))", "+b = int(eval(input()))", "+c = int(eval(input()))", "+x = int(eval(input()))", "+a = min(x // 500, a) + 1", "+b = min(x // 100, b) + 1", "+c = min(x // 50, c)", "+cnt = 0", "+for i in range(a):", "+ for j in range(b):", "+ now = x - 500 * i - 100 * j", "+ if now >= 0 and now // 50 <= c:", "+ cnt += 1", "+print(cnt)" ]
false
0.082743
0.037665
2.196787
[ "s322590124", "s705747558" ]
u285891772
p03077
python
s912359164
s348217532
51
39
5,712
5,200
Accepted
Accepted
23.53
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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 #from decimal import * N = INT() L = [INT() for _ in range(5)] C = min(L) l = L.index(C) r = 4 - l print((-(-N//C)+l+r))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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 #from decimal import * N, A, B, C, D, E = [INT() for _ in range(6)] print((-(-N//min(A, B, C, D, E))+4))
29
24
1,001
978
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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 # from decimal import * N = INT() L = [INT() for _ in range(5)] C = min(L) l = L.index(C) r = 4 - l print((-(-N // C) + l + r))
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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 # from decimal import * N, A, B, C, D, E = [INT() for _ in range(6)] print((-(-N // min(A, B, C, D, E)) + 4))
false
17.241379
[ "-N = INT()", "-L = [INT() for _ in range(5)]", "-C = min(L)", "-l = L.index(C)", "-r = 4 - l", "-print((-(-N // C) + l + r))", "+N, A, B, C, D, E = [INT() for _ in range(6)]", "+print((-(-N // min(A, B, C, D, E)) + 4))" ]
false
0.063324
0.103491
0.611878
[ "s912359164", "s348217532" ]
u814986259
p03457
python
s351008808
s594753935
397
172
3,064
3,060
Accepted
Accepted
56.68
N=int(eval(input())) pos=[0,0] now=0 flag=True for i in range(N): t,x,y=list(map(int,input().split())) d = abs(x-pos[0])+abs(y-pos[1]) if d>t-now: flag=False break else: if d%2==(t-now)%2: now=t pos[0],pos[1]=x,y else: flag=False break if flag: print("Yes") else: print("No")
def main(): import sys input = sys.stdin.readline N = int(eval(input())) prev = 0 x = 0 y = 0 for i in range(N): a, b, c = list(map(int, input().split())) dis = abs(b - x) + abs(c - y) diff = a - prev if diff >= dis and diff % 2 == dis % 2: prev = a x = b y = c else: print("No") exit(0) print("Yes") main()
21
26
335
459
N = int(eval(input())) pos = [0, 0] now = 0 flag = True for i in range(N): t, x, y = list(map(int, input().split())) d = abs(x - pos[0]) + abs(y - pos[1]) if d > t - now: flag = False break else: if d % 2 == (t - now) % 2: now = t pos[0], pos[1] = x, y else: flag = False break if flag: print("Yes") else: print("No")
def main(): import sys input = sys.stdin.readline N = int(eval(input())) prev = 0 x = 0 y = 0 for i in range(N): a, b, c = list(map(int, input().split())) dis = abs(b - x) + abs(c - y) diff = a - prev if diff >= dis and diff % 2 == dis % 2: prev = a x = b y = c else: print("No") exit(0) print("Yes") main()
false
19.230769
[ "-N = int(eval(input()))", "-pos = [0, 0]", "-now = 0", "-flag = True", "-for i in range(N):", "- t, x, y = list(map(int, input().split()))", "- d = abs(x - pos[0]) + abs(y - pos[1])", "- if d > t - now:", "- flag = False", "- break", "- else:", "- if d % 2 == (t - now) % 2:", "- now = t", "- pos[0], pos[1] = x, y", "+def main():", "+ import sys", "+", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ prev = 0", "+ x = 0", "+ y = 0", "+ for i in range(N):", "+ a, b, c = list(map(int, input().split()))", "+ dis = abs(b - x) + abs(c - y)", "+ diff = a - prev", "+ if diff >= dis and diff % 2 == dis % 2:", "+ prev = a", "+ x = b", "+ y = c", "- flag = False", "- break", "-if flag:", "+ print(\"No\")", "+ exit(0)", "-else:", "- print(\"No\")", "+", "+", "+main()" ]
false
0.03227
0.036532
0.88335
[ "s351008808", "s594753935" ]
u562935282
p03240
python
s595592091
s723146934
590
102
3,064
3,064
Accepted
Accepted
82.71
N = int(eval(input())) XYHs = [list(map(int, input().split())) for _ in range(N)] for Cx in range(100 + 1): for Cy in range(100 + 1): flg = True H = -1 max_H = float('inf') for x, y, h in XYHs: CF = abs(x - Cx) + abs(y - Cy) if h == 0: max_H = min(max_H, CF) else: t = h + CF if H == -1: H = t elif H != t: flg = False break if flg and H <= max_H: print((Cx, Cy, H)) exit()
N = int(eval(input())) x = [] y = [] h = [] for _ in range(N): xx, yy, hh = list(map(int, input().split())) x.append(xx) y.append(yy) h.append(hh) V_MAX = 100 for cx in range(V_MAX + 1): for cy in range(V_MAX + 1): # 頂上がどのくらいの高さであって欲しいか # -1: 未定, 0以上は確定しているとき # -2: 不可能だと分かったとき needH = - 1 for i in range(N): if h[i] > 0: dist = abs(x[i] - cx) + abs(y[i] - cy) # この頂点から見て, 頂上がcx, cyのときに, どの位の高さがあって欲しいか tmp = h[i] + dist if needH == -1: needH = tmp else: if needH != tmp: needH = -2 break if needH == -2: continue # ダメだったら別の場所を探す for i in range(N): if h[i] == 0: dist = abs(x[i] - cx) + abs(y[i] - cy) if needH > dist: needH = - 2 break if needH == -2: continue # ダメだったら別の場所を探す print((cx, cy, needH))
22
46
615
1,119
N = int(eval(input())) XYHs = [list(map(int, input().split())) for _ in range(N)] for Cx in range(100 + 1): for Cy in range(100 + 1): flg = True H = -1 max_H = float("inf") for x, y, h in XYHs: CF = abs(x - Cx) + abs(y - Cy) if h == 0: max_H = min(max_H, CF) else: t = h + CF if H == -1: H = t elif H != t: flg = False break if flg and H <= max_H: print((Cx, Cy, H)) exit()
N = int(eval(input())) x = [] y = [] h = [] for _ in range(N): xx, yy, hh = list(map(int, input().split())) x.append(xx) y.append(yy) h.append(hh) V_MAX = 100 for cx in range(V_MAX + 1): for cy in range(V_MAX + 1): # 頂上がどのくらいの高さであって欲しいか # -1: 未定, 0以上は確定しているとき # -2: 不可能だと分かったとき needH = -1 for i in range(N): if h[i] > 0: dist = abs(x[i] - cx) + abs(y[i] - cy) # この頂点から見て, 頂上がcx, cyのときに, どの位の高さがあって欲しいか tmp = h[i] + dist if needH == -1: needH = tmp else: if needH != tmp: needH = -2 break if needH == -2: continue # ダメだったら別の場所を探す for i in range(N): if h[i] == 0: dist = abs(x[i] - cx) + abs(y[i] - cy) if needH > dist: needH = -2 break if needH == -2: continue # ダメだったら別の場所を探す print((cx, cy, needH))
false
52.173913
[ "-XYHs = [list(map(int, input().split())) for _ in range(N)]", "-for Cx in range(100 + 1):", "- for Cy in range(100 + 1):", "- flg = True", "- H = -1", "- max_H = float(\"inf\")", "- for x, y, h in XYHs:", "- CF = abs(x - Cx) + abs(y - Cy)", "- if h == 0:", "- max_H = min(max_H, CF)", "- else:", "- t = h + CF", "- if H == -1:", "- H = t", "- elif H != t:", "- flg = False", "+x = []", "+y = []", "+h = []", "+for _ in range(N):", "+ xx, yy, hh = list(map(int, input().split()))", "+ x.append(xx)", "+ y.append(yy)", "+ h.append(hh)", "+V_MAX = 100", "+for cx in range(V_MAX + 1):", "+ for cy in range(V_MAX + 1):", "+ # 頂上がどのくらいの高さであって欲しいか", "+ # -1: 未定, 0以上は確定しているとき", "+ # -2: 不可能だと分かったとき", "+ needH = -1", "+ for i in range(N):", "+ if h[i] > 0:", "+ dist = abs(x[i] - cx) + abs(y[i] - cy)", "+ # この頂点から見て, 頂上がcx, cyのときに, どの位の高さがあって欲しいか", "+ tmp = h[i] + dist", "+ if needH == -1:", "+ needH = tmp", "+ else:", "+ if needH != tmp:", "+ needH = -2", "+ break", "+ if needH == -2:", "+ continue # ダメだったら別の場所を探す", "+ for i in range(N):", "+ if h[i] == 0:", "+ dist = abs(x[i] - cx) + abs(y[i] - cy)", "+ if needH > dist:", "+ needH = -2", "- if flg and H <= max_H:", "- print((Cx, Cy, H))", "- exit()", "+ if needH == -2:", "+ continue # ダメだったら別の場所を探す", "+ print((cx, cy, needH))" ]
false
0.038311
0.11814
0.324284
[ "s595592091", "s723146934" ]
u545368057
p03329
python
s727963758
s935829182
621
199
54,436
44,912
Accepted
Accepted
67.95
N = int(eval(input())) n6 = 1 n9 = 1 li = [] while 9**n9 <= N: li.append(9**n9) n9 += 1 while 6**n6 <= N: li.append(6**n6) n6 += 1 li.sort() INF = 10**10 # 1円の場合はね dp = [[i for i in range(N+1)] for i in range(len(li) + 1)] dp = [i for i in range(N+1)] for i,l in enumerate(li): for j in range(N+1): if j+l > N : continue dp[j+l] = min(dp[j+l], dp[j]+1) print((dp[N]))
N = int(eval(input())) array = [] cnt6 = 0 while 6**cnt6 <= N: array.append(6**cnt6) cnt6 += 1 cnt9 = 0 while 9**cnt9 <= N: array.append(9**cnt9) cnt9 += 1 a = sorted(list(set(array))) # 最小 dp = [i for i in range(N+1)] # print(a) n = 6 for n in a: for i in range(N+1): if i+n <= N: dp[i+n] = min(dp[i]+1, dp[i+n]) print((dp[N]))
23
23
421
390
N = int(eval(input())) n6 = 1 n9 = 1 li = [] while 9**n9 <= N: li.append(9**n9) n9 += 1 while 6**n6 <= N: li.append(6**n6) n6 += 1 li.sort() INF = 10**10 # 1円の場合はね dp = [[i for i in range(N + 1)] for i in range(len(li) + 1)] dp = [i for i in range(N + 1)] for i, l in enumerate(li): for j in range(N + 1): if j + l > N: continue dp[j + l] = min(dp[j + l], dp[j] + 1) print((dp[N]))
N = int(eval(input())) array = [] cnt6 = 0 while 6**cnt6 <= N: array.append(6**cnt6) cnt6 += 1 cnt9 = 0 while 9**cnt9 <= N: array.append(9**cnt9) cnt9 += 1 a = sorted(list(set(array))) # 最小 dp = [i for i in range(N + 1)] # print(a) n = 6 for n in a: for i in range(N + 1): if i + n <= N: dp[i + n] = min(dp[i] + 1, dp[i + n]) print((dp[N]))
false
0
[ "-n6 = 1", "-n9 = 1", "-li = []", "-while 9**n9 <= N:", "- li.append(9**n9)", "- n9 += 1", "-while 6**n6 <= N:", "- li.append(6**n6)", "- n6 += 1", "-li.sort()", "-INF = 10**10", "-# 1円の場合はね", "-dp = [[i for i in range(N + 1)] for i in range(len(li) + 1)]", "+array = []", "+cnt6 = 0", "+while 6**cnt6 <= N:", "+ array.append(6**cnt6)", "+ cnt6 += 1", "+cnt9 = 0", "+while 9**cnt9 <= N:", "+ array.append(9**cnt9)", "+ cnt9 += 1", "+a = sorted(list(set(array)))", "+# 最小", "-for i, l in enumerate(li):", "- for j in range(N + 1):", "- if j + l > N:", "- continue", "- dp[j + l] = min(dp[j + l], dp[j] + 1)", "+# print(a)", "+n = 6", "+for n in a:", "+ for i in range(N + 1):", "+ if i + n <= N:", "+ dp[i + n] = min(dp[i] + 1, dp[i + n])" ]
false
0.182874
0.179943
1.016289
[ "s727963758", "s935829182" ]
u608088992
p03201
python
s898179877
s584709635
1,537
746
33,200
33,908
Accepted
Accepted
51.46
import sys F = sys.stdin N = int(F.readline().strip("\n")) A = list(map(int, F.readline().strip("\n").split())) A.sort() pair_sum = 0 A_dict = dict() for a in A: if a not in A_dict: A_dict[a] = 1 else: A_dict[a] += 1 for i in reversed(list(range(1, N))): if A_dict[A[i]] > 0: nowA = A[i] temp_a = A[i] k = 0 while temp_a > 0: temp_a //= 2 k += 1 opposite = 2 ** k - nowA if opposite in A_dict: if opposite == nowA and A_dict[opposite] > 1: pair_sum += 1 A_dict[opposite] -= 2 elif opposite != nowA and A_dict[opposite] > 0: pair_sum += 1 A_dict[opposite] -= 1 A_dict[nowA] -= 1 print(pair_sum)
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) A = [int(a) for a in input().split()] A.sort() nDict = dict() for i, a in enumerate(A): if a in nDict: nDict[a] += 1 else: nDict[a] = 1 count = 0 for i in reversed(list(range(N))): if nDict[A[i]] == 0: continue k = 1 while k <= A[i]: k <<= 1 if k - A[i] in nDict: if k - A[i] == A[i] and nDict[k - A[i]] > 1: count += 1 nDict[A[i]] -= 2 elif k - A[i] != A[i] and nDict[k - A[i]] > 0: count += 1 nDict[A[i]] -= 1 nDict[k - A[i]] -= 1 print(count) return 0 if __name__ == "__main__": solve()
31
32
808
791
import sys F = sys.stdin N = int(F.readline().strip("\n")) A = list(map(int, F.readline().strip("\n").split())) A.sort() pair_sum = 0 A_dict = dict() for a in A: if a not in A_dict: A_dict[a] = 1 else: A_dict[a] += 1 for i in reversed(list(range(1, N))): if A_dict[A[i]] > 0: nowA = A[i] temp_a = A[i] k = 0 while temp_a > 0: temp_a //= 2 k += 1 opposite = 2**k - nowA if opposite in A_dict: if opposite == nowA and A_dict[opposite] > 1: pair_sum += 1 A_dict[opposite] -= 2 elif opposite != nowA and A_dict[opposite] > 0: pair_sum += 1 A_dict[opposite] -= 1 A_dict[nowA] -= 1 print(pair_sum)
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) A = [int(a) for a in input().split()] A.sort() nDict = dict() for i, a in enumerate(A): if a in nDict: nDict[a] += 1 else: nDict[a] = 1 count = 0 for i in reversed(list(range(N))): if nDict[A[i]] == 0: continue k = 1 while k <= A[i]: k <<= 1 if k - A[i] in nDict: if k - A[i] == A[i] and nDict[k - A[i]] > 1: count += 1 nDict[A[i]] -= 2 elif k - A[i] != A[i] and nDict[k - A[i]] > 0: count += 1 nDict[A[i]] -= 1 nDict[k - A[i]] -= 1 print(count) return 0 if __name__ == "__main__": solve()
false
3.125
[ "-F = sys.stdin", "-N = int(F.readline().strip(\"\\n\"))", "-A = list(map(int, F.readline().strip(\"\\n\").split()))", "-A.sort()", "-pair_sum = 0", "-A_dict = dict()", "-for a in A:", "- if a not in A_dict:", "- A_dict[a] = 1", "- else:", "- A_dict[a] += 1", "-for i in reversed(list(range(1, N))):", "- if A_dict[A[i]] > 0:", "- nowA = A[i]", "- temp_a = A[i]", "- k = 0", "- while temp_a > 0:", "- temp_a //= 2", "- k += 1", "- opposite = 2**k - nowA", "- if opposite in A_dict:", "- if opposite == nowA and A_dict[opposite] > 1:", "- pair_sum += 1", "- A_dict[opposite] -= 2", "- elif opposite != nowA and A_dict[opposite] > 0:", "- pair_sum += 1", "- A_dict[opposite] -= 1", "- A_dict[nowA] -= 1", "-print(pair_sum)", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ A = [int(a) for a in input().split()]", "+ A.sort()", "+ nDict = dict()", "+ for i, a in enumerate(A):", "+ if a in nDict:", "+ nDict[a] += 1", "+ else:", "+ nDict[a] = 1", "+ count = 0", "+ for i in reversed(list(range(N))):", "+ if nDict[A[i]] == 0:", "+ continue", "+ k = 1", "+ while k <= A[i]:", "+ k <<= 1", "+ if k - A[i] in nDict:", "+ if k - A[i] == A[i] and nDict[k - A[i]] > 1:", "+ count += 1", "+ nDict[A[i]] -= 2", "+ elif k - A[i] != A[i] and nDict[k - A[i]] > 0:", "+ count += 1", "+ nDict[A[i]] -= 1", "+ nDict[k - A[i]] -= 1", "+ print(count)", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.040465
0.041432
0.976665
[ "s898179877", "s584709635" ]
u371763408
p03805
python
s749063191
s768296519
31
27
3,064
3,316
Accepted
Accepted
12.9
n,m=list(map(int,input().split())) edges=[[] for i in range(n)] for i in range(m): s,t = list(map(int,input().split())) edges[s-1].append(t-1) edges[t-1].append(s-1) cnt =[0] def dfs(V,s): V[s]=1 if sum(V)==n: cnt[0]+=1 else: for adj in edges[s]: if V[adj] == 0: dfs(V[:adj] + [1] + V[adj + 1:], adj) dfs([0] * n, 0) print((cnt[0]))
n,m=list(map(int,input().split())) edges=[[] for i in range(n)] for i in range(m): s,t = list(map(int,input().split())) edges[s-1].append(t-1) edges[t-1].append(s-1) cnt =0 V=[0]*n def dfs(V,s): global cnt V=V[:] V[s]=1 if sum(V)==n: cnt+=1 else: for v in edges[s]: if V[v]==0: dfs(V,v) # print(V) dfs(V,0) print(cnt)
22
26
379
375
n, m = list(map(int, input().split())) edges = [[] for i in range(n)] for i in range(m): s, t = list(map(int, input().split())) edges[s - 1].append(t - 1) edges[t - 1].append(s - 1) cnt = [0] def dfs(V, s): V[s] = 1 if sum(V) == n: cnt[0] += 1 else: for adj in edges[s]: if V[adj] == 0: dfs(V[:adj] + [1] + V[adj + 1 :], adj) dfs([0] * n, 0) print((cnt[0]))
n, m = list(map(int, input().split())) edges = [[] for i in range(n)] for i in range(m): s, t = list(map(int, input().split())) edges[s - 1].append(t - 1) edges[t - 1].append(s - 1) cnt = 0 V = [0] * n def dfs(V, s): global cnt V = V[:] V[s] = 1 if sum(V) == n: cnt += 1 else: for v in edges[s]: if V[v] == 0: dfs(V, v) # print(V) dfs(V, 0) print(cnt)
false
15.384615
[ "-cnt = [0]", "+cnt = 0", "+V = [0] * n", "+ global cnt", "+ V = V[:]", "- cnt[0] += 1", "+ cnt += 1", "- for adj in edges[s]:", "- if V[adj] == 0:", "- dfs(V[:adj] + [1] + V[adj + 1 :], adj)", "+ for v in edges[s]:", "+ if V[v] == 0:", "+ dfs(V, v)", "+ # print(V)", "-dfs([0] * n, 0)", "-print((cnt[0]))", "+dfs(V, 0)", "+print(cnt)" ]
false
0.164283
0.048238
3.405682
[ "s749063191", "s768296519" ]
u017810624
p02863
python
s167825019
s950523644
1,615
515
268,552
121,304
Accepted
Accepted
68.11
import sys input=sys.stdin.readline def knapsack(N,W,weight,value): dp=[[float('inf') for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i]=0 for i in range(N): for w in range(W+1): if weight[i]<=w: if dp[i][w-weight[i]]+value[i]>dp[i][w]: dp[i+1][w]=dp[i][w-weight[i]]+value[i] else: dp[i+1][w]=dp[i][w] else: dp[i+1][w]=dp[i][w] return dp n,t=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] l.sort() a=[];b=[] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp=knapsack(n,t-1,a,b) ans=[] for i in range(n): if i!=n: ans.append(dp[i][t-1]+b[i]) else: ans.append(dp[n][t]) print((max(ans)))
import sys input=sys.stdin.readline def knapsack(N,W,weight,value): dp=[[999999999999 for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i]=0 for i in range(N): for w in range(W+1): if weight[i]<=w: if dp[i][w-weight[i]]+value[i]>dp[i][w]: dp[i+1][w]=dp[i][w-weight[i]]+value[i] else: dp[i+1][w]=dp[i][w] else: dp[i+1][w]=dp[i][w] return dp n,t=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] l.sort() a=[];b=[] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp=knapsack(n,t-1,a,b) ans=[] for i in range(n): if i!=n: ans.append(dp[i][t-1]+b[i]) else: ans.append(dp[n][t]) print((max(ans)))
33
33
767
767
import sys input = sys.stdin.readline def knapsack(N, W, weight, value): dp = [[float("inf") for i in range(W + 1)] for j in range(N + 1)] for i in range(W + 1): dp[0][i] = 0 for i in range(N): for w in range(W + 1): if weight[i] <= w: if dp[i][w - weight[i]] + value[i] > dp[i][w]: dp[i + 1][w] = dp[i][w - weight[i]] + value[i] else: dp[i + 1][w] = dp[i][w] else: dp[i + 1][w] = dp[i][w] return dp n, t = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(n)] l.sort() a = [] b = [] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp = knapsack(n, t - 1, a, b) ans = [] for i in range(n): if i != n: ans.append(dp[i][t - 1] + b[i]) else: ans.append(dp[n][t]) print((max(ans)))
import sys input = sys.stdin.readline def knapsack(N, W, weight, value): dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)] for i in range(W + 1): dp[0][i] = 0 for i in range(N): for w in range(W + 1): if weight[i] <= w: if dp[i][w - weight[i]] + value[i] > dp[i][w]: dp[i + 1][w] = dp[i][w - weight[i]] + value[i] else: dp[i + 1][w] = dp[i][w] else: dp[i + 1][w] = dp[i][w] return dp n, t = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(n)] l.sort() a = [] b = [] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp = knapsack(n, t - 1, a, b) ans = [] for i in range(n): if i != n: ans.append(dp[i][t - 1] + b[i]) else: ans.append(dp[n][t]) print((max(ans)))
false
0
[ "- dp = [[float(\"inf\") for i in range(W + 1)] for j in range(N + 1)]", "+ dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)]" ]
false
0.038746
0.047645
0.813222
[ "s167825019", "s950523644" ]
u201928947
p02573
python
s200687321
s779875690
270
193
87,084
84,564
Accepted
Accepted
28.52
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N,M = list(map(int,input().split())) uf = UnionFind(N) for i in range(M): A,B = list(map(int,input().split())) uf.union(A-1,B-1) ans = 0 for i in uf.roots(): ans = max(uf.size(i),ans) print(ans)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: li.append(x) x = self.parents[x] for y in li: self.parents[y] = x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N,M = list(map(int,input().split())) uf = UnionFind(N) for i in range(M): A,B = list(map(int,input().split())) uf.union(A-1,B-1) ans = 0 for i in uf.roots(): ans = max(uf.size(i),ans) print(ans)
58
63
1,444
1,564
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N, M = list(map(int, input().split())) uf = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) uf.union(A - 1, B - 1) ans = 0 for i in uf.roots(): ans = max(uf.size(i), ans) print(ans)
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: li.append(x) x = self.parents[x] for y in li: self.parents[y] = x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N, M = list(map(int, input().split())) uf = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) uf.union(A - 1, B - 1) ans = 0 for i in uf.roots(): ans = max(uf.size(i), ans) print(ans)
false
7.936508
[ "- self.parents[x] = self.find(self.parents[x])", "- return self.parents[x]", "+ li = []", "+ while self.parents[x] >= 0:", "+ li.append(x)", "+ x = self.parents[x]", "+ for y in li:", "+ self.parents[y] = x", "+ return x" ]
false
0.04019
0.046297
0.868093
[ "s200687321", "s779875690" ]
u863370423
p04039
python
s325880124
s385762802
67
49
2,940
3,060
Accepted
Accepted
26.87
n,m = input().split() k=int(n) li = list(input().split()) for i in range(k,100000): for e in li: if e in str(i): break else: print(i) break
n, k = list(map(int, input().split())) digits = [0]*10 digits_disliked = list(map(int, input().split())) for i in digits_disliked: digits[i] = 1 for i in range(n, 10**7+1): temp = i flag = True while(temp): rem = temp%10 temp = temp//10 if(digits[rem] != 0): flag = False break if(flag == True): print(i) break
11
23
194
426
n, m = input().split() k = int(n) li = list(input().split()) for i in range(k, 100000): for e in li: if e in str(i): break else: print(i) break
n, k = list(map(int, input().split())) digits = [0] * 10 digits_disliked = list(map(int, input().split())) for i in digits_disliked: digits[i] = 1 for i in range(n, 10**7 + 1): temp = i flag = True while temp: rem = temp % 10 temp = temp // 10 if digits[rem] != 0: flag = False break if flag == True: print(i) break
false
52.173913
[ "-n, m = input().split()", "-k = int(n)", "-li = list(input().split())", "-for i in range(k, 100000):", "- for e in li:", "- if e in str(i):", "+n, k = list(map(int, input().split()))", "+digits = [0] * 10", "+digits_disliked = list(map(int, input().split()))", "+for i in digits_disliked:", "+ digits[i] = 1", "+for i in range(n, 10**7 + 1):", "+ temp = i", "+ flag = True", "+ while temp:", "+ rem = temp % 10", "+ temp = temp // 10", "+ if digits[rem] != 0:", "+ flag = False", "- else:", "+ if flag == True:" ]
false
0.036364
0.096898
0.375277
[ "s325880124", "s385762802" ]
u227082700
p03986
python
s719343219
s429403748
81
55
3,500
9,172
Accepted
Accepted
32.1
x=eval(input());a,l=0,len(x) for i in range(l): if x[l-i-1]=="T":a+=1 else:a=max(0,a-1) print((a*2))
x=eval(input()) s=t=0 for i in x: if i=="S":s+=1 else: if s: s-=1 else: t+=1 print((s+t))
5
10
100
114
x = eval(input()) a, l = 0, len(x) for i in range(l): if x[l - i - 1] == "T": a += 1 else: a = max(0, a - 1) print((a * 2))
x = eval(input()) s = t = 0 for i in x: if i == "S": s += 1 else: if s: s -= 1 else: t += 1 print((s + t))
false
50
[ "-a, l = 0, len(x)", "-for i in range(l):", "- if x[l - i - 1] == \"T\":", "- a += 1", "+s = t = 0", "+for i in x:", "+ if i == \"S\":", "+ s += 1", "- a = max(0, a - 1)", "-print((a * 2))", "+ if s:", "+ s -= 1", "+ else:", "+ t += 1", "+print((s + t))" ]
false
0.036654
0.035603
1.029526
[ "s719343219", "s429403748" ]
u809006576
p03160
python
s519221338
s085145913
98
88
13,928
13,980
Accepted
Accepted
10.2
def helper(h, n): res = [0]*n res[0] = 0 res[1] = abs(h[1]-h[0]) for i in range(2, n): res[i] = min(res[i-1]+abs(h[i]-h[i-1]), res[i-2]+abs(h[i]-h[i-2])) return res[-1] def main(): n = int(eval(input())) h = list(map(int, input().split(" "))) print((helper(h, n))) if __name__ == "__main__": main()
def helper(h, n): prev = 0 curr = abs(h[1]-h[0]) for i in range(2, n): next = min(curr+abs(h[i]-h[i-1]), prev+abs(h[i]-h[i-2])) prev = curr curr = next return curr def main(): n = int(eval(input())) h = list(map(int, input().split(" "))) print((helper(h, n))) if __name__ == "__main__": main()
15
16
350
358
def helper(h, n): res = [0] * n res[0] = 0 res[1] = abs(h[1] - h[0]) for i in range(2, n): res[i] = min( res[i - 1] + abs(h[i] - h[i - 1]), res[i - 2] + abs(h[i] - h[i - 2]) ) return res[-1] def main(): n = int(eval(input())) h = list(map(int, input().split(" "))) print((helper(h, n))) if __name__ == "__main__": main()
def helper(h, n): prev = 0 curr = abs(h[1] - h[0]) for i in range(2, n): next = min(curr + abs(h[i] - h[i - 1]), prev + abs(h[i] - h[i - 2])) prev = curr curr = next return curr def main(): n = int(eval(input())) h = list(map(int, input().split(" "))) print((helper(h, n))) if __name__ == "__main__": main()
false
6.25
[ "- res = [0] * n", "- res[0] = 0", "- res[1] = abs(h[1] - h[0])", "+ prev = 0", "+ curr = abs(h[1] - h[0])", "- res[i] = min(", "- res[i - 1] + abs(h[i] - h[i - 1]), res[i - 2] + abs(h[i] - h[i - 2])", "- )", "- return res[-1]", "+ next = min(curr + abs(h[i] - h[i - 1]), prev + abs(h[i] - h[i - 2]))", "+ prev = curr", "+ curr = next", "+ return curr" ]
false
0.205325
0.138386
1.483711
[ "s519221338", "s085145913" ]
u632360669
p02819
python
s884947873
s730128786
25
23
2,940
2,940
Accepted
Accepted
8
X = int(eval(input())) result = False while result == False: result = True for i in range(2,-(-X//2)+1): if X % i == 0: result = False break else: result = True if not result: X += 1 print(X)
X = int(eval(input()))-1 result = False while not result: result = True X += 1 for i in range(2,X//2+1): if X % i == 0: result = False break print(X)
14
11
236
176
X = int(eval(input())) result = False while result == False: result = True for i in range(2, -(-X // 2) + 1): if X % i == 0: result = False break else: result = True if not result: X += 1 print(X)
X = int(eval(input())) - 1 result = False while not result: result = True X += 1 for i in range(2, X // 2 + 1): if X % i == 0: result = False break print(X)
false
21.428571
[ "-X = int(eval(input()))", "+X = int(eval(input())) - 1", "-while result == False:", "+while not result:", "- for i in range(2, -(-X // 2) + 1):", "+ X += 1", "+ for i in range(2, X // 2 + 1):", "- else:", "- result = True", "- if not result:", "- X += 1" ]
false
0.047145
0.045977
1.025409
[ "s884947873", "s730128786" ]
u349449706
p03380
python
s910514477
s763547321
306
110
85,744
84,232
Accepted
Accepted
64.05
n,*a=list(map(int,open(0).read().split())) m=max(a) b=m//2 o=min(a) for A in a: if abs(A-b)<abs(o-b):o=A print((m,o))
n,a=open(0) *a,=list(map(int,a.split())) m=max(a) print((m,min((abs(m-2*i),i)for i in a)[1]))
7
4
117
89
n, *a = list(map(int, open(0).read().split())) m = max(a) b = m // 2 o = min(a) for A in a: if abs(A - b) < abs(o - b): o = A print((m, o))
n, a = open(0) (*a,) = list(map(int, a.split())) m = max(a) print((m, min((abs(m - 2 * i), i) for i in a)[1]))
false
42.857143
[ "-n, *a = list(map(int, open(0).read().split()))", "+n, a = open(0)", "+(*a,) = list(map(int, a.split()))", "-b = m // 2", "-o = min(a)", "-for A in a:", "- if abs(A - b) < abs(o - b):", "- o = A", "-print((m, o))", "+print((m, min((abs(m - 2 * i), i) for i in a)[1]))" ]
false
0.036214
0.037013
0.978404
[ "s910514477", "s763547321" ]
u678167152
p03610
python
s130738712
s275771326
38
17
3,188
3,188
Accepted
Accepted
55.26
S = eval(input()) ans = '' for i,s in enumerate(S): if i%2==0: ans += s print(ans)
def solve(): S = eval(input()) ans = S[0::2] return ans print((solve()))
6
6
87
86
S = eval(input()) ans = "" for i, s in enumerate(S): if i % 2 == 0: ans += s print(ans)
def solve(): S = eval(input()) ans = S[0::2] return ans print((solve()))
false
0
[ "-S = eval(input())", "-ans = \"\"", "-for i, s in enumerate(S):", "- if i % 2 == 0:", "- ans += s", "-print(ans)", "+def solve():", "+ S = eval(input())", "+ ans = S[0::2]", "+ return ans", "+", "+", "+print((solve()))" ]
false
0.046697
0.046611
1.001843
[ "s130738712", "s275771326" ]
u861141787
p03035
python
s275316697
s930833863
161
17
38,256
2,940
Accepted
Accepted
89.44
A, B = list(map(int, input().split())) if A >= 13: print(B) elif A <= 12 and A >= 6: print((B//2)) else: print((0))
a, b = list(map(int, input().split())) if a >= 13: print(b) elif a <= 5: print((0)) else: print((b//2))
7
8
123
104
A, B = list(map(int, input().split())) if A >= 13: print(B) elif A <= 12 and A >= 6: print((B // 2)) else: print((0))
a, b = list(map(int, input().split())) if a >= 13: print(b) elif a <= 5: print((0)) else: print((b // 2))
false
12.5
[ "-A, B = list(map(int, input().split()))", "-if A >= 13:", "- print(B)", "-elif A <= 12 and A >= 6:", "- print((B // 2))", "+a, b = list(map(int, input().split()))", "+if a >= 13:", "+ print(b)", "+elif a <= 5:", "+ print((0))", "- print((0))", "+ print((b // 2))" ]
false
0.082844
0.042243
1.96112
[ "s275316697", "s930833863" ]
u790012205
p03290
python
s480012487
s004515244
146
46
3,064
3,064
Accepted
Accepted
68.49
D, G = list(map(int, input().split())) pc = [list(map(int, input().split())) for i in range(D)] G /= 100 C = 2e3 N = len(pc) for i in range(2 ** N): p = 0 c = 0 for j in range(N): if i >> j & 1: p += pc[j][0] * (j + 1) + pc[j][1] / 100 c += pc[j][0] if p >= G: C = min(c, C) continue for j in range(N-1, -1, -1): if not i >> j & 1: for k in range(pc[j][0] - 1): p += j + 1 c += 1 if p >= G: break if p >= G: break if p >= G: C = min(c, C) continue print(C)
D, G = list(map(int, input().split())) G = int(G / 100) pc = [list(map(int, input().split())) for _ in range(D)] N = 10 ** 9 for bit in range(2 ** D): S = 0 c = 0 A = True a = -1 for i in range(D - 1, -1, -1): if bit & (1 << i): S += (i + 1) * pc[i][0] + int(pc[i][1] / 100) c += pc[i][0] elif A: a = i A = False if a != -1: for i in range(1, pc[a][0]): if S >= G: break S += a + 1 c += 1 if S >= G: N = min(N, c) print(N)
29
27
675
604
D, G = list(map(int, input().split())) pc = [list(map(int, input().split())) for i in range(D)] G /= 100 C = 2e3 N = len(pc) for i in range(2**N): p = 0 c = 0 for j in range(N): if i >> j & 1: p += pc[j][0] * (j + 1) + pc[j][1] / 100 c += pc[j][0] if p >= G: C = min(c, C) continue for j in range(N - 1, -1, -1): if not i >> j & 1: for k in range(pc[j][0] - 1): p += j + 1 c += 1 if p >= G: break if p >= G: break if p >= G: C = min(c, C) continue print(C)
D, G = list(map(int, input().split())) G = int(G / 100) pc = [list(map(int, input().split())) for _ in range(D)] N = 10**9 for bit in range(2**D): S = 0 c = 0 A = True a = -1 for i in range(D - 1, -1, -1): if bit & (1 << i): S += (i + 1) * pc[i][0] + int(pc[i][1] / 100) c += pc[i][0] elif A: a = i A = False if a != -1: for i in range(1, pc[a][0]): if S >= G: break S += a + 1 c += 1 if S >= G: N = min(N, c) print(N)
false
6.896552
[ "-pc = [list(map(int, input().split())) for i in range(D)]", "-G /= 100", "-C = 2e3", "-N = len(pc)", "-for i in range(2**N):", "- p = 0", "+G = int(G / 100)", "+pc = [list(map(int, input().split())) for _ in range(D)]", "+N = 10**9", "+for bit in range(2**D):", "+ S = 0", "- for j in range(N):", "- if i >> j & 1:", "- p += pc[j][0] * (j + 1) + pc[j][1] / 100", "- c += pc[j][0]", "- if p >= G:", "- C = min(c, C)", "- continue", "- for j in range(N - 1, -1, -1):", "- if not i >> j & 1:", "- for k in range(pc[j][0] - 1):", "- p += j + 1", "- c += 1", "- if p >= G:", "- break", "- if p >= G:", "- break", "- if p >= G:", "- C = min(c, C)", "- continue", "-print(C)", "+ A = True", "+ a = -1", "+ for i in range(D - 1, -1, -1):", "+ if bit & (1 << i):", "+ S += (i + 1) * pc[i][0] + int(pc[i][1] / 100)", "+ c += pc[i][0]", "+ elif A:", "+ a = i", "+ A = False", "+ if a != -1:", "+ for i in range(1, pc[a][0]):", "+ if S >= G:", "+ break", "+ S += a + 1", "+ c += 1", "+ if S >= G:", "+ N = min(N, c)", "+print(N)" ]
false
0.156058
0.04569
3.415631
[ "s480012487", "s004515244" ]
u227082700
p02859
python
s630200984
s519468518
20
17
3,316
2,940
Accepted
Accepted
15
r=int(eval(input())) print((r*r))
print((int(eval(input()))**2))
2
1
26
22
r = int(eval(input())) print((r * r))
print((int(eval(input())) ** 2))
false
50
[ "-r = int(eval(input()))", "-print((r * r))", "+print((int(eval(input())) ** 2))" ]
false
0.042397
0.040741
1.040646
[ "s630200984", "s519468518" ]
u621935300
p03732
python
s159466854
s550123536
350
129
2,940
5,364
Accepted
Accepted
63.14
from collections import defaultdict N,W=list(map(int,input().split())) a=defaultdict(lambda:[]) for i in range(N): w,v=list(map(int,input().split())) a[w]=a[w]+[v] for i,j in list(a.items()): a[i]=sorted(j,reverse=True) lst=[] for i,j in list(a.items()): lst.append( (i,len(j)) ) max_val=0 if len(lst)==1: w1=lst[0][0] c1=lst[0][1] for i in range(c1+1): if i*w1<=W: max_val=max(max_val, sum(a[w1][:i])) elif len(lst)==2: w1=lst[0][0]; w2=lst[1][0] c1=lst[0][1]; c2=lst[1][1] for i in range(c1+1): for j in range(c2+1): if i*w1+j*w2<=W: max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j])) elif len(lst)==3: w1=lst[0][0]; w2=lst[1][0]; w3=lst[2][0] c1=lst[0][1]; c2=lst[1][1]; c3=lst[2][1] for i in range(c1+1): for j in range(c2+1): for k in range(c3+1): if i*w1+j*w2+k*w3<=W: max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j])+sum(a[w3][:k])) elif len(lst)==4: w1=lst[0][0]; w2=lst[1][0]; w3=lst[2][0]; w4=lst[3][0] c1=lst[0][1]; c2=lst[1][1]; c3=lst[2][1]; c4=lst[3][1] for i in range(c1+1): for j in range(c2+1): for k in range(c3+1): for m in range(c4+1): if i*w1+j*w2+k*w3+m*w4<=W: max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j])+sum(a[w3][:k])+sum(a[w4][:m])) print(max_val)
from collections import defaultdict N,W=list(map(int,input().split())) wv=[] for i in range(N): w,v=list(map(int,input().split())) wv.append((w,v)) dp=defaultdict(lambda: 0) # Weight:Value dp[0]=0 for w1,v1 in wv: d=dp.copy() for w,v in list(dp.items()): dp[w+w1]=max( dp[w+w1], d[w]+v1 ) l1=[x for x in list(dp.items()) if x[0]<=W] print(sorted(l1, key=lambda x: x[1],reverse=True)[0][1])
54
20
1,296
407
from collections import defaultdict N, W = list(map(int, input().split())) a = defaultdict(lambda: []) for i in range(N): w, v = list(map(int, input().split())) a[w] = a[w] + [v] for i, j in list(a.items()): a[i] = sorted(j, reverse=True) lst = [] for i, j in list(a.items()): lst.append((i, len(j))) max_val = 0 if len(lst) == 1: w1 = lst[0][0] c1 = lst[0][1] for i in range(c1 + 1): if i * w1 <= W: max_val = max(max_val, sum(a[w1][:i])) elif len(lst) == 2: w1 = lst[0][0] w2 = lst[1][0] c1 = lst[0][1] c2 = lst[1][1] for i in range(c1 + 1): for j in range(c2 + 1): if i * w1 + j * w2 <= W: max_val = max(max_val, sum(a[w1][:i]) + sum(a[w2][:j])) elif len(lst) == 3: w1 = lst[0][0] w2 = lst[1][0] w3 = lst[2][0] c1 = lst[0][1] c2 = lst[1][1] c3 = lst[2][1] for i in range(c1 + 1): for j in range(c2 + 1): for k in range(c3 + 1): if i * w1 + j * w2 + k * w3 <= W: max_val = max( max_val, sum(a[w1][:i]) + sum(a[w2][:j]) + sum(a[w3][:k]) ) elif len(lst) == 4: w1 = lst[0][0] w2 = lst[1][0] w3 = lst[2][0] w4 = lst[3][0] c1 = lst[0][1] c2 = lst[1][1] c3 = lst[2][1] c4 = lst[3][1] for i in range(c1 + 1): for j in range(c2 + 1): for k in range(c3 + 1): for m in range(c4 + 1): if i * w1 + j * w2 + k * w3 + m * w4 <= W: max_val = max( max_val, sum(a[w1][:i]) + sum(a[w2][:j]) + sum(a[w3][:k]) + sum(a[w4][:m]), ) print(max_val)
from collections import defaultdict N, W = list(map(int, input().split())) wv = [] for i in range(N): w, v = list(map(int, input().split())) wv.append((w, v)) dp = defaultdict(lambda: 0) # Weight:Value dp[0] = 0 for w1, v1 in wv: d = dp.copy() for w, v in list(dp.items()): dp[w + w1] = max(dp[w + w1], d[w] + v1) l1 = [x for x in list(dp.items()) if x[0] <= W] print(sorted(l1, key=lambda x: x[1], reverse=True)[0][1])
false
62.962963
[ "-a = defaultdict(lambda: [])", "+wv = []", "- a[w] = a[w] + [v]", "-for i, j in list(a.items()):", "- a[i] = sorted(j, reverse=True)", "-lst = []", "-for i, j in list(a.items()):", "- lst.append((i, len(j)))", "-max_val = 0", "-if len(lst) == 1:", "- w1 = lst[0][0]", "- c1 = lst[0][1]", "- for i in range(c1 + 1):", "- if i * w1 <= W:", "- max_val = max(max_val, sum(a[w1][:i]))", "-elif len(lst) == 2:", "- w1 = lst[0][0]", "- w2 = lst[1][0]", "- c1 = lst[0][1]", "- c2 = lst[1][1]", "- for i in range(c1 + 1):", "- for j in range(c2 + 1):", "- if i * w1 + j * w2 <= W:", "- max_val = max(max_val, sum(a[w1][:i]) + sum(a[w2][:j]))", "-elif len(lst) == 3:", "- w1 = lst[0][0]", "- w2 = lst[1][0]", "- w3 = lst[2][0]", "- c1 = lst[0][1]", "- c2 = lst[1][1]", "- c3 = lst[2][1]", "- for i in range(c1 + 1):", "- for j in range(c2 + 1):", "- for k in range(c3 + 1):", "- if i * w1 + j * w2 + k * w3 <= W:", "- max_val = max(", "- max_val, sum(a[w1][:i]) + sum(a[w2][:j]) + sum(a[w3][:k])", "- )", "-elif len(lst) == 4:", "- w1 = lst[0][0]", "- w2 = lst[1][0]", "- w3 = lst[2][0]", "- w4 = lst[3][0]", "- c1 = lst[0][1]", "- c2 = lst[1][1]", "- c3 = lst[2][1]", "- c4 = lst[3][1]", "- for i in range(c1 + 1):", "- for j in range(c2 + 1):", "- for k in range(c3 + 1):", "- for m in range(c4 + 1):", "- if i * w1 + j * w2 + k * w3 + m * w4 <= W:", "- max_val = max(", "- max_val,", "- sum(a[w1][:i])", "- + sum(a[w2][:j])", "- + sum(a[w3][:k])", "- + sum(a[w4][:m]),", "- )", "-print(max_val)", "+ wv.append((w, v))", "+dp = defaultdict(lambda: 0) # Weight:Value", "+dp[0] = 0", "+for w1, v1 in wv:", "+ d = dp.copy()", "+ for w, v in list(dp.items()):", "+ dp[w + w1] = max(dp[w + w1], d[w] + v1)", "+l1 = [x for x in list(dp.items()) if x[0] <= W]", "+print(sorted(l1, key=lambda x: x[1], reverse=True)[0][1])" ]
false
0.038078
0.039236
0.970493
[ "s159466854", "s550123536" ]
u679439110
p03062
python
s298432978
s981459344
173
97
16,716
14,252
Accepted
Accepted
43.93
n = int(eval(input())) la = list(map(int, input().split())) lb = [0]*(n+1) lb_flip = [-100000000000000]*(n+1) for i in range(n): lb[i+1] = max(lb[i]+la[i], lb_flip[i]-la[i]) lb_flip[i+1] = max(lb[i]-la[i], lb_flip[i]+la[i]) #print(lb) #print(lb_flip) print((lb[n]))
n = int(eval(input())) la = list(map(int, input().split())) ct0 = 0 ctm = 0 minm = 100000000000000000 ans = 0 for i in range(n): if la[i] == 0: ct0 += 1 elif la[i] < 0: ctm += 1 m = abs(la[i]) if m < minm: minm = m ans += m if ct0 > 0 or ctm % 2 == 0: print(ans) else: ans -= 2 * minm print(ans)
14
24
276
331
n = int(eval(input())) la = list(map(int, input().split())) lb = [0] * (n + 1) lb_flip = [-100000000000000] * (n + 1) for i in range(n): lb[i + 1] = max(lb[i] + la[i], lb_flip[i] - la[i]) lb_flip[i + 1] = max(lb[i] - la[i], lb_flip[i] + la[i]) # print(lb) # print(lb_flip) print((lb[n]))
n = int(eval(input())) la = list(map(int, input().split())) ct0 = 0 ctm = 0 minm = 100000000000000000 ans = 0 for i in range(n): if la[i] == 0: ct0 += 1 elif la[i] < 0: ctm += 1 m = abs(la[i]) if m < minm: minm = m ans += m if ct0 > 0 or ctm % 2 == 0: print(ans) else: ans -= 2 * minm print(ans)
false
41.666667
[ "-lb = [0] * (n + 1)", "-lb_flip = [-100000000000000] * (n + 1)", "+ct0 = 0", "+ctm = 0", "+minm = 100000000000000000", "+ans = 0", "- lb[i + 1] = max(lb[i] + la[i], lb_flip[i] - la[i])", "- lb_flip[i + 1] = max(lb[i] - la[i], lb_flip[i] + la[i])", "-# print(lb)", "-# print(lb_flip)", "-print((lb[n]))", "+ if la[i] == 0:", "+ ct0 += 1", "+ elif la[i] < 0:", "+ ctm += 1", "+ m = abs(la[i])", "+ if m < minm:", "+ minm = m", "+ ans += m", "+if ct0 > 0 or ctm % 2 == 0:", "+ print(ans)", "+else:", "+ ans -= 2 * minm", "+ print(ans)" ]
false
0.119633
0.039539
3.025656
[ "s298432978", "s981459344" ]
u191874006
p03325
python
s280566361
s758072473
241
153
4,148
4,148
Accepted
Accepted
36.51
#!/usr/bin/env python3 import re n = int(eval(input())) a = eval(input()) a = re.split(" ",a) count = 0 for i in range(len(a)): if(int(a[i]) % 2 == 0): while(int(a[i]) > 1): a[i] = int(a[i])/2 count += 1 if(int(a[i]) % 2 != 0): break; else: pass print(count)
#!/usr/bin/env python3 #ABC100 C N = int(eval(input())) a = list(map(int,input().split())) ans = 0 for i in range(N): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] / 2 ans += 1 print(ans)
21
13
347
238
#!/usr/bin/env python3 import re n = int(eval(input())) a = eval(input()) a = re.split(" ", a) count = 0 for i in range(len(a)): if int(a[i]) % 2 == 0: while int(a[i]) > 1: a[i] = int(a[i]) / 2 count += 1 if int(a[i]) % 2 != 0: break else: pass print(count)
#!/usr/bin/env python3 # ABC100 C N = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(N): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] / 2 ans += 1 print(ans)
false
38.095238
[ "-import re", "-", "-n = int(eval(input()))", "-a = eval(input())", "-a = re.split(\" \", a)", "-count = 0", "-for i in range(len(a)):", "- if int(a[i]) % 2 == 0:", "- while int(a[i]) > 1:", "- a[i] = int(a[i]) / 2", "- count += 1", "- if int(a[i]) % 2 != 0:", "- break", "- else:", "- pass", "-print(count)", "+# ABC100 C", "+N = int(eval(input()))", "+a = list(map(int, input().split()))", "+ans = 0", "+for i in range(N):", "+ if a[i] % 2 == 0:", "+ while a[i] % 2 == 0:", "+ a[i] = a[i] / 2", "+ ans += 1", "+print(ans)" ]
false
0.050851
0.062629
0.811943
[ "s280566361", "s758072473" ]
u600402037
p03112
python
s251995360
s068566223
1,115
850
17,640
12,944
Accepted
Accepted
23.77
import bisect import itertools A,B,Q = list(map(int,input().split())) # 簡略化のため常に左右に存在するようにしておく INF = 10 ** 15 S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF] T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF] X = [int(eval(input())) for _ in range(Q)] def solve(x): # xの位置 i = bisect.bisect_left(S, x) j = bisect.bisect_left(T, x) result = INF # どの2つを目指すのか for s,t in itertools.product(S[i-1:i+1], T[j-1:j+1]): d = min(abs(s-x),abs(t-x)) + abs(t-s) result = min(result,d) return result for x in X: answer = solve(x) print(answer)
# coding: utf-8 import sys from bisect import bisect_left sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 番兵を左右に置いて、4通り試す A, B, Q = lr() INF = 10 ** 12 S = [-INF] + [ir() for _ in range(A)] + [INF] T = [-INF] + [ir() for _ in range(B)] + [INF] S.sort(); T.sort() for _ in range(Q): x = ir() si = bisect_left(S, x) ti = bisect_left(T, x) temp = [] temp.append(max(S[si], T[ti]) - x) y = abs(S[si] - x) z = abs(T[ti-1] - x) temp.append(min(y, z) * 2 + max(y, z)) y = abs(S[si-1] - x) z = abs(T[ti] - x) temp.append(min(y, z) * 2 + max(y, z)) temp.append(x - min(S[si-1], T[ti-1])) print((min(temp))) # 46
25
30
581
747
import bisect import itertools A, B, Q = list(map(int, input().split())) # 簡略化のため常に左右に存在するようにしておく INF = 10**15 S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF] T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF] X = [int(eval(input())) for _ in range(Q)] def solve(x): # xの位置 i = bisect.bisect_left(S, x) j = bisect.bisect_left(T, x) result = INF # どの2つを目指すのか for s, t in itertools.product(S[i - 1 : i + 1], T[j - 1 : j + 1]): d = min(abs(s - x), abs(t - x)) + abs(t - s) result = min(result, d) return result for x in X: answer = solve(x) print(answer)
# coding: utf-8 import sys from bisect import bisect_left sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 番兵を左右に置いて、4通り試す A, B, Q = lr() INF = 10**12 S = [-INF] + [ir() for _ in range(A)] + [INF] T = [-INF] + [ir() for _ in range(B)] + [INF] S.sort() T.sort() for _ in range(Q): x = ir() si = bisect_left(S, x) ti = bisect_left(T, x) temp = [] temp.append(max(S[si], T[ti]) - x) y = abs(S[si] - x) z = abs(T[ti - 1] - x) temp.append(min(y, z) * 2 + max(y, z)) y = abs(S[si - 1] - x) z = abs(T[ti] - x) temp.append(min(y, z) * 2 + max(y, z)) temp.append(x - min(S[si - 1], T[ti - 1])) print((min(temp))) # 46
false
16.666667
[ "-import bisect", "-import itertools", "+# coding: utf-8", "+import sys", "+from bisect import bisect_left", "-A, B, Q = list(map(int, input().split()))", "-# 簡略化のため常に左右に存在するようにしておく", "-INF = 10**15", "-S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]", "-T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]", "-X = [int(eval(input())) for _ in range(Q)]", "-", "-", "-def solve(x):", "- # xの位置", "- i = bisect.bisect_left(S, x)", "- j = bisect.bisect_left(T, x)", "- result = INF", "- # どの2つを目指すのか", "- for s, t in itertools.product(S[i - 1 : i + 1], T[j - 1 : j + 1]):", "- d = min(abs(s - x), abs(t - x)) + abs(t - s)", "- result = min(result, d)", "- return result", "-", "-", "-for x in X:", "- answer = solve(x)", "- print(answer)", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+# 番兵を左右に置いて、4通り試す", "+A, B, Q = lr()", "+INF = 10**12", "+S = [-INF] + [ir() for _ in range(A)] + [INF]", "+T = [-INF] + [ir() for _ in range(B)] + [INF]", "+S.sort()", "+T.sort()", "+for _ in range(Q):", "+ x = ir()", "+ si = bisect_left(S, x)", "+ ti = bisect_left(T, x)", "+ temp = []", "+ temp.append(max(S[si], T[ti]) - x)", "+ y = abs(S[si] - x)", "+ z = abs(T[ti - 1] - x)", "+ temp.append(min(y, z) * 2 + max(y, z))", "+ y = abs(S[si - 1] - x)", "+ z = abs(T[ti] - x)", "+ temp.append(min(y, z) * 2 + max(y, z))", "+ temp.append(x - min(S[si - 1], T[ti - 1]))", "+ print((min(temp)))", "+# 46" ]
false
0.045408
0.037289
1.217726
[ "s251995360", "s068566223" ]
u417365712
p02803
python
s330346400
s744620339
1,114
1,028
12,544
12,532
Accepted
Accepted
7.72
from copy import deepcopy from collections import deque from itertools import product import numpy as np inputs = open(0).readlines() class Grid(): def __init__(self, grid, w=0, h=0, function=lambda x: x): self.w = w = w if w else len(grid[0]) self.h = h = h if h else len(grid) dtype = type(function(grid[0][0])) self.grid = np.empty((h, w), dtype=dtype) for i, rows in zip(list(range(h)), grid): for j, val in zip(list(range(w)), rows): self.grid[i][j] = function(val) def is_valid_x(self, x): return 0 <= x < self.w def is_valid_y(self, y): return 0 <= y < self.h def is_valid_xy(self, x, y): return self.is_valid_x(x) and self.is_valid_y(y) def __iter__(self): return iter(self.grid) def __repr__(self): return '\n'.join([' '.join(map(str, rows)) for rows in self.grid]) def __getitem__(self, x): return self.grid[x] def __setitem__(self, x, val): self.grid[x] = val h, w = list(map(int, inputs[0].split())) grid_origin = Grid(inputs[1:], function=lambda x: int(x == '.')) def bfs(root): queue = deque([root]) while queue: x, y, d = queue.popleft() d += 1 grid[y, x] = 0 for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]): if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]: queue.append((x+dx, y+dy, d)) grid[y+dy, x+dx] = 0 return d-1 ans = 0 for i, j in product(list(range(h)), list(range(w))): if grid_origin[i, j]: grid = deepcopy(grid_origin) ans = max(ans, bfs((j, i, 0))) print(ans)
from copy import deepcopy from collections import deque from itertools import product import numpy as np inputs = open(0).readlines() class Grid(): def __init__(self, grid, w=0, h=0, function=lambda x: x): self.w = w = w if w else len(grid[0]) self.h = h = h if h else len(grid) dtype = type(function(grid[0][0])) self.grid = np.empty((h, w), dtype=dtype) for i, row in zip(list(range(h)), grid): for j, val in zip(list(range(w)), row): self.grid[i][j] = function(val) def is_valid_x(self, x): return 0 <= x < self.w def is_valid_y(self, y): return 0 <= y < self.h def is_valid_xy(self, x, y): return self.is_valid_x(x) and self.is_valid_y(y) def __iter__(self): return iter(self.grid) def __repr__(self): return '\n'.join([' '.join(map(str, row)) for row in self.grid]) def __getitem__(self, x): return self.grid[x] def __setitem__(self, x, val): self.grid[x] = val h, w = list(map(int, inputs[0].split())) grid_origin = Grid(inputs[1:], function=lambda x: int(x == '.')) def bfs(root): x, y, _ = root grid[y, x] = 0 queue = deque([root]) while queue: x, y, d = queue.popleft() for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]): if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]: queue.append((x+dx, y+dy, d+1)) grid[y+dy, x+dx] = 0 return d ans = 0 for i, j in product(list(range(h)), list(range(w))): if grid_origin[i, j]: grid = deepcopy(grid_origin) ans = max(ans, bfs((j, i, 0))) print(ans)
51
52
1,694
1,700
from copy import deepcopy from collections import deque from itertools import product import numpy as np inputs = open(0).readlines() class Grid: def __init__(self, grid, w=0, h=0, function=lambda x: x): self.w = w = w if w else len(grid[0]) self.h = h = h if h else len(grid) dtype = type(function(grid[0][0])) self.grid = np.empty((h, w), dtype=dtype) for i, rows in zip(list(range(h)), grid): for j, val in zip(list(range(w)), rows): self.grid[i][j] = function(val) def is_valid_x(self, x): return 0 <= x < self.w def is_valid_y(self, y): return 0 <= y < self.h def is_valid_xy(self, x, y): return self.is_valid_x(x) and self.is_valid_y(y) def __iter__(self): return iter(self.grid) def __repr__(self): return "\n".join([" ".join(map(str, rows)) for rows in self.grid]) def __getitem__(self, x): return self.grid[x] def __setitem__(self, x, val): self.grid[x] = val h, w = list(map(int, inputs[0].split())) grid_origin = Grid(inputs[1:], function=lambda x: int(x == ".")) def bfs(root): queue = deque([root]) while queue: x, y, d = queue.popleft() d += 1 grid[y, x] = 0 for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]): if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]: queue.append((x + dx, y + dy, d)) grid[y + dy, x + dx] = 0 return d - 1 ans = 0 for i, j in product(list(range(h)), list(range(w))): if grid_origin[i, j]: grid = deepcopy(grid_origin) ans = max(ans, bfs((j, i, 0))) print(ans)
from copy import deepcopy from collections import deque from itertools import product import numpy as np inputs = open(0).readlines() class Grid: def __init__(self, grid, w=0, h=0, function=lambda x: x): self.w = w = w if w else len(grid[0]) self.h = h = h if h else len(grid) dtype = type(function(grid[0][0])) self.grid = np.empty((h, w), dtype=dtype) for i, row in zip(list(range(h)), grid): for j, val in zip(list(range(w)), row): self.grid[i][j] = function(val) def is_valid_x(self, x): return 0 <= x < self.w def is_valid_y(self, y): return 0 <= y < self.h def is_valid_xy(self, x, y): return self.is_valid_x(x) and self.is_valid_y(y) def __iter__(self): return iter(self.grid) def __repr__(self): return "\n".join([" ".join(map(str, row)) for row in self.grid]) def __getitem__(self, x): return self.grid[x] def __setitem__(self, x, val): self.grid[x] = val h, w = list(map(int, inputs[0].split())) grid_origin = Grid(inputs[1:], function=lambda x: int(x == ".")) def bfs(root): x, y, _ = root grid[y, x] = 0 queue = deque([root]) while queue: x, y, d = queue.popleft() for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]): if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]: queue.append((x + dx, y + dy, d + 1)) grid[y + dy, x + dx] = 0 return d ans = 0 for i, j in product(list(range(h)), list(range(w))): if grid_origin[i, j]: grid = deepcopy(grid_origin) ans = max(ans, bfs((j, i, 0))) print(ans)
false
1.923077
[ "- for i, rows in zip(list(range(h)), grid):", "- for j, val in zip(list(range(w)), rows):", "+ for i, row in zip(list(range(h)), grid):", "+ for j, val in zip(list(range(w)), row):", "- return \"\\n\".join([\" \".join(map(str, rows)) for rows in self.grid])", "+ return \"\\n\".join([\" \".join(map(str, row)) for row in self.grid])", "+ x, y, _ = root", "+ grid[y, x] = 0", "- d += 1", "- grid[y, x] = 0", "- queue.append((x + dx, y + dy, d))", "+ queue.append((x + dx, y + dy, d + 1))", "- return d - 1", "+ return d" ]
false
0.303001
0.284177
1.066238
[ "s330346400", "s744620339" ]
u644907318
p02820
python
s568544671
s642762809
217
106
45,648
92,020
Accepted
Accepted
51.15
N,K = list(map(int,input().split())) R,S,P = list(map(int,input().split())) D = {"r":P,"s":R,"p":S} T = input().strip() hist = [0 for _ in range(N)] ans = 0 for i in range(N): a = T[i] if hist[i]==0: hist[i] = 1 cnt = 1 j = i while j+K<N and T[j+K]==a: hist[j+K]=1 cnt += 1 j += K ans += D[a]*(cnt-cnt//2) print(ans)
N,K = list(map(int,input().split())) R,S,P = list(map(int,input().split())) D={"r":P,"s":R,"p":S} T = input().strip() A = {i:[] for i in range(K)} for i in range(N): A[i%K].append(T[i]) cnt = 0 for k in range(K): if len(A[k])>0: cnt += D[A[k][0]] for i in range(1,len(A[k])): if A[k][i]==A[k][i-1]: A[k][i] = 0 elif A[k][i]!=A[k][i-1]: cnt += D[A[k][i]] print(cnt)
18
17
405
448
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) D = {"r": P, "s": R, "p": S} T = input().strip() hist = [0 for _ in range(N)] ans = 0 for i in range(N): a = T[i] if hist[i] == 0: hist[i] = 1 cnt = 1 j = i while j + K < N and T[j + K] == a: hist[j + K] = 1 cnt += 1 j += K ans += D[a] * (cnt - cnt // 2) print(ans)
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) D = {"r": P, "s": R, "p": S} T = input().strip() A = {i: [] for i in range(K)} for i in range(N): A[i % K].append(T[i]) cnt = 0 for k in range(K): if len(A[k]) > 0: cnt += D[A[k][0]] for i in range(1, len(A[k])): if A[k][i] == A[k][i - 1]: A[k][i] = 0 elif A[k][i] != A[k][i - 1]: cnt += D[A[k][i]] print(cnt)
false
5.555556
[ "-hist = [0 for _ in range(N)]", "-ans = 0", "+A = {i: [] for i in range(K)}", "- a = T[i]", "- if hist[i] == 0:", "- hist[i] = 1", "- cnt = 1", "- j = i", "- while j + K < N and T[j + K] == a:", "- hist[j + K] = 1", "- cnt += 1", "- j += K", "- ans += D[a] * (cnt - cnt // 2)", "-print(ans)", "+ A[i % K].append(T[i])", "+cnt = 0", "+for k in range(K):", "+ if len(A[k]) > 0:", "+ cnt += D[A[k][0]]", "+ for i in range(1, len(A[k])):", "+ if A[k][i] == A[k][i - 1]:", "+ A[k][i] = 0", "+ elif A[k][i] != A[k][i - 1]:", "+ cnt += D[A[k][i]]", "+print(cnt)" ]
false
0.090512
0.047407
1.909239
[ "s568544671", "s642762809" ]
u729133443
p03993
python
s795786054
s433950641
208
66
52,912
13,940
Accepted
Accepted
68.27
n=int(eval(input()));a=list(map(int,input().split()));print((sum([0,1][a[a[i]-1]-1==i]for i in range(n))//2))
n,*a=list(map(int,open(0).read().split()));print((sum(a[a[i]-1]==i+1for i in range(n))>>1))
1
1
101
83
n = int(eval(input())) a = list(map(int, input().split())) print((sum([0, 1][a[a[i] - 1] - 1 == i] for i in range(n)) // 2))
n, *a = list(map(int, open(0).read().split())) print((sum(a[a[i] - 1] == i + 1 for i in range(n)) >> 1))
false
0
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-print((sum([0, 1][a[a[i] - 1] - 1 == i] for i in range(n)) // 2))", "+n, *a = list(map(int, open(0).read().split()))", "+print((sum(a[a[i] - 1] == i + 1 for i in range(n)) >> 1))" ]
false
0.04498
0.046298
0.971526
[ "s795786054", "s433950641" ]
u983181637
p02802
python
s870921636
s201397606
312
169
22,888
19,620
Accepted
Accepted
45.83
from collections import defaultdict n, m = list(map(int, input().split())) ac = 0 wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない already = set() for line in range(m): p, s = input().split() # forでその都度入力を受け取る p = int(p) if p in already: # acを見つけたときのみalreadyにpをいれすので、ac後のwaのカウントを避けている。 continue if s == 'AC': ac += 1 already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。 else: wa[p] += 1 #{1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。 # print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので× print((ac, sum(wa[i] for i in already)))
from collections import defaultdict import sys input = sys.stdin.readline n, m = list(map(int, input().split())) ac = 0 wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない already = set() sum_wa = 0 for line in range(m): p, s = input().split() # forでその都度入力を受け取る p = int(p) if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。 continue if s == 'AC': ac += 1 already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。 sum_wa += wa[p] else: wa[p] += 1 #{1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。 # print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので× print((ac, sum_wa))
18
23
633
690
from collections import defaultdict n, m = list(map(int, input().split())) ac = 0 wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない already = set() for line in range(m): p, s = input().split() # forでその都度入力を受け取る p = int(p) if p in already: # acを見つけたときのみalreadyにpをいれすので、ac後のwaのカウントを避けている。 continue if s == "AC": ac += 1 already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。 else: wa[p] += 1 # {1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。 # print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので× print((ac, sum(wa[i] for i in already)))
from collections import defaultdict import sys input = sys.stdin.readline n, m = list(map(int, input().split())) ac = 0 wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない already = set() sum_wa = 0 for line in range(m): p, s = input().split() # forでその都度入力を受け取る p = int(p) if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。 continue if s == "AC": ac += 1 already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。 sum_wa += wa[p] else: wa[p] += 1 # {1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。 # print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので× print((ac, sum_wa))
false
21.73913
[ "+import sys", "+input = sys.stdin.readline", "+sum_wa = 0", "- if p in already: # acを見つけたときのみalreadyにpをいれすので、ac後のwaのカウントを避けている。", "+ if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。", "+ sum_wa += wa[p]", "-print((ac, sum(wa[i] for i in already)))", "+print((ac, sum_wa))" ]
false
0.03786
0.079547
0.475949
[ "s870921636", "s201397606" ]
u216928054
p03161
python
s176884768
s157575575
540
385
344,800
83,496
Accepted
Accepted
28.7
#!/usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys sys.setrecursionlimit(10**6) input = sys.stdin.buffer.readline INF = 10 ** 9 + 1 # sys.maxsize # float("inf") def debug(*x): print((*x)) def solve1(N, K, heights): heights += [INF] * K costs = [INF] * (N + K) costs[0] = 0 for i in range(N - 1): for k in range(1, K + 1): newcost = costs[i] + abs(heights[i + k] - heights[i]) if newcost < costs[i + k]: costs[i + k] = newcost return costs[N - 1] def solve2(N, K, heights): costs = [0] * N costs[0] = 0 for i in range(1, N): costs[i] = min( costs[j] + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) return costs[-1] def solve(N, K, heights): costs = [None] * N costs[0] = 0 def get_cost(i): if costs[i] != None: return costs[i] c = min( get_cost(j) + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) costs[i] = c return c return get_cost(N - 1) def main(): N, K = list(map(int, input().split())) heights = list(map(int, input().split())) print((solve(N, K, heights))) def _test(): """ >>> solve(5, 3, [10, 30, 40, 50, 20]) 30 >>> solve(3, 1, [10, 20, 10]) 20 >>> solve(2, 100, [10, 10]) 0 >>> solve(10, 4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]) 40 """ import doctest doctest.testmod() def as_input(s): "use in test, use given string as input file" import io global read, input f = io.StringIO(s.strip()) input = f.readline read = f.read USE_NUMBA = False if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c': print("compiling") from numba.pycc import CC cc = CC('my_module') cc.export('solve', solve.__doc__.strip().split()[0])(solve) cc.compile() exit() else: input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba": # -p: pure python mode # if not -p, import compiled module from my_module import solve # pylint: disable=all elif sys.argv[-1] == "-t": _test() sys.exit() elif sys.argv[-1] != '-p' and len(sys.argv) == 2: # input given as file input_as_file = open(sys.argv[1]) input = input_as_file.buffer.readline read = input_as_file.buffer.read main()
#!/usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys sys.setrecursionlimit(10**6) input = sys.stdin.buffer.readline INF = 10 ** 9 + 1 # sys.maxsize # float("inf") def debug(*x): print((*x)) def solve1(N, K, heights): heights += [INF] * K costs = [INF] * (N + K) costs[0] = 0 for i in range(N - 1): for k in range(1, K + 1): newcost = costs[i] + abs(heights[i + k] - heights[i]) if newcost < costs[i + k]: costs[i + k] = newcost return costs[N - 1] def solve(N, K, heights): costs = [0] * N costs[0] = 0 for i in range(1, N): costs[i] = min( costs[j] + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) return costs[-1] def solve3(N, K, heights): costs = [None] * N costs[0] = 0 def get_cost(i): if costs[i] != None: return costs[i] c = min( get_cost(j) + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) costs[i] = c return c return get_cost(N - 1) def main(): N, K = list(map(int, input().split())) heights = list(map(int, input().split())) print((solve(N, K, heights))) def _test(): """ >>> solve(5, 3, [10, 30, 40, 50, 20]) 30 >>> solve(3, 1, [10, 20, 10]) 20 >>> solve(2, 100, [10, 10]) 0 >>> solve(10, 4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]) 40 """ import doctest doctest.testmod() def as_input(s): "use in test, use given string as input file" import io global read, input f = io.StringIO(s.strip()) input = f.readline read = f.read USE_NUMBA = False if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c': print("compiling") from numba.pycc import CC cc = CC('my_module') cc.export('solve', solve.__doc__.strip().split()[0])(solve) cc.compile() exit() else: input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba": # -p: pure python mode # if not -p, import compiled module from my_module import solve # pylint: disable=all elif sys.argv[-1] == "-t": _test() sys.exit() elif sys.argv[-1] != '-p' and len(sys.argv) == 2: # input given as file input_as_file = open(sys.argv[1]) input = input_as_file.buffer.readline read = input_as_file.buffer.read main()
113
113
2,695
2,695
#!/usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys sys.setrecursionlimit(10**6) input = sys.stdin.buffer.readline INF = 10**9 + 1 # sys.maxsize # float("inf") def debug(*x): print((*x)) def solve1(N, K, heights): heights += [INF] * K costs = [INF] * (N + K) costs[0] = 0 for i in range(N - 1): for k in range(1, K + 1): newcost = costs[i] + abs(heights[i + k] - heights[i]) if newcost < costs[i + k]: costs[i + k] = newcost return costs[N - 1] def solve2(N, K, heights): costs = [0] * N costs[0] = 0 for i in range(1, N): costs[i] = min( costs[j] + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) return costs[-1] def solve(N, K, heights): costs = [None] * N costs[0] = 0 def get_cost(i): if costs[i] != None: return costs[i] c = min( get_cost(j) + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) costs[i] = c return c return get_cost(N - 1) def main(): N, K = list(map(int, input().split())) heights = list(map(int, input().split())) print((solve(N, K, heights))) def _test(): """ >>> solve(5, 3, [10, 30, 40, 50, 20]) 30 >>> solve(3, 1, [10, 20, 10]) 20 >>> solve(2, 100, [10, 10]) 0 >>> solve(10, 4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]) 40 """ import doctest doctest.testmod() def as_input(s): "use in test, use given string as input file" import io global read, input f = io.StringIO(s.strip()) input = f.readline read = f.read USE_NUMBA = False if (USE_NUMBA and sys.argv[-1] == "ONLINE_JUDGE") or sys.argv[-1] == "-c": print("compiling") from numba.pycc import CC cc = CC("my_module") cc.export("solve", solve.__doc__.strip().split()[0])(solve) cc.compile() exit() else: input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if (USE_NUMBA and sys.argv[-1] != "-p") or sys.argv[-1] == "--numba": # -p: pure python mode # if not -p, import compiled module from my_module import solve # pylint: disable=all elif sys.argv[-1] == "-t": _test() sys.exit() elif sys.argv[-1] != "-p" and len(sys.argv) == 2: # input given as file input_as_file = open(sys.argv[1]) input = input_as_file.buffer.readline read = input_as_file.buffer.read main()
#!/usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys sys.setrecursionlimit(10**6) input = sys.stdin.buffer.readline INF = 10**9 + 1 # sys.maxsize # float("inf") def debug(*x): print((*x)) def solve1(N, K, heights): heights += [INF] * K costs = [INF] * (N + K) costs[0] = 0 for i in range(N - 1): for k in range(1, K + 1): newcost = costs[i] + abs(heights[i + k] - heights[i]) if newcost < costs[i + k]: costs[i + k] = newcost return costs[N - 1] def solve(N, K, heights): costs = [0] * N costs[0] = 0 for i in range(1, N): costs[i] = min( costs[j] + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) return costs[-1] def solve3(N, K, heights): costs = [None] * N costs[0] = 0 def get_cost(i): if costs[i] != None: return costs[i] c = min( get_cost(j) + abs(heights[i] - heights[j]) for j in range(max(i - K, 0), i) ) costs[i] = c return c return get_cost(N - 1) def main(): N, K = list(map(int, input().split())) heights = list(map(int, input().split())) print((solve(N, K, heights))) def _test(): """ >>> solve(5, 3, [10, 30, 40, 50, 20]) 30 >>> solve(3, 1, [10, 20, 10]) 20 >>> solve(2, 100, [10, 10]) 0 >>> solve(10, 4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]) 40 """ import doctest doctest.testmod() def as_input(s): "use in test, use given string as input file" import io global read, input f = io.StringIO(s.strip()) input = f.readline read = f.read USE_NUMBA = False if (USE_NUMBA and sys.argv[-1] == "ONLINE_JUDGE") or sys.argv[-1] == "-c": print("compiling") from numba.pycc import CC cc = CC("my_module") cc.export("solve", solve.__doc__.strip().split()[0])(solve) cc.compile() exit() else: input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if (USE_NUMBA and sys.argv[-1] != "-p") or sys.argv[-1] == "--numba": # -p: pure python mode # if not -p, import compiled module from my_module import solve # pylint: disable=all elif sys.argv[-1] == "-t": _test() sys.exit() elif sys.argv[-1] != "-p" and len(sys.argv) == 2: # input given as file input_as_file = open(sys.argv[1]) input = input_as_file.buffer.readline read = input_as_file.buffer.read main()
false
0
[ "-def solve2(N, K, heights):", "+def solve(N, K, heights):", "-def solve(N, K, heights):", "+def solve3(N, K, heights):" ]
false
0.03748
0.037687
0.994494
[ "s176884768", "s157575575" ]
u505420467
p03805
python
s580041776
s247237317
31
26
4,212
3,064
Accepted
Accepted
16.13
v=[] n,m=list(map(int,input().split())) ans=[[] for i in range(n)] for i in range(m): a,b=list(map(int,input().split())) ans[a-1].append((b-1)) ans[b-1].append((a-1)) def dfs(now,visited=[]): if len(visited)==n: v.append([visited]) return for j in ans[now]: if j not in visited: dfs(j,visited+[j]) dfs(0,[0]) print((len(v)))
def DFS(now, visited): if len(visited) == n: ans.append(1) return for i in graph[now]: if not i in visited: DFS(i, visited + [i]) n, m = list(map(int, input().split())) graph = [[] for i in range(n)] ans = [] for i in range(m): a, b = list(map(int, input().split())) graph[a-1].append(b-1) graph[b-1].append(a-1) DFS(0,[0]) print((len(ans)))
16
23
382
413
v = [] n, m = list(map(int, input().split())) ans = [[] for i in range(n)] for i in range(m): a, b = list(map(int, input().split())) ans[a - 1].append((b - 1)) ans[b - 1].append((a - 1)) def dfs(now, visited=[]): if len(visited) == n: v.append([visited]) return for j in ans[now]: if j not in visited: dfs(j, visited + [j]) dfs(0, [0]) print((len(v)))
def DFS(now, visited): if len(visited) == n: ans.append(1) return for i in graph[now]: if not i in visited: DFS(i, visited + [i]) n, m = list(map(int, input().split())) graph = [[] for i in range(n)] ans = [] for i in range(m): a, b = list(map(int, input().split())) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) DFS(0, [0]) print((len(ans)))
false
30.434783
[ "-v = []", "+def DFS(now, visited):", "+ if len(visited) == n:", "+ ans.append(1)", "+ return", "+ for i in graph[now]:", "+ if not i in visited:", "+ DFS(i, visited + [i])", "+", "+", "-ans = [[] for i in range(n)]", "+graph = [[] for i in range(n)]", "+ans = []", "- ans[a - 1].append((b - 1))", "- ans[b - 1].append((a - 1))", "-", "-", "-def dfs(now, visited=[]):", "- if len(visited) == n:", "- v.append([visited])", "- return", "- for j in ans[now]:", "- if j not in visited:", "- dfs(j, visited + [j])", "-", "-", "-dfs(0, [0])", "-print((len(v)))", "+ graph[a - 1].append(b - 1)", "+ graph[b - 1].append(a - 1)", "+DFS(0, [0])", "+print((len(ans)))" ]
false
0.037556
0.053297
0.704654
[ "s580041776", "s247237317" ]
u411537765
p03488
python
s822485564
s051029051
1,322
219
3,444
3,444
Accepted
Accepted
83.43
import sys from collections import deque s = deque(eval(input()) + 'T') X, Y = list(map(int, input().split())) while True: if s[0] == 'T': break s.popleft() X -= 1 dirx = True x_list = [] y_list = [] count = 0 for c in s: if c == 'F': count += 1 else: if count > 0: x_list.append(count) if dirx else y_list.append(count) count = 0 dirx = not(dirx) if (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0 or sum(x_list) < abs(X) or sum(y_list) < abs(Y): print('No') sys.exit() dx = (sum(x_list) + abs(X)) // 2 dy = (sum(y_list) + abs(Y)) // 2 dp_x = [False for _ in range(dx + 1)] dp_x[0] = True for x in x_list: for i in range(dx - x, -1, -1): if dp_x[i] and i + x <= dx: dp_x[i + x] = True if not dp_x[dx]: print('No') sys.exit() dp_y = [False for _ in range(dy + 1)] dp_y[0] = True for y in y_list: for i in range(dy - y, -1, -1): if dp_y[i] and i + y <= dy: dp_y[i + y] = True if not dp_y[dy]: print('No') sys.exit() print('Yes')
import sys from collections import deque s = deque(eval(input()) + 'T') X, Y = list(map(int, input().split())) while True: if s[0] == 'T': break s.popleft() X -= 1 dirx = True x_list = [] y_list = [] count = 0 for c in s: if c == 'F': count += 1 else: if count > 0: x_list.append(count) if dirx else y_list.append(count) count = 0 dirx = not(dirx) if (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0 or sum(x_list) < abs(X) or sum(y_list) < abs(Y): print('No') sys.exit() dx = (sum(x_list) - abs(X)) // 2 dp_x = [False for _ in range(dx + 1)] dp_x[0] = True for x in x_list: for i in range(dx - x, -1, -1): if dp_x[i]: dp_x[i + x] = True if dp_x[dx]: break if not dp_x[dx]: print('No') sys.exit() dy = (sum(y_list) - abs(Y)) // 2 dp_y = [False for _ in range(dy + 1)] dp_y[0] = True for y in y_list: for i in range(dy - y, -1, -1): if dp_y[i]: dp_y[i + y] = True if dp_y[dy]: break if not dp_y[dy]: print('No') sys.exit() print('Yes')
53
56
1,133
1,165
import sys from collections import deque s = deque(eval(input()) + "T") X, Y = list(map(int, input().split())) while True: if s[0] == "T": break s.popleft() X -= 1 dirx = True x_list = [] y_list = [] count = 0 for c in s: if c == "F": count += 1 else: if count > 0: x_list.append(count) if dirx else y_list.append(count) count = 0 dirx = not (dirx) if ( (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0 or sum(x_list) < abs(X) or sum(y_list) < abs(Y) ): print("No") sys.exit() dx = (sum(x_list) + abs(X)) // 2 dy = (sum(y_list) + abs(Y)) // 2 dp_x = [False for _ in range(dx + 1)] dp_x[0] = True for x in x_list: for i in range(dx - x, -1, -1): if dp_x[i] and i + x <= dx: dp_x[i + x] = True if not dp_x[dx]: print("No") sys.exit() dp_y = [False for _ in range(dy + 1)] dp_y[0] = True for y in y_list: for i in range(dy - y, -1, -1): if dp_y[i] and i + y <= dy: dp_y[i + y] = True if not dp_y[dy]: print("No") sys.exit() print("Yes")
import sys from collections import deque s = deque(eval(input()) + "T") X, Y = list(map(int, input().split())) while True: if s[0] == "T": break s.popleft() X -= 1 dirx = True x_list = [] y_list = [] count = 0 for c in s: if c == "F": count += 1 else: if count > 0: x_list.append(count) if dirx else y_list.append(count) count = 0 dirx = not (dirx) if ( (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0 or sum(x_list) < abs(X) or sum(y_list) < abs(Y) ): print("No") sys.exit() dx = (sum(x_list) - abs(X)) // 2 dp_x = [False for _ in range(dx + 1)] dp_x[0] = True for x in x_list: for i in range(dx - x, -1, -1): if dp_x[i]: dp_x[i + x] = True if dp_x[dx]: break if not dp_x[dx]: print("No") sys.exit() dy = (sum(y_list) - abs(Y)) // 2 dp_y = [False for _ in range(dy + 1)] dp_y[0] = True for y in y_list: for i in range(dy - y, -1, -1): if dp_y[i]: dp_y[i + y] = True if dp_y[dy]: break if not dp_y[dy]: print("No") sys.exit() print("Yes")
false
5.357143
[ "-dx = (sum(x_list) + abs(X)) // 2", "-dy = (sum(y_list) + abs(Y)) // 2", "+dx = (sum(x_list) - abs(X)) // 2", "- if dp_x[i] and i + x <= dx:", "+ if dp_x[i]:", "+ if dp_x[dx]:", "+ break", "+dy = (sum(y_list) - abs(Y)) // 2", "- if dp_y[i] and i + y <= dy:", "+ if dp_y[i]:", "+ if dp_y[dy]:", "+ break" ]
false
0.047449
0.047692
0.994902
[ "s822485564", "s051029051" ]
u064505481
p03164
python
s682945283
s125595348
369
234
71,584
83,080
Accepted
Accepted
36.59
from sys import stdin, stdout from collections import deque, defaultdict import math as m rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def main(): n, W = rli() items = [] maxval = 0 for _ in range(n): w, v = rli() maxval += v items.append((w, v)) dp = [INF for _ in range(maxval + 1)] dp[0] = 0 for w, v in items: for i in range(maxval, -1, -1): if i - v >= 0: dp[i] = min(dp[i], dp[i-v] + w) ans = NINF for val, minweight in enumerate(dp): if minweight <= W: ans = val print(ans) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) rlf = lambda: list(map(float, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def pprint(M): for row in M: print(row) print("~~~") def main(): n, W = rli() weights, vals = [], [] for _ in range(n): w, v = rli() weights.append(w) vals.append(v) maxval = 10**5 + 100 dp = [INF for _ in range(maxval+1)] dp[0] = 0 for w, v in zip(weights, vals): for i in range(maxval, -1, -1): if i - v < 0: continue dp[i] = min(dp[i], dp[i-v] + w) for i in range(maxval, -1, -1): if dp[i] <= W: print(i) break stdout.close() if __name__ == "__main__": main()
34
39
712
899
from sys import stdin, stdout from collections import deque, defaultdict import math as m rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def main(): n, W = rli() items = [] maxval = 0 for _ in range(n): w, v = rli() maxval += v items.append((w, v)) dp = [INF for _ in range(maxval + 1)] dp[0] = 0 for w, v in items: for i in range(maxval, -1, -1): if i - v >= 0: dp[i] = min(dp[i], dp[i - v] + w) ans = NINF for val, minweight in enumerate(dp): if minweight <= W: ans = val print(ans) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) rlf = lambda: list(map(float, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def pprint(M): for row in M: print(row) print("~~~") def main(): n, W = rli() weights, vals = [], [] for _ in range(n): w, v = rli() weights.append(w) vals.append(v) maxval = 10**5 + 100 dp = [INF for _ in range(maxval + 1)] dp[0] = 0 for w, v in zip(weights, vals): for i in range(maxval, -1, -1): if i - v < 0: continue dp[i] = min(dp[i], dp[i - v] + w) for i in range(maxval, -1, -1): if dp[i] <= W: print(i) break stdout.close() if __name__ == "__main__": main()
false
12.820513
[ "-from sys import stdin, stdout", "-from collections import deque, defaultdict", "-import math as m", "+from sys import stdin, stdout, setrecursionlimit", "+from collections import deque, defaultdict, Counter", "+from heapq import heappush, heappop", "+import math", "+rlf = lambda: list(map(float, stdin.readline().split()))", "+", "+", "+def pprint(M):", "+ for row in M:", "+ print(row)", "+ print(\"~~~\")", "- items = []", "- maxval = 0", "+ weights, vals = [], []", "- maxval += v", "- items.append((w, v))", "+ weights.append(w)", "+ vals.append(v)", "+ maxval = 10**5 + 100", "- for w, v in items:", "+ for w, v in zip(weights, vals):", "- if i - v >= 0:", "- dp[i] = min(dp[i], dp[i - v] + w)", "- ans = NINF", "- for val, minweight in enumerate(dp):", "- if minweight <= W:", "- ans = val", "- print(ans)", "+ if i - v < 0:", "+ continue", "+ dp[i] = min(dp[i], dp[i - v] + w)", "+ for i in range(maxval, -1, -1):", "+ if dp[i] <= W:", "+ print(i)", "+ break" ]
false
0.098669
0.39088
0.252429
[ "s682945283", "s125595348" ]
u360515075
p03329
python
s282758368
s852660663
36
18
3,064
3,060
Accepted
Accepted
50
import bisect as bi li6 = [6 ** i for i in range(7)] li9 = [9 ** i for i in range(6)] def s69(n): if n < 6: return n else: s6 = li6[bi.bisect(li6, n)-1] s9 = li9[bi.bisect(li9, n)-1] return min(n // s6 + s69(n % s6), 1 + s69(n-s9), n // s9 + s69(n % s9)) print((s69(int(eval(input())))))
import bisect as bi li6 = [6 ** i for i in range(7)] li9 = [9 ** i for i in range(6)] def s69(n): if n < 6: return n else: s6 = li6[bi.bisect(li6, n)-1] s9 = li9[bi.bisect(li9, n)-1] return min(n // s6 + s69(n % s6), 1 + s69(n-s9)) print((s69(int(eval(input())))))
14
14
318
295
import bisect as bi li6 = [6**i for i in range(7)] li9 = [9**i for i in range(6)] def s69(n): if n < 6: return n else: s6 = li6[bi.bisect(li6, n) - 1] s9 = li9[bi.bisect(li9, n) - 1] return min(n // s6 + s69(n % s6), 1 + s69(n - s9), n // s9 + s69(n % s9)) print((s69(int(eval(input())))))
import bisect as bi li6 = [6**i for i in range(7)] li9 = [9**i for i in range(6)] def s69(n): if n < 6: return n else: s6 = li6[bi.bisect(li6, n) - 1] s9 = li9[bi.bisect(li9, n) - 1] return min(n // s6 + s69(n % s6), 1 + s69(n - s9)) print((s69(int(eval(input())))))
false
0
[ "- return min(n // s6 + s69(n % s6), 1 + s69(n - s9), n // s9 + s69(n % s9))", "+ return min(n // s6 + s69(n % s6), 1 + s69(n - s9))" ]
false
0.052054
0.046396
1.121948
[ "s282758368", "s852660663" ]
u513081876
p03862
python
s209134601
s857451142
119
109
14,588
14,548
Accepted
Accepted
8.4
N, X = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 for i in range(N-1): if a[i] + a[i+1] > X: if X - a[i] >= 0: ans += a[i+1] - (X - a[i]) a[i+1] = (X - a[i]) else: ans += a[i+1] a[i+1] = 0 ans += a[i] - X a[i] = X print(ans)
N, x = list(map(int, input().split())) a = [int(i) for i in input().split()] ans = 0 if a[0] > x: ans += a[0] - x a[0] = x for i in range(1, N): if a[i] + a[i - 1] > x: ans += a[i] - (x - a[i - 1]) a[i] = x - a[i - 1] print(ans)
18
14
384
266
N, X = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 for i in range(N - 1): if a[i] + a[i + 1] > X: if X - a[i] >= 0: ans += a[i + 1] - (X - a[i]) a[i + 1] = X - a[i] else: ans += a[i + 1] a[i + 1] = 0 ans += a[i] - X a[i] = X print(ans)
N, x = list(map(int, input().split())) a = [int(i) for i in input().split()] ans = 0 if a[0] > x: ans += a[0] - x a[0] = x for i in range(1, N): if a[i] + a[i - 1] > x: ans += a[i] - (x - a[i - 1]) a[i] = x - a[i - 1] print(ans)
false
22.222222
[ "-N, X = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "+N, x = list(map(int, input().split()))", "+a = [int(i) for i in input().split()]", "-for i in range(N - 1):", "- if a[i] + a[i + 1] > X:", "- if X - a[i] >= 0:", "- ans += a[i + 1] - (X - a[i])", "- a[i + 1] = X - a[i]", "- else:", "- ans += a[i + 1]", "- a[i + 1] = 0", "- ans += a[i] - X", "- a[i] = X", "+if a[0] > x:", "+ ans += a[0] - x", "+ a[0] = x", "+for i in range(1, N):", "+ if a[i] + a[i - 1] > x:", "+ ans += a[i] - (x - a[i - 1])", "+ a[i] = x - a[i - 1]" ]
false
0.043927
0.006322
6.947963
[ "s209134601", "s857451142" ]
u879870653
p03325
python
s130104970
s161112493
121
97
4,148
4,212
Accepted
Accepted
19.83
N = int(eval(input())) L = list(map(int,input().split())) ans = 0 for i in range(N) : flag = 0 while flag == 0 : if (L[i] % 2) == 0 : ans += 1 L[i] = L[i]//2 else : flag = 1 print(ans)
N = int(eval(input())) A = list(map(int,input().split())) ans = 0 for i in range(len(A)) : while True : if A[i] % 2 != 0 : break ans += 1 A[i] //= 2 print(ans)
13
11
252
205
N = int(eval(input())) L = list(map(int, input().split())) ans = 0 for i in range(N): flag = 0 while flag == 0: if (L[i] % 2) == 0: ans += 1 L[i] = L[i] // 2 else: flag = 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for i in range(len(A)): while True: if A[i] % 2 != 0: break ans += 1 A[i] //= 2 print(ans)
false
15.384615
[ "-L = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "-for i in range(N):", "- flag = 0", "- while flag == 0:", "- if (L[i] % 2) == 0:", "- ans += 1", "- L[i] = L[i] // 2", "- else:", "- flag = 1", "+for i in range(len(A)):", "+ while True:", "+ if A[i] % 2 != 0:", "+ break", "+ ans += 1", "+ A[i] //= 2" ]
false
0.037119
0.038402
0.966583
[ "s130104970", "s161112493" ]
u489959379
p03141
python
s018007764
s323875234
583
301
30,272
30,580
Accepted
Accepted
48.37
n = int(eval(input())) A, B, C = [], [], [] for i in range(n): a, b = list(map(int, input().split())) A.append(a) B.append(b) C.append([a + b, i]) C = sorted(C, reverse=True) suma, sumb = 0, 0 for i in range(n): if i % 2: sumb += B[C[i][1]] else: suma += A[C[i][1]] print((suma - sumb))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] for i in range(n): a, b = AB[i] AB[i] = [a + b, a, b] AB.sort(key=lambda x: x[0], reverse=True) score_t, score_a = 0, 0 for i in range(n): if i % 2 == 0: score_t += AB[i][1] else: score_a += AB[i][2] print((score_t - score_a)) if __name__ == '__main__': resolve()
16
28
328
581
n = int(eval(input())) A, B, C = [], [], [] for i in range(n): a, b = list(map(int, input().split())) A.append(a) B.append(b) C.append([a + b, i]) C = sorted(C, reverse=True) suma, sumb = 0, 0 for i in range(n): if i % 2: sumb += B[C[i][1]] else: suma += A[C[i][1]] print((suma - sumb))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] for i in range(n): a, b = AB[i] AB[i] = [a + b, a, b] AB.sort(key=lambda x: x[0], reverse=True) score_t, score_a = 0, 0 for i in range(n): if i % 2 == 0: score_t += AB[i][1] else: score_a += AB[i][2] print((score_t - score_a)) if __name__ == "__main__": resolve()
false
42.857143
[ "-n = int(eval(input()))", "-A, B, C = [], [], []", "-for i in range(n):", "- a, b = list(map(int, input().split()))", "- A.append(a)", "- B.append(b)", "- C.append([a + b, i])", "-C = sorted(C, reverse=True)", "-suma, sumb = 0, 0", "-for i in range(n):", "- if i % 2:", "- sumb += B[C[i][1]]", "- else:", "- suma += A[C[i][1]]", "-print((suma - sumb))", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ AB = [list(map(int, input().split())) for _ in range(n)]", "+ for i in range(n):", "+ a, b = AB[i]", "+ AB[i] = [a + b, a, b]", "+ AB.sort(key=lambda x: x[0], reverse=True)", "+ score_t, score_a = 0, 0", "+ for i in range(n):", "+ if i % 2 == 0:", "+ score_t += AB[i][1]", "+ else:", "+ score_a += AB[i][2]", "+ print((score_t - score_a))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.036945
0.037788
0.977696
[ "s018007764", "s323875234" ]
u729133443
p03246
python
s848635196
s730415280
216
86
36,356
20,520
Accepted
Accepted
60.19
n=int(eval(input())) v=list(map(int,input().split())) w=sorted(a for a in v[0::2]) x=sorted(a for a in v[1::2]) a=[[0,i]for i in range(10**5+1)] b=[[0,i]for i in range(10**5+1)] for t in w: a[t][0]+=1 for t in x: b[t][0]+=1 c=sorted(a) d=sorted(b) e=c[len(c)-1][0] i=c[len(c)-1][1] f=d[len(d)-1][0] g=c[len(c)-1][0] h=d[len(d)-1][0] for t in range(len(c)): if i!=d[len(d)-1][1]:break e=c[len(c)-t-1][0] i=c[len(c)-t-1][1] i=d[len(d)-1][1] for t in range(len(d)): if i!=c[len(c)-1][1]:break g=d[len(d)-t-1][0] i=d[len(d)-t-1][1] print((min(n-e-f,n-g-h)))
from collections import* n,*v=list(map(int,open(0).read().split())) a=Counter(v[::2]).most_common() b=Counter(v[1::2]).most_common() if a[0][0]==b[0][0]: if len(a)>1and len(b)>1: print((min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))) elif len(a)>1: print((n-a[1][1]-b[0][1])) elif len(b)>1: print((n-a[0][1]-b[1][1])) else: print((n//2)) else: print((n-a[0][1]-b[0][1]))
27
15
603
415
n = int(eval(input())) v = list(map(int, input().split())) w = sorted(a for a in v[0::2]) x = sorted(a for a in v[1::2]) a = [[0, i] for i in range(10**5 + 1)] b = [[0, i] for i in range(10**5 + 1)] for t in w: a[t][0] += 1 for t in x: b[t][0] += 1 c = sorted(a) d = sorted(b) e = c[len(c) - 1][0] i = c[len(c) - 1][1] f = d[len(d) - 1][0] g = c[len(c) - 1][0] h = d[len(d) - 1][0] for t in range(len(c)): if i != d[len(d) - 1][1]: break e = c[len(c) - t - 1][0] i = c[len(c) - t - 1][1] i = d[len(d) - 1][1] for t in range(len(d)): if i != c[len(c) - 1][1]: break g = d[len(d) - t - 1][0] i = d[len(d) - t - 1][1] print((min(n - e - f, n - g - h)))
from collections import * n, *v = list(map(int, open(0).read().split())) a = Counter(v[::2]).most_common() b = Counter(v[1::2]).most_common() if a[0][0] == b[0][0]: if len(a) > 1 and len(b) > 1: print((min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1]))) elif len(a) > 1: print((n - a[1][1] - b[0][1])) elif len(b) > 1: print((n - a[0][1] - b[1][1])) else: print((n // 2)) else: print((n - a[0][1] - b[0][1]))
false
44.444444
[ "-n = int(eval(input()))", "-v = list(map(int, input().split()))", "-w = sorted(a for a in v[0::2])", "-x = sorted(a for a in v[1::2])", "-a = [[0, i] for i in range(10**5 + 1)]", "-b = [[0, i] for i in range(10**5 + 1)]", "-for t in w:", "- a[t][0] += 1", "-for t in x:", "- b[t][0] += 1", "-c = sorted(a)", "-d = sorted(b)", "-e = c[len(c) - 1][0]", "-i = c[len(c) - 1][1]", "-f = d[len(d) - 1][0]", "-g = c[len(c) - 1][0]", "-h = d[len(d) - 1][0]", "-for t in range(len(c)):", "- if i != d[len(d) - 1][1]:", "- break", "- e = c[len(c) - t - 1][0]", "- i = c[len(c) - t - 1][1]", "-i = d[len(d) - 1][1]", "-for t in range(len(d)):", "- if i != c[len(c) - 1][1]:", "- break", "- g = d[len(d) - t - 1][0]", "- i = d[len(d) - t - 1][1]", "-print((min(n - e - f, n - g - h)))", "+from collections import *", "+", "+n, *v = list(map(int, open(0).read().split()))", "+a = Counter(v[::2]).most_common()", "+b = Counter(v[1::2]).most_common()", "+if a[0][0] == b[0][0]:", "+ if len(a) > 1 and len(b) > 1:", "+ print((min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])))", "+ elif len(a) > 1:", "+ print((n - a[1][1] - b[0][1]))", "+ elif len(b) > 1:", "+ print((n - a[0][1] - b[1][1]))", "+ else:", "+ print((n // 2))", "+else:", "+ print((n - a[0][1] - b[0][1]))" ]
false
0.352121
0.096324
3.655597
[ "s848635196", "s730415280" ]
u465699806
p03665
python
s489752601
s225526853
227
127
76,724
76,712
Accepted
Accepted
44.05
import random as rng import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump_impl(*objects): print(*objects, file=sys.stderr) def dump_dummy(*objects): pass dump = dump_impl if "DEBUG" in sys.argv else dump_dummy def odd(n): return n & 1 def even(n): return not odd(n) def comb(n, m): r = 1 for i in range(1, n+1): r *= i for i in range(1, m+1): r //= i for i in range(1, n-m+1): r //= i return r if __name__ == '__main__': N, P = map(int, input().split()) A = [int(n) % 2 for n in input().split()] cnt0 = len([a for a in A if a == 0]) cnt1 = len([a for a in A if a == 1]) ans = 0 if odd(P): for i in range(cnt1 + 1): if odd(i): ans += comb(cnt1, i) else: for i in range(cnt1 + 1): if even(i): ans += comb(cnt1, i) ans *= pow(2, cnt0) print(ans)
import random as rng import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump_impl(*objects): print(*objects, file=sys.stderr) def dump_dummy(*objects): pass dump = dump_impl if "DEBUG" in sys.argv else dump_dummy def odd(n): return n & 1 def even(n): return not odd(n) def comb(n, m): r = 1 for i in range(1, n+1): r *= i for i in range(1, m+1): r //= i for i in range(1, n-m+1): r //= i return r N, P = map(int, input().split()) A = [int(n) % 2 for n in input().split()] cnt0 = len([a for a in A if a == 0]) cnt1 = len([a for a in A if a == 1]) ans = 0 if odd(P): for i in range(cnt1 + 1): if odd(i): ans += comb(cnt1, i) else: for i in range(cnt1 + 1): if even(i): ans += comb(cnt1, i) ans *= pow(2, cnt0) print(ans)
54
53
1,079
991
import random as rng import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump_impl(*objects): print(*objects, file=sys.stderr) def dump_dummy(*objects): pass dump = dump_impl if "DEBUG" in sys.argv else dump_dummy def odd(n): return n & 1 def even(n): return not odd(n) def comb(n, m): r = 1 for i in range(1, n + 1): r *= i for i in range(1, m + 1): r //= i for i in range(1, n - m + 1): r //= i return r if __name__ == "__main__": N, P = map(int, input().split()) A = [int(n) % 2 for n in input().split()] cnt0 = len([a for a in A if a == 0]) cnt1 = len([a for a in A if a == 1]) ans = 0 if odd(P): for i in range(cnt1 + 1): if odd(i): ans += comb(cnt1, i) else: for i in range(cnt1 + 1): if even(i): ans += comb(cnt1, i) ans *= pow(2, cnt0) print(ans)
import random as rng import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump_impl(*objects): print(*objects, file=sys.stderr) def dump_dummy(*objects): pass dump = dump_impl if "DEBUG" in sys.argv else dump_dummy def odd(n): return n & 1 def even(n): return not odd(n) def comb(n, m): r = 1 for i in range(1, n + 1): r *= i for i in range(1, m + 1): r //= i for i in range(1, n - m + 1): r //= i return r N, P = map(int, input().split()) A = [int(n) % 2 for n in input().split()] cnt0 = len([a for a in A if a == 0]) cnt1 = len([a for a in A if a == 1]) ans = 0 if odd(P): for i in range(cnt1 + 1): if odd(i): ans += comb(cnt1, i) else: for i in range(cnt1 + 1): if even(i): ans += comb(cnt1, i) ans *= pow(2, cnt0) print(ans)
false
1.851852
[ "-if __name__ == \"__main__\":", "- N, P = map(int, input().split())", "- A = [int(n) % 2 for n in input().split()]", "- cnt0 = len([a for a in A if a == 0])", "- cnt1 = len([a for a in A if a == 1])", "- ans = 0", "- if odd(P):", "- for i in range(cnt1 + 1):", "- if odd(i):", "- ans += comb(cnt1, i)", "- else:", "- for i in range(cnt1 + 1):", "- if even(i):", "- ans += comb(cnt1, i)", "- ans *= pow(2, cnt0)", "- print(ans)", "+N, P = map(int, input().split())", "+A = [int(n) % 2 for n in input().split()]", "+cnt0 = len([a for a in A if a == 0])", "+cnt1 = len([a for a in A if a == 1])", "+ans = 0", "+if odd(P):", "+ for i in range(cnt1 + 1):", "+ if odd(i):", "+ ans += comb(cnt1, i)", "+else:", "+ for i in range(cnt1 + 1):", "+ if even(i):", "+ ans += comb(cnt1, i)", "+ans *= pow(2, cnt0)", "+print(ans)" ]
false
0.047363
0.046517
1.018181
[ "s489752601", "s225526853" ]
u780475861
p02773
python
s360130757
s396566181
682
283
61,044
38,476
Accepted
Accepted
58.5
from collections import Counter import sys n = int(sys.stdin.readline()) sn = sys.stdin.read().split() c = Counter(sn) c = sorted(list(c.items()), key=lambda x: (-x[1], x[0])) num = c[0][1] for i, j in c: if j == num: print(i) else: quit()
from collections import Counter import sys n = int(sys.stdin.readline()) sn = sys.stdin.read().split() c = Counter(sn) num = max(c.values()) ans = [i for i, j in list(c.items()) if j == num] ans.sort() print(('\n'.join(ans)))
12
9
256
225
from collections import Counter import sys n = int(sys.stdin.readline()) sn = sys.stdin.read().split() c = Counter(sn) c = sorted(list(c.items()), key=lambda x: (-x[1], x[0])) num = c[0][1] for i, j in c: if j == num: print(i) else: quit()
from collections import Counter import sys n = int(sys.stdin.readline()) sn = sys.stdin.read().split() c = Counter(sn) num = max(c.values()) ans = [i for i, j in list(c.items()) if j == num] ans.sort() print(("\n".join(ans)))
false
25
[ "-c = sorted(list(c.items()), key=lambda x: (-x[1], x[0]))", "-num = c[0][1]", "-for i, j in c:", "- if j == num:", "- print(i)", "- else:", "- quit()", "+num = max(c.values())", "+ans = [i for i, j in list(c.items()) if j == num]", "+ans.sort()", "+print((\"\\n\".join(ans)))" ]
false
0.104945
0.080311
1.306729
[ "s360130757", "s396566181" ]
u631277801
p03095
python
s426662583
s450530534
102
26
3,956
3,572
Accepted
Accepted
74.51
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter n = ni() s = ns() MOD = 10**9+7 cnt = Counter(s) ans = 1 for key, val in list(cnt.items()): ans *= (val+1) ans %= MOD ans -= 1 if ans < 0: ans += MOD print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter n = ni() s = ns() cnt = Counter(s) ans = 1 mod = 10**9+7 for k,v in list(cnt.items()): ans *= (v+1) ans %= mod ans -= 1 if ans < 0: ans += mod print(ans)
33
33
675
668
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter n = ni() s = ns() MOD = 10**9 + 7 cnt = Counter(s) ans = 1 for key, val in list(cnt.items()): ans *= val + 1 ans %= MOD ans -= 1 if ans < 0: ans += MOD print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter n = ni() s = ns() cnt = Counter(s) ans = 1 mod = 10**9 + 7 for k, v in list(cnt.items()): ans *= v + 1 ans %= mod ans -= 1 if ans < 0: ans += mod print(ans)
false
0
[ "-MOD = 10**9 + 7", "-for key, val in list(cnt.items()):", "- ans *= val + 1", "- ans %= MOD", "+mod = 10**9 + 7", "+for k, v in list(cnt.items()):", "+ ans *= v + 1", "+ ans %= mod", "- ans += MOD", "+ ans += mod" ]
false
0.076989
0.007323
10.513407
[ "s426662583", "s450530534" ]
u705617253
p03448
python
s562212782
s029028589
54
49
3,060
3,060
Accepted
Accepted
9.26
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) result = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: result += 1 print(result)
13
13
261
264
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) result = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: result += 1 print(result)
false
0
[ "-count = 0", "+result = 0", "- count += 1", "-print(count)", "+ result += 1", "+print(result)" ]
false
0.073618
0.3016
0.244091
[ "s562212782", "s029028589" ]
u904945034
p03671
python
s097816269
s466596825
29
24
9,120
9,104
Accepted
Accepted
17.24
ring = list(map(int,input().split())) print((sum(ring) - max(ring)))
a,b,c = sorted(map(int,input().split())) print((a+b))
2
2
67
52
ring = list(map(int, input().split())) print((sum(ring) - max(ring)))
a, b, c = sorted(map(int, input().split())) print((a + b))
false
0
[ "-ring = list(map(int, input().split()))", "-print((sum(ring) - max(ring)))", "+a, b, c = sorted(map(int, input().split()))", "+print((a + b))" ]
false
0.035202
0.039699
0.886718
[ "s097816269", "s466596825" ]
u397384480
p02996
python
s645200705
s805922113
1,625
1,021
72,172
68,460
Accepted
Accepted
37.17
N = int(eval(input())) A = [[None]*2 for i in range(N)] for i in range(N): A[i][1],A[i][0] = list(map(int,input().split())) A.sort() zum = 0 now = 0 for i in range(N): zum += A[i][1] now = A[i][0] if zum > now: print("No") break else: print("Yes")
import sys input = sys.stdin.readline N = int(eval(input())) A = [[None]*2 for i in range(N)] for i in range(N): A[i][1],A[i][0] = list(map(int,input().split())) A.sort() zum = 0 now = 0 for i in range(N): zum += A[i][1] now = A[i][0] if zum > now: print("No") break else: print("Yes")
17
20
289
331
N = int(eval(input())) A = [[None] * 2 for i in range(N)] for i in range(N): A[i][1], A[i][0] = list(map(int, input().split())) A.sort() zum = 0 now = 0 for i in range(N): zum += A[i][1] now = A[i][0] if zum > now: print("No") break else: print("Yes")
import sys input = sys.stdin.readline N = int(eval(input())) A = [[None] * 2 for i in range(N)] for i in range(N): A[i][1], A[i][0] = list(map(int, input().split())) A.sort() zum = 0 now = 0 for i in range(N): zum += A[i][1] now = A[i][0] if zum > now: print("No") break else: print("Yes")
false
15
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.040493
0.096798
0.418329
[ "s645200705", "s805922113" ]
u964998676
p03814
python
s923299000
s487242424
60
17
3,512
3,500
Accepted
Accepted
71.67
str = eval(input('')) start = -1 end = -1 for x in range(len(str)): if str[x] == 'A' and start == -1: start = x elif str[x] == 'Z': end = x print((end - start + 1))
str = eval(input('')) start = str.find('A') end = str.rfind('Z') print((end - start + 1))
9
4
176
84
str = eval(input("")) start = -1 end = -1 for x in range(len(str)): if str[x] == "A" and start == -1: start = x elif str[x] == "Z": end = x print((end - start + 1))
str = eval(input("")) start = str.find("A") end = str.rfind("Z") print((end - start + 1))
false
55.555556
[ "-start = -1", "-end = -1", "-for x in range(len(str)):", "- if str[x] == \"A\" and start == -1:", "- start = x", "- elif str[x] == \"Z\":", "- end = x", "+start = str.find(\"A\")", "+end = str.rfind(\"Z\")" ]
false
0.035695
0.037109
0.961909
[ "s923299000", "s487242424" ]
u380524497
p03682
python
s480574387
s902732303
1,211
1,052
89,796
86,420
Accepted
Accepted
13.13
import sys import heapq input = sys.stdin.readline n = int(eval(input())) Xs = [] Ys = [] for i in range(n): x, y = list(map(int, input().split())) Xs.append((x-1, i)) Ys.append((y-1, i)) Xs.sort() Ys.sort() edges = [[] for _ in range(n)] for i in range(n-1): x, node = Xs[i] nx, new_node = Xs[i+1] edges[node].append((nx-x, new_node)) edges[new_node].append((nx-x, node)) for i in range(n-1): y, node = Ys[i] ny, new_node = Ys[i+1] edges[node].append((ny-y, new_node)) edges[new_node].append((ny-y, node)) seen = [False] * n dist = [float('INF')] * n todo = [(0, 0)] while todo: d, node = heapq.heappop(todo) if seen[node]: continue seen[node] = True dist[node] = d for edge in edges[node]: nd, to = edge if dist[to] <= nd: continue heapq.heappush(todo, (nd, to)) print((sum(dist)))
import sys from heapq import heappush, heappop buf = sys.stdin.buffer def main(): n = int(buf.readline()) XY = list(map(int, buf.read().split())) Xs = [] Ys = [] for i, (x, y) in enumerate(zip(XY, XY)): Xs.append((x-1, i)) Ys.append((y-1, i)) Xs.sort() Ys.sort() edges = [[] for _ in range(n)] for i, ((x, node), (nx, new_node)) in enumerate(zip(Xs[:-1], Xs[1:])): edges[node].append((nx-x, new_node)) edges[new_node].append((nx-x, node)) for i, ((y, node), (ny, new_node)) in enumerate(zip(Ys[:-1], Ys[1:])): edges[node].append((ny-y, new_node)) edges[new_node].append((ny-y, node)) seen = [False] * n dist = [float('INF')] * n todo = [(0, 0)] while todo: d, node = heappop(todo) if seen[node]: continue seen[node] = True dist[node] = d while edges[node]: edge = edges[node].pop() nd, to = edge if dist[to] <= nd: continue heappush(todo, (nd, to)) print((sum(dist))) if __name__ == "__main__": main()
47
49
932
1,181
import sys import heapq input = sys.stdin.readline n = int(eval(input())) Xs = [] Ys = [] for i in range(n): x, y = list(map(int, input().split())) Xs.append((x - 1, i)) Ys.append((y - 1, i)) Xs.sort() Ys.sort() edges = [[] for _ in range(n)] for i in range(n - 1): x, node = Xs[i] nx, new_node = Xs[i + 1] edges[node].append((nx - x, new_node)) edges[new_node].append((nx - x, node)) for i in range(n - 1): y, node = Ys[i] ny, new_node = Ys[i + 1] edges[node].append((ny - y, new_node)) edges[new_node].append((ny - y, node)) seen = [False] * n dist = [float("INF")] * n todo = [(0, 0)] while todo: d, node = heapq.heappop(todo) if seen[node]: continue seen[node] = True dist[node] = d for edge in edges[node]: nd, to = edge if dist[to] <= nd: continue heapq.heappush(todo, (nd, to)) print((sum(dist)))
import sys from heapq import heappush, heappop buf = sys.stdin.buffer def main(): n = int(buf.readline()) XY = list(map(int, buf.read().split())) Xs = [] Ys = [] for i, (x, y) in enumerate(zip(XY, XY)): Xs.append((x - 1, i)) Ys.append((y - 1, i)) Xs.sort() Ys.sort() edges = [[] for _ in range(n)] for i, ((x, node), (nx, new_node)) in enumerate(zip(Xs[:-1], Xs[1:])): edges[node].append((nx - x, new_node)) edges[new_node].append((nx - x, node)) for i, ((y, node), (ny, new_node)) in enumerate(zip(Ys[:-1], Ys[1:])): edges[node].append((ny - y, new_node)) edges[new_node].append((ny - y, node)) seen = [False] * n dist = [float("INF")] * n todo = [(0, 0)] while todo: d, node = heappop(todo) if seen[node]: continue seen[node] = True dist[node] = d while edges[node]: edge = edges[node].pop() nd, to = edge if dist[to] <= nd: continue heappush(todo, (nd, to)) print((sum(dist))) if __name__ == "__main__": main()
false
4.081633
[ "-import heapq", "+from heapq import heappush, heappop", "-input = sys.stdin.readline", "-n = int(eval(input()))", "-Xs = []", "-Ys = []", "-for i in range(n):", "- x, y = list(map(int, input().split()))", "- Xs.append((x - 1, i))", "- Ys.append((y - 1, i))", "-Xs.sort()", "-Ys.sort()", "-edges = [[] for _ in range(n)]", "-for i in range(n - 1):", "- x, node = Xs[i]", "- nx, new_node = Xs[i + 1]", "- edges[node].append((nx - x, new_node))", "- edges[new_node].append((nx - x, node))", "-for i in range(n - 1):", "- y, node = Ys[i]", "- ny, new_node = Ys[i + 1]", "- edges[node].append((ny - y, new_node))", "- edges[new_node].append((ny - y, node))", "-seen = [False] * n", "-dist = [float(\"INF\")] * n", "-todo = [(0, 0)]", "-while todo:", "- d, node = heapq.heappop(todo)", "- if seen[node]:", "- continue", "- seen[node] = True", "- dist[node] = d", "- for edge in edges[node]:", "- nd, to = edge", "- if dist[to] <= nd:", "+buf = sys.stdin.buffer", "+", "+", "+def main():", "+ n = int(buf.readline())", "+ XY = list(map(int, buf.read().split()))", "+ Xs = []", "+ Ys = []", "+ for i, (x, y) in enumerate(zip(XY, XY)):", "+ Xs.append((x - 1, i))", "+ Ys.append((y - 1, i))", "+ Xs.sort()", "+ Ys.sort()", "+ edges = [[] for _ in range(n)]", "+ for i, ((x, node), (nx, new_node)) in enumerate(zip(Xs[:-1], Xs[1:])):", "+ edges[node].append((nx - x, new_node))", "+ edges[new_node].append((nx - x, node))", "+ for i, ((y, node), (ny, new_node)) in enumerate(zip(Ys[:-1], Ys[1:])):", "+ edges[node].append((ny - y, new_node))", "+ edges[new_node].append((ny - y, node))", "+ seen = [False] * n", "+ dist = [float(\"INF\")] * n", "+ todo = [(0, 0)]", "+ while todo:", "+ d, node = heappop(todo)", "+ if seen[node]:", "- heapq.heappush(todo, (nd, to))", "-print((sum(dist)))", "+ seen[node] = True", "+ dist[node] = d", "+ while edges[node]:", "+ edge = edges[node].pop()", "+ nd, to = edge", "+ if dist[to] <= nd:", "+ continue", "+ heappush(todo, (nd, to))", "+ print((sum(dist)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037684
0.036535
1.031441
[ "s480574387", "s902732303" ]
u190405389
p02767
python
s971017313
s687612398
184
168
38,512
38,384
Accepted
Accepted
8.7
n = int(eval(input())) x = list(map(int, input().split())) ans = 10**9 for p in range(1,101): a = 0 for k in x: a+=(k-p)**2 ans = min(ans,a) print(ans)
n = int(eval(input())) x = list(map(int, input().split())) s = round(sum(x)/n) ans = [(a-s)**2 for a in x] print((sum(ans)))
12
7
179
124
n = int(eval(input())) x = list(map(int, input().split())) ans = 10**9 for p in range(1, 101): a = 0 for k in x: a += (k - p) ** 2 ans = min(ans, a) print(ans)
n = int(eval(input())) x = list(map(int, input().split())) s = round(sum(x) / n) ans = [(a - s) ** 2 for a in x] print((sum(ans)))
false
41.666667
[ "-ans = 10**9", "-for p in range(1, 101):", "- a = 0", "- for k in x:", "- a += (k - p) ** 2", "- ans = min(ans, a)", "-print(ans)", "+s = round(sum(x) / n)", "+ans = [(a - s) ** 2 for a in x]", "+print((sum(ans)))" ]
false
0.036443
0.036434
1.00025
[ "s971017313", "s687612398" ]
u066337396
p02990
python
s395990410
s707689472
71
62
32,876
33,004
Accepted
Accepted
12.68
MOD = 10 ** 9 + 7 def main(): n, k = list(map(int, input().split())) a = aa = n + 1 - k b = 1 bb = k for i in range(1, k + 1): print(a * b % MOD) aa -= 1 a = a * aa / (i + 1) bb -= 1 b = b * bb / i if __name__ == '__main__': main()
MOD = 10 ** 9 + 7 def main(): n, k = list(map(int, input().split())) a = aa = n + 1 - k b = 1 bb = k for i in range(1, k + 1): print(a * b % MOD) aa -= 1 a = a * aa // (i + 1) bb -= 1 b = b * bb // i if __name__ == '__main__': main()
19
19
317
319
MOD = 10**9 + 7 def main(): n, k = list(map(int, input().split())) a = aa = n + 1 - k b = 1 bb = k for i in range(1, k + 1): print(a * b % MOD) aa -= 1 a = a * aa / (i + 1) bb -= 1 b = b * bb / i if __name__ == "__main__": main()
MOD = 10**9 + 7 def main(): n, k = list(map(int, input().split())) a = aa = n + 1 - k b = 1 bb = k for i in range(1, k + 1): print(a * b % MOD) aa -= 1 a = a * aa // (i + 1) bb -= 1 b = b * bb // i if __name__ == "__main__": main()
false
0
[ "- a = a * aa / (i + 1)", "+ a = a * aa // (i + 1)", "- b = b * bb / i", "+ b = b * bb // i" ]
false
0.036595
0.036498
1.002665
[ "s395990410", "s707689472" ]
u002459665
p03293
python
s362337975
s399353149
20
18
2,940
3,064
Accepted
Accepted
10
x = eval(input()) y = eval(input()) l = [] for i in range(len(x)): s = x[-i - 1:] + x[:-i - 1] l.append(s) if y in l: print("Yes") else: print("No")
def main(): x = eval(input()) y = eval(input()) l = [] for i in range(len(x)): s = x[-i - 1:] + x[:-i - 1] l.append(s) if y in l: print("Yes") else: print("No") def main2(): x = eval(input()) y = eval(input()) ans = False s = x for i in range(len(x)): if s == y: ans = True break s = s[-1] + s[:-1] if ans: print("Yes") else: print("No") if __name__ == '__main__': main2()
12
35
165
535
x = eval(input()) y = eval(input()) l = [] for i in range(len(x)): s = x[-i - 1 :] + x[: -i - 1] l.append(s) if y in l: print("Yes") else: print("No")
def main(): x = eval(input()) y = eval(input()) l = [] for i in range(len(x)): s = x[-i - 1 :] + x[: -i - 1] l.append(s) if y in l: print("Yes") else: print("No") def main2(): x = eval(input()) y = eval(input()) ans = False s = x for i in range(len(x)): if s == y: ans = True break s = s[-1] + s[:-1] if ans: print("Yes") else: print("No") if __name__ == "__main__": main2()
false
65.714286
[ "-x = eval(input())", "-y = eval(input())", "-l = []", "-for i in range(len(x)):", "- s = x[-i - 1 :] + x[: -i - 1]", "- l.append(s)", "-if y in l:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+def main():", "+ x = eval(input())", "+ y = eval(input())", "+ l = []", "+ for i in range(len(x)):", "+ s = x[-i - 1 :] + x[: -i - 1]", "+ l.append(s)", "+ if y in l:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")", "+", "+", "+def main2():", "+ x = eval(input())", "+ y = eval(input())", "+ ans = False", "+ s = x", "+ for i in range(len(x)):", "+ if s == y:", "+ ans = True", "+ break", "+ s = s[-1] + s[:-1]", "+ if ans:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")", "+", "+", "+if __name__ == \"__main__\":", "+ main2()" ]
false
0.035083
0.036063
0.972814
[ "s362337975", "s399353149" ]
u930705402
p02613
python
s056097290
s994223014
154
139
16,608
16,172
Accepted
Accepted
9.74
from collections import Counter N=int(eval(input())) S=[eval(input()) for i in range(N)] a=[0]*4 for i in range(N): if S[i]=='AC': a[0]+=1 elif S[i]=='WA': a[1]+=1 elif S[i]=='TLE': a[2]+=1 else: a[3]+=1 print(('AC','x',a[0])) print(('WA','x',a[1])) print(('TLE','x',a[2])) print(('RE','x',a[3]))
N=int(eval(input())) S=[eval(input()) for i in range(N)] print(('AC','x',S.count('AC'))) print(('WA','x',S.count('WA'))) print(('TLE','x',S.count('TLE'))) print(('RE','x',S.count('RE')))
17
6
340
171
from collections import Counter N = int(eval(input())) S = [eval(input()) for i in range(N)] a = [0] * 4 for i in range(N): if S[i] == "AC": a[0] += 1 elif S[i] == "WA": a[1] += 1 elif S[i] == "TLE": a[2] += 1 else: a[3] += 1 print(("AC", "x", a[0])) print(("WA", "x", a[1])) print(("TLE", "x", a[2])) print(("RE", "x", a[3]))
N = int(eval(input())) S = [eval(input()) for i in range(N)] print(("AC", "x", S.count("AC"))) print(("WA", "x", S.count("WA"))) print(("TLE", "x", S.count("TLE"))) print(("RE", "x", S.count("RE")))
false
64.705882
[ "-from collections import Counter", "-", "-a = [0] * 4", "-for i in range(N):", "- if S[i] == \"AC\":", "- a[0] += 1", "- elif S[i] == \"WA\":", "- a[1] += 1", "- elif S[i] == \"TLE\":", "- a[2] += 1", "- else:", "- a[3] += 1", "-print((\"AC\", \"x\", a[0]))", "-print((\"WA\", \"x\", a[1]))", "-print((\"TLE\", \"x\", a[2]))", "-print((\"RE\", \"x\", a[3]))", "+print((\"AC\", \"x\", S.count(\"AC\")))", "+print((\"WA\", \"x\", S.count(\"WA\")))", "+print((\"TLE\", \"x\", S.count(\"TLE\")))", "+print((\"RE\", \"x\", S.count(\"RE\")))" ]
false
0.048377
0.12243
0.395137
[ "s056097290", "s994223014" ]
u225388820
p02558
python
s031359525
s036272030
297
264
79,888
75,156
Accepted
Accepted
11.11
def main(): class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return - self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) ans = [0, 1] uf = UnionFind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t: print((ans[uf.same(u, v)])) else: uf.union(u, v) main()
class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return - self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = UnionFind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t: print((int(uf.same(u, v)))) else: uf.union(u, v)
83
79
2,411
2,099
def main(): class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return -self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) ans = [0, 1] uf = UnionFind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t: print((ans[uf.same(u, v)])) else: uf.union(u, v) main()
class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return -self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = UnionFind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t: print((int(uf.same(u, v)))) else: uf.union(u, v)
false
4.819277
[ "-def main():", "- class UnionFind:", "- def __init__(self, N):", "- \"\"\"", "- N:要素数", "- root:各要素の親要素の番号を格納するリスト.", "- ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.", "- rank:ランク", "- \"\"\"", "- self.N = N", "- self.root = [-1] * N", "- self.rank = [0] * N", "+class UnionFind:", "+ def __init__(self, N):", "+ \"\"\"", "+ N:要素数", "+ root:各要素の親要素の番号を格納するリスト.", "+ ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.", "+ rank:ランク", "+ \"\"\"", "+ self.N = N", "+ self.root = [-1] * N", "+ self.rank = [0] * N", "- def __repr__(self):", "- return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "+ def __repr__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "- def find(self, x):", "- \"\"\"頂点xの根を見つける\"\"\"", "- if self.root[x] < 0:", "- return x", "- else:", "- while self.root[x] >= 0:", "- x = self.root[x]", "- return x", "+ def find(self, x):", "+ \"\"\"頂点xの根を見つける\"\"\"", "+ if self.root[x] < 0:", "+ return x", "+ else:", "+ while self.root[x] >= 0:", "+ x = self.root[x]", "+ return x", "- def union(self, x, y):", "- \"\"\"x,yが属する木をunion\"\"\"", "- # 根を比較する", "- # すでに同じ木に属していた場合は何もしない.", "- # 違う木に属していた場合はrankを見てくっつける方を決める.", "- # rankが同じ時はrankを1増やす", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- elif self.rank[x] > self.rank[y]:", "- self.root[x] += self.root[y]", "- self.root[y] = x", "- else:", "- self.root[y] += self.root[x]", "- self.root[x] = y", "- if self.rank[x] == self.rank[y]:", "- self.rank[y] += 1", "+ def union(self, x, y):", "+ \"\"\"x,yが属する木をunion\"\"\"", "+ # 根を比較する", "+ # すでに同じ木に属していた場合は何もしない.", "+ # 違う木に属していた場合はrankを見てくっつける方を決める.", "+ # rankが同じ時はrankを1増やす", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ elif self.rank[x] > self.rank[y]:", "+ self.root[x] += self.root[y]", "+ self.root[y] = x", "+ else:", "+ self.root[y] += self.root[x]", "+ self.root[x] = y", "+ if self.rank[x] == self.rank[y]:", "+ self.rank[y] += 1", "- def same(self, x, y):", "- \"\"\"xとyが同じグループに属するかどうか\"\"\"", "- return self.find(x) == self.find(y)", "+ def same(self, x, y):", "+ \"\"\"xとyが同じグループに属するかどうか\"\"\"", "+ return self.find(x) == self.find(y)", "- def count(self, x):", "- \"\"\"頂点xが属する木のサイズを返す\"\"\"", "- return -self.root[self.find(x)]", "+ def count(self, x):", "+ \"\"\"頂点xが属する木のサイズを返す\"\"\"", "+ return -self.root[self.find(x)]", "- def members(self, x):", "- \"\"\"xが属する木の要素を列挙\"\"\"", "- _root = self.find(x)", "- return [i for i in range(self.N) if self.find == _root]", "+ def members(self, x):", "+ \"\"\"xが属する木の要素を列挙\"\"\"", "+ _root = self.find(x)", "+ return [i for i in range(self.N) if self.find == _root]", "- def roots(self):", "- \"\"\"森の根を列挙\"\"\"", "- return [i for i, x in enumerate(self.root) if x < 0]", "+ def roots(self):", "+ \"\"\"森の根を列挙\"\"\"", "+ return [i for i, x in enumerate(self.root) if x < 0]", "- def group_count(self):", "- \"\"\"連結成分の数\"\"\"", "- return len(self.roots())", "+ def group_count(self):", "+ \"\"\"連結成分の数\"\"\"", "+ return len(self.roots())", "- def all_group_members(self):", "- \"\"\"{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す\"\"\"", "- return {r: self.members(r) for r in self.roots()}", "-", "- import sys", "-", "- input = sys.stdin.readline", "- n, q = list(map(int, input().split()))", "- ans = [0, 1]", "- uf = UnionFind(n)", "- for i in range(q):", "- t, u, v = list(map(int, input().split()))", "- if t:", "- print((ans[uf.same(u, v)]))", "- else:", "- uf.union(u, v)", "+ def all_group_members(self):", "+ \"\"\"{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す\"\"\"", "+ return {r: self.members(r) for r in self.roots()}", "-main()", "+import sys", "+", "+input = sys.stdin.readline", "+n, q = list(map(int, input().split()))", "+uf = UnionFind(n)", "+for i in range(q):", "+ t, u, v = list(map(int, input().split()))", "+ if t:", "+ print((int(uf.same(u, v))))", "+ else:", "+ uf.union(u, v)" ]
false
0.041333
0.072474
0.570314
[ "s031359525", "s036272030" ]
u635540732
p02713
python
s649373912
s903744651
1,194
1,042
9,204
76,908
Accepted
Accepted
12.73
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) k=int(eval(input())) count=0 count+=k*(k+1)//2 for i in range(1,k+1): for j in range(1,k+1): if i!=j: count+=3*gcd(i,j) for a in range(1,k+1): for b in range(a+1,k+1): for c in range(b+1,k+1): count+=6*gcd(gcd(a,b),c) print(count)
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) k=int(eval(input())) count=0 for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): count+=gcd(gcd(a,b),c) print(count)
17
12
348
235
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) k = int(eval(input())) count = 0 count += k * (k + 1) // 2 for i in range(1, k + 1): for j in range(1, k + 1): if i != j: count += 3 * gcd(i, j) for a in range(1, k + 1): for b in range(a + 1, k + 1): for c in range(b + 1, k + 1): count += 6 * gcd(gcd(a, b), c) print(count)
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) k = int(eval(input())) count = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): count += gcd(gcd(a, b), c) print(count)
false
29.411765
[ "-count += k * (k + 1) // 2", "-for i in range(1, k + 1):", "- for j in range(1, k + 1):", "- if i != j:", "- count += 3 * gcd(i, j)", "- for b in range(a + 1, k + 1):", "- for c in range(b + 1, k + 1):", "- count += 6 * gcd(gcd(a, b), c)", "+ for b in range(1, k + 1):", "+ for c in range(1, k + 1):", "+ count += gcd(gcd(a, b), c)" ]
false
0.144518
0.073208
1.974085
[ "s649373912", "s903744651" ]
u564589929
p02861
python
s363949304
s926449248
384
326
3,064
3,064
Accepted
Accepted
15.1
import math from itertools import permutations def solve(): n = int(eval(input())) cord = [list(map(int, input().split())) for _ in range(n)] # print(cord) # dist = {} # for i in range(n): # for j in range(n): # if i == j: continue # d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2)) # dist[(i, j)] = d # print(dist) sm = 0 for cnt, i in enumerate(permutations(list(range(n)))): # print(i) for j in range(1, n): # print('aaa', i[j-1], i[j]) # d = dist[(i[j-1], i[j])] s = i[j-1] t = i[j] d = math.sqrt(pow(cord[s][0] - cord[t][0], 2) + pow(cord[s][1] - cord[t][1], 2)) # print(d) sm = sm + d print((sm / (cnt+1))) if __name__ == '__main__': solve()
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def printlist(lst, k='\n'): return k.join(list(map(str, lst))) INF = float('inf') from math import sqrt from itertools import permutations def solve(): n = II() town = [] for i in range(n): x, y = MI() town.append((x, y)) def f(t1, t2): x1, y1 = t1 x2, y2 = t2 return sqrt( (x1 - x2) ** 2 + (y1 - y2) ** 2) tot = 0 cnt = 0 for t in permutations(town, n): cnt += 1 d = 0 # print(t) for i in range(n-1): j = i + 1 d = f(t[i], t[j]) # print(d) tot += d print((tot / cnt)) if __name__ == '__main__': solve()
30
47
882
1,102
import math from itertools import permutations def solve(): n = int(eval(input())) cord = [list(map(int, input().split())) for _ in range(n)] # print(cord) # dist = {} # for i in range(n): # for j in range(n): # if i == j: continue # d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2)) # dist[(i, j)] = d # print(dist) sm = 0 for cnt, i in enumerate(permutations(list(range(n)))): # print(i) for j in range(1, n): # print('aaa', i[j-1], i[j]) # d = dist[(i[j-1], i[j])] s = i[j - 1] t = i[j] d = math.sqrt( pow(cord[s][0] - cord[t][0], 2) + pow(cord[s][1] - cord[t][1], 2) ) # print(d) sm = sm + d print((sm / (cnt + 1))) if __name__ == "__main__": solve()
import sys sys.setrecursionlimit(10**6) # input = sys.stdin.readline #### int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def printlist(lst, k="\n"): return k.join(list(map(str, lst))) INF = float("inf") from math import sqrt from itertools import permutations def solve(): n = II() town = [] for i in range(n): x, y = MI() town.append((x, y)) def f(t1, t2): x1, y1 = t1 x2, y2 = t2 return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) tot = 0 cnt = 0 for t in permutations(town, n): cnt += 1 d = 0 # print(t) for i in range(n - 1): j = i + 1 d = f(t[i], t[j]) # print(d) tot += d print((tot / cnt)) if __name__ == "__main__": solve()
false
36.170213
[ "-import math", "+import sys", "+", "+sys.setrecursionlimit(10**6)", "+# input = sys.stdin.readline ####", "+int1 = lambda x: int(x) - 1", "+", "+", "+def II():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def MI1():", "+ return list(map(int1, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI1():", "+ return list(map(int1, input().split()))", "+", "+", "+def LLI(rows_number):", "+ return [LI() for _ in range(rows_number)]", "+", "+", "+def printlist(lst, k=\"\\n\"):", "+ return k.join(list(map(str, lst)))", "+", "+", "+INF = float(\"inf\")", "+from math import sqrt", "- n = int(eval(input()))", "- cord = [list(map(int, input().split())) for _ in range(n)]", "- # print(cord)", "- # dist = {}", "- # for i in range(n):", "- # for j in range(n):", "- # if i == j: continue", "- # d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2))", "- # dist[(i, j)] = d", "- # print(dist)", "- sm = 0", "- for cnt, i in enumerate(permutations(list(range(n)))):", "- # print(i)", "- for j in range(1, n):", "- # print('aaa', i[j-1], i[j])", "- # d = dist[(i[j-1], i[j])]", "- s = i[j - 1]", "- t = i[j]", "- d = math.sqrt(", "- pow(cord[s][0] - cord[t][0], 2) + pow(cord[s][1] - cord[t][1], 2)", "- )", "+ n = II()", "+ town = []", "+ for i in range(n):", "+ x, y = MI()", "+ town.append((x, y))", "+", "+ def f(t1, t2):", "+ x1, y1 = t1", "+ x2, y2 = t2", "+ return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)", "+", "+ tot = 0", "+ cnt = 0", "+ for t in permutations(town, n):", "+ cnt += 1", "+ d = 0", "+ # print(t)", "+ for i in range(n - 1):", "+ j = i + 1", "+ d = f(t[i], t[j])", "- sm = sm + d", "- print((sm / (cnt + 1)))", "+ tot += d", "+ print((tot / cnt))" ]
false
0.035686
0.046799
0.76253
[ "s363949304", "s926449248" ]
u880480312
p02813
python
s755972746
s587524513
46
37
3,060
13,816
Accepted
Accepted
19.57
#<C> import math import itertools n = int(eval(input())) p = list(map(int,input().split())) q = list(map(int,input().split())) ans1=n ans2=n x = [i for i in range(1, n+1)] for i in itertools.permutations(x,n): if p < list(i): ans1 -= 1 if q < list(i): ans2 -= 1 print((abs(ans1-ans2)))
#<順列全探索> #n!通りの順列の組み合わせを全探索する方法。 #pythonにはitertoolsが存在するからそれを利用 #<ex.1(ABC150-C)> import itertools n = int(eval(input())) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) ls = list(itertools.permutations(list(range(1, n + 1)))) #順列作成 print((abs(ls.index(p) - ls.index(q))))
17
12
323
297
# <C> import math import itertools n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) ans1 = n ans2 = n x = [i for i in range(1, n + 1)] for i in itertools.permutations(x, n): if p < list(i): ans1 -= 1 if q < list(i): ans2 -= 1 print((abs(ans1 - ans2)))
# <順列全探索> # n!通りの順列の組み合わせを全探索する方法。 # pythonにはitertoolsが存在するからそれを利用 # <ex.1(ABC150-C)> import itertools n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) ls = list(itertools.permutations(list(range(1, n + 1)))) # 順列作成 print((abs(ls.index(p) - ls.index(q))))
false
29.411765
[ "-# <C>", "-import math", "+# <順列全探索>", "+# n!通りの順列の組み合わせを全探索する方法。", "+# pythonにはitertoolsが存在するからそれを利用", "+# <ex.1(ABC150-C)>", "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-ans1 = n", "-ans2 = n", "-x = [i for i in range(1, n + 1)]", "-for i in itertools.permutations(x, n):", "- if p < list(i):", "- ans1 -= 1", "- if q < list(i):", "- ans2 -= 1", "-print((abs(ans1 - ans2)))", "+p = tuple(map(int, input().split()))", "+q = tuple(map(int, input().split()))", "+ls = list(itertools.permutations(list(range(1, n + 1)))) # 順列作成", "+print((abs(ls.index(p) - ls.index(q))))" ]
false
0.04293
0.045409
0.945395
[ "s755972746", "s587524513" ]
u729133443
p02838
python
s196810779
s570876017
1,913
1,240
38,884
156,172
Accepted
Accepted
35.18
n,*a=list(map(int,open(0).read().split())) c=0 for i in range(61): i=2**i t=sum(i&b and 1for b in a) c=(c+t*(n-t)*i)%(10**9+7) print(c)
n,*a=list(map(int,open(0).read().split())) c=0 for i in range(61):t=sum(2**i&b>0for b in a);c=(c+t*(n-t)*2**i)%(10**9+7) print(c)
7
4
141
126
n, *a = list(map(int, open(0).read().split())) c = 0 for i in range(61): i = 2**i t = sum(i & b and 1 for b in a) c = (c + t * (n - t) * i) % (10**9 + 7) print(c)
n, *a = list(map(int, open(0).read().split())) c = 0 for i in range(61): t = sum(2**i & b > 0 for b in a) c = (c + t * (n - t) * 2**i) % (10**9 + 7) print(c)
false
42.857143
[ "- i = 2**i", "- t = sum(i & b and 1 for b in a)", "- c = (c + t * (n - t) * i) % (10**9 + 7)", "+ t = sum(2**i & b > 0 for b in a)", "+ c = (c + t * (n - t) * 2**i) % (10**9 + 7)" ]
false
0.043745
0.076628
0.570878
[ "s196810779", "s570876017" ]
u974935538
p03556
python
s875286243
s279086727
504
25
42,776
2,940
Accepted
Accepted
95.04
li =[] for i in range(1000000): li.append(i**2) N = int(eval(input())) ans = [] for i in range(1000000): if li[i]<=N: ans.append(li[i]) print((max(ans)))
n = int(eval(input())) a = 0 for i in range(n+1): if i*i <= n: a = i*i else: break print(a)
9
8
169
117
li = [] for i in range(1000000): li.append(i**2) N = int(eval(input())) ans = [] for i in range(1000000): if li[i] <= N: ans.append(li[i]) print((max(ans)))
n = int(eval(input())) a = 0 for i in range(n + 1): if i * i <= n: a = i * i else: break print(a)
false
11.111111
[ "-li = []", "-for i in range(1000000):", "- li.append(i**2)", "-N = int(eval(input()))", "-ans = []", "-for i in range(1000000):", "- if li[i] <= N:", "- ans.append(li[i])", "-print((max(ans)))", "+n = int(eval(input()))", "+a = 0", "+for i in range(n + 1):", "+ if i * i <= n:", "+ a = i * i", "+ else:", "+ break", "+print(a)" ]
false
1.738141
0.038033
45.701267
[ "s875286243", "s279086727" ]
u836939578
p02585
python
s791535516
s982328972
517
477
80,876
81,136
Accepted
Accepted
7.74
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(len(p)): p[i] -= 1 ans = float("-inf") for i in range(N): #iはスタートポジション pos = i #移動先のマスにかかれたポイント point = [] total = 0 while True: pos = p[pos] point.append(c[pos]) # totalは周期の和がマイナスかプラスかで後々場合分けするために使う。(周期が負だったら一巡目で終わらせたい。周期が正だったらできる限り後の方で終わらせたい) total += c[pos] #スタートポジションに戻ってきた==サイクルを検知した if pos == i: break l = len(point) t = 0 #total<0のときはif total>0以外の処理でまきとれる for i in range(l): t += point[i] #Kがi+1より小さい時のハンドリング if i+1 > K: break now = t if total > 0: #K-i-1の-1はポイントの一個目を獲得する時に1個動くので-1。二こ目のポイントを取る時はi=1で、K-2になり計算が合う。それをlでわり周期が何個回れるかを計算する #nowはtotalのセットが何個かあって、その先にpoint[i]がくっつくイメージ。[a,b,c] + [a,b,c] + [a,b,c] + ([a] or [a+b] + [a+b+c]) now += (total * ((K-i-1)//l)) ans = max(ans, now) print(ans)
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(len(p)): p[i] -= 1 ans = float("-inf") for i in range(N): #iはスタートポジション pos = i #移動先のマスにかかれたポイント point = [] total = 0 while True: pos = p[pos] point.append(c[pos]) # totalは周期の和がマイナスかプラスかで後々場合分けするために使う。(周期が負だったら一巡目で終わらせたい。周期が正だったらできる限り後の方で終わらせたい) total += c[pos] #スタートポジションに戻ってきた==サイクルを検知した if pos == i: break l = len(point) t = 0 #total<0のときはif total>0以外の処理でまきとれる for i in range(l): t += point[i] #Kがi+1より小さい時のハンドリング if i+1 > K: break now = t if total > 0: #K-i-1の-1はポイントの一個目を獲得する時に1個動くので-1。二こ目のポイントを取る時はi=1で、K-2になり計算が合う。それをlでわり周期が何個回れるかを計算する #nowはtotalのセットが何個かあって、その先にpoint[i]がくっつくイメージ。[a,b,c] + [a,b,c] + [a,b,c] + ([a] or [a+b] + [a+b+c]) cnt = (K-i-1) // l now += total * cnt ans = max(ans, now) print(ans)
43
44
1,052
1,074
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(len(p)): p[i] -= 1 ans = float("-inf") for i in range(N): # iはスタートポジション pos = i # 移動先のマスにかかれたポイント point = [] total = 0 while True: pos = p[pos] point.append(c[pos]) # totalは周期の和がマイナスかプラスかで後々場合分けするために使う。(周期が負だったら一巡目で終わらせたい。周期が正だったらできる限り後の方で終わらせたい) total += c[pos] # スタートポジションに戻ってきた==サイクルを検知した if pos == i: break l = len(point) t = 0 # total<0のときはif total>0以外の処理でまきとれる for i in range(l): t += point[i] # Kがi+1より小さい時のハンドリング if i + 1 > K: break now = t if total > 0: # K-i-1の-1はポイントの一個目を獲得する時に1個動くので-1。二こ目のポイントを取る時はi=1で、K-2になり計算が合う。それをlでわり周期が何個回れるかを計算する # nowはtotalのセットが何個かあって、その先にpoint[i]がくっつくイメージ。[a,b,c] + [a,b,c] + [a,b,c] + ([a] or [a+b] + [a+b+c]) now += total * ((K - i - 1) // l) ans = max(ans, now) print(ans)
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(len(p)): p[i] -= 1 ans = float("-inf") for i in range(N): # iはスタートポジション pos = i # 移動先のマスにかかれたポイント point = [] total = 0 while True: pos = p[pos] point.append(c[pos]) # totalは周期の和がマイナスかプラスかで後々場合分けするために使う。(周期が負だったら一巡目で終わらせたい。周期が正だったらできる限り後の方で終わらせたい) total += c[pos] # スタートポジションに戻ってきた==サイクルを検知した if pos == i: break l = len(point) t = 0 # total<0のときはif total>0以外の処理でまきとれる for i in range(l): t += point[i] # Kがi+1より小さい時のハンドリング if i + 1 > K: break now = t if total > 0: # K-i-1の-1はポイントの一個目を獲得する時に1個動くので-1。二こ目のポイントを取る時はi=1で、K-2になり計算が合う。それをlでわり周期が何個回れるかを計算する # nowはtotalのセットが何個かあって、その先にpoint[i]がくっつくイメージ。[a,b,c] + [a,b,c] + [a,b,c] + ([a] or [a+b] + [a+b+c]) cnt = (K - i - 1) // l now += total * cnt ans = max(ans, now) print(ans)
false
2.272727
[ "- now += total * ((K - i - 1) // l)", "+ cnt = (K - i - 1) // l", "+ now += total * cnt" ]
false
0.03561
0.036397
0.978391
[ "s791535516", "s982328972" ]
u631277801
p03283
python
s901853708
s439515272
811
739
46,652
46,800
Accepted
Accepted
8.88
from itertools import accumulate import sys sdin = sys.stdin.readline n,m,q = list(map(int, sdin().split())) lr = [] for i in range(m): l,r = list(map(int, sdin().split())) lr.append(tuple([l-1, r-1])) pq = [] for _ in range(q): p,q = list(map(int, sdin().split())) pq.append(tuple([p-1, q-1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # field_cumのy方向の累積和をとる for r in range(1,n): for l in range(n): field_cum[r][l] += field_cum[r-1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p,q in pq: if p > 0: print((field_cum[q][q] - field_cum[p-1][q] - field_cum[q][p-1] + field_cum[p-1][p-1])) else: print((field_cum[q][q]))
from itertools import accumulate import sys sdin = sys.stdin.readline n,m,q = list(map(int, sdin().split())) lr = [] for i in range(m): l,r = list(map(int, sdin().split())) lr.append(tuple([l, r])) pq = [] for _ in range(q): p,q = list(map(int, sdin().split())) pq.append(tuple([p, q])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n+1)] for _ in range(n+1)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n+1)] # field_cumのy方向の累積和をとる for r in range(1,n+1): for l in range(n+1): field_cum[r][l] += field_cum[r-1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p,q in pq: print((field_cum[q][q] - field_cum[p-1][q] - field_cum[q][p-1] + field_cum[p-1][p-1]))
37
33
862
801
from itertools import accumulate import sys sdin = sys.stdin.readline n, m, q = list(map(int, sdin().split())) lr = [] for i in range(m): l, r = list(map(int, sdin().split())) lr.append(tuple([l - 1, r - 1])) pq = [] for _ in range(q): p, q = list(map(int, sdin().split())) pq.append(tuple([p - 1, q - 1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # field_cumのy方向の累積和をとる for r in range(1, n): for l in range(n): field_cum[r][l] += field_cum[r - 1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p, q in pq: if p > 0: print( ( field_cum[q][q] - field_cum[p - 1][q] - field_cum[q][p - 1] + field_cum[p - 1][p - 1] ) ) else: print((field_cum[q][q]))
from itertools import accumulate import sys sdin = sys.stdin.readline n, m, q = list(map(int, sdin().split())) lr = [] for i in range(m): l, r = list(map(int, sdin().split())) lr.append(tuple([l, r])) pq = [] for _ in range(q): p, q = list(map(int, sdin().split())) pq.append(tuple([p, q])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n + 1)] for _ in range(n + 1)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n + 1)] # field_cumのy方向の累積和をとる for r in range(1, n + 1): for l in range(n + 1): field_cum[r][l] += field_cum[r - 1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p, q in pq: print( ( field_cum[q][q] - field_cum[p - 1][q] - field_cum[q][p - 1] + field_cum[p - 1][p - 1] ) )
false
10.810811
[ "- lr.append(tuple([l - 1, r - 1]))", "+ lr.append(tuple([l, r]))", "- pq.append(tuple([p - 1, q - 1]))", "+ pq.append(tuple([p, q]))", "-field = [[0 for _ in range(n)] for _ in range(n)]", "+field = [[0 for _ in range(n + 1)] for _ in range(n + 1)]", "-field_cum = [list(accumulate(field[i])) for i in range(n)]", "+field_cum = [list(accumulate(field[i])) for i in range(n + 1)]", "-for r in range(1, n):", "- for l in range(n):", "+for r in range(1, n + 1):", "+ for l in range(n + 1):", "- if p > 0:", "- print(", "- (", "- field_cum[q][q]", "- - field_cum[p - 1][q]", "- - field_cum[q][p - 1]", "- + field_cum[p - 1][p - 1]", "- )", "+ print(", "+ (", "+ field_cum[q][q]", "+ - field_cum[p - 1][q]", "+ - field_cum[q][p - 1]", "+ + field_cum[p - 1][p - 1]", "- else:", "- print((field_cum[q][q]))", "+ )" ]
false
0.042323
0.045135
0.937692
[ "s901853708", "s439515272" ]
u761320129
p03061
python
s009716060
s555975183
1,971
183
16,140
16,144
Accepted
Accepted
90.72
from fractions import gcd N = int(eval(input())) A = list(map(int,input().split())) class SegTree: def __init__(self,arr,func,unit): self.func = func self.unit = unit n = 1 while n < len(arr): n *= 2 self.n = n nodes = [unit]*(2*n-1) nodes[n-1:n-1+len(arr)] = arr for i in range(n-2,-1,-1): nodes[i] = func(nodes[2*i+1],nodes[2*i+2]) self.nodes = nodes def update(self,i,val): i += self.n-1 self.nodes[i] = val while i >= 0: i = (i - 1) // 2 self.nodes[i] = self.func(self.nodes[2*i+1], self.nodes[2*i+2]) def query(self,l,r): l += self.n r += self.n s = self.unit while l < r: if r & 1: r -= 1 s = self.func(s, self.nodes[r-1]) if l & 1: s = self.func(s, self.nodes[l-1]) l += 1 l >>= 1 r >>= 1 return s segt = SegTree(A, lambda x,y:gcd(x,y), 0) ans = 0 for i in range(N): l = segt.query(0,i) r = segt.query(i+1,N) g = gcd(l,r) ans = max(ans, g) print(ans)
from fractions import gcd N = int(eval(input())) A = list(map(int,input().split())) lc = [0] for a in A: lc.append(gcd(lc[-1], a)) rc = [0] for a in A[::-1]: rc.append(gcd(rc[-1], a)) rc.reverse() ans = 0 for l,r in zip(lc,rc[1:]): g = gcd(l,r) ans = max(ans, g) print(ans)
48
17
1,226
301
from fractions import gcd N = int(eval(input())) A = list(map(int, input().split())) class SegTree: def __init__(self, arr, func, unit): self.func = func self.unit = unit n = 1 while n < len(arr): n *= 2 self.n = n nodes = [unit] * (2 * n - 1) nodes[n - 1 : n - 1 + len(arr)] = arr for i in range(n - 2, -1, -1): nodes[i] = func(nodes[2 * i + 1], nodes[2 * i + 2]) self.nodes = nodes def update(self, i, val): i += self.n - 1 self.nodes[i] = val while i >= 0: i = (i - 1) // 2 self.nodes[i] = self.func(self.nodes[2 * i + 1], self.nodes[2 * i + 2]) def query(self, l, r): l += self.n r += self.n s = self.unit while l < r: if r & 1: r -= 1 s = self.func(s, self.nodes[r - 1]) if l & 1: s = self.func(s, self.nodes[l - 1]) l += 1 l >>= 1 r >>= 1 return s segt = SegTree(A, lambda x, y: gcd(x, y), 0) ans = 0 for i in range(N): l = segt.query(0, i) r = segt.query(i + 1, N) g = gcd(l, r) ans = max(ans, g) print(ans)
from fractions import gcd N = int(eval(input())) A = list(map(int, input().split())) lc = [0] for a in A: lc.append(gcd(lc[-1], a)) rc = [0] for a in A[::-1]: rc.append(gcd(rc[-1], a)) rc.reverse() ans = 0 for l, r in zip(lc, rc[1:]): g = gcd(l, r) ans = max(ans, g) print(ans)
false
64.583333
[ "-", "-", "-class SegTree:", "- def __init__(self, arr, func, unit):", "- self.func = func", "- self.unit = unit", "- n = 1", "- while n < len(arr):", "- n *= 2", "- self.n = n", "- nodes = [unit] * (2 * n - 1)", "- nodes[n - 1 : n - 1 + len(arr)] = arr", "- for i in range(n - 2, -1, -1):", "- nodes[i] = func(nodes[2 * i + 1], nodes[2 * i + 2])", "- self.nodes = nodes", "-", "- def update(self, i, val):", "- i += self.n - 1", "- self.nodes[i] = val", "- while i >= 0:", "- i = (i - 1) // 2", "- self.nodes[i] = self.func(self.nodes[2 * i + 1], self.nodes[2 * i + 2])", "-", "- def query(self, l, r):", "- l += self.n", "- r += self.n", "- s = self.unit", "- while l < r:", "- if r & 1:", "- r -= 1", "- s = self.func(s, self.nodes[r - 1])", "- if l & 1:", "- s = self.func(s, self.nodes[l - 1])", "- l += 1", "- l >>= 1", "- r >>= 1", "- return s", "-", "-", "-segt = SegTree(A, lambda x, y: gcd(x, y), 0)", "+lc = [0]", "+for a in A:", "+ lc.append(gcd(lc[-1], a))", "+rc = [0]", "+for a in A[::-1]:", "+ rc.append(gcd(rc[-1], a))", "+rc.reverse()", "-for i in range(N):", "- l = segt.query(0, i)", "- r = segt.query(i + 1, N)", "+for l, r in zip(lc, rc[1:]):" ]
false
0.062173
0.060981
1.019547
[ "s009716060", "s555975183" ]
u936985471
p04034
python
s652248360
s501014277
365
225
4,596
12,652
Accepted
Accepted
38.36
n,m=list(map(int,input().split())) b=[1]*n red=[False]*n red[0]=True for i in range(m): x,y=list(map(int,input().split())) x,y=x-1,y-1 if not b[x]: continue b[y]+=1 if red[x]: red[y]=True b[x]-=1 if b[x]==0: red[x]=False print((red.count(True)))
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) B = [1] * N possible = {0} for i in range(M): x,y = list(map(int,readline().split())) x,y = x - 1,y - 1 B[x] -= 1 B[y] += 1 if x in possible: possible.add(y) if x in possible and B[x] == 0: possible.remove(x) print((len(possible)))
18
17
283
336
n, m = list(map(int, input().split())) b = [1] * n red = [False] * n red[0] = True for i in range(m): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 if not b[x]: continue b[y] += 1 if red[x]: red[y] = True b[x] -= 1 if b[x] == 0: red[x] = False print((red.count(True)))
import sys readline = sys.stdin.readline N, M = list(map(int, readline().split())) B = [1] * N possible = {0} for i in range(M): x, y = list(map(int, readline().split())) x, y = x - 1, y - 1 B[x] -= 1 B[y] += 1 if x in possible: possible.add(y) if x in possible and B[x] == 0: possible.remove(x) print((len(possible)))
false
5.555556
[ "-n, m = list(map(int, input().split()))", "-b = [1] * n", "-red = [False] * n", "-red[0] = True", "-for i in range(m):", "- x, y = list(map(int, input().split()))", "+import sys", "+", "+readline = sys.stdin.readline", "+N, M = list(map(int, readline().split()))", "+B = [1] * N", "+possible = {0}", "+for i in range(M):", "+ x, y = list(map(int, readline().split()))", "- if not b[x]:", "- continue", "- b[y] += 1", "- if red[x]:", "- red[y] = True", "- b[x] -= 1", "- if b[x] == 0:", "- red[x] = False", "-print((red.count(True)))", "+ B[x] -= 1", "+ B[y] += 1", "+ if x in possible:", "+ possible.add(y)", "+ if x in possible and B[x] == 0:", "+ possible.remove(x)", "+print((len(possible)))" ]
false
0.037567
0.044298
0.848043
[ "s652248360", "s501014277" ]
u624475441
p03448
python
s355077649
s611501200
58
18
3,060
3,060
Accepted
Accepted
68.97
A,B,C,X=[int(eval(input()))for _ in[0]*4] ans=sum(a*500+b*100+c*50==X for a in range(A+1)for b in range(B+1)for c in range(C+1)) print(ans)
A, B, C, X = [int(eval(input())) for _ in range(4)] ans = 0 for a in range(A + 1): if X < 500 * a: break for b in range(B + 1): remainder = X - 500 * a - 100 * b if remainder < 0: break if remainder // 50 > C: continue ans += 1 print(ans)
3
13
135
316
A, B, C, X = [int(eval(input())) for _ in [0] * 4] ans = sum( a * 500 + b * 100 + c * 50 == X for a in range(A + 1) for b in range(B + 1) for c in range(C + 1) ) print(ans)
A, B, C, X = [int(eval(input())) for _ in range(4)] ans = 0 for a in range(A + 1): if X < 500 * a: break for b in range(B + 1): remainder = X - 500 * a - 100 * b if remainder < 0: break if remainder // 50 > C: continue ans += 1 print(ans)
false
76.923077
[ "-A, B, C, X = [int(eval(input())) for _ in [0] * 4]", "-ans = sum(", "- a * 500 + b * 100 + c * 50 == X", "- for a in range(A + 1)", "- for b in range(B + 1)", "- for c in range(C + 1)", "-)", "+A, B, C, X = [int(eval(input())) for _ in range(4)]", "+ans = 0", "+for a in range(A + 1):", "+ if X < 500 * a:", "+ break", "+ for b in range(B + 1):", "+ remainder = X - 500 * a - 100 * b", "+ if remainder < 0:", "+ break", "+ if remainder // 50 > C:", "+ continue", "+ ans += 1" ]
false
0.066161
0.037318
1.7729
[ "s355077649", "s611501200" ]
u923668099
p02258
python
s296857004
s617881879
310
260
7,676
15,696
Accepted
Accepted
16.13
import sys n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(sys.stdin.readline()) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
from sys import stdin inf = 10**9 + 1 def solve(): n = int(stdin.readline()) R = [int(stdin.readline()) for i in range(n)] ans = max_profit(n, R) print(ans) def max_profit(n, R): max_dif = -inf min_v = R[0] for i in range(1, n): max_dif = max(max_dif, R[i] - min_v) min_v = min(min_v, R[i]) return max_dif if __name__ == '__main__': solve()
13
22
220
419
import sys n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(sys.stdin.readline()) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
from sys import stdin inf = 10**9 + 1 def solve(): n = int(stdin.readline()) R = [int(stdin.readline()) for i in range(n)] ans = max_profit(n, R) print(ans) def max_profit(n, R): max_dif = -inf min_v = R[0] for i in range(1, n): max_dif = max(max_dif, R[i] - min_v) min_v = min(min_v, R[i]) return max_dif if __name__ == "__main__": solve()
false
40.909091
[ "-import sys", "+from sys import stdin", "-n = int(eval(input()))", "-dif_max = -float(\"inf\")", "-min_v = float(\"inf\")", "-for i in range(n):", "- r = int(sys.stdin.readline())", "- dif_max = max(dif_max, r - min_v)", "- min_v = min(min_v, r)", "-print(dif_max)", "+inf = 10**9 + 1", "+", "+", "+def solve():", "+ n = int(stdin.readline())", "+ R = [int(stdin.readline()) for i in range(n)]", "+ ans = max_profit(n, R)", "+ print(ans)", "+", "+", "+def max_profit(n, R):", "+ max_dif = -inf", "+ min_v = R[0]", "+ for i in range(1, n):", "+ max_dif = max(max_dif, R[i] - min_v)", "+ min_v = min(min_v, R[i])", "+ return max_dif", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.036189
0.039489
0.916445
[ "s296857004", "s617881879" ]
u709079466
p02628
python
s538341323
s549412124
39
28
9,260
9,192
Accepted
Accepted
28.21
n, k = list(map(int, input().split())) price_list = list(map(int, input().split())) sum = 0 min_index = 0 for i in range(k): min_index = price_list.index(min(price_list)) sum += price_list.pop(min_index) print(sum)
n, k = list(map(int, input().split())) price_list = list(map(int, input().split())) price_list.sort() sum = 0 for i in range(k): sum += price_list[i] print(sum)
11
10
229
170
n, k = list(map(int, input().split())) price_list = list(map(int, input().split())) sum = 0 min_index = 0 for i in range(k): min_index = price_list.index(min(price_list)) sum += price_list.pop(min_index) print(sum)
n, k = list(map(int, input().split())) price_list = list(map(int, input().split())) price_list.sort() sum = 0 for i in range(k): sum += price_list[i] print(sum)
false
9.090909
[ "+price_list.sort()", "-min_index = 0", "- min_index = price_list.index(min(price_list))", "- sum += price_list.pop(min_index)", "+ sum += price_list[i]" ]
false
0.10456
0.08621
1.212853
[ "s538341323", "s549412124" ]
u802963389
p02947
python
s599283807
s391417732
506
360
43,528
19,764
Accepted
Accepted
28.85
import collections N = int(eval(input())) s = [list(eval(input())) for _ in range(N)] mydict = {} ans = 0 for i in s: a = str(sorted(i)) if a in mydict: ans += mydict[a] mydict[a] += 1 else: mydict.setdefault(a,1) print(ans)
# C - Green Bin # https://atcoder.jp/contests/abc137/tasks/abc137_c from collections import Counter n = int(eval(input())) S = [] for _ in range(n): s = "".join(sorted(eval(input()))) S.append(s) C = Counter(S) ans = 0 for i in list(C.values()): ans += (i * (i - 1)) // 2 print(ans)
13
18
242
293
import collections N = int(eval(input())) s = [list(eval(input())) for _ in range(N)] mydict = {} ans = 0 for i in s: a = str(sorted(i)) if a in mydict: ans += mydict[a] mydict[a] += 1 else: mydict.setdefault(a, 1) print(ans)
# C - Green Bin # https://atcoder.jp/contests/abc137/tasks/abc137_c from collections import Counter n = int(eval(input())) S = [] for _ in range(n): s = "".join(sorted(eval(input()))) S.append(s) C = Counter(S) ans = 0 for i in list(C.values()): ans += (i * (i - 1)) // 2 print(ans)
false
27.777778
[ "-import collections", "+# C - Green Bin", "+# https://atcoder.jp/contests/abc137/tasks/abc137_c", "+from collections import Counter", "-N = int(eval(input()))", "-s = [list(eval(input())) for _ in range(N)]", "-mydict = {}", "+n = int(eval(input()))", "+S = []", "+for _ in range(n):", "+ s = \"\".join(sorted(eval(input())))", "+ S.append(s)", "+C = Counter(S)", "-for i in s:", "- a = str(sorted(i))", "- if a in mydict:", "- ans += mydict[a]", "- mydict[a] += 1", "- else:", "- mydict.setdefault(a, 1)", "+for i in list(C.values()):", "+ ans += (i * (i - 1)) // 2" ]
false
0.039409
0.039162
1.006305
[ "s599283807", "s391417732" ]
u672475305
p03472
python
s932671240
s547145584
1,328
373
17,880
12,156
Accepted
Accepted
71.91
import numpy as np n,h = list(map(int,input().split())) amax = 0 lst = [] for i in range(n): a,b = list(map(int,input().split())) amax = max(amax,a) lst.append(b) lst.sort(reverse = True) rui = np.cumsum(lst) cnt = 10**10 for k in range(n): if rui[k] > h: cnt = min(cnt,k+1) break else: tmp = (h - rui[k]) // amax if (h - rui[k]) % amax != 0: tmp += 1 cnt = min(cnt,k+tmp+1) print(cnt)
import math n,h = list(map(int,input().split())) A = [] B = [] for i in range(n): a,b = list(map(int,input().split())) A.append(a) B.append(b) x = max(A) B = sorted(B, reverse=True) B_lst = [] for i in range(n): if B[i] > x: B_lst.append(B[i]) cnt = 0 damage = 0 ans = None for i in range(len(B_lst)): damage += B_lst[i] cnt += 1 if damage >= h: ans = cnt break ans = cnt if damage < h: ans = cnt + math.ceil((h - damage)/x) print(ans)
23
30
469
519
import numpy as np n, h = list(map(int, input().split())) amax = 0 lst = [] for i in range(n): a, b = list(map(int, input().split())) amax = max(amax, a) lst.append(b) lst.sort(reverse=True) rui = np.cumsum(lst) cnt = 10**10 for k in range(n): if rui[k] > h: cnt = min(cnt, k + 1) break else: tmp = (h - rui[k]) // amax if (h - rui[k]) % amax != 0: tmp += 1 cnt = min(cnt, k + tmp + 1) print(cnt)
import math n, h = list(map(int, input().split())) A = [] B = [] for i in range(n): a, b = list(map(int, input().split())) A.append(a) B.append(b) x = max(A) B = sorted(B, reverse=True) B_lst = [] for i in range(n): if B[i] > x: B_lst.append(B[i]) cnt = 0 damage = 0 ans = None for i in range(len(B_lst)): damage += B_lst[i] cnt += 1 if damage >= h: ans = cnt break ans = cnt if damage < h: ans = cnt + math.ceil((h - damage) / x) print(ans)
false
23.333333
[ "-import numpy as np", "+import math", "-amax = 0", "-lst = []", "+A = []", "+B = []", "- amax = max(amax, a)", "- lst.append(b)", "-lst.sort(reverse=True)", "-rui = np.cumsum(lst)", "-cnt = 10**10", "-for k in range(n):", "- if rui[k] > h:", "- cnt = min(cnt, k + 1)", "+ A.append(a)", "+ B.append(b)", "+x = max(A)", "+B = sorted(B, reverse=True)", "+B_lst = []", "+for i in range(n):", "+ if B[i] > x:", "+ B_lst.append(B[i])", "+cnt = 0", "+damage = 0", "+ans = None", "+for i in range(len(B_lst)):", "+ damage += B_lst[i]", "+ cnt += 1", "+ if damage >= h:", "+ ans = cnt", "- else:", "- tmp = (h - rui[k]) // amax", "- if (h - rui[k]) % amax != 0:", "- tmp += 1", "- cnt = min(cnt, k + tmp + 1)", "-print(cnt)", "+ans = cnt", "+if damage < h:", "+ ans = cnt + math.ceil((h - damage) / x)", "+print(ans)" ]
false
0.61333
0.037974
16.151271
[ "s932671240", "s547145584" ]
u227082700
p02939
python
s547877930
s106945379
100
72
3,624
9,220
Accepted
Accepted
28
s=eval(input()) l=len(s) a=0 b="" i=0 while i<l: if s[i]!=b:a+=1;b=s[i] else:b="";i+=1;a+=1 i+=1 if i==l+1:a-=1 print(a)
s=eval(input())+"--" n=len(s)-1 ans=0 i=0 a="" while i<n: if s[i]==a: i+=1 a="" else: a=s[i] i+=1 ans+=1 print((ans-1))
11
14
132
144
s = eval(input()) l = len(s) a = 0 b = "" i = 0 while i < l: if s[i] != b: a += 1 b = s[i] else: b = "" i += 1 a += 1 i += 1 if i == l + 1: a -= 1 print(a)
s = eval(input()) + "--" n = len(s) - 1 ans = 0 i = 0 a = "" while i < n: if s[i] == a: i += 1 a = "" else: a = s[i] i += 1 ans += 1 print((ans - 1))
false
21.428571
[ "-s = eval(input())", "-l = len(s)", "-a = 0", "-b = \"\"", "+s = eval(input()) + \"--\"", "+n = len(s) - 1", "+ans = 0", "-while i < l:", "- if s[i] != b:", "- a += 1", "- b = s[i]", "+a = \"\"", "+while i < n:", "+ if s[i] == a:", "+ i += 1", "+ a = \"\"", "- b = \"\"", "- i += 1", "- a += 1", "+ a = s[i]", "- if i == l + 1:", "- a -= 1", "-print(a)", "+ ans += 1", "+print((ans - 1))" ]
false
0.04721
0.067483
0.699585
[ "s547877930", "s106945379" ]
u021548497
p02560
python
s294395433
s546169217
976
657
9,376
106,300
Accepted
Accepted
32.68
import sys input = sys.stdin.readline def floor_sum(n, m, a, b): ans = 0 if a >= m: ans += (n-1) * n * (a // m) // 2 a %= m if b >= m: ans += b * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ans ans += (n - (x_max + a - 1) // a) * y_max ans += floor_sum(y_max, a, m, (a - x_max % a) % a) return ans def main(): t = int(eval(input())) for i in range(t): n, m, a, b =list(map(int, input().split())) res = floor_sum(n, m, a, b) print(res) if __name__ == "__main__": main()
import sys import numba from numba import njit, i8 input = sys.stdin.readline @njit(i8(i8, i8, i8, i8), cache=True) def floor_sum(n, m, a, b): ans = 0 if a >= m: ans += (n-1) * n * (a // m) // 2 a %= m if b >= m: ans += b * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ans ans += (n - (x_max + a - 1) // a) * y_max ans += floor_sum(y_max, a, m, (a - x_max % a) % a) return ans def main(): t = int(eval(input())) for i in range(t): n, m, a, b = list(map(int, input().split())) res = floor_sum(n, m, a, b) print(res) if __name__ == "__main__": main()
31
33
654
733
import sys input = sys.stdin.readline def floor_sum(n, m, a, b): ans = 0 if a >= m: ans += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ans += b * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ans ans += (n - (x_max + a - 1) // a) * y_max ans += floor_sum(y_max, a, m, (a - x_max % a) % a) return ans def main(): t = int(eval(input())) for i in range(t): n, m, a, b = list(map(int, input().split())) res = floor_sum(n, m, a, b) print(res) if __name__ == "__main__": main()
import sys import numba from numba import njit, i8 input = sys.stdin.readline @njit(i8(i8, i8, i8, i8), cache=True) def floor_sum(n, m, a, b): ans = 0 if a >= m: ans += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ans += b * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ans ans += (n - (x_max + a - 1) // a) * y_max ans += floor_sum(y_max, a, m, (a - x_max % a) % a) return ans def main(): t = int(eval(input())) for i in range(t): n, m, a, b = list(map(int, input().split())) res = floor_sum(n, m, a, b) print(res) if __name__ == "__main__": main()
false
6.060606
[ "+import numba", "+from numba import njit, i8", "+@njit(i8(i8, i8, i8, i8), cache=True)" ]
false
0.036674
0.044152
0.830626
[ "s294395433", "s546169217" ]
u623819879
p03579
python
s549309049
s576228900
481
425
75,624
75,496
Accepted
Accepted
11.64
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def GI(V,E,Directed=False,index=0): org_inp=[] g=[[] for i in range(n)] for i in range(E): inp=LI() org_inp.append(inp) if index==0: inp[0]-=1 inp[1]-=1 if len(inp)==2: a,b=inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp)==3: a,b,c=inp aa=(inp[0],inp[2]) bb=(inp[1],inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g,org_inp def show(*inp,end='\n'): if show_flg: print(*inp,end=end) YN=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase u_alp=string.ascii_uppercase ts=time.time() #sys.setrecursionlimit(10**5) input=lambda: sys.stdin.readline().rstrip() def ran_input(): import random n=random.randint(4,16) a=sorted([random.randint(0,5) for _ in range(n)])[::-1] return n,a show_flg=False show_flg=True n,m=LI() g,c=GI(n,m) v=[-1 for i in range(n)] def bfs(x): q=[x] v[x]=0 while q: c=q.pop() for n in g[c]: if v[n]==-1: q.append(n) v[n]=1-v[c] bfs(0) flg=True for i in range(n): MM=max([v[nb] for nb in g[i]]) mm=min([v[nb] for nb in g[i]]) if MM==mm and MM!=v[i]: continue else: flg=False break #show(v,flg) if flg: ans=sum(v)*(n-sum(v))-m else: ans=n*(n-1)//2-m print(ans)
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def GI(V,E,Directed=False,index=0): org_inp=[] g=[[] for i in range(n)] for i in range(E): inp=LI() org_inp.append(inp) if index==0: inp[0]-=1 inp[1]-=1 if len(inp)==2: a,b=inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp)==3: a,b,c=inp aa=(inp[0],inp[2]) bb=(inp[1],inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g,org_inp def show(*inp,end='\n'): if show_flg: print(*inp,end=end) YN=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase u_alp=string.ascii_uppercase ts=time.time() #sys.setrecursionlimit(10**5) input=lambda: sys.stdin.readline().rstrip() def ran_input(): import random n=random.randint(4,16) a=sorted([random.randint(0,5) for _ in range(n)])[::-1] return n,a show_flg=False show_flg=True n,m=LI() g,c=GI(n,m) v=[-1 for i in range(n)] def IsBipartite(): q=[0] v[0]=0 while q: c=q.pop() for n in g[c]: if v[n]==-1: q.append(n) v[n]=1-v[c] elif v[n]==v[c]: return False return True if IsBipartite(): ans=sum(v)*(n-sum(v))-m else: ans=n*(n-1)//2-m print(ans)
98
88
2,104
1,978
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**5) input = lambda: sys.stdin.readline().rstrip() def ran_input(): import random n = random.randint(4, 16) a = sorted([random.randint(0, 5) for _ in range(n)])[::-1] return n, a show_flg = False show_flg = True n, m = LI() g, c = GI(n, m) v = [-1 for i in range(n)] def bfs(x): q = [x] v[x] = 0 while q: c = q.pop() for n in g[c]: if v[n] == -1: q.append(n) v[n] = 1 - v[c] bfs(0) flg = True for i in range(n): MM = max([v[nb] for nb in g[i]]) mm = min([v[nb] for nb in g[i]]) if MM == mm and MM != v[i]: continue else: flg = False break # show(v,flg) if flg: ans = sum(v) * (n - sum(v)) - m else: ans = n * (n - 1) // 2 - m print(ans)
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**5) input = lambda: sys.stdin.readline().rstrip() def ran_input(): import random n = random.randint(4, 16) a = sorted([random.randint(0, 5) for _ in range(n)])[::-1] return n, a show_flg = False show_flg = True n, m = LI() g, c = GI(n, m) v = [-1 for i in range(n)] def IsBipartite(): q = [0] v[0] = 0 while q: c = q.pop() for n in g[c]: if v[n] == -1: q.append(n) v[n] = 1 - v[c] elif v[n] == v[c]: return False return True if IsBipartite(): ans = sum(v) * (n - sum(v)) - m else: ans = n * (n - 1) // 2 - m print(ans)
false
10.204082
[ "-def bfs(x):", "- q = [x]", "- v[x] = 0", "+def IsBipartite():", "+ q = [0]", "+ v[0] = 0", "+ elif v[n] == v[c]:", "+ return False", "+ return True", "-bfs(0)", "-flg = True", "-for i in range(n):", "- MM = max([v[nb] for nb in g[i]])", "- mm = min([v[nb] for nb in g[i]])", "- if MM == mm and MM != v[i]:", "- continue", "- else:", "- flg = False", "- break", "-# show(v,flg)", "-if flg:", "+if IsBipartite():" ]
false
0.056098
0.127775
0.439035
[ "s549309049", "s576228900" ]
u062484507
p03835
python
s678675090
s432326569
1,905
18
2,940
3,060
Accepted
Accepted
99.06
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): for y in range(K + 1): z = S - (x + y) if 0 <= z <= K: if x <= S or y <= S: count += 1 print(count)
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): yz = S - x if yz < 0: break elif yz <= K: count += yz + 1 elif yz <= 2*K: count += K - (yz-K) + 1 print(count)
9
11
221
226
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): for y in range(K + 1): z = S - (x + y) if 0 <= z <= K: if x <= S or y <= S: count += 1 print(count)
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): yz = S - x if yz < 0: break elif yz <= K: count += yz + 1 elif yz <= 2 * K: count += K - (yz - K) + 1 print(count)
false
18.181818
[ "- for y in range(K + 1):", "- z = S - (x + y)", "- if 0 <= z <= K:", "- if x <= S or y <= S:", "- count += 1", "+ yz = S - x", "+ if yz < 0:", "+ break", "+ elif yz <= K:", "+ count += yz + 1", "+ elif yz <= 2 * K:", "+ count += K - (yz - K) + 1" ]
false
0.047849
0.046968
1.018765
[ "s678675090", "s432326569" ]
u926412290
p02707
python
s425780020
s787241795
229
155
40,824
94,384
Accepted
Accepted
32.31
N = int(eval(input())) boss = {i+1: 0 for i in range(N)} A = list(map(int, input().split())) for i in A: boss[i] += 1 for i in range(N): print((boss[i+1]))
N = int(input()) boss = [0] * N A = map(lambda x:int(x) - 1, input().split()) for i in A: boss[i] += 1 print(*boss, sep='\n')
9
8
159
138
N = int(eval(input())) boss = {i + 1: 0 for i in range(N)} A = list(map(int, input().split())) for i in A: boss[i] += 1 for i in range(N): print((boss[i + 1]))
N = int(input()) boss = [0] * N A = map(lambda x: int(x) - 1, input().split()) for i in A: boss[i] += 1 print(*boss, sep="\n")
false
11.111111
[ "-N = int(eval(input()))", "-boss = {i + 1: 0 for i in range(N)}", "-A = list(map(int, input().split()))", "+N = int(input())", "+boss = [0] * N", "+A = map(lambda x: int(x) - 1, input().split())", "-for i in range(N):", "- print((boss[i + 1]))", "+print(*boss, sep=\"\\n\")" ]
false
0.036796
0.036025
1.021393
[ "s425780020", "s787241795" ]
u327466606
p03716
python
s534198400
s254528422
722
297
59,052
38,748
Accepted
Accepted
58.86
from heapq import * N = int(eval(input())) A = list(map(int, input().split())) A_indexed = [(a, i) for i, a in enumerate(A)] def scores(): # initial N:2N selected_left = A[:N] # min heap heapify(selected_left) l_score = sum(selected_left) temp = sorted(A_indexed[N:]) selected_right_set = set(temp[:N]) unselected_right = temp[N:] # min heap del temp r_score = sum([x[0] for x in selected_right_set]) yield l_score,r_score for i in range(N, 2*N): a = A[i] # left 使うものを減らす, right 使うものを増やす if selected_left[0] < a: l_score -= heapreplace(selected_left, a) l_score += a if (a,i) in selected_right_set: r_score -= a selected_right_set.remove((a,i)) n_element = heappop(unselected_right) while n_element[1] <= i: n_element = heappop(unselected_right) selected_right_set.add(n_element) r_score += n_element[0] yield l_score,r_score # print(list(scores())) print((max([x[0]-x[1] for x in scores()])))
from heapq import * N = int(eval(input())) A = list(map(int, input().split())) B = list([-x for x in reversed(A)]) def left_scores(L): s = sum(L[:N]) scores = [s] q = L[:N] heapify(q) for e in L[N:2*N]: s -= heappushpop(q, e) s += e scores.append(s) return scores print((max([x[0]+x[1] for x in zip(left_scores(A), reversed(left_scores(B)))])))
42
19
1,049
393
from heapq import * N = int(eval(input())) A = list(map(int, input().split())) A_indexed = [(a, i) for i, a in enumerate(A)] def scores(): # initial N:2N selected_left = A[:N] # min heap heapify(selected_left) l_score = sum(selected_left) temp = sorted(A_indexed[N:]) selected_right_set = set(temp[:N]) unselected_right = temp[N:] # min heap del temp r_score = sum([x[0] for x in selected_right_set]) yield l_score, r_score for i in range(N, 2 * N): a = A[i] # left 使うものを減らす, right 使うものを増やす if selected_left[0] < a: l_score -= heapreplace(selected_left, a) l_score += a if (a, i) in selected_right_set: r_score -= a selected_right_set.remove((a, i)) n_element = heappop(unselected_right) while n_element[1] <= i: n_element = heappop(unselected_right) selected_right_set.add(n_element) r_score += n_element[0] yield l_score, r_score # print(list(scores())) print((max([x[0] - x[1] for x in scores()])))
from heapq import * N = int(eval(input())) A = list(map(int, input().split())) B = list([-x for x in reversed(A)]) def left_scores(L): s = sum(L[:N]) scores = [s] q = L[:N] heapify(q) for e in L[N : 2 * N]: s -= heappushpop(q, e) s += e scores.append(s) return scores print((max([x[0] + x[1] for x in zip(left_scores(A), reversed(left_scores(B)))])))
false
54.761905
[ "-A_indexed = [(a, i) for i, a in enumerate(A)]", "+B = list([-x for x in reversed(A)])", "-def scores():", "- # initial N:2N", "- selected_left = A[:N] # min heap", "- heapify(selected_left)", "- l_score = sum(selected_left)", "- temp = sorted(A_indexed[N:])", "- selected_right_set = set(temp[:N])", "- unselected_right = temp[N:] # min heap", "- del temp", "- r_score = sum([x[0] for x in selected_right_set])", "- yield l_score, r_score", "- for i in range(N, 2 * N):", "- a = A[i]", "- # left 使うものを減らす, right 使うものを増やす", "- if selected_left[0] < a:", "- l_score -= heapreplace(selected_left, a)", "- l_score += a", "- if (a, i) in selected_right_set:", "- r_score -= a", "- selected_right_set.remove((a, i))", "- n_element = heappop(unselected_right)", "- while n_element[1] <= i:", "- n_element = heappop(unselected_right)", "- selected_right_set.add(n_element)", "- r_score += n_element[0]", "- yield l_score, r_score", "+def left_scores(L):", "+ s = sum(L[:N])", "+ scores = [s]", "+ q = L[:N]", "+ heapify(q)", "+ for e in L[N : 2 * N]:", "+ s -= heappushpop(q, e)", "+ s += e", "+ scores.append(s)", "+ return scores", "-# print(list(scores()))", "-print((max([x[0] - x[1] for x in scores()])))", "+print((max([x[0] + x[1] for x in zip(left_scores(A), reversed(left_scores(B)))])))" ]
false
0.163717
0.166723
0.981966
[ "s534198400", "s254528422" ]
u077291787
p03732
python
s054185848
s483849901
33
30
3,064
3,064
Accepted
Accepted
9.09
# ABC060D - Simple Knapsack (ARC073D) # exhaustive search from itertools import accumulate def main(): N, W, *A = list(map(int, open(0).read().split())) V, x = [[] for _ in range(4)], A[0] # x: w1 (W1 ≤ wi ≤ w1 + 3) for i in range(0, 2 * N, 2): # group by weight w, v = A[i : i + 2] V[w - x] += [v] for i in range(4): # V[i][j] := max value of picking up j items from group i V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1))) L = [len(v) for v in V] ans = 0 for i in range(L[0]): for j in range(L[1]): for k in range(L[2]): w = i * x + j * (x + 1) + k * (x + 2) if w > W: break l = min(L[3] - 1, (W - w) // (x + 3)) v = V[0][i] + V[1][j] + V[2][k] + V[3][l] ans = max(ans, v) print(ans) if __name__ == "__main__": main()
# ABC060D - Simple Knapsack (ARC073D) from itertools import accumulate as acc def main(): N, W, *A = list(map(int, open(0).read().split())) V, x = [[] for _ in range(4)], A[0] # x: w1 (W1 ≤ wi ≤ w1 + 3) for w, v in zip(*[iter(A)] * 2): # group by weight V[w - x].append(v) for i in range(4): # V[i][j] := max value of picking up j items from group i V[i] = tuple(acc([0] + sorted(V[i], reverse=1))) L = [len(v) for v in V] ans = 0 for i in range(L[0]): for j in range(L[1]): for k in range(L[2]): w = i * x + j * (x + 1) + k * (x + 2) if w > W: break l = min(L[3] - 1, (W - w) // (x + 3)) v = V[0][i] + V[1][j] + V[2][k] + V[3][l] ans = max(ans, v) print(ans) if __name__ == "__main__": main()
29
27
935
892
# ABC060D - Simple Knapsack (ARC073D) # exhaustive search from itertools import accumulate def main(): N, W, *A = list(map(int, open(0).read().split())) V, x = [[] for _ in range(4)], A[0] # x: w1 (W1 ≤ wi ≤ w1 + 3) for i in range(0, 2 * N, 2): # group by weight w, v = A[i : i + 2] V[w - x] += [v] for i in range(4): # V[i][j] := max value of picking up j items from group i V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1))) L = [len(v) for v in V] ans = 0 for i in range(L[0]): for j in range(L[1]): for k in range(L[2]): w = i * x + j * (x + 1) + k * (x + 2) if w > W: break l = min(L[3] - 1, (W - w) // (x + 3)) v = V[0][i] + V[1][j] + V[2][k] + V[3][l] ans = max(ans, v) print(ans) if __name__ == "__main__": main()
# ABC060D - Simple Knapsack (ARC073D) from itertools import accumulate as acc def main(): N, W, *A = list(map(int, open(0).read().split())) V, x = [[] for _ in range(4)], A[0] # x: w1 (W1 ≤ wi ≤ w1 + 3) for w, v in zip(*[iter(A)] * 2): # group by weight V[w - x].append(v) for i in range(4): # V[i][j] := max value of picking up j items from group i V[i] = tuple(acc([0] + sorted(V[i], reverse=1))) L = [len(v) for v in V] ans = 0 for i in range(L[0]): for j in range(L[1]): for k in range(L[2]): w = i * x + j * (x + 1) + k * (x + 2) if w > W: break l = min(L[3] - 1, (W - w) // (x + 3)) v = V[0][i] + V[1][j] + V[2][k] + V[3][l] ans = max(ans, v) print(ans) if __name__ == "__main__": main()
false
6.896552
[ "-# exhaustive search", "-from itertools import accumulate", "+from itertools import accumulate as acc", "- for i in range(0, 2 * N, 2): # group by weight", "- w, v = A[i : i + 2]", "- V[w - x] += [v]", "+ for w, v in zip(*[iter(A)] * 2): # group by weight", "+ V[w - x].append(v)", "- V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))", "+ V[i] = tuple(acc([0] + sorted(V[i], reverse=1)))" ]
false
0.092258
0.046244
1.995027
[ "s054185848", "s483849901" ]
u352394527
p00315
python
s754186393
s169097657
5,270
4,590
68,828
68,824
Accepted
Accepted
12.9
C, n = list(map(int, input().split())) mp = [eval(input()) for _ in range(n)] diff_dic = {} def change(x, y): global diff_dic if (x, y) in diff_dic: diff_dic.pop((x, y)) else: diff_dic[(x, y)] = True for y in range(n // 2): for x in range(n // 2): base = mp[y][x] if mp[y][n - 1 - x] != base: change(n - 1 - x, y) if mp[n - 1 - y][x] != base: change(x, n - 1 - y) if mp[n - 1 - y][n - 1 - x] != base: change(n - 1 - x, n - 1 - y) if n % 2: for x in range(n // 2): if mp[n // 2][x] != mp[n // 2][n - 1 - x]: chenge(n - 1 - x, n // 2) for y in range(n // 2): if mp[y][n // 2] != mp[n - 1 - y][n // 2]: change(n // 2, n - 1 - y) ans = 0 if not diff_dic: ans += 1 for _ in range(C - 1): d = int(eval(input())) for _ in range(d): r, c = list(map(int, input().split())) r -= 1 c -= 1 if r < n // 2 and c < n // 2: change(c, n - 1 - r) change(n - 1 - c, r) change(n - 1 - c, n - 1 - r) elif n % 2 and r == n // 2 and c != n // 2: change(max(c, n - 1 - c), r) elif n % 2 and r != n // 2 and c == n // 2: change(c, max(r, n - 1 - r)) else: change(c, r) if not diff_dic: ans += 1 print(ans)
def main(): C, n = list(map(int, input().split())) mp = [eval(input()) for _ in range(n)] diff_dic = {} def change(x, y): if (x, y) in diff_dic: diff_dic.pop((x, y)) else: diff_dic[(x, y)] = True for y in range(n // 2): for x in range(n // 2): base = mp[y][x] if mp[y][n - 1 - x] != base: change(n - 1 - x, y) if mp[n - 1 - y][x] != base: change(x, n - 1 - y) if mp[n - 1 - y][n - 1 - x] != base: change(n - 1 - x, n - 1 - y) if n % 2: for x in range(n // 2): if mp[n // 2][x] != mp[n // 2][n - 1 - x]: chenge(n - 1 - x, n // 2) for y in range(n // 2): if mp[y][n // 2] != mp[n - 1 - y][n // 2]: change(n // 2, n - 1 - y) ans = 0 if not diff_dic: ans += 1 for _ in range(C - 1): d = int(eval(input())) for _ in range(d): r, c = list(map(int, input().split())) r -= 1 c -= 1 if r < n // 2 and c < n // 2: change(c, n - 1 - r) change(n - 1 - c, r) change(n - 1 - c, n - 1 - r) elif n % 2 and r == n // 2 and c != n // 2: change(max(c, n - 1 - c), r) elif n % 2 and r != n // 2 and c == n // 2: change(c, max(r, n - 1 - r)) else: change(c, r) if not diff_dic: ans += 1 print(ans) main()
50
53
1,261
1,365
C, n = list(map(int, input().split())) mp = [eval(input()) for _ in range(n)] diff_dic = {} def change(x, y): global diff_dic if (x, y) in diff_dic: diff_dic.pop((x, y)) else: diff_dic[(x, y)] = True for y in range(n // 2): for x in range(n // 2): base = mp[y][x] if mp[y][n - 1 - x] != base: change(n - 1 - x, y) if mp[n - 1 - y][x] != base: change(x, n - 1 - y) if mp[n - 1 - y][n - 1 - x] != base: change(n - 1 - x, n - 1 - y) if n % 2: for x in range(n // 2): if mp[n // 2][x] != mp[n // 2][n - 1 - x]: chenge(n - 1 - x, n // 2) for y in range(n // 2): if mp[y][n // 2] != mp[n - 1 - y][n // 2]: change(n // 2, n - 1 - y) ans = 0 if not diff_dic: ans += 1 for _ in range(C - 1): d = int(eval(input())) for _ in range(d): r, c = list(map(int, input().split())) r -= 1 c -= 1 if r < n // 2 and c < n // 2: change(c, n - 1 - r) change(n - 1 - c, r) change(n - 1 - c, n - 1 - r) elif n % 2 and r == n // 2 and c != n // 2: change(max(c, n - 1 - c), r) elif n % 2 and r != n // 2 and c == n // 2: change(c, max(r, n - 1 - r)) else: change(c, r) if not diff_dic: ans += 1 print(ans)
def main(): C, n = list(map(int, input().split())) mp = [eval(input()) for _ in range(n)] diff_dic = {} def change(x, y): if (x, y) in diff_dic: diff_dic.pop((x, y)) else: diff_dic[(x, y)] = True for y in range(n // 2): for x in range(n // 2): base = mp[y][x] if mp[y][n - 1 - x] != base: change(n - 1 - x, y) if mp[n - 1 - y][x] != base: change(x, n - 1 - y) if mp[n - 1 - y][n - 1 - x] != base: change(n - 1 - x, n - 1 - y) if n % 2: for x in range(n // 2): if mp[n // 2][x] != mp[n // 2][n - 1 - x]: chenge(n - 1 - x, n // 2) for y in range(n // 2): if mp[y][n // 2] != mp[n - 1 - y][n // 2]: change(n // 2, n - 1 - y) ans = 0 if not diff_dic: ans += 1 for _ in range(C - 1): d = int(eval(input())) for _ in range(d): r, c = list(map(int, input().split())) r -= 1 c -= 1 if r < n // 2 and c < n // 2: change(c, n - 1 - r) change(n - 1 - c, r) change(n - 1 - c, n - 1 - r) elif n % 2 and r == n // 2 and c != n // 2: change(max(c, n - 1 - c), r) elif n % 2 and r != n // 2 and c == n // 2: change(c, max(r, n - 1 - r)) else: change(c, r) if not diff_dic: ans += 1 print(ans) main()
false
5.660377
[ "-C, n = list(map(int, input().split()))", "-mp = [eval(input()) for _ in range(n)]", "-diff_dic = {}", "+def main():", "+ C, n = list(map(int, input().split()))", "+ mp = [eval(input()) for _ in range(n)]", "+ diff_dic = {}", "+", "+ def change(x, y):", "+ if (x, y) in diff_dic:", "+ diff_dic.pop((x, y))", "+ else:", "+ diff_dic[(x, y)] = True", "+", "+ for y in range(n // 2):", "+ for x in range(n // 2):", "+ base = mp[y][x]", "+ if mp[y][n - 1 - x] != base:", "+ change(n - 1 - x, y)", "+ if mp[n - 1 - y][x] != base:", "+ change(x, n - 1 - y)", "+ if mp[n - 1 - y][n - 1 - x] != base:", "+ change(n - 1 - x, n - 1 - y)", "+ if n % 2:", "+ for x in range(n // 2):", "+ if mp[n // 2][x] != mp[n // 2][n - 1 - x]:", "+ chenge(n - 1 - x, n // 2)", "+ for y in range(n // 2):", "+ if mp[y][n // 2] != mp[n - 1 - y][n // 2]:", "+ change(n // 2, n - 1 - y)", "+ ans = 0", "+ if not diff_dic:", "+ ans += 1", "+ for _ in range(C - 1):", "+ d = int(eval(input()))", "+ for _ in range(d):", "+ r, c = list(map(int, input().split()))", "+ r -= 1", "+ c -= 1", "+ if r < n // 2 and c < n // 2:", "+ change(c, n - 1 - r)", "+ change(n - 1 - c, r)", "+ change(n - 1 - c, n - 1 - r)", "+ elif n % 2 and r == n // 2 and c != n // 2:", "+ change(max(c, n - 1 - c), r)", "+ elif n % 2 and r != n // 2 and c == n // 2:", "+ change(c, max(r, n - 1 - r))", "+ else:", "+ change(c, r)", "+ if not diff_dic:", "+ ans += 1", "+ print(ans)", "-def change(x, y):", "- global diff_dic", "- if (x, y) in diff_dic:", "- diff_dic.pop((x, y))", "- else:", "- diff_dic[(x, y)] = True", "-", "-", "-for y in range(n // 2):", "- for x in range(n // 2):", "- base = mp[y][x]", "- if mp[y][n - 1 - x] != base:", "- change(n - 1 - x, y)", "- if mp[n - 1 - y][x] != base:", "- change(x, n - 1 - y)", "- if mp[n - 1 - y][n - 1 - x] != base:", "- change(n - 1 - x, n - 1 - y)", "-if n % 2:", "- for x in range(n // 2):", "- if mp[n // 2][x] != mp[n // 2][n - 1 - x]:", "- chenge(n - 1 - x, n // 2)", "- for y in range(n // 2):", "- if mp[y][n // 2] != mp[n - 1 - y][n // 2]:", "- change(n // 2, n - 1 - y)", "-ans = 0", "-if not diff_dic:", "- ans += 1", "-for _ in range(C - 1):", "- d = int(eval(input()))", "- for _ in range(d):", "- r, c = list(map(int, input().split()))", "- r -= 1", "- c -= 1", "- if r < n // 2 and c < n // 2:", "- change(c, n - 1 - r)", "- change(n - 1 - c, r)", "- change(n - 1 - c, n - 1 - r)", "- elif n % 2 and r == n // 2 and c != n // 2:", "- change(max(c, n - 1 - c), r)", "- elif n % 2 and r != n // 2 and c == n // 2:", "- change(c, max(r, n - 1 - r))", "- else:", "- change(c, r)", "- if not diff_dic:", "- ans += 1", "-print(ans)", "+main()" ]
false
0.039092
0.037971
1.029524
[ "s754186393", "s169097657" ]
u125545880
p03611
python
s885444903
s718653203
75
67
14,292
14,068
Accepted
Accepted
10.67
import sys import collections #import numpy as np readline = sys.stdin.readline def main(): N = int(eval(input())) #A1 = np.array(list(map(int, readline().split()))) A = list(map(int, readline().split())) count = [0] * (max(A) + 3) for a in A: count[a+1] += 1 count[a] += 1 count[a+2] += 1 print((max(count))) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline def main(): N = int(eval(input())) A = list(map(int, readline().split())) count = [0] * (pow(10, 5)+3) for a in A: count[a] += 1 count[a+1] += 1 count[a+2] += 1 ans = max(count) print(ans) if __name__ == "__main__": main()
23
18
417
337
import sys import collections # import numpy as np readline = sys.stdin.readline def main(): N = int(eval(input())) # A1 = np.array(list(map(int, readline().split()))) A = list(map(int, readline().split())) count = [0] * (max(A) + 3) for a in A: count[a + 1] += 1 count[a] += 1 count[a + 2] += 1 print((max(count))) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline def main(): N = int(eval(input())) A = list(map(int, readline().split())) count = [0] * (pow(10, 5) + 3) for a in A: count[a] += 1 count[a + 1] += 1 count[a + 2] += 1 ans = max(count) print(ans) if __name__ == "__main__": main()
false
21.73913
[ "-import collections", "-# import numpy as np", "- # A1 = np.array(list(map(int, readline().split())))", "- count = [0] * (max(A) + 3)", "+ count = [0] * (pow(10, 5) + 3)", "+ count[a] += 1", "- count[a] += 1", "- print((max(count)))", "+ ans = max(count)", "+ print(ans)" ]
false
0.046238
0.051248
0.90225
[ "s885444903", "s718653203" ]
u832039789
p03073
python
s036498888
s837619777
67
53
3,188
3,188
Accepted
Accepted
20.9
s = eval(input()) res1, res2 = 0, 0 for i, j in enumerate(s): if i % 2 == 0: if j == '0': res1 += 1 else: if j == '1': res1 += 1 for i, j in enumerate(s): if i % 2 == 1: if j == '0': res2 += 1 else: if j == '1': res2 += 1 print((min(res1, res2)))
s=eval(input()) n=len(s) a=sum(i%2^int(s[i])for i in range(n)) print((min(a,n-a)))
17
4
351
77
s = eval(input()) res1, res2 = 0, 0 for i, j in enumerate(s): if i % 2 == 0: if j == "0": res1 += 1 else: if j == "1": res1 += 1 for i, j in enumerate(s): if i % 2 == 1: if j == "0": res2 += 1 else: if j == "1": res2 += 1 print((min(res1, res2)))
s = eval(input()) n = len(s) a = sum(i % 2 ^ int(s[i]) for i in range(n)) print((min(a, n - a)))
false
76.470588
[ "-res1, res2 = 0, 0", "-for i, j in enumerate(s):", "- if i % 2 == 0:", "- if j == \"0\":", "- res1 += 1", "- else:", "- if j == \"1\":", "- res1 += 1", "-for i, j in enumerate(s):", "- if i % 2 == 1:", "- if j == \"0\":", "- res2 += 1", "- else:", "- if j == \"1\":", "- res2 += 1", "-print((min(res1, res2)))", "+n = len(s)", "+a = sum(i % 2 ^ int(s[i]) for i in range(n))", "+print((min(a, n - a)))" ]
false
0.042258
0.106152
0.398089
[ "s036498888", "s837619777" ]
u864197622
p02734
python
s654307247
s078045053
116
100
3,316
3,316
Accepted
Accepted
13.79
K = 32 P = 998244353 pa = (1 << 30) - ((1 << 30) % P) M = [] N, S = list(map(int, input().split())) m = int(("1" * 2 + "0" * 30) * (S + 1), 2) mm = (1 << K * (S + 1)) - 1 A = [int(a) for a in input().split()] s = 0 ans = 0 for a in A: s += 1 s += s << a * K s &= mm s -= ((s & m) >> 30) * pa ans += s >> S * K print((ans % P))
K = 32 P = 998244353 pa = (1 << 30) - ((1 << 30) % P) M = [] N, S = list(map(int, input().split())) m = int(("1" * 2 + "0" * 30) * (S + 1), 2) mm = 1 << K * S mmm = (1 << K) - 1 A = [int(a) for a in input().split()] s = 0 ans = 0 for a in A: s += mm s += s >> a * K s -= ((s & m) >> 30) * pa ans += s & mmm print((ans % P))
18
18
356
349
K = 32 P = 998244353 pa = (1 << 30) - ((1 << 30) % P) M = [] N, S = list(map(int, input().split())) m = int(("1" * 2 + "0" * 30) * (S + 1), 2) mm = (1 << K * (S + 1)) - 1 A = [int(a) for a in input().split()] s = 0 ans = 0 for a in A: s += 1 s += s << a * K s &= mm s -= ((s & m) >> 30) * pa ans += s >> S * K print((ans % P))
K = 32 P = 998244353 pa = (1 << 30) - ((1 << 30) % P) M = [] N, S = list(map(int, input().split())) m = int(("1" * 2 + "0" * 30) * (S + 1), 2) mm = 1 << K * S mmm = (1 << K) - 1 A = [int(a) for a in input().split()] s = 0 ans = 0 for a in A: s += mm s += s >> a * K s -= ((s & m) >> 30) * pa ans += s & mmm print((ans % P))
false
0
[ "-mm = (1 << K * (S + 1)) - 1", "+mm = 1 << K * S", "+mmm = (1 << K) - 1", "- s += 1", "- s += s << a * K", "- s &= mm", "+ s += mm", "+ s += s >> a * K", "- ans += s >> S * K", "+ ans += s & mmm" ]
false
0.070487
0.036772
1.916875
[ "s654307247", "s078045053" ]
u928254435
p02730
python
s810834063
s174967898
19
17
3,064
3,064
Accepted
Accepted
10.53
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): N = len(S) a = S[0:int((N-1)/2)] b = S[int((N+3)/2)-1:N] if a == b[::-1]: Na = len(a) if Na % 2 == 0: aa = a[0:int(Na/2)] ab = a[int(Na/2):Na] else: aa = a[0:int((Na - 1) / 2)] ab = a[int((Na + 3) / 2)-1:Na] Nb = len(b) if Nb % 2 == 0: ba = b[0:int(Nb/2)] bb = b[int(Nb/2):Nb] else: ba = b[0:int((Nb - 1) / 2)] bb = b[int((Nb + 3) / 2)-1: Nb] if aa == ab[::-1] and ba == bb[::-1]: print(YES) else: print(NO) return print(NO) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): N = len(S) a = S[0:int((N-1)/2)] b = S[int((N+3)/2)-1:N] print(YES) if S == S[::-1] and a == a[::-1] and b == b[::-1] else print(NO) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == '__main__': main()
48
28
1,218
710
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): N = len(S) a = S[0 : int((N - 1) / 2)] b = S[int((N + 3) / 2) - 1 : N] if a == b[::-1]: Na = len(a) if Na % 2 == 0: aa = a[0 : int(Na / 2)] ab = a[int(Na / 2) : Na] else: aa = a[0 : int((Na - 1) / 2)] ab = a[int((Na + 3) / 2) - 1 : Na] Nb = len(b) if Nb % 2 == 0: ba = b[0 : int(Nb / 2)] bb = b[int(Nb / 2) : Nb] else: ba = b[0 : int((Nb - 1) / 2)] bb = b[int((Nb + 3) / 2) - 1 : Nb] if aa == ab[::-1] and ba == bb[::-1]: print(YES) else: print(NO) return print(NO) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): N = len(S) a = S[0 : int((N - 1) / 2)] b = S[int((N + 3) / 2) - 1 : N] print(YES) if S == S[::-1] and a == a[::-1] and b == b[::-1] else print(NO) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == "__main__": main()
false
41.666667
[ "- if a == b[::-1]:", "- Na = len(a)", "- if Na % 2 == 0:", "- aa = a[0 : int(Na / 2)]", "- ab = a[int(Na / 2) : Na]", "- else:", "- aa = a[0 : int((Na - 1) / 2)]", "- ab = a[int((Na + 3) / 2) - 1 : Na]", "- Nb = len(b)", "- if Nb % 2 == 0:", "- ba = b[0 : int(Nb / 2)]", "- bb = b[int(Nb / 2) : Nb]", "- else:", "- ba = b[0 : int((Nb - 1) / 2)]", "- bb = b[int((Nb + 3) / 2) - 1 : Nb]", "- if aa == ab[::-1] and ba == bb[::-1]:", "- print(YES)", "- else:", "- print(NO)", "- return", "- print(NO)", "+ print(YES) if S == S[::-1] and a == a[::-1] and b == b[::-1] else print(NO)" ]
false
0.036257
0.034611
1.047565
[ "s810834063", "s174967898" ]
u513081876
p03361
python
s649960901
s097012317
24
18
3,064
3,064
Accepted
Accepted
25
H, W = list(map(int, input().split())) s = [[] for i in range(H)] num = 0 judge = 0 start = [] for i in range(H): s[i] = eval(input()) if '#' in s[i]: num += s[i].count('#') if num == 0: print('Yes') else: for y in range(H): for x in range(W): flag = False if s[y][x] == '#': for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]: if 0 <= y + dy <= H-1 and 0 <= x+dx <= W-1: if s[y+dy][x+dx] != '#': continue else: flag = True if flag == True: judge += 1 if num == judge: print('Yes') else: print('No')
import sys H, W = list(map(int, input().split())) col = [] col.append('.' * (W + 2)) for i in range(H): col.append('.' + eval(input()) + '.') col.append('.' * (W + 2)) dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]] for y in range(1, H + 1): for x in range(1, W + 1): if col[y][x] == '#': for dx, dy in dxdy: if col[y + dy][x + dx] == '#': break else: print('No') sys.exit() print('Yes')
30
23
796
504
H, W = list(map(int, input().split())) s = [[] for i in range(H)] num = 0 judge = 0 start = [] for i in range(H): s[i] = eval(input()) if "#" in s[i]: num += s[i].count("#") if num == 0: print("Yes") else: for y in range(H): for x in range(W): flag = False if s[y][x] == "#": for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]: if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1: if s[y + dy][x + dx] != "#": continue else: flag = True if flag == True: judge += 1 if num == judge: print("Yes") else: print("No")
import sys H, W = list(map(int, input().split())) col = [] col.append("." * (W + 2)) for i in range(H): col.append("." + eval(input()) + ".") col.append("." * (W + 2)) dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]] for y in range(1, H + 1): for x in range(1, W + 1): if col[y][x] == "#": for dx, dy in dxdy: if col[y + dy][x + dx] == "#": break else: print("No") sys.exit() print("Yes")
false
23.333333
[ "+import sys", "+", "-s = [[] for i in range(H)]", "-num = 0", "-judge = 0", "-start = []", "+col = []", "+col.append(\".\" * (W + 2))", "- s[i] = eval(input())", "- if \"#\" in s[i]:", "- num += s[i].count(\"#\")", "-if num == 0:", "- print(\"Yes\")", "-else:", "- for y in range(H):", "- for x in range(W):", "- flag = False", "- if s[y][x] == \"#\":", "- for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:", "- if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1:", "- if s[y + dy][x + dx] != \"#\":", "- continue", "- else:", "- flag = True", "- if flag == True:", "- judge += 1", "- if num == judge:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ col.append(\".\" + eval(input()) + \".\")", "+col.append(\".\" * (W + 2))", "+dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]", "+for y in range(1, H + 1):", "+ for x in range(1, W + 1):", "+ if col[y][x] == \"#\":", "+ for dx, dy in dxdy:", "+ if col[y + dy][x + dx] == \"#\":", "+ break", "+ else:", "+ print(\"No\")", "+ sys.exit()", "+print(\"Yes\")" ]
false
0.039099
0.04927
0.793579
[ "s649960901", "s097012317" ]
u439063038
p03160
python
s913125345
s906165774
122
97
20,592
85,108
Accepted
Accepted
20.49
N = int(eval(input())) h = list(map(int, input().split())) dp = [0] * N dp[1] = abs(h[1]-h[0]) for i in range(2, N): dp[i] = min([dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1])]) print((dp[N-1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [10**9] * N dp[0] = 0 dp[1] = abs(h[1]-h[0]) for i in range(2, N): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print((dp[N-1]))
8
9
203
216
N = int(eval(input())) h = list(map(int, input().split())) dp = [0] * N dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min([dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])]) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [10**9] * N dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
false
11.111111
[ "-dp = [0] * N", "+dp = [10**9] * N", "+dp[0] = 0", "- dp[i] = min([dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])])", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.039273
0.148204
0.26499
[ "s913125345", "s906165774" ]
u600402037
p03999
python
s116838889
s097570940
31
18
3,568
3,060
Accepted
Accepted
41.94
import itertools import copy S = list(eval(input())) answer = 0 length = len(S) for pattern in itertools.product((True, False), repeat=length-1): S2 = S[:] for i in range(length-1): if pattern[i]: S2.insert(length-i-1, '+') answer += eval(''.join(S2)) print(answer)
S = eval(input()) N = len(S) def f(i, a): if i == N-1: return sum(list(map(int, a.split('+')))) return f(i+1, a + S[i+1]) + f(i+1, a + '+' + S[i+1]) print((f(0, S[0])))
15
10
308
192
import itertools import copy S = list(eval(input())) answer = 0 length = len(S) for pattern in itertools.product((True, False), repeat=length - 1): S2 = S[:] for i in range(length - 1): if pattern[i]: S2.insert(length - i - 1, "+") answer += eval("".join(S2)) print(answer)
S = eval(input()) N = len(S) def f(i, a): if i == N - 1: return sum(list(map(int, a.split("+")))) return f(i + 1, a + S[i + 1]) + f(i + 1, a + "+" + S[i + 1]) print((f(0, S[0])))
false
33.333333
[ "-import itertools", "-import copy", "+S = eval(input())", "+N = len(S)", "-S = list(eval(input()))", "-answer = 0", "-length = len(S)", "-for pattern in itertools.product((True, False), repeat=length - 1):", "- S2 = S[:]", "- for i in range(length - 1):", "- if pattern[i]:", "- S2.insert(length - i - 1, \"+\")", "- answer += eval(\"\".join(S2))", "-print(answer)", "+", "+def f(i, a):", "+ if i == N - 1:", "+ return sum(list(map(int, a.split(\"+\"))))", "+ return f(i + 1, a + S[i + 1]) + f(i + 1, a + \"+\" + S[i + 1])", "+", "+", "+print((f(0, S[0])))" ]
false
0.037614
0.09089
0.413834
[ "s116838889", "s097570940" ]
u624617831
p02946
python
s459212813
s725135706
302
17
20,656
3,060
Accepted
Accepted
94.37
K = list(map(int, input().split())) import numpy as np tmp = [] for i in range(K[1]-K[0]+1, K[1]+K[0]): if abs(i) <= 1000000: print(i)
k, x = list(map(int, input().split())) under = x-(k-1) top = x+(k-1) ans = '' for i in range(under,top+1): if i == top: ans += str(i) else: ans += str(i)+' ' print(ans)
8
14
156
203
K = list(map(int, input().split())) import numpy as np tmp = [] for i in range(K[1] - K[0] + 1, K[1] + K[0]): if abs(i) <= 1000000: print(i)
k, x = list(map(int, input().split())) under = x - (k - 1) top = x + (k - 1) ans = "" for i in range(under, top + 1): if i == top: ans += str(i) else: ans += str(i) + " " print(ans)
false
42.857143
[ "-K = list(map(int, input().split()))", "-import numpy as np", "-", "-tmp = []", "-for i in range(K[1] - K[0] + 1, K[1] + K[0]):", "- if abs(i) <= 1000000:", "- print(i)", "+k, x = list(map(int, input().split()))", "+under = x - (k - 1)", "+top = x + (k - 1)", "+ans = \"\"", "+for i in range(under, top + 1):", "+ if i == top:", "+ ans += str(i)", "+ else:", "+ ans += str(i) + \" \"", "+print(ans)" ]
false
0.041269
0.036172
1.140909
[ "s459212813", "s725135706" ]
u345389118
p02630
python
s799999777
s561738246
443
378
40,336
40,256
Accepted
Accepted
14.67
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B = [list(map(int, input().split())) for _ in range(Q)] res = sum(A) A_counter = Counter(A) for i, j in B: if i not in A_counter: A_counter[i] = 0 if j not in A_counter: A_counter[j] = 0 res += (j - i) * A_counter[i] print(res) A_counter[j] += A_counter[i] A_counter[i] = 0
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B = [list(map(int, input().split())) for _ in range(Q)] res = sum(A) A_counter = Counter(A) for i, j in B: # if i not in A_counter: # A_counter[i] = 0 # if j not in A_counter: # A_counter[j] = 0 res += (j - i) * A_counter[i] print(res) A_counter[j] += A_counter[i] A_counter[i] = 0
19
19
441
445
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B = [list(map(int, input().split())) for _ in range(Q)] res = sum(A) A_counter = Counter(A) for i, j in B: if i not in A_counter: A_counter[i] = 0 if j not in A_counter: A_counter[j] = 0 res += (j - i) * A_counter[i] print(res) A_counter[j] += A_counter[i] A_counter[i] = 0
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B = [list(map(int, input().split())) for _ in range(Q)] res = sum(A) A_counter = Counter(A) for i, j in B: # if i not in A_counter: # A_counter[i] = 0 # if j not in A_counter: # A_counter[j] = 0 res += (j - i) * A_counter[i] print(res) A_counter[j] += A_counter[i] A_counter[i] = 0
false
0
[ "- if i not in A_counter:", "- A_counter[i] = 0", "- if j not in A_counter:", "- A_counter[j] = 0", "+ # if i not in A_counter:", "+ # A_counter[i] = 0", "+ # if j not in A_counter:", "+ # A_counter[j] = 0" ]
false
0.03792
0.038607
0.982197
[ "s799999777", "s561738246" ]
u188827677
p02982
python
s486882881
s964243781
31
26
9,136
9,384
Accepted
Accepted
16.13
n,d = list(map(int, input().split())) x = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n-1): for j in range(i+1,n): s = 0 for k in range(d): s += abs(x[i][k] - x[j][k])**2 s = s**0.5 if s.is_integer(): ans += 1 print(ans)
n,d = list(map(int, input().split())) x = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n-1): for j in range(i+1, n): t = 0 for k in range(d): t += abs(x[i][k] - x[j][k])**2 t **= 0.5 if t.is_integer(): ans += 1 print(ans)
12
11
281
274
n, d = list(map(int, input().split())) x = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n - 1): for j in range(i + 1, n): s = 0 for k in range(d): s += abs(x[i][k] - x[j][k]) ** 2 s = s**0.5 if s.is_integer(): ans += 1 print(ans)
n, d = list(map(int, input().split())) x = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n - 1): for j in range(i + 1, n): t = 0 for k in range(d): t += abs(x[i][k] - x[j][k]) ** 2 t **= 0.5 if t.is_integer(): ans += 1 print(ans)
false
8.333333
[ "- s = 0", "+ t = 0", "- s += abs(x[i][k] - x[j][k]) ** 2", "- s = s**0.5", "- if s.is_integer():", "+ t += abs(x[i][k] - x[j][k]) ** 2", "+ t **= 0.5", "+ if t.is_integer():" ]
false
0.063914
0.063675
1.003757
[ "s486882881", "s964243781" ]
u265118937
p02627
python
s600241794
s570034894
33
26
8,952
9,080
Accepted
Accepted
21.21
a = eval(input()) if ord(a) < 0x61: print('A') else: print("a")
s = eval(input()) if ord(s) <= 0x5a: print("A") else: print("a")
5
5
69
70
a = eval(input()) if ord(a) < 0x61: print("A") else: print("a")
s = eval(input()) if ord(s) <= 0x5A: print("A") else: print("a")
false
0
[ "-a = eval(input())", "-if ord(a) < 0x61:", "+s = eval(input())", "+if ord(s) <= 0x5A:" ]
false
0.038168
0.035425
1.077419
[ "s600241794", "s570034894" ]