user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u440180827
p00007
python
s822625372
s489372348
30
20
7,628
7,568
Accepted
Accepted
33.33
import math loan = 100000 n = int(eval(input())) for i in range(n): loan += math.ceil(loan * 0.05 / 1000) * 1000 print(loan)
import math loan = 100000 for i in range(int(eval(input()))): loan += math.ceil(loan * 0.05 / 1000) * 1000 print(loan)
6
5
127
120
import math loan = 100000 n = int(eval(input())) for i in range(n): loan += math.ceil(loan * 0.05 / 1000) * 1000 print(loan)
import math loan = 100000 for i in range(int(eval(input()))): loan += math.ceil(loan * 0.05 / 1000) * 1000 print(loan)
false
16.666667
[ "-n = int(eval(input()))", "-for i in range(n):", "+for i in range(int(eval(input()))):" ]
false
0.044134
0.041038
1.075436
[ "s822625372", "s489372348" ]
u131406102
p03013
python
s540535595
s192021830
497
214
460,020
7,896
Accepted
Accepted
56.94
n, m = list(map(int, input().split())) k = [] count_sub = 0 steps = [] j = 0 for i in range(m): k.append(int(eval(input()))) if len(k)>1 and k[i]-k[i-1]==1: count_sub = 1 if count_sub ==1: steps = [0 for i in range(n)] else: for i in range(n+1): if k!=[] and k[j]==i: steps.append(0) if j < len(k)-1: j = j + 1 elif i ==0: steps.append(1) elif i ==1: steps.append(1) else: steps.append(steps[i-1]+steps[i-2]) print((steps[-1]%(1000000007)))
n, m = list(map(int, input().split())) k = [] count_sub = 0 steps = [] j = 0 for i in range(m): k.append(int(eval(input()))) if len(k)>1 and k[i]-k[i-1]==1: count_sub = 1 if count_sub ==1: steps = [0 for i in range(n)] else: for i in range(n+1): if k!=[] and k[j]==i: steps.append(0) if j < len(k)-1: j = j + 1 elif i ==0: steps.append(1) elif i ==1: steps.append(1) else: steps.append((steps[i-1]+steps[i-2])%1000000007) print((steps[-1]))
26
26
599
599
n, m = list(map(int, input().split())) k = [] count_sub = 0 steps = [] j = 0 for i in range(m): k.append(int(eval(input()))) if len(k) > 1 and k[i] - k[i - 1] == 1: count_sub = 1 if count_sub == 1: steps = [0 for i in range(n)] else: for i in range(n + 1): if k != [] and k[j] == i: steps.append(0) if j < len(k) - 1: j = j + 1 elif i == 0: steps.append(1) elif i == 1: steps.append(1) else: steps.append(steps[i - 1] + steps[i - 2]) print((steps[-1] % (1000000007)))
n, m = list(map(int, input().split())) k = [] count_sub = 0 steps = [] j = 0 for i in range(m): k.append(int(eval(input()))) if len(k) > 1 and k[i] - k[i - 1] == 1: count_sub = 1 if count_sub == 1: steps = [0 for i in range(n)] else: for i in range(n + 1): if k != [] and k[j] == i: steps.append(0) if j < len(k) - 1: j = j + 1 elif i == 0: steps.append(1) elif i == 1: steps.append(1) else: steps.append((steps[i - 1] + steps[i - 2]) % 1000000007) print((steps[-1]))
false
0
[ "- steps.append(steps[i - 1] + steps[i - 2])", "-print((steps[-1] % (1000000007)))", "+ steps.append((steps[i - 1] + steps[i - 2]) % 1000000007)", "+print((steps[-1]))" ]
false
0.072065
0.040841
1.764536
[ "s540535595", "s192021830" ]
u981931040
p03103
python
s096996854
s914104129
1,930
527
20,064
27,752
Accepted
Accepted
72.69
N , M = list(map(int,input().split())) drink = [] for _ in range(N): a , b = list(map(int,input().split())) drink.append([a,b]) drink.sort() value = 0 hold = 0 while hold != M: if drink[0][1] == 0: drink.pop(0) value += drink[0][0] hold += 1 drink[0][1] -= 1 print(value)
N, M = list(map(int, input().split())) shops = list(list(map(int, input().split())) for _ in range(N)) shops.sort() ans = 0 for value, count in shops: tmp_M = max(M - count , 0) ans += (M - tmp_M) * value M = tmp_M if M == 0: break print(ans)
17
11
309
271
N, M = list(map(int, input().split())) drink = [] for _ in range(N): a, b = list(map(int, input().split())) drink.append([a, b]) drink.sort() value = 0 hold = 0 while hold != M: if drink[0][1] == 0: drink.pop(0) value += drink[0][0] hold += 1 drink[0][1] -= 1 print(value)
N, M = list(map(int, input().split())) shops = list(list(map(int, input().split())) for _ in range(N)) shops.sort() ans = 0 for value, count in shops: tmp_M = max(M - count, 0) ans += (M - tmp_M) * value M = tmp_M if M == 0: break print(ans)
false
35.294118
[ "-drink = []", "-for _ in range(N):", "- a, b = list(map(int, input().split()))", "- drink.append([a, b])", "-drink.sort()", "-value = 0", "-hold = 0", "-while hold != M:", "- if drink[0][1] == 0:", "- drink.pop(0)", "- value += drink[0][0]", "- hold += 1", "- drink[0][1] -= 1", "-print(value)", "+shops = list(list(map(int, input().split())) for _ in range(N))", "+shops.sort()", "+ans = 0", "+for value, count in shops:", "+ tmp_M = max(M - count, 0)", "+ ans += (M - tmp_M) * value", "+ M = tmp_M", "+ if M == 0:", "+ break", "+print(ans)" ]
false
0.044461
0.038063
1.168101
[ "s096996854", "s914104129" ]
u969850098
p02631
python
s781018196
s885351213
177
134
36,324
31,584
Accepted
Accepted
24.29
import sys readline = sys.stdin.readline def main(): N = int(readline()) # 偶数 A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...] if N == 2: print((*A[::-1])) return xor = [] for i in range(N-1): xor.append(A[i] ^ A[i+1]) # a xor b, b xor c, c xor d ... # bを求める b = A[0] for i in range(2, N, 2): b ^= xor[i] # aを求める a = xor[0] ^ b # print(a, b) res = [a, b] pre = b # c以降を求める for x in xor[1:]: next = pre ^ x res.append(next) pre = next print((*res)) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline def main(): N = int(readline()) # 偶数 A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...] xor = 0 for a in A: xor ^= a res = [a ^ xor for a in A] print((*res)) if __name__ == '__main__': main()
40
18
698
320
import sys readline = sys.stdin.readline def main(): N = int(readline()) # 偶数 A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...] if N == 2: print((*A[::-1])) return xor = [] for i in range(N - 1): xor.append(A[i] ^ A[i + 1]) # a xor b, b xor c, c xor d ... # bを求める b = A[0] for i in range(2, N, 2): b ^= xor[i] # aを求める a = xor[0] ^ b # print(a, b) res = [a, b] pre = b # c以降を求める for x in xor[1:]: next = pre ^ x res.append(next) pre = next print((*res)) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline def main(): N = int(readline()) # 偶数 A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...] xor = 0 for a in A: xor ^= a res = [a ^ xor for a in A] print((*res)) if __name__ == "__main__": main()
false
55
[ "- if N == 2:", "- print((*A[::-1]))", "- return", "- xor = []", "- for i in range(N - 1):", "- xor.append(A[i] ^ A[i + 1]) # a xor b, b xor c, c xor d ...", "- # bを求める", "- b = A[0]", "- for i in range(2, N, 2):", "- b ^= xor[i]", "- # aを求める", "- a = xor[0] ^ b", "- # print(a, b)", "- res = [a, b]", "- pre = b", "- # c以降を求める", "- for x in xor[1:]:", "- next = pre ^ x", "- res.append(next)", "- pre = next", "+ xor = 0", "+ for a in A:", "+ xor ^= a", "+ res = [a ^ xor for a in A]" ]
false
0.068694
0.076217
0.901289
[ "s781018196", "s885351213" ]
u606045429
p02936
python
s272286494
s340086945
1,887
1,249
109,772
63,608
Accepted
Accepted
33.81
N, Q = [int(i) for i in input().split()] E = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = [int(i) for i in input().split()] E[a].append(b) E[b].append(a) M = [0] * (N + 1) for _ in range(Q): p, x = [int(i) for i in input().split()] M[p] += x from collections import deque ans = M[:] visited = [False] * (N + 1) visited[1] = True Q = deque([1]) while Q: a = Q.popleft() for e in E[a]: if visited[e]: continue visited[e] = True ans[e] += ans[a] Q.append(e) print((*ans[1:]))
from collections import deque import sys input = sys.stdin.readline N, Q = [int(i) for i in input().split()] E = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = [int(i) for i in input().split()] E[a].append(b) E[b].append(a) M = [0] * (N + 1) for _ in range(Q): p, x = [int(i) for i in input().split()] M[p] += x ans = M[:] visited = [False] * (N + 1) visited[1] = True Q = deque([1]) while Q: a = Q.popleft() for e in E[a]: if visited[e]: continue visited[e] = True ans[e] += ans[a] Q.append(e) print((*ans[1:]))
30
31
589
628
N, Q = [int(i) for i in input().split()] E = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = [int(i) for i in input().split()] E[a].append(b) E[b].append(a) M = [0] * (N + 1) for _ in range(Q): p, x = [int(i) for i in input().split()] M[p] += x from collections import deque ans = M[:] visited = [False] * (N + 1) visited[1] = True Q = deque([1]) while Q: a = Q.popleft() for e in E[a]: if visited[e]: continue visited[e] = True ans[e] += ans[a] Q.append(e) print((*ans[1:]))
from collections import deque import sys input = sys.stdin.readline N, Q = [int(i) for i in input().split()] E = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = [int(i) for i in input().split()] E[a].append(b) E[b].append(a) M = [0] * (N + 1) for _ in range(Q): p, x = [int(i) for i in input().split()] M[p] += x ans = M[:] visited = [False] * (N + 1) visited[1] = True Q = deque([1]) while Q: a = Q.popleft() for e in E[a]: if visited[e]: continue visited[e] = True ans[e] += ans[a] Q.append(e) print((*ans[1:]))
false
3.225806
[ "+from collections import deque", "+import sys", "+", "+input = sys.stdin.readline", "-from collections import deque", "-" ]
false
0.038662
0.008341
4.635015
[ "s272286494", "s340086945" ]
u179169725
p03164
python
s730976337
s390806382
1,415
1,138
199,916
273,228
Accepted
Accepted
19.58
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) import numpy as np from numba import njit N, W_max = ints() W, V = read_col(N) W = np.array(W, dtype=np.int64) V = np.array(V, dtype=np.int64) ''' dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき) 答えはW以下の数字が入ってるマスの一番左側 更新則 chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合 chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合 ''' @njit('(i8, i8, i8[:], i8[:])', cache=True) def solve(N, W_max, W, V): V_max = np.sum(V) + 1 dp = np.full((N + 1, V_max), 10**12, dtype=np.int64) # 初期化 dp[0][0] = 0 # 一個も選ばず価値が0なら必ず重さも0 # 更新 for i in range(N): dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :]) dp[i + 1, V[i]:] = np.minimum(dp[i + 1, V[i]:], dp[i, :-V[i]] + W[i]) # 以下のコードを高速化 # for j in range(V_max): # jv = j + V[i] # if jv < V_max: # dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i]) # dp[i + 1, j] = min(dp[i + 1, j], dp[i, j]) # 左から見てく for j in range(V_max - 1, -1, -1): if np.any(dp[:, j] <= W_max): print(j) return solve(N, W_max, W, V)
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) import numpy as np from numba import njit N, W_max = ints() W, V = read_col(N) W = np.array(W, dtype=np.int64) V = np.array(V, dtype=np.int64) ''' dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき) 答えはW以下の数字が入ってるマスの一番左側 更新則 chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合 chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合 ''' @njit('(i8, i8, i8[:], i8[:])', cache=True) def solve(N, W_max, W, V): V_max = np.sum(V) + 1 dp = np.full((N + 1, 2 * V_max), 10**12, dtype=np.int64) # 初期化 dp[0][0] = 0 # 一個も選ばず価値が0なら必ず重さも0 # 更新 for i in range(N): # numba使うならベクトル化しないほうが早い!!! for j in range(V_max): jv = j + V[i] dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i]) dp[i + 1, j] = min(dp[i + 1, j], dp[i, j]) # 左から見てく for j in range(V_max - 1, -1, -1): if np.any(dp[:, j] <= W_max): print(j) return solve(N, W_max, W, V)
73
70
1,738
1,577
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) import numpy as np from numba import njit N, W_max = ints() W, V = read_col(N) W = np.array(W, dtype=np.int64) V = np.array(V, dtype=np.int64) """ dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき) 答えはW以下の数字が入ってるマスの一番左側 更新則 chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合 chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合 """ @njit("(i8, i8, i8[:], i8[:])", cache=True) def solve(N, W_max, W, V): V_max = np.sum(V) + 1 dp = np.full((N + 1, V_max), 10**12, dtype=np.int64) # 初期化 dp[0][0] = 0 # 一個も選ばず価値が0なら必ず重さも0 # 更新 for i in range(N): dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :]) dp[i + 1, V[i] :] = np.minimum(dp[i + 1, V[i] :], dp[i, : -V[i]] + W[i]) # 以下のコードを高速化 # for j in range(V_max): # jv = j + V[i] # if jv < V_max: # dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i]) # dp[i + 1, j] = min(dp[i + 1, j], dp[i, j]) # 左から見てく for j in range(V_max - 1, -1, -1): if np.any(dp[:, j] <= W_max): print(j) return solve(N, W_max, W, V)
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) import numpy as np from numba import njit N, W_max = ints() W, V = read_col(N) W = np.array(W, dtype=np.int64) V = np.array(V, dtype=np.int64) """ dp[i,j] ... 重さの最小 (:iまで考慮したとき、価値がちょうどjのとき) 答えはW以下の数字が入ってるマスの一番左側 更新則 chmin(dp[i+1,j+V[i]] , dp[i, j]+W[i]) #ナップサックに入れた場合 chmin(dp[i+1,j] , dp[i, j]) # ナップサックに入れなかった場合 """ @njit("(i8, i8, i8[:], i8[:])", cache=True) def solve(N, W_max, W, V): V_max = np.sum(V) + 1 dp = np.full((N + 1, 2 * V_max), 10**12, dtype=np.int64) # 初期化 dp[0][0] = 0 # 一個も選ばず価値が0なら必ず重さも0 # 更新 for i in range(N): # numba使うならベクトル化しないほうが早い!!! for j in range(V_max): jv = j + V[i] dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i]) dp[i + 1, j] = min(dp[i + 1, j], dp[i, j]) # 左から見てく for j in range(V_max - 1, -1, -1): if np.any(dp[:, j] <= W_max): print(j) return solve(N, W_max, W, V)
false
4.109589
[ "- dp = np.full((N + 1, V_max), 10**12, dtype=np.int64)", "+ dp = np.full((N + 1, 2 * V_max), 10**12, dtype=np.int64)", "- dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :])", "- dp[i + 1, V[i] :] = np.minimum(dp[i + 1, V[i] :], dp[i, : -V[i]] + W[i])", "- # 以下のコードを高速化", "- # for j in range(V_max):", "- # jv = j + V[i]", "- # if jv < V_max:", "- # dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i])", "- # dp[i + 1, j] = min(dp[i + 1, j], dp[i, j])", "+ # numba使うならベクトル化しないほうが早い!!!", "+ for j in range(V_max):", "+ jv = j + V[i]", "+ dp[i + 1, jv] = min(dp[i + 1, jv], dp[i, j] + W[i])", "+ dp[i + 1, j] = min(dp[i + 1, j], dp[i, j])" ]
false
0.229811
0.214572
1.071021
[ "s730976337", "s390806382" ]
u222668979
p03634
python
s305878320
s751965206
608
529
178,000
165,128
Accepted
Accepted
12.99
from collections import deque def nearlist(N, LIST): # 隣接リスト NEAR = [set() for _ in range(N)] COST = {} for a, b, c in LIST: NEAR[a - 1].add(b - 1) NEAR[b - 1].add(a - 1) COST[(a - 1, b - 1)] = c COST[(b - 1, a - 1)] = c return NEAR, COST def bfs(NEAR, S, N): # 幅優先探索 # キュー DIST = [-1 for _ in range(N)] # 前処理 DIST[S] = 0 que, frag = deque([S]), set([S]) while len(que) > 0: q = que.popleft() for i in NEAR[q]: # 移動先の候補 if i in frag: # 処理済みか否か continue DIST[i] = DIST[q] + cost[(q, i)] que.append(i), frag.add(i) return DIST n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] near, cost = nearlist(n, abc) dist = bfs(near, k - 1, n) for x, y in xy: print((dist[x - 1] + dist[y - 1]))
from collections import deque def nearlist(N, LIST): # 隣接リスト NEAR = [{} for _ in range(N)] for a, b, c in LIST: NEAR[a - 1][b - 1] = c NEAR[b - 1][a - 1] = c return NEAR def bfs(NEAR, S, N): # 幅優先探索 # キュー DIST = [-1 for _ in range(N)] # 前処理 DIST[S] = 0 que, frag = deque([S]), set([S]) while len(que) > 0: q = que.popleft() for i, c in list(NEAR[q].items()): # 移動先の候補 if i in frag: # 処理済みか否か continue DIST[i] = DIST[q] + c que.append(i), frag.add(i) return DIST n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] near = nearlist(n, abc) dist = bfs(near, k - 1, n) for x, y in xy: print((dist[x - 1] + dist[y - 1]))
38
35
991
893
from collections import deque def nearlist(N, LIST): # 隣接リスト NEAR = [set() for _ in range(N)] COST = {} for a, b, c in LIST: NEAR[a - 1].add(b - 1) NEAR[b - 1].add(a - 1) COST[(a - 1, b - 1)] = c COST[(b - 1, a - 1)] = c return NEAR, COST def bfs(NEAR, S, N): # 幅優先探索 # キュー DIST = [-1 for _ in range(N)] # 前処理 DIST[S] = 0 que, frag = deque([S]), set([S]) while len(que) > 0: q = que.popleft() for i in NEAR[q]: # 移動先の候補 if i in frag: # 処理済みか否か continue DIST[i] = DIST[q] + cost[(q, i)] que.append(i), frag.add(i) return DIST n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] near, cost = nearlist(n, abc) dist = bfs(near, k - 1, n) for x, y in xy: print((dist[x - 1] + dist[y - 1]))
from collections import deque def nearlist(N, LIST): # 隣接リスト NEAR = [{} for _ in range(N)] for a, b, c in LIST: NEAR[a - 1][b - 1] = c NEAR[b - 1][a - 1] = c return NEAR def bfs(NEAR, S, N): # 幅優先探索 # キュー DIST = [-1 for _ in range(N)] # 前処理 DIST[S] = 0 que, frag = deque([S]), set([S]) while len(que) > 0: q = que.popleft() for i, c in list(NEAR[q].items()): # 移動先の候補 if i in frag: # 処理済みか否か continue DIST[i] = DIST[q] + c que.append(i), frag.add(i) return DIST n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] near = nearlist(n, abc) dist = bfs(near, k - 1, n) for x, y in xy: print((dist[x - 1] + dist[y - 1]))
false
7.894737
[ "- NEAR = [set() for _ in range(N)]", "- COST = {}", "+ NEAR = [{} for _ in range(N)]", "- NEAR[a - 1].add(b - 1)", "- NEAR[b - 1].add(a - 1)", "- COST[(a - 1, b - 1)] = c", "- COST[(b - 1, a - 1)] = c", "- return NEAR, COST", "+ NEAR[a - 1][b - 1] = c", "+ NEAR[b - 1][a - 1] = c", "+ return NEAR", "- for i in NEAR[q]: # 移動先の候補", "+ for i, c in list(NEAR[q].items()): # 移動先の候補", "- DIST[i] = DIST[q] + cost[(q, i)]", "+ DIST[i] = DIST[q] + c", "-near, cost = nearlist(n, abc)", "+near = nearlist(n, abc)" ]
false
0.036708
0.042588
0.861928
[ "s305878320", "s751965206" ]
u498487134
p02983
python
s742547908
s781817485
227
81
40,684
64,376
Accepted
Accepted
64.32
L,R =list(map(int,input().split())) mod=2019 ans=mod l=L%mod r=R%mod if r<=l: ans=0 elif (R-L)>=2019: ans=0 else: for i in range(l,r+1): for j in range(i+1,r+1): ans=min(ans,i*j%mod) print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=2019 L,R=MI() if R-L>=2019: print((0)) exit() a=L%mod b=R%mod if b<=a: print((0)) exit() ans=mod for i in range(a,b+1): for j in range(i+1,b+1): temp=(i*j)%mod ans=min(ans,temp) print(ans) main()
16
30
236
535
L, R = list(map(int, input().split())) mod = 2019 ans = mod l = L % mod r = R % mod if r <= l: ans = 0 elif (R - L) >= 2019: ans = 0 else: for i in range(l, r + 1): for j in range(i + 1, r + 1): ans = min(ans, i * j % mod) print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 2019 L, R = MI() if R - L >= 2019: print((0)) exit() a = L % mod b = R % mod if b <= a: print((0)) exit() ans = mod for i in range(a, b + 1): for j in range(i + 1, b + 1): temp = (i * j) % mod ans = min(ans, temp) print(ans) main()
false
46.666667
[ "-L, R = list(map(int, input().split()))", "-mod = 2019", "-ans = mod", "-l = L % mod", "-r = R % mod", "-if r <= l:", "- ans = 0", "-elif (R - L) >= 2019:", "- ans = 0", "-else:", "- for i in range(l, r + 1):", "- for j in range(i + 1, r + 1):", "- ans = min(ans, i * j % mod)", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 2019", "+ L, R = MI()", "+ if R - L >= 2019:", "+ print((0))", "+ exit()", "+ a = L % mod", "+ b = R % mod", "+ if b <= a:", "+ print((0))", "+ exit()", "+ ans = mod", "+ for i in range(a, b + 1):", "+ for j in range(i + 1, b + 1):", "+ temp = (i * j) % mod", "+ ans = min(ans, temp)", "+ print(ans)", "+", "+", "+main()" ]
false
0.042569
0.041837
1.017496
[ "s742547908", "s781817485" ]
u353919145
p03605
python
s217612756
s534765028
17
11
2,940
2,568
Accepted
Accepted
35.29
n = eval(input()) if n[0] == '9' or n[1] == '9': print("Yes") else: print("No")
n = input() if '9' in n: print('Yes') else: print('No')
7
5
98
63
n = eval(input()) if n[0] == "9" or n[1] == "9": print("Yes") else: print("No")
n = input() if "9" in n: print("Yes") else: print("No")
false
28.571429
[ "-n = eval(input())", "-if n[0] == \"9\" or n[1] == \"9\":", "+n = input()", "+if \"9\" in n:" ]
false
0.137247
0.13503
1.016421
[ "s217612756", "s534765028" ]
u056801547
p02898
python
s195399742
s926427955
212
195
51,440
51,440
Accepted
Accepted
8.02
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h = sorted(h, reverse=True) for i in range(n): if h[i] < k: break else: print((i+1)) exit() print(i)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) print((len([i for i in a if i >= k])))
10
3
196
107
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h = sorted(h, reverse=True) for i in range(n): if h[i] < k: break else: print((i + 1)) exit() print(i)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) print((len([i for i in a if i >= k])))
false
70
[ "-h = list(map(int, input().split()))", "-h = sorted(h, reverse=True)", "-for i in range(n):", "- if h[i] < k:", "- break", "-else:", "- print((i + 1))", "- exit()", "-print(i)", "+a = list(map(int, input().split()))", "+print((len([i for i in a if i >= k])))" ]
false
0.039162
0.039384
0.994373
[ "s195399742", "s926427955" ]
u346395915
p03607
python
s902874436
s213998373
318
198
16,460
14,696
Accepted
Accepted
37.74
n = int(eval(input())) ans = [eval(input()) for i in range(n)] ans.sort() s = sorted(set(ans)) t = 0 cnt = 0 result = 0 for i in range(n): temp = s[t] if ans[i] == temp: cnt += 1 else: if cnt % 2 == 1: result += 1 cnt = 1 t += 1 else: if cnt % 2 == 1: result += 1 print(result)
n = int(eval(input())) ans = set() for i in range(n): ans ^= {eval(input())} print((len(ans)))
28
9
384
100
n = int(eval(input())) ans = [eval(input()) for i in range(n)] ans.sort() s = sorted(set(ans)) t = 0 cnt = 0 result = 0 for i in range(n): temp = s[t] if ans[i] == temp: cnt += 1 else: if cnt % 2 == 1: result += 1 cnt = 1 t += 1 else: if cnt % 2 == 1: result += 1 print(result)
n = int(eval(input())) ans = set() for i in range(n): ans ^= {eval(input())} print((len(ans)))
false
67.857143
[ "-ans = [eval(input()) for i in range(n)]", "-ans.sort()", "-s = sorted(set(ans))", "-t = 0", "-cnt = 0", "-result = 0", "+ans = set()", "- temp = s[t]", "- if ans[i] == temp:", "- cnt += 1", "- else:", "- if cnt % 2 == 1:", "- result += 1", "- cnt = 1", "- t += 1", "-else:", "- if cnt % 2 == 1:", "- result += 1", "-print(result)", "+ ans ^= {eval(input())}", "+print((len(ans)))" ]
false
0.047711
0.043282
1.10233
[ "s902874436", "s213998373" ]
u037441960
p01086
python
s349723324
s281421007
40
30
5,616
5,616
Accepted
Accepted
25
while True : n = int(eval(input())) if(n == 0) : break else : A = [5, 7, 5, 7, 7] ans = 0 w = [len(eval(input())) for i in range(n)] for i in range(n) : k = 0 s = 0 for j in range(i, n) : s += w[j] if(s == A[k]) : s = 0 k += 1 if(k == 5) : ans = i + 1 break elif(s > A[k]) : break if(ans != 0) : break print(ans)
while True : n = int(eval(input())) if(n == 0) : break else : S = [len(eval(input())) for i in range(n)] T = [5, 7, 5, 7, 7] ans = 0 for i in range(n) : s = 0 w = 0 for j in range(i, n) : s += S[j] if(s == T[w]) : s = 0 w += 1 if(w == 5) : ans = i + 1 break else : pass elif(s > T[w]) : break else : pass if(ans != 0) : break else : pass print(ans)
24
34
478
806
while True: n = int(eval(input())) if n == 0: break else: A = [5, 7, 5, 7, 7] ans = 0 w = [len(eval(input())) for i in range(n)] for i in range(n): k = 0 s = 0 for j in range(i, n): s += w[j] if s == A[k]: s = 0 k += 1 if k == 5: ans = i + 1 break elif s > A[k]: break if ans != 0: break print(ans)
while True: n = int(eval(input())) if n == 0: break else: S = [len(eval(input())) for i in range(n)] T = [5, 7, 5, 7, 7] ans = 0 for i in range(n): s = 0 w = 0 for j in range(i, n): s += S[j] if s == T[w]: s = 0 w += 1 if w == 5: ans = i + 1 break else: pass elif s > T[w]: break else: pass if ans != 0: break else: pass print(ans)
false
29.411765
[ "- A = [5, 7, 5, 7, 7]", "+ S = [len(eval(input())) for i in range(n)]", "+ T = [5, 7, 5, 7, 7]", "- w = [len(eval(input())) for i in range(n)]", "- k = 0", "+ w = 0", "- s += w[j]", "- if s == A[k]:", "+ s += S[j]", "+ if s == T[w]:", "- k += 1", "- if k == 5:", "+ w += 1", "+ if w == 5:", "- elif s > A[k]:", "- break", "+ else:", "+ pass", "+ elif s > T[w]:", "+ break", "+ else:", "+ pass", "+ else:", "+ pass" ]
false
0.047279
0.047549
0.994312
[ "s349723324", "s281421007" ]
u753803401
p03821
python
s902915894
s732193894
386
338
56,540
56,028
Accepted
Accepted
12.44
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip('\n')) ab = [list(map(int, (str(i) + " " + input().rstrip('\n')).split())) for i in range(n)] ab.sort(reverse=True) cnt = 0 for i, a, b in ab: if (a + cnt) % b != 0: cnt += (b - (a + cnt) % b) print(cnt) if __name__ == '__main__': slove()
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip('\n')) ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] t = 0 for i in range(n-1, -1, -1): while True: if (ab[i][0] + t) % ab[i][1] == 0: break else: t += (ab[i][1] - (ab[i][0] + t) % ab[i][1]) print(t) if __name__ == '__main__': slove()
15
17
385
447
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip("\n")) ab = [ list(map(int, (str(i) + " " + input().rstrip("\n")).split())) for i in range(n) ] ab.sort(reverse=True) cnt = 0 for i, a, b in ab: if (a + cnt) % b != 0: cnt += b - (a + cnt) % b print(cnt) if __name__ == "__main__": slove()
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip("\n")) ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)] t = 0 for i in range(n - 1, -1, -1): while True: if (ab[i][0] + t) % ab[i][1] == 0: break else: t += ab[i][1] - (ab[i][0] + t) % ab[i][1] print(t) if __name__ == "__main__": slove()
false
11.764706
[ "- ab = [", "- list(map(int, (str(i) + \" \" + input().rstrip(\"\\n\")).split())) for i in range(n)", "- ]", "- ab.sort(reverse=True)", "- cnt = 0", "- for i, a, b in ab:", "- if (a + cnt) % b != 0:", "- cnt += b - (a + cnt) % b", "- print(cnt)", "+ ab = [list(map(int, input().rstrip(\"\\n\").split())) for _ in range(n)]", "+ t = 0", "+ for i in range(n - 1, -1, -1):", "+ while True:", "+ if (ab[i][0] + t) % ab[i][1] == 0:", "+ break", "+ else:", "+ t += ab[i][1] - (ab[i][0] + t) % ab[i][1]", "+ print(t)" ]
false
0.045552
0.046786
0.973626
[ "s902915894", "s732193894" ]
u077291787
p03478
python
s232528772
s937416029
31
27
3,064
2,940
Accepted
Accepted
12.9
# ABC083B - Some Sums def main(): n, a, b = list(map(int, input().rstrip().split())) ans = 0 for i in range(1, n + 1): if a <= sum(map(int, list(str(i)))) <= b: ans += i print(ans) if __name__ == "__main__": main()
# ABC083B - Some Sums def main(): N, A, B = tuple(map(int, input().split())) ans = sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B) print(ans) if __name__ == "__main__": main()
12
9
267
220
# ABC083B - Some Sums def main(): n, a, b = list(map(int, input().rstrip().split())) ans = 0 for i in range(1, n + 1): if a <= sum(map(int, list(str(i)))) <= b: ans += i print(ans) if __name__ == "__main__": main()
# ABC083B - Some Sums def main(): N, A, B = tuple(map(int, input().split())) ans = sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B) print(ans) if __name__ == "__main__": main()
false
25
[ "- n, a, b = list(map(int, input().rstrip().split()))", "- ans = 0", "- for i in range(1, n + 1):", "- if a <= sum(map(int, list(str(i)))) <= b:", "- ans += i", "+ N, A, B = tuple(map(int, input().split()))", "+ ans = sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B)" ]
false
0.047054
0.110099
0.427381
[ "s232528772", "s937416029" ]
u896741788
p03475
python
s603941969
s408915383
120
75
3,188
3,188
Accepted
Accepted
37.5
n=int(input()) l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]] al=[] mati=0 for i in range(n): now=l[i][1]+l[i][0] for j in range(i+1,n): now=l[j][0]+l[j][1]-(-max(0,now-l[j][1])//l[j][2])*l[j][2] al.append(now) print(*al,sep="\n")
def f(): n=int(eval(input())) l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]] for i in range(n): now=0 for a,s,d in l[i:]: now=a+s-(-max(0,now-s)//d)*d print(now) if __name__=="__main__": f()
10
10
267
237
n = int(input()) l = [list(map(int, input().split())) for i in range(n - 1)] + [[0, 0, 1]] al = [] mati = 0 for i in range(n): now = l[i][1] + l[i][0] for j in range(i + 1, n): now = l[j][0] + l[j][1] - (-max(0, now - l[j][1]) // l[j][2]) * l[j][2] al.append(now) print(*al, sep="\n")
def f(): n = int(eval(input())) l = [list(map(int, input().split())) for i in range(n - 1)] + [[0, 0, 1]] for i in range(n): now = 0 for a, s, d in l[i:]: now = a + s - (-max(0, now - s) // d) * d print(now) if __name__ == "__main__": f()
false
0
[ "-n = int(input())", "-l = [list(map(int, input().split())) for i in range(n - 1)] + [[0, 0, 1]]", "-al = []", "-mati = 0", "-for i in range(n):", "- now = l[i][1] + l[i][0]", "- for j in range(i + 1, n):", "- now = l[j][0] + l[j][1] - (-max(0, now - l[j][1]) // l[j][2]) * l[j][2]", "- al.append(now)", "-print(*al, sep=\"\\n\")", "+def f():", "+ n = int(eval(input()))", "+ l = [list(map(int, input().split())) for i in range(n - 1)] + [[0, 0, 1]]", "+ for i in range(n):", "+ now = 0", "+ for a, s, d in l[i:]:", "+ now = a + s - (-max(0, now - s) // d) * d", "+ print(now)", "+", "+", "+if __name__ == \"__main__\":", "+ f()" ]
false
0.068725
0.063114
1.088907
[ "s603941969", "s408915383" ]
u370429695
p03127
python
s084587678
s547315262
96
81
16,240
16,300
Accepted
Accepted
15.62
import fractions N = int(eval(input())) a = list(map(int, input().split())) ans = a[0] for i in range(1, N): ans = fractions.gcd(ans, a[i]) print(ans)
import functools from fractions import gcd n = int(eval(input())) li = list(map(int,input().split())) print((functools.reduce(gcd,li)))
7
5
154
132
import fractions N = int(eval(input())) a = list(map(int, input().split())) ans = a[0] for i in range(1, N): ans = fractions.gcd(ans, a[i]) print(ans)
import functools from fractions import gcd n = int(eval(input())) li = list(map(int, input().split())) print((functools.reduce(gcd, li)))
false
28.571429
[ "-import fractions", "+import functools", "+from fractions import gcd", "-N = int(eval(input()))", "-a = list(map(int, input().split()))", "-ans = a[0]", "-for i in range(1, N):", "- ans = fractions.gcd(ans, a[i])", "-print(ans)", "+n = int(eval(input()))", "+li = list(map(int, input().split()))", "+print((functools.reduce(gcd, li)))" ]
false
0.07525
0.13888
0.541832
[ "s084587678", "s547315262" ]
u038027079
p03264
python
s110974523
s921832020
19
17
2,940
2,940
Accepted
Accepted
10.53
k = int(eval(input())) count = 0 for i in range(k): for j in range(i+1, k): if (i % 2 == 0 and j % 2 == 1) or (i % 2 == 1 and j % 2 == 0): count +=1 print(count)
k = int(eval(input())) print(((k // 2) * (k - k // 2)))
7
2
185
49
k = int(eval(input())) count = 0 for i in range(k): for j in range(i + 1, k): if (i % 2 == 0 and j % 2 == 1) or (i % 2 == 1 and j % 2 == 0): count += 1 print(count)
k = int(eval(input())) print(((k // 2) * (k - k // 2)))
false
71.428571
[ "-count = 0", "-for i in range(k):", "- for j in range(i + 1, k):", "- if (i % 2 == 0 and j % 2 == 1) or (i % 2 == 1 and j % 2 == 0):", "- count += 1", "-print(count)", "+print(((k // 2) * (k - k // 2)))" ]
false
0.00815
0.042904
0.189963
[ "s110974523", "s921832020" ]
u983918956
p03050
python
s788530303
s245359678
143
116
3,188
3,296
Accepted
Accepted
18.88
from math import floor N = int(eval(input())) ans = 0 sup = floor(pow(N,1/2)) for r in range(1,sup+1): if N % r == 0: m = N // r - 1 if 0 <= r <= m-1: ans += m print(ans)
from math import floor def divisor(n): left = [1] right = [n] sup = floor(pow(n,1/2)) for p in range(2,sup+1): if n % p == 0: left.append(p) right.append(n//p) res = left + right[::-1] return res N = int(eval(input())) div = divisor(N) ans = 0 for d in div: if d != 1 and N // (d-1) == N % (d-1): ans += (d-1) print(ans)
11
23
207
417
from math import floor N = int(eval(input())) ans = 0 sup = floor(pow(N, 1 / 2)) for r in range(1, sup + 1): if N % r == 0: m = N // r - 1 if 0 <= r <= m - 1: ans += m print(ans)
from math import floor def divisor(n): left = [1] right = [n] sup = floor(pow(n, 1 / 2)) for p in range(2, sup + 1): if n % p == 0: left.append(p) right.append(n // p) res = left + right[::-1] return res N = int(eval(input())) div = divisor(N) ans = 0 for d in div: if d != 1 and N // (d - 1) == N % (d - 1): ans += d - 1 print(ans)
false
52.173913
[ "+", "+def divisor(n):", "+ left = [1]", "+ right = [n]", "+ sup = floor(pow(n, 1 / 2))", "+ for p in range(2, sup + 1):", "+ if n % p == 0:", "+ left.append(p)", "+ right.append(n // p)", "+ res = left + right[::-1]", "+ return res", "+", "+", "+div = divisor(N)", "-sup = floor(pow(N, 1 / 2))", "-for r in range(1, sup + 1):", "- if N % r == 0:", "- m = N // r - 1", "- if 0 <= r <= m - 1:", "- ans += m", "+for d in div:", "+ if d != 1 and N // (d - 1) == N % (d - 1):", "+ ans += d - 1" ]
false
0.29086
0.159013
1.829165
[ "s788530303", "s245359678" ]
u555503067
p02899
python
s576226490
s518876034
290
164
18,264
13,812
Accepted
Accepted
43.45
N = int(input()) A_list = list(map(int, input().split())) my_list = [] for i in range(len(A_list)): my_list.append((A_list[i], i+1)) my_list.sort() for val in my_list: print(val[1], end=" ") print()
N = int(input()) A_list = list(map(int, input().split())) # my_list = [] # for i in range(len(A_list)): # my_list.append((A_list[i], i+1)) # my_list.sort() # for val in my_list: # print(val[1], end=" ") # print() my_list = [0] * N for i in range(len(A_list)): my_list[A_list[i] - 1] = i + 1 for val in my_list: print(val, end=" ") print()
9
16
214
371
N = int(input()) A_list = list(map(int, input().split())) my_list = [] for i in range(len(A_list)): my_list.append((A_list[i], i + 1)) my_list.sort() for val in my_list: print(val[1], end=" ") print()
N = int(input()) A_list = list(map(int, input().split())) # my_list = [] # for i in range(len(A_list)): # my_list.append((A_list[i], i+1)) # my_list.sort() # for val in my_list: # print(val[1], end=" ") # print() my_list = [0] * N for i in range(len(A_list)): my_list[A_list[i] - 1] = i + 1 for val in my_list: print(val, end=" ") print()
false
43.75
[ "-my_list = []", "+# my_list = []", "+# for i in range(len(A_list)):", "+# my_list.append((A_list[i], i+1))", "+# my_list.sort()", "+# for val in my_list:", "+# print(val[1], end=\" \")", "+# print()", "+my_list = [0] * N", "- my_list.append((A_list[i], i + 1))", "-my_list.sort()", "+ my_list[A_list[i] - 1] = i + 1", "- print(val[1], end=\" \")", "+ print(val, end=\" \")" ]
false
0.078996
0.04189
1.885788
[ "s576226490", "s518876034" ]
u678505520
p02714
python
s667516497
s181607012
1,849
1,315
9,468
9,220
Accepted
Accepted
28.88
from collections import Counter N = int(eval(input())) S = [i for i in eval(input())] count = 0 s = Counter(S) for i in range(N): for j in range(i,N): if (i+j)%2==0 and S[(i+j)//2]!=S[i] and S[i]!=S[j] and S[(i+j)//2]!=S[j]: count += 1 print(((s['R'] * s['B'] * s['G'])-count))
N = int(eval(input())) S = [i for i in eval(input())] r = 0 g = 0 b = 0 no = 0 for i in S: if i == "R": r += 1 elif i == "G": g += 1 else: b += 1 for i in range(N): for j in range(i+1, N): k = j*2 - i if k >= N: break elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: no += 1 print((r*g*b - no))
11
25
298
401
from collections import Counter N = int(eval(input())) S = [i for i in eval(input())] count = 0 s = Counter(S) for i in range(N): for j in range(i, N): if ( (i + j) % 2 == 0 and S[(i + j) // 2] != S[i] and S[i] != S[j] and S[(i + j) // 2] != S[j] ): count += 1 print(((s["R"] * s["B"] * s["G"]) - count))
N = int(eval(input())) S = [i for i in eval(input())] r = 0 g = 0 b = 0 no = 0 for i in S: if i == "R": r += 1 elif i == "G": g += 1 else: b += 1 for i in range(N): for j in range(i + 1, N): k = j * 2 - i if k >= N: break elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: no += 1 print((r * g * b - no))
false
56
[ "-from collections import Counter", "-", "-count = 0", "-s = Counter(S)", "+r = 0", "+g = 0", "+b = 0", "+no = 0", "+for i in S:", "+ if i == \"R\":", "+ r += 1", "+ elif i == \"G\":", "+ g += 1", "+ else:", "+ b += 1", "- for j in range(i, N):", "- if (", "- (i + j) % 2 == 0", "- and S[(i + j) // 2] != S[i]", "- and S[i] != S[j]", "- and S[(i + j) // 2] != S[j]", "- ):", "- count += 1", "-print(((s[\"R\"] * s[\"B\"] * s[\"G\"]) - count))", "+ for j in range(i + 1, N):", "+ k = j * 2 - i", "+ if k >= N:", "+ break", "+ elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:", "+ no += 1", "+print((r * g * b - no))" ]
false
0.081364
0.096472
0.843394
[ "s667516497", "s181607012" ]
u721316601
p02947
python
s732785494
s774952249
776
481
17,848
18,236
Accepted
Accepted
38.02
import math N = int(eval(input())) s = {} ans = 0 for i in range(N): tmp = ''.join(sorted(eval(input()))) if tmp in s: s[tmp] += 1 else: s[tmp] = 1 x = math.factorial(2) for n in list(s.values()): if n > 1: ans += math.factorial(n) // (math.factorial(n-2) * x) print(ans)
from collections import Counter count = Counter() for i in range(int(eval(input()))): s = sorted(eval(input())) count[''.join(s)] += 1 ans = 0 for n in list(count.values()): if n >= 2: ans += (n**2 - n) // 2 print(ans)
18
14
310
226
import math N = int(eval(input())) s = {} ans = 0 for i in range(N): tmp = "".join(sorted(eval(input()))) if tmp in s: s[tmp] += 1 else: s[tmp] = 1 x = math.factorial(2) for n in list(s.values()): if n > 1: ans += math.factorial(n) // (math.factorial(n - 2) * x) print(ans)
from collections import Counter count = Counter() for i in range(int(eval(input()))): s = sorted(eval(input())) count["".join(s)] += 1 ans = 0 for n in list(count.values()): if n >= 2: ans += (n**2 - n) // 2 print(ans)
false
22.222222
[ "-import math", "+from collections import Counter", "-N = int(eval(input()))", "-s = {}", "+count = Counter()", "+for i in range(int(eval(input()))):", "+ s = sorted(eval(input()))", "+ count[\"\".join(s)] += 1", "-for i in range(N):", "- tmp = \"\".join(sorted(eval(input())))", "- if tmp in s:", "- s[tmp] += 1", "- else:", "- s[tmp] = 1", "-x = math.factorial(2)", "-for n in list(s.values()):", "- if n > 1:", "- ans += math.factorial(n) // (math.factorial(n - 2) * x)", "+for n in list(count.values()):", "+ if n >= 2:", "+ ans += (n**2 - n) // 2" ]
false
0.046605
0.11705
0.398165
[ "s732785494", "s774952249" ]
u285891772
p03576
python
s642038813
s124021292
1,145
51
79,688
10,056
Accepted
Accepted
95.55
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, K = MAP() xy = [LIST() for _ in range(N)] x, y = list(zip(*xy)) x = sorted(x) y = sorted(y) ans = INF for ax, bx in combinations(x, 2): for ay, by in combinations(y, 2): cnt = 0 for cx, cy in xy: if ax <= cx <= bx and ay <= cy <= by: cnt += 1 if K <= cnt: ans = min(ans, (bx-ax)*(by-ay)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 #from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, K = MAP() xy = [LIST() for _ in range(N)] ans = INF xy.sort() for l in range(N-K+1): #長方形の最も左の点 for r in range(l+K, N+1): #長方形の最も右の点 y = sorted(xy[l:r], key = lambda x: x[1]) #lからrの中でyのとりうる値をソート for i in range(r-l-K+1): sq = (xy[r-1][0] - xy[l][0])*(y[i+K-1][1] - y[i][1]) ans = min(ans, sq) print(ans)
42
36
1,333
1,343
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 N, K = MAP() xy = [LIST() for _ in range(N)] x, y = list(zip(*xy)) x = sorted(x) y = sorted(y) ans = INF for ax, bx in combinations(x, 2): for ay, by in combinations(y, 2): cnt = 0 for cx, cy in xy: if ax <= cx <= bx and ay <= cy <= by: cnt += 1 if K <= cnt: ans = min(ans, (bx - ax) * (by - ay)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 # from decimal import * # import numpy as np # decimal.getcontext().prec = 10 N, K = MAP() xy = [LIST() for _ in range(N)] ans = INF xy.sort() for l in range(N - K + 1): # 長方形の最も左の点 for r in range(l + K, N + 1): # 長方形の最も右の点 y = sorted(xy[l:r], key=lambda x: x[1]) # lからrの中でyのとりうる値をソート for i in range(r - l - K + 1): sq = (xy[r - 1][0] - xy[l][0]) * (y[i + K - 1][1] - y[i][1]) ans = min(ans, sq) print(ans)
false
14.285714
[ "-from functools import reduce", "+from functools import reduce, lru_cache", "-from decimal import *", "-", "+# from decimal import *", "-x, y = list(zip(*xy))", "-x = sorted(x)", "-y = sorted(y)", "-for ax, bx in combinations(x, 2):", "- for ay, by in combinations(y, 2):", "- cnt = 0", "- for cx, cy in xy:", "- if ax <= cx <= bx and ay <= cy <= by:", "- cnt += 1", "- if K <= cnt:", "- ans = min(ans, (bx - ax) * (by - ay))", "+xy.sort()", "+for l in range(N - K + 1): # 長方形の最も左の点", "+ for r in range(l + K, N + 1): # 長方形の最も右の点", "+ y = sorted(xy[l:r], key=lambda x: x[1]) # lからrの中でyのとりうる値をソート", "+ for i in range(r - l - K + 1):", "+ sq = (xy[r - 1][0] - xy[l][0]) * (y[i + K - 1][1] - y[i][1])", "+ ans = min(ans, sq)" ]
false
0.036148
0.035318
1.02352
[ "s642038813", "s124021292" ]
u454557108
p02696
python
s065213970
s287213924
138
60
64,064
62,180
Accepted
Accepted
56.52
import math a,b,n = list(map(int,input().split())) c = 0 ans = 0 for i in range(1,10**7) : x = b*i-1 if x > n : x = n c = 1 ans = max(ans,math.floor((a*x)/b)-a*math.floor(x/b)) if c == 1 : break print(ans)
import math a,b,n = list(map(int,input().split())) c = 0 ans = -1 for i in range(1,n//b+2) : x = b*i-1 if x > n : x = n c = 1 if ans >= math.floor((a*x)/b)-a*math.floor(x/b) : break ans = math.floor((a*x)/b)-a*math.floor(x/b) if c == 1 : break print(ans)
16
18
258
320
import math a, b, n = list(map(int, input().split())) c = 0 ans = 0 for i in range(1, 10**7): x = b * i - 1 if x > n: x = n c = 1 ans = max(ans, math.floor((a * x) / b) - a * math.floor(x / b)) if c == 1: break print(ans)
import math a, b, n = list(map(int, input().split())) c = 0 ans = -1 for i in range(1, n // b + 2): x = b * i - 1 if x > n: x = n c = 1 if ans >= math.floor((a * x) / b) - a * math.floor(x / b): break ans = math.floor((a * x) / b) - a * math.floor(x / b) if c == 1: break print(ans)
false
11.111111
[ "-ans = 0", "-for i in range(1, 10**7):", "+ans = -1", "+for i in range(1, n // b + 2):", "- ans = max(ans, math.floor((a * x) / b) - a * math.floor(x / b))", "+ if ans >= math.floor((a * x) / b) - a * math.floor(x / b):", "+ break", "+ ans = math.floor((a * x) / b) - a * math.floor(x / b)" ]
false
0.036453
0.035551
1.025379
[ "s065213970", "s287213924" ]
u967136506
p02821
python
s840581384
s313523317
1,031
838
14,620
14,268
Accepted
Accepted
18.72
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) N, M = ints() A = ints() A.sort() def combinations(x): s = 0 i = 0 j = N-1 while j>=0: while i<N and A[i]+A[j]<x: i += 1 s += N-i j -= 1 return s def koufukudo(x): s = 0 si = 0 j = 0 i = N-1 while j<N: while i>=0 and A[i]+A[j]>=x: si += A[i] i -= 1 s += si + A[j]*(N-1-i) j += 1 return s def bsearch(lower, upper): l = lower u = upper m = (l+u)//2 c = combinations(m) if c<M: return bsearch(l, m) else: if l==m: return (l, c-M) return bsearch(m, u) x, dm = bsearch(0, A[-1]*2+1) print((koufukudo(x)-dm*x))
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) N, M = ints() A = ints() A.sort() A.reverse() def combinations(x): s = 0 i = 0 for j in reversed(list(range(N))): while i<N and A[i]+A[j]>=x: i += 1 s += i return s def koufukudo(x): s = 0 si = 0 i = 0 for j in reversed(list(range(N))): while i<N and A[i]+A[j]>=x: si += A[i] i += 1 s += si + A[j]*i return s def bsearch(l, u): m = (l+u)//2 c = combinations(m) if c<M: return bsearch(l, m) else: if l==m: return (l, c-M) return bsearch(m, u) x, dm = bsearch(0, A[0]*2+1) print((koufukudo(x)-dm*x))
52
45
754
709
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) N, M = ints() A = ints() A.sort() def combinations(x): s = 0 i = 0 j = N - 1 while j >= 0: while i < N and A[i] + A[j] < x: i += 1 s += N - i j -= 1 return s def koufukudo(x): s = 0 si = 0 j = 0 i = N - 1 while j < N: while i >= 0 and A[i] + A[j] >= x: si += A[i] i -= 1 s += si + A[j] * (N - 1 - i) j += 1 return s def bsearch(lower, upper): l = lower u = upper m = (l + u) // 2 c = combinations(m) if c < M: return bsearch(l, m) else: if l == m: return (l, c - M) return bsearch(m, u) x, dm = bsearch(0, A[-1] * 2 + 1) print((koufukudo(x) - dm * x))
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) N, M = ints() A = ints() A.sort() A.reverse() def combinations(x): s = 0 i = 0 for j in reversed(list(range(N))): while i < N and A[i] + A[j] >= x: i += 1 s += i return s def koufukudo(x): s = 0 si = 0 i = 0 for j in reversed(list(range(N))): while i < N and A[i] + A[j] >= x: si += A[i] i += 1 s += si + A[j] * i return s def bsearch(l, u): m = (l + u) // 2 c = combinations(m) if c < M: return bsearch(l, m) else: if l == m: return (l, c - M) return bsearch(m, u) x, dm = bsearch(0, A[0] * 2 + 1) print((koufukudo(x) - dm * x))
false
13.461538
[ "+A.reverse()", "- j = N - 1", "- while j >= 0:", "- while i < N and A[i] + A[j] < x:", "+ for j in reversed(list(range(N))):", "+ while i < N and A[i] + A[j] >= x:", "- s += N - i", "- j -= 1", "+ s += i", "- j = 0", "- i = N - 1", "- while j < N:", "- while i >= 0 and A[i] + A[j] >= x:", "+ i = 0", "+ for j in reversed(list(range(N))):", "+ while i < N and A[i] + A[j] >= x:", "- i -= 1", "- s += si + A[j] * (N - 1 - i)", "- j += 1", "+ i += 1", "+ s += si + A[j] * i", "-def bsearch(lower, upper):", "- l = lower", "- u = upper", "+def bsearch(l, u):", "-x, dm = bsearch(0, A[-1] * 2 + 1)", "+x, dm = bsearch(0, A[0] * 2 + 1)" ]
false
0.040434
0.038667
1.04571
[ "s840581384", "s313523317" ]
u125807888
p02615
python
s372528441
s646005116
451
132
128,720
105,132
Accepted
Accepted
70.73
import heapq FAST_IO = 1 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).__next__ sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: list(map(int, rr().split())) rrmm = lambda n: [rrm() for _ in range(n)] rrn = lambda n: [ rr() for _ in range(n)] N = rri() arr = rrm() arr = sorted(arr) def solve(N, arr): pq = [] cur1 = arr.pop() ans = cur1 cur2 = arr.pop() heapq.heappush(pq, (-cur2, (cur2, cur1))) heapq.heappush(pq, (-cur2,(cur1, cur2))) while arr: neg_max, (start, end) = heapq.heappop(pq) ans-=neg_max cur = arr.pop() heapq.heappush(pq, (-cur, (start, cur))) heapq.heappush(pq, (-cur, (cur, end))) return ans print((solve(N, arr)))
n = int(eval(input())) arr = list(map(int , input().split())) arr.sort(reverse = True) ptr = 1 s = arr[0] n-=2 while n: s+=arr[ptr] n-=1 if n == 0: break s+=arr[ptr] n-=1 ptr+=1 print(s)
36
14
926
217
import heapq FAST_IO = 1 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).__next__ sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: list(map(int, rr().split())) rrmm = lambda n: [rrm() for _ in range(n)] rrn = lambda n: [rr() for _ in range(n)] N = rri() arr = rrm() arr = sorted(arr) def solve(N, arr): pq = [] cur1 = arr.pop() ans = cur1 cur2 = arr.pop() heapq.heappush(pq, (-cur2, (cur2, cur1))) heapq.heappush(pq, (-cur2, (cur1, cur2))) while arr: neg_max, (start, end) = heapq.heappop(pq) ans -= neg_max cur = arr.pop() heapq.heappush(pq, (-cur, (start, cur))) heapq.heappush(pq, (-cur, (cur, end))) return ans print((solve(N, arr)))
n = int(eval(input())) arr = list(map(int, input().split())) arr.sort(reverse=True) ptr = 1 s = arr[0] n -= 2 while n: s += arr[ptr] n -= 1 if n == 0: break s += arr[ptr] n -= 1 ptr += 1 print(s)
false
61.111111
[ "-import heapq", "-", "-FAST_IO = 1", "-if FAST_IO:", "- import io, sys, atexit", "-", "- rr = iter(sys.stdin.read().splitlines()).__next__", "- sys.stdout = _OUTPUT_BUFFER = io.BytesIO()", "-", "- @atexit.register", "- def write():", "- sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())", "-", "-else:", "- rr = raw_input", "-rri = lambda: int(rr())", "-rrm = lambda: list(map(int, rr().split()))", "-rrmm = lambda n: [rrm() for _ in range(n)]", "-rrn = lambda n: [rr() for _ in range(n)]", "-N = rri()", "-arr = rrm()", "-arr = sorted(arr)", "-", "-", "-def solve(N, arr):", "- pq = []", "- cur1 = arr.pop()", "- ans = cur1", "- cur2 = arr.pop()", "- heapq.heappush(pq, (-cur2, (cur2, cur1)))", "- heapq.heappush(pq, (-cur2, (cur1, cur2)))", "- while arr:", "- neg_max, (start, end) = heapq.heappop(pq)", "- ans -= neg_max", "- cur = arr.pop()", "- heapq.heappush(pq, (-cur, (start, cur)))", "- heapq.heappush(pq, (-cur, (cur, end)))", "- return ans", "-", "-", "-print((solve(N, arr)))", "+n = int(eval(input()))", "+arr = list(map(int, input().split()))", "+arr.sort(reverse=True)", "+ptr = 1", "+s = arr[0]", "+n -= 2", "+while n:", "+ s += arr[ptr]", "+ n -= 1", "+ if n == 0:", "+ break", "+ s += arr[ptr]", "+ n -= 1", "+ ptr += 1", "+print(s)" ]
false
0.038861
0.037252
1.043184
[ "s372528441", "s646005116" ]
u402629484
p03112
python
s162995832
s770971893
1,791
1,491
12,800
13,952
Accepted
Accepted
16.75
A,B,Q = list(map(int, input().split())) s = [-(10**11)]+[int(eval(input())) for _ in range(A)]+[10**11] t = [-(10**11)]+[int(eval(input())) for _ in range(B)]+[10**11] s.sort() t.sort() import bisect import itertools for _ in range(Q): pos = int(eval(input())) s_near_id = bisect.bisect_left(s, pos)-1 t_near_id = bisect.bisect_left(t, pos)-1 print((min( min(abs(pos-s_pos)+abs(s_pos-t_pos), abs(pos-t_pos)+abs(t_pos-s_pos)) for s_pos, t_pos in itertools.product(s[s_near_id:s_near_id+2],t[t_near_id:t_near_id+2]) )))
A,B,Q = list(map(int, input().split())) s = [-(10**11)]+[int(eval(input())) for _ in range(A)]+[10**11] t = [-(10**11)]+[int(eval(input())) for _ in range(B)]+[10**11] s.sort() t.sort() import bisect import itertools for _ in range(Q): pos = int(eval(input())) near_s = bisect.bisect_left(s, pos)-1 near_t = bisect.bisect_left(t, pos)-1 s1, s2 = s[near_s], s[near_s+1] t1, t2 = t[near_t], t[near_t+1] print((min( pos - min(s1,t1), max(s2,t2) - pos, (s2 - pos) + (s2 - t1), (pos - t1) + (s2 - t1), (t2 - pos) + (t2 - s1), (pos - s1) + (t2 - s1) )))
13
22
521
621
A, B, Q = list(map(int, input().split())) s = [-(10**11)] + [int(eval(input())) for _ in range(A)] + [10**11] t = [-(10**11)] + [int(eval(input())) for _ in range(B)] + [10**11] s.sort() t.sort() import bisect import itertools for _ in range(Q): pos = int(eval(input())) s_near_id = bisect.bisect_left(s, pos) - 1 t_near_id = bisect.bisect_left(t, pos) - 1 print( ( min( min( abs(pos - s_pos) + abs(s_pos - t_pos), abs(pos - t_pos) + abs(t_pos - s_pos), ) for s_pos, t_pos in itertools.product( s[s_near_id : s_near_id + 2], t[t_near_id : t_near_id + 2] ) ) ) )
A, B, Q = list(map(int, input().split())) s = [-(10**11)] + [int(eval(input())) for _ in range(A)] + [10**11] t = [-(10**11)] + [int(eval(input())) for _ in range(B)] + [10**11] s.sort() t.sort() import bisect import itertools for _ in range(Q): pos = int(eval(input())) near_s = bisect.bisect_left(s, pos) - 1 near_t = bisect.bisect_left(t, pos) - 1 s1, s2 = s[near_s], s[near_s + 1] t1, t2 = t[near_t], t[near_t + 1] print( ( min( pos - min(s1, t1), max(s2, t2) - pos, (s2 - pos) + (s2 - t1), (pos - t1) + (s2 - t1), (t2 - pos) + (t2 - s1), (pos - s1) + (t2 - s1), ) ) )
false
40.909091
[ "- s_near_id = bisect.bisect_left(s, pos) - 1", "- t_near_id = bisect.bisect_left(t, pos) - 1", "+ near_s = bisect.bisect_left(s, pos) - 1", "+ near_t = bisect.bisect_left(t, pos) - 1", "+ s1, s2 = s[near_s], s[near_s + 1]", "+ t1, t2 = t[near_t], t[near_t + 1]", "- min(", "- abs(pos - s_pos) + abs(s_pos - t_pos),", "- abs(pos - t_pos) + abs(t_pos - s_pos),", "- )", "- for s_pos, t_pos in itertools.product(", "- s[s_near_id : s_near_id + 2], t[t_near_id : t_near_id + 2]", "- )", "+ pos - min(s1, t1),", "+ max(s2, t2) - pos,", "+ (s2 - pos) + (s2 - t1),", "+ (pos - t1) + (s2 - t1),", "+ (t2 - pos) + (t2 - s1),", "+ (pos - s1) + (t2 - s1)," ]
false
0.007425
0.044747
0.165934
[ "s162995832", "s770971893" ]
u923668099
p02258
python
s495207722
s296857004
510
310
7,676
7,676
Accepted
Accepted
39.22
n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(eval(input())) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
import sys n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(sys.stdin.readline()) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
12
13
195
220
n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(eval(input())) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
import sys n = int(eval(input())) dif_max = -float("inf") min_v = float("inf") for i in range(n): r = int(sys.stdin.readline()) dif_max = max(dif_max, r - min_v) min_v = min(min_v, r) print(dif_max)
false
7.692308
[ "+import sys", "+", "- r = int(eval(input()))", "+ r = int(sys.stdin.readline())" ]
false
0.039313
0.036189
1.086314
[ "s495207722", "s296857004" ]
u745360181
p00423
python
s904982754
s085661507
110
100
5,608
5,620
Accepted
Accepted
9.09
while True: n = int(eval(input())) if n == 0: break sum_a = sum_b = 0 for i in range(n): a, b = list(map(int, input().split())) if a > b:sum_a = sum_a + a + b elif a < b:sum_b = sum_b + a + b else: sum_a = sum_a + a sum_b = sum_b + b print((sum_a,sum_b))
while 1: n = int(eval(input())) if n == 0: break sum_a = 0 sum_b = 0 for i in range(n): a,b = list(map(int, input().split())) if a > b: sum_a = sum_a + a + b elif a < b: sum_b = sum_b + a + b elif a == b: sum_a = sum_a + a sum_b = sum_b + b print(("%s %s" %(sum_a,sum_b)))
13
23
330
424
while True: n = int(eval(input())) if n == 0: break sum_a = sum_b = 0 for i in range(n): a, b = list(map(int, input().split())) if a > b: sum_a = sum_a + a + b elif a < b: sum_b = sum_b + a + b else: sum_a = sum_a + a sum_b = sum_b + b print((sum_a, sum_b))
while 1: n = int(eval(input())) if n == 0: break sum_a = 0 sum_b = 0 for i in range(n): a, b = list(map(int, input().split())) if a > b: sum_a = sum_a + a + b elif a < b: sum_b = sum_b + a + b elif a == b: sum_a = sum_a + a sum_b = sum_b + b print(("%s %s" % (sum_a, sum_b)))
false
43.478261
[ "-while True:", "+while 1:", "- sum_a = sum_b = 0", "+ sum_a = 0", "+ sum_b = 0", "- else:", "+ elif a == b:", "- print((sum_a, sum_b))", "+ print((\"%s %s\" % (sum_a, sum_b)))" ]
false
0.038924
0.038689
1.006076
[ "s904982754", "s085661507" ]
u790710233
p02984
python
s365269746
s460167701
170
127
14,092
14,092
Accepted
Accepted
25.29
n = int(eval(input())) A = list(map(int, input().split())) SUM = sum(A) dp = [0]*n dp[0] = cnt = 0 for i in range(1, n): dp[i] = 2*A[i-1]-dp[i-1] cnt += dp[i] init = SUM-cnt dp = [0]*n dp[0] = cnt = init for i in range(1, n): dp[i] = 2*A[i-1]-dp[i-1] cnt += dp[i] print((*dp))
n = int(eval(input())) A = list(map(int, input().split())) SUM = sum(A) init = SUM - 2*sum(A[1::2]) dp = [0]*n dp[0] = init for i in range(1, n): dp[i] = 2*A[i-1]-dp[i-1] print((*dp))
18
9
304
188
n = int(eval(input())) A = list(map(int, input().split())) SUM = sum(A) dp = [0] * n dp[0] = cnt = 0 for i in range(1, n): dp[i] = 2 * A[i - 1] - dp[i - 1] cnt += dp[i] init = SUM - cnt dp = [0] * n dp[0] = cnt = init for i in range(1, n): dp[i] = 2 * A[i - 1] - dp[i - 1] cnt += dp[i] print((*dp))
n = int(eval(input())) A = list(map(int, input().split())) SUM = sum(A) init = SUM - 2 * sum(A[1::2]) dp = [0] * n dp[0] = init for i in range(1, n): dp[i] = 2 * A[i - 1] - dp[i - 1] print((*dp))
false
50
[ "+init = SUM - 2 * sum(A[1::2])", "-dp[0] = cnt = 0", "+dp[0] = init", "- cnt += dp[i]", "-init = SUM - cnt", "-dp = [0] * n", "-dp[0] = cnt = init", "-for i in range(1, n):", "- dp[i] = 2 * A[i - 1] - dp[i - 1]", "- cnt += dp[i]" ]
false
0.047294
0.04754
0.994822
[ "s365269746", "s460167701" ]
u729133443
p02647
python
s179116548
s791694697
1,976
286
35,516
172,352
Accepted
Accepted
85.53
import sys from itertools import accumulate input=sys.stdin.buffer.readline def main(): n,k=list(map(int,input().split())) a=[*list(map(int,input().split()))] for _ in'_'*k: b=[0]*n for i,t in enumerate(a): if i>t:b[i-t]+=1 else:b[0]+=1 j=i-~t if j<n:b[j]-=1 a=[*accumulate(b)] if min(a)==n:break print((' '.join(map(str,a)))) main()
n,k,*a=list(map(int,open(0).read().split())) r=list(range(n)) for _ in a[:k][:41]: b=[0]*n*3 for i in r:b[max(0,i-a[i])]+=1;b[i-~a[i]]-=1 for i in r:b[i+1]+=b[i] a=b print((*a[:n]))
17
8
431
178
import sys from itertools import accumulate input = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) a = [*list(map(int, input().split()))] for _ in "_" * k: b = [0] * n for i, t in enumerate(a): if i > t: b[i - t] += 1 else: b[0] += 1 j = i - ~t if j < n: b[j] -= 1 a = [*accumulate(b)] if min(a) == n: break print((" ".join(map(str, a)))) main()
n, k, *a = list(map(int, open(0).read().split())) r = list(range(n)) for _ in a[:k][:41]: b = [0] * n * 3 for i in r: b[max(0, i - a[i])] += 1 b[i - ~a[i]] -= 1 for i in r: b[i + 1] += b[i] a = b print((*a[:n]))
false
52.941176
[ "-import sys", "-from itertools import accumulate", "-", "-input = sys.stdin.buffer.readline", "-", "-", "-def main():", "- n, k = list(map(int, input().split()))", "- a = [*list(map(int, input().split()))]", "- for _ in \"_\" * k:", "- b = [0] * n", "- for i, t in enumerate(a):", "- if i > t:", "- b[i - t] += 1", "- else:", "- b[0] += 1", "- j = i - ~t", "- if j < n:", "- b[j] -= 1", "- a = [*accumulate(b)]", "- if min(a) == n:", "- break", "- print((\" \".join(map(str, a))))", "-", "-", "-main()", "+n, k, *a = list(map(int, open(0).read().split()))", "+r = list(range(n))", "+for _ in a[:k][:41]:", "+ b = [0] * n * 3", "+ for i in r:", "+ b[max(0, i - a[i])] += 1", "+ b[i - ~a[i]] -= 1", "+ for i in r:", "+ b[i + 1] += b[i]", "+ a = b", "+print((*a[:n]))" ]
false
0.134377
0.045379
2.961227
[ "s179116548", "s791694697" ]
u745087332
p03287
python
s067374321
s311146377
91
77
17,284
17,284
Accepted
Accepted
15.38
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和(mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] # 各要素の個数を数える C = Counter(S) ans = 0 for num in C: if C[num] <= 1: continue # C[num]個から2つ選ぶ組み合わせ ans += C[num] * (C[num] - 1) // 2 # 1箱で条件を満たす(Si = 0, l=r)場合を加算 return ans + C[0] N, M = inpl() A = inpl() print((solve(N, M, A)))
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和S (mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) ans = 0 # 各要素の個数を数える for v in list(Counter(S).values()): # v個から2個選ぶ組み合わせ ans += v * (v - 1) // 2 return ans N, M = inpl() A = inpl() print((solve(N, M, A)))
37
31
634
512
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和(mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] # 各要素の個数を数える C = Counter(S) ans = 0 for num in C: if C[num] <= 1: continue # C[num]個から2つ選ぶ組み合わせ ans += C[num] * (C[num] - 1) // 2 # 1箱で条件を満たす(Si = 0, l=r)場合を加算 return ans + C[0] N, M = inpl() A = inpl() print((solve(N, M, A)))
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和S (mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) ans = 0 # 各要素の個数を数える for v in list(Counter(S).values()): # v個から2個選ぶ組み合わせ ans += v * (v - 1) // 2 return ans N, M = inpl() A = inpl() print((solve(N, M, A)))
false
16.216216
[ "- # 累積和(mod M)を求める", "+ # 累積和S (mod M)を求める", "- del S[0]", "+ ans = 0", "- C = Counter(S)", "- ans = 0", "- for num in C:", "- if C[num] <= 1:", "- continue", "- # C[num]個から2つ選ぶ組み合わせ", "- ans += C[num] * (C[num] - 1) // 2", "- # 1箱で条件を満たす(Si = 0, l=r)場合を加算", "- return ans + C[0]", "+ for v in list(Counter(S).values()):", "+ # v個から2個選ぶ組み合わせ", "+ ans += v * (v - 1) // 2", "+ return ans" ]
false
0.079439
0.03856
2.060156
[ "s067374321", "s311146377" ]
u619819312
p03624
python
s845372120
s997244128
45
37
3,188
3,188
Accepted
Accepted
17.78
a=[True]*26 s=eval(input()) for i in range(len(s)): a[ord(s[i])-ord("a")]=False for i in range(26): if a[i]: print((chr(ord("a")+i))) break else: print("None")
d=[0]*26 for i in eval(input()): d[ord(i)-97]+=1 print((chr(97+d.index(0)) if 0 in d else"None"))
10
4
188
96
a = [True] * 26 s = eval(input()) for i in range(len(s)): a[ord(s[i]) - ord("a")] = False for i in range(26): if a[i]: print((chr(ord("a") + i))) break else: print("None")
d = [0] * 26 for i in eval(input()): d[ord(i) - 97] += 1 print((chr(97 + d.index(0)) if 0 in d else "None"))
false
60
[ "-a = [True] * 26", "-s = eval(input())", "-for i in range(len(s)):", "- a[ord(s[i]) - ord(\"a\")] = False", "-for i in range(26):", "- if a[i]:", "- print((chr(ord(\"a\") + i)))", "- break", "-else:", "- print(\"None\")", "+d = [0] * 26", "+for i in eval(input()):", "+ d[ord(i) - 97] += 1", "+print((chr(97 + d.index(0)) if 0 in d else \"None\"))" ]
false
0.116112
0.0455
2.551897
[ "s845372120", "s997244128" ]
u863370423
p03563
python
s999717412
s968447379
17
10
2,940
2,568
Accepted
Accepted
41.18
r=int(eval(input())) g=int(eval(input())) print((2*g - r))
r=float(input()) g=float(input()) if int(g*2-r)==float(g*2-r): print(int(g*2-r)) else: print(g*2-r)
4
7
57
114
r = int(eval(input())) g = int(eval(input())) print((2 * g - r))
r = float(input()) g = float(input()) if int(g * 2 - r) == float(g * 2 - r): print(int(g * 2 - r)) else: print(g * 2 - r)
false
42.857143
[ "-r = int(eval(input()))", "-g = int(eval(input()))", "-print((2 * g - r))", "+r = float(input())", "+g = float(input())", "+if int(g * 2 - r) == float(g * 2 - r):", "+ print(int(g * 2 - r))", "+else:", "+ print(g * 2 - r)" ]
false
0.087884
0.057258
1.534874
[ "s999717412", "s968447379" ]
u207241407
p03142
python
s141216648
s560318544
413
329
35,440
21,564
Accepted
Accepted
20.34
import sys from collections import defaultdict, deque def main(): n, m = list(map(int, sys.stdin.readline().split())) out_list = defaultdict(list) in_cnt = defaultdict(int) for _ in range(n - 1 + m): a, b = list(map(int, sys.stdin.readline().split())) out_list[a].append(b) in_cnt[b] = in_cnt[b] + 1 ans = [0] * (n + 1) que = deque([i for i in range(n) if in_cnt[i] == 0]) while que: p = que.popleft() for i in out_list[p]: in_cnt[i] = in_cnt[i] - 1 if in_cnt[i] == 0: que.append(i) ans[i] = p for i in ans[1:]: print(i) if __name__ == "__main__": main()
import sys from collections import deque def main(): n, m = list(map(int, sys.stdin.readline().split())) out_list = [[] for _ in range(n + 1)] in_cnt = [0] * (n + 1) in_cnt[0] = -1 for _ in range(n - 1 + m): a, b = list(map(int, sys.stdin.readline().split())) out_list[a].append(b) in_cnt[b] = in_cnt[b] + 1 root = in_cnt.index(0) ans = [0] * (n + 1) que = deque([root]) while que: p = que.popleft() for i in out_list[p]: in_cnt[i] = in_cnt[i] - 1 if in_cnt[i] == 0: que.append(i) ans[i] = p for i in ans[1:]: print(i) if __name__ == "__main__": main()
30
32
718
726
import sys from collections import defaultdict, deque def main(): n, m = list(map(int, sys.stdin.readline().split())) out_list = defaultdict(list) in_cnt = defaultdict(int) for _ in range(n - 1 + m): a, b = list(map(int, sys.stdin.readline().split())) out_list[a].append(b) in_cnt[b] = in_cnt[b] + 1 ans = [0] * (n + 1) que = deque([i for i in range(n) if in_cnt[i] == 0]) while que: p = que.popleft() for i in out_list[p]: in_cnt[i] = in_cnt[i] - 1 if in_cnt[i] == 0: que.append(i) ans[i] = p for i in ans[1:]: print(i) if __name__ == "__main__": main()
import sys from collections import deque def main(): n, m = list(map(int, sys.stdin.readline().split())) out_list = [[] for _ in range(n + 1)] in_cnt = [0] * (n + 1) in_cnt[0] = -1 for _ in range(n - 1 + m): a, b = list(map(int, sys.stdin.readline().split())) out_list[a].append(b) in_cnt[b] = in_cnt[b] + 1 root = in_cnt.index(0) ans = [0] * (n + 1) que = deque([root]) while que: p = que.popleft() for i in out_list[p]: in_cnt[i] = in_cnt[i] - 1 if in_cnt[i] == 0: que.append(i) ans[i] = p for i in ans[1:]: print(i) if __name__ == "__main__": main()
false
6.25
[ "-from collections import defaultdict, deque", "+from collections import deque", "- out_list = defaultdict(list)", "- in_cnt = defaultdict(int)", "+ out_list = [[] for _ in range(n + 1)]", "+ in_cnt = [0] * (n + 1)", "+ in_cnt[0] = -1", "+ root = in_cnt.index(0)", "- que = deque([i for i in range(n) if in_cnt[i] == 0])", "+ que = deque([root])" ]
false
0.045222
0.03641
1.242014
[ "s141216648", "s560318544" ]
u335406314
p02719
python
s493725339
s652442357
28
24
9,108
9,084
Accepted
Accepted
14.29
N,K=list(map(int,input(' ').split(' '))) print((min(N%K,(-N)%K)))
N,K=list(map(int,input().split())) print((min(N%K,-N%K)))
2
2
64
50
N, K = list(map(int, input(" ").split(" "))) print((min(N % K, (-N) % K)))
N, K = list(map(int, input().split())) print((min(N % K, -N % K)))
false
0
[ "-N, K = list(map(int, input(\" \").split(\" \")))", "-print((min(N % K, (-N) % K)))", "+N, K = list(map(int, input().split()))", "+print((min(N % K, -N % K)))" ]
false
0.121426
0.007813
15.541297
[ "s493725339", "s652442357" ]
u256678932
p02418
python
s102754077
s156224570
30
20
7,432
5,556
Accepted
Accepted
33.33
s = eval(input()) p = eval(input()) if p in s+s: print('Yes') else: print('No')
def main(): s = eval(input()) p = eval(input()) if p in s*2: print("Yes") else: print("No") if __name__ == '__main__': main()
7
12
82
164
s = eval(input()) p = eval(input()) if p in s + s: print("Yes") else: print("No")
def main(): s = eval(input()) p = eval(input()) if p in s * 2: print("Yes") else: print("No") if __name__ == "__main__": main()
false
41.666667
[ "-s = eval(input())", "-p = eval(input())", "-if p in s + s:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+def main():", "+ s = eval(input())", "+ p = eval(input())", "+ if p in s * 2:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.035146
0.037694
0.932406
[ "s102754077", "s156224570" ]
u506858457
p02630
python
s985790780
s404664754
559
300
23,852
97,932
Accepted
Accepted
46.33
N=int(eval(input())) A=list(map(int,input().split())) TMP=sum(A) Q=int(eval(input())) import collections List=collections.Counter(A) for i in range(Q): S,T=list(map(int,input().split())) TMP=TMP+(T-S)*List[S] print(TMP) List[T]+=List[S] List[S]=0
def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N=II() A=LI() Sum=sum(A) Q=II() cnt={} queries=[] for i in range(Q): b,c=MI() queries.append((b,c)) for a in A: if a not in cnt: cnt[a]=0 cnt[a]+=1 #print(cnt) for b,c in queries: if b in cnt: Sum-=cnt[b]*b Sum+=cnt[b]*c if c not in cnt: cnt[c]=0 cnt[c]+=cnt[b] cnt[b]=0 print(Sum)
12
27
253
478
N = int(eval(input())) A = list(map(int, input().split())) TMP = sum(A) Q = int(eval(input())) import collections List = collections.Counter(A) for i in range(Q): S, T = list(map(int, input().split())) TMP = TMP + (T - S) * List[S] print(TMP) List[T] += List[S] List[S] = 0
def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N = II() A = LI() Sum = sum(A) Q = II() cnt = {} queries = [] for i in range(Q): b, c = MI() queries.append((b, c)) for a in A: if a not in cnt: cnt[a] = 0 cnt[a] += 1 # print(cnt) for b, c in queries: if b in cnt: Sum -= cnt[b] * b Sum += cnt[b] * c if c not in cnt: cnt[c] = 0 cnt[c] += cnt[b] cnt[b] = 0 print(Sum)
false
55.555556
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-TMP = sum(A)", "-Q = int(eval(input()))", "-import collections", "+def II():", "+ return int(eval(input()))", "-List = collections.Counter(A)", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+N = II()", "+A = LI()", "+Sum = sum(A)", "+Q = II()", "+cnt = {}", "+queries = []", "- S, T = list(map(int, input().split()))", "- TMP = TMP + (T - S) * List[S]", "- print(TMP)", "- List[T] += List[S]", "- List[S] = 0", "+ b, c = MI()", "+ queries.append((b, c))", "+for a in A:", "+ if a not in cnt:", "+ cnt[a] = 0", "+ cnt[a] += 1", "+# print(cnt)", "+for b, c in queries:", "+ if b in cnt:", "+ Sum -= cnt[b] * b", "+ Sum += cnt[b] * c", "+ if c not in cnt:", "+ cnt[c] = 0", "+ cnt[c] += cnt[b]", "+ cnt[b] = 0", "+ print(Sum)" ]
false
0.035772
0.120976
0.295692
[ "s985790780", "s404664754" ]
u729133443
p02579
python
s007695417
s847412166
817
751
185,496
227,276
Accepted
Accepted
8.08
from collections import* I=9**9 (h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3) m,d=list(zip(*eval('(input(),[I]*w),'*h))) q=deque([(s-1,t-1,1)]) while q: y,x,c=q.popleft() if d[y][x]>c: d[y][x]=c for i in range(y-2,y+3): for j in range(x-2,x+3):h>i>-1<j<w<I==d[i][j]!=m[i][j]>'#'!=(abs(y-i)+abs(x-j)<2!=q.appendleft((i,j,c))or q.append((i,j,c+1))) print((d[f-1][g-1]%I-1))
from collections import* I=9**9 (h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3) m,d=list(zip(*eval('(input(),[I]*w),'*h))) q=deque([(s-1,t-1,1)]) while q: y,x,c=q.popleft() if d[y][x]>c: d[y][x]=c for i in range(y-2,y+3): for j in range(x-2,x+3):h>i>-1<j<w<d[i][j]!=m[i][j]>'#'!=(abs(y-i)+abs(x-j)<2!=q.appendleft((i,j,c))or q.append((i,j,c+1))) print((d[f-1][g-1]%I-1))
12
12
391
388
from collections import * I = 9**9 (h, w), (s, t), (f, g) = eval("map(int,input().split())," * 3) m, d = list(zip(*eval("(input(),[I]*w)," * h))) q = deque([(s - 1, t - 1, 1)]) while q: y, x, c = q.popleft() if d[y][x] > c: d[y][x] = c for i in range(y - 2, y + 3): for j in range(x - 2, x + 3): h > i > -1 < j < w < I == d[i][j] != m[i][j] > "#" != ( abs(y - i) + abs(x - j) < 2 != q.appendleft((i, j, c)) or q.append((i, j, c + 1)) ) print((d[f - 1][g - 1] % I - 1))
from collections import * I = 9**9 (h, w), (s, t), (f, g) = eval("map(int,input().split())," * 3) m, d = list(zip(*eval("(input(),[I]*w)," * h))) q = deque([(s - 1, t - 1, 1)]) while q: y, x, c = q.popleft() if d[y][x] > c: d[y][x] = c for i in range(y - 2, y + 3): for j in range(x - 2, x + 3): h > i > -1 < j < w < d[i][j] != m[i][j] > "#" != ( abs(y - i) + abs(x - j) < 2 != q.appendleft((i, j, c)) or q.append((i, j, c + 1)) ) print((d[f - 1][g - 1] % I - 1))
false
0
[ "- h > i > -1 < j < w < I == d[i][j] != m[i][j] > \"#\" != (", "+ h > i > -1 < j < w < d[i][j] != m[i][j] > \"#\" != (" ]
false
0.043601
0.007619
5.722448
[ "s007695417", "s847412166" ]
u588341295
p03944
python
s959213139
s094564173
82
18
3,188
3,064
Accepted
Accepted
78.05
# -*- coding: utf-8 -*- W, H, N = list(map(int, input().split())) HW = [[0 for i in range(W)] for j in range(H)] aN = [list(map(int, input().split())) for i in range (N)] for i in range(N): if aN[i][2] == 1: for j in range(H): for k in range(aN[i][0]): HW[j][k] = 1 elif aN[i][2] == 2: for j in range(H): for k in range(aN[i][0], W): HW[j][k] = 1 elif aN[i][2] == 3: for j in range(aN[i][1]): for k in range(W): HW[j][k] = 1 elif aN[i][2] == 4: for j in range(aN[i][1], H): for k in range(W): HW[j][k] = 1 ans = 0 for i in range(H): ans += HW[i].count(0) print(ans)
# -*- coding: utf-8 -*- W, H, N = list(map(int, input().split())) aN = [list(map(int, input().split())) for i in range (N)] # 1マスずつ塗りつぶさないパターン(こっちのが速い) minXY = [0, 0] maxXY = [W, H] for i in range(N): if aN[i][2] == 1: minXY[0] = max(minXY[0], aN[i][0]) elif aN[i][2] == 2: maxXY[0] = min(maxXY[0], aN[i][0]) elif aN[i][2] == 3: minXY[1] = max(minXY[1], aN[i][1]) elif aN[i][2] == 4: maxXY[1] = min(maxXY[1], aN[i][1]) # 縦横それぞれにマイナスの可能性を考慮する ansW = maxXY[0] - minXY[0] ansH = maxXY[1] - minXY[1] if ansW < 0: ansW = 0 if ansH < 0: ansH = 0 print((ansH * ansW))
33
31
763
650
# -*- coding: utf-8 -*- W, H, N = list(map(int, input().split())) HW = [[0 for i in range(W)] for j in range(H)] aN = [list(map(int, input().split())) for i in range(N)] for i in range(N): if aN[i][2] == 1: for j in range(H): for k in range(aN[i][0]): HW[j][k] = 1 elif aN[i][2] == 2: for j in range(H): for k in range(aN[i][0], W): HW[j][k] = 1 elif aN[i][2] == 3: for j in range(aN[i][1]): for k in range(W): HW[j][k] = 1 elif aN[i][2] == 4: for j in range(aN[i][1], H): for k in range(W): HW[j][k] = 1 ans = 0 for i in range(H): ans += HW[i].count(0) print(ans)
# -*- coding: utf-8 -*- W, H, N = list(map(int, input().split())) aN = [list(map(int, input().split())) for i in range(N)] # 1マスずつ塗りつぶさないパターン(こっちのが速い) minXY = [0, 0] maxXY = [W, H] for i in range(N): if aN[i][2] == 1: minXY[0] = max(minXY[0], aN[i][0]) elif aN[i][2] == 2: maxXY[0] = min(maxXY[0], aN[i][0]) elif aN[i][2] == 3: minXY[1] = max(minXY[1], aN[i][1]) elif aN[i][2] == 4: maxXY[1] = min(maxXY[1], aN[i][1]) # 縦横それぞれにマイナスの可能性を考慮する ansW = maxXY[0] - minXY[0] ansH = maxXY[1] - minXY[1] if ansW < 0: ansW = 0 if ansH < 0: ansH = 0 print((ansH * ansW))
false
6.060606
[ "-HW = [[0 for i in range(W)] for j in range(H)]", "+# 1マスずつ塗りつぶさないパターン(こっちのが速い)", "+minXY = [0, 0]", "+maxXY = [W, H]", "- for j in range(H):", "- for k in range(aN[i][0]):", "- HW[j][k] = 1", "+ minXY[0] = max(minXY[0], aN[i][0])", "- for j in range(H):", "- for k in range(aN[i][0], W):", "- HW[j][k] = 1", "+ maxXY[0] = min(maxXY[0], aN[i][0])", "- for j in range(aN[i][1]):", "- for k in range(W):", "- HW[j][k] = 1", "+ minXY[1] = max(minXY[1], aN[i][1])", "- for j in range(aN[i][1], H):", "- for k in range(W):", "- HW[j][k] = 1", "-ans = 0", "-for i in range(H):", "- ans += HW[i].count(0)", "-print(ans)", "+ maxXY[1] = min(maxXY[1], aN[i][1])", "+# 縦横それぞれにマイナスの可能性を考慮する", "+ansW = maxXY[0] - minXY[0]", "+ansH = maxXY[1] - minXY[1]", "+if ansW < 0:", "+ ansW = 0", "+if ansH < 0:", "+ ansH = 0", "+print((ansH * ansW))" ]
false
0.007162
0.061108
0.117199
[ "s959213139", "s094564173" ]
u232852711
p03946
python
s454922642
s621862686
207
135
17,244
14,224
Accepted
Accepted
34.78
n, t = list(map(int, input().split())) a = list(map(int, input().split())) remain_max = [a[-1]]*n for i in range(1, n): remain_max[-(i+1)] = max(a[-i], remain_max[-i]) diffs1 = [0]*n for i in range(n): diffs1[i] = remain_max[i] - a[i] max_diff1 = 0 ans1 = 0 for i in range(n): if diffs1[i] > max_diff1: max_diff1 = diffs1[i] ans1 = 1 elif diffs1[i] == max_diff1: ans1 += 1 # print(diffs1, ans1) remain_min = [a[0]]*n for i in range(1, n): remain_min[i] = min(a[i-1], remain_min[i-1]) diffs2 = [0]*n for i in range(n): diffs2[i] = a[i] - remain_min[i] max_diff2 = 0 ans2 = 0 for i in range(n): if diffs2[i] > max_diff2: max_diff2 = diffs2[i] ans2 = 1 elif diffs2[i] == max_diff2: ans2 += 1 # print(diffs2, ans2) print((min(ans1, ans2)))
n, t = list(map(int, input().split())) a = list(map(int, input().split())) remain_max = [a[-1]]*n for i in range(1, n): remain_max[-(i+1)] = max(a[-i], remain_max[-i]) diffs = [0]*n for i in range(n): diffs[i] = remain_max[i] - a[i] max_diff = 0 ans = 0 for i in range(n): if diffs[i] > max_diff: max_diff = diffs[i] ans = 1 elif diffs[i] == max_diff: ans += 1 print(ans)
41
21
870
435
n, t = list(map(int, input().split())) a = list(map(int, input().split())) remain_max = [a[-1]] * n for i in range(1, n): remain_max[-(i + 1)] = max(a[-i], remain_max[-i]) diffs1 = [0] * n for i in range(n): diffs1[i] = remain_max[i] - a[i] max_diff1 = 0 ans1 = 0 for i in range(n): if diffs1[i] > max_diff1: max_diff1 = diffs1[i] ans1 = 1 elif diffs1[i] == max_diff1: ans1 += 1 # print(diffs1, ans1) remain_min = [a[0]] * n for i in range(1, n): remain_min[i] = min(a[i - 1], remain_min[i - 1]) diffs2 = [0] * n for i in range(n): diffs2[i] = a[i] - remain_min[i] max_diff2 = 0 ans2 = 0 for i in range(n): if diffs2[i] > max_diff2: max_diff2 = diffs2[i] ans2 = 1 elif diffs2[i] == max_diff2: ans2 += 1 # print(diffs2, ans2) print((min(ans1, ans2)))
n, t = list(map(int, input().split())) a = list(map(int, input().split())) remain_max = [a[-1]] * n for i in range(1, n): remain_max[-(i + 1)] = max(a[-i], remain_max[-i]) diffs = [0] * n for i in range(n): diffs[i] = remain_max[i] - a[i] max_diff = 0 ans = 0 for i in range(n): if diffs[i] > max_diff: max_diff = diffs[i] ans = 1 elif diffs[i] == max_diff: ans += 1 print(ans)
false
48.780488
[ "-diffs1 = [0] * n", "+diffs = [0] * n", "- diffs1[i] = remain_max[i] - a[i]", "-max_diff1 = 0", "-ans1 = 0", "+ diffs[i] = remain_max[i] - a[i]", "+max_diff = 0", "+ans = 0", "- if diffs1[i] > max_diff1:", "- max_diff1 = diffs1[i]", "- ans1 = 1", "- elif diffs1[i] == max_diff1:", "- ans1 += 1", "-# print(diffs1, ans1)", "-remain_min = [a[0]] * n", "-for i in range(1, n):", "- remain_min[i] = min(a[i - 1], remain_min[i - 1])", "-diffs2 = [0] * n", "-for i in range(n):", "- diffs2[i] = a[i] - remain_min[i]", "-max_diff2 = 0", "-ans2 = 0", "-for i in range(n):", "- if diffs2[i] > max_diff2:", "- max_diff2 = diffs2[i]", "- ans2 = 1", "- elif diffs2[i] == max_diff2:", "- ans2 += 1", "-# print(diffs2, ans2)", "-print((min(ans1, ans2)))", "+ if diffs[i] > max_diff:", "+ max_diff = diffs[i]", "+ ans = 1", "+ elif diffs[i] == max_diff:", "+ ans += 1", "+print(ans)" ]
false
0.040027
0.106031
0.377505
[ "s454922642", "s621862686" ]
u232652798
p02640
python
s400989374
s071821942
30
26
9,084
9,172
Accepted
Accepted
13.33
x, y = [int(x) for x in input().split()] for i in range(x+1): ans = 'No' b = x - i if (i*2 + b*4) == y: ans = 'Yes' break print(ans)
X, Y = [int(x) for x in input().split()] check = True if X*4 < Y: check = False elif Y < 2*X: check = False elif Y%2==1: check = False if check: print('Yes') else: print('No')
10
13
171
208
x, y = [int(x) for x in input().split()] for i in range(x + 1): ans = "No" b = x - i if (i * 2 + b * 4) == y: ans = "Yes" break print(ans)
X, Y = [int(x) for x in input().split()] check = True if X * 4 < Y: check = False elif Y < 2 * X: check = False elif Y % 2 == 1: check = False if check: print("Yes") else: print("No")
false
23.076923
[ "-x, y = [int(x) for x in input().split()]", "-for i in range(x + 1):", "- ans = \"No\"", "- b = x - i", "- if (i * 2 + b * 4) == y:", "- ans = \"Yes\"", "- break", "-print(ans)", "+X, Y = [int(x) for x in input().split()]", "+check = True", "+if X * 4 < Y:", "+ check = False", "+elif Y < 2 * X:", "+ check = False", "+elif Y % 2 == 1:", "+ check = False", "+if check:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.044764
0.035945
1.245352
[ "s400989374", "s071821942" ]
u133347536
p03107
python
s356526786
s472297180
59
47
4,652
4,652
Accepted
Accepted
20.34
#python 3.7.1 s = list(eval(input())) s = [int(i) for i in s] n = 0 r = 0 b = 0 for i in s: if s[n] == 0: r += 1 elif s[n] == 1: b += 1 n += 1 print((min(r,b) * 2))
s = list(eval(input())) s = [int(i) for i in s] count_one = 0 count_zero = 0 for i in s: if i == 0: count_zero += 1 else: count_one += 1 print((min(count_one, count_zero) * 2))
13
10
175
202
# python 3.7.1 s = list(eval(input())) s = [int(i) for i in s] n = 0 r = 0 b = 0 for i in s: if s[n] == 0: r += 1 elif s[n] == 1: b += 1 n += 1 print((min(r, b) * 2))
s = list(eval(input())) s = [int(i) for i in s] count_one = 0 count_zero = 0 for i in s: if i == 0: count_zero += 1 else: count_one += 1 print((min(count_one, count_zero) * 2))
false
23.076923
[ "-# python 3.7.1", "-n = 0", "-r = 0", "-b = 0", "+count_one = 0", "+count_zero = 0", "- if s[n] == 0:", "- r += 1", "- elif s[n] == 1:", "- b += 1", "- n += 1", "-print((min(r, b) * 2))", "+ if i == 0:", "+ count_zero += 1", "+ else:", "+ count_one += 1", "+print((min(count_one, count_zero) * 2))" ]
false
0.046837
0.046094
1.01613
[ "s356526786", "s472297180" ]
u141610915
p03061
python
s448647165
s740213383
711
344
87,776
85,228
Accepted
Accepted
51.62
import sys from fractions import gcd input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) class SegTree: def segfunc(self, x, y): return gcd(x, y) #ここ判定関数(ただし結合則があるもの) def __init__(self, n, ide_ele, init_val): #####単位元###### self.ide_ele = ide_ele #num:n以上の最小の2のべき乗 self.num = 2 ** (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num #set_val for i in range(n): self.seg[i + self.num - 1] = init_val[i] #built for i in range(self.num - 2, -1, -1) : self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) def update(self, k, x): k += self.num - 1 self.seg[k] = x while k + 1: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = self.segfunc(res, self.seg[p]) if q & 1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res seg = SegTree(N, 0, a) res = 0 for i in range(N): res = max(res, gcd(seg.query(0, i), seg.query(i + 1, N))) #print(seg.query(0, i), seg.query(i + 1, N)) print(res)
import sys from fractions import gcd input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) l = [0] * (N + 1) r = [0] * (N + 1) for i in range(N): l[i + 1] = gcd(l[i], a[i]) a.reverse() for i in range(N): r[i + 1] = gcd(r[i], a[i]) res = 0 for i in range(N + 1): res = max(res, gcd(l[i], r[N - i - 1])) print(res)
51
13
1,511
351
import sys from fractions import gcd input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) class SegTree: def segfunc(self, x, y): return gcd(x, y) # ここ判定関数(ただし結合則があるもの) def __init__(self, n, ide_ele, init_val): #####単位元###### self.ide_ele = ide_ele # num:n以上の最小の2のべき乗 self.num = 2 ** (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num # set_val for i in range(n): self.seg[i + self.num - 1] = init_val[i] # built for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) def update(self, k, x): k += self.num - 1 self.seg[k] = x while k + 1: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = self.segfunc(res, self.seg[p]) if q & 1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res seg = SegTree(N, 0, a) res = 0 for i in range(N): res = max(res, gcd(seg.query(0, i), seg.query(i + 1, N))) # print(seg.query(0, i), seg.query(i + 1, N)) print(res)
import sys from fractions import gcd input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) l = [0] * (N + 1) r = [0] * (N + 1) for i in range(N): l[i + 1] = gcd(l[i], a[i]) a.reverse() for i in range(N): r[i + 1] = gcd(r[i], a[i]) res = 0 for i in range(N + 1): res = max(res, gcd(l[i], r[N - i - 1])) print(res)
false
74.509804
[ "-", "-", "-class SegTree:", "- def segfunc(self, x, y):", "- return gcd(x, y) # ここ判定関数(ただし結合則があるもの)", "-", "- def __init__(self, n, ide_ele, init_val):", "- #####単位元######", "- self.ide_ele = ide_ele", "- # num:n以上の最小の2のべき乗", "- self.num = 2 ** (n - 1).bit_length()", "- self.seg = [self.ide_ele] * 2 * self.num", "- # set_val", "- for i in range(n):", "- self.seg[i + self.num - 1] = init_val[i]", "- # built", "- for i in range(self.num - 2, -1, -1):", "- self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])", "-", "- def update(self, k, x):", "- k += self.num - 1", "- self.seg[k] = x", "- while k + 1:", "- k = (k - 1) // 2", "- self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])", "-", "- def query(self, p, q):", "- if q <= p:", "- return self.ide_ele", "- p += self.num - 1", "- q += self.num - 2", "- res = self.ide_ele", "- while q - p > 1:", "- if p & 1 == 0:", "- res = self.segfunc(res, self.seg[p])", "- if q & 1 == 1:", "- res = self.segfunc(res, self.seg[q])", "- q -= 1", "- p = p // 2", "- q = (q - 1) // 2", "- if p == q:", "- res = self.segfunc(res, self.seg[p])", "- else:", "- res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])", "- return res", "-", "-", "-seg = SegTree(N, 0, a)", "+l = [0] * (N + 1)", "+r = [0] * (N + 1)", "+for i in range(N):", "+ l[i + 1] = gcd(l[i], a[i])", "+a.reverse()", "+for i in range(N):", "+ r[i + 1] = gcd(r[i], a[i])", "-for i in range(N):", "- res = max(res, gcd(seg.query(0, i), seg.query(i + 1, N)))", "- # print(seg.query(0, i), seg.query(i + 1, N))", "+for i in range(N + 1):", "+ res = max(res, gcd(l[i], r[N - i - 1]))" ]
false
0.0595
0.04981
1.194537
[ "s448647165", "s740213383" ]
u390901183
p03160
python
s235272182
s087870987
143
129
13,780
13,980
Accepted
Accepted
9.79
N = int(eval(input())) h = [i for i in map(int, input().split())] """ dp値を書き込んでいく。 dp値はこの場合、その足場にたどり着くまでの最小コストのことである。 """ dp = [0] * N # 0番目でのコストは0なので dp[0] = 0 # 1番目でのコストは0番目から1つ飛ぶ場合の一通り。0と1番目の高さの差を代入 dp[1] = abs(h[0] - h[1]) # 2番目以降は、1つ前と2つ前から飛ぶ場合があるのでイテレーションする for i in range(2, N): dp[i] = min( dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]), ) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) """ dp[i]: カエルが足場 i にたどり着くまでの最小コスト i の一つ前は、 i-1 or i-2 にいる. dp[0] = 0. """ dp = [0] * N dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) print((dp[N - 1]))
18
14
434
313
N = int(eval(input())) h = [i for i in map(int, input().split())] """ dp値を書き込んでいく。 dp値はこの場合、その足場にたどり着くまでの最小コストのことである。 """ dp = [0] * N # 0番目でのコストは0なので dp[0] = 0 # 1番目でのコストは0番目から1つ飛ぶ場合の一通り。0と1番目の高さの差を代入 dp[1] = abs(h[0] - h[1]) # 2番目以降は、1つ前と2つ前から飛ぶ場合があるのでイテレーションする for i in range(2, N): dp[i] = min( dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]), ) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) """ dp[i]: カエルが足場 i にたどり着くまでの最小コスト i の一つ前は、 i-1 or i-2 にいる. dp[0] = 0. """ dp = [0] * N dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) print((dp[N - 1]))
false
22.222222
[ "-h = [i for i in map(int, input().split())]", "+h = list(map(int, input().split()))", "- dp値を書き込んでいく。", "- dp値はこの場合、その足場にたどり着くまでの最小コストのことである。", "+ dp[i]: カエルが足場 i にたどり着くまでの最小コスト", "+ i の一つ前は、 i-1 or i-2 にいる. dp[0] = 0.", "-# 0番目でのコストは0なので dp[0] = 0", "-# 1番目でのコストは0番目から1つ飛ぶ場合の一通り。0と1番目の高さの差を代入", "-dp[1] = abs(h[0] - h[1])", "-# 2番目以降は、1つ前と2つ前から飛ぶ場合があるのでイテレーションする", "+dp[1] = abs(h[1] - h[0])", "- dp[i] = min(", "- dp[i - 2] + abs(h[i] - h[i - 2]),", "- dp[i - 1] + abs(h[i] - h[i - 1]),", "- )", "+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))" ]
false
0.038531
0.03885
0.991801
[ "s235272182", "s087870987" ]
u811169796
p03295
python
s518193810
s953662396
457
404
16,976
18,964
Accepted
Accepted
11.6
n,m = list(map(int,input().split())) data = [] for i in range(m): a,b = list(map(int,input().split())) a -= 1 b -= 1 data.append((b,a)) data.sort() cnt = 0 dis = -1 for i in range(m): b,a = data[i] if(dis < a): cnt += 1 dis = b - 1 print(cnt)
n,m = list(map(int,input().split())) data = [] for i in range(m): a,b = list(map(int,input().split())) a -= 1 b -= 1 data.append((a,b)) data = sorted(data,key=lambda x:x[1]) cnt = 0 dis = -1 for i in range(m): a,b = data[i] if(dis < a): cnt += 1 dis = b - 1 print(cnt)
16
16
285
311
n, m = list(map(int, input().split())) data = [] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 data.append((b, a)) data.sort() cnt = 0 dis = -1 for i in range(m): b, a = data[i] if dis < a: cnt += 1 dis = b - 1 print(cnt)
n, m = list(map(int, input().split())) data = [] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 data.append((a, b)) data = sorted(data, key=lambda x: x[1]) cnt = 0 dis = -1 for i in range(m): a, b = data[i] if dis < a: cnt += 1 dis = b - 1 print(cnt)
false
0
[ "- data.append((b, a))", "-data.sort()", "+ data.append((a, b))", "+data = sorted(data, key=lambda x: x[1])", "- b, a = data[i]", "+ a, b = data[i]" ]
false
0.041844
0.043568
0.960433
[ "s518193810", "s953662396" ]
u007270338
p02267
python
s851469458
s363355733
60
50
6,320
6,552
Accepted
Accepted
16.67
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break print(cnt)
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(array)-1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_banpei_search() print(cnt)
15
37
242
736
# coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break print(cnt)
# coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array) - 1] array[len(array) - 1] = target n = 0 while array[n] != target: n += 1 array[len(array) - 1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_banpei_search() print(cnt)
false
59.459459
[ "-cnt = 0", "-for t in T:", "- for s in S:", "- if t == s:", "- cnt += 1", "- break", "+", "+", "+def search_banpei(array, target, cnt):", "+ tmp = array[len(array) - 1]", "+ array[len(array) - 1] = target", "+ n = 0", "+ while array[n] != target:", "+ n += 1", "+ array[len(array) - 1] = tmp", "+ if n < len(array) - 1 or target == tmp:", "+ cnt += 1", "+ return cnt", "+", "+", "+def linear_search():", "+ cnt = 0", "+ for t in T:", "+ for s in S:", "+ if t == s:", "+ cnt += 1", "+ break", "+", "+", "+def linear_banpei_search():", "+ cnt = 0", "+ for target in T:", "+ cnt = search_banpei(S, target, cnt)", "+ return cnt", "+", "+", "+cnt = linear_banpei_search()" ]
false
0.041664
0.044986
0.926146
[ "s851469458", "s363355733" ]
u533039576
p03108
python
s873845826
s440461680
1,038
847
46,344
33,424
Accepted
Accepted
18.4
import sys sys.setrecursionlimit(100000) class UnionFind(): def __init__(self, n): self.par = [i for i in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] != x: self.par[x] = self.find(self.par[x]) # contraction return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if not self.same(x, y): self.size[y] += self.size[x] self.par[x] = y def same(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) edge = [list([int(x) - 1 for x in input().split()]) for _ in range(m)] uf = UnionFind(n) ans = n * (n-1) // 2 anss = [] for i in reversed(list(range(m))): anss.append(ans) # print(uf.par) # print(uf.size, [uf.size[uf.find(i)] for i in range(n)]) a, b = edge[i] if not uf.same(a, b): ans -= uf.size[uf.find(a)] * uf.size[uf.find(b)] # print(i, a, b) uf.unite(a, b) for i in reversed(list(range(m))): print((anss[i]))
class UnionFind(): def __init__(self, n): self.par = [-1 for i in range(n)] def root(self, x): if self.par[x] < 0: return x else: self.par[x] = self.root(self.par[x]) # contraction return self.par[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return - self.par[self.root(x)] n, m = list(map(int, input().split())) edge = [list([int(x) - 1 for x in input().split()]) for _ in range(m)] uf = UnionFind(n) ans = n * (n-1) // 2 anss = [] for i in reversed(list(range(m))): anss.append(ans) # print(uf.par) # print(uf.size, [uf.size[uf.find(i)] for i in range(n)]) a, b = edge[i] if not uf.same(a, b): ans -= uf.size(a) * uf.size(b) # print(i, a, b) uf.unite(a, b) for i in reversed(list(range(m))): print((anss[i]))
44
48
1,089
1,181
import sys sys.setrecursionlimit(100000) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] != x: self.par[x] = self.find(self.par[x]) # contraction return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if not self.same(x, y): self.size[y] += self.size[x] self.par[x] = y def same(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) edge = [list([int(x) - 1 for x in input().split()]) for _ in range(m)] uf = UnionFind(n) ans = n * (n - 1) // 2 anss = [] for i in reversed(list(range(m))): anss.append(ans) # print(uf.par) # print(uf.size, [uf.size[uf.find(i)] for i in range(n)]) a, b = edge[i] if not uf.same(a, b): ans -= uf.size[uf.find(a)] * uf.size[uf.find(b)] # print(i, a, b) uf.unite(a, b) for i in reversed(list(range(m))): print((anss[i]))
class UnionFind: def __init__(self, n): self.par = [-1 for i in range(n)] def root(self, x): if self.par[x] < 0: return x else: self.par[x] = self.root(self.par[x]) # contraction return self.par[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.par[self.root(x)] n, m = list(map(int, input().split())) edge = [list([int(x) - 1 for x in input().split()]) for _ in range(m)] uf = UnionFind(n) ans = n * (n - 1) // 2 anss = [] for i in reversed(list(range(m))): anss.append(ans) # print(uf.par) # print(uf.size, [uf.size[uf.find(i)] for i in range(n)]) a, b = edge[i] if not uf.same(a, b): ans -= uf.size(a) * uf.size(b) # print(i, a, b) uf.unite(a, b) for i in reversed(list(range(m))): print((anss[i]))
false
8.333333
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "-", "-", "- self.par = [i for i in range(n)]", "- self.size = [1 for _ in range(n)]", "+ self.par = [-1 for i in range(n)]", "- def find(self, x):", "- if self.par[x] != x:", "- self.par[x] = self.find(self.par[x]) # contraction", "- return self.par[x]", "+ def root(self, x):", "+ if self.par[x] < 0:", "+ return x", "+ else:", "+ self.par[x] = self.root(self.par[x]) # contraction", "+ return self.par[x]", "- x = self.find(x)", "- y = self.find(y)", "- if not self.same(x, y):", "- self.size[y] += self.size[x]", "- self.par[x] = y", "+ x = self.root(x)", "+ y = self.root(y)", "+ if x == y:", "+ return False", "+ if self.par[x] > self.par[y]:", "+ x, y = y, x", "+ self.par[x] += self.par[y]", "+ self.par[y] = x", "+ return True", "- return self.find(x) == self.find(y)", "+ return self.root(x) == self.root(y)", "+", "+ def size(self, x):", "+ return -self.par[self.root(x)]", "- ans -= uf.size[uf.find(a)] * uf.size[uf.find(b)]", "+ ans -= uf.size(a) * uf.size(b)" ]
false
0.03976
0.045444
0.874915
[ "s873845826", "s440461680" ]
u826263061
p03160
python
s206853975
s933254252
138
124
13,928
14,696
Accepted
Accepted
10.14
n = int(eval(input())) a = list(map(int, input().split())) dp = [10**9+1]*n dp[0] = 0 dp[1] = dp[0] + abs(a[1]-a[0]) for i in range(2, n): dp[i] = min([dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])]) print((dp[n-1]))
n = int(eval(input())) dp = [0]*(n+1) a = list(map(int, input().split())) dp[1] = abs(a[1]-a[0]) for i in range(2,n): dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1])) print((dp[n-1]))
11
8
230
203
n = int(eval(input())) a = list(map(int, input().split())) dp = [10**9 + 1] * n dp[0] = 0 dp[1] = dp[0] + abs(a[1] - a[0]) for i in range(2, n): dp[i] = min([dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2])]) print((dp[n - 1]))
n = int(eval(input())) dp = [0] * (n + 1) a = list(map(int, input().split())) dp[1] = abs(a[1] - a[0]) for i in range(2, n): dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1])) print((dp[n - 1]))
false
27.272727
[ "+dp = [0] * (n + 1)", "-dp = [10**9 + 1] * n", "-dp[0] = 0", "-dp[1] = dp[0] + abs(a[1] - a[0])", "+dp[1] = abs(a[1] - a[0])", "- dp[i] = min([dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2])])", "+ dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]))" ]
false
0.094306
0.077664
1.214282
[ "s206853975", "s933254252" ]
u982591663
p02899
python
s250030381
s807878208
225
182
25,504
25,916
Accepted
Accepted
19.11
#ABC-142-C N = int(input()) A = list(map(int, input().split())) ans_dict = {} for idx, item in enumerate(A): ans_dict[item] = idx+1 sorted_dict = sorted(ans_dict.items(), key = lambda x:x[0]) for i in sorted_dict: print(i[1], end = " ")
N = int(eval(input())) A = list(map(int, input().split())) memo = {} for i in range(1, N+1): memo[i] = A[i-1] memo = sorted(list(memo.items()), key=lambda x:x[1]) # print(memo) ans = [] for student, order in memo: ans.append(str(student)) print((" ".join(ans)))
12
15
262
274
# ABC-142-C N = int(input()) A = list(map(int, input().split())) ans_dict = {} for idx, item in enumerate(A): ans_dict[item] = idx + 1 sorted_dict = sorted(ans_dict.items(), key=lambda x: x[0]) for i in sorted_dict: print(i[1], end=" ")
N = int(eval(input())) A = list(map(int, input().split())) memo = {} for i in range(1, N + 1): memo[i] = A[i - 1] memo = sorted(list(memo.items()), key=lambda x: x[1]) # print(memo) ans = [] for student, order in memo: ans.append(str(student)) print((" ".join(ans)))
false
20
[ "-# ABC-142-C", "-N = int(input())", "+N = int(eval(input()))", "-ans_dict = {}", "-for idx, item in enumerate(A):", "- ans_dict[item] = idx + 1", "-sorted_dict = sorted(ans_dict.items(), key=lambda x: x[0])", "-for i in sorted_dict:", "- print(i[1], end=\" \")", "+memo = {}", "+for i in range(1, N + 1):", "+ memo[i] = A[i - 1]", "+memo = sorted(list(memo.items()), key=lambda x: x[1])", "+# print(memo)", "+ans = []", "+for student, order in memo:", "+ ans.append(str(student))", "+print((\" \".join(ans)))" ]
false
0.036943
0.068857
0.53651
[ "s250030381", "s807878208" ]
u844646164
p03457
python
s610827441
s751611496
370
242
27,300
85,404
Accepted
Accepted
34.59
N = int(eval(input())) L = [list(map(int, input().split())) for _ in range(N)] switch = 0 for li in L: t = li[0] co = li[1]+li[2] if t >= co: if co % 2 == 0 and t % 2 == 0: pass elif co % 2 != 0 and t % 2 != 0: pass else: switch += 1 break else: switch += 1 break if switch == 0: print('Yes') else: print('No')
N = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(N)] now_x, now_y = 0, 0 pre_t = 0 for t, x, y in txy: walk = abs(now_x - x) + abs(now_y - y) if t - pre_t < walk: print('No') exit() if (t-pre_t) % 2 != walk % 2: print('No') exit() now_x = x now_y = y pre_t = t print('Yes')
21
19
437
372
N = int(eval(input())) L = [list(map(int, input().split())) for _ in range(N)] switch = 0 for li in L: t = li[0] co = li[1] + li[2] if t >= co: if co % 2 == 0 and t % 2 == 0: pass elif co % 2 != 0 and t % 2 != 0: pass else: switch += 1 break else: switch += 1 break if switch == 0: print("Yes") else: print("No")
N = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(N)] now_x, now_y = 0, 0 pre_t = 0 for t, x, y in txy: walk = abs(now_x - x) + abs(now_y - y) if t - pre_t < walk: print("No") exit() if (t - pre_t) % 2 != walk % 2: print("No") exit() now_x = x now_y = y pre_t = t print("Yes")
false
9.52381
[ "-L = [list(map(int, input().split())) for _ in range(N)]", "-switch = 0", "-for li in L:", "- t = li[0]", "- co = li[1] + li[2]", "- if t >= co:", "- if co % 2 == 0 and t % 2 == 0:", "- pass", "- elif co % 2 != 0 and t % 2 != 0:", "- pass", "- else:", "- switch += 1", "- break", "- else:", "- switch += 1", "- break", "-if switch == 0:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+txy = [list(map(int, input().split())) for _ in range(N)]", "+now_x, now_y = 0, 0", "+pre_t = 0", "+for t, x, y in txy:", "+ walk = abs(now_x - x) + abs(now_y - y)", "+ if t - pre_t < walk:", "+ print(\"No\")", "+ exit()", "+ if (t - pre_t) % 2 != walk % 2:", "+ print(\"No\")", "+ exit()", "+ now_x = x", "+ now_y = y", "+ pre_t = t", "+print(\"Yes\")" ]
false
0.045529
0.036629
1.242954
[ "s610827441", "s751611496" ]
u729133443
p03998
python
s530334593
s068264626
183
18
38,256
2,940
Accepted
Accepted
90.16
s=[list(eval(input()))for _ in[0]*3];i=0 while s[i]:i='abc'.index(s[i].pop(0)) print(('ABC'[i]))
d={i:list(eval(input()))for i in'abc'};i='a' while d[i]:i=d[i].pop(0) print((i.upper()))
3
3
90
82
s = [list(eval(input())) for _ in [0] * 3] i = 0 while s[i]: i = "abc".index(s[i].pop(0)) print(("ABC"[i]))
d = {i: list(eval(input())) for i in "abc"} i = "a" while d[i]: i = d[i].pop(0) print((i.upper()))
false
0
[ "-s = [list(eval(input())) for _ in [0] * 3]", "-i = 0", "-while s[i]:", "- i = \"abc\".index(s[i].pop(0))", "-print((\"ABC\"[i]))", "+d = {i: list(eval(input())) for i in \"abc\"}", "+i = \"a\"", "+while d[i]:", "+ i = d[i].pop(0)", "+print((i.upper()))" ]
false
0.03973
0.039409
1.00816
[ "s530334593", "s068264626" ]
u906501980
p02762
python
s461553892
s560356237
1,157
1,057
74,776
41,320
Accepted
Accepted
8.64
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [set() for _ in range(n+1)] blocks = [set() for _ in range(n+1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a] |= {b} friends[b] |= {a} uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c] |= {d} blocks[d] |= {c} for i in range(1, n+1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [[] for _ in range(n+1)] blocks = [[] for _ in range(n+1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a].append(b) friends[b].append(a) uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n+1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
57
57
1,460
1,466
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [set() for _ in range(n + 1)] blocks = [set() for _ in range(n + 1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a] |= {b} friends[b] |= {a} uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c] |= {d} blocks[d] |= {c} for i in range(1, n + 1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [[] for _ in range(n + 1)] blocks = [[] for _ in range(n + 1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a].append(b) friends[b].append(a) uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n + 1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
false
0
[ "- friends = [set() for _ in range(n + 1)]", "- blocks = [set() for _ in range(n + 1)]", "+ friends = [[] for _ in range(n + 1)]", "+ blocks = [[] for _ in range(n + 1)]", "- friends[a] |= {b}", "- friends[b] |= {a}", "+ friends[a].append(b)", "+ friends[b].append(a)", "- blocks[c] |= {d}", "- blocks[d] |= {c}", "+ blocks[c].append(d)", "+ blocks[d].append(c)" ]
false
0.042236
0.042389
0.996386
[ "s461553892", "s560356237" ]
u947883560
p03061
python
s972400923
s284746193
923
178
16,432
17,968
Accepted
Accepted
80.72
#!/usr/bin/env python3 import sys import math from collections import Counter import collections INF = float("inf") def factorial(n): # 試し割りによる素因数分解 prime_count = collections.Counter() for i in range(2, int(math.sqrt(n)) + 2): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 return prime_count def GCD(a, b): if a == 0: return b else: return GCD(b % a, a) def GCDs(*a): # リストで入力しないよう注意。 if len(a) == 0: return -1 # エラー if len(a) == 1: return a[0] res = a[0] for i in range(1, len(a)): res = GCD(res, a[i]) return res def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors def solve(N: int, A: "List[int]"): c1 = make_divisors(A[0]) c2 = make_divisors(A[1]) c = sorted(list(set(c1 + c2))) OKs = [] for cv in c: if sum([1 if a % cv == 0 else 0 for a in A]) >= N-1: OKs.append(cv) print((max(OKs))) # b = A[0] # m = INF # mi = -1 # for i in range(N): # g = GCD(A[i], b) # print(g) # if m > g: # m = g # mi = i # buf = None # for i in range(N): # if mi == i: # continue # if buf is None: # buf = A[i] # else: # buf = GCD(buf, A[i]) # print([buf, GCDs(*A[1:])]) # print("回答: ", max([buf, GCDs(*A[1:])])) # # print(g) # s = SegmentTree(N) # for i in range(N): # s.update(i, A[i]) # # print("tree ", s.tree) # g = [] # for i in range(N): # # iを覗いたGCDをとる # if i == 0: # g.append(s.query(1, N)) # elif i == N-1: # g.append(s.query(0, N-1)) # else: # # print(s.query(0, i), s.query(i+1, N)) # g.append(GCD(s.query(0, i), s.query(i+1, N))) # # print(g) # # print("回答2: ", max(g)) # print(max(g)) # g = [] # for i in range(N): # buf = None # for j in range(N): # if i == j: # continue # if buf is None: # buf = A[j] # else: # buf = GCD(buf, A[j]) # g.append(buf) # # print(g) # print("正解:", max(g)) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys import math from collections import Counter import collections INF = float("inf") def factorial(n): # 試し割りによる素因数分解 prime_count = collections.Counter() for i in range(2, int(math.sqrt(n)) + 2): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 return prime_count def GCD(a, b): if a == 0: return b else: return GCD(b % a, a) def GCDs(*a): # リストで入力しないよう注意。 if len(a) == 0: return -1 # エラー if len(a) == 1: return a[0] res = a[0] for i in range(1, len(a)): res = GCD(res, a[i]) return res def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors def solve(N: int, A: "List[int]"): asc = [0] for i in range(N): asc.append(GCD(asc[-1], A[i])) desc = [0] for i in range(N): desc.append(GCD(desc[-1], A[N-i-1])) buf = [] for i in range(N): buf.append(GCD(asc[i], desc[N-i-1])) print((max(buf))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
136
86
2,962
1,660
#!/usr/bin/env python3 import sys import math from collections import Counter import collections INF = float("inf") def factorial(n): # 試し割りによる素因数分解 prime_count = collections.Counter() for i in range(2, int(math.sqrt(n)) + 2): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 return prime_count def GCD(a, b): if a == 0: return b else: return GCD(b % a, a) def GCDs(*a): # リストで入力しないよう注意。 if len(a) == 0: return -1 # エラー if len(a) == 1: return a[0] res = a[0] for i in range(1, len(a)): res = GCD(res, a[i]) return res def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort() return divisors def solve(N: int, A: "List[int]"): c1 = make_divisors(A[0]) c2 = make_divisors(A[1]) c = sorted(list(set(c1 + c2))) OKs = [] for cv in c: if sum([1 if a % cv == 0 else 0 for a in A]) >= N - 1: OKs.append(cv) print((max(OKs))) # b = A[0] # m = INF # mi = -1 # for i in range(N): # g = GCD(A[i], b) # print(g) # if m > g: # m = g # mi = i # buf = None # for i in range(N): # if mi == i: # continue # if buf is None: # buf = A[i] # else: # buf = GCD(buf, A[i]) # print([buf, GCDs(*A[1:])]) # print("回答: ", max([buf, GCDs(*A[1:])])) # # print(g) # s = SegmentTree(N) # for i in range(N): # s.update(i, A[i]) # # print("tree ", s.tree) # g = [] # for i in range(N): # # iを覗いたGCDをとる # if i == 0: # g.append(s.query(1, N)) # elif i == N-1: # g.append(s.query(0, N-1)) # else: # # print(s.query(0, i), s.query(i+1, N)) # g.append(GCD(s.query(0, i), s.query(i+1, N))) # # print(g) # # print("回答2: ", max(g)) # print(max(g)) # g = [] # for i in range(N): # buf = None # for j in range(N): # if i == j: # continue # if buf is None: # buf = A[j] # else: # buf = GCD(buf, A[j]) # g.append(buf) # # print(g) # print("正解:", max(g)) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys import math from collections import Counter import collections INF = float("inf") def factorial(n): # 試し割りによる素因数分解 prime_count = collections.Counter() for i in range(2, int(math.sqrt(n)) + 2): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 return prime_count def GCD(a, b): if a == 0: return b else: return GCD(b % a, a) def GCDs(*a): # リストで入力しないよう注意。 if len(a) == 0: return -1 # エラー if len(a) == 1: return a[0] res = a[0] for i in range(1, len(a)): res = GCD(res, a[i]) return res def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort() return divisors def solve(N: int, A: "List[int]"): asc = [0] for i in range(N): asc.append(GCD(asc[-1], A[i])) desc = [0] for i in range(N): desc.append(GCD(desc[-1], A[N - i - 1])) buf = [] for i in range(N): buf.append(GCD(asc[i], desc[N - i - 1])) print((max(buf))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == "__main__": main()
false
36.764706
[ "- c1 = make_divisors(A[0])", "- c2 = make_divisors(A[1])", "- c = sorted(list(set(c1 + c2)))", "- OKs = []", "- for cv in c:", "- if sum([1 if a % cv == 0 else 0 for a in A]) >= N - 1:", "- OKs.append(cv)", "- print((max(OKs)))", "- # b = A[0]", "- # m = INF", "- # mi = -1", "- # for i in range(N):", "- # g = GCD(A[i], b)", "- # print(g)", "- # if m > g:", "- # m = g", "- # mi = i", "- # buf = None", "- # for i in range(N):", "- # if mi == i:", "- # continue", "- # if buf is None:", "- # buf = A[i]", "- # else:", "- # buf = GCD(buf, A[i])", "- # print([buf, GCDs(*A[1:])])", "- # print(\"回答: \", max([buf, GCDs(*A[1:])]))", "- # # print(g)", "- # s = SegmentTree(N)", "- # for i in range(N):", "- # s.update(i, A[i])", "- # # print(\"tree \", s.tree)", "- # g = []", "- # for i in range(N):", "- # # iを覗いたGCDをとる", "- # if i == 0:", "- # g.append(s.query(1, N))", "- # elif i == N-1:", "- # g.append(s.query(0, N-1))", "- # else:", "- # # print(s.query(0, i), s.query(i+1, N))", "- # g.append(GCD(s.query(0, i), s.query(i+1, N)))", "- # # print(g)", "- # # print(\"回答2: \", max(g))", "- # print(max(g))", "- # g = []", "- # for i in range(N):", "- # buf = None", "- # for j in range(N):", "- # if i == j:", "- # continue", "- # if buf is None:", "- # buf = A[j]", "- # else:", "- # buf = GCD(buf, A[j])", "- # g.append(buf)", "- # # print(g)", "- # print(\"正解:\", max(g))", "+ asc = [0]", "+ for i in range(N):", "+ asc.append(GCD(asc[-1], A[i]))", "+ desc = [0]", "+ for i in range(N):", "+ desc.append(GCD(desc[-1], A[N - i - 1]))", "+ buf = []", "+ for i in range(N):", "+ buf.append(GCD(asc[i], desc[N - i - 1]))", "+ print((max(buf)))" ]
false
0.050664
0.039618
1.27882
[ "s972400923", "s284746193" ]
u730769327
p03325
python
s041535106
s334437012
196
72
41,708
70,816
Accepted
Accepted
63.27
n=int(eval(input())) x=list(map(int,input().split())) cnt=0 for i in x: j=1 while(1): if i%2: break elif i: cnt+=1 i//=2 else: break j+=1 print(cnt)
n=int(eval(input())) a=list(map(int,input().split())) ans=0 for i in a: while i%2==0: i//=2 ans+=1 print(ans)
16
8
197
120
n = int(eval(input())) x = list(map(int, input().split())) cnt = 0 for i in x: j = 1 while 1: if i % 2: break elif i: cnt += 1 i //= 2 else: break j += 1 print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: while i % 2 == 0: i //= 2 ans += 1 print(ans)
false
50
[ "-x = list(map(int, input().split()))", "-cnt = 0", "-for i in x:", "- j = 1", "- while 1:", "- if i % 2:", "- break", "- elif i:", "- cnt += 1", "- i //= 2", "- else:", "- break", "- j += 1", "-print(cnt)", "+a = list(map(int, input().split()))", "+ans = 0", "+for i in a:", "+ while i % 2 == 0:", "+ i //= 2", "+ ans += 1", "+print(ans)" ]
false
0.04497
0.037164
1.210067
[ "s041535106", "s334437012" ]
u228223940
p02633
python
s960270367
s169537314
31
25
9,144
8,936
Accepted
Accepted
19.35
import math #print(math.cos(math.radians(90))) #exit() x = int(eval(input())) print((360//math.gcd(360,x)))
x = int(eval(input())) for i in range(1000): if x * (i+1) % 360 == 0: print((i+1)) exit()
5
5
103
106
import math # print(math.cos(math.radians(90))) # exit() x = int(eval(input())) print((360 // math.gcd(360, x)))
x = int(eval(input())) for i in range(1000): if x * (i + 1) % 360 == 0: print((i + 1)) exit()
false
0
[ "-import math", "-", "-# print(math.cos(math.radians(90)))", "-# exit()", "-print((360 // math.gcd(360, x)))", "+for i in range(1000):", "+ if x * (i + 1) % 360 == 0:", "+ print((i + 1))", "+ exit()" ]
false
0.105618
0.083622
1.263033
[ "s960270367", "s169537314" ]
u391819434
p03862
python
s103755298
s541934371
254
123
63,856
14,060
Accepted
Accepted
51.57
N,X=list(map(int,input().split())) *A,=list(map(int,input().split())) ans=0 if A[0]>X: ans+=A[0]-X A[0]=X i=0 while i+1<=N-1: if A[i]+A[i+1]>X: ans+=A[i]+A[i+1]-X A[i+1]=X-A[i] i+=1 print(ans)
N,X=list(map(int,input().split())) *A,=list(map(int,input().split())) ans=0 if A[0]>X: ans+=A[0]-X A[0]=X i=1 while i<N: if A[i]+A[i-1]>X: ans+=A[i]+A[i-1]-X A[i]=X-A[i-1] i+=1 print(ans)
17
16
233
233
N, X = list(map(int, input().split())) (*A,) = list(map(int, input().split())) ans = 0 if A[0] > X: ans += A[0] - X A[0] = X i = 0 while i + 1 <= N - 1: if A[i] + A[i + 1] > X: ans += A[i] + A[i + 1] - X A[i + 1] = X - A[i] i += 1 print(ans)
N, X = list(map(int, input().split())) (*A,) = list(map(int, input().split())) ans = 0 if A[0] > X: ans += A[0] - X A[0] = X i = 1 while i < N: if A[i] + A[i - 1] > X: ans += A[i] + A[i - 1] - X A[i] = X - A[i - 1] i += 1 print(ans)
false
5.882353
[ "-i = 0", "-while i + 1 <= N - 1:", "- if A[i] + A[i + 1] > X:", "- ans += A[i] + A[i + 1] - X", "- A[i + 1] = X - A[i]", "+i = 1", "+while i < N:", "+ if A[i] + A[i - 1] > X:", "+ ans += A[i] + A[i - 1] - X", "+ A[i] = X - A[i - 1]" ]
false
0.084866
0.042814
1.982197
[ "s103755298", "s541934371" ]
u796942881
p03846
python
s751945501
s633589085
103
90
14,436
13,940
Accepted
Accepted
12.62
from functools import reduce INF = int(1e9+7) def main(): N, *An = list(map(int, open(0).read().split())) An.sort() if N % 2: if [0] + [i for i in range(2, N, 2) for j in range(2)] == An: print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1))) return else: if [i for i in range(1, N, 2) for j in range(2)] == An: print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1))) return print((0)) return main()
INF = int(1e9+7) def main(): N, *An = list(map(int, open(0).read().split())) An.sort() if N % 2: if [0] + [i for i in range(2, N, 2) for j in range(2)] == An: print((2 ** (N // 2) % INF)) return else: if [i for i in range(1, N, 2) for j in range(2)] == An: print((2 ** (N // 2) % INF)) return print((0)) return main()
20
19
514
416
from functools import reduce INF = int(1e9 + 7) def main(): N, *An = list(map(int, open(0).read().split())) An.sort() if N % 2: if [0] + [i for i in range(2, N, 2) for j in range(2)] == An: print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1))) return else: if [i for i in range(1, N, 2) for j in range(2)] == An: print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1))) return print((0)) return main()
INF = int(1e9 + 7) def main(): N, *An = list(map(int, open(0).read().split())) An.sort() if N % 2: if [0] + [i for i in range(2, N, 2) for j in range(2)] == An: print((2 ** (N // 2) % INF)) return else: if [i for i in range(1, N, 2) for j in range(2)] == An: print((2 ** (N // 2) % INF)) return print((0)) return main()
false
5
[ "-from functools import reduce", "-", "- print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1)))", "+ print((2 ** (N // 2) % INF))", "- print((reduce(lambda x, y: (x << 1) % INF, list(range(N // 2)), 1)))", "+ print((2 ** (N // 2) % INF))" ]
false
0.064682
0.037406
1.729215
[ "s751945501", "s633589085" ]
u871980676
p02954
python
s162844017
s958885274
205
124
17,724
17,476
Accepted
Accepted
39.51
s = eval(input()) N = len(s) ls = [0] + [i for i in range(1,N) if (s[i-1]=='L' and s[i] == 'R')] ls.append(N) #print(ls) ls2 = [(ls[i],ls[i+1]) for i in range(len(ls)-1)] #print(ls2) ls3 = [i for i in range(1,N) if (s[i-1]=='R' and s[i] == 'L')] #print(ls3) res = ['0']*N for i,tp in enumerate(ls2): for j in range(tp[0],tp[1]): res[ls3[i]] = str((tp[1]-ls3[i]-1)//2+(ls3[i]-tp[0])//2+1) res[ls3[i]-1] = str((tp[1]-ls3[i])//2+(ls3[i]-tp[0]-1)//2+1) print((' '.join(res)))
s = eval(input()) N = len(s) ls = [0] + [i for i in range(1,N) if (s[i-1]=='L' and s[i] == 'R')] ls.append(N) ls2 = [(ls[i],ls[i+1]) for i in range(len(ls)-1)] ls3 = [i for i in range(1,N) if (s[i-1]=='R' and s[i] == 'L')] res = ['0']*N for i,tp in enumerate(ls2): res[ls3[i]] = str((tp[1]-ls3[i]-1)//2+(ls3[i]-tp[0])//2+1) res[ls3[i]-1] = str((tp[1]-ls3[i])//2+(ls3[i]-tp[0]-1)//2+1) print((' '.join(res)))
15
11
498
418
s = eval(input()) N = len(s) ls = [0] + [i for i in range(1, N) if (s[i - 1] == "L" and s[i] == "R")] ls.append(N) # print(ls) ls2 = [(ls[i], ls[i + 1]) for i in range(len(ls) - 1)] # print(ls2) ls3 = [i for i in range(1, N) if (s[i - 1] == "R" and s[i] == "L")] # print(ls3) res = ["0"] * N for i, tp in enumerate(ls2): for j in range(tp[0], tp[1]): res[ls3[i]] = str((tp[1] - ls3[i] - 1) // 2 + (ls3[i] - tp[0]) // 2 + 1) res[ls3[i] - 1] = str((tp[1] - ls3[i]) // 2 + (ls3[i] - tp[0] - 1) // 2 + 1) print((" ".join(res)))
s = eval(input()) N = len(s) ls = [0] + [i for i in range(1, N) if (s[i - 1] == "L" and s[i] == "R")] ls.append(N) ls2 = [(ls[i], ls[i + 1]) for i in range(len(ls) - 1)] ls3 = [i for i in range(1, N) if (s[i - 1] == "R" and s[i] == "L")] res = ["0"] * N for i, tp in enumerate(ls2): res[ls3[i]] = str((tp[1] - ls3[i] - 1) // 2 + (ls3[i] - tp[0]) // 2 + 1) res[ls3[i] - 1] = str((tp[1] - ls3[i]) // 2 + (ls3[i] - tp[0] - 1) // 2 + 1) print((" ".join(res)))
false
26.666667
[ "-# print(ls)", "-# print(ls2)", "-# print(ls3)", "- for j in range(tp[0], tp[1]):", "- res[ls3[i]] = str((tp[1] - ls3[i] - 1) // 2 + (ls3[i] - tp[0]) // 2 + 1)", "- res[ls3[i] - 1] = str((tp[1] - ls3[i]) // 2 + (ls3[i] - tp[0] - 1) // 2 + 1)", "+ res[ls3[i]] = str((tp[1] - ls3[i] - 1) // 2 + (ls3[i] - tp[0]) // 2 + 1)", "+ res[ls3[i] - 1] = str((tp[1] - ls3[i]) // 2 + (ls3[i] - tp[0] - 1) // 2 + 1)" ]
false
0.049987
0.042083
1.18782
[ "s162844017", "s958885274" ]
u624475441
p03164
python
s332844038
s181563074
348
182
21,740
14,904
Accepted
Accepted
47.7
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64) dp[0] = 0 for w, v in zip(it, it): np.minimum(dp[:-v] + w, dp[v:], out=dp[v:]) print((((dp <= W) * np.arange(N * 1000 + 1)).max()))
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.full(N * 1000 + 1, W + 1, dtype=np.int64) dp[0] = 0 for w, v in zip(it, it): np.minimum(dp[:-v] + w, dp[v:], out=dp[v:]) print((((dp <= W) * np.arange(N * 1000 + 1)).max()))
9
9
303
300
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.full(N * 1000 + 1, 10**10, dtype=np.int64) dp[0] = 0 for w, v in zip(it, it): np.minimum(dp[:-v] + w, dp[v:], out=dp[v:]) print((((dp <= W) * np.arange(N * 1000 + 1)).max()))
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.full(N * 1000 + 1, W + 1, dtype=np.int64) dp[0] = 0 for w, v in zip(it, it): np.minimum(dp[:-v] + w, dp[v:], out=dp[v:]) print((((dp <= W) * np.arange(N * 1000 + 1)).max()))
false
0
[ "-dp = np.full(N * 1000 + 1, 10**10, dtype=np.int64)", "+dp = np.full(N * 1000 + 1, W + 1, dtype=np.int64)" ]
false
0.359033
0.4412
0.813765
[ "s332844038", "s181563074" ]
u343675824
p03847
python
s026193837
s507045288
168
20
38,512
3,316
Accepted
Accepted
88.1
N = int(eval(input())) dp = [[0] * 3 for i in range(100)] MOD = int(1e9+7) maxBit = 70 while not (N >> maxBit): maxBit -= 1 dp[maxBit][0] = 1 dp[maxBit][1] = 1 for i in range(maxBit-1, -1, -1): for j in range(3): bit = (N >> i) & 1 for k in range(3): nj = 2 * j + bit - k if nj < 0: continue nj = min((nj, 2)) dp[i][nj] += dp[i+1][j] dp[i][nj] %= MOD print((sum(dp[0]) % MOD))
N = int(eval(input())) s = bin(N)[2:] n = len(s) dp = [[0] * 4 for i in range(len(s)+1)] dp[0][0] = 1 MOD = int(1e9) + 7 for i in range(n): b = 1 if s[i] == '1' else 0 for j in range(4): for k in range(3): nj = min(((j << 1) + b - k, 3)) if 0 <= nj: dp[i+1][nj] += dp[i][j] dp[i+1][nj] %= MOD print((sum(dp[n]) % MOD))
22
15
493
397
N = int(eval(input())) dp = [[0] * 3 for i in range(100)] MOD = int(1e9 + 7) maxBit = 70 while not (N >> maxBit): maxBit -= 1 dp[maxBit][0] = 1 dp[maxBit][1] = 1 for i in range(maxBit - 1, -1, -1): for j in range(3): bit = (N >> i) & 1 for k in range(3): nj = 2 * j + bit - k if nj < 0: continue nj = min((nj, 2)) dp[i][nj] += dp[i + 1][j] dp[i][nj] %= MOD print((sum(dp[0]) % MOD))
N = int(eval(input())) s = bin(N)[2:] n = len(s) dp = [[0] * 4 for i in range(len(s) + 1)] dp[0][0] = 1 MOD = int(1e9) + 7 for i in range(n): b = 1 if s[i] == "1" else 0 for j in range(4): for k in range(3): nj = min(((j << 1) + b - k, 3)) if 0 <= nj: dp[i + 1][nj] += dp[i][j] dp[i + 1][nj] %= MOD print((sum(dp[n]) % MOD))
false
31.818182
[ "-dp = [[0] * 3 for i in range(100)]", "-MOD = int(1e9 + 7)", "-maxBit = 70", "-while not (N >> maxBit):", "- maxBit -= 1", "-dp[maxBit][0] = 1", "-dp[maxBit][1] = 1", "-for i in range(maxBit - 1, -1, -1):", "- for j in range(3):", "- bit = (N >> i) & 1", "+s = bin(N)[2:]", "+n = len(s)", "+dp = [[0] * 4 for i in range(len(s) + 1)]", "+dp[0][0] = 1", "+MOD = int(1e9) + 7", "+for i in range(n):", "+ b = 1 if s[i] == \"1\" else 0", "+ for j in range(4):", "- nj = 2 * j + bit - k", "- if nj < 0:", "- continue", "- nj = min((nj, 2))", "- dp[i][nj] += dp[i + 1][j]", "- dp[i][nj] %= MOD", "-print((sum(dp[0]) % MOD))", "+ nj = min(((j << 1) + b - k, 3))", "+ if 0 <= nj:", "+ dp[i + 1][nj] += dp[i][j]", "+ dp[i + 1][nj] %= MOD", "+print((sum(dp[n]) % MOD))" ]
false
0.061283
0.038143
1.60668
[ "s026193837", "s507045288" ]
u254871849
p03557
python
s730023694
s224743338
362
325
36,340
22,720
Accepted
Accepted
10.22
import sys # import collections # import math # import string import bisect def main(): n, *parts = (int(x) for x in sys.stdin.read().split()) uppers, middles, lowers = (parts[n*i:n*(i+1)] for i in range(3)) uppers.sort() lowers.sort() count = 0 for j in middles: i = bisect.bisect_left(uppers, j) k = len(lowers) - bisect.bisect_right(lowers, j) count += i * k print(count) if __name__ == "__main__": main()
import sys from bisect import bisect_left as bi_l, bisect_right as bi_r n = int(sys.stdin.readline().rstrip()) *a, = list(map(int, sys.stdin.readline().split())) *b, = list(map(int, sys.stdin.readline().split())) *c, = list(map(int, sys.stdin.readline().split())) def main(): a.sort() b.sort() c.sort() res = 0 for i in b: cnt_a = bi_l(a, i) cnt_c = n - bi_r(c, i) res += cnt_a * cnt_c return res if __name__ == '__main__': ans = main() print(ans)
23
23
500
516
import sys # import collections # import math # import string import bisect def main(): n, *parts = (int(x) for x in sys.stdin.read().split()) uppers, middles, lowers = (parts[n * i : n * (i + 1)] for i in range(3)) uppers.sort() lowers.sort() count = 0 for j in middles: i = bisect.bisect_left(uppers, j) k = len(lowers) - bisect.bisect_right(lowers, j) count += i * k print(count) if __name__ == "__main__": main()
import sys from bisect import bisect_left as bi_l, bisect_right as bi_r n = int(sys.stdin.readline().rstrip()) (*a,) = list(map(int, sys.stdin.readline().split())) (*b,) = list(map(int, sys.stdin.readline().split())) (*c,) = list(map(int, sys.stdin.readline().split())) def main(): a.sort() b.sort() c.sort() res = 0 for i in b: cnt_a = bi_l(a, i) cnt_c = n - bi_r(c, i) res += cnt_a * cnt_c return res if __name__ == "__main__": ans = main() print(ans)
false
0
[ "+from bisect import bisect_left as bi_l, bisect_right as bi_r", "-# import collections", "-# import math", "-# import string", "-import bisect", "+n = int(sys.stdin.readline().rstrip())", "+(*a,) = list(map(int, sys.stdin.readline().split()))", "+(*b,) = list(map(int, sys.stdin.readline().split()))", "+(*c,) = list(map(int, sys.stdin.readline().split()))", "- n, *parts = (int(x) for x in sys.stdin.read().split())", "- uppers, middles, lowers = (parts[n * i : n * (i + 1)] for i in range(3))", "- uppers.sort()", "- lowers.sort()", "- count = 0", "- for j in middles:", "- i = bisect.bisect_left(uppers, j)", "- k = len(lowers) - bisect.bisect_right(lowers, j)", "- count += i * k", "- print(count)", "+ a.sort()", "+ b.sort()", "+ c.sort()", "+ res = 0", "+ for i in b:", "+ cnt_a = bi_l(a, i)", "+ cnt_c = n - bi_r(c, i)", "+ res += cnt_a * cnt_c", "+ return res", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.126904
0.049606
2.55822
[ "s730023694", "s224743338" ]
u998741086
p02659
python
s640101772
s587732972
22
20
9,168
9,032
Accepted
Accepted
9.09
#!/usr/bin/env python3 import math a, b = input().split() a = int(a) b = int(b.replace('.', '')) print((a*b//100))
#!/usr/bin/env python3 a, b = input().split() a = int(a) b = int(float(b)*100+0.5) print((a*b//100))
7
6
120
105
#!/usr/bin/env python3 import math a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
#!/usr/bin/env python3 a, b = input().split() a = int(a) b = int(float(b) * 100 + 0.5) print((a * b // 100))
false
14.285714
[ "-import math", "-", "-b = int(b.replace(\".\", \"\"))", "+b = int(float(b) * 100 + 0.5)" ]
false
0.042069
0.047323
0.888975
[ "s640101772", "s587732972" ]
u644907318
p02796
python
s220437154
s525959894
793
537
80,984
43,360
Accepted
Accepted
32.28
N = int(eval(input())) A = [list(map(int,input().split())) for _ in range(N)] B = sorted([[A[i][0]-A[i][1],A[i][0]+A[i][1]] for i in range(N)],key=lambda x:x[1]) cur = 1 C = [B[0]] while cur<N: if B[cur][0]>=C[-1][1]: C.append(B[cur]) cur += 1 print((len(C)))
N = int(eval(input())) A = [list(map(int,input().split())) for _ in range(N)] B = sorted([(A[i][0]-A[i][1],A[i][0]+A[i][1]) for i in range(N)],key=lambda x:x[0],reverse=True) B = sorted(B,key=lambda x:x[1]) cnt = 1 cur = B[0][1] for i in range(1,N): if B[i][0]>=cur: cnt += 1 cur = B[i][1] print(cnt)
10
11
276
324
N = int(eval(input())) A = [list(map(int, input().split())) for _ in range(N)] B = sorted( [[A[i][0] - A[i][1], A[i][0] + A[i][1]] for i in range(N)], key=lambda x: x[1] ) cur = 1 C = [B[0]] while cur < N: if B[cur][0] >= C[-1][1]: C.append(B[cur]) cur += 1 print((len(C)))
N = int(eval(input())) A = [list(map(int, input().split())) for _ in range(N)] B = sorted( [(A[i][0] - A[i][1], A[i][0] + A[i][1]) for i in range(N)], key=lambda x: x[0], reverse=True, ) B = sorted(B, key=lambda x: x[1]) cnt = 1 cur = B[0][1] for i in range(1, N): if B[i][0] >= cur: cnt += 1 cur = B[i][1] print(cnt)
false
9.090909
[ "- [[A[i][0] - A[i][1], A[i][0] + A[i][1]] for i in range(N)], key=lambda x: x[1]", "+ [(A[i][0] - A[i][1], A[i][0] + A[i][1]) for i in range(N)],", "+ key=lambda x: x[0],", "+ reverse=True,", "-cur = 1", "-C = [B[0]]", "-while cur < N:", "- if B[cur][0] >= C[-1][1]:", "- C.append(B[cur])", "- cur += 1", "-print((len(C)))", "+B = sorted(B, key=lambda x: x[1])", "+cnt = 1", "+cur = B[0][1]", "+for i in range(1, N):", "+ if B[i][0] >= cur:", "+ cnt += 1", "+ cur = B[i][1]", "+print(cnt)" ]
false
0.111423
0.044156
2.523413
[ "s220437154", "s525959894" ]
u896741788
p03403
python
s014475432
s001604152
265
207
13,920
20,620
Accepted
Accepted
21.89
n=int(eval(input())) l=[0]+list(map(int,input().split()))+[0] ans=0 for a,s in zip(l,l[1:]): ans+=abs(a-s) for i in range(n): a,s=sorted([l[i],l[i+2]]) if a<=l[i+1]<=s:print(ans) else: print((ans-abs(a-l[i+1])-abs(l[i+1]-s)+s-a))
n=eval(input()) l=[0]+list(map(int,input().split()))+[0] ans=0 pre=0 for i in l:ans+=abs(pre-i);pre=i for i in range(1,int(n)+1): dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1]) if l[i]in(l[i-1],l[i+1]):print(ans) elif l[i]<l[i-1]: print((ans if l[i+1]<l[i] else ans+dif)) else:print((ans if l[i+1]>l[i] else ans+dif))
10
11
254
340
n = int(eval(input())) l = [0] + list(map(int, input().split())) + [0] ans = 0 for a, s in zip(l, l[1:]): ans += abs(a - s) for i in range(n): a, s = sorted([l[i], l[i + 2]]) if a <= l[i + 1] <= s: print(ans) else: print((ans - abs(a - l[i + 1]) - abs(l[i + 1] - s) + s - a))
n = eval(input()) l = [0] + list(map(int, input().split())) + [0] ans = 0 pre = 0 for i in l: ans += abs(pre - i) pre = i for i in range(1, int(n) + 1): dif = -abs(l[i] - l[i - 1]) - abs(l[i] - l[i + 1]) + abs(l[i - 1] - l[i + 1]) if l[i] in (l[i - 1], l[i + 1]): print(ans) elif l[i] < l[i - 1]: print((ans if l[i + 1] < l[i] else ans + dif)) else: print((ans if l[i + 1] > l[i] else ans + dif))
false
9.090909
[ "-n = int(eval(input()))", "+n = eval(input())", "-for a, s in zip(l, l[1:]):", "- ans += abs(a - s)", "-for i in range(n):", "- a, s = sorted([l[i], l[i + 2]])", "- if a <= l[i + 1] <= s:", "+pre = 0", "+for i in l:", "+ ans += abs(pre - i)", "+ pre = i", "+for i in range(1, int(n) + 1):", "+ dif = -abs(l[i] - l[i - 1]) - abs(l[i] - l[i + 1]) + abs(l[i - 1] - l[i + 1])", "+ if l[i] in (l[i - 1], l[i + 1]):", "+ elif l[i] < l[i - 1]:", "+ print((ans if l[i + 1] < l[i] else ans + dif))", "- print((ans - abs(a - l[i + 1]) - abs(l[i + 1] - s) + s - a))", "+ print((ans if l[i + 1] > l[i] else ans + dif))" ]
false
0.081374
0.037262
2.183824
[ "s014475432", "s001604152" ]
u655110382
p02773
python
s954414993
s927839196
712
618
34,052
35,568
Accepted
Accepted
13.2
N = int(input()) d = {} mv = 0 mfw = [] for _ in range(N): w = input() d[w] = d.get(w, 0) + 1 if d[w] > mv: mv += 1 mfw.clear() mfw.append(w) elif d[w] == mv: mfw.append(w) [print(w) for w in sorted(mfw)]
from collections import Counter N = int(input()) c = Counter([input() for _ in range(N)]) mv = max(c.values()) [print(w) for w in sorted(c.keys()) if c[w] == mv]
14
6
266
168
N = int(input()) d = {} mv = 0 mfw = [] for _ in range(N): w = input() d[w] = d.get(w, 0) + 1 if d[w] > mv: mv += 1 mfw.clear() mfw.append(w) elif d[w] == mv: mfw.append(w) [print(w) for w in sorted(mfw)]
from collections import Counter N = int(input()) c = Counter([input() for _ in range(N)]) mv = max(c.values()) [print(w) for w in sorted(c.keys()) if c[w] == mv]
false
57.142857
[ "+from collections import Counter", "+", "-d = {}", "-mv = 0", "-mfw = []", "-for _ in range(N):", "- w = input()", "- d[w] = d.get(w, 0) + 1", "- if d[w] > mv:", "- mv += 1", "- mfw.clear()", "- mfw.append(w)", "- elif d[w] == mv:", "- mfw.append(w)", "-[print(w) for w in sorted(mfw)]", "+c = Counter([input() for _ in range(N)])", "+mv = max(c.values())", "+[print(w) for w in sorted(c.keys()) if c[w] == mv]" ]
false
0.039186
0.03915
1.000911
[ "s954414993", "s927839196" ]
u600402037
p03032
python
s080913697
s681113066
90
35
3,064
4,884
Accepted
Accepted
61.11
# coding: utf-8 import sys sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 持っている宝石をDに詰めるのは最後 N, K = lr() V = lr() answer = 0 V = V[::-1] + V[::-1] for x in range(K+1): # x回Dから取り出す、K-x回戻すことが可能 x = min(x, N) for i in range(N-1, N-1+x+1): take = V[i-x+1:i+1] take.sort(reverse=True) result = sum(take) if result > answer: answer = result for j in range(K-x): if take: result -= take.pop() if result > answer: answer = result print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() V = lr() scores = [0] limit = min(N, K) for i in range(limit+1): # iは左から取り出す個数 for j in range(limit-i+1): # jは右から取り出す個数 stone = V[:i] + V[N-j:] stone.sort() result = sum(stone) scores.append(result) for k in range(min(len(stone), K-(i+j))): # kは戻す個数 if stone[k] > 0: break result -= stone[k] scores.append(result) answer = max(scores) print(answer) # 07
29
26
688
625
# coding: utf-8 import sys sys.setrecursionlimit(10**7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 持っている宝石をDに詰めるのは最後 N, K = lr() V = lr() answer = 0 V = V[::-1] + V[::-1] for x in range(K + 1): # x回Dから取り出す、K-x回戻すことが可能 x = min(x, N) for i in range(N - 1, N - 1 + x + 1): take = V[i - x + 1 : i + 1] take.sort(reverse=True) result = sum(take) if result > answer: answer = result for j in range(K - x): if take: result -= take.pop() if result > answer: answer = result print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() V = lr() scores = [0] limit = min(N, K) for i in range(limit + 1): # iは左から取り出す個数 for j in range(limit - i + 1): # jは右から取り出す個数 stone = V[:i] + V[N - j :] stone.sort() result = sum(stone) scores.append(result) for k in range(min(len(stone), K - (i + j))): # kは戻す個数 if stone[k] > 0: break result -= stone[k] scores.append(result) answer = max(scores) print(answer) # 07
false
10.344828
[ "-sys.setrecursionlimit(10**7)", "-# 持っている宝石をDに詰めるのは最後", "-answer = 0", "-V = V[::-1] + V[::-1]", "-for x in range(K + 1):", "- # x回Dから取り出す、K-x回戻すことが可能", "- x = min(x, N)", "- for i in range(N - 1, N - 1 + x + 1):", "- take = V[i - x + 1 : i + 1]", "- take.sort(reverse=True)", "- result = sum(take)", "- if result > answer:", "- answer = result", "- for j in range(K - x):", "- if take:", "- result -= take.pop()", "- if result > answer:", "- answer = result", "+scores = [0]", "+limit = min(N, K)", "+for i in range(limit + 1): # iは左から取り出す個数", "+ for j in range(limit - i + 1): # jは右から取り出す個数", "+ stone = V[:i] + V[N - j :]", "+ stone.sort()", "+ result = sum(stone)", "+ scores.append(result)", "+ for k in range(min(len(stone), K - (i + j))): # kは戻す個数", "+ if stone[k] > 0:", "+ break", "+ result -= stone[k]", "+ scores.append(result)", "+answer = max(scores)", "+# 07" ]
false
0.03665
0.006908
5.305419
[ "s080913697", "s681113066" ]
u945181840
p03674
python
s913642015
s231131364
361
318
31,704
31,708
Accepted
Accepted
11.91
from collections import Counter n, *a = list(map(int, open(0).read().split())) n += 1 def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10 ** 9 + 7 N = n # 元テーブル g1 = [0] * (N + 1) g1[0] = 1 g1[1] = 1 # 逆元テーブル g2 = [0] * (N + 1) g2[0] = 1 g2[1] = 1 # 逆元テーブル計算用テーブル inverse = [0] * (N + 1) inverse[0] = 0 inverse[1] = 1 for i in range(2, N + 1): g1[i] = (g1[i - 1] * i) % mod inverse[i] = (-inverse[mod % i] * (mod // i)) % mod g2[i] = (g2[i - 1] * inverse[i]) % mod d = Counter(a).most_common(1)[0][0] lr = [i for i, e in enumerate(a) if e == d] l = lr[1] - lr[0] + 1 answer = [(cmb(n, i, mod) - cmb(n - l, i - 1, mod)) % mod for i in range(1, n + 1)] print(('\n'.join(map(str, answer))))
from collections import Counter n, *a = list(map(int, open(0).read().split())) n += 1 def cmb(n, r, mod=10 ** 9 + 7): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod def make_table(n, mod=10 ** 9 + 7): mod = mod N = n # 元テーブル g1 = [0] * (N + 1) g1[0] = 1 g1[1] = 1 # 逆元テーブル g2 = [0] * (N + 1) g2[0] = 1 g2[1] = 1 # 逆元テーブル計算用テーブル inverse = [0] * (N + 1) inverse[0] = 0 inverse[1] = 1 for i in range(2, N + 1): g1[i] = (g1[i - 1] * i) % mod inverse[i] = (-inverse[mod % i] * (mod // i)) % mod g2[i] = (g2[i - 1] * inverse[i]) % mod return g1, g2, inverse d = Counter(a).most_common(1)[0][0] lr = [i for i, e in enumerate(a) if e == d] l = lr[1] - lr[0] + 1 g1, g2, inverse = make_table(n) MOD = 10 ** 9 + 7 answer = [(cmb(n, i) - cmb(n - l, i - 1)) % MOD for i in range(1, n + 1)] print(('\n'.join(map(str, answer))))
41
47
823
1,010
from collections import Counter n, *a = list(map(int, open(0).read().split())) n += 1 def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 N = n # 元テーブル g1 = [0] * (N + 1) g1[0] = 1 g1[1] = 1 # 逆元テーブル g2 = [0] * (N + 1) g2[0] = 1 g2[1] = 1 # 逆元テーブル計算用テーブル inverse = [0] * (N + 1) inverse[0] = 0 inverse[1] = 1 for i in range(2, N + 1): g1[i] = (g1[i - 1] * i) % mod inverse[i] = (-inverse[mod % i] * (mod // i)) % mod g2[i] = (g2[i - 1] * inverse[i]) % mod d = Counter(a).most_common(1)[0][0] lr = [i for i, e in enumerate(a) if e == d] l = lr[1] - lr[0] + 1 answer = [(cmb(n, i, mod) - cmb(n - l, i - 1, mod)) % mod for i in range(1, n + 1)] print(("\n".join(map(str, answer))))
from collections import Counter n, *a = list(map(int, open(0).read().split())) n += 1 def cmb(n, r, mod=10**9 + 7): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod def make_table(n, mod=10**9 + 7): mod = mod N = n # 元テーブル g1 = [0] * (N + 1) g1[0] = 1 g1[1] = 1 # 逆元テーブル g2 = [0] * (N + 1) g2[0] = 1 g2[1] = 1 # 逆元テーブル計算用テーブル inverse = [0] * (N + 1) inverse[0] = 0 inverse[1] = 1 for i in range(2, N + 1): g1[i] = (g1[i - 1] * i) % mod inverse[i] = (-inverse[mod % i] * (mod // i)) % mod g2[i] = (g2[i - 1] * inverse[i]) % mod return g1, g2, inverse d = Counter(a).most_common(1)[0][0] lr = [i for i, e in enumerate(a) if e == d] l = lr[1] - lr[0] + 1 g1, g2, inverse = make_table(n) MOD = 10**9 + 7 answer = [(cmb(n, i) - cmb(n - l, i - 1)) % MOD for i in range(1, n + 1)] print(("\n".join(map(str, answer))))
false
12.765957
[ "-def cmb(n, r, mod):", "+def cmb(n, r, mod=10**9 + 7):", "-mod = 10**9 + 7", "-N = n", "-# 元テーブル", "-g1 = [0] * (N + 1)", "-g1[0] = 1", "-g1[1] = 1", "-# 逆元テーブル", "-g2 = [0] * (N + 1)", "-g2[0] = 1", "-g2[1] = 1", "-# 逆元テーブル計算用テーブル", "-inverse = [0] * (N + 1)", "-inverse[0] = 0", "-inverse[1] = 1", "-for i in range(2, N + 1):", "- g1[i] = (g1[i - 1] * i) % mod", "- inverse[i] = (-inverse[mod % i] * (mod // i)) % mod", "- g2[i] = (g2[i - 1] * inverse[i]) % mod", "+def make_table(n, mod=10**9 + 7):", "+ mod = mod", "+ N = n", "+ # 元テーブル", "+ g1 = [0] * (N + 1)", "+ g1[0] = 1", "+ g1[1] = 1", "+ # 逆元テーブル", "+ g2 = [0] * (N + 1)", "+ g2[0] = 1", "+ g2[1] = 1", "+ # 逆元テーブル計算用テーブル", "+ inverse = [0] * (N + 1)", "+ inverse[0] = 0", "+ inverse[1] = 1", "+ for i in range(2, N + 1):", "+ g1[i] = (g1[i - 1] * i) % mod", "+ inverse[i] = (-inverse[mod % i] * (mod // i)) % mod", "+ g2[i] = (g2[i - 1] * inverse[i]) % mod", "+ return g1, g2, inverse", "+", "+", "-answer = [(cmb(n, i, mod) - cmb(n - l, i - 1, mod)) % mod for i in range(1, n + 1)]", "+g1, g2, inverse = make_table(n)", "+MOD = 10**9 + 7", "+answer = [(cmb(n, i) - cmb(n - l, i - 1)) % MOD for i in range(1, n + 1)]" ]
false
0.043953
0.048681
0.90287
[ "s913642015", "s231131364" ]
u847467233
p00042
python
s526520967
s023745497
1,070
880
5,728
5,728
Accepted
Accepted
17.76
# AOJ 0042 A Thief # Python3 2018.6.22 bal4u MAX = 1003 for cno in range(1, 100): lim = int(input()) if lim == 0: break print("Case ", cno, ":", sep='') N = int(input()) vw = [(0, 0)] for i in range(N): v, w = list(map(int, input().split(','))) vw.append((v, w)) V = [[0 for j in range(MAX)] for i in range(2)] W = [[0 for j in range(MAX)] for i in range(2)] k1, k2 = 0, 1 for i in range(1, N+1): for j in range(1, lim+1): v, w = vw[i] if w > j: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] else: d = j - w if V[k1][d] + v >= V[k1][j]: V[k2][j] = V[k1][d] + v W[k2][j] = W[k1][d] + w else: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] k1, k2 = k2, k1 print(V[k1][lim], W[k1][lim], sep='\n')
# AOJ 0042 A Thief # Python3 2018.6.22 bal4u MAX = 1003 for cno in range(1, 100): lim = int(input()) if lim == 0: break print("Case ", cno, ":", sep='') N = int(input()) V = [[0 for j in range(MAX)] for i in range(2)] W = [[0 for j in range(MAX)] for i in range(2)] k1, k2 = 0, 1 for i in range(1, N+1): v, w = map(int, input().split(',')) for j in range(1, w): V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] for j in range(w, lim+1): d = j - w if V[k1][d] + v >= V[k1][j]: V[k2][j] = V[k1][d] + v W[k2][j] = W[k1][d] + w else: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] k1, k2 = k2, k1 print(V[k1][lim], W[k1][lim], sep='\n')
34
28
787
696
# AOJ 0042 A Thief # Python3 2018.6.22 bal4u MAX = 1003 for cno in range(1, 100): lim = int(input()) if lim == 0: break print("Case ", cno, ":", sep="") N = int(input()) vw = [(0, 0)] for i in range(N): v, w = list(map(int, input().split(","))) vw.append((v, w)) V = [[0 for j in range(MAX)] for i in range(2)] W = [[0 for j in range(MAX)] for i in range(2)] k1, k2 = 0, 1 for i in range(1, N + 1): for j in range(1, lim + 1): v, w = vw[i] if w > j: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] else: d = j - w if V[k1][d] + v >= V[k1][j]: V[k2][j] = V[k1][d] + v W[k2][j] = W[k1][d] + w else: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] k1, k2 = k2, k1 print(V[k1][lim], W[k1][lim], sep="\n")
# AOJ 0042 A Thief # Python3 2018.6.22 bal4u MAX = 1003 for cno in range(1, 100): lim = int(input()) if lim == 0: break print("Case ", cno, ":", sep="") N = int(input()) V = [[0 for j in range(MAX)] for i in range(2)] W = [[0 for j in range(MAX)] for i in range(2)] k1, k2 = 0, 1 for i in range(1, N + 1): v, w = map(int, input().split(",")) for j in range(1, w): V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] for j in range(w, lim + 1): d = j - w if V[k1][d] + v >= V[k1][j]: V[k2][j] = V[k1][d] + v W[k2][j] = W[k1][d] + w else: V[k2][j] = V[k1][j] W[k2][j] = W[k1][j] k1, k2 = k2, k1 print(V[k1][lim], W[k1][lim], sep="\n")
false
17.647059
[ "- vw = [(0, 0)]", "- for i in range(N):", "- v, w = list(map(int, input().split(\",\")))", "- vw.append((v, w))", "- for j in range(1, lim + 1):", "- v, w = vw[i]", "- if w > j:", "+ v, w = map(int, input().split(\",\"))", "+ for j in range(1, w):", "+ V[k2][j] = V[k1][j]", "+ W[k2][j] = W[k1][j]", "+ for j in range(w, lim + 1):", "+ d = j - w", "+ if V[k1][d] + v >= V[k1][j]:", "+ V[k2][j] = V[k1][d] + v", "+ W[k2][j] = W[k1][d] + w", "+ else:", "- else:", "- d = j - w", "- if V[k1][d] + v >= V[k1][j]:", "- V[k2][j] = V[k1][d] + v", "- W[k2][j] = W[k1][d] + w", "- else:", "- V[k2][j] = V[k1][j]", "- W[k2][j] = W[k1][j]" ]
false
0.059058
0.038154
1.547914
[ "s526520967", "s023745497" ]
u014268998
p02887
python
s147879902
s411422788
55
32
3,316
3,316
Accepted
Accepted
41.82
n = int(eval(input())) s = eval(input()) out = s[0] x = s[0] for i in range(1,n): if s[i] == x: continue else: out += s[i] x = s[i] print(( len(out) ))
n = int(eval(input())) s = eval(input()) ans = 0 current = '' for i in s: if i != current: ans += 1 current = i print(ans)
12
11
165
132
n = int(eval(input())) s = eval(input()) out = s[0] x = s[0] for i in range(1, n): if s[i] == x: continue else: out += s[i] x = s[i] print((len(out)))
n = int(eval(input())) s = eval(input()) ans = 0 current = "" for i in s: if i != current: ans += 1 current = i print(ans)
false
8.333333
[ "-out = s[0]", "-x = s[0]", "-for i in range(1, n):", "- if s[i] == x:", "- continue", "- else:", "- out += s[i]", "- x = s[i]", "-print((len(out)))", "+ans = 0", "+current = \"\"", "+for i in s:", "+ if i != current:", "+ ans += 1", "+ current = i", "+print(ans)" ]
false
0.037906
0.036888
1.027602
[ "s147879902", "s411422788" ]
u878654696
p02882
python
s064473021
s161144410
30
27
9,464
9,364
Accepted
Accepted
10
from math import * a, b, x = list(map(int, input().split())) areatotal = a*a*b if areatotal / 2 == x: print((45.0)) elif x > areatotal/2: left = 0.0 right = 90.0 while right-left > 0.00000001: current = (right+left)/2 if a**2 * tan(radians(current)) / 2 * a < (areatotal - x): left = current else: right = current print(left) else: left = 0.0 right = 90.0 while right-left > 0.00000001: current = (right+left)/2 if b**2 * tan(radians(90-current))/2*a > x: left = current else: right = current print(left)
from math import atan, degrees def angle(a, b, x): return degrees(atan(((a * b ** 2) / ( 2 * x)) if x <= 0.5 * b * a ** 2 else ((2 * (b - (x / (a ** 2)))) / a))) print((angle(*list(map(int, input().split())))))
28
6
656
214
from math import * a, b, x = list(map(int, input().split())) areatotal = a * a * b if areatotal / 2 == x: print((45.0)) elif x > areatotal / 2: left = 0.0 right = 90.0 while right - left > 0.00000001: current = (right + left) / 2 if a**2 * tan(radians(current)) / 2 * a < (areatotal - x): left = current else: right = current print(left) else: left = 0.0 right = 90.0 while right - left > 0.00000001: current = (right + left) / 2 if b**2 * tan(radians(90 - current)) / 2 * a > x: left = current else: right = current print(left)
from math import atan, degrees def angle(a, b, x): return degrees( atan( ((a * b**2) / (2 * x)) if x <= 0.5 * b * a**2 else ((2 * (b - (x / (a**2)))) / a) ) ) print((angle(*list(map(int, input().split())))))
false
78.571429
[ "-from math import *", "+from math import atan, degrees", "-a, b, x = list(map(int, input().split()))", "-areatotal = a * a * b", "-if areatotal / 2 == x:", "- print((45.0))", "-elif x > areatotal / 2:", "- left = 0.0", "- right = 90.0", "- while right - left > 0.00000001:", "- current = (right + left) / 2", "- if a**2 * tan(radians(current)) / 2 * a < (areatotal - x):", "- left = current", "- else:", "- right = current", "- print(left)", "-else:", "- left = 0.0", "- right = 90.0", "- while right - left > 0.00000001:", "- current = (right + left) / 2", "- if b**2 * tan(radians(90 - current)) / 2 * a > x:", "- left = current", "- else:", "- right = current", "- print(left)", "+", "+def angle(a, b, x):", "+ return degrees(", "+ atan(", "+ ((a * b**2) / (2 * x))", "+ if x <= 0.5 * b * a**2", "+ else ((2 * (b - (x / (a**2)))) / a)", "+ )", "+ )", "+", "+", "+print((angle(*list(map(int, input().split())))))" ]
false
0.047545
0.055355
0.858907
[ "s064473021", "s161144410" ]
u292735000
p03416
python
s447463940
s955067319
73
45
2,940
2,940
Accepted
Accepted
38.36
a, b = list(map(int, input().split())) sum_n = 0 for i in range(a, b + 1): if str(i)[0] == str(i)[-1] and str(i)[1] == str(i)[-2]: sum_n += 1 print(sum_n)
a, b = list(map(int, input().split())) sum_s = 0 for i in range(a, b + 1): s = str(i) if s[0] == s[-1] and s[1] == s[-2]: sum_s += 1 print(sum_s)
8
9
169
165
a, b = list(map(int, input().split())) sum_n = 0 for i in range(a, b + 1): if str(i)[0] == str(i)[-1] and str(i)[1] == str(i)[-2]: sum_n += 1 print(sum_n)
a, b = list(map(int, input().split())) sum_s = 0 for i in range(a, b + 1): s = str(i) if s[0] == s[-1] and s[1] == s[-2]: sum_s += 1 print(sum_s)
false
11.111111
[ "-sum_n = 0", "+sum_s = 0", "- if str(i)[0] == str(i)[-1] and str(i)[1] == str(i)[-2]:", "- sum_n += 1", "-print(sum_n)", "+ s = str(i)", "+ if s[0] == s[-1] and s[1] == s[-2]:", "+ sum_s += 1", "+print(sum_s)" ]
false
0.049683
0.080094
0.620301
[ "s447463940", "s955067319" ]
u488127128
p03073
python
s697083121
s708531461
48
17
3,316
3,188
Accepted
Accepted
64.58
S = eval(input()) d,m = len(S)//2,len(S)%2 A = '01'*d+'0'*m B = '10'*d+'1'*m count_a = 0 count_b = 0 for s,a,b in zip(S,A,B): if s != a: count_a += 1 if s != b: count_b += 1 print((min(count_a, count_b)))
s = eval(input()) h = s[::2].count('1') + s[1::2].count('0') print((min(h, len(s)-h)))
12
3
231
80
S = eval(input()) d, m = len(S) // 2, len(S) % 2 A = "01" * d + "0" * m B = "10" * d + "1" * m count_a = 0 count_b = 0 for s, a, b in zip(S, A, B): if s != a: count_a += 1 if s != b: count_b += 1 print((min(count_a, count_b)))
s = eval(input()) h = s[::2].count("1") + s[1::2].count("0") print((min(h, len(s) - h)))
false
75
[ "-S = eval(input())", "-d, m = len(S) // 2, len(S) % 2", "-A = \"01\" * d + \"0\" * m", "-B = \"10\" * d + \"1\" * m", "-count_a = 0", "-count_b = 0", "-for s, a, b in zip(S, A, B):", "- if s != a:", "- count_a += 1", "- if s != b:", "- count_b += 1", "-print((min(count_a, count_b)))", "+s = eval(input())", "+h = s[::2].count(\"1\") + s[1::2].count(\"0\")", "+print((min(h, len(s) - h)))" ]
false
0.03669
0.035369
1.03735
[ "s697083121", "s708531461" ]
u150984829
p02413
python
s019050824
s323111459
30
20
6,252
6,248
Accepted
Accepted
33.33
r,c=list(map(int,input().split())) m=[[int(_) for _ in input().split()] for i in range(r)] for i in range(r):m[i].append(sum(m[i])) m.append([sum([m[i][j] for i in range(r)]) for j in range(c+1)]) for i in range(r+1):print((*m[i]))
r,c=map(int,input().split()) m=[[int(_) for _ in input().split()] for i in range(r)] for i in range(r):m[i].append(sum(m[i])) m.append([sum([m[i][j] for i in range(r)]) for j in range(c+1)]) [print(*m[i]) for i in range(r+1)]
5
5
227
229
r, c = list(map(int, input().split())) m = [[int(_) for _ in input().split()] for i in range(r)] for i in range(r): m[i].append(sum(m[i])) m.append([sum([m[i][j] for i in range(r)]) for j in range(c + 1)]) for i in range(r + 1): print((*m[i]))
r, c = map(int, input().split()) m = [[int(_) for _ in input().split()] for i in range(r)] for i in range(r): m[i].append(sum(m[i])) m.append([sum([m[i][j] for i in range(r)]) for j in range(c + 1)]) [print(*m[i]) for i in range(r + 1)]
false
0
[ "-r, c = list(map(int, input().split()))", "+r, c = map(int, input().split())", "-for i in range(r + 1):", "- print((*m[i]))", "+[print(*m[i]) for i in range(r + 1)]" ]
false
0.064844
0.053356
1.215307
[ "s019050824", "s323111459" ]
u197457087
p03325
python
s164830738
s900847342
110
84
4,148
70,744
Accepted
Accepted
23.64
N = int(eval(input())) A = list(map(int,input().split())) ans = 0 for i in range(N): while A[i]%2 == 0: ans += 1 A[i] = A[i]//2 print(ans)
N = int(eval(input())) A = list(map(int,input().split())) Flag = True for x in A: if x%2 != 1: Flag = False break if Flag: print((0)) exit() ans = 0 for x in A: while x%2 == 0: ans += 1 x = x//2 print(ans)
10
16
154
236
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for i in range(N): while A[i] % 2 == 0: ans += 1 A[i] = A[i] // 2 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) Flag = True for x in A: if x % 2 != 1: Flag = False break if Flag: print((0)) exit() ans = 0 for x in A: while x % 2 == 0: ans += 1 x = x // 2 print(ans)
false
37.5
[ "+Flag = True", "+for x in A:", "+ if x % 2 != 1:", "+ Flag = False", "+ break", "+if Flag:", "+ print((0))", "+ exit()", "-for i in range(N):", "- while A[i] % 2 == 0:", "+for x in A:", "+ while x % 2 == 0:", "- A[i] = A[i] // 2", "+ x = x // 2" ]
false
0.095325
0.036876
2.585011
[ "s164830738", "s900847342" ]
u893962649
p02621
python
s536350192
s499303382
30
25
9,056
9,092
Accepted
Accepted
16.67
a = int(eval(input())) print((a + a**2 + a**3))
A = int(eval(input())) ans = A + A**2 + A**3 print(ans)
3
5
43
55
a = int(eval(input())) print((a + a**2 + a**3))
A = int(eval(input())) ans = A + A**2 + A**3 print(ans)
false
40
[ "-a = int(eval(input()))", "-print((a + a**2 + a**3))", "+A = int(eval(input()))", "+ans = A + A**2 + A**3", "+print(ans)" ]
false
0.059614
0.037995
1.568998
[ "s536350192", "s499303382" ]
u278356323
p02951
python
s295966258
s285484064
19
17
3,060
2,940
Accepted
Accepted
10.53
# ABC136a import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a, b, c = list(map(int, input().split())) print((max(0, c-(a-b))))
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a, b, c = list(map(int, input().split())) print((c-min(a-b, c))) if __name__ == '__main__': main()
8
10
144
205
# ABC136a import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a, b, c = list(map(int, input().split())) print((max(0, c - (a - b))))
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a, b, c = list(map(int, input().split())) print((c - min(a - b, c))) if __name__ == "__main__": main()
false
20
[ "-# ABC136a", "-import sys", "+def main():", "+ import sys", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**6)", "-a, b, c = list(map(int, input().split()))", "-print((max(0, c - (a - b))))", "+ input = sys.stdin.readline", "+ sys.setrecursionlimit(10**6)", "+ a, b, c = list(map(int, input().split()))", "+ print((c - min(a - b, c)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.046336
0.049597
0.934241
[ "s295966258", "s285484064" ]
u439396449
p03212
python
s306173836
s541161064
56
19
3,060
3,064
Accepted
Accepted
66.07
from itertools import product N = int(eval(input())) S = str(N) n = len(S) ans = 0 for i in range(3, n + 1): for p in product(['3', '5', '7'], repeat=i): x = int(''.join(p)) if x <= N and len(set(p) & {'3', '5', '7'}) == 3: ans += 1 print(ans)
from itertools import product N = int(eval(input())) S = [int(x) for x in str(N)] n = len(S) # dp[pos][smaller?][started?][3?][5?][7?] dp = [[[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(n + 1)] dp[0][0][0][0][0][0] = 1 for i, j, k, c3, c5, c7 in product(list(range(n)), [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]): num = [0, 3, 5, 7] if not j: num = [x for x in num if x <= S[i]] if k: num = [x for x in num if x != 0] for x in num: f0 = k or x != 0 f3 = c3 or x == 3 f5 = c5 or x == 5 f7 = c7 or x == 7 dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7] ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]]) print(ans)
14
28
286
822
from itertools import product N = int(eval(input())) S = str(N) n = len(S) ans = 0 for i in range(3, n + 1): for p in product(["3", "5", "7"], repeat=i): x = int("".join(p)) if x <= N and len(set(p) & {"3", "5", "7"}) == 3: ans += 1 print(ans)
from itertools import product N = int(eval(input())) S = [int(x) for x in str(N)] n = len(S) # dp[pos][smaller?][started?][3?][5?][7?] dp = [ [ [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2) ] for _ in range(n + 1) ] dp[0][0][0][0][0][0] = 1 for i, j, k, c3, c5, c7 in product( list(range(n)), [0, 1], [0, 1], [0, 1], [0, 1], [0, 1] ): num = [0, 3, 5, 7] if not j: num = [x for x in num if x <= S[i]] if k: num = [x for x in num if x != 0] for x in num: f0 = k or x != 0 f3 = c3 or x == 3 f5 = c5 or x == 5 f7 = c7 or x == 7 dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7] ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]]) print(ans)
false
50
[ "-S = str(N)", "+S = [int(x) for x in str(N)]", "-ans = 0", "-for i in range(3, n + 1):", "- for p in product([\"3\", \"5\", \"7\"], repeat=i):", "- x = int(\"\".join(p))", "- if x <= N and len(set(p) & {\"3\", \"5\", \"7\"}) == 3:", "- ans += 1", "+# dp[pos][smaller?][started?][3?][5?][7?]", "+dp = [", "+ [", "+ [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]", "+ for _ in range(2)", "+ ]", "+ for _ in range(n + 1)", "+]", "+dp[0][0][0][0][0][0] = 1", "+for i, j, k, c3, c5, c7 in product(", "+ list(range(n)), [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]", "+):", "+ num = [0, 3, 5, 7]", "+ if not j:", "+ num = [x for x in num if x <= S[i]]", "+ if k:", "+ num = [x for x in num if x != 0]", "+ for x in num:", "+ f0 = k or x != 0", "+ f3 = c3 or x == 3", "+ f5 = c5 or x == 5", "+ f7 = c7 or x == 7", "+ dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7]", "+ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]])" ]
false
0.058024
0.048058
1.207353
[ "s306173836", "s541161064" ]
u279605379
p02300
python
s466141440
s822589679
980
830
33,784
33,924
Accepted
Accepted
15.31
def isCLKWISE(ph): a = ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1] b = ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1] crs = b[1]*a[0] - a[1]*b[0] if crs < 0 : return False else : return True def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): if isCLKWISE(phU) : break else : del phU[-2] if len(phU) == 2 : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): if isCLKWISE(phL) : break else : del phL[-2] if len(phL) == 2 : break ph = phU + phL[1:-1] return ph n = int(eval(input())) P = [] for i in range(n): P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print((len(Q))) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print((r[0],r[1]))
def isCLKWISE(ph): a = ph[-1][0] - ph[-3][0] d = - ph[-3][1] + ph[-2][1] c = ph[-2][0] - ph[-3][0] b = - ph[-3][1] + ph[-1][1] crs = a*d - b*c if crs < 0 : return False else : return True def ConvexHullScan(P): P = sorted(P) phU = [P[0],P[1]] for p in P[2:]: phU.append(p) while(True): if isCLKWISE(phU) : break else : del phU[-2] if len(phU) == 2 : break phL = [P[-1],P[-2]] for p in P[-3::-1]: phL.append(p) while(True): if isCLKWISE(phL) : break else : del phL[-2] if len(phL) == 2 : break ph = phU + phL[1:-1] return ph n = int(eval(input())) P = [] for i in range(n): P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print((len(Q))) idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print((r[0],r[1]))
40
42
1,015
1,034
def isCLKWISE(ph): a = ph[-1][0] - ph[-3][0], ph[-1][1] - ph[-3][1] b = ph[-2][0] - ph[-3][0], ph[-2][1] - ph[-3][1] crs = b[1] * a[0] - a[1] * b[0] if crs < 0: return False else: return True def ConvexHullScan(P): P = sorted(P) phU = [P[0], P[1]] for p in P[2:]: phU.append(p) while True: if isCLKWISE(phU): break else: del phU[-2] if len(phU) == 2: break phL = [P[-1], P[-2]] for p in P[-3::-1]: phL.append(p) while True: if isCLKWISE(phL): break else: del phL[-2] if len(phL) == 2: break ph = phU + phL[1:-1] return ph n = int(eval(input())) P = [] for i in range(n): P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print((len(Q))) idx = min([[x[1][1], x[1][0], x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print((r[0], r[1]))
def isCLKWISE(ph): a = ph[-1][0] - ph[-3][0] d = -ph[-3][1] + ph[-2][1] c = ph[-2][0] - ph[-3][0] b = -ph[-3][1] + ph[-1][1] crs = a * d - b * c if crs < 0: return False else: return True def ConvexHullScan(P): P = sorted(P) phU = [P[0], P[1]] for p in P[2:]: phU.append(p) while True: if isCLKWISE(phU): break else: del phU[-2] if len(phU) == 2: break phL = [P[-1], P[-2]] for p in P[-3::-1]: phL.append(p) while True: if isCLKWISE(phL): break else: del phL[-2] if len(phL) == 2: break ph = phU + phL[1:-1] return ph n = int(eval(input())) P = [] for i in range(n): P.append([int(x) for x in input().split()]) Q = ConvexHullScan(P) Q.reverse() print((len(Q))) idx = min([[x[1][1], x[1][0], x[0]] for x in enumerate(Q)])[2] R = Q[idx:] + Q[:idx] for r in R: print((r[0], r[1]))
false
4.761905
[ "- a = ph[-1][0] - ph[-3][0], ph[-1][1] - ph[-3][1]", "- b = ph[-2][0] - ph[-3][0], ph[-2][1] - ph[-3][1]", "- crs = b[1] * a[0] - a[1] * b[0]", "+ a = ph[-1][0] - ph[-3][0]", "+ d = -ph[-3][1] + ph[-2][1]", "+ c = ph[-2][0] - ph[-3][0]", "+ b = -ph[-3][1] + ph[-1][1]", "+ crs = a * d - b * c" ]
false
0.036558
0.042069
0.869002
[ "s466141440", "s822589679" ]
u440566786
p02912
python
s509269657
s507568092
454
144
68,296
14,380
Accepted
Accepted
68.28
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 import heapq input=sys.stdin.readline def resolve(): n,m=list(map(int,input().split())) A=list([-(int(x)) for x in input().split()]) heapq.heapify(A) for _ in range(m): a=heapq.heappop(A) a=-a a=a>>1 heapq.heappush(A,-a) print((-sum(A))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): from heapq import heapify,heappop,heappush n,m=list(map(int,input().split())) A=[-a for a in map(int,input().split())] heapify(A) for _ in range(m): x=-heappop(A) heappush(A,-(x//2)) print((-sum(A))) resolve()
18
15
386
388
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 import heapq input = sys.stdin.readline def resolve(): n, m = list(map(int, input().split())) A = list([-(int(x)) for x in input().split()]) heapq.heapify(A) for _ in range(m): a = heapq.heappop(A) a = -a a = a >> 1 heapq.heappush(A, -a) print((-sum(A))) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): from heapq import heapify, heappop, heappush n, m = list(map(int, input().split())) A = [-a for a in map(int, input().split())] heapify(A) for _ in range(m): x = -heappop(A) heappush(A, -(x // 2)) print((-sum(A))) resolve()
false
16.666667
[ "-import heapq", "-", "-input = sys.stdin.readline", "+input = lambda: sys.stdin.readline().rstrip()", "+ from heapq import heapify, heappop, heappush", "+", "- A = list([-(int(x)) for x in input().split()])", "- heapq.heapify(A)", "+ A = [-a for a in map(int, input().split())]", "+ heapify(A)", "- a = heapq.heappop(A)", "- a = -a", "- a = a >> 1", "- heapq.heappush(A, -a)", "+ x = -heappop(A)", "+ heappush(A, -(x // 2))" ]
false
0.040241
0.065429
0.615031
[ "s509269657", "s507568092" ]
u688281605
p02803
python
s265242318
s457770223
262
217
19,388
16,656
Accepted
Accepted
17.18
import numpy as np from scipy.sparse import csgraph H, W = list(map(int, input().split())) maze = "".join(eval(input()) for _ in range(H)) array = np.zeros((H * W, H * W), dtype=np.bool) for n in range(H * W): if maze[n] == "#": continue r, c = divmod(n, W) if c and maze[n - 1] == ".": array[n][n - 1] = 1 array[n - 1][n] = 1 if r and maze[n - W] == ".": array[n][n - W] = 1 array[n - W][n] = 1 dist = csgraph.shortest_path(array) print((int(dist[dist < 401].max())))
import numpy as np from scipy.sparse import csgraph H, W = list(map(int, input().split()))#縦と横の大きさを入力から得る maze = "".join(eval(input()) for _ in range(H))#入力を全行数分取得 #配列を生成する。np.zeros()は全てを0に初期化する関数 #第1引数は H*W,H*Wの2次元配列、第2引数はbool型を意味する array = np.zeros((H * W, H * W), dtype=np.bool) for n in range(H * W): if maze[n] == "#": continue r, c = divmod(n, W)#divmod()は商と余りを求める関数。(r:商 c:余り) if c and maze[n - 1] == ".": array[n][n - 1] = 1 array[n - 1][n] = 1 if r and maze[n - W] == ".": array[n][n - W] = 1 array[n - W][n] = 1 dist = csgraph.shortest_path(array) print((int(dist[dist < 401].max())))
17
22
527
664
import numpy as np from scipy.sparse import csgraph H, W = list(map(int, input().split())) maze = "".join(eval(input()) for _ in range(H)) array = np.zeros((H * W, H * W), dtype=np.bool) for n in range(H * W): if maze[n] == "#": continue r, c = divmod(n, W) if c and maze[n - 1] == ".": array[n][n - 1] = 1 array[n - 1][n] = 1 if r and maze[n - W] == ".": array[n][n - W] = 1 array[n - W][n] = 1 dist = csgraph.shortest_path(array) print((int(dist[dist < 401].max())))
import numpy as np from scipy.sparse import csgraph H, W = list(map(int, input().split())) # 縦と横の大きさを入力から得る maze = "".join(eval(input()) for _ in range(H)) # 入力を全行数分取得 # 配列を生成する。np.zeros()は全てを0に初期化する関数 # 第1引数は H*W,H*Wの2次元配列、第2引数はbool型を意味する array = np.zeros((H * W, H * W), dtype=np.bool) for n in range(H * W): if maze[n] == "#": continue r, c = divmod(n, W) # divmod()は商と余りを求める関数。(r:商 c:余り) if c and maze[n - 1] == ".": array[n][n - 1] = 1 array[n - 1][n] = 1 if r and maze[n - W] == ".": array[n][n - W] = 1 array[n - W][n] = 1 dist = csgraph.shortest_path(array) print((int(dist[dist < 401].max())))
false
22.727273
[ "-H, W = list(map(int, input().split()))", "-maze = \"\".join(eval(input()) for _ in range(H))", "+H, W = list(map(int, input().split())) # 縦と横の大きさを入力から得る", "+maze = \"\".join(eval(input()) for _ in range(H)) # 入力を全行数分取得", "+# 配列を生成する。np.zeros()は全てを0に初期化する関数", "+# 第1引数は H*W,H*Wの2次元配列、第2引数はbool型を意味する", "- r, c = divmod(n, W)", "+ r, c = divmod(n, W) # divmod()は商と余りを求める関数。(r:商 c:余り)" ]
false
0.449332
0.643813
0.697923
[ "s265242318", "s457770223" ]
u254871849
p02850
python
s449078889
s609259844
344
252
38,204
37,820
Accepted
Accepted
26.74
# 2019-11-24 20:59:47(JST) import sys def main(): n = int(sys.stdin.readline().rstrip()) m = list(map(int, sys.stdin.read().split())) ab = list(zip(m, m)) # 2回以上使えるようにlist化 graph = [[] for _ in range(n + 1)] for a, b in ab: graph[a].append(b) graph[b].append(a) root = 1 parent = [None] * (n + 1) # treeなのでループがないため、parentが定義できる checked = [] to_check = [root] # dfs: depth first search では stack # bfs: breadth first search では queueを使う # 今回は stack while to_check: x = to_check.pop() # stackから要素を取り除き、xにset for y in graph[x]: # xから直接つながっているverticesについて if y == parent[x]: continue # yがxの親でなければ parent[y] = x # xを親にして to_check.append(y) # 子であるyをto_checkにstackしていく checked.append(x) # 探索が終わったらvertexを記録 color = [None] * (n + 1) # 初期状態ではなにも塗らないのがNG # vertexに色を、色1から始めて一つ塗ったら色2, 色3,...と変えて塗っていく # その際、色iがngだったらその色iを跳ばして色i+1,色i+2,...と塗っていく(ngは親の色) for x in checked: # checkされた順になっている ng = color[x] c = 1 for y in graph[x]: if y == parent[x]: continue if c == ng: c += 1 color[y] = c c += 1 res = [] for a, b in ab: if a == parent[b]: res.append(color[b]) else: # 木なので parent[a] == b res.append(color[a]) print((max(res))) print(('\n'.join(map(str, res)))) if __name__ == '__main__': main()
import sys from collections import deque def main(): n = int(sys.stdin.readline().rstrip()) ab = list(map(int, sys.stdin.read().split())) ab = list(zip(ab, ab)) G = [[] for _ in range(n + 1)] for a, b in ab: G[a].append(b) G[b].append(a) root = 1 q = deque() q.append(root) parent = [None] * (n + 1) color = [0] * (n + 1) # color[y]はx = parent[y]としてcolor[x] に依存する。 while q: x = q.popleft() c = 1 for y in G[x]: if y == parent[x]: continue parent[y] = x if color[x] == c: c += 1 color[y] = c c += 1 q.append(y) res = [] for a, b in ab: if a == parent[b]: res.append(color[b]) else: res.append(color[a]) k = max(color) print(k) print(('\n'.join(map(str, res)))) if __name__ == '__main__': main()
60
45
1,590
996
# 2019-11-24 20:59:47(JST) import sys def main(): n = int(sys.stdin.readline().rstrip()) m = list(map(int, sys.stdin.read().split())) ab = list(zip(m, m)) # 2回以上使えるようにlist化 graph = [[] for _ in range(n + 1)] for a, b in ab: graph[a].append(b) graph[b].append(a) root = 1 parent = [None] * (n + 1) # treeなのでループがないため、parentが定義できる checked = [] to_check = [root] # dfs: depth first search では stack # bfs: breadth first search では queueを使う # 今回は stack while to_check: x = to_check.pop() # stackから要素を取り除き、xにset for y in graph[x]: # xから直接つながっているverticesについて if y == parent[x]: continue # yがxの親でなければ parent[y] = x # xを親にして to_check.append(y) # 子であるyをto_checkにstackしていく checked.append(x) # 探索が終わったらvertexを記録 color = [None] * (n + 1) # 初期状態ではなにも塗らないのがNG # vertexに色を、色1から始めて一つ塗ったら色2, 色3,...と変えて塗っていく # その際、色iがngだったらその色iを跳ばして色i+1,色i+2,...と塗っていく(ngは親の色) for x in checked: # checkされた順になっている ng = color[x] c = 1 for y in graph[x]: if y == parent[x]: continue if c == ng: c += 1 color[y] = c c += 1 res = [] for a, b in ab: if a == parent[b]: res.append(color[b]) else: # 木なので parent[a] == b res.append(color[a]) print((max(res))) print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
import sys from collections import deque def main(): n = int(sys.stdin.readline().rstrip()) ab = list(map(int, sys.stdin.read().split())) ab = list(zip(ab, ab)) G = [[] for _ in range(n + 1)] for a, b in ab: G[a].append(b) G[b].append(a) root = 1 q = deque() q.append(root) parent = [None] * (n + 1) color = [0] * (n + 1) # color[y]はx = parent[y]としてcolor[x] に依存する。 while q: x = q.popleft() c = 1 for y in G[x]: if y == parent[x]: continue parent[y] = x if color[x] == c: c += 1 color[y] = c c += 1 q.append(y) res = [] for a, b in ab: if a == parent[b]: res.append(color[b]) else: res.append(color[a]) k = max(color) print(k) print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
false
25
[ "-# 2019-11-24 20:59:47(JST)", "+from collections import deque", "- m = list(map(int, sys.stdin.read().split()))", "- ab = list(zip(m, m)) # 2回以上使えるようにlist化", "- graph = [[] for _ in range(n + 1)]", "+ ab = list(map(int, sys.stdin.read().split()))", "+ ab = list(zip(ab, ab))", "+ G = [[] for _ in range(n + 1)]", "- graph[a].append(b)", "- graph[b].append(a)", "+ G[a].append(b)", "+ G[b].append(a)", "+ q = deque()", "+ q.append(root)", "- # treeなのでループがないため、parentが定義できる", "- checked = []", "- to_check = [root]", "- # dfs: depth first search では stack", "- # bfs: breadth first search では queueを使う", "- # 今回は stack", "- while to_check:", "- x = to_check.pop()", "- # stackから要素を取り除き、xにset", "- for y in graph[x]: # xから直接つながっているverticesについて", "+ color = [0] * (n + 1) # color[y]はx = parent[y]としてcolor[x] に依存する。", "+ while q:", "+ x = q.popleft()", "+ c = 1", "+ for y in G[x]:", "- # yがxの親でなければ", "- parent[y] = x # xを親にして", "- to_check.append(y) # 子であるyをto_checkにstackしていく", "- checked.append(x) # 探索が終わったらvertexを記録", "- color = [None] * (n + 1) # 初期状態ではなにも塗らないのがNG", "- # vertexに色を、色1から始めて一つ塗ったら色2, 色3,...と変えて塗っていく", "- # その際、色iがngだったらその色iを跳ばして色i+1,色i+2,...と塗っていく(ngは親の色)", "- for x in checked: # checkされた順になっている", "- ng = color[x]", "- c = 1", "- for y in graph[x]:", "- if y == parent[x]:", "- continue", "- if c == ng:", "+ parent[y] = x", "+ if color[x] == c:", "+ q.append(y)", "- else: # 木なので parent[a] == b", "+ else:", "- print((max(res)))", "+ k = max(color)", "+ print(k)" ]
false
0.100436
0.104387
0.962143
[ "s449078889", "s609259844" ]
u150984829
p02268
python
s906063514
s778160211
100
40
16,740
18,460
Accepted
Accepted
60
import bisect n = int(eval(input())) A = list(map(int, input().split())) eval(input()) k = 0 for e in map(int, input().split()): i = bisect.bisect_left(A, e) if i < n and A[i] == e: k += 1 print(k)
def m(): eval(input());s=set(input().split()) eval(input());print((len(s&set(input().split())))) if'__main__'==__name__:m()
9
4
203
115
import bisect n = int(eval(input())) A = list(map(int, input().split())) eval(input()) k = 0 for e in map(int, input().split()): i = bisect.bisect_left(A, e) if i < n and A[i] == e: k += 1 print(k)
def m(): eval(input()) s = set(input().split()) eval(input()) print((len(s & set(input().split())))) if "__main__" == __name__: m()
false
55.555556
[ "-import bisect", "+def m():", "+ eval(input())", "+ s = set(input().split())", "+ eval(input())", "+ print((len(s & set(input().split()))))", "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "-eval(input())", "-k = 0", "-for e in map(int, input().split()):", "- i = bisect.bisect_left(A, e)", "- if i < n and A[i] == e:", "- k += 1", "-print(k)", "+", "+if \"__main__\" == __name__:", "+ m()" ]
false
0.039357
0.038562
1.02062
[ "s906063514", "s778160211" ]
u899909022
p03013
python
s121442627
s684233633
189
174
6,876
6,900
Accepted
Accepted
7.94
n,m=list(map(int,input().split())) MOD = 1000000007 D=[0] * (n + 1) for _ in range(m): D[int(eval(input()))] = -1 for i in range(n+1): if D[i] == -1: continue if i in (0, 1): D[i] = 1 continue if D[i-1] != -1: D[i] += D[i-1] if D[i-2] != -1: D[i] += D[i-2] D[i]%=MOD print((D[i] % MOD))
n,m=list(map(int,input().split())) D=[1] * (n + 1) for _ in range(m): D[int(eval(input()))] = 0 for i in range(n+1): if D[i] == 0 or i < 2: continue D[i] = (D[i-1] + D[i-2]) % 1000000007 print((D[i]))
17
9
353
215
n, m = list(map(int, input().split())) MOD = 1000000007 D = [0] * (n + 1) for _ in range(m): D[int(eval(input()))] = -1 for i in range(n + 1): if D[i] == -1: continue if i in (0, 1): D[i] = 1 continue if D[i - 1] != -1: D[i] += D[i - 1] if D[i - 2] != -1: D[i] += D[i - 2] D[i] %= MOD print((D[i] % MOD))
n, m = list(map(int, input().split())) D = [1] * (n + 1) for _ in range(m): D[int(eval(input()))] = 0 for i in range(n + 1): if D[i] == 0 or i < 2: continue D[i] = (D[i - 1] + D[i - 2]) % 1000000007 print((D[i]))
false
47.058824
[ "-MOD = 1000000007", "-D = [0] * (n + 1)", "+D = [1] * (n + 1)", "- D[int(eval(input()))] = -1", "+ D[int(eval(input()))] = 0", "- if D[i] == -1:", "+ if D[i] == 0 or i < 2:", "- if i in (0, 1):", "- D[i] = 1", "- continue", "- if D[i - 1] != -1:", "- D[i] += D[i - 1]", "- if D[i - 2] != -1:", "- D[i] += D[i - 2]", "- D[i] %= MOD", "-print((D[i] % MOD))", "+ D[i] = (D[i - 1] + D[i - 2]) % 1000000007", "+print((D[i]))" ]
false
0.036791
0.093386
0.39397
[ "s121442627", "s684233633" ]
u251899209
p02722
python
s411859064
s525413152
719
344
3,064
3,064
Accepted
Accepted
52.16
def check(i): tot=k while(tot%i==0): tot//=i if(tot%i==1): setl.add(i) import math k=int(eval(input())) if(k==2): print((1)) exit() setl = set() setl.add(k); setl.add(k-1) for x in range(2,int(math.sqrt(k))+1): check(x) check(k//x) print((len(setl)))
def check(i): tot=k pw=0 while(tot%i==0): tot//=i pw+=1 if(tot%i==1): other = tot//i if(pw==0 and other>=2 and other<=k): setl.add(other) setl.add(i) import math k=int(eval(input())) if(k==2): print((1)) exit() setl = set() setl.add(k); setl.add(k-1) for x in range(2,int(math.sqrt(k))+1): check(x) # check(k//x) print((len(setl)))
17
23
267
365
def check(i): tot = k while tot % i == 0: tot //= i if tot % i == 1: setl.add(i) import math k = int(eval(input())) if k == 2: print((1)) exit() setl = set() setl.add(k) setl.add(k - 1) for x in range(2, int(math.sqrt(k)) + 1): check(x) check(k // x) print((len(setl)))
def check(i): tot = k pw = 0 while tot % i == 0: tot //= i pw += 1 if tot % i == 1: other = tot // i if pw == 0 and other >= 2 and other <= k: setl.add(other) setl.add(i) import math k = int(eval(input())) if k == 2: print((1)) exit() setl = set() setl.add(k) setl.add(k - 1) for x in range(2, int(math.sqrt(k)) + 1): check(x) # check(k//x) print((len(setl)))
false
26.086957
[ "+ pw = 0", "+ pw += 1", "+ other = tot // i", "+ if pw == 0 and other >= 2 and other <= k:", "+ setl.add(other)", "- check(k // x)", "+ # check(k//x)" ]
false
0.148667
0.254988
0.583035
[ "s411859064", "s525413152" ]
u832039789
p03863
python
s147284817
s423277930
58
50
3,444
5,492
Accepted
Accepted
13.79
s = eval(input()) t = '' for c in s: if c in (s[0],s[-1]): t += c r = len(t) for c,d in zip(t[:-1],t[1:]): if c==d: r += 1 if len(s)%2==r%2: print('Second') else: print('First')
s = eval(input()) t = [i for i in s if i in (s[0],s[-1])] r = len(t) for c,d in zip(t[:-1],t[1:]): r += c==d print(('Second' if len(s)%2==r%2 else 'First'))
13
6
216
158
s = eval(input()) t = "" for c in s: if c in (s[0], s[-1]): t += c r = len(t) for c, d in zip(t[:-1], t[1:]): if c == d: r += 1 if len(s) % 2 == r % 2: print("Second") else: print("First")
s = eval(input()) t = [i for i in s if i in (s[0], s[-1])] r = len(t) for c, d in zip(t[:-1], t[1:]): r += c == d print(("Second" if len(s) % 2 == r % 2 else "First"))
false
53.846154
[ "-t = \"\"", "-for c in s:", "- if c in (s[0], s[-1]):", "- t += c", "+t = [i for i in s if i in (s[0], s[-1])]", "- if c == d:", "- r += 1", "-if len(s) % 2 == r % 2:", "- print(\"Second\")", "-else:", "- print(\"First\")", "+ r += c == d", "+print((\"Second\" if len(s) % 2 == r % 2 else \"First\"))" ]
false
0.044339
0.040593
1.092283
[ "s147284817", "s423277930" ]
u912237403
p00043
python
s296595059
s294805589
60
30
4,332
4,276
Accepted
Accepted
50
NUM="0123456789" def atama(x): return [e for e in set(x) if x.count(e)>=2] def koutu(x,i): return x.count(i)>=3 def shuntu(x,i): return i<8 and x.count(i)>0 and x.count(i+1)>0 and x.count(i+2)>0 def make(x): return [int(c) for c in x] def check(x): for e in set(x): if koutu(x,e): y = [NUM[e]*3] x1=x+[] x1.remove(e) x1.remove(e) x1.remove(e) if len(x1)==0: return y else: y1 = check(x1) if len(y1)>0: return y+y1 elif shuntu(x,e): x1=x+[] y = [NUM[e:e+3]] x1.remove(e) x1.remove(e+1) x1.remove(e+2) if len(x1)==0: return y else: y1 = check(x1) if len(y1)>0: return y+y1 return "" try: while True: s = input() y = [] for e in NUM[1:]: if s.count(e)>=4: continue x = make(s+e) for e0 in atama(x): s0= [ NUM[e0]*2] x1 = x+[] x1.remove(e0) x1.remove(e0) s0 += check(x1) if len(s0)==5: y.append(e) break if len(y)==0: print(0) else: for e in y: print(e, end=' ') print() except: pass
def check(x,j=1): if sum(x)==0: return True for i in range(j,10): y = x[:] if y[i]>=3: y[i] -= 3 if check(y,i): return True y = x[:] if i<8 and y[i]>0 and y[i+1]>0 and y[i+2]>0: y[i] -= 1 y[i+1] -= 1 y[i+2] -= 1 if check(y,i): return True return False while True: c = [0]*10 try: for e in map(int,input()): c[e] += 1 except: break f = False for i in range(1,10): c1=c[:] if c1[i]>=4: continue else: c1[i]+=1 atama = [j for j,e in enumerate(c1) if e>=2] for e in atama: c1[e]-=2 if check(c1): f = True print(i, end=' ') break c1[e]+=2 if f: print() else: print(0)
61
38
1,469
889
NUM = "0123456789" def atama(x): return [e for e in set(x) if x.count(e) >= 2] def koutu(x, i): return x.count(i) >= 3 def shuntu(x, i): return i < 8 and x.count(i) > 0 and x.count(i + 1) > 0 and x.count(i + 2) > 0 def make(x): return [int(c) for c in x] def check(x): for e in set(x): if koutu(x, e): y = [NUM[e] * 3] x1 = x + [] x1.remove(e) x1.remove(e) x1.remove(e) if len(x1) == 0: return y else: y1 = check(x1) if len(y1) > 0: return y + y1 elif shuntu(x, e): x1 = x + [] y = [NUM[e : e + 3]] x1.remove(e) x1.remove(e + 1) x1.remove(e + 2) if len(x1) == 0: return y else: y1 = check(x1) if len(y1) > 0: return y + y1 return "" try: while True: s = input() y = [] for e in NUM[1:]: if s.count(e) >= 4: continue x = make(s + e) for e0 in atama(x): s0 = [NUM[e0] * 2] x1 = x + [] x1.remove(e0) x1.remove(e0) s0 += check(x1) if len(s0) == 5: y.append(e) break if len(y) == 0: print(0) else: for e in y: print(e, end=" ") print() except: pass
def check(x, j=1): if sum(x) == 0: return True for i in range(j, 10): y = x[:] if y[i] >= 3: y[i] -= 3 if check(y, i): return True y = x[:] if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0: y[i] -= 1 y[i + 1] -= 1 y[i + 2] -= 1 if check(y, i): return True return False while True: c = [0] * 10 try: for e in map(int, input()): c[e] += 1 except: break f = False for i in range(1, 10): c1 = c[:] if c1[i] >= 4: continue else: c1[i] += 1 atama = [j for j, e in enumerate(c1) if e >= 2] for e in atama: c1[e] -= 2 if check(c1): f = True print(i, end=" ") break c1[e] += 2 if f: print() else: print(0)
false
37.704918
[ "-NUM = \"0123456789\"", "+def check(x, j=1):", "+ if sum(x) == 0:", "+ return True", "+ for i in range(j, 10):", "+ y = x[:]", "+ if y[i] >= 3:", "+ y[i] -= 3", "+ if check(y, i):", "+ return True", "+ y = x[:]", "+ if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:", "+ y[i] -= 1", "+ y[i + 1] -= 1", "+ y[i + 2] -= 1", "+ if check(y, i):", "+ return True", "+ return False", "-def atama(x):", "- return [e for e in set(x) if x.count(e) >= 2]", "-", "-", "-def koutu(x, i):", "- return x.count(i) >= 3", "-", "-", "-def shuntu(x, i):", "- return i < 8 and x.count(i) > 0 and x.count(i + 1) > 0 and x.count(i + 2) > 0", "-", "-", "-def make(x):", "- return [int(c) for c in x]", "-", "-", "-def check(x):", "- for e in set(x):", "- if koutu(x, e):", "- y = [NUM[e] * 3]", "- x1 = x + []", "- x1.remove(e)", "- x1.remove(e)", "- x1.remove(e)", "- if len(x1) == 0:", "- return y", "- else:", "- y1 = check(x1)", "- if len(y1) > 0:", "- return y + y1", "- elif shuntu(x, e):", "- x1 = x + []", "- y = [NUM[e : e + 3]]", "- x1.remove(e)", "- x1.remove(e + 1)", "- x1.remove(e + 2)", "- if len(x1) == 0:", "- return y", "- else:", "- y1 = check(x1)", "- if len(y1) > 0:", "- return y + y1", "- return \"\"", "-", "-", "-try:", "- while True:", "- s = input()", "- y = []", "- for e in NUM[1:]:", "- if s.count(e) >= 4:", "- continue", "- x = make(s + e)", "- for e0 in atama(x):", "- s0 = [NUM[e0] * 2]", "- x1 = x + []", "- x1.remove(e0)", "- x1.remove(e0)", "- s0 += check(x1)", "- if len(s0) == 5:", "- y.append(e)", "- break", "- if len(y) == 0:", "- print(0)", "+while True:", "+ c = [0] * 10", "+ try:", "+ for e in map(int, input()):", "+ c[e] += 1", "+ except:", "+ break", "+ f = False", "+ for i in range(1, 10):", "+ c1 = c[:]", "+ if c1[i] >= 4:", "+ continue", "- for e in y:", "- print(e, end=\" \")", "- print()", "-except:", "- pass", "+ c1[i] += 1", "+ atama = [j for j, e in enumerate(c1) if e >= 2]", "+ for e in atama:", "+ c1[e] -= 2", "+ if check(c1):", "+ f = True", "+ print(i, end=\" \")", "+ break", "+ c1[e] += 2", "+ if f:", "+ print()", "+ else:", "+ print(0)" ]
false
0.072709
0.189396
0.3839
[ "s296595059", "s294805589" ]
u312025627
p03627
python
s247128888
s833512201
402
277
78,616
71,832
Accepted
Accepted
31.09
def main(): N = int(input()) A = [int(i) for i in input().split()] from collections import Counter c = Counter(A) if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \ and c.most_common()[0][1] < 4: return print(0) d = [i[0] for i in c.items() if i[1] >= 2] if d: d.sort() e = [i[0] for i in c.items() if i[1] >= 4] if e: e.sort() if d and e: print(max(d[-1] * d[-2], e[-1]*e[-1])) elif d: print(d[-1] * d[-2]) else: print(e[-1]*e[-1]) if __name__ == '__main__': main()
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] from collections import Counter c = Counter(A) most = c.most_common() if most[0][1] >= 4: ans = [] for k, v in most: if v >= 4: ans.append(k) ans.append(k) elif v >= 2: ans.append(k) ans.sort() print((ans[-1]*ans[-2])) elif most[0][1] >= 2 and most[1][1] >= 2: ans = [] for k, v in most: if v >= 2: ans.append(k) ans.sort() print((ans[-1]*ans[-2])) else: print((0)) if __name__ == '__main__': main()
24
29
615
699
def main(): N = int(input()) A = [int(i) for i in input().split()] from collections import Counter c = Counter(A) if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) and c.most_common()[0][ 1 ] < 4: return print(0) d = [i[0] for i in c.items() if i[1] >= 2] if d: d.sort() e = [i[0] for i in c.items() if i[1] >= 4] if e: e.sort() if d and e: print(max(d[-1] * d[-2], e[-1] * e[-1])) elif d: print(d[-1] * d[-2]) else: print(e[-1] * e[-1]) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] from collections import Counter c = Counter(A) most = c.most_common() if most[0][1] >= 4: ans = [] for k, v in most: if v >= 4: ans.append(k) ans.append(k) elif v >= 2: ans.append(k) ans.sort() print((ans[-1] * ans[-2])) elif most[0][1] >= 2 and most[1][1] >= 2: ans = [] for k, v in most: if v >= 2: ans.append(k) ans.sort() print((ans[-1] * ans[-2])) else: print((0)) if __name__ == "__main__": main()
false
17.241379
[ "- N = int(input())", "+ N = int(eval(input()))", "- if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) and c.most_common()[0][", "- 1", "- ] < 4:", "- return print(0)", "- d = [i[0] for i in c.items() if i[1] >= 2]", "- if d:", "- d.sort()", "- e = [i[0] for i in c.items() if i[1] >= 4]", "- if e:", "- e.sort()", "- if d and e:", "- print(max(d[-1] * d[-2], e[-1] * e[-1]))", "- elif d:", "- print(d[-1] * d[-2])", "+ most = c.most_common()", "+ if most[0][1] >= 4:", "+ ans = []", "+ for k, v in most:", "+ if v >= 4:", "+ ans.append(k)", "+ ans.append(k)", "+ elif v >= 2:", "+ ans.append(k)", "+ ans.sort()", "+ print((ans[-1] * ans[-2]))", "+ elif most[0][1] >= 2 and most[1][1] >= 2:", "+ ans = []", "+ for k, v in most:", "+ if v >= 2:", "+ ans.append(k)", "+ ans.sort()", "+ print((ans[-1] * ans[-2]))", "- print(e[-1] * e[-1])", "+ print((0))" ]
false
0.039034
0.041612
0.938046
[ "s247128888", "s833512201" ]
u006880673
p03665
python
s881774794
s613718020
180
74
42,136
67,500
Accepted
Accepted
58.89
from scipy.special import comb N, P = list(map(int, input().split())) A = list(map(int, input().split())) MAX_C = 100 # def comb_dp(): # """ # dpテーブルを作ってnCkを計算. # modのpは素数でなくてよい. # 1 <= k <= n <= 2000程度 # O(MAX_C ** 2). # """ # Com = [[0]*MAX_C for _ in range(MAX_C)] # for i in range(1, MAX_C): # # iC0 = 1 # Com[i][0] = 1 # for j in range(1, MAX_C): # # iCj = i-1_C_j-1 + i-1_C_j mod p # Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) # return Com # Com = comb_dp() # print(Com[2][1]) # print(Com[2][2]) if P == 0: is_even = [A[i]%2==0 for i in range(N)] num_e = is_even.count(True) num_o = N-num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e+1): tmp1 += comb(num_e, i, exact=True) for i in range(0, num_o+1, 2): tmp2 += comb(num_o, i, exact=True) print((tmp1*tmp2)) else: is_even = [A[i]%2==0 for i in range(N)] num_e = is_even.count(True) num_o = N-num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e+1): tmp1 += comb(num_e, i, exact=True) for i in range(1, num_o+1, 2): tmp2 += comb(num_o, i, exact=True) print((tmp1*tmp2))
N, P = list(map(int, input().split())) A = list(map(int, input().split())) MAX_C = 100 def comb_dp(): """ dpテーブルを作ってnCkを計算. modのpは素数でなくてよい. 1 <= k <= n <= 2000程度 O(MAX_C ** 2). """ Com = [[0]*MAX_C for _ in range(MAX_C)] Com[0][0] = 1 for i in range(1, MAX_C): # iC0 = 1 Com[i][0] = 1 for j in range(1, MAX_C): # iCj = i-1_C_j-1 + i-1_C_j mod p Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) return Com Com = comb_dp() if P == 0: is_even = [A[i]%2==0 for i in range(N)] num_e = is_even.count(True) num_o = N-num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e+1): tmp1 += Com[num_e][i] for i in range(0, num_o+1, 2): tmp2 += Com[num_o][i] print((tmp1*tmp2)) else: is_even = [A[i]%2==0 for i in range(N)] num_e = is_even.count(True) num_o = N-num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e+1): tmp1 += Com[num_e][i] for i in range(1, num_o+1, 2): tmp2 += Com[num_o][i] print((tmp1*tmp2))
46
44
1,243
1,106
from scipy.special import comb N, P = list(map(int, input().split())) A = list(map(int, input().split())) MAX_C = 100 # def comb_dp(): # """ # dpテーブルを作ってnCkを計算. # modのpは素数でなくてよい. # 1 <= k <= n <= 2000程度 # O(MAX_C ** 2). # """ # Com = [[0]*MAX_C for _ in range(MAX_C)] # for i in range(1, MAX_C): # # iC0 = 1 # Com[i][0] = 1 # for j in range(1, MAX_C): # # iCj = i-1_C_j-1 + i-1_C_j mod p # Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) # return Com # Com = comb_dp() # print(Com[2][1]) # print(Com[2][2]) if P == 0: is_even = [A[i] % 2 == 0 for i in range(N)] num_e = is_even.count(True) num_o = N - num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e + 1): tmp1 += comb(num_e, i, exact=True) for i in range(0, num_o + 1, 2): tmp2 += comb(num_o, i, exact=True) print((tmp1 * tmp2)) else: is_even = [A[i] % 2 == 0 for i in range(N)] num_e = is_even.count(True) num_o = N - num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e + 1): tmp1 += comb(num_e, i, exact=True) for i in range(1, num_o + 1, 2): tmp2 += comb(num_o, i, exact=True) print((tmp1 * tmp2))
N, P = list(map(int, input().split())) A = list(map(int, input().split())) MAX_C = 100 def comb_dp(): """ dpテーブルを作ってnCkを計算. modのpは素数でなくてよい. 1 <= k <= n <= 2000程度 O(MAX_C ** 2). """ Com = [[0] * MAX_C for _ in range(MAX_C)] Com[0][0] = 1 for i in range(1, MAX_C): # iC0 = 1 Com[i][0] = 1 for j in range(1, MAX_C): # iCj = i-1_C_j-1 + i-1_C_j mod p Com[i][j] = Com[i - 1][j - 1] + Com[i - 1][j] return Com Com = comb_dp() if P == 0: is_even = [A[i] % 2 == 0 for i in range(N)] num_e = is_even.count(True) num_o = N - num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e + 1): tmp1 += Com[num_e][i] for i in range(0, num_o + 1, 2): tmp2 += Com[num_o][i] print((tmp1 * tmp2)) else: is_even = [A[i] % 2 == 0 for i in range(N)] num_e = is_even.count(True) num_o = N - num_e tmp1 = 0 tmp2 = 0 for i in range(0, num_e + 1): tmp1 += Com[num_e][i] for i in range(1, num_o + 1, 2): tmp2 += Com[num_o][i] print((tmp1 * tmp2))
false
4.347826
[ "-from scipy.special import comb", "-", "-# def comb_dp():", "-# \"\"\"", "-# dpテーブルを作ってnCkを計算.", "-# modのpは素数でなくてよい.", "-# 1 <= k <= n <= 2000程度", "-# O(MAX_C ** 2).", "-# \"\"\"", "-# Com = [[0]*MAX_C for _ in range(MAX_C)]", "-# for i in range(1, MAX_C):", "-# # iC0 = 1", "-# Com[i][0] = 1", "-# for j in range(1, MAX_C):", "-# # iCj = i-1_C_j-1 + i-1_C_j mod p", "-# Com[i][j] = (Com[i-1][j-1] + Com[i-1][j])", "-# return Com", "-# Com = comb_dp()", "-# print(Com[2][1])", "-# print(Com[2][2])", "+", "+", "+def comb_dp():", "+ \"\"\"", "+ dpテーブルを作ってnCkを計算.", "+ modのpは素数でなくてよい.", "+ 1 <= k <= n <= 2000程度", "+ O(MAX_C ** 2).", "+ \"\"\"", "+ Com = [[0] * MAX_C for _ in range(MAX_C)]", "+ Com[0][0] = 1", "+ for i in range(1, MAX_C):", "+ # iC0 = 1", "+ Com[i][0] = 1", "+ for j in range(1, MAX_C):", "+ # iCj = i-1_C_j-1 + i-1_C_j mod p", "+ Com[i][j] = Com[i - 1][j - 1] + Com[i - 1][j]", "+ return Com", "+", "+", "+Com = comb_dp()", "- tmp1 += comb(num_e, i, exact=True)", "+ tmp1 += Com[num_e][i]", "- tmp2 += comb(num_o, i, exact=True)", "+ tmp2 += Com[num_o][i]", "- tmp1 += comb(num_e, i, exact=True)", "+ tmp1 += Com[num_e][i]", "- tmp2 += comb(num_o, i, exact=True)", "+ tmp2 += Com[num_o][i]" ]
false
1.13483
0.042273
26.845087
[ "s881774794", "s613718020" ]
u625963200
p03599
python
s480170470
s592009178
119
101
3,188
3,188
Accepted
Accepted
15.13
A,B,C,D,E,F=list(map(int,input().split())) water=set() for a in range(0,F+1,100*A): for b in range(0,F+1,100*B): if a+b<=F: water.add(a+b) water=sorted(list(water)) suger=set() for c in range(0,F+1,C): for d in range(0,F+1,D): if c+d<=F: suger.add(c+d) suger=sorted(list(suger)) ans,answater,anssuger=0,0,0 for w in water: for s in suger: if (w//100)*E<s or w+s>F: break if w+s!=0: if ans<=(100*s)/(w+s): answater,anssuger=w+s,s ans=(100*s)/(w+s) print((answater,anssuger))
A,B,C,D,E,F=list(map(int,input().split())) water=set() for a in range(0,F+1,100*A): for b in range(0,F+1,100*B): if a+b<=F: water.add(a+b) water=sorted(list(water)) suger=set() for c in range(0,F+1,C): for d in range(0,F+1,D): if c+d<=F: suger.add(c+d) suger=sorted(list(suger)) kosa,ans1,ans2=0,0,0 for w in water: for s in suger: if (w//100)*E<s or w+s>F: break if w+s!=0 and kosa<=(100*s) / (w+s): kosa=(100*s) / (w+s) ans1,ans2=w+s,s print((ans1,ans2))
23
21
534
504
A, B, C, D, E, F = list(map(int, input().split())) water = set() for a in range(0, F + 1, 100 * A): for b in range(0, F + 1, 100 * B): if a + b <= F: water.add(a + b) water = sorted(list(water)) suger = set() for c in range(0, F + 1, C): for d in range(0, F + 1, D): if c + d <= F: suger.add(c + d) suger = sorted(list(suger)) ans, answater, anssuger = 0, 0, 0 for w in water: for s in suger: if (w // 100) * E < s or w + s > F: break if w + s != 0: if ans <= (100 * s) / (w + s): answater, anssuger = w + s, s ans = (100 * s) / (w + s) print((answater, anssuger))
A, B, C, D, E, F = list(map(int, input().split())) water = set() for a in range(0, F + 1, 100 * A): for b in range(0, F + 1, 100 * B): if a + b <= F: water.add(a + b) water = sorted(list(water)) suger = set() for c in range(0, F + 1, C): for d in range(0, F + 1, D): if c + d <= F: suger.add(c + d) suger = sorted(list(suger)) kosa, ans1, ans2 = 0, 0, 0 for w in water: for s in suger: if (w // 100) * E < s or w + s > F: break if w + s != 0 and kosa <= (100 * s) / (w + s): kosa = (100 * s) / (w + s) ans1, ans2 = w + s, s print((ans1, ans2))
false
8.695652
[ "-ans, answater, anssuger = 0, 0, 0", "+kosa, ans1, ans2 = 0, 0, 0", "- if w + s != 0:", "- if ans <= (100 * s) / (w + s):", "- answater, anssuger = w + s, s", "- ans = (100 * s) / (w + s)", "-print((answater, anssuger))", "+ if w + s != 0 and kosa <= (100 * s) / (w + s):", "+ kosa = (100 * s) / (w + s)", "+ ans1, ans2 = w + s, s", "+print((ans1, ans2))" ]
false
0.063532
0.215762
0.294455
[ "s480170470", "s592009178" ]
u588341295
p03291
python
s273371696
s484050471
1,101
525
18,992
27,612
Accepted
Accepted
52.32
# -*- coding: utf-8 -*- """ 参考:http://tutuz.hateblo.jp/entry/2018/08/06/074104    https://www.hamayanhamayan.com/entry/2018/08/05/232127 ・別解 ・予め必要なA,C,?の個数は集めておく。 ・Bの位置を決めて、4つの選び方パターンを全部数え上げる。 ・3べきの計算はpowの第三引数modで高速化 """ MOD = 10 ** 9 + 7 S = eval(input()) # あるBの位置よりも左にあるAと?の個数 A, LQ = [0] * len(S), [0] * len(S) for i in range(len(S)-1): a = lq = 0 if S[i] == 'A': a += 1 if S[i] == '?': lq += 1 A[i+1] = A[i] + a LQ[i+1] = LQ[i] + lq # あるBの位置よりも右にあるCと?の個数 C, RQ = [0] * len(S), [0] * len(S) for i in range(len(S)-1, 0, -1): c = rq = 0 if S[i] == 'C': c += 1 if S[i] == '?': rq += 1 C[i-1] = C[i] + c RQ[i-1] = RQ[i] + rq ans = 0 for i in range(len(S)): if S[i] == '?' or S[i] == 'B': # (A,B,C) と選ぶ場合(後ろの3べきは使わなかった?の分) case1 = (A[i] * C[i] * pow(3, LQ[i] + RQ[i], MOD)) % MOD # (A,B,?) と選ぶ場合 case2 = (A[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD # (?,B,C) と選ぶ場合 case3 = (LQ[i] * C[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD # (?,B,?) と選ぶ場合 case4 = (LQ[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 2, 0), MOD)) % MOD # 全部足し合わせてMOD ans = (ans + case1 + case2 + case3 + case4) % MOD print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 S = input() N = len(S) # dp[i][j] := i文字目まで見て、ABCのうちj文字目まで選んだ状態の通り数 dp = list2d(N+1, 4, 0) dp[0][0] = 1 for i in range(N): s = S[i] for j in range(4): # 今回の文字を選ばない if s == '?': # ?は3通り遷移させる dp[i+1][j] += dp[i][j] * 3 dp[i+1][j] %= MOD else: dp[i+1][j] += dp[i][j] dp[i+1][j] %= MOD # 今回の文字を選ぶ if j < 3: # 条件に合わせて次の文字へ進む if s == '?' or s == 'A' and j == 0 \ or s == 'B' and j == 1 \ or s == 'C' and j == 2: dp[i+1][j+1] += dp[i][j] dp[i+1][j+1] %= MOD # N文字目まで見て、3文字選び終わっている通り数 print(dp[N][3])
50
47
1,316
1,429
# -*- coding: utf-8 -*- """ 参考:http://tutuz.hateblo.jp/entry/2018/08/06/074104    https://www.hamayanhamayan.com/entry/2018/08/05/232127 ・別解 ・予め必要なA,C,?の個数は集めておく。 ・Bの位置を決めて、4つの選び方パターンを全部数え上げる。 ・3べきの計算はpowの第三引数modで高速化 """ MOD = 10**9 + 7 S = eval(input()) # あるBの位置よりも左にあるAと?の個数 A, LQ = [0] * len(S), [0] * len(S) for i in range(len(S) - 1): a = lq = 0 if S[i] == "A": a += 1 if S[i] == "?": lq += 1 A[i + 1] = A[i] + a LQ[i + 1] = LQ[i] + lq # あるBの位置よりも右にあるCと?の個数 C, RQ = [0] * len(S), [0] * len(S) for i in range(len(S) - 1, 0, -1): c = rq = 0 if S[i] == "C": c += 1 if S[i] == "?": rq += 1 C[i - 1] = C[i] + c RQ[i - 1] = RQ[i] + rq ans = 0 for i in range(len(S)): if S[i] == "?" or S[i] == "B": # (A,B,C) と選ぶ場合(後ろの3べきは使わなかった?の分) case1 = (A[i] * C[i] * pow(3, LQ[i] + RQ[i], MOD)) % MOD # (A,B,?) と選ぶ場合 case2 = (A[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD # (?,B,C) と選ぶ場合 case3 = (LQ[i] * C[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD # (?,B,?) と選ぶ場合 case4 = (LQ[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 2, 0), MOD)) % MOD # 全部足し合わせてMOD ans = (ans + case1 + case2 + case3 + case4) % MOD print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 S = input() N = len(S) # dp[i][j] := i文字目まで見て、ABCのうちj文字目まで選んだ状態の通り数 dp = list2d(N + 1, 4, 0) dp[0][0] = 1 for i in range(N): s = S[i] for j in range(4): # 今回の文字を選ばない if s == "?": # ?は3通り遷移させる dp[i + 1][j] += dp[i][j] * 3 dp[i + 1][j] %= MOD else: dp[i + 1][j] += dp[i][j] dp[i + 1][j] %= MOD # 今回の文字を選ぶ if j < 3: # 条件に合わせて次の文字へ進む if ( s == "?" or s == "A" and j == 0 or s == "B" and j == 1 or s == "C" and j == 2 ): dp[i + 1][j + 1] += dp[i][j] dp[i + 1][j + 1] %= MOD # N文字目まで見て、3文字選び終わっている通り数 print(dp[N][3])
false
6
[ "-\"\"\"", "-参考:http://tutuz.hateblo.jp/entry/2018/08/06/074104", "-   https://www.hamayanhamayan.com/entry/2018/08/05/232127", "-・別解", "-・予め必要なA,C,?の個数は集めておく。", "-・Bの位置を決めて、4つの選び方パターンを全部数え上げる。", "-・3べきの計算はpowの第三引数modで高速化", "-\"\"\"", "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def list2d(a, b, c):", "+ return [[c] * b for i in range(a)]", "+", "+", "+def list3d(a, b, c, d):", "+ return [[[d] * c for j in range(b)] for i in range(a)]", "+", "+", "+def list4d(a, b, c, d, e):", "+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]", "+", "+", "+def ceil(x, y=1):", "+ return int(-(-x // y))", "+", "+", "+def INT():", "+ return int(input())", "+", "+", "+def MAP():", "+ return map(int, input().split())", "+", "+", "+def LIST(N=None):", "+ return list(MAP()) if N is None else [INT() for i in range(N)]", "+", "+", "+def Yes():", "+ print(\"Yes\")", "+", "+", "+def No():", "+ print(\"No\")", "+", "+", "+def YES():", "+ print(\"YES\")", "+", "+", "+def NO():", "+ print(\"NO\")", "+", "+", "+sys.setrecursionlimit(10**9)", "+INF = 10**18", "-S = eval(input())", "-# あるBの位置よりも左にあるAと?の個数", "-A, LQ = [0] * len(S), [0] * len(S)", "-for i in range(len(S) - 1):", "- a = lq = 0", "- if S[i] == \"A\":", "- a += 1", "- if S[i] == \"?\":", "- lq += 1", "- A[i + 1] = A[i] + a", "- LQ[i + 1] = LQ[i] + lq", "-# あるBの位置よりも右にあるCと?の個数", "-C, RQ = [0] * len(S), [0] * len(S)", "-for i in range(len(S) - 1, 0, -1):", "- c = rq = 0", "- if S[i] == \"C\":", "- c += 1", "- if S[i] == \"?\":", "- rq += 1", "- C[i - 1] = C[i] + c", "- RQ[i - 1] = RQ[i] + rq", "-ans = 0", "-for i in range(len(S)):", "- if S[i] == \"?\" or S[i] == \"B\":", "- # (A,B,C) と選ぶ場合(後ろの3べきは使わなかった?の分)", "- case1 = (A[i] * C[i] * pow(3, LQ[i] + RQ[i], MOD)) % MOD", "- # (A,B,?) と選ぶ場合", "- case2 = (A[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD", "- # (?,B,C) と選ぶ場合", "- case3 = (LQ[i] * C[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0), MOD)) % MOD", "- # (?,B,?) と選ぶ場合", "- case4 = (LQ[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 2, 0), MOD)) % MOD", "- # 全部足し合わせてMOD", "- ans = (ans + case1 + case2 + case3 + case4) % MOD", "-print(ans)", "+S = input()", "+N = len(S)", "+# dp[i][j] := i文字目まで見て、ABCのうちj文字目まで選んだ状態の通り数", "+dp = list2d(N + 1, 4, 0)", "+dp[0][0] = 1", "+for i in range(N):", "+ s = S[i]", "+ for j in range(4):", "+ # 今回の文字を選ばない", "+ if s == \"?\":", "+ # ?は3通り遷移させる", "+ dp[i + 1][j] += dp[i][j] * 3", "+ dp[i + 1][j] %= MOD", "+ else:", "+ dp[i + 1][j] += dp[i][j]", "+ dp[i + 1][j] %= MOD", "+ # 今回の文字を選ぶ", "+ if j < 3:", "+ # 条件に合わせて次の文字へ進む", "+ if (", "+ s == \"?\"", "+ or s == \"A\"", "+ and j == 0", "+ or s == \"B\"", "+ and j == 1", "+ or s == \"C\"", "+ and j == 2", "+ ):", "+ dp[i + 1][j + 1] += dp[i][j]", "+ dp[i + 1][j + 1] %= MOD", "+# N文字目まで見て、3文字選び終わっている通り数", "+print(dp[N][3])" ]
false
0.047382
0.036408
1.301426
[ "s273371696", "s484050471" ]
u978178314
p03559
python
s467916452
s801880927
607
503
107,236
106,340
Accepted
Accepted
17.13
from bisect import bisect from collections import deque N = int(eval(input())) A = list(map(int, input().split())) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) BC_ruiseki = deque([0]) for i, b in enumerate(B): BC_ruiseki.append(BC_ruiseki[i] + N - bisect(C, b)) ans = 0 for a in A: idx = bisect(B, a) ans += BC_ruiseki[-1] - BC_ruiseki[idx] print(ans)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = list(map(int, input().split())) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a = bisect.bisect_left(A, b) c = N-bisect.bisect(C, b) ans += a*c print(ans)
17
13
413
271
from bisect import bisect from collections import deque N = int(eval(input())) A = list(map(int, input().split())) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) BC_ruiseki = deque([0]) for i, b in enumerate(B): BC_ruiseki.append(BC_ruiseki[i] + N - bisect(C, b)) ans = 0 for a in A: idx = bisect(B, a) ans += BC_ruiseki[-1] - BC_ruiseki[idx] print(ans)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = list(map(int, input().split())) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a = bisect.bisect_left(A, b) c = N - bisect.bisect(C, b) ans += a * c print(ans)
false
23.529412
[ "-from bisect import bisect", "-from collections import deque", "+import bisect", "-A = list(map(int, input().split()))", "-B = sorted(list(map(int, input().split())))", "+A = sorted(list(map(int, input().split())))", "+B = list(map(int, input().split()))", "-BC_ruiseki = deque([0])", "-for i, b in enumerate(B):", "- BC_ruiseki.append(BC_ruiseki[i] + N - bisect(C, b))", "-for a in A:", "- idx = bisect(B, a)", "- ans += BC_ruiseki[-1] - BC_ruiseki[idx]", "+for b in B:", "+ a = bisect.bisect_left(A, b)", "+ c = N - bisect.bisect(C, b)", "+ ans += a * c" ]
false
0.042478
0.067121
0.632862
[ "s467916452", "s801880927" ]
u506689504
p03494
python
s832676936
s880430230
19
17
3,060
3,060
Accepted
Accepted
10.53
import math N = int(eval(input())) a = list(map(int, input().split())) A = list(a) min = 10**10 for e in A: m=0 #eが2で割り切れる回数 while e%2==0: e = e/2 m+=1 if min>m: min = m print(min)
n = eval(input()) a = list(map(int, input().split())) ans = float("inf") for i in a: ans = min(ans, len(bin(i)) - bin(i).rfind("1")-1) print(ans)
14
6
218
148
import math N = int(eval(input())) a = list(map(int, input().split())) A = list(a) min = 10**10 for e in A: m = 0 # eが2で割り切れる回数 while e % 2 == 0: e = e / 2 m += 1 if min > m: min = m print(min)
n = eval(input()) a = list(map(int, input().split())) ans = float("inf") for i in a: ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1) print(ans)
false
57.142857
[ "-import math", "-", "-N = int(eval(input()))", "+n = eval(input())", "-A = list(a)", "-min = 10**10", "-for e in A:", "- m = 0 # eが2で割り切れる回数", "- while e % 2 == 0:", "- e = e / 2", "- m += 1", "- if min > m:", "- min = m", "-print(min)", "+ans = float(\"inf\")", "+for i in a:", "+ ans = min(ans, len(bin(i)) - bin(i).rfind(\"1\") - 1)", "+print(ans)" ]
false
0.039642
0.039071
1.0146
[ "s832676936", "s880430230" ]
u201928947
p02564
python
s723344383
s777757697
1,132
942
198,696
214,184
Accepted
Accepted
16.78
from collections import deque class csr: def __init__(self,N,edges): self.start = [0]*(N+1) self.elist = [0]*len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1,N+1): self.start[i] += self.start[i-1] counter = self.start[:] for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class scc_graph: def __init__(self,N): self.N = N self.edges = [] def add_edge(self,v,w): self.edges.append((v,w)) def scc_ids(self): g = csr(self.N,self.edges) now_ord = group_num = 0 visited = deque() low = [0]*self.N order = [-1]*self.N ids = [0]*self.N parent = [-1]*self.N for i in range(self.N): if order[i] == -1: stack = deque() stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(g.start[v],g.start[v+1]): to = g.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v],order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]],low[v]) for i,x in enumerate(ids): ids[i] = group_num-1-x return group_num,ids def scc(self): group_num,ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i,x in enumerate(ids): groups[x].append(i) return groups import sys input = sys.stdin.buffer.readline N,M = list(map(int,input().split())) sg = scc_graph(N) for i in range(M): a,b = list(map(int,input().split())) sg.add_edge(a,b) scc = sg.scc() print((len(scc))) for group in scc: print((str(len(group))+' '+' '.join(map(str,group))))
from collections import deque class csr: def __init__(self,N,edges): self.start = [0]*(N+1) self.elist = [0]*len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1,N+1): self.start[i] += self.start[i-1] counter = self.start[:] for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class scc_graph: def __init__(self,N): self.N = N self.edges = [] def add_edge(self,v,w): self.edges.append((v,w)) def scc_ids(self): g = csr(self.N,self.edges) now_ord = group_num = 0 visited = deque() low = [0]*self.N order = [-1]*self.N ids = [0]*self.N parent = [-1]*self.N for i in range(self.N): if order[i] == -1: stack = deque() stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(g.start[v],g.start[v+1]): to = g.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v],order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]],low[v]) for i,x in enumerate(ids): ids[i] = group_num-1-x return group_num,ids def scc(self): group_num,ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i,x in enumerate(ids): groups[x].append(i) return groups import sys readline = sys.stdin.buffer.readline read = sys.stdin.buffer.read N,M = list(map(int,readline().split())) ab = list(map(int,read().split())) sg = scc_graph(N) it = iter(ab) for a,b in zip(it,it): sg.add_edge(a,b) scc = sg.scc() print((len(scc))) for group in scc: print((str(len(group))+' '+' '.join(map(str,group))))
84
87
2,749
2,806
from collections import deque class csr: def __init__(self, N, edges): self.start = [0] * (N + 1) self.elist = [0] * len(edges) for e in edges: self.start[e[0] + 1] += 1 for i in range(1, N + 1): self.start[i] += self.start[i - 1] counter = self.start[:] for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class scc_graph: def __init__(self, N): self.N = N self.edges = [] def add_edge(self, v, w): self.edges.append((v, w)) def scc_ids(self): g = csr(self.N, self.edges) now_ord = group_num = 0 visited = deque() low = [0] * self.N order = [-1] * self.N ids = [0] * self.N parent = [-1] * self.N for i in range(self.N): if order[i] == -1: stack = deque() stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(g.start[v], g.start[v + 1]): to = g.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups import sys input = sys.stdin.buffer.readline N, M = list(map(int, input().split())) sg = scc_graph(N) for i in range(M): a, b = list(map(int, input().split())) sg.add_edge(a, b) scc = sg.scc() print((len(scc))) for group in scc: print((str(len(group)) + " " + " ".join(map(str, group))))
from collections import deque class csr: def __init__(self, N, edges): self.start = [0] * (N + 1) self.elist = [0] * len(edges) for e in edges: self.start[e[0] + 1] += 1 for i in range(1, N + 1): self.start[i] += self.start[i - 1] counter = self.start[:] for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class scc_graph: def __init__(self, N): self.N = N self.edges = [] def add_edge(self, v, w): self.edges.append((v, w)) def scc_ids(self): g = csr(self.N, self.edges) now_ord = group_num = 0 visited = deque() low = [0] * self.N order = [-1] * self.N ids = [0] * self.N parent = [-1] * self.N for i in range(self.N): if order[i] == -1: stack = deque() stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(g.start[v], g.start[v + 1]): to = g.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups import sys readline = sys.stdin.buffer.readline read = sys.stdin.buffer.read N, M = list(map(int, readline().split())) ab = list(map(int, read().split())) sg = scc_graph(N) it = iter(ab) for a, b in zip(it, it): sg.add_edge(a, b) scc = sg.scc() print((len(scc))) for group in scc: print((str(len(group)) + " " + " ".join(map(str, group))))
false
3.448276
[ "-input = sys.stdin.buffer.readline", "-N, M = list(map(int, input().split()))", "+readline = sys.stdin.buffer.readline", "+read = sys.stdin.buffer.read", "+N, M = list(map(int, readline().split()))", "+ab = list(map(int, read().split()))", "-for i in range(M):", "- a, b = list(map(int, input().split()))", "+it = iter(ab)", "+for a, b in zip(it, it):" ]
false
0.080295
0.03791
2.118057
[ "s723344383", "s777757697" ]
u482019060
p02911
python
s302869668
s531539432
304
241
7,884
11,788
Accepted
Accepted
20.72
N,K,Q=list(map(int,input().split())) ans=[K for i in range(N)] ans=list([x-Q for x in ans]) for i in range(Q): A=int(eval(input())) ans[A-1]=ans[A-1]+1 for i in range(N): if ans[i]>0: print('Yes') else: print('No')
n, k, q = list(map(int, input().split())) a_list = [int(eval(input()))-1 for _ in range(q)] p_list = [k-q for _ in range(n)] for a in a_list: p_list[a] += 1 for p in p_list: if p <= 0: print("No") else: print("Yes")
11
12
231
245
N, K, Q = list(map(int, input().split())) ans = [K for i in range(N)] ans = list([x - Q for x in ans]) for i in range(Q): A = int(eval(input())) ans[A - 1] = ans[A - 1] + 1 for i in range(N): if ans[i] > 0: print("Yes") else: print("No")
n, k, q = list(map(int, input().split())) a_list = [int(eval(input())) - 1 for _ in range(q)] p_list = [k - q for _ in range(n)] for a in a_list: p_list[a] += 1 for p in p_list: if p <= 0: print("No") else: print("Yes")
false
8.333333
[ "-N, K, Q = list(map(int, input().split()))", "-ans = [K for i in range(N)]", "-ans = list([x - Q for x in ans])", "-for i in range(Q):", "- A = int(eval(input()))", "- ans[A - 1] = ans[A - 1] + 1", "-for i in range(N):", "- if ans[i] > 0:", "+n, k, q = list(map(int, input().split()))", "+a_list = [int(eval(input())) - 1 for _ in range(q)]", "+p_list = [k - q for _ in range(n)]", "+for a in a_list:", "+ p_list[a] += 1", "+for p in p_list:", "+ if p <= 0:", "+ print(\"No\")", "+ else:", "- else:", "- print(\"No\")" ]
false
0.04318
0.044507
0.970192
[ "s302869668", "s531539432" ]
u628581330
p02813
python
s333342165
s199709271
35
27
8,052
8,052
Accepted
Accepted
22.86
n = int(eval(input())) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) seq = [i+1 for i in range(n)] a = 0 b = 0 from itertools import permutations per = list(permutations(seq,n)) for i in range(len(per)): if per[i] == p: a = i if per[i] == q: b = i print((abs(a-b)))
n = int(eval(input())) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) seq = [i+1 for i in range(n)] # a = 0 # b = 0 from itertools import permutations per = list(permutations(seq,n)) # for i in range(len(per)): # if per[i] == p: # a = i # if per[i] == q: # b = i print((abs(per.index(p)-per.index(q))))
14
14
320
356
n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) seq = [i + 1 for i in range(n)] a = 0 b = 0 from itertools import permutations per = list(permutations(seq, n)) for i in range(len(per)): if per[i] == p: a = i if per[i] == q: b = i print((abs(a - b)))
n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) seq = [i + 1 for i in range(n)] # a = 0 # b = 0 from itertools import permutations per = list(permutations(seq, n)) # for i in range(len(per)): # if per[i] == p: # a = i # if per[i] == q: # b = i print((abs(per.index(p) - per.index(q))))
false
0
[ "-a = 0", "-b = 0", "+# a = 0", "+# b = 0", "-for i in range(len(per)):", "- if per[i] == p:", "- a = i", "- if per[i] == q:", "- b = i", "-print((abs(a - b)))", "+# for i in range(len(per)):", "+# if per[i] == p:", "+# a = i", "+# if per[i] == q:", "+# b = i", "+print((abs(per.index(p) - per.index(q))))" ]
false
0.047197
0.048799
0.967172
[ "s333342165", "s199709271" ]
u858742833
p03161
python
s105517879
s919369490
1,946
1,740
13,980
13,980
Accepted
Accepted
10.59
def main(): n, k = list(map(int, input().split())) h = list(map(int, input().split())) a = [0] * n a[0] = 0 for i in range(1, n): hi = h[i] a[i] = min(a[j] + abs(hi - h[j]) for j in range(max(0, i - k), i)) print((a[-1])) if __name__ == '__main__': main()
def main(): n, k = list(map(int, input().split())) h = list(map(int, input().split())) a = [0] * n a[0] = 0 for i in range(1, n): hi = h[i] s = max(0, i - k) a[i] = min(aj + abs(hi - hj) for hj, aj in zip(h[s:i], a[s:i])) print((a[-1])) if __name__ == '__main__': main()
12
13
304
328
def main(): n, k = list(map(int, input().split())) h = list(map(int, input().split())) a = [0] * n a[0] = 0 for i in range(1, n): hi = h[i] a[i] = min(a[j] + abs(hi - h[j]) for j in range(max(0, i - k), i)) print((a[-1])) if __name__ == "__main__": main()
def main(): n, k = list(map(int, input().split())) h = list(map(int, input().split())) a = [0] * n a[0] = 0 for i in range(1, n): hi = h[i] s = max(0, i - k) a[i] = min(aj + abs(hi - hj) for hj, aj in zip(h[s:i], a[s:i])) print((a[-1])) if __name__ == "__main__": main()
false
7.692308
[ "- a[i] = min(a[j] + abs(hi - h[j]) for j in range(max(0, i - k), i))", "+ s = max(0, i - k)", "+ a[i] = min(aj + abs(hi - hj) for hj, aj in zip(h[s:i], a[s:i]))" ]
false
0.043719
0.046472
0.940758
[ "s105517879", "s919369490" ]
u672475305
p03436
python
s053691358
s808901004
154
30
12,496
3,444
Accepted
Accepted
80.52
R,C = list(map(int,input().split())) sy,sx = 1,1 gy,gx = R,C maze = [list(eval(input())) for _ in range(R)] mx = 0 for m in maze: mx += m.count('.') sx,sy = sx-1, sy-1 gx,gy = gx-1, gy-1 def bfs(R,C,sy,sx,gy,gx,maze): from collections import deque import numpy as np INF = np.inf visited = [[INF]*C for _ in range(R)] visited[sy][sx] = 0 que = deque([(sy,sx)]) while que: y,x = que.popleft() for i,j in ((1,0),(0,1),(-1,0),(0,-1)): ny,nx = y+i, x+j if 0<=ny<R and 0<=nx<C: if (maze[ny][nx]!='#') and visited[ny][nx]==INF: visited[ny][nx] = visited[y][x] + 1 que.append((ny,nx)) if visited[gy][gx]!=INF: return visited[gy][gx] else: return -1 ans = bfs(R,C,sy,sx,gy,gx,maze) print((mx-ans-1 if ans!=-1 else -1))
from collections import deque h,w = list(map(int,input().split())) maze = [] visited = [[0]*(w) for _ in range(h)] mx = 0 for _ in range(h): s = eval(input()) mx += s.count('.') maze.append(list(s)) sy,sx = 0, 0 gy, gx = h-1, w-1 que = deque([(sy,sx,1)]) while que: y,x,c = que.popleft() if visited[y][x] != 0: continue visited[y][x] = c for dy,dx in zip((1,-1,0,0), (0,0,1,-1)): ny,nx = y+dy, x+dx if 0<=ny<h and 0<=nx<w: if maze[ny][nx]=='.': que.append((ny,nx,c+1)) print((mx-visited[gy][gx] if visited[gy][gx]!=0 else -1))
34
26
879
636
R, C = list(map(int, input().split())) sy, sx = 1, 1 gy, gx = R, C maze = [list(eval(input())) for _ in range(R)] mx = 0 for m in maze: mx += m.count(".") sx, sy = sx - 1, sy - 1 gx, gy = gx - 1, gy - 1 def bfs(R, C, sy, sx, gy, gx, maze): from collections import deque import numpy as np INF = np.inf visited = [[INF] * C for _ in range(R)] visited[sy][sx] = 0 que = deque([(sy, sx)]) while que: y, x = que.popleft() for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)): ny, nx = y + i, x + j if 0 <= ny < R and 0 <= nx < C: if (maze[ny][nx] != "#") and visited[ny][nx] == INF: visited[ny][nx] = visited[y][x] + 1 que.append((ny, nx)) if visited[gy][gx] != INF: return visited[gy][gx] else: return -1 ans = bfs(R, C, sy, sx, gy, gx, maze) print((mx - ans - 1 if ans != -1 else -1))
from collections import deque h, w = list(map(int, input().split())) maze = [] visited = [[0] * (w) for _ in range(h)] mx = 0 for _ in range(h): s = eval(input()) mx += s.count(".") maze.append(list(s)) sy, sx = 0, 0 gy, gx = h - 1, w - 1 que = deque([(sy, sx, 1)]) while que: y, x, c = que.popleft() if visited[y][x] != 0: continue visited[y][x] = c for dy, dx in zip((1, -1, 0, 0), (0, 0, 1, -1)): ny, nx = y + dy, x + dx if 0 <= ny < h and 0 <= nx < w: if maze[ny][nx] == ".": que.append((ny, nx, c + 1)) print((mx - visited[gy][gx] if visited[gy][gx] != 0 else -1))
false
23.529412
[ "-R, C = list(map(int, input().split()))", "-sy, sx = 1, 1", "-gy, gx = R, C", "-maze = [list(eval(input())) for _ in range(R)]", "+from collections import deque", "+", "+h, w = list(map(int, input().split()))", "+maze = []", "+visited = [[0] * (w) for _ in range(h)]", "-for m in maze:", "- mx += m.count(\".\")", "-sx, sy = sx - 1, sy - 1", "-gx, gy = gx - 1, gy - 1", "-", "-", "-def bfs(R, C, sy, sx, gy, gx, maze):", "- from collections import deque", "- import numpy as np", "-", "- INF = np.inf", "- visited = [[INF] * C for _ in range(R)]", "- visited[sy][sx] = 0", "- que = deque([(sy, sx)])", "- while que:", "- y, x = que.popleft()", "- for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "- ny, nx = y + i, x + j", "- if 0 <= ny < R and 0 <= nx < C:", "- if (maze[ny][nx] != \"#\") and visited[ny][nx] == INF:", "- visited[ny][nx] = visited[y][x] + 1", "- que.append((ny, nx))", "- if visited[gy][gx] != INF:", "- return visited[gy][gx]", "- else:", "- return -1", "-", "-", "-ans = bfs(R, C, sy, sx, gy, gx, maze)", "-print((mx - ans - 1 if ans != -1 else -1))", "+for _ in range(h):", "+ s = eval(input())", "+ mx += s.count(\".\")", "+ maze.append(list(s))", "+sy, sx = 0, 0", "+gy, gx = h - 1, w - 1", "+que = deque([(sy, sx, 1)])", "+while que:", "+ y, x, c = que.popleft()", "+ if visited[y][x] != 0:", "+ continue", "+ visited[y][x] = c", "+ for dy, dx in zip((1, -1, 0, 0), (0, 0, 1, -1)):", "+ ny, nx = y + dy, x + dx", "+ if 0 <= ny < h and 0 <= nx < w:", "+ if maze[ny][nx] == \".\":", "+ que.append((ny, nx, c + 1))", "+print((mx - visited[gy][gx] if visited[gy][gx] != 0 else -1))" ]
false
0.043223
0.036425
1.186646
[ "s053691358", "s808901004" ]
u466331465
p02953
python
s463841801
s909013497
129
97
14,704
14,252
Accepted
Accepted
24.81
N = int(eval(input())) H = list(map(int,input().split())) a = [] cnt = 0 for i in range(N-1): if cnt-H[i]>1: print("No") exit() elif H[i]>H[i+1] and H[i]-H[i+1]==1: a.append(H[i]-1) cnt = max(cnt,H[i]) elif H[i]<=H[i+1]: a.append(H[i]) cnt = max(cnt,H[i]) else: print("No") exit() if cnt-H[N-1]>1: print("No") exit() print("Yes")
N = int(eval(input())) H = list(map(int,input().split())) for i in range(N-2,-1,-1): if H[i]>H[i+1] and H[i]-H[i+1]==1: H[i] = H[i]-1 elif H[i]<=H[i+1]: H[i] = H[i] else: print("No") exit() print("Yes")
21
11
389
229
N = int(eval(input())) H = list(map(int, input().split())) a = [] cnt = 0 for i in range(N - 1): if cnt - H[i] > 1: print("No") exit() elif H[i] > H[i + 1] and H[i] - H[i + 1] == 1: a.append(H[i] - 1) cnt = max(cnt, H[i]) elif H[i] <= H[i + 1]: a.append(H[i]) cnt = max(cnt, H[i]) else: print("No") exit() if cnt - H[N - 1] > 1: print("No") exit() print("Yes")
N = int(eval(input())) H = list(map(int, input().split())) for i in range(N - 2, -1, -1): if H[i] > H[i + 1] and H[i] - H[i + 1] == 1: H[i] = H[i] - 1 elif H[i] <= H[i + 1]: H[i] = H[i] else: print("No") exit() print("Yes")
false
47.619048
[ "-a = []", "-cnt = 0", "-for i in range(N - 1):", "- if cnt - H[i] > 1:", "- print(\"No\")", "- exit()", "- elif H[i] > H[i + 1] and H[i] - H[i + 1] == 1:", "- a.append(H[i] - 1)", "- cnt = max(cnt, H[i])", "+for i in range(N - 2, -1, -1):", "+ if H[i] > H[i + 1] and H[i] - H[i + 1] == 1:", "+ H[i] = H[i] - 1", "- a.append(H[i])", "- cnt = max(cnt, H[i])", "+ H[i] = H[i]", "-if cnt - H[N - 1] > 1:", "- print(\"No\")", "- exit()" ]
false
0.046223
0.037231
1.241505
[ "s463841801", "s909013497" ]
u191874006
p02843
python
s796075257
s050654940
171
76
38,256
65,456
Accepted
Accepted
55.56
#!/usr/bin/env python3 #三井住友信託銀行プログラミングコンテスト2019 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) x = I() y,z = divmod(x,100) if y*5 >= z: print((1)) else: print((0))
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) x = I() y = x // 100 z = x % 100 if 0 <= z <= 5*y: print((1)) else: print((0))
26
26
663
649
#!/usr/bin/env python3 # 三井住友信託銀行プログラミングコンテスト2019 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) x = I() y, z = divmod(x, 100) if y * 5 >= z: print((1)) else: print((0))
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) x = I() y = x // 100 z = x % 100 if 0 <= z <= 5 * y: print((1)) else: print((0))
false
0
[ "-# 三井住友信託銀行プログラミングコンテスト2019 C", "-sys.setrecursionlimit(1000000)", "+sys.setrecursionlimit(2147483647)", "-y, z = divmod(x, 100)", "-if y * 5 >= z:", "+y = x // 100", "+z = x % 100", "+if 0 <= z <= 5 * y:" ]
false
0.035966
0.03641
0.987801
[ "s796075257", "s050654940" ]
u774845108
p02902
python
s948270192
s881127718
259
157
45,292
13,280
Accepted
Accepted
39.38
from sys import stdin import sys #import numpy as np import collections from functools import cmp_to_key import heapq ## input functions for me def rsa(sep = ''): if sep == '' : return input().split() else: return input().split(sep) def rip(sep = ''): if sep == '' : return list(map(int, input().split())) else: return list(map(int, input().split(sep))) def ria(sep = ''): return list(rip(sep)) def ri(): return int(eval(input())) def rd(): return float(eval(input())) def rs(): return eval(input()) ## compo = [] cs = [] N = 0 M = 0 A = None B = None E = None def main(): global compo,cs,N,M,A,B,E N, M = rip() A = [0] * M B = [0] * M for i in range(M): A[i], B[i] = rip() A[i] -= 1 B[i] -= 1 E = [[] for i in range(N)] for i in range(M): E[A[i]].append(B[i]) compo = [-1] * N def dfs(cmp, route, hs): global compo,cs,N,M,A,B,E if(len(cs) > 0) : return now = route[len(route) - 1] for nxt in E[now]: if compo[nxt] == -1: compo[nxt] = cmp route.append(nxt) hs.add(nxt) dfs(cmp, route, hs) hs.remove(nxt) route.pop(-1) elif compo[nxt] == cmp: if nxt in hs: cs = route[route.index(nxt):] return else: return cs = [] c = 0 for i in range(N): if(compo[i] != -1): continue c += 1 a = [] hs = set() a.append(i) hs.add(i) compo[i] = c dfs(c, a, hs) if len(cs) == 0: print((-1)) sys.exit(0) l = cs while(True): di = dict() for i in range(len(l)): di[l[i]] = l[(i + 1) % len(l)] edx = -1 for i in range(M): if A[i] in di and B[i] in di: if di[A[i]] != B[i]: edx = i break if edx == -1: print((len(l))) print(("\n".join([str(n + 1) for n in l]))) sys.exit(0) di[A[edx]] = B[edx] nl = [A[edx], B[edx]] while True: nxt = di[nl[-1]] if nxt != nl[0]: nl.append(nxt) else: break l = nl if __name__ == "__main__": main()
from sys import stdin import sys import numpy as np import collections from functools import cmp_to_key import heapq sys.setrecursionlimit(100000) ## input functions for me def rsa(sep = ''): if sep == '' : return input().split() else: return input().split(sep) def rip(sep = ''): if sep == '' : return list(map(int, input().split())) else: return list(map(int, input().split(sep))) def ria(sep = ''): return list(rip(sep)) def ri(): return int(eval(input())) def rd(): return float(eval(input())) def rs(): return eval(input()) ## compo = [] cs = [] N = 0 M = 0 A = None B = None E = None def main(): global compo,cs,N,M,A,B,E N, M = rip() A = [0] * M B = [0] * M for i in range(M): A[i], B[i] = rip() A[i] -= 1 B[i] -= 1 E = [[] for i in range(N)] for i in range(M): E[A[i]].append(B[i]) compo = [-1] * N def dfs(cmp, route, hs): global compo,cs,N,M,A,B,E if(len(cs) > 0) : return now = route[len(route) - 1] for nxt in E[now]: if compo[nxt] == -1: compo[nxt] = cmp route.append(nxt) hs.add(nxt) dfs(cmp, route, hs) hs.remove(nxt) route.pop(-1) elif compo[nxt] == cmp: if nxt in hs: cs = route[route.index(nxt):] return else: return cs = [] c = 0 for i in range(N): if(compo[i] != -1): continue c += 1 a = [] hs = set() a.append(i) hs.add(i) compo[i] = c dfs(c, a, hs) if len(cs) == 0: print((-1)) sys.exit(0) l = cs while(True): di = dict() for i in range(len(l)): di[l[i]] = l[(i + 1) % len(l)] edx = -1 for i in range(M): if A[i] in di and B[i] in di: if di[A[i]] != B[i]: edx = i break if edx == -1: print((len(l))) print(("\n".join([str(n + 1) for n in l]))) sys.exit(0) di[A[edx]] = B[edx] nl = [A[edx], B[edx]] while True: nxt = di[nl[-1]] if nxt != nl[0]: nl.append(nxt) else: break l = nl if __name__ == "__main__": main()
112
113
2,525
2,555
from sys import stdin import sys # import numpy as np import collections from functools import cmp_to_key import heapq ## input functions for me def rsa(sep=""): if sep == "": return input().split() else: return input().split(sep) def rip(sep=""): if sep == "": return list(map(int, input().split())) else: return list(map(int, input().split(sep))) def ria(sep=""): return list(rip(sep)) def ri(): return int(eval(input())) def rd(): return float(eval(input())) def rs(): return eval(input()) ## compo = [] cs = [] N = 0 M = 0 A = None B = None E = None def main(): global compo, cs, N, M, A, B, E N, M = rip() A = [0] * M B = [0] * M for i in range(M): A[i], B[i] = rip() A[i] -= 1 B[i] -= 1 E = [[] for i in range(N)] for i in range(M): E[A[i]].append(B[i]) compo = [-1] * N def dfs(cmp, route, hs): global compo, cs, N, M, A, B, E if len(cs) > 0: return now = route[len(route) - 1] for nxt in E[now]: if compo[nxt] == -1: compo[nxt] = cmp route.append(nxt) hs.add(nxt) dfs(cmp, route, hs) hs.remove(nxt) route.pop(-1) elif compo[nxt] == cmp: if nxt in hs: cs = route[route.index(nxt) :] return else: return cs = [] c = 0 for i in range(N): if compo[i] != -1: continue c += 1 a = [] hs = set() a.append(i) hs.add(i) compo[i] = c dfs(c, a, hs) if len(cs) == 0: print((-1)) sys.exit(0) l = cs while True: di = dict() for i in range(len(l)): di[l[i]] = l[(i + 1) % len(l)] edx = -1 for i in range(M): if A[i] in di and B[i] in di: if di[A[i]] != B[i]: edx = i break if edx == -1: print((len(l))) print(("\n".join([str(n + 1) for n in l]))) sys.exit(0) di[A[edx]] = B[edx] nl = [A[edx], B[edx]] while True: nxt = di[nl[-1]] if nxt != nl[0]: nl.append(nxt) else: break l = nl if __name__ == "__main__": main()
from sys import stdin import sys import numpy as np import collections from functools import cmp_to_key import heapq sys.setrecursionlimit(100000) ## input functions for me def rsa(sep=""): if sep == "": return input().split() else: return input().split(sep) def rip(sep=""): if sep == "": return list(map(int, input().split())) else: return list(map(int, input().split(sep))) def ria(sep=""): return list(rip(sep)) def ri(): return int(eval(input())) def rd(): return float(eval(input())) def rs(): return eval(input()) ## compo = [] cs = [] N = 0 M = 0 A = None B = None E = None def main(): global compo, cs, N, M, A, B, E N, M = rip() A = [0] * M B = [0] * M for i in range(M): A[i], B[i] = rip() A[i] -= 1 B[i] -= 1 E = [[] for i in range(N)] for i in range(M): E[A[i]].append(B[i]) compo = [-1] * N def dfs(cmp, route, hs): global compo, cs, N, M, A, B, E if len(cs) > 0: return now = route[len(route) - 1] for nxt in E[now]: if compo[nxt] == -1: compo[nxt] = cmp route.append(nxt) hs.add(nxt) dfs(cmp, route, hs) hs.remove(nxt) route.pop(-1) elif compo[nxt] == cmp: if nxt in hs: cs = route[route.index(nxt) :] return else: return cs = [] c = 0 for i in range(N): if compo[i] != -1: continue c += 1 a = [] hs = set() a.append(i) hs.add(i) compo[i] = c dfs(c, a, hs) if len(cs) == 0: print((-1)) sys.exit(0) l = cs while True: di = dict() for i in range(len(l)): di[l[i]] = l[(i + 1) % len(l)] edx = -1 for i in range(M): if A[i] in di and B[i] in di: if di[A[i]] != B[i]: edx = i break if edx == -1: print((len(l))) print(("\n".join([str(n + 1) for n in l]))) sys.exit(0) di[A[edx]] = B[edx] nl = [A[edx], B[edx]] while True: nxt = di[nl[-1]] if nxt != nl[0]: nl.append(nxt) else: break l = nl if __name__ == "__main__": main()
false
0.884956
[ "-", "-# import numpy as np", "+import numpy as np", "+sys.setrecursionlimit(100000)" ]
false
0.059282
0.038356
1.545568
[ "s948270192", "s881127718" ]