user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u343977188
p03944
python
s022075526
s227469846
31
24
9,168
9,204
Accepted
Accepted
22.58
w,h,n=list(map(int,input().split())) x1=0 x2=w y1=0 y2=h for i in range(n): x,y,a=list(map(int,input().split())) if a==1 and x > x1: x1 = x elif a==2 and x < x2: x2 = x elif a==3 and y > y1: y1 = y elif a==4 and y < y2: y2 = y if x1 > x2 or y1 > y2: print((0)) else: print(((x2 - x1)*(y2 - y1)))
w,h,n=list(map(int,input().split())) x1,x2,y1,y2=0,w,0,h for i in range(n): x,y,a=list(map(int,input().split())) if a==1 and x > x1: x1 = x elif a==2 and x < x2: x2 = x elif a==3 and y > y1: y1 = y elif a==4 and y < y2: y2 = y if x1 > x2 or y1 > y2: print((0)) else: print(((x2 - x1)*(y2 - y1)))
19
16
328
324
w, h, n = list(map(int, input().split())) x1 = 0 x2 = w y1 = 0 y2 = h for i in range(n): x, y, a = list(map(int, input().split())) if a == 1 and x > x1: x1 = x elif a == 2 and x < x2: x2 = x elif a == 3 and y > y1: y1 = y elif a == 4 and y < y2: y2 = y if x1 > x2 or y1 > y2: print((0)) else: print(((x2 - x1) * (y2 - y1)))
w, h, n = list(map(int, input().split())) x1, x2, y1, y2 = 0, w, 0, h for i in range(n): x, y, a = list(map(int, input().split())) if a == 1 and x > x1: x1 = x elif a == 2 and x < x2: x2 = x elif a == 3 and y > y1: y1 = y elif a == 4 and y < y2: y2 = y if x1 > x2 or y1 > y2: print((0)) else: print(((x2 - x1) * (y2 - y1)))
false
15.789474
[ "-x1 = 0", "-x2 = w", "-y1 = 0", "-y2 = h", "+x1, x2, y1, y2 = 0, w, 0, h" ]
false
0.035238
0.033253
1.059693
[ "s022075526", "s227469846" ]
u908984540
p02255
python
s555772911
s810565012
50
30
8,532
8,016
Accepted
Accepted
40
def show_list(num_list): for i in range(len(num_list)): print(str(num_list[i]), end="") if i < len(num_list)-1: print(" ", end="") else: print() input_num = int(input()) num_list = [int(i) for i in input().split()] show_list(num_list) for i in range(1, len(num_list)): v = num_list[i] j = i - 1 while j >= 0 and num_list[j] > v: num_list[j+1] = num_list[j] j -= 1 num_list[j+1] = v show_list(num_list)
# -*- coding : utf-8 -*- def insertion_sort(list): for i in range(1, len(list)): key = list[i] j = i - 1 show_list(list) while(j >= 0 and list[j] > key): list[j+1] = list[j] j = j - 1 list[j+1] = key show_list(list) return list def show_list(list): i = 0; while(i < len(list)-1): print(list[i], end=" ") i = i + 1 print(list[i]) list_length = int(input()) list = [int(x) for x in input().split(" ")] insertion_sort(list)
19
24
508
550
def show_list(num_list): for i in range(len(num_list)): print(str(num_list[i]), end="") if i < len(num_list) - 1: print(" ", end="") else: print() input_num = int(input()) num_list = [int(i) for i in input().split()] show_list(num_list) for i in range(1, len(num_list)): v = num_list[i] j = i - 1 while j >= 0 and num_list[j] > v: num_list[j + 1] = num_list[j] j -= 1 num_list[j + 1] = v show_list(num_list)
# -*- coding : utf-8 -*- def insertion_sort(list): for i in range(1, len(list)): key = list[i] j = i - 1 show_list(list) while j >= 0 and list[j] > key: list[j + 1] = list[j] j = j - 1 list[j + 1] = key show_list(list) return list def show_list(list): i = 0 while i < len(list) - 1: print(list[i], end=" ") i = i + 1 print(list[i]) list_length = int(input()) list = [int(x) for x in input().split(" ")] insertion_sort(list)
false
20.833333
[ "-def show_list(num_list):", "- for i in range(len(num_list)):", "- print(str(num_list[i]), end=\"\")", "- if i < len(num_list) - 1:", "- print(\" \", end=\"\")", "- else:", "- print()", "+# -*- coding : utf-8 -*-", "+def insertion_sort(list):", "+ for i in range(1, len(list)):", "+ key = list[i]", "+ j = i - 1", "+ show_list(list)", "+ while j >= 0 and list[j] > key:", "+ list[j + 1] = list[j]", "+ j = j - 1", "+ list[j + 1] = key", "+ show_list(list)", "+ return list", "-input_num = int(input())", "-num_list = [int(i) for i in input().split()]", "-show_list(num_list)", "-for i in range(1, len(num_list)):", "- v = num_list[i]", "- j = i - 1", "- while j >= 0 and num_list[j] > v:", "- num_list[j + 1] = num_list[j]", "- j -= 1", "- num_list[j + 1] = v", "- show_list(num_list)", "+def show_list(list):", "+ i = 0", "+ while i < len(list) - 1:", "+ print(list[i], end=\" \")", "+ i = i + 1", "+ print(list[i])", "+", "+", "+list_length = int(input())", "+list = [int(x) for x in input().split(\" \")]", "+insertion_sort(list)" ]
false
0.041769
0.035751
1.168337
[ "s555772911", "s810565012" ]
u729133443
p02579
python
s926973726
s597123005
1,406
1,247
252,796
255,684
Accepted
Accepted
11.31
from collections import* I=9**9 (h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3) m,d=list(zip(*eval('(input(),[I]*w),'*h))) q=deque([(s-1,t-1,1)]) r=list(range(-2,3)) while q: y,x,c=q.popleft() if d[y][x]>c: for a in r: for b in r:i=a+y;j=b+x;d[y][x]=c;h>i>-1<j<w!=m[i][j]>'#'!=(abs(a)+abs(b)<2!=q.appendleft((i,j,c)),q.append((i,j,c+1))) print((d[f-1][g-1]%I-1))
from collections import* I=9**9 (h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3) m,d=list(zip(*eval('(input(),[I]*w),'*h))) q=deque([(s-1,t-1,1)]) while q: y,x,c=q.popleft() if d[y][x]>c: for a in range(25):a,b=a//5-2,a%5-2;i=a+y;j=b+x;d[y][x]=c;h>i>-1<j<w!=m[i][j]>'#'!=(abs(a)+abs(b)<2!=q.appendleft((i,j,c)),q.append((i,j,c+1))) print((d[f-1][g-1]%I-1))
12
10
373
366
from collections import * I = 9**9 (h, w), (s, t), (f, g) = eval("map(int,input().split())," * 3) m, d = list(zip(*eval("(input(),[I]*w)," * h))) q = deque([(s - 1, t - 1, 1)]) r = list(range(-2, 3)) while q: y, x, c = q.popleft() if d[y][x] > c: for a in r: for b in r: i = a + y j = b + x d[y][x] = c h > i > -1 < j < w != m[i][j] > "#" != ( abs(a) + abs(b) < 2 != q.appendleft((i, j, c)), q.append((i, j, c + 1)), ) print((d[f - 1][g - 1] % I - 1))
from collections import * I = 9**9 (h, w), (s, t), (f, g) = eval("map(int,input().split())," * 3) m, d = list(zip(*eval("(input(),[I]*w)," * h))) q = deque([(s - 1, t - 1, 1)]) while q: y, x, c = q.popleft() if d[y][x] > c: for a in range(25): a, b = a // 5 - 2, a % 5 - 2 i = a + y j = b + x d[y][x] = c h > i > -1 < j < w != m[i][j] > "#" != ( abs(a) + abs(b) < 2 != q.appendleft((i, j, c)), q.append((i, j, c + 1)), ) print((d[f - 1][g - 1] % I - 1))
false
16.666667
[ "-r = list(range(-2, 3))", "- for a in r:", "- for b in r:", "- i = a + y", "- j = b + x", "- d[y][x] = c", "- h > i > -1 < j < w != m[i][j] > \"#\" != (", "- abs(a) + abs(b) < 2 != q.appendleft((i, j, c)),", "- q.append((i, j, c + 1)),", "- )", "+ for a in range(25):", "+ a, b = a // 5 - 2, a % 5 - 2", "+ i = a + y", "+ j = b + x", "+ d[y][x] = c", "+ h > i > -1 < j < w != m[i][j] > \"#\" != (", "+ abs(a) + abs(b) < 2 != q.appendleft((i, j, c)),", "+ q.append((i, j, c + 1)),", "+ )" ]
false
0.034899
0.036885
0.946149
[ "s926973726", "s597123005" ]
u620480037
p03305
python
s806130892
s462467600
1,575
1,349
81,596
81,452
Accepted
Accepted
14.35
n,m,s,t=list(map(int,input().split())) en=[[]for i in range(n+1)] sn=[[]for i in range(n+1)] for i in range(m): u,v,a,b=list(map(int,input().split())) en[v].append((u,a)) en[u].append((v,a)) sn[v].append((u,b)) sn[u].append((v,b)) #print(en) import numpy as np INF=10**20 def dijkstra(S, N, paths): from heapq import heappush,heappop q=[(0,S)] shortest=[INF]*N shortest[S]=0 while len(q)>0: d0, src=heappop(q) if d0>shortest[src]: continue for dst, d1 in paths[src]: if d0+d1<shortest[dst]: shortest[dst]=d0+d1 heappush(q, (d0+d1, dst)) return np.array(shortest) en=dijkstra(s,n+1,en) sn=dijkstra(t,n+1,sn) cost=[] for i in range(1,n+1): cost.append(en[i]+sn[i]) cost=cost[::-1] #print(cost) ans=[] mi=cost[0] for i in range(n): ans.append(min(mi,cost[i])) mi=min(mi,cost[i]) ans=ans[::-1] #print(ans) for i in ans: print((10**15-i))
import sys input=sys.stdin.readline n,m,s,t=list(map(int,input().split())) en=[[]for i in range(n+1)] sn=[[]for i in range(n+1)] for i in range(m): u,v,a,b=list(map(int,input().split())) en[v].append((u,a)) en[u].append((v,a)) sn[v].append((u,b)) sn[u].append((v,b)) #print(en) import numpy as np INF=10**20 def dijkstra(S, N, paths): from heapq import heappush,heappop q=[(0,S)] shortest=[INF]*N shortest[S]=0 while len(q)>0: d0, src=heappop(q) if d0>shortest[src]: continue for dst, d1 in paths[src]: if d0+d1<shortest[dst]: shortest[dst]=d0+d1 heappush(q, (d0+d1, dst)) return np.array(shortest) en=dijkstra(s,n+1,en) sn=dijkstra(t,n+1,sn) cost=[] for i in range(1,n+1): cost.append(en[i]+sn[i]) cost=cost[::-1] #print(cost) ans=[] mi=cost[0] for i in range(n): ans.append(min(mi,cost[i])) mi=min(mi,cost[i]) ans=ans[::-1] #print(ans) for i in ans: print((10**15-i))
49
51
1,019
1,057
n, m, s, t = list(map(int, input().split())) en = [[] for i in range(n + 1)] sn = [[] for i in range(n + 1)] for i in range(m): u, v, a, b = list(map(int, input().split())) en[v].append((u, a)) en[u].append((v, a)) sn[v].append((u, b)) sn[u].append((v, b)) # print(en) import numpy as np INF = 10**20 def dijkstra(S, N, paths): from heapq import heappush, heappop q = [(0, S)] shortest = [INF] * N shortest[S] = 0 while len(q) > 0: d0, src = heappop(q) if d0 > shortest[src]: continue for dst, d1 in paths[src]: if d0 + d1 < shortest[dst]: shortest[dst] = d0 + d1 heappush(q, (d0 + d1, dst)) return np.array(shortest) en = dijkstra(s, n + 1, en) sn = dijkstra(t, n + 1, sn) cost = [] for i in range(1, n + 1): cost.append(en[i] + sn[i]) cost = cost[::-1] # print(cost) ans = [] mi = cost[0] for i in range(n): ans.append(min(mi, cost[i])) mi = min(mi, cost[i]) ans = ans[::-1] # print(ans) for i in ans: print((10**15 - i))
import sys input = sys.stdin.readline n, m, s, t = list(map(int, input().split())) en = [[] for i in range(n + 1)] sn = [[] for i in range(n + 1)] for i in range(m): u, v, a, b = list(map(int, input().split())) en[v].append((u, a)) en[u].append((v, a)) sn[v].append((u, b)) sn[u].append((v, b)) # print(en) import numpy as np INF = 10**20 def dijkstra(S, N, paths): from heapq import heappush, heappop q = [(0, S)] shortest = [INF] * N shortest[S] = 0 while len(q) > 0: d0, src = heappop(q) if d0 > shortest[src]: continue for dst, d1 in paths[src]: if d0 + d1 < shortest[dst]: shortest[dst] = d0 + d1 heappush(q, (d0 + d1, dst)) return np.array(shortest) en = dijkstra(s, n + 1, en) sn = dijkstra(t, n + 1, sn) cost = [] for i in range(1, n + 1): cost.append(en[i] + sn[i]) cost = cost[::-1] # print(cost) ans = [] mi = cost[0] for i in range(n): ans.append(min(mi, cost[i])) mi = min(mi, cost[i]) ans = ans[::-1] # print(ans) for i in ans: print((10**15 - i))
false
3.921569
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.51632
0.22456
2.299252
[ "s806130892", "s462467600" ]
u312025627
p03214
python
s220957677
s610733188
166
69
38,384
61,984
Accepted
Accepted
58.43
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] avg = sum(A)/N ans = 0 mi = abs(A[0] - avg) for i, a in enumerate(A[1:], start=1): if abs(a - avg) < mi: ans = i mi = abs(a - avg) print(ans) if __name__ == '__main__': main()
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] avg = sum(A)/N mi = abs(A[0] - avg) idx = 0 for i, a in enumerate(A[1:], start=1): if abs(a - avg) < mi: mi = abs(a - avg) idx = i print(idx) if __name__ == '__main__': main()
15
15
323
323
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] avg = sum(A) / N ans = 0 mi = abs(A[0] - avg) for i, a in enumerate(A[1:], start=1): if abs(a - avg) < mi: ans = i mi = abs(a - avg) print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] avg = sum(A) / N mi = abs(A[0] - avg) idx = 0 for i, a in enumerate(A[1:], start=1): if abs(a - avg) < mi: mi = abs(a - avg) idx = i print(idx) if __name__ == "__main__": main()
false
0
[ "- ans = 0", "+ idx = 0", "- ans = i", "- print(ans)", "+ idx = i", "+ print(idx)" ]
false
0.200367
0.044368
4.51606
[ "s220957677", "s610733188" ]
u644516473
p03379
python
s643062004
s695756555
235
205
25,620
30,228
Accepted
Accepted
12.77
N = int(input()) X = list(map(int, input().split())) mid1, mid2 = sorted(X)[N//2-1:N//2+1] print(*[mid1 if xi>mid1 else mid2 for xi in X], sep="\n")
N = int(eval(input())) X = list(map(int, input().split())) mid1, mid2 = sorted(X)[N//2-1:N//2+1] print(('\n'.join(str(mid1) if xi>mid1 else str(mid2) for xi in X)))
5
5
154
162
N = int(input()) X = list(map(int, input().split())) mid1, mid2 = sorted(X)[N // 2 - 1 : N // 2 + 1] print(*[mid1 if xi > mid1 else mid2 for xi in X], sep="\n")
N = int(eval(input())) X = list(map(int, input().split())) mid1, mid2 = sorted(X)[N // 2 - 1 : N // 2 + 1] print(("\n".join(str(mid1) if xi > mid1 else str(mid2) for xi in X)))
false
0
[ "-N = int(input())", "+N = int(eval(input()))", "-print(*[mid1 if xi > mid1 else mid2 for xi in X], sep=\"\\n\")", "+print((\"\\n\".join(str(mid1) if xi > mid1 else str(mid2) for xi in X)))" ]
false
0.045457
0.068141
0.667096
[ "s643062004", "s695756555" ]
u873482706
p00254
python
s924145797
s967447549
480
270
4,224
4,224
Accepted
Accepted
43.75
data = [str(i+1)*4 for i in range(9)] while True: n = input() if n == '0000': break elif n in data: print('NA') continue c = 0 while n != '6174': L = int(''.join(sorted(list(n), key=int, reverse=True))) S = int(''.join(sorted(list(n), key=int))) n = str(L-S).zfill(4) c += 1 else: print(c)
data = [str(i+1)*4 for i in range(9)] while True: n = input() if n == '0000': break elif n in data: print('NA') continue c = 0 while n != '6174': L = int(''.join(sorted(n, reverse=True))) S = int(''.join(sorted(n))) n = str(L-S).zfill(4) c += 1 else: print(c)
16
16
395
365
data = [str(i + 1) * 4 for i in range(9)] while True: n = input() if n == "0000": break elif n in data: print("NA") continue c = 0 while n != "6174": L = int("".join(sorted(list(n), key=int, reverse=True))) S = int("".join(sorted(list(n), key=int))) n = str(L - S).zfill(4) c += 1 else: print(c)
data = [str(i + 1) * 4 for i in range(9)] while True: n = input() if n == "0000": break elif n in data: print("NA") continue c = 0 while n != "6174": L = int("".join(sorted(n, reverse=True))) S = int("".join(sorted(n))) n = str(L - S).zfill(4) c += 1 else: print(c)
false
0
[ "- L = int(\"\".join(sorted(list(n), key=int, reverse=True)))", "- S = int(\"\".join(sorted(list(n), key=int)))", "+ L = int(\"\".join(sorted(n, reverse=True)))", "+ S = int(\"\".join(sorted(n)))" ]
false
0.037533
0.065929
0.569295
[ "s924145797", "s967447549" ]
u287132915
p02804
python
s525528614
s388002200
567
359
16,408
71,208
Accepted
Accepted
36.68
n,k = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) a_reverse = a[::-1] mod = 10**9+7 factorial = [1] inverse = [1] for i in range(1, n+1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod - 2, mod)) def comb(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % mod plus = 0 minus = 0 cnt = 0 ind = 0 for i in range(n-k+1): kaisu = comb(n-i-1, k-1, mod) plus = (plus + (kaisu * a_reverse[ind]) % mod) % mod minus = (minus + (kaisu * a[ind]) % mod) % mod ind += 1 print(((plus-minus) % mod))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 factorial = [1] inverse = [1] for i in range(1, n+1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod - 2, mod)) def comb(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % mod a.sort() mini = 0 for i in range(n-1): mini += a[i] * comb(n-i-1, k-1, mod) mini %= mod a.sort(reverse=True) maxi = 0 for i in range(n-1): maxi += a[i] * comb(n-i-1, k-1, mod) maxi %= mod print(((maxi-mini)%mod))
29
28
690
635
n, k = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) a_reverse = a[::-1] mod = 10**9 + 7 factorial = [1] inverse = [1] for i in range(1, n + 1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod - 2, mod)) def comb(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % mod plus = 0 minus = 0 cnt = 0 ind = 0 for i in range(n - k + 1): kaisu = comb(n - i - 1, k - 1, mod) plus = (plus + (kaisu * a_reverse[ind]) % mod) % mod minus = (minus + (kaisu * a[ind]) % mod) % mod ind += 1 print(((plus - minus) % mod))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 factorial = [1] inverse = [1] for i in range(1, n + 1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod - 2, mod)) def comb(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % mod a.sort() mini = 0 for i in range(n - 1): mini += a[i] * comb(n - i - 1, k - 1, mod) mini %= mod a.sort(reverse=True) maxi = 0 for i in range(n - 1): maxi += a[i] * comb(n - i - 1, k - 1, mod) maxi %= mod print(((maxi - mini) % mod))
false
3.448276
[ "-a = sorted(list(map(int, input().split())))", "-a_reverse = a[::-1]", "+a = list(map(int, input().split()))", "-plus = 0", "-minus = 0", "-cnt = 0", "-ind = 0", "-for i in range(n - k + 1):", "- kaisu = comb(n - i - 1, k - 1, mod)", "- plus = (plus + (kaisu * a_reverse[ind]) % mod) % mod", "- minus = (minus + (kaisu * a[ind]) % mod) % mod", "- ind += 1", "-print(((plus - minus) % mod))", "+a.sort()", "+mini = 0", "+for i in range(n - 1):", "+ mini += a[i] * comb(n - i - 1, k - 1, mod)", "+ mini %= mod", "+a.sort(reverse=True)", "+maxi = 0", "+for i in range(n - 1):", "+ maxi += a[i] * comb(n - i - 1, k - 1, mod)", "+ maxi %= mod", "+print(((maxi - mini) % mod))" ]
false
0.118386
0.037933
3.120946
[ "s525528614", "s388002200" ]
u104911888
p00441
python
s861495348
s700288175
21,720
12,130
5,256
5,788
Accepted
Accepted
44.15
while True: n = eval(input()) if n == 0: break P = set(tuple(map(int, input().split())) for i in range(n)) ans = 0 for xi, yi in P: for xj, yj in P: q = (xj - yj + yi, yj + xj - xi) r = (xi - yj + yi, yi + xj - xi) if q in P and r in P: ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2) print(ans)
while True: n = eval(input()) if n == 0: break P = [(list(map(int, input().split()))) for i in range(n)] S = set(map(tuple, P)) ans = 0 for i in range(n - 1): xi, yi = P[i] for j in range(i + 1, n): xj, yj = P[j] q = (xj - yj + yi, yj + xj - xi) r = (xi - yj + yi, yi + xj - xi) if q in S and r in S: ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2) print(ans)
12
15
387
472
while True: n = eval(input()) if n == 0: break P = set(tuple(map(int, input().split())) for i in range(n)) ans = 0 for xi, yi in P: for xj, yj in P: q = (xj - yj + yi, yj + xj - xi) r = (xi - yj + yi, yi + xj - xi) if q in P and r in P: ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2) print(ans)
while True: n = eval(input()) if n == 0: break P = [(list(map(int, input().split()))) for i in range(n)] S = set(map(tuple, P)) ans = 0 for i in range(n - 1): xi, yi = P[i] for j in range(i + 1, n): xj, yj = P[j] q = (xj - yj + yi, yj + xj - xi) r = (xi - yj + yi, yi + xj - xi) if q in S and r in S: ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2) print(ans)
false
20
[ "- P = set(tuple(map(int, input().split())) for i in range(n))", "+ P = [(list(map(int, input().split()))) for i in range(n)]", "+ S = set(map(tuple, P))", "- for xi, yi in P:", "- for xj, yj in P:", "+ for i in range(n - 1):", "+ xi, yi = P[i]", "+ for j in range(i + 1, n):", "+ xj, yj = P[j]", "- if q in P and r in P:", "+ if q in S and r in S:" ]
false
0.042764
0.037524
1.139636
[ "s861495348", "s700288175" ]
u308914480
p03156
python
s968676935
s811161036
31
25
9,048
9,044
Accepted
Accepted
19.35
n = int(eval(input())) a,b = list(map(int,input().split())) l = list(map(int,input().split())) c = [0,0,0] for i in l: if i <= a: c[0] += 1 elif i > b: c[2] += 1 else: c[1] += 1 print((min(c)))
n=int(eval(input())) a,b=list(map(int, input().split())) p=list(map(int, input().split())) c=[0]*3 for i in p: if i <=a: c[0] +=1 elif i>b: c[2] +=1 else: c[1]+=1 print((min(c)))
12
12
226
220
n = int(eval(input())) a, b = list(map(int, input().split())) l = list(map(int, input().split())) c = [0, 0, 0] for i in l: if i <= a: c[0] += 1 elif i > b: c[2] += 1 else: c[1] += 1 print((min(c)))
n = int(eval(input())) a, b = list(map(int, input().split())) p = list(map(int, input().split())) c = [0] * 3 for i in p: if i <= a: c[0] += 1 elif i > b: c[2] += 1 else: c[1] += 1 print((min(c)))
false
0
[ "-l = list(map(int, input().split()))", "-c = [0, 0, 0]", "-for i in l:", "+p = list(map(int, input().split()))", "+c = [0] * 3", "+for i in p:" ]
false
0.044932
0.039716
1.131338
[ "s968676935", "s811161036" ]
u735335967
p03073
python
s155719697
s044983903
129
51
3,956
3,956
Accepted
Accepted
60.47
s = eval(input()) s = list("".join(s)) ans = 0 for i in range(1,len(s)): if int(s[i-1]) == int(s[i]) == 0: s[i] = 1 ans += 1 elif int(s[i-1]) == int(s[i]) == 1: s[i] = 0 ans += 1 print(ans)
s = eval(input()) s = list(s) ans = 0 for i in range(1,len(s)): if s[i] == s[i-1]: ans += 1 if s[i] == "0": s[i] = "1" else: s[i] = "0" print(ans)
11
11
234
203
s = eval(input()) s = list("".join(s)) ans = 0 for i in range(1, len(s)): if int(s[i - 1]) == int(s[i]) == 0: s[i] = 1 ans += 1 elif int(s[i - 1]) == int(s[i]) == 1: s[i] = 0 ans += 1 print(ans)
s = eval(input()) s = list(s) ans = 0 for i in range(1, len(s)): if s[i] == s[i - 1]: ans += 1 if s[i] == "0": s[i] = "1" else: s[i] = "0" print(ans)
false
0
[ "-s = list(\"\".join(s))", "+s = list(s)", "- if int(s[i - 1]) == int(s[i]) == 0:", "- s[i] = 1", "+ if s[i] == s[i - 1]:", "- elif int(s[i - 1]) == int(s[i]) == 1:", "- s[i] = 0", "- ans += 1", "+ if s[i] == \"0\":", "+ s[i] = \"1\"", "+ else:", "+ s[i] = \"0\"" ]
false
0.036287
0.035987
1.008325
[ "s155719697", "s044983903" ]
u764860452
p03545
python
s496817092
s790413117
19
17
3,060
3,060
Accepted
Accepted
10.53
import itertools S=eval(input()) sum1=0 for i in itertools.product(["+","-"],repeat=3): ans="" for j in range(3): if i[j]=="+": ans+=S[j]+i[j] elif i[j]=="-": ans+=S[j]+"-" ans+=S[-1] sum1=eval(ans) if sum1==7: print((ans+"="+str(7))) exit()
import itertools S=eval(input()) for i in itertools.product(["+","-"],repeat=3): ans="" for j in range(3): if i[j]=="+": ans+=S[j]+i[j] elif i[j]=="-": ans+=S[j]+i[j] ans+=S[-1] sum1=eval(ans) if sum1==7: print((ans+"="+str(7))) exit()
20
16
345
320
import itertools S = eval(input()) sum1 = 0 for i in itertools.product(["+", "-"], repeat=3): ans = "" for j in range(3): if i[j] == "+": ans += S[j] + i[j] elif i[j] == "-": ans += S[j] + "-" ans += S[-1] sum1 = eval(ans) if sum1 == 7: print((ans + "=" + str(7))) exit()
import itertools S = eval(input()) for i in itertools.product(["+", "-"], repeat=3): ans = "" for j in range(3): if i[j] == "+": ans += S[j] + i[j] elif i[j] == "-": ans += S[j] + i[j] ans += S[-1] sum1 = eval(ans) if sum1 == 7: print((ans + "=" + str(7))) exit()
false
20
[ "-sum1 = 0", "- ans += S[j] + \"-\"", "+ ans += S[j] + i[j]" ]
false
0.040265
0.039601
1.016772
[ "s496817092", "s790413117" ]
u145950990
p03241
python
s222975967
s394680208
171
21
38,640
3,060
Accepted
Accepted
87.72
n,m = list(map(int,input().split())) ans = 1 for i in range(1,int(m**0.5)+1): if m%i==0: x = m//i if x>=n: ans = max(ans,i) if i>=n: ans = max(ans,x) print(ans)
n,m = list(map(int,input().split())) ans = 1 for i in range(1,int(m**0.5)+1): if m%i!=0:continue if m//i>=n: ans = max(i,ans) if i>=n: ans = max(m//i,ans) print(ans)
11
10
226
197
n, m = list(map(int, input().split())) ans = 1 for i in range(1, int(m**0.5) + 1): if m % i == 0: x = m // i if x >= n: ans = max(ans, i) if i >= n: ans = max(ans, x) print(ans)
n, m = list(map(int, input().split())) ans = 1 for i in range(1, int(m**0.5) + 1): if m % i != 0: continue if m // i >= n: ans = max(i, ans) if i >= n: ans = max(m // i, ans) print(ans)
false
9.090909
[ "- if m % i == 0:", "- x = m // i", "- if x >= n:", "- ans = max(ans, i)", "- if i >= n:", "- ans = max(ans, x)", "+ if m % i != 0:", "+ continue", "+ if m // i >= n:", "+ ans = max(i, ans)", "+ if i >= n:", "+ ans = max(m // i, ans)" ]
false
0.092507
0.039925
2.317014
[ "s222975967", "s394680208" ]
u268314634
p02988
python
s172237420
s310386986
27
24
9,164
9,180
Accepted
Accepted
11.11
n=int(eval(input())) p=list(map(int, input().split())) o=0 for i in range(1,n-1): if p[i-1]>p[i]>p[i+1] or p[i+1]>p[i]>p[i-1]: o+=1 print(o)
n=int(eval(input())) p=list(map(int, input().split())) c=0 for i in range(0,n-2): if p[i]<p[i+1]<p[i+2] or p[i+2]<p[i+1]<p[i]: c+=1 print(c)
14
10
167
169
n = int(eval(input())) p = list(map(int, input().split())) o = 0 for i in range(1, n - 1): if p[i - 1] > p[i] > p[i + 1] or p[i + 1] > p[i] > p[i - 1]: o += 1 print(o)
n = int(eval(input())) p = list(map(int, input().split())) c = 0 for i in range(0, n - 2): if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]: c += 1 print(c)
false
28.571429
[ "-o = 0", "-for i in range(1, n - 1):", "- if p[i - 1] > p[i] > p[i + 1] or p[i + 1] > p[i] > p[i - 1]:", "- o += 1", "-print(o)", "+c = 0", "+for i in range(0, n - 2):", "+ if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:", "+ c += 1", "+print(c)" ]
false
0.164511
0.044251
3.717703
[ "s172237420", "s310386986" ]
u801049006
p02598
python
s410519906
s666683034
1,303
989
30,672
30,856
Accepted
Accepted
24.1
n, k = list(map(int, input().split())) a = list(map(int, input().split())) def check(l): cnt = 0 for i in range(n): cnt += a[i] // mid if a[i] % mid != 0: cnt += 1 cnt -= 1 return cnt <= k lb, ub = 0, max(a) while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): ub = mid else: lb = mid print(ub)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) def check(l): cnt = 0 for L in a: cnt += L // mid if L % mid != 0: cnt += 1 cnt -= 1 return cnt <= k lb, ub = 0, max(a) while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): ub = mid else: lb = mid print(ub)
25
25
398
385
n, k = list(map(int, input().split())) a = list(map(int, input().split())) def check(l): cnt = 0 for i in range(n): cnt += a[i] // mid if a[i] % mid != 0: cnt += 1 cnt -= 1 return cnt <= k lb, ub = 0, max(a) while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): ub = mid else: lb = mid print(ub)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) def check(l): cnt = 0 for L in a: cnt += L // mid if L % mid != 0: cnt += 1 cnt -= 1 return cnt <= k lb, ub = 0, max(a) while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): ub = mid else: lb = mid print(ub)
false
0
[ "- for i in range(n):", "- cnt += a[i] // mid", "- if a[i] % mid != 0:", "+ for L in a:", "+ cnt += L // mid", "+ if L % mid != 0:" ]
false
0.102256
0.159488
0.641154
[ "s410519906", "s666683034" ]
u823885866
p03162
python
s310015186
s181214589
608
305
56,520
43,116
Accepted
Accepted
49.84
import sys import math import itertools import collections import numpy as np rl = sys.stdin.readline n = int(rl()) li = [list(map(int, rl().split())) for _ in range(n)] dp = [[0]*3 for _ in range(n)] dp[0] = li[0] for i in range(1, n): a = dp[i-1][1] + li[i][0] b = dp[i-1][2] + li[i][0] dp[i][0] = max(a, b) a = dp[i-1][0] + li[i][1] b = dp[i-1][2] + li[i][1] dp[i][1] = max(a, b) a = dp[i-1][0] + li[i][2] b = dp[i-1][1] + li[i][2] dp[i][2] = max(a, b) print((max(dp[-1])))
import sys rl = sys.stdin.readline n = int(rl()) x, y, z = 0, 0, 0 for _ in range(n): a, b, c = list(map(int, rl().split())) x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c print((max(x, y, z)))
27
8
547
204
import sys import math import itertools import collections import numpy as np rl = sys.stdin.readline n = int(rl()) li = [list(map(int, rl().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0] = li[0] for i in range(1, n): a = dp[i - 1][1] + li[i][0] b = dp[i - 1][2] + li[i][0] dp[i][0] = max(a, b) a = dp[i - 1][0] + li[i][1] b = dp[i - 1][2] + li[i][1] dp[i][1] = max(a, b) a = dp[i - 1][0] + li[i][2] b = dp[i - 1][1] + li[i][2] dp[i][2] = max(a, b) print((max(dp[-1])))
import sys rl = sys.stdin.readline n = int(rl()) x, y, z = 0, 0, 0 for _ in range(n): a, b, c = list(map(int, rl().split())) x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c print((max(x, y, z)))
false
70.37037
[ "-import math", "-import itertools", "-import collections", "-import numpy as np", "-li = [list(map(int, rl().split())) for _ in range(n)]", "-dp = [[0] * 3 for _ in range(n)]", "-dp[0] = li[0]", "-for i in range(1, n):", "- a = dp[i - 1][1] + li[i][0]", "- b = dp[i - 1][2] + li[i][0]", "- dp[i][0] = max(a, b)", "- a = dp[i - 1][0] + li[i][1]", "- b = dp[i - 1][2] + li[i][1]", "- dp[i][1] = max(a, b)", "- a = dp[i - 1][0] + li[i][2]", "- b = dp[i - 1][1] + li[i][2]", "- dp[i][2] = max(a, b)", "-print((max(dp[-1])))", "+x, y, z = 0, 0, 0", "+for _ in range(n):", "+ a, b, c = list(map(int, rl().split()))", "+ x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c", "+print((max(x, y, z)))" ]
false
0.064729
0.13701
0.472437
[ "s310015186", "s181214589" ]
u761320129
p03600
python
s004059451
s466356055
943
744
44,764
45,788
Accepted
Accepted
21.1
N = int(eval(input())) src = [list(map(int,input().split())) for i in range(N)] ans = 0 for k in range(N): for i in range(N): for j in range(N): if src[i][j] > src[i][k] + src[k][j]: print((-1)) exit() src[i][j] = min(src[i][j], src[i][k] + src[k][j]) for i in range(N-1): for j in range(i+1,N): use = True for k in range(N): if k==i or k==j: continue if src[i][j] == src[i][k] + src[k][j]: use = False break if use: ans += src[i][j] print(ans)
N = int(eval(input())) src = [list(map(int,input().split())) for i in range(N)] ans = 0 for k in range(N): for i in range(N): for j in range(N): if src[i][j] > src[i][k] + src[k][j]: print((-1)) exit() for i in range(N-1): for j in range(i+1,N): use = True for k in range(N): if k==i or k==j: continue if src[i][j] == src[i][k] + src[k][j]: use = False break if use: ans += src[i][j] print(ans)
23
22
624
561
N = int(eval(input())) src = [list(map(int, input().split())) for i in range(N)] ans = 0 for k in range(N): for i in range(N): for j in range(N): if src[i][j] > src[i][k] + src[k][j]: print((-1)) exit() src[i][j] = min(src[i][j], src[i][k] + src[k][j]) for i in range(N - 1): for j in range(i + 1, N): use = True for k in range(N): if k == i or k == j: continue if src[i][j] == src[i][k] + src[k][j]: use = False break if use: ans += src[i][j] print(ans)
N = int(eval(input())) src = [list(map(int, input().split())) for i in range(N)] ans = 0 for k in range(N): for i in range(N): for j in range(N): if src[i][j] > src[i][k] + src[k][j]: print((-1)) exit() for i in range(N - 1): for j in range(i + 1, N): use = True for k in range(N): if k == i or k == j: continue if src[i][j] == src[i][k] + src[k][j]: use = False break if use: ans += src[i][j] print(ans)
false
4.347826
[ "- src[i][j] = min(src[i][j], src[i][k] + src[k][j])" ]
false
0.037645
0.038866
0.968565
[ "s004059451", "s466356055" ]
u678167152
p02623
python
s009182153
s113955381
261
193
47,436
41,844
Accepted
Accepted
26.05
from bisect import * def solve(): ans = 0 N, M, K = list(map(int, input().split())) A = list(map(int, input().split()))+[float('inf')] B = list(map(int, input().split()))+[float('inf')] cumA = [0]*(N+1) cumB = [0]*(M+1) for i in range(N): cumA[i+1] = cumA[i]+A[i] for i in range(M): cumB[i+1] = cumB[i]+B[i] for i in range(N+1): rest = K-cumA[i] if rest<0: break ind = bisect_right(cumB,rest) ans = max(ans,i+ind-1) return ans print((solve()))
from itertools import groupby, accumulate, product, permutations, combinations def solve(): ans = 0 N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A = [0]+list(accumulate(A)) B = [0]+list(accumulate(B)) b = M for a in range(N+1): if A[a]>K: break while A[a]+B[b]>K: b -= 1 ans = max(a+b,ans) return ans print((solve()))
20
17
554
478
from bisect import * def solve(): ans = 0 N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) + [float("inf")] B = list(map(int, input().split())) + [float("inf")] cumA = [0] * (N + 1) cumB = [0] * (M + 1) for i in range(N): cumA[i + 1] = cumA[i] + A[i] for i in range(M): cumB[i + 1] = cumB[i] + B[i] for i in range(N + 1): rest = K - cumA[i] if rest < 0: break ind = bisect_right(cumB, rest) ans = max(ans, i + ind - 1) return ans print((solve()))
from itertools import groupby, accumulate, product, permutations, combinations def solve(): ans = 0 N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A = [0] + list(accumulate(A)) B = [0] + list(accumulate(B)) b = M for a in range(N + 1): if A[a] > K: break while A[a] + B[b] > K: b -= 1 ans = max(a + b, ans) return ans print((solve()))
false
15
[ "-from bisect import *", "+from itertools import groupby, accumulate, product, permutations, combinations", "- A = list(map(int, input().split())) + [float(\"inf\")]", "- B = list(map(int, input().split())) + [float(\"inf\")]", "- cumA = [0] * (N + 1)", "- cumB = [0] * (M + 1)", "- for i in range(N):", "- cumA[i + 1] = cumA[i] + A[i]", "- for i in range(M):", "- cumB[i + 1] = cumB[i] + B[i]", "- for i in range(N + 1):", "- rest = K - cumA[i]", "- if rest < 0:", "+ A = list(map(int, input().split()))", "+ B = list(map(int, input().split()))", "+ A = [0] + list(accumulate(A))", "+ B = [0] + list(accumulate(B))", "+ b = M", "+ for a in range(N + 1):", "+ if A[a] > K:", "- ind = bisect_right(cumB, rest)", "- ans = max(ans, i + ind - 1)", "+ while A[a] + B[b] > K:", "+ b -= 1", "+ ans = max(a + b, ans)" ]
false
0.036294
0.035859
1.012119
[ "s009182153", "s113955381" ]
u497596438
p03253
python
s405178062
s170765548
828
594
40,044
38,512
Accepted
Accepted
28.26
def nCr(n,r): a=1 x=n while(x!=n-r): a*=x x-=1 b=1 x=r while(x!=0): b*=x x-=1 return a//b INF=10**9+7 N,m=list(map(int,input().split())) sum=1 yd = {} i = 2 while m != 1: while m % i == 0: if i in yd: yd[i] += 1 else: yd[i] = 1 m //= i i += 1 for b in list(yd.values()): if b<N-1: sum*=nCr(N-1+b,b) else: sum*=nCr(N-1+b,N-1) sum%=INF print(sum)
def main(): def nCr(n,r): a=1 x=n while(x!=n-r): a*=x x-=1 b=1 x=r while(x!=0): b*=x x-=1 return a//b INF=10**9+7 N,m=list(map(int,input().split())) sum=1 yd = {} i = 2 while m != 1: while m % i == 0: if i in yd: yd[i] += 1 else: yd[i] = 1 m //= i i += 1 for b in list(yd.values()): if b<N-1: sum*=nCr(N-1+b,b) else: sum*=nCr(N-1+b,N-1) sum%=INF print(sum) if __name__ == '__main__': main()
35
38
480
661
def nCr(n, r): a = 1 x = n while x != n - r: a *= x x -= 1 b = 1 x = r while x != 0: b *= x x -= 1 return a // b INF = 10**9 + 7 N, m = list(map(int, input().split())) sum = 1 yd = {} i = 2 while m != 1: while m % i == 0: if i in yd: yd[i] += 1 else: yd[i] = 1 m //= i i += 1 for b in list(yd.values()): if b < N - 1: sum *= nCr(N - 1 + b, b) else: sum *= nCr(N - 1 + b, N - 1) sum %= INF print(sum)
def main(): def nCr(n, r): a = 1 x = n while x != n - r: a *= x x -= 1 b = 1 x = r while x != 0: b *= x x -= 1 return a // b INF = 10**9 + 7 N, m = list(map(int, input().split())) sum = 1 yd = {} i = 2 while m != 1: while m % i == 0: if i in yd: yd[i] += 1 else: yd[i] = 1 m //= i i += 1 for b in list(yd.values()): if b < N - 1: sum *= nCr(N - 1 + b, b) else: sum *= nCr(N - 1 + b, N - 1) sum %= INF print(sum) if __name__ == "__main__": main()
false
7.894737
[ "-def nCr(n, r):", "- a = 1", "- x = n", "- while x != n - r:", "- a *= x", "- x -= 1", "- b = 1", "- x = r", "- while x != 0:", "- b *= x", "- x -= 1", "- return a // b", "+def main():", "+ def nCr(n, r):", "+ a = 1", "+ x = n", "+ while x != n - r:", "+ a *= x", "+ x -= 1", "+ b = 1", "+ x = r", "+ while x != 0:", "+ b *= x", "+ x -= 1", "+ return a // b", "+", "+ INF = 10**9 + 7", "+ N, m = list(map(int, input().split()))", "+ sum = 1", "+ yd = {}", "+ i = 2", "+ while m != 1:", "+ while m % i == 0:", "+ if i in yd:", "+ yd[i] += 1", "+ else:", "+ yd[i] = 1", "+ m //= i", "+ i += 1", "+ for b in list(yd.values()):", "+ if b < N - 1:", "+ sum *= nCr(N - 1 + b, b)", "+ else:", "+ sum *= nCr(N - 1 + b, N - 1)", "+ sum %= INF", "+ print(sum)", "-INF = 10**9 + 7", "-N, m = list(map(int, input().split()))", "-sum = 1", "-yd = {}", "-i = 2", "-while m != 1:", "- while m % i == 0:", "- if i in yd:", "- yd[i] += 1", "- else:", "- yd[i] = 1", "- m //= i", "- i += 1", "-for b in list(yd.values()):", "- if b < N - 1:", "- sum *= nCr(N - 1 + b, b)", "- else:", "- sum *= nCr(N - 1 + b, N - 1)", "- sum %= INF", "-print(sum)", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.085937
0.03946
2.177798
[ "s405178062", "s170765548" ]
u571969099
p03163
python
s785235465
s077679208
420
315
42,348
41,740
Accepted
Accepted
25
n, w = [int(i) for i in input().split()] a = [0] * (w + 1) for _ in range(n): b, c = [int(i) for i in input().split()] for i in reversed(list(range(w + 1))): if i + b >= w + 1: continue d = i + b a[d] = max(a[d], a[i] + c) print((a[-1]))
n, w = [int(i) for i in input().split()] dp = [0] * (w + 1) for _ in range(n): u, v = [int(i) for i in input().split()] for i in reversed(list(range(w - u + 1))): dp[i + u] = max(dp[i + u], dp[i] + v) print((max(dp)))
10
8
283
234
n, w = [int(i) for i in input().split()] a = [0] * (w + 1) for _ in range(n): b, c = [int(i) for i in input().split()] for i in reversed(list(range(w + 1))): if i + b >= w + 1: continue d = i + b a[d] = max(a[d], a[i] + c) print((a[-1]))
n, w = [int(i) for i in input().split()] dp = [0] * (w + 1) for _ in range(n): u, v = [int(i) for i in input().split()] for i in reversed(list(range(w - u + 1))): dp[i + u] = max(dp[i + u], dp[i] + v) print((max(dp)))
false
20
[ "-a = [0] * (w + 1)", "+dp = [0] * (w + 1)", "- b, c = [int(i) for i in input().split()]", "- for i in reversed(list(range(w + 1))):", "- if i + b >= w + 1:", "- continue", "- d = i + b", "- a[d] = max(a[d], a[i] + c)", "-print((a[-1]))", "+ u, v = [int(i) for i in input().split()]", "+ for i in reversed(list(range(w - u + 1))):", "+ dp[i + u] = max(dp[i + u], dp[i] + v)", "+print((max(dp)))" ]
false
0.042214
0.044952
0.939095
[ "s785235465", "s077679208" ]
u522293645
p02642
python
s344634919
s061602378
489
159
219,804
100,860
Accepted
Accepted
67.48
n = int(eval(input())) li = list(map(int,input().split())) ok = set() ng = set() mul = set() ans = 0 for i in li: if i not in ok: ok.add(i) else: ng.add(i) M = max(ok) for i in ok: for j in range(2,M+1): if i*j > 10**6: break else: mul.add(i*j) for i in ok: if i not in mul: if i not in ng: ans+=1 print(ans)
N = 1000001 a = [0]* N eval(input()) for x in input().split(): a[int(x)] += 1 for i in range(1, N): if a[i]: for j in range(i + i, N, i): a[j] = 0 print((a.count(1)))
29
10
429
181
n = int(eval(input())) li = list(map(int, input().split())) ok = set() ng = set() mul = set() ans = 0 for i in li: if i not in ok: ok.add(i) else: ng.add(i) M = max(ok) for i in ok: for j in range(2, M + 1): if i * j > 10**6: break else: mul.add(i * j) for i in ok: if i not in mul: if i not in ng: ans += 1 print(ans)
N = 1000001 a = [0] * N eval(input()) for x in input().split(): a[int(x)] += 1 for i in range(1, N): if a[i]: for j in range(i + i, N, i): a[j] = 0 print((a.count(1)))
false
65.517241
[ "-n = int(eval(input()))", "-li = list(map(int, input().split()))", "-ok = set()", "-ng = set()", "-mul = set()", "-ans = 0", "-for i in li:", "- if i not in ok:", "- ok.add(i)", "- else:", "- ng.add(i)", "-M = max(ok)", "-for i in ok:", "- for j in range(2, M + 1):", "- if i * j > 10**6:", "- break", "- else:", "- mul.add(i * j)", "-for i in ok:", "- if i not in mul:", "- if i not in ng:", "- ans += 1", "-print(ans)", "+N = 1000001", "+a = [0] * N", "+eval(input())", "+for x in input().split():", "+ a[int(x)] += 1", "+for i in range(1, N):", "+ if a[i]:", "+ for j in range(i + i, N, i):", "+ a[j] = 0", "+print((a.count(1)))" ]
false
0.057189
0.514111
0.111239
[ "s344634919", "s061602378" ]
u004208081
p03111
python
s781927900
s975823689
308
73
3,316
3,064
Accepted
Accepted
76.3
n, a, b, c = list(map(int, input().split())) l = [] for _ in range(n): l.append(int(eval(input()))) def dfs(depth, t, ans): if depth == n: sum = calc(t) if sum < ans: return sum else: return ans for j in range(4): tt = t.copy() tt.append(j) ans = dfs(depth + 1, tt, ans) return ans def calc(t): ttt = [ [0, 0] ] * 3 for i, v in enumerate(t): if v < 3: ttt[v] = [ttt[v][0] + 1, ttt[v][1] + l[i]] if ttt[0][0] == 0 or ttt[1][0] == 0 or ttt[2][0] == 0: return 1000000000 sum = 0 abc = [a, b, c, 0] for i, v in enumerate(ttt): sum += ((v[0] - 1) * 10) + abs(v[1] - abc[i]) return sum ans = dfs(0, [], 1000000000) print(ans)
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for _ in range(N)] INF = 10**12 def dfs(depth, a, b, c): if depth == N: return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF res1 = dfs(depth + 1, a, b, c) res2 = dfs(depth + 1, a + l[depth], b, c) + 10 res3 = dfs(depth + 1, a, b + l[depth], c) + 10 res4 = dfs(depth + 1, a, b, c + l[depth]) + 10 return min(res1, res2, res3, res4) print((dfs(0, 0, 0, 0)))
40
16
814
493
n, a, b, c = list(map(int, input().split())) l = [] for _ in range(n): l.append(int(eval(input()))) def dfs(depth, t, ans): if depth == n: sum = calc(t) if sum < ans: return sum else: return ans for j in range(4): tt = t.copy() tt.append(j) ans = dfs(depth + 1, tt, ans) return ans def calc(t): ttt = [[0, 0]] * 3 for i, v in enumerate(t): if v < 3: ttt[v] = [ttt[v][0] + 1, ttt[v][1] + l[i]] if ttt[0][0] == 0 or ttt[1][0] == 0 or ttt[2][0] == 0: return 1000000000 sum = 0 abc = [a, b, c, 0] for i, v in enumerate(ttt): sum += ((v[0] - 1) * 10) + abs(v[1] - abc[i]) return sum ans = dfs(0, [], 1000000000) print(ans)
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for _ in range(N)] INF = 10**12 def dfs(depth, a, b, c): if depth == N: return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF res1 = dfs(depth + 1, a, b, c) res2 = dfs(depth + 1, a + l[depth], b, c) + 10 res3 = dfs(depth + 1, a, b + l[depth], c) + 10 res4 = dfs(depth + 1, a, b, c + l[depth]) + 10 return min(res1, res2, res3, res4) print((dfs(0, 0, 0, 0)))
false
60
[ "-n, a, b, c = list(map(int, input().split()))", "-l = []", "-for _ in range(n):", "- l.append(int(eval(input())))", "+N, A, B, C = list(map(int, input().split()))", "+l = [int(eval(input())) for _ in range(N)]", "+INF = 10**12", "-def dfs(depth, t, ans):", "- if depth == n:", "- sum = calc(t)", "- if sum < ans:", "- return sum", "- else:", "- return ans", "- for j in range(4):", "- tt = t.copy()", "- tt.append(j)", "- ans = dfs(depth + 1, tt, ans)", "- return ans", "+def dfs(depth, a, b, c):", "+ if depth == N:", "+ return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF", "+ res1 = dfs(depth + 1, a, b, c)", "+ res2 = dfs(depth + 1, a + l[depth], b, c) + 10", "+ res3 = dfs(depth + 1, a, b + l[depth], c) + 10", "+ res4 = dfs(depth + 1, a, b, c + l[depth]) + 10", "+ return min(res1, res2, res3, res4)", "-def calc(t):", "- ttt = [[0, 0]] * 3", "- for i, v in enumerate(t):", "- if v < 3:", "- ttt[v] = [ttt[v][0] + 1, ttt[v][1] + l[i]]", "- if ttt[0][0] == 0 or ttt[1][0] == 0 or ttt[2][0] == 0:", "- return 1000000000", "- sum = 0", "- abc = [a, b, c, 0]", "- for i, v in enumerate(ttt):", "- sum += ((v[0] - 1) * 10) + abs(v[1] - abc[i])", "- return sum", "-", "-", "-ans = dfs(0, [], 1000000000)", "-print(ans)", "+print((dfs(0, 0, 0, 0)))" ]
false
0.354223
0.203968
1.736658
[ "s781927900", "s975823689" ]
u496821919
p02803
python
s979834240
s098008596
637
576
3,572
3,316
Accepted
Accepted
9.58
from collections import deque import copy h,w = list(map(int,input().split())) origin = [] dx = [1,-1,0,0] dy = [0,0,1,-1] ans = 0 for i in range(h): origin.append(list(eval(input()))) for i in range(h): if "#" in origin[i]: break else: print((h+w-2)) exit() for i in range(h): for j in range(w): if origin[i][j] == ".": d = [[0 for j in range(w)] for i in range(h)] maze = copy.deepcopy(origin) dq = deque([(j,i)]) while dq: x,y = dq.popleft() for k in range(4): nx = x + dx[k] ny = y + dy[k] if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[ny][nx] != "#": dq.append((nx,ny)) d[ny][nx] = d[y][x]+1 ans = max(ans,d[ny][nx]) maze[y][x] = "#" #print(maze) print(ans)
from collections import deque h,w = list(map(int,input().split())) dx = [1,-1,0,0] dy = [0,0,1,-1] ans = 0 maze = [] for i in range(h): maze.append(list(eval(input()))) for i in range(h): for j in range(w): if maze[i][j] == ".": d = [[-1 for a in range(w)] for b in range(h)] dq = deque([(j,i)]) d[i][j] = 0 while dq: x,y = dq.popleft() for k in range(4): nx = x + dx[k] ny = y + dy[k] if 0<=nx<=w-1 and 0<=ny<=h-1 and maze[ny][nx] != "#" and d[ny][nx] == -1: dq.append((nx,ny)) d[ny][nx] = d[y][x]+1 ans = max(ans,d[ny][nx]) print(ans)
33
24
948
775
from collections import deque import copy h, w = list(map(int, input().split())) origin = [] dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] ans = 0 for i in range(h): origin.append(list(eval(input()))) for i in range(h): if "#" in origin[i]: break else: print((h + w - 2)) exit() for i in range(h): for j in range(w): if origin[i][j] == ".": d = [[0 for j in range(w)] for i in range(h)] maze = copy.deepcopy(origin) dq = deque([(j, i)]) while dq: x, y = dq.popleft() for k in range(4): nx = x + dx[k] ny = y + dy[k] if 0 <= nx <= w - 1 and 0 <= ny <= h - 1 and maze[ny][nx] != "#": dq.append((nx, ny)) d[ny][nx] = d[y][x] + 1 ans = max(ans, d[ny][nx]) maze[y][x] = "#" # print(maze) print(ans)
from collections import deque h, w = list(map(int, input().split())) dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] ans = 0 maze = [] for i in range(h): maze.append(list(eval(input()))) for i in range(h): for j in range(w): if maze[i][j] == ".": d = [[-1 for a in range(w)] for b in range(h)] dq = deque([(j, i)]) d[i][j] = 0 while dq: x, y = dq.popleft() for k in range(4): nx = x + dx[k] ny = y + dy[k] if ( 0 <= nx <= w - 1 and 0 <= ny <= h - 1 and maze[ny][nx] != "#" and d[ny][nx] == -1 ): dq.append((nx, ny)) d[ny][nx] = d[y][x] + 1 ans = max(ans, d[ny][nx]) print(ans)
false
27.272727
[ "-import copy", "-origin = []", "+maze = []", "- origin.append(list(eval(input())))", "-for i in range(h):", "- if \"#\" in origin[i]:", "- break", "-else:", "- print((h + w - 2))", "- exit()", "+ maze.append(list(eval(input())))", "- if origin[i][j] == \".\":", "- d = [[0 for j in range(w)] for i in range(h)]", "- maze = copy.deepcopy(origin)", "+ if maze[i][j] == \".\":", "+ d = [[-1 for a in range(w)] for b in range(h)]", "+ d[i][j] = 0", "- if 0 <= nx <= w - 1 and 0 <= ny <= h - 1 and maze[ny][nx] != \"#\":", "+ if (", "+ 0 <= nx <= w - 1", "+ and 0 <= ny <= h - 1", "+ and maze[ny][nx] != \"#\"", "+ and d[ny][nx] == -1", "+ ):", "- maze[y][x] = \"#\"", "- # print(maze)" ]
false
0.0367
0.036262
1.012066
[ "s979834240", "s098008596" ]
u323045245
p02971
python
s148654822
s164571476
577
431
14,112
19,100
Accepted
Accepted
25.3
n = int(eval(input())) num = [int(eval(input())) for _ in range(n)] Sort_num = sorted(num) for i in range(n): if num[i] == Sort_num[n-1]: print((Sort_num[n-2])) else: print((Sort_num[n-1]))
from copy import deepcopy n=int(eval(input())) a=[int(eval(input())) for _ in range(n)] b = deepcopy(a) b.sort() for i in range(n): if a[i] == b[-1]: print((b[-2])) else: print((b[-1]))
8
11
193
205
n = int(eval(input())) num = [int(eval(input())) for _ in range(n)] Sort_num = sorted(num) for i in range(n): if num[i] == Sort_num[n - 1]: print((Sort_num[n - 2])) else: print((Sort_num[n - 1]))
from copy import deepcopy n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] b = deepcopy(a) b.sort() for i in range(n): if a[i] == b[-1]: print((b[-2])) else: print((b[-1]))
false
27.272727
[ "+from copy import deepcopy", "+", "-num = [int(eval(input())) for _ in range(n)]", "-Sort_num = sorted(num)", "+a = [int(eval(input())) for _ in range(n)]", "+b = deepcopy(a)", "+b.sort()", "- if num[i] == Sort_num[n - 1]:", "- print((Sort_num[n - 2]))", "+ if a[i] == b[-1]:", "+ print((b[-2]))", "- print((Sort_num[n - 1]))", "+ print((b[-1]))" ]
false
0.007861
0.127073
0.06186
[ "s148654822", "s164571476" ]
u454093752
p03043
python
s476205313
s852578110
249
178
60,012
38,896
Accepted
Accepted
28.51
from decimal import Decimal N, K = list(map(int, input().split())) t = 0 i = 1 while(i < K): t += 1 i *= 2 under = 2**t p = 0 for i in range(1, N+1): c = 0 while(i < K): c += 1 i *= 2 p += 2**(t-c) print((Decimal(p/((2**t)*N))))
N, K = list(map(int, input().split())) t = 0 i = 1 while(i < K): t += 1 i *= 2 under = 2**t p = 0 for i in range(1, N+1): c = 0 while(i < K): c += 1 i *= 2 p += 2**(t-c) print((p/((2**t)*N)))
17
16
274
235
from decimal import Decimal N, K = list(map(int, input().split())) t = 0 i = 1 while i < K: t += 1 i *= 2 under = 2**t p = 0 for i in range(1, N + 1): c = 0 while i < K: c += 1 i *= 2 p += 2 ** (t - c) print((Decimal(p / ((2**t) * N))))
N, K = list(map(int, input().split())) t = 0 i = 1 while i < K: t += 1 i *= 2 under = 2**t p = 0 for i in range(1, N + 1): c = 0 while i < K: c += 1 i *= 2 p += 2 ** (t - c) print((p / ((2**t) * N)))
false
5.882353
[ "-from decimal import Decimal", "-", "-print((Decimal(p / ((2**t) * N))))", "+print((p / ((2**t) * N)))" ]
false
0.093439
0.007986
11.700323
[ "s476205313", "s852578110" ]
u226108478
p03253
python
s238650880
s071615012
27
19
3,508
3,064
Accepted
Accepted
29.63
# -*- coding: utf-8 -*- '''Snippets for prime. Available functions: - is_included: Determine whether it is a prime number. - generate: Generate a list of prime numbers using sieve of Eratosthenes. ''' class Prime(object): '''Represents a snippet for prime numbers. ''' def __init__(self, number): self.number = number self._values = [] def is_included(self) -> bool: '''Determine whether it is a prime number. Args: number: Int of number (greater than 0). Returns: True if the input number was prime. False if the input number was not prime. See: https://qiita.com/srtk86/items/874639e361917e5016d4 https://docs.python.org/ja/3/library/2to3.html?highlight=isinstance#2to3fixer-isinstance ''' from math import sqrt if (self.number <= 1) or (isinstance(self.number, float)): return False for i in range(2, int(sqrt(self.number)) + 1): if self.number % i == 0: return False return True def generate(self) -> list: '''Generate a list of prime numbers using sieve of Eratosthenes. Returns: A list of prime numbers that is eqaul to or less than the input number. Landau notation: O(n log log n) See: https://beta.atcoder.jp/contests/abc110/submissions/3254947 ''' if self._values: return self._values is_met = [True for _ in range(self.number + 1)] is_met[0] = False is_met[1] = False for i in range(2, self.number + 1): if is_met[i]: self._values.append(i) for j in range(2 * i, self.number + 1, i): is_met[j] = False return self._values def count_combinations(n, k, mod): ans = 1 for i in range(1, k + 1): ans *= n - i + 1 ans %= mod ans *= pow(i, mod - 2, mod) ans %= mod return ans def main(): from math import sqrt n, m = list(map(int, input().split())) _prime = Prime(int(sqrt(m)) + 1) primes = _prime.generate() mod = 10 ** 9 + 7 ans = 1 for prime in primes: count = 0 while m % prime == 0: count += 1 m //= prime ans *= count_combinations(n + count - 1, count, mod) ans %= mod if m != 1: ans *= count_combinations(n, 1, mod) ans %= mod print(ans) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- mod = 10 ** 9 + 7 '''Snippets for combination. Available functions: - count_combination: Count the total number of combinations. ''' def count_combination(n: int, r: int, mod: int = 10 ** 9 + 7) -> int: '''Count the total number of combinations. nCr % mod. Args: n : Elements. Int of number (greater than 1). r : The number of r-th combinations. Int of number (greater than 0). mod : Modulo. The default is 10 ** 9 + 7. Returns: The total number of combinations. Landau notation: O(n) See: https://qiita.com/derodero24/items/91b6468e66923a87f39f ''' if r > (n - r): return count_combination(n, n - r) if r == 0 or r == n: return 1 if r == 1: return n multiple = 1 division = 1 for i in range(r): multiple *= n - i division *= i + 1 multiple %= mod division %= mod return multiple * pow(division, mod - 2, mod) % mod def solve(n: int, m: int): from math import sqrt ans = 1 remain = m for j in range(2, int(sqrt(m)) + 1): if remain % j == 0: count = 0 while remain % j == 0: count += 1 remain //= j ans *= count_combination(n + count - 1, n - 1) ans %= mod if remain != 1: ans *= count_combination(n, 1) ans %= mod return ans def main(): n, m = list(map(int, input().split())) # See: # https://www.youtube.com/watch?v=gdQxKESnXKs print((solve(n, m))) if __name__ == '__main__': main()
107
85
2,676
1,717
# -*- coding: utf-8 -*- """Snippets for prime. Available functions: - is_included: Determine whether it is a prime number. - generate: Generate a list of prime numbers using sieve of Eratosthenes. """ class Prime(object): """Represents a snippet for prime numbers.""" def __init__(self, number): self.number = number self._values = [] def is_included(self) -> bool: """Determine whether it is a prime number. Args: number: Int of number (greater than 0). Returns: True if the input number was prime. False if the input number was not prime. See: https://qiita.com/srtk86/items/874639e361917e5016d4 https://docs.python.org/ja/3/library/2to3.html?highlight=isinstance#2to3fixer-isinstance """ from math import sqrt if (self.number <= 1) or (isinstance(self.number, float)): return False for i in range(2, int(sqrt(self.number)) + 1): if self.number % i == 0: return False return True def generate(self) -> list: """Generate a list of prime numbers using sieve of Eratosthenes. Returns: A list of prime numbers that is eqaul to or less than the input number. Landau notation: O(n log log n) See: https://beta.atcoder.jp/contests/abc110/submissions/3254947 """ if self._values: return self._values is_met = [True for _ in range(self.number + 1)] is_met[0] = False is_met[1] = False for i in range(2, self.number + 1): if is_met[i]: self._values.append(i) for j in range(2 * i, self.number + 1, i): is_met[j] = False return self._values def count_combinations(n, k, mod): ans = 1 for i in range(1, k + 1): ans *= n - i + 1 ans %= mod ans *= pow(i, mod - 2, mod) ans %= mod return ans def main(): from math import sqrt n, m = list(map(int, input().split())) _prime = Prime(int(sqrt(m)) + 1) primes = _prime.generate() mod = 10**9 + 7 ans = 1 for prime in primes: count = 0 while m % prime == 0: count += 1 m //= prime ans *= count_combinations(n + count - 1, count, mod) ans %= mod if m != 1: ans *= count_combinations(n, 1, mod) ans %= mod print(ans) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- mod = 10**9 + 7 """Snippets for combination. Available functions: - count_combination: Count the total number of combinations. """ def count_combination(n: int, r: int, mod: int = 10**9 + 7) -> int: """Count the total number of combinations. nCr % mod. Args: n : Elements. Int of number (greater than 1). r : The number of r-th combinations. Int of number (greater than 0). mod : Modulo. The default is 10 ** 9 + 7. Returns: The total number of combinations. Landau notation: O(n) See: https://qiita.com/derodero24/items/91b6468e66923a87f39f """ if r > (n - r): return count_combination(n, n - r) if r == 0 or r == n: return 1 if r == 1: return n multiple = 1 division = 1 for i in range(r): multiple *= n - i division *= i + 1 multiple %= mod division %= mod return multiple * pow(division, mod - 2, mod) % mod def solve(n: int, m: int): from math import sqrt ans = 1 remain = m for j in range(2, int(sqrt(m)) + 1): if remain % j == 0: count = 0 while remain % j == 0: count += 1 remain //= j ans *= count_combination(n + count - 1, n - 1) ans %= mod if remain != 1: ans *= count_combination(n, 1) ans %= mod return ans def main(): n, m = list(map(int, input().split())) # See: # https://www.youtube.com/watch?v=gdQxKESnXKs print((solve(n, m))) if __name__ == "__main__": main()
false
20.560748
[ "-\"\"\"Snippets for prime.", "+mod = 10**9 + 7", "+\"\"\"Snippets for combination.", "-- is_included: Determine whether it is a prime number.", "-- generate: Generate a list of prime numbers using sieve of Eratosthenes.", "+- count_combination: Count the total number of combinations.", "-class Prime(object):", "- \"\"\"Represents a snippet for prime numbers.\"\"\"", "-", "- def __init__(self, number):", "- self.number = number", "- self._values = []", "-", "- def is_included(self) -> bool:", "- \"\"\"Determine whether it is a prime number.", "- Args:", "- number: Int of number (greater than 0).", "- Returns:", "- True if the input number was prime.", "- False if the input number was not prime.", "- See:", "- https://qiita.com/srtk86/items/874639e361917e5016d4", "- https://docs.python.org/ja/3/library/2to3.html?highlight=isinstance#2to3fixer-isinstance", "- \"\"\"", "- from math import sqrt", "-", "- if (self.number <= 1) or (isinstance(self.number, float)):", "- return False", "- for i in range(2, int(sqrt(self.number)) + 1):", "- if self.number % i == 0:", "- return False", "- return True", "-", "- def generate(self) -> list:", "- \"\"\"Generate a list of prime numbers using sieve of Eratosthenes.", "- Returns:", "- A list of prime numbers that is eqaul to or less than the input", "- number.", "- Landau notation: O(n log log n)", "- See:", "- https://beta.atcoder.jp/contests/abc110/submissions/3254947", "- \"\"\"", "- if self._values:", "- return self._values", "- is_met = [True for _ in range(self.number + 1)]", "- is_met[0] = False", "- is_met[1] = False", "- for i in range(2, self.number + 1):", "- if is_met[i]:", "- self._values.append(i)", "- for j in range(2 * i, self.number + 1, i):", "- is_met[j] = False", "- return self._values", "+def count_combination(n: int, r: int, mod: int = 10**9 + 7) -> int:", "+ \"\"\"Count the total number of combinations.", "+ nCr % mod.", "+ Args:", "+ n : Elements. Int of number (greater than 1).", "+ r : The number of r-th combinations. Int of number (greater than 0).", "+ mod : Modulo. The default is 10 ** 9 + 7.", "+ Returns:", "+ The total number of combinations.", "+ Landau notation: O(n)", "+ See:", "+ https://qiita.com/derodero24/items/91b6468e66923a87f39f", "+ \"\"\"", "+ if r > (n - r):", "+ return count_combination(n, n - r)", "+ if r == 0 or r == n:", "+ return 1", "+ if r == 1:", "+ return n", "+ multiple = 1", "+ division = 1", "+ for i in range(r):", "+ multiple *= n - i", "+ division *= i + 1", "+ multiple %= mod", "+ division %= mod", "+ return multiple * pow(division, mod - 2, mod) % mod", "-def count_combinations(n, k, mod):", "+def solve(n: int, m: int):", "+ from math import sqrt", "+", "- for i in range(1, k + 1):", "- ans *= n - i + 1", "- ans %= mod", "- ans *= pow(i, mod - 2, mod)", "+ remain = m", "+ for j in range(2, int(sqrt(m)) + 1):", "+ if remain % j == 0:", "+ count = 0", "+ while remain % j == 0:", "+ count += 1", "+ remain //= j", "+ ans *= count_combination(n + count - 1, n - 1)", "+ ans %= mod", "+ if remain != 1:", "+ ans *= count_combination(n, 1)", "- from math import sqrt", "-", "- _prime = Prime(int(sqrt(m)) + 1)", "- primes = _prime.generate()", "- mod = 10**9 + 7", "- ans = 1", "- for prime in primes:", "- count = 0", "- while m % prime == 0:", "- count += 1", "- m //= prime", "- ans *= count_combinations(n + count - 1, count, mod)", "- ans %= mod", "- if m != 1:", "- ans *= count_combinations(n, 1, mod)", "- ans %= mod", "- print(ans)", "+ # See:", "+ # https://www.youtube.com/watch?v=gdQxKESnXKs", "+ print((solve(n, m)))" ]
false
0.046677
0.081852
0.570252
[ "s238650880", "s071615012" ]
u782930273
p02923
python
s681377097
s942090940
90
76
14,252
14,252
Accepted
Accepted
15.56
N = int(eval(input())) H = [int(h) for h in input().split()] H.append(1e10) dH = [H[i + 1] - H[i] for i in range(N)] m, c = 0, 0 for i in range(N): d = H[i + 1] - H[i] if d <= 0: c += 1 else: if c > m: m = c c = 0 print(m)
N = int(eval(input())) H = [int(h) for h in input().split()] H.append(1e10) m, c = 0, 0 for i in range(N): d = H[i + 1] - H[i] if d <= 0: c += 1 else: if c > m: m = c c = 0 print(m)
14
13
277
211
N = int(eval(input())) H = [int(h) for h in input().split()] H.append(1e10) dH = [H[i + 1] - H[i] for i in range(N)] m, c = 0, 0 for i in range(N): d = H[i + 1] - H[i] if d <= 0: c += 1 else: if c > m: m = c c = 0 print(m)
N = int(eval(input())) H = [int(h) for h in input().split()] H.append(1e10) m, c = 0, 0 for i in range(N): d = H[i + 1] - H[i] if d <= 0: c += 1 else: if c > m: m = c c = 0 print(m)
false
7.142857
[ "-dH = [H[i + 1] - H[i] for i in range(N)]" ]
false
0.132857
0.07502
1.770946
[ "s681377097", "s942090940" ]
u440566786
p02840
python
s242900918
s963395140
1,559
687
82,524
88,148
Accepted
Accepted
55.93
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from itertools import groupby def resolve(): n,a,d=list(map(int,input().split())) if(d==0): if(a==0): print((1)) else: print((n+1)) return if(d<0): a,d=-a,-d A=[None]*(2*n+2) for k in range(n+1): L=k*a+k*(k-1)*d//2 R=k*a+k*(2*n-k-1)*d//2 r=L%d A[2*k]=(r,L//d,0) A[2*k+1]=(r,R//d,1) A.sort() ans=0 for key,iter in groupby(A,lambda x:x[0]): now=0 over=0 for r,v,q in iter: if(q==0): if(not over): now=v over+=1 else: over-=1 if(not over): ans+=v-now+1 print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n,a,d=list(map(int,input().split())) if(d==0): if(a!=0): print((n+1)) else: print((1)) return if(d<0): a,d=-a,-d # d>0 D=defaultdict(list) for k in range(n+1): q,r=divmod(k*a,d) L=q+k*(k-1)//2 R=q+k*(2*n-k-1)//2 D[r].append((L,1)) # 1 -> add D[r].append((R,2)) # 2 -> remove ans=0 for arr in list(D.values()): arr.sort() # print(arr) over=0 for v,q in arr: if(q==1 and over==0): left=v over+=1 if(q==1) else -1 if(over==0): ans+=v-left+1 print(ans) resolve()
37
37
832
868
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() from itertools import groupby def resolve(): n, a, d = list(map(int, input().split())) if d == 0: if a == 0: print((1)) else: print((n + 1)) return if d < 0: a, d = -a, -d A = [None] * (2 * n + 2) for k in range(n + 1): L = k * a + k * (k - 1) * d // 2 R = k * a + k * (2 * n - k - 1) * d // 2 r = L % d A[2 * k] = (r, L // d, 0) A[2 * k + 1] = (r, R // d, 1) A.sort() ans = 0 for key, iter in groupby(A, lambda x: x[0]): now = 0 over = 0 for r, v, q in iter: if q == 0: if not over: now = v over += 1 else: over -= 1 if not over: ans += v - now + 1 print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n, a, d = list(map(int, input().split())) if d == 0: if a != 0: print((n + 1)) else: print((1)) return if d < 0: a, d = -a, -d # d>0 D = defaultdict(list) for k in range(n + 1): q, r = divmod(k * a, d) L = q + k * (k - 1) // 2 R = q + k * (2 * n - k - 1) // 2 D[r].append((L, 1)) # 1 -> add D[r].append((R, 2)) # 2 -> remove ans = 0 for arr in list(D.values()): arr.sort() # print(arr) over = 0 for v, q in arr: if q == 1 and over == 0: left = v over += 1 if (q == 1) else -1 if over == 0: ans += v - left + 1 print(ans) resolve()
false
0
[ "-from itertools import groupby", "+from collections import defaultdict", "- if a == 0:", "+ if a != 0:", "+ print((n + 1))", "+ else:", "- else:", "- print((n + 1))", "- a, d = -a, -d", "- A = [None] * (2 * n + 2)", "+ a, d = -a, -d # d>0", "+ D = defaultdict(list)", "- L = k * a + k * (k - 1) * d // 2", "- R = k * a + k * (2 * n - k - 1) * d // 2", "- r = L % d", "- A[2 * k] = (r, L // d, 0)", "- A[2 * k + 1] = (r, R // d, 1)", "- A.sort()", "+ q, r = divmod(k * a, d)", "+ L = q + k * (k - 1) // 2", "+ R = q + k * (2 * n - k - 1) // 2", "+ D[r].append((L, 1)) # 1 -> add", "+ D[r].append((R, 2)) # 2 -> remove", "- for key, iter in groupby(A, lambda x: x[0]):", "- now = 0", "+ for arr in list(D.values()):", "+ arr.sort()", "+ # print(arr)", "- for r, v, q in iter:", "- if q == 0:", "- if not over:", "- now = v", "- over += 1", "- else:", "- over -= 1", "- if not over:", "- ans += v - now + 1", "+ for v, q in arr:", "+ if q == 1 and over == 0:", "+ left = v", "+ over += 1 if (q == 1) else -1", "+ if over == 0:", "+ ans += v - left + 1" ]
false
0.042815
0.03854
1.110928
[ "s242900918", "s963395140" ]
u562935282
p02991
python
s387769891
s329618121
636
549
93,708
99,496
Accepted
Accepted
13.68
def bfs(g, N, s, t): from collections import deque dist = [-1] * (N * 3) dist[s] = 0 dq = deque() dq.append(s) while dq: v = dq.popleft() d = dist[v] for u in g[v]: if ~dist[u]: continue dist[u] = d + 1 if u == t: return dist[t] // 3 # TLEしたので解を見つけたら即returnに変えた dq.append(u) return -1 def main(): import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N * 3)) for _ in range(M): u, v = (int(x) - 1 for x in input().split()) g[u].add(v + N) g[u + N].add(v + N * 2) g[u + N * 2].add(v) S, T = (int(x) - 1 for x in input().split()) ans = bfs(g, N, S, T) print(ans) if __name__ == '__main__': main()
def main(): from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N * 3)) for _ in range(M): u, v = (int(x) - 1 for x in input().split()) g[u].add(v + N) g[u + N].add(v + N + N) g[u + N + N].add(v) S, T = (int(x) - 1 for x in input().split()) dist = [-1] * (N * 3) dist[S] = 0 dq = deque() dq.append(S) while dq: v = dq.popleft() for u in g[v]: if ~dist[u]: continue dist[u] = dist[v] + 1 dq.append(u) if dist[T] % 3: print((-1)) return print((dist[T] // 3)) if __name__ == '__main__': main()
43
37
882
772
def bfs(g, N, s, t): from collections import deque dist = [-1] * (N * 3) dist[s] = 0 dq = deque() dq.append(s) while dq: v = dq.popleft() d = dist[v] for u in g[v]: if ~dist[u]: continue dist[u] = d + 1 if u == t: return dist[t] // 3 # TLEしたので解を見つけたら即returnに変えた dq.append(u) return -1 def main(): import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N * 3)) for _ in range(M): u, v = (int(x) - 1 for x in input().split()) g[u].add(v + N) g[u + N].add(v + N * 2) g[u + N * 2].add(v) S, T = (int(x) - 1 for x in input().split()) ans = bfs(g, N, S, T) print(ans) if __name__ == "__main__": main()
def main(): from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N * 3)) for _ in range(M): u, v = (int(x) - 1 for x in input().split()) g[u].add(v + N) g[u + N].add(v + N + N) g[u + N + N].add(v) S, T = (int(x) - 1 for x in input().split()) dist = [-1] * (N * 3) dist[S] = 0 dq = deque() dq.append(S) while dq: v = dq.popleft() for u in g[v]: if ~dist[u]: continue dist[u] = dist[v] + 1 dq.append(u) if dist[T] % 3: print((-1)) return print((dist[T] // 3)) if __name__ == "__main__": main()
false
13.953488
[ "-def bfs(g, N, s, t):", "+def main():", "-", "- dist = [-1] * (N * 3)", "- dist[s] = 0", "- dq = deque()", "- dq.append(s)", "- while dq:", "- v = dq.popleft()", "- d = dist[v]", "- for u in g[v]:", "- if ~dist[u]:", "- continue", "- dist[u] = d + 1", "- if u == t:", "- return dist[t] // 3 # TLEしたので解を見つけたら即returnに変えた", "- dq.append(u)", "- return -1", "-", "-", "-def main():", "- g[u + N].add(v + N * 2)", "- g[u + N * 2].add(v)", "+ g[u + N].add(v + N + N)", "+ g[u + N + N].add(v)", "- ans = bfs(g, N, S, T)", "- print(ans)", "+ dist = [-1] * (N * 3)", "+ dist[S] = 0", "+ dq = deque()", "+ dq.append(S)", "+ while dq:", "+ v = dq.popleft()", "+ for u in g[v]:", "+ if ~dist[u]:", "+ continue", "+ dist[u] = dist[v] + 1", "+ dq.append(u)", "+ if dist[T] % 3:", "+ print((-1))", "+ return", "+ print((dist[T] // 3))" ]
false
0.039666
0.038102
1.041048
[ "s387769891", "s329618121" ]
u047102107
p03283
python
s865069002
s328712539
2,931
633
55,384
78,524
Accepted
Accepted
78.4
# https://atcoder.jp/contests/abc106/tasks/abc106_d # MAX_N = 505 n, m, q = list(map(int, input().split())) X = [[0] * (n + 1) for _ in range(n + 1)] C = [[0] * (n + 1) for _ in range(n + 1)] count = [0] * (n + 1) for _ in range(m): li, ri = list(map(int, input().split())) X[li][ri] += 1 for i in range(1, n + 1): for j in range(1, n + 1): C[i][j] = C[i][j - 1] + X[i][j] for _ in range(q): p, q = list(map(int, input().split())) sum_k = 0 for j in range(p, q + 1): sum_k += C[j][q] - C[j][p - 1] print(sum_k)
# https://atcoder.jp/contests/abc106/tasks/abc106_d MAX_N = 505 n, m, q = list(map(int, input().split())) P = [[0] * MAX_N for _ in range(MAX_N)] # 二次元累積和 for _ in range(m): li, ri = list(map(int, input().split())) P[li][ri] += 1 for i in range(1, MAX_N): for j in range(1, MAX_N): P[i][j] += P[i][j - 1] for i in range(1, MAX_N): for j in range(1, MAX_N): P[i][j] += P[i - 1][j] # queryに答える for _ in range(q): l, r = list(map(int, input().split())) ans = P[r][r] + P[l - 1][l - 1] - P[l - 1][r] - P[r][l - 1] print(ans)
20
22
557
570
# https://atcoder.jp/contests/abc106/tasks/abc106_d # MAX_N = 505 n, m, q = list(map(int, input().split())) X = [[0] * (n + 1) for _ in range(n + 1)] C = [[0] * (n + 1) for _ in range(n + 1)] count = [0] * (n + 1) for _ in range(m): li, ri = list(map(int, input().split())) X[li][ri] += 1 for i in range(1, n + 1): for j in range(1, n + 1): C[i][j] = C[i][j - 1] + X[i][j] for _ in range(q): p, q = list(map(int, input().split())) sum_k = 0 for j in range(p, q + 1): sum_k += C[j][q] - C[j][p - 1] print(sum_k)
# https://atcoder.jp/contests/abc106/tasks/abc106_d MAX_N = 505 n, m, q = list(map(int, input().split())) P = [[0] * MAX_N for _ in range(MAX_N)] # 二次元累積和 for _ in range(m): li, ri = list(map(int, input().split())) P[li][ri] += 1 for i in range(1, MAX_N): for j in range(1, MAX_N): P[i][j] += P[i][j - 1] for i in range(1, MAX_N): for j in range(1, MAX_N): P[i][j] += P[i - 1][j] # queryに答える for _ in range(q): l, r = list(map(int, input().split())) ans = P[r][r] + P[l - 1][l - 1] - P[l - 1][r] - P[r][l - 1] print(ans)
false
9.090909
[ "-# MAX_N = 505", "+MAX_N = 505", "-X = [[0] * (n + 1) for _ in range(n + 1)]", "-C = [[0] * (n + 1) for _ in range(n + 1)]", "-count = [0] * (n + 1)", "+P = [[0] * MAX_N for _ in range(MAX_N)]", "+# 二次元累積和", "- X[li][ri] += 1", "-for i in range(1, n + 1):", "- for j in range(1, n + 1):", "- C[i][j] = C[i][j - 1] + X[i][j]", "+ P[li][ri] += 1", "+for i in range(1, MAX_N):", "+ for j in range(1, MAX_N):", "+ P[i][j] += P[i][j - 1]", "+for i in range(1, MAX_N):", "+ for j in range(1, MAX_N):", "+ P[i][j] += P[i - 1][j]", "+# queryに答える", "- p, q = list(map(int, input().split()))", "- sum_k = 0", "- for j in range(p, q + 1):", "- sum_k += C[j][q] - C[j][p - 1]", "- print(sum_k)", "+ l, r = list(map(int, input().split()))", "+ ans = P[r][r] + P[l - 1][l - 1] - P[l - 1][r] - P[r][l - 1]", "+ print(ans)" ]
false
0.045826
0.952121
0.048131
[ "s865069002", "s328712539" ]
u596276291
p04014
python
s943327468
s766193186
425
264
3,064
4,068
Accepted
Accepted
37.88
from math import floor, sqrt INF = 10 ** 20 def f(b, n): if n < b: return n else: return f(b, n // b) + (n % b) def main(): n = int(eval(input())) s = int(eval(input())) ans = INF # 1桁 if n == s: ans = min(ans, n + 1) # 2桁 for p in range(1, int(sqrt(n)) + 1): q = s - p b = (n - q) // p if 2 <= b and f(b, n) == s: ans = min(ans, b) # 3桁以上 for b in range(2, int(sqrt(n)) + 1): if f(b, n) == s: ans = min(ans, b) print((-1 if ans == INF else ans)) if __name__ == '__main__': main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt, floor from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def f(b, n): if n < b: return n return f(b, n // b) + n % b def main(): N = int(eval(input())) S = int(eval(input())) if N == S: print((N + 1)) return if N < S: print((-1)) return ans = INF for b in range(2, int(sqrt(N)) + 1): if f(b, N) == S: ans = min(ans, b) bs = set() t = N - S for i in range(1, int(sqrt(N)) + 1): if t % i == 0: bs.add(i + 1) bs.add((t // i) + 1) for b in bs: if b == 1: continue if f(b, N) == S: ans = min(ans, b) if ans == INF: print((-1)) else: print(ans) if __name__ == '__main__': main()
36
66
643
1,430
from math import floor, sqrt INF = 10**20 def f(b, n): if n < b: return n else: return f(b, n // b) + (n % b) def main(): n = int(eval(input())) s = int(eval(input())) ans = INF # 1桁 if n == s: ans = min(ans, n + 1) # 2桁 for p in range(1, int(sqrt(n)) + 1): q = s - p b = (n - q) // p if 2 <= b and f(b, n) == s: ans = min(ans, b) # 3桁以上 for b in range(2, int(sqrt(n)) + 1): if f(b, n) == s: ans = min(ans, b) print((-1 if ans == INF else ans)) if __name__ == "__main__": main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt, floor from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def f(b, n): if n < b: return n return f(b, n // b) + n % b def main(): N = int(eval(input())) S = int(eval(input())) if N == S: print((N + 1)) return if N < S: print((-1)) return ans = INF for b in range(2, int(sqrt(N)) + 1): if f(b, N) == S: ans = min(ans, b) bs = set() t = N - S for i in range(1, int(sqrt(N)) + 1): if t % i == 0: bs.add(i + 1) bs.add((t // i) + 1) for b in bs: if b == 1: continue if f(b, N) == S: ans = min(ans, b) if ans == INF: print((-1)) else: print(ans) if __name__ == "__main__": main()
false
45.454545
[ "-from math import floor, sqrt", "+from collections import defaultdict, Counter", "+from itertools import product, groupby, count, permutations, combinations", "+from math import pi, sqrt, floor", "+from collections import deque", "+from bisect import bisect, bisect_left, bisect_right", "+from string import ascii_lowercase", "+from functools import lru_cache", "+import sys", "-INF = 10**20", "+sys.setrecursionlimit(10000)", "+INF = float(\"inf\")", "+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"", "+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]", "+dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]", "+", "+", "+def inside(y, x, H, W):", "+ return 0 <= y < H and 0 <= x < W", "+", "+", "+def ceil(a, b):", "+ return (a + b - 1) // b", "- else:", "- return f(b, n // b) + (n % b)", "+ return f(b, n // b) + n % b", "- n = int(eval(input()))", "- s = int(eval(input()))", "+ N = int(eval(input()))", "+ S = int(eval(input()))", "+ if N == S:", "+ print((N + 1))", "+ return", "+ if N < S:", "+ print((-1))", "+ return", "- # 1桁", "- if n == s:", "- ans = min(ans, n + 1)", "- # 2桁", "- for p in range(1, int(sqrt(n)) + 1):", "- q = s - p", "- b = (n - q) // p", "- if 2 <= b and f(b, n) == s:", "+ for b in range(2, int(sqrt(N)) + 1):", "+ if f(b, N) == S:", "- # 3桁以上", "- for b in range(2, int(sqrt(n)) + 1):", "- if f(b, n) == s:", "+ bs = set()", "+ t = N - S", "+ for i in range(1, int(sqrt(N)) + 1):", "+ if t % i == 0:", "+ bs.add(i + 1)", "+ bs.add((t // i) + 1)", "+ for b in bs:", "+ if b == 1:", "+ continue", "+ if f(b, N) == S:", "- print((-1 if ans == INF else ans))", "+ if ans == INF:", "+ print((-1))", "+ else:", "+ print(ans)" ]
false
0.066538
0.055929
1.189673
[ "s943327468", "s766193186" ]
u021019433
p03032
python
s937139481
s621293098
44
40
3,316
3,064
Accepted
Accepted
9.09
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = list(range(i - j)), list(range(n - j, n)) s = sum(v[m] for m in chain(r1, r2)) j = i for x, m in a: if j == k: break if m in r1 or m in r2: s -= x j += 1 r = max(r, s) print(r)
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = i - j, n - j s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n)))) j = i for x, m in a: if j == k: break if m < r1 or m >= r2: s -= x j += 1 r = max(r, s) print(r)
20
20
514
513
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = list(range(i - j)), list(range(n - j, n)) s = sum(v[m] for m in chain(r1, r2)) j = i for x, m in a: if j == k: break if m in r1 or m in r2: s -= x j += 1 r = max(r, s) print(r)
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = i - j, n - j s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n)))) j = i for x, m in a: if j == k: break if m < r1 or m >= r2: s -= x j += 1 r = max(r, s) print(r)
false
0
[ "- r1, r2 = list(range(i - j)), list(range(n - j, n))", "- s = sum(v[m] for m in chain(r1, r2))", "+ r1, r2 = i - j, n - j", "+ s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n))))", "- if m in r1 or m in r2:", "+ if m < r1 or m >= r2:" ]
false
0.038038
0.112788
0.337251
[ "s937139481", "s621293098" ]
u561231954
p02948
python
s227824266
s701467233
488
446
31,924
20,432
Accepted
Accepted
8.61
def main(): from heapq import heapify,heappop,heappush n,m=list(map(int,input().split())) W=[list(map(int,input().split())) for _ in range(n)] W.sort(key=lambda x:x[0]) q=[] heapify(q) j,income=0,0 for i in range(1,m+1): while j<n and W[j][0]<=i: heappush(q,-W[j][1]) j+=1 if q: t=heappop(q) income+=-t print(income) if __name__=='__main__': main()
MOD = 10 ** 9 + 7 INF = 10 ** 11 import sys sys.setrecursionlimit(100000000) from heapq import heapify,heappop,heappush def main(): N,M = list(map(int,input().split())) works = [tuple(map(int,input().split())) for _ in range(N)] works.sort(key = lambda x:x[0]) q = [] ans = 0 j = 0 for i in range(M): while j < N and works[j][0] <= i + 1: heappush(q,-works[j][1]) j += 1 if q: p = heappop(q) ans -= p print(ans) if __name__ == '__main__': main()
22
23
476
563
def main(): from heapq import heapify, heappop, heappush n, m = list(map(int, input().split())) W = [list(map(int, input().split())) for _ in range(n)] W.sort(key=lambda x: x[0]) q = [] heapify(q) j, income = 0, 0 for i in range(1, m + 1): while j < n and W[j][0] <= i: heappush(q, -W[j][1]) j += 1 if q: t = heappop(q) income += -t print(income) if __name__ == "__main__": main()
MOD = 10**9 + 7 INF = 10**11 import sys sys.setrecursionlimit(100000000) from heapq import heapify, heappop, heappush def main(): N, M = list(map(int, input().split())) works = [tuple(map(int, input().split())) for _ in range(N)] works.sort(key=lambda x: x[0]) q = [] ans = 0 j = 0 for i in range(M): while j < N and works[j][0] <= i + 1: heappush(q, -works[j][1]) j += 1 if q: p = heappop(q) ans -= p print(ans) if __name__ == "__main__": main()
false
4.347826
[ "+MOD = 10**9 + 7", "+INF = 10**11", "+import sys", "+", "+sys.setrecursionlimit(100000000)", "+from heapq import heapify, heappop, heappush", "+", "+", "- from heapq import heapify, heappop, heappush", "-", "- n, m = list(map(int, input().split()))", "- W = [list(map(int, input().split())) for _ in range(n)]", "- W.sort(key=lambda x: x[0])", "+ N, M = list(map(int, input().split()))", "+ works = [tuple(map(int, input().split())) for _ in range(N)]", "+ works.sort(key=lambda x: x[0])", "- heapify(q)", "- j, income = 0, 0", "- for i in range(1, m + 1):", "- while j < n and W[j][0] <= i:", "- heappush(q, -W[j][1])", "+ ans = 0", "+ j = 0", "+ for i in range(M):", "+ while j < N and works[j][0] <= i + 1:", "+ heappush(q, -works[j][1])", "- t = heappop(q)", "- income += -t", "- print(income)", "+ p = heappop(q)", "+ ans -= p", "+ print(ans)" ]
false
0.066278
0.069222
0.957476
[ "s227824266", "s701467233" ]
u235027735
p02755
python
s604555250
s948619459
20
17
3,060
2,940
Accepted
Accepted
15
import math a, b = list(map(int, input().split())) for i in range(10001): if math.floor(i*0.08)==a and math.floor(i*0.1)==b: ans = i break else : ans = -1 print(ans)
import math a, b = list(map(int, input().split())) for i in range(1001): if math.floor(i*0.08)==a and math.floor(i*0.1)==b: ans = i break else : ans = -1 print(ans)
13
13
208
207
import math a, b = list(map(int, input().split())) for i in range(10001): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: ans = i break else: ans = -1 print(ans)
import math a, b = list(map(int, input().split())) for i in range(1001): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: ans = i break else: ans = -1 print(ans)
false
0
[ "-for i in range(10001):", "+for i in range(1001):" ]
false
0.046184
0.045377
1.017799
[ "s604555250", "s948619459" ]
u970197315
p03761
python
s134877597
s855267943
22
18
3,316
3,064
Accepted
Accepted
18.18
# ABC0 C - 怪文書 / Dubious Document from collections import defaultdict si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) N = ni() S = [eval(input()) for _ in range(N)] ABC = set() t = set() for i,s in enumerate(S): if i == 0: for ss in s: ABC.add(ss) t.add(ss) else: ABC = ABC & t t = set() for ss in s: t.add(ss) if len(ABC)==0: print('') exit() ABC = list(ABC) D = defaultdict(lambda: 10000) for s in S: for abc in ABC: t = s.count(abc) D[abc] = min(t,D[abc]) ANS = '' for k in D: ANS += k*D[k] L = [] for ans in ANS: L.append(ans) L.sort() print((''.join(L)))
n=int(eval(input())) s=[eval(input()) for i in range(n)] c=[[0]*26 for i in range(n)] a=[0]*26 for i,ss in enumerate(s): for sss in ss: c[i][ord(sss)-97]+=1 for i in range(26): tmp=10**9 for j in range(n): tmp=min(tmp,c[j][i]) a[i]=tmp ans=[] for i,aa in enumerate(a): t_str=chr(i+97) ans+=[t_str]*aa ans.sort() print((''.join(ans)))
43
21
795
383
# ABC0 C - 怪文書 / Dubious Document from collections import defaultdict si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) N = ni() S = [eval(input()) for _ in range(N)] ABC = set() t = set() for i, s in enumerate(S): if i == 0: for ss in s: ABC.add(ss) t.add(ss) else: ABC = ABC & t t = set() for ss in s: t.add(ss) if len(ABC) == 0: print("") exit() ABC = list(ABC) D = defaultdict(lambda: 10000) for s in S: for abc in ABC: t = s.count(abc) D[abc] = min(t, D[abc]) ANS = "" for k in D: ANS += k * D[k] L = [] for ans in ANS: L.append(ans) L.sort() print(("".join(L)))
n = int(eval(input())) s = [eval(input()) for i in range(n)] c = [[0] * 26 for i in range(n)] a = [0] * 26 for i, ss in enumerate(s): for sss in ss: c[i][ord(sss) - 97] += 1 for i in range(26): tmp = 10**9 for j in range(n): tmp = min(tmp, c[j][i]) a[i] = tmp ans = [] for i, aa in enumerate(a): t_str = chr(i + 97) ans += [t_str] * aa ans.sort() print(("".join(ans)))
false
51.162791
[ "-# ABC0 C - 怪文書 / Dubious Document", "-from collections import defaultdict", "-", "-si = lambda: eval(input())", "-ni = lambda: int(eval(input()))", "-nm = lambda: list(map(int, input().split()))", "-nl = lambda: list(map(int, input().split()))", "-N = ni()", "-S = [eval(input()) for _ in range(N)]", "-ABC = set()", "-t = set()", "-for i, s in enumerate(S):", "- if i == 0:", "- for ss in s:", "- ABC.add(ss)", "- t.add(ss)", "- else:", "- ABC = ABC & t", "- t = set()", "- for ss in s:", "- t.add(ss)", "-if len(ABC) == 0:", "- print(\"\")", "- exit()", "-ABC = list(ABC)", "-D = defaultdict(lambda: 10000)", "-for s in S:", "- for abc in ABC:", "- t = s.count(abc)", "- D[abc] = min(t, D[abc])", "-ANS = \"\"", "-for k in D:", "- ANS += k * D[k]", "-L = []", "-for ans in ANS:", "- L.append(ans)", "-L.sort()", "-print((\"\".join(L)))", "+n = int(eval(input()))", "+s = [eval(input()) for i in range(n)]", "+c = [[0] * 26 for i in range(n)]", "+a = [0] * 26", "+for i, ss in enumerate(s):", "+ for sss in ss:", "+ c[i][ord(sss) - 97] += 1", "+for i in range(26):", "+ tmp = 10**9", "+ for j in range(n):", "+ tmp = min(tmp, c[j][i])", "+ a[i] = tmp", "+ans = []", "+for i, aa in enumerate(a):", "+ t_str = chr(i + 97)", "+ ans += [t_str] * aa", "+ans.sort()", "+print((\"\".join(ans)))" ]
false
0.045483
0.044727
1.016899
[ "s134877597", "s855267943" ]
u729133443
p03399
python
s747100861
s385458396
164
17
38,420
2,940
Accepted
Accepted
89.63
i=lambda:int(eval(input()));print((min(i(),i())+min(i(),i())))
s='int(input())';print((eval(('+min(%s,%s)'%(s,s))*2)))
1
1
54
53
i = lambda: int(eval(input())) print((min(i(), i()) + min(i(), i())))
s = "int(input())" print((eval(("+min(%s,%s)" % (s, s)) * 2)))
false
0
[ "-i = lambda: int(eval(input()))", "-print((min(i(), i()) + min(i(), i())))", "+s = \"int(input())\"", "+print((eval((\"+min(%s,%s)\" % (s, s)) * 2)))" ]
false
0.147949
0.04208
3.515886
[ "s747100861", "s385458396" ]
u347640436
p03262
python
s958376148
s940922170
100
90
16,080
16,080
Accepted
Accepted
10
from sys import stdin from fractions import gcd n, x, *xs = list(map(int, stdin.read().split())) result = abs(xs[0] - x) for i in range(1, n): result = gcd(result, abs(xs[i] - x)) print(result)
from sys import stdin from fractions import gcd from functools import reduce n, x, *xs = list(map(int, stdin.read().split())) print((reduce(gcd, [abs(xs[i] - x) for i in range(n)])))
7
5
196
179
from sys import stdin from fractions import gcd n, x, *xs = list(map(int, stdin.read().split())) result = abs(xs[0] - x) for i in range(1, n): result = gcd(result, abs(xs[i] - x)) print(result)
from sys import stdin from fractions import gcd from functools import reduce n, x, *xs = list(map(int, stdin.read().split())) print((reduce(gcd, [abs(xs[i] - x) for i in range(n)])))
false
28.571429
[ "+from functools import reduce", "-result = abs(xs[0] - x)", "-for i in range(1, n):", "- result = gcd(result, abs(xs[i] - x))", "-print(result)", "+print((reduce(gcd, [abs(xs[i] - x) for i in range(n)])))" ]
false
0.049416
0.046759
1.056835
[ "s958376148", "s940922170" ]
u714300041
p03162
python
s258107612
s035962523
1,274
972
15,928
31,896
Accepted
Accepted
23.7
import numpy as np N = int(eval(input())) dp = np.zeros((N+1, 3)) # (i日目にa, b, cを行って)i日目までに得られる幸福度の最大値 """ i日目にaを選んだ場合 dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a i日目にbを選んだ場合 dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b i-1日目にcを選んだ場合 dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c """ for i in range(1, N+1): a, b, c = list(map(int, input().split())) dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c print((int(max(dp[-1, :]))))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) import bisect import numpy as np N = int(eval(input())) ABC = np.array([np.array(list(map(int, input().split()))) for _ in range(N)]) dp = np.ones((N, 3))*-float("inf") dp[0] = ABC[0] for i in range(1, N): dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + ABC[i, 0] dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + ABC[i, 1] dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + ABC[i, 2] print((int(max(dp[-1]))))
20
19
527
480
import numpy as np N = int(eval(input())) dp = np.zeros((N + 1, 3)) # (i日目にa, b, cを行って)i日目までに得られる幸福度の最大値 """ i日目にaを選んだ場合 dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a i日目にbを選んだ場合 dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b i-1日目にcを選んだ場合 dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c """ for i in range(1, N + 1): a, b, c = list(map(int, input().split())) dp[i, 0] = max(dp[i - 1, 1], dp[i - 1, 2]) + a dp[i, 1] = max(dp[i - 1, 0], dp[i - 1, 2]) + b dp[i, 2] = max(dp[i - 1, 0], dp[i - 1, 1]) + c print((int(max(dp[-1, :]))))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) import bisect import numpy as np N = int(eval(input())) ABC = np.array([np.array(list(map(int, input().split()))) for _ in range(N)]) dp = np.ones((N, 3)) * -float("inf") dp[0] = ABC[0] for i in range(1, N): dp[i, 0] = max(dp[i - 1, 1], dp[i - 1, 2]) + ABC[i, 0] dp[i, 1] = max(dp[i - 1, 0], dp[i - 1, 2]) + ABC[i, 1] dp[i, 2] = max(dp[i - 1, 0], dp[i - 1, 1]) + ABC[i, 2] print((int(max(dp[-1]))))
false
5
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)", "+import bisect", "-dp = np.zeros((N + 1, 3)) # (i日目にa, b, cを行って)i日目までに得られる幸福度の最大値", "-\"\"\"", "-i日目にaを選んだ場合", "-dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2]) + a", "-i日目にbを選んだ場合", "-dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2]) + b", "-i-1日目にcを選んだ場合", "-dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1]) + c", "-\"\"\"", "-for i in range(1, N + 1):", "- a, b, c = list(map(int, input().split()))", "- dp[i, 0] = max(dp[i - 1, 1], dp[i - 1, 2]) + a", "- dp[i, 1] = max(dp[i - 1, 0], dp[i - 1, 2]) + b", "- dp[i, 2] = max(dp[i - 1, 0], dp[i - 1, 1]) + c", "-print((int(max(dp[-1, :]))))", "+ABC = np.array([np.array(list(map(int, input().split()))) for _ in range(N)])", "+dp = np.ones((N, 3)) * -float(\"inf\")", "+dp[0] = ABC[0]", "+for i in range(1, N):", "+ dp[i, 0] = max(dp[i - 1, 1], dp[i - 1, 2]) + ABC[i, 0]", "+ dp[i, 1] = max(dp[i - 1, 0], dp[i - 1, 2]) + ABC[i, 1]", "+ dp[i, 2] = max(dp[i - 1, 0], dp[i - 1, 1]) + ABC[i, 2]", "+print((int(max(dp[-1]))))" ]
false
0.20239
0.508637
0.397906
[ "s258107612", "s035962523" ]
u523087093
p02579
python
s027618031
s232262323
1,919
677
23,116
129,064
Accepted
Accepted
64.72
import sys input = sys.stdin.readline def main(): h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch += 1 cw += 1 dh += 1 dw += 1 s = ["#"*(w+4)] s.append("#"*(w+4)) for i in range(h): s.append("##" + input()[:-1] + "##") s.append("#"*(w+4)) s.append("#"*(w+4)) ans = [[-1]*(w+4) for _ in range(h+4)] for i in range(h+4): for j in range(w+4): if s[i][j] == "#": ans[i][j] = -2 ans[ch][cw] = 0 move = [(-1, 0), (1, 0), (0, -1), (0, 1)] move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), \ (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), \ (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), \ (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), \ (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)] not_yet = [(ch, cw)] one_time = [] while len(not_yet) > 0: x, y = not_yet.pop() one_time.append((x, y)) for (p, q) in move: v1, v2 = x+p, y+q if ans[v1][v2] == -1: not_yet.append((v1, v2)) ans[v1][v2] = ans[x][y] if len(not_yet) == 0: while len(one_time) > 0: x2, y2 = one_time.pop() for (v1, v2) in move2: i, j = x2+v1, y2+v2 if ans[i][j] == -1: ans[i][j] = ans[x2][y2]+1 not_yet.append((i, j)) print((ans[dh][dw])) if __name__ == "__main__": main()
#----------[インポート]----------# from collections import deque def main(): #----------[入力受取・初期設定]----------# H, W = list(map(int, input().split())) C = tuple(map(int, input().split())) # 魔法の位置 D = tuple(map(int, input().split())) # ゴール D_y = D[0] -1 # 0スタート D_x = D[1] -1 # 0スタート S = [list(eval(input())) for _ in range(H)] visited = [[-1] * W for _ in range(H)] visited[C[0]-1][C[1]-1] = 0 # 初期値 moves = [(1, 0), (0, 1), (-1, 0), (0, -1)] # 普通の移動 main_q = deque() magic_q = deque() # マジック用のキュー main_q.append((C[0]-1, C[1]-1)) # magic_q.append((C[0]-1, C[1]-1)) #----------[BFS]----------# while main_q: y, x = main_q.pop() magic_q.append((y, x)) for move in moves: dy, dx = move moved_y = y + dy moved_x = x + dx if moved_y < 0 or H -1 < moved_y or moved_x < 0 or W -1 < moved_x: continue if S[moved_y][moved_x] == '#': continue if S[moved_y][moved_x] == '.' and visited[moved_y][moved_x] == -1: main_q.append((moved_y, moved_x)) visited[moved_y][moved_x] = visited[y][x] #----------[マジック用のBFS]----------# if not main_q: # main_qが空になった場合は探索済みからマジックを使う while magic_q: y, x = magic_q.pop() for dy in range(-2, 3): for dx in range(-2, 3): moved_y = y + dy moved_x = x + dx if moved_y < 0 or H -1 < moved_y or moved_x < 0 or W -1 < moved_x: continue if S[moved_y][moved_x] == '#': continue if S[moved_y][moved_x] == '.' and visited[moved_y][moved_x] == -1: main_q.append((moved_y, moved_x)) visited[moved_y][moved_x] = visited[y][x] + 1 answer = visited[D_y][D_x] print(answer) if __name__ == "__main__": main()
64
58
1,732
2,105
import sys input = sys.stdin.readline def main(): h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch += 1 cw += 1 dh += 1 dw += 1 s = ["#" * (w + 4)] s.append("#" * (w + 4)) for i in range(h): s.append("##" + input()[:-1] + "##") s.append("#" * (w + 4)) s.append("#" * (w + 4)) ans = [[-1] * (w + 4) for _ in range(h + 4)] for i in range(h + 4): for j in range(w + 4): if s[i][j] == "#": ans[i][j] = -2 ans[ch][cw] = 0 move = [(-1, 0), (1, 0), (0, -1), (0, 1)] move2 = [ (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), ] not_yet = [(ch, cw)] one_time = [] while len(not_yet) > 0: x, y = not_yet.pop() one_time.append((x, y)) for (p, q) in move: v1, v2 = x + p, y + q if ans[v1][v2] == -1: not_yet.append((v1, v2)) ans[v1][v2] = ans[x][y] if len(not_yet) == 0: while len(one_time) > 0: x2, y2 = one_time.pop() for (v1, v2) in move2: i, j = x2 + v1, y2 + v2 if ans[i][j] == -1: ans[i][j] = ans[x2][y2] + 1 not_yet.append((i, j)) print((ans[dh][dw])) if __name__ == "__main__": main()
# ----------[インポート]----------# from collections import deque def main(): # ----------[入力受取・初期設定]----------# H, W = list(map(int, input().split())) C = tuple(map(int, input().split())) # 魔法の位置 D = tuple(map(int, input().split())) # ゴール D_y = D[0] - 1 # 0スタート D_x = D[1] - 1 # 0スタート S = [list(eval(input())) for _ in range(H)] visited = [[-1] * W for _ in range(H)] visited[C[0] - 1][C[1] - 1] = 0 # 初期値 moves = [(1, 0), (0, 1), (-1, 0), (0, -1)] # 普通の移動 main_q = deque() magic_q = deque() # マジック用のキュー main_q.append((C[0] - 1, C[1] - 1)) # magic_q.append((C[0]-1, C[1]-1)) # ----------[BFS]----------# while main_q: y, x = main_q.pop() magic_q.append((y, x)) for move in moves: dy, dx = move moved_y = y + dy moved_x = x + dx if moved_y < 0 or H - 1 < moved_y or moved_x < 0 or W - 1 < moved_x: continue if S[moved_y][moved_x] == "#": continue if S[moved_y][moved_x] == "." and visited[moved_y][moved_x] == -1: main_q.append((moved_y, moved_x)) visited[moved_y][moved_x] = visited[y][x] # ----------[マジック用のBFS]----------# if not main_q: # main_qが空になった場合は探索済みからマジックを使う while magic_q: y, x = magic_q.pop() for dy in range(-2, 3): for dx in range(-2, 3): moved_y = y + dy moved_x = x + dx if ( moved_y < 0 or H - 1 < moved_y or moved_x < 0 or W - 1 < moved_x ): continue if S[moved_y][moved_x] == "#": continue if ( S[moved_y][moved_x] == "." and visited[moved_y][moved_x] == -1 ): main_q.append((moved_y, moved_x)) visited[moved_y][moved_x] = visited[y][x] + 1 answer = visited[D_y][D_x] print(answer) if __name__ == "__main__": main()
false
9.375
[ "-import sys", "-", "-input = sys.stdin.readline", "+from collections import deque", "- h, w = list(map(int, input().split()))", "- ch, cw = list(map(int, input().split()))", "- dh, dw = list(map(int, input().split()))", "- ch += 1", "- cw += 1", "- dh += 1", "- dw += 1", "- s = [\"#\" * (w + 4)]", "- s.append(\"#\" * (w + 4))", "- for i in range(h):", "- s.append(\"##\" + input()[:-1] + \"##\")", "- s.append(\"#\" * (w + 4))", "- s.append(\"#\" * (w + 4))", "- ans = [[-1] * (w + 4) for _ in range(h + 4)]", "- for i in range(h + 4):", "- for j in range(w + 4):", "- if s[i][j] == \"#\":", "- ans[i][j] = -2", "- ans[ch][cw] = 0", "- move = [(-1, 0), (1, 0), (0, -1), (0, 1)]", "- move2 = [", "- (-2, -2),", "- (-2, -1),", "- (-2, 0),", "- (-2, 1),", "- (-2, 2),", "- (-1, -2),", "- (-1, -1),", "- (-1, 0),", "- (-1, 1),", "- (-1, 2),", "- (0, -2),", "- (0, -1),", "- (0, 0),", "- (0, 1),", "- (0, 2),", "- (1, -2),", "- (1, -1),", "- (1, 0),", "- (1, 1),", "- (1, 2),", "- (2, -2),", "- (2, -1),", "- (2, 0),", "- (2, 1),", "- (2, 2),", "- ]", "- not_yet = [(ch, cw)]", "- one_time = []", "- while len(not_yet) > 0:", "- x, y = not_yet.pop()", "- one_time.append((x, y))", "- for (p, q) in move:", "- v1, v2 = x + p, y + q", "- if ans[v1][v2] == -1:", "- not_yet.append((v1, v2))", "- ans[v1][v2] = ans[x][y]", "- if len(not_yet) == 0:", "- while len(one_time) > 0:", "- x2, y2 = one_time.pop()", "- for (v1, v2) in move2:", "- i, j = x2 + v1, y2 + v2", "- if ans[i][j] == -1:", "- ans[i][j] = ans[x2][y2] + 1", "- not_yet.append((i, j))", "- print((ans[dh][dw]))", "+ H, W = list(map(int, input().split()))", "+ C = tuple(map(int, input().split())) # 魔法の位置", "+ D = tuple(map(int, input().split())) # ゴール", "+ D_y = D[0] - 1 # 0スタート", "+ D_x = D[1] - 1 # 0スタート", "+ S = [list(eval(input())) for _ in range(H)]", "+ visited = [[-1] * W for _ in range(H)]", "+ visited[C[0] - 1][C[1] - 1] = 0 # 初期値", "+ moves = [(1, 0), (0, 1), (-1, 0), (0, -1)] # 普通の移動", "+ main_q = deque()", "+ magic_q = deque() # マジック用のキュー", "+ main_q.append((C[0] - 1, C[1] - 1))", "+ # magic_q.append((C[0]-1, C[1]-1))", "+ while main_q:", "+ y, x = main_q.pop()", "+ magic_q.append((y, x))", "+ for move in moves:", "+ dy, dx = move", "+ moved_y = y + dy", "+ moved_x = x + dx", "+ if moved_y < 0 or H - 1 < moved_y or moved_x < 0 or W - 1 < moved_x:", "+ continue", "+ if S[moved_y][moved_x] == \"#\":", "+ continue", "+ if S[moved_y][moved_x] == \".\" and visited[moved_y][moved_x] == -1:", "+ main_q.append((moved_y, moved_x))", "+ visited[moved_y][moved_x] = visited[y][x]", "+ if not main_q: # main_qが空になった場合は探索済みからマジックを使う", "+ while magic_q:", "+ y, x = magic_q.pop()", "+ for dy in range(-2, 3):", "+ for dx in range(-2, 3):", "+ moved_y = y + dy", "+ moved_x = x + dx", "+ if (", "+ moved_y < 0", "+ or H - 1 < moved_y", "+ or moved_x < 0", "+ or W - 1 < moved_x", "+ ):", "+ continue", "+ if S[moved_y][moved_x] == \"#\":", "+ continue", "+ if (", "+ S[moved_y][moved_x] == \".\"", "+ and visited[moved_y][moved_x] == -1", "+ ):", "+ main_q.append((moved_y, moved_x))", "+ visited[moved_y][moved_x] = visited[y][x] + 1", "+ answer = visited[D_y][D_x]", "+ print(answer)" ]
false
0.036445
0.037553
0.970499
[ "s027618031", "s232262323" ]
u449473917
p03029
python
s394515964
s131119825
19
17
2,940
2,940
Accepted
Accepted
10.53
a,b=list(map(int,input().split())) print((((a*3)+b)//2))
import math a,p=list(map(int,input().split())) ans=math.floor((a*3+p)/2) print(ans)
2
6
49
84
a, b = list(map(int, input().split())) print((((a * 3) + b) // 2))
import math a, p = list(map(int, input().split())) ans = math.floor((a * 3 + p) / 2) print(ans)
false
66.666667
[ "-a, b = list(map(int, input().split()))", "-print((((a * 3) + b) // 2))", "+import math", "+", "+a, p = list(map(int, input().split()))", "+ans = math.floor((a * 3 + p) / 2)", "+print(ans)" ]
false
0.111305
0.051995
2.140688
[ "s394515964", "s131119825" ]
u732061897
p03147
python
s340722382
s112929968
34
29
9,108
9,160
Accepted
Accepted
14.71
N = int(eval(input())) H = list(map(int, input().split())) is_init = True is_end = False ans = 0 while not is_end: is_init = True for i in range(N): h = H[i] if h <= 0: if i == N - 1 and is_init: is_end = True H[i] -= 1 else: is_init = False if i - 1 >= 0: pre = H[i - 1] if pre <= -1: ans += 1 else: if h != 0: ans += 1 H[i] -= 1 print(ans)
N = int(eval(input())) H = list(map(int, input().split())) ans = H[0] active = H[0] for i in range(1,N): h = H[i] ans += max(0, h - active) active = h print(ans)
24
9
566
176
N = int(eval(input())) H = list(map(int, input().split())) is_init = True is_end = False ans = 0 while not is_end: is_init = True for i in range(N): h = H[i] if h <= 0: if i == N - 1 and is_init: is_end = True H[i] -= 1 else: is_init = False if i - 1 >= 0: pre = H[i - 1] if pre <= -1: ans += 1 else: if h != 0: ans += 1 H[i] -= 1 print(ans)
N = int(eval(input())) H = list(map(int, input().split())) ans = H[0] active = H[0] for i in range(1, N): h = H[i] ans += max(0, h - active) active = h print(ans)
false
62.5
[ "-is_init = True", "-is_end = False", "-ans = 0", "-while not is_end:", "- is_init = True", "- for i in range(N):", "- h = H[i]", "- if h <= 0:", "- if i == N - 1 and is_init:", "- is_end = True", "- H[i] -= 1", "- else:", "- is_init = False", "- if i - 1 >= 0:", "- pre = H[i - 1]", "- if pre <= -1:", "- ans += 1", "- else:", "- if h != 0:", "- ans += 1", "- H[i] -= 1", "+ans = H[0]", "+active = H[0]", "+for i in range(1, N):", "+ h = H[i]", "+ ans += max(0, h - active)", "+ active = h" ]
false
0.037621
0.036925
1.018842
[ "s340722382", "s112929968" ]
u977389981
p03013
python
s478164558
s416497846
480
146
50,776
14,320
Accepted
Accepted
69.58
import sys N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] mod = 10 ** 9 + 7 if N == 1: print((1)) sys.exit() B = ['.'] * (N + 1) for a in A: B[a] = '#' dp = [0] * (N + 1) if B[1] == '.' and B[2] == '.': dp[1] = 1 dp[2] = 2 elif B[1] == '#' and B[2] == '.': dp[2] = 1 elif B[1] == '.' and B[2] == '#': dp[1] = 1 for i in range(3, N + 1): if B[i] == '.': dp[i] = (dp[i - 2] + dp[i - 1]) % mod print((dp[N]))
import sys n, m = list(map(int, input().split())) A = [int(eval(input())) for _ in range(m)] mod = 1000000007 if n == 1: print((1)) sys.exit() B = ['.'] * (n + 1) for a in A: B[a] = '#' dp = [0] * (n + 1) if B[1] == '.' and B[2] == '.': dp[1] = 1 dp[2] = 2 elif B[1] == '#' and B[2] == '.': dp[2] = 1 elif B[1] == '.' and B[2] == '#': dp[1] = 1 for i in range(3, n + 1): if B[i] == '.': dp[i] = (dp[i - 2] + dp[i - 1]) % mod print((dp[-1]))
27
27
508
507
import sys N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] mod = 10**9 + 7 if N == 1: print((1)) sys.exit() B = ["."] * (N + 1) for a in A: B[a] = "#" dp = [0] * (N + 1) if B[1] == "." and B[2] == ".": dp[1] = 1 dp[2] = 2 elif B[1] == "#" and B[2] == ".": dp[2] = 1 elif B[1] == "." and B[2] == "#": dp[1] = 1 for i in range(3, N + 1): if B[i] == ".": dp[i] = (dp[i - 2] + dp[i - 1]) % mod print((dp[N]))
import sys n, m = list(map(int, input().split())) A = [int(eval(input())) for _ in range(m)] mod = 1000000007 if n == 1: print((1)) sys.exit() B = ["."] * (n + 1) for a in A: B[a] = "#" dp = [0] * (n + 1) if B[1] == "." and B[2] == ".": dp[1] = 1 dp[2] = 2 elif B[1] == "#" and B[2] == ".": dp[2] = 1 elif B[1] == "." and B[2] == "#": dp[1] = 1 for i in range(3, n + 1): if B[i] == ".": dp[i] = (dp[i - 2] + dp[i - 1]) % mod print((dp[-1]))
false
0
[ "-N, M = list(map(int, input().split()))", "-A = [int(eval(input())) for _ in range(M)]", "-mod = 10**9 + 7", "-if N == 1:", "+n, m = list(map(int, input().split()))", "+A = [int(eval(input())) for _ in range(m)]", "+mod = 1000000007", "+if n == 1:", "-B = [\".\"] * (N + 1)", "+B = [\".\"] * (n + 1)", "-dp = [0] * (N + 1)", "+dp = [0] * (n + 1)", "-for i in range(3, N + 1):", "+for i in range(3, n + 1):", "-print((dp[N]))", "+print((dp[-1]))" ]
false
0.043335
0.043346
0.99974
[ "s478164558", "s416497846" ]
u313291636
p03000
python
s884325223
s333580229
61
29
61,900
9,112
Accepted
Accepted
52.46
n, x = list(map(int, input().split())) l = list(map(int, input().split())) bound = [0] for i in range(n): bound.append(bound[i] + l[i]) ans = 0 for j in range(n+1): if bound[j] <= x: ans += 1 print(ans)
n, x = list(map(int, input().split())) l = list(map(int, input().split())) d = [0] * (n+1) ans = 1 for i in range(1, n+1): d[i] = d[i-1] + l[i-1] if d[i] <= x: ans += 1 print(ans)
12
11
226
202
n, x = list(map(int, input().split())) l = list(map(int, input().split())) bound = [0] for i in range(n): bound.append(bound[i] + l[i]) ans = 0 for j in range(n + 1): if bound[j] <= x: ans += 1 print(ans)
n, x = list(map(int, input().split())) l = list(map(int, input().split())) d = [0] * (n + 1) ans = 1 for i in range(1, n + 1): d[i] = d[i - 1] + l[i - 1] if d[i] <= x: ans += 1 print(ans)
false
8.333333
[ "-bound = [0]", "-for i in range(n):", "- bound.append(bound[i] + l[i])", "-ans = 0", "-for j in range(n + 1):", "- if bound[j] <= x:", "+d = [0] * (n + 1)", "+ans = 1", "+for i in range(1, n + 1):", "+ d[i] = d[i - 1] + l[i - 1]", "+ if d[i] <= x:" ]
false
0.03838
0.037219
1.031203
[ "s884325223", "s333580229" ]
u072053884
p02246
python
s248305161
s821769700
12,520
4,370
424,920
7,936
Accepted
Accepted
65.1
# Manhattan Distance distance = ( (), (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6), (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5), (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4), (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3), (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5), (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4), (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3), (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2), (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4), (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3), (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2), (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1), (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3), (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2), (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1) ) def get_distance(board): sd = 0 for i in range(16): p = board[i] if p == 0: continue sd += distance[p][i] return sd adjacent = ( (1, 4), # 0 (0, 2, 5), # 1 (1, 3, 6), # 2 (2, 7), # 3 (0, 5, 8), # 4 (1, 4, 6, 9), # 5 (2, 5, 7, 10), # 6 (3, 6, 11), # 7 (4, 9, 12), # 8 (5, 8, 10, 13), # 9 (6, 9, 11, 14), # 10 (7, 10, 15), # 11 (8, 13), # 12 (9, 12, 14), # 13 (10, 13, 15), # 14 (11, 14) # 15 ) GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] import sys import heapq # A* algorithm def solve(): board = list(map(int, sys.stdin.read().split())) h_cost = get_distance(board) state = (h_cost, board) q = [state] # priority queue d = {tuple(board): True} while q: state1 = heapq.heappop(q) h_cost, board = state1 if board == GOAL: return h_cost space = board.index(0) for i in adjacent[space]: p = board[i] new_board = board[:] new_board[space], new_board[i] = p, 0 new_h_cost = h_cost + 1 - distance[p][i] + distance[p][space] key = tuple(new_board) if key not in d and new_h_cost <= 45: new_state = (new_h_cost, new_board) heapq.heappush(q, new_state) d[key] = True print((solve()))
distance = ( (), (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6), (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5), (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4), (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3), (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5), (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4), (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3), (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2), (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4), (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3), (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2), (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1), (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3), (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2), (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1) ) def get_distance(board): sd = 0 for i in range(16): p = board[i] if p == 0: continue sd += distance[p][i] return sd adjacent = ( (1, 4), # 0 (0, 2, 5), # 1 (1, 3, 6), # 2 (2, 7), # 3 (0, 5, 8), # 4 (1, 4, 6, 9), # 5 (2, 5, 7, 10), # 6 (3, 6, 11), # 7 (4, 9, 12), # 8 (5, 8, 10, 13), # 9 (6, 9, 11, 14), # 10 (7, 10, 15), # 11 (8, 13), # 12 (9, 12, 14), # 13 (10, 13, 15), # 14 (11, 14) # 15 ) GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] def df_lower_search(limit, move, space, lower, pre_p): if move == limit: if board == GOAL: return True else: for i in adjacent[space]: p = board[i] if p == pre_p: continue board[space] = p board[i] = 0 new_lower = lower - distance[p][i] + distance[p][space] if new_lower + move <= limit: if df_lower_search(limit, move + 1, i, new_lower, p): return True board[space] = 0 board[i] = p import sys board = list(map(int, sys.stdin.read().split())) s = board.index(0) e_o = (0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0) n = get_distance(board) if e_o[s] != n % 2: n += 1 for l in range(n, 46, 2): if df_lower_search(l, 0, s, n, None): print(l) break
81
83
2,421
2,410
# Manhattan Distance distance = ( (), (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6), (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5), (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4), (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3), (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5), (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4), (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3), (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2), (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4), (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3), (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2), (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1), (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3), (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2), (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1), ) def get_distance(board): sd = 0 for i in range(16): p = board[i] if p == 0: continue sd += distance[p][i] return sd adjacent = ( (1, 4), # 0 (0, 2, 5), # 1 (1, 3, 6), # 2 (2, 7), # 3 (0, 5, 8), # 4 (1, 4, 6, 9), # 5 (2, 5, 7, 10), # 6 (3, 6, 11), # 7 (4, 9, 12), # 8 (5, 8, 10, 13), # 9 (6, 9, 11, 14), # 10 (7, 10, 15), # 11 (8, 13), # 12 (9, 12, 14), # 13 (10, 13, 15), # 14 (11, 14), # 15 ) GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] import sys import heapq # A* algorithm def solve(): board = list(map(int, sys.stdin.read().split())) h_cost = get_distance(board) state = (h_cost, board) q = [state] # priority queue d = {tuple(board): True} while q: state1 = heapq.heappop(q) h_cost, board = state1 if board == GOAL: return h_cost space = board.index(0) for i in adjacent[space]: p = board[i] new_board = board[:] new_board[space], new_board[i] = p, 0 new_h_cost = h_cost + 1 - distance[p][i] + distance[p][space] key = tuple(new_board) if key not in d and new_h_cost <= 45: new_state = (new_h_cost, new_board) heapq.heappush(q, new_state) d[key] = True print((solve()))
distance = ( (), (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6), (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5), (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4), (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3), (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5), (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4), (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3), (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2), (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4), (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3), (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2), (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1), (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3), (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2), (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1), ) def get_distance(board): sd = 0 for i in range(16): p = board[i] if p == 0: continue sd += distance[p][i] return sd adjacent = ( (1, 4), # 0 (0, 2, 5), # 1 (1, 3, 6), # 2 (2, 7), # 3 (0, 5, 8), # 4 (1, 4, 6, 9), # 5 (2, 5, 7, 10), # 6 (3, 6, 11), # 7 (4, 9, 12), # 8 (5, 8, 10, 13), # 9 (6, 9, 11, 14), # 10 (7, 10, 15), # 11 (8, 13), # 12 (9, 12, 14), # 13 (10, 13, 15), # 14 (11, 14), # 15 ) GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] def df_lower_search(limit, move, space, lower, pre_p): if move == limit: if board == GOAL: return True else: for i in adjacent[space]: p = board[i] if p == pre_p: continue board[space] = p board[i] = 0 new_lower = lower - distance[p][i] + distance[p][space] if new_lower + move <= limit: if df_lower_search(limit, move + 1, i, new_lower, p): return True board[space] = 0 board[i] = p import sys board = list(map(int, sys.stdin.read().split())) s = board.index(0) e_o = (0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0) n = get_distance(board) if e_o[s] != n % 2: n += 1 for l in range(n, 46, 2): if df_lower_search(l, 0, s, n, None): print(l) break
false
2.409639
[ "-# Manhattan Distance", "-import sys", "-import heapq", "-# A* algorithm", "-def solve():", "- board = list(map(int, sys.stdin.read().split()))", "- h_cost = get_distance(board)", "- state = (h_cost, board)", "- q = [state] # priority queue", "- d = {tuple(board): True}", "- while q:", "- state1 = heapq.heappop(q)", "- h_cost, board = state1", "+", "+def df_lower_search(limit, move, space, lower, pre_p):", "+ if move == limit:", "- return h_cost", "- space = board.index(0)", "+ return True", "+ else:", "- new_board = board[:]", "- new_board[space], new_board[i] = p, 0", "- new_h_cost = h_cost + 1 - distance[p][i] + distance[p][space]", "- key = tuple(new_board)", "- if key not in d and new_h_cost <= 45:", "- new_state = (new_h_cost, new_board)", "- heapq.heappush(q, new_state)", "- d[key] = True", "+ if p == pre_p:", "+ continue", "+ board[space] = p", "+ board[i] = 0", "+ new_lower = lower - distance[p][i] + distance[p][space]", "+ if new_lower + move <= limit:", "+ if df_lower_search(limit, move + 1, i, new_lower, p):", "+ return True", "+ board[space] = 0", "+ board[i] = p", "-print((solve()))", "+import sys", "+", "+board = list(map(int, sys.stdin.read().split()))", "+s = board.index(0)", "+e_o = (0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0)", "+n = get_distance(board)", "+if e_o[s] != n % 2:", "+ n += 1", "+for l in range(n, 46, 2):", "+ if df_lower_search(l, 0, s, n, None):", "+ print(l)", "+ break" ]
false
0.103632
0.043582
2.377897
[ "s248305161", "s821769700" ]
u606878291
p03163
python
s051295031
s412755248
227
182
92,616
29,620
Accepted
Accepted
19.82
import numpy as np N, W = list(map(int, input().split(' '))) items = [tuple(map(int, input().split(' '))) for _ in range(N)] dp = np.zeros(shape=(N + 1, W + 1), dtype=int) for i in range(N): weight = items[i][0] value = items[i][1] dp[i + 1][:weight] = dp[i][:weight] dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight]) print((dp[N][W]))
import numpy as np N, W = list(map(int, input().split(' '))) items = [tuple(map(int, input().split(' '))) for _ in range(N)] dp = np.zeros(shape=W + 1, dtype=np.int64) for weight, value in items: dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value) print((dp[-1]))
15
10
386
280
import numpy as np N, W = list(map(int, input().split(" "))) items = [tuple(map(int, input().split(" "))) for _ in range(N)] dp = np.zeros(shape=(N + 1, W + 1), dtype=int) for i in range(N): weight = items[i][0] value = items[i][1] dp[i + 1][:weight] = dp[i][:weight] dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight]) print((dp[N][W]))
import numpy as np N, W = list(map(int, input().split(" "))) items = [tuple(map(int, input().split(" "))) for _ in range(N)] dp = np.zeros(shape=W + 1, dtype=np.int64) for weight, value in items: dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value) print((dp[-1]))
false
33.333333
[ "-dp = np.zeros(shape=(N + 1, W + 1), dtype=int)", "-for i in range(N):", "- weight = items[i][0]", "- value = items[i][1]", "- dp[i + 1][:weight] = dp[i][:weight]", "- dp[i + 1][weight:] = np.maximum(dp[i][weight:], value + dp[i][:-weight])", "-print((dp[N][W]))", "+dp = np.zeros(shape=W + 1, dtype=np.int64)", "+for weight, value in items:", "+ dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)", "+print((dp[-1]))" ]
false
0.253446
0.252911
1.002114
[ "s051295031", "s412755248" ]
u816631826
p03239
python
s598687606
s010226842
20
18
3,316
3,064
Accepted
Accepted
10
a, b = list(map(int, input().split())) menor_t, menor_c = 1000, 1000 index = 0 for i in range(a): c, t = list(map(int, input().split())) if t <= b: if c < menor_c: menor_c = c index = i + 1 if index == 0: print('TLE') else: print(menor_c)
fline = eval(input()) it, max_time = [int(n) for n in fline.split()] cost_time = [] for i in range(it): line = eval(input()) c, t = [int(n) for n in line.split()] pair = (c, t) cost_time.append(pair) cost_time.sort(key=lambda x: x[1]) cost_time2 = [] for i in range(it): tupl = cost_time[i] if(tupl[1]<=max_time): cost_time2.append(cost_time[i]) cost_time2.sort(key=lambda x: x[0]) if(len(cost_time2)==0): print('TLE') else: el = cost_time2[0] print((el[0]))
13
24
282
515
a, b = list(map(int, input().split())) menor_t, menor_c = 1000, 1000 index = 0 for i in range(a): c, t = list(map(int, input().split())) if t <= b: if c < menor_c: menor_c = c index = i + 1 if index == 0: print("TLE") else: print(menor_c)
fline = eval(input()) it, max_time = [int(n) for n in fline.split()] cost_time = [] for i in range(it): line = eval(input()) c, t = [int(n) for n in line.split()] pair = (c, t) cost_time.append(pair) cost_time.sort(key=lambda x: x[1]) cost_time2 = [] for i in range(it): tupl = cost_time[i] if tupl[1] <= max_time: cost_time2.append(cost_time[i]) cost_time2.sort(key=lambda x: x[0]) if len(cost_time2) == 0: print("TLE") else: el = cost_time2[0] print((el[0]))
false
45.833333
[ "-a, b = list(map(int, input().split()))", "-menor_t, menor_c = 1000, 1000", "-index = 0", "-for i in range(a):", "- c, t = list(map(int, input().split()))", "- if t <= b:", "- if c < menor_c:", "- menor_c = c", "- index = i + 1", "-if index == 0:", "+fline = eval(input())", "+it, max_time = [int(n) for n in fline.split()]", "+cost_time = []", "+for i in range(it):", "+ line = eval(input())", "+ c, t = [int(n) for n in line.split()]", "+ pair = (c, t)", "+ cost_time.append(pair)", "+cost_time.sort(key=lambda x: x[1])", "+cost_time2 = []", "+for i in range(it):", "+ tupl = cost_time[i]", "+ if tupl[1] <= max_time:", "+ cost_time2.append(cost_time[i])", "+cost_time2.sort(key=lambda x: x[0])", "+if len(cost_time2) == 0:", "- print(menor_c)", "+ el = cost_time2[0]", "+ print((el[0]))" ]
false
0.044798
0.045687
0.980529
[ "s598687606", "s010226842" ]
u730769327
p03281
python
s994222868
s455453505
164
63
38,256
63,504
Accepted
Accepted
61.59
n=int(eval(input())) a=[3,5,7,9,11,13,17,19] count=0 for i in range(len(a)): for j in range(i+1,len(a)): for k in range(j+1,len(a)): if a[i]*a[j]*a[k]<=n: count+=1 print(count)
n=int(eval(input())) ans=0 for i in range(1,n+1): cnt=0 if i%2==0:continue for j in range(1,i+1): if i%j==0:cnt+=1 if cnt==8: ans+=1 print(ans)
11
10
202
162
n = int(eval(input())) a = [3, 5, 7, 9, 11, 13, 17, 19] count = 0 for i in range(len(a)): for j in range(i + 1, len(a)): for k in range(j + 1, len(a)): if a[i] * a[j] * a[k] <= n: count += 1 print(count)
n = int(eval(input())) ans = 0 for i in range(1, n + 1): cnt = 0 if i % 2 == 0: continue for j in range(1, i + 1): if i % j == 0: cnt += 1 if cnt == 8: ans += 1 print(ans)
false
9.090909
[ "-a = [3, 5, 7, 9, 11, 13, 17, 19]", "-count = 0", "-for i in range(len(a)):", "- for j in range(i + 1, len(a)):", "- for k in range(j + 1, len(a)):", "- if a[i] * a[j] * a[k] <= n:", "- count += 1", "-print(count)", "+ans = 0", "+for i in range(1, n + 1):", "+ cnt = 0", "+ if i % 2 == 0:", "+ continue", "+ for j in range(1, i + 1):", "+ if i % j == 0:", "+ cnt += 1", "+ if cnt == 8:", "+ ans += 1", "+print(ans)" ]
false
0.038771
0.063471
0.610844
[ "s994222868", "s455453505" ]
u644907318
p03733
python
s751367899
s331922142
268
107
85,328
103,836
Accepted
Accepted
60.07
N,T = list(map(int,input().split())) A = list(map(int,input().split())) cnt = 0 cur = 0 for i in range(1,N): b = A[i] a = A[i-1] if b-a<T: cur += b-a else: cnt += cur+T cur = 0 cnt += cur+T print(cnt)
N,T = list(map(int,input().split())) A = list(map(int,input().split())) cnt = 0 cur = 0 for i in range(1,N): if A[i]-A[i-1]>T: cnt += A[i-1]-cur+T cur = A[i] cnt += A[N-1]+T-cur print(cnt)
14
10
247
211
N, T = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 cur = 0 for i in range(1, N): b = A[i] a = A[i - 1] if b - a < T: cur += b - a else: cnt += cur + T cur = 0 cnt += cur + T print(cnt)
N, T = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 cur = 0 for i in range(1, N): if A[i] - A[i - 1] > T: cnt += A[i - 1] - cur + T cur = A[i] cnt += A[N - 1] + T - cur print(cnt)
false
28.571429
[ "- b = A[i]", "- a = A[i - 1]", "- if b - a < T:", "- cur += b - a", "- else:", "- cnt += cur + T", "- cur = 0", "-cnt += cur + T", "+ if A[i] - A[i - 1] > T:", "+ cnt += A[i - 1] - cur + T", "+ cur = A[i]", "+cnt += A[N - 1] + T - cur" ]
false
0.107952
0.038027
2.838814
[ "s751367899", "s331922142" ]
u367701763
p03014
python
s159844207
s123206640
1,499
642
227,636
254,444
Accepted
Accepted
57.17
def make_mat(grid, H, W): res = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if (grid[h]>>w)&1 == 1: for i in range(cnt): res[h][w - 1 - i] = cnt cnt = 0 else: cnt += 1 if (grid[h]>>w)&1 == 0: for i in range(cnt): res[h][w - i] = cnt return res def max2(x,y): return x if x > y else y import sys input = sys.stdin.readline H, W = list(map(int, input().split())) grid = [] grid_t = [0]*W for h in range(H): temp = 0 for w, s in enumerate(input().rstrip()): if s=="#": temp += 1<<w grid_t[w] += 1<<h grid.append(temp) A = make_mat(grid, H, W) B = make_mat(grid_t, W, H) res = 0 for h in range(H): for w in range(W): res = max2(A[h][w] + B[w][h], res) print((res-1))
def make_mat(grid, H, W): res = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if grid[h][w] == 1: for i in range(cnt): res[h][w - 1 - i] = cnt cnt = 0 else: cnt += 1 if grid[h][w] == 0: for i in range(cnt): res[h][w - i] = cnt return res def max2(x,y): return x if x > y else y import sys input = sys.stdin.readline H, W = list(map(int, input().split())) grid = [] grid_t = [[] for _ in range(W)] for h in range(H): temp = [] for w, s in enumerate(input().rstrip()): if s=="#": temp.append(1) grid_t[w].append(1) else: temp.append(0) grid_t[w].append(0) grid.append(temp) A = make_mat(grid, H, W) B = make_mat(grid_t, W, H) res = 0 for h in range(H): for w in range(W): res = max2(A[h][w] + B[w][h], res) print((res-1))
45
48
953
1,043
def make_mat(grid, H, W): res = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if (grid[h] >> w) & 1 == 1: for i in range(cnt): res[h][w - 1 - i] = cnt cnt = 0 else: cnt += 1 if (grid[h] >> w) & 1 == 0: for i in range(cnt): res[h][w - i] = cnt return res def max2(x, y): return x if x > y else y import sys input = sys.stdin.readline H, W = list(map(int, input().split())) grid = [] grid_t = [0] * W for h in range(H): temp = 0 for w, s in enumerate(input().rstrip()): if s == "#": temp += 1 << w grid_t[w] += 1 << h grid.append(temp) A = make_mat(grid, H, W) B = make_mat(grid_t, W, H) res = 0 for h in range(H): for w in range(W): res = max2(A[h][w] + B[w][h], res) print((res - 1))
def make_mat(grid, H, W): res = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if grid[h][w] == 1: for i in range(cnt): res[h][w - 1 - i] = cnt cnt = 0 else: cnt += 1 if grid[h][w] == 0: for i in range(cnt): res[h][w - i] = cnt return res def max2(x, y): return x if x > y else y import sys input = sys.stdin.readline H, W = list(map(int, input().split())) grid = [] grid_t = [[] for _ in range(W)] for h in range(H): temp = [] for w, s in enumerate(input().rstrip()): if s == "#": temp.append(1) grid_t[w].append(1) else: temp.append(0) grid_t[w].append(0) grid.append(temp) A = make_mat(grid, H, W) B = make_mat(grid_t, W, H) res = 0 for h in range(H): for w in range(W): res = max2(A[h][w] + B[w][h], res) print((res - 1))
false
6.25
[ "- if (grid[h] >> w) & 1 == 1:", "+ if grid[h][w] == 1:", "- if (grid[h] >> w) & 1 == 0:", "+ if grid[h][w] == 0:", "-grid_t = [0] * W", "+grid_t = [[] for _ in range(W)]", "- temp = 0", "+ temp = []", "- temp += 1 << w", "- grid_t[w] += 1 << h", "+ temp.append(1)", "+ grid_t[w].append(1)", "+ else:", "+ temp.append(0)", "+ grid_t[w].append(0)" ]
false
0.073511
0.037895
1.939867
[ "s159844207", "s123206640" ]
u853185302
p03274
python
s272336329
s509842005
239
96
23,108
14,252
Accepted
Accepted
59.83
import numpy as np N,K = list(map(int,input().split())) x = list(map(int,input().split())) min_t = None for i in range(N-K+1): t = min(abs(x[i])+abs(x[i]-x[i+K-1]), abs(x[i+K-1])+abs(x[i]-x[i+K-1])) if min_t == None: min_t = t if min_t > t: min_t = t print(min_t)
n,k = list(map(int,input().split())) x = list(map(int,input().split())) INF = float("inf") cost = INF for i in range(len(x)-k+1): l = x[i] r = x[i+k-1] tmp = min(abs(l)+abs(l-r),abs(r)+abs(r-l)) cost = min(cost,tmp) print(cost)
14
10
290
239
import numpy as np N, K = list(map(int, input().split())) x = list(map(int, input().split())) min_t = None for i in range(N - K + 1): t = min( abs(x[i]) + abs(x[i] - x[i + K - 1]), abs(x[i + K - 1]) + abs(x[i] - x[i + K - 1]), ) if min_t == None: min_t = t if min_t > t: min_t = t print(min_t)
n, k = list(map(int, input().split())) x = list(map(int, input().split())) INF = float("inf") cost = INF for i in range(len(x) - k + 1): l = x[i] r = x[i + k - 1] tmp = min(abs(l) + abs(l - r), abs(r) + abs(r - l)) cost = min(cost, tmp) print(cost)
false
28.571429
[ "-import numpy as np", "-", "-N, K = list(map(int, input().split()))", "+n, k = list(map(int, input().split()))", "-min_t = None", "-for i in range(N - K + 1):", "- t = min(", "- abs(x[i]) + abs(x[i] - x[i + K - 1]),", "- abs(x[i + K - 1]) + abs(x[i] - x[i + K - 1]),", "- )", "- if min_t == None:", "- min_t = t", "- if min_t > t:", "- min_t = t", "-print(min_t)", "+INF = float(\"inf\")", "+cost = INF", "+for i in range(len(x) - k + 1):", "+ l = x[i]", "+ r = x[i + k - 1]", "+ tmp = min(abs(l) + abs(l - r), abs(r) + abs(r - l))", "+ cost = min(cost, tmp)", "+print(cost)" ]
false
0.092835
0.044734
2.075266
[ "s272336329", "s509842005" ]
u046187684
p03457
python
s119524723
s657157865
216
151
28,224
29,596
Accepted
Accepted
30.09
def solve(string): n, *txy = list(map(int, string.split())) checks = [ abs(x) + abs(y) <= t and (t + x + y) % 2 == 0 for t, x, y in zip(txy[::3], txy[1::3], txy[2::3]) ] return "Yes" if all(checks) else "No" if __name__ == '__main__': n = int(eval(input())) print((solve('{}\n'.format(n) + '\n'.join([eval(input()) for _ in range(n)]))))
#!/usr/bin/env python3 # coding=utf-8 import sys n = int(sys.stdin.readline().strip()) txy = [(0,0,0)]+[tuple(map(int, l.strip().split(" "))) for l in sys.stdin.readlines()] check_txy = [abs(_x - _xp) + abs(_y - _yp) <= _t - _tp and (_t + _x + _y) % 2 == 0 for (_t, _x, _y), (_tp, _xp, _yp) in zip(txy[1:], txy)] if all(check_txy): print("Yes") else: print("No")
13
13
373
386
def solve(string): n, *txy = list(map(int, string.split())) checks = [ abs(x) + abs(y) <= t and (t + x + y) % 2 == 0 for t, x, y in zip(txy[::3], txy[1::3], txy[2::3]) ] return "Yes" if all(checks) else "No" if __name__ == "__main__": n = int(eval(input())) print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(n)]))))
#!/usr/bin/env python3 # coding=utf-8 import sys n = int(sys.stdin.readline().strip()) txy = [(0, 0, 0)] + [ tuple(map(int, l.strip().split(" "))) for l in sys.stdin.readlines() ] check_txy = [ abs(_x - _xp) + abs(_y - _yp) <= _t - _tp and (_t + _x + _y) % 2 == 0 for (_t, _x, _y), (_tp, _xp, _yp) in zip(txy[1:], txy) ] if all(check_txy): print("Yes") else: print("No")
false
0
[ "-def solve(string):", "- n, *txy = list(map(int, string.split()))", "- checks = [", "- abs(x) + abs(y) <= t and (t + x + y) % 2 == 0", "- for t, x, y in zip(txy[::3], txy[1::3], txy[2::3])", "- ]", "- return \"Yes\" if all(checks) else \"No\"", "+#!/usr/bin/env python3", "+# coding=utf-8", "+import sys", "-", "-if __name__ == \"__main__\":", "- n = int(eval(input()))", "- print((solve(\"{}\\n\".format(n) + \"\\n\".join([eval(input()) for _ in range(n)]))))", "+n = int(sys.stdin.readline().strip())", "+txy = [(0, 0, 0)] + [", "+ tuple(map(int, l.strip().split(\" \"))) for l in sys.stdin.readlines()", "+]", "+check_txy = [", "+ abs(_x - _xp) + abs(_y - _yp) <= _t - _tp and (_t + _x + _y) % 2 == 0", "+ for (_t, _x, _y), (_tp, _xp, _yp) in zip(txy[1:], txy)", "+]", "+if all(check_txy):", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.085421
0.044863
1.904035
[ "s119524723", "s657157865" ]
u644907318
p03712
python
s177666544
s478214273
168
64
38,384
62,088
Accepted
Accepted
61.9
H,W = list(map(int,input().split())) A = [input().strip() for _ in range(H)] A.insert(0,"#"*(W+2)) for i in range(1,H+1): A[i] = "#"+A[i]+"#" A.append("#"*(W+2)) for i in range(H+2): print((A[i]))
H,W = list(map(int,input().split())) x = ["#"*(W+2)] for _ in range(H): a = input().strip() a = "#"+a+"#" x.append(a) x.append("#"*(W+2)) for i in range(H+2): print((x[i]))
8
9
203
188
H, W = list(map(int, input().split())) A = [input().strip() for _ in range(H)] A.insert(0, "#" * (W + 2)) for i in range(1, H + 1): A[i] = "#" + A[i] + "#" A.append("#" * (W + 2)) for i in range(H + 2): print((A[i]))
H, W = list(map(int, input().split())) x = ["#" * (W + 2)] for _ in range(H): a = input().strip() a = "#" + a + "#" x.append(a) x.append("#" * (W + 2)) for i in range(H + 2): print((x[i]))
false
11.111111
[ "-A = [input().strip() for _ in range(H)]", "-A.insert(0, \"#\" * (W + 2))", "-for i in range(1, H + 1):", "- A[i] = \"#\" + A[i] + \"#\"", "-A.append(\"#\" * (W + 2))", "+x = [\"#\" * (W + 2)]", "+for _ in range(H):", "+ a = input().strip()", "+ a = \"#\" + a + \"#\"", "+ x.append(a)", "+x.append(\"#\" * (W + 2))", "- print((A[i]))", "+ print((x[i]))" ]
false
0.037994
0.037263
1.019626
[ "s177666544", "s478214273" ]
u367130284
p03721
python
s413728679
s572543154
673
464
57,560
29,912
Accepted
Accepted
31.05
n,k=list(map(int,input().split())) L=[] for s in range(n): a,b=list(map(int,input().split())) L.append((a,b)) #print(L) L=sorted(L,key=lambda x:x[0]) #print(L) sun=0 for s in L: sun+=s[1] if sun+1>k: print((s[0])) exit()
n,k=list(map(int,input().split())) for s,t in sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]): if k>t: k-=t else: print(s) exit()
14
8
235
195
n, k = list(map(int, input().split())) L = [] for s in range(n): a, b = list(map(int, input().split())) L.append((a, b)) # print(L) L = sorted(L, key=lambda x: x[0]) # print(L) sun = 0 for s in L: sun += s[1] if sun + 1 > k: print((s[0])) exit()
n, k = list(map(int, input().split())) for s, t in sorted( [list(map(int, input().split())) for i in range(n)], key=lambda x: x[0] ): if k > t: k -= t else: print(s) exit()
false
42.857143
[ "-L = []", "-for s in range(n):", "- a, b = list(map(int, input().split()))", "- L.append((a, b))", "-# print(L)", "-L = sorted(L, key=lambda x: x[0])", "-# print(L)", "-sun = 0", "-for s in L:", "- sun += s[1]", "- if sun + 1 > k:", "- print((s[0]))", "+for s, t in sorted(", "+ [list(map(int, input().split())) for i in range(n)], key=lambda x: x[0]", "+):", "+ if k > t:", "+ k -= t", "+ else:", "+ print(s)" ]
false
0.045294
0.045051
1.005393
[ "s413728679", "s572543154" ]
u021019433
p03032
python
s570342146
s041913919
27
24
3,060
3,060
Accepted
Accepted
11.11
R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) ans = max(sum(v[:i - j] + v[n - j:]) - sum([x for x, m in a if m < i - j or m >= n - j][:k - i]) for i in range(1, min(n, k) + 1) for j in range(i)) print(ans)
R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) ans = max(sum(v[:i - j] + v[n - j:]) - sum(sorted(x for x in v[:i - j] + v[n - j:] if x < 0)[: k - i]) for i in range(1, min(n, k) + 1) for j in range(i)) print(ans)
8
7
303
255
R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) ans = max( sum(v[: i - j] + v[n - j :]) - sum([x for x, m in a if m < i - j or m >= n - j][: k - i]) for i in range(1, min(n, k) + 1) for j in range(i) ) print(ans)
R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) ans = max( sum(v[: i - j] + v[n - j :]) - sum(sorted(x for x in v[: i - j] + v[n - j :] if x < 0)[: k - i]) for i in range(1, min(n, k) + 1) for j in range(i) ) print(ans)
false
12.5
[ "-a = sorted((x, i) for i, x in enumerate(v) if x < 0)", "- - sum([x for x, m in a if m < i - j or m >= n - j][: k - i])", "+ - sum(sorted(x for x in v[: i - j] + v[n - j :] if x < 0)[: k - i])" ]
false
0.057039
0.045102
1.264656
[ "s570342146", "s041913919" ]
u936985471
p03854
python
s383455888
s373872699
60
37
3,432
3,188
Accepted
Accepted
38.33
S=eval(input()) W=("dream","dreamer","erase","eraser") s=[0] while s: i=s.pop() if i==len(S): print("YES") break for w in W: if S[i:i+len(w)]==w: s.append(i+len(w)) else: print("NO")
S=input()[::-1] W=("dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]) ind=0 while ind<len(S): for w in W: if S[ind:ind+len(w)]==w: ind+=len(w) break else: print("NO") break else: print("YES")
13
13
214
242
S = eval(input()) W = ("dream", "dreamer", "erase", "eraser") s = [0] while s: i = s.pop() if i == len(S): print("YES") break for w in W: if S[i : i + len(w)] == w: s.append(i + len(w)) else: print("NO")
S = input()[::-1] W = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]) ind = 0 while ind < len(S): for w in W: if S[ind : ind + len(w)] == w: ind += len(w) break else: print("NO") break else: print("YES")
false
0
[ "-S = eval(input())", "-W = (\"dream\", \"dreamer\", \"erase\", \"eraser\")", "-s = [0]", "-while s:", "- i = s.pop()", "- if i == len(S):", "- print(\"YES\")", "+S = input()[::-1]", "+W = (\"dream\"[::-1], \"dreamer\"[::-1], \"erase\"[::-1], \"eraser\"[::-1])", "+ind = 0", "+while ind < len(S):", "+ for w in W:", "+ if S[ind : ind + len(w)] == w:", "+ ind += len(w)", "+ break", "+ else:", "+ print(\"NO\")", "- for w in W:", "- if S[i : i + len(w)] == w:", "- s.append(i + len(w))", "- print(\"NO\")", "+ print(\"YES\")" ]
false
0.056912
0.05605
1.015384
[ "s383455888", "s373872699" ]
u297574184
p02987
python
s116770422
s841410776
61
17
3,444
2,940
Accepted
Accepted
72.13
from collections import Counter Ss = eval(input()) num = len(set(Ss)) cnt = Counter(Ss) if num == 2 and min(cnt.values()) == 2: print('Yes') else: print('No')
Ss = list(input().rstrip()) Ss.sort() if Ss[0]==Ss[1] and Ss[1]!=Ss[2] and Ss[2]==Ss[3]: print('Yes') else: print('No')
11
8
174
137
from collections import Counter Ss = eval(input()) num = len(set(Ss)) cnt = Counter(Ss) if num == 2 and min(cnt.values()) == 2: print("Yes") else: print("No")
Ss = list(input().rstrip()) Ss.sort() if Ss[0] == Ss[1] and Ss[1] != Ss[2] and Ss[2] == Ss[3]: print("Yes") else: print("No")
false
27.272727
[ "-from collections import Counter", "-", "-Ss = eval(input())", "-num = len(set(Ss))", "-cnt = Counter(Ss)", "-if num == 2 and min(cnt.values()) == 2:", "+Ss = list(input().rstrip())", "+Ss.sort()", "+if Ss[0] == Ss[1] and Ss[1] != Ss[2] and Ss[2] == Ss[3]:" ]
false
0.007116
0.040227
0.176888
[ "s116770422", "s841410776" ]
u729133443
p03416
python
s863598517
s998837613
187
51
40,428
2,940
Accepted
Accepted
72.73
a,b=list(map(int,input().split()));c=0 while a<=b:s=str(a);c+=s==s[::-1];a+=1 print(c)
a,b=list(map(int,input().split()));print((sum(s==s[::-1]for s in map(str,list(range(a,b+1))))))
3
1
82
81
a, b = list(map(int, input().split())) c = 0 while a <= b: s = str(a) c += s == s[::-1] a += 1 print(c)
a, b = list(map(int, input().split())) print((sum(s == s[::-1] for s in map(str, list(range(a, b + 1))))))
false
66.666667
[ "-c = 0", "-while a <= b:", "- s = str(a)", "- c += s == s[::-1]", "- a += 1", "-print(c)", "+print((sum(s == s[::-1] for s in map(str, list(range(a, b + 1))))))" ]
false
0.04933
0.073251
0.673444
[ "s863598517", "s998837613" ]
u380524497
p03148
python
s295346426
s242091551
666
440
33,804
33,804
Accepted
Accepted
33.93
from collections import defaultdict import heapq n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi.pop() kinds[neta] += 1 ans += point heapq.heappush(eaten, [point, neta]) num_of_kinds = len(list(kinds.keys())) ans += num_of_kinds ** 2 candidate = ans for i in range(k): point, neta = heapq.heappop(eaten) if kinds[neta] == 1: continue kinds[neta] -= 1 while sushi: new_neta, new_point = sushi.pop() if kinds[new_neta] >= 1: continue else: break else: break kinds[new_neta] += 1 num_of_kinds += 1 delta = new_point - point + (2*num_of_kinds - 1) candidate += delta ans = max(ans, candidate) print(ans)
from collections import defaultdict import heapq import sys input = sys.stdin.readline n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi.pop() kinds[neta] += 1 ans += point heapq.heappush(eaten, [point, neta]) num_of_kinds = len(list(kinds.keys())) ans += num_of_kinds ** 2 candidate = ans for i in range(k): point, neta = heapq.heappop(eaten) if kinds[neta] == 1: continue kinds[neta] -= 1 while sushi: new_neta, new_point = sushi.pop() if kinds[new_neta] >= 1: continue else: break else: break kinds[new_neta] += 1 num_of_kinds += 1 delta = new_point - point + (2*num_of_kinds - 1) candidate += delta ans = max(ans, candidate) print(ans)
42
44
920
960
from collections import defaultdict import heapq n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi.pop() kinds[neta] += 1 ans += point heapq.heappush(eaten, [point, neta]) num_of_kinds = len(list(kinds.keys())) ans += num_of_kinds**2 candidate = ans for i in range(k): point, neta = heapq.heappop(eaten) if kinds[neta] == 1: continue kinds[neta] -= 1 while sushi: new_neta, new_point = sushi.pop() if kinds[new_neta] >= 1: continue else: break else: break kinds[new_neta] += 1 num_of_kinds += 1 delta = new_point - point + (2 * num_of_kinds - 1) candidate += delta ans = max(ans, candidate) print(ans)
from collections import defaultdict import heapq import sys input = sys.stdin.readline n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi.pop() kinds[neta] += 1 ans += point heapq.heappush(eaten, [point, neta]) num_of_kinds = len(list(kinds.keys())) ans += num_of_kinds**2 candidate = ans for i in range(k): point, neta = heapq.heappop(eaten) if kinds[neta] == 1: continue kinds[neta] -= 1 while sushi: new_neta, new_point = sushi.pop() if kinds[new_neta] >= 1: continue else: break else: break kinds[new_neta] += 1 num_of_kinds += 1 delta = new_point - point + (2 * num_of_kinds - 1) candidate += delta ans = max(ans, candidate) print(ans)
false
4.545455
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.038404
0.038582
0.995365
[ "s295346426", "s242091551" ]
u909643606
p03339
python
s825742800
s334745293
276
214
3,828
65,252
Accepted
Accepted
22.46
n=int(eval(input())) s=eval(input()) ss=s[::-1] ans=10**7 front_bucket=[0,0] back_bucket=[0,0] for i in range(n): if s[i]=="E": front_bucket[0]+=1 else: front_bucket[1]+=1 for i in range(n): if ss[i]=="E": front_bucket[0]-=1 ans=min(ans, front_bucket[1]+back_bucket[0]) back_bucket[0]+=1 else: front_bucket[1]-=1 ans=min(ans, front_bucket[1]+back_bucket[0]) back_bucket[1]+=1 print(ans)
n=int(eval(input())) s=eval(input()) E = [0 for i in range(n)] W = [0 for i in range(n)] for i in range(n): if s[i] == "E": E[i] = 1 else: W[i] = 1 for i in range(n-1): W[i+1] += W[i] E[-i-2] += E[-i-1] ans = float("inf") for i in range(n): if i == 0: ans = min(ans, E[i+1]) elif i == n-1: ans = min(ans, W[i-1]) else: ans = min(ans, E[i+1]+W[i-1]) print(ans) #print(E) #print(W)
25
28
446
467
n = int(eval(input())) s = eval(input()) ss = s[::-1] ans = 10**7 front_bucket = [0, 0] back_bucket = [0, 0] for i in range(n): if s[i] == "E": front_bucket[0] += 1 else: front_bucket[1] += 1 for i in range(n): if ss[i] == "E": front_bucket[0] -= 1 ans = min(ans, front_bucket[1] + back_bucket[0]) back_bucket[0] += 1 else: front_bucket[1] -= 1 ans = min(ans, front_bucket[1] + back_bucket[0]) back_bucket[1] += 1 print(ans)
n = int(eval(input())) s = eval(input()) E = [0 for i in range(n)] W = [0 for i in range(n)] for i in range(n): if s[i] == "E": E[i] = 1 else: W[i] = 1 for i in range(n - 1): W[i + 1] += W[i] E[-i - 2] += E[-i - 1] ans = float("inf") for i in range(n): if i == 0: ans = min(ans, E[i + 1]) elif i == n - 1: ans = min(ans, W[i - 1]) else: ans = min(ans, E[i + 1] + W[i - 1]) print(ans) # print(E) # print(W)
false
10.714286
[ "-ss = s[::-1]", "-ans = 10**7", "-front_bucket = [0, 0]", "-back_bucket = [0, 0]", "+E = [0 for i in range(n)]", "+W = [0 for i in range(n)]", "- front_bucket[0] += 1", "+ E[i] = 1", "- front_bucket[1] += 1", "+ W[i] = 1", "+for i in range(n - 1):", "+ W[i + 1] += W[i]", "+ E[-i - 2] += E[-i - 1]", "+ans = float(\"inf\")", "- if ss[i] == \"E\":", "- front_bucket[0] -= 1", "- ans = min(ans, front_bucket[1] + back_bucket[0])", "- back_bucket[0] += 1", "+ if i == 0:", "+ ans = min(ans, E[i + 1])", "+ elif i == n - 1:", "+ ans = min(ans, W[i - 1])", "- front_bucket[1] -= 1", "- ans = min(ans, front_bucket[1] + back_bucket[0])", "- back_bucket[1] += 1", "+ ans = min(ans, E[i + 1] + W[i - 1])", "+# print(E)", "+# print(W)" ]
false
0.039501
0.040219
0.982138
[ "s825742800", "s334745293" ]
u287500079
p02683
python
s059774434
s267925804
111
94
70,252
70,284
Accepted
Accepted
15.32
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd from itertools import permutations, combinations, product, accumulate, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits #from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 dx = [0, 1, 0, -1, 1, -1, -1, 1] dy = [1, 0, -1, 0, 1, -1, 1, -1] debugmode = True n, m, x = MAP() arr = [LIST() for _ in range(n)] c = [arr[i][0] for i in range(n)] a = [arr[i][1:] for i in range(n)] ans = inf for i in range(1, n + 1): cmb = list(combinations(list(range(n)), i)) for lst in cmb: tmp = [0 for _ in range(m)] cst = 0 for idx in lst: cst += c[idx] for j in range(m): tmp[j] += a[idx][j] flag = True for j in range(m): if tmp[j] < x: flag = False if flag: ans = min(ans, cst) if ans == inf: print((-1)) else: print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd from itertools import permutations, combinations, product, accumulate, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits #from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 dx = [0, 1, 0, -1, 1, -1, -1, 1] dy = [1, 0, -1, 0, 1, -1, 1, -1] debugmode = True n, m, x = MAP() arr = [LIST() for _ in range(n)] c = [arr[i][0] for i in range(n)] a = [arr[i][1:] for i in range(n)] ans = inf for i in range(2 ** n): tmp = [0 for _ in range(m)] cst = 0 for j in range(n): if i - (i >> (j + 1)) * (2 ** (j + 1)) >= 2 ** j: for k in range(m): tmp[k] += a[j][k] cst += c[j] flag = True for j in range(m): if tmp[j] < x: flag = False if flag: ans = min(ans, cst) if ans == inf: print((-1)) else: print(ans)
52
51
1,648
1,604
import sys, re, os from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd, ) from itertools import ( permutations, combinations, product, accumulate, combinations_with_replacement, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits # from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**9) inf = sys.maxsize mod = 10**9 + 7 dx = [0, 1, 0, -1, 1, -1, -1, 1] dy = [1, 0, -1, 0, 1, -1, 1, -1] debugmode = True n, m, x = MAP() arr = [LIST() for _ in range(n)] c = [arr[i][0] for i in range(n)] a = [arr[i][1:] for i in range(n)] ans = inf for i in range(1, n + 1): cmb = list(combinations(list(range(n)), i)) for lst in cmb: tmp = [0 for _ in range(m)] cst = 0 for idx in lst: cst += c[idx] for j in range(m): tmp[j] += a[idx][j] flag = True for j in range(m): if tmp[j] < x: flag = False if flag: ans = min(ans, cst) if ans == inf: print((-1)) else: print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd, ) from itertools import ( permutations, combinations, product, accumulate, combinations_with_replacement, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits # from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**9) inf = sys.maxsize mod = 10**9 + 7 dx = [0, 1, 0, -1, 1, -1, -1, 1] dy = [1, 0, -1, 0, 1, -1, 1, -1] debugmode = True n, m, x = MAP() arr = [LIST() for _ in range(n)] c = [arr[i][0] for i in range(n)] a = [arr[i][1:] for i in range(n)] ans = inf for i in range(2**n): tmp = [0 for _ in range(m)] cst = 0 for j in range(n): if i - (i >> (j + 1)) * (2 ** (j + 1)) >= 2**j: for k in range(m): tmp[k] += a[j][k] cst += c[j] flag = True for j in range(m): if tmp[j] < x: flag = False if flag: ans = min(ans, cst) if ans == inf: print((-1)) else: print(ans)
false
1.923077
[ "-for i in range(1, n + 1):", "- cmb = list(combinations(list(range(n)), i))", "- for lst in cmb:", "- tmp = [0 for _ in range(m)]", "- cst = 0", "- for idx in lst:", "- cst += c[idx]", "- for j in range(m):", "- tmp[j] += a[idx][j]", "- flag = True", "- for j in range(m):", "- if tmp[j] < x:", "- flag = False", "- if flag:", "- ans = min(ans, cst)", "+for i in range(2**n):", "+ tmp = [0 for _ in range(m)]", "+ cst = 0", "+ for j in range(n):", "+ if i - (i >> (j + 1)) * (2 ** (j + 1)) >= 2**j:", "+ for k in range(m):", "+ tmp[k] += a[j][k]", "+ cst += c[j]", "+ flag = True", "+ for j in range(m):", "+ if tmp[j] < x:", "+ flag = False", "+ if flag:", "+ ans = min(ans, cst)" ]
false
0.120167
0.049403
2.43236
[ "s059774434", "s267925804" ]
u493520238
p03486
python
s393445489
s841755161
71
63
61,968
61,860
Accepted
Accepted
11.27
s =eval(input()) t = eval(input()) s = sorted(s, key=str.lower) t = sorted(t, key=str.lower, reverse=True) s = ''.join(s) t = ''.join(t) l = [s,t] l.sort() if l[0] == s and s != t: print('Yes') else: print('No')
s=eval(input()) t=eval(input()) s = sorted(s) t = sorted(t, reverse=True) if s < t: print('Yes') else: print('No')
12
8
218
117
s = eval(input()) t = eval(input()) s = sorted(s, key=str.lower) t = sorted(t, key=str.lower, reverse=True) s = "".join(s) t = "".join(t) l = [s, t] l.sort() if l[0] == s and s != t: print("Yes") else: print("No")
s = eval(input()) t = eval(input()) s = sorted(s) t = sorted(t, reverse=True) if s < t: print("Yes") else: print("No")
false
33.333333
[ "-s = sorted(s, key=str.lower)", "-t = sorted(t, key=str.lower, reverse=True)", "-s = \"\".join(s)", "-t = \"\".join(t)", "-l = [s, t]", "-l.sort()", "-if l[0] == s and s != t:", "+s = sorted(s)", "+t = sorted(t, reverse=True)", "+if s < t:" ]
false
0.043546
0.042855
1.016122
[ "s393445489", "s841755161" ]
u263830634
p03329
python
s440754070
s428285053
670
580
3,828
3,828
Accepted
Accepted
13.43
#DP 動的計画法 N = int(eval(input())) INF = 10 ** 9 dp = [INF] * (N+1) #初期化配列 dp[0] = 0 for n in range(1, N+1): power = 1 while power <= N: dp[n] = min(dp[n], dp[n-power]+1) power *= 6 power = 1 while power <= N: dp[n] = min(dp[n], dp[n-power]+1) power *= 9 #print (dp) print((dp[N]))
N = int(eval(input())) INF = 10 ** 9 dp = [INF] * (N + 1) dp[0] = 0 for i in range(1, N + 1): dp[i] = dp[i - 1] + 1 tmp = 6 while i - tmp >= 0: dp[i] = min(dp[i], dp[i - tmp] + 1) tmp *= 6 tmp = 9 while i - tmp >= 0: dp[i] = min(dp[i], dp[i - tmp] + 1) tmp *= 9 # print (dp) print((dp[N]))
20
22
343
369
# DP 動的計画法 N = int(eval(input())) INF = 10**9 dp = [INF] * (N + 1) # 初期化配列 dp[0] = 0 for n in range(1, N + 1): power = 1 while power <= N: dp[n] = min(dp[n], dp[n - power] + 1) power *= 6 power = 1 while power <= N: dp[n] = min(dp[n], dp[n - power] + 1) power *= 9 # print (dp) print((dp[N]))
N = int(eval(input())) INF = 10**9 dp = [INF] * (N + 1) dp[0] = 0 for i in range(1, N + 1): dp[i] = dp[i - 1] + 1 tmp = 6 while i - tmp >= 0: dp[i] = min(dp[i], dp[i - tmp] + 1) tmp *= 6 tmp = 9 while i - tmp >= 0: dp[i] = min(dp[i], dp[i - tmp] + 1) tmp *= 9 # print (dp) print((dp[N]))
false
9.090909
[ "-# DP 動的計画法", "-dp = [INF] * (N + 1) # 初期化配列", "+dp = [INF] * (N + 1)", "-for n in range(1, N + 1):", "- power = 1", "- while power <= N:", "- dp[n] = min(dp[n], dp[n - power] + 1)", "- power *= 6", "- power = 1", "- while power <= N:", "- dp[n] = min(dp[n], dp[n - power] + 1)", "- power *= 9", "+for i in range(1, N + 1):", "+ dp[i] = dp[i - 1] + 1", "+ tmp = 6", "+ while i - tmp >= 0:", "+ dp[i] = min(dp[i], dp[i - tmp] + 1)", "+ tmp *= 6", "+ tmp = 9", "+ while i - tmp >= 0:", "+ dp[i] = min(dp[i], dp[i - tmp] + 1)", "+ tmp *= 9" ]
false
0.109041
0.096724
1.127344
[ "s440754070", "s428285053" ]
u930705402
p02599
python
s366308648
s915715107
1,724
799
231,808
184,796
Accepted
Accepted
53.65
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=self.bit[x] x=(x&(x+1))-1 return ret def cum(self,l,r): return self.get(r)-self.get(l) def update(x,i): if good[x]==-1: good[x]=i bit.add(i,1) else: bit.add(good[x],-1) good[x]=i bit.add(good[x],1) return N,Q=map(int,read().split()) c=tuple(map(int,read().split())) Query=[] for i in range(Q): l,r=map(lambda x:int(x)-1,read().split()) Query.append((l,r,i)) Query.sort(key=lambda x:x[1]) ans=[-1]*Q good=[-1]*(N+1) bit=BIT(N) i=0 for L,R,w in Query: while(i<=R): update(c[i],i) i+=1 ans[w]=bit.cum(L,R+1) print(*ans,sep='\n')
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=self.bit[x] x=(x&(x+1))-1 return ret def cum(self,l,r): return self.get(r)-self.get(l) def update(x,i): if good[x]==-1: good[x]=i bit.add(i,1) else: bit.add(good[x],-1) good[x]=i bit.add(good[x],1) return N,Q=map(int,read().split()) c=tuple(map(int,read().split())) Query=[] for i in range(Q): l,r=map(lambda x:int(x)-1,read().split()) Query.append(r*10**12+l*10**6+i) Query.sort() ans=[-1]*Q good=[-1]*(N+1) bit=BIT(N) i=0 for w in Query: R=w//10**12 w%=10**12 L=w//10**6 w%=10**6 while(i<=R): update(c[i],i) i+=1 ans[w]=bit.cum(L,R+1) print(*ans,sep='\n')
50
54
1,003
1,055
import sys read = sys.stdin.buffer.readline class BIT: def __init__(self, N): self.N = N self.bit = [0] * N def add(self, a, w): x = a while x < self.N: self.bit[x] += w x |= x + 1 def get(self, a): ret, x = 0, a - 1 while x >= 0: ret += self.bit[x] x = (x & (x + 1)) - 1 return ret def cum(self, l, r): return self.get(r) - self.get(l) def update(x, i): if good[x] == -1: good[x] = i bit.add(i, 1) else: bit.add(good[x], -1) good[x] = i bit.add(good[x], 1) return N, Q = map(int, read().split()) c = tuple(map(int, read().split())) Query = [] for i in range(Q): l, r = map(lambda x: int(x) - 1, read().split()) Query.append((l, r, i)) Query.sort(key=lambda x: x[1]) ans = [-1] * Q good = [-1] * (N + 1) bit = BIT(N) i = 0 for L, R, w in Query: while i <= R: update(c[i], i) i += 1 ans[w] = bit.cum(L, R + 1) print(*ans, sep="\n")
import sys read = sys.stdin.buffer.readline class BIT: def __init__(self, N): self.N = N self.bit = [0] * N def add(self, a, w): x = a while x < self.N: self.bit[x] += w x |= x + 1 def get(self, a): ret, x = 0, a - 1 while x >= 0: ret += self.bit[x] x = (x & (x + 1)) - 1 return ret def cum(self, l, r): return self.get(r) - self.get(l) def update(x, i): if good[x] == -1: good[x] = i bit.add(i, 1) else: bit.add(good[x], -1) good[x] = i bit.add(good[x], 1) return N, Q = map(int, read().split()) c = tuple(map(int, read().split())) Query = [] for i in range(Q): l, r = map(lambda x: int(x) - 1, read().split()) Query.append(r * 10**12 + l * 10**6 + i) Query.sort() ans = [-1] * Q good = [-1] * (N + 1) bit = BIT(N) i = 0 for w in Query: R = w // 10**12 w %= 10**12 L = w // 10**6 w %= 10**6 while i <= R: update(c[i], i) i += 1 ans[w] = bit.cum(L, R + 1) print(*ans, sep="\n")
false
7.407407
[ "- Query.append((l, r, i))", "-Query.sort(key=lambda x: x[1])", "+ Query.append(r * 10**12 + l * 10**6 + i)", "+Query.sort()", "-for L, R, w in Query:", "+for w in Query:", "+ R = w // 10**12", "+ w %= 10**12", "+ L = w // 10**6", "+ w %= 10**6" ]
false
0.043505
0.037544
1.158779
[ "s366308648", "s915715107" ]
u281303342
p03829
python
s826471081
s032049000
105
86
14,172
14,172
Accepted
Accepted
18.1
# python3 (3.4.3) import sys input = sys.stdin.readline # main N,A,B = list(map(int,input().split())) X = list(map(int,input().split())) ans = 0 for i in range(N-1): ans += min(B, A*(X[i+1]-X[i])) print(ans)
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- N,A,B = list(map(int,input().split())) X = list(map(int,input().split())) ans = 0 for i in range(N-1): d = X[i+1] - X[i] if d*A > B: ans += B else: ans += d*A print(ans)
13
24
220
549
# python3 (3.4.3) import sys input = sys.stdin.readline # main N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 for i in range(N - 1): ans += min(B, A * (X[i + 1] - X[i])) print(ans)
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 for i in range(N - 1): d = X[i + 1] - X[i] if d * A > B: ans += B else: ans += d * A print(ans)
false
45.833333
[ "-# python3 (3.4.3)", "+# Python3 (3.4.3)", "+# function", "- ans += min(B, A * (X[i + 1] - X[i]))", "+ d = X[i + 1] - X[i]", "+ if d * A > B:", "+ ans += B", "+ else:", "+ ans += d * A" ]
false
0.048411
0.04952
0.977592
[ "s826471081", "s032049000" ]
u592547545
p02761
python
s760128511
s530605723
29
26
9,244
9,300
Accepted
Accepted
10.34
def readinput(): n,m=list(map(int,input().split())) sc=[] for _ in range(m): s,c=list(map(int,input().split())) sc.append((s,c)) return n,m,sc def main(n,m,sc): ans=[-1]*n for s,c in sc: if ans[s-1]==-1: ans[s-1]=c else: if ans[s-1]!=c: return -1 if ans[0]==0: if n==1: return 0 else: return -1 elif ans[0]==-1: if n==1: ans[0]=0 else: ans[0]=1 for i in range(1,n): if ans[i]==-1: ans[i]=0 sum=0 for i in range(n): sum*=10 sum+=ans[i] return sum if __name__=='__main__': n,m,sc=readinput() ans=main(n,m,sc) print(ans)
def readinput(): n,m=list(map(int,input().split())) sc=[] for _ in range(m): s,c=list(map(int,input().split())) sc.append((s,c)) return n,m,sc def main(n,m,sc): ans=[-1]*n for s,c in sc: if ans[s-1]==-1: ans[s-1]=c else: if ans[s-1]!=c: return -1 if ans[0]==0: if n==1: return 0 else: return -1 elif ans[0]==-1: if n==1: ans[0]=0 else: ans[0]=1 for i in range(1,n): if ans[i]==-1: ans[i]=0 sum=0 for i in range(n): sum*=10 sum+=ans[i] return sum def main2(n,m,sc): cands=[x for x in range(10**n)] for cand in cands: cc=str(cand) if (len(cc)!=n): continue i=0 #print(cc) while(i<m): #print(sc[i]) s,c=sc[i] if cc[s-1]!=str(c): break i+=1 else: return cand return -1 if __name__=='__main__': n,m,sc=readinput() ans=main2(n,m,sc) print(ans)
39
58
794
1,191
def readinput(): n, m = list(map(int, input().split())) sc = [] for _ in range(m): s, c = list(map(int, input().split())) sc.append((s, c)) return n, m, sc def main(n, m, sc): ans = [-1] * n for s, c in sc: if ans[s - 1] == -1: ans[s - 1] = c else: if ans[s - 1] != c: return -1 if ans[0] == 0: if n == 1: return 0 else: return -1 elif ans[0] == -1: if n == 1: ans[0] = 0 else: ans[0] = 1 for i in range(1, n): if ans[i] == -1: ans[i] = 0 sum = 0 for i in range(n): sum *= 10 sum += ans[i] return sum if __name__ == "__main__": n, m, sc = readinput() ans = main(n, m, sc) print(ans)
def readinput(): n, m = list(map(int, input().split())) sc = [] for _ in range(m): s, c = list(map(int, input().split())) sc.append((s, c)) return n, m, sc def main(n, m, sc): ans = [-1] * n for s, c in sc: if ans[s - 1] == -1: ans[s - 1] = c else: if ans[s - 1] != c: return -1 if ans[0] == 0: if n == 1: return 0 else: return -1 elif ans[0] == -1: if n == 1: ans[0] = 0 else: ans[0] = 1 for i in range(1, n): if ans[i] == -1: ans[i] = 0 sum = 0 for i in range(n): sum *= 10 sum += ans[i] return sum def main2(n, m, sc): cands = [x for x in range(10**n)] for cand in cands: cc = str(cand) if len(cc) != n: continue i = 0 # print(cc) while i < m: # print(sc[i]) s, c = sc[i] if cc[s - 1] != str(c): break i += 1 else: return cand return -1 if __name__ == "__main__": n, m, sc = readinput() ans = main2(n, m, sc) print(ans)
false
32.758621
[ "+def main2(n, m, sc):", "+ cands = [x for x in range(10**n)]", "+ for cand in cands:", "+ cc = str(cand)", "+ if len(cc) != n:", "+ continue", "+ i = 0", "+ # print(cc)", "+ while i < m:", "+ # print(sc[i])", "+ s, c = sc[i]", "+ if cc[s - 1] != str(c):", "+ break", "+ i += 1", "+ else:", "+ return cand", "+ return -1", "+", "+", "- ans = main(n, m, sc)", "+ ans = main2(n, m, sc)" ]
false
0.039177
0.039436
0.993444
[ "s760128511", "s530605723" ]
u934442292
p02936
python
s254935316
s443211760
1,406
887
232,212
54,516
Accepted
Accepted
36.91
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def dfs(G, v, p, point): """G: graph, v: vertex, p: parent""" # Loop for each child for c in G[v]: if c == p: continue point[c] += point[v] dfs(G, c, v, point) def main(): N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) point = [0] * N for i in range(Q): p, x = list(map(int, input().split())) p -= 1 point[p] += x dfs(G, 0, -1, point) print((" ".join(map(str, point)))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # NOQA sys.setrecursionlimit(10 ** 7) # NOQA from collections import deque def dfs(G, v, p, counter): """G: graph, v: vertex, p: parent""" parent = [-1] * len(G) stack = deque([v]) while stack: v = stack.pop() for c in G[v]: if c == parent[v]: continue parent[c] = v stack.append(c) counter[c] += counter[v] def main(): N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) counter = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 counter[p] += x dfs(G, 0, -1, counter) print((*counter)) if __name__ == "__main__": main()
38
43
768
929
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def dfs(G, v, p, point): """G: graph, v: vertex, p: parent""" # Loop for each child for c in G[v]: if c == p: continue point[c] += point[v] dfs(G, c, v, point) def main(): N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) point = [0] * N for i in range(Q): p, x = list(map(int, input().split())) p -= 1 point[p] += x dfs(G, 0, -1, point) print((" ".join(map(str, point)))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # NOQA sys.setrecursionlimit(10**7) # NOQA from collections import deque def dfs(G, v, p, counter): """G: graph, v: vertex, p: parent""" parent = [-1] * len(G) stack = deque([v]) while stack: v = stack.pop() for c in G[v]: if c == parent[v]: continue parent[c] = v stack.append(c) counter[c] += counter[v] def main(): N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) counter = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 counter[p] += x dfs(G, 0, -1, counter) print((*counter)) if __name__ == "__main__": main()
false
11.627907
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline # NOQA", "+sys.setrecursionlimit(10**7) # NOQA", "+from collections import deque", "-def dfs(G, v, p, point):", "+def dfs(G, v, p, counter):", "- # Loop for each child", "- for c in G[v]:", "- if c == p:", "- continue", "- point[c] += point[v]", "- dfs(G, c, v, point)", "+ parent = [-1] * len(G)", "+ stack = deque([v])", "+ while stack:", "+ v = stack.pop()", "+ for c in G[v]:", "+ if c == parent[v]:", "+ continue", "+ parent[c] = v", "+ stack.append(c)", "+ counter[c] += counter[v]", "- point = [0] * N", "- for i in range(Q):", "+ counter = [0] * N", "+ for _ in range(Q):", "- point[p] += x", "- dfs(G, 0, -1, point)", "- print((\" \".join(map(str, point))))", "+ counter[p] += x", "+ dfs(G, 0, -1, counter)", "+ print((*counter))" ]
false
0.035203
0.036988
0.951738
[ "s254935316", "s443211760" ]
u811967730
p02971
python
s995282187
s397179466
392
339
14,204
14,092
Accepted
Accepted
13.52
import sys input = sys.stdin.readline n = int(eval(input())) nums = [None] * n for i in range(n): nums[i] = int(eval(input())) sorted_nums = sorted(nums) for i in range(n): max_val = sorted_nums[n - 1] if nums[i] == max_val: max_val = sorted_nums[n - 2] print(max_val)
import sys input = sys.stdin.readline n = int(eval(input())) nums = [None] * n for i in range(n): nums[i] = int(eval(input())) sorted_nums = sorted(nums) for num in nums: max_val = sorted_nums[n - 1] if num == max_val: max_val = sorted_nums[n - 2] print(max_val)
15
15
298
292
import sys input = sys.stdin.readline n = int(eval(input())) nums = [None] * n for i in range(n): nums[i] = int(eval(input())) sorted_nums = sorted(nums) for i in range(n): max_val = sorted_nums[n - 1] if nums[i] == max_val: max_val = sorted_nums[n - 2] print(max_val)
import sys input = sys.stdin.readline n = int(eval(input())) nums = [None] * n for i in range(n): nums[i] = int(eval(input())) sorted_nums = sorted(nums) for num in nums: max_val = sorted_nums[n - 1] if num == max_val: max_val = sorted_nums[n - 2] print(max_val)
false
0
[ "-for i in range(n):", "+for num in nums:", "- if nums[i] == max_val:", "+ if num == max_val:" ]
false
0.035635
0.04358
0.8177
[ "s995282187", "s397179466" ]
u729133443
p02904
python
s330084945
s561210699
1,805
736
28,896
120,892
Accepted
Accepted
59.22
class SWAG(): def __init__(self,unit,f): self.fold_r=[unit] self.fold_l=[unit] self.data_r=[] self.data_l=[] self.f=f def __refill_right(self): temp=[] n=len(self.data_l) for _ in range(n//2): temp.append(self.popleft()) for _ in range(n//2,n): self.append(self.popleft()) for _ in range(n//2): self.appendleft(temp.pop()) def __refill_left(self): temp=[] n=len(self.data_r) for _ in range(n//2): temp.append(self.pop()) for _ in range(n//2,n): self.appendleft(self.pop()) for _ in range(n//2): self.append(temp.pop()) def append(self,x): self.fold_r.append(self.f(self.fold_r[-1],x)) self.data_r.append(x) def appendleft(self,x): self.fold_l.append(self.f(self.fold_l[-1],x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1],self.fold_l[-1]) n,k,*p=list(map(int,open(0).read().split())) c=[0] for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] x=not f s_min=SWAG(10**18,min) s_max=SWAG(0,max) *_,=list(map(s_min.append,p[:k-1])) *_,=list(map(s_max.append,p[1:k])) for i,(a,b,c)in enumerate(zip(p,p[k:],c)): f|=c s_min.append(p[i+k-1]) s_max.append(b) if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1 s_min.popleft() s_max.popleft() print((x+f))
class SWAG(): def __init__(self,unit,f): self.fold_r=[unit] self.fold_l=[unit] self.data_r=[] self.data_l=[] self.f=f def __refill_right(self): temp=[] n=len(self.data_l) *_,=list(map(temp.append,(self.popleft()for _ in range(n//2)))) *_,=list(map(self.append,(self.popleft()for _ in range(n//2,n)))) *_,=list(map(self.appendleft,temp[::-1])) def __refill_left(self): temp=[] n=len(self.data_r) *_,=list(map(temp.append,(self.pop()for _ in range(n//2)))) *_,=list(map(self.appendleft,(self.pop()for _ in range(n//2,n)))) *_,=list(map(self.append,temp[::-1])) def append(self,x): self.fold_r.append(self.f(self.fold_r[-1],x)) self.data_r.append(x) def appendleft(self,x): self.fold_l.append(self.f(self.fold_l[-1],x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1],self.fold_l[-1]) n,k,*p=list(map(int,open(0).read().split())) c=[0] for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] x=not f s_min=SWAG(10**18,min) s_max=SWAG(0,max) *_,=list(map(s_min.append,p[:k-1])) *_,=list(map(s_max.append,p[1:k])) for i,(a,b,c)in enumerate(zip(p,p[k:],c)): f|=c s_min.append(p[i+k-1]) s_max.append(b) if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1 s_min.popleft() s_max.popleft() print((x+f))
60
54
1,812
1,738
class SWAG: def __init__(self, unit, f): self.fold_r = [unit] self.fold_l = [unit] self.data_r = [] self.data_l = [] self.f = f def __refill_right(self): temp = [] n = len(self.data_l) for _ in range(n // 2): temp.append(self.popleft()) for _ in range(n // 2, n): self.append(self.popleft()) for _ in range(n // 2): self.appendleft(temp.pop()) def __refill_left(self): temp = [] n = len(self.data_r) for _ in range(n // 2): temp.append(self.pop()) for _ in range(n // 2, n): self.appendleft(self.pop()) for _ in range(n // 2): self.append(temp.pop()) def append(self, x): self.fold_r.append(self.f(self.fold_r[-1], x)) self.data_r.append(x) def appendleft(self, x): self.fold_l.append(self.f(self.fold_l[-1], x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1], self.fold_l[-1]) n, k, *p = list(map(int, open(0).read().split())) c = [0] for a, b in zip(p, p[1:]): c += (c[-1] + (a < b),) *c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])] x = not f s_min = SWAG(10**18, min) s_max = SWAG(0, max) (*_,) = list(map(s_min.append, p[: k - 1])) (*_,) = list(map(s_max.append, p[1:k])) for i, (a, b, c) in enumerate(zip(p, p[k:], c)): f |= c s_min.append(p[i + k - 1]) s_max.append(b) if not c and (a != s_min.fold_all() or b != s_max.fold_all()): x += 1 s_min.popleft() s_max.popleft() print((x + f))
class SWAG: def __init__(self, unit, f): self.fold_r = [unit] self.fold_l = [unit] self.data_r = [] self.data_l = [] self.f = f def __refill_right(self): temp = [] n = len(self.data_l) (*_,) = list(map(temp.append, (self.popleft() for _ in range(n // 2)))) (*_,) = list(map(self.append, (self.popleft() for _ in range(n // 2, n)))) (*_,) = list(map(self.appendleft, temp[::-1])) def __refill_left(self): temp = [] n = len(self.data_r) (*_,) = list(map(temp.append, (self.pop() for _ in range(n // 2)))) (*_,) = list(map(self.appendleft, (self.pop() for _ in range(n // 2, n)))) (*_,) = list(map(self.append, temp[::-1])) def append(self, x): self.fold_r.append(self.f(self.fold_r[-1], x)) self.data_r.append(x) def appendleft(self, x): self.fold_l.append(self.f(self.fold_l[-1], x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1], self.fold_l[-1]) n, k, *p = list(map(int, open(0).read().split())) c = [0] for a, b in zip(p, p[1:]): c += (c[-1] + (a < b),) *c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])] x = not f s_min = SWAG(10**18, min) s_max = SWAG(0, max) (*_,) = list(map(s_min.append, p[: k - 1])) (*_,) = list(map(s_max.append, p[1:k])) for i, (a, b, c) in enumerate(zip(p, p[k:], c)): f |= c s_min.append(p[i + k - 1]) s_max.append(b) if not c and (a != s_min.fold_all() or b != s_max.fold_all()): x += 1 s_min.popleft() s_max.popleft() print((x + f))
false
10
[ "- for _ in range(n // 2):", "- temp.append(self.popleft())", "- for _ in range(n // 2, n):", "- self.append(self.popleft())", "- for _ in range(n // 2):", "- self.appendleft(temp.pop())", "+ (*_,) = list(map(temp.append, (self.popleft() for _ in range(n // 2))))", "+ (*_,) = list(map(self.append, (self.popleft() for _ in range(n // 2, n))))", "+ (*_,) = list(map(self.appendleft, temp[::-1]))", "- for _ in range(n // 2):", "- temp.append(self.pop())", "- for _ in range(n // 2, n):", "- self.appendleft(self.pop())", "- for _ in range(n // 2):", "- self.append(temp.pop())", "+ (*_,) = list(map(temp.append, (self.pop() for _ in range(n // 2))))", "+ (*_,) = list(map(self.appendleft, (self.pop() for _ in range(n // 2, n))))", "+ (*_,) = list(map(self.append, temp[::-1]))" ]
false
0.043671
0.044489
0.9816
[ "s330084945", "s561210699" ]
u077291787
p02913
python
s509912036
s605360236
108
83
76,212
11,208
Accepted
Accepted
23.15
from typing import List, Tuple class RollingHash: """Rolling Hash""" __slots__ = ["_base", "_mod", "_hash", "_power"] def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7): self._base = base self._mod = mod self._hash, self._power = self._build(source) def _build(self, source: str) -> Tuple[List[int], List[int]]: """Compute "hash" and "mod of power of base" of interval [0, right).""" length = len(source) hash_, power = [0] * (length + 1), [0] * (length + 1) power[0] = 1 for i, c in enumerate(source, 1): hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod power[i] = power[i - 1] * self._base % self._mod return hash_, power def get_hash(self, left: int, right: int): """Return hash of interval [left, right).""" return ( self._hash[right] - self._hash[left] * self._power[right - left] ) % self._mod def abc141_e(): # https://atcoder.jp/contests/abc141/tasks/abc141_e N = int(eval(input())) S = input().rstrip() rh = RollingHash(S) ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg = False memo = set() for i in range(N - 2 * mid + 1): memo.add(rh.get_hash(i, i + mid)) if rh.get_hash(i + mid, i + 2 * mid) in memo: flg = True break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": abc141_e()
from typing import List, Tuple class RollingHash: """Rolling Hash""" __slots__ = ["_base", "_mod", "_hash", "_power"] def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7): self._base = base self._mod = mod self._hash, self._power = self._build(source) def _build(self, source: str) -> Tuple[List[int], List[int]]: """Compute "hash" and "mod of power of base" of interval [0, right).""" hash_, power = [0] * (len(source) + 1), [0] * (len(source) + 1) power[0] = 1 for i, c in enumerate(source, 1): hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod power[i] = power[i - 1] * self._base % self._mod return hash_, power def get_hash(self, left: int, right: int): """Return hash of interval [left, right).""" return ( self._hash[right] - self._hash[left] * self._power[right - left] ) % self._mod def abc141_e(): # https://atcoder.jp/contests/abc141/tasks/abc141_e N = int(eval(input())) S = input().rstrip() rh = RollingHash(S) ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg = False memo = set() for i in range(N - 2 * mid + 1): memo.add(rh.get_hash(i, i + mid)) if rh.get_hash(i + mid, i + 2 * mid) in memo: flg = True break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": abc141_e()
56
55
1,743
1,723
from typing import List, Tuple class RollingHash: """Rolling Hash""" __slots__ = ["_base", "_mod", "_hash", "_power"] def __init__(self, source: str, base: int = 1007, mod: int = 10**9 + 7): self._base = base self._mod = mod self._hash, self._power = self._build(source) def _build(self, source: str) -> Tuple[List[int], List[int]]: """Compute "hash" and "mod of power of base" of interval [0, right).""" length = len(source) hash_, power = [0] * (length + 1), [0] * (length + 1) power[0] = 1 for i, c in enumerate(source, 1): hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod power[i] = power[i - 1] * self._base % self._mod return hash_, power def get_hash(self, left: int, right: int): """Return hash of interval [left, right).""" return ( self._hash[right] - self._hash[left] * self._power[right - left] ) % self._mod def abc141_e(): # https://atcoder.jp/contests/abc141/tasks/abc141_e N = int(eval(input())) S = input().rstrip() rh = RollingHash(S) ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg = False memo = set() for i in range(N - 2 * mid + 1): memo.add(rh.get_hash(i, i + mid)) if rh.get_hash(i + mid, i + 2 * mid) in memo: flg = True break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": abc141_e()
from typing import List, Tuple class RollingHash: """Rolling Hash""" __slots__ = ["_base", "_mod", "_hash", "_power"] def __init__(self, source: str, base: int = 1007, mod: int = 10**9 + 7): self._base = base self._mod = mod self._hash, self._power = self._build(source) def _build(self, source: str) -> Tuple[List[int], List[int]]: """Compute "hash" and "mod of power of base" of interval [0, right).""" hash_, power = [0] * (len(source) + 1), [0] * (len(source) + 1) power[0] = 1 for i, c in enumerate(source, 1): hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod power[i] = power[i - 1] * self._base % self._mod return hash_, power def get_hash(self, left: int, right: int): """Return hash of interval [left, right).""" return ( self._hash[right] - self._hash[left] * self._power[right - left] ) % self._mod def abc141_e(): # https://atcoder.jp/contests/abc141/tasks/abc141_e N = int(eval(input())) S = input().rstrip() rh = RollingHash(S) ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg = False memo = set() for i in range(N - 2 * mid + 1): memo.add(rh.get_hash(i, i + mid)) if rh.get_hash(i + mid, i + 2 * mid) in memo: flg = True break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": abc141_e()
false
1.785714
[ "- length = len(source)", "- hash_, power = [0] * (length + 1), [0] * (length + 1)", "+ hash_, power = [0] * (len(source) + 1), [0] * (len(source) + 1)" ]
false
0.089157
0.081822
1.089645
[ "s509912036", "s605360236" ]
u608088992
p02861
python
s129430528
s726833218
375
330
3,064
3,064
Accepted
Accepted
12
import sys from itertools import permutations from math import sqrt def solve(): input = sys.stdin.readline N = int(eval(input())) coordinate = dict() for i in range(N): coordinate[i] = tuple(map(int, input().split())) total_length = 0 perm_count = 0 for p in permutations(list(range(N))): perm_count += 1 current_id = coordinate[int(p[0])] for j in range(1, N): next_id = coordinate[int(p[j])] total_length += sqrt((current_id[0] - next_id[0]) ** 2 + (current_id[1] - next_id[1]) ** 2) current_id = next_id print((total_length / perm_count)) return 0 if __name__ == "__main__": solve()
import sys from itertools import permutations from math import sqrt def solve(): input = sys.stdin.readline N = int(eval(input())) C = [[int(i) for i in input().split()] for _ in range(N)] totalDist = 0 count =0 for order in permutations(list(range(N))): count += 1 dist = 0 for i in range((N-1)): X = C[order[i]] Y = C[order[i+1]] dist += sqrt((X[0] - Y[0]) ** 2 + (X[1] - Y[1]) ** 2) totalDist += dist print((totalDist / count)) return 0 if __name__ == "__main__": solve()
27
24
711
591
import sys from itertools import permutations from math import sqrt def solve(): input = sys.stdin.readline N = int(eval(input())) coordinate = dict() for i in range(N): coordinate[i] = tuple(map(int, input().split())) total_length = 0 perm_count = 0 for p in permutations(list(range(N))): perm_count += 1 current_id = coordinate[int(p[0])] for j in range(1, N): next_id = coordinate[int(p[j])] total_length += sqrt( (current_id[0] - next_id[0]) ** 2 + (current_id[1] - next_id[1]) ** 2 ) current_id = next_id print((total_length / perm_count)) return 0 if __name__ == "__main__": solve()
import sys from itertools import permutations from math import sqrt def solve(): input = sys.stdin.readline N = int(eval(input())) C = [[int(i) for i in input().split()] for _ in range(N)] totalDist = 0 count = 0 for order in permutations(list(range(N))): count += 1 dist = 0 for i in range((N - 1)): X = C[order[i]] Y = C[order[i + 1]] dist += sqrt((X[0] - Y[0]) ** 2 + (X[1] - Y[1]) ** 2) totalDist += dist print((totalDist / count)) return 0 if __name__ == "__main__": solve()
false
11.111111
[ "- coordinate = dict()", "- for i in range(N):", "- coordinate[i] = tuple(map(int, input().split()))", "- total_length = 0", "- perm_count = 0", "- for p in permutations(list(range(N))):", "- perm_count += 1", "- current_id = coordinate[int(p[0])]", "- for j in range(1, N):", "- next_id = coordinate[int(p[j])]", "- total_length += sqrt(", "- (current_id[0] - next_id[0]) ** 2 + (current_id[1] - next_id[1]) ** 2", "- )", "- current_id = next_id", "- print((total_length / perm_count))", "+ C = [[int(i) for i in input().split()] for _ in range(N)]", "+ totalDist = 0", "+ count = 0", "+ for order in permutations(list(range(N))):", "+ count += 1", "+ dist = 0", "+ for i in range((N - 1)):", "+ X = C[order[i]]", "+ Y = C[order[i + 1]]", "+ dist += sqrt((X[0] - Y[0]) ** 2 + (X[1] - Y[1]) ** 2)", "+ totalDist += dist", "+ print((totalDist / count))" ]
false
0.039814
0.034148
1.16592
[ "s129430528", "s726833218" ]
u909643606
p03716
python
s777672817
s090431689
543
501
38,292
38,288
Accepted
Accepted
7.73
import heapq n = int(eval(input())) a = [int(i) for i in input().split()] k = 0 a_front = [] a_center = [] a_back = [] front_sum = 0 back_sum = 0 for i in a: k += 1 if k <= n: a_front += [i] front_sum += i elif k <= 2 * n: a_center += [i] else: a_back += [-i] back_sum += i heapq.heapify(a_front) heapq.heapify(a_back) front_sums = [front_sum] back_sums = [back_sum] for i in range(n): front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) front_sums += [front_sum] back_sum += a_center[-i-1] + heapq.heappushpop(a_back, -a_center[-i-1]) back_sums += [back_sum] print((max([front_sums[i] - back_sums[-i-1] for i in range(n+1)]))) #print(front_sums, back_sums)
import heapq def calc(front_sum, back_sum): heapq.heapify(a_front) heapq.heapify(a_back) front_sums = [front_sum] back_sums = [back_sum] for i in range(n): front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) front_sums += [front_sum] back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1]) back_sums += [back_sum] return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)]) if __name__ == "__main__": n = int(eval(input())) a = [int(i) for i in input().split()] k = 0 a_front = [] a_center = [] a_back = [] front_sum = 0 back_sum = 0 for i in a: k += 1 if k <= n: a_front += [i] front_sum += i elif k <= 2 * n: a_center += [i] else: a_back += [-i] back_sum += i print((calc(front_sum, back_sum)))
35
39
792
963
import heapq n = int(eval(input())) a = [int(i) for i in input().split()] k = 0 a_front = [] a_center = [] a_back = [] front_sum = 0 back_sum = 0 for i in a: k += 1 if k <= n: a_front += [i] front_sum += i elif k <= 2 * n: a_center += [i] else: a_back += [-i] back_sum += i heapq.heapify(a_front) heapq.heapify(a_back) front_sums = [front_sum] back_sums = [back_sum] for i in range(n): front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) front_sums += [front_sum] back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1]) back_sums += [back_sum] print((max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)]))) # print(front_sums, back_sums)
import heapq def calc(front_sum, back_sum): heapq.heapify(a_front) heapq.heapify(a_back) front_sums = [front_sum] back_sums = [back_sum] for i in range(n): front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) front_sums += [front_sum] back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1]) back_sums += [back_sum] return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)]) if __name__ == "__main__": n = int(eval(input())) a = [int(i) for i in input().split()] k = 0 a_front = [] a_center = [] a_back = [] front_sum = 0 back_sum = 0 for i in a: k += 1 if k <= n: a_front += [i] front_sum += i elif k <= 2 * n: a_center += [i] else: a_back += [-i] back_sum += i print((calc(front_sum, back_sum)))
false
10.25641
[ "-n = int(eval(input()))", "-a = [int(i) for i in input().split()]", "-k = 0", "-a_front = []", "-a_center = []", "-a_back = []", "-front_sum = 0", "-back_sum = 0", "-for i in a:", "- k += 1", "- if k <= n:", "- a_front += [i]", "- front_sum += i", "- elif k <= 2 * n:", "- a_center += [i]", "- else:", "- a_back += [-i]", "- back_sum += i", "-heapq.heapify(a_front)", "-heapq.heapify(a_back)", "-front_sums = [front_sum]", "-back_sums = [back_sum]", "-for i in range(n):", "- front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])", "- front_sums += [front_sum]", "- back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])", "- back_sums += [back_sum]", "-print((max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])))", "-# print(front_sums, back_sums)", "+", "+def calc(front_sum, back_sum):", "+ heapq.heapify(a_front)", "+ heapq.heapify(a_back)", "+ front_sums = [front_sum]", "+ back_sums = [back_sum]", "+ for i in range(n):", "+ front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])", "+ front_sums += [front_sum]", "+ back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])", "+ back_sums += [back_sum]", "+ return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])", "+", "+", "+if __name__ == \"__main__\":", "+ n = int(eval(input()))", "+ a = [int(i) for i in input().split()]", "+ k = 0", "+ a_front = []", "+ a_center = []", "+ a_back = []", "+ front_sum = 0", "+ back_sum = 0", "+ for i in a:", "+ k += 1", "+ if k <= n:", "+ a_front += [i]", "+ front_sum += i", "+ elif k <= 2 * n:", "+ a_center += [i]", "+ else:", "+ a_back += [-i]", "+ back_sum += i", "+ print((calc(front_sum, back_sum)))" ]
false
0.049052
0.040747
1.203818
[ "s777672817", "s090431689" ]
u987164499
p03352
python
s998520805
s606963513
288
22
18,532
2,940
Accepted
Accepted
92.36
from sys import stdin import bisect from itertools import accumulate import numpy as np n = int(stdin.readline().rstrip()) li = [1] for i in range(2,34): for s in range(2,10): if i**s <= 1000: li.append(i**s) else: break li = list(set(li)) li.sort() print((li[bisect.bisect(li,n)-1]))
x = int(eval(input())) ma = 0 for i in range(1,100): for j in range(2,100): if i**j <= x: ma = max(ma,i**j) print(ma)
21
7
356
141
from sys import stdin import bisect from itertools import accumulate import numpy as np n = int(stdin.readline().rstrip()) li = [1] for i in range(2, 34): for s in range(2, 10): if i**s <= 1000: li.append(i**s) else: break li = list(set(li)) li.sort() print((li[bisect.bisect(li, n) - 1]))
x = int(eval(input())) ma = 0 for i in range(1, 100): for j in range(2, 100): if i**j <= x: ma = max(ma, i**j) print(ma)
false
66.666667
[ "-from sys import stdin", "-import bisect", "-from itertools import accumulate", "-import numpy as np", "-", "-n = int(stdin.readline().rstrip())", "-li = [1]", "-for i in range(2, 34):", "- for s in range(2, 10):", "- if i**s <= 1000:", "- li.append(i**s)", "- else:", "- break", "-li = list(set(li))", "-li.sort()", "-print((li[bisect.bisect(li, n) - 1]))", "+x = int(eval(input()))", "+ma = 0", "+for i in range(1, 100):", "+ for j in range(2, 100):", "+ if i**j <= x:", "+ ma = max(ma, i**j)", "+print(ma)" ]
false
0.060076
0.054311
1.106147
[ "s998520805", "s606963513" ]
u507116804
p03609
python
s251900635
s174110353
21
18
3,060
2,940
Accepted
Accepted
14.29
x,t=list(map(int, input().split())) if x-t>0: print((int(x-t))) else: print((int(0)))
x,t=list(map(int, input().split())) A=x-t if A>=0: print(A) else: print((0))
6
8
85
81
x, t = list(map(int, input().split())) if x - t > 0: print((int(x - t))) else: print((int(0)))
x, t = list(map(int, input().split())) A = x - t if A >= 0: print(A) else: print((0))
false
25
[ "-if x - t > 0:", "- print((int(x - t)))", "+A = x - t", "+if A >= 0:", "+ print(A)", "- print((int(0)))", "+ print((0))" ]
false
0.035939
0.034757
1.033985
[ "s251900635", "s174110353" ]
u831244171
p02255
python
s600882488
s423637954
30
20
5,976
5,604
Accepted
Accepted
33.33
n = int(input()) lst = list(map(int,input().split())) def pri(lst): for i in range(len(lst)-1): print(lst[i],end=" ") print(lst[-1]) pri(lst) for i in range(1,n): v = lst[i] j = i-1 while True: if j < 0: lst[0] = v break if lst[j] > v: lst[j+1] = lst[j] j -= 1 else: lst[j+1] = v break pri(lst)
def insertsort(array): for i in range(1,len(array)): print((" ".join(list(map(str,array))))) temp = array[i] j = i-1 while j >= 0 and temp < array[j]: array[j+1] = array[j] j -= 1 array[j+1] = temp return array eval(input()) a = insertsort(list(map(int,input().split()))) print((" ".join(list(map(str,a)))))
24
15
449
386
n = int(input()) lst = list(map(int, input().split())) def pri(lst): for i in range(len(lst) - 1): print(lst[i], end=" ") print(lst[-1]) pri(lst) for i in range(1, n): v = lst[i] j = i - 1 while True: if j < 0: lst[0] = v break if lst[j] > v: lst[j + 1] = lst[j] j -= 1 else: lst[j + 1] = v break pri(lst)
def insertsort(array): for i in range(1, len(array)): print((" ".join(list(map(str, array))))) temp = array[i] j = i - 1 while j >= 0 and temp < array[j]: array[j + 1] = array[j] j -= 1 array[j + 1] = temp return array eval(input()) a = insertsort(list(map(int, input().split()))) print((" ".join(list(map(str, a)))))
false
37.5
[ "-n = int(input())", "-lst = list(map(int, input().split()))", "+def insertsort(array):", "+ for i in range(1, len(array)):", "+ print((\" \".join(list(map(str, array)))))", "+ temp = array[i]", "+ j = i - 1", "+ while j >= 0 and temp < array[j]:", "+ array[j + 1] = array[j]", "+ j -= 1", "+ array[j + 1] = temp", "+ return array", "-def pri(lst):", "- for i in range(len(lst) - 1):", "- print(lst[i], end=\" \")", "- print(lst[-1])", "-", "-", "-pri(lst)", "-for i in range(1, n):", "- v = lst[i]", "- j = i - 1", "- while True:", "- if j < 0:", "- lst[0] = v", "- break", "- if lst[j] > v:", "- lst[j + 1] = lst[j]", "- j -= 1", "- else:", "- lst[j + 1] = v", "- break", "- pri(lst)", "+eval(input())", "+a = insertsort(list(map(int, input().split())))", "+print((\" \".join(list(map(str, a)))))" ]
false
0.039082
0.078754
0.496259
[ "s600882488", "s423637954" ]
u987164499
p03574
python
s695652480
s668421136
153
33
12,264
3,188
Accepted
Accepted
78.43
from sys import stdin import math import bisect import heapq import numpy as np from math import factorial inf = 10**10 h,w = [int(x) for x in stdin.readline().rstrip().split()] li = [["." for i in range(w+2)]for j in range(h+2)] for i in range(1,h+1): s = stdin.readline().rstrip() for j in range(1,w+1): li[i][j] = s[j-1] lin = [[0 for i in range(w)]for j in range(h)] for i in range(1,h+1): for j in range(1,j+1): if li[i][j] == "#": lin[i-1][j-1] = "#" else: point = 0 if li[i-1][j-1] == "#": point += 1 if li[i-1][j] == "#": point += 1 if li[i-1][j+1] == "#": point += 1 if li[i][j-1] == "#": point += 1 if li[i][j+1] == "#": point += 1 if li[i+1][j-1] == "#": point += 1 if li[i+1][j] == "#": point += 1 if li[i+1][j+1] == "#": point += 1 lin[i-1][j-1] = str(point) for i in lin: s = "".join(i) print(s)
from sys import stdin,setrecursionlimit setrecursionlimit(10 ** 7) h,w = list(map(int,stdin.readline().rstrip().split())) s = [stdin.readline().rstrip() for _ in range(h)] li = [[0 for i in range(w)]for j in range(h)] x = [-1,0,1] y = [-1,0,1] for i in range(h): for j in range(w): count = 0 for xx in x: for yy in y: if xx == 0 and yy == 0: continue if j+xx < 0 or j+xx > w-1: continue if i+yy < 0 or i+yy > h-1: continue if s[i+yy][j+xx] == "#": count += 1 if s[i][j] == "#": li[i][j] = "#" else:li[i][j] = str(count) for i in li: print(("".join(i)))
45
30
1,169
786
from sys import stdin import math import bisect import heapq import numpy as np from math import factorial inf = 10**10 h, w = [int(x) for x in stdin.readline().rstrip().split()] li = [["." for i in range(w + 2)] for j in range(h + 2)] for i in range(1, h + 1): s = stdin.readline().rstrip() for j in range(1, w + 1): li[i][j] = s[j - 1] lin = [[0 for i in range(w)] for j in range(h)] for i in range(1, h + 1): for j in range(1, j + 1): if li[i][j] == "#": lin[i - 1][j - 1] = "#" else: point = 0 if li[i - 1][j - 1] == "#": point += 1 if li[i - 1][j] == "#": point += 1 if li[i - 1][j + 1] == "#": point += 1 if li[i][j - 1] == "#": point += 1 if li[i][j + 1] == "#": point += 1 if li[i + 1][j - 1] == "#": point += 1 if li[i + 1][j] == "#": point += 1 if li[i + 1][j + 1] == "#": point += 1 lin[i - 1][j - 1] = str(point) for i in lin: s = "".join(i) print(s)
from sys import stdin, setrecursionlimit setrecursionlimit(10**7) h, w = list(map(int, stdin.readline().rstrip().split())) s = [stdin.readline().rstrip() for _ in range(h)] li = [[0 for i in range(w)] for j in range(h)] x = [-1, 0, 1] y = [-1, 0, 1] for i in range(h): for j in range(w): count = 0 for xx in x: for yy in y: if xx == 0 and yy == 0: continue if j + xx < 0 or j + xx > w - 1: continue if i + yy < 0 or i + yy > h - 1: continue if s[i + yy][j + xx] == "#": count += 1 if s[i][j] == "#": li[i][j] = "#" else: li[i][j] = str(count) for i in li: print(("".join(i)))
false
33.333333
[ "-from sys import stdin", "-import math", "-import bisect", "-import heapq", "-import numpy as np", "-from math import factorial", "+from sys import stdin, setrecursionlimit", "-inf = 10**10", "-h, w = [int(x) for x in stdin.readline().rstrip().split()]", "-li = [[\".\" for i in range(w + 2)] for j in range(h + 2)]", "-for i in range(1, h + 1):", "- s = stdin.readline().rstrip()", "- for j in range(1, w + 1):", "- li[i][j] = s[j - 1]", "-lin = [[0 for i in range(w)] for j in range(h)]", "-for i in range(1, h + 1):", "- for j in range(1, j + 1):", "- if li[i][j] == \"#\":", "- lin[i - 1][j - 1] = \"#\"", "+setrecursionlimit(10**7)", "+h, w = list(map(int, stdin.readline().rstrip().split()))", "+s = [stdin.readline().rstrip() for _ in range(h)]", "+li = [[0 for i in range(w)] for j in range(h)]", "+x = [-1, 0, 1]", "+y = [-1, 0, 1]", "+for i in range(h):", "+ for j in range(w):", "+ count = 0", "+ for xx in x:", "+ for yy in y:", "+ if xx == 0 and yy == 0:", "+ continue", "+ if j + xx < 0 or j + xx > w - 1:", "+ continue", "+ if i + yy < 0 or i + yy > h - 1:", "+ continue", "+ if s[i + yy][j + xx] == \"#\":", "+ count += 1", "+ if s[i][j] == \"#\":", "+ li[i][j] = \"#\"", "- point = 0", "- if li[i - 1][j - 1] == \"#\":", "- point += 1", "- if li[i - 1][j] == \"#\":", "- point += 1", "- if li[i - 1][j + 1] == \"#\":", "- point += 1", "- if li[i][j - 1] == \"#\":", "- point += 1", "- if li[i][j + 1] == \"#\":", "- point += 1", "- if li[i + 1][j - 1] == \"#\":", "- point += 1", "- if li[i + 1][j] == \"#\":", "- point += 1", "- if li[i + 1][j + 1] == \"#\":", "- point += 1", "- lin[i - 1][j - 1] = str(point)", "-for i in lin:", "- s = \"\".join(i)", "- print(s)", "+ li[i][j] = str(count)", "+for i in li:", "+ print((\"\".join(i)))" ]
false
0.04071
0.066684
0.610497
[ "s695652480", "s668421136" ]
u496744988
p03487
python
s578663801
s963769344
111
87
21,224
18,672
Accepted
Accepted
21.62
from collections import Counter def MI(): return list(map(int, input().split())) def II(): return int(eval(input())) def IS(): return eval(input()) def LI(): return list(map(int, input().split())) n = II() l = list(Counter(LI()).items()) ans = 0 for num in l: if num[0] < num[1]: ans += num[1]-num[0] elif num[0] > num[1]: ans += num[1] else: # num[0] == num[1] pass print(ans)
from collections import Counter n=int(eval(input())) ans=0 for i in list(Counter(list(map(int,input().split()))).items()): if i[0]<i[1]: ans+=i[1]-i[0] elif i[0]>i[1]: ans+=i[1] print(ans)
18
9
416
208
from collections import Counter def MI(): return list(map(int, input().split())) def II(): return int(eval(input())) def IS(): return eval(input()) def LI(): return list(map(int, input().split())) n = II() l = list(Counter(LI()).items()) ans = 0 for num in l: if num[0] < num[1]: ans += num[1] - num[0] elif num[0] > num[1]: ans += num[1] else: # num[0] == num[1] pass print(ans)
from collections import Counter n = int(eval(input())) ans = 0 for i in list(Counter(list(map(int, input().split()))).items()): if i[0] < i[1]: ans += i[1] - i[0] elif i[0] > i[1]: ans += i[1] print(ans)
false
50
[ "-", "-def MI():", "- return list(map(int, input().split()))", "-", "-", "-def II():", "- return int(eval(input()))", "-", "-", "-def IS():", "- return eval(input())", "-", "-", "-def LI():", "- return list(map(int, input().split()))", "-", "-", "-n = II()", "-l = list(Counter(LI()).items())", "+n = int(eval(input()))", "-for num in l:", "- if num[0] < num[1]:", "- ans += num[1] - num[0]", "- elif num[0] > num[1]:", "- ans += num[1]", "- else: # num[0] == num[1]", "- pass", "+for i in list(Counter(list(map(int, input().split()))).items()):", "+ if i[0] < i[1]:", "+ ans += i[1] - i[0]", "+ elif i[0] > i[1]:", "+ ans += i[1]" ]
false
0.126231
0.044637
2.827954
[ "s578663801", "s963769344" ]
u037430802
p03253
python
s866685188
s808175288
1,708
22
4,400
3,316
Accepted
Accepted
98.71
import math def getPrimeFactorsDict(num): pn = 2 #素数は2から pfdict = {} #素因数のリスト while pn * pn <= num: #√numまで調べる while num % pn == 0: #現在の素数で割り切れる範囲でループ num = num / pn pfdict[pn] = pfdict.get(pn, 0) + 1 pn += 1 #割り切れなくなったら次の素数へ if num > 1: pfdict[int(num)] = pfdict.get(int(num), 0) + 1 return pfdict N, M = list(map(int, input().split())) d = getPrimeFactorsDict(M) ans = 1 for key in list(d.keys()): if d[key] == 1: ans *= N else: ans *= math.factorial(N+d[key]-1) // (math.factorial(N-1) * math.factorial(d[key])) print((ans % (10**9+7)))
from collections import defaultdict N,M = list(map(int, input().split())) MOD = 10**9+7 # 素因数分解 d = defaultdict(int) i = 2 while i*i <= M: if M % i == 0: d[i] += 1 M //= i else: i += 1 if M > 1: d[M] += 1 # 素因数をN個に分配する方法 def nCr(n,r): if n < 0 or r < 0 or n < r: return 0 if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n # 分子のn*(n-1)*...がr個分続くやつ numerator = [n-r+k+1 for k in range(r)] # 分母:r!=r*(r-1)*...*3*2の要素 denominator = [k+1 for k in range(r)] # 分母の要素で割れる部分を割っていく部分 for p in range(2, r+1): # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か pivot = denominator[p-1] if pivot > 1: # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか offset = (n-r) % p for k in range(p-1, r, p): # 約分できる要素について割る numerator[k - offset] /= pivot denominator[k] /= pivot ret = 1 for k in range(r): if numerator[k] > 1: ret *= int(numerator[k]) return ret """ それぞれの素数についてどの用意分配するか考える 例:2が5個あり、3箇所に分ける(2を受け取らない場所があってもよい)とは 並んでいる5つの2の間にしきりを二つ入れる、のと同じ なので、5つの2と2つの仕切りの重複順列といえる。 上の例は3H5と表せて、 nHr = (n+r-1)Crとなる """ ans = 1 for k in list(d.keys()): ans *= nCr((N+d[k]-1), d[k]) ans %= MOD print(ans)
30
59
616
1,392
import math def getPrimeFactorsDict(num): pn = 2 # 素数は2から pfdict = {} # 素因数のリスト while pn * pn <= num: # √numまで調べる while num % pn == 0: # 現在の素数で割り切れる範囲でループ num = num / pn pfdict[pn] = pfdict.get(pn, 0) + 1 pn += 1 # 割り切れなくなったら次の素数へ if num > 1: pfdict[int(num)] = pfdict.get(int(num), 0) + 1 return pfdict N, M = list(map(int, input().split())) d = getPrimeFactorsDict(M) ans = 1 for key in list(d.keys()): if d[key] == 1: ans *= N else: ans *= math.factorial(N + d[key] - 1) // ( math.factorial(N - 1) * math.factorial(d[key]) ) print((ans % (10**9 + 7)))
from collections import defaultdict N, M = list(map(int, input().split())) MOD = 10**9 + 7 # 素因数分解 d = defaultdict(int) i = 2 while i * i <= M: if M % i == 0: d[i] += 1 M //= i else: i += 1 if M > 1: d[M] += 1 # 素因数をN個に分配する方法 def nCr(n, r): if n < 0 or r < 0 or n < r: return 0 if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n # 分子のn*(n-1)*...がr個分続くやつ numerator = [n - r + k + 1 for k in range(r)] # 分母:r!=r*(r-1)*...*3*2の要素 denominator = [k + 1 for k in range(r)] # 分母の要素で割れる部分を割っていく部分 for p in range(2, r + 1): # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か pivot = denominator[p - 1] if pivot > 1: # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか offset = (n - r) % p for k in range(p - 1, r, p): # 約分できる要素について割る numerator[k - offset] /= pivot denominator[k] /= pivot ret = 1 for k in range(r): if numerator[k] > 1: ret *= int(numerator[k]) return ret """ それぞれの素数についてどの用意分配するか考える 例:2が5個あり、3箇所に分ける(2を受け取らない場所があってもよい)とは 並んでいる5つの2の間にしきりを二つ入れる、のと同じ なので、5つの2と2つの仕切りの重複順列といえる。 上の例は3H5と表せて、 nHr = (n+r-1)Crとなる """ ans = 1 for k in list(d.keys()): ans *= nCr((N + d[k] - 1), d[k]) ans %= MOD print(ans)
false
49.152542
[ "-import math", "+from collections import defaultdict", "+", "+N, M = list(map(int, input().split()))", "+MOD = 10**9 + 7", "+# 素因数分解", "+d = defaultdict(int)", "+i = 2", "+while i * i <= M:", "+ if M % i == 0:", "+ d[i] += 1", "+ M //= i", "+ else:", "+ i += 1", "+if M > 1:", "+ d[M] += 1", "+# 素因数をN個に分配する方法", "+def nCr(n, r):", "+ if n < 0 or r < 0 or n < r:", "+ return 0", "+ if n - r < r:", "+ r = n - r", "+ if r == 0:", "+ return 1", "+ if r == 1:", "+ return n", "+ # 分子のn*(n-1)*...がr個分続くやつ", "+ numerator = [n - r + k + 1 for k in range(r)]", "+ # 分母:r!=r*(r-1)*...*3*2の要素", "+ denominator = [k + 1 for k in range(r)]", "+ # 分母の要素で割れる部分を割っていく部分", "+ for p in range(2, r + 1):", "+ # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か", "+ pivot = denominator[p - 1]", "+ if pivot > 1:", "+ # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか", "+ offset = (n - r) % p", "+ for k in range(p - 1, r, p):", "+ # 約分できる要素について割る", "+ numerator[k - offset] /= pivot", "+ denominator[k] /= pivot", "+ ret = 1", "+ for k in range(r):", "+ if numerator[k] > 1:", "+ ret *= int(numerator[k])", "+ return ret", "-def getPrimeFactorsDict(num):", "- pn = 2 # 素数は2から", "- pfdict = {} # 素因数のリスト", "- while pn * pn <= num: # √numまで調べる", "- while num % pn == 0: # 現在の素数で割り切れる範囲でループ", "- num = num / pn", "- pfdict[pn] = pfdict.get(pn, 0) + 1", "- pn += 1 # 割り切れなくなったら次の素数へ", "- if num > 1:", "- pfdict[int(num)] = pfdict.get(int(num), 0) + 1", "- return pfdict", "-", "-", "-N, M = list(map(int, input().split()))", "-d = getPrimeFactorsDict(M)", "+\"\"\"", "+それぞれの素数についてどの用意分配するか考える", "+例:2が5個あり、3箇所に分ける(2を受け取らない場所があってもよい)とは", "+並んでいる5つの2の間にしきりを二つ入れる、のと同じ", "+なので、5つの2と2つの仕切りの重複順列といえる。", "+上の例は3H5と表せて、", "+nHr = (n+r-1)Crとなる", "+\"\"\"", "-for key in list(d.keys()):", "- if d[key] == 1:", "- ans *= N", "- else:", "- ans *= math.factorial(N + d[key] - 1) // (", "- math.factorial(N - 1) * math.factorial(d[key])", "- )", "-print((ans % (10**9 + 7)))", "+for k in list(d.keys()):", "+ ans *= nCr((N + d[k] - 1), d[k])", "+ ans %= MOD", "+print(ans)" ]
false
0.319679
0.049415
6.469268
[ "s866685188", "s808175288" ]
u203383537
p02732
python
s300609572
s163932468
475
282
26,772
33,988
Accepted
Accepted
40.63
import collections n=int(eval(input())) A=list(map(int,input().split())) a=collections.Counter(A) total=0 for v in list(a.values()): if v>1: c=(v*(v-1))//2 total+=c for i in A: ans=total-(a[i]*(a[i]-1))//2+((a[i]-1)*(a[i]-2))//2 print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) A = Counter(a) cnt = 0 for i in list(A.values()): if i > 1: cnt += (i*(i-1)//2) for i in a: ans = 0 before = (A[i]*(A[i]-1))//2 after = ((A[i]-1)*(A[i]-2))//2 ans = cnt - before + after print(ans)
16
21
274
341
import collections n = int(eval(input())) A = list(map(int, input().split())) a = collections.Counter(A) total = 0 for v in list(a.values()): if v > 1: c = (v * (v - 1)) // 2 total += c for i in A: ans = total - (a[i] * (a[i] - 1)) // 2 + ((a[i] - 1) * (a[i] - 2)) // 2 print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) A = Counter(a) cnt = 0 for i in list(A.values()): if i > 1: cnt += i * (i - 1) // 2 for i in a: ans = 0 before = (A[i] * (A[i] - 1)) // 2 after = ((A[i] - 1) * (A[i] - 2)) // 2 ans = cnt - before + after print(ans)
false
23.809524
[ "-import collections", "+from collections import Counter", "-A = list(map(int, input().split()))", "-a = collections.Counter(A)", "-total = 0", "-for v in list(a.values()):", "- if v > 1:", "- c = (v * (v - 1)) // 2", "- total += c", "-for i in A:", "- ans = total - (a[i] * (a[i] - 1)) // 2 + ((a[i] - 1) * (a[i] - 2)) // 2", "+a = list(map(int, input().split()))", "+A = Counter(a)", "+cnt = 0", "+for i in list(A.values()):", "+ if i > 1:", "+ cnt += i * (i - 1) // 2", "+for i in a:", "+ ans = 0", "+ before = (A[i] * (A[i] - 1)) // 2", "+ after = ((A[i] - 1) * (A[i] - 2)) // 2", "+ ans = cnt - before + after" ]
false
0.036291
0.036907
0.98331
[ "s300609572", "s163932468" ]
u021019433
p02975
python
s201198322
s197239541
76
62
14,212
14,212
Accepted
Accepted
18.42
R = lambda: list(map(int, input().split())) n = int(eval(input())) if n % 3: ans = 'YNeos'[any(R())::2] else: a = sorted(R()) m = n // 3 if a[0] ^ a[m] ^ a[2 * m]: ans = 'No' elif any(a[i] != a[i - 1] for i in range(1, n) if m != i != 2 * m): ans = 'No' else: ans = 'Yes' print(ans)
R = lambda: list(map(int, input().split())) n = int(eval(input())) if n % 3: ans = 'YNeos'[any(R())::2] else: a = sorted(R()) m = n // 3 if a[0] ^ a[m] ^ a[2 * m]: ans = 'No' elif any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)): ans = 'No' else: ans = 'Yes' print(ans)
15
15
335
326
R = lambda: list(map(int, input().split())) n = int(eval(input())) if n % 3: ans = "YNeos"[any(R()) :: 2] else: a = sorted(R()) m = n // 3 if a[0] ^ a[m] ^ a[2 * m]: ans = "No" elif any(a[i] != a[i - 1] for i in range(1, n) if m != i != 2 * m): ans = "No" else: ans = "Yes" print(ans)
R = lambda: list(map(int, input().split())) n = int(eval(input())) if n % 3: ans = "YNeos"[any(R()) :: 2] else: a = sorted(R()) m = n // 3 if a[0] ^ a[m] ^ a[2 * m]: ans = "No" elif any(len(set(a[i : i + m])) > 1 for i in range(0, n, m)): ans = "No" else: ans = "Yes" print(ans)
false
0
[ "- elif any(a[i] != a[i - 1] for i in range(1, n) if m != i != 2 * m):", "+ elif any(len(set(a[i : i + m])) > 1 for i in range(0, n, m)):" ]
false
0.042564
0.037758
1.127294
[ "s201198322", "s197239541" ]
u440180827
p02385
python
s438004176
s642733299
30
20
7,732
7,724
Accepted
Accepted
33.33
x = list(map(int, input().split())) y = list(map(int, input().split())) z = [0, 1, 2] for i in range(6): order = [0, 0, 0] for j in range(3): if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}: break if x[j] == y[z[j]]: order[j] = 1 if x[j] == x[-j-1]: order[j] = 2 else: if 2 in order or (i < 3) == sum(order) % 2: print('Yes') break z = z[-1:] + z[:-1] if i == 2: z = [z[0], z[2], z[1]] else: print('No')
x = list(map(int, input().split())) y = list(map(int, input().split())) z = [0, 1, 2] for i in range(6): order = [0, 0, 0] for j in range(3): if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}: break if x[j] == y[z[j]]: order[j] = 1 if x[j] == x[-j-1]: order[j] = 2 else: if 2 in order or (i < 3) == sum(order) % 2: print('Yes') break z = [z[2], z[0], z[1]] if i == 2: z = [z[0], z[2], z[1]] else: print('No')
21
21
553
556
x = list(map(int, input().split())) y = list(map(int, input().split())) z = [0, 1, 2] for i in range(6): order = [0, 0, 0] for j in range(3): if {x[j], x[-j - 1]} != {y[z[j]], y[-z[j] - 1]}: break if x[j] == y[z[j]]: order[j] = 1 if x[j] == x[-j - 1]: order[j] = 2 else: if 2 in order or (i < 3) == sum(order) % 2: print("Yes") break z = z[-1:] + z[:-1] if i == 2: z = [z[0], z[2], z[1]] else: print("No")
x = list(map(int, input().split())) y = list(map(int, input().split())) z = [0, 1, 2] for i in range(6): order = [0, 0, 0] for j in range(3): if {x[j], x[-j - 1]} != {y[z[j]], y[-z[j] - 1]}: break if x[j] == y[z[j]]: order[j] = 1 if x[j] == x[-j - 1]: order[j] = 2 else: if 2 in order or (i < 3) == sum(order) % 2: print("Yes") break z = [z[2], z[0], z[1]] if i == 2: z = [z[0], z[2], z[1]] else: print("No")
false
0
[ "- z = z[-1:] + z[:-1]", "+ z = [z[2], z[0], z[1]]" ]
false
0.035138
0.033625
1.045003
[ "s438004176", "s642733299" ]
u074220993
p03759
python
s089818497
s632912155
29
26
9,160
9,160
Accepted
Accepted
10.34
a, b, c = list(map(int, input().split())) if b - a == c - b: print("YES") else: print("NO")
a,b,c = list(map(int, input().split())) print(('YES' if b-a == c-b else 'NO'))
5
2
97
71
a, b, c = list(map(int, input().split())) if b - a == c - b: print("YES") else: print("NO")
a, b, c = list(map(int, input().split())) print(("YES" if b - a == c - b else "NO"))
false
60
[ "-if b - a == c - b:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+print((\"YES\" if b - a == c - b else \"NO\"))" ]
false
0.19749
0.121291
1.628239
[ "s089818497", "s632912155" ]
u762420987
p03799
python
s228199201
s295588336
166
17
38,384
2,940
Accepted
Accepted
89.76
N, M = list(map(int, input().split())) if N == M // 2: ans = N if N > M // 2: ans = M // 2 if N < M // 2: ans = N M -= (N * 2) ans += M // 4 print(ans)
N, M = list(map(int, input().split())) if 2*N <= M: ans = N M -= 2*N ans += M//4 else: ans = M//2 print(ans)
10
8
175
126
N, M = list(map(int, input().split())) if N == M // 2: ans = N if N > M // 2: ans = M // 2 if N < M // 2: ans = N M -= N * 2 ans += M // 4 print(ans)
N, M = list(map(int, input().split())) if 2 * N <= M: ans = N M -= 2 * N ans += M // 4 else: ans = M // 2 print(ans)
false
20
[ "-if N == M // 2:", "+if 2 * N <= M:", "-if N > M // 2:", "+ M -= 2 * N", "+ ans += M // 4", "+else:", "-if N < M // 2:", "- ans = N", "- M -= N * 2", "- ans += M // 4" ]
false
0.045293
0.036995
1.224323
[ "s228199201", "s295588336" ]
u581187895
p02682
python
s826177538
s090344876
23
20
9,140
9,180
Accepted
Accepted
13.04
def resolve(): A, B, C, K = map(int, input().split()) ans = 0 cnt = min(K, A) ans += cnt * 1 K -= cnt if K < 1: return print(ans) cnt = min(K, B) ans += cnt * 0 K -= cnt if K < 1: return print(ans) ans += K * -1 print(ans) if __name__ == "__main__": resolve()
def resolve(): a, b,c,k = list(map(int, input().split())) ans = 0 used = min(k,a) ans += used * 1 k -= used used = min(k, b) k -= used ans += k*(-1) print(ans) if __name__ == "__main__": resolve()
23
16
355
249
def resolve(): A, B, C, K = map(int, input().split()) ans = 0 cnt = min(K, A) ans += cnt * 1 K -= cnt if K < 1: return print(ans) cnt = min(K, B) ans += cnt * 0 K -= cnt if K < 1: return print(ans) ans += K * -1 print(ans) if __name__ == "__main__": resolve()
def resolve(): a, b, c, k = list(map(int, input().split())) ans = 0 used = min(k, a) ans += used * 1 k -= used used = min(k, b) k -= used ans += k * (-1) print(ans) if __name__ == "__main__": resolve()
false
30.434783
[ "- A, B, C, K = map(int, input().split())", "+ a, b, c, k = list(map(int, input().split()))", "- cnt = min(K, A)", "- ans += cnt * 1", "- K -= cnt", "- if K < 1:", "- return print(ans)", "- cnt = min(K, B)", "- ans += cnt * 0", "- K -= cnt", "- if K < 1:", "- return print(ans)", "- ans += K * -1", "+ used = min(k, a)", "+ ans += used * 1", "+ k -= used", "+ used = min(k, b)", "+ k -= used", "+ ans += k * (-1)" ]
false
0.046938
0.047118
0.996194
[ "s826177538", "s090344876" ]
u179169725
p03283
python
s671831877
s515183551
1,423
1,237
20,656
48,896
Accepted
Accepted
13.07
# https://atcoder.jp/contests/abc106/tasks/abc106_d # どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか? # p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる # このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数 # queryに高速に答えるために二次元累積和を構築する import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret import numpy as np N, M, Q = read_ints() # numpy使わずに再実装 #入れるときはpythonのほうが速いので LR2d = [[0] * (N + 1) for _ in range(N + 1)] for _ in range(M): L, R = read_ints() LR2d[L][R] += 1 LR2d = np.array(LR2d) LR2d_accum = np.zeros((N + 2, N + 2), np.int64) LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1) # 1次元累積和同様半開区間で考える # つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す # pq = read_tuple(Q) for _ in range(Q): p, q = read_ints() print((LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] - LR2d_accum[p, q + 1] + LR2d_accum[p, p])) ''' 以下numpyを使わずに実装してみる '''
# https://atcoder.jp/contests/abc106/tasks/abc106_d # どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか? # p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる # このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数 # queryに高速に答えるために二次元累積和を構築する import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret import numpy as np N, M, Q = read_ints() LR = read_tuple(M) pq = read_tuple(Q) # numpy使わずに再実装 #入れるときはpythonのほうが速いので LR2d = [[0] * (N + 1) for _ in range(N + 1)] for L, R in LR: LR2d[L][R] += 1 LR2d = np.array(LR2d, np.int64) LR2d_accum = np.zeros((N + 2, N + 2), np.int64) LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1) # 1次元累積和同様半開区間で考える # つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す # queryに答えていく for p, q in pq: print((LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] - LR2d_accum[p, q + 1] + LR2d_accum[p, p]))
50
43
1,126
1,077
# https://atcoder.jp/contests/abc106/tasks/abc106_d # どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか? # p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる # このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数 # queryに高速に答えるために二次元累積和を構築する import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret import numpy as np N, M, Q = read_ints() # numpy使わずに再実装 #入れるときはpythonのほうが速いので LR2d = [[0] * (N + 1) for _ in range(N + 1)] for _ in range(M): L, R = read_ints() LR2d[L][R] += 1 LR2d = np.array(LR2d) LR2d_accum = np.zeros((N + 2, N + 2), np.int64) LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1) # 1次元累積和同様半開区間で考える # つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す # pq = read_tuple(Q) for _ in range(Q): p, q = read_ints() print( ( LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] - LR2d_accum[p, q + 1] + LR2d_accum[p, p] ) ) """ 以下numpyを使わずに実装してみる """
# https://atcoder.jp/contests/abc106/tasks/abc106_d # どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか? # p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる # このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数 # queryに高速に答えるために二次元累積和を構築する import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret import numpy as np N, M, Q = read_ints() LR = read_tuple(M) pq = read_tuple(Q) # numpy使わずに再実装 #入れるときはpythonのほうが速いので LR2d = [[0] * (N + 1) for _ in range(N + 1)] for L, R in LR: LR2d[L][R] += 1 LR2d = np.array(LR2d, np.int64) LR2d_accum = np.zeros((N + 2, N + 2), np.int64) LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1) # 1次元累積和同様半開区間で考える # つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す # queryに答えていく for p, q in pq: print( ( LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] - LR2d_accum[p, q + 1] + LR2d_accum[p, p] ) )
false
14
[ "+LR = read_tuple(M)", "+pq = read_tuple(Q)", "-for _ in range(M):", "- L, R = read_ints()", "+for L, R in LR:", "-LR2d = np.array(LR2d)", "+LR2d = np.array(LR2d, np.int64)", "-# pq = read_tuple(Q)", "-for _ in range(Q):", "- p, q = read_ints()", "+# queryに答えていく", "+for p, q in pq:", "-\"\"\"", "-以下numpyを使わずに実装してみる", "-\"\"\"" ]
false
0.263134
0.200981
1.309253
[ "s671831877", "s515183551" ]
u077291787
p03162
python
s878590467
s375287991
413
247
21,308
21,308
Accepted
Accepted
40.19
# dpC - Vacation # 3 variables def main(): n = int(eval(input())) A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n)) a, b, c = A[0] for x, y, z in A[1:]: a, b, c = x + max(b, c), y + max(a, c), z + max(a, b) print((max(a, b, c))) if __name__ == "__main__": main()
# dpC - Vacation # 3 variables import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n)) a, b, c = A[0] for x, y, z in A[1:]: a, b, c = x + max(b, c), y + max(a, c), z + max(a, b) print((max(a, b, c))) if __name__ == "__main__": main()
13
16
321
363
# dpC - Vacation # 3 variables def main(): n = int(eval(input())) A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n)) a, b, c = A[0] for x, y, z in A[1:]: a, b, c = x + max(b, c), y + max(a, c), z + max(a, b) print((max(a, b, c))) if __name__ == "__main__": main()
# dpC - Vacation # 3 variables import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n)) a, b, c = A[0] for x, y, z in A[1:]: a, b, c = x + max(b, c), y + max(a, c), z + max(a, b) print((max(a, b, c))) if __name__ == "__main__": main()
false
18.75
[ "+import sys", "+", "+input = sys.stdin.readline", "+", "+" ]
false
0.035085
0.042429
0.826916
[ "s878590467", "s375287991" ]
u033606236
p03434
python
s717818983
s598336588
21
17
3,060
3,060
Accepted
Accepted
19.05
Num = int(eval(input())) Num_Array = list(map(int,input().split())) Alice,Bob = 0,0 for i in range ( Num ): Check_Max = -1 for x in range(len(Num_Array)): if Num_Array[x] > Check_Max : Check_Max = Num_Array[x] check = x Num_Array.pop(check) if i % 2 == 0 : Alice += Check_Max else: Bob += Check_Max print((Alice - Bob))
Num = int(eval(input())) Num_Array = sorted(list(map(int,input().split())),reverse=True) Alice,Bob = 0,0 for i in range(Num): if i % 2 == 0 : Alice += Num_Array[i] else: Bob += Num_Array[i] print((Alice - Bob))
20
12
403
242
Num = int(eval(input())) Num_Array = list(map(int, input().split())) Alice, Bob = 0, 0 for i in range(Num): Check_Max = -1 for x in range(len(Num_Array)): if Num_Array[x] > Check_Max: Check_Max = Num_Array[x] check = x Num_Array.pop(check) if i % 2 == 0: Alice += Check_Max else: Bob += Check_Max print((Alice - Bob))
Num = int(eval(input())) Num_Array = sorted(list(map(int, input().split())), reverse=True) Alice, Bob = 0, 0 for i in range(Num): if i % 2 == 0: Alice += Num_Array[i] else: Bob += Num_Array[i] print((Alice - Bob))
false
40
[ "-Num_Array = list(map(int, input().split()))", "+Num_Array = sorted(list(map(int, input().split())), reverse=True)", "- Check_Max = -1", "- for x in range(len(Num_Array)):", "- if Num_Array[x] > Check_Max:", "- Check_Max = Num_Array[x]", "- check = x", "- Num_Array.pop(check)", "- Alice += Check_Max", "+ Alice += Num_Array[i]", "- Bob += Check_Max", "+ Bob += Num_Array[i]" ]
false
0.046239
0.045273
1.021335
[ "s717818983", "s598336588" ]
u934442292
p03017
python
s704702493
s721974806
76
61
3,572
9,516
Accepted
Accepted
19.74
import sys input = sys.stdin.readline # NOQA def main(): N, A, B, C, D = list(map(int, input().split())) A -= 1 B -= 1 C -= 1 D -= 1 S = input().rstrip() can_jump_R = True # '##' can_jump_B = False # '...' for i in range(A + 1, N - 1): if S[i] == S[i+1] == "#": if A < i < C or B < i < D: can_jump_R = False if S[i-1] == S[i] == S[i+1] == ".": if B <= i < C and i-1 != D: can_jump_B = True if C < D: if can_jump_R: ans = "Yes" else: ans = "No" else: if can_jump_R and can_jump_B: ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N, A, B, C, D = list(map(int, input().split())) A -= 1 B -= 1 C -= 1 D -= 1 S = input().rstrip() if C < D: is_ok = True for i in range(A, D): if S[i:i + 2] == "##": is_ok = False break ans = "Yes" if is_ok else "No" else: is_ok = True for i in range(A, C): if S[i:i + 2] == "##": is_ok = False break if not is_ok: ans = "No" else: is_ok = False for i in range(B, D + 1): if S[i - 1:i + 2] == "...": is_ok = True break ans = "Yes" if is_ok else "No" print(ans) if __name__ == "__main__": main()
37
41
797
873
import sys input = sys.stdin.readline # NOQA def main(): N, A, B, C, D = list(map(int, input().split())) A -= 1 B -= 1 C -= 1 D -= 1 S = input().rstrip() can_jump_R = True # '##' can_jump_B = False # '...' for i in range(A + 1, N - 1): if S[i] == S[i + 1] == "#": if A < i < C or B < i < D: can_jump_R = False if S[i - 1] == S[i] == S[i + 1] == ".": if B <= i < C and i - 1 != D: can_jump_B = True if C < D: if can_jump_R: ans = "Yes" else: ans = "No" else: if can_jump_R and can_jump_B: ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N, A, B, C, D = list(map(int, input().split())) A -= 1 B -= 1 C -= 1 D -= 1 S = input().rstrip() if C < D: is_ok = True for i in range(A, D): if S[i : i + 2] == "##": is_ok = False break ans = "Yes" if is_ok else "No" else: is_ok = True for i in range(A, C): if S[i : i + 2] == "##": is_ok = False break if not is_ok: ans = "No" else: is_ok = False for i in range(B, D + 1): if S[i - 1 : i + 2] == "...": is_ok = True break ans = "Yes" if is_ok else "No" print(ans) if __name__ == "__main__": main()
false
9.756098
[ "-input = sys.stdin.readline # NOQA", "+input = sys.stdin.readline", "- can_jump_R = True # '##'", "- can_jump_B = False # '...'", "- for i in range(A + 1, N - 1):", "- if S[i] == S[i + 1] == \"#\":", "- if A < i < C or B < i < D:", "- can_jump_R = False", "- if S[i - 1] == S[i] == S[i + 1] == \".\":", "- if B <= i < C and i - 1 != D:", "- can_jump_B = True", "- if can_jump_R:", "- ans = \"Yes\"", "+ is_ok = True", "+ for i in range(A, D):", "+ if S[i : i + 2] == \"##\":", "+ is_ok = False", "+ break", "+ ans = \"Yes\" if is_ok else \"No\"", "+ else:", "+ is_ok = True", "+ for i in range(A, C):", "+ if S[i : i + 2] == \"##\":", "+ is_ok = False", "+ break", "+ if not is_ok:", "+ ans = \"No\"", "- ans = \"No\"", "- else:", "- if can_jump_R and can_jump_B:", "- ans = \"Yes\"", "- else:", "- ans = \"No\"", "+ is_ok = False", "+ for i in range(B, D + 1):", "+ if S[i - 1 : i + 2] == \"...\":", "+ is_ok = True", "+ break", "+ ans = \"Yes\" if is_ok else \"No\"" ]
false
0.048268
0.063593
0.759005
[ "s704702493", "s721974806" ]
u619144316
p02928
python
s701332170
s441154376
1,463
1,281
3,188
3,188
Accepted
Accepted
12.44
N, k = list(map(int,input().split())) A = list(map(int,input().split())) MOD = 10**9+7 ans = 0 for i in range(N): for j in range(N): if A[i] > A[j]: if i > j: ans += k*(k-1)//2 elif i < j: ans += k*(k+1)//2 ans %= MOD print(ans)
N,k = list(map(int,input().split())) A = list(map(int,input().split())) ans = 0 MOD = 10**9+7 for i in range(N): for j in range(i+1,N): if A[i] > A[j]: ans += k*(k+1)//2 elif A[i] < A[j]: ans += k*(k-1)//2 ans %= MOD print(ans)
15
14
319
288
N, k = list(map(int, input().split())) A = list(map(int, input().split())) MOD = 10**9 + 7 ans = 0 for i in range(N): for j in range(N): if A[i] > A[j]: if i > j: ans += k * (k - 1) // 2 elif i < j: ans += k * (k + 1) // 2 ans %= MOD print(ans)
N, k = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 MOD = 10**9 + 7 for i in range(N): for j in range(i + 1, N): if A[i] > A[j]: ans += k * (k + 1) // 2 elif A[i] < A[j]: ans += k * (k - 1) // 2 ans %= MOD print(ans)
false
6.666667
[ "+ans = 0", "-ans = 0", "- for j in range(N):", "+ for j in range(i + 1, N):", "- if i > j:", "- ans += k * (k - 1) // 2", "- elif i < j:", "- ans += k * (k + 1) // 2", "- ans %= MOD", "+ ans += k * (k + 1) // 2", "+ elif A[i] < A[j]:", "+ ans += k * (k - 1) // 2", "+ ans %= MOD" ]
false
0.04768
0.046418
1.027179
[ "s701332170", "s441154376" ]
u694665829
p03472
python
s655725003
s709929477
278
255
13,044
14,448
Accepted
Accepted
8.27
N,H=list(map(int,input().split())) B=[] A=0 for _ in range(N): a,b=list(map(int,input().split())) A=max(A,a) B.append(b) B.sort(reverse=True) ans=(H-1)//A+1 for i in range(N): H-=B[i] if H<=0: ans=min(ans,i+1) break ans=min(ans,(H-1)//A+1+i+1) print(ans)
N,H=list(map(int,input().split())) B=[] A=0 for _ in range(N): a,b = list(map(int,input().split())) A = max(A,a) B.append(b) B = sorted(B, reverse=True) + [0] i = 0 while B[i] >= A: i += 1 B = B[:i] ans = 0 for i in range(len(B)): H -= B[i] ans += 1 if H <= 0: print(ans) exit() print((ans + (H -1)//A + 1))
16
22
297
361
N, H = list(map(int, input().split())) B = [] A = 0 for _ in range(N): a, b = list(map(int, input().split())) A = max(A, a) B.append(b) B.sort(reverse=True) ans = (H - 1) // A + 1 for i in range(N): H -= B[i] if H <= 0: ans = min(ans, i + 1) break ans = min(ans, (H - 1) // A + 1 + i + 1) print(ans)
N, H = list(map(int, input().split())) B = [] A = 0 for _ in range(N): a, b = list(map(int, input().split())) A = max(A, a) B.append(b) B = sorted(B, reverse=True) + [0] i = 0 while B[i] >= A: i += 1 B = B[:i] ans = 0 for i in range(len(B)): H -= B[i] ans += 1 if H <= 0: print(ans) exit() print((ans + (H - 1) // A + 1))
false
27.272727
[ "-B.sort(reverse=True)", "-ans = (H - 1) // A + 1", "-for i in range(N):", "+B = sorted(B, reverse=True) + [0]", "+i = 0", "+while B[i] >= A:", "+ i += 1", "+B = B[:i]", "+ans = 0", "+for i in range(len(B)):", "+ ans += 1", "- ans = min(ans, i + 1)", "- break", "- ans = min(ans, (H - 1) // A + 1 + i + 1)", "-print(ans)", "+ print(ans)", "+ exit()", "+print((ans + (H - 1) // A + 1))" ]
false
0.047106
0.047122
0.999663
[ "s655725003", "s709929477" ]
u623814058
p03160
python
s529528911
s763159513
142
118
20,444
20,388
Accepted
Accepted
16.9
N=int(eval(input())) *H,=list(map(int,input().split())) D=[10**4*N]*N D[0]=0 for i in range(N): if 1<=i: #print(i,H[i],H[i-1],abs(H[i]-H[i-1])) D[i]=min(D[i],abs(H[i]-H[i-1])+D[i-1]) if 2<=i: #print(i,H[i],H[i-2],abs(H[i]-H[i-2])) D[i]=min(D[i],abs(H[i]-H[i-2])+D[i-2]) print((D[-1]))
N=int(eval(input())) *H,=list(map(int,input().split())) D=[-1]*N D[0]=0 D[1]=abs(H[1]-H[0]) for i in range(2,N): D[i]=min(abs(H[i]-H[i-1])+D[i-1],abs(H[i]-H[i-2])+D[i-2]) print((D[-1]))
14
8
325
182
N = int(eval(input())) (*H,) = list(map(int, input().split())) D = [10**4 * N] * N D[0] = 0 for i in range(N): if 1 <= i: # print(i,H[i],H[i-1],abs(H[i]-H[i-1])) D[i] = min(D[i], abs(H[i] - H[i - 1]) + D[i - 1]) if 2 <= i: # print(i,H[i],H[i-2],abs(H[i]-H[i-2])) D[i] = min(D[i], abs(H[i] - H[i - 2]) + D[i - 2]) print((D[-1]))
N = int(eval(input())) (*H,) = list(map(int, input().split())) D = [-1] * N D[0] = 0 D[1] = abs(H[1] - H[0]) for i in range(2, N): D[i] = min(abs(H[i] - H[i - 1]) + D[i - 1], abs(H[i] - H[i - 2]) + D[i - 2]) print((D[-1]))
false
42.857143
[ "-D = [10**4 * N] * N", "+D = [-1] * N", "-for i in range(N):", "- if 1 <= i:", "- # print(i,H[i],H[i-1],abs(H[i]-H[i-1]))", "- D[i] = min(D[i], abs(H[i] - H[i - 1]) + D[i - 1])", "- if 2 <= i:", "- # print(i,H[i],H[i-2],abs(H[i]-H[i-2]))", "- D[i] = min(D[i], abs(H[i] - H[i - 2]) + D[i - 2])", "+D[1] = abs(H[1] - H[0])", "+for i in range(2, N):", "+ D[i] = min(abs(H[i] - H[i - 1]) + D[i - 1], abs(H[i] - H[i - 2]) + D[i - 2])" ]
false
0.042779
0.035744
1.196831
[ "s529528911", "s763159513" ]
u810356688
p02845
python
s597440370
s598206311
300
67
53,036
14,008
Accepted
Accepted
77.67
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): n=int(eval(input())) A=list(map(int,input().split())) rgb=[-1,-1,-1] ans=1 mod=10**9+7 for a in A: ans=ans*Counter(rgb)[a-1]%mod if ans==0:break rgb[rgb.index(a-1)]+=1 print(ans) if __name__=='__main__': main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(eval(input())) A=list(map(int,input().split())) cunt=[0]*(n+1) cunt[0]=3 ans=1 mod=10**9+7 for a in A: ans=ans*cunt[a]%mod if ans==0:break cunt[a+1]+=1 cunt[a]-=1 print(ans) if __name__=='__main__': main()
18
19
388
370
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): n = int(eval(input())) A = list(map(int, input().split())) rgb = [-1, -1, -1] ans = 1 mod = 10**9 + 7 for a in A: ans = ans * Counter(rgb)[a - 1] % mod if ans == 0: break rgb[rgb.index(a - 1)] += 1 print(ans) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): n = int(eval(input())) A = list(map(int, input().split())) cunt = [0] * (n + 1) cunt[0] = 3 ans = 1 mod = 10**9 + 7 for a in A: ans = ans * cunt[a] % mod if ans == 0: break cunt[a + 1] += 1 cunt[a] -= 1 print(ans) if __name__ == "__main__": main()
false
5.263158
[ "-from collections import Counter", "-", "-", "- rgb = [-1, -1, -1]", "+ cunt = [0] * (n + 1)", "+ cunt[0] = 3", "- ans = ans * Counter(rgb)[a - 1] % mod", "+ ans = ans * cunt[a] % mod", "- rgb[rgb.index(a - 1)] += 1", "+ cunt[a + 1] += 1", "+ cunt[a] -= 1" ]
false
0.037393
0.036885
1.013756
[ "s597440370", "s598206311" ]
u761320129
p02763
python
s417211494
s249305189
914
839
172,148
172,020
Accepted
Accepted
8.21
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] def ctoi(c): return ord(c) - ord('a') bit = [[0]*(N+2) for _ in range(26)] def bit_add(x,w,ci): while x <= N+1: bit[ci][x] += w x += (x & -x) def bit_sum(x,ci): ret = 0 while x > 0: ret += bit[ci][x] x -= (x & -x) return ret for i,c in enumerate(S): bit_add(i+1,1,ctoi(c)) s = list(S) ans = [] for a,b,c in qs: if a=='1': x = int(b) bit_add(x,1,ctoi(c)) bit_add(x,-1, ctoi(s[x-1])) s[x-1] = c else: tmp = 0 for i in range(26): if bit_sum(int(c),i) - bit_sum(int(b)-1,i) > 0: tmp += 1 ans.append(tmp) print(*ans, sep='\n')
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] def ctoi(c): return ord(c) - ord('a') class BinaryIndexedTree: def __init__(self,size): self.N = size self.bit = [0]*(size+1) def add(self,x,w): while x <= self.N: self.bit[x] += w x += (x & -x) def sum(self,x): ret = 0 while x > 0: ret += self.bit[x] x -= (x & -x) return ret bits = [BinaryIndexedTree(N) for _ in range(26)] for i,c in enumerate(S): bits[ctoi(c)].add(i+1,1) s = list(S) ans = [] for a,b,c in qs: if a=='1': x = int(b) bits[ctoi(c)].add(x,1) bits[ctoi(s[x-1])].add(x,-1) s[x-1] = c else: tmp = 0 for i in range(26): if bits[i].sum(int(c)) - bits[i].sum(int(b)-1) > 0: tmp += 1 ans.append(tmp) print(*ans, sep='\n')
40
44
846
1,020
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] def ctoi(c): return ord(c) - ord("a") bit = [[0] * (N + 2) for _ in range(26)] def bit_add(x, w, ci): while x <= N + 1: bit[ci][x] += w x += x & -x def bit_sum(x, ci): ret = 0 while x > 0: ret += bit[ci][x] x -= x & -x return ret for i, c in enumerate(S): bit_add(i + 1, 1, ctoi(c)) s = list(S) ans = [] for a, b, c in qs: if a == "1": x = int(b) bit_add(x, 1, ctoi(c)) bit_add(x, -1, ctoi(s[x - 1])) s[x - 1] = c else: tmp = 0 for i in range(26): if bit_sum(int(c), i) - bit_sum(int(b) - 1, i) > 0: tmp += 1 ans.append(tmp) print(*ans, sep="\n")
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] def ctoi(c): return ord(c) - ord("a") class BinaryIndexedTree: def __init__(self, size): self.N = size self.bit = [0] * (size + 1) def add(self, x, w): while x <= self.N: self.bit[x] += w x += x & -x def sum(self, x): ret = 0 while x > 0: ret += self.bit[x] x -= x & -x return ret bits = [BinaryIndexedTree(N) for _ in range(26)] for i, c in enumerate(S): bits[ctoi(c)].add(i + 1, 1) s = list(S) ans = [] for a, b, c in qs: if a == "1": x = int(b) bits[ctoi(c)].add(x, 1) bits[ctoi(s[x - 1])].add(x, -1) s[x - 1] = c else: tmp = 0 for i in range(26): if bits[i].sum(int(c)) - bits[i].sum(int(b) - 1) > 0: tmp += 1 ans.append(tmp) print(*ans, sep="\n")
false
9.090909
[ "-bit = [[0] * (N + 2) for _ in range(26)]", "+class BinaryIndexedTree:", "+ def __init__(self, size):", "+ self.N = size", "+ self.bit = [0] * (size + 1)", "+", "+ def add(self, x, w):", "+ while x <= self.N:", "+ self.bit[x] += w", "+ x += x & -x", "+", "+ def sum(self, x):", "+ ret = 0", "+ while x > 0:", "+ ret += self.bit[x]", "+ x -= x & -x", "+ return ret", "-def bit_add(x, w, ci):", "- while x <= N + 1:", "- bit[ci][x] += w", "- x += x & -x", "-", "-", "-def bit_sum(x, ci):", "- ret = 0", "- while x > 0:", "- ret += bit[ci][x]", "- x -= x & -x", "- return ret", "-", "-", "+bits = [BinaryIndexedTree(N) for _ in range(26)]", "- bit_add(i + 1, 1, ctoi(c))", "+ bits[ctoi(c)].add(i + 1, 1)", "- bit_add(x, 1, ctoi(c))", "- bit_add(x, -1, ctoi(s[x - 1]))", "+ bits[ctoi(c)].add(x, 1)", "+ bits[ctoi(s[x - 1])].add(x, -1)", "- if bit_sum(int(c), i) - bit_sum(int(b) - 1, i) > 0:", "+ if bits[i].sum(int(c)) - bits[i].sum(int(b) - 1) > 0:" ]
false
0.0378
0.036134
1.046104
[ "s417211494", "s249305189" ]
u454022848
p02401
python
s016457594
s297057212
30
10
6,732
6,432
Accepted
Accepted
66.67
while True: a,op,b=input().split(" ") a,b=[int(i) for i in (a,b)] if op=="+": print((a+b)) elif op=="-": print((a-b)) elif op=="*": print((a*b)) elif op=="/": print((int(a/b))) else: break
# encoding:utf-8 while True: a, op, b = input().split() if op == "?": break a, b = list(map(int, (a,b))) if op == "+": print((a+b)) elif op == "-": print((a-b)) elif op == "*": print((a*b)) else: print((a/b))
13
15
209
230
while True: a, op, b = input().split(" ") a, b = [int(i) for i in (a, b)] if op == "+": print((a + b)) elif op == "-": print((a - b)) elif op == "*": print((a * b)) elif op == "/": print((int(a / b))) else: break
# encoding:utf-8 while True: a, op, b = input().split() if op == "?": break a, b = list(map(int, (a, b))) if op == "+": print((a + b)) elif op == "-": print((a - b)) elif op == "*": print((a * b)) else: print((a / b))
false
13.333333
[ "+# encoding:utf-8", "- a, op, b = input().split(\" \")", "- a, b = [int(i) for i in (a, b)]", "+ a, op, b = input().split()", "+ if op == \"?\":", "+ break", "+ a, b = list(map(int, (a, b)))", "- elif op == \"/\":", "- print((int(a / b)))", "- break", "+ print((a / b))" ]
false
0.037626
0.036955
1.018172
[ "s016457594", "s297057212" ]
u970197315
p02802
python
s404693032
s868855244
431
340
27,744
12,652
Accepted
Accepted
21.11
# ABC151 C si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(str, input().split())) nl = lambda: list(map(int, input().split())) from collections import defaultdict n,m=list(map(int, input().split())) ac=set() ac_cnt=0 wa_cnt=0 d_ac=defaultdict(int) d_wa=defaultdict(int) for i in range(m): p,s=nm() if s=='AC': if int(p) in ac: continue ac.add(int(p)) ac_cnt+=1 elif s=='WA': if int(p) in ac: continue d_wa[p]+=1 for a in ac: wa_cnt+=d_wa[str(a)] print((ac_cnt,wa_cnt))
n,m=list(map(int,input().split())) ac,wa=0,0 ac_set=set() wa_cnt=[0]*(n+1) for i in range(m): p,s=list(map(str,input().split())) p=int(p) if s=="AC": if p in ac_set: continue ac_set.add(p) else: if p in ac_set: continue wa_cnt[p]+=1 ac=len(ac_set) for a in ac_set: wa+=wa_cnt[a] print((ac,wa))
29
19
587
335
# ABC151 C si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(str, input().split())) nl = lambda: list(map(int, input().split())) from collections import defaultdict n, m = list(map(int, input().split())) ac = set() ac_cnt = 0 wa_cnt = 0 d_ac = defaultdict(int) d_wa = defaultdict(int) for i in range(m): p, s = nm() if s == "AC": if int(p) in ac: continue ac.add(int(p)) ac_cnt += 1 elif s == "WA": if int(p) in ac: continue d_wa[p] += 1 for a in ac: wa_cnt += d_wa[str(a)] print((ac_cnt, wa_cnt))
n, m = list(map(int, input().split())) ac, wa = 0, 0 ac_set = set() wa_cnt = [0] * (n + 1) for i in range(m): p, s = list(map(str, input().split())) p = int(p) if s == "AC": if p in ac_set: continue ac_set.add(p) else: if p in ac_set: continue wa_cnt[p] += 1 ac = len(ac_set) for a in ac_set: wa += wa_cnt[a] print((ac, wa))
false
34.482759
[ "-# ABC151 C", "-si = lambda: eval(input())", "-ni = lambda: int(eval(input()))", "-nm = lambda: list(map(str, input().split()))", "-nl = lambda: list(map(int, input().split()))", "-from collections import defaultdict", "-", "-ac = set()", "-ac_cnt = 0", "-wa_cnt = 0", "-d_ac = defaultdict(int)", "-d_wa = defaultdict(int)", "+ac, wa = 0, 0", "+ac_set = set()", "+wa_cnt = [0] * (n + 1)", "- p, s = nm()", "+ p, s = list(map(str, input().split()))", "+ p = int(p)", "- if int(p) in ac:", "+ if p in ac_set:", "- ac.add(int(p))", "- ac_cnt += 1", "- elif s == \"WA\":", "- if int(p) in ac:", "+ ac_set.add(p)", "+ else:", "+ if p in ac_set:", "- d_wa[p] += 1", "-for a in ac:", "- wa_cnt += d_wa[str(a)]", "-print((ac_cnt, wa_cnt))", "+ wa_cnt[p] += 1", "+ac = len(ac_set)", "+for a in ac_set:", "+ wa += wa_cnt[a]", "+print((ac, wa))" ]
false
0.045375
0.04892
0.927547
[ "s404693032", "s868855244" ]
u595289165
p02832
python
s763013270
s963373666
106
89
24,744
24,744
Accepted
Accepted
16.04
n = int(eval(input())) a = list(map(int, input().split())) now = 1 ans = 0 for i in range(n): if a[i] == now: now += 1 else: ans += 1 if ans == len(a): print((-1)) else: print(ans)
n = int(eval(input())) a = list(map(int, input().split())) val = 1 ans = 0 for a_i in a: if a_i == val: val += 1 else: ans += 1 if val == 1: print((-1)) else: print(ans)
15
15
220
209
n = int(eval(input())) a = list(map(int, input().split())) now = 1 ans = 0 for i in range(n): if a[i] == now: now += 1 else: ans += 1 if ans == len(a): print((-1)) else: print(ans)
n = int(eval(input())) a = list(map(int, input().split())) val = 1 ans = 0 for a_i in a: if a_i == val: val += 1 else: ans += 1 if val == 1: print((-1)) else: print(ans)
false
0
[ "-now = 1", "+val = 1", "-for i in range(n):", "- if a[i] == now:", "- now += 1", "+for a_i in a:", "+ if a_i == val:", "+ val += 1", "-if ans == len(a):", "+if val == 1:" ]
false
0.031128
0.032439
0.95957
[ "s763013270", "s963373666" ]
u218834617
p02579
python
s427956692
s996247067
1,235
826
217,728
201,324
Accepted
Accepted
33.12
import sys from collections import deque H,W=list(map(int,input().split())) si,sj=[int(x)-1 for x in input().split()] ti,tj=[int(x)-1 for x in input().split()] A=list(sys.stdin) dirs=[-2,-1,0,1,2] dist=[[10**6]*W for _ in range(H)] dist[si][sj]=0 dq=deque() dq.append((0,si,sj)) ok=False while dq: k,i,j=dq.popleft() if k>dist[i][j]: continue if i==ti and j==tj: ok=True break for di in dirs: for dj in dirs: if di==dj==0: continue ni,nj=i+di,j+dj if not (0<=ni<H and 0<=nj<W): continue if A[ni][nj]=='#': continue if abs(di)+abs(dj)==1: append=dq.appendleft nk=k else: append=dq.append nk=k+1 if k>=dist[ni][nj]: continue dist[ni][nj]=nk append((nk,ni,nj)) if ok: ans=dist[ti][tj] else: ans=-1 print(ans)
import sys from collections import deque H,W=list(map(int,input().split())) si,sj=[int(x)-1 for x in input().split()] ti,tj=[int(x)-1 for x in input().split()] A=[[*next(sys.stdin)] for _ in range(H)] N=-1 for i in range(H): for j in range(W): if A[i][j]!='.': continue N+=1 stk=[(i,j)] while stk: ii,jj=stk.pop() A[ii][jj]=N for ni,nj in (ii-1,jj),(ii,jj+1),(ii+1,jj),(ii,jj-1): if not (0<=ni<H and 0<=nj<W): continue if A[ni][nj]!='.': continue stk.append((ni,nj)) s=t=-1 dirs=[-2,-1,0,1,2] adj=[{*()} for _ in range(N+1)] for i in range(H): for j in range(W): u=A[i][j] if u=='#': continue if i==si and j==sj: s=u elif i==ti and j==tj: t=u for di in dirs: for dj in dirs: if di==dj==0: continue ni,nj=i+di,j+dj if not (0<=ni<H and 0<=nj<W): continue v=A[ni][nj] if v=='#': continue if u!=v: adj[u].add(v) adj[v].add(u) que=deque() que.append(s) vis={s} m=-1 ok=False while que: m+=1 for _ in range(len(que)): u=que.popleft() if u==t: ok=True break for v in adj[u]: if v in vis: continue vis.add(v) que.append(v) if ok: break if ok: print(m) else: print((-1))
47
75
1,048
1,737
import sys from collections import deque H, W = list(map(int, input().split())) si, sj = [int(x) - 1 for x in input().split()] ti, tj = [int(x) - 1 for x in input().split()] A = list(sys.stdin) dirs = [-2, -1, 0, 1, 2] dist = [[10**6] * W for _ in range(H)] dist[si][sj] = 0 dq = deque() dq.append((0, si, sj)) ok = False while dq: k, i, j = dq.popleft() if k > dist[i][j]: continue if i == ti and j == tj: ok = True break for di in dirs: for dj in dirs: if di == dj == 0: continue ni, nj = i + di, j + dj if not (0 <= ni < H and 0 <= nj < W): continue if A[ni][nj] == "#": continue if abs(di) + abs(dj) == 1: append = dq.appendleft nk = k else: append = dq.append nk = k + 1 if k >= dist[ni][nj]: continue dist[ni][nj] = nk append((nk, ni, nj)) if ok: ans = dist[ti][tj] else: ans = -1 print(ans)
import sys from collections import deque H, W = list(map(int, input().split())) si, sj = [int(x) - 1 for x in input().split()] ti, tj = [int(x) - 1 for x in input().split()] A = [[*next(sys.stdin)] for _ in range(H)] N = -1 for i in range(H): for j in range(W): if A[i][j] != ".": continue N += 1 stk = [(i, j)] while stk: ii, jj = stk.pop() A[ii][jj] = N for ni, nj in (ii - 1, jj), (ii, jj + 1), (ii + 1, jj), (ii, jj - 1): if not (0 <= ni < H and 0 <= nj < W): continue if A[ni][nj] != ".": continue stk.append((ni, nj)) s = t = -1 dirs = [-2, -1, 0, 1, 2] adj = [{*()} for _ in range(N + 1)] for i in range(H): for j in range(W): u = A[i][j] if u == "#": continue if i == si and j == sj: s = u elif i == ti and j == tj: t = u for di in dirs: for dj in dirs: if di == dj == 0: continue ni, nj = i + di, j + dj if not (0 <= ni < H and 0 <= nj < W): continue v = A[ni][nj] if v == "#": continue if u != v: adj[u].add(v) adj[v].add(u) que = deque() que.append(s) vis = {s} m = -1 ok = False while que: m += 1 for _ in range(len(que)): u = que.popleft() if u == t: ok = True break for v in adj[u]: if v in vis: continue vis.add(v) que.append(v) if ok: break if ok: print(m) else: print((-1))
false
37.333333
[ "-A = list(sys.stdin)", "+A = [[*next(sys.stdin)] for _ in range(H)]", "+N = -1", "+for i in range(H):", "+ for j in range(W):", "+ if A[i][j] != \".\":", "+ continue", "+ N += 1", "+ stk = [(i, j)]", "+ while stk:", "+ ii, jj = stk.pop()", "+ A[ii][jj] = N", "+ for ni, nj in (ii - 1, jj), (ii, jj + 1), (ii + 1, jj), (ii, jj - 1):", "+ if not (0 <= ni < H and 0 <= nj < W):", "+ continue", "+ if A[ni][nj] != \".\":", "+ continue", "+ stk.append((ni, nj))", "+s = t = -1", "-dist = [[10**6] * W for _ in range(H)]", "-dist[si][sj] = 0", "-dq = deque()", "-dq.append((0, si, sj))", "+adj = [{*()} for _ in range(N + 1)]", "+for i in range(H):", "+ for j in range(W):", "+ u = A[i][j]", "+ if u == \"#\":", "+ continue", "+ if i == si and j == sj:", "+ s = u", "+ elif i == ti and j == tj:", "+ t = u", "+ for di in dirs:", "+ for dj in dirs:", "+ if di == dj == 0:", "+ continue", "+ ni, nj = i + di, j + dj", "+ if not (0 <= ni < H and 0 <= nj < W):", "+ continue", "+ v = A[ni][nj]", "+ if v == \"#\":", "+ continue", "+ if u != v:", "+ adj[u].add(v)", "+ adj[v].add(u)", "+que = deque()", "+que.append(s)", "+vis = {s}", "+m = -1", "-while dq:", "- k, i, j = dq.popleft()", "- if k > dist[i][j]:", "- continue", "- if i == ti and j == tj:", "- ok = True", "+while que:", "+ m += 1", "+ for _ in range(len(que)):", "+ u = que.popleft()", "+ if u == t:", "+ ok = True", "+ break", "+ for v in adj[u]:", "+ if v in vis:", "+ continue", "+ vis.add(v)", "+ que.append(v)", "+ if ok:", "- for di in dirs:", "- for dj in dirs:", "- if di == dj == 0:", "- continue", "- ni, nj = i + di, j + dj", "- if not (0 <= ni < H and 0 <= nj < W):", "- continue", "- if A[ni][nj] == \"#\":", "- continue", "- if abs(di) + abs(dj) == 1:", "- append = dq.appendleft", "- nk = k", "- else:", "- append = dq.append", "- nk = k + 1", "- if k >= dist[ni][nj]:", "- continue", "- dist[ni][nj] = nk", "- append((nk, ni, nj))", "- ans = dist[ti][tj]", "+ print(m)", "- ans = -1", "-print(ans)", "+ print((-1))" ]
false
0.038372
0.040389
0.95006
[ "s427956692", "s996247067" ]
u357230322
p02713
python
s485022710
s549967397
1,557
1,096
188,732
69,864
Accepted
Accepted
29.61
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) x=0 k=int(eval(input())) r = list(range(1, k + 1)) x = sum([gcd(a, b, c) for a in r for b in r for c in r]) print(x)
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) x=0 k=int(eval(input())) for i in range(1,k+1): for j in range(1,k+1): for l in range(1,k+1): x+=gcd(i,j,l) print(x)
11
15
214
238
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) x = 0 k = int(eval(input())) r = list(range(1, k + 1)) x = sum([gcd(a, b, c) for a in r for b in r for c in r]) print(x)
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) x = 0 k = int(eval(input())) for i in range(1, k + 1): for j in range(1, k + 1): for l in range(1, k + 1): x += gcd(i, j, l) print(x)
false
26.666667
[ "-r = list(range(1, k + 1))", "-x = sum([gcd(a, b, c) for a in r for b in r for c in r])", "+for i in range(1, k + 1):", "+ for j in range(1, k + 1):", "+ for l in range(1, k + 1):", "+ x += gcd(i, j, l)" ]
false
0.045008
0.034246
1.314238
[ "s485022710", "s549967397" ]
u754022296
p03634
python
s727416408
s242581462
1,541
1,396
137,936
131,632
Accepted
Accepted
9.41
import sys sys.setrecursionlimit(10**7) n = int(eval(input())) l = [[] for _ in range(n)] for _ in range(n-1): a, b, c = list(map(int, input().split())) l[a-1].append([b-1, c]) l[b-1].append([a-1, c]) q, k = list(map(int, input().split())) dist = [-1]*n dist[k-1] = 0 def dfs(v): for nv, c in l[v]: if dist[nv] == -1: dist[nv] = dist[v]+c dfs(nv) dfs(k-1) for _ in range(q): x, y = list(map(int, input().split())) print((dist[x-1] + dist[y-1]))
import sys sys.setrecursionlimit(10**7) n = int(eval(input())) l = [[] for _ in range(n)] for _ in range(n-1): a, b, c = list(map(int, input().split())) l[a-1].append((b-1, c)) l[b-1].append((a-1, c)) q, k = list(map(int, input().split())) dist = [-1]*n dist[k-1] = 0 def dfs(v): for nv, c in l[v]: if dist[nv] == -1: dist[nv] = dist[v]+c dfs(nv) dfs(k-1) for _ in range(q): x, y = list(map(int, input().split())) print((dist[x-1] + dist[y-1]))
21
21
467
468
import sys sys.setrecursionlimit(10**7) n = int(eval(input())) l = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = list(map(int, input().split())) l[a - 1].append([b - 1, c]) l[b - 1].append([a - 1, c]) q, k = list(map(int, input().split())) dist = [-1] * n dist[k - 1] = 0 def dfs(v): for nv, c in l[v]: if dist[nv] == -1: dist[nv] = dist[v] + c dfs(nv) dfs(k - 1) for _ in range(q): x, y = list(map(int, input().split())) print((dist[x - 1] + dist[y - 1]))
import sys sys.setrecursionlimit(10**7) n = int(eval(input())) l = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = list(map(int, input().split())) l[a - 1].append((b - 1, c)) l[b - 1].append((a - 1, c)) q, k = list(map(int, input().split())) dist = [-1] * n dist[k - 1] = 0 def dfs(v): for nv, c in l[v]: if dist[nv] == -1: dist[nv] = dist[v] + c dfs(nv) dfs(k - 1) for _ in range(q): x, y = list(map(int, input().split())) print((dist[x - 1] + dist[y - 1]))
false
0
[ "- l[a - 1].append([b - 1, c])", "- l[b - 1].append([a - 1, c])", "+ l[a - 1].append((b - 1, c))", "+ l[b - 1].append((a - 1, c))" ]
false
0.084899
0.043173
1.96651
[ "s727416408", "s242581462" ]
u606045429
p03296
python
s236419901
s692497044
19
17
3,316
3,060
Accepted
Accepted
10.53
N = int(eval(input())) a = [int(i) for i in input().split()] result = 0 prev = -1 count = 1 for i in range(len(a)): if a[i] == prev: count += 1 if i == N - 1: result += count // 2 else: result += count // 2 prev = a[i] count = 1 print(result)
from itertools import groupby N, *A = list(map(int, open(0).read().split())) print((sum(len(tuple(v)) // 2 for _, v in groupby(A))))
17
4
314
129
N = int(eval(input())) a = [int(i) for i in input().split()] result = 0 prev = -1 count = 1 for i in range(len(a)): if a[i] == prev: count += 1 if i == N - 1: result += count // 2 else: result += count // 2 prev = a[i] count = 1 print(result)
from itertools import groupby N, *A = list(map(int, open(0).read().split())) print((sum(len(tuple(v)) // 2 for _, v in groupby(A))))
false
76.470588
[ "-N = int(eval(input()))", "-a = [int(i) for i in input().split()]", "-result = 0", "-prev = -1", "-count = 1", "-for i in range(len(a)):", "- if a[i] == prev:", "- count += 1", "- if i == N - 1:", "- result += count // 2", "- else:", "- result += count // 2", "- prev = a[i]", "- count = 1", "-print(result)", "+from itertools import groupby", "+", "+N, *A = list(map(int, open(0).read().split()))", "+print((sum(len(tuple(v)) // 2 for _, v in groupby(A))))" ]
false
0.061368
0.071791
0.854807
[ "s236419901", "s692497044" ]
u151005508
p02861
python
s898540789
s220403430
377
18
3,064
3,064
Accepted
Accepted
95.23
import itertools import math n=int(eval(input())) lst=[None]*n for i in range(n): lst[i]=tuple(map(int, input().split())) total=0 for v in itertools.permutations(lst): for i in range(n-1): dis=math.sqrt( (v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2 ) total+=dis print((total/math.factorial(n)))
import itertools import math N=int(eval(input())) lst=[None]*N for i in range(N): lst[i]=tuple(map(int, input().split())) total=0 for i in range(N-1): for j in range(i+1,N): total+=math.sqrt( (lst[i][0]-lst[j][0])**2 + (lst[i][1]-lst[j][1])**2 ) ave=total*2/N print(ave)
13
13
327
293
import itertools import math n = int(eval(input())) lst = [None] * n for i in range(n): lst[i] = tuple(map(int, input().split())) total = 0 for v in itertools.permutations(lst): for i in range(n - 1): dis = math.sqrt((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2) total += dis print((total / math.factorial(n)))
import itertools import math N = int(eval(input())) lst = [None] * N for i in range(N): lst[i] = tuple(map(int, input().split())) total = 0 for i in range(N - 1): for j in range(i + 1, N): total += math.sqrt((lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2) ave = total * 2 / N print(ave)
false
0
[ "-n = int(eval(input()))", "-lst = [None] * n", "-for i in range(n):", "+N = int(eval(input()))", "+lst = [None] * N", "+for i in range(N):", "-for v in itertools.permutations(lst):", "- for i in range(n - 1):", "- dis = math.sqrt((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2)", "- total += dis", "-print((total / math.factorial(n)))", "+for i in range(N - 1):", "+ for j in range(i + 1, N):", "+ total += math.sqrt((lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2)", "+ave = total * 2 / N", "+print(ave)" ]
false
0.106479
0.039934
2.666372
[ "s898540789", "s220403430" ]