user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u562935282
p02989
python
s492977909
s076084846
289
76
53,172
13,992
Accepted
Accepted
73.7
from bisect import bisect_left N = int(eval(input())) d = list(map(int, input().split())) d.sort() to_take = N // 2 cnt = 0 for x in range(d[0], d[-1] + 1): idx = bisect_left(d, x) # ABC用の問題数 if idx == to_take: cnt += 1 print(cnt)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((d[n // 2] - d[n // 2 - 1]))
15
5
262
100
from bisect import bisect_left N = int(eval(input())) d = list(map(int, input().split())) d.sort() to_take = N // 2 cnt = 0 for x in range(d[0], d[-1] + 1): idx = bisect_left(d, x) # ABC用の問題数 if idx == to_take: cnt += 1 print(cnt)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((d[n // 2] - d[n // 2 - 1]))
false
66.666667
[ "-from bisect import bisect_left", "-", "-N = int(eval(input()))", "+n = int(eval(input()))", "-to_take = N // 2", "-cnt = 0", "-for x in range(d[0], d[-1] + 1):", "- idx = bisect_left(d, x)", "- # ABC用の問題数", "- if idx == to_take:", "- cnt += 1", "-print(cnt)", "+print((d[n // 2] - d[n // 2 - 1]))" ]
false
0.057641
0.033255
1.733292
[ "s492977909", "s076084846" ]
u936985471
p02684
python
s762657113
s205805718
1,661
1,534
31,352
31,220
Accepted
Accepted
7.65
import sys readline = sys.stdin.readline N,K = list(map(int,readline().split())) A = [0] + list(map(int,readline().split())) now = 1 while K > 0: if K & 1: now = A[now] A = [A[A[i]] for i in range(len(A))] K >>= 1 print(now)
import sys readline = sys.stdin.readline N,K = list(map(int,readline().split())) A = [0] + list(map(int,readline().split())) pos = 1 while K: if K & 1: pos = A[pos] A = [A[A[i]] for i in range(N + 1)] K >>= 1 print(pos)
14
15
244
243
import sys readline = sys.stdin.readline N, K = list(map(int, readline().split())) A = [0] + list(map(int, readline().split())) now = 1 while K > 0: if K & 1: now = A[now] A = [A[A[i]] for i in range(len(A))] K >>= 1 print(now)
import sys readline = sys.stdin.readline N, K = list(map(int, readline().split())) A = [0] + list(map(int, readline().split())) pos = 1 while K: if K & 1: pos = A[pos] A = [A[A[i]] for i in range(N + 1)] K >>= 1 print(pos)
false
6.666667
[ "-now = 1", "-while K > 0:", "+pos = 1", "+while K:", "- now = A[now]", "- A = [A[A[i]] for i in range(len(A))]", "+ pos = A[pos]", "+ A = [A[A[i]] for i in range(N + 1)]", "-print(now)", "+print(pos)" ]
false
0.041786
0.091233
0.458016
[ "s762657113", "s205805718" ]
u179169725
p02937
python
s611190684
s283764415
1,722
154
377,504
12,268
Accepted
Accepted
91.06
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する # 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdict(lambda: []) for i, ss in enumerate(s + s): mojiidx[ss].append(i) # i文字目において、次に文字cが出てくるのは何文字あと? skiptable = [] for i in range(0, len(s)): tmp = {} for c, ls in list(mojiidx.items()): tmp[c] = ls[bisect_right(ls, i)] - i skiptable.append(tmp) # print(skiptable) # 本処理 # 最初にうまく飛べる点を探索 for i, ss in enumerate(s): if ss == t[0]: now = i break for tt in t[1:]: idx = now % len(s) now += skiptable[idx][tt] print((now + 1))
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdict(lambda: []) for i, ss in enumerate(s + s): mojiidx[ss].append(i) # 本処理 # 最初にうまく飛べる点を探索 for i, ss in enumerate(s): if ss == t[0]: now = i break for tt in t[1:]: idx = now % len(s) # 前処理の列から文字ttが何文字あとに出現するかを探索する ls = mojiidx[tt] tmp = ls[bisect_right(ls, idx)] - idx now += tmp print((now + 1))
41
33
808
622
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する # 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdict(lambda: []) for i, ss in enumerate(s + s): mojiidx[ss].append(i) # i文字目において、次に文字cが出てくるのは何文字あと? skiptable = [] for i in range(0, len(s)): tmp = {} for c, ls in list(mojiidx.items()): tmp[c] = ls[bisect_right(ls, i)] - i skiptable.append(tmp) # print(skiptable) # 本処理 # 最初にうまく飛べる点を探索 for i, ss in enumerate(s): if ss == t[0]: now = i break for tt in t[1:]: idx = now % len(s) now += skiptable[idx][tt] print((now + 1))
from bisect import bisect_right from collections import defaultdict import sys read = sys.stdin.readline s = read()[:-1] t = read()[:-1] # 即時終了 if set(t) - set(s): print((-1)) exit() # 前処理 # 0文字目から見たときにその文字が何文字目にあるかを記録しておく mojiidx = defaultdict(lambda: []) for i, ss in enumerate(s + s): mojiidx[ss].append(i) # 本処理 # 最初にうまく飛べる点を探索 for i, ss in enumerate(s): if ss == t[0]: now = i break for tt in t[1:]: idx = now % len(s) # 前処理の列から文字ttが何文字あとに出現するかを探索する ls = mojiidx[tt] tmp = ls[bisect_right(ls, idx)] - idx now += tmp print((now + 1))
false
19.512195
[ "-# 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する", "-# 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく", "+# 0文字目から見たときにその文字が何文字目にあるかを記録しておく", "-# i文字目において、次に文字cが出てくるのは何文字あと?", "-skiptable = []", "-for i in range(0, len(s)):", "- tmp = {}", "- for c, ls in list(mojiidx.items()):", "- tmp[c] = ls[bisect_right(ls, i)] - i", "- skiptable.append(tmp)", "-# print(skiptable)", "- now += skiptable[idx][tt]", "+ # 前処理の列から文字ttが何文字あとに出現するかを探索する", "+ ls = mojiidx[tt]", "+ tmp = ls[bisect_right(ls, idx)] - idx", "+ now += tmp" ]
false
0.064098
0.036012
1.779909
[ "s611190684", "s283764415" ]
u937092222
p02685
python
s947066984
s719231782
1,402
659
24,632
24,684
Accepted
Accepted
53
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0]*(n+1) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(n+1) for i in range(n+1): invfact[i] = pow(fact[i], MOD-2, MOD) def nCk(n, k): return fact[n]*invfact[k]*invfact[n-k] ans = 0 for i in range(k+1): ans += m*pow(m-1, n-1-i, MOD)*nCk(n-1, i) ans %= MOD print(ans)
import sys input = sys.stdin.readline def comb(n, r): return (fact[n] * revfact[n-r] * revfact[r]) % mod mod = 998244353 N, M, K = list(map(int, input().split())) fact = [1] * (N + 1) for i in range(1, N + 1): fact[i] = (fact[i-1] * i) % mod #n!を計算 # print('fact:{}'.format(fact)) revfact = [1] * (N + 1) #逆元を定義 revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算 # print('revfact:{}'.format(revfact)) for i in reversed(list(range(1, N))): #N-1から1まで revfact[i] = ((i + 1) * revfact[i + 1]) % mod # print('revfact:{}'.format(revfact)) ans = 0 for k in range(K + 1): ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod ans %= mod print(ans)
22
26
411
694
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0] * (n + 1) fact[0] = 1 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % MOD invfact = [0] * (n + 1) for i in range(n + 1): invfact[i] = pow(fact[i], MOD - 2, MOD) def nCk(n, k): return fact[n] * invfact[k] * invfact[n - k] ans = 0 for i in range(k + 1): ans += m * pow(m - 1, n - 1 - i, MOD) * nCk(n - 1, i) ans %= MOD print(ans)
import sys input = sys.stdin.readline def comb(n, r): return (fact[n] * revfact[n - r] * revfact[r]) % mod mod = 998244353 N, M, K = list(map(int, input().split())) fact = [1] * (N + 1) for i in range(1, N + 1): fact[i] = (fact[i - 1] * i) % mod # n!を計算 # print('fact:{}'.format(fact)) revfact = [1] * (N + 1) # 逆元を定義 revfact[N] = pow(fact[N], mod - 2, mod) # n!のmod-2乗を計算 # print('revfact:{}'.format(revfact)) for i in reversed(list(range(1, N))): # N-1から1まで revfact[i] = ((i + 1) * revfact[i + 1]) % mod # print('revfact:{}'.format(revfact)) ans = 0 for k in range(K + 1): ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod ans %= mod print(ans)
false
15.384615
[ "-MOD = 998244353", "-n, m, k = list(map(int, input().split()))", "-fact = [0] * (n + 1)", "-fact[0] = 1", "-for i in range(1, n + 1):", "- fact[i] = fact[i - 1] * i % MOD", "-invfact = [0] * (n + 1)", "-for i in range(n + 1):", "- invfact[i] = pow(fact[i], MOD - 2, MOD)", "+import sys", "+", "+input = sys.stdin.readline", "-def nCk(n, k):", "- return fact[n] * invfact[k] * invfact[n - k]", "+def comb(n, r):", "+ return (fact[n] * revfact[n - r] * revfact[r]) % mod", "+mod = 998244353", "+N, M, K = list(map(int, input().split()))", "+fact = [1] * (N + 1)", "+for i in range(1, N + 1):", "+ fact[i] = (fact[i - 1] * i) % mod # n!を計算", "+# print('fact:{}'.format(fact))", "+revfact = [1] * (N + 1) # 逆元を定義", "+revfact[N] = pow(fact[N], mod - 2, mod) # n!のmod-2乗を計算", "+# print('revfact:{}'.format(revfact))", "+for i in reversed(list(range(1, N))): # N-1から1まで", "+ revfact[i] = ((i + 1) * revfact[i + 1]) % mod", "+# print('revfact:{}'.format(revfact))", "-for i in range(k + 1):", "- ans += m * pow(m - 1, n - 1 - i, MOD) * nCk(n - 1, i)", "- ans %= MOD", "+for k in range(K + 1):", "+ ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod", "+ ans %= mod" ]
false
0.212944
0.12327
1.727462
[ "s947066984", "s719231782" ]
u983918956
p03450
python
s636746116
s752783141
1,464
1,352
8,804
8,804
Accepted
Accepted
7.65
def prepare(n): global nodes,diff_weight # ノードは-1で初期化, Nは頂点数 nodes = [-1]*n # 差分重みは0で初期化, Nは頂点数 diff_weight = [0]*n # 差分重みの累積和をとることでxの重みが分かる def weight(x): # xの重みを知りたいので経路圧縮 root(x) return diff_weight[x] # xからyへの重み def diff(x,y): return weight(y) - weight(x) # x,yの根が同じ->True def same(x,y): return root(x) == root(y) # xの木の高さを返す def rank(x): return -nodes[x] def root(x): # ノードが負 <=> xは根 if nodes[x] < 0: return x else: # 再帰的に根を調べる root_x = root(nodes[x]) # 根に近いものから親の重みを足す. これがxを根に直接繋いだ時の重みになる diff_weight[x] += diff_weight[nodes[x]] # xを根に直接繋ぎ直す nodes[x] = root_x return root_x def unite(x,y,w): # 以下x,yの根について考えるので,重みを補正 w += weight(x); w -= weight(y) x = root(x); y = root(y) # 根が同じならreturn (自己ループを考慮) if x == y: return rank_x = rank(x); rank_y = rank(y) # xの方が木が高いことを想定しているのでx,yをスワップ,wを-wに if rank_x < rank_y: x,y = y,x; w = -w # 木の高さが同じ場合は繋いだ後の高さが1だけ高くなる if rank_x == rank_y: nodes[x] -= 1 # 低い木の根を高い木の根に繋ぎ直す nodes[y] = x # 低い木の根の差分重みを設定 diff_weight[y] = w N,M = list(map(int,input().split())) prepare(N) ans = "Yes" for _ in range(M): L,R,D = list(map(int,input().split())) L -= 1; R -= 1 unite(L,R,D) if diff(L,R) != D: ans = "No" print(ans)
def prepare(n): global nodes,diff_weight # ノードは-1で初期化, Nは頂点数 nodes = [-1]*n # 差分重みは0で初期化, Nは頂点数 diff_weight = [0]*n # 差分重みの累積和をとることでxの重みが分かる def weight(x): # xの重みを知りたいので経路圧縮 root(x) return diff_weight[x] # xからyへの重み def diff(x,y): return weight(y) - weight(x) # x,yの根が同じ->True def same(x,y): return root(x) == root(y) # xの木の高さを返す def rank(x): return -nodes[root(x)] def root(x): # ノードが負 <=> xは根 if nodes[x] < 0: return x else: # 再帰的に根を調べる root_x = root(nodes[x]) # 根に近いものから親の重みを足す. これがxを根に直接繋いだ時の重みになる diff_weight[x] += diff_weight[nodes[x]] # xを根に直接繋ぎ直す nodes[x] = root_x return root_x def unite(x,y,w): rx = root(x); ry = root(y) # 根が同じならreturn (自己ループを考慮) if rx == ry: return rank_x = rank(rx); rank_y = rank(ry) # xの方が木が高いことを想定しているので下の場合はx,yとrx,ryをスワップ,wを-wに if rank_x < rank_y: x,y = y,x; rx,ry = ry,rx; w = -w # 木の高さが同じ場合は繋いだ後の高さが1だけ高くなる if rank_x == rank_y: nodes[rx] -= 1 # 低い木の根の差分重みを設定 diff_weight[ry] = w + weight(x) - weight(y) # 低い木の根を高い木の根に繋ぎ直す nodes[ry] = rx N,M = list(map(int,input().split())) prepare(N) ans = "Yes" for _ in range(M): L,R,D = list(map(int,input().split())) L -= 1; R -= 1 unite(L,R,D) if diff(L,R) != D: ans = "No" print(ans)
67
65
1,433
1,433
def prepare(n): global nodes, diff_weight # ノードは-1で初期化, Nは頂点数 nodes = [-1] * n # 差分重みは0で初期化, Nは頂点数 diff_weight = [0] * n # 差分重みの累積和をとることでxの重みが分かる def weight(x): # xの重みを知りたいので経路圧縮 root(x) return diff_weight[x] # xからyへの重み def diff(x, y): return weight(y) - weight(x) # x,yの根が同じ->True def same(x, y): return root(x) == root(y) # xの木の高さを返す def rank(x): return -nodes[x] def root(x): # ノードが負 <=> xは根 if nodes[x] < 0: return x else: # 再帰的に根を調べる root_x = root(nodes[x]) # 根に近いものから親の重みを足す. これがxを根に直接繋いだ時の重みになる diff_weight[x] += diff_weight[nodes[x]] # xを根に直接繋ぎ直す nodes[x] = root_x return root_x def unite(x, y, w): # 以下x,yの根について考えるので,重みを補正 w += weight(x) w -= weight(y) x = root(x) y = root(y) # 根が同じならreturn (自己ループを考慮) if x == y: return rank_x = rank(x) rank_y = rank(y) # xの方が木が高いことを想定しているのでx,yをスワップ,wを-wに if rank_x < rank_y: x, y = y, x w = -w # 木の高さが同じ場合は繋いだ後の高さが1だけ高くなる if rank_x == rank_y: nodes[x] -= 1 # 低い木の根を高い木の根に繋ぎ直す nodes[y] = x # 低い木の根の差分重みを設定 diff_weight[y] = w N, M = list(map(int, input().split())) prepare(N) ans = "Yes" for _ in range(M): L, R, D = list(map(int, input().split())) L -= 1 R -= 1 unite(L, R, D) if diff(L, R) != D: ans = "No" print(ans)
def prepare(n): global nodes, diff_weight # ノードは-1で初期化, Nは頂点数 nodes = [-1] * n # 差分重みは0で初期化, Nは頂点数 diff_weight = [0] * n # 差分重みの累積和をとることでxの重みが分かる def weight(x): # xの重みを知りたいので経路圧縮 root(x) return diff_weight[x] # xからyへの重み def diff(x, y): return weight(y) - weight(x) # x,yの根が同じ->True def same(x, y): return root(x) == root(y) # xの木の高さを返す def rank(x): return -nodes[root(x)] def root(x): # ノードが負 <=> xは根 if nodes[x] < 0: return x else: # 再帰的に根を調べる root_x = root(nodes[x]) # 根に近いものから親の重みを足す. これがxを根に直接繋いだ時の重みになる diff_weight[x] += diff_weight[nodes[x]] # xを根に直接繋ぎ直す nodes[x] = root_x return root_x def unite(x, y, w): rx = root(x) ry = root(y) # 根が同じならreturn (自己ループを考慮) if rx == ry: return rank_x = rank(rx) rank_y = rank(ry) # xの方が木が高いことを想定しているので下の場合はx,yとrx,ryをスワップ,wを-wに if rank_x < rank_y: x, y = y, x rx, ry = ry, rx w = -w # 木の高さが同じ場合は繋いだ後の高さが1だけ高くなる if rank_x == rank_y: nodes[rx] -= 1 # 低い木の根の差分重みを設定 diff_weight[ry] = w + weight(x) - weight(y) # 低い木の根を高い木の根に繋ぎ直す nodes[ry] = rx N, M = list(map(int, input().split())) prepare(N) ans = "Yes" for _ in range(M): L, R, D = list(map(int, input().split())) L -= 1 R -= 1 unite(L, R, D) if diff(L, R) != D: ans = "No" print(ans)
false
2.985075
[ "- return -nodes[x]", "+ return -nodes[root(x)]", "- # 以下x,yの根について考えるので,重みを補正", "- w += weight(x)", "- w -= weight(y)", "- x = root(x)", "- y = root(y)", "+ rx = root(x)", "+ ry = root(y)", "- if x == y:", "+ if rx == ry:", "- rank_x = rank(x)", "- rank_y = rank(y)", "- # xの方が木が高いことを想定しているのでx,yをスワップ,wを-wに", "+ rank_x = rank(rx)", "+ rank_y = rank(ry)", "+ # xの方が木が高いことを想定しているので下の場合はx,yとrx,ryをスワップ,wを-wに", "+ rx, ry = ry, rx", "- nodes[x] -= 1", "+ nodes[rx] -= 1", "+ # 低い木の根の差分重みを設定", "+ diff_weight[ry] = w + weight(x) - weight(y)", "- nodes[y] = x", "- # 低い木の根の差分重みを設定", "- diff_weight[y] = w", "+ nodes[ry] = rx" ]
false
0.039028
0.038447
1.015102
[ "s636746116", "s752783141" ]
u136916346
p00085
python
s261571337
s883092790
40
30
5,600
5,592
Accepted
Accepted
25
while 1: n,m=list(map(int,input().split())) if n==0 and m==0:break l=[i for i in range(1,1+n)] st=m-1 while len(l)!=1: del l[st] st+=(m-1) while 1: if st>=len(l): st=st-len(l) if st<len(l):break print((l[0]))
while 1: n,m=list(map(int,input().split())) if n==0 and m==0:break l=list(range(1,1+n)) st=m-1 while len(l)!=1: del l[st] st+=(m-1) while 1: if st>=len(l): st=st-len(l) if st<len(l):break print((l[0]))
13
14
309
304
while 1: n, m = list(map(int, input().split())) if n == 0 and m == 0: break l = [i for i in range(1, 1 + n)] st = m - 1 while len(l) != 1: del l[st] st += m - 1 while 1: if st >= len(l): st = st - len(l) if st < len(l): break print((l[0]))
while 1: n, m = list(map(int, input().split())) if n == 0 and m == 0: break l = list(range(1, 1 + n)) st = m - 1 while len(l) != 1: del l[st] st += m - 1 while 1: if st >= len(l): st = st - len(l) if st < len(l): break print((l[0]))
false
7.142857
[ "- l = [i for i in range(1, 1 + n)]", "+ l = list(range(1, 1 + n))" ]
false
0.04362
0.046078
0.946649
[ "s261571337", "s883092790" ]
u476674388
p03160
python
s107471107
s453365915
145
116
13,908
18,092
Accepted
Accepted
20
N = int(eval(input())) h = list(map(int,input().split())) dp = [float('inf')] * N dp[0] = 0 def chmin(lst,a,b): if lst[a]>b: lst[a]=b def chmax(lst,a,b): if lst[a]<b: lst[a]=b for i in range(1,N): chmin(dp,i,dp[i-1]+abs(h[i-1]-h[i])) if i>1: chmin(dp,i,dp[i-2]+abs(h[i-2]-h[i])) print((dp[N-1]))
#!/usr/bin/env python3 import sys def solve(N: int, h: "List[int]"): dp = [float('inf')] * N dp[0] = 0 dp[1] = abs(h[0]-h[1]) for i in range(2,N): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) print((dp[-1])) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 h = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, h) if __name__ == '__main__': main()
20
29
3,043
788
N = int(eval(input())) h = list(map(int, input().split())) dp = [float("inf")] * N dp[0] = 0 def chmin(lst, a, b): if lst[a] > b: lst[a] = b def chmax(lst, a, b): if lst[a] < b: lst[a] = b for i in range(1, N): chmin(dp, i, dp[i - 1] + abs(h[i - 1] - h[i])) if i > 1: chmin(dp, i, dp[i - 2] + abs(h[i - 2] - h[i])) print((dp[N - 1]))
#!/usr/bin/env python3 import sys def solve(N: int, h: "List[int]"): dp = [float("inf")] * N dp[0] = 0 dp[1] = abs(h[0] - h[1]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1])) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 h = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, h) if __name__ == "__main__": main()
false
31.034483
[ "-N = int(eval(input()))", "-h = list(map(int, input().split()))", "-dp = [float(\"inf\")] * N", "-dp[0] = 0", "+#!/usr/bin/env python3", "+import sys", "-def chmin(lst, a, b):", "- if lst[a] > b:", "- lst[a] = b", "+def solve(N: int, h: \"List[int]\"):", "+ dp = [float(\"inf\")] * N", "+ dp[0] = 0", "+ dp[1] = abs(h[0] - h[1])", "+ for i in range(2, N):", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))", "+ print((dp[-1]))", "+ return", "-def chmax(lst, a, b):", "- if lst[a] < b:", "- lst[a] = b", "+# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)", "+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", "+ h = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"", "+ solve(N, h)", "-for i in range(1, N):", "- chmin(dp, i, dp[i - 1] + abs(h[i - 1] - h[i]))", "- if i > 1:", "- chmin(dp, i, dp[i - 2] + abs(h[i - 2] - h[i]))", "-print((dp[N - 1]))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.046375
0.110576
0.419394
[ "s107471107", "s453365915" ]
u832039789
p02818
python
s429438846
s204121333
20
17
3,316
2,940
Accepted
Accepted
15
a,b,k = list(map(int,input().split())) if k <= a: a -= k k = 0 print((a, b)) exit() k -= a print((0, max(0, b - k)))
a,b,k = list(map(int,input().split())) if a < k: k -= a a = 0 else: a -= k k = 0 if b < k: k -= b b = 0 else: b -= k k = 0 print((a, b))
10
17
134
180
a, b, k = list(map(int, input().split())) if k <= a: a -= k k = 0 print((a, b)) exit() k -= a print((0, max(0, b - k)))
a, b, k = list(map(int, input().split())) if a < k: k -= a a = 0 else: a -= k k = 0 if b < k: k -= b b = 0 else: b -= k k = 0 print((a, b))
false
41.176471
[ "-if k <= a:", "+if a < k:", "+ k -= a", "+ a = 0", "+else:", "- print((a, b))", "- exit()", "-k -= a", "-print((0, max(0, b - k)))", "+if b < k:", "+ k -= b", "+ b = 0", "+else:", "+ b -= k", "+ k = 0", "+print((a, b))" ]
false
0.035699
0.056599
0.630735
[ "s429438846", "s204121333" ]
u785578220
p03837
python
s058189146
s110615442
586
312
3,444
46,700
Accepted
Accepted
46.76
n, m = list(map(int, input().split())) INF = 10 ** 20 edgeList = [] dist = [[INF] * n for _ in range(n)] for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 dist[a][b] = dist[b][a] = c edgeList.append((a, b, c)) for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) print((sum([dist[a][b] < c for a, b, c in edgeList])))
N, M = list(map(int, input().split())) inf = float("inf") dp = [[inf]*N for _ in [0]*N] for i in range(N):dp[i][i] = 0 d = [list(map(int, input().split())) for i in range(M)] ans = 0 for a,b,c in d: dp[a-1][b-1] = c dp[b-1][a-1] = c for k in range(N): for i in range(N): for j in range(N): dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]) for a,b,c in d: if dp[a-1][b-1] != c: ans += 1 print(ans)
17
18
449
456
n, m = list(map(int, input().split())) INF = 10**20 edgeList = [] dist = [[INF] * n for _ in range(n)] for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 dist[a][b] = dist[b][a] = c edgeList.append((a, b, c)) for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) print((sum([dist[a][b] < c for a, b, c in edgeList])))
N, M = list(map(int, input().split())) inf = float("inf") dp = [[inf] * N for _ in [0] * N] for i in range(N): dp[i][i] = 0 d = [list(map(int, input().split())) for i in range(M)] ans = 0 for a, b, c in d: dp[a - 1][b - 1] = c dp[b - 1][a - 1] = c for k in range(N): for i in range(N): for j in range(N): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) for a, b, c in d: if dp[a - 1][b - 1] != c: ans += 1 print(ans)
false
5.555556
[ "-n, m = list(map(int, input().split()))", "-INF = 10**20", "-edgeList = []", "-dist = [[INF] * n for _ in range(n)]", "-for _ in range(m):", "- a, b, c = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- dist[a][b] = dist[b][a] = c", "- edgeList.append((a, b, c))", "-for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "-print((sum([dist[a][b] < c for a, b, c in edgeList])))", "+N, M = list(map(int, input().split()))", "+inf = float(\"inf\")", "+dp = [[inf] * N for _ in [0] * N]", "+for i in range(N):", "+ dp[i][i] = 0", "+d = [list(map(int, input().split())) for i in range(M)]", "+ans = 0", "+for a, b, c in d:", "+ dp[a - 1][b - 1] = c", "+ dp[b - 1][a - 1] = c", "+for k in range(N):", "+ for i in range(N):", "+ for j in range(N):", "+ dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])", "+for a, b, c in d:", "+ if dp[a - 1][b - 1] != c:", "+ ans += 1", "+print(ans)" ]
false
0.046279
0.106791
0.433363
[ "s058189146", "s110615442" ]
u761320129
p02804
python
s997009961
s258883447
419
217
36,460
25,488
Accepted
Accepted
48.21
N,K = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() MOD = 10**9+7 MAXN = N+5 fac = [1,1] + [0]*MAXN finv = [1,1] + [0]*MAXN inv = [0,1] + [0]*MAXN for i in range(2,MAXN+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def ncr(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD combs = [] l = N-K+1 for i in range(l): combs.append(ncr(N-l+i,i)) cmax = [0]*(N-l) + combs cmin = combs[::-1] from collections import Counter mins = Counter() maxs = Counter() for a,c in zip(A,cmax): maxs[a] += c for a,c in zip(A,cmin): mins[a] += c mx = A[-1] mn = A[0] ans = ncr(N,K) * (mx-mn) for k,v in list(maxs.items()): ans -= v * (mx-k) ans %= MOD for k,v in list(mins.items()): ans -= v * (k-mn) ans %= MOD print(ans)
N,K = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() MOD = 10**9+7 MAXN = N+5 fac = [1,1] + [0]*MAXN finv = [1,1] + [0]*MAXN inv = [0,1] + [0]*MAXN for i in range(2,MAXN+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def comb(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD ans = 0 for n in range(K-1,N): c = comb(n,K-1) mx = A[n] mn = A[-1-n] ans += (mx-mn)*c ans %= MOD print(ans)
47
27
931
592
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() MOD = 10**9 + 7 MAXN = N + 5 fac = [1, 1] + [0] * MAXN finv = [1, 1] + [0] * MAXN inv = [0, 1] + [0] * MAXN for i in range(2, MAXN + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def ncr(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD combs = [] l = N - K + 1 for i in range(l): combs.append(ncr(N - l + i, i)) cmax = [0] * (N - l) + combs cmin = combs[::-1] from collections import Counter mins = Counter() maxs = Counter() for a, c in zip(A, cmax): maxs[a] += c for a, c in zip(A, cmin): mins[a] += c mx = A[-1] mn = A[0] ans = ncr(N, K) * (mx - mn) for k, v in list(maxs.items()): ans -= v * (mx - k) ans %= MOD for k, v in list(mins.items()): ans -= v * (k - mn) ans %= MOD print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() MOD = 10**9 + 7 MAXN = N + 5 fac = [1, 1] + [0] * MAXN finv = [1, 1] + [0] * MAXN inv = [0, 1] + [0] * MAXN for i in range(2, MAXN + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def comb(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD ans = 0 for n in range(K - 1, N): c = comb(n, K - 1) mx = A[n] mn = A[-1 - n] ans += (mx - mn) * c ans %= MOD print(ans)
false
42.553191
[ "-def ncr(n, r):", "+def comb(n, r):", "-combs = []", "-l = N - K + 1", "-for i in range(l):", "- combs.append(ncr(N - l + i, i))", "-cmax = [0] * (N - l) + combs", "-cmin = combs[::-1]", "-from collections import Counter", "-", "-mins = Counter()", "-maxs = Counter()", "-for a, c in zip(A, cmax):", "- maxs[a] += c", "-for a, c in zip(A, cmin):", "- mins[a] += c", "-mx = A[-1]", "-mn = A[0]", "-ans = ncr(N, K) * (mx - mn)", "-for k, v in list(maxs.items()):", "- ans -= v * (mx - k)", "- ans %= MOD", "-for k, v in list(mins.items()):", "- ans -= v * (k - mn)", "+ans = 0", "+for n in range(K - 1, N):", "+ c = comb(n, K - 1)", "+ mx = A[n]", "+ mn = A[-1 - n]", "+ ans += (mx - mn) * c" ]
false
0.085001
0.044841
1.895622
[ "s997009961", "s258883447" ]
u678167152
p03096
python
s087438960
s530038995
1,439
982
789,140
52,120
Accepted
Accepted
31.76
from collections import defaultdict from bisect import * def solve(): mod = 10**9+7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [] ends = [-1] for l in list(d.values()): for i in range(len(l)-1): if l[i+1]-1>l[i]: selist.append([l[i],l[i+1]]) ends.append(l[i+1]) selist = [[-1,-1]]+sorted(selist,key=lambda x:x[1]) # s_ind = {} # for i,(s,e) in enumerate(selist): # e_ind[e] = i # ends = list(e_ind.keys()) ends.sort() dp = [0]*(len(selist)) for i in range(1,len(selist)): dp[i] = dp[i-1]+1 ind = bisect_right(ends,selist[i][0]) dp[i] += dp[ind-1] ans = dp[-1]+1 ans %= mod return ans print((solve()))
from collections import defaultdict from bisect import * def solve(): mod = 10**9+7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [] ends = [-1] for l in list(d.values()): for i in range(len(l)-1): if l[i+1]-1>l[i]: selist.append([l[i],l[i+1]]) ends.append(l[i+1]) selist = [[-1,-1]]+sorted(selist,key=lambda x:x[1]) # s_ind = {} # for i,(s,e) in enumerate(selist): # e_ind[e] = i # ends = list(e_ind.keys()) ends.sort() dp = [0]*(len(selist)) for i in range(1,len(selist)): dp[i] = (dp[i-1]+1)%mod ind = bisect_right(ends,selist[i][0]) dp[i] += dp[ind-1] ans = dp[-1]+1 ans %= mod return ans print((solve()))
31
31
852
858
from collections import defaultdict from bisect import * def solve(): mod = 10**9 + 7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [] ends = [-1] for l in list(d.values()): for i in range(len(l) - 1): if l[i + 1] - 1 > l[i]: selist.append([l[i], l[i + 1]]) ends.append(l[i + 1]) selist = [[-1, -1]] + sorted(selist, key=lambda x: x[1]) # s_ind = {} # for i,(s,e) in enumerate(selist): # e_ind[e] = i # ends = list(e_ind.keys()) ends.sort() dp = [0] * (len(selist)) for i in range(1, len(selist)): dp[i] = dp[i - 1] + 1 ind = bisect_right(ends, selist[i][0]) dp[i] += dp[ind - 1] ans = dp[-1] + 1 ans %= mod return ans print((solve()))
from collections import defaultdict from bisect import * def solve(): mod = 10**9 + 7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [] ends = [-1] for l in list(d.values()): for i in range(len(l) - 1): if l[i + 1] - 1 > l[i]: selist.append([l[i], l[i + 1]]) ends.append(l[i + 1]) selist = [[-1, -1]] + sorted(selist, key=lambda x: x[1]) # s_ind = {} # for i,(s,e) in enumerate(selist): # e_ind[e] = i # ends = list(e_ind.keys()) ends.sort() dp = [0] * (len(selist)) for i in range(1, len(selist)): dp[i] = (dp[i - 1] + 1) % mod ind = bisect_right(ends, selist[i][0]) dp[i] += dp[ind - 1] ans = dp[-1] + 1 ans %= mod return ans print((solve()))
false
0
[ "- dp[i] = dp[i - 1] + 1", "+ dp[i] = (dp[i - 1] + 1) % mod" ]
false
0.074698
0.094198
0.792984
[ "s087438960", "s530038995" ]
u048034149
p03545
python
s805537097
s957140813
19
17
3,064
2,940
Accepted
Accepted
10.53
a,b,c,d = list(map(str, eval(input()))) op_list = ['+', '-'] for op1 in op_list: for op2 in op_list: for op3 in op_list: f = a+op1+b+op2+c+op3+d if eval(f) == 7: print((f+'=7')) exit()
abcd = eval(input()) op = ['+', '-'] for op1 in op: for op2 in op: for op3 in op: tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3] if eval(tmp_ans) == 7: print((tmp_ans+'=7')) exit()
11
12
250
289
a, b, c, d = list(map(str, eval(input()))) op_list = ["+", "-"] for op1 in op_list: for op2 in op_list: for op3 in op_list: f = a + op1 + b + op2 + c + op3 + d if eval(f) == 7: print((f + "=7")) exit()
abcd = eval(input()) op = ["+", "-"] for op1 in op: for op2 in op: for op3 in op: tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3] if eval(tmp_ans) == 7: print((tmp_ans + "=7")) exit()
false
8.333333
[ "-a, b, c, d = list(map(str, eval(input())))", "-op_list = [\"+\", \"-\"]", "-for op1 in op_list:", "- for op2 in op_list:", "- for op3 in op_list:", "- f = a + op1 + b + op2 + c + op3 + d", "- if eval(f) == 7:", "- print((f + \"=7\"))", "+abcd = eval(input())", "+op = [\"+\", \"-\"]", "+for op1 in op:", "+ for op2 in op:", "+ for op3 in op:", "+ tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]", "+ if eval(tmp_ans) == 7:", "+ print((tmp_ans + \"=7\"))" ]
false
0.065301
0.049335
1.323622
[ "s805537097", "s957140813" ]
u271934630
p03106
python
s535284643
s576638769
189
17
38,384
3,060
Accepted
Accepted
91.01
a, b, k = list(map(int, input().split())) arr = [] for i in range(1, min(a, b)+1): if a % i == 0 and b % i == 0: arr.append(i) print((arr[-k]))
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() A, B, K = i_l() arr = [] for i in range(1, min(A, B)+1): if A % i == 0 and B % i == 0: arr.append(i) print((arr[::-1][K-1]))
8
16
157
334
a, b, k = list(map(int, input().split())) arr = [] for i in range(1, min(a, b) + 1): if a % i == 0 and b % i == 0: arr.append(i) print((arr[-k]))
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() A, B, K = i_l() arr = [] for i in range(1, min(A, B) + 1): if A % i == 0 and B % i == 0: arr.append(i) print((arr[::-1][K - 1]))
false
50
[ "-a, b, k = list(map(int, input().split()))", "+import sys", "+", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**7)", "+i_i = lambda: int(i_s())", "+i_l = lambda: list(map(int, stdin.readline().split()))", "+i_s = lambda: stdin.readline().rstrip()", "+A, B, K = i_l()", "-for i in range(1, min(a, b) + 1):", "- if a % i == 0 and b % i == 0:", "+for i in range(1, min(A, B) + 1):", "+ if A % i == 0 and B % i == 0:", "-print((arr[-k]))", "+print((arr[::-1][K - 1]))" ]
false
0.11776
0.036732
3.205968
[ "s535284643", "s576638769" ]
u638795007
p03212
python
s427012846
s311024849
351
27
55,004
3,956
Accepted
Accepted
92.31
def dfs(s,n): if int(s)>n: return 0 cur = 0 if all(s.count(c) > 0 for c in '753'): cur = 1 for c in "753": cur += dfs(s+c,n) return cur def examC(): N = I() ans = dfs("0",N) print(ans) import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float('inf') if __name__ == '__main__': examC()
def examA(): N, M = LI() l = 1; r = N for _ in range(M): L, R = LI() l = max(L,l) r = min(R,r) ans = max(0,r-l+1) print(ans) return def examB(): N = I() S = [I()for _ in range(N)] rest = [] for s in S: if s%10==0: continue rest.append(s) if sum(S)%10==0: if not rest: print((0)) return ans = sum(S) - min(rest) else: ans = sum(S) print(ans) return def examC(): N, K = LI() K -= 1 A = LI() L = A.index(1) #print(L) ans = (N-1+K-1)//K print(ans) return def examD(): def ketadp(a): n = len(a) dp = defaultdict(int) dp[0, 0, 0, 0, 0] = 1 for i, less, has3, has5, has7 in itertools.product(list(range(n)), (0, 1), (0, 1), (0,1), (0,1)): max_d = 7 if less else int(a[i]) for d in range(max_d + 1): if d==0 and has3==0 and has5==0 and has7==0: dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7] if not (d==3 or d==5 or d==7): continue less_ = less or d < max_d has3_ = has3 or d == 3 has5_ = has5 or d == 5 has7_ = has7 or d == 7 dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7] ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1)) return ans N = SI() ans = ketadp(N) print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int,readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
27
104
737
2,516
def dfs(s, n): if int(s) > n: return 0 cur = 0 if all(s.count(c) > 0 for c in "753"): cur = 1 for c in "753": cur += dfs(s + c, n) return cur def examC(): N = I() ans = dfs("0", N) print(ans) import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float("inf") if __name__ == "__main__": examC()
def examA(): N, M = LI() l = 1 r = N for _ in range(M): L, R = LI() l = max(L, l) r = min(R, r) ans = max(0, r - l + 1) print(ans) return def examB(): N = I() S = [I() for _ in range(N)] rest = [] for s in S: if s % 10 == 0: continue rest.append(s) if sum(S) % 10 == 0: if not rest: print((0)) return ans = sum(S) - min(rest) else: ans = sum(S) print(ans) return def examC(): N, K = LI() K -= 1 A = LI() L = A.index(1) # print(L) ans = (N - 1 + K - 1) // K print(ans) return def examD(): def ketadp(a): n = len(a) dp = defaultdict(int) dp[0, 0, 0, 0, 0] = 1 for i, less, has3, has5, has7 in itertools.product( list(range(n)), (0, 1), (0, 1), (0, 1), (0, 1) ): max_d = 7 if less else int(a[i]) for d in range(max_d + 1): if d == 0 and has3 == 0 and has5 == 0 and has7 == 0: dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7] if not (d == 3 or d == 5 or d == 7): continue less_ = less or d < max_d has3_ = has3 or d == 3 has5_ = has5 or d == 5 has7_ = has7 or d == 7 dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7] ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1)) return ans N = SI() ans = ketadp(N) print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int, readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
false
74.038462
[ "-def dfs(s, n):", "- if int(s) > n:", "- return 0", "- cur = 0", "- if all(s.count(c) > 0 for c in \"753\"):", "- cur = 1", "- for c in \"753\":", "- cur += dfs(s + c, n)", "- return cur", "+def examA():", "+ N, M = LI()", "+ l = 1", "+ r = N", "+ for _ in range(M):", "+ L, R = LI()", "+ l = max(L, l)", "+ r = min(R, r)", "+ ans = max(0, r - l + 1)", "+ print(ans)", "+ return", "+", "+", "+def examB():", "+ N = I()", "+ S = [I() for _ in range(N)]", "+ rest = []", "+ for s in S:", "+ if s % 10 == 0:", "+ continue", "+ rest.append(s)", "+ if sum(S) % 10 == 0:", "+ if not rest:", "+ print((0))", "+ return", "+ ans = sum(S) - min(rest)", "+ else:", "+ ans = sum(S)", "+ print(ans)", "+ return", "- N = I()", "- ans = dfs(\"0\", N)", "+ N, K = LI()", "+ K -= 1", "+ A = LI()", "+ L = A.index(1)", "+ # print(L)", "+ ans = (N - 1 + K - 1) // K", "+ return", "-import sys, copy, bisect, itertools, heapq, math", "+def examD():", "+ def ketadp(a):", "+ n = len(a)", "+ dp = defaultdict(int)", "+ dp[0, 0, 0, 0, 0] = 1", "+ for i, less, has3, has5, has7 in itertools.product(", "+ list(range(n)), (0, 1), (0, 1), (0, 1), (0, 1)", "+ ):", "+ max_d = 7 if less else int(a[i])", "+ for d in range(max_d + 1):", "+ if d == 0 and has3 == 0 and has5 == 0 and has7 == 0:", "+ dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7]", "+ if not (d == 3 or d == 5 or d == 7):", "+ continue", "+ less_ = less or d < max_d", "+ has3_ = has3 or d == 3", "+ has5_ = has5 or d == 5", "+ has7_ = has7 or d == 7", "+ dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7]", "+ ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1))", "+ return ans", "+", "+ N = SI()", "+ ans = ketadp(N)", "+ print(ans)", "+ return", "+", "+", "+def examE():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+import sys, bisect, itertools, heapq, math, random", "+from copy import deepcopy", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+", "- return int(sys.stdin.readline())", "+ return int(readline())", "- return list(map(int, sys.stdin.readline().split()))", "+ return list(map(int, readline().split()))", "+global mod, mod2, inf, alphabet, _ep", "-inf = float(\"inf\")", "+mod2 = 998244353", "+inf = 10**18", "+_ep = 10 ** (-12)", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+sys.setrecursionlimit(10**7)", "- examC()", "+ examD()", "+\"\"\"", "+142", "+12 9 1445 0 1", "+asd dfg hj o o", "+aidn", "+\"\"\"" ]
false
0.115847
0.037274
3.107957
[ "s427012846", "s311024849" ]
u226108478
p03807
python
s188470961
s663740206
56
42
14,104
14,108
Accepted
Accepted
25
# -*- coding: utf-8 -*- # AtCoder Grand Contest # Problem A if __name__ == '__main__': n = int(eval(input())) a = list(map(int, input().split())) odd_count = 0 for ai in a: if ai % 2 == 1: odd_count += 1 even_count = n - odd_count if odd_count % 2 == 1: if even_count > 0: print('NO') exit() elif even_count == 0 and odd_count == 1: print('NO') exit() else: print('YES') exit() else: print('YES') exit()
# -*- coding: utf-8 -*- # AtCoder Grand Contest # Problem A if __name__ == '__main__': n = int(eval(input())) if sum(list(map(int, input().split()))) % 2 == 0: print('YES') else: print('NO')
30
12
593
227
# -*- coding: utf-8 -*- # AtCoder Grand Contest # Problem A if __name__ == "__main__": n = int(eval(input())) a = list(map(int, input().split())) odd_count = 0 for ai in a: if ai % 2 == 1: odd_count += 1 even_count = n - odd_count if odd_count % 2 == 1: if even_count > 0: print("NO") exit() elif even_count == 0 and odd_count == 1: print("NO") exit() else: print("YES") exit() else: print("YES") exit()
# -*- coding: utf-8 -*- # AtCoder Grand Contest # Problem A if __name__ == "__main__": n = int(eval(input())) if sum(list(map(int, input().split()))) % 2 == 0: print("YES") else: print("NO")
false
60
[ "- a = list(map(int, input().split()))", "- odd_count = 0", "- for ai in a:", "- if ai % 2 == 1:", "- odd_count += 1", "- even_count = n - odd_count", "- if odd_count % 2 == 1:", "- if even_count > 0:", "- print(\"NO\")", "- exit()", "- elif even_count == 0 and odd_count == 1:", "- print(\"NO\")", "- exit()", "- else:", "- print(\"YES\")", "- exit()", "+ if sum(list(map(int, input().split()))) % 2 == 0:", "+ print(\"YES\")", "- print(\"YES\")", "- exit()", "+ print(\"NO\")" ]
false
0.036998
0.035679
1.036972
[ "s188470961", "s663740206" ]
u360116509
p03111
python
s807634038
s732014969
554
79
3,188
3,064
Accepted
Accepted
85.74
N, A, B, C = map(int, input().split()) def f(a, b, c, bl, ans): if len(bl) == 0: if len(a) == 0 or len(b) == 0 or len(c) == 0: return ans return abs(A - sum(a)) + (len(a) - 1) * 10 + \ abs(B - sum(b)) + (len(b) - 1) * 10 + \ abs(C - sum(c)) + (len(c) - 1) * 10 for i in range(len(bl)): l = bl[i] a.append(l) ans = min(ans, f(a, b, c, bl[i + 1:], ans)) a.pop(-1) b.append(l) ans = min(ans, f(a, b, c, bl[i + 1:], ans)) b.pop(-1) c.append(l) ans = min(ans, f(a, b, c, bl[i + 1:], ans)) c.pop(-1) ans = min(ans, f(a, b, c, bl[i + 1:], ans)) return ans def main(): bl = [] for _ in range(N): bl.append(int(input())) print(f([], [], [], bl, 10000)) main()
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] def f(a, b, c, i): if i == N: if min(a, b, c) == 0: return float('inf') return abs(A - a) + abs(B - b) + abs(C - c) - 30 al = f(a + L[i], b, c, i + 1) + 10 bl = f(a, b + L[i], c, i + 1) + 10 cl = f(a, b, c + L[i], i + 1) + 10 dl = f(a, b, c, i + 1) return min(al, bl, cl, dl) def main(): print((f(0, 0, 0, 0))) main()
33
21
861
474
N, A, B, C = map(int, input().split()) def f(a, b, c, bl, ans): if len(bl) == 0: if len(a) == 0 or len(b) == 0 or len(c) == 0: return ans return ( abs(A - sum(a)) + (len(a) - 1) * 10 + abs(B - sum(b)) + (len(b) - 1) * 10 + abs(C - sum(c)) + (len(c) - 1) * 10 ) for i in range(len(bl)): l = bl[i] a.append(l) ans = min(ans, f(a, b, c, bl[i + 1 :], ans)) a.pop(-1) b.append(l) ans = min(ans, f(a, b, c, bl[i + 1 :], ans)) b.pop(-1) c.append(l) ans = min(ans, f(a, b, c, bl[i + 1 :], ans)) c.pop(-1) ans = min(ans, f(a, b, c, bl[i + 1 :], ans)) return ans def main(): bl = [] for _ in range(N): bl.append(int(input())) print(f([], [], [], bl, 10000)) main()
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] def f(a, b, c, i): if i == N: if min(a, b, c) == 0: return float("inf") return abs(A - a) + abs(B - b) + abs(C - c) - 30 al = f(a + L[i], b, c, i + 1) + 10 bl = f(a, b + L[i], c, i + 1) + 10 cl = f(a, b, c + L[i], i + 1) + 10 dl = f(a, b, c, i + 1) return min(al, bl, cl, dl) def main(): print((f(0, 0, 0, 0))) main()
false
36.363636
[ "-N, A, B, C = map(int, input().split())", "+N, A, B, C = list(map(int, input().split()))", "+L = [int(eval(input())) for _ in range(N)]", "-def f(a, b, c, bl, ans):", "- if len(bl) == 0:", "- if len(a) == 0 or len(b) == 0 or len(c) == 0:", "- return ans", "- return (", "- abs(A - sum(a))", "- + (len(a) - 1) * 10", "- + abs(B - sum(b))", "- + (len(b) - 1) * 10", "- + abs(C - sum(c))", "- + (len(c) - 1) * 10", "- )", "- for i in range(len(bl)):", "- l = bl[i]", "- a.append(l)", "- ans = min(ans, f(a, b, c, bl[i + 1 :], ans))", "- a.pop(-1)", "- b.append(l)", "- ans = min(ans, f(a, b, c, bl[i + 1 :], ans))", "- b.pop(-1)", "- c.append(l)", "- ans = min(ans, f(a, b, c, bl[i + 1 :], ans))", "- c.pop(-1)", "- ans = min(ans, f(a, b, c, bl[i + 1 :], ans))", "- return ans", "+def f(a, b, c, i):", "+ if i == N:", "+ if min(a, b, c) == 0:", "+ return float(\"inf\")", "+ return abs(A - a) + abs(B - b) + abs(C - c) - 30", "+ al = f(a + L[i], b, c, i + 1) + 10", "+ bl = f(a, b + L[i], c, i + 1) + 10", "+ cl = f(a, b, c + L[i], i + 1) + 10", "+ dl = f(a, b, c, i + 1)", "+ return min(al, bl, cl, dl)", "- bl = []", "- for _ in range(N):", "- bl.append(int(input()))", "- print(f([], [], [], bl, 10000))", "+ print((f(0, 0, 0, 0)))" ]
false
0.041324
0.059489
0.694641
[ "s807634038", "s732014969" ]
u562935282
p02820
python
s707031657
s597952478
325
44
22,604
3,316
Accepted
Accepted
86.46
def solve(r, s, p, t) -> int: R, S, P = 0, 1, 2 n = len(t) dp = [[0] * 3 for _ in range(n + 1)] for i, c in enumerate(t, 1): dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == 's' else 0) dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == 'p' else 0) dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == 'r' else 0) return max(dp[n]) def main(): n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) ret = 0 for i in range(k): ti = t[i::k] ret += solve(r, s, p, ti) print(ret) if __name__ == '__main__': main() # mod Kで小問題に分割して、 # 独立なk個の問題を解く
def main(): N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = eval(input()) score = {'r': P, 's': R, 'p': S} ret = 0 for r in range(K): i = r p = '' while i < N: if T[i] == p: p = '' else: ret += score[T[i]] p = T[i] i += K print(ret) if __name__ == '__main__': main()
32
23
712
452
def solve(r, s, p, t) -> int: R, S, P = 0, 1, 2 n = len(t) dp = [[0] * 3 for _ in range(n + 1)] for i, c in enumerate(t, 1): dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == "s" else 0) dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == "p" else 0) dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == "r" else 0) return max(dp[n]) def main(): n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) ret = 0 for i in range(k): ti = t[i::k] ret += solve(r, s, p, ti) print(ret) if __name__ == "__main__": main() # mod Kで小問題に分割して、 # 独立なk個の問題を解く
def main(): N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = eval(input()) score = {"r": P, "s": R, "p": S} ret = 0 for r in range(K): i = r p = "" while i < N: if T[i] == p: p = "" else: ret += score[T[i]] p = T[i] i += K print(ret) if __name__ == "__main__": main()
false
28.125
[ "-def solve(r, s, p, t) -> int:", "- R, S, P = 0, 1, 2", "- n = len(t)", "- dp = [[0] * 3 for _ in range(n + 1)]", "- for i, c in enumerate(t, 1):", "- dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == \"s\" else 0)", "- dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == \"p\" else 0)", "- dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == \"r\" else 0)", "- return max(dp[n])", "-", "-", "- n, k = list(map(int, input().split()))", "- r, s, p = list(map(int, input().split()))", "- t = eval(input())", "+ N, K = list(map(int, input().split()))", "+ R, S, P = list(map(int, input().split()))", "+ T = eval(input())", "+ score = {\"r\": P, \"s\": R, \"p\": S}", "- for i in range(k):", "- ti = t[i::k]", "- ret += solve(r, s, p, ti)", "+ for r in range(K):", "+ i = r", "+ p = \"\"", "+ while i < N:", "+ if T[i] == p:", "+ p = \"\"", "+ else:", "+ ret += score[T[i]]", "+ p = T[i]", "+ i += K", "-# mod Kで小問題に分割して、", "-# 独立なk個の問題を解く" ]
false
0.035684
0.043327
0.823582
[ "s707031657", "s597952478" ]
u762420987
p03273
python
s694524800
s917142125
33
25
3,700
3,188
Accepted
Accepted
24.24
from copy import deepcopy H, W = list(map(int, input().split())) alist = [list(eval(input())) for _ in range(H)] acopy = deepcopy(alist) counter = 0 for i in range(W): for a in alist: if a[i] == "#": break else: for a in acopy: a.pop(i - counter) counter += 1 for a in acopy: if "#" in a: print(("".join(a)))
H, W = list(map(int, input().split())) graph = [list(eval(input())) for _ in range(H)] flg = True while flg: loop = False for i in range(len(graph)): if "#" not in graph[i]: graph.pop(i) loop = True break if loop: continue for j in range(len(graph[0])): tate = [line[j] for line in graph] if "#" not in tate: for i in range(len(graph)): graph[i].pop(j) break else: flg = False for line in graph: print(("".join(line)))
17
22
380
566
from copy import deepcopy H, W = list(map(int, input().split())) alist = [list(eval(input())) for _ in range(H)] acopy = deepcopy(alist) counter = 0 for i in range(W): for a in alist: if a[i] == "#": break else: for a in acopy: a.pop(i - counter) counter += 1 for a in acopy: if "#" in a: print(("".join(a)))
H, W = list(map(int, input().split())) graph = [list(eval(input())) for _ in range(H)] flg = True while flg: loop = False for i in range(len(graph)): if "#" not in graph[i]: graph.pop(i) loop = True break if loop: continue for j in range(len(graph[0])): tate = [line[j] for line in graph] if "#" not in tate: for i in range(len(graph)): graph[i].pop(j) break else: flg = False for line in graph: print(("".join(line)))
false
22.727273
[ "-from copy import deepcopy", "-", "-alist = [list(eval(input())) for _ in range(H)]", "-acopy = deepcopy(alist)", "-counter = 0", "-for i in range(W):", "- for a in alist:", "- if a[i] == \"#\":", "+graph = [list(eval(input())) for _ in range(H)]", "+flg = True", "+while flg:", "+ loop = False", "+ for i in range(len(graph)):", "+ if \"#\" not in graph[i]:", "+ graph.pop(i)", "+ loop = True", "+ break", "+ if loop:", "+ continue", "+ for j in range(len(graph[0])):", "+ tate = [line[j] for line in graph]", "+ if \"#\" not in tate:", "+ for i in range(len(graph)):", "+ graph[i].pop(j)", "- for a in acopy:", "- a.pop(i - counter)", "- counter += 1", "-for a in acopy:", "- if \"#\" in a:", "- print((\"\".join(a)))", "+ flg = False", "+for line in graph:", "+ print((\"\".join(line)))" ]
false
0.0395
0.040908
0.96558
[ "s694524800", "s917142125" ]
u077898957
p03712
python
s073555646
s116092657
26
21
4,596
4,596
Accepted
Accepted
19.23
h,w = map(int,input().split()) A = [list(input()) for i in range(h)] B = [['']*(w+2)]*(h+2) for i in range(h+2): for j in range(w+2): if i==0 or i==h+1: B[i][j]='#' elif j == 0 or j == w+1: B[i][j]='#' else: B[i][j]=A[i-1][j-1] print(*B[i],sep='')
h,w=map(int,input().split()) ans=[['' for i in range(w+2)] for j in range(h+2)] ans[0] = ['#' for i in range(w+2)] ans[-1] = ['#' for i in range(w+2)] for i in range(h): ans[i+1][1:w+1] = list(input()) ans[i+1][0] = '#' ans[i+1][-1] = '#' for i in range(h+2): print(*ans[i],sep='')
12
10
326
298
h, w = map(int, input().split()) A = [list(input()) for i in range(h)] B = [[""] * (w + 2)] * (h + 2) for i in range(h + 2): for j in range(w + 2): if i == 0 or i == h + 1: B[i][j] = "#" elif j == 0 or j == w + 1: B[i][j] = "#" else: B[i][j] = A[i - 1][j - 1] print(*B[i], sep="")
h, w = map(int, input().split()) ans = [["" for i in range(w + 2)] for j in range(h + 2)] ans[0] = ["#" for i in range(w + 2)] ans[-1] = ["#" for i in range(w + 2)] for i in range(h): ans[i + 1][1 : w + 1] = list(input()) ans[i + 1][0] = "#" ans[i + 1][-1] = "#" for i in range(h + 2): print(*ans[i], sep="")
false
16.666667
[ "-A = [list(input()) for i in range(h)]", "-B = [[\"\"] * (w + 2)] * (h + 2)", "+ans = [[\"\" for i in range(w + 2)] for j in range(h + 2)]", "+ans[0] = [\"#\" for i in range(w + 2)]", "+ans[-1] = [\"#\" for i in range(w + 2)]", "+for i in range(h):", "+ ans[i + 1][1 : w + 1] = list(input())", "+ ans[i + 1][0] = \"#\"", "+ ans[i + 1][-1] = \"#\"", "- for j in range(w + 2):", "- if i == 0 or i == h + 1:", "- B[i][j] = \"#\"", "- elif j == 0 or j == w + 1:", "- B[i][j] = \"#\"", "- else:", "- B[i][j] = A[i - 1][j - 1]", "- print(*B[i], sep=\"\")", "+ print(*ans[i], sep=\"\")" ]
false
0.041719
0.099894
0.417633
[ "s073555646", "s116092657" ]
u693953100
p03821
python
s781482819
s445469844
368
326
11,816
11,048
Accepted
Accepted
11.41
n = int(eval(input())) a = [] b = [] for i in range(n): x,y = list(map(int,input().split())) a.append(x) b.append(y) a = a[::-1] b = b[::-1] cnt = 0 for i in range(n): if (a[i]+cnt)%b[i]: cnt+=b[i]-(a[i]+cnt)%b[i] print(cnt)
def solve(): n = int(eval(input())) a = [] b = [] for _ in range(n): x,y = list(map(int,input().split())) a.append(x) b.append(y) ans = 0 for i in range(n)[::-1]: if (a[i]+ans)%b[i]: ans+=b[i]-(a[i]+ans)%b[i] print(ans) if __name__=='__main__': solve()
14
15
249
330
n = int(eval(input())) a = [] b = [] for i in range(n): x, y = list(map(int, input().split())) a.append(x) b.append(y) a = a[::-1] b = b[::-1] cnt = 0 for i in range(n): if (a[i] + cnt) % b[i]: cnt += b[i] - (a[i] + cnt) % b[i] print(cnt)
def solve(): n = int(eval(input())) a = [] b = [] for _ in range(n): x, y = list(map(int, input().split())) a.append(x) b.append(y) ans = 0 for i in range(n)[::-1]: if (a[i] + ans) % b[i]: ans += b[i] - (a[i] + ans) % b[i] print(ans) if __name__ == "__main__": solve()
false
6.666667
[ "-n = int(eval(input()))", "-a = []", "-b = []", "-for i in range(n):", "- x, y = list(map(int, input().split()))", "- a.append(x)", "- b.append(y)", "-a = a[::-1]", "-b = b[::-1]", "-cnt = 0", "-for i in range(n):", "- if (a[i] + cnt) % b[i]:", "- cnt += b[i] - (a[i] + cnt) % b[i]", "-print(cnt)", "+def solve():", "+ n = int(eval(input()))", "+ a = []", "+ b = []", "+ for _ in range(n):", "+ x, y = list(map(int, input().split()))", "+ a.append(x)", "+ b.append(y)", "+ ans = 0", "+ for i in range(n)[::-1]:", "+ if (a[i] + ans) % b[i]:", "+ ans += b[i] - (a[i] + ans) % b[i]", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.047944
0.069965
0.685254
[ "s781482819", "s445469844" ]
u094191970
p03107
python
s609198488
s740820876
21
18
3,956
3,188
Accepted
Accepted
14.29
S = eval(input()) S_list = list(S) a = S_list.count('0') b = S_list.count('1') print((len(S_list) - abs(a - b)))
s=eval(input()) print((min(s.count('0'),s.count('1'))*2))
5
2
108
50
S = eval(input()) S_list = list(S) a = S_list.count("0") b = S_list.count("1") print((len(S_list) - abs(a - b)))
s = eval(input()) print((min(s.count("0"), s.count("1")) * 2))
false
60
[ "-S = eval(input())", "-S_list = list(S)", "-a = S_list.count(\"0\")", "-b = S_list.count(\"1\")", "-print((len(S_list) - abs(a - b)))", "+s = eval(input())", "+print((min(s.count(\"0\"), s.count(\"1\")) * 2))" ]
false
0.048396
0.041282
1.172346
[ "s609198488", "s740820876" ]
u196368253
p03289
python
s813583929
s463084926
189
174
38,292
38,256
Accepted
Accepted
7.94
import re S = eval(input()) flag_1 = False flag_2 = False flag_3 = False if S[0] == 'A': flag_1 = True if S[2:-1].count('C') == 1: flag_2 = True if flag_1 == True and flag_2 == True: if len(re.findall('[A-Z]', S)) == 2: flag_3 = True if flag_1 == True and flag_2 == True and flag_3 == True: print('AC') else: print('WA')
S = eval(input()) if S[0] == 'A' and S[2:-1].count('C') == 1 and S[1:].replace('C', '', 1).islower(): print('AC') else: print('WA')
17
5
351
137
import re S = eval(input()) flag_1 = False flag_2 = False flag_3 = False if S[0] == "A": flag_1 = True if S[2:-1].count("C") == 1: flag_2 = True if flag_1 == True and flag_2 == True: if len(re.findall("[A-Z]", S)) == 2: flag_3 = True if flag_1 == True and flag_2 == True and flag_3 == True: print("AC") else: print("WA")
S = eval(input()) if S[0] == "A" and S[2:-1].count("C") == 1 and S[1:].replace("C", "", 1).islower(): print("AC") else: print("WA")
false
70.588235
[ "-import re", "-", "-flag_1 = False", "-flag_2 = False", "-flag_3 = False", "-if S[0] == \"A\":", "- flag_1 = True", "-if S[2:-1].count(\"C\") == 1:", "- flag_2 = True", "-if flag_1 == True and flag_2 == True:", "- if len(re.findall(\"[A-Z]\", S)) == 2:", "- flag_3 = True", "-if flag_1 == True and flag_2 == True and flag_3 == True:", "+if S[0] == \"A\" and S[2:-1].count(\"C\") == 1 and S[1:].replace(\"C\", \"\", 1).islower():" ]
false
0.050391
0.045401
1.109913
[ "s813583929", "s463084926" ]
u321035578
p03037
python
s568999951
s513161963
362
319
11,008
3,188
Accepted
Accepted
11.88
n,m = list(map(int,input().split())) l = [] r = [] low = 0 high = 10 ** 5 + 1 for i in range(m): ll,rr = list(map(int,input().split())) l.append(ll) r.append(rr) low = max(low,ll) high = min(high,rr) if high>=low: print((high-low+1)) else: print((0))
n,m = list(map(int,input().split())) low = 0 high = 10 ** 5 + 1 for i in range(m): ll,rr = list(map(int,input().split())) low = max(low,ll) high = min(high,rr) if high>=low: print((high-low+1)) else: print((0))
16
14
279
235
n, m = list(map(int, input().split())) l = [] r = [] low = 0 high = 10**5 + 1 for i in range(m): ll, rr = list(map(int, input().split())) l.append(ll) r.append(rr) low = max(low, ll) high = min(high, rr) if high >= low: print((high - low + 1)) else: print((0))
n, m = list(map(int, input().split())) low = 0 high = 10**5 + 1 for i in range(m): ll, rr = list(map(int, input().split())) low = max(low, ll) high = min(high, rr) if high >= low: print((high - low + 1)) else: print((0))
false
12.5
[ "-l = []", "-r = []", "- l.append(ll)", "- r.append(rr)" ]
false
0.089006
0.07121
1.24991
[ "s568999951", "s513161963" ]
u863044225
p02820
python
s129394789
s863952713
579
392
20,972
20,980
Accepted
Accepted
32.3
n,k=list(map(int,input().split())) p=list(map(int,input().split())) t=eval(input()) s='rsp' dp=[[-10**10]*(n+k) for _ in range(3)] for i in range(k): for j in range(3): dp[j][i]=0 for i in range(n): for j in range(3): for l in range(3): if j==l: continue res=((s.index(t[i])-l+3)%3==1)*p[l] if dp[l][i+k]<dp[j][i]+res: dp[l][i+k]=dp[j][i]+res ans=0 for i in range(n,n+k): ans+=max(dp[0][i],dp[1][i],dp[2][i]) print(ans)
def main(): n,k=list(map(int,input().split())) p=list(map(int,input().split())) t=eval(input()) s='rsp' dp=[[-10**10]*(n+k) for _ in range(3)] for i in range(k): for j in range(3): dp[j][i]=0 for i in range(n): for j in range(3): for l in range(3): if j==l: continue res=((s.index(t[i])-l+3)%3==1)*p[l] if dp[l][i+k]<dp[j][i]+res: dp[l][i+k]=dp[j][i]+res ans=0 for i in range(n,n+k): ans+=max(dp[0][i],dp[1][i],dp[2][i]) print(ans) main()
20
22
474
535
n, k = list(map(int, input().split())) p = list(map(int, input().split())) t = eval(input()) s = "rsp" dp = [[-(10**10)] * (n + k) for _ in range(3)] for i in range(k): for j in range(3): dp[j][i] = 0 for i in range(n): for j in range(3): for l in range(3): if j == l: continue res = ((s.index(t[i]) - l + 3) % 3 == 1) * p[l] if dp[l][i + k] < dp[j][i] + res: dp[l][i + k] = dp[j][i] + res ans = 0 for i in range(n, n + k): ans += max(dp[0][i], dp[1][i], dp[2][i]) print(ans)
def main(): n, k = list(map(int, input().split())) p = list(map(int, input().split())) t = eval(input()) s = "rsp" dp = [[-(10**10)] * (n + k) for _ in range(3)] for i in range(k): for j in range(3): dp[j][i] = 0 for i in range(n): for j in range(3): for l in range(3): if j == l: continue res = ((s.index(t[i]) - l + 3) % 3 == 1) * p[l] if dp[l][i + k] < dp[j][i] + res: dp[l][i + k] = dp[j][i] + res ans = 0 for i in range(n, n + k): ans += max(dp[0][i], dp[1][i], dp[2][i]) print(ans) main()
false
9.090909
[ "-n, k = list(map(int, input().split()))", "-p = list(map(int, input().split()))", "-t = eval(input())", "-s = \"rsp\"", "-dp = [[-(10**10)] * (n + k) for _ in range(3)]", "-for i in range(k):", "- for j in range(3):", "- dp[j][i] = 0", "-for i in range(n):", "- for j in range(3):", "- for l in range(3):", "- if j == l:", "- continue", "- res = ((s.index(t[i]) - l + 3) % 3 == 1) * p[l]", "- if dp[l][i + k] < dp[j][i] + res:", "- dp[l][i + k] = dp[j][i] + res", "-ans = 0", "-for i in range(n, n + k):", "- ans += max(dp[0][i], dp[1][i], dp[2][i])", "-print(ans)", "+def main():", "+ n, k = list(map(int, input().split()))", "+ p = list(map(int, input().split()))", "+ t = eval(input())", "+ s = \"rsp\"", "+ dp = [[-(10**10)] * (n + k) for _ in range(3)]", "+ for i in range(k):", "+ for j in range(3):", "+ dp[j][i] = 0", "+ for i in range(n):", "+ for j in range(3):", "+ for l in range(3):", "+ if j == l:", "+ continue", "+ res = ((s.index(t[i]) - l + 3) % 3 == 1) * p[l]", "+ if dp[l][i + k] < dp[j][i] + res:", "+ dp[l][i + k] = dp[j][i] + res", "+ ans = 0", "+ for i in range(n, n + k):", "+ ans += max(dp[0][i], dp[1][i], dp[2][i])", "+ print(ans)", "+", "+", "+main()" ]
false
0.007269
0.08978
0.080962
[ "s129394789", "s863952713" ]
u044964932
p03387
python
s927416276
s689369648
33
28
9,032
9,148
Accepted
Accepted
15.15
def main(): abc = list(map(int, input().split())) abc_sort = sorted(abc) min_num, mid_num, max_num = abc_sort Count = 0 while(max_num - min_num > 1): diff = max_num - min_num Count += diff//2 abc_sort[0] += (diff//2) * 2 abc_sort = sorted(abc_sort) max_num = abc_sort[2] min_num = abc_sort[0] if (abc_sort[2] - abc_sort[1] == 1): Count += 1 elif (abc_sort[2]-abc_sort[1] == 0 and abc_sort[1] - abc_sort[0] == 1): Count += 2 print(Count) if __name__ == "__main__": main()
def main(): abc = sorted(list(map(int, input().split()))) cnt = 0 while True: if abs(abc[2] - abc[0]) <= 1 and abs(abc[2] - abc[0]) <= 1: break abc[0] += 2 abc = sorted(abc) cnt += 1 ans = cnt if abc[0] == abc[1] and abc[1] == abc[2]: ans = cnt elif abc[2] == abc[1]: ans += 2 elif abc[0] == abc[1]: ans += 1 print(ans) if __name__ == "__main__": main()
23
22
597
482
def main(): abc = list(map(int, input().split())) abc_sort = sorted(abc) min_num, mid_num, max_num = abc_sort Count = 0 while max_num - min_num > 1: diff = max_num - min_num Count += diff // 2 abc_sort[0] += (diff // 2) * 2 abc_sort = sorted(abc_sort) max_num = abc_sort[2] min_num = abc_sort[0] if abc_sort[2] - abc_sort[1] == 1: Count += 1 elif abc_sort[2] - abc_sort[1] == 0 and abc_sort[1] - abc_sort[0] == 1: Count += 2 print(Count) if __name__ == "__main__": main()
def main(): abc = sorted(list(map(int, input().split()))) cnt = 0 while True: if abs(abc[2] - abc[0]) <= 1 and abs(abc[2] - abc[0]) <= 1: break abc[0] += 2 abc = sorted(abc) cnt += 1 ans = cnt if abc[0] == abc[1] and abc[1] == abc[2]: ans = cnt elif abc[2] == abc[1]: ans += 2 elif abc[0] == abc[1]: ans += 1 print(ans) if __name__ == "__main__": main()
false
4.347826
[ "- abc = list(map(int, input().split()))", "- abc_sort = sorted(abc)", "- min_num, mid_num, max_num = abc_sort", "- Count = 0", "- while max_num - min_num > 1:", "- diff = max_num - min_num", "- Count += diff // 2", "- abc_sort[0] += (diff // 2) * 2", "- abc_sort = sorted(abc_sort)", "- max_num = abc_sort[2]", "- min_num = abc_sort[0]", "- if abc_sort[2] - abc_sort[1] == 1:", "- Count += 1", "- elif abc_sort[2] - abc_sort[1] == 0 and abc_sort[1] - abc_sort[0] == 1:", "- Count += 2", "- print(Count)", "+ abc = sorted(list(map(int, input().split())))", "+ cnt = 0", "+ while True:", "+ if abs(abc[2] - abc[0]) <= 1 and abs(abc[2] - abc[0]) <= 1:", "+ break", "+ abc[0] += 2", "+ abc = sorted(abc)", "+ cnt += 1", "+ ans = cnt", "+ if abc[0] == abc[1] and abc[1] == abc[2]:", "+ ans = cnt", "+ elif abc[2] == abc[1]:", "+ ans += 2", "+ elif abc[0] == abc[1]:", "+ ans += 1", "+ print(ans)" ]
false
0.079532
0.044398
1.791352
[ "s927416276", "s689369648" ]
u952708174
p02912
python
s862653713
s897608592
768
135
14,180
14,180
Accepted
Accepted
82.42
def d_powerful_discount_tickets(): import heapq N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] # 参考: https://juppy.hatenablog.com/entry/2019/04/05/蟻本_Python_プライオリティキュー_2_heapq_競技プログラミン def _heappush_max(heap, item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap) - 1) def _heappop_max(heap): """Maxheap version of a heappop.""" lastelt = heap.pop() # raises appropriate IndexError if heap is empty if heap: returnitem = heap[0] heap[0] = lastelt heapq._siftup_max(heap, 0) return returnitem return lastelt heapq._heapify_max(A) for _ in range(M): _heappush_max(A, _heappop_max(A) // 2) return sum(A) print((d_powerful_discount_tickets()))
def d_powerful_discount_tickets(): from heapq import heapify, heappop, heappush N, M = [int(i) for i in input().split()] A = [-int(i) for i in input().split()] heapify(A) for _ in range(M): heappush(A, -(-heappop(A) // 2)) return -sum(A) print((d_powerful_discount_tickets()))
26
11
850
318
def d_powerful_discount_tickets(): import heapq N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] # 参考: https://juppy.hatenablog.com/entry/2019/04/05/蟻本_Python_プライオリティキュー_2_heapq_競技プログラミン def _heappush_max(heap, item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap) - 1) def _heappop_max(heap): """Maxheap version of a heappop.""" lastelt = heap.pop() # raises appropriate IndexError if heap is empty if heap: returnitem = heap[0] heap[0] = lastelt heapq._siftup_max(heap, 0) return returnitem return lastelt heapq._heapify_max(A) for _ in range(M): _heappush_max(A, _heappop_max(A) // 2) return sum(A) print((d_powerful_discount_tickets()))
def d_powerful_discount_tickets(): from heapq import heapify, heappop, heappush N, M = [int(i) for i in input().split()] A = [-int(i) for i in input().split()] heapify(A) for _ in range(M): heappush(A, -(-heappop(A) // 2)) return -sum(A) print((d_powerful_discount_tickets()))
false
57.692308
[ "- import heapq", "+ from heapq import heapify, heappop, heappush", "- A = [int(i) for i in input().split()]", "- # 参考: https://juppy.hatenablog.com/entry/2019/04/05/蟻本_Python_プライオリティキュー_2_heapq_競技プログラミン", "- def _heappush_max(heap, item):", "- heap.append(item)", "- heapq._siftdown_max(heap, 0, len(heap) - 1)", "-", "- def _heappop_max(heap):", "- \"\"\"Maxheap version of a heappop.\"\"\"", "- lastelt = heap.pop() # raises appropriate IndexError if heap is empty", "- if heap:", "- returnitem = heap[0]", "- heap[0] = lastelt", "- heapq._siftup_max(heap, 0)", "- return returnitem", "- return lastelt", "-", "- heapq._heapify_max(A)", "+ A = [-int(i) for i in input().split()]", "+ heapify(A)", "- _heappush_max(A, _heappop_max(A) // 2)", "- return sum(A)", "+ heappush(A, -(-heappop(A) // 2))", "+ return -sum(A)" ]
false
0.065777
0.050423
1.304505
[ "s862653713", "s897608592" ]
u280667879
p03653
python
s161592289
s007122973
1,138
754
106,180
39,200
Accepted
Accepted
33.74
from heapq import*;X,Y,Z=list(map(int,input().split()));N=X+Y+Z;A=[];q1=[];q2=[];L=[0];R=[0] for _ in[0]*N:A.append([int(e)for e in input().split()]) A.sort(key=lambda a:a[0]-a[1]) for i in range(N): L+=[L[i]+A[i][1]];heappush(q1,A[i][1]-A[i][2]);R+=[R[i]+A[-1-i][0]];heappush(q2,A[~i][0]-A[~i][2]) if i>=Y:L[i+1]-=heappop(q1) if i>=X:R[i+1]-=heappop(q2) print((max(L[i]+R[~i]for i in range(Y,N-X+1))))
from heapq import* X,Y,Z=list(map(int,input().split()));N=X+Y+Z;A=[];p=[];q=[];L=[0];R=[0] for _ in[0]*N:A.append([int(e)for e in input().split()]) A.sort(key=lambda a:a[0]-a[1]) for i in range(N): L+=[L[i]+A[i][1]];heappush(p,A[i][1]-A[i][2]);R+=[R[i]+A[-1-i][0]];heappush(q,A[~i][0]-A[~i][2]) if i>=Y:L[i+1]-=heappop(p) if i>=X:R[i+1]-=heappop(q) print((max(L[i]+R[~i]for i in range(Y,N-X+1))))
8
9
404
399
from heapq import * X, Y, Z = list(map(int, input().split())) N = X + Y + Z A = [] q1 = [] q2 = [] L = [0] R = [0] for _ in [0] * N: A.append([int(e) for e in input().split()]) A.sort(key=lambda a: a[0] - a[1]) for i in range(N): L += [L[i] + A[i][1]] heappush(q1, A[i][1] - A[i][2]) R += [R[i] + A[-1 - i][0]] heappush(q2, A[~i][0] - A[~i][2]) if i >= Y: L[i + 1] -= heappop(q1) if i >= X: R[i + 1] -= heappop(q2) print((max(L[i] + R[~i] for i in range(Y, N - X + 1))))
from heapq import * X, Y, Z = list(map(int, input().split())) N = X + Y + Z A = [] p = [] q = [] L = [0] R = [0] for _ in [0] * N: A.append([int(e) for e in input().split()]) A.sort(key=lambda a: a[0] - a[1]) for i in range(N): L += [L[i] + A[i][1]] heappush(p, A[i][1] - A[i][2]) R += [R[i] + A[-1 - i][0]] heappush(q, A[~i][0] - A[~i][2]) if i >= Y: L[i + 1] -= heappop(p) if i >= X: R[i + 1] -= heappop(q) print((max(L[i] + R[~i] for i in range(Y, N - X + 1))))
false
11.111111
[ "-q1 = []", "-q2 = []", "+p = []", "+q = []", "- heappush(q1, A[i][1] - A[i][2])", "+ heappush(p, A[i][1] - A[i][2])", "- heappush(q2, A[~i][0] - A[~i][2])", "+ heappush(q, A[~i][0] - A[~i][2])", "- L[i + 1] -= heappop(q1)", "+ L[i + 1] -= heappop(p)", "- R[i + 1] -= heappop(q2)", "+ R[i + 1] -= heappop(q)" ]
false
0.056913
0.036593
1.555296
[ "s161592289", "s007122973" ]
u321035578
p02881
python
s626627408
s897975527
195
115
40,172
2,940
Accepted
Accepted
41.03
import math import copy n=int(eval(input())) i=int(n**0.5) j=0 # print(i) for i in range(i+1,0,-1): # print(i) if n==i: print((n-1)) break if n%i==0: j=n/i print((int(i+j-2))) break
def main(): n = int(eval(input())) ans = -1 for i in range(1,int(n**0.5)+1): if n % i == 0: a = i b = n // i if ans == -1: ans = a + b - 2 else: ans = min(ans,a + b - 2) print(ans) if __name__ == '__main__': main()
18
14
244
330
import math import copy n = int(eval(input())) i = int(n**0.5) j = 0 # print(i) for i in range(i + 1, 0, -1): # print(i) if n == i: print((n - 1)) break if n % i == 0: j = n / i print((int(i + j - 2))) break
def main(): n = int(eval(input())) ans = -1 for i in range(1, int(n**0.5) + 1): if n % i == 0: a = i b = n // i if ans == -1: ans = a + b - 2 else: ans = min(ans, a + b - 2) print(ans) if __name__ == "__main__": main()
false
22.222222
[ "-import math", "-import copy", "+def main():", "+ n = int(eval(input()))", "+ ans = -1", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ a = i", "+ b = n // i", "+ if ans == -1:", "+ ans = a + b - 2", "+ else:", "+ ans = min(ans, a + b - 2)", "+ print(ans)", "-n = int(eval(input()))", "-i = int(n**0.5)", "-j = 0", "-# print(i)", "-for i in range(i + 1, 0, -1):", "- # print(i)", "- if n == i:", "- print((n - 1))", "- break", "- if n % i == 0:", "- j = n / i", "- print((int(i + j - 2)))", "- break", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.115405
0.038212
3.02016
[ "s626627408", "s897975527" ]
u386819480
p03087
python
s017494949
s437030622
246
224
18,060
18,060
Accepted
Accepted
8.94
#!/usr/bin/env python3 import sys def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): ans = [] carray = [0] * N for i in range(1,N): if(S[i-1:i+1] == 'AC'): carray[i] = carray[i-1]+1 # carray[i:] = map(lambda x:x+1, carray[i:]) else: carray[i] = carray[i-1] # print(carray) for i in range(Q): # print(carray[l[i]-1:r[i]]) t = carray[r[i]-1] - carray[l[i]-1] ans.append(t) for i in range(Q): print((ans[i])) return # Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): ac = [0]*N for i in range(1,N): if(S[i-1:i+1] == 'AC'): ac[i] = ac[i-1]+1 else: ac[i] = ac[i-1] ans = [0]*Q for i in range(Q): ans[i] = ac[r[i]-1] - ac[l[i]-1] for i in ans: print(i) return # Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == '__main__': main()
43
40
1,270
1,099
#!/usr/bin/env python3 import sys def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): ans = [] carray = [0] * N for i in range(1, N): if S[i - 1 : i + 1] == "AC": carray[i] = carray[i - 1] + 1 # carray[i:] = map(lambda x:x+1, carray[i:]) else: carray[i] = carray[i - 1] # print(carray) for i in range(Q): # print(carray[l[i]-1:r[i]]) t = carray[r[i] - 1] - carray[l[i] - 1] ans.append(t) for i in range(Q): print((ans[i])) return # Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): ac = [0] * N for i in range(1, N): if S[i - 1 : i + 1] == "AC": ac[i] = ac[i - 1] + 1 else: ac[i] = ac[i - 1] ans = [0] * Q for i in range(Q): ans[i] = ac[r[i] - 1] - ac[l[i] - 1] for i in ans: print(i) return # Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) 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 Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == "__main__": main()
false
6.976744
[ "- ans = []", "- carray = [0] * N", "+ ac = [0] * N", "- carray[i] = carray[i - 1] + 1", "- # carray[i:] = map(lambda x:x+1, carray[i:])", "+ ac[i] = ac[i - 1] + 1", "- carray[i] = carray[i - 1]", "- # print(carray)", "+ ac[i] = ac[i - 1]", "+ ans = [0] * Q", "- # print(carray[l[i]-1:r[i]])", "- t = carray[r[i] - 1] - carray[l[i] - 1]", "- ans.append(t)", "- for i in range(Q):", "- print((ans[i]))", "+ ans[i] = ac[r[i] - 1] - ac[l[i] - 1]", "+ for i in ans:", "+ print(i)" ]
false
0.044368
0.040946
1.083561
[ "s017494949", "s437030622" ]
u059210959
p03379
python
s451745570
s684857672
467
206
35,384
32,852
Accepted
Accepted
55.89
# encoding:utf-8 import copy import numpy as np import random n = int(eval(input())) x = [int(i) for i in input().split()] x_sorted = sorted(x) middle = n//2 middle_num = x_sorted[middle] for i in range(n): if x[i] < middle_num: print((x_sorted[middle])) else: print((x_sorted[middle-1]))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N = int(eval(input())) X = LI() X_sort = sorted(X) # X.sort() mid = X_sort[N // 2] for i in range(N): if X[i] < mid: print((X_sort[N // 2])) else: print((X_sort[N // 2 - 1]))
17
32
322
604
# encoding:utf-8 import copy import numpy as np import random n = int(eval(input())) x = [int(i) for i in input().split()] x_sorted = sorted(x) middle = n // 2 middle_num = x_sorted[middle] for i in range(n): if x[i] < middle_num: print((x_sorted[middle])) else: print((x_sorted[middle - 1]))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N = int(eval(input())) X = LI() X_sort = sorted(X) # X.sort() mid = X_sort[N // 2] for i in range(N): if X[i] < mid: print((X_sort[N // 2])) else: print((X_sort[N // 2 - 1]))
false
46.875
[ "+#!/usr/bin/env python3", "-import numpy as np", "+import bisect # bisect_left これで二部探索の大小検索が行える", "+import fractions # 最小公倍数などはこっち", "+import math", "+import sys", "+import collections", "+from decimal import Decimal # 10進数で考慮できる", "-n = int(eval(input()))", "-x = [int(i) for i in input().split()]", "-x_sorted = sorted(x)", "-middle = n // 2", "-middle_num = x_sorted[middle]", "-for i in range(n):", "- if x[i] < middle_num:", "- print((x_sorted[middle]))", "+mod = 10**9 + 7", "+sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000", "+d = collections.deque()", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+N = int(eval(input()))", "+X = LI()", "+X_sort = sorted(X)", "+# X.sort()", "+mid = X_sort[N // 2]", "+for i in range(N):", "+ if X[i] < mid:", "+ print((X_sort[N // 2]))", "- print((x_sorted[middle - 1]))", "+ print((X_sort[N // 2 - 1]))" ]
false
0.117964
0.103744
1.137077
[ "s451745570", "s684857672" ]
u912237403
p02420
python
s158685220
s563518829
20
10
4,228
4,216
Accepted
Accepted
50
import sys p = 0 for line in sys.stdin: ls = line.strip('\n') if p == 0: if ls =='-': break letters = ls p = 1 elif p == 1: m = int(ls) p =2 elif p == 2: h = int(ls) letters = letters[h:] + letters[:h] if m > 1: m -= 1 else: print(letters) p = 0
while True: ls = input() if ls == '-': break m = int(input()) for i in range(m): h = int(input()) ls = ls[h:] + ls[:h] print(ls)
20
9
388
184
import sys p = 0 for line in sys.stdin: ls = line.strip("\n") if p == 0: if ls == "-": break letters = ls p = 1 elif p == 1: m = int(ls) p = 2 elif p == 2: h = int(ls) letters = letters[h:] + letters[:h] if m > 1: m -= 1 else: print(letters) p = 0
while True: ls = input() if ls == "-": break m = int(input()) for i in range(m): h = int(input()) ls = ls[h:] + ls[:h] print(ls)
false
55
[ "-import sys", "-", "-p = 0", "-for line in sys.stdin:", "- ls = line.strip(\"\\n\")", "- if p == 0:", "- if ls == \"-\":", "- break", "- letters = ls", "- p = 1", "- elif p == 1:", "- m = int(ls)", "- p = 2", "- elif p == 2:", "- h = int(ls)", "- letters = letters[h:] + letters[:h]", "- if m > 1:", "- m -= 1", "- else:", "- print(letters)", "- p = 0", "+while True:", "+ ls = input()", "+ if ls == \"-\":", "+ break", "+ m = int(input())", "+ for i in range(m):", "+ h = int(input())", "+ ls = ls[h:] + ls[:h]", "+ print(ls)" ]
false
0.042768
0.093315
0.458312
[ "s158685220", "s563518829" ]
u059210959
p03061
python
s290940915
s064256542
386
356
16,564
16,560
Accepted
Accepted
7.77
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import fractions from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def gcd(nums): return reduce(fractions.gcd,nums) ans = 1 A.sort() gcd1 = gcd(A) for i in range(N): A[i] //= gcd1 ans *= gcd1 gcd2 = A[0] for i in range(1,N): gcd2 = fractions.gcd(gcd2,A[i]) if gcd2 == 1: key = i break a = copy.deepcopy(A) a.remove(A[0]) if gcd(a)!=1: ans *= gcd(a) print(ans) exit() a = copy.deepcopy(A) a.remove(A[key]) if gcd(a)!=1: ans *= gcd(a) print(ans) exit() print(ans)
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import fractions from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def gcd(nums): return reduce(fractions.gcd,nums) ans = 1 A.sort() gcd1 = gcd(A) for i in range(N): A[i] //= gcd1 ans *= gcd1 gcd2 = A[0] for i in range(1,N): gcd2 = fractions.gcd(gcd2,A[i]) if gcd2 == 1: key = i break a = copy.deepcopy(A) a.remove(A[0]) b = copy.deepcopy(A) b.remove(A[key]) ans *= max(gcd(a),gcd(b)) print(ans)
46
36
735
632
# encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import fractions from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def gcd(nums): return reduce(fractions.gcd, nums) ans = 1 A.sort() gcd1 = gcd(A) for i in range(N): A[i] //= gcd1 ans *= gcd1 gcd2 = A[0] for i in range(1, N): gcd2 = fractions.gcd(gcd2, A[i]) if gcd2 == 1: key = i break a = copy.deepcopy(A) a.remove(A[0]) if gcd(a) != 1: ans *= gcd(a) print(ans) exit() a = copy.deepcopy(A) a.remove(A[key]) if gcd(a) != 1: ans *= gcd(a) print(ans) exit() print(ans)
# encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import fractions from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def gcd(nums): return reduce(fractions.gcd, nums) ans = 1 A.sort() gcd1 = gcd(A) for i in range(N): A[i] //= gcd1 ans *= gcd1 gcd2 = A[0] for i in range(1, N): gcd2 = fractions.gcd(gcd2, A[i]) if gcd2 == 1: key = i break a = copy.deepcopy(A) a.remove(A[0]) b = copy.deepcopy(A) b.remove(A[key]) ans *= max(gcd(a), gcd(b)) print(ans)
false
21.73913
[ "-if gcd(a) != 1:", "- ans *= gcd(a)", "- print(ans)", "- exit()", "-a = copy.deepcopy(A)", "-a.remove(A[key])", "-if gcd(a) != 1:", "- ans *= gcd(a)", "- print(ans)", "- exit()", "+b = copy.deepcopy(A)", "+b.remove(A[key])", "+ans *= max(gcd(a), gcd(b))" ]
false
0.061984
0.057703
1.074194
[ "s290940915", "s064256542" ]
u022979415
p03261
python
s897914387
s237228850
32
28
3,064
9,152
Accepted
Accepted
12.5
def main(): N = int(eval(input())) words = [] success = True for _ in range(N): word = eval(input()) if word in words: success = False if not words == []: if not words[-1][-1] == word[0]: success = False words.append(word) if success: print("Yes") else: print("No") if __name__ == '__main__': main()
def main(): has_said = set() n = int(eval(input())) last = "" for i in range(n): w = eval(input()) if i > 0 and (w[0] != last or w in has_said): print("No") break last = w[-1] has_said.add(w) else: print("Yes") if __name__ == '__main__': main()
20
18
424
341
def main(): N = int(eval(input())) words = [] success = True for _ in range(N): word = eval(input()) if word in words: success = False if not words == []: if not words[-1][-1] == word[0]: success = False words.append(word) if success: print("Yes") else: print("No") if __name__ == "__main__": main()
def main(): has_said = set() n = int(eval(input())) last = "" for i in range(n): w = eval(input()) if i > 0 and (w[0] != last or w in has_said): print("No") break last = w[-1] has_said.add(w) else: print("Yes") if __name__ == "__main__": main()
false
10
[ "- N = int(eval(input()))", "- words = []", "- success = True", "- for _ in range(N):", "- word = eval(input())", "- if word in words:", "- success = False", "- if not words == []:", "- if not words[-1][-1] == word[0]:", "- success = False", "- words.append(word)", "- if success:", "+ has_said = set()", "+ n = int(eval(input()))", "+ last = \"\"", "+ for i in range(n):", "+ w = eval(input())", "+ if i > 0 and (w[0] != last or w in has_said):", "+ print(\"No\")", "+ break", "+ last = w[-1]", "+ has_said.add(w)", "+ else:", "- else:", "- print(\"No\")" ]
false
0.157777
0.095808
1.646809
[ "s897914387", "s237228850" ]
u644907318
p03085
python
s225855257
s491479601
167
69
38,256
61,760
Accepted
Accepted
58.68
D = {"A":"T","T":"A","C":"G","G":"C"} b = input().strip() x = "" for i in range(len(b)): x += D[b[i]] print(x)
b = input().strip() if b=="A": print("T") elif b=="T": print("A") elif b=="C": print("G") else: print("C")
6
9
119
130
D = {"A": "T", "T": "A", "C": "G", "G": "C"} b = input().strip() x = "" for i in range(len(b)): x += D[b[i]] print(x)
b = input().strip() if b == "A": print("T") elif b == "T": print("A") elif b == "C": print("G") else: print("C")
false
33.333333
[ "-D = {\"A\": \"T\", \"T\": \"A\", \"C\": \"G\", \"G\": \"C\"}", "-x = \"\"", "-for i in range(len(b)):", "- x += D[b[i]]", "-print(x)", "+if b == \"A\":", "+ print(\"T\")", "+elif b == \"T\":", "+ print(\"A\")", "+elif b == \"C\":", "+ print(\"G\")", "+else:", "+ print(\"C\")" ]
false
0.038476
0.083125
0.462868
[ "s225855257", "s491479601" ]
u836737505
p02837
python
s698858510
s660081849
232
144
3,064
3,064
Accepted
Accepted
37.93
n = int(eval(input())) a =[] for _ in range(n): m = int(eval(input())) a.append([list(map(int, input().split())) for _ in range(m)]) c = 0 for i in range(1 << n): Flag = True for j in range(n): if ((i>>j)&1) == 1: for k in a[j]: if i>>(k[0]-1)&1 != k[1]: Flag = False if Flag == False:break else: honest = sum([i>>j&1 for j in range(n)]) c = max(c,honest) print(c)
n = int(eval(input())) a = [] for _ in range(n): m = int(eval(input())) a.append([list(map(int, input().split())) for _ in range(m)]) ans = 0 for i in range(2**n): for j in range(n): if ((i >> j) & 1) == 1: for k,l in a[j]: if ((i >> (k-1)) & 1) != l: break else: continue break else: ans = max(ans,bin(i).count('1')) print(ans)
18
19
469
455
n = int(eval(input())) a = [] for _ in range(n): m = int(eval(input())) a.append([list(map(int, input().split())) for _ in range(m)]) c = 0 for i in range(1 << n): Flag = True for j in range(n): if ((i >> j) & 1) == 1: for k in a[j]: if i >> (k[0] - 1) & 1 != k[1]: Flag = False if Flag == False: break else: honest = sum([i >> j & 1 for j in range(n)]) c = max(c, honest) print(c)
n = int(eval(input())) a = [] for _ in range(n): m = int(eval(input())) a.append([list(map(int, input().split())) for _ in range(m)]) ans = 0 for i in range(2**n): for j in range(n): if ((i >> j) & 1) == 1: for k, l in a[j]: if ((i >> (k - 1)) & 1) != l: break else: continue break else: ans = max(ans, bin(i).count("1")) print(ans)
false
5.263158
[ "-c = 0", "-for i in range(1 << n):", "- Flag = True", "+ans = 0", "+for i in range(2**n):", "- for k in a[j]:", "- if i >> (k[0] - 1) & 1 != k[1]:", "- Flag = False", "- if Flag == False:", "+ for k, l in a[j]:", "+ if ((i >> (k - 1)) & 1) != l:", "+ break", "+ else:", "+ continue", "- honest = sum([i >> j & 1 for j in range(n)])", "- c = max(c, honest)", "-print(c)", "+ ans = max(ans, bin(i).count(\"1\"))", "+print(ans)" ]
false
0.054747
0.036877
1.484574
[ "s698858510", "s660081849" ]
u696684809
p02706
python
s647121744
s474685650
35
32
9,792
10,148
Accepted
Accepted
8.57
n,m = list(map(int, input().split())) a = list(map(int, input().split())) b = 0 for i in range(m): b +=a[i] if n<b: print("-1") else: print((n-b))
n,m = list(map(int,input().split())) a = list(map(int, input().split())) b = sum(a) print((max(-1,n-b)))
9
4
152
99
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = 0 for i in range(m): b += a[i] if n < b: print("-1") else: print((n - b))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = sum(a) print((max(-1, n - b)))
false
55.555556
[ "-b = 0", "-for i in range(m):", "- b += a[i]", "-if n < b:", "- print(\"-1\")", "-else:", "- print((n - b))", "+b = sum(a)", "+print((max(-1, n - b)))" ]
false
0.039619
0.039699
0.997983
[ "s647121744", "s474685650" ]
u077291787
p03497
python
s791192846
s500822813
246
194
33,696
33,696
Accepted
Accepted
21.14
# ARC086C - Not so Diverse n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) ans = 0 for i in range(len(cnt)): if k > 0: k -= 1 continue ans += cnt[i] print(ans)
# ARC086C - Not so Diverse (ABC081C) n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) print((n - sum(cnt[:k])))
18
12
403
322
# ARC086C - Not so Diverse n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) ans = 0 for i in range(len(cnt)): if k > 0: k -= 1 continue ans += cnt[i] print(ans)
# ARC086C - Not so Diverse (ABC081C) n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) print((n - sum(cnt[:k])))
false
33.333333
[ "-# ARC086C - Not so Diverse", "+# ARC086C - Not so Diverse (ABC081C)", "-ans = 0", "-for i in range(len(cnt)):", "- if k > 0:", "- k -= 1", "- continue", "- ans += cnt[i]", "-print(ans)", "+print((n - sum(cnt[:k])))" ]
false
0.044053
0.084023
0.524298
[ "s791192846", "s500822813" ]
u088552457
p02996
python
s407982155
s964444684
1,025
880
83,468
35,464
Accepted
Accepted
14.15
n = int(eval(input())) a_list = [] b_list = [] t = [] for i in range(n): a, b = list(map(int, input().split())) t.append({"time": a, "limit": b}) a_list.append(a) b_list.append(b) s = sorted(t, key=lambda x: x["limit"]) time = 0 for ss in s: time += ss['time'] if time > ss['limit']: print('No') exit(0) print('Yes')
def count_section_by_zero(data): count = 0 flg = False start = 0 for i, d in enumerate(data): if flg is False and d != 0: count += 1 flg = True if d == 0: flg = False return count def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) def gcd(*numbers): return reduce(fractions.gcd, numbers) def gcd_list(numbers): return reduce(fractions.gcd, numbers) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 2で割り切れる回数 def divide_two(arg): c = 0 while True: if c >= 2: break if arg % 2 != 0: break arg //= 2 c += 1 return c # 素因数分解 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def main(): n = int(eval(input())) works = [] for i in range(n): t, limit = input_list() works.append((t, limit)) sw = sorted(works, key=lambda x: x[1]) total = 0 for t, limit in sw: total += t if total > limit: print('No') exit(0) print('Yes') import math import fractions import collections import itertools from functools import reduce main()
21
84
351
1,611
n = int(eval(input())) a_list = [] b_list = [] t = [] for i in range(n): a, b = list(map(int, input().split())) t.append({"time": a, "limit": b}) a_list.append(a) b_list.append(b) s = sorted(t, key=lambda x: x["limit"]) time = 0 for ss in s: time += ss["time"] if time > ss["limit"]: print("No") exit(0) print("Yes")
def count_section_by_zero(data): count = 0 flg = False start = 0 for i, d in enumerate(data): if flg is False and d != 0: count += 1 flg = True if d == 0: flg = False return count def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) def gcd(*numbers): return reduce(fractions.gcd, numbers) def gcd_list(numbers): return reduce(fractions.gcd, numbers) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 2で割り切れる回数 def divide_two(arg): c = 0 while True: if c >= 2: break if arg % 2 != 0: break arg //= 2 c += 1 return c # 素因数分解 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def main(): n = int(eval(input())) works = [] for i in range(n): t, limit = input_list() works.append((t, limit)) sw = sorted(works, key=lambda x: x[1]) total = 0 for t, limit in sw: total += t if total > limit: print("No") exit(0) print("Yes") import math import fractions import collections import itertools from functools import reduce main()
false
75
[ "-n = int(eval(input()))", "-a_list = []", "-b_list = []", "-t = []", "-for i in range(n):", "- a, b = list(map(int, input().split()))", "- t.append({\"time\": a, \"limit\": b})", "- a_list.append(a)", "- b_list.append(b)", "-s = sorted(t, key=lambda x: x[\"limit\"])", "-time = 0", "-for ss in s:", "- time += ss[\"time\"]", "- if time > ss[\"limit\"]:", "- print(\"No\")", "- exit(0)", "-print(\"Yes\")", "+def count_section_by_zero(data):", "+ count = 0", "+ flg = False", "+ start = 0", "+ for i, d in enumerate(data):", "+ if flg is False and d != 0:", "+ count += 1", "+ flg = True", "+ if d == 0:", "+ flg = False", "+ return count", "+", "+", "+def input_list():", "+ return list(map(int, input().split()))", "+", "+", "+def input_list_str():", "+ return list(map(str, input().split()))", "+", "+", "+def lcm_base(x, y):", "+ return (x * y) // fractions.gcd(x, y)", "+", "+", "+def lcm_list(numbers):", "+ return reduce(lcm_base, numbers, 1)", "+", "+", "+def gcd(*numbers):", "+ return reduce(fractions.gcd, numbers)", "+", "+", "+def gcd_list(numbers):", "+ return reduce(fractions.gcd, numbers)", "+", "+", "+def combinations_count(n, r):", "+ return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "+", "+", "+# 2で割り切れる回数", "+def divide_two(arg):", "+ c = 0", "+ while True:", "+ if c >= 2:", "+ break", "+ if arg % 2 != 0:", "+ break", "+ arg //= 2", "+ c += 1", "+ return c", "+", "+", "+# 素因数分解", "+def prime_factorize(n):", "+ a = []", "+ while n % 2 == 0:", "+ a.append(2)", "+ n //= 2", "+ f = 3", "+ while f * f <= n:", "+ if n % f == 0:", "+ a.append(f)", "+ n //= f", "+ else:", "+ f += 2", "+ if n != 1:", "+ a.append(n)", "+ return a", "+", "+", "+def main():", "+ n = int(eval(input()))", "+ works = []", "+ for i in range(n):", "+ t, limit = input_list()", "+ works.append((t, limit))", "+ sw = sorted(works, key=lambda x: x[1])", "+ total = 0", "+ for t, limit in sw:", "+ total += t", "+ if total > limit:", "+ print(\"No\")", "+ exit(0)", "+ print(\"Yes\")", "+", "+", "+import math", "+import fractions", "+import collections", "+import itertools", "+from functools import reduce", "+", "+main()" ]
false
0.07208
0.10217
0.705487
[ "s407982155", "s964444684" ]
u329675280
p02683
python
s596183160
s980917051
172
152
27,324
27,672
Accepted
Accepted
11.63
import numpy as np _,*_t=[list(map(int,i.split())) for i in open(0)] n=_[0] m=_[1] x=_[2] table=np.array(_t) value=9000000 def boolAchieve(nums): for i in range(1,m+1): if nums[i]<x: return False return True tmp=np.sum(table,axis=0) if not boolAchieve(tmp): print((-1)) exit() for i in range(1,2 ** n): #numpyで書いてみた slist=np.right_shift(i,np.arange(n)) blist=np.bitwise_and(slist,1).tolist() selects=list(map(bool,blist)) #元のコード #selects=[bool((i >> j) & 1) for j in range(n)] picks=np.sum(table[selects,:],axis=0) if not boolAchieve(picks): continue value=min(value,picks[0]) print(value)
import itertools import numpy as np _,*_t=[list(map(int,i.split())) for i in open(0)] n=_[0] m=_[1] x=_[2] table=np.array(_t) patterns=list(itertools.product([False,True], repeat=n)) value=9000000 def boolAchieve(nums): for i in range(1,m+1): if nums[i]<x: return False return True tmp=np.sum(table,axis=0) if not boolAchieve(tmp): print((-1)) exit() for i in range(1,2 ** n): selects=patterns[i] picks=np.sum(table[selects,:],axis=0) if not boolAchieve(picks): continue value=min(value,picks[0]) print(value)
38
34
676
581
import numpy as np _, *_t = [list(map(int, i.split())) for i in open(0)] n = _[0] m = _[1] x = _[2] table = np.array(_t) value = 9000000 def boolAchieve(nums): for i in range(1, m + 1): if nums[i] < x: return False return True tmp = np.sum(table, axis=0) if not boolAchieve(tmp): print((-1)) exit() for i in range(1, 2**n): # numpyで書いてみた slist = np.right_shift(i, np.arange(n)) blist = np.bitwise_and(slist, 1).tolist() selects = list(map(bool, blist)) # 元のコード # selects=[bool((i >> j) & 1) for j in range(n)] picks = np.sum(table[selects, :], axis=0) if not boolAchieve(picks): continue value = min(value, picks[0]) print(value)
import itertools import numpy as np _, *_t = [list(map(int, i.split())) for i in open(0)] n = _[0] m = _[1] x = _[2] table = np.array(_t) patterns = list(itertools.product([False, True], repeat=n)) value = 9000000 def boolAchieve(nums): for i in range(1, m + 1): if nums[i] < x: return False return True tmp = np.sum(table, axis=0) if not boolAchieve(tmp): print((-1)) exit() for i in range(1, 2**n): selects = patterns[i] picks = np.sum(table[selects, :], axis=0) if not boolAchieve(picks): continue value = min(value, picks[0]) print(value)
false
10.526316
[ "+import itertools", "+patterns = list(itertools.product([False, True], repeat=n))", "- # numpyで書いてみた", "- slist = np.right_shift(i, np.arange(n))", "- blist = np.bitwise_and(slist, 1).tolist()", "- selects = list(map(bool, blist))", "- # 元のコード", "- # selects=[bool((i >> j) & 1) for j in range(n)]", "+ selects = patterns[i]" ]
false
0.185791
0.269109
0.690395
[ "s596183160", "s980917051" ]
u186838327
p02756
python
s497602738
s019954272
1,555
380
6,244
100,864
Accepted
Accepted
75.56
import sys #input = sys.stdin.readline S = str(eval(input())) q = int(eval(input())) p = '' s = '' cur = 0 for i in range(q): query = input().split() #print(query) if len(query) == 1: if cur == 0: cur = 1 else: cur = 0 else: t, f, c = query if f == '1': if cur == 0: p = c + p else: s = s + c else: if cur == 0: s = s + c else: p = c + p ans = p+S+s if cur == 1: ans = ''.join(list(reversed(ans))) print(ans)
s = list(str(eval(input()))) q = int(eval(input())) from collections import deque s = deque(s) cnt = 0 for i in range(q): query = list(map(str, input().split())) if len(query) == 1: cnt += 1 else: t, f, c = query if f == '1': if cnt%2 == 0: s.appendleft(c) else: s.append(c) else: if cnt%2 == 0: s.append(c) else: s.appendleft(c) s = list(s) if cnt%2 == 1: s.reverse() print((''.join(s)))
33
28
628
565
import sys # input = sys.stdin.readline S = str(eval(input())) q = int(eval(input())) p = "" s = "" cur = 0 for i in range(q): query = input().split() # print(query) if len(query) == 1: if cur == 0: cur = 1 else: cur = 0 else: t, f, c = query if f == "1": if cur == 0: p = c + p else: s = s + c else: if cur == 0: s = s + c else: p = c + p ans = p + S + s if cur == 1: ans = "".join(list(reversed(ans))) print(ans)
s = list(str(eval(input()))) q = int(eval(input())) from collections import deque s = deque(s) cnt = 0 for i in range(q): query = list(map(str, input().split())) if len(query) == 1: cnt += 1 else: t, f, c = query if f == "1": if cnt % 2 == 0: s.appendleft(c) else: s.append(c) else: if cnt % 2 == 0: s.append(c) else: s.appendleft(c) s = list(s) if cnt % 2 == 1: s.reverse() print(("".join(s)))
false
15.151515
[ "-import sys", "+s = list(str(eval(input())))", "+q = int(eval(input()))", "+from collections import deque", "-# input = sys.stdin.readline", "-S = str(eval(input()))", "-q = int(eval(input()))", "-p = \"\"", "-s = \"\"", "-cur = 0", "+s = deque(s)", "+cnt = 0", "- query = input().split()", "- # print(query)", "+ query = list(map(str, input().split()))", "- if cur == 0:", "- cur = 1", "- else:", "- cur = 0", "+ cnt += 1", "- if cur == 0:", "- p = c + p", "+ if cnt % 2 == 0:", "+ s.appendleft(c)", "- s = s + c", "+ s.append(c)", "- if cur == 0:", "- s = s + c", "+ if cnt % 2 == 0:", "+ s.append(c)", "- p = c + p", "-ans = p + S + s", "-if cur == 1:", "- ans = \"\".join(list(reversed(ans)))", "-print(ans)", "+ s.appendleft(c)", "+s = list(s)", "+if cnt % 2 == 1:", "+ s.reverse()", "+print((\"\".join(s)))" ]
false
0.039527
0.037646
1.049961
[ "s497602738", "s019954272" ]
u102461423
p02998
python
s337511776
s119611354
695
590
11,336
25,060
Accepted
Accepted
15.11
# (x,a), (x,b) → (s,a)と(t,b)は同値になる → aとbを同一視 # 連結成分を作る N = int(eval(input())) U = 10 ** 5 root_x = [None] * (U+1) root_y = [None] * (U+1) size_x = [0] * (U+1) # 連結成分のxの個数 size_y = [0] * (U+1) # 連結成分のyの個数 cnt_x = [0] * (U+1) # 生成時に登場した点 cnt_y = [0] * (U+1) # 生成時に登場した点 x_to_y = [None] * (U+1) y_to_x = [None] * (U+1) def find_root(root,size,x): y = root[x] if y is None: root[x] = x size[x] = 1 return x if x == y: return y z = find_root(root,size,y) root[x] = z return z def merge(root,size,cnt,x,y): rx = find_root(root,size,x) ry = find_root(root,size,y) if rx == ry: return sx = size[rx] sy = size[ry] if sx > sy: root[ry] = rx size[rx] += sy cnt[rx] += cnt[ry] else: root[rx] = ry size[ry] += sx cnt[ry] += cnt[rx] return for _ in range(N): x,y = list(map(int,input().split())) rx = find_root(root_x,size_x,x) ry = find_root(root_y,size_y,y) cnt_x[rx] += 1 cnt_y[ry] += 1 if x_to_y[rx] is None: x_to_y[rx] = ry if y_to_x[ry] is None: y_to_x[ry] = rx merge(root_y, size_y, cnt_y, x_to_y[rx], ry) merge(root_x, size_x, cnt_x, y_to_x[ry], rx) x_to_y[root_x[rx]] = root_y[ry] y_to_x[root_y[ry]] = root_x[rx] answer = 0 for x in range(1,U+1): if root_x[x] is None: continue rx = find_root(root_x,size_x,x) if x != rx: continue y = x_to_y[x] ry = find_root(root_y,size_y,y) sx = size_x[rx] sy = size_y[ry] cnt = cnt_x[rx] answer += (sx * sy - cnt) print(answer)
from collections import defaultdict U = 10 ** 5 root = [None] * (2*U+1) N = int(eval(input())) XY = [[int(x) for x in input().split()] for _ in range(N)] def find_root(x): y = root[x] if y is None: root[x] = x return x if x == y: return y z = find_root(y) root[x] = z return z def merge(x,y): rx = find_root(x) ry = find_root(y) if rx == ry: return root[ry] = rx return for x,y in XY: merge(x,U+y) pts_cnt = defaultdict(int) x_cnt = defaultdict(int) y_cnt = defaultdict(int) for x in range(U+1): if root[x] is None: continue x_cnt[find_root(x)] += 1 for y in range(U+1,U+U+1): if root[y] is None: continue y_cnt[find_root(y)] += 1 for x,y in XY: pts_cnt[find_root(x)] += 1 answer = 0 for k,v in list(pts_cnt.items()): answer += x_cnt[k] * y_cnt[k] - v print(answer)
73
50
1,556
871
# (x,a), (x,b) → (s,a)と(t,b)は同値になる → aとbを同一視 # 連結成分を作る N = int(eval(input())) U = 10**5 root_x = [None] * (U + 1) root_y = [None] * (U + 1) size_x = [0] * (U + 1) # 連結成分のxの個数 size_y = [0] * (U + 1) # 連結成分のyの個数 cnt_x = [0] * (U + 1) # 生成時に登場した点 cnt_y = [0] * (U + 1) # 生成時に登場した点 x_to_y = [None] * (U + 1) y_to_x = [None] * (U + 1) def find_root(root, size, x): y = root[x] if y is None: root[x] = x size[x] = 1 return x if x == y: return y z = find_root(root, size, y) root[x] = z return z def merge(root, size, cnt, x, y): rx = find_root(root, size, x) ry = find_root(root, size, y) if rx == ry: return sx = size[rx] sy = size[ry] if sx > sy: root[ry] = rx size[rx] += sy cnt[rx] += cnt[ry] else: root[rx] = ry size[ry] += sx cnt[ry] += cnt[rx] return for _ in range(N): x, y = list(map(int, input().split())) rx = find_root(root_x, size_x, x) ry = find_root(root_y, size_y, y) cnt_x[rx] += 1 cnt_y[ry] += 1 if x_to_y[rx] is None: x_to_y[rx] = ry if y_to_x[ry] is None: y_to_x[ry] = rx merge(root_y, size_y, cnt_y, x_to_y[rx], ry) merge(root_x, size_x, cnt_x, y_to_x[ry], rx) x_to_y[root_x[rx]] = root_y[ry] y_to_x[root_y[ry]] = root_x[rx] answer = 0 for x in range(1, U + 1): if root_x[x] is None: continue rx = find_root(root_x, size_x, x) if x != rx: continue y = x_to_y[x] ry = find_root(root_y, size_y, y) sx = size_x[rx] sy = size_y[ry] cnt = cnt_x[rx] answer += sx * sy - cnt print(answer)
from collections import defaultdict U = 10**5 root = [None] * (2 * U + 1) N = int(eval(input())) XY = [[int(x) for x in input().split()] for _ in range(N)] def find_root(x): y = root[x] if y is None: root[x] = x return x if x == y: return y z = find_root(y) root[x] = z return z def merge(x, y): rx = find_root(x) ry = find_root(y) if rx == ry: return root[ry] = rx return for x, y in XY: merge(x, U + y) pts_cnt = defaultdict(int) x_cnt = defaultdict(int) y_cnt = defaultdict(int) for x in range(U + 1): if root[x] is None: continue x_cnt[find_root(x)] += 1 for y in range(U + 1, U + U + 1): if root[y] is None: continue y_cnt[find_root(y)] += 1 for x, y in XY: pts_cnt[find_root(x)] += 1 answer = 0 for k, v in list(pts_cnt.items()): answer += x_cnt[k] * y_cnt[k] - v print(answer)
false
31.506849
[ "-# (x,a), (x,b) → (s,a)と(t,b)は同値になる → aとbを同一視", "-# 連結成分を作る", "+from collections import defaultdict", "+", "+U = 10**5", "+root = [None] * (2 * U + 1)", "-U = 10**5", "-root_x = [None] * (U + 1)", "-root_y = [None] * (U + 1)", "-size_x = [0] * (U + 1) # 連結成分のxの個数", "-size_y = [0] * (U + 1) # 連結成分のyの個数", "-cnt_x = [0] * (U + 1) # 生成時に登場した点", "-cnt_y = [0] * (U + 1) # 生成時に登場した点", "-x_to_y = [None] * (U + 1)", "-y_to_x = [None] * (U + 1)", "+XY = [[int(x) for x in input().split()] for _ in range(N)]", "-def find_root(root, size, x):", "+def find_root(x):", "- size[x] = 1", "- z = find_root(root, size, y)", "+ z = find_root(y)", "-def merge(root, size, cnt, x, y):", "- rx = find_root(root, size, x)", "- ry = find_root(root, size, y)", "+def merge(x, y):", "+ rx = find_root(x)", "+ ry = find_root(y)", "- sx = size[rx]", "- sy = size[ry]", "- if sx > sy:", "- root[ry] = rx", "- size[rx] += sy", "- cnt[rx] += cnt[ry]", "- else:", "- root[rx] = ry", "- size[ry] += sx", "- cnt[ry] += cnt[rx]", "+ root[ry] = rx", "-for _ in range(N):", "- x, y = list(map(int, input().split()))", "- rx = find_root(root_x, size_x, x)", "- ry = find_root(root_y, size_y, y)", "- cnt_x[rx] += 1", "- cnt_y[ry] += 1", "- if x_to_y[rx] is None:", "- x_to_y[rx] = ry", "- if y_to_x[ry] is None:", "- y_to_x[ry] = rx", "- merge(root_y, size_y, cnt_y, x_to_y[rx], ry)", "- merge(root_x, size_x, cnt_x, y_to_x[ry], rx)", "- x_to_y[root_x[rx]] = root_y[ry]", "- y_to_x[root_y[ry]] = root_x[rx]", "+for x, y in XY:", "+ merge(x, U + y)", "+pts_cnt = defaultdict(int)", "+x_cnt = defaultdict(int)", "+y_cnt = defaultdict(int)", "+for x in range(U + 1):", "+ if root[x] is None:", "+ continue", "+ x_cnt[find_root(x)] += 1", "+for y in range(U + 1, U + U + 1):", "+ if root[y] is None:", "+ continue", "+ y_cnt[find_root(y)] += 1", "+for x, y in XY:", "+ pts_cnt[find_root(x)] += 1", "-for x in range(1, U + 1):", "- if root_x[x] is None:", "- continue", "- rx = find_root(root_x, size_x, x)", "- if x != rx:", "- continue", "- y = x_to_y[x]", "- ry = find_root(root_y, size_y, y)", "- sx = size_x[rx]", "- sy = size_y[ry]", "- cnt = cnt_x[rx]", "- answer += sx * sy - cnt", "+for k, v in list(pts_cnt.items()):", "+ answer += x_cnt[k] * y_cnt[k] - v" ]
false
0.072698
0.08093
0.898289
[ "s337511776", "s119611354" ]
u829796346
p02574
python
s058833116
s219173334
403
358
202,028
195,192
Accepted
Accepted
11.17
#!/usr/bin/env pypy3 # N,M = map(int,sys.stdin.readline().split()) # a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param # a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param # s = sys.stdin.readline().rstrip() # N = int(sys.stdin.readline()) # INF = float("inf") import math from collections import defaultdict pc = True n = int(eval(input())) a = list(map(int,input().split())) g = math.gcd(a[0],a[1]) for i in range(2,n): g = math.gcd(g,a[i]) M = max(a) LIMIT=max(a) minPrime = [0]*(LIMIT+1) minPrime[1] = 1 def make(): for i in range(2,LIMIT+1): if minPrime[i] == 0: minPrime[i] = i #print(i) for j in range(i+i,LIMIT+1,i): #print(i,j) if minPrime[j] == 0: minPrime[j] = i make() class Sieve_of_Eratosthenes: def __init__(self, N): self.sieve = [-1] * (N+1) for i in range(2,N+1): if self.sieve[i] == -1: for j in range(1,1+N//i): self.sieve[i*j] = i def isprime(self, num): if num <= 1: return False else: return self.sieve[num] == num def factorization(self, num): ret = set([]) while num != 1: div = self.sieve[num] ret.add(div) num //= div return ret def factrial(self,N): ret = set() while 1 != N: ret.add(minPrime[N]) N = N//minPrime[N] if N != 1: ret.add(N) return ret sofe = Sieve_of_Eratosthenes(M) ddic = defaultdict() judge = set([]) for i in a: if not pc: break #asf = sofe.factorization(i) asf = sofe.factrial(i) if judge & asf != set(): pc = False judge |= asf if pc: print("pairwise coprime") elif g == 1: print("setwise coprime") else: print("not coprime") # import sys,collections # N = int(sys.stdin.readline()) # #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = list(map(int,input().split())) # import math # # def factrial(N): # # ret = [] # # while minPrime[N] != N: # # ret.append(minPrime[N]) # # N = N//minPrime[N] # # if N != 1: # # ret.append(N) # # return ret # def factrial(N): # ret = set() # while 1 != N: # ret.add(minPrime[N]) # N = N//minPrime[N] # if N != 1: # ret.add(N) # return ret # for i in range(N): # acc = math.gcd(acc,a[i]) # if acc != 1: # print("not coprime") # exit() # pairwise = True # p = set() #all prime # for e in a: # if not pairwise: # break # f = factrial(e) # if p & f != set(): # pairwise = False # print("setwise coprime") # exit(0) # p = p | f # if pairwise: # print("pairwise coprime") # else: # print("setwise coprime")
#!/usr/bin/env pypy3 # N,M = map(int,sys.stdin.readline().split()) # a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param # a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param # s = sys.stdin.readline().rstrip() # N = int(sys.stdin.readline()) # INF = float("inf") import math from collections import defaultdict pc = True n = int(eval(input())) a = list(map(int,input().split())) g = math.gcd(a[0],a[1]) for i in range(2,n): g = math.gcd(g,a[i]) M = max(a) LIMIT=max(a) minPrime = [0]*(LIMIT+1) minPrime[1] = 1 def make(): for i in range(2,LIMIT+1): if minPrime[i] == 0: minPrime[i] = i #print(i) for j in range(i+i,LIMIT+1,i): #print(i,j) if minPrime[j] == 0: minPrime[j] = i make() class Sieve_of_Eratosthenes: def __init__(self, N): self.sieve = [-1] * (N+1) for i in range(2,N+1): if self.sieve[i] == -1: for j in range(1,1+N//i): self.sieve[i*j] = i def isprime(self, num): if num <= 1: return False else: return self.sieve[num] == num def factorization(self, num): ret = set([]) while num != 1: div = self.sieve[num] ret.add(div) num //= div return ret def factrial(N): ret = set() while 1 != N: ret.add(minPrime[N]) N = N//minPrime[N] if N != 1: ret.add(N) return ret sofe = Sieve_of_Eratosthenes(M) ddic = defaultdict() judge = set([]) for i in a: if not pc: break #asf = sofe.factorization(i) asf = factrial(i) if judge & asf != set(): pc = False judge |= asf if pc: print("pairwise coprime") elif g == 1: print("setwise coprime") else: print("not coprime") # import sys,collections # N = int(sys.stdin.readline()) # #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = list(map(int,input().split())) # import math # # def factrial(N): # # ret = [] # # while minPrime[N] != N: # # ret.append(minPrime[N]) # # N = N//minPrime[N] # # if N != 1: # # ret.append(N) # # return ret # def factrial(N): # ret = set() # while 1 != N: # ret.add(minPrime[N]) # N = N//minPrime[N] # if N != 1: # ret.add(N) # return ret # for i in range(N): # acc = math.gcd(acc,a[i]) # if acc != 1: # print("not coprime") # exit() # pairwise = True # p = set() #all prime # for e in a: # if not pairwise: # break # f = factrial(e) # if p & f != set(): # pairwise = False # print("setwise coprime") # exit(0) # p = p | f # if pairwise: # print("pairwise coprime") # else: # print("setwise coprime")
131
131
3,188
3,146
#!/usr/bin/env pypy3 # N,M = map(int,sys.stdin.readline().split()) # a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param # a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param # s = sys.stdin.readline().rstrip() # N = int(sys.stdin.readline()) # INF = float("inf") import math from collections import defaultdict pc = True n = int(eval(input())) a = list(map(int, input().split())) g = math.gcd(a[0], a[1]) for i in range(2, n): g = math.gcd(g, a[i]) M = max(a) LIMIT = max(a) minPrime = [0] * (LIMIT + 1) minPrime[1] = 1 def make(): for i in range(2, LIMIT + 1): if minPrime[i] == 0: minPrime[i] = i # print(i) for j in range(i + i, LIMIT + 1, i): # print(i,j) if minPrime[j] == 0: minPrime[j] = i make() class Sieve_of_Eratosthenes: def __init__(self, N): self.sieve = [-1] * (N + 1) for i in range(2, N + 1): if self.sieve[i] == -1: for j in range(1, 1 + N // i): self.sieve[i * j] = i def isprime(self, num): if num <= 1: return False else: return self.sieve[num] == num def factorization(self, num): ret = set([]) while num != 1: div = self.sieve[num] ret.add(div) num //= div return ret def factrial(self, N): ret = set() while 1 != N: ret.add(minPrime[N]) N = N // minPrime[N] if N != 1: ret.add(N) return ret sofe = Sieve_of_Eratosthenes(M) ddic = defaultdict() judge = set([]) for i in a: if not pc: break # asf = sofe.factorization(i) asf = sofe.factrial(i) if judge & asf != set(): pc = False judge |= asf if pc: print("pairwise coprime") elif g == 1: print("setwise coprime") else: print("not coprime") # import sys,collections # N = int(sys.stdin.readline()) # #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = list(map(int,input().split())) # import math # # def factrial(N): # # ret = [] # # while minPrime[N] != N: # # ret.append(minPrime[N]) # # N = N//minPrime[N] # # if N != 1: # # ret.append(N) # # return ret # def factrial(N): # ret = set() # while 1 != N: # ret.add(minPrime[N]) # N = N//minPrime[N] # if N != 1: # ret.add(N) # return ret # for i in range(N): # acc = math.gcd(acc,a[i]) # if acc != 1: # print("not coprime") # exit() # pairwise = True # p = set() #all prime # for e in a: # if not pairwise: # break # f = factrial(e) # if p & f != set(): # pairwise = False # print("setwise coprime") # exit(0) # p = p | f # if pairwise: # print("pairwise coprime") # else: # print("setwise coprime")
#!/usr/bin/env pypy3 # N,M = map(int,sys.stdin.readline().split()) # a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param # a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param # s = sys.stdin.readline().rstrip() # N = int(sys.stdin.readline()) # INF = float("inf") import math from collections import defaultdict pc = True n = int(eval(input())) a = list(map(int, input().split())) g = math.gcd(a[0], a[1]) for i in range(2, n): g = math.gcd(g, a[i]) M = max(a) LIMIT = max(a) minPrime = [0] * (LIMIT + 1) minPrime[1] = 1 def make(): for i in range(2, LIMIT + 1): if minPrime[i] == 0: minPrime[i] = i # print(i) for j in range(i + i, LIMIT + 1, i): # print(i,j) if minPrime[j] == 0: minPrime[j] = i make() class Sieve_of_Eratosthenes: def __init__(self, N): self.sieve = [-1] * (N + 1) for i in range(2, N + 1): if self.sieve[i] == -1: for j in range(1, 1 + N // i): self.sieve[i * j] = i def isprime(self, num): if num <= 1: return False else: return self.sieve[num] == num def factorization(self, num): ret = set([]) while num != 1: div = self.sieve[num] ret.add(div) num //= div return ret def factrial(N): ret = set() while 1 != N: ret.add(minPrime[N]) N = N // minPrime[N] if N != 1: ret.add(N) return ret sofe = Sieve_of_Eratosthenes(M) ddic = defaultdict() judge = set([]) for i in a: if not pc: break # asf = sofe.factorization(i) asf = factrial(i) if judge & asf != set(): pc = False judge |= asf if pc: print("pairwise coprime") elif g == 1: print("setwise coprime") else: print("not coprime") # import sys,collections # N = int(sys.stdin.readline()) # #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param # a = list(map(int,input().split())) # import math # # def factrial(N): # # ret = [] # # while minPrime[N] != N: # # ret.append(minPrime[N]) # # N = N//minPrime[N] # # if N != 1: # # ret.append(N) # # return ret # def factrial(N): # ret = set() # while 1 != N: # ret.add(minPrime[N]) # N = N//minPrime[N] # if N != 1: # ret.add(N) # return ret # for i in range(N): # acc = math.gcd(acc,a[i]) # if acc != 1: # print("not coprime") # exit() # pairwise = True # p = set() #all prime # for e in a: # if not pairwise: # break # f = factrial(e) # if p & f != set(): # pairwise = False # print("setwise coprime") # exit(0) # p = p | f # if pairwise: # print("pairwise coprime") # else: # print("setwise coprime")
false
0
[ "- def factrial(self, N):", "- ret = set()", "- while 1 != N:", "- ret.add(minPrime[N])", "- N = N // minPrime[N]", "- if N != 1:", "- ret.add(N)", "- return ret", "+", "+def factrial(N):", "+ ret = set()", "+ while 1 != N:", "+ ret.add(minPrime[N])", "+ N = N // minPrime[N]", "+ if N != 1:", "+ ret.add(N)", "+ return ret", "- asf = sofe.factrial(i)", "+ asf = factrial(i)" ]
false
0.042275
0.041915
1.00859
[ "s058833116", "s219173334" ]
u513736711
p03250
python
s788759979
s676021470
20
17
3,060
2,940
Accepted
Accepted
15
a, b, c =sorted(map(int, input().split())) print((a + b + c * 10))
a, b, c = list(map(int, input().split())) mx = max([a, b, c]) print((mx * 9 + a + b + c))
2
3
65
83
a, b, c = sorted(map(int, input().split())) print((a + b + c * 10))
a, b, c = list(map(int, input().split())) mx = max([a, b, c]) print((mx * 9 + a + b + c))
false
33.333333
[ "-a, b, c = sorted(map(int, input().split()))", "-print((a + b + c * 10))", "+a, b, c = list(map(int, input().split()))", "+mx = max([a, b, c])", "+print((mx * 9 + a + b + c))" ]
false
0.047436
0.098021
0.483936
[ "s788759979", "s676021470" ]
u762420987
p03017
python
s145024028
s886343060
169
19
40,816
3,640
Accepted
Accepted
88.76
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) if C < D: Aok = "##" not in S[A-1:C] Bok = "##" not in S[B-1:D] if Aok and Bok: print("Yes") else: print("No") else: Aok = "##" not in S[A-1:C] Bok = "##" not in S[B-1:D] jumpok = "..." in S[B-2:D+1] if Aok and Bok and jumpok: print("Yes") else: print("No")
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) canA = "##" not in S[A-1:C] canB = "##" not in S[B-1:D] if C < D: if canA and canB: print("Yes") else: print("No") else: if canA and canB and ("..." in S[B-2:D+1]): print("Yes") else: print("No")
17
14
396
311
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) if C < D: Aok = "##" not in S[A - 1 : C] Bok = "##" not in S[B - 1 : D] if Aok and Bok: print("Yes") else: print("No") else: Aok = "##" not in S[A - 1 : C] Bok = "##" not in S[B - 1 : D] jumpok = "..." in S[B - 2 : D + 1] if Aok and Bok and jumpok: print("Yes") else: print("No")
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) canA = "##" not in S[A - 1 : C] canB = "##" not in S[B - 1 : D] if C < D: if canA and canB: print("Yes") else: print("No") else: if canA and canB and ("..." in S[B - 2 : D + 1]): print("Yes") else: print("No")
false
17.647059
[ "+canA = \"##\" not in S[A - 1 : C]", "+canB = \"##\" not in S[B - 1 : D]", "- Aok = \"##\" not in S[A - 1 : C]", "- Bok = \"##\" not in S[B - 1 : D]", "- if Aok and Bok:", "+ if canA and canB:", "- Aok = \"##\" not in S[A - 1 : C]", "- Bok = \"##\" not in S[B - 1 : D]", "- jumpok = \"...\" in S[B - 2 : D + 1]", "- if Aok and Bok and jumpok:", "+ if canA and canB and (\"...\" in S[B - 2 : D + 1]):" ]
false
0.102308
0.038653
2.646794
[ "s145024028", "s886343060" ]
u883048396
p03274
python
s286067799
s599597333
121
94
14,396
14,228
Accepted
Accepted
22.31
#とりあえず全検索 iN,iK = [int(_) for _ in input().split()] aX = [int(_) for _ in input().split()] aP = [_ for _ in aX if _ >= 0] aM = [-1*_ for _ in aX if _ < 0][::-1] iP = len(aP) iM = len(aM) if iP == 0: print((aM[iK-1])) exit() elif iM == 0: print((aP[iK-1])) exit() iD = 2*aP[-1]+2*aM[-1] for i in range(min(iP-1,iK-1),-1,-1): if iK - 2 -i < 0: iD = min(iD,aP[i]) elif iM > iK -2 - i : iD = min(iD,aP[i] + 2*aM[iK-i-2]) for i in range(min(iM-1,iK-1),-1,-1): if iK - 2 - i < 0: iD = min(iD,aM[i]) elif iP > iK -2 - i : iD = min(iD,aM[i] + 2*aP[iK-i-2]) print(iD)
iN,iK = [int(_) for _ in input().split()] aX = [int(_) for _ in input().split()] ans = 10**9 iDiff = iN-iK for i in range(iDiff + 1): iL = aX[i] iR = aX[iN-iDiff+i-1] ans = min(ans ,abs(iL) + abs(iL-iR),abs(iR) + abs(iR-iL)) print(ans)
26
9
648
256
# とりあえず全検索 iN, iK = [int(_) for _ in input().split()] aX = [int(_) for _ in input().split()] aP = [_ for _ in aX if _ >= 0] aM = [-1 * _ for _ in aX if _ < 0][::-1] iP = len(aP) iM = len(aM) if iP == 0: print((aM[iK - 1])) exit() elif iM == 0: print((aP[iK - 1])) exit() iD = 2 * aP[-1] + 2 * aM[-1] for i in range(min(iP - 1, iK - 1), -1, -1): if iK - 2 - i < 0: iD = min(iD, aP[i]) elif iM > iK - 2 - i: iD = min(iD, aP[i] + 2 * aM[iK - i - 2]) for i in range(min(iM - 1, iK - 1), -1, -1): if iK - 2 - i < 0: iD = min(iD, aM[i]) elif iP > iK - 2 - i: iD = min(iD, aM[i] + 2 * aP[iK - i - 2]) print(iD)
iN, iK = [int(_) for _ in input().split()] aX = [int(_) for _ in input().split()] ans = 10**9 iDiff = iN - iK for i in range(iDiff + 1): iL = aX[i] iR = aX[iN - iDiff + i - 1] ans = min(ans, abs(iL) + abs(iL - iR), abs(iR) + abs(iR - iL)) print(ans)
false
65.384615
[ "-# とりあえず全検索", "-aP = [_ for _ in aX if _ >= 0]", "-aM = [-1 * _ for _ in aX if _ < 0][::-1]", "-iP = len(aP)", "-iM = len(aM)", "-if iP == 0:", "- print((aM[iK - 1]))", "- exit()", "-elif iM == 0:", "- print((aP[iK - 1]))", "- exit()", "-iD = 2 * aP[-1] + 2 * aM[-1]", "-for i in range(min(iP - 1, iK - 1), -1, -1):", "- if iK - 2 - i < 0:", "- iD = min(iD, aP[i])", "- elif iM > iK - 2 - i:", "- iD = min(iD, aP[i] + 2 * aM[iK - i - 2])", "-for i in range(min(iM - 1, iK - 1), -1, -1):", "- if iK - 2 - i < 0:", "- iD = min(iD, aM[i])", "- elif iP > iK - 2 - i:", "- iD = min(iD, aM[i] + 2 * aP[iK - i - 2])", "-print(iD)", "+ans = 10**9", "+iDiff = iN - iK", "+for i in range(iDiff + 1):", "+ iL = aX[i]", "+ iR = aX[iN - iDiff + i - 1]", "+ ans = min(ans, abs(iL) + abs(iL - iR), abs(iR) + abs(iR - iL))", "+print(ans)" ]
false
0.03739
0.099802
0.374644
[ "s286067799", "s599597333" ]
u150984829
p02284
python
s609197197
s441013074
5,300
3,310
94,736
55,880
Accepted
Accepted
37.55
import sys class Node: def __init__(self, key): self.key = key self.left = self.right = None root = None def insert(key): global root x, y = root, None while x != None: x, y = x.left if key < x.key else x.right, x if y == None: root = Node(key) elif key < y.key: y.left = Node(key) else: y.right = Node(key) def find(target): result = root while result and target != result.key: result = result.left if target < result.key else result.right return result == None def inorder(node): return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else '' def preorder(node): return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else '' eval(input()) for e in sys.stdin: if e[0] == 'i': insert(int(e[7:])) elif e[0] == 'f': print((['yes','no'][find(int(e[5:]))])) else: print((inorder(root))); print((preorder(root)))
import sys class Node: __slots__ = ['key', 'left', 'right'] def __init__(self, key): self.key = key self.left = self.right = None root = None def insert(key): global root x, y = root, None while x is not None: x, y = x.left if key < x.key else x.right, x if y is None: root = Node(key) elif key < y.key: y.left = Node(key) else: y.right = Node(key) def find(target): result = root while result and target != result.key: result = result.left if target < result.key else result.right return result is None def inorder(node): return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else '' def preorder(node): return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else '' eval(input()) for e in sys.stdin: if e[0] == 'i': insert(int(e[7:])) elif e[0] == 'f': print((['yes','no'][find(int(e[5:]))])) else: print((inorder(root))); print((preorder(root)))
33
34
963
1,003
import sys class Node: def __init__(self, key): self.key = key self.left = self.right = None root = None def insert(key): global root x, y = root, None while x != None: x, y = x.left if key < x.key else x.right, x if y == None: root = Node(key) elif key < y.key: y.left = Node(key) else: y.right = Node(key) def find(target): result = root while result and target != result.key: result = result.left if target < result.key else result.right return result == None def inorder(node): return inorder(node.left) + f" {node.key}" + inorder(node.right) if node else "" def preorder(node): return f" {node.key}" + preorder(node.left) + preorder(node.right) if node else "" eval(input()) for e in sys.stdin: if e[0] == "i": insert(int(e[7:])) elif e[0] == "f": print((["yes", "no"][find(int(e[5:]))])) else: print((inorder(root))) print((preorder(root)))
import sys class Node: __slots__ = ["key", "left", "right"] def __init__(self, key): self.key = key self.left = self.right = None root = None def insert(key): global root x, y = root, None while x is not None: x, y = x.left if key < x.key else x.right, x if y is None: root = Node(key) elif key < y.key: y.left = Node(key) else: y.right = Node(key) def find(target): result = root while result and target != result.key: result = result.left if target < result.key else result.right return result is None def inorder(node): return inorder(node.left) + f" {node.key}" + inorder(node.right) if node else "" def preorder(node): return f" {node.key}" + preorder(node.left) + preorder(node.right) if node else "" eval(input()) for e in sys.stdin: if e[0] == "i": insert(int(e[7:])) elif e[0] == "f": print((["yes", "no"][find(int(e[5:]))])) else: print((inorder(root))) print((preorder(root)))
false
2.941176
[ "+ __slots__ = [\"key\", \"left\", \"right\"]", "+", "- while x != None:", "+ while x is not None:", "- if y == None:", "+ if y is None:", "- return result == None", "+ return result is None" ]
false
0.065377
0.043279
1.510604
[ "s609197197", "s441013074" ]
u911575040
p03038
python
s444978349
s033150384
927
566
86,424
26,732
Accepted
Accepted
38.94
n,m=list(map(int,input().split())) *a,=list(map(int,input().split())) l=[list(map(int,input().split()))[::-1] for _ in range(m)] a.sort() d=[] e=0 for c,b in sorted(l)[::-1]: d+=[c]*b e+=b if e>n:break for i,(x,y) in enumerate(zip(a,d)): if x<y:a[i]=y print((sum(a)))
n,m=list(map(int,input().split())) a=list(map(int,input().split())) Z=[list(map(int,input().split()))[::-1] for _ in range(m)] d=[] e=0 a.sort() Z.sort(reverse=True) for c,b in Z: d+=[c]*b e+=b if e>n: break for i , (x,y) in enumerate(zip(a,d)): if x<y: a[i]=y print((sum(a)))
13
18
270
320
n, m = list(map(int, input().split())) (*a,) = list(map(int, input().split())) l = [list(map(int, input().split()))[::-1] for _ in range(m)] a.sort() d = [] e = 0 for c, b in sorted(l)[::-1]: d += [c] * b e += b if e > n: break for i, (x, y) in enumerate(zip(a, d)): if x < y: a[i] = y print((sum(a)))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) Z = [list(map(int, input().split()))[::-1] for _ in range(m)] d = [] e = 0 a.sort() Z.sort(reverse=True) for c, b in Z: d += [c] * b e += b if e > n: break for i, (x, y) in enumerate(zip(a, d)): if x < y: a[i] = y print((sum(a)))
false
27.777778
[ "-(*a,) = list(map(int, input().split()))", "-l = [list(map(int, input().split()))[::-1] for _ in range(m)]", "-a.sort()", "+a = list(map(int, input().split()))", "+Z = [list(map(int, input().split()))[::-1] for _ in range(m)]", "-for c, b in sorted(l)[::-1]:", "+a.sort()", "+Z.sort(reverse=True)", "+for c, b in Z:" ]
false
0.035581
0.040114
0.886992
[ "s444978349", "s033150384" ]
u718096172
p03078
python
s109613101
s719344748
797
64
4,852
5,464
Accepted
Accepted
91.97
import heapq X, Y, Z, K = [int(i) for i in input().split()] ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)] pQ = [] heapq.heappush(pQ, [sum(ABC[0] for ABC in ABCList) * (-1), [0, 0, 0]]) QList = [(0, 0, 0)] for _ in range(K): item = heapq.heappop(pQ) print((item[0] * (-1))) abc = item.copy()[1] for i, element in enumerate(abc): abcTemp = abc.copy() abcTemp[i] += 1 if abcTemp[i] < len(ABCList[i]) and not tuple(abcTemp) in QList: newItem = [sum([ABCList[i][abcTemp[i]] for i in range(3)]) * (-1), abcTemp] heapq.heappush(pQ, newItem) QList.append(tuple(abcTemp))
import heapq from collections import defaultdict as dd X, Y, Z, K = [int(i) for i in input().split()] ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)] pQ = [] heapq.heappush(pQ, [sum(ABC[0] for ABC in ABCList) * (-1), [0, 0, 0]]) QDict = dd(int) QDict[(0, 0, 0)] = 1 for _ in range(K): item = heapq.heappop(pQ) print((item[0] * (-1))) abc = item.copy()[1] for i, element in enumerate(abc): abcTemp = abc.copy() abcTemp[i] += 1 if abcTemp[i] < len(ABCList[i]) and QDict[tuple(abcTemp)] == 0: newItem = [sum([ABCList[i][abcTemp[i]] for i in range(3)]) * (-1), abcTemp] heapq.heappush(pQ, newItem) QDict[(tuple(abcTemp))] = 1
19
21
696
756
import heapq X, Y, Z, K = [int(i) for i in input().split()] ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)] pQ = [] heapq.heappush(pQ, [sum(ABC[0] for ABC in ABCList) * (-1), [0, 0, 0]]) QList = [(0, 0, 0)] for _ in range(K): item = heapq.heappop(pQ) print((item[0] * (-1))) abc = item.copy()[1] for i, element in enumerate(abc): abcTemp = abc.copy() abcTemp[i] += 1 if abcTemp[i] < len(ABCList[i]) and not tuple(abcTemp) in QList: newItem = [sum([ABCList[i][abcTemp[i]] for i in range(3)]) * (-1), abcTemp] heapq.heappush(pQ, newItem) QList.append(tuple(abcTemp))
import heapq from collections import defaultdict as dd X, Y, Z, K = [int(i) for i in input().split()] ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)] pQ = [] heapq.heappush(pQ, [sum(ABC[0] for ABC in ABCList) * (-1), [0, 0, 0]]) QDict = dd(int) QDict[(0, 0, 0)] = 1 for _ in range(K): item = heapq.heappop(pQ) print((item[0] * (-1))) abc = item.copy()[1] for i, element in enumerate(abc): abcTemp = abc.copy() abcTemp[i] += 1 if abcTemp[i] < len(ABCList[i]) and QDict[tuple(abcTemp)] == 0: newItem = [sum([ABCList[i][abcTemp[i]] for i in range(3)]) * (-1), abcTemp] heapq.heappush(pQ, newItem) QDict[(tuple(abcTemp))] = 1
false
9.52381
[ "+from collections import defaultdict as dd", "-QList = [(0, 0, 0)]", "+QDict = dd(int)", "+QDict[(0, 0, 0)] = 1", "- if abcTemp[i] < len(ABCList[i]) and not tuple(abcTemp) in QList:", "+ if abcTemp[i] < len(ABCList[i]) and QDict[tuple(abcTemp)] == 0:", "- QList.append(tuple(abcTemp))", "+ QDict[(tuple(abcTemp))] = 1" ]
false
0.058751
0.033944
1.730817
[ "s109613101", "s719344748" ]
u439396449
p03287
python
s930018564
s367364554
121
83
16,208
16,596
Accepted
Accepted
31.4
from collections import defaultdict N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [0] * N B[0] = A[0] for i in range(1, N): B[i] = B[i - 1] + A[i] B = [0] + B c = defaultdict(int) for i in range(N + 1): c[B[i] % M] += 1 ans = 0 for k, v in list(c.items()): if v >= 2: ans += v * (v - 1) // 2 print(ans)
from collections import Counter from itertools import accumulate N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] c = Counter([0] + [x % M for x in accumulate(A)]) ans = 0 for k, v in list(c.items()): if v >= 2: ans += v * (v - 1) // 2 print(ans)
20
12
368
287
from collections import defaultdict N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [0] * N B[0] = A[0] for i in range(1, N): B[i] = B[i - 1] + A[i] B = [0] + B c = defaultdict(int) for i in range(N + 1): c[B[i] % M] += 1 ans = 0 for k, v in list(c.items()): if v >= 2: ans += v * (v - 1) // 2 print(ans)
from collections import Counter from itertools import accumulate N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] c = Counter([0] + [x % M for x in accumulate(A)]) ans = 0 for k, v in list(c.items()): if v >= 2: ans += v * (v - 1) // 2 print(ans)
false
40
[ "-from collections import defaultdict", "+from collections import Counter", "+from itertools import accumulate", "-B = [0] * N", "-B[0] = A[0]", "-for i in range(1, N):", "- B[i] = B[i - 1] + A[i]", "-B = [0] + B", "-c = defaultdict(int)", "-for i in range(N + 1):", "- c[B[i] % M] += 1", "+c = Counter([0] + [x % M for x in accumulate(A)])" ]
false
0.041822
0.081925
0.510487
[ "s930018564", "s367364554" ]
u784022244
p03108
python
s824017841
s739528589
927
839
23,220
23,660
Accepted
Accepted
9.49
N,M=list(map(int, input().split())) #島、橋 class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if (x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める #rnkが大きい方に結合 elif (self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] L=[] for i in range(M): a,b=list(map(int, input().split())) L.append((a-1,b-1)) uni=UnionFind(N) ans=[0]*M L=reversed(L) for i,t in enumerate(L): a,b=t ca=uni.Count(a) cb=uni.Count(b) if uni.isSameGroup(a,b): ans[-(i+1)]=0 else: ans[-(i+1)]=uni.Count(a)*uni.Count(b) uni.Unite(a,b) final=[0]*M final[0]=ans[0] #print(ans) for i in range(1,M): final[i]=final[i-1]+ans[i] for f in final: print(f)
N,M=list(map(int, input().split())) B=[] class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if (x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める #rnkが大きい方に結合 elif (self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] for i in range(M): a,b=list(map(int, input().split())) B.append((a-1,b-1)) B=B[::-1] uni=UnionFind(N) now=N*(N-1)//2 ans=[] for t in B: ans.append(now) a,b=t if uni.isSameGroup(a,b): uni.Unite(a,b) else: A=uni.Count(a) B=uni.Count(b) now-=(A*B) uni.Unite(a,b) for a in ans[::-1]: print(a)
75
73
1,666
1,572
N, M = list(map(int, input().split())) # 島、橋 class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める # rnkが大きい方に結合 elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] L = [] for i in range(M): a, b = list(map(int, input().split())) L.append((a - 1, b - 1)) uni = UnionFind(N) ans = [0] * M L = reversed(L) for i, t in enumerate(L): a, b = t ca = uni.Count(a) cb = uni.Count(b) if uni.isSameGroup(a, b): ans[-(i + 1)] = 0 else: ans[-(i + 1)] = uni.Count(a) * uni.Count(b) uni.Unite(a, b) final = [0] * M final[0] = ans[0] # print(ans) for i in range(1, M): final[i] = final[i - 1] + ans[i] for f in final: print(f)
N, M = list(map(int, input().split())) B = [] class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める # rnkが大きい方に結合 elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] for i in range(M): a, b = list(map(int, input().split())) B.append((a - 1, b - 1)) B = B[::-1] uni = UnionFind(N) now = N * (N - 1) // 2 ans = [] for t in B: ans.append(now) a, b = t if uni.isSameGroup(a, b): uni.Unite(a, b) else: A = uni.Count(a) B = uni.Count(b) now -= A * B uni.Unite(a, b) for a in ans[::-1]: print(a)
false
2.666667
[ "-# 島、橋", "+B = []", "+", "+", "-L = []", "- L.append((a - 1, b - 1))", "+ B.append((a - 1, b - 1))", "+B = B[::-1]", "-ans = [0] * M", "-L = reversed(L)", "-for i, t in enumerate(L):", "+now = N * (N - 1) // 2", "+ans = []", "+for t in B:", "+ ans.append(now)", "- ca = uni.Count(a)", "- cb = uni.Count(b)", "- ans[-(i + 1)] = 0", "+ uni.Unite(a, b)", "- ans[-(i + 1)] = uni.Count(a) * uni.Count(b)", "- uni.Unite(a, b)", "-final = [0] * M", "-final[0] = ans[0]", "-# print(ans)", "-for i in range(1, M):", "- final[i] = final[i - 1] + ans[i]", "-for f in final:", "- print(f)", "+ A = uni.Count(a)", "+ B = uni.Count(b)", "+ now -= A * B", "+ uni.Unite(a, b)", "+for a in ans[::-1]:", "+ print(a)" ]
false
0.045673
0.036682
1.245107
[ "s824017841", "s739528589" ]
u054514819
p02608
python
s235912286
s202679958
160
101
72,564
74,472
Accepted
Accepted
36.88
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) from collections import defaultdict dic = defaultdict(int) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): dic[x**2+y**2+z**2+x*y+y*z+z*x] += 1 for i in range(1, N+1): print((dic[i]))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) ans = [0]*N for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): val = x**2+y**2+z**2+x*y+y*z+z*x if val<=N: ans[val-1] += 1 for v in ans: print(v)
15
17
402
394
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) from collections import defaultdict dic = defaultdict(int) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): dic[x**2 + y**2 + z**2 + x * y + y * z + z * x] += 1 for i in range(1, N + 1): print((dic[i]))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N = int(eval(input())) ans = [0] * N for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): val = x**2 + y**2 + z**2 + x * y + y * z + z * x if val <= N: ans[val - 1] += 1 for v in ans: print(v)
false
11.764706
[ "-from collections import defaultdict", "-", "-dic = defaultdict(int)", "+ans = [0] * N", "- dic[x**2 + y**2 + z**2 + x * y + y * z + z * x] += 1", "-for i in range(1, N + 1):", "- print((dic[i]))", "+ val = x**2 + y**2 + z**2 + x * y + y * z + z * x", "+ if val <= N:", "+ ans[val - 1] += 1", "+for v in ans:", "+ print(v)" ]
false
2.13591
2.818593
0.757793
[ "s235912286", "s202679958" ]
u573754721
p02842
python
s500802721
s289153136
34
17
2,940
2,940
Accepted
Accepted
50
import math n=int(eval(input())) for i in range(1,50001): if math.floor(i*1.08)==n: print(i) exit() print(":(")
n=int(eval(input())) if int(n//1.08) !=int((n+1)//1.08): print((int((n+1)//1.08))) else: print(':(')
10
6
138
110
import math n = int(eval(input())) for i in range(1, 50001): if math.floor(i * 1.08) == n: print(i) exit() print(":(")
n = int(eval(input())) if int(n // 1.08) != int((n + 1) // 1.08): print((int((n + 1) // 1.08))) else: print(":(")
false
40
[ "-import math", "-", "-for i in range(1, 50001):", "- if math.floor(i * 1.08) == n:", "- print(i)", "- exit()", "-print(\":(\")", "+if int(n // 1.08) != int((n + 1) // 1.08):", "+ print((int((n + 1) // 1.08)))", "+else:", "+ print(\":(\")" ]
false
0.067731
0.037575
1.802553
[ "s500802721", "s289153136" ]
u148551245
p03351
python
s328150349
s929241033
162
17
38,384
2,940
Accepted
Accepted
89.51
(a, b, c, d) = list(map(int, input().split())) if abs(a - c) <= d: print("Yes") elif abs(a - b) <= d and abs(b - c) <= d: print("Yes") else: print("No")
a, b, c, d = list(map(int, input().split())) if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d): print("Yes") else: print("No")
7
6
164
138
(a, b, c, d) = list(map(int, input().split())) if abs(a - c) <= d: print("Yes") elif abs(a - b) <= d and abs(b - c) <= d: print("Yes") else: print("No")
a, b, c, d = list(map(int, input().split())) if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d): print("Yes") else: print("No")
false
14.285714
[ "-(a, b, c, d) = list(map(int, input().split()))", "-if abs(a - c) <= d:", "- print(\"Yes\")", "-elif abs(a - b) <= d and abs(b - c) <= d:", "+a, b, c, d = list(map(int, input().split()))", "+if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):" ]
false
0.068957
0.03703
1.862197
[ "s328150349", "s929241033" ]
u894265012
p02623
python
s410609247
s731686221
187
160
132,476
132,336
Accepted
Accepted
14.44
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A_sum = [0] for i in range(N): A_sum.append(A[i] + A_sum[i]) B_sum = [0] for i in range(M): B_sum.append(B[i] + B_sum[i]) import bisect ans = 0 for i in range(N+1): a = A_sum[i] if K-a >=0: b_idx = bisect.bisect(B_sum, K-a) - 1 if b_idx < 0: b_idx = 0 ans = max(ans, i+b_idx) print(ans)
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A_sum = [0] for i in range(N): A_sum.append(A[i] + A_sum[i]) B_sum = [0] for i in range(M): B_sum.append(B[i] + B_sum[i]) b_idx = 0 for i in range(1, M+1): if B_sum[i] <= K: b_idx = i ans = 0 for i in range(N+1): if b_idx > 0: while A_sum[i] + B_sum[b_idx] > K: b_idx -= 1 if b_idx < 0: b_idx = 0 break if A_sum[i] + B_sum[b_idx] <= K: ans = max(ans, i+b_idx) print(ans)
19
25
469
610
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A_sum = [0] for i in range(N): A_sum.append(A[i] + A_sum[i]) B_sum = [0] for i in range(M): B_sum.append(B[i] + B_sum[i]) import bisect ans = 0 for i in range(N + 1): a = A_sum[i] if K - a >= 0: b_idx = bisect.bisect(B_sum, K - a) - 1 if b_idx < 0: b_idx = 0 ans = max(ans, i + b_idx) print(ans)
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A_sum = [0] for i in range(N): A_sum.append(A[i] + A_sum[i]) B_sum = [0] for i in range(M): B_sum.append(B[i] + B_sum[i]) b_idx = 0 for i in range(1, M + 1): if B_sum[i] <= K: b_idx = i ans = 0 for i in range(N + 1): if b_idx > 0: while A_sum[i] + B_sum[b_idx] > K: b_idx -= 1 if b_idx < 0: b_idx = 0 break if A_sum[i] + B_sum[b_idx] <= K: ans = max(ans, i + b_idx) print(ans)
false
24
[ "-import bisect", "-", "+b_idx = 0", "+for i in range(1, M + 1):", "+ if B_sum[i] <= K:", "+ b_idx = i", "- a = A_sum[i]", "- if K - a >= 0:", "- b_idx = bisect.bisect(B_sum, K - a) - 1", "- if b_idx < 0:", "- b_idx = 0", "+ if b_idx > 0:", "+ while A_sum[i] + B_sum[b_idx] > K:", "+ b_idx -= 1", "+ if b_idx < 0:", "+ b_idx = 0", "+ break", "+ if A_sum[i] + B_sum[b_idx] <= K:" ]
false
0.045591
0.048878
0.932741
[ "s410609247", "s731686221" ]
u681444474
p02922
python
s628225495
s733857322
171
18
38,256
3,060
Accepted
Accepted
89.47
A,B=list(map(int,input().split())) cnt=0 num=1 while num<B: num+=(A-1) cnt+=1 print(cnt)
# coding: utf-8 import math a, b = list(map(int,input().split())) if a >= b: ans = 1 else: ans = 1 ans += math.ceil((b-a)/(a-1)) if b == 1: ans = 0 print(ans)
8
12
102
180
A, B = list(map(int, input().split())) cnt = 0 num = 1 while num < B: num += A - 1 cnt += 1 print(cnt)
# coding: utf-8 import math a, b = list(map(int, input().split())) if a >= b: ans = 1 else: ans = 1 ans += math.ceil((b - a) / (a - 1)) if b == 1: ans = 0 print(ans)
false
33.333333
[ "-A, B = list(map(int, input().split()))", "-cnt = 0", "-num = 1", "-while num < B:", "- num += A - 1", "- cnt += 1", "-print(cnt)", "+# coding: utf-8", "+import math", "+", "+a, b = list(map(int, input().split()))", "+if a >= b:", "+ ans = 1", "+else:", "+ ans = 1", "+ ans += math.ceil((b - a) / (a - 1))", "+if b == 1:", "+ ans = 0", "+print(ans)" ]
false
0.046657
0.043308
1.077318
[ "s628225495", "s733857322" ]
u144913062
p02984
python
s097677849
s134473671
892
97
19,140
19,140
Accepted
Accepted
89.13
N = int(eval(input())) A = list(map(int, input().split())) left = 0 right = 2 * A[0] + 2 while left < right: rain = [0] * N rain[0] = (left + right) // 4 * 2 for i in range(N-1): rain[i+1] = 2 * A[i] - rain[i] rain0 = 2 * A[-1] - rain[-1] if rain[0] > rain0: right = rain[0] elif rain[0] < rain0: left = rain[0] + 2 else: print((' '.join(map(str, rain)))) exit()
N = int(eval(input())) A = list(map(int, input().split())) rain = [0] * N rain[0] = sum(A) - 2 * sum(A[i] for i in range(1, N, 2)) for i in range(N-1): rain[i+1] = 2 * A[i] - rain[i] print((' '.join(map(str, rain))))
17
7
439
219
N = int(eval(input())) A = list(map(int, input().split())) left = 0 right = 2 * A[0] + 2 while left < right: rain = [0] * N rain[0] = (left + right) // 4 * 2 for i in range(N - 1): rain[i + 1] = 2 * A[i] - rain[i] rain0 = 2 * A[-1] - rain[-1] if rain[0] > rain0: right = rain[0] elif rain[0] < rain0: left = rain[0] + 2 else: print((" ".join(map(str, rain)))) exit()
N = int(eval(input())) A = list(map(int, input().split())) rain = [0] * N rain[0] = sum(A) - 2 * sum(A[i] for i in range(1, N, 2)) for i in range(N - 1): rain[i + 1] = 2 * A[i] - rain[i] print((" ".join(map(str, rain))))
false
58.823529
[ "-left = 0", "-right = 2 * A[0] + 2", "-while left < right:", "- rain = [0] * N", "- rain[0] = (left + right) // 4 * 2", "- for i in range(N - 1):", "- rain[i + 1] = 2 * A[i] - rain[i]", "- rain0 = 2 * A[-1] - rain[-1]", "- if rain[0] > rain0:", "- right = rain[0]", "- elif rain[0] < rain0:", "- left = rain[0] + 2", "- else:", "- print((\" \".join(map(str, rain))))", "- exit()", "+rain = [0] * N", "+rain[0] = sum(A) - 2 * sum(A[i] for i in range(1, N, 2))", "+for i in range(N - 1):", "+ rain[i + 1] = 2 * A[i] - rain[i]", "+print((\" \".join(map(str, rain))))" ]
false
0.105419
0.044067
2.392237
[ "s097677849", "s134473671" ]
u562935282
p03731
python
s627599500
s585430966
151
127
26,836
25,328
Accepted
Accepted
15.89
def inpl(): return input().split() N, T = list(map(int, inpl())) t = list(map(int, inpl())) ret = 0 for i in range(1, N): if (t[i] - t[i-1]) < T: ret += (t[i] - t[i-1]) else: ret += T ret += T print(ret)
n, t = list(map(int, input().split())) a = tuple(map(int, input().split())) b = tuple(a_ato - a_mae for a_ato, a_mae in zip(a[1:], a)) print((sum([min(x, t) for x in b]) + t)) """ 最後の人が出したシャワーは、時間いっぱい出る それ以前の人が出したシャワーは、 時間いっぱいか、次の人が押すまでの時間のうち、短い時間だけ出る """
12
10
233
263
def inpl(): return input().split() N, T = list(map(int, inpl())) t = list(map(int, inpl())) ret = 0 for i in range(1, N): if (t[i] - t[i - 1]) < T: ret += t[i] - t[i - 1] else: ret += T ret += T print(ret)
n, t = list(map(int, input().split())) a = tuple(map(int, input().split())) b = tuple(a_ato - a_mae for a_ato, a_mae in zip(a[1:], a)) print((sum([min(x, t) for x in b]) + t)) """ 最後の人が出したシャワーは、時間いっぱい出る それ以前の人が出したシャワーは、 時間いっぱいか、次の人が押すまでの時間のうち、短い時間だけ出る """
false
16.666667
[ "-def inpl():", "- return input().split()", "-", "-", "-N, T = list(map(int, inpl()))", "-t = list(map(int, inpl()))", "-ret = 0", "-for i in range(1, N):", "- if (t[i] - t[i - 1]) < T:", "- ret += t[i] - t[i - 1]", "- else:", "- ret += T", "-ret += T", "-print(ret)", "+n, t = list(map(int, input().split()))", "+a = tuple(map(int, input().split()))", "+b = tuple(a_ato - a_mae for a_ato, a_mae in zip(a[1:], a))", "+print((sum([min(x, t) for x in b]) + t))", "+\"\"\"", "+最後の人が出したシャワーは、時間いっぱい出る", "+それ以前の人が出したシャワーは、", "+時間いっぱいか、次の人が押すまでの時間のうち、短い時間だけ出る", "+\"\"\"" ]
false
0.039265
0.036152
1.086126
[ "s627599500", "s585430966" ]
u186838327
p03488
python
s829219978
s718949699
328
220
136,696
151,436
Accepted
Accepted
32.93
def main(): s = str(eval(input())) n = len(s) x, y = list(map(int, input().split())) dx = [] dy = [] dir = 0 cnt = 0 for i in range(n): if s[i] == 'F': cnt += 1 else: if dir%2 == 0: dx.append(cnt) cnt = 0 dir += 1 else: dy.append(cnt) cnt = 0 dir += 1 else: if dir%2 == 0: dx.append(cnt) else: dy.append(cnt) dpx = [0]*(len(dx)+1) dpy = [0]*(len(dy)+1) import numpy as np D = 2*n+1 dpx[0] = np.zeros(D, np.bool) dpy[0] = np.zeros(D, np.bool) dpx[0][n] = 1 dpy[0][n] = 1 for i in range(len(dx)): d = dx[i] if i == 0: b = np.zeros(D, np.bool) b[d:] |= dpx[i][:D-d] else: b = np.zeros(D, np.bool) b[d:] |= dpx[i][:D-d] b[:D-d] |= dpx[i][d:] dpx[i+1] = b for i in range(len(dy)): d = dy[i] b = np.zeros(D, np.bool) b[d:] |= dpy[i][:D-d] b[:D-d] |= dpy[i][d:] dpy[i+1] = b if dpx[-1][n+x] and dpy[-1][n+y]: print('Yes') else: print('No') if __name__ == '__main__': main()
def main(): s = str(eval(input())) x, y = list(map(int, input().split())) n = len(s) dir = 1 dx = [] dy = [] cnt = 0 for i in range(n): if s[i] == 'F': cnt += 1 else: if dir == 1: dx.append(cnt) cnt = 0 dir = -1 else: dy.append(cnt) cnt = 0 dir = 1 else: if dir == 1: dx.append(cnt) else: dy.append(cnt) #print(dx) #print(dy) D = 8000*2+1 import numpy as np dpx = [0]*(len(dx)+1) dpy = [0]*(len(dy)+1) dpx[0] = np.zeros(D, np.bool) dpy[0] = np.zeros(D, np.bool) dpx[0][8000] = 1 dpy[0][8000] = 1 for i, d in enumerate(dx): if i == 0: b = np.zeros(D, np.bool) b[d:] |= dpx[i][:D-d] dpx[i+1] = b else: b = np.zeros(D, np.bool) b[d:] |= dpx[i][:D-d] b[:D-d] |= dpx[i][d:] dpx[i+1] = b for i, d in enumerate(dy): b = np.zeros(D, np.bool) b[d:] |= dpy[i][:D-d] b[:D-d] |= dpy[i][d:] dpy[i+1] = b if dpx[-1][8000+x] == 1 and dpy[-1][8000+y] == 1: print('Yes') else: print('No') if __name__ == '__main__': main()
62
63
1,347
1,395
def main(): s = str(eval(input())) n = len(s) x, y = list(map(int, input().split())) dx = [] dy = [] dir = 0 cnt = 0 for i in range(n): if s[i] == "F": cnt += 1 else: if dir % 2 == 0: dx.append(cnt) cnt = 0 dir += 1 else: dy.append(cnt) cnt = 0 dir += 1 else: if dir % 2 == 0: dx.append(cnt) else: dy.append(cnt) dpx = [0] * (len(dx) + 1) dpy = [0] * (len(dy) + 1) import numpy as np D = 2 * n + 1 dpx[0] = np.zeros(D, np.bool) dpy[0] = np.zeros(D, np.bool) dpx[0][n] = 1 dpy[0][n] = 1 for i in range(len(dx)): d = dx[i] if i == 0: b = np.zeros(D, np.bool) b[d:] |= dpx[i][: D - d] else: b = np.zeros(D, np.bool) b[d:] |= dpx[i][: D - d] b[: D - d] |= dpx[i][d:] dpx[i + 1] = b for i in range(len(dy)): d = dy[i] b = np.zeros(D, np.bool) b[d:] |= dpy[i][: D - d] b[: D - d] |= dpy[i][d:] dpy[i + 1] = b if dpx[-1][n + x] and dpy[-1][n + y]: print("Yes") else: print("No") if __name__ == "__main__": main()
def main(): s = str(eval(input())) x, y = list(map(int, input().split())) n = len(s) dir = 1 dx = [] dy = [] cnt = 0 for i in range(n): if s[i] == "F": cnt += 1 else: if dir == 1: dx.append(cnt) cnt = 0 dir = -1 else: dy.append(cnt) cnt = 0 dir = 1 else: if dir == 1: dx.append(cnt) else: dy.append(cnt) # print(dx) # print(dy) D = 8000 * 2 + 1 import numpy as np dpx = [0] * (len(dx) + 1) dpy = [0] * (len(dy) + 1) dpx[0] = np.zeros(D, np.bool) dpy[0] = np.zeros(D, np.bool) dpx[0][8000] = 1 dpy[0][8000] = 1 for i, d in enumerate(dx): if i == 0: b = np.zeros(D, np.bool) b[d:] |= dpx[i][: D - d] dpx[i + 1] = b else: b = np.zeros(D, np.bool) b[d:] |= dpx[i][: D - d] b[: D - d] |= dpx[i][d:] dpx[i + 1] = b for i, d in enumerate(dy): b = np.zeros(D, np.bool) b[d:] |= dpy[i][: D - d] b[: D - d] |= dpy[i][d:] dpy[i + 1] = b if dpx[-1][8000 + x] == 1 and dpy[-1][8000 + y] == 1: print("Yes") else: print("No") if __name__ == "__main__": main()
false
1.587302
[ "+ x, y = list(map(int, input().split()))", "- x, y = list(map(int, input().split()))", "+ dir = 1", "- dir = 0", "- if dir % 2 == 0:", "+ if dir == 1:", "- dir += 1", "+ dir = -1", "- dir += 1", "+ dir = 1", "- if dir % 2 == 0:", "+ if dir == 1:", "+ # print(dx)", "+ # print(dy)", "+ D = 8000 * 2 + 1", "+ import numpy as np", "+", "- import numpy as np", "-", "- D = 2 * n + 1", "- dpx[0][n] = 1", "- dpy[0][n] = 1", "- for i in range(len(dx)):", "- d = dx[i]", "+ dpx[0][8000] = 1", "+ dpy[0][8000] = 1", "+ for i, d in enumerate(dx):", "+ dpx[i + 1] = b", "- dpx[i + 1] = b", "- for i in range(len(dy)):", "- d = dy[i]", "+ dpx[i + 1] = b", "+ for i, d in enumerate(dy):", "- if dpx[-1][n + x] and dpy[-1][n + y]:", "+ if dpx[-1][8000 + x] == 1 and dpy[-1][8000 + y] == 1:" ]
false
0.04237
0.043657
0.970519
[ "s829219978", "s718949699" ]
u422272120
p02779
python
s473611288
s813280691
84
65
25,936
32,688
Accepted
Accepted
22.62
n = int(eval(input())) l = list(map(int,input().split())) if len(l) == len(set(l)): print ("YES") else: print ("NO")
n = int(input()) l = list(input().split()) print ("YES") if len(l) == len(set(l)) else print ("NO")
6
3
123
102
n = int(eval(input())) l = list(map(int, input().split())) if len(l) == len(set(l)): print("YES") else: print("NO")
n = int(input()) l = list(input().split()) print("YES") if len(l) == len(set(l)) else print("NO")
false
50
[ "-n = int(eval(input()))", "-l = list(map(int, input().split()))", "-if len(l) == len(set(l)):", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+n = int(input())", "+l = list(input().split())", "+print(\"YES\") if len(l) == len(set(l)) else print(\"NO\")" ]
false
0.041195
0.043418
0.948804
[ "s473611288", "s813280691" ]
u298297089
p03109
python
s149359565
s438203675
173
17
38,256
2,940
Accepted
Accepted
90.17
s = eval(input()) m = int(s[5:7]) d = int(s[8:10]) tt = m * 100 + d print(('Heisei' if tt <= 430 else 'TBD'))
y,m,d = list(map(int, input().split('/'))) if y < 2019 or (y == 2019 and m <= 4): print('Heisei') else: print('TBD')
5
6
105
120
s = eval(input()) m = int(s[5:7]) d = int(s[8:10]) tt = m * 100 + d print(("Heisei" if tt <= 430 else "TBD"))
y, m, d = list(map(int, input().split("/"))) if y < 2019 or (y == 2019 and m <= 4): print("Heisei") else: print("TBD")
false
16.666667
[ "-s = eval(input())", "-m = int(s[5:7])", "-d = int(s[8:10])", "-tt = m * 100 + d", "-print((\"Heisei\" if tt <= 430 else \"TBD\"))", "+y, m, d = list(map(int, input().split(\"/\")))", "+if y < 2019 or (y == 2019 and m <= 4):", "+ print(\"Heisei\")", "+else:", "+ print(\"TBD\")" ]
false
0.071041
0.082387
0.862294
[ "s149359565", "s438203675" ]
u698176039
p03043
python
s501805869
s981452391
124
71
3,064
66,332
Accepted
Accepted
42.74
import math N,K = list(map(int,input().split())) list2 = [1] tmp = 1 while tmp < 10 ** 5 + 1: tmp *= 2 list2 += [tmp] L2 = len(list2) ans = 0 for i in range(1,N+1): tmp = math.ceil(K/i) for j in range(L2): if tmp <= list2[j]: break ans += list2[j] ** (-1) ans /= N print(ans)
N, K = list(map(int,input().split())) ans = 0 for i in range(1,N+1): c = 1 p = 1/N while c*i<K: c *= 2 p /= 2 ans += p print(ans)
19
13
333
174
import math N, K = list(map(int, input().split())) list2 = [1] tmp = 1 while tmp < 10**5 + 1: tmp *= 2 list2 += [tmp] L2 = len(list2) ans = 0 for i in range(1, N + 1): tmp = math.ceil(K / i) for j in range(L2): if tmp <= list2[j]: break ans += list2[j] ** (-1) ans /= N print(ans)
N, K = list(map(int, input().split())) ans = 0 for i in range(1, N + 1): c = 1 p = 1 / N while c * i < K: c *= 2 p /= 2 ans += p print(ans)
false
31.578947
[ "-import math", "-", "-list2 = [1]", "-tmp = 1", "-while tmp < 10**5 + 1:", "- tmp *= 2", "- list2 += [tmp]", "-L2 = len(list2)", "- tmp = math.ceil(K / i)", "- for j in range(L2):", "- if tmp <= list2[j]:", "- break", "- ans += list2[j] ** (-1)", "-ans /= N", "+ c = 1", "+ p = 1 / N", "+ while c * i < K:", "+ c *= 2", "+ p /= 2", "+ ans += p" ]
false
0.368161
0.083793
4.393716
[ "s501805869", "s981452391" ]
u303039933
p02727
python
s553934810
s225526092
457
264
120,092
24,460
Accepted
Accepted
42.23
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [eval(input()) for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(eval(input())) for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True class PriorityQueue: def __init__(self, l=[]): self.q = l heapq.heapify(self.q) return def push(self, n): heapq.heappush(self.q, n) return def pop(self): return heapq.heappop(self.q) def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def main(): # sys.stdin = open("sample.txt") X, Y, A, B, C = Scanner.map_int() P = Scanner.map_int() Q = Scanner.map_int() R = Scanner.map_int() P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) P = P[:X] Q = Q[:Y] A = P + Q + R A.sort(reverse=True) print((sum(A[:X + Y]))) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): X, Y, A, B, C = Scanner.map_int() P = Scanner.map_int() Q = Scanner.map_int() R = Scanner.map_int() P.sort(reverse=True) P = P[:X] Q.sort(reverse=True) Q = Q[:Y] R.sort(reverse=True) R = R[:min(X + Y, C)] ans = P + Q + R ans.sort(reverse=True) print((sum(ans[:X + Y]))) def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
130
143
2,751
3,098
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [eval(input()) for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(eval(input())) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True class PriorityQueue: def __init__(self, l=[]): self.q = l heapq.heapify(self.q) return def push(self, n): heapq.heappush(self.q, n) return def pop(self): return heapq.heappop(self.q) def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F MOD = int(1e09) + 7 INF = int(1e15) def main(): # sys.stdin = open("sample.txt") X, Y, A, B, C = Scanner.map_int() P = Scanner.map_int() Q = Scanner.map_int() R = Scanner.map_int() P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) P = P[:X] Q = Q[:Y] A = P + Q + R A.sort(reverse=True) print((sum(A[: X + Y]))) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N**0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F MOD = int(1e09) + 7 INF = int(1e15) def solve(): X, Y, A, B, C = Scanner.map_int() P = Scanner.map_int() Q = Scanner.map_int() R = Scanner.map_int() P.sort(reverse=True) P = P[:X] Q.sort(reverse=True) Q = Q[:Y] R.sort(reverse=True) R = R[: min(X + Y, C)] ans = P + Q + R ans.sort(reverse=True) print((sum(ans[: X + Y]))) def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
false
9.090909
[ "+from collections import deque", "-from decimal import *", "+import decimal", "- return [eval(input()) for i in range(n)]", "+ return [Scanner.string() for i in range(n)]", "- return [int(eval(input())) for i in range(n)]", "+ return [Scanner.int() for i in range(n)]", "-", "-class PriorityQueue:", "- def __init__(self, l=[]):", "- self.q = l", "- heapq.heapify(self.q)", "- return", "-", "- def push(self, n):", "- heapq.heappush(self.q, n)", "- return", "-", "- def pop(self):", "- return heapq.heappop(self.q)", "+ @staticmethod", "+ def fact(N):", "+ res = {}", "+ tmp = N", "+ for i in range(2, int(N**0.5 + 1) + 1):", "+ cnt = 0", "+ while tmp % i == 0:", "+ cnt += 1", "+ tmp //= i", "+ if cnt > 0:", "+ res[i] = cnt", "+ if tmp != 1:", "+ res[tmp] = 1", "+ if res == {}:", "+ res[N] = 1", "+ return res", "-def main():", "- # sys.stdin = open(\"sample.txt\")", "+def solve():", "+ P = P[:X]", "+ Q = Q[:Y]", "- P = P[:X]", "- Q = Q[:Y]", "- A = P + Q + R", "- A.sort(reverse=True)", "- print((sum(A[: X + Y])))", "+ R = R[: min(X + Y, C)]", "+ ans = P + Q + R", "+ ans.sort(reverse=True)", "+ print((sum(ans[: X + Y])))", "+", "+", "+def main():", "+ # sys.stdin = open(\"sample.txt\")", "+ # T = Scanner.int()", "+ # for _ in range(T):", "+ # solve()", "+ # print('YNeos'[not solve()::2])", "+ solve()" ]
false
0.07092
0.068217
1.039629
[ "s553934810", "s225526092" ]
u775681539
p02690
python
s956912542
s503402143
758
67
9,324
64,700
Accepted
Accepted
91.16
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from itertools import combinations def main(): X = int(readline()) p = [int(i) for i in range(-1000, 1001)] for b, a in combinations(p, 2): if a**5 - b**5 == X: A = a B = b break print((A, B)) if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def f(a, b): return pow(a, 5) - pow(b, 5) def main(): x = int(readline()) for i in range(-1000, 1001): for j in range(-1000, 1001): if i**5 - j**5 == x: print((i, j)) return if __name__ == '__main__': main()
16
17
419
414
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from itertools import combinations def main(): X = int(readline()) p = [int(i) for i in range(-1000, 1001)] for b, a in combinations(p, 2): if a**5 - b**5 == X: A = a B = b break print((A, B)) if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def f(a, b): return pow(a, 5) - pow(b, 5) def main(): x = int(readline()) for i in range(-1000, 1001): for j in range(-1000, 1001): if i**5 - j**5 == x: print((i, j)) return if __name__ == "__main__": main()
false
5.882353
[ "-from itertools import combinations", "+", "+", "+def f(a, b):", "+ return pow(a, 5) - pow(b, 5)", "- X = int(readline())", "- p = [int(i) for i in range(-1000, 1001)]", "- for b, a in combinations(p, 2):", "- if a**5 - b**5 == X:", "- A = a", "- B = b", "- break", "- print((A, B))", "+ x = int(readline())", "+ for i in range(-1000, 1001):", "+ for j in range(-1000, 1001):", "+ if i**5 - j**5 == x:", "+ print((i, j))", "+ return" ]
false
1.054625
1.528412
0.690014
[ "s956912542", "s503402143" ]
u391731808
p02938
python
s726683391
s403683550
808
697
3,192
3,064
Accepted
Accepted
13.74
L,R = list(map(int,input().split())) mod = 10**9+7 def f(L,R): if L>R : return 0 R = bin(R)[2:] N = len(R) ret = f(L,int("0"+"1"*(N-1),2)) L = bin(L)[2:] if len(L) != N : L = "1"+"0"*(N-1) for i in range(N): if R[i] == "0" : continue R2 = R[:i] + "0" + "?"*(N-i-1) if i==0: R2 = R for j in range(N): if L[j] == "1" and j!=0 : continue L2 = L[:j] + "1" + "?"*(N-j-1) if j==0 : L2 = L if L2[0] == "0" : break tmp = 1 for r,l in zip(R2[1:],L2[1:]): if r=="0" and l=="1" : tmp *= 0 ; break if r=="?" and l=="?" : tmp = tmp*3%mod if r=="?" and l=="0" : tmp = tmp*2%mod if r=="1" and l=="?" : tmp = tmp*2%mod ret += tmp ret %= mod return ret print((f(L,R)))
L,R = list(map(int,input().split())) mod = 10**9+7 def f(L,R): if L>R : return 0 R = bin(R)[2:] N = len(R) ret = f(L,int("0"+"1"*(N-1),2)) L = bin(L)[2:] if len(L) != N : L = "1"+"0"*(N-1) for i in range(N): if R[i] == "0" : continue R2 = R[:i] + "0" + "?"*(N-i-1) if i==0: R2 = R for j in range(N): if L[j] == "1" and j!=0 : continue L2 = L[:j] + "1" + "?"*(N-j-1) if j==0 : L2 = L tmp = 1 for r,l in zip(R2,L2): if r=="0" and l=="1" : tmp *= 0 ; break elif r=="?" and l=="?" : tmp = tmp*3%mod elif r=="?" and l=="0" : tmp = tmp*2%mod elif r=="1" and l=="?" : tmp = tmp*2%mod ret += tmp ret %= mod return ret print((f(L,R)))
31
30
900
861
L, R = list(map(int, input().split())) mod = 10**9 + 7 def f(L, R): if L > R: return 0 R = bin(R)[2:] N = len(R) ret = f(L, int("0" + "1" * (N - 1), 2)) L = bin(L)[2:] if len(L) != N: L = "1" + "0" * (N - 1) for i in range(N): if R[i] == "0": continue R2 = R[:i] + "0" + "?" * (N - i - 1) if i == 0: R2 = R for j in range(N): if L[j] == "1" and j != 0: continue L2 = L[:j] + "1" + "?" * (N - j - 1) if j == 0: L2 = L if L2[0] == "0": break tmp = 1 for r, l in zip(R2[1:], L2[1:]): if r == "0" and l == "1": tmp *= 0 break if r == "?" and l == "?": tmp = tmp * 3 % mod if r == "?" and l == "0": tmp = tmp * 2 % mod if r == "1" and l == "?": tmp = tmp * 2 % mod ret += tmp ret %= mod return ret print((f(L, R)))
L, R = list(map(int, input().split())) mod = 10**9 + 7 def f(L, R): if L > R: return 0 R = bin(R)[2:] N = len(R) ret = f(L, int("0" + "1" * (N - 1), 2)) L = bin(L)[2:] if len(L) != N: L = "1" + "0" * (N - 1) for i in range(N): if R[i] == "0": continue R2 = R[:i] + "0" + "?" * (N - i - 1) if i == 0: R2 = R for j in range(N): if L[j] == "1" and j != 0: continue L2 = L[:j] + "1" + "?" * (N - j - 1) if j == 0: L2 = L tmp = 1 for r, l in zip(R2, L2): if r == "0" and l == "1": tmp *= 0 break elif r == "?" and l == "?": tmp = tmp * 3 % mod elif r == "?" and l == "0": tmp = tmp * 2 % mod elif r == "1" and l == "?": tmp = tmp * 2 % mod ret += tmp ret %= mod return ret print((f(L, R)))
false
3.225806
[ "- if L2[0] == \"0\":", "- break", "- for r, l in zip(R2[1:], L2[1:]):", "+ for r, l in zip(R2, L2):", "- if r == \"?\" and l == \"?\":", "+ elif r == \"?\" and l == \"?\":", "- if r == \"?\" and l == \"0\":", "+ elif r == \"?\" and l == \"0\":", "- if r == \"1\" and l == \"?\":", "+ elif r == \"1\" and l == \"?\":" ]
false
0.402202
0.438094
0.918072
[ "s726683391", "s403683550" ]
u440566786
p02684
python
s754338322
s270938763
776
352
180,196
170,356
Accepted
Accepted
54.64
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() def resolve(): n, k = list(map(int, input().split())) A = list([int(x) - 1 for x in input().split()]) nexts = [] nexts.append(A) for _ in range(61): next = nexts[-1] nnext = [None] * n for i in range(n): nnext[i] = next[next[i]] nexts.append(nnext) now = 0 for d in range(61): if (k >> d) & 1: now = nexts[d][now] print((now + 1)) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): n, k = list(map(int, input().split())) b = list([int(x) - 1 for x in input().split()]) now = 0 while k: if k & 1: now = b[now] b = [b[b[i]] for i in range(n)] k >>= 1 print((now + 1)) resolve()
25
16
591
398
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, k = list(map(int, input().split())) A = list([int(x) - 1 for x in input().split()]) nexts = [] nexts.append(A) for _ in range(61): next = nexts[-1] nnext = [None] * n for i in range(n): nnext[i] = next[next[i]] nexts.append(nnext) now = 0 for d in range(61): if (k >> d) & 1: now = nexts[d][now] print((now + 1)) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() def resolve(): n, k = list(map(int, input().split())) b = list([int(x) - 1 for x in input().split()]) now = 0 while k: if k & 1: now = b[now] b = [b[b[i]] for i in range(n)] k >>= 1 print((now + 1)) resolve()
false
36
[ "-sys.setrecursionlimit(2147483647)", "+sys.setrecursionlimit(2147483647)", "- A = list([int(x) - 1 for x in input().split()])", "- nexts = []", "- nexts.append(A)", "- for _ in range(61):", "- next = nexts[-1]", "- nnext = [None] * n", "- for i in range(n):", "- nnext[i] = next[next[i]]", "- nexts.append(nnext)", "+ b = list([int(x) - 1 for x in input().split()])", "- for d in range(61):", "- if (k >> d) & 1:", "- now = nexts[d][now]", "+ while k:", "+ if k & 1:", "+ now = b[now]", "+ b = [b[b[i]] for i in range(n)]", "+ k >>= 1" ]
false
0.047024
0.035711
1.316785
[ "s754338322", "s270938763" ]
u811967730
p02695
python
s851965023
s932931826
1,017
337
9,188
9,180
Accepted
Accepted
66.86
import itertools N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] max_score = 0 for A in itertools.combinations_with_replacement(list(range(1, M + 1)), N): score = 0 for a, b, c, d in ABCD: if A[b - 1] - A[a - 1] == c: score += d max_score = max(max_score, score) print(max_score)
import copy def dfs(A): global ans if len(A) == N: score = 0 for a, b, c, d in buff: if A[b - 1] - A[a - 1] == c: score += d ans = max(ans, score) return A.append(A[-1]) while A[-1] <= M: dfs(copy.copy(A)) A[-1] += 1 N, M, Q = list(map(int, input().split())) buff = [list(map(int, input().split())) for _ in range(Q)] ans = 0 dfs([1]) print(ans)
15
24
371
460
import itertools N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] max_score = 0 for A in itertools.combinations_with_replacement(list(range(1, M + 1)), N): score = 0 for a, b, c, d in ABCD: if A[b - 1] - A[a - 1] == c: score += d max_score = max(max_score, score) print(max_score)
import copy def dfs(A): global ans if len(A) == N: score = 0 for a, b, c, d in buff: if A[b - 1] - A[a - 1] == c: score += d ans = max(ans, score) return A.append(A[-1]) while A[-1] <= M: dfs(copy.copy(A)) A[-1] += 1 N, M, Q = list(map(int, input().split())) buff = [list(map(int, input().split())) for _ in range(Q)] ans = 0 dfs([1]) print(ans)
false
37.5
[ "-import itertools", "+import copy", "+", "+", "+def dfs(A):", "+ global ans", "+ if len(A) == N:", "+ score = 0", "+ for a, b, c, d in buff:", "+ if A[b - 1] - A[a - 1] == c:", "+ score += d", "+ ans = max(ans, score)", "+ return", "+ A.append(A[-1])", "+ while A[-1] <= M:", "+ dfs(copy.copy(A))", "+ A[-1] += 1", "+", "-ABCD = [list(map(int, input().split())) for _ in range(Q)]", "-max_score = 0", "-for A in itertools.combinations_with_replacement(list(range(1, M + 1)), N):", "- score = 0", "- for a, b, c, d in ABCD:", "- if A[b - 1] - A[a - 1] == c:", "- score += d", "- max_score = max(max_score, score)", "-print(max_score)", "+buff = [list(map(int, input().split())) for _ in range(Q)]", "+ans = 0", "+dfs([1])", "+print(ans)" ]
false
0.045416
0.100261
0.452974
[ "s851965023", "s932931826" ]
u047796752
p02682
python
s655019532
s281376854
67
58
64,776
61,796
Accepted
Accepted
13.43
from collections import * A, B, C, K = list(map(int, input().split())) if K<=A: print(K) elif K<=A+B: print(A) else: print((A-(K-A-B)))
A, B, C, K = list(map(int, input().split())) if K<A: print(K) elif K<A+B: print(A) else: print((A-(K-A-B)))
10
8
151
119
from collections import * A, B, C, K = list(map(int, input().split())) if K <= A: print(K) elif K <= A + B: print(A) else: print((A - (K - A - B)))
A, B, C, K = list(map(int, input().split())) if K < A: print(K) elif K < A + B: print(A) else: print((A - (K - A - B)))
false
20
[ "-from collections import *", "-", "-if K <= A:", "+if K < A:", "-elif K <= A + B:", "+elif K < A + B:" ]
false
0.040521
0.040133
1.009672
[ "s655019532", "s281376854" ]
u934442292
p02888
python
s673343158
s880622575
740
672
9,252
9,368
Accepted
Accepted
9.19
import sys import bisect input = sys.stdin.readline def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): c = bisect.bisect_left(L, L[a] + L[b]) - 1 ans += c - b print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left input = sys.stdin.readline def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): k = bisect_left(L, a + L[j]) ans += (k - 1 - j) print(ans) if __name__ == "__main__": main()
22
23
376
403
import sys import bisect input = sys.stdin.readline def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): c = bisect.bisect_left(L, L[a] + L[b]) - 1 ans += c - b print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left input = sys.stdin.readline def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): k = bisect_left(L, a + L[j]) ans += k - 1 - j print(ans) if __name__ == "__main__": main()
false
4.347826
[ "-import bisect", "+from bisect import bisect_left", "- for a in range(N - 2):", "- for b in range(a + 1, N - 1):", "- c = bisect.bisect_left(L, L[a] + L[b]) - 1", "- ans += c - b", "+ for i in range(N - 2):", "+ a = L[i]", "+ for j in range(i + 1, N - 1):", "+ k = bisect_left(L, a + L[j])", "+ ans += k - 1 - j" ]
false
0.045396
0.043677
1.039354
[ "s673343158", "s880622575" ]
u309834353
p03163
python
s636436924
s687696436
648
250
171,656
147,056
Accepted
Accepted
61.42
n,W = list(map(int, input().split())) w = [] v = [] for i in range(n): a,b = list(map(int, input().split())) w.append(a) v.append(b) c = [[0 for j in range(W)] for i in range(n)] for i in range(W): if i+1 < w[0]: c[0][i] = 0 else: c[0][i] = v[0] for i in range(1,n): for j in range(W): if j+1 < w[i]: c[i][j] = c[i-1][j] else: diff = (j+1)-w[i] if diff > 0: c[i][j] = max(c[i-1][j], v[i]+c[i-1][diff-1]) else: c[i][j] = max(c[i-1][j], v[i]) print((max(c[-1])))
def knapsack(W,weight,value): n = len(weight)#or len(value) dp = [[0]*(W+1) for _ in range(n+1)] # 初期化 for j in range(W): dp[0][j] = 0 for i in range(n): for j in range(W+1): if weight[i] <= j: dp[i+1][j] = max(dp[i][j-weight[i]]+value[i],dp[i][j]) else: dp[i+1][j] = dp[i][j] return dp N,W = list(map(int,input().split())) values, weights = [],[] for _ in range(N): w,v = list(map(int,input().split())) values.append(v) weights.append(w) dp = knapsack(W,weights,values) print((dp[-1][-1]))
26
23
610
612
n, W = list(map(int, input().split())) w = [] v = [] for i in range(n): a, b = list(map(int, input().split())) w.append(a) v.append(b) c = [[0 for j in range(W)] for i in range(n)] for i in range(W): if i + 1 < w[0]: c[0][i] = 0 else: c[0][i] = v[0] for i in range(1, n): for j in range(W): if j + 1 < w[i]: c[i][j] = c[i - 1][j] else: diff = (j + 1) - w[i] if diff > 0: c[i][j] = max(c[i - 1][j], v[i] + c[i - 1][diff - 1]) else: c[i][j] = max(c[i - 1][j], v[i]) print((max(c[-1])))
def knapsack(W, weight, value): n = len(weight) # or len(value) dp = [[0] * (W + 1) for _ in range(n + 1)] # 初期化 for j in range(W): dp[0][j] = 0 for i in range(n): for j in range(W + 1): if weight[i] <= j: dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j]) else: dp[i + 1][j] = dp[i][j] return dp N, W = list(map(int, input().split())) values, weights = [], [] for _ in range(N): w, v = list(map(int, input().split())) values.append(v) weights.append(w) dp = knapsack(W, weights, values) print((dp[-1][-1]))
false
11.538462
[ "-n, W = list(map(int, input().split()))", "-w = []", "-v = []", "-for i in range(n):", "- a, b = list(map(int, input().split()))", "- w.append(a)", "- v.append(b)", "-c = [[0 for j in range(W)] for i in range(n)]", "-for i in range(W):", "- if i + 1 < w[0]:", "- c[0][i] = 0", "- else:", "- c[0][i] = v[0]", "-for i in range(1, n):", "+def knapsack(W, weight, value):", "+ n = len(weight) # or len(value)", "+ dp = [[0] * (W + 1) for _ in range(n + 1)]", "+ # 初期化", "- if j + 1 < w[i]:", "- c[i][j] = c[i - 1][j]", "- else:", "- diff = (j + 1) - w[i]", "- if diff > 0:", "- c[i][j] = max(c[i - 1][j], v[i] + c[i - 1][diff - 1])", "+ dp[0][j] = 0", "+ for i in range(n):", "+ for j in range(W + 1):", "+ if weight[i] <= j:", "+ dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j])", "- c[i][j] = max(c[i - 1][j], v[i])", "-print((max(c[-1])))", "+ dp[i + 1][j] = dp[i][j]", "+ return dp", "+", "+", "+N, W = list(map(int, input().split()))", "+values, weights = [], []", "+for _ in range(N):", "+ w, v = list(map(int, input().split()))", "+ values.append(v)", "+ weights.append(w)", "+dp = knapsack(W, weights, values)", "+print((dp[-1][-1]))" ]
false
0.033747
0.035452
0.951911
[ "s636436924", "s687696436" ]
u806976856
p03449
python
s678376346
s347653022
32
28
9,164
9,180
Accepted
Accepted
12.5
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) dp=[[0 for i in range(n)] for j in range(2)] dp[0][0]=a[0] for i in range(1,n): dp[0][i]=a[i]+dp[0][i-1] dp[1][0]=dp[0][0]+b[0] for i in range(1,n): dp[1][i]=max(dp[0][i],dp[1][i-1])+b[i] print((dp[1][n-1]))
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 for i in range(n): z=0 for j in range(i+1): z+=a[j] for j in range(i,n): z+=b[j] ans=max(ans,z) print(ans)
12
12
307
237
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) dp = [[0 for i in range(n)] for j in range(2)] dp[0][0] = a[0] for i in range(1, n): dp[0][i] = a[i] + dp[0][i - 1] dp[1][0] = dp[0][0] + b[0] for i in range(1, n): dp[1][i] = max(dp[0][i], dp[1][i - 1]) + b[i] print((dp[1][n - 1]))
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i in range(n): z = 0 for j in range(i + 1): z += a[j] for j in range(i, n): z += b[j] ans = max(ans, z) print(ans)
false
0
[ "-dp = [[0 for i in range(n)] for j in range(2)]", "-dp[0][0] = a[0]", "-for i in range(1, n):", "- dp[0][i] = a[i] + dp[0][i - 1]", "-dp[1][0] = dp[0][0] + b[0]", "-for i in range(1, n):", "- dp[1][i] = max(dp[0][i], dp[1][i - 1]) + b[i]", "-print((dp[1][n - 1]))", "+ans = 0", "+for i in range(n):", "+ z = 0", "+ for j in range(i + 1):", "+ z += a[j]", "+ for j in range(i, n):", "+ z += b[j]", "+ ans = max(ans, z)", "+print(ans)" ]
false
0.045719
0.041632
1.098181
[ "s678376346", "s347653022" ]
u573754721
p02899
python
s035656350
s272896257
221
116
34,288
13,812
Accepted
Accepted
47.51
n=int(eval(input())) a=list(map(int,input().split())) d={} for i in range(len(a)): d.update([(i,a[i])]) new_d = sorted(list(d.items()),key=lambda x:x[1]) p=[] for i in range(len(a)): p.append(new_d[i][0]+1) print((' '.join(map(str,p))))
import bisect n=int(eval(input())) L=list(map(int,(eval(input())).split())) L=list([x-1 for x in L]) NL=[0]*n for i in range(n): NL[L[i]]=i+1 print((*NL))
12
10
247
163
n = int(eval(input())) a = list(map(int, input().split())) d = {} for i in range(len(a)): d.update([(i, a[i])]) new_d = sorted(list(d.items()), key=lambda x: x[1]) p = [] for i in range(len(a)): p.append(new_d[i][0] + 1) print((" ".join(map(str, p))))
import bisect n = int(eval(input())) L = list(map(int, (eval(input())).split())) L = list([x - 1 for x in L]) NL = [0] * n for i in range(n): NL[L[i]] = i + 1 print((*NL))
false
16.666667
[ "+import bisect", "+", "-a = list(map(int, input().split()))", "-d = {}", "-for i in range(len(a)):", "- d.update([(i, a[i])])", "-new_d = sorted(list(d.items()), key=lambda x: x[1])", "-p = []", "-for i in range(len(a)):", "- p.append(new_d[i][0] + 1)", "-print((\" \".join(map(str, p))))", "+L = list(map(int, (eval(input())).split()))", "+L = list([x - 1 for x in L])", "+NL = [0] * n", "+for i in range(n):", "+ NL[L[i]] = i + 1", "+print((*NL))" ]
false
0.043762
0.037559
1.165143
[ "s035656350", "s272896257" ]
u163320134
p02934
python
s377265894
s956811521
178
17
39,024
2,940
Accepted
Accepted
90.45
n=int(eval(input())) arr=list(map(int,input().split())) sum1=1 for val in arr: sum1*=val sum2=0 for i in range(n): tmp=1 for j in range(n): if i==j: continue tmp*=arr[j] sum2+=tmp print((sum1/sum2))
n=int(eval(input())) arr=list(map(int,input().split())) sums=0 for val in arr: sums+=1.0/val print((1.0/sums))
14
6
225
109
n = int(eval(input())) arr = list(map(int, input().split())) sum1 = 1 for val in arr: sum1 *= val sum2 = 0 for i in range(n): tmp = 1 for j in range(n): if i == j: continue tmp *= arr[j] sum2 += tmp print((sum1 / sum2))
n = int(eval(input())) arr = list(map(int, input().split())) sums = 0 for val in arr: sums += 1.0 / val print((1.0 / sums))
false
57.142857
[ "-sum1 = 1", "+sums = 0", "- sum1 *= val", "-sum2 = 0", "-for i in range(n):", "- tmp = 1", "- for j in range(n):", "- if i == j:", "- continue", "- tmp *= arr[j]", "- sum2 += tmp", "-print((sum1 / sum2))", "+ sums += 1.0 / val", "+print((1.0 / sums))" ]
false
0.079707
0.03911
2.038012
[ "s377265894", "s956811521" ]
u935558307
p02788
python
s661526009
s964167528
1,501
1,066
221,708
224,032
Accepted
Accepted
28.98
""" 普通に端っこを基準にして、貪欲的に爆弾をおいていく方法を考えるのがよさそう。 座標圧縮したうえで、遅延セグ木で各座標に蓄積しているダメージを管理しておけばよい。 一番左端のやつの体力を削れるだけの爆弾を設置してみる:O(1) 次の左端になるモンスターの位置(体力が1以上あるモンスターのなかで一番左端のやつの座標)を探す。これはO(logN)かかる。 このサイクルをモンスターが全滅するまで行うので、O(N)サイクル回す。したがって全体でO(NlogN) """ from math import ceil class lazySegTree: def __init__(self,n): self.end_leave = 2**(n.bit_length()+1) self.tree = [0]*(2*self.end_leave) self.lazy = [0]*(2*self.end_leave) def gindex(self,left,right): #leftとrightの真上にあるノードを返す left = left + self.end_leave right = right + self.end_leave left >>= 1 while left: yield left left >>= 1 right >>= 1 while right: yield right right >>= 1 def add(self,left,right,x): L = left + self.end_leave R = right + self.end_leave while L < R: if L&1: self.lazy[L] += x self.tree[L] += x L += 1 if R&1: R -= 1 self.lazy[R] += x self.tree[R] += x L >>= 1 R >>= 1 for i in self.gindex(left,right): self.tree[i] = max(self.tree[i*2],self.tree[i*2+1])+self.lazy[i] def propagates(self,*ids): for i in reversed(ids): self.lazy[i*2] += self.lazy[i] self.lazy[i*2+1] += self.lazy[i] self.tree[i*2] += self.lazy[i] self.tree[i*2+1] += self.lazy[i] self.lazy[i] = 0 def get(self,left,right): self.propagates(*self.gindex(left,right)) L = left + self.end_leave R = right + self.end_leave res = 0 while L < R: if L&1: res = max(res,self.tree[L]) L += 1 if R&1: R -= 1 res = max(res,self.tree[R]) L >>= 1 R >>= 1 return res N,D,A = list(map(int,input().split())) XH = [list(map(int,input().split())) for _ in range(N)] XH.sort() compSet = [] for x,h in XH: compSet.append(x) compSet.append(x+2*D) compSet.sort() compSet = sorted(set(compSet)) compDic = {x:i for i,x in enumerate(compSet)} LST = lazySegTree(len(compDic)) ans = 0 for x,h in XH: compX = compDic[x] h -= LST.get(compX,compX+1) if h > 0: bomb = ceil(h/A) ans += bomb damage = bomb*A compRight = compDic[x+2*D] LST.add(compX,compRight+1,damage) print(ans)
""" lazyseg使う方法とかもあるが、imos法使うのが簡単そう。 座標圧縮は必須。 """ from math import ceil N,D,A = list(map(int,input().split())) XH = [list(map(int,input().split())) for _ in range(N)] XH.sort() coordinates = set() for x,h in XH: coordinates.add(x) coordinates.add(x+2*D+1) compress = {x:i for i,x in enumerate(sorted(coordinates))} imos = [0]*(len(compress)) damage = 0 cur = 0 ans = 0 for x,h in XH: compX = compress[x] while cur <= compX: damage += imos[cur] cur += 1 rest = h-damage if rest > 0: add = A*ceil(rest/A) ans += int(ceil(rest/A)) imos[cur] += add right = compress[x+2*D+1] imos[right] -= add print(ans)
93
33
2,593
709
""" 普通に端っこを基準にして、貪欲的に爆弾をおいていく方法を考えるのがよさそう。 座標圧縮したうえで、遅延セグ木で各座標に蓄積しているダメージを管理しておけばよい。 一番左端のやつの体力を削れるだけの爆弾を設置してみる:O(1) 次の左端になるモンスターの位置(体力が1以上あるモンスターのなかで一番左端のやつの座標)を探す。これはO(logN)かかる。 このサイクルをモンスターが全滅するまで行うので、O(N)サイクル回す。したがって全体でO(NlogN) """ from math import ceil class lazySegTree: def __init__(self, n): self.end_leave = 2 ** (n.bit_length() + 1) self.tree = [0] * (2 * self.end_leave) self.lazy = [0] * (2 * self.end_leave) def gindex(self, left, right): # leftとrightの真上にあるノードを返す left = left + self.end_leave right = right + self.end_leave left >>= 1 while left: yield left left >>= 1 right >>= 1 while right: yield right right >>= 1 def add(self, left, right, x): L = left + self.end_leave R = right + self.end_leave while L < R: if L & 1: self.lazy[L] += x self.tree[L] += x L += 1 if R & 1: R -= 1 self.lazy[R] += x self.tree[R] += x L >>= 1 R >>= 1 for i in self.gindex(left, right): self.tree[i] = max(self.tree[i * 2], self.tree[i * 2 + 1]) + self.lazy[i] def propagates(self, *ids): for i in reversed(ids): self.lazy[i * 2] += self.lazy[i] self.lazy[i * 2 + 1] += self.lazy[i] self.tree[i * 2] += self.lazy[i] self.tree[i * 2 + 1] += self.lazy[i] self.lazy[i] = 0 def get(self, left, right): self.propagates(*self.gindex(left, right)) L = left + self.end_leave R = right + self.end_leave res = 0 while L < R: if L & 1: res = max(res, self.tree[L]) L += 1 if R & 1: R -= 1 res = max(res, self.tree[R]) L >>= 1 R >>= 1 return res N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() compSet = [] for x, h in XH: compSet.append(x) compSet.append(x + 2 * D) compSet.sort() compSet = sorted(set(compSet)) compDic = {x: i for i, x in enumerate(compSet)} LST = lazySegTree(len(compDic)) ans = 0 for x, h in XH: compX = compDic[x] h -= LST.get(compX, compX + 1) if h > 0: bomb = ceil(h / A) ans += bomb damage = bomb * A compRight = compDic[x + 2 * D] LST.add(compX, compRight + 1, damage) print(ans)
""" lazyseg使う方法とかもあるが、imos法使うのが簡単そう。 座標圧縮は必須。 """ from math import ceil N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() coordinates = set() for x, h in XH: coordinates.add(x) coordinates.add(x + 2 * D + 1) compress = {x: i for i, x in enumerate(sorted(coordinates))} imos = [0] * (len(compress)) damage = 0 cur = 0 ans = 0 for x, h in XH: compX = compress[x] while cur <= compX: damage += imos[cur] cur += 1 rest = h - damage if rest > 0: add = A * ceil(rest / A) ans += int(ceil(rest / A)) imos[cur] += add right = compress[x + 2 * D + 1] imos[right] -= add print(ans)
false
64.516129
[ "-普通に端っこを基準にして、貪欲的に爆弾をおいていく方法を考えるのがよさそう。", "-座標圧縮したうえで、遅延セグ木で各座標に蓄積しているダメージを管理しておけばよい。", "-一番左端のやつの体力を削れるだけの爆弾を設置してみる:O(1)", "-次の左端になるモンスターの位置(体力が1以上あるモンスターのなかで一番左端のやつの座標)を探す。これはO(logN)かかる。", "-このサイクルをモンスターが全滅するまで行うので、O(N)サイクル回す。したがって全体でO(NlogN)", "+lazyseg使う方法とかもあるが、imos法使うのが簡単そう。", "+座標圧縮は必須。", "-", "-", "-class lazySegTree:", "- def __init__(self, n):", "- self.end_leave = 2 ** (n.bit_length() + 1)", "- self.tree = [0] * (2 * self.end_leave)", "- self.lazy = [0] * (2 * self.end_leave)", "-", "- def gindex(self, left, right):", "- # leftとrightの真上にあるノードを返す", "- left = left + self.end_leave", "- right = right + self.end_leave", "- left >>= 1", "- while left:", "- yield left", "- left >>= 1", "- right >>= 1", "- while right:", "- yield right", "- right >>= 1", "-", "- def add(self, left, right, x):", "- L = left + self.end_leave", "- R = right + self.end_leave", "- while L < R:", "- if L & 1:", "- self.lazy[L] += x", "- self.tree[L] += x", "- L += 1", "- if R & 1:", "- R -= 1", "- self.lazy[R] += x", "- self.tree[R] += x", "- L >>= 1", "- R >>= 1", "- for i in self.gindex(left, right):", "- self.tree[i] = max(self.tree[i * 2], self.tree[i * 2 + 1]) + self.lazy[i]", "-", "- def propagates(self, *ids):", "- for i in reversed(ids):", "- self.lazy[i * 2] += self.lazy[i]", "- self.lazy[i * 2 + 1] += self.lazy[i]", "- self.tree[i * 2] += self.lazy[i]", "- self.tree[i * 2 + 1] += self.lazy[i]", "- self.lazy[i] = 0", "-", "- def get(self, left, right):", "- self.propagates(*self.gindex(left, right))", "- L = left + self.end_leave", "- R = right + self.end_leave", "- res = 0", "- while L < R:", "- if L & 1:", "- res = max(res, self.tree[L])", "- L += 1", "- if R & 1:", "- R -= 1", "- res = max(res, self.tree[R])", "- L >>= 1", "- R >>= 1", "- return res", "-", "-compSet = []", "+coordinates = set()", "- compSet.append(x)", "- compSet.append(x + 2 * D)", "-compSet.sort()", "-compSet = sorted(set(compSet))", "-compDic = {x: i for i, x in enumerate(compSet)}", "-LST = lazySegTree(len(compDic))", "+ coordinates.add(x)", "+ coordinates.add(x + 2 * D + 1)", "+compress = {x: i for i, x in enumerate(sorted(coordinates))}", "+imos = [0] * (len(compress))", "+damage = 0", "+cur = 0", "- compX = compDic[x]", "- h -= LST.get(compX, compX + 1)", "- if h > 0:", "- bomb = ceil(h / A)", "- ans += bomb", "- damage = bomb * A", "- compRight = compDic[x + 2 * D]", "- LST.add(compX, compRight + 1, damage)", "+ compX = compress[x]", "+ while cur <= compX:", "+ damage += imos[cur]", "+ cur += 1", "+ rest = h - damage", "+ if rest > 0:", "+ add = A * ceil(rest / A)", "+ ans += int(ceil(rest / A))", "+ imos[cur] += add", "+ right = compress[x + 2 * D + 1]", "+ imos[right] -= add" ]
false
0.048618
0.007558
6.432748
[ "s661526009", "s964167528" ]
u597374218
p03597
python
s664815147
s505333044
33
29
9,136
9,136
Accepted
Accepted
12.12
N=int(eval(input())) A=int(eval(input())) print((N*N-A))
N=int(eval(input())) A=int(eval(input())) print((N**2-A))
3
3
44
45
N = int(eval(input())) A = int(eval(input())) print((N * N - A))
N = int(eval(input())) A = int(eval(input())) print((N**2 - A))
false
0
[ "-print((N * N - A))", "+print((N**2 - A))" ]
false
0.036876
0.039004
0.945452
[ "s664815147", "s505333044" ]
u540631540
p02832
python
s392161942
s063426982
236
108
25,768
26,268
Accepted
Accepted
54.24
n = int(eval(input())) a = [int(i) for i in input().split()] c = 0 d = 0 for i in range(n): for j in range(c, n): if i + 1 == a[j]: c = j d += 1 break else: break if c == n - 1: break if 1 not in a: print((-1)) else: print((n - d))
n = int(eval(input())) a = [int(i) for i in input().split()] if 1 in a: j = 0 for ai in a: if ai == j + 1: j += 1 print((n - j)) else: print((-1))
18
10
318
181
n = int(eval(input())) a = [int(i) for i in input().split()] c = 0 d = 0 for i in range(n): for j in range(c, n): if i + 1 == a[j]: c = j d += 1 break else: break if c == n - 1: break if 1 not in a: print((-1)) else: print((n - d))
n = int(eval(input())) a = [int(i) for i in input().split()] if 1 in a: j = 0 for ai in a: if ai == j + 1: j += 1 print((n - j)) else: print((-1))
false
44.444444
[ "-c = 0", "-d = 0", "-for i in range(n):", "- for j in range(c, n):", "- if i + 1 == a[j]:", "- c = j", "- d += 1", "- break", "- else:", "- break", "- if c == n - 1:", "- break", "-if 1 not in a:", "+if 1 in a:", "+ j = 0", "+ for ai in a:", "+ if ai == j + 1:", "+ j += 1", "+ print((n - j))", "+else:", "-else:", "- print((n - d))" ]
false
0.036679
0.038765
0.946193
[ "s392161942", "s063426982" ]
u098968285
p03137
python
s697344914
s810223523
137
115
13,960
13,968
Accepted
Accepted
16.06
def makelist(n, m): return [[0 for _ in range(m)] for _ in range(n)] N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() hoge = [0]*(M-1) for i in range(1, M): hoge[i-1] = X[i] - X[i-1] hoge = list(reversed(sorted(hoge))) ans = sum(hoge) if N >= M: ans = 0 else: for i in range(N-1): ans -= hoge[i] print(ans)
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X = list(sorted(X)) Y = [0]*(M-1) for i in range(M-1): Y[i] = X[i+1] - X[i] Y = list(reversed(sorted(Y))) ans = sum(Y) - sum(Y[:N-1]) print(ans)
20
12
383
232
def makelist(n, m): return [[0 for _ in range(m)] for _ in range(n)] N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() hoge = [0] * (M - 1) for i in range(1, M): hoge[i - 1] = X[i] - X[i - 1] hoge = list(reversed(sorted(hoge))) ans = sum(hoge) if N >= M: ans = 0 else: for i in range(N - 1): ans -= hoge[i] print(ans)
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X = list(sorted(X)) Y = [0] * (M - 1) for i in range(M - 1): Y[i] = X[i + 1] - X[i] Y = list(reversed(sorted(Y))) ans = sum(Y) - sum(Y[: N - 1]) print(ans)
false
40
[ "-def makelist(n, m):", "- return [[0 for _ in range(m)] for _ in range(n)]", "-", "-", "-X.sort()", "-hoge = [0] * (M - 1)", "-for i in range(1, M):", "- hoge[i - 1] = X[i] - X[i - 1]", "-hoge = list(reversed(sorted(hoge)))", "-ans = sum(hoge)", "-if N >= M:", "- ans = 0", "-else:", "- for i in range(N - 1):", "- ans -= hoge[i]", "+X = list(sorted(X))", "+Y = [0] * (M - 1)", "+for i in range(M - 1):", "+ Y[i] = X[i + 1] - X[i]", "+Y = list(reversed(sorted(Y)))", "+ans = sum(Y) - sum(Y[: N - 1])" ]
false
0.045513
0.04076
1.116621
[ "s697344914", "s810223523" ]
u230621983
p03645
python
s583589150
s980999531
611
265
21,944
21,804
Accepted
Accepted
56.63
n, m = list(map(int, input().split())) transit = [] transit_ = [] for a,b in (list(map(int, input().split())) for _ in range(m)): if a == 1: transit.append(b) if b == n: transit_.append(a) if set(transit)&set(transit_): print("POSSIBLE") else: print("IMPOSSIBLE")
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) transit = [] transit_ = [] for a,b in (list(map(int, input().split())) for _ in range(m)): if a == 1: transit.append(b) if b == n: transit_.append(a) if set(transit)&set(transit_): print("POSSIBLE") else: print("IMPOSSIBLE")
15
18
300
342
n, m = list(map(int, input().split())) transit = [] transit_ = [] for a, b in (list(map(int, input().split())) for _ in range(m)): if a == 1: transit.append(b) if b == n: transit_.append(a) if set(transit) & set(transit_): print("POSSIBLE") else: print("IMPOSSIBLE")
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) transit = [] transit_ = [] for a, b in (list(map(int, input().split())) for _ in range(m)): if a == 1: transit.append(b) if b == n: transit_.append(a) if set(transit) & set(transit_): print("POSSIBLE") else: print("IMPOSSIBLE")
false
16.666667
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.038491
0.038958
0.988011
[ "s583589150", "s980999531" ]
u729133443
p03085
python
s169275653
s237284807
20
17
2,940
2,940
Accepted
Accepted
15
print(('TA CG'[(66-ord(eval(input())))//4]))
print(('TCG A'[ord(eval(input()))%5]))
1
1
37
30
print(("TA CG"[(66 - ord(eval(input()))) // 4]))
print(("TCG A"[ord(eval(input())) % 5]))
false
0
[ "-print((\"TA CG\"[(66 - ord(eval(input()))) // 4]))", "+print((\"TCG A\"[ord(eval(input())) % 5]))" ]
false
0.047399
0.048845
0.970413
[ "s169275653", "s237284807" ]
u648881683
p02883
python
s669206035
s504685543
761
461
138,032
37,292
Accepted
Accepted
39.42
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(eval(input())) def F(): return float(eval(input())) def S(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N, K = LI() A = LI() F = LI() A.sort() F.sort(reverse=True) # 時間tで感触できるか def can_complete(t): return sum([max(i-t//j, 0) for i, j in zip(A, F)]) <= K # for j in range(20): # print(can_complete(j)) ng = -1 ok = max(A)*max(F) while abs(ok-ng)>1: m = (ng+ok)//2 if can_complete(m): ok = m else: ng = m print(ok) if __name__ == '__main__': resolve()
import sys import numpy as np input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(eval(input())) def F(): return float(eval(input())) def S(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N, K = LI() A = np.array(LI()) F = np.array(LI()) A.sort() F.sort() F = F[::-1] # 時間tで感触できるか def can_complete(t): return np.maximum(0, A-t//F).sum() <= K # for j in range(20): # print(can_complete(j)) ng = -1 ok = max(A)*max(F) while abs(ok-ng)>1: m = (ng+ok)//2 if can_complete(m): ok = m else: ng = m print(ok) if __name__ == '__main__': resolve()
39
41
896
925
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(eval(input())) def F(): return float(eval(input())) def S(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N, K = LI() A = LI() F = LI() A.sort() F.sort(reverse=True) # 時間tで感触できるか def can_complete(t): return sum([max(i - t // j, 0) for i, j in zip(A, F)]) <= K # for j in range(20): # print(can_complete(j)) ng = -1 ok = max(A) * max(F) while abs(ok - ng) > 1: m = (ng + ok) // 2 if can_complete(m): ok = m else: ng = m print(ok) if __name__ == "__main__": resolve()
import sys import numpy as np input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(eval(input())) def F(): return float(eval(input())) def S(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N, K = LI() A = np.array(LI()) F = np.array(LI()) A.sort() F.sort() F = F[::-1] # 時間tで感触できるか def can_complete(t): return np.maximum(0, A - t // F).sum() <= K # for j in range(20): # print(can_complete(j)) ng = -1 ok = max(A) * max(F) while abs(ok - ng) > 1: m = (ng + ok) // 2 if can_complete(m): ok = m else: ng = m print(ok) if __name__ == "__main__": resolve()
false
4.878049
[ "+import numpy as np", "- A = LI()", "- F = LI()", "+ A = np.array(LI())", "+ F = np.array(LI())", "- F.sort(reverse=True)", "+ F.sort()", "+ F = F[::-1]", "- return sum([max(i - t // j, 0) for i, j in zip(A, F)]) <= K", "+ return np.maximum(0, A - t // F).sum() <= K" ]
false
0.039822
0.200067
0.199042
[ "s669206035", "s504685543" ]
u659159398
p02659
python
s005379779
s545746853
149
64
72,884
61,852
Accepted
Accepted
57.05
from fractions import Fraction a, b = list(map(Fraction, input().split())) print((int(a*b)))
a, b = input().split() a = int(a) bint, bdec = list(map(int, b.split('.'))) b = 100*bint + bdec print(((a*b)//100))
4
6
88
113
from fractions import Fraction a, b = list(map(Fraction, input().split())) print((int(a * b)))
a, b = input().split() a = int(a) bint, bdec = list(map(int, b.split("."))) b = 100 * bint + bdec print(((a * b) // 100))
false
33.333333
[ "-from fractions import Fraction", "-", "-a, b = list(map(Fraction, input().split()))", "-print((int(a * b)))", "+a, b = input().split()", "+a = int(a)", "+bint, bdec = list(map(int, b.split(\".\")))", "+b = 100 * bint + bdec", "+print(((a * b) // 100))" ]
false
0.044071
0.03721
1.184393
[ "s005379779", "s545746853" ]
u588341295
p02787
python
s398888350
s543829882
624
424
41,452
40,940
Accepted
Accepted
32.05
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 H, N = MAP() AB = [] for i in range(N): a, b = MAP() AB.append((a, b)) dp = [INF] * 20007 dp[0] = 0 for i in range(20007): for a, b in AB: if i-a >= 0: dp[i] = min(dp[i], dp[i-a] + b) ans = min(dp[H:]) 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(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 H, N = MAP() AB = [] for i in range(N): a, b = MAP() AB.append((a, b)) dp = [INF] * 20007 dp[0] = 0 for a, b in AB: for i in range(20007): if i-a >= 0: dp[i] = min(dp[i], dp[i-a] + b) ans = min(dp[H:]) print(ans)
34
34
956
956
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 H, N = MAP() AB = [] for i in range(N): a, b = MAP() AB.append((a, b)) dp = [INF] * 20007 dp[0] = 0 for i in range(20007): for a, b in AB: if i - a >= 0: dp[i] = min(dp[i], dp[i - a] + b) ans = min(dp[H:]) 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(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 H, N = MAP() AB = [] for i in range(N): a, b = MAP() AB.append((a, b)) dp = [INF] * 20007 dp[0] = 0 for a, b in AB: for i in range(20007): if i - a >= 0: dp[i] = min(dp[i], dp[i - a] + b) ans = min(dp[H:]) print(ans)
false
0
[ "-for i in range(20007):", "- for a, b in AB:", "+for a, b in AB:", "+ for i in range(20007):" ]
false
0.135577
0.125854
1.077253
[ "s398888350", "s543829882" ]
u537782349
p03695
python
s105606210
s894457418
21
18
3,316
3,064
Accepted
Accepted
14.29
a = int(eval(input())) b = list(map(int, input().split())) c = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0} d = 0 for i in b: if 1 <= i <= 399: c[0] += 1 elif 400 <= i <= 799: c[1] += 1 elif 800 <= i <= 1199: c[2] += 1 elif 1200 <= i <= 1599: c[3] += 1 elif 1600 <= i <= 1999: c[4] += 1 elif 2000 <= i <= 2399: c[5] += 1 elif 2400 <= i <= 2799: c[6] += 1 elif 2800 <= i <= 3199: c[7] += 1 else: d += 1 e = 0 for k, v in list(c.items()): if v != 0: e += 1 print((str(max(e, 1)) + " " + str(e + d)))
a = int(eval(input())) b = list(map(int, input().split())) c = {} for i in b: if 1 <= i <= 399: c[0] = 1 elif 400 <= i <= 799: c[1] = 1 elif 800 <= i <= 1199: c[2] = 1 elif 1200 <= i <= 1599: c[3] = 1 elif 1600 <= i <= 1999: c[4] = 1 elif 2000 <= i <= 2399: c[5] = 1 elif 2400 <= i <= 2799: c[6] = 1 elif 2800 <= i <= 3199: c[7] = 1 else: if 8 not in c: c[8] = 1 else: c[8] += 1 count = 0 se = 0 for k, v in list(c.items()): if k == 8: se = v else: count += 1 if se == 0: print(("{} {}".format(count, count))) else: if count == 0: print(("{} {}".format(1, se))) else: print(("{} {}".format(count, count + se)))
28
39
635
823
a = int(eval(input())) b = list(map(int, input().split())) c = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0} d = 0 for i in b: if 1 <= i <= 399: c[0] += 1 elif 400 <= i <= 799: c[1] += 1 elif 800 <= i <= 1199: c[2] += 1 elif 1200 <= i <= 1599: c[3] += 1 elif 1600 <= i <= 1999: c[4] += 1 elif 2000 <= i <= 2399: c[5] += 1 elif 2400 <= i <= 2799: c[6] += 1 elif 2800 <= i <= 3199: c[7] += 1 else: d += 1 e = 0 for k, v in list(c.items()): if v != 0: e += 1 print((str(max(e, 1)) + " " + str(e + d)))
a = int(eval(input())) b = list(map(int, input().split())) c = {} for i in b: if 1 <= i <= 399: c[0] = 1 elif 400 <= i <= 799: c[1] = 1 elif 800 <= i <= 1199: c[2] = 1 elif 1200 <= i <= 1599: c[3] = 1 elif 1600 <= i <= 1999: c[4] = 1 elif 2000 <= i <= 2399: c[5] = 1 elif 2400 <= i <= 2799: c[6] = 1 elif 2800 <= i <= 3199: c[7] = 1 else: if 8 not in c: c[8] = 1 else: c[8] += 1 count = 0 se = 0 for k, v in list(c.items()): if k == 8: se = v else: count += 1 if se == 0: print(("{} {}".format(count, count))) else: if count == 0: print(("{} {}".format(1, se))) else: print(("{} {}".format(count, count + se)))
false
28.205128
[ "-c = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}", "-d = 0", "+c = {}", "- c[0] += 1", "+ c[0] = 1", "- c[1] += 1", "+ c[1] = 1", "- c[2] += 1", "+ c[2] = 1", "- c[3] += 1", "+ c[3] = 1", "- c[4] += 1", "+ c[4] = 1", "- c[5] += 1", "+ c[5] = 1", "- c[6] += 1", "+ c[6] = 1", "- c[7] += 1", "+ c[7] = 1", "- d += 1", "-e = 0", "+ if 8 not in c:", "+ c[8] = 1", "+ else:", "+ c[8] += 1", "+count = 0", "+se = 0", "- if v != 0:", "- e += 1", "-print((str(max(e, 1)) + \" \" + str(e + d)))", "+ if k == 8:", "+ se = v", "+ else:", "+ count += 1", "+if se == 0:", "+ print((\"{} {}\".format(count, count)))", "+else:", "+ if count == 0:", "+ print((\"{} {}\".format(1, se)))", "+ else:", "+ print((\"{} {}\".format(count, count + se)))" ]
false
0.041145
0.041131
1.000346
[ "s105606210", "s894457418" ]
u614628638
p02733
python
s603430606
s186717914
824
513
3,564
3,564
Accepted
Accepted
37.74
from collections import defaultdict from itertools import product H,W,K = list(map(int,input().split())) S = [eval(input()) for i in range(H)] C = [[int(S[i][k]) for i in range(H)] for k in range(W)] answer = H*W #出力がこれを超えることはない for X in product([True,False],repeat = H-1): M = [[0]] ans = sum(X) if ans > answer:#初期値がanswerよりも大きかったら考える必要がない continue for i,x in enumerate(X):#配列Mの作成 if x: M.append([]) M[-1].append(i+1) D = [0]*len(M) for c in C: for k,m in enumerate(M): D[k] += sum(c[i] for i in m)#k番目の要素に足していく #Dにどんどん代入することによってどの列まで足すことができるか算出することができる if any(d>K for d in D):#一つでもKを超えていたら ans += 1 if ans >answer: break D = [sum(c[i] for i in m) for m in M]#超えた行について再び調査 if any(d>K for d in D): ans = answer + 1 #デフォルトanswerの結果より高い値にしてこの結果が出力にならないように設定する break answer = min(answer,ans)#あるXに対してanswerを算出(更新) print(answer)
from collections import defaultdict from itertools import product H,W,K = list(map(int,input().split())) S = [eval(input()) for i in range(H)] C = [[int(S[i][k]) for i in range(H)] for k in range(W)] answer = H*W #出力がこれを超えることはない for X in product([False,True],repeat = H-1): M = [[0]] ans = sum(X) if ans > answer:#初期値がanswerよりも大きかったら考える必要がない continue for i,x in enumerate(X):#配列Mの作成 if x: M.append([]) M[-1].append(i+1) D = [0]*len(M) for c in C: for k,m in enumerate(M): D[k] += sum(c[i] for i in m)#k番目の要素に足していく #Dにどんどん代入することによってどの列まで足すことができるか算出することができる if any(d>K for d in D):#一つでもKを超えていたら ans += 1 if ans >answer: break D = [sum(c[i] for i in m) for m in M]#超えた行について再び調査 if any(d>K for d in D): ans = answer + 1 #デフォルトanswerの結果より高い値にしてこの結果が出力にならないように設定する break answer = min(answer,ans)#あるXに対してanswerを算出(更新) print(answer)
33
33
955
956
from collections import defaultdict from itertools import product H, W, K = list(map(int, input().split())) S = [eval(input()) for i in range(H)] C = [[int(S[i][k]) for i in range(H)] for k in range(W)] answer = H * W # 出力がこれを超えることはない for X in product([True, False], repeat=H - 1): M = [[0]] ans = sum(X) if ans > answer: # 初期値がanswerよりも大きかったら考える必要がない continue for i, x in enumerate(X): # 配列Mの作成 if x: M.append([]) M[-1].append(i + 1) D = [0] * len(M) for c in C: for k, m in enumerate(M): D[k] += sum(c[i] for i in m) # k番目の要素に足していく # Dにどんどん代入することによってどの列まで足すことができるか算出することができる if any(d > K for d in D): # 一つでもKを超えていたら ans += 1 if ans > answer: break D = [sum(c[i] for i in m) for m in M] # 超えた行について再び調査 if any(d > K for d in D): ans = answer + 1 # デフォルトanswerの結果より高い値にしてこの結果が出力にならないように設定する break answer = min(answer, ans) # あるXに対してanswerを算出(更新) print(answer)
from collections import defaultdict from itertools import product H, W, K = list(map(int, input().split())) S = [eval(input()) for i in range(H)] C = [[int(S[i][k]) for i in range(H)] for k in range(W)] answer = H * W # 出力がこれを超えることはない for X in product([False, True], repeat=H - 1): M = [[0]] ans = sum(X) if ans > answer: # 初期値がanswerよりも大きかったら考える必要がない continue for i, x in enumerate(X): # 配列Mの作成 if x: M.append([]) M[-1].append(i + 1) D = [0] * len(M) for c in C: for k, m in enumerate(M): D[k] += sum(c[i] for i in m) # k番目の要素に足していく # Dにどんどん代入することによってどの列まで足すことができるか算出することができる if any(d > K for d in D): # 一つでもKを超えていたら ans += 1 if ans > answer: break D = [sum(c[i] for i in m) for m in M] # 超えた行について再び調査 if any(d > K for d in D): ans = answer + 1 # デフォルトanswerの結果より高い値にしてこの結果が出力にならないように設定する break answer = min(answer, ans) # あるXに対してanswerを算出(更新) print(answer)
false
0
[ "-for X in product([True, False], repeat=H - 1):", "+for X in product([False, True], repeat=H - 1):" ]
false
0.048104
0.118976
0.404318
[ "s603430606", "s186717914" ]
u297574184
p02819
python
s096529424
s457814083
132
29
24,660
9,360
Accepted
Accepted
78.03
maxA = 10**6 X = int(eval(input())) def getIsPrimes(n): isPrimes = [False]*2 + [True]*(n-1) for x in range(2*2, n+1, 2): isPrimes[x] = False for d in range(3, int(n**0.5)+1): if isPrimes[d]: for x in range(d*d, n+1, d): isPrimes[x] = False return isPrimes isPrimes = getIsPrimes(maxA) for i in range(X, maxA+1): if isPrimes[i]: print(i) break
maxA = 10**5 + 3 X = int(eval(input())) def isPrime(x): for d in range(2, int(x**0.5)+1): if x%d == 0: return False return x != 1 for i in range(X, maxA+1): if isPrime(i): print(i) break
21
14
442
245
maxA = 10**6 X = int(eval(input())) def getIsPrimes(n): isPrimes = [False] * 2 + [True] * (n - 1) for x in range(2 * 2, n + 1, 2): isPrimes[x] = False for d in range(3, int(n**0.5) + 1): if isPrimes[d]: for x in range(d * d, n + 1, d): isPrimes[x] = False return isPrimes isPrimes = getIsPrimes(maxA) for i in range(X, maxA + 1): if isPrimes[i]: print(i) break
maxA = 10**5 + 3 X = int(eval(input())) def isPrime(x): for d in range(2, int(x**0.5) + 1): if x % d == 0: return False return x != 1 for i in range(X, maxA + 1): if isPrime(i): print(i) break
false
33.333333
[ "-maxA = 10**6", "+maxA = 10**5 + 3", "-def getIsPrimes(n):", "- isPrimes = [False] * 2 + [True] * (n - 1)", "- for x in range(2 * 2, n + 1, 2):", "- isPrimes[x] = False", "- for d in range(3, int(n**0.5) + 1):", "- if isPrimes[d]:", "- for x in range(d * d, n + 1, d):", "- isPrimes[x] = False", "- return isPrimes", "+def isPrime(x):", "+ for d in range(2, int(x**0.5) + 1):", "+ if x % d == 0:", "+ return False", "+ return x != 1", "-isPrimes = getIsPrimes(maxA)", "- if isPrimes[i]:", "+ if isPrime(i):" ]
false
0.616074
0.034546
17.833344
[ "s096529424", "s457814083" ]
u200887663
p02719
python
s538137079
s683597640
43
22
5,560
9,152
Accepted
Accepted
48.84
#n=int(input()) n,k=list(map(int,input().split())) #l=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] ans=0 import fractions newval=n%k if n>=k: ans=min(n%k,abs(k-n%k)) else: ans=min(k-n,n) print(ans)
#k=int(input()) n,k=list(map(int,input().split())) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] t=n%k print((min(t,k-t)))
12
7
250
165
# n=int(input()) n, k = list(map(int, input().split())) # l=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] ans = 0 import fractions newval = n % k if n >= k: ans = min(n % k, abs(k - n % k)) else: ans = min(k - n, n) print(ans)
# k=int(input()) n, k = list(map(int, input().split())) # hl=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] t = n % k print((min(t, k - t)))
false
41.666667
[ "-# n=int(input())", "+# k=int(input())", "-# l=list(map(int,input().split()))", "+# hl=list(map(int,input().split()))", "-ans = 0", "-import fractions", "-", "-newval = n % k", "-if n >= k:", "- ans = min(n % k, abs(k - n % k))", "-else:", "- ans = min(k - n, n)", "-print(ans)", "+t = n % k", "+print((min(t, k - t)))" ]
false
0.054087
0.046563
1.161581
[ "s538137079", "s683597640" ]
u632413369
p02675
python
s715785211
s287528942
308
61
81,104
61,800
Accepted
Accepted
80.19
n = int(eval(input())) % 10 a = 'hon' if n == 3: a = 'bon' elif n in [0,1,6,8]: a = 'pon' print(a)
n = int(eval(input())) % 10 a = 'hon' if n == 3: a = 'bon' elif n == 0 or n == 1 or n == 6 or n == 8: a = 'pon' print(a)
7
7
106
128
n = int(eval(input())) % 10 a = "hon" if n == 3: a = "bon" elif n in [0, 1, 6, 8]: a = "pon" print(a)
n = int(eval(input())) % 10 a = "hon" if n == 3: a = "bon" elif n == 0 or n == 1 or n == 6 or n == 8: a = "pon" print(a)
false
0
[ "-elif n in [0, 1, 6, 8]:", "+elif n == 0 or n == 1 or n == 6 or n == 8:" ]
false
0.036199
0.035551
1.01822
[ "s715785211", "s287528942" ]
u576432509
p03328
python
s171226148
s550497520
151
17
2,940
2,940
Accepted
Accepted
88.74
icase=0 if icase==0: import sys a,b=list(map(int,input().split())) for i in range(1,999): isum=(i*(i+1))//2-a for j in range(i,1000): jsum=(j*(j+1))//2-b if jsum==isum and 1<=jsum and j==i+1: print(jsum) sys.exit()
icase=0 if icase==0: a,b=list(map(int,input().split())) n=b-a-1 print((n*(n+1)//2-a))
11
6
303
107
icase = 0 if icase == 0: import sys a, b = list(map(int, input().split())) for i in range(1, 999): isum = (i * (i + 1)) // 2 - a for j in range(i, 1000): jsum = (j * (j + 1)) // 2 - b if jsum == isum and 1 <= jsum and j == i + 1: print(jsum) sys.exit()
icase = 0 if icase == 0: a, b = list(map(int, input().split())) n = b - a - 1 print((n * (n + 1) // 2 - a))
false
45.454545
[ "- import sys", "-", "- for i in range(1, 999):", "- isum = (i * (i + 1)) // 2 - a", "- for j in range(i, 1000):", "- jsum = (j * (j + 1)) // 2 - b", "- if jsum == isum and 1 <= jsum and j == i + 1:", "- print(jsum)", "- sys.exit()", "+ n = b - a - 1", "+ print((n * (n + 1) // 2 - a))" ]
false
0.120975
0.035673
3.391261
[ "s171226148", "s550497520" ]
u227082700
p03059
python
s924047049
s574053950
20
18
3,316
2,940
Accepted
Accepted
10
a,b,c=list(map(int,input().split())) print(((c//a)*b))
a,b,t=list(map(int,input().split())) print(((t//a)*b))
2
2
47
47
a, b, c = list(map(int, input().split())) print(((c // a) * b))
a, b, t = list(map(int, input().split())) print(((t // a) * b))
false
0
[ "-a, b, c = list(map(int, input().split()))", "-print(((c // a) * b))", "+a, b, t = list(map(int, input().split()))", "+print(((t // a) * b))" ]
false
0.04833
0.048162
1.003489
[ "s924047049", "s574053950" ]
u627803856
p02936
python
s214234544
s499342529
1,855
1,699
284,512
55,828
Accepted
Accepted
8.41
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) n, q = list(map(int, input().split())) AB = [[int(x) for x in input().split()] for _ in range(n - 1)] PX = [[int(x) for x in input().split()] for _ in range(q)] graph = [[] for _ in range(n + 1)] for a, b in AB: graph[a].append(b) graph[b].append(a) value = [0] * (n + 1) for p, x in PX: value[p] += x def dfs(v, parent, add): value[v] += add for x in graph[v]: if x == parent: continue dfs(x, v, value[v]) dfs(1, 0, 0) print((*value[1:]))
n, q = list(map(int, input().split())) graph = [[] for _ in range(n + 1)] for i in range(n - 1): a, b = list(map(int, input().split())) graph[a].append(b) graph[b].append(a) counter = [0] * (n + 1) for i in range(q): p, x = list(map(int, input().split())) counter[p] += x parents = [0] * (n + 1) q = [1] while q: y = q.pop() for x in graph[y]: if x == parents[y]: continue counter[x] += counter[y] q.append(x) parents[x] = y print((*counter[1:]))
27
27
545
531
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n, q = list(map(int, input().split())) AB = [[int(x) for x in input().split()] for _ in range(n - 1)] PX = [[int(x) for x in input().split()] for _ in range(q)] graph = [[] for _ in range(n + 1)] for a, b in AB: graph[a].append(b) graph[b].append(a) value = [0] * (n + 1) for p, x in PX: value[p] += x def dfs(v, parent, add): value[v] += add for x in graph[v]: if x == parent: continue dfs(x, v, value[v]) dfs(1, 0, 0) print((*value[1:]))
n, q = list(map(int, input().split())) graph = [[] for _ in range(n + 1)] for i in range(n - 1): a, b = list(map(int, input().split())) graph[a].append(b) graph[b].append(a) counter = [0] * (n + 1) for i in range(q): p, x = list(map(int, input().split())) counter[p] += x parents = [0] * (n + 1) q = [1] while q: y = q.pop() for x in graph[y]: if x == parents[y]: continue counter[x] += counter[y] q.append(x) parents[x] = y print((*counter[1:]))
false
0
[ "-import sys", "-", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-AB = [[int(x) for x in input().split()] for _ in range(n - 1)]", "-PX = [[int(x) for x in input().split()] for _ in range(q)]", "-for a, b in AB:", "+for i in range(n - 1):", "+ a, b = list(map(int, input().split()))", "-value = [0] * (n + 1)", "-for p, x in PX:", "- value[p] += x", "-", "-", "-def dfs(v, parent, add):", "- value[v] += add", "- for x in graph[v]:", "- if x == parent:", "+counter = [0] * (n + 1)", "+for i in range(q):", "+ p, x = list(map(int, input().split()))", "+ counter[p] += x", "+parents = [0] * (n + 1)", "+q = [1]", "+while q:", "+ y = q.pop()", "+ for x in graph[y]:", "+ if x == parents[y]:", "- dfs(x, v, value[v])", "-", "-", "-dfs(1, 0, 0)", "-print((*value[1:]))", "+ counter[x] += counter[y]", "+ q.append(x)", "+ parents[x] = y", "+print((*counter[1:]))" ]
false
0.035981
0.035463
1.014598
[ "s214234544", "s499342529" ]
u193182854
p02845
python
s374232522
s260129789
201
91
14,056
14,092
Accepted
Accepted
54.73
n = int(eval(input())) a = list(map(int, input().split())) MOD = 10**9+7 ans = 1 s = [0] * 3 for i in range(n): ans *= len([0 for x in s if x == a[i]]) if ans == 0: break ans %= MOD for j in range(3): if s[j] == a[i]: s[j] += 1 break print((ans % MOD))
MOD = 10**9+7 n = int(eval(input())) a = list(map(int, input().split())) cnt = [0 for _ in range(n)] ans = 1 for x in a: if x > 0: ans *= cnt[x-1] - cnt[x] else: ans *= 3 - cnt[0] cnt[x] += 1 ans %= MOD print(ans)
16
13
310
252
n = int(eval(input())) a = list(map(int, input().split())) MOD = 10**9 + 7 ans = 1 s = [0] * 3 for i in range(n): ans *= len([0 for x in s if x == a[i]]) if ans == 0: break ans %= MOD for j in range(3): if s[j] == a[i]: s[j] += 1 break print((ans % MOD))
MOD = 10**9 + 7 n = int(eval(input())) a = list(map(int, input().split())) cnt = [0 for _ in range(n)] ans = 1 for x in a: if x > 0: ans *= cnt[x - 1] - cnt[x] else: ans *= 3 - cnt[0] cnt[x] += 1 ans %= MOD print(ans)
false
18.75
[ "+MOD = 10**9 + 7", "-MOD = 10**9 + 7", "+cnt = [0 for _ in range(n)]", "-s = [0] * 3", "-for i in range(n):", "- ans *= len([0 for x in s if x == a[i]])", "- if ans == 0:", "- break", "+for x in a:", "+ if x > 0:", "+ ans *= cnt[x - 1] - cnt[x]", "+ else:", "+ ans *= 3 - cnt[0]", "+ cnt[x] += 1", "- for j in range(3):", "- if s[j] == a[i]:", "- s[j] += 1", "- break", "-print((ans % MOD))", "+print(ans)" ]
false
0.038785
0.037353
1.038327
[ "s374232522", "s260129789" ]
u545368057
p02936
python
s756969065
s787393805
1,982
1,832
108,080
93,488
Accepted
Accepted
7.57
N,Q = list(map(int, input().split())) # 木 G = [[] for i in range(N)] for i in range(N-1): u,v = list(map(int,input().split())) G[u-1].append((v-1)) G[v-1].append((u-1)) ## クエリを覚えておく scores = [0]*N for i in range(Q): p,x = list(map(int, input().split())) scores[p-1] += x # 和をとっていく ans = [0]*N ans[0] = scores[0] used = [False] * N """ dfs TLEする。なんで """ # import sys # sys.setrecursionlimit(100000) # def dfs(G, v): # # vを訪問済みにする # used[v] = True # #グラフ中の次のVについて # for next_v in G[v]: # if used[next_v]: continue # ans[next_v] = ans[v] + scores[next_v] # dfs(G, next_v) # dfs(G,0) # print(*ans) # 木をBFSをする from collections import deque used = [False] * N used[0] = True # 始めどこから行くか q = deque([0]) while len(q) > 0: v = q.popleft() Vs = G[v] for next_v in Vs: if not used[next_v]: q.append(next_v) ans[next_v] = ans[v] + scores[next_v] used[next_v] = True print((*ans))
N,Q = list(map(int, input().split())) # 木 G = [[] for i in range(N)] for i in range(N-1): u,v = list(map(int,input().split())) G[u-1].append((v-1)) # a<bが決まっているなら、必要ない? # G[v-1].append((u-1)) ## クエリを覚えておく scores = [0]*N for i in range(Q): p,x = list(map(int, input().split())) scores[p-1] += x # 和をとっていく ans = [0]*N ans[0] = scores[0] used = [False] * N # 木をBFSをする from collections import deque used = [False] * N used[0] = True # 始めどこから行くか q = deque([0]) while len(q) > 0: v = q.popleft() Vs = G[v] for next_v in Vs: if not used[next_v]: q.append(next_v) ans[next_v] = ans[v] + scores[next_v] used[next_v] = True print((*ans))
51
36
1,015
730
N, Q = list(map(int, input().split())) # 木 G = [[] for i in range(N)] for i in range(N - 1): u, v = list(map(int, input().split())) G[u - 1].append((v - 1)) G[v - 1].append((u - 1)) ## クエリを覚えておく scores = [0] * N for i in range(Q): p, x = list(map(int, input().split())) scores[p - 1] += x # 和をとっていく ans = [0] * N ans[0] = scores[0] used = [False] * N """ dfs TLEする。なんで """ # import sys # sys.setrecursionlimit(100000) # def dfs(G, v): # # vを訪問済みにする # used[v] = True # #グラフ中の次のVについて # for next_v in G[v]: # if used[next_v]: continue # ans[next_v] = ans[v] + scores[next_v] # dfs(G, next_v) # dfs(G,0) # print(*ans) # 木をBFSをする from collections import deque used = [False] * N used[0] = True # 始めどこから行くか q = deque([0]) while len(q) > 0: v = q.popleft() Vs = G[v] for next_v in Vs: if not used[next_v]: q.append(next_v) ans[next_v] = ans[v] + scores[next_v] used[next_v] = True print((*ans))
N, Q = list(map(int, input().split())) # 木 G = [[] for i in range(N)] for i in range(N - 1): u, v = list(map(int, input().split())) G[u - 1].append((v - 1)) # a<bが決まっているなら、必要ない? # G[v-1].append((u-1)) ## クエリを覚えておく scores = [0] * N for i in range(Q): p, x = list(map(int, input().split())) scores[p - 1] += x # 和をとっていく ans = [0] * N ans[0] = scores[0] used = [False] * N # 木をBFSをする from collections import deque used = [False] * N used[0] = True # 始めどこから行くか q = deque([0]) while len(q) > 0: v = q.popleft() Vs = G[v] for next_v in Vs: if not used[next_v]: q.append(next_v) ans[next_v] = ans[v] + scores[next_v] used[next_v] = True print((*ans))
false
29.411765
[ "- G[v - 1].append((u - 1))", "+ # a<bが決まっているなら、必要ない?", "+ # G[v-1].append((u-1))", "-\"\"\"", "-dfs TLEする。なんで", "-\"\"\"", "-# import sys", "-# sys.setrecursionlimit(100000)", "-# def dfs(G, v):", "-# # vを訪問済みにする", "-# used[v] = True", "-# #グラフ中の次のVについて", "-# for next_v in G[v]:", "-# if used[next_v]: continue", "-# ans[next_v] = ans[v] + scores[next_v]", "-# dfs(G, next_v)", "-# dfs(G,0)", "-# print(*ans)" ]
false
0.04228
0.040263
1.050097
[ "s756969065", "s787393805" ]
u417096287
p02936
python
s310475025
s629225610
1,805
774
105,236
128,508
Accepted
Accepted
57.12
from collections import deque N, Q = list(map(int, input().split())) tree = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) tree[a - 1].append(b - 1) tree[b - 1].append(a - 1) X = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) X[p - 1] += x d = deque([0]) ans = X visited = [False] * N while d: q = d.pop() visited[q] = True for t in tree[q]: if not visited[t]: ans[t] += X[q] d.append(t) print((*ans))
from collections import deque def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N, Q = MI() T = [[] for _ in range(N)] for _ in range(N - 1): a, b = MI() T[a - 1].append(b - 1) T[b - 1].append(a - 1) plus = [0] * N for _ in range(Q): p, x = MI() plus[p - 1] += x queue = deque([0]) visited = [False] * N while queue: u = queue.popleft() visited[u] = True for t in T[u]: if not visited[t]: plus[t] += plus[u] queue.append(t) print((*plus))
31
35
546
602
from collections import deque N, Q = list(map(int, input().split())) tree = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) tree[a - 1].append(b - 1) tree[b - 1].append(a - 1) X = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) X[p - 1] += x d = deque([0]) ans = X visited = [False] * N while d: q = d.pop() visited[q] = True for t in tree[q]: if not visited[t]: ans[t] += X[q] d.append(t) print((*ans))
from collections import deque def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N, Q = MI() T = [[] for _ in range(N)] for _ in range(N - 1): a, b = MI() T[a - 1].append(b - 1) T[b - 1].append(a - 1) plus = [0] * N for _ in range(Q): p, x = MI() plus[p - 1] += x queue = deque([0]) visited = [False] * N while queue: u = queue.popleft() visited[u] = True for t in T[u]: if not visited[t]: plus[t] += plus[u] queue.append(t) print((*plus))
false
11.428571
[ "-N, Q = list(map(int, input().split()))", "-tree = [[] for _ in range(N)]", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+N, Q = MI()", "+T = [[] for _ in range(N)]", "- a, b = list(map(int, input().split()))", "- tree[a - 1].append(b - 1)", "- tree[b - 1].append(a - 1)", "-X = [0] * N", "+ a, b = MI()", "+ T[a - 1].append(b - 1)", "+ T[b - 1].append(a - 1)", "+plus = [0] * N", "- p, x = list(map(int, input().split()))", "- X[p - 1] += x", "-d = deque([0])", "-ans = X", "+ p, x = MI()", "+ plus[p - 1] += x", "+queue = deque([0])", "-while d:", "- q = d.pop()", "- visited[q] = True", "- for t in tree[q]:", "+while queue:", "+ u = queue.popleft()", "+ visited[u] = True", "+ for t in T[u]:", "- ans[t] += X[q]", "- d.append(t)", "-print((*ans))", "+ plus[t] += plus[u]", "+ queue.append(t)", "+print((*plus))" ]
false
0.038967
0.037647
1.035053
[ "s310475025", "s629225610" ]
u197955752
p03103
python
s832238028
s512211334
494
330
21,612
21,536
Accepted
Accepted
33.2
N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(N)] PRICE = 0 NBOTTLE = 1 AB.sort() # price昇順でソート bought = 0 paid = 0 for i in range(N): if bought >= M: break buy = min(M - bought, AB[i][NBOTTLE]) bought += buy paid += buy * AB[i][PRICE] print(paid)
import sys input=sys.stdin.readline N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(N)] PRICE = 0 NBOTTLE = 1 AB.sort() # price昇順でソート bought = 0 paid = 0 for i in range(N): if bought >= M: break buy = min(M - bought, AB[i][NBOTTLE]) bought += buy paid += buy * AB[i][PRICE] print(paid)
15
18
329
370
N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(N)] PRICE = 0 NBOTTLE = 1 AB.sort() # price昇順でソート bought = 0 paid = 0 for i in range(N): if bought >= M: break buy = min(M - bought, AB[i][NBOTTLE]) bought += buy paid += buy * AB[i][PRICE] print(paid)
import sys input = sys.stdin.readline N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(N)] PRICE = 0 NBOTTLE = 1 AB.sort() # price昇順でソート bought = 0 paid = 0 for i in range(N): if bought >= M: break buy = min(M - bought, AB[i][NBOTTLE]) bought += buy paid += buy * AB[i][PRICE] print(paid)
false
16.666667
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.0412
0.044057
0.935166
[ "s832238028", "s512211334" ]
u600402037
p02862
python
s209567322
s270698565
700
255
82,448
53,576
Accepted
Accepted
63.57
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def cmb(n, k, mod, fac, ifac): # nCkを計算する k = min(k, n-k) return fac[n] * ifac[k] * ifac[n-k] % mod def make_tables(mod, n): # 階乗テーブル、逆元の階乗テーブルを作成する fac = [1, 1] # 階乗テーブル ifac = [1, 1] # 逆元の階乗テーブル inverse = [0, 1] # 逆元テーブル 0の階乗は1 0の逆元は0 for i in range(2, n+1): fac.append((fac[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) ifac.append((ifac[-1] * inverse[-1]) % mod) return fac, ifac X, Y = lr() MOD = 10 ** 9 + 7 if (X+Y)%3 != 0 or X > 2 * Y or Y > 2 * X: print((0)) exit() if X < Y: X, Y = Y, X # Xが大きい total_time = (X+Y)//3 x_time = (X - Y + total_time) // 2 # total_time C i_time fac, ifac = make_tables(MOD, total_time) answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD print(answer) # 44
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD def cumprod(arr, MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10 ** 6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) X, Y = lr() if (X+Y)%3 != 0 or X > Y + Y or Y > X + X: print((0)); exit() time = (X+Y) // 3 diff = abs(X-Y) a = (time-diff)//2 # timeCaが答え answer = cmb(time, a) print((answer%MOD))
38
41
971
1,086
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def cmb(n, k, mod, fac, ifac): # nCkを計算する k = min(k, n - k) return fac[n] * ifac[k] * ifac[n - k] % mod def make_tables(mod, n): # 階乗テーブル、逆元の階乗テーブルを作成する fac = [1, 1] # 階乗テーブル ifac = [1, 1] # 逆元の階乗テーブル inverse = [0, 1] # 逆元テーブル 0の階乗は1 0の逆元は0 for i in range(2, n + 1): fac.append((fac[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) ifac.append((ifac[-1] * inverse[-1]) % mod) return fac, ifac X, Y = lr() MOD = 10**9 + 7 if (X + Y) % 3 != 0 or X > 2 * Y or Y > 2 * X: print((0)) exit() if X < Y: X, Y = Y, X # Xが大きい total_time = (X + Y) // 3 x_time = (X - Y + total_time) // 2 # total_time C i_time fac, ifac = make_tables(MOD, total_time) answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD print(answer) # 44
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10**9 + 7 def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) X, Y = lr() if (X + Y) % 3 != 0 or X > Y + Y or Y > X + X: print((0)) exit() time = (X + Y) // 3 diff = abs(X - Y) a = (time - diff) // 2 # timeCaが答え answer = cmb(time, a) print((answer % MOD))
false
7.317073
[ "+import numpy as np", "+MOD = 10**9 + 7", "-def cmb(n, k, mod, fac, ifac):", "- # nCkを計算する", "- k = min(k, n - k)", "- return fac[n] * ifac[k] * ifac[n - k] % mod", "+def cmb(n, k):", "+ if k < 0 or k > n:", "+ return 0", "+ return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD", "-def make_tables(mod, n):", "- # 階乗テーブル、逆元の階乗テーブルを作成する", "- fac = [1, 1] # 階乗テーブル", "- ifac = [1, 1] # 逆元の階乗テーブル", "- inverse = [0, 1] # 逆元テーブル 0の階乗は1 0の逆元は0", "- for i in range(2, n + 1):", "- fac.append((fac[-1] * i) % mod)", "- inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "- ifac.append((ifac[-1] * inverse[-1]) % mod)", "- return fac, ifac", "+def cumprod(arr, MOD):", "+ L = len(arr)", "+ Lsq = int(L**0.5 + 1)", "+ arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)", "+ for n in range(1, Lsq):", "+ arr[:, n] *= arr[:, n - 1]", "+ arr[:, n] %= MOD", "+ for n in range(1, Lsq):", "+ arr[n] *= arr[n - 1, -1]", "+ arr[n] %= MOD", "+ return arr.ravel()[:L]", "+def make_fact(U, MOD):", "+ x = np.arange(U, dtype=np.int64)", "+ x[0] = 1", "+ fact = cumprod(x, MOD)", "+ x = np.arange(U, 0, -1, dtype=np.int64)", "+ x[0] = pow(int(fact[-1]), MOD - 2, MOD)", "+ fact_inv = cumprod(x, MOD)[::-1]", "+ return fact, fact_inv", "+", "+", "+U = 10**6 # 階乗テーブルの上限", "+fact, fact_inv = make_fact(U, MOD)", "-MOD = 10**9 + 7", "-if (X + Y) % 3 != 0 or X > 2 * Y or Y > 2 * X:", "+if (X + Y) % 3 != 0 or X > Y + Y or Y > X + X:", "-if X < Y:", "- X, Y = Y, X", "-# Xが大きい", "-total_time = (X + Y) // 3", "-x_time = (X - Y + total_time) // 2", "-# total_time C i_time", "-fac, ifac = make_tables(MOD, total_time)", "-answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD", "-print(answer)", "-# 44", "+time = (X + Y) // 3", "+diff = abs(X - Y)", "+a = (time - diff) // 2", "+# timeCaが答え", "+answer = cmb(time, a)", "+print((answer % MOD))" ]
false
0.70967
0.708827
1.001189
[ "s209567322", "s270698565" ]
u747602774
p03997
python
s617555953
s646472471
161
20
38,256
3,188
Accepted
Accepted
87.58
a=int(eval(input())) b=int(eval(input())) h=int(eval(input())) S=(a+b)*h//2 print(S)
a = int(eval(input())) b = int(eval(input())) h = int(eval(input())) print(((a+b)*h//2))
7
4
74
71
a = int(eval(input())) b = int(eval(input())) h = int(eval(input())) S = (a + b) * h // 2 print(S)
a = int(eval(input())) b = int(eval(input())) h = int(eval(input())) print(((a + b) * h // 2))
false
42.857143
[ "-S = (a + b) * h // 2", "-print(S)", "+print(((a + b) * h // 2))" ]
false
0.042454
0.034964
1.214238
[ "s617555953", "s646472471" ]
u392319141
p03310
python
s632859225
s762194953
1,010
599
25,676
58,140
Accepted
Accepted
40.69
N = int(eval(input())) A = list(map(int, input().split())) S = [0] * (N+1) for i in range(N) : S[i+1] = S[i] + A[i] leftMiddle = 0 rightMiddle = 2 ans = float('inf') for middle in range(2, N-1) : leftS = S[leftMiddle] rightS = S[middle] - leftS diff = abs(leftS - rightS) # 左側の更新 for i in range(leftMiddle, middle) : leftS += A[i] rightS -= A[i] if diff > abs(leftS - rightS) : leftMiddle += 1 diff = abs(leftS - rightS) else : break leftS = S[rightMiddle] - S[middle] rightS = S[-1] - S[rightMiddle] diff = abs(leftS - rightS) # 右側の更新 for i in range(rightMiddle, N) : leftS += A[i] rightS -= A[i] if diff > abs(leftS - rightS) : rightMiddle += 1 diff = abs(leftS - rightS) else : break B = S[leftMiddle] C = S[middle] - B D = S[rightMiddle] - S[middle] E = S[-1] - B - C - D diff = max(B, C, D, E) - min(B, C, D, E) ans = min(ans, diff) print(ans)
N = int(eval(input())) A = tuple(map(int, input().split())) def calc(B): P, Q = B[0], B[1] ret = [None] * N ret[1] = (P, Q) mid = 1 for right in range(2, N - 2): Q += B[right] while mid < right: newP = P + B[mid] newQ = Q - B[mid] if abs(newP - newQ) >= abs(P - Q): break mid += 1 P = newP Q = newQ ret[right] = (P, Q) return ret left = calc(A)[1: -2] right = calc(A[:: -1])[1: -2][:: -1] ans = 10**10 for (P, Q), (R, S) in zip(left, right): ans = min(ans, abs(max(P, Q, R, S) - min(P, Q, R, S))) print(ans)
51
33
1,108
682
N = int(eval(input())) A = list(map(int, input().split())) S = [0] * (N + 1) for i in range(N): S[i + 1] = S[i] + A[i] leftMiddle = 0 rightMiddle = 2 ans = float("inf") for middle in range(2, N - 1): leftS = S[leftMiddle] rightS = S[middle] - leftS diff = abs(leftS - rightS) # 左側の更新 for i in range(leftMiddle, middle): leftS += A[i] rightS -= A[i] if diff > abs(leftS - rightS): leftMiddle += 1 diff = abs(leftS - rightS) else: break leftS = S[rightMiddle] - S[middle] rightS = S[-1] - S[rightMiddle] diff = abs(leftS - rightS) # 右側の更新 for i in range(rightMiddle, N): leftS += A[i] rightS -= A[i] if diff > abs(leftS - rightS): rightMiddle += 1 diff = abs(leftS - rightS) else: break B = S[leftMiddle] C = S[middle] - B D = S[rightMiddle] - S[middle] E = S[-1] - B - C - D diff = max(B, C, D, E) - min(B, C, D, E) ans = min(ans, diff) print(ans)
N = int(eval(input())) A = tuple(map(int, input().split())) def calc(B): P, Q = B[0], B[1] ret = [None] * N ret[1] = (P, Q) mid = 1 for right in range(2, N - 2): Q += B[right] while mid < right: newP = P + B[mid] newQ = Q - B[mid] if abs(newP - newQ) >= abs(P - Q): break mid += 1 P = newP Q = newQ ret[right] = (P, Q) return ret left = calc(A)[1:-2] right = calc(A[::-1])[1:-2][::-1] ans = 10**10 for (P, Q), (R, S) in zip(left, right): ans = min(ans, abs(max(P, Q, R, S) - min(P, Q, R, S))) print(ans)
false
35.294118
[ "-A = list(map(int, input().split()))", "-S = [0] * (N + 1)", "-for i in range(N):", "- S[i + 1] = S[i] + A[i]", "-leftMiddle = 0", "-rightMiddle = 2", "-ans = float(\"inf\")", "-for middle in range(2, N - 1):", "- leftS = S[leftMiddle]", "- rightS = S[middle] - leftS", "- diff = abs(leftS - rightS)", "- # 左側の更新", "- for i in range(leftMiddle, middle):", "- leftS += A[i]", "- rightS -= A[i]", "- if diff > abs(leftS - rightS):", "- leftMiddle += 1", "- diff = abs(leftS - rightS)", "- else:", "- break", "- leftS = S[rightMiddle] - S[middle]", "- rightS = S[-1] - S[rightMiddle]", "- diff = abs(leftS - rightS)", "- # 右側の更新", "- for i in range(rightMiddle, N):", "- leftS += A[i]", "- rightS -= A[i]", "- if diff > abs(leftS - rightS):", "- rightMiddle += 1", "- diff = abs(leftS - rightS)", "- else:", "- break", "- B = S[leftMiddle]", "- C = S[middle] - B", "- D = S[rightMiddle] - S[middle]", "- E = S[-1] - B - C - D", "- diff = max(B, C, D, E) - min(B, C, D, E)", "- ans = min(ans, diff)", "+A = tuple(map(int, input().split()))", "+", "+", "+def calc(B):", "+ P, Q = B[0], B[1]", "+ ret = [None] * N", "+ ret[1] = (P, Q)", "+ mid = 1", "+ for right in range(2, N - 2):", "+ Q += B[right]", "+ while mid < right:", "+ newP = P + B[mid]", "+ newQ = Q - B[mid]", "+ if abs(newP - newQ) >= abs(P - Q):", "+ break", "+ mid += 1", "+ P = newP", "+ Q = newQ", "+ ret[right] = (P, Q)", "+ return ret", "+", "+", "+left = calc(A)[1:-2]", "+right = calc(A[::-1])[1:-2][::-1]", "+ans = 10**10", "+for (P, Q), (R, S) in zip(left, right):", "+ ans = min(ans, abs(max(P, Q, R, S) - min(P, Q, R, S)))" ]
false
0.050141
0.046243
1.084307
[ "s632859225", "s762194953" ]
u620480037
p03545
python
s012593642
s423568445
22
17
3,444
3,060
Accepted
Accepted
22.73
S=eval(input()) list1=[] for i in range(4): list1.append(int(S[i])) #print(list1) list2=[] for j in range(8): k=j list2.append(int(k/4)) k=j%4 list2.append(int(k/2)) k=j%2 list2.append(int(k/1)) #print(list2) if list2[0]==1: A=list1[0]+list1[1] else: A=list1[0]-list1[1] if list2[1]==1: A=A+list1[2] else: A=A-list1[2] if list2[2]==1: A=A+list1[3] else: A=A-list1[3] if A==7: list3=[] for a in range(3): if list2[a]==0: list3.append("-") else: list3.append("+") print((str(list1[0])+list3[0]+str(list1[1])+list3[1]+str(list1[2])+list3[2]+str(list1[3])+"=7")) ans=1 break list2=[]
A,B,C,D=list(eval(input())) F=["+","-"] for x in range(2): for y in range(2): for z in range(2): if eval(A+F[x]+B+F[y]+C+F[z]+D)==7: print((A+F[x]+B+F[y]+C+F[z]+D+"=7")) exit()
40
10
826
236
S = eval(input()) list1 = [] for i in range(4): list1.append(int(S[i])) # print(list1) list2 = [] for j in range(8): k = j list2.append(int(k / 4)) k = j % 4 list2.append(int(k / 2)) k = j % 2 list2.append(int(k / 1)) # print(list2) if list2[0] == 1: A = list1[0] + list1[1] else: A = list1[0] - list1[1] if list2[1] == 1: A = A + list1[2] else: A = A - list1[2] if list2[2] == 1: A = A + list1[3] else: A = A - list1[3] if A == 7: list3 = [] for a in range(3): if list2[a] == 0: list3.append("-") else: list3.append("+") print( ( str(list1[0]) + list3[0] + str(list1[1]) + list3[1] + str(list1[2]) + list3[2] + str(list1[3]) + "=7" ) ) ans = 1 break list2 = []
A, B, C, D = list(eval(input())) F = ["+", "-"] for x in range(2): for y in range(2): for z in range(2): if eval(A + F[x] + B + F[y] + C + F[z] + D) == 7: print((A + F[x] + B + F[y] + C + F[z] + D + "=7")) exit()
false
75
[ "-S = eval(input())", "-list1 = []", "-for i in range(4):", "- list1.append(int(S[i]))", "-# print(list1)", "-list2 = []", "-for j in range(8):", "- k = j", "- list2.append(int(k / 4))", "- k = j % 4", "- list2.append(int(k / 2))", "- k = j % 2", "- list2.append(int(k / 1))", "- # print(list2)", "- if list2[0] == 1:", "- A = list1[0] + list1[1]", "- else:", "- A = list1[0] - list1[1]", "- if list2[1] == 1:", "- A = A + list1[2]", "- else:", "- A = A - list1[2]", "- if list2[2] == 1:", "- A = A + list1[3]", "- else:", "- A = A - list1[3]", "- if A == 7:", "- list3 = []", "- for a in range(3):", "- if list2[a] == 0:", "- list3.append(\"-\")", "- else:", "- list3.append(\"+\")", "- print(", "- (", "- str(list1[0])", "- + list3[0]", "- + str(list1[1])", "- + list3[1]", "- + str(list1[2])", "- + list3[2]", "- + str(list1[3])", "- + \"=7\"", "- )", "- )", "- ans = 1", "- break", "- list2 = []", "+A, B, C, D = list(eval(input()))", "+F = [\"+\", \"-\"]", "+for x in range(2):", "+ for y in range(2):", "+ for z in range(2):", "+ if eval(A + F[x] + B + F[y] + C + F[z] + D) == 7:", "+ print((A + F[x] + B + F[y] + C + F[z] + D + \"=7\"))", "+ exit()" ]
false
0.044231
0.042829
1.03275
[ "s012593642", "s423568445" ]
u561231954
p02868
python
s776319548
s379273560
969
867
79,648
54,504
Accepted
Accepted
10.53
INF = 10 ** 15 MOD = 10 ** 9 + 7 class SegmentTree(): f = min unit = INF def __init__(self,array): self.N = len(array) self.tree = [self.unit] * (2*self.N) self._build(array) def _build(self,array): for i,x in enumerate(array,self.N): self.tree[i] = x for i in range(self.N - 1,0,-1): self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1]) def update(self,k,x): k += self.N if self.tree[k] <= x: return self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1]) def query(self,l,r): l += self.N r += self.N vl = self.unit vr = self.unit while l < r: if l&1: vl = self.f(vl,self.tree[l]) l += 1 if r&1: r -= 1 vr = self.f(self.tree[r],vr) l >>= 1 r >>= 1 return self.f(vl,vr) def __str__(self): return '\n'.join(' '.join(str(v) for v in self.tree[1<<i:1<<(i + 1)]) for i in range((2*self.N).bit_length())) N,M = list(map(int,input().split())) paths = [[] for _ in range(N)] for _ in range(M): l,r,c = list(map(int,input().split())) l -= 1 r -= 1 paths[l].append((r,c)) dp = SegmentTree([0] + [INF] * (N - 1)) for l,path in enumerate(paths): for r,c in path: before_min = dp.query(l,N) dp.update(r,before_min + c) ans = dp.query(N - 1,N) print((ans if ans < INF else -1))
INF = 10 ** 15 MOD = 10 ** 9 + 7 from heapq import heappop,heappush,heapify def dijkstra(G,start = 0): N = len(G) dist = [INF] *N dist[start] = 0 q = [(0,start)] while q: d,v = heappop(q) if d > dist[v]: continue for e,c in G[v]: if dist[v] + c < dist[e]: dist[e] = dist[v] + c heappush(q,(dist[e],e)) return dist[-1] def main(): N,M = list(map(int,input().split())) G = [[] for _ in range(N)] for _ in range(M): l,r,c = list(map(int,input().split())) l -= 1 r -= 1 G[l].append((r,c)) G[r].append((l,c)) for i in range(N - 1): G[i + 1].append((i,0)) ans = dijkstra(G) print((ans if ans < INF else -1)) if __name__ == '__main__': main()
61
34
1,655
837
INF = 10**15 MOD = 10**9 + 7 class SegmentTree: f = min unit = INF def __init__(self, array): self.N = len(array) self.tree = [self.unit] * (2 * self.N) self._build(array) def _build(self, array): for i, x in enumerate(array, self.N): self.tree[i] = x for i in range(self.N - 1, 0, -1): self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1]) def update(self, k, x): k += self.N if self.tree[k] <= x: return self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1]) def query(self, l, r): l += self.N r += self.N vl = self.unit vr = self.unit while l < r: if l & 1: vl = self.f(vl, self.tree[l]) l += 1 if r & 1: r -= 1 vr = self.f(self.tree[r], vr) l >>= 1 r >>= 1 return self.f(vl, vr) def __str__(self): return "\n".join( " ".join(str(v) for v in self.tree[1 << i : 1 << (i + 1)]) for i in range((2 * self.N).bit_length()) ) N, M = list(map(int, input().split())) paths = [[] for _ in range(N)] for _ in range(M): l, r, c = list(map(int, input().split())) l -= 1 r -= 1 paths[l].append((r, c)) dp = SegmentTree([0] + [INF] * (N - 1)) for l, path in enumerate(paths): for r, c in path: before_min = dp.query(l, N) dp.update(r, before_min + c) ans = dp.query(N - 1, N) print((ans if ans < INF else -1))
INF = 10**15 MOD = 10**9 + 7 from heapq import heappop, heappush, heapify def dijkstra(G, start=0): N = len(G) dist = [INF] * N dist[start] = 0 q = [(0, start)] while q: d, v = heappop(q) if d > dist[v]: continue for e, c in G[v]: if dist[v] + c < dist[e]: dist[e] = dist[v] + c heappush(q, (dist[e], e)) return dist[-1] def main(): N, M = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(M): l, r, c = list(map(int, input().split())) l -= 1 r -= 1 G[l].append((r, c)) G[r].append((l, c)) for i in range(N - 1): G[i + 1].append((i, 0)) ans = dijkstra(G) print((ans if ans < INF else -1)) if __name__ == "__main__": main()
false
44.262295
[ "+from heapq import heappop, heappush, heapify", "-class SegmentTree:", "- f = min", "- unit = INF", "-", "- def __init__(self, array):", "- self.N = len(array)", "- self.tree = [self.unit] * (2 * self.N)", "- self._build(array)", "-", "- def _build(self, array):", "- for i, x in enumerate(array, self.N):", "- self.tree[i] = x", "- for i in range(self.N - 1, 0, -1):", "- self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1])", "-", "- def update(self, k, x):", "- k += self.N", "- if self.tree[k] <= x:", "- return", "- self.tree[k] = x", "- while k > 1:", "- k >>= 1", "- self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1])", "-", "- def query(self, l, r):", "- l += self.N", "- r += self.N", "- vl = self.unit", "- vr = self.unit", "- while l < r:", "- if l & 1:", "- vl = self.f(vl, self.tree[l])", "- l += 1", "- if r & 1:", "- r -= 1", "- vr = self.f(self.tree[r], vr)", "- l >>= 1", "- r >>= 1", "- return self.f(vl, vr)", "-", "- def __str__(self):", "- return \"\\n\".join(", "- \" \".join(str(v) for v in self.tree[1 << i : 1 << (i + 1)])", "- for i in range((2 * self.N).bit_length())", "- )", "+def dijkstra(G, start=0):", "+ N = len(G)", "+ dist = [INF] * N", "+ dist[start] = 0", "+ q = [(0, start)]", "+ while q:", "+ d, v = heappop(q)", "+ if d > dist[v]:", "+ continue", "+ for e, c in G[v]:", "+ if dist[v] + c < dist[e]:", "+ dist[e] = dist[v] + c", "+ heappush(q, (dist[e], e))", "+ return dist[-1]", "-N, M = list(map(int, input().split()))", "-paths = [[] for _ in range(N)]", "-for _ in range(M):", "- l, r, c = list(map(int, input().split()))", "- l -= 1", "- r -= 1", "- paths[l].append((r, c))", "-dp = SegmentTree([0] + [INF] * (N - 1))", "-for l, path in enumerate(paths):", "- for r, c in path:", "- before_min = dp.query(l, N)", "- dp.update(r, before_min + c)", "-ans = dp.query(N - 1, N)", "-print((ans if ans < INF else -1))", "+def main():", "+ N, M = list(map(int, input().split()))", "+ G = [[] for _ in range(N)]", "+ for _ in range(M):", "+ l, r, c = list(map(int, input().split()))", "+ l -= 1", "+ r -= 1", "+ G[l].append((r, c))", "+ G[r].append((l, c))", "+ for i in range(N - 1):", "+ G[i + 1].append((i, 0))", "+ ans = dijkstra(G)", "+ print((ans if ans < INF else -1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.067389
0.08086
0.833394
[ "s776319548", "s379273560" ]
u531599639
p02691
python
s668322638
s129801878
514
241
88,996
61,460
Accepted
Accepted
53.11
n = int(eval(input())) a = list(map(int,input().split())) ans = 0 d = {} for i in range(n): if d.get(i+a[i],0)==0: d[i+a[i]] = [0,0] if d.get(i-a[i],0)==0: d[i-a[i]] = [0,0] d[i+a[i]][0] += 1 d[i-a[i]][1] += 1 for v in list(d.values()): ans += v[0]*v[1] print(ans)
import collections n = int(eval(input())) a = list(map(int,input().split())) ans = 0 cnt = collections.defaultdict(int) for i in range(n): ans += cnt[i-a[i]] cnt[i+a[i]]+=1 print(ans)
14
9
283
189
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 d = {} for i in range(n): if d.get(i + a[i], 0) == 0: d[i + a[i]] = [0, 0] if d.get(i - a[i], 0) == 0: d[i - a[i]] = [0, 0] d[i + a[i]][0] += 1 d[i - a[i]][1] += 1 for v in list(d.values()): ans += v[0] * v[1] print(ans)
import collections n = int(eval(input())) a = list(map(int, input().split())) ans = 0 cnt = collections.defaultdict(int) for i in range(n): ans += cnt[i - a[i]] cnt[i + a[i]] += 1 print(ans)
false
35.714286
[ "+import collections", "+", "-d = {}", "+cnt = collections.defaultdict(int)", "- if d.get(i + a[i], 0) == 0:", "- d[i + a[i]] = [0, 0]", "- if d.get(i - a[i], 0) == 0:", "- d[i - a[i]] = [0, 0]", "- d[i + a[i]][0] += 1", "- d[i - a[i]][1] += 1", "-for v in list(d.values()):", "- ans += v[0] * v[1]", "+ ans += cnt[i - a[i]]", "+ cnt[i + a[i]] += 1" ]
false
0.036323
0.037257
0.97493
[ "s668322638", "s129801878" ]
u411353821
p02861
python
s817344604
s329089251
401
103
9,332
80,580
Accepted
Accepted
74.31
from itertools import permutations def calc(x, y): return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5 def main(): n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] A = list(permutations(A)) ls = [] for c in A: l = calc(c[0], c[1]) if len(c) > 2: prev_idx = 1 for a in c[2:]: l += calc(c[prev_idx], a) prev_idx += 1 ls.append(l) print((sum(ls) / len(ls))) if __name__ == "__main__": main()
from itertools import permutations def main(): N = int(eval(input())) cities = [i for i in range(N)] xys = [] for _ in range(N): xys.append(list(map(int, input().split()))) combs = list(permutations(cities)) sum_dist = 0 for comb in combs: for i in range(len(comb)-1): idx1 = comb[i] idx2 = comb[i+1] sum_dist += ( (xys[idx1][0] - xys[idx2][0]) ** 2 + (xys[idx1][1] - xys[idx2][1]) ** 2) ** 0.5 print((sum_dist / len(combs))) if __name__ == '__main__': main()
23
24
546
600
from itertools import permutations def calc(x, y): return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5 def main(): n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] A = list(permutations(A)) ls = [] for c in A: l = calc(c[0], c[1]) if len(c) > 2: prev_idx = 1 for a in c[2:]: l += calc(c[prev_idx], a) prev_idx += 1 ls.append(l) print((sum(ls) / len(ls))) if __name__ == "__main__": main()
from itertools import permutations def main(): N = int(eval(input())) cities = [i for i in range(N)] xys = [] for _ in range(N): xys.append(list(map(int, input().split()))) combs = list(permutations(cities)) sum_dist = 0 for comb in combs: for i in range(len(comb) - 1): idx1 = comb[i] idx2 = comb[i + 1] sum_dist += ( (xys[idx1][0] - xys[idx2][0]) ** 2 + (xys[idx1][1] - xys[idx2][1]) ** 2 ) ** 0.5 print((sum_dist / len(combs))) if __name__ == "__main__": main()
false
4.166667
[ "-def calc(x, y):", "- return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5", "-", "-", "- n = int(eval(input()))", "- A = [list(map(int, input().split())) for i in range(n)]", "- A = list(permutations(A))", "- ls = []", "- for c in A:", "- l = calc(c[0], c[1])", "- if len(c) > 2:", "- prev_idx = 1", "- for a in c[2:]:", "- l += calc(c[prev_idx], a)", "- prev_idx += 1", "- ls.append(l)", "- print((sum(ls) / len(ls)))", "+ N = int(eval(input()))", "+ cities = [i for i in range(N)]", "+ xys = []", "+ for _ in range(N):", "+ xys.append(list(map(int, input().split())))", "+ combs = list(permutations(cities))", "+ sum_dist = 0", "+ for comb in combs:", "+ for i in range(len(comb) - 1):", "+ idx1 = comb[i]", "+ idx2 = comb[i + 1]", "+ sum_dist += (", "+ (xys[idx1][0] - xys[idx2][0]) ** 2 + (xys[idx1][1] - xys[idx2][1]) ** 2", "+ ) ** 0.5", "+ print((sum_dist / len(combs)))" ]
false
0.041296
0.03679
1.122471
[ "s817344604", "s329089251" ]