user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u595893956
p03062
python
s005594228
s638660651
71
65
14,412
14,224
Accepted
Accepted
8.45
n=int(eval(input())) a=list(map(int,input().split())) b=[abs(x) for x in a] ret=0 for i in range(n): if a[i]!=b[i]: ret+=1 ans=sum(b) if ret%2: ans-=2*min(b) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) neg_sum=sum(x<0 for x in a) a=list([abs(x) for x in a]) m=min(a) s=sum(a) if neg_sum%2 : s-=m*2 print(s)
11
8
180
163
n = int(eval(input())) a = list(map(int, input().split())) b = [abs(x) for x in a] ret = 0 for i in range(n): if a[i] != b[i]: ret += 1 ans = sum(b) if ret % 2: ans -= 2 * min(b) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) neg_sum = sum(x < 0 for x in a) a = list([abs(x) for x in a]) m = min(a) s = sum(a) if neg_sum % 2: s -= m * 2 print(s)
false
27.272727
[ "-b = [abs(x) for x in a]", "-ret = 0", "-for i in range(n):", "- if a[i] != b[i]:", "- ret += 1", "-ans = sum(b)", "-if ret % 2:", "- ans -= 2 * min(b)", "-print(ans)", "+neg_sum = sum(x < 0 for x in a)", "+a = list([abs(x) for x in a])", "+m = min(a)", "+s = sum(a)", "+if neg_sum % 2:", "+ s -= m * 2", "+print(s)" ]
false
0.083832
0.048991
1.711153
[ "s005594228", "s638660651" ]
u936985471
p03645
python
s192227346
s053346135
602
345
19,024
41,712
Accepted
Accepted
42.69
N,M=list(map(int,input().split())) f=set() t=set() for i in range(M): a,b=list(map(int,input().split())) if a<2: f.add(b) if b==N: t.add(a) print(("IM"*(len(f&t)^1)+"POSSIBLE"))
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) G = [[] for i in range(N)] for i in range(M): a,b = list(map(int,readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) for child in G[0]: for gchild in G[child]: if gchild == N - 1: print("POSSIBLE") exit(0) print("IMPOSSIBLE")
10
17
186
356
N, M = list(map(int, input().split())) f = set() t = set() for i in range(M): a, b = list(map(int, input().split())) if a < 2: f.add(b) if b == N: t.add(a) print(("IM" * (len(f & t) ^ 1) + "POSSIBLE"))
import sys readline = sys.stdin.readline N, M = list(map(int, readline().split())) G = [[] for i in range(N)] for i in range(M): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) for child in G[0]: for gchild in G[child]: if gchild == N - 1: print("POSSIBLE") exit(0) print("IMPOSSIBLE")
false
41.176471
[ "-N, M = list(map(int, input().split()))", "-f = set()", "-t = set()", "+import sys", "+", "+readline = sys.stdin.readline", "+N, M = list(map(int, readline().split()))", "+G = [[] for i in range(N)]", "- a, b = list(map(int, input().split()))", "- if a < 2:", "- f.add(b)", "- if b == N:", "- t.add(a)", "-print((\"IM\" * (len(f & t) ^ 1) + \"POSSIBLE\"))", "+ a, b = list(map(int, readline().split()))", "+ G[a - 1].append(b - 1)", "+ G[b - 1].append(a - 1)", "+for child in G[0]:", "+ for gchild in G[child]:", "+ if gchild == N - 1:", "+ print(\"POSSIBLE\")", "+ exit(0)", "+print(\"IMPOSSIBLE\")" ]
false
0.112184
0.041397
2.709959
[ "s192227346", "s053346135" ]
u545368057
p02998
python
s699146910
s042980693
736
554
96,876
30,432
Accepted
Accepted
24.73
import sys # DFSの再帰限界を増やす sys.setrecursionlimit(10**6) N = int(eval(input())) nmax = 100001 # nmax = 10 # 第一成分にx,第二成分にyをぶち込んでいく。(二部グラフなので) xys = [[[] for i in range(nmax)] for j in range(2)] used = [[0 for i in range(nmax)] for j in range(2)] # 読み込み for _ in range(N): x, y = list(map(int, input().split())) xys[0][x].append(y) xys[1][y].append(x) # print(xys) # 座標の切り替えをx = 1 or 0と1-xで行うのか、うまい! # よく考えたらtrue/falseをひっくり返しているだけか。 def dfs(i, el=0): # el=0->x, el=1->y for i in xys[el][i]: if not used[1-el][i]: used[1-el][i] = True dfs(i, 1-el) cnt[1-el] += 1 ans = 0 for i in range(nmax): # まだ行ったことがなくて空じゃないところ if xys[0][i] != [] and used[0][i] == 0: used[0][i] = 1 cnt = [1,0] dfs(i,0) ans += cnt[0]*cnt[1] print((ans-N))
from collections import deque N = int(eval(input())) nmax = 2*10**5 nhalf = 10**5 G = [[] for i in range(nmax)] for i in range(N): x,y = list(map(int,input().split())) G[x-1].append(nhalf+y-1) G[nhalf+y-1].append(x-1) used = [False] * nmax ans = 0 # 全探索 for i in range(nhalf): # 見つかったノードからBFS if G[i] != [] and not used[i]: cnt_1 = 0 #前半の連結 cnt_2 = 0 #後半の連結 q = deque([i]) used[i] = True # 始めどこから行くか while len(q) > 0: a = q.popleft() if a < nhalf: cnt_2 += 1 else: cnt_1 += 1 Vs = G[a] # print(Vs) for u in Vs: # 頂点以外の要素がグラフにあるときはここ if not used[u]: q.append(u) # なにか処理を書きたいときはここに書く used[u] = True ans += cnt_1*cnt_2 print((ans-N))
37
37
852
905
import sys # DFSの再帰限界を増やす sys.setrecursionlimit(10**6) N = int(eval(input())) nmax = 100001 # nmax = 10 # 第一成分にx,第二成分にyをぶち込んでいく。(二部グラフなので) xys = [[[] for i in range(nmax)] for j in range(2)] used = [[0 for i in range(nmax)] for j in range(2)] # 読み込み for _ in range(N): x, y = list(map(int, input().split())) xys[0][x].append(y) xys[1][y].append(x) # print(xys) # 座標の切り替えをx = 1 or 0と1-xで行うのか、うまい! # よく考えたらtrue/falseをひっくり返しているだけか。 def dfs(i, el=0): # el=0->x, el=1->y for i in xys[el][i]: if not used[1 - el][i]: used[1 - el][i] = True dfs(i, 1 - el) cnt[1 - el] += 1 ans = 0 for i in range(nmax): # まだ行ったことがなくて空じゃないところ if xys[0][i] != [] and used[0][i] == 0: used[0][i] = 1 cnt = [1, 0] dfs(i, 0) ans += cnt[0] * cnt[1] print((ans - N))
from collections import deque N = int(eval(input())) nmax = 2 * 10**5 nhalf = 10**5 G = [[] for i in range(nmax)] for i in range(N): x, y = list(map(int, input().split())) G[x - 1].append(nhalf + y - 1) G[nhalf + y - 1].append(x - 1) used = [False] * nmax ans = 0 # 全探索 for i in range(nhalf): # 見つかったノードからBFS if G[i] != [] and not used[i]: cnt_1 = 0 # 前半の連結 cnt_2 = 0 # 後半の連結 q = deque([i]) used[i] = True # 始めどこから行くか while len(q) > 0: a = q.popleft() if a < nhalf: cnt_2 += 1 else: cnt_1 += 1 Vs = G[a] # print(Vs) for u in Vs: # 頂点以外の要素がグラフにあるときはここ if not used[u]: q.append(u) # なにか処理を書きたいときはここに書く used[u] = True ans += cnt_1 * cnt_2 print((ans - N))
false
0
[ "-import sys", "+from collections import deque", "-# DFSの再帰限界を増やす", "-sys.setrecursionlimit(10**6)", "-nmax = 100001", "-# nmax = 10", "-# 第一成分にx,第二成分にyをぶち込んでいく。(二部グラフなので)", "-xys = [[[] for i in range(nmax)] for j in range(2)]", "-used = [[0 for i in range(nmax)] for j in range(2)]", "-# 読み込み", "-for _ in range(N):", "+nmax = 2 * 10**5", "+nhalf = 10**5", "+G = [[] for i in range(nmax)]", "+for i in range(N):", "- xys[0][x].append(y)", "- xys[1][y].append(x)", "-# print(xys)", "-# 座標の切り替えをx = 1 or 0と1-xで行うのか、うまい!", "-# よく考えたらtrue/falseをひっくり返しているだけか。", "-def dfs(i, el=0):", "- # el=0->x, el=1->y", "- for i in xys[el][i]:", "- if not used[1 - el][i]:", "- used[1 - el][i] = True", "- dfs(i, 1 - el)", "- cnt[1 - el] += 1", "-", "-", "+ G[x - 1].append(nhalf + y - 1)", "+ G[nhalf + y - 1].append(x - 1)", "+used = [False] * nmax", "-for i in range(nmax):", "- # まだ行ったことがなくて空じゃないところ", "- if xys[0][i] != [] and used[0][i] == 0:", "- used[0][i] = 1", "- cnt = [1, 0]", "- dfs(i, 0)", "- ans += cnt[0] * cnt[1]", "+# 全探索", "+for i in range(nhalf):", "+ # 見つかったノードからBFS", "+ if G[i] != [] and not used[i]:", "+ cnt_1 = 0 # 前半の連結", "+ cnt_2 = 0 # 後半の連結", "+ q = deque([i])", "+ used[i] = True # 始めどこから行くか", "+ while len(q) > 0:", "+ a = q.popleft()", "+ if a < nhalf:", "+ cnt_2 += 1", "+ else:", "+ cnt_1 += 1", "+ Vs = G[a]", "+ # print(Vs)", "+ for u in Vs: # 頂点以外の要素がグラフにあるときはここ", "+ if not used[u]:", "+ q.append(u)", "+ # なにか処理を書きたいときはここに書く", "+ used[u] = True", "+ ans += cnt_1 * cnt_2" ]
false
0.304595
0.25957
1.173458
[ "s699146910", "s042980693" ]
u628597699
p02743
python
s443412220
s447239440
153
34
5,076
5,076
Accepted
Accepted
77.78
from decimal import Decimal, getcontext a,b,c = input().split() getcontext().prec = 10000 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a+b+Decimal(1e-14)< c: print("Yes") else: print("No")
from decimal import Decimal, getcontext a,b,c = input().split() getcontext().prec = 65 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a+b < c: print("Yes") else: print("No")
10
10
225
209
from decimal import Decimal, getcontext a, b, c = input().split() getcontext().prec = 10000 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a + b + Decimal(1e-14) < c: print("Yes") else: print("No")
from decimal import Decimal, getcontext a, b, c = input().split() getcontext().prec = 65 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a + b < c: print("Yes") else: print("No")
false
0
[ "-getcontext().prec = 10000", "+getcontext().prec = 65", "-if a + b + Decimal(1e-14) < c:", "+if a + b < c:" ]
false
0.286294
0.039269
7.290608
[ "s443412220", "s447239440" ]
u411923565
p03549
python
s907462167
s446231556
294
31
9,500
9,424
Accepted
Accepted
89.46
#78 C - HSI N,M = list(map(int,input().split())) # 全て AC となる確率 p = (1/2)**M # 全て AC となるときの期待値 # k 回目までに「成功しない」確率の期待値 # E = (1-p)**0 + (1-p)**1 + (1-p)**2+... E = 0 for k in range(10**6): E += (1-p)**k ans = (1900*M + 100*(N-M))*E ans = round(ans) print(ans)
#78 C - HSI N,M = list(map(int,input().split())) # 全て AC となる確率 p = (1/2)**M # E = 1/p になる E = 1/p ans = (1900*M + 100*(N-M))*E ans = round(ans) print(ans)
15
10
271
158
# 78 C - HSI N, M = list(map(int, input().split())) # 全て AC となる確率 p = (1 / 2) ** M # 全て AC となるときの期待値 # k 回目までに「成功しない」確率の期待値 # E = (1-p)**0 + (1-p)**1 + (1-p)**2+... E = 0 for k in range(10**6): E += (1 - p) ** k ans = (1900 * M + 100 * (N - M)) * E ans = round(ans) print(ans)
# 78 C - HSI N, M = list(map(int, input().split())) # 全て AC となる確率 p = (1 / 2) ** M # E = 1/p になる E = 1 / p ans = (1900 * M + 100 * (N - M)) * E ans = round(ans) print(ans)
false
33.333333
[ "-# 全て AC となるときの期待値", "-# k 回目までに「成功しない」確率の期待値", "-# E = (1-p)**0 + (1-p)**1 + (1-p)**2+...", "-E = 0", "-for k in range(10**6):", "- E += (1 - p) ** k", "+# E = 1/p になる", "+E = 1 / p" ]
false
1.08799
0.047324
22.99048
[ "s907462167", "s446231556" ]
u690536347
p02732
python
s079620333
s992372756
453
292
26,772
34,112
Accepted
Accepted
35.54
from collections import Counter N = int(eval(input())) *l, = list(map(int, input().split())) c = Counter(l) v = 0 for i in list(c.values()): v += i*(i-1)//2 for i in l: print((v-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2)))
from collections import Counter N = int(eval(input())) *A, = list(map(int, input().split())) c = Counter(A) ans = 0 for i in list(c.values()): ans += i*(i-1)//2 for i in A: b = ans b -= c[i]*(c[i]-1)//2 b += (c[i]-1)*(c[i]-2)//2 print(b)
12
15
223
256
from collections import Counter N = int(eval(input())) (*l,) = list(map(int, input().split())) c = Counter(l) v = 0 for i in list(c.values()): v += i * (i - 1) // 2 for i in l: print((v - (c[i] * (c[i] - 1) // 2) + ((c[i] - 1) * (c[i] - 2) // 2)))
from collections import Counter N = int(eval(input())) (*A,) = list(map(int, input().split())) c = Counter(A) ans = 0 for i in list(c.values()): ans += i * (i - 1) // 2 for i in A: b = ans b -= c[i] * (c[i] - 1) // 2 b += (c[i] - 1) * (c[i] - 2) // 2 print(b)
false
20
[ "-(*l,) = list(map(int, input().split()))", "-c = Counter(l)", "-v = 0", "+(*A,) = list(map(int, input().split()))", "+c = Counter(A)", "+ans = 0", "- v += i * (i - 1) // 2", "-for i in l:", "- print((v - (c[i] * (c[i] - 1) // 2) + ((c[i] - 1) * (c[i] - 2) // 2)))", "+ ans += i * (i - 1) // 2", "+for i in A:", "+ b = ans", "+ b -= c[i] * (c[i] - 1) // 2", "+ b += (c[i] - 1) * (c[i] - 2) // 2", "+ print(b)" ]
false
0.042172
0.041215
1.023227
[ "s079620333", "s992372756" ]
u222668979
p02550
python
s219057117
s720652836
320
75
80,296
77,388
Accepted
Accepted
76.56
n, x, m = list(map(int, input().split())) lst, num = set(), [] for i in range(1, n + 1): lst.add(x), num.append(x) x = x ** 2 % m if x in lst: break ans = sum(num) if x in lst: cnt, idx = i, num.index(x) div, mod = divmod(n - cnt, len(num) - idx) ans += sum(num[idx:idx + mod]) ans += sum(num[idx:]) * div print(ans)
n, x, m = list(map(int, input().split())) lst, num = set(), [] for i in range(n): lst.add(x), num.append(x) x = x ** 2 % m if x in lst: cnt, idx = i + 1, num.index(x) break ans = sum(num) if x in lst: div, mod = divmod(n - cnt, len(num) - idx) ans += sum(num[idx:]) * div ans += sum(num[idx:idx + mod]) print(ans)
16
16
364
365
n, x, m = list(map(int, input().split())) lst, num = set(), [] for i in range(1, n + 1): lst.add(x), num.append(x) x = x**2 % m if x in lst: break ans = sum(num) if x in lst: cnt, idx = i, num.index(x) div, mod = divmod(n - cnt, len(num) - idx) ans += sum(num[idx : idx + mod]) ans += sum(num[idx:]) * div print(ans)
n, x, m = list(map(int, input().split())) lst, num = set(), [] for i in range(n): lst.add(x), num.append(x) x = x**2 % m if x in lst: cnt, idx = i + 1, num.index(x) break ans = sum(num) if x in lst: div, mod = divmod(n - cnt, len(num) - idx) ans += sum(num[idx:]) * div ans += sum(num[idx : idx + mod]) print(ans)
false
0
[ "-for i in range(1, n + 1):", "+for i in range(n):", "+ cnt, idx = i + 1, num.index(x)", "- cnt, idx = i, num.index(x)", "+ ans += sum(num[idx:]) * div", "- ans += sum(num[idx:]) * div" ]
false
0.034411
0.034459
0.998609
[ "s219057117", "s720652836" ]
u072717685
p03611
python
s910476661
s362156929
144
72
32,172
13,964
Accepted
Accepted
50
from collections import Counter def main(): n = int(eval(input())) a = list(map(int, input().split())) a1 = [i + 1 for i in a] a2 = [i - 1 for i in a] a = a + a1 + a2 ac = Counter(a) print((ac.most_common()[0][1])) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) l1 = [0] * (max(a) + 3) for ea in a: l1[ea] += 1 l1[ea+1] += 1 l1[ea+2] += 1 print((max(l1))) if __name__ == '__main__': main()
12
12
289
250
from collections import Counter def main(): n = int(eval(input())) a = list(map(int, input().split())) a1 = [i + 1 for i in a] a2 = [i - 1 for i in a] a = a + a1 + a2 ac = Counter(a) print((ac.most_common()[0][1])) if __name__ == "__main__": main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) l1 = [0] * (max(a) + 3) for ea in a: l1[ea] += 1 l1[ea + 1] += 1 l1[ea + 2] += 1 print((max(l1))) if __name__ == "__main__": main()
false
0
[ "-from collections import Counter", "-", "-", "- a1 = [i + 1 for i in a]", "- a2 = [i - 1 for i in a]", "- a = a + a1 + a2", "- ac = Counter(a)", "- print((ac.most_common()[0][1]))", "+ l1 = [0] * (max(a) + 3)", "+ for ea in a:", "+ l1[ea] += 1", "+ l1[ea + 1] += 1", "+ l1[ea + 2] += 1", "+ print((max(l1)))" ]
false
0.047635
0.111963
0.425454
[ "s910476661", "s362156929" ]
u562935282
p03222
python
s805618981
s934512529
40
31
3,064
3,572
Accepted
Accepted
22.5
mod = 10 ** 9 + 7 h, w, k = list(map(int, input().split())) k -= 1 dp = [0] * w dp[0] = 1 ndp = [0] * w for _ in range(h): for bits in range(1 << w - 1): if '11' in bin(bits): continue to = list(range(w)) for i in range(w - 1): if (bits >> i) & 1: to[i], to[i + 1] = to[i + 1], to[i] for i in range(w): ndp[to[i]] += dp[i] ndp[to[i]] %= mod dp = ndp ndp = [0] * w print((dp[k]))
from functools import lru_cache mod = 10 ** 9 + 7 h, w, k = list(map(int, input().split())) k -= 1 @lru_cache(maxsize=w + 10) def fib(n): if n <= 1: return 1 else: return fib(n - 1) + fib(n - 2) # 縦線n本のあみだくじのパターン数 # 右端の縦線を引くかどうかで漸化式を作る dp = [0] * w dp[0] = 1 ndp = [0] * w for _ in range(h): for i in range(w): ndp[i] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1)) # 真下 ndp[i] %= mod if i - 1 >= 0: ndp[i - 1] += dp[i] * fib((i + 1) - 2) * fib(w - (i + 1)) # 左 ndp[i - 1] %= mod if i + 1 < w: ndp[i + 1] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1) - 1) # 右 ndp[i + 1] %= mod dp = ndp ndp = [0] * w print((dp[k]))
21
35
489
775
mod = 10**9 + 7 h, w, k = list(map(int, input().split())) k -= 1 dp = [0] * w dp[0] = 1 ndp = [0] * w for _ in range(h): for bits in range(1 << w - 1): if "11" in bin(bits): continue to = list(range(w)) for i in range(w - 1): if (bits >> i) & 1: to[i], to[i + 1] = to[i + 1], to[i] for i in range(w): ndp[to[i]] += dp[i] ndp[to[i]] %= mod dp = ndp ndp = [0] * w print((dp[k]))
from functools import lru_cache mod = 10**9 + 7 h, w, k = list(map(int, input().split())) k -= 1 @lru_cache(maxsize=w + 10) def fib(n): if n <= 1: return 1 else: return fib(n - 1) + fib(n - 2) # 縦線n本のあみだくじのパターン数 # 右端の縦線を引くかどうかで漸化式を作る dp = [0] * w dp[0] = 1 ndp = [0] * w for _ in range(h): for i in range(w): ndp[i] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1)) # 真下 ndp[i] %= mod if i - 1 >= 0: ndp[i - 1] += dp[i] * fib((i + 1) - 2) * fib(w - (i + 1)) # 左 ndp[i - 1] %= mod if i + 1 < w: ndp[i + 1] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1) - 1) # 右 ndp[i + 1] %= mod dp = ndp ndp = [0] * w print((dp[k]))
false
40
[ "+from functools import lru_cache", "+", "+", "+", "+@lru_cache(maxsize=w + 10)", "+def fib(n):", "+ if n <= 1:", "+ return 1", "+ else:", "+ return fib(n - 1) + fib(n - 2)", "+ # 縦線n本のあみだくじのパターン数", "+ # 右端の縦線を引くかどうかで漸化式を作る", "+", "+", "- for bits in range(1 << w - 1):", "- if \"11\" in bin(bits):", "- continue", "- to = list(range(w))", "- for i in range(w - 1):", "- if (bits >> i) & 1:", "- to[i], to[i + 1] = to[i + 1], to[i]", "- for i in range(w):", "- ndp[to[i]] += dp[i]", "- ndp[to[i]] %= mod", "+ for i in range(w):", "+ ndp[i] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1)) # 真下", "+ ndp[i] %= mod", "+ if i - 1 >= 0:", "+ ndp[i - 1] += dp[i] * fib((i + 1) - 2) * fib(w - (i + 1)) # 左", "+ ndp[i - 1] %= mod", "+ if i + 1 < w:", "+ ndp[i + 1] += dp[i] * fib((i + 1) - 1) * fib(w - (i + 1) - 1) # 右", "+ ndp[i + 1] %= mod" ]
false
0.086047
0.05776
1.489737
[ "s805618981", "s934512529" ]
u284854859
p03317
python
s266610642
s447773439
48
42
14,008
14,388
Accepted
Accepted
12.5
# your code goes here N,K = list(map(int,input().split())) li = list(map(int,input().split())) if N == K: print((1)) quit() i = 1 N = N-K while N >= K: N = N - K +1 i = i + 1 print((i+1))
import sys input = sys.stdin.readline n,k = list(map(int,input().split())) a = list(map(int,input().split())) res = 1 cnt = k if n <= cnt: print(res) else: if (n-k)%(k-1) == 0: print((1 + (n-k)//(k-1))) else: print((1 + (n-k)//(k-1)+1))
15
16
199
272
# your code goes here N, K = list(map(int, input().split())) li = list(map(int, input().split())) if N == K: print((1)) quit() i = 1 N = N - K while N >= K: N = N - K + 1 i = i + 1 print((i + 1))
import sys input = sys.stdin.readline n, k = list(map(int, input().split())) a = list(map(int, input().split())) res = 1 cnt = k if n <= cnt: print(res) else: if (n - k) % (k - 1) == 0: print((1 + (n - k) // (k - 1))) else: print((1 + (n - k) // (k - 1) + 1))
false
6.25
[ "-# your code goes here", "-N, K = list(map(int, input().split()))", "-li = list(map(int, input().split()))", "-if N == K:", "- print((1))", "- quit()", "-i = 1", "-N = N - K", "-while N >= K:", "- N = N - K + 1", "- i = i + 1", "-print((i + 1))", "+import sys", "+", "+input = sys.stdin.readline", "+n, k = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+res = 1", "+cnt = k", "+if n <= cnt:", "+ print(res)", "+else:", "+ if (n - k) % (k - 1) == 0:", "+ print((1 + (n - k) // (k - 1)))", "+ else:", "+ print((1 + (n - k) // (k - 1) + 1))" ]
false
0.038921
0.038433
1.012694
[ "s266610642", "s447773439" ]
u312025627
p03611
python
s621456649
s874111121
243
122
65,516
20,572
Accepted
Accepted
49.79
def main(): _ = int(eval(input())) A = [int(i) for i in input().split()] A.sort() from collections import Counter, defaultdict c = defaultdict(int) for k, v in list(Counter(A).items()): c[k] = v ans = 0 for i in range(10**5+1): if i != 0: cur = c[i] + c[i-1] + c[i+1] else: cur = c[i] + c[i+1] ans = max(ans, cur) print(ans) if __name__ == '__main__': main()
def main(): _ = int(eval(input())) A = [int(i) for i in input().split()] from collections import Counter, defaultdict c = defaultdict(int) for k, v in list(Counter(A).items()): c[k] = v ans = 0 for i in range(max(A) + 1): if i != 0: cur = c[i] + c[i-1] + c[i+1] else: cur = c[i] + c[i+1] ans = max(ans, cur) print(ans) if __name__ == '__main__': main()
20
19
464
453
def main(): _ = int(eval(input())) A = [int(i) for i in input().split()] A.sort() from collections import Counter, defaultdict c = defaultdict(int) for k, v in list(Counter(A).items()): c[k] = v ans = 0 for i in range(10**5 + 1): if i != 0: cur = c[i] + c[i - 1] + c[i + 1] else: cur = c[i] + c[i + 1] ans = max(ans, cur) print(ans) if __name__ == "__main__": main()
def main(): _ = int(eval(input())) A = [int(i) for i in input().split()] from collections import Counter, defaultdict c = defaultdict(int) for k, v in list(Counter(A).items()): c[k] = v ans = 0 for i in range(max(A) + 1): if i != 0: cur = c[i] + c[i - 1] + c[i + 1] else: cur = c[i] + c[i + 1] ans = max(ans, cur) print(ans) if __name__ == "__main__": main()
false
5
[ "- A.sort()", "- for i in range(10**5 + 1):", "+ for i in range(max(A) + 1):" ]
false
0.111796
0.039095
2.859608
[ "s621456649", "s874111121" ]
u579699847
p02936
python
s265825312
s290822629
1,920
1,614
299,224
241,824
Accepted
Accepted
15.94
import collections,sys def LI(): return list(map(int,sys.stdin.readline().split())) N,Q = LI() ab = [LI() for _ in range(N-1)] px = [LI() for _ in range(Q)] ans = {i:0 for i in range(1,N+1)} #1_index graph = {i:collections.deque() for i in range(1,N+1)} #1_index for a,b in ab: graph[a].append(b) graph[b].append(a) for p,x in px: ans[p] += x seen = {i:-1 for i in range(1,N+1)} #1_index stack = [] def dfs(): seen[1] = 1 stack.append(1) while stack: s = stack.pop() if not graph[s]: continue for j in range(len(graph[s])): g_NO = graph[s].popleft() if seen[g_NO]!=-1: continue seen[g_NO] = 1 stack.append(g_NO) ans[g_NO] += ans[s] dfs() print((*[a for a in list(ans.values())]))
import collections,sys def LI(): return list(map(int,sys.stdin.readline().split())) N,Q = LI() ab = [LI() for _ in range(N-1)] px = [LI() for _ in range(Q)] ans = [0]*(N+1) #1_index graph = [collections.deque() for _ in range(N+1)] #1_index for a,b in ab: graph[a].append(b) graph[b].append(a) for p,x in px: ans[p] += x seen = [0]*(N+1) #1_index stack = [] def dfs(): seen[1] = 1 stack.append(1) while stack: s = stack.pop() if not graph[s]: continue for j in range(len(graph[s])): g_NO = graph[s].popleft() if seen[g_NO]: continue seen[g_NO] = 1 stack.append(g_NO) ans[g_NO] += ans[s] dfs() print((*ans[1:]))
30
30
845
782
import collections, sys def LI(): return list(map(int, sys.stdin.readline().split())) N, Q = LI() ab = [LI() for _ in range(N - 1)] px = [LI() for _ in range(Q)] ans = {i: 0 for i in range(1, N + 1)} # 1_index graph = {i: collections.deque() for i in range(1, N + 1)} # 1_index for a, b in ab: graph[a].append(b) graph[b].append(a) for p, x in px: ans[p] += x seen = {i: -1 for i in range(1, N + 1)} # 1_index stack = [] def dfs(): seen[1] = 1 stack.append(1) while stack: s = stack.pop() if not graph[s]: continue for j in range(len(graph[s])): g_NO = graph[s].popleft() if seen[g_NO] != -1: continue seen[g_NO] = 1 stack.append(g_NO) ans[g_NO] += ans[s] dfs() print((*[a for a in list(ans.values())]))
import collections, sys def LI(): return list(map(int, sys.stdin.readline().split())) N, Q = LI() ab = [LI() for _ in range(N - 1)] px = [LI() for _ in range(Q)] ans = [0] * (N + 1) # 1_index graph = [collections.deque() for _ in range(N + 1)] # 1_index for a, b in ab: graph[a].append(b) graph[b].append(a) for p, x in px: ans[p] += x seen = [0] * (N + 1) # 1_index stack = [] def dfs(): seen[1] = 1 stack.append(1) while stack: s = stack.pop() if not graph[s]: continue for j in range(len(graph[s])): g_NO = graph[s].popleft() if seen[g_NO]: continue seen[g_NO] = 1 stack.append(g_NO) ans[g_NO] += ans[s] dfs() print((*ans[1:]))
false
0
[ "-ans = {i: 0 for i in range(1, N + 1)} # 1_index", "-graph = {i: collections.deque() for i in range(1, N + 1)} # 1_index", "+ans = [0] * (N + 1) # 1_index", "+graph = [collections.deque() for _ in range(N + 1)] # 1_index", "-seen = {i: -1 for i in range(1, N + 1)} # 1_index", "+seen = [0] * (N + 1) # 1_index", "- if seen[g_NO] != -1:", "+ if seen[g_NO]:", "-print((*[a for a in list(ans.values())]))", "+print((*ans[1:]))" ]
false
0.049705
0.047682
1.042434
[ "s265825312", "s290822629" ]
u073852194
p02913
python
s286859449
s989655700
1,272
797
41,436
55,772
Accepted
Accepted
37.34
N = int(eval(input())) S = eval(input()) res = 0 for i in range(N - 1): for j in range(i + res, N): if S[i:j] not in S[j:]: break res = max(res, j - i - 1) print(res)
def z_algorithm(s): res = [0 for _ in range(len(s))] res[0] = len(s) i, j = 1, 0 while i < len(s): while i + j < len(s) and s[j] == s[i + j]: j += 1 res[i] = j if j == 0: i += 1 continue k = 1 while k < j and k + res[k] < j: res[i + k] = res[k] k += 1 i += k j -= k return res N = int(eval(input())) S = eval(input()) res = 0 for i in range(N): z = z_algorithm(S[i:]) for j in range(N - i): res = max(res, min(j, z[j])) print(res)
12
30
196
603
N = int(eval(input())) S = eval(input()) res = 0 for i in range(N - 1): for j in range(i + res, N): if S[i:j] not in S[j:]: break res = max(res, j - i - 1) print(res)
def z_algorithm(s): res = [0 for _ in range(len(s))] res[0] = len(s) i, j = 1, 0 while i < len(s): while i + j < len(s) and s[j] == s[i + j]: j += 1 res[i] = j if j == 0: i += 1 continue k = 1 while k < j and k + res[k] < j: res[i + k] = res[k] k += 1 i += k j -= k return res N = int(eval(input())) S = eval(input()) res = 0 for i in range(N): z = z_algorithm(S[i:]) for j in range(N - i): res = max(res, min(j, z[j])) print(res)
false
60
[ "+def z_algorithm(s):", "+ res = [0 for _ in range(len(s))]", "+ res[0] = len(s)", "+ i, j = 1, 0", "+ while i < len(s):", "+ while i + j < len(s) and s[j] == s[i + j]:", "+ j += 1", "+ res[i] = j", "+ if j == 0:", "+ i += 1", "+ continue", "+ k = 1", "+ while k < j and k + res[k] < j:", "+ res[i + k] = res[k]", "+ k += 1", "+ i += k", "+ j -= k", "+ return res", "+", "+", "-for i in range(N - 1):", "- for j in range(i + res, N):", "- if S[i:j] not in S[j:]:", "- break", "- res = max(res, j - i - 1)", "+for i in range(N):", "+ z = z_algorithm(S[i:])", "+ for j in range(N - i):", "+ res = max(res, min(j, z[j]))" ]
false
0.057108
0.036727
1.554932
[ "s286859449", "s989655700" ]
u577170763
p02922
python
s693769912
s264294097
168
20
38,384
3,316
Accepted
Accepted
88.1
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): a, b = geta(int) if b == 1: print((0)) exit() n = 1 while a * n - n + 1 < b: n += 1 print(n) if __name__ == "__main__": main()
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): a, b = geta(int) tot = 1 ans = 0 while tot < b: ans += 1 tot += a - 1 print(ans) if __name__ == "__main__": main()
30
28
482
461
import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): a, b = geta(int) if b == 1: print((0)) exit() n = 1 while a * n - n + 1 < b: n += 1 print(n) if __name__ == "__main__": main()
import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): a, b = geta(int) tot = 1 ans = 0 while tot < b: ans += 1 tot += a - 1 print(ans) if __name__ == "__main__": main()
false
6.666667
[ "- if b == 1:", "- print((0))", "- exit()", "- n = 1", "- while a * n - n + 1 < b:", "- n += 1", "- print(n)", "+ tot = 1", "+ ans = 0", "+ while tot < b:", "+ ans += 1", "+ tot += a - 1", "+ print(ans)" ]
false
0.045519
0.17497
0.260151
[ "s693769912", "s264294097" ]
u054556734
p03575
python
s885186304
s748082494
285
253
12,516
12,500
Accepted
Accepted
11.23
import numpy as np import sys ; sys.setrecursionlimit(2000) import copy def dfs(v1): visited[v1] = 1 for v2 in range(n): if graph[v1][v2] == 0: continue if visited[v2] == 1: continue dfs(v2) # nは頂点の数 n, m = list(map(int,input().split())) ab = np.array([list(map(int,input().split())) for i in range(m)]) a,b = ab.T[0]-1,ab.T[1]-1 #隣接行列 G = np.array([[0] * n for _ in range(n)]) for aa,bb in zip(a,b): G[aa][bb],G[bb][aa] = 1,1 ans = 0 for aa,bb in zip(a,b): graph = copy.deepcopy(G) graph[aa][bb],graph[bb][aa] = 0,0 visited = [0]*(n) dfs(0) if not all(visited): ans += 1 print(ans)
import numpy as np import copy as cp def isTree(now=0): know[now] = 1 for next in range(n): if know[next]==1 or graph[now][next]==0: continue else: isTree(next) if all(know): return 1 else: return 0 # nは頂点の数 n, m = list(map(int,input().split())) ab = np.array([list(map(int,input().split())) for i in range(m)]) a,b = ab.T[0]-1,ab.T[1]-1 #隣接行列 G = [[0] * n for _ in range(n)] for aa,bb in zip(a,b): G[aa][bb],G[bb][aa] = 1,1 ans = 0 for x,y in zip(a,b): graph = cp.deepcopy(G) graph[x][y],graph[y][x] = 0,0 know = [0]*(n) if not isTree(): ans += 1 print(ans)
30
29
664
635
import numpy as np import sys sys.setrecursionlimit(2000) import copy def dfs(v1): visited[v1] = 1 for v2 in range(n): if graph[v1][v2] == 0: continue if visited[v2] == 1: continue dfs(v2) # nは頂点の数 n, m = list(map(int, input().split())) ab = np.array([list(map(int, input().split())) for i in range(m)]) a, b = ab.T[0] - 1, ab.T[1] - 1 # 隣接行列 G = np.array([[0] * n for _ in range(n)]) for aa, bb in zip(a, b): G[aa][bb], G[bb][aa] = 1, 1 ans = 0 for aa, bb in zip(a, b): graph = copy.deepcopy(G) graph[aa][bb], graph[bb][aa] = 0, 0 visited = [0] * (n) dfs(0) if not all(visited): ans += 1 print(ans)
import numpy as np import copy as cp def isTree(now=0): know[now] = 1 for next in range(n): if know[next] == 1 or graph[now][next] == 0: continue else: isTree(next) if all(know): return 1 else: return 0 # nは頂点の数 n, m = list(map(int, input().split())) ab = np.array([list(map(int, input().split())) for i in range(m)]) a, b = ab.T[0] - 1, ab.T[1] - 1 # 隣接行列 G = [[0] * n for _ in range(n)] for aa, bb in zip(a, b): G[aa][bb], G[bb][aa] = 1, 1 ans = 0 for x, y in zip(a, b): graph = cp.deepcopy(G) graph[x][y], graph[y][x] = 0, 0 know = [0] * (n) if not isTree(): ans += 1 print(ans)
false
3.333333
[ "-import sys", "-", "-sys.setrecursionlimit(2000)", "-import copy", "+import copy as cp", "-def dfs(v1):", "- visited[v1] = 1", "- for v2 in range(n):", "- if graph[v1][v2] == 0:", "+def isTree(now=0):", "+ know[now] = 1", "+ for next in range(n):", "+ if know[next] == 1 or graph[now][next] == 0:", "- if visited[v2] == 1:", "- continue", "- dfs(v2)", "+ else:", "+ isTree(next)", "+ if all(know):", "+ return 1", "+ else:", "+ return 0", "-G = np.array([[0] * n for _ in range(n)])", "+G = [[0] * n for _ in range(n)]", "-for aa, bb in zip(a, b):", "- graph = copy.deepcopy(G)", "- graph[aa][bb], graph[bb][aa] = 0, 0", "- visited = [0] * (n)", "- dfs(0)", "- if not all(visited):", "+for x, y in zip(a, b):", "+ graph = cp.deepcopy(G)", "+ graph[x][y], graph[y][x] = 0, 0", "+ know = [0] * (n)", "+ if not isTree():" ]
false
0.541475
0.504606
1.073065
[ "s885186304", "s748082494" ]
u678167152
p02613
python
s192403610
s132318758
182
140
78,736
16,208
Accepted
Accepted
23.08
from collections import Counter N = int(input()) S = [input() for _ in range(N)] C = Counter(S) ans = ['AC x {}'.format(C['AC']),'WA x {}'.format(C['WA']),'TLE x {}'.format(C['TLE']),'RE x {}'.format(C['RE'])] print(*ans, sep='\n')
N = int(eval(input())) S = [eval(input()) for _ in range(N)] lis = ['AC','WA','TLE','RE'] for l in lis: print(('{} x {}'.format(l,S.count(l))))
6
5
236
135
from collections import Counter N = int(input()) S = [input() for _ in range(N)] C = Counter(S) ans = [ "AC x {}".format(C["AC"]), "WA x {}".format(C["WA"]), "TLE x {}".format(C["TLE"]), "RE x {}".format(C["RE"]), ] print(*ans, sep="\n")
N = int(eval(input())) S = [eval(input()) for _ in range(N)] lis = ["AC", "WA", "TLE", "RE"] for l in lis: print(("{} x {}".format(l, S.count(l))))
false
16.666667
[ "-from collections import Counter", "-", "-N = int(input())", "-S = [input() for _ in range(N)]", "-C = Counter(S)", "-ans = [", "- \"AC x {}\".format(C[\"AC\"]),", "- \"WA x {}\".format(C[\"WA\"]),", "- \"TLE x {}\".format(C[\"TLE\"]),", "- \"RE x {}\".format(C[\"RE\"]),", "-]", "-print(*ans, sep=\"\\n\")", "+N = int(eval(input()))", "+S = [eval(input()) for _ in range(N)]", "+lis = [\"AC\", \"WA\", \"TLE\", \"RE\"]", "+for l in lis:", "+ print((\"{} x {}\".format(l, S.count(l))))" ]
false
0.046232
0.048484
0.953552
[ "s192403610", "s132318758" ]
u373274281
p03137
python
s304446832
s602387180
246
112
57,384
13,968
Accepted
Accepted
54.47
import sys n,m = list(map(int, input().split())) X = list(map(int, input().split())) if n >= m: print((0)) sys.exit(0) X.sort() Y = [] for i in range(len(X)-1): Y.append(X[i+1]-X[i]) Y.sort(reverse=True) print((X[-1]-X[0]-sum(Y[:n-1])))
import sys N, M = list(map(int, input().split())) X = list(map(int, input().split())) if N >= M: print((0)) sys.exit() X.sort() # O(MlogM) # O(M) D = [] for i in range(M-1): D.append(X[i+1] - X[i]) D.sort() # O(MlogM) print((sum(D[:M-N]))) # O(M)
15
18
256
265
import sys n, m = list(map(int, input().split())) X = list(map(int, input().split())) if n >= m: print((0)) sys.exit(0) X.sort() Y = [] for i in range(len(X) - 1): Y.append(X[i + 1] - X[i]) Y.sort(reverse=True) print((X[-1] - X[0] - sum(Y[: n - 1])))
import sys N, M = list(map(int, input().split())) X = list(map(int, input().split())) if N >= M: print((0)) sys.exit() X.sort() # O(MlogM) # O(M) D = [] for i in range(M - 1): D.append(X[i + 1] - X[i]) D.sort() # O(MlogM) print((sum(D[: M - N]))) # O(M)
false
16.666667
[ "-n, m = list(map(int, input().split()))", "+N, M = list(map(int, input().split()))", "-if n >= m:", "+if N >= M:", "- sys.exit(0)", "-X.sort()", "-Y = []", "-for i in range(len(X) - 1):", "- Y.append(X[i + 1] - X[i])", "-Y.sort(reverse=True)", "-print((X[-1] - X[0] - sum(Y[: n - 1])))", "+ sys.exit()", "+X.sort() # O(MlogM)", "+# O(M)", "+D = []", "+for i in range(M - 1):", "+ D.append(X[i + 1] - X[i])", "+D.sort() # O(MlogM)", "+print((sum(D[: M - N]))) # O(M)" ]
false
0.035662
0.03574
0.99781
[ "s304446832", "s602387180" ]
u077291787
p03208
python
s677621176
s055816569
217
123
14,236
14,236
Accepted
Accepted
43.32
# ABC115C - Christmas Eve n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
# ABC115C - Christmas Eve import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
7
10
245
287
# ABC115C - Christmas Eve n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
# ABC115C - Christmas Eve import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
false
30
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.035091
0.078018
0.449774
[ "s677621176", "s055816569" ]
u150984829
p02382
python
s657419657
s890210496
30
20
5,652
5,652
Accepted
Accepted
33.33
n=int(input()) x=list(int(s) for s in input().split()) y=list(int(s) for s in input().split()) d=[(s-t,t-s)[s<t]for s,t in zip(x,y)] f=lambda n:sum([s**n for s in d])**(1/n) print(f(1),f(2),f(3),max(d),sep='\n')
n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) d=[abs(s-t)for s,t in zip(x,y)] f=lambda n:sum([s**n for s in d])**(1/n) print(f(1),f(2),f(3),max(d),sep='\n')
6
6
216
197
n = int(input()) x = list(int(s) for s in input().split()) y = list(int(s) for s in input().split()) d = [(s - t, t - s)[s < t] for s, t in zip(x, y)] f = lambda n: sum([s**n for s in d]) ** (1 / n) print(f(1), f(2), f(3), max(d), sep="\n")
n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) d = [abs(s - t) for s, t in zip(x, y)] f = lambda n: sum([s**n for s in d]) ** (1 / n) print(f(1), f(2), f(3), max(d), sep="\n")
false
0
[ "-x = list(int(s) for s in input().split())", "-y = list(int(s) for s in input().split())", "-d = [(s - t, t - s)[s < t] for s, t in zip(x, y)]", "+x = list(map(int, input().split()))", "+y = list(map(int, input().split()))", "+d = [abs(s - t) for s, t in zip(x, y)]" ]
false
0.03853
0.081899
0.470463
[ "s657419657", "s890210496" ]
u141610915
p03652
python
s853122438
s725816464
967
241
46,684
43,996
Accepted
Accepted
75.08
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(N)] inva = [[0] * M for _ in range(N)] for i in range(N): for j in range(M): inva[i][a[i][j] - 1] = j dp = [N * M] * M t = [0] * N vis = set() #print(inva) for i in range(M): x = 0 y = 0 for j in range(M): z = 0 for k in range(N): z += inva[k][j] == t[k] if z > y: y = z x = j dp[i] = y vis.add(x) for k in range(N): w = M for j in range(M): if j in vis: continue w = min(w, inva[k][j]) t[k] = w print((min(dp)))
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(N)] t = [0] * (M + 1) p = [0] * N s = set() res = float("inf") for _ in range(M): t = [0] * (M + 1) for i in range(N): t[a[i][p[i]]] += 1 x = 0 y = 0 for j in range(1, M + 1): if y < t[j]: x = j y = t[j] s.add(x) for i in range(N): while a[i][p[i]] in s: p[i] += 1 if p[i] >= M: break if max(p) >= M: break res = min(res, max(t)) #print(t, p) print((min(res, N)))
31
27
635
570
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(N)] inva = [[0] * M for _ in range(N)] for i in range(N): for j in range(M): inva[i][a[i][j] - 1] = j dp = [N * M] * M t = [0] * N vis = set() # print(inva) for i in range(M): x = 0 y = 0 for j in range(M): z = 0 for k in range(N): z += inva[k][j] == t[k] if z > y: y = z x = j dp[i] = y vis.add(x) for k in range(N): w = M for j in range(M): if j in vis: continue w = min(w, inva[k][j]) t[k] = w print((min(dp)))
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(N)] t = [0] * (M + 1) p = [0] * N s = set() res = float("inf") for _ in range(M): t = [0] * (M + 1) for i in range(N): t[a[i][p[i]]] += 1 x = 0 y = 0 for j in range(1, M + 1): if y < t[j]: x = j y = t[j] s.add(x) for i in range(N): while a[i][p[i]] in s: p[i] += 1 if p[i] >= M: break if max(p) >= M: break res = min(res, max(t)) # print(t, p) print((min(res, N)))
false
12.903226
[ "-inva = [[0] * M for _ in range(N)]", "-for i in range(N):", "- for j in range(M):", "- inva[i][a[i][j] - 1] = j", "-dp = [N * M] * M", "-t = [0] * N", "-vis = set()", "-# print(inva)", "-for i in range(M):", "+t = [0] * (M + 1)", "+p = [0] * N", "+s = set()", "+res = float(\"inf\")", "+for _ in range(M):", "+ t = [0] * (M + 1)", "+ for i in range(N):", "+ t[a[i][p[i]]] += 1", "- for j in range(M):", "- z = 0", "- for k in range(N):", "- z += inva[k][j] == t[k]", "- if z > y:", "- y = z", "+ for j in range(1, M + 1):", "+ if y < t[j]:", "- dp[i] = y", "- vis.add(x)", "- for k in range(N):", "- w = M", "- for j in range(M):", "- if j in vis:", "- continue", "- w = min(w, inva[k][j])", "- t[k] = w", "-print((min(dp)))", "+ y = t[j]", "+ s.add(x)", "+ for i in range(N):", "+ while a[i][p[i]] in s:", "+ p[i] += 1", "+ if p[i] >= M:", "+ break", "+ if max(p) >= M:", "+ break", "+ res = min(res, max(t))", "+ # print(t, p)", "+print((min(res, N)))" ]
false
0.04778
0.00898
5.320774
[ "s853122438", "s725816464" ]
u393253137
p02691
python
s923860245
s635768675
233
146
56,788
32,152
Accepted
Accepted
37.34
n = int(eval(input())) A = list(map(int, input().split())) D1 = {} D2 = {} def count(D, s): if s in D: D[s] += 1 else: D[s] = 1 for i, a in enumerate(A): count(D1, a+i) count(D2, i-a) ans = 0 for d, num in list(D1.items()): if d in D2: ans += num * D2[d] print(ans)
n = int(eval(input())) A = list(map(int, input().split())) # a+i と i-aのとりうる値の個数をカウントするが # 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分 D = [0]*n for i, a in enumerate(A): if i+a < n: D[i+a] += 1 ans = 0 # i-aに対応するD[i-a]を加えるだけで答えが求まる for i, a in enumerate(A): if i-a >= 0: ans += D[i-a] print(ans)
17
14
321
315
n = int(eval(input())) A = list(map(int, input().split())) D1 = {} D2 = {} def count(D, s): if s in D: D[s] += 1 else: D[s] = 1 for i, a in enumerate(A): count(D1, a + i) count(D2, i - a) ans = 0 for d, num in list(D1.items()): if d in D2: ans += num * D2[d] print(ans)
n = int(eval(input())) A = list(map(int, input().split())) # a+i と i-aのとりうる値の個数をカウントするが # 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分 D = [0] * n for i, a in enumerate(A): if i + a < n: D[i + a] += 1 ans = 0 # i-aに対応するD[i-a]を加えるだけで答えが求まる for i, a in enumerate(A): if i - a >= 0: ans += D[i - a] print(ans)
false
17.647059
[ "-D1 = {}", "-D2 = {}", "-", "-", "-def count(D, s):", "- if s in D:", "- D[s] += 1", "- else:", "- D[s] = 1", "-", "-", "+# a+i と i-aのとりうる値の個数をカウントするが", "+# 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分", "+D = [0] * n", "- count(D1, a + i)", "- count(D2, i - a)", "+ if i + a < n:", "+ D[i + a] += 1", "-for d, num in list(D1.items()):", "- if d in D2:", "- ans += num * D2[d]", "+# i-aに対応するD[i-a]を加えるだけで答えが求まる", "+for i, a in enumerate(A):", "+ if i - a >= 0:", "+ ans += D[i - a]" ]
false
0.042059
0.036637
1.148009
[ "s923860245", "s635768675" ]
u924691798
p03776
python
s807943544
s093432564
324
22
28,700
3,316
Accepted
Accepted
93.21
from collections import defaultdict # Combination MOD = 10**17+3 MAX = 2*10**5 fac = [1,1] + [0]*MAX finv = [1,1] + [0]*MAX inv = [0,1] + [0]*MAX for i in range(2,MAX+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 N, A, B = list(map(int, input().split())) V = list(map(int, input().split())) V.sort(reverse=True) arr = V[:A] se = set() mi = 10**18 dic2 = defaultdict(int) tot = 0 for a in arr: tot += a dic2[a] += 1 se.add(a) if a < mi: mi = a dic = defaultdict(int) for v in V: dic[v] += 1 if len(se) == 1: ans = 0 for i in range(A, B+1): ans += comb(dic[mi], i) else: ans = comb(dic[mi], dic2[mi]) print((tot/A)) print(ans)
from collections import defaultdict def comb(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 res = 1 for i in range(r): res *= n n -= 1 for i in range(1,r+1): res //= i return res N, A, B = list(map(int, input().split())) V = list(map(int, input().split())) V.sort(reverse=True) mi = 10**18 dic = defaultdict(int) dic2 = defaultdict(int) tot = 0 for i,a in enumerate(V): if i < A: tot += a dic2[a] += 1 if a < mi: mi = a dic[a] += 1 if len(dic2) == 1: ans = 0 for i in range(A, B+1): ans += comb(dic[mi], i) else: ans = comb(dic[mi], dic2[mi]) print((tot/A)) print(ans)
43
35
907
715
from collections import defaultdict # Combination MOD = 10**17 + 3 MAX = 2 * 10**5 fac = [1, 1] + [0] * MAX finv = [1, 1] + [0] * MAX inv = [0, 1] + [0] * MAX for i in range(2, MAX + 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 N, A, B = list(map(int, input().split())) V = list(map(int, input().split())) V.sort(reverse=True) arr = V[:A] se = set() mi = 10**18 dic2 = defaultdict(int) tot = 0 for a in arr: tot += a dic2[a] += 1 se.add(a) if a < mi: mi = a dic = defaultdict(int) for v in V: dic[v] += 1 if len(se) == 1: ans = 0 for i in range(A, B + 1): ans += comb(dic[mi], i) else: ans = comb(dic[mi], dic2[mi]) print((tot / A)) print(ans)
from collections import defaultdict def comb(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 res = 1 for i in range(r): res *= n n -= 1 for i in range(1, r + 1): res //= i return res N, A, B = list(map(int, input().split())) V = list(map(int, input().split())) V.sort(reverse=True) mi = 10**18 dic = defaultdict(int) dic2 = defaultdict(int) tot = 0 for i, a in enumerate(V): if i < A: tot += a dic2[a] += 1 if a < mi: mi = a dic[a] += 1 if len(dic2) == 1: ans = 0 for i in range(A, B + 1): ans += comb(dic[mi], i) else: ans = comb(dic[mi], dic2[mi]) print((tot / A)) print(ans)
false
18.604651
[ "-", "-# Combination", "-MOD = 10**17 + 3", "-MAX = 2 * 10**5", "-fac = [1, 1] + [0] * MAX", "-finv = [1, 1] + [0] * MAX", "-inv = [0, 1] + [0] * MAX", "-for i in range(2, MAX + 2):", "- fac[i] = fac[i - 1] * i % MOD", "- inv[i] = -inv[MOD % i] * (MOD // i) % MOD", "- finv[i] = finv[i - 1] * inv[i] % MOD", "- return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD", "+ res = 1", "+ for i in range(r):", "+ res *= n", "+ n -= 1", "+ for i in range(1, r + 1):", "+ res //= i", "+ return res", "-arr = V[:A]", "-se = set()", "+dic = defaultdict(int)", "-for a in arr:", "- tot += a", "- dic2[a] += 1", "- se.add(a)", "- if a < mi:", "- mi = a", "-dic = defaultdict(int)", "-for v in V:", "- dic[v] += 1", "-if len(se) == 1:", "+for i, a in enumerate(V):", "+ if i < A:", "+ tot += a", "+ dic2[a] += 1", "+ if a < mi:", "+ mi = a", "+ dic[a] += 1", "+if len(dic2) == 1:" ]
false
0.816662
0.035427
23.052031
[ "s807943544", "s093432564" ]
u453055089
p03164
python
s696781524
s180801136
1,153
604
311,888
251,624
Accepted
Accepted
47.61
n, W = list(map(int, input().split())) w, v = [0]*n, [0]*n for i in range(n): w[i], v[i] = list(map(int, input().split())) # Dのように品物と重さでループまわすとO(nW)で今W<=10**9だから間に合わない # 品物と価値でループ回す # dp[i][j]の意味はi番目までの品物で、価値j以上となるように選んだ時の、重さの最小値 sum_v = sum(v) dp = [[float("inf")]*(sum_v+1) for i in range(n+1)] dp[0][0] = 0 for i in range(n): for j in range(sum_v+1): if j - v[i] >= 0: dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]) dp[i+1][j] = min(dp[i+1][j], dp[i][j]) #print(dp) ans = 0 for j in range(sum_v+1): if dp[n][j] <= W: ans = j print(ans)
n, W = list(map(int, input().split())) w, v = [0]*(n+1), [0]*(n+1) for i in range(1, n+1): w[i], v[i] = list(map(int, input().split())) #制約から、品物と価値のdpにする dp = [[float("inf")]*(sum(v)+1) for _ in range(n+1)] dp[0][0] = 0 #dp[i][j]はi番目までの品物の中から、価値jを for i in range(1, n+1): for j in range(sum(v) + 1): dp[i][j] = dp[i-1][j] if j - v[i] >= 0: dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]) ans = 0 for i in range(sum(v)+1): if dp[n][i] <= W: ans = max(ans, i) #print(dp[n]) print(ans)
23
20
603
540
n, W = list(map(int, input().split())) w, v = [0] * n, [0] * n for i in range(n): w[i], v[i] = list(map(int, input().split())) # Dのように品物と重さでループまわすとO(nW)で今W<=10**9だから間に合わない # 品物と価値でループ回す # dp[i][j]の意味はi番目までの品物で、価値j以上となるように選んだ時の、重さの最小値 sum_v = sum(v) dp = [[float("inf")] * (sum_v + 1) for i in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(sum_v + 1): if j - v[i] >= 0: dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]) # print(dp) ans = 0 for j in range(sum_v + 1): if dp[n][j] <= W: ans = j print(ans)
n, W = list(map(int, input().split())) w, v = [0] * (n + 1), [0] * (n + 1) for i in range(1, n + 1): w[i], v[i] = list(map(int, input().split())) # 制約から、品物と価値のdpにする dp = [[float("inf")] * (sum(v) + 1) for _ in range(n + 1)] dp[0][0] = 0 # dp[i][j]はi番目までの品物の中から、価値jを for i in range(1, n + 1): for j in range(sum(v) + 1): dp[i][j] = dp[i - 1][j] if j - v[i] >= 0: dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]) ans = 0 for i in range(sum(v) + 1): if dp[n][i] <= W: ans = max(ans, i) # print(dp[n]) print(ans)
false
13.043478
[ "-w, v = [0] * n, [0] * n", "-for i in range(n):", "+w, v = [0] * (n + 1), [0] * (n + 1)", "+for i in range(1, n + 1):", "-# Dのように品物と重さでループまわすとO(nW)で今W<=10**9だから間に合わない", "-# 品物と価値でループ回す", "-# dp[i][j]の意味はi番目までの品物で、価値j以上となるように選んだ時の、重さの最小値", "-sum_v = sum(v)", "-dp = [[float(\"inf\")] * (sum_v + 1) for i in range(n + 1)]", "+# 制約から、品物と価値のdpにする", "+dp = [[float(\"inf\")] * (sum(v) + 1) for _ in range(n + 1)]", "-for i in range(n):", "- for j in range(sum_v + 1):", "+# dp[i][j]はi番目までの品物の中から、価値jを", "+for i in range(1, n + 1):", "+ for j in range(sum(v) + 1):", "+ dp[i][j] = dp[i - 1][j]", "- dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])", "- dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])", "-# print(dp)", "+ dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i])", "-for j in range(sum_v + 1):", "- if dp[n][j] <= W:", "- ans = j", "+for i in range(sum(v) + 1):", "+ if dp[n][i] <= W:", "+ ans = max(ans, i)", "+# print(dp[n])" ]
false
0.153526
0.038297
4.008834
[ "s696781524", "s180801136" ]
u912237403
p00170
python
s701454620
s344201583
280
220
4,288
4,280
Accepted
Accepted
21.43
def solve(placed, w1, w2): global weight, D n = len(N) - len(placed) x = list(set(N) - set(placed)) if x == []: if weight > w1: D = placed weight = w1 return for e in x: w = W[e] if w2 > S[e]: return a = w1 + w * n if a > weight: return b = w2 + w solve(placed+[e], a, b) return while 1: n = eval(input()) if n==0: break D = [] weight = 1e9 N = list(range(n)) f = lambda x: [int(x[1]),int(x[2]),x[0]] x = [f(input().split()) for _ in [0]*n] W, S, Name = list(zip(*sorted(x))) solve([], 0, 0) for e in D[::-1]: print(Name[e])
def solve(placed, w1, w2): global ans n = len(N) - len(placed) if n==0: ans = min(ans, [w1, placed]) return for e in N: if e in placed: continue w, lim, s = Food[e] if w2 > lim: return a = w1 + w * n if a > ans[0]: return solve(placed+[e], a, w2 + w) return while 1: n = eval(input()) if n==0: break ans = [1e9, []] N = list(range(n)) f = lambda x: list(map(int, x[1:3])) + [x[0]] Food = [f(input().split()) for _ in [0]*n] solve([], 0, 0) for e in ans[1][::-1]: print(Food[e][2])
31
26
625
555
def solve(placed, w1, w2): global weight, D n = len(N) - len(placed) x = list(set(N) - set(placed)) if x == []: if weight > w1: D = placed weight = w1 return for e in x: w = W[e] if w2 > S[e]: return a = w1 + w * n if a > weight: return b = w2 + w solve(placed + [e], a, b) return while 1: n = eval(input()) if n == 0: break D = [] weight = 1e9 N = list(range(n)) f = lambda x: [int(x[1]), int(x[2]), x[0]] x = [f(input().split()) for _ in [0] * n] W, S, Name = list(zip(*sorted(x))) solve([], 0, 0) for e in D[::-1]: print(Name[e])
def solve(placed, w1, w2): global ans n = len(N) - len(placed) if n == 0: ans = min(ans, [w1, placed]) return for e in N: if e in placed: continue w, lim, s = Food[e] if w2 > lim: return a = w1 + w * n if a > ans[0]: return solve(placed + [e], a, w2 + w) return while 1: n = eval(input()) if n == 0: break ans = [1e9, []] N = list(range(n)) f = lambda x: list(map(int, x[1:3])) + [x[0]] Food = [f(input().split()) for _ in [0] * n] solve([], 0, 0) for e in ans[1][::-1]: print(Food[e][2])
false
16.129032
[ "- global weight, D", "+ global ans", "- x = list(set(N) - set(placed))", "- if x == []:", "- if weight > w1:", "- D = placed", "- weight = w1", "+ if n == 0:", "+ ans = min(ans, [w1, placed])", "- for e in x:", "- w = W[e]", "- if w2 > S[e]:", "+ for e in N:", "+ if e in placed:", "+ continue", "+ w, lim, s = Food[e]", "+ if w2 > lim:", "- if a > weight:", "+ if a > ans[0]:", "- b = w2 + w", "- solve(placed + [e], a, b)", "+ solve(placed + [e], a, w2 + w)", "- D = []", "- weight = 1e9", "+ ans = [1e9, []]", "- f = lambda x: [int(x[1]), int(x[2]), x[0]]", "- x = [f(input().split()) for _ in [0] * n]", "- W, S, Name = list(zip(*sorted(x)))", "+ f = lambda x: list(map(int, x[1:3])) + [x[0]]", "+ Food = [f(input().split()) for _ in [0] * n]", "- for e in D[::-1]:", "- print(Name[e])", "+ for e in ans[1][::-1]:", "+ print(Food[e][2])" ]
false
0.114376
0.099793
1.146132
[ "s701454620", "s344201583" ]
u688219499
p02995
python
s392834159
s353712695
33
28
9,904
9,188
Accepted
Accepted
15.15
from math import gcd from decimal import Decimal as dec a, b, c, d = list(map(dec,input().split())) if a % c ==0: c_explicit = b // c - a // c + 1 else: c_explicit = b // c - a // c if a % d ==0: d_explicit = b // d - a // d + 1 else: d_explicit = b // d - a // d e = gcd(int(c), int(d)) e = dec(e) gcl = (c / e) * (d / e) * e if a % gcl ==0: e_explicit = b // gcl - a // gcl + 1 else: e_explicit = b // gcl - a // gcl g = b - a + 1 - c_explicit - d_explicit + e_explicit print(g)
from math import gcd as gcd a, b, c, d = list(map(int,input().split())) #cでわれるもの s = gcd(c, d) p = c * d // s divide_c = b // c - (a - 1) // c divide_d = b // d - (a - 1) // d divide_cd = b // p - (a - 1) // p print((int(b - a + 1 - divide_c - divide_d + divide_cd)))
20
9
521
267
from math import gcd from decimal import Decimal as dec a, b, c, d = list(map(dec, input().split())) if a % c == 0: c_explicit = b // c - a // c + 1 else: c_explicit = b // c - a // c if a % d == 0: d_explicit = b // d - a // d + 1 else: d_explicit = b // d - a // d e = gcd(int(c), int(d)) e = dec(e) gcl = (c / e) * (d / e) * e if a % gcl == 0: e_explicit = b // gcl - a // gcl + 1 else: e_explicit = b // gcl - a // gcl g = b - a + 1 - c_explicit - d_explicit + e_explicit print(g)
from math import gcd as gcd a, b, c, d = list(map(int, input().split())) # cでわれるもの s = gcd(c, d) p = c * d // s divide_c = b // c - (a - 1) // c divide_d = b // d - (a - 1) // d divide_cd = b // p - (a - 1) // p print((int(b - a + 1 - divide_c - divide_d + divide_cd)))
false
55
[ "-from math import gcd", "-from decimal import Decimal as dec", "+from math import gcd as gcd", "-a, b, c, d = list(map(dec, input().split()))", "-if a % c == 0:", "- c_explicit = b // c - a // c + 1", "-else:", "- c_explicit = b // c - a // c", "-if a % d == 0:", "- d_explicit = b // d - a // d + 1", "-else:", "- d_explicit = b // d - a // d", "-e = gcd(int(c), int(d))", "-e = dec(e)", "-gcl = (c / e) * (d / e) * e", "-if a % gcl == 0:", "- e_explicit = b // gcl - a // gcl + 1", "-else:", "- e_explicit = b // gcl - a // gcl", "-g = b - a + 1 - c_explicit - d_explicit + e_explicit", "-print(g)", "+a, b, c, d = list(map(int, input().split()))", "+# cでわれるもの", "+s = gcd(c, d)", "+p = c * d // s", "+divide_c = b // c - (a - 1) // c", "+divide_d = b // d - (a - 1) // d", "+divide_cd = b // p - (a - 1) // p", "+print((int(b - a + 1 - divide_c - divide_d + divide_cd)))" ]
false
0.193851
0.045125
4.295831
[ "s392834159", "s353712695" ]
u853185302
p03013
python
s795535298
s459302031
463
206
460,788
13,216
Accepted
Accepted
55.51
N,M = list(map(int,input().split())) num = 1000000007 hole = [False]*(N+1) a = [int(eval(input())) for _ in range(M)] for i in a: hole[i] = True dp = [0]*(N+1) dp[0] = 1 for i in range(1,N+1): if i == 1: if hole[i] == True: dp[i] = 0 else: dp[i] = dp[0] else: if hole[i] == True: dp[i] = 0 else: dp[i] = dp[i-1] + dp[i-2] print((dp[-1]%num))
n,m = list(map(int,input().split())) a = set([int(eval(input())) for _ in range(m)]) dp = [0]*(n+1) dp[0] = 1 for i in range(1,n+1): dp[i] = (dp[i-1]+dp[i-2])%(10**9+7) if i in a: dp[i]=0 print((dp[n]))
24
8
402
200
N, M = list(map(int, input().split())) num = 1000000007 hole = [False] * (N + 1) a = [int(eval(input())) for _ in range(M)] for i in a: hole[i] = True dp = [0] * (N + 1) dp[0] = 1 for i in range(1, N + 1): if i == 1: if hole[i] == True: dp[i] = 0 else: dp[i] = dp[0] else: if hole[i] == True: dp[i] = 0 else: dp[i] = dp[i - 1] + dp[i - 2] print((dp[-1] % num))
n, m = list(map(int, input().split())) a = set([int(eval(input())) for _ in range(m)]) dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7) if i in a: dp[i] = 0 print((dp[n]))
false
66.666667
[ "-N, M = list(map(int, input().split()))", "-num = 1000000007", "-hole = [False] * (N + 1)", "-a = [int(eval(input())) for _ in range(M)]", "-for i in a:", "- hole[i] = True", "-dp = [0] * (N + 1)", "+n, m = list(map(int, input().split()))", "+a = set([int(eval(input())) for _ in range(m)])", "+dp = [0] * (n + 1)", "-for i in range(1, N + 1):", "- if i == 1:", "- if hole[i] == True:", "- dp[i] = 0", "- else:", "- dp[i] = dp[0]", "- else:", "- if hole[i] == True:", "- dp[i] = 0", "- else:", "- dp[i] = dp[i - 1] + dp[i - 2]", "-print((dp[-1] % num))", "+for i in range(1, n + 1):", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7)", "+ if i in a:", "+ dp[i] = 0", "+print((dp[n]))" ]
false
0.077195
0.07684
1.004623
[ "s795535298", "s459302031" ]
u630511239
p03150
python
s903770807
s117580952
19
17
2,940
2,940
Accepted
Accepted
10.53
S = eval(input()) ans = 'NO' n = len(S) if S == 'keyence': ans = 'YES' for i in range(n): for j in range(i,n): T = S[:i]+S[j:] if T == 'keyence': ans = 'YES' print(ans)
S = eval(input()) n = len(S) ans = 'NO' for i in range(n): j = i+n-7 Q = S[:i] + S[j:] if Q == 'keyence': ans = 'YES' print(ans)
14
9
200
140
S = eval(input()) ans = "NO" n = len(S) if S == "keyence": ans = "YES" for i in range(n): for j in range(i, n): T = S[:i] + S[j:] if T == "keyence": ans = "YES" print(ans)
S = eval(input()) n = len(S) ans = "NO" for i in range(n): j = i + n - 7 Q = S[:i] + S[j:] if Q == "keyence": ans = "YES" print(ans)
false
35.714286
[ "+n = len(S)", "-n = len(S)", "-if S == \"keyence\":", "- ans = \"YES\"", "- for j in range(i, n):", "- T = S[:i] + S[j:]", "- if T == \"keyence\":", "- ans = \"YES\"", "+ j = i + n - 7", "+ Q = S[:i] + S[j:]", "+ if Q == \"keyence\":", "+ ans = \"YES\"" ]
false
0.078563
0.071294
1.101968
[ "s903770807", "s117580952" ]
u211706121
p02889
python
s268989528
s622486082
1,671
1,284
90,200
56,144
Accepted
Accepted
23.16
n,m,l=list(map(int,input().split())) cost=[[10**9+1]*n for i in range(n)] length=[[10**9]*n for i in range(n)] for i in range(m): a,b,c=list(map(int,input().split())) a-=1 b-=1 cost[a][b]=c cost[b][a]=c q=int(eval(input())) st=[list(map(int,input().split()))for i in range(q)] for k in range(n): for i in range(n): for j in range(n): cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]) for i in range(n): length[i][i]=0 for i in range(n): for j in range(n): if cost[i][j]<=l: length[i][j]=0 for k in range(n): for i in range(n): for j in range(n): length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1) for s,t in st: ch=min(length[s-1][t-1],length[t-1][s-1]) print((-1 if ch>10**8 else ch))
import numpy as np from scipy.sparse import lil_matrix, csr_matrix from scipy.sparse.csgraph import shortest_path n,m,limit=list(map(int,input().split())) G=np.zeros((n,n),dtype=np.int64) for i in range(m): a,b,cost=list(map(int,input().split())) G[a-1,b-1]=cost G[b-1,a-1]=cost G=shortest_path(G,method='FW') for c in range(n): for l in range(n): if G[c][l]<=limit: G[c][l]=1 else: G[c][l]=0 G=shortest_path(G,method='FW') q=int(eval(input())) Q=[list(map(int,input().split()))for i in range(q)] for a,b in Q: print((int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1))
29
22
799
624
n, m, l = list(map(int, input().split())) cost = [[10**9 + 1] * n for i in range(n)] length = [[10**9] * n for i in range(n)] for i in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 cost[a][b] = c cost[b][a] = c q = int(eval(input())) st = [list(map(int, input().split())) for i in range(q)] for k in range(n): for i in range(n): for j in range(n): cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) for i in range(n): length[i][i] = 0 for i in range(n): for j in range(n): if cost[i][j] <= l: length[i][j] = 0 for k in range(n): for i in range(n): for j in range(n): length[i][j] = min(length[i][j], length[i][k] + length[k][j] + 1) for s, t in st: ch = min(length[s - 1][t - 1], length[t - 1][s - 1]) print((-1 if ch > 10**8 else ch))
import numpy as np from scipy.sparse import lil_matrix, csr_matrix from scipy.sparse.csgraph import shortest_path n, m, limit = list(map(int, input().split())) G = np.zeros((n, n), dtype=np.int64) for i in range(m): a, b, cost = list(map(int, input().split())) G[a - 1, b - 1] = cost G[b - 1, a - 1] = cost G = shortest_path(G, method="FW") for c in range(n): for l in range(n): if G[c][l] <= limit: G[c][l] = 1 else: G[c][l] = 0 G = shortest_path(G, method="FW") q = int(eval(input())) Q = [list(map(int, input().split())) for i in range(q)] for a, b in Q: print((int(G[a - 1][b - 1]) - 1 if G[a - 1][b - 1] < 10**18 else -1))
false
24.137931
[ "-n, m, l = list(map(int, input().split()))", "-cost = [[10**9 + 1] * n for i in range(n)]", "-length = [[10**9] * n for i in range(n)]", "+import numpy as np", "+from scipy.sparse import lil_matrix, csr_matrix", "+from scipy.sparse.csgraph import shortest_path", "+", "+n, m, limit = list(map(int, input().split()))", "+G = np.zeros((n, n), dtype=np.int64)", "- a, b, c = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- cost[a][b] = c", "- cost[b][a] = c", "+ a, b, cost = list(map(int, input().split()))", "+ G[a - 1, b - 1] = cost", "+ G[b - 1, a - 1] = cost", "+G = shortest_path(G, method=\"FW\")", "+for c in range(n):", "+ for l in range(n):", "+ if G[c][l] <= limit:", "+ G[c][l] = 1", "+ else:", "+ G[c][l] = 0", "+G = shortest_path(G, method=\"FW\")", "-st = [list(map(int, input().split())) for i in range(q)]", "-for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])", "-for i in range(n):", "- length[i][i] = 0", "-for i in range(n):", "- for j in range(n):", "- if cost[i][j] <= l:", "- length[i][j] = 0", "-for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- length[i][j] = min(length[i][j], length[i][k] + length[k][j] + 1)", "-for s, t in st:", "- ch = min(length[s - 1][t - 1], length[t - 1][s - 1])", "- print((-1 if ch > 10**8 else ch))", "+Q = [list(map(int, input().split())) for i in range(q)]", "+for a, b in Q:", "+ print((int(G[a - 1][b - 1]) - 1 if G[a - 1][b - 1] < 10**18 else -1))" ]
false
0.037746
0.662832
0.056946
[ "s268989528", "s622486082" ]
u852690916
p03464
python
s779879827
s510325810
361
118
63,856
14,224
Accepted
Accepted
67.31
K=int(eval(input())) A=list(map(int,input().split())) def g(n): for a in A: n=n-n%a return n a_max=max(A) l=1 r=2+K*a_max while r-l>1: m=(l+r)//2 if g(m)>=2: r=m else: l=m l0=r l=1 r=2+K*a_max while r-l>1: m=(l+r)//2 if g(m)<=2: l=m else: r=m r0=l if l0>r0: print((-1)) else: print((l0,r0))
K=int(eval(input())) A=list(map(int, input().split())) mx=2 mn=2 for i in range(K-1,-1,-1): a = A[i] a_mn = ((mn+a-1)//a)*a a_mx = mx - mx%a if a_mn > a_mx: print((-1)) exit() mn=a_mn mx=a_mx+a-1 print(("{} {}".format(mn,mx)))
33
15
396
271
K = int(eval(input())) A = list(map(int, input().split())) def g(n): for a in A: n = n - n % a return n a_max = max(A) l = 1 r = 2 + K * a_max while r - l > 1: m = (l + r) // 2 if g(m) >= 2: r = m else: l = m l0 = r l = 1 r = 2 + K * a_max while r - l > 1: m = (l + r) // 2 if g(m) <= 2: l = m else: r = m r0 = l if l0 > r0: print((-1)) else: print((l0, r0))
K = int(eval(input())) A = list(map(int, input().split())) mx = 2 mn = 2 for i in range(K - 1, -1, -1): a = A[i] a_mn = ((mn + a - 1) // a) * a a_mx = mx - mx % a if a_mn > a_mx: print((-1)) exit() mn = a_mn mx = a_mx + a - 1 print(("{} {}".format(mn, mx)))
false
54.545455
[ "-", "-", "-def g(n):", "- for a in A:", "- n = n - n % a", "- return n", "-", "-", "-a_max = max(A)", "-l = 1", "-r = 2 + K * a_max", "-while r - l > 1:", "- m = (l + r) // 2", "- if g(m) >= 2:", "- r = m", "- else:", "- l = m", "-l0 = r", "-l = 1", "-r = 2 + K * a_max", "-while r - l > 1:", "- m = (l + r) // 2", "- if g(m) <= 2:", "- l = m", "- else:", "- r = m", "-r0 = l", "-if l0 > r0:", "- print((-1))", "-else:", "- print((l0, r0))", "+mx = 2", "+mn = 2", "+for i in range(K - 1, -1, -1):", "+ a = A[i]", "+ a_mn = ((mn + a - 1) // a) * a", "+ a_mx = mx - mx % a", "+ if a_mn > a_mx:", "+ print((-1))", "+ exit()", "+ mn = a_mn", "+ mx = a_mx + a - 1", "+print((\"{} {}\".format(mn, mx)))" ]
false
0.041092
0.034781
1.181446
[ "s779879827", "s510325810" ]
u368249389
p02743
python
s284414648
s941227718
169
17
38,384
2,940
Accepted
Accepted
89.94
# Problem C - Sqrt Inequality # 注意:ルートの計算は近似計算によりWAとなってしまう。 # :整数に落とし込んで計算しよう # input process a, b, c = list(map(int, input().split())) # initialization tochu_1 = c - a - b tochu_2 = 4 * a * b # output process if tochu_1>0 and (tochu_1)**2>tochu_2: print("Yes") else: print("No")
# Problem C - Sqrt Inequality # input a, b, c = list(map(int, input().split())) # check is_ok = (a * b)*4 < (c - a - b)**2 and (c-a-b)>0 # output if is_ok: print("Yes") else: print("No")
17
13
305
204
# Problem C - Sqrt Inequality # 注意:ルートの計算は近似計算によりWAとなってしまう。 # :整数に落とし込んで計算しよう # input process a, b, c = list(map(int, input().split())) # initialization tochu_1 = c - a - b tochu_2 = 4 * a * b # output process if tochu_1 > 0 and (tochu_1) ** 2 > tochu_2: print("Yes") else: print("No")
# Problem C - Sqrt Inequality # input a, b, c = list(map(int, input().split())) # check is_ok = (a * b) * 4 < (c - a - b) ** 2 and (c - a - b) > 0 # output if is_ok: print("Yes") else: print("No")
false
23.529412
[ "-# 注意:ルートの計算は近似計算によりWAとなってしまう。", "-# :整数に落とし込んで計算しよう", "-# input process", "+# input", "-# initialization", "-tochu_1 = c - a - b", "-tochu_2 = 4 * a * b", "-# output process", "-if tochu_1 > 0 and (tochu_1) ** 2 > tochu_2:", "+# check", "+is_ok = (a * b) * 4 < (c - a - b) ** 2 and (c - a - b) > 0", "+# output", "+if is_ok:" ]
false
0.047006
0.043007
1.092988
[ "s284414648", "s941227718" ]
u597455618
p02559
python
s860078532
s994585171
3,605
2,734
68,284
77,772
Accepted
Accepted
24.16
import sys class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def build(self, arr): #assert len(arr) <= n for i, a in enumerate(arr): self.add(i+1, a) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): #assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n) bit.build(list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p+1, x) if __name__ == "__main__": main()
import sys class Bit: def __init__(self, n, arr): self.size = n self.tree = [0] + arr for i in range(1, n+1): if i + (i & -i) < n + 1: self.tree[i + (i & -i)] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p+1, x) if __name__ == "__main__": main()
44
40
987
941
import sys class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def build(self, arr): # assert len(arr) <= n for i, a in enumerate(arr): self.add(i + 1, a) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): # assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n) bit.build(list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p + 1, x) if __name__ == "__main__": main()
import sys class Bit: def __init__(self, n, arr): self.size = n self.tree = [0] + arr for i in range(1, n + 1): if i + (i & -i) < n + 1: self.tree[i + (i & -i)] += self.tree[i] def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def range_sum(self, l, r): return self.sum(r) - self.sum(l) def main(): n, q = list(map(int, sys.stdin.buffer.readline().split())) bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split()))) for x in sys.stdin.buffer.readlines(): q, p, x = list(map(int, x.split())) if q: print((bit.range_sum(p, x))) else: bit.add(p + 1, x) if __name__ == "__main__": main()
false
9.090909
[ "- def __init__(self, n):", "+ def __init__(self, n, arr):", "- self.tree = [0] * (n + 1)", "-", "- def build(self, arr):", "- # assert len(arr) <= n", "- for i, a in enumerate(arr):", "- self.add(i + 1, a)", "+ self.tree = [0] + arr", "+ for i in range(1, n + 1):", "+ if i + (i & -i) < n + 1:", "+ self.tree[i + (i & -i)] += self.tree[i]", "- # assert 0 <= l <= r <= self.n", "- bit = Bit(n)", "- bit.build(list(map(int, sys.stdin.buffer.readline().split())))", "+ bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split())))" ]
false
0.053805
0.034691
1.550963
[ "s860078532", "s994585171" ]
u102461423
p03987
python
s119927975
s810197950
322
157
36,380
39,708
Accepted
Accepted
51.24
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・大きい数から挿入していく ・連結成分の両端を管理する """ N,*A = list(map(int,read().split())) A = [0] + A + [0] ind = [0] * (N+1) for i,x in enumerate(A): ind[x] = i left = list(range(1,len(A)+1)) right = list(range(-1,len(A)-1)) answer = 0 for i in ind[:0:-1]: # i番目に数を挿入 l = left[i-1]; r = right[i+1] left[r] = l; right[l] = r x = i - l + 1; y = r - i + 1 answer += A[i] * (x * y) print(answer)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def maximal_rectangle(H): """ヒストグラムに対して、極大長方形を計算。 各 i に対して、[l,r) が高さ H[i] となるような l, r を計算する。 アリ本 p.299~p.300 """ N = len(H) L = np.empty(N, np.int32) R = np.empty(N, np.int32) st = np.zeros(N, np.int32) # 左端の計算 t = 0 for i in range(N): while t and H[st[t - 1]] >= H[i]: t -= 1 L[i] = 0 if t == 0 else st[t - 1] + 1 st[t] = i t += 1 # 右端の計算 t = 0 for i in range(N - 1, -1, -1): while t and H[st[t - 1]] >= H[i]: t -= 1 R[i] = N if t == 0 else st[t - 1] st[t] = i t += 1 return L, R signature = '(i8[:],)' if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('my_module') cc.export('maximal_rectangle', signature)(maximal_rectangle) cc.compile() from my_module import maximal_rectangle A = np.array(read().split(), np.int64)[1:] N = len(A) L, R = maximal_rectangle(A) coef = (np.arange(N) - L + 1) * (R - np.arange(N)) x = np.sum(coef * A) print(x)
28
50
541
1,216
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・大きい数から挿入していく ・連結成分の両端を管理する """ N, *A = list(map(int, read().split())) A = [0] + A + [0] ind = [0] * (N + 1) for i, x in enumerate(A): ind[x] = i left = list(range(1, len(A) + 1)) right = list(range(-1, len(A) - 1)) answer = 0 for i in ind[:0:-1]: # i番目に数を挿入 l = left[i - 1] r = right[i + 1] left[r] = l right[l] = r x = i - l + 1 y = r - i + 1 answer += A[i] * (x * y) print(answer)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def maximal_rectangle(H): """ヒストグラムに対して、極大長方形を計算。 各 i に対して、[l,r) が高さ H[i] となるような l, r を計算する。 アリ本 p.299~p.300 """ N = len(H) L = np.empty(N, np.int32) R = np.empty(N, np.int32) st = np.zeros(N, np.int32) # 左端の計算 t = 0 for i in range(N): while t and H[st[t - 1]] >= H[i]: t -= 1 L[i] = 0 if t == 0 else st[t - 1] + 1 st[t] = i t += 1 # 右端の計算 t = 0 for i in range(N - 1, -1, -1): while t and H[st[t - 1]] >= H[i]: t -= 1 R[i] = N if t == 0 else st[t - 1] st[t] = i t += 1 return L, R signature = "(i8[:],)" if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("maximal_rectangle", signature)(maximal_rectangle) cc.compile() from my_module import maximal_rectangle A = np.array(read().split(), np.int64)[1:] N = len(A) L, R = maximal_rectangle(A) coef = (np.arange(N) - L + 1) * (R - np.arange(N)) x = np.sum(coef * A) print(x)
false
44
[ "+import numpy as np", "-\"\"\"", "-・大きい数から挿入していく", "-・連結成分の両端を管理する", "-\"\"\"", "-N, *A = list(map(int, read().split()))", "-A = [0] + A + [0]", "-ind = [0] * (N + 1)", "-for i, x in enumerate(A):", "- ind[x] = i", "-left = list(range(1, len(A) + 1))", "-right = list(range(-1, len(A) - 1))", "-answer = 0", "-for i in ind[:0:-1]:", "- # i番目に数を挿入", "- l = left[i - 1]", "- r = right[i + 1]", "- left[r] = l", "- right[l] = r", "- x = i - l + 1", "- y = r - i + 1", "- answer += A[i] * (x * y)", "-print(answer)", "+", "+", "+def maximal_rectangle(H):", "+ \"\"\"ヒストグラムに対して、極大長方形を計算。", "+ 各 i に対して、[l,r) が高さ H[i] となるような l, r を計算する。", "+ アリ本 p.299~p.300", "+ \"\"\"", "+ N = len(H)", "+ L = np.empty(N, np.int32)", "+ R = np.empty(N, np.int32)", "+ st = np.zeros(N, np.int32)", "+ # 左端の計算", "+ t = 0", "+ for i in range(N):", "+ while t and H[st[t - 1]] >= H[i]:", "+ t -= 1", "+ L[i] = 0 if t == 0 else st[t - 1] + 1", "+ st[t] = i", "+ t += 1", "+ # 右端の計算", "+ t = 0", "+ for i in range(N - 1, -1, -1):", "+ while t and H[st[t - 1]] >= H[i]:", "+ t -= 1", "+ R[i] = N if t == 0 else st[t - 1]", "+ st[t] = i", "+ t += 1", "+ return L, R", "+", "+", "+signature = \"(i8[:],)\"", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"maximal_rectangle\", signature)(maximal_rectangle)", "+ cc.compile()", "+from my_module import maximal_rectangle", "+", "+A = np.array(read().split(), np.int64)[1:]", "+N = len(A)", "+L, R = maximal_rectangle(A)", "+coef = (np.arange(N) - L + 1) * (R - np.arange(N))", "+x = np.sum(coef * A)", "+print(x)" ]
false
0.049656
0.253764
0.195677
[ "s119927975", "s810197950" ]
u968166680
p03476
python
s784421026
s807486929
154
121
29,720
29,000
Accepted
Accepted
21.43
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n ** 0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10 ** 5) A = [n % 2 and n in primes and (n + 1) // 2 in primes for n in range(10 ** 5 + 1)] B = [0] B.extend(accumulate(A)) Q, *LR = map(int, read().split()) ans = [0] * Q for i, (l, r) in enumerate(zip(LR[::2], LR[1::2])): ans[i] = B[r + 1] - B[l] print(*ans, sep='\n') return if __name__ == '__main__': main()
from sys import stdin, setrecursionlimit from itertools import accumulate setrecursionlimit(10 ** 9) INF = 1 << 60 def input(): return stdin.readline().strip() def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n ** 0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): N = 10 ** 5 primes = prime_numbers(N) a = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(N + 1)] a = tuple(accumulate(a)) ans = [] Q, *LR = list(map(int, open(0).read().split())) for l, r in zip(*[iter(LR)] * 2): ans.append(a[r] - a[l - 1]) print(('\n'.join(map(str, ans)))) if __name__ == "__main__": main()
40
40
937
912
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n**0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * ( ((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1 ) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10**5) A = [n % 2 and n in primes and (n + 1) // 2 in primes for n in range(10**5 + 1)] B = [0] B.extend(accumulate(A)) Q, *LR = map(int, read().split()) ans = [0] * Q for i, (l, r) in enumerate(zip(LR[::2], LR[1::2])): ans[i] = B[r + 1] - B[l] print(*ans, sep="\n") return if __name__ == "__main__": main()
from sys import stdin, setrecursionlimit from itertools import accumulate setrecursionlimit(10**9) INF = 1 << 60 def input(): return stdin.readline().strip() def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n**0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * ( ((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1 ) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): N = 10**5 primes = prime_numbers(N) a = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(N + 1)] a = tuple(accumulate(a)) ans = [] Q, *LR = list(map(int, open(0).read().split())) for l, r in zip(*[iter(LR)] * 2): ans.append(a[r] - a[l - 1]) print(("\n".join(map(str, ans)))) if __name__ == "__main__": main()
false
0
[ "-import sys", "+from sys import stdin, setrecursionlimit", "-read = sys.stdin.read", "-readline = sys.stdin.readline", "-readlines = sys.stdin.readlines", "-sys.setrecursionlimit(10**9)", "+setrecursionlimit(10**9)", "+", "+", "+def input():", "+ return stdin.readline().strip()", "- primes = prime_numbers(10**5)", "- A = [n % 2 and n in primes and (n + 1) // 2 in primes for n in range(10**5 + 1)]", "- B = [0]", "- B.extend(accumulate(A))", "- Q, *LR = map(int, read().split())", "- ans = [0] * Q", "- for i, (l, r) in enumerate(zip(LR[::2], LR[1::2])):", "- ans[i] = B[r + 1] - B[l]", "- print(*ans, sep=\"\\n\")", "- return", "+ N = 10**5", "+ primes = prime_numbers(N)", "+ a = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(N + 1)]", "+ a = tuple(accumulate(a))", "+ ans = []", "+ Q, *LR = list(map(int, open(0).read().split()))", "+ for l, r in zip(*[iter(LR)] * 2):", "+ ans.append(a[r] - a[l - 1])", "+ print((\"\\n\".join(map(str, ans))))" ]
false
0.076641
0.072266
1.060539
[ "s784421026", "s807486929" ]
u994521204
p03163
python
s041290965
s206732347
820
521
172,040
120,428
Accepted
Accepted
36.46
n,w=list(map(int,input().split())) WV=[list(map(int,input().split())) for i in range(n)] #WV[i][0]が重さ、WV[i][1]が価値 #配るDP dp=[[0 for i in range(w+1)] for i in range(n+1)] #dp[i][j]はi回目(0,n-1)に重さjまで入るmax value for i in range(n): for j in range(w+1): if WV[i][0]+j<=w and i <=n-1: dp[i+1][j+WV[i][0]]=max(dp[i][j+WV[i][0]], dp[i][j]+WV[i][1]) dp[i+1][j]=max(dp[i][j],dp[i+1][j]) else: dp[i+1][j]=max(dp[i][j],dp[i+1][j]) print((max(dp[n])))
# 貰うDP n, w = list(map(int, input().split())) WV = [list(map(int, input().split())) for i in range(n)] # dp[i][w] 重さwでの最高価値 dp = [[-1] * (w + 1) for i in range(n + 1)] for j in range(w + 1): dp[0][j] = 0 for i in range(n): for j in range(w + 1): if j - WV[i][0] >= 0 and j - WV[i][0] <= w: dp[i + 1][j] = max(dp[i][j - WV[i][0]] + WV[i][1], dp[i][j]) else: dp[i + 1][j] = dp[i][j] print((dp[n][w]))
14
14
497
452
n, w = list(map(int, input().split())) WV = [list(map(int, input().split())) for i in range(n)] # WV[i][0]が重さ、WV[i][1]が価値 # 配るDP dp = [[0 for i in range(w + 1)] for i in range(n + 1)] # dp[i][j]はi回目(0,n-1)に重さjまで入るmax value for i in range(n): for j in range(w + 1): if WV[i][0] + j <= w and i <= n - 1: dp[i + 1][j + WV[i][0]] = max(dp[i][j + WV[i][0]], dp[i][j] + WV[i][1]) dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]) else: dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]) print((max(dp[n])))
# 貰うDP n, w = list(map(int, input().split())) WV = [list(map(int, input().split())) for i in range(n)] # dp[i][w] 重さwでの最高価値 dp = [[-1] * (w + 1) for i in range(n + 1)] for j in range(w + 1): dp[0][j] = 0 for i in range(n): for j in range(w + 1): if j - WV[i][0] >= 0 and j - WV[i][0] <= w: dp[i + 1][j] = max(dp[i][j - WV[i][0]] + WV[i][1], dp[i][j]) else: dp[i + 1][j] = dp[i][j] print((dp[n][w]))
false
0
[ "+# 貰うDP", "-# WV[i][0]が重さ、WV[i][1]が価値", "-# 配るDP", "-dp = [[0 for i in range(w + 1)] for i in range(n + 1)]", "-# dp[i][j]はi回目(0,n-1)に重さjまで入るmax value", "+# dp[i][w] 重さwでの最高価値", "+dp = [[-1] * (w + 1) for i in range(n + 1)]", "+for j in range(w + 1):", "+ dp[0][j] = 0", "- if WV[i][0] + j <= w and i <= n - 1:", "- dp[i + 1][j + WV[i][0]] = max(dp[i][j + WV[i][0]], dp[i][j] + WV[i][1])", "- dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])", "+ if j - WV[i][0] >= 0 and j - WV[i][0] <= w:", "+ dp[i + 1][j] = max(dp[i][j - WV[i][0]] + WV[i][1], dp[i][j])", "- dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])", "-print((max(dp[n])))", "+ dp[i + 1][j] = dp[i][j]", "+print((dp[n][w]))" ]
false
0.042987
0.043038
0.998807
[ "s041290965", "s206732347" ]
u843175622
p03472
python
s134982667
s007138187
166
139
25,124
25,124
Accepted
Accepted
16.27
n, h, *k = list(map(int, open(0).read().split())) a = 0; b = [] for i, j in zip(*[iter(k)]*2): a = max(a, i) b.append(j) b = sorted(b, reverse = True) ans = 0 while ans < n and b[ans] > a and h > 0: h -= b[ans] ans += 1 if h > 0: ans += (h + a - 1) // a print(ans)
n, h, *k = list(map(int, open(0).read().split())) a = max(k[::2]); b = sorted(k[1::2], reverse = True) ans = 0 while ans < n and b[ans] > a and h > 0: h -= b[ans] ans += 1 if h > 0: ans += (h + a - 1) // a print(ans)
15
9
291
227
n, h, *k = list(map(int, open(0).read().split())) a = 0 b = [] for i, j in zip(*[iter(k)] * 2): a = max(a, i) b.append(j) b = sorted(b, reverse=True) ans = 0 while ans < n and b[ans] > a and h > 0: h -= b[ans] ans += 1 if h > 0: ans += (h + a - 1) // a print(ans)
n, h, *k = list(map(int, open(0).read().split())) a = max(k[::2]) b = sorted(k[1::2], reverse=True) ans = 0 while ans < n and b[ans] > a and h > 0: h -= b[ans] ans += 1 if h > 0: ans += (h + a - 1) // a print(ans)
false
40
[ "-a = 0", "-b = []", "-for i, j in zip(*[iter(k)] * 2):", "- a = max(a, i)", "- b.append(j)", "-b = sorted(b, reverse=True)", "+a = max(k[::2])", "+b = sorted(k[1::2], reverse=True)" ]
false
0.151513
0.104818
1.445481
[ "s134982667", "s007138187" ]
u007381711
p04045
python
s835835399
s669028794
77
64
16,476
13,928
Accepted
Accepted
16.88
# -*- coding: utf-8 -*- import sys,math,itertools input = sys.stdin.readline n, k = list(map(int, input().split())) d = [int(_) for _ in input().split()] d_set = set(d) d_all = set(range(10)) d_use = [str(a) for a in list(d_all - d_set)] keta = int(math.log10(n))+1 l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))] l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))] print((min(min(l1), min(l2))))
# -*- coding: utf-8 -*- import sys,math,itertools input = sys.stdin.readline n, k = list(map(int, input().split())) d = [int(_) for _ in input().split()] d_set = set(d) d_all = set(range(10)) d_use = [str(a) for a in list(d_all - d_set)] keta = int(math.log10(n))+1 # l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))] # l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))] temp = 100000 for i in list(itertools.product(d_use, repeat=keta+1)): a = int(''.join(list(i))) if (a>=n)&(a<temp): temp = a for i in list(itertools.product(d_use, repeat=keta)): a = int(''.join(list(i))) if (a>=n)&(a<temp): temp = a print(temp)
13
22
547
793
# -*- coding: utf-8 -*- import sys, math, itertools input = sys.stdin.readline n, k = list(map(int, input().split())) d = [int(_) for _ in input().split()] d_set = set(d) d_all = set(range(10)) d_use = [str(a) for a in list(d_all - d_set)] keta = int(math.log10(n)) + 1 l1 = [ int("".join(list(a))) if int("".join(list(a))) >= n else 100000 for a in list(itertools.product(d_use, repeat=keta + 1)) ] l2 = [ int("".join(list(a))) if int("".join(list(a))) >= n else 100000 for a in list(itertools.product(d_use, repeat=keta)) ] print((min(min(l1), min(l2))))
# -*- coding: utf-8 -*- import sys, math, itertools input = sys.stdin.readline n, k = list(map(int, input().split())) d = [int(_) for _ in input().split()] d_set = set(d) d_all = set(range(10)) d_use = [str(a) for a in list(d_all - d_set)] keta = int(math.log10(n)) + 1 # l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))] # l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))] temp = 100000 for i in list(itertools.product(d_use, repeat=keta + 1)): a = int("".join(list(i))) if (a >= n) & (a < temp): temp = a for i in list(itertools.product(d_use, repeat=keta)): a = int("".join(list(i))) if (a >= n) & (a < temp): temp = a print(temp)
false
40.909091
[ "-l1 = [", "- int(\"\".join(list(a))) if int(\"\".join(list(a))) >= n else 100000", "- for a in list(itertools.product(d_use, repeat=keta + 1))", "-]", "-l2 = [", "- int(\"\".join(list(a))) if int(\"\".join(list(a))) >= n else 100000", "- for a in list(itertools.product(d_use, repeat=keta))", "-]", "-print((min(min(l1), min(l2))))", "+# l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))]", "+# l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))]", "+temp = 100000", "+for i in list(itertools.product(d_use, repeat=keta + 1)):", "+ a = int(\"\".join(list(i)))", "+ if (a >= n) & (a < temp):", "+ temp = a", "+for i in list(itertools.product(d_use, repeat=keta)):", "+ a = int(\"\".join(list(i)))", "+ if (a >= n) & (a < temp):", "+ temp = a", "+print(temp)" ]
false
0.040122
0.031879
1.258558
[ "s835835399", "s669028794" ]
u309039873
p02887
python
s748454433
s064702221
166
72
39,280
67,444
Accepted
Accepted
56.63
N = int(eval(input())) S = eval(input()) postc = '' answer = 0 for c in S: if c != postc: answer += 1 postc = c print(answer)
N = int(eval(input())) S = eval(input()) cnt = 0 post_c = '' for i in range(len(S)): if post_c != S[i]: post_c = S[i] cnt += 1 print(cnt)
9
9
138
154
N = int(eval(input())) S = eval(input()) postc = "" answer = 0 for c in S: if c != postc: answer += 1 postc = c print(answer)
N = int(eval(input())) S = eval(input()) cnt = 0 post_c = "" for i in range(len(S)): if post_c != S[i]: post_c = S[i] cnt += 1 print(cnt)
false
0
[ "-postc = \"\"", "-answer = 0", "-for c in S:", "- if c != postc:", "- answer += 1", "- postc = c", "-print(answer)", "+cnt = 0", "+post_c = \"\"", "+for i in range(len(S)):", "+ if post_c != S[i]:", "+ post_c = S[i]", "+ cnt += 1", "+print(cnt)" ]
false
0.044836
0.036526
1.227481
[ "s748454433", "s064702221" ]
u489124637
p02813
python
s685928393
s749910410
46
27
8,052
8,052
Accepted
Accepted
41.3
import itertools N = int(eval(input())) T = list(range(1,N+1)) S = list(itertools.permutations(T, N)) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] for i in range(len(S)): if tuple(P) == S[i]: A = i if tuple(Q) == S[i]: B = i print((abs(A-B)))
import itertools N = int(eval(input())) T = list(range(1,N+1)) S = list(itertools.permutations(T, N)) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] A = S.index(tuple(P)) B = S.index(tuple(Q)) print((abs(A-B)))
14
11
304
243
import itertools N = int(eval(input())) T = list(range(1, N + 1)) S = list(itertools.permutations(T, N)) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] for i in range(len(S)): if tuple(P) == S[i]: A = i if tuple(Q) == S[i]: B = i print((abs(A - B)))
import itertools N = int(eval(input())) T = list(range(1, N + 1)) S = list(itertools.permutations(T, N)) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] A = S.index(tuple(P)) B = S.index(tuple(Q)) print((abs(A - B)))
false
21.428571
[ "-for i in range(len(S)):", "- if tuple(P) == S[i]:", "- A = i", "- if tuple(Q) == S[i]:", "- B = i", "+A = S.index(tuple(P))", "+B = S.index(tuple(Q))" ]
false
0.048394
0.040772
1.186939
[ "s685928393", "s749910410" ]
u092301301
p02861
python
s709873854
s876338127
209
17
48,016
3,060
Accepted
Accepted
91.87
import sys input = lambda: sys.stdin.readline().rstrip() from itertools import combinations_with_replacement as cwr , combinations , permutations ,product from math import sqrt a=[] for _ in range(int(eval(input()))): a.append([int(i) for i in input().split()]) p=list(permutations(a)) ans=[] for i in p: cur=0 for j in range(len(i)-1): cur+=sqrt((i[j+1][0]-i[j][0])**2+(i[j+1][1]-i[j][1])**2) ans.append(cur) print((sum(ans)/len(ans)))
import sys input = lambda: sys.stdin.readline().rstrip() from math import sqrt a=[] for _ in range(int(eval(input()))): a.append([int(i) for i in input().split()]) summ=0 for i in a: for j in a: summ+=sqrt((i[0]-j[0])**2+(i[1]-j[1])**2) print((summ/len(a)))
16
12
473
285
import sys input = lambda: sys.stdin.readline().rstrip() from itertools import ( combinations_with_replacement as cwr, combinations, permutations, product, ) from math import sqrt a = [] for _ in range(int(eval(input()))): a.append([int(i) for i in input().split()]) p = list(permutations(a)) ans = [] for i in p: cur = 0 for j in range(len(i) - 1): cur += sqrt((i[j + 1][0] - i[j][0]) ** 2 + (i[j + 1][1] - i[j][1]) ** 2) ans.append(cur) print((sum(ans) / len(ans)))
import sys input = lambda: sys.stdin.readline().rstrip() from math import sqrt a = [] for _ in range(int(eval(input()))): a.append([int(i) for i in input().split()]) summ = 0 for i in a: for j in a: summ += sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) print((summ / len(a)))
false
25
[ "-from itertools import (", "- combinations_with_replacement as cwr,", "- combinations,", "- permutations,", "- product,", "-)", "-p = list(permutations(a))", "-ans = []", "-for i in p:", "- cur = 0", "- for j in range(len(i) - 1):", "- cur += sqrt((i[j + 1][0] - i[j][0]) ** 2 + (i[j + 1][1] - i[j][1]) ** 2)", "- ans.append(cur)", "-print((sum(ans) / len(ans)))", "+summ = 0", "+for i in a:", "+ for j in a:", "+ summ += sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)", "+print((summ / len(a)))" ]
false
0.044571
0.043639
1.021372
[ "s709873854", "s876338127" ]
u952708174
p03805
python
s084448909
s728384461
27
24
3,064
3,064
Accepted
Accepted
11.11
def c_One_stroke_Path(N, M, E): import itertools edge = [[] for j in range(N + 1)] for a, b in E: edge[a].append(b) edge[b].append(a) ans = 0 route = itertools.permutations(list(range(2, N + 1)), N - 1) for r in route: if not r[0] in edge[1]: # 頂点1からrが示す次の行き先に行くことができない continue count = 0 for i in range(len(r)): if count == len(r) - 1: # すべての頂点を回れた ans += 1 break if not r[i + 1] in edge[r[i]]: # 次の行き先に行くことができなかった break count += 1 return ans N,M = [int(i) for i in input().split()] E = [[int(i) for i in input().split()] for j in range(M)] print((c_One_stroke_Path(N, M, E)))
def c_one_stroke_path(N, M, E): import itertools edge = [[] for j in range(N + 1)] for a, b in E: edge[a].append(b) edge[b].append(a) ans = 0 # 頂点1を除いて、この順番に頂点を回れるか試す route = itertools.permutations(list(range(2, N + 1)), N - 1) for r in route: if not r[0] in edge[1]: # 頂点1からrが示す次の行き先に行くことができない continue count = 0 for i in range(len(r) - 1): if not r[i + 1] in edge[r[i]]: # 次の行き先に行くことができなかった break else: # すべての頂点を訪れることができた ans += 1 return ans N,M = [int(i) for i in input().split()] E = [[int(i) for i in input().split()] for j in range(M)] print((c_one_stroke_path(N, M, E)))
29
26
808
757
def c_One_stroke_Path(N, M, E): import itertools edge = [[] for j in range(N + 1)] for a, b in E: edge[a].append(b) edge[b].append(a) ans = 0 route = itertools.permutations(list(range(2, N + 1)), N - 1) for r in route: if not r[0] in edge[1]: # 頂点1からrが示す次の行き先に行くことができない continue count = 0 for i in range(len(r)): if count == len(r) - 1: # すべての頂点を回れた ans += 1 break if not r[i + 1] in edge[r[i]]: # 次の行き先に行くことができなかった break count += 1 return ans N, M = [int(i) for i in input().split()] E = [[int(i) for i in input().split()] for j in range(M)] print((c_One_stroke_Path(N, M, E)))
def c_one_stroke_path(N, M, E): import itertools edge = [[] for j in range(N + 1)] for a, b in E: edge[a].append(b) edge[b].append(a) ans = 0 # 頂点1を除いて、この順番に頂点を回れるか試す route = itertools.permutations(list(range(2, N + 1)), N - 1) for r in route: if not r[0] in edge[1]: # 頂点1からrが示す次の行き先に行くことができない continue count = 0 for i in range(len(r) - 1): if not r[i + 1] in edge[r[i]]: # 次の行き先に行くことができなかった break else: # すべての頂点を訪れることができた ans += 1 return ans N, M = [int(i) for i in input().split()] E = [[int(i) for i in input().split()] for j in range(M)] print((c_one_stroke_path(N, M, E)))
false
10.344828
[ "-def c_One_stroke_Path(N, M, E):", "+def c_one_stroke_path(N, M, E):", "+ # 頂点1を除いて、この順番に頂点を回れるか試す", "- for i in range(len(r)):", "- if count == len(r) - 1:", "- # すべての頂点を回れた", "- ans += 1", "- break", "+ for i in range(len(r) - 1):", "- count += 1", "+ else: # すべての頂点を訪れることができた", "+ ans += 1", "-print((c_One_stroke_Path(N, M, E)))", "+print((c_one_stroke_path(N, M, E)))" ]
false
0.170148
0.043455
3.915508
[ "s084448909", "s728384461" ]
u623819879
p02913
python
s393862070
s762881926
615
449
41,820
41,948
Accepted
Accepted
26.99
n=int(eval(input())) s=list(eval(input())) f=0 b=-1 for d in range(1,n): c=0 b=-1 for i in range(n-d): if c>=d: break if s[i]==s[i+d]: if b==-1:b=i c+=1 f=max(f,c) else: c=0 b=-1 print(f)
n=int(eval(input())) s=list(eval(input())) f=0 b=-1 for d in range(1,n): c=0 b=-1 for i in range(n-d): if s[i]==s[i+d] and c<d: if b==-1:b=i c+=1 f=max(f,c) if c>=d: break else: c=0 b=-1 print(f)
18
18
247
259
n = int(eval(input())) s = list(eval(input())) f = 0 b = -1 for d in range(1, n): c = 0 b = -1 for i in range(n - d): if c >= d: break if s[i] == s[i + d]: if b == -1: b = i c += 1 f = max(f, c) else: c = 0 b = -1 print(f)
n = int(eval(input())) s = list(eval(input())) f = 0 b = -1 for d in range(1, n): c = 0 b = -1 for i in range(n - d): if s[i] == s[i + d] and c < d: if b == -1: b = i c += 1 f = max(f, c) if c >= d: break else: c = 0 b = -1 print(f)
false
0
[ "- if c >= d:", "- break", "- if s[i] == s[i + d]:", "+ if s[i] == s[i + d] and c < d:", "+ if c >= d:", "+ break" ]
false
0.037293
0.037138
1.004164
[ "s393862070", "s762881926" ]
u278057806
p02603
python
s128621754
s777934748
31
25
9,188
9,140
Accepted
Accepted
19.35
from sys import stdin input = stdin.readline N = int(eval(input())) A = list(map(int, input().split())) start = 0 money = 1000 for i in range(N - 1): if A[i + 1] > A[i]: tmp = 10 ** 3 for k in range(i, start - 1, -1): tmp = min(A[k], tmp) buy = money // tmp money -= tmp * buy money += buy * A[i + 1] start = i + 1 print(money)
from sys import stdin input = stdin.readline N = int(eval(input())) A = list(map(int, input().split())) start = 0 money = 1000 for i in range(N - 1): if A[i + 1] > A[i]: buy = money // A[i] money -= A[i] * buy money += buy * A[i + 1] print(money)
20
16
409
288
from sys import stdin input = stdin.readline N = int(eval(input())) A = list(map(int, input().split())) start = 0 money = 1000 for i in range(N - 1): if A[i + 1] > A[i]: tmp = 10**3 for k in range(i, start - 1, -1): tmp = min(A[k], tmp) buy = money // tmp money -= tmp * buy money += buy * A[i + 1] start = i + 1 print(money)
from sys import stdin input = stdin.readline N = int(eval(input())) A = list(map(int, input().split())) start = 0 money = 1000 for i in range(N - 1): if A[i + 1] > A[i]: buy = money // A[i] money -= A[i] * buy money += buy * A[i + 1] print(money)
false
20
[ "- tmp = 10**3", "- for k in range(i, start - 1, -1):", "- tmp = min(A[k], tmp)", "- buy = money // tmp", "- money -= tmp * buy", "+ buy = money // A[i]", "+ money -= A[i] * buy", "- start = i + 1" ]
false
0.090761
0.103806
0.874331
[ "s128621754", "s777934748" ]
u398383435
p02641
python
s936886499
s939128598
31
28
9,512
9,140
Accepted
Accepted
9.68
import random X,N = input().split() X,N = int(X),int(N) P = input().split() P = [int(c) for c in P] if len(P) == 0: print(X) else: L = list(range(max(0,X-N),min(102,X+N))) if X+N <= 101: L.append(X+N) for i in range(N): if P[i] in L: L.remove(P[i]) while len(L) > 2: rand = random.randint(1,len(L)-2) if L[rand] == X: break elif L[rand] > X: L = L[0:rand+1] else: L = L[rand:len(L)] if X in L: print(X) elif len(L) == 1: print((L[0])) else: if abs(L[0]-X) > abs(L[1]-X): print((L[1])) else: print((L[0]))
X,N = input().split() X,N = int(X),int(N) P = input().split() P = [int(c) for c in P] i = X j = X if len(P) == 0: print(X) elif X not in P: print(X) else: while i < 101: i += 1 if i not in P: break while j > 0: j -= 1 if j not in P: break if i - X >= X - j: print(j) else: print(i)
38
27
730
416
import random X, N = input().split() X, N = int(X), int(N) P = input().split() P = [int(c) for c in P] if len(P) == 0: print(X) else: L = list(range(max(0, X - N), min(102, X + N))) if X + N <= 101: L.append(X + N) for i in range(N): if P[i] in L: L.remove(P[i]) while len(L) > 2: rand = random.randint(1, len(L) - 2) if L[rand] == X: break elif L[rand] > X: L = L[0 : rand + 1] else: L = L[rand : len(L)] if X in L: print(X) elif len(L) == 1: print((L[0])) else: if abs(L[0] - X) > abs(L[1] - X): print((L[1])) else: print((L[0]))
X, N = input().split() X, N = int(X), int(N) P = input().split() P = [int(c) for c in P] i = X j = X if len(P) == 0: print(X) elif X not in P: print(X) else: while i < 101: i += 1 if i not in P: break while j > 0: j -= 1 if j not in P: break if i - X >= X - j: print(j) else: print(i)
false
28.947368
[ "-import random", "-", "+i = X", "+j = X", "+elif X not in P:", "+ print(X)", "- L = list(range(max(0, X - N), min(102, X + N)))", "- if X + N <= 101:", "- L.append(X + N)", "- for i in range(N):", "- if P[i] in L:", "- L.remove(P[i])", "- while len(L) > 2:", "- rand = random.randint(1, len(L) - 2)", "- if L[rand] == X:", "+ while i < 101:", "+ i += 1", "+ if i not in P:", "- elif L[rand] > X:", "- L = L[0 : rand + 1]", "- else:", "- L = L[rand : len(L)]", "- if X in L:", "- print(X)", "- elif len(L) == 1:", "- print((L[0]))", "+ while j > 0:", "+ j -= 1", "+ if j not in P:", "+ break", "+ if i - X >= X - j:", "+ print(j)", "- if abs(L[0] - X) > abs(L[1] - X):", "- print((L[1]))", "- else:", "- print((L[0]))", "+ print(i)" ]
false
0.039749
0.03884
1.023393
[ "s936886499", "s939128598" ]
u112364985
p02608
python
s368866572
s036079297
520
450
9,780
9,648
Accepted
Accepted
13.46
n=int(eval(input())) l=[0]*(10**5) for x in range(1,101): for y in range(1,101): for z in range(1,101): l[(x*x+y*y+z*z+x*y+y*z+z*x)-1]+=1 for i in range(n): print((l[i]))
n=int(eval(input())) l=[0]*(6*(10**4)) for x in range(1,101): for y in range(1,101): for z in range(1,101): l[(x*x+y*y+z*z+x*y+y*z+z*x)-1]+=1 for i in range(n): print((l[i]))
8
8
197
202
n = int(eval(input())) l = [0] * (10**5) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): l[(x * x + y * y + z * z + x * y + y * z + z * x) - 1] += 1 for i in range(n): print((l[i]))
n = int(eval(input())) l = [0] * (6 * (10**4)) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): l[(x * x + y * y + z * z + x * y + y * z + z * x) - 1] += 1 for i in range(n): print((l[i]))
false
0
[ "-l = [0] * (10**5)", "+l = [0] * (6 * (10**4))" ]
false
0.687157
1.274321
0.539234
[ "s368866572", "s036079297" ]
u508732591
p02315
python
s418934533
s356966117
580
370
6,664
6,664
Accepted
Accepted
36.21
N,W = list(map(int, input().split())) dp = [0]*(W+1) temp = [0]*(W+1) for i in range(1,N+1): v,w = list(map(int,input().split())) for j in range(w, W+1): dp[j] = max(temp[j-w]+v,temp[j]) temp[0:W+1] = dp[0:W+1] print((dp[W]))
N,W = list(map(int, input().split())) dp = [0]*(W+1) temp = [0]*(W+1) for i in range(1,N+1): v,w = list(map(int,input().split())) for j in range(w, W+1): x = v+temp[j-w] if x > temp[j]: dp[j] = x temp[0:W+1] = dp[0:W+1] print((dp[W]))
11
13
243
263
N, W = list(map(int, input().split())) dp = [0] * (W + 1) temp = [0] * (W + 1) for i in range(1, N + 1): v, w = list(map(int, input().split())) for j in range(w, W + 1): dp[j] = max(temp[j - w] + v, temp[j]) temp[0 : W + 1] = dp[0 : W + 1] print((dp[W]))
N, W = list(map(int, input().split())) dp = [0] * (W + 1) temp = [0] * (W + 1) for i in range(1, N + 1): v, w = list(map(int, input().split())) for j in range(w, W + 1): x = v + temp[j - w] if x > temp[j]: dp[j] = x temp[0 : W + 1] = dp[0 : W + 1] print((dp[W]))
false
15.384615
[ "- dp[j] = max(temp[j - w] + v, temp[j])", "+ x = v + temp[j - w]", "+ if x > temp[j]:", "+ dp[j] = x" ]
false
0.111088
0.046406
2.393812
[ "s418934533", "s356966117" ]
u061916079
p03966
python
s064212933
s731183231
160
21
12,736
3,060
Accepted
Accepted
86.88
# -*- coding: utf-8 -*- import math import sys import itertools import numpy as np import functools import collections mo = 1000000007 r = range n = int(eval(input())) x, y = list(map(int, input().split())) for i in range(n-1): a, b = list(map(int, input().split())) k = max((x-1)//a+1, (y-1)//b+1) x, y = k * a, k * b print((x+y))
n = int(eval(input())) x, y = list(map(int, input().split())) for i in range(n-1): a, b = list(map(int, input().split())) k = max((x-1)//a+1, (y-1)//b+1) x, y = k * a, k * b print((x+y))
18
8
343
186
# -*- coding: utf-8 -*- import math import sys import itertools import numpy as np import functools import collections mo = 1000000007 r = range n = int(eval(input())) x, y = list(map(int, input().split())) for i in range(n - 1): a, b = list(map(int, input().split())) k = max((x - 1) // a + 1, (y - 1) // b + 1) x, y = k * a, k * b print((x + y))
n = int(eval(input())) x, y = list(map(int, input().split())) for i in range(n - 1): a, b = list(map(int, input().split())) k = max((x - 1) // a + 1, (y - 1) // b + 1) x, y = k * a, k * b print((x + y))
false
55.555556
[ "-# -*- coding: utf-8 -*-", "-import math", "-import sys", "-import itertools", "-import numpy as np", "-import functools", "-import collections", "-", "-mo = 1000000007", "-r = range" ]
false
0.119449
0.037557
3.180466
[ "s064212933", "s731183231" ]
u261103969
p02753
python
s639032712
s056118605
182
17
38,496
2,940
Accepted
Accepted
90.66
# import bisect # from collections import Counter, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): s = input() ss = set(s) print('Yes') if len(ss) == 2 else print('No') if __name__ == '__main__': main()
s = eval(input()) if s == "AAA" or s == "BBB": print("No") else: print("Yes")
26
6
513
85
# import bisect # from collections import Counter, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): s = input() ss = set(s) print("Yes") if len(ss) == 2 else print("No") if __name__ == "__main__": main()
s = eval(input()) if s == "AAA" or s == "BBB": print("No") else: print("Yes")
false
76.923077
[ "-# import bisect", "-# from collections import Counter, deque", "-# import copy", "-# from heapq import heappush, heappop, heapify", "-# from fractions import gcd", "-# import itertools", "-# from operator import attrgetter, itemgetter", "-# import math", "-import sys", "-", "-# import numpy as np", "-ipti = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- s = input()", "- ss = set(s)", "- print(\"Yes\") if len(ss) == 2 else print(\"No\")", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+s = eval(input())", "+if s == \"AAA\" or s == \"BBB\":", "+ print(\"No\")", "+else:", "+ print(\"Yes\")" ]
false
0.076185
0.038606
1.973376
[ "s639032712", "s056118605" ]
u467957734
p02682
python
s289695819
s019340306
26
21
9,180
9,176
Accepted
Accepted
19.23
a, b, c, k = list(map(int, input().split(' '))) if a+b>k: print(k) else: if a+b+c<=k: print((a-c)) else: print((a-(k-(a+b))))
a, b, c, k = list(map(int, input().split(' '))) if a+b>k: print(k) elif a+b+c<=k: print((a-c)) else: print((a-(k-(a+b))))
8
7
156
135
a, b, c, k = list(map(int, input().split(" "))) if a + b > k: print(k) else: if a + b + c <= k: print((a - c)) else: print((a - (k - (a + b))))
a, b, c, k = list(map(int, input().split(" "))) if a + b > k: print(k) elif a + b + c <= k: print((a - c)) else: print((a - (k - (a + b))))
false
12.5
[ "+elif a + b + c <= k:", "+ print((a - c))", "- if a + b + c <= k:", "- print((a - c))", "- else:", "- print((a - (k - (a + b))))", "+ print((a - (k - (a + b))))" ]
false
0.038551
0.04246
0.907947
[ "s289695819", "s019340306" ]
u948524308
p03157
python
s650246840
s241274589
706
438
232,724
24,960
Accepted
Accepted
37.96
import sys sys.setrecursionlimit(1000000) H,W=list(map(int,input().split())) S=[] for i in range(H): S.append(eval(input())) def DFS(h,w,black,white,m): black,white=BorW(h,w,black,white) step=[[0,1],[0,-1],[1,0],[-1,0]] seen[h][w]=1 for dh,dw in step: nh=h+dh nw=w+dw if 0<=nh<H and 0<=nw<W: if seen[nh][nw]==0 and m!=S[nh][nw]: seen[nh][nw]=1 black,white=DFS(nh,nw,black,white,S[nh][nw]) return black,white def BorW(h,w,black,white): if S[h][w]=="#": black+=1 else: white+=1 return black,white seen=[[0]*W for _ in range(H)] L=[] for h in range(H): for w in range(W): black=0 white=0 if seen[h][w]==0: black,white=DFS(h,w,black,white,S[h][w]) L.append([black,white]) ans=0 for b,w in L: ans+=b*w print(ans)
from collections import deque H,W=list(map(int,input().split())) S=[] for i in range(H): S.append(eval(input())) q=deque([]) T=[] seen=[[0]*W for _ in range(H)] step=[[0,1],[0,-1],[1,0],[-1,0]] for h in range(H): for w in range(W): temp=[] if seen[h][w]==0: temp.append(S[h][w]) seen[h][w]=1 q.append([h,w,S[h][w]]) while q: oh,ow,m=q.popleft() for dh,dw in step: if 0<=oh+dh<H and 0<=ow+dw<W: if seen[oh+dh][ow+dw]==0 and m!=S[oh+dh][ow+dw]: temp.append(S[oh+dh][ow+dw]) seen[oh+dh][ow+dw]=1 q.append([oh+dh,ow+dw,S[oh+dh][ow+dw]]) T.append(temp) ans=0 for i in range(len(T)): black=0 white=0 for s in T[i]: if s=="#": black+=1 else: white+=1 ans+=black*white print(ans)
47
42
928
1,007
import sys sys.setrecursionlimit(1000000) H, W = list(map(int, input().split())) S = [] for i in range(H): S.append(eval(input())) def DFS(h, w, black, white, m): black, white = BorW(h, w, black, white) step = [[0, 1], [0, -1], [1, 0], [-1, 0]] seen[h][w] = 1 for dh, dw in step: nh = h + dh nw = w + dw if 0 <= nh < H and 0 <= nw < W: if seen[nh][nw] == 0 and m != S[nh][nw]: seen[nh][nw] = 1 black, white = DFS(nh, nw, black, white, S[nh][nw]) return black, white def BorW(h, w, black, white): if S[h][w] == "#": black += 1 else: white += 1 return black, white seen = [[0] * W for _ in range(H)] L = [] for h in range(H): for w in range(W): black = 0 white = 0 if seen[h][w] == 0: black, white = DFS(h, w, black, white, S[h][w]) L.append([black, white]) ans = 0 for b, w in L: ans += b * w print(ans)
from collections import deque H, W = list(map(int, input().split())) S = [] for i in range(H): S.append(eval(input())) q = deque([]) T = [] seen = [[0] * W for _ in range(H)] step = [[0, 1], [0, -1], [1, 0], [-1, 0]] for h in range(H): for w in range(W): temp = [] if seen[h][w] == 0: temp.append(S[h][w]) seen[h][w] = 1 q.append([h, w, S[h][w]]) while q: oh, ow, m = q.popleft() for dh, dw in step: if 0 <= oh + dh < H and 0 <= ow + dw < W: if seen[oh + dh][ow + dw] == 0 and m != S[oh + dh][ow + dw]: temp.append(S[oh + dh][ow + dw]) seen[oh + dh][ow + dw] = 1 q.append([oh + dh, ow + dw, S[oh + dh][ow + dw]]) T.append(temp) ans = 0 for i in range(len(T)): black = 0 white = 0 for s in T[i]: if s == "#": black += 1 else: white += 1 ans += black * white print(ans)
false
10.638298
[ "-import sys", "+from collections import deque", "-sys.setrecursionlimit(1000000)", "-", "-", "-def DFS(h, w, black, white, m):", "- black, white = BorW(h, w, black, white)", "- step = [[0, 1], [0, -1], [1, 0], [-1, 0]]", "- seen[h][w] = 1", "- for dh, dw in step:", "- nh = h + dh", "- nw = w + dw", "- if 0 <= nh < H and 0 <= nw < W:", "- if seen[nh][nw] == 0 and m != S[nh][nw]:", "- seen[nh][nw] = 1", "- black, white = DFS(nh, nw, black, white, S[nh][nw])", "- return black, white", "-", "-", "-def BorW(h, w, black, white):", "- if S[h][w] == \"#\":", "- black += 1", "- else:", "- white += 1", "- return black, white", "-", "-", "+q = deque([])", "+T = []", "-L = []", "+step = [[0, 1], [0, -1], [1, 0], [-1, 0]]", "- black = 0", "- white = 0", "+ temp = []", "- black, white = DFS(h, w, black, white, S[h][w])", "- L.append([black, white])", "+ temp.append(S[h][w])", "+ seen[h][w] = 1", "+ q.append([h, w, S[h][w]])", "+ while q:", "+ oh, ow, m = q.popleft()", "+ for dh, dw in step:", "+ if 0 <= oh + dh < H and 0 <= ow + dw < W:", "+ if seen[oh + dh][ow + dw] == 0 and m != S[oh + dh][ow + dw]:", "+ temp.append(S[oh + dh][ow + dw])", "+ seen[oh + dh][ow + dw] = 1", "+ q.append([oh + dh, ow + dw, S[oh + dh][ow + dw]])", "+ T.append(temp)", "-for b, w in L:", "- ans += b * w", "+for i in range(len(T)):", "+ black = 0", "+ white = 0", "+ for s in T[i]:", "+ if s == \"#\":", "+ black += 1", "+ else:", "+ white += 1", "+ ans += black * white" ]
false
0.090232
0.199985
0.451192
[ "s650246840", "s241274589" ]
u759412327
p02923
python
s282520781
s856600206
79
73
14,224
20,492
Accepted
Accepted
7.59
N = int(eval(input())) H = list(map(int,input().split())) n = 0 a = 0 for i in range(N-1): if H[i+1]<=H[i]: n+=1 else: a=max(a,n) n=0 print((max(a,n)))
N = int(eval(input())) H = list(map(int,input().split())) ans = [0] for h1,h2 in zip(H,H[1:]): if h2<=h1: ans+=[ans[-1]+1] else: ans+=[0] print((max(ans)))
13
11
173
171
N = int(eval(input())) H = list(map(int, input().split())) n = 0 a = 0 for i in range(N - 1): if H[i + 1] <= H[i]: n += 1 else: a = max(a, n) n = 0 print((max(a, n)))
N = int(eval(input())) H = list(map(int, input().split())) ans = [0] for h1, h2 in zip(H, H[1:]): if h2 <= h1: ans += [ans[-1] + 1] else: ans += [0] print((max(ans)))
false
15.384615
[ "-n = 0", "-a = 0", "-for i in range(N - 1):", "- if H[i + 1] <= H[i]:", "- n += 1", "+ans = [0]", "+for h1, h2 in zip(H, H[1:]):", "+ if h2 <= h1:", "+ ans += [ans[-1] + 1]", "- a = max(a, n)", "- n = 0", "-print((max(a, n)))", "+ ans += [0]", "+print((max(ans)))" ]
false
0.007725
0.087808
0.087981
[ "s282520781", "s856600206" ]
u306516971
p02813
python
s657108206
s079113220
55
43
10,228
10,228
Accepted
Accepted
21.82
n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) A = list(range(1, n+1)) from itertools import permutations li=[] for i in permutations(A, n): li.extend([list(i)]) for i, v in enumerate(li): if li[i] == p: s = i if li[i] == q: t = i print((abs(s-t)))
from itertools import permutations N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) R = [i for i in range(1, N+1)] li = [] for i in permutations(R, N): li.append(list(i)) print((abs(li.index(P) - li.index(Q))))
18
13
341
268
n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) A = list(range(1, n + 1)) from itertools import permutations li = [] for i in permutations(A, n): li.extend([list(i)]) for i, v in enumerate(li): if li[i] == p: s = i if li[i] == q: t = i print((abs(s - t)))
from itertools import permutations N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) R = [i for i in range(1, N + 1)] li = [] for i in permutations(R, N): li.append(list(i)) print((abs(li.index(P) - li.index(Q))))
false
27.777778
[ "-n = int(eval(input()))", "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-A = list(range(1, n + 1))", "+N = int(eval(input()))", "+P = list(map(int, input().split()))", "+Q = list(map(int, input().split()))", "+R = [i for i in range(1, N + 1)]", "-for i in permutations(A, n):", "- li.extend([list(i)])", "-for i, v in enumerate(li):", "- if li[i] == p:", "- s = i", "- if li[i] == q:", "- t = i", "-print((abs(s - t)))", "+for i in permutations(R, N):", "+ li.append(list(i))", "+print((abs(li.index(P) - li.index(Q))))" ]
false
0.046311
0.048275
0.959323
[ "s657108206", "s079113220" ]
u131811591
p02361
python
s996304575
s360507794
3,750
2,590
141,016
139,716
Accepted
Accepted
30.93
import sys import queue class Dijkstra: class Edge: def __init__(self, end, cost): self.to = end self.cost = cost def __init__(self, node_size, inf): self._node = node_size self._graph = [[] for _ in range(self._node)] self.inf = inf self.dist = [self.inf for _ in range(self._node)] def add_edge(self, st, ed, cs): self._graph[st].append(self.Edge(ed, cs)) def solve(self, start): que = queue.PriorityQueue() self.dist[start] = 0 que.put((0, start)) while not que.empty(): cur_cost, cur_vertex = que.get() if self.dist[cur_vertex] < cur_cost: continue for e in self._graph[cur_vertex]: if self.dist[e.to] > cur_cost + e.cost: self.dist[e.to] = cur_cost + e.cost que.put((self.dist[e.to], e.to)) if __name__ == '__main__': V, E, r = list(map(int, sys.stdin.readline().split())) dk = Dijkstra(V, 10 ** 10) for i in range(E): s, t, d = list(map(int, sys.stdin.readline().split())) dk.add_edge(s, t, d) dk.solve(r) for value in dk.dist: if value == dk.inf: print("INF") else: print(value)
import sys from heapq import heappush, heappop class Dijkstra: class Edge: def __init__(self, end, cost): self.to = end self.cost = cost def __init__(self, node_size, inf): self._node = node_size self._graph = [[] for _ in range(self._node)] self.inf = inf self.dist = [self.inf for _ in range(self._node)] def add_edge(self, st, ed, cs): self._graph[st].append(self.Edge(ed, cs)) def solve(self, start): que = [] self.dist[start] = 0 heappush(que, (0, start)) while que: cur_cost, cur_vertex = heappop(que) if self.dist[cur_vertex] < cur_cost: continue for e in self._graph[cur_vertex]: if self.dist[e.to] > cur_cost + e.cost: self.dist[e.to] = cur_cost + e.cost heappush(que, (self.dist[e.to], e.to)) if __name__ == '__main__': V, E, r = list(map(int, sys.stdin.readline().split())) dk = Dijkstra(V, 10 ** 10) for i in range(E): s, t, d = list(map(int, sys.stdin.readline().split())) dk.add_edge(s, t, d) dk.solve(r) for value in dk.dist: if value == dk.inf: sys.stdout.write("INF\n") else: sys.stdout.write("%s\n" % value)
45
45
1,329
1,369
import sys import queue class Dijkstra: class Edge: def __init__(self, end, cost): self.to = end self.cost = cost def __init__(self, node_size, inf): self._node = node_size self._graph = [[] for _ in range(self._node)] self.inf = inf self.dist = [self.inf for _ in range(self._node)] def add_edge(self, st, ed, cs): self._graph[st].append(self.Edge(ed, cs)) def solve(self, start): que = queue.PriorityQueue() self.dist[start] = 0 que.put((0, start)) while not que.empty(): cur_cost, cur_vertex = que.get() if self.dist[cur_vertex] < cur_cost: continue for e in self._graph[cur_vertex]: if self.dist[e.to] > cur_cost + e.cost: self.dist[e.to] = cur_cost + e.cost que.put((self.dist[e.to], e.to)) if __name__ == "__main__": V, E, r = list(map(int, sys.stdin.readline().split())) dk = Dijkstra(V, 10**10) for i in range(E): s, t, d = list(map(int, sys.stdin.readline().split())) dk.add_edge(s, t, d) dk.solve(r) for value in dk.dist: if value == dk.inf: print("INF") else: print(value)
import sys from heapq import heappush, heappop class Dijkstra: class Edge: def __init__(self, end, cost): self.to = end self.cost = cost def __init__(self, node_size, inf): self._node = node_size self._graph = [[] for _ in range(self._node)] self.inf = inf self.dist = [self.inf for _ in range(self._node)] def add_edge(self, st, ed, cs): self._graph[st].append(self.Edge(ed, cs)) def solve(self, start): que = [] self.dist[start] = 0 heappush(que, (0, start)) while que: cur_cost, cur_vertex = heappop(que) if self.dist[cur_vertex] < cur_cost: continue for e in self._graph[cur_vertex]: if self.dist[e.to] > cur_cost + e.cost: self.dist[e.to] = cur_cost + e.cost heappush(que, (self.dist[e.to], e.to)) if __name__ == "__main__": V, E, r = list(map(int, sys.stdin.readline().split())) dk = Dijkstra(V, 10**10) for i in range(E): s, t, d = list(map(int, sys.stdin.readline().split())) dk.add_edge(s, t, d) dk.solve(r) for value in dk.dist: if value == dk.inf: sys.stdout.write("INF\n") else: sys.stdout.write("%s\n" % value)
false
0
[ "-import queue", "+from heapq import heappush, heappop", "- que = queue.PriorityQueue()", "+ que = []", "- que.put((0, start))", "- while not que.empty():", "- cur_cost, cur_vertex = que.get()", "+ heappush(que, (0, start))", "+ while que:", "+ cur_cost, cur_vertex = heappop(que)", "- que.put((self.dist[e.to], e.to))", "+ heappush(que, (self.dist[e.to], e.to))", "- print(\"INF\")", "+ sys.stdout.write(\"INF\\n\")", "- print(value)", "+ sys.stdout.write(\"%s\\n\" % value)" ]
false
0.041105
0.037512
1.095794
[ "s996304575", "s360507794" ]
u164727245
p02691
python
s011680723
s156078276
244
160
65,956
42,996
Accepted
Accepted
34.43
# coding: utf-8 from bisect import bisect_left from collections import defaultdict def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) ret = 0 X = defaultdict(list) for i, a in enumerate(A): X[a+i].append(i) for j, a in enumerate(A): if 0 <= j-a: ret += bisect_left(X[j-a], j) return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) ret = 0 X = defaultdict(int) for i, a in enumerate(A): X[a+i] += 1 if 0 <= i-a: ret += X[i-a] return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
23
21
485
400
# coding: utf-8 from bisect import bisect_left from collections import defaultdict def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) ret = 0 X = defaultdict(list) for i, a in enumerate(A): X[a + i].append(i) for j, a in enumerate(A): if 0 <= j - a: ret += bisect_left(X[j - a], j) return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) ret = 0 X = defaultdict(int) for i, a in enumerate(A): X[a + i] += 1 if 0 <= i - a: ret += X[i - a] return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
8.695652
[ "-from bisect import bisect_left", "- X = defaultdict(list)", "+ X = defaultdict(int)", "- X[a + i].append(i)", "- for j, a in enumerate(A):", "- if 0 <= j - a:", "- ret += bisect_left(X[j - a], j)", "+ X[a + i] += 1", "+ if 0 <= i - a:", "+ ret += X[i - a]" ]
false
0.037472
0.045011
0.8325
[ "s011680723", "s156078276" ]
u497046426
p03665
python
s492378317
s398736223
23
17
3,572
2,940
Accepted
Accepted
26.09
from functools import reduce def binom(n, r): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n numerator = [n - r + 1 + k for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n denominator = [1+ k for k in range(r)] # 1*2*...*(r-1)*r # reduce prod(numerator)//prod(denominator) for p in range(2, r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1, r, p): numerator[k - offset] //= pivot denominator[k] //= pivot # calculate nCr return reduce(lambda x, y: x*y, numerator) N, P = list(map(int, input().split())) *A, = list(map(int, input().split())) even = 0; odd = 0; for a in A: if a % 2 == 0: even += 1 else: odd += 1 ans = 2**even temp = 0 if P == 0: for i in range(0, odd+1, 2): temp += binom(odd, i) else: for i in range(1, odd+1, 2): temp += binom(odd, i) ans *= temp print(ans)
N, P = list(map(int, input().split())) *A, = list(map(int, input().split())) even = 0 for a in A: if a % 2 == 0: even += 1 if even == N: print((2**N if P == 0 else 0)) else: print((2**(N-1)))
42
10
1,079
204
from functools import reduce def binom(n, r): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n numerator = [n - r + 1 + k for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n denominator = [1 + k for k in range(r)] # 1*2*...*(r-1)*r # reduce prod(numerator)//prod(denominator) for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] //= pivot denominator[k] //= pivot # calculate nCr return reduce(lambda x, y: x * y, numerator) N, P = list(map(int, input().split())) (*A,) = list(map(int, input().split())) even = 0 odd = 0 for a in A: if a % 2 == 0: even += 1 else: odd += 1 ans = 2**even temp = 0 if P == 0: for i in range(0, odd + 1, 2): temp += binom(odd, i) else: for i in range(1, odd + 1, 2): temp += binom(odd, i) ans *= temp print(ans)
N, P = list(map(int, input().split())) (*A,) = list(map(int, input().split())) even = 0 for a in A: if a % 2 == 0: even += 1 if even == N: print((2**N if P == 0 else 0)) else: print((2 ** (N - 1)))
false
76.190476
[ "-from functools import reduce", "-", "-", "-def binom(n, r):", "- if n < r or n < 0 or r < 0:", "- return 0", "- if n - r < r:", "- r = n - r", "- if r == 0:", "- return 1", "- elif r == 1:", "- return n", "- numerator = [n - r + 1 + k for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n", "- denominator = [1 + k for k in range(r)] # 1*2*...*(r-1)*r", "- # reduce prod(numerator)//prod(denominator)", "- for p in range(2, r + 1):", "- pivot = denominator[p - 1]", "- if pivot > 1:", "- offset = (n - r) % p", "- for k in range(p - 1, r, p):", "- numerator[k - offset] //= pivot", "- denominator[k] //= pivot", "- # calculate nCr", "- return reduce(lambda x, y: x * y, numerator)", "-", "-", "-odd = 0", "- else:", "- odd += 1", "-ans = 2**even", "-temp = 0", "-if P == 0:", "- for i in range(0, odd + 1, 2):", "- temp += binom(odd, i)", "+if even == N:", "+ print((2**N if P == 0 else 0))", "- for i in range(1, odd + 1, 2):", "- temp += binom(odd, i)", "-ans *= temp", "-print(ans)", "+ print((2 ** (N - 1)))" ]
false
0.069255
0.077608
0.892364
[ "s492378317", "s398736223" ]
u130900604
p02792
python
s040763654
s041816618
228
190
40,428
3,064
Accepted
Accepted
16.67
n=int(eval(input())) c=[[0]*10 for i in range(10)] for i in range(1,n+1): t=str(i) c[int(t[0])][int(t[-1])]+=1 ans=0 for i in range(10): for j in range(10): ans+=c[i][j]*c[j][i] print(ans)
n=int(eval(input())) cnt=[[0 for i in range(10)] for j in range(10)] for i in range(1,n+1): s=str(i) head=int(s[0]) tail=int(s[-1]) cnt[head][tail]+=1 ans=0 for h in range(0,10): for t in range(0,10): ans+=cnt[h][t]*cnt[t][h] print(ans)
14
14
231
259
n = int(eval(input())) c = [[0] * 10 for i in range(10)] for i in range(1, n + 1): t = str(i) c[int(t[0])][int(t[-1])] += 1 ans = 0 for i in range(10): for j in range(10): ans += c[i][j] * c[j][i] print(ans)
n = int(eval(input())) cnt = [[0 for i in range(10)] for j in range(10)] for i in range(1, n + 1): s = str(i) head = int(s[0]) tail = int(s[-1]) cnt[head][tail] += 1 ans = 0 for h in range(0, 10): for t in range(0, 10): ans += cnt[h][t] * cnt[t][h] print(ans)
false
0
[ "-c = [[0] * 10 for i in range(10)]", "+cnt = [[0 for i in range(10)] for j in range(10)]", "- t = str(i)", "- c[int(t[0])][int(t[-1])] += 1", "+ s = str(i)", "+ head = int(s[0])", "+ tail = int(s[-1])", "+ cnt[head][tail] += 1", "-for i in range(10):", "- for j in range(10):", "- ans += c[i][j] * c[j][i]", "+for h in range(0, 10):", "+ for t in range(0, 10):", "+ ans += cnt[h][t] * cnt[t][h]" ]
false
0.046643
0.04947
0.942847
[ "s040763654", "s041816618" ]
u211160392
p03103
python
s671234090
s954306802
1,987
486
27,884
27,880
Accepted
Accepted
75.54
N,M = list(map(int,input().split())) AB = list(list(map(int,input().split()))for i in range(N)) AB.sort() ans = 0 while M > 0: A,B = AB.pop(0) ans += A*B M -= B ans += M*A print(ans)
N,M = list(map(int,input().split())) AB = list(list(map(int,input().split()))for i in range(N)) AB.sort() ans = 0 i = 0 while M > 0: A,B = AB[i] ans += A*B M -= B i+=1 ans += M*A print(ans)
10
12
197
210
N, M = list(map(int, input().split())) AB = list(list(map(int, input().split())) for i in range(N)) AB.sort() ans = 0 while M > 0: A, B = AB.pop(0) ans += A * B M -= B ans += M * A print(ans)
N, M = list(map(int, input().split())) AB = list(list(map(int, input().split())) for i in range(N)) AB.sort() ans = 0 i = 0 while M > 0: A, B = AB[i] ans += A * B M -= B i += 1 ans += M * A print(ans)
false
16.666667
[ "+i = 0", "- A, B = AB.pop(0)", "+ A, B = AB[i]", "+ i += 1" ]
false
0.037603
0.073364
0.512553
[ "s671234090", "s954306802" ]
u285891772
p02788
python
s673073649
s587655450
962
849
65,760
57,644
Accepted
Accepted
11.75
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, D, A = MAP() XH = [LIST() for _ in range(N)] XH.sort(key = lambda x: x[0]) X, H = list(zip(*XH)) right = [0]*N for i, x in enumerate(X): right[i] = bisect(X, x+2*D) damage = [0]*(N+1) ans = 0 for i, (X, H) in enumerate(XH): if i != 0: damage[i] += damage[i-1] H -= damage[i] if 0 < H: n = -(-H//A) ans += n d = A*n damage[i] += d damage[right[i]] -= d print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, D, A = MAP() XH = [LIST() for _ in range(N)] XH.sort(key = lambda x: x[0]) X = [XH[i][0] for i in range(N)] H = [XH[i][1] for i in range(N)] ans = 0 imos = [0]*(N+1) tmp = 0 for i in range(N): x, h = XH[i] tmp += imos[i] left = h-tmp if 0 < left: cnt = -(-left//A) damage = A*cnt idx = bisect(X, x+2*D) tmp += damage imos[idx] -= damage ans += cnt print(ans)
48
49
1,404
1,408
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 N, D, A = MAP() XH = [LIST() for _ in range(N)] XH.sort(key=lambda x: x[0]) X, H = list(zip(*XH)) right = [0] * N for i, x in enumerate(X): right[i] = bisect(X, x + 2 * D) damage = [0] * (N + 1) ans = 0 for i, (X, H) in enumerate(XH): if i != 0: damage[i] += damage[i - 1] H -= damage[i] if 0 < H: n = -(-H // A) ans += n d = A * n damage[i] += d damage[right[i]] -= d print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 N, D, A = MAP() XH = [LIST() for _ in range(N)] XH.sort(key=lambda x: x[0]) X = [XH[i][0] for i in range(N)] H = [XH[i][1] for i in range(N)] ans = 0 imos = [0] * (N + 1) tmp = 0 for i in range(N): x, h = XH[i] tmp += imos[i] left = h - tmp if 0 < left: cnt = -(-left // A) damage = A * cnt idx = bisect(X, x + 2 * D) tmp += damage imos[idx] -= damage ans += cnt print(ans)
false
2.040816
[ "-X, H = list(zip(*XH))", "-right = [0] * N", "-for i, x in enumerate(X):", "- right[i] = bisect(X, x + 2 * D)", "-damage = [0] * (N + 1)", "+X = [XH[i][0] for i in range(N)]", "+H = [XH[i][1] for i in range(N)]", "-for i, (X, H) in enumerate(XH):", "- if i != 0:", "- damage[i] += damage[i - 1]", "- H -= damage[i]", "- if 0 < H:", "- n = -(-H // A)", "- ans += n", "- d = A * n", "- damage[i] += d", "- damage[right[i]] -= d", "+imos = [0] * (N + 1)", "+tmp = 0", "+for i in range(N):", "+ x, h = XH[i]", "+ tmp += imos[i]", "+ left = h - tmp", "+ if 0 < left:", "+ cnt = -(-left // A)", "+ damage = A * cnt", "+ idx = bisect(X, x + 2 * D)", "+ tmp += damage", "+ imos[idx] -= damage", "+ ans += cnt" ]
false
0.259269
0.090657
2.859899
[ "s673073649", "s587655450" ]
u312025627
p03252
python
s028128380
s531135279
184
97
41,840
75,696
Accepted
Accepted
47.28
def main(): S = input() T = input() from collections import defaultdict tran = defaultdict(set) rtran = defaultdict(set) for s, t in zip(S, T): tran[s].add(t) rtran[t].add(s) if all(len(v) <= 1 for v in tran.values()) and \ all(len(v) <= 1 for v in rtran.values()): print("Yes") else: print("No") if __name__ == '__main__': main()
def main(): from string import ascii_lowercase S = input() T = input() dic1 = {a: set() for a in ascii_lowercase} dic2 = {a: set() for a in ascii_lowercase} for s, t in zip(S, T): dic1[s].add(t) dic2[t].add(s) if all(len(s) <= 1 for s in dic1.values()) and\ all(len(s) <= 1 for s in dic2.values()): print("Yes") else: print("No") if __name__ == '__main__': main()
18
19
430
465
def main(): S = input() T = input() from collections import defaultdict tran = defaultdict(set) rtran = defaultdict(set) for s, t in zip(S, T): tran[s].add(t) rtran[t].add(s) if all(len(v) <= 1 for v in tran.values()) and all( len(v) <= 1 for v in rtran.values() ): print("Yes") else: print("No") if __name__ == "__main__": main()
def main(): from string import ascii_lowercase S = input() T = input() dic1 = {a: set() for a in ascii_lowercase} dic2 = {a: set() for a in ascii_lowercase} for s, t in zip(S, T): dic1[s].add(t) dic2[t].add(s) if all(len(s) <= 1 for s in dic1.values()) and all( len(s) <= 1 for s in dic2.values() ): print("Yes") else: print("No") if __name__ == "__main__": main()
false
5.263158
[ "+ from string import ascii_lowercase", "+", "- from collections import defaultdict", "-", "- tran = defaultdict(set)", "- rtran = defaultdict(set)", "+ dic1 = {a: set() for a in ascii_lowercase}", "+ dic2 = {a: set() for a in ascii_lowercase}", "- tran[s].add(t)", "- rtran[t].add(s)", "- if all(len(v) <= 1 for v in tran.values()) and all(", "- len(v) <= 1 for v in rtran.values()", "+ dic1[s].add(t)", "+ dic2[t].add(s)", "+ if all(len(s) <= 1 for s in dic1.values()) and all(", "+ len(s) <= 1 for s in dic2.values()" ]
false
0.046663
0.041165
1.133544
[ "s028128380", "s531135279" ]
u279955105
p02392
python
s881151397
s598231180
30
20
7,656
7,656
Accepted
Accepted
33.33
t = input().split() a = int(t[0]) b = int(t[1]) c = int(t[2]) if a < b and b < c: print("Yes") else : print("No")
a,b,c = list(map(int, input().split())) if (a < b) and (b < c): print("Yes") else: print("No")
8
5
122
100
t = input().split() a = int(t[0]) b = int(t[1]) c = int(t[2]) if a < b and b < c: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if (a < b) and (b < c): print("Yes") else: print("No")
false
37.5
[ "-t = input().split()", "-a = int(t[0])", "-b = int(t[1])", "-c = int(t[2])", "-if a < b and b < c:", "+a, b, c = list(map(int, input().split()))", "+if (a < b) and (b < c):" ]
false
0.122441
0.045808
2.672923
[ "s881151397", "s598231180" ]
u409757418
p02898
python
s046045620
s524749164
59
53
9,992
11,908
Accepted
Accepted
10.17
n, k = list(map(int, input().split())) hs = input().split() num = 0 for i in range(n): if int(hs[i]) >= k: num += 1 print(num)
n,k = list(map(int, input().split())) his = list(map(int, input().split())) j = 0 for i in range(n): if his[i] >= k: j += 1 print(j)
7
7
132
140
n, k = list(map(int, input().split())) hs = input().split() num = 0 for i in range(n): if int(hs[i]) >= k: num += 1 print(num)
n, k = list(map(int, input().split())) his = list(map(int, input().split())) j = 0 for i in range(n): if his[i] >= k: j += 1 print(j)
false
0
[ "-hs = input().split()", "-num = 0", "+his = list(map(int, input().split()))", "+j = 0", "- if int(hs[i]) >= k:", "- num += 1", "-print(num)", "+ if his[i] >= k:", "+ j += 1", "+print(j)" ]
false
0.046512
0.110108
0.422427
[ "s046045620", "s524749164" ]
u644907318
p02795
python
s947670476
s742086662
85
64
61,156
61,796
Accepted
Accepted
24.71
import math H = int(eval(input())) W = int(eval(input())) N = int(eval(input())) n = max(H,W) print((math.ceil(N/n)))
H = int(eval(input())) W = int(eval(input())) N = int(eval(input())) a = max(H,W) n = N//a if N%a==0: print(n) else: print((n+1))
6
9
102
125
import math H = int(eval(input())) W = int(eval(input())) N = int(eval(input())) n = max(H, W) print((math.ceil(N / n)))
H = int(eval(input())) W = int(eval(input())) N = int(eval(input())) a = max(H, W) n = N // a if N % a == 0: print(n) else: print((n + 1))
false
33.333333
[ "-import math", "-", "-n = max(H, W)", "-print((math.ceil(N / n)))", "+a = max(H, W)", "+n = N // a", "+if N % a == 0:", "+ print(n)", "+else:", "+ print((n + 1))" ]
false
0.038178
0.105776
0.360937
[ "s947670476", "s742086662" ]
u672475305
p03565
python
s282803912
s580685568
23
17
3,064
3,064
Accepted
Accepted
26.09
def check(p, s): flg = True for i in range(len(tmp)): if s[i]=='?' or p[i]=='?': continue elif s[i] == p[i]: continue elif s[i] != p[i]: flg = False return flg S = eval(input()) T = eval(input()) lst = [] for i in range(len(S)-len(T)+1): tmp = S[:i]+T+S[i+len(T):] if check(tmp, S): lst.append(tmp) if len(lst)==0: ans = 'UNRESTORABLE' else: ans_lst = [] for x in lst: ans_lst.append(x.replace('?','a')) ans = min(ans_lst) print(ans)
s = eval(input()) t = eval(input()) ans = [] for i in range(len(s)-len(t)+1): tmp = s[i:i+len(t)] flg = True for j in range(len(t)): if tmp[j]!=t[j]: if tmp[j]!='?': flg = False if flg: c = s[:i]+t+s[i+len(t):] ans.append(c.replace('?', 'a')) print(('UNRESTORABLE' if len(ans)==0 else min(ans)))
29
14
565
362
def check(p, s): flg = True for i in range(len(tmp)): if s[i] == "?" or p[i] == "?": continue elif s[i] == p[i]: continue elif s[i] != p[i]: flg = False return flg S = eval(input()) T = eval(input()) lst = [] for i in range(len(S) - len(T) + 1): tmp = S[:i] + T + S[i + len(T) :] if check(tmp, S): lst.append(tmp) if len(lst) == 0: ans = "UNRESTORABLE" else: ans_lst = [] for x in lst: ans_lst.append(x.replace("?", "a")) ans = min(ans_lst) print(ans)
s = eval(input()) t = eval(input()) ans = [] for i in range(len(s) - len(t) + 1): tmp = s[i : i + len(t)] flg = True for j in range(len(t)): if tmp[j] != t[j]: if tmp[j] != "?": flg = False if flg: c = s[:i] + t + s[i + len(t) :] ans.append(c.replace("?", "a")) print(("UNRESTORABLE" if len(ans) == 0 else min(ans)))
false
51.724138
[ "-def check(p, s):", "+s = eval(input())", "+t = eval(input())", "+ans = []", "+for i in range(len(s) - len(t) + 1):", "+ tmp = s[i : i + len(t)]", "- for i in range(len(tmp)):", "- if s[i] == \"?\" or p[i] == \"?\":", "- continue", "- elif s[i] == p[i]:", "- continue", "- elif s[i] != p[i]:", "- flg = False", "- return flg", "-", "-", "-S = eval(input())", "-T = eval(input())", "-lst = []", "-for i in range(len(S) - len(T) + 1):", "- tmp = S[:i] + T + S[i + len(T) :]", "- if check(tmp, S):", "- lst.append(tmp)", "-if len(lst) == 0:", "- ans = \"UNRESTORABLE\"", "-else:", "- ans_lst = []", "- for x in lst:", "- ans_lst.append(x.replace(\"?\", \"a\"))", "- ans = min(ans_lst)", "-print(ans)", "+ for j in range(len(t)):", "+ if tmp[j] != t[j]:", "+ if tmp[j] != \"?\":", "+ flg = False", "+ if flg:", "+ c = s[:i] + t + s[i + len(t) :]", "+ ans.append(c.replace(\"?\", \"a\"))", "+print((\"UNRESTORABLE\" if len(ans) == 0 else min(ans)))" ]
false
0.046106
0.12314
0.374419
[ "s282803912", "s580685568" ]
u889914341
p03148
python
s954974836
s367946925
451
294
19,848
19,800
Accepted
Accepted
34.81
n, k = list(map(int, input().split())) A = [] for _ in range(n): t, d = list(map(int, input().split())) A.append((d, t)) A.sort(reverse=True) X = [] Y = [] st = set() for i in range(k): d, t = A[i] if t in st: X.append(d) else: Y.append(d) st.add(t) x = sum(X) y = sum(Y) v = len(Y) ans = x + y + v ** 2 for i in range(k, n): if not X: break d, t = A[i] if t in st: continue st.add(t) x -= X.pop() y += d v += 1 ans = max(ans, x + y + v ** 2) print(ans)
import sys readline = sys.stdin.readline n, k = list(map(int, input().split())) A = [] for _ in range(n): t, d = list(map(int, readline().split())) A.append((d, t)) A.sort(reverse=True) X = [] Y = [] st = set() for i in range(k): d, t = A[i] if t in st: X.append(d) else: Y.append(d) st.add(t) x = sum(X) y = sum(Y) v = len(Y) ans = x + y + v ** 2 for i in range(k, n): if not X: break d, t = A[i] if t in st: continue st.add(t) x -= X.pop() y += d v += 1 ans = max(ans, x + y + v ** 2) print(ans)
32
34
565
611
n, k = list(map(int, input().split())) A = [] for _ in range(n): t, d = list(map(int, input().split())) A.append((d, t)) A.sort(reverse=True) X = [] Y = [] st = set() for i in range(k): d, t = A[i] if t in st: X.append(d) else: Y.append(d) st.add(t) x = sum(X) y = sum(Y) v = len(Y) ans = x + y + v**2 for i in range(k, n): if not X: break d, t = A[i] if t in st: continue st.add(t) x -= X.pop() y += d v += 1 ans = max(ans, x + y + v**2) print(ans)
import sys readline = sys.stdin.readline n, k = list(map(int, input().split())) A = [] for _ in range(n): t, d = list(map(int, readline().split())) A.append((d, t)) A.sort(reverse=True) X = [] Y = [] st = set() for i in range(k): d, t = A[i] if t in st: X.append(d) else: Y.append(d) st.add(t) x = sum(X) y = sum(Y) v = len(Y) ans = x + y + v**2 for i in range(k, n): if not X: break d, t = A[i] if t in st: continue st.add(t) x -= X.pop() y += d v += 1 ans = max(ans, x + y + v**2) print(ans)
false
5.882353
[ "+import sys", "+", "+readline = sys.stdin.readline", "- t, d = list(map(int, input().split()))", "+ t, d = list(map(int, readline().split()))" ]
false
0.057445
0.034982
1.64211
[ "s954974836", "s367946925" ]
u969850098
p03448
python
s865326320
s984557205
49
18
3,060
3,064
Accepted
Accepted
63.27
A, B, C, X = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())) cnt = 0 for n_500 in range(A + 1): for n_100 in range(B + 1): for n_50 in range(C + 1): if n_500 * 500 + n_100 * 100 + n_50 * 50 == X: cnt += 1 print(cnt)
A = int(eval(input())) # 500円玉の枚数 B = int(eval(input())) # 100円玉の枚数 C = int(eval(input())) # 50円玉の枚数 X = int(eval(input())) # 合計X円にしたい ans = 0 for a in range(min(A+1, X//500+1)): x = X - 500 * a for b in range(min(B+1, X//100+1)): xx = x - 100 * b if (xx/50).is_integer() and xx//50 <= C and xx//50 >= 0: ans += 1 print(ans)
8
14
269
367
A, B, C, X = ( int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())), ) cnt = 0 for n_500 in range(A + 1): for n_100 in range(B + 1): for n_50 in range(C + 1): if n_500 * 500 + n_100 * 100 + n_50 * 50 == X: cnt += 1 print(cnt)
A = int(eval(input())) # 500円玉の枚数 B = int(eval(input())) # 100円玉の枚数 C = int(eval(input())) # 50円玉の枚数 X = int(eval(input())) # 合計X円にしたい ans = 0 for a in range(min(A + 1, X // 500 + 1)): x = X - 500 * a for b in range(min(B + 1, X // 100 + 1)): xx = x - 100 * b if (xx / 50).is_integer() and xx // 50 <= C and xx // 50 >= 0: ans += 1 print(ans)
false
42.857143
[ "-A, B, C, X = (", "- int(eval(input())),", "- int(eval(input())),", "- int(eval(input())),", "- int(eval(input())),", "-)", "-cnt = 0", "-for n_500 in range(A + 1):", "- for n_100 in range(B + 1):", "- for n_50 in range(C + 1):", "- if n_500 * 500 + n_100 * 100 + n_50 * 50 == X:", "- cnt += 1", "-print(cnt)", "+A = int(eval(input())) # 500円玉の枚数", "+B = int(eval(input())) # 100円玉の枚数", "+C = int(eval(input())) # 50円玉の枚数", "+X = int(eval(input())) # 合計X円にしたい", "+ans = 0", "+for a in range(min(A + 1, X // 500 + 1)):", "+ x = X - 500 * a", "+ for b in range(min(B + 1, X // 100 + 1)):", "+ xx = x - 100 * b", "+ if (xx / 50).is_integer() and xx // 50 <= C and xx // 50 >= 0:", "+ ans += 1", "+print(ans)" ]
false
0.058642
0.053608
1.093897
[ "s865326320", "s984557205" ]
u514118270
p03796
python
s643598638
s036135083
268
100
59,116
77,420
Accepted
Accepted
62.69
import sys import math import itertools from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 def fact(n,mod): f = 1 for m in range(1,n + 1): f *= m f %= mod return f mod = 10**9+7 N = i() print((fact(N,mod)))
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) INF = 10**9 mod = 10**9+7 def fact(n,mod): f = 1 for m in range(1,n + 1): f *= m f %= mod return f N = i() print((fact(N,mod)))
25
27
590
605
import sys import math import itertools from copy import copy from collections import deque, Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int, input().split())) def L(): return list(input().split()) def l(): return list(map(int, input().split())) def lcm(a, b): return a * b // math.gcd(a, b) sys.setrecursionlimit(10**9) mod = 10**9 + 7 def fact(n, mod): f = 1 for m in range(1, n + 1): f *= m f %= mod return f mod = 10**9 + 7 N = i() print((fact(N, mod)))
import sys import math import itertools import bisect from copy import copy from collections import deque, Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int, input().split())) def L(): return list(input().split()) def l(): return list(map(int, input().split())) def lcm(a, b): return a * b // math.gcd(a, b) sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9 + 7 def fact(n, mod): f = 1 for m in range(1, n + 1): f *= m f %= mod return f N = i() print((fact(N, mod)))
false
7.407407
[ "+import bisect", "+INF = 10**9", "-mod = 10**9 + 7" ]
false
0.130074
0.047057
2.764146
[ "s643598638", "s036135083" ]
u797673668
p02315
python
s369479151
s628403452
560
400
7,876
7,864
Accepted
Accepted
28.57
n, cap = list(map(int, input().split())) dp = [None] * (cap + 1) dp[0] = 0 for _ in range(n): v, w = list(map(int, input().split())) for k in range(cap - w, -1, -1): tmp_before_v = dp[k] if tmp_before_v == None: continue tmp_after_v, new_v = dp[k + w], tmp_before_v + v if tmp_after_v == None or tmp_after_v < new_v: dp[k + w] = new_v print((max([_f for _f in dp if _f])))
n, cap = list(map(int, input().split())) dp = [0] * (cap + 1) for _ in range(n): v, w = list(map(int, input().split())) for k in range(cap - w, -1, -1): new_v = dp[k] + v if dp[k + w] < new_v: dp[k + w] = new_v print((max(dp)))
15
11
431
261
n, cap = list(map(int, input().split())) dp = [None] * (cap + 1) dp[0] = 0 for _ in range(n): v, w = list(map(int, input().split())) for k in range(cap - w, -1, -1): tmp_before_v = dp[k] if tmp_before_v == None: continue tmp_after_v, new_v = dp[k + w], tmp_before_v + v if tmp_after_v == None or tmp_after_v < new_v: dp[k + w] = new_v print((max([_f for _f in dp if _f])))
n, cap = list(map(int, input().split())) dp = [0] * (cap + 1) for _ in range(n): v, w = list(map(int, input().split())) for k in range(cap - w, -1, -1): new_v = dp[k] + v if dp[k + w] < new_v: dp[k + w] = new_v print((max(dp)))
false
26.666667
[ "-dp = [None] * (cap + 1)", "-dp[0] = 0", "+dp = [0] * (cap + 1)", "- tmp_before_v = dp[k]", "- if tmp_before_v == None:", "- continue", "- tmp_after_v, new_v = dp[k + w], tmp_before_v + v", "- if tmp_after_v == None or tmp_after_v < new_v:", "+ new_v = dp[k] + v", "+ if dp[k + w] < new_v:", "-print((max([_f for _f in dp if _f])))", "+print((max(dp)))" ]
false
0.039569
0.034879
1.134462
[ "s369479151", "s628403452" ]
u551857719
p04031
python
s081568551
s257853811
32
29
9,164
9,168
Accepted
Accepted
9.38
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def _main(): eval(input()) an = list(get_ints()) t = 0 old = 1000000000 while 1: ans = sq(t, an) g = sq(t+1, an) - sq(t, an) t -= g / abs(g) if old > ans: old = ans else: break print((int(old))) def sq(t, an): ans = 0 for ai in an: ans += pow(ai - t, 2) return ans if __name__ == "__main__": _main()
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def _main(): eval(input()) an = list(get_ints()) t = 0 old = 1000000000 while 1: ans = sq(t, an) g = sq(t+1, an) - ans t -= g / abs(g) if old > ans: old = ans else: break print((int(old))) def sq(t, an): ans = 0 for ai in an: ans += pow(ai - t, 2) return ans if __name__ == "__main__": _main()
36
36
576
570
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def _main(): eval(input()) an = list(get_ints()) t = 0 old = 1000000000 while 1: ans = sq(t, an) g = sq(t + 1, an) - sq(t, an) t -= g / abs(g) if old > ans: old = ans else: break print((int(old))) def sq(t, an): ans = 0 for ai in an: ans += pow(ai - t, 2) return ans if __name__ == "__main__": _main()
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def _main(): eval(input()) an = list(get_ints()) t = 0 old = 1000000000 while 1: ans = sq(t, an) g = sq(t + 1, an) - ans t -= g / abs(g) if old > ans: old = ans else: break print((int(old))) def sq(t, an): ans = 0 for ai in an: ans += pow(ai - t, 2) return ans if __name__ == "__main__": _main()
false
0
[ "- g = sq(t + 1, an) - sq(t, an)", "+ g = sq(t + 1, an) - ans" ]
false
0.04665
0.047351
0.985199
[ "s081568551", "s257853811" ]
u562935282
p02882
python
s271767678
s354398949
168
17
40,368
3,064
Accepted
Accepted
89.88
# import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split()) from math import atan, degrees a, b, x = list(map(int, input().split())) # 三角柱 w = x * 2 / (a * b) if 0 <= w <= a: print((degrees(atan(b / w)))) exit() # 台形柱 h = x * 2 / (a ** 2) - b print((degrees(atan((b - h) / a))))
# https://img.atcoder.jp/abc144/editorial.pdf def main(): from math import pi, tan, radians a, b, x = list(map(int, input().split())) def volume(theta: float): """傾けた直方体に存在できる水の体積 水面を地面に対し平行にした図を描き tanを用いると計算できる""" theta = radians(theta) if a * tan(theta) <= b: # 台形 return a * a * b - a * a * a * tan(theta) / 2 else: # 三角形 return a * b * b * tan(pi / 2 - theta) / 2 def is_ok(theta): return volume(theta) >= x def binary_search(): small, large = 0, 90 for _ in range(30): mid = (small + large) / 2 if is_ok(mid): small = mid else: large = mid return small ret = binary_search() print(ret) if __name__ == '__main__': main()
23
36
377
868
# import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split()) from math import atan, degrees a, b, x = list(map(int, input().split())) # 三角柱 w = x * 2 / (a * b) if 0 <= w <= a: print((degrees(atan(b / w)))) exit() # 台形柱 h = x * 2 / (a**2) - b print((degrees(atan((b - h) / a))))
# https://img.atcoder.jp/abc144/editorial.pdf def main(): from math import pi, tan, radians a, b, x = list(map(int, input().split())) def volume(theta: float): """傾けた直方体に存在できる水の体積 水面を地面に対し平行にした図を描き tanを用いると計算できる""" theta = radians(theta) if a * tan(theta) <= b: # 台形 return a * a * b - a * a * a * tan(theta) / 2 else: # 三角形 return a * b * b * tan(pi / 2 - theta) / 2 def is_ok(theta): return volume(theta) >= x def binary_search(): small, large = 0, 90 for _ in range(30): mid = (small + large) / 2 if is_ok(mid): small = mid else: large = mid return small ret = binary_search() print(ret) if __name__ == "__main__": main()
false
36.111111
[ "-# import sys", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# input = sys.stdin.readline", "-# rstrip()", "-# int(input())", "-# map(int, input().split())", "-from math import atan, degrees", "+# https://img.atcoder.jp/abc144/editorial.pdf", "+def main():", "+ from math import pi, tan, radians", "-a, b, x = list(map(int, input().split()))", "-# 三角柱", "-w = x * 2 / (a * b)", "-if 0 <= w <= a:", "- print((degrees(atan(b / w))))", "- exit()", "-# 台形柱", "-h = x * 2 / (a**2) - b", "-print((degrees(atan((b - h) / a))))", "+ a, b, x = list(map(int, input().split()))", "+", "+ def volume(theta: float):", "+ \"\"\"傾けた直方体に存在できる水の体積", "+ 水面を地面に対し平行にした図を描き", "+ tanを用いると計算できる\"\"\"", "+ theta = radians(theta)", "+ if a * tan(theta) <= b: # 台形", "+ return a * a * b - a * a * a * tan(theta) / 2", "+ else: # 三角形", "+ return a * b * b * tan(pi / 2 - theta) / 2", "+", "+ def is_ok(theta):", "+ return volume(theta) >= x", "+", "+ def binary_search():", "+ small, large = 0, 90", "+ for _ in range(30):", "+ mid = (small + large) / 2", "+ if is_ok(mid):", "+ small = mid", "+ else:", "+ large = mid", "+ return small", "+", "+ ret = binary_search()", "+ print(ret)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045102
0.088667
0.508669
[ "s271767678", "s354398949" ]
u190405389
p02629
python
s692454760
s032701009
79
66
61,948
61,972
Accepted
Accepted
16.46
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print(('\n'.join(map(str,x)))) def printline(x):print((' '.join(map(str,x)))) n = readint() a = ord('a')-1 ans = [] i = 1 while n: if n%26==0: ans.append('z') n = n//26-1 else: ans.append(chr(n%26+a)) n//=26 ans.reverse() print((''.join(ans)))
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print(('\n'.join(map(str,x)))) def printline(x):print((' '.join(map(str,x)))) n = readint() a = ['z'] + [chr(ord('a')+i) for i in range(25)] ans = [] while n: ans.append(a[n%26]) n = (n-1)//26 ans.reverse() print((''.join(ans)))
26
21
600
548
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr(): return readline().rstrip().decode() def readstrs(): return list(readline().decode().split()) def readint(): return int(readline()) def readints(): return list(map(int, readline().split())) def printrows(x): print(("\n".join(map(str, x)))) def printline(x): print((" ".join(map(str, x)))) n = readint() a = ord("a") - 1 ans = [] i = 1 while n: if n % 26 == 0: ans.append("z") n = n // 26 - 1 else: ans.append(chr(n % 26 + a)) n //= 26 ans.reverse() print(("".join(ans)))
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr(): return readline().rstrip().decode() def readstrs(): return list(readline().decode().split()) def readint(): return int(readline()) def readints(): return list(map(int, readline().split())) def printrows(x): print(("\n".join(map(str, x)))) def printline(x): print((" ".join(map(str, x)))) n = readint() a = ["z"] + [chr(ord("a") + i) for i in range(25)] ans = [] while n: ans.append(a[n % 26]) n = (n - 1) // 26 ans.reverse() print(("".join(ans)))
false
19.230769
[ "-a = ord(\"a\") - 1", "+a = [\"z\"] + [chr(ord(\"a\") + i) for i in range(25)]", "-i = 1", "- if n % 26 == 0:", "- ans.append(\"z\")", "- n = n // 26 - 1", "- else:", "- ans.append(chr(n % 26 + a))", "- n //= 26", "+ ans.append(a[n % 26])", "+ n = (n - 1) // 26" ]
false
0.039486
0.038873
1.015768
[ "s692454760", "s032701009" ]
u074220993
p03730
python
s424999004
s997449083
30
25
9,036
9,172
Accepted
Accepted
16.67
A, B, C = list(map(int, input().split())) N = A % B M, i = 0, 2 while M != N: M = i * N % B if M == C: print("YES") break i += 1 else: print("NO")
A, B, C = list(map(int, open(0).readline().split())) import math print(('YES' if C % math.gcd(B,A%B) == 0 else 'NO'))
11
3
182
111
A, B, C = list(map(int, input().split())) N = A % B M, i = 0, 2 while M != N: M = i * N % B if M == C: print("YES") break i += 1 else: print("NO")
A, B, C = list(map(int, open(0).readline().split())) import math print(("YES" if C % math.gcd(B, A % B) == 0 else "NO"))
false
72.727273
[ "-A, B, C = list(map(int, input().split()))", "-N = A % B", "-M, i = 0, 2", "-while M != N:", "- M = i * N % B", "- if M == C:", "- print(\"YES\")", "- break", "- i += 1", "-else:", "- print(\"NO\")", "+A, B, C = list(map(int, open(0).readline().split()))", "+import math", "+", "+print((\"YES\" if C % math.gcd(B, A % B) == 0 else \"NO\"))" ]
false
0.035755
0.03509
1.018946
[ "s424999004", "s997449083" ]
u628285938
p02726
python
s563004283
s167939135
1,533
1,157
3,444
9,196
Accepted
Accepted
24.53
# -*- coding: utf-8 -*- """ Created on Tue Mar 31 01:29:10 2020 @author: liang """ N, X, Y = list(map(int,input().split())) length = [0]*(N) for i in range(1,N+1): for j in range(i+1,N+1): ans = min(j-i,abs(i-X) + 1 + abs(j-Y)) length[ans] += 1 for i in range(1,N): print((length[i]))
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 15:49:02 2020 @author: liang """ N, X, Y = list(map(int, input().split())) ans = [0]*(N-1) for i in range(1,N+1): for j in range(i+1, N+1): #print(i,j) res = min(abs(i-j), abs(X-i) + 1 + abs(Y-j)) #print(i, j, res) ans[res-1] += 1 for i in ans: print(i)
16
18
318
357
# -*- coding: utf-8 -*- """ Created on Tue Mar 31 01:29:10 2020 @author: liang """ N, X, Y = list(map(int, input().split())) length = [0] * (N) for i in range(1, N + 1): for j in range(i + 1, N + 1): ans = min(j - i, abs(i - X) + 1 + abs(j - Y)) length[ans] += 1 for i in range(1, N): print((length[i]))
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 15:49:02 2020 @author: liang """ N, X, Y = list(map(int, input().split())) ans = [0] * (N - 1) for i in range(1, N + 1): for j in range(i + 1, N + 1): # print(i,j) res = min(abs(i - j), abs(X - i) + 1 + abs(Y - j)) # print(i, j, res) ans[res - 1] += 1 for i in ans: print(i)
false
11.111111
[ "-Created on Tue Mar 31 01:29:10 2020", "+Created on Mon Sep 7 15:49:02 2020", "-length = [0] * (N)", "+ans = [0] * (N - 1)", "- ans = min(j - i, abs(i - X) + 1 + abs(j - Y))", "- length[ans] += 1", "-for i in range(1, N):", "- print((length[i]))", "+ # print(i,j)", "+ res = min(abs(i - j), abs(X - i) + 1 + abs(Y - j))", "+ # print(i, j, res)", "+ ans[res - 1] += 1", "+for i in ans:", "+ print(i)" ]
false
0.047673
0.071167
0.669876
[ "s563004283", "s167939135" ]
u577311000
p00448
python
s717873037
s086292734
9,810
4,900
10,692
10,812
Accepted
Accepted
50.05
while 1: r, c = list(map(int, input().split())) if r == 0: break old = [input().split() for i in range(r)] old = list(map(list, list(zip(*old)))) new = [int("".join(lst),2) for lst in old] ans = 0 for i in range(1<<r): ret = 0 for j in new: cnt = bin(i^j).count('1') ret += cnt if cnt > r/2 else r-cnt ans = max(ans, ret) print(ans)
while 1: r, c = list(map(int, input().split())) if r == 0: break old = [input().split() for i in range(r)] old = list(map(list, list(zip(*old)))) new = [int("".join(lst),2) for lst in old] ans = 0 for i in range(1<<(r-1)): ret = 0 for j in new: cnt = bin(i^j).count('1') ret += cnt if cnt > r/2 else r-cnt ans = max(ans, ret) print(ans)
14
14
414
418
while 1: r, c = list(map(int, input().split())) if r == 0: break old = [input().split() for i in range(r)] old = list(map(list, list(zip(*old)))) new = [int("".join(lst), 2) for lst in old] ans = 0 for i in range(1 << r): ret = 0 for j in new: cnt = bin(i ^ j).count("1") ret += cnt if cnt > r / 2 else r - cnt ans = max(ans, ret) print(ans)
while 1: r, c = list(map(int, input().split())) if r == 0: break old = [input().split() for i in range(r)] old = list(map(list, list(zip(*old)))) new = [int("".join(lst), 2) for lst in old] ans = 0 for i in range(1 << (r - 1)): ret = 0 for j in new: cnt = bin(i ^ j).count("1") ret += cnt if cnt > r / 2 else r - cnt ans = max(ans, ret) print(ans)
false
0
[ "- for i in range(1 << r):", "+ for i in range(1 << (r - 1)):" ]
false
0.034596
0.032774
1.055604
[ "s717873037", "s086292734" ]
u261103969
p02675
python
s527381656
s599490982
23
20
9,104
9,080
Accepted
Accepted
13.04
n = eval(input()) c = n[-1] if c in ["3"]: print("bon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("hon")
n = int(eval(input())) c = n % 10 if c in [3]: print("bon") elif c in [0, 1, 6, 8]: print("pon") else: print("hon")
9
9
128
130
n = eval(input()) c = n[-1] if c in ["3"]: print("bon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("hon")
n = int(eval(input())) c = n % 10 if c in [3]: print("bon") elif c in [0, 1, 6, 8]: print("pon") else: print("hon")
false
0
[ "-n = eval(input())", "-c = n[-1]", "-if c in [\"3\"]:", "+n = int(eval(input()))", "+c = n % 10", "+if c in [3]:", "-elif c in [\"0\", \"1\", \"6\", \"8\"]:", "+elif c in [0, 1, 6, 8]:" ]
false
0.036003
0.090804
0.396485
[ "s527381656", "s599490982" ]
u934442292
p02888
python
s711916306
s168161525
1,831
921
3,188
3,188
Accepted
Accepted
49.7
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 - 1): a = L[i] for j in range(i + 1, N): k = bisect_left(L, a + L[j], lo=j) ans += (k - 1 - j) 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 - 1): a = L[i] for j in range(i + 1, N): k = bisect_left(L, a + L[j]) ans += (k - 1 - j) print(ans) if __name__ == "__main__": main()
23
23
405
399
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 - 1): a = L[i] for j in range(i + 1, N): k = bisect_left(L, a + L[j], lo=j) ans += k - 1 - j 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 - 1): a = L[i] for j in range(i + 1, N): k = bisect_left(L, a + L[j]) ans += k - 1 - j print(ans) if __name__ == "__main__": main()
false
0
[ "- k = bisect_left(L, a + L[j], lo=j)", "+ k = bisect_left(L, a + L[j])" ]
false
0.037975
0.068032
0.558194
[ "s711916306", "s168161525" ]
u631277801
p03401
python
s310480417
s932457086
825
227
22,848
14,048
Accepted
Accepted
72.48
import numpy as np def main(): #1. make master list N = int(eval(input())) A = list(map(int, input().split())) A.append(0) A.insert(0,0) A = np.array(A) cost = np.abs(A[1:] - A[:-1]) total = sum(cost) #2. remove i-th componet for i in range(N): #3. output print((total - cost[i] - cost[i+1] + abs(A[i+2]-A[i]))) if __name__ == "__main__": main()
N = int(eval(input())) A = list(map(int, input().split())) A.append(0) A.insert(0,0) total = 0 for i in range(1,N+2): total += abs(A[i]-A[i-1]) for i in range(1,N+1): print((total - abs(A[i+1]-A[i]) - abs(A[i]-A[i-1]) + abs(A[i+1]-A[i-1])))
22
11
436
252
import numpy as np def main(): # 1. make master list N = int(eval(input())) A = list(map(int, input().split())) A.append(0) A.insert(0, 0) A = np.array(A) cost = np.abs(A[1:] - A[:-1]) total = sum(cost) # 2. remove i-th componet for i in range(N): # 3. output print((total - cost[i] - cost[i + 1] + abs(A[i + 2] - A[i]))) if __name__ == "__main__": main()
N = int(eval(input())) A = list(map(int, input().split())) A.append(0) A.insert(0, 0) total = 0 for i in range(1, N + 2): total += abs(A[i] - A[i - 1]) for i in range(1, N + 1): print( (total - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1])) )
false
50
[ "-import numpy as np", "-", "-", "-def main():", "- # 1. make master list", "- N = int(eval(input()))", "- A = list(map(int, input().split()))", "- A.append(0)", "- A.insert(0, 0)", "- A = np.array(A)", "- cost = np.abs(A[1:] - A[:-1])", "- total = sum(cost)", "- # 2. remove i-th componet", "- for i in range(N):", "- # 3. output", "- print((total - cost[i] - cost[i + 1] + abs(A[i + 2] - A[i])))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+A.append(0)", "+A.insert(0, 0)", "+total = 0", "+for i in range(1, N + 2):", "+ total += abs(A[i] - A[i - 1])", "+for i in range(1, N + 1):", "+ print(", "+ (total - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1]))", "+ )" ]
false
0.48376
0.035688
13.5554
[ "s310480417", "s932457086" ]
u729133443
p02640
python
s969299806
s225039129
23
21
9,168
9,080
Accepted
Accepted
8.7
x,y=list(map(int,input().split())) f=0 for i in range(x+1):j=x-i;f|=i*2+j*4==y print(('NYoe s'[f::2]))
x,y=list(map(int,input().split())) print(('YNeos'[y%2or y>x*4or y<x*2::2]))
4
2
97
68
x, y = list(map(int, input().split())) f = 0 for i in range(x + 1): j = x - i f |= i * 2 + j * 4 == y print(("NYoe s"[f::2]))
x, y = list(map(int, input().split())) print(("YNeos"[y % 2 or y > x * 4 or y < x * 2 :: 2]))
false
50
[ "-f = 0", "-for i in range(x + 1):", "- j = x - i", "- f |= i * 2 + j * 4 == y", "-print((\"NYoe s\"[f::2]))", "+print((\"YNeos\"[y % 2 or y > x * 4 or y < x * 2 :: 2]))" ]
false
0.039984
0.040146
0.995949
[ "s969299806", "s225039129" ]
u133936772
p03475
python
s349004598
s751553705
102
73
3,060
9,124
Accepted
Accepted
28.43
n=int(input());l=[0]*n for i in range(1,n): c,s,f=map(int,input().split()) for j in range(i):l[j]=max(-l[j]//f*-f,s)+c print(*l,sep='\n')
n=int(eval(input())) l=[] for _ in range(n-1): c,s,f=list(map(int,input().split())) for i,t in enumerate(l): if t>s: t=-(-t//f)*f else: t=s l[i]=t+c l+=[s+c] for i in l+[0]: print(i)
5
11
143
200
n = int(input()) l = [0] * n for i in range(1, n): c, s, f = map(int, input().split()) for j in range(i): l[j] = max(-l[j] // f * -f, s) + c print(*l, sep="\n")
n = int(eval(input())) l = [] for _ in range(n - 1): c, s, f = list(map(int, input().split())) for i, t in enumerate(l): if t > s: t = -(-t // f) * f else: t = s l[i] = t + c l += [s + c] for i in l + [0]: print(i)
false
54.545455
[ "-n = int(input())", "-l = [0] * n", "-for i in range(1, n):", "- c, s, f = map(int, input().split())", "- for j in range(i):", "- l[j] = max(-l[j] // f * -f, s) + c", "-print(*l, sep=\"\\n\")", "+n = int(eval(input()))", "+l = []", "+for _ in range(n - 1):", "+ c, s, f = list(map(int, input().split()))", "+ for i, t in enumerate(l):", "+ if t > s:", "+ t = -(-t // f) * f", "+ else:", "+ t = s", "+ l[i] = t + c", "+ l += [s + c]", "+for i in l + [0]:", "+ print(i)" ]
false
0.09927
0.068802
1.442837
[ "s349004598", "s751553705" ]
u644907318
p03240
python
s440393329
s900935091
200
93
41,328
73,908
Accepted
Accepted
53.5
N = int(eval(input())) A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True) for x in range(101): for y in range(101): a,b,h = A[0] H = h+abs(x-a)+abs(y-b) flag = 1 for i in range(1,N): a,b,h = A[i] if max(0,H-abs(x-a)-abs(y-b))==h:continue else: flag = 0 break if flag==1: cx = x cy = y break if flag==1:break print((cx,cy,H))
def dist(X,Y): return abs(X[0]-Y[0])+abs(X[1]-Y[1]) N = int(eval(input())) A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True) for i in range(101): for j in range(101): flag=0 x0,y0,h0 = A[0] H = h0+dist((i,j),(x0,y0)) for k in range(1,N): x,y,h = A[k] if h>0 and H==h+dist((i,j),(x,y)): continue elif h>0 and H!=h+dist((i,j),(x,y)): flag=1 break elif h==0 and H<=dist((i,j),(x,y)): continue elif h==0 and H>dist((i,j),(x,y)): flag = 1 break if flag==0: Cx = i Cy = j break if flag==0:break print((Cx,Cy,H))
19
27
529
811
N = int(eval(input())) A = sorted( [list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2], reverse=True, ) for x in range(101): for y in range(101): a, b, h = A[0] H = h + abs(x - a) + abs(y - b) flag = 1 for i in range(1, N): a, b, h = A[i] if max(0, H - abs(x - a) - abs(y - b)) == h: continue else: flag = 0 break if flag == 1: cx = x cy = y break if flag == 1: break print((cx, cy, H))
def dist(X, Y): return abs(X[0] - Y[0]) + abs(X[1] - Y[1]) N = int(eval(input())) A = sorted( [list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2], reverse=True, ) for i in range(101): for j in range(101): flag = 0 x0, y0, h0 = A[0] H = h0 + dist((i, j), (x0, y0)) for k in range(1, N): x, y, h = A[k] if h > 0 and H == h + dist((i, j), (x, y)): continue elif h > 0 and H != h + dist((i, j), (x, y)): flag = 1 break elif h == 0 and H <= dist((i, j), (x, y)): continue elif h == 0 and H > dist((i, j), (x, y)): flag = 1 break if flag == 0: Cx = i Cy = j break if flag == 0: break print((Cx, Cy, H))
false
29.62963
[ "+def dist(X, Y):", "+ return abs(X[0] - Y[0]) + abs(X[1] - Y[1])", "+", "+", "-for x in range(101):", "- for y in range(101):", "- a, b, h = A[0]", "- H = h + abs(x - a) + abs(y - b)", "- flag = 1", "- for i in range(1, N):", "- a, b, h = A[i]", "- if max(0, H - abs(x - a) - abs(y - b)) == h:", "+for i in range(101):", "+ for j in range(101):", "+ flag = 0", "+ x0, y0, h0 = A[0]", "+ H = h0 + dist((i, j), (x0, y0))", "+ for k in range(1, N):", "+ x, y, h = A[k]", "+ if h > 0 and H == h + dist((i, j), (x, y)):", "- else:", "- flag = 0", "+ elif h > 0 and H != h + dist((i, j), (x, y)):", "+ flag = 1", "- if flag == 1:", "- cx = x", "- cy = y", "+ elif h == 0 and H <= dist((i, j), (x, y)):", "+ continue", "+ elif h == 0 and H > dist((i, j), (x, y)):", "+ flag = 1", "+ break", "+ if flag == 0:", "+ Cx = i", "+ Cy = j", "- if flag == 1:", "+ if flag == 0:", "-print((cx, cy, H))", "+print((Cx, Cy, H))" ]
false
0.04126
0.042491
0.971023
[ "s440393329", "s900935091" ]
u832224732
p03145
python
s527464349
s442564077
12
11
2,568
2,568
Accepted
Accepted
8.33
# -*- coding: utf-8 -*- # Luis Yoichi Morales January 2019 a, b, c = list(map(int, input().split())) print(a*b /2)
# -*- coding: utf-8 -*- # Luis Yoichi Morales January 2019 ab, bc, ca = list(map(int, input().split())) print(ab*bc/2)
6
5
119
121
# -*- coding: utf-8 -*- # Luis Yoichi Morales January 2019 a, b, c = list(map(int, input().split())) print(a * b / 2)
# -*- coding: utf-8 -*- # Luis Yoichi Morales January 2019 ab, bc, ca = list(map(int, input().split())) print(ab * bc / 2)
false
16.666667
[ "-a, b, c = list(map(int, input().split()))", "-print(a * b / 2)", "+ab, bc, ca = list(map(int, input().split()))", "+print(ab * bc / 2)" ]
false
0.038695
0.037931
1.020156
[ "s527464349", "s442564077" ]
u485319545
p03043
python
s555020160
s416967452
45
39
5,048
9,436
Accepted
Accepted
13.33
n,k = list(map(int,input().split())) from fractions import math ans=0 if n>=k: ans += 1 - (k-1)/n for i in range(1,n+1): if i<=k-1: exp = math.ceil(math.log2(k/i)) p_i = (1/n) * ((1/2)**exp) ans += p_i print(ans)
n,k=list(map(int,input().split())) ans= 0 from math import ceil,log2 for i in range(1,n+1): if i<k: a = ceil(log2(k/i)) ans +=(1/n)*(1/2)**a else: ans += (1/n) print(ans)
16
13
258
212
n, k = list(map(int, input().split())) from fractions import math ans = 0 if n >= k: ans += 1 - (k - 1) / n for i in range(1, n + 1): if i <= k - 1: exp = math.ceil(math.log2(k / i)) p_i = (1 / n) * ((1 / 2) ** exp) ans += p_i print(ans)
n, k = list(map(int, input().split())) ans = 0 from math import ceil, log2 for i in range(1, n + 1): if i < k: a = ceil(log2(k / i)) ans += (1 / n) * (1 / 2) ** a else: ans += 1 / n print(ans)
false
18.75
[ "-from fractions import math", "+ans = 0", "+from math import ceil, log2", "-ans = 0", "-if n >= k:", "- ans += 1 - (k - 1) / n", "- if i <= k - 1:", "- exp = math.ceil(math.log2(k / i))", "- p_i = (1 / n) * ((1 / 2) ** exp)", "- ans += p_i", "+ if i < k:", "+ a = ceil(log2(k / i))", "+ ans += (1 / n) * (1 / 2) ** a", "+ else:", "+ ans += 1 / n" ]
false
0.046942
0.045967
1.021207
[ "s555020160", "s416967452" ]
u133936772
p03043
python
s165900112
s992648741
55
34
2,940
9,408
Accepted
Accepted
38.18
n,k=list(map(int,input().split()));a=0 for i in range(n): i+=1;p=1/n while i<k:i*=2;p/=2 a+=p print(a)
n,k=list(map(int,input().split())) p=0 for i in range(1,n+1): if i<k: p+=4*0.5**len(bin(~-k//i)) else: p+=1 print((p/n))
6
6
107
121
n, k = list(map(int, input().split())) a = 0 for i in range(n): i += 1 p = 1 / n while i < k: i *= 2 p /= 2 a += p print(a)
n, k = list(map(int, input().split())) p = 0 for i in range(1, n + 1): if i < k: p += 4 * 0.5 ** len(bin(~-k // i)) else: p += 1 print((p / n))
false
0
[ "-a = 0", "-for i in range(n):", "- i += 1", "- p = 1 / n", "- while i < k:", "- i *= 2", "- p /= 2", "- a += p", "-print(a)", "+p = 0", "+for i in range(1, n + 1):", "+ if i < k:", "+ p += 4 * 0.5 ** len(bin(~-k // i))", "+ else:", "+ p += 1", "+print((p / n))" ]
false
0.047452
0.043535
1.089968
[ "s165900112", "s992648741" ]
u983918956
p03049
python
s040376358
s415425145
48
38
3,700
3,064
Accepted
Accepted
20.83
N = int(eval(input())) S = [eval(input()) for _ in range(N)] a = 0 b = 0 a_b = 0 for s in S: if s[-1] == "A" and s[0] == "B": a_b += 1 elif s[-1] == "A": a += 1 elif s[0] == "B": b += 1 ans = 0 if a_b > 0: ans += a_b - 1 if a > 0: ans += 1 a -= 1 if b > 0: ans += 1 b -= 1 ans += min(a,b) for line in S: for i in range(len(line)-1): if (line[i],line[i+1]) == ("A","B"): ans += 1 print(ans)
N = int(eval(input())) cnt = 0 A = 0 B = 0 BA = 0 for _ in range(N): s = eval(input()) cnt += s.count("AB") if s[0] == "B" and s[-1] == "A": BA += 1 elif s[0] == "B": B += 1 elif s[-1] == "A": A += 1 if BA == 0: ans = cnt + min(A, B) else: ans = cnt + BA - 1 if A > 0: ans += 1 A -= 1 if B > 0: ans += 1 B -= 1 ans += min(A, B) print(ans)
32
28
517
451
N = int(eval(input())) S = [eval(input()) for _ in range(N)] a = 0 b = 0 a_b = 0 for s in S: if s[-1] == "A" and s[0] == "B": a_b += 1 elif s[-1] == "A": a += 1 elif s[0] == "B": b += 1 ans = 0 if a_b > 0: ans += a_b - 1 if a > 0: ans += 1 a -= 1 if b > 0: ans += 1 b -= 1 ans += min(a, b) for line in S: for i in range(len(line) - 1): if (line[i], line[i + 1]) == ("A", "B"): ans += 1 print(ans)
N = int(eval(input())) cnt = 0 A = 0 B = 0 BA = 0 for _ in range(N): s = eval(input()) cnt += s.count("AB") if s[0] == "B" and s[-1] == "A": BA += 1 elif s[0] == "B": B += 1 elif s[-1] == "A": A += 1 if BA == 0: ans = cnt + min(A, B) else: ans = cnt + BA - 1 if A > 0: ans += 1 A -= 1 if B > 0: ans += 1 B -= 1 ans += min(A, B) print(ans)
false
12.5
[ "-S = [eval(input()) for _ in range(N)]", "-a = 0", "-b = 0", "-a_b = 0", "-for s in S:", "- if s[-1] == \"A\" and s[0] == \"B\":", "- a_b += 1", "+cnt = 0", "+A = 0", "+B = 0", "+BA = 0", "+for _ in range(N):", "+ s = eval(input())", "+ cnt += s.count(\"AB\")", "+ if s[0] == \"B\" and s[-1] == \"A\":", "+ BA += 1", "+ elif s[0] == \"B\":", "+ B += 1", "- a += 1", "- elif s[0] == \"B\":", "- b += 1", "-ans = 0", "-if a_b > 0:", "- ans += a_b - 1", "- if a > 0:", "+ A += 1", "+if BA == 0:", "+ ans = cnt + min(A, B)", "+else:", "+ ans = cnt + BA - 1", "+ if A > 0:", "- a -= 1", "- if b > 0:", "+ A -= 1", "+ if B > 0:", "- b -= 1", "-ans += min(a, b)", "-for line in S:", "- for i in range(len(line) - 1):", "- if (line[i], line[i + 1]) == (\"A\", \"B\"):", "- ans += 1", "+ B -= 1", "+ ans += min(A, B)" ]
false
0.06922
0.095845
0.722208
[ "s040376358", "s415425145" ]
u227082700
p03208
python
s226442190
s546789154
250
224
7,384
7,508
Accepted
Accepted
10.4
n,k=list(map(int,input().split())) h=[int(eval(input()))for _ in range(n)] h.sort() a=9999999999 for i in range(n-k+1):a=min(a,h[i+k-1]-h[i]) print(a)
n,k=list(map(int,input().split())) h=[int(eval(input()))for _ in range(n)] h.sort(reverse=1) print((min(h[i-k+1]-h[i] for i in range(k-1,n))))
6
4
143
131
n, k = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] h.sort() a = 9999999999 for i in range(n - k + 1): a = min(a, h[i + k - 1] - h[i]) print(a)
n, k = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] h.sort(reverse=1) print((min(h[i - k + 1] - h[i] for i in range(k - 1, n))))
false
33.333333
[ "-h.sort()", "-a = 9999999999", "-for i in range(n - k + 1):", "- a = min(a, h[i + k - 1] - h[i])", "-print(a)", "+h.sort(reverse=1)", "+print((min(h[i - k + 1] - h[i] for i in range(k - 1, n))))" ]
false
0.046913
0.047408
0.989554
[ "s226442190", "s546789154" ]
u523545435
p02803
python
s865065647
s099006541
640
528
3,496
3,424
Accepted
Accepted
17.5
import copy from collections import deque H,W=list(map(int,input().split())) S=[list(eval(input())) for _ in range(H)] def check(tup): global H global W global S tup_x=tup[0] tup_y=tup[1] if 0<=tup_x<H and 0<=tup_y<W: if S[tup_x][tup_y]=='.': return True else: return False def neighbor(tup): x=tup[0] y=tup[1] cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)] List=[] for c in cand: if check(c): List.append(c) return List def bfs(start):#startはtuple型 global H global W if check(start): deq=deque()#as queue Dict=[] component=[] for i in range(W): component.append(-1) for j in range(H): Dict.append(copy.copy(component)) deq.append(start) Dict[start[0]][start[1]]=0 while deq: now=deq.popleft() nexts=neighbor(now) for next in nexts: next_x=next[0] next_y=next[1] if Dict[next_x][next_y]>=0: continue if next in deq: continue deq.append(next) Dict[next_x][next_y]=Dict[now[0]][now[1]]+1 M=[] for d in Dict: M.append(max(d)) return max(M) else: return 0 Ans=[] for k in range(H): for l in range(W): Ans.append(bfs((k,l))) print((max(Ans)))
import copy from collections import deque H,W=list(map(int,input().split())) S=[list(eval(input())) for _ in range(H)] def check(tup): global H global W global S tup_x=tup[0] tup_y=tup[1] if 0<=tup_x<H and 0<=tup_y<W: if S[tup_x][tup_y]=='.': return True else: return False def neighbor(tup): x=tup[0] y=tup[1] cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)] List=[] for c in cand: if check(c): List.append(c) return List def bfs(start):#startはtuple型 global H global W if check(start): deq=deque()#as queue Dict=[] component=[] for i in range(W): component.append(-1) for j in range(H): Dict.append(copy.copy(component)) deq.append(start) Dict[start[0]][start[1]]=0 while deq: now=deq.popleft() nexts=neighbor(now) for next in nexts: next_x=next[0] next_y=next[1] if Dict[next_x][next_y]>=0: continue #if next in deq: #continue deq.append(next) Dict[next_x][next_y]=Dict[now[0]][now[1]]+1 M=[] for d in Dict: M.append(max(d)) return max(M) else: return 0 Ans=[] for k in range(H): for l in range(W): Ans.append(bfs((k,l))) print((max(Ans)))
74
74
1,539
1,541
import copy from collections import deque H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] def check(tup): global H global W global S tup_x = tup[0] tup_y = tup[1] if 0 <= tup_x < H and 0 <= tup_y < W: if S[tup_x][tup_y] == ".": return True else: return False def neighbor(tup): x = tup[0] y = tup[1] cand = [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)] List = [] for c in cand: if check(c): List.append(c) return List def bfs(start): # startはtuple型 global H global W if check(start): deq = deque() # as queue Dict = [] component = [] for i in range(W): component.append(-1) for j in range(H): Dict.append(copy.copy(component)) deq.append(start) Dict[start[0]][start[1]] = 0 while deq: now = deq.popleft() nexts = neighbor(now) for next in nexts: next_x = next[0] next_y = next[1] if Dict[next_x][next_y] >= 0: continue if next in deq: continue deq.append(next) Dict[next_x][next_y] = Dict[now[0]][now[1]] + 1 M = [] for d in Dict: M.append(max(d)) return max(M) else: return 0 Ans = [] for k in range(H): for l in range(W): Ans.append(bfs((k, l))) print((max(Ans)))
import copy from collections import deque H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] def check(tup): global H global W global S tup_x = tup[0] tup_y = tup[1] if 0 <= tup_x < H and 0 <= tup_y < W: if S[tup_x][tup_y] == ".": return True else: return False def neighbor(tup): x = tup[0] y = tup[1] cand = [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)] List = [] for c in cand: if check(c): List.append(c) return List def bfs(start): # startはtuple型 global H global W if check(start): deq = deque() # as queue Dict = [] component = [] for i in range(W): component.append(-1) for j in range(H): Dict.append(copy.copy(component)) deq.append(start) Dict[start[0]][start[1]] = 0 while deq: now = deq.popleft() nexts = neighbor(now) for next in nexts: next_x = next[0] next_y = next[1] if Dict[next_x][next_y] >= 0: continue # if next in deq: # continue deq.append(next) Dict[next_x][next_y] = Dict[now[0]][now[1]] + 1 M = [] for d in Dict: M.append(max(d)) return max(M) else: return 0 Ans = [] for k in range(H): for l in range(W): Ans.append(bfs((k, l))) print((max(Ans)))
false
0
[ "- if next in deq:", "- continue", "+ # if next in deq:", "+ # continue" ]
false
0.060601
0.050776
1.193482
[ "s865065647", "s099006541" ]
u377989038
p02689
python
s147911267
s246757306
663
536
41,484
57,228
Accepted
Accepted
19.16
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = sorted([sorted(list(map(int, input().split()))) for _ in range(m)]) l = [[] for _ in range(n + 1)] for a, b in ab: l[a].append(b) l[b].append(a) cnt = 0 f = 0 for i, v in enumerate(l): for k in v: if h[i] <= h[k]: f = 1 break if f == 0: cnt += 1 f = 0 print((cnt - 1))
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = [(list(map(int, input().split())))for _ in range(m)] l = [set({}) for _ in range(n + 1)] for a, b in ab: l[a].add(b) l[b].add(a) cnt = -1 for i, v in enumerate(l): if len(v) != 0: if h[i] > max([h[j] for j in v]): cnt += 1 else: cnt += 1 print(cnt)
22
17
443
390
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = sorted([sorted(list(map(int, input().split()))) for _ in range(m)]) l = [[] for _ in range(n + 1)] for a, b in ab: l[a].append(b) l[b].append(a) cnt = 0 f = 0 for i, v in enumerate(l): for k in v: if h[i] <= h[k]: f = 1 break if f == 0: cnt += 1 f = 0 print((cnt - 1))
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = [(list(map(int, input().split()))) for _ in range(m)] l = [set({}) for _ in range(n + 1)] for a, b in ab: l[a].add(b) l[b].add(a) cnt = -1 for i, v in enumerate(l): if len(v) != 0: if h[i] > max([h[j] for j in v]): cnt += 1 else: cnt += 1 print(cnt)
false
22.727273
[ "-ab = sorted([sorted(list(map(int, input().split()))) for _ in range(m)])", "-l = [[] for _ in range(n + 1)]", "+ab = [(list(map(int, input().split()))) for _ in range(m)]", "+l = [set({}) for _ in range(n + 1)]", "- l[a].append(b)", "- l[b].append(a)", "-cnt = 0", "-f = 0", "+ l[a].add(b)", "+ l[b].add(a)", "+cnt = -1", "- for k in v:", "- if h[i] <= h[k]:", "- f = 1", "- break", "- if f == 0:", "+ if len(v) != 0:", "+ if h[i] > max([h[j] for j in v]):", "+ cnt += 1", "+ else:", "- f = 0", "-print((cnt - 1))", "+print(cnt)" ]
false
0.08154
0.096879
0.841672
[ "s147911267", "s246757306" ]
u466105944
p03737
python
s905714746
s590957111
22
18
2,940
2,940
Accepted
Accepted
18.18
s1,s2,s3 = input().split() ans = s1[:1]+s2[:1]+s3[:1] print((ans.upper()))
a,b,c = list(map(str,input().split())) print(((a[0]+b[0]+c[0]).upper()))
3
2
75
66
s1, s2, s3 = input().split() ans = s1[:1] + s2[:1] + s3[:1] print((ans.upper()))
a, b, c = list(map(str, input().split())) print(((a[0] + b[0] + c[0]).upper()))
false
33.333333
[ "-s1, s2, s3 = input().split()", "-ans = s1[:1] + s2[:1] + s3[:1]", "-print((ans.upper()))", "+a, b, c = list(map(str, input().split()))", "+print(((a[0] + b[0] + c[0]).upper()))" ]
false
0.035195
0.034887
1.008807
[ "s905714746", "s590957111" ]
u488127128
p03086
python
s310022514
s485908133
22
17
3,188
2,940
Accepted
Accepted
22.73
import re S = eval(input()) S = list(map(len, re.sub('[^ACGT]', ',', S).split(','))) print((max(S)))
S = eval(input()) ans = 0 count = 0 for s in S: if s in 'ACGT': count += 1 else: ans = max(ans, count) count = 0 else: ans = max(ans, count) print(ans)
4
12
89
192
import re S = eval(input()) S = list(map(len, re.sub("[^ACGT]", ",", S).split(","))) print((max(S)))
S = eval(input()) ans = 0 count = 0 for s in S: if s in "ACGT": count += 1 else: ans = max(ans, count) count = 0 else: ans = max(ans, count) print(ans)
false
66.666667
[ "-import re", "-", "-S = list(map(len, re.sub(\"[^ACGT]\", \",\", S).split(\",\")))", "-print((max(S)))", "+ans = 0", "+count = 0", "+for s in S:", "+ if s in \"ACGT\":", "+ count += 1", "+ else:", "+ ans = max(ans, count)", "+ count = 0", "+else:", "+ ans = max(ans, count)", "+print(ans)" ]
false
0.049394
0.087387
0.565231
[ "s310022514", "s485908133" ]
u588785393
p03170
python
s480607045
s071247192
748
145
3,928
72,484
Accepted
Accepted
80.61
def solve(ls, k): dp = [False for i in range(k + 1)] for i in range(k + 1): for stone in ls: if stone <= i and not dp[i - stone]: dp[i] = True return dp[k] n, k = list(map(int, input().split())) ls = list(map(int, input().split())) if solve(ls, k): print('First') else: print('Second')
n, k = list(map(int, input().split())) ls = list(map(int, input().split())) dp = [False] * (k + 1) for i in range(1, k + 1): for j in ls: if i - j >= 0 and not dp[i - j]: dp[i] = True if dp[k]: print('First') else: print('Second')
15
11
310
243
def solve(ls, k): dp = [False for i in range(k + 1)] for i in range(k + 1): for stone in ls: if stone <= i and not dp[i - stone]: dp[i] = True return dp[k] n, k = list(map(int, input().split())) ls = list(map(int, input().split())) if solve(ls, k): print("First") else: print("Second")
n, k = list(map(int, input().split())) ls = list(map(int, input().split())) dp = [False] * (k + 1) for i in range(1, k + 1): for j in ls: if i - j >= 0 and not dp[i - j]: dp[i] = True if dp[k]: print("First") else: print("Second")
false
26.666667
[ "-def solve(ls, k):", "- dp = [False for i in range(k + 1)]", "- for i in range(k + 1):", "- for stone in ls:", "- if stone <= i and not dp[i - stone]:", "- dp[i] = True", "- return dp[k]", "-", "-", "-if solve(ls, k):", "+dp = [False] * (k + 1)", "+for i in range(1, k + 1):", "+ for j in ls:", "+ if i - j >= 0 and not dp[i - j]:", "+ dp[i] = True", "+if dp[k]:" ]
false
0.091933
0.042047
2.186442
[ "s480607045", "s071247192" ]
u537782349
p03470
python
s253533074
s895981554
21
19
3,316
3,060
Accepted
Accepted
9.52
a = int(eval(input())) b = {} for i in range(a): b[int(eval(input()))] = 1 print((len(b)))
a = int(eval(input())) print((len({int(eval(input())): "" for _ in range(a)})))
5
2
85
67
a = int(eval(input())) b = {} for i in range(a): b[int(eval(input()))] = 1 print((len(b)))
a = int(eval(input())) print((len({int(eval(input())): "" for _ in range(a)})))
false
60
[ "-b = {}", "-for i in range(a):", "- b[int(eval(input()))] = 1", "-print((len(b)))", "+print((len({int(eval(input())): \"\" for _ in range(a)})))" ]
false
0.032334
0.034401
0.93993
[ "s253533074", "s895981554" ]
u119148115
p02602
python
s968851832
s296486412
172
159
94,048
105,732
Accepted
Accepted
7.56
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,K = MI() A = [0] + LI() for i in range(K+1,N+1): if A[i] > A[i-K]: print('Yes') else: print('No')
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = [0] + LI() for i in range(K+1,N+1): print(('Yes' if A[i] > A[i-K] else 'No'))
20
9
624
257
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N, K = MI() A = [0] + LI() for i in range(K + 1, N + 1): if A[i] > A[i - K]: print("Yes") else: print("No")
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = [0] + LI() for i in range(K + 1, N + 1): print(("Yes" if A[i] > A[i - K] else "No"))
false
55
[ "-", "-sys.setrecursionlimit(10**7)", "-", "-", "-def I():", "- return int(sys.stdin.readline().rstrip())", "-def LI2():", "- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "-", "-", "-def S():", "- return sys.stdin.readline().rstrip()", "-", "-", "-def LS():", "- return list(sys.stdin.readline().rstrip().split()) # 空白あり", "-", "-", "-def LS2():", "- return list(sys.stdin.readline().rstrip()) # 空白なし", "-", "-", "- if A[i] > A[i - K]:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ print((\"Yes\" if A[i] > A[i - K] else \"No\"))" ]
false
0.042143
0.104249
0.404253
[ "s968851832", "s296486412" ]
u476604182
p03018
python
s753225190
s769145275
66
55
5,476
5,476
Accepted
Accepted
16.67
s = eval(input()) if 'BC' not in s: print((0)) import sys sys.exit() t = s.split('BC') m = 0 ans = 0 for l in t[:-1]: cnt = 0 for i in range(len(l)-1,-1,-1): if l[i]!='A': ans += cnt m = cnt break cnt += 1 else: m += cnt ans += m print(ans)
s = eval(input()) if 'BC' not in s: print((0)) import sys sys.exit() t = s.split('BC') m = 0 ans = 0 for l in t[:-1]: cnt = 0 for c in l[::-1]: if c!='A': ans += cnt m = cnt break cnt += 1 else: m += cnt ans += m print(ans)
20
20
297
280
s = eval(input()) if "BC" not in s: print((0)) import sys sys.exit() t = s.split("BC") m = 0 ans = 0 for l in t[:-1]: cnt = 0 for i in range(len(l) - 1, -1, -1): if l[i] != "A": ans += cnt m = cnt break cnt += 1 else: m += cnt ans += m print(ans)
s = eval(input()) if "BC" not in s: print((0)) import sys sys.exit() t = s.split("BC") m = 0 ans = 0 for l in t[:-1]: cnt = 0 for c in l[::-1]: if c != "A": ans += cnt m = cnt break cnt += 1 else: m += cnt ans += m print(ans)
false
0
[ "- for i in range(len(l) - 1, -1, -1):", "- if l[i] != \"A\":", "+ for c in l[::-1]:", "+ if c != \"A\":" ]
false
0.049473
0.035593
1.389977
[ "s753225190", "s769145275" ]
u188827677
p02785
python
s619649121
s878477613
209
187
25,872
26,764
Accepted
Accepted
10.53
# -*- coding:utf-8 -*- n,k = list(map(int, input().split())) h = [] count = 0 for i in map(int, input().split()): h.append(i) hr = sorted(h, reverse=True) for l in range(n): if l >= k: count += hr[l] print(count)
n,k = list(map(int, input().split())) h = list(map(int, input().split())) h = sorted(h, reverse = True) for i in range(k): if i == n: break h[i] = 0 a = 0 for i in h: a += i print(a)
15
14
236
202
# -*- coding:utf-8 -*- n, k = list(map(int, input().split())) h = [] count = 0 for i in map(int, input().split()): h.append(i) hr = sorted(h, reverse=True) for l in range(n): if l >= k: count += hr[l] print(count)
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h = sorted(h, reverse=True) for i in range(k): if i == n: break h[i] = 0 a = 0 for i in h: a += i print(a)
false
6.666667
[ "-# -*- coding:utf-8 -*-", "-h = []", "-count = 0", "-for i in map(int, input().split()):", "- h.append(i)", "-hr = sorted(h, reverse=True)", "-for l in range(n):", "- if l >= k:", "- count += hr[l]", "-print(count)", "+h = list(map(int, input().split()))", "+h = sorted(h, reverse=True)", "+for i in range(k):", "+ if i == n:", "+ break", "+ h[i] = 0", "+a = 0", "+for i in h:", "+ a += i", "+print(a)" ]
false
0.044396
0.043141
1.02911
[ "s619649121", "s878477613" ]
u605748139
p03053
python
s774664597
s283262613
809
422
176,092
87,900
Accepted
Accepted
47.84
from collections import deque H, W = list(map(int, input().split())) grid = [list(eval(input())) for i in range(H)] # '#'の位置をキューに追加(=今回はこれが複数あるので、複数スタートとなる) black_cells = deque() for h in range(H): for w in range(W): if grid[h][w] == '#': black_cells.append([h, w, 0]) ans = 0 while len(black_cells) > 0: one_black_cell = black_cells.popleft() # キューとして使うのでpop()ではなくpopleft() for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]: nh = one_black_cell[0] + dy nw = one_black_cell[1] + dx d = one_black_cell[2] if nh < 0 or H <= nh or nw < 0 or W <= nw: continue if grid[nh][nw] == '.': grid[nh][nw] = '#' black_cells.append([nh, nw, d + 1]) ans = d print(ans)
from collections import deque H, W = list(map(int, input().split())) grid = [eval(input()) for i in range(H)] # 初期の黒('#')の位置からの距離 dist = [[-1]*W for _ in range(H)] # '#'の位置をキューに追加(=今回はこれが複数あるので、複数スタートとなる) black_cells = deque() for h in range(H): for w in range(W): if grid[h][w] == '#': black_cells.append((h, w)) dist[h][w] = 0 d = 0 while black_cells: # キューとして使うのでpop()ではなくpopleft() h, w = black_cells.popleft() # 黒いセルの座標 d = dist[h][w] for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)): new_h = h + dy new_w = w + dx if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w: continue if dist[new_h][new_w] == -1: # セルが白('.')であるのと同義 dist[new_h][new_w] = d+1 black_cells.append((new_h, new_w)) print(d)
27
31
787
844
from collections import deque H, W = list(map(int, input().split())) grid = [list(eval(input())) for i in range(H)] # '#'の位置をキューに追加(=今回はこれが複数あるので、複数スタートとなる) black_cells = deque() for h in range(H): for w in range(W): if grid[h][w] == "#": black_cells.append([h, w, 0]) ans = 0 while len(black_cells) > 0: one_black_cell = black_cells.popleft() # キューとして使うのでpop()ではなくpopleft() for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]: nh = one_black_cell[0] + dy nw = one_black_cell[1] + dx d = one_black_cell[2] if nh < 0 or H <= nh or nw < 0 or W <= nw: continue if grid[nh][nw] == ".": grid[nh][nw] = "#" black_cells.append([nh, nw, d + 1]) ans = d print(ans)
from collections import deque H, W = list(map(int, input().split())) grid = [eval(input()) for i in range(H)] # 初期の黒('#')の位置からの距離 dist = [[-1] * W for _ in range(H)] # '#'の位置をキューに追加(=今回はこれが複数あるので、複数スタートとなる) black_cells = deque() for h in range(H): for w in range(W): if grid[h][w] == "#": black_cells.append((h, w)) dist[h][w] = 0 d = 0 while black_cells: # キューとして使うのでpop()ではなくpopleft() h, w = black_cells.popleft() # 黒いセルの座標 d = dist[h][w] for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)): new_h = h + dy new_w = w + dx if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w: continue if dist[new_h][new_w] == -1: # セルが白('.')であるのと同義 dist[new_h][new_w] = d + 1 black_cells.append((new_h, new_w)) print(d)
false
12.903226
[ "-grid = [list(eval(input())) for i in range(H)]", "+grid = [eval(input()) for i in range(H)]", "+# 初期の黒('#')の位置からの距離", "+dist = [[-1] * W for _ in range(H)]", "- black_cells.append([h, w, 0])", "-ans = 0", "-while len(black_cells) > 0:", "- one_black_cell = black_cells.popleft() # キューとして使うのでpop()ではなくpopleft()", "- for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:", "- nh = one_black_cell[0] + dy", "- nw = one_black_cell[1] + dx", "- d = one_black_cell[2]", "- if nh < 0 or H <= nh or nw < 0 or W <= nw:", "+ black_cells.append((h, w))", "+ dist[h][w] = 0", "+d = 0", "+while black_cells:", "+ # キューとして使うのでpop()ではなくpopleft()", "+ h, w = black_cells.popleft() # 黒いセルの座標", "+ d = dist[h][w]", "+ for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "+ new_h = h + dy", "+ new_w = w + dx", "+ if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:", "- if grid[nh][nw] == \".\":", "- grid[nh][nw] = \"#\"", "- black_cells.append([nh, nw, d + 1])", "- ans = d", "-print(ans)", "+ if dist[new_h][new_w] == -1: # セルが白('.')であるのと同義", "+ dist[new_h][new_w] = d + 1", "+ black_cells.append((new_h, new_w))", "+print(d)" ]
false
0.037804
0.058166
0.649931
[ "s774664597", "s283262613" ]
u539367121
p02838
python
s655912717
s818690033
1,742
276
50,980
68,804
Accepted
Accepted
84.16
N=int(eval(input())) M=10**9+7 A=[int(x) for x in input().split()] ans=0 for i in range(60): one=sum([a>>i&1 for a in A]) zero=N-one ans+=(one*zero)*pow(2,i,M)%M ans%=M #print(one,zero) print(ans)
import numpy as np N=int(eval(input())) A=np.array([int(x) for x in input().split()]) ans=0 M=pow(10,9)+7 for i in range(100): one=np.sum((A>>i)&1) zero=N-one ans+=(one*zero)%M*pow(2,i,M)%M ans%=M #print(one,zero) print(ans)
12
14
212
243
N = int(eval(input())) M = 10**9 + 7 A = [int(x) for x in input().split()] ans = 0 for i in range(60): one = sum([a >> i & 1 for a in A]) zero = N - one ans += (one * zero) * pow(2, i, M) % M ans %= M # print(one,zero) print(ans)
import numpy as np N = int(eval(input())) A = np.array([int(x) for x in input().split()]) ans = 0 M = pow(10, 9) + 7 for i in range(100): one = np.sum((A >> i) & 1) zero = N - one ans += (one * zero) % M * pow(2, i, M) % M ans %= M # print(one,zero) print(ans)
false
14.285714
[ "+import numpy as np", "+", "-M = 10**9 + 7", "-A = [int(x) for x in input().split()]", "+A = np.array([int(x) for x in input().split()])", "-for i in range(60):", "- one = sum([a >> i & 1 for a in A])", "+M = pow(10, 9) + 7", "+for i in range(100):", "+ one = np.sum((A >> i) & 1)", "- ans += (one * zero) * pow(2, i, M) % M", "+ ans += (one * zero) % M * pow(2, i, M) % M" ]
false
0.044593
0.211058
0.211285
[ "s655912717", "s818690033" ]
u183509493
p02702
python
s792553948
s775467523
362
129
23,448
75,732
Accepted
Accepted
64.36
a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))] s = [0] for x in a: s += [(s[-1] + x) % 2019] cnt, ans = [0] * 2019, 0 for x in s: ans += cnt[x] cnt[x] += 1 print(ans)
# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818 # authored by catamanyan S = list(map(int,eval(input()))) counter = 0 amari = [0]*2019 s = 0 for i in range(len(S)): if S[len(S)-i-1] == 0: continue else: s += S[len(S)-i-1] * pow(10, i, 2019) s = s % 2019 amari[s] += 1 for i in range(2019): counter += amari[i] * (amari[i]-1) / 2 counter += amari[0] print((int(counter)))
9
22
214
467
a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))] s = [0] for x in a: s += [(s[-1] + x) % 2019] cnt, ans = [0] * 2019, 0 for x in s: ans += cnt[x] cnt[x] += 1 print(ans)
# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818 # authored by catamanyan S = list(map(int, eval(input()))) counter = 0 amari = [0] * 2019 s = 0 for i in range(len(S)): if S[len(S) - i - 1] == 0: continue else: s += S[len(S) - i - 1] * pow(10, i, 2019) s = s % 2019 amari[s] += 1 for i in range(2019): counter += amari[i] * (amari[i] - 1) / 2 counter += amari[0] print((int(counter)))
false
59.090909
[ "-a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))]", "-s = [0]", "-for x in a:", "- s += [(s[-1] + x) % 2019]", "-cnt, ans = [0] * 2019, 0", "-for x in s:", "- ans += cnt[x]", "- cnt[x] += 1", "-print(ans)", "+# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818", "+# authored by catamanyan", "+S = list(map(int, eval(input())))", "+counter = 0", "+amari = [0] * 2019", "+s = 0", "+for i in range(len(S)):", "+ if S[len(S) - i - 1] == 0:", "+ continue", "+ else:", "+ s += S[len(S) - i - 1] * pow(10, i, 2019)", "+ s = s % 2019", "+ amari[s] += 1", "+for i in range(2019):", "+ counter += amari[i] * (amari[i] - 1) / 2", "+counter += amari[0]", "+print((int(counter)))" ]
false
0.036387
0.036908
0.985882
[ "s792553948", "s775467523" ]
u112317104
p03494
python
s328731228
s450346334
19
17
3,060
3,064
Accepted
Accepted
10.53
def solve(): N = int(eval(input())) A = list(map(int, input().split())) ans = 0 while True: for i in range(N): if A[i] % 2 != 0: return ans // N A[i] //= 2 ans += 1 return ans print((solve()))
def solve(): N = int(eval(input())) A = list(map(int, input().split())) l = [] for a in A: if a % 2 == 0: c = 0 while a % 2 == 0: a //= 2 c += 1 l.append(c) else: l.append(0) return min(l) print((solve()))
14
18
280
334
def solve(): N = int(eval(input())) A = list(map(int, input().split())) ans = 0 while True: for i in range(N): if A[i] % 2 != 0: return ans // N A[i] //= 2 ans += 1 return ans print((solve()))
def solve(): N = int(eval(input())) A = list(map(int, input().split())) l = [] for a in A: if a % 2 == 0: c = 0 while a % 2 == 0: a //= 2 c += 1 l.append(c) else: l.append(0) return min(l) print((solve()))
false
22.222222
[ "- ans = 0", "- while True:", "- for i in range(N):", "- if A[i] % 2 != 0:", "- return ans // N", "- A[i] //= 2", "- ans += 1", "- return ans", "+ l = []", "+ for a in A:", "+ if a % 2 == 0:", "+ c = 0", "+ while a % 2 == 0:", "+ a //= 2", "+ c += 1", "+ l.append(c)", "+ else:", "+ l.append(0)", "+ return min(l)" ]
false
0.045152
0.045285
0.997079
[ "s328731228", "s450346334" ]
u562935282
p02888
python
s671501160
s033955538
1,999
1,344
3,188
3,188
Accepted
Accepted
32.77
def main(): from bisect import bisect_right N = int(eval(input())) *e, = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += i - bisect_right(e, d, lo=0, hi=i) print(ans) if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip()
def main(): from bisect import bisect_right N = int(eval(input())) *e, = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += max(0, i - bisect_right(e, d)) print(ans) if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip()
27
27
484
478
def main(): from bisect import bisect_right N = int(eval(input())) (*e,) = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += i - bisect_right(e, d, lo=0, hi=i) print(ans) if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip()
def main(): from bisect import bisect_right N = int(eval(input())) (*e,) = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += max(0, i - bisect_right(e, d)) print(ans) if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip()
false
0
[ "- ans += i - bisect_right(e, d, lo=0, hi=i)", "+ ans += max(0, i - bisect_right(e, d))" ]
false
0.037245
0.044265
0.841415
[ "s671501160", "s033955538" ]
u413165887
p03240
python
s144038534
s291254591
49
45
3,064
3,064
Accepted
Accepted
8.16
def check_h(x, y, xy_): difference_h = abs(x-xy_[0]) + abs(y-xy_[1]) return difference_h def main(): n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] for x_, y_, h_ in xyh: if h_ != 0: X, Y, H = x_, y_, h_ break for i in range(101): for j in range(101): xy = [i, j] h = H + check_h(X, Y, xy) if h >= H: if all(xyh[s][2]==max(h-check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n)): print((i, j, h)) break return 0 if __name__=="__main__": main()
def check_h(x, y, xy_): difference_h = abs(x-xy_[0]) + abs(y-xy_[1]) return difference_h def main(): n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] get_h = [xyh[i][2] for i in range(n)] X, Y, H = xyh[get_h.index(max(get_h))] for i in range(101): for j in range(101): xy = [i, j] h = H + check_h(X, Y, xy) if h >= H: if all(xyh[s][2]==max(h-check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n)): print((i, j, h)) break return 0 if __name__=="__main__": main()
25
22
664
647
def check_h(x, y, xy_): difference_h = abs(x - xy_[0]) + abs(y - xy_[1]) return difference_h def main(): n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] for x_, y_, h_ in xyh: if h_ != 0: X, Y, H = x_, y_, h_ break for i in range(101): for j in range(101): xy = [i, j] h = H + check_h(X, Y, xy) if h >= H: if all( xyh[s][2] == max(h - check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n) ): print((i, j, h)) break return 0 if __name__ == "__main__": main()
def check_h(x, y, xy_): difference_h = abs(x - xy_[0]) + abs(y - xy_[1]) return difference_h def main(): n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] get_h = [xyh[i][2] for i in range(n)] X, Y, H = xyh[get_h.index(max(get_h))] for i in range(101): for j in range(101): xy = [i, j] h = H + check_h(X, Y, xy) if h >= H: if all( xyh[s][2] == max(h - check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n) ): print((i, j, h)) break return 0 if __name__ == "__main__": main()
false
12
[ "- for x_, y_, h_ in xyh:", "- if h_ != 0:", "- X, Y, H = x_, y_, h_", "- break", "+ get_h = [xyh[i][2] for i in range(n)]", "+ X, Y, H = xyh[get_h.index(max(get_h))]" ]
false
0.080518
0.077871
1.033983
[ "s144038534", "s291254591" ]
u857293613
p02659
python
s214436529
s192323691
26
23
10,060
9,164
Accepted
Accepted
11.54
import decimal a, b = input().split() a = decimal.Decimal(a) b = decimal.Decimal(b) print((int(a*b)))
a, b = input().split() a = int(a) b = int(b.replace('.', '')) print((a*b//100))
5
4
103
80
import decimal a, b = input().split() a = decimal.Decimal(a) b = decimal.Decimal(b) print((int(a * b)))
a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
false
20
[ "-import decimal", "-", "-a = decimal.Decimal(a)", "-b = decimal.Decimal(b)", "-print((int(a * b)))", "+a = int(a)", "+b = int(b.replace(\".\", \"\"))", "+print((a * b // 100))" ]
false
0.038203
0.036767
1.039056
[ "s214436529", "s192323691" ]
u780475861
p02775
python
s126518733
s463837079
545
384
18,768
18,768
Accepted
Accepted
29.54
n = list(map(int, input()[::-1])) + [0] s = 0 res = 0 for i, ni in enumerate(n[:-1]): k = ni + s if k < 5 or (k == 5 and int(n[i + 1]) < 5): res += k s = 0 else: res += 10 - k s = 1 res += s print(res)
# https://atcoder.jp/contests/abc155/submissions/10175015 def main(): n = list(map(int, input()[::-1])) + [0] s = 0 res = 0 for i, ni in enumerate(n[:-1]): k = ni + s if k < 5 or (k == 5 and int(n[i + 1]) < 5): res += k s = 0 else: res += 10 - k s = 1 res += s print(res) if __name__ == '__main__': main()
13
20
258
427
n = list(map(int, input()[::-1])) + [0] s = 0 res = 0 for i, ni in enumerate(n[:-1]): k = ni + s if k < 5 or (k == 5 and int(n[i + 1]) < 5): res += k s = 0 else: res += 10 - k s = 1 res += s print(res)
# https://atcoder.jp/contests/abc155/submissions/10175015 def main(): n = list(map(int, input()[::-1])) + [0] s = 0 res = 0 for i, ni in enumerate(n[:-1]): k = ni + s if k < 5 or (k == 5 and int(n[i + 1]) < 5): res += k s = 0 else: res += 10 - k s = 1 res += s print(res) if __name__ == "__main__": main()
false
35
[ "-n = list(map(int, input()[::-1])) + [0]", "-s = 0", "-res = 0", "-for i, ni in enumerate(n[:-1]):", "- k = ni + s", "- if k < 5 or (k == 5 and int(n[i + 1]) < 5):", "- res += k", "- s = 0", "- else:", "- res += 10 - k", "- s = 1", "-res += s", "-print(res)", "+# https://atcoder.jp/contests/abc155/submissions/10175015", "+def main():", "+ n = list(map(int, input()[::-1])) + [0]", "+ s = 0", "+ res = 0", "+ for i, ni in enumerate(n[:-1]):", "+ k = ni + s", "+ if k < 5 or (k == 5 and int(n[i + 1]) < 5):", "+ res += k", "+ s = 0", "+ else:", "+ res += 10 - k", "+ s = 1", "+ res += s", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.03834
0.038563
0.994215
[ "s126518733", "s463837079" ]