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
u888092736
p02954
python
s401182608
s129110964
149
104
11,348
19,148
Accepted
Accepted
30.2
def agg(li): LEN = len(li) agged = [0] * 2 if LEN % 2: agged[0] = (LEN + 1) // 2 agged[1] = LEN // 2 else: agged[0] = agged[1] = LEN // 2 for i in range(LEN - 1): if li[i + 1] != li[i]: if i % 2: return [0] * i + agged[::-1] + [0] * (LEN - i - 2) else: return [0] * i + agged + [0] * (LEN - i - 2) return S = eval(input()) N = len(S) ans = [] chunk = [S[0]] for i in range(N - 1): if S[i] == 'L' and S[i + 1] == 'R': ans += agg(chunk) chunk = [S[i + 1]] else: chunk.append(S[i + 1]) ans += agg(chunk) print((' '.join(map(str, ans))))
S = eval(input()) N = len(S) divs = [0] for i in range(N - 1): if S[i] == "L" and S[i + 1] == "R": divs.append(i + 1) divs.append(N) ans = [0] * N for start, end in zip(divs, divs[1:]): sub = S[start:end] M = end - start for j in range(M - 1): if sub[j] == "R" and sub[j + 1] == "L": if j % 2: ans[start + j] = M // 2 else: ans[start + j] = (M + 1) // 2 ans[start + j + 1] = M - ans[start + j] print((" ".join(map(str, ans))))
30
19
702
537
def agg(li): LEN = len(li) agged = [0] * 2 if LEN % 2: agged[0] = (LEN + 1) // 2 agged[1] = LEN // 2 else: agged[0] = agged[1] = LEN // 2 for i in range(LEN - 1): if li[i + 1] != li[i]: if i % 2: return [0] * i + agged[::-1] + [0] * (LEN - i - 2) else: return [0] * i + agged + [0] * (LEN - i - 2) return S = eval(input()) N = len(S) ans = [] chunk = [S[0]] for i in range(N - 1): if S[i] == "L" and S[i + 1] == "R": ans += agg(chunk) chunk = [S[i + 1]] else: chunk.append(S[i + 1]) ans += agg(chunk) print((" ".join(map(str, ans))))
S = eval(input()) N = len(S) divs = [0] for i in range(N - 1): if S[i] == "L" and S[i + 1] == "R": divs.append(i + 1) divs.append(N) ans = [0] * N for start, end in zip(divs, divs[1:]): sub = S[start:end] M = end - start for j in range(M - 1): if sub[j] == "R" and sub[j + 1] == "L": if j % 2: ans[start + j] = M // 2 else: ans[start + j] = (M + 1) // 2 ans[start + j + 1] = M - ans[start + j] print((" ".join(map(str, ans))))
false
36.666667
[ "-def agg(li):", "- LEN = len(li)", "- agged = [0] * 2", "- if LEN % 2:", "- agged[0] = (LEN + 1) // 2", "- agged[1] = LEN // 2", "- else:", "- agged[0] = agged[1] = LEN // 2", "- for i in range(LEN - 1):", "- if li[i + 1] != li[i]:", "- if i % 2:", "- return [0] * i + agged[::-1] + [0] * (LEN - i - 2)", "- else:", "- return [0] * i + agged + [0] * (LEN - i - 2)", "- return", "-", "-", "-ans = []", "-chunk = [S[0]]", "+divs = [0]", "- ans += agg(chunk)", "- chunk = [S[i + 1]]", "- else:", "- chunk.append(S[i + 1])", "-ans += agg(chunk)", "+ divs.append(i + 1)", "+divs.append(N)", "+ans = [0] * N", "+for start, end in zip(divs, divs[1:]):", "+ sub = S[start:end]", "+ M = end - start", "+ for j in range(M - 1):", "+ if sub[j] == \"R\" and sub[j + 1] == \"L\":", "+ if j % 2:", "+ ans[start + j] = M // 2", "+ else:", "+ ans[start + j] = (M + 1) // 2", "+ ans[start + j + 1] = M - ans[start + j]" ]
false
0.036347
0.043503
0.835501
[ "s401182608", "s129110964" ]
u761320129
p03426
python
s468491444
s643520566
556
494
40,812
48,004
Accepted
Accepted
11.15
H,W,D = map(int,input().split()) A = [list(map(int,input().split())) for i in range(H)] Q = int(input()) qs = [tuple(map(int,input().split())) for i in range(Q)] places = [None] * (H*W+1) for i in range(H): for j in range(W): places[A[i][j]] = (j,i) costs = [[] for i in range(D)] for i in range(H*W+1): if i <= D: costs[i%D].append(0) else: x1,y1 = places[i-D] x2,y2 = places[i] c = abs(x1-x2) + abs(y1-y2) costs[i%D].append(costs[i%D][-1] + c) ans = [] for l,r in qs: m = l%D a = costs[m][r//D] - costs[m][l//D] ans.append(a) print(*ans, sep='\n')
import sys input = sys.stdin.readline H,W,D = map(int,input().split()) A = [list(map(int,input().split())) for i in range(H)] Q = int(input()) LR = [tuple(map(int,input().split())) for i in range(Q)] INF = float('inf') h = 0--(H*W+1)//D pos = [[INF]*h for _ in range(D)] for i,row in enumerate(A): for j,a in enumerate(row): d,m = divmod(a,D) pos[m][d] = (i,j) dists = [[0] for _ in range(D)] for i,p in enumerate(pos): for p1,p2 in zip(p,p[1:]): if p1==INF or p2==INF: continue a1,b1 = p1 a2,b2 = p2 dist = abs(a1-a2) + abs(b1-b2) dists[i].append(dists[i][-1] + dist) ans = [] for l,r in LR: a,i = divmod(l,D) b,j = divmod(r,D) if i==0: a-=1; b-=1 ans.append(dists[i][b] - dists[i][a]) print(*ans, sep='\n')
26
33
649
832
H, W, D = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] Q = int(input()) qs = [tuple(map(int, input().split())) for i in range(Q)] places = [None] * (H * W + 1) for i in range(H): for j in range(W): places[A[i][j]] = (j, i) costs = [[] for i in range(D)] for i in range(H * W + 1): if i <= D: costs[i % D].append(0) else: x1, y1 = places[i - D] x2, y2 = places[i] c = abs(x1 - x2) + abs(y1 - y2) costs[i % D].append(costs[i % D][-1] + c) ans = [] for l, r in qs: m = l % D a = costs[m][r // D] - costs[m][l // D] ans.append(a) print(*ans, sep="\n")
import sys input = sys.stdin.readline H, W, D = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] Q = int(input()) LR = [tuple(map(int, input().split())) for i in range(Q)] INF = float("inf") h = 0 - -(H * W + 1) // D pos = [[INF] * h for _ in range(D)] for i, row in enumerate(A): for j, a in enumerate(row): d, m = divmod(a, D) pos[m][d] = (i, j) dists = [[0] for _ in range(D)] for i, p in enumerate(pos): for p1, p2 in zip(p, p[1:]): if p1 == INF or p2 == INF: continue a1, b1 = p1 a2, b2 = p2 dist = abs(a1 - a2) + abs(b1 - b2) dists[i].append(dists[i][-1] + dist) ans = [] for l, r in LR: a, i = divmod(l, D) b, j = divmod(r, D) if i == 0: a -= 1 b -= 1 ans.append(dists[i][b] - dists[i][a]) print(*ans, sep="\n")
false
21.212121
[ "+import sys", "+", "+input = sys.stdin.readline", "-qs = [tuple(map(int, input().split())) for i in range(Q)]", "-places = [None] * (H * W + 1)", "-for i in range(H):", "- for j in range(W):", "- places[A[i][j]] = (j, i)", "-costs = [[] for i in range(D)]", "-for i in range(H * W + 1):", "- if i <= D:", "- costs[i % D].append(0)", "- else:", "- x1, y1 = places[i - D]", "- x2, y2 = places[i]", "- c = abs(x1 - x2) + abs(y1 - y2)", "- costs[i % D].append(costs[i % D][-1] + c)", "+LR = [tuple(map(int, input().split())) for i in range(Q)]", "+INF = float(\"inf\")", "+h = 0 - -(H * W + 1) // D", "+pos = [[INF] * h for _ in range(D)]", "+for i, row in enumerate(A):", "+ for j, a in enumerate(row):", "+ d, m = divmod(a, D)", "+ pos[m][d] = (i, j)", "+dists = [[0] for _ in range(D)]", "+for i, p in enumerate(pos):", "+ for p1, p2 in zip(p, p[1:]):", "+ if p1 == INF or p2 == INF:", "+ continue", "+ a1, b1 = p1", "+ a2, b2 = p2", "+ dist = abs(a1 - a2) + abs(b1 - b2)", "+ dists[i].append(dists[i][-1] + dist)", "-for l, r in qs:", "- m = l % D", "- a = costs[m][r // D] - costs[m][l // D]", "- ans.append(a)", "+for l, r in LR:", "+ a, i = divmod(l, D)", "+ b, j = divmod(r, D)", "+ if i == 0:", "+ a -= 1", "+ b -= 1", "+ ans.append(dists[i][b] - dists[i][a])" ]
false
0.045328
0.073657
0.615393
[ "s468491444", "s643520566" ]
u729133443
p02909
python
s551456646
s080001551
165
17
38,256
2,940
Accepted
Accepted
89.7
l='Rainy CloudySunny ';print((l[l.find(eval(input()))-6:][:6]))
l=' RainyCloudySunny';print((l[l.find(eval(input()))-6:][:6]))
1
1
55
54
l = "Rainy CloudySunny " print((l[l.find(eval(input())) - 6 :][:6]))
l = " RainyCloudySunny" print((l[l.find(eval(input())) - 6 :][:6]))
false
0
[ "-l = \"Rainy CloudySunny \"", "+l = \" RainyCloudySunny\"" ]
false
0.13088
0.04668
2.803805
[ "s551456646", "s080001551" ]
u459233539
p03211
python
s189295024
s788742351
20
17
2,940
2,940
Accepted
Accepted
15
x = 753 s = eval(input()) ans=10**10 for i in range(len(s)-2): if(abs(x-int(s[i:i+3]))<ans): ans=abs(x-int(s[i:i+3])) print(ans)
x = 753 s = eval(input()) ans= 1000 for i in range(len(s)-2): if(abs(x-int(s[i:i+3]))<ans): ans=abs(x-int(s[i:i+3])) print(ans)
7
7
131
130
x = 753 s = eval(input()) ans = 10**10 for i in range(len(s) - 2): if abs(x - int(s[i : i + 3])) < ans: ans = abs(x - int(s[i : i + 3])) print(ans)
x = 753 s = eval(input()) ans = 1000 for i in range(len(s) - 2): if abs(x - int(s[i : i + 3])) < ans: ans = abs(x - int(s[i : i + 3])) print(ans)
false
0
[ "-ans = 10**10", "+ans = 1000" ]
false
0.049359
0.04706
1.048844
[ "s189295024", "s788742351" ]
u789364190
p03781
python
s723038556
s852242924
25
17
2,940
2,940
Accepted
Accepted
32
str = eval(input()) x = int(str) res = 1 s = 0 for i in range(1, 10 ** 5): s = s + i if s >= x: res = i break print(res)
import math str = eval(input()) x = int(str) res = math.ceil((-1 + math.sqrt(1 + 8 * x)) / 2.0) print(res)
13
8
142
111
str = eval(input()) x = int(str) res = 1 s = 0 for i in range(1, 10**5): s = s + i if s >= x: res = i break print(res)
import math str = eval(input()) x = int(str) res = math.ceil((-1 + math.sqrt(1 + 8 * x)) / 2.0) print(res)
false
38.461538
[ "+import math", "+", "-res = 1", "-s = 0", "-for i in range(1, 10**5):", "- s = s + i", "- if s >= x:", "- res = i", "- break", "+res = math.ceil((-1 + math.sqrt(1 + 8 * x)) / 2.0)" ]
false
0.086454
0.037906
2.280764
[ "s723038556", "s852242924" ]
u811733736
p00181
python
s023462450
s630868940
60
40
7,700
7,696
Accepted
Accepted
33.33
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: rem -= books[0] books = books[1:] if len(books) == 0: break rem = mid m -= 1 if m >= 0: return True else: return False def solve(m, n, books): ub = 1500000 lb = 0 min_width = float('inf') for i in range(50): mid = (ub + lb) // 2 if Cond(m, n, mid, books): min_width = min(min_width, mid) ub = mid else: lb = mid return min_width def main(args): while True: m, n = list(map(int, input().split())) if m == 0 and n == 0: break books = [int(eval(input())) for _ in range(n)] result = solve(m, n, books) print(result) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: rem -= books[0] books = books[1:] if len(books) == 0: break rem = mid m -= 1 if m >= 0: return True else: return False def solve(m, n, books): ub = 1500000 lb = min(books) min_width = float('inf') for i in range(30): mid = (ub + lb) // 2 if Cond(m, n, mid, books): min_width = min(min_width, mid) ub = mid else: lb = mid return min_width def main(args): while True: m, n = list(map(int, input().split())) if m == 0 and n == 0: break books = [int(eval(input())) for _ in range(n)] result = solve(m, n, books) print(result) if __name__ == '__main__': main(sys.argv[1:])
59
59
1,136
1,145
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: rem -= books[0] books = books[1:] if len(books) == 0: break rem = mid m -= 1 if m >= 0: return True else: return False def solve(m, n, books): ub = 1500000 lb = 0 min_width = float("inf") for i in range(50): mid = (ub + lb) // 2 if Cond(m, n, mid, books): min_width = min(min_width, mid) ub = mid else: lb = mid return min_width def main(args): while True: m, n = list(map(int, input().split())) if m == 0 and n == 0: break books = [int(eval(input())) for _ in range(n)] result = solve(m, n, books) print(result) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181 """ import sys from sys import stdin input = stdin.readline def Cond(m, n, mid, books): if max(books) > mid: return False rem = mid while books: while rem >= books[0]: rem -= books[0] books = books[1:] if len(books) == 0: break rem = mid m -= 1 if m >= 0: return True else: return False def solve(m, n, books): ub = 1500000 lb = min(books) min_width = float("inf") for i in range(30): mid = (ub + lb) // 2 if Cond(m, n, mid, books): min_width = min(min_width, mid) ub = mid else: lb = mid return min_width def main(args): while True: m, n = list(map(int, input().split())) if m == 0 and n == 0: break books = [int(eval(input())) for _ in range(n)] result = solve(m, n, books) print(result) if __name__ == "__main__": main(sys.argv[1:])
false
0
[ "- lb = 0", "+ lb = min(books)", "- for i in range(50):", "+ for i in range(30):" ]
false
0.043554
0.04455
0.977643
[ "s023462450", "s630868940" ]
u261260430
p02936
python
s849308181
s177644893
1,694
1,526
268,384
268,460
Accepted
Accepted
9.92
N, Q = list(map(int, input().split())) graph = [[] for i in range(200010)] ans = [0 for i in range(200010)] import sys #sys.setrecursionlimit(100000) sys.setrecursionlimit(10**7) # readline = sys.stdin.readline for _ in range(N - 1): #a, b = map(int, input().split()) a, b = list(map(int, readline().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for _ in range(Q): #p, x = map(int, input().split()) p, x = list(map(int, readline().split())) p -= 1 ans[p] += x def dfs(node, frm=-1): for to in graph[node]: if to == frm: continue ans[to] += ans[node] dfs(to, node) dfs(0) print((*ans[:N]))
def main(): N, Q = list(map(int, input().split())) graph = [[] for i in range(200010)] ans = [0 for i in range(200010)] import sys #sys.setrecursionlimit(100000) sys.setrecursionlimit(10**7) # readline = sys.stdin.readline for _ in range(N - 1): #a, b = map(int, input().split()) a, b = list(map(int, readline().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for _ in range(Q): #p, x = map(int, input().split()) p, x = list(map(int, readline().split())) p -= 1 ans[p] += x def dfs(node, frm=-1): for to in graph[node]: if to == frm: continue ans[to] += ans[node] dfs(to, node) dfs(0) print((*ans[:N])) if __name__ == '__main__': main()
35
39
705
814
N, Q = list(map(int, input().split())) graph = [[] for i in range(200010)] ans = [0 for i in range(200010)] import sys # sys.setrecursionlimit(100000) sys.setrecursionlimit(10**7) # readline = sys.stdin.readline for _ in range(N - 1): # a, b = map(int, input().split()) a, b = list(map(int, readline().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for _ in range(Q): # p, x = map(int, input().split()) p, x = list(map(int, readline().split())) p -= 1 ans[p] += x def dfs(node, frm=-1): for to in graph[node]: if to == frm: continue ans[to] += ans[node] dfs(to, node) dfs(0) print((*ans[:N]))
def main(): N, Q = list(map(int, input().split())) graph = [[] for i in range(200010)] ans = [0 for i in range(200010)] import sys # sys.setrecursionlimit(100000) sys.setrecursionlimit(10**7) # readline = sys.stdin.readline for _ in range(N - 1): # a, b = map(int, input().split()) a, b = list(map(int, readline().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for _ in range(Q): # p, x = map(int, input().split()) p, x = list(map(int, readline().split())) p -= 1 ans[p] += x def dfs(node, frm=-1): for to in graph[node]: if to == frm: continue ans[to] += ans[node] dfs(to, node) dfs(0) print((*ans[:N])) if __name__ == "__main__": main()
false
10.25641
[ "-N, Q = list(map(int, input().split()))", "-graph = [[] for i in range(200010)]", "-ans = [0 for i in range(200010)]", "-import sys", "+def main():", "+ N, Q = list(map(int, input().split()))", "+ graph = [[] for i in range(200010)]", "+ ans = [0 for i in range(200010)]", "+ import sys", "-# sys.setrecursionlimit(100000)", "-sys.setrecursionlimit(10**7)", "-#", "-readline = sys.stdin.readline", "-for _ in range(N - 1):", "- # a, b = map(int, input().split())", "- a, b = list(map(int, readline().split()))", "- a -= 1", "- b -= 1", "- graph[a].append(b)", "- graph[b].append(a)", "-for _ in range(Q):", "- # p, x = map(int, input().split())", "- p, x = list(map(int, readline().split()))", "- p -= 1", "- ans[p] += x", "+ # sys.setrecursionlimit(100000)", "+ sys.setrecursionlimit(10**7)", "+ #", "+ readline = sys.stdin.readline", "+ for _ in range(N - 1):", "+ # a, b = map(int, input().split())", "+ a, b = list(map(int, readline().split()))", "+ a -= 1", "+ b -= 1", "+ graph[a].append(b)", "+ graph[b].append(a)", "+ for _ in range(Q):", "+ # p, x = map(int, input().split())", "+ p, x = list(map(int, readline().split()))", "+ p -= 1", "+ ans[p] += x", "+", "+ def dfs(node, frm=-1):", "+ for to in graph[node]:", "+ if to == frm:", "+ continue", "+ ans[to] += ans[node]", "+ dfs(to, node)", "+", "+ dfs(0)", "+ print((*ans[:N]))", "-def dfs(node, frm=-1):", "- for to in graph[node]:", "- if to == frm:", "- continue", "- ans[to] += ans[node]", "- dfs(to, node)", "-", "-", "-dfs(0)", "-print((*ans[:N]))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.207715
0.193712
1.072288
[ "s849308181", "s177644893" ]
u724687935
p02585
python
s735580228
s407981865
1,284
342
144,168
81,096
Accepted
Accepted
73.36
N, K = list(map(int, input().split())) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -float('inf') for i in range(N): done = set() S = [] done.add(i) S.append(C[i]) i = P[i] - 1 while i not in done: done.add(i) S.append(S[-1] + C[i]) i = P[i] - 1 if K <= len(S): score = max(S[:K]) elif S[-1] <= 0: score = max(S) else: score1 = S[-1] * (K // len(S) - 1) score1 += max(S) score2 = S[-1] * (K // len(S)) r = K % len(S) if r != 0: score2 += max(0, max(S[:r])) score = max(score1, score2) ans = max(ans, score) print(ans)
N, K = list(map(int, input().split())) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -float('inf') for s in range(N): S = [] S.append(C[s]) i = P[s] - 1 while i != s: S.append(S[-1] + C[i]) i = P[i] - 1 if K <= len(S): score = max(S[:K]) elif S[-1] <= 0: score = max(S) else: score1 = S[-1] * (K // len(S) - 1) score1 += max(S) score2 = S[-1] * (K // len(S)) r = K % len(S) if r != 0: score2 += max(0, max(S[:r])) score = max(score1, score2) ans = max(ans, score) print(ans)
30
28
716
655
N, K = list(map(int, input().split())) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -float("inf") for i in range(N): done = set() S = [] done.add(i) S.append(C[i]) i = P[i] - 1 while i not in done: done.add(i) S.append(S[-1] + C[i]) i = P[i] - 1 if K <= len(S): score = max(S[:K]) elif S[-1] <= 0: score = max(S) else: score1 = S[-1] * (K // len(S) - 1) score1 += max(S) score2 = S[-1] * (K // len(S)) r = K % len(S) if r != 0: score2 += max(0, max(S[:r])) score = max(score1, score2) ans = max(ans, score) print(ans)
N, K = list(map(int, input().split())) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -float("inf") for s in range(N): S = [] S.append(C[s]) i = P[s] - 1 while i != s: S.append(S[-1] + C[i]) i = P[i] - 1 if K <= len(S): score = max(S[:K]) elif S[-1] <= 0: score = max(S) else: score1 = S[-1] * (K // len(S) - 1) score1 += max(S) score2 = S[-1] * (K // len(S)) r = K % len(S) if r != 0: score2 += max(0, max(S[:r])) score = max(score1, score2) ans = max(ans, score) print(ans)
false
6.666667
[ "-for i in range(N):", "- done = set()", "+for s in range(N):", "- done.add(i)", "- S.append(C[i])", "- i = P[i] - 1", "- while i not in done:", "- done.add(i)", "+ S.append(C[s])", "+ i = P[s] - 1", "+ while i != s:" ]
false
0.035104
0.123405
0.284464
[ "s735580228", "s407981865" ]
u879870653
p03018
python
s267240622
s676890976
102
47
3,500
3,500
Accepted
Accepted
53.92
S = eval(input()) ans = 0 cnt = 0 flg = 0 for i in range(len(S)-1) : if S[i] == "A" : cnt += 1 elif S[i]+S[i+1] == "BC" : ans += cnt flg = 1 elif flg : flg = 0 else : cnt = 0 print(ans)
S = input().replace("BC","D") ans = 0 cnt = 0 for s in S : if s == "A" : cnt += 1 elif s == "D" : ans += cnt else : cnt = 0 print(ans)
18
14
256
187
S = eval(input()) ans = 0 cnt = 0 flg = 0 for i in range(len(S) - 1): if S[i] == "A": cnt += 1 elif S[i] + S[i + 1] == "BC": ans += cnt flg = 1 elif flg: flg = 0 else: cnt = 0 print(ans)
S = input().replace("BC", "D") ans = 0 cnt = 0 for s in S: if s == "A": cnt += 1 elif s == "D": ans += cnt else: cnt = 0 print(ans)
false
22.222222
[ "-S = eval(input())", "+S = input().replace(\"BC\", \"D\")", "-flg = 0", "-for i in range(len(S) - 1):", "- if S[i] == \"A\":", "+for s in S:", "+ if s == \"A\":", "- elif S[i] + S[i + 1] == \"BC\":", "+ elif s == \"D\":", "- flg = 1", "- elif flg:", "- flg = 0" ]
false
0.036759
0.036922
0.995583
[ "s267240622", "s676890976" ]
u285681431
p02599
python
s585728232
s260069866
1,980
1,614
239,116
226,684
Accepted
Accepted
18.48
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, Q = list(map(int, input().split())) c = list(map(int, input().split())) lr = [] for i in range(Q): l, r = list(map(int, input().split())) lr.append([l, r, i]) lr.sort(key=lambda x: x[1]) # print("lr", lr) rightest = [-1] * (N + 1) current_q = 0 bit = Bit(N) ans = [0] * Q for i in range(N): if rightest[c[i]] != -1: bit.add(rightest[c[i]] + 1, -1) rightest[c[i]] = i bit.add(i + 1, 1) # print(bit.tree) while current_q < Q and lr[current_q][1] == i + 1: ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1) current_q += 1 for i in range(Q): print((ans[i]))
from sys import stdin input = stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, Q = list(map(int, input().split())) c = list(map(int, input().split())) lr = [] for i in range(Q): l, r = list(map(int, input().split())) lr.append([l, r, i]) lr.sort(key=lambda x: x[1]) # print("lr", lr) rightest = [-1] * (N + 1) current_q = 0 bit = Bit(N) ans = [0] * Q for i in range(N): if rightest[c[i]] != -1: bit.add(rightest[c[i]] + 1, -1) rightest[c[i]] = i bit.add(i + 1, 1) # print(bit.tree) while current_q < Q and lr[current_q][1] == i + 1: ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1) current_q += 1 for i in range(Q): print((ans[i]))
46
50
1,016
1,067
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, Q = list(map(int, input().split())) c = list(map(int, input().split())) lr = [] for i in range(Q): l, r = list(map(int, input().split())) lr.append([l, r, i]) lr.sort(key=lambda x: x[1]) # print("lr", lr) rightest = [-1] * (N + 1) current_q = 0 bit = Bit(N) ans = [0] * Q for i in range(N): if rightest[c[i]] != -1: bit.add(rightest[c[i]] + 1, -1) rightest[c[i]] = i bit.add(i + 1, 1) # print(bit.tree) while current_q < Q and lr[current_q][1] == i + 1: ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum( lr[current_q][0] - 1 ) current_q += 1 for i in range(Q): print((ans[i]))
from sys import stdin input = stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, Q = list(map(int, input().split())) c = list(map(int, input().split())) lr = [] for i in range(Q): l, r = list(map(int, input().split())) lr.append([l, r, i]) lr.sort(key=lambda x: x[1]) # print("lr", lr) rightest = [-1] * (N + 1) current_q = 0 bit = Bit(N) ans = [0] * Q for i in range(N): if rightest[c[i]] != -1: bit.add(rightest[c[i]] + 1, -1) rightest[c[i]] = i bit.add(i + 1, 1) # print(bit.tree) while current_q < Q and lr[current_q][1] == i + 1: ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum( lr[current_q][0] - 1 ) current_q += 1 for i in range(Q): print((ans[i]))
false
8
[ "+from sys import stdin", "+", "+input = stdin.readline", "+", "+" ]
false
0.037723
0.037172
1.014821
[ "s585728232", "s260069866" ]
u353919145
p03631
python
s202136870
s377239719
20
17
3,064
3,060
Accepted
Accepted
15
import sys pagos=0 lines = sys.stdin.readlines() for linea in lines: c = linea.split() c = list(map(str,c)) list(c) p = c[0] texto = p rever = texto[::-1] if texto == rever: print("Yes") else: print("No")
"""MILOY""" x=eval(input()) p=len(x) n=int(x) s=0 c=int(x) for i in range(p): rem=n%10 n=n/10 s=(s*10)+int(rem) n=int(n) if (c==s): print('Yes') else: print('No')
14
21
233
228
import sys pagos = 0 lines = sys.stdin.readlines() for linea in lines: c = linea.split() c = list(map(str, c)) list(c) p = c[0] texto = p rever = texto[::-1] if texto == rever: print("Yes") else: print("No")
"""MILOY""" x = eval(input()) p = len(x) n = int(x) s = 0 c = int(x) for i in range(p): rem = n % 10 n = n / 10 s = (s * 10) + int(rem) n = int(n) if c == s: print("Yes") else: print("No")
false
33.333333
[ "-import sys", "-", "-pagos = 0", "-lines = sys.stdin.readlines()", "-for linea in lines:", "- c = linea.split()", "- c = list(map(str, c))", "-list(c)", "-p = c[0]", "-texto = p", "-rever = texto[::-1]", "-if texto == rever:", "+\"\"\"MILOY\"\"\"", "+x = eval(input())", "+p = len(x)", "+n = int(x)", "+s = 0", "+c = int(x)", "+for i in range(p):", "+ rem = n % 10", "+ n = n / 10", "+ s = (s * 10) + int(rem)", "+ n = int(n)", "+if c == s:" ]
false
0.043299
0.043711
0.990571
[ "s202136870", "s377239719" ]
u788137651
p03307
python
s867034172
s549858686
39
17
5,304
2,940
Accepted
Accepted
56.41
from fractions import gcd N = int(eval(input())) print((2*N//gcd(N, 2)))
N = int(eval(input())) if N % 2 == 0: print(N) else: print((N*2))
3
5
67
70
from fractions import gcd N = int(eval(input())) print((2 * N // gcd(N, 2)))
N = int(eval(input())) if N % 2 == 0: print(N) else: print((N * 2))
false
40
[ "-from fractions import gcd", "-", "-print((2 * N // gcd(N, 2)))", "+if N % 2 == 0:", "+ print(N)", "+else:", "+ print((N * 2))" ]
false
0.048324
0.037792
1.278678
[ "s867034172", "s549858686" ]
u005677960
p02911
python
s429246858
s408187350
849
750
14,428
15,052
Accepted
Accepted
11.66
import numpy as np N,K,Q=list(map(int,input().split())) score=np.full(N,K) for i in range(Q): a=int(eval(input())) score[a-1]+=1 for j in score: if j-Q>0: print("Yes") else: print("No")
import numpy as np N,K,Q=list(map(int,input().split())) score=np.full(N,K-Q) for i in range(Q): a=int(eval(input())) score[a-1]+=1 for j in score: if j>0: print("Yes") else: print("No")
11
11
199
199
import numpy as np N, K, Q = list(map(int, input().split())) score = np.full(N, K) for i in range(Q): a = int(eval(input())) score[a - 1] += 1 for j in score: if j - Q > 0: print("Yes") else: print("No")
import numpy as np N, K, Q = list(map(int, input().split())) score = np.full(N, K - Q) for i in range(Q): a = int(eval(input())) score[a - 1] += 1 for j in score: if j > 0: print("Yes") else: print("No")
false
0
[ "-score = np.full(N, K)", "+score = np.full(N, K - Q)", "- if j - Q > 0:", "+ if j > 0:" ]
false
0.50478
0.852811
0.591902
[ "s429246858", "s408187350" ]
u256464928
p03109
python
s963831247
s680061491
19
17
2,940
2,940
Accepted
Accepted
10.53
y,m,d = list(map(int,input().split("/"))) print(("Heisei" if y < 2019 else "Heisei" if y == 2019 and m < 4 else "Heisei" if y == 2019 and m == 4 and d <= 30 else "TBD"))
s = eval(input()) print(("Heisei" if s <= "2019/04/30" else "TBD"))
2
2
163
61
y, m, d = list(map(int, input().split("/"))) print( ( "Heisei" if y < 2019 else "Heisei" if y == 2019 and m < 4 else "Heisei" if y == 2019 and m == 4 and d <= 30 else "TBD" ) )
s = eval(input()) print(("Heisei" if s <= "2019/04/30" else "TBD"))
false
0
[ "-y, m, d = list(map(int, input().split(\"/\")))", "-print(", "- (", "- \"Heisei\"", "- if y < 2019", "- else \"Heisei\"", "- if y == 2019 and m < 4", "- else \"Heisei\"", "- if y == 2019 and m == 4 and d <= 30", "- else \"TBD\"", "- )", "-)", "+s = eval(input())", "+print((\"Heisei\" if s <= \"2019/04/30\" else \"TBD\"))" ]
false
0.055371
0.043384
1.276293
[ "s963831247", "s680061491" ]
u630511239
p03137
python
s656442476
s764998439
113
95
13,968
20,472
Accepted
Accepted
15.93
N, M = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 if M>N: X.sort() D = [] for i in range(M-1): d = X[i+1]-X[i] D.append(d) D.sort() D = D[:(M-N)] ans = sum(D) print(ans)
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() A = [] for i in range(1, M): L = X[i] - X[i - 1] A.append(L) A.sort() A = A[M - N:] ans = X[-1] - X[0] - sum(A) if N >= M: ans = 0 print(ans)
16
14
241
248
N, M = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 if M > N: X.sort() D = [] for i in range(M - 1): d = X[i + 1] - X[i] D.append(d) D.sort() D = D[: (M - N)] ans = sum(D) print(ans)
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() A = [] for i in range(1, M): L = X[i] - X[i - 1] A.append(L) A.sort() A = A[M - N :] ans = X[-1] - X[0] - sum(A) if N >= M: ans = 0 print(ans)
false
12.5
[ "-ans = 0", "-if M > N:", "- X.sort()", "- D = []", "- for i in range(M - 1):", "- d = X[i + 1] - X[i]", "- D.append(d)", "- D.sort()", "- D = D[: (M - N)]", "- ans = sum(D)", "+X.sort()", "+A = []", "+for i in range(1, M):", "+ L = X[i] - X[i - 1]", "+ A.append(L)", "+A.sort()", "+A = A[M - N :]", "+ans = X[-1] - X[0] - sum(A)", "+if N >= M:", "+ ans = 0" ]
false
0.035601
0.036919
0.964289
[ "s656442476", "s764998439" ]
u353797797
p03392
python
s830215489
s655846070
1,441
52
216,612
3,628
Accepted
Accepted
96.39
def main(): md = 998244353 s = eval(input()) n = len(s) if s.count(s[0]) == n: print((1)) exit() if n == 2: print((2)) exit() if n == 3: if s[0] == s[-1]: print((7)) elif s[0] == s[1] or s[1] == s[2]: print((6)) else: print((3)) exit() ord0 = ord("a") a = [ord(c) - ord0 for c in s] r = sum(a) % 3 dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)] for m in range(3): dp[0][m][0][m] = 1 # print(a) # print(dp) for i in range(n - 1): for j in range(3): for k in range(2): for m in range(3): pre = dp[i][j][k][m] # iけた j余り k連続有無 m前の位 for nm in range(3): nj = (j + nm) % 3 if nm == m: dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md else: dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md d = 1 for c0, c1 in zip(s, s[1:]): if c0 == c1: d = 0 break print(((sum(dp[n - 1][r][1]) + d) % md)) main()
def main(): md = 998244353 s = eval(input()) n = len(s) al = True # allすべて同じ文字 an = 1 # any連続が存在すると0 for c0, c1 in zip(s, s[1:]): if c0 == c1: an = 0 else: al = False if an == 0 and not al: break if al: print((1)) exit() if n == 2: print((2)) exit() if n == 3: if s[0] == s[-1]: print((7)) elif s[0] == s[1] or s[1] == s[2]: print((6)) else: print((3)) exit() #print(n) #print(an) ord0=ord("a") r = sum(ord(c) - ord0 for c in s) % 3 if n%3==0: d=pow(2,n//3-1,md) if r==0: an-=d*2 else: an+=d print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md)) main()
45
39
1,272
837
def main(): md = 998244353 s = eval(input()) n = len(s) if s.count(s[0]) == n: print((1)) exit() if n == 2: print((2)) exit() if n == 3: if s[0] == s[-1]: print((7)) elif s[0] == s[1] or s[1] == s[2]: print((6)) else: print((3)) exit() ord0 = ord("a") a = [ord(c) - ord0 for c in s] r = sum(a) % 3 dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)] for m in range(3): dp[0][m][0][m] = 1 # print(a) # print(dp) for i in range(n - 1): for j in range(3): for k in range(2): for m in range(3): pre = dp[i][j][k][m] # iけた j余り k連続有無 m前の位 for nm in range(3): nj = (j + nm) % 3 if nm == m: dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md else: dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md d = 1 for c0, c1 in zip(s, s[1:]): if c0 == c1: d = 0 break print(((sum(dp[n - 1][r][1]) + d) % md)) main()
def main(): md = 998244353 s = eval(input()) n = len(s) al = True # allすべて同じ文字 an = 1 # any連続が存在すると0 for c0, c1 in zip(s, s[1:]): if c0 == c1: an = 0 else: al = False if an == 0 and not al: break if al: print((1)) exit() if n == 2: print((2)) exit() if n == 3: if s[0] == s[-1]: print((7)) elif s[0] == s[1] or s[1] == s[2]: print((6)) else: print((3)) exit() # print(n) # print(an) ord0 = ord("a") r = sum(ord(c) - ord0 for c in s) % 3 if n % 3 == 0: d = pow(2, n // 3 - 1, md) if r == 0: an -= d * 2 else: an += d print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md)) main()
false
13.333333
[ "- if s.count(s[0]) == n:", "+ al = True # allすべて同じ文字", "+ an = 1 # any連続が存在すると0", "+ for c0, c1 in zip(s, s[1:]):", "+ if c0 == c1:", "+ an = 0", "+ else:", "+ al = False", "+ if an == 0 and not al:", "+ break", "+ if al:", "+ # print(n)", "+ # print(an)", "- a = [ord(c) - ord0 for c in s]", "- r = sum(a) % 3", "- dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)]", "- for m in range(3):", "- dp[0][m][0][m] = 1", "- # print(a)", "- # print(dp)", "- for i in range(n - 1):", "- for j in range(3):", "- for k in range(2):", "- for m in range(3):", "- pre = dp[i][j][k][m] # iけた j余り k連続有無 m前の位", "- for nm in range(3):", "- nj = (j + nm) % 3", "- if nm == m:", "- dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md", "- else:", "- dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md", "- d = 1", "- for c0, c1 in zip(s, s[1:]):", "- if c0 == c1:", "- d = 0", "- break", "- print(((sum(dp[n - 1][r][1]) + d) % md))", "+ r = sum(ord(c) - ord0 for c in s) % 3", "+ if n % 3 == 0:", "+ d = pow(2, n // 3 - 1, md)", "+ if r == 0:", "+ an -= d * 2", "+ else:", "+ an += d", "+ print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md))" ]
false
0.060264
0.037584
1.603445
[ "s830215489", "s655846070" ]
u873190923
p03151
python
s377296079
s290499083
402
165
115,304
102,604
Accepted
Accepted
58.96
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) # list(map(int, list(input()))) # スペースがない数字リストを読み込み import math import fractions import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) import collections from collections import Counter from collections import deque import pprint sr = lambda: eval(input()) ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): arr = [] temp = n if n == 1: return arr for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr # a^n def power(a,n,mod): x = 1 while n: if n & 1: x *= a % mod n >>= 1 a *= a % mod return x % mod # n*(n-1)*...*(l+1)*l def kaijo(n, l, mod): if n == 0: return 1 a = n tmp = n-1 while(tmp >= l): a = a*tmp%mod tmp -= 1 return a inf = 10**18 mod = 10**9+7 n = ir() a = lr() b = lr() yoyu = [] muri = [] for i in range(n): if a[i] > b[i]: yoyu.append(a[i]-b[i]) if a[i] < b[i]: muri.append(b[i]-a[i]) if sum(yoyu) < sum(muri): print((-1)) else: if muri: yoyu.sort(reverse=True) muri.sort() yoyu_ind = 0 muri_ind = 0 flag = False while muri_ind < len(muri): ret = muri[muri_ind] while ret > 0: if yoyu[yoyu_ind] > ret: yoyu[yoyu_ind] -= ret ret = 0 flag = False elif yoyu[yoyu_ind] == ret: yoyu[yoyu_ind] -= ret ret = 0 yoyu_ind+=1 flag = True else: ret -= yoyu[yoyu_ind] yoyu[yoyu_ind] = 0 yoyu_ind+=1 muri_ind+=1 if flag: print((muri_ind + yoyu_ind)) else: print((muri_ind + yoyu_ind+1)) else: print((0))
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) # list(map(int, list(input()))) # スペースがない数字リストを読み込み import math import fractions import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) import collections from collections import Counter from collections import deque import pprint import itertools sr = lambda: eval(input()) ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): arr = [] temp = n if n == 1: return arr for i in range(2, int(-(-n ** 0.5 // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # a^n def power(a, n, mod): x = 1 while n: if n & 1: x *= a % mod n >>= 1 a *= a % mod return x % mod # n*(n-1)*...*(l+1)*l def kaijo(n, l, mod): if n == 0: return 1 a = n tmp = n - 1 while (tmp >= l): a = a * tmp % mod tmp -= 1 return a # Union Find class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) # 約数生成 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors inf = 10 ** 18 mod = 10 ** 9 + 7 n = ir() a = lr() b = lr() if sum(b) > sum(a): print((-1)) else: p = [] m = [] for i in range(n): if a[i] > b[i]: p.append(a[i]-b[i]) elif a[i] < b[i]: m.append(b[i]-a[i]) p.sort(reverse=True) t = sum(m) ans = 0 total = 0 for num in p: if total < t: total+=num ans+=1 else: break print((ans+len(m)))
112
157
2,374
3,253
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) # list(map(int, list(input()))) # スペースがない数字リストを読み込み import math import fractions import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) import collections from collections import Counter from collections import deque import pprint sr = lambda: eval(input()) ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): arr = [] temp = n if n == 1: return arr for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # a^n def power(a, n, mod): x = 1 while n: if n & 1: x *= a % mod n >>= 1 a *= a % mod return x % mod # n*(n-1)*...*(l+1)*l def kaijo(n, l, mod): if n == 0: return 1 a = n tmp = n - 1 while tmp >= l: a = a * tmp % mod tmp -= 1 return a inf = 10**18 mod = 10**9 + 7 n = ir() a = lr() b = lr() yoyu = [] muri = [] for i in range(n): if a[i] > b[i]: yoyu.append(a[i] - b[i]) if a[i] < b[i]: muri.append(b[i] - a[i]) if sum(yoyu) < sum(muri): print((-1)) else: if muri: yoyu.sort(reverse=True) muri.sort() yoyu_ind = 0 muri_ind = 0 flag = False while muri_ind < len(muri): ret = muri[muri_ind] while ret > 0: if yoyu[yoyu_ind] > ret: yoyu[yoyu_ind] -= ret ret = 0 flag = False elif yoyu[yoyu_ind] == ret: yoyu[yoyu_ind] -= ret ret = 0 yoyu_ind += 1 flag = True else: ret -= yoyu[yoyu_ind] yoyu[yoyu_ind] = 0 yoyu_ind += 1 muri_ind += 1 if flag: print((muri_ind + yoyu_ind)) else: print((muri_ind + yoyu_ind + 1)) else: print((0))
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) # list(map(int, list(input()))) # スペースがない数字リストを読み込み import math import fractions import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) import collections from collections import Counter from collections import deque import pprint import itertools sr = lambda: eval(input()) ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): arr = [] temp = n if n == 1: return arr for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # a^n def power(a, n, mod): x = 1 while n: if n & 1: x *= a % mod n >>= 1 a *= a % mod return x % mod # n*(n-1)*...*(l+1)*l def kaijo(n, l, mod): if n == 0: return 1 a = n tmp = n - 1 while tmp >= l: a = a * tmp % mod tmp -= 1 return a # Union Find class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # 約数生成 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors inf = 10**18 mod = 10**9 + 7 n = ir() a = lr() b = lr() if sum(b) > sum(a): print((-1)) else: p = [] m = [] for i in range(n): if a[i] > b[i]: p.append(a[i] - b[i]) elif a[i] < b[i]: m.append(b[i] - a[i]) p.sort(reverse=True) t = sum(m) ans = 0 total = 0 for num in p: if total < t: total += num ans += 1 else: break print((ans + len(m)))
false
28.66242
[ "+import itertools", "+# Union Find", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.parents = [-1] * n", "+", "+ def find(self, x):", "+ if self.parents[x] < 0:", "+ return x", "+ else:", "+ self.parents[x] = self.find(self.parents[x])", "+ return self.parents[x]", "+", "+ def union(self, x, y):", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ if self.parents[x] > self.parents[y]:", "+ x, y = y, x", "+ self.parents[x] += self.parents[y]", "+ self.parents[y] = x", "+", "+ def size(self, x):", "+ return -self.parents[self.find(x)]", "+", "+ def same(self, x, y):", "+ return self.find(x) == self.find(y)", "+", "+ def members(self, x):", "+ root = self.find(x)", "+ return [i for i in range(self.n) if self.find(i) == root]", "+", "+ def roots(self):", "+ return [i for i, x in enumerate(self.parents) if x < 0]", "+", "+ def group_count(self):", "+ return len(self.roots())", "+", "+ def all_group_members(self):", "+ return {r: self.members(r) for r in self.roots()}", "+", "+ def __str__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "+", "+", "+# 約数生成", "+def make_divisors(n):", "+ divisors = []", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ divisors.append(i)", "+ if i != n // i:", "+ divisors.append(n // i)", "+ divisors.sort()", "+ return divisors", "+", "+", "-yoyu = []", "-muri = []", "-for i in range(n):", "- if a[i] > b[i]:", "- yoyu.append(a[i] - b[i])", "- if a[i] < b[i]:", "- muri.append(b[i] - a[i])", "-if sum(yoyu) < sum(muri):", "+if sum(b) > sum(a):", "- if muri:", "- yoyu.sort(reverse=True)", "- muri.sort()", "- yoyu_ind = 0", "- muri_ind = 0", "- flag = False", "- while muri_ind < len(muri):", "- ret = muri[muri_ind]", "- while ret > 0:", "- if yoyu[yoyu_ind] > ret:", "- yoyu[yoyu_ind] -= ret", "- ret = 0", "- flag = False", "- elif yoyu[yoyu_ind] == ret:", "- yoyu[yoyu_ind] -= ret", "- ret = 0", "- yoyu_ind += 1", "- flag = True", "- else:", "- ret -= yoyu[yoyu_ind]", "- yoyu[yoyu_ind] = 0", "- yoyu_ind += 1", "- muri_ind += 1", "- if flag:", "- print((muri_ind + yoyu_ind))", "+ p = []", "+ m = []", "+ for i in range(n):", "+ if a[i] > b[i]:", "+ p.append(a[i] - b[i])", "+ elif a[i] < b[i]:", "+ m.append(b[i] - a[i])", "+ p.sort(reverse=True)", "+ t = sum(m)", "+ ans = 0", "+ total = 0", "+ for num in p:", "+ if total < t:", "+ total += num", "+ ans += 1", "- print((muri_ind + yoyu_ind + 1))", "- else:", "- print((0))", "+ break", "+ print((ans + len(m)))" ]
false
0.06915
0.101463
0.681533
[ "s377296079", "s290499083" ]
u519939795
p02923
python
s166884509
s505683360
107
69
14,252
15,020
Accepted
Accepted
35.51
n=int(eval(input())) h=list(map(int,input().split())) l=[] for i in range(n-1): if h[i+1]-h[i]<=0: l.append(1) else: l.append(0) ans=0 mn=0 for j in range(len(l)): if l[j]==0: ans=0 else: ans+=1 mn=max(ans,mn) print(mn)
n = int(eval(input())) h = list(map(int,input().split())) c_list = [] count = 0 for i in range(n-1): if h[i] >= h[i+1]: count += 1 else: c_list.append(count) count = 0 c_list.append(count) print((max(c_list)))
17
12
285
245
n = int(eval(input())) h = list(map(int, input().split())) l = [] for i in range(n - 1): if h[i + 1] - h[i] <= 0: l.append(1) else: l.append(0) ans = 0 mn = 0 for j in range(len(l)): if l[j] == 0: ans = 0 else: ans += 1 mn = max(ans, mn) print(mn)
n = int(eval(input())) h = list(map(int, input().split())) c_list = [] count = 0 for i in range(n - 1): if h[i] >= h[i + 1]: count += 1 else: c_list.append(count) count = 0 c_list.append(count) print((max(c_list)))
false
29.411765
[ "-l = []", "+c_list = []", "+count = 0", "- if h[i + 1] - h[i] <= 0:", "- l.append(1)", "+ if h[i] >= h[i + 1]:", "+ count += 1", "- l.append(0)", "-ans = 0", "-mn = 0", "-for j in range(len(l)):", "- if l[j] == 0:", "- ans = 0", "- else:", "- ans += 1", "- mn = max(ans, mn)", "-print(mn)", "+ c_list.append(count)", "+ count = 0", "+c_list.append(count)", "+print((max(c_list)))" ]
false
0.037035
0.0434
0.853336
[ "s166884509", "s505683360" ]
u909514237
p02596
python
s415961234
s896136124
1,458
192
8,944
63,200
Accepted
Accepted
86.83
K = int(eval(input())) L = 0 if K % 7 == 0: L = 9*K//7 else: L = 9*K ans = -1 a = 10 for i in range(1,L+1,1): if a % L == 1: ans = i break a = (a % L) * 10 print(ans)
K = int(eval(input())) L = 0 if K % 7 == 0: L = 9*K//7 else: L = 9*K ans = -1 s = 10 for i in range(1,L,1): if s % L == 1: ans = i break s = s % L * 10 print(ans)
15
15
192
189
K = int(eval(input())) L = 0 if K % 7 == 0: L = 9 * K // 7 else: L = 9 * K ans = -1 a = 10 for i in range(1, L + 1, 1): if a % L == 1: ans = i break a = (a % L) * 10 print(ans)
K = int(eval(input())) L = 0 if K % 7 == 0: L = 9 * K // 7 else: L = 9 * K ans = -1 s = 10 for i in range(1, L, 1): if s % L == 1: ans = i break s = s % L * 10 print(ans)
false
0
[ "-a = 10", "-for i in range(1, L + 1, 1):", "- if a % L == 1:", "+s = 10", "+for i in range(1, L, 1):", "+ if s % L == 1:", "- a = (a % L) * 10", "+ s = s % L * 10" ]
false
0.331974
0.007249
45.798854
[ "s415961234", "s896136124" ]
u747602774
p03317
python
s951319280
s544593194
41
18
14,008
2,940
Accepted
Accepted
56.1
N,K = list(map(int,input().split())) A = list(map(int,input().split())) ind = A.index(1) if (N-1)%(K-1) == 0: print(((N-1)//(K-1))) else: print(((N-1)//(K-1)+1))
N,K = list(map(int,input().split())) print(((N+K-3)//(K-1)))
7
2
166
54
N, K = list(map(int, input().split())) A = list(map(int, input().split())) ind = A.index(1) if (N - 1) % (K - 1) == 0: print(((N - 1) // (K - 1))) else: print(((N - 1) // (K - 1) + 1))
N, K = list(map(int, input().split())) print(((N + K - 3) // (K - 1)))
false
71.428571
[ "-A = list(map(int, input().split()))", "-ind = A.index(1)", "-if (N - 1) % (K - 1) == 0:", "- print(((N - 1) // (K - 1)))", "-else:", "- print(((N - 1) // (K - 1) + 1))", "+print(((N + K - 3) // (K - 1)))" ]
false
0.038112
0.046812
0.814151
[ "s951319280", "s544593194" ]
u671060652
p03239
python
s274422205
s187876381
285
70
63,980
62,592
Accepted
Accepted
75.44
import itertools import math import fractions import functools import copy N, T = list(map(int, input().split())) c= [] t = [] for i in range(N): ci, ti = list(map(int, input().split())) c.append(ci) t.append(ti) cost = 10**10 for i in range(N): if t[i] <= T: cost = min(cost,c[i]) if cost == 10**10: print("TLE") else:print(cost)
def main(): # n = int(input()) n, t = list(map(int, input().split())) # a = list(map(int, input().split())) # s = input() ct = [] for _ in range(n): ct.append(list(map(int, input().split()))) mini = 10**10 for i in range(n): if ct[i][1] <= t and ct[i][0] < mini: mini = ct[i][0] if mini == 10**10: print("TLE") else: print(mini) if __name__ == '__main__': main()
21
22
371
470
import itertools import math import fractions import functools import copy N, T = list(map(int, input().split())) c = [] t = [] for i in range(N): ci, ti = list(map(int, input().split())) c.append(ci) t.append(ti) cost = 10**10 for i in range(N): if t[i] <= T: cost = min(cost, c[i]) if cost == 10**10: print("TLE") else: print(cost)
def main(): # n = int(input()) n, t = list(map(int, input().split())) # a = list(map(int, input().split())) # s = input() ct = [] for _ in range(n): ct.append(list(map(int, input().split()))) mini = 10**10 for i in range(n): if ct[i][1] <= t and ct[i][0] < mini: mini = ct[i][0] if mini == 10**10: print("TLE") else: print(mini) if __name__ == "__main__": main()
false
4.545455
[ "-import itertools", "-import math", "-import fractions", "-import functools", "-import copy", "+def main():", "+ # n = int(input())", "+ n, t = list(map(int, input().split()))", "+ # a = list(map(int, input().split()))", "+ # s = input()", "+ ct = []", "+ for _ in range(n):", "+ ct.append(list(map(int, input().split())))", "+ mini = 10**10", "+ for i in range(n):", "+ if ct[i][1] <= t and ct[i][0] < mini:", "+ mini = ct[i][0]", "+ if mini == 10**10:", "+ print(\"TLE\")", "+ else:", "+ print(mini)", "-N, T = list(map(int, input().split()))", "-c = []", "-t = []", "-for i in range(N):", "- ci, ti = list(map(int, input().split()))", "- c.append(ci)", "- t.append(ti)", "-cost = 10**10", "-for i in range(N):", "- if t[i] <= T:", "- cost = min(cost, c[i])", "-if cost == 10**10:", "- print(\"TLE\")", "-else:", "- print(cost)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045807
0.007491
6.114663
[ "s274422205", "s187876381" ]
u796942881
p03495
python
s141770206
s685350583
180
103
39,272
35,980
Accepted
Accepted
42.78
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter([int(i) for i in input().split()]) def main(): # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ # 先頭 K + 1 個目から 末尾 まで # 要素数(v) 合計 print((sum([v for k, v in An.most_common()[K:]]))) return main()
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter(input().split()) def main(): # 要素数(v) 昇順 # 先頭 から インデックス len(An) - K - 1 まで # 要素数(v) 合計 print((sum(sorted(An.values())[:len(An) - K]))) return main()
21
21
349
319
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter([int(i) for i in input().split()]) def main(): # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ # 先頭 K + 1 個目から 末尾 まで # 要素数(v) 合計 print((sum([v for k, v in An.most_common()[K:]]))) return main()
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter(input().split()) def main(): # 要素数(v) 昇順 # 先頭 から インデックス len(An) - K - 1 まで # 要素数(v) 合計 print((sum(sorted(An.values())[: len(An) - K]))) return main()
false
0
[ "-An = Counter([int(i) for i in input().split()])", "+An = Counter(input().split())", "- # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ", "- # 先頭 K + 1 個目から 末尾 まで", "+ # 要素数(v) 昇順", "+ # 先頭 から インデックス len(An) - K - 1 まで", "- print((sum([v for k, v in An.most_common()[K:]])))", "+ print((sum(sorted(An.values())[: len(An) - K])))" ]
false
0.047558
0.046217
1.029013
[ "s141770206", "s685350583" ]
u925940521
p03331
python
s783857347
s898382616
347
272
3,060
2,940
Accepted
Accepted
21.61
import sys def digits_sum(x): return sum(list(map(int, str(x)))) def solve(n): ans = sys.maxsize for a in range(1, n): b = n - a ans = min(ans, digits_sum(a) + digits_sum(b)) return ans if __name__ == '__main__': n = int(eval(input())) print((solve(n)))
import sys def digits_sum(x): return sum(map(int, str(x))) def solve(n): ans = sys.maxsize for a in range(1, n): b = n - a ans = min(ans, digits_sum(a) + digits_sum(b)) return ans if __name__ == '__main__': n = int(eval(input())) print((solve(n)))
16
16
305
299
import sys def digits_sum(x): return sum(list(map(int, str(x)))) def solve(n): ans = sys.maxsize for a in range(1, n): b = n - a ans = min(ans, digits_sum(a) + digits_sum(b)) return ans if __name__ == "__main__": n = int(eval(input())) print((solve(n)))
import sys def digits_sum(x): return sum(map(int, str(x))) def solve(n): ans = sys.maxsize for a in range(1, n): b = n - a ans = min(ans, digits_sum(a) + digits_sum(b)) return ans if __name__ == "__main__": n = int(eval(input())) print((solve(n)))
false
0
[ "- return sum(list(map(int, str(x))))", "+ return sum(map(int, str(x)))" ]
false
0.079866
0.071952
1.109987
[ "s783857347", "s898382616" ]
u955865009
p03030
python
s434406239
s929504567
30
26
9,172
9,064
Accepted
Accepted
13.33
N = int(eval(input())) l = [] for i in range(N): s,p = input().split(" ") l.append([s,-int(p),i+1]) l.sort() for s,p,i in l: print(i)
N = int(eval(input())) l = [] for i in range(N): s,p = input().split(" ") l.append([s,-int(p),i+1]) l.sort() for i in l: print((i[2]))
9
9
148
147
N = int(eval(input())) l = [] for i in range(N): s, p = input().split(" ") l.append([s, -int(p), i + 1]) l.sort() for s, p, i in l: print(i)
N = int(eval(input())) l = [] for i in range(N): s, p = input().split(" ") l.append([s, -int(p), i + 1]) l.sort() for i in l: print((i[2]))
false
0
[ "-for s, p, i in l:", "- print(i)", "+for i in l:", "+ print((i[2]))" ]
false
0.147726
0.007812
18.909604
[ "s434406239", "s929504567" ]
u690536347
p03700
python
s771453725
s172540310
1,730
1,185
10,908
11,080
Accepted
Accepted
31.5
n,a,b=list(map(int,input().split())) h=[int(eval(input())) for _ in [0]*n] f=lambda n:lambda x:x-b*n def calc(n): g=f(n) k=lambda x:1+x//(a-b) if x%(a-b) else x//(a-b) o=[x for x in map(g,h) if x>0] *p,=list(map(k,o)) if not p: return True else: return sum(p)<=n l,r=0,max(h) while r-l>1: m=(r+l)//2 if calc(m): r=m else: l=m print(r)
from math import ceil N,A,B=list(map(int,input().split())) h=[int(eval(input())) for _ in range(N)] def f(k): return sum([ceil((hi-B*k)/(A-B)) for hi in h if hi-k*B>0])<=k l,r=0,ceil(max(h)/B) while r-l>1: if f((l+r)//2): r=(l+r)//2 else: l=(l+r)//2 print(r)
22
17
374
295
n, a, b = list(map(int, input().split())) h = [int(eval(input())) for _ in [0] * n] f = lambda n: lambda x: x - b * n def calc(n): g = f(n) k = lambda x: 1 + x // (a - b) if x % (a - b) else x // (a - b) o = [x for x in map(g, h) if x > 0] (*p,) = list(map(k, o)) if not p: return True else: return sum(p) <= n l, r = 0, max(h) while r - l > 1: m = (r + l) // 2 if calc(m): r = m else: l = m print(r)
from math import ceil N, A, B = list(map(int, input().split())) h = [int(eval(input())) for _ in range(N)] def f(k): return sum([ceil((hi - B * k) / (A - B)) for hi in h if hi - k * B > 0]) <= k l, r = 0, ceil(max(h) / B) while r - l > 1: if f((l + r) // 2): r = (l + r) // 2 else: l = (l + r) // 2 print(r)
false
22.727273
[ "-n, a, b = list(map(int, input().split()))", "-h = [int(eval(input())) for _ in [0] * n]", "-f = lambda n: lambda x: x - b * n", "+from math import ceil", "+", "+N, A, B = list(map(int, input().split()))", "+h = [int(eval(input())) for _ in range(N)]", "-def calc(n):", "- g = f(n)", "- k = lambda x: 1 + x // (a - b) if x % (a - b) else x // (a - b)", "- o = [x for x in map(g, h) if x > 0]", "- (*p,) = list(map(k, o))", "- if not p:", "- return True", "- else:", "- return sum(p) <= n", "+def f(k):", "+ return sum([ceil((hi - B * k) / (A - B)) for hi in h if hi - k * B > 0]) <= k", "-l, r = 0, max(h)", "+l, r = 0, ceil(max(h) / B)", "- m = (r + l) // 2", "- if calc(m):", "- r = m", "+ if f((l + r) // 2):", "+ r = (l + r) // 2", "- l = m", "+ l = (l + r) // 2" ]
false
0.031713
0.063105
0.502549
[ "s771453725", "s172540310" ]
u768636516
p02641
python
s947485141
s541145997
68
29
61,964
9,104
Accepted
Accepted
57.35
X,N = list(map(int,input().split())) if N == 0: print(X) exit() array = sorted(list(map(int,input().split()))) if not X in array: print(X) exit() else: for i in range(1,200): X_plus = X + i X_pull = X - i if not X_pull in array: print(X_pull) exit() if not X_plus in array: print(X_plus) exit()
X, N = list(map(int, input().split())) P = list(map(int, input().split())) Q = [q for q in range(-1, 102) if q not in P] # -1以上101以下整数のうちPに存在しないもの ans = min(Q, key=lambda q: (abs(q - X), q)) # maspyさん解法 print(ans)
18
6
358
215
X, N = list(map(int, input().split())) if N == 0: print(X) exit() array = sorted(list(map(int, input().split()))) if not X in array: print(X) exit() else: for i in range(1, 200): X_plus = X + i X_pull = X - i if not X_pull in array: print(X_pull) exit() if not X_plus in array: print(X_plus) exit()
X, N = list(map(int, input().split())) P = list(map(int, input().split())) Q = [q for q in range(-1, 102) if q not in P] # -1以上101以下整数のうちPに存在しないもの ans = min(Q, key=lambda q: (abs(q - X), q)) # maspyさん解法 print(ans)
false
66.666667
[ "-if N == 0:", "- print(X)", "- exit()", "-array = sorted(list(map(int, input().split())))", "-if not X in array:", "- print(X)", "- exit()", "-else:", "- for i in range(1, 200):", "- X_plus = X + i", "- X_pull = X - i", "- if not X_pull in array:", "- print(X_pull)", "- exit()", "- if not X_plus in array:", "- print(X_plus)", "- exit()", "+P = list(map(int, input().split()))", "+Q = [q for q in range(-1, 102) if q not in P] # -1以上101以下整数のうちPに存在しないもの", "+ans = min(Q, key=lambda q: (abs(q - X), q)) # maspyさん解法", "+print(ans)" ]
false
0.113094
0.059972
1.885775
[ "s947485141", "s541145997" ]
u226108478
p03243
python
s146303344
s780766866
19
17
2,940
2,940
Accepted
Accepted
10.53
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) for i in range(100, 1000): if i % 111 == 0 and i >= n: print(i) exit() if __name__ == '__main__': main()
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) # See: # https://www.youtube.com/watch?v=fYS-rAUSD5o for i in range(111, 1000, 111): if i >= n: print(i) exit() if __name__ == '__main__': main()
14
16
220
271
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) for i in range(100, 1000): if i % 111 == 0 and i >= n: print(i) exit() if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) # See: # https://www.youtube.com/watch?v=fYS-rAUSD5o for i in range(111, 1000, 111): if i >= n: print(i) exit() if __name__ == "__main__": main()
false
12.5
[ "- for i in range(100, 1000):", "- if i % 111 == 0 and i >= n:", "+ # See:", "+ # https://www.youtube.com/watch?v=fYS-rAUSD5o", "+ for i in range(111, 1000, 111):", "+ if i >= n:" ]
false
0.162763
0.156467
1.040238
[ "s146303344", "s780766866" ]
u415905784
p03290
python
s658884653
s313831654
409
292
3,288
3,316
Accepted
Accepted
28.61
D, G= list(map(int, input().split())) P = [[int(x) for x in input().split()] for d in range(D)] Score = [[] for d in range(D)] for d in range(D): for i in range(P[d][0] + 1): Score[d].append(100 * (d + 1) * i) Score[d][-1] += P[d][1] DP = [[] for d in range(D)] DP[0] = [x for x in Score[0]] p_all = P[0][0] for d in range(1, D): p_all += P[d][0] DP[d] = [0 for i in range(p_all + 1)] for p in range(p_all + 1): for s in range(min(P[d][0], p) + 1): if p - s < p_all - P[d][0] + 1: DP[d][p] = max(Score[d][s] + DP[d - 1][p - s], DP[d][p]) for i, s in enumerate(DP[D - 1]): if s >= G: print(i) break
D, G = list(map(int, input().split())) S = [[0] for i in range(D + 1)] B = [[0] for i in range(D + 1)] sumP = 0 for i in range(D): p, c = list(map(int, input().split())) S[i + 1] += [0] * (len(S[i]) + p - 1) B[i + 1] += [100 * (i + 1) * (x + 1) for x in range(p)] B[i + 1][-1] += c for i in range(1, D + 1): for j in range(1, len(S[i])): for k in range(max(j - len(S[i - 1]) + 1, 0), min(len(B[i]), j + 1)): S[i][j] = max(B[i][k] + S[i - 1][j - k], S[i][j]) for i, s in enumerate(S[D]): if s >= G: print(i) break
21
17
653
546
D, G = list(map(int, input().split())) P = [[int(x) for x in input().split()] for d in range(D)] Score = [[] for d in range(D)] for d in range(D): for i in range(P[d][0] + 1): Score[d].append(100 * (d + 1) * i) Score[d][-1] += P[d][1] DP = [[] for d in range(D)] DP[0] = [x for x in Score[0]] p_all = P[0][0] for d in range(1, D): p_all += P[d][0] DP[d] = [0 for i in range(p_all + 1)] for p in range(p_all + 1): for s in range(min(P[d][0], p) + 1): if p - s < p_all - P[d][0] + 1: DP[d][p] = max(Score[d][s] + DP[d - 1][p - s], DP[d][p]) for i, s in enumerate(DP[D - 1]): if s >= G: print(i) break
D, G = list(map(int, input().split())) S = [[0] for i in range(D + 1)] B = [[0] for i in range(D + 1)] sumP = 0 for i in range(D): p, c = list(map(int, input().split())) S[i + 1] += [0] * (len(S[i]) + p - 1) B[i + 1] += [100 * (i + 1) * (x + 1) for x in range(p)] B[i + 1][-1] += c for i in range(1, D + 1): for j in range(1, len(S[i])): for k in range(max(j - len(S[i - 1]) + 1, 0), min(len(B[i]), j + 1)): S[i][j] = max(B[i][k] + S[i - 1][j - k], S[i][j]) for i, s in enumerate(S[D]): if s >= G: print(i) break
false
19.047619
[ "-P = [[int(x) for x in input().split()] for d in range(D)]", "-Score = [[] for d in range(D)]", "-for d in range(D):", "- for i in range(P[d][0] + 1):", "- Score[d].append(100 * (d + 1) * i)", "- Score[d][-1] += P[d][1]", "-DP = [[] for d in range(D)]", "-DP[0] = [x for x in Score[0]]", "-p_all = P[0][0]", "-for d in range(1, D):", "- p_all += P[d][0]", "- DP[d] = [0 for i in range(p_all + 1)]", "- for p in range(p_all + 1):", "- for s in range(min(P[d][0], p) + 1):", "- if p - s < p_all - P[d][0] + 1:", "- DP[d][p] = max(Score[d][s] + DP[d - 1][p - s], DP[d][p])", "-for i, s in enumerate(DP[D - 1]):", "+S = [[0] for i in range(D + 1)]", "+B = [[0] for i in range(D + 1)]", "+sumP = 0", "+for i in range(D):", "+ p, c = list(map(int, input().split()))", "+ S[i + 1] += [0] * (len(S[i]) + p - 1)", "+ B[i + 1] += [100 * (i + 1) * (x + 1) for x in range(p)]", "+ B[i + 1][-1] += c", "+for i in range(1, D + 1):", "+ for j in range(1, len(S[i])):", "+ for k in range(max(j - len(S[i - 1]) + 1, 0), min(len(B[i]), j + 1)):", "+ S[i][j] = max(B[i][k] + S[i - 1][j - k], S[i][j])", "+for i, s in enumerate(S[D]):" ]
false
0.092771
0.048367
1.918051
[ "s658884653", "s313831654" ]
u645487439
p02781
python
s588576261
s317464996
464
18
3,060
3,064
Accepted
Accepted
96.12
def solve(n,k) : if n <= 9 and k == 1 : return n elif n <= 9 and k >= 2 : return 0 elif k == 0: return 1 else : m = n //10 r = n % 10 return r * solve(m,k-1) + (9 - r) * solve(m-1,k-1) + solve(m,k) n = int(eval(input())) k = int(eval(input())) print((solve(n,k)))
N = eval(input()) K = int(eval(input())) m = len(N) dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)] dp[0][0][0] = 1 for i in range(1, m + 1): l = int(N[i - 1]) for k in range(K + 1): dp[i][1][k] += dp[i - 1][1][k] if l != 0: dp[i][1][k] += dp[i - 1][0][k] else: dp[i][0][k] += dp[i - 1][0][k] if k - 1 >= 0: dp[i][1][k] += 9 * dp[i - 1][1][k - 1] if l != 0: dp[i][0][k] += dp[i - 1][0][k - 1] dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1] print((dp[m][0][K] + dp[m][1][K]))
15
21
329
616
def solve(n, k): if n <= 9 and k == 1: return n elif n <= 9 and k >= 2: return 0 elif k == 0: return 1 else: m = n // 10 r = n % 10 return r * solve(m, k - 1) + (9 - r) * solve(m - 1, k - 1) + solve(m, k) n = int(eval(input())) k = int(eval(input())) print((solve(n, k)))
N = eval(input()) K = int(eval(input())) m = len(N) dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)] dp[0][0][0] = 1 for i in range(1, m + 1): l = int(N[i - 1]) for k in range(K + 1): dp[i][1][k] += dp[i - 1][1][k] if l != 0: dp[i][1][k] += dp[i - 1][0][k] else: dp[i][0][k] += dp[i - 1][0][k] if k - 1 >= 0: dp[i][1][k] += 9 * dp[i - 1][1][k - 1] if l != 0: dp[i][0][k] += dp[i - 1][0][k - 1] dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1] print((dp[m][0][K] + dp[m][1][K]))
false
28.571429
[ "-def solve(n, k):", "- if n <= 9 and k == 1:", "- return n", "- elif n <= 9 and k >= 2:", "- return 0", "- elif k == 0:", "- return 1", "- else:", "- m = n // 10", "- r = n % 10", "- return r * solve(m, k - 1) + (9 - r) * solve(m - 1, k - 1) + solve(m, k)", "-", "-", "-n = int(eval(input()))", "-k = int(eval(input()))", "-print((solve(n, k)))", "+N = eval(input())", "+K = int(eval(input()))", "+m = len(N)", "+dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]", "+dp[0][0][0] = 1", "+for i in range(1, m + 1):", "+ l = int(N[i - 1])", "+ for k in range(K + 1):", "+ dp[i][1][k] += dp[i - 1][1][k]", "+ if l != 0:", "+ dp[i][1][k] += dp[i - 1][0][k]", "+ else:", "+ dp[i][0][k] += dp[i - 1][0][k]", "+ if k - 1 >= 0:", "+ dp[i][1][k] += 9 * dp[i - 1][1][k - 1]", "+ if l != 0:", "+ dp[i][0][k] += dp[i - 1][0][k - 1]", "+ dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1]", "+print((dp[m][0][K] + dp[m][1][K]))" ]
false
0.126355
0.036345
3.476553
[ "s588576261", "s317464996" ]
u608241985
p02725
python
s094819943
s113103937
119
85
21,556
27,784
Accepted
Accepted
28.57
import sys read = sys.stdin.buffer.read k, n, *A = read().split() far = int(k) + int(A[0]) - int(A[-1]) for x, y in zip(A[1:], A): if far < int(x) - int(y): far = int(x) - int(y) print((int(k)-far))
import sys read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] for x, y in zip(A[1:], A): if far < x - y: far = x - y print((k-far))
8
8
215
185
import sys read = sys.stdin.buffer.read k, n, *A = read().split() far = int(k) + int(A[0]) - int(A[-1]) for x, y in zip(A[1:], A): if far < int(x) - int(y): far = int(x) - int(y) print((int(k) - far))
import sys read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] for x, y in zip(A[1:], A): if far < x - y: far = x - y print((k - far))
false
0
[ "-k, n, *A = read().split()", "-far = int(k) + int(A[0]) - int(A[-1])", "+k, n, *A = list(map(int, read().split()))", "+far = k + A[0] - A[-1]", "- if far < int(x) - int(y):", "- far = int(x) - int(y)", "-print((int(k) - far))", "+ if far < x - y:", "+ far = x - y", "+print((k - far))" ]
false
0.038325
0.083018
0.461646
[ "s094819943", "s113103937" ]
u174394352
p03078
python
s899501190
s610989247
974
352
149,616
54,744
Accepted
Accepted
63.86
X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) from itertools import product D=sorted([a+b for a,b in product(A,B)],reverse=True) D=D[:K] E=sorted([d+c for d,c in product(D,C)],reverse=True) for i in range(K): print((E[i]))
X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) from heapq import heappop,heappush from collections import defaultdict f=defaultdict(int) pq=[] def push(a,b,c): if f[(a,b,c)]==0 and a<X and b<Y and c<Z: heappush(pq,(-(A[a]+B[b]+C[c]),a,b,c)) f[(a,b,c)]=1 push(0,0,0) for i in range(K): d,a,b,c=heappop(pq) print((-d)) push(a+1,b,c) push(a,b+1,c) push(a,b,c+1)
11
28
322
578
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) from itertools import product D = sorted([a + b for a, b in product(A, B)], reverse=True) D = D[:K] E = sorted([d + c for d, c in product(D, C)], reverse=True) for i in range(K): print((E[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) from heapq import heappop, heappush from collections import defaultdict f = defaultdict(int) pq = [] def push(a, b, c): if f[(a, b, c)] == 0 and a < X and b < Y and c < Z: heappush(pq, (-(A[a] + B[b] + C[c]), a, b, c)) f[(a, b, c)] = 1 push(0, 0, 0) for i in range(K): d, a, b, c = heappop(pq) print((-d)) push(a + 1, b, c) push(a, b + 1, c) push(a, b, c + 1)
false
60.714286
[ "-from itertools import product", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+from heapq import heappop, heappush", "+from collections import defaultdict", "-D = sorted([a + b for a, b in product(A, B)], reverse=True)", "-D = D[:K]", "-E = sorted([d + c for d, c in product(D, C)], reverse=True)", "+f = defaultdict(int)", "+pq = []", "+", "+", "+def push(a, b, c):", "+ if f[(a, b, c)] == 0 and a < X and b < Y and c < Z:", "+ heappush(pq, (-(A[a] + B[b] + C[c]), a, b, c))", "+ f[(a, b, c)] = 1", "+", "+", "+push(0, 0, 0)", "- print((E[i]))", "+ d, a, b, c = heappop(pq)", "+ print((-d))", "+ push(a + 1, b, c)", "+ push(a, b + 1, c)", "+ push(a, b, c + 1)" ]
false
0.037431
0.038343
0.976201
[ "s899501190", "s610989247" ]
u941047297
p03574
python
s874551762
s260903097
219
27
44,016
3,188
Accepted
Accepted
87.67
from itertools import product H, W = list(map(int, input().split())) S = [input() for _ in range(H)] ans = S[:] ans = [list(a) for a in ans] S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)] for h, w in product(range(1, H + 1), range(1, W + 1)): if S[h][w] == '#': continue count = 0 for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)): if (i == h) and (j == w): continue if S[i][j] == '#': count += 1 ans[h - 1][w - 1] = str(count) ans = [''.join(a) for a in ans] [print(a) for a in ans]
from itertools import product H, W = list(map(int, input().split())) S = [['.'] * (W + 2)] + [['.', ] + list(input()) + ['.', ] for _ in range(H)] + [['.'] * (W + 2)] ans = [[0] * W for _ in range(H)] for i, j in product(range(1, H + 1), range(1, W + 1)): if S[i][j] == '.': count = 0 for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)): if k == i and l == j: continue elif S[k][l] == '#': count += 1 ans[i - 1][j - 1] = str(count) else: ans[i - 1][j - 1] = '#' [print(''.join(a)) for a in ans]
18
16
596
615
from itertools import product H, W = list(map(int, input().split())) S = [input() for _ in range(H)] ans = S[:] ans = [list(a) for a in ans] S = ["." * (W + 2)] + ["." + s + "." for s in S] + ["." * (W + 2)] for h, w in product(range(1, H + 1), range(1, W + 1)): if S[h][w] == "#": continue count = 0 for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)): if (i == h) and (j == w): continue if S[i][j] == "#": count += 1 ans[h - 1][w - 1] = str(count) ans = ["".join(a) for a in ans] [print(a) for a in ans]
from itertools import product H, W = list(map(int, input().split())) S = ( [["."] * (W + 2)] + [ [ ".", ] + list(input()) + [ ".", ] for _ in range(H) ] + [["."] * (W + 2)] ) ans = [[0] * W for _ in range(H)] for i, j in product(range(1, H + 1), range(1, W + 1)): if S[i][j] == ".": count = 0 for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)): if k == i and l == j: continue elif S[k][l] == "#": count += 1 ans[i - 1][j - 1] = str(count) else: ans[i - 1][j - 1] = "#" [print("".join(a)) for a in ans]
false
11.111111
[ "-S = [input() for _ in range(H)]", "-ans = S[:]", "-ans = [list(a) for a in ans]", "-S = [\".\" * (W + 2)] + [\".\" + s + \".\" for s in S] + [\".\" * (W + 2)]", "-for h, w in product(range(1, H + 1), range(1, W + 1)):", "- if S[h][w] == \"#\":", "- continue", "- count = 0", "- for i, j in product(range(h - 1, h + 2), range(w - 1, w + 2)):", "- if (i == h) and (j == w):", "- continue", "- if S[i][j] == \"#\":", "- count += 1", "- ans[h - 1][w - 1] = str(count)", "-ans = [\"\".join(a) for a in ans]", "-[print(a) for a in ans]", "+S = (", "+ [[\".\"] * (W + 2)]", "+ + [", "+ [", "+ \".\",", "+ ]", "+ + list(input())", "+ + [", "+ \".\",", "+ ]", "+ for _ in range(H)", "+ ]", "+ + [[\".\"] * (W + 2)]", "+)", "+ans = [[0] * W for _ in range(H)]", "+for i, j in product(range(1, H + 1), range(1, W + 1)):", "+ if S[i][j] == \".\":", "+ count = 0", "+ for k, l in product(range(i - 1, i + 2), range(j - 1, j + 2)):", "+ if k == i and l == j:", "+ continue", "+ elif S[k][l] == \"#\":", "+ count += 1", "+ ans[i - 1][j - 1] = str(count)", "+ else:", "+ ans[i - 1][j - 1] = \"#\"", "+[print(\"\".join(a)) for a in ans]" ]
false
0.07197
0.164916
0.436401
[ "s874551762", "s260903097" ]
u968404618
p02683
python
s006122706
s988971340
81
62
9,220
9,280
Accepted
Accepted
23.46
n, m, x = list(map(int, input().split())) C = [] A = [] for _ in range(n): tmp = list(map(int, input().split())) C.append(tmp[0]) A.append(tmp[1:]) f_inf = float("inf") ans = f_inf for s in range(1<<n): cst = 0 D = [0] * m for i in range(n): if s>>i & 1: cst += C[i] for j in range(m): D[j] += A[i][j] flg = True for d in D: if d < x: flg = False if flg: ans = min(ans, cst) if ans == f_inf: print((-1)) else: print(ans)
def main(): ## IMPORT MODULE #import sys #sys.setrecursionlimit(100000) #input=lambda :sys.stdin.readline().rstrip() f_inf=float("inf") #MOD=10**9+7 if 'get_ipython' in globals(): ## SAMPLE INPUT n, m, x = 3, 3, 10 C = [60, 70, 50] A = [[2, 2, 4], [8, 7, 9], [2, 3, 9]] else: ##INPUT #n = input() n, m, x = list(map(int, input().split())) C = [] A = [] for _ in range(n): tmp = list(map(int, input().split())) C.append(tmp[0]) A.append(tmp[1:]) ## SUBMITION CODES HERE ans = f_inf for s in range(1<<n): # 1<<n: 2^n cost = 0 D = [0] * m for i in range(n): if s>>i & 1: # Shift s by i times to the right and check if the least significant digit is 1 cost += C[i] for j in range(m): D[j] += A[i][j] flg = True for d in D: if d < x: flg = False if flg: ans = min(ans, cost) if ans == f_inf: print((-1)) else: print(ans) main()
29
49
554
1,054
n, m, x = list(map(int, input().split())) C = [] A = [] for _ in range(n): tmp = list(map(int, input().split())) C.append(tmp[0]) A.append(tmp[1:]) f_inf = float("inf") ans = f_inf for s in range(1 << n): cst = 0 D = [0] * m for i in range(n): if s >> i & 1: cst += C[i] for j in range(m): D[j] += A[i][j] flg = True for d in D: if d < x: flg = False if flg: ans = min(ans, cst) if ans == f_inf: print((-1)) else: print(ans)
def main(): ## IMPORT MODULE # import sys # sys.setrecursionlimit(100000) # input=lambda :sys.stdin.readline().rstrip() f_inf = float("inf") # MOD=10**9+7 if "get_ipython" in globals(): ## SAMPLE INPUT n, m, x = 3, 3, 10 C = [60, 70, 50] A = [[2, 2, 4], [8, 7, 9], [2, 3, 9]] else: ##INPUT # n = input() n, m, x = list(map(int, input().split())) C = [] A = [] for _ in range(n): tmp = list(map(int, input().split())) C.append(tmp[0]) A.append(tmp[1:]) ## SUBMITION CODES HERE ans = f_inf for s in range(1 << n): # 1<<n: 2^n cost = 0 D = [0] * m for i in range(n): if ( s >> i & 1 ): # Shift s by i times to the right and check if the least significant digit is 1 cost += C[i] for j in range(m): D[j] += A[i][j] flg = True for d in D: if d < x: flg = False if flg: ans = min(ans, cost) if ans == f_inf: print((-1)) else: print(ans) main()
false
40.816327
[ "-n, m, x = list(map(int, input().split()))", "-C = []", "-A = []", "-for _ in range(n):", "- tmp = list(map(int, input().split()))", "- C.append(tmp[0])", "- A.append(tmp[1:])", "-f_inf = float(\"inf\")", "-ans = f_inf", "-for s in range(1 << n):", "- cst = 0", "- D = [0] * m", "- for i in range(n):", "- if s >> i & 1:", "- cst += C[i]", "- for j in range(m):", "- D[j] += A[i][j]", "- flg = True", "- for d in D:", "- if d < x:", "- flg = False", "- if flg:", "- ans = min(ans, cst)", "-if ans == f_inf:", "- print((-1))", "-else:", "- print(ans)", "+def main():", "+ ## IMPORT MODULE", "+ # import sys", "+ # sys.setrecursionlimit(100000)", "+ # input=lambda :sys.stdin.readline().rstrip()", "+ f_inf = float(\"inf\")", "+ # MOD=10**9+7", "+ if \"get_ipython\" in globals():", "+ ## SAMPLE INPUT", "+ n, m, x = 3, 3, 10", "+ C = [60, 70, 50]", "+ A = [[2, 2, 4], [8, 7, 9], [2, 3, 9]]", "+ else:", "+ ##INPUT", "+ # n = input()", "+ n, m, x = list(map(int, input().split()))", "+ C = []", "+ A = []", "+ for _ in range(n):", "+ tmp = list(map(int, input().split()))", "+ C.append(tmp[0])", "+ A.append(tmp[1:])", "+ ## SUBMITION CODES HERE", "+ ans = f_inf", "+ for s in range(1 << n): # 1<<n: 2^n", "+ cost = 0", "+ D = [0] * m", "+ for i in range(n):", "+ if (", "+ s >> i & 1", "+ ): # Shift s by i times to the right and check if the least significant digit is 1", "+ cost += C[i]", "+ for j in range(m):", "+ D[j] += A[i][j]", "+ flg = True", "+ for d in D:", "+ if d < x:", "+ flg = False", "+ if flg:", "+ ans = min(ans, cost)", "+ if ans == f_inf:", "+ print((-1))", "+ else:", "+ print(ans)", "+", "+", "+main()" ]
false
0.044814
0.038052
1.177724
[ "s006122706", "s988971340" ]
u214617707
p03436
python
s155119453
s017802496
84
26
3,436
3,064
Accepted
Accepted
69.05
from collections import deque H, W = list(map(int, input().split())) INF = float("inf") d = [[INF] * W for _ in range(H)] T = [[""] * W for _ in range(H)] sx, sy = 0, 0 gx, gy = H - 1, W - 1 num = 0 for i in range(H): a = eval(input()) for j in range(W): T[i][j] = a[j] num += a.count("#") def bfs(): que = deque() que.append((sx, sy)) d[sx][sy] = 0 while len(que): x, y = que.popleft() if x == gx and y == gy: break for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and T[nx][ny] != "#" and d[nx][ny] == INF: que.append((nx, ny)) d[nx][ny] = d[x][y] + 1 return d[gx][gy] ans = bfs() if ans < INF: print((H * W - ans - num - 1)) else: print((-1))
H, W = list(map(int, input().split())) T = [[] for i in range(H)] b = 0 for i in range(H): T[i] = list(eval(input())) for j in range(W): if T[i][j] == '#': b += 1 que = [(0, 0, 1)] while que: x, y, k = que.pop(0) if x == H - 1 and y == W - 1: print((H * W - b - k)) exit() for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == '.': T[nx][ny] = '#' que.append((nx, ny, k + 1)) print((-1))
39
22
871
558
from collections import deque H, W = list(map(int, input().split())) INF = float("inf") d = [[INF] * W for _ in range(H)] T = [[""] * W for _ in range(H)] sx, sy = 0, 0 gx, gy = H - 1, W - 1 num = 0 for i in range(H): a = eval(input()) for j in range(W): T[i][j] = a[j] num += a.count("#") def bfs(): que = deque() que.append((sx, sy)) d[sx][sy] = 0 while len(que): x, y = que.popleft() if x == gx and y == gy: break for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and T[nx][ny] != "#" and d[nx][ny] == INF: que.append((nx, ny)) d[nx][ny] = d[x][y] + 1 return d[gx][gy] ans = bfs() if ans < INF: print((H * W - ans - num - 1)) else: print((-1))
H, W = list(map(int, input().split())) T = [[] for i in range(H)] b = 0 for i in range(H): T[i] = list(eval(input())) for j in range(W): if T[i][j] == "#": b += 1 que = [(0, 0, 1)] while que: x, y, k = que.pop(0) if x == H - 1 and y == W - 1: print((H * W - b - k)) exit() for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == ".": T[nx][ny] = "#" que.append((nx, ny, k + 1)) print((-1))
false
43.589744
[ "-from collections import deque", "-", "-INF = float(\"inf\")", "-d = [[INF] * W for _ in range(H)]", "-T = [[\"\"] * W for _ in range(H)]", "-sx, sy = 0, 0", "-gx, gy = H - 1, W - 1", "-num = 0", "+T = [[] for i in range(H)]", "+b = 0", "- a = eval(input())", "+ T[i] = list(eval(input()))", "- T[i][j] = a[j]", "- num += a.count(\"#\")", "-", "-", "-def bfs():", "- que = deque()", "- que.append((sx, sy))", "- d[sx][sy] = 0", "- while len(que):", "- x, y = que.popleft()", "- if x == gx and y == gy:", "- break", "- for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:", "- nx, ny = x + dx, y + dy", "- if 0 <= nx < H and 0 <= ny < W and T[nx][ny] != \"#\" and d[nx][ny] == INF:", "- que.append((nx, ny))", "- d[nx][ny] = d[x][y] + 1", "- return d[gx][gy]", "-", "-", "-ans = bfs()", "-if ans < INF:", "- print((H * W - ans - num - 1))", "-else:", "- print((-1))", "+ if T[i][j] == \"#\":", "+ b += 1", "+que = [(0, 0, 1)]", "+while que:", "+ x, y, k = que.pop(0)", "+ if x == H - 1 and y == W - 1:", "+ print((H * W - b - k))", "+ exit()", "+ for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:", "+ nx, ny = x + dx, y + dy", "+ if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == \".\":", "+ T[nx][ny] = \"#\"", "+ que.append((nx, ny, k + 1))", "+print((-1))" ]
false
0.038158
0.062009
0.615363
[ "s155119453", "s017802496" ]
u119148115
p02609
python
s002881970
s809911169
297
182
133,692
134,748
Accepted
Accepted
38.72
import sys def I(): return int(sys.stdin.readline().rstrip()) def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() A = [0] # A[i] = f(i) (0<=i<=N-1) for i in range(1,N): a = 0 # iの2進表記に現れる1の個数 for j in range(18): a += (i >> j) & 1 A.append(1 + A[i % a]) X = LS2() b = 0 # Xの2進表記に現れる1の個数 for i in range(N): if X[i] == '1': b += 1 if b >= 2: c1,c2 = b-1,b+1 amari1 = [1] amari2 = [1] for i in range(1,N): amari1.append((amari1[-1]*2) % c1) amari2.append((amari2[-1]*2) % c2) amari1.reverse() amari2.reverse() # amari1[i] = 2**(N-i-1) mod c1 # amari2[i] = 2**(N-i-1) mod c2 r1,r2 = 0,0 # ri = X mod ci for i in range(N): if X[i] == '1': r1 += amari1[i] r1 %= c1 r2 += amari2[i] r2 %= c2 ANS = [] for i in range(N): if X[i] == '1': ANS.append(A[(r1-amari1[i]) % c1]+1) else: ANS.append(A[(r2+amari2[i]) % c2]+1) else: c2 = b+1 amari2 = [1] for i in range(1, N): amari2.append((amari2[-1]*2) % c2) amari2.reverse() # amari2[i] = 2**(N-i-1) mod c2 r2 = 0 # X mod c2 for i in range(N): if X[i] == '1': r2 += amari2[i] r2 %= c2 ANS = [] for i in range(N): if X[i] == '1': ANS.append(0) else: ANS.append(A[(r2+amari2[i]) % c2] + 1) print(*ANS,sep='\n')
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() X = LI2() X.reverse() if N == 1 and len(X) == 1 and X[0] == 0: print(1) exit() def popcount(n): res = 0 m = n.bit_length() for i in range(m): res += (n >> i) & 1 return res F = [0]*(2*10**5) for i in range(1,2*10**5): F[i] = 1 + F[i % popcount(i)] a = sum(X) b = a-1 c = a+1 if a == 1: A, C = [1], [1] # 2冪をa,b,cで割った余り xa, xc = 0, 0 # Xをa,b,cで割った余り for i in range(N): if X[i] == 1: xa += A[-1] xc += C[-1] xa %= a xc %= c A.append((2 * A[-1]) % a) C.append((2 * C[-1]) % c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(0) else: ANS.append(1 + F[(xc + C[i]) % c]) ANS.reverse() print(*ANS, sep='\n') exit() A,B,C = [1],[1],[1] # 2冪をa,b,cで割った余り xa,xb,xc = 0,0,0 # Xをa,b,cで割った余り for i in range(N): if X[i] == 1: xa += A[-1] xb += B[-1] xc += C[-1] xa %= a xb %= b xc %= c A.append((2*A[-1])%a) B.append((2*B[-1])%b) C.append((2*C[-1])%c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(1 + F[(xb-B[i]) % b]) else: ANS.append(1 + F[(xc+C[i]) % c]) ANS.reverse() print(*ANS,sep='\n')
69
82
1,551
1,844
import sys def I(): return int(sys.stdin.readline().rstrip()) def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N = I() A = [0] # A[i] = f(i) (0<=i<=N-1) for i in range(1, N): a = 0 # iの2進表記に現れる1の個数 for j in range(18): a += (i >> j) & 1 A.append(1 + A[i % a]) X = LS2() b = 0 # Xの2進表記に現れる1の個数 for i in range(N): if X[i] == "1": b += 1 if b >= 2: c1, c2 = b - 1, b + 1 amari1 = [1] amari2 = [1] for i in range(1, N): amari1.append((amari1[-1] * 2) % c1) amari2.append((amari2[-1] * 2) % c2) amari1.reverse() amari2.reverse() # amari1[i] = 2**(N-i-1) mod c1 # amari2[i] = 2**(N-i-1) mod c2 r1, r2 = 0, 0 # ri = X mod ci for i in range(N): if X[i] == "1": r1 += amari1[i] r1 %= c1 r2 += amari2[i] r2 %= c2 ANS = [] for i in range(N): if X[i] == "1": ANS.append(A[(r1 - amari1[i]) % c1] + 1) else: ANS.append(A[(r2 + amari2[i]) % c2] + 1) else: c2 = b + 1 amari2 = [1] for i in range(1, N): amari2.append((amari2[-1] * 2) % c2) amari2.reverse() # amari2[i] = 2**(N-i-1) mod c2 r2 = 0 # X mod c2 for i in range(N): if X[i] == "1": r2 += amari2[i] r2 %= c2 ANS = [] for i in range(N): if X[i] == "1": ANS.append(0) else: ANS.append(A[(r2 + amari2[i]) % c2] + 1) print(*ANS, sep="\n")
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N = I() X = LI2() X.reverse() if N == 1 and len(X) == 1 and X[0] == 0: print(1) exit() def popcount(n): res = 0 m = n.bit_length() for i in range(m): res += (n >> i) & 1 return res F = [0] * (2 * 10**5) for i in range(1, 2 * 10**5): F[i] = 1 + F[i % popcount(i)] a = sum(X) b = a - 1 c = a + 1 if a == 1: A, C = [1], [1] # 2冪をa,b,cで割った余り xa, xc = 0, 0 # Xをa,b,cで割った余り for i in range(N): if X[i] == 1: xa += A[-1] xc += C[-1] xa %= a xc %= c A.append((2 * A[-1]) % a) C.append((2 * C[-1]) % c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(0) else: ANS.append(1 + F[(xc + C[i]) % c]) ANS.reverse() print(*ANS, sep="\n") exit() A, B, C = [1], [1], [1] # 2冪をa,b,cで割った余り xa, xb, xc = 0, 0, 0 # Xをa,b,cで割った余り for i in range(N): if X[i] == 1: xa += A[-1] xb += B[-1] xc += C[-1] xa %= a xb %= b xc %= c A.append((2 * A[-1]) % a) B.append((2 * B[-1]) % b) C.append((2 * C[-1]) % c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(1 + F[(xb - B[i]) % b]) else: ANS.append(1 + F[(xc + C[i]) % c]) ANS.reverse() print(*ANS, sep="\n")
false
15.853659
[ "+", "+sys.setrecursionlimit(10**7)", "+", "+", "+def MI():", "+ return map(int, sys.stdin.readline().rstrip().split())", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "+", "+", "+def LI2():", "+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "+", "+", "+def S():", "+ return sys.stdin.readline().rstrip()", "+", "+", "+def LS():", "+ return list(sys.stdin.readline().rstrip().split()) # 空白あり", "-A = [0] # A[i] = f(i) (0<=i<=N-1)", "-for i in range(1, N):", "- a = 0 # iの2進表記に現れる1の個数", "- for j in range(18):", "- a += (i >> j) & 1", "- A.append(1 + A[i % a])", "-X = LS2()", "-b = 0 # Xの2進表記に現れる1の個数", "-for i in range(N):", "- if X[i] == \"1\":", "- b += 1", "-if b >= 2:", "- c1, c2 = b - 1, b + 1", "- amari1 = [1]", "- amari2 = [1]", "- for i in range(1, N):", "- amari1.append((amari1[-1] * 2) % c1)", "- amari2.append((amari2[-1] * 2) % c2)", "- amari1.reverse()", "- amari2.reverse()", "- # amari1[i] = 2**(N-i-1) mod c1", "- # amari2[i] = 2**(N-i-1) mod c2", "- r1, r2 = 0, 0 # ri = X mod ci", "+X = LI2()", "+X.reverse()", "+if N == 1 and len(X) == 1 and X[0] == 0:", "+ print(1)", "+ exit()", "+", "+", "+def popcount(n):", "+ res = 0", "+ m = n.bit_length()", "+ for i in range(m):", "+ res += (n >> i) & 1", "+ return res", "+", "+", "+F = [0] * (2 * 10**5)", "+for i in range(1, 2 * 10**5):", "+ F[i] = 1 + F[i % popcount(i)]", "+a = sum(X)", "+b = a - 1", "+c = a + 1", "+if a == 1:", "+ A, C = [1], [1] # 2冪をa,b,cで割った余り", "+ xa, xc = 0, 0 # Xをa,b,cで割った余り", "- if X[i] == \"1\":", "- r1 += amari1[i]", "- r1 %= c1", "- r2 += amari2[i]", "- r2 %= c2", "+ if X[i] == 1:", "+ xa += A[-1]", "+ xc += C[-1]", "+ xa %= a", "+ xc %= c", "+ A.append((2 * A[-1]) % a)", "+ C.append((2 * C[-1]) % c)", "- if X[i] == \"1\":", "- ANS.append(A[(r1 - amari1[i]) % c1] + 1)", "- else:", "- ANS.append(A[(r2 + amari2[i]) % c2] + 1)", "-else:", "- c2 = b + 1", "- amari2 = [1]", "- for i in range(1, N):", "- amari2.append((amari2[-1] * 2) % c2)", "- amari2.reverse()", "- # amari2[i] = 2**(N-i-1) mod c2", "- r2 = 0 # X mod c2", "- for i in range(N):", "- if X[i] == \"1\":", "- r2 += amari2[i]", "- r2 %= c2", "- ANS = []", "- for i in range(N):", "- if X[i] == \"1\":", "+ if X[i] == 1:", "- ANS.append(A[(r2 + amari2[i]) % c2] + 1)", "+ ANS.append(1 + F[(xc + C[i]) % c])", "+ ANS.reverse()", "+ print(*ANS, sep=\"\\n\")", "+ exit()", "+A, B, C = [1], [1], [1] # 2冪をa,b,cで割った余り", "+xa, xb, xc = 0, 0, 0 # Xをa,b,cで割った余り", "+for i in range(N):", "+ if X[i] == 1:", "+ xa += A[-1]", "+ xb += B[-1]", "+ xc += C[-1]", "+ xa %= a", "+ xb %= b", "+ xc %= c", "+ A.append((2 * A[-1]) % a)", "+ B.append((2 * B[-1]) % b)", "+ C.append((2 * C[-1]) % c)", "+ANS = []", "+for i in range(N):", "+ if X[i] == 1:", "+ ANS.append(1 + F[(xb - B[i]) % b])", "+ else:", "+ ANS.append(1 + F[(xc + C[i]) % c])", "+ANS.reverse()" ]
false
0.040123
4.170107
0.009622
[ "s002881970", "s809911169" ]
u089376182
p03281
python
s798438250
s713644731
22
19
3,060
3,060
Accepted
Accepted
13.64
n = int(eval(input())) counter = 0 for i in range(1, n+1): if i%2!=0 and len([j for j in range(1,i+1) if i%j==0])==8: counter += 1 print(counter)
n = int(eval(input())) ans = 0 for i in range(1, n+1, 2): counter = 0 for j in range(1, i+1): if i%j==0: counter += 1 if counter > 8: break if counter == 8: ans += 1 print(ans)
9
14
162
219
n = int(eval(input())) counter = 0 for i in range(1, n + 1): if i % 2 != 0 and len([j for j in range(1, i + 1) if i % j == 0]) == 8: counter += 1 print(counter)
n = int(eval(input())) ans = 0 for i in range(1, n + 1, 2): counter = 0 for j in range(1, i + 1): if i % j == 0: counter += 1 if counter > 8: break if counter == 8: ans += 1 print(ans)
false
35.714286
[ "-counter = 0", "-for i in range(1, n + 1):", "- if i % 2 != 0 and len([j for j in range(1, i + 1) if i % j == 0]) == 8:", "- counter += 1", "-print(counter)", "+ans = 0", "+for i in range(1, n + 1, 2):", "+ counter = 0", "+ for j in range(1, i + 1):", "+ if i % j == 0:", "+ counter += 1", "+ if counter > 8:", "+ break", "+ if counter == 8:", "+ ans += 1", "+print(ans)" ]
false
0.046857
0.045843
1.02211
[ "s798438250", "s713644731" ]
u903005414
p03274
python
s435635509
s810372180
596
324
23,080
23,108
Accepted
Accepted
45.64
import numpy as np N, K = list(map(int, input().split())) X = np.array(list(map(int, input().split()))) idx = np.searchsorted(X, 0) # print('idx', idx) ans = 10**10 for i in range(N - K + 1): l = i r = i + K - 1 d1 = np.abs(X[l]) + np.abs(X[r] - X[l]) d2 = np.abs(X[r]) + np.abs(X[r] - X[l]) d = min(d1, d2) ans = min(ans, d) print(ans)
import numpy as np N, K = list(map(int, input().split())) X = np.array(list(map(int, input().split()))) arr = X[K - 1:] - X[:-K + 1] arr1 = arr + np.abs(X[:-K + 1]) arr2 = arr + np.abs(X[K - 1:]) if len(arr) == 0: print((0)) else: ans = min(arr1.min(), arr2.min()) print(ans)
14
11
368
290
import numpy as np N, K = list(map(int, input().split())) X = np.array(list(map(int, input().split()))) idx = np.searchsorted(X, 0) # print('idx', idx) ans = 10**10 for i in range(N - K + 1): l = i r = i + K - 1 d1 = np.abs(X[l]) + np.abs(X[r] - X[l]) d2 = np.abs(X[r]) + np.abs(X[r] - X[l]) d = min(d1, d2) ans = min(ans, d) print(ans)
import numpy as np N, K = list(map(int, input().split())) X = np.array(list(map(int, input().split()))) arr = X[K - 1 :] - X[: -K + 1] arr1 = arr + np.abs(X[: -K + 1]) arr2 = arr + np.abs(X[K - 1 :]) if len(arr) == 0: print((0)) else: ans = min(arr1.min(), arr2.min()) print(ans)
false
21.428571
[ "-idx = np.searchsorted(X, 0)", "-# print('idx', idx)", "-ans = 10**10", "-for i in range(N - K + 1):", "- l = i", "- r = i + K - 1", "- d1 = np.abs(X[l]) + np.abs(X[r] - X[l])", "- d2 = np.abs(X[r]) + np.abs(X[r] - X[l])", "- d = min(d1, d2)", "- ans = min(ans, d)", "-print(ans)", "+arr = X[K - 1 :] - X[: -K + 1]", "+arr1 = arr + np.abs(X[: -K + 1])", "+arr2 = arr + np.abs(X[K - 1 :])", "+if len(arr) == 0:", "+ print((0))", "+else:", "+ ans = min(arr1.min(), arr2.min())", "+ print(ans)" ]
false
0.39148
0.167582
2.33605
[ "s435635509", "s810372180" ]
u934442292
p03252
python
s685374424
s320491966
57
52
3,632
9,640
Accepted
Accepted
8.77
import sys input = sys.stdin.readline def main(): S = input().rstrip() T = input().rstrip() S_table = {} T_table = {} ans = "Yes" for s, t in zip(S, T): # S if s in S_table: if S_table[s] != t: ans = "No" else: S_table[s] = t # T if t in T_table: if T_table[t] != s: ans = "No" else: T_table[t] = s print(ans) if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): S = input().rstrip() T = input().rstrip() c_S = Counter(S) c_T = Counter(T) count_S = list(c_S.values()) count_T = list(c_T.values()) count_S.sort() count_T.sort() is_same = True for s, t in zip(count_S, count_T): if s != t: is_same = False break ans = "Yes" if is_same else "No" print(ans) if __name__ == "__main__": main()
31
28
541
525
import sys input = sys.stdin.readline def main(): S = input().rstrip() T = input().rstrip() S_table = {} T_table = {} ans = "Yes" for s, t in zip(S, T): # S if s in S_table: if S_table[s] != t: ans = "No" else: S_table[s] = t # T if t in T_table: if T_table[t] != s: ans = "No" else: T_table[t] = s print(ans) if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): S = input().rstrip() T = input().rstrip() c_S = Counter(S) c_T = Counter(T) count_S = list(c_S.values()) count_T = list(c_T.values()) count_S.sort() count_T.sort() is_same = True for s, t in zip(count_S, count_T): if s != t: is_same = False break ans = "Yes" if is_same else "No" print(ans) if __name__ == "__main__": main()
false
9.677419
[ "+from collections import Counter", "- S_table = {}", "- T_table = {}", "- ans = \"Yes\"", "- for s, t in zip(S, T):", "- # S", "- if s in S_table:", "- if S_table[s] != t:", "- ans = \"No\"", "- else:", "- S_table[s] = t", "- # T", "- if t in T_table:", "- if T_table[t] != s:", "- ans = \"No\"", "- else:", "- T_table[t] = s", "+ c_S = Counter(S)", "+ c_T = Counter(T)", "+ count_S = list(c_S.values())", "+ count_T = list(c_T.values())", "+ count_S.sort()", "+ count_T.sort()", "+ is_same = True", "+ for s, t in zip(count_S, count_T):", "+ if s != t:", "+ is_same = False", "+ break", "+ ans = \"Yes\" if is_same else \"No\"" ]
false
0.044833
0.076277
0.587757
[ "s685374424", "s320491966" ]
u638795007
p03699
python
s173237141
s901555375
184
31
39,152
4,196
Accepted
Accepted
83.15
def examC(): N = I() s = [I() for _ in range(N)] is_trueScore = [False]*(max(s)*N+1) is_trueScore[0] = True ans = 0 for i in s: for j in range(max(s)*N,i-1,-1): if is_trueScore[j-i]==True: is_trueScore[j]=True for i in range(max(s)*N+1): if i%10!=0: if is_trueScore[i]: ans = i print(ans) import sys import copy import bisect import heapq from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float('inf') examC()
def examA(): N, M = LI() l = 1; r = N for _ in range(M): L, R = LI() l = max(L,l) r = min(R,r) ans = max(0,r-l+1) print(ans) return def examB(): N = I() S = [I()for _ in range(N)] rest = [] for s in S: if s%10==0: continue rest.append(s) if sum(S)%10==0: if not rest: print((0)) return ans = sum(S) - min(rest) else: ans = sum(S) print(ans) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int,readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return read().rstrip().decode('utf-8') global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examB() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
32
79
766
1,561
def examC(): N = I() s = [I() for _ in range(N)] is_trueScore = [False] * (max(s) * N + 1) is_trueScore[0] = True ans = 0 for i in s: for j in range(max(s) * N, i - 1, -1): if is_trueScore[j - i] == True: is_trueScore[j] = True for i in range(max(s) * N + 1): if i % 10 != 0: if is_trueScore[i]: ans = i print(ans) import sys import copy import bisect import heapq from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float("inf") examC()
def examA(): N, M = LI() l = 1 r = N for _ in range(M): L, R = LI() l = max(L, l) r = min(R, r) ans = max(0, r - l + 1) print(ans) return def examB(): N = I() S = [I() for _ in range(N)] rest = [] for s in S: if s % 10 == 0: continue rest.append(s) if sum(S) % 10 == 0: if not rest: print((0)) return ans = sum(S) - min(rest) else: ans = sum(S) print(ans) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int, readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return read().rstrip().decode("utf-8") global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examB() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
false
59.493671
[ "-def examC():", "- N = I()", "- s = [I() for _ in range(N)]", "- is_trueScore = [False] * (max(s) * N + 1)", "- is_trueScore[0] = True", "- ans = 0", "- for i in s:", "- for j in range(max(s) * N, i - 1, -1):", "- if is_trueScore[j - i] == True:", "- is_trueScore[j] = True", "- for i in range(max(s) * N + 1):", "- if i % 10 != 0:", "- if is_trueScore[i]:", "- ans = i", "+def examA():", "+ N, M = LI()", "+ l = 1", "+ r = N", "+ for _ in range(M):", "+ L, R = LI()", "+ l = max(L, l)", "+ r = min(R, r)", "+ ans = max(0, r - l + 1)", "+ return", "-import sys", "-import copy", "-import bisect", "-import heapq", "+def examB():", "+ N = I()", "+ S = [I() for _ in range(N)]", "+ rest = []", "+ for s in S:", "+ if s % 10 == 0:", "+ continue", "+ rest.append(s)", "+ if sum(S) % 10 == 0:", "+ if not rest:", "+ print((0))", "+ return", "+ ans = sum(S) - min(rest)", "+ else:", "+ ans = sum(S)", "+ print(ans)", "+ return", "+", "+", "+def examC():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examD():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examE():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+import sys, bisect, itertools, heapq, math, random", "+from copy import deepcopy", "+from heapq import heappop, heappush, heapify", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "- return int(sys.stdin.readline())", "+ return int(readline())", "- return list(map(int, sys.stdin.readline().split()))", "+ return list(map(int, readline().split()))", "+", "+", "+def LSI():", "+ return list(map(str, sys.stdin.readline().split()))", "-def S():", "- return sys.stdin.readline().strip()", "+def SI():", "+ return read().rstrip().decode(\"utf-8\")", "+global mod, mod2, inf, alphabet, _ep", "-inf = float(\"inf\")", "-examC()", "+mod2 = 998244353", "+inf = 10**18", "+_ep = 10 ** (-12)", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+sys.setrecursionlimit(10**7)", "+if __name__ == \"__main__\":", "+ examB()", "+\"\"\"", "+142", "+12 9 1445 0 1", "+asd dfg hj o o", "+aidn", "+\"\"\"" ]
false
0.042167
0.043701
0.964893
[ "s173237141", "s901555375" ]
u962718741
p03760
python
s666403876
s833069376
26
23
9,108
9,100
Accepted
Accepted
11.54
#!/usr/bin/env python3 def main(): a = input() b = input() for i in range(len(a)): print(a[i], end="") if i < len(b): print(b[i], end="") print() if __name__ == "__main__": main()
#!/usr/bin/env python3 def main(): a = list(input()) b = list(input()) + [""] for i in range(len(a)): print(a[i], end="") print(b[i], end="") if __name__ == "__main__": main()
14
12
244
222
#!/usr/bin/env python3 def main(): a = input() b = input() for i in range(len(a)): print(a[i], end="") if i < len(b): print(b[i], end="") print() if __name__ == "__main__": main()
#!/usr/bin/env python3 def main(): a = list(input()) b = list(input()) + [""] for i in range(len(a)): print(a[i], end="") print(b[i], end="") if __name__ == "__main__": main()
false
14.285714
[ "- a = input()", "- b = input()", "+ a = list(input())", "+ b = list(input()) + [\"\"]", "- if i < len(b):", "- print(b[i], end=\"\")", "- print()", "+ print(b[i], end=\"\")" ]
false
0.036701
0.037347
0.982699
[ "s666403876", "s833069376" ]
u704284486
p02659
python
s607789729
s012263701
23
20
9,160
9,156
Accepted
Accepted
13.04
a,b=input().split() a = int(a) b1,b2 = b.split('.') ans = a*(int(b1)*100+int(b2))//100 print(ans)
a,b = input().split() a = int(a) b = int(100*float(b)+0.5) print(((a*b)//100))
5
4
102
80
a, b = input().split() a = int(a) b1, b2 = b.split(".") ans = a * (int(b1) * 100 + int(b2)) // 100 print(ans)
a, b = input().split() a = int(a) b = int(100 * float(b) + 0.5) print(((a * b) // 100))
false
20
[ "-b1, b2 = b.split(\".\")", "-ans = a * (int(b1) * 100 + int(b2)) // 100", "-print(ans)", "+b = int(100 * float(b) + 0.5)", "+print(((a * b) // 100))" ]
false
0.111534
0.046702
2.388206
[ "s607789729", "s012263701" ]
u072717685
p02623
python
s416397279
s994918214
820
219
56,376
56,192
Accepted
Accepted
73.29
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = list(map(int, input().split())) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = a.cumsum() ba = b.cumsum() r = np.searchsorted(ba, k, side='right') for i1, aae in enumerate(aa): if k < aae: break r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1) print(r) if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = list(map(int, input().split())) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = np.zeros(n + 1, np.int64) ba = np.zeros(m + 1, np.int64) aa[1:] = a.cumsum() ba[1:] = b.cumsum() aa = aa[aa <= k] ba = ba[ba <= k] rs = np.searchsorted(ba, k - aa, side='right') - 1 rs += np.arange(len(aa)) r = rs.max() print(r) if __name__ == '__main__': main()
20
22
563
593
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = list(map(int, input().split())) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = a.cumsum() ba = b.cumsum() r = np.searchsorted(ba, k, side="right") for i1, aae in enumerate(aa): if k < aae: break r = max(r, np.searchsorted(ba, k - aae, side="right") + i1 + 1) print(r) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = list(map(int, input().split())) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = np.zeros(n + 1, np.int64) ba = np.zeros(m + 1, np.int64) aa[1:] = a.cumsum() ba[1:] = b.cumsum() aa = aa[aa <= k] ba = ba[ba <= k] rs = np.searchsorted(ba, k - aa, side="right") - 1 rs += np.arange(len(aa)) r = rs.max() print(r) if __name__ == "__main__": main()
false
9.090909
[ "- aa = a.cumsum()", "- ba = b.cumsum()", "- r = np.searchsorted(ba, k, side=\"right\")", "- for i1, aae in enumerate(aa):", "- if k < aae:", "- break", "- r = max(r, np.searchsorted(ba, k - aae, side=\"right\") + i1 + 1)", "+ aa = np.zeros(n + 1, np.int64)", "+ ba = np.zeros(m + 1, np.int64)", "+ aa[1:] = a.cumsum()", "+ ba[1:] = b.cumsum()", "+ aa = aa[aa <= k]", "+ ba = ba[ba <= k]", "+ rs = np.searchsorted(ba, k - aa, side=\"right\") - 1", "+ rs += np.arange(len(aa))", "+ r = rs.max()" ]
false
0.299176
0.382215
0.782742
[ "s416397279", "s994918214" ]
u761320129
p03039
python
s039669994
s989800041
360
276
28,344
34,084
Accepted
Accepted
23.33
N,M,K = list(map(int,input().split())) MOD = 10**9+7 a = 0 for i in range(N): j = N-1-i a += i*(i+1)//2 + j*(j+1)//2 b = 0 for i in range(M): j = M-1-i b += i*(i+1)//2 + j*(j+1)//2 MAX = N*M+5 fac = [1,1] + [0]*MAX finv = [1,1] + [0]*MAX inv = [0,1] + [0]*MAX for i in range(2,MAX+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def ncr(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD ans = (a * inv[N]**2 + b * inv[M]**2) * inv[N*M-1] * (N*M) ans *= K*(K-1)//2 ans *= ncr(N*M, K) print((ans % MOD))
N,M,K = list(map(int,input().split())) MOD = 10**9+7 MAXN = N*M+5 fac = [1,1] + [0]*MAXN finv = [1,1] + [0]*MAXN inv = [0,1] + [0]*MAXN for i in range(2,MAXN+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def comb(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD a = 0 for d in range(1,N): a += d*(N-d) * M*M b = 0 for d in range(1,M): b += d*(M-d) * N*N ans = (a+b) * comb(N*M-2, K-2) ans %= MOD print(ans)
31
26
680
575
N, M, K = list(map(int, input().split())) MOD = 10**9 + 7 a = 0 for i in range(N): j = N - 1 - i a += i * (i + 1) // 2 + j * (j + 1) // 2 b = 0 for i in range(M): j = M - 1 - i b += i * (i + 1) // 2 + j * (j + 1) // 2 MAX = N * M + 5 fac = [1, 1] + [0] * MAX finv = [1, 1] + [0] * MAX inv = [0, 1] + [0] * MAX for i in range(2, MAX + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def ncr(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD ans = (a * inv[N] ** 2 + b * inv[M] ** 2) * inv[N * M - 1] * (N * M) ans *= K * (K - 1) // 2 ans *= ncr(N * M, K) print((ans % MOD))
N, M, K = list(map(int, input().split())) MOD = 10**9 + 7 MAXN = N * M + 5 fac = [1, 1] + [0] * MAXN finv = [1, 1] + [0] * MAXN inv = [0, 1] + [0] * MAXN for i in range(2, MAXN + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def comb(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD a = 0 for d in range(1, N): a += d * (N - d) * M * M b = 0 for d in range(1, M): b += d * (M - d) * N * N ans = (a + b) * comb(N * M - 2, K - 2) ans %= MOD print(ans)
false
16.129032
[ "-a = 0", "-for i in range(N):", "- j = N - 1 - i", "- a += i * (i + 1) // 2 + j * (j + 1) // 2", "-b = 0", "-for i in range(M):", "- j = M - 1 - i", "- b += i * (i + 1) // 2 + j * (j + 1) // 2", "-MAX = N * M + 5", "-fac = [1, 1] + [0] * MAX", "-finv = [1, 1] + [0] * MAX", "-inv = [0, 1] + [0] * MAX", "-for i in range(2, MAX + 2):", "+MAXN = N * M + 5", "+fac = [1, 1] + [0] * MAXN", "+finv = [1, 1] + [0] * MAXN", "+inv = [0, 1] + [0] * MAXN", "+for i in range(2, MAXN + 2):", "-def ncr(n, r):", "+def comb(n, r):", "-ans = (a * inv[N] ** 2 + b * inv[M] ** 2) * inv[N * M - 1] * (N * M)", "-ans *= K * (K - 1) // 2", "-ans *= ncr(N * M, K)", "-print((ans % MOD))", "+a = 0", "+for d in range(1, N):", "+ a += d * (N - d) * M * M", "+b = 0", "+for d in range(1, M):", "+ b += d * (M - d) * N * N", "+ans = (a + b) * comb(N * M - 2, K - 2)", "+ans %= MOD", "+print(ans)" ]
false
0.053625
0.053026
1.011297
[ "s039669994", "s989800041" ]
u187058053
p02773
python
s637312369
s711280276
895
715
45,072
45,068
Accepted
Accepted
20.11
n = int(eval(input())) s = [eval(input()) for i in range(n)] import collections c = collections.Counter(s).most_common() fin = [c[0][0]] for j in range(1,len(c)): if c[j][1]==c[j-1][1]: fin.append(c[j][0]) continue break a = sorted(fin) for kekka in a: print(kekka)
n = int(eval(input())) s = [eval(input()) for i in range(n)] import collections c = collections.Counter(s).most_common() fin = [c[0][0]] for j in range(1,len(c)): if c[j][1]==c[j-1][1]: fin.append(c[j][0]) continue break for kekka in sorted(fin): print(kekka)
13
12
293
286
n = int(eval(input())) s = [eval(input()) for i in range(n)] import collections c = collections.Counter(s).most_common() fin = [c[0][0]] for j in range(1, len(c)): if c[j][1] == c[j - 1][1]: fin.append(c[j][0]) continue break a = sorted(fin) for kekka in a: print(kekka)
n = int(eval(input())) s = [eval(input()) for i in range(n)] import collections c = collections.Counter(s).most_common() fin = [c[0][0]] for j in range(1, len(c)): if c[j][1] == c[j - 1][1]: fin.append(c[j][0]) continue break for kekka in sorted(fin): print(kekka)
false
7.692308
[ "-a = sorted(fin)", "-for kekka in a:", "+for kekka in sorted(fin):" ]
false
0.090102
0.04228
2.131066
[ "s637312369", "s711280276" ]
u932868243
p02934
python
s801891420
s430692276
20
17
2,940
2,940
Accepted
Accepted
15
n=int(eval(input())) lista=list(map(int,input().split())) count=0 for a in lista: count+=1/a print((1/count))
n=int(eval(input())) l=list(map(int,input().split())) sum=0 for ll in l: sum+=1/ll print((1/sum))
6
6
108
96
n = int(eval(input())) lista = list(map(int, input().split())) count = 0 for a in lista: count += 1 / a print((1 / count))
n = int(eval(input())) l = list(map(int, input().split())) sum = 0 for ll in l: sum += 1 / ll print((1 / sum))
false
0
[ "-lista = list(map(int, input().split()))", "-count = 0", "-for a in lista:", "- count += 1 / a", "-print((1 / count))", "+l = list(map(int, input().split()))", "+sum = 0", "+for ll in l:", "+ sum += 1 / ll", "+print((1 / sum))" ]
false
0.048835
0.048661
1.003586
[ "s801891420", "s430692276" ]
u282228874
p03287
python
s805407095
s964468677
92
74
16,556
15,404
Accepted
Accepted
19.57
from collections import Counter n,m = list(map(int,input().split())) A = list(map(int,input().split())) B = [0] for a in A: B.append((B[-1]+a)%m) D = Counter(B) res = 0 for v in list(D.values()): res += v*(v-1)//2 print(res)
import collections,itertools n,m = list(map(int,input().split())) s = [0] s.extend(itertools.accumulate(list(map(int,input().split())))) s = collections.Counter(a%m for a in s) print((sum(v*(v-1)//2 for v in list(s.values()))))
11
6
231
213
from collections import Counter n, m = list(map(int, input().split())) A = list(map(int, input().split())) B = [0] for a in A: B.append((B[-1] + a) % m) D = Counter(B) res = 0 for v in list(D.values()): res += v * (v - 1) // 2 print(res)
import collections, itertools n, m = list(map(int, input().split())) s = [0] s.extend(itertools.accumulate(list(map(int, input().split())))) s = collections.Counter(a % m for a in s) print((sum(v * (v - 1) // 2 for v in list(s.values()))))
false
45.454545
[ "-from collections import Counter", "+import collections, itertools", "-A = list(map(int, input().split()))", "-B = [0]", "-for a in A:", "- B.append((B[-1] + a) % m)", "-D = Counter(B)", "-res = 0", "-for v in list(D.values()):", "- res += v * (v - 1) // 2", "-print(res)", "+s = [0]", "+s.extend(itertools.accumulate(list(map(int, input().split()))))", "+s = collections.Counter(a % m for a in s)", "+print((sum(v * (v - 1) // 2 for v in list(s.values()))))" ]
false
0.038924
0.036338
1.071153
[ "s805407095", "s964468677" ]
u596536048
p03105
python
s475161035
s111810570
34
29
8,956
9,140
Accepted
Accepted
14.71
A, B, C = list(map(int, input().split())) if B // A > C: print(C) else: print((B // A))
A, B, C = list(map(int, input().split())) print((C if B // A > C else B // A))
5
2
91
71
A, B, C = list(map(int, input().split())) if B // A > C: print(C) else: print((B // A))
A, B, C = list(map(int, input().split())) print((C if B // A > C else B // A))
false
60
[ "-if B // A > C:", "- print(C)", "-else:", "- print((B // A))", "+print((C if B // A > C else B // A))" ]
false
0.040052
0.041166
0.972939
[ "s475161035", "s111810570" ]
u530383736
p02598
python
s555045028
s642951492
1,958
1,402
32,372
32,712
Accepted
Accepted
28.4
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N,K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length :int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += (divide - 1) return (True if cnt <= K else False) L = 0.1 # the minimum length R = max(A_list) # the maximum length while (R - L) > 0.01: M = L + (R - L) / 2 if check(M): R = M else: L = M ans = float( Decimal(str(M)).quantize(Decimal('1E-1'), rounding=ROUND_HALF_UP) ) ans = -(-ans // 1) # round up print(( int(ans) )) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N,K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length :int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += (divide - 1) return (True if cnt <= K else False) L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
41
39
943
800
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N, K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length: int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += divide - 1 return True if cnt <= K else False L = 0.1 # the minimum length R = max(A_list) # the maximum length while (R - L) > 0.01: M = L + (R - L) / 2 if check(M): R = M else: L = M ans = float(Decimal(str(M)).quantize(Decimal("1E-1"), rounding=ROUND_HALF_UP)) ans = -(-ans // 1) # round up print((int(ans))) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N, K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length: int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += divide - 1 return True if cnt <= K else False L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
false
4.878049
[ "- L = 0.1 # the minimum length", "+ L = 0 # the minimum length", "- while (R - L) > 0.01:", "- M = L + (R - L) / 2", "+ while (R - L) > 1:", "+ M = L + (R - L) // 2", "- ans = float(Decimal(str(M)).quantize(Decimal(\"1E-1\"), rounding=ROUND_HALF_UP))", "- ans = -(-ans // 1) # round up", "- print((int(ans)))", "+ print(R)" ]
false
0.040779
0.101769
0.400702
[ "s555045028", "s642951492" ]
u226155577
p03390
python
s296078741
s910480163
178
18
38,384
3,064
Accepted
Accepted
89.89
from math import sqrt for i in range(int(eval(input()))): a, b = list(map(int, input().split())) if not a < b: a, b = b, a ans = (a-1)*2 + (a < b-1) c = int(sqrt(a*b)) if c**2 == a*b: c -= 1 if a < c: if (a*b) % c == 0: d = (a*b)//c - 1 else: d = a*b//c ans += (c - a) * 2 - (c==d) print(ans)
# seishin.py from math import sqrt Q = int(eval(input())) for i in range(Q): a, b = list(map(int, input().split())) if not a < b: a, b = b, a if a == b or a+1 == b: print((2*a-2)) continue c = int(sqrt(a*b)) if c**2 == a*b: c -= 1 if c*(c+1) >= a*b: print((2*c-2)) continue print((2*c-1))
18
17
392
362
from math import sqrt for i in range(int(eval(input()))): a, b = list(map(int, input().split())) if not a < b: a, b = b, a ans = (a - 1) * 2 + (a < b - 1) c = int(sqrt(a * b)) if c**2 == a * b: c -= 1 if a < c: if (a * b) % c == 0: d = (a * b) // c - 1 else: d = a * b // c ans += (c - a) * 2 - (c == d) print(ans)
# seishin.py from math import sqrt Q = int(eval(input())) for i in range(Q): a, b = list(map(int, input().split())) if not a < b: a, b = b, a if a == b or a + 1 == b: print((2 * a - 2)) continue c = int(sqrt(a * b)) if c**2 == a * b: c -= 1 if c * (c + 1) >= a * b: print((2 * c - 2)) continue print((2 * c - 1))
false
5.555556
[ "+# seishin.py", "-for i in range(int(eval(input()))):", "+Q = int(eval(input()))", "+for i in range(Q):", "- ans = (a - 1) * 2 + (a < b - 1)", "+ if a == b or a + 1 == b:", "+ print((2 * a - 2))", "+ continue", "- if a < c:", "- if (a * b) % c == 0:", "- d = (a * b) // c - 1", "- else:", "- d = a * b // c", "- ans += (c - a) * 2 - (c == d)", "- print(ans)", "+ if c * (c + 1) >= a * b:", "+ print((2 * c - 2))", "+ continue", "+ print((2 * c - 1))" ]
false
0.187176
0.044318
4.223429
[ "s296078741", "s910480163" ]
u731807761
p02580
python
s099483647
s919449422
1,188
1,054
123,028
120,736
Accepted
Accepted
11.28
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = list(map(int, input().split())) row.update([h]) col.update([w]) D.update([str(h) + str(w)]) # rmax = row.most_common(1) # cmax = col.most_common(1) # idx = str(rmax[0][0]) + str(cmax[0][0]) # p = D[idx] # ans = rmax[0][1] + cmax[0][1] - p rtmp = row.most_common(1)[0][1] ctmp = col.most_common(1)[0][1] rmax = [] cmax = [] for r in row.most_common(): if r[1] < rtmp: break rmax.append(r) for c in col.most_common(): if c[1] < ctmp: break cmax.append(c) ridx = str(rmax[0][0]) for d in cmax: if D[ridx + str(d[0])] == 0: ans = rmax[0][1] + d[1] break else: ans = rmax[0][1] + d[1] - 1 cidx = str(cmax[0][0]) for d in rmax: if D[str(d[0]) + cidx] == 0: ans2 = cmax[0][1] + d[1] break else: ans2 = cmax[0][1] + d[1] - 1 print((max(ans, ans2)))
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = input().split() row.update([h]) col.update([w]) D.update([h + w]) rtop = row.most_common(1)[0] ctop = col.most_common(1)[0] for c in col.most_common(): if c[1] < ctop[1]: break else: if D[rtop[0] + c[0]] == 0: ans = rtop[1] + c[1] break else: ans = rtop[1] + c[1] - 1 for r in row.most_common(): if r[1] < rtop[1]: break else: if D[r[0] + ctop[0]] == 0: ans2 = r[1] + ctop[1] break else: ans2 = r[1] + c[1] - 1 print((max(ans, ans2)))
59
45
1,133
872
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = list(map(int, input().split())) row.update([h]) col.update([w]) D.update([str(h) + str(w)]) # rmax = row.most_common(1) # cmax = col.most_common(1) # idx = str(rmax[0][0]) + str(cmax[0][0]) # p = D[idx] # ans = rmax[0][1] + cmax[0][1] - p rtmp = row.most_common(1)[0][1] ctmp = col.most_common(1)[0][1] rmax = [] cmax = [] for r in row.most_common(): if r[1] < rtmp: break rmax.append(r) for c in col.most_common(): if c[1] < ctmp: break cmax.append(c) ridx = str(rmax[0][0]) for d in cmax: if D[ridx + str(d[0])] == 0: ans = rmax[0][1] + d[1] break else: ans = rmax[0][1] + d[1] - 1 cidx = str(cmax[0][0]) for d in rmax: if D[str(d[0]) + cidx] == 0: ans2 = cmax[0][1] + d[1] break else: ans2 = cmax[0][1] + d[1] - 1 print((max(ans, ans2)))
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = input().split() row.update([h]) col.update([w]) D.update([h + w]) rtop = row.most_common(1)[0] ctop = col.most_common(1)[0] for c in col.most_common(): if c[1] < ctop[1]: break else: if D[rtop[0] + c[0]] == 0: ans = rtop[1] + c[1] break else: ans = rtop[1] + c[1] - 1 for r in row.most_common(): if r[1] < rtop[1]: break else: if D[r[0] + ctop[0]] == 0: ans2 = r[1] + ctop[1] break else: ans2 = r[1] + c[1] - 1 print((max(ans, ans2)))
false
23.728814
[ "- h, w = list(map(int, input().split()))", "+ h, w = input().split()", "- D.update([str(h) + str(w)])", "-# rmax = row.most_common(1)", "-# cmax = col.most_common(1)", "-# idx = str(rmax[0][0]) + str(cmax[0][0])", "-# p = D[idx]", "-# ans = rmax[0][1] + cmax[0][1] - p", "-rtmp = row.most_common(1)[0][1]", "-ctmp = col.most_common(1)[0][1]", "-rmax = []", "-cmax = []", "+ D.update([h + w])", "+rtop = row.most_common(1)[0]", "+ctop = col.most_common(1)[0]", "+for c in col.most_common():", "+ if c[1] < ctop[1]:", "+ break", "+ else:", "+ if D[rtop[0] + c[0]] == 0:", "+ ans = rtop[1] + c[1]", "+ break", "+ else:", "+ ans = rtop[1] + c[1] - 1", "- if r[1] < rtmp:", "+ if r[1] < rtop[1]:", "- rmax.append(r)", "-for c in col.most_common():", "- if c[1] < ctmp:", "- break", "- cmax.append(c)", "-ridx = str(rmax[0][0])", "-for d in cmax:", "- if D[ridx + str(d[0])] == 0:", "- ans = rmax[0][1] + d[1]", "- break", "-else:", "- ans = rmax[0][1] + d[1] - 1", "-cidx = str(cmax[0][0])", "-for d in rmax:", "- if D[str(d[0]) + cidx] == 0:", "- ans2 = cmax[0][1] + d[1]", "- break", "-else:", "- ans2 = cmax[0][1] + d[1] - 1", "+ else:", "+ if D[r[0] + ctop[0]] == 0:", "+ ans2 = r[1] + ctop[1]", "+ break", "+ else:", "+ ans2 = r[1] + c[1] - 1" ]
false
0.039773
0.040662
0.978144
[ "s099483647", "s919449422" ]
u930705402
p02766
python
s743144346
s030440558
63
19
6,328
3,060
Accepted
Accepted
69.84
import fractions import collections from collections import deque import math import itertools N,K=list(map(int,input().split())) i=1 P=K while(P<=N): i=i+1 P=P*K else: print(i)
def keta(n,k): cnt=0 while(n!=0): n//=k cnt+=1 return cnt N,K=list(map(int,input().split())) print((keta(N,K)))
14
9
197
140
import fractions import collections from collections import deque import math import itertools N, K = list(map(int, input().split())) i = 1 P = K while P <= N: i = i + 1 P = P * K else: print(i)
def keta(n, k): cnt = 0 while n != 0: n //= k cnt += 1 return cnt N, K = list(map(int, input().split())) print((keta(N, K)))
false
35.714286
[ "-import fractions", "-import collections", "-from collections import deque", "-import math", "-import itertools", "+def keta(n, k):", "+ cnt = 0", "+ while n != 0:", "+ n //= k", "+ cnt += 1", "+ return cnt", "+", "-i = 1", "-P = K", "-while P <= N:", "- i = i + 1", "- P = P * K", "-else:", "- print(i)", "+print((keta(N, K)))" ]
false
0.039034
0.089445
0.4364
[ "s743144346", "s030440558" ]
u729133443
p03734
python
s278696269
s492090805
216
29
41,072
3,064
Accepted
Accepted
86.57
I=lambda:list(map(int,input().split())) N,W=I() g={} for _ in[0]*N: a,b=I() g[a]=g.get(a,[])+[b] *w,=list(g.keys()) v=[] for i in range(len(w)): s=[0]+sorted(g[w[i]])[::-1] for i in range(1,len(s)): s[i]+=s[i-1] v.append(s) for i in range(len(w),4): w.append(10**18+i) v.append([0,10**18]) ans=0 for i in range(len(v[0])): s0=w[0]*i for j in range(len(v[1])): s1=s0+w[1]*j if s1>W:break for k in range(len(v[2])): s2=s1+w[2]*k if s2>W:break l=min((W-s2)//w[3],len(v[3])-1) ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l]) print(ans)
def solve(): I=lambda:list(map(int,input().split())) N,W=I() g={} for _ in[0]*N: a,b=I() g[a]=g.get(a,[])+[b] *w,=list(g.keys()) v=[] for i in range(len(w)): s=[0]+sorted(g[w[i]])[::-1] for i in range(1,len(s)): s[i]+=s[i-1] v.append(s) for _ in[0]*(4-len(w)): w.append(10**18) v.append([0]) ans=0 for i in range(len(v[0])): s0=w[0]*i for j in range(len(v[1])): s1=s0+w[1]*j if s1>W:break for k in range(len(v[2])): s2=s1+w[2]*k if s2>W:break l=min((W-s2)//w[3],len(v[3])-1) ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l]) print(ans) if __name__=='__main__': solve()
28
31
607
697
I = lambda: list(map(int, input().split())) N, W = I() g = {} for _ in [0] * N: a, b = I() g[a] = g.get(a, []) + [b] (*w,) = list(g.keys()) v = [] for i in range(len(w)): s = [0] + sorted(g[w[i]])[::-1] for i in range(1, len(s)): s[i] += s[i - 1] v.append(s) for i in range(len(w), 4): w.append(10**18 + i) v.append([0, 10**18]) ans = 0 for i in range(len(v[0])): s0 = w[0] * i for j in range(len(v[1])): s1 = s0 + w[1] * j if s1 > W: break for k in range(len(v[2])): s2 = s1 + w[2] * k if s2 > W: break l = min((W - s2) // w[3], len(v[3]) - 1) ans = max(ans, v[0][i] + v[1][j] + v[2][k] + v[3][l]) print(ans)
def solve(): I = lambda: list(map(int, input().split())) N, W = I() g = {} for _ in [0] * N: a, b = I() g[a] = g.get(a, []) + [b] (*w,) = list(g.keys()) v = [] for i in range(len(w)): s = [0] + sorted(g[w[i]])[::-1] for i in range(1, len(s)): s[i] += s[i - 1] v.append(s) for _ in [0] * (4 - len(w)): w.append(10**18) v.append([0]) ans = 0 for i in range(len(v[0])): s0 = w[0] * i for j in range(len(v[1])): s1 = s0 + w[1] * j if s1 > W: break for k in range(len(v[2])): s2 = s1 + w[2] * k if s2 > W: break l = min((W - s2) // w[3], len(v[3]) - 1) ans = max(ans, v[0][i] + v[1][j] + v[2][k] + v[3][l]) print(ans) if __name__ == "__main__": solve()
false
9.677419
[ "-I = lambda: list(map(int, input().split()))", "-N, W = I()", "-g = {}", "-for _ in [0] * N:", "- a, b = I()", "- g[a] = g.get(a, []) + [b]", "-(*w,) = list(g.keys())", "-v = []", "-for i in range(len(w)):", "- s = [0] + sorted(g[w[i]])[::-1]", "- for i in range(1, len(s)):", "- s[i] += s[i - 1]", "- v.append(s)", "-for i in range(len(w), 4):", "- w.append(10**18 + i)", "- v.append([0, 10**18])", "-ans = 0", "-for i in range(len(v[0])):", "- s0 = w[0] * i", "- for j in range(len(v[1])):", "- s1 = s0 + w[1] * j", "- if s1 > W:", "- break", "- for k in range(len(v[2])):", "- s2 = s1 + w[2] * k", "- if s2 > W:", "+def solve():", "+ I = lambda: list(map(int, input().split()))", "+ N, W = I()", "+ g = {}", "+ for _ in [0] * N:", "+ a, b = I()", "+ g[a] = g.get(a, []) + [b]", "+ (*w,) = list(g.keys())", "+ v = []", "+ for i in range(len(w)):", "+ s = [0] + sorted(g[w[i]])[::-1]", "+ for i in range(1, len(s)):", "+ s[i] += s[i - 1]", "+ v.append(s)", "+ for _ in [0] * (4 - len(w)):", "+ w.append(10**18)", "+ v.append([0])", "+ ans = 0", "+ for i in range(len(v[0])):", "+ s0 = w[0] * i", "+ for j in range(len(v[1])):", "+ s1 = s0 + w[1] * j", "+ if s1 > W:", "- l = min((W - s2) // w[3], len(v[3]) - 1)", "- ans = max(ans, v[0][i] + v[1][j] + v[2][k] + v[3][l])", "-print(ans)", "+ for k in range(len(v[2])):", "+ s2 = s1 + w[2] * k", "+ if s2 > W:", "+ break", "+ l = min((W - s2) // w[3], len(v[3]) - 1)", "+ ans = max(ans, v[0][i] + v[1][j] + v[2][k] + v[3][l])", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.04118
0.036817
1.1185
[ "s278696269", "s492090805" ]
u150984829
p00040
python
s109412919
s990126150
110
30
5,604
5,600
Accepted
Accepted
72.73
z='abcdefghijklmnopqrstuvwxyz' def f(x): for i in range(1,26,2): for j in range(26): a=''.join(z[(z.index(c)*i+j)%26]if c in z else c for c in x) if'that'in a or'this'in a:return a for _ in[0]*int(eval(input())):print((f(eval(input()))))
z='abcdefghijklmnopqrstuvwxyz' e=lambda x,i,j:z[(z.index(x)*i+j)%26] def f(): for i in range(1,26,2): for j in range(26): if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j) def g(x,y,s=0,t=1): q,r=x//y,x%y return g(y,r,t,s-q*t) if r else t for _ in[0]*int(eval(input())): s=eval(input()) a,b=f() h=g(26,a) print((''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s)))
7
14
239
422
z = "abcdefghijklmnopqrstuvwxyz" def f(x): for i in range(1, 26, 2): for j in range(26): a = "".join(z[(z.index(c) * i + j) % 26] if c in z else c for c in x) if "that" in a or "this" in a: return a for _ in [0] * int(eval(input())): print((f(eval(input()))))
z = "abcdefghijklmnopqrstuvwxyz" e = lambda x, i, j: z[(z.index(x) * i + j) % 26] def f(): for i in range(1, 26, 2): for j in range(26): if ( "".join(e(c, i, j) for c in "that") in s or "".join(e(c, i, j) for c in "this") in s ): return (i, j) def g(x, y, s=0, t=1): q, r = x // y, x % y return g(y, r, t, s - q * t) if r else t for _ in [0] * int(eval(input())): s = eval(input()) a, b = f() h = g(26, a) print(("".join(z[h * (z.index(c) - b) % 26] if c in z else c for c in s)))
false
50
[ "+e = lambda x, i, j: z[(z.index(x) * i + j) % 26]", "-def f(x):", "+def f():", "- a = \"\".join(z[(z.index(c) * i + j) % 26] if c in z else c for c in x)", "- if \"that\" in a or \"this\" in a:", "- return a", "+ if (", "+ \"\".join(e(c, i, j) for c in \"that\") in s", "+ or \"\".join(e(c, i, j) for c in \"this\") in s", "+ ):", "+ return (i, j)", "+", "+", "+def g(x, y, s=0, t=1):", "+ q, r = x // y, x % y", "+ return g(y, r, t, s - q * t) if r else t", "- print((f(eval(input()))))", "+ s = eval(input())", "+ a, b = f()", "+ h = g(26, a)", "+ print((\"\".join(z[h * (z.index(c) - b) % 26] if c in z else c for c in s)))" ]
false
0.043349
0.084629
0.512219
[ "s109412919", "s990126150" ]
u489959379
p03295
python
s179546150
s831592439
456
176
29,852
29,460
Accepted
Accepted
61.4
n, m = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1]) remove = ab[0][1] res = 1 for i in range(m): if remove <= ab[i][0]: res += 1 remove = ab[i][1] print(res)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) AB = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x:x[1]) res = 0 remove = -1 for a, b in AB: if remove <= a: res += 1 remove = b print(res) if __name__ == '__main__': resolve()
11
23
255
448
n, m = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1]) remove = ab[0][1] res = 1 for i in range(m): if remove <= ab[i][0]: res += 1 remove = ab[i][1] print(res)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) AB = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1]) res = 0 remove = -1 for a, b in AB: if remove <= a: res += 1 remove = b print(res) if __name__ == "__main__": resolve()
false
52.173913
[ "-n, m = list(map(int, input().split()))", "-ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1])", "-remove = ab[0][1]", "-res = 1", "-for i in range(m):", "- if remove <= ab[i][0]:", "- res += 1", "- remove = ab[i][1]", "-print(res)", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n, m = list(map(int, input().split()))", "+ AB = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1])", "+ res = 0", "+ remove = -1", "+ for a, b in AB:", "+ if remove <= a:", "+ res += 1", "+ remove = b", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.035874
0.037412
0.958907
[ "s179546150", "s831592439" ]
u644907318
p03951
python
s023344029
s063671814
170
85
38,384
61,872
Accepted
Accepted
50
N = int(eval(input())) s = input().strip() t = input().strip() ans = 2*N for i in range(N): if s[i:]==t[:N-i]: ans = N+i break print(ans)
N = int(eval(input())) s = input().strip() t = input().strip() k = 0 for i in range(1,N+1): if s[-i:]==t[:i]: k = i continue print((2*N-k))
9
9
159
159
N = int(eval(input())) s = input().strip() t = input().strip() ans = 2 * N for i in range(N): if s[i:] == t[: N - i]: ans = N + i break print(ans)
N = int(eval(input())) s = input().strip() t = input().strip() k = 0 for i in range(1, N + 1): if s[-i:] == t[:i]: k = i continue print((2 * N - k))
false
0
[ "-ans = 2 * N", "-for i in range(N):", "- if s[i:] == t[: N - i]:", "- ans = N + i", "- break", "-print(ans)", "+k = 0", "+for i in range(1, N + 1):", "+ if s[-i:] == t[:i]:", "+ k = i", "+ continue", "+print((2 * N - k))" ]
false
0.136277
0.046704
2.917899
[ "s023344029", "s063671814" ]
u969850098
p03044
python
s155144474
s987461967
577
416
42,948
47,840
Accepted
Accepted
27.9
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop def dijkstra(path, N, a): visited = [False] * N que = [(0, a)] heapify(que) # 始点aから各頂点への(距離, 頂点ID) dist = [-1] * N # 始点aから各頂点への距離 dist[a] = 0 # 始点aからaへの距離は0 while que: d, v = heappop(que) # 始点から最短距離の頂点を(確定ノード)を取り出す visited[v] = True # 確定フラグを立てる # 接続先ノードの情報を更新する for d, to in path[v]: cost = dist[v] + d if dist[to] < 0 or cost < dist[to]: dist[to] = cost if not visited[to]: heappush(que, (cost, to)) return dist def main(): N = int(eval(input())) path = [[] for _ in range(N)] for _ in range(N-1): u, v, w = list(map(int, readline().rstrip().split())) path[u-1].append((w, v-1)) path[v-1].append((w, u-1)) G = dijkstra(path, N, 0) for i in range(N): if G[i] % 2 == 0: print((0)) else: print((1)) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop def dijkstra(path, N, start): visited = [False] * N que = [(0, start)] heapify(que) # 始点aから各頂点への(距離, 頂点ID) dist = [-1] * N # 始点aから各頂点への距離 dist[start] = 0 # 始点aからaへの距離は0 while que: d, v = heappop(que) # 始点から最短距離の頂点を(確定ノード)を取り出す visited[v] = True # 確定フラグを立てる # 接続先ノードの情報を更新する for d, to in path[v]: cost = dist[v] + d if dist[to] < 0 or cost < dist[to]: dist[to] = cost if not visited[to]: heappush(que, (cost, to)) return dist def main(): N = int(readline()) path = [[] for _ in range(N)] for _ in range(N-1): u, v, w = list(map(int, readline().rstrip().split())) path[u-1].append((w, v-1)) path[v-1].append((w, u-1)) dist = dijkstra(path, N, 0) for d in dist: if d % 2 == 0: print((0)) else: print((1)) if __name__ == '__main__': main()
40
40
1,077
1,088
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop def dijkstra(path, N, a): visited = [False] * N que = [(0, a)] heapify(que) # 始点aから各頂点への(距離, 頂点ID) dist = [-1] * N # 始点aから各頂点への距離 dist[a] = 0 # 始点aからaへの距離は0 while que: d, v = heappop(que) # 始点から最短距離の頂点を(確定ノード)を取り出す visited[v] = True # 確定フラグを立てる # 接続先ノードの情報を更新する for d, to in path[v]: cost = dist[v] + d if dist[to] < 0 or cost < dist[to]: dist[to] = cost if not visited[to]: heappush(que, (cost, to)) return dist def main(): N = int(eval(input())) path = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, readline().rstrip().split())) path[u - 1].append((w, v - 1)) path[v - 1].append((w, u - 1)) G = dijkstra(path, N, 0) for i in range(N): if G[i] % 2 == 0: print((0)) else: print((1)) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop def dijkstra(path, N, start): visited = [False] * N que = [(0, start)] heapify(que) # 始点aから各頂点への(距離, 頂点ID) dist = [-1] * N # 始点aから各頂点への距離 dist[start] = 0 # 始点aからaへの距離は0 while que: d, v = heappop(que) # 始点から最短距離の頂点を(確定ノード)を取り出す visited[v] = True # 確定フラグを立てる # 接続先ノードの情報を更新する for d, to in path[v]: cost = dist[v] + d if dist[to] < 0 or cost < dist[to]: dist[to] = cost if not visited[to]: heappush(que, (cost, to)) return dist def main(): N = int(readline()) path = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, readline().rstrip().split())) path[u - 1].append((w, v - 1)) path[v - 1].append((w, u - 1)) dist = dijkstra(path, N, 0) for d in dist: if d % 2 == 0: print((0)) else: print((1)) if __name__ == "__main__": main()
false
0
[ "-def dijkstra(path, N, a):", "+def dijkstra(path, N, start):", "- que = [(0, a)]", "+ que = [(0, start)]", "- dist[a] = 0 # 始点aからaへの距離は0", "+ dist[start] = 0 # 始点aからaへの距離は0", "- N = int(eval(input()))", "+ N = int(readline())", "- G = dijkstra(path, N, 0)", "- for i in range(N):", "- if G[i] % 2 == 0:", "+ dist = dijkstra(path, N, 0)", "+ for d in dist:", "+ if d % 2 == 0:" ]
false
0.144401
0.0434
3.32719
[ "s155144474", "s987461967" ]
u987164499
p03449
python
s159244626
s341009901
150
17
12,424
3,060
Accepted
Accepted
88.67
from sys import stdin from itertools import combinations from math import factorial import numpy as np n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) lin = list(map(int,stdin.readline().rstrip().split())) ma = 0 for i in range(n): ma = max(sum(li[:i+1]+lin[i:]),ma) print(ma)
n = int(eval(input())) li = [list(map(int,input().split())) for _ in range(2)] ma = 0 for i in range(n): ma = max(ma,sum(li[0][:i+1])+sum(li[1][i:])) print(ma)
14
9
341
168
from sys import stdin from itertools import combinations from math import factorial import numpy as np n = int(stdin.readline().rstrip()) li = list(map(int, stdin.readline().rstrip().split())) lin = list(map(int, stdin.readline().rstrip().split())) ma = 0 for i in range(n): ma = max(sum(li[: i + 1] + lin[i:]), ma) print(ma)
n = int(eval(input())) li = [list(map(int, input().split())) for _ in range(2)] ma = 0 for i in range(n): ma = max(ma, sum(li[0][: i + 1]) + sum(li[1][i:])) print(ma)
false
35.714286
[ "-from sys import stdin", "-from itertools import combinations", "-from math import factorial", "-import numpy as np", "-", "-n = int(stdin.readline().rstrip())", "-li = list(map(int, stdin.readline().rstrip().split()))", "-lin = list(map(int, stdin.readline().rstrip().split()))", "+n = int(eval(input()))", "+li = [list(map(int, input().split())) for _ in range(2)]", "- ma = max(sum(li[: i + 1] + lin[i:]), ma)", "+ ma = max(ma, sum(li[0][: i + 1]) + sum(li[1][i:]))" ]
false
0.044033
0.039217
1.122814
[ "s159244626", "s341009901" ]
u968950181
p03076
python
s502741356
s284861104
188
167
38,256
38,256
Accepted
Accepted
11.17
from functools import reduce l = [int(eval(input())) for _ in range(5)] r = [10 if i % 10 == 0 else i % 10 for i in l] m = [i if i % 10 == 0 else i // 10 * 10 + 10 for i in l] print((sum(m) + min(r) - 10))
l = [int(eval(input())) for _ in range(5)] r = [10 if i % 10 == 0 else i % 10 for i in l] m = [i if i % 10 == 0 else i // 10 * 10 + 10 for i in l] print((sum(m) + min(r) - 10))
5
4
203
173
from functools import reduce l = [int(eval(input())) for _ in range(5)] r = [10 if i % 10 == 0 else i % 10 for i in l] m = [i if i % 10 == 0 else i // 10 * 10 + 10 for i in l] print((sum(m) + min(r) - 10))
l = [int(eval(input())) for _ in range(5)] r = [10 if i % 10 == 0 else i % 10 for i in l] m = [i if i % 10 == 0 else i // 10 * 10 + 10 for i in l] print((sum(m) + min(r) - 10))
false
20
[ "-from functools import reduce", "-" ]
false
0.058396
0.037229
1.568548
[ "s502741356", "s284861104" ]
u432853936
p02743
python
s263136106
s603573045
35
19
5,076
2,940
Accepted
Accepted
45.71
from decimal import Decimal import math a,b,c = list(map(int,input().split())) a = Decimal(a) b = Decimal(b) c = Decimal(c) if (a.sqrt() + b.sqrt()) < c.sqrt(): print("Yes") else: print("No")
a,b,c = list(map(int,input().split())) if c - a - b > 0 and 4*a*b < (c-a-b)**2: print("Yes") else: print("No")
12
5
217
127
from decimal import Decimal import math a, b, c = list(map(int, input().split())) a = Decimal(a) b = Decimal(b) c = Decimal(c) if (a.sqrt() + b.sqrt()) < c.sqrt(): print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2: print("Yes") else: print("No")
false
58.333333
[ "-from decimal import Decimal", "-import math", "-", "-a = Decimal(a)", "-b = Decimal(b)", "-c = Decimal(c)", "-if (a.sqrt() + b.sqrt()) < c.sqrt():", "+if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:" ]
false
0.036846
0.042035
0.876576
[ "s263136106", "s603573045" ]
u620868411
p03007
python
s561249804
s885603426
361
282
65,108
20,396
Accepted
Accepted
21.88
n = int(eval(input())) al = list(map(int, input().split())) if n==2: print((max(al)-min(al))) print((max(al),min(al))) exit() pos = [] neg = [] for a in al: if a>=0: pos.append(a) else: neg.append(a) pos.sort() neg.sort(reverse=True) res = [] if len(pos)==0: x = neg[0] for a in neg[1:]: res.append((x,a)) x -= a elif len(neg)==0: x = pos[0] for a in pos[1:-1]: res.append((x,a)) x -= a res.append((pos[-1],x)) x = pos[-1]-x else: p = pos[0] pos = pos[1:] x = neg[0] neg = neg[1:] for a in pos: res.append((x,a)) x -= a res.append((p,x)) x = p - x for a in neg: res.append((x,a)) x -= a print(x) for a,b in res: print((a,b))
n = int(eval(input())) al = list(map(int, input().split())) al.sort() if n==2: print((al[1]-al[0])) print((al[1],al[0])) exit() res = [] neg = [] pos = [] for a in al: if a>=0: pos.append(a) else: neg.append(a) if len(pos)==0: res.append((neg[-1],neg[-2])) pos.append(neg[-1]-neg[-2]) neg = neg[:-2] if len(neg)==0: res.append((pos[0],pos[1])) neg.append(pos[0]-pos[1]) pos = pos[2:] # len(pos)>0 and len(neg)>0 n = neg[0] for i in range(1,len(pos)): res.append((n,pos[i])) n = n - pos[i] p = pos[0] for i in range(1,len(neg)): res.append((p,neg[i])) p = p - neg[i] res.append((p,n)) print((p-n)) for x,y in res: print((x,y))
52
41
831
736
n = int(eval(input())) al = list(map(int, input().split())) if n == 2: print((max(al) - min(al))) print((max(al), min(al))) exit() pos = [] neg = [] for a in al: if a >= 0: pos.append(a) else: neg.append(a) pos.sort() neg.sort(reverse=True) res = [] if len(pos) == 0: x = neg[0] for a in neg[1:]: res.append((x, a)) x -= a elif len(neg) == 0: x = pos[0] for a in pos[1:-1]: res.append((x, a)) x -= a res.append((pos[-1], x)) x = pos[-1] - x else: p = pos[0] pos = pos[1:] x = neg[0] neg = neg[1:] for a in pos: res.append((x, a)) x -= a res.append((p, x)) x = p - x for a in neg: res.append((x, a)) x -= a print(x) for a, b in res: print((a, b))
n = int(eval(input())) al = list(map(int, input().split())) al.sort() if n == 2: print((al[1] - al[0])) print((al[1], al[0])) exit() res = [] neg = [] pos = [] for a in al: if a >= 0: pos.append(a) else: neg.append(a) if len(pos) == 0: res.append((neg[-1], neg[-2])) pos.append(neg[-1] - neg[-2]) neg = neg[:-2] if len(neg) == 0: res.append((pos[0], pos[1])) neg.append(pos[0] - pos[1]) pos = pos[2:] # len(pos)>0 and len(neg)>0 n = neg[0] for i in range(1, len(pos)): res.append((n, pos[i])) n = n - pos[i] p = pos[0] for i in range(1, len(neg)): res.append((p, neg[i])) p = p - neg[i] res.append((p, n)) print((p - n)) for x, y in res: print((x, y))
false
21.153846
[ "+al.sort()", "- print((max(al) - min(al)))", "- print((max(al), min(al)))", "+ print((al[1] - al[0]))", "+ print((al[1], al[0]))", "+res = []", "+neg = []", "-neg = []", "-pos.sort()", "-neg.sort(reverse=True)", "-res = []", "- x = neg[0]", "- for a in neg[1:]:", "- res.append((x, a))", "- x -= a", "-elif len(neg) == 0:", "- x = pos[0]", "- for a in pos[1:-1]:", "- res.append((x, a))", "- x -= a", "- res.append((pos[-1], x))", "- x = pos[-1] - x", "-else:", "- p = pos[0]", "- pos = pos[1:]", "- x = neg[0]", "- neg = neg[1:]", "- for a in pos:", "- res.append((x, a))", "- x -= a", "- res.append((p, x))", "- x = p - x", "- for a in neg:", "- res.append((x, a))", "- x -= a", "-print(x)", "-for a, b in res:", "- print((a, b))", "+ res.append((neg[-1], neg[-2]))", "+ pos.append(neg[-1] - neg[-2])", "+ neg = neg[:-2]", "+if len(neg) == 0:", "+ res.append((pos[0], pos[1]))", "+ neg.append(pos[0] - pos[1])", "+ pos = pos[2:]", "+# len(pos)>0 and len(neg)>0", "+n = neg[0]", "+for i in range(1, len(pos)):", "+ res.append((n, pos[i]))", "+ n = n - pos[i]", "+p = pos[0]", "+for i in range(1, len(neg)):", "+ res.append((p, neg[i]))", "+ p = p - neg[i]", "+res.append((p, n))", "+print((p - n))", "+for x, y in res:", "+ print((x, y))" ]
false
0.037347
0.041028
0.910277
[ "s561249804", "s885603426" ]
u312025627
p02639
python
s004770514
s580782904
66
32
61,648
8,836
Accepted
Accepted
51.52
def main(): A = [False]*5 B = [int(i) for i in input().split()] for b in B: if b == 0: continue A[b-1] = True for i, a in enumerate(A): if not a: print((i+1)) if __name__ == '__main__': main()
def main(): A = [int(i) for i in input().split()] B = [False]*5 for a in A: if a == 0: continue B[a-1] = True for i, b in enumerate(B): if not b: print((i+1)) break if __name__ == '__main__': main()
14
17
274
297
def main(): A = [False] * 5 B = [int(i) for i in input().split()] for b in B: if b == 0: continue A[b - 1] = True for i, a in enumerate(A): if not a: print((i + 1)) if __name__ == "__main__": main()
def main(): A = [int(i) for i in input().split()] B = [False] * 5 for a in A: if a == 0: continue B[a - 1] = True for i, b in enumerate(B): if not b: print((i + 1)) break if __name__ == "__main__": main()
false
17.647059
[ "- A = [False] * 5", "- B = [int(i) for i in input().split()]", "- for b in B:", "- if b == 0:", "+ A = [int(i) for i in input().split()]", "+ B = [False] * 5", "+ for a in A:", "+ if a == 0:", "- A[b - 1] = True", "- for i, a in enumerate(A):", "- if not a:", "+ B[a - 1] = True", "+ for i, b in enumerate(B):", "+ if not b:", "+ break" ]
false
0.124309
0.079103
1.571477
[ "s004770514", "s580782904" ]
u417220101
p03161
python
s153388094
s791157853
1,997
491
13,976
53,984
Accepted
Accepted
75.41
#atcoder https://atcoder.jp/contests/dp/tasks/dp_b def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[0] = 0 for i in range(1, N): dp[i] = min( dp[k] + abs(h[i]-h[k]) for k in range(max(i-K,0), i) ) print((dp[N-1])) main()
def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) N, K = MAP() h = LIST() INF = 10**23 dp = [INF] * N dp[0] = 0 for i in range(1, N): for j in range(1, K+1): if i - j < 0: continue dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j])) print((dp[-1]))
19
19
343
374
# atcoder https://atcoder.jp/contests/dp/tasks/dp_b def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[0] = 0 for i in range(1, N): dp[i] = min(dp[k] + abs(h[i] - h[k]) for k in range(max(i - K, 0), i)) print((dp[N - 1])) main()
def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) N, K = MAP() h = LIST() INF = 10**23 dp = [INF] * N dp[0] = 0 for i in range(1, N): for j in range(1, K + 1): if i - j < 0: continue dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])) print((dp[-1]))
false
0
[ "-# atcoder https://atcoder.jp/contests/dp/tasks/dp_b", "-def main():", "- N, K = list(map(int, input().split()))", "- h = list(map(int, input().split()))", "- dp = [0] * N", "- dp[0] = 0", "- for i in range(1, N):", "- dp[i] = min(dp[k] + abs(h[i] - h[k]) for k in range(max(i - K, 0), i))", "- print((dp[N - 1]))", "+def INT():", "+ return int(eval(input()))", "-main()", "+def MAP():", "+ return list(map(int, input().split()))", "+", "+", "+def LIST():", "+ return list(map(int, input().split()))", "+", "+", "+N, K = MAP()", "+h = LIST()", "+INF = 10**23", "+dp = [INF] * N", "+dp[0] = 0", "+for i in range(1, N):", "+ for j in range(1, K + 1):", "+ if i - j < 0:", "+ continue", "+ dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))", "+print((dp[-1]))" ]
false
0.040966
0.03727
1.099159
[ "s153388094", "s791157853" ]
u908984540
p02257
python
s731546874
s782585039
800
650
7,768
5,680
Accepted
Accepted
18.75
# -*- coding : utf-8 -*- import math def is_prime_number(num): if num == 2: return True if num < 2 or num % 2 == 0: return False i = 3 while i <= math.sqrt(num): if num % i == 0: return False i = i + 2 return True list_num = int(eval(input())) count_prime = 0 for i in range(list_num): num = int(eval(input())) if is_prime_number(num): count_prime = count_prime + 1 print(count_prime)
import math def is_prime(num): if num == 2: return True elif num < 2 or num % 2 == 0: return False else: i = 3 while i <= math.sqrt(num): if num % i == 0: return False i += 2 return True if __name__ == '__main__': n = int(eval(input())) prime_numbers = [] for i in range(n): num = int(eval(input())) if is_prime(num): prime_numbers.append(num) print((len(prime_numbers)))
23
27
477
522
# -*- coding : utf-8 -*- import math def is_prime_number(num): if num == 2: return True if num < 2 or num % 2 == 0: return False i = 3 while i <= math.sqrt(num): if num % i == 0: return False i = i + 2 return True list_num = int(eval(input())) count_prime = 0 for i in range(list_num): num = int(eval(input())) if is_prime_number(num): count_prime = count_prime + 1 print(count_prime)
import math def is_prime(num): if num == 2: return True elif num < 2 or num % 2 == 0: return False else: i = 3 while i <= math.sqrt(num): if num % i == 0: return False i += 2 return True if __name__ == "__main__": n = int(eval(input())) prime_numbers = [] for i in range(n): num = int(eval(input())) if is_prime(num): prime_numbers.append(num) print((len(prime_numbers)))
false
14.814815
[ "-# -*- coding : utf-8 -*-", "-def is_prime_number(num):", "+def is_prime(num):", "- if num < 2 or num % 2 == 0:", "+ elif num < 2 or num % 2 == 0:", "- i = 3", "- while i <= math.sqrt(num):", "- if num % i == 0:", "- return False", "- i = i + 2", "+ else:", "+ i = 3", "+ while i <= math.sqrt(num):", "+ if num % i == 0:", "+ return False", "+ i += 2", "-list_num = int(eval(input()))", "-count_prime = 0", "-for i in range(list_num):", "- num = int(eval(input()))", "- if is_prime_number(num):", "- count_prime = count_prime + 1", "-print(count_prime)", "+if __name__ == \"__main__\":", "+ n = int(eval(input()))", "+ prime_numbers = []", "+ for i in range(n):", "+ num = int(eval(input()))", "+ if is_prime(num):", "+ prime_numbers.append(num)", "+ print((len(prime_numbers)))" ]
false
0.112058
0.130524
0.858527
[ "s731546874", "s782585039" ]
u416758623
p03486
python
s645075505
s580890967
19
17
3,060
2,940
Accepted
Accepted
10.53
s = eval(input()) t = eval(input()) S = sorted(s) T = sorted(t,reverse=True) if S < T: print("Yes") else: print("No")
s = sorted(list(eval(input()))) t = sorted(list(eval(input())),reverse=True) s = "".join(s) t = "".join(t) if s < t: print("Yes") else: print("No")
8
9
120
152
s = eval(input()) t = eval(input()) S = sorted(s) T = sorted(t, reverse=True) if S < T: print("Yes") else: print("No")
s = sorted(list(eval(input()))) t = sorted(list(eval(input())), reverse=True) s = "".join(s) t = "".join(t) if s < t: print("Yes") else: print("No")
false
11.111111
[ "-s = eval(input())", "-t = eval(input())", "-S = sorted(s)", "-T = sorted(t, reverse=True)", "-if S < T:", "+s = sorted(list(eval(input())))", "+t = sorted(list(eval(input())), reverse=True)", "+s = \"\".join(s)", "+t = \"\".join(t)", "+if s < t:" ]
false
0.046365
0.047084
0.984739
[ "s645075505", "s580890967" ]
u622045059
p03087
python
s592764088
s697103348
559
330
32,756
16,308
Accepted
Accepted
40.97
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9+7 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def iin(): return int(eval(input())) #整数読み込み def ifn(): return float(eval(input())) #浮動小数点読み込み def isn(): return input().split() #文字列読み込み def imn(): return list(map(int, input().split())) #整数map取得 def fmn(): return list(map(float, input().split())) #浮動小数点map取得 def iln(): return list(map(int, input().split())) #整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得 def join(l, s=''): return s.join(l) #リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def m_add(a,b): return (a+b) % MOD N,Q = imn() S = eval(input()) lr = [iln() for _ in range(Q)] c = [0 for _ in range(N+1)] for i in range(N): c[i+1] = c[i] if i+1 < N and S[i] == 'A' and S[i+1] == 'C': c[i+1] += 1 for i in range(Q): left = lr[i][0]-1 right = lr[i][1]-1 print((c[right]-c[left]))
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9+7 INF = float('inf') #無限大 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def iin(): return int(sys.stdin.readline()) #整数読み込み def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み def isn(): return sys.stdin.readline().split() #文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=''): return s.join(l) #リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def m_add(a,b): return (a+b) % MOD def lprint(l): print(*l, sep='\n') N,Q = imn() S = input() L = [] R = [] for _ in range(Q): l,r = imn() L.append(l-1) R.append(r-1) s = [0 for _ in range(N+1)] for i in range(1, N+1): s[i] = s[i-1] if S[i-1:i+1] == 'AC': s[i] += 1 for i in range(Q): print(s[R[i]]-s[L[i]])
45
53
1,550
1,822
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(eval(input())) # 整数読み込み def ifn(): return float(eval(input())) # 浮動小数点読み込み def isn(): return input().split() # 文字列読み込み def imn(): return list(map(int, input().split())) # 整数map取得 def fmn(): return list(map(float, input().split())) # 浮動小数点map取得 def iln(): return list(map(int, input().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD N, Q = imn() S = eval(input()) lr = [iln() for _ in range(Q)] c = [0 for _ in range(N + 1)] for i in range(N): c[i + 1] = c[i] if i + 1 < N and S[i] == "A" and S[i + 1] == "C": c[i + 1] += 1 for i in range(Q): left = lr[i][0] - 1 right = lr[i][1] - 1 print((c[right] - c[left]))
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def lprint(l): print(*l, sep="\n") N, Q = imn() S = input() L = [] R = [] for _ in range(Q): l, r = imn() L.append(l - 1) R.append(r - 1) s = [0 for _ in range(N + 1)] for i in range(1, N + 1): s[i] = s[i - 1] if S[i - 1 : i + 1] == "AC": s[i] += 1 for i in range(Q): print(s[R[i]] - s[L[i]])
false
15.09434
[ "+# python3.4.2用", "+from decimal import *", "+INF = float(\"inf\") # 無限大", "- return int(eval(input())) # 整数読み込み", "+ return int(sys.stdin.readline()) # 整数読み込み", "- return float(eval(input())) # 浮動小数点読み込み", "+ return float(sys.stdin.readline()) # 浮動小数点読み込み", "- return input().split() # 文字列読み込み", "+ return sys.stdin.readline().split() # 文字列読み込み", "- return list(map(int, input().split())) # 整数map取得", "+ return map(int, sys.stdin.readline().split()) # 整数map取得", "+", "+", "+def imnn():", "+ return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得", "- return list(map(float, input().split())) # 浮動小数点map取得", "+ return map(float, sys.stdin.readline().split()) # 浮動小数点map取得", "- return list(map(int, input().split())) # 整数リスト取得", "+ return list(map(int, sys.stdin.readline().split())) # 整数リスト取得", "- return list(map(float, input().split())) # 浮動小数点リスト取得", "+ return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得", "+def lprint(l):", "+ print(*l, sep=\"\\n\")", "+", "+", "-S = eval(input())", "-lr = [iln() for _ in range(Q)]", "-c = [0 for _ in range(N + 1)]", "-for i in range(N):", "- c[i + 1] = c[i]", "- if i + 1 < N and S[i] == \"A\" and S[i + 1] == \"C\":", "- c[i + 1] += 1", "+S = input()", "+L = []", "+R = []", "+for _ in range(Q):", "+ l, r = imn()", "+ L.append(l - 1)", "+ R.append(r - 1)", "+s = [0 for _ in range(N + 1)]", "+for i in range(1, N + 1):", "+ s[i] = s[i - 1]", "+ if S[i - 1 : i + 1] == \"AC\":", "+ s[i] += 1", "- left = lr[i][0] - 1", "- right = lr[i][1] - 1", "- print((c[right] - c[left]))", "+ print(s[R[i]] - s[L[i]])" ]
false
0.050753
0.061466
0.825714
[ "s592764088", "s697103348" ]
u633068244
p00729
python
s438990738
s773856311
5,430
4,910
22,052
20,908
Accepted
Accepted
9.58
while 1: N,M = list(map(int,input().split())) if N == 0: break T = [[0]*1261 for i in range(N)] for i in range(eval(input())): t,n,m,s = list(map(int,input().split())) for ti in range(t,1261): T[n-1][ti] = s*m for i in range(eval(input())): ts,te,m = list(map(int,input().split())) print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))
while 1: N,M = list(map(int,input().split())) if N == 0: break T = [[0]*1261 for i in range(N)] r = eval(input()) tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1]) for i in range(0,r,2): t1,n,m,s = tnms[i] t2,n,m,s = tnms[i+1] T[n-1][t1:t2] = [m for j in range(t1,t2)] for i in range(eval(input())): ts,te,m = list(map(int,input().split())) print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))
12
14
373
472
while 1: N, M = list(map(int, input().split())) if N == 0: break T = [[0] * 1261 for i in range(N)] for i in range(eval(input())): t, n, m, s = list(map(int, input().split())) for ti in range(t, 1261): T[n - 1][ti] = s * m for i in range(eval(input())): ts, te, m = list(map(int, input().split())) print( sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts, te)) )
while 1: N, M = list(map(int, input().split())) if N == 0: break T = [[0] * 1261 for i in range(N)] r = eval(input()) tnms = sorted( [list(map(int, input().split())) for i in range(r)], key=lambda x: x[1] ) for i in range(0, r, 2): t1, n, m, s = tnms[i] t2, n, m, s = tnms[i + 1] T[n - 1][t1:t2] = [m for j in range(t1, t2)] for i in range(eval(input())): ts, te, m = list(map(int, input().split())) print( sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts, te)) )
false
14.285714
[ "- for i in range(eval(input())):", "- t, n, m, s = list(map(int, input().split()))", "- for ti in range(t, 1261):", "- T[n - 1][ti] = s * m", "+ r = eval(input())", "+ tnms = sorted(", "+ [list(map(int, input().split())) for i in range(r)], key=lambda x: x[1]", "+ )", "+ for i in range(0, r, 2):", "+ t1, n, m, s = tnms[i]", "+ t2, n, m, s = tnms[i + 1]", "+ T[n - 1][t1:t2] = [m for j in range(t1, t2)]" ]
false
0.044421
0.039934
1.11238
[ "s438990738", "s773856311" ]
u670180528
p03912
python
s084469666
s009604823
170
155
14,324
14,324
Accepted
Accepted
8.82
n,m,*X=list(map(int,open(0).read().split())) E=[0]*(max(X)+1) P=[0]*m M=[0]*m for x in X:E[x]+=1;M[x%m]+=1 for i,e in enumerate(E):P[i%m]+=e//2 ans=0 for i in range(m//2+1): if i==0 or i*2==m: ans+=M[i]//2 else: l=min(M[i],M[(m-i)%m]) ans+=l+min((M[i]-l)//2,P[i])+min((M[(m-i)%m]-l)//2,P[(m-i)%m]) print(ans)
n,m,*X=list(map(int,open(0).read().split())) E=[0]*(max(X)+1) P=[0]*m M=[0]*m for x in X:E[x]+=1;M[x%m]+=1 for i,e in enumerate(E):P[i%m]+=e//2 ans=0 min=lambda a,b: a if a<b else b for i in range(m//2+1): if i==0 or i*2==m: ans+=M[i]//2 else: l=min(M[i],M[(m-i)%m]) ans+=l+min((M[i]-l)//2,P[i])+min((M[(m-i)%m]-l)//2,P[(m-i)%m]) print(ans)
14
15
323
356
n, m, *X = list(map(int, open(0).read().split())) E = [0] * (max(X) + 1) P = [0] * m M = [0] * m for x in X: E[x] += 1 M[x % m] += 1 for i, e in enumerate(E): P[i % m] += e // 2 ans = 0 for i in range(m // 2 + 1): if i == 0 or i * 2 == m: ans += M[i] // 2 else: l = min(M[i], M[(m - i) % m]) ans += ( l + min((M[i] - l) // 2, P[i]) + min((M[(m - i) % m] - l) // 2, P[(m - i) % m]) ) print(ans)
n, m, *X = list(map(int, open(0).read().split())) E = [0] * (max(X) + 1) P = [0] * m M = [0] * m for x in X: E[x] += 1 M[x % m] += 1 for i, e in enumerate(E): P[i % m] += e // 2 ans = 0 min = lambda a, b: a if a < b else b for i in range(m // 2 + 1): if i == 0 or i * 2 == m: ans += M[i] // 2 else: l = min(M[i], M[(m - i) % m]) ans += ( l + min((M[i] - l) // 2, P[i]) + min((M[(m - i) % m] - l) // 2, P[(m - i) % m]) ) print(ans)
false
6.666667
[ "+min = lambda a, b: a if a < b else b" ]
false
0.041038
0.03916
1.047966
[ "s084469666", "s009604823" ]
u218834617
p02580
python
s444587857
s180237024
954
575
180,456
176,792
Accepted
Accepted
39.73
from collections import defaultdict as ddict ii=jj=0 ia,ja=[],[] rows=ddict(int) cols=ddict(int) H,W,M=list(map(int,input().split())) tgts=set() for _ in range(M): i,j=list(map(int,input().split())) tgts.add((i,j)) rows[i]+=1 cols[j]+=1 x=rows[i] if x>ii: ii=x ia=[i] elif x==ii: ia.append(i) y=cols[j] if y>jj: jj=y ja=[j] elif y==jj: ja.append(j) ans=0 for i in ia: for j in ja: k=rows[i]+cols[j] if (i,j) in tgts: k-=1 else: ans=k break ans=max(ans,k) print(ans)
from collections import defaultdict as ddict h,w,m=list(map(int,input().split())) xs=[0]*w ys=[0]*h xsmx=ysmx=0 pts=set() for _ in range(m): y,x=list(map(int,input().split())) x,y=x-1,y-1 xs[x]+=1 ys[y]+=1 pts.add((x,y)) xsmx=max(xsmx,xs[x]) ysmx=max(ysmx,ys[y]) xsc=[x for x in range(w) if xs[x]==xsmx] ysc=[y for y in range(h) if ys[y]==ysmx] ans=xsmx+ysmx-1 ok=False for y in ysc: for x in xsc: if (x,y) not in pts: ans+=1 ok=True break if ok: break print(ans)
41
31
660
574
from collections import defaultdict as ddict ii = jj = 0 ia, ja = [], [] rows = ddict(int) cols = ddict(int) H, W, M = list(map(int, input().split())) tgts = set() for _ in range(M): i, j = list(map(int, input().split())) tgts.add((i, j)) rows[i] += 1 cols[j] += 1 x = rows[i] if x > ii: ii = x ia = [i] elif x == ii: ia.append(i) y = cols[j] if y > jj: jj = y ja = [j] elif y == jj: ja.append(j) ans = 0 for i in ia: for j in ja: k = rows[i] + cols[j] if (i, j) in tgts: k -= 1 else: ans = k break ans = max(ans, k) print(ans)
from collections import defaultdict as ddict h, w, m = list(map(int, input().split())) xs = [0] * w ys = [0] * h xsmx = ysmx = 0 pts = set() for _ in range(m): y, x = list(map(int, input().split())) x, y = x - 1, y - 1 xs[x] += 1 ys[y] += 1 pts.add((x, y)) xsmx = max(xsmx, xs[x]) ysmx = max(ysmx, ys[y]) xsc = [x for x in range(w) if xs[x] == xsmx] ysc = [y for y in range(h) if ys[y] == ysmx] ans = xsmx + ysmx - 1 ok = False for y in ysc: for x in xsc: if (x, y) not in pts: ans += 1 ok = True break if ok: break print(ans)
false
24.390244
[ "-ii = jj = 0", "-ia, ja = [], []", "-rows = ddict(int)", "-cols = ddict(int)", "-H, W, M = list(map(int, input().split()))", "-tgts = set()", "-for _ in range(M):", "- i, j = list(map(int, input().split()))", "- tgts.add((i, j))", "- rows[i] += 1", "- cols[j] += 1", "- x = rows[i]", "- if x > ii:", "- ii = x", "- ia = [i]", "- elif x == ii:", "- ia.append(i)", "- y = cols[j]", "- if y > jj:", "- jj = y", "- ja = [j]", "- elif y == jj:", "- ja.append(j)", "-ans = 0", "-for i in ia:", "- for j in ja:", "- k = rows[i] + cols[j]", "- if (i, j) in tgts:", "- k -= 1", "- else:", "- ans = k", "+h, w, m = list(map(int, input().split()))", "+xs = [0] * w", "+ys = [0] * h", "+xsmx = ysmx = 0", "+pts = set()", "+for _ in range(m):", "+ y, x = list(map(int, input().split()))", "+ x, y = x - 1, y - 1", "+ xs[x] += 1", "+ ys[y] += 1", "+ pts.add((x, y))", "+ xsmx = max(xsmx, xs[x])", "+ ysmx = max(ysmx, ys[y])", "+xsc = [x for x in range(w) if xs[x] == xsmx]", "+ysc = [y for y in range(h) if ys[y] == ysmx]", "+ans = xsmx + ysmx - 1", "+ok = False", "+for y in ysc:", "+ for x in xsc:", "+ if (x, y) not in pts:", "+ ans += 1", "+ ok = True", "- ans = max(ans, k)", "+ if ok:", "+ break" ]
false
0.041809
0.040975
1.020377
[ "s444587857", "s180237024" ]
u313111801
p02994
python
s387102211
s640617939
29
26
9,176
9,172
Accepted
Accepted
10.34
N,L=list(map(int,input().split())) v=[L+i for i in range(N)] s=sum(v) ans=10**9 for i in range(N): if abs(s-(s-v[i]))<abs(s-ans): ans=s-v[i] print(ans)
N,L=list(map(int,input().split())) v=[L+i for i in range(N)] ans=sum(v)-min(v,key=abs) print(ans)
8
4
164
94
N, L = list(map(int, input().split())) v = [L + i for i in range(N)] s = sum(v) ans = 10**9 for i in range(N): if abs(s - (s - v[i])) < abs(s - ans): ans = s - v[i] print(ans)
N, L = list(map(int, input().split())) v = [L + i for i in range(N)] ans = sum(v) - min(v, key=abs) print(ans)
false
50
[ "-s = sum(v)", "-ans = 10**9", "-for i in range(N):", "- if abs(s - (s - v[i])) < abs(s - ans):", "- ans = s - v[i]", "+ans = sum(v) - min(v, key=abs)" ]
false
0.036315
0.036251
1.001766
[ "s387102211", "s640617939" ]
u395202850
p02732
python
s708943165
s783994011
320
281
26,140
26,140
Accepted
Accepted
12.19
import math import sys readline = sys.stdin.readline def main(): # input n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) B = [0] * n for a in A: B[a - 1] += 1 total = 0 for b in B: if b > 1: total += b * (b - 1) // 2 C = [0] * n for i, b in enumerate(B): C[i] = total + (b - 1) * (b - 2) // 2 - (b) * (b - 1) // 2 for a in A: print((C[a-1])) if __name__ == '__main__': main()
import math import sys readline = sys.stdin.readline def main(): # input n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) B = [0] * n for a in A: B[a - 1] += 1 total = 0 for b in B: if b > 1: total += b * (b - 1) // 2 C = [0] * n for i, b in enumerate(B): C[i] = total - b + 1 for a in A: print((C[a-1])) if __name__ == '__main__': main()
29
29
527
489
import math import sys readline = sys.stdin.readline def main(): # input n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) B = [0] * n for a in A: B[a - 1] += 1 total = 0 for b in B: if b > 1: total += b * (b - 1) // 2 C = [0] * n for i, b in enumerate(B): C[i] = total + (b - 1) * (b - 2) // 2 - (b) * (b - 1) // 2 for a in A: print((C[a - 1])) if __name__ == "__main__": main()
import math import sys readline = sys.stdin.readline def main(): # input n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) B = [0] * n for a in A: B[a - 1] += 1 total = 0 for b in B: if b > 1: total += b * (b - 1) // 2 C = [0] * n for i, b in enumerate(B): C[i] = total - b + 1 for a in A: print((C[a - 1])) if __name__ == "__main__": main()
false
0
[ "- C[i] = total + (b - 1) * (b - 2) // 2 - (b) * (b - 1) // 2", "+ C[i] = total - b + 1" ]
false
0.042574
0.043253
0.984304
[ "s708943165", "s783994011" ]
u655761160
p03680
python
s675308481
s828388581
194
53
7,084
7,068
Accepted
Accepted
72.68
N = int(eval(input())) a = [int(eval(input())) for i in range(N)] isFound = False ai = 1 for i in range(1, N + 1): ai = a[ai - 1] # print(f'a{i} = {ai}') if (ai == 2): isFound = True print(i) break if (isFound is False): print((-1))
import sys N = list(map(int, sys.stdin)) bot = N[1] for i in range(N[0]): if bot == 2: print((i+1)) break bot = N[bot] else: print((-1))
13
12
270
174
N = int(eval(input())) a = [int(eval(input())) for i in range(N)] isFound = False ai = 1 for i in range(1, N + 1): ai = a[ai - 1] # print(f'a{i} = {ai}') if ai == 2: isFound = True print(i) break if isFound is False: print((-1))
import sys N = list(map(int, sys.stdin)) bot = N[1] for i in range(N[0]): if bot == 2: print((i + 1)) break bot = N[bot] else: print((-1))
false
7.692308
[ "-N = int(eval(input()))", "-a = [int(eval(input())) for i in range(N)]", "-isFound = False", "-ai = 1", "-for i in range(1, N + 1):", "- ai = a[ai - 1]", "- # print(f'a{i} = {ai}')", "- if ai == 2:", "- isFound = True", "- print(i)", "+import sys", "+", "+N = list(map(int, sys.stdin))", "+bot = N[1]", "+for i in range(N[0]):", "+ if bot == 2:", "+ print((i + 1))", "-if isFound is False:", "+ bot = N[bot]", "+else:" ]
false
0.082203
0.077622
1.059022
[ "s675308481", "s828388581" ]
u753803401
p03476
python
s297497062
s419135830
929
423
4,212
65,500
Accepted
Accepted
54.47
import bisect a = [True] * 100001 a[0] = False a[1] = False p = [] for i in range(2, 100001): if a[i]: for j in range(i * 2, 100001, i): if a[j]: a[j] = False if i % 2 != 0 and a[(i + 1) // 2]: p.append(i) q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))
def slove(): import sys input = sys.stdin.readline pl = {} p = [True] * (10 ** 5 + 1) p[0] = False p[1] = False cnt = 0 pll = [0] * (10 ** 5 + 1) for i in range(2, len(p)): if p[i]: pl[i] = 1 for j in range(i, len(p), i): p[j] = False if i % 2 != 0: if (i + 1) // 2 in pl and i in pl: cnt += 1 pll[i] = cnt q = int(input().rstrip('\n')) lr = [list(map(int, input().rstrip('\n').split())) for _ in range(q)] for l, r in lr: print((pll[r] - pll[l-1])) if __name__ == '__main__': slove()
16
26
418
662
import bisect a = [True] * 100001 a[0] = False a[1] = False p = [] for i in range(2, 100001): if a[i]: for j in range(i * 2, 100001, i): if a[j]: a[j] = False if i % 2 != 0 and a[(i + 1) // 2]: p.append(i) q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))
def slove(): import sys input = sys.stdin.readline pl = {} p = [True] * (10**5 + 1) p[0] = False p[1] = False cnt = 0 pll = [0] * (10**5 + 1) for i in range(2, len(p)): if p[i]: pl[i] = 1 for j in range(i, len(p), i): p[j] = False if i % 2 != 0: if (i + 1) // 2 in pl and i in pl: cnt += 1 pll[i] = cnt q = int(input().rstrip("\n")) lr = [list(map(int, input().rstrip("\n").split())) for _ in range(q)] for l, r in lr: print((pll[r] - pll[l - 1])) if __name__ == "__main__": slove()
false
38.461538
[ "-import bisect", "+def slove():", "+ import sys", "-a = [True] * 100001", "-a[0] = False", "-a[1] = False", "-p = []", "-for i in range(2, 100001):", "- if a[i]:", "- for j in range(i * 2, 100001, i):", "- if a[j]:", "- a[j] = False", "- if i % 2 != 0 and a[(i + 1) // 2]:", "- p.append(i)", "-q = int(eval(input()))", "-for i in range(q):", "- l, r = list(map(int, input().split()))", "- print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))", "+ input = sys.stdin.readline", "+ pl = {}", "+ p = [True] * (10**5 + 1)", "+ p[0] = False", "+ p[1] = False", "+ cnt = 0", "+ pll = [0] * (10**5 + 1)", "+ for i in range(2, len(p)):", "+ if p[i]:", "+ pl[i] = 1", "+ for j in range(i, len(p), i):", "+ p[j] = False", "+ if i % 2 != 0:", "+ if (i + 1) // 2 in pl and i in pl:", "+ cnt += 1", "+ pll[i] = cnt", "+ q = int(input().rstrip(\"\\n\"))", "+ lr = [list(map(int, input().rstrip(\"\\n\").split())) for _ in range(q)]", "+ for l, r in lr:", "+ print((pll[r] - pll[l - 1]))", "+", "+", "+if __name__ == \"__main__\":", "+ slove()" ]
false
0.191694
0.129029
1.485665
[ "s297497062", "s419135830" ]
u930705402
p02756
python
s739887254
s849427727
1,829
494
93,784
12,272
Accepted
Accepted
72.99
from collections import deque S=input() d=deque(S) rev=False Q=int(input()) for i in range(Q): Que=input() if(Que=='1'): rev=True if not rev else False else: T,F,C=map(str,Que.split()) if(F=='1'): if(not rev): d.appendleft(C) else: d.append(C) elif(F=='2'): if(not rev): d.append(C) else: d.appendleft(C) if(not rev): for i in range(len(d)): print(d[i],end='') else: for i in reversed(range(len(d))): print(d[i],end='')
from collections import deque S=input() d=deque(S) rev=False Q=int(input()) for i in range(Q): Que=input().split() if(Que[0]=='1'): rev=not rev else: if(Que[1]=='1'): if(not rev): d.appendleft(Que[2]) else: d.append(Que[2]) else: if(not rev): d.append(Que[2]) else: d.appendleft(Que[2]) d=d if not rev else reversed(d) print(*d,sep='')
27
22
626
505
from collections import deque S = input() d = deque(S) rev = False Q = int(input()) for i in range(Q): Que = input() if Que == "1": rev = True if not rev else False else: T, F, C = map(str, Que.split()) if F == "1": if not rev: d.appendleft(C) else: d.append(C) elif F == "2": if not rev: d.append(C) else: d.appendleft(C) if not rev: for i in range(len(d)): print(d[i], end="") else: for i in reversed(range(len(d))): print(d[i], end="")
from collections import deque S = input() d = deque(S) rev = False Q = int(input()) for i in range(Q): Que = input().split() if Que[0] == "1": rev = not rev else: if Que[1] == "1": if not rev: d.appendleft(Que[2]) else: d.append(Que[2]) else: if not rev: d.append(Que[2]) else: d.appendleft(Que[2]) d = d if not rev else reversed(d) print(*d, sep="")
false
18.518519
[ "- Que = input()", "- if Que == \"1\":", "- rev = True if not rev else False", "+ Que = input().split()", "+ if Que[0] == \"1\":", "+ rev = not rev", "- T, F, C = map(str, Que.split())", "- if F == \"1\":", "+ if Que[1] == \"1\":", "- d.appendleft(C)", "+ d.appendleft(Que[2])", "- d.append(C)", "- elif F == \"2\":", "+ d.append(Que[2])", "+ else:", "- d.append(C)", "+ d.append(Que[2])", "- d.appendleft(C)", "-if not rev:", "- for i in range(len(d)):", "- print(d[i], end=\"\")", "-else:", "- for i in reversed(range(len(d))):", "- print(d[i], end=\"\")", "+ d.appendleft(Que[2])", "+d = d if not rev else reversed(d)", "+print(*d, sep=\"\")" ]
false
0.140377
0.117643
1.193253
[ "s739887254", "s849427727" ]
u244493040
p02396
python
s556306359
s034465468
160
140
5,600
5,592
Accepted
Accepted
12.5
i = 1 while True: x = int(eval(input())) if x == 0: break print(("Case {}: {}".format(i, x))) i+=1
i = 1 while True: x = int(eval(input())) if not x: break print(("Case {}: {}".format(i, x))) i+=1
6
6
104
103
i = 1 while True: x = int(eval(input())) if x == 0: break print(("Case {}: {}".format(i, x))) i += 1
i = 1 while True: x = int(eval(input())) if not x: break print(("Case {}: {}".format(i, x))) i += 1
false
0
[ "- if x == 0:", "+ if not x:" ]
false
0.04415
0.042606
1.036248
[ "s556306359", "s034465468" ]
u227550284
p02693
python
s007418406
s464724603
23
21
9,172
8,968
Accepted
Accepted
8.7
import sys input = sys.stdin.readline def main(): n = int(eval(input())) a, b = list(map(int, input().split())) flag = False for i in range(a,b+1): if i % n == 0: flag = True break if flag: print('OK') else: print('NG') if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): k = int(eval(input())) a, b = list(map(int, input().split())) largest = (b // k) * k if a <= largest: print('OK') else: print('NG') if __name__ == '__main__': main()
19
16
339
263
import sys input = sys.stdin.readline def main(): n = int(eval(input())) a, b = list(map(int, input().split())) flag = False for i in range(a, b + 1): if i % n == 0: flag = True break if flag: print("OK") else: print("NG") if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): k = int(eval(input())) a, b = list(map(int, input().split())) largest = (b // k) * k if a <= largest: print("OK") else: print("NG") if __name__ == "__main__": main()
false
15.789474
[ "- n = int(eval(input()))", "+ k = int(eval(input()))", "- flag = False", "- for i in range(a, b + 1):", "- if i % n == 0:", "- flag = True", "- break", "- if flag:", "+ largest = (b // k) * k", "+ if a <= largest:" ]
false
0.038671
0.049066
0.788141
[ "s007418406", "s464724603" ]
u827885761
p03006
python
s132762550
s607004817
25
23
3,948
3,956
Accepted
Accepted
8
import sys import itertools import collections sys.setrecursionlimit(10**7) def lmi(): return list(map(int, input().split())) n = int(eval(input())) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = lmi() d = [[0 for j in range(n)] for i in range(n)] for i in range(n): for j in range(n): d[i][j] = (x[i]-x[j], y[i]-y[j]) dd = [] for i in range(n): dd += d[i] c = collections.Counter(dd) c1 = c.most_common()[0] if c1[0] == (0,0) and n != 1: c1 = c.most_common()[1] print((n-c1[1])) else: print((1))
import sys import itertools import collections sys.setrecursionlimit(10**7) def lmi(): return list(map(int, input().split())) n = int(eval(input())) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = lmi() d = [] for i in range(n): for j in range(n): d.append((x[i]-x[j], y[i]-y[j])) c = collections.Counter(d) if n != 1: c1 = c.most_common()[1] print((n - c1[1])) else: print((1))
28
23
559
430
import sys import itertools import collections sys.setrecursionlimit(10**7) def lmi(): return list(map(int, input().split())) n = int(eval(input())) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = lmi() d = [[0 for j in range(n)] for i in range(n)] for i in range(n): for j in range(n): d[i][j] = (x[i] - x[j], y[i] - y[j]) dd = [] for i in range(n): dd += d[i] c = collections.Counter(dd) c1 = c.most_common()[0] if c1[0] == (0, 0) and n != 1: c1 = c.most_common()[1] print((n - c1[1])) else: print((1))
import sys import itertools import collections sys.setrecursionlimit(10**7) def lmi(): return list(map(int, input().split())) n = int(eval(input())) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = lmi() d = [] for i in range(n): for j in range(n): d.append((x[i] - x[j], y[i] - y[j])) c = collections.Counter(d) if n != 1: c1 = c.most_common()[1] print((n - c1[1])) else: print((1))
false
17.857143
[ "-d = [[0 for j in range(n)] for i in range(n)]", "+d = []", "- d[i][j] = (x[i] - x[j], y[i] - y[j])", "-dd = []", "-for i in range(n):", "- dd += d[i]", "-c = collections.Counter(dd)", "-c1 = c.most_common()[0]", "-if c1[0] == (0, 0) and n != 1:", "+ d.append((x[i] - x[j], y[i] - y[j]))", "+c = collections.Counter(d)", "+if n != 1:" ]
false
0.127985
0.047388
2.700806
[ "s132762550", "s607004817" ]
u762420987
p03469
python
s502854208
s290091292
18
16
2,940
2,940
Accepted
Accepted
11.11
S = list(eval(input())) S[3] = "8" print(("".join(S)))
print((input().replace("2017", "2018")))
3
1
48
38
S = list(eval(input())) S[3] = "8" print(("".join(S)))
print((input().replace("2017", "2018")))
false
66.666667
[ "-S = list(eval(input()))", "-S[3] = \"8\"", "-print((\"\".join(S)))", "+print((input().replace(\"2017\", \"2018\")))" ]
false
0.035624
0.035764
0.996092
[ "s502854208", "s290091292" ]
u573754721
p02953
python
s338623430
s728029515
71
64
14,224
14,252
Accepted
Accepted
9.86
n = int(eval(input())) L = list(map(int,input().split())) for i in range(n-1,0,-1): if L[i]<L[i-1]: L[i-1]-=1 if L[i]<L[i-1]: print("No") exit() print("Yes")
n=int(eval(input())) L=list(map(int,input().split())) L=L[::-1] pre=L[0] for i in range(1,n): if L[i]>pre: if L[i]-1>pre: print("No") exit() else: pre=L[i]-1 else: pre = L[i] print("Yes")
11
16
240
300
n = int(eval(input())) L = list(map(int, input().split())) for i in range(n - 1, 0, -1): if L[i] < L[i - 1]: L[i - 1] -= 1 if L[i] < L[i - 1]: print("No") exit() print("Yes")
n = int(eval(input())) L = list(map(int, input().split())) L = L[::-1] pre = L[0] for i in range(1, n): if L[i] > pre: if L[i] - 1 > pre: print("No") exit() else: pre = L[i] - 1 else: pre = L[i] print("Yes")
false
31.25
[ "-for i in range(n - 1, 0, -1):", "- if L[i] < L[i - 1]:", "- L[i - 1] -= 1", "- if L[i] < L[i - 1]:", "+L = L[::-1]", "+pre = L[0]", "+for i in range(1, n):", "+ if L[i] > pre:", "+ if L[i] - 1 > pre:", "+ else:", "+ pre = L[i] - 1", "+ else:", "+ pre = L[i]" ]
false
0.070824
0.044083
1.606606
[ "s338623430", "s728029515" ]
u979552932
p04025
python
s162177788
s308537328
23
17
2,940
2,940
Accepted
Accepted
26.09
import sys n = int(eval(input())) a = list(map(int, input().split())) m = sys.maxsize for x in range(min(a), max(a) + 1): b = sum([(x - y) ** 2 for y in a]) if m > b: m = b print(m)
n = int(eval(input())) a = list(map(int, input().split())) b = round(sum([0 + x for x in a]) / n) m = sum([(x - b) ** 2 for x in a]) print(m)
10
5
201
139
import sys n = int(eval(input())) a = list(map(int, input().split())) m = sys.maxsize for x in range(min(a), max(a) + 1): b = sum([(x - y) ** 2 for y in a]) if m > b: m = b print(m)
n = int(eval(input())) a = list(map(int, input().split())) b = round(sum([0 + x for x in a]) / n) m = sum([(x - b) ** 2 for x in a]) print(m)
false
50
[ "-import sys", "-", "-m = sys.maxsize", "-for x in range(min(a), max(a) + 1):", "- b = sum([(x - y) ** 2 for y in a])", "- if m > b:", "- m = b", "+b = round(sum([0 + x for x in a]) / n)", "+m = sum([(x - b) ** 2 for x in a])" ]
false
0.04589
0.039338
1.166574
[ "s162177788", "s308537328" ]
u600402037
p03031
python
s209496790
s084167858
45
26
3,064
3,064
Accepted
Accepted
42.22
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() lights = [lr() for _ in range(M)] P = lr() answer = 0 for bit in range(2 ** N): bl = True for i in range(M): p = P[i] result = 0 for s in lights[i][1:]: s -= 1 if (bit >> s) & 1: result += 1 if result % 2 != p: bl = False if bl: answer += 1 print(answer)
# coding: utf-8 import sys import itertools sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() KS = [lr() for _ in range(M)] P = lr() answer = 0 for pattern in itertools.product([0, 1], repeat=N): bl = True for i in range(M): if sum(pattern[x-1] for x in KS[i][1:]) % 2 != P[i]: bl = False break if bl: answer += 1 print(answer)
25
22
532
474
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() lights = [lr() for _ in range(M)] P = lr() answer = 0 for bit in range(2**N): bl = True for i in range(M): p = P[i] result = 0 for s in lights[i][1:]: s -= 1 if (bit >> s) & 1: result += 1 if result % 2 != p: bl = False if bl: answer += 1 print(answer)
# coding: utf-8 import sys import itertools sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() KS = [lr() for _ in range(M)] P = lr() answer = 0 for pattern in itertools.product([0, 1], repeat=N): bl = True for i in range(M): if sum(pattern[x - 1] for x in KS[i][1:]) % 2 != P[i]: bl = False break if bl: answer += 1 print(answer)
false
12
[ "+import itertools", "-lights = [lr() for _ in range(M)]", "+KS = [lr() for _ in range(M)]", "-for bit in range(2**N):", "+for pattern in itertools.product([0, 1], repeat=N):", "- p = P[i]", "- result = 0", "- for s in lights[i][1:]:", "- s -= 1", "- if (bit >> s) & 1:", "- result += 1", "- if result % 2 != p:", "+ if sum(pattern[x - 1] for x in KS[i][1:]) % 2 != P[i]:", "+ break" ]
false
0.038184
0.08371
0.456153
[ "s209496790", "s084167858" ]
u672475305
p03329
python
s451015358
s826383818
867
284
237,428
6,296
Accepted
Accepted
67.24
n = int(eval(input())) dp = [10**9]*30000000 dp[0] = 0 pow6 = [6**i for i in range(10) if 6**i <= n] pow9 = [9**i for i in range(10) if 9**i <= n] for i in range(n): for p6 in pow6: dp[i+p6] = min(dp[i+p6], dp[i]+1) for p9 in pow9: dp[i+p9] = min(dp[i+p9], dp[i]+1) print((dp[n]))
from bisect import bisect_right n = int(eval(input())) MX = 100010 dp = [float('inf') for _ in range(MX)] dp[0] = 0 pow_6, pow_9 = [6], [9] while True: flg = False if pow_6[-1]*6 <= MX: pow_6.append(pow_6[-1]*6) flg = True if pow_9[-1]*9 <= MX: pow_9.append(pow_9[-1]*9) flg = True if flg == False: break for i in range(1, MX): tmp = [1] if i >= 6: x = bisect_right(pow_6, i) tmp.append(pow_6[x-1]) if i >= 9: y = bisect_right(pow_9, i) tmp.append(pow_9[y-1]) for t in tmp: dp[i] = min(dp[i], dp[i-t]+1) print((dp[n]))
12
29
309
656
n = int(eval(input())) dp = [10**9] * 30000000 dp[0] = 0 pow6 = [6**i for i in range(10) if 6**i <= n] pow9 = [9**i for i in range(10) if 9**i <= n] for i in range(n): for p6 in pow6: dp[i + p6] = min(dp[i + p6], dp[i] + 1) for p9 in pow9: dp[i + p9] = min(dp[i + p9], dp[i] + 1) print((dp[n]))
from bisect import bisect_right n = int(eval(input())) MX = 100010 dp = [float("inf") for _ in range(MX)] dp[0] = 0 pow_6, pow_9 = [6], [9] while True: flg = False if pow_6[-1] * 6 <= MX: pow_6.append(pow_6[-1] * 6) flg = True if pow_9[-1] * 9 <= MX: pow_9.append(pow_9[-1] * 9) flg = True if flg == False: break for i in range(1, MX): tmp = [1] if i >= 6: x = bisect_right(pow_6, i) tmp.append(pow_6[x - 1]) if i >= 9: y = bisect_right(pow_9, i) tmp.append(pow_9[y - 1]) for t in tmp: dp[i] = min(dp[i], dp[i - t] + 1) print((dp[n]))
false
58.62069
[ "+from bisect import bisect_right", "+", "-dp = [10**9] * 30000000", "+MX = 100010", "+dp = [float(\"inf\") for _ in range(MX)]", "-pow6 = [6**i for i in range(10) if 6**i <= n]", "-pow9 = [9**i for i in range(10) if 9**i <= n]", "-for i in range(n):", "- for p6 in pow6:", "- dp[i + p6] = min(dp[i + p6], dp[i] + 1)", "- for p9 in pow9:", "- dp[i + p9] = min(dp[i + p9], dp[i] + 1)", "+pow_6, pow_9 = [6], [9]", "+while True:", "+ flg = False", "+ if pow_6[-1] * 6 <= MX:", "+ pow_6.append(pow_6[-1] * 6)", "+ flg = True", "+ if pow_9[-1] * 9 <= MX:", "+ pow_9.append(pow_9[-1] * 9)", "+ flg = True", "+ if flg == False:", "+ break", "+for i in range(1, MX):", "+ tmp = [1]", "+ if i >= 6:", "+ x = bisect_right(pow_6, i)", "+ tmp.append(pow_6[x - 1])", "+ if i >= 9:", "+ y = bisect_right(pow_9, i)", "+ tmp.append(pow_9[y - 1])", "+ for t in tmp:", "+ dp[i] = min(dp[i], dp[i - t] + 1)" ]
false
0.657444
0.784511
0.83803
[ "s451015358", "s826383818" ]
u064434060
p03053
python
s608713751
s523731144
703
516
140,636
122,076
Accepted
Accepted
26.6
import sys #import numpy as np import math #from fractions import Fraction #import itertools from collections import deque #import heapq #from fractions import gcd input=sys.stdin.readline h,w=list(map(int,input().split())) a=[list(map(str,eval(input()))) for _ in range(h)] b=deque() n=[-1]*(h*w) c=0 for i in range(h): for j in range(w): if a[i][j]=="#": b.append((i,j)) n[i*w+j]=0 else: continue while b: z=b.popleft() i=z[0] j=z[1] if i<h-1 and n[(i+1)*w+j]==-1: n[(i+1)*w+j]=n[i*w+j]+1 c=max(c,n[i*w+j]+1) b.append(((i+1),j)) f=True if i>0 and n[(i-1)*w+j]==-1: n[(i-1)*w+j]=n[i*w+j]+1 c=max(c,n[i*w+j]+1) b.append(((i-1),j)) f=True if j<w-1 and n[i*w+(j+1)]==-1: f=True n[i*w+(j+1)]=n[i*w+j]+1 c=max(c,n[i*w+j]+1) b.append((i,(j+1))) if j>0 and n[i*w+(j-1)]==-1: f=True n[i*w+(j-1)]=n[i*w+j]+1 c=max(c,n[i*w+j]+1) b.append((i,(j-1))) print(c)
import sys #import numpy as np import math #from fractions import Fraction #import itertools from collections import deque #import heapq #from fractions import gcd input=sys.stdin.readline h,w=list(map(int,input().split())) a=[list(map(str,eval(input()))) for _ in range(h)] b=deque() n=[-1]*(h*w) p=((1,0),(-1,0),(0,1),(0,-1)) for x in range(h): for y in range(w): if a[x][y]=="#": b.append((x,y)) n[x*w+y]=0 while b: x,y=b.popleft() for idx in p: s,t=idx if 0<=x+s<h and 0<=y+t<w: if n[(x+s)*w+(y+t)]==-1: n[(x+s)*w+(y+t)]=n[x*w+y]+1 b.append((x+s,y+t)) print((max(n)))
48
28
1,081
638
import sys # import numpy as np import math # from fractions import Fraction # import itertools from collections import deque # import heapq # from fractions import gcd input = sys.stdin.readline h, w = list(map(int, input().split())) a = [list(map(str, eval(input()))) for _ in range(h)] b = deque() n = [-1] * (h * w) c = 0 for i in range(h): for j in range(w): if a[i][j] == "#": b.append((i, j)) n[i * w + j] = 0 else: continue while b: z = b.popleft() i = z[0] j = z[1] if i < h - 1 and n[(i + 1) * w + j] == -1: n[(i + 1) * w + j] = n[i * w + j] + 1 c = max(c, n[i * w + j] + 1) b.append(((i + 1), j)) f = True if i > 0 and n[(i - 1) * w + j] == -1: n[(i - 1) * w + j] = n[i * w + j] + 1 c = max(c, n[i * w + j] + 1) b.append(((i - 1), j)) f = True if j < w - 1 and n[i * w + (j + 1)] == -1: f = True n[i * w + (j + 1)] = n[i * w + j] + 1 c = max(c, n[i * w + j] + 1) b.append((i, (j + 1))) if j > 0 and n[i * w + (j - 1)] == -1: f = True n[i * w + (j - 1)] = n[i * w + j] + 1 c = max(c, n[i * w + j] + 1) b.append((i, (j - 1))) print(c)
import sys # import numpy as np import math # from fractions import Fraction # import itertools from collections import deque # import heapq # from fractions import gcd input = sys.stdin.readline h, w = list(map(int, input().split())) a = [list(map(str, eval(input()))) for _ in range(h)] b = deque() n = [-1] * (h * w) p = ((1, 0), (-1, 0), (0, 1), (0, -1)) for x in range(h): for y in range(w): if a[x][y] == "#": b.append((x, y)) n[x * w + y] = 0 while b: x, y = b.popleft() for idx in p: s, t = idx if 0 <= x + s < h and 0 <= y + t < w: if n[(x + s) * w + (y + t)] == -1: n[(x + s) * w + (y + t)] = n[x * w + y] + 1 b.append((x + s, y + t)) print((max(n)))
false
41.666667
[ "-c = 0", "-for i in range(h):", "- for j in range(w):", "- if a[i][j] == \"#\":", "- b.append((i, j))", "- n[i * w + j] = 0", "- else:", "- continue", "+p = ((1, 0), (-1, 0), (0, 1), (0, -1))", "+for x in range(h):", "+ for y in range(w):", "+ if a[x][y] == \"#\":", "+ b.append((x, y))", "+ n[x * w + y] = 0", "- z = b.popleft()", "- i = z[0]", "- j = z[1]", "- if i < h - 1 and n[(i + 1) * w + j] == -1:", "- n[(i + 1) * w + j] = n[i * w + j] + 1", "- c = max(c, n[i * w + j] + 1)", "- b.append(((i + 1), j))", "- f = True", "- if i > 0 and n[(i - 1) * w + j] == -1:", "- n[(i - 1) * w + j] = n[i * w + j] + 1", "- c = max(c, n[i * w + j] + 1)", "- b.append(((i - 1), j))", "- f = True", "- if j < w - 1 and n[i * w + (j + 1)] == -1:", "- f = True", "- n[i * w + (j + 1)] = n[i * w + j] + 1", "- c = max(c, n[i * w + j] + 1)", "- b.append((i, (j + 1)))", "- if j > 0 and n[i * w + (j - 1)] == -1:", "- f = True", "- n[i * w + (j - 1)] = n[i * w + j] + 1", "- c = max(c, n[i * w + j] + 1)", "- b.append((i, (j - 1)))", "-print(c)", "+ x, y = b.popleft()", "+ for idx in p:", "+ s, t = idx", "+ if 0 <= x + s < h and 0 <= y + t < w:", "+ if n[(x + s) * w + (y + t)] == -1:", "+ n[(x + s) * w + (y + t)] = n[x * w + y] + 1", "+ b.append((x + s, y + t))", "+print((max(n)))" ]
false
0.082742
0.042436
1.949787
[ "s608713751", "s523731144" ]
u170183831
p03244
python
s200003715
s813960857
107
90
16,228
15,588
Accepted
Accepted
15.89
from collections import Counter def solve(n, V): if len(set(V)) == 1: return n // 2 return min( n - oc - ec for o, oc in Counter(V[0::2]).most_common(2) for e, ec in Counter(V[1::2]).most_common(2) if o != e ) _n = int(eval(input())) _V = list(map(int, input().split())) print((solve(_n, _V)))
from collections import Counter def solve(n, V): if V.count(V[0]) == n: return n // 2 return min( n - oc - ec for o, oc in Counter(V[0::2]).most_common(2) for e, ec in Counter(V[1::2]).most_common(2) if o != e ) _n = int(eval(input())) _V = list(map(int, input().split())) print((solve(_n, _V)))
15
15
354
356
from collections import Counter def solve(n, V): if len(set(V)) == 1: return n // 2 return min( n - oc - ec for o, oc in Counter(V[0::2]).most_common(2) for e, ec in Counter(V[1::2]).most_common(2) if o != e ) _n = int(eval(input())) _V = list(map(int, input().split())) print((solve(_n, _V)))
from collections import Counter def solve(n, V): if V.count(V[0]) == n: return n // 2 return min( n - oc - ec for o, oc in Counter(V[0::2]).most_common(2) for e, ec in Counter(V[1::2]).most_common(2) if o != e ) _n = int(eval(input())) _V = list(map(int, input().split())) print((solve(_n, _V)))
false
0
[ "- if len(set(V)) == 1:", "+ if V.count(V[0]) == n:" ]
false
0.040523
0.04028
1.006024
[ "s200003715", "s813960857" ]
u968166680
p03557
python
s539007591
s068182365
799
311
38,620
22,720
Accepted
Accepted
61.08
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *ABC = list(map(int, read().split())) A = sorted(ABC[:N]) B = sorted(ABC[N : 2 * N]) C = sorted(ABC[2 * N : 3 * N]) ans = 0 for b in B: ok = N ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if A[mid] >= b: ok = mid else: ng = mid a_num = ok ok = N ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid c_num = N - ok ans += a_num * c_num print(ans) return if __name__ == '__main__': main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
45
24
870
463
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): N, *ABC = list(map(int, read().split())) A = sorted(ABC[:N]) B = sorted(ABC[N : 2 * N]) C = sorted(ABC[2 * N : 3 * N]) ans = 0 for b in B: ok = N ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if A[mid] >= b: ok = mid else: ng = mid a_num = ok ok = N ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid c_num = N - ok ans += a_num * c_num print(ans) return if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
false
46.666667
[ "-import sys", "+from sys import stdin", "+from bisect import bisect_right, bisect_left", "-read = sys.stdin.read", "-readline = sys.stdin.readline", "-readlines = sys.stdin.readlines", "-sys.setrecursionlimit(10**9)", "-INF = 1 << 60", "+", "+def input():", "+ return stdin.readline().strip()", "- N, *ABC = list(map(int, read().split()))", "- A = sorted(ABC[:N])", "- B = sorted(ABC[N : 2 * N])", "- C = sorted(ABC[2 * N : 3 * N])", "- ans = 0", "- for b in B:", "- ok = N", "- ng = -1", "- while ok - ng > 1:", "- mid = (ok + ng) // 2", "- if A[mid] >= b:", "- ok = mid", "- else:", "- ng = mid", "- a_num = ok", "- ok = N", "- ng = -1", "- while ok - ng > 1:", "- mid = (ok + ng) // 2", "- if C[mid] > b:", "- ok = mid", "- else:", "- ng = mid", "- c_num = N - ok", "- ans += a_num * c_num", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ B = list(map(int, input().split()))", "+ C = list(map(int, input().split()))", "+ A.sort()", "+ B.sort()", "+ C.sort()", "+ ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)", "- return" ]
false
0.047139
0.045045
1.046507
[ "s539007591", "s068182365" ]
u951601135
p03416
python
s235712424
s241230073
98
55
3,060
3,060
Accepted
Accepted
43.88
A,B=list(map(int,input().split())) count=0 for i in range(A,B+1): #print(i) str_i=str(i) for j in range(len(str_i)): #print(str_i[j],str_i[-j-1]) if(str_i[j]!=str_i[-j-1]): break if(j>(len(str_i)//2+1)): #print(i) count+=1 print(count)
A,B=list(map(int,input().split())) S=0 for I in range(A,B+1): Q=str(I) R=Q[::-1] if R==Q: S+=1 print(S)
13
8
277
109
A, B = list(map(int, input().split())) count = 0 for i in range(A, B + 1): # print(i) str_i = str(i) for j in range(len(str_i)): # print(str_i[j],str_i[-j-1]) if str_i[j] != str_i[-j - 1]: break if j > (len(str_i) // 2 + 1): # print(i) count += 1 print(count)
A, B = list(map(int, input().split())) S = 0 for I in range(A, B + 1): Q = str(I) R = Q[::-1] if R == Q: S += 1 print(S)
false
38.461538
[ "-count = 0", "-for i in range(A, B + 1):", "- # print(i)", "- str_i = str(i)", "- for j in range(len(str_i)):", "- # print(str_i[j],str_i[-j-1])", "- if str_i[j] != str_i[-j - 1]:", "- break", "- if j > (len(str_i) // 2 + 1):", "- # print(i)", "- count += 1", "-print(count)", "+S = 0", "+for I in range(A, B + 1):", "+ Q = str(I)", "+ R = Q[::-1]", "+ if R == Q:", "+ S += 1", "+print(S)" ]
false
0.075582
0.047335
1.596746
[ "s235712424", "s241230073" ]
u104911888
p00507
python
s915941370
s399922481
90
70
4,716
4,724
Accepted
Accepted
22.22
from heapq import heappush, heappop n = eval(input()) h = [-10000]*4 for i in range(n): a = eval(input()) heappush(h, -a) heappop(h) h = [str(-a) for a in h] ans = [] for i in range(3): for j in range(i+1, 4): ans.append(int(h[i]+h[j])) ans.append(int(h[j]+h[i])) ans.sort() print(ans[2])
n = eval(input()) h = sorted(eval(input()) for i in range(n))[:4] h = list(map(str, h)) ans = [] for i in range(3): for j in range(i+1, 4): ans.append(int(h[i]+h[j])) ans.append(int(h[j]+h[i])) print(sorted(ans)[2])
15
9
321
224
from heapq import heappush, heappop n = eval(input()) h = [-10000] * 4 for i in range(n): a = eval(input()) heappush(h, -a) heappop(h) h = [str(-a) for a in h] ans = [] for i in range(3): for j in range(i + 1, 4): ans.append(int(h[i] + h[j])) ans.append(int(h[j] + h[i])) ans.sort() print(ans[2])
n = eval(input()) h = sorted(eval(input()) for i in range(n))[:4] h = list(map(str, h)) ans = [] for i in range(3): for j in range(i + 1, 4): ans.append(int(h[i] + h[j])) ans.append(int(h[j] + h[i])) print(sorted(ans)[2])
false
40
[ "-from heapq import heappush, heappop", "-", "-h = [-10000] * 4", "-for i in range(n):", "- a = eval(input())", "- heappush(h, -a)", "- heappop(h)", "-h = [str(-a) for a in h]", "+h = sorted(eval(input()) for i in range(n))[:4]", "+h = list(map(str, h))", "-ans.sort()", "-print(ans[2])", "+print(sorted(ans)[2])" ]
false
0.039948
0.092184
0.433346
[ "s915941370", "s399922481" ]
u130900604
p02844
python
s924219277
s049232532
800
69
47,624
66,872
Accepted
Accepted
91.38
# coding: utf-8 # Your code here! n=int(eval(input())) S=eval(input()) l=list("0123456789") ret=[False]*1000 for i in (l): for j in (l): for k in (l): flg1=flg2=False for s in S: if s==i and not flg1: flg1=True continue if flg1 and s==j and not flg2: flg2=True continue if flg2 and s==k: tmp=int(i+j+k) # print(tmp) ret[tmp]=True break print((sum(ret)))
n=int(eval(input())) s=eval(input()) from itertools import product cnt=0 for i,j in product("0123456789",repeat=2): try: ind_i=s.index(i) except: continue try: ind_j=s.rindex(j) except: continue if ind_i>ind_j: continue for k in "0123456789": cnt+=(k in s[ind_i+1:ind_j]) print(cnt)
26
20
621
371
# coding: utf-8 # Your code here! n = int(eval(input())) S = eval(input()) l = list("0123456789") ret = [False] * 1000 for i in l: for j in l: for k in l: flg1 = flg2 = False for s in S: if s == i and not flg1: flg1 = True continue if flg1 and s == j and not flg2: flg2 = True continue if flg2 and s == k: tmp = int(i + j + k) # print(tmp) ret[tmp] = True break print((sum(ret)))
n = int(eval(input())) s = eval(input()) from itertools import product cnt = 0 for i, j in product("0123456789", repeat=2): try: ind_i = s.index(i) except: continue try: ind_j = s.rindex(j) except: continue if ind_i > ind_j: continue for k in "0123456789": cnt += k in s[ind_i + 1 : ind_j] print(cnt)
false
23.076923
[ "-# coding: utf-8", "-# Your code here!", "-S = eval(input())", "-l = list(\"0123456789\")", "-ret = [False] * 1000", "-for i in l:", "- for j in l:", "- for k in l:", "- flg1 = flg2 = False", "- for s in S:", "- if s == i and not flg1:", "- flg1 = True", "- continue", "- if flg1 and s == j and not flg2:", "- flg2 = True", "- continue", "- if flg2 and s == k:", "- tmp = int(i + j + k)", "- # print(tmp)", "- ret[tmp] = True", "- break", "-print((sum(ret)))", "+s = eval(input())", "+from itertools import product", "+", "+cnt = 0", "+for i, j in product(\"0123456789\", repeat=2):", "+ try:", "+ ind_i = s.index(i)", "+ except:", "+ continue", "+ try:", "+ ind_j = s.rindex(j)", "+ except:", "+ continue", "+ if ind_i > ind_j:", "+ continue", "+ for k in \"0123456789\":", "+ cnt += k in s[ind_i + 1 : ind_j]", "+print(cnt)" ]
false
0.106489
0.034037
3.128652
[ "s924219277", "s049232532" ]
u821989875
p02887
python
s063895930
s899729641
1,540
46
4,084
4,024
Accepted
Accepted
97.01
# coding: utf-8 num = int(eval(input())) colors = list(eval(input())) i = 0 while i+1 != len(colors): if colors[i] == colors[i+1]: colors.pop(i+1) else: i += 1 print((len(colors)))
# coding: utf-8 num = int(eval(input())) colors = list(eval(input())) count = 0 for i in range(num-1): if colors[i] != colors[i+1]: count += 1 print((count+1))
10
10
187
164
# coding: utf-8 num = int(eval(input())) colors = list(eval(input())) i = 0 while i + 1 != len(colors): if colors[i] == colors[i + 1]: colors.pop(i + 1) else: i += 1 print((len(colors)))
# coding: utf-8 num = int(eval(input())) colors = list(eval(input())) count = 0 for i in range(num - 1): if colors[i] != colors[i + 1]: count += 1 print((count + 1))
false
0
[ "-i = 0", "-while i + 1 != len(colors):", "- if colors[i] == colors[i + 1]:", "- colors.pop(i + 1)", "- else:", "- i += 1", "-print((len(colors)))", "+count = 0", "+for i in range(num - 1):", "+ if colors[i] != colors[i + 1]:", "+ count += 1", "+print((count + 1))" ]
false
0.06108
0.035946
1.699213
[ "s063895930", "s899729641" ]
u541017633
p03238
python
s333340340
s262806198
66
17
2,940
2,940
Accepted
Accepted
74.24
N=int(eval(input())) sum_a=0 if N==1: print("Hello World") else: for _ in range(2): a=int(eval(input())) sum_a+=a print(sum_a)
N = int(eval(input())) if N == 1: print("Hello World") else: A = int(eval(input())) B = int(eval(input())) print((A+B))
9
10
151
139
N = int(eval(input())) sum_a = 0 if N == 1: print("Hello World") else: for _ in range(2): a = int(eval(input())) sum_a += a print(sum_a)
N = int(eval(input())) if N == 1: print("Hello World") else: A = int(eval(input())) B = int(eval(input())) print((A + B))
false
10
[ "-sum_a = 0", "- for _ in range(2):", "- a = int(eval(input()))", "- sum_a += a", "- print(sum_a)", "+ A = int(eval(input()))", "+ B = int(eval(input()))", "+ print((A + B))" ]
false
0.045568
0.038641
1.179267
[ "s333340340", "s262806198" ]
u418149936
p02725
python
s084365867
s893899817
159
143
32,296
32,356
Accepted
Accepted
10.06
K, N = list(map(int, input().split(' '))) A_ls = list(map(int, input().split(' '))) max_l = -1 for i in range(N): l = A_ls[(i + 1) % len(A_ls)] - A_ls[i] if l < 0: l = K - A_ls[i] + A_ls[(i + 1) % len(A_ls)] if max_l == -1: max_l = l else: max_l = max(max_l, l) print((K - max_l))
K, N = list(map(int, input().split(' '))) A_ls = list(map(int, input().split(' '))) max_l = 0 for i in range(N): l = A_ls[(i + 1) % N] - A_ls[i] if l < 0: l = K - A_ls[i] + A_ls[(i + 1) % N] max_l = max(max_l, l) print((K - max_l))
12
9
323
251
K, N = list(map(int, input().split(" "))) A_ls = list(map(int, input().split(" "))) max_l = -1 for i in range(N): l = A_ls[(i + 1) % len(A_ls)] - A_ls[i] if l < 0: l = K - A_ls[i] + A_ls[(i + 1) % len(A_ls)] if max_l == -1: max_l = l else: max_l = max(max_l, l) print((K - max_l))
K, N = list(map(int, input().split(" "))) A_ls = list(map(int, input().split(" "))) max_l = 0 for i in range(N): l = A_ls[(i + 1) % N] - A_ls[i] if l < 0: l = K - A_ls[i] + A_ls[(i + 1) % N] max_l = max(max_l, l) print((K - max_l))
false
25
[ "-max_l = -1", "+max_l = 0", "- l = A_ls[(i + 1) % len(A_ls)] - A_ls[i]", "+ l = A_ls[(i + 1) % N] - A_ls[i]", "- l = K - A_ls[i] + A_ls[(i + 1) % len(A_ls)]", "- if max_l == -1:", "- max_l = l", "- else:", "- max_l = max(max_l, l)", "+ l = K - A_ls[i] + A_ls[(i + 1) % N]", "+ max_l = max(max_l, l)" ]
false
0.086112
0.037635
2.288102
[ "s084365867", "s893899817" ]
u729133443
p03288
python
s399838084
s878849537
17
10
2,940
2,568
Accepted
Accepted
41.18
print(('A%sC'%'BRG'[int(eval(input()))//50+8>>5]))
print('A%sC'%'BRG'[eval(input())/50+8>>5])
1
1
42
34
print(("A%sC" % "BRG"[int(eval(input())) // 50 + 8 >> 5]))
print("A%sC" % "BRG"[eval(input()) / 50 + 8 >> 5])
false
0
[ "-print((\"A%sC\" % \"BRG\"[int(eval(input())) // 50 + 8 >> 5]))", "+print(\"A%sC\" % \"BRG\"[eval(input()) / 50 + 8 >> 5])" ]
false
0.036738
0.034732
1.057761
[ "s399838084", "s878849537" ]
u254871849
p02844
python
s139104177
s666786500
720
327
50,680
50,672
Accepted
Accepted
54.58
import sys from string import digits def main(): n, s = sys.stdin.read().split() n = int(n) place = dict((i, set()) for i in digits) for i in range(n): place[s[i]].add(i) l = [None] * n l[0] = set() for i in range(1, n): l[i] = l[i-1] | set([s[i-1]]) r = [None] * n r[n-1] = set() for i in range(n-2, -1, -1): r[i] = r[i+1] | set([s[i+1]]) res = set() for j in digits: for c in place[j]: for i in digits: if i in l[c]: for k in digits: if k in r[c]: res.add((i, j, k)) print((len(res))) if __name__ == '__main__': main()
import sys from string import digits def main(): n, s = sys.stdin.read().split() n = int(n) place = dict((i, set()) for i in digits) for i in range(n): place[s[i]].add(i) l = [None] * n l[0] = set() for i in range(1, n): l[i] = l[i-1] | set([s[i-1]]) r = [None] * n r[n-1] = set() for i in range(n-2, -1, -1): r[i] = r[i+1] | set([s[i+1]]) res = set() for j in digits: for i in digits: for k in digits: for c in place[j]: if not i in l[c]: continue if not k in r[c]: continue res.add((i, j, k)) break print((len(res))) if __name__ == '__main__': main()
35
37
756
841
import sys from string import digits def main(): n, s = sys.stdin.read().split() n = int(n) place = dict((i, set()) for i in digits) for i in range(n): place[s[i]].add(i) l = [None] * n l[0] = set() for i in range(1, n): l[i] = l[i - 1] | set([s[i - 1]]) r = [None] * n r[n - 1] = set() for i in range(n - 2, -1, -1): r[i] = r[i + 1] | set([s[i + 1]]) res = set() for j in digits: for c in place[j]: for i in digits: if i in l[c]: for k in digits: if k in r[c]: res.add((i, j, k)) print((len(res))) if __name__ == "__main__": main()
import sys from string import digits def main(): n, s = sys.stdin.read().split() n = int(n) place = dict((i, set()) for i in digits) for i in range(n): place[s[i]].add(i) l = [None] * n l[0] = set() for i in range(1, n): l[i] = l[i - 1] | set([s[i - 1]]) r = [None] * n r[n - 1] = set() for i in range(n - 2, -1, -1): r[i] = r[i + 1] | set([s[i + 1]]) res = set() for j in digits: for i in digits: for k in digits: for c in place[j]: if not i in l[c]: continue if not k in r[c]: continue res.add((i, j, k)) break print((len(res))) if __name__ == "__main__": main()
false
5.405405
[ "- for c in place[j]:", "- for i in digits:", "- if i in l[c]:", "- for k in digits:", "- if k in r[c]:", "- res.add((i, j, k))", "+ for i in digits:", "+ for k in digits:", "+ for c in place[j]:", "+ if not i in l[c]:", "+ continue", "+ if not k in r[c]:", "+ continue", "+ res.add((i, j, k))", "+ break" ]
false
0.046781
0.041363
1.130976
[ "s139104177", "s666786500" ]
u730769327
p03014
python
s499537412
s860830259
466
377
142,636
111,524
Accepted
Accepted
19.1
h,w=list(map(int,input().split())) s=[eval(input()) for _ in range(h)] d1=[[0]*(w+1) for _ in range(h+1)] d2=[[0]*(w+1) for _ in range(h+1)] for i in range(h): k=1 for j in range(w): if s[i][j]=='.':d1[i+1][k]+=1 else:k=j+2 for j in range(w): if s[i][j]=='.':d1[i+1][j+1]+=d1[i+1][j] for j in range(w): k=1 for i in range(h): if s[i][j]=='.':d2[k][j+1]+=1 else:k=i+2 for i in range(h): if s[i][j]=='.':d2[i+1][j+1]+=d2[i][j+1] ans=0 for i in range(1,h+1): for j in range(1,w+1): d1[i][j]+=d2[i][j]-1 ans=max(ans,max(d1[i])) print(ans)
h,w=list(map(int,input().split())) s=[eval(input()) for _ in range(h)] a=[[0]*w for _ in range(h)] for i in range(h): cnt=0 for j in range(w): if s[i][j]=='.':cnt+=1 else: for k in range(cnt): a[i][j-k-1]=cnt cnt=0 for k in range(cnt): a[i][j-k]=cnt for i in range(w): cnt=0 for j in range(h): if s[j][i]=='.':cnt+=1 else: for k in range(cnt): a[j-k-1][i]+=cnt cnt=0 for k in range(cnt): a[j-k][i]+=cnt ans=0 for i in range(h): for j in range(w): ans=max(ans,a[i][j]) print((ans-1))
24
28
589
577
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] d1 = [[0] * (w + 1) for _ in range(h + 1)] d2 = [[0] * (w + 1) for _ in range(h + 1)] for i in range(h): k = 1 for j in range(w): if s[i][j] == ".": d1[i + 1][k] += 1 else: k = j + 2 for j in range(w): if s[i][j] == ".": d1[i + 1][j + 1] += d1[i + 1][j] for j in range(w): k = 1 for i in range(h): if s[i][j] == ".": d2[k][j + 1] += 1 else: k = i + 2 for i in range(h): if s[i][j] == ".": d2[i + 1][j + 1] += d2[i][j + 1] ans = 0 for i in range(1, h + 1): for j in range(1, w + 1): d1[i][j] += d2[i][j] - 1 ans = max(ans, max(d1[i])) print(ans)
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] a = [[0] * w for _ in range(h)] for i in range(h): cnt = 0 for j in range(w): if s[i][j] == ".": cnt += 1 else: for k in range(cnt): a[i][j - k - 1] = cnt cnt = 0 for k in range(cnt): a[i][j - k] = cnt for i in range(w): cnt = 0 for j in range(h): if s[j][i] == ".": cnt += 1 else: for k in range(cnt): a[j - k - 1][i] += cnt cnt = 0 for k in range(cnt): a[j - k][i] += cnt ans = 0 for i in range(h): for j in range(w): ans = max(ans, a[i][j]) print((ans - 1))
false
14.285714
[ "-d1 = [[0] * (w + 1) for _ in range(h + 1)]", "-d2 = [[0] * (w + 1) for _ in range(h + 1)]", "+a = [[0] * w for _ in range(h)]", "- k = 1", "+ cnt = 0", "- d1[i + 1][k] += 1", "+ cnt += 1", "- k = j + 2", "+ for k in range(cnt):", "+ a[i][j - k - 1] = cnt", "+ cnt = 0", "+ for k in range(cnt):", "+ a[i][j - k] = cnt", "+for i in range(w):", "+ cnt = 0", "+ for j in range(h):", "+ if s[j][i] == \".\":", "+ cnt += 1", "+ else:", "+ for k in range(cnt):", "+ a[j - k - 1][i] += cnt", "+ cnt = 0", "+ for k in range(cnt):", "+ a[j - k][i] += cnt", "+ans = 0", "+for i in range(h):", "- if s[i][j] == \".\":", "- d1[i + 1][j + 1] += d1[i + 1][j]", "-for j in range(w):", "- k = 1", "- for i in range(h):", "- if s[i][j] == \".\":", "- d2[k][j + 1] += 1", "- else:", "- k = i + 2", "- for i in range(h):", "- if s[i][j] == \".\":", "- d2[i + 1][j + 1] += d2[i][j + 1]", "-ans = 0", "-for i in range(1, h + 1):", "- for j in range(1, w + 1):", "- d1[i][j] += d2[i][j] - 1", "- ans = max(ans, max(d1[i]))", "-print(ans)", "+ ans = max(ans, a[i][j])", "+print((ans - 1))" ]
false
0.047676
0.080661
0.591071
[ "s499537412", "s860830259" ]
u231136358
p02263
python
s936925307
s362979038
40
30
7,696
7,664
Accepted
Accepted
25
# stack exp = [i for i in input().split()] s = [] for lt in exp: if lt == '+': rhs = s.pop() lhs = s.pop() s.append(lhs + rhs) elif lt == '*': rhs = s.pop() lhs = s.pop() s.append(lhs * rhs) elif lt == '-': rhs = s.pop() lhs = s.pop() s.append(lhs - rhs) else: s.append(int(lt)) print((str(s[0])))
# stack exp = input().split() s = [] for lt in exp: if lt == '+': rhs = s.pop() lhs = s.pop() s.append(lhs + rhs) elif lt == '*': rhs = s.pop() lhs = s.pop() s.append(lhs * rhs) elif lt == '-': rhs = s.pop() lhs = s.pop() s.append(lhs - rhs) else: s.append(int(lt)) print((str(s[0])))
21
21
421
408
# stack exp = [i for i in input().split()] s = [] for lt in exp: if lt == "+": rhs = s.pop() lhs = s.pop() s.append(lhs + rhs) elif lt == "*": rhs = s.pop() lhs = s.pop() s.append(lhs * rhs) elif lt == "-": rhs = s.pop() lhs = s.pop() s.append(lhs - rhs) else: s.append(int(lt)) print((str(s[0])))
# stack exp = input().split() s = [] for lt in exp: if lt == "+": rhs = s.pop() lhs = s.pop() s.append(lhs + rhs) elif lt == "*": rhs = s.pop() lhs = s.pop() s.append(lhs * rhs) elif lt == "-": rhs = s.pop() lhs = s.pop() s.append(lhs - rhs) else: s.append(int(lt)) print((str(s[0])))
false
0
[ "-exp = [i for i in input().split()]", "+exp = input().split()" ]
false
0.045278
0.045199
1.001755
[ "s936925307", "s362979038" ]
u644778646
p02937
python
s127708034
s902384914
233
203
9,300
9,308
Accepted
Accepted
12.88
import bisect s = list(eval(input())) t = list(eval(input())) from collections import defaultdict ds = defaultdict(int) # sに含まれる文字それぞれの数 dsl = defaultdict(list) # sの文字の位置 for i in range(len(s)): ds[s[i]] += 1 dsl[s[i]].append(i) ans = 0 now = -1#ここが-1じゃないと、最初の遷移でsの最初の文字を使えない for i in range(len(t)): if ds[t[i]] == 0: # sにtを構成する文字がない場合 print("-1") exit() elif ds[t[i]] == 1: if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合 ans += (dsl[t[i]][0] - now) else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] else: index = bisect.bisect_right(dsl[t[i]], now) if index == len(dsl[t[i]]): index = -1 if dsl[t[i]][index] > now: # tの次の文字が現在地より右にある場合 ans += (dsl[t[i]][index] - now) now = dsl[t[i]][index] else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] print(ans)
from collections import defaultdict import bisect s = list(eval(input())) t = list(eval(input())) ds = defaultdict(int) # sに含まれる文字のそれぞれの数 dsl = defaultdict(list) # sの文字のindex for i in range(len(s)): ds[s[i]] += 1 dsl[s[i]].append(i) ans = 0 now = -1 # ここが-1じゃないと、最初の遷移でsの最初の文字を使えない for i in range(len(t)): if ds[t[i]] == 0: # sにtを構成する文字がない場合 print("-1") exit() # elif ds[t[i]] == 1: # if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合 # ans += (dsl[t[i]][0] - now) # else: # tの次の文字が現在地より左にある場合 # ans += dsl[t[i]][0] + (len(s) - now) # now = dsl[t[i]][0] else: index = bisect.bisect_right(dsl[t[i]], now) if index == len(dsl[t[i]]): index = -1 if dsl[t[i]][index] > now: # tの次の文字が現在地より右にある場合 ans += (dsl[t[i]][index] - now) now = dsl[t[i]][index] else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] print(ans)
35
35
1,024
1,043
import bisect s = list(eval(input())) t = list(eval(input())) from collections import defaultdict ds = defaultdict(int) # sに含まれる文字それぞれの数 dsl = defaultdict(list) # sの文字の位置 for i in range(len(s)): ds[s[i]] += 1 dsl[s[i]].append(i) ans = 0 now = -1 # ここが-1じゃないと、最初の遷移でsの最初の文字を使えない for i in range(len(t)): if ds[t[i]] == 0: # sにtを構成する文字がない場合 print("-1") exit() elif ds[t[i]] == 1: if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合 ans += dsl[t[i]][0] - now else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] else: index = bisect.bisect_right(dsl[t[i]], now) if index == len(dsl[t[i]]): index = -1 if dsl[t[i]][index] > now: # tの次の文字が現在地より右にある場合 ans += dsl[t[i]][index] - now now = dsl[t[i]][index] else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] print(ans)
from collections import defaultdict import bisect s = list(eval(input())) t = list(eval(input())) ds = defaultdict(int) # sに含まれる文字のそれぞれの数 dsl = defaultdict(list) # sの文字のindex for i in range(len(s)): ds[s[i]] += 1 dsl[s[i]].append(i) ans = 0 now = -1 # ここが-1じゃないと、最初の遷移でsの最初の文字を使えない for i in range(len(t)): if ds[t[i]] == 0: # sにtを構成する文字がない場合 print("-1") exit() # elif ds[t[i]] == 1: # if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合 # ans += (dsl[t[i]][0] - now) # else: # tの次の文字が現在地より左にある場合 # ans += dsl[t[i]][0] + (len(s) - now) # now = dsl[t[i]][0] else: index = bisect.bisect_right(dsl[t[i]], now) if index == len(dsl[t[i]]): index = -1 if dsl[t[i]][index] > now: # tの次の文字が現在地より右にある場合 ans += dsl[t[i]][index] - now now = dsl[t[i]][index] else: # tの次の文字が現在地より左にある場合 ans += dsl[t[i]][0] + (len(s) - now) now = dsl[t[i]][0] print(ans)
false
0
[ "+from collections import defaultdict", "-from collections import defaultdict", "-", "-ds = defaultdict(int) # sに含まれる文字それぞれの数", "-dsl = defaultdict(list) # sの文字の位置", "+ds = defaultdict(int) # sに含まれる文字のそれぞれの数", "+dsl = defaultdict(list) # sの文字のindex", "- elif ds[t[i]] == 1:", "- if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合", "- ans += dsl[t[i]][0] - now", "- else: # tの次の文字が現在地より左にある場合", "- ans += dsl[t[i]][0] + (len(s) - now)", "- now = dsl[t[i]][0]", "+ # elif ds[t[i]] == 1:", "+ # if dsl[t[i]][0] > now: # tの次の文字が現在地より右にある場合", "+ # ans += (dsl[t[i]][0] - now)", "+ # else: # tの次の文字が現在地より左にある場合", "+ # ans += dsl[t[i]][0] + (len(s) - now)", "+ # now = dsl[t[i]][0]" ]
false
0.043934
0.043867
1.001543
[ "s127708034", "s902384914" ]
u496344397
p03330
python
s131588294
s254024360
952
752
3,444
3,444
Accepted
Accepted
21.01
from itertools import permutations from collections import defaultdict N, C = list(map(int, input().split())) D =[list(map(int, input().split())) for _ in range(C)] remains = {0: defaultdict(int), 1: defaultdict(int), 2: defaultdict(int)} for i in range(1, N+1): line = list(map(int, input().split())) for j in range(N): remains[(i+j+1)%3][line[j]] += 1 INF = float('inf') def recolor(x, y, count): return D[x-1][y-1] * count answer = INF for choice in permutations(list(range(1, C+1)), 3): _answer = 0 for i, c in enumerate(choice): _answer += sum([recolor(r, c, remains[i][r]) for r in remains[i] if c != r]) answer = min(answer, _answer) print(answer)
from itertools import permutations from collections import defaultdict N, C = list(map(int, input().split())) D =[list(map(int, input().split())) for _ in range(C)] remains = {0: defaultdict(int), 1: defaultdict(int), 2: defaultdict(int)} for i in range(1, N+1): line = list(map(int, input().split())) for j in range(N): remains[(i+j+1)%3][line[j]] += 1 INF = float('inf') answer = INF for choice in permutations(list(range(1, C+1)), 3): _answer = 0 for i, c in enumerate(choice): _answer += sum([D[r-1][c-1] * remains[i][r] for r in remains[i] if c != r]) answer = min(answer, _answer) print(answer)
25
22
718
656
from itertools import permutations from collections import defaultdict N, C = list(map(int, input().split())) D = [list(map(int, input().split())) for _ in range(C)] remains = {0: defaultdict(int), 1: defaultdict(int), 2: defaultdict(int)} for i in range(1, N + 1): line = list(map(int, input().split())) for j in range(N): remains[(i + j + 1) % 3][line[j]] += 1 INF = float("inf") def recolor(x, y, count): return D[x - 1][y - 1] * count answer = INF for choice in permutations(list(range(1, C + 1)), 3): _answer = 0 for i, c in enumerate(choice): _answer += sum([recolor(r, c, remains[i][r]) for r in remains[i] if c != r]) answer = min(answer, _answer) print(answer)
from itertools import permutations from collections import defaultdict N, C = list(map(int, input().split())) D = [list(map(int, input().split())) for _ in range(C)] remains = {0: defaultdict(int), 1: defaultdict(int), 2: defaultdict(int)} for i in range(1, N + 1): line = list(map(int, input().split())) for j in range(N): remains[(i + j + 1) % 3][line[j]] += 1 INF = float("inf") answer = INF for choice in permutations(list(range(1, C + 1)), 3): _answer = 0 for i, c in enumerate(choice): _answer += sum([D[r - 1][c - 1] * remains[i][r] for r in remains[i] if c != r]) answer = min(answer, _answer) print(answer)
false
12
[ "-", "-", "-def recolor(x, y, count):", "- return D[x - 1][y - 1] * count", "-", "-", "- _answer += sum([recolor(r, c, remains[i][r]) for r in remains[i] if c != r])", "+ _answer += sum([D[r - 1][c - 1] * remains[i][r] for r in remains[i] if c != r])" ]
false
0.071502
0.151861
0.470835
[ "s131588294", "s254024360" ]
u677523557
p02821
python
s799610891
s605604927
1,264
880
30,276
20,456
Accepted
Accepted
30.38
from numpy.fft import rfft, irfft import numpy as np import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) C = [0]*(10**5+1) for a in A: C[a] += 1 L = 2*10**5+4 CC = rfft(np.array(C), L) X = (irfft(CC*CC)+0.5).astype(int) count = 0 ans = 0 for i in reversed(list(range(L))): x = X[i] if count + x >= M: ans += i*(M-count) break ans += i*x count += x print(ans)
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) l = 0 r = 3*10**5 while r - l > 1: m = (r + l)//2 # 和がm以上になるペアはいくつ? ind = N-1 cnt = 0 for a in A: while ind >= 0 and A[ind] + a < m: ind -= 1 cnt += ind+1 if cnt >= M: l = m else: r = m B = [0] for a in A: B.append(B[-1]+a) ans = 0 border = l ind = N-1 cnt = 0 for a in A: while ind >= 0 and A[ind] + a < border: ind -= 1 cnt += (ind+1) ans += a*(ind+1) + B[ind+1] ans -= (cnt-M)*border print(ans)
28
39
476
661
from numpy.fft import rfft, irfft import numpy as np import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) C = [0] * (10**5 + 1) for a in A: C[a] += 1 L = 2 * 10**5 + 4 CC = rfft(np.array(C), L) X = (irfft(CC * CC) + 0.5).astype(int) count = 0 ans = 0 for i in reversed(list(range(L))): x = X[i] if count + x >= M: ans += i * (M - count) break ans += i * x count += x print(ans)
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) l = 0 r = 3 * 10**5 while r - l > 1: m = (r + l) // 2 # 和がm以上になるペアはいくつ? ind = N - 1 cnt = 0 for a in A: while ind >= 0 and A[ind] + a < m: ind -= 1 cnt += ind + 1 if cnt >= M: l = m else: r = m B = [0] for a in A: B.append(B[-1] + a) ans = 0 border = l ind = N - 1 cnt = 0 for a in A: while ind >= 0 and A[ind] + a < border: ind -= 1 cnt += ind + 1 ans += a * (ind + 1) + B[ind + 1] ans -= (cnt - M) * border print(ans)
false
28.205128
[ "-from numpy.fft import rfft, irfft", "-import numpy as np", "-C = [0] * (10**5 + 1)", "+A.sort(reverse=True)", "+l = 0", "+r = 3 * 10**5", "+while r - l > 1:", "+ m = (r + l) // 2 # 和がm以上になるペアはいくつ?", "+ ind = N - 1", "+ cnt = 0", "+ for a in A:", "+ while ind >= 0 and A[ind] + a < m:", "+ ind -= 1", "+ cnt += ind + 1", "+ if cnt >= M:", "+ l = m", "+ else:", "+ r = m", "+B = [0]", "- C[a] += 1", "-L = 2 * 10**5 + 4", "-CC = rfft(np.array(C), L)", "-X = (irfft(CC * CC) + 0.5).astype(int)", "-count = 0", "+ B.append(B[-1] + a)", "-for i in reversed(list(range(L))):", "- x = X[i]", "- if count + x >= M:", "- ans += i * (M - count)", "- break", "- ans += i * x", "- count += x", "+border = l", "+ind = N - 1", "+cnt = 0", "+for a in A:", "+ while ind >= 0 and A[ind] + a < border:", "+ ind -= 1", "+ cnt += ind + 1", "+ ans += a * (ind + 1) + B[ind + 1]", "+ans -= (cnt - M) * border" ]
false
0.473253
0.0495
9.560611
[ "s799610891", "s605604927" ]
u252828980
p03416
python
s514203716
s399686195
82
50
2,940
2,940
Accepted
Accepted
39.02
a,b = list(map(int,input().split())) cnt = 0 for i in range(a,b+1): i = list(str(i)) if i == i[::-1]: cnt += 1 print(cnt)
n,m = list(map(int,input().split())) cnt = 0 for i in range(n,m+1): s = str(i) if s == s[::-1]: cnt +=1 print(cnt)
7
7
129
122
a, b = list(map(int, input().split())) cnt = 0 for i in range(a, b + 1): i = list(str(i)) if i == i[::-1]: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) cnt = 0 for i in range(n, m + 1): s = str(i) if s == s[::-1]: cnt += 1 print(cnt)
false
0
[ "-a, b = list(map(int, input().split()))", "+n, m = list(map(int, input().split()))", "-for i in range(a, b + 1):", "- i = list(str(i))", "- if i == i[::-1]:", "+for i in range(n, m + 1):", "+ s = str(i)", "+ if s == s[::-1]:" ]
false
0.072217
0.063626
1.135022
[ "s514203716", "s399686195" ]
u052499405
p02803
python
s360420071
s137043230
900
412
14,404
3,316
Accepted
Accepted
54.22
import numpy as np from collections import deque h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if s[i][j] == '#': continue q = deque() q.append([i, j, 0]) visited = np.zeros((h + 5, w + 5), dtype = bool) visited[i][j] = True dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]] mx = 0 while len(q) != 0: x, y, z = q[0] for p in range(4): nx, ny = x + dirr[p][0], y + dirr[p][1] if 0 <= nx < h and 0 <= ny < w: if not visited[nx][ny] and s[nx][ny] == '.': q.append([nx, ny, z + 1]) visited[nx][ny] = True ans = max(ans, z + 1) q.popleft() print(ans)
from collections import deque h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] dirr = ((1, 0), (0, 1), (-1, 0), (0, -1)) ans = 0 for i in range(h): for j in range(w): if s[i][j] == '#': continue q = deque() q.append((i, j, 0)) visited = [[False] * w for _ in range(h)] visited[i][j] = True while q: x, y, z = q.popleft() for dx, dy in dirr: nx, ny = x + dx, y + dy if 0 <= nx < h and 0 <= ny < w: if not visited[nx][ny] and s[nx][ny] == '.': q.append((nx, ny, z + 1)) if z + 1 > ans: ans = z + 1 visited[nx][ny] = True print(ans)
27
24
865
779
import numpy as np from collections import deque h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if s[i][j] == "#": continue q = deque() q.append([i, j, 0]) visited = np.zeros((h + 5, w + 5), dtype=bool) visited[i][j] = True dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]] mx = 0 while len(q) != 0: x, y, z = q[0] for p in range(4): nx, ny = x + dirr[p][0], y + dirr[p][1] if 0 <= nx < h and 0 <= ny < w: if not visited[nx][ny] and s[nx][ny] == ".": q.append([nx, ny, z + 1]) visited[nx][ny] = True ans = max(ans, z + 1) q.popleft() print(ans)
from collections import deque h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] dirr = ((1, 0), (0, 1), (-1, 0), (0, -1)) ans = 0 for i in range(h): for j in range(w): if s[i][j] == "#": continue q = deque() q.append((i, j, 0)) visited = [[False] * w for _ in range(h)] visited[i][j] = True while q: x, y, z = q.popleft() for dx, dy in dirr: nx, ny = x + dx, y + dy if 0 <= nx < h and 0 <= ny < w: if not visited[nx][ny] and s[nx][ny] == ".": q.append((nx, ny, z + 1)) if z + 1 > ans: ans = z + 1 visited[nx][ny] = True print(ans)
false
11.111111
[ "-import numpy as np", "+dirr = ((1, 0), (0, 1), (-1, 0), (0, -1))", "- q.append([i, j, 0])", "- visited = np.zeros((h + 5, w + 5), dtype=bool)", "+ q.append((i, j, 0))", "+ visited = [[False] * w for _ in range(h)]", "- dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "- mx = 0", "- while len(q) != 0:", "- x, y, z = q[0]", "- for p in range(4):", "- nx, ny = x + dirr[p][0], y + dirr[p][1]", "+ while q:", "+ x, y, z = q.popleft()", "+ for dx, dy in dirr:", "+ nx, ny = x + dx, y + dy", "- q.append([nx, ny, z + 1])", "+ q.append((nx, ny, z + 1))", "+ if z + 1 > ans:", "+ ans = z + 1", "- ans = max(ans, z + 1)", "- q.popleft()" ]
false
0.208709
0.04213
4.953888
[ "s360420071", "s137043230" ]
u441599836
p02983
python
s348500834
s073988826
666
54
3,060
3,064
Accepted
Accepted
91.89
l, r = list(map(int, input().split())) n = r-l+1 l = l%2019 r = r%2019 if n >= 2019: print((0)) else: if l > r: print((0)) else: ans = 2018 for i in range(l,r): for j in range(i+1,r+1): ans = min(ans,(j*i)%2019) print(ans)
l, r = list(map(int, input().split())) n = r-l+1 l = l%2019 r = r%2019 if n >= 2019: print((0)) else: if l > r: print((0)) else: ans = 2018 for i in range(l,r): for j in range(i+1,r+1): ans = min(ans,(j*i)%2019) if ans == 0: print((0)) break else: continue break else: print(ans)
15
22
298
468
l, r = list(map(int, input().split())) n = r - l + 1 l = l % 2019 r = r % 2019 if n >= 2019: print((0)) else: if l > r: print((0)) else: ans = 2018 for i in range(l, r): for j in range(i + 1, r + 1): ans = min(ans, (j * i) % 2019) print(ans)
l, r = list(map(int, input().split())) n = r - l + 1 l = l % 2019 r = r % 2019 if n >= 2019: print((0)) else: if l > r: print((0)) else: ans = 2018 for i in range(l, r): for j in range(i + 1, r + 1): ans = min(ans, (j * i) % 2019) if ans == 0: print((0)) break else: continue break else: print(ans)
false
31.818182
[ "- print(ans)", "+ if ans == 0:", "+ print((0))", "+ break", "+ else:", "+ continue", "+ break", "+ else:", "+ print(ans)" ]
false
0.035201
0.035266
0.998168
[ "s348500834", "s073988826" ]