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
u254871849
p02834
python
s353844913
s318582453
446
304
36,284
31,960
Accepted
Accepted
31.84
import sys n, u, v, *ab = list(map(int, sys.stdin.read().split())) ab = list(zip(*[iter(ab)] * 2)) graph = [[] for _ in range(n+1)] for a, b in ab: graph[a].append(b) graph[b].append(a) def dfs(v): dist = [None] * (n + 1) dist[v] = 0 stack = [v] while stack: x = stack.pop() for y in graph[x]: if dist[y] is None: dist[y] = dist[x] + 1 stack.append(y) return dist def main(): dist_u = dfs(u) dist_v = dfs(v) d = 1 for i in range(1, n+1): if dist_v[i] >= dist_u[i]: d = max(d, dist_v[i]) ans = d - 1 return ans if __name__ == '__main__': ans = main() print(ans)
import sys n, u, v, *ab = list(map(int, sys.stdin.read().split())) graph = [[] for _ in range(n+1)] for a, b in zip(*[iter(ab)] * 2): graph[a].append(b) graph[b].append(a) def dfs(v): dist = [None] * (n + 1) dist[v] = 0 stack = [v] while stack: x = stack.pop() for y in graph[x]: if dist[y] is None: dist[y] = dist[x] + 1 stack.append(y) return dist def main(): dist_u = dfs(u) dist_v = dfs(v) d = 1 for i in range(1, n+1): if dist_v[i] >= dist_u[i]: d = max(d, dist_v[i]) ans = d - 1 return ans if __name__ == '__main__': ans = main() print(ans)
35
34
733
718
import sys n, u, v, *ab = list(map(int, sys.stdin.read().split())) ab = list(zip(*[iter(ab)] * 2)) graph = [[] for _ in range(n + 1)] for a, b in ab: graph[a].append(b) graph[b].append(a) def dfs(v): dist = [None] * (n + 1) dist[v] = 0 stack = [v] while stack: x = stack.pop() for y in graph[x]: if dist[y] is None: dist[y] = dist[x] + 1 stack.append(y) return dist def main(): dist_u = dfs(u) dist_v = dfs(v) d = 1 for i in range(1, n + 1): if dist_v[i] >= dist_u[i]: d = max(d, dist_v[i]) ans = d - 1 return ans if __name__ == "__main__": ans = main() print(ans)
import sys n, u, v, *ab = list(map(int, sys.stdin.read().split())) graph = [[] for _ in range(n + 1)] for a, b in zip(*[iter(ab)] * 2): graph[a].append(b) graph[b].append(a) def dfs(v): dist = [None] * (n + 1) dist[v] = 0 stack = [v] while stack: x = stack.pop() for y in graph[x]: if dist[y] is None: dist[y] = dist[x] + 1 stack.append(y) return dist def main(): dist_u = dfs(u) dist_v = dfs(v) d = 1 for i in range(1, n + 1): if dist_v[i] >= dist_u[i]: d = max(d, dist_v[i]) ans = d - 1 return ans if __name__ == "__main__": ans = main() print(ans)
false
2.857143
[ "-ab = list(zip(*[iter(ab)] * 2))", "-for a, b in ab:", "+for a, b in zip(*[iter(ab)] * 2):" ]
false
0.130503
0.065496
1.992543
[ "s353844913", "s318582453" ]
u760802228
p02573
python
s825125623
s829385262
1,012
477
115,452
79,544
Accepted
Accepted
52.87
import queue N, M = list(map(int, input().split())) l = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) l[a - 1].append(b - 1) l[b - 1].append(a - 1) c = [0] * N ans = 1 q = queue.Queue() for j in range(N): q.put(l[j]) u = 0 while not q.empty(): temp = q.get() for k in temp: if c[k]: continue c[k] = 1 u += 1 q.put(l[k]) ans = max(ans, u) print(ans)
N, M = list(map(int, input().split())) r = [-1] * (N + 1) def root(x): if r[x] < 0: return x return root(r[x]) for i in range(M): x, y = list(map(int, input().split())) x = root(x) y = root(y) if x == y: continue if r[x] > r[y]: x, y = y, x r[x] += r[y] r[y] = x print((-min(r)))
23
20
613
408
import queue N, M = list(map(int, input().split())) l = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) l[a - 1].append(b - 1) l[b - 1].append(a - 1) c = [0] * N ans = 1 q = queue.Queue() for j in range(N): q.put(l[j]) u = 0 while not q.empty(): temp = q.get() for k in temp: if c[k]: continue c[k] = 1 u += 1 q.put(l[k]) ans = max(ans, u) print(ans)
N, M = list(map(int, input().split())) r = [-1] * (N + 1) def root(x): if r[x] < 0: return x return root(r[x]) for i in range(M): x, y = list(map(int, input().split())) x = root(x) y = root(y) if x == y: continue if r[x] > r[y]: x, y = y, x r[x] += r[y] r[y] = x print((-min(r)))
false
13.043478
[ "-import queue", "+N, M = list(map(int, input().split()))", "+r = [-1] * (N + 1)", "-N, M = list(map(int, input().split()))", "-l = [[] for i in range(N)]", "+", "+def root(x):", "+ if r[x] < 0:", "+ return x", "+ return root(r[x])", "+", "+", "- a, b = list(map(int, input().split()))", "- l[a - 1].append(b - 1)", "- l[b - 1].append(a - 1)", "-c = [0] * N", "-ans = 1", "-q = queue.Queue()", "-for j in range(N):", "- q.put(l[j])", "- u = 0", "- while not q.empty():", "- temp = q.get()", "- for k in temp:", "- if c[k]:", "- continue", "- c[k] = 1", "- u += 1", "- q.put(l[k])", "- ans = max(ans, u)", "-print(ans)", "+ x, y = list(map(int, input().split()))", "+ x = root(x)", "+ y = root(y)", "+ if x == y:", "+ continue", "+ if r[x] > r[y]:", "+ x, y = y, x", "+ r[x] += r[y]", "+ r[y] = x", "+print((-min(r)))" ]
false
0.04143
0.037665
1.099973
[ "s825125623", "s829385262" ]
u143492911
p03339
python
s732691661
s249005774
331
280
29,328
19,948
Accepted
Accepted
15.41
n=int(eval(input())) s=list(eval(input())) cnt=s[1:].count("E") e_cnt=[0]*(n+1) w_cnt=[0]*(n+1) e_cnt[0]=cnt for i in range(n): w_cnt[i+1]=w_cnt[i]+(s[i]=="W")#Wの数を累積和でとる for i in range(1,n): e_cnt[i]=e_cnt[i-1]-(s[i]=="E")#Eの数を累積和でとる ans=float("inf") for i in range(n): ans=min(ans,w_cnt[i]+e_cnt[i]) print(ans)
n=int(eval(input())) s=list(eval(input())) w_cnt=[0]*(n+1) e_cnt=[0]*(n+1) s.insert(0,"G") for i in range(1,n+1): if s[i]=="W": w_cnt[i]=w_cnt[i-1]+1 else: w_cnt[i]=w_cnt[i-1] s.reverse() s.pop(n) s.insert(0,"G") for i in range(1,n+1): if s[i]=="E": e_cnt[i]=e_cnt[i-1]+1 else: e_cnt[i]=e_cnt[i-1] ans=float("inf") for i in range(n): temp=w_cnt[i]+e_cnt[n-1-i] if temp<=ans: ans=temp print(ans)
14
24
326
470
n = int(eval(input())) s = list(eval(input())) cnt = s[1:].count("E") e_cnt = [0] * (n + 1) w_cnt = [0] * (n + 1) e_cnt[0] = cnt for i in range(n): w_cnt[i + 1] = w_cnt[i] + (s[i] == "W") # Wの数を累積和でとる for i in range(1, n): e_cnt[i] = e_cnt[i - 1] - (s[i] == "E") # Eの数を累積和でとる ans = float("inf") for i in range(n): ans = min(ans, w_cnt[i] + e_cnt[i]) print(ans)
n = int(eval(input())) s = list(eval(input())) w_cnt = [0] * (n + 1) e_cnt = [0] * (n + 1) s.insert(0, "G") for i in range(1, n + 1): if s[i] == "W": w_cnt[i] = w_cnt[i - 1] + 1 else: w_cnt[i] = w_cnt[i - 1] s.reverse() s.pop(n) s.insert(0, "G") for i in range(1, n + 1): if s[i] == "E": e_cnt[i] = e_cnt[i - 1] + 1 else: e_cnt[i] = e_cnt[i - 1] ans = float("inf") for i in range(n): temp = w_cnt[i] + e_cnt[n - 1 - i] if temp <= ans: ans = temp print(ans)
false
41.666667
[ "-cnt = s[1:].count(\"E\")", "+w_cnt = [0] * (n + 1)", "-w_cnt = [0] * (n + 1)", "-e_cnt[0] = cnt", "-for i in range(n):", "- w_cnt[i + 1] = w_cnt[i] + (s[i] == \"W\") # Wの数を累積和でとる", "-for i in range(1, n):", "- e_cnt[i] = e_cnt[i - 1] - (s[i] == \"E\") # Eの数を累積和でとる", "+s.insert(0, \"G\")", "+for i in range(1, n + 1):", "+ if s[i] == \"W\":", "+ w_cnt[i] = w_cnt[i - 1] + 1", "+ else:", "+ w_cnt[i] = w_cnt[i - 1]", "+s.reverse()", "+s.pop(n)", "+s.insert(0, \"G\")", "+for i in range(1, n + 1):", "+ if s[i] == \"E\":", "+ e_cnt[i] = e_cnt[i - 1] + 1", "+ else:", "+ e_cnt[i] = e_cnt[i - 1]", "- ans = min(ans, w_cnt[i] + e_cnt[i])", "+ temp = w_cnt[i] + e_cnt[n - 1 - i]", "+ if temp <= ans:", "+ ans = temp" ]
false
0.03779
0.03962
0.953807
[ "s732691661", "s249005774" ]
u989345508
p02720
python
s091215385
s236306768
415
174
33,640
23,388
Accepted
Accepted
58.07
k=int(eval(input())) ans=[[i for i in range(1,10)]] d=9 while d<k: ans.append([]) for i in ans[-2]: x=str(i) y=int(x[0]) if y==1: ans[-1].append(str(y)+x) ans[-1].append(str(y+1)+x) elif 2<=y<=8: ans[-1].append(str(y-1)+x) ans[-1].append(str(y)+x) ans[-1].append(str(y+1)+x) else: ans[-1].append(str(y-1)+x) ans[-1].append(str(y)+x) z=int(x[-1]) if z==0: ans[-1].append(x+str(z)) ans[-1].append(x+str(z+1)) elif 1<=z<=8: ans[-1].append(x+str(z-1)) ans[-1].append(x+str(z)) ans[-1].append(x+str(z+1)) else: ans[-1].append(x+str(z-1)) ans[-1].append(x+str(z)) ans[-1]=list(set(ans[-1])) d+=len(ans[-1]) l=len(ans[-1]) v=sorted([int(i) for i in ans[-1]]) print((v[k-(d-l)-1]))
k=int(eval(input())) ans=[[i for i in range(1,10)]] d=9 while d<k: ans.append([]) for i in ans[-2]: x=str(i) z=int(x[-1]) if z==0: ans[-1].append(x+str(z)) ans[-1].append(x+str(z+1)) elif 1<=z<=8: ans[-1].append(x+str(z-1)) ans[-1].append(x+str(z)) ans[-1].append(x+str(z+1)) else: ans[-1].append(x+str(z-1)) ans[-1].append(x+str(z)) d+=len(ans[-1]) l=len(ans[-1]) v=sorted([int(i) for i in ans[-1]]) print((v[k-(d-l)-1]))
35
23
956
573
k = int(eval(input())) ans = [[i for i in range(1, 10)]] d = 9 while d < k: ans.append([]) for i in ans[-2]: x = str(i) y = int(x[0]) if y == 1: ans[-1].append(str(y) + x) ans[-1].append(str(y + 1) + x) elif 2 <= y <= 8: ans[-1].append(str(y - 1) + x) ans[-1].append(str(y) + x) ans[-1].append(str(y + 1) + x) else: ans[-1].append(str(y - 1) + x) ans[-1].append(str(y) + x) z = int(x[-1]) if z == 0: ans[-1].append(x + str(z)) ans[-1].append(x + str(z + 1)) elif 1 <= z <= 8: ans[-1].append(x + str(z - 1)) ans[-1].append(x + str(z)) ans[-1].append(x + str(z + 1)) else: ans[-1].append(x + str(z - 1)) ans[-1].append(x + str(z)) ans[-1] = list(set(ans[-1])) d += len(ans[-1]) l = len(ans[-1]) v = sorted([int(i) for i in ans[-1]]) print((v[k - (d - l) - 1]))
k = int(eval(input())) ans = [[i for i in range(1, 10)]] d = 9 while d < k: ans.append([]) for i in ans[-2]: x = str(i) z = int(x[-1]) if z == 0: ans[-1].append(x + str(z)) ans[-1].append(x + str(z + 1)) elif 1 <= z <= 8: ans[-1].append(x + str(z - 1)) ans[-1].append(x + str(z)) ans[-1].append(x + str(z + 1)) else: ans[-1].append(x + str(z - 1)) ans[-1].append(x + str(z)) d += len(ans[-1]) l = len(ans[-1]) v = sorted([int(i) for i in ans[-1]]) print((v[k - (d - l) - 1]))
false
34.285714
[ "- y = int(x[0])", "- if y == 1:", "- ans[-1].append(str(y) + x)", "- ans[-1].append(str(y + 1) + x)", "- elif 2 <= y <= 8:", "- ans[-1].append(str(y - 1) + x)", "- ans[-1].append(str(y) + x)", "- ans[-1].append(str(y + 1) + x)", "- else:", "- ans[-1].append(str(y - 1) + x)", "- ans[-1].append(str(y) + x)", "- ans[-1] = list(set(ans[-1]))" ]
false
0.466594
0.269561
1.730943
[ "s091215385", "s236306768" ]
u271934630
p03998
python
s169843918
s083936237
198
21
38,256
3,316
Accepted
Accepted
89.39
A = list(eval(input())) B = list(eval(input())) C = list(eval(input())) card = A.pop(0) while True: if card == 'a': if A: card = A.pop(0) else: print('A') exit() elif card == 'b': if B: card = B.pop(0) else: print('B') exit() else: if C: card = C.pop(0) else: print('C') exit()
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) from collections import deque i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() a = deque(list(i_s())) b = deque(list(i_s())) c = deque(list(i_s())) x = a.popleft() while True: if a and x == 'a': x = a.popleft() elif not a and x == 'a': print('A') exit() elif b and x == 'b': x = b.popleft() elif not b and x == 'b': print('B') exit() elif c and x == 'c': x = c.popleft() elif not c and x == 'c': print('C') exit()
24
30
451
673
A = list(eval(input())) B = list(eval(input())) C = list(eval(input())) card = A.pop(0) while True: if card == "a": if A: card = A.pop(0) else: print("A") exit() elif card == "b": if B: card = B.pop(0) else: print("B") exit() else: if C: card = C.pop(0) else: print("C") exit()
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) from collections import deque i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() a = deque(list(i_s())) b = deque(list(i_s())) c = deque(list(i_s())) x = a.popleft() while True: if a and x == "a": x = a.popleft() elif not a and x == "a": print("A") exit() elif b and x == "b": x = b.popleft() elif not b and x == "b": print("B") exit() elif c and x == "c": x = c.popleft() elif not c and x == "c": print("C") exit()
false
20
[ "-A = list(eval(input()))", "-B = list(eval(input()))", "-C = list(eval(input()))", "-card = A.pop(0)", "+import sys", "+", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**7)", "+from collections import deque", "+", "+i_i = lambda: int(i_s())", "+i_l = lambda: list(map(int, stdin.readline().split()))", "+i_s = lambda: stdin.readline().rstrip()", "+a = deque(list(i_s()))", "+b = deque(list(i_s()))", "+c = deque(list(i_s()))", "+x = a.popleft()", "- if card == \"a\":", "- if A:", "- card = A.pop(0)", "- else:", "- print(\"A\")", "- exit()", "- elif card == \"b\":", "- if B:", "- card = B.pop(0)", "- else:", "- print(\"B\")", "- exit()", "- else:", "- if C:", "- card = C.pop(0)", "- else:", "- print(\"C\")", "- exit()", "+ if a and x == \"a\":", "+ x = a.popleft()", "+ elif not a and x == \"a\":", "+ print(\"A\")", "+ exit()", "+ elif b and x == \"b\":", "+ x = b.popleft()", "+ elif not b and x == \"b\":", "+ print(\"B\")", "+ exit()", "+ elif c and x == \"c\":", "+ x = c.popleft()", "+ elif not c and x == \"c\":", "+ print(\"C\")", "+ exit()" ]
false
0.035279
0.035869
0.983552
[ "s169843918", "s083936237" ]
u957167787
p02899
python
s341041572
s287508631
382
101
21,420
13,880
Accepted
Accepted
73.56
N = int(input()) A = list(map(int, input().split())) B = [] for i in range(1, N+1): B.append([A[i-1], i]) B.sort() for i in range(N): print(B[i][1] ,end=' ') print()
N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N # enumerate関数 # enumerate(イテラブル) # 前の変数には0, 1, 2, ...のように0から開始して1ずつ増える数が入る # 後ろの変数にはイテラブルの要素が入る # enumerate関数は(番号, イテラブルの要素)というtupleを作るので # それをアンパックして前の変数と後ろの変数に代入している for i, a in enumerate(A): ans[a-1] = i+1 # アスタリスクをつけると中身だけを出力できる # 細かい原理はよくわからん # listだけでなくtupleでもできる print((*ans))
11
18
185
372
N = int(input()) A = list(map(int, input().split())) B = [] for i in range(1, N + 1): B.append([A[i - 1], i]) B.sort() for i in range(N): print(B[i][1], end=" ") print()
N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N # enumerate関数 # enumerate(イテラブル) # 前の変数には0, 1, 2, ...のように0から開始して1ずつ増える数が入る # 後ろの変数にはイテラブルの要素が入る # enumerate関数は(番号, イテラブルの要素)というtupleを作るので # それをアンパックして前の変数と後ろの変数に代入している for i, a in enumerate(A): ans[a - 1] = i + 1 # アスタリスクをつけると中身だけを出力できる # 細かい原理はよくわからん # listだけでなくtupleでもできる print((*ans))
false
38.888889
[ "-N = int(input())", "+N = int(eval(input()))", "-B = []", "-for i in range(1, N + 1):", "- B.append([A[i - 1], i])", "-B.sort()", "-for i in range(N):", "- print(B[i][1], end=\" \")", "-print()", "+ans = [0] * N", "+# enumerate関数", "+# enumerate(イテラブル)", "+# 前の変数には0, 1, 2, ...のように0から開始して1ずつ増える数が入る", "+# 後ろの変数にはイテラブルの要素が入る", "+# enumerate関数は(番号, イテラブルの要素)というtupleを作るので", "+# それをアンパックして前の変数と後ろの変数に代入している", "+for i, a in enumerate(A):", "+ ans[a - 1] = i + 1", "+# アスタリスクをつけると中身だけを出力できる", "+# 細かい原理はよくわからん", "+# listだけでなくtupleでもできる", "+print((*ans))" ]
false
0.054844
0.03687
1.487502
[ "s341041572", "s287508631" ]
u057109575
p02733
python
s073607656
s898746276
1,242
524
44,764
75,524
Accepted
Accepted
57.81
H, W, K = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] ans = 10 ** 5 for bit in range(2 ** (H - 1)): group = [0] * H gnum = 0 # Group each row for i in range(H - 1): if not bit >> i & 1: group[i + 1] = group[i] else: group[i + 1] = group[i] + 1 gnum += 1 gok = True add = 0 # Vertical split num nums = [0] * (gnum + 1) # Number of '1' in previous blocks # For each column for j in range(W): ones = [0] * (gnum + 1) ok = True # For each row for i in range(H): ones[group[i]] += int(S[i][j]) nums[group[i]] += int(S[i][j]) if ones[group[i]] > K: gok = False; if nums[group[i]] > K: ok = False; if not ok: add += 1 nums = ones[:] if gok: ans = min(ans, gnum + add) print(ans)
H, W, K = list(map(int, input().split())) X = [list(eval(input())) for _ in range(H)] MOD = 10 ** 9 + 7 ans = MOD for bit in range(2 ** (H - 1)): n = bin(bit).count("1") ctr = [0] * (n + 1) # Accumulation res = 0 for j in range(W): k = 0 tmp = [0] * (n + 1) # One column for i in range(H): tmp[k] += int(X[i][j]) if bit >> i & 1: k += 1 # Check counts if any(v > K for v in tmp): res = MOD break elif any(u + v > K for u, v in zip(ctr, tmp)): # Split res += 1 ctr = tmp[:] else: # Accumulate for i in range(n + 1): ctr[i] += tmp[i] ans = min(ans, res + n) print(ans)
39
34
981
811
H, W, K = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] ans = 10**5 for bit in range(2 ** (H - 1)): group = [0] * H gnum = 0 # Group each row for i in range(H - 1): if not bit >> i & 1: group[i + 1] = group[i] else: group[i + 1] = group[i] + 1 gnum += 1 gok = True add = 0 # Vertical split num nums = [0] * (gnum + 1) # Number of '1' in previous blocks # For each column for j in range(W): ones = [0] * (gnum + 1) ok = True # For each row for i in range(H): ones[group[i]] += int(S[i][j]) nums[group[i]] += int(S[i][j]) if ones[group[i]] > K: gok = False if nums[group[i]] > K: ok = False if not ok: add += 1 nums = ones[:] if gok: ans = min(ans, gnum + add) print(ans)
H, W, K = list(map(int, input().split())) X = [list(eval(input())) for _ in range(H)] MOD = 10**9 + 7 ans = MOD for bit in range(2 ** (H - 1)): n = bin(bit).count("1") ctr = [0] * (n + 1) # Accumulation res = 0 for j in range(W): k = 0 tmp = [0] * (n + 1) # One column for i in range(H): tmp[k] += int(X[i][j]) if bit >> i & 1: k += 1 # Check counts if any(v > K for v in tmp): res = MOD break elif any(u + v > K for u, v in zip(ctr, tmp)): # Split res += 1 ctr = tmp[:] else: # Accumulate for i in range(n + 1): ctr[i] += tmp[i] ans = min(ans, res + n) print(ans)
false
12.820513
[ "-S = [eval(input()) for _ in range(H)]", "-ans = 10**5", "+X = [list(eval(input())) for _ in range(H)]", "+MOD = 10**9 + 7", "+ans = MOD", "- group = [0] * H", "- gnum = 0", "- # Group each row", "- for i in range(H - 1):", "- if not bit >> i & 1:", "- group[i + 1] = group[i]", "+ n = bin(bit).count(\"1\")", "+ ctr = [0] * (n + 1) # Accumulation", "+ res = 0", "+ for j in range(W):", "+ k = 0", "+ tmp = [0] * (n + 1) # One column", "+ for i in range(H):", "+ tmp[k] += int(X[i][j])", "+ if bit >> i & 1:", "+ k += 1", "+ # Check counts", "+ if any(v > K for v in tmp):", "+ res = MOD", "+ break", "+ elif any(u + v > K for u, v in zip(ctr, tmp)):", "+ # Split", "+ res += 1", "+ ctr = tmp[:]", "- group[i + 1] = group[i] + 1", "- gnum += 1", "- gok = True", "- add = 0 # Vertical split num", "- nums = [0] * (gnum + 1) # Number of '1' in previous blocks", "- # For each column", "- for j in range(W):", "- ones = [0] * (gnum + 1)", "- ok = True", "- # For each row", "- for i in range(H):", "- ones[group[i]] += int(S[i][j])", "- nums[group[i]] += int(S[i][j])", "- if ones[group[i]] > K:", "- gok = False", "- if nums[group[i]] > K:", "- ok = False", "- if not ok:", "- add += 1", "- nums = ones[:]", "- if gok:", "- ans = min(ans, gnum + add)", "+ # Accumulate", "+ for i in range(n + 1):", "+ ctr[i] += tmp[i]", "+ ans = min(ans, res + n)" ]
false
0.042385
0.042452
0.998408
[ "s073607656", "s898746276" ]
u729133443
p03987
python
s545888976
s791410263
177
125
33,392
22,192
Accepted
Accepted
29.38
code = r""" # distutils: language=c++ from libcpp.set cimport set from libcpp.vector cimport vector from cython.operator cimport dereference as deref, predecrement as dec cdef int n = int(input()), i cdef long c cdef vector[long] a = [*map(int, input().split())] cdef vector[long] l = [0] * n for i in range(n): l[a[i] - 1] = i cdef set[long] s = set[long]([-1, n]) cdef set[long].iterator it for i in range(n): it = s.lower_bound(l[i]) c += (deref(it) - l[i]) * (l[i] - deref(dec(it))) * (i + 1) s.insert(l[i]) print(c) """ import os, sys if sys.argv[-1] == 'ONLINE_JUDGE': open('solve.pyx', 'w').write(code) os.system('cythonize -i -3 -b solve.pyx') import solve
import sys if sys.argv[-1] == 'ONLINE_JUDGE': import os, zlib, base64 open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${rg?P`QD5d7~`ER<5McXC316zM&QJxYwLw=|bXvi9iPcVn!*mIj3E%<Q-yxr3ep&rBvXV3ZwaHR4g1Wj1(s0YjahrYazVrpx3!gWP{{AE?>+jZWc@q6*xT+vpKlpOxRi<jL}obo!Ie&Q@+huWr41^f<_8HG&E$jG5S@_IN?d3D%kJaR4!tRGSxI-AJa%K+eW=JJ4{1!-8JVWDx2kiKi24txfXx@btV<Gzj|whXy*2>V3nbn}$cI4^Tq4z#e(_7H;aXQ50+10VUKpJANzDu-XWnK#BAg$Ze4gG7S<V@Uj{dqyg2Y9`{h6Bx7}zt*kadz%9z#eZ2#FD*mV{;&s-<|NLZWhB!J^#$D0Bb#AtOu38eS)O>k_eA!4&9IIJ48OI`$IB~L^$QKJkGN?M`hl*@K&#Ps64f(^p>0j-GY^un<0PhaYas"))) os.system('cythonize -i -3 -b solve.pyx') import solve
23
6
706
642
code = r""" # distutils: language=c++ from libcpp.set cimport set from libcpp.vector cimport vector from cython.operator cimport dereference as deref, predecrement as dec cdef int n = int(input()), i cdef long c cdef vector[long] a = [*map(int, input().split())] cdef vector[long] l = [0] * n for i in range(n): l[a[i] - 1] = i cdef set[long] s = set[long]([-1, n]) cdef set[long].iterator it for i in range(n): it = s.lower_bound(l[i]) c += (deref(it) - l[i]) * (l[i] - deref(dec(it))) * (i + 1) s.insert(l[i]) print(c) """ import os, sys if sys.argv[-1] == "ONLINE_JUDGE": open("solve.pyx", "w").write(code) os.system("cythonize -i -3 -b solve.pyx") import solve
import sys if sys.argv[-1] == "ONLINE_JUDGE": import os, zlib, base64 open("solve.pyx", "wb").write( zlib.decompress( base64.b85decode( "c${rg?P`QD5d7~`ER<5McXC316zM&QJxYwLw=|bXvi9iPcVn!*mIj3E%<Q-yxr3ep&rBvXV3ZwaHR4g1Wj1(s0YjahrYazVrpx3!gWP{{AE?>+jZWc@q6*xT+vpKlpOxRi<jL}obo!Ie&Q@+huWr41^f<_8HG&E$jG5S@_IN?d3D%kJaR4!tRGSxI-AJa%K+eW=JJ4{1!-8JVWDx2kiKi24txfXx@btV<Gzj|whXy*2>V3nbn}$cI4^Tq4z#e(_7H;aXQ50+10VUKpJANzDu-XWnK#BAg$Ze4gG7S<V@Uj{dqyg2Y9`{h6Bx7}zt*kadz%9z#eZ2#FD*mV{;&s-<|NLZWhB!J^#$D0Bb#AtOu38eS)O>k_eA!4&9IIJ48OI`$IB~L^$QKJkGN?M`hl*@K&#Ps64f(^p>0j-GY^un<0PhaYas" ) ) ) os.system("cythonize -i -3 -b solve.pyx") import solve
false
73.913043
[ "-code = r\"\"\"", "-# distutils: language=c++", "-from libcpp.set cimport set", "-from libcpp.vector cimport vector", "-from cython.operator cimport dereference as deref, predecrement as dec", "-cdef int n = int(input()), i", "-cdef long c", "-cdef vector[long] a = [*map(int, input().split())]", "-cdef vector[long] l = [0] * n", "-for i in range(n): l[a[i] - 1] = i", "-cdef set[long] s = set[long]([-1, n])", "-cdef set[long].iterator it", "-for i in range(n):", "- it = s.lower_bound(l[i])", "- c += (deref(it) - l[i]) * (l[i] - deref(dec(it))) * (i + 1)", "- s.insert(l[i])", "-print(c)", "-\"\"\"", "-import os, sys", "+import sys", "- open(\"solve.pyx\", \"w\").write(code)", "+ import os, zlib, base64", "+", "+ open(\"solve.pyx\", \"wb\").write(", "+ zlib.decompress(", "+ base64.b85decode(", "+ \"c${rg?P`QD5d7~`ER<5McXC316zM&QJxYwLw=|bXvi9iPcVn!*mIj3E%<Q-yxr3ep&rBvXV3ZwaHR4g1Wj1(s0YjahrYazVrpx3!gWP{{AE?>+jZWc@q6*xT+vpKlpOxRi<jL}obo!Ie&Q@+huWr41^f<_8HG&E$jG5S@_IN?d3D%kJaR4!tRGSxI-AJa%K+eW=JJ4{1!-8JVWDx2kiKi24txfXx@btV<Gzj|whXy*2>V3nbn}$cI4^Tq4z#e(_7H;aXQ50+10VUKpJANzDu-XWnK#BAg$Ze4gG7S<V@Uj{dqyg2Y9`{h6Bx7}zt*kadz%9z#eZ2#FD*mV{;&s-<|NLZWhB!J^#$D0Bb#AtOu38eS)O>k_eA!4&9IIJ48OI`$IB~L^$QKJkGN?M`hl*@K&#Ps64f(^p>0j-GY^un<0PhaYas\"", "+ )", "+ )", "+ )" ]
false
0.03811
0.055982
0.680747
[ "s545888976", "s791410263" ]
u832039789
p02847
python
s691237343
s125248911
19
17
2,940
2,940
Accepted
Accepted
10.53
print(("SATFRITHUWEDTUEMONSUN".index(eval(input()))//3+1))
s = eval(input()) l = ["SUN","MON","TUE","WED","THU","FRI","SAT","SUN"] print((7 - l.index(s)))
1
3
50
90
print(("SATFRITHUWEDTUEMONSUN".index(eval(input())) // 3 + 1))
s = eval(input()) l = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"] print((7 - l.index(s)))
false
66.666667
[ "-print((\"SATFRITHUWEDTUEMONSUN\".index(eval(input())) // 3 + 1))", "+s = eval(input())", "+l = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\", \"SUN\"]", "+print((7 - l.index(s)))" ]
false
0.052995
0.086794
0.610585
[ "s691237343", "s125248911" ]
u045830275
p02257
python
s869603713
s769043018
840
70
8,196
8,184
Accepted
Accepted
91.67
import math def isPrime(x) : if x == 2 : return True if x < 2 or x % 2 == 0 : return False i = 3 while i <= math.sqrt(x) : if x % i == 0 : return False i += 2 return True def main() : n = int(eval(input())) nums = [] for i in range(n) : x = int(eval(input())) nums.append(x) count = 0 for num in nums : if isPrime(num) : count += 1 print(count) if __name__ == '__main__' : main()
def is_prime(x) : if x == 2 : return True if x < 2 or x % 2 == 0 : return False return pow(2, x-1, x) == 1 def main() : n = int(eval(input())) nums = [] for _ in range(n) : x = int(eval(input())) nums.append(x) count = 0 for num in nums : if is_prime(num) : count += 1 print(count) if __name__ == '__main__' : main()
35
24
539
424
import math def isPrime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False i = 3 while i <= math.sqrt(x): if x % i == 0: return False i += 2 return True def main(): n = int(eval(input())) nums = [] for i in range(n): x = int(eval(input())) nums.append(x) count = 0 for num in nums: if isPrime(num): count += 1 print(count) if __name__ == "__main__": main()
def is_prime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False return pow(2, x - 1, x) == 1 def main(): n = int(eval(input())) nums = [] for _ in range(n): x = int(eval(input())) nums.append(x) count = 0 for num in nums: if is_prime(num): count += 1 print(count) if __name__ == "__main__": main()
false
31.428571
[ "-import math", "-", "-", "-def isPrime(x):", "+def is_prime(x):", "- i = 3", "- while i <= math.sqrt(x):", "- if x % i == 0:", "- return False", "- i += 2", "- return True", "+ return pow(2, x - 1, x) == 1", "- for i in range(n):", "+ for _ in range(n):", "- if isPrime(num):", "+ if is_prime(num):" ]
false
0.060072
0.040208
1.494027
[ "s869603713", "s769043018" ]
u225388820
p03659
python
s800678855
s482032701
203
162
24,832
24,800
Accepted
Accepted
20.2
n=int(eval(input())) a=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1] ABS=10**15 for i in range(n-1): ABS=min(abs(a[-1]-2*a[i]),ABS) print(ABS)
n=int(eval(input())) a=list(map(int,input().split())) s=sum(a) now=0 ans=10**14 for i in a[:n-1]: now+=i ans=min(abs(2*now-s),ans) print(ans)
8
9
170
151
n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i - 1] ABS = 10**15 for i in range(n - 1): ABS = min(abs(a[-1] - 2 * a[i]), ABS) print(ABS)
n = int(eval(input())) a = list(map(int, input().split())) s = sum(a) now = 0 ans = 10**14 for i in a[: n - 1]: now += i ans = min(abs(2 * now - s), ans) print(ans)
false
11.111111
[ "-for i in range(1, n):", "- a[i] += a[i - 1]", "-ABS = 10**15", "-for i in range(n - 1):", "- ABS = min(abs(a[-1] - 2 * a[i]), ABS)", "-print(ABS)", "+s = sum(a)", "+now = 0", "+ans = 10**14", "+for i in a[: n - 1]:", "+ now += i", "+ ans = min(abs(2 * now - s), ans)", "+print(ans)" ]
false
0.04162
0.043331
0.960511
[ "s800678855", "s482032701" ]
u433375322
p02582
python
s399134722
s520938477
34
28
8,984
9,052
Accepted
Accepted
17.65
a=list(eval(input())) if a[0]=="R": if a[1]=="S": print((1)) else: if a[2]=="R": print((3)) else: print((2)) else: if a[1]=="R" and a[2]=="R": print((2)) elif a[1]=="S" and a[2]=="S": print((0)) else: print((1))
s=list(eval(input())) c=0 l=[] for i in range(3): if s[i]=="R": c+=1 else: c=0 l.append(c) print((max(l)))
16
11
254
145
a = list(eval(input())) if a[0] == "R": if a[1] == "S": print((1)) else: if a[2] == "R": print((3)) else: print((2)) else: if a[1] == "R" and a[2] == "R": print((2)) elif a[1] == "S" and a[2] == "S": print((0)) else: print((1))
s = list(eval(input())) c = 0 l = [] for i in range(3): if s[i] == "R": c += 1 else: c = 0 l.append(c) print((max(l)))
false
31.25
[ "-a = list(eval(input()))", "-if a[0] == \"R\":", "- if a[1] == \"S\":", "- print((1))", "+s = list(eval(input()))", "+c = 0", "+l = []", "+for i in range(3):", "+ if s[i] == \"R\":", "+ c += 1", "- if a[2] == \"R\":", "- print((3))", "- else:", "- print((2))", "-else:", "- if a[1] == \"R\" and a[2] == \"R\":", "- print((2))", "- elif a[1] == \"S\" and a[2] == \"S\":", "- print((0))", "- else:", "- print((1))", "+ c = 0", "+ l.append(c)", "+print((max(l)))" ]
false
0.039564
0.064702
0.61149
[ "s399134722", "s520938477" ]
u952467214
p03164
python
s379939222
s787658246
959
383
308,168
119,788
Accepted
Accepted
60.06
N, W = [int(i) for i in input().split()] w, v = [0]*N, [0]*N for i in range(N): w[i], v[i] = [int(_) for _ in input().split()] V = sum(v) dp = [[float('inf')] * (V+1) for _ in range(N+1)] # dp[i][j] i番目までの荷物で価値がj以上になるように選んだときの重さの最小値 dp[0][0] = 0 for i in range(N): for j in range(V+1): if v[i] <= j:# 荷物v[i]の価値がjに足りてないのでi番目の荷物を入れる可能性がある dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]) else: dp[i+1][j] = dp[i][j] ans = 0 for j in range(V + 1): if dp[N][j] <= W: ans = j print(ans)
N, W = list(map(int, input().split())) w, v = [0]*(N+1),[0]*(N+1) for i in range(N): w[i+1], v[i+1] = [int(_) for _ in input().split()] V = sum(v) dp = [[10**12]*(V+1) for _ in range(N+1)] dp[0][0] = 0 # dp[i][j]:i番目以前の商品を見たときの価値総和jとしたときの重さの最小値 ans = 0 for i in range(1,N+1): for j in range(V+1): # なんか間違えて1スタートにしててハマった if v[i] <= j: #v[i]が入るとjになるときの計算なので,v[i]がjよりでかいのはあり得ない。j-v[i]>0だしね。 # i-1番目までの商品で価値jの場合とi番目の商品を入れて価値jの場合の比較 dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]) else: dp[i][j] = dp[i-1][j] for j in range(V+1): if dp[N][j] <= W: ans = max(ans, j) print(ans)
23
25
557
669
N, W = [int(i) for i in input().split()] w, v = [0] * N, [0] * N for i in range(N): w[i], v[i] = [int(_) for _ in input().split()] V = sum(v) dp = [[float("inf")] * (V + 1) for _ in range(N + 1)] # dp[i][j] i番目までの荷物で価値がj以上になるように選んだときの重さの最小値 dp[0][0] = 0 for i in range(N): for j in range(V + 1): if v[i] <= j: # 荷物v[i]の価値がjに足りてないのでi番目の荷物を入れる可能性がある dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]) else: dp[i + 1][j] = dp[i][j] ans = 0 for j in range(V + 1): if dp[N][j] <= W: ans = j print(ans)
N, W = list(map(int, input().split())) w, v = [0] * (N + 1), [0] * (N + 1) for i in range(N): w[i + 1], v[i + 1] = [int(_) for _ in input().split()] V = sum(v) dp = [[10**12] * (V + 1) for _ in range(N + 1)] dp[0][0] = 0 # dp[i][j]:i番目以前の商品を見たときの価値総和jとしたときの重さの最小値 ans = 0 for i in range(1, N + 1): for j in range(V + 1): # なんか間違えて1スタートにしててハマった if v[i] <= j: # v[i]が入るとjになるときの計算なので,v[i]がjよりでかいのはあり得ない。j-v[i]>0だしね。 # i-1番目までの商品で価値jの場合とi番目の商品を入れて価値jの場合の比較 dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]) else: dp[i][j] = dp[i - 1][j] for j in range(V + 1): if dp[N][j] <= W: ans = max(ans, j) print(ans)
false
8
[ "-N, W = [int(i) for i in input().split()]", "-w, v = [0] * N, [0] * N", "+N, W = list(map(int, input().split()))", "+w, v = [0] * (N + 1), [0] * (N + 1)", "- w[i], v[i] = [int(_) for _ in input().split()]", "+ w[i + 1], v[i + 1] = [int(_) for _ in input().split()]", "-dp = [[float(\"inf\")] * (V + 1) for _ in range(N + 1)]", "-# dp[i][j] i番目までの荷物で価値がj以上になるように選んだときの重さの最小値", "+dp = [[10**12] * (V + 1) for _ in range(N + 1)]", "-for i in range(N):", "- for j in range(V + 1):", "- if v[i] <= j: # 荷物v[i]の価値がjに足りてないのでi番目の荷物を入れる可能性がある", "- dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])", "+# dp[i][j]:i番目以前の商品を見たときの価値総和jとしたときの重さの最小値", "+ans = 0", "+for i in range(1, N + 1):", "+ for j in range(V + 1): # なんか間違えて1スタートにしててハマった", "+ if v[i] <= j: # v[i]が入るとjになるときの計算なので,v[i]がjよりでかいのはあり得ない。j-v[i]>0だしね。", "+ # i-1番目までの商品で価値jの場合とi番目の商品を入れて価値jの場合の比較", "+ dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i])", "- dp[i + 1][j] = dp[i][j]", "-ans = 0", "+ dp[i][j] = dp[i - 1][j]", "- ans = j", "+ ans = max(ans, j)" ]
false
0.045473
0.046688
0.973982
[ "s379939222", "s787658246" ]
u345966487
p03724
python
s567180571
s832128170
633
252
51,672
82,800
Accepted
Accepted
60.19
from collections import Counter N, M = list(map(int, input().split())) counter = Counter() for i in range(M): a, b = list(map(int, input().split())) counter[a] += 1 counter[b] += 1 if all(x % 2 == 0 for x in list(counter.values())): print("YES") else: print("NO")
n,m,*p=list(map(int,open(0).read().split()));c=[0]*n for x in p:c[x-1]+=1 print(("YNEOS"[any(x%2for x in c)::2]))
13
3
280
107
from collections import Counter N, M = list(map(int, input().split())) counter = Counter() for i in range(M): a, b = list(map(int, input().split())) counter[a] += 1 counter[b] += 1 if all(x % 2 == 0 for x in list(counter.values())): print("YES") else: print("NO")
n, m, *p = list(map(int, open(0).read().split())) c = [0] * n for x in p: c[x - 1] += 1 print(("YNEOS"[any(x % 2 for x in c) :: 2]))
false
76.923077
[ "-from collections import Counter", "-", "-N, M = list(map(int, input().split()))", "-counter = Counter()", "-for i in range(M):", "- a, b = list(map(int, input().split()))", "- counter[a] += 1", "- counter[b] += 1", "-if all(x % 2 == 0 for x in list(counter.values())):", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+n, m, *p = list(map(int, open(0).read().split()))", "+c = [0] * n", "+for x in p:", "+ c[x - 1] += 1", "+print((\"YNEOS\"[any(x % 2 for x in c) :: 2]))" ]
false
0.036025
0.035394
1.017835
[ "s567180571", "s832128170" ]
u738622346
p03361
python
s057928861
s421511816
28
25
3,064
3,064
Accepted
Accepted
10.71
h, w = list(map(int, input().split(" "))) s = [] for row in range(h): line = eval(input()) tmp = [] for column in range(w): tmp.append(line[column]) s.append(tmp) sx = [-1, 0, 0, 1] sy = [0, 1, -1, 0] res = True for row in range(h): for column in range(w): if s[row][column] == "#": count = 0 for i in range(len(sx)): if row + sx[i] < 0 or len(s) <= row + sx[i]: continue if column + sy[i] < 0 or len(s[row]) <= column + sy[i]: continue if s[row + sx[i]][column + sy[i]] == "#": count += 1 if count == 0: res = False print(("Yes" if res == True else "No"))
h, w = list(map(int, input().split(" "))) s = [] for row in range(h): line = eval(input()) tmp = [] for column in range(w): tmp.append(line[column]) s.append(tmp) sx = [-1, 0, 0, 1] sy = [0, 1, -1, 0] res = True for row in range(h): for column in range(w): if s[row][column] == "#": count = 0 for i in range(len(sx)): row_target = row + sx[i] column_target = column + sy[i] if row_target < 0 or len(s) <= row_target: continue if column_target < 0 or len(s[row]) <= column_target: continue if s[row_target][column_target] == "#": count += 1 if count == 0: res = False print(("Yes" if res == True else "No"))
28
31
769
855
h, w = list(map(int, input().split(" "))) s = [] for row in range(h): line = eval(input()) tmp = [] for column in range(w): tmp.append(line[column]) s.append(tmp) sx = [-1, 0, 0, 1] sy = [0, 1, -1, 0] res = True for row in range(h): for column in range(w): if s[row][column] == "#": count = 0 for i in range(len(sx)): if row + sx[i] < 0 or len(s) <= row + sx[i]: continue if column + sy[i] < 0 or len(s[row]) <= column + sy[i]: continue if s[row + sx[i]][column + sy[i]] == "#": count += 1 if count == 0: res = False print(("Yes" if res == True else "No"))
h, w = list(map(int, input().split(" "))) s = [] for row in range(h): line = eval(input()) tmp = [] for column in range(w): tmp.append(line[column]) s.append(tmp) sx = [-1, 0, 0, 1] sy = [0, 1, -1, 0] res = True for row in range(h): for column in range(w): if s[row][column] == "#": count = 0 for i in range(len(sx)): row_target = row + sx[i] column_target = column + sy[i] if row_target < 0 or len(s) <= row_target: continue if column_target < 0 or len(s[row]) <= column_target: continue if s[row_target][column_target] == "#": count += 1 if count == 0: res = False print(("Yes" if res == True else "No"))
false
9.677419
[ "- if row + sx[i] < 0 or len(s) <= row + sx[i]:", "+ row_target = row + sx[i]", "+ column_target = column + sy[i]", "+ if row_target < 0 or len(s) <= row_target:", "- if column + sy[i] < 0 or len(s[row]) <= column + sy[i]:", "+ if column_target < 0 or len(s[row]) <= column_target:", "- if s[row + sx[i]][column + sy[i]] == \"#\":", "+ if s[row_target][column_target] == \"#\":" ]
false
0.08043
0.043984
1.828604
[ "s057928861", "s421511816" ]
u852690916
p03013
python
s501793787
s324497975
489
246
50,008
57,180
Accepted
Accepted
49.69
N,M=list(map(int,input().split())) a=[int(eval(input())) for _ in range(M)] MOD=10**9+7 dp=[0]*(N+1) dp[0]=1 dp[1]=1 for i in a: dp[i]=-1 for i in range(2,N+1): if dp[i]==-1: continue if dp[i-1]!=-1: dp[i] = (dp[i]+dp[i-1])%MOD if dp[i-2]!=-1: dp[i] = (dp[i]+dp[i-2])%MOD print((dp[N]))
import sys def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] + [-1] dp = [Mint() for _ in range(N+1)] dp[0] = Mint(1) j = 0 for i in range(1,N+1): if i == A[j]: j += 1 continue dp[i] += dp[i-1] if i >= 2: dp[i] += dp[i-2] print((dp[N])) class Mint: def __init__(self, value=0, mod=10**9+7): self.value = ((value % mod) + mod) % mod self.mod = mod @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, self.mod u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v return (u + self.mod) % self.mod def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value, self.mod) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % self.mod return self def __add__(self, other): new_obj = Mint(self.value, self.mod) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod return self def __sub__(self, other): new_obj = Mint(self.value, self.mod) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % self.mod return self def __mul__(self, other): new_obj = Mint(self.value, self.mod) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other, self.mod) self *= other.inverse return self def __floordiv__(self, other): new_obj = Mint(self.value, self.mod) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj //= self return new_obj if __name__ == '__main__': main()
18
85
332
2,555
N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] MOD = 10**9 + 7 dp = [0] * (N + 1) dp[0] = 1 dp[1] = 1 for i in a: dp[i] = -1 for i in range(2, N + 1): if dp[i] == -1: continue if dp[i - 1] != -1: dp[i] = (dp[i] + dp[i - 1]) % MOD if dp[i - 2] != -1: dp[i] = (dp[i] + dp[i - 2]) % MOD print((dp[N]))
import sys def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] + [-1] dp = [Mint() for _ in range(N + 1)] dp[0] = Mint(1) j = 0 for i in range(1, N + 1): if i == A[j]: j += 1 continue dp[i] += dp[i - 1] if i >= 2: dp[i] += dp[i - 2] print((dp[N])) class Mint: def __init__(self, value=0, mod=10**9 + 7): self.value = ((value % mod) + mod) % mod self.mod = mod @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, self.mod u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v return (u + self.mod) % self.mod def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value, self.mod) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % self.mod return self def __add__(self, other): new_obj = Mint(self.value, self.mod) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod return self def __sub__(self, other): new_obj = Mint(self.value, self.mod) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % self.mod return self def __mul__(self, other): new_obj = Mint(self.value, self.mod) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other, self.mod) self *= other.inverse return self def __floordiv__(self, other): new_obj = Mint(self.value, self.mod) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj //= self return new_obj if __name__ == "__main__": main()
false
78.823529
[ "-N, M = list(map(int, input().split()))", "-a = [int(eval(input())) for _ in range(M)]", "-MOD = 10**9 + 7", "-dp = [0] * (N + 1)", "-dp[0] = 1", "-dp[1] = 1", "-for i in a:", "- dp[i] = -1", "-for i in range(2, N + 1):", "- if dp[i] == -1:", "- continue", "- if dp[i - 1] != -1:", "- dp[i] = (dp[i] + dp[i - 1]) % MOD", "- if dp[i - 2] != -1:", "- dp[i] = (dp[i] + dp[i - 2]) % MOD", "-print((dp[N]))", "+import sys", "+", "+", "+def main():", "+ input = sys.stdin.readline", "+ N, M = list(map(int, input().split()))", "+ A = [int(eval(input())) for _ in range(M)] + [-1]", "+ dp = [Mint() for _ in range(N + 1)]", "+ dp[0] = Mint(1)", "+ j = 0", "+ for i in range(1, N + 1):", "+ if i == A[j]:", "+ j += 1", "+ continue", "+ dp[i] += dp[i - 1]", "+ if i >= 2:", "+ dp[i] += dp[i - 2]", "+ print((dp[N]))", "+", "+", "+class Mint:", "+ def __init__(self, value=0, mod=10**9 + 7):", "+ self.value = ((value % mod) + mod) % mod", "+ self.mod = mod", "+", "+ @staticmethod", "+ def get_value(x):", "+ return x.value if isinstance(x, Mint) else x", "+", "+ def inverse(self):", "+ a, b = self.value, self.mod", "+ u, v = 1, 0", "+ while b:", "+ t = a // b", "+ b, a = a - t * b, b", "+ v, u = u - t * v, v", "+ return (u + self.mod) % self.mod", "+", "+ def __repr__(self):", "+ return str(self.value)", "+", "+ def __eq__(self, other):", "+ return self.value == other.value", "+", "+ def __neg__(self):", "+ return Mint(-self.value, self.mod)", "+", "+ def __hash__(self):", "+ return hash(self.value)", "+", "+ def __bool__(self):", "+ return self.value != 0", "+", "+ def __iadd__(self, other):", "+ self.value = (self.value + Mint.get_value(other)) % self.mod", "+ return self", "+", "+ def __add__(self, other):", "+ new_obj = Mint(self.value, self.mod)", "+ new_obj += other", "+ return new_obj", "+", "+ __radd__ = __add__", "+", "+ def __isub__(self, other):", "+ self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod", "+ return self", "+", "+ def __sub__(self, other):", "+ new_obj = Mint(self.value, self.mod)", "+ new_obj -= other", "+ return new_obj", "+", "+ def __rsub__(self, other):", "+ new_obj = Mint(Mint.get_value(other), self.mod)", "+ new_obj -= self", "+ return new_obj", "+", "+ def __imul__(self, other):", "+ self.value = self.value * Mint.get_value(other) % self.mod", "+ return self", "+", "+ def __mul__(self, other):", "+ new_obj = Mint(self.value, self.mod)", "+ new_obj *= other", "+ return new_obj", "+", "+ __rmul__ = __mul__", "+", "+ def __ifloordiv__(self, other):", "+ other = other if isinstance(other, Mint) else Mint(other, self.mod)", "+ self *= other.inverse", "+ return self", "+", "+ def __floordiv__(self, other):", "+ new_obj = Mint(self.value, self.mod)", "+ new_obj //= other", "+ return new_obj", "+", "+ def __rfloordiv__(self, other):", "+ new_obj = Mint(Mint.get_value(other), self.mod)", "+ new_obj //= self", "+ return new_obj", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.068818
0.035162
1.957199
[ "s501793787", "s324497975" ]
u670567845
p03331
python
s070183021
s357649648
146
132
9,048
74,240
Accepted
Accepted
9.59
N = int(eval(input())) ans = float('inf') for i in range(N//2): A = i+1 B = N-A ans = min(ans, sum(list(map(int,str(A)))) + sum(list(map(int,str(B))) )) print(ans)
N = int(eval(input())) ans = 10**9+7 for i in range(1,N): A = i B = N-i ans = min(ans, sum(list(map(int,str(A))))+sum(list(map(int,str(B))))) print(ans)
8
7
171
158
N = int(eval(input())) ans = float("inf") for i in range(N // 2): A = i + 1 B = N - A ans = min(ans, sum(list(map(int, str(A)))) + sum(list(map(int, str(B))))) print(ans)
N = int(eval(input())) ans = 10**9 + 7 for i in range(1, N): A = i B = N - i ans = min(ans, sum(list(map(int, str(A)))) + sum(list(map(int, str(B))))) print(ans)
false
12.5
[ "-ans = float(\"inf\")", "-for i in range(N // 2):", "- A = i + 1", "- B = N - A", "+ans = 10**9 + 7", "+for i in range(1, N):", "+ A = i", "+ B = N - i" ]
false
0.250604
0.100811
2.485884
[ "s070183021", "s357649648" ]
u392319141
p02814
python
s083058620
s198355055
511
158
63,984
14,244
Accepted
Accepted
69.08
N, M = list(map(int, input().split())) A = list(set(map(int, input().split()))) def gcd(m, n): if n == 0: return m return gcd(n, m % n) LCM = A[0] for a in A: LCM = LCM * a // gcd(LCM, a) K = max(A) for X in range(K // 2, M + 1, K): for a in A: if (X - a // 2) % a != 0: break else: print(((M - X) // LCM + 1)) exit() print((0))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = set([a & (-a) for a in A]) if len(B) > 1: print((0)) exit() def gcd(n, m): if m == 0: return n return gcd(m, n % m) def lcm(x, y): return x * y // gcd(x, y) A = [a // 2 for a in A] LCM = A[0] for a in A: LCM = lcm(LCM, a) ans = ((M // LCM) + 1) // 2 print(ans)
21
23
406
391
N, M = list(map(int, input().split())) A = list(set(map(int, input().split()))) def gcd(m, n): if n == 0: return m return gcd(n, m % n) LCM = A[0] for a in A: LCM = LCM * a // gcd(LCM, a) K = max(A) for X in range(K // 2, M + 1, K): for a in A: if (X - a // 2) % a != 0: break else: print(((M - X) // LCM + 1)) exit() print((0))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = set([a & (-a) for a in A]) if len(B) > 1: print((0)) exit() def gcd(n, m): if m == 0: return n return gcd(m, n % m) def lcm(x, y): return x * y // gcd(x, y) A = [a // 2 for a in A] LCM = A[0] for a in A: LCM = lcm(LCM, a) ans = ((M // LCM) + 1) // 2 print(ans)
false
8.695652
[ "-A = list(set(map(int, input().split())))", "+A = list(map(int, input().split()))", "+B = set([a & (-a) for a in A])", "+if len(B) > 1:", "+ print((0))", "+ exit()", "-def gcd(m, n):", "- if n == 0:", "- return m", "- return gcd(n, m % n)", "+def gcd(n, m):", "+ if m == 0:", "+ return n", "+ return gcd(m, n % m)", "+def lcm(x, y):", "+ return x * y // gcd(x, y)", "+", "+", "+A = [a // 2 for a in A]", "- LCM = LCM * a // gcd(LCM, a)", "-K = max(A)", "-for X in range(K // 2, M + 1, K):", "- for a in A:", "- if (X - a // 2) % a != 0:", "- break", "- else:", "- print(((M - X) // LCM + 1))", "- exit()", "-print((0))", "+ LCM = lcm(LCM, a)", "+ans = ((M // LCM) + 1) // 2", "+print(ans)" ]
false
0.075867
0.076469
0.992128
[ "s083058620", "s198355055" ]
u667024514
p03795
python
s615203565
s969830995
19
17
2,940
2,940
Accepted
Accepted
10.53
a = int(eval(input())) b = int(a/15) print((800*a-200*b))
n = int(eval(input())) print((n * 800 - (n // 15) * 200))
3
2
51
50
a = int(eval(input())) b = int(a / 15) print((800 * a - 200 * b))
n = int(eval(input())) print((n * 800 - (n // 15) * 200))
false
33.333333
[ "-a = int(eval(input()))", "-b = int(a / 15)", "-print((800 * a - 200 * b))", "+n = int(eval(input()))", "+print((n * 800 - (n // 15) * 200))" ]
false
0.075351
0.078521
0.959627
[ "s615203565", "s969830995" ]
u070201429
p03283
python
s511542875
s517463046
956
307
50,596
22,400
Accepted
Accepted
67.89
# Reference: https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree # Fenwick Tree class BinaryIndexedTree: # a = [0] * n # O(n) def __init__(self, n): self.size = n self.data = [0] * (n+1) # return sum(a[0:i]) # O(log(n)) def cumulative_sum(self, i): ans = 0 while i > 0: ans += self.data[i] i -= i & -i return ans # a[i] += x # O(log(n)) def add(self, i, x): i += 1 while i <= self.size: self.data[i] += x i += i & -i from sys import stdin input = stdin.buffer.readline def main(): n, m, q = list(map(int, input().split())) lr = [tuple(map(int, input().split())) for _ in range(m)] pq = [(0, 0, 0)] * q for ind in range(q): i, j = list(map(int, input().split())) pq[ind] = (i, j, ind) lr.sort(key=lambda x: x[0]) l = [i for i, j in lr] r = [j for i, j in lr] pq.sort(key=lambda x: x[0]) BIT = BinaryIndexedTree(n+1) for i in r: BIT.add(i, 1) # search r[lr_ind:] lr_ind = 0 ans = [0] * q for left, right, pq_ind in pq: while lr_ind < m and l[lr_ind] < left: BIT.add(r[lr_ind], -1) lr_ind += 1 ans[pq_ind] = BIT.cumulative_sum(right+1) for i in ans: print(i) main()
from sys import stdin input = stdin.buffer.readline def main(): n, m, q = list(map(int, input().split())) # Two-dimensional Cumulative Sum cs = [[0] * (n+1) for _ in range(n+1)] for _ in range(m): l, r = list(map(int, input().split())) cs[l][r] += 1 for l in range(1, n+1): for r in range(1, n+1): cs[l][r] += cs[l][r-1] for r in range(1, n+1): cs[l][r] += cs[l-1][r] ans = [-1] * q for lap in range(q): l, r = list(map(int, input().split())) ans[lap] = cs[n][r] - cs[l-1][r] for i in ans: print(i) main()
60
28
1,421
633
# Reference: https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree # Fenwick Tree class BinaryIndexedTree: # a = [0] * n # O(n) def __init__(self, n): self.size = n self.data = [0] * (n + 1) # return sum(a[0:i]) # O(log(n)) def cumulative_sum(self, i): ans = 0 while i > 0: ans += self.data[i] i -= i & -i return ans # a[i] += x # O(log(n)) def add(self, i, x): i += 1 while i <= self.size: self.data[i] += x i += i & -i from sys import stdin input = stdin.buffer.readline def main(): n, m, q = list(map(int, input().split())) lr = [tuple(map(int, input().split())) for _ in range(m)] pq = [(0, 0, 0)] * q for ind in range(q): i, j = list(map(int, input().split())) pq[ind] = (i, j, ind) lr.sort(key=lambda x: x[0]) l = [i for i, j in lr] r = [j for i, j in lr] pq.sort(key=lambda x: x[0]) BIT = BinaryIndexedTree(n + 1) for i in r: BIT.add(i, 1) # search r[lr_ind:] lr_ind = 0 ans = [0] * q for left, right, pq_ind in pq: while lr_ind < m and l[lr_ind] < left: BIT.add(r[lr_ind], -1) lr_ind += 1 ans[pq_ind] = BIT.cumulative_sum(right + 1) for i in ans: print(i) main()
from sys import stdin input = stdin.buffer.readline def main(): n, m, q = list(map(int, input().split())) # Two-dimensional Cumulative Sum cs = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): l, r = list(map(int, input().split())) cs[l][r] += 1 for l in range(1, n + 1): for r in range(1, n + 1): cs[l][r] += cs[l][r - 1] for r in range(1, n + 1): cs[l][r] += cs[l - 1][r] ans = [-1] * q for lap in range(q): l, r = list(map(int, input().split())) ans[lap] = cs[n][r] - cs[l - 1][r] for i in ans: print(i) main()
false
53.333333
[ "-# Reference: https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree", "-# Fenwick Tree", "-class BinaryIndexedTree:", "- # a = [0] * n", "- # O(n)", "- def __init__(self, n):", "- self.size = n", "- self.data = [0] * (n + 1)", "-", "- # return sum(a[0:i])", "- # O(log(n))", "- def cumulative_sum(self, i):", "- ans = 0", "- while i > 0:", "- ans += self.data[i]", "- i -= i & -i", "- return ans", "-", "- # a[i] += x", "- # O(log(n))", "- def add(self, i, x):", "- i += 1", "- while i <= self.size:", "- self.data[i] += x", "- i += i & -i", "-", "-", "- lr = [tuple(map(int, input().split())) for _ in range(m)]", "- pq = [(0, 0, 0)] * q", "- for ind in range(q):", "- i, j = list(map(int, input().split()))", "- pq[ind] = (i, j, ind)", "- lr.sort(key=lambda x: x[0])", "- l = [i for i, j in lr]", "- r = [j for i, j in lr]", "- pq.sort(key=lambda x: x[0])", "- BIT = BinaryIndexedTree(n + 1)", "- for i in r:", "- BIT.add(i, 1)", "- # search r[lr_ind:]", "- lr_ind = 0", "- ans = [0] * q", "- for left, right, pq_ind in pq:", "- while lr_ind < m and l[lr_ind] < left:", "- BIT.add(r[lr_ind], -1)", "- lr_ind += 1", "- ans[pq_ind] = BIT.cumulative_sum(right + 1)", "+ # Two-dimensional Cumulative Sum", "+ cs = [[0] * (n + 1) for _ in range(n + 1)]", "+ for _ in range(m):", "+ l, r = list(map(int, input().split()))", "+ cs[l][r] += 1", "+ for l in range(1, n + 1):", "+ for r in range(1, n + 1):", "+ cs[l][r] += cs[l][r - 1]", "+ for r in range(1, n + 1):", "+ cs[l][r] += cs[l - 1][r]", "+ ans = [-1] * q", "+ for lap in range(q):", "+ l, r = list(map(int, input().split()))", "+ ans[lap] = cs[n][r] - cs[l - 1][r]" ]
false
0.042563
0.042964
0.990648
[ "s511542875", "s517463046" ]
u523087093
p03281
python
s776990114
s996757594
120
28
27,220
9,180
Accepted
Accepted
76.67
import itertools import numpy as np def check_eight(n): div_list = [] for i in range(3, n + 1, 2): if n % i == 0: while n % i == 0: n = n // i div_list.append(i) if n == 1: break answer_list = [] for i in range(1, len(div_list)+1): comb = itertools.combinations(div_list, i) for c in comb: c = np.array(c) answer_list.append(c.prod()) answer = len(set(answer_list)) + 1 return answer == 8 if __name__ == "__main__": N = int(eval(input())) count = 0 for n in range(1, N + 1, 2): count += check_eight(n) print(count)
N = int(eval(input())) ans = 0 for n in range(3, N+1, 2): count = 1 for i in range(3, n+1, 2): if n % i == 0: count += 1 if n == 1: break if count == 8: ans += 1 print(ans)
32
15
710
244
import itertools import numpy as np def check_eight(n): div_list = [] for i in range(3, n + 1, 2): if n % i == 0: while n % i == 0: n = n // i div_list.append(i) if n == 1: break answer_list = [] for i in range(1, len(div_list) + 1): comb = itertools.combinations(div_list, i) for c in comb: c = np.array(c) answer_list.append(c.prod()) answer = len(set(answer_list)) + 1 return answer == 8 if __name__ == "__main__": N = int(eval(input())) count = 0 for n in range(1, N + 1, 2): count += check_eight(n) print(count)
N = int(eval(input())) ans = 0 for n in range(3, N + 1, 2): count = 1 for i in range(3, n + 1, 2): if n % i == 0: count += 1 if n == 1: break if count == 8: ans += 1 print(ans)
false
53.125
[ "-import itertools", "-import numpy as np", "-", "-", "-def check_eight(n):", "- div_list = []", "+N = int(eval(input()))", "+ans = 0", "+for n in range(3, N + 1, 2):", "+ count = 1", "- while n % i == 0:", "- n = n // i", "- div_list.append(i)", "+ count += 1", "- answer_list = []", "- for i in range(1, len(div_list) + 1):", "- comb = itertools.combinations(div_list, i)", "- for c in comb:", "- c = np.array(c)", "- answer_list.append(c.prod())", "- answer = len(set(answer_list)) + 1", "- return answer == 8", "-", "-", "-if __name__ == \"__main__\":", "- N = int(eval(input()))", "- count = 0", "- for n in range(1, N + 1, 2):", "- count += check_eight(n)", "- print(count)", "+ if count == 8:", "+ ans += 1", "+print(ans)" ]
false
0.292536
0.035396
8.26478
[ "s776990114", "s996757594" ]
u157020659
p02947
python
s477367465
s440954614
287
240
37,080
23,816
Accepted
Accepted
16.38
n = int(eval(input())) s = [list(eval(input())) for _ in range(n)] s_dict = dict([]) for i in s: key = ''.join(sorted(i)) s_dict.setdefault(key, 0) s_dict[key] += 1 ans = 0 for v in list(s_dict.values()): ans += v * (v - 1) // 2 print(ans)
import collections n = int(eval(input())) s = [''.join(sorted(list(eval(input())))) for _ in range(n)] s = collections.Counter(s) ans = 0 for v in list(s.values()): ans += v * (v - 1) // 2 print(ans)
14
10
253
196
n = int(eval(input())) s = [list(eval(input())) for _ in range(n)] s_dict = dict([]) for i in s: key = "".join(sorted(i)) s_dict.setdefault(key, 0) s_dict[key] += 1 ans = 0 for v in list(s_dict.values()): ans += v * (v - 1) // 2 print(ans)
import collections n = int(eval(input())) s = ["".join(sorted(list(eval(input())))) for _ in range(n)] s = collections.Counter(s) ans = 0 for v in list(s.values()): ans += v * (v - 1) // 2 print(ans)
false
28.571429
[ "+import collections", "+", "-s = [list(eval(input())) for _ in range(n)]", "-s_dict = dict([])", "-for i in s:", "- key = \"\".join(sorted(i))", "- s_dict.setdefault(key, 0)", "- s_dict[key] += 1", "+s = [\"\".join(sorted(list(eval(input())))) for _ in range(n)]", "+s = collections.Counter(s)", "-for v in list(s_dict.values()):", "+for v in list(s.values()):" ]
false
0.036148
0.036099
1.001359
[ "s477367465", "s440954614" ]
u564589929
p02989
python
s069770345
s634808833
93
75
14,812
14,396
Accepted
Accepted
19.35
import sys sys.setrecursionlimit(10 ** 9) int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] from collections import deque def solve(): n = II() D = deque(sorted(LI())) for i in range(n): l = D.popleft() # print('l', l) if len(D) == 0: print((1)) break else: r = D.pop() # print('r', r) if len(D) == 0: print((r - l)) break else: continue if __name__ == '__main__': solve()
# import sys # sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solve(): n = II() D = LI() D = sorted(D) t = n // 2 print((D[t] - D[t-1])) if __name__ == '__main__': solve()
37
23
791
470
import sys sys.setrecursionlimit(10**9) int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] from collections import deque def solve(): n = II() D = deque(sorted(LI())) for i in range(n): l = D.popleft() # print('l', l) if len(D) == 0: print((1)) break else: r = D.pop() # print('r', r) if len(D) == 0: print((r - l)) break else: continue if __name__ == "__main__": solve()
# import sys # sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solve(): n = II() D = LI() D = sorted(D) t = n // 2 print((D[t] - D[t - 1])) if __name__ == "__main__": solve()
false
37.837838
[ "-import sys", "-", "-sys.setrecursionlimit(10**9)", "+# import sys", "+# sys.setrecursionlimit(10 ** 6)", "-from collections import deque", "-", "-", "- D = deque(sorted(LI()))", "- for i in range(n):", "- l = D.popleft()", "- # print('l', l)", "- if len(D) == 0:", "- print((1))", "- break", "- else:", "- r = D.pop()", "- # print('r', r)", "- if len(D) == 0:", "- print((r - l))", "- break", "- else:", "- continue", "+ D = LI()", "+ D = sorted(D)", "+ t = n // 2", "+ print((D[t] - D[t - 1]))" ]
false
0.09126
0.097789
0.933236
[ "s069770345", "s634808833" ]
u347640436
p03504
python
s219858103
s108691231
1,110
585
29,428
35,460
Accepted
Accepted
47.3
N, C = list(map(int, input().split())) tt = [[0] * (10 ** 5 + 1) for _ in range(30)] for _ in range(N): s, t, c = list(map(int, input().split())) ttc = tt[c - 1] for i in range(s - 1, t): ttc[i] = 1 ct = [0] * (10 ** 5 + 1) for i in range(30): tti = tt[i] for j in range(10 ** 5 + 1): ct[j] += tti[j] print((max(ct)))
# imos 法 from operator import itemgetter N, C = list(map(int, input().split())) stc = [list(map(int, input().split())) for _ in range(N)] stc.sort(key=itemgetter(2, 0)) cs = [0] * (10 ** 5 + 1) pc = -1 for s, t, c in stc: if pc != c: pt = -1 pc = c if pt == s: cs[s] += 1 else: cs[s - 1] += 1 cs[t] -= 1 pt = t for i in range(1, 10 ** 5 + 1): cs[i] += cs[i - 1] print((max(cs)))
16
24
358
454
N, C = list(map(int, input().split())) tt = [[0] * (10**5 + 1) for _ in range(30)] for _ in range(N): s, t, c = list(map(int, input().split())) ttc = tt[c - 1] for i in range(s - 1, t): ttc[i] = 1 ct = [0] * (10**5 + 1) for i in range(30): tti = tt[i] for j in range(10**5 + 1): ct[j] += tti[j] print((max(ct)))
# imos 法 from operator import itemgetter N, C = list(map(int, input().split())) stc = [list(map(int, input().split())) for _ in range(N)] stc.sort(key=itemgetter(2, 0)) cs = [0] * (10**5 + 1) pc = -1 for s, t, c in stc: if pc != c: pt = -1 pc = c if pt == s: cs[s] += 1 else: cs[s - 1] += 1 cs[t] -= 1 pt = t for i in range(1, 10**5 + 1): cs[i] += cs[i - 1] print((max(cs)))
false
33.333333
[ "+# imos 法", "+from operator import itemgetter", "+", "-tt = [[0] * (10**5 + 1) for _ in range(30)]", "-for _ in range(N):", "- s, t, c = list(map(int, input().split()))", "- ttc = tt[c - 1]", "- for i in range(s - 1, t):", "- ttc[i] = 1", "-ct = [0] * (10**5 + 1)", "-for i in range(30):", "- tti = tt[i]", "- for j in range(10**5 + 1):", "- ct[j] += tti[j]", "-print((max(ct)))", "+stc = [list(map(int, input().split())) for _ in range(N)]", "+stc.sort(key=itemgetter(2, 0))", "+cs = [0] * (10**5 + 1)", "+pc = -1", "+for s, t, c in stc:", "+ if pc != c:", "+ pt = -1", "+ pc = c", "+ if pt == s:", "+ cs[s] += 1", "+ else:", "+ cs[s - 1] += 1", "+ cs[t] -= 1", "+ pt = t", "+for i in range(1, 10**5 + 1):", "+ cs[i] += cs[i - 1]", "+print((max(cs)))" ]
false
1.213267
0.064444
18.826729
[ "s219858103", "s108691231" ]
u905582793
p02775
python
s110945367
s606798305
730
673
5,492
5,492
Accepted
Accepted
7.81
n = eval(input()) n = n[::-1] l = len(n) ans = 0 flg = 0 x = [] for j in range(l): i = n[j] i = int(i) if i+flg>=6: i += flg ans += (10-i) flg = 1 elif i+flg == 5: if j == l-1: ans += i+flg flg = 0 elif int(n[j+1]) >= 5: i += flg ans += (10-i) flg = 1 else: ans += i+flg flg = 0 else: i += flg ans += i flg = 0 if flg: ans += 1 print(ans)
n = eval(input()) n = n[::-1] l = len(n) ans = 0 flg = 0 x = [] for j in range(l): i = n[j] i = int(i) i += flg if i >= 6: ans += (10-i) flg = 1 elif i == 5: if j == l-1: ans += i flg = 0 elif int(n[j+1]) >= 5: ans += (10-i) flg = 1 else: ans += i flg = 0 else: ans += i flg = 0 if flg: ans += 1 print(ans)
31
29
452
406
n = eval(input()) n = n[::-1] l = len(n) ans = 0 flg = 0 x = [] for j in range(l): i = n[j] i = int(i) if i + flg >= 6: i += flg ans += 10 - i flg = 1 elif i + flg == 5: if j == l - 1: ans += i + flg flg = 0 elif int(n[j + 1]) >= 5: i += flg ans += 10 - i flg = 1 else: ans += i + flg flg = 0 else: i += flg ans += i flg = 0 if flg: ans += 1 print(ans)
n = eval(input()) n = n[::-1] l = len(n) ans = 0 flg = 0 x = [] for j in range(l): i = n[j] i = int(i) i += flg if i >= 6: ans += 10 - i flg = 1 elif i == 5: if j == l - 1: ans += i flg = 0 elif int(n[j + 1]) >= 5: ans += 10 - i flg = 1 else: ans += i flg = 0 else: ans += i flg = 0 if flg: ans += 1 print(ans)
false
6.451613
[ "- if i + flg >= 6:", "- i += flg", "+ i += flg", "+ if i >= 6:", "- elif i + flg == 5:", "+ elif i == 5:", "- ans += i + flg", "+ ans += i", "- i += flg", "- ans += i + flg", "+ ans += i", "- i += flg" ]
false
0.031397
0.03823
0.821256
[ "s110945367", "s606798305" ]
u546285759
p00590
python
s894421349
s470697839
950
490
7,800
7,752
Accepted
Accepted
48.42
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i*i, 10001, i): primes[j] = 0 while True: try: N = int(eval(input())) except: break print((sum(primes[i] & primes[N-i+1] for i in range(1, N+1))))
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i*i, 10001, i): primes[j] = 0 while True: try: N = int(eval(input())) except: break print((sum(primes[i] and primes[N-i+1] for i in range(1, N+1))))
12
12
284
286
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i * i, 10001, i): primes[j] = 0 while True: try: N = int(eval(input())) except: break print((sum(primes[i] & primes[N - i + 1] for i in range(1, N + 1))))
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i * i, 10001, i): primes[j] = 0 while True: try: N = int(eval(input())) except: break print((sum(primes[i] and primes[N - i + 1] for i in range(1, N + 1))))
false
0
[ "- print((sum(primes[i] & primes[N - i + 1] for i in range(1, N + 1))))", "+ print((sum(primes[i] and primes[N - i + 1] for i in range(1, N + 1))))" ]
false
0.08304
0.045185
1.837781
[ "s894421349", "s470697839" ]
u761529120
p03634
python
s083939253
s961032358
754
388
94,752
112,352
Accepted
Accepted
48.54
import heapq import sys input = sys.stdin.readline def dijkstra(s, edge, N): d = [float('inf')] * N used = [True] * N d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10 ** 6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge%(10 ** 6)]: continue v = minedge % (10 ** 6) d[v] = minedge // (10 ** 6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10 ** 6) + e[1]) return d def main(): N = int(eval(input())) edge = [[] for _ in range(N)] for _ in range(N-1): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 edge[a].append([c,b]) edge[b].append([c,a]) Q, K = list(map(int, input().split())) K -= 1 d = dijkstra(K, edge, N) for _ in range(Q): x, y = list(map(int, input().split())) x -= 1 y -= 1 print((d[x] + d[y])) if __name__ == "__main__": main()
import heapq import sys input = sys.stdin.readline def dijkstra_heap(s,edge,n): #始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n #True:未確定 d[s] = 0 used[s] = False edgelist = [] for a,b in edge[s]: heapq.heappush(edgelist,a*(10**6)+b) while len(edgelist): minedge = heapq.heappop(edgelist) #まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge%(10**6)]: continue v = minedge%(10**6) d[v] = minedge//(10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1]) return d def main(): N = int(eval(input())) edge = [[] for i in range(N)] for _ in range(N-1): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 edge[a].append([c,b]) edge[b].append([c,a]) Q, K = list(map(int, input().split())) K -= 1 d = dijkstra_heap(K,edge,N) for _ in range(Q): x, y = list(map(int, input().split())) x -= 1 y -= 1 print((d[x]+d[y])) if __name__ == "__main__": main()
48
50
1,130
1,171
import heapq import sys input = sys.stdin.readline def dijkstra(s, edge, N): d = [float("inf")] * N used = [True] * N d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d def main(): N = int(eval(input())) edge = [[] for _ in range(N)] for _ in range(N - 1): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 edge[a].append([c, b]) edge[b].append([c, a]) Q, K = list(map(int, input().split())) K -= 1 d = dijkstra(K, edge, N) for _ in range(Q): x, y = list(map(int, input().split())) x -= 1 y -= 1 print((d[x] + d[y])) if __name__ == "__main__": main()
import heapq import sys input = sys.stdin.readline def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d def main(): N = int(eval(input())) edge = [[] for i in range(N)] for _ in range(N - 1): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 edge[a].append([c, b]) edge[b].append([c, a]) Q, K = list(map(int, input().split())) K -= 1 d = dijkstra_heap(K, edge, N) for _ in range(Q): x, y = list(map(int, input().split())) x -= 1 y -= 1 print((d[x] + d[y])) if __name__ == "__main__": main()
false
4
[ "-def dijkstra(s, edge, N):", "- d = [float(\"inf\")] * N", "- used = [True] * N", "+def dijkstra_heap(s, edge, n):", "+ # 始点sから各頂点への最短距離", "+ d = [10**20] * n", "+ used = [True] * n # True:未確定", "+ # まだ使われてない頂点の中から最小の距離のものを探す", "- edge = [[] for _ in range(N)]", "+ edge = [[] for i in range(N)]", "- d = dijkstra(K, edge, N)", "+ d = dijkstra_heap(K, edge, N)" ]
false
0.088581
0.085382
1.037462
[ "s083939253", "s961032358" ]
u254871849
p03681
python
s192739059
s863149610
442
45
4,084
6,900
Accepted
Accepted
89.82
import sys input = sys.stdin.readline from math import factorial mod = 10 ** 9 + 7 N, M = [int(x) for x in input().split()] if abs(N - M) >= 2: ans = 0 else: ans = (factorial(N) % mod * factorial(M) % mod) % mod if N == M: ans *= 2 print((ans % mod))
import sys MOD = 10 ** 9 + 7 def make_factorial_mod(n, mod): fac = [None] * (n + 1) fac[0] = 1 for i in range(n): fac[i+1] = fac[i] * (i + 1) % mod return fac fac = make_factorial_mod(10**5, MOD) n, m = list(map(int, sys.stdin.readline().split())) if n < m: n, m = m, n def main(): if n == m: return fac[n] * fac[m] * 2 % MOD elif n == m + 1: return fac[n] * fac[m] % MOD else: return 0 if __name__ == '__main__': ans = main() print(ans)
10
29
259
538
import sys input = sys.stdin.readline from math import factorial mod = 10**9 + 7 N, M = [int(x) for x in input().split()] if abs(N - M) >= 2: ans = 0 else: ans = (factorial(N) % mod * factorial(M) % mod) % mod if N == M: ans *= 2 print((ans % mod))
import sys MOD = 10**9 + 7 def make_factorial_mod(n, mod): fac = [None] * (n + 1) fac[0] = 1 for i in range(n): fac[i + 1] = fac[i] * (i + 1) % mod return fac fac = make_factorial_mod(10**5, MOD) n, m = list(map(int, sys.stdin.readline().split())) if n < m: n, m = m, n def main(): if n == m: return fac[n] * fac[m] * 2 % MOD elif n == m + 1: return fac[n] * fac[m] % MOD else: return 0 if __name__ == "__main__": ans = main() print(ans)
false
65.517241
[ "-input = sys.stdin.readline", "-from math import factorial", "+MOD = 10**9 + 7", "-mod = 10**9 + 7", "-N, M = [int(x) for x in input().split()]", "-if abs(N - M) >= 2:", "- ans = 0", "-else:", "- ans = (factorial(N) % mod * factorial(M) % mod) % mod", "-if N == M:", "- ans *= 2", "-print((ans % mod))", "+", "+def make_factorial_mod(n, mod):", "+ fac = [None] * (n + 1)", "+ fac[0] = 1", "+ for i in range(n):", "+ fac[i + 1] = fac[i] * (i + 1) % mod", "+ return fac", "+", "+", "+fac = make_factorial_mod(10**5, MOD)", "+n, m = list(map(int, sys.stdin.readline().split()))", "+if n < m:", "+ n, m = m, n", "+", "+", "+def main():", "+ if n == m:", "+ return fac[n] * fac[m] * 2 % MOD", "+ elif n == m + 1:", "+ return fac[n] * fac[m] % MOD", "+ else:", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ ans = main()", "+ print(ans)" ]
false
0.082556
0.091445
0.902797
[ "s192739059", "s863149610" ]
u588341295
p03450
python
s104695241
s396198608
1,458
1,234
11,536
12,140
Accepted
Accepted
15.36
# -*- coding: utf-8 -*- """ 参考:http://hamko.hatenadiary.jp/entry/2018/01/30/210057    http://at274.hatenablog.com/entry/2018/02/03/140504 ・重み付きUnion-Find木 """ class WeightedUnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) # 根への距離を管理 self.weight = [0] * (n+1) # 検索 def find(self, x): if self.par[x] == x: return x else: y = self.find(self.par[x]) # 親への重みを追加しながら根まで走査 self.weight[x] += self.weight[self.par[x]] self.par[x] = y return y # 併合 def union(self, x, y, w): rx = self.find(x) ry = self.find(y) # xの木の高さ < yの木の高さ if self.rank[rx] < self.rank[ry]: self.par[rx] = ry self.weight[rx] = w - self.weight[x] + self.weight[y] # xの木の高さ ≧ yの木の高さ else: self.par[ry] = rx self.weight[ry] = - w - self.weight[y] + self.weight[x] # 木の高さが同じだった場合の処理 if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 # 同じ集合に属するか def same(self, x, y): return self.find(x) == self.find(y) # xからyへのコスト def diff(self, x, y): return self.weight[x] - self.weight[y] N, M = list(map(int, input().split())) wuf = WeightedUnionFind(N) for i in range(M): x, y, w = list(map(int, input().split())) # 同じ集合に属する場合は if wuf.same(x, y): # 記録された距離と今回の情報に矛盾がないか確認 if wuf.diff(x, y) != w: print('No') exit() wuf.union(x, y, w) # 全部無矛盾で木が構築できればOK print('Yes')
# -*- coding: utf-8 -*- """ 参考:http://hamko.hatenadiary.jp/entry/2018/01/30/210057    http://at274.hatenablog.com/entry/2018/02/03/140504 ・重み付きUnion-Find木 """ import sys def input(): return sys.stdin.readline().strip() class WeightedUnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) # 根への距離を管理 self.weight = [0] * (n+1) # 検索 def find(self, x): if self.par[x] == x: return x else: y = self.find(self.par[x]) # 親への重みを追加しながら根まで走査 self.weight[x] += self.weight[self.par[x]] self.par[x] = y return y # 併合 def union(self, x, y, w): rx = self.find(x) ry = self.find(y) # xの木の高さ < yの木の高さ if self.rank[rx] < self.rank[ry]: self.par[rx] = ry self.weight[rx] = w - self.weight[x] + self.weight[y] # xの木の高さ ≧ yの木の高さ else: self.par[ry] = rx self.weight[ry] = - w - self.weight[y] + self.weight[x] # 木の高さが同じだった場合の処理 if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 # 同じ集合に属するか def same(self, x, y): return self.find(x) == self.find(y) # xからyへのコスト def diff(self, x, y): return self.weight[x] - self.weight[y] N, M = list(map(int, input().split())) wuf = WeightedUnionFind(N) for i in range(M): x, y, w = list(map(int, input().split())) # 同じ集合に属する場合 if wuf.same(x, y): # 記録された距離と今回の情報に矛盾がないか確認 if wuf.diff(x, y) != w: print('No') exit() wuf.union(x, y, w) # 全部無矛盾で木が構築できればOK print('Yes')
64
67
1,684
1,747
# -*- coding: utf-8 -*- """ 参考:http://hamko.hatenadiary.jp/entry/2018/01/30/210057    http://at274.hatenablog.com/entry/2018/02/03/140504 ・重み付きUnion-Find木 """ class WeightedUnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) # 根への距離を管理 self.weight = [0] * (n + 1) # 検索 def find(self, x): if self.par[x] == x: return x else: y = self.find(self.par[x]) # 親への重みを追加しながら根まで走査 self.weight[x] += self.weight[self.par[x]] self.par[x] = y return y # 併合 def union(self, x, y, w): rx = self.find(x) ry = self.find(y) # xの木の高さ < yの木の高さ if self.rank[rx] < self.rank[ry]: self.par[rx] = ry self.weight[rx] = w - self.weight[x] + self.weight[y] # xの木の高さ ≧ yの木の高さ else: self.par[ry] = rx self.weight[ry] = -w - self.weight[y] + self.weight[x] # 木の高さが同じだった場合の処理 if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 # 同じ集合に属するか def same(self, x, y): return self.find(x) == self.find(y) # xからyへのコスト def diff(self, x, y): return self.weight[x] - self.weight[y] N, M = list(map(int, input().split())) wuf = WeightedUnionFind(N) for i in range(M): x, y, w = list(map(int, input().split())) # 同じ集合に属する場合は if wuf.same(x, y): # 記録された距離と今回の情報に矛盾がないか確認 if wuf.diff(x, y) != w: print("No") exit() wuf.union(x, y, w) # 全部無矛盾で木が構築できればOK print("Yes")
# -*- coding: utf-8 -*- """ 参考:http://hamko.hatenadiary.jp/entry/2018/01/30/210057    http://at274.hatenablog.com/entry/2018/02/03/140504 ・重み付きUnion-Find木 """ import sys def input(): return sys.stdin.readline().strip() class WeightedUnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) # 根への距離を管理 self.weight = [0] * (n + 1) # 検索 def find(self, x): if self.par[x] == x: return x else: y = self.find(self.par[x]) # 親への重みを追加しながら根まで走査 self.weight[x] += self.weight[self.par[x]] self.par[x] = y return y # 併合 def union(self, x, y, w): rx = self.find(x) ry = self.find(y) # xの木の高さ < yの木の高さ if self.rank[rx] < self.rank[ry]: self.par[rx] = ry self.weight[rx] = w - self.weight[x] + self.weight[y] # xの木の高さ ≧ yの木の高さ else: self.par[ry] = rx self.weight[ry] = -w - self.weight[y] + self.weight[x] # 木の高さが同じだった場合の処理 if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 # 同じ集合に属するか def same(self, x, y): return self.find(x) == self.find(y) # xからyへのコスト def diff(self, x, y): return self.weight[x] - self.weight[y] N, M = list(map(int, input().split())) wuf = WeightedUnionFind(N) for i in range(M): x, y, w = list(map(int, input().split())) # 同じ集合に属する場合 if wuf.same(x, y): # 記録された距離と今回の情報に矛盾がないか確認 if wuf.diff(x, y) != w: print("No") exit() wuf.union(x, y, w) # 全部無矛盾で木が構築できればOK print("Yes")
false
4.477612
[ "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "- # 同じ集合に属する場合は", "+ # 同じ集合に属する場合" ]
false
0.043005
0.040229
1.069003
[ "s104695241", "s396198608" ]
u716530146
p02753
python
s904424661
s869738989
181
167
38,256
38,256
Accepted
Accepted
7.73
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 s = eval(input()) S = {"A","B"} s1 = {s[0],s[1]} s2 = {s[2],s[1]} if s1 == S or s2 == S: print("Yes") else: print("No")
import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 s = eval(input()) for i in range(2): if s[i] != s[i+1]: count += 1 print(("Yes" if count >= 1 else "No"))
14
10
347
305
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") inf = float("inf") mod = 10**9 + 7 mans = inf ans = 0 count = 0 pro = 1 s = eval(input()) S = {"A", "B"} s1 = {s[0], s[1]} s2 = {s[2], s[1]} if s1 == S or s2 == S: print("Yes") else: print("No")
import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") inf = float("inf") mod = 10**9 + 7 mans = inf ans = 0 count = 0 pro = 1 s = eval(input()) for i in range(2): if s[i] != s[i + 1]: count += 1 print(("Yes" if count >= 1 else "No"))
false
28.571429
[ "-#!/usr/bin/env python3", "-S = {\"A\", \"B\"}", "-s1 = {s[0], s[1]}", "-s2 = {s[2], s[1]}", "-if s1 == S or s2 == S:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+for i in range(2):", "+ if s[i] != s[i + 1]:", "+ count += 1", "+print((\"Yes\" if count >= 1 else \"No\"))" ]
false
0.040028
0.039515
1.012976
[ "s904424661", "s869738989" ]
u761320129
p03296
python
s745001197
s210749859
20
17
3,316
3,060
Accepted
Accepted
15
N = int(eval(input())) src = list(map(int,input().split())) prev = -1 seq = 1 ans = 0 for a in src: if prev == a: seq += 1 else: ans += seq//2 seq = 1 prev = a if seq > 1: ans += seq//2 print(ans)
N = int(eval(input())) A = list(map(int,input().split())) ans = 0 changed = False for a,b in zip(A,A[1:]): if changed: changed = False continue if a == b: ans += 1 changed = True print(ans)
17
13
248
236
N = int(eval(input())) src = list(map(int, input().split())) prev = -1 seq = 1 ans = 0 for a in src: if prev == a: seq += 1 else: ans += seq // 2 seq = 1 prev = a if seq > 1: ans += seq // 2 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 changed = False for a, b in zip(A, A[1:]): if changed: changed = False continue if a == b: ans += 1 changed = True print(ans)
false
23.529412
[ "-src = list(map(int, input().split()))", "-prev = -1", "-seq = 1", "+A = list(map(int, input().split()))", "-for a in src:", "- if prev == a:", "- seq += 1", "- else:", "- ans += seq // 2", "- seq = 1", "- prev = a", "-if seq > 1:", "- ans += seq // 2", "+changed = False", "+for a, b in zip(A, A[1:]):", "+ if changed:", "+ changed = False", "+ continue", "+ if a == b:", "+ ans += 1", "+ changed = True" ]
false
0.008618
0.039044
0.220734
[ "s745001197", "s210749859" ]
u268822556
p02657
python
s064652758
s134524285
23
20
9,152
9,024
Accepted
Accepted
13.04
A, B = list(map(int, input().split())) print((A*B))
A, B = list(map(float, input().split())) i = (int(A)*int(B*100))//100 print(i)
2
3
44
75
A, B = list(map(int, input().split())) print((A * B))
A, B = list(map(float, input().split())) i = (int(A) * int(B * 100)) // 100 print(i)
false
33.333333
[ "-A, B = list(map(int, input().split()))", "-print((A * B))", "+A, B = list(map(float, input().split()))", "+i = (int(A) * int(B * 100)) // 100", "+print(i)" ]
false
0.07459
0.042846
1.74087
[ "s064652758", "s134524285" ]
u670180528
p03781
python
s547493995
s888395414
30
17
2,940
2,940
Accepted
Accepted
43.33
x=int(eval(input())) n=1 while n*(n+1)//2<x:n+=1 print(n)
print((int((8*int(eval(input())))**.5+1)//2))
4
1
54
37
x = int(eval(input())) n = 1 while n * (n + 1) // 2 < x: n += 1 print(n)
print((int((8 * int(eval(input()))) ** 0.5 + 1) // 2))
false
75
[ "-x = int(eval(input()))", "-n = 1", "-while n * (n + 1) // 2 < x:", "- n += 1", "-print(n)", "+print((int((8 * int(eval(input()))) ** 0.5 + 1) // 2))" ]
false
0.076383
0.087588
0.872068
[ "s547493995", "s888395414" ]
u330661451
p03013
python
s428107599
s879023289
179
72
7,064
6,900
Accepted
Accepted
59.78
MOD = 1000000007 n , m = list(map(int,input().split())) count = [-1 for i in range(n+1)] for i in range(m): count[int(eval(input()))] = 0 for i in range(1,n+1): if count[i] == 0: continue if i == 1: count[i] = 1 elif i == 2: count[i] = count[i-1] + 1 else: count[i] = (count[i-1] + count[i-2]) % MOD print((count[n]))
import sys input = sys.stdin.readline MOD = 1000000007 n , m = list(map(int,input().split())) count = [-1] * (n+1) for i in range(m): count[int(eval(input()))] = 0 for i in range(1,n+1): if count[i] == 0: continue if i == 1: count[i] = 1 elif i == 2: count[i] = count[i-1] + 1 else: count[i] = (count[i-1] + count[i-2]) % MOD print((count[n]))
20
23
385
415
MOD = 1000000007 n, m = list(map(int, input().split())) count = [-1 for i in range(n + 1)] for i in range(m): count[int(eval(input()))] = 0 for i in range(1, n + 1): if count[i] == 0: continue if i == 1: count[i] = 1 elif i == 2: count[i] = count[i - 1] + 1 else: count[i] = (count[i - 1] + count[i - 2]) % MOD print((count[n]))
import sys input = sys.stdin.readline MOD = 1000000007 n, m = list(map(int, input().split())) count = [-1] * (n + 1) for i in range(m): count[int(eval(input()))] = 0 for i in range(1, n + 1): if count[i] == 0: continue if i == 1: count[i] = 1 elif i == 2: count[i] = count[i - 1] + 1 else: count[i] = (count[i - 1] + count[i - 2]) % MOD print((count[n]))
false
13.043478
[ "+import sys", "+", "+input = sys.stdin.readline", "-count = [-1 for i in range(n + 1)]", "+count = [-1] * (n + 1)" ]
false
0.127889
0.042078
3.039334
[ "s428107599", "s879023289" ]
u948524308
p02947
python
s391277155
s941220571
956
771
61,696
11,428
Accepted
Accepted
19.35
import math N = int(eval(input())) s = [[""]*10 for i in range(N)] a =[[0]*26 for i in range(N)] b =[""]*N cn =ord("a") for i in range(N): s[i] = list(eval(input())) s[i].sort() b[i] ="".join(s[i]) b.sort() c = 0 ans =0 for i in range(N-1): if b[i]==b[i+1]: c +=1 else: if c !=0: ans=ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2)) c = 0 if c !=0: ans = ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2)) print((int(ans)))
import math N = int(eval(input())) b =[""]*N cn =ord("a") for i in range(N): s = list(eval(input())) s.sort() b[i] ="".join(s) b.sort() c = 0 ans =0 for i in range(N-1): if b[i]==b[i+1]: c +=1 else: if c !=0: ans=ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2)) c = 0 if c !=0: ans = ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2)) print((int(ans)))
32
31
554
491
import math N = int(eval(input())) s = [[""] * 10 for i in range(N)] a = [[0] * 26 for i in range(N)] b = [""] * N cn = ord("a") for i in range(N): s[i] = list(eval(input())) s[i].sort() b[i] = "".join(s[i]) b.sort() c = 0 ans = 0 for i in range(N - 1): if b[i] == b[i + 1]: c += 1 else: if c != 0: ans = ans + math.factorial(c + 1) / ( math.factorial(2) * math.factorial(c + 1 - 2) ) c = 0 if c != 0: ans = ans + math.factorial(c + 1) / (math.factorial(2) * math.factorial(c + 1 - 2)) print((int(ans)))
import math N = int(eval(input())) b = [""] * N cn = ord("a") for i in range(N): s = list(eval(input())) s.sort() b[i] = "".join(s) b.sort() c = 0 ans = 0 for i in range(N - 1): if b[i] == b[i + 1]: c += 1 else: if c != 0: ans = ans + math.factorial(c + 1) / ( math.factorial(2) * math.factorial(c + 1 - 2) ) c = 0 if c != 0: ans = ans + math.factorial(c + 1) / (math.factorial(2) * math.factorial(c + 1 - 2)) print((int(ans)))
false
3.125
[ "-s = [[\"\"] * 10 for i in range(N)]", "-a = [[0] * 26 for i in range(N)]", "- s[i] = list(eval(input()))", "- s[i].sort()", "- b[i] = \"\".join(s[i])", "+ s = list(eval(input()))", "+ s.sort()", "+ b[i] = \"\".join(s)" ]
false
0.038048
0.061061
0.623107
[ "s391277155", "s941220571" ]
u175034939
p02609
python
s150079668
s124096300
690
451
12,912
15,932
Accepted
Accepted
34.64
n = int(eval(input())) s = eval(input()) x = [int(i) for i in s] pc = s.count('1') def popcnt(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def f(x): if x == 0: return 0 return f(x % popcnt(x)) + 1 ans = [0]*n for a in range(2): npc = pc if a == 0: npc += 1 else: npc -= 1 if npc <= 0: continue r0 = 0 for i in range(n): r0 = (r0*2) % npc r0 += x[i] k = 1 for i in range(n-1, -1, -1): if x[i] == a: r = r0 if a == 0: r = (r+k) % npc else: r = (r-k+npc) % npc ans[i] = f(r) + 1 k = (k*2) % npc for i in ans: print(i)
n = int(input()) s = input() int_s = [int(i) for i in s] pc = s.count('1') def f(x): bi = bin(x) pc = bi.count('1') cnt = 1 while True: if x == 0: break x = x % pc bi = bin(x) pc = bi.count('1') cnt += 1 return cnt num_pl = 0 for i in range(n): num_pl = (num_pl*2) % (pc+1) num_pl += int_s[i] num_mi = 0 for i in range(n): if pc-1 <= 0: continue num_mi = (num_mi*2) % (pc-1) num_mi += int_s[i] ans = [0]*n pc_pl, pc_mi = pc+1, pc-1 r_pl, r_mi = 1, 1 for i in range(n-1, -1, -1): if int_s[i] == 0: num = num_pl num = (num+r_pl) % pc_pl else: num = num_mi if pc_mi <= 0: continue num = (num-r_mi+pc_mi) % pc_mi ans[i] = f(num) r_pl = (r_pl*2) % pc_pl if pc_mi <= 0: continue r_mi = (r_mi*2) % pc_mi print(*ans, sep='\n')
48
50
957
962
n = int(eval(input())) s = eval(input()) x = [int(i) for i in s] pc = s.count("1") def popcnt(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F def f(x): if x == 0: return 0 return f(x % popcnt(x)) + 1 ans = [0] * n for a in range(2): npc = pc if a == 0: npc += 1 else: npc -= 1 if npc <= 0: continue r0 = 0 for i in range(n): r0 = (r0 * 2) % npc r0 += x[i] k = 1 for i in range(n - 1, -1, -1): if x[i] == a: r = r0 if a == 0: r = (r + k) % npc else: r = (r - k + npc) % npc ans[i] = f(r) + 1 k = (k * 2) % npc for i in ans: print(i)
n = int(input()) s = input() int_s = [int(i) for i in s] pc = s.count("1") def f(x): bi = bin(x) pc = bi.count("1") cnt = 1 while True: if x == 0: break x = x % pc bi = bin(x) pc = bi.count("1") cnt += 1 return cnt num_pl = 0 for i in range(n): num_pl = (num_pl * 2) % (pc + 1) num_pl += int_s[i] num_mi = 0 for i in range(n): if pc - 1 <= 0: continue num_mi = (num_mi * 2) % (pc - 1) num_mi += int_s[i] ans = [0] * n pc_pl, pc_mi = pc + 1, pc - 1 r_pl, r_mi = 1, 1 for i in range(n - 1, -1, -1): if int_s[i] == 0: num = num_pl num = (num + r_pl) % pc_pl else: num = num_mi if pc_mi <= 0: continue num = (num - r_mi + pc_mi) % pc_mi ans[i] = f(num) r_pl = (r_pl * 2) % pc_pl if pc_mi <= 0: continue r_mi = (r_mi * 2) % pc_mi print(*ans, sep="\n")
false
4
[ "-n = int(eval(input()))", "-s = eval(input())", "-x = [int(i) for i in s]", "+n = int(input())", "+s = input()", "+int_s = [int(i) for i in s]", "-def popcnt(x):", "- x = x - ((x >> 1) & 0x5555555555555555)", "- x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)", "- x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F", "- x = x + (x >> 8)", "- x = x + (x >> 16)", "- x = x + (x >> 32)", "- return x & 0x0000007F", "+def f(x):", "+ bi = bin(x)", "+ pc = bi.count(\"1\")", "+ cnt = 1", "+ while True:", "+ if x == 0:", "+ break", "+ x = x % pc", "+ bi = bin(x)", "+ pc = bi.count(\"1\")", "+ cnt += 1", "+ return cnt", "-def f(x):", "- if x == 0:", "- return 0", "- return f(x % popcnt(x)) + 1", "-", "-", "+num_pl = 0", "+for i in range(n):", "+ num_pl = (num_pl * 2) % (pc + 1)", "+ num_pl += int_s[i]", "+num_mi = 0", "+for i in range(n):", "+ if pc - 1 <= 0:", "+ continue", "+ num_mi = (num_mi * 2) % (pc - 1)", "+ num_mi += int_s[i]", "-for a in range(2):", "- npc = pc", "- if a == 0:", "- npc += 1", "+pc_pl, pc_mi = pc + 1, pc - 1", "+r_pl, r_mi = 1, 1", "+for i in range(n - 1, -1, -1):", "+ if int_s[i] == 0:", "+ num = num_pl", "+ num = (num + r_pl) % pc_pl", "- npc -= 1", "- if npc <= 0:", "+ num = num_mi", "+ if pc_mi <= 0:", "+ continue", "+ num = (num - r_mi + pc_mi) % pc_mi", "+ ans[i] = f(num)", "+ r_pl = (r_pl * 2) % pc_pl", "+ if pc_mi <= 0:", "- r0 = 0", "- for i in range(n):", "- r0 = (r0 * 2) % npc", "- r0 += x[i]", "- k = 1", "- for i in range(n - 1, -1, -1):", "- if x[i] == a:", "- r = r0", "- if a == 0:", "- r = (r + k) % npc", "- else:", "- r = (r - k + npc) % npc", "- ans[i] = f(r) + 1", "- k = (k * 2) % npc", "-for i in ans:", "- print(i)", "+ r_mi = (r_mi * 2) % pc_mi", "+print(*ans, sep=\"\\n\")" ]
false
0.038219
0.037427
1.021152
[ "s150079668", "s124096300" ]
u604774382
p02422
python
s254369768
s151643364
40
20
6,724
4,236
Accepted
Accepted
50
s = list( eval(input( )) ) n = int( eval(input( )) ) for i in range( n ): cmd = input( ).split( " " ) a = int( cmd[1] ) b = int( cmd[2] ) + 1 if "print" == cmd[0]: print(( "".join( s[ a:b ] ) )) elif "reverse" == cmd[0]: for i in reversed( s[ a:b ] ): s[ a ] = i a += 1 elif "replace" == cmd[0]: for i in cmd[3]: s[ a ] = i a += 1
s = list( input( ) ) n = int( input( ) ) for i in range( n ): cmd = input( ).split( " " ) a = int( cmd[1] ) b = int( cmd[2] ) + 1 if "print" == cmd[0]: print(( "".join( s[ a:b ] ) )) elif "reverse" == cmd[0]: for i, ss in enumerate( reversed( s[ a:b ] ) ): s[ a+i ] = ss elif "replace" == cmd[0]: for i, ss in enumerate( cmd[3] ): s[ a+i ] = ss
16
14
355
385
s = list(eval(input())) n = int(eval(input())) for i in range(n): cmd = input().split(" ") a = int(cmd[1]) b = int(cmd[2]) + 1 if "print" == cmd[0]: print(("".join(s[a:b]))) elif "reverse" == cmd[0]: for i in reversed(s[a:b]): s[a] = i a += 1 elif "replace" == cmd[0]: for i in cmd[3]: s[a] = i a += 1
s = list(input()) n = int(input()) for i in range(n): cmd = input().split(" ") a = int(cmd[1]) b = int(cmd[2]) + 1 if "print" == cmd[0]: print(("".join(s[a:b]))) elif "reverse" == cmd[0]: for i, ss in enumerate(reversed(s[a:b])): s[a + i] = ss elif "replace" == cmd[0]: for i, ss in enumerate(cmd[3]): s[a + i] = ss
false
12.5
[ "-s = list(eval(input()))", "-n = int(eval(input()))", "+s = list(input())", "+n = int(input())", "- for i in reversed(s[a:b]):", "- s[a] = i", "- a += 1", "+ for i, ss in enumerate(reversed(s[a:b])):", "+ s[a + i] = ss", "- for i in cmd[3]:", "- s[a] = i", "- a += 1", "+ for i, ss in enumerate(cmd[3]):", "+ s[a + i] = ss" ]
false
0.035819
0.037479
0.955708
[ "s254369768", "s151643364" ]
u597374218
p03834
python
s235016294
s383875907
31
25
8,884
9,000
Accepted
Accepted
19.35
s=eval(input()) print((*s.split(",")))
s=input().split(",") print((*s))
2
2
31
31
s = eval(input()) print((*s.split(",")))
s = input().split(",") print((*s))
false
0
[ "-s = eval(input())", "-print((*s.split(\",\")))", "+s = input().split(\",\")", "+print((*s))" ]
false
0.040308
0.037305
1.080503
[ "s235016294", "s383875907" ]
u374103100
p02925
python
s680954867
s040026085
1,665
563
53,592
57,692
Accepted
Accepted
66.19
# import sys import time def input(): return sys.stdin.readline().strip() def main(): n = int(eval(input())) agrid = [] agrid_pointer = [0] * n start = time.time() for i in range(n): al = list(map(int, input().split())) agrid.append(al) ans = 0 while True: match = set() for i in range(n): if agrid_pointer[i] == n - 1 or i in match: # もう全部対戦済み or この日対戦済み continue target = agrid[i][agrid_pointer[i]] - 1 if agrid_pointer[target] == n - 1 or target in match: # もう全部対戦済み or この日対戦済み continue # i, target は対戦可能 if agrid[target][agrid_pointer[target]] - 1 != i: continue # can match agrid_pointer[i] += 1 agrid_pointer[target] += 1 match.add(i) match.add(target) if len(match) == n or len(match) == n - 1: # 全員試合することが決まったら break # print(match) if len(match) == 0: # 対戦がなくなったら break elapsed_time = time.time() - start if elapsed_time > 1.5: print((n * (n-1)//2)) return ans += 1 # print(aconditions) # 対戦が残ってたら for p in agrid_pointer: if p != n - 1: print((-1)) return print(ans) if __name__ == '__main__': main()
# import sys from collections import deque def input(): return sys.stdin.readline().strip() def main(): n = int(eval(input())) agrid = [] agrid_pointer = [0] * n for i in range(n): al = list(map(int, input().split())) for j in range(len(al)): al[j] -= 1 agrid.append(al) ans = 0 def find_next(idx, q, m): if agrid_pointer[idx] == n - 1 or i in m: # もう全部対戦済み or この日対戦済み return target = agrid[idx][agrid_pointer[idx]] if agrid_pointer[target] == n - 1 or target in m: # もう全部対戦済み or この日対戦済み return if agrid[target][agrid_pointer[target]] != idx: return q.append((idx, target)) m.add(idx) m.add(target) que = deque() first_matching = set() for i in range(n): find_next(i, que, first_matching) while que: ans += 1 changed = [] while que: i, j = que.popleft() agrid_pointer[i] += 1 agrid_pointer[j] += 1 changed.append(i) changed.append(j) next_que = deque() match = set() for i in changed: find_next(i, next_que, match) # print(match) que = next_que # print(aconditions) # 対戦が残ってたら for p in agrid_pointer: if p != n - 1: print((-1)) return print(ans) if __name__ == '__main__': main()
64
69
1,466
1,522
# import sys import time def input(): return sys.stdin.readline().strip() def main(): n = int(eval(input())) agrid = [] agrid_pointer = [0] * n start = time.time() for i in range(n): al = list(map(int, input().split())) agrid.append(al) ans = 0 while True: match = set() for i in range(n): if agrid_pointer[i] == n - 1 or i in match: # もう全部対戦済み or この日対戦済み continue target = agrid[i][agrid_pointer[i]] - 1 if agrid_pointer[target] == n - 1 or target in match: # もう全部対戦済み or この日対戦済み continue # i, target は対戦可能 if agrid[target][agrid_pointer[target]] - 1 != i: continue # can match agrid_pointer[i] += 1 agrid_pointer[target] += 1 match.add(i) match.add(target) if len(match) == n or len(match) == n - 1: # 全員試合することが決まったら break # print(match) if len(match) == 0: # 対戦がなくなったら break elapsed_time = time.time() - start if elapsed_time > 1.5: print((n * (n - 1) // 2)) return ans += 1 # print(aconditions) # 対戦が残ってたら for p in agrid_pointer: if p != n - 1: print((-1)) return print(ans) if __name__ == "__main__": main()
# import sys from collections import deque def input(): return sys.stdin.readline().strip() def main(): n = int(eval(input())) agrid = [] agrid_pointer = [0] * n for i in range(n): al = list(map(int, input().split())) for j in range(len(al)): al[j] -= 1 agrid.append(al) ans = 0 def find_next(idx, q, m): if agrid_pointer[idx] == n - 1 or i in m: # もう全部対戦済み or この日対戦済み return target = agrid[idx][agrid_pointer[idx]] if agrid_pointer[target] == n - 1 or target in m: # もう全部対戦済み or この日対戦済み return if agrid[target][agrid_pointer[target]] != idx: return q.append((idx, target)) m.add(idx) m.add(target) que = deque() first_matching = set() for i in range(n): find_next(i, que, first_matching) while que: ans += 1 changed = [] while que: i, j = que.popleft() agrid_pointer[i] += 1 agrid_pointer[j] += 1 changed.append(i) changed.append(j) next_que = deque() match = set() for i in changed: find_next(i, next_que, match) # print(match) que = next_que # print(aconditions) # 対戦が残ってたら for p in agrid_pointer: if p != n - 1: print((-1)) return print(ans) if __name__ == "__main__": main()
false
7.246377
[ "-import time", "+from collections import deque", "- start = time.time()", "+ for j in range(len(al)):", "+ al[j] -= 1", "- while True:", "+", "+ def find_next(idx, q, m):", "+ if agrid_pointer[idx] == n - 1 or i in m: # もう全部対戦済み or この日対戦済み", "+ return", "+ target = agrid[idx][agrid_pointer[idx]]", "+ if agrid_pointer[target] == n - 1 or target in m: # もう全部対戦済み or この日対戦済み", "+ return", "+ if agrid[target][agrid_pointer[target]] != idx:", "+ return", "+ q.append((idx, target))", "+ m.add(idx)", "+ m.add(target)", "+", "+ que = deque()", "+ first_matching = set()", "+ for i in range(n):", "+ find_next(i, que, first_matching)", "+ while que:", "+ ans += 1", "+ changed = []", "+ while que:", "+ i, j = que.popleft()", "+ agrid_pointer[i] += 1", "+ agrid_pointer[j] += 1", "+ changed.append(i)", "+ changed.append(j)", "+ next_que = deque()", "- for i in range(n):", "- if agrid_pointer[i] == n - 1 or i in match: # もう全部対戦済み or この日対戦済み", "- continue", "- target = agrid[i][agrid_pointer[i]] - 1", "- if agrid_pointer[target] == n - 1 or target in match: # もう全部対戦済み or この日対戦済み", "- continue", "- # i, target は対戦可能", "- if agrid[target][agrid_pointer[target]] - 1 != i:", "- continue", "- # can match", "- agrid_pointer[i] += 1", "- agrid_pointer[target] += 1", "- match.add(i)", "- match.add(target)", "- if len(match) == n or len(match) == n - 1: # 全員試合することが決まったら", "- break", "+ for i in changed:", "+ find_next(i, next_que, match)", "- if len(match) == 0: # 対戦がなくなったら", "- break", "- elapsed_time = time.time() - start", "- if elapsed_time > 1.5:", "- print((n * (n - 1) // 2))", "- return", "- ans += 1", "+ que = next_que" ]
false
0.064552
0.111715
0.577826
[ "s680954867", "s040026085" ]
u565204025
p03478
python
s386986623
s610024048
237
39
42,972
3,060
Accepted
Accepted
83.54
# -*- coding: utf-8 -*- n,a,b = list(map(int,input().split())) answer = 0 for i in range(n+1): nc = list(str(i)) nc = list(map(int,nc)) ncsum = sum(nc) nc = list(map(str,nc)) nc = int("".join(nc)) if a <= ncsum and b >= ncsum: answer += nc print(answer)
# -*- coding: utf-8 -*- n,a,b = list(map(int,input().split())) def digit_list(num): num = str(num) num = list(num) num = list(map(int,num)) return num cnt = 0 for i in range(1,n+1): temp = sum(digit_list(i)) if a <= temp <= b: cnt += i print(cnt)
16
18
299
295
# -*- coding: utf-8 -*- n, a, b = list(map(int, input().split())) answer = 0 for i in range(n + 1): nc = list(str(i)) nc = list(map(int, nc)) ncsum = sum(nc) nc = list(map(str, nc)) nc = int("".join(nc)) if a <= ncsum and b >= ncsum: answer += nc print(answer)
# -*- coding: utf-8 -*- n, a, b = list(map(int, input().split())) def digit_list(num): num = str(num) num = list(num) num = list(map(int, num)) return num cnt = 0 for i in range(1, n + 1): temp = sum(digit_list(i)) if a <= temp <= b: cnt += i print(cnt)
false
11.111111
[ "-answer = 0", "-for i in range(n + 1):", "- nc = list(str(i))", "- nc = list(map(int, nc))", "- ncsum = sum(nc)", "- nc = list(map(str, nc))", "- nc = int(\"\".join(nc))", "- if a <= ncsum and b >= ncsum:", "- answer += nc", "-print(answer)", "+", "+", "+def digit_list(num):", "+ num = str(num)", "+ num = list(num)", "+ num = list(map(int, num))", "+ return num", "+", "+", "+cnt = 0", "+for i in range(1, n + 1):", "+ temp = sum(digit_list(i))", "+ if a <= temp <= b:", "+ cnt += i", "+print(cnt)" ]
false
0.039149
0.034983
1.11909
[ "s386986623", "s610024048" ]
u832039789
p03076
python
s996997765
s812054997
263
188
64,364
38,256
Accepted
Accepted
28.52
import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from itertools import combinations as comb from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) def y(f): if f: print('Yes') else: print('No') def Y(f): if f: print('YES') else: print('NO') def Z(f): if f: print('Yay!') else: print(':(') def ispow(n): if int(n**.5)**2==n: return True return False l = [int(eval(input())) for _ in range(5)] res = 10 ** 100 for p in perm(list(range(5))): cur = 0 for i in p: cur = (cur + 9) // 10 * 10 cur += l[i] res = min(res, cur) print(res)
from itertools import permutations as perm l = [int(eval(input())) for _ in range(5)] res = 10 ** 100 for p in perm(l): tmp = 0 for i in p: tmp = (tmp + 9) // 10 * 10 tmp += i res = min(res, tmp) print(res)
38
11
798
239
import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from itertools import combinations as comb from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) def y(f): if f: print("Yes") else: print("No") def Y(f): if f: print("YES") else: print("NO") def Z(f): if f: print("Yay!") else: print(":(") def ispow(n): if int(n**0.5) ** 2 == n: return True return False l = [int(eval(input())) for _ in range(5)] res = 10**100 for p in perm(list(range(5))): cur = 0 for i in p: cur = (cur + 9) // 10 * 10 cur += l[i] res = min(res, cur) print(res)
from itertools import permutations as perm l = [int(eval(input())) for _ in range(5)] res = 10**100 for p in perm(l): tmp = 0 for i in p: tmp = (tmp + 9) // 10 * 10 tmp += i res = min(res, tmp) print(res)
false
71.052632
[ "-import sys", "-from fractions import gcd", "-from itertools import groupby as gb", "-from itertools import combinations as comb", "-from collections import Counter as C", "-from collections import defaultdict as dd", "-", "-sys.setrecursionlimit(10**5)", "-", "-", "-def y(f):", "- if f:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "-", "-", "-def Y(f):", "- if f:", "- print(\"YES\")", "- else:", "- print(\"NO\")", "-", "-", "-def Z(f):", "- if f:", "- print(\"Yay!\")", "- else:", "- print(\":(\")", "-", "-", "-def ispow(n):", "- if int(n**0.5) ** 2 == n:", "- return True", "- return False", "-", "-for p in perm(list(range(5))):", "- cur = 0", "+for p in perm(l):", "+ tmp = 0", "- cur = (cur + 9) // 10 * 10", "- cur += l[i]", "- res = min(res, cur)", "+ tmp = (tmp + 9) // 10 * 10", "+ tmp += i", "+ res = min(res, tmp)" ]
false
0.049394
0.046216
1.068778
[ "s996997765", "s812054997" ]
u886633618
p03044
python
s918025750
s628494182
823
701
108,960
81,300
Accepted
Accepted
14.82
N = int(eval(input())) node_array = [list(map(int, input().split())) for i in range(N - 1)] # print(node_array) tree_num_array = [-1] * N # print(tree_num_array) tree_num_max = -1 tree = {} last_tree_num = -1 for node in node_array: # print(tree) i, j, w = node i = i - 1 j = j - 1 if tree_num_array[i] == -1 and tree_num_array[j] == -1: # print(i, j, "added") tree_num_max += 1 tree[tree_num_max] = {i: 0, j: w} tree_num_array[i] = tree_num_max tree_num_array[j] = tree_num_max last_tree_num = tree_num_max continue elif tree_num_array[i] == -1: # print(i, "added") tree_num_added = tree_num_array[j] tree[tree_num_added][i] = tree[tree_num_added][j] + w tree_num_array[i] = tree_num_added last_tree_num = tree_num_added elif tree_num_array[j] == -1: # print(j, "added") tree_num_added = tree_num_array[i] tree[tree_num_added][j] = tree[tree_num_added][i] + w tree_num_array[j] = tree_num_added last_tree_num = tree_num_added else: tree_num_i = tree_num_array[i] tree_num_j = tree_num_array[j] # print(tree_num_i, tree_num_j, "unite") if len(tree[tree_num_i]) > len(tree[tree_num_j]): tree_main_num = tree_num_i tree_main_value = tree[tree_main_num][i] tree_sub_num = tree_num_j tree_sub_value = tree[tree_sub_num][j] else: tree_main_num = tree_num_j tree_main_value = tree[tree_main_num][j] tree_sub_num = tree_num_i tree_sub_value = tree[tree_sub_num][i] for key, value in list(tree[tree_sub_num].items()): tree[tree_main_num][ key] = tree_main_value + w + abs(value - tree_sub_value) tree_num_array[int(key)] = tree_main_num last_tree_num = tree_main_num # print(tree) ans_dict = sorted(list(tree[last_tree_num].items()), key=lambda x: int(x[0])) # print(ans_dict) for distance in ans_dict: print((distance[1] % 2))
from sys import setrecursionlimit setrecursionlimit(10**8) def dfs(i, d): # print(i, d) for j, w in node_array[i]: if color_array[j] == -1: color_array[j] = (d + w) % 2 dfs(j, d + w) N = int(eval(input())) node_array = [[] for i in range(N)] color_array = [-1] * N for _ in range(N - 1): i, j, w = list(map(int, input().split())) node_array[i - 1].append((j - 1, w)) node_array[j - 1].append((i - 1, w)) color_array[0] = 0 dfs(0, 0) for i in range(N): print((color_array[i]))
59
26
2,124
550
N = int(eval(input())) node_array = [list(map(int, input().split())) for i in range(N - 1)] # print(node_array) tree_num_array = [-1] * N # print(tree_num_array) tree_num_max = -1 tree = {} last_tree_num = -1 for node in node_array: # print(tree) i, j, w = node i = i - 1 j = j - 1 if tree_num_array[i] == -1 and tree_num_array[j] == -1: # print(i, j, "added") tree_num_max += 1 tree[tree_num_max] = {i: 0, j: w} tree_num_array[i] = tree_num_max tree_num_array[j] = tree_num_max last_tree_num = tree_num_max continue elif tree_num_array[i] == -1: # print(i, "added") tree_num_added = tree_num_array[j] tree[tree_num_added][i] = tree[tree_num_added][j] + w tree_num_array[i] = tree_num_added last_tree_num = tree_num_added elif tree_num_array[j] == -1: # print(j, "added") tree_num_added = tree_num_array[i] tree[tree_num_added][j] = tree[tree_num_added][i] + w tree_num_array[j] = tree_num_added last_tree_num = tree_num_added else: tree_num_i = tree_num_array[i] tree_num_j = tree_num_array[j] # print(tree_num_i, tree_num_j, "unite") if len(tree[tree_num_i]) > len(tree[tree_num_j]): tree_main_num = tree_num_i tree_main_value = tree[tree_main_num][i] tree_sub_num = tree_num_j tree_sub_value = tree[tree_sub_num][j] else: tree_main_num = tree_num_j tree_main_value = tree[tree_main_num][j] tree_sub_num = tree_num_i tree_sub_value = tree[tree_sub_num][i] for key, value in list(tree[tree_sub_num].items()): tree[tree_main_num][key] = tree_main_value + w + abs(value - tree_sub_value) tree_num_array[int(key)] = tree_main_num last_tree_num = tree_main_num # print(tree) ans_dict = sorted(list(tree[last_tree_num].items()), key=lambda x: int(x[0])) # print(ans_dict) for distance in ans_dict: print((distance[1] % 2))
from sys import setrecursionlimit setrecursionlimit(10**8) def dfs(i, d): # print(i, d) for j, w in node_array[i]: if color_array[j] == -1: color_array[j] = (d + w) % 2 dfs(j, d + w) N = int(eval(input())) node_array = [[] for i in range(N)] color_array = [-1] * N for _ in range(N - 1): i, j, w = list(map(int, input().split())) node_array[i - 1].append((j - 1, w)) node_array[j - 1].append((i - 1, w)) color_array[0] = 0 dfs(0, 0) for i in range(N): print((color_array[i]))
false
55.932203
[ "+from sys import setrecursionlimit", "+", "+setrecursionlimit(10**8)", "+", "+", "+def dfs(i, d):", "+ # print(i, d)", "+ for j, w in node_array[i]:", "+ if color_array[j] == -1:", "+ color_array[j] = (d + w) % 2", "+ dfs(j, d + w)", "+", "+", "-node_array = [list(map(int, input().split())) for i in range(N - 1)]", "-# print(node_array)", "-tree_num_array = [-1] * N", "-# print(tree_num_array)", "-tree_num_max = -1", "-tree = {}", "-last_tree_num = -1", "-for node in node_array:", "- # print(tree)", "- i, j, w = node", "- i = i - 1", "- j = j - 1", "- if tree_num_array[i] == -1 and tree_num_array[j] == -1:", "- # print(i, j, \"added\")", "- tree_num_max += 1", "- tree[tree_num_max] = {i: 0, j: w}", "- tree_num_array[i] = tree_num_max", "- tree_num_array[j] = tree_num_max", "- last_tree_num = tree_num_max", "- continue", "- elif tree_num_array[i] == -1:", "- # print(i, \"added\")", "- tree_num_added = tree_num_array[j]", "- tree[tree_num_added][i] = tree[tree_num_added][j] + w", "- tree_num_array[i] = tree_num_added", "- last_tree_num = tree_num_added", "- elif tree_num_array[j] == -1:", "- # print(j, \"added\")", "- tree_num_added = tree_num_array[i]", "- tree[tree_num_added][j] = tree[tree_num_added][i] + w", "- tree_num_array[j] = tree_num_added", "- last_tree_num = tree_num_added", "- else:", "- tree_num_i = tree_num_array[i]", "- tree_num_j = tree_num_array[j]", "- # print(tree_num_i, tree_num_j, \"unite\")", "- if len(tree[tree_num_i]) > len(tree[tree_num_j]):", "- tree_main_num = tree_num_i", "- tree_main_value = tree[tree_main_num][i]", "- tree_sub_num = tree_num_j", "- tree_sub_value = tree[tree_sub_num][j]", "- else:", "- tree_main_num = tree_num_j", "- tree_main_value = tree[tree_main_num][j]", "- tree_sub_num = tree_num_i", "- tree_sub_value = tree[tree_sub_num][i]", "- for key, value in list(tree[tree_sub_num].items()):", "- tree[tree_main_num][key] = tree_main_value + w + abs(value - tree_sub_value)", "- tree_num_array[int(key)] = tree_main_num", "- last_tree_num = tree_main_num", "-# print(tree)", "-ans_dict = sorted(list(tree[last_tree_num].items()), key=lambda x: int(x[0]))", "-# print(ans_dict)", "-for distance in ans_dict:", "- print((distance[1] % 2))", "+node_array = [[] for i in range(N)]", "+color_array = [-1] * N", "+for _ in range(N - 1):", "+ i, j, w = list(map(int, input().split()))", "+ node_array[i - 1].append((j - 1, w))", "+ node_array[j - 1].append((i - 1, w))", "+color_array[0] = 0", "+dfs(0, 0)", "+for i in range(N):", "+ print((color_array[i]))" ]
false
0.043258
0.044594
0.970032
[ "s918025750", "s628494182" ]
u203843959
p03964
python
s248103195
s295946496
39
20
5,052
3,064
Accepted
Accepted
48.72
import fractions N=int(eval(input())) vt=va=0 for _ in range(N): T,A=list(map(int,input().split())) kt=-(-vt//T) ka=-(-va//A) if kt==0 and ka==0: vt=T va=A else: k=max(kt,ka) vt=k*T va=k*A #print(vt,va) print((vt+va))
N=int(eval(input())) vt=va=0 for _ in range(N): T,A=list(map(int,input().split())) kt=-(-vt//T) ka=-(-va//A) k=max(kt,ka,1) vt=k*T va=k*A #print(vt,va) print((vt+va))
19
14
260
188
import fractions N = int(eval(input())) vt = va = 0 for _ in range(N): T, A = list(map(int, input().split())) kt = -(-vt // T) ka = -(-va // A) if kt == 0 and ka == 0: vt = T va = A else: k = max(kt, ka) vt = k * T va = k * A # print(vt,va) print((vt + va))
N = int(eval(input())) vt = va = 0 for _ in range(N): T, A = list(map(int, input().split())) kt = -(-vt // T) ka = -(-va // A) k = max(kt, ka, 1) vt = k * T va = k * A # print(vt,va) print((vt + va))
false
26.315789
[ "-import fractions", "-", "- if kt == 0 and ka == 0:", "- vt = T", "- va = A", "- else:", "- k = max(kt, ka)", "- vt = k * T", "- va = k * A", "+ k = max(kt, ka, 1)", "+ vt = k * T", "+ va = k * A" ]
false
0.088578
0.063172
1.402168
[ "s248103195", "s295946496" ]
u587821863
p00491
python
s623849898
s965715061
40
30
6,760
6,752
Accepted
Accepted
25
#f = open("input.txt") #N, K = [int(x) for x in f.readline().split(' ')] #lines = f.readlines() #f.close() import sys N, K = [int(x) for x in sys.stdin.readline().split(' ')] lines = sys.stdin.readlines() schedule = [0]*N for line in lines: strs = line.split(' ') schedule[int(strs[0])-1] = int(strs[1]) number = [0]*9 for i in range(9): l1 = i // 3 l2 = i % 3 if(schedule[0]!=l2+1 and schedule[0]!=0): number[i] = 0 elif(schedule[1]!=l1+1 and schedule[1]!=0): number[i] = 0 else: number[i] = 1 for s in schedule[2:]: new_number = [0]*9 for i in range(9): l1 = i // 3 l2 = i % 3 for j in range(3): new_number[i] += number[l2*3 + j] if((s==0 or s==l1+1) and not (l2==j and l1==j)) else 0 for i in range(9): number[i] = new_number[i] % 10000 sum = 0 for n in number: sum += n print((sum % 10000))
#f = open("input.txt") #N, K = [int(x) for x in f.readline().split(' ')] #lines = f.readlines() #f.close() from sys import stdin N, K = [int(x) for x in stdin.readline().split(' ')] lines = stdin.readlines() schedule = [0]*N for line in lines: strs = line.split(' ') schedule[int(strs[0])-1] = int(strs[1]) number = [1]*9 for i in range(9): l1 = i // 3 l2 = i % 3 if schedule[0]!=l2+1 and schedule[0]!=0: number[i] = 0 elif schedule[1]!=l1+1 and schedule[1]!=0: number[i] = 0 for s in schedule[2:]: tmp = [0]*9 for i in range(9): l1 = i // 3 l2 = i % 3 tmp[i] = [number[l2*3+j] for j in range(3) \ if (s==0 or s==l1+1) and not (l2==j and l1==j)] for i in range(9): number[i] = sum(tmp[i]) print((sum(number) % 10000))
39
32
948
846
# f = open("input.txt") # N, K = [int(x) for x in f.readline().split(' ')] # lines = f.readlines() # f.close() import sys N, K = [int(x) for x in sys.stdin.readline().split(" ")] lines = sys.stdin.readlines() schedule = [0] * N for line in lines: strs = line.split(" ") schedule[int(strs[0]) - 1] = int(strs[1]) number = [0] * 9 for i in range(9): l1 = i // 3 l2 = i % 3 if schedule[0] != l2 + 1 and schedule[0] != 0: number[i] = 0 elif schedule[1] != l1 + 1 and schedule[1] != 0: number[i] = 0 else: number[i] = 1 for s in schedule[2:]: new_number = [0] * 9 for i in range(9): l1 = i // 3 l2 = i % 3 for j in range(3): new_number[i] += ( number[l2 * 3 + j] if ((s == 0 or s == l1 + 1) and not (l2 == j and l1 == j)) else 0 ) for i in range(9): number[i] = new_number[i] % 10000 sum = 0 for n in number: sum += n print((sum % 10000))
# f = open("input.txt") # N, K = [int(x) for x in f.readline().split(' ')] # lines = f.readlines() # f.close() from sys import stdin N, K = [int(x) for x in stdin.readline().split(" ")] lines = stdin.readlines() schedule = [0] * N for line in lines: strs = line.split(" ") schedule[int(strs[0]) - 1] = int(strs[1]) number = [1] * 9 for i in range(9): l1 = i // 3 l2 = i % 3 if schedule[0] != l2 + 1 and schedule[0] != 0: number[i] = 0 elif schedule[1] != l1 + 1 and schedule[1] != 0: number[i] = 0 for s in schedule[2:]: tmp = [0] * 9 for i in range(9): l1 = i // 3 l2 = i % 3 tmp[i] = [ number[l2 * 3 + j] for j in range(3) if (s == 0 or s == l1 + 1) and not (l2 == j and l1 == j) ] for i in range(9): number[i] = sum(tmp[i]) print((sum(number) % 10000))
false
17.948718
[ "-import sys", "+from sys import stdin", "-N, K = [int(x) for x in sys.stdin.readline().split(\" \")]", "-lines = sys.stdin.readlines()", "+N, K = [int(x) for x in stdin.readline().split(\" \")]", "+lines = stdin.readlines()", "-number = [0] * 9", "+number = [1] * 9", "- else:", "- number[i] = 1", "- new_number = [0] * 9", "+ tmp = [0] * 9", "- for j in range(3):", "- new_number[i] += (", "- number[l2 * 3 + j]", "- if ((s == 0 or s == l1 + 1) and not (l2 == j and l1 == j))", "- else 0", "- )", "+ tmp[i] = [", "+ number[l2 * 3 + j]", "+ for j in range(3)", "+ if (s == 0 or s == l1 + 1) and not (l2 == j and l1 == j)", "+ ]", "- number[i] = new_number[i] % 10000", "-sum = 0", "-for n in number:", "- sum += n", "-print((sum % 10000))", "+ number[i] = sum(tmp[i])", "+print((sum(number) % 10000))" ]
false
0.037957
0.036973
1.026619
[ "s623849898", "s965715061" ]
u729133443
p03062
python
s801341909
s354026353
277
185
74,016
26,192
Accepted
Accepted
33.21
_,a=open(0);b,c=list(zip(*[(abs(i),i<0)for i in map(int,a.split())]));print((sum(b)-sum(c)%2*min(b)*2))
from numpy import*;_,a=open(0);a=int64(a.split());b=abs(a);print((sum(b)-sum(a<0)%2*min(b)*2))
1
1
95
92
_, a = open(0) b, c = list(zip(*[(abs(i), i < 0) for i in map(int, a.split())])) print((sum(b) - sum(c) % 2 * min(b) * 2))
from numpy import * _, a = open(0) a = int64(a.split()) b = abs(a) print((sum(b) - sum(a < 0) % 2 * min(b) * 2))
false
0
[ "+from numpy import *", "+", "-b, c = list(zip(*[(abs(i), i < 0) for i in map(int, a.split())]))", "-print((sum(b) - sum(c) % 2 * min(b) * 2))", "+a = int64(a.split())", "+b = abs(a)", "+print((sum(b) - sum(a < 0) % 2 * min(b) * 2))" ]
false
0.036573
0.512492
0.071363
[ "s801341909", "s354026353" ]
u241159583
p03331
python
s376445321
s947338773
212
156
3,060
9,212
Accepted
Accepted
26.42
n = int(eval(input())) N = n//2 ans = float("INF") for i in range(1,N+1): a,b = list(str(i)), list(str(n-i)) A,B = sum(list(map(int, a))), sum(list(map(int, b))) if ans > A+B: ans = A+B print(ans)
n = int(eval(input())) ans = 10**5+1 for a in range(1, n//2+1): a,b = list(str(a)), list(str(n-a)) ans = min(ans, sum(list(map(int, a)))+sum(list(map(int, b)))) print(ans)
8
6
203
178
n = int(eval(input())) N = n // 2 ans = float("INF") for i in range(1, N + 1): a, b = list(str(i)), list(str(n - i)) A, B = sum(list(map(int, a))), sum(list(map(int, b))) if ans > A + B: ans = A + B print(ans)
n = int(eval(input())) ans = 10**5 + 1 for a in range(1, n // 2 + 1): a, b = list(str(a)), list(str(n - a)) ans = min(ans, sum(list(map(int, a))) + sum(list(map(int, b)))) print(ans)
false
25
[ "-N = n // 2", "-ans = float(\"INF\")", "-for i in range(1, N + 1):", "- a, b = list(str(i)), list(str(n - i))", "- A, B = sum(list(map(int, a))), sum(list(map(int, b)))", "- if ans > A + B:", "- ans = A + B", "+ans = 10**5 + 1", "+for a in range(1, n // 2 + 1):", "+ a, b = list(str(a)), list(str(n - a))", "+ ans = min(ans, sum(list(map(int, a))) + sum(list(map(int, b))))" ]
false
0.088012
0.086559
1.01679
[ "s376445321", "s947338773" ]
u753803401
p03645
python
s646431710
s613820090
512
388
80,604
78,172
Accepted
Accepted
24.22
import sys import collections def solve(): sys.setrecursionlimit(2000) input = sys.stdin.readline mod = 10 ** 9 + 7 n, m = list(map(int, input().rstrip('\n').split())) d = collections.defaultdict(list) for i in range(m): a, b = list(map(int, input().rstrip('\n').split())) if a == 1: d[b] += [1] if b == 1: d[a] += [1] if a == n: d[b] += [n] if b == n: d[a] += [n] for k, v in list(d.items()): if len(v) == 2: print("POSSIBLE") exit() print("IMPOSSIBLE") if __name__ == '__main__': solve()
import sys import collections def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, m = list(map(int, readline().split())) d = collections.defaultdict(list) for _ in range(m): a, b = list(map(int, readline().split())) if a == 1 or a == n: if a not in d[b]: d[b] += [a] elif b == 1 or b == n: if b not in d[a]: d[a] += [b] for k, v in list(d.items()): if k != 1 and k != n: if len(v) == 2: print("POSSIBLE") exit() print("IMPOSSIBLE") if __name__ == '__main__': solve()
29
27
672
674
import sys import collections def solve(): sys.setrecursionlimit(2000) input = sys.stdin.readline mod = 10**9 + 7 n, m = list(map(int, input().rstrip("\n").split())) d = collections.defaultdict(list) for i in range(m): a, b = list(map(int, input().rstrip("\n").split())) if a == 1: d[b] += [1] if b == 1: d[a] += [1] if a == n: d[b] += [n] if b == n: d[a] += [n] for k, v in list(d.items()): if len(v) == 2: print("POSSIBLE") exit() print("IMPOSSIBLE") if __name__ == "__main__": solve()
import sys import collections def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n, m = list(map(int, readline().split())) d = collections.defaultdict(list) for _ in range(m): a, b = list(map(int, readline().split())) if a == 1 or a == n: if a not in d[b]: d[b] += [a] elif b == 1 or b == n: if b not in d[a]: d[a] += [b] for k, v in list(d.items()): if k != 1 and k != n: if len(v) == 2: print("POSSIBLE") exit() print("IMPOSSIBLE") if __name__ == "__main__": solve()
false
6.896552
[ "- sys.setrecursionlimit(2000)", "- input = sys.stdin.readline", "+ readline = sys.stdin.buffer.readline", "- n, m = list(map(int, input().rstrip(\"\\n\").split()))", "+ n, m = list(map(int, readline().split()))", "- for i in range(m):", "- a, b = list(map(int, input().rstrip(\"\\n\").split()))", "- if a == 1:", "- d[b] += [1]", "- if b == 1:", "- d[a] += [1]", "- if a == n:", "- d[b] += [n]", "- if b == n:", "- d[a] += [n]", "+ for _ in range(m):", "+ a, b = list(map(int, readline().split()))", "+ if a == 1 or a == n:", "+ if a not in d[b]:", "+ d[b] += [a]", "+ elif b == 1 or b == n:", "+ if b not in d[a]:", "+ d[a] += [b]", "- if len(v) == 2:", "- print(\"POSSIBLE\")", "- exit()", "+ if k != 1 and k != n:", "+ if len(v) == 2:", "+ print(\"POSSIBLE\")", "+ exit()" ]
false
0.120293
0.038027
3.163323
[ "s646431710", "s613820090" ]
u448994613
p02615
python
s087636238
s260336087
1,162
478
117,752
117,552
Accepted
Accepted
58.86
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import itertools import random from collections import deque from decimal import * import queue input = sys.stdin.readline def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) def inputStr(): return input()[:-1] inf = float('inf') mod = 1000000007 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): N = inputInt() A = inputList() A.sort() A = A[::-1] ans = 0 maxs = 0 cnt = 0 fst = True ansans = [] pgt = queue.Queue() for i,val in enumerate(A): if i == 0: pgt.put(val) else: tmp = pgt.get() ansans.append(tmp) pgt.put(val) if tmp == val: pgt.put(val) else: pgt.put(val) #print(ansans) print((sum(ansans))) #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import itertools import random from collections import deque from decimal import * import queue input = sys.stdin.readline def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) def inputStr(): return input()[:-1] inf = float('inf') mod = 1000000007 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): N = inputInt() A = inputList() A.sort() A = A[::-1] ans = 0 maxs = 0 cnt = 0 fst = True ansans = [] pgt = queue.Queue() for i,val in enumerate(A): if i == 0: pgt.put(val) else: tmp = pgt.get() ansans.append(tmp) pgt.put(val) pgt.put(val) print((sum(ansans))) #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- if __name__ == "__main__": main()
61
55
1,222
1,153
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import itertools import random from collections import deque from decimal import * import queue input = sys.stdin.readline def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) def inputStr(): return input()[:-1] inf = float("inf") mod = 1000000007 # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): N = inputInt() A = inputList() A.sort() A = A[::-1] ans = 0 maxs = 0 cnt = 0 fst = True ansans = [] pgt = queue.Queue() for i, val in enumerate(A): if i == 0: pgt.put(val) else: tmp = pgt.get() ansans.append(tmp) pgt.put(val) if tmp == val: pgt.put(val) else: pgt.put(val) # print(ansans) print((sum(ansans))) # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import itertools import random from collections import deque from decimal import * import queue input = sys.stdin.readline def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) def inputStr(): return input()[:-1] inf = float("inf") mod = 1000000007 # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): N = inputInt() A = inputList() A.sort() A = A[::-1] ans = 0 maxs = 0 cnt = 0 fst = True ansans = [] pgt = queue.Queue() for i, val in enumerate(A): if i == 0: pgt.put(val) else: tmp = pgt.get() ansans.append(tmp) pgt.put(val) pgt.put(val) print((sum(ansans))) # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- if __name__ == "__main__": main()
false
9.836066
[ "- if tmp == val:", "- pgt.put(val)", "- else:", "- pgt.put(val)", "- # print(ansans)", "+ pgt.put(val)" ]
false
0.039367
0.046753
0.842019
[ "s087636238", "s260336087" ]
u796060588
p03479
python
s697093939
s736924068
949
17
2,568
3,192
Accepted
Accepted
98.21
# vim: set fileencoding=utf-8: """ X,Yの区間は[1, pow(10,18)]であり、全探索すると日が暮れる。 厳密には、区間[X, Y]のすべてを検証する必要はないはずで、 [X, 2*X]でいいはずである。たぶん。 """ def main(): X, Y = list(map(int, input().split())) ans = 0 temp = 0 X2 = 2 * X ct = 0 for i, _ in enumerate(range(X2), X): ct += 1 n = i while n <= Y: temp += 1 n *= 2 ans = max(ans, temp) temp = 0 if ct == 400000: break print(ans) if __name__ == "__main__": main()
#!/usr/bin/python3 # vim: set fileencoding=utf-8: import sys input = sys.stdin.readline """ H = int(input()) h = [int(ele) for ele in input().split()] h = [0] + h """ def main(): A = [] X, Y = list(map(int, input().split())) n = X A.append(n) while n * 2 <= Y: n = n*2 A.append(n) print((len(A))) def bfs(queue): global yet, graph if len(queue) == 0: return yet.remove(queue[-1]) for i, adjacency in enumerate(graph[queue[-1]]): if adjacency == 1 and (i in yet) and (i not in queue): # 隣接かつ未探索であれば、stackにpush queue.appendleft(i) else: queue.pop() bfs(queue) def dfs(stack): global yet, graph yet.remove(stack[-1]) for i, adjacency in enumerate(graph[stack[-1]]): if adjacency == 1 and i in yet: # 隣接かつ未探索であれば、stackにpush stack.append(i) dfs(stack) else: stack.pop() def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors class Node(): def __init__(self): self.idx = None self.left = None self.right = None self.parent = None return def pre_order(self): global pre_order_str pre_order_str += str(self.idx) + " " if self.left: self.left.pre_order() if self.right: self.right.pre_order() def in_order(self): global in_order_str if self.left: self.left.in_order() in_order_str += str(self.idx) + " " if self.right: self.right.in_order() def post_order(self): global post_order_str if self.left: self.left.post_order() if self.right: self.right.post_order() post_order_str += str(self.idx) + " " class HeapHelper(): """HeapContrler. 完全二分木を二分ヒープで表現した配列 A に対して、 HeapHelper.parent(idx) とするとそのノードの親の添字を返す 存在しない場合は Falseを返す Returns: [type] -- [description] """ def __init__(self): return @staticmethod def parent(i): if i == 1: return False return int(i/2) @staticmethod def left(i): l_idx = 2*i if H < l_idx: return False return l_idx @staticmethod def right(i): r_idx = 2*i + 1 if H < r_idx: return False return r_idx if __name__ == "__main__": main()
34
140
555
2,724
# vim: set fileencoding=utf-8: """ X,Yの区間は[1, pow(10,18)]であり、全探索すると日が暮れる。 厳密には、区間[X, Y]のすべてを検証する必要はないはずで、 [X, 2*X]でいいはずである。たぶん。 """ def main(): X, Y = list(map(int, input().split())) ans = 0 temp = 0 X2 = 2 * X ct = 0 for i, _ in enumerate(range(X2), X): ct += 1 n = i while n <= Y: temp += 1 n *= 2 ans = max(ans, temp) temp = 0 if ct == 400000: break print(ans) if __name__ == "__main__": main()
#!/usr/bin/python3 # vim: set fileencoding=utf-8: import sys input = sys.stdin.readline """ H = int(input()) h = [int(ele) for ele in input().split()] h = [0] + h """ def main(): A = [] X, Y = list(map(int, input().split())) n = X A.append(n) while n * 2 <= Y: n = n * 2 A.append(n) print((len(A))) def bfs(queue): global yet, graph if len(queue) == 0: return yet.remove(queue[-1]) for i, adjacency in enumerate(graph[queue[-1]]): if adjacency == 1 and (i in yet) and (i not in queue): # 隣接かつ未探索であれば、stackにpush queue.appendleft(i) else: queue.pop() bfs(queue) def dfs(stack): global yet, graph yet.remove(stack[-1]) for i, adjacency in enumerate(graph[stack[-1]]): if adjacency == 1 and i in yet: # 隣接かつ未探索であれば、stackにpush stack.append(i) dfs(stack) else: stack.pop() def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors class Node: def __init__(self): self.idx = None self.left = None self.right = None self.parent = None return def pre_order(self): global pre_order_str pre_order_str += str(self.idx) + " " if self.left: self.left.pre_order() if self.right: self.right.pre_order() def in_order(self): global in_order_str if self.left: self.left.in_order() in_order_str += str(self.idx) + " " if self.right: self.right.in_order() def post_order(self): global post_order_str if self.left: self.left.post_order() if self.right: self.right.post_order() post_order_str += str(self.idx) + " " class HeapHelper: """HeapContrler. 完全二分木を二分ヒープで表現した配列 A に対して、 HeapHelper.parent(idx) とするとそのノードの親の添字を返す 存在しない場合は Falseを返す Returns: [type] -- [description] """ def __init__(self): return @staticmethod def parent(i): if i == 1: return False return int(i / 2) @staticmethod def left(i): l_idx = 2 * i if H < l_idx: return False return l_idx @staticmethod def right(i): r_idx = 2 * i + 1 if H < r_idx: return False return r_idx if __name__ == "__main__": main()
false
75.714286
[ "+#!/usr/bin/python3", "+import sys", "+", "+input = sys.stdin.readline", "-X,Yの区間は[1, pow(10,18)]であり、全探索すると日が暮れる。", "-厳密には、区間[X, Y]のすべてを検証する必要はないはずで、", "-[X, 2*X]でいいはずである。たぶん。", "+H = int(input())", "+h = [int(ele) for ele in input().split()]", "+h = [0] + h", "+ A = []", "- ans = 0", "- temp = 0", "- X2 = 2 * X", "- ct = 0", "- for i, _ in enumerate(range(X2), X):", "- ct += 1", "- n = i", "- while n <= Y:", "- temp += 1", "- n *= 2", "- ans = max(ans, temp)", "- temp = 0", "- if ct == 400000:", "- break", "- print(ans)", "+ n = X", "+ A.append(n)", "+ while n * 2 <= Y:", "+ n = n * 2", "+ A.append(n)", "+ print((len(A)))", "+", "+", "+def bfs(queue):", "+ global yet, graph", "+ if len(queue) == 0:", "+ return", "+ yet.remove(queue[-1])", "+ for i, adjacency in enumerate(graph[queue[-1]]):", "+ if adjacency == 1 and (i in yet) and (i not in queue): # 隣接かつ未探索であれば、stackにpush", "+ queue.appendleft(i)", "+ else:", "+ queue.pop()", "+ bfs(queue)", "+", "+", "+def dfs(stack):", "+ global yet, graph", "+ yet.remove(stack[-1])", "+ for i, adjacency in enumerate(graph[stack[-1]]):", "+ if adjacency == 1 and i in yet: # 隣接かつ未探索であれば、stackにpush", "+ stack.append(i)", "+ dfs(stack)", "+ else:", "+ stack.pop()", "+", "+", "+def make_divisors(n):", "+ divisors = []", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ divisors.append(i)", "+ if i != n // i:", "+ divisors.append(n // i)", "+ return divisors", "+", "+", "+class Node:", "+ def __init__(self):", "+ self.idx = None", "+ self.left = None", "+ self.right = None", "+ self.parent = None", "+ return", "+", "+ def pre_order(self):", "+ global pre_order_str", "+ pre_order_str += str(self.idx) + \" \"", "+ if self.left:", "+ self.left.pre_order()", "+ if self.right:", "+ self.right.pre_order()", "+", "+ def in_order(self):", "+ global in_order_str", "+ if self.left:", "+ self.left.in_order()", "+ in_order_str += str(self.idx) + \" \"", "+ if self.right:", "+ self.right.in_order()", "+", "+ def post_order(self):", "+ global post_order_str", "+ if self.left:", "+ self.left.post_order()", "+ if self.right:", "+ self.right.post_order()", "+ post_order_str += str(self.idx) + \" \"", "+", "+", "+class HeapHelper:", "+ \"\"\"HeapContrler.", "+ 完全二分木を二分ヒープで表現した配列 A に対して、", "+ HeapHelper.parent(idx) とするとそのノードの親の添字を返す", "+ 存在しない場合は Falseを返す", "+ Returns:", "+ [type] -- [description]", "+ \"\"\"", "+", "+ def __init__(self):", "+ return", "+", "+ @staticmethod", "+ def parent(i):", "+ if i == 1:", "+ return False", "+ return int(i / 2)", "+", "+ @staticmethod", "+ def left(i):", "+ l_idx = 2 * i", "+ if H < l_idx:", "+ return False", "+ return l_idx", "+", "+ @staticmethod", "+ def right(i):", "+ r_idx = 2 * i + 1", "+ if H < r_idx:", "+ return False", "+ return r_idx" ]
false
0.798234
0.050019
15.958771
[ "s697093939", "s736924068" ]
u077291787
p03878
python
s194622809
s932362420
417
345
28,328
28,536
Accepted
Accepted
17.27
# cf16-exhibition-final-openA - 1D Matching import sys input = sys.stdin.readline def calc(x, y, total): MOD = 10 ** 9 + 7 if y: total = (total * y) % MOD y -= 1 else: x += 1 return x, y, total def main(): N = int(eval(input())) A = tuple(map(int, [eval(input()) for _ in range(N)])) B = tuple(map(int, [eval(input()) for _ in range(N)])) C = sorted([(i, 1) for i in A] + [(i, 0) for i in B]) ans, a, b = 1, 0, 0 for i, t in C: if t: # laptop a, b, ans = calc(a, b, ans) else: # power sources b, a, ans = calc(b, a, ans) print(ans) if __name__ == "__main__": main()
# cf16-exhibition-final-openA - 1D Matching def calc(x, y, total): if y: total = (total * y) % MOD y -= 1 else: x += 1 return x, y, total def main(): global MOD # sort A, B and the lines between A, B shouldn't cross # cross <-> not min distance N, *AB = list(map(int, open(0))) C = sorted([(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]]) MOD = 10 ** 9 + 7 ans, a, b = 1, 0, 0 for i, t in C: if t: # laptop a, b, ans = calc(a, b, ans) else: # power sources b, a, ans = calc(b, a, ans) print(ans) if __name__ == "__main__": main()
29
28
693
675
# cf16-exhibition-final-openA - 1D Matching import sys input = sys.stdin.readline def calc(x, y, total): MOD = 10**9 + 7 if y: total = (total * y) % MOD y -= 1 else: x += 1 return x, y, total def main(): N = int(eval(input())) A = tuple(map(int, [eval(input()) for _ in range(N)])) B = tuple(map(int, [eval(input()) for _ in range(N)])) C = sorted([(i, 1) for i in A] + [(i, 0) for i in B]) ans, a, b = 1, 0, 0 for i, t in C: if t: # laptop a, b, ans = calc(a, b, ans) else: # power sources b, a, ans = calc(b, a, ans) print(ans) if __name__ == "__main__": main()
# cf16-exhibition-final-openA - 1D Matching def calc(x, y, total): if y: total = (total * y) % MOD y -= 1 else: x += 1 return x, y, total def main(): global MOD # sort A, B and the lines between A, B shouldn't cross # cross <-> not min distance N, *AB = list(map(int, open(0))) C = sorted([(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]]) MOD = 10**9 + 7 ans, a, b = 1, 0, 0 for i, t in C: if t: # laptop a, b, ans = calc(a, b, ans) else: # power sources b, a, ans = calc(b, a, ans) print(ans) if __name__ == "__main__": main()
false
3.448276
[ "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "- MOD = 10**9 + 7", "- N = int(eval(input()))", "- A = tuple(map(int, [eval(input()) for _ in range(N)]))", "- B = tuple(map(int, [eval(input()) for _ in range(N)]))", "- C = sorted([(i, 1) for i in A] + [(i, 0) for i in B])", "+ global MOD", "+ # sort A, B and the lines between A, B shouldn't cross", "+ # cross <-> not min distance", "+ N, *AB = list(map(int, open(0)))", "+ C = sorted([(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]])", "+ MOD = 10**9 + 7" ]
false
0.178321
0.007498
23.782554
[ "s194622809", "s932362420" ]
u888337853
p02924
python
s206154455
s059409139
157
17
13,664
2,940
Accepted
Accepted
89.17
import math import copy import sys import fractions import numpy as np from functools import reduce # ===FUNCTION=== def getInputInt(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputoData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n, = list(map(int, input().split())) # data = getInputListInt() if n % 2 == 0: ans = int(n / 2) ans = int(ans * (n - 1)) else: ans = int((n - 1) / 2) ans = int(ans * n) print(ans)
import sys # import math # import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) # INF = sys.maxsize # MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n = ni() ans = ((n-1)*n)//2 print(ans) if __name__ == '__main__': main()
52
29
1,023
491
import math import copy import sys import fractions import numpy as np from functools import reduce # ===FUNCTION=== def getInputInt(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputoData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== (n,) = list(map(int, input().split())) # data = getInputListInt() if n % 2 == 0: ans = int(n / 2) ans = int(ans * (n - 1)) else: ans = int((n - 1) / 2) ans = int(ans * n) print(ans)
import sys # import math # import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) # INF = sys.maxsize # MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n = ni() ans = ((n - 1) * n) // 2 print(ans) if __name__ == "__main__": main()
false
44.230769
[ "-import math", "-import copy", "-import fractions", "-import numpy as np", "-from functools import reduce", "-# ===FUNCTION===", "-def getInputInt():", "- inputNum = int(eval(input()))", "- return inputNum", "+# import math", "+# import bisect", "+# import copy", "+# import heapq", "+# from collections import deque", "+# import decimal", "+# sys.setrecursionlimit(100001)", "+# INF = sys.maxsize", "+# MOD = 10 ** 9 + 7", "+ni = lambda: int(sys.stdin.readline())", "+ns = lambda: list(map(int, sys.stdin.readline().split()))", "+na = lambda: list(map(int, sys.stdin.readline().split()))", "+# ===CODE===", "+def main():", "+ n = ni()", "+ ans = ((n - 1) * n) // 2", "+ print(ans)", "-def getInputListInt():", "- outputoData = []", "- inputData = input().split()", "- outputData = [int(n) for n in inputData]", "- return outputData", "-", "-", "-def getSomeInputInt(n):", "- outputDataList = []", "- for i in range(n):", "- inputData = int(eval(input()))", "- outputDataList.append(inputData)", "- return outputDataList", "-", "-", "-def getSomeInputListInt(n):", "- inputDataList = []", "- outputDataList = []", "- for i in range(n):", "- inputData = input().split()", "- inputDataList = [int(n) for n in inputData]", "- outputDataList.append(inputDataList)", "- return outputDataList", "-", "-", "-# ===CODE===", "-(n,) = list(map(int, input().split()))", "-# data = getInputListInt()", "-if n % 2 == 0:", "- ans = int(n / 2)", "- ans = int(ans * (n - 1))", "-else:", "- ans = int((n - 1) / 2)", "- ans = int(ans * n)", "-print(ans)", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047527
0.043029
1.104519
[ "s206154455", "s059409139" ]
u475675023
p02702
python
s085564926
s938886246
324
92
9,196
9,340
Accepted
Accepted
71.6
s=eval(input()) ans=0 u=0 l=[0]*2019 l[0]=1 for i,n in enumerate(map(int,s)): u=(u+n*pow(10,len(s)-i,2019))%2019 l[u]+=1 for i in l: ans+=i*(i-1)//2 print(ans)
s=input()[::-1] ans=0 u=0 d=1 l=[0]*2019 l[0]=1 for i in map(int,s): u=(u+i*d)%2019 l[u]+=1 d=d*10%2019 for i in l: ans+=i*(i-1)//2 print(ans)
11
13
169
162
s = eval(input()) ans = 0 u = 0 l = [0] * 2019 l[0] = 1 for i, n in enumerate(map(int, s)): u = (u + n * pow(10, len(s) - i, 2019)) % 2019 l[u] += 1 for i in l: ans += i * (i - 1) // 2 print(ans)
s = input()[::-1] ans = 0 u = 0 d = 1 l = [0] * 2019 l[0] = 1 for i in map(int, s): u = (u + i * d) % 2019 l[u] += 1 d = d * 10 % 2019 for i in l: ans += i * (i - 1) // 2 print(ans)
false
15.384615
[ "-s = eval(input())", "+s = input()[::-1]", "+d = 1", "-for i, n in enumerate(map(int, s)):", "- u = (u + n * pow(10, len(s) - i, 2019)) % 2019", "+for i in map(int, s):", "+ u = (u + i * d) % 2019", "+ d = d * 10 % 2019" ]
false
0.044013
0.043729
1.006488
[ "s085564926", "s938886246" ]
u585482323
p03329
python
s638002148
s114043965
233
208
41,200
39,280
Accepted
Accepted
10.73
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() ans = float("inf") for i in range(n+1): m = 0 k = i while k > 0: m += k%6 k //= 6 k = n-i while k > 0: m += k%9 k //= 9 ans = min(ans,m) print(ans) #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": C()
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n = I() ans = float("inf") for i in range(n+1): m = 0 k = i while k > 0: m += k%6 k //= 6 k = n-i while k > 0: m += k%9 k //= 9 if m < ans: ans = m print(ans) return #B def B(): return #C def C(): return #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": A()
77
89
1,337
1,456
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A def A(): return # B def B(): return # C def C(): n = I() ans = float("inf") for i in range(n + 1): m = 0 k = i while k > 0: m += k % 6 k //= 6 k = n - i while k > 0: m += k % 9 k //= 9 ans = min(ans, m) print(ans) # D def D(): return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": C()
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 # A def A(): n = I() ans = float("inf") for i in range(n + 1): m = 0 k = i while k > 0: m += k % 6 k //= 6 k = n - i while k > 0: m += k % 9 k //= 9 if m < ans: ans = m print(ans) return # B def B(): return # C def C(): return # D def D(): return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # I def I_(): return # J def J(): return # Solve if __name__ == "__main__": A()
false
13.483146
[ "- l[i] = SR()", "+ l[i] = LS()", "+sys.setrecursionlimit(1000000)", "- return", "-", "-", "-# B", "-def B():", "- return", "-", "-", "-# C", "-def C():", "- ans = min(ans, m)", "+ if m < ans:", "+ ans = m", "+ return", "+", "+", "+# B", "+def B():", "+ return", "+", "+", "+# C", "+def C():", "+ return", "+# I", "+def I_():", "+ return", "+", "+", "+# J", "+def J():", "+ return", "+", "+", "- C()", "+ A()" ]
false
0.122852
0.070229
1.74931
[ "s638002148", "s114043965" ]
u392319141
p02930
python
s895069891
s705655176
552
139
63,192
3,952
Accepted
Accepted
74.82
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10**9 + 7 def sol(): N = int(input()) for i in range(1, N): for j in range(i + 1, N + 1): digit = 0 while (i & (1 << digit)) == (j & (1 << digit)): digit += 1 print('{} '.format(digit + 1), end='') print('') sol()
N = int(eval(input())) for i in range(N - 1): row = [] for j in range(i + 1, N): d = 0 while (i & (1 << d)) == (j & (1 << d)): d += 1 row.append(d + 1) print((*row))
21
10
529
216
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10**7) MOD = 10**9 + 7 def sol(): N = int(input()) for i in range(1, N): for j in range(i + 1, N + 1): digit = 0 while (i & (1 << digit)) == (j & (1 << digit)): digit += 1 print("{} ".format(digit + 1), end="") print("") sol()
N = int(eval(input())) for i in range(N - 1): row = [] for j in range(i + 1, N): d = 0 while (i & (1 << d)) == (j & (1 << d)): d += 1 row.append(d + 1) print((*row))
false
52.380952
[ "-import sys", "-import heapq", "-from operator import itemgetter", "-from collections import deque, defaultdict, Counter", "-from bisect import bisect_left, bisect_right", "-", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-MOD = 10**9 + 7", "-", "-", "-def sol():", "- N = int(input())", "- for i in range(1, N):", "- for j in range(i + 1, N + 1):", "- digit = 0", "- while (i & (1 << digit)) == (j & (1 << digit)):", "- digit += 1", "- print(\"{} \".format(digit + 1), end=\"\")", "- print(\"\")", "-", "-", "-sol()", "+N = int(eval(input()))", "+for i in range(N - 1):", "+ row = []", "+ for j in range(i + 1, N):", "+ d = 0", "+ while (i & (1 << d)) == (j & (1 << d)):", "+ d += 1", "+ row.append(d + 1)", "+ print((*row))" ]
false
0.054619
0.125916
0.433773
[ "s895069891", "s705655176" ]
u009348313
p02720
python
s384329287
s259829574
323
266
91,440
52,048
Accepted
Accepted
17.65
K = int(eval(input())) ans = [] R = [[] for _ in range(11)] for i in range(1,10): R[0].append(i) for i in range(1,11): R[i] = [10**i] if i > 1: for j in range(i-1): for r in R[i-2-j]: d = r//(10**(i-2-j)) if d <= 1: R[i].append(10**i+r) for r in R[i-1]: d = r//(10**(i-1)) for j in [-1,0,1]: if 1<= d+j <= 9: R[i].append((d+j)*(10**i)+r) A = [] #print(sorted(R[0])) #print(sorted(R[1])) #print(sorted(R[2])) #print(sorted(R[3])) #print(sorted(R[4])) #print(sorted(R[10])) for i in range(11): for r in R[i]: A.append(r) A.sort() #print(len(A)) print((A[K-1]))
from heapq import heappush, heappop K = int(eval(input())) hq = [] for i in range(1,10): heappush(hq,i) cnt = 0 while(cnt < K): x = heappop(hq) cnt += 1 for i in [-1,0,1]: d = (x%10)+i if 0 <= d <= 9: heappush(hq,x*10+d) print(x)
34
15
690
261
K = int(eval(input())) ans = [] R = [[] for _ in range(11)] for i in range(1, 10): R[0].append(i) for i in range(1, 11): R[i] = [10**i] if i > 1: for j in range(i - 1): for r in R[i - 2 - j]: d = r // (10 ** (i - 2 - j)) if d <= 1: R[i].append(10**i + r) for r in R[i - 1]: d = r // (10 ** (i - 1)) for j in [-1, 0, 1]: if 1 <= d + j <= 9: R[i].append((d + j) * (10**i) + r) A = [] # print(sorted(R[0])) # print(sorted(R[1])) # print(sorted(R[2])) # print(sorted(R[3])) # print(sorted(R[4])) # print(sorted(R[10])) for i in range(11): for r in R[i]: A.append(r) A.sort() # print(len(A)) print((A[K - 1]))
from heapq import heappush, heappop K = int(eval(input())) hq = [] for i in range(1, 10): heappush(hq, i) cnt = 0 while cnt < K: x = heappop(hq) cnt += 1 for i in [-1, 0, 1]: d = (x % 10) + i if 0 <= d <= 9: heappush(hq, x * 10 + d) print(x)
false
55.882353
[ "+from heapq import heappush, heappop", "+", "-ans = []", "-R = [[] for _ in range(11)]", "+hq = []", "- R[0].append(i)", "-for i in range(1, 11):", "- R[i] = [10**i]", "- if i > 1:", "- for j in range(i - 1):", "- for r in R[i - 2 - j]:", "- d = r // (10 ** (i - 2 - j))", "- if d <= 1:", "- R[i].append(10**i + r)", "- for r in R[i - 1]:", "- d = r // (10 ** (i - 1))", "- for j in [-1, 0, 1]:", "- if 1 <= d + j <= 9:", "- R[i].append((d + j) * (10**i) + r)", "-A = []", "-# print(sorted(R[0]))", "-# print(sorted(R[1]))", "-# print(sorted(R[2]))", "-# print(sorted(R[3]))", "-# print(sorted(R[4]))", "-# print(sorted(R[10]))", "-for i in range(11):", "- for r in R[i]:", "- A.append(r)", "-A.sort()", "-# print(len(A))", "-print((A[K - 1]))", "+ heappush(hq, i)", "+cnt = 0", "+while cnt < K:", "+ x = heappop(hq)", "+ cnt += 1", "+ for i in [-1, 0, 1]:", "+ d = (x % 10) + i", "+ if 0 <= d <= 9:", "+ heappush(hq, x * 10 + d)", "+print(x)" ]
false
1.155127
0.078409
14.732078
[ "s384329287", "s259829574" ]
u887207211
p03219
python
s932857076
s951276477
19
17
2,940
2,940
Accepted
Accepted
10.53
def ans(): X, Y = list(map(int,input().split())) print((X+Y//2)) ans()
X, Y = list(map(int,input().split())) print((X+Y//2))
4
2
69
46
def ans(): X, Y = list(map(int, input().split())) print((X + Y // 2)) ans()
X, Y = list(map(int, input().split())) print((X + Y // 2))
false
50
[ "-def ans():", "- X, Y = list(map(int, input().split()))", "- print((X + Y // 2))", "-", "-", "-ans()", "+X, Y = list(map(int, input().split()))", "+print((X + Y // 2))" ]
false
0.073349
0.071303
1.028693
[ "s932857076", "s951276477" ]
u564902833
p03049
python
s532921963
s312688908
285
36
48,216
3,700
Accepted
Accepted
87.37
N = int(eval(input())) s = [eval(input()) for _ in range(N)] k = sum(t.count('AB') for t in s) ab = sum(t[-1] == 'A' and t[0] == 'B' for t in s) a = sum(t[-1] == 'A' and t[0] != 'B' for t in s) b = sum(t[-1] != 'A' and t[0] == 'B' for t in s) ans = k isA = False if a > 0: a -= 1 isA = True if ab > 0: if isA: ans += ab else: ans += ab - 1 isA = True if isA: if b > 0: ans += 1 b -= 1 ans += min(a, b) else: ans += min(a, b) print(ans)
# 入力 N = int(eval(input())) s = [eval(input()) for _ in range(N)] # 先頭がBである/ではない、末尾がAである/ではない文字列の個数を数え上げる a = sum(t[0] != 'B' and t[-1] == 'A' for t in s) b = sum(t[0] == 'B' and t[-1] != 'A' for t in s) ba = sum(t[0] == 'B' and t[-1] == 'A' for t in s) # 最初に、先頭文字がBではない、かつ、末尾文字がAの文字列を先頭におく(そのような文字列が存在すれば) # 次に、先頭文字がB、かつ、末尾文字がAの文字列を可能な限り連結する # 次に、(先頭文字がB、かつ、末尾文字がAでない文字列)と(先頭文字がBではない、かつ、末尾文字がAの文字列)を交互に連結する # 最後に、余っている文字列を適当に連結する ans = ( sum(t.count('AB') for t in s) + ( ba if a > 0 else max(0, ba - 1) ) + ( min(1, b) if a == 0 and ba > 0 else min(a, b) ) ) # 出力 print(ans)
26
27
514
646
N = int(eval(input())) s = [eval(input()) for _ in range(N)] k = sum(t.count("AB") for t in s) ab = sum(t[-1] == "A" and t[0] == "B" for t in s) a = sum(t[-1] == "A" and t[0] != "B" for t in s) b = sum(t[-1] != "A" and t[0] == "B" for t in s) ans = k isA = False if a > 0: a -= 1 isA = True if ab > 0: if isA: ans += ab else: ans += ab - 1 isA = True if isA: if b > 0: ans += 1 b -= 1 ans += min(a, b) else: ans += min(a, b) print(ans)
# 入力 N = int(eval(input())) s = [eval(input()) for _ in range(N)] # 先頭がBである/ではない、末尾がAである/ではない文字列の個数を数え上げる a = sum(t[0] != "B" and t[-1] == "A" for t in s) b = sum(t[0] == "B" and t[-1] != "A" for t in s) ba = sum(t[0] == "B" and t[-1] == "A" for t in s) # 最初に、先頭文字がBではない、かつ、末尾文字がAの文字列を先頭におく(そのような文字列が存在すれば) # 次に、先頭文字がB、かつ、末尾文字がAの文字列を可能な限り連結する # 次に、(先頭文字がB、かつ、末尾文字がAでない文字列)と(先頭文字がBではない、かつ、末尾文字がAの文字列)を交互に連結する # 最後に、余っている文字列を適当に連結する ans = ( sum(t.count("AB") for t in s) + (ba if a > 0 else max(0, ba - 1)) + (min(1, b) if a == 0 and ba > 0 else min(a, b)) ) # 出力 print(ans)
false
3.703704
[ "+# 入力", "-k = sum(t.count(\"AB\") for t in s)", "-ab = sum(t[-1] == \"A\" and t[0] == \"B\" for t in s)", "-a = sum(t[-1] == \"A\" and t[0] != \"B\" for t in s)", "-b = sum(t[-1] != \"A\" and t[0] == \"B\" for t in s)", "-ans = k", "-isA = False", "-if a > 0:", "- a -= 1", "- isA = True", "-if ab > 0:", "- if isA:", "- ans += ab", "- else:", "- ans += ab - 1", "- isA = True", "-if isA:", "- if b > 0:", "- ans += 1", "- b -= 1", "- ans += min(a, b)", "-else:", "- ans += min(a, b)", "+# 先頭がBである/ではない、末尾がAである/ではない文字列の個数を数え上げる", "+a = sum(t[0] != \"B\" and t[-1] == \"A\" for t in s)", "+b = sum(t[0] == \"B\" and t[-1] != \"A\" for t in s)", "+ba = sum(t[0] == \"B\" and t[-1] == \"A\" for t in s)", "+# 最初に、先頭文字がBではない、かつ、末尾文字がAの文字列を先頭におく(そのような文字列が存在すれば)", "+# 次に、先頭文字がB、かつ、末尾文字がAの文字列を可能な限り連結する", "+# 次に、(先頭文字がB、かつ、末尾文字がAでない文字列)と(先頭文字がBではない、かつ、末尾文字がAの文字列)を交互に連結する", "+# 最後に、余っている文字列を適当に連結する", "+ans = (", "+ sum(t.count(\"AB\") for t in s)", "+ + (ba if a > 0 else max(0, ba - 1))", "+ + (min(1, b) if a == 0 and ba > 0 else min(a, b))", "+)", "+# 出力" ]
false
0.084321
0.046263
1.822645
[ "s532921963", "s312688908" ]
u411203878
p03700
python
s207263631
s258911541
743
186
52,460
81,596
Accepted
Accepted
74.97
n, a, b = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] import math def ok(x): t = 0 for i in range(n): r = h[i] - b*x if r < 0: continue else: t += math.ceil(r/(a-b)) if t <= x: return True else: return False l = 0 r = 10**14+1 while l+1 < r: c = (l+r)//2 if ok(c): r = c else: l = c print(r)
N,A,B = list(map(int,input().split())) H = [] for _ in range(N): h = int(eval(input())) H.append(h) ok = 1000000000 ng = 0 while ok != ng+1: mid = (ok+ng)//2 range_damage = mid*B attack_count = 0 for value in H: if range_damage < value: if (value - range_damage)%(A-B)==0: attack_count += (value - range_damage)//(A-B) else: attack_count += 1+(value - range_damage)//(A-B) if attack_count <= mid: ok = mid else: ng = mid print(ok)
26
25
447
557
n, a, b = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] import math def ok(x): t = 0 for i in range(n): r = h[i] - b * x if r < 0: continue else: t += math.ceil(r / (a - b)) if t <= x: return True else: return False l = 0 r = 10**14 + 1 while l + 1 < r: c = (l + r) // 2 if ok(c): r = c else: l = c print(r)
N, A, B = list(map(int, input().split())) H = [] for _ in range(N): h = int(eval(input())) H.append(h) ok = 1000000000 ng = 0 while ok != ng + 1: mid = (ok + ng) // 2 range_damage = mid * B attack_count = 0 for value in H: if range_damage < value: if (value - range_damage) % (A - B) == 0: attack_count += (value - range_damage) // (A - B) else: attack_count += 1 + (value - range_damage) // (A - B) if attack_count <= mid: ok = mid else: ng = mid print(ok)
false
3.846154
[ "-n, a, b = list(map(int, input().split()))", "-h = [int(eval(input())) for _ in range(n)]", "-import math", "-", "-", "-def ok(x):", "- t = 0", "- for i in range(n):", "- r = h[i] - b * x", "- if r < 0:", "- continue", "- else:", "- t += math.ceil(r / (a - b))", "- if t <= x:", "- return True", "+N, A, B = list(map(int, input().split()))", "+H = []", "+for _ in range(N):", "+ h = int(eval(input()))", "+ H.append(h)", "+ok = 1000000000", "+ng = 0", "+while ok != ng + 1:", "+ mid = (ok + ng) // 2", "+ range_damage = mid * B", "+ attack_count = 0", "+ for value in H:", "+ if range_damage < value:", "+ if (value - range_damage) % (A - B) == 0:", "+ attack_count += (value - range_damage) // (A - B)", "+ else:", "+ attack_count += 1 + (value - range_damage) // (A - B)", "+ if attack_count <= mid:", "+ ok = mid", "- return False", "-", "-", "-l = 0", "-r = 10**14 + 1", "-while l + 1 < r:", "- c = (l + r) // 2", "- if ok(c):", "- r = c", "- else:", "- l = c", "-print(r)", "+ ng = mid", "+print(ok)" ]
false
0.044773
0.043412
1.031365
[ "s207263631", "s258911541" ]
u600402037
p03401
python
s381258078
s836679300
231
211
14,048
14,048
Accepted
Accepted
8.66
N = int(eval(input())) A = [0] + [int(x) for x in input().split()] + [0] cnt = 0 for i in range(N+1): cnt += abs(A[i+1]-A[i]) for j in range(1, N+1): print((cnt - (abs(A[j]-A[j-1]) + abs(A[j+1]-A[j])) + abs(A[j+1]-A[j-1])))
N = int(eval(input())) A = [0] + [int(x) for x in input().split()] + [0] cnt = sum(abs(A[i+1] - A[i]) for i in range(N+1)) for j in range(1, N+1): print((cnt - (abs(A[j]-A[j-1]) + abs(A[j+1]-A[j])) + abs(A[j+1]-A[j-1])))
9
7
237
225
N = int(eval(input())) A = [0] + [int(x) for x in input().split()] + [0] cnt = 0 for i in range(N + 1): cnt += abs(A[i + 1] - A[i]) for j in range(1, N + 1): print( (cnt - (abs(A[j] - A[j - 1]) + abs(A[j + 1] - A[j])) + abs(A[j + 1] - A[j - 1])) )
N = int(eval(input())) A = [0] + [int(x) for x in input().split()] + [0] cnt = sum(abs(A[i + 1] - A[i]) for i in range(N + 1)) for j in range(1, N + 1): print( (cnt - (abs(A[j] - A[j - 1]) + abs(A[j + 1] - A[j])) + abs(A[j + 1] - A[j - 1])) )
false
22.222222
[ "-cnt = 0", "-for i in range(N + 1):", "- cnt += abs(A[i + 1] - A[i])", "+cnt = sum(abs(A[i + 1] - A[i]) for i in range(N + 1))" ]
false
0.119239
0.037837
3.151386
[ "s381258078", "s836679300" ]
u017810624
p02936
python
s905786032
s811657771
1,946
967
157,320
148,956
Accepted
Accepted
50.31
n,q=list(map(int,input().split())) l=[] for i in range(n-1): l.append(list(map(int,input().split()))) l2=[] for i in range(q): l2.append(list(map(int,input().split()))) connection=[[] for i in range(n)] for i in range(n-1): connection[l[i][0]-1].append(l[i][1]-1) L4=[] for i in range(n): L4.append(0) for i in range(q): L4[l2[i][0]-1]+=l2[i][1] distance=[0 for i in range(n)] distance[0]=L4[0] ans=[0 for i in range(n)] ans[0]=L4[0] L=[0] L2=[] L3=[] while len(L2)!=n and len(L)!=0: for j in range(len(L)): for k in range(len(connection[L[j]])): distance[connection[L[j]][k]]=distance[L[j]]+L4[connection[L[j]][k]] L3.append(connection[L[j]][k]) L2.append(L[j]) L=L3 L3=[] for i in range(len(distance)): distance[i]=str(distance[i]) print((' '.join(distance)))
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) l=[] for i in range(n-1): l.append(list(map(int,input().split()))) l2=[] for i in range(q): l2.append(list(map(int,input().split()))) connection=[[] for i in range(n)] for i in range(n-1): connection[l[i][0]-1].append(l[i][1]-1) L4=[] for i in range(n): L4.append(0) for i in range(q): L4[l2[i][0]-1]+=l2[i][1] distance=[0 for i in range(n)] distance[0]=L4[0] ans=[0 for i in range(n)] ans[0]=L4[0] L=[0] L2=[] L3=[] while len(L2)!=n and len(L)!=0: for j in range(len(L)): for k in range(len(connection[L[j]])): distance[connection[L[j]][k]]=distance[L[j]]+L4[connection[L[j]][k]] L3.append(connection[L[j]][k]) L2.append(L[j]) L=L3 L3=[] for i in range(len(distance)): distance[i]=str(distance[i]) print((' '.join(distance)))
34
36
826
864
n, q = list(map(int, input().split())) l = [] for i in range(n - 1): l.append(list(map(int, input().split()))) l2 = [] for i in range(q): l2.append(list(map(int, input().split()))) connection = [[] for i in range(n)] for i in range(n - 1): connection[l[i][0] - 1].append(l[i][1] - 1) L4 = [] for i in range(n): L4.append(0) for i in range(q): L4[l2[i][0] - 1] += l2[i][1] distance = [0 for i in range(n)] distance[0] = L4[0] ans = [0 for i in range(n)] ans[0] = L4[0] L = [0] L2 = [] L3 = [] while len(L2) != n and len(L) != 0: for j in range(len(L)): for k in range(len(connection[L[j]])): distance[connection[L[j]][k]] = distance[L[j]] + L4[connection[L[j]][k]] L3.append(connection[L[j]][k]) L2.append(L[j]) L = L3 L3 = [] for i in range(len(distance)): distance[i] = str(distance[i]) print((" ".join(distance)))
import sys input = sys.stdin.readline n, q = list(map(int, input().split())) l = [] for i in range(n - 1): l.append(list(map(int, input().split()))) l2 = [] for i in range(q): l2.append(list(map(int, input().split()))) connection = [[] for i in range(n)] for i in range(n - 1): connection[l[i][0] - 1].append(l[i][1] - 1) L4 = [] for i in range(n): L4.append(0) for i in range(q): L4[l2[i][0] - 1] += l2[i][1] distance = [0 for i in range(n)] distance[0] = L4[0] ans = [0 for i in range(n)] ans[0] = L4[0] L = [0] L2 = [] L3 = [] while len(L2) != n and len(L) != 0: for j in range(len(L)): for k in range(len(connection[L[j]])): distance[connection[L[j]][k]] = distance[L[j]] + L4[connection[L[j]][k]] L3.append(connection[L[j]][k]) L2.append(L[j]) L = L3 L3 = [] for i in range(len(distance)): distance[i] = str(distance[i]) print((" ".join(distance)))
false
5.555556
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.033658
0.037328
0.901682
[ "s905786032", "s811657771" ]
u375616706
p02863
python
s431227213
s192732932
857
460
120,920
47,976
Accepted
Accepted
46.32
N,T = list(map(int,input().split())) item=[list(map(int,input().split())) for _ in range(N)] item = sorted(item,key=lambda x:x[0]) dp=[[0]*(T+1) for _ in range(N+1)] for i,(a,b) in enumerate(item,1): for t in reversed(list(range(T))): dist=min(T,t+a) dp[i][dist] = max(dp[i-1][t]+b,dp[i][dist]) dp[i][t]=max(dp[i-1][t],dp[i-1][t]) ans=0 for l in dp: ans=max(ans,max(l)) print(ans)
N,T = list(map(int,input().split())) item=[list(map(int,input().split())) for _ in range(N)] item = sorted(item,key=lambda x:x[0]) dp=[0]*(T+1) for a,b in item: for t in reversed(list(range(T))): dist=min(T,t+a) dp[dist] = max(dp[t]+b,dp[dist]) print((max(dp)))
16
12
420
282
N, T = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(N)] item = sorted(item, key=lambda x: x[0]) dp = [[0] * (T + 1) for _ in range(N + 1)] for i, (a, b) in enumerate(item, 1): for t in reversed(list(range(T))): dist = min(T, t + a) dp[i][dist] = max(dp[i - 1][t] + b, dp[i][dist]) dp[i][t] = max(dp[i - 1][t], dp[i - 1][t]) ans = 0 for l in dp: ans = max(ans, max(l)) print(ans)
N, T = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(N)] item = sorted(item, key=lambda x: x[0]) dp = [0] * (T + 1) for a, b in item: for t in reversed(list(range(T))): dist = min(T, t + a) dp[dist] = max(dp[t] + b, dp[dist]) print((max(dp)))
false
25
[ "-dp = [[0] * (T + 1) for _ in range(N + 1)]", "-for i, (a, b) in enumerate(item, 1):", "+dp = [0] * (T + 1)", "+for a, b in item:", "- dp[i][dist] = max(dp[i - 1][t] + b, dp[i][dist])", "- dp[i][t] = max(dp[i - 1][t], dp[i - 1][t])", "-ans = 0", "-for l in dp:", "- ans = max(ans, max(l))", "-print(ans)", "+ dp[dist] = max(dp[t] + b, dp[dist])", "+print((max(dp)))" ]
false
0.173244
0.08594
2.015878
[ "s431227213", "s192732932" ]
u935558307
p02787
python
s632587506
s344823168
1,148
378
21,528
42,348
Accepted
Accepted
67.07
#モンスターの体力は H #トキはN種類の魔法が使え、 #i番目の魔法を使うと、モンスターの体力を Ai減らすことができますが、 #トキの魔力を Bi消耗します。 #dp[i] = モンスターの体力を i 減らすため消耗する魔力の最小値 #dp[i+1] = min(dp[i-Ai]+Bi,dp[i]) #dp[0]=0 import numpy as np h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab = np.array(ab) a = ab[:, 0] b = ab[:, 1] dp = np.zeros(100001, dtype=np.int) for i in range(1, h+1): dp[i] = (dp[i-a]+b).min() print((dp[h]))
h, n = list(map(int, input().split())) a = [] b = [] for i in range(n): a_, b_ = list(map(int, input().split())) a.append(a_) b.append(b_) dp = [10**9] * (h+1) dp[0] = 0 for i in range(1, h+1): for j in range(n): dp[i] = min(dp[i], dp[max(i-a[j], 0)] + b[j]) print((dp[-1]))
22
16
447
303
# モンスターの体力は H # トキはN種類の魔法が使え、 # i番目の魔法を使うと、モンスターの体力を Ai減らすことができますが、 # トキの魔力を Bi消耗します。 # dp[i] = モンスターの体力を i 減らすため消耗する魔力の最小値 # dp[i+1] = min(dp[i-Ai]+Bi,dp[i]) # dp[0]=0 import numpy as np h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab = np.array(ab) a = ab[:, 0] b = ab[:, 1] dp = np.zeros(100001, dtype=np.int) for i in range(1, h + 1): dp[i] = (dp[i - a] + b).min() print((dp[h]))
h, n = list(map(int, input().split())) a = [] b = [] for i in range(n): a_, b_ = list(map(int, input().split())) a.append(a_) b.append(b_) dp = [10**9] * (h + 1) dp[0] = 0 for i in range(1, h + 1): for j in range(n): dp[i] = min(dp[i], dp[max(i - a[j], 0)] + b[j]) print((dp[-1]))
false
27.272727
[ "-# モンスターの体力は H", "-# トキはN種類の魔法が使え、", "-# i番目の魔法を使うと、モンスターの体力を Ai減らすことができますが、", "-# トキの魔力を Bi消耗します。", "-# dp[i] = モンスターの体力を i 減らすため消耗する魔力の最小値", "-# dp[i+1] = min(dp[i-Ai]+Bi,dp[i])", "-# dp[0]=0", "-import numpy as np", "-", "-ab = [list(map(int, input().split())) for _ in range(n)]", "-ab = np.array(ab)", "-a = ab[:, 0]", "-b = ab[:, 1]", "-dp = np.zeros(100001, dtype=np.int)", "+a = []", "+b = []", "+for i in range(n):", "+ a_, b_ = list(map(int, input().split()))", "+ a.append(a_)", "+ b.append(b_)", "+dp = [10**9] * (h + 1)", "+dp[0] = 0", "- dp[i] = (dp[i - a] + b).min()", "-print((dp[h]))", "+ for j in range(n):", "+ dp[i] = min(dp[i], dp[max(i - a[j], 0)] + b[j])", "+print((dp[-1]))" ]
false
0.220151
0.089762
2.452608
[ "s632587506", "s344823168" ]
u197300773
p02845
python
s776834819
s946006475
178
69
14,396
13,964
Accepted
Accepted
61.24
def main(): import sys N=int(eval(input())) MOD=1000000007 a=list(map(int,input().split())) c=[0,0,0] ans=1 for i in range(N): if a[i]!=c[0] and a[i]!=c[1] and a[i]!=c[2]: print((0)) sys.exit() if c[1]==c[0] and c[2]==c[0]: ans=(ans*3)%MOD c[0]+=1 elif c[0]==c[1]: if c[0]==a[i]: c[0]+=1 ans=(ans*2)%MOD else: c[2]+=1 elif c[0]>c[1] and c[1]==c[2]: if c[0]==a[i]: c[0]+=1 else: ans=(ans*2)%MOD c[1]+=1 else: if c[0]==a[i]: c[0]+=1 if c[1]==a[i]: c[1]+=1 if c[2]==a[i]: c[2]+=1 c.sort(reverse=True) print(ans) if __name__ == '__main__': main()
def main(): import sys N=int(eval(input())) MOD=1000000007 a=list(map(int,input().split())) c=[3]+[0]*N ans=1 for i in range(N): p=a[i] ans=ans*c[p]%MOD c[p]-=1 c[p+1]+=1 print(ans) if __name__ == '__main__': main()
44
20
924
307
def main(): import sys N = int(eval(input())) MOD = 1000000007 a = list(map(int, input().split())) c = [0, 0, 0] ans = 1 for i in range(N): if a[i] != c[0] and a[i] != c[1] and a[i] != c[2]: print((0)) sys.exit() if c[1] == c[0] and c[2] == c[0]: ans = (ans * 3) % MOD c[0] += 1 elif c[0] == c[1]: if c[0] == a[i]: c[0] += 1 ans = (ans * 2) % MOD else: c[2] += 1 elif c[0] > c[1] and c[1] == c[2]: if c[0] == a[i]: c[0] += 1 else: ans = (ans * 2) % MOD c[1] += 1 else: if c[0] == a[i]: c[0] += 1 if c[1] == a[i]: c[1] += 1 if c[2] == a[i]: c[2] += 1 c.sort(reverse=True) print(ans) if __name__ == "__main__": main()
def main(): import sys N = int(eval(input())) MOD = 1000000007 a = list(map(int, input().split())) c = [3] + [0] * N ans = 1 for i in range(N): p = a[i] ans = ans * c[p] % MOD c[p] -= 1 c[p + 1] += 1 print(ans) if __name__ == "__main__": main()
false
54.545455
[ "- c = [0, 0, 0]", "+ c = [3] + [0] * N", "- if a[i] != c[0] and a[i] != c[1] and a[i] != c[2]:", "- print((0))", "- sys.exit()", "- if c[1] == c[0] and c[2] == c[0]:", "- ans = (ans * 3) % MOD", "- c[0] += 1", "- elif c[0] == c[1]:", "- if c[0] == a[i]:", "- c[0] += 1", "- ans = (ans * 2) % MOD", "- else:", "- c[2] += 1", "- elif c[0] > c[1] and c[1] == c[2]:", "- if c[0] == a[i]:", "- c[0] += 1", "- else:", "- ans = (ans * 2) % MOD", "- c[1] += 1", "- else:", "- if c[0] == a[i]:", "- c[0] += 1", "- if c[1] == a[i]:", "- c[1] += 1", "- if c[2] == a[i]:", "- c[2] += 1", "- c.sort(reverse=True)", "+ p = a[i]", "+ ans = ans * c[p] % MOD", "+ c[p] -= 1", "+ c[p + 1] += 1" ]
false
0.123238
0.134913
0.913458
[ "s776834819", "s946006475" ]
u232852711
p03999
python
s189864172
s972622902
38
29
3,572
3,444
Accepted
Accepted
23.68
from copy import deepcopy s = eval(input()) length = len(s) ans = 0 def solve(s_split, s, i): if i == length: # print(s_split) global ans ans += sum(list(map(int, s_split))) else: tmp1 = deepcopy(s_split) tmp1[-1] += s[0] solve(tmp1, s[1:], i+1) tmp2 = deepcopy(s_split) tmp2.append(s[0]) solve(tmp2, s[1:], i+1) solve(['0'], s, 0) print((int(ans/2)))
from copy import deepcopy s = eval(input()) length = len(s) ans = 0 def solve(s_split, s, i): if i == length: # print(s_split) global ans ans += sum(list(map(int, s_split))) else: tmp1 = deepcopy(s_split) tmp1[-1] += s[0] solve(tmp1, s[1:], i+1) tmp2 = deepcopy(s_split) tmp2.append(s[0]) solve(tmp2, s[1:], i+1) solve([s[0]], s[1:], 1) print(ans)
21
21
454
452
from copy import deepcopy s = eval(input()) length = len(s) ans = 0 def solve(s_split, s, i): if i == length: # print(s_split) global ans ans += sum(list(map(int, s_split))) else: tmp1 = deepcopy(s_split) tmp1[-1] += s[0] solve(tmp1, s[1:], i + 1) tmp2 = deepcopy(s_split) tmp2.append(s[0]) solve(tmp2, s[1:], i + 1) solve(["0"], s, 0) print((int(ans / 2)))
from copy import deepcopy s = eval(input()) length = len(s) ans = 0 def solve(s_split, s, i): if i == length: # print(s_split) global ans ans += sum(list(map(int, s_split))) else: tmp1 = deepcopy(s_split) tmp1[-1] += s[0] solve(tmp1, s[1:], i + 1) tmp2 = deepcopy(s_split) tmp2.append(s[0]) solve(tmp2, s[1:], i + 1) solve([s[0]], s[1:], 1) print(ans)
false
0
[ "-solve([\"0\"], s, 0)", "-print((int(ans / 2)))", "+solve([s[0]], s[1:], 1)", "+print(ans)" ]
false
0.037935
0.038082
0.996153
[ "s189864172", "s972622902" ]
u325264482
p03363
python
s972325738
s267898053
395
198
48,488
48,144
Accepted
Accepted
49.87
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) S = [0] for i, a in enumerate(A): S.append(S[i] + a) S = sorted(S) a = Counter(S).most_common() cnt = 0 for i in range(len(a)): cnt += ((a[i][1]-1)*a[i][1])//2 print(cnt)
from itertools import accumulate import collections N = int(eval(input())) A = list(map(int, input().split())) def main(): # 累積和 B = [0] + A B = list(accumulate(B)) c = collections.Counter(B) cm = c.most_common() cnt = 0 for v in cm: if v[1] > 1: cnt += (v[1]*(v[1]-1)//2) return cnt print((main()))
18
23
287
373
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) S = [0] for i, a in enumerate(A): S.append(S[i] + a) S = sorted(S) a = Counter(S).most_common() cnt = 0 for i in range(len(a)): cnt += ((a[i][1] - 1) * a[i][1]) // 2 print(cnt)
from itertools import accumulate import collections N = int(eval(input())) A = list(map(int, input().split())) def main(): # 累積和 B = [0] + A B = list(accumulate(B)) c = collections.Counter(B) cm = c.most_common() cnt = 0 for v in cm: if v[1] > 1: cnt += v[1] * (v[1] - 1) // 2 return cnt print((main()))
false
21.73913
[ "-from collections import Counter", "+from itertools import accumulate", "+import collections", "-S = [0]", "-for i, a in enumerate(A):", "- S.append(S[i] + a)", "-S = sorted(S)", "-a = Counter(S).most_common()", "-cnt = 0", "-for i in range(len(a)):", "- cnt += ((a[i][1] - 1) * a[i][1]) // 2", "-print(cnt)", "+", "+", "+def main():", "+ # 累積和", "+ B = [0] + A", "+ B = list(accumulate(B))", "+ c = collections.Counter(B)", "+ cm = c.most_common()", "+ cnt = 0", "+ for v in cm:", "+ if v[1] > 1:", "+ cnt += v[1] * (v[1] - 1) // 2", "+ return cnt", "+", "+", "+print((main()))" ]
false
0.089547
0.093511
0.957614
[ "s972325738", "s267898053" ]
u699296734
p03448
python
s727071207
s643729542
58
26
9,088
9,180
Accepted
Accepted
55.17
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) res = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: res += 1 print(res)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) c_nums = set(50 * i for i in range(c + 1)) res = 0 for i in range(a + 1): for j in range(b + 1): tmp = x - 500 * i - 100 * j if tmp in c_nums: res += 1 print(res)
13
14
255
278
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) res = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: res += 1 print(res)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) c_nums = set(50 * i for i in range(c + 1)) res = 0 for i in range(a + 1): for j in range(b + 1): tmp = x - 500 * i - 100 * j if tmp in c_nums: res += 1 print(res)
false
7.142857
[ "+c_nums = set(50 * i for i in range(c + 1))", "- for k in range(c + 1):", "- if 500 * i + 100 * j + 50 * k == x:", "- res += 1", "+ tmp = x - 500 * i - 100 * j", "+ if tmp in c_nums:", "+ res += 1" ]
false
0.227559
0.084703
2.686544
[ "s727071207", "s643729542" ]
u895515293
p03504
python
s451884108
s951365799
1,124
967
63,448
62,736
Accepted
Accepted
13.97
N,C=list(map(int, input().split())) inl = [tuple(map(int, input().split())) for i in range(N)] inl.sort() res = 0 st = set() for s,t,c in inl: nx = set() for t1, c1 in st: if not (t1 == s and c == c1) and t1 >= s: nx.add((t1,c1)) nx.add((t,c)) st = nx res = max(len(nx), res) print(res)
N,C=list(map(int, input().split())) inl = [tuple(map(int, input().split())) for i in range(N)] inl.sort() res = 0 st = [(0,0)]*30 for s,t,c in inl: nx = (t,c) cnt = 0 for i, (t1, c1) in enumerate(st): if not (t1 == s and c == c1) and t1 >= s: st[i] = (t1,c1) else: st[i] = nx nx = (0, 0) if st[i][0] != 0: cnt += 1 res = max(cnt, res) print(res)
16
21
338
451
N, C = list(map(int, input().split())) inl = [tuple(map(int, input().split())) for i in range(N)] inl.sort() res = 0 st = set() for s, t, c in inl: nx = set() for t1, c1 in st: if not (t1 == s and c == c1) and t1 >= s: nx.add((t1, c1)) nx.add((t, c)) st = nx res = max(len(nx), res) print(res)
N, C = list(map(int, input().split())) inl = [tuple(map(int, input().split())) for i in range(N)] inl.sort() res = 0 st = [(0, 0)] * 30 for s, t, c in inl: nx = (t, c) cnt = 0 for i, (t1, c1) in enumerate(st): if not (t1 == s and c == c1) and t1 >= s: st[i] = (t1, c1) else: st[i] = nx nx = (0, 0) if st[i][0] != 0: cnt += 1 res = max(cnt, res) print(res)
false
23.809524
[ "-st = set()", "+st = [(0, 0)] * 30", "- nx = set()", "- for t1, c1 in st:", "+ nx = (t, c)", "+ cnt = 0", "+ for i, (t1, c1) in enumerate(st):", "- nx.add((t1, c1))", "- nx.add((t, c))", "- st = nx", "- res = max(len(nx), res)", "+ st[i] = (t1, c1)", "+ else:", "+ st[i] = nx", "+ nx = (0, 0)", "+ if st[i][0] != 0:", "+ cnt += 1", "+ res = max(cnt, res)" ]
false
0.038234
0.064434
0.593387
[ "s451884108", "s951365799" ]
u133936772
p03673
python
s254408564
s321725190
135
108
23,492
23,968
Accepted
Accepted
20
n=int(eval(input()));l=list(input().split());print((*l[n-n%2::-2]+l[n%2::2]))
n=int(eval(input()));l=input().split();print((*l[::-2]+l[n%2::2]))
1
1
69
58
n = int(eval(input())) l = list(input().split()) print((*l[n - n % 2 :: -2] + l[n % 2 :: 2]))
n = int(eval(input())) l = input().split() print((*l[::-2] + l[n % 2 :: 2]))
false
0
[ "-l = list(input().split())", "-print((*l[n - n % 2 :: -2] + l[n % 2 :: 2]))", "+l = input().split()", "+print((*l[::-2] + l[n % 2 :: 2]))" ]
false
0.072943
0.040118
1.818208
[ "s254408564", "s321725190" ]
u839857256
p03565
python
s464936016
s922580394
19
17
3,064
3,064
Accepted
Accepted
10.53
s = eval(input()) t = eval(input()) flag = 0 count = 0 new = '' l = [] for i in range(len(s)): if s[i] == '?' or s[i] in t: if count == 0: start = i count += 1 else: if count >= len(t): for j in range(count-len(t)+1): check = 0 for k in range(len(t)): if s[start+j+k] != t[k] and s[start+j+k] != '?': check = 1 break if check == 0: new = s[:start+j] + t + s[start+len(t)+j:] l.append(new) flag = 1 count = 0 if count >= len(t): for j in range(count-len(t)+1): check = 0 for k in range(len(t)): if s[start+j+k] != t[k] and s[start+j+k] != '?': check = 1 break if check == 0: new = s[:start+j] + t + s[start+len(t)+j:] l.append(new) flag = 1 if flag == 0: print('UNRESTORABLE') else: ans = [] for n in l: for i in range(len(n)): if n[i] == '?': n = n[:i] + 'a' + n[i+1:] ans.append(n) print((sorted(ans)[0]))
s = eval(input()) t = eval(input()) ans = '' if len(s) >= len(t): for i in range(len(s)-len(t), -1, -1): s_tmp = s[i:i+len(t)] flag = 0 for j in range(len(t)): if s_tmp[j] == '?': s_tmp = t[:j+1] + s_tmp[j+1:] elif s_tmp[j] != t[j]: flag = 1 break if flag == 0: ans = s[:i] + t + s[i+len(t):] break else: flag = 1 if flag == 0: for i in range(len(ans)): if ans[i] == '?': ans = ans[:i] + 'a' + ans[i+1:] print(ans) else: print('UNRESTORABLE')
48
26
1,251
625
s = eval(input()) t = eval(input()) flag = 0 count = 0 new = "" l = [] for i in range(len(s)): if s[i] == "?" or s[i] in t: if count == 0: start = i count += 1 else: if count >= len(t): for j in range(count - len(t) + 1): check = 0 for k in range(len(t)): if s[start + j + k] != t[k] and s[start + j + k] != "?": check = 1 break if check == 0: new = s[: start + j] + t + s[start + len(t) + j :] l.append(new) flag = 1 count = 0 if count >= len(t): for j in range(count - len(t) + 1): check = 0 for k in range(len(t)): if s[start + j + k] != t[k] and s[start + j + k] != "?": check = 1 break if check == 0: new = s[: start + j] + t + s[start + len(t) + j :] l.append(new) flag = 1 if flag == 0: print("UNRESTORABLE") else: ans = [] for n in l: for i in range(len(n)): if n[i] == "?": n = n[:i] + "a" + n[i + 1 :] ans.append(n) print((sorted(ans)[0]))
s = eval(input()) t = eval(input()) ans = "" if len(s) >= len(t): for i in range(len(s) - len(t), -1, -1): s_tmp = s[i : i + len(t)] flag = 0 for j in range(len(t)): if s_tmp[j] == "?": s_tmp = t[: j + 1] + s_tmp[j + 1 :] elif s_tmp[j] != t[j]: flag = 1 break if flag == 0: ans = s[:i] + t + s[i + len(t) :] break else: flag = 1 if flag == 0: for i in range(len(ans)): if ans[i] == "?": ans = ans[:i] + "a" + ans[i + 1 :] print(ans) else: print("UNRESTORABLE")
false
45.833333
[ "-flag = 0", "-count = 0", "-new = \"\"", "-l = []", "-for i in range(len(s)):", "- if s[i] == \"?\" or s[i] in t:", "- if count == 0:", "- start = i", "- count += 1", "- else:", "- if count >= len(t):", "- for j in range(count - len(t) + 1):", "- check = 0", "- for k in range(len(t)):", "- if s[start + j + k] != t[k] and s[start + j + k] != \"?\":", "- check = 1", "- break", "- if check == 0:", "- new = s[: start + j] + t + s[start + len(t) + j :]", "- l.append(new)", "- flag = 1", "- count = 0", "-if count >= len(t):", "- for j in range(count - len(t) + 1):", "- check = 0", "- for k in range(len(t)):", "- if s[start + j + k] != t[k] and s[start + j + k] != \"?\":", "- check = 1", "+ans = \"\"", "+if len(s) >= len(t):", "+ for i in range(len(s) - len(t), -1, -1):", "+ s_tmp = s[i : i + len(t)]", "+ flag = 0", "+ for j in range(len(t)):", "+ if s_tmp[j] == \"?\":", "+ s_tmp = t[: j + 1] + s_tmp[j + 1 :]", "+ elif s_tmp[j] != t[j]:", "+ flag = 1", "- if check == 0:", "- new = s[: start + j] + t + s[start + len(t) + j :]", "- l.append(new)", "- flag = 1", "+ if flag == 0:", "+ ans = s[:i] + t + s[i + len(t) :]", "+ break", "+else:", "+ flag = 1", "+ for i in range(len(ans)):", "+ if ans[i] == \"?\":", "+ ans = ans[:i] + \"a\" + ans[i + 1 :]", "+ print(ans)", "+else:", "-else:", "- ans = []", "- for n in l:", "- for i in range(len(n)):", "- if n[i] == \"?\":", "- n = n[:i] + \"a\" + n[i + 1 :]", "- ans.append(n)", "- print((sorted(ans)[0]))" ]
false
0.04211
0.038602
1.090872
[ "s464936016", "s922580394" ]
u187620552
p03103
python
s077753972
s711429899
632
458
21,544
21,604
Accepted
Accepted
27.53
n, m = list(map(int, input().split())) stores = [] for i in range(n): store = input().split() stores.append([int(store[i]) for i in range(2)]) stores.sort() drinks = 0 cost = 0 for store in stores: if drinks + store[1] <= m: drinks += store[1] cost += store[0]*store[1] elif drinks + store[1] > m: cost += (m - drinks)*store[0] break print(cost)
n, m = list(map(int, input().split())) stores = [[int(j) for j in input().split()]for i in range(n)] stores.sort() drinks = 0 cost = 0 for store in stores: if drinks + store[1] <= m: drinks += store[1] cost += store[0]*store[1] elif drinks + store[1] > m: cost += (m - drinks)*store[0] break print(cost)
17
14
404
351
n, m = list(map(int, input().split())) stores = [] for i in range(n): store = input().split() stores.append([int(store[i]) for i in range(2)]) stores.sort() drinks = 0 cost = 0 for store in stores: if drinks + store[1] <= m: drinks += store[1] cost += store[0] * store[1] elif drinks + store[1] > m: cost += (m - drinks) * store[0] break print(cost)
n, m = list(map(int, input().split())) stores = [[int(j) for j in input().split()] for i in range(n)] stores.sort() drinks = 0 cost = 0 for store in stores: if drinks + store[1] <= m: drinks += store[1] cost += store[0] * store[1] elif drinks + store[1] > m: cost += (m - drinks) * store[0] break print(cost)
false
17.647059
[ "-stores = []", "-for i in range(n):", "- store = input().split()", "- stores.append([int(store[i]) for i in range(2)])", "+stores = [[int(j) for j in input().split()] for i in range(n)]" ]
false
0.06884
0.051973
1.32453
[ "s077753972", "s711429899" ]
u941407962
p03968
python
s211173480
s214941447
3,358
2,988
51,160
50,548
Accepted
Accepted
11.02
from collections import defaultdict N, = list(map(int, input().split())) def normal(xs): return tuple(min((xs[j:] + xs[:j] for j in range(1, 5)))) dd = defaultdict(int) cc = dict() norm = dict() ss = [] for _ in range(N): xs = list(map(int, input().split())) cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)] x = min(cnd) for item in cnd: norm[item] = x dd[x] += 1 cc[x] = (4 if x[0] == x[1] else 2)if x[0] == x[2] and x[1] == x[3] else 1 ss.append(x) def icr(x): dd[x] += 1 def dcr(x): dd[x] -= 1 def f(ff, gg): a,b,c,d=ff e,h,g,f=gg tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)] for cp in tl: if cp not in norm: return 0 r = 1 for cp in tl: cp = norm[cp] r *= dd[cp]*cc[cp] dcr(cp) for cp in tl: cp = norm[cp] icr(cp) return r r = 0 for i in range(N): ff = ss[i] dcr(ff) for j in range(i+1, N): sl = ss[j] dcr(sl) x, y, z, w = sl sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)] for s in sls: r += f(ff, s) icr(sl) icr(ff) print((r//3))
from collections import defaultdict N, = list(map(int, input().split())) dd = defaultdict(int) cc = dict() norm = dict() ss = [] for _ in range(N): xs = list(map(int, input().split())) cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)] x = min(cnd) for item in cnd: norm[item] = x dd[x] += 1 cc[x] = (4 if x[0] == x[1] else 2)if x[0] == x[2] and x[1] == x[3] else 1 ss.append(x) def f(ff, gg): a,b,c,d=ff e,h,g,f=gg tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)] for i in range(4): if tl[i] not in norm: return 0 tl[i] = norm[tl[i]] r = 1 for cp in tl: r *= dd[cp]*cc[cp] dd[cp] -= 1 for cp in tl: dd[cp] += 1 return r r = 0 for i in range(N): ff = ss[i] dd[ff]-=1 for j in range(i+1, N): sl = ss[j] x, y, z, w = sl dd[sl]-=1 sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)] for s in sls: r += f(ff, s) dd[sl]+=1 dd[ff]+=1 print((r//3))
57
47
1,217
1,080
from collections import defaultdict (N,) = list(map(int, input().split())) def normal(xs): return tuple(min((xs[j:] + xs[:j] for j in range(1, 5)))) dd = defaultdict(int) cc = dict() norm = dict() ss = [] for _ in range(N): xs = list(map(int, input().split())) cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)] x = min(cnd) for item in cnd: norm[item] = x dd[x] += 1 cc[x] = (4 if x[0] == x[1] else 2) if x[0] == x[2] and x[1] == x[3] else 1 ss.append(x) def icr(x): dd[x] += 1 def dcr(x): dd[x] -= 1 def f(ff, gg): a, b, c, d = ff e, h, g, f = gg tl = [(a, e, f, b), (b, f, g, c), (c, g, h, d), (d, h, e, a)] for cp in tl: if cp not in norm: return 0 r = 1 for cp in tl: cp = norm[cp] r *= dd[cp] * cc[cp] dcr(cp) for cp in tl: cp = norm[cp] icr(cp) return r r = 0 for i in range(N): ff = ss[i] dcr(ff) for j in range(i + 1, N): sl = ss[j] dcr(sl) x, y, z, w = sl sls = [(x, y, z, w), (y, z, w, x), (z, w, x, y), (w, x, y, z)] for s in sls: r += f(ff, s) icr(sl) icr(ff) print((r // 3))
from collections import defaultdict (N,) = list(map(int, input().split())) dd = defaultdict(int) cc = dict() norm = dict() ss = [] for _ in range(N): xs = list(map(int, input().split())) cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)] x = min(cnd) for item in cnd: norm[item] = x dd[x] += 1 cc[x] = (4 if x[0] == x[1] else 2) if x[0] == x[2] and x[1] == x[3] else 1 ss.append(x) def f(ff, gg): a, b, c, d = ff e, h, g, f = gg tl = [(a, e, f, b), (b, f, g, c), (c, g, h, d), (d, h, e, a)] for i in range(4): if tl[i] not in norm: return 0 tl[i] = norm[tl[i]] r = 1 for cp in tl: r *= dd[cp] * cc[cp] dd[cp] -= 1 for cp in tl: dd[cp] += 1 return r r = 0 for i in range(N): ff = ss[i] dd[ff] -= 1 for j in range(i + 1, N): sl = ss[j] x, y, z, w = sl dd[sl] -= 1 sls = [(x, y, z, w), (y, z, w, x), (z, w, x, y), (w, x, y, z)] for s in sls: r += f(ff, s) dd[sl] += 1 dd[ff] += 1 print((r // 3))
false
17.54386
[ "-", "-", "-def normal(xs):", "- return tuple(min((xs[j:] + xs[:j] for j in range(1, 5))))", "-", "-", "-def icr(x):", "- dd[x] += 1", "-", "-", "-def dcr(x):", "- dd[x] -= 1", "-", "-", "- for cp in tl:", "- if cp not in norm:", "+ for i in range(4):", "+ if tl[i] not in norm:", "+ tl[i] = norm[tl[i]]", "- cp = norm[cp]", "- dcr(cp)", "+ dd[cp] -= 1", "- cp = norm[cp]", "- icr(cp)", "+ dd[cp] += 1", "- dcr(ff)", "+ dd[ff] -= 1", "- dcr(sl)", "+ dd[sl] -= 1", "- icr(sl)", "- icr(ff)", "+ dd[sl] += 1", "+ dd[ff] += 1" ]
false
0.040599
0.039635
1.024314
[ "s211173480", "s214941447" ]
u150984829
p00106
python
s743051847
s678066602
70
20
5,596
5,612
Accepted
Accepted
71.43
while True: N = int(eval(input())) if N==0: break ans = float('inf') for c200 in range(N//200+1): for c300 in range(N//300+1): for c500 in range(N//500+1): if 200 * c200 + c300 * 300 + c500 * 500 == N: ans = min(ans, 1520*(c200//5)+380*(c200%5)+1870*(c300//4)+550*(c300%4)+2244*(c500//3)+850*(c500%3)) print(ans)
a=[1e4]*51 for i,j in[(2,380),(3,550),(5,850),(10,1520),(12,1870),(15,2244)]: a[i]=j for k in range(51-i): if a[k+i]>a[k]+j:a[k+i]=a[k]+j for n in iter(input,'0'):print((a[int(n)//100]))
10
6
335
194
while True: N = int(eval(input())) if N == 0: break ans = float("inf") for c200 in range(N // 200 + 1): for c300 in range(N // 300 + 1): for c500 in range(N // 500 + 1): if 200 * c200 + c300 * 300 + c500 * 500 == N: ans = min( ans, 1520 * (c200 // 5) + 380 * (c200 % 5) + 1870 * (c300 // 4) + 550 * (c300 % 4) + 2244 * (c500 // 3) + 850 * (c500 % 3), ) print(ans)
a = [1e4] * 51 for i, j in [(2, 380), (3, 550), (5, 850), (10, 1520), (12, 1870), (15, 2244)]: a[i] = j for k in range(51 - i): if a[k + i] > a[k] + j: a[k + i] = a[k] + j for n in iter(input, "0"): print((a[int(n) // 100]))
false
40
[ "-while True:", "- N = int(eval(input()))", "- if N == 0:", "- break", "- ans = float(\"inf\")", "- for c200 in range(N // 200 + 1):", "- for c300 in range(N // 300 + 1):", "- for c500 in range(N // 500 + 1):", "- if 200 * c200 + c300 * 300 + c500 * 500 == N:", "- ans = min(", "- ans,", "- 1520 * (c200 // 5)", "- + 380 * (c200 % 5)", "- + 1870 * (c300 // 4)", "- + 550 * (c300 % 4)", "- + 2244 * (c500 // 3)", "- + 850 * (c500 % 3),", "- )", "- print(ans)", "+a = [1e4] * 51", "+for i, j in [(2, 380), (3, 550), (5, 850), (10, 1520), (12, 1870), (15, 2244)]:", "+ a[i] = j", "+ for k in range(51 - i):", "+ if a[k + i] > a[k] + j:", "+ a[k + i] = a[k] + j", "+for n in iter(input, \"0\"):", "+ print((a[int(n) // 100]))" ]
false
0.036693
0.035503
1.033515
[ "s743051847", "s678066602" ]
u644907318
p03837
python
s712741229
s972409418
393
98
56,796
68,168
Accepted
Accepted
75.06
import heapq INFTY = 10**6 N,M = list(map(int,input().split())) G = {i:[] for i in range(1,N+1)} Arc = {} for _ in range(M): a,b,c = list(map(int,input().split())) G[a].append((b,c)) G[b].append((a,c)) Arc[(a,b)]=0 Arc[(b,a)]=0 for s in range(1,N+1): dist = [INFTY for _ in range(N+1)] dist[s] = 0 hist = [0 for _ in range(N+1)] heap = [(0,s)] pre = {} while heap: d,x = heapq.heappop(heap) if dist[x]<d:continue hist[x] = 1 for y,e in G[x]: if hist[y]==0 and dist[y]>d+e: dist[y] = d+e pre[y] = x heapq.heappush(heap,(d+e,y)) for j in pre: a = j while pre[a]!=s: b = pre[a] Arc[(a,b)] = 1 Arc[(b,a)] = 1 a = b Arc[(a,s)] = 1 Arc[(s,a)] = 1 cnt = 0 for x in Arc: if Arc[x]==0: cnt += 1 print((cnt//2))
INFTY = 10**5+10 N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for _ in range(M)] G = {i:[] for i in range(1,N+1)} dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)] for j in range(M): a,b,c = L[j] G[a].append(b) G[b].append(a) dist[a][b] = c dist[b][a] = c for k in range(1,N+1): for i in range(1,N+1): for j in range(1,N+1): dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) cnt = 0 for j in range(M): a,b,c = L[j] if dist[a][b]<c: cnt += 1 print(cnt)
40
21
958
561
import heapq INFTY = 10**6 N, M = list(map(int, input().split())) G = {i: [] for i in range(1, N + 1)} Arc = {} for _ in range(M): a, b, c = list(map(int, input().split())) G[a].append((b, c)) G[b].append((a, c)) Arc[(a, b)] = 0 Arc[(b, a)] = 0 for s in range(1, N + 1): dist = [INFTY for _ in range(N + 1)] dist[s] = 0 hist = [0 for _ in range(N + 1)] heap = [(0, s)] pre = {} while heap: d, x = heapq.heappop(heap) if dist[x] < d: continue hist[x] = 1 for y, e in G[x]: if hist[y] == 0 and dist[y] > d + e: dist[y] = d + e pre[y] = x heapq.heappush(heap, (d + e, y)) for j in pre: a = j while pre[a] != s: b = pre[a] Arc[(a, b)] = 1 Arc[(b, a)] = 1 a = b Arc[(a, s)] = 1 Arc[(s, a)] = 1 cnt = 0 for x in Arc: if Arc[x] == 0: cnt += 1 print((cnt // 2))
INFTY = 10**5 + 10 N, M = list(map(int, input().split())) L = [list(map(int, input().split())) for _ in range(M)] G = {i: [] for i in range(1, N + 1)} dist = [[INFTY for _ in range(N + 1)] for _ in range(N + 1)] for j in range(M): a, b, c = L[j] G[a].append(b) G[b].append(a) dist[a][b] = c dist[b][a] = c for k in range(1, N + 1): for i in range(1, N + 1): for j in range(1, N + 1): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) cnt = 0 for j in range(M): a, b, c = L[j] if dist[a][b] < c: cnt += 1 print(cnt)
false
47.5
[ "-import heapq", "-", "-INFTY = 10**6", "+INFTY = 10**5 + 10", "+L = [list(map(int, input().split())) for _ in range(M)]", "-Arc = {}", "-for _ in range(M):", "- a, b, c = list(map(int, input().split()))", "- G[a].append((b, c))", "- G[b].append((a, c))", "- Arc[(a, b)] = 0", "- Arc[(b, a)] = 0", "-for s in range(1, N + 1):", "- dist = [INFTY for _ in range(N + 1)]", "- dist[s] = 0", "- hist = [0 for _ in range(N + 1)]", "- heap = [(0, s)]", "- pre = {}", "- while heap:", "- d, x = heapq.heappop(heap)", "- if dist[x] < d:", "- continue", "- hist[x] = 1", "- for y, e in G[x]:", "- if hist[y] == 0 and dist[y] > d + e:", "- dist[y] = d + e", "- pre[y] = x", "- heapq.heappush(heap, (d + e, y))", "- for j in pre:", "- a = j", "- while pre[a] != s:", "- b = pre[a]", "- Arc[(a, b)] = 1", "- Arc[(b, a)] = 1", "- a = b", "- Arc[(a, s)] = 1", "- Arc[(s, a)] = 1", "+dist = [[INFTY for _ in range(N + 1)] for _ in range(N + 1)]", "+for j in range(M):", "+ a, b, c = L[j]", "+ G[a].append(b)", "+ G[b].append(a)", "+ dist[a][b] = c", "+ dist[b][a] = c", "+for k in range(1, N + 1):", "+ for i in range(1, N + 1):", "+ for j in range(1, N + 1):", "+ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "-for x in Arc:", "- if Arc[x] == 0:", "+for j in range(M):", "+ a, b, c = L[j]", "+ if dist[a][b] < c:", "-print((cnt // 2))", "+print(cnt)" ]
false
0.040685
0.036295
1.120937
[ "s712741229", "s972409418" ]
u934740772
p03575
python
s355467940
s117797648
23
20
3,064
3,064
Accepted
Accepted
13.04
n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] def bfs(i, edges, r): if all(r): return True if r[i]: return False r[i] = True if any([bfs(e, edges, r) for e in edges[i]]): return True return False ans = 0 for i in range(m): edges = [[] for _ in range(n)] for j in range(m): if i != j: edges[ab[j][0]-1].append(ab[j][1]-1) edges[ab[j][1]-1].append(ab[j][0]-1) reached = [False for _ in range(n)] if not bfs(0, edges, reached): ans += 1 print(ans)
def dfs(i,edge): if vis[i]==True: return vis[i]=True for j in edge[i]: dfs(j,edge) N,M=list(map(int,input().split())) ab=[[0,0] for _ in range(M)] for i in range(M): a,b=list(map(int,input().split())) ab[i][0],ab[i][1]=a,b ans=0 for i in range(M): edge=[[] for _ in range(N+1)] for j in range(M): if j!=i: edge[ab[j][0]].append(ab[j][1]) edge[ab[j][1]].append(ab[j][0]) vis=[False]*(N+1) vis[0]=True dfs(1,edge) if False in vis: ans+=1 print(ans)
24
25
613
559
n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] def bfs(i, edges, r): if all(r): return True if r[i]: return False r[i] = True if any([bfs(e, edges, r) for e in edges[i]]): return True return False ans = 0 for i in range(m): edges = [[] for _ in range(n)] for j in range(m): if i != j: edges[ab[j][0] - 1].append(ab[j][1] - 1) edges[ab[j][1] - 1].append(ab[j][0] - 1) reached = [False for _ in range(n)] if not bfs(0, edges, reached): ans += 1 print(ans)
def dfs(i, edge): if vis[i] == True: return vis[i] = True for j in edge[i]: dfs(j, edge) N, M = list(map(int, input().split())) ab = [[0, 0] for _ in range(M)] for i in range(M): a, b = list(map(int, input().split())) ab[i][0], ab[i][1] = a, b ans = 0 for i in range(M): edge = [[] for _ in range(N + 1)] for j in range(M): if j != i: edge[ab[j][0]].append(ab[j][1]) edge[ab[j][1]].append(ab[j][0]) vis = [False] * (N + 1) vis[0] = True dfs(1, edge) if False in vis: ans += 1 print(ans)
false
4
[ "-n, m = list(map(int, input().split()))", "-ab = [list(map(int, input().split())) for _ in range(m)]", "+def dfs(i, edge):", "+ if vis[i] == True:", "+ return", "+ vis[i] = True", "+ for j in edge[i]:", "+ dfs(j, edge)", "-def bfs(i, edges, r):", "- if all(r):", "- return True", "- if r[i]:", "- return False", "- r[i] = True", "- if any([bfs(e, edges, r) for e in edges[i]]):", "- return True", "- return False", "-", "-", "+N, M = list(map(int, input().split()))", "+ab = [[0, 0] for _ in range(M)]", "+for i in range(M):", "+ a, b = list(map(int, input().split()))", "+ ab[i][0], ab[i][1] = a, b", "-for i in range(m):", "- edges = [[] for _ in range(n)]", "- for j in range(m):", "- if i != j:", "- edges[ab[j][0] - 1].append(ab[j][1] - 1)", "- edges[ab[j][1] - 1].append(ab[j][0] - 1)", "- reached = [False for _ in range(n)]", "- if not bfs(0, edges, reached):", "+for i in range(M):", "+ edge = [[] for _ in range(N + 1)]", "+ for j in range(M):", "+ if j != i:", "+ edge[ab[j][0]].append(ab[j][1])", "+ edge[ab[j][1]].append(ab[j][0])", "+ vis = [False] * (N + 1)", "+ vis[0] = True", "+ dfs(1, edge)", "+ if False in vis:" ]
false
0.079254
0.037934
2.089263
[ "s355467940", "s117797648" ]
u347600233
p02688
python
s429927942
s960775871
29
26
9,124
9,172
Accepted
Accepted
10.34
n, k = list(map(int, input().split())) a = set() for i in range(k): d = int(eval(input())) a |= set(map(int, input().split())) print((len(set(range(1, n + 1)) - a)))
n, k = list(map(int, input().split())) a = set() for i in range(k): d = int(eval(input())) a |= set(map(int, input().split())) print((n - len(a)))
6
6
164
145
n, k = list(map(int, input().split())) a = set() for i in range(k): d = int(eval(input())) a |= set(map(int, input().split())) print((len(set(range(1, n + 1)) - a)))
n, k = list(map(int, input().split())) a = set() for i in range(k): d = int(eval(input())) a |= set(map(int, input().split())) print((n - len(a)))
false
0
[ "-print((len(set(range(1, n + 1)) - a)))", "+print((n - len(a)))" ]
false
0.047134
0.043134
1.092738
[ "s429927942", "s960775871" ]
u257162238
p03044
python
s663648391
s597690596
1,037
905
47,176
59,336
Accepted
Accepted
12.73
import numpy as np def read(): N = int(input().strip()) # N <= 10**5 to = [[] for _ in range(N)] cost = [[] for _ in range(N)] for i in range(N-1): # u[i] < v[i] は保証されている u, v, w = list(map(int, input().strip().split())) to[u-1].append(v-1) to[v-1].append(u-1) cost[u-1].append(w % 2) cost[v-1].append(w % 2) return N, to, cost def solve(N, to, cost): c = [-1] * N # -1: unvisited, 0: white, 1: black q = list() c[0] = 0 q.append(0) while len(q) > 0: s = q.pop() for t, co in zip(to[s], cost[s]): if c[t] == -1: if co: c[t] = 1 - c[s] else: c[t] = c[s] q.append(t) return c if __name__ == '__main__': inputs = read() colors = solve(*inputs) for col in colors: print(("%d" % col))
import numpy as np def read(): N = int(input().strip()) # N <= 10**5 edges = dict() for i in range(N-1): # u[i] < v[i] は保証されている u, v, w = list(map(int, input().strip().split())) if u - 1 in list(edges.keys()): edges[u - 1].update({v - 1: w % 2}) else: edges.update({u - 1: {v - 1: w % 2}}) if v - 1 in list(edges.keys()): edges[v - 1].update({u - 1: w % 2}) else: edges.update({v - 1: {u - 1: w % 2}}) return N, edges def solve(N, edges): c = [-1] * N # -1: unvisited, 0: white, 1: black stack = list() c[0] = 0 stack.append(0) while len(stack) > 0: s = stack.pop() for t in list(edges[s].keys()): if c[t] == -1: if edges[s][t]: c[t] = 1 - c[s] else: c[t] = c[s] stack.append(t) return c if __name__ == '__main__': inputs = read() colors = solve(*inputs) for col in colors: print(("%d" % col))
39
42
952
1,095
import numpy as np def read(): N = int(input().strip()) # N <= 10**5 to = [[] for _ in range(N)] cost = [[] for _ in range(N)] for i in range(N - 1): # u[i] < v[i] は保証されている u, v, w = list(map(int, input().strip().split())) to[u - 1].append(v - 1) to[v - 1].append(u - 1) cost[u - 1].append(w % 2) cost[v - 1].append(w % 2) return N, to, cost def solve(N, to, cost): c = [-1] * N # -1: unvisited, 0: white, 1: black q = list() c[0] = 0 q.append(0) while len(q) > 0: s = q.pop() for t, co in zip(to[s], cost[s]): if c[t] == -1: if co: c[t] = 1 - c[s] else: c[t] = c[s] q.append(t) return c if __name__ == "__main__": inputs = read() colors = solve(*inputs) for col in colors: print(("%d" % col))
import numpy as np def read(): N = int(input().strip()) # N <= 10**5 edges = dict() for i in range(N - 1): # u[i] < v[i] は保証されている u, v, w = list(map(int, input().strip().split())) if u - 1 in list(edges.keys()): edges[u - 1].update({v - 1: w % 2}) else: edges.update({u - 1: {v - 1: w % 2}}) if v - 1 in list(edges.keys()): edges[v - 1].update({u - 1: w % 2}) else: edges.update({v - 1: {u - 1: w % 2}}) return N, edges def solve(N, edges): c = [-1] * N # -1: unvisited, 0: white, 1: black stack = list() c[0] = 0 stack.append(0) while len(stack) > 0: s = stack.pop() for t in list(edges[s].keys()): if c[t] == -1: if edges[s][t]: c[t] = 1 - c[s] else: c[t] = c[s] stack.append(t) return c if __name__ == "__main__": inputs = read() colors = solve(*inputs) for col in colors: print(("%d" % col))
false
7.142857
[ "- to = [[] for _ in range(N)]", "- cost = [[] for _ in range(N)]", "+ edges = dict()", "- to[u - 1].append(v - 1)", "- to[v - 1].append(u - 1)", "- cost[u - 1].append(w % 2)", "- cost[v - 1].append(w % 2)", "- return N, to, cost", "+ if u - 1 in list(edges.keys()):", "+ edges[u - 1].update({v - 1: w % 2})", "+ else:", "+ edges.update({u - 1: {v - 1: w % 2}})", "+ if v - 1 in list(edges.keys()):", "+ edges[v - 1].update({u - 1: w % 2})", "+ else:", "+ edges.update({v - 1: {u - 1: w % 2}})", "+ return N, edges", "-def solve(N, to, cost):", "+def solve(N, edges):", "- q = list()", "+ stack = list()", "- q.append(0)", "- while len(q) > 0:", "- s = q.pop()", "- for t, co in zip(to[s], cost[s]):", "+ stack.append(0)", "+ while len(stack) > 0:", "+ s = stack.pop()", "+ for t in list(edges[s].keys()):", "- if co:", "+ if edges[s][t]:", "- q.append(t)", "+ stack.append(t)" ]
false
0.105054
0.105271
0.997933
[ "s663648391", "s597690596" ]
u496744988
p03645
python
s747438425
s352010181
634
344
62,228
21,360
Accepted
Accepted
45.74
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import pprint import random import sys import time sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) 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 MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return (m * n // fractions.gcd(m, n)) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x,y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v,depth): # ノードに訪れた visited[v] = 1 if depth == 2: return for a, b in sides: if v == a-1: depth += 1 dfs(b-1, depth) depth -= 1 n, m = MI() sides = [LI() for _ in range(m)] islands = [[0] * 2 for _ in range(n)] for a, b in sides: if a-1 == 0: islands[b-1][0] = 1 if b-1 == n-1: islands[a-1][1] = 1 for a, b in islands: if a == b == 1: print('POSSIBLE') exit() print('IMPOSSIBLE')
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import pprint import random import sys import time sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) 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 MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return (m * n // fractions.gcd(m, n)) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x,y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v,depth): # ノードに訪れた visited[v] = 1 if depth == 2: return for a, b in sides: if v == a-1: depth += 1 dfs(b-1, depth) depth -= 1 n, m = MI() a, b = set(), set() for i in range(m): x, y = MI() if x == 1: a.add(y) if y == n: b.add(x) print(("POSSIBLE" if a&b else "IMPOSSIBLE"))
68
63
1,643
1,515
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import pprint import random import sys import time sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) 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 MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return m * n // fractions.gcd(m, n) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x, y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v, depth): # ノードに訪れた visited[v] = 1 if depth == 2: return for a, b in sides: if v == a - 1: depth += 1 dfs(b - 1, depth) depth -= 1 n, m = MI() sides = [LI() for _ in range(m)] islands = [[0] * 2 for _ in range(n)] for a, b in sides: if a - 1 == 0: islands[b - 1][0] = 1 if b - 1 == n - 1: islands[a - 1][1] = 1 for a, b in islands: if a == b == 1: print("POSSIBLE") exit() print("IMPOSSIBLE")
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import pprint import random import sys import time sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) 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 MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return m * n // fractions.gcd(m, n) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x, y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v, depth): # ノードに訪れた visited[v] = 1 if depth == 2: return for a, b in sides: if v == a - 1: depth += 1 dfs(b - 1, depth) depth -= 1 n, m = MI() a, b = set(), set() for i in range(m): x, y = MI() if x == 1: a.add(y) if y == n: b.add(x) print(("POSSIBLE" if a & b else "IMPOSSIBLE"))
false
7.352941
[ "-sides = [LI() for _ in range(m)]", "-islands = [[0] * 2 for _ in range(n)]", "-for a, b in sides:", "- if a - 1 == 0:", "- islands[b - 1][0] = 1", "- if b - 1 == n - 1:", "- islands[a - 1][1] = 1", "-for a, b in islands:", "- if a == b == 1:", "- print(\"POSSIBLE\")", "- exit()", "-print(\"IMPOSSIBLE\")", "+a, b = set(), set()", "+for i in range(m):", "+ x, y = MI()", "+ if x == 1:", "+ a.add(y)", "+ if y == n:", "+ b.add(x)", "+print((\"POSSIBLE\" if a & b else \"IMPOSSIBLE\"))" ]
false
0.048377
0.049074
0.98581
[ "s747438425", "s352010181" ]
u921518222
p03031
python
s999727449
s274500052
294
201
12,504
41,948
Accepted
Accepted
31.63
import numpy as np n, m = list(map(int, input().split())) S = [] for _ in range(m): *a, = list(map(int, input().split())) l = a[1:] S.append(l) *p, = list(map(int, input().split())) ans = 0 for i in range(2**n): tmp = np.array([i >> j & 1 for j in range(n)]) if p == [sum(tmp[np.array(s)-1]) % 2 for s in S]: ans += 1 print(ans)
n, m = list(map(int, input().split())) S = [] for _ in range(m): S.append(list(map(int, input().split()))[1:]) *p, = list(map(int, input().split())) ans = 0 for i in range(2**n): switch = [i >> j & 1 for j in range(n)] c = 0 for k, s in enumerate(S): count = 0 for s1 in s: if switch[s1-1]: count += 1 if count % 2 == p[k]: c += 1 if m == c: ans += 1 print(ans)
16
20
356
462
import numpy as np n, m = list(map(int, input().split())) S = [] for _ in range(m): (*a,) = list(map(int, input().split())) l = a[1:] S.append(l) (*p,) = list(map(int, input().split())) ans = 0 for i in range(2**n): tmp = np.array([i >> j & 1 for j in range(n)]) if p == [sum(tmp[np.array(s) - 1]) % 2 for s in S]: ans += 1 print(ans)
n, m = list(map(int, input().split())) S = [] for _ in range(m): S.append(list(map(int, input().split()))[1:]) (*p,) = list(map(int, input().split())) ans = 0 for i in range(2**n): switch = [i >> j & 1 for j in range(n)] c = 0 for k, s in enumerate(S): count = 0 for s1 in s: if switch[s1 - 1]: count += 1 if count % 2 == p[k]: c += 1 if m == c: ans += 1 print(ans)
false
20
[ "-import numpy as np", "-", "- (*a,) = list(map(int, input().split()))", "- l = a[1:]", "- S.append(l)", "+ S.append(list(map(int, input().split()))[1:])", "- tmp = np.array([i >> j & 1 for j in range(n)])", "- if p == [sum(tmp[np.array(s) - 1]) % 2 for s in S]:", "+ switch = [i >> j & 1 for j in range(n)]", "+ c = 0", "+ for k, s in enumerate(S):", "+ count = 0", "+ for s1 in s:", "+ if switch[s1 - 1]:", "+ count += 1", "+ if count % 2 == p[k]:", "+ c += 1", "+ if m == c:" ]
false
0.4084
0.039105
10.443601
[ "s999727449", "s274500052" ]
u350064373
p02409
python
s339254205
s052873432
60
40
7,732
7,772
Accepted
Accepted
33.33
R=range l=[[[0 for i in R(10)]for j in R(3)]for s in R(4)] for i in R(int(eval(input()))):b,f,r,v=list(map(int,input().split()));l[b-1][f-1][r-1]+=v for i in R(4): for k in l[i]:print(("",*k)) if i!=3:print(("#"*20))
R=range I=input p=print l=[[[0 for i in R(10)]for j in R(3)]for s in R(4)] for i in R(int(I())):b,f,r,v=map(int,I().split());l[b-1][f-1][r-1]+=v for i in R(4): for k in l[i]:p("",*k) if i!=3:p("#"*20)
6
8
207
209
R = range l = [[[0 for i in R(10)] for j in R(3)] for s in R(4)] for i in R(int(eval(input()))): b, f, r, v = list(map(int, input().split())) l[b - 1][f - 1][r - 1] += v for i in R(4): for k in l[i]: print(("", *k)) if i != 3: print(("#" * 20))
R = range I = input p = print l = [[[0 for i in R(10)] for j in R(3)] for s in R(4)] for i in R(int(I())): b, f, r, v = map(int, I().split()) l[b - 1][f - 1][r - 1] += v for i in R(4): for k in l[i]: p("", *k) if i != 3: p("#" * 20)
false
25
[ "+I = input", "+p = print", "-for i in R(int(eval(input()))):", "- b, f, r, v = list(map(int, input().split()))", "+for i in R(int(I())):", "+ b, f, r, v = map(int, I().split())", "- print((\"\", *k))", "+ p(\"\", *k)", "- print((\"#\" * 20))", "+ p(\"#\" * 20)" ]
false
0.039142
0.039215
0.998135
[ "s339254205", "s052873432" ]
u644907318
p03107
python
s419354453
s882705877
183
165
39,280
39,280
Accepted
Accepted
9.84
S = input().strip() N = len(S) k = 0 for i in range(N): if S[i]=="0": k += 1 m = min(k,N-k) print((2*m))
S = input().strip() N = len(S) cnt = 0 for i in range(N): if S[i]=="1": cnt += 1 print((min(cnt,N-cnt)*2))
8
7
121
122
S = input().strip() N = len(S) k = 0 for i in range(N): if S[i] == "0": k += 1 m = min(k, N - k) print((2 * m))
S = input().strip() N = len(S) cnt = 0 for i in range(N): if S[i] == "1": cnt += 1 print((min(cnt, N - cnt) * 2))
false
12.5
[ "-k = 0", "+cnt = 0", "- if S[i] == \"0\":", "- k += 1", "-m = min(k, N - k)", "-print((2 * m))", "+ if S[i] == \"1\":", "+ cnt += 1", "+print((min(cnt, N - cnt) * 2))" ]
false
0.098092
0.007684
12.765436
[ "s419354453", "s882705877" ]
u493520238
p03472
python
s213476154
s771818748
1,088
211
70,104
86,700
Accepted
Accepted
80.61
import math n,h = list(map(int, input().split())) al = [] bl = [] for _ in range(n): a,b = list(map(int, input().split())) al.append((a,'swing')) bl.append((b,'throw')) abl = al + bl abl.sort(reverse=True) remain_h = h ans = 0 for v in abl: damage, command = v if command == 'swing': ans += math.ceil(remain_h/damage) break else: ans += 1 remain_h -= damage if remain_h <= 0: break print(ans)
n,h = list(map(int, input().split())) al = [] bl = [] for _ in range(n): a,b = list(map(int, input().split())) al.append(a) bl.append(b) al.sort(reverse=True) bl.sort(reverse=True) amax = al[0] ans = 0 rem = h for b in bl: if b >= amax: rem -= b ans += 1 else: break if rem <= 0: print(ans) exit() cnt = (rem-1)//amax + 1 ans += cnt print(ans)
27
27
486
424
import math n, h = list(map(int, input().split())) al = [] bl = [] for _ in range(n): a, b = list(map(int, input().split())) al.append((a, "swing")) bl.append((b, "throw")) abl = al + bl abl.sort(reverse=True) remain_h = h ans = 0 for v in abl: damage, command = v if command == "swing": ans += math.ceil(remain_h / damage) break else: ans += 1 remain_h -= damage if remain_h <= 0: break print(ans)
n, h = list(map(int, input().split())) al = [] bl = [] for _ in range(n): a, b = list(map(int, input().split())) al.append(a) bl.append(b) al.sort(reverse=True) bl.sort(reverse=True) amax = al[0] ans = 0 rem = h for b in bl: if b >= amax: rem -= b ans += 1 else: break if rem <= 0: print(ans) exit() cnt = (rem - 1) // amax + 1 ans += cnt print(ans)
false
0
[ "-import math", "-", "- al.append((a, \"swing\"))", "- bl.append((b, \"throw\"))", "-abl = al + bl", "-abl.sort(reverse=True)", "-remain_h = h", "+ al.append(a)", "+ bl.append(b)", "+al.sort(reverse=True)", "+bl.sort(reverse=True)", "+amax = al[0]", "-for v in abl:", "- damage, command = v", "- if command == \"swing\":", "- ans += math.ceil(remain_h / damage)", "+rem = h", "+for b in bl:", "+ if b >= amax:", "+ rem -= b", "+ ans += 1", "+ else:", "- else:", "- ans += 1", "- remain_h -= damage", "- if remain_h <= 0:", "- break", "+ if rem <= 0:", "+ print(ans)", "+ exit()", "+cnt = (rem - 1) // amax + 1", "+ans += cnt" ]
false
0.036672
0.075417
0.486252
[ "s213476154", "s771818748" ]
u594244257
p02954
python
s429808366
s732584285
117
92
20,900
10,484
Accepted
Accepted
21.37
def solve(): S = eval(input()) result = [0] * len(S) children_position = [] even_odd_sum = [] even_sum = 0 odd_sum = 0 R_i = 0 L_i = -2 for idx, s in enumerate(S): if s == 'R': R_i = idx if L_i+1 == R_i: even_odd_sum.append((even_sum, odd_sum)) even_sum = 0 odd_sum = 0 elif s == 'L': L_i = idx if R_i+1 == idx: children_position.append((R_i, L_i)) even_sum += idx % 2 == 0 odd_sum += idx % 2 == 1 even_odd_sum.append((even_sum, odd_sum)) # print(children_position, even_odd_sum) for idx in range(len(children_position)): t = children_position[idx] even_odd_R = t[0] % 2 even_odd_L = t[1] % 2 result[t[0]] = even_odd_sum[idx][0] if even_odd_R == 0 else even_odd_sum[idx][1] result[t[1]] = even_odd_sum[idx][0] if even_odd_L == 0 else even_odd_sum[idx][1] print((' '.join(map(str, result)))) solve()
S = eval(input()) ret = [0] * len(S) cont_R = 0 idx_R = 0 cont_L = 0 for i,s in enumerate(S): if s == 'R': cont_L = 0 cont_R += 1 idx_R = i idx_L = i+1 elif s == 'L': if idx_L == i: q = cont_R//2 r = cont_R%2 ret[idx_R] = q+r ret[idx_L] = q # print(ret,idx_R,idx_L) cont_R = 0 cont_L += 1 if cont_L % 2 == 1: ret[idx_L] += 1 else: ret[idx_R] += 1 print((' '.join(map(str, ret))))
39
27
1,135
563
def solve(): S = eval(input()) result = [0] * len(S) children_position = [] even_odd_sum = [] even_sum = 0 odd_sum = 0 R_i = 0 L_i = -2 for idx, s in enumerate(S): if s == "R": R_i = idx if L_i + 1 == R_i: even_odd_sum.append((even_sum, odd_sum)) even_sum = 0 odd_sum = 0 elif s == "L": L_i = idx if R_i + 1 == idx: children_position.append((R_i, L_i)) even_sum += idx % 2 == 0 odd_sum += idx % 2 == 1 even_odd_sum.append((even_sum, odd_sum)) # print(children_position, even_odd_sum) for idx in range(len(children_position)): t = children_position[idx] even_odd_R = t[0] % 2 even_odd_L = t[1] % 2 result[t[0]] = even_odd_sum[idx][0] if even_odd_R == 0 else even_odd_sum[idx][1] result[t[1]] = even_odd_sum[idx][0] if even_odd_L == 0 else even_odd_sum[idx][1] print((" ".join(map(str, result)))) solve()
S = eval(input()) ret = [0] * len(S) cont_R = 0 idx_R = 0 cont_L = 0 for i, s in enumerate(S): if s == "R": cont_L = 0 cont_R += 1 idx_R = i idx_L = i + 1 elif s == "L": if idx_L == i: q = cont_R // 2 r = cont_R % 2 ret[idx_R] = q + r ret[idx_L] = q # print(ret,idx_R,idx_L) cont_R = 0 cont_L += 1 if cont_L % 2 == 1: ret[idx_L] += 1 else: ret[idx_R] += 1 print((" ".join(map(str, ret))))
false
30.769231
[ "-def solve():", "- S = eval(input())", "- result = [0] * len(S)", "- children_position = []", "- even_odd_sum = []", "- even_sum = 0", "- odd_sum = 0", "- R_i = 0", "- L_i = -2", "- for idx, s in enumerate(S):", "- if s == \"R\":", "- R_i = idx", "- if L_i + 1 == R_i:", "- even_odd_sum.append((even_sum, odd_sum))", "- even_sum = 0", "- odd_sum = 0", "- elif s == \"L\":", "- L_i = idx", "- if R_i + 1 == idx:", "- children_position.append((R_i, L_i))", "- even_sum += idx % 2 == 0", "- odd_sum += idx % 2 == 1", "- even_odd_sum.append((even_sum, odd_sum))", "- # print(children_position, even_odd_sum)", "- for idx in range(len(children_position)):", "- t = children_position[idx]", "- even_odd_R = t[0] % 2", "- even_odd_L = t[1] % 2", "- result[t[0]] = even_odd_sum[idx][0] if even_odd_R == 0 else even_odd_sum[idx][1]", "- result[t[1]] = even_odd_sum[idx][0] if even_odd_L == 0 else even_odd_sum[idx][1]", "- print((\" \".join(map(str, result))))", "-", "-", "-solve()", "+S = eval(input())", "+ret = [0] * len(S)", "+cont_R = 0", "+idx_R = 0", "+cont_L = 0", "+for i, s in enumerate(S):", "+ if s == \"R\":", "+ cont_L = 0", "+ cont_R += 1", "+ idx_R = i", "+ idx_L = i + 1", "+ elif s == \"L\":", "+ if idx_L == i:", "+ q = cont_R // 2", "+ r = cont_R % 2", "+ ret[idx_R] = q + r", "+ ret[idx_L] = q", "+ # print(ret,idx_R,idx_L)", "+ cont_R = 0", "+ cont_L += 1", "+ if cont_L % 2 == 1:", "+ ret[idx_L] += 1", "+ else:", "+ ret[idx_R] += 1", "+print((\" \".join(map(str, ret))))" ]
false
0.095458
0.045414
2.101939
[ "s429808366", "s732584285" ]
u334712262
p02788
python
s445704835
s842611603
1,254
1,147
110,344
100,796
Accepted
Accepted
8.53
# -*- 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(N, D, A, XH): XH.sort() X = [x for x, _ in XH] H = [h for _, h in XH] q = deque() ans = 0 dmg = 0 for x, h in XH: while q and q[0][0] < x: _, d = q.popleft() dmg -= d if h <= dmg: continue a = -(-(h - dmg) // A) ans += a q.append((x+2*D, a*A)) dmg += a*A return ans def main(): N, D, A = read_int_n() XH = [read_int_n() for _ in range(N)] print(slv(N, D, A, XH)) 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(N, D, A, XH): XH.sort() q = deque() ans = 0 dmg = 0 for x, h in XH: while q and q[0][0] < x: _, d = q.popleft() dmg -= d if h <= dmg: continue a = -(-(h - dmg) // A) ans += a q.append((x+2*D, a*A)) dmg += a*A return ans def main(): N, D, A = read_int_n() XH = [read_int_n() for _ in range(N)] print(slv(N, D, A, XH)) if __name__ == '__main__': main()
88
86
1,667
1,611
# -*- 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(N, D, A, XH): XH.sort() X = [x for x, _ in XH] H = [h for _, h in XH] q = deque() ans = 0 dmg = 0 for x, h in XH: while q and q[0][0] < x: _, d = q.popleft() dmg -= d if h <= dmg: continue a = -(-(h - dmg) // A) ans += a q.append((x + 2 * D, a * A)) dmg += a * A return ans def main(): N, D, A = read_int_n() XH = [read_int_n() for _ in range(N)] print(slv(N, D, A, XH)) 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(N, D, A, XH): XH.sort() q = deque() ans = 0 dmg = 0 for x, h in XH: while q and q[0][0] < x: _, d = q.popleft() dmg -= d if h <= dmg: continue a = -(-(h - dmg) // A) ans += a q.append((x + 2 * D, a * A)) dmg += a * A return ans def main(): N, D, A = read_int_n() XH = [read_int_n() for _ in range(N)] print(slv(N, D, A, XH)) if __name__ == "__main__": main()
false
2.272727
[ "- X = [x for x, _ in XH]", "- H = [h for _, h in XH]" ]
false
0.10194
0.091371
1.115677
[ "s445704835", "s842611603" ]
u953237709
p03060
python
s383279887
s010826167
521
18
42,348
3,060
Accepted
Accepted
96.55
n = int(eval(input())) value = list(map(int, input().split())) cost = list(map(int, input().split())) ret = 0 for state in range((1 << n)): values = costs = 0 for shift in range(n): if (state >> shift) & 1 == 1: values += value[shift] costs += cost[shift] ret = max(ret, values - costs) print(ret)
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) print((sum(max(v[i] - c[i], 0) for i in range(n))))
12
4
346
141
n = int(eval(input())) value = list(map(int, input().split())) cost = list(map(int, input().split())) ret = 0 for state in range((1 << n)): values = costs = 0 for shift in range(n): if (state >> shift) & 1 == 1: values += value[shift] costs += cost[shift] ret = max(ret, values - costs) print(ret)
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) print((sum(max(v[i] - c[i], 0) for i in range(n))))
false
66.666667
[ "-value = list(map(int, input().split()))", "-cost = list(map(int, input().split()))", "-ret = 0", "-for state in range((1 << n)):", "- values = costs = 0", "- for shift in range(n):", "- if (state >> shift) & 1 == 1:", "- values += value[shift]", "- costs += cost[shift]", "- ret = max(ret, values - costs)", "-print(ret)", "+v = list(map(int, input().split()))", "+c = list(map(int, input().split()))", "+print((sum(max(v[i] - c[i], 0) for i in range(n))))" ]
false
0.082624
0.037066
2.229106
[ "s383279887", "s010826167" ]
u562935282
p03846
python
s282520493
s306319457
107
65
14,008
14,820
Accepted
Accepted
39.25
def inpl(): return input().split() n = int(eval(input())) a = sorted(list(map(int, inpl()))) p = 10 ** 9 + 7 if a[0] == 0: st = 1 next_value = 2 else: st = 0 next_value = 1 ans = 1 found = False for i in range(st, n): if (next_value == a[i]): if found: next_value += 2 found = False ans *= 2 if ans > p: ans %= p else: found = True else: ans = 0 break print(ans)
from collections import Counter MOD = 10 ** 9 + 7 N = int(eval(input())) a = list(map(int, input().split())) ans = 2 ** (N // 2) % MOD flg = True b = Counter(a) if N % 2 == 1: for i in range(0, N, 2): if i == 0: if b[i] != 1: flg = False break else: if b[i] != 2: flg = False break else: for i in range(1, N, 2): if b[i] != 2: flg = False break print((ans if flg else 0))
29
28
523
540
def inpl(): return input().split() n = int(eval(input())) a = sorted(list(map(int, inpl()))) p = 10**9 + 7 if a[0] == 0: st = 1 next_value = 2 else: st = 0 next_value = 1 ans = 1 found = False for i in range(st, n): if next_value == a[i]: if found: next_value += 2 found = False ans *= 2 if ans > p: ans %= p else: found = True else: ans = 0 break print(ans)
from collections import Counter MOD = 10**9 + 7 N = int(eval(input())) a = list(map(int, input().split())) ans = 2 ** (N // 2) % MOD flg = True b = Counter(a) if N % 2 == 1: for i in range(0, N, 2): if i == 0: if b[i] != 1: flg = False break else: if b[i] != 2: flg = False break else: for i in range(1, N, 2): if b[i] != 2: flg = False break print((ans if flg else 0))
false
3.448276
[ "-def inpl():", "- return input().split()", "+from collections import Counter", "-", "-n = int(eval(input()))", "-a = sorted(list(map(int, inpl())))", "-p = 10**9 + 7", "-if a[0] == 0:", "- st = 1", "- next_value = 2", "+MOD = 10**9 + 7", "+N = int(eval(input()))", "+a = list(map(int, input().split()))", "+ans = 2 ** (N // 2) % MOD", "+flg = True", "+b = Counter(a)", "+if N % 2 == 1:", "+ for i in range(0, N, 2):", "+ if i == 0:", "+ if b[i] != 1:", "+ flg = False", "+ break", "+ else:", "+ if b[i] != 2:", "+ flg = False", "+ break", "- st = 0", "- next_value = 1", "-ans = 1", "-found = False", "-for i in range(st, n):", "- if next_value == a[i]:", "- if found:", "- next_value += 2", "- found = False", "- ans *= 2", "- if ans > p:", "- ans %= p", "- else:", "- found = True", "- else:", "- ans = 0", "- break", "-print(ans)", "+ for i in range(1, N, 2):", "+ if b[i] != 2:", "+ flg = False", "+ break", "+print((ans if flg else 0))" ]
false
0.095847
0.066413
1.443208
[ "s282520493", "s306319457" ]
u794173881
p02889
python
s166474950
s605410991
1,662
1,024
76,764
74,332
Accepted
Accepted
38.39
from collections import deque import sys import random input = sys.stdin.readline n, m, l = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [[] for i in range(n)] for i in range(m): a, b, cost = info[i] if cost > l: continue a -= 1 b -= 1 graph[a].append((b, cost)) graph[b].append((a, cost)) for i in range(n): graph[i] = random.sample(graph[i], len(graph[i])) def dfs(start): INF = float("inf") visited_t = [INF]*n # 回数, 残り燃料 visited_l = [0]*n visited_t[start] = 0 q = deque([start]) while q: pos = q.popleft() for next_pos, cost in graph[pos]: tmp = cost + visited_l[pos] times = visited_t[pos] next_times = visited_t[next_pos] if tmp <= l: if next_times > times: q.append(next_pos) visited_t[next_pos] = times visited_l[next_pos] = tmp elif next_times == times: if visited_l[next_pos] > tmp: q.append(next_pos) visited_t[next_pos] = times visited_l[next_pos] = tmp else: continue else: tmp = cost if next_times > times + 1: q.append(next_pos) visited_t[next_pos] = times + 1 visited_l[next_pos] = tmp elif next_times == times + 1: if visited_l[next_pos] > tmp: q.append(next_pos) visited_t[next_pos] = times + 1 visited_l[next_pos] = tmp else: continue return visited_t ans = [None]*n for i in range(n): ans[i] = dfs(i) INF = float("inf") q = int(eval(input())) query = [list(map(int, input().split())) for i in range(q)] for i in range(q): a, b = query[i] a -= 1 b -= 1 tmp = ans[a][b] if tmp == INF: print((-1)) else: print(tmp)
from collections import deque import sys input = sys.stdin.readline n, m, l = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [[] for i in range(n)] for i in range(m): a, b, cost = info[i] if cost > l: continue a -= 1 b -= 1 graph[a].append((b, cost)) graph[b].append((a, cost)) def warshall_floid(graph): n = len(graph) INF = 10**18 dp = [[INF]*n for i in range(n)] for i in range(n): dp[i][i] = 0 for i in range(n): for j, cost in graph[i]: dp[i][j] = cost dp[j][i] = cost for k in range(n): for i in range(n): for j in range(n): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) return dp def warshall_floid2(matrix): n = len(matrix) dp = matrix for k in range(n): for i in range(n): for j in range(n): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) return dp dp1 = warshall_floid(graph) INF = 10**18 dp2 = [[INF]*n for i in range(n)] for i in range(n): for j in range(n): if dp1[i][j] <= l: dp2[i][j] = 1 ans = warshall_floid2(dp2) q = int(eval(input())) query = [list(map(int, input().split())) for i in range(q)] for i in range(q): a, b = query[i] a -= 1 b -= 1 if ans[a][b] == 10**18: print((-1)) else: print((ans[a][b] - 1))
77
66
2,199
1,496
from collections import deque import sys import random input = sys.stdin.readline n, m, l = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [[] for i in range(n)] for i in range(m): a, b, cost = info[i] if cost > l: continue a -= 1 b -= 1 graph[a].append((b, cost)) graph[b].append((a, cost)) for i in range(n): graph[i] = random.sample(graph[i], len(graph[i])) def dfs(start): INF = float("inf") visited_t = [INF] * n # 回数, 残り燃料 visited_l = [0] * n visited_t[start] = 0 q = deque([start]) while q: pos = q.popleft() for next_pos, cost in graph[pos]: tmp = cost + visited_l[pos] times = visited_t[pos] next_times = visited_t[next_pos] if tmp <= l: if next_times > times: q.append(next_pos) visited_t[next_pos] = times visited_l[next_pos] = tmp elif next_times == times: if visited_l[next_pos] > tmp: q.append(next_pos) visited_t[next_pos] = times visited_l[next_pos] = tmp else: continue else: tmp = cost if next_times > times + 1: q.append(next_pos) visited_t[next_pos] = times + 1 visited_l[next_pos] = tmp elif next_times == times + 1: if visited_l[next_pos] > tmp: q.append(next_pos) visited_t[next_pos] = times + 1 visited_l[next_pos] = tmp else: continue return visited_t ans = [None] * n for i in range(n): ans[i] = dfs(i) INF = float("inf") q = int(eval(input())) query = [list(map(int, input().split())) for i in range(q)] for i in range(q): a, b = query[i] a -= 1 b -= 1 tmp = ans[a][b] if tmp == INF: print((-1)) else: print(tmp)
from collections import deque import sys input = sys.stdin.readline n, m, l = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [[] for i in range(n)] for i in range(m): a, b, cost = info[i] if cost > l: continue a -= 1 b -= 1 graph[a].append((b, cost)) graph[b].append((a, cost)) def warshall_floid(graph): n = len(graph) INF = 10**18 dp = [[INF] * n for i in range(n)] for i in range(n): dp[i][i] = 0 for i in range(n): for j, cost in graph[i]: dp[i][j] = cost dp[j][i] = cost for k in range(n): for i in range(n): for j in range(n): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) return dp def warshall_floid2(matrix): n = len(matrix) dp = matrix for k in range(n): for i in range(n): for j in range(n): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) return dp dp1 = warshall_floid(graph) INF = 10**18 dp2 = [[INF] * n for i in range(n)] for i in range(n): for j in range(n): if dp1[i][j] <= l: dp2[i][j] = 1 ans = warshall_floid2(dp2) q = int(eval(input())) query = [list(map(int, input().split())) for i in range(q)] for i in range(q): a, b = query[i] a -= 1 b -= 1 if ans[a][b] == 10**18: print((-1)) else: print((ans[a][b] - 1))
false
14.285714
[ "-import random", "-for i in range(n):", "- graph[i] = random.sample(graph[i], len(graph[i]))", "-def dfs(start):", "- INF = float(\"inf\")", "- visited_t = [INF] * n # 回数, 残り燃料", "- visited_l = [0] * n", "- visited_t[start] = 0", "- q = deque([start])", "- while q:", "- pos = q.popleft()", "- for next_pos, cost in graph[pos]:", "- tmp = cost + visited_l[pos]", "- times = visited_t[pos]", "- next_times = visited_t[next_pos]", "- if tmp <= l:", "- if next_times > times:", "- q.append(next_pos)", "- visited_t[next_pos] = times", "- visited_l[next_pos] = tmp", "- elif next_times == times:", "- if visited_l[next_pos] > tmp:", "- q.append(next_pos)", "- visited_t[next_pos] = times", "- visited_l[next_pos] = tmp", "- else:", "- continue", "- else:", "- tmp = cost", "- if next_times > times + 1:", "- q.append(next_pos)", "- visited_t[next_pos] = times + 1", "- visited_l[next_pos] = tmp", "- elif next_times == times + 1:", "- if visited_l[next_pos] > tmp:", "- q.append(next_pos)", "- visited_t[next_pos] = times + 1", "- visited_l[next_pos] = tmp", "- else:", "- continue", "- return visited_t", "+def warshall_floid(graph):", "+ n = len(graph)", "+ INF = 10**18", "+ dp = [[INF] * n for i in range(n)]", "+ for i in range(n):", "+ dp[i][i] = 0", "+ for i in range(n):", "+ for j, cost in graph[i]:", "+ dp[i][j] = cost", "+ dp[j][i] = cost", "+ for k in range(n):", "+ for i in range(n):", "+ for j in range(n):", "+ dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])", "+ return dp", "-ans = [None] * n", "+def warshall_floid2(matrix):", "+ n = len(matrix)", "+ dp = matrix", "+ for k in range(n):", "+ for i in range(n):", "+ for j in range(n):", "+ dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])", "+ return dp", "+", "+", "+dp1 = warshall_floid(graph)", "+INF = 10**18", "+dp2 = [[INF] * n for i in range(n)]", "- ans[i] = dfs(i)", "-INF = float(\"inf\")", "+ for j in range(n):", "+ if dp1[i][j] <= l:", "+ dp2[i][j] = 1", "+ans = warshall_floid2(dp2)", "- tmp = ans[a][b]", "- if tmp == INF:", "+ if ans[a][b] == 10**18:", "- print(tmp)", "+ print((ans[a][b] - 1))" ]
false
0.043256
0.041285
1.04773
[ "s166474950", "s605410991" ]
u699699071
p03854
python
s208264664
s555319095
22
19
3,188
3,188
Accepted
Accepted
13.64
s = eval(input()) t = s.replace("dreameraser","1") t = t.replace("dreamerase","2") t = t.replace("dreamer","3") t = t.replace("eraser","4") t = t.replace("dream","5") t = t.replace("erase","6") try: int(t) print("YES") except : print("NO")
s = eval(input()) t = s.replace("eraser","") t = t.replace("erase","") t = t.replace("dreamer","") t = t.replace("dream","") if len(t)==0: print("YES") else : print("NO")
14
11
260
184
s = eval(input()) t = s.replace("dreameraser", "1") t = t.replace("dreamerase", "2") t = t.replace("dreamer", "3") t = t.replace("eraser", "4") t = t.replace("dream", "5") t = t.replace("erase", "6") try: int(t) print("YES") except: print("NO")
s = eval(input()) t = s.replace("eraser", "") t = t.replace("erase", "") t = t.replace("dreamer", "") t = t.replace("dream", "") if len(t) == 0: print("YES") else: print("NO")
false
21.428571
[ "-t = s.replace(\"dreameraser\", \"1\")", "-t = t.replace(\"dreamerase\", \"2\")", "-t = t.replace(\"dreamer\", \"3\")", "-t = t.replace(\"eraser\", \"4\")", "-t = t.replace(\"dream\", \"5\")", "-t = t.replace(\"erase\", \"6\")", "-try:", "- int(t)", "+t = s.replace(\"eraser\", \"\")", "+t = t.replace(\"erase\", \"\")", "+t = t.replace(\"dreamer\", \"\")", "+t = t.replace(\"dream\", \"\")", "+if len(t) == 0:", "-except:", "+else:" ]
false
0.045394
0.043493
1.043716
[ "s208264664", "s555319095" ]
u222668979
p02945
python
s165863164
s362912647
173
17
38,384
2,940
Accepted
Accepted
90.17
a,b= list(map(int,input().split())) print((max((a+b,a-b,a*b))))
a,b= list(map(int,input().split())) print((max(a+b,a-b,a*b)))
2
2
57
55
a, b = list(map(int, input().split())) print((max((a + b, a - b, a * b))))
a, b = list(map(int, input().split())) print((max(a + b, a - b, a * b)))
false
0
[ "-print((max((a + b, a - b, a * b))))", "+print((max(a + b, a - b, a * b)))" ]
false
0.040125
0.039721
1.010156
[ "s165863164", "s362912647" ]
u977389981
p02988
python
s361514428
s698228872
171
17
38,384
3,060
Accepted
Accepted
90.06
N = int(eval(input())) P = [int(i) for i in input().split()] cnt = 0 for i in range(1, N - 1): A = [P[i - 1], P[i], P[i + 1]] maxA = max(A) minA = min(A) if P[i] != maxA and P[i] != minA: cnt += 1 print(cnt)
n = int(eval(input())) P = [int(i) for i in input().split()] ans = 0 for i in range(1, n - 1): if P[i] != max(P[i - 1], P[i], P[i + 1]) and P[i] != min(P[i - 1], P[i], P[i + 1]): ans += 1 print(ans)
12
9
246
222
N = int(eval(input())) P = [int(i) for i in input().split()] cnt = 0 for i in range(1, N - 1): A = [P[i - 1], P[i], P[i + 1]] maxA = max(A) minA = min(A) if P[i] != maxA and P[i] != minA: cnt += 1 print(cnt)
n = int(eval(input())) P = [int(i) for i in input().split()] ans = 0 for i in range(1, n - 1): if P[i] != max(P[i - 1], P[i], P[i + 1]) and P[i] != min(P[i - 1], P[i], P[i + 1]): ans += 1 print(ans)
false
25
[ "-N = int(eval(input()))", "+n = int(eval(input()))", "-cnt = 0", "-for i in range(1, N - 1):", "- A = [P[i - 1], P[i], P[i + 1]]", "- maxA = max(A)", "- minA = min(A)", "- if P[i] != maxA and P[i] != minA:", "- cnt += 1", "-print(cnt)", "+ans = 0", "+for i in range(1, n - 1):", "+ if P[i] != max(P[i - 1], P[i], P[i + 1]) and P[i] != min(P[i - 1], P[i], P[i + 1]):", "+ ans += 1", "+print(ans)" ]
false
0.048488
0.105494
0.459632
[ "s361514428", "s698228872" ]
u634079249
p02641
python
s089858383
s218218281
176
160
37,552
37,544
Accepted
Accepted
9.09
import sys, os, math, bisect, itertools, collections, heapq, queue from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") X, N = il() P = il() ret = 0 s = MAX for n in range(-101, 102): if n not in P and abs(X-n) < s: s = abs(X-n) ret = n print(ret) if __name__ == '__main__': main()
import sys, os, math, bisect, itertools, collections, heapq, queue from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") X, N = il() P = il() if len(P) == 0: print(X) exit() mx = max(P) p = MAX ret = 0 for n in range(mx + 2): if n not in P and p > abs(X - n): ret = n p = X - n print(ret) if __name__ == '__main__': main()
43
48
1,223
1,293
import sys, os, math, bisect, itertools, collections, heapq, queue from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") X, N = il() P = il() ret = 0 s = MAX for n in range(-101, 102): if n not in P and abs(X - n) < s: s = abs(X - n) ret = n print(ret) if __name__ == "__main__": main()
import sys, os, math, bisect, itertools, collections, heapq, queue from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") X, N = il() P = il() if len(P) == 0: print(X) exit() mx = max(P) p = MAX ret = 0 for n in range(mx + 2): if n not in P and p > abs(X - n): ret = n p = X - n print(ret) if __name__ == "__main__": main()
false
10.416667
[ "+ if len(P) == 0:", "+ print(X)", "+ exit()", "+ mx = max(P)", "+ p = MAX", "- s = MAX", "- for n in range(-101, 102):", "- if n not in P and abs(X - n) < s:", "- s = abs(X - n)", "+ for n in range(mx + 2):", "+ if n not in P and p > abs(X - n):", "+ p = X - n" ]
false
0.036456
0.034755
1.048935
[ "s089858383", "s218218281" ]
u983918956
p03221
python
s362852552
s159282118
970
722
65,240
37,696
Accepted
Accepted
25.57
N,M = list(map(int,input().split())) city = [] count = 1 for i in range(M): p,y = list(map(int,input().split())) city.append([p,y]) city_sorted = sorted(city) for i in range(M): if city_sorted[i][0] == city_sorted[i-1][0] and i != 0: count += 1 else: count = 1 city_sorted[i][1] = count for i in range(M): number_f = "0"*(6-len(str(city[i][0]))) + str(city[i][0]) number_b = "0"*(6-len(str(city[i][1]))) + str(city[i][1]) print((number_f + number_b))
N,M = list(map(int,input().split())) info = [list(map(int,input().split())) for i in range(M)] info_new = sorted(info,key=lambda x:(x[0],x[1])) note = info_new[0][0] cnt = 1 for i in range(M): if info_new[i][0] == note: info_new[i][1] = cnt cnt += 1 else: note = info_new[i][0] cnt = 1 info_new[i][1] = cnt cnt += 1 for i in range(M): pri = str(info[i][0]) bir = str(info[i][1]) number = "0"*(6-len(pri)) + pri + "0"*(6-len(bir)) + bir print(number)
17
20
500
543
N, M = list(map(int, input().split())) city = [] count = 1 for i in range(M): p, y = list(map(int, input().split())) city.append([p, y]) city_sorted = sorted(city) for i in range(M): if city_sorted[i][0] == city_sorted[i - 1][0] and i != 0: count += 1 else: count = 1 city_sorted[i][1] = count for i in range(M): number_f = "0" * (6 - len(str(city[i][0]))) + str(city[i][0]) number_b = "0" * (6 - len(str(city[i][1]))) + str(city[i][1]) print((number_f + number_b))
N, M = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(M)] info_new = sorted(info, key=lambda x: (x[0], x[1])) note = info_new[0][0] cnt = 1 for i in range(M): if info_new[i][0] == note: info_new[i][1] = cnt cnt += 1 else: note = info_new[i][0] cnt = 1 info_new[i][1] = cnt cnt += 1 for i in range(M): pri = str(info[i][0]) bir = str(info[i][1]) number = "0" * (6 - len(pri)) + pri + "0" * (6 - len(bir)) + bir print(number)
false
15
[ "-city = []", "-count = 1", "+info = [list(map(int, input().split())) for i in range(M)]", "+info_new = sorted(info, key=lambda x: (x[0], x[1]))", "+note = info_new[0][0]", "+cnt = 1", "- p, y = list(map(int, input().split()))", "- city.append([p, y])", "-city_sorted = sorted(city)", "+ if info_new[i][0] == note:", "+ info_new[i][1] = cnt", "+ cnt += 1", "+ else:", "+ note = info_new[i][0]", "+ cnt = 1", "+ info_new[i][1] = cnt", "+ cnt += 1", "- if city_sorted[i][0] == city_sorted[i - 1][0] and i != 0:", "- count += 1", "- else:", "- count = 1", "- city_sorted[i][1] = count", "-for i in range(M):", "- number_f = \"0\" * (6 - len(str(city[i][0]))) + str(city[i][0])", "- number_b = \"0\" * (6 - len(str(city[i][1]))) + str(city[i][1])", "- print((number_f + number_b))", "+ pri = str(info[i][0])", "+ bir = str(info[i][1])", "+ number = \"0\" * (6 - len(pri)) + pri + \"0\" * (6 - len(bir)) + bir", "+ print(number)" ]
false
0.037289
0.061309
0.608216
[ "s362852552", "s159282118" ]
u677267454
p03087
python
s152183268
s831139804
834
406
7,748
11,876
Accepted
Accepted
51.32
n, q = list(map(int, input().split())) s = eval(input()) t = [0] * (n + 1) for i in range(n): t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0) for i in range(q): l, r = list(map(int, input().split())) print((t[r - 1] - t[l - 1]))
n, q = list(map(int, input().split())) s = eval(input()) t = [0] * (n + 1) for i in range(n): t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0) ans = [] for i in range(q): l, r = list(map(int, input().split())) ans.append(t[r - 1] - t[l - 1]) for a in ans: print(a)
10
14
233
279
n, q = list(map(int, input().split())) s = eval(input()) t = [0] * (n + 1) for i in range(n): t[i + 1] = t[i] + (1 if s[i : i + 2] == "AC" else 0) for i in range(q): l, r = list(map(int, input().split())) print((t[r - 1] - t[l - 1]))
n, q = list(map(int, input().split())) s = eval(input()) t = [0] * (n + 1) for i in range(n): t[i + 1] = t[i] + (1 if s[i : i + 2] == "AC" else 0) ans = [] for i in range(q): l, r = list(map(int, input().split())) ans.append(t[r - 1] - t[l - 1]) for a in ans: print(a)
false
28.571429
[ "+ans = []", "- print((t[r - 1] - t[l - 1]))", "+ ans.append(t[r - 1] - t[l - 1])", "+for a in ans:", "+ print(a)" ]
false
0.049313
0.046267
1.065837
[ "s152183268", "s831139804" ]
u621935300
p03556
python
s536582201
s783846815
27
11
5,764
2,568
Accepted
Accepted
59.26
import sys N=eval(input()) for i in range(100000): if i*i==N: print(i*i) sys.exit() elif i*i>N: print((i-1)*(i-1)) sys.exit() else: continue
import math N=eval(input()) print(int(math.sqrt(N))*int(math.sqrt(N)))
14
3
165
65
import sys N = eval(input()) for i in range(100000): if i * i == N: print(i * i) sys.exit() elif i * i > N: print((i - 1) * (i - 1)) sys.exit() else: continue
import math N = eval(input()) print(int(math.sqrt(N)) * int(math.sqrt(N)))
false
78.571429
[ "-import sys", "+import math", "-for i in range(100000):", "- if i * i == N:", "- print(i * i)", "- sys.exit()", "- elif i * i > N:", "- print((i - 1) * (i - 1))", "- sys.exit()", "- else:", "- continue", "+print(int(math.sqrt(N)) * int(math.sqrt(N)))" ]
false
0.034421
0.036377
0.94624
[ "s536582201", "s783846815" ]
u790905630
p02866
python
s296403227
s921449213
337
80
14,396
14,396
Accepted
Accepted
76.26
def main(): N = eval(input()) D = list(map(int,input().split())) M = max(D) countlist=[0] * (M + 1) ans=1 for i in D: countlist[i]+=1 if countlist[0]!=1 : ans = 0 else : if D[0]!=0 : ans = 0 else: for i in range(2,M+1): ans *= (countlist[i-1]**countlist[i]) print((ans % 998244353)) if __name__ == "__main__": main()
def main(): N = eval(input()) D = list(map(int,input().split())) M = max(D) countlist=[0] * (M + 1) ans=1 for i in D: countlist[i]+=1 if countlist[0]!=1 : ans = 0 else : if D[0]!=0 : ans = 0 else: for i in range(2,M+1): ans = (ans * (countlist[i-1]**countlist[i])) % 998244353 print(ans) if __name__ == "__main__": main()
24
24
449
456
def main(): N = eval(input()) D = list(map(int, input().split())) M = max(D) countlist = [0] * (M + 1) ans = 1 for i in D: countlist[i] += 1 if countlist[0] != 1: ans = 0 else: if D[0] != 0: ans = 0 else: for i in range(2, M + 1): ans *= countlist[i - 1] ** countlist[i] print((ans % 998244353)) if __name__ == "__main__": main()
def main(): N = eval(input()) D = list(map(int, input().split())) M = max(D) countlist = [0] * (M + 1) ans = 1 for i in D: countlist[i] += 1 if countlist[0] != 1: ans = 0 else: if D[0] != 0: ans = 0 else: for i in range(2, M + 1): ans = (ans * (countlist[i - 1] ** countlist[i])) % 998244353 print(ans) if __name__ == "__main__": main()
false
0
[ "- ans *= countlist[i - 1] ** countlist[i]", "- print((ans % 998244353))", "+ ans = (ans * (countlist[i - 1] ** countlist[i])) % 998244353", "+ print(ans)" ]
false
0.03772
0.045413
0.830601
[ "s296403227", "s921449213" ]
u894953648
p03001
python
s890135289
s448800531
19
17
3,064
2,940
Accepted
Accepted
10.53
a=list(map(int,input().split())) print((a[0]*a[1]/2,1 if a[0]/2==a[2] and a[1]/2==a[3] else 0))
a=list(map(int,input().split())) ans=str(a[0]*a[1]/2) if a[0]/2==a[2] and a[1]/2==a[3]: print((ans+" 1")) else:print((ans+" 0"))
2
6
94
134
a = list(map(int, input().split())) print((a[0] * a[1] / 2, 1 if a[0] / 2 == a[2] and a[1] / 2 == a[3] else 0))
a = list(map(int, input().split())) ans = str(a[0] * a[1] / 2) if a[0] / 2 == a[2] and a[1] / 2 == a[3]: print((ans + " 1")) else: print((ans + " 0"))
false
66.666667
[ "-print((a[0] * a[1] / 2, 1 if a[0] / 2 == a[2] and a[1] / 2 == a[3] else 0))", "+ans = str(a[0] * a[1] / 2)", "+if a[0] / 2 == a[2] and a[1] / 2 == a[3]:", "+ print((ans + \" 1\"))", "+else:", "+ print((ans + \" 0\"))" ]
false
0.047014
0.049493
0.949909
[ "s890135289", "s448800531" ]
u366886346
p03569
python
s556741525
s398721974
809
81
9,880
12,696
Accepted
Accepted
89.99
s=list(eval(input())) ans=0 for i in range(len(s)): if len(s)<=1: break if s[0]==s[-1]: del s[0] del s[-1] else: if s[0]=="x": ans+=1 del s[0] elif s[-1]=="x": ans+=1 del s[-1] else: ans=-1 break print(ans)
s=eval(input()) t="" num=[] for i in range(len(s)): if s[i]!="x": t+=s[i] num.append(i) yn=0 for i in range(-(len(t)//-2)): if t[i]!=t[-1-i]: yn=1 break if yn==1: print((-1)) else: if len(num)==0: print((0)) else: ans=abs(num[0]-(len(s)-num[-1]-1)) for i in range(len(num)//2): ans+=abs((num[i+1]-num[i])-(num[-1-i]-num[-2-i])) print(ans)
19
22
351
446
s = list(eval(input())) ans = 0 for i in range(len(s)): if len(s) <= 1: break if s[0] == s[-1]: del s[0] del s[-1] else: if s[0] == "x": ans += 1 del s[0] elif s[-1] == "x": ans += 1 del s[-1] else: ans = -1 break print(ans)
s = eval(input()) t = "" num = [] for i in range(len(s)): if s[i] != "x": t += s[i] num.append(i) yn = 0 for i in range(-(len(t) // -2)): if t[i] != t[-1 - i]: yn = 1 break if yn == 1: print((-1)) else: if len(num) == 0: print((0)) else: ans = abs(num[0] - (len(s) - num[-1] - 1)) for i in range(len(num) // 2): ans += abs((num[i + 1] - num[i]) - (num[-1 - i] - num[-2 - i])) print(ans)
false
13.636364
[ "-s = list(eval(input()))", "-ans = 0", "+s = eval(input())", "+t = \"\"", "+num = []", "- if len(s) <= 1:", "+ if s[i] != \"x\":", "+ t += s[i]", "+ num.append(i)", "+yn = 0", "+for i in range(-(len(t) // -2)):", "+ if t[i] != t[-1 - i]:", "+ yn = 1", "- if s[0] == s[-1]:", "- del s[0]", "- del s[-1]", "+if yn == 1:", "+ print((-1))", "+else:", "+ if len(num) == 0:", "+ print((0))", "- if s[0] == \"x\":", "- ans += 1", "- del s[0]", "- elif s[-1] == \"x\":", "- ans += 1", "- del s[-1]", "- else:", "- ans = -1", "- break", "-print(ans)", "+ ans = abs(num[0] - (len(s) - num[-1] - 1))", "+ for i in range(len(num) // 2):", "+ ans += abs((num[i + 1] - num[i]) - (num[-1 - i] - num[-2 - i]))", "+ print(ans)" ]
false
0.039014
0.046323
0.842208
[ "s556741525", "s398721974" ]
u519939795
p03610
python
s124431109
s717427190
68
41
4,596
3,188
Accepted
Accepted
39.71
s = input() for i in range(0,len(s),2): print(s[i],end="")
s = eval(input()) ans = "" for i in range(len(s)): if i%2 == 0: ans = ans + s[i] print(ans)
3
6
64
102
s = input() for i in range(0, len(s), 2): print(s[i], end="")
s = eval(input()) ans = "" for i in range(len(s)): if i % 2 == 0: ans = ans + s[i] print(ans)
false
50
[ "-s = input()", "-for i in range(0, len(s), 2):", "- print(s[i], end=\"\")", "+s = eval(input())", "+ans = \"\"", "+for i in range(len(s)):", "+ if i % 2 == 0:", "+ ans = ans + s[i]", "+print(ans)" ]
false
0.039285
0.040595
0.967735
[ "s124431109", "s717427190" ]
u347600233
p02836
python
s605019084
s825088844
30
26
9,040
9,000
Accepted
Accepted
13.33
s = eval(input()) n = len(s) print((sum(t != u for t, u in zip(s[:n//2], s[-(-n//2):][::-1]))))
s = eval(input()) n = len(s) print((sum(t != u for t, u in zip(s[:n//2], s[::-1]))))
3
3
89
78
s = eval(input()) n = len(s) print((sum(t != u for t, u in zip(s[: n // 2], s[-(-n // 2) :][::-1]))))
s = eval(input()) n = len(s) print((sum(t != u for t, u in zip(s[: n // 2], s[::-1]))))
false
0
[ "-print((sum(t != u for t, u in zip(s[: n // 2], s[-(-n // 2) :][::-1]))))", "+print((sum(t != u for t, u in zip(s[: n // 2], s[::-1]))))" ]
false
0.042368
0.041108
1.030641
[ "s605019084", "s825088844" ]
u156815136
p02597
python
s961240555
s139749090
118
85
10,672
10,748
Accepted
Accepted
27.97
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) n = I() C = eval(input()) flag = False cnt = 0 for i in range(n): if not flag and C[i] == 'W': flag = True if flag: if C[i] == 'R': cnt += 1 # elif C[i] == 'W': # if i + 1 < n: # if C[i+1] == 'W': # pass # else: # cnt = max(cnt-1,0) # else: # cnt = max(cnt-1,0) r = C.count('R') w = n-r nya = 0 for i in range(r,n): if C[i] == 'R': nya += 1 pya = 0 for i in range(r): if C[i] == 'W': pya += 1 a = 0 for i in range(n-1): if C[i] == 'W' and C[i+1] == 'R': a += 1 print((min(max(a,cnt), nya, pya)))
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n = I() s = eval(input()) C = Counter(s) w,r = 0,0 for k,v in list(C.items()): if k == 'W': w += v else: r += v p = 'R' * r + 'W' * w ans = 0 for i in range(n): if p[i] == s[i]: pass else: ans += 1 print((ans//2))
62
57
1,435
1,241
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) n = I() C = eval(input()) flag = False cnt = 0 for i in range(n): if not flag and C[i] == "W": flag = True if flag: if C[i] == "R": cnt += 1 # elif C[i] == 'W': # if i + 1 < n: # if C[i+1] == 'W': # pass # else: # cnt = max(cnt-1,0) # else: # cnt = max(cnt-1,0) r = C.count("R") w = n - r nya = 0 for i in range(r, n): if C[i] == "R": nya += 1 pya = 0 for i in range(r): if C[i] == "W": pya += 1 a = 0 for i in range(n - 1): if C[i] == "W" and C[i + 1] == "R": a += 1 print((min(max(a, cnt), nya, pya)))
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate, product # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 # mod = 998244353 INF = float("inf") from sys import stdin readline = stdin.readline def readInts(): return list(map(int, readline().split())) def readTuples(): return tuple(map(int, readline().split())) def I(): return int(readline()) n = I() s = eval(input()) C = Counter(s) w, r = 0, 0 for k, v in list(C.items()): if k == "W": w += v else: r += v p = "R" * r + "W" * w ans = 0 for i in range(n): if p[i] == s[i]: pass else: ans += 1 print((ans // 2))
false
8.064516
[ "-from itertools import combinations, permutations, accumulate # (string,3) 3回", "+from itertools import combinations, permutations, accumulate, product # (string,3) 3回", "+import math", "+import bisect", "+import heapq", "-# import bisect", "-#", "-# d = m - k[i] - k[j]", "-# if kk[bisect.bisect_right(kk,d) - 1] == d:", "-# 四捨五入", "+# 四捨五入g", "+#", "+# インデックス系", "+# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);", "+# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);", "+#", "+#", "+# mod = 998244353", "+INF = float(\"inf\")", "+from sys import stdin", "+", "+readline = stdin.readline", "+", "+", "- return list(map(int, input().split()))", "+ return list(map(int, readline().split()))", "+", "+", "+def readTuples():", "+ return tuple(map(int, readline().split()))", "- return int(eval(input()))", "+ return int(readline())", "-C = eval(input())", "-flag = False", "-cnt = 0", "+s = eval(input())", "+C = Counter(s)", "+w, r = 0, 0", "+for k, v in list(C.items()):", "+ if k == \"W\":", "+ w += v", "+ else:", "+ r += v", "+p = \"R\" * r + \"W\" * w", "+ans = 0", "- if not flag and C[i] == \"W\":", "- flag = True", "- if flag:", "- if C[i] == \"R\":", "- cnt += 1", "- # elif C[i] == 'W':", "- # if i + 1 < n:", "- # if C[i+1] == 'W':", "- # pass", "- # else:", "- # cnt = max(cnt-1,0)", "- # else:", "- # cnt = max(cnt-1,0)", "-r = C.count(\"R\")", "-w = n - r", "-nya = 0", "-for i in range(r, n):", "- if C[i] == \"R\":", "- nya += 1", "-pya = 0", "-for i in range(r):", "- if C[i] == \"W\":", "- pya += 1", "-a = 0", "-for i in range(n - 1):", "- if C[i] == \"W\" and C[i + 1] == \"R\":", "- a += 1", "-print((min(max(a, cnt), nya, pya)))", "+ if p[i] == s[i]:", "+ pass", "+ else:", "+ ans += 1", "+print((ans // 2))" ]
false
0.036521
0.069823
0.52305
[ "s961240555", "s139749090" ]
u203843959
p02796
python
s998502439
s453814430
453
314
26,008
22,804
Accepted
Accepted
30.68
import bisect N=int(eval(input())) rllist=[] for _ in range(N): X,L=list(map(int,input().split())) rllist.append((X+L,X-L)) rllist.sort() #print(rllist) dp=[0]*N for i in range(N): r,l=rllist[i] pos=bisect.bisect(rllist,(l,float("inf"))) #print(i,pos) dp[i]=max(dp[i-1],dp[pos-1]+1) #print(dp) print((dp[-1]))
N=int(eval(input())) rllist=[] for _ in range(N): X,L=list(map(int,input().split())) rllist.append((X+L,X-L)) rllist.sort() #print(rllist) answer=0 max_r=-float("inf") for r,l in rllist: #print(max_r,l) if max_r<=l: answer+=1 max_r=max(max_r,r) print(answer)
20
18
334
284
import bisect N = int(eval(input())) rllist = [] for _ in range(N): X, L = list(map(int, input().split())) rllist.append((X + L, X - L)) rllist.sort() # print(rllist) dp = [0] * N for i in range(N): r, l = rllist[i] pos = bisect.bisect(rllist, (l, float("inf"))) # print(i,pos) dp[i] = max(dp[i - 1], dp[pos - 1] + 1) # print(dp) print((dp[-1]))
N = int(eval(input())) rllist = [] for _ in range(N): X, L = list(map(int, input().split())) rllist.append((X + L, X - L)) rllist.sort() # print(rllist) answer = 0 max_r = -float("inf") for r, l in rllist: # print(max_r,l) if max_r <= l: answer += 1 max_r = max(max_r, r) print(answer)
false
10
[ "-import bisect", "-", "-dp = [0] * N", "-for i in range(N):", "- r, l = rllist[i]", "- pos = bisect.bisect(rllist, (l, float(\"inf\")))", "- # print(i,pos)", "- dp[i] = max(dp[i - 1], dp[pos - 1] + 1)", "-# print(dp)", "-print((dp[-1]))", "+answer = 0", "+max_r = -float(\"inf\")", "+for r, l in rllist:", "+ # print(max_r,l)", "+ if max_r <= l:", "+ answer += 1", "+ max_r = max(max_r, r)", "+print(answer)" ]
false
0.038433
0.043844
0.876567
[ "s998502439", "s453814430" ]