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
u263830634
p03450
python
s604625696
s911431445
1,185
893
66,288
66,296
Accepted
Accepted
24.64
from collections import deque N, M = list(map(int, input().split())) G = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, input().split())) G[l].append((r, -d)) G[r].append((l, d)) MIN = -10 ** 18 lst = [MIN] * (N + 1) que = deque() for i in range(1, N + 1): if lst[i] == MIN: que.append(i) lst[i] = 0 while que: tmp = que.popleft() for next_, d in G[tmp]: if lst[next_] == MIN: lst[next_] = lst[tmp] + d que.append(next_) continue if lst[next_] == lst[tmp] + d: continue else: print ('No') exit() print ('Yes')
from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) G = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, input().split())) G[l].append((r, -d)) G[r].append((l, d)) MIN = -10 ** 18 lst = [MIN] * (N + 1) que = deque() for i in range(1, N + 1): if lst[i] == MIN: que.append(i) lst[i] = 0 while que: tmp = que.popleft() for next_, d in G[tmp]: if lst[next_] == MIN: lst[next_] = lst[tmp] + d que.append(next_) continue if lst[next_] == lst[tmp] + d: continue else: print ('No') exit() print ('Yes')
38
40
765
805
from collections import deque N, M = list(map(int, input().split())) G = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, input().split())) G[l].append((r, -d)) G[r].append((l, d)) MIN = -(10**18) lst = [MIN] * (N + 1) que = deque() for i in range(1, N + 1): if lst[i] == MIN: que.append(i) lst[i] = 0 while que: tmp = que.popleft() for next_, d in G[tmp]: if lst[next_] == MIN: lst[next_] = lst[tmp] + d que.append(next_) continue if lst[next_] == lst[tmp] + d: continue else: print("No") exit() print("Yes")
from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) G = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, input().split())) G[l].append((r, -d)) G[r].append((l, d)) MIN = -(10**18) lst = [MIN] * (N + 1) que = deque() for i in range(1, N + 1): if lst[i] == MIN: que.append(i) lst[i] = 0 while que: tmp = que.popleft() for next_, d in G[tmp]: if lst[next_] == MIN: lst[next_] = lst[tmp] + d que.append(next_) continue if lst[next_] == lst[tmp] + d: continue else: print("No") exit() print("Yes")
false
5
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.04103
0.04025
1.019372
[ "s604625696", "s911431445" ]
u585482323
p03085
python
s924237825
s728384322
185
169
38,256
38,256
Accepted
Accepted
8.65
n = eval(input());ans="ACGT";k=ans.index(n)^3;print((ans[k]))
n=eval(input());a="ACGT";print((a[a.index(n)^3]))
1
1
53
41
n = eval(input()) ans = "ACGT" k = ans.index(n) ^ 3 print((ans[k]))
n = eval(input()) a = "ACGT" print((a[a.index(n) ^ 3]))
false
0
[ "-ans = \"ACGT\"", "-k = ans.index(n) ^ 3", "-print((ans[k]))", "+a = \"ACGT\"", "+print((a[a.index(n) ^ 3]))" ]
false
0.048257
0.039515
1.221226
[ "s924237825", "s728384322" ]
u183509493
p02678
python
s380926150
s625108554
781
417
34,104
99,140
Accepted
Accepted
46.61
from collections import deque n,m=list(map(int,input().split())) adj=[[] for _ in range(n)] for _ in range(m): x,y=list(map(int,input().split())) adj[x-1].append(y-1) adj[y-1].append(x-1) before=[None] * n before[0] = -1 q=deque([0]) while len(q): node=q.popleft() for nxt in adj[node]: if before[nxt] is not None: continue q.append(nxt) before[nxt] = node print("Yes") for i in range(1, n): print((before[i] + 1))
from collections import deque N, M = list(map(int, input().split())) AB = [[] for _ in range(N+1)] for i in range(M): A_tmp , B_tmp = list(map(int, input().split())) AB[A_tmp].append(B_tmp) AB[B_tmp].append(A_tmp) ans = [0]*(N+1) visited = [False] * (N + 1) q = deque() q.append((1, -1)) while len(q) > 0: node, past = q.popleft() if visited[node]: continue ans[node] = past visited[node] = True for t in AB[node]: if visited[t]: continue q.append((t, node)) print("Yes") for i in range(2, N+1): print((ans[i]))
24
27
459
597
from collections import deque n, m = list(map(int, input().split())) adj = [[] for _ in range(n)] for _ in range(m): x, y = list(map(int, input().split())) adj[x - 1].append(y - 1) adj[y - 1].append(x - 1) before = [None] * n before[0] = -1 q = deque([0]) while len(q): node = q.popleft() for nxt in adj[node]: if before[nxt] is not None: continue q.append(nxt) before[nxt] = node print("Yes") for i in range(1, n): print((before[i] + 1))
from collections import deque N, M = list(map(int, input().split())) AB = [[] for _ in range(N + 1)] for i in range(M): A_tmp, B_tmp = list(map(int, input().split())) AB[A_tmp].append(B_tmp) AB[B_tmp].append(A_tmp) ans = [0] * (N + 1) visited = [False] * (N + 1) q = deque() q.append((1, -1)) while len(q) > 0: node, past = q.popleft() if visited[node]: continue ans[node] = past visited[node] = True for t in AB[node]: if visited[t]: continue q.append((t, node)) print("Yes") for i in range(2, N + 1): print((ans[i]))
false
11.111111
[ "-n, m = list(map(int, input().split()))", "-adj = [[] for _ in range(n)]", "-for _ in range(m):", "- x, y = list(map(int, input().split()))", "- adj[x - 1].append(y - 1)", "- adj[y - 1].append(x - 1)", "-before = [None] * n", "-before[0] = -1", "-q = deque([0])", "-while len(q):", "- node = q.popleft()", "- for nxt in adj[node]:", "- if before[nxt] is not None:", "+N, M = list(map(int, input().split()))", "+AB = [[] for _ in range(N + 1)]", "+for i in range(M):", "+ A_tmp, B_tmp = list(map(int, input().split()))", "+ AB[A_tmp].append(B_tmp)", "+ AB[B_tmp].append(A_tmp)", "+ans = [0] * (N + 1)", "+visited = [False] * (N + 1)", "+q = deque()", "+q.append((1, -1))", "+while len(q) > 0:", "+ node, past = q.popleft()", "+ if visited[node]:", "+ continue", "+ ans[node] = past", "+ visited[node] = True", "+ for t in AB[node]:", "+ if visited[t]:", "- q.append(nxt)", "- before[nxt] = node", "+ q.append((t, node))", "-for i in range(1, n):", "- print((before[i] + 1))", "+for i in range(2, N + 1):", "+ print((ans[i]))" ]
false
0.037139
0.037507
0.990175
[ "s380926150", "s625108554" ]
u631277801
p03593
python
s636475527
s392120029
25
22
3,316
3,316
Accepted
Accepted
12
import sys stdin = sys.stdin def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter h,w = li() cnt = Counter([]) for _ in range(h): tmp = lc() for c in tmp: cnt[c] += 1 exist = True if h%2 == 0 and w%2 == 0: for key,value in list(cnt.items()): if value%4 != 0: exist = False break elif h%2 == 1 and w%2 == 1: odd = 0 mod4_2 = 0 for key,value in list(cnt.items()): if value % 2 == 1: odd += 1 elif value % 4 == 2: mod4_2 += 1 if odd > 1: exist = False elif mod4_2 > (h+w-2)//2: exist = False else: odmax = 0 if h%2 == 0: odmax = h//2 else: odmax = w//2 mod4_2 = 0 for key, value in list(cnt.items()): if value%2 != 0: exist = False break elif value%4 == 2: mod4_2 +=1 if mod4_2 > odmax: exist = False if exist: print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import defaultdict def judge(cnts, h, w): odd_cnt = 0 mod4_2_cnt = 0 mod4_0_cnt = 0 for key, val in list(cnts.items()): if val % 2 == 1: odd_cnt += 1 elif val % 4 == 2: mod4_2_cnt += 1 else: mod4_0_cnt += 1 if h == 1 and w == 1: return True elif h == 1: if w % 2 == 1: return True if odd_cnt == 1 else False else: return True if odd_cnt == 0 else False elif w == 1: if h % 2 == 1: return True if odd_cnt == 1 else False else: return True if odd_cnt == 0 else False elif h % 2 == 1 and w % 2 == 1: return True if mod4_2_cnt == (w//2 + h//2) and odd_cnt == 1 else False elif h%2 == 1: return True if mod4_2_cnt == (w//2) and odd_cnt == 0 else False elif w%2 == 1: return True if mod4_2_cnt == (h//2) and odd_cnt == 0 else False else: return True if mod4_2_cnt == 0 and odd_cnt == 0 else False h, w = li() a = [ns() for _ in range(h)] char_cnt = defaultdict(int) for ai in a: for aij in ai: char_cnt[aij] += 1 print(("Yes" if judge(char_cnt, h, w) else "No"))
68
70
1,451
1,719
import sys stdin = sys.stdin def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import Counter h, w = li() cnt = Counter([]) for _ in range(h): tmp = lc() for c in tmp: cnt[c] += 1 exist = True if h % 2 == 0 and w % 2 == 0: for key, value in list(cnt.items()): if value % 4 != 0: exist = False break elif h % 2 == 1 and w % 2 == 1: odd = 0 mod4_2 = 0 for key, value in list(cnt.items()): if value % 2 == 1: odd += 1 elif value % 4 == 2: mod4_2 += 1 if odd > 1: exist = False elif mod4_2 > (h + w - 2) // 2: exist = False else: odmax = 0 if h % 2 == 0: odmax = h // 2 else: odmax = w // 2 mod4_2 = 0 for key, value in list(cnt.items()): if value % 2 != 0: exist = False break elif value % 4 == 2: mod4_2 += 1 if mod4_2 > odmax: exist = False if exist: print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import defaultdict def judge(cnts, h, w): odd_cnt = 0 mod4_2_cnt = 0 mod4_0_cnt = 0 for key, val in list(cnts.items()): if val % 2 == 1: odd_cnt += 1 elif val % 4 == 2: mod4_2_cnt += 1 else: mod4_0_cnt += 1 if h == 1 and w == 1: return True elif h == 1: if w % 2 == 1: return True if odd_cnt == 1 else False else: return True if odd_cnt == 0 else False elif w == 1: if h % 2 == 1: return True if odd_cnt == 1 else False else: return True if odd_cnt == 0 else False elif h % 2 == 1 and w % 2 == 1: return True if mod4_2_cnt == (w // 2 + h // 2) and odd_cnt == 1 else False elif h % 2 == 1: return True if mod4_2_cnt == (w // 2) and odd_cnt == 0 else False elif w % 2 == 1: return True if mod4_2_cnt == (h // 2) and odd_cnt == 0 else False else: return True if mod4_2_cnt == 0 and odd_cnt == 0 else False h, w = li() a = [ns() for _ in range(h)] char_cnt = defaultdict(int) for ai in a: for aij in ai: char_cnt[aij] += 1 print(("Yes" if judge(char_cnt, h, w) else "No"))
false
2.857143
[ "+sys.setrecursionlimit(10**7)", "-from collections import Counter", "+from collections import defaultdict", "+", "+", "+def judge(cnts, h, w):", "+ odd_cnt = 0", "+ mod4_2_cnt = 0", "+ mod4_0_cnt = 0", "+ for key, val in list(cnts.items()):", "+ if val % 2 == 1:", "+ odd_cnt += 1", "+ elif val % 4 == 2:", "+ mod4_2_cnt += 1", "+ else:", "+ mod4_0_cnt += 1", "+ if h == 1 and w == 1:", "+ return True", "+ elif h == 1:", "+ if w % 2 == 1:", "+ return True if odd_cnt == 1 else False", "+ else:", "+ return True if odd_cnt == 0 else False", "+ elif w == 1:", "+ if h % 2 == 1:", "+ return True if odd_cnt == 1 else False", "+ else:", "+ return True if odd_cnt == 0 else False", "+ elif h % 2 == 1 and w % 2 == 1:", "+ return True if mod4_2_cnt == (w // 2 + h // 2) and odd_cnt == 1 else False", "+ elif h % 2 == 1:", "+ return True if mod4_2_cnt == (w // 2) and odd_cnt == 0 else False", "+ elif w % 2 == 1:", "+ return True if mod4_2_cnt == (h // 2) and odd_cnt == 0 else False", "+ else:", "+ return True if mod4_2_cnt == 0 and odd_cnt == 0 else False", "+", "-cnt = Counter([])", "-for _ in range(h):", "- tmp = lc()", "- for c in tmp:", "- cnt[c] += 1", "-exist = True", "-if h % 2 == 0 and w % 2 == 0:", "- for key, value in list(cnt.items()):", "- if value % 4 != 0:", "- exist = False", "- break", "-elif h % 2 == 1 and w % 2 == 1:", "- odd = 0", "- mod4_2 = 0", "- for key, value in list(cnt.items()):", "- if value % 2 == 1:", "- odd += 1", "- elif value % 4 == 2:", "- mod4_2 += 1", "- if odd > 1:", "- exist = False", "- elif mod4_2 > (h + w - 2) // 2:", "- exist = False", "-else:", "- odmax = 0", "- if h % 2 == 0:", "- odmax = h // 2", "- else:", "- odmax = w // 2", "- mod4_2 = 0", "- for key, value in list(cnt.items()):", "- if value % 2 != 0:", "- exist = False", "- break", "- elif value % 4 == 2:", "- mod4_2 += 1", "- if mod4_2 > odmax:", "- exist = False", "-if exist:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+a = [ns() for _ in range(h)]", "+char_cnt = defaultdict(int)", "+for ai in a:", "+ for aij in ai:", "+ char_cnt[aij] += 1", "+print((\"Yes\" if judge(char_cnt, h, w) else \"No\"))" ]
false
0.037243
0.041165
0.904731
[ "s636475527", "s392120029" ]
u199830845
p02732
python
s714754174
s634061243
1,790
439
26,780
26,772
Accepted
Accepted
75.47
import collections import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(eval(input())) A_list = list(map(int, input().split())) counts = collections.Counter(A_list) ans = 0 for _, v in list(counts.items()): # ans += len(list(itertools.combinations(range(v), 2))) if v > 1: ans += combinations_count(v, 2) for k in range(1, N + 1): n = counts[A_list[k - 1]] ans_k = ans if n > 1: ans_k -= n - 1 print((int(ans_k)))
import collections # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(eval(input())) A_list = list(map(int, input().split())) counts = collections.Counter(A_list) ans = 0 for _, v in list(counts.items()): ans += v * (v - 1) / 2 for k in range(1, N + 1): n = counts[A_list[k - 1]] ans_k = ans if n > 1: ans_k -= n - 1 print((int(ans_k)))
23
20
539
441
import collections import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(eval(input())) A_list = list(map(int, input().split())) counts = collections.Counter(A_list) ans = 0 for _, v in list(counts.items()): # ans += len(list(itertools.combinations(range(v), 2))) if v > 1: ans += combinations_count(v, 2) for k in range(1, N + 1): n = counts[A_list[k - 1]] ans_k = ans if n > 1: ans_k -= n - 1 print((int(ans_k)))
import collections # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(eval(input())) A_list = list(map(int, input().split())) counts = collections.Counter(A_list) ans = 0 for _, v in list(counts.items()): ans += v * (v - 1) / 2 for k in range(1, N + 1): n = counts[A_list[k - 1]] ans_k = ans if n > 1: ans_k -= n - 1 print((int(ans_k)))
false
13.043478
[ "-import math", "-", "-def combinations_count(n, r):", "- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "-", "-", "+# def combinations_count(n, r):", "+# return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "- # ans += len(list(itertools.combinations(range(v), 2)))", "- if v > 1:", "- ans += combinations_count(v, 2)", "+ ans += v * (v - 1) / 2" ]
false
0.037065
0.038909
0.952595
[ "s714754174", "s634061243" ]
u729133443
p03077
python
s709476707
s304132111
183
17
38,384
2,940
Accepted
Accepted
90.71
n,*a=eval('int(input()),'*6);print((4--n//min(a)))
n,*a=list(map(int,open(0)));print((4--n//min(a)))
1
1
48
41
n, *a = eval("int(input())," * 6) print((4 - -n // min(a)))
n, *a = list(map(int, open(0))) print((4 - -n // min(a)))
false
0
[ "-n, *a = eval(\"int(input()),\" * 6)", "+n, *a = list(map(int, open(0)))" ]
false
0.047619
0.097663
0.48759
[ "s709476707", "s304132111" ]
u072053884
p02376
python
s348115507
s669951985
50
40
8,168
8,164
Accepted
Accepted
20
# Acceptance of input import sys file_input = sys.stdin V, E = list(map(int, file_input.readline().split())) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = list(map(int, line.split())) adj_mat[u][v] = c # Ford???Fulkerson algorithm import collections # BFS for residual capacity network def bfs(start, goal, parent): unvisited = [True] * V queue = collections.deque() queue.append(start) unvisited[start] = False while queue: u = queue.popleft() for v, flow in enumerate(adj_mat[u]): if unvisited[v] and (flow > 0): queue.append(v) unvisited[v] = False parent[v] = u return not unvisited[goal] def ford_fulkerson(source, sink): parent = [None] * V max_flow = 0 while bfs(source, sink, parent): aug_path_flow = 10000 v = sink while (v != source): aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v]) v = parent[v] max_flow += aug_path_flow v = sink while (v != source): u = parent[v] adj_mat[u][v] -= aug_path_flow adj_mat[v][u] += aug_path_flow v = u return max_flow # output print((ford_fulkerson(0, V - 1)))
# Acceptance of input import sys file_input = sys.stdin V, E = list(map(int, file_input.readline().split())) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = list(map(int, line.split())) adj_mat[u][v] = c # Ford???Fulkerson algorithm import collections # BFS for residual capacity network def bfs(start, goal, parent): flow = [0] * V queue = collections.deque() queue.append(start) flow[start] = 10000 while queue: u = queue.popleft() for v, r_capacity in enumerate(adj_mat[u]): if not flow[v] and (r_capacity > 0): queue.append(v) flow[v] = min(flow[u], r_capacity) parent[v] = u if v == goal: return flow[goal] def ford_fulkerson(source, sink): max_flow = 0 while True: parent = [None] * V aug_path_flow = bfs(source, sink, parent) if aug_path_flow: max_flow += aug_path_flow v = sink while (v != source): u = parent[v] adj_mat[u][v] -= aug_path_flow adj_mat[v][u] += aug_path_flow v = u else: break return max_flow # output print((ford_fulkerson(0, V - 1)))
53
53
1,331
1,327
# Acceptance of input import sys file_input = sys.stdin V, E = list(map(int, file_input.readline().split())) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = list(map(int, line.split())) adj_mat[u][v] = c # Ford???Fulkerson algorithm import collections # BFS for residual capacity network def bfs(start, goal, parent): unvisited = [True] * V queue = collections.deque() queue.append(start) unvisited[start] = False while queue: u = queue.popleft() for v, flow in enumerate(adj_mat[u]): if unvisited[v] and (flow > 0): queue.append(v) unvisited[v] = False parent[v] = u return not unvisited[goal] def ford_fulkerson(source, sink): parent = [None] * V max_flow = 0 while bfs(source, sink, parent): aug_path_flow = 10000 v = sink while v != source: aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v]) v = parent[v] max_flow += aug_path_flow v = sink while v != source: u = parent[v] adj_mat[u][v] -= aug_path_flow adj_mat[v][u] += aug_path_flow v = u return max_flow # output print((ford_fulkerson(0, V - 1)))
# Acceptance of input import sys file_input = sys.stdin V, E = list(map(int, file_input.readline().split())) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = list(map(int, line.split())) adj_mat[u][v] = c # Ford???Fulkerson algorithm import collections # BFS for residual capacity network def bfs(start, goal, parent): flow = [0] * V queue = collections.deque() queue.append(start) flow[start] = 10000 while queue: u = queue.popleft() for v, r_capacity in enumerate(adj_mat[u]): if not flow[v] and (r_capacity > 0): queue.append(v) flow[v] = min(flow[u], r_capacity) parent[v] = u if v == goal: return flow[goal] def ford_fulkerson(source, sink): max_flow = 0 while True: parent = [None] * V aug_path_flow = bfs(source, sink, parent) if aug_path_flow: max_flow += aug_path_flow v = sink while v != source: u = parent[v] adj_mat[u][v] -= aug_path_flow adj_mat[v][u] += aug_path_flow v = u else: break return max_flow # output print((ford_fulkerson(0, V - 1)))
false
0
[ "- unvisited = [True] * V", "+ flow = [0] * V", "- unvisited[start] = False", "+ flow[start] = 10000", "- for v, flow in enumerate(adj_mat[u]):", "- if unvisited[v] and (flow > 0):", "+ for v, r_capacity in enumerate(adj_mat[u]):", "+ if not flow[v] and (r_capacity > 0):", "- unvisited[v] = False", "+ flow[v] = min(flow[u], r_capacity)", "- return not unvisited[goal]", "+ if v == goal:", "+ return flow[goal]", "- parent = [None] * V", "- while bfs(source, sink, parent):", "- aug_path_flow = 10000", "- v = sink", "- while v != source:", "- aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v])", "- v = parent[v]", "- max_flow += aug_path_flow", "- v = sink", "- while v != source:", "- u = parent[v]", "- adj_mat[u][v] -= aug_path_flow", "- adj_mat[v][u] += aug_path_flow", "- v = u", "+ while True:", "+ parent = [None] * V", "+ aug_path_flow = bfs(source, sink, parent)", "+ if aug_path_flow:", "+ max_flow += aug_path_flow", "+ v = sink", "+ while v != source:", "+ u = parent[v]", "+ adj_mat[u][v] -= aug_path_flow", "+ adj_mat[v][u] += aug_path_flow", "+ v = u", "+ else:", "+ break" ]
false
0.069522
0.03707
1.875398
[ "s348115507", "s669951985" ]
u392319141
p03695
python
s479478724
s360151884
21
17
3,316
3,060
Accepted
Accepted
19.05
from collections import defaultdict N = int(eval(input())) A = list(map(int, input().split())) colorCount = defaultdict(int) for a in A: if a < 400: colorCount['a'] += 1 elif a < 800: colorCount['b'] += 1 elif a < 1200: colorCount['c'] += 1 elif a < 1600: colorCount['d'] += 1 elif a < 2000: colorCount['e'] += 1 elif a < 2400: colorCount['f'] += 1 elif a < 2800: colorCount['g'] += 1 elif a < 3200: colorCount['h'] += 1 else: colorCount['z'] += 1 minAns = len(colorCount) maxAns = minAns if colorCount['z'] > 0: if minAns == 1: minAns = 1 maxAns = colorCount['z'] else: minAns -= 1 maxAns = maxAns - 1 + colorCount['z'] print((minAns, maxAns))
N = int(eval(input())) A = list(map(int, input().split())) ans = set() cnt = 0 for a in A: if a >= 3200: cnt += 1 else: ans.add(a // 400) mx = len(ans) + cnt mi = max(1, len(ans)) print((mi, mx))
38
15
826
229
from collections import defaultdict N = int(eval(input())) A = list(map(int, input().split())) colorCount = defaultdict(int) for a in A: if a < 400: colorCount["a"] += 1 elif a < 800: colorCount["b"] += 1 elif a < 1200: colorCount["c"] += 1 elif a < 1600: colorCount["d"] += 1 elif a < 2000: colorCount["e"] += 1 elif a < 2400: colorCount["f"] += 1 elif a < 2800: colorCount["g"] += 1 elif a < 3200: colorCount["h"] += 1 else: colorCount["z"] += 1 minAns = len(colorCount) maxAns = minAns if colorCount["z"] > 0: if minAns == 1: minAns = 1 maxAns = colorCount["z"] else: minAns -= 1 maxAns = maxAns - 1 + colorCount["z"] print((minAns, maxAns))
N = int(eval(input())) A = list(map(int, input().split())) ans = set() cnt = 0 for a in A: if a >= 3200: cnt += 1 else: ans.add(a // 400) mx = len(ans) + cnt mi = max(1, len(ans)) print((mi, mx))
false
60.526316
[ "-from collections import defaultdict", "-", "-colorCount = defaultdict(int)", "+ans = set()", "+cnt = 0", "- if a < 400:", "- colorCount[\"a\"] += 1", "- elif a < 800:", "- colorCount[\"b\"] += 1", "- elif a < 1200:", "- colorCount[\"c\"] += 1", "- elif a < 1600:", "- colorCount[\"d\"] += 1", "- elif a < 2000:", "- colorCount[\"e\"] += 1", "- elif a < 2400:", "- colorCount[\"f\"] += 1", "- elif a < 2800:", "- colorCount[\"g\"] += 1", "- elif a < 3200:", "- colorCount[\"h\"] += 1", "+ if a >= 3200:", "+ cnt += 1", "- colorCount[\"z\"] += 1", "-minAns = len(colorCount)", "-maxAns = minAns", "-if colorCount[\"z\"] > 0:", "- if minAns == 1:", "- minAns = 1", "- maxAns = colorCount[\"z\"]", "- else:", "- minAns -= 1", "- maxAns = maxAns - 1 + colorCount[\"z\"]", "-print((minAns, maxAns))", "+ ans.add(a // 400)", "+mx = len(ans) + cnt", "+mi = max(1, len(ans))", "+print((mi, mx))" ]
false
0.046549
0.047202
0.986164
[ "s479478724", "s360151884" ]
u350093546
p02819
python
s816232866
s331682045
182
168
38,512
38,512
Accepted
Accepted
7.69
x=int(eval(input())) while True: cnt=0 for i in range(2,x//2): if x%i==0: cnt+=1 break if cnt==0: print(x) break else: x+=1 continue
x=int(eval(input())) while True: cnt=0 for i in range(2,x//2): if x%i==0: cnt+=1 break if cnt==0: print(x) break elif cnt==1: x+=1 continue
13
13
178
186
x = int(eval(input())) while True: cnt = 0 for i in range(2, x // 2): if x % i == 0: cnt += 1 break if cnt == 0: print(x) break else: x += 1 continue
x = int(eval(input())) while True: cnt = 0 for i in range(2, x // 2): if x % i == 0: cnt += 1 break if cnt == 0: print(x) break elif cnt == 1: x += 1 continue
false
0
[ "- else:", "+ elif cnt == 1:" ]
false
0.039118
0.037362
1.047007
[ "s816232866", "s331682045" ]
u498487134
p02792
python
s709799526
s007141211
225
85
40,428
73,352
Accepted
Accepted
62.22
S=eval(input()) TT=[[0]*10 for _ in range(10)] N=int(S) for i in range(1,N+1): ii=str(i) a=int(ii[0]) b=int(ii[-1]) TT[a][b]+=1 ans=0 for i in range(10): for j in range(10): ans+=TT[i][j]*TT[j][i] print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() def ht(x): t=x%10 string=str(x) h=int(string[0]) return (h,t) cnt=[[0]*10 for _ in range(10)] for i in range(1,N+1): h,t=ht(i) cnt[h][t]+=1 ans=0 for i in range(10): for j in range(10): a=cnt[i][j] b=cnt[j][i] ans+=a*b print(ans) main()
16
34
259
636
S = eval(input()) TT = [[0] * 10 for _ in range(10)] N = int(S) for i in range(1, N + 1): ii = str(i) a = int(ii[0]) b = int(ii[-1]) TT[a][b] += 1 ans = 0 for i in range(10): for j in range(10): ans += TT[i][j] * TT[j][i] print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() def ht(x): t = x % 10 string = str(x) h = int(string[0]) return (h, t) cnt = [[0] * 10 for _ in range(10)] for i in range(1, N + 1): h, t = ht(i) cnt[h][t] += 1 ans = 0 for i in range(10): for j in range(10): a = cnt[i][j] b = cnt[j][i] ans += a * b print(ans) main()
false
52.941176
[ "-S = eval(input())", "-TT = [[0] * 10 for _ in range(10)]", "-N = int(S)", "-for i in range(1, N + 1):", "- ii = str(i)", "- a = int(ii[0])", "- b = int(ii[-1])", "- TT[a][b] += 1", "-ans = 0", "-for i in range(10):", "- for j in range(10):", "- ans += TT[i][j] * TT[j][i]", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N = I()", "+", "+ def ht(x):", "+ t = x % 10", "+ string = str(x)", "+ h = int(string[0])", "+ return (h, t)", "+", "+ cnt = [[0] * 10 for _ in range(10)]", "+ for i in range(1, N + 1):", "+ h, t = ht(i)", "+ cnt[h][t] += 1", "+ ans = 0", "+ for i in range(10):", "+ for j in range(10):", "+ a = cnt[i][j]", "+ b = cnt[j][i]", "+ ans += a * b", "+ print(ans)", "+", "+", "+main()" ]
false
0.073111
0.065808
1.110979
[ "s709799526", "s007141211" ]
u668503853
p03147
python
s318888414
s176544832
25
22
3,060
2,940
Accepted
Accepted
12
N=int(eval(input())) h=list(map(int, input().split())) c=i=0 while sum(h)>0: if h[i]>0: j=i c+=1 while j<N and h[j]>0: h[j]-=1 j+=1 else: i+=1 print(c)
N=int(eval(input())) h=[0]+list(map(int,input().split())) c=0 for i in range(N): c+=max(h[i+1]-h[i],0) print(c)
13
6
189
112
N = int(eval(input())) h = list(map(int, input().split())) c = i = 0 while sum(h) > 0: if h[i] > 0: j = i c += 1 while j < N and h[j] > 0: h[j] -= 1 j += 1 else: i += 1 print(c)
N = int(eval(input())) h = [0] + list(map(int, input().split())) c = 0 for i in range(N): c += max(h[i + 1] - h[i], 0) print(c)
false
53.846154
[ "-h = list(map(int, input().split()))", "-c = i = 0", "-while sum(h) > 0:", "- if h[i] > 0:", "- j = i", "- c += 1", "- while j < N and h[j] > 0:", "- h[j] -= 1", "- j += 1", "- else:", "- i += 1", "+h = [0] + list(map(int, input().split()))", "+c = 0", "+for i in range(N):", "+ c += max(h[i + 1] - h[i], 0)" ]
false
0.064208
0.038541
1.665969
[ "s318888414", "s176544832" ]
u600402037
p03329
python
s157221321
s461462547
366
201
3,060
41,584
Accepted
Accepted
45.08
N = int(eval(input())) answer = N for i in range(N+1): count = 0 t = i # i円を6円で払い、残りを9円で払う while t: count += t%6 t //= 6 t = N-i while t: count += t%9 t //= 9 answer = min(answer, count) print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # dp N = ir() INF = 10 ** 8 dp = [INF] * (N+1) dp[0] = 0 for i in range(5, 0, -1): num = 9 ** i for j in range(N): if j+num <= N: dp[j+num] = min(dp[j+num], dp[j]+1) for i in range(6, 0, -1): num = 6 ** i for j in range(N): if j+num <= N: dp[j+num] = min(dp[j+num], dp[j]+1) num = 1 for j in range(N): dp[j+num] = min(dp[j+num], dp[j]+1) answer = dp[N] print(answer)
17
30
273
596
N = int(eval(input())) answer = N for i in range(N + 1): count = 0 t = i # i円を6円で払い、残りを9円で払う while t: count += t % 6 t //= 6 t = N - i while t: count += t % 9 t //= 9 answer = min(answer, count) print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # dp N = ir() INF = 10**8 dp = [INF] * (N + 1) dp[0] = 0 for i in range(5, 0, -1): num = 9**i for j in range(N): if j + num <= N: dp[j + num] = min(dp[j + num], dp[j] + 1) for i in range(6, 0, -1): num = 6**i for j in range(N): if j + num <= N: dp[j + num] = min(dp[j + num], dp[j] + 1) num = 1 for j in range(N): dp[j + num] = min(dp[j + num], dp[j] + 1) answer = dp[N] print(answer)
false
43.333333
[ "-N = int(eval(input()))", "-answer = N", "-for i in range(N + 1):", "- count = 0", "- t = i", "- # i円を6円で払い、残りを9円で払う", "- while t:", "- count += t % 6", "- t //= 6", "- t = N - i", "- while t:", "- count += t % 9", "- t //= 9", "- answer = min(answer, count)", "+# coding: utf-8", "+import sys", "+", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+# dp", "+N = ir()", "+INF = 10**8", "+dp = [INF] * (N + 1)", "+dp[0] = 0", "+for i in range(5, 0, -1):", "+ num = 9**i", "+ for j in range(N):", "+ if j + num <= N:", "+ dp[j + num] = min(dp[j + num], dp[j] + 1)", "+for i in range(6, 0, -1):", "+ num = 6**i", "+ for j in range(N):", "+ if j + num <= N:", "+ dp[j + num] = min(dp[j + num], dp[j] + 1)", "+num = 1", "+for j in range(N):", "+ dp[j + num] = min(dp[j + num], dp[j] + 1)", "+answer = dp[N]" ]
false
0.088418
0.176152
0.501941
[ "s157221321", "s461462547" ]
u085472528
p02412
python
s187238116
s874636364
990
550
7,648
7,712
Accepted
Accepted
44.44
while True: n, x = [int(i) for i in input().split()] if n == x == 0: break count = 0 for s in range(1, n - 1): for m in range(s + 1, n): for e in range(m + 1, n + 1): if x == sum([s, m, e]): count += 1 print(count)
while True: n, x = [int(i) for i in input().split()] if n == x == 0: break count = 0 for s in range(1, n - 1): for m in range(s + 1, n): for e in range(m + 1, n + 1): if x == s + m + e: count += 1 print(count)
14
14
314
309
while True: n, x = [int(i) for i in input().split()] if n == x == 0: break count = 0 for s in range(1, n - 1): for m in range(s + 1, n): for e in range(m + 1, n + 1): if x == sum([s, m, e]): count += 1 print(count)
while True: n, x = [int(i) for i in input().split()] if n == x == 0: break count = 0 for s in range(1, n - 1): for m in range(s + 1, n): for e in range(m + 1, n + 1): if x == s + m + e: count += 1 print(count)
false
0
[ "- if x == sum([s, m, e]):", "+ if x == s + m + e:" ]
false
0.037674
0.038422
0.980541
[ "s187238116", "s874636364" ]
u941438707
p03497
python
s892517174
s785125759
134
94
33,788
33,556
Accepted
Accepted
29.85
n,k,*a=list(map(int,open(0).read().split())) d={} for i in a: d[i]=d.get(i,0)+1 b=list(d.values()) b.sort() print((sum(b[:-k])))
from collections import * _,k,*a = list(map(int,open(0).read().split())) print((sum(sorted(Counter(a).values())[:-k])))
7
3
130
113
n, k, *a = list(map(int, open(0).read().split())) d = {} for i in a: d[i] = d.get(i, 0) + 1 b = list(d.values()) b.sort() print((sum(b[:-k])))
from collections import * _, k, *a = list(map(int, open(0).read().split())) print((sum(sorted(Counter(a).values())[:-k])))
false
57.142857
[ "-n, k, *a = list(map(int, open(0).read().split()))", "-d = {}", "-for i in a:", "- d[i] = d.get(i, 0) + 1", "-b = list(d.values())", "-b.sort()", "-print((sum(b[:-k])))", "+from collections import *", "+", "+_, k, *a = list(map(int, open(0).read().split()))", "+print((sum(sorted(Counter(a).values())[:-k])))" ]
false
0.044206
0.046824
0.944078
[ "s892517174", "s785125759" ]
u729939940
p02701
python
s332681786
s500523935
92
82
39,132
35,588
Accepted
Accepted
10.87
import sys N = int(eval(input())) S = [str(s) for s in sys.stdin.read().split()] print((len(set(S))))
N, *S = open(0) print((len(set(S))))
4
2
96
35
import sys N = int(eval(input())) S = [str(s) for s in sys.stdin.read().split()] print((len(set(S))))
N, *S = open(0) print((len(set(S))))
false
50
[ "-import sys", "-", "-N = int(eval(input()))", "-S = [str(s) for s in sys.stdin.read().split()]", "+N, *S = open(0)" ]
false
0.050425
0.041499
1.215094
[ "s332681786", "s500523935" ]
u531436689
p02881
python
s574927969
s556613648
372
172
70,124
7,112
Accepted
Accepted
53.76
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools def main(): N = int(eval(input())) ans = 10e+12 max_sq = int(math.sqrt(N)+1) for i in range(1, max_sq): if N % i == 0: j = N // i ans = min(ans, i+j-2) print(ans) main()
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools def main(): N = int(eval(input())) ans = N-1 max_sq = int(math.sqrt(N)+1) for i in range(1, max_sq): if N % i != 0: continue j = N // i ans = min(ans, i+j-2) print(ans) main()
12
13
333
343
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools def main(): N = int(eval(input())) ans = 10e12 max_sq = int(math.sqrt(N) + 1) for i in range(1, max_sq): if N % i == 0: j = N // i ans = min(ans, i + j - 2) print(ans) main()
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools def main(): N = int(eval(input())) ans = N - 1 max_sq = int(math.sqrt(N) + 1) for i in range(1, max_sq): if N % i != 0: continue j = N // i ans = min(ans, i + j - 2) print(ans) main()
false
7.692308
[ "- ans = 10e12", "+ ans = N - 1", "- if N % i == 0:", "- j = N // i", "- ans = min(ans, i + j - 2)", "+ if N % i != 0:", "+ continue", "+ j = N // i", "+ ans = min(ans, i + j - 2)" ]
false
0.126127
0.070706
1.783837
[ "s574927969", "s556613648" ]
u934442292
p02960
python
s251626879
s094408177
883
503
125,812
117,940
Accepted
Accepted
43.04
import sys import numba as nb import numpy as np input = sys.stdin.readline P = 10 ** 9 + 7 Q = 13 @nb.njit("i8(i8[:])", cache=True) def solve(S): N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): D = S[i] if D == -1: for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: d = int(D) for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P return dp[N][5] def main(): S = input().rstrip() S = np.array([int(s) if s != "?" else -1 for s in S], dtype=np.int64) ans = solve(S) print(ans) if __name__ == "__main__": main()
import sys import numba as nb import numpy as np input = sys.stdin.readline P = 10 ** 9 + 7 Q = 13 @nb.njit("i8(i8[:])", cache=True) def solve(S): N = len(S) dp = np.zeros(shape=(N + 1, Q), dtype=np.int64) dp[0][0] = 1 for i in range(N): D = S[i] if D == -1: for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: for j in range(Q): dp[i + 1][(10 * j + D) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P return dp[N][5] def main(): S = input().rstrip() S = np.array([int(s) if s != "?" else -1 for s in S], dtype=np.int64) ans = solve(S) print(ans) if __name__ == "__main__": main()
43
42
845
832
import sys import numba as nb import numpy as np input = sys.stdin.readline P = 10**9 + 7 Q = 13 @nb.njit("i8(i8[:])", cache=True) def solve(S): N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): D = S[i] if D == -1: for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: d = int(D) for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P return dp[N][5] def main(): S = input().rstrip() S = np.array([int(s) if s != "?" else -1 for s in S], dtype=np.int64) ans = solve(S) print(ans) if __name__ == "__main__": main()
import sys import numba as nb import numpy as np input = sys.stdin.readline P = 10**9 + 7 Q = 13 @nb.njit("i8(i8[:])", cache=True) def solve(S): N = len(S) dp = np.zeros(shape=(N + 1, Q), dtype=np.int64) dp[0][0] = 1 for i in range(N): D = S[i] if D == -1: for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: for j in range(Q): dp[i + 1][(10 * j + D) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P return dp[N][5] def main(): S = input().rstrip() S = np.array([int(s) if s != "?" else -1 for s in S], dtype=np.int64) ans = solve(S) print(ans) if __name__ == "__main__": main()
false
2.325581
[ "- dp = [[0] * Q for _ in range(N + 1)]", "+ dp = np.zeros(shape=(N + 1, Q), dtype=np.int64)", "- d = int(D)", "- dp[i + 1][(10 * j + d) % Q] += dp[i][j]", "+ dp[i + 1][(10 * j + D) % Q] += dp[i][j]" ]
false
0.041089
0.036907
1.113329
[ "s251626879", "s094408177" ]
u839188633
p02669
python
s856806281
s976714557
550
482
86,936
84,272
Accepted
Accepted
12.36
from heapq import heappop, heappush T = int(input()) ans = [] for _ in range(T): N, A, B, C, D = map(int, input().split()) Q = [(0, N)] # already processed S = set() an = D * N while Q: cost, num = heappop(Q) if num in S: continue an = min(an, cost + num * D) if num == 1: break S.add(num) q, r = divmod(num, 2) if r < 2: heappush(Q, (cost + A + r * D, q)) if r > 0: heappush(Q, (cost + A + (2 - r) * D, q + 1)) q, r = divmod(num, 3) if r < 2: heappush(Q, (cost + B + r * D, q)) if r > 0: heappush(Q, (cost + B + (3 - r) * D, q + 1)) q, r = divmod(num, 5) if r < 3: heappush(Q, (cost + C + r * D, q)) if r > 0: heappush(Q, (cost + C + (5 - r) * D, q + 1)) ans.append(an) print(*ans, sep="\n")
from heapq import heappop, heappush T = int(input()) ans = [] for _ in range(T): N, A, B, C, D = map(int, input().split()) Q = [(0, N)] # already processed S = set() an = D * N while Q: cost, num = heappop(Q) if num in S: continue an = min(an, cost + num * D) if num == 1: break S.add(num) q, r = divmod(num, 2) if r < 2: heappush(Q, (cost + A + r * D, q)) if r > 0: heappush(Q, (cost + A + (2 - r) * D, q + 1)) q, r = divmod(num, 3) if r < 2: heappush(Q, (cost + B + r * D, q)) if r > 1: heappush(Q, (cost + B + (3 - r) * D, q + 1)) q, r = divmod(num, 5) if r < 3: heappush(Q, (cost + C + r * D, q)) if r > 2: heappush(Q, (cost + C + (5 - r) * D, q + 1)) ans.append(an) print(*ans, sep="\n")
40
40
974
974
from heapq import heappop, heappush T = int(input()) ans = [] for _ in range(T): N, A, B, C, D = map(int, input().split()) Q = [(0, N)] # already processed S = set() an = D * N while Q: cost, num = heappop(Q) if num in S: continue an = min(an, cost + num * D) if num == 1: break S.add(num) q, r = divmod(num, 2) if r < 2: heappush(Q, (cost + A + r * D, q)) if r > 0: heappush(Q, (cost + A + (2 - r) * D, q + 1)) q, r = divmod(num, 3) if r < 2: heappush(Q, (cost + B + r * D, q)) if r > 0: heappush(Q, (cost + B + (3 - r) * D, q + 1)) q, r = divmod(num, 5) if r < 3: heappush(Q, (cost + C + r * D, q)) if r > 0: heappush(Q, (cost + C + (5 - r) * D, q + 1)) ans.append(an) print(*ans, sep="\n")
from heapq import heappop, heappush T = int(input()) ans = [] for _ in range(T): N, A, B, C, D = map(int, input().split()) Q = [(0, N)] # already processed S = set() an = D * N while Q: cost, num = heappop(Q) if num in S: continue an = min(an, cost + num * D) if num == 1: break S.add(num) q, r = divmod(num, 2) if r < 2: heappush(Q, (cost + A + r * D, q)) if r > 0: heappush(Q, (cost + A + (2 - r) * D, q + 1)) q, r = divmod(num, 3) if r < 2: heappush(Q, (cost + B + r * D, q)) if r > 1: heappush(Q, (cost + B + (3 - r) * D, q + 1)) q, r = divmod(num, 5) if r < 3: heappush(Q, (cost + C + r * D, q)) if r > 2: heappush(Q, (cost + C + (5 - r) * D, q + 1)) ans.append(an) print(*ans, sep="\n")
false
0
[ "- if r > 0:", "+ if r > 1:", "- if r > 0:", "+ if r > 2:" ]
false
0.205985
0.144002
1.430433
[ "s856806281", "s976714557" ]
u922449550
p03305
python
s081920053
s482430209
1,453
1,235
123,900
87,300
Accepted
Accepted
15
from heapq import heappush, heappop money = 10**15 N, M, s, t = map(int, input().split()) s -= 1; t -= 1 graph = [[[] for i in range(N)] for _ in range(2)] for i in range(M): u, v, a, b = map(int, input().split()) u -= 1; v -= 1 graph[0][u].append((v, a)); graph[0][v].append((u, a)) graph[1][u].append((v, b)); graph[1][v].append((u, b)) def dijkstra(s, mode): dist = [-1] * N dist[s] = 0 e = [] for child, cost in graph[mode][s]: heappush(e, (cost, child)) while e: cost, node = heappop(e) if dist[node] >= 0: continue dist[node] = cost for child, c in graph[mode][node]: if dist[child] >= 0: continue heappush(e, (cost+c, child)) return dist dist = [dijkstra(s, 0), dijkstra(t, 1)] value = [dist[0][i]+dist[1][i] for i in range(N)] ans = [] cost = [] for i in range(N-1, -1, -1): heappush(cost, value[i]) ans.append(money - cost[0]) print(*(ans[::-1]), sep='\n')
from heapq import heappush, heappop import sys input = sys.stdin.readline money = 10**15 N, M, s, t = map(int, input().split()) s -= 1; t -= 1 graph = [[[] for i in range(N)] for _ in range(2)] for i in range(M): u, v, a, b = map(int, input().split()) u -= 1; v -= 1 graph[0][u].append((v, a)); graph[0][v].append((u, a)) graph[1][u].append((v, b)); graph[1][v].append((u, b)) def dijkstra(s, mode): dist = [-1] * N dist[s] = 0 e = [] for child, cost in graph[mode][s]: heappush(e, (cost, child)) while e: cost, node = heappop(e) if dist[node] >= 0: continue dist[node] = cost for child, c in graph[mode][node]: if dist[child] >= 0: continue heappush(e, (cost+c, child)) return dist dist = [dijkstra(s, 0), dijkstra(t, 1)] value = [dist[0][i]+dist[1][i] for i in range(N)] ans = [] cost = [] for i in range(N-1, -1, -1): heappush(cost, value[i]) ans.append(money - cost[0]) print(*(ans[::-1]), sep='\n')
40
42
984
1,024
from heapq import heappush, heappop money = 10**15 N, M, s, t = map(int, input().split()) s -= 1 t -= 1 graph = [[[] for i in range(N)] for _ in range(2)] for i in range(M): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 graph[0][u].append((v, a)) graph[0][v].append((u, a)) graph[1][u].append((v, b)) graph[1][v].append((u, b)) def dijkstra(s, mode): dist = [-1] * N dist[s] = 0 e = [] for child, cost in graph[mode][s]: heappush(e, (cost, child)) while e: cost, node = heappop(e) if dist[node] >= 0: continue dist[node] = cost for child, c in graph[mode][node]: if dist[child] >= 0: continue heappush(e, (cost + c, child)) return dist dist = [dijkstra(s, 0), dijkstra(t, 1)] value = [dist[0][i] + dist[1][i] for i in range(N)] ans = [] cost = [] for i in range(N - 1, -1, -1): heappush(cost, value[i]) ans.append(money - cost[0]) print(*(ans[::-1]), sep="\n")
from heapq import heappush, heappop import sys input = sys.stdin.readline money = 10**15 N, M, s, t = map(int, input().split()) s -= 1 t -= 1 graph = [[[] for i in range(N)] for _ in range(2)] for i in range(M): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 graph[0][u].append((v, a)) graph[0][v].append((u, a)) graph[1][u].append((v, b)) graph[1][v].append((u, b)) def dijkstra(s, mode): dist = [-1] * N dist[s] = 0 e = [] for child, cost in graph[mode][s]: heappush(e, (cost, child)) while e: cost, node = heappop(e) if dist[node] >= 0: continue dist[node] = cost for child, c in graph[mode][node]: if dist[child] >= 0: continue heappush(e, (cost + c, child)) return dist dist = [dijkstra(s, 0), dijkstra(t, 1)] value = [dist[0][i] + dist[1][i] for i in range(N)] ans = [] cost = [] for i in range(N - 1, -1, -1): heappush(cost, value[i]) ans.append(money - cost[0]) print(*(ans[::-1]), sep="\n")
false
4.761905
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.038187
0.037758
1.011351
[ "s081920053", "s482430209" ]
u102461423
p02957
python
s142554424
s850468977
304
18
536,644
2,940
Accepted
Accepted
94.08
import numpy as np A = np.arange(1<<27,dtype=np.int32) a,b = list(map(int,input().split())) if (a-b) % 2 == 0: print(((a+b)//2)) else: print('IMPOSSIBLE')
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A,B = list(map(int,read().split())) q,r = divmod(A+B,2) if r == 1: print('IMPOSSIBLE') else: print(q)
9
13
161
234
import numpy as np A = np.arange(1 << 27, dtype=np.int32) a, b = list(map(int, input().split())) if (a - b) % 2 == 0: print(((a + b) // 2)) else: print("IMPOSSIBLE")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A, B = list(map(int, read().split())) q, r = divmod(A + B, 2) if r == 1: print("IMPOSSIBLE") else: print(q)
false
30.769231
[ "-import numpy as np", "+import sys", "-A = np.arange(1 << 27, dtype=np.int32)", "-a, b = list(map(int, input().split()))", "-if (a - b) % 2 == 0:", "- print(((a + b) // 2))", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+A, B = list(map(int, read().split()))", "+q, r = divmod(A + B, 2)", "+if r == 1:", "+ print(\"IMPOSSIBLE\")", "- print(\"IMPOSSIBLE\")", "+ print(q)" ]
false
0.338155
0.035829
9.438125
[ "s142554424", "s850468977" ]
u562935282
p02972
python
s928418824
s028489706
479
268
14,132
13,224
Accepted
Accepted
44.05
def main(): N = int(input()) a = [0] a += map(int, input().split()) b = [0] * (N + 1) x = N k = 1 while x > 0: while x * (k + 1) > N: t = 0 for j in range(2, k + 1): t ^= b[x * j] b[x] = a[x] ^ t x -= 1 k += 1 ans = [i for i, x in enumerate(b) if x == 1] print(len(ans)) print(*ans, sep='\n') if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): from functools import reduce from operator import xor N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = reduce(xor, a[x::x]) ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep='\n') if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
43
38
833
784
def main(): N = int(input()) a = [0] a += map(int, input().split()) b = [0] * (N + 1) x = N k = 1 while x > 0: while x * (k + 1) > N: t = 0 for j in range(2, k + 1): t ^= b[x * j] b[x] = a[x] ^ t x -= 1 k += 1 ans = [i for i, x in enumerate(b) if x == 1] print(len(ans)) print(*ans, sep="\n") if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
# https://atcoder.jp/contests/abc134/submissions/7469219 def main(): from functools import reduce from operator import xor N = int(input()) a = [0] a += map(int, input().split()) for x in reversed(range(1, N // 2 + 1)): a[x] = reduce(xor, a[x::x]) ans = [i for i, x in enumerate(a) if x] print(len(ans)) print(*ans, sep="\n") if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
false
11.627907
[ "+# https://atcoder.jp/contests/abc134/submissions/7469219", "+ from functools import reduce", "+ from operator import xor", "+", "- b = [0] * (N + 1)", "- x = N", "- k = 1", "- while x > 0:", "- while x * (k + 1) > N:", "- t = 0", "- for j in range(2, k + 1):", "- t ^= b[x * j]", "- b[x] = a[x] ^ t", "- x -= 1", "- k += 1", "- ans = [i for i, x in enumerate(b) if x == 1]", "+ for x in reversed(range(1, N // 2 + 1)):", "+ a[x] = reduce(xor, a[x::x])", "+ ans = [i for i, x in enumerate(a) if x]" ]
false
0.036164
0.042441
0.852099
[ "s928418824", "s028489706" ]
u022979415
p02918
python
s386660897
s632379999
61
45
4,084
3,956
Accepted
Accepted
26.23
def main(): length, operation = list(map(int, input().split())) direction = list(eval(input())) before = "" inverse = {"L": "R", "R": "L"} change = 0 section = 0 answer = 0 for i in range(length): if not before == direction[i]: before = direction[i] section += 1 if section % 2: change += 1 if section % 2 == 0 and change <= operation: direction[i] = inverse[direction[i]] for i in range(1, length): if direction[i] == direction[i - 1]: answer += 1 print(answer) if __name__ == '__main__': main()
def main(): n, k = list(map(int, input().split())) s = list("*" + eval(input()) + "*") count = 0 for i in range(1, n + 1): if (s[i] == s[i - 1] == "L") or (s[i] == s[i + 1] == "R"): count += 1 print((min(count + 2 * k, n - 1))) if __name__ == '__main__': main()
25
13
656
307
def main(): length, operation = list(map(int, input().split())) direction = list(eval(input())) before = "" inverse = {"L": "R", "R": "L"} change = 0 section = 0 answer = 0 for i in range(length): if not before == direction[i]: before = direction[i] section += 1 if section % 2: change += 1 if section % 2 == 0 and change <= operation: direction[i] = inverse[direction[i]] for i in range(1, length): if direction[i] == direction[i - 1]: answer += 1 print(answer) if __name__ == "__main__": main()
def main(): n, k = list(map(int, input().split())) s = list("*" + eval(input()) + "*") count = 0 for i in range(1, n + 1): if (s[i] == s[i - 1] == "L") or (s[i] == s[i + 1] == "R"): count += 1 print((min(count + 2 * k, n - 1))) if __name__ == "__main__": main()
false
48
[ "- length, operation = list(map(int, input().split()))", "- direction = list(eval(input()))", "- before = \"\"", "- inverse = {\"L\": \"R\", \"R\": \"L\"}", "- change = 0", "- section = 0", "- answer = 0", "- for i in range(length):", "- if not before == direction[i]:", "- before = direction[i]", "- section += 1", "- if section % 2:", "- change += 1", "- if section % 2 == 0 and change <= operation:", "- direction[i] = inverse[direction[i]]", "- for i in range(1, length):", "- if direction[i] == direction[i - 1]:", "- answer += 1", "- print(answer)", "+ n, k = list(map(int, input().split()))", "+ s = list(\"*\" + eval(input()) + \"*\")", "+ count = 0", "+ for i in range(1, n + 1):", "+ if (s[i] == s[i - 1] == \"L\") or (s[i] == s[i + 1] == \"R\"):", "+ count += 1", "+ print((min(count + 2 * k, n - 1)))" ]
false
0.007484
0.153119
0.048877
[ "s386660897", "s632379999" ]
u326609687
p02579
python
s522324935
s272156176
512
151
114,476
35,592
Accepted
Accepted
70.51
import numpy as np from numba import njit, int32, int64 i4 = np.int32 i8 = np.int64 INF = 1000000000 @njit((int32[:,:], int64, int64), cache=True) def solve(s, ch, cw): H = s.shape[0] W = s.shape[1] - 1 ah = H + 4 aw = W + 4 a = np.full((ah, aw), -1, i4) for i in range(H): for j in range(W): if s[i, j] == 46: a[i + 2, j + 2] = INF sh1 = np.empty(1000000, i4) sw1 = np.empty(1000000, i4) p1 = 0 sh2 = np.empty(1000000, i4) sw2 = np.empty(1000000, i4) p2 = 0 dis = 0 a[ch + 1, cw + 1] = dis sh1[p1] = ch + 1 sw1[p1] = cw + 1 p1 += 1 while True: while p1 > 0: p1 -= 1 h = sh1[p1] w = sw1[p1] for i in range(-2, 3): for j in range(-2, 3): if ((i == 1 or i == -1) and j == 0) or (i == 0 and (j == 1 or j == -1)): if a[h + i, w + j] > dis: a[h + i, w + j] = dis sh1[p1] = h + i sw1[p1] = w + j p1 += 1 else: if a[h + i, w + j] > dis + 1: a[h + i, w + j] = dis + 1 sh2[p2] = h + i sw2[p2] = w + j p2 += 1 dis += 1 for i in range(p2): if a[sh2[i], sw2[i]] == dis: sh1[p1] = sh2[i] sw1[p1] = sw2[i] p1 += 1 p2 = 0 if p1 == 0: break return a def main(in_file): stdin = open(in_file) H, W = [int(x) for x in stdin.readline().split()] ch, cw = [int(x) for x in stdin.readline().split()] dh, dw = [int(x) for x in stdin.readline().split()] s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1)) a = solve(s, ch, cw) ans = a[dh + 1, dw + 1] if ans == INF: print((-1)) else: print(ans) main('/dev/stdin')
import numpy as np i4 = np.int32 i8 = np.int64 INF = 1000000000 def solve(s, ch, cw): H = s.shape[0] W = s.shape[1] - 1 ah = H + 4 aw = W + 4 a = np.full((ah, aw), -1, i4) for i in range(H): for j in range(W): if s[i, j] == 46: a[i + 2, j + 2] = INF sh1 = np.empty(1000000, i4) sw1 = np.empty(1000000, i4) p1 = 0 sh2 = np.empty(1000000, i4) sw2 = np.empty(1000000, i4) p2 = 0 dis = 0 a[ch + 1, cw + 1] = dis sh1[p1] = ch + 1 sw1[p1] = cw + 1 p1 += 1 while True: while p1 > 0: p1 -= 1 h = sh1[p1] w = sw1[p1] for i in range(-2, 3): for j in range(-2, 3): if ((i == 1 or i == -1) and j == 0) or (i == 0 and (j == 1 or j == -1)): if a[h + i, w + j] > dis: a[h + i, w + j] = dis sh1[p1] = h + i sw1[p1] = w + j p1 += 1 else: if a[h + i, w + j] > dis + 1: a[h + i, w + j] = dis + 1 sh2[p2] = h + i sw2[p2] = w + j p2 += 1 dis += 1 for i in range(p2): if a[sh2[i], sw2[i]] == dis: sh1[p1] = sh2[i] sw1[p1] = sw2[i] p1 += 1 p2 = 0 if p1 == 0: break return a def main(in_file): stdin = open(in_file) H, W = [int(x) for x in stdin.readline().split()] ch, cw = [int(x) for x in stdin.readline().split()] dh, dw = [int(x) for x in stdin.readline().split()] s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1)) a = solve(s, ch, cw) ans = a[dh + 1, dw + 1] if ans == INF: print((-1)) else: print(ans) def cc_export(): from numba.pycc import CC from numba import int32, int64 cc = CC('my_module') cc.export('solve', (int32[:,:], int64, int64))(solve) cc.compile() if __name__ == '__main__': import sys if sys.argv[-1] == 'ONLINE_JUDGE': cc_export() exit(0) from my_module import solve main('/dev/stdin')
83
95
2,149
2,415
import numpy as np from numba import njit, int32, int64 i4 = np.int32 i8 = np.int64 INF = 1000000000 @njit((int32[:, :], int64, int64), cache=True) def solve(s, ch, cw): H = s.shape[0] W = s.shape[1] - 1 ah = H + 4 aw = W + 4 a = np.full((ah, aw), -1, i4) for i in range(H): for j in range(W): if s[i, j] == 46: a[i + 2, j + 2] = INF sh1 = np.empty(1000000, i4) sw1 = np.empty(1000000, i4) p1 = 0 sh2 = np.empty(1000000, i4) sw2 = np.empty(1000000, i4) p2 = 0 dis = 0 a[ch + 1, cw + 1] = dis sh1[p1] = ch + 1 sw1[p1] = cw + 1 p1 += 1 while True: while p1 > 0: p1 -= 1 h = sh1[p1] w = sw1[p1] for i in range(-2, 3): for j in range(-2, 3): if ((i == 1 or i == -1) and j == 0) or ( i == 0 and (j == 1 or j == -1) ): if a[h + i, w + j] > dis: a[h + i, w + j] = dis sh1[p1] = h + i sw1[p1] = w + j p1 += 1 else: if a[h + i, w + j] > dis + 1: a[h + i, w + j] = dis + 1 sh2[p2] = h + i sw2[p2] = w + j p2 += 1 dis += 1 for i in range(p2): if a[sh2[i], sw2[i]] == dis: sh1[p1] = sh2[i] sw1[p1] = sw2[i] p1 += 1 p2 = 0 if p1 == 0: break return a def main(in_file): stdin = open(in_file) H, W = [int(x) for x in stdin.readline().split()] ch, cw = [int(x) for x in stdin.readline().split()] dh, dw = [int(x) for x in stdin.readline().split()] s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1)) a = solve(s, ch, cw) ans = a[dh + 1, dw + 1] if ans == INF: print((-1)) else: print(ans) main("/dev/stdin")
import numpy as np i4 = np.int32 i8 = np.int64 INF = 1000000000 def solve(s, ch, cw): H = s.shape[0] W = s.shape[1] - 1 ah = H + 4 aw = W + 4 a = np.full((ah, aw), -1, i4) for i in range(H): for j in range(W): if s[i, j] == 46: a[i + 2, j + 2] = INF sh1 = np.empty(1000000, i4) sw1 = np.empty(1000000, i4) p1 = 0 sh2 = np.empty(1000000, i4) sw2 = np.empty(1000000, i4) p2 = 0 dis = 0 a[ch + 1, cw + 1] = dis sh1[p1] = ch + 1 sw1[p1] = cw + 1 p1 += 1 while True: while p1 > 0: p1 -= 1 h = sh1[p1] w = sw1[p1] for i in range(-2, 3): for j in range(-2, 3): if ((i == 1 or i == -1) and j == 0) or ( i == 0 and (j == 1 or j == -1) ): if a[h + i, w + j] > dis: a[h + i, w + j] = dis sh1[p1] = h + i sw1[p1] = w + j p1 += 1 else: if a[h + i, w + j] > dis + 1: a[h + i, w + j] = dis + 1 sh2[p2] = h + i sw2[p2] = w + j p2 += 1 dis += 1 for i in range(p2): if a[sh2[i], sw2[i]] == dis: sh1[p1] = sh2[i] sw1[p1] = sw2[i] p1 += 1 p2 = 0 if p1 == 0: break return a def main(in_file): stdin = open(in_file) H, W = [int(x) for x in stdin.readline().split()] ch, cw = [int(x) for x in stdin.readline().split()] dh, dw = [int(x) for x in stdin.readline().split()] s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1)) a = solve(s, ch, cw) ans = a[dh + 1, dw + 1] if ans == INF: print((-1)) else: print(ans) def cc_export(): from numba.pycc import CC from numba import int32, int64 cc = CC("my_module") cc.export("solve", (int32[:, :], int64, int64))(solve) cc.compile() if __name__ == "__main__": import sys if sys.argv[-1] == "ONLINE_JUDGE": cc_export() exit(0) from my_module import solve main("/dev/stdin")
false
12.631579
[ "-from numba import njit, int32, int64", "-@njit((int32[:, :], int64, int64), cache=True)", "-main(\"/dev/stdin\")", "+def cc_export():", "+ from numba.pycc import CC", "+ from numba import int32, int64", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"solve\", (int32[:, :], int64, int64))(solve)", "+ cc.compile()", "+", "+", "+if __name__ == \"__main__\":", "+ import sys", "+", "+ if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ cc_export()", "+ exit(0)", "+ from my_module import solve", "+", "+ main(\"/dev/stdin\")" ]
false
0.435398
0.188171
2.313844
[ "s522324935", "s272156176" ]
u203843959
p03219
python
s698549516
s928512667
20
17
2,940
2,940
Accepted
Accepted
15
X,Y=list(map(int,input().split())) print((X+Y//2))
print((sum([int(x)//(i+1) for i,x in enumerate(input().split())])))
2
1
43
65
X, Y = list(map(int, input().split())) print((X + Y // 2))
print((sum([int(x) // (i + 1) for i, x in enumerate(input().split())])))
false
50
[ "-X, Y = list(map(int, input().split()))", "-print((X + Y // 2))", "+print((sum([int(x) // (i + 1) for i, x in enumerate(input().split())])))" ]
false
0.059746
0.04523
1.320939
[ "s698549516", "s928512667" ]
u054514819
p02787
python
s399361378
s693905935
1,680
455
3,572
43,100
Accepted
Accepted
72.92
H, N = list(map(int, input().split())) magics = [] for _ in range(N): a, b = list(map(int, input().split())) magics.append([a, b]) max_a = max(a for a, _ in magics) dp = [0]*(H+max_a) for i in range(1, H+max_a): dp[i] = min(dp[i-a]+b for a, b in magics) print((min(dp[H:])))
H, N = list(map(int, input().split())) magics = [tuple(map(int, input().split())) for _ in range(N)] maxA = max([x for x, y in magics]) dp = [10**18]*(H+maxA+1) dp[0] = 0 for i in range(1, H+maxA+1): for j in range(N): a, b = magics[j] if a<=i: dp[i] = min(dp[i-a]+b, dp[i]) print((min(dp[H:])))
10
14
275
335
H, N = list(map(int, input().split())) magics = [] for _ in range(N): a, b = list(map(int, input().split())) magics.append([a, b]) max_a = max(a for a, _ in magics) dp = [0] * (H + max_a) for i in range(1, H + max_a): dp[i] = min(dp[i - a] + b for a, b in magics) print((min(dp[H:])))
H, N = list(map(int, input().split())) magics = [tuple(map(int, input().split())) for _ in range(N)] maxA = max([x for x, y in magics]) dp = [10**18] * (H + maxA + 1) dp[0] = 0 for i in range(1, H + maxA + 1): for j in range(N): a, b = magics[j] if a <= i: dp[i] = min(dp[i - a] + b, dp[i]) print((min(dp[H:])))
false
28.571429
[ "-magics = []", "-for _ in range(N):", "- a, b = list(map(int, input().split()))", "- magics.append([a, b])", "-max_a = max(a for a, _ in magics)", "-dp = [0] * (H + max_a)", "-for i in range(1, H + max_a):", "- dp[i] = min(dp[i - a] + b for a, b in magics)", "+magics = [tuple(map(int, input().split())) for _ in range(N)]", "+maxA = max([x for x, y in magics])", "+dp = [10**18] * (H + maxA + 1)", "+dp[0] = 0", "+for i in range(1, H + maxA + 1):", "+ for j in range(N):", "+ a, b = magics[j]", "+ if a <= i:", "+ dp[i] = min(dp[i - a] + b, dp[i])" ]
false
0.051242
0.084151
0.608932
[ "s399361378", "s693905935" ]
u525065967
p02612
python
s405012442
s514016174
31
23
8,956
9,028
Accepted
Accepted
25.81
r = 1000 - int(eval(input())) % 1000 print((r if r < 1000 else 0))
print(((1000 - int(eval(input())) % 1000) % 1000))
2
1
60
43
r = 1000 - int(eval(input())) % 1000 print((r if r < 1000 else 0))
print(((1000 - int(eval(input())) % 1000) % 1000))
false
50
[ "-r = 1000 - int(eval(input())) % 1000", "-print((r if r < 1000 else 0))", "+print(((1000 - int(eval(input())) % 1000) % 1000))" ]
false
0.03569
0.034681
1.029092
[ "s405012442", "s514016174" ]
u466116762
p02886
python
s128108561
s453052852
191
169
39,280
38,896
Accepted
Accepted
11.52
import itertools N=int(eval(input())) d_list=[int(i) for i in input().split()] comb = list(itertools.combinations(d_list, 2)) sum_heal = 0 for i,j in comb: sum_heal += i*j print(sum_heal)
N=int(eval(input())) d_list=[int(i) for i in input().split()] sum_heal = 0 for i in range(N): for j in range(i+1, N): sum_heal += d_list[i]*d_list[j] print(sum_heal)
8
7
192
178
import itertools N = int(eval(input())) d_list = [int(i) for i in input().split()] comb = list(itertools.combinations(d_list, 2)) sum_heal = 0 for i, j in comb: sum_heal += i * j print(sum_heal)
N = int(eval(input())) d_list = [int(i) for i in input().split()] sum_heal = 0 for i in range(N): for j in range(i + 1, N): sum_heal += d_list[i] * d_list[j] print(sum_heal)
false
12.5
[ "-import itertools", "-", "-comb = list(itertools.combinations(d_list, 2))", "-for i, j in comb:", "- sum_heal += i * j", "+for i in range(N):", "+ for j in range(i + 1, N):", "+ sum_heal += d_list[i] * d_list[j]" ]
false
0.045452
0.045258
1.004275
[ "s128108561", "s453052852" ]
u334712262
p02803
python
s991312130
s652722329
891
449
63,852
72,408
Accepted
Accepted
49.61
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def warshall_floyd(g, N): d = g for k in range(N): for i in range(N): for j in range(N): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] return d @mt def slv(H, W, S): ans = 0 g = [[INF] *(H*W) for _ in range(H*W)] def idx(i, j): return i*W + j for i in range(H): for j in range(W): if S[i][j] != '.': continue if i > 0 and S[i-1][j] == '.': g[idx(i, j)][idx(i-1, j)] = 1 if i < H-1 and S[i+1][j] == '.': g[idx(i, j)][idx(i+1, j)] = 1 if j > 0 and S[i][j-1] == '.': g[idx(i, j)][idx(i, j-1)] = 1 if j < W-1 and S[i][j+1] == '.': g[idx(i, j)][idx(i, j+1)] = 1 d = warshall_floyd(g, W*H) ans = 0 for i, r in enumerate(d): for j, v in enumerate(r): if v != INF and i != j: ans = max(ans, v) return ans def main(): H, W = read_int_n() S = [read_str() for _ in range(H)] # H = 20 # W = 20 # S = ['.'*W]*H print(slv(H, W, S)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(H, W, S): def edges(v): i, j = v r = [] if i > 0 and S[i-1][j] == '.': r.append((i-1, j)) if i < H-1 and S[i+1][j] == '.': r.append((i+1, j)) if j > 0 and S[i][j-1] == '.': r.append((i, j-1)) if j < W-1 and S[i][j+1] == '.': r.append((i, j+1)) return r def bfs(s): q = deque([s]) d = {s: 0} while q: u = q.popleft() for v in edges(u): if v not in d: d[v] = d[u] + 1 q.append(v) return max(d.values()) ans = 0 for i in range(H): for j in range(W): if S[i][j] == '.': l = bfs((i, j)) ans = max(ans, l) return ans def main(): H, W = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, S)) if __name__ == '__main__': main()
113
106
2,345
2,098
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def warshall_floyd(g, N): d = g for k in range(N): for i in range(N): for j in range(N): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] return d @mt def slv(H, W, S): ans = 0 g = [[INF] * (H * W) for _ in range(H * W)] def idx(i, j): return i * W + j for i in range(H): for j in range(W): if S[i][j] != ".": continue if i > 0 and S[i - 1][j] == ".": g[idx(i, j)][idx(i - 1, j)] = 1 if i < H - 1 and S[i + 1][j] == ".": g[idx(i, j)][idx(i + 1, j)] = 1 if j > 0 and S[i][j - 1] == ".": g[idx(i, j)][idx(i, j - 1)] = 1 if j < W - 1 and S[i][j + 1] == ".": g[idx(i, j)][idx(i, j + 1)] = 1 d = warshall_floyd(g, W * H) ans = 0 for i, r in enumerate(d): for j, v in enumerate(r): if v != INF and i != j: ans = max(ans, v) return ans def main(): H, W = read_int_n() S = [read_str() for _ in range(H)] # H = 20 # W = 20 # S = ['.'*W]*H print(slv(H, W, S)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(H, W, S): def edges(v): i, j = v r = [] if i > 0 and S[i - 1][j] == ".": r.append((i - 1, j)) if i < H - 1 and S[i + 1][j] == ".": r.append((i + 1, j)) if j > 0 and S[i][j - 1] == ".": r.append((i, j - 1)) if j < W - 1 and S[i][j + 1] == ".": r.append((i, j + 1)) return r def bfs(s): q = deque([s]) d = {s: 0} while q: u = q.popleft() for v in edges(u): if v not in d: d[v] = d[u] + 1 q.append(v) return max(d.values()) ans = 0 for i in range(H): for j in range(W): if S[i][j] == ".": l = bfs((i, j)) ans = max(ans, l) return ans def main(): H, W = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, S)) if __name__ == "__main__": main()
false
6.19469
[ "-def warshall_floyd(g, N):", "- d = g", "- for k in range(N):", "- for i in range(N):", "- for j in range(N):", "- if d[i][j] > d[i][k] + d[k][j]:", "- d[i][j] = d[i][k] + d[k][j]", "- return d", "-", "-", "+ def edges(v):", "+ i, j = v", "+ r = []", "+ if i > 0 and S[i - 1][j] == \".\":", "+ r.append((i - 1, j))", "+ if i < H - 1 and S[i + 1][j] == \".\":", "+ r.append((i + 1, j))", "+ if j > 0 and S[i][j - 1] == \".\":", "+ r.append((i, j - 1))", "+ if j < W - 1 and S[i][j + 1] == \".\":", "+ r.append((i, j + 1))", "+ return r", "+", "+ def bfs(s):", "+ q = deque([s])", "+ d = {s: 0}", "+ while q:", "+ u = q.popleft()", "+ for v in edges(u):", "+ if v not in d:", "+ d[v] = d[u] + 1", "+ q.append(v)", "+ return max(d.values())", "+", "- g = [[INF] * (H * W) for _ in range(H * W)]", "-", "- def idx(i, j):", "- return i * W + j", "-", "- if S[i][j] != \".\":", "- continue", "- if i > 0 and S[i - 1][j] == \".\":", "- g[idx(i, j)][idx(i - 1, j)] = 1", "- if i < H - 1 and S[i + 1][j] == \".\":", "- g[idx(i, j)][idx(i + 1, j)] = 1", "- if j > 0 and S[i][j - 1] == \".\":", "- g[idx(i, j)][idx(i, j - 1)] = 1", "- if j < W - 1 and S[i][j + 1] == \".\":", "- g[idx(i, j)][idx(i, j + 1)] = 1", "- d = warshall_floyd(g, W * H)", "- ans = 0", "- for i, r in enumerate(d):", "- for j, v in enumerate(r):", "- if v != INF and i != j:", "- ans = max(ans, v)", "+ if S[i][j] == \".\":", "+ l = bfs((i, j))", "+ ans = max(ans, l)", "- # H = 20", "- # W = 20", "- # S = ['.'*W]*H" ]
false
0.043738
0.036274
1.205767
[ "s991312130", "s652722329" ]
u581187895
p02911
python
s340970213
s982624467
250
129
8,244
8,228
Accepted
Accepted
48.4
N, K, Q = map(int, input().split()) score = [K-Q]*(N+1) for _ in range(Q): a = int(input()) score[a] += 1 [print("No" if ans < 1 else "Yes") for ans in score[1:]]
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, K, Q = map(int, input().split()) score = [K-Q]*(N+1) for _ in range(Q): a = int(input()) score[a] += 1 [print("No" if ans < 1 else "Yes") for ans in score[1:]]
7
10
173
245
N, K, Q = map(int, input().split()) score = [K - Q] * (N + 1) for _ in range(Q): a = int(input()) score[a] += 1 [print("No" if ans < 1 else "Yes") for ans in score[1:]]
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, K, Q = map(int, input().split()) score = [K - Q] * (N + 1) for _ in range(Q): a = int(input()) score[a] += 1 [print("No" if ans < 1 else "Yes") for ans in score[1:]]
false
30
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)" ]
false
0.036192
0.074625
0.484988
[ "s340970213", "s982624467" ]
u814663076
p03162
python
s701159055
s231792190
627
482
74,072
82,904
Accepted
Accepted
23.13
N = int(eval(input())) data = [[int(i) for i in input().split()] for _ in range(N)] dp = [[0] * 3 for _ in range(N)] dp[0] = data[0] for i in range(1, N): for j in range(3): dp[i][j] = data[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) print((max(dp[N-1])))
# region header import sys import math from bisect import bisect_left, bisect_right, insort_left, insort_right from collections import defaultdict, deque, Counter from copy import deepcopy from fractions import gcd from functools import lru_cache, reduce from heapq import heappop, heappush from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement from math import ceil, floor, factorial, log, sqrt, sin, cos from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, digits sys.setrecursionlimit(10**6) INF = float('inf') MOD = 10 ** 9 + 7 def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rf(): return float(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] def rf_(): return [float(_) for _ in rs().split()] def divisors(n, sortresult=True): div = [] for i in range(1, int(n**0.5)+1): if n % i == 0: div.append(i) if i != n // i: div.append(n//i) if sortresult: div.sort() return div # endregion N = ri() a = [0] * N b = [0] * N c = [0] * N for i in range(N): a[i], b[i], c[i] = ri_() dp = [[0] * 3 for _ in range(N)] dp[0][0] = a[0] dp[0][1] = b[0] dp[0][2] = c[0] for i in range(1, N): dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i] dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i] dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i] print((max(dp[N - 1])))
10
48
274
1,553
N = int(eval(input())) data = [[int(i) for i in input().split()] for _ in range(N)] dp = [[0] * 3 for _ in range(N)] dp[0] = data[0] for i in range(1, N): for j in range(3): dp[i][j] = data[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) print((max(dp[N - 1])))
# region header import sys import math from bisect import bisect_left, bisect_right, insort_left, insort_right from collections import defaultdict, deque, Counter from copy import deepcopy from fractions import gcd from functools import lru_cache, reduce from heapq import heappop, heappush from itertools import ( accumulate, groupby, product, permutations, combinations, combinations_with_replacement, ) from math import ceil, floor, factorial, log, sqrt, sin, cos from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, digits sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rf(): return float(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] def rf_(): return [float(_) for _ in rs().split()] def divisors(n, sortresult=True): div = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: div.append(i) if i != n // i: div.append(n // i) if sortresult: div.sort() return div # endregion N = ri() a = [0] * N b = [0] * N c = [0] * N for i in range(N): a[i], b[i], c[i] = ri_() dp = [[0] * 3 for _ in range(N)] dp[0][0] = a[0] dp[0][1] = b[0] dp[0][2] = c[0] for i in range(1, N): dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i] dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i] dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i] print((max(dp[N - 1])))
false
79.166667
[ "-N = int(eval(input()))", "-data = [[int(i) for i in input().split()] for _ in range(N)]", "+# region header", "+import sys", "+import math", "+from bisect import bisect_left, bisect_right, insort_left, insort_right", "+from collections import defaultdict, deque, Counter", "+from copy import deepcopy", "+from fractions import gcd", "+from functools import lru_cache, reduce", "+from heapq import heappop, heappush", "+from itertools import (", "+ accumulate,", "+ groupby,", "+ product,", "+ permutations,", "+ combinations,", "+ combinations_with_replacement,", "+)", "+from math import ceil, floor, factorial, log, sqrt, sin, cos", "+from operator import itemgetter", "+from string import ascii_lowercase, ascii_uppercase, digits", "+", "+sys.setrecursionlimit(10**6)", "+INF = float(\"inf\")", "+MOD = 10**9 + 7", "+", "+", "+def rs():", "+ return sys.stdin.readline().rstrip()", "+", "+", "+def ri():", "+ return int(rs())", "+", "+", "+def rf():", "+ return float(rs())", "+", "+", "+def rs_():", "+ return [_ for _ in rs().split()]", "+", "+", "+def ri_():", "+ return [int(_) for _ in rs().split()]", "+", "+", "+def rf_():", "+ return [float(_) for _ in rs().split()]", "+", "+", "+def divisors(n, sortresult=True):", "+ div = []", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ div.append(i)", "+ if i != n // i:", "+ div.append(n // i)", "+ if sortresult:", "+ div.sort()", "+ return div", "+", "+", "+# endregion", "+N = ri()", "+a = [0] * N", "+b = [0] * N", "+c = [0] * N", "+for i in range(N):", "+ a[i], b[i], c[i] = ri_()", "-dp[0] = data[0]", "+dp[0][0] = a[0]", "+dp[0][1] = b[0]", "+dp[0][2] = c[0]", "- for j in range(3):", "- dp[i][j] = data[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3])", "+ dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]", "+ dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]", "+ dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]" ]
false
0.042701
0.078856
0.541507
[ "s701159055", "s231792190" ]
u408260374
p00723
python
s508638494
s052425122
80
50
6,848
6,848
Accepted
Accepted
37.5
m = int(eval(input())) for i in range(m): d = eval(input()) trains = [d] for j in range(1, len(d)): trains.extend([d[:j][::-1] + d[j:], d[:j] + d[j:][::-1], d[:j][::-1] + d[j:][::-1], d[j:] + d[:j], d[j:][::-1] + d[:j], d[j:] + d[:j][::-1], d[j:][::-1] + d[:j][::-1]]) print((len(set(trains))))
m = int(eval(input())) for i in range(m): d = eval(input()) trains = [d] for j in range(1, len(d)): f, b = d[:j], d[j:] rf, rb = f[::-1], b[::-1] trains.extend([rf+b, f+rb, rf+rb, b+f, rb+f, b+rf, rb+rf]) print((len(set(trains))))
7
9
310
264
m = int(eval(input())) for i in range(m): d = eval(input()) trains = [d] for j in range(1, len(d)): trains.extend( [ d[:j][::-1] + d[j:], d[:j] + d[j:][::-1], d[:j][::-1] + d[j:][::-1], d[j:] + d[:j], d[j:][::-1] + d[:j], d[j:] + d[:j][::-1], d[j:][::-1] + d[:j][::-1], ] ) print((len(set(trains))))
m = int(eval(input())) for i in range(m): d = eval(input()) trains = [d] for j in range(1, len(d)): f, b = d[:j], d[j:] rf, rb = f[::-1], b[::-1] trains.extend([rf + b, f + rb, rf + rb, b + f, rb + f, b + rf, rb + rf]) print((len(set(trains))))
false
22.222222
[ "- trains.extend(", "- [", "- d[:j][::-1] + d[j:],", "- d[:j] + d[j:][::-1],", "- d[:j][::-1] + d[j:][::-1],", "- d[j:] + d[:j],", "- d[j:][::-1] + d[:j],", "- d[j:] + d[:j][::-1],", "- d[j:][::-1] + d[:j][::-1],", "- ]", "- )", "+ f, b = d[:j], d[j:]", "+ rf, rb = f[::-1], b[::-1]", "+ trains.extend([rf + b, f + rb, rf + rb, b + f, rb + f, b + rf, rb + rf])" ]
false
0.041732
0.041152
1.014082
[ "s508638494", "s052425122" ]
u112629957
p02727
python
s054613739
s897646338
367
248
106,980
23,328
Accepted
Accepted
32.43
X,Y,A,B,C=list(map(int,input().split())) ls_a=sorted(list(map(int,input().split()))) ls_b=sorted(list(map(int,input().split()))) ls_c=sorted(list(map(int,input().split()))) ls_x=ls_a[A-X:A] ls_y=ls_b[B-Y:B] ls_c.reverse() ans=sum(ls_x)+sum(ls_y) a=b=c=0 for _ in range(min([X+Y,C])): if a==len(ls_x): m=min([ls_y[b],ls_c[c]]) if m==ls_y[b]: ans+=(-ls_y[b]+ls_c[c]) b+=1 c+=1 else: break elif b==len(ls_y): m=min([ls_x[a],ls_c[c]]) if m==ls_x[a]: ans+=(-ls_x[a]+ls_c[c]) a+=1 c+=1 else: break else: m=min([ls_x[a],ls_y[b],ls_c[c]]) if m==ls_x[a]: ans+=(-ls_x[a]+ls_c[c]) a+=1 c+=1 elif m==ls_y[b]: ans+=(-ls_y[b]+ls_c[c]) b+=1 c+=1 else: break print(ans)
X,Y,A,B,C=list(map(int,input().split())) ls_a=list(map(int,input().split())) ls_b=list(map(int,input().split())) ls_c=list(map(int,input().split())) ls_a.sort(reverse=True) ls_b.sort(reverse=True) ls_c.sort(reverse=True) ls=sorted(ls_a[:X]+ls_b[:Y]) ans=sum(ls) for i in range(min(X+Y, C)): if ls[i] < ls_c[i]: ans += ls_c[i] - ls[i] print(ans)
40
15
827
366
X, Y, A, B, C = list(map(int, input().split())) ls_a = sorted(list(map(int, input().split()))) ls_b = sorted(list(map(int, input().split()))) ls_c = sorted(list(map(int, input().split()))) ls_x = ls_a[A - X : A] ls_y = ls_b[B - Y : B] ls_c.reverse() ans = sum(ls_x) + sum(ls_y) a = b = c = 0 for _ in range(min([X + Y, C])): if a == len(ls_x): m = min([ls_y[b], ls_c[c]]) if m == ls_y[b]: ans += -ls_y[b] + ls_c[c] b += 1 c += 1 else: break elif b == len(ls_y): m = min([ls_x[a], ls_c[c]]) if m == ls_x[a]: ans += -ls_x[a] + ls_c[c] a += 1 c += 1 else: break else: m = min([ls_x[a], ls_y[b], ls_c[c]]) if m == ls_x[a]: ans += -ls_x[a] + ls_c[c] a += 1 c += 1 elif m == ls_y[b]: ans += -ls_y[b] + ls_c[c] b += 1 c += 1 else: break print(ans)
X, Y, A, B, C = list(map(int, input().split())) ls_a = list(map(int, input().split())) ls_b = list(map(int, input().split())) ls_c = list(map(int, input().split())) ls_a.sort(reverse=True) ls_b.sort(reverse=True) ls_c.sort(reverse=True) ls = sorted(ls_a[:X] + ls_b[:Y]) ans = sum(ls) for i in range(min(X + Y, C)): if ls[i] < ls_c[i]: ans += ls_c[i] - ls[i] print(ans)
false
62.5
[ "-ls_a = sorted(list(map(int, input().split())))", "-ls_b = sorted(list(map(int, input().split())))", "-ls_c = sorted(list(map(int, input().split())))", "-ls_x = ls_a[A - X : A]", "-ls_y = ls_b[B - Y : B]", "-ls_c.reverse()", "-ans = sum(ls_x) + sum(ls_y)", "-a = b = c = 0", "-for _ in range(min([X + Y, C])):", "- if a == len(ls_x):", "- m = min([ls_y[b], ls_c[c]])", "- if m == ls_y[b]:", "- ans += -ls_y[b] + ls_c[c]", "- b += 1", "- c += 1", "- else:", "- break", "- elif b == len(ls_y):", "- m = min([ls_x[a], ls_c[c]])", "- if m == ls_x[a]:", "- ans += -ls_x[a] + ls_c[c]", "- a += 1", "- c += 1", "- else:", "- break", "- else:", "- m = min([ls_x[a], ls_y[b], ls_c[c]])", "- if m == ls_x[a]:", "- ans += -ls_x[a] + ls_c[c]", "- a += 1", "- c += 1", "- elif m == ls_y[b]:", "- ans += -ls_y[b] + ls_c[c]", "- b += 1", "- c += 1", "- else:", "- break", "+ls_a = list(map(int, input().split()))", "+ls_b = list(map(int, input().split()))", "+ls_c = list(map(int, input().split()))", "+ls_a.sort(reverse=True)", "+ls_b.sort(reverse=True)", "+ls_c.sort(reverse=True)", "+ls = sorted(ls_a[:X] + ls_b[:Y])", "+ans = sum(ls)", "+for i in range(min(X + Y, C)):", "+ if ls[i] < ls_c[i]:", "+ ans += ls_c[i] - ls[i]" ]
false
0.037852
0.045044
0.840326
[ "s054613739", "s897646338" ]
u389910364
p02776
python
s176399831
s317703527
1,798
1,404
149,352
129,372
Accepted
Accepted
21.91
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, M = list(map(int, sys.stdin.buffer.readline().split())) AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)] AB = np.array(AB, dtype=int) LR = np.array(LR, dtype=int) AB = AB[np.argsort(AB[:, 0])] A, B = AB[:, 0], AB[:, 1] L, R = LR[:, 0], LR[:, 1] L = np.searchsorted(A, L, side='left').tolist() R = np.searchsorted(A, R, side='right').tolist() # L か R の数が奇数になる場所が True is_odd = np.diff(np.concatenate(([0], B, [0]))) != 0 graph = [[] for _ in range(N + 1)] for i, (l, r) in enumerate(list(zip(L, R))): graph[l].append((r, i)) graph[r].append((l, i)) seen_graph = [False] * (N + 1) seen_v = [False] * (N + 1) parents = [None] * (N + 1) def dfs(v): # 子の is_odd の数が奇数ならその辺を切る。葉からやってけば root で辻褄が合う ret = int(is_odd[v]) for u, j in graph[v]: if seen_v[u]: continue seen_v[u] = True children_odds = dfs(u) if children_odds % 2 == 1: ans.append(j) ret += children_odds return ret ans = [] for v in range(N + 1): if seen_v[v]: continue seen_v[v] = True if dfs(v) % 2 != 0: print((-1)) exit() ans = np.array(ans, dtype=int) ans.sort() print((len(ans))) print((*(ans + 1)))
import bisect import os import sys 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, M = list(map(int, sys.stdin.buffer.readline().split())) AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)] AB.sort() odd = 0 # 偶奇が変わる値 nums = [(0, 0)] + AB + [(INF, 0)] A = [a for a, b in nums] B = [b for a, b in nums] size = len(nums) graph = [[] for _ in range(size)] for i, (l, r) in enumerate(LR, start=1): # l 未満が全部変わる v = bisect.bisect_left(A, l) - 1 # r 以下が全部変わる u = bisect.bisect_right(A, r) - 1 graph[v].append((u, i)) graph[u].append((v, i)) parity = [0] * size for i, (b1, b2) in enumerate(zip(B, B[1:])): if b1 == 0 and b2 == 1: parity[i] = 1 if b1 == 1 and b2 == 0: parity[i] = 1 # 適当に全域木を作って 1 を押し出していけばいい seen = [False] * size trees = [] for root in range(size): if seen[root] or not graph[root]: continue edges = [] seen[root] = True stack = [root] while stack: v = stack.pop() for u, i in graph[v]: if seen[u]: continue seen[u] = True stack.append(u) edges.append((v, u, i)) # 頂点が1つしかない if not edges and parity[root] == 1: print((-1)) exit() trees.append(edges) graph = [[] for _ in range(size)] degrees = [0] * size for edges in trees: for v, u, i in edges: graph[v].append((u, i)) graph[u].append((v, i)) degrees[v] += 1 degrees[u] += 1 ans = [] seen = [False] * size stack = [] for v, d in enumerate(degrees): if d == 1: stack.append(v) while stack: v = stack.pop() if degrees[v] == 0: continue assert degrees[v] == 1 if seen[v]: continue seen[v] = True degrees[v] = 0 # 葉っぱから内側にずらしてく for u, i in graph[v]: if seen[u]: continue if parity[v] == parity[u] == 1: parity[u] = parity[v] = 0 ans.append(i) elif parity[v] == 1 and parity[u] == 0: parity[u] = 1 parity[v] = 0 ans.append(i) degrees[u] -= 1 if degrees[u] == 1: stack.append(u) if 1 in parity: print((-1)) else: print((len(ans))) print((*sorted(ans)))
69
113
1,578
2,566
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, M = list(map(int, sys.stdin.buffer.readline().split())) AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)] AB = np.array(AB, dtype=int) LR = np.array(LR, dtype=int) AB = AB[np.argsort(AB[:, 0])] A, B = AB[:, 0], AB[:, 1] L, R = LR[:, 0], LR[:, 1] L = np.searchsorted(A, L, side="left").tolist() R = np.searchsorted(A, R, side="right").tolist() # L か R の数が奇数になる場所が True is_odd = np.diff(np.concatenate(([0], B, [0]))) != 0 graph = [[] for _ in range(N + 1)] for i, (l, r) in enumerate(list(zip(L, R))): graph[l].append((r, i)) graph[r].append((l, i)) seen_graph = [False] * (N + 1) seen_v = [False] * (N + 1) parents = [None] * (N + 1) def dfs(v): # 子の is_odd の数が奇数ならその辺を切る。葉からやってけば root で辻褄が合う ret = int(is_odd[v]) for u, j in graph[v]: if seen_v[u]: continue seen_v[u] = True children_odds = dfs(u) if children_odds % 2 == 1: ans.append(j) ret += children_odds return ret ans = [] for v in range(N + 1): if seen_v[v]: continue seen_v[v] = True if dfs(v) % 2 != 0: print((-1)) exit() ans = np.array(ans, dtype=int) ans.sort() print((len(ans))) print((*(ans + 1)))
import bisect import os import sys 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, M = list(map(int, sys.stdin.buffer.readline().split())) AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)] AB.sort() odd = 0 # 偶奇が変わる値 nums = [(0, 0)] + AB + [(INF, 0)] A = [a for a, b in nums] B = [b for a, b in nums] size = len(nums) graph = [[] for _ in range(size)] for i, (l, r) in enumerate(LR, start=1): # l 未満が全部変わる v = bisect.bisect_left(A, l) - 1 # r 以下が全部変わる u = bisect.bisect_right(A, r) - 1 graph[v].append((u, i)) graph[u].append((v, i)) parity = [0] * size for i, (b1, b2) in enumerate(zip(B, B[1:])): if b1 == 0 and b2 == 1: parity[i] = 1 if b1 == 1 and b2 == 0: parity[i] = 1 # 適当に全域木を作って 1 を押し出していけばいい seen = [False] * size trees = [] for root in range(size): if seen[root] or not graph[root]: continue edges = [] seen[root] = True stack = [root] while stack: v = stack.pop() for u, i in graph[v]: if seen[u]: continue seen[u] = True stack.append(u) edges.append((v, u, i)) # 頂点が1つしかない if not edges and parity[root] == 1: print((-1)) exit() trees.append(edges) graph = [[] for _ in range(size)] degrees = [0] * size for edges in trees: for v, u, i in edges: graph[v].append((u, i)) graph[u].append((v, i)) degrees[v] += 1 degrees[u] += 1 ans = [] seen = [False] * size stack = [] for v, d in enumerate(degrees): if d == 1: stack.append(v) while stack: v = stack.pop() if degrees[v] == 0: continue assert degrees[v] == 1 if seen[v]: continue seen[v] = True degrees[v] = 0 # 葉っぱから内側にずらしてく for u, i in graph[v]: if seen[u]: continue if parity[v] == parity[u] == 1: parity[u] = parity[v] = 0 ans.append(i) elif parity[v] == 1 and parity[u] == 0: parity[u] = 1 parity[v] = 0 ans.append(i) degrees[u] -= 1 if degrees[u] == 1: stack.append(u) if 1 in parity: print((-1)) else: print((len(ans))) print((*sorted(ans)))
false
38.938053
[ "+import bisect", "-import numpy as np", "-# 解説", "-AB = np.array(AB, dtype=int)", "-LR = np.array(LR, dtype=int)", "-AB = AB[np.argsort(AB[:, 0])]", "-A, B = AB[:, 0], AB[:, 1]", "-L, R = LR[:, 0], LR[:, 1]", "-L = np.searchsorted(A, L, side=\"left\").tolist()", "-R = np.searchsorted(A, R, side=\"right\").tolist()", "-# L か R の数が奇数になる場所が True", "-is_odd = np.diff(np.concatenate(([0], B, [0]))) != 0", "-graph = [[] for _ in range(N + 1)]", "-for i, (l, r) in enumerate(list(zip(L, R))):", "- graph[l].append((r, i))", "- graph[r].append((l, i))", "-seen_graph = [False] * (N + 1)", "-seen_v = [False] * (N + 1)", "-parents = [None] * (N + 1)", "-", "-", "-def dfs(v):", "- # 子の is_odd の数が奇数ならその辺を切る。葉からやってけば root で辻褄が合う", "- ret = int(is_odd[v])", "- for u, j in graph[v]:", "- if seen_v[u]:", "- continue", "- seen_v[u] = True", "- children_odds = dfs(u)", "- if children_odds % 2 == 1:", "- ans.append(j)", "- ret += children_odds", "- return ret", "-", "-", "-ans = []", "-for v in range(N + 1):", "- if seen_v[v]:", "+AB.sort()", "+odd = 0", "+# 偶奇が変わる値", "+nums = [(0, 0)] + AB + [(INF, 0)]", "+A = [a for a, b in nums]", "+B = [b for a, b in nums]", "+size = len(nums)", "+graph = [[] for _ in range(size)]", "+for i, (l, r) in enumerate(LR, start=1):", "+ # l 未満が全部変わる", "+ v = bisect.bisect_left(A, l) - 1", "+ # r 以下が全部変わる", "+ u = bisect.bisect_right(A, r) - 1", "+ graph[v].append((u, i))", "+ graph[u].append((v, i))", "+parity = [0] * size", "+for i, (b1, b2) in enumerate(zip(B, B[1:])):", "+ if b1 == 0 and b2 == 1:", "+ parity[i] = 1", "+ if b1 == 1 and b2 == 0:", "+ parity[i] = 1", "+# 適当に全域木を作って 1 を押し出していけばいい", "+seen = [False] * size", "+trees = []", "+for root in range(size):", "+ if seen[root] or not graph[root]:", "- seen_v[v] = True", "- if dfs(v) % 2 != 0:", "+ edges = []", "+ seen[root] = True", "+ stack = [root]", "+ while stack:", "+ v = stack.pop()", "+ for u, i in graph[v]:", "+ if seen[u]:", "+ continue", "+ seen[u] = True", "+ stack.append(u)", "+ edges.append((v, u, i))", "+ # 頂点が1つしかない", "+ if not edges and parity[root] == 1:", "-ans = np.array(ans, dtype=int)", "-ans.sort()", "-print((len(ans)))", "-print((*(ans + 1)))", "+ trees.append(edges)", "+graph = [[] for _ in range(size)]", "+degrees = [0] * size", "+for edges in trees:", "+ for v, u, i in edges:", "+ graph[v].append((u, i))", "+ graph[u].append((v, i))", "+ degrees[v] += 1", "+ degrees[u] += 1", "+ans = []", "+seen = [False] * size", "+stack = []", "+for v, d in enumerate(degrees):", "+ if d == 1:", "+ stack.append(v)", "+while stack:", "+ v = stack.pop()", "+ if degrees[v] == 0:", "+ continue", "+ assert degrees[v] == 1", "+ if seen[v]:", "+ continue", "+ seen[v] = True", "+ degrees[v] = 0", "+ # 葉っぱから内側にずらしてく", "+ for u, i in graph[v]:", "+ if seen[u]:", "+ continue", "+ if parity[v] == parity[u] == 1:", "+ parity[u] = parity[v] = 0", "+ ans.append(i)", "+ elif parity[v] == 1 and parity[u] == 0:", "+ parity[u] = 1", "+ parity[v] = 0", "+ ans.append(i)", "+ degrees[u] -= 1", "+ if degrees[u] == 1:", "+ stack.append(u)", "+if 1 in parity:", "+ print((-1))", "+else:", "+ print((len(ans)))", "+ print((*sorted(ans)))" ]
false
0.603912
0.07525
8.025456
[ "s176399831", "s317703527" ]
u590825760
p02762
python
s983532220
s398704241
1,571
1,168
48,452
10,268
Accepted
Accepted
25.65
N, M, K = map(int, input().split()) F = [[] for _ in range(N)] B = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) a, b = a - 1, b - 1 F[a].append(b) F[b].append(a) for _ in range(K): c, d = map(int, input().split()) c, d = c - 1, d - 1 B[c].append(d) B[d].append(c) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.rank = [0] * n self.size = [1] * n # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same(self, x, y): return self.find(x) == self.find(y) # すべての頂点に対して親を検索する def all_find(self): for n in range(len(self.par)): self.find(n) UF = UnionFind(N) for iam in range(N): for friend in F[iam]: UF.union(iam, friend) ans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] for iam in range(N): ans[iam] -= len(F[iam]) for iam in range(N): for block in B[iam]: if UF.same(iam, block): ans[iam] -= 1 print(*ans, sep=' ')
class UnionFind(): def __init__(self,n): self.n = n self.parents = [-1] * (n+1) def FindRoot(self,x): if self.parents[x] < 0: return x else: self.parents[x] = self.FindRoot(self.parents[x]) return self.parents[x] def Union(self,x,y): x = self.FindRoot(x) y = self.FindRoot(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def isSame(self,x,y): return self.FindRoot(x) == self.FindRoot(y) def Size(self,x): return -self.parents[self.FindRoot(x)] n,m,k = [int(x) for x in input().split()] obj = UnionFind(n) cnt = [0]*(n+1) for _ in range(m): a,b = [int(x) for x in input().split()] obj.Union(a,b) cnt[a] += 1 cnt[b] += 1 for _ in range(k): c,d = [int(x) for x in input().split()] if obj.isSame(c,d): cnt[c] += 1 cnt[d] += 1 ans = 0 for i in range(1,n+1): ans = obj.Size(i)-1-cnt[i] print(ans,end=" ")
73
48
1,646
1,175
N, M, K = map(int, input().split()) F = [[] for _ in range(N)] B = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) a, b = a - 1, b - 1 F[a].append(b) F[b].append(a) for _ in range(K): c, d = map(int, input().split()) c, d = c - 1, d - 1 B[c].append(d) B[d].append(c) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.rank = [0] * n self.size = [1] * n # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same(self, x, y): return self.find(x) == self.find(y) # すべての頂点に対して親を検索する def all_find(self): for n in range(len(self.par)): self.find(n) UF = UnionFind(N) for iam in range(N): for friend in F[iam]: UF.union(iam, friend) ans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] for iam in range(N): ans[iam] -= len(F[iam]) for iam in range(N): for block in B[iam]: if UF.same(iam, block): ans[iam] -= 1 print(*ans, sep=" ")
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * (n + 1) def FindRoot(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.FindRoot(self.parents[x]) return self.parents[x] def Union(self, x, y): x = self.FindRoot(x) y = self.FindRoot(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def isSame(self, x, y): return self.FindRoot(x) == self.FindRoot(y) def Size(self, x): return -self.parents[self.FindRoot(x)] n, m, k = [int(x) for x in input().split()] obj = UnionFind(n) cnt = [0] * (n + 1) for _ in range(m): a, b = [int(x) for x in input().split()] obj.Union(a, b) cnt[a] += 1 cnt[b] += 1 for _ in range(k): c, d = [int(x) for x in input().split()] if obj.isSame(c, d): cnt[c] += 1 cnt[d] += 1 ans = 0 for i in range(1, n + 1): ans = obj.Size(i) - 1 - cnt[i] print(ans, end=" ")
false
34.246575
[ "-N, M, K = map(int, input().split())", "-F = [[] for _ in range(N)]", "-B = [[] for _ in range(N)]", "-for _ in range(M):", "- a, b = map(int, input().split())", "- a, b = a - 1, b - 1", "- F[a].append(b)", "- F[b].append(a)", "-for _ in range(K):", "- c, d = map(int, input().split())", "- c, d = c - 1, d - 1", "- B[c].append(d)", "- B[d].append(c)", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.parents = [-1] * (n + 1)", "+", "+ def FindRoot(self, x):", "+ if self.parents[x] < 0:", "+ return x", "+ else:", "+ self.parents[x] = self.FindRoot(self.parents[x])", "+ return self.parents[x]", "+", "+ def Union(self, x, y):", "+ x = self.FindRoot(x)", "+ y = self.FindRoot(y)", "+ if x == y:", "+ return", "+ if self.parents[x] > self.parents[y]:", "+ x, y = y, x", "+ self.parents[x] += self.parents[y]", "+ self.parents[y] = x", "+", "+ def isSame(self, x, y):", "+ return self.FindRoot(x) == self.FindRoot(y)", "+", "+ def Size(self, x):", "+ return -self.parents[self.FindRoot(x)]", "-class UnionFind:", "- def __init__(self, n):", "- self.par = [i for i in range(n)]", "- self.rank = [0] * n", "- self.size = [1] * n", "-", "- # 検索", "- def find(self, x):", "- if self.par[x] == x:", "- return x", "- else:", "- self.par[x] = self.find(self.par[x])", "- return self.par[x]", "-", "- # 併合", "- def union(self, x, y):", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- if self.rank[x] < self.rank[y]:", "- self.par[x] = y", "- self.size[y] += self.size[x]", "- else:", "- self.par[y] = x", "- self.size[x] += self.size[y]", "- if self.rank[x] == self.rank[y]:", "- self.rank[x] += 1", "-", "- # 同じ集合に属するか判定", "- def same(self, x, y):", "- return self.find(x) == self.find(y)", "-", "- # すべての頂点に対して親を検索する", "- def all_find(self):", "- for n in range(len(self.par)):", "- self.find(n)", "-", "-", "-UF = UnionFind(N)", "-for iam in range(N):", "- for friend in F[iam]:", "- UF.union(iam, friend)", "-ans = [UF.size[UF.find(iam)] - 1 for iam in range(N)]", "-for iam in range(N):", "- ans[iam] -= len(F[iam])", "-for iam in range(N):", "- for block in B[iam]:", "- if UF.same(iam, block):", "- ans[iam] -= 1", "-print(*ans, sep=\" \")", "+n, m, k = [int(x) for x in input().split()]", "+obj = UnionFind(n)", "+cnt = [0] * (n + 1)", "+for _ in range(m):", "+ a, b = [int(x) for x in input().split()]", "+ obj.Union(a, b)", "+ cnt[a] += 1", "+ cnt[b] += 1", "+for _ in range(k):", "+ c, d = [int(x) for x in input().split()]", "+ if obj.isSame(c, d):", "+ cnt[c] += 1", "+ cnt[d] += 1", "+ans = 0", "+for i in range(1, n + 1):", "+ ans = obj.Size(i) - 1 - cnt[i]", "+ print(ans, end=\" \")" ]
false
0.038172
0.038361
0.995075
[ "s983532220", "s398704241" ]
u297574184
p02936
python
s911490525
s669732914
1,577
944
284,052
144,092
Accepted
Accepted
40.14
def solve(): import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, Q = list(map(int, input().split())) adjL = [[] for _ in range(N)] for _ in range(N-1): A, B = list(map(int, input().split())) A, B = A-1, B-1 adjL[A].append(B) adjL[B].append(A) anss = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p = p-1 anss[p] += x def dfs(vNow, vPar, x): anss[vNow] += x ans = anss[vNow] for v2 in adjL[vNow]: if v2 != vPar: dfs(v2, vNow, ans) dfs(0, -1, 0) print((' '.join(map(str, anss)))) solve()
from collections import deque import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) adjL = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) a, b = a-1, b-1 adjL[a].append(b) adjL[b].append(a) querys = [tuple(map(int, input().split())) for _ in range(Q)] anss = [0] * N for p, x in querys: anss[p-1] += x def bfs(vSt): useds = [False] * (N) useds[vSt] = True Q = deque([vSt]) while Q: vNow = Q.popleft() ans = anss[vNow] for v2 in adjL[vNow]: if not useds[v2]: anss[v2] += ans Q.append(v2) useds[v2] = True bfs(0) print((' '.join(map(str, anss))))
31
33
692
747
def solve(): import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, Q = list(map(int, input().split())) adjL = [[] for _ in range(N)] for _ in range(N - 1): A, B = list(map(int, input().split())) A, B = A - 1, B - 1 adjL[A].append(B) adjL[B].append(A) anss = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p = p - 1 anss[p] += x def dfs(vNow, vPar, x): anss[vNow] += x ans = anss[vNow] for v2 in adjL[vNow]: if v2 != vPar: dfs(v2, vNow, ans) dfs(0, -1, 0) print((" ".join(map(str, anss)))) solve()
from collections import deque import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) adjL = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 adjL[a].append(b) adjL[b].append(a) querys = [tuple(map(int, input().split())) for _ in range(Q)] anss = [0] * N for p, x in querys: anss[p - 1] += x def bfs(vSt): useds = [False] * (N) useds[vSt] = True Q = deque([vSt]) while Q: vNow = Q.popleft() ans = anss[vNow] for v2 in adjL[vNow]: if not useds[v2]: anss[v2] += ans Q.append(v2) useds[v2] = True bfs(0) print((" ".join(map(str, anss))))
false
6.060606
[ "-def solve():", "- import sys", "+from collections import deque", "+import sys", "- sys.setrecursionlimit(10**9)", "- input = sys.stdin.readline", "- N, Q = list(map(int, input().split()))", "- adjL = [[] for _ in range(N)]", "- for _ in range(N - 1):", "- A, B = list(map(int, input().split()))", "- A, B = A - 1, B - 1", "- adjL[A].append(B)", "- adjL[B].append(A)", "- anss = [0] * N", "- for _ in range(Q):", "- p, x = list(map(int, input().split()))", "- p = p - 1", "- anss[p] += x", "+input = sys.stdin.readline", "+N, Q = list(map(int, input().split()))", "+adjL = [[] for _ in range(N)]", "+for _ in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ adjL[a].append(b)", "+ adjL[b].append(a)", "+querys = [tuple(map(int, input().split())) for _ in range(Q)]", "+anss = [0] * N", "+for p, x in querys:", "+ anss[p - 1] += x", "- def dfs(vNow, vPar, x):", "- anss[vNow] += x", "+", "+def bfs(vSt):", "+ useds = [False] * (N)", "+ useds[vSt] = True", "+ Q = deque([vSt])", "+ while Q:", "+ vNow = Q.popleft()", "- if v2 != vPar:", "- dfs(v2, vNow, ans)", "-", "- dfs(0, -1, 0)", "- print((\" \".join(map(str, anss))))", "+ if not useds[v2]:", "+ anss[v2] += ans", "+ Q.append(v2)", "+ useds[v2] = True", "-solve()", "+bfs(0)", "+print((\" \".join(map(str, anss))))" ]
false
0.036457
0.036143
1.008693
[ "s911490525", "s669732914" ]
u796942881
p03659
python
s059597851
s884405733
148
118
24,216
24,320
Accepted
Accepted
20.27
INF = float('inf') def main(): N, *a = list(map(int, open(0).read().split())) ans = INF tmp = 0 total = sum(a) for i in range(N - 1): tmp += a[i] ans = min(ans, abs(2 * tmp - total)) print(ans) return main()
from itertools import accumulate def main(): N, *a = list(map(int, open(0).read().split())) a = list(accumulate(a)) total = a[-1] print((min(abs(2 * a[i] - total) for i in range(N - 1)))) return main()
16
12
265
229
INF = float("inf") def main(): N, *a = list(map(int, open(0).read().split())) ans = INF tmp = 0 total = sum(a) for i in range(N - 1): tmp += a[i] ans = min(ans, abs(2 * tmp - total)) print(ans) return main()
from itertools import accumulate def main(): N, *a = list(map(int, open(0).read().split())) a = list(accumulate(a)) total = a[-1] print((min(abs(2 * a[i] - total) for i in range(N - 1)))) return main()
false
25
[ "-INF = float(\"inf\")", "+from itertools import accumulate", "- ans = INF", "- tmp = 0", "- total = sum(a)", "- for i in range(N - 1):", "- tmp += a[i]", "- ans = min(ans, abs(2 * tmp - total))", "- print(ans)", "+ a = list(accumulate(a))", "+ total = a[-1]", "+ print((min(abs(2 * a[i] - total) for i in range(N - 1))))" ]
false
0.046078
0.04503
1.023261
[ "s059597851", "s884405733" ]
u077291787
p03645
python
s064267600
s039034142
266
244
19,004
19,012
Accepted
Accepted
8.27
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
18
18
426
409
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
false
0
[ "- n, m = list(map(int, input().rstrip().split()))", "+ n, m = list(map(int, input().split()))", "- a, b = list(map(int, input().rstrip().split()))", "+ a, b = list(map(int, input().split()))" ]
false
0.185639
0.047343
3.921179
[ "s064267600", "s039034142" ]
u415905784
p03504
python
s004381313
s871964292
1,355
1,163
27,168
40,804
Accepted
Accepted
14.17
import functools N, C = list(map(int, input().split())) T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)] for i in range(N): s, t, c = list(map(int, input().split())) for j in range(s - 1, t): T[c - 1][j] = 1 ans = 0 for j in range(10 ** 5 + 1): r = 0 for i in range(C): r += T[i][j] ans = max(ans, r) print(ans)
import functools N, C = list(map(int, input().split())) P = [[0 for c in range(C)] for i in range(10 ** 5 + 1)] T = 0 for i in range(N): s, t, c = list(map(int, input().split())) T = max(t, T) for j in range(s - 1, t): P[j][c - 1] = 1 ans = 0 for p in P[:T + 1]: ans = max(sum(p), ans) print(ans)
14
13
337
308
import functools N, C = list(map(int, input().split())) T = [[0 for i in range(10**5 + 1)] for j in range(C)] for i in range(N): s, t, c = list(map(int, input().split())) for j in range(s - 1, t): T[c - 1][j] = 1 ans = 0 for j in range(10**5 + 1): r = 0 for i in range(C): r += T[i][j] ans = max(ans, r) print(ans)
import functools N, C = list(map(int, input().split())) P = [[0 for c in range(C)] for i in range(10**5 + 1)] T = 0 for i in range(N): s, t, c = list(map(int, input().split())) T = max(t, T) for j in range(s - 1, t): P[j][c - 1] = 1 ans = 0 for p in P[: T + 1]: ans = max(sum(p), ans) print(ans)
false
7.142857
[ "-T = [[0 for i in range(10**5 + 1)] for j in range(C)]", "+P = [[0 for c in range(C)] for i in range(10**5 + 1)]", "+T = 0", "+ T = max(t, T)", "- T[c - 1][j] = 1", "+ P[j][c - 1] = 1", "-for j in range(10**5 + 1):", "- r = 0", "- for i in range(C):", "- r += T[i][j]", "- ans = max(ans, r)", "+for p in P[: T + 1]:", "+ ans = max(sum(p), ans)" ]
false
0.307886
0.198727
1.549292
[ "s004381313", "s871964292" ]
u202727309
p03162
python
s207714770
s669213924
1,000
573
47,352
34,616
Accepted
Accepted
42.7
N = int(eval(input())) Y = [] for _ in range(N): Y.append(list(map(int, input().split()))) # Y = [[3, 9, 7], [10, 3, 2]] dp = [[0] * 3 for _ in range(N)] # 初期化 dp[0] = Y[0] # 初期化 # A, B, C の3パターン以外にも対応 for i in range(N-1): for j in range(3): for k in range(3): if j == k: continue dp[i+1][j] = max(dp[i+1][j], dp[i][k] + Y[i+1][j]) print((max(dp[N-1])))
N = int(eval(input())) A = [0] * N B = [0] * N C = [0] * N for i in range(N): A[i], B[i], C[i] = list(map(int, input().split())) dp = [[0] * 3 for _ in range(N)] # 初期化 [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4 dp[0] = [A[0], B[0], C[0]] for i in range(N-1): dp[i+1][0] = max(dp[i][1]+A[i+1], dp[i][2]+A[i+1]) dp[i+1][1] = max(dp[i][0]+B[i+1], dp[i][2]+B[i+1]) dp[i+1][2] = max(dp[i][0]+C[i+1], dp[i][1]+C[i+1]) print((max(dp[N-1])))
15
14
419
462
N = int(eval(input())) Y = [] for _ in range(N): Y.append(list(map(int, input().split()))) # Y = [[3, 9, 7], [10, 3, 2]] dp = [[0] * 3 for _ in range(N)] # 初期化 dp[0] = Y[0] # 初期化 # A, B, C の3パターン以外にも対応 for i in range(N - 1): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + Y[i + 1][j]) print((max(dp[N - 1])))
N = int(eval(input())) A = [0] * N B = [0] * N C = [0] * N for i in range(N): A[i], B[i], C[i] = list(map(int, input().split())) dp = [ [0] * 3 for _ in range(N) ] # 初期化 [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4 dp[0] = [A[0], B[0], C[0]] for i in range(N - 1): dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1]) dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1]) dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1]) print((max(dp[N - 1])))
false
6.666667
[ "-Y = []", "-for _ in range(N):", "- Y.append(list(map(int, input().split()))) # Y = [[3, 9, 7], [10, 3, 2]]", "-dp = [[0] * 3 for _ in range(N)] # 初期化", "-dp[0] = Y[0] # 初期化", "-# A, B, C の3パターン以外にも対応", "+A = [0] * N", "+B = [0] * N", "+C = [0] * N", "+for i in range(N):", "+ A[i], B[i], C[i] = list(map(int, input().split()))", "+dp = [", "+ [0] * 3 for _ in range(N)", "+] # 初期化 [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4", "+dp[0] = [A[0], B[0], C[0]]", "- for j in range(3):", "- for k in range(3):", "- if j == k:", "- continue", "- dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + Y[i + 1][j])", "+ dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1])", "+ dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1])", "+ dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1])" ]
false
0.042498
0.036902
1.151646
[ "s207714770", "s669213924" ]
u566529875
p03112
python
s065734394
s052475138
1,655
1,530
12,092
12,072
Accepted
Accepted
7.55
import bisect a,b,q=list(map(int,input().split())) s=[int(eval(input()))for _ in range(a)] s.append(12345678901234) s.insert(0,-12345678901234) t=[int(eval(input()))for _ in range(b)] t.append(12345678901234) t.insert(0,-12345678901234) for query in range(q): ans = 123456789012345 x=int(eval(input())) idxs = bisect.bisect_left(s,x) idxt = bisect.bisect_left(t,x) ls = s[idxs-1] rs=s[idxs] lt=t[idxt-1] rt=t[idxt] # 左 ans = min(ans,max(abs(x-ls),abs(x-lt))) # 右 ans = min(ans,max(abs(x-rs),abs(x-rt))) # 行って帰って ans = min(ans,2*abs(x-ls)+abs(x-rt)) ans = min(ans,2*abs(x-lt)+abs(x-rs)) ans = min(ans,2*abs(x-rs)+abs(x-lt)) ans = min(ans,2*abs(x-rt)+abs(x-ls)) print(ans)
import bisect a,b,q=list(map(int,input().split())) INF = 12345678901234 s=[int(eval(input()))for _ in range(a)] s.append(INF) s.insert(0,-INF) t=[int(eval(input()))for _ in range(b)] t.append(INF) t.insert(0,-INF) for query in range(q): ans = INF x=int(eval(input())) idxs = bisect.bisect_left(s,x) idxt = bisect.bisect_left(t,x) ls = x - s[idxs-1] rs = s[idxs] - x lt = x - t[idxt-1] rt = t[idxt] - x ans = min( ans, max(ls,lt) ) ans = min( ans, max(rt,rs) ) ans = min( ans, ls + rt + min(ls,rt) ) ans = min( ans, lt + rs + min(lt,rs) ) print(ans)
30
25
759
614
import bisect a, b, q = list(map(int, input().split())) s = [int(eval(input())) for _ in range(a)] s.append(12345678901234) s.insert(0, -12345678901234) t = [int(eval(input())) for _ in range(b)] t.append(12345678901234) t.insert(0, -12345678901234) for query in range(q): ans = 123456789012345 x = int(eval(input())) idxs = bisect.bisect_left(s, x) idxt = bisect.bisect_left(t, x) ls = s[idxs - 1] rs = s[idxs] lt = t[idxt - 1] rt = t[idxt] # 左 ans = min(ans, max(abs(x - ls), abs(x - lt))) # 右 ans = min(ans, max(abs(x - rs), abs(x - rt))) # 行って帰って ans = min(ans, 2 * abs(x - ls) + abs(x - rt)) ans = min(ans, 2 * abs(x - lt) + abs(x - rs)) ans = min(ans, 2 * abs(x - rs) + abs(x - lt)) ans = min(ans, 2 * abs(x - rt) + abs(x - ls)) print(ans)
import bisect a, b, q = list(map(int, input().split())) INF = 12345678901234 s = [int(eval(input())) for _ in range(a)] s.append(INF) s.insert(0, -INF) t = [int(eval(input())) for _ in range(b)] t.append(INF) t.insert(0, -INF) for query in range(q): ans = INF x = int(eval(input())) idxs = bisect.bisect_left(s, x) idxt = bisect.bisect_left(t, x) ls = x - s[idxs - 1] rs = s[idxs] - x lt = x - t[idxt - 1] rt = t[idxt] - x ans = min(ans, max(ls, lt)) ans = min(ans, max(rt, rs)) ans = min(ans, ls + rt + min(ls, rt)) ans = min(ans, lt + rs + min(lt, rs)) print(ans)
false
16.666667
[ "+INF = 12345678901234", "-s.append(12345678901234)", "-s.insert(0, -12345678901234)", "+s.append(INF)", "+s.insert(0, -INF)", "-t.append(12345678901234)", "-t.insert(0, -12345678901234)", "+t.append(INF)", "+t.insert(0, -INF)", "- ans = 123456789012345", "+ ans = INF", "- ls = s[idxs - 1]", "- rs = s[idxs]", "- lt = t[idxt - 1]", "- rt = t[idxt]", "- # 左", "- ans = min(ans, max(abs(x - ls), abs(x - lt)))", "- # 右", "- ans = min(ans, max(abs(x - rs), abs(x - rt)))", "- # 行って帰って", "- ans = min(ans, 2 * abs(x - ls) + abs(x - rt))", "- ans = min(ans, 2 * abs(x - lt) + abs(x - rs))", "- ans = min(ans, 2 * abs(x - rs) + abs(x - lt))", "- ans = min(ans, 2 * abs(x - rt) + abs(x - ls))", "+ ls = x - s[idxs - 1]", "+ rs = s[idxs] - x", "+ lt = x - t[idxt - 1]", "+ rt = t[idxt] - x", "+ ans = min(ans, max(ls, lt))", "+ ans = min(ans, max(rt, rs))", "+ ans = min(ans, ls + rt + min(ls, rt))", "+ ans = min(ans, lt + rs + min(lt, rs))" ]
false
0.045345
0.045118
1.00505
[ "s065734394", "s052475138" ]
u021019433
p02837
python
s642703666
s766619123
90
52
3,188
3,064
Accepted
Accepted
42.22
from itertools import combinations n = int(eval(input())) l = (1 << n) - 1 r = list(range(n)) a = [[0, 0] for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y] |= 1 << x - 1 def fail(x): x = sum(1 << i for i in x) return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1) while all(map(fail, combinations(r, n))): n -= 1 print(n)
from itertools import combinations, count n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) r = next(i for i in count(n, - 1) for x in map(set, combinations(r, i)) if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)) print(r)
18
12
414
368
from itertools import combinations n = int(eval(input())) l = (1 << n) - 1 r = list(range(n)) a = [[0, 0] for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y] |= 1 << x - 1 def fail(x): x = sum(1 << i for i in x) return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1) while all(map(fail, combinations(r, n))): n -= 1 print(n)
from itertools import combinations, count n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) r = next( i for i in count(n, -1) for x in map(set, combinations(r, i)) if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x) ) print(r)
false
33.333333
[ "-from itertools import combinations", "+from itertools import combinations, count", "-l = (1 << n) - 1", "-a = [[0, 0] for _ in r]", "+a = [(set(), set()) for _ in r]", "- a[i][y] |= 1 << x - 1", "-", "-", "-def fail(x):", "- x = sum(1 << i for i in x)", "- return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1)", "-", "-", "-while all(map(fail, combinations(r, n))):", "- n -= 1", "-print(n)", "+ a[i][y].add(x - 1)", "+r = next(", "+ i", "+ for i in count(n, -1)", "+ for x in map(set, combinations(r, i))", "+ if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)", "+)", "+print(r)" ]
false
0.084306
0.101695
0.829006
[ "s642703666", "s766619123" ]
u669382434
p03221
python
s705509512
s735368092
978
739
51,216
34,712
Accepted
Accepted
24.44
from operator import itemgetter N,M=list(map(int,input().split())) PY=[] P=[[] for i in range(N)] ans=[0 for i in range(M)] for i in range(M): PYi=list(map(int,input().split())) PY.append(PYi) P[PYi[0]-1].append([i,PYi[1]]) for i in range(N): P[i]=sorted(P[i], key=itemgetter(1)) for i in range(N): for j in range(len(P[i])): ans[P[i][j][0]]=j+1 for i in range(M): a=format(PY[i][0],'06d') b=format(ans[i],'06d') print((a+b))
from operator import itemgetter N,M=list(map(int,input().split())) PY=[] ans=[0 for i in range(M)] cc=[0 for i in range(N)] for i in range(M): PYi=list(map(int,input().split())) PY.append([i,PYi[0],PYi[1]]) PY=sorted(PY, key=itemgetter(2)) for i in range(M): cc[PY[i][1]-1]+=1 ans[PY[i][0]]=format(PY[i][1],'06d')+format(cc[PY[i][1]-1],'06d') for i in range(M): print((ans[i]))
22
18
482
415
from operator import itemgetter N, M = list(map(int, input().split())) PY = [] P = [[] for i in range(N)] ans = [0 for i in range(M)] for i in range(M): PYi = list(map(int, input().split())) PY.append(PYi) P[PYi[0] - 1].append([i, PYi[1]]) for i in range(N): P[i] = sorted(P[i], key=itemgetter(1)) for i in range(N): for j in range(len(P[i])): ans[P[i][j][0]] = j + 1 for i in range(M): a = format(PY[i][0], "06d") b = format(ans[i], "06d") print((a + b))
from operator import itemgetter N, M = list(map(int, input().split())) PY = [] ans = [0 for i in range(M)] cc = [0 for i in range(N)] for i in range(M): PYi = list(map(int, input().split())) PY.append([i, PYi[0], PYi[1]]) PY = sorted(PY, key=itemgetter(2)) for i in range(M): cc[PY[i][1] - 1] += 1 ans[PY[i][0]] = format(PY[i][1], "06d") + format(cc[PY[i][1] - 1], "06d") for i in range(M): print((ans[i]))
false
18.181818
[ "-P = [[] for i in range(N)]", "+cc = [0 for i in range(N)]", "- PY.append(PYi)", "- P[PYi[0] - 1].append([i, PYi[1]])", "-for i in range(N):", "- P[i] = sorted(P[i], key=itemgetter(1))", "-for i in range(N):", "- for j in range(len(P[i])):", "- ans[P[i][j][0]] = j + 1", "+ PY.append([i, PYi[0], PYi[1]])", "+PY = sorted(PY, key=itemgetter(2))", "- a = format(PY[i][0], \"06d\")", "- b = format(ans[i], \"06d\")", "- print((a + b))", "+ cc[PY[i][1] - 1] += 1", "+ ans[PY[i][0]] = format(PY[i][1], \"06d\") + format(cc[PY[i][1] - 1], \"06d\")", "+for i in range(M):", "+ print((ans[i]))" ]
false
0.040855
0.048059
0.850096
[ "s705509512", "s735368092" ]
u347640436
p03450
python
s059756406
s450779738
1,044
889
39,088
65,888
Accepted
Accepted
14.85
# Union Find 木 from sys import setrecursionlimit, stdin def find(parent, diff_weight, i): t = parent[i] if t < 0: return i t = find(parent, diff_weight, t) diff_weight[i] += diff_weight[parent[i]] parent[i] = t return t def weight(parent, diff_weight, i): find(parent, diff_weight, i) return diff_weight[i] def unite(parent, diff_weight, i, j, d): d -= weight(parent, diff_weight, j) d += weight(parent, diff_weight, i) i = find(parent, diff_weight, i) j = find(parent, diff_weight, j) if i == j: return diff_weight[j] = d parent[i] += parent[j] parent[j] = i setrecursionlimit(10 ** 6) N, M = list(map(int, stdin.readline().split())) LRD = [tuple(map(int, stdin.readline().split())) for _ in range(M)] parent = [-1] * (N + 1) diff_weight = [0] * (N + 1) for L, R, D in LRD: i = find(parent, diff_weight, L) j = find(parent, diff_weight, R) if i != j: unite(parent, diff_weight, L, R, D) else: if weight(parent, diff_weight, L) + D != weight(parent, diff_weight, R): print('No') exit() print('Yes')
# 深さ優先探索 from sys import stdin N, M = list(map(int, stdin.readline().split())) links = [[] for _ in range(N + 1)] for _ in range(M): L, R, D = list(map(int, stdin.readline().split())) links[L].append((R, D)) links[R].append((L, -D)) t = [None] * (N + 1) for i in range(1, N + 1): if t[i] is not None: continue t[i] = 0 s = [i] while s: j = s.pop() for k, l in links[j]: if t[k] is None: t[k] = t[j] + l s.append(k) else: if t[k] != t[j] + l: print('No') exit() print('Yes')
48
28
1,186
656
# Union Find 木 from sys import setrecursionlimit, stdin def find(parent, diff_weight, i): t = parent[i] if t < 0: return i t = find(parent, diff_weight, t) diff_weight[i] += diff_weight[parent[i]] parent[i] = t return t def weight(parent, diff_weight, i): find(parent, diff_weight, i) return diff_weight[i] def unite(parent, diff_weight, i, j, d): d -= weight(parent, diff_weight, j) d += weight(parent, diff_weight, i) i = find(parent, diff_weight, i) j = find(parent, diff_weight, j) if i == j: return diff_weight[j] = d parent[i] += parent[j] parent[j] = i setrecursionlimit(10**6) N, M = list(map(int, stdin.readline().split())) LRD = [tuple(map(int, stdin.readline().split())) for _ in range(M)] parent = [-1] * (N + 1) diff_weight = [0] * (N + 1) for L, R, D in LRD: i = find(parent, diff_weight, L) j = find(parent, diff_weight, R) if i != j: unite(parent, diff_weight, L, R, D) else: if weight(parent, diff_weight, L) + D != weight(parent, diff_weight, R): print("No") exit() print("Yes")
# 深さ優先探索 from sys import stdin N, M = list(map(int, stdin.readline().split())) links = [[] for _ in range(N + 1)] for _ in range(M): L, R, D = list(map(int, stdin.readline().split())) links[L].append((R, D)) links[R].append((L, -D)) t = [None] * (N + 1) for i in range(1, N + 1): if t[i] is not None: continue t[i] = 0 s = [i] while s: j = s.pop() for k, l in links[j]: if t[k] is None: t[k] = t[j] + l s.append(k) else: if t[k] != t[j] + l: print("No") exit() print("Yes")
false
41.666667
[ "-# Union Find 木", "-from sys import setrecursionlimit, stdin", "+# 深さ優先探索", "+from sys import stdin", "-", "-def find(parent, diff_weight, i):", "- t = parent[i]", "- if t < 0:", "- return i", "- t = find(parent, diff_weight, t)", "- diff_weight[i] += diff_weight[parent[i]]", "- parent[i] = t", "- return t", "-", "-", "-def weight(parent, diff_weight, i):", "- find(parent, diff_weight, i)", "- return diff_weight[i]", "-", "-", "-def unite(parent, diff_weight, i, j, d):", "- d -= weight(parent, diff_weight, j)", "- d += weight(parent, diff_weight, i)", "- i = find(parent, diff_weight, i)", "- j = find(parent, diff_weight, j)", "- if i == j:", "- return", "- diff_weight[j] = d", "- parent[i] += parent[j]", "- parent[j] = i", "-", "-", "-setrecursionlimit(10**6)", "-LRD = [tuple(map(int, stdin.readline().split())) for _ in range(M)]", "-parent = [-1] * (N + 1)", "-diff_weight = [0] * (N + 1)", "-for L, R, D in LRD:", "- i = find(parent, diff_weight, L)", "- j = find(parent, diff_weight, R)", "- if i != j:", "- unite(parent, diff_weight, L, R, D)", "- else:", "- if weight(parent, diff_weight, L) + D != weight(parent, diff_weight, R):", "- print(\"No\")", "- exit()", "+links = [[] for _ in range(N + 1)]", "+for _ in range(M):", "+ L, R, D = list(map(int, stdin.readline().split()))", "+ links[L].append((R, D))", "+ links[R].append((L, -D))", "+t = [None] * (N + 1)", "+for i in range(1, N + 1):", "+ if t[i] is not None:", "+ continue", "+ t[i] = 0", "+ s = [i]", "+ while s:", "+ j = s.pop()", "+ for k, l in links[j]:", "+ if t[k] is None:", "+ t[k] = t[j] + l", "+ s.append(k)", "+ else:", "+ if t[k] != t[j] + l:", "+ print(\"No\")", "+ exit()" ]
false
0.114508
0.085521
1.338943
[ "s059756406", "s450779738" ]
u025501820
p03108
python
s298718074
s027427882
992
914
123,952
116,184
Accepted
Accepted
7.86
N, M = list(map(int, input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return -1, -1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return x, y def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} bridge = [(list(map(int, input().split()))) for _ in range(M)][::-1] unionfind = UnionFind(N) total = N * (N - 1) // 2 ans = [total] roots = set() size = [0] * (N + 1) not_fuben = 0 for a, b in bridge[:-1]: x, y = unionfind.union(a - 1, b - 1) if x != -1: if x not in roots: roots.add(x) size[x] = 2 not_fuben += 1 else: if y in roots: not_fuben += size[y] * size[x] size[x] += size[y] else: not_fuben += size[x] size[x] += 1 ans.append(total - not_fuben) for a in ans[::-1]: print(a)
N, M = list(map(int, input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return -1, -1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return x, y def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} bridge = [(list(map(int, input().split()))) for _ in range(M)][::-1] unionfind = UnionFind(N) total = N * (N - 1) // 2 ans = [total] roots = set() size = [1] * (N + 1) not_fuben = 0 for a, b in bridge[:-1]: x, y = unionfind.union(a - 1, b - 1) if x != -1: not_fuben += size[y] * size[x] size[x] += size[y] ans.append(total - not_fuben) for a in ans[::-1]: print(a)
74
65
1,812
1,561
N, M = list(map(int, input().split())) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return -1, -1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return x, y def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} bridge = [(list(map(int, input().split()))) for _ in range(M)][::-1] unionfind = UnionFind(N) total = N * (N - 1) // 2 ans = [total] roots = set() size = [0] * (N + 1) not_fuben = 0 for a, b in bridge[:-1]: x, y = unionfind.union(a - 1, b - 1) if x != -1: if x not in roots: roots.add(x) size[x] = 2 not_fuben += 1 else: if y in roots: not_fuben += size[y] * size[x] size[x] += size[y] else: not_fuben += size[x] size[x] += 1 ans.append(total - not_fuben) for a in ans[::-1]: print(a)
N, M = list(map(int, input().split())) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return -1, -1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return x, y def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} bridge = [(list(map(int, input().split()))) for _ in range(M)][::-1] unionfind = UnionFind(N) total = N * (N - 1) // 2 ans = [total] roots = set() size = [1] * (N + 1) not_fuben = 0 for a, b in bridge[:-1]: x, y = unionfind.union(a - 1, b - 1) if x != -1: not_fuben += size[y] * size[x] size[x] += size[y] ans.append(total - not_fuben) for a in ans[::-1]: print(a)
false
12.162162
[ "-size = [0] * (N + 1)", "+size = [1] * (N + 1)", "- if x not in roots:", "- roots.add(x)", "- size[x] = 2", "- not_fuben += 1", "- else:", "- if y in roots:", "- not_fuben += size[y] * size[x]", "- size[x] += size[y]", "- else:", "- not_fuben += size[x]", "- size[x] += 1", "+ not_fuben += size[y] * size[x]", "+ size[x] += size[y]" ]
false
0.0448
0.098011
0.457089
[ "s298718074", "s027427882" ]
u332793228
p02993
python
s488652232
s868003708
22
17
9,052
2,940
Accepted
Accepted
22.73
a,b,c,d=eval(input()) print(("Bad"if a==b or b==c or c==d else"Good"))
s=eval(input()) print(("Good"if s[0]!=s[1]!=s[2]!=s[3] else "Bad"))
2
2
63
60
a, b, c, d = eval(input()) print(("Bad" if a == b or b == c or c == d else "Good"))
s = eval(input()) print(("Good" if s[0] != s[1] != s[2] != s[3] else "Bad"))
false
0
[ "-a, b, c, d = eval(input())", "-print((\"Bad\" if a == b or b == c or c == d else \"Good\"))", "+s = eval(input())", "+print((\"Good\" if s[0] != s[1] != s[2] != s[3] else \"Bad\"))" ]
false
0.036824
0.069179
0.532303
[ "s488652232", "s868003708" ]
u320098990
p03448
python
s368252364
s212332322
54
27
3,060
9,084
Accepted
Accepted
50
# ABC-087_B-Coins A_num = int(eval(input())) B_num = int(eval(input())) C_num = int(eval(input())) X_yen = int(eval(input())) count = 0 for a in range(A_num+1): for b in range(B_num+1): for c in range(C_num+1): total = 500*a + 100*b + 50*c if total == X_yen: count += 1 print(count)
in_a = eval(input()) in_b = eval(input()) in_c = eval(input()) in_x = eval(input()) A = int(in_a) B = int(in_b) C = int(in_c) X = int(in_x) count = 0 for i in range(A+1): for j in range(B+1): k = ( X - 500*i - 100*j ) / 50 # print(f'k:{k}') if k < 0: break; elif k.is_integer() and k <= C: count +=1 # print('clear', k, count) print(count)
16
22
328
411
# ABC-087_B-Coins A_num = int(eval(input())) B_num = int(eval(input())) C_num = int(eval(input())) X_yen = int(eval(input())) count = 0 for a in range(A_num + 1): for b in range(B_num + 1): for c in range(C_num + 1): total = 500 * a + 100 * b + 50 * c if total == X_yen: count += 1 print(count)
in_a = eval(input()) in_b = eval(input()) in_c = eval(input()) in_x = eval(input()) A = int(in_a) B = int(in_b) C = int(in_c) X = int(in_x) count = 0 for i in range(A + 1): for j in range(B + 1): k = (X - 500 * i - 100 * j) / 50 # print(f'k:{k}') if k < 0: break elif k.is_integer() and k <= C: count += 1 # print('clear', k, count) print(count)
false
27.272727
[ "-# ABC-087_B-Coins", "-A_num = int(eval(input()))", "-B_num = int(eval(input()))", "-C_num = int(eval(input()))", "-X_yen = int(eval(input()))", "+in_a = eval(input())", "+in_b = eval(input())", "+in_c = eval(input())", "+in_x = eval(input())", "+A = int(in_a)", "+B = int(in_b)", "+C = int(in_c)", "+X = int(in_x)", "-for a in range(A_num + 1):", "- for b in range(B_num + 1):", "- for c in range(C_num + 1):", "- total = 500 * a + 100 * b + 50 * c", "- if total == X_yen:", "- count += 1", "+for i in range(A + 1):", "+ for j in range(B + 1):", "+ k = (X - 500 * i - 100 * j) / 50", "+ # print(f'k:{k}')", "+ if k < 0:", "+ break", "+ elif k.is_integer() and k <= C:", "+ count += 1", "+ # print('clear', k, count)" ]
false
0.09571
0.036062
2.654051
[ "s368252364", "s212332322" ]
u576917603
p03693
python
s845600983
s995876723
27
19
3,700
2,940
Accepted
Accepted
29.63
a = int(input().replace(" ","")) if a % 4 == 0: print("YES") else: print("NO")
a,b,c=input().split() x=a x+=b x+=c if int(x)%4==0: print('YES') else: print('NO')
7
8
99
97
a = int(input().replace(" ", "")) if a % 4 == 0: print("YES") else: print("NO")
a, b, c = input().split() x = a x += b x += c if int(x) % 4 == 0: print("YES") else: print("NO")
false
12.5
[ "-a = int(input().replace(\" \", \"\"))", "-if a % 4 == 0:", "+a, b, c = input().split()", "+x = a", "+x += b", "+x += c", "+if int(x) % 4 == 0:" ]
false
0.066534
0.037434
1.777366
[ "s845600983", "s995876723" ]
u597455618
p03241
python
s986783637
s065199108
32
28
9,320
9,312
Accepted
Accepted
12.5
def divisor(n): i = 1 res = [] for i in range(1, int(n**.5) + 1): if n%i == 0: res.append(i) if n//i not in res: res.append(n//i) res.sort() return res def main(): n, m = list(map(int, input().split())) md = divisor(m) ans = 0 for i in md: if (m - n*i)%i == 0 and (m - n*i) >= 0: ans = i else: break print(ans) if __name__ == '__main__': main()
def divisor(n): i = 1 res = [] for i in range(1, int(n**.5) + 1): if n%i == 0: res.append(i) if n//i not in res: res.append(n//i) res.sort(reverse=True) return res def main(): n, m = list(map(int, input().split())) md = divisor(m) ans = 0 for i in md: if i*n <= m: print(i) exit() if __name__ == '__main__': main()
24
22
495
451
def divisor(n): i = 1 res = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if n // i not in res: res.append(n // i) res.sort() return res def main(): n, m = list(map(int, input().split())) md = divisor(m) ans = 0 for i in md: if (m - n * i) % i == 0 and (m - n * i) >= 0: ans = i else: break print(ans) if __name__ == "__main__": main()
def divisor(n): i = 1 res = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if n // i not in res: res.append(n // i) res.sort(reverse=True) return res def main(): n, m = list(map(int, input().split())) md = divisor(m) ans = 0 for i in md: if i * n <= m: print(i) exit() if __name__ == "__main__": main()
false
8.333333
[ "- res.sort()", "+ res.sort(reverse=True)", "- if (m - n * i) % i == 0 and (m - n * i) >= 0:", "- ans = i", "- else:", "- break", "- print(ans)", "+ if i * n <= m:", "+ print(i)", "+ exit()" ]
false
0.047578
0.041948
1.13421
[ "s986783637", "s065199108" ]
u541055501
p02577
python
s443074487
s011935464
357
325
84,916
84,940
Accepted
Accepted
8.96
print("YNeos"[int(eval(input()))%9!=0::2])
print("YNeos"[int(eval(input()))%9>0::2])
1
1
34
33
print("YNeos"[int(eval(input())) % 9 != 0 :: 2])
print("YNeos"[int(eval(input())) % 9 > 0 :: 2])
false
0
[ "-print(\"YNeos\"[int(eval(input())) % 9 != 0 :: 2])", "+print(\"YNeos\"[int(eval(input())) % 9 > 0 :: 2])" ]
false
0.075084
0.072577
1.03454
[ "s443074487", "s011935464" ]
u131464432
p03086
python
s780598450
s277425764
31
26
9,024
9,040
Accepted
Accepted
16.13
s = eval(input()) left = 0 ans = 0 for right in range(0,len(s)): if s[right] in ("A","C","G","T"): pass else: left=right+1 ans = max(ans,right-left+1) print(ans)
s = eval(input()) ans = 0 for i in range(len(s)): for j in range(i,len(s)): if all("ATGC".count(c) == 1 for c in s[i:j+1]): ans = max(ans,j-i+1) print(ans)
10
7
178
167
s = eval(input()) left = 0 ans = 0 for right in range(0, len(s)): if s[right] in ("A", "C", "G", "T"): pass else: left = right + 1 ans = max(ans, right - left + 1) print(ans)
s = eval(input()) ans = 0 for i in range(len(s)): for j in range(i, len(s)): if all("ATGC".count(c) == 1 for c in s[i : j + 1]): ans = max(ans, j - i + 1) print(ans)
false
30
[ "-left = 0", "-for right in range(0, len(s)):", "- if s[right] in (\"A\", \"C\", \"G\", \"T\"):", "- pass", "- else:", "- left = right + 1", "- ans = max(ans, right - left + 1)", "+for i in range(len(s)):", "+ for j in range(i, len(s)):", "+ if all(\"ATGC\".count(c) == 1 for c in s[i : j + 1]):", "+ ans = max(ans, j - i + 1)" ]
false
0.034696
0.035534
0.976425
[ "s780598450", "s277425764" ]
u645250356
p03739
python
s122523016
s644311954
159
135
16,392
16,392
Accepted
Accepted
15.09
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,fractions mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def inpl_str(): return list(sys.stdin.readline().split()) def lcm(x, y): return (x * y) // fractions.gcd(x, y) n = inp() a = inpl() acc = list(itertools.accumulate(a)) #+-+-+- cnt = 0 tmp = 0 for i in range(n): if i%2==0: tt = acc[i] + tmp if tt <= 0: cnt += 1 - tt tmp += 1 - tt else: tt = acc[i] + tmp if tt >= 0: cnt += tt + 1 tmp -= tt + 1 ans = cnt #-+-+-+ cnt = 0 tmp = 0 for i in range(n): if i%2: tt = acc[i] + tmp if tt <= 0: cnt += 1 - tt tmp += 1 - tt else: tt = acc[i] + tmp if tt >= 0: cnt += tt + 1 tmp -= tt + 1 # print(i,cnt,tmp,tt) print((min(ans,cnt)))
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() now = 0 res = INF cnt = 0 for i in range(n): now += a[i] if i%2 == 0: if now <= 0: cnt += 1-now now = 1 else: if now >= 0: cnt += now+1 now = -1 # print(i,now,cnt) res = min(res,cnt) now = 0 cnt = 0 for i in range(n): now += a[i] if i%2: if now <= 0: cnt += -now + 1 now = 1 else: if now >= 0: cnt += now + 1 now = -1 # print(i,now,cnt) res = min(res,cnt) print(res)
44
42
1,095
944
from collections import Counter, defaultdict import sys, heapq, bisect, math, itertools, string, queue, fractions mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def inpl_str(): return list(sys.stdin.readline().split()) def lcm(x, y): return (x * y) // fractions.gcd(x, y) n = inp() a = inpl() acc = list(itertools.accumulate(a)) # +-+-+- cnt = 0 tmp = 0 for i in range(n): if i % 2 == 0: tt = acc[i] + tmp if tt <= 0: cnt += 1 - tt tmp += 1 - tt else: tt = acc[i] + tmp if tt >= 0: cnt += tt + 1 tmp -= tt + 1 ans = cnt # -+-+-+ cnt = 0 tmp = 0 for i in range(n): if i % 2: tt = acc[i] + tmp if tt <= 0: cnt += 1 - tt tmp += 1 - tt else: tt = acc[i] + tmp if tt >= 0: cnt += tt + 1 tmp -= tt + 1 # print(i,cnt,tmp,tt) print((min(ans, cnt)))
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() now = 0 res = INF cnt = 0 for i in range(n): now += a[i] if i % 2 == 0: if now <= 0: cnt += 1 - now now = 1 else: if now >= 0: cnt += now + 1 now = -1 # print(i,now,cnt) res = min(res, cnt) now = 0 cnt = 0 for i in range(n): now += a[i] if i % 2: if now <= 0: cnt += -now + 1 now = 1 else: if now >= 0: cnt += now + 1 now = -1 # print(i,now,cnt) res = min(res, cnt) print(res)
false
4.545455
[ "-from collections import Counter, defaultdict", "-import sys, heapq, bisect, math, itertools, string, queue, fractions", "+from collections import Counter, defaultdict, deque", "+from heapq import heappop, heappush, heapify", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "+sys.setrecursionlimit(10**8)", "+INF = float(\"inf\")", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def lcm(x, y):", "- return (x * y) // fractions.gcd(x, y)", "-", "-", "-acc = list(itertools.accumulate(a))", "-# +-+-+-", "+now = 0", "+res = INF", "-tmp = 0", "+ now += a[i]", "- tt = acc[i] + tmp", "- if tt <= 0:", "- cnt += 1 - tt", "- tmp += 1 - tt", "+ if now <= 0:", "+ cnt += 1 - now", "+ now = 1", "- tt = acc[i] + tmp", "- if tt >= 0:", "- cnt += tt + 1", "- tmp -= tt + 1", "-ans = cnt", "-# -+-+-+", "+ if now >= 0:", "+ cnt += now + 1", "+ now = -1", "+ # print(i,now,cnt)", "+res = min(res, cnt)", "+now = 0", "-tmp = 0", "+ now += a[i]", "- tt = acc[i] + tmp", "- if tt <= 0:", "- cnt += 1 - tt", "- tmp += 1 - tt", "+ if now <= 0:", "+ cnt += -now + 1", "+ now = 1", "- tt = acc[i] + tmp", "- if tt >= 0:", "- cnt += tt + 1", "- tmp -= tt + 1", "- # print(i,cnt,tmp,tt)", "-print((min(ans, cnt)))", "+ if now >= 0:", "+ cnt += now + 1", "+ now = -1", "+ # print(i,now,cnt)", "+res = min(res, cnt)", "+print(res)" ]
false
0.050434
0.04258
1.184461
[ "s122523016", "s644311954" ]
u246033265
p00008
python
s566096371
s975739576
20
10
4,232
4,236
Accepted
Accepted
50
memo = [[None for i in range(51)] for j in range(5)] memo[0][0] = 1 for i in range(1, 51): memo[0][i] = 0 def f(n, sm): if memo[n][sm] is not None: return memo[n][sm] memo[n][sm] = 0 for i in range(min(10, sm + 1)): memo[n][sm] += f(n - 1, sm - i) return memo[n][sm] try: while True: print(f(4, int(input()))) except: pass
def mlist(n, *args, **keys): if len(args) == 0: return [keys.get('default')] * n else: return [mlist(*args, **keys) for i in range(n)] def f(n, sm): if n == 0: return int(sm == 0) if memo[n][sm] is not None: return memo[n][sm] memo[n][sm] = 0 for i in range(min(10, sm + 1)): memo[n][sm] += f(n - 1, sm - i) return memo[n][sm] try: memo = mlist(5, 51) while True: print(f(4, int(input()))) except EOFError: pass
19
23
398
591
memo = [[None for i in range(51)] for j in range(5)] memo[0][0] = 1 for i in range(1, 51): memo[0][i] = 0 def f(n, sm): if memo[n][sm] is not None: return memo[n][sm] memo[n][sm] = 0 for i in range(min(10, sm + 1)): memo[n][sm] += f(n - 1, sm - i) return memo[n][sm] try: while True: print(f(4, int(input()))) except: pass
def mlist(n, *args, **keys): if len(args) == 0: return [keys.get("default")] * n else: return [mlist(*args, **keys) for i in range(n)] def f(n, sm): if n == 0: return int(sm == 0) if memo[n][sm] is not None: return memo[n][sm] memo[n][sm] = 0 for i in range(min(10, sm + 1)): memo[n][sm] += f(n - 1, sm - i) return memo[n][sm] try: memo = mlist(5, 51) while True: print(f(4, int(input()))) except EOFError: pass
false
17.391304
[ "-memo = [[None for i in range(51)] for j in range(5)]", "-memo[0][0] = 1", "-for i in range(1, 51):", "- memo[0][i] = 0", "+def mlist(n, *args, **keys):", "+ if len(args) == 0:", "+ return [keys.get(\"default\")] * n", "+ else:", "+ return [mlist(*args, **keys) for i in range(n)]", "+ if n == 0:", "+ return int(sm == 0)", "+ memo = mlist(5, 51)", "-except:", "+except EOFError:" ]
false
0.167942
0.110027
1.526369
[ "s566096371", "s975739576" ]
u013629972
p03147
python
s928881524
s749177468
741
166
12,320
12,468
Accepted
Accepted
77.6
import sys import numpy as np # sys.setrecursionlimit(10**7) # inf = 10 ** 20 # eps = 1.0 / 10**10 # mod = 10**9+7 # dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] # ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N = I() h = LI() h = np.array(h) # print(N, h) # 0以上の塊をみつける # その塊に水をやる # 以上を繰り返す count = 0 while True: # print(h) first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0] if len(first_non_zero_idx) == 0: # 終了 print(count) return else: first_non_zero_idx = first_non_zero_idx[0] first_zero_idx = [idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0] if len(first_zero_idx) == 0: # 0がないので最後まで水をやる first_zero_idx = len(h) else: first_zero_idx = first_zero_idx[0] # 水をやる h[first_non_zero_idx:first_zero_idx] -= 1 count += 1 main()
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools import sys import numpy as np # sys.setrecursionlimit(10**7) # inf = 10 ** 20 # eps = 1.0 / 10**10 # mod = 10**9+7 # dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] # ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N = I() h = LI() h = np.array(h) # print(N, h) # 0以上の塊をみつける # その塊に水をやる # 以上を繰り返す count = 0 while True: # print(h) first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0] if len(first_non_zero_idx) == 0: # 終了 print(count) return else: first_non_zero_idx = first_non_zero_idx[0] first_zero_idx = [idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0] if len(first_zero_idx) == 0: # 0がないので最後まで水をやる first_zero_idx = len(h) else: first_zero_idx = first_zero_idx[0] # 水をやる min_value = min(h[first_non_zero_idx:first_zero_idx]) h[first_non_zero_idx:first_zero_idx] -= min_value count += min_value main()
56
58
1,467
1,668
import sys import numpy as np # sys.setrecursionlimit(10**7) # inf = 10 ** 20 # eps = 1.0 / 10**10 # mod = 10**9+7 # dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] # ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N = I() h = LI() h = np.array(h) # print(N, h) # 0以上の塊をみつける # その塊に水をやる # 以上を繰り返す count = 0 while True: # print(h) first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0] if len(first_non_zero_idx) == 0: # 終了 print(count) return else: first_non_zero_idx = first_non_zero_idx[0] first_zero_idx = [ idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0 ] if len(first_zero_idx) == 0: # 0がないので最後まで水をやる first_zero_idx = len(h) else: first_zero_idx = first_zero_idx[0] # 水をやる h[first_non_zero_idx:first_zero_idx] -= 1 count += 1 main()
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools import sys import numpy as np # sys.setrecursionlimit(10**7) # inf = 10 ** 20 # eps = 1.0 / 10**10 # mod = 10**9+7 # dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] # ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N = I() h = LI() h = np.array(h) # print(N, h) # 0以上の塊をみつける # その塊に水をやる # 以上を繰り返す count = 0 while True: # print(h) first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0] if len(first_non_zero_idx) == 0: # 終了 print(count) return else: first_non_zero_idx = first_non_zero_idx[0] first_zero_idx = [ idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0 ] if len(first_zero_idx) == 0: # 0がないので最後まで水をやる first_zero_idx = len(h) else: first_zero_idx = first_zero_idx[0] # 水をやる min_value = min(h[first_non_zero_idx:first_zero_idx]) h[first_non_zero_idx:first_zero_idx] -= min_value count += min_value main()
false
3.448276
[ "+# import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools", "- h[first_non_zero_idx:first_zero_idx] -= 1", "- count += 1", "+ min_value = min(h[first_non_zero_idx:first_zero_idx])", "+ h[first_non_zero_idx:first_zero_idx] -= min_value", "+ count += min_value" ]
false
0.576367
0.33179
1.737143
[ "s928881524", "s749177468" ]
u844646164
p03435
python
s659475710
s543428762
153
73
12,480
61,804
Accepted
Accepted
52.29
import numpy as np C = np.array([list(map(int, input().split())) for _ in range(3)]) c12 = C[1]-C[0] c23 = C[2]-C[1] if len(set(c12)) == 1 and len(set(c23)) == 1: CT = C.T ct12 = CT[1]-CT[0] ct23 = CT[2]-CT[1] if len(set(ct12)) == 1 and len(set(ct23)) == 1: print('Yes') else: print('No') else: print('No')
c = [list(map(int, input().split())) for _ in range(3)] x1 = c[0][0]-c[1][0] x2 = c[0][1]-c[1][1] x3 = c[0][2]-c[1][2] x4 = c[1][0]-c[2][0] x5 = c[1][1]-c[2][1] x6 = c[1][2]-c[2][2] if x1==x2 and x2==x3: pass else: print('No') exit() if x4==x5 and x5==x6: pass else: print('No') exit() x1 = c[0][0]-c[0][1] x2 = c[1][0]-c[1][1] x3 = c[2][0]-c[2][1] x4 = c[0][1]-c[0][2] x5 = c[1][1]-c[1][2] x6 = c[2][1]-c[2][2] if x1==x2 and x2==x3: pass else: print('No') exit() if x4==x5 and x5==x6: pass else: print('No') exit() print('Yes')
14
40
360
625
import numpy as np C = np.array([list(map(int, input().split())) for _ in range(3)]) c12 = C[1] - C[0] c23 = C[2] - C[1] if len(set(c12)) == 1 and len(set(c23)) == 1: CT = C.T ct12 = CT[1] - CT[0] ct23 = CT[2] - CT[1] if len(set(ct12)) == 1 and len(set(ct23)) == 1: print("Yes") else: print("No") else: print("No")
c = [list(map(int, input().split())) for _ in range(3)] x1 = c[0][0] - c[1][0] x2 = c[0][1] - c[1][1] x3 = c[0][2] - c[1][2] x4 = c[1][0] - c[2][0] x5 = c[1][1] - c[2][1] x6 = c[1][2] - c[2][2] if x1 == x2 and x2 == x3: pass else: print("No") exit() if x4 == x5 and x5 == x6: pass else: print("No") exit() x1 = c[0][0] - c[0][1] x2 = c[1][0] - c[1][1] x3 = c[2][0] - c[2][1] x4 = c[0][1] - c[0][2] x5 = c[1][1] - c[1][2] x6 = c[2][1] - c[2][2] if x1 == x2 and x2 == x3: pass else: print("No") exit() if x4 == x5 and x5 == x6: pass else: print("No") exit() print("Yes")
false
65
[ "-import numpy as np", "-", "-C = np.array([list(map(int, input().split())) for _ in range(3)])", "-c12 = C[1] - C[0]", "-c23 = C[2] - C[1]", "-if len(set(c12)) == 1 and len(set(c23)) == 1:", "- CT = C.T", "- ct12 = CT[1] - CT[0]", "- ct23 = CT[2] - CT[1]", "- if len(set(ct12)) == 1 and len(set(ct23)) == 1:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+c = [list(map(int, input().split())) for _ in range(3)]", "+x1 = c[0][0] - c[1][0]", "+x2 = c[0][1] - c[1][1]", "+x3 = c[0][2] - c[1][2]", "+x4 = c[1][0] - c[2][0]", "+x5 = c[1][1] - c[2][1]", "+x6 = c[1][2] - c[2][2]", "+if x1 == x2 and x2 == x3:", "+ pass", "+ exit()", "+if x4 == x5 and x5 == x6:", "+ pass", "+else:", "+ print(\"No\")", "+ exit()", "+x1 = c[0][0] - c[0][1]", "+x2 = c[1][0] - c[1][1]", "+x3 = c[2][0] - c[2][1]", "+x4 = c[0][1] - c[0][2]", "+x5 = c[1][1] - c[1][2]", "+x6 = c[2][1] - c[2][2]", "+if x1 == x2 and x2 == x3:", "+ pass", "+else:", "+ print(\"No\")", "+ exit()", "+if x4 == x5 and x5 == x6:", "+ pass", "+else:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.447106
0.063902
6.996772
[ "s659475710", "s543428762" ]
u645250356
p03945
python
s587226175
s585853589
192
133
40,428
77,116
Accepted
Accepted
30.73
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) s = eval(input()) n = len(s) cnt = 1 for i in range(n): if i == 0: tmp = s[i] else: if s[i] == tmp: continue cnt += 1 tmp = s[i] if s[i] != tmp: cnt += 1 print((cnt-1))
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) s = eval(input()) now = -1 res = -1 for x in s: if now != x: res += 1 now = x print(res)
23
18
616
471
from collections import Counter, defaultdict import sys, heapq, bisect, math, itertools, string, queue sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) s = eval(input()) n = len(s) cnt = 1 for i in range(n): if i == 0: tmp = s[i] else: if s[i] == tmp: continue cnt += 1 tmp = s[i] if s[i] != tmp: cnt += 1 print((cnt - 1))
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) s = eval(input()) now = -1 res = -1 for x in s: if now != x: res += 1 now = x print(res)
false
21.73913
[ "-from collections import Counter, defaultdict", "-import sys, heapq, bisect, math, itertools, string, queue", "+from collections import Counter, defaultdict, deque", "+from heapq import heappop, heappush, heapify", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "+INF = float(\"inf\")", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-n = len(s)", "-cnt = 1", "-for i in range(n):", "- if i == 0:", "- tmp = s[i]", "- else:", "- if s[i] == tmp:", "- continue", "- cnt += 1", "- tmp = s[i]", "-if s[i] != tmp:", "- cnt += 1", "-print((cnt - 1))", "+now = -1", "+res = -1", "+for x in s:", "+ if now != x:", "+ res += 1", "+ now = x", "+print(res)" ]
false
0.037438
0.037702
0.993005
[ "s587226175", "s585853589" ]
u583507988
p03998
python
s710184394
s267653041
28
25
8,940
8,980
Accepted
Accepted
10.71
sa = eval(input()) sb = eval(input()) sc = eval(input()) a = [sa[i] for i in range(len(sa))] b = [sb[i] for i in range(len(sb))] c = [sc[i] for i in range(len(sc))] n = 'a' while True: if n == 'a': if len(a) == 0: print('A') exit() else: n = a.pop(0) elif n == 'b': if len(b) == 0: print('B') exit() else: n = b.pop(0) elif n == 'c': if len(c) == 0: print('C') exit() else: n = c.pop(0)
sa=eval(input())+'a' sb=eval(input())+'b' sc=eval(input())+'c' st='a' a=0 b=0 c=0 while a<len(sa) and b<len(sb) and c<len(sc): if st=='a': st=sa[a] a+=1 elif st=='b': st=sb[b] b+=1 else: st=sc[c] c+=1 if a==len(sa): print('A') elif b==len(sb): print('B') else: print('C')
27
23
479
311
sa = eval(input()) sb = eval(input()) sc = eval(input()) a = [sa[i] for i in range(len(sa))] b = [sb[i] for i in range(len(sb))] c = [sc[i] for i in range(len(sc))] n = "a" while True: if n == "a": if len(a) == 0: print("A") exit() else: n = a.pop(0) elif n == "b": if len(b) == 0: print("B") exit() else: n = b.pop(0) elif n == "c": if len(c) == 0: print("C") exit() else: n = c.pop(0)
sa = eval(input()) + "a" sb = eval(input()) + "b" sc = eval(input()) + "c" st = "a" a = 0 b = 0 c = 0 while a < len(sa) and b < len(sb) and c < len(sc): if st == "a": st = sa[a] a += 1 elif st == "b": st = sb[b] b += 1 else: st = sc[c] c += 1 if a == len(sa): print("A") elif b == len(sb): print("B") else: print("C")
false
14.814815
[ "-sa = eval(input())", "-sb = eval(input())", "-sc = eval(input())", "-a = [sa[i] for i in range(len(sa))]", "-b = [sb[i] for i in range(len(sb))]", "-c = [sc[i] for i in range(len(sc))]", "-n = \"a\"", "-while True:", "- if n == \"a\":", "- if len(a) == 0:", "- print(\"A\")", "- exit()", "- else:", "- n = a.pop(0)", "- elif n == \"b\":", "- if len(b) == 0:", "- print(\"B\")", "- exit()", "- else:", "- n = b.pop(0)", "- elif n == \"c\":", "- if len(c) == 0:", "- print(\"C\")", "- exit()", "- else:", "- n = c.pop(0)", "+sa = eval(input()) + \"a\"", "+sb = eval(input()) + \"b\"", "+sc = eval(input()) + \"c\"", "+st = \"a\"", "+a = 0", "+b = 0", "+c = 0", "+while a < len(sa) and b < len(sb) and c < len(sc):", "+ if st == \"a\":", "+ st = sa[a]", "+ a += 1", "+ elif st == \"b\":", "+ st = sb[b]", "+ b += 1", "+ else:", "+ st = sc[c]", "+ c += 1", "+if a == len(sa):", "+ print(\"A\")", "+elif b == len(sb):", "+ print(\"B\")", "+else:", "+ print(\"C\")" ]
false
0.048367
0.04839
0.999535
[ "s710184394", "s267653041" ]
u832409298
p02925
python
s581955389
s025416110
1,405
1,291
177,380
176,872
Accepted
Accepted
8.11
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10 ** 18 MOD = 10 ** 9 + 7 def conv(n,a,b): return a*(2*n-a-1)//2+b-a-1 def main(): N = II() # A = [[] for _ in range(N)] # for i in range(N): # A[i] = LI() # print(A) # return from collections import defaultdict outs = defaultdict(list) ins = defaultdict(int) for i in range(N): # prev_v = (i+1, A[i][0]) if i+1 < A[i][0] else (A[i][0], i+1) a = LI() for j in range(1,N-1): # prev_v = (i+1, A[i][j-1]) if i+1 < A[i][j-1] else (A[i][j-1], i+1) # next_v = (i+1, A[i][j]) if (i+1 < A[i][j]) else (A[i][j] , i+1) # prev_v = conv(N, prev_v[0], prev_v[1]) # next_v = conv(N, next_v[0], next_v[1]) prev_v = (min(i+1, a[j-1]), max(i+1, a[j-1])) next_v = (min(i+1, a[j]), max(i+1, a[j])) prev_v = conv(N, prev_v[0]-1, prev_v[1]-1) next_v = conv(N, next_v[0]-1, next_v[1]-1) outs[prev_v].append(next_v) ins[next_v] += 1 # print(outs, ins) # return from collections import deque q = deque() for i in range(1, N+1): for j in range(1, N+1): # j = A[i-1][0] if i < j and ins[conv(N, i-1, j-1)] == 0: q.append([conv(N, i-1, j-1), 0]) if not q: print((-1)) return # q = deque(v1 for v1 in range(1, N+1) if ins[v1] == 0) res = [] depth_max = 0 while q: v1, depth = q.popleft() res.append(v1) for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append([v2, depth+1]) depth_max = max(depth_max, depth+1) if len(res)!=N*(N-1)//2: print((-1)) return else: print((depth_max+1)) return main()
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10 ** 18 MOD = 10 ** 9 + 7 def conv(a, b, b_max): return a*(b_max+1)+b def main(): N = II() # A = [[] for _ in range(N)] # for i in range(N): # A[i] = LI() # print(A) # return from collections import defaultdict outs = defaultdict(list) ins = defaultdict(int) for i in range(N): # prev_v = (i+1, A[i][0]) if i+1 < A[i][0] else (A[i][0], i+1) a = LI() for j in range(1,N-1): # prev_v = (i+1, A[i][j-1]) if i+1 < A[i][j-1] else (A[i][j-1], i+1) # next_v = (i+1, A[i][j]) if (i+1 < A[i][j]) else (A[i][j] , i+1) # prev_v = conv(N, prev_v[0], prev_v[1]) # next_v = conv(N, next_v[0], next_v[1]) prev_v = (min(i+1, a[j-1]), max(i+1, a[j-1])) next_v = (min(i+1, a[j]), max(i+1, a[j])) prev_v = conv(prev_v[0]-1, prev_v[1]-1, N) next_v = conv( next_v[0]-1, next_v[1]-1, N) outs[prev_v].append(next_v) ins[next_v] += 1 # print(outs, ins) # return from collections import deque q = deque() for i in range(1, N+1): for j in range(1, N+1): # j = A[i-1][0] if i < j and ins[conv(i-1, j-1, N)] == 0: q.append([conv( i-1, j-1, N), 0]) if not q: print((-1)) return # q = deque(v1 for v1 in range(1, N+1) if ins[v1] == 0) res = [] depth_max = 0 while q: v1, depth = q.popleft() res.append(v1) for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append([v2, depth+1]) depth_max = max(depth_max, depth+1) if len(res)!=N*(N-1)//2: print((-1)) return else: print((depth_max+1)) return main()
77
76
2,244
2,243
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10**18 MOD = 10**9 + 7 def conv(n, a, b): return a * (2 * n - a - 1) // 2 + b - a - 1 def main(): N = II() # A = [[] for _ in range(N)] # for i in range(N): # A[i] = LI() # print(A) # return from collections import defaultdict outs = defaultdict(list) ins = defaultdict(int) for i in range(N): # prev_v = (i+1, A[i][0]) if i+1 < A[i][0] else (A[i][0], i+1) a = LI() for j in range(1, N - 1): # prev_v = (i+1, A[i][j-1]) if i+1 < A[i][j-1] else (A[i][j-1], i+1) # next_v = (i+1, A[i][j]) if (i+1 < A[i][j]) else (A[i][j] , i+1) # prev_v = conv(N, prev_v[0], prev_v[1]) # next_v = conv(N, next_v[0], next_v[1]) prev_v = (min(i + 1, a[j - 1]), max(i + 1, a[j - 1])) next_v = (min(i + 1, a[j]), max(i + 1, a[j])) prev_v = conv(N, prev_v[0] - 1, prev_v[1] - 1) next_v = conv(N, next_v[0] - 1, next_v[1] - 1) outs[prev_v].append(next_v) ins[next_v] += 1 # print(outs, ins) # return from collections import deque q = deque() for i in range(1, N + 1): for j in range(1, N + 1): # j = A[i-1][0] if i < j and ins[conv(N, i - 1, j - 1)] == 0: q.append([conv(N, i - 1, j - 1), 0]) if not q: print((-1)) return # q = deque(v1 for v1 in range(1, N+1) if ins[v1] == 0) res = [] depth_max = 0 while q: v1, depth = q.popleft() res.append(v1) for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append([v2, depth + 1]) depth_max = max(depth_max, depth + 1) if len(res) != N * (N - 1) // 2: print((-1)) return else: print((depth_max + 1)) return main()
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10**18 MOD = 10**9 + 7 def conv(a, b, b_max): return a * (b_max + 1) + b def main(): N = II() # A = [[] for _ in range(N)] # for i in range(N): # A[i] = LI() # print(A) # return from collections import defaultdict outs = defaultdict(list) ins = defaultdict(int) for i in range(N): # prev_v = (i+1, A[i][0]) if i+1 < A[i][0] else (A[i][0], i+1) a = LI() for j in range(1, N - 1): # prev_v = (i+1, A[i][j-1]) if i+1 < A[i][j-1] else (A[i][j-1], i+1) # next_v = (i+1, A[i][j]) if (i+1 < A[i][j]) else (A[i][j] , i+1) # prev_v = conv(N, prev_v[0], prev_v[1]) # next_v = conv(N, next_v[0], next_v[1]) prev_v = (min(i + 1, a[j - 1]), max(i + 1, a[j - 1])) next_v = (min(i + 1, a[j]), max(i + 1, a[j])) prev_v = conv(prev_v[0] - 1, prev_v[1] - 1, N) next_v = conv(next_v[0] - 1, next_v[1] - 1, N) outs[prev_v].append(next_v) ins[next_v] += 1 # print(outs, ins) # return from collections import deque q = deque() for i in range(1, N + 1): for j in range(1, N + 1): # j = A[i-1][0] if i < j and ins[conv(i - 1, j - 1, N)] == 0: q.append([conv(i - 1, j - 1, N), 0]) if not q: print((-1)) return # q = deque(v1 for v1 in range(1, N+1) if ins[v1] == 0) res = [] depth_max = 0 while q: v1, depth = q.popleft() res.append(v1) for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append([v2, depth + 1]) depth_max = max(depth_max, depth + 1) if len(res) != N * (N - 1) // 2: print((-1)) return else: print((depth_max + 1)) return main()
false
1.298701
[ "-def conv(n, a, b):", "- return a * (2 * n - a - 1) // 2 + b - a - 1", "+def conv(a, b, b_max):", "+ return a * (b_max + 1) + b", "- prev_v = conv(N, prev_v[0] - 1, prev_v[1] - 1)", "- next_v = conv(N, next_v[0] - 1, next_v[1] - 1)", "+ prev_v = conv(prev_v[0] - 1, prev_v[1] - 1, N)", "+ next_v = conv(next_v[0] - 1, next_v[1] - 1, N)", "- if i < j and ins[conv(N, i - 1, j - 1)] == 0:", "- q.append([conv(N, i - 1, j - 1), 0])", "+ if i < j and ins[conv(i - 1, j - 1, N)] == 0:", "+ q.append([conv(i - 1, j - 1, N), 0])" ]
false
0.045111
0.048737
0.925597
[ "s581955389", "s025416110" ]
u002459665
p03048
python
s280266592
s555633272
1,812
1,104
2,940
3,060
Accepted
Accepted
39.07
r, g, b, n = list(map(int, input().split())) cnt = 0 for i in range(int(n//r)+1): r_num = r * i for j in range(int((n - r_num)//g)+1): g_num = g * j b_num = (n - r_num - g_num) if b_num >= 0 and b_num % b == 0: cnt += 1 print(cnt)
def main(): r, g, b, n = list(map(int, input().split())) cnt = 0 for i in range(int(n//r)+1): r_num = r * i for j in range(int((n - r_num)//g)+1): g_num = g * j b_num = (n - r_num - g_num) if b_num >= 0 and b_num % b == 0: cnt += 1 print(cnt) if __name__ == "__main__": main()
12
18
282
380
r, g, b, n = list(map(int, input().split())) cnt = 0 for i in range(int(n // r) + 1): r_num = r * i for j in range(int((n - r_num) // g) + 1): g_num = g * j b_num = n - r_num - g_num if b_num >= 0 and b_num % b == 0: cnt += 1 print(cnt)
def main(): r, g, b, n = list(map(int, input().split())) cnt = 0 for i in range(int(n // r) + 1): r_num = r * i for j in range(int((n - r_num) // g) + 1): g_num = g * j b_num = n - r_num - g_num if b_num >= 0 and b_num % b == 0: cnt += 1 print(cnt) if __name__ == "__main__": main()
false
33.333333
[ "-r, g, b, n = list(map(int, input().split()))", "-cnt = 0", "-for i in range(int(n // r) + 1):", "- r_num = r * i", "- for j in range(int((n - r_num) // g) + 1):", "- g_num = g * j", "- b_num = n - r_num - g_num", "- if b_num >= 0 and b_num % b == 0:", "- cnt += 1", "-print(cnt)", "+def main():", "+ r, g, b, n = list(map(int, input().split()))", "+ cnt = 0", "+ for i in range(int(n // r) + 1):", "+ r_num = r * i", "+ for j in range(int((n - r_num) // g) + 1):", "+ g_num = g * j", "+ b_num = n - r_num - g_num", "+ if b_num >= 0 and b_num % b == 0:", "+ cnt += 1", "+ print(cnt)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.102186
0.049448
2.066559
[ "s280266592", "s555633272" ]
u387774811
p03166
python
s780246114
s218694589
1,609
951
186,956
182,732
Accepted
Accepted
40.89
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N,M = list(map(int,input().split())) lst=[{} for f in range(N)] for i in range(M): x,y=list(map(int,input().split())) lst[x-1][y-1]=1 memo = {} def cost(a): ans=0 for i in lst[a]: if i in memo: ans=max(memo[i]+1,ans) else: ans=max(cost(i)+1,ans) memo[a]=ans return ans T=0 for i in range(N): T=max(T,cost(i)) print(T)
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N,M = list(map(int,input().split())) lst=[{} for f in range(N)] for i in range(M): x,y=list(map(int,input().split())) lst[x-1][y-1]=1 memo = {} def cost(a): ans=0 if a in memo: return memo[a] else: for i in lst[a]: if i in memo: ans=max(memo[i]+1,ans) else: ans=max(cost(i)+1,ans) memo[a]=ans return ans T=0 for i in range(N): T=max(T,cost(i)) print(T)
22
25
413
460
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N, M = list(map(int, input().split())) lst = [{} for f in range(N)] for i in range(M): x, y = list(map(int, input().split())) lst[x - 1][y - 1] = 1 memo = {} def cost(a): ans = 0 for i in lst[a]: if i in memo: ans = max(memo[i] + 1, ans) else: ans = max(cost(i) + 1, ans) memo[a] = ans return ans T = 0 for i in range(N): T = max(T, cost(i)) print(T)
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N, M = list(map(int, input().split())) lst = [{} for f in range(N)] for i in range(M): x, y = list(map(int, input().split())) lst[x - 1][y - 1] = 1 memo = {} def cost(a): ans = 0 if a in memo: return memo[a] else: for i in lst[a]: if i in memo: ans = max(memo[i] + 1, ans) else: ans = max(cost(i) + 1, ans) memo[a] = ans return ans T = 0 for i in range(N): T = max(T, cost(i)) print(T)
false
12
[ "- for i in lst[a]:", "- if i in memo:", "- ans = max(memo[i] + 1, ans)", "- else:", "- ans = max(cost(i) + 1, ans)", "- memo[a] = ans", "- return ans", "+ if a in memo:", "+ return memo[a]", "+ else:", "+ for i in lst[a]:", "+ if i in memo:", "+ ans = max(memo[i] + 1, ans)", "+ else:", "+ ans = max(cost(i) + 1, ans)", "+ memo[a] = ans", "+ return ans" ]
false
0.041086
0.042287
0.971599
[ "s780246114", "s218694589" ]
u504469481
p03545
python
s262611188
s795095371
19
17
3,188
3,060
Accepted
Accepted
10.53
def dfs(i, sum, n, s, k): # n 個決め終わったら、今までの和 sum が k と等しいかを返す if i == n - 1: # print(sum) if eval(sum) == k: print((sum+"=7")) return eval(sum) == k # + を使う if dfs(i + 1, sum + "-" + s[i+1],n,s,k): return True # - を使う if dfs(i + 1, sum + "+" + s[i+1],n,s,k): return True # print(sum) return False def main(): s = eval(input()) n = len(s) k = 7 if dfs(0, s[0], n, s,k): pass else: pass if __name__ == '__main__': main()
s = eval(input()) n = len(s) def dfs(i, f): if i == n-1: if eval(f)==7: print((f+"=7")) exit() else: return False else: dfs(i+1,f + "+" + s[i+1]) dfs(i+1,f + "-" + s[i+1]) def main(): if dfs(0,s[0]): exit() if __name__ == '__main__': main()
28
21
570
354
def dfs(i, sum, n, s, k): # n 個決め終わったら、今までの和 sum が k と等しいかを返す if i == n - 1: # print(sum) if eval(sum) == k: print((sum + "=7")) return eval(sum) == k # + を使う if dfs(i + 1, sum + "-" + s[i + 1], n, s, k): return True # - を使う if dfs(i + 1, sum + "+" + s[i + 1], n, s, k): return True # print(sum) return False def main(): s = eval(input()) n = len(s) k = 7 if dfs(0, s[0], n, s, k): pass else: pass if __name__ == "__main__": main()
s = eval(input()) n = len(s) def dfs(i, f): if i == n - 1: if eval(f) == 7: print((f + "=7")) exit() else: return False else: dfs(i + 1, f + "+" + s[i + 1]) dfs(i + 1, f + "-" + s[i + 1]) def main(): if dfs(0, s[0]): exit() if __name__ == "__main__": main()
false
25
[ "-def dfs(i, sum, n, s, k):", "- # n 個決め終わったら、今までの和 sum が k と等しいかを返す", "+s = eval(input())", "+n = len(s)", "+", "+", "+def dfs(i, f):", "- # print(sum)", "- if eval(sum) == k:", "- print((sum + \"=7\"))", "- return eval(sum) == k", "- # + を使う", "- if dfs(i + 1, sum + \"-\" + s[i + 1], n, s, k):", "- return True", "- # - を使う", "- if dfs(i + 1, sum + \"+\" + s[i + 1], n, s, k):", "- return True", "- # print(sum)", "- return False", "+ if eval(f) == 7:", "+ print((f + \"=7\"))", "+ exit()", "+ else:", "+ return False", "+ else:", "+ dfs(i + 1, f + \"+\" + s[i + 1])", "+ dfs(i + 1, f + \"-\" + s[i + 1])", "- s = eval(input())", "- n = len(s)", "- k = 7", "- if dfs(0, s[0], n, s, k):", "- pass", "- else:", "- pass", "+ if dfs(0, s[0]):", "+ exit()" ]
false
0.042102
0.042087
1.000366
[ "s262611188", "s795095371" ]
u887207211
p03329
python
s508615035
s021971778
23
19
3,572
3,064
Accepted
Accepted
17.39
N = int(eval(input())) sixs = [6**i for i in range(1,7)] nines = [9**i for i in range(1,6)] tmp = {} def dfs(n): if(n < 6): return n if(n in tmp): return tmp[n] m = 10**9+7 if(n >= 9): max_nine = max(nine for nine in nines if nine <= n) if(n%max_nine == 0): m = min(m, n // max_nine) else: m = min(m, dfs(n - max_nine) + 1) max_six = max(six for six in sixs if six <= n) if(n%max_six == 0): m = min(m, n // max_six) tmp[n] = min(m, dfs(n - max_six) + 1) return tmp[n] print((dfs(N)))
N = int(eval(input())) nine = [9**i for i in range(7, 0, -1)] six = [6**i for i in range(8, 0, -1)] tmp = {} def f(n): if(n < 6): return n if(n in tmp): return tmp[n] m = 1e9+7 if(n >= 9): mn = max(x for x in nine if x <= n) if(n%mn == 0): m = min(m, n//mn) else: m = min(m, f(n-mn)+1) ms = max(x for x in six if x <= n) if(n%ms == 0): m = min(m, n//ms) tmp[n] = min(m, f(n-ms)+1) return tmp[n] print((f(N)))
29
25
562
481
N = int(eval(input())) sixs = [6**i for i in range(1, 7)] nines = [9**i for i in range(1, 6)] tmp = {} def dfs(n): if n < 6: return n if n in tmp: return tmp[n] m = 10**9 + 7 if n >= 9: max_nine = max(nine for nine in nines if nine <= n) if n % max_nine == 0: m = min(m, n // max_nine) else: m = min(m, dfs(n - max_nine) + 1) max_six = max(six for six in sixs if six <= n) if n % max_six == 0: m = min(m, n // max_six) tmp[n] = min(m, dfs(n - max_six) + 1) return tmp[n] print((dfs(N)))
N = int(eval(input())) nine = [9**i for i in range(7, 0, -1)] six = [6**i for i in range(8, 0, -1)] tmp = {} def f(n): if n < 6: return n if n in tmp: return tmp[n] m = 1e9 + 7 if n >= 9: mn = max(x for x in nine if x <= n) if n % mn == 0: m = min(m, n // mn) else: m = min(m, f(n - mn) + 1) ms = max(x for x in six if x <= n) if n % ms == 0: m = min(m, n // ms) tmp[n] = min(m, f(n - ms) + 1) return tmp[n] print((f(N)))
false
13.793103
[ "-sixs = [6**i for i in range(1, 7)]", "-nines = [9**i for i in range(1, 6)]", "+nine = [9**i for i in range(7, 0, -1)]", "+six = [6**i for i in range(8, 0, -1)]", "-def dfs(n):", "+def f(n):", "- m = 10**9 + 7", "+ m = 1e9 + 7", "- max_nine = max(nine for nine in nines if nine <= n)", "- if n % max_nine == 0:", "- m = min(m, n // max_nine)", "+ mn = max(x for x in nine if x <= n)", "+ if n % mn == 0:", "+ m = min(m, n // mn)", "- m = min(m, dfs(n - max_nine) + 1)", "- max_six = max(six for six in sixs if six <= n)", "- if n % max_six == 0:", "- m = min(m, n // max_six)", "- tmp[n] = min(m, dfs(n - max_six) + 1)", "+ m = min(m, f(n - mn) + 1)", "+ ms = max(x for x in six if x <= n)", "+ if n % ms == 0:", "+ m = min(m, n // ms)", "+ tmp[n] = min(m, f(n - ms) + 1)", "-print((dfs(N)))", "+print((f(N)))" ]
false
0.037191
0.045774
0.812501
[ "s508615035", "s021971778" ]
u707124227
p03912
python
s178716441
s048136952
164
149
32,308
37,436
Accepted
Accepted
9.15
def main(): n,m=list(map(int,input().split())) x=list(map(int,input().split())) xmod=[y%m for y in x] from collections import Counter cx=Counter(x) cxmod=Counter(xmod) keys=list(cxmod.keys()) ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる for k in keys: if k==0: ans1+=cxmod[k]//2 cxmod[k]-=2*(cxmod[k]//2) else: if k==m-k: ans1+=cxmod[k]//2 cxmod[k]-=2*(cxmod[k]//2) elif m-k in keys: tmp=min(cxmod[k],cxmod[m-k]) ans1+=tmp cxmod[k]-=tmp cxmod[m-k]-=tmp for k in cx: v=cx[k] if v>=2 and cxmod[k%m]>=2: tmp=min(v//2,cxmod[k%m]//2) ans2+=tmp cxmod[k%m]-=tmp*2 print((ans1+ans2)) if __name__=='__main__': main()
def main(): n,m=list(map(int,input().split())) x=list(map(int,input().split())) xmod=[y%m for y in x] from collections import Counter cx=dict(Counter(x)) cxmod=dict(Counter(xmod)) keys=list(cxmod.keys()) ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる for k in keys: if k==0: ans1+=cxmod[k]//2 cxmod[k]-=2*(cxmod[k]//2) else: if k==m-k: ans1+=cxmod[k]//2 cxmod[k]-=2*(cxmod[k]//2) elif m-k in keys: tmp=min(cxmod[k],cxmod[m-k]) ans1+=tmp cxmod[k]-=tmp cxmod[m-k]-=tmp for k in cx: v=cx[k] if v>=2 and cxmod[k%m]>=2: tmp=min(v//2,cxmod[k%m]//2) ans2+=tmp cxmod[k%m]-=tmp*2 print((ans1+ans2)) if __name__=='__main__': main()
33
33
764
776
def main(): n, m = list(map(int, input().split())) x = list(map(int, input().split())) xmod = [y % m for y in x] from collections import Counter cx = Counter(x) cxmod = Counter(xmod) keys = list(cxmod.keys()) ans1, ans2 = 0, 0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる for k in keys: if k == 0: ans1 += cxmod[k] // 2 cxmod[k] -= 2 * (cxmod[k] // 2) else: if k == m - k: ans1 += cxmod[k] // 2 cxmod[k] -= 2 * (cxmod[k] // 2) elif m - k in keys: tmp = min(cxmod[k], cxmod[m - k]) ans1 += tmp cxmod[k] -= tmp cxmod[m - k] -= tmp for k in cx: v = cx[k] if v >= 2 and cxmod[k % m] >= 2: tmp = min(v // 2, cxmod[k % m] // 2) ans2 += tmp cxmod[k % m] -= tmp * 2 print((ans1 + ans2)) if __name__ == "__main__": main()
def main(): n, m = list(map(int, input().split())) x = list(map(int, input().split())) xmod = [y % m for y in x] from collections import Counter cx = dict(Counter(x)) cxmod = dict(Counter(xmod)) keys = list(cxmod.keys()) ans1, ans2 = 0, 0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる for k in keys: if k == 0: ans1 += cxmod[k] // 2 cxmod[k] -= 2 * (cxmod[k] // 2) else: if k == m - k: ans1 += cxmod[k] // 2 cxmod[k] -= 2 * (cxmod[k] // 2) elif m - k in keys: tmp = min(cxmod[k], cxmod[m - k]) ans1 += tmp cxmod[k] -= tmp cxmod[m - k] -= tmp for k in cx: v = cx[k] if v >= 2 and cxmod[k % m] >= 2: tmp = min(v // 2, cxmod[k % m] // 2) ans2 += tmp cxmod[k % m] -= tmp * 2 print((ans1 + ans2)) if __name__ == "__main__": main()
false
0
[ "- cx = Counter(x)", "- cxmod = Counter(xmod)", "+ cx = dict(Counter(x))", "+ cxmod = dict(Counter(xmod))" ]
false
0.102941
0.078516
1.311074
[ "s178716441", "s048136952" ]
u809541036
p02783
python
s103669426
s829919548
19
17
2,940
2,940
Accepted
Accepted
10.53
H, A = list(map(int, input().split())) x = 0 while True: if H <= 0: break if H > 0: H -= A x += 1 print(x)
H, A = list(map(int, input().split())) print(((H+A-1)//A))
10
3
126
53
H, A = list(map(int, input().split())) x = 0 while True: if H <= 0: break if H > 0: H -= A x += 1 print(x)
H, A = list(map(int, input().split())) print(((H + A - 1) // A))
false
70
[ "-x = 0", "-while True:", "- if H <= 0:", "- break", "- if H > 0:", "- H -= A", "- x += 1", "-print(x)", "+print(((H + A - 1) // A))" ]
false
0.083595
0.075407
1.108575
[ "s103669426", "s829919548" ]
u347640436
p03732
python
s007714607
s621261946
107
98
9,300
9,272
Accepted
Accepted
8.41
from sys import stdin from itertools import accumulate readline = stdin.readline N, W = list(map(int, input().split())) vs = [[] for _ in range(4)] w, v = list(map(int, input().split())) w1 = w vs[0].append(v) for _ in range(N - 1): w, v = list(map(int, input().split())) vs[w - w1].append(v) for i in range(4): vs[i].sort(reverse=True) vs[i] = list(accumulate(vs[i])) result = 0 for i in range(len(vs[0]) + 1): a = W - w1 * i if a < 0: break for j in range(len(vs[1]) + 1): b = a - (w1 + 1) * j if b < 0: break for k in range(len(vs[2]) + 1): c = b - (w1 + 2) * k if c < 0: break t = 0 if i != 0: t += vs[0][i - 1] if j != 0: t += vs[1][j - 1] if k != 0: t += vs[2][k - 1] for l in range(len(vs[3]) + 1): d = c - (w1 + 3) * l if d < 0: break if l == 0: result = max(result, t) else: result = max(result, t + vs[3][l -1]) print(result)
from sys import stdin from itertools import accumulate readline = stdin.readline N, W = list(map(int, input().split())) vs = [[] for _ in range(4)] w, v = list(map(int, input().split())) w1 = w vs[0].append(v) for _ in range(N - 1): w, v = list(map(int, input().split())) vs[w - w1].append(v) for i in range(4): vs[i].sort(reverse=True) vs[i] = [0] + list(accumulate(vs[i])) result = 0 for i in range(len(vs[0])): a = W - w1 * i if a < 0: break for j in range(len(vs[1])): b = a - (w1 + 1) * j if b < 0: break for k in range(len(vs[2])): c = b - (w1 + 2) * k if c < 0: break t = vs[0][i] + vs[1][j] + vs[2][k] for l in range(len(vs[3])): d = c - (w1 + 3) * l if d < 0: break result = max(result, t + vs[3][l]) print(result)
46
37
1,204
949
from sys import stdin from itertools import accumulate readline = stdin.readline N, W = list(map(int, input().split())) vs = [[] for _ in range(4)] w, v = list(map(int, input().split())) w1 = w vs[0].append(v) for _ in range(N - 1): w, v = list(map(int, input().split())) vs[w - w1].append(v) for i in range(4): vs[i].sort(reverse=True) vs[i] = list(accumulate(vs[i])) result = 0 for i in range(len(vs[0]) + 1): a = W - w1 * i if a < 0: break for j in range(len(vs[1]) + 1): b = a - (w1 + 1) * j if b < 0: break for k in range(len(vs[2]) + 1): c = b - (w1 + 2) * k if c < 0: break t = 0 if i != 0: t += vs[0][i - 1] if j != 0: t += vs[1][j - 1] if k != 0: t += vs[2][k - 1] for l in range(len(vs[3]) + 1): d = c - (w1 + 3) * l if d < 0: break if l == 0: result = max(result, t) else: result = max(result, t + vs[3][l - 1]) print(result)
from sys import stdin from itertools import accumulate readline = stdin.readline N, W = list(map(int, input().split())) vs = [[] for _ in range(4)] w, v = list(map(int, input().split())) w1 = w vs[0].append(v) for _ in range(N - 1): w, v = list(map(int, input().split())) vs[w - w1].append(v) for i in range(4): vs[i].sort(reverse=True) vs[i] = [0] + list(accumulate(vs[i])) result = 0 for i in range(len(vs[0])): a = W - w1 * i if a < 0: break for j in range(len(vs[1])): b = a - (w1 + 1) * j if b < 0: break for k in range(len(vs[2])): c = b - (w1 + 2) * k if c < 0: break t = vs[0][i] + vs[1][j] + vs[2][k] for l in range(len(vs[3])): d = c - (w1 + 3) * l if d < 0: break result = max(result, t + vs[3][l]) print(result)
false
19.565217
[ "- vs[i] = list(accumulate(vs[i]))", "+ vs[i] = [0] + list(accumulate(vs[i]))", "-for i in range(len(vs[0]) + 1):", "+for i in range(len(vs[0])):", "- for j in range(len(vs[1]) + 1):", "+ for j in range(len(vs[1])):", "- for k in range(len(vs[2]) + 1):", "+ for k in range(len(vs[2])):", "- t = 0", "- if i != 0:", "- t += vs[0][i - 1]", "- if j != 0:", "- t += vs[1][j - 1]", "- if k != 0:", "- t += vs[2][k - 1]", "- for l in range(len(vs[3]) + 1):", "+ t = vs[0][i] + vs[1][j] + vs[2][k]", "+ for l in range(len(vs[3])):", "- if l == 0:", "- result = max(result, t)", "- else:", "- result = max(result, t + vs[3][l - 1])", "+ result = max(result, t + vs[3][l])" ]
false
0.040588
0.038903
1.043312
[ "s007714607", "s621261946" ]
u585482323
p02824
python
s016035616
s213213903
255
231
58,864
58,736
Accepted
Accepted
9.41
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n,m,v,p = LI() a = LI() a.sort() l = -1 r = n-1 while l+1 < r: i = (l+r) >> 1 A = a[i]+m ri = bisect.bisect_right(a,A) j = n-ri if j >= p: l = i continue s = m*p for j in range(n-p+1): if i == j: continue s += min(m,A-a[j]) if s >= m*v: r = i else: l = i print((n-r)) return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n,m,v,p = LI() a = LI() a.sort() l = -1 r = n-1 while l+1 < r: i = (l+r) >> 1 A = a[i]+m ri = bisect.bisect_right(a,A) j = n-ri if j >= p: l = i continue li = bisect.bisect_right(a,a[i]) res = v-j-li if res <= 0: r = i continue res -= (p-j-1) s = 0 for j in range(li,ri-(p-j-1)): s += A-a[j] if s >= res*m: r = i else: l = i print((n-r)) return #Solve if __name__ == "__main__": solve()
56
60
1,282
1,384
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n, m, v, p = LI() a = LI() a.sort() l = -1 r = n - 1 while l + 1 < r: i = (l + r) >> 1 A = a[i] + m ri = bisect.bisect_right(a, A) j = n - ri if j >= p: l = i continue s = m * p for j in range(n - p + 1): if i == j: continue s += min(m, A - a[j]) if s >= m * v: r = i else: l = i print((n - r)) return # Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n, m, v, p = LI() a = LI() a.sort() l = -1 r = n - 1 while l + 1 < r: i = (l + r) >> 1 A = a[i] + m ri = bisect.bisect_right(a, A) j = n - ri if j >= p: l = i continue li = bisect.bisect_right(a, a[i]) res = v - j - li if res <= 0: r = i continue res -= p - j - 1 s = 0 for j in range(li, ri - (p - j - 1)): s += A - a[j] if s >= res * m: r = i else: l = i print((n - r)) return # Solve if __name__ == "__main__": solve()
false
6.666667
[ "- s = m * p", "- for j in range(n - p + 1):", "- if i == j:", "- continue", "- s += min(m, A - a[j])", "- if s >= m * v:", "+ li = bisect.bisect_right(a, a[i])", "+ res = v - j - li", "+ if res <= 0:", "+ r = i", "+ continue", "+ res -= p - j - 1", "+ s = 0", "+ for j in range(li, ri - (p - j - 1)):", "+ s += A - a[j]", "+ if s >= res * m:" ]
false
0.049644
0.042219
1.175867
[ "s016035616", "s213213903" ]
u745097373
p03165
python
s551300360
s767865241
675
571
121,308
124,760
Accepted
Accepted
15.41
def solve(): s, t = read() result = think(s, t) write(result) def read(): return read_line(), read_line() def read_int(n): return list([int(x) for x in read_line().split(' ')])[:n] def read_line(n=0): if n == 0: return input().rstrip() else: return input().rstrip()[:n] def think(s, t): # create dp table local_s = ' ' + s # for convenience local_t = ' ' + t dp = [[0 for x in range(len(local_s))] for y in range(len(local_t))] for y, ct in enumerate(local_t): for x, cs in enumerate(local_s): if x == 0 or y == 0: dp[y][x] = 0 else: if local_s[x] == local_t[y]: dp[y][x] = dp[y - 1][x - 1] + 1 else: dp[y][x] = max(dp[y - 1][x], dp[y][x - 1], dp[y - 1][x - 1]) # scan dp table backward x = len(dp[0]) - 1 y = len(dp) - 1 buf = '' while x > 0 and y > 0: if local_s[x] == local_t[y]: buf += local_s[x] x -= 1 y -= 1 else: if dp[y][x] == dp[y - 1][x]: y -= 1 else: x -= 1 buf = list(buf) buf.reverse() return ''.join(buf) def write(result): print(result) if __name__ == '__main__': solve()
import unittest class TestF(unittest.TestCase): def test_1(self): self.assertEqual( len(think('axyb', 'abyxb')), 3 ) def test_2(self): self.assertEqual( len(think('aa', 'xayaz')), 2 ) def test_3(self): self.assertEqual( len(think('a', 'z')), 0 ) def test_4(self): self.assertEqual( len(think('abracadabra', 'avadakedavra')), 7 ) def solve(): s, t = read() result = think(s, t) write(result) def read(): s = read_line() t = read_line() return s, t def read_int(n): return read_type(int, n, sep=' ') def read_float(n): return read_type(float, n, sep=' ') def read_type(t, n, sep): return list([t(x) for x in read_line().split(sep)])[:n] def read_line(n=0): if n == 0: return input().rstrip() else: return input().rstrip()[:n] def think(s, t): # dp[0][j] = 0 # dp[i][j] = 0 # dp[i + 1][j + 1] = max len of LCS for s[0 to ith] and t[0 to jth] dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)] for i in range(len(s)): if s[i] == t[0]: dp[i + 1][1] = 1 if i > 0 and dp[i][1] == 1: dp[i + 1][1] = 1 for j in range(len(t)): if t[j] == s[0]: dp[1][j + 1] = 1 if j > 0 and dp[1][j] == 1: dp[1][j + 1] = 1 for i in range(1, len(s)): for j in range(1, len(t)): if s[i] == t[j]: dp[i + 1][j + 1] = dp[i][j] + 1 else: dp[i + 1][j + 1] = max( dp[i + 1][j], dp[i][j + 1] ) return restore_lcs(s, t, dp) def write(result): print(result) def restore_lcs(s, t, dp): lcs = '' i, j = len(s), len(t) while i >= 0 and j >= 0: if dp[i][j] == dp[i - 1][j]: i -= 1 continue if dp[i][j] == dp[i][j - 1]: j -= 1 continue lcs += s[i - 1] i -= 1 j -= 1 return lcs[::-1] if __name__ == '__main__': # unittest.main() solve()
64
115
1,404
2,339
def solve(): s, t = read() result = think(s, t) write(result) def read(): return read_line(), read_line() def read_int(n): return list([int(x) for x in read_line().split(" ")])[:n] def read_line(n=0): if n == 0: return input().rstrip() else: return input().rstrip()[:n] def think(s, t): # create dp table local_s = " " + s # for convenience local_t = " " + t dp = [[0 for x in range(len(local_s))] for y in range(len(local_t))] for y, ct in enumerate(local_t): for x, cs in enumerate(local_s): if x == 0 or y == 0: dp[y][x] = 0 else: if local_s[x] == local_t[y]: dp[y][x] = dp[y - 1][x - 1] + 1 else: dp[y][x] = max(dp[y - 1][x], dp[y][x - 1], dp[y - 1][x - 1]) # scan dp table backward x = len(dp[0]) - 1 y = len(dp) - 1 buf = "" while x > 0 and y > 0: if local_s[x] == local_t[y]: buf += local_s[x] x -= 1 y -= 1 else: if dp[y][x] == dp[y - 1][x]: y -= 1 else: x -= 1 buf = list(buf) buf.reverse() return "".join(buf) def write(result): print(result) if __name__ == "__main__": solve()
import unittest class TestF(unittest.TestCase): def test_1(self): self.assertEqual(len(think("axyb", "abyxb")), 3) def test_2(self): self.assertEqual(len(think("aa", "xayaz")), 2) def test_3(self): self.assertEqual(len(think("a", "z")), 0) def test_4(self): self.assertEqual(len(think("abracadabra", "avadakedavra")), 7) def solve(): s, t = read() result = think(s, t) write(result) def read(): s = read_line() t = read_line() return s, t def read_int(n): return read_type(int, n, sep=" ") def read_float(n): return read_type(float, n, sep=" ") def read_type(t, n, sep): return list([t(x) for x in read_line().split(sep)])[:n] def read_line(n=0): if n == 0: return input().rstrip() else: return input().rstrip()[:n] def think(s, t): # dp[0][j] = 0 # dp[i][j] = 0 # dp[i + 1][j + 1] = max len of LCS for s[0 to ith] and t[0 to jth] dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)] for i in range(len(s)): if s[i] == t[0]: dp[i + 1][1] = 1 if i > 0 and dp[i][1] == 1: dp[i + 1][1] = 1 for j in range(len(t)): if t[j] == s[0]: dp[1][j + 1] = 1 if j > 0 and dp[1][j] == 1: dp[1][j + 1] = 1 for i in range(1, len(s)): for j in range(1, len(t)): if s[i] == t[j]: dp[i + 1][j + 1] = dp[i][j] + 1 else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) return restore_lcs(s, t, dp) def write(result): print(result) def restore_lcs(s, t, dp): lcs = "" i, j = len(s), len(t) while i >= 0 and j >= 0: if dp[i][j] == dp[i - 1][j]: i -= 1 continue if dp[i][j] == dp[i][j - 1]: j -= 1 continue lcs += s[i - 1] i -= 1 j -= 1 return lcs[::-1] if __name__ == "__main__": # unittest.main() solve()
false
44.347826
[ "+import unittest", "+", "+", "+class TestF(unittest.TestCase):", "+ def test_1(self):", "+ self.assertEqual(len(think(\"axyb\", \"abyxb\")), 3)", "+", "+ def test_2(self):", "+ self.assertEqual(len(think(\"aa\", \"xayaz\")), 2)", "+", "+ def test_3(self):", "+ self.assertEqual(len(think(\"a\", \"z\")), 0)", "+", "+ def test_4(self):", "+ self.assertEqual(len(think(\"abracadabra\", \"avadakedavra\")), 7)", "+", "+", "- return read_line(), read_line()", "+ s = read_line()", "+ t = read_line()", "+ return s, t", "- return list([int(x) for x in read_line().split(\" \")])[:n]", "+ return read_type(int, n, sep=\" \")", "+", "+", "+def read_float(n):", "+ return read_type(float, n, sep=\" \")", "+", "+", "+def read_type(t, n, sep):", "+ return list([t(x) for x in read_line().split(sep)])[:n]", "- # create dp table", "- local_s = \" \" + s # for convenience", "- local_t = \" \" + t", "- dp = [[0 for x in range(len(local_s))] for y in range(len(local_t))]", "- for y, ct in enumerate(local_t):", "- for x, cs in enumerate(local_s):", "- if x == 0 or y == 0:", "- dp[y][x] = 0", "+ # dp[0][j] = 0", "+ # dp[i][j] = 0", "+ # dp[i + 1][j + 1] = max len of LCS for s[0 to ith] and t[0 to jth]", "+ dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]", "+ for i in range(len(s)):", "+ if s[i] == t[0]:", "+ dp[i + 1][1] = 1", "+ if i > 0 and dp[i][1] == 1:", "+ dp[i + 1][1] = 1", "+ for j in range(len(t)):", "+ if t[j] == s[0]:", "+ dp[1][j + 1] = 1", "+ if j > 0 and dp[1][j] == 1:", "+ dp[1][j + 1] = 1", "+ for i in range(1, len(s)):", "+ for j in range(1, len(t)):", "+ if s[i] == t[j]:", "+ dp[i + 1][j + 1] = dp[i][j] + 1", "- if local_s[x] == local_t[y]:", "- dp[y][x] = dp[y - 1][x - 1] + 1", "- else:", "- dp[y][x] = max(dp[y - 1][x], dp[y][x - 1], dp[y - 1][x - 1])", "- # scan dp table backward", "- x = len(dp[0]) - 1", "- y = len(dp) - 1", "- buf = \"\"", "- while x > 0 and y > 0:", "- if local_s[x] == local_t[y]:", "- buf += local_s[x]", "- x -= 1", "- y -= 1", "- else:", "- if dp[y][x] == dp[y - 1][x]:", "- y -= 1", "- else:", "- x -= 1", "- buf = list(buf)", "- buf.reverse()", "- return \"\".join(buf)", "+ dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])", "+ return restore_lcs(s, t, dp)", "+def restore_lcs(s, t, dp):", "+ lcs = \"\"", "+ i, j = len(s), len(t)", "+ while i >= 0 and j >= 0:", "+ if dp[i][j] == dp[i - 1][j]:", "+ i -= 1", "+ continue", "+ if dp[i][j] == dp[i][j - 1]:", "+ j -= 1", "+ continue", "+ lcs += s[i - 1]", "+ i -= 1", "+ j -= 1", "+ return lcs[::-1]", "+", "+", "+ # unittest.main()" ]
false
0.060689
0.184535
0.328873
[ "s551300360", "s767865241" ]
u254456372
p03632
python
s614369550
s482236856
33
18
4,080
2,940
Accepted
Accepted
45.45
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import re import math import collections import itertools import functools DEBUG = True DEBUG = False def dbg(*args): if DEBUG: print("DBG: ", file=sys.stderr, end="") print(*args, file=sys.stderr) def main(): A, B, C, D = map(int, input().split()) alice = [A <= t < B for t in range(100)] bob = [C <= t < D for t in range(100)] cnt = 0 for t in range(100): if alice[t] and bob[t]: cnt += 1 print(cnt) if __name__ == "__main__": main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): A, B, C, D = list(map(int, input().split())) if A <= D and B >= C: print((min(B,D) - max(A,C))) else: print((0)) if __name__ == "__main__": main()
34
14
603
242
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import re import math import collections import itertools import functools DEBUG = True DEBUG = False def dbg(*args): if DEBUG: print("DBG: ", file=sys.stderr, end="") print(*args, file=sys.stderr) def main(): A, B, C, D = map(int, input().split()) alice = [A <= t < B for t in range(100)] bob = [C <= t < D for t in range(100)] cnt = 0 for t in range(100): if alice[t] and bob[t]: cnt += 1 print(cnt) if __name__ == "__main__": main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): A, B, C, D = list(map(int, input().split())) if A <= D and B >= C: print((min(B, D) - max(A, C))) else: print((0)) if __name__ == "__main__": main()
false
58.823529
[ "-import sys", "-import re", "-import math", "-import collections", "-import itertools", "-import functools", "-", "-DEBUG = True", "-DEBUG = False", "-", "-", "-def dbg(*args):", "- if DEBUG:", "- print(\"DBG: \", file=sys.stderr, end=\"\")", "- print(*args, file=sys.stderr)", "-", "-", "- A, B, C, D = map(int, input().split())", "- alice = [A <= t < B for t in range(100)]", "- bob = [C <= t < D for t in range(100)]", "- cnt = 0", "- for t in range(100):", "- if alice[t] and bob[t]:", "- cnt += 1", "- print(cnt)", "+ A, B, C, D = list(map(int, input().split()))", "+ if A <= D and B >= C:", "+ print((min(B, D) - max(A, C)))", "+ else:", "+ print((0))" ]
false
0.048097
0.047078
1.021649
[ "s614369550", "s482236856" ]
u831244171
p02407
python
s687405202
s699153400
30
20
7,352
7,336
Accepted
Accepted
33.33
n = eval(input()) a = input().split() print((" ".join(a[::-1])))
eval(input()) a = input().split() print((" ".join(a[::-1])))
3
3
58
54
n = eval(input()) a = input().split() print((" ".join(a[::-1])))
eval(input()) a = input().split() print((" ".join(a[::-1])))
false
0
[ "-n = eval(input())", "+eval(input())" ]
false
0.036701
0.08494
0.432087
[ "s687405202", "s699153400" ]
u347600233
p02631
python
s740192519
s965335850
160
145
31,752
31,408
Accepted
Accepted
9.38
n = int(eval(input())) a = [int(i) for i in input().split()] s = 0 for ai in a: s ^= ai b = [a[i] ^ s for i in range(n)] print((*b))
n = int(eval(input())) a = list(map(int, input().split())) s = 0 for ai in a: s ^= ai print((*[s ^ ai for ai in a]))
7
6
134
117
n = int(eval(input())) a = [int(i) for i in input().split()] s = 0 for ai in a: s ^= ai b = [a[i] ^ s for i in range(n)] print((*b))
n = int(eval(input())) a = list(map(int, input().split())) s = 0 for ai in a: s ^= ai print((*[s ^ ai for ai in a]))
false
14.285714
[ "-a = [int(i) for i in input().split()]", "+a = list(map(int, input().split()))", "-b = [a[i] ^ s for i in range(n)]", "-print((*b))", "+print((*[s ^ ai for ai in a]))" ]
false
0.038388
0.037729
1.017484
[ "s740192519", "s965335850" ]
u562935282
p03167
python
s301467557
s960730978
291
228
54,000
51,184
Accepted
Accepted
21.65
mod = 10 ** 9 + 7 h, w = list(map(int, input().split())) a = tuple(eval(input()) for _ in range(h)) dp = [[0] * w for _ in range(h)] dp[0][0] = 1 # 配る for r in range(h): for c in range(w): if a[r][c] == '#': continue if r + 1 < h and a[r + 1][c] == '.': dp[r + 1][c] = (dp[r + 1][c] + dp[r][c]) % mod if c + 1 < w and a[r][c + 1] == '.': dp[r][c + 1] = (dp[r][c + 1] + dp[r][c]) % mod print((dp[h - 1][w - 1]))
def main(): import sys readline = sys.stdin.readline mod = 10 ** 9 + 7 h, w = list(map(int, readline().split())) a = [readline().rstrip() for _ in range(h)] dp = [[0] * w for _ in range(h)] dp[0][0] = 1 for r in range(h): for c in range(w): if a[r][c] == '#': continue if r > 0: dp[r][c] += dp[r - 1][c] if c > 0: dp[r][c] += dp[r][c - 1] dp[r][c] %= mod print((dp[h - 1][w - 1])) if __name__ == '__main__': main()
18
26
481
567
mod = 10**9 + 7 h, w = list(map(int, input().split())) a = tuple(eval(input()) for _ in range(h)) dp = [[0] * w for _ in range(h)] dp[0][0] = 1 # 配る for r in range(h): for c in range(w): if a[r][c] == "#": continue if r + 1 < h and a[r + 1][c] == ".": dp[r + 1][c] = (dp[r + 1][c] + dp[r][c]) % mod if c + 1 < w and a[r][c + 1] == ".": dp[r][c + 1] = (dp[r][c + 1] + dp[r][c]) % mod print((dp[h - 1][w - 1]))
def main(): import sys readline = sys.stdin.readline mod = 10**9 + 7 h, w = list(map(int, readline().split())) a = [readline().rstrip() for _ in range(h)] dp = [[0] * w for _ in range(h)] dp[0][0] = 1 for r in range(h): for c in range(w): if a[r][c] == "#": continue if r > 0: dp[r][c] += dp[r - 1][c] if c > 0: dp[r][c] += dp[r][c - 1] dp[r][c] %= mod print((dp[h - 1][w - 1])) if __name__ == "__main__": main()
false
30.769231
[ "-mod = 10**9 + 7", "-h, w = list(map(int, input().split()))", "-a = tuple(eval(input()) for _ in range(h))", "-dp = [[0] * w for _ in range(h)]", "-dp[0][0] = 1", "-# 配る", "-for r in range(h):", "- for c in range(w):", "- if a[r][c] == \"#\":", "- continue", "- if r + 1 < h and a[r + 1][c] == \".\":", "- dp[r + 1][c] = (dp[r + 1][c] + dp[r][c]) % mod", "- if c + 1 < w and a[r][c + 1] == \".\":", "- dp[r][c + 1] = (dp[r][c + 1] + dp[r][c]) % mod", "-print((dp[h - 1][w - 1]))", "+def main():", "+ import sys", "+", "+ readline = sys.stdin.readline", "+ mod = 10**9 + 7", "+ h, w = list(map(int, readline().split()))", "+ a = [readline().rstrip() for _ in range(h)]", "+ dp = [[0] * w for _ in range(h)]", "+ dp[0][0] = 1", "+ for r in range(h):", "+ for c in range(w):", "+ if a[r][c] == \"#\":", "+ continue", "+ if r > 0:", "+ dp[r][c] += dp[r - 1][c]", "+ if c > 0:", "+ dp[r][c] += dp[r][c - 1]", "+ dp[r][c] %= mod", "+ print((dp[h - 1][w - 1]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.05617
0.062602
0.897255
[ "s301467557", "s960730978" ]
u906501980
p02762
python
s881912854
s088747207
829
612
33,280
16,392
Accepted
Accepted
26.18
import sys input = sys.stdin.buffer.readline class UnionFind: def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0]*(n+1) blocks = [[] for _ in range(n+1)] uf = UnionFind(n) ans = [] for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n+1): nf = friends[i] nb = 0 for b in blocks[i]: if uf.same(i, b): nb += 1 ans.append(uf.size(i) - 1 - nf - nb) print((" ".join(list(map(str, ans))))) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0]*(n+1) blocks = [0]*(n+1) uf = UnionFind(n) ans = [] for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) if uf.same(c, d): blocks[c] += 1 blocks[d] += 1 for i in range(1, n+1): ans.append(uf.size(i)-1-friends[i]-blocks[i]) print((" ".join(list(map(str, ans))))) if __name__ == "__main__": main()
59
57
1,493
1,418
import sys input = sys.stdin.buffer.readline class UnionFind: def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0] * (n + 1) blocks = [[] for _ in range(n + 1)] uf = UnionFind(n) ans = [] for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n + 1): nf = friends[i] nb = 0 for b in blocks[i]: if uf.same(i, b): nb += 1 ans.append(uf.size(i) - 1 - nf - nb) print((" ".join(list(map(str, ans))))) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0] * (n + 1) blocks = [0] * (n + 1) uf = UnionFind(n) ans = [] for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) if uf.same(c, d): blocks[c] += 1 blocks[d] += 1 for i in range(1, n + 1): ans.append(uf.size(i) - 1 - friends[i] - blocks[i]) print((" ".join(list(map(str, ans))))) if __name__ == "__main__": main()
false
3.389831
[ "+ __slots__ = [\"data\"]", "+", "- blocks = [[] for _ in range(n + 1)]", "+ blocks = [0] * (n + 1)", "- blocks[c].append(d)", "- blocks[d].append(c)", "+ if uf.same(c, d):", "+ blocks[c] += 1", "+ blocks[d] += 1", "- nf = friends[i]", "- nb = 0", "- for b in blocks[i]:", "- if uf.same(i, b):", "- nb += 1", "- ans.append(uf.size(i) - 1 - nf - nb)", "+ ans.append(uf.size(i) - 1 - friends[i] - blocks[i])" ]
false
0.046476
0.036871
1.260496
[ "s881912854", "s088747207" ]
u718706479
p02886
python
s406173274
s700472542
20
17
3,316
2,940
Accepted
Accepted
15
n,*d=list(map(int,open(0).read().split())) s=sum(d)**2 for v in d: s-=v**2 print(("%d"%(s/2)))
n,*d=list(map(int,open(0).read().split())) s=sum(d)**2 for v in d:s-=v**2 print((s//2))
4
4
89
82
n, *d = list(map(int, open(0).read().split())) s = sum(d) ** 2 for v in d: s -= v**2 print(("%d" % (s / 2)))
n, *d = list(map(int, open(0).read().split())) s = sum(d) ** 2 for v in d: s -= v**2 print((s // 2))
false
0
[ "-print((\"%d\" % (s / 2)))", "+print((s // 2))" ]
false
0.049821
0.132441
0.376175
[ "s406173274", "s700472542" ]
u750990077
p02694
python
s982985257
s954320081
172
74
62,776
62,784
Accepted
Accepted
56.98
def main(): x = int(eval(input())) m = 100 for i in range(10**5): if m >= x: print(i) return m += m//100 if __name__ == "__main__": main()
def main(): x = int(eval(input())) money = 100 for i in range(10**5): if money >= x: print(i) return money += money//100 if __name__ == "__main__": main()
11
12
199
218
def main(): x = int(eval(input())) m = 100 for i in range(10**5): if m >= x: print(i) return m += m // 100 if __name__ == "__main__": main()
def main(): x = int(eval(input())) money = 100 for i in range(10**5): if money >= x: print(i) return money += money // 100 if __name__ == "__main__": main()
false
8.333333
[ "- m = 100", "+ money = 100", "- if m >= x:", "+ if money >= x:", "- m += m // 100", "+ money += money // 100" ]
false
0.03775
0.09074
0.416024
[ "s982985257", "s954320081" ]
u192154323
p03266
python
s810713574
s712588507
105
72
4,596
9,044
Accepted
Accepted
31.43
n,k = list(map(int,input().split())) mod_ls = [0] * k for i in range(1,n+1): rest = i % k mod_ls[rest] += 1 ans = 0 for i in range(1,k): first = i second = k - i third = k - second if (first + third) % k == 0: ans += mod_ls[first] * mod_ls[second] * mod_ls[third] ans += mod_ls[0] ** 3 print(ans)
n,k = list(map(int,input().split())) n_O = 0 n_E = 0 for i in range(1,n+1): if (2*i) % k == 0: if (2*i//k)%2 == 0: n_E += 1 else: n_O += 1 print((n_E**3+n_O**3))
16
10
340
207
n, k = list(map(int, input().split())) mod_ls = [0] * k for i in range(1, n + 1): rest = i % k mod_ls[rest] += 1 ans = 0 for i in range(1, k): first = i second = k - i third = k - second if (first + third) % k == 0: ans += mod_ls[first] * mod_ls[second] * mod_ls[third] ans += mod_ls[0] ** 3 print(ans)
n, k = list(map(int, input().split())) n_O = 0 n_E = 0 for i in range(1, n + 1): if (2 * i) % k == 0: if (2 * i // k) % 2 == 0: n_E += 1 else: n_O += 1 print((n_E**3 + n_O**3))
false
37.5
[ "-mod_ls = [0] * k", "+n_O = 0", "+n_E = 0", "- rest = i % k", "- mod_ls[rest] += 1", "-ans = 0", "-for i in range(1, k):", "- first = i", "- second = k - i", "- third = k - second", "- if (first + third) % k == 0:", "- ans += mod_ls[first] * mod_ls[second] * mod_ls[third]", "-ans += mod_ls[0] ** 3", "-print(ans)", "+ if (2 * i) % k == 0:", "+ if (2 * i // k) % 2 == 0:", "+ n_E += 1", "+ else:", "+ n_O += 1", "+print((n_E**3 + n_O**3))" ]
false
0.038854
0.03936
0.987123
[ "s810713574", "s712588507" ]
u761989513
p02959
python
s913254721
s183579067
147
124
18,624
18,624
Accepted
Accepted
15.65
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i in range(n): if a[i] <= b[i]: ans += a[i] b[i] -= a[i] if a[i + 1] <= b[i]: ans += a[i + 1] a[i + 1] = 0 else: ans += b[i] a[i + 1] -= b[i] else: ans += b[i] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 now = a[0] for i in range(n): ato_taoseru = b[i] if ato_taoseru <= now: ans += ato_taoseru now = a[i + 1] else: ans += now ato_taoseru -= now now = a[i + 1] if ato_taoseru <= now: ans += ato_taoseru now -= ato_taoseru else: ans += now now = 0 print(ans)
17
23
383
490
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i in range(n): if a[i] <= b[i]: ans += a[i] b[i] -= a[i] if a[i + 1] <= b[i]: ans += a[i + 1] a[i + 1] = 0 else: ans += b[i] a[i + 1] -= b[i] else: ans += b[i] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 now = a[0] for i in range(n): ato_taoseru = b[i] if ato_taoseru <= now: ans += ato_taoseru now = a[i + 1] else: ans += now ato_taoseru -= now now = a[i + 1] if ato_taoseru <= now: ans += ato_taoseru now -= ato_taoseru else: ans += now now = 0 print(ans)
false
26.086957
[ "+now = a[0]", "- if a[i] <= b[i]:", "- ans += a[i]", "- b[i] -= a[i]", "- if a[i + 1] <= b[i]:", "- ans += a[i + 1]", "- a[i + 1] = 0", "+ ato_taoseru = b[i]", "+ if ato_taoseru <= now:", "+ ans += ato_taoseru", "+ now = a[i + 1]", "+ else:", "+ ans += now", "+ ato_taoseru -= now", "+ now = a[i + 1]", "+ if ato_taoseru <= now:", "+ ans += ato_taoseru", "+ now -= ato_taoseru", "- ans += b[i]", "- a[i + 1] -= b[i]", "- else:", "- ans += b[i]", "+ ans += now", "+ now = 0" ]
false
0.045697
0.039032
1.170734
[ "s913254721", "s183579067" ]
u607865971
p03152
python
s655834054
s392406882
1,296
578
48,084
3,188
Accepted
Accepted
55.4
N, M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] ret = 1 MOD = 10 ** 9 + 7 from collections import Counter import sys ca = Counter(A) cb = Counter(B) if ca.most_common(1)[0][1] >= 2 or cb.most_common(1)[0][1] >= 2: print((0)) sys.exit(0) A.sort() B.sort() import bisect def index(a, x): 'Locate the leftmost value exactly equal to x' i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i return -1 for n in range(N * M, 0, -1): a = index(A, n) b = index(B, n) cntA = len(A) - bisect.bisect_right(A, n) cntB = len(B) - bisect.bisect_right(B, n) # 両方みつけた if a != -1 and b != -1: pass # Bの方だけ見つけた elif a == -1 and b != -1: ret *= cntA # Aの方だけ見つけた elif a != -1 and b == -1: ret *= cntB # 両方なかった else: ret *= (cntA * cntB - (N * M - n)) ret = ret % MOD print(ret)
N, M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] ret = 1 MOD = 10 ** 9 + 7 A.sort(reverse=True) B.sort(reverse=True) aidx = bidx = 0 for n in range(N * M, 0, -1): # 両方みつけた if aidx < N and bidx < M and n == A[aidx] and n == B[bidx] and A[aidx] == B[bidx]: aidx += 1 bidx += 1 # Bの方だけ見つけた elif bidx < M and n == B[bidx]: ret *= aidx bidx += 1 # Aの方だけ見つけた elif aidx < N and n == A[aidx]: ret *= bidx aidx += 1 # 両方なかった else: ret *= (aidx * bidx - (N * M - n)) ret = ret % MOD print(ret)
55
35
1,024
687
N, M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] ret = 1 MOD = 10**9 + 7 from collections import Counter import sys ca = Counter(A) cb = Counter(B) if ca.most_common(1)[0][1] >= 2 or cb.most_common(1)[0][1] >= 2: print((0)) sys.exit(0) A.sort() B.sort() import bisect def index(a, x): "Locate the leftmost value exactly equal to x" i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i return -1 for n in range(N * M, 0, -1): a = index(A, n) b = index(B, n) cntA = len(A) - bisect.bisect_right(A, n) cntB = len(B) - bisect.bisect_right(B, n) # 両方みつけた if a != -1 and b != -1: pass # Bの方だけ見つけた elif a == -1 and b != -1: ret *= cntA # Aの方だけ見つけた elif a != -1 and b == -1: ret *= cntB # 両方なかった else: ret *= cntA * cntB - (N * M - n) ret = ret % MOD print(ret)
N, M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] ret = 1 MOD = 10**9 + 7 A.sort(reverse=True) B.sort(reverse=True) aidx = bidx = 0 for n in range(N * M, 0, -1): # 両方みつけた if aidx < N and bidx < M and n == A[aidx] and n == B[bidx] and A[aidx] == B[bidx]: aidx += 1 bidx += 1 # Bの方だけ見つけた elif bidx < M and n == B[bidx]: ret *= aidx bidx += 1 # Aの方だけ見つけた elif aidx < N and n == A[aidx]: ret *= bidx aidx += 1 # 両方なかった else: ret *= aidx * bidx - (N * M - n) ret = ret % MOD print(ret)
false
36.363636
[ "-from collections import Counter", "-import sys", "-", "-ca = Counter(A)", "-cb = Counter(B)", "-if ca.most_common(1)[0][1] >= 2 or cb.most_common(1)[0][1] >= 2:", "- print((0))", "- sys.exit(0)", "-A.sort()", "-B.sort()", "-import bisect", "-", "-", "-def index(a, x):", "- \"Locate the leftmost value exactly equal to x\"", "- i = bisect.bisect_left(a, x)", "- if i != len(a) and a[i] == x:", "- return i", "- return -1", "-", "-", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+aidx = bidx = 0", "- a = index(A, n)", "- b = index(B, n)", "- cntA = len(A) - bisect.bisect_right(A, n)", "- cntB = len(B) - bisect.bisect_right(B, n)", "- if a != -1 and b != -1:", "- pass", "+ if aidx < N and bidx < M and n == A[aidx] and n == B[bidx] and A[aidx] == B[bidx]:", "+ aidx += 1", "+ bidx += 1", "- elif a == -1 and b != -1:", "- ret *= cntA", "+ elif bidx < M and n == B[bidx]:", "+ ret *= aidx", "+ bidx += 1", "- elif a != -1 and b == -1:", "- ret *= cntB", "+ elif aidx < N and n == A[aidx]:", "+ ret *= bidx", "+ aidx += 1", "- ret *= cntA * cntB - (N * M - n)", "+ ret *= aidx * bidx - (N * M - n)" ]
false
0.037813
0.047579
0.794748
[ "s655834054", "s392406882" ]
u143492911
p03964
python
s564622602
s886982652
332
55
5,944
5,680
Accepted
Accepted
83.43
n=int(eval(input())) from fractions import Fraction import math t=[[int(i)for i in input().split()]for i in range(n)] dp=[0]*n dp[0]=1 for i in range(1,n): dp[i]=math.ceil((max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1])) print((dp[-1]*(t[n-1][0]+t[n-1][1])))
n=int(eval(input())) t=[[int(i)for i in input().split()]for i in range(n)] import math from fractions import Fraction dp=[0]*n dp[0]=1 for i in range(1,n): dp[i]=math.ceil(max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1]) print((dp[-1]*(t[n-1][0]+t[n-1][1])))
9
9
285
283
n = int(eval(input())) from fractions import Fraction import math t = [[int(i) for i in input().split()] for i in range(n)] dp = [0] * n dp[0] = 1 for i in range(1, n): dp[i] = math.ceil( ( max(Fraction(t[i - 1][0], t[i][0]), Fraction(t[i - 1][1], t[i][1])) * dp[i - 1] ) ) print((dp[-1] * (t[n - 1][0] + t[n - 1][1])))
n = int(eval(input())) t = [[int(i) for i in input().split()] for i in range(n)] import math from fractions import Fraction dp = [0] * n dp[0] = 1 for i in range(1, n): dp[i] = math.ceil( max(Fraction(t[i - 1][0], t[i][0]), Fraction(t[i - 1][1], t[i][1])) * dp[i - 1] ) print((dp[-1] * (t[n - 1][0] + t[n - 1][1])))
false
0
[ "+t = [[int(i) for i in input().split()] for i in range(n)]", "+import math", "-import math", "-t = [[int(i) for i in input().split()] for i in range(n)]", "- (", "- max(Fraction(t[i - 1][0], t[i][0]), Fraction(t[i - 1][1], t[i][1]))", "- * dp[i - 1]", "- )", "+ max(Fraction(t[i - 1][0], t[i][0]), Fraction(t[i - 1][1], t[i][1])) * dp[i - 1]" ]
false
0.109871
0.044223
2.484485
[ "s564622602", "s886982652" ]
u840247626
p02258
python
s432271596
s105492416
710
290
5,620
5,624
Accepted
Accepted
59.15
f = lambda: int(eval(input())) d = -float('inf') n = f() l = f() for _ in range(n-1): r = f() d = max(d, r-l) l = min(l, r) print(d)
import sys d = -float('inf') n = int(eval(input())) l = int(eval(input())) for s in sys.stdin: r = int(s) d = max(d, r-l) l = min(l, r) print(d)
9
9
138
144
f = lambda: int(eval(input())) d = -float("inf") n = f() l = f() for _ in range(n - 1): r = f() d = max(d, r - l) l = min(l, r) print(d)
import sys d = -float("inf") n = int(eval(input())) l = int(eval(input())) for s in sys.stdin: r = int(s) d = max(d, r - l) l = min(l, r) print(d)
false
0
[ "-f = lambda: int(eval(input()))", "+import sys", "+", "-n = f()", "-l = f()", "-for _ in range(n - 1):", "- r = f()", "+n = int(eval(input()))", "+l = int(eval(input()))", "+for s in sys.stdin:", "+ r = int(s)" ]
false
0.036055
0.034883
1.033589
[ "s432271596", "s105492416" ]
u714587753
p03324
python
s424410907
s113364455
225
194
2,568
40,556
Accepted
Accepted
13.78
s = input() ss = s.split() d = int(ss[0]) n = int(ss[1]) i = 1 while 1: x = i c = 0 while x % 100 == 0: x //= 100 c += 1 if c == d: n -= 1 if n == 0: print(i) break i += 1
s = input().strip() ss = s.split() d = int(ss[0]) n = int(ss[1]) i = 1 while 1: x = i c = 0 while x % 100 == 0: x //= 100 c += 1 if c == d: n -= 1 if n == 0: print(i) break i += 1
17
17
210
215
s = input() ss = s.split() d = int(ss[0]) n = int(ss[1]) i = 1 while 1: x = i c = 0 while x % 100 == 0: x //= 100 c += 1 if c == d: n -= 1 if n == 0: print(i) break i += 1
s = input().strip() ss = s.split() d = int(ss[0]) n = int(ss[1]) i = 1 while 1: x = i c = 0 while x % 100 == 0: x //= 100 c += 1 if c == d: n -= 1 if n == 0: print(i) break i += 1
false
0
[ "-s = input()", "+s = input().strip()" ]
false
0.443506
0.115609
3.836262
[ "s424410907", "s113364455" ]
u017415492
p03240
python
s541298487
s234677404
150
68
9,220
9,240
Accepted
Accepted
54.67
n=int(eval(input())) xyh = [list(map(int,input().split())) for i in range(n)] xyh.sort(key=lambda x:x[2], reverse=True) ansh=-1 ans=[[]] flag=True for cx in range(0,101): if flag==False: break for cy in range(0,101): ansh = 0 for pira in xyh: if ansh==0: ansh=pira[2]+(abs(cx-pira[0])+abs(cy-pira[1])) ans[0]=[cx,cy,ansh] elif len(ans[0])>0 and max(ansh -(abs(cx-pira[0])+abs(cy-pira[1])), 0) != pira[2]: ans[0]=[] if len(ans[0])>0: flag=False break print((*ans[0]))
n=int(eval(input())) xyh=[] for i in range(n): x,y,h=list(map(int,input().split())) xyh.append([h,x,y]) xyh.sort(reverse=True) ans=0 for cx in range(101): for cy in range(101): for N in range(n): if abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0]>0: H=abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0] else: break if xyh[N][0]!=max(H-abs(xyh[N][1]-cx)-abs(xyh[N][2]-cy),0): break if N == n-1: ans=[cx,cy,H] print((*ans))
24
20
565
486
n = int(eval(input())) xyh = [list(map(int, input().split())) for i in range(n)] xyh.sort(key=lambda x: x[2], reverse=True) ansh = -1 ans = [[]] flag = True for cx in range(0, 101): if flag == False: break for cy in range(0, 101): ansh = 0 for pira in xyh: if ansh == 0: ansh = pira[2] + (abs(cx - pira[0]) + abs(cy - pira[1])) ans[0] = [cx, cy, ansh] elif ( len(ans[0]) > 0 and max(ansh - (abs(cx - pira[0]) + abs(cy - pira[1])), 0) != pira[2] ): ans[0] = [] if len(ans[0]) > 0: flag = False break print((*ans[0]))
n = int(eval(input())) xyh = [] for i in range(n): x, y, h = list(map(int, input().split())) xyh.append([h, x, y]) xyh.sort(reverse=True) ans = 0 for cx in range(101): for cy in range(101): for N in range(n): if abs(xyh[0][1] - cx) + abs(xyh[0][2] - cy) + xyh[0][0] > 0: H = abs(xyh[0][1] - cx) + abs(xyh[0][2] - cy) + xyh[0][0] else: break if xyh[N][0] != max(H - abs(xyh[N][1] - cx) - abs(xyh[N][2] - cy), 0): break if N == n - 1: ans = [cx, cy, H] print((*ans))
false
16.666667
[ "-xyh = [list(map(int, input().split())) for i in range(n)]", "-xyh.sort(key=lambda x: x[2], reverse=True)", "-ansh = -1", "-ans = [[]]", "-flag = True", "-for cx in range(0, 101):", "- if flag == False:", "- break", "- for cy in range(0, 101):", "- ansh = 0", "- for pira in xyh:", "- if ansh == 0:", "- ansh = pira[2] + (abs(cx - pira[0]) + abs(cy - pira[1]))", "- ans[0] = [cx, cy, ansh]", "- elif (", "- len(ans[0]) > 0", "- and max(ansh - (abs(cx - pira[0]) + abs(cy - pira[1])), 0) != pira[2]", "- ):", "- ans[0] = []", "- if len(ans[0]) > 0:", "- flag = False", "- break", "-print((*ans[0]))", "+xyh = []", "+for i in range(n):", "+ x, y, h = list(map(int, input().split()))", "+ xyh.append([h, x, y])", "+xyh.sort(reverse=True)", "+ans = 0", "+for cx in range(101):", "+ for cy in range(101):", "+ for N in range(n):", "+ if abs(xyh[0][1] - cx) + abs(xyh[0][2] - cy) + xyh[0][0] > 0:", "+ H = abs(xyh[0][1] - cx) + abs(xyh[0][2] - cy) + xyh[0][0]", "+ else:", "+ break", "+ if xyh[N][0] != max(H - abs(xyh[N][1] - cx) - abs(xyh[N][2] - cy), 0):", "+ break", "+ if N == n - 1:", "+ ans = [cx, cy, H]", "+print((*ans))" ]
false
0.149281
0.137068
1.0891
[ "s541298487", "s234677404" ]
u048176319
p03799
python
s432081584
s482098825
71
17
2,940
2,940
Accepted
Accepted
76.06
n,m = list(map(int, input().split())) if n > (m+n)/3: print((m//2)) exit() if m > 10000000000: print((m//4)) exit() while n <= (n+m)/3: n += 1 m -= 2 print((n-1))
n,m = list(map(int, input().split())) if n > (m+n)/3: print((m//2)) exit() ans = n m -= 2*n ans += m//4 print(ans)
14
10
190
125
n, m = list(map(int, input().split())) if n > (m + n) / 3: print((m // 2)) exit() if m > 10000000000: print((m // 4)) exit() while n <= (n + m) / 3: n += 1 m -= 2 print((n - 1))
n, m = list(map(int, input().split())) if n > (m + n) / 3: print((m // 2)) exit() ans = n m -= 2 * n ans += m // 4 print(ans)
false
28.571429
[ "-if m > 10000000000:", "- print((m // 4))", "- exit()", "-while n <= (n + m) / 3:", "- n += 1", "- m -= 2", "-print((n - 1))", "+ans = n", "+m -= 2 * n", "+ans += m // 4", "+print(ans)" ]
false
0.062724
0.043176
1.452733
[ "s432081584", "s482098825" ]
u476604182
p02948
python
s165675934
s644402374
573
520
31,976
20,428
Accepted
Accepted
9.25
from heapq import heappop, heappush N, M = list(map(int, input().split())) X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0]) hq = [] ans, j = 0, 0 for i in range(1, M + 1): # M - i 日後にするバイトを考える while (j < N) and (X[j][0] <= i): heappush(hq, -X[j][1]) # 候補の追加 j += 1 if len(hq): ans += -heappop(hq) # 候補があるとき、候補から最大値を取り出す print(ans)
from heapq import heappush, heappop N, M = list(map(int, input().split())) job = [] for i in range(N): a, b = list(map(int, input().split())) job += [(a,b)] job.sort(key=lambda x:x[0]) ls = [] ans = 0 j = 0 a = -1 for i in range(1,M+1): while a<=i and j<len(job): a, b = job[j] if a>i: break heappush(ls, -b) j += 1 if ls: x = (-1)*heappop(ls) # print(x, i) ans += x print(ans)
15
25
414
432
from heapq import heappop, heappush N, M = list(map(int, input().split())) X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) hq = [] ans, j = 0, 0 for i in range(1, M + 1): # M - i 日後にするバイトを考える while (j < N) and (X[j][0] <= i): heappush(hq, -X[j][1]) # 候補の追加 j += 1 if len(hq): ans += -heappop(hq) # 候補があるとき、候補から最大値を取り出す print(ans)
from heapq import heappush, heappop N, M = list(map(int, input().split())) job = [] for i in range(N): a, b = list(map(int, input().split())) job += [(a, b)] job.sort(key=lambda x: x[0]) ls = [] ans = 0 j = 0 a = -1 for i in range(1, M + 1): while a <= i and j < len(job): a, b = job[j] if a > i: break heappush(ls, -b) j += 1 if ls: x = (-1) * heappop(ls) # print(x, i) ans += x print(ans)
false
40
[ "-from heapq import heappop, heappush", "+from heapq import heappush, heappop", "-X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])", "-hq = []", "-ans, j = 0, 0", "-for i in range(1, M + 1): # M - i 日後にするバイトを考える", "- while (j < N) and (X[j][0] <= i):", "- heappush(hq, -X[j][1]) # 候補の追加", "+job = []", "+for i in range(N):", "+ a, b = list(map(int, input().split()))", "+ job += [(a, b)]", "+job.sort(key=lambda x: x[0])", "+ls = []", "+ans = 0", "+j = 0", "+a = -1", "+for i in range(1, M + 1):", "+ while a <= i and j < len(job):", "+ a, b = job[j]", "+ if a > i:", "+ break", "+ heappush(ls, -b)", "- if len(hq):", "- ans += -heappop(hq) # 候補があるとき、候補から最大値を取り出す", "+ if ls:", "+ x = (-1) * heappop(ls)", "+ # print(x, i)", "+ ans += x" ]
false
0.091479
0.047103
1.942114
[ "s165675934", "s644402374" ]
u078349616
p03160
python
s312438521
s529518466
169
134
13,980
13,980
Accepted
Accepted
20.71
N = int(eval(input())) h = list(map(int,input().split())) dp = [float("INF")]*(N+1) dp[0] = 0 for i in range(1, N): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print((dp[N-1]))
N = int(eval(input())) h = list(map(int,input().split())) dp = [float("INF")]*N dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): c1 = dp[i-1] + abs(h[i] - h[i-1]) c2 = dp[i-2] + abs(h[i] - h[i-2]) dp[i] = min(c1, c2) print((dp[N-1]))
11
13
252
260
N = int(eval(input())) h = list(map(int, input().split())) dp = [float("INF")] * (N + 1) dp[0] = 0 for i in range(1, N): dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [float("INF")] * N dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): c1 = dp[i - 1] + abs(h[i] - h[i - 1]) c2 = dp[i - 2] + abs(h[i] - h[i - 2]) dp[i] = min(c1, c2) print((dp[N - 1]))
false
15.384615
[ "-dp = [float(\"INF\")] * (N + 1)", "+dp = [float(\"INF\")] * N", "-for i in range(1, N):", "- dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))", "- if i > 1:", "- dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))", "+dp[1] = abs(h[1] - h[0])", "+for i in range(2, N):", "+ c1 = dp[i - 1] + abs(h[i] - h[i - 1])", "+ c2 = dp[i - 2] + abs(h[i] - h[i - 2])", "+ dp[i] = min(c1, c2)" ]
false
0.037099
0.038971
0.951965
[ "s312438521", "s529518466" ]
u347600233
p02813
python
s930048633
s540030165
40
35
13,772
14,008
Accepted
Accepted
12.5
from itertools import permutations n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) perm = list(permutations(list(range(1, n + 1)), n)) print((abs(perm.index(p) - perm.index(q))))
from itertools import permutations n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) np = list(permutations(list(range(1, n + 1)), n)) print((abs(np.index(p) - np.index(q))))
6
6
218
212
from itertools import permutations n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) perm = list(permutations(list(range(1, n + 1)), n)) print((abs(perm.index(p) - perm.index(q))))
from itertools import permutations n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) np = list(permutations(list(range(1, n + 1)), n)) print((abs(np.index(p) - np.index(q))))
false
0
[ "-perm = list(permutations(list(range(1, n + 1)), n))", "-print((abs(perm.index(p) - perm.index(q))))", "+np = list(permutations(list(range(1, n + 1)), n))", "+print((abs(np.index(p) - np.index(q))))" ]
false
0.046439
0.048616
0.955218
[ "s930048633", "s540030165" ]
u645354978
p02270
python
s652622842
s423689366
590
540
9,432
9,356
Accepted
Accepted
8.47
import sys N, K = [int(s) for s in input().split()] ws = [int(input()) for _ in range(N)] lo, hi = max(ws), 100000 * 10000 while lo != hi: p = P = (lo + hi) / 2 k = 1 for w in ws: if w > p: p = P k += 1 p -= w if k <= K: hi = P else: lo = P + 1 print(lo)
N, K = [int(s) for s in input().split()] ws = [int(input()) for _ in range(N)] lo, hi = max(ws) - 1, sum(ws) while hi - lo > 1: p = P = (lo + hi) / 2 k = 1 for w in ws: if w > p: p = P k += 1 p -= w if k <= K: hi = P else: lo = P print(hi)
20
18
360
342
import sys N, K = [int(s) for s in input().split()] ws = [int(input()) for _ in range(N)] lo, hi = max(ws), 100000 * 10000 while lo != hi: p = P = (lo + hi) / 2 k = 1 for w in ws: if w > p: p = P k += 1 p -= w if k <= K: hi = P else: lo = P + 1 print(lo)
N, K = [int(s) for s in input().split()] ws = [int(input()) for _ in range(N)] lo, hi = max(ws) - 1, sum(ws) while hi - lo > 1: p = P = (lo + hi) / 2 k = 1 for w in ws: if w > p: p = P k += 1 p -= w if k <= K: hi = P else: lo = P print(hi)
false
10
[ "-import sys", "-", "-lo, hi = max(ws), 100000 * 10000", "-while lo != hi:", "+lo, hi = max(ws) - 1, sum(ws)", "+while hi - lo > 1:", "- lo = P + 1", "-print(lo)", "+ lo = P", "+print(hi)" ]
false
0.036724
0.036798
0.997997
[ "s652622842", "s423689366" ]
u645250356
p03127
python
s172424931
s591775506
331
177
85,352
90,556
Accepted
Accepted
46.53
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() res = a[0] for i in range(n-1): res = fractions.gcd(res,a[i+1]) print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() now = a[0] for i in range(1,n): now = math.gcd(now, a[i]) print(now)
15
16
428
452
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() res = a[0] for i in range(n - 1): res = fractions.gcd(res, a[i + 1]) print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() now = a[0] for i in range(1, n): now = math.gcd(now, a[i]) print(now)
false
6.25
[ "-from heapq import heappop, heappush, heapify", "-import sys, bisect, math, itertools, fractions, pprint", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "-res = a[0]", "-for i in range(n - 1):", "- res = fractions.gcd(res, a[i + 1])", "-print(res)", "+now = a[0]", "+for i in range(1, n):", "+ now = math.gcd(now, a[i])", "+print(now)" ]
false
0.046065
0.038838
1.186092
[ "s172424931", "s591775506" ]
u912237403
p00042
python
s628575886
s627737925
490
190
4,332
4,312
Accepted
Accepted
61.22
c =0 while True: W = eval(input()) if W==0: break dt = [0]*1001 c +=1 N = eval(input()) m = 0 n = 0 for i in range(N): p,w = eval(input()) for w0 in range(W+1)[::-1]: p0 = dt[w0] if w0==0 or p0!=0: w1 = w0+w p1 = p0+p if w1<=W and dt[w1]<p1: dt[w1]=p1 m = max(dt) n = dt.index(m) print("Case {}:".format(c)) print(m) print(n)
def f(): p,w = eval(input()) for w0 in R[w:]: w1,p1 = w0+w,dt[w0]+p if dt[w1]<p1: dt[w1]=p1 return c = 0 while 1: W = eval(input()) if W==0: break R = list(range(W+1))[::-1] dt = [0]*1001 c += 1 N = eval(input()) for i in range(N): f() m = max(dt) n = dt.index(m) print("Case {}:\n{}\n{}".format(c,m,n))
22
19
465
365
c = 0 while True: W = eval(input()) if W == 0: break dt = [0] * 1001 c += 1 N = eval(input()) m = 0 n = 0 for i in range(N): p, w = eval(input()) for w0 in range(W + 1)[::-1]: p0 = dt[w0] if w0 == 0 or p0 != 0: w1 = w0 + w p1 = p0 + p if w1 <= W and dt[w1] < p1: dt[w1] = p1 m = max(dt) n = dt.index(m) print("Case {}:".format(c)) print(m) print(n)
def f(): p, w = eval(input()) for w0 in R[w:]: w1, p1 = w0 + w, dt[w0] + p if dt[w1] < p1: dt[w1] = p1 return c = 0 while 1: W = eval(input()) if W == 0: break R = list(range(W + 1))[::-1] dt = [0] * 1001 c += 1 N = eval(input()) for i in range(N): f() m = max(dt) n = dt.index(m) print("Case {}:\n{}\n{}".format(c, m, n))
false
13.636364
[ "+def f():", "+ p, w = eval(input())", "+ for w0 in R[w:]:", "+ w1, p1 = w0 + w, dt[w0] + p", "+ if dt[w1] < p1:", "+ dt[w1] = p1", "+ return", "+", "+", "-while True:", "+while 1:", "+ R = list(range(W + 1))[::-1]", "- m = 0", "- n = 0", "- p, w = eval(input())", "- for w0 in range(W + 1)[::-1]:", "- p0 = dt[w0]", "- if w0 == 0 or p0 != 0:", "- w1 = w0 + w", "- p1 = p0 + p", "- if w1 <= W and dt[w1] < p1:", "- dt[w1] = p1", "+ f()", "- print(\"Case {}:\".format(c))", "- print(m)", "- print(n)", "+ print(\"Case {}:\\n{}\\n{}\".format(c, m, n))" ]
false
0.042208
0.079452
0.531236
[ "s628575886", "s627737925" ]
u263830634
p03644
python
s782387821
s884428270
19
17
2,940
2,940
Accepted
Accepted
10.53
N = int(eval(input())) ans = 1 while ans * 2 <= N: ans *= 2 print (ans)
N = int(eval(input())) ans = 0 count = 0 for i in range(1, N + 1): tmp = 0 j = i while j % 2 == 0: j //= 2 tmp += 1 if tmp >= count: count = tmp ans = i print (ans)
7
16
77
232
N = int(eval(input())) ans = 1 while ans * 2 <= N: ans *= 2 print(ans)
N = int(eval(input())) ans = 0 count = 0 for i in range(1, N + 1): tmp = 0 j = i while j % 2 == 0: j //= 2 tmp += 1 if tmp >= count: count = tmp ans = i print(ans)
false
56.25
[ "-ans = 1", "-while ans * 2 <= N:", "- ans *= 2", "+ans = 0", "+count = 0", "+for i in range(1, N + 1):", "+ tmp = 0", "+ j = i", "+ while j % 2 == 0:", "+ j //= 2", "+ tmp += 1", "+ if tmp >= count:", "+ count = tmp", "+ ans = i" ]
false
0.049401
0.048798
1.01235
[ "s782387821", "s884428270" ]
u539281377
p02983
python
s413426105
s409975492
816
405
149,080
75,392
Accepted
Accepted
50.37
L,R=list(map(int,input().split())) if R-L>2019: print((0)) else: ans=[i*j%2019 for i in range(L,R) for j in range(L+1,R+1)] print((min(ans)))
L,R=list(map(int,input().split())) ans=0 if R-L<2019: ans=min([i*j%2019 for i in range(L,R) for j in range(i+1,R+1)]) print(ans)
5
5
145
130
L, R = list(map(int, input().split())) if R - L > 2019: print((0)) else: ans = [i * j % 2019 for i in range(L, R) for j in range(L + 1, R + 1)] print((min(ans)))
L, R = list(map(int, input().split())) ans = 0 if R - L < 2019: ans = min([i * j % 2019 for i in range(L, R) for j in range(i + 1, R + 1)]) print(ans)
false
0
[ "-if R - L > 2019:", "- print((0))", "-else:", "- ans = [i * j % 2019 for i in range(L, R) for j in range(L + 1, R + 1)]", "- print((min(ans)))", "+ans = 0", "+if R - L < 2019:", "+ ans = min([i * j % 2019 for i in range(L, R) for j in range(i + 1, R + 1)])", "+print(ans)" ]
false
0.044335
0.05083
0.872222
[ "s413426105", "s409975492" ]
u301624971
p02755
python
s614042345
s904255373
38
18
5,048
3,064
Accepted
Accepted
52.63
import fractions import sys A,B=list(map(int,input().split())) for i in range(1,1009): if(int(i*0.08) == A and int(i*0.1)==B): print(i) sys.exit() print((-1))
from math import floor def myAnswer(A:int,B:int) -> int: price = 1 while True: if(floor(price*0.08)==A and floor(price*0.1)==B): return price elif(floor(price*0.08)>A or floor(price*0.1)>B): return -1 else: price+=1 def modelAnswer(): tmp=1 def main(): A,B = list(map(int,input().split())) print((myAnswer(A,B))) if __name__ == '__main__': main()
9
20
179
426
import fractions import sys A, B = list(map(int, input().split())) for i in range(1, 1009): if int(i * 0.08) == A and int(i * 0.1) == B: print(i) sys.exit() print((-1))
from math import floor def myAnswer(A: int, B: int) -> int: price = 1 while True: if floor(price * 0.08) == A and floor(price * 0.1) == B: return price elif floor(price * 0.08) > A or floor(price * 0.1) > B: return -1 else: price += 1 def modelAnswer(): tmp = 1 def main(): A, B = list(map(int, input().split())) print((myAnswer(A, B))) if __name__ == "__main__": main()
false
55
[ "-import fractions", "-import sys", "+from math import floor", "-A, B = list(map(int, input().split()))", "-for i in range(1, 1009):", "- if int(i * 0.08) == A and int(i * 0.1) == B:", "- print(i)", "- sys.exit()", "-print((-1))", "+", "+def myAnswer(A: int, B: int) -> int:", "+ price = 1", "+ while True:", "+ if floor(price * 0.08) == A and floor(price * 0.1) == B:", "+ return price", "+ elif floor(price * 0.08) > A or floor(price * 0.1) > B:", "+ return -1", "+ else:", "+ price += 1", "+", "+", "+def modelAnswer():", "+ tmp = 1", "+", "+", "+def main():", "+ A, B = list(map(int, input().split()))", "+ print((myAnswer(A, B)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037953
0.075573
0.502208
[ "s614042345", "s904255373" ]
u261103969
p02596
python
s450979000
s860752158
201
139
62,876
9,092
Accepted
Accepted
30.85
def calc(k): cur = 0 for i in range(1, 10 ** 7): cur *= 10 cur += 7 cur %= k if cur == 0: return i return -1 k = int(eval(input())) print((calc(k)))
def calc(k): cur = 7 % k for i in range(1, k + 1): if cur == 0: return i else: cur *= 10 cur += 7 cur %= k return -1 k = int(eval(input())) print((calc(k)))
14
14
212
240
def calc(k): cur = 0 for i in range(1, 10**7): cur *= 10 cur += 7 cur %= k if cur == 0: return i return -1 k = int(eval(input())) print((calc(k)))
def calc(k): cur = 7 % k for i in range(1, k + 1): if cur == 0: return i else: cur *= 10 cur += 7 cur %= k return -1 k = int(eval(input())) print((calc(k)))
false
0
[ "- cur = 0", "- for i in range(1, 10**7):", "- cur *= 10", "- cur += 7", "- cur %= k", "+ cur = 7 % k", "+ for i in range(1, k + 1):", "+ else:", "+ cur *= 10", "+ cur += 7", "+ cur %= k" ]
false
0.803408
0.089
9.027085
[ "s450979000", "s860752158" ]
u476604182
p02949
python
s493662087
s226153031
1,637
602
48,868
48,928
Accepted
Accepted
63.23
from collections import deque N,M,P,*L = list(map(int, open(0).read().split())) INF = 10**9 Els = [] dic = [[] for i in range(N+1)] rdic = [[] for i in range(N+1)] for a,b,c in zip(*[iter(L)]*3): dic[a].append((b,c-P)) rdic[b].append((a,c-P)) Els.append((a,b,-c+P)) ok1 = [False]*(N+1) ok1[1] = True q = deque([1]) while q: v = q.popleft() for p,c in dic[v]: if not ok1[p]: ok1[p] = True q.append(p) ok2 = [False]*(N+1) ok2[N] = True q = deque([N]) while q: v = q.popleft() for p,c in rdic[v]: if not ok2[p]: ok2[p] = True q.append(p) ok = [a&b for a,b in zip(ok1,ok2)] dist = [INF]*(N+1) dist[1] = 0 cnt = 0 while True: end = True for a,b,c in Els: if ok[a] and ok[b] and dist[a]!=INF and dist[b]>dist[a]+c: end = False dist[b] = dist[a]+c if end: print((max(0,-dist[N]))) break cnt += 1 if cnt>2*M: print((-1)) break
from collections import deque N,M,P,*L = list(map(int, open(0).read().split())) INF = 10**9 Els = [] dic = [[] for i in range(N+1)] rdic = [[] for i in range(N+1)] for a,b,c in zip(*[iter(L)]*3): dic[a].append((b,c-P)) rdic[b].append((a,c-P)) Els.append((a,b,-c+P)) ok1 = [False]*(N+1) ok1[1] = True q = deque([1]) while q: v = q.popleft() for p,c in dic[v]: if not ok1[p]: ok1[p] = True q.append(p) ok2 = [False]*(N+1) ok2[N] = True q = deque([N]) while q: v = q.popleft() for p,c in rdic[v]: if not ok2[p]: ok2[p] = True q.append(p) ok = [a&b for a,b in zip(ok1,ok2)] dist = [INF]*(N+1) dist[1] = 0 cnt = 0 while True: end = True for a,b,c in Els: if ok[a] and ok[b] and dist[a]!=INF and dist[b]>dist[a]+c: end = False dist[b] = dist[a]+c if end: print((max(0,-dist[N]))) break cnt += 1 if cnt>N: print((-1)) break
48
48
946
944
from collections import deque N, M, P, *L = list(map(int, open(0).read().split())) INF = 10**9 Els = [] dic = [[] for i in range(N + 1)] rdic = [[] for i in range(N + 1)] for a, b, c in zip(*[iter(L)] * 3): dic[a].append((b, c - P)) rdic[b].append((a, c - P)) Els.append((a, b, -c + P)) ok1 = [False] * (N + 1) ok1[1] = True q = deque([1]) while q: v = q.popleft() for p, c in dic[v]: if not ok1[p]: ok1[p] = True q.append(p) ok2 = [False] * (N + 1) ok2[N] = True q = deque([N]) while q: v = q.popleft() for p, c in rdic[v]: if not ok2[p]: ok2[p] = True q.append(p) ok = [a & b for a, b in zip(ok1, ok2)] dist = [INF] * (N + 1) dist[1] = 0 cnt = 0 while True: end = True for a, b, c in Els: if ok[a] and ok[b] and dist[a] != INF and dist[b] > dist[a] + c: end = False dist[b] = dist[a] + c if end: print((max(0, -dist[N]))) break cnt += 1 if cnt > 2 * M: print((-1)) break
from collections import deque N, M, P, *L = list(map(int, open(0).read().split())) INF = 10**9 Els = [] dic = [[] for i in range(N + 1)] rdic = [[] for i in range(N + 1)] for a, b, c in zip(*[iter(L)] * 3): dic[a].append((b, c - P)) rdic[b].append((a, c - P)) Els.append((a, b, -c + P)) ok1 = [False] * (N + 1) ok1[1] = True q = deque([1]) while q: v = q.popleft() for p, c in dic[v]: if not ok1[p]: ok1[p] = True q.append(p) ok2 = [False] * (N + 1) ok2[N] = True q = deque([N]) while q: v = q.popleft() for p, c in rdic[v]: if not ok2[p]: ok2[p] = True q.append(p) ok = [a & b for a, b in zip(ok1, ok2)] dist = [INF] * (N + 1) dist[1] = 0 cnt = 0 while True: end = True for a, b, c in Els: if ok[a] and ok[b] and dist[a] != INF and dist[b] > dist[a] + c: end = False dist[b] = dist[a] + c if end: print((max(0, -dist[N]))) break cnt += 1 if cnt > N: print((-1)) break
false
0
[ "- if cnt > 2 * M:", "+ if cnt > N:" ]
false
0.038277
0.037786
1.012999
[ "s493662087", "s226153031" ]
u434872492
p02984
python
s824797604
s981582358
190
109
14,408
95,384
Accepted
Accepted
42.63
N=int(eval(input())) A=list(map(int,input().split())) ans=[0]*N t=0 for i in range(N): if i%2==0: t+=A[i] else: t-=A[i] t=t/2 ans[0]=t for i in range(1,N): ans[i]=A[i-1]-ans[i-1] for i in range(N): ans[i]=int(2*ans[i]) print((*ans[0:]))
N = int(eval(input())) A = list(map(int,input().split())) ans = [] res = 0 for i in range(N): if i%2==0: res += A[i] else: res -= A[i] ans.append(res) for i in range(1,N): res = 2*A[i-1]-ans[-1] ans.append(res) print((*ans))
17
18
277
269
N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N t = 0 for i in range(N): if i % 2 == 0: t += A[i] else: t -= A[i] t = t / 2 ans[0] = t for i in range(1, N): ans[i] = A[i - 1] - ans[i - 1] for i in range(N): ans[i] = int(2 * ans[i]) print((*ans[0:]))
N = int(eval(input())) A = list(map(int, input().split())) ans = [] res = 0 for i in range(N): if i % 2 == 0: res += A[i] else: res -= A[i] ans.append(res) for i in range(1, N): res = 2 * A[i - 1] - ans[-1] ans.append(res) print((*ans))
false
5.555556
[ "-ans = [0] * N", "-t = 0", "+ans = []", "+res = 0", "- t += A[i]", "+ res += A[i]", "- t -= A[i]", "-t = t / 2", "-ans[0] = t", "+ res -= A[i]", "+ans.append(res)", "- ans[i] = A[i - 1] - ans[i - 1]", "-for i in range(N):", "- ans[i] = int(2 * ans[i])", "-print((*ans[0:]))", "+ res = 2 * A[i - 1] - ans[-1]", "+ ans.append(res)", "+print((*ans))" ]
false
0.037056
0.035285
1.050177
[ "s824797604", "s981582358" ]
u628070051
p03605
python
s528520526
s246685123
28
25
9,012
8,936
Accepted
Accepted
10.71
N = eval(input()) if '9' in N: print('Yes') else: print('No')
N = str(eval(input())) def answer(N: str) -> str: if '9' in N: return 'Yes' else: return 'No' print((answer(N)))
5
9
67
138
N = eval(input()) if "9" in N: print("Yes") else: print("No")
N = str(eval(input())) def answer(N: str) -> str: if "9" in N: return "Yes" else: return "No" print((answer(N)))
false
44.444444
[ "-N = eval(input())", "-if \"9\" in N:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+N = str(eval(input()))", "+", "+", "+def answer(N: str) -> str:", "+ if \"9\" in N:", "+ return \"Yes\"", "+ else:", "+ return \"No\"", "+", "+", "+print((answer(N)))" ]
false
0.043486
0.037221
1.168336
[ "s528520526", "s246685123" ]
u462329577
p03606
python
s778083549
s745412202
206
20
39,408
2,940
Accepted
Accepted
90.29
def print_ans(l,r,N): """print(sum(r)-sum(l)+N) Parameters -------------- >>> print_ans([24],[30],1) 7 >>> print_ans([6,3],[8,3],2) 4 """ print((sum(r)-sum(l)+N)) def main(): N = int(eval(input())) l = [] r = [] for i in range(N): s = list(map(int,input().split())) l.append(s[0]) r.append(s[1]) print_ans(l,r,N) if __name__ == '__main__': main()
n = int(eval(input())) ans = 0 for i in range(n): r,l = list(map(int,input().split())) ans = ans + l -r + 1 print(ans)
29
6
420
120
def print_ans(l, r, N): """print(sum(r)-sum(l)+N) Parameters -------------- >>> print_ans([24],[30],1) 7 >>> print_ans([6,3],[8,3],2) 4 """ print((sum(r) - sum(l) + N)) def main(): N = int(eval(input())) l = [] r = [] for i in range(N): s = list(map(int, input().split())) l.append(s[0]) r.append(s[1]) print_ans(l, r, N) if __name__ == "__main__": main()
n = int(eval(input())) ans = 0 for i in range(n): r, l = list(map(int, input().split())) ans = ans + l - r + 1 print(ans)
false
79.310345
[ "-def print_ans(l, r, N):", "- \"\"\"print(sum(r)-sum(l)+N)", "- Parameters", "- >>> print_ans([24],[30],1)", "- 7", "- >>> print_ans([6,3],[8,3],2)", "- 4", "- \"\"\"", "- print((sum(r) - sum(l) + N))", "-", "-", "-def main():", "- N = int(eval(input()))", "- l = []", "- r = []", "- for i in range(N):", "- s = list(map(int, input().split()))", "- l.append(s[0])", "- r.append(s[1])", "- print_ans(l, r, N)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n = int(eval(input()))", "+ans = 0", "+for i in range(n):", "+ r, l = list(map(int, input().split()))", "+ ans = ans + l - r + 1", "+print(ans)" ]
false
0.067572
0.117818
0.573531
[ "s778083549", "s745412202" ]
u680851063
p02743
python
s123940124
s147865144
36
31
5,076
9,080
Accepted
Accepted
13.89
from decimal import Decimal a, b, c = list(map(int,input().split())) if (Decimal(a).sqrt() + Decimal(b).sqrt()) >= Decimal(c).sqrt(): print('No') else: print('Yes')
a,b,c = list(map(int, input().split())) if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0: print('Yes') else: print('No')
8
6
175
130
from decimal import Decimal a, b, c = list(map(int, input().split())) if (Decimal(a).sqrt() + Decimal(b).sqrt()) >= Decimal(c).sqrt(): print("No") else: print("Yes")
a, b, c = list(map(int, input().split())) if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0: print("Yes") else: print("No")
false
25
[ "-from decimal import Decimal", "-", "-if (Decimal(a).sqrt() + Decimal(b).sqrt()) >= Decimal(c).sqrt():", "+if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0:", "+ print(\"Yes\")", "+else:", "-else:", "- print(\"Yes\")" ]
false
0.062006
0.036031
1.720936
[ "s123940124", "s147865144" ]
u088115428
p02713
python
s318639706
s976315697
1,967
1,347
9,168
9,572
Accepted
Accepted
31.52
from math import gcd n = int(eval(input())) g = 0 for i in range (1, n+1): for j in range (1, n+1): for k in range (1, n+1): g += gcd(gcd(i,j),k) print(g)
import functools from math import gcd n = int(eval(input())) @functools.lru_cache(None) def main(n): g=0 for i in range (1, n+1): for j in range (1, n+1): for k in range (1, n+1): g += gcd(gcd(i,j),k) return (g) print((main(n)))
9
12
171
256
from math import gcd n = int(eval(input())) g = 0 for i in range(1, n + 1): for j in range(1, n + 1): for k in range(1, n + 1): g += gcd(gcd(i, j), k) print(g)
import functools from math import gcd n = int(eval(input())) @functools.lru_cache(None) def main(n): g = 0 for i in range(1, n + 1): for j in range(1, n + 1): for k in range(1, n + 1): g += gcd(gcd(i, j), k) return g print((main(n)))
false
25
[ "+import functools", "-g = 0", "-for i in range(1, n + 1):", "- for j in range(1, n + 1):", "- for k in range(1, n + 1):", "- g += gcd(gcd(i, j), k)", "-print(g)", "+", "+", "[email protected]_cache(None)", "+def main(n):", "+ g = 0", "+ for i in range(1, n + 1):", "+ for j in range(1, n + 1):", "+ for k in range(1, n + 1):", "+ g += gcd(gcd(i, j), k)", "+ return g", "+", "+", "+print((main(n)))" ]
false
0.04283
0.039572
1.082329
[ "s318639706", "s976315697" ]
u670180528
p03448
python
s799069372
s886095012
59
50
2,940
2,940
Accepted
Accepted
15.25
a,b,c,x=list(map(int,open(0)));d=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): d+=i*500+j*100+k*50==x print(d)
a,b,c,x=list(map(int,open(0))) print((sum(500*i+100*j+50*k==x for i in range(a+1)for j in range(b+1)for k in range(c+1))))
6
2
135
115
a, b, c, x = list(map(int, open(0))) d = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): d += i * 500 + j * 100 + k * 50 == x print(d)
a, b, c, x = list(map(int, open(0))) print( ( sum( 500 * i + 100 * j + 50 * k == x for i in range(a + 1) for j in range(b + 1) for k in range(c + 1) ) ) )
false
66.666667
[ "-d = 0", "-for i in range(a + 1):", "- for j in range(b + 1):", "- for k in range(c + 1):", "- d += i * 500 + j * 100 + k * 50 == x", "-print(d)", "+print(", "+ (", "+ sum(", "+ 500 * i + 100 * j + 50 * k == x", "+ for i in range(a + 1)", "+ for j in range(b + 1)", "+ for k in range(c + 1)", "+ )", "+ )", "+)" ]
false
0.244404
0.074235
3.292306
[ "s799069372", "s886095012" ]
u403301154
p02975
python
s012962791
s567878587
237
74
60,784
14,832
Accepted
Accepted
68.78
n = int(eval(input())) a = list(map(int, input().split())) b = set(a) c = sorted(list(b)) if len(b)==1 and c[0]==0: print("Yes") exit() if c[0]==0: if n%2==0 and a.count(c[0])==n//2 and a.count(c[1])==n//2: print("Yes") exit() if n%2==1 and a.count(c[0])==n//2 and a.count(c[1])==n//2+1: print("Yes") exit() if n%3!=0: print("No") exit() if len(b)==2: if c[0]==0 and a.count(c[0])==n//3 and a.count(c[1])==(n//3)*2: print("Yes") exit() if len(b)==3: p, q, r = c[0], c[1], c[2] if p^q==r or q^r==p or r^p==q: if a.count(c[0])==n//3 and a.count(c[1])==n//3 and a.count(c[2])==n//3: print("Yes") exit() print("No")
n = int(eval(input())) a = list(map(int, input().split())) b = set(a) c = sorted(list(b)) if len(b)==1 and c[0]==0: print("Yes") exit() elif n%3!=0: print("No") exit() elif len(b)==2: if c[0]==0 and a.count(c[0])==n//3 and a.count(c[1])==(n//3)*2: print("Yes") exit() elif len(b)==3: p, q, r = c[0], c[1], c[2] if p^q==r or q^r==p or r^p==q: if a.count(c[0])==n//3 and a.count(c[1])==n//3 and a.count(c[2])==n//3: print("Yes") exit() print("No")
28
21
690
497
n = int(eval(input())) a = list(map(int, input().split())) b = set(a) c = sorted(list(b)) if len(b) == 1 and c[0] == 0: print("Yes") exit() if c[0] == 0: if n % 2 == 0 and a.count(c[0]) == n // 2 and a.count(c[1]) == n // 2: print("Yes") exit() if n % 2 == 1 and a.count(c[0]) == n // 2 and a.count(c[1]) == n // 2 + 1: print("Yes") exit() if n % 3 != 0: print("No") exit() if len(b) == 2: if c[0] == 0 and a.count(c[0]) == n // 3 and a.count(c[1]) == (n // 3) * 2: print("Yes") exit() if len(b) == 3: p, q, r = c[0], c[1], c[2] if p ^ q == r or q ^ r == p or r ^ p == q: if ( a.count(c[0]) == n // 3 and a.count(c[1]) == n // 3 and a.count(c[2]) == n // 3 ): print("Yes") exit() print("No")
n = int(eval(input())) a = list(map(int, input().split())) b = set(a) c = sorted(list(b)) if len(b) == 1 and c[0] == 0: print("Yes") exit() elif n % 3 != 0: print("No") exit() elif len(b) == 2: if c[0] == 0 and a.count(c[0]) == n // 3 and a.count(c[1]) == (n // 3) * 2: print("Yes") exit() elif len(b) == 3: p, q, r = c[0], c[1], c[2] if p ^ q == r or q ^ r == p or r ^ p == q: if ( a.count(c[0]) == n // 3 and a.count(c[1]) == n // 3 and a.count(c[2]) == n // 3 ): print("Yes") exit() print("No")
false
25
[ "-if c[0] == 0:", "- if n % 2 == 0 and a.count(c[0]) == n // 2 and a.count(c[1]) == n // 2:", "- print(\"Yes\")", "- exit()", "- if n % 2 == 1 and a.count(c[0]) == n // 2 and a.count(c[1]) == n // 2 + 1:", "- print(\"Yes\")", "- exit()", "-if n % 3 != 0:", "+elif n % 3 != 0:", "-if len(b) == 2:", "+elif len(b) == 2:", "-if len(b) == 3:", "+elif len(b) == 3:" ]
false
0.065552
0.040341
1.624945
[ "s012962791", "s567878587" ]
u597455618
p02559
python
s073690892
s403209143
2,713
687
160,764
172,544
Accepted
Accepted
74.68
import numpy as np from numba import njit, i8, jitclass import sys spec = [ ("size", i8), ("tree", i8[:]) ] @jitclass(spec) class Bit: def __init__(self, n, arr): self.size = n self.tree = np.array([0] + arr, np.int64) for i in range(1, n+1): x = i + (i & -i) if x < n + 1: self.tree[x] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p+1, x) if __name__ == "__main__": main()
import sys class Bit: def __init__(self, n, arr): self.size = n self.tree = [0] + arr for i in range(1, n+1): x = i + (i & -i) if x < n + 1: self.tree[x] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p+1, x) if __name__ == "__main__": main()
49
40
1,099
947
import numpy as np from numba import njit, i8, jitclass import sys spec = [("size", i8), ("tree", i8[:])] @jitclass(spec) class Bit: def __init__(self, n, arr): self.size = n self.tree = np.array([0] + arr, np.int64) for i in range(1, n + 1): x = i + (i & -i) if x < n + 1: self.tree[x] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p + 1, x) if __name__ == "__main__": main()
import sys class Bit: def __init__(self, n, arr): self.size = n self.tree = [0] + arr for i in range(1, n + 1): x = i + (i & -i) if x < n + 1: self.tree[x] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p + 1, x) if __name__ == "__main__": main()
false
18.367347
[ "-import numpy as np", "-from numba import njit, i8, jitclass", "-spec = [(\"size\", i8), (\"tree\", i8[:])]", "-", "-@jitclass(spec)", "- self.tree = np.array([0] + arr, np.int64)", "+ self.tree = [0] + arr" ]
false
0.252624
0.046249
5.462284
[ "s073690892", "s403209143" ]