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
u597374218
p03457
python
s908733300
s126833504
395
336
27,380
3,060
Accepted
Accepted
14.94
N=int(eval(input())) txy=[list(map(int,input().split())) for i in range(N)] ans=0 for i in range(N): t,x,y=txy[i][0],txy[i][1],txy[i][2] if x+y<=t and t%2==(x+y)%2:ans+=1 print(("Yes" if ans==N else "No"))
N=int(eval(input())) count=0 for i in range(N): t,x,y=list(map(int,input().split())) if x+y<=t and t%2==(x+y)%2:count+=1 print(("Yes" if count==N else "No"))
7
6
211
156
N = int(eval(input())) txy = [list(map(int, input().split())) for i in range(N)] ans = 0 for i in range(N): t, x, y = txy[i][0], txy[i][1], txy[i][2] if x + y <= t and t % 2 == (x + y) % 2: ans += 1 print(("Yes" if ans == N else "No"))
N = int(eval(input())) count = 0 for i in range(N): t, x, y = list(map(int, input().split())) if x + y <= t and t % 2 == (x + y) % 2: count += 1 print(("Yes" if count == N else "No"))
false
14.285714
[ "-txy = [list(map(int, input().split())) for i in range(N)]", "-ans = 0", "+count = 0", "- t, x, y = txy[i][0], txy[i][1], txy[i][2]", "+ t, x, y = list(map(int, input().split()))", "- ans += 1", "-print((\"Yes\" if ans == N else \"No\"))", "+ count += 1", "+print((\"Yes\" if count == N else \"No\"))" ]
false
0.066396
0.067813
0.979098
[ "s908733300", "s126833504" ]
u905203728
p03786
python
s031750834
s496017514
227
115
14,956
14,432
Accepted
Accepted
49.34
import copy n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=copy.deepcopy(A) for i in range(1,n): B[i]=B[i]+B[i-1] cnt=1 for i in reversed(list(range(n-1))): if B[i]*2>=A[i+1]: cnt +=1 else:break print(cnt)
n=int(eval(input())) A=sorted(list(map(int,input().split()))) sum_A=sum(A) cnt=1 for i in reversed(list(range(n))): sum_A -=A[i] if sum_A*2>=A[i]: cnt +=1 else:break print(cnt)
13
10
243
193
import copy n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = copy.deepcopy(A) for i in range(1, n): B[i] = B[i] + B[i - 1] cnt = 1 for i in reversed(list(range(n - 1))): if B[i] * 2 >= A[i + 1]: cnt += 1 else: break print(cnt)
n = int(eval(input())) A = sorted(list(map(int, input().split()))) sum_A = sum(A) cnt = 1 for i in reversed(list(range(n))): sum_A -= A[i] if sum_A * 2 >= A[i]: cnt += 1 else: break print(cnt)
false
23.076923
[ "-import copy", "-", "-B = copy.deepcopy(A)", "-for i in range(1, n):", "- B[i] = B[i] + B[i - 1]", "+sum_A = sum(A)", "-for i in reversed(list(range(n - 1))):", "- if B[i] * 2 >= A[i + 1]:", "+for i in reversed(list(range(n))):", "+ sum_A -= A[i]", "+ if sum_A * 2 >= A[i]:" ]
false
0.04369
0.034514
1.26589
[ "s031750834", "s496017514" ]
u945181840
p02802
python
s708302105
s684814523
133
123
4,596
4,596
Accepted
Accepted
7.52
import sys read = sys.stdin.read readline = sys.stdin.readline N, M = list(map(int, readline().split())) WA = [0] * (N + 1) AC = [False] * (N + 1) for _ in range(M): p, S = readline().split() p = int(p) if AC[p]: continue if S == 'AC': AC[p] = True else: WA[p] += 1 for i in range(1, N + 1): if not AC[i]: WA[i] = 0 print((sum(AC), sum(WA)))
import sys read = sys.stdin.read readline = sys.stdin.readline N, M = list(map(int, readline().split())) WA = [0] * (N + 1) wa = 0 AC = [False] * (N + 1) for _ in range(M): p, S = readline().split() p = int(p) if AC[p]: continue if S == 'AC': AC[p] = True wa += WA[p] else: WA[p] += 1 print((sum(AC), wa))
25
23
420
377
import sys read = sys.stdin.read readline = sys.stdin.readline N, M = list(map(int, readline().split())) WA = [0] * (N + 1) AC = [False] * (N + 1) for _ in range(M): p, S = readline().split() p = int(p) if AC[p]: continue if S == "AC": AC[p] = True else: WA[p] += 1 for i in range(1, N + 1): if not AC[i]: WA[i] = 0 print((sum(AC), sum(WA)))
import sys read = sys.stdin.read readline = sys.stdin.readline N, M = list(map(int, readline().split())) WA = [0] * (N + 1) wa = 0 AC = [False] * (N + 1) for _ in range(M): p, S = readline().split() p = int(p) if AC[p]: continue if S == "AC": AC[p] = True wa += WA[p] else: WA[p] += 1 print((sum(AC), wa))
false
8
[ "+wa = 0", "+ wa += WA[p]", "-for i in range(1, N + 1):", "- if not AC[i]:", "- WA[i] = 0", "-print((sum(AC), sum(WA)))", "+print((sum(AC), wa))" ]
false
0.076828
0.044804
1.714756
[ "s708302105", "s684814523" ]
u232852711
p03312
python
s827304890
s473959021
969
720
25,676
24,684
Accepted
Accepted
25.7
n = int(eval(input())) a = list(map(int, input().split())) cumsum = [a[0]] for i in range(1, n): cumsum.append(cumsum[i-1] + a[i]) i, k = 0, 2 ans = 10**18 for j in range(1, n-2): while i < j: p = cumsum[i] q = cumsum[j] - cumsum[i] p_new = cumsum[i+1] q_new = cumsum[j] - cumsum[i+1] if abs(q_new - p_new) > abs(q - p): break else: i += 1 while k < n-1: r = cumsum[k] - cumsum[j] s = cumsum[n-1] - cumsum[k] r_new = cumsum[k+1] - cumsum[j] s_new = cumsum[n-1] - cumsum[k+1] if abs(s_new - r_new) > abs(s - r): break else: k += 1 pqrs = [p, q, r, s] ans = min(ans, abs(max(pqrs) - min(pqrs))) # print(i, j, k, ans, pqrs) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) i, k = 0, 2 p, q, r, s = 0, a[0], a[1], sum(a[2:]) ans = sum(a) for j in range(1, n-2): q += a[j] while abs((q-a[i]) - (p+a[i])) < abs(q - p): p += a[i] q -= a[i] i += 1 r -= a[j] while abs((s-a[k]) - (r+a[k])) < abs(s - r): r += a[k] s -= a[k] k += 1 pqrs = [p, q, r, s] ans = min(ans, abs(max(pqrs) - min(pqrs))) # print(i, j, k, ans, pqrs) print(ans)
35
24
837
516
n = int(eval(input())) a = list(map(int, input().split())) cumsum = [a[0]] for i in range(1, n): cumsum.append(cumsum[i - 1] + a[i]) i, k = 0, 2 ans = 10**18 for j in range(1, n - 2): while i < j: p = cumsum[i] q = cumsum[j] - cumsum[i] p_new = cumsum[i + 1] q_new = cumsum[j] - cumsum[i + 1] if abs(q_new - p_new) > abs(q - p): break else: i += 1 while k < n - 1: r = cumsum[k] - cumsum[j] s = cumsum[n - 1] - cumsum[k] r_new = cumsum[k + 1] - cumsum[j] s_new = cumsum[n - 1] - cumsum[k + 1] if abs(s_new - r_new) > abs(s - r): break else: k += 1 pqrs = [p, q, r, s] ans = min(ans, abs(max(pqrs) - min(pqrs))) # print(i, j, k, ans, pqrs) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) i, k = 0, 2 p, q, r, s = 0, a[0], a[1], sum(a[2:]) ans = sum(a) for j in range(1, n - 2): q += a[j] while abs((q - a[i]) - (p + a[i])) < abs(q - p): p += a[i] q -= a[i] i += 1 r -= a[j] while abs((s - a[k]) - (r + a[k])) < abs(s - r): r += a[k] s -= a[k] k += 1 pqrs = [p, q, r, s] ans = min(ans, abs(max(pqrs) - min(pqrs))) # print(i, j, k, ans, pqrs) print(ans)
false
31.428571
[ "-cumsum = [a[0]]", "-for i in range(1, n):", "- cumsum.append(cumsum[i - 1] + a[i])", "-ans = 10**18", "+p, q, r, s = 0, a[0], a[1], sum(a[2:])", "+ans = sum(a)", "- while i < j:", "- p = cumsum[i]", "- q = cumsum[j] - cumsum[i]", "- p_new = cumsum[i + 1]", "- q_new = cumsum[j] - cumsum[i + 1]", "- if abs(q_new - p_new) > abs(q - p):", "- break", "- else:", "- i += 1", "- while k < n - 1:", "- r = cumsum[k] - cumsum[j]", "- s = cumsum[n - 1] - cumsum[k]", "- r_new = cumsum[k + 1] - cumsum[j]", "- s_new = cumsum[n - 1] - cumsum[k + 1]", "- if abs(s_new - r_new) > abs(s - r):", "- break", "- else:", "- k += 1", "+ q += a[j]", "+ while abs((q - a[i]) - (p + a[i])) < abs(q - p):", "+ p += a[i]", "+ q -= a[i]", "+ i += 1", "+ r -= a[j]", "+ while abs((s - a[k]) - (r + a[k])) < abs(s - r):", "+ r += a[k]", "+ s -= a[k]", "+ k += 1" ]
false
0.065776
0.037422
1.75766
[ "s827304890", "s473959021" ]
u588341295
p03550
python
s404901944
s048181368
1,022
832
50,140
46,852
Accepted
Accepted
18.59
# -*- coding: utf-8 -*- """ 参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/ ・ミニマックス法 ・メモ化再帰 ・先手と後手にそれぞれのメモを作る """ import sys from collections import defaultdict # 再帰呼び出しの回数制限(デフォルト1000) sys.setrecursionlimit(10 ** 9) N, Z, W = list(map(int, input().split())) aN = list(map(int, input().split())) # 先手番用メモ[残り山札数][相手のスコア] = このルートでのmax # 後手番用メモ[残り山札数][相手のスコア] = このルートでのmin memo1 = [defaultdict(int) for _ in range(N+1)] memo2 = [defaultdict(int) for _ in range(N+1)] def dfs(turn, rest, x, y): if rest == 0: return abs(x - y) # 先手番 if turn % 2 == 0: # 既に見た局面ならメモの内容を返す if memo1[rest][y]: return memo1[rest][y] mx = -1 for i in range(N-rest, N): x = aN[i] idx = i+1 mx = max(dfs(turn+1, N-idx, x, y), mx) # ここより深い所を探し終わったので結果をメモする memo1[rest][y] = mx return mx # 後手番 else: if memo2[rest][x]: return memo2[rest][x] mn = float('inf') for i in range(N-rest, N): y = aN[i] idx = i+1 mn = min(dfs(turn+1, N-idx, x, y), mn) memo2[rest][x] = mn return mn print((dfs(0, N, Z, W)))
# -*- coding: utf-8 -*- """ 参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/    https://atcoder.jp/contests/abc078/submissions/3854338 ・ミニマックス法 ・メモ化再帰 ・メモの持ち方をシンプルにした版 """ import sys from collections import defaultdict # 再帰呼び出しの回数制限(デフォルト1000) sys.setrecursionlimit(10 ** 9) N, Z, W = list(map(int, input().split())) aN = list(map(int, input().split())) # メモ[手番][残り山札数] = このルートでのmax,min memo = [[0] * (N+1) for _ in range(2)] def dfs(turn, rest, x, y): if rest == 0: return abs(x - y) # 先手番 if turn % 2 == 0: # 既に見た局面ならメモの内容を返す if memo[0][rest]: return memo[0][rest] mx = -1 for i in range(N-rest, N): x = aN[i] idx = i+1 mx = max(dfs(turn+1, N-idx, x, y), mx) # ここより深い所を探し終わったので結果をメモする memo[0][rest] = mx return mx # 後手番 else: if memo[1][rest]: return memo[1][rest] mn = float('inf') for i in range(N-rest, N): y = aN[i] idx = i+1 mn = min(dfs(turn+1, N-idx, x, y), mn) memo[1][rest] = mn return mn print((dfs(0, N, Z, W)))
52
51
1,250
1,204
# -*- coding: utf-8 -*- """ 参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/ ・ミニマックス法 ・メモ化再帰 ・先手と後手にそれぞれのメモを作る """ import sys from collections import defaultdict # 再帰呼び出しの回数制限(デフォルト1000) sys.setrecursionlimit(10**9) N, Z, W = list(map(int, input().split())) aN = list(map(int, input().split())) # 先手番用メモ[残り山札数][相手のスコア] = このルートでのmax # 後手番用メモ[残り山札数][相手のスコア] = このルートでのmin memo1 = [defaultdict(int) for _ in range(N + 1)] memo2 = [defaultdict(int) for _ in range(N + 1)] def dfs(turn, rest, x, y): if rest == 0: return abs(x - y) # 先手番 if turn % 2 == 0: # 既に見た局面ならメモの内容を返す if memo1[rest][y]: return memo1[rest][y] mx = -1 for i in range(N - rest, N): x = aN[i] idx = i + 1 mx = max(dfs(turn + 1, N - idx, x, y), mx) # ここより深い所を探し終わったので結果をメモする memo1[rest][y] = mx return mx # 後手番 else: if memo2[rest][x]: return memo2[rest][x] mn = float("inf") for i in range(N - rest, N): y = aN[i] idx = i + 1 mn = min(dfs(turn + 1, N - idx, x, y), mn) memo2[rest][x] = mn return mn print((dfs(0, N, Z, W)))
# -*- coding: utf-8 -*- """ 参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/    https://atcoder.jp/contests/abc078/submissions/3854338 ・ミニマックス法 ・メモ化再帰 ・メモの持ち方をシンプルにした版 """ import sys from collections import defaultdict # 再帰呼び出しの回数制限(デフォルト1000) sys.setrecursionlimit(10**9) N, Z, W = list(map(int, input().split())) aN = list(map(int, input().split())) # メモ[手番][残り山札数] = このルートでのmax,min memo = [[0] * (N + 1) for _ in range(2)] def dfs(turn, rest, x, y): if rest == 0: return abs(x - y) # 先手番 if turn % 2 == 0: # 既に見た局面ならメモの内容を返す if memo[0][rest]: return memo[0][rest] mx = -1 for i in range(N - rest, N): x = aN[i] idx = i + 1 mx = max(dfs(turn + 1, N - idx, x, y), mx) # ここより深い所を探し終わったので結果をメモする memo[0][rest] = mx return mx # 後手番 else: if memo[1][rest]: return memo[1][rest] mn = float("inf") for i in range(N - rest, N): y = aN[i] idx = i + 1 mn = min(dfs(turn + 1, N - idx, x, y), mn) memo[1][rest] = mn return mn print((dfs(0, N, Z, W)))
false
1.923077
[ "+   https://atcoder.jp/contests/abc078/submissions/3854338", "-・先手と後手にそれぞれのメモを作る", "+・メモの持ち方をシンプルにした版", "-# 先手番用メモ[残り山札数][相手のスコア] = このルートでのmax", "-# 後手番用メモ[残り山札数][相手のスコア] = このルートでのmin", "-memo1 = [defaultdict(int) for _ in range(N + 1)]", "-memo2 = [defaultdict(int) for _ in range(N + 1)]", "+# メモ[手番][残り山札数] = このルートでのmax,min", "+memo = [[0] * (N + 1) for _ in range(2)]", "- if memo1[rest][y]:", "- return memo1[rest][y]", "+ if memo[0][rest]:", "+ return memo[0][rest]", "- memo1[rest][y] = mx", "+ memo[0][rest] = mx", "- if memo2[rest][x]:", "- return memo2[rest][x]", "+ if memo[1][rest]:", "+ return memo[1][rest]", "- memo2[rest][x] = mn", "+ memo[1][rest] = mn" ]
false
0.046477
0.129895
0.357806
[ "s404901944", "s048181368" ]
u150984829
p00447
python
s311786368
s675475771
940
90
5,896
6,052
Accepted
Accepted
90.43
for e in iter(input,'0'): a=list(tuple(map(int,input().split())) for _ in range(int(e))) s,t=a[0] b=[tuple(map(int,input().split())) for _ in range(int(eval(input())))] for x,y in b: flag = True for u,v in a[1:]: if(x+u-s,y+v-t)not in b: flag = False break if flag == True: print((x - s, y - t)) break
for e in iter(input,'0'): a=list(tuple(map(int,input().split())) for _ in range(int(e))) s,t=a[0] b={tuple(map(int,input().split())) for _ in range(int(eval(input())))} for x,y in b: f=1 for u,v in a[1:]: if(x+u-s,y+v-t)not in b:f=0;break if f:print((x-s,y-t));break
13
9
333
280
for e in iter(input, "0"): a = list(tuple(map(int, input().split())) for _ in range(int(e))) s, t = a[0] b = [tuple(map(int, input().split())) for _ in range(int(eval(input())))] for x, y in b: flag = True for u, v in a[1:]: if (x + u - s, y + v - t) not in b: flag = False break if flag == True: print((x - s, y - t)) break
for e in iter(input, "0"): a = list(tuple(map(int, input().split())) for _ in range(int(e))) s, t = a[0] b = {tuple(map(int, input().split())) for _ in range(int(eval(input())))} for x, y in b: f = 1 for u, v in a[1:]: if (x + u - s, y + v - t) not in b: f = 0 break if f: print((x - s, y - t)) break
false
30.769231
[ "- b = [tuple(map(int, input().split())) for _ in range(int(eval(input())))]", "+ b = {tuple(map(int, input().split())) for _ in range(int(eval(input())))}", "- flag = True", "+ f = 1", "- flag = False", "+ f = 0", "- if flag == True:", "+ if f:" ]
false
0.04736
0.043494
1.088896
[ "s311786368", "s675475771" ]
u547608423
p03944
python
s299687444
s574482216
20
18
3,064
3,064
Accepted
Accepted
10
W,H,N=list(map(int,input().split())) xya=[list(map(int,input().split())) for _ in range(N)] x_l=0 x_h=W y_l=0 y_h=H for i in xya: if i[2]==1 and x_l<i[0]: x_l=i[0] elif i[2]==2 and x_h>i[0]: x_h=i[0] elif i[2]==3 and y_l<i[1]: y_l=i[1] elif i[2]==4 and y_h>i[1]: y_h=i[1] print((max(0,x_h-x_l)*max(0,y_h-y_l)))
W,H,N=list(map(int,input().split())) x_l=0 x_r=W y_h=H y_l=0 for i in range(N): x,y,a=list(map(int,input().split())) if a==1: x_l=max(x_l,x) elif a==2: x_r=min(x_r,x) elif a==3: y_l=max(y_l,y) else: y_h=min(y_h,y) #print(x_l,x_r,y_h,y_l) print((max(x_r-x_l,0)*max(y_h-y_l,0)))
19
20
371
336
W, H, N = list(map(int, input().split())) xya = [list(map(int, input().split())) for _ in range(N)] x_l = 0 x_h = W y_l = 0 y_h = H for i in xya: if i[2] == 1 and x_l < i[0]: x_l = i[0] elif i[2] == 2 and x_h > i[0]: x_h = i[0] elif i[2] == 3 and y_l < i[1]: y_l = i[1] elif i[2] == 4 and y_h > i[1]: y_h = i[1] print((max(0, x_h - x_l) * max(0, y_h - y_l)))
W, H, N = list(map(int, input().split())) x_l = 0 x_r = W y_h = H y_l = 0 for i in range(N): x, y, a = list(map(int, input().split())) if a == 1: x_l = max(x_l, x) elif a == 2: x_r = min(x_r, x) elif a == 3: y_l = max(y_l, y) else: y_h = min(y_h, y) # print(x_l,x_r,y_h,y_l) print((max(x_r - x_l, 0) * max(y_h - y_l, 0)))
false
5
[ "-xya = [list(map(int, input().split())) for _ in range(N)]", "-x_h = W", "+x_r = W", "+y_h = H", "-y_h = H", "-for i in xya:", "- if i[2] == 1 and x_l < i[0]:", "- x_l = i[0]", "- elif i[2] == 2 and x_h > i[0]:", "- x_h = i[0]", "- elif i[2] == 3 and y_l < i[1]:", "- y_l = i[1]", "- elif i[2] == 4 and y_h > i[1]:", "- y_h = i[1]", "-print((max(0, x_h - x_l) * max(0, y_h - y_l)))", "+for i in range(N):", "+ x, y, a = list(map(int, input().split()))", "+ if a == 1:", "+ x_l = max(x_l, x)", "+ elif a == 2:", "+ x_r = min(x_r, x)", "+ elif a == 3:", "+ y_l = max(y_l, y)", "+ else:", "+ y_h = min(y_h, y)", "+# print(x_l,x_r,y_h,y_l)", "+print((max(x_r - x_l, 0) * max(y_h - y_l, 0)))" ]
false
0.033491
0.033508
0.999494
[ "s299687444", "s574482216" ]
u094999522
p02688
python
s139499145
s867744484
24
22
9,208
9,184
Accepted
Accepted
8.33
(n,k),*p = [[*list(map(int, i.split()))] for i in open(0)] a = sum([p[2*i+1] for i in range(k)],[]) print((n - len(set(a))))
n,k = list(map(int, input().split())) a = set() for i in [0]*k: _ = eval(input()) a = a | set([*list(map(int, input().split()))]) print((n - len(a)))
3
6
118
142
(n, k), *p = [[*list(map(int, i.split()))] for i in open(0)] a = sum([p[2 * i + 1] for i in range(k)], []) print((n - len(set(a))))
n, k = list(map(int, input().split())) a = set() for i in [0] * k: _ = eval(input()) a = a | set([*list(map(int, input().split()))]) print((n - len(a)))
false
50
[ "-(n, k), *p = [[*list(map(int, i.split()))] for i in open(0)]", "-a = sum([p[2 * i + 1] for i in range(k)], [])", "-print((n - len(set(a))))", "+n, k = list(map(int, input().split()))", "+a = set()", "+for i in [0] * k:", "+ _ = eval(input())", "+ a = a | set([*list(map(int, input().split()))])", "+print((n - len(a)))" ]
false
0.050651
0.047193
1.073273
[ "s139499145", "s867744484" ]
u710921979
p03495
python
s135219787
s393128412
120
102
35,892
35,996
Accepted
Accepted
15
import collections from collections import OrderedDict count=0 N,K=list(map(int,input().split())) ball=list(map(str,input().split())) c=sorted(collections.Counter(ball).values()) n=len(c)-K if n==0: print(count) else: for i in range(n): count+=c[i] print(count)
import collections N,K=list(map(int,input().split())) c=sorted(collections.Counter(list(map(str,input().split()))).values()) print((sum(c[:-K])))
13
4
287
140
import collections from collections import OrderedDict count = 0 N, K = list(map(int, input().split())) ball = list(map(str, input().split())) c = sorted(collections.Counter(ball).values()) n = len(c) - K if n == 0: print(count) else: for i in range(n): count += c[i] print(count)
import collections N, K = list(map(int, input().split())) c = sorted(collections.Counter(list(map(str, input().split()))).values()) print((sum(c[:-K])))
false
69.230769
[ "-from collections import OrderedDict", "-count = 0", "-ball = list(map(str, input().split()))", "-c = sorted(collections.Counter(ball).values())", "-n = len(c) - K", "-if n == 0:", "- print(count)", "-else:", "- for i in range(n):", "- count += c[i]", "- print(count)", "+c = sorted(collections.Counter(list(map(str, input().split()))).values())", "+print((sum(c[:-K])))" ]
false
0.091859
0.04722
1.945364
[ "s135219787", "s393128412" ]
u546285759
p00638
python
s581246171
s930198359
60
40
7,680
7,836
Accepted
Accepted
33.33
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: break cnt += 1 print(("Yes" if cnt == n else "No"))
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: cnt = 1 break print(("No" if cnt else "Yes"))
12
12
316
314
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: break cnt += 1 print(("Yes" if cnt == n else "No"))
while True: n = int(eval(input())) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cnt = total = 0 for a, b in z: total += a if total > b: cnt = 1 break print(("No" if cnt else "Yes"))
false
0
[ "+ cnt = 1", "- cnt += 1", "- print((\"Yes\" if cnt == n else \"No\"))", "+ print((\"No\" if cnt else \"Yes\"))" ]
false
0.07352
0.036027
2.040668
[ "s581246171", "s930198359" ]
u309141201
p03160
python
s049233007
s321454441
157
132
13,904
13,980
Accepted
Accepted
15.92
N = int(eval(input())) h = list(map(int, input().split())) # print(N, h) # dpの最小値を変更する関数 def chmin(a, b): if a > b: return b else: return a # 無限大の値 f_inf = float('inf') # DP テーブルを初期化 (最小化問題なので INF に初期化) dp = [f_inf] * (10 ** 5 + 10) # 初期条件 dp[0] = 0 # 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]| # 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]| for i in range(1, N): dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) # 一番目の足場では一つ前しか存在しない if i > 1: dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [float('inf')]*N dp[0] = 0 for i in range(1, N): if i == 1: dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) else: dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2])) print((dp[N-1]))
29
11
584
295
N = int(eval(input())) h = list(map(int, input().split())) # print(N, h) # dpの最小値を変更する関数 def chmin(a, b): if a > b: return b else: return a # 無限大の値 f_inf = float("inf") # DP テーブルを初期化 (最小化問題なので INF に初期化) dp = [f_inf] * (10**5 + 10) # 初期条件 dp[0] = 0 # 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]| # 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]| for i in range(1, N): dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) # 一番目の足場では一つ前しか存在しない if i > 1: dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [float("inf")] * N dp[0] = 0 for i in range(1, N): if i == 1: dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) else: dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
false
62.068966
[ "-# print(N, h)", "-# dpの最小値を変更する関数", "-def chmin(a, b):", "- if a > b:", "- return b", "+dp = [float(\"inf\")] * N", "+dp[0] = 0", "+for i in range(1, N):", "+ if i == 1:", "+ dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))", "- return a", "-", "-", "-# 無限大の値", "-f_inf = float(\"inf\")", "-# DP テーブルを初期化 (最小化問題なので INF に初期化)", "-dp = [f_inf] * (10**5 + 10)", "-# 初期条件", "-dp[0] = 0", "-# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|", "-# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|", "-for i in range(1, N):", "- dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))", "- # 一番目の足場では一つ前しか存在しない", "- if i > 1:", "- dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.043701
0.036094
1.210737
[ "s049233007", "s321454441" ]
u631914718
p03283
python
s722326073
s794812125
1,675
499
11,508
32,888
Accepted
Accepted
70.21
from itertools import accumulate as acc def LI(): return list(map(int, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) if __name__ == "__main__": N, M, Q = LI() LR = [[0]*N for _ in range(N)] for i in range(M): l, r = LI_() LR[l][r] += 1 # 二次元累積和 S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))] for _ in range(Q): p, q = LI() # 必ず正方形だから、 print((S[q-1][N-p]))
from itertools import accumulate as acc import sys if __name__ == "__main__": s = sys.stdin.readlines() N, M, Q = list(map(int, s[0].split())) LR = [[0]*N for _ in range(N)] for l, r in (list(map(int, e.split())) for e in s[1:M + 1]): LR[l - 1][r - 1] += 1 S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))] for p, q in (list(map(int, e.split())) for e in s[M+1:]): print((S[q-1][N-p]))
19
13
498
436
from itertools import accumulate as acc def LI(): return list(map(int, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) if __name__ == "__main__": N, M, Q = LI() LR = [[0] * N for _ in range(N)] for i in range(M): l, r = LI_() LR[l][r] += 1 # 二次元累積和 S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))] for _ in range(Q): p, q = LI() # 必ず正方形だから、 print((S[q - 1][N - p]))
from itertools import accumulate as acc import sys if __name__ == "__main__": s = sys.stdin.readlines() N, M, Q = list(map(int, s[0].split())) LR = [[0] * N for _ in range(N)] for l, r in (list(map(int, e.split())) for e in s[1 : M + 1]): LR[l - 1][r - 1] += 1 S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))] for p, q in (list(map(int, e.split())) for e in s[M + 1 :]): print((S[q - 1][N - p]))
false
31.578947
[ "-", "-", "-def LI():", "- return list(map(int, input().split()))", "-", "-", "-def LI_():", "- return list([int(x) - 1 for x in input().split()])", "-", "+import sys", "- N, M, Q = LI()", "+ s = sys.stdin.readlines()", "+ N, M, Q = list(map(int, s[0].split()))", "- for i in range(M):", "- l, r = LI_()", "- LR[l][r] += 1", "- # 二次元累積和", "+ for l, r in (list(map(int, e.split())) for e in s[1 : M + 1]):", "+ LR[l - 1][r - 1] += 1", "- for _ in range(Q):", "- p, q = LI()", "- # 必ず正方形だから、", "+ for p, q in (list(map(int, e.split())) for e in s[M + 1 :]):" ]
false
0.035597
0.057558
0.618454
[ "s722326073", "s794812125" ]
u983918956
p02937
python
s082312298
s377603238
173
139
7,668
7,616
Accepted
Accepted
19.65
from bisect import bisect s = eval(input()) t = eval(input()) d = dict() for i in range(26): d[chr(i+97)] = [] for i, si in enumerate(s): d[si].append(i) ans = 0 res = -1 for i in range(len(t)): if d[t[i]] == []: print((-1)) exit() index = bisect(d[t[i]], res) if index == len(d[t[i]]): ans += len(s) - res + d[t[i]][0] res = d[t[i]][0] else: ans += d[t[i]][index] - res res = d[t[i]][index] print(ans)
from bisect import bisect s = eval(input()) t = eval(input()) if len(set(t) & set(s)) != len(set(t)): print((-1)) exit() d = dict() for i, si in enumerate(s): if si in d: d[si].append(i) else: d[si] = [i] ans = 0 res = d[t[0]][0] for i in range(1, len(t)): index = bisect(d[t[i]], res) if index == len(d[t[i]]): ans += len(s) res = d[t[i]][0] else: res = d[t[i]][index] ans += res + 1 print(ans)
29
31
495
487
from bisect import bisect s = eval(input()) t = eval(input()) d = dict() for i in range(26): d[chr(i + 97)] = [] for i, si in enumerate(s): d[si].append(i) ans = 0 res = -1 for i in range(len(t)): if d[t[i]] == []: print((-1)) exit() index = bisect(d[t[i]], res) if index == len(d[t[i]]): ans += len(s) - res + d[t[i]][0] res = d[t[i]][0] else: ans += d[t[i]][index] - res res = d[t[i]][index] print(ans)
from bisect import bisect s = eval(input()) t = eval(input()) if len(set(t) & set(s)) != len(set(t)): print((-1)) exit() d = dict() for i, si in enumerate(s): if si in d: d[si].append(i) else: d[si] = [i] ans = 0 res = d[t[0]][0] for i in range(1, len(t)): index = bisect(d[t[i]], res) if index == len(d[t[i]]): ans += len(s) res = d[t[i]][0] else: res = d[t[i]][index] ans += res + 1 print(ans)
false
6.451613
[ "+if len(set(t) & set(s)) != len(set(t)):", "+ print((-1))", "+ exit()", "-for i in range(26):", "- d[chr(i + 97)] = []", "- d[si].append(i)", "+ if si in d:", "+ d[si].append(i)", "+ else:", "+ d[si] = [i]", "-res = -1", "-for i in range(len(t)):", "- if d[t[i]] == []:", "- print((-1))", "- exit()", "+res = d[t[0]][0]", "+for i in range(1, len(t)):", "- ans += len(s) - res + d[t[i]][0]", "+ ans += len(s)", "- ans += d[t[i]][index] - res", "+ans += res + 1" ]
false
0.089106
0.041345
2.15521
[ "s082312298", "s377603238" ]
u126232616
p03564
python
s294922552
s855437778
19
17
2,940
2,940
Accepted
Accepted
10.53
n = int(eval(input())) k = int(eval(input())) ans = 10**10 for i in range(2**n): m = 1 for j in range(n): if (i>>j)&1 == 1: m *= 2 else: m += k ans = min(m,ans) print(ans)
n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): ans = min(2*ans,ans+k) print(ans)
12
6
222
103
n = int(eval(input())) k = int(eval(input())) ans = 10**10 for i in range(2**n): m = 1 for j in range(n): if (i >> j) & 1 == 1: m *= 2 else: m += k ans = min(m, ans) print(ans)
n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): ans = min(2 * ans, ans + k) print(ans)
false
50
[ "-ans = 10**10", "-for i in range(2**n):", "- m = 1", "- for j in range(n):", "- if (i >> j) & 1 == 1:", "- m *= 2", "- else:", "- m += k", "- ans = min(m, ans)", "+ans = 1", "+for i in range(n):", "+ ans = min(2 * ans, ans + k)" ]
false
0.085741
0.075542
1.135016
[ "s294922552", "s855437778" ]
u078349616
p03546
python
s973492008
s634989810
535
208
25,808
14,084
Accepted
Accepted
61.12
from scipy.sparse.csgraph import floyd_warshall from itertools import permutations H, W = list(map(int, input().split())) C = [[0]*10 for _ in range(10)] A = [[0]*W for _ in range(H)] for i in range(10): C[i] = list(map(int, input().split())) C = floyd_warshall(C) cost = 0 for i in range(H): A[i] = list(map(int, input().split())) for a in A[i]: if a != -1: cost += C[a][1] print((int(cost)))
# ABC79 D - Wall from scipy.sparse.csgraph import floyd_warshall from itertools import permutations H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] A = [list(map(int, input().split())) for _ in range(H)] C = floyd_warshall(C) cost = 0 for i in range(H): for a in A[i]: if a != -1: cost += C[a][1] print((int(cost)))
20
17
427
401
from scipy.sparse.csgraph import floyd_warshall from itertools import permutations H, W = list(map(int, input().split())) C = [[0] * 10 for _ in range(10)] A = [[0] * W for _ in range(H)] for i in range(10): C[i] = list(map(int, input().split())) C = floyd_warshall(C) cost = 0 for i in range(H): A[i] = list(map(int, input().split())) for a in A[i]: if a != -1: cost += C[a][1] print((int(cost)))
# ABC79 D - Wall from scipy.sparse.csgraph import floyd_warshall from itertools import permutations H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] A = [list(map(int, input().split())) for _ in range(H)] C = floyd_warshall(C) cost = 0 for i in range(H): for a in A[i]: if a != -1: cost += C[a][1] print((int(cost)))
false
15
[ "+# ABC79 D - Wall", "-C = [[0] * 10 for _ in range(10)]", "-A = [[0] * W for _ in range(H)]", "-for i in range(10):", "- C[i] = list(map(int, input().split()))", "+C = [list(map(int, input().split())) for _ in range(10)]", "+A = [list(map(int, input().split())) for _ in range(H)]", "- A[i] = list(map(int, input().split()))" ]
false
0.417645
0.274032
1.524072
[ "s973492008", "s634989810" ]
u989345508
p03816
python
s958962434
s189785327
120
104
17,304
17,704
Accepted
Accepted
13.33
n=int(eval(input())) a=sorted([int(i) for i in input().split()]) def groupby(a): a2=[[a[0],1]] for i in range(1,len(a)): if a2[-1][0]==a[i]: a2[-1][1]+=1 else: a2.append([a[i],1]) return a2 a=groupby(a) #print(a) l=len(a) for i in range(l): if a[i][1]%2==0: a[i][1]=2 else: a[i][1]=1 c=0 for i in range(l): if a[i][1]==2: c+=1 if c%2==0: print(l) else: print((l-1))
n=int(eval(input())) def groupby(a): a2=[[a[0],1]] for i in range(1,len(a)): if a2[-1][0]==a[i]: a2[-1][1]+=1 else: a2.append([a[i],1]) return a2 b=groupby(sorted([int(i) for i in input().split()])) l=len(b) co=0 for i in range(l): co+=(b[i][1]-1) if co%2==0: print(l) else: print((l-1))
27
19
481
363
n = int(eval(input())) a = sorted([int(i) for i in input().split()]) def groupby(a): a2 = [[a[0], 1]] for i in range(1, len(a)): if a2[-1][0] == a[i]: a2[-1][1] += 1 else: a2.append([a[i], 1]) return a2 a = groupby(a) # print(a) l = len(a) for i in range(l): if a[i][1] % 2 == 0: a[i][1] = 2 else: a[i][1] = 1 c = 0 for i in range(l): if a[i][1] == 2: c += 1 if c % 2 == 0: print(l) else: print((l - 1))
n = int(eval(input())) def groupby(a): a2 = [[a[0], 1]] for i in range(1, len(a)): if a2[-1][0] == a[i]: a2[-1][1] += 1 else: a2.append([a[i], 1]) return a2 b = groupby(sorted([int(i) for i in input().split()])) l = len(b) co = 0 for i in range(l): co += b[i][1] - 1 if co % 2 == 0: print(l) else: print((l - 1))
false
29.62963
[ "-a = sorted([int(i) for i in input().split()])", "-a = groupby(a)", "-# print(a)", "-l = len(a)", "+b = groupby(sorted([int(i) for i in input().split()]))", "+l = len(b)", "+co = 0", "- if a[i][1] % 2 == 0:", "- a[i][1] = 2", "- else:", "- a[i][1] = 1", "-c = 0", "-for i in range(l):", "- if a[i][1] == 2:", "- c += 1", "-if c % 2 == 0:", "+ co += b[i][1] - 1", "+if co % 2 == 0:" ]
false
0.034843
0.058723
0.593345
[ "s958962434", "s189785327" ]
u312025627
p02863
python
s722704326
s830489041
902
356
179,332
146,044
Accepted
Accepted
60.53
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0]*(T+1) for i in range(N+2)] for i in range(1, N+1): for j in range(T): dp1[i][j] = max(dp1[i][j], dp1[i-1][j]) if j + A[i-1] < T: dp1[i][j + A[i-1]] = \ max(dp1[i][j + A[i-1]], dp1[i-1][j] + B[i-1]) dp2 = [[0]*(T+1) for i in range(N+2)] for i in range(1, N+1)[::-1]: for j in range(T): dp2[i][j] = max(dp2[i][j], dp2[i+1][j]) if j + A[i-1] < T: dp2[i][j + A[i-1]] = \ max(dp2[i][j + A[i-1]], dp2[i+1][j] + B[i-1]) ans = 0 for i in range(1, N+1): for j in range(T): ans = max(ans, dp1[i-1][j] + dp2[i+1][T-1-j] + B[i-1]) print(ans) if __name__ == '__main__': main()
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] AB.sort() A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0]*(T+1) for _ in range(N+1)] for i in range(N): for j in range(T): dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j]) t = j - A[i] if 0 <= t: dp1[i+1][j] = max(dp1[i+1][j], dp1[i][t] + B[i]) ans = 0 for i in range(N): ans = max(ans, dp1[i][T-1] + B[i]) print(ans) if __name__ == '__main__': main()
30
23
970
604
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0] * (T + 1) for i in range(N + 2)] for i in range(1, N + 1): for j in range(T): dp1[i][j] = max(dp1[i][j], dp1[i - 1][j]) if j + A[i - 1] < T: dp1[i][j + A[i - 1]] = max( dp1[i][j + A[i - 1]], dp1[i - 1][j] + B[i - 1] ) dp2 = [[0] * (T + 1) for i in range(N + 2)] for i in range(1, N + 1)[::-1]: for j in range(T): dp2[i][j] = max(dp2[i][j], dp2[i + 1][j]) if j + A[i - 1] < T: dp2[i][j + A[i - 1]] = max( dp2[i][j + A[i - 1]], dp2[i + 1][j] + B[i - 1] ) ans = 0 for i in range(1, N + 1): for j in range(T): ans = max(ans, dp1[i - 1][j] + dp2[i + 1][T - 1 - j] + B[i - 1]) print(ans) if __name__ == "__main__": main()
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] AB.sort() A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0] * (T + 1) for _ in range(N + 1)] for i in range(N): for j in range(T): dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]) t = j - A[i] if 0 <= t: dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][t] + B[i]) ans = 0 for i in range(N): ans = max(ans, dp1[i][T - 1] + B[i]) print(ans) if __name__ == "__main__": main()
false
23.333333
[ "+ AB.sort()", "- dp1 = [[0] * (T + 1) for i in range(N + 2)]", "- for i in range(1, N + 1):", "+ dp1 = [[0] * (T + 1) for _ in range(N + 1)]", "+ for i in range(N):", "- dp1[i][j] = max(dp1[i][j], dp1[i - 1][j])", "- if j + A[i - 1] < T:", "- dp1[i][j + A[i - 1]] = max(", "- dp1[i][j + A[i - 1]], dp1[i - 1][j] + B[i - 1]", "- )", "- dp2 = [[0] * (T + 1) for i in range(N + 2)]", "- for i in range(1, N + 1)[::-1]:", "- for j in range(T):", "- dp2[i][j] = max(dp2[i][j], dp2[i + 1][j])", "- if j + A[i - 1] < T:", "- dp2[i][j + A[i - 1]] = max(", "- dp2[i][j + A[i - 1]], dp2[i + 1][j] + B[i - 1]", "- )", "+ dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j])", "+ t = j - A[i]", "+ if 0 <= t:", "+ dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][t] + B[i])", "- for i in range(1, N + 1):", "- for j in range(T):", "- ans = max(ans, dp1[i - 1][j] + dp2[i + 1][T - 1 - j] + B[i - 1])", "+ for i in range(N):", "+ ans = max(ans, dp1[i][T - 1] + B[i])" ]
false
0.034397
0.060137
0.571972
[ "s722704326", "s830489041" ]
u013408661
p03309
python
s983473585
s341179958
701
219
49,772
26,836
Accepted
Accepted
68.76
n=int(eval(input())) a=list(map(int,input().split())) b=[0] c=[0] d=[0] e=[0] count=0 count2=0 count3=0 count4=0 for i in range(n): a[i]-=i a.sort() for i in range(n-1): count+=a[i+1]-a[i] count3+=a[n-i-1]-a[n-i-2] b.append(count) d.append(count3) for i in range(n-1): count2+=b[i+1] count4+=d[i+1] c.append(count2) e.append(count4) ans=10**18 for i in range(n): ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) for i in range(n): a[i]-=i a.sort() x=a[n//2] ans=0 for i in range(n): ans+=abs(a[i]-x) print(ans)
27
10
476
159
n = int(eval(input())) a = list(map(int, input().split())) b = [0] c = [0] d = [0] e = [0] count = 0 count2 = 0 count3 = 0 count4 = 0 for i in range(n): a[i] -= i a.sort() for i in range(n - 1): count += a[i + 1] - a[i] count3 += a[n - i - 1] - a[n - i - 2] b.append(count) d.append(count3) for i in range(n - 1): count2 += b[i + 1] count4 += d[i + 1] c.append(count2) e.append(count4) ans = 10**18 for i in range(n): ans = min( ans, c[-1] - c[i] - b[i] * (n - i - 1) + e[-1] - e[n - i - 1] - d[n - i - 1] * i ) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) for i in range(n): a[i] -= i a.sort() x = a[n // 2] ans = 0 for i in range(n): ans += abs(a[i] - x) print(ans)
false
62.962963
[ "-b = [0]", "-c = [0]", "-d = [0]", "-e = [0]", "-count = 0", "-count2 = 0", "-count3 = 0", "-count4 = 0", "-for i in range(n - 1):", "- count += a[i + 1] - a[i]", "- count3 += a[n - i - 1] - a[n - i - 2]", "- b.append(count)", "- d.append(count3)", "-for i in range(n - 1):", "- count2 += b[i + 1]", "- count4 += d[i + 1]", "- c.append(count2)", "- e.append(count4)", "-ans = 10**18", "+x = a[n // 2]", "+ans = 0", "- ans = min(", "- ans, c[-1] - c[i] - b[i] * (n - i - 1) + e[-1] - e[n - i - 1] - d[n - i - 1] * i", "- )", "+ ans += abs(a[i] - x)" ]
false
0.082079
0.035722
2.297701
[ "s983473585", "s341179958" ]
u368249389
p03361
python
s637672601
s119110212
183
18
39,152
3,064
Accepted
Accepted
90.16
# Problem C - Grid Repainting # input process H, W = list(map(int, input().split())) s_list = [[0]*W for i in range(H)] for i in range(H): tmp = eval(input()) for j in range(W): s_list[i][j] = tmp[j] # search process is_ok = True for i in range(H): for j in range(W): if s_list[i][j]==".": continue # right process if j+1<W: if s_list[i][j+1]=="#": continue # left process if j-1>=0: if s_list[i][j-1]=="#": continue # down process if i+1<H: if s_list[i+1][j]=="#": continue # up process if i-1>=0: if s_list[i-1][j]=="#": continue # stop process is_ok = False break if is_ok: print("Yes") else: print("No")
# Problem C - Grid Repainting 2 # input H, W = list(map(int, input().split())) board = [[0]*W for i in range(H)] for i in range(H): s_list = list(eval(input())) for j in range(W): board[i][j] = s_list[j] # initialization is_ok = True # check for i in range(H): for j in range(W): s = board[i][j] if s=='.': continue # right if j+1<W: if s=='#' and board[i][j+1]=='#': continue # left if j-1>=0: if s=='#' and board[i][j-1]=='#': continue # up if i-1>=0: if s=='#' and board[i-1][j]=='#': continue # down if i+1<H: if s=='#' and board[i+1][j]=='#': continue is_ok = False break # output if is_ok: print("Yes") else: print("No")
40
48
886
919
# Problem C - Grid Repainting # input process H, W = list(map(int, input().split())) s_list = [[0] * W for i in range(H)] for i in range(H): tmp = eval(input()) for j in range(W): s_list[i][j] = tmp[j] # search process is_ok = True for i in range(H): for j in range(W): if s_list[i][j] == ".": continue # right process if j + 1 < W: if s_list[i][j + 1] == "#": continue # left process if j - 1 >= 0: if s_list[i][j - 1] == "#": continue # down process if i + 1 < H: if s_list[i + 1][j] == "#": continue # up process if i - 1 >= 0: if s_list[i - 1][j] == "#": continue # stop process is_ok = False break if is_ok: print("Yes") else: print("No")
# Problem C - Grid Repainting 2 # input H, W = list(map(int, input().split())) board = [[0] * W for i in range(H)] for i in range(H): s_list = list(eval(input())) for j in range(W): board[i][j] = s_list[j] # initialization is_ok = True # check for i in range(H): for j in range(W): s = board[i][j] if s == ".": continue # right if j + 1 < W: if s == "#" and board[i][j + 1] == "#": continue # left if j - 1 >= 0: if s == "#" and board[i][j - 1] == "#": continue # up if i - 1 >= 0: if s == "#" and board[i - 1][j] == "#": continue # down if i + 1 < H: if s == "#" and board[i + 1][j] == "#": continue is_ok = False break # output if is_ok: print("Yes") else: print("No")
false
16.666667
[ "-# Problem C - Grid Repainting", "-# input process", "+# Problem C - Grid Repainting 2", "+# input", "-s_list = [[0] * W for i in range(H)]", "+board = [[0] * W for i in range(H)]", "- tmp = eval(input())", "+ s_list = list(eval(input()))", "- s_list[i][j] = tmp[j]", "-# search process", "+ board[i][j] = s_list[j]", "+# initialization", "+# check", "- if s_list[i][j] == \".\":", "+ s = board[i][j]", "+ if s == \".\":", "- # right process", "+ # right", "- if s_list[i][j + 1] == \"#\":", "+ if s == \"#\" and board[i][j + 1] == \"#\":", "- # left process", "+ # left", "- if s_list[i][j - 1] == \"#\":", "+ if s == \"#\" and board[i][j - 1] == \"#\":", "- # down process", "+ # up", "+ if i - 1 >= 0:", "+ if s == \"#\" and board[i - 1][j] == \"#\":", "+ continue", "+ # down", "- if s_list[i + 1][j] == \"#\":", "+ if s == \"#\" and board[i + 1][j] == \"#\":", "- # up process", "- if i - 1 >= 0:", "- if s_list[i - 1][j] == \"#\":", "- continue", "- # stop process", "+# output" ]
false
0.034748
0.032408
1.072214
[ "s637672601", "s119110212" ]
u941753895
p03574
python
s206649122
s148619080
53
47
6,304
5,544
Accepted
Accepted
11.32
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): h,w=LI() a=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] l=[] for i in range(h): l.append(list(S())) for i in range(h): for j in range(w): if l[i][j]!='#': c=0 for x in a: if i+x[0]>=0 and i+x[0]<h and j+x[1]>=0 and j+x[1]<w: if l[i+x[0]][j+x[1]]=='#': c+=1 l[i][j]=str(c) for x in l: print((''.join(x))) main()
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): h,w=LI() a=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] l=[] for i in range(h): l.append(list(S())) for i in range(h): for j in range(w): if l[i][j]=='#': continue c=0 for x in a: p=i+x[0] q=j+x[1] if 0<=p and p<h and 0<=q and q<w: if l[p][q]=='#': c+=1 l[i][j]=str(c) for x in l: print((''.join(x))) main()
35
37
742
750
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): h, w = LI() a = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]] l = [] for i in range(h): l.append(list(S())) for i in range(h): for j in range(w): if l[i][j] != "#": c = 0 for x in a: if ( i + x[0] >= 0 and i + x[0] < h and j + x[1] >= 0 and j + x[1] < w ): if l[i + x[0]][j + x[1]] == "#": c += 1 l[i][j] = str(c) for x in l: print(("".join(x))) main()
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): h, w = LI() a = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]] l = [] for i in range(h): l.append(list(S())) for i in range(h): for j in range(w): if l[i][j] == "#": continue c = 0 for x in a: p = i + x[0] q = j + x[1] if 0 <= p and p < h and 0 <= q and q < w: if l[p][q] == "#": c += 1 l[i][j] = str(c) for x in l: print(("".join(x))) main()
false
5.405405
[ "- if l[i][j] != \"#\":", "- c = 0", "- for x in a:", "- if (", "- i + x[0] >= 0", "- and i + x[0] < h", "- and j + x[1] >= 0", "- and j + x[1] < w", "- ):", "- if l[i + x[0]][j + x[1]] == \"#\":", "- c += 1", "- l[i][j] = str(c)", "+ if l[i][j] == \"#\":", "+ continue", "+ c = 0", "+ for x in a:", "+ p = i + x[0]", "+ q = j + x[1]", "+ if 0 <= p and p < h and 0 <= q and q < w:", "+ if l[p][q] == \"#\":", "+ c += 1", "+ l[i][j] = str(c)" ]
false
0.041044
0.072792
0.563846
[ "s206649122", "s148619080" ]
u623231048
p02761
python
s617667541
s876724090
19
17
3,064
3,064
Accepted
Accepted
10.53
n,m = list(map(int,input().split())) sc = [list(map(int,input().split())) for _ in range(m)] for i in range(1000): li = [] j = str(i) for k in range(len(j)): li.append(int(j[k])) if len(li) != n: continue else: flag = True for s,c in sc: if li[s-1] != c: flag = False if flag: print(j) exit() print((-1))
n,m = list(map(int,input().split())) sc = [list(map(int,input().split())) for _ in range(m)] li = [-1] * n for s,c in sc: if li[s-1] == -1 or li[s-1] == c: li[s-1] = c else: print((-1)) exit() if n != 1 and s == 1 and c == 0: print((-1)) exit() for i in range(n): if li[i] == -1: if i == 0 and n != 1: li[i] = 1 else: li[i] = 0 ans = '' for i in li: ans += str(i) print((int(ans)))
21
27
432
501
n, m = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(m)] for i in range(1000): li = [] j = str(i) for k in range(len(j)): li.append(int(j[k])) if len(li) != n: continue else: flag = True for s, c in sc: if li[s - 1] != c: flag = False if flag: print(j) exit() print((-1))
n, m = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(m)] li = [-1] * n for s, c in sc: if li[s - 1] == -1 or li[s - 1] == c: li[s - 1] = c else: print((-1)) exit() if n != 1 and s == 1 and c == 0: print((-1)) exit() for i in range(n): if li[i] == -1: if i == 0 and n != 1: li[i] = 1 else: li[i] = 0 ans = "" for i in li: ans += str(i) print((int(ans)))
false
22.222222
[ "-for i in range(1000):", "- li = []", "- j = str(i)", "- for k in range(len(j)):", "- li.append(int(j[k]))", "- if len(li) != n:", "- continue", "+li = [-1] * n", "+for s, c in sc:", "+ if li[s - 1] == -1 or li[s - 1] == c:", "+ li[s - 1] = c", "- flag = True", "- for s, c in sc:", "- if li[s - 1] != c:", "- flag = False", "- if flag:", "- print(j)", "- exit()", "-print((-1))", "+ print((-1))", "+ exit()", "+ if n != 1 and s == 1 and c == 0:", "+ print((-1))", "+ exit()", "+for i in range(n):", "+ if li[i] == -1:", "+ if i == 0 and n != 1:", "+ li[i] = 1", "+ else:", "+ li[i] = 0", "+ans = \"\"", "+for i in li:", "+ ans += str(i)", "+print((int(ans)))" ]
false
0.044164
0.10848
0.407117
[ "s617667541", "s876724090" ]
u330039499
p03610
python
s954321373
s725253127
105
24
7,168
3,140
Accepted
Accepted
77.14
s = input() print("".join([c for i, c in enumerate(s) if (i + 1) % 2 == 1]))
print("".join([c for i, c in enumerate(input()) if (i + 1) % 2 == 1]))
2
1
81
74
s = input() print("".join([c for i, c in enumerate(s) if (i + 1) % 2 == 1]))
print("".join([c for i, c in enumerate(input()) if (i + 1) % 2 == 1]))
false
50
[ "-s = input()", "-print(\"\".join([c for i, c in enumerate(s) if (i + 1) % 2 == 1]))", "+print(\"\".join([c for i, c in enumerate(input()) if (i + 1) % 2 == 1]))" ]
false
0.120069
0.063145
1.901465
[ "s954321373", "s725253127" ]
u644907318
p03352
python
s604219930
s837667824
209
66
62,088
62,124
Accepted
Accepted
68.42
X = int(eval(input())) cmax = 1 for i in range(2,int(X**0.5)+1): k = 2 while i**k<=X: cmax = max(cmax,i**k) k += 1 print(cmax)
X = int(eval(input())) if X==1: print((1)) else: cmax = 1 for i in range(2,int(X**0.5)+1): k = 2 while i**k<=X: cmax = max(cmax,i**k) k += 1 print(cmax)
8
11
151
210
X = int(eval(input())) cmax = 1 for i in range(2, int(X**0.5) + 1): k = 2 while i**k <= X: cmax = max(cmax, i**k) k += 1 print(cmax)
X = int(eval(input())) if X == 1: print((1)) else: cmax = 1 for i in range(2, int(X**0.5) + 1): k = 2 while i**k <= X: cmax = max(cmax, i**k) k += 1 print(cmax)
false
27.272727
[ "-cmax = 1", "-for i in range(2, int(X**0.5) + 1):", "- k = 2", "- while i**k <= X:", "- cmax = max(cmax, i**k)", "- k += 1", "-print(cmax)", "+if X == 1:", "+ print((1))", "+else:", "+ cmax = 1", "+ for i in range(2, int(X**0.5) + 1):", "+ k = 2", "+ while i**k <= X:", "+ cmax = max(cmax, i**k)", "+ k += 1", "+ print(cmax)" ]
false
0.045906
0.046669
0.983653
[ "s604219930", "s837667824" ]
u670180528
p02735
python
s469349716
s322030510
558
53
3,572
3,444
Accepted
Accepted
90.5
from collections import deque t,*g=open(0) h,w=list(map(int,t.split())) vis=[[1e9]*w for _ in range(h)] vis[0][0]=int(g[0][0]=="#") q=deque([(0,0,vis[0][0])]) while q: cy,cx,c=q.popleft() for ny,nx in ((cy+1,cx),(cy,cx+1)): cc=c if not (0<=ny<h and 0<=nx<w): continue if g[cy][cx]=="." and g[ny][nx]=="#": cc+=1 if cc<vis[ny][nx]: vis[ny][nx]=cc q.append((ny,nx,cc)) #print(vis) print((vis[-1][-1]))
from collections import deque t,*g=open(0) h,w=list(map(int,t.split())) vis=[[1e9]*w for _ in range(h)] vis[0][0]=int(g[0][0]=="#") q=deque([(0,0)]) while q: cy,cx=q.popleft() for ny,nx in ((cy+1,cx),(cy,cx+1)): if not not (0<=ny<h and 0<=nx<w) and vis[cy][cx]+(g[cy][cx]!=g[ny][nx]=="#")<vis[ny][nx]: vis[ny][nx]=vis[cy][cx]+(g[cy][cx]!=g[ny][nx]=="#") q.append((ny,nx)) print((vis[-1][-1]))
19
13
431
406
from collections import deque t, *g = open(0) h, w = list(map(int, t.split())) vis = [[1e9] * w for _ in range(h)] vis[0][0] = int(g[0][0] == "#") q = deque([(0, 0, vis[0][0])]) while q: cy, cx, c = q.popleft() for ny, nx in ((cy + 1, cx), (cy, cx + 1)): cc = c if not (0 <= ny < h and 0 <= nx < w): continue if g[cy][cx] == "." and g[ny][nx] == "#": cc += 1 if cc < vis[ny][nx]: vis[ny][nx] = cc q.append((ny, nx, cc)) # print(vis) print((vis[-1][-1]))
from collections import deque t, *g = open(0) h, w = list(map(int, t.split())) vis = [[1e9] * w for _ in range(h)] vis[0][0] = int(g[0][0] == "#") q = deque([(0, 0)]) while q: cy, cx = q.popleft() for ny, nx in ((cy + 1, cx), (cy, cx + 1)): if ( not not (0 <= ny < h and 0 <= nx < w) and vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#") < vis[ny][nx] ): vis[ny][nx] = vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#") q.append((ny, nx)) print((vis[-1][-1]))
false
31.578947
[ "-q = deque([(0, 0, vis[0][0])])", "+q = deque([(0, 0)])", "- cy, cx, c = q.popleft()", "+ cy, cx = q.popleft()", "- cc = c", "- if not (0 <= ny < h and 0 <= nx < w):", "- continue", "- if g[cy][cx] == \".\" and g[ny][nx] == \"#\":", "- cc += 1", "- if cc < vis[ny][nx]:", "- vis[ny][nx] = cc", "- q.append((ny, nx, cc))", "-# print(vis)", "+ if (", "+ not not (0 <= ny < h and 0 <= nx < w)", "+ and vis[cy][cx] + (g[cy][cx] != g[ny][nx] == \"#\") < vis[ny][nx]", "+ ):", "+ vis[ny][nx] = vis[cy][cx] + (g[cy][cx] != g[ny][nx] == \"#\")", "+ q.append((ny, nx))" ]
false
0.059963
0.037345
1.605626
[ "s469349716", "s322030510" ]
u078042885
p01751
python
s332960341
s057463794
30
20
7,684
7,676
Accepted
Accepted
33.33
a,b,c=list(map(int, input().split())) d=0 for _ in range(60): if c<=d+a: print(c) break d+=a+b while c<=d:c+=60 else: print((-1))
a,b,c=list(map(int, input().split())) d,e=0,60 for _ in range(e): if c<=d+a: print(c) break d+=a+b c+=(d+e-c)//e*e else: print((-1))
9
9
157
160
a, b, c = list(map(int, input().split())) d = 0 for _ in range(60): if c <= d + a: print(c) break d += a + b while c <= d: c += 60 else: print((-1))
a, b, c = list(map(int, input().split())) d, e = 0, 60 for _ in range(e): if c <= d + a: print(c) break d += a + b c += (d + e - c) // e * e else: print((-1))
false
0
[ "-d = 0", "-for _ in range(60):", "+d, e = 0, 60", "+for _ in range(e):", "- while c <= d:", "- c += 60", "+ c += (d + e - c) // e * e" ]
false
0.049788
0.049051
1.015014
[ "s332960341", "s057463794" ]
u354246246
p02598
python
s446073104
s487204905
1,011
635
31,156
31,108
Accepted
Accepted
37.19
import math def possible(l, a, k): for x in a: k -= math.ceil(x/l)-1 return k>=0 n, k = list(map(int, input().split())) a = [int(x) for x in input().split()] mini = 1 maxi = 10**9+7 while(mini!=maxi): mid = (mini+maxi)//2 if possible(mid, a, k): maxi = mid else: mini = mid + 1 print(mini)
import math def possible(l, a, k): for x in a: k -= x//l if x%l==0: k += 1 return k>=0 n, k = list(map(int, input().split())) a = [int(x) for x in input().split()] mini = 1 maxi = 10**9+7 while(mini!=maxi): mid = (mini+maxi)//2 if possible(mid, a, k): maxi = mid else: mini = mid + 1 print(mini)
17
19
345
373
import math def possible(l, a, k): for x in a: k -= math.ceil(x / l) - 1 return k >= 0 n, k = list(map(int, input().split())) a = [int(x) for x in input().split()] mini = 1 maxi = 10**9 + 7 while mini != maxi: mid = (mini + maxi) // 2 if possible(mid, a, k): maxi = mid else: mini = mid + 1 print(mini)
import math def possible(l, a, k): for x in a: k -= x // l if x % l == 0: k += 1 return k >= 0 n, k = list(map(int, input().split())) a = [int(x) for x in input().split()] mini = 1 maxi = 10**9 + 7 while mini != maxi: mid = (mini + maxi) // 2 if possible(mid, a, k): maxi = mid else: mini = mid + 1 print(mini)
false
10.526316
[ "- k -= math.ceil(x / l) - 1", "+ k -= x // l", "+ if x % l == 0:", "+ k += 1" ]
false
0.046588
0.007647
6.092335
[ "s446073104", "s487204905" ]
u922172470
p02748
python
s974388568
s352464370
447
178
38,556
35,124
Accepted
Accepted
60.18
def resolve(): A, B, M = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) grid=[list(map(int,input().split())) for i in range(M)] res = min(a) + min(b) for x, y, c in grid: res = min(res, a[x-1]+b[y-1]-c) print(res) resolve()
import sys A, B, M = list(map(int, sys.stdin.readline().split())) *a, = list(map(int, sys.stdin.readline().split())) *b, = list(map(int, sys.stdin.readline().split())) xyc = list(zip(*[list(map(int, sys.stdin.read().split()))] * 3)) def main(): res = min(a) + min(b) for x, y, c in xyc: res = min(res, a[x-1] + b[y-1] - c) return res if __name__ == '__main__': ans = main() print(ans)
14
17
331
409
def resolve(): A, B, M = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) grid = [list(map(int, input().split())) for i in range(M)] res = min(a) + min(b) for x, y, c in grid: res = min(res, a[x - 1] + b[y - 1] - c) print(res) resolve()
import sys A, B, M = list(map(int, sys.stdin.readline().split())) (*a,) = list(map(int, sys.stdin.readline().split())) (*b,) = list(map(int, sys.stdin.readline().split())) xyc = list(zip(*[list(map(int, sys.stdin.read().split()))] * 3)) def main(): res = min(a) + min(b) for x, y, c in xyc: res = min(res, a[x - 1] + b[y - 1] - c) return res if __name__ == "__main__": ans = main() print(ans)
false
17.647059
[ "-def resolve():", "- A, B, M = list(map(int, input().split()))", "- a = list(map(int, input().split()))", "- b = list(map(int, input().split()))", "- grid = [list(map(int, input().split())) for i in range(M)]", "- res = min(a) + min(b)", "- for x, y, c in grid:", "- res = min(res, a[x - 1] + b[y - 1] - c)", "- print(res)", "+import sys", "+", "+A, B, M = list(map(int, sys.stdin.readline().split()))", "+(*a,) = list(map(int, sys.stdin.readline().split()))", "+(*b,) = list(map(int, sys.stdin.readline().split()))", "+xyc = list(zip(*[list(map(int, sys.stdin.read().split()))] * 3))", "-resolve()", "+def main():", "+ res = min(a) + min(b)", "+ for x, y, c in xyc:", "+ res = min(res, a[x - 1] + b[y - 1] - c)", "+ return res", "+", "+", "+if __name__ == \"__main__\":", "+ ans = main()", "+ print(ans)" ]
false
0.108714
0.036841
2.950902
[ "s974388568", "s352464370" ]
u729133443
p03238
python
s700551485
s410390200
39
10
27,500
2,568
Accepted
Accepted
74.36
print(eval(input())+eval(input())if eval(input())-1else'Hello World')
print(eval(input())+eval(input())if~-eval(input())else'Hello World')
1
1
50
49
print(eval(input()) + eval(input()) if eval(input()) - 1 else "Hello World")
print(eval(input()) + eval(input()) if ~-eval(input()) else "Hello World")
false
0
[ "-print(eval(input()) + eval(input()) if eval(input()) - 1 else \"Hello World\")", "+print(eval(input()) + eval(input()) if ~-eval(input()) else \"Hello World\")" ]
false
0.084606
0.064612
1.309443
[ "s700551485", "s410390200" ]
u074220993
p03455
python
s376526564
s780964770
29
26
9,024
9,012
Accepted
Accepted
10.34
a, b = list(map(int, input().split())) print(('Odd' if a & 1 and b & 1 else 'Even'))
a, b = list(map(int, input().split())) print(('Odd' if a*b % 2 == 1 else 'Even'))
2
2
77
74
a, b = list(map(int, input().split())) print(("Odd" if a & 1 and b & 1 else "Even"))
a, b = list(map(int, input().split())) print(("Odd" if a * b % 2 == 1 else "Even"))
false
0
[ "-print((\"Odd\" if a & 1 and b & 1 else \"Even\"))", "+print((\"Odd\" if a * b % 2 == 1 else \"Even\"))" ]
false
0.055255
0.054713
1.009914
[ "s376526564", "s780964770" ]
u156815136
p02843
python
s244082293
s422419953
203
183
5,916
41,324
Accepted
Accepted
9.85
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): X = int(eval(input())) dp = [False] * (X+1) # dp[i+1] := i円、そのお金で払えますか? # dp[i - 100], ... がTrue なら Trueだあ MENU = [100,101,102,103,104,105] dp[0] = True # 0円は買える for i in range(X): for v in MENU: if i + 1 - v < 0: continue dp[i+1] |= dp[i+1-v] print((1 if dp[X] else 0)) if __name__ == '__main__': main()
X = int(eval(input())) Food = [100,101,102,103,104,105] dp = [False] * (X+1) dp[0] = True for i in range(X+1): for f in Food: if i - f >= 0: #print(i,i-f) dp[i] = dp[i - f] | dp[i] print(('1' if dp[X] else '0'))
40
10
956
249
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): X = int(eval(input())) dp = [False] * (X + 1) # dp[i+1] := i円、そのお金で払えますか? # dp[i - 100], ... がTrue なら Trueだあ MENU = [100, 101, 102, 103, 104, 105] dp[0] = True # 0円は買える for i in range(X): for v in MENU: if i + 1 - v < 0: continue dp[i + 1] |= dp[i + 1 - v] print((1 if dp[X] else 0)) if __name__ == "__main__": main()
X = int(eval(input())) Food = [100, 101, 102, 103, 104, 105] dp = [False] * (X + 1) dp[0] = True for i in range(X + 1): for f in Food: if i - f >= 0: # print(i,i-f) dp[i] = dp[i - f] | dp[i] print(("1" if dp[X] else "0"))
false
75
[ "-from statistics import median", "-", "-# import collections", "-# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "-from collections import defaultdict", "-import bisect", "-", "-#", "-# d = m - k[i] - k[j]", "-# if kk[bisect.bisect_right(kk,d) - 1] == d:", "-#", "-#", "-#", "-# pythonで無理なときは、pypyでやると正解するかも!!", "-#", "-#", "-import sys", "-", "-sys.setrecursionlimit(10000000)", "-mod = 10**9 + 7", "-", "-", "-def readInts():", "- return list(map(int, input().split()))", "-", "-", "-def main():", "- X = int(eval(input()))", "- dp = [False] * (X + 1)", "- # dp[i+1] := i円、そのお金で払えますか?", "- # dp[i - 100], ... がTrue なら Trueだあ", "- MENU = [100, 101, 102, 103, 104, 105]", "- dp[0] = True # 0円は買える", "- for i in range(X):", "- for v in MENU:", "- if i + 1 - v < 0:", "- continue", "- dp[i + 1] |= dp[i + 1 - v]", "- print((1 if dp[X] else 0))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+X = int(eval(input()))", "+Food = [100, 101, 102, 103, 104, 105]", "+dp = [False] * (X + 1)", "+dp[0] = True", "+for i in range(X + 1):", "+ for f in Food:", "+ if i - f >= 0:", "+ # print(i,i-f)", "+ dp[i] = dp[i - f] | dp[i]", "+print((\"1\" if dp[X] else \"0\"))" ]
false
0.039318
0.06807
0.57761
[ "s244082293", "s422419953" ]
u750651325
p02694
python
s375251442
s581461190
25
22
9,180
9,172
Accepted
Accepted
12
X = int(eval(input())) count = 0 sum = 100 while sum < X: sum += sum // 100 count += 1 print(count)
X = int(eval(input())) sum = 100 count = 0 while sum < X: sum += int(sum * 0.01) count += 1 print(count)
12
9
118
117
X = int(eval(input())) count = 0 sum = 100 while sum < X: sum += sum // 100 count += 1 print(count)
X = int(eval(input())) sum = 100 count = 0 while sum < X: sum += int(sum * 0.01) count += 1 print(count)
false
25
[ "+sum = 100", "-sum = 100", "- sum += sum // 100", "+ sum += int(sum * 0.01)" ]
false
0.048792
0.047988
1.016763
[ "s375251442", "s581461190" ]
u116002573
p03290
python
s966874416
s485686318
40
23
3,316
3,444
Accepted
Accepted
42.5
def main(): D, G = list(map(int, input().split())) pc = [] min_ct = 0 for i in range(D): p, c = list(map(int, input().split())) pc.append([p, c]) min_ct += p bonus = [set()] for i in range(D): temp = [] for st in bonus: temp.append(st | {i}) bonus += temp # print(bonus) for comp in bonus: pt = sum([pc[i][0]*100*(i+1)+pc[i][1] for i in comp]) ct = sum([pc[i][0] for i in comp]) j = 0 # print(comp, pt, j) for i in range(D-1, -1, -1): if i not in comp: while j < pc[i][0] and pt < G: pt += 100 * (i+1) j += 1 break # print(comp, pt, j) if pt >= G: min_ct = min(min_ct, ct+j) return min_ct if __name__ == '__main__': print((main()))
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] cur = [[0, 0]] used = [set()] for i, p, c in A: temp = [] temp_used = [] for j in range(len(cur)): temp.append(cur[j]) temp_used.append(used[j]) temp.append([cur[j][0]+ 100*(i+1)*p+c, cur[j][1] + p]) temp_used.append(used[j] | {i}) cur = temp used = temp_used # # print(cur) # print(used) ans = float('inf') for j in range(len(cur)): if cur[j][0] >= G: ans = min(ans, cur[j][1]) else: for i, p, c in A: if i not in used[j]: if cur[j][0] + 100 * (i+1) * (p-1) < G: cur[j][0] += 100 * (i+1) * (p-1) cur[j][1] += p-1 else: if (G - cur[j][0]) % (100*(i+1)) == 0: ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1))) else: ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1)) + 1) break return ans if __name__ == '__main__': print((main()))
36
48
909
1,367
def main(): D, G = list(map(int, input().split())) pc = [] min_ct = 0 for i in range(D): p, c = list(map(int, input().split())) pc.append([p, c]) min_ct += p bonus = [set()] for i in range(D): temp = [] for st in bonus: temp.append(st | {i}) bonus += temp # print(bonus) for comp in bonus: pt = sum([pc[i][0] * 100 * (i + 1) + pc[i][1] for i in comp]) ct = sum([pc[i][0] for i in comp]) j = 0 # print(comp, pt, j) for i in range(D - 1, -1, -1): if i not in comp: while j < pc[i][0] and pt < G: pt += 100 * (i + 1) j += 1 break # print(comp, pt, j) if pt >= G: min_ct = min(min_ct, ct + j) return min_ct if __name__ == "__main__": print((main()))
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] cur = [[0, 0]] used = [set()] for i, p, c in A: temp = [] temp_used = [] for j in range(len(cur)): temp.append(cur[j]) temp_used.append(used[j]) temp.append([cur[j][0] + 100 * (i + 1) * p + c, cur[j][1] + p]) temp_used.append(used[j] | {i}) cur = temp used = temp_used # # print(cur) # print(used) ans = float("inf") for j in range(len(cur)): if cur[j][0] >= G: ans = min(ans, cur[j][1]) else: for i, p, c in A: if i not in used[j]: if cur[j][0] + 100 * (i + 1) * (p - 1) < G: cur[j][0] += 100 * (i + 1) * (p - 1) cur[j][1] += p - 1 else: if (G - cur[j][0]) % (100 * (i + 1)) == 0: ans = min( ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) ) else: ans = min( ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) + 1 ) break return ans if __name__ == "__main__": print((main()))
false
25
[ "- pc = []", "- min_ct = 0", "+ A = []", "- pc.append([p, c])", "- min_ct += p", "- bonus = [set()]", "- for i in range(D):", "+ A.append([i, p, c])", "+ A = A[::-1]", "+ cur = [[0, 0]]", "+ used = [set()]", "+ for i, p, c in A:", "- for st in bonus:", "- temp.append(st | {i})", "- bonus += temp", "- # print(bonus)", "- for comp in bonus:", "- pt = sum([pc[i][0] * 100 * (i + 1) + pc[i][1] for i in comp])", "- ct = sum([pc[i][0] for i in comp])", "- j = 0", "- # print(comp, pt, j)", "- for i in range(D - 1, -1, -1):", "- if i not in comp:", "- while j < pc[i][0] and pt < G:", "- pt += 100 * (i + 1)", "- j += 1", "- break", "- # print(comp, pt, j)", "- if pt >= G:", "- min_ct = min(min_ct, ct + j)", "- return min_ct", "+ temp_used = []", "+ for j in range(len(cur)):", "+ temp.append(cur[j])", "+ temp_used.append(used[j])", "+ temp.append([cur[j][0] + 100 * (i + 1) * p + c, cur[j][1] + p])", "+ temp_used.append(used[j] | {i})", "+ cur = temp", "+ used = temp_used", "+ #", "+ # print(cur)", "+ # print(used)", "+ ans = float(\"inf\")", "+ for j in range(len(cur)):", "+ if cur[j][0] >= G:", "+ ans = min(ans, cur[j][1])", "+ else:", "+ for i, p, c in A:", "+ if i not in used[j]:", "+ if cur[j][0] + 100 * (i + 1) * (p - 1) < G:", "+ cur[j][0] += 100 * (i + 1) * (p - 1)", "+ cur[j][1] += p - 1", "+ else:", "+ if (G - cur[j][0]) % (100 * (i + 1)) == 0:", "+ ans = min(", "+ ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1))", "+ )", "+ else:", "+ ans = min(", "+ ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) + 1", "+ )", "+ break", "+ return ans" ]
false
0.044576
0.065526
0.680278
[ "s966874416", "s485686318" ]
u225388820
p02612
python
s690387417
s053589970
64
28
61,712
9,120
Accepted
Accepted
56.25
n = int(eval(input()))%1000 print((1000 - n if n else 0))
print(((1000 - int(eval(input())) % 1000) % 1000))
2
1
50
42
n = int(eval(input())) % 1000 print((1000 - n if n else 0))
print(((1000 - int(eval(input())) % 1000) % 1000))
false
50
[ "-n = int(eval(input())) % 1000", "-print((1000 - n if n else 0))", "+print(((1000 - int(eval(input())) % 1000) % 1000))" ]
false
0.088515
0.036844
2.402409
[ "s690387417", "s053589970" ]
u998435601
p02396
python
s673294606
s623374330
50
40
6,632
6,576
Accepted
Accepted
20
lis = [] a = int(input()) while a != 0: lis.append(a) a = int(input()) for i,v in enumerate(lis): print("Case %d: %d" % (i+1,v))
lis = [] a = input() while a != '0': lis.append(a) a = input() for i,v in enumerate(lis): print("Case %d: %s" % (i+1,v))
8
8
146
138
lis = [] a = int(input()) while a != 0: lis.append(a) a = int(input()) for i, v in enumerate(lis): print("Case %d: %d" % (i + 1, v))
lis = [] a = input() while a != "0": lis.append(a) a = input() for i, v in enumerate(lis): print("Case %d: %s" % (i + 1, v))
false
0
[ "-a = int(input())", "-while a != 0:", "+a = input()", "+while a != \"0\":", "- a = int(input())", "+ a = input()", "- print(\"Case %d: %d\" % (i + 1, v))", "+ print(\"Case %d: %s\" % (i + 1, v))" ]
false
0.040255
0.042934
0.937596
[ "s673294606", "s623374330" ]
u006880673
p02579
python
s675386827
s249740018
763
704
159,780
136,584
Accepted
Accepted
7.73
from itertools import product from collections import deque INF = 1e7 def main(): H, W = list(map(int, input().split())) ch, cw = [int(x)+1 for x in input().split()] dh, dw = [int(x)+1 for x in input().split()] S = [["#"]*(W+4) for _ in range(H+4)] whites = [] # 道であるindex for i in range(2, H+2): tmp = eval(input()) for j in range(2, W+2): S[i][j] = tmp[j-2] if S[i][j] == ".": whites.append((i,j)) dxdy = [(1,0), (-1,0), (0,1), (0,-1)] magic = list(product(list(range(-2, 3)), repeat=2)) magic.remove((0, 0)) for to_remove in dxdy: magic.remove(to_remove) # graph = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for dx, dy in dxdy: # if S[x+dx][y+dy] == ".": # graph[idx].append((x+dx, y+dy)) # graph2 = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for mx, my in magic: # if S[x+mx][y+my] == ".": # graph2[idx].append((x+mx, y+my)) def bfs(u,v): dist = [[INF] * (W+4) for _ in range(H+4)] #indexed from 1 # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1 queue = deque() # seen[u][v] = 1 dist[u][v] = 0 queue.append((u,v)) while queue: p, q = queue.popleft() # if not graph[(p,q)]: # queue.popleft() # continue # g,h = graph[(p,q)].popleft() # if seen[g][h]: # continue # seen[g][h] = 1 # dist[g][h] = min(dist[g][h], dist[p][q]) for dx, dy in dxdy: g = p+dx h = q+dy if S[g][h]=="." and dist[g][h] > dist[p][q]: dist[g][h] = dist[p][q] queue.appendleft((g,h)) for dx, dy in magic: g = p+dx h = q+dy if S[g][h]=="." and dist[g][h] > dist[p][q]+1: dist[g][h] = dist[p][q]+1 queue.append((g,h)) # dist[g][h] = min(dist[g][h], dist[p][q]+1) # queue.append((g,h)) return dist D = bfs(ch, cw) ans = D[dh][dw] if ans == INF: print((-1)) else: print(ans) if __name__ == "__main__": main()
from itertools import product from collections import deque INF = 1e7 def main(): H, W = list(map(int, input().split())) ch, cw = [int(x)+1 for x in input().split()] dh, dw = [int(x)+1 for x in input().split()] S = [["#"]*(W+4) for _ in range(H+4)] # whites = [] # 道であるindex for i in range(2, H+2): tmp = eval(input()) for j in range(2, W+2): S[i][j] = tmp[j-2] # if S[i][j] == ".": # whites.append((i,j)) dxdy = [(1,0), (-1,0), (0,1), (0,-1)] magic = list(product(list(range(-2, 3)), repeat=2)) magic.remove((0, 0)) for to_remove in dxdy: magic.remove(to_remove) # graph = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for dx, dy in dxdy: # if S[x+dx][y+dy] == ".": # graph[idx].append((x+dx, y+dy)) # graph2 = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for mx, my in magic: # if S[x+mx][y+my] == ".": # graph2[idx].append((x+mx, y+my)) def bfs(u,v): dist = [[INF] * (W+4) for _ in range(H+4)] #indexed from 1 # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1 queue = deque() # seen[u][v] = 1 dist[u][v] = 0 queue.append((u,v)) while queue: p, q = queue.popleft() # if not graph[(p,q)]: # queue.popleft() # continue # g,h = graph[(p,q)].popleft() # if seen[g][h]: # continue # seen[g][h] = 1 # dist[g][h] = min(dist[g][h], dist[p][q]) for dx, dy in dxdy: g = p+dx h = q+dy if S[g][h]=="." and dist[g][h] > dist[p][q]: dist[g][h] = dist[p][q] queue.appendleft((g,h)) for dx, dy in magic: g = p+dx h = q+dy if S[g][h]=="." and dist[g][h] > dist[p][q]+1: dist[g][h] = dist[p][q]+1 queue.append((g,h)) # dist[g][h] = min(dist[g][h], dist[p][q]+1) # queue.append((g,h)) return dist D = bfs(ch, cw) ans = D[dh][dw] if ans == INF: print((-1)) else: print(ans) if __name__ == "__main__": main()
79
79
2,518
2,524
from itertools import product from collections import deque INF = 1e7 def main(): H, W = list(map(int, input().split())) ch, cw = [int(x) + 1 for x in input().split()] dh, dw = [int(x) + 1 for x in input().split()] S = [["#"] * (W + 4) for _ in range(H + 4)] whites = [] #  道であるindex for i in range(2, H + 2): tmp = eval(input()) for j in range(2, W + 2): S[i][j] = tmp[j - 2] if S[i][j] == ".": whites.append((i, j)) dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)] magic = list(product(list(range(-2, 3)), repeat=2)) magic.remove((0, 0)) for to_remove in dxdy: magic.remove(to_remove) # graph = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for dx, dy in dxdy: # if S[x+dx][y+dy] == ".": # graph[idx].append((x+dx, y+dy)) # graph2 = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for mx, my in magic: # if S[x+mx][y+my] == ".": # graph2[idx].append((x+mx, y+my)) def bfs(u, v): dist = [[INF] * (W + 4) for _ in range(H + 4)] # indexed from 1 # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1 queue = deque() # seen[u][v] = 1 dist[u][v] = 0 queue.append((u, v)) while queue: p, q = queue.popleft() # if not graph[(p,q)]: # queue.popleft() # continue # g,h = graph[(p,q)].popleft() # if seen[g][h]: # continue # seen[g][h] = 1 # dist[g][h] = min(dist[g][h], dist[p][q]) for dx, dy in dxdy: g = p + dx h = q + dy if S[g][h] == "." and dist[g][h] > dist[p][q]: dist[g][h] = dist[p][q] queue.appendleft((g, h)) for dx, dy in magic: g = p + dx h = q + dy if S[g][h] == "." and dist[g][h] > dist[p][q] + 1: dist[g][h] = dist[p][q] + 1 queue.append((g, h)) # dist[g][h] = min(dist[g][h], dist[p][q]+1) # queue.append((g,h)) return dist D = bfs(ch, cw) ans = D[dh][dw] if ans == INF: print((-1)) else: print(ans) if __name__ == "__main__": main()
from itertools import product from collections import deque INF = 1e7 def main(): H, W = list(map(int, input().split())) ch, cw = [int(x) + 1 for x in input().split()] dh, dw = [int(x) + 1 for x in input().split()] S = [["#"] * (W + 4) for _ in range(H + 4)] # whites = [] # 道であるindex for i in range(2, H + 2): tmp = eval(input()) for j in range(2, W + 2): S[i][j] = tmp[j - 2] # if S[i][j] == ".": # whites.append((i,j)) dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)] magic = list(product(list(range(-2, 3)), repeat=2)) magic.remove((0, 0)) for to_remove in dxdy: magic.remove(to_remove) # graph = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for dx, dy in dxdy: # if S[x+dx][y+dy] == ".": # graph[idx].append((x+dx, y+dy)) # graph2 = {idx: deque() for idx in whites} # for idx in whites: # x = idx[0] # y = idx[1] # for mx, my in magic: # if S[x+mx][y+my] == ".": # graph2[idx].append((x+mx, y+my)) def bfs(u, v): dist = [[INF] * (W + 4) for _ in range(H + 4)] # indexed from 1 # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1 queue = deque() # seen[u][v] = 1 dist[u][v] = 0 queue.append((u, v)) while queue: p, q = queue.popleft() # if not graph[(p,q)]: # queue.popleft() # continue # g,h = graph[(p,q)].popleft() # if seen[g][h]: # continue # seen[g][h] = 1 # dist[g][h] = min(dist[g][h], dist[p][q]) for dx, dy in dxdy: g = p + dx h = q + dy if S[g][h] == "." and dist[g][h] > dist[p][q]: dist[g][h] = dist[p][q] queue.appendleft((g, h)) for dx, dy in magic: g = p + dx h = q + dy if S[g][h] == "." and dist[g][h] > dist[p][q] + 1: dist[g][h] = dist[p][q] + 1 queue.append((g, h)) # dist[g][h] = min(dist[g][h], dist[p][q]+1) # queue.append((g,h)) return dist D = bfs(ch, cw) ans = D[dh][dw] if ans == INF: print((-1)) else: print(ans) if __name__ == "__main__": main()
false
0
[ "- whites = [] #  道であるindex", "+ # whites = [] # 道であるindex", "- if S[i][j] == \".\":", "- whites.append((i, j))", "+ # if S[i][j] == \".\":", "+ # whites.append((i,j))" ]
false
0.121488
0.106823
1.137286
[ "s675386827", "s249740018" ]
u216015528
p03086
python
s465123928
s657151505
63
28
61,892
8,872
Accepted
Accepted
55.56
#!/usr/bin/env python3 def main(): S = eval(input()) lst = set(['A', 'C', 'G', 'T']) cnt = 0 ans = 0 for s in S: if s in lst: cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans) if __name__ == '__main__': main()
def resolve(): S = eval(input()) ans, cnt = 0, 0 for s in S: if s == 'A' or s == 'C'or s == 'G' or s == 'T': cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans) resolve()
19
13
333
272
#!/usr/bin/env python3 def main(): S = eval(input()) lst = set(["A", "C", "G", "T"]) cnt = 0 ans = 0 for s in S: if s in lst: cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans) if __name__ == "__main__": main()
def resolve(): S = eval(input()) ans, cnt = 0, 0 for s in S: if s == "A" or s == "C" or s == "G" or s == "T": cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans) resolve()
false
31.578947
[ "-#!/usr/bin/env python3", "-def main():", "+def resolve():", "- lst = set([\"A\", \"C\", \"G\", \"T\"])", "- cnt = 0", "- ans = 0", "+ ans, cnt = 0, 0", "- if s in lst:", "+ if s == \"A\" or s == \"C\" or s == \"G\" or s == \"T\":", "-if __name__ == \"__main__\":", "- main()", "+resolve()" ]
false
0.045577
0.094605
0.481767
[ "s465123928", "s657151505" ]
u385167811
p03127
python
s167652063
s847488370
813
582
14,308
14,252
Accepted
Accepted
28.41
N = int(eval(input())) A = input().split(" ") A = [int(i) for i in A] list = [min(A)] A = sorted(A) iii = 0 while True: iii += 1 if A[N-1] % A[N-2] != 0: A[N-1] = A[N-1] % A[N-2] elif N >= 3 and A[N-1] % A[N-3] != 0: A[N-1] = A[N-1] % A[N-3] elif N >= 4 and A[N-1] % A[N-4] != 0: A[N-1] = A[N-1] % A[N-4] elif N >= 5 and A[N-1] % A[N-5] != 0: A[N-1] = A[N-1] % A[N-5] elif N >= 6 and A[N-1] % A[N-6] != 0: A[N-1] = A[N-1] % A[N-6] elif N >= 7 and A[N-1] % A[N-7] != 0: A[N-1] = A[N-1] % A[N-7] elif N >= 8 and A[N-1] % A[N-8] != 0: A[N-1] = A[N-1] % A[N-8] elif N >= 9 and A[N-1] % A[N-9] != 0: A[N-1] = A[N-1] % A[N-9] elif N >= 10 and A[N-1] % A[N-10] != 0: A[N-1] = A[N-1] % A[N-10] A = sorted(A) list.append(min(A)) if iii > 96: break #print(list) for i in range(N-1): if A[i+1]-A[i] > 0: list.append(A[i+1]-A[i]) #print(list) print((min(list)))
N = int(eval(input())) A = input().split(" ") A = [int(i) for i in A] list = [min(A)] A = sorted(A) iii = 0 while True: iii += 1 if A[N-1] % A[N-2] != 0: A[N-1] = A[N-1] % A[N-2] elif N >= 3 and A[N-1] % A[N-3] != 0: A[N-1] = A[N-1] % A[N-3] elif N >= 4 and A[N-1] % A[N-4] != 0: A[N-1] = A[N-1] % A[N-4] elif N >= 5 and A[N-1] % A[N-5] != 0: A[N-1] = A[N-1] % A[N-5] A = sorted(A) list.append(min(A)) if iii > 64: break #print(list) for i in range(N-1): if A[i+1]-A[i] > 0: list.append(A[i+1]-A[i]) #print(list) print((min(list)))
37
27
1,029
641
N = int(eval(input())) A = input().split(" ") A = [int(i) for i in A] list = [min(A)] A = sorted(A) iii = 0 while True: iii += 1 if A[N - 1] % A[N - 2] != 0: A[N - 1] = A[N - 1] % A[N - 2] elif N >= 3 and A[N - 1] % A[N - 3] != 0: A[N - 1] = A[N - 1] % A[N - 3] elif N >= 4 and A[N - 1] % A[N - 4] != 0: A[N - 1] = A[N - 1] % A[N - 4] elif N >= 5 and A[N - 1] % A[N - 5] != 0: A[N - 1] = A[N - 1] % A[N - 5] elif N >= 6 and A[N - 1] % A[N - 6] != 0: A[N - 1] = A[N - 1] % A[N - 6] elif N >= 7 and A[N - 1] % A[N - 7] != 0: A[N - 1] = A[N - 1] % A[N - 7] elif N >= 8 and A[N - 1] % A[N - 8] != 0: A[N - 1] = A[N - 1] % A[N - 8] elif N >= 9 and A[N - 1] % A[N - 9] != 0: A[N - 1] = A[N - 1] % A[N - 9] elif N >= 10 and A[N - 1] % A[N - 10] != 0: A[N - 1] = A[N - 1] % A[N - 10] A = sorted(A) list.append(min(A)) if iii > 96: break # print(list) for i in range(N - 1): if A[i + 1] - A[i] > 0: list.append(A[i + 1] - A[i]) # print(list) print((min(list)))
N = int(eval(input())) A = input().split(" ") A = [int(i) for i in A] list = [min(A)] A = sorted(A) iii = 0 while True: iii += 1 if A[N - 1] % A[N - 2] != 0: A[N - 1] = A[N - 1] % A[N - 2] elif N >= 3 and A[N - 1] % A[N - 3] != 0: A[N - 1] = A[N - 1] % A[N - 3] elif N >= 4 and A[N - 1] % A[N - 4] != 0: A[N - 1] = A[N - 1] % A[N - 4] elif N >= 5 and A[N - 1] % A[N - 5] != 0: A[N - 1] = A[N - 1] % A[N - 5] A = sorted(A) list.append(min(A)) if iii > 64: break # print(list) for i in range(N - 1): if A[i + 1] - A[i] > 0: list.append(A[i + 1] - A[i]) # print(list) print((min(list)))
false
27.027027
[ "- elif N >= 6 and A[N - 1] % A[N - 6] != 0:", "- A[N - 1] = A[N - 1] % A[N - 6]", "- elif N >= 7 and A[N - 1] % A[N - 7] != 0:", "- A[N - 1] = A[N - 1] % A[N - 7]", "- elif N >= 8 and A[N - 1] % A[N - 8] != 0:", "- A[N - 1] = A[N - 1] % A[N - 8]", "- elif N >= 9 and A[N - 1] % A[N - 9] != 0:", "- A[N - 1] = A[N - 1] % A[N - 9]", "- elif N >= 10 and A[N - 1] % A[N - 10] != 0:", "- A[N - 1] = A[N - 1] % A[N - 10]", "- if iii > 96:", "+ if iii > 64:" ]
false
0.044127
0.043669
1.010501
[ "s167652063", "s847488370" ]
u014333473
p03408
python
s319553334
s961883276
29
25
9,068
9,084
Accepted
Accepted
13.79
r1=[eval(input()) for _ in range(int(eval(input())))];r2=[eval(input()) for _ in range(int(eval(input())))];ans=0 for i in set(r1): ans=max(ans,r1.count(i)-r2.count(i)) print(ans)
r1,r2=[eval(input()) for _ in range(int(eval(input())))],[eval(input()) for _ in range(int(eval(input())))];ans=0 ans=[r1.count(i)-r2.count(i) for i in set(r1)];print((max(0,max(ans))))
3
2
157
160
r1 = [eval(input()) for _ in range(int(eval(input())))] r2 = [eval(input()) for _ in range(int(eval(input())))] ans = 0 for i in set(r1): ans = max(ans, r1.count(i) - r2.count(i)) print(ans)
r1, r2 = [eval(input()) for _ in range(int(eval(input())))], [ eval(input()) for _ in range(int(eval(input()))) ] ans = 0 ans = [r1.count(i) - r2.count(i) for i in set(r1)] print((max(0, max(ans))))
false
33.333333
[ "-r1 = [eval(input()) for _ in range(int(eval(input())))]", "-r2 = [eval(input()) for _ in range(int(eval(input())))]", "+r1, r2 = [eval(input()) for _ in range(int(eval(input())))], [", "+ eval(input()) for _ in range(int(eval(input())))", "+]", "-for i in set(r1):", "- ans = max(ans, r1.count(i) - r2.count(i))", "-print(ans)", "+ans = [r1.count(i) - r2.count(i) for i in set(r1)]", "+print((max(0, max(ans))))" ]
false
0.038334
0.036124
1.061179
[ "s319553334", "s961883276" ]
u724687935
p03147
python
s700736334
s550218238
23
17
3,188
2,940
Accepted
Accepted
26.09
N = int(eval(input())) H = list(map(int, input().split())) H.append(0) t = 1 ans = 0 while t > 0: p = H[-1] t = 0 for i in range(N): if H[i] > 0 and p <= 0: ans += 1 p = H[i] H[i] -= 1 t = max(H[i], t) #print(ans, H[i], t) print(ans)
N = int(eval(input())) H = list(map(int, input().split())) ans = 0 pre = 0 for h in H: if pre < h: ans += h - pre pre = h print(ans)
18
12
311
157
N = int(eval(input())) H = list(map(int, input().split())) H.append(0) t = 1 ans = 0 while t > 0: p = H[-1] t = 0 for i in range(N): if H[i] > 0 and p <= 0: ans += 1 p = H[i] H[i] -= 1 t = max(H[i], t) # print(ans, H[i], t) print(ans)
N = int(eval(input())) H = list(map(int, input().split())) ans = 0 pre = 0 for h in H: if pre < h: ans += h - pre pre = h print(ans)
false
33.333333
[ "-H.append(0)", "-t = 1", "-while t > 0:", "- p = H[-1]", "- t = 0", "- for i in range(N):", "- if H[i] > 0 and p <= 0:", "- ans += 1", "- p = H[i]", "- H[i] -= 1", "- t = max(H[i], t)", "- # print(ans, H[i], t)", "+pre = 0", "+for h in H:", "+ if pre < h:", "+ ans += h - pre", "+ pre = h" ]
false
0.038837
0.075958
0.511291
[ "s700736334", "s550218238" ]
u021548497
p02788
python
s385460761
s815402649
1,679
1,287
70,308
53,448
Accepted
Accepted
23.35
import bisect n, d, a = list(map(int, input().split())) fox = [None]*n for i in range(n): x, h = list(map(int, input().split())) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0]*n for i in range(n): if i != 0: bit[i] += bit[i-1] if bit[i] >= h[i]: continue sub = (h[i]-bit[i]-1)//a+1 ans += sub bit[i] += sub*a index = bisect.bisect_right(x, x[i]+2*d) if index == n: continue bit[index] -= sub*a print(ans)
import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) fox = [list(map(int, input().split())) for _ in range(n)] fox.sort() sub = [0]*(n+1) def bisect(x): l, r = 0, n while r-l > 1: k = (r+l)//2 if fox[k][0] <= x: l = k else: r = k if fox[l][0] <= x: return l return r def main(): ans = 0 for i in range(n): if i != 0: sub[i] += sub[i-1] if fox[i][1]-a*sub[i] <= 0: continue count = (fox[i][1]-sub[i]*a-1)//a+1 ans += count sub[i] += count sub[bisect(fox[i][0]+2*d)+1] -= count print(ans) if __name__ == "__main__": main()
26
42
527
762
import bisect n, d, a = list(map(int, input().split())) fox = [None] * n for i in range(n): x, h = list(map(int, input().split())) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0] * n for i in range(n): if i != 0: bit[i] += bit[i - 1] if bit[i] >= h[i]: continue sub = (h[i] - bit[i] - 1) // a + 1 ans += sub bit[i] += sub * a index = bisect.bisect_right(x, x[i] + 2 * d) if index == n: continue bit[index] -= sub * a print(ans)
import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) fox = [list(map(int, input().split())) for _ in range(n)] fox.sort() sub = [0] * (n + 1) def bisect(x): l, r = 0, n while r - l > 1: k = (r + l) // 2 if fox[k][0] <= x: l = k else: r = k if fox[l][0] <= x: return l return r def main(): ans = 0 for i in range(n): if i != 0: sub[i] += sub[i - 1] if fox[i][1] - a * sub[i] <= 0: continue count = (fox[i][1] - sub[i] * a - 1) // a + 1 ans += count sub[i] += count sub[bisect(fox[i][0] + 2 * d) + 1] -= count print(ans) if __name__ == "__main__": main()
false
38.095238
[ "-import bisect", "+import sys", "+input = sys.stdin.readline", "-fox = [None] * n", "-for i in range(n):", "- x, h = list(map(int, input().split()))", "- fox[i] = (x, h)", "+fox = [list(map(int, input().split())) for _ in range(n)]", "-x = [int(fox[i][0]) for i in range(n)]", "-h = [int(fox[i][1]) for i in range(n)]", "-ans = 0", "-bit = [0] * n", "-for i in range(n):", "- if i != 0:", "- bit[i] += bit[i - 1]", "- if bit[i] >= h[i]:", "- continue", "- sub = (h[i] - bit[i] - 1) // a + 1", "- ans += sub", "- bit[i] += sub * a", "- index = bisect.bisect_right(x, x[i] + 2 * d)", "- if index == n:", "- continue", "- bit[index] -= sub * a", "-print(ans)", "+sub = [0] * (n + 1)", "+", "+", "+def bisect(x):", "+ l, r = 0, n", "+ while r - l > 1:", "+ k = (r + l) // 2", "+ if fox[k][0] <= x:", "+ l = k", "+ else:", "+ r = k", "+ if fox[l][0] <= x:", "+ return l", "+ return r", "+", "+", "+def main():", "+ ans = 0", "+ for i in range(n):", "+ if i != 0:", "+ sub[i] += sub[i - 1]", "+ if fox[i][1] - a * sub[i] <= 0:", "+ continue", "+ count = (fox[i][1] - sub[i] * a - 1) // a + 1", "+ ans += count", "+ sub[i] += count", "+ sub[bisect(fox[i][0] + 2 * d) + 1] -= count", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.08599
0.080002
1.074848
[ "s385460761", "s815402649" ]
u746419473
p02812
python
s636683771
s978647131
20
17
2,940
2,940
Accepted
Accepted
15
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n-2): if s[i:i+3] == "ABC": ans += 1 print(ans)
n = int(eval(input())) *s, = eval(input()) ans = 0 for i in range(n-2): if "".join(s[i:i+3]) == "ABC": ans += 1 print(ans)
9
9
122
133
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n - 2): if s[i : i + 3] == "ABC": ans += 1 print(ans)
n = int(eval(input())) (*s,) = eval(input()) ans = 0 for i in range(n - 2): if "".join(s[i : i + 3]) == "ABC": ans += 1 print(ans)
false
0
[ "-s = eval(input())", "+(*s,) = eval(input())", "- if s[i : i + 3] == \"ABC\":", "+ if \"\".join(s[i : i + 3]) == \"ABC\":" ]
false
0.047116
0.039409
1.195575
[ "s636683771", "s978647131" ]
u692746605
p02726
python
s480536267
s887338803
1,812
902
3,572
3,444
Accepted
Accepted
50.22
N,X,Y=list(map(int,input().split())) C=[0]*N for i in range(1,N): for j in range(i+1,N+1): C[min(j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))]+=1 for i in range(1,N): print((C[i]))
def main(): N,X,Y=list(map(int,input().split())) C=[0]*N for i in range(1,N): for j in range(i+1,N+1): C[min(j-i,abs(X-i)+1+abs(j-Y))]+=1 for i in range(1,N): print((C[i])) main()
9
11
191
206
N, X, Y = list(map(int, input().split())) C = [0] * N for i in range(1, N): for j in range(i + 1, N + 1): C[min(j - i, abs(X - i) + 1 + abs(j - Y), abs(Y - i) + 1 + abs(j - X))] += 1 for i in range(1, N): print((C[i]))
def main(): N, X, Y = list(map(int, input().split())) C = [0] * N for i in range(1, N): for j in range(i + 1, N + 1): C[min(j - i, abs(X - i) + 1 + abs(j - Y))] += 1 for i in range(1, N): print((C[i])) main()
false
18.181818
[ "-N, X, Y = list(map(int, input().split()))", "-C = [0] * N", "-for i in range(1, N):", "- for j in range(i + 1, N + 1):", "- C[min(j - i, abs(X - i) + 1 + abs(j - Y), abs(Y - i) + 1 + abs(j - X))] += 1", "-for i in range(1, N):", "- print((C[i]))", "+def main():", "+ N, X, Y = list(map(int, input().split()))", "+ C = [0] * N", "+ for i in range(1, N):", "+ for j in range(i + 1, N + 1):", "+ C[min(j - i, abs(X - i) + 1 + abs(j - Y))] += 1", "+ for i in range(1, N):", "+ print((C[i]))", "+", "+", "+main()" ]
false
0.126337
0.131014
0.964301
[ "s480536267", "s887338803" ]
u620084012
p02724
python
s591974023
s985323375
173
26
38,384
9,168
Accepted
Accepted
84.97
X = int(eval(input())) print((1000*(X//500) + 5*((X-500*(X//500))//5)))
X = int(eval(input())) ans = 1000*(X//500) X -= 500*(X//500) ans += 5*(X//5) print(ans)
2
5
65
85
X = int(eval(input())) print((1000 * (X // 500) + 5 * ((X - 500 * (X // 500)) // 5)))
X = int(eval(input())) ans = 1000 * (X // 500) X -= 500 * (X // 500) ans += 5 * (X // 5) print(ans)
false
60
[ "-print((1000 * (X // 500) + 5 * ((X - 500 * (X // 500)) // 5)))", "+ans = 1000 * (X // 500)", "+X -= 500 * (X // 500)", "+ans += 5 * (X // 5)", "+print(ans)" ]
false
0.079014
0.040732
1.939841
[ "s591974023", "s985323375" ]
u888092736
p02768
python
s855022653
s604300188
144
122
3,064
9,156
Accepted
Accepted
15.28
def cmb(n, r, p): # nume/deno === nume * pow(deno, p - 2, p) (mod p) nume, deno = 1, 1 for i in range(r): nume = nume * (n - i) % p deno = deno * (i + 1) % p return nume * pow(deno, p - 2, p) % p if __name__ == "__main__": n, a, b = list(map(int, input().split())) p = 10 ** 9 + 7 print(((pow(2, n, p) - cmb(n, a, p) - cmb(n, b, p) - 1) % p))
def comb(n, r, p): num, den = 1, 1 r = min(r, n - r) for i in range(1, r + 1): num = num * (n - i + 1) % p den = den * i % p return num * pow(den, p - 2, p) % p n, a, b = list(map(int, input().split())) MOD = 1_000_000_007 ans = pow(2, n, MOD) ans %= MOD ans -= comb(n, a, MOD) ans %= MOD ans -= comb(n, b, MOD) ans %= MOD ans -= 1 ans %= MOD print(ans)
14
20
395
401
def cmb(n, r, p): # nume/deno === nume * pow(deno, p - 2, p) (mod p) nume, deno = 1, 1 for i in range(r): nume = nume * (n - i) % p deno = deno * (i + 1) % p return nume * pow(deno, p - 2, p) % p if __name__ == "__main__": n, a, b = list(map(int, input().split())) p = 10**9 + 7 print(((pow(2, n, p) - cmb(n, a, p) - cmb(n, b, p) - 1) % p))
def comb(n, r, p): num, den = 1, 1 r = min(r, n - r) for i in range(1, r + 1): num = num * (n - i + 1) % p den = den * i % p return num * pow(den, p - 2, p) % p n, a, b = list(map(int, input().split())) MOD = 1_000_000_007 ans = pow(2, n, MOD) ans %= MOD ans -= comb(n, a, MOD) ans %= MOD ans -= comb(n, b, MOD) ans %= MOD ans -= 1 ans %= MOD print(ans)
false
30
[ "-def cmb(n, r, p):", "- # nume/deno === nume * pow(deno, p - 2, p) (mod p)", "- nume, deno = 1, 1", "- for i in range(r):", "- nume = nume * (n - i) % p", "- deno = deno * (i + 1) % p", "- return nume * pow(deno, p - 2, p) % p", "+def comb(n, r, p):", "+ num, den = 1, 1", "+ r = min(r, n - r)", "+ for i in range(1, r + 1):", "+ num = num * (n - i + 1) % p", "+ den = den * i % p", "+ return num * pow(den, p - 2, p) % p", "-if __name__ == \"__main__\":", "- n, a, b = list(map(int, input().split()))", "- p = 10**9 + 7", "- print(((pow(2, n, p) - cmb(n, a, p) - cmb(n, b, p) - 1) % p))", "+n, a, b = list(map(int, input().split()))", "+MOD = 1_000_000_007", "+ans = pow(2, n, MOD)", "+ans %= MOD", "+ans -= comb(n, a, MOD)", "+ans %= MOD", "+ans -= comb(n, b, MOD)", "+ans %= MOD", "+ans -= 1", "+ans %= MOD", "+print(ans)" ]
false
0.083548
0.083761
0.997458
[ "s855022653", "s604300188" ]
u620084012
p03287
python
s681647002
s537819370
121
91
17,624
16,552
Accepted
Accepted
24.79
from collections import Counter N, M = list(map(int,input().split())) A = list(map(int, input().split())) ans = 0 S = [0 for k in range(N)] S[0] = A[0] for k in range(1,N): S[k] = S[k-1] + A[k] S = [0] + S for k in range(N+1): S[k] %= M C = Counter(S) for a in C: if C[a] >= 2: ans += (C[a]*(C[a]-1))//2 print(ans)
import sys from collections import Counter def input(): return sys.stdin.readline()[:-1] def main(): N, M = list(map(int,input().split())) A = list(map(int,input().split())) S = [0]*N S[0] = A[0]%M for k in range(1,N): S[k] = (S[k-1] + A[k])%M C = Counter(S) C[0] += 1 ans = 0 for e in C: ans += (C[e]*(C[e]-1))//2 print(ans) if __name__ == '__main__': main()
18
19
347
436
from collections import Counter N, M = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 S = [0 for k in range(N)] S[0] = A[0] for k in range(1, N): S[k] = S[k - 1] + A[k] S = [0] + S for k in range(N + 1): S[k] %= M C = Counter(S) for a in C: if C[a] >= 2: ans += (C[a] * (C[a] - 1)) // 2 print(ans)
import sys from collections import Counter def input(): return sys.stdin.readline()[:-1] def main(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) S = [0] * N S[0] = A[0] % M for k in range(1, N): S[k] = (S[k - 1] + A[k]) % M C = Counter(S) C[0] += 1 ans = 0 for e in C: ans += (C[e] * (C[e] - 1)) // 2 print(ans) if __name__ == "__main__": main()
false
5.263158
[ "+import sys", "-N, M = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-ans = 0", "-S = [0 for k in range(N)]", "-S[0] = A[0]", "-for k in range(1, N):", "- S[k] = S[k - 1] + A[k]", "-S = [0] + S", "-for k in range(N + 1):", "- S[k] %= M", "-C = Counter(S)", "-for a in C:", "- if C[a] >= 2:", "- ans += (C[a] * (C[a] - 1)) // 2", "-print(ans)", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def main():", "+ N, M = list(map(int, input().split()))", "+ A = list(map(int, input().split()))", "+ S = [0] * N", "+ S[0] = A[0] % M", "+ for k in range(1, N):", "+ S[k] = (S[k - 1] + A[k]) % M", "+ C = Counter(S)", "+ C[0] += 1", "+ ans = 0", "+ for e in C:", "+ ans += (C[e] * (C[e] - 1)) // 2", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.061955
0.038405
1.613191
[ "s681647002", "s537819370" ]
u057109575
p02803
python
s959536821
s693002903
244
122
44,508
75,120
Accepted
Accepted
50
from collections import deque H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] def solve(x, y): offset = [(1, 0), (-1, 0), (0, 1), (0, -1)] visited = [[-1] * W for _ in range(H)] visited[y][x] = 0 q = deque() q.append((x, y)) while q: x, y = q.popleft() for u, v in offset: if not (0 <= x + u < W) or not (0 <= y + v < H): continue if visited[y + v][x + u] > -1 or S[y + v][x + u] == "#": continue visited[y + v][x + u] = visited[y][x] + 1 q.append((x + u, y + v)) return visited ans = 0 for y, ss in enumerate(S): for x, s in enumerate(ss): if s == ".": ans = max(ans, max(max(v) for v in solve(x, y))) print(ans)
from collections import deque H, W = list(map(int, input().split())) X = [eval(input()) for _ in range(H)] def solve_maze(s): bias = [(0, 1), (0, -1), (1, 0), (-1, 0)] inf = 10 ** 9 d = [[inf] * W for _ in range(H)] d[s[0]][s[1]] = 0 q = deque() q.append(s) while q: u, v = q.popleft() for i, j in bias: if (0 <= u + i < H and 0 <= v + j < W and X[u + i][v + j] == "." and d[u + i][v + j] > d[u][v] + 1): d[u + i][v + j] = d[u][v] + 1 q.append((u + i, v + j)) res = 0 for i in range(H): for j in range(W): if d[i][j] < inf: res = max(res, d[i][j]) return res ans = 0 for i in range(H): for j in range(W): if X[i][j] == ".": ans = max(ans, solve_maze((i, j))) print(ans)
35
40
839
923
from collections import deque H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] def solve(x, y): offset = [(1, 0), (-1, 0), (0, 1), (0, -1)] visited = [[-1] * W for _ in range(H)] visited[y][x] = 0 q = deque() q.append((x, y)) while q: x, y = q.popleft() for u, v in offset: if not (0 <= x + u < W) or not (0 <= y + v < H): continue if visited[y + v][x + u] > -1 or S[y + v][x + u] == "#": continue visited[y + v][x + u] = visited[y][x] + 1 q.append((x + u, y + v)) return visited ans = 0 for y, ss in enumerate(S): for x, s in enumerate(ss): if s == ".": ans = max(ans, max(max(v) for v in solve(x, y))) print(ans)
from collections import deque H, W = list(map(int, input().split())) X = [eval(input()) for _ in range(H)] def solve_maze(s): bias = [(0, 1), (0, -1), (1, 0), (-1, 0)] inf = 10**9 d = [[inf] * W for _ in range(H)] d[s[0]][s[1]] = 0 q = deque() q.append(s) while q: u, v = q.popleft() for i, j in bias: if ( 0 <= u + i < H and 0 <= v + j < W and X[u + i][v + j] == "." and d[u + i][v + j] > d[u][v] + 1 ): d[u + i][v + j] = d[u][v] + 1 q.append((u + i, v + j)) res = 0 for i in range(H): for j in range(W): if d[i][j] < inf: res = max(res, d[i][j]) return res ans = 0 for i in range(H): for j in range(W): if X[i][j] == ".": ans = max(ans, solve_maze((i, j))) print(ans)
false
12.5
[ "-S = [eval(input()) for _ in range(H)]", "+X = [eval(input()) for _ in range(H)]", "-def solve(x, y):", "- offset = [(1, 0), (-1, 0), (0, 1), (0, -1)]", "- visited = [[-1] * W for _ in range(H)]", "- visited[y][x] = 0", "+def solve_maze(s):", "+ bias = [(0, 1), (0, -1), (1, 0), (-1, 0)]", "+ inf = 10**9", "+ d = [[inf] * W for _ in range(H)]", "+ d[s[0]][s[1]] = 0", "- q.append((x, y))", "+ q.append(s)", "- x, y = q.popleft()", "- for u, v in offset:", "- if not (0 <= x + u < W) or not (0 <= y + v < H):", "- continue", "- if visited[y + v][x + u] > -1 or S[y + v][x + u] == \"#\":", "- continue", "- visited[y + v][x + u] = visited[y][x] + 1", "- q.append((x + u, y + v))", "- return visited", "+ u, v = q.popleft()", "+ for i, j in bias:", "+ if (", "+ 0 <= u + i < H", "+ and 0 <= v + j < W", "+ and X[u + i][v + j] == \".\"", "+ and d[u + i][v + j] > d[u][v] + 1", "+ ):", "+ d[u + i][v + j] = d[u][v] + 1", "+ q.append((u + i, v + j))", "+ res = 0", "+ for i in range(H):", "+ for j in range(W):", "+ if d[i][j] < inf:", "+ res = max(res, d[i][j])", "+ return res", "-for y, ss in enumerate(S):", "- for x, s in enumerate(ss):", "- if s == \".\":", "- ans = max(ans, max(max(v) for v in solve(x, y)))", "+for i in range(H):", "+ for j in range(W):", "+ if X[i][j] == \".\":", "+ ans = max(ans, solve_maze((i, j)))" ]
false
0.039114
0.039107
1.000181
[ "s959536821", "s693002903" ]
u022979415
p03408
python
s669143914
s035232635
20
18
3,064
3,064
Accepted
Accepted
10
def get_info(diff): length = int(eval(input())) strings = {} for _ in range(length): tmp = eval(input()) if tmp in strings: strings[tmp] += diff else: strings[tmp] = diff return length, strings def main(): blue_card, blue_card_str = get_info(1) red_card, red_card_str = get_info(-1) answer = 0 available_keys = (list(blue_card_str.keys()) & list(red_card_str.keys())) | list(blue_card_str.keys()) for key in available_keys: if key in red_card_str: diff = blue_card_str[key] + red_card_str[key] else: diff = blue_card_str[key] answer = max(answer, diff) print(answer) if __name__ == '__main__': main()
def main(): n = int(eval(input())) card = {} for _ in range(n): s = eval(input()) if s in card: card[s] += 1 else: card[s] = 1 m = int(eval(input())) for _ in range(m): t = eval(input()) if t in card: card[t] -= 1 else: card[t] = -1 card = sorted(list(card.items()), key=lambda x: x[1], reverse=True) print((max(card[0][1], 0))) if __name__ == '__main__': main()
28
23
741
484
def get_info(diff): length = int(eval(input())) strings = {} for _ in range(length): tmp = eval(input()) if tmp in strings: strings[tmp] += diff else: strings[tmp] = diff return length, strings def main(): blue_card, blue_card_str = get_info(1) red_card, red_card_str = get_info(-1) answer = 0 available_keys = (list(blue_card_str.keys()) & list(red_card_str.keys())) | list( blue_card_str.keys() ) for key in available_keys: if key in red_card_str: diff = blue_card_str[key] + red_card_str[key] else: diff = blue_card_str[key] answer = max(answer, diff) print(answer) if __name__ == "__main__": main()
def main(): n = int(eval(input())) card = {} for _ in range(n): s = eval(input()) if s in card: card[s] += 1 else: card[s] = 1 m = int(eval(input())) for _ in range(m): t = eval(input()) if t in card: card[t] -= 1 else: card[t] = -1 card = sorted(list(card.items()), key=lambda x: x[1], reverse=True) print((max(card[0][1], 0))) if __name__ == "__main__": main()
false
17.857143
[ "-def get_info(diff):", "- length = int(eval(input()))", "- strings = {}", "- for _ in range(length):", "- tmp = eval(input())", "- if tmp in strings:", "- strings[tmp] += diff", "+def main():", "+ n = int(eval(input()))", "+ card = {}", "+ for _ in range(n):", "+ s = eval(input())", "+ if s in card:", "+ card[s] += 1", "- strings[tmp] = diff", "- return length, strings", "-", "-", "-def main():", "- blue_card, blue_card_str = get_info(1)", "- red_card, red_card_str = get_info(-1)", "- answer = 0", "- available_keys = (list(blue_card_str.keys()) & list(red_card_str.keys())) | list(", "- blue_card_str.keys()", "- )", "- for key in available_keys:", "- if key in red_card_str:", "- diff = blue_card_str[key] + red_card_str[key]", "+ card[s] = 1", "+ m = int(eval(input()))", "+ for _ in range(m):", "+ t = eval(input())", "+ if t in card:", "+ card[t] -= 1", "- diff = blue_card_str[key]", "- answer = max(answer, diff)", "- print(answer)", "+ card[t] = -1", "+ card = sorted(list(card.items()), key=lambda x: x[1], reverse=True)", "+ print((max(card[0][1], 0)))" ]
false
0.04692
0.046517
1.008653
[ "s669143914", "s035232635" ]
u623819879
p02744
python
s085511273
s300658245
400
358
83,420
82,524
Accepted
Accepted
10.5
# coding: utf-8 # Your code here! def solv1(): n=int(eval(input())) a=[[]for i in range(n)] a[0]=[[0]] for i in range(n-1): b=[] for pa in a[i]: # print(pa) el=[j for j in set(pa)] # print(el) el.append(max(pa)+1) for l in el: b+=[pa+[l]] # print(i,b) a[i+1]=b ans=[j for j in a[n-1]] #print(i) ans=sorted(ans) for i in ans: print((''.join([chr(j+97) for j in i]))) solv1()
# coding: utf-8 # Your code here! def solv1(): n=int(eval(input())) a=[[]for i in range(n)] a[0]=[[0]] for i in range(n-1): b=[] for pa in a[i]: # print(pa) el=[j for j in set(pa)] # print(el) el.append(max(pa)+1) for l in el: b+=[pa+[l]] # print(i,b) a[i+1]=b ans=[j for j in a[n-1]] #print(i) #ans=sorted(ans) for i in ans: print((''.join([chr(j+97) for j in i]))) solv1()
26
26
551
552
# coding: utf-8 # Your code here! def solv1(): n = int(eval(input())) a = [[] for i in range(n)] a[0] = [[0]] for i in range(n - 1): b = [] for pa in a[i]: # print(pa) el = [j for j in set(pa)] # print(el) el.append(max(pa) + 1) for l in el: b += [pa + [l]] # print(i,b) a[i + 1] = b ans = [j for j in a[n - 1]] # print(i) ans = sorted(ans) for i in ans: print(("".join([chr(j + 97) for j in i]))) solv1()
# coding: utf-8 # Your code here! def solv1(): n = int(eval(input())) a = [[] for i in range(n)] a[0] = [[0]] for i in range(n - 1): b = [] for pa in a[i]: # print(pa) el = [j for j in set(pa)] # print(el) el.append(max(pa) + 1) for l in el: b += [pa + [l]] # print(i,b) a[i + 1] = b ans = [j for j in a[n - 1]] # print(i) # ans=sorted(ans) for i in ans: print(("".join([chr(j + 97) for j in i]))) solv1()
false
0
[ "- ans = sorted(ans)", "+ # ans=sorted(ans)" ]
false
0.15621
0.058153
2.686191
[ "s085511273", "s300658245" ]
u243572357
p02811
python
s809834014
s662509651
19
17
3,060
2,940
Accepted
Accepted
10.53
k, x = list(map(int, input().split())) print(('Yes' if k*500 >= x else 'No'))
a, b = list(map(int, input().split())) print(('Yes' if a*500 >= b else 'No'))
2
2
70
70
k, x = list(map(int, input().split())) print(("Yes" if k * 500 >= x else "No"))
a, b = list(map(int, input().split())) print(("Yes" if a * 500 >= b else "No"))
false
0
[ "-k, x = list(map(int, input().split()))", "-print((\"Yes\" if k * 500 >= x else \"No\"))", "+a, b = list(map(int, input().split()))", "+print((\"Yes\" if a * 500 >= b else \"No\"))" ]
false
0.048068
0.051621
0.93118
[ "s809834014", "s662509651" ]
u156815136
p02720
python
s845199493
s333644226
433
104
76,380
20,128
Accepted
Accepted
75.98
import sys sys.setrecursionlimit(10**7) k = int(eval(input())) from collections import deque d = deque() for i in range(9): d.append(str(i+1)) # 初期 def dfs(): global cnt a = d.popleft() #print(cnt) for i in range(-1,2,1): nya = a last_string = int(a[-1]) + i if last_string < 0 or last_string > 9: pass else: nya += str(last_string) cnt += 1 if k == cnt: print(nya) exit() d.append(nya) dfs() cnt = 9 if k <= cnt: print(k) exit() dfs()
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) k = I() que = deque([]) for i in range(1,10): que.append(i) if k <= 9: print((que[k-1])) exit() while que: num = que.popleft() if k == 1: print(num) exit() lo = num%10 if 0 <= lo - 1: que.append(num*10 + lo-1) que.append(num*10 + lo) if lo + 1 <= 9: que.append(num*10 + lo + 1) k -= 1
32
45
624
955
import sys sys.setrecursionlimit(10**7) k = int(eval(input())) from collections import deque d = deque() for i in range(9): d.append(str(i + 1)) # 初期 def dfs(): global cnt a = d.popleft() # print(cnt) for i in range(-1, 2, 1): nya = a last_string = int(a[-1]) + i if last_string < 0 or last_string > 9: pass else: nya += str(last_string) cnt += 1 if k == cnt: print(nya) exit() d.append(nya) dfs() cnt = 9 if k <= cnt: print(k) exit() dfs()
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) k = I() que = deque([]) for i in range(1, 10): que.append(i) if k <= 9: print((que[k - 1])) exit() while que: num = que.popleft() if k == 1: print(num) exit() lo = num % 10 if 0 <= lo - 1: que.append(num * 10 + lo - 1) que.append(num * 10 + lo) if lo + 1 <= 9: que.append(num * 10 + lo + 1) k -= 1
false
28.888889
[ "+from statistics import median", "+", "+# import collections", "+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "+from fractions import gcd", "+from itertools import combinations # (string,3) 3回", "+from collections import deque", "+from collections import defaultdict", "+import bisect", "+", "+#", "+# d = m - k[i] - k[j]", "+# if kk[bisect.bisect_right(kk,d) - 1] == d:", "+#", "+#", "+#", "+# pythonで無理なときは、pypyでやると正解するかも!!", "+#", "+#", "-sys.setrecursionlimit(10**7)", "-k = int(eval(input()))", "-from collections import deque", "-", "-d = deque()", "-for i in range(9):", "- d.append(str(i + 1)) # 初期", "+sys.setrecursionlimit(10000000)", "+mod = 10**9 + 7", "-def dfs():", "- global cnt", "- a = d.popleft()", "- # print(cnt)", "- for i in range(-1, 2, 1):", "- nya = a", "- last_string = int(a[-1]) + i", "- if last_string < 0 or last_string > 9:", "- pass", "- else:", "- nya += str(last_string)", "- cnt += 1", "- if k == cnt:", "- print(nya)", "- exit()", "- d.append(nya)", "- dfs()", "+def readInts():", "+ return list(map(int, input().split()))", "-cnt = 9", "-if k <= cnt:", "- print(k)", "+def I():", "+ return int(eval(input()))", "+", "+", "+k = I()", "+que = deque([])", "+for i in range(1, 10):", "+ que.append(i)", "+if k <= 9:", "+ print((que[k - 1]))", "-dfs()", "+while que:", "+ num = que.popleft()", "+ if k == 1:", "+ print(num)", "+ exit()", "+ lo = num % 10", "+ if 0 <= lo - 1:", "+ que.append(num * 10 + lo - 1)", "+ que.append(num * 10 + lo)", "+ if lo + 1 <= 9:", "+ que.append(num * 10 + lo + 1)", "+ k -= 1" ]
false
0.079095
0.06289
1.257686
[ "s845199493", "s333644226" ]
u761320129
p04020
python
s859036855
s858236339
211
189
7,328
7,072
Accepted
Accepted
10.43
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] rem = 0 ans = 0 for a in A: ans += (rem+a)//2 rem = 0 if a==0 else (rem+a)%2 print(ans)
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = ans = 0 for a in A: if a==0: ans += c//2 c = 0 else: c += a ans += c//2 print(ans)
8
12
156
184
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] rem = 0 ans = 0 for a in A: ans += (rem + a) // 2 rem = 0 if a == 0 else (rem + a) % 2 print(ans)
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = ans = 0 for a in A: if a == 0: ans += c // 2 c = 0 else: c += a ans += c // 2 print(ans)
false
33.333333
[ "-rem = 0", "-ans = 0", "+c = ans = 0", "- ans += (rem + a) // 2", "- rem = 0 if a == 0 else (rem + a) % 2", "+ if a == 0:", "+ ans += c // 2", "+ c = 0", "+ else:", "+ c += a", "+ans += c // 2" ]
false
0.044624
0.066047
0.67565
[ "s859036855", "s858236339" ]
u726615467
p02988
python
s860188454
s161361394
21
18
3,316
3,060
Accepted
Accepted
14.29
# encoding: utf-8 import sys # input = sys.stdin.readline N = int(eval(input())) p = list(map(int, input().split())) ans = 0 for i in range(N - 2): pool = [p[i], p[i + 1], p[i + 2]] if min(pool) == p[i + 1]: continue if max(pool) == p[i + 1]: continue # ans += 1 print(ans)
n = int(eval(input())) p = list(map(int, input().split())) ans = 0 for i in range(n - 2): if p[i] <= p[i + 1] < p[i + 2]: ans += 1 elif p[i + 2] <= p[i + 1] < p[i]: ans += 1 else: continue print(ans)
18
13
323
244
# encoding: utf-8 import sys # input = sys.stdin.readline N = int(eval(input())) p = list(map(int, input().split())) ans = 0 for i in range(N - 2): pool = [p[i], p[i + 1], p[i + 2]] if min(pool) == p[i + 1]: continue if max(pool) == p[i + 1]: continue # ans += 1 print(ans)
n = int(eval(input())) p = list(map(int, input().split())) ans = 0 for i in range(n - 2): if p[i] <= p[i + 1] < p[i + 2]: ans += 1 elif p[i + 2] <= p[i + 1] < p[i]: ans += 1 else: continue print(ans)
false
27.777778
[ "-# encoding: utf-8", "-import sys", "-", "-# input = sys.stdin.readline", "-N = int(eval(input()))", "+n = int(eval(input()))", "-for i in range(N - 2):", "- pool = [p[i], p[i + 1], p[i + 2]]", "- if min(pool) == p[i + 1]:", "+for i in range(n - 2):", "+ if p[i] <= p[i + 1] < p[i + 2]:", "+ ans += 1", "+ elif p[i + 2] <= p[i + 1] < p[i]:", "+ ans += 1", "+ else:", "- if max(pool) == p[i + 1]:", "- continue", "- #", "- ans += 1" ]
false
0.037166
0.036384
1.021508
[ "s860188454", "s161361394" ]
u525065967
p02598
python
s424345253
s757844374
567
502
30,796
31,000
Accepted
Accepted
11.46
_, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] ng, ok = 0, 1<<30 while ok - ng > 1: m = (ng + ok) // 2 if k < sum([(a-1)//m for a in A]): ng = m else: ok = m print(ok)
_, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] ng, ok = 0, 1<<30 while ok - ng > 1: m = (ng + ok) // 2 if k < sum((a-1)//m for a in A): ng = m else: ok = m print(ok)
8
8
211
204
_, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] ng, ok = 0, 1 << 30 while ok - ng > 1: m = (ng + ok) // 2 if k < sum([(a - 1) // m for a in A]): ng = m else: ok = m print(ok)
_, k = list(map(int, input().split())) A = [*list(map(int, input().split()))] ng, ok = 0, 1 << 30 while ok - ng > 1: m = (ng + ok) // 2 if k < sum((a - 1) // m for a in A): ng = m else: ok = m print(ok)
false
0
[ "- if k < sum([(a - 1) // m for a in A]):", "+ if k < sum((a - 1) // m for a in A):" ]
false
0.046684
0.040071
1.165028
[ "s424345253", "s757844374" ]
u312025627
p02863
python
s619201480
s541124956
521
289
211,940
145,672
Accepted
Accepted
44.53
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0]*(T+1) for _ in range(N+1)] for i in range(N): for j in range(T): t = j - A[i] if 0 <= t: dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + B[i]) else: dp1[i+1][j] = dp1[i][j] dp2 = [[0]*(T+1) for _ in range(N+2)] for i in range(1, N+1)[::-1]: for j in range(T): t = j - A[i-1] if 0 <= t: dp2[i][j] = max(dp2[i+1][j], dp2[i+1][t] + B[i-1]) else: dp2[i][j] = dp2[i+1][j] ans = 0 for i in range(N): for j in range(T): ans = max(ans, dp1[i][j] + dp2[i+2][T - 1 - j] + B[i]) print(ans) if __name__ == '__main__': main()
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] AB.sort() ans = 0 dp1 = [[0]*(T+1) for _ in range(N+1)] for i in range(N): for j in range(T): t = j - AB[i][0] if 0 <= t: dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + AB[i][1]) else: dp1[i+1][j] = dp1[i][j] ans = max(ans, dp1[i][T-1] + AB[i][1]) print(ans) if __name__ == '__main__': main()
31
20
928
537
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] A = [a[0] for a in AB] B = [b[1] for b in AB] dp1 = [[0] * (T + 1) for _ in range(N + 1)] for i in range(N): for j in range(T): t = j - A[i] if 0 <= t: dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + B[i]) else: dp1[i + 1][j] = dp1[i][j] dp2 = [[0] * (T + 1) for _ in range(N + 2)] for i in range(1, N + 1)[::-1]: for j in range(T): t = j - A[i - 1] if 0 <= t: dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][t] + B[i - 1]) else: dp2[i][j] = dp2[i + 1][j] ans = 0 for i in range(N): for j in range(T): ans = max(ans, dp1[i][j] + dp2[i + 2][T - 1 - j] + B[i]) print(ans) if __name__ == "__main__": main()
def main(): N, T = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(N)] AB.sort() ans = 0 dp1 = [[0] * (T + 1) for _ in range(N + 1)] for i in range(N): for j in range(T): t = j - AB[i][0] if 0 <= t: dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + AB[i][1]) else: dp1[i + 1][j] = dp1[i][j] ans = max(ans, dp1[i][T - 1] + AB[i][1]) print(ans) if __name__ == "__main__": main()
false
35.483871
[ "- A = [a[0] for a in AB]", "- B = [b[1] for b in AB]", "+ AB.sort()", "+ ans = 0", "- t = j - A[i]", "+ t = j - AB[i][0]", "- dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + B[i])", "+ dp1[i + 1][j] = max(dp1[i][j], dp1[i][t] + AB[i][1])", "- dp2 = [[0] * (T + 1) for _ in range(N + 2)]", "- for i in range(1, N + 1)[::-1]:", "- for j in range(T):", "- t = j - A[i - 1]", "- if 0 <= t:", "- dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][t] + B[i - 1])", "- else:", "- dp2[i][j] = dp2[i + 1][j]", "- ans = 0", "- for i in range(N):", "- for j in range(T):", "- ans = max(ans, dp1[i][j] + dp2[i + 2][T - 1 - j] + B[i])", "+ ans = max(ans, dp1[i][T - 1] + AB[i][1])" ]
false
0.052521
0.074484
0.705141
[ "s619201480", "s541124956" ]
u597455618
p02572
python
s230972757
s679227055
165
149
29,316
29,124
Accepted
Accepted
9.7
import sys from itertools import accumulate n = int(sys.stdin.buffer.readline()) a = list(map(int, sys.stdin.buffer.readline().split())) aa = list(accumulate(a)) MOD = 10**9+7 ans = 0 for i in range(n): ans += a[i]*(aa[n-1] - aa[i]) % MOD ans %= MOD print(ans)
import sys from itertools import accumulate n = int(sys.stdin.buffer.readline()) a = list(map(int, sys.stdin.buffer.readline().split())) aa = list(accumulate(a)) MOD = 10**9+7 ans = 0 for i in range(n): ans += a[i]*(aa[n-1] - aa[i]) % MOD print((ans%MOD))
11
10
279
267
import sys from itertools import accumulate n = int(sys.stdin.buffer.readline()) a = list(map(int, sys.stdin.buffer.readline().split())) aa = list(accumulate(a)) MOD = 10**9 + 7 ans = 0 for i in range(n): ans += a[i] * (aa[n - 1] - aa[i]) % MOD ans %= MOD print(ans)
import sys from itertools import accumulate n = int(sys.stdin.buffer.readline()) a = list(map(int, sys.stdin.buffer.readline().split())) aa = list(accumulate(a)) MOD = 10**9 + 7 ans = 0 for i in range(n): ans += a[i] * (aa[n - 1] - aa[i]) % MOD print((ans % MOD))
false
9.090909
[ "- ans %= MOD", "-print(ans)", "+print((ans % MOD))" ]
false
0.038999
0.036135
1.07926
[ "s230972757", "s679227055" ]
u562935282
p02972
python
s028489706
s921825339
268
165
13,224
12,724
Accepted
Accepted
38.43
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): from functools import reduce from operator import xor N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = reduce(xor, a[x::x]) ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep='\n') if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = sum(a[x::x]) & 1 ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep='\n') if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
38
35
784
714
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): from functools import reduce from operator import xor N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = reduce(xor, a[x::x]) ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep="\n") if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = sum(a[x::x]) & 1 ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep="\n") if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
false
7.894737
[ "- from functools import reduce", "- from operator import xor", "-", "- a[x] = reduce(xor, a[x::x])", "+ a[x] = sum(a[x::x]) & 1" ]
false
0.042441
0.045645
0.9298
[ "s028489706", "s921825339" ]
u392319141
p03262
python
s527150309
s265397275
151
95
14,252
14,252
Accepted
Accepted
37.09
N, X = list(map(int, input().split())) axis = list(map(int, input().split())) ans = abs(axis[0] - X) def gcd(n, m) : n, m = max(n, m), min(n, m) if m == 0 : return n return gcd(m, n % m) for a in axis : ans = gcd(ans, abs(a - X)) print(ans)
N, X = list(map(int, input().split())) A = [X] + list(map(int, input().split())) def gcd(n, m): if m == 0: return n return gcd(m, n % m) B = [abs(a - A[0]) for a in A] ans = 0 for d in B: ans = gcd(ans, d) print(ans)
15
13
276
245
N, X = list(map(int, input().split())) axis = list(map(int, input().split())) ans = abs(axis[0] - X) def gcd(n, m): n, m = max(n, m), min(n, m) if m == 0: return n return gcd(m, n % m) for a in axis: ans = gcd(ans, abs(a - X)) print(ans)
N, X = list(map(int, input().split())) A = [X] + list(map(int, input().split())) def gcd(n, m): if m == 0: return n return gcd(m, n % m) B = [abs(a - A[0]) for a in A] ans = 0 for d in B: ans = gcd(ans, d) print(ans)
false
13.333333
[ "-axis = list(map(int, input().split()))", "-ans = abs(axis[0] - X)", "+A = [X] + list(map(int, input().split()))", "- n, m = max(n, m), min(n, m)", "-for a in axis:", "- ans = gcd(ans, abs(a - X))", "+B = [abs(a - A[0]) for a in A]", "+ans = 0", "+for d in B:", "+ ans = gcd(ans, d)" ]
false
0.0435
0.042535
1.022697
[ "s527150309", "s265397275" ]
u648868410
p02599
python
s097532746
s852197286
1,822
1,358
160,236
85,824
Accepted
Accepted
25.47
import sys import numpy as np from numba import njit#,i8 def input(): return sys.stdin.readline() N,Q = list(map(int,input().split())) C=np.array(input().split(), int) # Query取得-rightでソート # dtypeQuery = [("index", int), ("start", int), ("end", int)] queries=np.empty((Q,2),int) # #rights=[[] for _ in range(N+1)] for q in range(Q): l,r=list(map(int,input().split())) #queries[q] = (q,l,r) queries[q][0] = l queries[q][1] = r #queries=np.sort(queries,order="end") #queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2) orderByR=np.argsort(queries[:,1]) # 各色の現在の一番右のindex mostRightColorIndex = np.zeros(N+1, int) # bit indexed tree bitArray=np.zeros(N+1,int) @njit(cache=True) # @jit(返り値の型(引数1の型,引数2の型,...,引数nの型)) #@jit(i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])) def main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray): def add(itemCount, items, i, value): while i <= itemCount: items[i] += value i += (i & (-i)) def sumFromStart(items, end): summary = 0 i = end while i > 0: summary += items[i] i -= (i & (-i)) return summary def sum(items, start,end): summary = sumFromStart(items, end) - sumFromStart(items, start-1) return summary # 答え配列 #ans=np.zeros(Q, i8)#int) ans=[0]*Q # 左からBITと現在色の更新をしながら、クエリのrightに到達したときにBITにクエリ発行する qindex = 0 for n in range(N): # 外側のループでは、全部の色をループ if Q <= qindex: break if 0 < mostRightColorIndex[C[n]]: # ループ中の場所の色のindexが既にある場合(=過去に、同じ色が登録されていた場合) # 今回で、同じ色の一番右側の要素はループ中の要素になる # 前登録したこの色の一番右のindexを一度BITから抜く(↓で再度登録される) add(N,bitArray,mostRightColorIndex[C[n]], -1 ) # この要素の色の一番右のindexを、BITに登録 mostRightColorIndex[C[n]] = n+1 add(N,bitArray,n+1, 1) # while qindex < Q and n+1 == queries[qindex][2]: while qindex < Q and n+1 == queries[orderByR[qindex]][1]: # 今のBITが次のクエリ発行するための状態(n==query.right)だったら、クエリ発行 tmpIndex = orderByR[qindex] start = queries[tmpIndex][0] end = queries[tmpIndex][1] ans[tmpIndex]=sum(bitArray,start,end) # print(tmpIndex,start,end,ans[tmpIndex]) qindex += 1 return ans for a in main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray): print(a)
import sys import numpy as np # from numba import njit#,i8 #@njit(cache=True) # @jit(返り値の型(引数1の型,引数2の型,...,引数nの型)) #@jit(i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])) def main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray): def add(itemCount, items, i, value): while i <= itemCount: items[i] += value i += (i & (-i)) def sumFromStart(items, end): summary = 0 i = end while i > 0: summary += items[i] i -= (i & (-i)) return summary def sum(items, start,end): summary = sumFromStart(items, end) - sumFromStart(items, start-1) return summary # 答え配列 ans=np.zeros(Q, dtype=np.int64) #ans=[0]*Q # 左からBITと現在色の更新をしながら、クエリのrightに到達したときにBITにクエリ発行する qindex = 0 for n in range(N): # 外側のループでは、全部の色をループ if Q <= qindex: break if 0 < mostRightColorIndex[C[n]]: # ループ中の場所の色のindexが既にある場合(=過去に、同じ色が登録されていた場合) # 今回で、同じ色の一番右側の要素はループ中の要素になる # 前登録したこの色の一番右のindexを一度BITから抜く(↓で再度登録される) add(N,bitArray,mostRightColorIndex[C[n]], -1 ) # この要素の色の一番右のindexを、BITに登録 mostRightColorIndex[C[n]] = n+1 add(N,bitArray,n+1, 1) # while qindex < Q and n+1 == queries[qindex][2]: while qindex < Q and n+1 == queries[orderByR[qindex]][1]: # 今のBITが次のクエリ発行するための状態(n==query.right)だったら、クエリ発行 tmpIndex = orderByR[qindex] start = queries[tmpIndex][0] end = queries[tmpIndex][1] ans[tmpIndex]=sum(bitArray,start,end) # print(tmpIndex,start,end,ans[tmpIndex]) qindex += 1 return ans if sys.argv[-1]=='ONLINE_JUDGE': from numba.pycc import CC cc=CC('my_module') cc.export('main','i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])')(main) cc.compile() exit(0) from my_module import main def input(): return sys.stdin.readline() N,Q = list(map(int,input().split())) C=np.array(input().split(), int) # Query取得-rightでソート # dtypeQuery = [("index", int), ("start", int), ("end", int)] queries=np.empty((Q,2),int) # #rights=[[] for _ in range(N+1)] for q in range(Q): l,r=list(map(int,input().split())) #queries[q] = (q,l,r) queries[q][0] = l queries[q][1] = r #queries=np.sort(queries,order="end") #queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2) orderByR=np.argsort(queries[:,1]) # 各色の現在の一番右のindex mostRightColorIndex = np.zeros(N+1, int) # bit indexed tree bitArray=np.zeros(N+1,int) for a in main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray): print(a)
90
99
2,212
2,435
import sys import numpy as np from numba import njit # ,i8 def input(): return sys.stdin.readline() N, Q = list(map(int, input().split())) C = np.array(input().split(), int) # Query取得-rightでソート # dtypeQuery = [("index", int), ("start", int), ("end", int)] queries = np.empty((Q, 2), int) # #rights=[[] for _ in range(N+1)] for q in range(Q): l, r = list(map(int, input().split())) # queries[q] = (q,l,r) queries[q][0] = l queries[q][1] = r # queries=np.sort(queries,order="end") # queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2) orderByR = np.argsort(queries[:, 1]) # 各色の現在の一番右のindex mostRightColorIndex = np.zeros(N + 1, int) # bit indexed tree bitArray = np.zeros(N + 1, int) @njit(cache=True) # @jit(返り値の型(引数1の型,引数2の型,...,引数nの型)) # @jit(i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])) def main(N, Q, C, queries, orderByR, mostRightColorIndex, bitArray): def add(itemCount, items, i, value): while i <= itemCount: items[i] += value i += i & (-i) def sumFromStart(items, end): summary = 0 i = end while i > 0: summary += items[i] i -= i & (-i) return summary def sum(items, start, end): summary = sumFromStart(items, end) - sumFromStart(items, start - 1) return summary # 答え配列 # ans=np.zeros(Q, i8)#int) ans = [0] * Q # 左からBITと現在色の更新をしながら、クエリのrightに到達したときにBITにクエリ発行する qindex = 0 for n in range(N): # 外側のループでは、全部の色をループ if Q <= qindex: break if 0 < mostRightColorIndex[C[n]]: # ループ中の場所の色のindexが既にある場合(=過去に、同じ色が登録されていた場合) # 今回で、同じ色の一番右側の要素はループ中の要素になる # 前登録したこの色の一番右のindexを一度BITから抜く(↓で再度登録される) add(N, bitArray, mostRightColorIndex[C[n]], -1) # この要素の色の一番右のindexを、BITに登録 mostRightColorIndex[C[n]] = n + 1 add(N, bitArray, n + 1, 1) # while qindex < Q and n+1 == queries[qindex][2]: while qindex < Q and n + 1 == queries[orderByR[qindex]][1]: # 今のBITが次のクエリ発行するための状態(n==query.right)だったら、クエリ発行 tmpIndex = orderByR[qindex] start = queries[tmpIndex][0] end = queries[tmpIndex][1] ans[tmpIndex] = sum(bitArray, start, end) # print(tmpIndex,start,end,ans[tmpIndex]) qindex += 1 return ans for a in main(N, Q, C, queries, orderByR, mostRightColorIndex, bitArray): print(a)
import sys import numpy as np # from numba import njit#,i8 # @njit(cache=True) # @jit(返り値の型(引数1の型,引数2の型,...,引数nの型)) # @jit(i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])) def main(N, Q, C, queries, orderByR, mostRightColorIndex, bitArray): def add(itemCount, items, i, value): while i <= itemCount: items[i] += value i += i & (-i) def sumFromStart(items, end): summary = 0 i = end while i > 0: summary += items[i] i -= i & (-i) return summary def sum(items, start, end): summary = sumFromStart(items, end) - sumFromStart(items, start - 1) return summary # 答え配列 ans = np.zeros(Q, dtype=np.int64) # ans=[0]*Q # 左からBITと現在色の更新をしながら、クエリのrightに到達したときにBITにクエリ発行する qindex = 0 for n in range(N): # 外側のループでは、全部の色をループ if Q <= qindex: break if 0 < mostRightColorIndex[C[n]]: # ループ中の場所の色のindexが既にある場合(=過去に、同じ色が登録されていた場合) # 今回で、同じ色の一番右側の要素はループ中の要素になる # 前登録したこの色の一番右のindexを一度BITから抜く(↓で再度登録される) add(N, bitArray, mostRightColorIndex[C[n]], -1) # この要素の色の一番右のindexを、BITに登録 mostRightColorIndex[C[n]] = n + 1 add(N, bitArray, n + 1, 1) # while qindex < Q and n+1 == queries[qindex][2]: while qindex < Q and n + 1 == queries[orderByR[qindex]][1]: # 今のBITが次のクエリ発行するための状態(n==query.right)だったら、クエリ発行 tmpIndex = orderByR[qindex] start = queries[tmpIndex][0] end = queries[tmpIndex][1] ans[tmpIndex] = sum(bitArray, start, end) # print(tmpIndex,start,end,ans[tmpIndex]) qindex += 1 return ans if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("main", "i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])")(main) cc.compile() exit(0) from my_module import main def input(): return sys.stdin.readline() N, Q = list(map(int, input().split())) C = np.array(input().split(), int) # Query取得-rightでソート # dtypeQuery = [("index", int), ("start", int), ("end", int)] queries = np.empty((Q, 2), int) # #rights=[[] for _ in range(N+1)] for q in range(Q): l, r = list(map(int, input().split())) # queries[q] = (q,l,r) queries[q][0] = l queries[q][1] = r # queries=np.sort(queries,order="end") # queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2) orderByR = np.argsort(queries[:, 1]) # 各色の現在の一番右のindex mostRightColorIndex = np.zeros(N + 1, int) # bit indexed tree bitArray = np.zeros(N + 1, int) for a in main(N, Q, C, queries, orderByR, mostRightColorIndex, bitArray): print(a)
false
9.090909
[ "-from numba import njit # ,i8", "-", "-def input():", "- return sys.stdin.readline()", "-", "-", "-N, Q = list(map(int, input().split()))", "-C = np.array(input().split(), int)", "-# Query取得-rightでソート", "-# dtypeQuery = [(\"index\", int), (\"start\", int), (\"end\", int)]", "-queries = np.empty((Q, 2), int)", "-# #rights=[[] for _ in range(N+1)]", "-for q in range(Q):", "- l, r = list(map(int, input().split()))", "- # queries[q] = (q,l,r)", "- queries[q][0] = l", "- queries[q][1] = r", "- # queries=np.sort(queries,order=\"end\")", "-# queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2)", "-orderByR = np.argsort(queries[:, 1])", "-# 各色の現在の一番右のindex", "-mostRightColorIndex = np.zeros(N + 1, int)", "-# bit indexed tree", "-bitArray = np.zeros(N + 1, int)", "-", "-", "-@njit(cache=True)", "+# from numba import njit#,i8", "+# @njit(cache=True)", "- # ans=np.zeros(Q, i8)#int)", "- ans = [0] * Q", "+ ans = np.zeros(Q, dtype=np.int64)", "+ # ans=[0]*Q", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"main\", \"i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])\")(main)", "+ cc.compile()", "+ exit(0)", "+from my_module import main", "+", "+", "+def input():", "+ return sys.stdin.readline()", "+", "+", "+N, Q = list(map(int, input().split()))", "+C = np.array(input().split(), int)", "+# Query取得-rightでソート", "+# dtypeQuery = [(\"index\", int), (\"start\", int), (\"end\", int)]", "+queries = np.empty((Q, 2), int)", "+# #rights=[[] for _ in range(N+1)]", "+for q in range(Q):", "+ l, r = list(map(int, input().split()))", "+ # queries[q] = (q,l,r)", "+ queries[q][0] = l", "+ queries[q][1] = r", "+ # queries=np.sort(queries,order=\"end\")", "+# queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2)", "+orderByR = np.argsort(queries[:, 1])", "+# 各色の現在の一番右のindex", "+mostRightColorIndex = np.zeros(N + 1, int)", "+# bit indexed tree", "+bitArray = np.zeros(N + 1, int)" ]
false
0.006946
0.684677
0.010145
[ "s097532746", "s852197286" ]
u753803401
p03005
python
s532517073
s023828473
189
164
38,256
38,256
Accepted
Accepted
13.23
def slove(): import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip('\n').split())) if k == 1: print((0)) else: print((n - k)) if __name__ == '__main__': slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, k = list(map(int, readline().split())) if k == 1: print((0)) elif n < k: print((1)) else: print((n - k)) if __name__ == '__main__': solve()
12
17
230
288
def slove(): import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip("\n").split())) if k == 1: print((0)) else: print((n - k)) if __name__ == "__main__": slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n, k = list(map(int, readline().split())) if k == 1: print((0)) elif n < k: print((1)) else: print((n - k)) if __name__ == "__main__": solve()
false
29.411765
[ "-def slove():", "- import sys", "+import sys", "- input = sys.stdin.readline", "- n, k = list(map(int, input().rstrip(\"\\n\").split()))", "+", "+def solve():", "+ readline = sys.stdin.buffer.readline", "+ mod = 10**9 + 7", "+ n, k = list(map(int, readline().split()))", "+ elif n < k:", "+ print((1))", "- slove()", "+ solve()" ]
false
0.042886
0.084097
0.509958
[ "s532517073", "s023828473" ]
u075595666
p03476
python
s067141505
s764896079
526
483
5,520
5,536
Accepted
Accepted
8.17
def is_prime(q): if q == 2: return True if q < 2 or q&1 == 0: return False return pow(5, q-1, q)*pow(7, q-1, q) == 1 s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831] b = [5,7] for i in range(2,10**5): if i in s: continue if is_prime(i): b.append(i) a = set([2*i-1 for i in b]) b = set(b) chk = sorted(list(a&b)) from bisect import bisect,bisect_left import sys input = sys.stdin.readline q = int(eval(input())) for i in range(q): l,r = list(map(int,input().split())) print((bisect(chk,r)-bisect_left(chk,l)))
def is_prime(q): if q == 2: return True if q < 2 or q&1 == 0: return False return pow(5, q-1, q)*pow(7, q-1, q) == 1 def main(): s = set([561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]) b = [5,7] for i in range(2,10**5): if i in s: continue if is_prime(i): b.append(i) a = set([2*i-1 for i in b]) b = set(b) chk = sorted(tuple(a&b)) from bisect import bisect,bisect_left import sys input = sys.stdin.readline q = int(eval(input())) for i in range(q): l,r = list(map(int,input().split())) print((bisect(chk,r)-bisect_left(chk,l))) if __name__ == '__main__': main()
25
29
573
668
def is_prime(q): if q == 2: return True if q < 2 or q & 1 == 0: return False return pow(5, q - 1, q) * pow(7, q - 1, q) == 1 s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831] b = [5, 7] for i in range(2, 10**5): if i in s: continue if is_prime(i): b.append(i) a = set([2 * i - 1 for i in b]) b = set(b) chk = sorted(list(a & b)) from bisect import bisect, bisect_left import sys input = sys.stdin.readline q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((bisect(chk, r) - bisect_left(chk, l)))
def is_prime(q): if q == 2: return True if q < 2 or q & 1 == 0: return False return pow(5, q - 1, q) * pow(7, q - 1, q) == 1 def main(): s = set([561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]) b = [5, 7] for i in range(2, 10**5): if i in s: continue if is_prime(i): b.append(i) a = set([2 * i - 1 for i in b]) b = set(b) chk = sorted(tuple(a & b)) from bisect import bisect, bisect_left import sys input = sys.stdin.readline q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((bisect(chk, r) - bisect_left(chk, l))) if __name__ == "__main__": main()
false
13.793103
[ "-s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]", "-b = [5, 7]", "-for i in range(2, 10**5):", "- if i in s:", "- continue", "- if is_prime(i):", "- b.append(i)", "-a = set([2 * i - 1 for i in b])", "-b = set(b)", "-chk = sorted(list(a & b))", "-from bisect import bisect, bisect_left", "-import sys", "+def main():", "+ s = set([561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831])", "+ b = [5, 7]", "+ for i in range(2, 10**5):", "+ if i in s:", "+ continue", "+ if is_prime(i):", "+ b.append(i)", "+ a = set([2 * i - 1 for i in b])", "+ b = set(b)", "+ chk = sorted(tuple(a & b))", "+ from bisect import bisect, bisect_left", "+ import sys", "-input = sys.stdin.readline", "-q = int(eval(input()))", "-for i in range(q):", "- l, r = list(map(int, input().split()))", "- print((bisect(chk, r) - bisect_left(chk, l)))", "+ input = sys.stdin.readline", "+ q = int(eval(input()))", "+ for i in range(q):", "+ l, r = list(map(int, input().split()))", "+ print((bisect(chk, r) - bisect_left(chk, l)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.7379
0.331648
2.224948
[ "s067141505", "s764896079" ]
u077291787
p03618
python
s574322837
s849996787
31
22
3,872
3,500
Accepted
Accepted
29.03
# AGC019B - Reverse and Compare from collections import Counter def main(): S = input().rstrip() C, N = list(Counter(S).values()), len(S) ans = N * (N - 1) // 2 + 1 # all possible patterns ans -= sum(i * (i - 1) // 2 for i in C) # duplicates print(ans) if __name__ == "__main__": main()
# AGC019B - Reverse and Compare def main(): S = input().rstrip() N = len(S) ans = N * (N - 1) // 2 + 1 # all possible patterns abc = "abcdefghijklmnopqrstuvwxyz" for a in abc: x = S.count(a) ans -= x * (x - 1) // 2 # exclude duplicates print(ans) if __name__ == "__main__": main()
14
14
323
341
# AGC019B - Reverse and Compare from collections import Counter def main(): S = input().rstrip() C, N = list(Counter(S).values()), len(S) ans = N * (N - 1) // 2 + 1 # all possible patterns ans -= sum(i * (i - 1) // 2 for i in C) # duplicates print(ans) if __name__ == "__main__": main()
# AGC019B - Reverse and Compare def main(): S = input().rstrip() N = len(S) ans = N * (N - 1) // 2 + 1 # all possible patterns abc = "abcdefghijklmnopqrstuvwxyz" for a in abc: x = S.count(a) ans -= x * (x - 1) // 2 # exclude duplicates print(ans) if __name__ == "__main__": main()
false
0
[ "-from collections import Counter", "-", "-", "- C, N = list(Counter(S).values()), len(S)", "+ N = len(S)", "- ans -= sum(i * (i - 1) // 2 for i in C) # duplicates", "+ abc = \"abcdefghijklmnopqrstuvwxyz\"", "+ for a in abc:", "+ x = S.count(a)", "+ ans -= x * (x - 1) // 2 # exclude duplicates" ]
false
0.059774
0.035839
1.66785
[ "s574322837", "s849996787" ]
u539367121
p02695
python
s478201918
s117245922
1,140
942
9,160
9,176
Accepted
Accepted
17.37
import itertools N, M, Q = list(map(int, input().split())) ABCD = [[int(x) for x in input().split()] for i in range(Q)] ans=0 for A in itertools.combinations_with_replacement([m for m in range(1,M+1)], N): ans2=0 for (a,b,c,d) in ABCD: if A[b-1]-A[a-1]==c: ans2+=d ans=max(ans, ans2) print(ans)
import itertools N, M, Q = list(map(int, input().split())) ABCD = [[int(x) for x in input().split()] for i in range(Q)] ans=0 t=[m for m in range(1,M+1)] for A in itertools.combinations_with_replacement(t, N): ans2=0 for (a,b,c,d) in ABCD: if A[b-1]-A[a-1]==c: ans2+=d ans=max(ans, ans2) print(ans)
13
14
319
324
import itertools N, M, Q = list(map(int, input().split())) ABCD = [[int(x) for x in input().split()] for i in range(Q)] ans = 0 for A in itertools.combinations_with_replacement([m for m in range(1, M + 1)], N): ans2 = 0 for (a, b, c, d) in ABCD: if A[b - 1] - A[a - 1] == c: ans2 += d ans = max(ans, ans2) print(ans)
import itertools N, M, Q = list(map(int, input().split())) ABCD = [[int(x) for x in input().split()] for i in range(Q)] ans = 0 t = [m for m in range(1, M + 1)] for A in itertools.combinations_with_replacement(t, N): ans2 = 0 for (a, b, c, d) in ABCD: if A[b - 1] - A[a - 1] == c: ans2 += d ans = max(ans, ans2) print(ans)
false
7.142857
[ "-for A in itertools.combinations_with_replacement([m for m in range(1, M + 1)], N):", "+t = [m for m in range(1, M + 1)]", "+for A in itertools.combinations_with_replacement(t, N):" ]
false
0.058362
0.208683
0.27967
[ "s478201918", "s117245922" ]
u694665829
p03476
python
s463526636
s944238063
528
480
13,516
13,564
Accepted
Accepted
9.09
dp = [1]*(10**5+1) #エラトステネスの篩 dp[0],dp[1] = 0, 0 for i in range(2, 10**5+1): if dp[i] == 0: continue j = i while j + i <= 10**5: j += i if dp[j] == 1: dp[j] = 0 ni = [0]*(10**5+1) #2012_like check for i in range(2, 10**5+1): if dp[i] == 1 and dp[(i+1)//2] == 1: ni[i] = 1 ru = [0]*(10**5+1) for i in range(1, 10**5+1): ru[i] = ru[i-1] + ni[i] q = int(eval(input())) for i in range(q): l, r = list(map(int,input().split())) print((ru[r] - ru[l-1]))
def f(): dp = [1]*(10**5+1) #エラトステネスの篩 dp[0],dp[1] = 0, 0 for i in range(2, 10**5+1): if dp[i] == 0: continue j = i while j + i <= 10**5: j += i if dp[j] == 1: dp[j] = 0 ni = [0]*(10**5+1) #2012_like check for i in range(2, 10**5+1): if dp[i] == 1 and dp[(i+1)//2] == 1: ni[i] = 1 ru = [0]*(10**5+1) for i in range(1, 10**5+1): ru[i] = ru[i-1] + ni[i] q = int(eval(input())) for i in range(q): l, r = list(map(int,input().split())) print((ru[r] - ru[l-1])) if __name__ == '__main__': f()
24
28
531
680
dp = [1] * (10**5 + 1) # エラトステネスの篩 dp[0], dp[1] = 0, 0 for i in range(2, 10**5 + 1): if dp[i] == 0: continue j = i while j + i <= 10**5: j += i if dp[j] == 1: dp[j] = 0 ni = [0] * (10**5 + 1) # 2012_like check for i in range(2, 10**5 + 1): if dp[i] == 1 and dp[(i + 1) // 2] == 1: ni[i] = 1 ru = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): ru[i] = ru[i - 1] + ni[i] q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((ru[r] - ru[l - 1]))
def f(): dp = [1] * (10**5 + 1) # エラトステネスの篩 dp[0], dp[1] = 0, 0 for i in range(2, 10**5 + 1): if dp[i] == 0: continue j = i while j + i <= 10**5: j += i if dp[j] == 1: dp[j] = 0 ni = [0] * (10**5 + 1) # 2012_like check for i in range(2, 10**5 + 1): if dp[i] == 1 and dp[(i + 1) // 2] == 1: ni[i] = 1 ru = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): ru[i] = ru[i - 1] + ni[i] q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((ru[r] - ru[l - 1])) if __name__ == "__main__": f()
false
14.285714
[ "-dp = [1] * (10**5 + 1) # エラトステネスの篩", "-dp[0], dp[1] = 0, 0", "-for i in range(2, 10**5 + 1):", "- if dp[i] == 0:", "- continue", "- j = i", "- while j + i <= 10**5:", "- j += i", "- if dp[j] == 1:", "- dp[j] = 0", "-ni = [0] * (10**5 + 1) # 2012_like check", "-for i in range(2, 10**5 + 1):", "- if dp[i] == 1 and dp[(i + 1) // 2] == 1:", "- ni[i] = 1", "-ru = [0] * (10**5 + 1)", "-for i in range(1, 10**5 + 1):", "- ru[i] = ru[i - 1] + ni[i]", "-q = int(eval(input()))", "-for i in range(q):", "- l, r = list(map(int, input().split()))", "- print((ru[r] - ru[l - 1]))", "+def f():", "+ dp = [1] * (10**5 + 1) # エラトステネスの篩", "+ dp[0], dp[1] = 0, 0", "+ for i in range(2, 10**5 + 1):", "+ if dp[i] == 0:", "+ continue", "+ j = i", "+ while j + i <= 10**5:", "+ j += i", "+ if dp[j] == 1:", "+ dp[j] = 0", "+ ni = [0] * (10**5 + 1) # 2012_like check", "+ for i in range(2, 10**5 + 1):", "+ if dp[i] == 1 and dp[(i + 1) // 2] == 1:", "+ ni[i] = 1", "+ ru = [0] * (10**5 + 1)", "+ for i in range(1, 10**5 + 1):", "+ ru[i] = ru[i - 1] + ni[i]", "+ q = int(eval(input()))", "+ for i in range(q):", "+ l, r = list(map(int, input().split()))", "+ print((ru[r] - ru[l - 1]))", "+", "+", "+if __name__ == \"__main__\":", "+ f()" ]
false
0.289886
0.283588
1.02221
[ "s463526636", "s944238063" ]
u921632705
p03485
python
s249988539
s835311259
31
28
9,156
9,100
Accepted
Accepted
9.68
x,y = list(map(int, input().split())) z =x+y import math print((math.ceil(z/2)))
x,y = list(map(int, input().split())) import math print((math.ceil((x+y)/2)))
4
3
75
71
x, y = list(map(int, input().split())) z = x + y import math print((math.ceil(z / 2)))
x, y = list(map(int, input().split())) import math print((math.ceil((x + y) / 2)))
false
25
[ "-z = x + y", "-print((math.ceil(z / 2)))", "+print((math.ceil((x + y) / 2)))" ]
false
0.039043
0.039374
0.991598
[ "s249988539", "s835311259" ]
u627803856
p03212
python
s615456870
s335458012
226
117
43,228
76,128
Accepted
Accepted
48.23
n = int(eval(input())) def dfs(val, A): if val > n: return A.append(val) dfs(10 * val + 3, A) dfs(10 * val + 5, A) dfs(10 * val + 7, A) A = [] dfs(3, A) dfs(5, A) dfs(7, A) cnt = 0 for v in A: if len(set(list(str(v)))) == 3: cnt += 1 print(cnt)
# 7/3 # n 以下の「753数」の個数 n = int(eval(input())) def dfs(val): # 終了条件 if val > n: return A.append(val) for v in [3, 5, 7]: val = A.pop() dfs(10 * val + v) A.append(val) A = [] for v in [3, 5, 7]: dfs(v) res = 0 for v in A: s = str(v) if '3' in s and '5' in s and '7' in s: res += 1 print(res)
20
29
300
387
n = int(eval(input())) def dfs(val, A): if val > n: return A.append(val) dfs(10 * val + 3, A) dfs(10 * val + 5, A) dfs(10 * val + 7, A) A = [] dfs(3, A) dfs(5, A) dfs(7, A) cnt = 0 for v in A: if len(set(list(str(v)))) == 3: cnt += 1 print(cnt)
# 7/3 # n 以下の「753数」の個数 n = int(eval(input())) def dfs(val): # 終了条件 if val > n: return A.append(val) for v in [3, 5, 7]: val = A.pop() dfs(10 * val + v) A.append(val) A = [] for v in [3, 5, 7]: dfs(v) res = 0 for v in A: s = str(v) if "3" in s and "5" in s and "7" in s: res += 1 print(res)
false
31.034483
[ "+# 7/3", "+# n 以下の「753数」の個数", "-def dfs(val, A):", "+def dfs(val):", "+ # 終了条件", "- dfs(10 * val + 3, A)", "- dfs(10 * val + 5, A)", "- dfs(10 * val + 7, A)", "+ for v in [3, 5, 7]:", "+ val = A.pop()", "+ dfs(10 * val + v)", "+ A.append(val)", "-dfs(3, A)", "-dfs(5, A)", "-dfs(7, A)", "-cnt = 0", "+for v in [3, 5, 7]:", "+ dfs(v)", "+res = 0", "- if len(set(list(str(v)))) == 3:", "- cnt += 1", "-print(cnt)", "+ s = str(v)", "+ if \"3\" in s and \"5\" in s and \"7\" in s:", "+ res += 1", "+print(res)" ]
false
0.056524
0.057246
0.987387
[ "s615456870", "s335458012" ]
u313111801
p03243
python
s203716441
s775875294
30
25
9,028
9,096
Accepted
Accepted
16.67
def ok(n): v=n%10 ret=True while n>0: ret&=n%10==v n//=10 return ret N=int(eval(input())) while not(ok(N)): N+=1 print(N)
n=int(eval(input())) ans=0 while ans<n: ans+=111 print(ans)
12
5
163
61
def ok(n): v = n % 10 ret = True while n > 0: ret &= n % 10 == v n //= 10 return ret N = int(eval(input())) while not (ok(N)): N += 1 print(N)
n = int(eval(input())) ans = 0 while ans < n: ans += 111 print(ans)
false
58.333333
[ "-def ok(n):", "- v = n % 10", "- ret = True", "- while n > 0:", "- ret &= n % 10 == v", "- n //= 10", "- return ret", "-", "-", "-N = int(eval(input()))", "-while not (ok(N)):", "- N += 1", "-print(N)", "+n = int(eval(input()))", "+ans = 0", "+while ans < n:", "+ ans += 111", "+print(ans)" ]
false
0.044413
0.043435
1.022517
[ "s203716441", "s775875294" ]
u676247559
p02639
python
s399223100
s483358542
30
26
8,924
9,024
Accepted
Accepted
13.33
l = list(map(int,input().split())) xr = 0 for i in range(1,6): xr ^= i for i in l: xr ^= i print(xr)
l = list(map(int,input().split())) xr = 0 for i in range(5): xr ^= (i+1) xr ^= l[i] print(xr)
7
6
110
103
l = list(map(int, input().split())) xr = 0 for i in range(1, 6): xr ^= i for i in l: xr ^= i print(xr)
l = list(map(int, input().split())) xr = 0 for i in range(5): xr ^= i + 1 xr ^= l[i] print(xr)
false
14.285714
[ "-for i in range(1, 6):", "- xr ^= i", "-for i in l:", "- xr ^= i", "+for i in range(5):", "+ xr ^= i + 1", "+ xr ^= l[i]" ]
false
0.048047
0.049422
0.972191
[ "s399223100", "s483358542" ]
u729133443
p02990
python
s159783611
s182582947
76
20
27,760
3,316
Accepted
Accepted
73.68
n,k=list(map(int,input().split()));p=n-k+1;i=0;exec('print(p%(10**9+7));i+=1;p=p*(k-i)*(n-k+1-i)//i//-~i;'*k)
n,k=list(map(int,input().split())) p=n-k+1 i=0 while i<k:print((p%(10**9+7)));i+=1;p=p*(k-i)*(n-k+1-i)//i//-~i
1
4
103
105
n, k = list(map(int, input().split())) p = n - k + 1 i = 0 exec("print(p%(10**9+7));i+=1;p=p*(k-i)*(n-k+1-i)//i//-~i;" * k)
n, k = list(map(int, input().split())) p = n - k + 1 i = 0 while i < k: print((p % (10**9 + 7))) i += 1 p = p * (k - i) * (n - k + 1 - i) // i // -~i
false
75
[ "-exec(\"print(p%(10**9+7));i+=1;p=p*(k-i)*(n-k+1-i)//i//-~i;\" * k)", "+while i < k:", "+ print((p % (10**9 + 7)))", "+ i += 1", "+ p = p * (k - i) * (n - k + 1 - i) // i // -~i" ]
false
0.034824
0.04103
0.848744
[ "s159783611", "s182582947" ]
u094999522
p02642
python
s990881595
s549056351
298
173
33,344
121,656
Accepted
Accepted
41.95
_,*a = list(map(int, open(0).read().split())) a.sort() m = -~a[-1] c = [0]*m for i in a: c[i] += 1 if c[i] > 1: continue for j in range(i * 2, m, i): c[j] = 2 print((sum(c[i]==1for i in a)))
#!/usr/bin/env python3 _, *a = list(map(int, open(0).read().split())) a.sort() p = [0] * a[-1] for i in a: for j in range(1, a[-1] // i + 1): p[j * i - 1] += j print((sum(i == 1 for i in p)))
11
8
220
203
_, *a = list(map(int, open(0).read().split())) a.sort() m = -~a[-1] c = [0] * m for i in a: c[i] += 1 if c[i] > 1: continue for j in range(i * 2, m, i): c[j] = 2 print((sum(c[i] == 1 for i in a)))
#!/usr/bin/env python3 _, *a = list(map(int, open(0).read().split())) a.sort() p = [0] * a[-1] for i in a: for j in range(1, a[-1] // i + 1): p[j * i - 1] += j print((sum(i == 1 for i in p)))
false
27.272727
[ "+#!/usr/bin/env python3", "-m = -~a[-1]", "-c = [0] * m", "+p = [0] * a[-1]", "- c[i] += 1", "- if c[i] > 1:", "- continue", "- for j in range(i * 2, m, i):", "- c[j] = 2", "-print((sum(c[i] == 1 for i in a)))", "+ for j in range(1, a[-1] // i + 1):", "+ p[j * i - 1] += j", "+print((sum(i == 1 for i in p)))" ]
false
0.043466
0.043396
1.001617
[ "s990881595", "s549056351" ]
u987164499
p02971
python
s052262854
s339167206
572
373
12,528
14,120
Accepted
Accepted
34.79
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_m = max(a) a_i = a.index(a_m) a.sort() for i in range(len(a)): if i == a_i: print((a[-2])) else: print(a_m)
from sys import stdin n = int(stdin.readline().rstrip()) li = list(int(stdin.readline().rstrip()) for _ in range(n)) li_to = sorted(li) one = li_to[-1] two = li_to[-2] for i in range(n): if one == li[i]: print(two) else: print(one)
10
11
182
265
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_m = max(a) a_i = a.index(a_m) a.sort() for i in range(len(a)): if i == a_i: print((a[-2])) else: print(a_m)
from sys import stdin n = int(stdin.readline().rstrip()) li = list(int(stdin.readline().rstrip()) for _ in range(n)) li_to = sorted(li) one = li_to[-1] two = li_to[-2] for i in range(n): if one == li[i]: print(two) else: print(one)
false
9.090909
[ "-n = int(eval(input()))", "-a = [int(eval(input())) for _ in range(n)]", "-a_m = max(a)", "-a_i = a.index(a_m)", "-a.sort()", "-for i in range(len(a)):", "- if i == a_i:", "- print((a[-2]))", "+from sys import stdin", "+", "+n = int(stdin.readline().rstrip())", "+li = list(int(stdin.readline().rstrip()) for _ in range(n))", "+li_to = sorted(li)", "+one = li_to[-1]", "+two = li_to[-2]", "+for i in range(n):", "+ if one == li[i]:", "+ print(two)", "- print(a_m)", "+ print(one)" ]
false
0.04213
0.036502
1.154176
[ "s052262854", "s339167206" ]
u793868662
p03672
python
s120207821
s806351063
191
175
38,256
38,384
Accepted
Accepted
8.38
def resolve(): s = eval(input()) l = len(s) for i in range(2, l, 2): test = s[0:(l-i)] t = len(test) if test[0:(t//2)] == test[(t//2):t]: print((len(test))) exit() resolve()
def resolve(): s = eval(input()) for i in range(2, len(s), 2): test = s[:len(s)-i] if test[:len(test)//2] == test[len(test)//2:]: print((len(test))) exit() resolve()
10
9
234
214
def resolve(): s = eval(input()) l = len(s) for i in range(2, l, 2): test = s[0 : (l - i)] t = len(test) if test[0 : (t // 2)] == test[(t // 2) : t]: print((len(test))) exit() resolve()
def resolve(): s = eval(input()) for i in range(2, len(s), 2): test = s[: len(s) - i] if test[: len(test) // 2] == test[len(test) // 2 :]: print((len(test))) exit() resolve()
false
10
[ "- l = len(s)", "- for i in range(2, l, 2):", "- test = s[0 : (l - i)]", "- t = len(test)", "- if test[0 : (t // 2)] == test[(t // 2) : t]:", "+ for i in range(2, len(s), 2):", "+ test = s[: len(s) - i]", "+ if test[: len(test) // 2] == test[len(test) // 2 :]:" ]
false
0.035993
0.03638
0.989372
[ "s120207821", "s806351063" ]
u860002137
p03050
python
s940708770
s703032183
186
166
3,528
9,292
Accepted
Accepted
10.75
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] def is_favorite(n, m): if x == 0: return False else: return n // m == n % m li = make_divisors(n) li = [x - 1 for x in li] ans = 0 for x in li: if is_favorite(n, x): ans += x print(ans)
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] # 約数から1引いたものが候補 arr = make_divisors(n) arr = [x - 1 for x in arr if x >= 2] # 商と剰余が不一致ならbreakできる ans = 0 for x in arr[::-1]: if n // x != n % x: break ans += x print(ans)
32
27
570
527
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] def is_favorite(n, m): if x == 0: return False else: return n // m == n % m li = make_divisors(n) li = [x - 1 for x in li] ans = 0 for x in li: if is_favorite(n, x): ans += x print(ans)
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] # 約数から1引いたものが候補 arr = make_divisors(n) arr = [x - 1 for x in arr if x >= 2] #  商と剰余が不一致ならbreakできる ans = 0 for x in arr[::-1]: if n // x != n % x: break ans += x print(ans)
false
15.625
[ "-def is_favorite(n, m):", "- if x == 0:", "- return False", "- else:", "- return n // m == n % m", "-", "-", "-li = make_divisors(n)", "-li = [x - 1 for x in li]", "+# 約数から1引いたものが候補", "+arr = make_divisors(n)", "+arr = [x - 1 for x in arr if x >= 2]", "+#  商と剰余が不一致ならbreakできる", "-for x in li:", "- if is_favorite(n, x):", "- ans += x", "+for x in arr[::-1]:", "+ if n // x != n % x:", "+ break", "+ ans += x" ]
false
0.300972
0.296402
1.01542
[ "s940708770", "s703032183" ]
u860657719
p02727
python
s775215802
s422587025
283
249
23,340
22,592
Accepted
Accepted
12.01
X,Y,A,B,C = list(map(int, input().split())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] r = [int(x) for x in input().split()] p.sort(reverse = True) q.sort(reverse = True) r.sort(reverse = True) newp = p[:X] newq = q[:Y] lis = newp + newq lis.sort(reverse = True) s = sum(lis) for i in range(len(r)): if lis[-i-1] < r[i]: s = s - lis[-i-1] + r[i] else: break print(s)
#X,Y,A,B,C = map(int, input().split()) #p = [int(x) for x in input().split()] #q = [int(x) for x in input().split()] #r = [int(x) for x in input().split()] #p.sort(reverse = True) #q.sort(reverse = True) #r.sort(reverse = True) #newp = p[:X] #newq = q[:Y] #lis = newp + newq #lis.sort(reverse = True) #s = sum(lis) #for i in range(len(r)): # if lis[-i-1] < r[i]: # s = s - lis[-i-1] + r[i] # else: # break #print(s) X,Y,A,B,C = list(map(int, input().split())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] r = [int(x) for x in input().split()] p.sort(reverse = True) q.sort(reverse = True) p = p[:X] q = q[:Y] ans = p+q+r ans.sort(reverse = True) print((sum(ans[:X+Y])))
18
30
435
743
X, Y, A, B, C = list(map(int, input().split())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] r = [int(x) for x in input().split()] p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) newp = p[:X] newq = q[:Y] lis = newp + newq lis.sort(reverse=True) s = sum(lis) for i in range(len(r)): if lis[-i - 1] < r[i]: s = s - lis[-i - 1] + r[i] else: break print(s)
# X,Y,A,B,C = map(int, input().split()) # p = [int(x) for x in input().split()] # q = [int(x) for x in input().split()] # r = [int(x) for x in input().split()] # p.sort(reverse = True) # q.sort(reverse = True) # r.sort(reverse = True) # newp = p[:X] # newq = q[:Y] # lis = newp + newq # lis.sort(reverse = True) # s = sum(lis) # for i in range(len(r)): # if lis[-i-1] < r[i]: # s = s - lis[-i-1] + r[i] # else: # break # print(s) X, Y, A, B, C = list(map(int, input().split())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] r = [int(x) for x in input().split()] p.sort(reverse=True) q.sort(reverse=True) p = p[:X] q = q[:Y] ans = p + q + r ans.sort(reverse=True) print((sum(ans[: X + Y])))
false
40
[ "+# X,Y,A,B,C = map(int, input().split())", "+# p = [int(x) for x in input().split()]", "+# q = [int(x) for x in input().split()]", "+# r = [int(x) for x in input().split()]", "+# p.sort(reverse = True)", "+# q.sort(reverse = True)", "+# r.sort(reverse = True)", "+# newp = p[:X]", "+# newq = q[:Y]", "+# lis = newp + newq", "+# lis.sort(reverse = True)", "+# s = sum(lis)", "+# for i in range(len(r)):", "+# if lis[-i-1] < r[i]:", "+# s = s - lis[-i-1] + r[i]", "+# else:", "+# break", "+# print(s)", "-r.sort(reverse=True)", "-newp = p[:X]", "-newq = q[:Y]", "-lis = newp + newq", "-lis.sort(reverse=True)", "-s = sum(lis)", "-for i in range(len(r)):", "- if lis[-i - 1] < r[i]:", "- s = s - lis[-i - 1] + r[i]", "- else:", "- break", "-print(s)", "+p = p[:X]", "+q = q[:Y]", "+ans = p + q + r", "+ans.sort(reverse=True)", "+print((sum(ans[: X + Y])))" ]
false
0.038025
0.083133
0.4574
[ "s775215802", "s422587025" ]
u684120680
p02936
python
s230172850
s848130262
1,978
1,103
123,180
92,156
Accepted
Accepted
44.24
from collections import deque n, q = [int(i) for i in input().split()] ab = [[int(i) for i in input().split()] for _ in range(n-1)] px = [[int(i) for i in input().split()] for _ in range(q)] tree = [[] for _ in range(n+1)] for a, b in ab: tree[a].append(b) tree[b].append(a) counter = [0] * (n+1) for p, x in px: counter[p] += x # pop, appendまたはQueueライブラリだと間に合わない queue = deque([[0,1]]) while queue: parent, node = queue.popleft() for leaf in tree[node]: if leaf == parent: continue counter[leaf] += counter[node] queue.append([node, leaf]) print((*counter[1:]))
from collections import deque import sys s = sys.stdin.readlines() n, q = list(map(int, s[0].split())) tree = [[] for _ in range(n+1)] for ab in s[1:n]: a, b = list(map(int, ab.split())) tree[a].append(b) tree[b].append(a) counter = [0] * (n+1) for px in s[n:]: p, x = list(map(int, px.split())) counter[p] += x # pop, appendまたはQueueライブラリだと間に合わない queue = deque([[0,1]]) while queue: parent, node = queue.popleft() for leaf in tree[node]: if leaf == parent: continue counter[leaf] += counter[node] queue.append([node, leaf]) print((*counter[1:]))
26
28
647
622
from collections import deque n, q = [int(i) for i in input().split()] ab = [[int(i) for i in input().split()] for _ in range(n - 1)] px = [[int(i) for i in input().split()] for _ in range(q)] tree = [[] for _ in range(n + 1)] for a, b in ab: tree[a].append(b) tree[b].append(a) counter = [0] * (n + 1) for p, x in px: counter[p] += x # pop, appendまたはQueueライブラリだと間に合わない queue = deque([[0, 1]]) while queue: parent, node = queue.popleft() for leaf in tree[node]: if leaf == parent: continue counter[leaf] += counter[node] queue.append([node, leaf]) print((*counter[1:]))
from collections import deque import sys s = sys.stdin.readlines() n, q = list(map(int, s[0].split())) tree = [[] for _ in range(n + 1)] for ab in s[1:n]: a, b = list(map(int, ab.split())) tree[a].append(b) tree[b].append(a) counter = [0] * (n + 1) for px in s[n:]: p, x = list(map(int, px.split())) counter[p] += x # pop, appendまたはQueueライブラリだと間に合わない queue = deque([[0, 1]]) while queue: parent, node = queue.popleft() for leaf in tree[node]: if leaf == parent: continue counter[leaf] += counter[node] queue.append([node, leaf]) print((*counter[1:]))
false
7.142857
[ "+import sys", "-n, q = [int(i) for i in input().split()]", "-ab = [[int(i) for i in input().split()] for _ in range(n - 1)]", "-px = [[int(i) for i in input().split()] for _ in range(q)]", "+s = sys.stdin.readlines()", "+n, q = list(map(int, s[0].split()))", "-for a, b in ab:", "+for ab in s[1:n]:", "+ a, b = list(map(int, ab.split()))", "-for p, x in px:", "+for px in s[n:]:", "+ p, x = list(map(int, px.split()))" ]
false
0.06654
0.044893
1.482193
[ "s230172850", "s848130262" ]
u625554679
p03240
python
s655079975
s323201700
35
32
3,064
3,064
Accepted
Accepted
8.57
N = int(eval(input())) #def height(x, y, h, cx, cz): def city_dist(x1, y1, x2, y2): return(abs(x1-x2)+abs(y1-y2)) def height(x1, y1, cx, cy, H): return max(H-city_dist(x1, y1, cx, cy), 0) x = [] y = [] h = [] non_zero_index = -1 for i in range(N): line = [int(a) for a in input().split()] x.append(line[0]) y.append(line[1]) h.append(line[2]) if line[2] != 0: non_zero_index = i for cx in range(101): for cy in range(101): H = h[non_zero_index] + city_dist(x[non_zero_index], y[non_zero_index], cx, cy) answer = True for i in range(N): #print(cx, cy, H, i, x[i], y[i], h[i], height(x[i], y[i], cx, cy, H)) if h[i] != height(x[i], y[i], cx, cy, H): answer = False break if answer: print(("{} {} {}".format(cx, cy, H))) break if answer: break
N = int(eval(input())) x = [] y = [] h = [] nonzero_x = 0 nonzero_y = 0 nonzero_h = 0 for _ in range(N): xx, yy, hh = [int(x) for x in input().split()] x.append(xx) y.append(yy) h.append(hh) if nonzero_h == 0 and hh != 0: nonzero_x = xx nonzero_y = yy nonzero_h = hh def solve(): for cx in range(101): for cy in range(101): res = True calc_h = nonzero_h + abs(nonzero_x-cx) + abs(nonzero_y-cy) for i in range(N): hh = max(calc_h - abs(x[i]-cx) - abs(y[i]-cy), 0) if hh != h[i]: res = False break if res: print(("{} {} {}".format(cx, cy, calc_h))) return return solve()
38
35
953
810
N = int(eval(input())) # def height(x, y, h, cx, cz): def city_dist(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def height(x1, y1, cx, cy, H): return max(H - city_dist(x1, y1, cx, cy), 0) x = [] y = [] h = [] non_zero_index = -1 for i in range(N): line = [int(a) for a in input().split()] x.append(line[0]) y.append(line[1]) h.append(line[2]) if line[2] != 0: non_zero_index = i for cx in range(101): for cy in range(101): H = h[non_zero_index] + city_dist(x[non_zero_index], y[non_zero_index], cx, cy) answer = True for i in range(N): # print(cx, cy, H, i, x[i], y[i], h[i], height(x[i], y[i], cx, cy, H)) if h[i] != height(x[i], y[i], cx, cy, H): answer = False break if answer: print(("{} {} {}".format(cx, cy, H))) break if answer: break
N = int(eval(input())) x = [] y = [] h = [] nonzero_x = 0 nonzero_y = 0 nonzero_h = 0 for _ in range(N): xx, yy, hh = [int(x) for x in input().split()] x.append(xx) y.append(yy) h.append(hh) if nonzero_h == 0 and hh != 0: nonzero_x = xx nonzero_y = yy nonzero_h = hh def solve(): for cx in range(101): for cy in range(101): res = True calc_h = nonzero_h + abs(nonzero_x - cx) + abs(nonzero_y - cy) for i in range(N): hh = max(calc_h - abs(x[i] - cx) - abs(y[i] - cy), 0) if hh != h[i]: res = False break if res: print(("{} {} {}".format(cx, cy, calc_h))) return return solve()
false
7.894737
[ "-# def height(x, y, h, cx, cz):", "-def city_dist(x1, y1, x2, y2):", "- return abs(x1 - x2) + abs(y1 - y2)", "-", "-", "-def height(x1, y1, cx, cy, H):", "- return max(H - city_dist(x1, y1, cx, cy), 0)", "-", "-", "-non_zero_index = -1", "-for i in range(N):", "- line = [int(a) for a in input().split()]", "- x.append(line[0])", "- y.append(line[1])", "- h.append(line[2])", "- if line[2] != 0:", "- non_zero_index = i", "-for cx in range(101):", "- for cy in range(101):", "- H = h[non_zero_index] + city_dist(x[non_zero_index], y[non_zero_index], cx, cy)", "- answer = True", "- for i in range(N):", "- # print(cx, cy, H, i, x[i], y[i], h[i], height(x[i], y[i], cx, cy, H))", "- if h[i] != height(x[i], y[i], cx, cy, H):", "- answer = False", "- break", "- if answer:", "- print((\"{} {} {}\".format(cx, cy, H)))", "- break", "- if answer:", "- break", "+nonzero_x = 0", "+nonzero_y = 0", "+nonzero_h = 0", "+for _ in range(N):", "+ xx, yy, hh = [int(x) for x in input().split()]", "+ x.append(xx)", "+ y.append(yy)", "+ h.append(hh)", "+ if nonzero_h == 0 and hh != 0:", "+ nonzero_x = xx", "+ nonzero_y = yy", "+ nonzero_h = hh", "+", "+", "+def solve():", "+ for cx in range(101):", "+ for cy in range(101):", "+ res = True", "+ calc_h = nonzero_h + abs(nonzero_x - cx) + abs(nonzero_y - cy)", "+ for i in range(N):", "+ hh = max(calc_h - abs(x[i] - cx) - abs(y[i] - cy), 0)", "+ if hh != h[i]:", "+ res = False", "+ break", "+ if res:", "+ print((\"{} {} {}\".format(cx, cy, calc_h)))", "+ return", "+ return", "+", "+", "+solve()" ]
false
0.04175
0.052807
0.79061
[ "s655079975", "s323201700" ]
u968166680
p02781
python
s313932033
s111594092
94
67
62,180
61,784
Accepted
Accepted
28.72
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = list(map(int, read().split())) X = list(map(int, str(N))) L = len(X) dp1 = [[0] * (K + 1) for _ in range(L + 1)] dp2 = [[0] * (K + 1) for _ in range(L + 1)] dp1[0][0] = 1 for i, x in enumerate(X): for j in range(K + 1): if x != 0: if j > 0: dp1[i + 1][j] = dp1[i][j - 1] else: dp1[i + 1][j] = dp1[i][j] if j > 0: dp2[i + 1][j] = dp2[i][j - 1] * 9 if x != 0: dp2[i + 1][j] += dp1[i][j - 1] * (x - 1) dp2[i + 1][j] += dp2[i][j] if x != 0: dp2[i + 1][j] += dp1[i][j] print((dp1[L][K] + dp2[L][K])) return if __name__ == '__main__': main()
import sys read = sys.stdin.read def main(): N, K = list(map(int, read().split())) dp1 = [0] * (K + 1) dp2 = [0] * (K + 1) dp1[0] = 1 for x in map(int, str(N)): dp1, dp1_prev = [0] * (K + 1), dp1 dp2, dp2_prev = [0] * (K + 1), dp2 for j in range(K, -1, -1): if j > 0: dp2[j] = dp2_prev[j - 1] * 9 if x != 0: dp2[j] += dp1_prev[j - 1] * (x - 1) dp2[j] += dp2_prev[j] if x != 0: dp2[j] += dp1_prev[j] if x != 0: if j > 0: dp1[j] = dp1_prev[j - 1] else: dp1[j] = dp1_prev[j] print((dp1[K] + dp2[K])) return if __name__ == '__main__': main()
41
36
981
826
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = list(map(int, read().split())) X = list(map(int, str(N))) L = len(X) dp1 = [[0] * (K + 1) for _ in range(L + 1)] dp2 = [[0] * (K + 1) for _ in range(L + 1)] dp1[0][0] = 1 for i, x in enumerate(X): for j in range(K + 1): if x != 0: if j > 0: dp1[i + 1][j] = dp1[i][j - 1] else: dp1[i + 1][j] = dp1[i][j] if j > 0: dp2[i + 1][j] = dp2[i][j - 1] * 9 if x != 0: dp2[i + 1][j] += dp1[i][j - 1] * (x - 1) dp2[i + 1][j] += dp2[i][j] if x != 0: dp2[i + 1][j] += dp1[i][j] print((dp1[L][K] + dp2[L][K])) return if __name__ == "__main__": main()
import sys read = sys.stdin.read def main(): N, K = list(map(int, read().split())) dp1 = [0] * (K + 1) dp2 = [0] * (K + 1) dp1[0] = 1 for x in map(int, str(N)): dp1, dp1_prev = [0] * (K + 1), dp1 dp2, dp2_prev = [0] * (K + 1), dp2 for j in range(K, -1, -1): if j > 0: dp2[j] = dp2_prev[j - 1] * 9 if x != 0: dp2[j] += dp1_prev[j - 1] * (x - 1) dp2[j] += dp2_prev[j] if x != 0: dp2[j] += dp1_prev[j] if x != 0: if j > 0: dp1[j] = dp1_prev[j - 1] else: dp1[j] = dp1_prev[j] print((dp1[K] + dp2[K])) return if __name__ == "__main__": main()
false
12.195122
[ "-readline = sys.stdin.readline", "-readlines = sys.stdin.readlines", "-sys.setrecursionlimit(10**9)", "-INF = 1 << 60", "-MOD = 1000000007", "- X = list(map(int, str(N)))", "- L = len(X)", "- dp1 = [[0] * (K + 1) for _ in range(L + 1)]", "- dp2 = [[0] * (K + 1) for _ in range(L + 1)]", "- dp1[0][0] = 1", "- for i, x in enumerate(X):", "- for j in range(K + 1):", "+ dp1 = [0] * (K + 1)", "+ dp2 = [0] * (K + 1)", "+ dp1[0] = 1", "+ for x in map(int, str(N)):", "+ dp1, dp1_prev = [0] * (K + 1), dp1", "+ dp2, dp2_prev = [0] * (K + 1), dp2", "+ for j in range(K, -1, -1):", "+ if j > 0:", "+ dp2[j] = dp2_prev[j - 1] * 9", "+ if x != 0:", "+ dp2[j] += dp1_prev[j - 1] * (x - 1)", "+ dp2[j] += dp2_prev[j]", "+ if x != 0:", "+ dp2[j] += dp1_prev[j]", "- dp1[i + 1][j] = dp1[i][j - 1]", "+ dp1[j] = dp1_prev[j - 1]", "- dp1[i + 1][j] = dp1[i][j]", "- if j > 0:", "- dp2[i + 1][j] = dp2[i][j - 1] * 9", "- if x != 0:", "- dp2[i + 1][j] += dp1[i][j - 1] * (x - 1)", "- dp2[i + 1][j] += dp2[i][j]", "- if x != 0:", "- dp2[i + 1][j] += dp1[i][j]", "- print((dp1[L][K] + dp2[L][K]))", "+ dp1[j] = dp1_prev[j]", "+ print((dp1[K] + dp2[K]))" ]
false
0.038583
0.038026
1.014647
[ "s313932033", "s111594092" ]
u533039576
p03017
python
s843558638
s742549083
56
19
3,636
3,572
Accepted
Accepted
66.07
n, a, b, c, d = list(map(int, input().split())) s = '#' + eval(input()) def check(l, r): for i in range(l, r): if s[i] == '#' and s[i+1] == '#': return False return True if c < d: if check(a, c) and check(b, d): print("Yes") else: print("No") else: # c > d space = False for i in range(b, d+1): if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.': space = True break if space and check(a, c) and check(b, d): print("Yes") else: print("No")
n, a, b, c, d = list(map(int, input().split())) s = '#' + eval(input()) def check(l, r): return "##" not in s[l:r] if c < d: if check(a, c) and check(b, d): print("Yes") else: print("No") else: # c > d space = "..." in s[b-1:d+2] if space and check(a, c) and check(b, d): print("Yes") else: print("No")
27
17
573
365
n, a, b, c, d = list(map(int, input().split())) s = "#" + eval(input()) def check(l, r): for i in range(l, r): if s[i] == "#" and s[i + 1] == "#": return False return True if c < d: if check(a, c) and check(b, d): print("Yes") else: print("No") else: # c > d space = False for i in range(b, d + 1): if s[i - 1] == "." and s[i] == "." and s[i + 1] == ".": space = True break if space and check(a, c) and check(b, d): print("Yes") else: print("No")
n, a, b, c, d = list(map(int, input().split())) s = "#" + eval(input()) def check(l, r): return "##" not in s[l:r] if c < d: if check(a, c) and check(b, d): print("Yes") else: print("No") else: # c > d space = "..." in s[b - 1 : d + 2] if space and check(a, c) and check(b, d): print("Yes") else: print("No")
false
37.037037
[ "- for i in range(l, r):", "- if s[i] == \"#\" and s[i + 1] == \"#\":", "- return False", "- return True", "+ return \"##\" not in s[l:r]", "- space = False", "- for i in range(b, d + 1):", "- if s[i - 1] == \".\" and s[i] == \".\" and s[i + 1] == \".\":", "- space = True", "- break", "+ space = \"...\" in s[b - 1 : d + 2]" ]
false
0.037991
0.038763
0.980088
[ "s843558638", "s742549083" ]
u412035967
p02789
python
s743331986
s683836773
167
26
38,256
3,952
Accepted
Accepted
84.43
N, M = list(map(int, input().split())) if N > M: print('No') else: print('Yes')
import queue as Q N, M = list(map(int, input().split())) if N > M: print('No') else: print('Yes')
6
8
83
104
N, M = list(map(int, input().split())) if N > M: print("No") else: print("Yes")
import queue as Q N, M = list(map(int, input().split())) if N > M: print("No") else: print("Yes")
false
25
[ "+import queue as Q", "+" ]
false
0.049873
0.033724
1.478852
[ "s743331986", "s683836773" ]
u595856802
p03031
python
s120550715
s171220381
216
195
41,712
41,324
Accepted
Accepted
9.72
N, M = list(map(int, input().split())) kss = [list(map(int, input().split())) for _ in range(M)] ps = list(map(int, input().split())) answer = 0 for i in range(1 << N): for (_, *ss), p in zip(kss, ps): okay = True if sum([(i >> s-1) & 1 for s in ss]) % 2 != p: okay = False break if okay: answer += 1 print(answer)
from itertools import product N, M = list(map(int, input().split())) kss = [list(map(int, input().split())) for _ in range(M)] ps = list(map(int, input().split())) answer = 0 for switches in product(list(range(2)), repeat=N): for (_, *ss), p in zip(kss, ps): okay = True if sum([switches[s-1] for s in ss]) % 2 != p: okay = False break if okay: answer += 1 print(answer)
15
17
381
434
N, M = list(map(int, input().split())) kss = [list(map(int, input().split())) for _ in range(M)] ps = list(map(int, input().split())) answer = 0 for i in range(1 << N): for (_, *ss), p in zip(kss, ps): okay = True if sum([(i >> s - 1) & 1 for s in ss]) % 2 != p: okay = False break if okay: answer += 1 print(answer)
from itertools import product N, M = list(map(int, input().split())) kss = [list(map(int, input().split())) for _ in range(M)] ps = list(map(int, input().split())) answer = 0 for switches in product(list(range(2)), repeat=N): for (_, *ss), p in zip(kss, ps): okay = True if sum([switches[s - 1] for s in ss]) % 2 != p: okay = False break if okay: answer += 1 print(answer)
false
11.764706
[ "+from itertools import product", "+", "-for i in range(1 << N):", "+for switches in product(list(range(2)), repeat=N):", "- if sum([(i >> s - 1) & 1 for s in ss]) % 2 != p:", "+ if sum([switches[s - 1] for s in ss]) % 2 != p:" ]
false
0.071811
0.062662
1.146008
[ "s120550715", "s171220381" ]
u077291787
p03741
python
s598227320
s550833629
103
74
14,468
14,084
Accepted
Accepted
28.16
# ARC072C - Sequence (ABC059C) def main(): n = int(eval(input())) lst = list(map(int, input().rstrip().split())) cnt = [0] * 2 # start with positive number cur = 0 for i, j in enumerate(lst): cur += j if i % 2 == 0 and cur <= 0: cnt[0] += abs(cur) + 1 cur = 1 elif i % 2 == 1 and cur >= 0: cnt[0] += abs(cur) + 1 cur = -1 # start with negative number cur = 0 for i, j in enumerate(lst): cur += j if i % 2 == 0 and cur >= 0: cnt[1] += abs(cur) + 1 cur = -1 elif i % 2 == 1 and cur <= 0: cnt[1] += abs(cur) + 1 cur = 1 print((min(cnt))) if __name__ == "__main__": main()
# ARC072C - Sequence (ABC059C) def modify_seq(seq: list, is_positive: bool) -> int: cur, cnt = 0, 0 for i in seq: cur += i if is_positive and cur <= 0: cnt += abs(cur) + 1 cur = 1 elif not is_positive and cur >= 0: cnt += abs(cur) + 1 cur = -1 is_positive = not is_positive return cnt def main(): _, *A = list(map(int, open(0).read().split())) print((min(modify_seq(A, True), modify_seq(A, False)))) if __name__ == "__main__": main()
33
22
789
555
# ARC072C - Sequence (ABC059C) def main(): n = int(eval(input())) lst = list(map(int, input().rstrip().split())) cnt = [0] * 2 # start with positive number cur = 0 for i, j in enumerate(lst): cur += j if i % 2 == 0 and cur <= 0: cnt[0] += abs(cur) + 1 cur = 1 elif i % 2 == 1 and cur >= 0: cnt[0] += abs(cur) + 1 cur = -1 # start with negative number cur = 0 for i, j in enumerate(lst): cur += j if i % 2 == 0 and cur >= 0: cnt[1] += abs(cur) + 1 cur = -1 elif i % 2 == 1 and cur <= 0: cnt[1] += abs(cur) + 1 cur = 1 print((min(cnt))) if __name__ == "__main__": main()
# ARC072C - Sequence (ABC059C) def modify_seq(seq: list, is_positive: bool) -> int: cur, cnt = 0, 0 for i in seq: cur += i if is_positive and cur <= 0: cnt += abs(cur) + 1 cur = 1 elif not is_positive and cur >= 0: cnt += abs(cur) + 1 cur = -1 is_positive = not is_positive return cnt def main(): _, *A = list(map(int, open(0).read().split())) print((min(modify_seq(A, True), modify_seq(A, False)))) if __name__ == "__main__": main()
false
33.333333
[ "+def modify_seq(seq: list, is_positive: bool) -> int:", "+ cur, cnt = 0, 0", "+ for i in seq:", "+ cur += i", "+ if is_positive and cur <= 0:", "+ cnt += abs(cur) + 1", "+ cur = 1", "+ elif not is_positive and cur >= 0:", "+ cnt += abs(cur) + 1", "+ cur = -1", "+ is_positive = not is_positive", "+ return cnt", "+", "+", "- n = int(eval(input()))", "- lst = list(map(int, input().rstrip().split()))", "- cnt = [0] * 2", "- # start with positive number", "- cur = 0", "- for i, j in enumerate(lst):", "- cur += j", "- if i % 2 == 0 and cur <= 0:", "- cnt[0] += abs(cur) + 1", "- cur = 1", "- elif i % 2 == 1 and cur >= 0:", "- cnt[0] += abs(cur) + 1", "- cur = -1", "- # start with negative number", "- cur = 0", "- for i, j in enumerate(lst):", "- cur += j", "- if i % 2 == 0 and cur >= 0:", "- cnt[1] += abs(cur) + 1", "- cur = -1", "- elif i % 2 == 1 and cur <= 0:", "- cnt[1] += abs(cur) + 1", "- cur = 1", "- print((min(cnt)))", "+ _, *A = list(map(int, open(0).read().split()))", "+ print((min(modify_seq(A, True), modify_seq(A, False))))" ]
false
0.042794
0.04578
0.934785
[ "s598227320", "s550833629" ]
u440566786
p03163
python
s315040167
s497825852
434
356
118,896
117,744
Accepted
Accepted
17.97
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.buffer.readline().rstrip() def resolve(): n,w=list(map(int,input().split())) W=[0]*n V=[0]*n for i in range(n): W[i],V[i]=list(map(int,input().split())) dp=[[0]*(w+1) for _ in range(n+1)] for i in range(n): for k in range(w+1): if(k+W[i]<=w): dp[i+1][k+W[i]]=max(dp[i][k]+V[i],dp[i+1][k+W[i]]) dp[i+1][k]=max(dp[i+1][k],dp[i][k]) print((dp[n][w])) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,W=list(map(int,input().split())) w=[0]*(n+1) v=[0]*(n+1) for i in range(1,n+1): w[i],v[i]=list(map(int,input().split())) dp=[0]*(W+1) for i in range(1,n+1): # i番目を見る newdp=dp[:] for j in range(W+1): if(j+w[i]<=W): newdp[j+w[i]]=max(newdp[j+w[i]],dp[j]+v[i]) dp=newdp print((dp[-1])) resolve()
19
20
543
520
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.buffer.readline().rstrip() def resolve(): n, w = list(map(int, input().split())) W = [0] * n V = [0] * n for i in range(n): W[i], V[i] = list(map(int, input().split())) dp = [[0] * (w + 1) for _ in range(n + 1)] for i in range(n): for k in range(w + 1): if k + W[i] <= w: dp[i + 1][k + W[i]] = max(dp[i][k] + V[i], dp[i + 1][k + W[i]]) dp[i + 1][k] = max(dp[i + 1][k], dp[i][k]) print((dp[n][w])) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, W = list(map(int, input().split())) w = [0] * (n + 1) v = [0] * (n + 1) for i in range(1, n + 1): w[i], v[i] = list(map(int, input().split())) dp = [0] * (W + 1) for i in range(1, n + 1): # i番目を見る newdp = dp[:] for j in range(W + 1): if j + w[i] <= W: newdp[j + w[i]] = max(newdp[j + w[i]], dp[j] + v[i]) dp = newdp print((dp[-1])) resolve()
false
5
[ "-input = lambda: sys.stdin.buffer.readline().rstrip()", "+input = lambda: sys.stdin.readline().rstrip()", "- n, w = list(map(int, input().split()))", "- W = [0] * n", "- V = [0] * n", "- for i in range(n):", "- W[i], V[i] = list(map(int, input().split()))", "- dp = [[0] * (w + 1) for _ in range(n + 1)]", "- for i in range(n):", "- for k in range(w + 1):", "- if k + W[i] <= w:", "- dp[i + 1][k + W[i]] = max(dp[i][k] + V[i], dp[i + 1][k + W[i]])", "- dp[i + 1][k] = max(dp[i + 1][k], dp[i][k])", "- print((dp[n][w]))", "+ n, W = list(map(int, input().split()))", "+ w = [0] * (n + 1)", "+ v = [0] * (n + 1)", "+ for i in range(1, n + 1):", "+ w[i], v[i] = list(map(int, input().split()))", "+ dp = [0] * (W + 1)", "+ for i in range(1, n + 1): # i番目を見る", "+ newdp = dp[:]", "+ for j in range(W + 1):", "+ if j + w[i] <= W:", "+ newdp[j + w[i]] = max(newdp[j + w[i]], dp[j] + v[i])", "+ dp = newdp", "+ print((dp[-1]))" ]
false
0.039341
0.033131
1.18742
[ "s315040167", "s497825852" ]
u808757777
p02879
python
s319630416
s940752035
19
17
3,060
2,940
Accepted
Accepted
10.53
a,b=list(map(int,input().split(' '))) if a<10 and b<10: print((a*b)) else: print((-1))
a, b = list(map(int, input().split(' '))) if 1<=a<=9 and 1<=b<=9: print((a*b)) else: print((-1))
6
6
86
97
a, b = list(map(int, input().split(" "))) if a < 10 and b < 10: print((a * b)) else: print((-1))
a, b = list(map(int, input().split(" "))) if 1 <= a <= 9 and 1 <= b <= 9: print((a * b)) else: print((-1))
false
0
[ "-if a < 10 and b < 10:", "+if 1 <= a <= 9 and 1 <= b <= 9:" ]
false
0.079402
0.072203
1.099712
[ "s319630416", "s940752035" ]
u653041271
p02701
python
s036944362
s356971432
336
276
23,920
45,876
Accepted
Accepted
17.86
n=int(eval(input())) s = [eval(input()) for i in range(n)] s.sort() ans=n for i in range(1,n): if s[i]==s[i-1]: ans-=1 print(ans)
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(eval(input())) def inpm(): return list(map(int,input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() s = [eval(input()) for _ in range(n)] s.sort() ans = 1 for i in range(1,n): if s[i] != s[i-1]: ans += 1 print(ans)
9
30
132
975
n = int(eval(input())) s = [eval(input()) for i in range(n)] s.sort() ans = n for i in range(1, n): if s[i] == s[i - 1]: ans -= 1 print(ans)
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter, defaultdict, deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(eval(input())) def inpm(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() s = [eval(input()) for _ in range(n)] s.sort() ans = 1 for i in range(1, n): if s[i] != s[i - 1]: ans += 1 print(ans)
false
70
[ "-n = int(eval(input()))", "-s = [eval(input()) for i in range(n)]", "+import sys, bisect, math, itertools, string, queue, copy", "+import numpy as np", "+import scipy", "+from collections import Counter, defaultdict, deque", "+from itertools import permutations, combinations", "+from heapq import heappop, heappush", "+from fractions import gcd", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**8)", "+mod = 10**9 + 7", "+", "+", "+def inp():", "+ return int(eval(input()))", "+", "+", "+def inpm():", "+ return list(map(int, input().split()))", "+", "+", "+def inpl():", "+ return list(map(int, input().split()))", "+", "+", "+def inpls():", "+ return list(input().split())", "+", "+", "+def inplm(n):", "+ return list(int(eval(input())) for _ in range(n))", "+", "+", "+def inplL(n):", "+ return [list(eval(input())) for _ in range(n)]", "+", "+", "+def inplT(n):", "+ return [tuple(eval(input())) for _ in range(n)]", "+", "+", "+def inpll(n):", "+ return [list(map(int, input().split())) for _ in range(n)]", "+", "+", "+def inplls(n):", "+ return sorted([list(map(int, input().split())) for _ in range(n)])", "+", "+", "+n = inp()", "+s = [eval(input()) for _ in range(n)]", "-ans = n", "+ans = 1", "- if s[i] == s[i - 1]:", "- ans -= 1", "+ if s[i] != s[i - 1]:", "+ ans += 1" ]
false
0.038045
0.04114
0.92477
[ "s036944362", "s356971432" ]
u312025627
p02579
python
s687278855
s495149244
918
770
97,160
97,860
Accepted
Accepted
16.12
INF = 10**9 + 7 def main(): from heapq import heappop, heappush H, W = (int(i) for i in input().split()) Ch, Cw = (int(i)-1 for i in input().split()) Dh, Dw = (int(i)-1 for i in input().split()) A = [eval(input()) for i in range(H)] dist = [[INF]*W for _ in range(H)] dist[Ch][Cw] = 0 que = [(0, Ch*W + Cw)] while que: u_dist, u = heappop(que) uh, uw = u//W, u % W if dist[uh][uw] < u_dist: continue for dh in range(-2, 3): for dw in range(-2, 3): nh = uh + dh nw = uw + dw if nh < 0 or H <= nh or nw < 0 or W <= nw: continue if A[nh][nw] == "#": continue cost = 0 if abs(dh) + abs(dw) <= 1 else 1 if dist[nh][nw] > dist[uh][uw] + cost: dist[nh][nw] = dist[uh][uw] + cost heappush(que, (dist[nh][nw], nh*W + nw)) if dist[Dh][Dw] == INF: print((-1)) else: print((dist[Dh][Dw])) # for h in range(H): # print(dist[h]) if __name__ == '__main__': main()
# 01BFS INF = 10**9 + 7 def main(): from collections import deque H, W = (int(i) for i in input().split()) Ch, Cw = (int(i)-1 for i in input().split()) Dh, Dw = (int(i)-1 for i in input().split()) A = [eval(input()) for i in range(H)] def bfs_2d(c, sy, sx, gh, gw, H, W): que = deque() dist = [[INF]*W for i in range(H)] dist[sy][sx] = 0 que.append((sy, sx)) while que: uh, uw = que.popleft() for dh in range(-2, 3): for dw in range(-2, 3): next_h = uh + dh next_w = uw + dw cost = 0 if abs(dh) + abs(dw) <= 1 else 1 if not(0 <= next_h < H and 0 <= next_w < W): continue if c[next_h][next_w] == "#": continue if dist[next_h][next_w] > dist[uh][uw] + cost: dist[next_h][next_w] = dist[uh][uw] + cost if cost == 1: que.append((next_h, next_w)) else: que.appendleft((next_h, next_w)) return dist[gh][gw] if dist[gh][gw] != INF else -1 ans = bfs_2d(A, Ch, Cw, Dh, Dw, H, W) print(ans) if __name__ == '__main__': main()
42
42
1,195
1,377
INF = 10**9 + 7 def main(): from heapq import heappop, heappush H, W = (int(i) for i in input().split()) Ch, Cw = (int(i) - 1 for i in input().split()) Dh, Dw = (int(i) - 1 for i in input().split()) A = [eval(input()) for i in range(H)] dist = [[INF] * W for _ in range(H)] dist[Ch][Cw] = 0 que = [(0, Ch * W + Cw)] while que: u_dist, u = heappop(que) uh, uw = u // W, u % W if dist[uh][uw] < u_dist: continue for dh in range(-2, 3): for dw in range(-2, 3): nh = uh + dh nw = uw + dw if nh < 0 or H <= nh or nw < 0 or W <= nw: continue if A[nh][nw] == "#": continue cost = 0 if abs(dh) + abs(dw) <= 1 else 1 if dist[nh][nw] > dist[uh][uw] + cost: dist[nh][nw] = dist[uh][uw] + cost heappush(que, (dist[nh][nw], nh * W + nw)) if dist[Dh][Dw] == INF: print((-1)) else: print((dist[Dh][Dw])) # for h in range(H): # print(dist[h]) if __name__ == "__main__": main()
# 01BFS INF = 10**9 + 7 def main(): from collections import deque H, W = (int(i) for i in input().split()) Ch, Cw = (int(i) - 1 for i in input().split()) Dh, Dw = (int(i) - 1 for i in input().split()) A = [eval(input()) for i in range(H)] def bfs_2d(c, sy, sx, gh, gw, H, W): que = deque() dist = [[INF] * W for i in range(H)] dist[sy][sx] = 0 que.append((sy, sx)) while que: uh, uw = que.popleft() for dh in range(-2, 3): for dw in range(-2, 3): next_h = uh + dh next_w = uw + dw cost = 0 if abs(dh) + abs(dw) <= 1 else 1 if not (0 <= next_h < H and 0 <= next_w < W): continue if c[next_h][next_w] == "#": continue if dist[next_h][next_w] > dist[uh][uw] + cost: dist[next_h][next_w] = dist[uh][uw] + cost if cost == 1: que.append((next_h, next_w)) else: que.appendleft((next_h, next_w)) return dist[gh][gw] if dist[gh][gw] != INF else -1 ans = bfs_2d(A, Ch, Cw, Dh, Dw, H, W) print(ans) if __name__ == "__main__": main()
false
0
[ "+# 01BFS", "- from heapq import heappop, heappush", "+ from collections import deque", "- dist = [[INF] * W for _ in range(H)]", "- dist[Ch][Cw] = 0", "- que = [(0, Ch * W + Cw)]", "- while que:", "- u_dist, u = heappop(que)", "- uh, uw = u // W, u % W", "- if dist[uh][uw] < u_dist:", "- continue", "- for dh in range(-2, 3):", "- for dw in range(-2, 3):", "- nh = uh + dh", "- nw = uw + dw", "- if nh < 0 or H <= nh or nw < 0 or W <= nw:", "- continue", "- if A[nh][nw] == \"#\":", "- continue", "- cost = 0 if abs(dh) + abs(dw) <= 1 else 1", "- if dist[nh][nw] > dist[uh][uw] + cost:", "- dist[nh][nw] = dist[uh][uw] + cost", "- heappush(que, (dist[nh][nw], nh * W + nw))", "- if dist[Dh][Dw] == INF:", "- print((-1))", "- else:", "- print((dist[Dh][Dw]))", "- # for h in range(H):", "- # print(dist[h])", "+", "+ def bfs_2d(c, sy, sx, gh, gw, H, W):", "+ que = deque()", "+ dist = [[INF] * W for i in range(H)]", "+ dist[sy][sx] = 0", "+ que.append((sy, sx))", "+ while que:", "+ uh, uw = que.popleft()", "+ for dh in range(-2, 3):", "+ for dw in range(-2, 3):", "+ next_h = uh + dh", "+ next_w = uw + dw", "+ cost = 0 if abs(dh) + abs(dw) <= 1 else 1", "+ if not (0 <= next_h < H and 0 <= next_w < W):", "+ continue", "+ if c[next_h][next_w] == \"#\":", "+ continue", "+ if dist[next_h][next_w] > dist[uh][uw] + cost:", "+ dist[next_h][next_w] = dist[uh][uw] + cost", "+ if cost == 1:", "+ que.append((next_h, next_w))", "+ else:", "+ que.appendleft((next_h, next_w))", "+ return dist[gh][gw] if dist[gh][gw] != INF else -1", "+", "+ ans = bfs_2d(A, Ch, Cw, Dh, Dw, H, W)", "+ print(ans)" ]
false
0.040412
0.040968
0.986437
[ "s687278855", "s495149244" ]
u392029857
p03796
python
s950593851
s884822078
46
41
2,940
2,940
Accepted
Accepted
10.87
N = int(eval(input())) ans = 1 for i in range(1, N+1): ans *= i if ans >= (10**9 + 7): ans %= (10**9+7) print(ans)
N = int(eval(input())) ans = 1 for i in range(1,N+1): ans *= i ans %= (1000000000+7) print(ans)
7
6
130
102
N = int(eval(input())) ans = 1 for i in range(1, N + 1): ans *= i if ans >= (10**9 + 7): ans %= 10**9 + 7 print(ans)
N = int(eval(input())) ans = 1 for i in range(1, N + 1): ans *= i ans %= 1000000000 + 7 print(ans)
false
14.285714
[ "- if ans >= (10**9 + 7):", "- ans %= 10**9 + 7", "+ ans %= 1000000000 + 7" ]
false
0.060089
0.043862
1.369944
[ "s950593851", "s884822078" ]
u312025627
p02689
python
s760612086
s447515153
248
132
106,836
85,560
Accepted
Accepted
46.77
def main(): import sys input = sys.stdin.buffer.readline N, M = (int(i) for i in input().split()) H = [int(i) for i in input().split()] G = [set() for _ in range(N)] for i in range(M): a, b = (int(i) for i in input().split()) G[a-1].add(b-1) G[b-1].add(a-1) ans = 0 for a in range(N): if all(H[b] < H[a] for b in G[a]): ans += 1 print(ans) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.buffer.readline N, M = (int(i) for i in input().split()) H = [int(i) for i in input().split()] ans = [1]*N for _ in range(M): a, b = (int(i)-1 for i in input().split()) if H[a] < H[b]: ans[a] = 0 elif H[b] < H[a]: ans[b] = 0 else: ans[a] = 0 ans[b] = 0 print((sum(ans))) if __name__ == '__main__': main()
19
21
478
479
def main(): import sys input = sys.stdin.buffer.readline N, M = (int(i) for i in input().split()) H = [int(i) for i in input().split()] G = [set() for _ in range(N)] for i in range(M): a, b = (int(i) for i in input().split()) G[a - 1].add(b - 1) G[b - 1].add(a - 1) ans = 0 for a in range(N): if all(H[b] < H[a] for b in G[a]): ans += 1 print(ans) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline N, M = (int(i) for i in input().split()) H = [int(i) for i in input().split()] ans = [1] * N for _ in range(M): a, b = (int(i) - 1 for i in input().split()) if H[a] < H[b]: ans[a] = 0 elif H[b] < H[a]: ans[b] = 0 else: ans[a] = 0 ans[b] = 0 print((sum(ans))) if __name__ == "__main__": main()
false
9.52381
[ "- G = [set() for _ in range(N)]", "- for i in range(M):", "- a, b = (int(i) for i in input().split())", "- G[a - 1].add(b - 1)", "- G[b - 1].add(a - 1)", "- ans = 0", "- for a in range(N):", "- if all(H[b] < H[a] for b in G[a]):", "- ans += 1", "- print(ans)", "+ ans = [1] * N", "+ for _ in range(M):", "+ a, b = (int(i) - 1 for i in input().split())", "+ if H[a] < H[b]:", "+ ans[a] = 0", "+ elif H[b] < H[a]:", "+ ans[b] = 0", "+ else:", "+ ans[a] = 0", "+ ans[b] = 0", "+ print((sum(ans)))" ]
false
0.042343
0.060477
0.700154
[ "s760612086", "s447515153" ]
u367713721
p04030
python
s522578709
s271664256
180
17
12,760
3,060
Accepted
Accepted
90.56
# -*- coding:utf-8 -*- import numpy as np import scipy as sp s = eval(input()) n = len(s) s_list = [] for i in range(0, n): if s[i] == 'B': if len(s_list) == 0: continue else: s_list.pop(-1) else: s_list.append(s[i]) S = '' for i in range(0, len(s_list)): S = S + s_list[i] print(S)
# -*- coding:utf-8 -*- s = eval(input()) n = len(s) s_list = [] for i in range(0, n): if s[i] == 'B': if len(s_list) == 0: continue else: s_list.pop(-1) else: s_list.append(s[i]) S = '' for i in range(0, len(s_list)): S = S + s_list[i] print(S)
24
21
451
409
# -*- coding:utf-8 -*- import numpy as np import scipy as sp s = eval(input()) n = len(s) s_list = [] for i in range(0, n): if s[i] == "B": if len(s_list) == 0: continue else: s_list.pop(-1) else: s_list.append(s[i]) S = "" for i in range(0, len(s_list)): S = S + s_list[i] print(S)
# -*- coding:utf-8 -*- s = eval(input()) n = len(s) s_list = [] for i in range(0, n): if s[i] == "B": if len(s_list) == 0: continue else: s_list.pop(-1) else: s_list.append(s[i]) S = "" for i in range(0, len(s_list)): S = S + s_list[i] print(S)
false
12.5
[ "-import numpy as np", "-import scipy as sp", "-" ]
false
0.047991
0.083096
0.577528
[ "s522578709", "s271664256" ]
u588341295
p03673
python
s833553104
s145062137
202
172
31,940
32,964
Accepted
Accepted
14.85
# -*- coding: utf-8 -*- N = int(eval(input())) aN = list(map(int, input().split())) bN = [0] * N if N % 2 == 0: for i in range(N): if i % 2 == 0: bN[(N//2) + i//2] = str(aN[i]) else: bN[(N//2) - (i+1)//2] = str(aN[i]) else: for i in range(N): if i % 2 == 0: bN[(N//2) - i//2] = str(aN[i]) else: bN[(N//2) + (i+1)//2] = str(aN[i]) print((" ".join(bN)))
# -*- coding: utf-8 -*- # 普通のリストじゃなくてこれ使えば、左への挿入も速いとのこと from collections import deque N = int(eval(input())) aN = list(map(int, input().split())) bN = deque() if N % 2 == 0: for i in range(N): if i % 2 == 0: bN.append(str(aN[i])) else: bN.appendleft(str(aN[i])) else: for i in range(N): if i % 2 == 1: bN.append(str(aN[i])) else: bN.appendleft(str(aN[i])) print((" ".join(bN)))
20
23
453
483
# -*- coding: utf-8 -*- N = int(eval(input())) aN = list(map(int, input().split())) bN = [0] * N if N % 2 == 0: for i in range(N): if i % 2 == 0: bN[(N // 2) + i // 2] = str(aN[i]) else: bN[(N // 2) - (i + 1) // 2] = str(aN[i]) else: for i in range(N): if i % 2 == 0: bN[(N // 2) - i // 2] = str(aN[i]) else: bN[(N // 2) + (i + 1) // 2] = str(aN[i]) print((" ".join(bN)))
# -*- coding: utf-8 -*- # 普通のリストじゃなくてこれ使えば、左への挿入も速いとのこと from collections import deque N = int(eval(input())) aN = list(map(int, input().split())) bN = deque() if N % 2 == 0: for i in range(N): if i % 2 == 0: bN.append(str(aN[i])) else: bN.appendleft(str(aN[i])) else: for i in range(N): if i % 2 == 1: bN.append(str(aN[i])) else: bN.appendleft(str(aN[i])) print((" ".join(bN)))
false
13.043478
[ "+# 普通のリストじゃなくてこれ使えば、左への挿入も速いとのこと", "+from collections import deque", "+", "-bN = [0] * N", "+bN = deque()", "- bN[(N // 2) + i // 2] = str(aN[i])", "+ bN.append(str(aN[i]))", "- bN[(N // 2) - (i + 1) // 2] = str(aN[i])", "+ bN.appendleft(str(aN[i]))", "- if i % 2 == 0:", "- bN[(N // 2) - i // 2] = str(aN[i])", "+ if i % 2 == 1:", "+ bN.append(str(aN[i]))", "- bN[(N // 2) + (i + 1) // 2] = str(aN[i])", "+ bN.appendleft(str(aN[i]))" ]
false
0.086261
0.049912
1.728245
[ "s833553104", "s145062137" ]
u852690916
p02763
python
s256583261
s726522465
1,919
527
453,840
112,336
Accepted
Accepted
72.54
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N,S,Q,*q = read().decode().split() N = int(N) S = list(S) c = lambda x: ord(x) - ord('a') tree = [SegmentTree(N, lambda x,y:x|y) for _ in range(26)] for i, l in enumerate(S): tree[c(l)].update(i, 1) for t, a, b in zip(*[iter(q)]*3): if t == '1': a = int(a) - 1 tree[c(S[a])].update(a, 0) tree[c(b)].update(a, 1) S[a] = b else: a, b = int(a)-1, int(b)-1 ans = 0 for i in range(26): t = tree[i].query(a, b+1) ans += 1 if t else 0 print(ans) class SegmentTree: def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None): assert(n or initial_values) size = n if n else len(initial_values) self.__f, self.__z, self.__c = f, zero_factory, converter self.__n = 1 << ((size - 1).bit_length()) self.__dat = [zero_factory() for _ in range(2 * self.__n)] if initial_values: zi = self.__get_leaf(0) for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v) for i in range(zi-1, -1, -1): self.__dat[i] = f(*self.__get_children(i)) def update(self, index, value): i, v = self.__get_leaf(index), self.__c(value) if self.__dat[i] == v: return self.__dat[i] = v while i: i = self.__get_parent(i) self.__dat[i] = self.__f(*self.__get_children(i)) def query(self, from_inclusive, to_exclusive): ans = self.__z() if to_exclusive <= from_inclusive: return ans l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1 while r - l > 1: if self.__is_right(l): ans = self.__f(ans, self.__dat[l]) if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1 l, r = l//2, self.__get_parent(r) ans = self.__f(ans, self.__dat[l]) if l != r: ans = self.__f(ans, self.__dat[r]) return ans def __get_leaf(self, i): return self.__n + i - 1 def __get_parent(self, i): return (i-1)//2 def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2]) def __is_left(self, i): return i&1 == 1 def __is_right(self, i): return i&1 == 0 if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N,S,Q,*q = read().split() S = S.decode() tree = SegmentTree(initial_values=S, f=lambda x,y:x|y, converter=lambda c: 1 << (ord(c)-ord('a'))) for t, a, b in zip(*[iter(q)]*3): if t == b'1': tree.update(int(a)-1, b) else: print((bin(tree.query(int(a)-1, int(b))).count('1'))) class SegmentTree: def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None): assert(n or initial_values) size = n if n else len(initial_values) self.__f, self.__z, self.__c = f, zero_factory, converter self.__n = 1 << ((size - 1).bit_length()) self.__dat = [zero_factory() for _ in range(2 * self.__n)] if initial_values: zi = self.__get_leaf(0) for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v) for i in range(zi-1, -1, -1): self.__dat[i] = f(*self.__get_children(i)) def update(self, index, value): i, v = self.__get_leaf(index), self.__c(value) if self.__dat[i] == v: return self.__dat[i] = v while i: i = self.__get_parent(i) self.__dat[i] = self.__f(*self.__get_children(i)) def query(self, from_inclusive, to_exclusive): ans = self.__z() if to_exclusive <= from_inclusive: return ans l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1 while r - l > 1: if self.__is_right(l): ans = self.__f(ans, self.__dat[l]) if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1 l, r = l//2, self.__get_parent(r) ans = self.__f(ans, self.__dat[l]) if l != r: ans = self.__f(ans, self.__dat[r]) return ans def __get_leaf(self, i): return self.__n + i - 1 def __get_parent(self, i): return (i-1)//2 def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2]) def __is_left(self, i): return i&1 == 1 def __is_right(self, i): return i&1 == 0 if __name__ == '__main__': main()
68
53
2,562
2,230
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N, S, Q, *q = read().decode().split() N = int(N) S = list(S) c = lambda x: ord(x) - ord("a") tree = [SegmentTree(N, lambda x, y: x | y) for _ in range(26)] for i, l in enumerate(S): tree[c(l)].update(i, 1) for t, a, b in zip(*[iter(q)] * 3): if t == "1": a = int(a) - 1 tree[c(S[a])].update(a, 0) tree[c(b)].update(a, 1) S[a] = b else: a, b = int(a) - 1, int(b) - 1 ans = 0 for i in range(26): t = tree[i].query(a, b + 1) ans += 1 if t else 0 print(ans) class SegmentTree: def __init__( self, n=None, f=max, zero_factory=int, converter=lambda x: x, initial_values=None, ): assert n or initial_values size = n if n else len(initial_values) self.__f, self.__z, self.__c = f, zero_factory, converter self.__n = 1 << ((size - 1).bit_length()) self.__dat = [zero_factory() for _ in range(2 * self.__n)] if initial_values: zi = self.__get_leaf(0) for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v) for i in range(zi - 1, -1, -1): self.__dat[i] = f(*self.__get_children(i)) def update(self, index, value): i, v = self.__get_leaf(index), self.__c(value) if self.__dat[i] == v: return self.__dat[i] = v while i: i = self.__get_parent(i) self.__dat[i] = self.__f(*self.__get_children(i)) def query(self, from_inclusive, to_exclusive): ans = self.__z() if to_exclusive <= from_inclusive: return ans l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1 while r - l > 1: if self.__is_right(l): ans = self.__f(ans, self.__dat[l]) if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r - 1 l, r = l // 2, self.__get_parent(r) ans = self.__f(ans, self.__dat[l]) if l != r: ans = self.__f(ans, self.__dat[r]) return ans def __get_leaf(self, i): return self.__n + i - 1 def __get_parent(self, i): return (i - 1) // 2 def __get_children(self, i): return (self.__dat[2 * i + 1], self.__dat[2 * i + 2]) def __is_left(self, i): return i & 1 == 1 def __is_right(self, i): return i & 1 == 0 if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N, S, Q, *q = read().split() S = S.decode() tree = SegmentTree( initial_values=S, f=lambda x, y: x | y, converter=lambda c: 1 << (ord(c) - ord("a")), ) for t, a, b in zip(*[iter(q)] * 3): if t == b"1": tree.update(int(a) - 1, b) else: print((bin(tree.query(int(a) - 1, int(b))).count("1"))) class SegmentTree: def __init__( self, n=None, f=max, zero_factory=int, converter=lambda x: x, initial_values=None, ): assert n or initial_values size = n if n else len(initial_values) self.__f, self.__z, self.__c = f, zero_factory, converter self.__n = 1 << ((size - 1).bit_length()) self.__dat = [zero_factory() for _ in range(2 * self.__n)] if initial_values: zi = self.__get_leaf(0) for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v) for i in range(zi - 1, -1, -1): self.__dat[i] = f(*self.__get_children(i)) def update(self, index, value): i, v = self.__get_leaf(index), self.__c(value) if self.__dat[i] == v: return self.__dat[i] = v while i: i = self.__get_parent(i) self.__dat[i] = self.__f(*self.__get_children(i)) def query(self, from_inclusive, to_exclusive): ans = self.__z() if to_exclusive <= from_inclusive: return ans l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1 while r - l > 1: if self.__is_right(l): ans = self.__f(ans, self.__dat[l]) if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r - 1 l, r = l // 2, self.__get_parent(r) ans = self.__f(ans, self.__dat[l]) if l != r: ans = self.__f(ans, self.__dat[r]) return ans def __get_leaf(self, i): return self.__n + i - 1 def __get_parent(self, i): return (i - 1) // 2 def __get_children(self, i): return (self.__dat[2 * i + 1], self.__dat[2 * i + 2]) def __is_left(self, i): return i & 1 == 1 def __is_right(self, i): return i & 1 == 0 if __name__ == "__main__": main()
false
22.058824
[ "- N, S, Q, *q = read().decode().split()", "- N = int(N)", "- S = list(S)", "- c = lambda x: ord(x) - ord(\"a\")", "- tree = [SegmentTree(N, lambda x, y: x | y) for _ in range(26)]", "- for i, l in enumerate(S):", "- tree[c(l)].update(i, 1)", "+ N, S, Q, *q = read().split()", "+ S = S.decode()", "+ tree = SegmentTree(", "+ initial_values=S,", "+ f=lambda x, y: x | y,", "+ converter=lambda c: 1 << (ord(c) - ord(\"a\")),", "+ )", "- if t == \"1\":", "- a = int(a) - 1", "- tree[c(S[a])].update(a, 0)", "- tree[c(b)].update(a, 1)", "- S[a] = b", "+ if t == b\"1\":", "+ tree.update(int(a) - 1, b)", "- a, b = int(a) - 1, int(b) - 1", "- ans = 0", "- for i in range(26):", "- t = tree[i].query(a, b + 1)", "- ans += 1 if t else 0", "- print(ans)", "+ print((bin(tree.query(int(a) - 1, int(b))).count(\"1\")))" ]
false
0.038869
0.090979
0.427233
[ "s256583261", "s726522465" ]
u072717685
p03637
python
s685539404
s204427927
208
61
14,764
14,252
Accepted
Accepted
70.67
from copy import deepcopy def main(): n = int(eval(input())) a = list(map(int, input().split())) div2 = [0] * n div4 = deepcopy(div2) notdiv4 = deepcopy(div2) for i in range(n): if a[i] % 4 == 0: div4[i] = 1 elif a[i] % 2 == 0: div2[i] = 1 else: notdiv4[i] = 1 num_notdiv4 = sum(notdiv4) num_notdiv4 += sum(div2) % 2 if num_notdiv4 - 1 > sum(div4): print('No') else: print('Yes') if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) div2 = 0 div4 = 0 notdiv4 = 0 for ea in a: if ea % 4 == 0: div4 += 1 elif ea % 2 == 0: div2 += 1 else: notdiv4 += 1 notdiv4 += div2 % 2 if notdiv4 - 1 > div4: print('No') else: print('Yes') if __name__ == '__main__': main()
24
23
553
429
from copy import deepcopy def main(): n = int(eval(input())) a = list(map(int, input().split())) div2 = [0] * n div4 = deepcopy(div2) notdiv4 = deepcopy(div2) for i in range(n): if a[i] % 4 == 0: div4[i] = 1 elif a[i] % 2 == 0: div2[i] = 1 else: notdiv4[i] = 1 num_notdiv4 = sum(notdiv4) num_notdiv4 += sum(div2) % 2 if num_notdiv4 - 1 > sum(div4): print("No") else: print("Yes") if __name__ == "__main__": main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) div2 = 0 div4 = 0 notdiv4 = 0 for ea in a: if ea % 4 == 0: div4 += 1 elif ea % 2 == 0: div2 += 1 else: notdiv4 += 1 notdiv4 += div2 % 2 if notdiv4 - 1 > div4: print("No") else: print("Yes") if __name__ == "__main__": main()
false
4.166667
[ "-from copy import deepcopy", "-", "-", "- div2 = [0] * n", "- div4 = deepcopy(div2)", "- notdiv4 = deepcopy(div2)", "- for i in range(n):", "- if a[i] % 4 == 0:", "- div4[i] = 1", "- elif a[i] % 2 == 0:", "- div2[i] = 1", "+ div2 = 0", "+ div4 = 0", "+ notdiv4 = 0", "+ for ea in a:", "+ if ea % 4 == 0:", "+ div4 += 1", "+ elif ea % 2 == 0:", "+ div2 += 1", "- notdiv4[i] = 1", "- num_notdiv4 = sum(notdiv4)", "- num_notdiv4 += sum(div2) % 2", "- if num_notdiv4 - 1 > sum(div4):", "+ notdiv4 += 1", "+ notdiv4 += div2 % 2", "+ if notdiv4 - 1 > div4:" ]
false
0.1986
0.035729
5.558481
[ "s685539404", "s204427927" ]
u844646164
p03722
python
s221948996
s116657948
732
465
3,572
3,316
Accepted
Accepted
36.48
def bellman_ford(V, E, s, std): dist = [float('inf') for _ in range(V)] dist[s] = 0 for i in range(V): for s, t, d in std: s -=1 t -= 1 d = -d if dist[t] > dist[s] + d: dist[t] = dist[s] + d if i == V-1 and t+1 == V: return -1 return dist def main(): N, M = list(map(int, input().split())) abc = [list(map(int, input().split())) for _ in range(M)] dist = bellman_ford(N, M, 0, abc) if dist == -1: print('inf') exit() else: print((-dist[N-1])) if __name__ == "__main__": main()
n, m = list(map(int, input().split())) abc = [] for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 c *= -1 abc += [[a,b,c]] def bellman_ford(s): # std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]] # (si, ti, di): si, ti間に重さdiの辺がある dist = [float('inf')]*n dist[s] = 0 for u in range(n): for s, t, d in abc: if dist[t] > dist[s] + d: dist[t] = dist[s] + d if u == n-1 and t == n-1: return -1 return dist dist = bellman_ford(0) if dist == -1: print('inf') else: print((-1*dist[n-1]))
26
29
583
591
def bellman_ford(V, E, s, std): dist = [float("inf") for _ in range(V)] dist[s] = 0 for i in range(V): for s, t, d in std: s -= 1 t -= 1 d = -d if dist[t] > dist[s] + d: dist[t] = dist[s] + d if i == V - 1 and t + 1 == V: return -1 return dist def main(): N, M = list(map(int, input().split())) abc = [list(map(int, input().split())) for _ in range(M)] dist = bellman_ford(N, M, 0, abc) if dist == -1: print("inf") exit() else: print((-dist[N - 1])) if __name__ == "__main__": main()
n, m = list(map(int, input().split())) abc = [] for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 c *= -1 abc += [[a, b, c]] def bellman_ford(s): # std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]] # (si, ti, di): si, ti間に重さdiの辺がある dist = [float("inf")] * n dist[s] = 0 for u in range(n): for s, t, d in abc: if dist[t] > dist[s] + d: dist[t] = dist[s] + d if u == n - 1 and t == n - 1: return -1 return dist dist = bellman_ford(0) if dist == -1: print("inf") else: print((-1 * dist[n - 1]))
false
10.344828
[ "-def bellman_ford(V, E, s, std):", "- dist = [float(\"inf\") for _ in range(V)]", "+n, m = list(map(int, input().split()))", "+abc = []", "+for _ in range(m):", "+ a, b, c = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ c *= -1", "+ abc += [[a, b, c]]", "+", "+", "+def bellman_ford(s):", "+ # std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]]", "+ # (si, ti, di): si, ti間に重さdiの辺がある", "+ dist = [float(\"inf\")] * n", "- for i in range(V):", "- for s, t, d in std:", "- s -= 1", "- t -= 1", "- d = -d", "+ for u in range(n):", "+ for s, t, d in abc:", "- if i == V - 1 and t + 1 == V:", "+ if u == n - 1 and t == n - 1:", "-def main():", "- N, M = list(map(int, input().split()))", "- abc = [list(map(int, input().split())) for _ in range(M)]", "- dist = bellman_ford(N, M, 0, abc)", "- if dist == -1:", "- print(\"inf\")", "- exit()", "- else:", "- print((-dist[N - 1]))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+dist = bellman_ford(0)", "+if dist == -1:", "+ print(\"inf\")", "+else:", "+ print((-1 * dist[n - 1]))" ]
false
0.083653
0.0442
1.892575
[ "s221948996", "s116657948" ]
u477977638
p02901
python
s578361767
s412878079
314
256
45,800
42,604
Accepted
Accepted
18.47
inf=10**8 n,m=list(map(int,input().split())) A=[] C=[] dp=[inf]*(1<<n) dp[0]=0 for _ in range(m): a,_=list(map(int,input().split())) c=list(map(int,input().split())) A.append(a) tmp=0 for i in c: tmp+=1<<(i-1) C.append(tmp) for i in range(1<<n): for index,j in enumerate(C): dp[i|j]=min(dp[i|j],dp[i]+A[index]) ans=dp[-1] if ans==inf:ans=-1 print(ans)
import sys input = sys.stdin.readline inf=10**8 n,m=list(map(int,input().split())) A=[] C=[] dp=[inf]*(1<<n) dp[0]=0 for _ in range(m): a,_=list(map(int,input().split())) c=list(map(int,input().split())) A.append(a) tmp=0 for i in c: tmp+=1<<(i-1) C.append(tmp) for i in range(1<<n): for index,j in enumerate(C): dp[i|j]=min(dp[i|j],dp[i]+A[index]) ans=dp[-1] if ans==inf:ans=-1 print(ans)
24
27
388
430
inf = 10**8 n, m = list(map(int, input().split())) A = [] C = [] dp = [inf] * (1 << n) dp[0] = 0 for _ in range(m): a, _ = list(map(int, input().split())) c = list(map(int, input().split())) A.append(a) tmp = 0 for i in c: tmp += 1 << (i - 1) C.append(tmp) for i in range(1 << n): for index, j in enumerate(C): dp[i | j] = min(dp[i | j], dp[i] + A[index]) ans = dp[-1] if ans == inf: ans = -1 print(ans)
import sys input = sys.stdin.readline inf = 10**8 n, m = list(map(int, input().split())) A = [] C = [] dp = [inf] * (1 << n) dp[0] = 0 for _ in range(m): a, _ = list(map(int, input().split())) c = list(map(int, input().split())) A.append(a) tmp = 0 for i in c: tmp += 1 << (i - 1) C.append(tmp) for i in range(1 << n): for index, j in enumerate(C): dp[i | j] = min(dp[i | j], dp[i] + A[index]) ans = dp[-1] if ans == inf: ans = -1 print(ans)
false
11.111111
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.094809
0.096213
0.985409
[ "s578361767", "s412878079" ]
u677523557
p03132
python
s008843730
s702534253
669
180
37,464
112,888
Accepted
Accepted
73.09
import sys input = sys.stdin.readline import numpy as np N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] p1 = 0 p2 = 0 P1 = [0] P2 = [0] for a in A: if a == 0: p1 -= 2 p2 += 1 elif a % 2 == 0: p2 -= 1 elif a % 2 == 1: p1 -= 1 p2 += 1 p1 += a P1.append(p1) P2.append(p2) dp = [P1[N], P1[N]+P2[N], -P1[N], 0] for i in reversed(list(range(N))): dp[0] = max(dp[0], P1[i]) dp[1] = max(dp[1], P2[i]+dp[0]) dp[2] = min(dp[2], P2[i]-dp[1]) dp[3] = min(dp[3], P1[i]+dp[2]) print((dp[3]+sum(A)))
import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] dp = [[0]*5 for _ in range(N+1)] for i, a in enumerate(A): b = a%2 if a > 0 else 2 dp[i+1][0] = dp[i][0] + a dp[i+1][1] = min(dp[i][1], dp[i][0]) + b dp[i+1][2] = min([dp[i][2], dp[i][1], dp[i][0]]) + (a+1)%2 dp[i+1][3] = min([dp[i][3], dp[i][2], dp[i][1], dp[i][0]]) + b dp[i+1][4] = min(dp[i]) + a ans = min([dp[N][4], dp[N][3], dp[N][2]]) print(ans)
33
18
601
489
import sys input = sys.stdin.readline import numpy as np N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] p1 = 0 p2 = 0 P1 = [0] P2 = [0] for a in A: if a == 0: p1 -= 2 p2 += 1 elif a % 2 == 0: p2 -= 1 elif a % 2 == 1: p1 -= 1 p2 += 1 p1 += a P1.append(p1) P2.append(p2) dp = [P1[N], P1[N] + P2[N], -P1[N], 0] for i in reversed(list(range(N))): dp[0] = max(dp[0], P1[i]) dp[1] = max(dp[1], P2[i] + dp[0]) dp[2] = min(dp[2], P2[i] - dp[1]) dp[3] = min(dp[3], P1[i] + dp[2]) print((dp[3] + sum(A)))
import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] dp = [[0] * 5 for _ in range(N + 1)] for i, a in enumerate(A): b = a % 2 if a > 0 else 2 dp[i + 1][0] = dp[i][0] + a dp[i + 1][1] = min(dp[i][1], dp[i][0]) + b dp[i + 1][2] = min([dp[i][2], dp[i][1], dp[i][0]]) + (a + 1) % 2 dp[i + 1][3] = min([dp[i][3], dp[i][2], dp[i][1], dp[i][0]]) + b dp[i + 1][4] = min(dp[i]) + a ans = min([dp[N][4], dp[N][3], dp[N][2]]) print(ans)
false
45.454545
[ "-import numpy as np", "-", "-p1 = 0", "-p2 = 0", "-P1 = [0]", "-P2 = [0]", "-for a in A:", "- if a == 0:", "- p1 -= 2", "- p2 += 1", "- elif a % 2 == 0:", "- p2 -= 1", "- elif a % 2 == 1:", "- p1 -= 1", "- p2 += 1", "- p1 += a", "- P1.append(p1)", "- P2.append(p2)", "-dp = [P1[N], P1[N] + P2[N], -P1[N], 0]", "-for i in reversed(list(range(N))):", "- dp[0] = max(dp[0], P1[i])", "- dp[1] = max(dp[1], P2[i] + dp[0])", "- dp[2] = min(dp[2], P2[i] - dp[1])", "- dp[3] = min(dp[3], P1[i] + dp[2])", "-print((dp[3] + sum(A)))", "+dp = [[0] * 5 for _ in range(N + 1)]", "+for i, a in enumerate(A):", "+ b = a % 2 if a > 0 else 2", "+ dp[i + 1][0] = dp[i][0] + a", "+ dp[i + 1][1] = min(dp[i][1], dp[i][0]) + b", "+ dp[i + 1][2] = min([dp[i][2], dp[i][1], dp[i][0]]) + (a + 1) % 2", "+ dp[i + 1][3] = min([dp[i][3], dp[i][2], dp[i][1], dp[i][0]]) + b", "+ dp[i + 1][4] = min(dp[i]) + a", "+ans = min([dp[N][4], dp[N][3], dp[N][2]])", "+print(ans)" ]
false
0.104592
0.037553
2.785167
[ "s008843730", "s702534253" ]
u729133443
p03110
python
s982249829
s701269544
163
17
38,384
2,940
Accepted
Accepted
89.57
print((sum(float(s[:-4])*[380000,1][s[-4]>'C']for s in open(0).readlines()[1:])))
print((sum(float(s[:-4])*(s[-4]>'C'or 380000)for s in open(0).readlines()[1:])))
1
1
79
78
print((sum(float(s[:-4]) * [380000, 1][s[-4] > "C"] for s in open(0).readlines()[1:])))
print((sum(float(s[:-4]) * (s[-4] > "C" or 380000) for s in open(0).readlines()[1:])))
false
0
[ "-print((sum(float(s[:-4]) * [380000, 1][s[-4] > \"C\"] for s in open(0).readlines()[1:])))", "+print((sum(float(s[:-4]) * (s[-4] > \"C\" or 380000) for s in open(0).readlines()[1:])))" ]
false
0.042712
0.047104
0.906767
[ "s982249829", "s701269544" ]
u525065967
p02579
python
s700342377
s893889535
1,575
1,406
263,936
264,444
Accepted
Accepted
10.73
dhw = [(1,0),(0,-1),(0,1),(-1,0), ( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2), ( 1,-2),( 1,-1), ( 1, 1),( 1, 2), ( 0,-2), ( 0, 2), (-1,-2),(-1,-1), (-1, 1),(-1, 2), (-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)] H, W = list(map(int, input().split())) sh, sw = [int(x)-1 for x in input().split()] eh, ew = [int(x)-1 for x in input().split()] S = [eval(input()) for _ in range(H)] dst = [[-1]*W for _ in range(H)] from collections import deque dq = deque([(sh, sw, 0)]) while dq: h, w, d = dq.popleft() if 0 <= h < H and 0 <= w < W and dst[h][w] < 0 and S[h][w] != '#': dst[h][w] = d for i in range(4): dq.appendleft((h + dhw[i][0], w + dhw[i][1], d)) for i in range(4, 24): dq.append((h + dhw[i][0], w + dhw[i][1], d+1)) print((dst[eh][ew]))
dhw = [(1,0),(0,-1),(0,1),(-1,0), ( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2), ( 1,-2),( 1,-1), ( 1, 1),( 1, 2), ( 0,-2), ( 0, 2), (-1,-2),(-1,-1), (-1, 1),(-1, 2), (-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)] H, W = list(map(int, input().split())) sh, sw = [int(x)-1 for x in input().split()] eh, ew = [int(x)-1 for x in input().split()] S = [eval(input()) for _ in range(H)] dst = [[-1]*W for _ in range(H)] from collections import deque dq = deque([(sh, sw, 0)]) while dq: h, w, d = dq.popleft() if h == eh and w == ew: dst[h][w] = d break if 0 <= h < H and 0 <= w < W and dst[h][w] < 0 and S[h][w] != '#': dst[h][w] = d for i in range(4): dq.appendleft((h + dhw[i][0], w + dhw[i][1], d)) for i in range(4, 24): dq.append((h + dhw[i][0], w + dhw[i][1], d+1)) print((dst[eh][ew]))
24
27
821
888
dhw = [ (1, 0), (0, -1), (0, 1), (-1, 0), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), (1, -2), (1, -1), (1, 1), (1, 2), (0, -2), (0, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), ] H, W = list(map(int, input().split())) sh, sw = [int(x) - 1 for x in input().split()] eh, ew = [int(x) - 1 for x in input().split()] S = [eval(input()) for _ in range(H)] dst = [[-1] * W for _ in range(H)] from collections import deque dq = deque([(sh, sw, 0)]) while dq: h, w, d = dq.popleft() if 0 <= h < H and 0 <= w < W and dst[h][w] < 0 and S[h][w] != "#": dst[h][w] = d for i in range(4): dq.appendleft((h + dhw[i][0], w + dhw[i][1], d)) for i in range(4, 24): dq.append((h + dhw[i][0], w + dhw[i][1], d + 1)) print((dst[eh][ew]))
dhw = [ (1, 0), (0, -1), (0, 1), (-1, 0), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), (1, -2), (1, -1), (1, 1), (1, 2), (0, -2), (0, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), ] H, W = list(map(int, input().split())) sh, sw = [int(x) - 1 for x in input().split()] eh, ew = [int(x) - 1 for x in input().split()] S = [eval(input()) for _ in range(H)] dst = [[-1] * W for _ in range(H)] from collections import deque dq = deque([(sh, sw, 0)]) while dq: h, w, d = dq.popleft() if h == eh and w == ew: dst[h][w] = d break if 0 <= h < H and 0 <= w < W and dst[h][w] < 0 and S[h][w] != "#": dst[h][w] = d for i in range(4): dq.appendleft((h + dhw[i][0], w + dhw[i][1], d)) for i in range(4, 24): dq.append((h + dhw[i][0], w + dhw[i][1], d + 1)) print((dst[eh][ew]))
false
11.111111
[ "+ if h == eh and w == ew:", "+ dst[h][w] = d", "+ break" ]
false
0.037629
0.034216
1.09973
[ "s700342377", "s893889535" ]
u945839160
p03495
python
s289534047
s421824829
370
330
119,488
109,384
Accepted
Accepted
10.81
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] Unique = list(set(A)) Dic = {x:0 for x in set(A)} if len(set(A)) <= k: print((0)) else: for x in A: Dic[x] += 1 Dicsort = sorted(list(Dic.items()), key=lambda x: x[1]) cnt = 0 for i in range(len(set(A)) - k): cnt += Dicsort[i][1] print(cnt) resolve()
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] Dic = {x:0 for x in set(A)} if len(Dic) <= k: print((0)) else: for i in A: Dic[i] += 1 Dicsort = sorted(list(Dic.items()), key=lambda x: x[1]) cnt = 0 for j in range(len(Dic) - k): cnt += Dicsort[j][1] print(cnt) resolve()
27
26
671
638
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] Unique = list(set(A)) Dic = {x: 0 for x in set(A)} if len(set(A)) <= k: print((0)) else: for x in A: Dic[x] += 1 Dicsort = sorted(list(Dic.items()), key=lambda x: x[1]) cnt = 0 for i in range(len(set(A)) - k): cnt += Dicsort[i][1] print(cnt) resolve()
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] Dic = {x: 0 for x in set(A)} if len(Dic) <= k: print((0)) else: for i in A: Dic[i] += 1 Dicsort = sorted(list(Dic.items()), key=lambda x: x[1]) cnt = 0 for j in range(len(Dic) - k): cnt += Dicsort[j][1] print(cnt) resolve()
false
3.703704
[ "- Unique = list(set(A))", "- if len(set(A)) <= k:", "+ if len(Dic) <= k:", "- for x in A:", "- Dic[x] += 1", "+ for i in A:", "+ Dic[i] += 1", "- for i in range(len(set(A)) - k):", "- cnt += Dicsort[i][1]", "+ for j in range(len(Dic) - k):", "+ cnt += Dicsort[j][1]" ]
false
0.04679
0.048855
0.957724
[ "s289534047", "s421824829" ]
u964299793
p04002
python
s330952465
s043110193
2,749
2,503
166,924
166,896
Accepted
Accepted
8.95
from collections import Counter h,w,n=map(int,input().split()) cc=Counter() for _ in range(n): b,a=map(int,input().split()) for i in range(3): for j in range(3): x=a+i y=b-j #brute forcing valid bottom right corners if x>=1 and x<=w and y>=1 and y<=h: if x-2>=1 and x-2<=w and y+2>=1 and y+2<=h: cc[(x,y)]+=1 # print(x,y,end=' xy\n')#a valid 3*3 grid bottom right ans=[0]*10 for i in cc.keys(): ans[cc[(i)]]+=1 ans[0]=(h-2)*(w-2)-sum(ans) print(*ans,sep='\n')
from collections import Counter import sys input=sys.stdin.buffer.readline h,w,n=map(int,input().split()) cc=Counter() for _ in range(n): b,a=map(int,input().split()) for i in range(3): for j in range(3): x=a+i y=b-j #brute forcing valid bottom right corners if x>=1 and x<=w and y>=1 and y<=h: if x-2>=1 and x-2<=w and y+2>=1 and y+2<=h: cc[(x,y)]+=1 # print(x,y,end=' xy\n')#a valid 3*3 grid bottom right ans=[0]*10 for i in cc.keys(): ans[cc[(i)]]+=1 ans[0]=(h-2)*(w-2)-sum(ans) print(*ans,sep='\n')
19
20
590
633
from collections import Counter h, w, n = map(int, input().split()) cc = Counter() for _ in range(n): b, a = map(int, input().split()) for i in range(3): for j in range(3): x = a + i y = b - j # brute forcing valid bottom right corners if x >= 1 and x <= w and y >= 1 and y <= h: if x - 2 >= 1 and x - 2 <= w and y + 2 >= 1 and y + 2 <= h: cc[(x, y)] += 1 # print(x,y,end=' xy\n')#a valid 3*3 grid bottom right ans = [0] * 10 for i in cc.keys(): ans[cc[(i)]] += 1 ans[0] = (h - 2) * (w - 2) - sum(ans) print(*ans, sep="\n")
from collections import Counter import sys input = sys.stdin.buffer.readline h, w, n = map(int, input().split()) cc = Counter() for _ in range(n): b, a = map(int, input().split()) for i in range(3): for j in range(3): x = a + i y = b - j # brute forcing valid bottom right corners if x >= 1 and x <= w and y >= 1 and y <= h: if x - 2 >= 1 and x - 2 <= w and y + 2 >= 1 and y + 2 <= h: cc[(x, y)] += 1 # print(x,y,end=' xy\n')#a valid 3*3 grid bottom right ans = [0] * 10 for i in cc.keys(): ans[cc[(i)]] += 1 ans[0] = (h - 2) * (w - 2) - sum(ans) print(*ans, sep="\n")
false
5
[ "+import sys", "+input = sys.stdin.buffer.readline" ]
false
0.042418
0.043848
0.967392
[ "s330952465", "s043110193" ]
u620084012
p03721
python
s088236534
s316453100
479
394
28,640
91,152
Accepted
Accepted
17.75
N, K = list(map(int,input().split())) L = sorted([list(map(int,input().split())) for _ in range(N)]) for e in L: K -= e[1] if K <= 0: print((e[0])) exit(0)
N, K = list(map(int,input().split())) L = [] for k in range(N): L.append(list(map(int,input().split()))) L = sorted(L) for e in L: K -= e[1] if K <= 0: print((e[0])) exit(0)
7
10
178
203
N, K = list(map(int, input().split())) L = sorted([list(map(int, input().split())) for _ in range(N)]) for e in L: K -= e[1] if K <= 0: print((e[0])) exit(0)
N, K = list(map(int, input().split())) L = [] for k in range(N): L.append(list(map(int, input().split()))) L = sorted(L) for e in L: K -= e[1] if K <= 0: print((e[0])) exit(0)
false
30
[ "-L = sorted([list(map(int, input().split())) for _ in range(N)])", "+L = []", "+for k in range(N):", "+ L.append(list(map(int, input().split())))", "+L = sorted(L)" ]
false
0.047839
0.04737
1.0099
[ "s088236534", "s316453100" ]
u767664985
p02959
python
s599022520
s774338704
147
135
19,156
18,624
Accepted
Accepted
8.16
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans, surplus = 0, 0 for i in range(N): tmp = min(A[i], surplus) ans += tmp A[i] -= tmp if B[i] > A[i]: ans += A[i] surplus = B[i] - A[i] else: ans += B[i] surplus = 0 tmp = min(A[N], surplus) ans += tmp print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans, mod = 0, 0 for i in range(N): if mod > A[i]: ans += A[i] A[i] = 0 else: ans += mod A[i] -= mod mod = 0 if B[i] > A[i]: ans += A[i] mod = B[i] - A[i] else: ans += B[i] mod = 0 ans += min(mod, A[N]) print(ans)
18
26
373
421
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans, surplus = 0, 0 for i in range(N): tmp = min(A[i], surplus) ans += tmp A[i] -= tmp if B[i] > A[i]: ans += A[i] surplus = B[i] - A[i] else: ans += B[i] surplus = 0 tmp = min(A[N], surplus) ans += tmp print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans, mod = 0, 0 for i in range(N): if mod > A[i]: ans += A[i] A[i] = 0 else: ans += mod A[i] -= mod mod = 0 if B[i] > A[i]: ans += A[i] mod = B[i] - A[i] else: ans += B[i] mod = 0 ans += min(mod, A[N]) print(ans)
false
30.769231
[ "-ans, surplus = 0, 0", "+ans, mod = 0, 0", "- tmp = min(A[i], surplus)", "- ans += tmp", "- A[i] -= tmp", "+ if mod > A[i]:", "+ ans += A[i]", "+ A[i] = 0", "+ else:", "+ ans += mod", "+ A[i] -= mod", "+ mod = 0", "- surplus = B[i] - A[i]", "+ mod = B[i] - A[i]", "- surplus = 0", "-tmp = min(A[N], surplus)", "-ans += tmp", "+ mod = 0", "+ans += min(mod, A[N])" ]
false
0.038867
0.046749
0.831404
[ "s599022520", "s774338704" ]
u997641430
p02996
python
s423299003
s314940244
1,339
845
63,296
31,860
Accepted
Accepted
36.89
N=int(eval(input())) works=[] for i in range(N): [a,b]=[int(_) for _ in input().split()] works.append([b,a]) works.sort() works2=works[:1] for work in works[1:]: if work[0]==works2[-1][0]: works2[-1][1]+=work[1] else: works2.append([work[0],works2[-1][1]]) works2[-1][1]+=work[1] if all([work[0]>=work[1] for work in works2]): print('Yes') else: print('No')
n = int(eval(input())) W = [] for i in range(n): a, b = list(map(int, input().split())) W.append((a, b)) W.sort(key=lambda x: x[1]) x = 0 for i in range(n): a, b = W[i] x += a if x > b: print('No') exit() print('Yes')
18
14
417
255
N = int(eval(input())) works = [] for i in range(N): [a, b] = [int(_) for _ in input().split()] works.append([b, a]) works.sort() works2 = works[:1] for work in works[1:]: if work[0] == works2[-1][0]: works2[-1][1] += work[1] else: works2.append([work[0], works2[-1][1]]) works2[-1][1] += work[1] if all([work[0] >= work[1] for work in works2]): print("Yes") else: print("No")
n = int(eval(input())) W = [] for i in range(n): a, b = list(map(int, input().split())) W.append((a, b)) W.sort(key=lambda x: x[1]) x = 0 for i in range(n): a, b = W[i] x += a if x > b: print("No") exit() print("Yes")
false
22.222222
[ "-N = int(eval(input()))", "-works = []", "-for i in range(N):", "- [a, b] = [int(_) for _ in input().split()]", "- works.append([b, a])", "-works.sort()", "-works2 = works[:1]", "-for work in works[1:]:", "- if work[0] == works2[-1][0]:", "- works2[-1][1] += work[1]", "- else:", "- works2.append([work[0], works2[-1][1]])", "- works2[-1][1] += work[1]", "-if all([work[0] >= work[1] for work in works2]):", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+n = int(eval(input()))", "+W = []", "+for i in range(n):", "+ a, b = list(map(int, input().split()))", "+ W.append((a, b))", "+W.sort(key=lambda x: x[1])", "+x = 0", "+for i in range(n):", "+ a, b = W[i]", "+ x += a", "+ if x > b:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.03519
0.053585
0.656714
[ "s423299003", "s314940244" ]