user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u536034761
p03837
python
s270994078
s554890234
273
167
77,084
9,360
Accepted
Accepted
38.83
import heapq n, m = list(map(int, input().split())) graph = [set() for _ in range(n)] side = dict() ans = [0 for _ in range(m + 1)] for i in range(m): a, b, c = list(map(int, input().split())) t = (a - 1, b - 1, c) side[i] = t graph[a-1].add(i) graph[b-1].add(i) for j in range(n): D = [(0, 0, j, m), ] heapq.heapify(D) done = [True for _ in range(n)] while D: d = heapq.heappop(D) if done[d[2]]: done[d[2]] = False ans[d[3]] = 1 for i in graph[d[2]]: a, b, c = side[i] if b == d[2]: a, b = b, a if done[b]: heapq.heappush(D, (d[0] + c, ans[i], b, i)) print((m - (sum(ans) - 1)))
import heapq n, m = list(map(int, input().split())) edges = dict() ans = [0 for _ in range(m + 1)] graph = [set() for _ in range(n)] for i in range(m): a, b, c = list(map(int, input().split())) edges[i] = (a - 1, b - 1, c) graph[a - 1].add(i) graph[b - 1].add(i) # (cost,done,node,edge) for i in range(n): done = [True for _ in range(n)] D = [(0, 0, i, m), ] heapq.heapify(D) while D: d = heapq.heappop(D) cost, mark, node, edge = d if done[node]: done[node] = False ans[edge] = 1 for g in graph[node]: a, b, c = edges[g] if b == node: a, b = b, a if done[b]: heapq.heappush(D, (cost + c, ans[g], b, g)) print((m - (sum(ans) - 1)))
32
37
778
843
import heapq n, m = list(map(int, input().split())) graph = [set() for _ in range(n)] side = dict() ans = [0 for _ in range(m + 1)] for i in range(m): a, b, c = list(map(int, input().split())) t = (a - 1, b - 1, c) side[i] = t graph[a - 1].add(i) graph[b - 1].add(i) for j in range(n): D = [ (0, 0, j, m), ] heapq.heapify(D) done = [True for _ in range(n)] while D: d = heapq.heappop(D) if done[d[2]]: done[d[2]] = False ans[d[3]] = 1 for i in graph[d[2]]: a, b, c = side[i] if b == d[2]: a, b = b, a if done[b]: heapq.heappush(D, (d[0] + c, ans[i], b, i)) print((m - (sum(ans) - 1)))
import heapq n, m = list(map(int, input().split())) edges = dict() ans = [0 for _ in range(m + 1)] graph = [set() for _ in range(n)] for i in range(m): a, b, c = list(map(int, input().split())) edges[i] = (a - 1, b - 1, c) graph[a - 1].add(i) graph[b - 1].add(i) # (cost,done,node,edge) for i in range(n): done = [True for _ in range(n)] D = [ (0, 0, i, m), ] heapq.heapify(D) while D: d = heapq.heappop(D) cost, mark, node, edge = d if done[node]: done[node] = False ans[edge] = 1 for g in graph[node]: a, b, c = edges[g] if b == node: a, b = b, a if done[b]: heapq.heappush(D, (cost + c, ans[g], b, g)) print((m - (sum(ans) - 1)))
false
13.513514
[ "+edges = dict()", "+ans = [0 for _ in range(m + 1)]", "-side = dict()", "-ans = [0 for _ in range(m + 1)]", "- t = (a - 1, b - 1, c)", "- side[i] = t", "+ edges[i] = (a - 1, b - 1, c)", "-for j in range(n):", "+# (cost,done,node,edge)", "+for i in range(n):", "+ done = [True for _ in range(n)]", "- (0, 0, j, m),", "+ (0, 0, i, m),", "- done = [True for _ in range(n)]", "- if done[d[2]]:", "- done[d[2]] = False", "- ans[d[3]] = 1", "- for i in graph[d[2]]:", "- a, b, c = side[i]", "- if b == d[2]:", "+ cost, mark, node, edge = d", "+ if done[node]:", "+ done[node] = False", "+ ans[edge] = 1", "+ for g in graph[node]:", "+ a, b, c = edges[g]", "+ if b == node:", "- heapq.heappush(D, (d[0] + c, ans[i], b, i))", "+ heapq.heappush(D, (cost + c, ans[g], b, g))" ]
false
0.045915
0.067838
0.676826
[ "s270994078", "s554890234" ]
u057993957
p02712
python
s958020038
s312712011
173
146
30,148
29,848
Accepted
Accepted
15.61
n = int(eval(input())) a = [] for i in range(1, n+1): if (i % 3 != 0) and (i % 5 != 0): a.append(i) print((sum(a)))
n = int(eval(input())) a= [i for i in range(1, n+1) if i % 3 != 0 and i % 5 != 0 and i % 15 != 0] print((sum(a)))
8
4
128
112
n = int(eval(input())) a = [] for i in range(1, n + 1): if (i % 3 != 0) and (i % 5 != 0): a.append(i) print((sum(a)))
n = int(eval(input())) a = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0 and i % 15 != 0] print((sum(a)))
false
50
[ "-a = []", "-for i in range(1, n + 1):", "- if (i % 3 != 0) and (i % 5 != 0):", "- a.append(i)", "+a = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0 and i % 15 != 0]" ]
false
0.105446
0.090004
1.171571
[ "s958020038", "s312712011" ]
u798818115
p02820
python
s530748926
s301772312
159
61
4,828
4,212
Accepted
Accepted
61.64
# coding: utf-8 # Your code here! N,K=list(map(int,input().split())) R,S,P=list(map(int,input().split())) l=list(eval(input())) play=[] def point(hand): if hand=="r": return ["p",P] elif hand=="s": return ["r",R] else: return ["s",S] ans=0 for i in range(N)[::-1]: if len(play)>=K: if point(l[i])[0]==play[-K]: if i-K>=0: temp=point(l[i-K])[0] for item in ["r","s","p"]: if item!=play[-K] and item!=temp: play.append(item) break else: for item in ["r","s","p"]: if item!=play[-K]: play.append(item) break else: play.append(point(l[i])[0]) ans+=point(l[i])[1] else: play.append(point(l[i])[0]) ans+=point(l[i])[1] #print(play[::-1]) print(ans)
# coding: utf-8 # Your code here! N,K=list(map(int,input().split())) R,S,P=list(map(int,input().split())) point=[R,S,P] T=eval(input()) myhand=[] for item in T: if item == "r": myhand.append("p") elif item == "s": myhand.append("r") else: myhand.append("s") for i in range(N-K): if myhand[i]==myhand[i+K]: myhand[i+K]="-" print((myhand.count("r")*R+myhand.count("s")*S+myhand.count("p")*P))
39
25
985
454
# coding: utf-8 # Your code here! N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) l = list(eval(input())) play = [] def point(hand): if hand == "r": return ["p", P] elif hand == "s": return ["r", R] else: return ["s", S] ans = 0 for i in range(N)[::-1]: if len(play) >= K: if point(l[i])[0] == play[-K]: if i - K >= 0: temp = point(l[i - K])[0] for item in ["r", "s", "p"]: if item != play[-K] and item != temp: play.append(item) break else: for item in ["r", "s", "p"]: if item != play[-K]: play.append(item) break else: play.append(point(l[i])[0]) ans += point(l[i])[1] else: play.append(point(l[i])[0]) ans += point(l[i])[1] # print(play[::-1]) print(ans)
# coding: utf-8 # Your code here! N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) point = [R, S, P] T = eval(input()) myhand = [] for item in T: if item == "r": myhand.append("p") elif item == "s": myhand.append("r") else: myhand.append("s") for i in range(N - K): if myhand[i] == myhand[i + K]: myhand[i + K] = "-" print((myhand.count("r") * R + myhand.count("s") * S + myhand.count("p") * P))
false
35.897436
[ "-l = list(eval(input()))", "-play = []", "-", "-", "-def point(hand):", "- if hand == \"r\":", "- return [\"p\", P]", "- elif hand == \"s\":", "- return [\"r\", R]", "+point = [R, S, P]", "+T = eval(input())", "+myhand = []", "+for item in T:", "+ if item == \"r\":", "+ myhand.append(\"p\")", "+ elif item == \"s\":", "+ myhand.append(\"r\")", "- return [\"s\", S]", "-", "-", "-ans = 0", "-for i in range(N)[::-1]:", "- if len(play) >= K:", "- if point(l[i])[0] == play[-K]:", "- if i - K >= 0:", "- temp = point(l[i - K])[0]", "- for item in [\"r\", \"s\", \"p\"]:", "- if item != play[-K] and item != temp:", "- play.append(item)", "- break", "- else:", "- for item in [\"r\", \"s\", \"p\"]:", "- if item != play[-K]:", "- play.append(item)", "- break", "- else:", "- play.append(point(l[i])[0])", "- ans += point(l[i])[1]", "- else:", "- play.append(point(l[i])[0])", "- ans += point(l[i])[1]", "-# print(play[::-1])", "-print(ans)", "+ myhand.append(\"s\")", "+for i in range(N - K):", "+ if myhand[i] == myhand[i + K]:", "+ myhand[i + K] = \"-\"", "+print((myhand.count(\"r\") * R + myhand.count(\"s\") * S + myhand.count(\"p\") * P))" ]
false
0.043521
0.037019
1.175635
[ "s530748926", "s301772312" ]
u983918956
p03722
python
s038898847
s545299644
744
467
3,316
3,316
Accepted
Accepted
37.23
inf = float('inf') N,M = list(map(int,input().split())) info = [] for _ in range(M): a,b,c = list(map(int,input().split())) a -= 1; b -= 1 info.append((a,b,c)) dist = [-inf for _ in range(N)] dist[0] = 0 for i in range(N): for v,nv,w in info: if dist[nv] < dist[v] + w: dist[nv] = dist[v] + w if i == N-1 and nv == N-1: print("inf") exit() ans = dist[N-1] print(ans)
inf = float('inf') # distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0 # True - >正常に更新, False -> 負閉路有り def bellmanford(dist,edges,N): for i in range(N): for v ,nv, w in edges: if dist[nv] > dist[v] + w: dist[nv] = dist[v] + w # 頂点数Nなら更新は高々N-1回で済む # N回目に更新を行うなら負閉路があるということ if i == N-1 and nv == N-1: return False return True N,M = list(map(int,input().split())) info = [] for _ in range(M): a,b,c = list(map(int,input().split())) a -= 1; b -= 1; c = -c info.append((a,b,c)) dist = [inf for _ in range(N)] dist[0] = 0 flag = bellmanford(dist,info,N) ans = -dist[N-1] if flag is True else "inf" print(ans)
20
28
456
754
inf = float("inf") N, M = list(map(int, input().split())) info = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 info.append((a, b, c)) dist = [-inf for _ in range(N)] dist[0] = 0 for i in range(N): for v, nv, w in info: if dist[nv] < dist[v] + w: dist[nv] = dist[v] + w if i == N - 1 and nv == N - 1: print("inf") exit() ans = dist[N - 1] print(ans)
inf = float("inf") # distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0 # True - >正常に更新, False -> 負閉路有り def bellmanford(dist, edges, N): for i in range(N): for v, nv, w in edges: if dist[nv] > dist[v] + w: dist[nv] = dist[v] + w # 頂点数Nなら更新は高々N-1回で済む # N回目に更新を行うなら負閉路があるということ if i == N - 1 and nv == N - 1: return False return True N, M = list(map(int, input().split())) info = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 c = -c info.append((a, b, c)) dist = [inf for _ in range(N)] dist[0] = 0 flag = bellmanford(dist, info, N) ans = -dist[N - 1] if flag is True else "inf" print(ans)
false
28.571429
[ "+# distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0", "+# True - >正常に更新, False -> 負閉路有り", "+def bellmanford(dist, edges, N):", "+ for i in range(N):", "+ for v, nv, w in edges:", "+ if dist[nv] > dist[v] + w:", "+ dist[nv] = dist[v] + w", "+ # 頂点数Nなら更新は高々N-1回で済む", "+ # N回目に更新を行うなら負閉路があるということ", "+ if i == N - 1 and nv == N - 1:", "+ return False", "+ return True", "+", "+", "+ c = -c", "-dist = [-inf for _ in range(N)]", "+dist = [inf for _ in range(N)]", "-for i in range(N):", "- for v, nv, w in info:", "- if dist[nv] < dist[v] + w:", "- dist[nv] = dist[v] + w", "- if i == N - 1 and nv == N - 1:", "- print(\"inf\")", "- exit()", "-ans = dist[N - 1]", "+flag = bellmanford(dist, info, N)", "+ans = -dist[N - 1] if flag is True else \"inf\"" ]
false
0.074842
0.036692
2.039752
[ "s038898847", "s545299644" ]
u139614630
p03013
python
s160347588
s917196933
59
51
11,884
11,884
Accepted
Accepted
13.56
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 comb = 1 for i in range(2, n+1): if i in a: comb = 0 a.remove(i) else: comb = (comb_m1 + comb_m2) % P_NUM comb_m1, comb_m2 = comb, comb_m1 return comb if __name__ == '__main__': n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 for i in range(2, n+1): if i in a: comb_m1, comb_m2 = 0, comb_m1 else: comb_m1, comb_m2 = (comb_m1 + comb_m2) % P_NUM, comb_m1 return comb_m1 if __name__ == '__main__': n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
38
34
603
565
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 comb = 1 for i in range(2, n + 1): if i in a: comb = 0 a.remove(i) else: comb = (comb_m1 + comb_m2) % P_NUM comb_m1, comb_m2 = comb, comb_m1 return comb if __name__ == "__main__": n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 for i in range(2, n + 1): if i in a: comb_m1, comb_m2 = 0, comb_m1 else: comb_m1, comb_m2 = (comb_m1 + comb_m2) % P_NUM, comb_m1 return comb_m1 if __name__ == "__main__": n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
false
10.526316
[ "- comb = 1", "- comb = 0", "- a.remove(i)", "+ comb_m1, comb_m2 = 0, comb_m1", "- comb = (comb_m1 + comb_m2) % P_NUM", "- comb_m1, comb_m2 = comb, comb_m1", "- return comb", "+ comb_m1, comb_m2 = (comb_m1 + comb_m2) % P_NUM, comb_m1", "+ return comb_m1" ]
false
0.064133
0.039269
1.633176
[ "s160347588", "s917196933" ]
u040298438
p02897
python
s277176472
s639963365
29
26
9,136
9,108
Accepted
Accepted
10.34
n = int(eval(input())) print(((n + 1) // 2 / n))
n = int(eval(input())) print(((((n + 1) // 2) / n, 0.5)[n % 2 == 0]))
2
2
41
62
n = int(eval(input())) print(((n + 1) // 2 / n))
n = int(eval(input())) print(((((n + 1) // 2) / n, 0.5)[n % 2 == 0]))
false
0
[ "-print(((n + 1) // 2 / n))", "+print(((((n + 1) // 2) / n, 0.5)[n % 2 == 0]))" ]
false
0.048855
0.046633
1.047639
[ "s277176472", "s639963365" ]
u332385682
p03722
python
s782734732
s044590260
441
225
68,572
42,352
Accepted
Accepted
48.98
import sys from collections import Counter sys.setrecursionlimit(10**7) inf = 1<<100 def solve(): N, M = list(map(int, input().split())) edges = [None]*M Adj = [[] for i in range(N)] for i in range(M): ui, vi, ci = list(map(int, sys.stdin.readline().split())) ui, vi = ui - 1, vi - 1 edges[i] = (ui, vi, -ci) Adj[ui].append(vi) visitable = [False]*N dfs(N, M, Adj, visitable, 0) reachable = [False]*N reachable[0] = True reachable[N - 1] = True for u in range(1, N - 1): visited = [False]*N dfs(N, M, Adj, visited, u) if visited[N - 1]: reachable[u] = True ans = Bellmanford(N, M, edges, visitable, reachable) if ans is not None: print((-ans)) else: print('inf') def dfs(N, M, Adj, visitable, u): visitable[u] = True for v in Adj[u]: if not visitable[v]: dfs(N, M, Adj, visitable, v) def Bellmanford(N, M, edges, visitable, reachable): dist = [inf]*N dist[0] = 0 flag = True cnt = 0 for i in range(N): flag = False for (u, v, c) in edges: if dist[u] != inf and dist[v] > dist[u] + c: dist[v] = dist[u] + c if visitable[v] and reachable[v]: flag = True # print(dist) if not flag: break if flag and i == N - 1: return None return dist[N - 1] if __name__ == '__main__': solve()
import sys inf = 1<<60 def solve(): N, M = list(map(int, input().split())) edges = [None] * M for i in range(M): ai, bi, ci = list(map(int, sys.stdin.readline().split())) ai, bi = ai - 1, bi - 1 edges[i] = (ai, bi, -ci) ans = BellmanFord(N, M, edges) if ans is None: print('inf') else: print((-ans)) def BellmanFord(N, M, edges): d = [inf] * N d[0] = 0 for i in range(N - 1): for (u, v, c) in edges: if d[u] + c < d[v]: d[v] = d[u] + c for i in range(N): for (u, v, c) in edges: if d[u] + c < d[v]: if v == N - 1: return None d[v] = d[u] + c return d[N - 1] if __name__ == '__main__': solve()
77
41
1,587
825
import sys from collections import Counter sys.setrecursionlimit(10**7) inf = 1 << 100 def solve(): N, M = list(map(int, input().split())) edges = [None] * M Adj = [[] for i in range(N)] for i in range(M): ui, vi, ci = list(map(int, sys.stdin.readline().split())) ui, vi = ui - 1, vi - 1 edges[i] = (ui, vi, -ci) Adj[ui].append(vi) visitable = [False] * N dfs(N, M, Adj, visitable, 0) reachable = [False] * N reachable[0] = True reachable[N - 1] = True for u in range(1, N - 1): visited = [False] * N dfs(N, M, Adj, visited, u) if visited[N - 1]: reachable[u] = True ans = Bellmanford(N, M, edges, visitable, reachable) if ans is not None: print((-ans)) else: print("inf") def dfs(N, M, Adj, visitable, u): visitable[u] = True for v in Adj[u]: if not visitable[v]: dfs(N, M, Adj, visitable, v) def Bellmanford(N, M, edges, visitable, reachable): dist = [inf] * N dist[0] = 0 flag = True cnt = 0 for i in range(N): flag = False for (u, v, c) in edges: if dist[u] != inf and dist[v] > dist[u] + c: dist[v] = dist[u] + c if visitable[v] and reachable[v]: flag = True # print(dist) if not flag: break if flag and i == N - 1: return None return dist[N - 1] if __name__ == "__main__": solve()
import sys inf = 1 << 60 def solve(): N, M = list(map(int, input().split())) edges = [None] * M for i in range(M): ai, bi, ci = list(map(int, sys.stdin.readline().split())) ai, bi = ai - 1, bi - 1 edges[i] = (ai, bi, -ci) ans = BellmanFord(N, M, edges) if ans is None: print("inf") else: print((-ans)) def BellmanFord(N, M, edges): d = [inf] * N d[0] = 0 for i in range(N - 1): for (u, v, c) in edges: if d[u] + c < d[v]: d[v] = d[u] + c for i in range(N): for (u, v, c) in edges: if d[u] + c < d[v]: if v == N - 1: return None d[v] = d[u] + c return d[N - 1] if __name__ == "__main__": solve()
false
46.753247
[ "-from collections import Counter", "-sys.setrecursionlimit(10**7)", "-inf = 1 << 100", "+inf = 1 << 60", "- Adj = [[] for i in range(N)]", "- ui, vi, ci = list(map(int, sys.stdin.readline().split()))", "- ui, vi = ui - 1, vi - 1", "- edges[i] = (ui, vi, -ci)", "- Adj[ui].append(vi)", "- visitable = [False] * N", "- dfs(N, M, Adj, visitable, 0)", "- reachable = [False] * N", "- reachable[0] = True", "- reachable[N - 1] = True", "- for u in range(1, N - 1):", "- visited = [False] * N", "- dfs(N, M, Adj, visited, u)", "- if visited[N - 1]:", "- reachable[u] = True", "- ans = Bellmanford(N, M, edges, visitable, reachable)", "- if ans is not None:", "+ ai, bi, ci = list(map(int, sys.stdin.readline().split()))", "+ ai, bi = ai - 1, bi - 1", "+ edges[i] = (ai, bi, -ci)", "+ ans = BellmanFord(N, M, edges)", "+ if ans is None:", "+ print(\"inf\")", "+ else:", "- else:", "- print(\"inf\")", "-def dfs(N, M, Adj, visitable, u):", "- visitable[u] = True", "- for v in Adj[u]:", "- if not visitable[v]:", "- dfs(N, M, Adj, visitable, v)", "-", "-", "-def Bellmanford(N, M, edges, visitable, reachable):", "- dist = [inf] * N", "- dist[0] = 0", "- flag = True", "- cnt = 0", "+def BellmanFord(N, M, edges):", "+ d = [inf] * N", "+ d[0] = 0", "+ for i in range(N - 1):", "+ for (u, v, c) in edges:", "+ if d[u] + c < d[v]:", "+ d[v] = d[u] + c", "- flag = False", "- if dist[u] != inf and dist[v] > dist[u] + c:", "- dist[v] = dist[u] + c", "- if visitable[v] and reachable[v]:", "- flag = True", "- # print(dist)", "- if not flag:", "- break", "- if flag and i == N - 1:", "- return None", "- return dist[N - 1]", "+ if d[u] + c < d[v]:", "+ if v == N - 1:", "+ return None", "+ d[v] = d[u] + c", "+ return d[N - 1]" ]
false
0.037411
0.035605
1.050715
[ "s782734732", "s044590260" ]
u761529120
p03411
python
s874414610
s882286968
181
67
39,024
63,932
Accepted
Accepted
62.98
def main(): N = int(eval(input())) Red = [] Blue = [] for i in range(N): a, b = list(map(int, input().split())) Red.append([b,a]) for i in range(N): c, d = list(map(int, input().split())) Blue.append([c,d]) Red.sort(reverse=True) Blue.sort() ans = 0 for x, y in Blue: for v, u in Red: if x > u and y > v: ans += 1 Red.remove([v,u]) break print(ans) if __name__ == "__main__": main()
from bisect import bisect_left def main(): N = int(eval(input())) ball = [] for i in range(N): a, b = list(map(int, input().split())) ball.append([a,b,'r']) for i in range(N): c, d = list(map(int, input().split())) ball.append([c,d,'b']) sort_ball = sorted(ball, key=lambda x:(-x[0],x[1])) ans = 0 cand = [] for i in range(2*N): if sort_ball[i][2] == 'b': cand.append(sort_ball[i][1]) if sort_ball[i][2] == 'r': if not cand: continue cand.sort() b_y = bisect_left(cand, sort_ball[i][1]) if b_y == len(cand): continue ans += 1 cand.pop(b_y) print(ans) if __name__ == "__main__": main()
25
39
539
839
def main(): N = int(eval(input())) Red = [] Blue = [] for i in range(N): a, b = list(map(int, input().split())) Red.append([b, a]) for i in range(N): c, d = list(map(int, input().split())) Blue.append([c, d]) Red.sort(reverse=True) Blue.sort() ans = 0 for x, y in Blue: for v, u in Red: if x > u and y > v: ans += 1 Red.remove([v, u]) break print(ans) if __name__ == "__main__": main()
from bisect import bisect_left def main(): N = int(eval(input())) ball = [] for i in range(N): a, b = list(map(int, input().split())) ball.append([a, b, "r"]) for i in range(N): c, d = list(map(int, input().split())) ball.append([c, d, "b"]) sort_ball = sorted(ball, key=lambda x: (-x[0], x[1])) ans = 0 cand = [] for i in range(2 * N): if sort_ball[i][2] == "b": cand.append(sort_ball[i][1]) if sort_ball[i][2] == "r": if not cand: continue cand.sort() b_y = bisect_left(cand, sort_ball[i][1]) if b_y == len(cand): continue ans += 1 cand.pop(b_y) print(ans) if __name__ == "__main__": main()
false
35.897436
[ "+from bisect import bisect_left", "+", "+", "- Red = []", "- Blue = []", "+ ball = []", "- Red.append([b, a])", "+ ball.append([a, b, \"r\"])", "- Blue.append([c, d])", "- Red.sort(reverse=True)", "- Blue.sort()", "+ ball.append([c, d, \"b\"])", "+ sort_ball = sorted(ball, key=lambda x: (-x[0], x[1]))", "- for x, y in Blue:", "- for v, u in Red:", "- if x > u and y > v:", "- ans += 1", "- Red.remove([v, u])", "- break", "+ cand = []", "+ for i in range(2 * N):", "+ if sort_ball[i][2] == \"b\":", "+ cand.append(sort_ball[i][1])", "+ if sort_ball[i][2] == \"r\":", "+ if not cand:", "+ continue", "+ cand.sort()", "+ b_y = bisect_left(cand, sort_ball[i][1])", "+ if b_y == len(cand):", "+ continue", "+ ans += 1", "+ cand.pop(b_y)" ]
false
0.042276
0.10723
0.39426
[ "s874414610", "s882286968" ]
u186838327
p03779
python
s773259636
s692731443
182
62
38,512
63,060
Accepted
Accepted
65.93
x = int(eval(input())) temp = 0 for i in range(x+1): temp += i if temp >= x: print(i) exit()
x = int(eval(input())) for i in range(10**6): if i*(i+1)//2 >= x: print(i) exit()
7
5
117
100
x = int(eval(input())) temp = 0 for i in range(x + 1): temp += i if temp >= x: print(i) exit()
x = int(eval(input())) for i in range(10**6): if i * (i + 1) // 2 >= x: print(i) exit()
false
28.571429
[ "-temp = 0", "-for i in range(x + 1):", "- temp += i", "- if temp >= x:", "+for i in range(10**6):", "+ if i * (i + 1) // 2 >= x:" ]
false
0.046969
0.036073
1.302048
[ "s773259636", "s692731443" ]
u970197315
p03559
python
s573985979
s901958192
345
319
23,360
22,516
Accepted
Accepted
7.54
from bisect import bisect_left,bisect_right 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=0 for i in range(n): ai=bisect_left(a,b[i]) ci=bisect_right(c,b[i]) ans+=ai*(n-ci) print(ans)
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() from bisect import bisect_left,bisect_right ans=0 for i in range(n): ida=bisect_left(a,b[i]) idc=bisect_right(c,b[i]) ans+=ida*(n-idc) print(ans)
15
14
310
305
from bisect import bisect_left, bisect_right 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 = 0 for i in range(n): ai = bisect_left(a, b[i]) ci = bisect_right(c, b[i]) ans += ai * (n - ci) print(ans)
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() from bisect import bisect_left, bisect_right ans = 0 for i in range(n): ida = bisect_left(a, b[i]) idc = bisect_right(c, b[i]) ans += ida * (n - idc) print(ans)
false
6.666667
[ "-from bisect import bisect_left, bisect_right", "-", "+from bisect import bisect_left, bisect_right", "+", "- ai = bisect_left(a, b[i])", "- ci = bisect_right(c, b[i])", "- ans += ai * (n - ci)", "+ ida = bisect_left(a, b[i])", "+ idc = bisect_right(c, b[i])", "+ ans += ida * (n - idc)" ]
false
0.039663
0.139212
0.284914
[ "s573985979", "s901958192" ]
u127499732
p03112
python
s579501219
s554995107
778
468
36,612
36,564
Accepted
Accepted
39.85
def main(): from bisect import bisect_left as bl a, b, q, *stx = list(map(int, open(0).read().split())) s = [-float('Inf')] + stx[:a] + [float('Inf')] t = [-float('Inf')] + stx[a:a + b] + [float('Inf')] x = stx[a + b:] tmp = [] for i in x: f, g = bl(s, i), bl(t, i) sl, sr = s[f - 1], s[f] tl, tr = t[g - 1], t[g] d = float('Inf') for j in [sl, sr]: for k in [tr, tl]: if j <= i and k <= i: d = min(d, i - min(j, k)) elif j <= i <= k or k <= i <= j: d = min(d, min(abs(i - j), abs(i - k)) * 2 + max(abs(i - j), abs(i - k))) else: d = min(d, max(j, k) - i) tmp.append(d) ans = '\n'.join(map(str, tmp)) print(ans) if __name__ == '__main__': main()
def main(): from bisect import bisect_left as bl a, b, q, *stx = list(map(int, open(0).read().split())) s = [-float('Inf')] + stx[:a] + [float('Inf')] t = [-float('Inf')] + stx[a:a + b] + [float('Inf')] x = stx[a + b:] tmp = [] for i in x: f, g = bl(s, i), bl(t, i) sr, sl = s[f - 1], s[f] tr, tl = t[g - 1], t[g] d = min([max(sl, tl) - i, i - min(sr, tr), 2 * (tl - sr) - max(i - sr, tl - i), 2 * (sl - tr) - max(sl - i, i - tr)]) tmp.append(d) ans = '\n'.join(map(str, tmp)) print(ans) if __name__ == '__main__': main()
31
22
884
622
def main(): from bisect import bisect_left as bl a, b, q, *stx = list(map(int, open(0).read().split())) s = [-float("Inf")] + stx[:a] + [float("Inf")] t = [-float("Inf")] + stx[a : a + b] + [float("Inf")] x = stx[a + b :] tmp = [] for i in x: f, g = bl(s, i), bl(t, i) sl, sr = s[f - 1], s[f] tl, tr = t[g - 1], t[g] d = float("Inf") for j in [sl, sr]: for k in [tr, tl]: if j <= i and k <= i: d = min(d, i - min(j, k)) elif j <= i <= k or k <= i <= j: d = min( d, min(abs(i - j), abs(i - k)) * 2 + max(abs(i - j), abs(i - k)) ) else: d = min(d, max(j, k) - i) tmp.append(d) ans = "\n".join(map(str, tmp)) print(ans) if __name__ == "__main__": main()
def main(): from bisect import bisect_left as bl a, b, q, *stx = list(map(int, open(0).read().split())) s = [-float("Inf")] + stx[:a] + [float("Inf")] t = [-float("Inf")] + stx[a : a + b] + [float("Inf")] x = stx[a + b :] tmp = [] for i in x: f, g = bl(s, i), bl(t, i) sr, sl = s[f - 1], s[f] tr, tl = t[g - 1], t[g] d = min( [ max(sl, tl) - i, i - min(sr, tr), 2 * (tl - sr) - max(i - sr, tl - i), 2 * (sl - tr) - max(sl - i, i - tr), ] ) tmp.append(d) ans = "\n".join(map(str, tmp)) print(ans) if __name__ == "__main__": main()
false
29.032258
[ "- sl, sr = s[f - 1], s[f]", "- tl, tr = t[g - 1], t[g]", "- d = float(\"Inf\")", "- for j in [sl, sr]:", "- for k in [tr, tl]:", "- if j <= i and k <= i:", "- d = min(d, i - min(j, k))", "- elif j <= i <= k or k <= i <= j:", "- d = min(", "- d, min(abs(i - j), abs(i - k)) * 2 + max(abs(i - j), abs(i - k))", "- )", "- else:", "- d = min(d, max(j, k) - i)", "+ sr, sl = s[f - 1], s[f]", "+ tr, tl = t[g - 1], t[g]", "+ d = min(", "+ [", "+ max(sl, tl) - i,", "+ i - min(sr, tr),", "+ 2 * (tl - sr) - max(i - sr, tl - i),", "+ 2 * (sl - tr) - max(sl - i, i - tr),", "+ ]", "+ )" ]
false
0.040575
0.04016
1.010345
[ "s579501219", "s554995107" ]
u284744415
p02899
python
s864602725
s788134697
187
159
24,180
24,180
Accepted
Accepted
14.97
n = int(eval(input())) print((" ".join([str(x[1]) for x in sorted([(int(a), num) for a, num in zip(input().split(" "), list(range(1,n + 1)))])])))
print((" ".join([str(x[0]) for x in sorted([(num, int(a)) for num, a in zip(list(range(1,int(eval(input())) + 1)), input().split(" "))], key=lambda x: x[1],)])))
2
1
144
158
n = int(eval(input())) print( ( " ".join( [ str(x[1]) for x in sorted( [ (int(a), num) for a, num in zip(input().split(" "), list(range(1, n + 1))) ] ) ] ) ) )
print( ( " ".join( [ str(x[0]) for x in sorted( [ (num, int(a)) for num, a in zip( list(range(1, int(eval(input())) + 1)), input().split(" ") ) ], key=lambda x: x[1], ) ] ) ) )
false
50
[ "-n = int(eval(input()))", "- str(x[1])", "+ str(x[0])", "- (int(a), num)", "- for a, num in zip(input().split(\" \"), list(range(1, n + 1)))", "- ]", "+ (num, int(a))", "+ for num, a in zip(", "+ list(range(1, int(eval(input())) + 1)), input().split(\" \")", "+ )", "+ ],", "+ key=lambda x: x[1]," ]
false
0.041613
0.043754
0.951067
[ "s864602725", "s788134697" ]
u191874006
p03244
python
s526973744
s818977370
284
252
64,272
62,304
Accepted
Accepted
11.27
#!/usr/bin/env python3 #ABC111 C import sys import math import bisect sys.setrecursionlimit(1000000000) from heapq import heappush, heappop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() v = LI() s,t = [],[] for i in range(n): if i % 2: t.append(v[i]) else: s.append(v[i]) s = list(Counter(s).items()) s.sort(key = itemgetter(1),reverse = True) t = list(Counter(t).items()) t.sort(key = itemgetter(1),reverse = True) m = min(len(s),len(t)) for i in range(m): a,b = s[i] c,d = t[i] if a != c: print(((n//2 - b)+(n//2 - d))) quit() elif a == c: if i + 1 < len(s) - 1: tmp1 = s[i+1][1] else: tmp1 = 0 if i + 1 < len(t) - 1: tmp2 = t[i+1][1] else: tmp2 = 0 print((min(((n//2 - b) + (n//2 - tmp2),((n//2 - d) + (n//2 - tmp1)))))) quit()
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() v = LI() a = [] b = [] for i in range(n): if i % 2 == 0: a.append(v[i]) else: b.append(v[i]) a = list(Counter(a).items()) b = list(Counter(b).items()) a.sort(key = lambda x:x[1], reverse=1) b.sort(key = lambda x:x[1], reverse=1) if len(a) == 1 and len(b) == 1: if a[0][0] == b[0][0]: print((n//2)) else: print((0)) elif len(a) > 1 and len(b) == 1: if a[0][0] == b[0][0]: print(((n-1)//2 + 1 - a[1][1])) else: print(((n-1)//2 + 1 - a[0][1])) elif len(a) == 1 and len(b) > 1: if a[0][0] == b[0][0]: print((n//2 - b[1][1])) else: print((n//2 - b[0][1])) else: if a[0][0] == b[0][0]: print((min((n-1)//2 + 1 - a[1][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[1][1]))) else: print((min((n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1])))
49
52
1,227
1,496
#!/usr/bin/env python3 # ABC111 C import sys import math import bisect sys.setrecursionlimit(1000000000) from heapq import heappush, heappop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() v = LI() s, t = [], [] for i in range(n): if i % 2: t.append(v[i]) else: s.append(v[i]) s = list(Counter(s).items()) s.sort(key=itemgetter(1), reverse=True) t = list(Counter(t).items()) t.sort(key=itemgetter(1), reverse=True) m = min(len(s), len(t)) for i in range(m): a, b = s[i] c, d = t[i] if a != c: print(((n // 2 - b) + (n // 2 - d))) quit() elif a == c: if i + 1 < len(s) - 1: tmp1 = s[i + 1][1] else: tmp1 = 0 if i + 1 < len(t) - 1: tmp2 = t[i + 1][1] else: tmp2 = 0 print((min(((n // 2 - b) + (n // 2 - tmp2), ((n // 2 - d) + (n // 2 - tmp1)))))) quit()
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() v = LI() a = [] b = [] for i in range(n): if i % 2 == 0: a.append(v[i]) else: b.append(v[i]) a = list(Counter(a).items()) b = list(Counter(b).items()) a.sort(key=lambda x: x[1], reverse=1) b.sort(key=lambda x: x[1], reverse=1) if len(a) == 1 and len(b) == 1: if a[0][0] == b[0][0]: print((n // 2)) else: print((0)) elif len(a) > 1 and len(b) == 1: if a[0][0] == b[0][0]: print(((n - 1) // 2 + 1 - a[1][1])) else: print(((n - 1) // 2 + 1 - a[0][1])) elif len(a) == 1 and len(b) > 1: if a[0][0] == b[0][0]: print((n // 2 - b[1][1])) else: print((n // 2 - b[0][1])) else: if a[0][0] == b[0][0]: print( ( min( (n - 1) // 2 + 1 - a[1][1] + (n // 2) - b[0][1], (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[1][1], ) ) ) else: print( ( min( (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[0][1], (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[0][1], ) ) )
false
5.769231
[ "-# ABC111 C", "-import bisect", "+from bisect import bisect_right as br", "+from bisect import bisect_left as bl", "-sys.setrecursionlimit(1000000000)", "-from heapq import heappush, heappop", "+sys.setrecursionlimit(2147483647)", "+from heapq import heappush, heappop, heappushpop", "-s, t = [], []", "+a = []", "+b = []", "- if i % 2:", "- t.append(v[i])", "+ if i % 2 == 0:", "+ a.append(v[i])", "- s.append(v[i])", "-s = list(Counter(s).items())", "-s.sort(key=itemgetter(1), reverse=True)", "-t = list(Counter(t).items())", "-t.sort(key=itemgetter(1), reverse=True)", "-m = min(len(s), len(t))", "-for i in range(m):", "- a, b = s[i]", "- c, d = t[i]", "- if a != c:", "- print(((n // 2 - b) + (n // 2 - d)))", "- quit()", "- elif a == c:", "- if i + 1 < len(s) - 1:", "- tmp1 = s[i + 1][1]", "- else:", "- tmp1 = 0", "- if i + 1 < len(t) - 1:", "- tmp2 = t[i + 1][1]", "- else:", "- tmp2 = 0", "- print((min(((n // 2 - b) + (n // 2 - tmp2), ((n // 2 - d) + (n // 2 - tmp1))))))", "- quit()", "+ b.append(v[i])", "+a = list(Counter(a).items())", "+b = list(Counter(b).items())", "+a.sort(key=lambda x: x[1], reverse=1)", "+b.sort(key=lambda x: x[1], reverse=1)", "+if len(a) == 1 and len(b) == 1:", "+ if a[0][0] == b[0][0]:", "+ print((n // 2))", "+ else:", "+ print((0))", "+elif len(a) > 1 and len(b) == 1:", "+ if a[0][0] == b[0][0]:", "+ print(((n - 1) // 2 + 1 - a[1][1]))", "+ else:", "+ print(((n - 1) // 2 + 1 - a[0][1]))", "+elif len(a) == 1 and len(b) > 1:", "+ if a[0][0] == b[0][0]:", "+ print((n // 2 - b[1][1]))", "+ else:", "+ print((n // 2 - b[0][1]))", "+else:", "+ if a[0][0] == b[0][0]:", "+ print(", "+ (", "+ min(", "+ (n - 1) // 2 + 1 - a[1][1] + (n // 2) - b[0][1],", "+ (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[1][1],", "+ )", "+ )", "+ )", "+ else:", "+ print(", "+ (", "+ min(", "+ (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[0][1],", "+ (n - 1) // 2 + 1 - a[0][1] + (n // 2) - b[0][1],", "+ )", "+ )", "+ )" ]
false
0.035294
0.099013
0.356456
[ "s526973744", "s818977370" ]
u077291787
p03160
python
s311286117
s720006678
204
157
24,264
13,876
Accepted
Accepted
23.04
# A - Frog 1 from collections import defaultdict def main(): N, *H = list(map(int, open(0).read().split())) H = [0] + H + [0, 0] dp = defaultdict(lambda: 1 << 30) dp[1] = 0 for i, a in enumerate(H[1:N + 1], 1): for j, b in enumerate(H[i + 1:i + 3], i + 1): dp[j] = min(dp[j], dp[i] + abs(a - b)) print((dp[N])) if __name__ == "__main__": main()
# A - Frog 1 def main(): N, *H = list(map(int, open(0).read().split())) H = [0] + H + [0, 0] dp = [1 << 30] * (N + 3) dp[1] = 0 for i, a in enumerate(H[1:N + 1], 1): for j, b in enumerate(H[i + 1:i + 3], i + 1): dp[j] = min(dp[j], dp[i] + abs(a - b)) print((dp[N])) if __name__ == "__main__": main()
17
14
405
355
# A - Frog 1 from collections import defaultdict def main(): N, *H = list(map(int, open(0).read().split())) H = [0] + H + [0, 0] dp = defaultdict(lambda: 1 << 30) dp[1] = 0 for i, a in enumerate(H[1 : N + 1], 1): for j, b in enumerate(H[i + 1 : i + 3], i + 1): dp[j] = min(dp[j], dp[i] + abs(a - b)) print((dp[N])) if __name__ == "__main__": main()
# A - Frog 1 def main(): N, *H = list(map(int, open(0).read().split())) H = [0] + H + [0, 0] dp = [1 << 30] * (N + 3) dp[1] = 0 for i, a in enumerate(H[1 : N + 1], 1): for j, b in enumerate(H[i + 1 : i + 3], i + 1): dp[j] = min(dp[j], dp[i] + abs(a - b)) print((dp[N])) if __name__ == "__main__": main()
false
17.647059
[ "-from collections import defaultdict", "-", "-", "- dp = defaultdict(lambda: 1 << 30)", "+ dp = [1 << 30] * (N + 3)" ]
false
0.04638
0.046885
0.989223
[ "s311286117", "s720006678" ]
u896847891
p02783
python
s394795717
s629738523
20
17
2,940
2,940
Accepted
Accepted
15
h,a=list(map(int,input().split())) print((int((h-1)/a)+1))
h, a = list(map(int, input().split())) print(((h+a-1)//a))
2
2
51
51
h, a = list(map(int, input().split())) print((int((h - 1) / a) + 1))
h, a = list(map(int, input().split())) print(((h + a - 1) // a))
false
0
[ "-print((int((h - 1) / a) + 1))", "+print(((h + a - 1) // a))" ]
false
0.069312
0.064963
1.066938
[ "s394795717", "s629738523" ]
u298297089
p03330
python
s081911357
s222938177
972
237
3,064
3,188
Accepted
Accepted
75.62
from itertools import permutations as perm N,C = list(map(int, input().split())) colors = [] for i in range(C): colors.append(list(map(int, input().split()))) grids = {0:{}, 1:{}, 2:{}} for i in range(1,N+1): A =list(map(int, input().split())) for j in range(N): if A[j] not in grids[(i+j+1)%3]: grids[(i+j+1)%3][A[j]] = 1 else: grids[(i+j+1)%3][A[j]] += 1 mn = 10**9 for color in perm([i for i in range(1,C+1)], 3): tmp = 0 for i in range(3): for k,v in list(grids[i].items()): tmp += colors[k-1][color[i]-1] * v mn = min(mn, tmp) print(mn)
n,c = list(map(int, input().split())) color, grid = [], [] for _ in range(c): color.append(list(map(int, input().split()))) grid = {i:{} for i in range(3)} for i in range(n): for j,t in enumerate(map(int, input().split())): t -= 1 if t not in grid[(i+j + 2) % 3]: grid[(i+j + 2) % 3][t] = 0 grid[(i+j + 2) % 3][t] += 1 costs = [[0 for _ in range(c)],[0 for _ in range(c)],[0 for _ in range(c)]] for cc in range(c): for i in range(3): for d,cnt in list(grid[i].items()): costs[i][cc] += color[d][cc] * cnt x = sorted(list(range(c)), key=lambda x: costs[0][x])[:3] y = sorted(list(range(c)), key=lambda x: costs[1][x])[:3] z = sorted(list(range(c)), key=lambda x: costs[2][x])[:3] mn = 10**9 for i in x: for j in y: for k in z: if i == j or j == k or k == i: continue if mn > costs[0][i] + costs[1][j] + costs[2][k]: mn = costs[0][i] + costs[1][j] + costs[2][k] print(mn)
22
31
635
1,026
from itertools import permutations as perm N, C = list(map(int, input().split())) colors = [] for i in range(C): colors.append(list(map(int, input().split()))) grids = {0: {}, 1: {}, 2: {}} for i in range(1, N + 1): A = list(map(int, input().split())) for j in range(N): if A[j] not in grids[(i + j + 1) % 3]: grids[(i + j + 1) % 3][A[j]] = 1 else: grids[(i + j + 1) % 3][A[j]] += 1 mn = 10**9 for color in perm([i for i in range(1, C + 1)], 3): tmp = 0 for i in range(3): for k, v in list(grids[i].items()): tmp += colors[k - 1][color[i] - 1] * v mn = min(mn, tmp) print(mn)
n, c = list(map(int, input().split())) color, grid = [], [] for _ in range(c): color.append(list(map(int, input().split()))) grid = {i: {} for i in range(3)} for i in range(n): for j, t in enumerate(map(int, input().split())): t -= 1 if t not in grid[(i + j + 2) % 3]: grid[(i + j + 2) % 3][t] = 0 grid[(i + j + 2) % 3][t] += 1 costs = [[0 for _ in range(c)], [0 for _ in range(c)], [0 for _ in range(c)]] for cc in range(c): for i in range(3): for d, cnt in list(grid[i].items()): costs[i][cc] += color[d][cc] * cnt x = sorted(list(range(c)), key=lambda x: costs[0][x])[:3] y = sorted(list(range(c)), key=lambda x: costs[1][x])[:3] z = sorted(list(range(c)), key=lambda x: costs[2][x])[:3] mn = 10**9 for i in x: for j in y: for k in z: if i == j or j == k or k == i: continue if mn > costs[0][i] + costs[1][j] + costs[2][k]: mn = costs[0][i] + costs[1][j] + costs[2][k] print(mn)
false
29.032258
[ "-from itertools import permutations as perm", "-", "-N, C = list(map(int, input().split()))", "-colors = []", "-for i in range(C):", "- colors.append(list(map(int, input().split())))", "-grids = {0: {}, 1: {}, 2: {}}", "-for i in range(1, N + 1):", "- A = list(map(int, input().split()))", "- for j in range(N):", "- if A[j] not in grids[(i + j + 1) % 3]:", "- grids[(i + j + 1) % 3][A[j]] = 1", "- else:", "- grids[(i + j + 1) % 3][A[j]] += 1", "+n, c = list(map(int, input().split()))", "+color, grid = [], []", "+for _ in range(c):", "+ color.append(list(map(int, input().split())))", "+grid = {i: {} for i in range(3)}", "+for i in range(n):", "+ for j, t in enumerate(map(int, input().split())):", "+ t -= 1", "+ if t not in grid[(i + j + 2) % 3]:", "+ grid[(i + j + 2) % 3][t] = 0", "+ grid[(i + j + 2) % 3][t] += 1", "+costs = [[0 for _ in range(c)], [0 for _ in range(c)], [0 for _ in range(c)]]", "+for cc in range(c):", "+ for i in range(3):", "+ for d, cnt in list(grid[i].items()):", "+ costs[i][cc] += color[d][cc] * cnt", "+x = sorted(list(range(c)), key=lambda x: costs[0][x])[:3]", "+y = sorted(list(range(c)), key=lambda x: costs[1][x])[:3]", "+z = sorted(list(range(c)), key=lambda x: costs[2][x])[:3]", "-for color in perm([i for i in range(1, C + 1)], 3):", "- tmp = 0", "- for i in range(3):", "- for k, v in list(grids[i].items()):", "- tmp += colors[k - 1][color[i] - 1] * v", "- mn = min(mn, tmp)", "+for i in x:", "+ for j in y:", "+ for k in z:", "+ if i == j or j == k or k == i:", "+ continue", "+ if mn > costs[0][i] + costs[1][j] + costs[2][k]:", "+ mn = costs[0][i] + costs[1][j] + costs[2][k]" ]
false
0.046136
0.045848
1.006282
[ "s081911357", "s222938177" ]
u927534107
p03044
python
s396128196
s338961295
862
748
57,692
57,692
Accepted
Accepted
13.23
n=int(eval(input())) c=[[] for i in range(n+1)] d={} for i in range(n-1): x,y,z=list(map(int,input().split())) c[x].append(y) c[y].append(x) d[x,y]=z d[1,1]=0 stack=[1] parent=[None]*(n+1) while stack: i=stack.pop() for j in c[i]: if j==parent[i]: continue parent[j]=i d[1,j]=d[1,i]+d[tuple(sorted([i,j]))] stack.append(j) for i in range(1,n+1): print((d[1,i]%2))
import sys input = sys.stdin.readline n=int(eval(input())) c=[[] for i in range(n+1)] d={} for i in range(n-1): x,y,z=list(map(int,input().split())) c[x].append(y) c[y].append(x) d[x,y]=z d[1,1]=0 stack=[1] parent=[None]*(n+1) while stack: i=stack.pop() for j in c[i]: if j==parent[i]: continue parent[j]=i d[1,j]=d[1,i]+d[tuple(sorted([i,j]))] stack.append(j) for i in range(1,n+1): print((d[1,i]%2))
21
23
441
481
n = int(eval(input())) c = [[] for i in range(n + 1)] d = {} for i in range(n - 1): x, y, z = list(map(int, input().split())) c[x].append(y) c[y].append(x) d[x, y] = z d[1, 1] = 0 stack = [1] parent = [None] * (n + 1) while stack: i = stack.pop() for j in c[i]: if j == parent[i]: continue parent[j] = i d[1, j] = d[1, i] + d[tuple(sorted([i, j]))] stack.append(j) for i in range(1, n + 1): print((d[1, i] % 2))
import sys input = sys.stdin.readline n = int(eval(input())) c = [[] for i in range(n + 1)] d = {} for i in range(n - 1): x, y, z = list(map(int, input().split())) c[x].append(y) c[y].append(x) d[x, y] = z d[1, 1] = 0 stack = [1] parent = [None] * (n + 1) while stack: i = stack.pop() for j in c[i]: if j == parent[i]: continue parent[j] = i d[1, j] = d[1, i] + d[tuple(sorted([i, j]))] stack.append(j) for i in range(1, n + 1): print((d[1, i] % 2))
false
8.695652
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.232763
0.046436
5.012512
[ "s396128196", "s338961295" ]
u017415492
p03061
python
s521588429
s580401332
146
135
21,100
25,768
Accepted
Accepted
7.53
import math n=int(eval(input())) a = list(map(int,input().split())) a.sort() lr=[0]*n rl=[0]*n for i in range(n): if i==0: g=a[0] lr[0]=g else: g=math.gcd(a[i],g) lr[i]=g for i in range(n-1,0,-1): if n-1==i: g=a[n-1] rl[n-1]=g else: g=math.gcd(a[i],g) rl[i]=g hantei=0 ans=0 #print(lr) #print(rl) for i in range(n): if i==0: hantei=rl[1] elif i==n-1: hantei=lr[n-2] else: hantei=math.gcd(lr[i-1],rl[i+1]) if ans<=hantei: ans=hantei print(ans)
import math n=int(eval(input())) a=list(map(int,input().split())) ra=list(reversed(a)) left=[] right=[] right.append(ra[0]) left.append(a[0]) if n>2: k=math.gcd(a[0],a[1]) left.append(k) for i in range(2,n-1): k=math.gcd(k,a[i]) left.append(k) k=math.gcd(ra[0],ra[1]) right.append(k) for i in range(2,n-1): k=math.gcd(k,ra[i]) right.append(k) ans=[right[-1]] for i in range(1,n-1): ans.append(math.gcd(left[i-1],right[len(right)-i-1])) ans.append(left[-1]) print((max(ans))) else: print((max(a[1],a[0])))
37
31
549
571
import math n = int(eval(input())) a = list(map(int, input().split())) a.sort() lr = [0] * n rl = [0] * n for i in range(n): if i == 0: g = a[0] lr[0] = g else: g = math.gcd(a[i], g) lr[i] = g for i in range(n - 1, 0, -1): if n - 1 == i: g = a[n - 1] rl[n - 1] = g else: g = math.gcd(a[i], g) rl[i] = g hantei = 0 ans = 0 # print(lr) # print(rl) for i in range(n): if i == 0: hantei = rl[1] elif i == n - 1: hantei = lr[n - 2] else: hantei = math.gcd(lr[i - 1], rl[i + 1]) if ans <= hantei: ans = hantei print(ans)
import math n = int(eval(input())) a = list(map(int, input().split())) ra = list(reversed(a)) left = [] right = [] right.append(ra[0]) left.append(a[0]) if n > 2: k = math.gcd(a[0], a[1]) left.append(k) for i in range(2, n - 1): k = math.gcd(k, a[i]) left.append(k) k = math.gcd(ra[0], ra[1]) right.append(k) for i in range(2, n - 1): k = math.gcd(k, ra[i]) right.append(k) ans = [right[-1]] for i in range(1, n - 1): ans.append(math.gcd(left[i - 1], right[len(right) - i - 1])) ans.append(left[-1]) print((max(ans))) else: print((max(a[1], a[0])))
false
16.216216
[ "-a.sort()", "-lr = [0] * n", "-rl = [0] * n", "-for i in range(n):", "- if i == 0:", "- g = a[0]", "- lr[0] = g", "- else:", "- g = math.gcd(a[i], g)", "- lr[i] = g", "-for i in range(n - 1, 0, -1):", "- if n - 1 == i:", "- g = a[n - 1]", "- rl[n - 1] = g", "- else:", "- g = math.gcd(a[i], g)", "- rl[i] = g", "-hantei = 0", "-ans = 0", "-# print(lr)", "-# print(rl)", "-for i in range(n):", "- if i == 0:", "- hantei = rl[1]", "- elif i == n - 1:", "- hantei = lr[n - 2]", "- else:", "- hantei = math.gcd(lr[i - 1], rl[i + 1])", "- if ans <= hantei:", "- ans = hantei", "-print(ans)", "+ra = list(reversed(a))", "+left = []", "+right = []", "+right.append(ra[0])", "+left.append(a[0])", "+if n > 2:", "+ k = math.gcd(a[0], a[1])", "+ left.append(k)", "+ for i in range(2, n - 1):", "+ k = math.gcd(k, a[i])", "+ left.append(k)", "+ k = math.gcd(ra[0], ra[1])", "+ right.append(k)", "+ for i in range(2, n - 1):", "+ k = math.gcd(k, ra[i])", "+ right.append(k)", "+ ans = [right[-1]]", "+ for i in range(1, n - 1):", "+ ans.append(math.gcd(left[i - 1], right[len(right) - i - 1]))", "+ ans.append(left[-1])", "+ print((max(ans)))", "+else:", "+ print((max(a[1], a[0])))" ]
false
0.041875
0.088919
0.470928
[ "s521588429", "s580401332" ]
u832871520
p02773
python
s939927855
s175372816
723
642
45,040
45,040
Accepted
Accepted
11.2
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] C = Counter(S) l = [] max = C.most_common(1)[0][1] for c in C.most_common(): if max == c[1]: l.append(c[0]) else: break l.sort() for x in l: print(x)
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] C = Counter(S) l = [] max = C.most_common(1)[0][1] for c in C.most_common(): if max == c[1]: l.append(c[0]) else: break l.sort() print(("\n".join(l)))
14
13
271
265
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] C = Counter(S) l = [] max = C.most_common(1)[0][1] for c in C.most_common(): if max == c[1]: l.append(c[0]) else: break l.sort() for x in l: print(x)
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] C = Counter(S) l = [] max = C.most_common(1)[0][1] for c in C.most_common(): if max == c[1]: l.append(c[0]) else: break l.sort() print(("\n".join(l)))
false
7.142857
[ "-for x in l:", "- print(x)", "+print((\"\\n\".join(l)))" ]
false
0.043243
0.065507
0.660123
[ "s939927855", "s175372816" ]
u620084012
p03730
python
s424045194
s756925203
175
17
38,384
2,940
Accepted
Accepted
90.29
A, B, C = list(map(int,input().split())) for k in range(1,101): if (A*k)%B == C: print("YES") exit(0) print("NO")
A, B, C = list(map(int,input().split())) for k in range(1,B+1): if (A*k)%B == C: print("YES") exit(0) print("NO")
7
6
134
133
A, B, C = list(map(int, input().split())) for k in range(1, 101): if (A * k) % B == C: print("YES") exit(0) print("NO")
A, B, C = list(map(int, input().split())) for k in range(1, B + 1): if (A * k) % B == C: print("YES") exit(0) print("NO")
false
14.285714
[ "-for k in range(1, 101):", "+for k in range(1, B + 1):" ]
false
0.078154
0.036939
2.115744
[ "s424045194", "s756925203" ]
u642883360
p03545
python
s090712082
s082178331
184
162
38,384
38,496
Accepted
Accepted
11.96
s = input() a = int(s[0]) b = int(s[1]) c = int(s[2]) d = int(s[3]) for i in range(2): for j in range(2): for k in range(2): x = a + b*(-1)**i + c*(-1)**j + d*(-1)**k if x == 7: print(a, end='') print('-' if i else '+', end='') print(b, end='') print('-' if j else '+', end='') print(c, end='') print('-' if k else '+', end='') print(d, end='') print("=7") exit()
a, b, c, d = eval(input()) for x in "+-": for y in "+-": for z in "+-": f = a + x + b + y + c + z + d if eval(f) == 7: print((f + "=7")) exit()
20
8
428
159
s = input() a = int(s[0]) b = int(s[1]) c = int(s[2]) d = int(s[3]) for i in range(2): for j in range(2): for k in range(2): x = a + b * (-1) ** i + c * (-1) ** j + d * (-1) ** k if x == 7: print(a, end="") print("-" if i else "+", end="") print(b, end="") print("-" if j else "+", end="") print(c, end="") print("-" if k else "+", end="") print(d, end="") print("=7") exit()
a, b, c, d = eval(input()) for x in "+-": for y in "+-": for z in "+-": f = a + x + b + y + c + z + d if eval(f) == 7: print((f + "=7")) exit()
false
60
[ "-s = input()", "-a = int(s[0])", "-b = int(s[1])", "-c = int(s[2])", "-d = int(s[3])", "-for i in range(2):", "- for j in range(2):", "- for k in range(2):", "- x = a + b * (-1) ** i + c * (-1) ** j + d * (-1) ** k", "- if x == 7:", "- print(a, end=\"\")", "- print(\"-\" if i else \"+\", end=\"\")", "- print(b, end=\"\")", "- print(\"-\" if j else \"+\", end=\"\")", "- print(c, end=\"\")", "- print(\"-\" if k else \"+\", end=\"\")", "- print(d, end=\"\")", "- print(\"=7\")", "+a, b, c, d = eval(input())", "+for x in \"+-\":", "+ for y in \"+-\":", "+ for z in \"+-\":", "+ f = a + x + b + y + c + z + d", "+ if eval(f) == 7:", "+ print((f + \"=7\"))" ]
false
0.044186
0.036496
1.210713
[ "s090712082", "s082178331" ]
u810356688
p03986
python
s044522743
s571613240
177
56
41,052
5,092
Accepted
Accepted
68.36
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): X=eval(input()) cunt=0 cunt_s=0 for x in X: if x=='S': cunt_s+=1 elif cunt_s>0: cunt_s-=1 else: cunt+=1 print((cunt+cunt_s)) if __name__=='__main__': main()
import sys def input(): return sys.stdin.readline().rstrip() from collections import deque def main(): X=eval(input()) stack=deque() for x in X: if x=='S' or (x=='T' and (not stack or stack[-1]=='T')): stack.append(x) elif stack and stack[-1]=='S': stack.pop() print((len(stack))) if __name__=='__main__': main()
18
14
355
377
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): X = eval(input()) cunt = 0 cunt_s = 0 for x in X: if x == "S": cunt_s += 1 elif cunt_s > 0: cunt_s -= 1 else: cunt += 1 print((cunt + cunt_s)) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().rstrip() from collections import deque def main(): X = eval(input()) stack = deque() for x in X: if x == "S" or (x == "T" and (not stack or stack[-1] == "T")): stack.append(x) elif stack and stack[-1] == "S": stack.pop() print((len(stack))) if __name__ == "__main__": main()
false
22.222222
[ "-from collections import Counter", "+from collections import deque", "- cunt = 0", "- cunt_s = 0", "+ stack = deque()", "- if x == \"S\":", "- cunt_s += 1", "- elif cunt_s > 0:", "- cunt_s -= 1", "- else:", "- cunt += 1", "- print((cunt + cunt_s))", "+ if x == \"S\" or (x == \"T\" and (not stack or stack[-1] == \"T\")):", "+ stack.append(x)", "+ elif stack and stack[-1] == \"S\":", "+ stack.pop()", "+ print((len(stack)))" ]
false
0.042405
0.04546
0.9328
[ "s044522743", "s571613240" ]
u934442292
p02744
python
s015026913
s726112310
92
81
9,304
20,048
Accepted
Accepted
11.96
import sys from collections import deque input = sys.stdin.readline def dfs(N): alphabet = "abcdefghij" stack = deque(["a"]) while stack: s = stack.pop() if len(s) == N: print(s) continue for suffix in reversed(alphabet[:len(set(s)) + 1]): stack.append("".join((s, suffix))) def main(): N = int(eval(input())) dfs(N) if __name__ == "__main__": main()
import sys from collections import deque input = sys.stdin.readline def dfs(N): alphabet = "abcdefghij" stack = deque(["a"]) ans = [] while stack: s = stack.pop() if len(s) == N: ans.append(s) continue for suffix in reversed(alphabet[:len(set(s)) + 1]): stack.append("".join((s, suffix))) return ans def main(): N = int(eval(input())) ans = dfs(N) print(("\n".join(ans))) if __name__ == "__main__": main()
26
29
462
530
import sys from collections import deque input = sys.stdin.readline def dfs(N): alphabet = "abcdefghij" stack = deque(["a"]) while stack: s = stack.pop() if len(s) == N: print(s) continue for suffix in reversed(alphabet[: len(set(s)) + 1]): stack.append("".join((s, suffix))) def main(): N = int(eval(input())) dfs(N) if __name__ == "__main__": main()
import sys from collections import deque input = sys.stdin.readline def dfs(N): alphabet = "abcdefghij" stack = deque(["a"]) ans = [] while stack: s = stack.pop() if len(s) == N: ans.append(s) continue for suffix in reversed(alphabet[: len(set(s)) + 1]): stack.append("".join((s, suffix))) return ans def main(): N = int(eval(input())) ans = dfs(N) print(("\n".join(ans))) if __name__ == "__main__": main()
false
10.344828
[ "+ ans = []", "- print(s)", "+ ans.append(s)", "+ return ans", "- dfs(N)", "+ ans = dfs(N)", "+ print((\"\\n\".join(ans)))" ]
false
0.048505
0.116234
0.41731
[ "s015026913", "s726112310" ]
u706414019
p02898
python
s471780143
s502667168
59
54
18,380
18,568
Accepted
Accepted
8.47
import bisect N,K =list(map(int,input().split())) H =sorted(list(map(int,input().split()))) i = bisect.bisect(H,K-1) print((N-i))
N,K = list(map(int,input().split())) H = list(map(int,input().split())) counter = 0 for h in H: if h >= K: counter += 1 print(counter)
5
8
131
154
import bisect N, K = list(map(int, input().split())) H = sorted(list(map(int, input().split()))) i = bisect.bisect(H, K - 1) print((N - i))
N, K = list(map(int, input().split())) H = list(map(int, input().split())) counter = 0 for h in H: if h >= K: counter += 1 print(counter)
false
37.5
[ "-import bisect", "-", "-H = sorted(list(map(int, input().split())))", "-i = bisect.bisect(H, K - 1)", "-print((N - i))", "+H = list(map(int, input().split()))", "+counter = 0", "+for h in H:", "+ if h >= K:", "+ counter += 1", "+print(counter)" ]
false
0.050242
0.047942
1.047964
[ "s471780143", "s502667168" ]
u372550522
p03163
python
s008400485
s281069392
520
249
120,172
148,056
Accepted
Accepted
52.12
inf = 2**60 ''' def table(size, init): #配列生成 x = len(size) l = [init for i in range(size[x-1])] for i in range(x-1): l = [l for k in range(size[x-2-i])] return l ''' n, W = list(map(int, input().split())) w, v = [[0]*n for i in range(2)] for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[-1] * (W+1) for i in range(n+1)] dp[0][0] = 0 for i in range(n): for j in range(W+1): if dp[i][j] != -1: dp[i+1][j] = max(dp[i][j], dp[i+1][j]) if j+w[i] <= W: dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]]) print((max(dp[n])))
inf = 2**60 ''' def table(size, init): #配列生成 x = len(size) l = [init for i in range(size[x-1])] for i in range(x-1): l = [l for k in range(size[x-2-i])] return l ''' n, W = list(map(int, input().split())) w, v = [[0]*n for i in range(2)] for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (W+1) for i in range(n+1)] for i in range(n): for j in range(W+1): if j>=w[i]: dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]) else: dp[i+1][j] = dp[i][j] print((max(dp[n])))
26
26
599
559
inf = 2**60 """ def table(size, init): #配列生成 x = len(size) l = [init for i in range(size[x-1])] for i in range(x-1): l = [l for k in range(size[x-2-i])] return l """ n, W = list(map(int, input().split())) w, v = [[0] * n for i in range(2)] for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[-1] * (W + 1) for i in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(W + 1): if dp[i][j] != -1: dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]) if j + w[i] <= W: dp[i + 1][j + w[i]] = max(dp[i][j] + v[i], dp[i + 1][j + w[i]]) print((max(dp[n])))
inf = 2**60 """ def table(size, init): #配列生成 x = len(size) l = [init for i in range(size[x-1])] for i in range(x-1): l = [l for k in range(size[x-2-i])] return l """ n, W = list(map(int, input().split())) w, v = [[0] * n for i in range(2)] for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (W + 1) for i in range(n + 1)] for i in range(n): for j in range(W + 1): if j >= w[i]: dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]) else: dp[i + 1][j] = dp[i][j] print((max(dp[n])))
false
0
[ "-dp = [[-1] * (W + 1) for i in range(n + 1)]", "-dp[0][0] = 0", "+dp = [[0] * (W + 1) for i in range(n + 1)]", "- if dp[i][j] != -1:", "- dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])", "- if j + w[i] <= W:", "- dp[i + 1][j + w[i]] = max(dp[i][j] + v[i], dp[i + 1][j + w[i]])", "+ if j >= w[i]:", "+ dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])", "+ else:", "+ dp[i + 1][j] = dp[i][j]" ]
false
0.039707
0.063369
0.626603
[ "s008400485", "s281069392" ]
u814986259
p03311
python
s270380646
s742518098
261
218
26,608
26,764
Accepted
Accepted
16.48
import math N=int(eval(input())) A=list(map(int,input().split())) B=[A[i]-(i+1) for i in range(N)] B.sort() temp=0 if N%2==0: ans = B[N//2] ans2= B[N//2 -1] temp=0 for j in range(N): temp+= abs(B[j] - ans) temp2=0 for j in range(N): temp2+= abs(B[j] - ans2) ans= min(temp,temp2) else: ans = B[N//2] temp=0 for j in range(N): temp+= abs(B[j] - ans ) ans=temp print(ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) B = [A[i] - (i+1) for i in range(N)] B.sort() ans = 0 t = B[len(B)//2] for x in B: ans += abs(x - t) print(ans)
26
14
425
205
import math N = int(eval(input())) A = list(map(int, input().split())) B = [A[i] - (i + 1) for i in range(N)] B.sort() temp = 0 if N % 2 == 0: ans = B[N // 2] ans2 = B[N // 2 - 1] temp = 0 for j in range(N): temp += abs(B[j] - ans) temp2 = 0 for j in range(N): temp2 += abs(B[j] - ans2) ans = min(temp, temp2) else: ans = B[N // 2] temp = 0 for j in range(N): temp += abs(B[j] - ans) ans = temp print(ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) B = [A[i] - (i + 1) for i in range(N)] B.sort() ans = 0 t = B[len(B) // 2] for x in B: ans += abs(x - t) print(ans)
false
46.153846
[ "-import math", "+import collections", "-temp = 0", "-if N % 2 == 0:", "- ans = B[N // 2]", "- ans2 = B[N // 2 - 1]", "- temp = 0", "- for j in range(N):", "- temp += abs(B[j] - ans)", "- temp2 = 0", "- for j in range(N):", "- temp2 += abs(B[j] - ans2)", "- ans = min(temp, temp2)", "-else:", "- ans = B[N // 2]", "- temp = 0", "- for j in range(N):", "- temp += abs(B[j] - ans)", "- ans = temp", "+ans = 0", "+t = B[len(B) // 2]", "+for x in B:", "+ ans += abs(x - t)" ]
false
0.048621
0.04809
1.011041
[ "s270380646", "s742518098" ]
u419686324
p03829
python
s516550487
s481779004
88
70
14,252
15,020
Accepted
Accepted
20.45
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) acc = 0 for u, v in zip(x[:-1], x[1:]): acc += min(a * (v - u), b) print(acc)
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) print((sum([min(a * (v - u), b) for u, v in zip(x[:-1], x[1:])])))
8
4
164
140
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) acc = 0 for u, v in zip(x[:-1], x[1:]): acc += min(a * (v - u), b) print(acc)
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) print((sum([min(a * (v - u), b) for u, v in zip(x[:-1], x[1:])])))
false
50
[ "-acc = 0", "-for u, v in zip(x[:-1], x[1:]):", "- acc += min(a * (v - u), b)", "-print(acc)", "+print((sum([min(a * (v - u), b) for u, v in zip(x[:-1], x[1:])])))" ]
false
0.101438
0.035449
2.861553
[ "s516550487", "s481779004" ]
u075012704
p02991
python
s599128325
s703515537
1,482
1,365
115,876
90,668
Accepted
Accepted
7.89
import heapq N, M = list(map(int, input().split())) Edge = [list(map(int, input().split())) for i in range(M)] S, T = list(map(int, input().split())) S, T = S - 1, T - 1 G3 = [[] for i in range(3 * N)] for u, v in Edge: u, v = u - 1, v - 1 G3[u].append([v + N, 1]) G3[u + N].append([v + N * 2, 1]) G3[u + 2 * N].append([v, 1]) def dijkstra(x): d = [float('inf')] * (3 * N) d[x] = 0 visited = {x} # d, u hq = [(0, x)] while hq: u = heapq.heappop(hq)[1] visited.add(u) for node, cost in G3[u]: if (node not in visited) and d[node] > d[u] + cost: d[node] = d[u] + cost heapq.heappush(hq, (d[u] + cost, node)) return d dist = dijkstra(S) print((dist[T] // 3 if dist[T] != float('inf') else - 1))
N, M = list(map(int, input().split())) G = [[] for i in range(3 * N)] for i in range(M): u, v = list(map(int, input().split())) u, v = u - 1, v - 1 G[u].append([v + N, 1]) G[u + N].append([v + 2 * N, 1]) G[u + 2 * N].append([v, 1]) S, T = list(map(int, input().split())) S, T = S - 1, T - 1 def dijkstra(graph, start, inf=float('inf')): import heapq n = len(graph) distances = [inf] * n distances[start] = 0 visited = [False] * n # 距離・頂点 hq = [(0, start)] while hq: dist, fr = heapq.heappop(hq) visited[fr] = True for to, cost in graph[fr]: new_dist = distances[fr] + cost if (visited[to]) or (distances[to] <= new_dist): continue distances[to] = new_dist heapq.heappush(hq, (new_dist, to)) return distances distances = dijkstra(G, S) print((distances[T] // 3 if distances[T] != float('inf') else -1))
37
39
836
973
import heapq N, M = list(map(int, input().split())) Edge = [list(map(int, input().split())) for i in range(M)] S, T = list(map(int, input().split())) S, T = S - 1, T - 1 G3 = [[] for i in range(3 * N)] for u, v in Edge: u, v = u - 1, v - 1 G3[u].append([v + N, 1]) G3[u + N].append([v + N * 2, 1]) G3[u + 2 * N].append([v, 1]) def dijkstra(x): d = [float("inf")] * (3 * N) d[x] = 0 visited = {x} # d, u hq = [(0, x)] while hq: u = heapq.heappop(hq)[1] visited.add(u) for node, cost in G3[u]: if (node not in visited) and d[node] > d[u] + cost: d[node] = d[u] + cost heapq.heappush(hq, (d[u] + cost, node)) return d dist = dijkstra(S) print((dist[T] // 3 if dist[T] != float("inf") else -1))
N, M = list(map(int, input().split())) G = [[] for i in range(3 * N)] for i in range(M): u, v = list(map(int, input().split())) u, v = u - 1, v - 1 G[u].append([v + N, 1]) G[u + N].append([v + 2 * N, 1]) G[u + 2 * N].append([v, 1]) S, T = list(map(int, input().split())) S, T = S - 1, T - 1 def dijkstra(graph, start, inf=float("inf")): import heapq n = len(graph) distances = [inf] * n distances[start] = 0 visited = [False] * n # 距離・頂点 hq = [(0, start)] while hq: dist, fr = heapq.heappop(hq) visited[fr] = True for to, cost in graph[fr]: new_dist = distances[fr] + cost if (visited[to]) or (distances[to] <= new_dist): continue distances[to] = new_dist heapq.heappush(hq, (new_dist, to)) return distances distances = dijkstra(G, S) print((distances[T] // 3 if distances[T] != float("inf") else -1))
false
5.128205
[ "-import heapq", "-", "-Edge = [list(map(int, input().split())) for i in range(M)]", "+G = [[] for i in range(3 * N)]", "+for i in range(M):", "+ u, v = list(map(int, input().split()))", "+ u, v = u - 1, v - 1", "+ G[u].append([v + N, 1])", "+ G[u + N].append([v + 2 * N, 1])", "+ G[u + 2 * N].append([v, 1])", "-G3 = [[] for i in range(3 * N)]", "-for u, v in Edge:", "- u, v = u - 1, v - 1", "- G3[u].append([v + N, 1])", "- G3[u + N].append([v + N * 2, 1])", "- G3[u + 2 * N].append([v, 1])", "-def dijkstra(x):", "- d = [float(\"inf\")] * (3 * N)", "- d[x] = 0", "- visited = {x}", "- # d, u", "- hq = [(0, x)]", "+def dijkstra(graph, start, inf=float(\"inf\")):", "+ import heapq", "+", "+ n = len(graph)", "+ distances = [inf] * n", "+ distances[start] = 0", "+ visited = [False] * n", "+ # 距離・頂点", "+ hq = [(0, start)]", "- u = heapq.heappop(hq)[1]", "- visited.add(u)", "- for node, cost in G3[u]:", "- if (node not in visited) and d[node] > d[u] + cost:", "- d[node] = d[u] + cost", "- heapq.heappush(hq, (d[u] + cost, node))", "- return d", "+ dist, fr = heapq.heappop(hq)", "+ visited[fr] = True", "+ for to, cost in graph[fr]:", "+ new_dist = distances[fr] + cost", "+ if (visited[to]) or (distances[to] <= new_dist):", "+ continue", "+ distances[to] = new_dist", "+ heapq.heappush(hq, (new_dist, to))", "+ return distances", "-dist = dijkstra(S)", "-print((dist[T] // 3 if dist[T] != float(\"inf\") else -1))", "+distances = dijkstra(G, S)", "+print((distances[T] // 3 if distances[T] != float(\"inf\") else -1))" ]
false
0.044648
0.04473
0.998174
[ "s599128325", "s703515537" ]
u681444474
p02898
python
s014802282
s219025498
209
55
51,440
18,472
Accepted
Accepted
73.68
n,k = list(map(int,input().split())) h = list(map(int,input().split())) h_=[i for i in h if i >= k] print((len(h_)))
n, k = list(map(int,input().split())) H = list(map(int,input().split())) ans = 0 for h in H: if h >= k: ans += 1 print(ans)
6
7
117
135
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h_ = [i for i in h if i >= k] print((len(h_)))
n, k = list(map(int, input().split())) H = list(map(int, input().split())) ans = 0 for h in H: if h >= k: ans += 1 print(ans)
false
14.285714
[ "-h = list(map(int, input().split()))", "-h_ = [i for i in h if i >= k]", "-print((len(h_)))", "+H = list(map(int, input().split()))", "+ans = 0", "+for h in H:", "+ if h >= k:", "+ ans += 1", "+print(ans)" ]
false
0.031418
0.03145
0.998987
[ "s014802282", "s219025498" ]
u063596417
p03636
python
s726736387
s573520463
61
29
61,708
8,752
Accepted
Accepted
52.46
s = eval(input()) print(f'{s[0]}{len(s) - 2}{s[-1]}')
def main(): s = eval(input()) print(f'{s[0]}{len(s) - 2}{s[-1]}') if __name__ == '__main__': main()
2
7
48
114
s = eval(input()) print(f"{s[0]}{len(s) - 2}{s[-1]}")
def main(): s = eval(input()) print(f"{s[0]}{len(s) - 2}{s[-1]}") if __name__ == "__main__": main()
false
71.428571
[ "-s = eval(input())", "-print(f\"{s[0]}{len(s) - 2}{s[-1]}\")", "+def main():", "+ s = eval(input())", "+ print(f\"{s[0]}{len(s) - 2}{s[-1]}\")", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047775
0.101567
0.470382
[ "s726736387", "s573520463" ]
u064408584
p03786
python
s775385368
s761315675
147
104
14,320
14,320
Accepted
Accepted
29.25
n=int(eval(input())) a=list(map(int, input().split())) a.sort(reverse=True) b=[0] for i in a: b.append(i+b[-1]) ans=1 for i in range(1,n): if b[i]-b[i-1]<=2*(b[-1]-b[i]): ans+=1 else:break print(ans)
n=int(eval(input())) t=sorted(map(int, input().split()),reverse=True) sm=sum(t) ans=0 for i in t: sm-=i ans+=1 if i>sm*2: break print(ans)
12
10
224
161
n = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse=True) b = [0] for i in a: b.append(i + b[-1]) ans = 1 for i in range(1, n): if b[i] - b[i - 1] <= 2 * (b[-1] - b[i]): ans += 1 else: break print(ans)
n = int(eval(input())) t = sorted(map(int, input().split()), reverse=True) sm = sum(t) ans = 0 for i in t: sm -= i ans += 1 if i > sm * 2: break print(ans)
false
16.666667
[ "-a = list(map(int, input().split()))", "-a.sort(reverse=True)", "-b = [0]", "-for i in a:", "- b.append(i + b[-1])", "-ans = 1", "-for i in range(1, n):", "- if b[i] - b[i - 1] <= 2 * (b[-1] - b[i]):", "- ans += 1", "- else:", "+t = sorted(map(int, input().split()), reverse=True)", "+sm = sum(t)", "+ans = 0", "+for i in t:", "+ sm -= i", "+ ans += 1", "+ if i > sm * 2:" ]
false
0.11461
0.035936
3.189297
[ "s775385368", "s761315675" ]
u254871849
p03854
python
s514783184
s556374486
22
18
3,956
3,444
Accepted
Accepted
18.18
s = eval(input()) def reverse(string): return ''.join(reversed(string)) def split_and_join(string, word): return ''.join(string.split(word)) s_r = reverse(s) ls = ["eraser", "erase", "dreamer", "dream"] ls_r = [] for item in ls: ls_r.append(reverse(item)) for word_r in ls_r: s_r = split_and_join(s_r, word_r) ans = "YES" if s_r == '' else "NO" print(ans)
s = eval(input()) def remove_word_from_string(string, word): return ''.join(string.split(word)) ls = ["eraser", "erase", "dreamer", "dream"] for word in ls: s = remove_word_from_string(s, word) ans = "YES" if s == '' else "NO" print(ans)
20
13
384
254
s = eval(input()) def reverse(string): return "".join(reversed(string)) def split_and_join(string, word): return "".join(string.split(word)) s_r = reverse(s) ls = ["eraser", "erase", "dreamer", "dream"] ls_r = [] for item in ls: ls_r.append(reverse(item)) for word_r in ls_r: s_r = split_and_join(s_r, word_r) ans = "YES" if s_r == "" else "NO" print(ans)
s = eval(input()) def remove_word_from_string(string, word): return "".join(string.split(word)) ls = ["eraser", "erase", "dreamer", "dream"] for word in ls: s = remove_word_from_string(s, word) ans = "YES" if s == "" else "NO" print(ans)
false
35
[ "-def reverse(string):", "- return \"\".join(reversed(string))", "-", "-", "-def split_and_join(string, word):", "+def remove_word_from_string(string, word):", "-s_r = reverse(s)", "-ls_r = []", "-for item in ls:", "- ls_r.append(reverse(item))", "-for word_r in ls_r:", "- s_r = split_and_join(s_r, word_r)", "-ans = \"YES\" if s_r == \"\" else \"NO\"", "+for word in ls:", "+ s = remove_word_from_string(s, word)", "+ans = \"YES\" if s == \"\" else \"NO\"" ]
false
0.183416
0.178171
1.02944
[ "s514783184", "s556374486" ]
u705617253
p03693
python
s945363245
s176970050
20
18
2,940
2,940
Accepted
Accepted
10
r, g, b = list(map(int, input().split())) if (10 * g + b) % 4 == 0: print("YES") else: print("NO")
r, g, b = list(map(int, input().split())) print(("YES" if (10 * g + b) % 4 == 0 else "NO"))
6
3
107
87
r, g, b = list(map(int, input().split())) if (10 * g + b) % 4 == 0: print("YES") else: print("NO")
r, g, b = list(map(int, input().split())) print(("YES" if (10 * g + b) % 4 == 0 else "NO"))
false
50
[ "-if (10 * g + b) % 4 == 0:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+print((\"YES\" if (10 * g + b) % 4 == 0 else \"NO\"))" ]
false
0.092318
0.047053
1.962007
[ "s945363245", "s176970050" ]
u175034939
p02574
python
s510836088
s114636950
365
318
197,176
195,028
Accepted
Accepted
12.88
from functools import reduce from math import gcd n = int(eval(input())) A = list(map(int, input().split())) def furui(x): memo = [0]*(x+1) primes = [] for i in range(2, x+1): if memo[i]: continue primes.append(i) memo[i] = i for j in range(i*i, x+1, i): if memo[j]: continue memo[j] = i return memo, primes memo, primes = furui(10**6+5) pr = [True]*(10**6+5) for a in A: if a == 1: continue while a != 1: w = memo[a] if not pr[w]: break pr[w] = False while a%w == 0: a = a // w else: continue break else: print('pairwise coprime') exit() if reduce(gcd, A) == 1: print('setwise coprime') else: print('not coprime')
from math import gcd n = int(eval(input())) maxA = 10**6+5 A = list(map(int, input().split())) c = [0]*maxA for a in A: c[a] += 1 for i in range(2, maxA): cnt = 0 for j in range(i, maxA, i): cnt += c[j] if cnt >= 2: break else: print('pairwise coprime') exit() g = 0 for a in A: g = gcd(g, a) if g == 1: print('setwise coprime') else: print('not coprime')
41
26
823
430
from functools import reduce from math import gcd n = int(eval(input())) A = list(map(int, input().split())) def furui(x): memo = [0] * (x + 1) primes = [] for i in range(2, x + 1): if memo[i]: continue primes.append(i) memo[i] = i for j in range(i * i, x + 1, i): if memo[j]: continue memo[j] = i return memo, primes memo, primes = furui(10**6 + 5) pr = [True] * (10**6 + 5) for a in A: if a == 1: continue while a != 1: w = memo[a] if not pr[w]: break pr[w] = False while a % w == 0: a = a // w else: continue break else: print("pairwise coprime") exit() if reduce(gcd, A) == 1: print("setwise coprime") else: print("not coprime")
from math import gcd n = int(eval(input())) maxA = 10**6 + 5 A = list(map(int, input().split())) c = [0] * maxA for a in A: c[a] += 1 for i in range(2, maxA): cnt = 0 for j in range(i, maxA, i): cnt += c[j] if cnt >= 2: break else: print("pairwise coprime") exit() g = 0 for a in A: g = gcd(g, a) if g == 1: print("setwise coprime") else: print("not coprime")
false
36.585366
[ "-from functools import reduce", "+maxA = 10**6 + 5", "-", "-", "-def furui(x):", "- memo = [0] * (x + 1)", "- primes = []", "- for i in range(2, x + 1):", "- if memo[i]:", "- continue", "- primes.append(i)", "- memo[i] = i", "- for j in range(i * i, x + 1, i):", "- if memo[j]:", "- continue", "- memo[j] = i", "- return memo, primes", "-", "-", "-memo, primes = furui(10**6 + 5)", "-pr = [True] * (10**6 + 5)", "+c = [0] * maxA", "- if a == 1:", "- continue", "- while a != 1:", "- w = memo[a]", "- if not pr[w]:", "- break", "- pr[w] = False", "- while a % w == 0:", "- a = a // w", "- else:", "- continue", "- break", "+ c[a] += 1", "+for i in range(2, maxA):", "+ cnt = 0", "+ for j in range(i, maxA, i):", "+ cnt += c[j]", "+ if cnt >= 2:", "+ break", "-if reduce(gcd, A) == 1:", "+g = 0", "+for a in A:", "+ g = gcd(g, a)", "+if g == 1:" ]
false
0.540692
1.759034
0.30738
[ "s510836088", "s114636950" ]
u179169725
p03112
python
s723848416
s392439046
1,770
1,603
13,924
14,056
Accepted
Accepted
9.44
A, B, Q = list(map(int, input().split())) # もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。 INF = 10 ** 18 S = [-INF] + [int(eval(input())) for _ in range(A)]+[INF] T = [-INF] + [int(eval(input())) for _ in range(B)]+[INF] from bisect import bisect_left as bisect_right from itertools import product for q in range(Q): # 各問に答える x = int(eval(input())) # 位置の指定 s_idx, t_idx = bisect_right(S, x), bisect_right(T, x) ans = INF # 左右の神社と寺のの組み合わせ for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]): t_root = abs(t - x) + abs(s - t) # 寺から最初に回るルート s_root = abs(s - x) + abs(s - t) ans = min(ans, t_root, s_root) # 最小をとって終わり print(ans) ''' bisect_right ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。 In[3]: A Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In[4]: bisect.bisect_right(A, 2.5) Out[4]: 3 In[5]: bisect.bisect_right(A, 3) Out[5]: 4 '''
from sys import stdin A, B, Q = list(map(int, input().split())) # もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。 INF = 10 ** 18 S = [-INF] + [int(stdin.readline()) for _ in range(A)]+[INF] T = [-INF] + [int(stdin.readline()) for _ in range(B)]+[INF] from bisect import bisect_right # from bisect import bisect_left as bisect_right #これでも通ったりする。 from itertools import product for q in range(Q): # 各問に答える x = int(eval(input())) # 位置の指定 s_idx, t_idx = bisect_right(S, x), bisect_right(T, x) ans = INF # 左右の神社と寺のの組み合わせ for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]): t_root = abs(t - x) + abs(s - t) # 寺から最初に回るルート s_root = abs(s - x) + abs(s - t) ans = min(ans, t_root, s_root) # 最小をとって終わり print(ans) ''' bisect_right ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。 In[3]: A Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In[4]: bisect.bisect_right(A, 2.5) Out[4]: 3 In[5]: bisect.bisect_right(A, 3) Out[5]: 4 '''
38
39
1,120
1,207
A, B, Q = list(map(int, input().split())) # もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。 INF = 10**18 S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF] T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF] from bisect import bisect_left as bisect_right from itertools import product for q in range(Q): # 各問に答える x = int(eval(input())) # 位置の指定 s_idx, t_idx = bisect_right(S, x), bisect_right(T, x) ans = INF # 左右の神社と寺のの組み合わせ for s, t in product(S[s_idx - 1 : s_idx + 1], T[t_idx - 1 : t_idx + 1]): t_root = abs(t - x) + abs(s - t) # 寺から最初に回るルート s_root = abs(s - x) + abs(s - t) ans = min(ans, t_root, s_root) # 最小をとって終わり print(ans) """ bisect_right ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。 In[3]: A Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In[4]: bisect.bisect_right(A, 2.5) Out[4]: 3 In[5]: bisect.bisect_right(A, 3) Out[5]: 4 """
from sys import stdin A, B, Q = list(map(int, input().split())) # もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。 INF = 10**18 S = [-INF] + [int(stdin.readline()) for _ in range(A)] + [INF] T = [-INF] + [int(stdin.readline()) for _ in range(B)] + [INF] from bisect import bisect_right # from bisect import bisect_left as bisect_right #これでも通ったりする。 from itertools import product for q in range(Q): # 各問に答える x = int(eval(input())) # 位置の指定 s_idx, t_idx = bisect_right(S, x), bisect_right(T, x) ans = INF # 左右の神社と寺のの組み合わせ for s, t in product(S[s_idx - 1 : s_idx + 1], T[t_idx - 1 : t_idx + 1]): t_root = abs(t - x) + abs(s - t) # 寺から最初に回るルート s_root = abs(s - x) + abs(s - t) ans = min(ans, t_root, s_root) # 最小をとって終わり print(ans) """ bisect_right ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。 In[3]: A Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In[4]: bisect.bisect_right(A, 2.5) Out[4]: 3 In[5]: bisect.bisect_right(A, 3) Out[5]: 4 """
false
2.564103
[ "+from sys import stdin", "+", "-S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]", "-T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]", "-from bisect import bisect_left as bisect_right", "+S = [-INF] + [int(stdin.readline()) for _ in range(A)] + [INF]", "+T = [-INF] + [int(stdin.readline()) for _ in range(B)] + [INF]", "+from bisect import bisect_right", "+", "+# from bisect import bisect_left as bisect_right #これでも通ったりする。" ]
false
0.107817
0.045451
2.37215
[ "s723848416", "s392439046" ]
u377989038
p02837
python
s056545256
s796391890
138
83
9,224
3,064
Accepted
Accepted
39.86
from itertools import product n = int(eval(input())) xy = [[] for i in range(n)] for i in range(n): for j in range(int(eval(input()))): xy[i].append(list(map(int, input().split()))) ans = 0 for bit in product([0, 1], repeat=n): f = 0 for i, j in enumerate(bit): if j == 1: for x, y in xy[i]: if bit[x - 1] != y: f = 1 break if f == 0: ans = max(ans, sum(bit)) print(ans)
from itertools import product def solve(bit): for i, j in enumerate(bit): if j == 1: for x, y in xy[i]: if bit[x - 1] != y: return 0 return sum(bit) n = int(eval(input())) xy = [[] for i in range(n)] for i in range(n): for j in range(int(eval(input()))): xy[i].append(list(map(int, input().split()))) ans = 0 for bit in product([0, 1], repeat=n): ans = max(ans, solve(bit)) print(ans)
21
23
490
480
from itertools import product n = int(eval(input())) xy = [[] for i in range(n)] for i in range(n): for j in range(int(eval(input()))): xy[i].append(list(map(int, input().split()))) ans = 0 for bit in product([0, 1], repeat=n): f = 0 for i, j in enumerate(bit): if j == 1: for x, y in xy[i]: if bit[x - 1] != y: f = 1 break if f == 0: ans = max(ans, sum(bit)) print(ans)
from itertools import product def solve(bit): for i, j in enumerate(bit): if j == 1: for x, y in xy[i]: if bit[x - 1] != y: return 0 return sum(bit) n = int(eval(input())) xy = [[] for i in range(n)] for i in range(n): for j in range(int(eval(input()))): xy[i].append(list(map(int, input().split()))) ans = 0 for bit in product([0, 1], repeat=n): ans = max(ans, solve(bit)) print(ans)
false
8.695652
[ "+", "+", "+def solve(bit):", "+ for i, j in enumerate(bit):", "+ if j == 1:", "+ for x, y in xy[i]:", "+ if bit[x - 1] != y:", "+ return 0", "+ return sum(bit)", "+", "- f = 0", "- for i, j in enumerate(bit):", "- if j == 1:", "- for x, y in xy[i]:", "- if bit[x - 1] != y:", "- f = 1", "- break", "- if f == 0:", "- ans = max(ans, sum(bit))", "+ ans = max(ans, solve(bit))" ]
false
0.038045
0.043864
0.867345
[ "s056545256", "s796391890" ]
u969850098
p03208
python
s968510608
s542641374
138
117
8,256
8,280
Accepted
Accepted
15.22
import sys input = sys.stdin.readline N, K = list(map(int, input().rstrip().split())) heights = sorted([int(input().rstrip()) for _ in range(N)]) ans = float('inf') for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) heights = sorted([int(eval(input())) for _ in range(N)]) ans = float('inf') for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
9
9
306
288
import sys input = sys.stdin.readline N, K = list(map(int, input().rstrip().split())) heights = sorted([int(input().rstrip()) for _ in range(N)]) ans = float("inf") for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) heights = sorted([int(eval(input())) for _ in range(N)]) ans = float("inf") for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
false
0
[ "-N, K = list(map(int, input().rstrip().split()))", "-heights = sorted([int(input().rstrip()) for _ in range(N)])", "+N, K = list(map(int, input().split()))", "+heights = sorted([int(eval(input())) for _ in range(N)])" ]
false
0.040168
0.036152
1.111074
[ "s968510608", "s542641374" ]
u745223262
p02899
python
s027676522
s646041100
282
171
13,880
13,812
Accepted
Accepted
39.36
n = int(input()) a = list(map(int, input().split())) list = [-1]*n for i in range(n): list[a[i] - 1] = i+1 # print(list) print(list[0], end="") for i in range(1, n): print(" ", end="") print(list[i], end="")
n = int(input()) a = list(map(int, input().split())) list = [0] * n for i in range(n): list[a[i] - 1] = i + 1 for i in range(n): print(list[i], end=" ")
11
9
230
171
n = int(input()) a = list(map(int, input().split())) list = [-1] * n for i in range(n): list[a[i] - 1] = i + 1 # print(list) print(list[0], end="") for i in range(1, n): print(" ", end="") print(list[i], end="")
n = int(input()) a = list(map(int, input().split())) list = [0] * n for i in range(n): list[a[i] - 1] = i + 1 for i in range(n): print(list[i], end=" ")
false
18.181818
[ "-list = [-1] * n", "+list = [0] * n", "-# print(list)", "-print(list[0], end=\"\")", "-for i in range(1, n):", "- print(\" \", end=\"\")", "- print(list[i], end=\"\")", "+for i in range(n):", "+ print(list[i], end=\" \")" ]
false
0.035491
0.036261
0.978774
[ "s027676522", "s646041100" ]
u488401358
p04017
python
s073209874
s096441086
1,718
810
132,212
135,600
Accepted
Accepted
52.85
import sys,bisect input=sys.stdin.readline N=int(eval(input())) x=list(map(int,input().split())) L=int(eval(input())) doubling=[[-1 for i in range(N)] for j in range(20)] backdoubling=[[-1 for i in range(N)] for j in range(20)] for i in range(N): npos=x[i]+L index=bisect.bisect_right(x,npos) doubling[0][i]=index-1 for i in range(1,20): for j in range(N): doubling[i][j]=doubling[i-1][doubling[i-1][j]] for i in range(N): npos=x[i]-L index=bisect.bisect_left(x,npos) backdoubling[0][i]=index for i in range(1,20): for j in range(N): backdoubling[i][j]=backdoubling[i-1][backdoubling[i-1][j]] def forward(num,start): for i in range(20): if num>>i &1==1: start=doubling[i][start] return start def back(num,start): for i in range(20): if num>>i &1==1: start=backdoubling[i][start] return start for _ in range(int(eval(input()))): a,b=list(map(int,input().split())) a-=1;b-=1 if b>=a: s=0 e=N while e-s>1: test=(e+s)//2 if forward(test,a)>=b: e=test else: s=test if forward(s,a)>=b: print(s) else: print(e) else: s=0 e=N while e-s>1: test=(e+s)//2 if b>=back(test,a): e=test else: s=test if b>=back(s,a): print(s) else: print(e)
import sys,bisect input=sys.stdin.readline N=int(eval(input())) x=list(map(int,input().split())) L=int(eval(input())) doubling=[[-1 for i in range(N)] for j in range(20)] for i in range(N): npos=x[i]+L index=bisect.bisect_right(x,npos) doubling[0][i]=index-1 for i in range(1,20): for j in range(N): doubling[i][j]=doubling[i-1][doubling[i-1][j]] forward=[[-1 for i in range(N)] for j in range(20)] for i in range(N): forward[0][i]=i for i in range(1,20): for j in range(N): forward[i][j]=doubling[i-1][forward[i-1][j]] for _ in range(int(eval(input()))): a,b=list(map(int,input().split())) a-=1;b-=1 if a>b: a,b=b,a res=0 for i in range(19,-1,-1): if b>forward[i][a]: a=doubling[i][a] res+=2**i print(res)
71
39
1,566
833
import sys, bisect input = sys.stdin.readline N = int(eval(input())) x = list(map(int, input().split())) L = int(eval(input())) doubling = [[-1 for i in range(N)] for j in range(20)] backdoubling = [[-1 for i in range(N)] for j in range(20)] for i in range(N): npos = x[i] + L index = bisect.bisect_right(x, npos) doubling[0][i] = index - 1 for i in range(1, 20): for j in range(N): doubling[i][j] = doubling[i - 1][doubling[i - 1][j]] for i in range(N): npos = x[i] - L index = bisect.bisect_left(x, npos) backdoubling[0][i] = index for i in range(1, 20): for j in range(N): backdoubling[i][j] = backdoubling[i - 1][backdoubling[i - 1][j]] def forward(num, start): for i in range(20): if num >> i & 1 == 1: start = doubling[i][start] return start def back(num, start): for i in range(20): if num >> i & 1 == 1: start = backdoubling[i][start] return start for _ in range(int(eval(input()))): a, b = list(map(int, input().split())) a -= 1 b -= 1 if b >= a: s = 0 e = N while e - s > 1: test = (e + s) // 2 if forward(test, a) >= b: e = test else: s = test if forward(s, a) >= b: print(s) else: print(e) else: s = 0 e = N while e - s > 1: test = (e + s) // 2 if b >= back(test, a): e = test else: s = test if b >= back(s, a): print(s) else: print(e)
import sys, bisect input = sys.stdin.readline N = int(eval(input())) x = list(map(int, input().split())) L = int(eval(input())) doubling = [[-1 for i in range(N)] for j in range(20)] for i in range(N): npos = x[i] + L index = bisect.bisect_right(x, npos) doubling[0][i] = index - 1 for i in range(1, 20): for j in range(N): doubling[i][j] = doubling[i - 1][doubling[i - 1][j]] forward = [[-1 for i in range(N)] for j in range(20)] for i in range(N): forward[0][i] = i for i in range(1, 20): for j in range(N): forward[i][j] = doubling[i - 1][forward[i - 1][j]] for _ in range(int(eval(input()))): a, b = list(map(int, input().split())) a -= 1 b -= 1 if a > b: a, b = b, a res = 0 for i in range(19, -1, -1): if b > forward[i][a]: a = doubling[i][a] res += 2**i print(res)
false
45.070423
[ "-backdoubling = [[-1 for i in range(N)] for j in range(20)]", "+forward = [[-1 for i in range(N)] for j in range(20)]", "- npos = x[i] - L", "- index = bisect.bisect_left(x, npos)", "- backdoubling[0][i] = index", "+ forward[0][i] = i", "- backdoubling[i][j] = backdoubling[i - 1][backdoubling[i - 1][j]]", "-", "-", "-def forward(num, start):", "- for i in range(20):", "- if num >> i & 1 == 1:", "- start = doubling[i][start]", "- return start", "-", "-", "-def back(num, start):", "- for i in range(20):", "- if num >> i & 1 == 1:", "- start = backdoubling[i][start]", "- return start", "-", "-", "+ forward[i][j] = doubling[i - 1][forward[i - 1][j]]", "- if b >= a:", "- s = 0", "- e = N", "- while e - s > 1:", "- test = (e + s) // 2", "- if forward(test, a) >= b:", "- e = test", "- else:", "- s = test", "- if forward(s, a) >= b:", "- print(s)", "- else:", "- print(e)", "- else:", "- s = 0", "- e = N", "- while e - s > 1:", "- test = (e + s) // 2", "- if b >= back(test, a):", "- e = test", "- else:", "- s = test", "- if b >= back(s, a):", "- print(s)", "- else:", "- print(e)", "+ if a > b:", "+ a, b = b, a", "+ res = 0", "+ for i in range(19, -1, -1):", "+ if b > forward[i][a]:", "+ a = doubling[i][a]", "+ res += 2**i", "+ print(res)" ]
false
0.048483
0.048455
1.000591
[ "s073209874", "s096441086" ]
u855831834
p03557
python
s185722228
s403781570
338
233
23,360
105,308
Accepted
Accepted
31.07
import bisect 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() #print(A) #print(B) #print(C) ans = 0 for b in B: a = bisect.bisect_right(A, b-1) c = N - bisect.bisect_right(C, b) #print("smaller",a,"bigger",c) ans += a*c print(ans)
import bisect n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() C.sort() ans = 0 for b in B: a = bisect.bisect_right(A, b-1) c = len(C)-bisect.bisect_right(C, b) ans += a*c print(ans)
23
16
374
294
import bisect 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() # print(A) # print(B) # print(C) ans = 0 for b in B: a = bisect.bisect_right(A, b - 1) c = N - bisect.bisect_right(C, b) # print("smaller",a,"bigger",c) ans += a * c print(ans)
import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for b in B: a = bisect.bisect_right(A, b - 1) c = len(C) - bisect.bisect_right(C, b) ans += a * c print(ans)
false
30.434783
[ "-N = int(eval(input()))", "+n = int(eval(input()))", "-B.sort()", "-# print(A)", "-# print(B)", "-# print(C)", "- c = N - bisect.bisect_right(C, b)", "- # print(\"smaller\",a,\"bigger\",c)", "+ c = len(C) - bisect.bisect_right(C, b)" ]
false
0.039123
0.040051
0.97684
[ "s185722228", "s403781570" ]
u556849401
p02912
python
s356765412
s889230012
1,327
262
15,432
14,224
Accepted
Accepted
80.26
# -*- coding: utf-8 -*- """ Created on Wed Oct 2 07:56:16 2019 @author: avina """ from queue import PriorityQueue as Q n,t = list(map(int,input().split())) q = Q() for i in input().split(): a = -1*int(i) q.put(a) while t >0: a = -1*(q.get()) a = -1*(a//2) q.put(a) t-=1 ans = 0 while q.qsize()>0: ans += q.get() print((-1*ans))
# -*- coding: utf-8 -*- """ Created on Thu Oct 3 07:43:37 2019 @author: avina """ import heapq class Maxheap(): def __init__(self, x): self.heap = [-e for e in x] heapq.heapify(self.heap) def push(self, value): heapq.heappush(self.heap, -value) def pop(self): return -heapq.heappop(self.heap) n,t = list(map(int, input().split())) l = list(map(int, input().split())) a = Maxheap(l) for i in range(t): b = a.pop()//2 a.push(b) sums = 0 for i in range(n): sums += a.pop() print(sums)
24
33
375
589
# -*- coding: utf-8 -*- """ Created on Wed Oct 2 07:56:16 2019 @author: avina """ from queue import PriorityQueue as Q n, t = list(map(int, input().split())) q = Q() for i in input().split(): a = -1 * int(i) q.put(a) while t > 0: a = -1 * (q.get()) a = -1 * (a // 2) q.put(a) t -= 1 ans = 0 while q.qsize() > 0: ans += q.get() print((-1 * ans))
# -*- coding: utf-8 -*- """ Created on Thu Oct 3 07:43:37 2019 @author: avina """ import heapq class Maxheap: def __init__(self, x): self.heap = [-e for e in x] heapq.heapify(self.heap) def push(self, value): heapq.heappush(self.heap, -value) def pop(self): return -heapq.heappop(self.heap) n, t = list(map(int, input().split())) l = list(map(int, input().split())) a = Maxheap(l) for i in range(t): b = a.pop() // 2 a.push(b) sums = 0 for i in range(n): sums += a.pop() print(sums)
false
27.272727
[ "-Created on Wed Oct 2 07:56:16 2019", "+Created on Thu Oct 3 07:43:37 2019", "-from queue import PriorityQueue as Q", "+import heapq", "+", "+", "+class Maxheap:", "+ def __init__(self, x):", "+ self.heap = [-e for e in x]", "+ heapq.heapify(self.heap)", "+", "+ def push(self, value):", "+ heapq.heappush(self.heap, -value)", "+", "+ def pop(self):", "+ return -heapq.heappop(self.heap)", "+", "-q = Q()", "-for i in input().split():", "- a = -1 * int(i)", "- q.put(a)", "-while t > 0:", "- a = -1 * (q.get())", "- a = -1 * (a // 2)", "- q.put(a)", "- t -= 1", "-ans = 0", "-while q.qsize() > 0:", "- ans += q.get()", "-print((-1 * ans))", "+l = list(map(int, input().split()))", "+a = Maxheap(l)", "+for i in range(t):", "+ b = a.pop() // 2", "+ a.push(b)", "+sums = 0", "+for i in range(n):", "+ sums += a.pop()", "+print(sums)" ]
false
0.109877
0.055569
1.977294
[ "s356765412", "s889230012" ]
u550061714
p03165
python
s834179053
s310544134
575
420
120,540
91,596
Accepted
Accepted
26.96
s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0 for _ in range(lt + 1)] for __ in range(ls + 1)] for ns in range(ls): for nt in range(lt): if s[ns] == t[nt]: dp[ns + 1][nt + 1] = max(dp[ns][nt] + 1, dp[ns + 1][nt + 1]) dp[ns + 1][nt + 1] = max(dp[ns + 1][nt + 1], dp[ns + 1][nt], dp[ns][nt + 1]) ans = '' i, j = ls, lt while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans = s[i - 1] + ans i -= 1 j -= 1 print(ans)
import numpy as np s = np.array(list(eval(input()))) t = np.array(list(eval(input()))) equal = (s[:, None] == t[None, :]) ls, lt = len(s), len(t) dp = np.zeros((ls + 1, lt + 1), dtype=int) for i in range(ls): dp[i + 1][1:] = np.maximum(dp[i][1:], dp[i][:-1] + equal[i]) dp[i + 1] = np.maximum.accumulate(dp[i + 1]) ans = '' i, j = ls, lt while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans = s[i - 1] + ans i -= 1 j -= 1 print(ans)
26
25
590
563
s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0 for _ in range(lt + 1)] for __ in range(ls + 1)] for ns in range(ls): for nt in range(lt): if s[ns] == t[nt]: dp[ns + 1][nt + 1] = max(dp[ns][nt] + 1, dp[ns + 1][nt + 1]) dp[ns + 1][nt + 1] = max(dp[ns + 1][nt + 1], dp[ns + 1][nt], dp[ns][nt + 1]) ans = "" i, j = ls, lt while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans = s[i - 1] + ans i -= 1 j -= 1 print(ans)
import numpy as np s = np.array(list(eval(input()))) t = np.array(list(eval(input()))) equal = s[:, None] == t[None, :] ls, lt = len(s), len(t) dp = np.zeros((ls + 1, lt + 1), dtype=int) for i in range(ls): dp[i + 1][1:] = np.maximum(dp[i][1:], dp[i][:-1] + equal[i]) dp[i + 1] = np.maximum.accumulate(dp[i + 1]) ans = "" i, j = ls, lt while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans = s[i - 1] + ans i -= 1 j -= 1 print(ans)
false
3.846154
[ "-s = eval(input())", "-t = eval(input())", "-ls = len(s)", "-lt = len(t)", "-dp = [[0 for _ in range(lt + 1)] for __ in range(ls + 1)]", "-for ns in range(ls):", "- for nt in range(lt):", "- if s[ns] == t[nt]:", "- dp[ns + 1][nt + 1] = max(dp[ns][nt] + 1, dp[ns + 1][nt + 1])", "- dp[ns + 1][nt + 1] = max(dp[ns + 1][nt + 1], dp[ns + 1][nt], dp[ns][nt + 1])", "+import numpy as np", "+", "+s = np.array(list(eval(input())))", "+t = np.array(list(eval(input())))", "+equal = s[:, None] == t[None, :]", "+ls, lt = len(s), len(t)", "+dp = np.zeros((ls + 1, lt + 1), dtype=int)", "+for i in range(ls):", "+ dp[i + 1][1:] = np.maximum(dp[i][1:], dp[i][:-1] + equal[i])", "+ dp[i + 1] = np.maximum.accumulate(dp[i + 1])" ]
false
0.060906
0.198897
0.30622
[ "s834179053", "s310544134" ]
u397496203
p03001
python
s487504198
s780930630
71
65
61,860
61,908
Accepted
Accepted
8.45
# import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): w, h, x, y = input_int_list() area = (w * h) / 2 bl = (w == 2 * x and h == 2 * y) print((area, 1 if bl else 0)) return if __name__ == "__main__": main()
w, h, x, y = [int(i) for i in input().split()] pat = 0 if x == w / 2 and y == h / 2: pat = 1 print(((w * h) / 2, pat))
28
7
431
129
# import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): w, h, x, y = input_int_list() area = (w * h) / 2 bl = w == 2 * x and h == 2 * y print((area, 1 if bl else 0)) return if __name__ == "__main__": main()
w, h, x, y = [int(i) for i in input().split()] pat = 0 if x == w / 2 and y == h / 2: pat = 1 print(((w * h) / 2, pat))
false
75
[ "-#", "-import sys", "-", "-# sys.setrecursionlimit(100000)", "-def input():", "- return sys.stdin.readline().strip()", "-", "-", "-def input_int():", "- return int(eval(input()))", "-", "-", "-def input_int_list():", "- return [int(i) for i in input().split()]", "-", "-", "-def main():", "- w, h, x, y = input_int_list()", "- area = (w * h) / 2", "- bl = w == 2 * x and h == 2 * y", "- print((area, 1 if bl else 0))", "- return", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+w, h, x, y = [int(i) for i in input().split()]", "+pat = 0", "+if x == w / 2 and y == h / 2:", "+ pat = 1", "+print(((w * h) / 2, pat))" ]
false
0.050507
0.114776
0.440044
[ "s487504198", "s780930630" ]
u254871849
p03425
python
s408924310
s952250186
53
45
3,064
11,596
Accepted
Accepted
15.09
# author: kagemeka # created: 2019-11-06 16:52:04(JST) import sys # import collections # import math # import string # import bisect # import re import itertools # import statistics # import functools # import operator # def nCr(n, r): # r = min(r, n - r) # return functools.reduce(operator.mul, range(n, n-r, -1), 1) // math.factorial(r) def main(): n = int(sys.stdin.readline().rstrip()) march = {l: 0 for l in 'MARCH'} for i in range(n): initial = sys.stdin.readline()[0] if initial in march: march[initial] += 1 march = {k: v for k, v in list(march.items()) if v != 0} if len(march) < 2: print((0)) exit() total_cmb = 0 for cmb in itertools.combinations(list(march.values()), 3): total_cmb += cmb[0] * cmb[1] * cmb[2] print(total_cmb) if __name__ == "__main__": # execute only if run as a script main()
import sys from collections import Counter from itertools import combinations MARCH = set('MARCH') n = int(sys.stdin.readline().rstrip()) s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH] def main(): c = Counter(s) ways = 0 for comb in combinations('MARCH', 3): res = 1 for i in comb: res *= c.get(i, 0) ways += res return ways if __name__ == '__main__': ans = main() print(ans)
42
23
1,013
481
# author: kagemeka # created: 2019-11-06 16:52:04(JST) import sys # import collections # import math # import string # import bisect # import re import itertools # import statistics # import functools # import operator # def nCr(n, r): # r = min(r, n - r) # return functools.reduce(operator.mul, range(n, n-r, -1), 1) // math.factorial(r) def main(): n = int(sys.stdin.readline().rstrip()) march = {l: 0 for l in "MARCH"} for i in range(n): initial = sys.stdin.readline()[0] if initial in march: march[initial] += 1 march = {k: v for k, v in list(march.items()) if v != 0} if len(march) < 2: print((0)) exit() total_cmb = 0 for cmb in itertools.combinations(list(march.values()), 3): total_cmb += cmb[0] * cmb[1] * cmb[2] print(total_cmb) if __name__ == "__main__": # execute only if run as a script main()
import sys from collections import Counter from itertools import combinations MARCH = set("MARCH") n = int(sys.stdin.readline().rstrip()) s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH] def main(): c = Counter(s) ways = 0 for comb in combinations("MARCH", 3): res = 1 for i in comb: res *= c.get(i, 0) ways += res return ways if __name__ == "__main__": ans = main() print(ans)
false
45.238095
[ "-# author: kagemeka", "-# created: 2019-11-06 16:52:04(JST)", "+from collections import Counter", "+from itertools import combinations", "-# import collections", "-# import math", "-# import string", "-# import bisect", "-# import re", "-import itertools", "+MARCH = set(\"MARCH\")", "+n = int(sys.stdin.readline().rstrip())", "+s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH]", "-# import statistics", "-# import functools", "-# import operator", "-# def nCr(n, r):", "-# r = min(r, n - r)", "-# return functools.reduce(operator.mul, range(n, n-r, -1), 1) // math.factorial(r)", "+", "- n = int(sys.stdin.readline().rstrip())", "- march = {l: 0 for l in \"MARCH\"}", "- for i in range(n):", "- initial = sys.stdin.readline()[0]", "- if initial in march:", "- march[initial] += 1", "- march = {k: v for k, v in list(march.items()) if v != 0}", "- if len(march) < 2:", "- print((0))", "- exit()", "- total_cmb = 0", "- for cmb in itertools.combinations(list(march.values()), 3):", "- total_cmb += cmb[0] * cmb[1] * cmb[2]", "- print(total_cmb)", "+ c = Counter(s)", "+ ways = 0", "+ for comb in combinations(\"MARCH\", 3):", "+ res = 1", "+ for i in comb:", "+ res *= c.get(i, 0)", "+ ways += res", "+ return ways", "- # execute only if run as a script", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.036039
0.03563
1.011479
[ "s408924310", "s952250186" ]
u896791216
p03294
python
s276780582
s206075180
145
30
9,412
9,324
Accepted
Accepted
79.31
import math n = int(eval(input())) a = list(map(int, input().split())) common_num = 1 for num in a: common_num = (common_num * num) // math.gcd(common_num, num) total = 0 for num in a: total += (common_num - 1) % num print(total)
# 合計が最大になるのは、余りが各aにおいてa-1となるとき。 n = int(eval(input())) a = list(map(int, input().split())) # 各aから1ずつ引くをn繰り返しているため。 ans = sum(a) - n print(ans)
11
6
243
141
import math n = int(eval(input())) a = list(map(int, input().split())) common_num = 1 for num in a: common_num = (common_num * num) // math.gcd(common_num, num) total = 0 for num in a: total += (common_num - 1) % num print(total)
# 合計が最大になるのは、余りが各aにおいてa-1となるとき。 n = int(eval(input())) a = list(map(int, input().split())) # 各aから1ずつ引くをn繰り返しているため。 ans = sum(a) - n print(ans)
false
45.454545
[ "-import math", "-", "+# 合計が最大になるのは、余りが各aにおいてa-1となるとき。", "-common_num = 1", "-for num in a:", "- common_num = (common_num * num) // math.gcd(common_num, num)", "-total = 0", "-for num in a:", "- total += (common_num - 1) % num", "-print(total)", "+# 各aから1ずつ引くをn繰り返しているため。", "+ans = sum(a) - n", "+print(ans)" ]
false
0.034918
0.034993
0.997862
[ "s276780582", "s206075180" ]
u924691798
p02678
python
s114800271
s904601021
819
658
39,936
38,536
Accepted
Accepted
19.66
from collections import deque N, M = list(map(int, input().split())) G = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) q = deque() done = [-1]*N def bfs(fr, now): done[now] = fr for to in G[now]: if done[to] != -1: continue q.appendleft((now, to)) q.appendleft((0, 0)) while q: fr, now = q.pop() if done[now] == -1: bfs(fr, now) print("Yes") for fr in done[1:]: print((fr+1))
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) q = deque() done = [-1]*N done[0] = 1 q.appendleft(0) while q: now = q.pop() for to in G[now]: if done[to] != -1: continue done[to] = now+1 q.appendleft(to) print("Yes") print(*done[1:], sep="\n")
25
22
530
457
from collections import deque N, M = list(map(int, input().split())) G = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) q = deque() done = [-1] * N def bfs(fr, now): done[now] = fr for to in G[now]: if done[to] != -1: continue q.appendleft((now, to)) q.appendleft((0, 0)) while q: fr, now = q.pop() if done[now] == -1: bfs(fr, now) print("Yes") for fr in done[1:]: print((fr + 1))
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) q = deque() done = [-1] * N done[0] = 1 q.appendleft(0) while q: now = q.pop() for to in G[now]: if done[to] != -1: continue done[to] = now + 1 q.appendleft(to) print("Yes") print(*done[1:], sep="\n")
false
12
[ "-N, M = list(map(int, input().split()))", "+N, M = map(int, input().split())", "- a, b = list(map(int, input().split()))", "+ a, b = map(int, input().split())", "-", "-", "-def bfs(fr, now):", "- done[now] = fr", "+done[0] = 1", "+q.appendleft(0)", "+while q:", "+ now = q.pop()", "- q.appendleft((now, to))", "-", "-", "-q.appendleft((0, 0))", "-while q:", "- fr, now = q.pop()", "- if done[now] == -1:", "- bfs(fr, now)", "+ done[to] = now + 1", "+ q.appendleft(to)", "-for fr in done[1:]:", "- print((fr + 1))", "+print(*done[1:], sep=\"\\n\")" ]
false
0.038886
0.133349
0.291608
[ "s114800271", "s904601021" ]
u512212329
p02850
python
s776934089
s475042670
1,199
1,103
95,120
95,072
Accepted
Accepted
8.01
from collections import OrderedDict, deque n = int(eval(input())) edges = [tuple(map(int, input().split())) for _ in range(n - 1)] tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる. coloring = OrderedDict() for e in edges: a, b = e[0] - 1, e[1] - 1 tree[a].append(b) tree[b].append(a) coloring[(a, b)] = 0 q = deque() q_append = q.append q_popleft = q.popleft seen = [False] * n q_append(0) col_count_by_v = [set() for _ in range(n)] while len(q): new_v = q_popleft() seen[new_v] = True color_i = 1 # One-based index. for adj in tree[new_v]: if seen[adj]: continue q_append(adj) while color_i in col_count_by_v[new_v]: color_i += 1 coloring[(new_v, adj)] = color_i col_count_by_v[new_v].add(color_i) col_count_by_v[adj].add(color_i) color_i += 1 print((len(set(coloring.values())))) for c in list(coloring.values()): print(c)
from collections import OrderedDict, deque def main(): n = int(eval(input())) edges = [tuple(map(int, input().split())) for _ in range(n - 1)] tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる. coloring = OrderedDict() for e in edges: a, b = e[0] - 1, e[1] - 1 tree[a].append(b) tree[b].append(a) coloring[(a, b)] = 0 q = deque() q_append = q.append q_popleft = q.popleft seen = [False] * n q_append(0) col_count_by_v = [set() for _ in range(n)] while len(q): new_v = q_popleft() seen[new_v] = True color_i = 1 # One-based index. for adj in tree[new_v]: if seen[adj]: continue q_append(adj) while color_i in col_count_by_v[new_v]: color_i += 1 coloring[(new_v, adj)] = color_i col_count_by_v[new_v].add(color_i) col_count_by_v[adj].add(color_i) print((len(set(coloring.values())))) for c in list(coloring.values()): print(c) if __name__ == '__main__': main() # なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.
36
43
971
1,178
from collections import OrderedDict, deque n = int(eval(input())) edges = [tuple(map(int, input().split())) for _ in range(n - 1)] tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる. coloring = OrderedDict() for e in edges: a, b = e[0] - 1, e[1] - 1 tree[a].append(b) tree[b].append(a) coloring[(a, b)] = 0 q = deque() q_append = q.append q_popleft = q.popleft seen = [False] * n q_append(0) col_count_by_v = [set() for _ in range(n)] while len(q): new_v = q_popleft() seen[new_v] = True color_i = 1 # One-based index. for adj in tree[new_v]: if seen[adj]: continue q_append(adj) while color_i in col_count_by_v[new_v]: color_i += 1 coloring[(new_v, adj)] = color_i col_count_by_v[new_v].add(color_i) col_count_by_v[adj].add(color_i) color_i += 1 print((len(set(coloring.values())))) for c in list(coloring.values()): print(c)
from collections import OrderedDict, deque def main(): n = int(eval(input())) edges = [tuple(map(int, input().split())) for _ in range(n - 1)] tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる. coloring = OrderedDict() for e in edges: a, b = e[0] - 1, e[1] - 1 tree[a].append(b) tree[b].append(a) coloring[(a, b)] = 0 q = deque() q_append = q.append q_popleft = q.popleft seen = [False] * n q_append(0) col_count_by_v = [set() for _ in range(n)] while len(q): new_v = q_popleft() seen[new_v] = True color_i = 1 # One-based index. for adj in tree[new_v]: if seen[adj]: continue q_append(adj) while color_i in col_count_by_v[new_v]: color_i += 1 coloring[(new_v, adj)] = color_i col_count_by_v[new_v].add(color_i) col_count_by_v[adj].add(color_i) print((len(set(coloring.values())))) for c in list(coloring.values()): print(c) if __name__ == "__main__": main() # なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.
false
16.27907
[ "-n = int(eval(input()))", "-edges = [tuple(map(int, input().split())) for _ in range(n - 1)]", "-tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる.", "-coloring = OrderedDict()", "-for e in edges:", "- a, b = e[0] - 1, e[1] - 1", "- tree[a].append(b)", "- tree[b].append(a)", "- coloring[(a, b)] = 0", "-q = deque()", "-q_append = q.append", "-q_popleft = q.popleft", "-seen = [False] * n", "-q_append(0)", "-col_count_by_v = [set() for _ in range(n)]", "-while len(q):", "- new_v = q_popleft()", "- seen[new_v] = True", "- color_i = 1 # One-based index.", "- for adj in tree[new_v]:", "- if seen[adj]:", "- continue", "- q_append(adj)", "- while color_i in col_count_by_v[new_v]:", "- color_i += 1", "- coloring[(new_v, adj)] = color_i", "- col_count_by_v[new_v].add(color_i)", "- col_count_by_v[adj].add(color_i)", "- color_i += 1", "-print((len(set(coloring.values()))))", "-for c in list(coloring.values()):", "- print(c)", "+", "+def main():", "+ n = int(eval(input()))", "+ edges = [tuple(map(int, input().split())) for _ in range(n - 1)]", "+ tree = [[] for _ in range(n)] # こうしないとすべて同じリストObjになる.", "+ coloring = OrderedDict()", "+ for e in edges:", "+ a, b = e[0] - 1, e[1] - 1", "+ tree[a].append(b)", "+ tree[b].append(a)", "+ coloring[(a, b)] = 0", "+ q = deque()", "+ q_append = q.append", "+ q_popleft = q.popleft", "+ seen = [False] * n", "+ q_append(0)", "+ col_count_by_v = [set() for _ in range(n)]", "+ while len(q):", "+ new_v = q_popleft()", "+ seen[new_v] = True", "+ color_i = 1 # One-based index.", "+ for adj in tree[new_v]:", "+ if seen[adj]:", "+ continue", "+ q_append(adj)", "+ while color_i in col_count_by_v[new_v]:", "+ color_i += 1", "+ coloring[(new_v, adj)] = color_i", "+ col_count_by_v[new_v].add(color_i)", "+ col_count_by_v[adj].add(color_i)", "+ print((len(set(coloring.values()))))", "+ for c in list(coloring.values()):", "+ print(c)", "+", "+", "+if __name__ == \"__main__\":", "+ main()", "+# なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い." ]
false
0.039924
0.04341
0.919716
[ "s776934089", "s475042670" ]
u588341295
p02833
python
s893195338
s921301894
19
17
3,192
3,064
Accepted
Accepted
10.53
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 def f(n): if n <= 1: return 1 else: return n * f(n-2) # for i in range(100): # for i in [90, 100, 140, 150, 160, 200, 1240, 1250, 1250, 1260]: # print(i, f(i)) N = INT() A = [] i = 0 while 5 ** i <= 10 ** 18: A.append(5**i * 10) i += 1 if N % 2 == 0: ans = 0 for a in A: ans += N // a print(ans) else: print((0))
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N = INT() A = [] i = 1 while 5 ** i * 2 <= INF: A.append(5**i * 2) i += 1 if N % 2 == 0: ans = 0 for a in A: ans += N // a print(ans) else: print((0))
45
35
1,100
894
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def f(n): if n <= 1: return 1 else: return n * f(n - 2) # for i in range(100): # for i in [90, 100, 140, 150, 160, 200, 1240, 1250, 1250, 1260]: # print(i, f(i)) N = INT() A = [] i = 0 while 5**i <= 10**18: A.append(5**i * 10) i += 1 if N % 2 == 0: ans = 0 for a in A: ans += N // a print(ans) else: print((0))
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() A = [] i = 1 while 5**i * 2 <= INF: A.append(5**i * 2) i += 1 if N % 2 == 0: ans = 0 for a in A: ans += N // a print(ans) else: print((0))
false
22.222222
[ "-", "-", "-def f(n):", "- if n <= 1:", "- return 1", "- else:", "- return n * f(n - 2)", "-", "-", "-# for i in range(100):", "-# for i in [90, 100, 140, 150, 160, 200, 1240, 1250, 1250, 1260]:", "-# print(i, f(i))", "-i = 0", "-while 5**i <= 10**18:", "- A.append(5**i * 10)", "+i = 1", "+while 5**i * 2 <= INF:", "+ A.append(5**i * 2)" ]
false
0.043438
0.043596
0.996374
[ "s893195338", "s921301894" ]
u606523772
p03146
python
s505092450
s307894571
22
19
2,940
3,064
Accepted
Accepted
13.64
def func1(N): if N%2==0: return N//2 else: return 3*N+1 s = int(eval(input())) a_n = {} for i in range(1, 1000001): if s in a_n: break else: a_n[s] = 1 s = func1(s) print(i)
s = int(eval(input())) a_list = [s] i = 0 ans = -1 while (ans==-1): if a_list[i]%2==0: a_list.append(a_list[i]//2) else: a_list.append(3*a_list[i]+1) i += 1 for j in range(len(a_list)-1): if a_list[i]==a_list[j]: ans = i break print((ans+1))
14
15
232
311
def func1(N): if N % 2 == 0: return N // 2 else: return 3 * N + 1 s = int(eval(input())) a_n = {} for i in range(1, 1000001): if s in a_n: break else: a_n[s] = 1 s = func1(s) print(i)
s = int(eval(input())) a_list = [s] i = 0 ans = -1 while ans == -1: if a_list[i] % 2 == 0: a_list.append(a_list[i] // 2) else: a_list.append(3 * a_list[i] + 1) i += 1 for j in range(len(a_list) - 1): if a_list[i] == a_list[j]: ans = i break print((ans + 1))
false
6.666667
[ "-def func1(N):", "- if N % 2 == 0:", "- return N // 2", "+s = int(eval(input()))", "+a_list = [s]", "+i = 0", "+ans = -1", "+while ans == -1:", "+ if a_list[i] % 2 == 0:", "+ a_list.append(a_list[i] // 2)", "- return 3 * N + 1", "-", "-", "-s = int(eval(input()))", "-a_n = {}", "-for i in range(1, 1000001):", "- if s in a_n:", "- break", "- else:", "- a_n[s] = 1", "- s = func1(s)", "-print(i)", "+ a_list.append(3 * a_list[i] + 1)", "+ i += 1", "+ for j in range(len(a_list) - 1):", "+ if a_list[i] == a_list[j]:", "+ ans = i", "+ break", "+print((ans + 1))" ]
false
0.038245
0.108036
0.354006
[ "s505092450", "s307894571" ]
u808373096
p03624
python
s663514691
s294698508
60
18
4,280
3,188
Accepted
Accepted
70
s = sorted(eval(input())) for i in range(26): if chr(i + 97) not in s: print((chr(i + 97))) exit() print(None)
s = eval(input()) for i in range(26): if chr(i + 97) not in s: print((chr(i + 97))) quit() print(None)
7
7
130
122
s = sorted(eval(input())) for i in range(26): if chr(i + 97) not in s: print((chr(i + 97))) exit() print(None)
s = eval(input()) for i in range(26): if chr(i + 97) not in s: print((chr(i + 97))) quit() print(None)
false
0
[ "-s = sorted(eval(input()))", "+s = eval(input())", "- exit()", "+ quit()" ]
false
0.039468
0.041434
0.95255
[ "s663514691", "s294698508" ]
u170201762
p04014
python
s819891665
s221242912
995
231
67,668
43,120
Accepted
Accepted
76.78
from math import floor,ceil def f(b,n): if n < b: return n else: return f(b,floor(n/b))+n%b n = int(eval(input())) s = int(eval(input())) for b in range(2,320000): if f(b,n)==s: print(b) exit() if n==s: print((s+1)) exit() d = {} for i in range(1,ceil(n**0.5)): m = f(n//i,n) if n//i==n//(i+1): d[i] = (m,m) else: M = f(n//(i+1)+1,n) d[i] = (m,M) for i in range(ceil(n**0.5)-1,0,-1): m,M = d[i] if m<=s<=M and (s-m)%i==0: print((n//i-(s-m)//i)) exit() print((-1))
def f(b,n): if n < b: return n else: return f(b,n//b)+n%b def get_divisor(n): res = [] for i in range(1,int(n**0.5)+1): if n%i==0: res.append(i) res.append(n//i) res = list(set(res)) res.sort() return res n = int(eval(input())) s = int(eval(input())) ans = -1 for b in range(2,int(n**0.5)+1): if f(b,n)==s: ans = b break if ans==-1 and n>=s: div = get_divisor(n-s) div.append(n) for b in div: b += 1 if f(b,n)==s: ans = b break print(ans)
34
35
595
613
from math import floor, ceil def f(b, n): if n < b: return n else: return f(b, floor(n / b)) + n % b n = int(eval(input())) s = int(eval(input())) for b in range(2, 320000): if f(b, n) == s: print(b) exit() if n == s: print((s + 1)) exit() d = {} for i in range(1, ceil(n**0.5)): m = f(n // i, n) if n // i == n // (i + 1): d[i] = (m, m) else: M = f(n // (i + 1) + 1, n) d[i] = (m, M) for i in range(ceil(n**0.5) - 1, 0, -1): m, M = d[i] if m <= s <= M and (s - m) % i == 0: print((n // i - (s - m) // i)) exit() print((-1))
def f(b, n): if n < b: return n else: return f(b, n // b) + n % b def get_divisor(n): res = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) res.append(n // i) res = list(set(res)) res.sort() return res n = int(eval(input())) s = int(eval(input())) ans = -1 for b in range(2, int(n**0.5) + 1): if f(b, n) == s: ans = b break if ans == -1 and n >= s: div = get_divisor(n - s) div.append(n) for b in div: b += 1 if f(b, n) == s: ans = b break print(ans)
false
2.857143
[ "-from math import floor, ceil", "-", "-", "- return f(b, floor(n / b)) + n % b", "+ return f(b, n // b) + n % b", "+", "+", "+def get_divisor(n):", "+ res = []", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ res.append(i)", "+ res.append(n // i)", "+ res = list(set(res))", "+ res.sort()", "+ return res", "-for b in range(2, 320000):", "+ans = -1", "+for b in range(2, int(n**0.5) + 1):", "- print(b)", "- exit()", "-if n == s:", "- print((s + 1))", "- exit()", "-d = {}", "-for i in range(1, ceil(n**0.5)):", "- m = f(n // i, n)", "- if n // i == n // (i + 1):", "- d[i] = (m, m)", "- else:", "- M = f(n // (i + 1) + 1, n)", "- d[i] = (m, M)", "-for i in range(ceil(n**0.5) - 1, 0, -1):", "- m, M = d[i]", "- if m <= s <= M and (s - m) % i == 0:", "- print((n // i - (s - m) // i))", "- exit()", "-print((-1))", "+ ans = b", "+ break", "+if ans == -1 and n >= s:", "+ div = get_divisor(n - s)", "+ div.append(n)", "+ for b in div:", "+ b += 1", "+ if f(b, n) == s:", "+ ans = b", "+ break", "+print(ans)" ]
false
0.200616
0.071148
2.819708
[ "s819891665", "s221242912" ]
u423585790
p02667
python
s378382989
s764200779
72
61
84,872
68,280
Accepted
Accepted
15.28
t=eval(input()) n=len(t) pos=[] sum=0 for i in range(n): if t[i]=="1": sum+=1 else: pos.append(sum) x=(sum+1)//2*((sum+2)//2) sz=len(pos) cnt=0 res=[] for i in range(sz): if ((pos[i]&1)^(cnt&1)): sum+=1 cnt+=1 x+=(sum+1)//2 else: res.append(i) res=res[::-1] odd=0 even=0 for i in range(len(res)): sum+=1 if i&1: odd = sz - res[i] - even x+=(sum+1)//2-odd else: even=sz-res[i]-odd x+=(sum+1)//2-even print(x)
T=eval(input()) n=len(T) i=r=a=0 for c in T: k=i-r if c=='0': r+=~k&1 else: a+=i//2-k//2+(~k&1)*(n-i) i+=1 print(a)
32
11
486
136
t = eval(input()) n = len(t) pos = [] sum = 0 for i in range(n): if t[i] == "1": sum += 1 else: pos.append(sum) x = (sum + 1) // 2 * ((sum + 2) // 2) sz = len(pos) cnt = 0 res = [] for i in range(sz): if (pos[i] & 1) ^ (cnt & 1): sum += 1 cnt += 1 x += (sum + 1) // 2 else: res.append(i) res = res[::-1] odd = 0 even = 0 for i in range(len(res)): sum += 1 if i & 1: odd = sz - res[i] - even x += (sum + 1) // 2 - odd else: even = sz - res[i] - odd x += (sum + 1) // 2 - even print(x)
T = eval(input()) n = len(T) i = r = a = 0 for c in T: k = i - r if c == "0": r += ~k & 1 else: a += i // 2 - k // 2 + (~k & 1) * (n - i) i += 1 print(a)
false
65.625
[ "-t = eval(input())", "-n = len(t)", "-pos = []", "-sum = 0", "-for i in range(n):", "- if t[i] == \"1\":", "- sum += 1", "+T = eval(input())", "+n = len(T)", "+i = r = a = 0", "+for c in T:", "+ k = i - r", "+ if c == \"0\":", "+ r += ~k & 1", "- pos.append(sum)", "-x = (sum + 1) // 2 * ((sum + 2) // 2)", "-sz = len(pos)", "-cnt = 0", "-res = []", "-for i in range(sz):", "- if (pos[i] & 1) ^ (cnt & 1):", "- sum += 1", "- cnt += 1", "- x += (sum + 1) // 2", "- else:", "- res.append(i)", "-res = res[::-1]", "-odd = 0", "-even = 0", "-for i in range(len(res)):", "- sum += 1", "- if i & 1:", "- odd = sz - res[i] - even", "- x += (sum + 1) // 2 - odd", "- else:", "- even = sz - res[i] - odd", "- x += (sum + 1) // 2 - even", "-print(x)", "+ a += i // 2 - k // 2 + (~k & 1) * (n - i)", "+ i += 1", "+print(a)" ]
false
0.03713
0.056457
0.657669
[ "s378382989", "s764200779" ]
u037830865
p02861
python
s997306375
s229853227
429
18
7,972
2,940
Accepted
Accepted
95.8
import itertools import math N = int(eval(input())) city_list = [] for i in range(N): x, y = [int(z) for z in input().split()] city_list.append((x, y)) root_list = list(itertools.permutations(city_list, N)) ave = 0 for root in root_list: length = 0 while len(root) > 1: x1, y1, x2, y2 = root[0][0], root[0][1], root[1][0], root[1][1] length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) root = root[1:] ave += (length / len(root_list)) print(ave)
import math N = int(eval(input())) city_list = [list(map(int, input().split())) for _ in range(N)] average = 0 for x1, y1 in city_list: for x2, y2 in city_list: average += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) print((average / N))
17
8
506
247
import itertools import math N = int(eval(input())) city_list = [] for i in range(N): x, y = [int(z) for z in input().split()] city_list.append((x, y)) root_list = list(itertools.permutations(city_list, N)) ave = 0 for root in root_list: length = 0 while len(root) > 1: x1, y1, x2, y2 = root[0][0], root[0][1], root[1][0], root[1][1] length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) root = root[1:] ave += length / len(root_list) print(ave)
import math N = int(eval(input())) city_list = [list(map(int, input().split())) for _ in range(N)] average = 0 for x1, y1 in city_list: for x2, y2 in city_list: average += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) print((average / N))
false
52.941176
[ "-import itertools", "-city_list = []", "-for i in range(N):", "- x, y = [int(z) for z in input().split()]", "- city_list.append((x, y))", "-root_list = list(itertools.permutations(city_list, N))", "-ave = 0", "-for root in root_list:", "- length = 0", "- while len(root) > 1:", "- x1, y1, x2, y2 = root[0][0], root[0][1], root[1][0], root[1][1]", "- length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)", "- root = root[1:]", "- ave += length / len(root_list)", "-print(ave)", "+city_list = [list(map(int, input().split())) for _ in range(N)]", "+average = 0", "+for x1, y1 in city_list:", "+ for x2, y2 in city_list:", "+ average += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)", "+print((average / N))" ]
false
0.051026
0.039773
1.282921
[ "s997306375", "s229853227" ]
u157232135
p02623
python
s153842248
s974874113
274
232
48,768
45,696
Accepted
Accepted
15.33
import itertools as it def main(): n,m,k=list(map(int,input().split())) Aa = list(map(int,input().split())) Bb = list(map(int, input().split())) a, b = [0],[0] for i in range(n): a.append(a[i] + Aa[i]) for i in range(m): b.append(b[i] + Bb[i]) M = m ans = 0 for A in range(n+1): aa = a[A] Kaa = k-aa if Kaa < 0: break for B in range(M,-1,-1): if b[B] <= Kaa: ans = max(ans, A+B) M = B break print(ans) if __name__ == '__main__': main()
import itertools as it def main(): n,m,k=list(map(int,input().split())) a = [0] a.extend(it.accumulate(list(map(int, input().split())))) b = [0] b.extend(it.accumulate(list(map(int, input().split())))) ans = 0 M = m for A in range(n+1): aa = a[A] Kaa = k-aa if Kaa < 0: break for B in range(M,-1,-1): if b[B] <= Kaa: ans = max(ans, A+B) M = B break print(ans) if __name__ == '__main__': main()
26
24
619
548
import itertools as it def main(): n, m, k = list(map(int, input().split())) Aa = list(map(int, input().split())) Bb = list(map(int, input().split())) a, b = [0], [0] for i in range(n): a.append(a[i] + Aa[i]) for i in range(m): b.append(b[i] + Bb[i]) M = m ans = 0 for A in range(n + 1): aa = a[A] Kaa = k - aa if Kaa < 0: break for B in range(M, -1, -1): if b[B] <= Kaa: ans = max(ans, A + B) M = B break print(ans) if __name__ == "__main__": main()
import itertools as it def main(): n, m, k = list(map(int, input().split())) a = [0] a.extend(it.accumulate(list(map(int, input().split())))) b = [0] b.extend(it.accumulate(list(map(int, input().split())))) ans = 0 M = m for A in range(n + 1): aa = a[A] Kaa = k - aa if Kaa < 0: break for B in range(M, -1, -1): if b[B] <= Kaa: ans = max(ans, A + B) M = B break print(ans) if __name__ == "__main__": main()
false
7.692308
[ "- Aa = list(map(int, input().split()))", "- Bb = list(map(int, input().split()))", "- a, b = [0], [0]", "- for i in range(n):", "- a.append(a[i] + Aa[i])", "- for i in range(m):", "- b.append(b[i] + Bb[i])", "+ a = [0]", "+ a.extend(it.accumulate(list(map(int, input().split()))))", "+ b = [0]", "+ b.extend(it.accumulate(list(map(int, input().split()))))", "+ ans = 0", "- ans = 0" ]
false
0.034061
0.046227
0.736819
[ "s153842248", "s974874113" ]
u475503988
p03212
python
s816882717
s549484545
84
42
3,064
3,064
Accepted
Accepted
50
def nextn(n): if n == 0: return 3 elif n % 10 == 3: return n+2 elif n % 10== 5: return n+2 elif n % 10 ==7: return nextn(n//10)*10 + 3 N = int(eval(input())) n = 357 ans = 0 while n <= N: s = str(n) a = [False,False,False] for c in s: if c == '3': a[0] = True elif c == '5': a[1] = True elif c == '7': a[2] = True else: print(s) if all(a): ans += 1 n = nextn(n) print(ans)
def nexti(i): if i == 0: return 3 elif i % 10 == 3: return i + 2 elif i % 10== 5: return i + 2 elif i % 10 ==7: return nexti(i//10)*10 + 3 n = int(eval(input())) nn = 0 i = 357 while i <= n: s = str(i) if '3' in s: if '5' in s: if '7' in s: #print(i) nn += 1 if i % 10 == 7: i = nexti(i) else: i +=2 print(nn)
29
26
553
420
def nextn(n): if n == 0: return 3 elif n % 10 == 3: return n + 2 elif n % 10 == 5: return n + 2 elif n % 10 == 7: return nextn(n // 10) * 10 + 3 N = int(eval(input())) n = 357 ans = 0 while n <= N: s = str(n) a = [False, False, False] for c in s: if c == "3": a[0] = True elif c == "5": a[1] = True elif c == "7": a[2] = True else: print(s) if all(a): ans += 1 n = nextn(n) print(ans)
def nexti(i): if i == 0: return 3 elif i % 10 == 3: return i + 2 elif i % 10 == 5: return i + 2 elif i % 10 == 7: return nexti(i // 10) * 10 + 3 n = int(eval(input())) nn = 0 i = 357 while i <= n: s = str(i) if "3" in s: if "5" in s: if "7" in s: # print(i) nn += 1 if i % 10 == 7: i = nexti(i) else: i += 2 print(nn)
false
10.344828
[ "-def nextn(n):", "- if n == 0:", "+def nexti(i):", "+ if i == 0:", "- elif n % 10 == 3:", "- return n + 2", "- elif n % 10 == 5:", "- return n + 2", "- elif n % 10 == 7:", "- return nextn(n // 10) * 10 + 3", "+ elif i % 10 == 3:", "+ return i + 2", "+ elif i % 10 == 5:", "+ return i + 2", "+ elif i % 10 == 7:", "+ return nexti(i // 10) * 10 + 3", "-N = int(eval(input()))", "-n = 357", "-ans = 0", "-while n <= N:", "- s = str(n)", "- a = [False, False, False]", "- for c in s:", "- if c == \"3\":", "- a[0] = True", "- elif c == \"5\":", "- a[1] = True", "- elif c == \"7\":", "- a[2] = True", "- else:", "- print(s)", "- if all(a):", "- ans += 1", "- n = nextn(n)", "-print(ans)", "+n = int(eval(input()))", "+nn = 0", "+i = 357", "+while i <= n:", "+ s = str(i)", "+ if \"3\" in s:", "+ if \"5\" in s:", "+ if \"7\" in s:", "+ # print(i)", "+ nn += 1", "+ if i % 10 == 7:", "+ i = nexti(i)", "+ else:", "+ i += 2", "+print(nn)" ]
false
0.08735
0.069406
1.258526
[ "s816882717", "s549484545" ]
u037430802
p03426
python
s145006768
s111967774
966
554
22,560
35,984
Accepted
Accepted
42.65
H, W, D = list(map(int, input().split())) field = {} for i in range(H): A = list(map(int, input().split())) for j in range(W): field[A[j]] = (i,j) Q = int(eval(input())) cum = [0] * (H*W+1) for i in range(D+1, H*W+1): cum[i] = cum[i-D] + abs(field[i][0] - field[i-D][0]) + abs(field[i][1] - field[i-D][1]) """ for i in range(1,D+1): tmp = 0 cum[i] = 0 n = D while i+n <= H*W: cum[i+n] = cum[i+n-D] + abs(field[i+n][0] - field[i+n-D][0]) + abs(field[i+n][1] - field[i+n-D][1]) #print("---", i+n, cum[i+n], field[i+n][0] , field[i+n-D][0], field[i+n][1] , field[i+n-D][1]) n += D """ #print(cum) for i in range(Q): L, R = list(map(int, input().split())) print((cum[R] - cum[L])) #print(field)
H, W, D = list(map(int, input().split())) field = {} for i in range(H): A = list(map(int, input().split())) for j in range(W): field[A[j]] = (i,j) Q = int(eval(input())) cum = [0] * (H*W+1) for i in range(D+1, H*W+1): cum[i] = cum[i-D] + abs(field[i][0] - field[i-D][0]) + abs(field[i][1] - field[i-D][1]) """ for i in range(1,D+1): tmp = 0 cum[i] = 0 n = D while i+n <= H*W: cum[i+n] = cum[i+n-D] + abs(field[i+n][0] - field[i+n-D][0]) + abs(field[i+n][1] - field[i+n-D][1]) #print("---", i+n, cum[i+n], field[i+n][0] , field[i+n-D][0], field[i+n][1] , field[i+n-D][1]) n += D """ #print(cum) LR = [None] * Q for i in range(Q): L, R = list(map(int, input().split())) LR[i] = (L,R) for l,r in LR: print((cum[r] - cum[l]))
32
35
776
816
H, W, D = list(map(int, input().split())) field = {} for i in range(H): A = list(map(int, input().split())) for j in range(W): field[A[j]] = (i, j) Q = int(eval(input())) cum = [0] * (H * W + 1) for i in range(D + 1, H * W + 1): cum[i] = ( cum[i - D] + abs(field[i][0] - field[i - D][0]) + abs(field[i][1] - field[i - D][1]) ) """ for i in range(1,D+1): tmp = 0 cum[i] = 0 n = D while i+n <= H*W: cum[i+n] = cum[i+n-D] + abs(field[i+n][0] - field[i+n-D][0]) + abs(field[i+n][1] - field[i+n-D][1]) #print("---", i+n, cum[i+n], field[i+n][0] , field[i+n-D][0], field[i+n][1] , field[i+n-D][1]) n += D """ # print(cum) for i in range(Q): L, R = list(map(int, input().split())) print((cum[R] - cum[L])) # print(field)
H, W, D = list(map(int, input().split())) field = {} for i in range(H): A = list(map(int, input().split())) for j in range(W): field[A[j]] = (i, j) Q = int(eval(input())) cum = [0] * (H * W + 1) for i in range(D + 1, H * W + 1): cum[i] = ( cum[i - D] + abs(field[i][0] - field[i - D][0]) + abs(field[i][1] - field[i - D][1]) ) """ for i in range(1,D+1): tmp = 0 cum[i] = 0 n = D while i+n <= H*W: cum[i+n] = cum[i+n-D] + abs(field[i+n][0] - field[i+n-D][0]) + abs(field[i+n][1] - field[i+n-D][1]) #print("---", i+n, cum[i+n], field[i+n][0] , field[i+n-D][0], field[i+n][1] , field[i+n-D][1]) n += D """ # print(cum) LR = [None] * Q for i in range(Q): L, R = list(map(int, input().split())) LR[i] = (L, R) for l, r in LR: print((cum[r] - cum[l]))
false
8.571429
[ "+LR = [None] * Q", "- print((cum[R] - cum[L]))", "-# print(field)", "+ LR[i] = (L, R)", "+for l, r in LR:", "+ print((cum[r] - cum[l]))" ]
false
0.037162
0.007795
4.767442
[ "s145006768", "s111967774" ]
u411203878
p03575
python
s776776940
s978004438
403
116
86,740
76,052
Accepted
Accepted
71.22
import copy import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) class UnionFindPathCompression(): def __init__(self, n:int): self.parents = list(range(n)) self.rank = [1]*n self.size = [1]*n def find(self, x:int) -> int: if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x:int, y:int): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] < self.rank[py]: self.parents[px] = py self.size[py] += self.size[px] else: self.parents[py] = px self.size[px] += self.size[py] #ランクの更新 if self.rank[px] == self.rank[py]: self.rank[px] += 1 n,m = list(map(int,input().split())) ab = [list(map(int, input().split())) for _ in range(m)] memo = 0 for i in range(m): ufpc = UnionFindPathCompression(n) ab_copy = copy.deepcopy(ab) ab_copy.pop(i) for a,b in ab_copy: a,b = a-1,b-1 ufpc.union(a,b) for i in range(n): ufpc.find(i) check = set(ufpc.parents) if len(check)==1: memo += 1 print((m-memo))
import copy import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) class UnionFindPathCompression(): def __init__(self, n:int): self.parents = list(range(n)) self.rank = [1]*n self.size = [1]*n def find(self, x:int) -> int: if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x:int, y:int): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] < self.rank[py]: self.parents[px] = py self.size[py] += self.size[px] else: self.parents[py] = px self.size[px] += self.size[py] #ランクの更新 if self.rank[px] == self.rank[py]: self.rank[px] += 1 n,m = list(map(int,input().split())) ab = [list(map(int, input().split())) for _ in range(m)] ans = 0 for i in range(m): ufpc = UnionFindPathCompression(n) ab_copy = copy.deepcopy(ab) ab_copy.pop(i) for a,b in ab_copy: a,b = a-1,b-1 ufpc.union(a,b) for i in range(n): ufpc.find(i) check = set(ufpc.parents) if len(check) != 1: ans += 1 print(ans)
54
55
1,399
1,406
import copy import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) class UnionFindPathCompression: def __init__(self, n: int): self.parents = list(range(n)) self.rank = [1] * n self.size = [1] * n def find(self, x: int) -> int: if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x: int, y: int): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] < self.rank[py]: self.parents[px] = py self.size[py] += self.size[px] else: self.parents[py] = px self.size[px] += self.size[py] # ランクの更新 if self.rank[px] == self.rank[py]: self.rank[px] += 1 n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] memo = 0 for i in range(m): ufpc = UnionFindPathCompression(n) ab_copy = copy.deepcopy(ab) ab_copy.pop(i) for a, b in ab_copy: a, b = a - 1, b - 1 ufpc.union(a, b) for i in range(n): ufpc.find(i) check = set(ufpc.parents) if len(check) == 1: memo += 1 print((m - memo))
import copy import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) class UnionFindPathCompression: def __init__(self, n: int): self.parents = list(range(n)) self.rank = [1] * n self.size = [1] * n def find(self, x: int) -> int: if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x: int, y: int): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] < self.rank[py]: self.parents[px] = py self.size[py] += self.size[px] else: self.parents[py] = px self.size[px] += self.size[py] # ランクの更新 if self.rank[px] == self.rank[py]: self.rank[px] += 1 n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] ans = 0 for i in range(m): ufpc = UnionFindPathCompression(n) ab_copy = copy.deepcopy(ab) ab_copy.pop(i) for a, b in ab_copy: a, b = a - 1, b - 1 ufpc.union(a, b) for i in range(n): ufpc.find(i) check = set(ufpc.parents) if len(check) != 1: ans += 1 print(ans)
false
1.818182
[ "-memo = 0", "+ans = 0", "- if len(check) == 1:", "- memo += 1", "-print((m - memo))", "+ if len(check) != 1:", "+ ans += 1", "+print(ans)" ]
false
0.046807
0.049102
0.953256
[ "s776776940", "s978004438" ]
u260216890
p03061
python
s556184124
s595868869
394
126
98,280
103,168
Accepted
Accepted
68.02
n=int(eval(input())) a=list(map(int,input().split())) from fractions import gcd L=[0] R=[] l=a[0] r=a[-1] for i in range(n-1): l=gcd(a[i], l) L.append(l) r=gcd(a[-i-1], r) R.append(r) R=R[::-1] R.append(0) M=[] #print(L,R) for i in range(n): m=gcd(L[i],R[i]) M.append(m) print((max(M)))
n=int(eval(input())) *a,=list(map(int,input().split())) a=sorted(a) from math import gcd for i in range(n): if i==0: tmp=a[i] else: tmp=gcd(tmp, a[i]) b=[x//tmp for x in a] for i in range(n): if i==0: tmp=b[i] else: tmp=gcd(tmp, b[i]) if tmp==1: l=i-1 r=i break if l>0: c=a[:l]+a[l+1:] else: c=a[1:] if r+1<n: d=a[:r]+a[r+1:] else: d=a[:r] for i in range(len(c)): if i==0: ctmp=c[i] dtmp=d[i] else: ctmp=gcd(ctmp, c[i]) dtmp=gcd(dtmp, d[i]) ans=max(ctmp,dtmp) for i in range(n-1,-1,-1): if i==n-1: tmp=b[i] else: tmp=gcd(tmp, b[i]) if tmp==1: l=i r=i+1 break if l>0: c=a[:l]+a[l+1:] else: c=a[1:] if r+1<n: d=a[:r]+a[r+1:] else: d=a[:r] for i in range(len(c)): if i==0: ctmp=c[i] dtmp=d[i] else: ctmp=gcd(ctmp, c[i]) dtmp=gcd(dtmp, d[i]) print((max(ans,ctmp,dtmp)))
20
68
321
1,098
n = int(eval(input())) a = list(map(int, input().split())) from fractions import gcd L = [0] R = [] l = a[0] r = a[-1] for i in range(n - 1): l = gcd(a[i], l) L.append(l) r = gcd(a[-i - 1], r) R.append(r) R = R[::-1] R.append(0) M = [] # print(L,R) for i in range(n): m = gcd(L[i], R[i]) M.append(m) print((max(M)))
n = int(eval(input())) (*a,) = list(map(int, input().split())) a = sorted(a) from math import gcd for i in range(n): if i == 0: tmp = a[i] else: tmp = gcd(tmp, a[i]) b = [x // tmp for x in a] for i in range(n): if i == 0: tmp = b[i] else: tmp = gcd(tmp, b[i]) if tmp == 1: l = i - 1 r = i break if l > 0: c = a[:l] + a[l + 1 :] else: c = a[1:] if r + 1 < n: d = a[:r] + a[r + 1 :] else: d = a[:r] for i in range(len(c)): if i == 0: ctmp = c[i] dtmp = d[i] else: ctmp = gcd(ctmp, c[i]) dtmp = gcd(dtmp, d[i]) ans = max(ctmp, dtmp) for i in range(n - 1, -1, -1): if i == n - 1: tmp = b[i] else: tmp = gcd(tmp, b[i]) if tmp == 1: l = i r = i + 1 break if l > 0: c = a[:l] + a[l + 1 :] else: c = a[1:] if r + 1 < n: d = a[:r] + a[r + 1 :] else: d = a[:r] for i in range(len(c)): if i == 0: ctmp = c[i] dtmp = d[i] else: ctmp = gcd(ctmp, c[i]) dtmp = gcd(dtmp, d[i]) print((max(ans, ctmp, dtmp)))
false
70.588235
[ "-a = list(map(int, input().split()))", "-from fractions import gcd", "+(*a,) = list(map(int, input().split()))", "+a = sorted(a)", "+from math import gcd", "-L = [0]", "-R = []", "-l = a[0]", "-r = a[-1]", "-for i in range(n - 1):", "- l = gcd(a[i], l)", "- L.append(l)", "- r = gcd(a[-i - 1], r)", "- R.append(r)", "-R = R[::-1]", "-R.append(0)", "-M = []", "-# print(L,R)", "- m = gcd(L[i], R[i])", "- M.append(m)", "-print((max(M)))", "+ if i == 0:", "+ tmp = a[i]", "+ else:", "+ tmp = gcd(tmp, a[i])", "+b = [x // tmp for x in a]", "+for i in range(n):", "+ if i == 0:", "+ tmp = b[i]", "+ else:", "+ tmp = gcd(tmp, b[i])", "+ if tmp == 1:", "+ l = i - 1", "+ r = i", "+ break", "+if l > 0:", "+ c = a[:l] + a[l + 1 :]", "+else:", "+ c = a[1:]", "+if r + 1 < n:", "+ d = a[:r] + a[r + 1 :]", "+else:", "+ d = a[:r]", "+for i in range(len(c)):", "+ if i == 0:", "+ ctmp = c[i]", "+ dtmp = d[i]", "+ else:", "+ ctmp = gcd(ctmp, c[i])", "+ dtmp = gcd(dtmp, d[i])", "+ans = max(ctmp, dtmp)", "+for i in range(n - 1, -1, -1):", "+ if i == n - 1:", "+ tmp = b[i]", "+ else:", "+ tmp = gcd(tmp, b[i])", "+ if tmp == 1:", "+ l = i", "+ r = i + 1", "+ break", "+if l > 0:", "+ c = a[:l] + a[l + 1 :]", "+else:", "+ c = a[1:]", "+if r + 1 < n:", "+ d = a[:r] + a[r + 1 :]", "+else:", "+ d = a[:r]", "+for i in range(len(c)):", "+ if i == 0:", "+ ctmp = c[i]", "+ dtmp = d[i]", "+ else:", "+ ctmp = gcd(ctmp, c[i])", "+ dtmp = gcd(dtmp, d[i])", "+print((max(ans, ctmp, dtmp)))" ]
false
0.052755
0.113999
0.462768
[ "s556184124", "s595868869" ]
u753803401
p03078
python
s392196089
s362357786
1,565
451
5,228
62,572
Accepted
Accepted
71.18
import heapq x, y, z , k = list(map(int, input().split())) a = sorted(list(map(int, input().split())), reverse=True) b = sorted(list(map(int, input().split())), reverse=True) c = sorted(list(map(int, input().split())), reverse=True) q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] qh = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] heapq.heapify(q) ans = [] heapq.heapify(ans) for i in range(k): t, aq, bq, cq = heapq.heappop(q) heapq.heappush(ans, t) if aq + 1 < len(a): if [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq] not in qh: heapq.heappush(q, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq]) heapq.heappush(qh, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq]) if bq + 1 < len(a): if [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq] not in qh: heapq.heappush(q, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq]) heapq.heappush(qh, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq]) if cq + 1 < len(a): if [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1] not in qh: heapq.heappush(q, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1]) heapq.heappush(qh, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1]) for i in range(len(ans)): print((-heapq.heappop(ans)))
def slove(): import sys import heapq import collections input = sys.stdin.readline x, y, z, k = list(map(int, input().rstrip('\n').split())) a = list(map(int, input().rstrip('\n').split())) a.sort(reverse=True) b = list(map(int, input().rstrip('\n').split())) b.sort(reverse=True) c = list(map(int, input().rstrip('\n').split())) c.sort(reverse=True) q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] heapq.heapify(q) fq = collections.defaultdict(list) fq[(-(a[0] + b[0] + c[0]), 0, 0, 0), 1] = 1 t = 0 for _ in range(k): if len(q) != 0: p = heapq.heappop(q) t = p[0] aq = p[1] bq = p[2] cq = p[3] if aq + 1 < len(a): if (-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq) not in fq: heapq.heappush(q, [-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq]) fq[(-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq)] = 1 if bq + 1 < len(b): if (-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq) not in fq: heapq.heappush(q, [-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq]) fq[(-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq)] = 1 if cq + 1 < len(c): if (-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1) not in fq: heapq.heappush(q, [-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1]) fq[(-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1)] = 1 print((-t)) if __name__ == '__main__': slove()
27
41
1,267
1,596
import heapq x, y, z, k = list(map(int, input().split())) a = sorted(list(map(int, input().split())), reverse=True) b = sorted(list(map(int, input().split())), reverse=True) c = sorted(list(map(int, input().split())), reverse=True) q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] qh = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] heapq.heapify(q) ans = [] heapq.heapify(ans) for i in range(k): t, aq, bq, cq = heapq.heappop(q) heapq.heappush(ans, t) if aq + 1 < len(a): if [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq] not in qh: heapq.heappush(q, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq]) heapq.heappush(qh, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq]) if bq + 1 < len(a): if [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq] not in qh: heapq.heappush(q, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq]) heapq.heappush(qh, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq]) if cq + 1 < len(a): if [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1] not in qh: heapq.heappush(q, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1]) heapq.heappush(qh, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1]) for i in range(len(ans)): print((-heapq.heappop(ans)))
def slove(): import sys import heapq import collections input = sys.stdin.readline x, y, z, k = list(map(int, input().rstrip("\n").split())) a = list(map(int, input().rstrip("\n").split())) a.sort(reverse=True) b = list(map(int, input().rstrip("\n").split())) b.sort(reverse=True) c = list(map(int, input().rstrip("\n").split())) c.sort(reverse=True) q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]] heapq.heapify(q) fq = collections.defaultdict(list) fq[(-(a[0] + b[0] + c[0]), 0, 0, 0), 1] = 1 t = 0 for _ in range(k): if len(q) != 0: p = heapq.heappop(q) t = p[0] aq = p[1] bq = p[2] cq = p[3] if aq + 1 < len(a): if (-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq) not in fq: heapq.heappush(q, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq]) fq[(-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq)] = 1 if bq + 1 < len(b): if (-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq) not in fq: heapq.heappush(q, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq]) fq[(-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq)] = 1 if cq + 1 < len(c): if (-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1) not in fq: heapq.heappush(q, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1]) fq[(-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1)] = 1 print((-t)) if __name__ == "__main__": slove()
false
34.146341
[ "-import heapq", "+def slove():", "+ import sys", "+ import heapq", "+ import collections", "-x, y, z, k = list(map(int, input().split()))", "-a = sorted(list(map(int, input().split())), reverse=True)", "-b = sorted(list(map(int, input().split())), reverse=True)", "-c = sorted(list(map(int, input().split())), reverse=True)", "-q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]", "-qh = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]", "-heapq.heapify(q)", "-ans = []", "-heapq.heapify(ans)", "-for i in range(k):", "- t, aq, bq, cq = heapq.heappop(q)", "- heapq.heappush(ans, t)", "- if aq + 1 < len(a):", "- if [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq] not in qh:", "- heapq.heappush(q, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq])", "- heapq.heappush(qh, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq])", "- if bq + 1 < len(a):", "- if [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq] not in qh:", "- heapq.heappush(q, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq])", "- heapq.heappush(qh, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq])", "- if cq + 1 < len(a):", "- if [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1] not in qh:", "- heapq.heappush(q, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1])", "- heapq.heappush(qh, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1])", "-for i in range(len(ans)):", "- print((-heapq.heappop(ans)))", "+ input = sys.stdin.readline", "+ x, y, z, k = list(map(int, input().rstrip(\"\\n\").split()))", "+ a = list(map(int, input().rstrip(\"\\n\").split()))", "+ a.sort(reverse=True)", "+ b = list(map(int, input().rstrip(\"\\n\").split()))", "+ b.sort(reverse=True)", "+ c = list(map(int, input().rstrip(\"\\n\").split()))", "+ c.sort(reverse=True)", "+ q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]", "+ heapq.heapify(q)", "+ fq = collections.defaultdict(list)", "+ fq[(-(a[0] + b[0] + c[0]), 0, 0, 0), 1] = 1", "+ t = 0", "+ for _ in range(k):", "+ if len(q) != 0:", "+ p = heapq.heappop(q)", "+ t = p[0]", "+ aq = p[1]", "+ bq = p[2]", "+ cq = p[3]", "+ if aq + 1 < len(a):", "+ if (-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq) not in fq:", "+ heapq.heappush(q, [-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq])", "+ fq[(-(a[aq + 1] + b[bq] + c[cq]), aq + 1, bq, cq)] = 1", "+ if bq + 1 < len(b):", "+ if (-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq) not in fq:", "+ heapq.heappush(q, [-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq])", "+ fq[(-(a[aq] + b[bq + 1] + c[cq]), aq, bq + 1, cq)] = 1", "+ if cq + 1 < len(c):", "+ if (-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1) not in fq:", "+ heapq.heappush(q, [-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1])", "+ fq[(-(a[aq] + b[bq] + c[cq + 1]), aq, bq, cq + 1)] = 1", "+ print((-t))", "+", "+", "+if __name__ == \"__main__\":", "+ slove()" ]
false
0.045842
0.116289
0.39421
[ "s392196089", "s362357786" ]
u017810624
p03212
python
s092168722
s872955515
1,164
300
3,064
3,064
Accepted
Accepted
74.23
n=int(eval(input())) c=0 l=[3,5,7] L=[] for i1 in l: for i2 in l: for i3 in l: for i4 in l: for i5 in l: L.append(10000*i1+1000*i2+100*i3+10*i4+i5) for i in range(min(n+1,10000)): l=str(i) if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1 for j in L: for i in range(j,n+1,100000): l=str(i) if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1 print(c)
n=int(eval(input())) c=0 l=[0,3,5,7] for i1 in l: for i2 in l: for i3 in l: for i4 in l: for i5 in l: for i6 in l: for i7 in l: for i8 in l: for i9 in l: x=str(i1+10*i2+100*i3+1000*i4+10000*i5+100000*i6+1000000*i7+10000000*i8+100000000*i9) if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1 print(c)
18
15
627
384
n = int(eval(input())) c = 0 l = [3, 5, 7] L = [] for i1 in l: for i2 in l: for i3 in l: for i4 in l: for i5 in l: L.append(10000 * i1 + 1000 * i2 + 100 * i3 + 10 * i4 + i5) for i in range(min(n + 1, 10000)): l = str(i) if ( "3" in l and "5" in l and "7" in l and "0" not in l and "1" not in l and "2" not in l and "4" not in l and "6" not in l and "8" not in l and "9" not in l ): c += 1 for j in L: for i in range(j, n + 1, 100000): l = str(i) if ( "3" in l and "5" in l and "7" in l and "0" not in l and "1" not in l and "2" not in l and "4" not in l and "6" not in l and "8" not in l and "9" not in l ): c += 1 print(c)
n = int(eval(input())) c = 0 l = [0, 3, 5, 7] for i1 in l: for i2 in l: for i3 in l: for i4 in l: for i5 in l: for i6 in l: for i7 in l: for i8 in l: for i9 in l: x = str( i1 + 10 * i2 + 100 * i3 + 1000 * i4 + 10000 * i5 + 100000 * i6 + 1000000 * i7 + 10000000 * i8 + 100000000 * i9 ) if ( "3" in x and "5" in x and "7" in x and "0" not in x and int(x) <= n ): c += 1 print(c)
false
16.666667
[ "-l = [3, 5, 7]", "-L = []", "+l = [0, 3, 5, 7]", "- L.append(10000 * i1 + 1000 * i2 + 100 * i3 + 10 * i4 + i5)", "-for i in range(min(n + 1, 10000)):", "- l = str(i)", "- if (", "- \"3\" in l", "- and \"5\" in l", "- and \"7\" in l", "- and \"0\" not in l", "- and \"1\" not in l", "- and \"2\" not in l", "- and \"4\" not in l", "- and \"6\" not in l", "- and \"8\" not in l", "- and \"9\" not in l", "- ):", "- c += 1", "-for j in L:", "- for i in range(j, n + 1, 100000):", "- l = str(i)", "- if (", "- \"3\" in l", "- and \"5\" in l", "- and \"7\" in l", "- and \"0\" not in l", "- and \"1\" not in l", "- and \"2\" not in l", "- and \"4\" not in l", "- and \"6\" not in l", "- and \"8\" not in l", "- and \"9\" not in l", "- ):", "- c += 1", "+ for i6 in l:", "+ for i7 in l:", "+ for i8 in l:", "+ for i9 in l:", "+ x = str(", "+ i1", "+ + 10 * i2", "+ + 100 * i3", "+ + 1000 * i4", "+ + 10000 * i5", "+ + 100000 * i6", "+ + 1000000 * i7", "+ + 10000000 * i8", "+ + 100000000 * i9", "+ )", "+ if (", "+ \"3\" in x", "+ and \"5\" in x", "+ and \"7\" in x", "+ and \"0\" not in x", "+ and int(x) <= n", "+ ):", "+ c += 1" ]
false
1.20449
0.425793
2.828814
[ "s092168722", "s872955515" ]
u079022693
p02765
python
s504399949
s070452270
20
17
3,316
2,940
Accepted
Accepted
15
def main(): N,R=list(map(int,input().split())) if N>=10: print(R) else: print((R+100*(10-N))) if __name__=="__main__": main()
from sys import stdin def main(): #入力 readline=stdin.readline n,r=list(map(int,readline().split())) if n>=10: print(r) else: print((r+100*(10-n))) if __name__=="__main__": main()
8
12
156
230
def main(): N, R = list(map(int, input().split())) if N >= 10: print(R) else: print((R + 100 * (10 - N))) if __name__ == "__main__": main()
from sys import stdin def main(): # 入力 readline = stdin.readline n, r = list(map(int, readline().split())) if n >= 10: print(r) else: print((r + 100 * (10 - n))) if __name__ == "__main__": main()
false
33.333333
[ "+from sys import stdin", "+", "+", "- N, R = list(map(int, input().split()))", "- if N >= 10:", "- print(R)", "+ # 入力", "+ readline = stdin.readline", "+ n, r = list(map(int, readline().split()))", "+ if n >= 10:", "+ print(r)", "- print((R + 100 * (10 - N)))", "+ print((r + 100 * (10 - n)))" ]
false
0.077342
0.076414
1.012136
[ "s504399949", "s070452270" ]
u553987207
p02947
python
s796499286
s768567163
526
169
24,652
27,928
Accepted
Accepted
67.87
N = int(eval(input())) s = sorted(sorted(eval(input())) for _ in range(N)) ans = 0 cnt = 1 for i in range(1, N): if s[i-1] == s[i]: cnt += 1 else: if cnt > 1: ans += (cnt * (cnt - 1) // 2) cnt = 1 if cnt > 1: ans += (cnt * (cnt - 1) // 2) print(ans)
import sys N = int(eval(input())) counts = {} for _ in range(N): s = tuple(sorted(sys.stdin.readline())) counts[s] = counts.get(s, 0) + 1 ans = 0 for count in list(counts.values()): if count > 1: ans += (count * (count - 1) // 2) print(ans)
14
11
298
258
N = int(eval(input())) s = sorted(sorted(eval(input())) for _ in range(N)) ans = 0 cnt = 1 for i in range(1, N): if s[i - 1] == s[i]: cnt += 1 else: if cnt > 1: ans += cnt * (cnt - 1) // 2 cnt = 1 if cnt > 1: ans += cnt * (cnt - 1) // 2 print(ans)
import sys N = int(eval(input())) counts = {} for _ in range(N): s = tuple(sorted(sys.stdin.readline())) counts[s] = counts.get(s, 0) + 1 ans = 0 for count in list(counts.values()): if count > 1: ans += count * (count - 1) // 2 print(ans)
false
21.428571
[ "+import sys", "+", "-s = sorted(sorted(eval(input())) for _ in range(N))", "+counts = {}", "+for _ in range(N):", "+ s = tuple(sorted(sys.stdin.readline()))", "+ counts[s] = counts.get(s, 0) + 1", "-cnt = 1", "-for i in range(1, N):", "- if s[i - 1] == s[i]:", "- cnt += 1", "- else:", "- if cnt > 1:", "- ans += cnt * (cnt - 1) // 2", "- cnt = 1", "-if cnt > 1:", "- ans += cnt * (cnt - 1) // 2", "+for count in list(counts.values()):", "+ if count > 1:", "+ ans += count * (count - 1) // 2" ]
false
0.071674
0.066311
1.080876
[ "s796499286", "s768567163" ]
u514401521
p03325
python
s578087096
s907932291
125
113
4,148
4,148
Accepted
Accepted
9.6
n = int(eval(input())) a = list(map(int, input().split())) cnt = 0 for i in range(n): while a[i] % 2 == 0: cnt += 1 a[i] /= 2 print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(len(a)): tmp = a[i] while tmp % 2 == 0: ans += 1 tmp /= 2 print(ans)
10
9
161
176
n = int(eval(input())) a = list(map(int, input().split())) cnt = 0 for i in range(n): while a[i] % 2 == 0: cnt += 1 a[i] /= 2 print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(len(a)): tmp = a[i] while tmp % 2 == 0: ans += 1 tmp /= 2 print(ans)
false
10
[ "-cnt = 0", "-for i in range(n):", "- while a[i] % 2 == 0:", "- cnt += 1", "- a[i] /= 2", "-print(cnt)", "+ans = 0", "+for i in range(len(a)):", "+ tmp = a[i]", "+ while tmp % 2 == 0:", "+ ans += 1", "+ tmp /= 2", "+print(ans)" ]
false
0.095834
0.042423
2.259005
[ "s578087096", "s907932291" ]
u577170763
p03318
python
s814931448
s992926117
196
181
38,896
38,640
Accepted
Accepted
7.65
K = int(eval(input())) def ns(n): return sum([int(c) for c in str(n)]) ans, base = 0, 1 for _ in range(K): ans += base print(ans) if (ans + base) / ns(ans + base) > (ans + 10 * base) / ns(ans + 10 * base): base *= 10
K = int(eval(input())) def ns(n): ret, tmp = 0, n while tmp > 0: tmp, r = divmod(tmp, 10) ret += r return ret ans, base = 0, 1 for _ in range(K): ans += base print(ans) if (ans + base) / ns(ans + base) > (ans + 10 * base) / ns(ans + 10 * base): base *= 10
14
20
252
323
K = int(eval(input())) def ns(n): return sum([int(c) for c in str(n)]) ans, base = 0, 1 for _ in range(K): ans += base print(ans) if (ans + base) / ns(ans + base) > (ans + 10 * base) / ns(ans + 10 * base): base *= 10
K = int(eval(input())) def ns(n): ret, tmp = 0, n while tmp > 0: tmp, r = divmod(tmp, 10) ret += r return ret ans, base = 0, 1 for _ in range(K): ans += base print(ans) if (ans + base) / ns(ans + base) > (ans + 10 * base) / ns(ans + 10 * base): base *= 10
false
30
[ "- return sum([int(c) for c in str(n)])", "+ ret, tmp = 0, n", "+ while tmp > 0:", "+ tmp, r = divmod(tmp, 10)", "+ ret += r", "+ return ret" ]
false
0.041191
0.137145
0.300346
[ "s814931448", "s992926117" ]
u092301301
p02756
python
s161481738
s022938924
920
370
83,064
75,184
Accepted
Accepted
59.78
s=[i for i in eval(input())] x=0 ; st=[[],[]] for _ in range(int(eval(input()))): inp=list(map(str,input().split())) if len(inp)==1: x^=1 else: st[(int(inp[1])-1)^x].append(inp[2]) if x==0: st[0].reverse() ans=st[0]+s+st[1] elif x==1: st[1].reverse() s.reverse() ans=st[1]+s+st[0] print((''.join(ans)))
import sys input = lambda: sys.stdin.readline().rstrip() s=[i for i in eval(input())] x=0 ; st=[[],[]] for _ in range(int(eval(input()))): inp=list(map(str,input().split())) if len(inp)==1: x^=1 else: st[(int(inp[1])-1)^x].append(inp[2]) if x==0: st[0].reverse() ans=st[0]+s+st[1] elif x==1: st[1].reverse() s.reverse() ans=st[1]+s+st[0] print((''.join(ans)))
21
18
399
404
s = [i for i in eval(input())] x = 0 st = [[], []] for _ in range(int(eval(input()))): inp = list(map(str, input().split())) if len(inp) == 1: x ^= 1 else: st[(int(inp[1]) - 1) ^ x].append(inp[2]) if x == 0: st[0].reverse() ans = st[0] + s + st[1] elif x == 1: st[1].reverse() s.reverse() ans = st[1] + s + st[0] print(("".join(ans)))
import sys input = lambda: sys.stdin.readline().rstrip() s = [i for i in eval(input())] x = 0 st = [[], []] for _ in range(int(eval(input()))): inp = list(map(str, input().split())) if len(inp) == 1: x ^= 1 else: st[(int(inp[1]) - 1) ^ x].append(inp[2]) if x == 0: st[0].reverse() ans = st[0] + s + st[1] elif x == 1: st[1].reverse() s.reverse() ans = st[1] + s + st[0] print(("".join(ans)))
false
14.285714
[ "+import sys", "+", "+input = lambda: sys.stdin.readline().rstrip()" ]
false
0.044548
0.038571
1.154966
[ "s161481738", "s022938924" ]
u046187684
p02850
python
s153973328
s024494145
544
176
50,604
29,220
Accepted
Accepted
67.65
from collections import deque def solve(string): n, *ab = list(map(int, string.split())) next_ = [dict([]) for _ in range(n + 1)] queue = deque([1]) for a, b in zip(*[iter(ab)] * 2): next_[a][b] = 0 next_[b][a] = 0 while len(queue) > 0: c = queue.popleft() _next = next_[c] use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values()) for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use): queue.append(_n) next_[c][_n] = u next_[_n][c] = u return str("{}\n{}".format(max([len(list(x.keys())) for x in next_]), "\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2)))) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
from collections import deque def solve(string): n, *ab = list(map(int, string.split())) e = [[] for _ in range(n + 1)] q = deque([1]) c = [0] * (n + 1) for a, b in zip(*[iter(ab)] * 2): e[a].append(b) while q: s = q.popleft() d = 0 for t in e[s]: d += 1 + (d + 1 == c[s]) c[t] = d q.append(t) return str("{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2)))) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
25
23
835
586
from collections import deque def solve(string): n, *ab = list(map(int, string.split())) next_ = [dict([]) for _ in range(n + 1)] queue = deque([1]) for a, b in zip(*[iter(ab)] * 2): next_[a][b] = 0 next_[b][a] = 0 while len(queue) > 0: c = queue.popleft() _next = next_[c] use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values()) for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use): queue.append(_n) next_[c][_n] = u next_[_n][c] = u return str( "{}\n{}".format( max([len(list(x.keys())) for x in next_]), "\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2)), ) ) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
from collections import deque def solve(string): n, *ab = list(map(int, string.split())) e = [[] for _ in range(n + 1)] q = deque([1]) c = [0] * (n + 1) for a, b in zip(*[iter(ab)] * 2): e[a].append(b) while q: s = q.popleft() d = 0 for t in e[s]: d += 1 + (d + 1 == c[s]) c[t] = d q.append(t) return str( "{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2))) ) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
false
8
[ "- next_ = [dict([]) for _ in range(n + 1)]", "- queue = deque([1])", "+ e = [[] for _ in range(n + 1)]", "+ q = deque([1])", "+ c = [0] * (n + 1)", "- next_[a][b] = 0", "- next_[b][a] = 0", "- while len(queue) > 0:", "- c = queue.popleft()", "- _next = next_[c]", "- use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values())", "- for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use):", "- queue.append(_n)", "- next_[c][_n] = u", "- next_[_n][c] = u", "+ e[a].append(b)", "+ while q:", "+ s = q.popleft()", "+ d = 0", "+ for t in e[s]:", "+ d += 1 + (d + 1 == c[s])", "+ c[t] = d", "+ q.append(t)", "- \"{}\\n{}\".format(", "- max([len(list(x.keys())) for x in next_]),", "- \"\\n\".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2)),", "- )", "+ \"{}\\n{}\".format(max(c), \"\\n\".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2)))" ]
false
0.04762
0.007362
6.468221
[ "s153973328", "s024494145" ]
u285891772
p03607
python
s779989822
s498119243
167
146
18,352
18,344
Accepted
Accepted
12.57
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = [INT() for _ in range(N)] dic = defaultdict(int) for a in A: #print(dic[a]) dic[a] ^= 1 #print(dic) ans = 0 for x in dic: ans += dic[x] print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = [INT() for _ in range(N)] dic = dict() for a in A: if a in dic: dic[a] ^= 1 else: dic[a] = 1 #print(dic) ans = 0 for x in dic: ans += dic[x] print(ans)
35
37
1,037
1,048
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = [INT() for _ in range(N)] dic = defaultdict(int) for a in A: # print(dic[a]) dic[a] ^= 1 # print(dic) ans = 0 for x in dic: ans += dic[x] print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = [INT() for _ in range(N)] dic = dict() for a in A: if a in dic: dic[a] ^= 1 else: dic[a] = 1 # print(dic) ans = 0 for x in dic: ans += dic[x] print(ans)
false
5.405405
[ "-dic = defaultdict(int)", "+dic = dict()", "- # print(dic[a])", "- dic[a] ^= 1", "+ if a in dic:", "+ dic[a] ^= 1", "+ else:", "+ dic[a] = 1" ]
false
0.046285
0.060456
0.765592
[ "s779989822", "s498119243" ]
u210827208
p02954
python
s492851103
s925888592
155
143
6,400
6,376
Accepted
Accepted
7.74
s=eval(input()) n=len(s) C=[0]*n cnt_r=0 cnt_l=0 def calc(tmp_r,tmp_l): n=cnt_r+cnt_l if n%2==0: C[tmp_r]=n//2 C[tmp_l]=n//2 else: if cnt_r>cnt_l: if cnt_r%2==0: C[tmp_r]=n//2 C[tmp_l]=n//2+1 else: C[tmp_r]=n//2+1 C[tmp_l]=n//2 else: if cnt_l%2==0: C[tmp_r]=n//2+1 C[tmp_l]=n//2 else: C[tmp_r]=n//2 C[tmp_l]=n//2+1 for i in range(n-1): if s[i]=='R' and s[i+1]=='R': cnt_r+=1 if s[i]=='R' and s[i+1]=='L': cnt_r+=1 tmp_r=i tmp_l=i+1 if s[i]=='L' and s[i+1]=='R': cnt_l+=1 if i==n-2: cnt_l+=1 calc(tmp_r,tmp_l) cnt_r=0 cnt_l=0 if s[i]=='L' and s[i+1]=='L': cnt_l+=1 if i==n-2: cnt_l+=1 calc(tmp_r,tmp_l) print((*C))
s=eval(input())+'R' n=len(s) C=[0]*n cnt_r=0 cnt_l=0 def calc(tmp_r,tmp_l,cnt_r,cnt_l): C[tmp_r]=(cnt_r-1)//2+cnt_l//2+1 C[tmp_l]=cnt_r//2+(cnt_l-1)//2+1 for i in range(n-1): if s[i]=='R' and s[i+1]=='R': cnt_r+=1 if s[i]=='R' and s[i+1]=='L': cnt_r+=1 tmp_r=i tmp_l=i+1 if s[i]=='L' and s[i+1]=='R': cnt_l+=1 calc(tmp_r,tmp_l,cnt_r,cnt_l) cnt_r=0 cnt_l=0 if s[i]=='L' and s[i+1]=='L': cnt_l+=1 print((*C[:-1]))
59
37
1,077
601
s = eval(input()) n = len(s) C = [0] * n cnt_r = 0 cnt_l = 0 def calc(tmp_r, tmp_l): n = cnt_r + cnt_l if n % 2 == 0: C[tmp_r] = n // 2 C[tmp_l] = n // 2 else: if cnt_r > cnt_l: if cnt_r % 2 == 0: C[tmp_r] = n // 2 C[tmp_l] = n // 2 + 1 else: C[tmp_r] = n // 2 + 1 C[tmp_l] = n // 2 else: if cnt_l % 2 == 0: C[tmp_r] = n // 2 + 1 C[tmp_l] = n // 2 else: C[tmp_r] = n // 2 C[tmp_l] = n // 2 + 1 for i in range(n - 1): if s[i] == "R" and s[i + 1] == "R": cnt_r += 1 if s[i] == "R" and s[i + 1] == "L": cnt_r += 1 tmp_r = i tmp_l = i + 1 if s[i] == "L" and s[i + 1] == "R": cnt_l += 1 if i == n - 2: cnt_l += 1 calc(tmp_r, tmp_l) cnt_r = 0 cnt_l = 0 if s[i] == "L" and s[i + 1] == "L": cnt_l += 1 if i == n - 2: cnt_l += 1 calc(tmp_r, tmp_l) print((*C))
s = eval(input()) + "R" n = len(s) C = [0] * n cnt_r = 0 cnt_l = 0 def calc(tmp_r, tmp_l, cnt_r, cnt_l): C[tmp_r] = (cnt_r - 1) // 2 + cnt_l // 2 + 1 C[tmp_l] = cnt_r // 2 + (cnt_l - 1) // 2 + 1 for i in range(n - 1): if s[i] == "R" and s[i + 1] == "R": cnt_r += 1 if s[i] == "R" and s[i + 1] == "L": cnt_r += 1 tmp_r = i tmp_l = i + 1 if s[i] == "L" and s[i + 1] == "R": cnt_l += 1 calc(tmp_r, tmp_l, cnt_r, cnt_l) cnt_r = 0 cnt_l = 0 if s[i] == "L" and s[i + 1] == "L": cnt_l += 1 print((*C[:-1]))
false
37.288136
[ "-s = eval(input())", "+s = eval(input()) + \"R\"", "-def calc(tmp_r, tmp_l):", "- n = cnt_r + cnt_l", "- if n % 2 == 0:", "- C[tmp_r] = n // 2", "- C[tmp_l] = n // 2", "- else:", "- if cnt_r > cnt_l:", "- if cnt_r % 2 == 0:", "- C[tmp_r] = n // 2", "- C[tmp_l] = n // 2 + 1", "- else:", "- C[tmp_r] = n // 2 + 1", "- C[tmp_l] = n // 2", "- else:", "- if cnt_l % 2 == 0:", "- C[tmp_r] = n // 2 + 1", "- C[tmp_l] = n // 2", "- else:", "- C[tmp_r] = n // 2", "- C[tmp_l] = n // 2 + 1", "+def calc(tmp_r, tmp_l, cnt_r, cnt_l):", "+ C[tmp_r] = (cnt_r - 1) // 2 + cnt_l // 2 + 1", "+ C[tmp_l] = cnt_r // 2 + (cnt_l - 1) // 2 + 1", "- if i == n - 2:", "- cnt_l += 1", "- calc(tmp_r, tmp_l)", "+ calc(tmp_r, tmp_l, cnt_r, cnt_l)", "- if i == n - 2:", "- cnt_l += 1", "- calc(tmp_r, tmp_l)", "-print((*C))", "+print((*C[:-1]))" ]
false
0.05821
0.042223
1.378636
[ "s492851103", "s925888592" ]
u721407235
p02714
python
s551274864
s290749754
1,975
1,552
9,152
9,184
Accepted
Accepted
21.42
N=int(eval(input())) S=eval(input()) ans=S.count("R")*S.count("G")*S.count("B") #j-i= k-j k=2*j-i for i in range(N): for j in range(i+1,N): if 2*j-i<N: if S[i]!=S[j] and S[i]!=S[2*j-i] and S[j]!=S[2*j-i]: ans -=1 print(ans)
N=int(eval(input())) S=eval(input()) ans=S.count("R")*S.count("G")*S.count("B") #j-i= k-j k=2*j-i for i in range(N): for j in range(i+1,N): if 2*j-i>=N: break if S[i]!=S[j] and S[i]!=S[2*j-i] and S[j]!=S[2*j-i]: ans -=1 print(ans)
17
19
276
294
N = int(eval(input())) S = eval(input()) ans = S.count("R") * S.count("G") * S.count("B") # j-i= k-j k=2*j-i for i in range(N): for j in range(i + 1, N): if 2 * j - i < N: if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]: ans -= 1 print(ans)
N = int(eval(input())) S = eval(input()) ans = S.count("R") * S.count("G") * S.count("B") # j-i= k-j k=2*j-i for i in range(N): for j in range(i + 1, N): if 2 * j - i >= N: break if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]: ans -= 1 print(ans)
false
10.526316
[ "- if 2 * j - i < N:", "- if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:", "- ans -= 1", "+ if 2 * j - i >= N:", "+ break", "+ if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:", "+ ans -= 1" ]
false
0.045236
0.065696
0.688557
[ "s551274864", "s290749754" ]
u063052907
p03503
python
s592950440
s195707478
224
177
42,220
3,064
Accepted
Accepted
20.98
# 写経 n = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(n)] lst_P = [list(map(int, input().split())) for _ in range(n)] ans = -float("INF") for b in range(1, 2**10): tmp = 0 for i in range(n): c = 0 for k in range(10): if b&(1<<k) and lst_F[i][k]: c += 1 tmp += lst_P[i][c] ans = max(tmp, ans) print(ans)
N = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(N)] lst_P = [list(map(int, input().split())) for _ in range(N)] n_timetable = 10 lst_joisino = [None] * n_timetable def score(src, F, P): cnt = 0 for i, j in zip(src, F): if i == j == 1: cnt += 1 return P[cnt] def dfs(pos): if pos == n_timetable: ret = 0 for i in range(N): if lst_joisino == [0] * n_timetable: return -float("INF") p = score(lst_joisino, lst_F[i], lst_P[i]) ret += p return ret lst_joisino[pos] = 0 ret0 = dfs(pos + 1) lst_joisino[pos] = 1 ret1 = dfs(pos + 1) return max(ret0, ret1) print((dfs(0)))
20
32
414
755
# 写経 n = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(n)] lst_P = [list(map(int, input().split())) for _ in range(n)] ans = -float("INF") for b in range(1, 2**10): tmp = 0 for i in range(n): c = 0 for k in range(10): if b & (1 << k) and lst_F[i][k]: c += 1 tmp += lst_P[i][c] ans = max(tmp, ans) print(ans)
N = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(N)] lst_P = [list(map(int, input().split())) for _ in range(N)] n_timetable = 10 lst_joisino = [None] * n_timetable def score(src, F, P): cnt = 0 for i, j in zip(src, F): if i == j == 1: cnt += 1 return P[cnt] def dfs(pos): if pos == n_timetable: ret = 0 for i in range(N): if lst_joisino == [0] * n_timetable: return -float("INF") p = score(lst_joisino, lst_F[i], lst_P[i]) ret += p return ret lst_joisino[pos] = 0 ret0 = dfs(pos + 1) lst_joisino[pos] = 1 ret1 = dfs(pos + 1) return max(ret0, ret1) print((dfs(0)))
false
37.5
[ "-# 写経", "-n = int(eval(input()))", "-lst_F = [list(map(int, input().split())) for _ in range(n)]", "-lst_P = [list(map(int, input().split())) for _ in range(n)]", "-ans = -float(\"INF\")", "-for b in range(1, 2**10):", "- tmp = 0", "- for i in range(n):", "- c = 0", "- for k in range(10):", "- if b & (1 << k) and lst_F[i][k]:", "- c += 1", "- tmp += lst_P[i][c]", "- ans = max(tmp, ans)", "-print(ans)", "+N = int(eval(input()))", "+lst_F = [list(map(int, input().split())) for _ in range(N)]", "+lst_P = [list(map(int, input().split())) for _ in range(N)]", "+n_timetable = 10", "+lst_joisino = [None] * n_timetable", "+", "+", "+def score(src, F, P):", "+ cnt = 0", "+ for i, j in zip(src, F):", "+ if i == j == 1:", "+ cnt += 1", "+ return P[cnt]", "+", "+", "+def dfs(pos):", "+ if pos == n_timetable:", "+ ret = 0", "+ for i in range(N):", "+ if lst_joisino == [0] * n_timetable:", "+ return -float(\"INF\")", "+ p = score(lst_joisino, lst_F[i], lst_P[i])", "+ ret += p", "+ return ret", "+ lst_joisino[pos] = 0", "+ ret0 = dfs(pos + 1)", "+ lst_joisino[pos] = 1", "+ ret1 = dfs(pos + 1)", "+ return max(ret0, ret1)", "+", "+", "+print((dfs(0)))" ]
false
0.099066
0.153717
0.644469
[ "s592950440", "s195707478" ]
u379716238
p03493
python
s625525153
s493106722
150
17
14,476
2,940
Accepted
Accepted
88.67
import numpy as np s = eval(input()) ss = [int(i) for i in s] print((np.sum(ss)))
s = eval(input()) print((s.count('1')))
5
2
78
32
import numpy as np s = eval(input()) ss = [int(i) for i in s] print((np.sum(ss)))
s = eval(input()) print((s.count("1")))
false
60
[ "-import numpy as np", "-", "-ss = [int(i) for i in s]", "-print((np.sum(ss)))", "+print((s.count(\"1\")))" ]
false
0.183915
0.161928
1.135783
[ "s625525153", "s493106722" ]
u221345507
p03262
python
s838938433
s434853314
339
296
24,992
22,156
Accepted
Accepted
12.68
import numpy as np import fractions N, X =list(map(int,input().split())) x = list(map(int,input().split())) result = abs(abs(np.array(x))-X) D= result[0] for i in range (1,len(result)): D=fractions.gcd(D,result[i]) print(D)
N, X = list(map(int,input().split())) x = list(map(int,input().split())) import numpy as np X_abs = abs(np.array(x)-X) #最大公約数、最小公倍数 import fractions gcd = X_abs[0] for i in range (1,N): gcd = fractions.gcd(gcd,X_abs[i]) print(gcd)
11
13
234
248
import numpy as np import fractions N, X = list(map(int, input().split())) x = list(map(int, input().split())) result = abs(abs(np.array(x)) - X) D = result[0] for i in range(1, len(result)): D = fractions.gcd(D, result[i]) print(D)
N, X = list(map(int, input().split())) x = list(map(int, input().split())) import numpy as np X_abs = abs(np.array(x) - X) # 最大公約数、最小公倍数 import fractions gcd = X_abs[0] for i in range(1, N): gcd = fractions.gcd(gcd, X_abs[i]) print(gcd)
false
15.384615
[ "+N, X = list(map(int, input().split()))", "+x = list(map(int, input().split()))", "+", "+X_abs = abs(np.array(x) - X)", "+# 最大公約数、最小公倍数", "-N, X = list(map(int, input().split()))", "-x = list(map(int, input().split()))", "-result = abs(abs(np.array(x)) - X)", "-D = result[0]", "-for i in range(1, len(result)):", "- D = fractions.gcd(D, result[i])", "-print(D)", "+gcd = X_abs[0]", "+for i in range(1, N):", "+ gcd = fractions.gcd(gcd, X_abs[i])", "+print(gcd)" ]
false
0.223905
0.313819
0.713484
[ "s838938433", "s434853314" ]
u665078057
p03160
python
s600224380
s444763781
156
142
13,980
13,900
Accepted
Accepted
8.97
N = int(eval(input())) [*h] = list(map(int, input().split())) dp = [float('inf') for _ in range(N)] dp[0] = 0 dp[1] = abs(h[0]-h[1]) for i in range(2, N): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print((dp[N-1]))
N = int(eval(input())) [*h] = list(map(int, input().split())) dp = [0 for _ in range(N)] dp[1] = abs(h[0]-h[1]) for i in range(2, N): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print((dp[N-1]))
9
8
234
213
N = int(eval(input())) [*h] = list(map(int, input().split())) dp = [float("inf") for _ in range(N)] dp[0] = 0 dp[1] = abs(h[0] - h[1]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
N = int(eval(input())) [*h] = list(map(int, input().split())) dp = [0 for _ in range(N)] dp[1] = abs(h[0] - h[1]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
false
11.111111
[ "-dp = [float(\"inf\") for _ in range(N)]", "-dp[0] = 0", "+dp = [0 for _ in range(N)]" ]
false
0.069741
0.096731
0.720979
[ "s600224380", "s444763781" ]
u367130284
p03732
python
s323422483
s335641173
86
70
4,016
4,116
Accepted
Accepted
18.6
N,W=list(map(int,input().split())) from collections import* d=defaultdict(int) d[0]=0 for i in range(N): w,v=list(map(int,input().split())) for k,b in list(d.copy().items()): if k+w<=W: d[k+w]=max(d[k+w],b+v) print((max(d.values())))
import functools from collections import* @functools.lru_cache(maxsize=None) def Knapsack(N,W): for i in range(N): w,v=list(map(int,input().split())) for k,b in list(d.copy().items()): if k+w<=W: d[k+w]=max(d[k+w],b+v) return max(d.values()) N,W=list(map(int,input().split())) #pypyで実行! d=defaultdict(int) d[0]=0 print((Knapsack(N,W)))
10
14
250
382
N, W = list(map(int, input().split())) from collections import * d = defaultdict(int) d[0] = 0 for i in range(N): w, v = list(map(int, input().split())) for k, b in list(d.copy().items()): if k + w <= W: d[k + w] = max(d[k + w], b + v) print((max(d.values())))
import functools from collections import * @functools.lru_cache(maxsize=None) def Knapsack(N, W): for i in range(N): w, v = list(map(int, input().split())) for k, b in list(d.copy().items()): if k + w <= W: d[k + w] = max(d[k + w], b + v) return max(d.values()) N, W = list(map(int, input().split())) # pypyで実行! d = defaultdict(int) d[0] = 0 print((Knapsack(N, W)))
false
28.571429
[ "-N, W = list(map(int, input().split()))", "+import functools", "+", "[email protected]_cache(maxsize=None)", "+def Knapsack(N, W):", "+ for i in range(N):", "+ w, v = list(map(int, input().split()))", "+ for k, b in list(d.copy().items()):", "+ if k + w <= W:", "+ d[k + w] = max(d[k + w], b + v)", "+ return max(d.values())", "+", "+", "+N, W = list(map(int, input().split())) # pypyで実行!", "-for i in range(N):", "- w, v = list(map(int, input().split()))", "- for k, b in list(d.copy().items()):", "- if k + w <= W:", "- d[k + w] = max(d[k + w], b + v)", "-print((max(d.values())))", "+print((Knapsack(N, W)))" ]
false
0.07756
0.077234
1.004221
[ "s323422483", "s335641173" ]
u309141201
p03547
python
s516760449
s419062713
171
32
38,256
8,904
Accepted
Accepted
81.29
X, Y = list(map(str, input().split())) if X == 'A': x = 10 elif X == 'B': x = 11 elif X == 'C': x = 12 elif X == 'D': x = 13 elif X == 'E': x = 14 elif X == 'F': x = 15 if Y == 'A': y = 10 elif Y == 'B': y = 11 elif Y == 'C': y = 12 elif Y == 'D': y = 13 elif Y == 'E': y = 14 elif Y == 'F': y = 15 if x < y: print('<') elif x == y: print('=') else: print('>')
A, B = input().split() if A > B: print('>') elif A == B: print('=') else: print('<')
33
7
449
104
X, Y = list(map(str, input().split())) if X == "A": x = 10 elif X == "B": x = 11 elif X == "C": x = 12 elif X == "D": x = 13 elif X == "E": x = 14 elif X == "F": x = 15 if Y == "A": y = 10 elif Y == "B": y = 11 elif Y == "C": y = 12 elif Y == "D": y = 13 elif Y == "E": y = 14 elif Y == "F": y = 15 if x < y: print("<") elif x == y: print("=") else: print(">")
A, B = input().split() if A > B: print(">") elif A == B: print("=") else: print("<")
false
78.787879
[ "-X, Y = list(map(str, input().split()))", "-if X == \"A\":", "- x = 10", "-elif X == \"B\":", "- x = 11", "-elif X == \"C\":", "- x = 12", "-elif X == \"D\":", "- x = 13", "-elif X == \"E\":", "- x = 14", "-elif X == \"F\":", "- x = 15", "-if Y == \"A\":", "- y = 10", "-elif Y == \"B\":", "- y = 11", "-elif Y == \"C\":", "- y = 12", "-elif Y == \"D\":", "- y = 13", "-elif Y == \"E\":", "- y = 14", "-elif Y == \"F\":", "- y = 15", "-if x < y:", "- print(\"<\")", "-elif x == y:", "+A, B = input().split()", "+if A > B:", "+ print(\">\")", "+elif A == B:", "- print(\">\")", "+ print(\"<\")" ]
false
0.035269
0.070178
0.502566
[ "s516760449", "s419062713" ]
u918845030
p03061
python
s044317023
s335081101
234
200
14,488
14,384
Accepted
Accepted
14.53
def gcd(a, b): if b == 0: return a elif a == 0: return b else: return gcd(b, a % b) def solve(n, a): l, r = [], [] l = [0 for i in range(n + 1)] r = [0 for i in range(n + 1)] r[n] = 0 for i in range(0, n): if i == 0: l[0] = 0 else: l[i] = gcd(l[i - 1], a[i - 1]) for i in range(n, 0, -1): if i == n: r[i] = 0 else: r[i] = gcd(r[i+1], a[i]) m = 0 for i in range(n): # print('m', m) m = max(m, gcd(l[i], r[i + 1])) return m def input_from_console(): n = int(eval(input())) a = list(map(int, input().split())) return n, a def main(): n, a_list = input_from_console() print((solve(n, a_list))) if __name__ == "__main__": main()
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def solve(n, a): l = [0] * n r = [0] * (n + 1) for i in range(1, n): l[i] = gcd(l[i - 1], a[i - 1]) for i in range(n - 1, 0, -1): r[i] = gcd(r[i + 1], a[i]) m = 0 for i in range(n): m = max(m, gcd(l[i], r[i + 1])) return m def input_from_console(): n = int(eval(input())) a = list(map(int, input().split())) return n, a def main(): n, a_list = input_from_console() print((solve(n, a_list))) if __name__ == "__main__": main()
48
34
867
608
def gcd(a, b): if b == 0: return a elif a == 0: return b else: return gcd(b, a % b) def solve(n, a): l, r = [], [] l = [0 for i in range(n + 1)] r = [0 for i in range(n + 1)] r[n] = 0 for i in range(0, n): if i == 0: l[0] = 0 else: l[i] = gcd(l[i - 1], a[i - 1]) for i in range(n, 0, -1): if i == n: r[i] = 0 else: r[i] = gcd(r[i + 1], a[i]) m = 0 for i in range(n): # print('m', m) m = max(m, gcd(l[i], r[i + 1])) return m def input_from_console(): n = int(eval(input())) a = list(map(int, input().split())) return n, a def main(): n, a_list = input_from_console() print((solve(n, a_list))) if __name__ == "__main__": main()
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def solve(n, a): l = [0] * n r = [0] * (n + 1) for i in range(1, n): l[i] = gcd(l[i - 1], a[i - 1]) for i in range(n - 1, 0, -1): r[i] = gcd(r[i + 1], a[i]) m = 0 for i in range(n): m = max(m, gcd(l[i], r[i + 1])) return m def input_from_console(): n = int(eval(input())) a = list(map(int, input().split())) return n, a def main(): n, a_list = input_from_console() print((solve(n, a_list))) if __name__ == "__main__": main()
false
29.166667
[ "- elif a == 0:", "- return b", "- else:", "- return gcd(b, a % b)", "+ return gcd(b, a % b)", "- l, r = [], []", "- l = [0 for i in range(n + 1)]", "- r = [0 for i in range(n + 1)]", "- r[n] = 0", "- for i in range(0, n):", "- if i == 0:", "- l[0] = 0", "- else:", "- l[i] = gcd(l[i - 1], a[i - 1])", "- for i in range(n, 0, -1):", "- if i == n:", "- r[i] = 0", "- else:", "- r[i] = gcd(r[i + 1], a[i])", "+ l = [0] * n", "+ r = [0] * (n + 1)", "+ for i in range(1, n):", "+ l[i] = gcd(l[i - 1], a[i - 1])", "+ for i in range(n - 1, 0, -1):", "+ r[i] = gcd(r[i + 1], a[i])", "- # print('m', m)" ]
false
0.033318
0.03664
0.90935
[ "s044317023", "s335081101" ]
u762420987
p02984
python
s466265805
s884490711
319
131
64,484
14,092
Accepted
Accepted
58.93
N = int(input()) Alist = list(map(int, input().split())) S = sum(Alist) Xlist = [0] * N Xlist[0] = S - 2 * sum([Alist[_] for _ in range(1, N, 2)]) print(Xlist[0], end=" ") for i in range(1, N): Xlist[i] = 2*Alist[i-1] - Xlist[i-1] print(Xlist[i], end=" ") print()
N = int(eval(input())) Alist = list(map(int, input().split())) S = sum(Alist) ans = [S - sum([2 * Alist[i] for i in range(1, N - 1, 2)])] for i in range(1, N): ans.append(-ans[i - 1] + 2 * Alist[i - 1]) print((*ans))
10
10
280
224
N = int(input()) Alist = list(map(int, input().split())) S = sum(Alist) Xlist = [0] * N Xlist[0] = S - 2 * sum([Alist[_] for _ in range(1, N, 2)]) print(Xlist[0], end=" ") for i in range(1, N): Xlist[i] = 2 * Alist[i - 1] - Xlist[i - 1] print(Xlist[i], end=" ") print()
N = int(eval(input())) Alist = list(map(int, input().split())) S = sum(Alist) ans = [S - sum([2 * Alist[i] for i in range(1, N - 1, 2)])] for i in range(1, N): ans.append(-ans[i - 1] + 2 * Alist[i - 1]) print((*ans))
false
0
[ "-N = int(input())", "+N = int(eval(input()))", "-Xlist = [0] * N", "-Xlist[0] = S - 2 * sum([Alist[_] for _ in range(1, N, 2)])", "-print(Xlist[0], end=\" \")", "+ans = [S - sum([2 * Alist[i] for i in range(1, N - 1, 2)])]", "- Xlist[i] = 2 * Alist[i - 1] - Xlist[i - 1]", "- print(Xlist[i], end=\" \")", "-print()", "+ ans.append(-ans[i - 1] + 2 * Alist[i - 1])", "+print((*ans))" ]
false
0.162603
0.163405
0.99509
[ "s466265805", "s884490711" ]
u873482706
p00067
python
s402731869
s147898781
50
30
7,476
7,624
Accepted
Accepted
40
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' for i in range(4): if i == 0: # U f2(x, y-1) elif i == 1: # D f2(x, y+1) elif i == 2: # R f2(x+1, y) elif i == 3: # L f2(x-1, y) def get_input(): while True: try: yield eval(input()) except EOFError: break M = [] for line in list(get_input()): if line == '': print((f1())) M = [] else: M.append(list(line)) print((f1()))
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) def get_input(): while True: try: yield eval(input()) except EOFError: break M = [] for line in list(get_input()): if line == '': print((f1())) M = [] else: M.append(list(line)) print((f1()))
42
37
884
690
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == "1": f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == "1": M[y][x] = "0" for i in range(4): if i == 0: # U f2(x, y - 1) elif i == 1: # D f2(x, y + 1) elif i == 2: # R f2(x + 1, y) elif i == 3: # L f2(x - 1, y) def get_input(): while True: try: yield eval(input()) except EOFError: break M = [] for line in list(get_input()): if line == "": print((f1())) M = [] else: M.append(list(line)) print((f1()))
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == "1": f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == "1": M[y][x] = "0" f2(x, y - 1) f2(x, y + 1) f2(x + 1, y) f2(x - 1, y) def get_input(): while True: try: yield eval(input()) except EOFError: break M = [] for line in list(get_input()): if line == "": print((f1())) M = [] else: M.append(list(line)) print((f1()))
false
11.904762
[ "- for i in range(4):", "- if i == 0: # U", "- f2(x, y - 1)", "- elif i == 1: # D", "- f2(x, y + 1)", "- elif i == 2: # R", "- f2(x + 1, y)", "- elif i == 3: # L", "- f2(x - 1, y)", "+ f2(x, y - 1)", "+ f2(x, y + 1)", "+ f2(x + 1, y)", "+ f2(x - 1, y)" ]
false
0.043288
0.048312
0.896008
[ "s402731869", "s147898781" ]
u532966492
p03253
python
s031963538
s517405677
785
230
3,444
3,424
Accepted
Accepted
70.7
N,M=list(map(int,input().split())) mod=10**9+7 from math import factorial from collections import Counter def soinsuu(n): list_=[] while(n!=1): for i in range(2,int(n**0.5)+1): if n%i==0: list_.append(i) n=n//i break else: list_.append(n) n=1 return sorted(list_) def product(a): pro=1 for b in a: pro=pro*b%mod return pro #n!,nPr,nCrの高速計算 def n_func(n,mod=10**9+7): ans=1 for i in range(1,n+1): ans=(ans*i)%mod return ans def inv_n(n,mod=10**9+7): return pow(n,mod-2,mod) def nPr(n,r,mod=10**9+7): ans=n_func(n-r,mod) ans=inv_n(ans,mod) return ans*n_func(n,mod)%mod nPr_list=[nPr(N,i) for i in range(30)] bunbo_list=dict() def dp(cur,init,seq,lest,num): #print(cur,init,seq,lest,num) if cur==N: if lest==0: cnt=sorted(list(Counter(seq).values())+[N-len(seq)],reverse=True) bunbo=product(list(map(factorial,cnt[1:]))) if bunbo not in list(bunbo_list.keys()): bunbo_list[bunbo]=inv_n(bunbo) memo[num]=(memo[num]+nPr_list[N-cnt[0]]*bunbo_list[bunbo])%mod elif lest==0: dp(N,init,seq,0,num) else: if cur==0: for i in range(1,lest+1): dp(cur+1,init,seq+[i],lest-i,num) else: for i in range(1,min(lest,seq[-1])+1): dp(cur+1,init,seq+[i],lest-i,num) p=list(Counter(soinsuu(M)).values()) memo=[0]*len(p) for i in range(len(p)): dp(0,p[i],[],p[i],i) print((product(memo)))
N,M=list(map(int,input().split())) from collections import Counter def soinsuu(n): list_=[] while(n!=1): for i in range(2,int(n**0.5)+1): if n%i==0: list_.append(i) n=n//i break else: list_.append(n) n=1 return sorted(list_) def product(a): pro=1 for b in a: pro=pro*b%(10**9+7) return pro #n!,nPr,nCrの高速計算 def n_func(n,mod=10**9+7): ans=1 for i in range(1,n+1): ans=(ans*i)%mod return ans def inv_n(n,mod=10**9+7): return pow(n,mod-2,mod) def nPr(n,r,mod=10**9+7): ans=n_func(n-r,mod) ans=inv_n(ans,mod) return ans*n_func(n,mod)%mod def nCr(n,r,mod=10**9+7): ans=n_func(n-r,mod)*n_func(r,mod)%mod ans=inv_n(ans,mod) return ans*n_func(n,mod)%mod p=list(Counter(soinsuu(M)).values()) print((product([nCr(N+p[i]-1,p[i]) for i in range(len(p))])))
67
42
1,668
969
N, M = list(map(int, input().split())) mod = 10**9 + 7 from math import factorial from collections import Counter def soinsuu(n): list_ = [] while n != 1: for i in range(2, int(n**0.5) + 1): if n % i == 0: list_.append(i) n = n // i break else: list_.append(n) n = 1 return sorted(list_) def product(a): pro = 1 for b in a: pro = pro * b % mod return pro # n!,nPr,nCrの高速計算 def n_func(n, mod=10**9 + 7): ans = 1 for i in range(1, n + 1): ans = (ans * i) % mod return ans def inv_n(n, mod=10**9 + 7): return pow(n, mod - 2, mod) def nPr(n, r, mod=10**9 + 7): ans = n_func(n - r, mod) ans = inv_n(ans, mod) return ans * n_func(n, mod) % mod nPr_list = [nPr(N, i) for i in range(30)] bunbo_list = dict() def dp(cur, init, seq, lest, num): # print(cur,init,seq,lest,num) if cur == N: if lest == 0: cnt = sorted(list(Counter(seq).values()) + [N - len(seq)], reverse=True) bunbo = product(list(map(factorial, cnt[1:]))) if bunbo not in list(bunbo_list.keys()): bunbo_list[bunbo] = inv_n(bunbo) memo[num] = (memo[num] + nPr_list[N - cnt[0]] * bunbo_list[bunbo]) % mod elif lest == 0: dp(N, init, seq, 0, num) else: if cur == 0: for i in range(1, lest + 1): dp(cur + 1, init, seq + [i], lest - i, num) else: for i in range(1, min(lest, seq[-1]) + 1): dp(cur + 1, init, seq + [i], lest - i, num) p = list(Counter(soinsuu(M)).values()) memo = [0] * len(p) for i in range(len(p)): dp(0, p[i], [], p[i], i) print((product(memo)))
N, M = list(map(int, input().split())) from collections import Counter def soinsuu(n): list_ = [] while n != 1: for i in range(2, int(n**0.5) + 1): if n % i == 0: list_.append(i) n = n // i break else: list_.append(n) n = 1 return sorted(list_) def product(a): pro = 1 for b in a: pro = pro * b % (10**9 + 7) return pro # n!,nPr,nCrの高速計算 def n_func(n, mod=10**9 + 7): ans = 1 for i in range(1, n + 1): ans = (ans * i) % mod return ans def inv_n(n, mod=10**9 + 7): return pow(n, mod - 2, mod) def nPr(n, r, mod=10**9 + 7): ans = n_func(n - r, mod) ans = inv_n(ans, mod) return ans * n_func(n, mod) % mod def nCr(n, r, mod=10**9 + 7): ans = n_func(n - r, mod) * n_func(r, mod) % mod ans = inv_n(ans, mod) return ans * n_func(n, mod) % mod p = list(Counter(soinsuu(M)).values()) print((product([nCr(N + p[i] - 1, p[i]) for i in range(len(p))])))
false
37.313433
[ "-mod = 10**9 + 7", "-from math import factorial", "- pro = pro * b % mod", "+ pro = pro * b % (10**9 + 7)", "-nPr_list = [nPr(N, i) for i in range(30)]", "-bunbo_list = dict()", "-", "-", "-def dp(cur, init, seq, lest, num):", "- # print(cur,init,seq,lest,num)", "- if cur == N:", "- if lest == 0:", "- cnt = sorted(list(Counter(seq).values()) + [N - len(seq)], reverse=True)", "- bunbo = product(list(map(factorial, cnt[1:])))", "- if bunbo not in list(bunbo_list.keys()):", "- bunbo_list[bunbo] = inv_n(bunbo)", "- memo[num] = (memo[num] + nPr_list[N - cnt[0]] * bunbo_list[bunbo]) % mod", "- elif lest == 0:", "- dp(N, init, seq, 0, num)", "- else:", "- if cur == 0:", "- for i in range(1, lest + 1):", "- dp(cur + 1, init, seq + [i], lest - i, num)", "- else:", "- for i in range(1, min(lest, seq[-1]) + 1):", "- dp(cur + 1, init, seq + [i], lest - i, num)", "+def nCr(n, r, mod=10**9 + 7):", "+ ans = n_func(n - r, mod) * n_func(r, mod) % mod", "+ ans = inv_n(ans, mod)", "+ return ans * n_func(n, mod) % mod", "-memo = [0] * len(p)", "-for i in range(len(p)):", "- dp(0, p[i], [], p[i], i)", "-print((product(memo)))", "+print((product([nCr(N + p[i] - 1, p[i]) for i in range(len(p))])))" ]
false
0.495866
0.072326
6.855959
[ "s031963538", "s517405677" ]
u962045495
p03096
python
s355500510
s599689801
116
103
71,536
45,212
Accepted
Accepted
11.21
#!/usr/bin/env python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <[email protected]> """ import itertools import os import sys from atexit import register from io import StringIO from collections import Counter range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = StringIO(os.read(0, os.fstat(0).st_size)).readline MOD = 10**9 + 7 MODF = float(MOD) MAGIC = 6755399441055744.0 SHRT = 65536.0 MODF_INV = 1.0 / MODF SHRT_INV = 1.0 / SHRT fround = lambda x: (x + MAGIC) - MAGIC fmod = lambda a: a - MODF * fround(MODF_INV * a) fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c) def main(): n = int(eval(input())) c = [int(eval(input())) for _ in range(n)] _c, prev = [], 0 for i in range(n): if c[i] != prev: _c.append(c[i]) prev = c[i] c = _c n = len(c) prev_occur = [0] * (2 * 10**5 + 1) res, counts = [1.0] * (n + 1), Counter() for i in range(n): ind = prev_occur[c[i]] if ind != 0: res[i + 1] = fmod(res[i] + res[ind]) else: res[i + 1] = res[i] counts[c[i]] += 1 prev_occur[c[i]] = i + 1 print(int(res[-1]) % MOD) if __name__ == '__main__': main()
#!/usr/bin/env python2 import itertools import os import sys from atexit import register from io import StringIO range = xrange sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = StringIO(os.read(0, os.fstat(0).st_size)).readline MOD = 10**9 + 7 MODF = float(MOD) MAGIC = 6755399441055744.0 SHRT = 65536.0 MODF_INV = 1.0 / MODF SHRT_INV = 1.0 / SHRT fround = lambda x: (x + MAGIC) - MAGIC fmod = lambda a: a - MODF * fround(MODF_INV * a) def main(): n = int(eval(input())) c = [int(eval(input())) for _ in range(n)] c = [x[0] for x in itertools.groupby(c)] n = len(c) res, prev = [1.0] * (n + 1), [0] * (2 * 10**5 + 1) for i in range(n): res[i + 1] = res[i] if prev[c[i]] == 0 else fmod(res[i] + res[prev[c[i]]]) prev[c[i]] = i + 1 print(int(res[-1]) % MOD) if __name__ == '__main__': main()
68
45
1,549
975
#!/usr/bin/env python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <[email protected]> """ import itertools import os import sys from atexit import register from io import StringIO from collections import Counter range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = StringIO(os.read(0, os.fstat(0).st_size)).readline MOD = 10**9 + 7 MODF = float(MOD) MAGIC = 6755399441055744.0 SHRT = 65536.0 MODF_INV = 1.0 / MODF SHRT_INV = 1.0 / SHRT fround = lambda x: (x + MAGIC) - MAGIC fmod = lambda a: a - MODF * fround(MODF_INV * a) fmul = lambda a, b, c=0.0: fmod( fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c ) def main(): n = int(eval(input())) c = [int(eval(input())) for _ in range(n)] _c, prev = [], 0 for i in range(n): if c[i] != prev: _c.append(c[i]) prev = c[i] c = _c n = len(c) prev_occur = [0] * (2 * 10**5 + 1) res, counts = [1.0] * (n + 1), Counter() for i in range(n): ind = prev_occur[c[i]] if ind != 0: res[i + 1] = fmod(res[i] + res[ind]) else: res[i + 1] = res[i] counts[c[i]] += 1 prev_occur[c[i]] = i + 1 print(int(res[-1]) % MOD) if __name__ == "__main__": main()
#!/usr/bin/env python2 import itertools import os import sys from atexit import register from io import StringIO range = xrange sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = StringIO(os.read(0, os.fstat(0).st_size)).readline MOD = 10**9 + 7 MODF = float(MOD) MAGIC = 6755399441055744.0 SHRT = 65536.0 MODF_INV = 1.0 / MODF SHRT_INV = 1.0 / SHRT fround = lambda x: (x + MAGIC) - MAGIC fmod = lambda a: a - MODF * fround(MODF_INV * a) def main(): n = int(eval(input())) c = [int(eval(input())) for _ in range(n)] c = [x[0] for x in itertools.groupby(c)] n = len(c) res, prev = [1.0] * (n + 1), [0] * (2 * 10**5 + 1) for i in range(n): res[i + 1] = res[i] if prev[c[i]] == 0 else fmod(res[i] + res[prev[c[i]]]) prev[c[i]] = i + 1 print(int(res[-1]) % MOD) if __name__ == "__main__": main()
false
33.823529
[ "-\"\"\"", "-This file is part of https://github.com/cheran-senthil/PyRival", "-Copyright 2019 Cheran Senthilkumar <[email protected]>", "-\"\"\"", "-from collections import Counter", "-filter = itertools.ifilter", "-map = itertools.imap", "-zip = itertools.izip", "-fmul = lambda a, b, c=0.0: fmod(", "- fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c", "-)", "- _c, prev = [], 0", "+ c = [x[0] for x in itertools.groupby(c)]", "+ n = len(c)", "+ res, prev = [1.0] * (n + 1), [0] * (2 * 10**5 + 1)", "- if c[i] != prev:", "- _c.append(c[i])", "- prev = c[i]", "- c = _c", "- n = len(c)", "- prev_occur = [0] * (2 * 10**5 + 1)", "- res, counts = [1.0] * (n + 1), Counter()", "- for i in range(n):", "- ind = prev_occur[c[i]]", "- if ind != 0:", "- res[i + 1] = fmod(res[i] + res[ind])", "- else:", "- res[i + 1] = res[i]", "- counts[c[i]] += 1", "- prev_occur[c[i]] = i + 1", "+ res[i + 1] = res[i] if prev[c[i]] == 0 else fmod(res[i] + res[prev[c[i]]])", "+ prev[c[i]] = i + 1" ]
false
0.057714
0.035671
1.617954
[ "s355500510", "s599689801" ]
u768896740
p03031
python
s229858660
s960239783
39
34
3,064
3,188
Accepted
Accepted
12.82
n, m = list(map(int, input().split())) switches = [] cnt = 0 for i in range(m): array = list(map(int, input().split())) array.pop(0) switches.append(array) p = list(map(int, input().split())) def ch_binary(l, digit): num = [0] * digit for i in l: num[i-1] = 1 return num #スイッチのON、OFFをバイナリで表現する。 switches_2 = [] for i in switches: array = ch_binary(i, n) switches_2.append(array) def check(a, b, digit, x): count = 0 for i in range(digit): if a[i] == b[i] and b[i] == 1: count += 1 if count % 2 == x: return 1 else: return 0 for i in range(2**n): bin_str = list(map(int, format(i, 'b').zfill(n))) count = 0 for j in range(m): y = check(switches_2[j], bin_str, n, p[j]) count += y if count == m: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) switches = [] for i in range(m): array = list(map(int, input().split())) switches.append(array[1:]) checker = list(map(int, input().split())) bit_size = 2 ** n ans = 0 for i in range(bit_size): num = format(i, 'b').zfill(n) flag = True for j in range(m): a = 0 for k in range(n): if num[k] == '1' and k+1 in switches[j]: a += 1 if a % 2 == checker[j]: continue else: flag = False break if flag is True: ans += 1 print(ans)
47
31
897
620
n, m = list(map(int, input().split())) switches = [] cnt = 0 for i in range(m): array = list(map(int, input().split())) array.pop(0) switches.append(array) p = list(map(int, input().split())) def ch_binary(l, digit): num = [0] * digit for i in l: num[i - 1] = 1 return num # スイッチのON、OFFをバイナリで表現する。 switches_2 = [] for i in switches: array = ch_binary(i, n) switches_2.append(array) def check(a, b, digit, x): count = 0 for i in range(digit): if a[i] == b[i] and b[i] == 1: count += 1 if count % 2 == x: return 1 else: return 0 for i in range(2**n): bin_str = list(map(int, format(i, "b").zfill(n))) count = 0 for j in range(m): y = check(switches_2[j], bin_str, n, p[j]) count += y if count == m: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) switches = [] for i in range(m): array = list(map(int, input().split())) switches.append(array[1:]) checker = list(map(int, input().split())) bit_size = 2**n ans = 0 for i in range(bit_size): num = format(i, "b").zfill(n) flag = True for j in range(m): a = 0 for k in range(n): if num[k] == "1" and k + 1 in switches[j]: a += 1 if a % 2 == checker[j]: continue else: flag = False break if flag is True: ans += 1 print(ans)
false
34.042553
[ "-cnt = 0", "- array.pop(0)", "- switches.append(array)", "-p = list(map(int, input().split()))", "-", "-", "-def ch_binary(l, digit):", "- num = [0] * digit", "- for i in l:", "- num[i - 1] = 1", "- return num", "-", "-", "-# スイッチのON、OFFをバイナリで表現する。", "-switches_2 = []", "-for i in switches:", "- array = ch_binary(i, n)", "- switches_2.append(array)", "-", "-", "-def check(a, b, digit, x):", "- count = 0", "- for i in range(digit):", "- if a[i] == b[i] and b[i] == 1:", "- count += 1", "- if count % 2 == x:", "- return 1", "- else:", "- return 0", "-", "-", "-for i in range(2**n):", "- bin_str = list(map(int, format(i, \"b\").zfill(n)))", "- count = 0", "+ switches.append(array[1:])", "+checker = list(map(int, input().split()))", "+bit_size = 2**n", "+ans = 0", "+for i in range(bit_size):", "+ num = format(i, \"b\").zfill(n)", "+ flag = True", "- y = check(switches_2[j], bin_str, n, p[j])", "- count += y", "- if count == m:", "- cnt += 1", "-print(cnt)", "+ a = 0", "+ for k in range(n):", "+ if num[k] == \"1\" and k + 1 in switches[j]:", "+ a += 1", "+ if a % 2 == checker[j]:", "+ continue", "+ else:", "+ flag = False", "+ break", "+ if flag is True:", "+ ans += 1", "+print(ans)" ]
false
0.09022
0.04402
2.049511
[ "s229858660", "s960239783" ]
u389910364
p03208
python
s800881698
s967315025
282
210
7,384
17,120
Accepted
Accepted
25.53
n, k = list(map(int, input().split())) heights = [] for _ in range(n): heights.append(int(eval(input()))) heights.sort() ans = float('inf') for i in range(len(heights)): if i + k - 1 >= len(heights): break ans = min(ans, heights[i + k - 1] - heights[i]) print(ans)
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 N, K = list(map(int, sys.stdin.buffer.readline().split())) H = [int(sys.stdin.buffer.readline()) for _ in range(N)] H = np.array(H, dtype=int) H.sort() d = N - K + 1 a = H[-d:] - H[:d] print((a.min() ))
14
25
290
440
n, k = list(map(int, input().split())) heights = [] for _ in range(n): heights.append(int(eval(input()))) heights.sort() ans = float("inf") for i in range(len(heights)): if i + k - 1 >= len(heights): break ans = min(ans, heights[i + k - 1] - heights[i]) print(ans)
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 N, K = list(map(int, sys.stdin.buffer.readline().split())) H = [int(sys.stdin.buffer.readline()) for _ in range(N)] H = np.array(H, dtype=int) H.sort() d = N - K + 1 a = H[-d:] - H[:d] print((a.min()))
false
44
[ "-n, k = list(map(int, input().split()))", "-heights = []", "-for _ in range(n):", "- heights.append(int(eval(input())))", "-heights.sort()", "-ans = float(\"inf\")", "-for i in range(len(heights)):", "- if i + k - 1 >= len(heights):", "- break", "- ans = min(ans, heights[i + k - 1] - heights[i])", "-print(ans)", "+import os", "+import sys", "+import numpy as np", "+", "+if os.getenv(\"LOCAL\"):", "+ sys.stdin = open(\"_in.txt\", \"r\")", "+sys.setrecursionlimit(10**9)", "+INF = float(\"inf\")", "+IINF = 10**18", "+MOD = 10**9 + 7", "+# MOD = 998244353", "+N, K = list(map(int, sys.stdin.buffer.readline().split()))", "+H = [int(sys.stdin.buffer.readline()) for _ in range(N)]", "+H = np.array(H, dtype=int)", "+H.sort()", "+d = N - K + 1", "+a = H[-d:] - H[:d]", "+print((a.min()))" ]
false
0.03697
0.19505
0.189542
[ "s800881698", "s967315025" ]
u888092736
p04012
python
s995821690
s428715573
21
17
3,316
2,940
Accepted
Accepted
19.05
from collections import Counter print('No') if any(v % 2 for v in Counter(input()).values()) else print('Yes')
cntr = [0] * 26 for c in input(): cntr[ord(c) - 97] += 1 print('No') if any(v % 2 for v in cntr) else print('Yes')
4
4
115
121
from collections import Counter print("No") if any(v % 2 for v in Counter(input()).values()) else print("Yes")
cntr = [0] * 26 for c in input(): cntr[ord(c) - 97] += 1 print("No") if any(v % 2 for v in cntr) else print("Yes")
false
0
[ "-from collections import Counter", "-", "-print(\"No\") if any(v % 2 for v in Counter(input()).values()) else print(\"Yes\")", "+cntr = [0] * 26", "+for c in input():", "+ cntr[ord(c) - 97] += 1", "+print(\"No\") if any(v % 2 for v in cntr) else print(\"Yes\")" ]
false
0.04115
0.040941
1.005106
[ "s995821690", "s428715573" ]
u537962130
p03136
python
s223057775
s797255401
178
63
38,384
61,884
Accepted
Accepted
64.61
n=int(eval(input())) l=list(map(int,input().split())) s=sum(l) m=max(l) ans='Yes' if s>m*2 else 'No' print(ans)
n=int(eval(input())) l=list(map(int,input().split())) print(('YNeos'[max(l)*2>=sum(l)::2]))
7
3
112
85
n = int(eval(input())) l = list(map(int, input().split())) s = sum(l) m = max(l) ans = "Yes" if s > m * 2 else "No" print(ans)
n = int(eval(input())) l = list(map(int, input().split())) print(("YNeos"[max(l) * 2 >= sum(l) :: 2]))
false
57.142857
[ "-s = sum(l)", "-m = max(l)", "-ans = \"Yes\" if s > m * 2 else \"No\"", "-print(ans)", "+print((\"YNeos\"[max(l) * 2 >= sum(l) :: 2]))" ]
false
0.042219
0.042555
0.992102
[ "s223057775", "s797255401" ]
u537859408
p02918
python
s571695297
s843159218
85
48
3,316
3,316
Accepted
Accepted
43.53
N, K = list(map(int, input().split())) S = eval(input()) happy = 0 ncc = 1 # number of connected components for i in range(N): if S[i] == 'L': if i > 0 and S[i - 1] == 'L': happy += 1 elif S[i] == 'R': if i < N - 1 and S[i + 1] == 'R': happy += 1 if i > 0 and S[i] != S[i - 1]: ncc += 1 if ncc >= 3: p = min(K, (ncc - 1) // 2) ncc -= 2 * p happy += 2 * p K -= p if ncc == 2 and K > 0: happy += 1 print(happy)
N, K = list(map(int, input().split())) S = eval(input()) happy = 0 ncc = 1 # number of connected components for i in range(N - 1): ncc += S[i] != S[i + 1] if ncc >= 3: p = min(K, (ncc - 1) // 2) ncc -= 2 * p K -= p if ncc == 2 and K > 0: ncc -= 1 print((N - ncc))
22
14
498
283
N, K = list(map(int, input().split())) S = eval(input()) happy = 0 ncc = 1 # number of connected components for i in range(N): if S[i] == "L": if i > 0 and S[i - 1] == "L": happy += 1 elif S[i] == "R": if i < N - 1 and S[i + 1] == "R": happy += 1 if i > 0 and S[i] != S[i - 1]: ncc += 1 if ncc >= 3: p = min(K, (ncc - 1) // 2) ncc -= 2 * p happy += 2 * p K -= p if ncc == 2 and K > 0: happy += 1 print(happy)
N, K = list(map(int, input().split())) S = eval(input()) happy = 0 ncc = 1 # number of connected components for i in range(N - 1): ncc += S[i] != S[i + 1] if ncc >= 3: p = min(K, (ncc - 1) // 2) ncc -= 2 * p K -= p if ncc == 2 and K > 0: ncc -= 1 print((N - ncc))
false
36.363636
[ "-for i in range(N):", "- if S[i] == \"L\":", "- if i > 0 and S[i - 1] == \"L\":", "- happy += 1", "- elif S[i] == \"R\":", "- if i < N - 1 and S[i + 1] == \"R\":", "- happy += 1", "- if i > 0 and S[i] != S[i - 1]:", "- ncc += 1", "+for i in range(N - 1):", "+ ncc += S[i] != S[i + 1]", "- happy += 2 * p", "- happy += 1", "-print(happy)", "+ ncc -= 1", "+print((N - ncc))" ]
false
0.038362
0.038311
1.001321
[ "s571695297", "s843159218" ]
u426534722
p02242
python
s344792314
s870771616
30
20
6,304
6,072
Accepted
Accepted
33.33
from collections import deque INF = float("inf") def MAIN(): n = int(eval(input())) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = deque([0]) while dp: u = dp.popleft() for v, c in list(m[u].items()): if G[v][1] > G[u][1] + c: G[v][1] = G[u][1] + c dp.append(v) print(("\n".join(" ".join(map(str, a)) for a in G))) MAIN()
from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(eval(input())) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = [(0, 0)] while dp: cost, u = heappop(dp) for v, c in list(m[u].items()): if G[v][1] > G[u][1] + c: G[v][1] = G[u][1] + c heappush(dp, (G[v][1], v)) print(("\n".join(" ".join(map(str, a)) for a in G))) MAIN()
22
22
591
623
from collections import deque INF = float("inf") def MAIN(): n = int(eval(input())) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = deque([0]) while dp: u = dp.popleft() for v, c in list(m[u].items()): if G[v][1] > G[u][1] + c: G[v][1] = G[u][1] + c dp.append(v) print(("\n".join(" ".join(map(str, a)) for a in G))) MAIN()
from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(eval(input())) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = [(0, 0)] while dp: cost, u = heappop(dp) for v, c in list(m[u].items()): if G[v][1] > G[u][1] + c: G[v][1] = G[u][1] + c heappush(dp, (G[v][1], v)) print(("\n".join(" ".join(map(str, a)) for a in G))) MAIN()
false
0
[ "-from collections import deque", "+from heapq import heapify, heappush, heappop", "- dp = deque([0])", "+ dp = [(0, 0)]", "- u = dp.popleft()", "+ cost, u = heappop(dp)", "- dp.append(v)", "+ heappush(dp, (G[v][1], v))" ]
false
0.046128
0.044264
1.042113
[ "s344792314", "s870771616" ]
u852690916
p03712
python
s900551011
s315191080
179
20
38,612
3,060
Accepted
Accepted
88.83
H,W=list(map(int, input().split())) A=[eval(input()) for _ in range(H)] print(('#'*(W+2))) for a in A: print(('#' + a + '#')) print(('#'*(W+2)))
H,W=list(map(int, input().split())) ans=[['#']*(W+2) for _ in range(H+2)] for i in range(1,H+1): for j,a in enumerate(eval(input())): j+=1 ans[i][j]=a for a in ans: print((''.join(a)))
6
8
136
201
H, W = list(map(int, input().split())) A = [eval(input()) for _ in range(H)] print(("#" * (W + 2))) for a in A: print(("#" + a + "#")) print(("#" * (W + 2)))
H, W = list(map(int, input().split())) ans = [["#"] * (W + 2) for _ in range(H + 2)] for i in range(1, H + 1): for j, a in enumerate(eval(input())): j += 1 ans[i][j] = a for a in ans: print(("".join(a)))
false
25
[ "-A = [eval(input()) for _ in range(H)]", "-print((\"#\" * (W + 2)))", "-for a in A:", "- print((\"#\" + a + \"#\"))", "-print((\"#\" * (W + 2)))", "+ans = [[\"#\"] * (W + 2) for _ in range(H + 2)]", "+for i in range(1, H + 1):", "+ for j, a in enumerate(eval(input())):", "+ j += 1", "+ ans[i][j] = a", "+for a in ans:", "+ print((\"\".join(a)))" ]
false
0.054454
0.084079
0.647652
[ "s900551011", "s315191080" ]
u780025254
p02400
python
s664458117
s675365278
50
20
7,616
5,576
Accepted
Accepted
60
import math r = float(eval(input())) circle = r * 2 * math.pi area = (r ** 2) * math.pi print(('{0:.5f} {1:.5f}'.format(area, circle)))
r = float(eval(input())) pi = 3.141592653589 print(("{:.10f} {:.10f}".format(r ** 2 * pi, 2 * r * pi)))
7
3
135
98
import math r = float(eval(input())) circle = r * 2 * math.pi area = (r**2) * math.pi print(("{0:.5f} {1:.5f}".format(area, circle)))
r = float(eval(input())) pi = 3.141592653589 print(("{:.10f} {:.10f}".format(r**2 * pi, 2 * r * pi)))
false
57.142857
[ "-import math", "-", "-circle = r * 2 * math.pi", "-area = (r**2) * math.pi", "-print((\"{0:.5f} {1:.5f}\".format(area, circle)))", "+pi = 3.141592653589", "+print((\"{:.10f} {:.10f}\".format(r**2 * pi, 2 * r * pi)))" ]
false
0.043539
0.046943
0.927487
[ "s664458117", "s675365278" ]
u328510800
p03281
python
s431508855
s022421540
31
26
9,120
9,152
Accepted
Accepted
16.13
# 引数nが持つ正の約数の数を調べる def divisor_count(n:int) -> int: count = 0 for x in range(1, n+1): if n % x == 0: count += 1 return count def solve(n: int) -> int: # [1..N]内で奇数かつ約数をちょうど8個持つ数字の数 result = 0 for x in range(1, n+1): if x&1 and divisor_count(x) == 8: result += 1 return result N = int(eval(input())) print((solve(N)))
# 引数nが持つ正の約数の数を調べる def divisor_count(n:int) -> int: count = 0 for x in range(1, n+1): if n % x == 0: count += 1 return count def solve(n: int) -> int: # [1..N]内で奇数かつ約数をちょうど8個持つ数字の数 result = 0 for x in range(1, n+1, 2): if divisor_count(x) == 8: result += 1 return result N = int(eval(input())) print((solve(N)))
19
19
367
362
# 引数nが持つ正の約数の数を調べる def divisor_count(n: int) -> int: count = 0 for x in range(1, n + 1): if n % x == 0: count += 1 return count def solve(n: int) -> int: # [1..N]内で奇数かつ約数をちょうど8個持つ数字の数 result = 0 for x in range(1, n + 1): if x & 1 and divisor_count(x) == 8: result += 1 return result N = int(eval(input())) print((solve(N)))
# 引数nが持つ正の約数の数を調べる def divisor_count(n: int) -> int: count = 0 for x in range(1, n + 1): if n % x == 0: count += 1 return count def solve(n: int) -> int: # [1..N]内で奇数かつ約数をちょうど8個持つ数字の数 result = 0 for x in range(1, n + 1, 2): if divisor_count(x) == 8: result += 1 return result N = int(eval(input())) print((solve(N)))
false
0
[ "- for x in range(1, n + 1):", "- if x & 1 and divisor_count(x) == 8:", "+ for x in range(1, n + 1, 2):", "+ if divisor_count(x) == 8:" ]
false
0.007594
0.035637
0.213104
[ "s431508855", "s022421540" ]
u721425712
p02713
python
s114427990
s682515791
1,809
947
9,092
9,108
Accepted
Accepted
47.65
from math import gcd k = int(eval(input())) sum_c = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): sum_c += gcd(gcd(a, b), c) print(sum_c)
import math A = int(eval(input())) def gcd(A): total = 0 for i in range(1,A+1): for j in range(1,A+1): B = math.gcd(i,j) for k in range(1,A+1): total += math.gcd(B,k) return total print((gcd(A)))
12
11
220
257
from math import gcd k = int(eval(input())) sum_c = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): sum_c += gcd(gcd(a, b), c) print(sum_c)
import math A = int(eval(input())) def gcd(A): total = 0 for i in range(1, A + 1): for j in range(1, A + 1): B = math.gcd(i, j) for k in range(1, A + 1): total += math.gcd(B, k) return total print((gcd(A)))
false
8.333333
[ "-from math import gcd", "+import math", "-k = int(eval(input()))", "-sum_c = 0", "-for a in range(1, k + 1):", "- for b in range(1, k + 1):", "- for c in range(1, k + 1):", "- sum_c += gcd(gcd(a, b), c)", "-print(sum_c)", "+A = int(eval(input()))", "+", "+", "+def gcd(A):", "+ total = 0", "+ for i in range(1, A + 1):", "+ for j in range(1, A + 1):", "+ B = math.gcd(i, j)", "+ for k in range(1, A + 1):", "+ total += math.gcd(B, k)", "+ return total", "+", "+", "+print((gcd(A)))" ]
false
0.162721
0.079139
2.056135
[ "s114427990", "s682515791" ]
u698176039
p02761
python
s363227105
s932752537
43
24
5,352
3,316
Accepted
Accepted
44.19
# -*- coding: utf-8 -*- import sys import random N,M = list(map(int,input().split())) sc = [list(map(int,input().split())) for _ in range(M)] # while True: # N = int(random.randint(1,3)) # M = int() ms = -1 upt = [False]*N ans = [0]*N for s,c in sc: ms = max(N-s,ms) if upt[s-1]: if ans[s-1] != c: print((-1)) sys.exit() else: continue else: upt[s-1] = True ans[s-1] = c if upt[0]: if ans[0] == 0: if N>1: print((-1)) sys.exit() else: print((0)) sys.exit() if M==0 and N==1: print((0)) sys.exit() A = 0 base = 1 for i,a in enumerate(reversed(ans)): if i==N-1 and a == 0: A += 1*base base *= 10 else: A += a * base base *= 10 print(A)
# -*- coding: utf-8 -*- import sys import random N,M = list(map(int,input().split())) sc = [list(map(int,input().split())) for _ in range(M)] #%% ans = -1 for i in range(1000): L = len(str(i)) if L!=N: continue a = [0]*L tmp = i for j in range(L): a[L-j-1] = tmp%10 tmp //= 10 for s,c in sc: if a[s-1] != c: break else: if N==1: print(i) else: if a[L-N]!=0: print(i) else: continue sys.exit() continue print(ans)
51
34
898
627
# -*- coding: utf-8 -*- import sys import random N, M = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(M)] # while True: # N = int(random.randint(1,3)) # M = int() ms = -1 upt = [False] * N ans = [0] * N for s, c in sc: ms = max(N - s, ms) if upt[s - 1]: if ans[s - 1] != c: print((-1)) sys.exit() else: continue else: upt[s - 1] = True ans[s - 1] = c if upt[0]: if ans[0] == 0: if N > 1: print((-1)) sys.exit() else: print((0)) sys.exit() if M == 0 and N == 1: print((0)) sys.exit() A = 0 base = 1 for i, a in enumerate(reversed(ans)): if i == N - 1 and a == 0: A += 1 * base base *= 10 else: A += a * base base *= 10 print(A)
# -*- coding: utf-8 -*- import sys import random N, M = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(M)] #%% ans = -1 for i in range(1000): L = len(str(i)) if L != N: continue a = [0] * L tmp = i for j in range(L): a[L - j - 1] = tmp % 10 tmp //= 10 for s, c in sc: if a[s - 1] != c: break else: if N == 1: print(i) else: if a[L - N] != 0: print(i) else: continue sys.exit() continue print(ans)
false
33.333333
[ "-# while True:", "-# N = int(random.randint(1,3))", "-# M = int()", "-ms = -1", "-upt = [False] * N", "-ans = [0] * N", "-for s, c in sc:", "- ms = max(N - s, ms)", "- if upt[s - 1]:", "- if ans[s - 1] != c:", "- print((-1))", "- sys.exit()", "+#%%", "+ans = -1", "+for i in range(1000):", "+ L = len(str(i))", "+ if L != N:", "+ continue", "+ a = [0] * L", "+ tmp = i", "+ for j in range(L):", "+ a[L - j - 1] = tmp % 10", "+ tmp //= 10", "+ for s, c in sc:", "+ if a[s - 1] != c:", "+ break", "+ else:", "+ if N == 1:", "+ print(i)", "- continue", "- else:", "- upt[s - 1] = True", "- ans[s - 1] = c", "-if upt[0]:", "- if ans[0] == 0:", "- if N > 1:", "- print((-1))", "- sys.exit()", "- else:", "- print((0))", "- sys.exit()", "-if M == 0 and N == 1:", "- print((0))", "- sys.exit()", "-A = 0", "-base = 1", "-for i, a in enumerate(reversed(ans)):", "- if i == N - 1 and a == 0:", "- A += 1 * base", "- base *= 10", "- else:", "- A += a * base", "- base *= 10", "-print(A)", "+ if a[L - N] != 0:", "+ print(i)", "+ else:", "+ continue", "+ sys.exit()", "+ continue", "+print(ans)" ]
false
0.036958
0.0448
0.82495
[ "s363227105", "s932752537" ]
u729133443
p02619
python
s311506237
s844801547
618
82
111,720
68,176
Accepted
Accepted
86.73
from time import time from random import randint from numba import njit from numpy import int64 @njit('i8(i8[:],i8[:])') def func(s,x): last=[0]*26 score=0 for i,v in enumerate(x,1): last[v]=i c=0 for j in range(26): c+=s[j]*(i-last[j]) score=score+s[i*26+v]-c print(score) return score def main(): start=time() d,*s=list(map(int,open(0).read().split())) s=int64(s) func(s,s[-d:]-1) main()
def func(s,x): last=[0]*26 score=0 for i,v in enumerate(x,1): last[v]=i c=0 for j in range(26): c+=s[j]*(i-last[j]) score=score+s[i*26+v]-c print(score) return score def main(): d,*s=list(map(int,open(0).read().split())) func(s,[t-1for t in s[-d:]]) main()
25
15
494
340
from time import time from random import randint from numba import njit from numpy import int64 @njit("i8(i8[:],i8[:])") def func(s, x): last = [0] * 26 score = 0 for i, v in enumerate(x, 1): last[v] = i c = 0 for j in range(26): c += s[j] * (i - last[j]) score = score + s[i * 26 + v] - c print(score) return score def main(): start = time() d, *s = list(map(int, open(0).read().split())) s = int64(s) func(s, s[-d:] - 1) main()
def func(s, x): last = [0] * 26 score = 0 for i, v in enumerate(x, 1): last[v] = i c = 0 for j in range(26): c += s[j] * (i - last[j]) score = score + s[i * 26 + v] - c print(score) return score def main(): d, *s = list(map(int, open(0).read().split())) func(s, [t - 1 for t in s[-d:]]) main()
false
40
[ "-from time import time", "-from random import randint", "-from numba import njit", "-from numpy import int64", "-", "-", "-@njit(\"i8(i8[:],i8[:])\")", "- start = time()", "- s = int64(s)", "- func(s, s[-d:] - 1)", "+ func(s, [t - 1 for t in s[-d:]])" ]
false
0.036913
0.037188
0.992608
[ "s311506237", "s844801547" ]
u697696097
p03861
python
s285274820
s828671931
43
18
5,624
3,060
Accepted
Accepted
58.14
import sys from io import StringIO import unittest def yn(b): print(("Yes" if b==1 else "No")) return def resolve(): readline=sys.stdin.readline a,b,x=list(map(int, readline().rstrip().split())) if a%x==0: f=a else: f=a-a%x+x if f > b: print((0)) return if b%x==0: t=b else: t=b-b%x if t<a: print((0)) return print(((t-f)//x+1)) return if 'doTest' not in globals(): resolve() sys.exit()
import sys def yn(b): print(("Yes" if b==1 else "No")) return def resolve(): readline=sys.stdin.readline a,b,x=list(map(int, readline().rstrip().split())) print((b//x - (a-1)//x)) return if 'doTest' not in globals(): resolve() sys.exit()
33
15
553
276
import sys from io import StringIO import unittest def yn(b): print(("Yes" if b == 1 else "No")) return def resolve(): readline = sys.stdin.readline a, b, x = list(map(int, readline().rstrip().split())) if a % x == 0: f = a else: f = a - a % x + x if f > b: print((0)) return if b % x == 0: t = b else: t = b - b % x if t < a: print((0)) return print(((t - f) // x + 1)) return if "doTest" not in globals(): resolve() sys.exit()
import sys def yn(b): print(("Yes" if b == 1 else "No")) return def resolve(): readline = sys.stdin.readline a, b, x = list(map(int, readline().rstrip().split())) print((b // x - (a - 1) // x)) return if "doTest" not in globals(): resolve() sys.exit()
false
54.545455
[ "-from io import StringIO", "-import unittest", "- if a % x == 0:", "- f = a", "- else:", "- f = a - a % x + x", "- if f > b:", "- print((0))", "- return", "- if b % x == 0:", "- t = b", "- else:", "- t = b - b % x", "- if t < a:", "- print((0))", "- return", "- print(((t - f) // x + 1))", "+ print((b // x - (a - 1) // x))" ]
false
0.037105
0.035758
1.037669
[ "s285274820", "s828671931" ]
u046187684
p02838
python
s918796566
s351661219
984
868
73,316
70,380
Accepted
Accepted
11.79
from itertools import starmap def solve(string): n, *a = list(map(int, string.split())) a = ["{:060b}".format(_a) for _a in a] m = 10**9 + 7 ans = 0 for s in starmap(lambda *x: x.count("1"), list(zip(*a))): ans <<= 1 ans += s * (n - s) ans %= m return str(ans) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
def solve(string): n, *a = list(map(int, string.split())) a = ("{:060b}".format(_a) for _a in a) m = 10**9 + 7 ans = 0 for s in [x.count("1") for x in zip(*a)]: ans <<= 1 ans += s * (n - s) ans %= m return str(ans) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
18
15
403
363
from itertools import starmap def solve(string): n, *a = list(map(int, string.split())) a = ["{:060b}".format(_a) for _a in a] m = 10**9 + 7 ans = 0 for s in starmap(lambda *x: x.count("1"), list(zip(*a))): ans <<= 1 ans += s * (n - s) ans %= m return str(ans) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
def solve(string): n, *a = list(map(int, string.split())) a = ("{:060b}".format(_a) for _a in a) m = 10**9 + 7 ans = 0 for s in [x.count("1") for x in zip(*a)]: ans <<= 1 ans += s * (n - s) ans %= m return str(ans) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
false
16.666667
[ "-from itertools import starmap", "-", "-", "- a = [\"{:060b}\".format(_a) for _a in a]", "+ a = (\"{:060b}\".format(_a) for _a in a)", "- for s in starmap(lambda *x: x.count(\"1\"), list(zip(*a))):", "+ for s in [x.count(\"1\") for x in zip(*a)]:" ]
false
0.085062
0.03761
2.2617
[ "s918796566", "s351661219" ]
u400765446
p02408
python
s467703249
s640509159
30
20
5,596
5,588
Accepted
Accepted
33.33
def main(): numlist = set() x = int(eval(input())) for _ in range(x): numlist.add(tuple(input().split())) cards = set() for mark in ('S', 'H', 'C', 'D'): for i in range(1,14): cards.add((mark, str(i))) for item in numlist: cards.remove(item) for mark in ('S', 'H', 'C', 'D'): for i in range(1, 14): if (mark, str(i)) in cards: print((mark, i)) if __name__ == '__main__': main()
cards = [] n = int(eval(input())) for _ in range(n): cards.append(eval(input())) # カードを全部用意する suits = ('S', 'H', 'C', 'D') res_cards = [] for suit in suits: for i in range(1, 14): res_cards.append(suit+' '+str(i)) for card in cards: res_cards.remove(card) for card in res_cards: print(card)
23
17
506
322
def main(): numlist = set() x = int(eval(input())) for _ in range(x): numlist.add(tuple(input().split())) cards = set() for mark in ("S", "H", "C", "D"): for i in range(1, 14): cards.add((mark, str(i))) for item in numlist: cards.remove(item) for mark in ("S", "H", "C", "D"): for i in range(1, 14): if (mark, str(i)) in cards: print((mark, i)) if __name__ == "__main__": main()
cards = [] n = int(eval(input())) for _ in range(n): cards.append(eval(input())) # カードを全部用意する suits = ("S", "H", "C", "D") res_cards = [] for suit in suits: for i in range(1, 14): res_cards.append(suit + " " + str(i)) for card in cards: res_cards.remove(card) for card in res_cards: print(card)
false
26.086957
[ "-def main():", "- numlist = set()", "- x = int(eval(input()))", "- for _ in range(x):", "- numlist.add(tuple(input().split()))", "- cards = set()", "- for mark in (\"S\", \"H\", \"C\", \"D\"):", "- for i in range(1, 14):", "- cards.add((mark, str(i)))", "- for item in numlist:", "- cards.remove(item)", "- for mark in (\"S\", \"H\", \"C\", \"D\"):", "- for i in range(1, 14):", "- if (mark, str(i)) in cards:", "- print((mark, i))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+cards = []", "+n = int(eval(input()))", "+for _ in range(n):", "+ cards.append(eval(input()))", "+# カードを全部用意する", "+suits = (\"S\", \"H\", \"C\", \"D\")", "+res_cards = []", "+for suit in suits:", "+ for i in range(1, 14):", "+ res_cards.append(suit + \" \" + str(i))", "+for card in cards:", "+ res_cards.remove(card)", "+for card in res_cards:", "+ print(card)" ]
false
0.062851
0.108309
0.580299
[ "s467703249", "s640509159" ]
u562935282
p02555
python
s090240153
s157313464
29
25
9,156
9,108
Accepted
Accepted
13.79
def main(): MOD = 10 ** 9 + 7 S = int(eval(input())) dp = [0] * (S + 1) dp[0] = 1 for x in range(3, S + 1): # dp[x-3] + dp[x-4] + dp[x-5] + ... + dp[0] # dp[x-3] + dp[x-1] dp[x] = (dp[x - 3] + dp[x - 1]) % MOD print((dp[S])) if __name__ == '__main__': main()
def main(): MOD = 10 ** 9 + 7 S = int(eval(input())) dp = [0] * (S + 1) dp[0] = 1 acc = 0 for x in range(3, S + 1): dp[x] = (acc := (acc + dp[x - 3]) % MOD) print((dp[S])) if __name__ == '__main__': main()
17
16
324
258
def main(): MOD = 10**9 + 7 S = int(eval(input())) dp = [0] * (S + 1) dp[0] = 1 for x in range(3, S + 1): # dp[x-3] + dp[x-4] + dp[x-5] + ... + dp[0] # dp[x-3] + dp[x-1] dp[x] = (dp[x - 3] + dp[x - 1]) % MOD print((dp[S])) if __name__ == "__main__": main()
def main(): MOD = 10**9 + 7 S = int(eval(input())) dp = [0] * (S + 1) dp[0] = 1 acc = 0 for x in range(3, S + 1): dp[x] = (acc := (acc + dp[x - 3]) % MOD) print((dp[S])) if __name__ == "__main__": main()
false
5.882353
[ "+ acc = 0", "- # dp[x-3] + dp[x-4] + dp[x-5] + ... + dp[0]", "- # dp[x-3] + dp[x-1]", "- dp[x] = (dp[x - 3] + dp[x - 1]) % MOD", "+ dp[x] = (acc := (acc + dp[x - 3]) % MOD)" ]
false
0.037284
0.035818
1.040952
[ "s090240153", "s157313464" ]
u970308980
p03241
python
s389799477
s467152080
187
22
38,640
3,188
Accepted
Accepted
88.24
def divisor(n): ass = [] for i in range(1, int(n**0.5)+1): if n % i == 0: ass.append(i) ass.append(n//i) return ass N, M = list(map(int, input().split())) K = divisor(M) ans = 0 for k in K: if N * k <= M: ans = max(ans, k) print(ans)
N, M = list(map(int, input().split())) # Mの約数列挙 divs = set() for i in range(1, int(M ** 0.5) + 1): if M % i == 0: divs.add(i) divs.add(M // i) ans = 0 for d in divs: if N * d <= M: ans = max(ans, d) print(ans)
21
15
311
253
def divisor(n): ass = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: ass.append(i) ass.append(n // i) return ass N, M = list(map(int, input().split())) K = divisor(M) ans = 0 for k in K: if N * k <= M: ans = max(ans, k) print(ans)
N, M = list(map(int, input().split())) # Mの約数列挙 divs = set() for i in range(1, int(M**0.5) + 1): if M % i == 0: divs.add(i) divs.add(M // i) ans = 0 for d in divs: if N * d <= M: ans = max(ans, d) print(ans)
false
28.571429
[ "-def divisor(n):", "- ass = []", "- for i in range(1, int(n**0.5) + 1):", "- if n % i == 0:", "- ass.append(i)", "- ass.append(n // i)", "- return ass", "-", "-", "-K = divisor(M)", "+# Mの約数列挙", "+divs = set()", "+for i in range(1, int(M**0.5) + 1):", "+ if M % i == 0:", "+ divs.add(i)", "+ divs.add(M // i)", "-for k in K:", "- if N * k <= M:", "- ans = max(ans, k)", "+for d in divs:", "+ if N * d <= M:", "+ ans = max(ans, d)" ]
false
0.049634
0.087933
0.564454
[ "s389799477", "s467152080" ]
u450904670
p03449
python
s101338565
s383411303
149
17
12,484
3,064
Accepted
Accepted
88.59
import numpy as np n = int(eval(input())) a = [ list(map(int, input().split())) for _ in range(2) ] na = np.array(a) top_sum = na[0].cumsum() under_sum = na[1][::-1].cumsum()[::-1] amount = [top_sum[i] + under_sum[i] for i in range(n)] print((max(amount)))
def main(): n = int(eval(input())) a = [ list(map(int, input().split())) for _ in range(2)] print((problem087c(n, a))) def problem087c(n, a): dp = [ [0 for _ in range(n)] for _ in range(2)] dp[0][0] = a[0][0] dp[1][0] = dp[0][0] + a[1][0] for i in range(n - 1): dp[0][i + 1] += dp[0][i] + a[0][i + 1] dp[1][i + 1] = max([dp[1][i] + a[1][i + 1], dp[0][i + 1] + a[1][i + 1]]) return max([dp[0][n - 1], dp[1][n - 1]]) main()
10
14
260
475
import numpy as np n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(2)] na = np.array(a) top_sum = na[0].cumsum() under_sum = na[1][::-1].cumsum()[::-1] amount = [top_sum[i] + under_sum[i] for i in range(n)] print((max(amount)))
def main(): n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(2)] print((problem087c(n, a))) def problem087c(n, a): dp = [[0 for _ in range(n)] for _ in range(2)] dp[0][0] = a[0][0] dp[1][0] = dp[0][0] + a[1][0] for i in range(n - 1): dp[0][i + 1] += dp[0][i] + a[0][i + 1] dp[1][i + 1] = max([dp[1][i] + a[1][i + 1], dp[0][i + 1] + a[1][i + 1]]) return max([dp[0][n - 1], dp[1][n - 1]]) main()
false
28.571429
[ "-import numpy as np", "+def main():", "+ n = int(eval(input()))", "+ a = [list(map(int, input().split())) for _ in range(2)]", "+ print((problem087c(n, a)))", "-n = int(eval(input()))", "-a = [list(map(int, input().split())) for _ in range(2)]", "-na = np.array(a)", "-top_sum = na[0].cumsum()", "-under_sum = na[1][::-1].cumsum()[::-1]", "-amount = [top_sum[i] + under_sum[i] for i in range(n)]", "-print((max(amount)))", "+", "+def problem087c(n, a):", "+ dp = [[0 for _ in range(n)] for _ in range(2)]", "+ dp[0][0] = a[0][0]", "+ dp[1][0] = dp[0][0] + a[1][0]", "+ for i in range(n - 1):", "+ dp[0][i + 1] += dp[0][i] + a[0][i + 1]", "+ dp[1][i + 1] = max([dp[1][i] + a[1][i + 1], dp[0][i + 1] + a[1][i + 1]])", "+ return max([dp[0][n - 1], dp[1][n - 1]])", "+", "+", "+main()" ]
false
0.182385
0.078684
2.317956
[ "s101338565", "s383411303" ]
u804566868
p03073
python
s865117090
s667821273
90
71
6,700
4,652
Accepted
Accepted
21.11
mass = eval(input()) mass = list(mass) count = 0 for i in range(0, len(mass)): try: if(mass[i] == mass[i+1]): mass[i+1] = (int(mass[i+1]) + 1) % 2 mass[i+1] = str(mass[i+1]) count += 1 except IndexError: print(count)
mass = eval(input()) mass = list(mass) #入力した文字列をリストで管理する mass = [int(n) for n in mass] count = 0 for i in range(0, len(mass)): try: if(mass[i] == mass[i+1]): #同じ数字が続くか判定する mass[i+1] = (mass[i+1] + 1) % 2 #0なら1に、1なら0に数字を入れ替える count += 1 except IndexError: #すべての文字を比較したときの処理 print(count)
13
12
285
340
mass = eval(input()) mass = list(mass) count = 0 for i in range(0, len(mass)): try: if mass[i] == mass[i + 1]: mass[i + 1] = (int(mass[i + 1]) + 1) % 2 mass[i + 1] = str(mass[i + 1]) count += 1 except IndexError: print(count)
mass = eval(input()) mass = list(mass) # 入力した文字列をリストで管理する mass = [int(n) for n in mass] count = 0 for i in range(0, len(mass)): try: if mass[i] == mass[i + 1]: # 同じ数字が続くか判定する mass[i + 1] = (mass[i + 1] + 1) % 2 # 0なら1に、1なら0に数字を入れ替える count += 1 except IndexError: # すべての文字を比較したときの処理 print(count)
false
7.692308
[ "-mass = list(mass)", "+mass = list(mass) # 入力した文字列をリストで管理する", "+mass = [int(n) for n in mass]", "- if mass[i] == mass[i + 1]:", "- mass[i + 1] = (int(mass[i + 1]) + 1) % 2", "- mass[i + 1] = str(mass[i + 1])", "+ if mass[i] == mass[i + 1]: # 同じ数字が続くか判定する", "+ mass[i + 1] = (mass[i + 1] + 1) % 2 # 0なら1に、1なら0に数字を入れ替える", "- except IndexError:", "+ except IndexError: # すべての文字を比較したときの処理" ]
false
0.109239
0.048785
2.239183
[ "s865117090", "s667821273" ]
u968166680
p02973
python
s263294294
s541482138
261
76
71,228
12,528
Accepted
Accepted
70.88
import sys from bisect import bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *A = list(map(int, read().split())) dp = [A.pop()] for a in reversed(A): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == '__main__': main()
def main(): import sys import bisect read = sys.stdin.buffer.read bisect_right = bisect.bisect_right N, *A = list(map(int, read().split())) dp = [A[-1]] for a in reversed(A[:-1]): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == '__main__': main()
26
22
469
400
import sys from bisect import bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): N, *A = list(map(int, read().split())) dp = [A.pop()] for a in reversed(A): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == "__main__": main()
def main(): import sys import bisect read = sys.stdin.buffer.read bisect_right = bisect.bisect_right N, *A = list(map(int, read().split())) dp = [A[-1]] for a in reversed(A[:-1]): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == "__main__": main()
false
15.384615
[ "-import sys", "-from bisect import bisect_right", "+def main():", "+ import sys", "+ import bisect", "-read = sys.stdin.read", "-readline = sys.stdin.readline", "-readlines = sys.stdin.readlines", "-sys.setrecursionlimit(10**9)", "-INF = 1 << 60", "-", "-", "-def main():", "+ read = sys.stdin.buffer.read", "+ bisect_right = bisect.bisect_right", "- dp = [A.pop()]", "- for a in reversed(A):", "+ dp = [A[-1]]", "+ for a in reversed(A[:-1]):" ]
false
0.060365
0.036924
1.634851
[ "s263294294", "s541482138" ]