user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u469226065
p02657
python
s800474646
s049747438
28
25
9,088
8,896
Accepted
Accepted
10.71
# 169A # A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆ # 1. ๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ a, b = list(map(int, input().split())) # print(a, b) # 2. ๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๅ‡ฆ็†๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ answer = a * b # 3.่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ print(answer)
# 169A # A ร— Bใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ A, B = list(map(int, input().split())) # print(A, B) answer = A * B print(answer)
12
8
194
108
# 169A # A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆ # 1. ๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ a, b = list(map(int, input().split())) # print(a, b) # 2. ๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๅ‡ฆ็†๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ answer = a * b # 3.่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ print(answer)
# 169A # A ร— Bใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ A, B = list(map(int, input().split())) # print(A, B) answer = A * B print(answer)
false
33.333333
[ "-# A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆ", "-# 1. ๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ", "-a, b = list(map(int, input().split()))", "-# print(a, b)", "-# 2. ๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๅ‡ฆ็†๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ", "-answer = a * b", "-# 3.่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ", "+# A ร— Bใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚", "+A, B = list(map(int, input().split()))", "+# print(A, B)", "+answer = A * B" ]
false
0.04195
0.007964
5.267209
[ "s800474646", "s049747438" ]
u072717685
p03163
python
s029656162
s461780709
563
405
171,400
58,632
Accepted
Accepted
28.06
n, w = list(map(int, input().split())) things = [] things.append([0,0]) things += [list(map(int, input().split())) for _ in range(n)] dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)] def do_dp(): for i,thing in enumerate(things): dp_1 = dp[i-1] for j in range(1, w + 1): dp[i][j] = dp_1[j-thing[0]] + thing[1] if (j - thing[0]) >= 0 else dp_1[j] dp[i][j] = max(dp[i][j], dp_1[j]) do_dp() print((dp[n][w]))
n, w = list(map(int, input().split())) dp = [0]*(w+1) for _ in range(n): wei, v = list(map(int, input().split())) dp_1 = dp[:] for j in range(w + 1): if j - wei >= 0: dp[j] = dp_1[j-wei] + v if (dp_1[j-wei] + v) > dp_1[j] else dp[j] print((dp[w]))
16
12
451
266
n, w = list(map(int, input().split())) things = [] things.append([0, 0]) things += [list(map(int, input().split())) for _ in range(n)] dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)] def do_dp(): for i, thing in enumerate(things): dp_1 = dp[i - 1] for j in range(1, w + 1): dp[i][j] = dp_1[j - thing[0]] + thing[1] if (j - thing[0]) >= 0 else dp_1[j] dp[i][j] = max(dp[i][j], dp_1[j]) do_dp() print((dp[n][w]))
n, w = list(map(int, input().split())) dp = [0] * (w + 1) for _ in range(n): wei, v = list(map(int, input().split())) dp_1 = dp[:] for j in range(w + 1): if j - wei >= 0: dp[j] = dp_1[j - wei] + v if (dp_1[j - wei] + v) > dp_1[j] else dp[j] print((dp[w]))
false
25
[ "-things = []", "-things.append([0, 0])", "-things += [list(map(int, input().split())) for _ in range(n)]", "-dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]", "-", "-", "-def do_dp():", "- for i, thing in enumerate(things):", "- dp_1 = dp[i - 1]", "- for j in range(1, w + 1):", "- dp[i][j] = dp_1[j - thing[0]] + thing[1] if (j - thing[0]) >= 0 else dp_1[j]", "- dp[i][j] = max(dp[i][j], dp_1[j])", "-", "-", "-do_dp()", "-print((dp[n][w]))", "+dp = [0] * (w + 1)", "+for _ in range(n):", "+ wei, v = list(map(int, input().split()))", "+ dp_1 = dp[:]", "+ for j in range(w + 1):", "+ if j - wei >= 0:", "+ dp[j] = dp_1[j - wei] + v if (dp_1[j - wei] + v) > dp_1[j] else dp[j]", "+print((dp[w]))" ]
false
0.047243
0.121362
0.389276
[ "s029656162", "s461780709" ]
u057109575
p02866
python
s829919388
s434388656
234
120
62,008
98,160
Accepted
Accepted
48.72
from collections import Counter N, *D = list(map(int, open(0).read().split())) MOD = 998244353 ctr = Counter(D) ans = 1 for i in range(1, max(ctr) + 1): ans = ans * ctr[i - 1] ** ctr[i] % MOD if ctr[0] == 1 and D[0] == 0: print(ans) else: print((0))
from collections import Counter N = int(eval(input())) X = list(map(int, input().split())) MOD = 998244353 ctr = Counter(X) if X[0] == 0 and ctr[0] == 1: ans = 1 for i in range(1, max(X) + 1): ans *= pow(ctr[i - 1], ctr[i], MOD) ans %= MOD print(ans) else: print((0))
13
17
268
312
from collections import Counter N, *D = list(map(int, open(0).read().split())) MOD = 998244353 ctr = Counter(D) ans = 1 for i in range(1, max(ctr) + 1): ans = ans * ctr[i - 1] ** ctr[i] % MOD if ctr[0] == 1 and D[0] == 0: print(ans) else: print((0))
from collections import Counter N = int(eval(input())) X = list(map(int, input().split())) MOD = 998244353 ctr = Counter(X) if X[0] == 0 and ctr[0] == 1: ans = 1 for i in range(1, max(X) + 1): ans *= pow(ctr[i - 1], ctr[i], MOD) ans %= MOD print(ans) else: print((0))
false
23.529412
[ "-N, *D = list(map(int, open(0).read().split()))", "+N = int(eval(input()))", "+X = list(map(int, input().split()))", "-ctr = Counter(D)", "-ans = 1", "-for i in range(1, max(ctr) + 1):", "- ans = ans * ctr[i - 1] ** ctr[i] % MOD", "-if ctr[0] == 1 and D[0] == 0:", "+ctr = Counter(X)", "+if X[0] == 0 and ctr[0] == 1:", "+ ans = 1", "+ for i in range(1, max(X) + 1):", "+ ans *= pow(ctr[i - 1], ctr[i], MOD)", "+ ans %= MOD" ]
false
0.04199
0.036581
1.147867
[ "s829919388", "s434388656" ]
u764600134
p03148
python
s381751646
s478464328
816
557
85,336
36,600
Accepted
Accepted
31.74
# -*- coding: utf-8 -*- """ D - Various Sushi https://atcoder.jp/contests/abc116/tasks/abc116_d """ import sys from collections import Counter def solve(N, K, sushi): sushi.sort(key=lambda x: x[1], reverse=True) pick = sushi[:K] # ใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใฎ้ซ˜ใ„ๆ–นใ‹ใ‚‰Kๅ€‹ใฎๅฏฟๅธใ‚’้ธๆŠž pick_type = set([t for t, d in pick]) # ้ธๆŠžๆธˆใฎ็จฎ้กž cnt = Counter() # ๅ„็จฎ้กžใฎๅฏฟๅธใŒไฝ•ๅ€‹ใšใคใ‚ใ‚‹ใ‹่ฆšใˆใฆใŠใ for t, d in pick: cnt[t] += 1 rem = dict() # ๆœช้ธๆŠžใฎ็จฎ้กžใฎๅฏฟๅธใฎใ†ใกใ€ไธ€็•ชใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใŒ้ซ˜ใ„็‰ฉ for t, d in sushi: if t not in pick_type: rem[t] = max(rem.get(t, 0), d) res = sorted([[k, v] for k, v in list(rem.items())], key=lambda x: x[1]) # ใŠใ„ใ—ใ•ใงๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ(ไธ€็•ชใŠใ„ใ—ใ„็‰ฉใŒๆœซๅฐพ) manzoku = sum([d for t, d in pick]) ans = [manzoku + len(pick_type)**2] # ็พๅœจใฎ้ธๆŠžใงใฎใ‚นใ‚ณใ‚ขใ€ใ“ใ“ใ‹ใ‚‰็จฎ้กžใ‚’1ใคใšใคๅข—ๅŠ ใ•ใ›ใฆใ„ใใ‚นใ‚ณใ‚ขใ‚’่จˆ็ฎ—ใ™ใ‚‹ while len(pick_type) < K and pick and res: t, d = res.pop() pick_type.add(t) tt, dd = pick.pop() while cnt[tt] == 1 and pick: tt, dd = pick.pop() if cnt[tt] > 1: cnt[tt] -= 1 manzoku = manzoku - dd + d ans.append(manzoku+ len(pick_type)**2) return max(ans) def main(args): N, K = list(map(int, input().split())) sushi = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, K, sushi) print(ans) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ D - Various Sushi https://atcoder.jp/contests/abc116/tasks/abc116_d AC """ import sys from collections import Counter def solve(N, K, sushi): sushi.sort(key=lambda x: x[1], reverse=True) pick = sushi[:K] # ใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใฎ้ซ˜ใ„ๆ–นใ‹ใ‚‰Kๅ€‹ใฎๅฏฟๅธใ‚’้ธๆŠž pick_type = set([t for t, d in pick]) # ้ธๆŠžๆธˆใฎ็จฎ้กž cnt = Counter() # ๅ„็จฎ้กžใฎๅฏฟๅธใŒไฝ•ๅ€‹ใšใคใ‚ใ‚‹ใ‹่ฆšใˆใฆใŠใ for t, d in pick: cnt[t] += 1 rem = dict() # ๆœช้ธๆŠžใฎ็จฎ้กžใฎๅฏฟๅธใฎใ†ใกใ€ไธ€็•ชใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใŒ้ซ˜ใ„็‰ฉ for t, d in sushi: if t not in pick_type: rem[t] = max(rem.get(t, 0), d) res = sorted([[k, v] for k, v in list(rem.items())], key=lambda x: x[1]) # ใŠใ„ใ—ใ•ใงๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ(ไธ€็•ชใŠใ„ใ—ใ„็‰ฉใŒๆœซๅฐพ) manzoku = sum([d for t, d in pick]) ans = [manzoku + len(pick_type)**2] # ็พๅœจใฎ้ธๆŠžใงใฎใ‚นใ‚ณใ‚ขใ€ใ“ใ“ใ‹ใ‚‰็จฎ้กžใ‚’1ใคใšใคๅข—ๅŠ ใ•ใ›ใฆใ„ใใ‚นใ‚ณใ‚ขใ‚’่จˆ็ฎ—ใ™ใ‚‹ while len(pick_type) < K and pick and res: t, d = res.pop() pick_type.add(t) tt, dd = pick.pop() while cnt[tt] == 1 and pick: tt, dd = pick.pop() if cnt[tt] > 1: cnt[tt] -= 1 manzoku = manzoku - dd + d ans.append(manzoku+ len(pick_type)**2) return max(ans) def main(args): N, K = list(map(int, input().split())) sushi = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, K, sushi) print(ans) if __name__ == '__main__': main(sys.argv[1:])
49
49
1,424
1,426
# -*- coding: utf-8 -*- """ D - Various Sushi https://atcoder.jp/contests/abc116/tasks/abc116_d """ import sys from collections import Counter def solve(N, K, sushi): sushi.sort(key=lambda x: x[1], reverse=True) pick = sushi[:K] # ใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใฎ้ซ˜ใ„ๆ–นใ‹ใ‚‰Kๅ€‹ใฎๅฏฟๅธใ‚’้ธๆŠž pick_type = set([t for t, d in pick]) # ้ธๆŠžๆธˆใฎ็จฎ้กž cnt = Counter() # ๅ„็จฎ้กžใฎๅฏฟๅธใŒไฝ•ๅ€‹ใšใคใ‚ใ‚‹ใ‹่ฆšใˆใฆใŠใ for t, d in pick: cnt[t] += 1 rem = dict() # ๆœช้ธๆŠžใฎ็จฎ้กžใฎๅฏฟๅธใฎใ†ใกใ€ไธ€็•ชใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใŒ้ซ˜ใ„็‰ฉ for t, d in sushi: if t not in pick_type: rem[t] = max(rem.get(t, 0), d) res = sorted( [[k, v] for k, v in list(rem.items())], key=lambda x: x[1] ) # ใŠใ„ใ—ใ•ใงๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ(ไธ€็•ชใŠใ„ใ—ใ„็‰ฉใŒๆœซๅฐพ) manzoku = sum([d for t, d in pick]) ans = [manzoku + len(pick_type) ** 2] # ็พๅœจใฎ้ธๆŠžใงใฎใ‚นใ‚ณใ‚ขใ€ใ“ใ“ใ‹ใ‚‰็จฎ้กžใ‚’1ใคใšใคๅข—ๅŠ ใ•ใ›ใฆใ„ใใ‚นใ‚ณใ‚ขใ‚’่จˆ็ฎ—ใ™ใ‚‹ while len(pick_type) < K and pick and res: t, d = res.pop() pick_type.add(t) tt, dd = pick.pop() while cnt[tt] == 1 and pick: tt, dd = pick.pop() if cnt[tt] > 1: cnt[tt] -= 1 manzoku = manzoku - dd + d ans.append(manzoku + len(pick_type) ** 2) return max(ans) def main(args): N, K = list(map(int, input().split())) sushi = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, K, sushi) print(ans) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ D - Various Sushi https://atcoder.jp/contests/abc116/tasks/abc116_d AC """ import sys from collections import Counter def solve(N, K, sushi): sushi.sort(key=lambda x: x[1], reverse=True) pick = sushi[:K] # ใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใฎ้ซ˜ใ„ๆ–นใ‹ใ‚‰Kๅ€‹ใฎๅฏฟๅธใ‚’้ธๆŠž pick_type = set([t for t, d in pick]) # ้ธๆŠžๆธˆใฎ็จฎ้กž cnt = Counter() # ๅ„็จฎ้กžใฎๅฏฟๅธใŒไฝ•ๅ€‹ใšใคใ‚ใ‚‹ใ‹่ฆšใˆใฆใŠใ for t, d in pick: cnt[t] += 1 rem = dict() # ๆœช้ธๆŠžใฎ็จฎ้กžใฎๅฏฟๅธใฎใ†ใกใ€ไธ€็•ชใŠใ„ใ—ใ•ใƒใ‚คใƒณใƒˆใŒ้ซ˜ใ„็‰ฉ for t, d in sushi: if t not in pick_type: rem[t] = max(rem.get(t, 0), d) res = sorted( [[k, v] for k, v in list(rem.items())], key=lambda x: x[1] ) # ใŠใ„ใ—ใ•ใงๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ(ไธ€็•ชใŠใ„ใ—ใ„็‰ฉใŒๆœซๅฐพ) manzoku = sum([d for t, d in pick]) ans = [manzoku + len(pick_type) ** 2] # ็พๅœจใฎ้ธๆŠžใงใฎใ‚นใ‚ณใ‚ขใ€ใ“ใ“ใ‹ใ‚‰็จฎ้กžใ‚’1ใคใšใคๅข—ๅŠ ใ•ใ›ใฆใ„ใใ‚นใ‚ณใ‚ขใ‚’่จˆ็ฎ—ใ™ใ‚‹ while len(pick_type) < K and pick and res: t, d = res.pop() pick_type.add(t) tt, dd = pick.pop() while cnt[tt] == 1 and pick: tt, dd = pick.pop() if cnt[tt] > 1: cnt[tt] -= 1 manzoku = manzoku - dd + d ans.append(manzoku + len(pick_type) ** 2) return max(ans) def main(args): N, K = list(map(int, input().split())) sushi = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, K, sushi) print(ans) if __name__ == "__main__": main(sys.argv[1:])
false
0
[ "+AC" ]
false
0.03954
0.039241
1.007616
[ "s381751646", "s478464328" ]
u046187684
p03287
python
s164098861
s205219276
236
73
69,272
15,524
Accepted
Accepted
69.07
from collections import Counter from itertools import accumulate def solve(string): n, m, *a = list(map(int, string.split())) a = list(accumulate(a)) d = Counter(_a % m for _a in a) ans = d[0] ans += sum(v * (v - 1) // 2 for v in list(d.values())) return str(ans) if __name__ == '__main__': print((solve('\n'.join([eval(input()), eval(input())]))))
from collections import Counter from itertools import accumulate def solve(string): n, m, *a = list(map(int, string.split())) d = Counter(_a % m for _a in accumulate([0] + a)) return str(sum(v * (v - 1) // 2 for v in list(d.values()))) if __name__ == '__main__': print((solve('\n'.join([eval(input()), eval(input())]))))
16
12
371
326
from collections import Counter from itertools import accumulate def solve(string): n, m, *a = list(map(int, string.split())) a = list(accumulate(a)) d = Counter(_a % m for _a in a) ans = d[0] ans += sum(v * (v - 1) // 2 for v in list(d.values())) return str(ans) if __name__ == "__main__": print((solve("\n".join([eval(input()), eval(input())]))))
from collections import Counter from itertools import accumulate def solve(string): n, m, *a = list(map(int, string.split())) d = Counter(_a % m for _a in accumulate([0] + a)) return str(sum(v * (v - 1) // 2 for v in list(d.values()))) if __name__ == "__main__": print((solve("\n".join([eval(input()), eval(input())]))))
false
25
[ "- a = list(accumulate(a))", "- d = Counter(_a % m for _a in a)", "- ans = d[0]", "- ans += sum(v * (v - 1) // 2 for v in list(d.values()))", "- return str(ans)", "+ d = Counter(_a % m for _a in accumulate([0] + a))", "+ return str(sum(v * (v - 1) // 2 for v in list(d.values())))" ]
false
0.070756
0.037409
1.89144
[ "s164098861", "s205219276" ]
u860002137
p02803
python
s952980410
s774608051
511
386
3,572
3,572
Accepted
Accepted
24.46
import copy from collections import deque H, W = list(map(int, input().split())) field_s = [] # ใƒ•ใ‚ฃใƒผใƒซใƒ‰ใ‚’ไฝœใ‚‹ for h in range(H + 2): field_s.append(["#"] * (W + 2)) if 1 <= h <= (H): field_s[h][1:-1] = list(map(str, input().rstrip())) #ใ€€ๅ‹•ใๆ–นใฎใ‚ปใƒƒใƒˆใ‚’ๆบ–ๅ‚™ moves = [[1, 0], [-1, 0], [0, 1], [0, -1]] # ใ‚นใ‚ฟใƒผใƒˆๅบงๆจ™ใ‚’ๅ–ๅพ— start = [] for y in range(1, H + 1): for x in range(1, W + 1): if field_s[y][x] == ".": start.append([y, x]) # ็ญ”ใˆ ans = 0 for s in start: # fieldใฎๅˆๆœŸๅŒ– field = copy.deepcopy(field_s) # startใ‚’ใ‚ญใƒฅใƒผใซ่ฟฝๅŠ  que = deque([s]) # startใฎ่ท้›ขใฏ0ใซ field[s[0]][s[1]] = 0 # ใ‚ญใƒฅใƒผใซไฝ•ใ‹ใŒใ‚ใ‚‹้™ใ‚ŠๆŽข็ดขใ‚’็ถšใ‘ใ‚‹ while que: c = que.popleft() # ไปŠใฎ่ท้›ข dist = field[c[0]][c[1]] # ๅ‹•ใ„ใŸๅ…ˆใŒใ€Œ.ใ€ใชใ‚‰ใ€่ท้›ขใ‚’่จ˜้Œฒใ—ใฆใ‚ญใƒฅใƒผใซ่ฟฝๅŠ  for m in moves: my = c[0] + m[0] mx = c[1] + m[1] if field[my][mx] == ".": field[my][mx] = dist + 1 que.append([my, mx]) else: continue # ใ‚ญใƒฅใƒผใ‚’ๆถˆๅŒ–ใ—ใŸใ‚‰ๆœ€ๅคงๅ€คใ‚’ๅ–ใ‚Šๅ‡บใ™ field = sum(field, []) ans = max(ans, max([x for x in field if type(x) == int])) print(ans)
import copy from collections import deque def bfs(s, f): f[s[0]][s[1]] = 0 moves = [[1, 0], [-1, 0], [0, 1], [0, -1]] q = deque([s]) while q: c = q.popleft() for m in moves: my, mx = c[0] + m[0], c[1] + m[1] if f[my][mx] == ".": f[my][mx] = f[c[0]][c[1]] + 1 q.append([my, mx]) else: continue f = sum(f, []) return max([x for x in f if type(x) == int]) def main(): H, W = list(map(int, input().split())) field_s = [] for h in range(H + 2): field_s.append(["#"] * (W + 2)) if 1 <= h <= (H): field_s[h][1:-1] = list(map(str, input().rstrip())) start = [] for y in range(1, H + 1): for x in range(1, W + 1): if field_s[y][x] == ".": start.append([y, x]) ans = 0 for s in start: field = copy.deepcopy(field_s) ans = max(ans, bfs(s, field)) print(ans) if __name__ == '__main__': main()
59
49
1,189
1,075
import copy from collections import deque H, W = list(map(int, input().split())) field_s = [] # ใƒ•ใ‚ฃใƒผใƒซใƒ‰ใ‚’ไฝœใ‚‹ for h in range(H + 2): field_s.append(["#"] * (W + 2)) if 1 <= h <= (H): field_s[h][1:-1] = list(map(str, input().rstrip())) # ใ€€ๅ‹•ใๆ–นใฎใ‚ปใƒƒใƒˆใ‚’ๆบ–ๅ‚™ moves = [[1, 0], [-1, 0], [0, 1], [0, -1]] # ใ‚นใ‚ฟใƒผใƒˆๅบงๆจ™ใ‚’ๅ–ๅพ— start = [] for y in range(1, H + 1): for x in range(1, W + 1): if field_s[y][x] == ".": start.append([y, x]) # ็ญ”ใˆ ans = 0 for s in start: # fieldใฎๅˆๆœŸๅŒ– field = copy.deepcopy(field_s) # startใ‚’ใ‚ญใƒฅใƒผใซ่ฟฝๅŠ  que = deque([s]) # startใฎ่ท้›ขใฏ0ใซ field[s[0]][s[1]] = 0 # ใ‚ญใƒฅใƒผใซไฝ•ใ‹ใŒใ‚ใ‚‹้™ใ‚ŠๆŽข็ดขใ‚’็ถšใ‘ใ‚‹ while que: c = que.popleft() # ไปŠใฎ่ท้›ข dist = field[c[0]][c[1]] # ๅ‹•ใ„ใŸๅ…ˆใŒใ€Œ.ใ€ใชใ‚‰ใ€่ท้›ขใ‚’่จ˜้Œฒใ—ใฆใ‚ญใƒฅใƒผใซ่ฟฝๅŠ  for m in moves: my = c[0] + m[0] mx = c[1] + m[1] if field[my][mx] == ".": field[my][mx] = dist + 1 que.append([my, mx]) else: continue # ใ‚ญใƒฅใƒผใ‚’ๆถˆๅŒ–ใ—ใŸใ‚‰ๆœ€ๅคงๅ€คใ‚’ๅ–ใ‚Šๅ‡บใ™ field = sum(field, []) ans = max(ans, max([x for x in field if type(x) == int])) print(ans)
import copy from collections import deque def bfs(s, f): f[s[0]][s[1]] = 0 moves = [[1, 0], [-1, 0], [0, 1], [0, -1]] q = deque([s]) while q: c = q.popleft() for m in moves: my, mx = c[0] + m[0], c[1] + m[1] if f[my][mx] == ".": f[my][mx] = f[c[0]][c[1]] + 1 q.append([my, mx]) else: continue f = sum(f, []) return max([x for x in f if type(x) == int]) def main(): H, W = list(map(int, input().split())) field_s = [] for h in range(H + 2): field_s.append(["#"] * (W + 2)) if 1 <= h <= (H): field_s[h][1:-1] = list(map(str, input().rstrip())) start = [] for y in range(1, H + 1): for x in range(1, W + 1): if field_s[y][x] == ".": start.append([y, x]) ans = 0 for s in start: field = copy.deepcopy(field_s) ans = max(ans, bfs(s, field)) print(ans) if __name__ == "__main__": main()
false
16.949153
[ "-H, W = list(map(int, input().split()))", "-field_s = []", "-# ใƒ•ใ‚ฃใƒผใƒซใƒ‰ใ‚’ไฝœใ‚‹", "-for h in range(H + 2):", "- field_s.append([\"#\"] * (W + 2))", "- if 1 <= h <= (H):", "- field_s[h][1:-1] = list(map(str, input().rstrip()))", "-# ใ€€ๅ‹•ใๆ–นใฎใ‚ปใƒƒใƒˆใ‚’ๆบ–ๅ‚™", "-moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]", "-# ใ‚นใ‚ฟใƒผใƒˆๅบงๆจ™ใ‚’ๅ–ๅพ—", "-start = []", "-for y in range(1, H + 1):", "- for x in range(1, W + 1):", "- if field_s[y][x] == \".\":", "- start.append([y, x])", "-# ็ญ”ใˆ", "-ans = 0", "-for s in start:", "- # fieldใฎๅˆๆœŸๅŒ–", "- field = copy.deepcopy(field_s)", "- # startใ‚’ใ‚ญใƒฅใƒผใซ่ฟฝๅŠ ", "- que = deque([s])", "- # startใฎ่ท้›ขใฏ0ใซ", "- field[s[0]][s[1]] = 0", "- # ใ‚ญใƒฅใƒผใซไฝ•ใ‹ใŒใ‚ใ‚‹้™ใ‚ŠๆŽข็ดขใ‚’็ถšใ‘ใ‚‹", "- while que:", "- c = que.popleft()", "- # ไปŠใฎ่ท้›ข", "- dist = field[c[0]][c[1]]", "- # ๅ‹•ใ„ใŸๅ…ˆใŒใ€Œ.ใ€ใชใ‚‰ใ€่ท้›ขใ‚’่จ˜้Œฒใ—ใฆใ‚ญใƒฅใƒผใซ่ฟฝๅŠ ", "+", "+def bfs(s, f):", "+ f[s[0]][s[1]] = 0", "+ moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]", "+ q = deque([s])", "+ while q:", "+ c = q.popleft()", "- my = c[0] + m[0]", "- mx = c[1] + m[1]", "- if field[my][mx] == \".\":", "- field[my][mx] = dist + 1", "- que.append([my, mx])", "+ my, mx = c[0] + m[0], c[1] + m[1]", "+ if f[my][mx] == \".\":", "+ f[my][mx] = f[c[0]][c[1]] + 1", "+ q.append([my, mx])", "- # ใ‚ญใƒฅใƒผใ‚’ๆถˆๅŒ–ใ—ใŸใ‚‰ๆœ€ๅคงๅ€คใ‚’ๅ–ใ‚Šๅ‡บใ™", "- field = sum(field, [])", "- ans = max(ans, max([x for x in field if type(x) == int]))", "-print(ans)", "+ f = sum(f, [])", "+ return max([x for x in f if type(x) == int])", "+", "+", "+def main():", "+ H, W = list(map(int, input().split()))", "+ field_s = []", "+ for h in range(H + 2):", "+ field_s.append([\"#\"] * (W + 2))", "+ if 1 <= h <= (H):", "+ field_s[h][1:-1] = list(map(str, input().rstrip()))", "+ start = []", "+ for y in range(1, H + 1):", "+ for x in range(1, W + 1):", "+ if field_s[y][x] == \".\":", "+ start.append([y, x])", "+ ans = 0", "+ for s in start:", "+ field = copy.deepcopy(field_s)", "+ ans = max(ans, bfs(s, field))", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045859
0.045762
1.002117
[ "s952980410", "s774608051" ]
u941753895
p03828
python
s490860772
s780264972
58
48
6,484
5,840
Accepted
Accepted
17.24
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) # Factoring by trial split def getPrimeList(n): l=[] t=int(math.sqrt(n))+1 for a in range(2,t): while n%a==0: n//=a l.append(a) if n!=1: l.append(n) return l def main(): l=[0]*1001 n=I() for i in range(2,n+1): x=getPrimeList(i) for j in x: l[j]+=1 sm=1 for i in l: sm*=i+1 return sm%mod print((main()))
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) # Factoring by trial split def getPrimeList(n): l=[] t=int(math.sqrt(n))+1 for a in range(2,t): while n%a==0: n//=a l.append(a) if n!=1: l.append(n) return l def main(): n=I() l=[0]*1001 for i in range(2,n+1): y=getPrimeList(i) for x in y: l[x]+=1 sm=1 for x in l: if x!=0: sm*=x+1 return sm%mod print((main()))
43
44
696
712
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) # Factoring by trial split def getPrimeList(n): l = [] t = int(math.sqrt(n)) + 1 for a in range(2, t): while n % a == 0: n //= a l.append(a) if n != 1: l.append(n) return l def main(): l = [0] * 1001 n = I() for i in range(2, n + 1): x = getPrimeList(i) for j in x: l[j] += 1 sm = 1 for i in l: sm *= i + 1 return sm % mod print((main()))
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) # Factoring by trial split def getPrimeList(n): l = [] t = int(math.sqrt(n)) + 1 for a in range(2, t): while n % a == 0: n //= a l.append(a) if n != 1: l.append(n) return l def main(): n = I() l = [0] * 1001 for i in range(2, n + 1): y = getPrimeList(i) for x in y: l[x] += 1 sm = 1 for x in l: if x != 0: sm *= x + 1 return sm % mod print((main()))
false
2.272727
[ "+ n = I()", "- n = I()", "- x = getPrimeList(i)", "- for j in x:", "- l[j] += 1", "+ y = getPrimeList(i)", "+ for x in y:", "+ l[x] += 1", "- for i in l:", "- sm *= i + 1", "+ for x in l:", "+ if x != 0:", "+ sm *= x + 1" ]
false
0.04773
0.089753
0.531799
[ "s490860772", "s780264972" ]
u086566114
p02412
python
s222732998
s243903556
560
450
6,416
6,416
Accepted
Accepted
19.64
while True: [n, m] = [int(x) for x in input().split()] if [n, m] == [0, 0]: break hoge = list(range(1, n + 1)) data = [] for x in range(n - 1, 1, -1): for y in range(x - 1, 0, -1): for z in range(y - 1, -1, -1): # print((x, y, z)) s = hoge[x] + hoge[y] + hoge[z] if s < m: break if s == m: data.append(s) print((len(data)))
while True: [n, m] = [int(x) for x in input().split()] if [n, m] == [0, 0]: break data = [] for x in range(n, 2, -1): for y in range(x - 1, 1, -1): for z in range(y - 1, 0, -1): s = x + y + z if s < m: break if s == m: data.append(s) print((len(data)))
19
16
496
407
while True: [n, m] = [int(x) for x in input().split()] if [n, m] == [0, 0]: break hoge = list(range(1, n + 1)) data = [] for x in range(n - 1, 1, -1): for y in range(x - 1, 0, -1): for z in range(y - 1, -1, -1): # print((x, y, z)) s = hoge[x] + hoge[y] + hoge[z] if s < m: break if s == m: data.append(s) print((len(data)))
while True: [n, m] = [int(x) for x in input().split()] if [n, m] == [0, 0]: break data = [] for x in range(n, 2, -1): for y in range(x - 1, 1, -1): for z in range(y - 1, 0, -1): s = x + y + z if s < m: break if s == m: data.append(s) print((len(data)))
false
15.789474
[ "- hoge = list(range(1, n + 1))", "- for x in range(n - 1, 1, -1):", "- for y in range(x - 1, 0, -1):", "- for z in range(y - 1, -1, -1):", "- # print((x, y, z))", "- s = hoge[x] + hoge[y] + hoge[z]", "+ for x in range(n, 2, -1):", "+ for y in range(x - 1, 1, -1):", "+ for z in range(y - 1, 0, -1):", "+ s = x + y + z" ]
false
0.046707
0.037292
1.252478
[ "s222732998", "s243903556" ]
u072717685
p02861
python
s028083006
s208107440
405
76
3,188
3,188
Accepted
Accepted
81.23
from math import factorial from itertools import permutations def main(): n = int(eval(input())) town_coor = [] for _ in range(n): town_coor.append(tuple(map(int, input().split()))) towns = [i for i in range(n)] roads = permutations(towns, n) sum_roads = 0 for road in roads: sum_road = 0 for i1 in range(n-1): sum_road += ((town_coor[road[i1]][0] - town_coor[road[i1 +1]][0])**2 + (town_coor[road[i1]][1] - town_coor[road[i1 +1]][1])**2)**0.5 sum_roads += sum_road print((sum_roads / factorial(n))) if __name__ == '__main__': main()
from math import factorial from itertools import permutations def main(): n = int(eval(input())) town_coor = [] for _ in range(n): town_coor.append(tuple(map(int, input().split()))) dists = [[0]*n for _ in range(n)] for j1 in range(n): for j2 in range(n): dists[j1][j2] = ((town_coor[j1][0] - town_coor[j2][0])**2 + (town_coor[j1][1] - town_coor[j2][1])**2)**0.5 towns = [i for i in range(n)] roads = permutations(towns, n) sum_roads = 0 for road in roads: sum_road = 0 for i1 in range(n-1): sum_road += dists[road[i1]][road[i1+1]] sum_roads += sum_road print((sum_roads / factorial(n))) if __name__ == '__main__': main()
20
26
627
751
from math import factorial from itertools import permutations def main(): n = int(eval(input())) town_coor = [] for _ in range(n): town_coor.append(tuple(map(int, input().split()))) towns = [i for i in range(n)] roads = permutations(towns, n) sum_roads = 0 for road in roads: sum_road = 0 for i1 in range(n - 1): sum_road += ( (town_coor[road[i1]][0] - town_coor[road[i1 + 1]][0]) ** 2 + (town_coor[road[i1]][1] - town_coor[road[i1 + 1]][1]) ** 2 ) ** 0.5 sum_roads += sum_road print((sum_roads / factorial(n))) if __name__ == "__main__": main()
from math import factorial from itertools import permutations def main(): n = int(eval(input())) town_coor = [] for _ in range(n): town_coor.append(tuple(map(int, input().split()))) dists = [[0] * n for _ in range(n)] for j1 in range(n): for j2 in range(n): dists[j1][j2] = ( (town_coor[j1][0] - town_coor[j2][0]) ** 2 + (town_coor[j1][1] - town_coor[j2][1]) ** 2 ) ** 0.5 towns = [i for i in range(n)] roads = permutations(towns, n) sum_roads = 0 for road in roads: sum_road = 0 for i1 in range(n - 1): sum_road += dists[road[i1]][road[i1 + 1]] sum_roads += sum_road print((sum_roads / factorial(n))) if __name__ == "__main__": main()
false
23.076923
[ "+ dists = [[0] * n for _ in range(n)]", "+ for j1 in range(n):", "+ for j2 in range(n):", "+ dists[j1][j2] = (", "+ (town_coor[j1][0] - town_coor[j2][0]) ** 2", "+ + (town_coor[j1][1] - town_coor[j2][1]) ** 2", "+ ) ** 0.5", "- sum_road += (", "- (town_coor[road[i1]][0] - town_coor[road[i1 + 1]][0]) ** 2", "- + (town_coor[road[i1]][1] - town_coor[road[i1 + 1]][1]) ** 2", "- ) ** 0.5", "+ sum_road += dists[road[i1]][road[i1 + 1]]" ]
false
0.039577
0.116061
0.341003
[ "s028083006", "s208107440" ]
u504836877
p02953
python
s101645730
s993897284
130
86
15,300
14,224
Accepted
Accepted
33.85
N = int(eval(input())) H = [int(h) for h in input().split()] if N == 1: ans = "Yes" else: c = 0 while c <= N-2: if H[c] < H[c+1]: H[c+1] -= 1 c += 1 List = [] for j in range(N): List.append(H[j]) List.sort() if List == H: ans = "Yes" else: ans = "No" print(ans)
N = int(eval(input())) H = [int(h) for h in input().split()] ans = "Yes" for i in range(1, N-1): if H[i] > H[i-1]: H[i] -= 1 if H[i] > H[i+1]: ans = "No" break print(ans)
21
11
361
207
N = int(eval(input())) H = [int(h) for h in input().split()] if N == 1: ans = "Yes" else: c = 0 while c <= N - 2: if H[c] < H[c + 1]: H[c + 1] -= 1 c += 1 List = [] for j in range(N): List.append(H[j]) List.sort() if List == H: ans = "Yes" else: ans = "No" print(ans)
N = int(eval(input())) H = [int(h) for h in input().split()] ans = "Yes" for i in range(1, N - 1): if H[i] > H[i - 1]: H[i] -= 1 if H[i] > H[i + 1]: ans = "No" break print(ans)
false
47.619048
[ "-if N == 1:", "- ans = \"Yes\"", "-else:", "- c = 0", "- while c <= N - 2:", "- if H[c] < H[c + 1]:", "- H[c + 1] -= 1", "- c += 1", "- List = []", "- for j in range(N):", "- List.append(H[j])", "- List.sort()", "- if List == H:", "- ans = \"Yes\"", "- else:", "+ans = \"Yes\"", "+for i in range(1, N - 1):", "+ if H[i] > H[i - 1]:", "+ H[i] -= 1", "+ if H[i] > H[i + 1]:", "+ break" ]
false
0.078171
0.034561
2.261843
[ "s101645730", "s993897284" ]
u652656291
p03457
python
s512755079
s724991739
393
344
11,636
3,060
Accepted
Accepted
12.47
N = int(eval(input())) t = [0] * (N+1) x = [0] * (N+1) y = [0] * (N+1) for i in range(N): t[i+1], x[i+1], y[i+1] = list(map(int, input().split())) f = True for i in range(N): dt = t[i+1] - t[i] dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]) if dt < dist: f = False if dist%2 != dt%2: f = False print(('Yes' if f else 'No'))
n = int(eval(input())) for i in range(n): t,x,y=list(map(int,input().split())) if (x + y) > t or (x + y + t) % 2: print("No") exit() print("Yes")
17
7
359
164
N = int(eval(input())) t = [0] * (N + 1) x = [0] * (N + 1) y = [0] * (N + 1) for i in range(N): t[i + 1], x[i + 1], y[i + 1] = list(map(int, input().split())) f = True for i in range(N): dt = t[i + 1] - t[i] dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) if dt < dist: f = False if dist % 2 != dt % 2: f = False print(("Yes" if f else "No"))
n = int(eval(input())) for i in range(n): t, x, y = list(map(int, input().split())) if (x + y) > t or (x + y + t) % 2: print("No") exit() print("Yes")
false
58.823529
[ "-N = int(eval(input()))", "-t = [0] * (N + 1)", "-x = [0] * (N + 1)", "-y = [0] * (N + 1)", "-for i in range(N):", "- t[i + 1], x[i + 1], y[i + 1] = list(map(int, input().split()))", "-f = True", "-for i in range(N):", "- dt = t[i + 1] - t[i]", "- dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])", "- if dt < dist:", "- f = False", "- if dist % 2 != dt % 2:", "- f = False", "-print((\"Yes\" if f else \"No\"))", "+n = int(eval(input()))", "+for i in range(n):", "+ t, x, y = list(map(int, input().split()))", "+ if (x + y) > t or (x + y + t) % 2:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.176458
0.042886
4.114598
[ "s512755079", "s724991739" ]
u525065967
p03634
python
s859796888
s658008237
1,366
602
52,952
53,080
Accepted
Accepted
55.93
## abc070d: Transit Tree Path from collections import deque n = int(eval(input())) T = [{} for _ in range(n)] for _ in range(n-1): v1,v2,d = list(map(int, input().split())) T[v1-1][v2-1] = d T[v2-1][v1-1] = d q,k = list(map(int, input().split())) visit = [False]*n depth = [0]*n que = deque() que.append(k-1) while que: p = que.popleft() visit[p] = True for c in list(T[p].keys()): if visit[c]: continue depth[c] = depth[p] + T[p][c] que.append(c) for _ in range(q): v1,v2 = list(map(int, input().split())) print((depth[v1-1]+depth[v2-1]))
## abc070d: Transit Tree Path import sys from collections import deque input = sys.stdin.readline n = int(eval(input())) T = [{} for _ in range(n)] for _ in range(n-1): v1,v2,d = list(map(int, input().split())) T[v1-1][v2-1] = d T[v2-1][v1-1] = d q,k = list(map(int, input().split())) visit = [False]*n depth = [0]*n que = deque() que.append(k-1) while que: p = que.popleft() visit[p] = True for c in list(T[p].keys()): if visit[c]: continue depth[c] = depth[p] + T[p][c] que.append(c) for _ in range(q): v1,v2 = list(map(int, input().split())) print((depth[v1-1]+depth[v2-1]))
29
30
597
635
## abc070d: Transit Tree Path from collections import deque n = int(eval(input())) T = [{} for _ in range(n)] for _ in range(n - 1): v1, v2, d = list(map(int, input().split())) T[v1 - 1][v2 - 1] = d T[v2 - 1][v1 - 1] = d q, k = list(map(int, input().split())) visit = [False] * n depth = [0] * n que = deque() que.append(k - 1) while que: p = que.popleft() visit[p] = True for c in list(T[p].keys()): if visit[c]: continue depth[c] = depth[p] + T[p][c] que.append(c) for _ in range(q): v1, v2 = list(map(int, input().split())) print((depth[v1 - 1] + depth[v2 - 1]))
## abc070d: Transit Tree Path import sys from collections import deque input = sys.stdin.readline n = int(eval(input())) T = [{} for _ in range(n)] for _ in range(n - 1): v1, v2, d = list(map(int, input().split())) T[v1 - 1][v2 - 1] = d T[v2 - 1][v1 - 1] = d q, k = list(map(int, input().split())) visit = [False] * n depth = [0] * n que = deque() que.append(k - 1) while que: p = que.popleft() visit[p] = True for c in list(T[p].keys()): if visit[c]: continue depth[c] = depth[p] + T[p][c] que.append(c) for _ in range(q): v1, v2 = list(map(int, input().split())) print((depth[v1 - 1] + depth[v2 - 1]))
false
3.333333
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.038161
0.038665
0.986958
[ "s859796888", "s658008237" ]
u767664985
p02658
python
s988462624
s541075525
52
48
21,696
21,672
Accepted
Accepted
7.69
N = int(eval(input())) A = list(map(int, input().split())) if 0 in A: print((0)) exit() ans = A[0] for i in range(1, N): ans *= A[i] if ans > 10**18: print((-1)) exit() print(ans)
N = int(eval(input())) A = list(map(int, input().split())) if 0 in A: print((0)) else: ans = 1 for i in range(N): ans *= A[i] if ans > 10**18: print((-1)) exit() print(ans)
14
13
217
232
N = int(eval(input())) A = list(map(int, input().split())) if 0 in A: print((0)) exit() ans = A[0] for i in range(1, N): ans *= A[i] if ans > 10**18: print((-1)) exit() print(ans)
N = int(eval(input())) A = list(map(int, input().split())) if 0 in A: print((0)) else: ans = 1 for i in range(N): ans *= A[i] if ans > 10**18: print((-1)) exit() print(ans)
false
7.142857
[ "- exit()", "-ans = A[0]", "-for i in range(1, N):", "- ans *= A[i]", "- if ans > 10**18:", "- print((-1))", "- exit()", "-print(ans)", "+else:", "+ ans = 1", "+ for i in range(N):", "+ ans *= A[i]", "+ if ans > 10**18:", "+ print((-1))", "+ exit()", "+ print(ans)" ]
false
0.036405
0.041832
0.870249
[ "s988462624", "s541075525" ]
u648315264
p02713
python
s336008115
s631232066
1,881
1,172
9,060
74,052
Accepted
Accepted
37.69
k = int(eval(input())) sum = 0 def gcd(x, y): # ใƒฆใƒผใ‚ฏใƒชใƒƒใƒ‰ใฎไบ’้™คๆณ• if y > x: y,x = x,y while y > 0: r = x%y x = y y = r return x import math for i in range(1,k+1): for m in range(1,k+1): sub = gcd(i,m) for l in range(1,k+1): sum += gcd(sub,l) print(sum)
k = int(eval(input())) sum = 0 def gcd(x, y): # ใƒฆใƒผใ‚ฏใƒชใƒƒใƒ‰ใฎไบ’้™คๆณ• if y > x: y,x = x,y while y > 0: r = x%y x = y y = r return x for i in range(1,k+1): for m in range(1,k+1): for l in range(1,k+1): sum += gcd(gcd(i,m),l) print(sum)
21
18
340
306
k = int(eval(input())) sum = 0 def gcd(x, y): # ใƒฆใƒผใ‚ฏใƒชใƒƒใƒ‰ใฎไบ’้™คๆณ• if y > x: y, x = x, y while y > 0: r = x % y x = y y = r return x import math for i in range(1, k + 1): for m in range(1, k + 1): sub = gcd(i, m) for l in range(1, k + 1): sum += gcd(sub, l) print(sum)
k = int(eval(input())) sum = 0 def gcd(x, y): # ใƒฆใƒผใ‚ฏใƒชใƒƒใƒ‰ใฎไบ’้™คๆณ• if y > x: y, x = x, y while y > 0: r = x % y x = y y = r return x for i in range(1, k + 1): for m in range(1, k + 1): for l in range(1, k + 1): sum += gcd(gcd(i, m), l) print(sum)
false
14.285714
[ "-import math", "-", "- sub = gcd(i, m)", "- sum += gcd(sub, l)", "+ sum += gcd(gcd(i, m), l)" ]
false
0.166051
0.04092
4.057984
[ "s336008115", "s631232066" ]
u782098901
p03013
python
s563723715
s745470052
214
193
7,856
7,860
Accepted
Accepted
9.81
MOD = 1000000007 N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] T = [0 for _ in range(N + 5)] for a in A: T[a] = -1 T[0] = 1 for i in range(0, N): if i + 1 <= N and T[i + 1] != -1 and T[i] != -1: T[i + 1] = (T[i + 1] + T[i]) % MOD if i + 2 <= N and T[i + 2] != -1 and T[i] != -1: T[i + 2] = (T[i + 2] + T[i]) % MOD print((T[N]))
MOD = 1000000007 N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] T = [0 for _ in range(N + 5)] for a in A: T[a] = -1 T[0] = 1 for i in range(0, N): if T[i + 1] != -1 and T[i] != -1: T[i + 1] = (T[i + 1] + T[i]) % MOD if T[i + 2] != -1 and T[i] != -1: T[i + 2] = (T[i + 2] + T[i]) % MOD print((T[N]))
18
18
400
370
MOD = 1000000007 N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] T = [0 for _ in range(N + 5)] for a in A: T[a] = -1 T[0] = 1 for i in range(0, N): if i + 1 <= N and T[i + 1] != -1 and T[i] != -1: T[i + 1] = (T[i + 1] + T[i]) % MOD if i + 2 <= N and T[i + 2] != -1 and T[i] != -1: T[i + 2] = (T[i + 2] + T[i]) % MOD print((T[N]))
MOD = 1000000007 N, M = list(map(int, input().split())) A = [int(eval(input())) for _ in range(M)] T = [0 for _ in range(N + 5)] for a in A: T[a] = -1 T[0] = 1 for i in range(0, N): if T[i + 1] != -1 and T[i] != -1: T[i + 1] = (T[i + 1] + T[i]) % MOD if T[i + 2] != -1 and T[i] != -1: T[i + 2] = (T[i + 2] + T[i]) % MOD print((T[N]))
false
0
[ "- if i + 1 <= N and T[i + 1] != -1 and T[i] != -1:", "+ if T[i + 1] != -1 and T[i] != -1:", "- if i + 2 <= N and T[i + 2] != -1 and T[i] != -1:", "+ if T[i + 2] != -1 and T[i] != -1:" ]
false
0.039371
0.062044
0.634566
[ "s563723715", "s745470052" ]
u047796752
p02684
python
s602848212
s573951496
431
116
227,904
113,708
Accepted
Accepted
73.09
import sys input = sys.stdin.readline from collections import * N, K = list(map(int, input().split())) A = list(map(int, input().split())) log_size = 100 dp = [[0]*N for _ in range(log_size)] for i in range(N): dp[0][i] = A[i]-1 for i in range(1, log_size): for j in range(N): dp[i][j] = dp[i-1][dp[i-1][j]] c = 0 cur = 0 while K>0: if K&1: cur = dp[c][cur] c += 1 K >>= 1 print((cur+1))
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = [0] s = {0} for i in range(K): nex = A[l[-1]]-1 if nex in s: for i in range(len(l)): if l[i]==nex: mark = i break t = len(l)-mark print((l[mark+(K-mark)%t]+1)) exit() l.append(nex) s.add(nex) print((nex+1))
27
25
464
451
import sys input = sys.stdin.readline from collections import * N, K = list(map(int, input().split())) A = list(map(int, input().split())) log_size = 100 dp = [[0] * N for _ in range(log_size)] for i in range(N): dp[0][i] = A[i] - 1 for i in range(1, log_size): for j in range(N): dp[i][j] = dp[i - 1][dp[i - 1][j]] c = 0 cur = 0 while K > 0: if K & 1: cur = dp[c][cur] c += 1 K >>= 1 print((cur + 1))
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = [0] s = {0} for i in range(K): nex = A[l[-1]] - 1 if nex in s: for i in range(len(l)): if l[i] == nex: mark = i break t = len(l) - mark print((l[mark + (K - mark) % t] + 1)) exit() l.append(nex) s.add(nex) print((nex + 1))
false
7.407407
[ "-from collections import *", "-", "-log_size = 100", "-dp = [[0] * N for _ in range(log_size)]", "-for i in range(N):", "- dp[0][i] = A[i] - 1", "-for i in range(1, log_size):", "- for j in range(N):", "- dp[i][j] = dp[i - 1][dp[i - 1][j]]", "-c = 0", "-cur = 0", "-while K > 0:", "- if K & 1:", "- cur = dp[c][cur]", "- c += 1", "- K >>= 1", "-print((cur + 1))", "+l = [0]", "+s = {0}", "+for i in range(K):", "+ nex = A[l[-1]] - 1", "+ if nex in s:", "+ for i in range(len(l)):", "+ if l[i] == nex:", "+ mark = i", "+ break", "+ t = len(l) - mark", "+ print((l[mark + (K - mark) % t] + 1))", "+ exit()", "+ l.append(nex)", "+ s.add(nex)", "+print((nex + 1))" ]
false
0.045556
0.040213
1.132865
[ "s602848212", "s573951496" ]
u241159583
p03487
python
s075517654
s355006065
76
70
22,480
22,368
Accepted
Accepted
7.89
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) ans = 0 for x,y in list(a.items()): if y<x: ans += y else:ans += y-x print(ans)
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) cnt = 0 for x,y in list(a.items()): if x==y: continue if x>y: cnt += y else: cnt += y-x print(cnt)
8
9
182
206
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) ans = 0 for x, y in list(a.items()): if y < x: ans += y else: ans += y - x print(ans)
from collections import Counter n = int(eval(input())) a = Counter(list(map(int, input().split()))) cnt = 0 for x, y in list(a.items()): if x == y: continue if x > y: cnt += y else: cnt += y - x print(cnt)
false
11.111111
[ "-ans = 0", "+cnt = 0", "- if y < x:", "- ans += y", "+ if x == y:", "+ continue", "+ if x > y:", "+ cnt += y", "- ans += y - x", "-print(ans)", "+ cnt += y - x", "+print(cnt)" ]
false
0.048457
0.050697
0.955817
[ "s075517654", "s355006065" ]
u013629972
p03212
python
s022836251
s670305073
222
55
44,632
3,060
Accepted
Accepted
75.23
def main(): global results, S S = int(eval(input())) S_str = str(S) results = [] for i in range(3, len(S_str) + 1): bfs(i, '') print((len(results))) def bfs(i, s): global results, S if i == 0: if int(s) <= S and len(set(s)) == 3: results.append(s) return i -= 1 bfs(i, s + '3') bfs(i, s + '5') bfs(i, s + '7') if __name__ == '__main__': main()
def main(): global result, S S = int(eval(input())) result = 0 bfs(0, '') print(result) def bfs(i, s): global result, S if s != '' and int(s) <= S and len(set(s)) == 3: result += 1 if i == len(str(S)): return i += 1 bfs(i, s + '3') bfs(i, s + '5') bfs(i, s + '7') if __name__ == '__main__': main()
24
22
451
385
def main(): global results, S S = int(eval(input())) S_str = str(S) results = [] for i in range(3, len(S_str) + 1): bfs(i, "") print((len(results))) def bfs(i, s): global results, S if i == 0: if int(s) <= S and len(set(s)) == 3: results.append(s) return i -= 1 bfs(i, s + "3") bfs(i, s + "5") bfs(i, s + "7") if __name__ == "__main__": main()
def main(): global result, S S = int(eval(input())) result = 0 bfs(0, "") print(result) def bfs(i, s): global result, S if s != "" and int(s) <= S and len(set(s)) == 3: result += 1 if i == len(str(S)): return i += 1 bfs(i, s + "3") bfs(i, s + "5") bfs(i, s + "7") if __name__ == "__main__": main()
false
8.333333
[ "- global results, S", "+ global result, S", "- S_str = str(S)", "- results = []", "- for i in range(3, len(S_str) + 1):", "- bfs(i, \"\")", "- print((len(results)))", "+ result = 0", "+ bfs(0, \"\")", "+ print(result)", "- global results, S", "- if i == 0:", "- if int(s) <= S and len(set(s)) == 3:", "- results.append(s)", "+ global result, S", "+ if s != \"\" and int(s) <= S and len(set(s)) == 3:", "+ result += 1", "+ if i == len(str(S)):", "- i -= 1", "+ i += 1" ]
false
0.066247
0.041271
1.60516
[ "s022836251", "s670305073" ]
u320511454
p03721
python
s501574343
s008594346
553
493
20,504
20,496
Accepted
Accepted
10.85
n,k=list(map(int,input().split())) li=[] for _ in range(n): a,b=list(map(int,input().split())) li.append([a,b]) li.sort() ans=0 for a,b in li: ans += b if k <= ans: print(a) break
n,k=list(map(int,input().split())) li=[] for _ in range(n): a,b=list(map(int,input().split())) li.append([a,b]) li.sort() for a,b in li: k -= b if k <= 0: print(a) break
13
12
208
197
n, k = list(map(int, input().split())) li = [] for _ in range(n): a, b = list(map(int, input().split())) li.append([a, b]) li.sort() ans = 0 for a, b in li: ans += b if k <= ans: print(a) break
n, k = list(map(int, input().split())) li = [] for _ in range(n): a, b = list(map(int, input().split())) li.append([a, b]) li.sort() for a, b in li: k -= b if k <= 0: print(a) break
false
7.692308
[ "-ans = 0", "- ans += b", "- if k <= ans:", "+ k -= b", "+ if k <= 0:" ]
false
0.045658
0.035277
1.294267
[ "s501574343", "s008594346" ]
u540631540
p02832
python
s063426982
s252448090
108
98
26,268
17,164
Accepted
Accepted
9.26
n = int(eval(input())) a = [int(i) for i in input().split()] if 1 in a: j = 0 for ai in a: if ai == j + 1: j += 1 print((n - j)) else: print((-1))
n,a=open(0);j=0 for b in map(int,a.split()): if b==j+1:j+=1 print(([-1,int(n)-j][j>0]))
10
4
181
92
n = int(eval(input())) a = [int(i) for i in input().split()] if 1 in a: j = 0 for ai in a: if ai == j + 1: j += 1 print((n - j)) else: print((-1))
n, a = open(0) j = 0 for b in map(int, a.split()): if b == j + 1: j += 1 print(([-1, int(n) - j][j > 0]))
false
60
[ "-n = int(eval(input()))", "-a = [int(i) for i in input().split()]", "-if 1 in a:", "- j = 0", "- for ai in a:", "- if ai == j + 1:", "- j += 1", "- print((n - j))", "-else:", "- print((-1))", "+n, a = open(0)", "+j = 0", "+for b in map(int, a.split()):", "+ if b == j + 1:", "+ j += 1", "+print(([-1, int(n) - j][j > 0]))" ]
false
0.038765
0.036461
1.063187
[ "s063426982", "s252448090" ]
u569117803
p03814
python
s495176366
s485354540
53
27
12,804
6,376
Accepted
Accepted
49.06
s = list(eval(input())) a_ind = [i for i, v in enumerate(s) if v == "A"] z_ind = [i for i, v in enumerate(s) if v == "Z"] ans = z_ind[-1] - a_ind[0] + 1 print(ans)
s = eval(input()) s_r = reversed(s) s = list(s) s_r = list(s_r) a_ind = s.index("A") z_ind = s_r.index("Z") z_ind = len(s) - z_ind ans = z_ind - a_ind print(ans)
9
12
170
169
s = list(eval(input())) a_ind = [i for i, v in enumerate(s) if v == "A"] z_ind = [i for i, v in enumerate(s) if v == "Z"] ans = z_ind[-1] - a_ind[0] + 1 print(ans)
s = eval(input()) s_r = reversed(s) s = list(s) s_r = list(s_r) a_ind = s.index("A") z_ind = s_r.index("Z") z_ind = len(s) - z_ind ans = z_ind - a_ind print(ans)
false
25
[ "-s = list(eval(input()))", "-a_ind = [i for i, v in enumerate(s) if v == \"A\"]", "-z_ind = [i for i, v in enumerate(s) if v == \"Z\"]", "-ans = z_ind[-1] - a_ind[0] + 1", "+s = eval(input())", "+s_r = reversed(s)", "+s = list(s)", "+s_r = list(s_r)", "+a_ind = s.index(\"A\")", "+z_ind = s_r.index(\"Z\")", "+z_ind = len(s) - z_ind", "+ans = z_ind - a_ind" ]
false
0.034333
0.035285
0.973032
[ "s495176366", "s485354540" ]
u144913062
p03855
python
s986447599
s828102942
1,768
948
151,184
119,384
Accepted
Accepted
46.38
from collections import defaultdict import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.parent = list(range(N)) self.rank = [0] * N self.size = [1] * N def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, K, L = list(map(int, input().split())) uf1 = UnionFind(N+1) for _ in range(K): p, q = list(map(int, input().split())) uf1.unite(p, q) uf2 = UnionFind(N+1) cnt = [defaultdict(int) for _ in range(N+1)] for i in range(1, N+1): cnt[i][uf1.find(i)] = 1 for _ in range(L): r, s = list(map(int, input().split())) if uf2.same(r, s): continue a = uf2.find(r) b = uf2.find(s) uf2.unite(r, s) c = uf2.find(r) if a == c: for k, v in list(cnt[b].items()): cnt[c][k] += v else: for k, v in list(cnt[a].items()): cnt[c][k] += v ans = [0] * (N+1) for i in range(1, N+1): ans[i] = cnt[uf2.find(i)][uf1.find(i)] print((*ans[1:]))
from collections import defaultdict import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.parent = list(range(N)) self.rank = [0] * N self.size = [1] * N def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, K, L = list(map(int, input().split())) uf1 = UnionFind(N+1) for _ in range(K): p, q = list(map(int, input().split())) uf1.unite(p, q) uf2 = UnionFind(N+1) for _ in range(L): r, s = list(map(int, input().split())) uf2.unite(r, s) cnt = defaultdict(int) for i in range(1, N+1): cnt[(uf1.find(i), uf2.find(i))] += 1 ans = [cnt[(uf1.find(i), uf2.find(i))] for i in range(1, N+1)] print((*ans))
62
49
1,624
1,325
from collections import defaultdict import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.parent = list(range(N)) self.rank = [0] * N self.size = [1] * N def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, K, L = list(map(int, input().split())) uf1 = UnionFind(N + 1) for _ in range(K): p, q = list(map(int, input().split())) uf1.unite(p, q) uf2 = UnionFind(N + 1) cnt = [defaultdict(int) for _ in range(N + 1)] for i in range(1, N + 1): cnt[i][uf1.find(i)] = 1 for _ in range(L): r, s = list(map(int, input().split())) if uf2.same(r, s): continue a = uf2.find(r) b = uf2.find(s) uf2.unite(r, s) c = uf2.find(r) if a == c: for k, v in list(cnt[b].items()): cnt[c][k] += v else: for k, v in list(cnt[a].items()): cnt[c][k] += v ans = [0] * (N + 1) for i in range(1, N + 1): ans[i] = cnt[uf2.find(i)][uf1.find(i)] print((*ans[1:]))
from collections import defaultdict import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.parent = list(range(N)) self.rank = [0] * N self.size = [1] * N def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, K, L = list(map(int, input().split())) uf1 = UnionFind(N + 1) for _ in range(K): p, q = list(map(int, input().split())) uf1.unite(p, q) uf2 = UnionFind(N + 1) for _ in range(L): r, s = list(map(int, input().split())) uf2.unite(r, s) cnt = defaultdict(int) for i in range(1, N + 1): cnt[(uf1.find(i), uf2.find(i))] += 1 ans = [cnt[(uf1.find(i), uf2.find(i))] for i in range(1, N + 1)] print((*ans))
false
20.967742
[ "-cnt = [defaultdict(int) for _ in range(N + 1)]", "-for i in range(1, N + 1):", "- cnt[i][uf1.find(i)] = 1", "- if uf2.same(r, s):", "- continue", "- a = uf2.find(r)", "- b = uf2.find(s)", "- c = uf2.find(r)", "- if a == c:", "- for k, v in list(cnt[b].items()):", "- cnt[c][k] += v", "- else:", "- for k, v in list(cnt[a].items()):", "- cnt[c][k] += v", "-ans = [0] * (N + 1)", "+cnt = defaultdict(int)", "- ans[i] = cnt[uf2.find(i)][uf1.find(i)]", "-print((*ans[1:]))", "+ cnt[(uf1.find(i), uf2.find(i))] += 1", "+ans = [cnt[(uf1.find(i), uf2.find(i))] for i in range(1, N + 1)]", "+print((*ans))" ]
false
0.039021
0.037457
1.041744
[ "s986447599", "s828102942" ]
u067983636
p03732
python
s408848253
s102265029
355
217
76,764
40,432
Accepted
Accepted
38.87
import sys input = sys.stdin.readline def read_values(): return list(map(int, input().split())) def read_list(): return list(read_values()) def func(N, mod): F = [1] for i in range(1, N + 1): F.append(F[-1] * i % mod) return F INV = {} def inv(a, mod): if a in INV: return INV[a] r = pow(a, mod - 2, mod) INV[a] = r return r def C(F, a, b, mod): return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod def main(): N, W = read_values() dp = [ [[0 for _ in range(N * 3 + 10)] for __ in range(N + 10)] for ___ in range(N + 10) ] I = [tuple(read_values()) for _ in range(N)] w0 = I[0][0] if w0 > W: print((0)) return for i, (w1, v) in enumerate(I): w = w1 - w0 for k in range(N): for j in range(N * 3 + 5): dp[i + 1][k][j] = max(dp[i][k][j], dp[i + 1][k][j]) dp[i + 1][k + 1][j + w] = max(dp[i][k][j] + v, dp[i + 1][k + 1][j + w]) res = 0 for k in range(N + 1): r = min(W - k * w0, 3 * N + 5) if r < 0: continue for i in range(r + 1): res = max(res, dp[N][k][i]) print(res) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def read_values(): return list(map(int, input().split())) def read_list(): return list(read_values()) def func(N, mod): F = [1] for i in range(1, N + 1): F.append(F[-1] * i % mod) return F INV = {} def inv(a, mod): if a in INV: return INV[a] r = pow(a, mod - 2, mod) INV[a] = r return r def C(F, a, b, mod): return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod def main(): import bisect N, W = read_values() I = [tuple(read_values()) for _ in range(N)] init_w = I[0][0] D = {i: [] for i in range(4)} S = {i: [0] for i in range(4)} for w, v in I: bisect.insort(D[w - init_w], -v) for i, d in list(D.items()): for v in d: S[i].append(v + S[i][-1]) res = 0 for t0 in range(len(D[0]) + 1): for t1 in range(len(D[1]) + 1): for t2 in range(len(D[2]) + 1): for t3 in range(len(D[3]) + 1): if (t0 + t1 + t2 + t3) * init_w + t1 + 2 * t2 + 3 * t3 > W: continue res = min(res, S[0][t0] + S[1][t1] + S[2][t2] + S[3][t3]) print((-res)) if __name__ == "__main__": main()
68
66
1,324
1,304
import sys input = sys.stdin.readline def read_values(): return list(map(int, input().split())) def read_list(): return list(read_values()) def func(N, mod): F = [1] for i in range(1, N + 1): F.append(F[-1] * i % mod) return F INV = {} def inv(a, mod): if a in INV: return INV[a] r = pow(a, mod - 2, mod) INV[a] = r return r def C(F, a, b, mod): return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod def main(): N, W = read_values() dp = [ [[0 for _ in range(N * 3 + 10)] for __ in range(N + 10)] for ___ in range(N + 10) ] I = [tuple(read_values()) for _ in range(N)] w0 = I[0][0] if w0 > W: print((0)) return for i, (w1, v) in enumerate(I): w = w1 - w0 for k in range(N): for j in range(N * 3 + 5): dp[i + 1][k][j] = max(dp[i][k][j], dp[i + 1][k][j]) dp[i + 1][k + 1][j + w] = max(dp[i][k][j] + v, dp[i + 1][k + 1][j + w]) res = 0 for k in range(N + 1): r = min(W - k * w0, 3 * N + 5) if r < 0: continue for i in range(r + 1): res = max(res, dp[N][k][i]) print(res) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def read_values(): return list(map(int, input().split())) def read_list(): return list(read_values()) def func(N, mod): F = [1] for i in range(1, N + 1): F.append(F[-1] * i % mod) return F INV = {} def inv(a, mod): if a in INV: return INV[a] r = pow(a, mod - 2, mod) INV[a] = r return r def C(F, a, b, mod): return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod def main(): import bisect N, W = read_values() I = [tuple(read_values()) for _ in range(N)] init_w = I[0][0] D = {i: [] for i in range(4)} S = {i: [0] for i in range(4)} for w, v in I: bisect.insort(D[w - init_w], -v) for i, d in list(D.items()): for v in d: S[i].append(v + S[i][-1]) res = 0 for t0 in range(len(D[0]) + 1): for t1 in range(len(D[1]) + 1): for t2 in range(len(D[2]) + 1): for t3 in range(len(D[3]) + 1): if (t0 + t1 + t2 + t3) * init_w + t1 + 2 * t2 + 3 * t3 > W: continue res = min(res, S[0][t0] + S[1][t1] + S[2][t2] + S[3][t3]) print((-res)) if __name__ == "__main__": main()
false
2.941176
[ "+ import bisect", "+", "- dp = [", "- [[0 for _ in range(N * 3 + 10)] for __ in range(N + 10)]", "- for ___ in range(N + 10)", "- ]", "- w0 = I[0][0]", "- if w0 > W:", "- print((0))", "- return", "- for i, (w1, v) in enumerate(I):", "- w = w1 - w0", "- for k in range(N):", "- for j in range(N * 3 + 5):", "- dp[i + 1][k][j] = max(dp[i][k][j], dp[i + 1][k][j])", "- dp[i + 1][k + 1][j + w] = max(dp[i][k][j] + v, dp[i + 1][k + 1][j + w])", "+ init_w = I[0][0]", "+ D = {i: [] for i in range(4)}", "+ S = {i: [0] for i in range(4)}", "+ for w, v in I:", "+ bisect.insort(D[w - init_w], -v)", "+ for i, d in list(D.items()):", "+ for v in d:", "+ S[i].append(v + S[i][-1])", "- for k in range(N + 1):", "- r = min(W - k * w0, 3 * N + 5)", "- if r < 0:", "- continue", "- for i in range(r + 1):", "- res = max(res, dp[N][k][i])", "- print(res)", "+ for t0 in range(len(D[0]) + 1):", "+ for t1 in range(len(D[1]) + 1):", "+ for t2 in range(len(D[2]) + 1):", "+ for t3 in range(len(D[3]) + 1):", "+ if (t0 + t1 + t2 + t3) * init_w + t1 + 2 * t2 + 3 * t3 > W:", "+ continue", "+ res = min(res, S[0][t0] + S[1][t1] + S[2][t2] + S[3][t3])", "+ print((-res))" ]
false
0.03957
0.03893
1.016438
[ "s408848253", "s102265029" ]
u455809703
p02731
python
s974129239
s845347184
36
17
5,332
2,940
Accepted
Accepted
52.78
from decimal import Decimal L = eval(input()) l = Decimal(L) / 3 print((l ** 3))
L = int(eval(input())) l = L / 3 print((l ** 3))
7
5
81
49
from decimal import Decimal L = eval(input()) l = Decimal(L) / 3 print((l**3))
L = int(eval(input())) l = L / 3 print((l**3))
false
28.571429
[ "-from decimal import Decimal", "-", "-L = eval(input())", "-l = Decimal(L) / 3", "+L = int(eval(input()))", "+l = L / 3" ]
false
0.040107
0.03771
1.06356
[ "s974129239", "s845347184" ]
u811156202
p04031
python
s363089013
s806001807
37
18
5,148
2,940
Accepted
Accepted
51.35
import statistics am = int(eval(input())) n_l = list(map(int, input().split(' '))) m = round(statistics.mean(n_l)) S = 0 for a in range(am): S += (n_l[a] - m)**2 print((int(S)))
am = int(eval(input())) n_l = list(map(int, input().split(' '))) m = round(sum(n_l)/len(n_l)) S = 0 for a in range(am): S += (n_l[a] - m)**2 print((int(S)))
12
10
188
164
import statistics am = int(eval(input())) n_l = list(map(int, input().split(" "))) m = round(statistics.mean(n_l)) S = 0 for a in range(am): S += (n_l[a] - m) ** 2 print((int(S)))
am = int(eval(input())) n_l = list(map(int, input().split(" "))) m = round(sum(n_l) / len(n_l)) S = 0 for a in range(am): S += (n_l[a] - m) ** 2 print((int(S)))
false
16.666667
[ "-import statistics", "-", "-m = round(statistics.mean(n_l))", "+m = round(sum(n_l) / len(n_l))" ]
false
0.061031
0.045731
1.334568
[ "s363089013", "s806001807" ]
u226108478
p03309
python
s095166859
s100471655
242
208
27,244
27,244
Accepted
Accepted
14.05
# -*- coding: utf-8 -*- # AtCoder Beginner Contest if __name__ == '__main__': from statistics import median n = int(eval(input())) a = list(map(int, input().split())) total = 0 # See: # https://www.youtube.com/watch?v=UX4AuiCVtN4 # https://beta.atcoder.jp/contests/abc102/submissions/2768315 mod_a = sorted([ai - i for i, ai in enumerate(a, 1)]) b = median(mod_a) for i in range(n): total += abs(mod_a[i] - b) print((int(total)))
# -*- coding: utf-8 -*- def main(): from statistics import median n = int(eval(input())) a = list(map(int, input().split())) mod_a = list() ans = 0 for index, ai in enumerate(a, 1): mod_a.append(ai - index) b = int(median(mod_a)) for mod_ai in mod_a: ans += abs(mod_ai - b) print(ans) if __name__ == '__main__': main()
21
24
500
401
# -*- coding: utf-8 -*- # AtCoder Beginner Contest if __name__ == "__main__": from statistics import median n = int(eval(input())) a = list(map(int, input().split())) total = 0 # See: # https://www.youtube.com/watch?v=UX4AuiCVtN4 # https://beta.atcoder.jp/contests/abc102/submissions/2768315 mod_a = sorted([ai - i for i, ai in enumerate(a, 1)]) b = median(mod_a) for i in range(n): total += abs(mod_a[i] - b) print((int(total)))
# -*- coding: utf-8 -*- def main(): from statistics import median n = int(eval(input())) a = list(map(int, input().split())) mod_a = list() ans = 0 for index, ai in enumerate(a, 1): mod_a.append(ai - index) b = int(median(mod_a)) for mod_ai in mod_a: ans += abs(mod_ai - b) print(ans) if __name__ == "__main__": main()
false
12.5
[ "-# AtCoder Beginner Contest", "-if __name__ == \"__main__\":", "+def main():", "- total = 0", "- # See:", "- # https://www.youtube.com/watch?v=UX4AuiCVtN4", "- # https://beta.atcoder.jp/contests/abc102/submissions/2768315", "- mod_a = sorted([ai - i for i, ai in enumerate(a, 1)])", "- b = median(mod_a)", "- for i in range(n):", "- total += abs(mod_a[i] - b)", "- print((int(total)))", "+ mod_a = list()", "+ ans = 0", "+ for index, ai in enumerate(a, 1):", "+ mod_a.append(ai - index)", "+ b = int(median(mod_a))", "+ for mod_ai in mod_a:", "+ ans += abs(mod_ai - b)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.048276
0.07767
0.621549
[ "s095166859", "s100471655" ]
u488401358
p02635
python
s814802048
s154801687
1,150
245
82,008
79,796
Accepted
Accepted
78.7
S,K=input().split() K=int(K) K=min(K,300) mod=998244353 a=[] val=0 for i in range(len(S)): if S[i]=="0": a.append(val) val=0 else: val+=1 if val!=0: a.append(val) m=len(a) K=min(sum(a),K) dp=[[0 for i in range(K+1)] for j in range(K+1)] for j in range(K+1): dp[j][j]=1 b=[a[i] for i in range(m)] c=[a[i] for i in range(m)] for i in range(1,m): b[i]+=b[i-1] b=[0]+b for i in range(m-2,-1,-1): c[i]+=c[i+1] for i in range(m-1,-1,-1): ndp=[[0 for j in range(K+1)] for k in range(K+1)] for k in range(min(b[i],K)+1): for j in range(min(K,k+c[i])+1): M=max(k-j,-a[i]) for l in range(max(0,M),K-j+1): ndp[j][k]=(ndp[j][k]+dp[j+l][k])%mod for l in range(1,min(K-k,-M)+1): ndp[j][k]=(ndp[j][k]+dp[j][k+l])%mod dp=ndp print((dp[0][0]))
S,K=input().split() K=int(K) K=min(K,300) mod=998244353 a=[] val=0 for i in range(len(S)): if S[i]=="0": a.append(val) val=0 else: val+=1 if val!=0: a.append(val) m=len(a) K=min(sum(a),K) b=[a[i] for i in range(m)] c=[a[i] for i in range(m)] for i in range(1,m): b[i]+=b[i-1] b=[0]+b for i in range(m-2,-1,-1): c[i]+=c[i+1] dp=[[0 for i in range(K+1)] for j in range(K+1)] plus=[[0 for j in range(K+1)] for k in range(K+1)] minus=[[0 for j in range(K+1)] for k in range(K+1)] for j in range(K+1): dp[j][j]=1 plus[j][j]=1 minus[j][j]=1 for k in range(K+1): for j in range(1,K+1): plus[j][k]+=plus[j-1][k] for j in range(K+1): for k in range(1,K+1): minus[j][k]+=minus[j][k-1] for i in range(m-1,-1,-1): ndp=[[0 for j in range(K+1)] for k in range(K+1)] for k in range(min(b[i],K)+1): for j in range(min(K,k+c[i])+1): M=max(k-j,-a[i]) if max(0,M)+j==0: ndp[j][k]+=plus[K][k] else: ndp[j][k]+=plus[K][k]-plus[(max(0,M))+j-1][k] if min(K-k,-M)>0: ndp[j][k]+=minus[j][k+min(K-k,-M)]-minus[j][k] ndp[j][k]%=mod dp=ndp for j in range(K+1): for k in range(K+1): plus[j][k]=ndp[j][k] minus[j][k]=ndp[j][k] for k in range(K+1): for j in range(1,K+1): plus[j][k]=(plus[j][k]+plus[j-1][k])%mod for j in range(K+1): for k in range(1,K+1): minus[j][k]=(minus[j][k]+minus[j][k-1])%mod print((dp[0][0]))
42
71
906
1,658
S, K = input().split() K = int(K) K = min(K, 300) mod = 998244353 a = [] val = 0 for i in range(len(S)): if S[i] == "0": a.append(val) val = 0 else: val += 1 if val != 0: a.append(val) m = len(a) K = min(sum(a), K) dp = [[0 for i in range(K + 1)] for j in range(K + 1)] for j in range(K + 1): dp[j][j] = 1 b = [a[i] for i in range(m)] c = [a[i] for i in range(m)] for i in range(1, m): b[i] += b[i - 1] b = [0] + b for i in range(m - 2, -1, -1): c[i] += c[i + 1] for i in range(m - 1, -1, -1): ndp = [[0 for j in range(K + 1)] for k in range(K + 1)] for k in range(min(b[i], K) + 1): for j in range(min(K, k + c[i]) + 1): M = max(k - j, -a[i]) for l in range(max(0, M), K - j + 1): ndp[j][k] = (ndp[j][k] + dp[j + l][k]) % mod for l in range(1, min(K - k, -M) + 1): ndp[j][k] = (ndp[j][k] + dp[j][k + l]) % mod dp = ndp print((dp[0][0]))
S, K = input().split() K = int(K) K = min(K, 300) mod = 998244353 a = [] val = 0 for i in range(len(S)): if S[i] == "0": a.append(val) val = 0 else: val += 1 if val != 0: a.append(val) m = len(a) K = min(sum(a), K) b = [a[i] for i in range(m)] c = [a[i] for i in range(m)] for i in range(1, m): b[i] += b[i - 1] b = [0] + b for i in range(m - 2, -1, -1): c[i] += c[i + 1] dp = [[0 for i in range(K + 1)] for j in range(K + 1)] plus = [[0 for j in range(K + 1)] for k in range(K + 1)] minus = [[0 for j in range(K + 1)] for k in range(K + 1)] for j in range(K + 1): dp[j][j] = 1 plus[j][j] = 1 minus[j][j] = 1 for k in range(K + 1): for j in range(1, K + 1): plus[j][k] += plus[j - 1][k] for j in range(K + 1): for k in range(1, K + 1): minus[j][k] += minus[j][k - 1] for i in range(m - 1, -1, -1): ndp = [[0 for j in range(K + 1)] for k in range(K + 1)] for k in range(min(b[i], K) + 1): for j in range(min(K, k + c[i]) + 1): M = max(k - j, -a[i]) if max(0, M) + j == 0: ndp[j][k] += plus[K][k] else: ndp[j][k] += plus[K][k] - plus[(max(0, M)) + j - 1][k] if min(K - k, -M) > 0: ndp[j][k] += minus[j][k + min(K - k, -M)] - minus[j][k] ndp[j][k] %= mod dp = ndp for j in range(K + 1): for k in range(K + 1): plus[j][k] = ndp[j][k] minus[j][k] = ndp[j][k] for k in range(K + 1): for j in range(1, K + 1): plus[j][k] = (plus[j][k] + plus[j - 1][k]) % mod for j in range(K + 1): for k in range(1, K + 1): minus[j][k] = (minus[j][k] + minus[j][k - 1]) % mod print((dp[0][0]))
false
40.84507
[ "-dp = [[0 for i in range(K + 1)] for j in range(K + 1)]", "-for j in range(K + 1):", "- dp[j][j] = 1", "+dp = [[0 for i in range(K + 1)] for j in range(K + 1)]", "+plus = [[0 for j in range(K + 1)] for k in range(K + 1)]", "+minus = [[0 for j in range(K + 1)] for k in range(K + 1)]", "+for j in range(K + 1):", "+ dp[j][j] = 1", "+ plus[j][j] = 1", "+ minus[j][j] = 1", "+for k in range(K + 1):", "+ for j in range(1, K + 1):", "+ plus[j][k] += plus[j - 1][k]", "+for j in range(K + 1):", "+ for k in range(1, K + 1):", "+ minus[j][k] += minus[j][k - 1]", "- for l in range(max(0, M), K - j + 1):", "- ndp[j][k] = (ndp[j][k] + dp[j + l][k]) % mod", "- for l in range(1, min(K - k, -M) + 1):", "- ndp[j][k] = (ndp[j][k] + dp[j][k + l]) % mod", "+ if max(0, M) + j == 0:", "+ ndp[j][k] += plus[K][k]", "+ else:", "+ ndp[j][k] += plus[K][k] - plus[(max(0, M)) + j - 1][k]", "+ if min(K - k, -M) > 0:", "+ ndp[j][k] += minus[j][k + min(K - k, -M)] - minus[j][k]", "+ ndp[j][k] %= mod", "+ for j in range(K + 1):", "+ for k in range(K + 1):", "+ plus[j][k] = ndp[j][k]", "+ minus[j][k] = ndp[j][k]", "+ for k in range(K + 1):", "+ for j in range(1, K + 1):", "+ plus[j][k] = (plus[j][k] + plus[j - 1][k]) % mod", "+ for j in range(K + 1):", "+ for k in range(1, K + 1):", "+ minus[j][k] = (minus[j][k] + minus[j][k - 1]) % mod" ]
false
0.169991
0.043695
3.890377
[ "s814802048", "s154801687" ]
u585482323
p02727
python
s108821991
s701273671
1,310
348
115,308
100,076
Accepted
Accepted
73.44
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): x,y,a,b,c = LI() p = LI() q = LI() r = LI() s = [(i,0) for i in p]+[(i,1) for i in q]+[(i,2) for i in r] s.sort(reverse = True) ans = 0 f = [0,0] l = [x,y] q = deque() q2 = deque() for a,i in s: if i > 1: q.append(a) else: if f[i] < l[i]: ans += a f[i] += 1 q2.append(a) s = ans while q and q2: s -= q2.pop() s += q.popleft() if ans < s: ans = s print(ans) return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): x,y,a,b,c = LI() p = LI() q = LI() r = LI() p.sort(reverse = True) q.sort(reverse = True) s = p[:x]+q[:y]+r s.sort(reverse = True) print((sum(s[:x+y]))) return #Solve if __name__ == "__main__": solve()
59
42
1,372
1,001
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): x, y, a, b, c = LI() p = LI() q = LI() r = LI() s = [(i, 0) for i in p] + [(i, 1) for i in q] + [(i, 2) for i in r] s.sort(reverse=True) ans = 0 f = [0, 0] l = [x, y] q = deque() q2 = deque() for a, i in s: if i > 1: q.append(a) else: if f[i] < l[i]: ans += a f[i] += 1 q2.append(a) s = ans while q and q2: s -= q2.pop() s += q.popleft() if ans < s: ans = s print(ans) return # Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): x, y, a, b, c = LI() p = LI() q = LI() r = LI() p.sort(reverse=True) q.sort(reverse=True) s = p[:x] + q[:y] + r s.sort(reverse=True) print((sum(s[: x + y]))) return # Solve if __name__ == "__main__": solve()
false
28.813559
[ "- s = [(i, 0) for i in p] + [(i, 1) for i in q] + [(i, 2) for i in r]", "+ p.sort(reverse=True)", "+ q.sort(reverse=True)", "+ s = p[:x] + q[:y] + r", "- ans = 0", "- f = [0, 0]", "- l = [x, y]", "- q = deque()", "- q2 = deque()", "- for a, i in s:", "- if i > 1:", "- q.append(a)", "- else:", "- if f[i] < l[i]:", "- ans += a", "- f[i] += 1", "- q2.append(a)", "- s = ans", "- while q and q2:", "- s -= q2.pop()", "- s += q.popleft()", "- if ans < s:", "- ans = s", "- print(ans)", "+ print((sum(s[: x + y])))" ]
false
0.107852
0.036884
2.924108
[ "s108821991", "s701273671" ]
u874395007
p02265
python
s990665866
s517536543
4,450
4,010
69,732
69,736
Accepted
Accepted
9.89
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): line = input().split() order = line[0] if order == 'deleteFirst': d.popleft() elif order == 'deleteLast': d.pop() else: key = line[1] if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(key) except ValueError: pass else: raise ValueError('Invalid order: {order}') print((' '.join(d)))
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): order = eval(input()) if order == 'deleteFirst': d.popleft() elif order == 'deleteLast': d.pop() else: order, key = order.split() if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(key) except ValueError: pass else: raise ValueError('Invalid order: {order}') print((' '.join(d)))
25
24
563
548
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): line = input().split() order = line[0] if order == "deleteFirst": d.popleft() elif order == "deleteLast": d.pop() else: key = line[1] if order == "insert": d.appendleft(key) elif order == "delete": try: d.remove(key) except ValueError: pass else: raise ValueError("Invalid order: {order}") print((" ".join(d)))
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): order = eval(input()) if order == "deleteFirst": d.popleft() elif order == "deleteLast": d.pop() else: order, key = order.split() if order == "insert": d.appendleft(key) elif order == "delete": try: d.remove(key) except ValueError: pass else: raise ValueError("Invalid order: {order}") print((" ".join(d)))
false
4
[ "- line = input().split()", "- order = line[0]", "+ order = eval(input())", "- key = line[1]", "+ order, key = order.split()" ]
false
0.046518
0.047187
0.985823
[ "s990665866", "s517536543" ]
u044220565
p02733
python
s916191396
s658444379
1,349
272
3,444
43,356
Accepted
Accepted
79.84
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque def run(): H,W,K = list(map(int, sysread().split())) S = [] for i in range(H): S.append(list(accumulate(list(map(int, list(eval(input())))), lambda x,y:x+y))) for h in range(1, H): for w in range(W): S[h][w] += S[h-1][w] ret = float('inf') for idxes_ in product((0,1), repeat=H-1): l = 0 r = 1 idxes = [0] for i, val in enumerate(idxes_, 1): if val == 1: idxes.append(i) idxes.append(H) min_cut = len(idxes) - 2 while r <= W: for i in range(len(idxes)-1): if idxes[i] == 0 and l == 0: cri = S[idxes[i+1]-1][r-1] elif l == 0: cri = S[idxes[i+1]-1][r-1] - S[idxes[i]-1][r-1] elif idxes[i] == 0: cri = S[idxes[i+1]-1][r-1] - S[idxes[i+1]-1][l-1] else: cri = S[idxes[i+1]-1][r-1] - S[idxes[i]-1][r-1] - S[idxes[i+1]-1][l-1] + S[idxes[i]-1][l-1] if cri > K: r -= 1 if l == r: min_cut = float('inf') r = W+1 break l = r min_cut += 1 break r += 1 ret = min(ret, min_cut) print(ret) if __name__ == "__main__": run()
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque def run(): H,W,K = list(map(int, sysread().split())) S = [] for i in range(H): S.append(list(accumulate(list(map(int, list(eval(input()))))))) for h in range(1, H): for w in range(W): S[h][w] += S[h-1][w] ret = float('inf') for idxes_ in product((0,1), repeat=H-1): l = 0 r = 1 idxes = [0] for i, val in enumerate(idxes_, 1): if val == 1: idxes.append(i) idxes.append(H) min_cut = len(idxes) - 2 while r <= W: for i in range(len(idxes)-1): if idxes[i] == 0 and l == 0: cri = S[idxes[i+1]-1][r-1] elif l == 0: cri = S[idxes[i+1]-1][r-1] - S[idxes[i]-1][r-1] elif idxes[i] == 0: cri = S[idxes[i+1]-1][r-1] - S[idxes[i+1]-1][l-1] else: cri = S[idxes[i+1]-1][r-1] - S[idxes[i]-1][r-1] - S[idxes[i+1]-1][l-1] + S[idxes[i]-1][l-1] if cri > K: r -= 1 if l == r: min_cut = float('inf') r = W+1 break l = r min_cut += 1 break r += 1 ret = min(ret, min_cut) print(ret) if __name__ == "__main__": run()
64
64
1,891
1,875
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) # import math from itertools import product, accumulate, combinations, product # import bisect# lower_bound etc # import numpy as np # from copy import deepcopy # from collections import deque def run(): H, W, K = list(map(int, sysread().split())) S = [] for i in range(H): S.append( list(accumulate(list(map(int, list(eval(input())))), lambda x, y: x + y)) ) for h in range(1, H): for w in range(W): S[h][w] += S[h - 1][w] ret = float("inf") for idxes_ in product((0, 1), repeat=H - 1): l = 0 r = 1 idxes = [0] for i, val in enumerate(idxes_, 1): if val == 1: idxes.append(i) idxes.append(H) min_cut = len(idxes) - 2 while r <= W: for i in range(len(idxes) - 1): if idxes[i] == 0 and l == 0: cri = S[idxes[i + 1] - 1][r - 1] elif l == 0: cri = S[idxes[i + 1] - 1][r - 1] - S[idxes[i] - 1][r - 1] elif idxes[i] == 0: cri = S[idxes[i + 1] - 1][r - 1] - S[idxes[i + 1] - 1][l - 1] else: cri = ( S[idxes[i + 1] - 1][r - 1] - S[idxes[i] - 1][r - 1] - S[idxes[i + 1] - 1][l - 1] + S[idxes[i] - 1][l - 1] ) if cri > K: r -= 1 if l == r: min_cut = float("inf") r = W + 1 break l = r min_cut += 1 break r += 1 ret = min(ret, min_cut) print(ret) if __name__ == "__main__": run()
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) # import math from itertools import product, accumulate, combinations, product # import bisect# lower_bound etc # import numpy as np # from copy import deepcopy # from collections import deque def run(): H, W, K = list(map(int, sysread().split())) S = [] for i in range(H): S.append(list(accumulate(list(map(int, list(eval(input()))))))) for h in range(1, H): for w in range(W): S[h][w] += S[h - 1][w] ret = float("inf") for idxes_ in product((0, 1), repeat=H - 1): l = 0 r = 1 idxes = [0] for i, val in enumerate(idxes_, 1): if val == 1: idxes.append(i) idxes.append(H) min_cut = len(idxes) - 2 while r <= W: for i in range(len(idxes) - 1): if idxes[i] == 0 and l == 0: cri = S[idxes[i + 1] - 1][r - 1] elif l == 0: cri = S[idxes[i + 1] - 1][r - 1] - S[idxes[i] - 1][r - 1] elif idxes[i] == 0: cri = S[idxes[i + 1] - 1][r - 1] - S[idxes[i + 1] - 1][l - 1] else: cri = ( S[idxes[i + 1] - 1][r - 1] - S[idxes[i] - 1][r - 1] - S[idxes[i + 1] - 1][l - 1] + S[idxes[i] - 1][l - 1] ) if cri > K: r -= 1 if l == r: min_cut = float("inf") r = W + 1 break l = r min_cut += 1 break r += 1 ret = min(ret, min_cut) print(ret) if __name__ == "__main__": run()
false
0
[ "- S.append(", "- list(accumulate(list(map(int, list(eval(input())))), lambda x, y: x + y))", "- )", "+ S.append(list(accumulate(list(map(int, list(eval(input())))))))" ]
false
0.039121
0.06545
0.597726
[ "s916191396", "s658444379" ]
u349449706
p03910
python
s154392897
s845570946
95
80
76,828
74,600
Accepted
Accepted
15.79
import sys sys.setrecursionlimit(10**7) def is_ok(m, n): return m*(m+1)//2>=n def meguru_bisect(ng, ok, n): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid, n): ok = mid else: ng = mid return ok def f(n): if n>0: m = meguru_bisect(0,10**7, n) print(m) f(n-m) N = int(eval(input())) f(N)
N=int(eval(input())) m=1 while m*(m+1)<2*N:m+=1 for i in range(1,m+1): if m*(m+1)//2-i!=N:print(i)
19
6
399
103
import sys sys.setrecursionlimit(10**7) def is_ok(m, n): return m * (m + 1) // 2 >= n def meguru_bisect(ng, ok, n): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid, n): ok = mid else: ng = mid return ok def f(n): if n > 0: m = meguru_bisect(0, 10**7, n) print(m) f(n - m) N = int(eval(input())) f(N)
N = int(eval(input())) m = 1 while m * (m + 1) < 2 * N: m += 1 for i in range(1, m + 1): if m * (m + 1) // 2 - i != N: print(i)
false
68.421053
[ "-import sys", "-", "-sys.setrecursionlimit(10**7)", "-", "-", "-def is_ok(m, n):", "- return m * (m + 1) // 2 >= n", "-", "-", "-def meguru_bisect(ng, ok, n):", "- while abs(ok - ng) > 1:", "- mid = (ok + ng) // 2", "- if is_ok(mid, n):", "- ok = mid", "- else:", "- ng = mid", "- return ok", "-", "-", "-def f(n):", "- if n > 0:", "- m = meguru_bisect(0, 10**7, n)", "- print(m)", "- f(n - m)", "-", "-", "-f(N)", "+m = 1", "+while m * (m + 1) < 2 * N:", "+ m += 1", "+for i in range(1, m + 1):", "+ if m * (m + 1) // 2 - i != N:", "+ print(i)" ]
false
0.038292
0.046854
0.817259
[ "s154392897", "s845570946" ]
u861466636
p03074
python
s566775006
s050853479
144
90
7,440
5,028
Accepted
Accepted
37.5
N, K = list(map(int, input().split())) S = eval(input()) l = [[], []] ans = [] k = [int(s) for s in S] if k[0] == 0: l[1].append(0) v0 = 1 if k[0] == 0 else 0 v1 = 1 if k[0] == 1 else 0 for i in range(1, N): if (k[i]==0) & (k[i-1]==0): v0 += 1 elif (k[i]==1) & (k[i-1]==0): l[0].append(v0) v0 = 0 v1 += 1 elif (k[i]==0) & (k[i-1]==1): l[1].append(v1) v0 += 1 v1 = 0 else: v1 += 1 for i, v in enumerate([v0, v1]): if v > 0: l[i].append(v) if k[0] == 0: l[1].append(0) l[0] += [0]*(K+1) l[1] += [0]*(K+1) a = sum(l[0][:K]) + sum(l[1][:K+1]) ans.append(a) for i in range(1, len(l[0])-K-1): a -= l[0][i-1] + l[1][i-1] a += l[0][i+K-1] + l[1][i+K] ans.append(a) print((max(ans)))
import sys from collections import deque input = sys.stdin.readline def main(): n,k = list(map(int,input().split())) s = list(eval(input())) #tank: '0...0'ใจ'1...1'ใฎๅกŠใฎๆ•ฐใƒชใ‚นใƒˆ #ex. 0001011ใชใ‚‰tank = [3,1,1,2] (0ใŒ3ใค,1ใŒ1ใค,0ใŒ2ใค,1ใŒ2ใค) tank = [] cnt = 1 for i in range(1,n): if s[i] != s[i-1]: tank.append(cnt) cnt = 0 cnt += 1 if i == n-1: tank.append(cnt) #p:tankใฎ้•ทใ• p = len(tank) #ๅ…จ้ƒจ1ใซใงใใฆใ—ใพใ†ๅ ดๅˆ if s[0] == '0' and (p+1)//2 <= k: print(n) exit() if p//2 <= k and s[0] == '1': print(n) exit() ans = 0 #res:tank[j]ใŒ1...1ใฎๅณ็ซฏใฎๆ™‚ใฎ่งฃ res = 0 if s[0] == '0': for j in range(2*k): res += tank[j] ans = res for j in range(2*k,p): if j == 2*k: res -= tank[0] elif j%2 == 0: res= res - tank[j-2*k] -tank[j-2*k-1] res += tank[j] ans = max(ans,res) else: for j in range(2*k+1): res += tank[j] ans = res for j in range(2*k+1,p): if j % 2 == 1: res = res- tank[j-2*k-1]-tank[j-2*k] res += tank[j] ans = max(ans,res) print(ans) if __name__ == '__main__': main()
40
61
837
1,365
N, K = list(map(int, input().split())) S = eval(input()) l = [[], []] ans = [] k = [int(s) for s in S] if k[0] == 0: l[1].append(0) v0 = 1 if k[0] == 0 else 0 v1 = 1 if k[0] == 1 else 0 for i in range(1, N): if (k[i] == 0) & (k[i - 1] == 0): v0 += 1 elif (k[i] == 1) & (k[i - 1] == 0): l[0].append(v0) v0 = 0 v1 += 1 elif (k[i] == 0) & (k[i - 1] == 1): l[1].append(v1) v0 += 1 v1 = 0 else: v1 += 1 for i, v in enumerate([v0, v1]): if v > 0: l[i].append(v) if k[0] == 0: l[1].append(0) l[0] += [0] * (K + 1) l[1] += [0] * (K + 1) a = sum(l[0][:K]) + sum(l[1][: K + 1]) ans.append(a) for i in range(1, len(l[0]) - K - 1): a -= l[0][i - 1] + l[1][i - 1] a += l[0][i + K - 1] + l[1][i + K] ans.append(a) print((max(ans)))
import sys from collections import deque input = sys.stdin.readline def main(): n, k = list(map(int, input().split())) s = list(eval(input())) # tank: '0...0'ใจ'1...1'ใฎๅกŠใฎๆ•ฐใƒชใ‚นใƒˆ # ex. 0001011ใชใ‚‰tank = [3,1,1,2] (0ใŒ3ใค,1ใŒ1ใค,0ใŒ2ใค,1ใŒ2ใค) tank = [] cnt = 1 for i in range(1, n): if s[i] != s[i - 1]: tank.append(cnt) cnt = 0 cnt += 1 if i == n - 1: tank.append(cnt) # p:tankใฎ้•ทใ• p = len(tank) # ๅ…จ้ƒจ1ใซใงใใฆใ—ใพใ†ๅ ดๅˆ if s[0] == "0" and (p + 1) // 2 <= k: print(n) exit() if p // 2 <= k and s[0] == "1": print(n) exit() ans = 0 # res:tank[j]ใŒ1...1ใฎๅณ็ซฏใฎๆ™‚ใฎ่งฃ res = 0 if s[0] == "0": for j in range(2 * k): res += tank[j] ans = res for j in range(2 * k, p): if j == 2 * k: res -= tank[0] elif j % 2 == 0: res = res - tank[j - 2 * k] - tank[j - 2 * k - 1] res += tank[j] ans = max(ans, res) else: for j in range(2 * k + 1): res += tank[j] ans = res for j in range(2 * k + 1, p): if j % 2 == 1: res = res - tank[j - 2 * k - 1] - tank[j - 2 * k] res += tank[j] ans = max(ans, res) print(ans) if __name__ == "__main__": main()
false
34.42623
[ "-N, K = list(map(int, input().split()))", "-S = eval(input())", "-l = [[], []]", "-ans = []", "-k = [int(s) for s in S]", "-if k[0] == 0:", "- l[1].append(0)", "-v0 = 1 if k[0] == 0 else 0", "-v1 = 1 if k[0] == 1 else 0", "-for i in range(1, N):", "- if (k[i] == 0) & (k[i - 1] == 0):", "- v0 += 1", "- elif (k[i] == 1) & (k[i - 1] == 0):", "- l[0].append(v0)", "- v0 = 0", "- v1 += 1", "- elif (k[i] == 0) & (k[i - 1] == 1):", "- l[1].append(v1)", "- v0 += 1", "- v1 = 0", "+import sys", "+from collections import deque", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ n, k = list(map(int, input().split()))", "+ s = list(eval(input()))", "+ # tank: '0...0'ใจ'1...1'ใฎๅกŠใฎๆ•ฐใƒชใ‚นใƒˆ", "+ # ex. 0001011ใชใ‚‰tank = [3,1,1,2] (0ใŒ3ใค,1ใŒ1ใค,0ใŒ2ใค,1ใŒ2ใค)", "+ tank = []", "+ cnt = 1", "+ for i in range(1, n):", "+ if s[i] != s[i - 1]:", "+ tank.append(cnt)", "+ cnt = 0", "+ cnt += 1", "+ if i == n - 1:", "+ tank.append(cnt)", "+ # p:tankใฎ้•ทใ•", "+ p = len(tank)", "+ # ๅ…จ้ƒจ1ใซใงใใฆใ—ใพใ†ๅ ดๅˆ", "+ if s[0] == \"0\" and (p + 1) // 2 <= k:", "+ print(n)", "+ exit()", "+ if p // 2 <= k and s[0] == \"1\":", "+ print(n)", "+ exit()", "+ ans = 0", "+ # res:tank[j]ใŒ1...1ใฎๅณ็ซฏใฎๆ™‚ใฎ่งฃ", "+ res = 0", "+ if s[0] == \"0\":", "+ for j in range(2 * k):", "+ res += tank[j]", "+ ans = res", "+ for j in range(2 * k, p):", "+ if j == 2 * k:", "+ res -= tank[0]", "+ elif j % 2 == 0:", "+ res = res - tank[j - 2 * k] - tank[j - 2 * k - 1]", "+ res += tank[j]", "+ ans = max(ans, res)", "- v1 += 1", "-for i, v in enumerate([v0, v1]):", "- if v > 0:", "- l[i].append(v)", "-if k[0] == 0:", "- l[1].append(0)", "-l[0] += [0] * (K + 1)", "-l[1] += [0] * (K + 1)", "-a = sum(l[0][:K]) + sum(l[1][: K + 1])", "-ans.append(a)", "-for i in range(1, len(l[0]) - K - 1):", "- a -= l[0][i - 1] + l[1][i - 1]", "- a += l[0][i + K - 1] + l[1][i + K]", "- ans.append(a)", "-print((max(ans)))", "+ for j in range(2 * k + 1):", "+ res += tank[j]", "+ ans = res", "+ for j in range(2 * k + 1, p):", "+ if j % 2 == 1:", "+ res = res - tank[j - 2 * k - 1] - tank[j - 2 * k]", "+ res += tank[j]", "+ ans = max(ans, res)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.10565
0.044808
2.357851
[ "s566775006", "s050853479" ]
u970197315
p03363
python
s058233219
s688949864
208
144
34,452
44,344
Accepted
Accepted
30.77
n=int(eval(input())) a=[0]+list(map(int,input().split())) from itertools import accumulate a=accumulate(a) a=list(a) a.sort() from collections import Counter c=Counter(a) ans=0 for k,v in list(c.items()): if v>=2: ans+=v*(v-1)//2 print(ans)
N = list(map(int, input().split())) a = [0] + list(map(int, input().split())) from collections import Counter from itertools import accumulate s = list(accumulate(a)) c = Counter(s) ans = 0 for v in list(c.values()): ans += v*(v-1)//2 print(ans)
13
13
253
253
n = int(eval(input())) a = [0] + list(map(int, input().split())) from itertools import accumulate a = accumulate(a) a = list(a) a.sort() from collections import Counter c = Counter(a) ans = 0 for k, v in list(c.items()): if v >= 2: ans += v * (v - 1) // 2 print(ans)
N = list(map(int, input().split())) a = [0] + list(map(int, input().split())) from collections import Counter from itertools import accumulate s = list(accumulate(a)) c = Counter(s) ans = 0 for v in list(c.values()): ans += v * (v - 1) // 2 print(ans)
false
0
[ "-n = int(eval(input()))", "+N = list(map(int, input().split()))", "+from collections import Counter", "-a = accumulate(a)", "-a = list(a)", "-a.sort()", "-from collections import Counter", "-", "-c = Counter(a)", "+s = list(accumulate(a))", "+c = Counter(s)", "-for k, v in list(c.items()):", "- if v >= 2:", "- ans += v * (v - 1) // 2", "+for v in list(c.values()):", "+ ans += v * (v - 1) // 2" ]
false
0.034557
0.128955
0.267979
[ "s058233219", "s688949864" ]
u340781749
p02925
python
s052245015
s376161456
1,205
1,049
35,848
35,848
Accepted
Accepted
12.95
import sys from collections import deque n = int(eval(input())) matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin] q = deque(list(range(n))) depth = [0] * n waiting = [-1] * n while q: a = q.popleft() ma = matches[a] if not ma: continue b = ma.pop() if waiting[b] == a: depth[a] = depth[b] = max(depth[a], depth[b]) + 1 q.append(a) q.append(b) else: waiting[a] = b if any(matches): print((-1)) else: print((max(depth)))
import sys from collections import deque n = int(eval(input())) matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin] q = deque(list(range(n))) depth = [0] * n waiting = [-1] * n while q: a = q.popleft() b = matches[a].pop() if waiting[b] == a: depth[a] = depth[b] = max(depth[a], depth[b]) + 1 if matches[a]: q.append(a) if matches[b]: q.append(b) else: waiting[a] = b if any(matches): print((-1)) else: print((max(depth)))
26
25
527
536
import sys from collections import deque n = int(eval(input())) matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin] q = deque(list(range(n))) depth = [0] * n waiting = [-1] * n while q: a = q.popleft() ma = matches[a] if not ma: continue b = ma.pop() if waiting[b] == a: depth[a] = depth[b] = max(depth[a], depth[b]) + 1 q.append(a) q.append(b) else: waiting[a] = b if any(matches): print((-1)) else: print((max(depth)))
import sys from collections import deque n = int(eval(input())) matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin] q = deque(list(range(n))) depth = [0] * n waiting = [-1] * n while q: a = q.popleft() b = matches[a].pop() if waiting[b] == a: depth[a] = depth[b] = max(depth[a], depth[b]) + 1 if matches[a]: q.append(a) if matches[b]: q.append(b) else: waiting[a] = b if any(matches): print((-1)) else: print((max(depth)))
false
3.846154
[ "- ma = matches[a]", "- if not ma:", "- continue", "- b = ma.pop()", "+ b = matches[a].pop()", "- q.append(a)", "- q.append(b)", "+ if matches[a]:", "+ q.append(a)", "+ if matches[b]:", "+ q.append(b)" ]
false
0.040915
0.036243
1.12889
[ "s052245015", "s376161456" ]
u785989355
p02936
python
s977638707
s225120070
1,853
817
107,540
96,532
Accepted
Accepted
55.91
N,Q = list(map(int,input().split())) e_list = [[] for i in range(N)] for i in range(N-1): a,b = list(map(int,input().split())) a,b = a-1,b-1 e_list[a].append(b) e_list[b].append(a) add_list = [0]*N for i in range(Q): p,x = list(map(int,input().split())) p = p-1 add_list[p]+=x count_list = [0]*N count_list[0] = add_list[0] vi = 0 #ๆ™‚ใจๅ ดๅˆใซใ‚ˆใฃใฆใ“ใ“ใ‚’ๅค‰ใˆใ‚‹ from collections import deque Q = deque([vi]) checked_list = [False]*N checked_list[vi]=True while len(Q)>0: v = Q.pop() for v1 in e_list[v]: if not checked_list[v1]: checked_list[v1]=True Q.appendleft(v1) count_list[v1] = count_list[v]+add_list[v1] print((*count_list))
import sys def input(): return sys.stdin.readline()[:-1] N,Q = list(map(int,input().split())) e_list = [[] for i in range(N)] for i in range(N-1): a,b = list(map(int,input().split())) a,b = a-1,b-1 e_list[a].append(b) e_list[b].append(a) add_list = [0]*N for i in range(Q): p,x = list(map(int,input().split())) p = p-1 add_list[p]+=x count_list = [0]*N count_list[0] = add_list[0] vi = 0 #ๆ™‚ใจๅ ดๅˆใซใ‚ˆใฃใฆใ“ใ“ใ‚’ๅค‰ใˆใ‚‹ from collections import deque Q = deque([vi]) checked_list = [False]*N checked_list[vi]=True while len(Q)>0: v = Q.pop() for v1 in e_list[v]: if not checked_list[v1]: checked_list[v1]=True Q.appendleft(v1) count_list[v1] = count_list[v]+add_list[v1] print((*count_list))
34
38
752
822
N, Q = list(map(int, input().split())) e_list = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 e_list[a].append(b) e_list[b].append(a) add_list = [0] * N for i in range(Q): p, x = list(map(int, input().split())) p = p - 1 add_list[p] += x count_list = [0] * N count_list[0] = add_list[0] vi = 0 # ๆ™‚ใจๅ ดๅˆใซใ‚ˆใฃใฆใ“ใ“ใ‚’ๅค‰ใˆใ‚‹ from collections import deque Q = deque([vi]) checked_list = [False] * N checked_list[vi] = True while len(Q) > 0: v = Q.pop() for v1 in e_list[v]: if not checked_list[v1]: checked_list[v1] = True Q.appendleft(v1) count_list[v1] = count_list[v] + add_list[v1] print((*count_list))
import sys def input(): return sys.stdin.readline()[:-1] N, Q = list(map(int, input().split())) e_list = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 e_list[a].append(b) e_list[b].append(a) add_list = [0] * N for i in range(Q): p, x = list(map(int, input().split())) p = p - 1 add_list[p] += x count_list = [0] * N count_list[0] = add_list[0] vi = 0 # ๆ™‚ใจๅ ดๅˆใซใ‚ˆใฃใฆใ“ใ“ใ‚’ๅค‰ใˆใ‚‹ from collections import deque Q = deque([vi]) checked_list = [False] * N checked_list[vi] = True while len(Q) > 0: v = Q.pop() for v1 in e_list[v]: if not checked_list[v1]: checked_list[v1] = True Q.appendleft(v1) count_list[v1] = count_list[v] + add_list[v1] print((*count_list))
false
10.526316
[ "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+" ]
false
0.108001
0.034618
3.11975
[ "s977638707", "s225120070" ]
u596536048
p03447
python
s975824870
s207904993
31
26
9,052
9,052
Accepted
Accepted
16.13
print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))
X, A, B = (int(eval(input())) for i in range(3)) print(((X - A) % B))
1
2
51
62
print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))
X, A, B = (int(eval(input())) for i in range(3)) print(((X - A) % B))
false
50
[ "-print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))", "+X, A, B = (int(eval(input())) for i in range(3))", "+print(((X - A) % B))" ]
false
0.046912
0.152407
0.307804
[ "s975824870", "s207904993" ]
u280552586
p03693
python
s159332003
s751294438
20
17
2,940
2,940
Accepted
Accepted
15
a, b, c = list(map(int, input().split())) A = 100*a + 10*b + c if A % 4 == 0: print('YES') else: print('NO')
r, g, b = list(map(int, input().split())) rgb = 100*r+10*g+b print(('YES' if rgb % 4 == 0 else 'NO'))
7
3
118
96
a, b, c = list(map(int, input().split())) A = 100 * a + 10 * b + c if A % 4 == 0: print("YES") else: print("NO")
r, g, b = list(map(int, input().split())) rgb = 100 * r + 10 * g + b print(("YES" if rgb % 4 == 0 else "NO"))
false
57.142857
[ "-a, b, c = list(map(int, input().split()))", "-A = 100 * a + 10 * b + c", "-if A % 4 == 0:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+r, g, b = list(map(int, input().split()))", "+rgb = 100 * r + 10 * g + b", "+print((\"YES\" if rgb % 4 == 0 else \"NO\"))" ]
false
0.063758
0.070984
0.8982
[ "s159332003", "s751294438" ]
u864197622
p02728
python
s500144790
s397021692
951
859
109,972
111,420
Accepted
Accepted
9.67
import sys input = sys.stdin.readline from collections import deque mod = 10 ** 9 + 7 N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) ##### Settings unit = 1 merge = lambda a, b: a * b % mod adj_bu = lambda a, i: a * inv(SIZE[i]) % mod adj_td = lambda a, i, p: a * inv(N-SIZE[i]) % mod adj_fin = lambda a, i: a * fa[N-1] % mod ##### nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod inv = lambda i: fainv[i] * fa[i-1] % mod SIZE = [1] * N for i in reversed(R[1:]): SIZE[P[i]] += SIZE[i] ME = [unit] * N XX = [0] * N TD = [unit] * N for i in reversed(R[1:]): XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in reversed(X[i]): TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) print(*XX, sep = "\n")
import sys input = sys.stdin.readline from collections import deque mod = 10 ** 9 + 7 N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) ##### Settings unit = 1 merge = lambda a, b: a * b % mod adj_bu = lambda a, i: a * inv(SIZE[i]) % mod adj_td = lambda a, i, p: a * inv(N-SIZE[i]) % mod adj_fin = lambda a, i: a * fa[N-1] % mod ##### nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod inv = lambda i: fainv[i] * fa[i-1] % mod SIZE = [1] * N for i in R[1:][::-1]: SIZE[P[i]] += SIZE[i] ME = [unit] * N XX = [0] * N TD = [unit] * N for i in R[1:][::-1]: XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in X[i][::-1]: TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) print(*XX, sep = "\n")
70
70
1,511
1,499
import sys input = sys.stdin.readline from collections import deque mod = 10**9 + 7 N = int(input()) X = [[] for i in range(N)] for i in range(N - 1): x, y = map(int, input().split()) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) ##### Settings unit = 1 merge = lambda a, b: a * b % mod adj_bu = lambda a, i: a * inv(SIZE[i]) % mod adj_td = lambda a, i, p: a * inv(N - SIZE[i]) % mod adj_fin = lambda a, i: a * fa[N - 1] % mod ##### nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod inv = lambda i: fainv[i] * fa[i - 1] % mod SIZE = [1] * N for i in reversed(R[1:]): SIZE[P[i]] += SIZE[i] ME = [unit] * N XX = [0] * N TD = [unit] * N for i in reversed(R[1:]): XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in reversed(X[i]): TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) print(*XX, sep="\n")
import sys input = sys.stdin.readline from collections import deque mod = 10**9 + 7 N = int(input()) X = [[] for i in range(N)] for i in range(N - 1): x, y = map(int, input().split()) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) ##### Settings unit = 1 merge = lambda a, b: a * b % mod adj_bu = lambda a, i: a * inv(SIZE[i]) % mod adj_td = lambda a, i, p: a * inv(N - SIZE[i]) % mod adj_fin = lambda a, i: a * fa[N - 1] % mod ##### nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod inv = lambda i: fainv[i] * fa[i - 1] % mod SIZE = [1] * N for i in R[1:][::-1]: SIZE[P[i]] += SIZE[i] ME = [unit] * N XX = [0] * N TD = [unit] * N for i in R[1:][::-1]: XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in X[i][::-1]: TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) print(*XX, sep="\n")
false
0
[ "-for i in reversed(R[1:]):", "+for i in R[1:][::-1]:", "-for i in reversed(R[1:]):", "+for i in R[1:][::-1]:", "- for j in reversed(X[i]):", "+ for j in X[i][::-1]:" ]
false
0.425907
0.258202
1.649513
[ "s500144790", "s397021692" ]
u991567869
p03575
python
s178481516
s406484543
331
29
53,388
9,220
Accepted
Accepted
91.24
import networkx as nx n, m = list(map(int, input().split())) g = nx.Graph() g.add_nodes_from(list(range(1, n + 1))) g.add_edges_from([tuple(map(int, input().split())) for i in range(m)]) print((len(tuple(nx.bridges(g)))))
def dfs(f): if vis[f] == 1: return vis[f] = 1 #fใ‚’่จชๅ•ๆธˆใซใ™ใ‚‹ for t in v[f]: #fใจใคใชใŒใฃใฆใ„ใ‚‹้ ‚็‚นใ‚’่ชญใฟ่พผใ‚€ if f != a or t != b: #(a,b)ใฎ็ต„ใฟๅˆใ‚ใ›ใงใชใ‘ใ‚Œใฐ็นฐใ‚Š่ฟ”ใ™ dfs(t) n, m = list(map(int, input().split())) v = [[] for i in range(n)] e = [] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 v[a].append(b) v[b].append(a) e.append([a, b]) ans = 0 for a, b in e: vis = [0]*n dfs(a) if vis[b] == 0: #aใ‹ใ‚‰a-bใฎ่พบไปฅๅค–ใ‚’่พฟใฃใฆbใซ่กŒใ‘ใ‚‹ใชใ‚‰1ใซใชใ‚‹ ans += 1 print(ans)
8
29
216
540
import networkx as nx n, m = list(map(int, input().split())) g = nx.Graph() g.add_nodes_from(list(range(1, n + 1))) g.add_edges_from([tuple(map(int, input().split())) for i in range(m)]) print((len(tuple(nx.bridges(g)))))
def dfs(f): if vis[f] == 1: return vis[f] = 1 # fใ‚’่จชๅ•ๆธˆใซใ™ใ‚‹ for t in v[f]: # fใจใคใชใŒใฃใฆใ„ใ‚‹้ ‚็‚นใ‚’่ชญใฟ่พผใ‚€ if f != a or t != b: # (a,b)ใฎ็ต„ใฟๅˆใ‚ใ›ใงใชใ‘ใ‚Œใฐ็นฐใ‚Š่ฟ”ใ™ dfs(t) n, m = list(map(int, input().split())) v = [[] for i in range(n)] e = [] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 v[a].append(b) v[b].append(a) e.append([a, b]) ans = 0 for a, b in e: vis = [0] * n dfs(a) if vis[b] == 0: # aใ‹ใ‚‰a-bใฎ่พบไปฅๅค–ใ‚’่พฟใฃใฆbใซ่กŒใ‘ใ‚‹ใชใ‚‰1ใซใชใ‚‹ ans += 1 print(ans)
false
72.413793
[ "-import networkx as nx", "+def dfs(f):", "+ if vis[f] == 1:", "+ return", "+ vis[f] = 1 # fใ‚’่จชๅ•ๆธˆใซใ™ใ‚‹", "+ for t in v[f]: # fใจใคใชใŒใฃใฆใ„ใ‚‹้ ‚็‚นใ‚’่ชญใฟ่พผใ‚€", "+ if f != a or t != b: # (a,b)ใฎ็ต„ใฟๅˆใ‚ใ›ใงใชใ‘ใ‚Œใฐ็นฐใ‚Š่ฟ”ใ™", "+ dfs(t)", "+", "-g = nx.Graph()", "-g.add_nodes_from(list(range(1, n + 1)))", "-g.add_edges_from([tuple(map(int, input().split())) for i in range(m)])", "-print((len(tuple(nx.bridges(g)))))", "+v = [[] for i in range(n)]", "+e = []", "+for i in range(m):", "+ a, b = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ v[a].append(b)", "+ v[b].append(a)", "+ e.append([a, b])", "+ans = 0", "+for a, b in e:", "+ vis = [0] * n", "+ dfs(a)", "+ if vis[b] == 0: # aใ‹ใ‚‰a-bใฎ่พบไปฅๅค–ใ‚’่พฟใฃใฆbใซ่กŒใ‘ใ‚‹ใชใ‚‰1ใซใชใ‚‹", "+ ans += 1", "+print(ans)" ]
false
0.037497
0.035428
1.058396
[ "s178481516", "s406484543" ]
u864197622
p02728
python
s227576585
s656623513
1,660
1,320
128,780
129,756
Accepted
Accepted
20.48
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) inv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i-1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N-1): x, y = list(map(int, input().split())) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AR = [1] * (c + 1) AL = 1 for k in range(c-1, 0, -1): j = X[i][k] AR[k] = AR[k+1] * BU[j] % mod for k, j in enumerate(X[i]): TD[j] = TD[i] * AL % mod * AR[k+1] % mod * inv[N - SI[j]] % mod AL = AL * BU[j] % mod for i in range(N): print((BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N-1, SI[i] - 1) % mod))
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) inv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i-1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0 N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for k, j in enumerate(X[i]): AL[k+1] = AL[k] * BU[j] % mod for k in range(c-1, 0, -1): j = X[i][k] AR[k] = AR[k+1] * BU[j] % mod for k, j in enumerate(X[i]): TD[j] = TD[i] * AL[k] % mod * AR[k+1] % mod * inv[N - SI[j]] % mod print(*[BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N-1, SI[i] - 1) % mod for i in range(N)], sep = "\n")
64
64
1,464
1,530
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) inv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i - 1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a - b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N - 1): x, y = list(map(int, input().split())) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AR = [1] * (c + 1) AL = 1 for k in range(c - 1, 0, -1): j = X[i][k] AR[k] = AR[k + 1] * BU[j] % mod for k, j in enumerate(X[i]): TD[j] = TD[i] * AL % mod * AR[k + 1] % mod * inv[N - SI[j]] % mod AL = AL * BU[j] % mod for i in range(N): print( ( BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N - 1, SI[i] - 1) % mod ) )
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) inv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i - 1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a - b] % mod if 0 <= b <= a else 0 N = int(input()) X = [[] for i in range(N)] for i in range(N - 1): x, y = map(int, input().split()) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for k, j in enumerate(X[i]): AL[k + 1] = AL[k] * BU[j] % mod for k in range(c - 1, 0, -1): j = X[i][k] AR[k] = AR[k + 1] * BU[j] % mod for k, j in enumerate(X[i]): TD[j] = TD[i] * AL[k] % mod * AR[k + 1] % mod * inv[N - SI[j]] % mod print( *[ BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N - 1, SI[i] - 1) % mod for i in range(N) ], sep="\n" )
false
0
[ "-N = int(eval(input()))", "+N = int(input())", "- x, y = list(map(int, input().split()))", "+ x, y = map(int, input().split())", "+ AL = [1] * (c + 1)", "- AL = 1", "+ for k, j in enumerate(X[i]):", "+ AL[k + 1] = AL[k] * BU[j] % mod", "- TD[j] = TD[i] * AL % mod * AR[k + 1] % mod * inv[N - SI[j]] % mod", "- AL = AL * BU[j] % mod", "-for i in range(N):", "- print(", "- (", "- BU[i]", "- * fa[SI[i]]", "- % mod", "- * TD[i]", "- % mod", "- * fa[N - SI[i]]", "- % mod", "- * C(N - 1, SI[i] - 1)", "- % mod", "- )", "- )", "+ TD[j] = TD[i] * AL[k] % mod * AR[k + 1] % mod * inv[N - SI[j]] % mod", "+print(", "+ *[", "+ BU[i]", "+ * fa[SI[i]]", "+ % mod", "+ * TD[i]", "+ % mod", "+ * fa[N - SI[i]]", "+ % mod", "+ * C(N - 1, SI[i] - 1)", "+ % mod", "+ for i in range(N)", "+ ],", "+ sep=\"\\n\"", "+)" ]
false
1.021927
0.418489
2.441946
[ "s227576585", "s656623513" ]
u470542271
p03078
python
s045480007
s347045276
785
717
196,748
248,536
Accepted
Accepted
8.66
if __name__ == '__main__': x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) bc = [] for bb in b: for cc in c: bc.append(bb + cc) bc.sort() from bisect import bisect_left def C(x): # count "abc >= x" ret = 0 for aa in a: idx = bisect_left(bc, x - aa) ret += len(bc) - idx return ret lb = 0 ub = (10 ** 10) * 3 + 1 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= k: lb = mid else: ub = mid kth = lb l = [] for aa in a: idx = bisect_left(bc, kth - aa) for i in range(idx, len(bc)): l.append(aa + bc[i]) l.sort(reverse=True) l = l[:k] for ll in l: print(ll)
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() bc = [] for bb in b: for cc in c: bc.append(bb + cc) bc.sort() from bisect import bisect_left, bisect_right def C(x): # count "abc <= x" ret = 0 for aa in a: idx = bisect_right(bc, x - aa) ret += idx return ret kk = x * y * z - k + 1 lb = 0 ub = (10 ** 10) * 4 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= kk: ub = mid else: lb = mid kth = ub l = [] for aa in a: idx = bisect_left(bc, kth - aa) for i in range(idx, len(bc)): l.append(aa + bc[i]) l.sort(reverse=True) l = l[:k] for ll in l: print(ll)
45
47
942
828
if __name__ == "__main__": x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) bc = [] for bb in b: for cc in c: bc.append(bb + cc) bc.sort() from bisect import bisect_left def C(x): # count "abc >= x" ret = 0 for aa in a: idx = bisect_left(bc, x - aa) ret += len(bc) - idx return ret lb = 0 ub = (10**10) * 3 + 1 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= k: lb = mid else: ub = mid kth = lb l = [] for aa in a: idx = bisect_left(bc, kth - aa) for i in range(idx, len(bc)): l.append(aa + bc[i]) l.sort(reverse=True) l = l[:k] for ll in l: print(ll)
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() bc = [] for bb in b: for cc in c: bc.append(bb + cc) bc.sort() from bisect import bisect_left, bisect_right def C(x): # count "abc <= x" ret = 0 for aa in a: idx = bisect_right(bc, x - aa) ret += idx return ret kk = x * y * z - k + 1 lb = 0 ub = (10**10) * 4 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= kk: ub = mid else: lb = mid kth = ub l = [] for aa in a: idx = bisect_left(bc, kth - aa) for i in range(idx, len(bc)): l.append(aa + bc[i]) l.sort(reverse=True) l = l[:k] for ll in l: print(ll)
false
4.255319
[ "-if __name__ == \"__main__\":", "- x, y, z, k = list(map(int, input().split()))", "- a = list(map(int, input().split()))", "- b = list(map(int, input().split()))", "- c = list(map(int, input().split()))", "- bc = []", "- for bb in b:", "- for cc in c:", "- bc.append(bb + cc)", "- bc.sort()", "- from bisect import bisect_left", "+x, y, z, k = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+b = list(map(int, input().split()))", "+c = list(map(int, input().split()))", "+a.sort()", "+b.sort()", "+c.sort()", "+bc = []", "+for bb in b:", "+ for cc in c:", "+ bc.append(bb + cc)", "+bc.sort()", "+from bisect import bisect_left, bisect_right", "- def C(x):", "- # count \"abc >= x\"", "- ret = 0", "- for aa in a:", "- idx = bisect_left(bc, x - aa)", "- ret += len(bc) - idx", "- return ret", "- lb = 0", "- ub = (10**10) * 3 + 1", "- while ub - lb > 1:", "- mid = (ub + lb) // 2", "- if C(mid) >= k:", "- lb = mid", "- else:", "- ub = mid", "- kth = lb", "- l = []", "+def C(x):", "+ # count \"abc <= x\"", "+ ret = 0", "- idx = bisect_left(bc, kth - aa)", "- for i in range(idx, len(bc)):", "- l.append(aa + bc[i])", "- l.sort(reverse=True)", "- l = l[:k]", "- for ll in l:", "- print(ll)", "+ idx = bisect_right(bc, x - aa)", "+ ret += idx", "+ return ret", "+", "+", "+kk = x * y * z - k + 1", "+lb = 0", "+ub = (10**10) * 4", "+while ub - lb > 1:", "+ mid = (ub + lb) // 2", "+ if C(mid) >= kk:", "+ ub = mid", "+ else:", "+ lb = mid", "+kth = ub", "+l = []", "+for aa in a:", "+ idx = bisect_left(bc, kth - aa)", "+ for i in range(idx, len(bc)):", "+ l.append(aa + bc[i])", "+l.sort(reverse=True)", "+l = l[:k]", "+for ll in l:", "+ print(ll)" ]
false
0.035523
0.036693
0.968119
[ "s045480007", "s347045276" ]
u824144553
p02804
python
s425539928
s371285452
298
248
74,536
21,572
Accepted
Accepted
16.78
import math from functools import lru_cache from operator import mul from functools import reduce def resolve(): import sys input = sys.stdin.readline MOD = 10**9 + 7 N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() B = A[::-1] @lru_cache(maxsize=None) def combinations_count__(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) @lru_cache(maxsize=None) def combinations_count____(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def combinations_count_(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] 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 result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) def combinations_count(n, r, mod=10**9+7): if (r < 0) or (n < r): return 0 r = min(r, n-r) return fact[n] * factinv[r] * factinv[n-r] % mod fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) sum = 0 for i in range(K-1, N): sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD print((sum % MOD)) if __name__ == "__main__": resolve()
import math from functools import lru_cache from operator import mul from functools import reduce def resolve(): import sys input = sys.stdin.readline MOD = 10**9 + 7 N, K = list(map(int, input().split())) A = list(map(int, input().split())) def combinations_count(n, r, mod=10**9+7): if (r < 0) or (n < r): return 0 r = min(r, n-r) return fact[n] * factinv[r] * factinv[n-r] % mod fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) A.sort() B = A[::-1] sum = 0 for i in range(K-1, N): sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD print((sum % MOD)) if __name__ == "__main__": resolve()
76
39
2,069
951
import math from functools import lru_cache from operator import mul from functools import reduce def resolve(): import sys input = sys.stdin.readline MOD = 10**9 + 7 N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() B = A[::-1] @lru_cache(maxsize=None) def combinations_count__(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) @lru_cache(maxsize=None) def combinations_count____(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def combinations_count_(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] 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 result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def modinv(a, mod=10**9 + 7): return pow(a, mod - 2, mod) def combinations_count(n, r, mod=10**9 + 7): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % mod fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) sum = 0 for i in range(K - 1, N): sum += ( combinations_count(i, K - 1) * A[i] % MOD - combinations_count(i, K - 1) * B[i] % MOD ) print((sum % MOD)) if __name__ == "__main__": resolve()
import math from functools import lru_cache from operator import mul from functools import reduce def resolve(): import sys input = sys.stdin.readline MOD = 10**9 + 7 N, K = list(map(int, input().split())) A = list(map(int, input().split())) def combinations_count(n, r, mod=10**9 + 7): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % mod fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) A.sort() B = A[::-1] sum = 0 for i in range(K - 1, N): sum += ( combinations_count(i, K - 1) * A[i] % MOD - combinations_count(i, K - 1) * B[i] % MOD ) print((sum % MOD)) if __name__ == "__main__": resolve()
false
48.684211
[ "- A.sort()", "- B = A[::-1]", "-", "- @lru_cache(maxsize=None)", "- def combinations_count__(n, r):", "- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "-", "- @lru_cache(maxsize=None)", "- def combinations_count____(n, r):", "- r = min(r, n - r)", "- numer = reduce(mul, list(range(n, n - r, -1)), 1)", "- denom = reduce(mul, list(range(1, r + 1)), 1)", "- return numer // denom", "-", "- def combinations_count_(n, r):", "- if n - r < r:", "- r = n - r", "- if r == 0:", "- return 1", "- if r == 1:", "- return n", "- numerator = [n - r + k + 1 for k in range(r)]", "- denominator = [k + 1 for k in range(r)]", "- 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", "- result = 1", "- for k in range(r):", "- if numerator[k] > 1:", "- result *= int(numerator[k])", "- return result", "-", "- def modinv(a, mod=10**9 + 7):", "- return pow(a, mod - 2, mod)", "+ A.sort()", "+ B = A[::-1]" ]
false
0.065929
0.034733
1.898164
[ "s425539928", "s371285452" ]
u729133443
p02813
python
s640651233
s141655659
188
29
44,656
7,972
Accepted
Accepted
84.57
from itertools import*;(n,),a,b=eval('tuple(map(int,input().split())),'*3);i=list(permutations(list(range(1,n+1)))).index;print((abs(i(a)-i(b))))
from itertools import* n,a,b=eval('eval(input().replace(" ",",")),'*3) i=list(permutations(list(range(1,n+1)))).index print((abs(i(a)-i(b))))
1
4
137
136
from itertools import * (n,), a, b = eval("tuple(map(int,input().split()))," * 3) i = list(permutations(list(range(1, n + 1)))).index print((abs(i(a) - i(b))))
from itertools import * n, a, b = eval('eval(input().replace(" ",",")),' * 3) i = list(permutations(list(range(1, n + 1)))).index print((abs(i(a) - i(b))))
false
75
[ "-(n,), a, b = eval(\"tuple(map(int,input().split())),\" * 3)", "+n, a, b = eval('eval(input().replace(\" \",\",\")),' * 3)" ]
false
0.082536
0.057581
1.433374
[ "s640651233", "s141655659" ]
u285891772
p03804
python
s934598416
s654447385
56
39
5,704
5,200
Accepted
Accepted
30.36
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd 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 ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np #from decimal import * N, M = MAP() A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for i in range(N-M+1): for j in range(N-M+1): #ๅทฆไธŠใฎใพใ™ใŒ(i, j) tmp_lis = [] for k in range(M): tmp_lis.append(A[i+k][j:j+M]) if tmp_lis == B: print("Yes") exit() else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd 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 ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np #from decimal import * N, M = MAP() A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for i in range(N-M+1): for j in range(N-M+1): for k in range(M): if A[i+k][j:j+M] != B[k]: break else: print("Yes") exit() else: print("No")
36
37
1,178
1,147
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd 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 ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # import numpy as np # from decimal import * N, M = MAP() A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for i in range(N - M + 1): for j in range(N - M + 1): # ๅทฆไธŠใฎใพใ™ใŒ(i, j) tmp_lis = [] for k in range(M): tmp_lis.append(A[i + k][j : j + M]) if tmp_lis == B: print("Yes") exit() else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd 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 ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # import numpy as np # from decimal import * N, M = MAP() A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for i in range(N - M + 1): for j in range(N - M + 1): for k in range(M): if A[i + k][j : j + M] != B[k]: break else: print("Yes") exit() else: print("No")
false
2.702703
[ "- for j in range(N - M + 1): # ๅทฆไธŠใฎใพใ™ใŒ(i, j)", "- tmp_lis = []", "+ for j in range(N - M + 1):", "- tmp_lis.append(A[i + k][j : j + M])", "- if tmp_lis == B:", "+ if A[i + k][j : j + M] != B[k]:", "+ break", "+ else:" ]
false
0.036622
0.05745
0.637462
[ "s934598416", "s654447385" ]
u223133214
p03618
python
s351983978
s869557779
57
34
4,840
5,224
Accepted
Accepted
40.35
A = list(eval(input())) n = len(A) str_cnt = {} for a in A: if a in str_cnt: str_cnt[a] += 1 else: str_cnt[a] = 1 # print(str_cnt) zen = n * (n - 1) // 2 + 1 for k in str_cnt: num = str_cnt[k] if num > 1: zen -= num * (num - 1) // 2 print(zen)
from collections import Counter A = list(eval(input())) n = len(A) b = Counter(A) z = n * (n - 1) // 2 + 1 for k in b: m = b[k] z -= m * (m - 1) // 2 print(z)
17
10
296
171
A = list(eval(input())) n = len(A) str_cnt = {} for a in A: if a in str_cnt: str_cnt[a] += 1 else: str_cnt[a] = 1 # print(str_cnt) zen = n * (n - 1) // 2 + 1 for k in str_cnt: num = str_cnt[k] if num > 1: zen -= num * (num - 1) // 2 print(zen)
from collections import Counter A = list(eval(input())) n = len(A) b = Counter(A) z = n * (n - 1) // 2 + 1 for k in b: m = b[k] z -= m * (m - 1) // 2 print(z)
false
41.176471
[ "+from collections import Counter", "+", "-str_cnt = {}", "-for a in A:", "- if a in str_cnt:", "- str_cnt[a] += 1", "- else:", "- str_cnt[a] = 1", "-# print(str_cnt)", "-zen = n * (n - 1) // 2 + 1", "-for k in str_cnt:", "- num = str_cnt[k]", "- if num > 1:", "- zen -= num * (num - 1) // 2", "-print(zen)", "+b = Counter(A)", "+z = n * (n - 1) // 2 + 1", "+for k in b:", "+ m = b[k]", "+ z -= m * (m - 1) // 2", "+print(z)" ]
false
0.112092
0.08742
1.282226
[ "s351983978", "s869557779" ]
u647999897
p03163
python
s923037539
s854730679
686
469
173,576
118,768
Accepted
Accepted
31.63
def solve(): N, W = list(map(int, input().split())) w = [] v = [] for i in range(N): tmpw, tmpv = list(map(int, input().split())) w.append(tmpw) v.append(tmpv) dp = [[0 for i in range(W+1)] for j in range(N+1)] for i in range(N+1): dp[i][0] = 0 for j in range(W+1): dp[0][j] = 0 for i in range(1,N+1): for sum_w in range(1, W+1): if sum_w - w[i-1] >= 0: dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w - w[i-1]] + v[i-1]) dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w]) print((dp[N][W])) if __name__ == '__main__': solve()
def solve(): N,W = list(map(int,input().split())) weight = [] value = [] for i in range(N): w, v = list(map(int,input().split())) weight.append(w) value.append(v) dp = [[0] * (W+1) for i in range(N+1)] for i in range(1,N+1): for w in range(W+1): if w - weight[i-1] < 0: dp[i][w] = max(dp[i][w], dp[i-1][w]) else: dp[i][w] = max(dp[i][w], dp[i-1][w-weight[i-1]] + value[i-1]) dp[i][w] = max(dp[i][w], dp[i-1][w]) print((max(dp[-1]))) if __name__ == '__main__': solve()
28
23
694
623
def solve(): N, W = list(map(int, input().split())) w = [] v = [] for i in range(N): tmpw, tmpv = list(map(int, input().split())) w.append(tmpw) v.append(tmpv) dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for j in range(W + 1): dp[0][j] = 0 for i in range(1, N + 1): for sum_w in range(1, W + 1): if sum_w - w[i - 1] >= 0: dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w - w[i - 1]] + v[i - 1]) dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w]) print((dp[N][W])) if __name__ == "__main__": solve()
def solve(): N, W = list(map(int, input().split())) weight = [] value = [] for i in range(N): w, v = list(map(int, input().split())) weight.append(w) value.append(v) dp = [[0] * (W + 1) for i in range(N + 1)] for i in range(1, N + 1): for w in range(W + 1): if w - weight[i - 1] < 0: dp[i][w] = max(dp[i][w], dp[i - 1][w]) else: dp[i][w] = max(dp[i][w], dp[i - 1][w - weight[i - 1]] + value[i - 1]) dp[i][w] = max(dp[i][w], dp[i - 1][w]) print((max(dp[-1]))) if __name__ == "__main__": solve()
false
17.857143
[ "- w = []", "- v = []", "+ weight = []", "+ value = []", "- tmpw, tmpv = list(map(int, input().split()))", "- w.append(tmpw)", "- v.append(tmpv)", "- dp = [[0 for i in range(W + 1)] for j in range(N + 1)]", "- for i in range(N + 1):", "- dp[i][0] = 0", "- for j in range(W + 1):", "- dp[0][j] = 0", "+ w, v = list(map(int, input().split()))", "+ weight.append(w)", "+ value.append(v)", "+ dp = [[0] * (W + 1) for i in range(N + 1)]", "- for sum_w in range(1, W + 1):", "- if sum_w - w[i - 1] >= 0:", "- dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w - w[i - 1]] + v[i - 1])", "- dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w])", "- print((dp[N][W]))", "+ for w in range(W + 1):", "+ if w - weight[i - 1] < 0:", "+ dp[i][w] = max(dp[i][w], dp[i - 1][w])", "+ else:", "+ dp[i][w] = max(dp[i][w], dp[i - 1][w - weight[i - 1]] + value[i - 1])", "+ dp[i][w] = max(dp[i][w], dp[i - 1][w])", "+ print((max(dp[-1])))" ]
false
0.045651
0.044561
1.02447
[ "s923037539", "s854730679" ]
u450983668
p03043
python
s308026360
s844506165
65
47
3,060
2,940
Accepted
Accepted
27.69
from math import * n,k=list(map(int,input().split())) e=0 for i in range(1,n+1): t=ceil(log2(k/i)) e+=1*(t<1)or 2**-t print((e/n))
n, k = list(map(int, input().split())) e=0 for i in range(1, n+1): tmp = i t = 0 while tmp < k: tmp *= 2 t += 1 e += 1*(t==0) or 2**-t print((e/n))
7
10
132
164
from math import * n, k = list(map(int, input().split())) e = 0 for i in range(1, n + 1): t = ceil(log2(k / i)) e += 1 * (t < 1) or 2**-t print((e / n))
n, k = list(map(int, input().split())) e = 0 for i in range(1, n + 1): tmp = i t = 0 while tmp < k: tmp *= 2 t += 1 e += 1 * (t == 0) or 2**-t print((e / n))
false
30
[ "-from math import *", "-", "- t = ceil(log2(k / i))", "- e += 1 * (t < 1) or 2**-t", "+ tmp = i", "+ t = 0", "+ while tmp < k:", "+ tmp *= 2", "+ t += 1", "+ e += 1 * (t == 0) or 2**-t" ]
false
0.057054
0.052184
1.093317
[ "s308026360", "s844506165" ]
u814781830
p03287
python
s875125762
s562181589
234
103
62,576
84,732
Accepted
Accepted
55.98
from collections import defaultdict N, M = list(map(int, input().split())) A = list(map(int, input().split())) amount = [0] * (N+1) for i in range(N): amount[i+1] = amount[i] + A[i] amount[i+1] %= M ans = 0 di = defaultdict(int) for i in range(N): ans += di[amount[i+1]] di[amount[i+1]] += 1 print((ans + di[0]))
from collections import Counter N, M = list(map(int, input().split())) A = list(map(int, input().split())) tmp = 0 for i in range(N): A[i] += tmp A[i] %= M tmp = A[i] c = Counter(A) ans = 0 for k, v in list(c.items()): if k == 0: ans += v ans += v * (v-1) // 2 print(ans)
17
17
341
306
from collections import defaultdict N, M = list(map(int, input().split())) A = list(map(int, input().split())) amount = [0] * (N + 1) for i in range(N): amount[i + 1] = amount[i] + A[i] amount[i + 1] %= M ans = 0 di = defaultdict(int) for i in range(N): ans += di[amount[i + 1]] di[amount[i + 1]] += 1 print((ans + di[0]))
from collections import Counter N, M = list(map(int, input().split())) A = list(map(int, input().split())) tmp = 0 for i in range(N): A[i] += tmp A[i] %= M tmp = A[i] c = Counter(A) ans = 0 for k, v in list(c.items()): if k == 0: ans += v ans += v * (v - 1) // 2 print(ans)
false
0
[ "-from collections import defaultdict", "+from collections import Counter", "-amount = [0] * (N + 1)", "+tmp = 0", "- amount[i + 1] = amount[i] + A[i]", "- amount[i + 1] %= M", "+ A[i] += tmp", "+ A[i] %= M", "+ tmp = A[i]", "+c = Counter(A)", "-di = defaultdict(int)", "-for i in range(N):", "- ans += di[amount[i + 1]]", "- di[amount[i + 1]] += 1", "-print((ans + di[0]))", "+for k, v in list(c.items()):", "+ if k == 0:", "+ ans += v", "+ ans += v * (v - 1) // 2", "+print(ans)" ]
false
0.042945
0.084084
0.510735
[ "s875125762", "s562181589" ]
u440566786
p03111
python
s399615195
s944211460
610
561
69,468
68,572
Accepted
Accepted
8.03
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,a,b,c=list(map(int,input().split())) L=[int(eval(input())) for _ in range(n)] def dfs(v,Idx)->int: # terminate condition if(v==n): score=0 Idx=tuple(Idx) A,B,C=[],[],[] for i,k in enumerate(Idx): if(k==0): A.append(L[i]) elif(k==1): B.append(L[i]) elif(k==2): C.append(L[i]) if((not A) or (not B) or (not C)): return INF # 1ใคใ‚‚็ซนใŒ็„กใ„ใฎใฏใƒ€ใƒก score+=(len(A)+len(B)+len(C)-3)*10 SA=sum(A) SB=sum(B) SC=sum(C) score+=abs(SA-a) score+=abs(SB-b) score+=abs(SC-c) return score res=INF for i in range(4): res=min(res,dfs(v+1,Idx+[i])) return res print((dfs(0,[]))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,a,b,c=list(map(int,input().split())) L=[int(eval(input())) for _ in range(n)] def dfs(v,Idx)->int: # terminate condition if(v==n): score=0 Idx=tuple(Idx) A,B,C=[],[],[] for i,k in enumerate(Idx): if(k==0): A.append(L[i]) elif(k==1): B.append(L[i]) elif(k==2): C.append(L[i]) if((not A) or (not B) or (not C)): return INF # 1ใคใ‚‚็ซนใŒ็„กใ„ใฎใฏใƒ€ใƒก score+=(len(A)+len(B)+len(C)-3)*10 SA=sum(A) SB=sum(B) SC=sum(C) score+=abs(SA-a) score+=abs(SB-b) score+=abs(SC-c) return score res=INF for i in range(4): Idx[v]=i res=min(res,dfs(v+1,Idx)) return res print((dfs(0,[0]*n))) resolve()
38
38
995
1,026
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, a, b, c = list(map(int, input().split())) L = [int(eval(input())) for _ in range(n)] def dfs(v, Idx) -> int: # terminate condition if v == n: score = 0 Idx = tuple(Idx) A, B, C = [], [], [] for i, k in enumerate(Idx): if k == 0: A.append(L[i]) elif k == 1: B.append(L[i]) elif k == 2: C.append(L[i]) if (not A) or (not B) or (not C): return INF # 1ใคใ‚‚็ซนใŒ็„กใ„ใฎใฏใƒ€ใƒก score += (len(A) + len(B) + len(C) - 3) * 10 SA = sum(A) SB = sum(B) SC = sum(C) score += abs(SA - a) score += abs(SB - b) score += abs(SC - c) return score res = INF for i in range(4): res = min(res, dfs(v + 1, Idx + [i])) return res print((dfs(0, []))) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, a, b, c = list(map(int, input().split())) L = [int(eval(input())) for _ in range(n)] def dfs(v, Idx) -> int: # terminate condition if v == n: score = 0 Idx = tuple(Idx) A, B, C = [], [], [] for i, k in enumerate(Idx): if k == 0: A.append(L[i]) elif k == 1: B.append(L[i]) elif k == 2: C.append(L[i]) if (not A) or (not B) or (not C): return INF # 1ใคใ‚‚็ซนใŒ็„กใ„ใฎใฏใƒ€ใƒก score += (len(A) + len(B) + len(C) - 3) * 10 SA = sum(A) SB = sum(B) SC = sum(C) score += abs(SA - a) score += abs(SB - b) score += abs(SC - c) return score res = INF for i in range(4): Idx[v] = i res = min(res, dfs(v + 1, Idx)) return res print((dfs(0, [0] * n))) resolve()
false
0
[ "- res = min(res, dfs(v + 1, Idx + [i]))", "+ Idx[v] = i", "+ res = min(res, dfs(v + 1, Idx))", "- print((dfs(0, [])))", "+ print((dfs(0, [0] * n)))" ]
false
0.139547
0.160628
0.868758
[ "s399615195", "s944211460" ]
u389910364
p03972
python
s773558663
s656818763
449
292
26,300
13,080
Accepted
Accepted
34.97
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใใHใจWใŽใ‚ƒใใ  W,H = list(map(int, sys.stdin.readline().split())) P = [int(sys.stdin.readline()) for _ in range(W)] Q = [int(sys.stdin.readline()) for _ in range(H)] edges = [] for p in P: edges.append((p, 'P')) for q in Q: edges.append((q, 'Q')) edges.sort() ans = 0 a = W + 1 b = H + 1 for e, pq in edges: if pq == 'P': ans += e * b a -= 1 else: ans += e * a b -= 1 print(ans)
import itertools import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 class UnionFind: def __init__(self, size=None, nodes=None): """ size ใ‹ nodes ใฉใฃใกใ‹ๆŒ‡ๅฎšใ€‚ nodes ใฏ setใ€size ใฏ list ใ‚’ไฝฟใ†ใ€‚ set ใฎๆœ€ๆ‚ช่จˆ็ฎ—้‡ใฏ O(N) ใชใฎใง size ๆŒ‡ๅฎšใฎใปใ†ใŒ่‹ฅๅนฒ้€Ÿใ„ :param int size: :param collections.Iterable nodes: """ assert size is not None or nodes is not None if size is not None: self._parents = [i for i in range(size)] self._ranks = [0 for _ in range(size)] self._sizes = [1 for _ in range(size)] else: self._parents = {k: k for k in nodes} self._ranks = {k: 0 for k in nodes} self._sizes = {k: 1 for k in nodes} def unite(self, x, y): """ x ใŒๅฑžใ™ใ‚‹ๆœจใจ y ใŒๅฑžใ™ใ‚‹ๆœจใ‚’ไฝตๅˆ :param x: :param y: :return: """ x = self.root(x) y = self.root(y) if x == y: return # rank ใŒๅฐใ•ใ„ๆ–นใŒไธ‹ if self._ranks[x] > self._ranks[y]: # x ใŒ root self._parents[y] = x self._sizes[x] += self._sizes[y] else: # y ใŒ root self._parents[x] = y self._sizes[y] += self._sizes[x] if self._ranks[x] == self._ranks[y]: self._ranks[y] += 1 def root(self, x): """ x ใŒๅฑžใ™ใ‚‹ๆœจใฎ root :param x: :return: """ if self._parents[x] == x: return x self._parents[x] = self.root(self._parents[x]) return self._parents[x] def size(self, x): """ x ใŒๅฑžใ™ใ‚‹ๆœจใฎใƒŽใƒผใƒ‰ๆ•ฐ :param x: :return: """ return self._sizes[self.root(x)] W, H = list(map(int, sys.stdin.readline().split())) P = [int(sys.stdin.readline()) for _ in range(W)] Q = [int(sys.stdin.readline()) for _ in range(H)] def test(): edges = [] vs = [] for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))): if w < W: edges.append((P[w], (w, h), (w + 1, h))) if h < H: edges.append((Q[h], (w, h), (w, h + 1))) for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))): vs.append((w, h)) edges.sort() # kruskal uf = UnionFind(nodes=vs) ret = 0 for s, v, u in edges: if uf.root(v) != uf.root(u): uf.unite(v, u) ret += s return ret # ๆจชๆฃ’ hs = P.copy() # ็ธฆๆฃ’ vs = Q.copy() hs.sort(reverse=True) vs.sort(reverse=True) ans = 0 v_nodes = W + 1 h_nodes = H + 1 while hs or vs: if not vs or (hs and hs[-1] < vs[-1]): # ๆจชๆฃ’ใ‚’ไฝฟใ† # ใพใ ใใฃใคใ‘ใฆใชใ„ๆจช่ปธใฎๆ•ฐใ ใ‘่พบใ‚’ๅผตใ‚‹ ans += hs.pop() * h_nodes v_nodes -= 1 else: # ็ธฆๆฃ’ใฎใŒ็Ÿญใ„ ans += vs.pop() * v_nodes h_nodes -= 1 print(ans) # print(test())
34
127
641
3,045
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใใHใจWใŽใ‚ƒใใ  W, H = list(map(int, sys.stdin.readline().split())) P = [int(sys.stdin.readline()) for _ in range(W)] Q = [int(sys.stdin.readline()) for _ in range(H)] edges = [] for p in P: edges.append((p, "P")) for q in Q: edges.append((q, "Q")) edges.sort() ans = 0 a = W + 1 b = H + 1 for e, pq in edges: if pq == "P": ans += e * b a -= 1 else: ans += e * a b -= 1 print(ans)
import itertools import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 class UnionFind: def __init__(self, size=None, nodes=None): """ size ใ‹ nodes ใฉใฃใกใ‹ๆŒ‡ๅฎšใ€‚ nodes ใฏ setใ€size ใฏ list ใ‚’ไฝฟใ†ใ€‚ set ใฎๆœ€ๆ‚ช่จˆ็ฎ—้‡ใฏ O(N) ใชใฎใง size ๆŒ‡ๅฎšใฎใปใ†ใŒ่‹ฅๅนฒ้€Ÿใ„ :param int size: :param collections.Iterable nodes: """ assert size is not None or nodes is not None if size is not None: self._parents = [i for i in range(size)] self._ranks = [0 for _ in range(size)] self._sizes = [1 for _ in range(size)] else: self._parents = {k: k for k in nodes} self._ranks = {k: 0 for k in nodes} self._sizes = {k: 1 for k in nodes} def unite(self, x, y): """ x ใŒๅฑžใ™ใ‚‹ๆœจใจ y ใŒๅฑžใ™ใ‚‹ๆœจใ‚’ไฝตๅˆ :param x: :param y: :return: """ x = self.root(x) y = self.root(y) if x == y: return # rank ใŒๅฐใ•ใ„ๆ–นใŒไธ‹ if self._ranks[x] > self._ranks[y]: # x ใŒ root self._parents[y] = x self._sizes[x] += self._sizes[y] else: # y ใŒ root self._parents[x] = y self._sizes[y] += self._sizes[x] if self._ranks[x] == self._ranks[y]: self._ranks[y] += 1 def root(self, x): """ x ใŒๅฑžใ™ใ‚‹ๆœจใฎ root :param x: :return: """ if self._parents[x] == x: return x self._parents[x] = self.root(self._parents[x]) return self._parents[x] def size(self, x): """ x ใŒๅฑžใ™ใ‚‹ๆœจใฎใƒŽใƒผใƒ‰ๆ•ฐ :param x: :return: """ return self._sizes[self.root(x)] W, H = list(map(int, sys.stdin.readline().split())) P = [int(sys.stdin.readline()) for _ in range(W)] Q = [int(sys.stdin.readline()) for _ in range(H)] def test(): edges = [] vs = [] for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))): if w < W: edges.append((P[w], (w, h), (w + 1, h))) if h < H: edges.append((Q[h], (w, h), (w, h + 1))) for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))): vs.append((w, h)) edges.sort() # kruskal uf = UnionFind(nodes=vs) ret = 0 for s, v, u in edges: if uf.root(v) != uf.root(u): uf.unite(v, u) ret += s return ret # ๆจชๆฃ’ hs = P.copy() # ็ธฆๆฃ’ vs = Q.copy() hs.sort(reverse=True) vs.sort(reverse=True) ans = 0 v_nodes = W + 1 h_nodes = H + 1 while hs or vs: if not vs or (hs and hs[-1] < vs[-1]): # ๆจชๆฃ’ใ‚’ไฝฟใ† # ใพใ ใใฃใคใ‘ใฆใชใ„ๆจช่ปธใฎๆ•ฐใ ใ‘่พบใ‚’ๅผตใ‚‹ ans += hs.pop() * h_nodes v_nodes -= 1 else: # ็ธฆๆฃ’ใฎใŒ็Ÿญใ„ ans += vs.pop() * v_nodes h_nodes -= 1 print(ans) # print(test())
false
73.228346
[ "+import itertools", "-# ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใ‚ใใHใจWใŽใ‚ƒใใ ", "+", "+", "+class UnionFind:", "+ def __init__(self, size=None, nodes=None):", "+ \"\"\"", "+ size ใ‹ nodes ใฉใฃใกใ‹ๆŒ‡ๅฎšใ€‚", "+ nodes ใฏ setใ€size ใฏ list ใ‚’ไฝฟใ†ใ€‚", "+ set ใฎๆœ€ๆ‚ช่จˆ็ฎ—้‡ใฏ O(N) ใชใฎใง size ๆŒ‡ๅฎšใฎใปใ†ใŒ่‹ฅๅนฒ้€Ÿใ„", "+ :param int size:", "+ :param collections.Iterable nodes:", "+ \"\"\"", "+ assert size is not None or nodes is not None", "+ if size is not None:", "+ self._parents = [i for i in range(size)]", "+ self._ranks = [0 for _ in range(size)]", "+ self._sizes = [1 for _ in range(size)]", "+ else:", "+ self._parents = {k: k for k in nodes}", "+ self._ranks = {k: 0 for k in nodes}", "+ self._sizes = {k: 1 for k in nodes}", "+", "+ def unite(self, x, y):", "+ \"\"\"", "+ x ใŒๅฑžใ™ใ‚‹ๆœจใจ y ใŒๅฑžใ™ใ‚‹ๆœจใ‚’ไฝตๅˆ", "+ :param x:", "+ :param y:", "+ :return:", "+ \"\"\"", "+ x = self.root(x)", "+ y = self.root(y)", "+ if x == y:", "+ return", "+ # rank ใŒๅฐใ•ใ„ๆ–นใŒไธ‹", "+ if self._ranks[x] > self._ranks[y]:", "+ # x ใŒ root", "+ self._parents[y] = x", "+ self._sizes[x] += self._sizes[y]", "+ else:", "+ # y ใŒ root", "+ self._parents[x] = y", "+ self._sizes[y] += self._sizes[x]", "+ if self._ranks[x] == self._ranks[y]:", "+ self._ranks[y] += 1", "+", "+ def root(self, x):", "+ \"\"\"", "+ x ใŒๅฑžใ™ใ‚‹ๆœจใฎ root", "+ :param x:", "+ :return:", "+ \"\"\"", "+ if self._parents[x] == x:", "+ return x", "+ self._parents[x] = self.root(self._parents[x])", "+ return self._parents[x]", "+", "+ def size(self, x):", "+ \"\"\"", "+ x ใŒๅฑžใ™ใ‚‹ๆœจใฎใƒŽใƒผใƒ‰ๆ•ฐ", "+ :param x:", "+ :return:", "+ \"\"\"", "+ return self._sizes[self.root(x)]", "+", "+", "-edges = []", "-for p in P:", "- edges.append((p, \"P\"))", "-for q in Q:", "- edges.append((q, \"Q\"))", "-edges.sort()", "+", "+", "+def test():", "+ edges = []", "+ vs = []", "+ for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))):", "+ if w < W:", "+ edges.append((P[w], (w, h), (w + 1, h)))", "+ if h < H:", "+ edges.append((Q[h], (w, h), (w, h + 1)))", "+ for h, w in itertools.product(list(range(H + 1)), list(range(W + 1))):", "+ vs.append((w, h))", "+ edges.sort()", "+ # kruskal", "+ uf = UnionFind(nodes=vs)", "+ ret = 0", "+ for s, v, u in edges:", "+ if uf.root(v) != uf.root(u):", "+ uf.unite(v, u)", "+ ret += s", "+ return ret", "+", "+", "+# ๆจชๆฃ’", "+hs = P.copy()", "+# ็ธฆๆฃ’", "+vs = Q.copy()", "+hs.sort(reverse=True)", "+vs.sort(reverse=True)", "-a = W + 1", "-b = H + 1", "-for e, pq in edges:", "- if pq == \"P\":", "- ans += e * b", "- a -= 1", "+v_nodes = W + 1", "+h_nodes = H + 1", "+while hs or vs:", "+ if not vs or (hs and hs[-1] < vs[-1]):", "+ # ๆจชๆฃ’ใ‚’ไฝฟใ†", "+ # ใพใ ใใฃใคใ‘ใฆใชใ„ๆจช่ปธใฎๆ•ฐใ ใ‘่พบใ‚’ๅผตใ‚‹", "+ ans += hs.pop() * h_nodes", "+ v_nodes -= 1", "- ans += e * a", "- b -= 1", "+ # ็ธฆๆฃ’ใฎใŒ็Ÿญใ„", "+ ans += vs.pop() * v_nodes", "+ h_nodes -= 1", "+# print(test())" ]
false
0.058433
0.142249
0.410781
[ "s773558663", "s656818763" ]
u759412327
p02771
python
s210807535
s195655250
22
17
3,316
3,060
Accepted
Accepted
22.73
A,B,C = sorted(list(map(int,input().split()))) if A==B and B==C: print("No") elif A==B or B==C: print("Yes") else: print("No")
if len(set(map(int,input().split())))==2: print("Yes") else: print("No")
8
4
140
79
A, B, C = sorted(list(map(int, input().split()))) if A == B and B == C: print("No") elif A == B or B == C: print("Yes") else: print("No")
if len(set(map(int, input().split()))) == 2: print("Yes") else: print("No")
false
50
[ "-A, B, C = sorted(list(map(int, input().split())))", "-if A == B and B == C:", "- print(\"No\")", "-elif A == B or B == C:", "+if len(set(map(int, input().split()))) == 2:" ]
false
0.078773
0.045429
1.734
[ "s210807535", "s195655250" ]
u604774382
p02408
python
s251594759
s181818324
30
20
6,752
4,248
Accepted
Accepted
33.33
import sys n = int( sys.stdin.readline() ) s = [ False ] * 13 h = [ False ] * 13 c = [ False ] * 13 d = [ False ] * 13 for i in range( 0, n ): pattern, num = sys.stdin.readline().split( " " ) if "S" == pattern: s[ int( num )-1 ] = True elif "H" == pattern: h[ int( num )-1 ] = True elif "C" == pattern: c[ int( num )-1 ] = True elif "D" == pattern: d[ int( num )-1 ] = True for i in range( 0, 13 ): if not s[i]: print(( "S {:d}".format( i+1 ) )) for i in range( 0, 13 ): if not h[i]: print(( "H {:d}".format( i+1 ) )) for i in range( 0, 13 ): if not c[i]: print(( "C {:d}".format( i+1 ) )) for i in range( 0, 13 ): if not d[i]: print(( "D {:d}".format( i+1 ) ))
import sys n = int( sys.stdin.readline() ) cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 } for i in range( n ): pattern, num = sys.stdin.readline().split( " " ) if "S" == pattern: cards[ 'S' ][ int( num )-1 ] = True elif "H" == pattern: cards[ 'H' ][ int( num )-1 ] = True elif "C" == pattern: cards[ 'C' ][ int( num )-1 ] = True elif "D" == pattern: cards[ 'D' ][ int( num )-1 ] = True for pattern in ( 'S', 'H', 'C', 'D' ): for i in range( 13 ): if not cards[ pattern ][ i ]: print(( "{:s} {:d}".format( pattern, i+1 ) ))
30
19
709
607
import sys n = int(sys.stdin.readline()) s = [False] * 13 h = [False] * 13 c = [False] * 13 d = [False] * 13 for i in range(0, n): pattern, num = sys.stdin.readline().split(" ") if "S" == pattern: s[int(num) - 1] = True elif "H" == pattern: h[int(num) - 1] = True elif "C" == pattern: c[int(num) - 1] = True elif "D" == pattern: d[int(num) - 1] = True for i in range(0, 13): if not s[i]: print(("S {:d}".format(i + 1))) for i in range(0, 13): if not h[i]: print(("H {:d}".format(i + 1))) for i in range(0, 13): if not c[i]: print(("C {:d}".format(i + 1))) for i in range(0, 13): if not d[i]: print(("D {:d}".format(i + 1)))
import sys n = int(sys.stdin.readline()) cards = {"S": [False] * 13, "H": [False] * 13, "C": [False] * 13, "D": [False] * 13} for i in range(n): pattern, num = sys.stdin.readline().split(" ") if "S" == pattern: cards["S"][int(num) - 1] = True elif "H" == pattern: cards["H"][int(num) - 1] = True elif "C" == pattern: cards["C"][int(num) - 1] = True elif "D" == pattern: cards["D"][int(num) - 1] = True for pattern in ("S", "H", "C", "D"): for i in range(13): if not cards[pattern][i]: print(("{:s} {:d}".format(pattern, i + 1)))
false
36.666667
[ "-s = [False] * 13", "-h = [False] * 13", "-c = [False] * 13", "-d = [False] * 13", "-for i in range(0, n):", "+cards = {\"S\": [False] * 13, \"H\": [False] * 13, \"C\": [False] * 13, \"D\": [False] * 13}", "+for i in range(n):", "- s[int(num) - 1] = True", "+ cards[\"S\"][int(num) - 1] = True", "- h[int(num) - 1] = True", "+ cards[\"H\"][int(num) - 1] = True", "- c[int(num) - 1] = True", "+ cards[\"C\"][int(num) - 1] = True", "- d[int(num) - 1] = True", "-for i in range(0, 13):", "- if not s[i]:", "- print((\"S {:d}\".format(i + 1)))", "-for i in range(0, 13):", "- if not h[i]:", "- print((\"H {:d}\".format(i + 1)))", "-for i in range(0, 13):", "- if not c[i]:", "- print((\"C {:d}\".format(i + 1)))", "-for i in range(0, 13):", "- if not d[i]:", "- print((\"D {:d}\".format(i + 1)))", "+ cards[\"D\"][int(num) - 1] = True", "+for pattern in (\"S\", \"H\", \"C\", \"D\"):", "+ for i in range(13):", "+ if not cards[pattern][i]:", "+ print((\"{:s} {:d}\".format(pattern, i + 1)))" ]
false
0.043717
0.086302
0.506554
[ "s251594759", "s181818324" ]
u886921509
p03042
python
s748145626
s477897014
28
24
9,128
9,052
Accepted
Accepted
14.29
S = str(eval(input())) front = int(S[:2]) back = int(S[2:]) S_list = list(S) if front > 12 or front == 0: if 0 < back <= 12 : print("YYMM") else: print("NA") elif front <= 12 or front == 0: if 0 < back <= 12: print("AMBIGUOUS") else: print("MMYY")
S = str(eval(input())) front = int(S[:2]) back = int(S[2:]) if front > 12 or front == 0: if 0 < back <= 12 : print("YYMM") else: print("NA") elif front <= 12 or front == 0: if 0 < back <= 12: print("AMBIGUOUS") else: print("MMYY")
15
14
305
287
S = str(eval(input())) front = int(S[:2]) back = int(S[2:]) S_list = list(S) if front > 12 or front == 0: if 0 < back <= 12: print("YYMM") else: print("NA") elif front <= 12 or front == 0: if 0 < back <= 12: print("AMBIGUOUS") else: print("MMYY")
S = str(eval(input())) front = int(S[:2]) back = int(S[2:]) if front > 12 or front == 0: if 0 < back <= 12: print("YYMM") else: print("NA") elif front <= 12 or front == 0: if 0 < back <= 12: print("AMBIGUOUS") else: print("MMYY")
false
6.666667
[ "-S_list = list(S)" ]
false
0.08138
0.03704
2.197069
[ "s748145626", "s477897014" ]
u562935282
p02936
python
s074935693
s508989886
1,927
1,051
295,528
81,440
Accepted
Accepted
45.46
def main(): import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline N, Q = list(map(int, input().split())) Graph = tuple(set() for _ in range(N)) for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) Graph[a].add(b) Graph[b].add(a) ctr = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 ctr[p] += x root = 0 visited = [False] * N visited[root] = True def dfs(v): x = ctr[v] for u in Graph[v]: if visited[u]: continue visited[u] = True ctr[u] += x dfs(u) dfs(root) print((*ctr)) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
def main(): from collections import deque import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) Graph = tuple(set() for _ in range(N)) for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) Graph[a].add(b) Graph[b].add(a) ctr = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 ctr[p] += x root = 0 visited = [False] * N visited[root] = True dq = deque() dq.append(root) while dq: v = dq.pop() x = ctr[v] for u in Graph[v]: if visited[u]: continue visited[u] = True ctr[u] += x dq.append(u) print((*ctr)) if __name__ == '__main__': main()
50
41
931
833
def main(): import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline N, Q = list(map(int, input().split())) Graph = tuple(set() for _ in range(N)) for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) Graph[a].add(b) Graph[b].add(a) ctr = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 ctr[p] += x root = 0 visited = [False] * N visited[root] = True def dfs(v): x = ctr[v] for u in Graph[v]: if visited[u]: continue visited[u] = True ctr[u] += x dfs(u) dfs(root) print((*ctr)) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
def main(): from collections import deque import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) Graph = tuple(set() for _ in range(N)) for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) Graph[a].add(b) Graph[b].add(a) ctr = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) p -= 1 ctr[p] += x root = 0 visited = [False] * N visited[root] = True dq = deque() dq.append(root) while dq: v = dq.pop() x = ctr[v] for u in Graph[v]: if visited[u]: continue visited[u] = True ctr[u] += x dq.append(u) print((*ctr)) if __name__ == "__main__": main()
false
18
[ "+ from collections import deque", "- sys.setrecursionlimit(10**7)", "-", "- def dfs(v):", "+ dq = deque()", "+ dq.append(root)", "+ while dq:", "+ v = dq.pop()", "- dfs(u)", "-", "- dfs(root)", "+ dq.append(u)", "-# import sys", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# input = sys.stdin.readline", "-# rstrip()", "-# int(input())", "-# map(int, input().split())" ]
false
0.036538
0.036559
0.999426
[ "s074935693", "s508989886" ]
u079022693
p03147
python
s805215330
s387491881
41
18
3,064
3,064
Accepted
Accepted
56.1
from sys import stdin def main(): #ๅ…ฅๅŠ› readline=stdin.readline N=int(readline()) h=list(map(int,readline().split())) count=0 while 1: first=True for i in range(N): if first and h[i]>=1: first=False h[i]-=1 elif first and h[i]==0: pass elif first is False and h[i]>=1: h[i]-=1 elif first is False and h[i]==0: break if first: break else: count+=1 print(count) if __name__=="__main__": main()
from sys import stdin def main(): #ๅ…ฅๅŠ› readline=stdin.readline n=int(readline()) h=list(map(int,readline().split())) ans=0 while True: flag=True flag2=True for i in range(n): if h[i]>0: h[i]-=1 flag=False flag2=False if i==n-1: ans+=1 else: if flag2==False: flag2=True ans+=1 if flag: break print(ans) if __name__=="__main__": main()
28
27
634
588
from sys import stdin def main(): # ๅ…ฅๅŠ› readline = stdin.readline N = int(readline()) h = list(map(int, readline().split())) count = 0 while 1: first = True for i in range(N): if first and h[i] >= 1: first = False h[i] -= 1 elif first and h[i] == 0: pass elif first is False and h[i] >= 1: h[i] -= 1 elif first is False and h[i] == 0: break if first: break else: count += 1 print(count) if __name__ == "__main__": main()
from sys import stdin def main(): # ๅ…ฅๅŠ› readline = stdin.readline n = int(readline()) h = list(map(int, readline().split())) ans = 0 while True: flag = True flag2 = True for i in range(n): if h[i] > 0: h[i] -= 1 flag = False flag2 = False if i == n - 1: ans += 1 else: if flag2 == False: flag2 = True ans += 1 if flag: break print(ans) if __name__ == "__main__": main()
false
3.571429
[ "- N = int(readline())", "+ n = int(readline())", "- count = 0", "- while 1:", "- first = True", "- for i in range(N):", "- if first and h[i] >= 1:", "- first = False", "+ ans = 0", "+ while True:", "+ flag = True", "+ flag2 = True", "+ for i in range(n):", "+ if h[i] > 0:", "- elif first and h[i] == 0:", "- pass", "- elif first is False and h[i] >= 1:", "- h[i] -= 1", "- elif first is False and h[i] == 0:", "- break", "- if first:", "+ flag = False", "+ flag2 = False", "+ if i == n - 1:", "+ ans += 1", "+ else:", "+ if flag2 == False:", "+ flag2 = True", "+ ans += 1", "+ if flag:", "- else:", "- count += 1", "- print(count)", "+ print(ans)" ]
false
0.082846
0.036503
2.269589
[ "s805215330", "s387491881" ]
u502389123
p03212
python
s319835919
s930235153
111
67
3,064
3,064
Accepted
Accepted
39.64
N = int(eval(input())) def dfs(x): if x > N: return 0 san, go, nana = 0, 0, 0 c = x for i in range(len(str(c))): if c % 10 == 3: san += 1 elif c % 10 == 5: go += 1 elif c % 10 == 7: nana += 1 c = c // 10 if san > 0 and go > 0 and nana > 0: ret = 1 else: ret = 0 for i in [3, 5, 7]: ret += dfs(10*x + i) return ret print((dfs(0)))
N = int(eval(input())) cnt = 0 nums = '' def dfs(nums): global cnt if len(nums) >= 10: return k = list(nums) k = set(nums) if len(nums) >= 1: if int(nums) <= N and len(k) >= 3: cnt += 1 dfs(nums + '3') dfs(nums + '5') dfs(nums + '7') return dfs(nums) print(cnt)
27
27
485
370
N = int(eval(input())) def dfs(x): if x > N: return 0 san, go, nana = 0, 0, 0 c = x for i in range(len(str(c))): if c % 10 == 3: san += 1 elif c % 10 == 5: go += 1 elif c % 10 == 7: nana += 1 c = c // 10 if san > 0 and go > 0 and nana > 0: ret = 1 else: ret = 0 for i in [3, 5, 7]: ret += dfs(10 * x + i) return ret print((dfs(0)))
N = int(eval(input())) cnt = 0 nums = "" def dfs(nums): global cnt if len(nums) >= 10: return k = list(nums) k = set(nums) if len(nums) >= 1: if int(nums) <= N and len(k) >= 3: cnt += 1 dfs(nums + "3") dfs(nums + "5") dfs(nums + "7") return dfs(nums) print(cnt)
false
0
[ "+cnt = 0", "+nums = \"\"", "-def dfs(x):", "- if x > N:", "- return 0", "- san, go, nana = 0, 0, 0", "- c = x", "- for i in range(len(str(c))):", "- if c % 10 == 3:", "- san += 1", "- elif c % 10 == 5:", "- go += 1", "- elif c % 10 == 7:", "- nana += 1", "- c = c // 10", "- if san > 0 and go > 0 and nana > 0:", "- ret = 1", "- else:", "- ret = 0", "- for i in [3, 5, 7]:", "- ret += dfs(10 * x + i)", "- return ret", "+def dfs(nums):", "+ global cnt", "+ if len(nums) >= 10:", "+ return", "+ k = list(nums)", "+ k = set(nums)", "+ if len(nums) >= 1:", "+ if int(nums) <= N and len(k) >= 3:", "+ cnt += 1", "+ dfs(nums + \"3\")", "+ dfs(nums + \"5\")", "+ dfs(nums + \"7\")", "+ return", "-print((dfs(0)))", "+dfs(nums)", "+print(cnt)" ]
false
0.058995
0.184223
0.320238
[ "s319835919", "s930235153" ]
u002459665
p02681
python
s519722046
s303692831
23
21
9,056
9,036
Accepted
Accepted
8.7
S = eval(input()) T = eval(input()) lens = len(S) lent = len(T) ans = True if lens + 1 != lent: ans = False for i in range(lens): if S[i] != T[i]: ans = False if ans: print('Yes') else: print('No')
S = eval(input()) T = eval(input()) if S == T[:-1]: print('Yes') else: print('No')
18
7
230
85
S = eval(input()) T = eval(input()) lens = len(S) lent = len(T) ans = True if lens + 1 != lent: ans = False for i in range(lens): if S[i] != T[i]: ans = False if ans: print("Yes") else: print("No")
S = eval(input()) T = eval(input()) if S == T[:-1]: print("Yes") else: print("No")
false
61.111111
[ "-lens = len(S)", "-lent = len(T)", "-ans = True", "-if lens + 1 != lent:", "- ans = False", "-for i in range(lens):", "- if S[i] != T[i]:", "- ans = False", "-if ans:", "+if S == T[:-1]:" ]
false
0.036864
0.036361
1.013829
[ "s519722046", "s303692831" ]
u604774382
p02269
python
s908337499
s062172837
3,560
1,670
60,344
62,724
Accepted
Accepted
53.09
n = int( eval(input( )) ) dic = {} output = [] for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if not dic.get( word ): output.append( "no" ) else: output.append( "yes" ) print(( "\n".join( output ) ))
n = int( input( ) ) dic = {} for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if not dic.get( word ): print( "no" ) else: print( "yes" )
14
11
287
234
n = int(eval(input())) dic = {} output = [] for i in range(n): cmd, word = input().split(" ") if "insert" == cmd: dic[word] = True elif "find" == cmd: if not dic.get(word): output.append("no") else: output.append("yes") print(("\n".join(output)))
n = int(input()) dic = {} for i in range(n): cmd, word = input().split(" ") if "insert" == cmd: dic[word] = True elif "find" == cmd: if not dic.get(word): print("no") else: print("yes")
false
21.428571
[ "-n = int(eval(input()))", "+n = int(input())", "-output = []", "- output.append(\"no\")", "+ print(\"no\")", "- output.append(\"yes\")", "-print((\"\\n\".join(output)))", "+ print(\"yes\")" ]
false
0.105039
0.098973
1.061283
[ "s908337499", "s062172837" ]
u600402037
p03148
python
s268009743
s335739757
764
363
76,760
31,220
Accepted
Accepted
52.49
from operator import itemgetter N, K = list(map(int, input().split())) TD = [list(map(int, input().split())) for _ in range(N)] TD.sort(key=itemgetter(1), reverse=True) selected = TD[:K] dlc = sum(map(itemgetter(1), selected)) variety = set(map(itemgetter(0), selected)) used = set() overlap = [] # ใƒ€ใƒ–ใฃใฆใ„ใ‚‹ใƒใ‚ฟใฎ็พŽๅ‘ณใ—ใ•ใฎใƒชใ‚นใƒˆ for t, d in TD[:K]: if t not in used: used.add(t) else: overlap.append(d) answer = dlc + len(variety)**2 for t, d in TD[K:]: if not overlap: break if t in used: continue ov = overlap.pop() dlc = dlc - ov + d used.add(t) answer = max(answer, dlc + len(used)**2) print(answer)
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() TD = [lr() for _ in range(N)] TD.sort(key=lambda x: x[1], reverse=True) used = set() overlap = [] for t, d in TD[:K]: if t in used: overlap.append(d) else: used.add(t) delicious = sum([x[1] for x in TD[:K]]) answer = delicious + len(used) ** 2 for i in range(K, N): if not overlap: break if TD[i][0] in used: continue delicious += (TD[i][1] - overlap.pop()) used.add(TD[i][0]) if answer < delicious + len(used)**2: answer = delicious + len(used)**2 print(answer) # 30
30
31
684
701
from operator import itemgetter N, K = list(map(int, input().split())) TD = [list(map(int, input().split())) for _ in range(N)] TD.sort(key=itemgetter(1), reverse=True) selected = TD[:K] dlc = sum(map(itemgetter(1), selected)) variety = set(map(itemgetter(0), selected)) used = set() overlap = [] # ใƒ€ใƒ–ใฃใฆใ„ใ‚‹ใƒใ‚ฟใฎ็พŽๅ‘ณใ—ใ•ใฎใƒชใ‚นใƒˆ for t, d in TD[:K]: if t not in used: used.add(t) else: overlap.append(d) answer = dlc + len(variety) ** 2 for t, d in TD[K:]: if not overlap: break if t in used: continue ov = overlap.pop() dlc = dlc - ov + d used.add(t) answer = max(answer, dlc + len(used) ** 2) print(answer)
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() TD = [lr() for _ in range(N)] TD.sort(key=lambda x: x[1], reverse=True) used = set() overlap = [] for t, d in TD[:K]: if t in used: overlap.append(d) else: used.add(t) delicious = sum([x[1] for x in TD[:K]]) answer = delicious + len(used) ** 2 for i in range(K, N): if not overlap: break if TD[i][0] in used: continue delicious += TD[i][1] - overlap.pop() used.add(TD[i][0]) if answer < delicious + len(used) ** 2: answer = delicious + len(used) ** 2 print(answer) # 30
false
3.225806
[ "-from operator import itemgetter", "+import sys", "-N, K = list(map(int, input().split()))", "-TD = [list(map(int, input().split())) for _ in range(N)]", "-TD.sort(key=itemgetter(1), reverse=True)", "-selected = TD[:K]", "-dlc = sum(map(itemgetter(1), selected))", "-variety = set(map(itemgetter(0), selected))", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+N, K = lr()", "+TD = [lr() for _ in range(N)]", "+TD.sort(key=lambda x: x[1], reverse=True)", "-overlap = [] # ใƒ€ใƒ–ใฃใฆใ„ใ‚‹ใƒใ‚ฟใฎ็พŽๅ‘ณใ—ใ•ใฎใƒชใ‚นใƒˆ", "+overlap = []", "- if t not in used:", "+ if t in used:", "+ overlap.append(d)", "+ else:", "- else:", "- overlap.append(d)", "-answer = dlc + len(variety) ** 2", "-for t, d in TD[K:]:", "+delicious = sum([x[1] for x in TD[:K]])", "+answer = delicious + len(used) ** 2", "+for i in range(K, N):", "- if t in used:", "+ if TD[i][0] in used:", "- ov = overlap.pop()", "- dlc = dlc - ov + d", "- used.add(t)", "- answer = max(answer, dlc + len(used) ** 2)", "+ delicious += TD[i][1] - overlap.pop()", "+ used.add(TD[i][0])", "+ if answer < delicious + len(used) ** 2:", "+ answer = delicious + len(used) ** 2", "+# 30" ]
false
0.042552
0.042721
0.996028
[ "s268009743", "s335739757" ]
u700805562
p02990
python
s974054813
s748429983
1,031
23
3,316
3,572
Accepted
Accepted
97.77
def nCr(n, r, mod): x, y = 1, 1 for r_ in range(1, r+1): x = x*(n+1-r_)%mod y = y*r_%mod return x*pow(y, mod-2, mod)%mod n, k = list(map(int, input().split())) mod = 10**9+7 for i in range(1, k+1): print((nCr(n-k+1, i, mod)*nCr(k-1, i-1, mod)%mod))
def cmb(n, r, mod): if (r < 0 or r > n): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 num = 2*(10**3) # ๅˆถ็ด„ใซๅˆใ‚ใ›ใ‚ˆใ† g1, g2, inverse = [1, 1] , [1, 1], [0, 1] for i in range(2, num + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) n, k = list(map(int, input().split())) for i in range(1, k+1): print((cmb(n-k+1, i, mod) * cmb(k-1, i-1, mod) % mod))
10
18
278
510
def nCr(n, r, mod): x, y = 1, 1 for r_ in range(1, r + 1): x = x * (n + 1 - r_) % mod y = y * r_ % mod return x * pow(y, mod - 2, mod) % mod n, k = list(map(int, input().split())) mod = 10**9 + 7 for i in range(1, k + 1): print((nCr(n - k + 1, i, mod) * nCr(k - 1, i - 1, mod) % mod))
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 num = 2 * (10**3) # ๅˆถ็ด„ใซๅˆใ‚ใ›ใ‚ˆใ† g1, g2, inverse = [1, 1], [1, 1], [0, 1] for i in range(2, num + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) n, k = list(map(int, input().split())) for i in range(1, k + 1): print((cmb(n - k + 1, i, mod) * cmb(k - 1, i - 1, mod) % mod))
false
44.444444
[ "-def nCr(n, r, mod):", "- x, y = 1, 1", "- for r_ in range(1, r + 1):", "- x = x * (n + 1 - r_) % mod", "- y = y * r_ % mod", "- return x * pow(y, mod - 2, mod) % mod", "+def cmb(n, r, mod):", "+ if r < 0 or r > n:", "+ return 0", "+ r = min(r, n - r)", "+ return g1[n] * g2[r] * g2[n - r] % mod", "+mod = 10**9 + 7", "+num = 2 * (10**3) # ๅˆถ็ด„ใซๅˆใ‚ใ›ใ‚ˆใ†", "+g1, g2, inverse = [1, 1], [1, 1], [0, 1]", "+for i in range(2, num + 1):", "+ g1.append((g1[-1] * i) % mod)", "+ inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "+ g2.append((g2[-1] * inverse[-1]) % mod)", "-mod = 10**9 + 7", "- print((nCr(n - k + 1, i, mod) * nCr(k - 1, i - 1, mod) % mod))", "+ print((cmb(n - k + 1, i, mod) * cmb(k - 1, i - 1, mod) % mod))" ]
false
0.130371
0.03897
3.345421
[ "s974054813", "s748429983" ]
u821588465
p03854
python
s083151304
s982598326
78
39
3,956
12,824
Accepted
Accepted
50
S = eval(input()) dp = [0]*(len(S) + 1) dp[0] = 1 words=['dream', 'dreamer', 'erase', 'eraser'] done = 'NO' for i in range(len(S)): if dp[i] == 0: continue for w in words: if S[i:i + len(w)] == w: dp[i + len(w)] = 1 if dp[len(S)] ==1: done = 'YES' break print(done)
from re import * if match("^(dream|dreamer|erase|eraser)+$", eval(input())): print('YES') else: print('NO')
19
7
357
122
S = eval(input()) dp = [0] * (len(S) + 1) dp[0] = 1 words = ["dream", "dreamer", "erase", "eraser"] done = "NO" for i in range(len(S)): if dp[i] == 0: continue for w in words: if S[i : i + len(w)] == w: dp[i + len(w)] = 1 if dp[len(S)] == 1: done = "YES" break print(done)
from re import * if match("^(dream|dreamer|erase|eraser)+$", eval(input())): print("YES") else: print("NO")
false
63.157895
[ "-S = eval(input())", "-dp = [0] * (len(S) + 1)", "-dp[0] = 1", "-words = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]", "-done = \"NO\"", "-for i in range(len(S)):", "- if dp[i] == 0:", "- continue", "- for w in words:", "- if S[i : i + len(w)] == w:", "- dp[i + len(w)] = 1", "- if dp[len(S)] == 1:", "- done = \"YES\"", "- break", "-print(done)", "+from re import *", "+", "+if match(\"^(dream|dreamer|erase|eraser)+$\", eval(input())):", "+ print(\"YES\")", "+else:", "+ print(\"NO\")" ]
false
0.04512
0.059956
0.752549
[ "s083151304", "s982598326" ]
u349856770
p02657
python
s107335291
s406332856
34
27
9,160
9,152
Accepted
Accepted
20.59
# 169A # A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆใ€‚ # ๏ผ‘๏ผŽๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ a, b = list(map(int, input().split())) # print(a, b) # ๏ผ’๏ผŽๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๆ›ธ้กž๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ answer = a * b # ๏ผ“๏ผŽ่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ print(answer)
A, B = list(map(int, input().split())) answer = A * B print(answer)
13
4
193
65
# 169A # A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆใ€‚ # ๏ผ‘๏ผŽๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ a, b = list(map(int, input().split())) # print(a, b) # ๏ผ’๏ผŽๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๆ›ธ้กž๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ answer = a * b # ๏ผ“๏ผŽ่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ print(answer)
A, B = list(map(int, input().split())) answer = A * B print(answer)
false
69.230769
[ "-# 169A", "-# A ร— B ใ‚’ๆ•ดๆ•ฐใจใ—ใฆๅ‡บๅŠ›ใ›ใ‚ˆใ€‚", "-# ๏ผ‘๏ผŽๅ…ฅๅŠ›ใ‚’ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงๆ‰ฑใˆใ‚‹ใ‚ˆใ†ใซๅ—ใ‘ๅ–ใ‚‹ใ“ใจ", "-a, b = list(map(int, input().split()))", "-# print(a, b)", "-# ๏ผ’๏ผŽๅ—ใ‘ๅ–ใฃใŸๅ…ฅๅŠ›ๅ€คใ‚’ไฝฟใฃใฆใ€้ฉๅˆ‡ใซๆ›ธ้กž๏ผˆ่จˆ็ฎ—๏ผ‰ใ™ใ‚‹ใ“ใจ", "-answer = a * b", "-# ๏ผ“๏ผŽ่จˆ็ฎ—ใ—ใŸ็ตๆžœใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ“ใจ", "+A, B = list(map(int, input().split()))", "+answer = A * B" ]
false
0.042346
0.007349
5.762489
[ "s107335291", "s406332856" ]
u298297089
p03048
python
s552397105
s568665620
1,727
19
2,940
3,060
Accepted
Accepted
98.9
*lst,N = list(map(int, input().split())) lst.sort(reverse=True) #print(lst) count = 0 for i in range(N // lst[0] + 1): for j in range((N - i * lst[0]) // lst[1] + 1): if (N - i * lst[0] - j * lst[1]) % lst[2] == 0: count += 1 print(count)
r,g,b,n = list(map(int,input().split())) a = [0]*(n+1) a[0] = 1 for j in range(0,n+1-r,r): a[j+r]=1 for j in range(n+1-b): a[j+b]+=a[j] for j in range(n+1-g): a[j+g]+=a[j] #print(a) print((a[n]))
10
11
267
214
*lst, N = list(map(int, input().split())) lst.sort(reverse=True) # print(lst) count = 0 for i in range(N // lst[0] + 1): for j in range((N - i * lst[0]) // lst[1] + 1): if (N - i * lst[0] - j * lst[1]) % lst[2] == 0: count += 1 print(count)
r, g, b, n = list(map(int, input().split())) a = [0] * (n + 1) a[0] = 1 for j in range(0, n + 1 - r, r): a[j + r] = 1 for j in range(n + 1 - b): a[j + b] += a[j] for j in range(n + 1 - g): a[j + g] += a[j] # print(a) print((a[n]))
false
9.090909
[ "-*lst, N = list(map(int, input().split()))", "-lst.sort(reverse=True)", "-# print(lst)", "-count = 0", "-for i in range(N // lst[0] + 1):", "- for j in range((N - i * lst[0]) // lst[1] + 1):", "- if (N - i * lst[0] - j * lst[1]) % lst[2] == 0:", "- count += 1", "-print(count)", "+r, g, b, n = list(map(int, input().split()))", "+a = [0] * (n + 1)", "+a[0] = 1", "+for j in range(0, n + 1 - r, r):", "+ a[j + r] = 1", "+for j in range(n + 1 - b):", "+ a[j + b] += a[j]", "+for j in range(n + 1 - g):", "+ a[j + g] += a[j]", "+ # print(a)", "+print((a[n]))" ]
false
0.073128
0.071796
1.018561
[ "s552397105", "s568665620" ]
u762199573
p02952
python
s689133013
s156775466
53
48
6,720
3,864
Accepted
Accepted
9.43
n = int(eval(input())) odd = [i for i in range(1, n+1) if len(str(i)) % 2 != 0] print((len(odd)))
n = int(eval(input())) print((sum([1 for i in range(1, n+1) if len(str(i)) % 2 == 1])))
3
2
91
80
n = int(eval(input())) odd = [i for i in range(1, n + 1) if len(str(i)) % 2 != 0] print((len(odd)))
n = int(eval(input())) print((sum([1 for i in range(1, n + 1) if len(str(i)) % 2 == 1])))
false
33.333333
[ "-odd = [i for i in range(1, n + 1) if len(str(i)) % 2 != 0]", "-print((len(odd)))", "+print((sum([1 for i in range(1, n + 1) if len(str(i)) % 2 == 1])))" ]
false
0.054353
0.124819
0.435452
[ "s689133013", "s156775466" ]
u761320129
p02574
python
s677176129
s805410299
1,320
327
132,608
188,940
Accepted
Accepted
75.23
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) def solve(): g = 0 for a in A: g = gcd(g,a) if g > 1: print('not coprime') exit() MAXA = 10**6 B = [0] * (MAXA+1) for a in A: if a==1: continue if B[a]: print('setwise coprime') exit() B[a] = 1 for n in range(2,MAXA+1): c = 0 for m in range(n,MAXA+1,n): c += B[m] if c > 1: print('setwise coprime') exit() print('pairwise coprime') solve()
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) g = 0 for a in A: g = gcd(g,a) if g > 1: print('not coprime') exit() MAXA = 10**6 B = [0] * (MAXA+1) for a in A: if a==1: continue if B[a]: print('setwise coprime') exit() B[a] = 1 for n in range(2,MAXA+1): c = 0 for m in range(n,MAXA+1,n): c += B[m] if c > 1: print('setwise coprime') exit() print('pairwise coprime')
31
29
622
511
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) def solve(): g = 0 for a in A: g = gcd(g, a) if g > 1: print("not coprime") exit() MAXA = 10**6 B = [0] * (MAXA + 1) for a in A: if a == 1: continue if B[a]: print("setwise coprime") exit() B[a] = 1 for n in range(2, MAXA + 1): c = 0 for m in range(n, MAXA + 1, n): c += B[m] if c > 1: print("setwise coprime") exit() print("pairwise coprime") solve()
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) g = 0 for a in A: g = gcd(g, a) if g > 1: print("not coprime") exit() MAXA = 10**6 B = [0] * (MAXA + 1) for a in A: if a == 1: continue if B[a]: print("setwise coprime") exit() B[a] = 1 for n in range(2, MAXA + 1): c = 0 for m in range(n, MAXA + 1, n): c += B[m] if c > 1: print("setwise coprime") exit() print("pairwise coprime")
false
6.451613
[ "-", "-", "-def solve():", "- g = 0", "- for a in A:", "- g = gcd(g, a)", "- if g > 1:", "- print(\"not coprime\")", "+g = 0", "+for a in A:", "+ g = gcd(g, a)", "+if g > 1:", "+ print(\"not coprime\")", "+ exit()", "+MAXA = 10**6", "+B = [0] * (MAXA + 1)", "+for a in A:", "+ if a == 1:", "+ continue", "+ if B[a]:", "+ print(\"setwise coprime\")", "- MAXA = 10**6", "- B = [0] * (MAXA + 1)", "- for a in A:", "- if a == 1:", "- continue", "- if B[a]:", "+ B[a] = 1", "+for n in range(2, MAXA + 1):", "+ c = 0", "+ for m in range(n, MAXA + 1, n):", "+ c += B[m]", "+ if c > 1:", "- B[a] = 1", "- for n in range(2, MAXA + 1):", "- c = 0", "- for m in range(n, MAXA + 1, n):", "- c += B[m]", "- if c > 1:", "- print(\"setwise coprime\")", "- exit()", "- print(\"pairwise coprime\")", "-", "-", "-solve()", "+print(\"pairwise coprime\")" ]
false
1.572338
1.508131
1.042574
[ "s677176129", "s805410299" ]
u113971909
p03494
python
s885734493
s585094884
20
18
4,212
3,060
Accepted
Accepted
10
N=int(eval(input())) A=list(map(int,input().split())) A.sort() for i in range(N): A[i]=list(format(A[i],'320b')) A=list(map(list,list(zip(*A)))) B=['0']*N ret=0 A.reverse() for i in A: if i==B: ret+=1 else: break print(ret)
def hd2(n): ans = 0 while n % 2 == 0: n /= 2 ans += 1 return ans n = int(eval(input())) a = list(map(int, input().split())) ans = min(list(map(hd2, a))) print(ans)
15
10
239
161
N = int(eval(input())) A = list(map(int, input().split())) A.sort() for i in range(N): A[i] = list(format(A[i], "320b")) A = list(map(list, list(zip(*A)))) B = ["0"] * N ret = 0 A.reverse() for i in A: if i == B: ret += 1 else: break print(ret)
def hd2(n): ans = 0 while n % 2 == 0: n /= 2 ans += 1 return ans n = int(eval(input())) a = list(map(int, input().split())) ans = min(list(map(hd2, a))) print(ans)
false
33.333333
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-A.sort()", "-for i in range(N):", "- A[i] = list(format(A[i], \"320b\"))", "-A = list(map(list, list(zip(*A))))", "-B = [\"0\"] * N", "-ret = 0", "-A.reverse()", "-for i in A:", "- if i == B:", "- ret += 1", "- else:", "- break", "-print(ret)", "+def hd2(n):", "+ ans = 0", "+ while n % 2 == 0:", "+ n /= 2", "+ ans += 1", "+ return ans", "+", "+", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+ans = min(list(map(hd2, a)))", "+print(ans)" ]
false
0.045304
0.043862
1.032885
[ "s885734493", "s585094884" ]
u073852194
p02559
python
s296359139
s435451703
609
539
166,896
143,840
Accepted
Accepted
11.49
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def build(self, arr): #assert len(arr) <= n for i, a in enumerate(arr): self.data[i] = a for i in range(1, self.n + 1): if i + (i & -i) <= self.n: self.data[i + (i & -i) - 1] += self.data[i - 1] def add(self, p, x): #assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r: s += self.data[r - 1] r -= r & -r return s def range_sum(self, l, r): #assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) A = tuple(map(int, input().split())) ft = FenwickTree(N) ft.build(A) res = [] for _ in range(Q): q, x, y = list(map(int, input().split())) if q: res.append(str(ft.range_sum(x, y))) else: ft.add(x, y) print(('\n'.join(res)))
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def build(self, arr): #assert len(arr) <= n for i, a in enumerate(arr): self.data[i] = a for i in range(1, self.n + 1): if i + (i & -i) <= self.n: self.data[i + (i & -i) - 1] += self.data[i - 1] def add(self, p, x): #assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r: s += self.data[r - 1] r -= r & -r return s def range_sum(self, l, r): #assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) A = list(map(int, input().split())) ft = FenwickTree(N) ft.build(A) res = [] for _ in range(Q): q, x, y = list(map(int, input().split())) if q: res.append(str(ft.range_sum(x, y))) else: ft.add(x, y) print(('\n'.join(res)))
49
49
1,131
1,124
class FenwickTree: def __init__(self, n): self.n = n self.data = [0] * n def build(self, arr): # assert len(arr) <= n for i, a in enumerate(arr): self.data[i] = a for i in range(1, self.n + 1): if i + (i & -i) <= self.n: self.data[i + (i & -i) - 1] += self.data[i - 1] def add(self, p, x): # assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r: s += self.data[r - 1] r -= r & -r return s def range_sum(self, l, r): # assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) A = tuple(map(int, input().split())) ft = FenwickTree(N) ft.build(A) res = [] for _ in range(Q): q, x, y = list(map(int, input().split())) if q: res.append(str(ft.range_sum(x, y))) else: ft.add(x, y) print(("\n".join(res)))
class FenwickTree: def __init__(self, n): self.n = n self.data = [0] * n def build(self, arr): # assert len(arr) <= n for i, a in enumerate(arr): self.data[i] = a for i in range(1, self.n + 1): if i + (i & -i) <= self.n: self.data[i + (i & -i) - 1] += self.data[i - 1] def add(self, p, x): # assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r: s += self.data[r - 1] r -= r & -r return s def range_sum(self, l, r): # assert 0 <= l <= r <= self.n return self.sum(r) - self.sum(l) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) A = list(map(int, input().split())) ft = FenwickTree(N) ft.build(A) res = [] for _ in range(Q): q, x, y = list(map(int, input().split())) if q: res.append(str(ft.range_sum(x, y))) else: ft.add(x, y) print(("\n".join(res)))
false
0
[ "-A = tuple(map(int, input().split()))", "+A = list(map(int, input().split()))" ]
false
0.044689
0.045095
0.990984
[ "s296359139", "s435451703" ]
u077291787
p02901
python
s850388927
s161100677
971
312
3,188
47,448
Accepted
Accepted
67.87
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 1 << N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
# ABC142E - Get Everything def main(): N, M = list(map(int, input().split())) p = 1 << N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
21
18
529
487
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 1 << N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
# ABC142E - Get Everything def main(): N, M = list(map(int, input().split())) p = 1 << N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
false
14.285714
[ "-import sys", "-", "-input = sys.stdin.readline", "-", "-" ]
false
0.085491
0.044335
1.928313
[ "s850388927", "s161100677" ]
u691018832
p02913
python
s872905934
s101533346
822
751
52,700
50,524
Accepted
Accepted
8.64
def Z_algo(S): n = len(S) LCP = [0] * n c = 0 # ๆœ€ใ‚‚ๆœซๅฐพๅดใพใงLCPใ‚’ๆฑ‚ใ‚ใŸใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น for i in range(1, n): # i็•ช็›ฎใ‹ใ‚‰ใฎLCPใŒไปฅๅ‰่จˆ็ฎ—ใ—ใŸcใ‹ใ‚‰ใฎLCPใซๅซใพใ‚Œใฆใ„ใ‚‹ๅ ดๅˆ if i + LCP[i - c] < c + LCP[c]: LCP[i] = LCP[i - c] else: j = max(0, c + LCP[c] - i) while i + j < n and S[j] == S[i + j]: j += 1 LCP[i] = j c = i LCP[0] = n return LCP n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n): lcp = Z_algo(s[i:]) for j, p in enumerate(lcp): tmp = min(j, p) ans = max(ans, tmp) print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) def Z_algo(S): n = len(S) LCP = [0] * n c = 0 # ๆœ€ใ‚‚ๆœซๅฐพๅดใพใงLCPใ‚’ๆฑ‚ใ‚ใŸใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น for i in range(1, n): # i็•ช็›ฎใ‹ใ‚‰ใฎLCPใŒไปฅๅ‰่จˆ็ฎ—ใ—ใŸcใ‹ใ‚‰ใฎLCPใซๅซใพใ‚Œใฆใ„ใ‚‹ๅ ดๅˆ if i + LCP[i - c] < c + LCP[c]: LCP[i] = LCP[i - c] else: j = max(0, c + LCP[c] - i) while i + j < n and S[j] == S[i + j]: j += 1 LCP[i] = j c = i LCP[0] = n return LCP n = int(readline()) s = read().rstrip().decode() ans = 0 for i in range(n): for j, m in enumerate(Z_algo(s[i:])): ans = max(ans, min(j, m)) print(ans)
27
32
623
765
def Z_algo(S): n = len(S) LCP = [0] * n c = 0 # ๆœ€ใ‚‚ๆœซๅฐพๅดใพใงLCPใ‚’ๆฑ‚ใ‚ใŸใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น for i in range(1, n): # i็•ช็›ฎใ‹ใ‚‰ใฎLCPใŒไปฅๅ‰่จˆ็ฎ—ใ—ใŸcใ‹ใ‚‰ใฎLCPใซๅซใพใ‚Œใฆใ„ใ‚‹ๅ ดๅˆ if i + LCP[i - c] < c + LCP[c]: LCP[i] = LCP[i - c] else: j = max(0, c + LCP[c] - i) while i + j < n and S[j] == S[i + j]: j += 1 LCP[i] = j c = i LCP[0] = n return LCP n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n): lcp = Z_algo(s[i:]) for j, p in enumerate(lcp): tmp = min(j, p) ans = max(ans, tmp) print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) def Z_algo(S): n = len(S) LCP = [0] * n c = 0 # ๆœ€ใ‚‚ๆœซๅฐพๅดใพใงLCPใ‚’ๆฑ‚ใ‚ใŸใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น for i in range(1, n): # i็•ช็›ฎใ‹ใ‚‰ใฎLCPใŒไปฅๅ‰่จˆ็ฎ—ใ—ใŸcใ‹ใ‚‰ใฎLCPใซๅซใพใ‚Œใฆใ„ใ‚‹ๅ ดๅˆ if i + LCP[i - c] < c + LCP[c]: LCP[i] = LCP[i - c] else: j = max(0, c + LCP[c] - i) while i + j < n and S[j] == S[i + j]: j += 1 LCP[i] = j c = i LCP[0] = n return LCP n = int(readline()) s = read().rstrip().decode() ans = 0 for i in range(n): for j, m in enumerate(Z_algo(s[i:])): ans = max(ans, min(j, m)) print(ans)
false
15.625
[ "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+sys.setrecursionlimit(10**7)", "+", "+", "-n = int(eval(input()))", "-s = eval(input())", "+n = int(readline())", "+s = read().rstrip().decode()", "- lcp = Z_algo(s[i:])", "- for j, p in enumerate(lcp):", "- tmp = min(j, p)", "- ans = max(ans, tmp)", "+ for j, m in enumerate(Z_algo(s[i:])):", "+ ans = max(ans, min(j, m))" ]
false
0.048164
0.069269
0.695319
[ "s872905934", "s101533346" ]
u607155447
p02755
python
s609227581
s958993826
88
67
62,320
62,000
Accepted
Accepted
23.86
import math A, B = list(map(int, input().split())) for i in range(1,1010): a, b = i*0.08, i*0.1 if math.floor(a) == A and math.floor(b) == B: print(i) break if i == 1009: print((-1))
import math A, B = list(map(int, input().split())) b1 = B*10 b2 = b1 + 10 for i in range(b1, b2): if math.floor(i*0.08) == A: print(i) break if i == b2-1: print((-1))
10
12
220
203
import math A, B = list(map(int, input().split())) for i in range(1, 1010): a, b = i * 0.08, i * 0.1 if math.floor(a) == A and math.floor(b) == B: print(i) break if i == 1009: print((-1))
import math A, B = list(map(int, input().split())) b1 = B * 10 b2 = b1 + 10 for i in range(b1, b2): if math.floor(i * 0.08) == A: print(i) break if i == b2 - 1: print((-1))
false
16.666667
[ "-for i in range(1, 1010):", "- a, b = i * 0.08, i * 0.1", "- if math.floor(a) == A and math.floor(b) == B:", "+b1 = B * 10", "+b2 = b1 + 10", "+for i in range(b1, b2):", "+ if math.floor(i * 0.08) == A:", "- if i == 1009:", "+ if i == b2 - 1:" ]
false
0.036798
0.046489
0.791535
[ "s609227581", "s958993826" ]
u263830634
p03356
python
s706219609
s602019046
1,098
803
95,852
13,812
Accepted
Accepted
26.87
N, M = list(map(int, input().split())) P = list(map(int, input().split())) class UnionFind(object): def __init__(self, N): self.parent = [-1] * N #parent[i] ใฏ(i+1)็•ช็›ฎใฎ่ฆ็ด ใŒๅซใพใ‚Œใ‚‹่ฆ็ด ๆ•ฐใฎ(-1)ๅ€ #่ฆ็ด ใŒ่ฒ -->ใใฎๆ•ฐใ‚’่ฆชใจใ™ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ™ใ‚‹่ฆ็ด ใฎๆ•ฐร—(-1) #่ฆ็ด ใŒๆญฃ-->่ฆชใฎindex #AใŒใฉใฎใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ใ‹ใ‚’่ชฟในใ‚‹ def root(self, A): if self.parent[A-1] < 0: #่ฒ ใฎๆ•ฐ-->ใใฎๆ•ฐใฏ่ฆช return A self.parent[A-1] = self.root(self.parent[A-1]) #่ฒ ใงใฏ็„กใ„ๆ™‚ใ€่ฆชใฎๅ ดๆ‰€ใŒๅ…ฅใฃใฆใ„ใ‚‹ใ‹ใ‚‰ใ€่ฆชใŒๅฑžใ—ใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใ‚’ใ€่‡ชๅˆ†่‡ช่บซใซๅ…ฅใ‚Œใ‚‹(ไธ€ๅบฆ็ขบ่ชใ—ใŸใจใ“ใ‚ใฏ็›ดๆŽฅ่ฆชใ‚’่ฆ‹ใ‚Œใ‚‹ใ‚ˆใ†ใซใ™ใ‚‹) return self.parent[A-1] #่ฆชใฎไฝ็ฝฎใ‚’่ฟ”ใ™ #AใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ๆ•ฐใ‚’่ฟ”ใ™ def size(self, A): return -1 * self.parent[self.root(A)-1] #AใจBใ‚’ใใฃไป˜ใ‘ใ‚‹ def connect(self, A, B): A = self.root(A) #Aใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ B = self.root(B) #Bใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ if A == B: #่ฆชใŒๅŒใ˜ใชใ‚‰ใชใซใ‚‚ใ—ใชใ„ return False #ๅคงใใ„ๆ–น(A)ใซๅฐใ•ใ„ๆ–น(B)ใ‚’ใคใชใŽใŸใ„ if self.size(A) < self.size(B): #ๅคงๅฐ้–ขไฟ‚ใŒ้€†ใฎๆ™‚ใฏๅ…ฅใ‚Œๆ›ฟใˆใ‚‹ A, B = B, A self.parent[A-1] += self.parent[B-1] #ๅคงใใ„ๆ–นใซๅฐใ•ใ„ๆ–นใ‚’ๅŠ ใˆใ‚‹ใ€€๏ผˆ่ฒ ใฎๆ•ฐ๏ผ‹่ฒ ใฎๆ•ฐ = ๆ–ฐใ—ใ„ใ‚ฐใƒซใƒผใƒ—ใซๅซใพใ‚Œใ‚‹ๆ•ฐร—(-1)๏ผ‰ self.parent[B-1] = A #ๅŠ ใˆใ‚‰ใ‚ŒใŸ่ฆชใฎๅ€คใ‚’ใ€ๅŠ ใˆใŸๅ…ˆใฎ่ฆชใฎไฝ็ฝฎใซๆ›ธใๅค‰ใˆใ‚‹ return True def same(self, A, B): if self.root(A) == self.root(B): return True else: return False uni = UnionFind(N + 1) for _ in range(M): x, y = list(map(int, input().split())) uni.connect(x, y) ans = 0 for i in range(N): if uni.same(i + 1, P[i]): ans += 1 print (ans)
N, M = list(map(int, input().split())) P = list(map(int, input().split())) class UnionFind(object): def __init__(self, N): self.parent = [-1] * N #parent[i] ใฏ(i+1)็•ช็›ฎใฎ่ฆ็ด ใŒๅซใพใ‚Œใ‚‹่ฆ็ด ๆ•ฐใฎ(-1)ๅ€ #่ฆ็ด ใŒ่ฒ -->ใใฎๆ•ฐใ‚’่ฆชใจใ™ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ™ใ‚‹่ฆ็ด ใฎๆ•ฐร—(-1) #่ฆ็ด ใŒๆญฃ-->่ฆชใฎindex #AใŒใฉใฎใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ใ‹ใ‚’่ชฟในใ‚‹ def root(self, A): if self.parent[A-1] < 0: #่ฒ ใฎๆ•ฐ-->ใใฎๆ•ฐใฏ่ฆช return A self.parent[A-1] = self.root(self.parent[A-1]) #่ฒ ใงใฏ็„กใ„ๆ™‚ใ€่ฆชใฎๅ ดๆ‰€ใŒๅ…ฅใฃใฆใ„ใ‚‹ใ‹ใ‚‰ใ€่ฆชใŒๅฑžใ—ใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใ‚’ใ€่‡ชๅˆ†่‡ช่บซใซๅ…ฅใ‚Œใ‚‹(ไธ€ๅบฆ็ขบ่ชใ—ใŸใจใ“ใ‚ใฏ็›ดๆŽฅ่ฆชใ‚’่ฆ‹ใ‚Œใ‚‹ใ‚ˆใ†ใซใ™ใ‚‹) return self.parent[A-1] #่ฆชใฎไฝ็ฝฎใ‚’่ฟ”ใ™ #AใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ๆ•ฐใ‚’่ฟ”ใ™ def size(self, A): return -1 * self.parent[self.root(A)-1] #AใจBใ‚’ใใฃไป˜ใ‘ใ‚‹ def connect(self, A, B): A = self.root(A) #Aใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ B = self.root(B) #Bใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ if A == B: #่ฆชใŒๅŒใ˜ใชใ‚‰ใชใซใ‚‚ใ—ใชใ„ return False #ๅคงใใ„ๆ–น(A)ใซๅฐใ•ใ„ๆ–น(B)ใ‚’ใคใชใŽใŸใ„ if self.size(A) < self.size(B): #ๅคงๅฐ้–ขไฟ‚ใŒ้€†ใฎๆ™‚ใฏๅ…ฅใ‚Œๆ›ฟใˆใ‚‹ A, B = B, A self.parent[A-1] += self.parent[B-1] #ๅคงใใ„ๆ–นใซๅฐใ•ใ„ๆ–นใ‚’ๅŠ ใˆใ‚‹ใ€€๏ผˆ่ฒ ใฎๆ•ฐ๏ผ‹่ฒ ใฎๆ•ฐ = ๆ–ฐใ—ใ„ใ‚ฐใƒซใƒผใƒ—ใซๅซใพใ‚Œใ‚‹ๆ•ฐร—(-1)๏ผ‰ self.parent[B-1] = A #ๅŠ ใˆใ‚‰ใ‚ŒใŸ่ฆชใฎๅ€คใ‚’ใ€ๅŠ ใˆใŸๅ…ˆใฎ่ฆชใฎไฝ็ฝฎใซๆ›ธใๅค‰ใˆใ‚‹ return True def same(self, A, B): if self.root(A) == self.root(B): return True else: return False uni = UnionFind(N + 1) for _ in range(M): x, y = list(map(int, input().split())) uni.connect(x, y) count = 0 for index, p in enumerate(P): if uni.same(p, index + 1): count += 1 print (count)
54
55
1,498
1,506
N, M = list(map(int, input().split())) P = list(map(int, input().split())) class UnionFind(object): def __init__(self, N): self.parent = [-1] * N # parent[i] ใฏ(i+1)็•ช็›ฎใฎ่ฆ็ด ใŒๅซใพใ‚Œใ‚‹่ฆ็ด ๆ•ฐใฎ(-1)ๅ€ # ่ฆ็ด ใŒ่ฒ -->ใใฎๆ•ฐใ‚’่ฆชใจใ™ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ™ใ‚‹่ฆ็ด ใฎๆ•ฐร—(-1) # ่ฆ็ด ใŒๆญฃ-->่ฆชใฎindex # AใŒใฉใฎใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ใ‹ใ‚’่ชฟในใ‚‹ def root(self, A): if self.parent[A - 1] < 0: # ่ฒ ใฎๆ•ฐ-->ใใฎๆ•ฐใฏ่ฆช return A self.parent[A - 1] = self.root( self.parent[A - 1] ) # ่ฒ ใงใฏ็„กใ„ๆ™‚ใ€่ฆชใฎๅ ดๆ‰€ใŒๅ…ฅใฃใฆใ„ใ‚‹ใ‹ใ‚‰ใ€่ฆชใŒๅฑžใ—ใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใ‚’ใ€่‡ชๅˆ†่‡ช่บซใซๅ…ฅใ‚Œใ‚‹(ไธ€ๅบฆ็ขบ่ชใ—ใŸใจใ“ใ‚ใฏ็›ดๆŽฅ่ฆชใ‚’่ฆ‹ใ‚Œใ‚‹ใ‚ˆใ†ใซใ™ใ‚‹) return self.parent[A - 1] # ่ฆชใฎไฝ็ฝฎใ‚’่ฟ”ใ™ # AใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ๆ•ฐใ‚’่ฟ”ใ™ def size(self, A): return -1 * self.parent[self.root(A) - 1] # AใจBใ‚’ใใฃไป˜ใ‘ใ‚‹ def connect(self, A, B): A = self.root(A) # Aใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ B = self.root(B) # Bใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ if A == B: # ่ฆชใŒๅŒใ˜ใชใ‚‰ใชใซใ‚‚ใ—ใชใ„ return False # ๅคงใใ„ๆ–น(A)ใซๅฐใ•ใ„ๆ–น(B)ใ‚’ใคใชใŽใŸใ„ if self.size(A) < self.size(B): # ๅคงๅฐ้–ขไฟ‚ใŒ้€†ใฎๆ™‚ใฏๅ…ฅใ‚Œๆ›ฟใˆใ‚‹ A, B = B, A self.parent[A - 1] += self.parent[ B - 1 ] # ๅคงใใ„ๆ–นใซๅฐใ•ใ„ๆ–นใ‚’ๅŠ ใˆใ‚‹ใ€€๏ผˆ่ฒ ใฎๆ•ฐ๏ผ‹่ฒ ใฎๆ•ฐ = ๆ–ฐใ—ใ„ใ‚ฐใƒซใƒผใƒ—ใซๅซใพใ‚Œใ‚‹ๆ•ฐร—(-1)๏ผ‰ self.parent[B - 1] = A # ๅŠ ใˆใ‚‰ใ‚ŒใŸ่ฆชใฎๅ€คใ‚’ใ€ๅŠ ใˆใŸๅ…ˆใฎ่ฆชใฎไฝ็ฝฎใซๆ›ธใๅค‰ใˆใ‚‹ return True def same(self, A, B): if self.root(A) == self.root(B): return True else: return False uni = UnionFind(N + 1) for _ in range(M): x, y = list(map(int, input().split())) uni.connect(x, y) ans = 0 for i in range(N): if uni.same(i + 1, P[i]): ans += 1 print(ans)
N, M = list(map(int, input().split())) P = list(map(int, input().split())) class UnionFind(object): def __init__(self, N): self.parent = [-1] * N # parent[i] ใฏ(i+1)็•ช็›ฎใฎ่ฆ็ด ใŒๅซใพใ‚Œใ‚‹่ฆ็ด ๆ•ฐใฎ(-1)ๅ€ # ่ฆ็ด ใŒ่ฒ -->ใใฎๆ•ฐใ‚’่ฆชใจใ™ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ™ใ‚‹่ฆ็ด ใฎๆ•ฐร—(-1) # ่ฆ็ด ใŒๆญฃ-->่ฆชใฎindex # AใŒใฉใฎใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ใ‹ใ‚’่ชฟในใ‚‹ def root(self, A): if self.parent[A - 1] < 0: # ่ฒ ใฎๆ•ฐ-->ใใฎๆ•ฐใฏ่ฆช return A self.parent[A - 1] = self.root( self.parent[A - 1] ) # ่ฒ ใงใฏ็„กใ„ๆ™‚ใ€่ฆชใฎๅ ดๆ‰€ใŒๅ…ฅใฃใฆใ„ใ‚‹ใ‹ใ‚‰ใ€่ฆชใŒๅฑžใ—ใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใ‚’ใ€่‡ชๅˆ†่‡ช่บซใซๅ…ฅใ‚Œใ‚‹(ไธ€ๅบฆ็ขบ่ชใ—ใŸใจใ“ใ‚ใฏ็›ดๆŽฅ่ฆชใ‚’่ฆ‹ใ‚Œใ‚‹ใ‚ˆใ†ใซใ™ใ‚‹) return self.parent[A - 1] # ่ฆชใฎไฝ็ฝฎใ‚’่ฟ”ใ™ # AใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‚ฐใƒซใƒผใƒ—ใซๅฑžใ—ใฆใ„ใ‚‹ๆ•ฐใ‚’่ฟ”ใ™ def size(self, A): return -1 * self.parent[self.root(A) - 1] # AใจBใ‚’ใใฃไป˜ใ‘ใ‚‹ def connect(self, A, B): A = self.root(A) # Aใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ B = self.root(B) # Bใ‚’ๅซใ‚€ใ‚ฐใƒซใƒผใƒ—ใฎ่ฆชใ‚’่ฟ”ใ™ if A == B: # ่ฆชใŒๅŒใ˜ใชใ‚‰ใชใซใ‚‚ใ—ใชใ„ return False # ๅคงใใ„ๆ–น(A)ใซๅฐใ•ใ„ๆ–น(B)ใ‚’ใคใชใŽใŸใ„ if self.size(A) < self.size(B): # ๅคงๅฐ้–ขไฟ‚ใŒ้€†ใฎๆ™‚ใฏๅ…ฅใ‚Œๆ›ฟใˆใ‚‹ A, B = B, A self.parent[A - 1] += self.parent[ B - 1 ] # ๅคงใใ„ๆ–นใซๅฐใ•ใ„ๆ–นใ‚’ๅŠ ใˆใ‚‹ใ€€๏ผˆ่ฒ ใฎๆ•ฐ๏ผ‹่ฒ ใฎๆ•ฐ = ๆ–ฐใ—ใ„ใ‚ฐใƒซใƒผใƒ—ใซๅซใพใ‚Œใ‚‹ๆ•ฐร—(-1)๏ผ‰ self.parent[B - 1] = A # ๅŠ ใˆใ‚‰ใ‚ŒใŸ่ฆชใฎๅ€คใ‚’ใ€ๅŠ ใˆใŸๅ…ˆใฎ่ฆชใฎไฝ็ฝฎใซๆ›ธใๅค‰ใˆใ‚‹ return True def same(self, A, B): if self.root(A) == self.root(B): return True else: return False uni = UnionFind(N + 1) for _ in range(M): x, y = list(map(int, input().split())) uni.connect(x, y) count = 0 for index, p in enumerate(P): if uni.same(p, index + 1): count += 1 print(count)
false
1.818182
[ "-ans = 0", "-for i in range(N):", "- if uni.same(i + 1, P[i]):", "- ans += 1", "-print(ans)", "+count = 0", "+for index, p in enumerate(P):", "+ if uni.same(p, index + 1):", "+ count += 1", "+print(count)" ]
false
0.038909
0.042787
0.909372
[ "s706219609", "s602019046" ]
u828706986
p03450
python
s969037620
s286961113
1,138
527
84,640
124,660
Accepted
Accepted
53.69
def main(): n, m = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(m): l, r, d = list(map(int, input().split())) g[l - 1].append((r - 1, d)) g[r - 1].append((l - 1, -d)) dis = [0] * n visited = [False] * n for i in range(n): if visited[i]: continue stack = list([i]) visited[i] = True while len(stack): v = stack[-1] stack.pop() for u, d in g[v]: if not visited[u]: dis[u] = dis[v] + d stack.append(u) visited[u] = True for v in range(n): for u, d in g[v]: if dis[v] + d != dis[u]: print('No') return print('Yes') if __name__ == '__main__': main()
import sys def main(): n, m = list(map(int, input().split())) g = [[] for i in range(n)] lines = sys.stdin.read().splitlines() for i in range(m): l, r, d = list(map(int, lines[i].split())) g[l - 1].append((r - 1, d)) g[r - 1].append((l - 1, -d)) dis = [0] * n visited = [False] * n for i in range(n): if visited[i]: continue stack = list([i]) visited[i] = True while len(stack): v = stack[-1] stack.pop() for u, d in g[v]: if not visited[u]: dis[u] = dis[v] + d stack.append(u) visited[u] = True for v in range(n): for u, d in g[v]: if dis[v] + d != dis[u]: print('No') return print('Yes') if __name__ == '__main__': main()
32
36
863
923
def main(): n, m = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(m): l, r, d = list(map(int, input().split())) g[l - 1].append((r - 1, d)) g[r - 1].append((l - 1, -d)) dis = [0] * n visited = [False] * n for i in range(n): if visited[i]: continue stack = list([i]) visited[i] = True while len(stack): v = stack[-1] stack.pop() for u, d in g[v]: if not visited[u]: dis[u] = dis[v] + d stack.append(u) visited[u] = True for v in range(n): for u, d in g[v]: if dis[v] + d != dis[u]: print("No") return print("Yes") if __name__ == "__main__": main()
import sys def main(): n, m = list(map(int, input().split())) g = [[] for i in range(n)] lines = sys.stdin.read().splitlines() for i in range(m): l, r, d = list(map(int, lines[i].split())) g[l - 1].append((r - 1, d)) g[r - 1].append((l - 1, -d)) dis = [0] * n visited = [False] * n for i in range(n): if visited[i]: continue stack = list([i]) visited[i] = True while len(stack): v = stack[-1] stack.pop() for u, d in g[v]: if not visited[u]: dis[u] = dis[v] + d stack.append(u) visited[u] = True for v in range(n): for u, d in g[v]: if dis[v] + d != dis[u]: print("No") return print("Yes") if __name__ == "__main__": main()
false
11.111111
[ "+import sys", "+", "+", "+ lines = sys.stdin.read().splitlines()", "- l, r, d = list(map(int, input().split()))", "+ l, r, d = list(map(int, lines[i].split()))" ]
false
0.045012
0.044718
1.006575
[ "s969037620", "s286961113" ]
u941438707
p02732
python
s056845549
s482160971
360
324
25,116
25,116
Accepted
Accepted
10
n,*a,=list(map(int,open(0).read().split())) d={} for i in a: d[i]=d.get(i,0)+1 b=0 for i in list(d.values()): b+=i*(i-1)//2 for i in a: print((b-d[i]+1))
n,*a=list(map(int,open(0).read().split())) d={} for i in a: d[i]=d.get(i,0)+1 ans=sum([i*(i-1)//2 for i in list(d.values())]) for i in a: print((ans+1-d[i]))
9
7
159
155
( n, *a, ) = list(map(int, open(0).read().split())) d = {} for i in a: d[i] = d.get(i, 0) + 1 b = 0 for i in list(d.values()): b += i * (i - 1) // 2 for i in a: print((b - d[i] + 1))
n, *a = list(map(int, open(0).read().split())) d = {} for i in a: d[i] = d.get(i, 0) + 1 ans = sum([i * (i - 1) // 2 for i in list(d.values())]) for i in a: print((ans + 1 - d[i]))
false
22.222222
[ "-(", "- n,", "- *a,", "-) = list(map(int, open(0).read().split()))", "+n, *a = list(map(int, open(0).read().split()))", "-b = 0", "-for i in list(d.values()):", "- b += i * (i - 1) // 2", "+ans = sum([i * (i - 1) // 2 for i in list(d.values())])", "- print((b - d[i] + 1))", "+ print((ans + 1 - d[i]))" ]
false
0.044889
0.045195
0.993235
[ "s056845549", "s482160971" ]
u784022244
p03107
python
s774455597
s550052708
176
18
39,664
3,188
Accepted
Accepted
89.77
S=eval(input()) N=len(S) prezero=0 preone=0 for i in range(N): s=S[i] if s=="0": if preone>0: preone-=1 else: prezero+=1 if s=="1": if prezero>0: prezero-=1 else: preone+=1 print((N-prezero-preone))
S=eval(input()) zeros=S.count("0") ones=S.count("1") print((len(S)-abs(zeros-ones)))
17
4
299
80
S = eval(input()) N = len(S) prezero = 0 preone = 0 for i in range(N): s = S[i] if s == "0": if preone > 0: preone -= 1 else: prezero += 1 if s == "1": if prezero > 0: prezero -= 1 else: preone += 1 print((N - prezero - preone))
S = eval(input()) zeros = S.count("0") ones = S.count("1") print((len(S) - abs(zeros - ones)))
false
76.470588
[ "-N = len(S)", "-prezero = 0", "-preone = 0", "-for i in range(N):", "- s = S[i]", "- if s == \"0\":", "- if preone > 0:", "- preone -= 1", "- else:", "- prezero += 1", "- if s == \"1\":", "- if prezero > 0:", "- prezero -= 1", "- else:", "- preone += 1", "-print((N - prezero - preone))", "+zeros = S.count(\"0\")", "+ones = S.count(\"1\")", "+print((len(S) - abs(zeros - ones)))" ]
false
0.075117
0.037632
1.996102
[ "s774455597", "s550052708" ]
u514118270
p02609
python
s101501636
s981404960
458
309
102,356
107,952
Accepted
Accepted
32.53
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) fact = math.factorial sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9+7 N = i() X = s()[::-1] num1 = 1 num2 = 1 num3 = 0 num4 = 0 cnt = 0 for i in range(N): if X[i] == '1': cnt += 1 cnt1 = cnt+1#0็”จ cnt2 = cnt-1#1็”จ nums = [] ans = [] tans = [1]*N for i in range(N): if X[i] == '0': nums.append(num1) else: num3 += num1 num4 += num2 nums.append(num2) if cnt1 != 0: num1 = (num1*2)%cnt1 if cnt2 != 0: num2 = (num2*2)%cnt2 if cnt1 != 0: num3 %= cnt1 if cnt2 != 0: num4 %= cnt2 for i in range(N): if X[i] == '0': if cnt1 != 0: ans.append((num3+nums[i])%cnt1) else: ans.append(0) tans[i] = 0 else: if cnt2 != 0: ans.append((num4-nums[i])%cnt2) else: ans.append(0) tans[i] = 0 ans.reverse() tans.reverse() def f(n): if n == 0: return tans[i] += 1 c = n%(list(bin(n)[2:]).count('1')) f(c) for i in range(N): f(ans[i]) for i in range(N): print((tans[i]))
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) fact = math.factorial sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9+7 N = i() X = s()[::-1] num1 = 1 num2 = 1 num3 = 0 num4 = 0 cnt = X.count('1') cnt1 = cnt+1#0็”จ cnt2 = cnt-1#1็”จ nums1 = [] nums2 = [] ans = [1]*N for i in range(N): if X[i] == '0': nums1.append(num1) else: num3 += num1 num4 += num2 nums1.append(num2) if cnt1 != 0: num1 = (num1*2)%cnt1 if cnt2 != 0: num2 = (num2*2)%cnt2 for i in range(N): if X[i] == '0': if cnt1 != 0: nums2.append((num3+nums1[i])%cnt1) else: nums2.append(0) ans[i] = 0 else: if cnt2 != 0: nums2.append((num4-nums1[i])%cnt2) else: nums2.append(0) ans[i] = 0 nums2.reverse() ans.reverse() def p(n): if n == 0: return ans[i] += 1 c = n%(bin(n).count('1')) p(c) for i in range(N): p(nums2[i]) for i in range(N): print((ans[i]))
74
71
1,548
1,445
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) fact = math.factorial sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9 + 7 N = i() X = s()[::-1] num1 = 1 num2 = 1 num3 = 0 num4 = 0 cnt = 0 for i in range(N): if X[i] == "1": cnt += 1 cnt1 = cnt + 1 # 0็”จ cnt2 = cnt - 1 # 1็”จ nums = [] ans = [] tans = [1] * N for i in range(N): if X[i] == "0": nums.append(num1) else: num3 += num1 num4 += num2 nums.append(num2) if cnt1 != 0: num1 = (num1 * 2) % cnt1 if cnt2 != 0: num2 = (num2 * 2) % cnt2 if cnt1 != 0: num3 %= cnt1 if cnt2 != 0: num4 %= cnt2 for i in range(N): if X[i] == "0": if cnt1 != 0: ans.append((num3 + nums[i]) % cnt1) else: ans.append(0) tans[i] = 0 else: if cnt2 != 0: ans.append((num4 - nums[i]) % cnt2) else: ans.append(0) tans[i] = 0 ans.reverse() tans.reverse() def f(n): if n == 0: return tans[i] += 1 c = n % (list(bin(n)[2:]).count("1")) f(c) for i in range(N): f(ans[i]) for i in range(N): print((tans[i]))
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) fact = math.factorial sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9 + 7 N = i() X = s()[::-1] num1 = 1 num2 = 1 num3 = 0 num4 = 0 cnt = X.count("1") cnt1 = cnt + 1 # 0็”จ cnt2 = cnt - 1 # 1็”จ nums1 = [] nums2 = [] ans = [1] * N for i in range(N): if X[i] == "0": nums1.append(num1) else: num3 += num1 num4 += num2 nums1.append(num2) if cnt1 != 0: num1 = (num1 * 2) % cnt1 if cnt2 != 0: num2 = (num2 * 2) % cnt2 for i in range(N): if X[i] == "0": if cnt1 != 0: nums2.append((num3 + nums1[i]) % cnt1) else: nums2.append(0) ans[i] = 0 else: if cnt2 != 0: nums2.append((num4 - nums1[i]) % cnt2) else: nums2.append(0) ans[i] = 0 nums2.reverse() ans.reverse() def p(n): if n == 0: return ans[i] += 1 c = n % (bin(n).count("1")) p(c) for i in range(N): p(nums2[i]) for i in range(N): print((ans[i]))
false
4.054054
[ "-cnt = 0", "-for i in range(N):", "- if X[i] == \"1\":", "- cnt += 1", "+cnt = X.count(\"1\")", "-nums = []", "-ans = []", "-tans = [1] * N", "+nums1 = []", "+nums2 = []", "+ans = [1] * N", "- nums.append(num1)", "+ nums1.append(num1)", "- nums.append(num2)", "+ nums1.append(num2)", "-if cnt1 != 0:", "- num3 %= cnt1", "-if cnt2 != 0:", "- num4 %= cnt2", "- ans.append((num3 + nums[i]) % cnt1)", "+ nums2.append((num3 + nums1[i]) % cnt1)", "- ans.append(0)", "- tans[i] = 0", "+ nums2.append(0)", "+ ans[i] = 0", "- ans.append((num4 - nums[i]) % cnt2)", "+ nums2.append((num4 - nums1[i]) % cnt2)", "- ans.append(0)", "- tans[i] = 0", "+ nums2.append(0)", "+ ans[i] = 0", "+nums2.reverse()", "-tans.reverse()", "-def f(n):", "+def p(n):", "- tans[i] += 1", "- c = n % (list(bin(n)[2:]).count(\"1\"))", "- f(c)", "+ ans[i] += 1", "+ c = n % (bin(n).count(\"1\"))", "+ p(c)", "- f(ans[i])", "+ p(nums2[i])", "- print((tans[i]))", "+ print((ans[i]))" ]
false
0.038919
0.047399
0.821095
[ "s101501636", "s981404960" ]
u678167152
p02954
python
s843512029
s887416394
1,463
483
394,700
398,688
Accepted
Accepted
66.99
S = eval(input()) N = len(S) db = [[0]*N for _ in range(400)] db[0] = [i+1 if S[i]=='R' else i-1 for i in range(N)] for i in range(1,400): for j in range(N): db[i][j] = db[i-1][db[i-1][j]] ans = [0]*N for i in range(N): K = 10**100 p = 0 pos = i while K: if K%2: pos = db[p][pos] p += 1 K >>= 1 ans[pos] += 1 print((*ans))
S = eval(input()) N = len(S) db = [[0]*N for _ in range(400)] db[0] = [i+1 if S[i]=='R' else i-1 for i in range(N)] for i in range(1,400): for j in range(N): db[i][j] = db[i-1][db[i-1][j]] ans = [0]*N for i in range(N): K = 10**5 p = 0 pos = i while K: if K%2: pos = db[p][pos] p += 1 K >>= 1 ans[pos] += 1 print((*ans))
19
19
367
365
S = eval(input()) N = len(S) db = [[0] * N for _ in range(400)] db[0] = [i + 1 if S[i] == "R" else i - 1 for i in range(N)] for i in range(1, 400): for j in range(N): db[i][j] = db[i - 1][db[i - 1][j]] ans = [0] * N for i in range(N): K = 10**100 p = 0 pos = i while K: if K % 2: pos = db[p][pos] p += 1 K >>= 1 ans[pos] += 1 print((*ans))
S = eval(input()) N = len(S) db = [[0] * N for _ in range(400)] db[0] = [i + 1 if S[i] == "R" else i - 1 for i in range(N)] for i in range(1, 400): for j in range(N): db[i][j] = db[i - 1][db[i - 1][j]] ans = [0] * N for i in range(N): K = 10**5 p = 0 pos = i while K: if K % 2: pos = db[p][pos] p += 1 K >>= 1 ans[pos] += 1 print((*ans))
false
0
[ "- K = 10**100", "+ K = 10**5" ]
false
0.039626
0.036009
1.100449
[ "s843512029", "s887416394" ]
u489959379
p03644
python
s024820677
s262355300
177
20
38,384
3,316
Accepted
Accepted
88.7
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) res = 0 ans = 0 for i in range(1, n + 1): n = int(str(i)[::]) cnt = 0 while n % 2 == 0: n //= 2 cnt += 1 if res <= cnt: res = cnt ans = i print(ans) if __name__ == '__main__': resolve()
import sys from collections import defaultdict sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) res = defaultdict(int) for i in range(1, n + 1): cnt = 0 k = i while k % 2 == 0: k //= 2 cnt += 1 res[i] = cnt ma = 0 ans = 1 for k, v in list(res.items()): if ma < v: ans = k ma = v print(ans) if __name__ == '__main__': resolve()
27
32
436
559
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) res = 0 ans = 0 for i in range(1, n + 1): n = int(str(i)[::]) cnt = 0 while n % 2 == 0: n //= 2 cnt += 1 if res <= cnt: res = cnt ans = i print(ans) if __name__ == "__main__": resolve()
import sys from collections import defaultdict sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) res = defaultdict(int) for i in range(1, n + 1): cnt = 0 k = i while k % 2 == 0: k //= 2 cnt += 1 res[i] = cnt ma = 0 ans = 1 for k, v in list(res.items()): if ma < v: ans = k ma = v print(ans) if __name__ == "__main__": resolve()
false
15.625
[ "+from collections import defaultdict", "+input = sys.stdin.readline", "- res = 0", "- ans = 0", "+ res = defaultdict(int)", "- n = int(str(i)[::])", "- while n % 2 == 0:", "- n //= 2", "+ k = i", "+ while k % 2 == 0:", "+ k //= 2", "- if res <= cnt:", "- res = cnt", "- ans = i", "+ res[i] = cnt", "+ ma = 0", "+ ans = 1", "+ for k, v in list(res.items()):", "+ if ma < v:", "+ ans = k", "+ ma = v" ]
false
0.085843
0.036873
2.328072
[ "s024820677", "s262355300" ]
u102461423
p02609
python
s975869111
s353741830
1,039
610
138,228
127,520
Accepted
Accepted
41.29
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines @njit((i8, ), cache=True) def popcount(n): ret = 0 while n: ret += n & 1 n >>= 1 return ret @njit((i8, ), cache=True) def f(n): t = 0 while n: t += 1 n %= popcount(n) return t @njit(cache=True) def main(X): popX = X.sum() MOD1 = popX + 1 MOD2 = popX - 1 if popX == 1: MOD2 = 1 pow1 = np.ones_like(X) pow2 = np.ones_like(X) for n in range(1, len(X)): pow1[n] = 2 * pow1[n - 1] % MOD1 pow2[n] = 2 * pow2[n - 1] % MOD2 X1, X2 = 0, 0 for x in X: X1 = (2 * X1 + x) % MOD1 X2 = (2 * X2 + x) % MOD2 ans = np.empty(N, np.int64) for i in range(N): x = X[N - 1 - i] if x == 0: nxt = (X1 + pow1[i]) % (popX + 1) ans[i] = 1 + f(nxt) elif x == 1: if popX == 1: ans[i] = 0 else: nxt = (X2 - pow2[i]) % (popX - 1) ans[i] = 1 + f(nxt) return ans[::-1] N = int(readline()) X = np.array(list(read().rstrip()), np.int64) - ord('0') ans = main(X) print(('\n'.join(map(str, ans.tolist()))))
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines @njit((i8, ), cache=True) def popcount(n): ret = 0 while n: ret += n & 1 n >>= 1 return ret @njit((i8, ), cache=True) def f(n): t = 0 while n: t += 1 n %= popcount(n) return t @njit((i8[:], ), cache=True) def main(X): N = len(X) popX = X.sum() MOD1 = popX + 1 MOD2 = popX - 1 if popX == 1: MOD2 = 1 pow1 = np.ones_like(X) pow2 = np.ones_like(X) for n in range(1, N): pow1[n] = 2 * pow1[n - 1] % MOD1 pow2[n] = 2 * pow2[n - 1] % MOD2 X1, X2 = 0, 0 for x in X: X1 = (2 * X1 + x) % MOD1 X2 = (2 * X2 + x) % MOD2 ans = np.empty(N, np.int64) for i in range(N): x = X[N - 1 - i] if x == 0: nxt = (X1 + pow1[i]) % (popX + 1) ans[i] = 1 + f(nxt) elif x == 1: if popX == 1: ans[i] = 0 else: nxt = (X2 - pow2[i]) % (popX - 1) ans[i] = 1 + f(nxt) return ans[::-1] N = int(readline()) X = np.array(list(read().rstrip()), np.int64) - ord('0') ans = main(X) print(('\n'.join(map(str, ans.tolist()))))
64
64
1,392
1,411
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines @njit((i8,), cache=True) def popcount(n): ret = 0 while n: ret += n & 1 n >>= 1 return ret @njit((i8,), cache=True) def f(n): t = 0 while n: t += 1 n %= popcount(n) return t @njit(cache=True) def main(X): popX = X.sum() MOD1 = popX + 1 MOD2 = popX - 1 if popX == 1: MOD2 = 1 pow1 = np.ones_like(X) pow2 = np.ones_like(X) for n in range(1, len(X)): pow1[n] = 2 * pow1[n - 1] % MOD1 pow2[n] = 2 * pow2[n - 1] % MOD2 X1, X2 = 0, 0 for x in X: X1 = (2 * X1 + x) % MOD1 X2 = (2 * X2 + x) % MOD2 ans = np.empty(N, np.int64) for i in range(N): x = X[N - 1 - i] if x == 0: nxt = (X1 + pow1[i]) % (popX + 1) ans[i] = 1 + f(nxt) elif x == 1: if popX == 1: ans[i] = 0 else: nxt = (X2 - pow2[i]) % (popX - 1) ans[i] = 1 + f(nxt) return ans[::-1] N = int(readline()) X = np.array(list(read().rstrip()), np.int64) - ord("0") ans = main(X) print(("\n".join(map(str, ans.tolist()))))
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines @njit((i8,), cache=True) def popcount(n): ret = 0 while n: ret += n & 1 n >>= 1 return ret @njit((i8,), cache=True) def f(n): t = 0 while n: t += 1 n %= popcount(n) return t @njit((i8[:],), cache=True) def main(X): N = len(X) popX = X.sum() MOD1 = popX + 1 MOD2 = popX - 1 if popX == 1: MOD2 = 1 pow1 = np.ones_like(X) pow2 = np.ones_like(X) for n in range(1, N): pow1[n] = 2 * pow1[n - 1] % MOD1 pow2[n] = 2 * pow2[n - 1] % MOD2 X1, X2 = 0, 0 for x in X: X1 = (2 * X1 + x) % MOD1 X2 = (2 * X2 + x) % MOD2 ans = np.empty(N, np.int64) for i in range(N): x = X[N - 1 - i] if x == 0: nxt = (X1 + pow1[i]) % (popX + 1) ans[i] = 1 + f(nxt) elif x == 1: if popX == 1: ans[i] = 0 else: nxt = (X2 - pow2[i]) % (popX - 1) ans[i] = 1 + f(nxt) return ans[::-1] N = int(readline()) X = np.array(list(read().rstrip()), np.int64) - ord("0") ans = main(X) print(("\n".join(map(str, ans.tolist()))))
false
0
[ "-@njit(cache=True)", "+@njit((i8[:],), cache=True)", "+ N = len(X)", "- for n in range(1, len(X)):", "+ for n in range(1, N):" ]
false
0.173881
0.173866
1.000091
[ "s975869111", "s353741830" ]
u344065503
p02947
python
s824034415
s351905915
906
689
128,728
65,496
Accepted
Accepted
23.95
N=int(eval(input())) dictionary={} count=0 for i in range(N): s=tuple(sorted(eval(input()))) if s in dictionary: dictionary[s]+=1 count+=dictionary[s] else: dictionary[s]=0 print(count)
N=int(eval(input())) dictionary={} count=0 for i in range(N): s="".join(sorted(eval(input()))) if s in dictionary: dictionary[s]+=1 count+=dictionary[s] else: dictionary[s]=0 print(count)
11
11
219
221
N = int(eval(input())) dictionary = {} count = 0 for i in range(N): s = tuple(sorted(eval(input()))) if s in dictionary: dictionary[s] += 1 count += dictionary[s] else: dictionary[s] = 0 print(count)
N = int(eval(input())) dictionary = {} count = 0 for i in range(N): s = "".join(sorted(eval(input()))) if s in dictionary: dictionary[s] += 1 count += dictionary[s] else: dictionary[s] = 0 print(count)
false
0
[ "- s = tuple(sorted(eval(input())))", "+ s = \"\".join(sorted(eval(input())))" ]
false
0.067459
0.046644
1.446238
[ "s824034415", "s351905915" ]
u070201429
p03161
python
s822643523
s570863541
308
260
84,976
84,856
Accepted
Accepted
15.58
def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0] * n for i in range(1, n): h = a[i] dp[i] = min([dp[j] + abs(h - a[j]) for j in range(max(0, i-k), i)]) print((dp[n-1])) main()
def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0] * n for i in range(1, n): h = a[i] cost = 10**9 for j in range(max(0, i-k), i): if dp[j] + abs(h - a[j]) < cost: cost = dp[j] + abs(h - a[j]) dp[i] = cost print((dp[n-1])) main()
12
16
264
364
def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0] * n for i in range(1, n): h = a[i] dp[i] = min([dp[j] + abs(h - a[j]) for j in range(max(0, i - k), i)]) print((dp[n - 1])) main()
def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0] * n for i in range(1, n): h = a[i] cost = 10**9 for j in range(max(0, i - k), i): if dp[j] + abs(h - a[j]) < cost: cost = dp[j] + abs(h - a[j]) dp[i] = cost print((dp[n - 1])) main()
false
25
[ "- dp[i] = min([dp[j] + abs(h - a[j]) for j in range(max(0, i - k), i)])", "+ cost = 10**9", "+ for j in range(max(0, i - k), i):", "+ if dp[j] + abs(h - a[j]) < cost:", "+ cost = dp[j] + abs(h - a[j])", "+ dp[i] = cost" ]
false
0.037218
0.036923
1.007998
[ "s822643523", "s570863541" ]
u042802884
p03805
python
s556454272
s240734707
429
180
43,868
40,048
Accepted
Accepted
58.04
def perm(k,x): v=[] for i in range(x): c=k%x+2 if c not in v: v.append(c) k//=x else: return [] return v N,M=list(map(int,input().split())) e=[[False for i in range(N+1)] for i in range(N+1)] for i in range(M): a,b=list(map(int,input().split())) e[a][b]=e[b][a]=True if N==2: ans=1 if e[1][2] else 0 else: ans=0 for k in range((N-1)**(N-1)): v=perm(k,N-1) if v and e[1][v[0]]: f=True for j in range(N-2): if not e[v[j]][v[j+1]]: f=False break if j==N-3: ans+=1 print(ans)
import itertools as it N,M=list(map(int,input().split())) e=[[False for j in range(N+1)] for i in range(N+1)] for i in range(M): a,b=list(map(int,input().split())) e[a][b]=e[b][a]=True # print(e) #DB ans=0 l=list(range(2,N+1)) for p in it.permutations(l,N-1): q=(1,)+p # print(q) #DB f=True for i in range(N-1): # print((q[i],q[i+1])) #DB if not e[q[i]][q[i+1]]: f=False break if f: ans+=1 print(ans)
33
24
725
494
def perm(k, x): v = [] for i in range(x): c = k % x + 2 if c not in v: v.append(c) k //= x else: return [] return v N, M = list(map(int, input().split())) e = [[False for i in range(N + 1)] for i in range(N + 1)] for i in range(M): a, b = list(map(int, input().split())) e[a][b] = e[b][a] = True if N == 2: ans = 1 if e[1][2] else 0 else: ans = 0 for k in range((N - 1) ** (N - 1)): v = perm(k, N - 1) if v and e[1][v[0]]: f = True for j in range(N - 2): if not e[v[j]][v[j + 1]]: f = False break if j == N - 3: ans += 1 print(ans)
import itertools as it N, M = list(map(int, input().split())) e = [[False for j in range(N + 1)] for i in range(N + 1)] for i in range(M): a, b = list(map(int, input().split())) e[a][b] = e[b][a] = True # print(e) #DB ans = 0 l = list(range(2, N + 1)) for p in it.permutations(l, N - 1): q = (1,) + p # print(q) #DB f = True for i in range(N - 1): # print((q[i],q[i+1])) #DB if not e[q[i]][q[i + 1]]: f = False break if f: ans += 1 print(ans)
false
27.272727
[ "-def perm(k, x):", "- v = []", "- for i in range(x):", "- c = k % x + 2", "- if c not in v:", "- v.append(c)", "- k //= x", "- else:", "- return []", "- return v", "-", "+import itertools as it", "-e = [[False for i in range(N + 1)] for i in range(N + 1)]", "+e = [[False for j in range(N + 1)] for i in range(N + 1)]", "-if N == 2:", "- ans = 1 if e[1][2] else 0", "-else:", "- ans = 0", "- for k in range((N - 1) ** (N - 1)):", "- v = perm(k, N - 1)", "- if v and e[1][v[0]]:", "- f = True", "- for j in range(N - 2):", "- if not e[v[j]][v[j + 1]]:", "- f = False", "- break", "- if j == N - 3:", "- ans += 1", "+# print(e) #DB", "+ans = 0", "+l = list(range(2, N + 1))", "+for p in it.permutations(l, N - 1):", "+ q = (1,) + p", "+ # print(q) #DB", "+ f = True", "+ for i in range(N - 1):", "+ # print((q[i],q[i+1])) #DB", "+ if not e[q[i]][q[i + 1]]:", "+ f = False", "+ break", "+ if f:", "+ ans += 1" ]
false
0.050873
0.043046
1.181808
[ "s556454272", "s240734707" ]
u852690916
p03160
python
s980118757
s273917536
183
139
13,924
13,980
Accepted
Accepted
24.04
N = int(eval(input())) H = list(map(int, input().split())) H.append(0) H.append(0) #dp[่ถณๅ ดi]=่ถณๅ ดiใซใŸใฉใ‚Š็€ใๆœ€ๅฐใ‚ณใ‚นใƒˆ dp = [10**10 for _ in range(N+10)] dp[0] = 0 for i in range(N): dp[i+1] = min(dp[i+1], dp[i] + abs(H[i]-H[i+1])) dp[i+2] = min(dp[i+2], dp[i] + abs(H[i]-H[i+2])) print((dp[N-1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [0] * (N) dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = dp[i-1] + abs(h[i] - h[i-1]) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print((dp[N-1]))
14
10
302
235
N = int(eval(input())) H = list(map(int, input().split())) H.append(0) H.append(0) # dp[่ถณๅ ดi]=่ถณๅ ดiใซใŸใฉใ‚Š็€ใๆœ€ๅฐใ‚ณใ‚นใƒˆ dp = [10**10 for _ in range(N + 10)] dp[0] = 0 for i in range(N): dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2])) print((dp[N - 1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [0] * (N) dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
false
28.571429
[ "-H = list(map(int, input().split()))", "-H.append(0)", "-H.append(0)", "-# dp[่ถณๅ ดi]=่ถณๅ ดiใซใŸใฉใ‚Š็€ใๆœ€ๅฐใ‚ณใ‚นใƒˆ", "-dp = [10**10 for _ in range(N + 10)]", "-dp[0] = 0", "-for i in range(N):", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))", "+h = list(map(int, input().split()))", "+dp = [0] * (N)", "+dp[1] = abs(h[1] - h[0])", "+for i in range(2, N):", "+ dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])", "+ dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.105155
0.174128
0.603896
[ "s980118757", "s273917536" ]
u302957509
p02983
python
s153061100
s381808358
850
415
3,064
2,940
Accepted
Accepted
51.18
L, R = list(map(int, input().split())) MOD = 2019 if R - L >= MOD - 1: print((0)) exit() if L % MOD < R % MOD: a = [n for n in range(L % MOD, R % MOD + 1)] elif L % MOD > R % MOD: a = [n for n in range(L % MOD, MOD)] + [n for n in range(R % MOD + 1)] else: a = list(range(MOD)) ans = MOD - 1 for i in range(len(a)): for j in range(i + 1, len(a)): ans = min(ans, (a[i] * a[j]) % MOD) print(ans)
L, R = list(map(int, input().split())) MOD = 2019 print((min( (i * j) % MOD for i in range(L, R + 1) for j in range(i + 1, R + 1) ) if R - L < MOD - 1 else 0))
20
8
441
172
L, R = list(map(int, input().split())) MOD = 2019 if R - L >= MOD - 1: print((0)) exit() if L % MOD < R % MOD: a = [n for n in range(L % MOD, R % MOD + 1)] elif L % MOD > R % MOD: a = [n for n in range(L % MOD, MOD)] + [n for n in range(R % MOD + 1)] else: a = list(range(MOD)) ans = MOD - 1 for i in range(len(a)): for j in range(i + 1, len(a)): ans = min(ans, (a[i] * a[j]) % MOD) print(ans)
L, R = list(map(int, input().split())) MOD = 2019 print( ( min((i * j) % MOD for i in range(L, R + 1) for j in range(i + 1, R + 1)) if R - L < MOD - 1 else 0 ) )
false
60
[ "-if R - L >= MOD - 1:", "- print((0))", "- exit()", "-if L % MOD < R % MOD:", "- a = [n for n in range(L % MOD, R % MOD + 1)]", "-elif L % MOD > R % MOD:", "- a = [n for n in range(L % MOD, MOD)] + [n for n in range(R % MOD + 1)]", "-else:", "- a = list(range(MOD))", "-ans = MOD - 1", "-for i in range(len(a)):", "- for j in range(i + 1, len(a)):", "- ans = min(ans, (a[i] * a[j]) % MOD)", "-print(ans)", "+print(", "+ (", "+ min((i * j) % MOD for i in range(L, R + 1) for j in range(i + 1, R + 1))", "+ if R - L < MOD - 1", "+ else 0", "+ )", "+)" ]
false
0.054598
0.037182
1.468396
[ "s153061100", "s381808358" ]
u623814058
p02982
python
s554609276
s556212908
28
25
9,396
9,460
Accepted
Accepted
10.71
N,D=list(map(int,input().split())) X=[list(map(int,input().split())) for i in range(N)] l=len(X) cnt=0 for i in range(l): for j in range(i+1,l): t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5 if t==int(t):cnt+=1 print(cnt)
N,D=list(map(int,input().split())) X=[list(map(int,input().split())) for i in range(N)] l=len(X) cnt=0 for i in range(l): for j in range(i+1,l): t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5 cnt+=t==int(t) print(cnt)
9
9
232
227
N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] l = len(X) cnt = 0 for i in range(l): for j in range(i + 1, l): t = sum((X[i][d] - X[j][d]) ** 2 for d in range(D)) ** 0.5 if t == int(t): cnt += 1 print(cnt)
N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] l = len(X) cnt = 0 for i in range(l): for j in range(i + 1, l): t = sum((X[i][d] - X[j][d]) ** 2 for d in range(D)) ** 0.5 cnt += t == int(t) print(cnt)
false
0
[ "- if t == int(t):", "- cnt += 1", "+ cnt += t == int(t)" ]
false
0.047306
0.07064
0.669682
[ "s554609276", "s556212908" ]
u466335531
p03061
python
s576985930
s559037572
230
163
63,984
14,588
Accepted
Accepted
29.13
from math import sqrt from sys import exit N=int(eval(input())) A=list(map(int,input().split())) if len(A)==2: print((max(A))) exit() def gcd(a,b): if a<b: a,b=b,a if a%b==0: return b return gcd(b,a%b) g=gcd(A[0],A[-1]) p=[] for i in range(1,int(sqrt(g)+1)): if g%i==0: if i*i==g: p.append(i) else: p+=[i,g//i] def ok(n): f=False for a in A[1:-1]: if a%n: if f: return False f=True return True def GCD(L): if len(L)==1: return L[0] ans=gcd(L[0],L[1]) if len(L)>2: for l in L[2:]: ans=gcd(ans,l) return ans p.sort(reverse=True) for num in p: if ok(num): ans=num break p1=GCD(A[1:-1]) print((max([ans,gcd(p1,A[0]),gcd(p1,A[-1])])))
from math import sqrt from sys import exit N=int(eval(input())) A=list(map(int,input().split())) if len(A)==2: print((max(A))) exit() def gcd(a,b): if a<b: a,b=b,a if a%b==0: return b return gcd(b,a%b) g=A[0] L=[g] for a in A[1:-1]: g=gcd(g,a) L.append(g) g=A[-1] R=[g] for a in A[1:-1][::-1]: g=gcd(g,a) R.append(g) ans=max(L[-1],R[-1]) for l,r in zip(L[:-1],R[:-1][::-1]): ans=max(ans,gcd(l,r)) print(ans)
46
30
829
481
from math import sqrt from sys import exit N = int(eval(input())) A = list(map(int, input().split())) if len(A) == 2: print((max(A))) exit() def gcd(a, b): if a < b: a, b = b, a if a % b == 0: return b return gcd(b, a % b) g = gcd(A[0], A[-1]) p = [] for i in range(1, int(sqrt(g) + 1)): if g % i == 0: if i * i == g: p.append(i) else: p += [i, g // i] def ok(n): f = False for a in A[1:-1]: if a % n: if f: return False f = True return True def GCD(L): if len(L) == 1: return L[0] ans = gcd(L[0], L[1]) if len(L) > 2: for l in L[2:]: ans = gcd(ans, l) return ans p.sort(reverse=True) for num in p: if ok(num): ans = num break p1 = GCD(A[1:-1]) print((max([ans, gcd(p1, A[0]), gcd(p1, A[-1])])))
from math import sqrt from sys import exit N = int(eval(input())) A = list(map(int, input().split())) if len(A) == 2: print((max(A))) exit() def gcd(a, b): if a < b: a, b = b, a if a % b == 0: return b return gcd(b, a % b) g = A[0] L = [g] for a in A[1:-1]: g = gcd(g, a) L.append(g) g = A[-1] R = [g] for a in A[1:-1][::-1]: g = gcd(g, a) R.append(g) ans = max(L[-1], R[-1]) for l, r in zip(L[:-1], R[:-1][::-1]): ans = max(ans, gcd(l, r)) print(ans)
false
34.782609
[ "-g = gcd(A[0], A[-1])", "-p = []", "-for i in range(1, int(sqrt(g) + 1)):", "- if g % i == 0:", "- if i * i == g:", "- p.append(i)", "- else:", "- p += [i, g // i]", "-", "-", "-def ok(n):", "- f = False", "- for a in A[1:-1]:", "- if a % n:", "- if f:", "- return False", "- f = True", "- return True", "-", "-", "-def GCD(L):", "- if len(L) == 1:", "- return L[0]", "- ans = gcd(L[0], L[1])", "- if len(L) > 2:", "- for l in L[2:]:", "- ans = gcd(ans, l)", "- return ans", "-", "-", "-p.sort(reverse=True)", "-for num in p:", "- if ok(num):", "- ans = num", "- break", "-p1 = GCD(A[1:-1])", "-print((max([ans, gcd(p1, A[0]), gcd(p1, A[-1])])))", "+g = A[0]", "+L = [g]", "+for a in A[1:-1]:", "+ g = gcd(g, a)", "+ L.append(g)", "+g = A[-1]", "+R = [g]", "+for a in A[1:-1][::-1]:", "+ g = gcd(g, a)", "+ R.append(g)", "+ans = max(L[-1], R[-1])", "+for l, r in zip(L[:-1], R[:-1][::-1]):", "+ ans = max(ans, gcd(l, r))", "+print(ans)" ]
false
0.074637
0.074314
1.004349
[ "s576985930", "s559037572" ]
u796942881
p03721
python
s259218261
s731985935
223
129
29,868
13,844
Accepted
Accepted
42.15
from sys import stdin from operator import itemgetter def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort(key=itemgetter(0)) cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
from sys import stdin def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) bn = [0] * (int(1e5) + 1) for line in lines[1:]: ai, bi = list(map(int, line.split())) bn[ai] += bi cnt = 0 for ai, bi in enumerate(bn): cnt += bi if K <= cnt: print(ai) break return main()
19
20
389
385
from sys import stdin from operator import itemgetter def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort(key=itemgetter(0)) cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
from sys import stdin def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) bn = [0] * (int(1e5) + 1) for line in lines[1:]: ai, bi = list(map(int, line.split())) bn[ai] += bi cnt = 0 for ai, bi in enumerate(bn): cnt += bi if K <= cnt: print(ai) break return main()
false
5
[ "-from operator import itemgetter", "- abn = [[int(abi) for abi in line.split()] for line in lines[1:]]", "- abn.sort(key=itemgetter(0))", "+ bn = [0] * (int(1e5) + 1)", "+ for line in lines[1:]:", "+ ai, bi = list(map(int, line.split()))", "+ bn[ai] += bi", "- for ai, bi in abn:", "+ for ai, bi in enumerate(bn):" ]
false
0.044353
0.039284
1.129019
[ "s259218261", "s731985935" ]
u467175809
p01420
python
s903468425
s797580721
720
660
5,180
5,184
Accepted
Accepted
8.33
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) N, M, L = list(map(int, input().split())) def fact(n): if n <= 1: return 1 return fact(n - 1) * n MC = [] for i in range(M + 1): MC.append(fact(M) / fact(i) / fact(M - i)) p_lst = [] P_val = [] P_sum = [] for i in range(N): P, T, V = list(map(int, input().split())) p_lst.append((T, V)) PP = [] for k in range(M + 1): PP.append(float(MC[k] * (P ** k) * ((100 - P) ** (M - k))) / 100 ** M) P_val.append(list(PP)) for k in range(M, 0, -1): PP[k - 1] += PP[k] P_sum.append(PP) def comp(p1, p2, k1, k2): T1, V1 = p1 T2, V2 = p2 return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1) for i in range(N): ans = 0 index_lst = [0 for j in range(N)] for k1 in range(M + 1): ret = P_val[i][k1] for j in range(N): if i == j: continue flag = True while True: k2 = index_lst[j] if k2 > M: ret *= 0 break if comp(p_lst[i], p_lst[j], k1, k2): ret *= P_sum[j][k2] break index_lst[j] += 1 ans += ret print('%.10f' % ans)
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) N, M, L = list(map(int, input().split())) def fact(n): if n <= 1: return 1 return fact(n - 1) * n MC = [] for i in range(M + 1): MC.append(fact(M) / fact(i) / fact(M - i)) p_lst = [] P_val = [] P_sum = [] for i in range(N): P, T, V = list(map(int, input().split())) p_lst.append((T, V)) PP = [] for k in range(M + 1): PP.append(float(MC[k] * (P ** k) * ((100 - P) ** (M - k))) / 100 ** M) P_val.append(list(PP)) for k in range(M, 0, -1): PP[k - 1] += PP[k] P_sum.append(PP) def comp(p1, p2, k1, k2): T1, V1 = p1 T2, V2 = p2 return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1) for i in range(N): ans = 0 index_lst = [0 for j in range(N)] for k1 in range(M + 1): ret = P_val[i][k1] for j in range(N): if i == j: continue while True: k2 = index_lst[j] if k2 > M: ret *= 0 break if comp(p_lst[i], p_lst[j], k1, k2): ret *= P_sum[j][k2] break index_lst[j] += 1 ans += ret print('%.10f' % ans)
59
58
1,392
1,367
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) N, M, L = list(map(int, input().split())) def fact(n): if n <= 1: return 1 return fact(n - 1) * n MC = [] for i in range(M + 1): MC.append(fact(M) / fact(i) / fact(M - i)) p_lst = [] P_val = [] P_sum = [] for i in range(N): P, T, V = list(map(int, input().split())) p_lst.append((T, V)) PP = [] for k in range(M + 1): PP.append(float(MC[k] * (P**k) * ((100 - P) ** (M - k))) / 100**M) P_val.append(list(PP)) for k in range(M, 0, -1): PP[k - 1] += PP[k] P_sum.append(PP) def comp(p1, p2, k1, k2): T1, V1 = p1 T2, V2 = p2 return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1) for i in range(N): ans = 0 index_lst = [0 for j in range(N)] for k1 in range(M + 1): ret = P_val[i][k1] for j in range(N): if i == j: continue flag = True while True: k2 = index_lst[j] if k2 > M: ret *= 0 break if comp(p_lst[i], p_lst[j], k1, k2): ret *= P_sum[j][k2] break index_lst[j] += 1 ans += ret print("%.10f" % ans)
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) N, M, L = list(map(int, input().split())) def fact(n): if n <= 1: return 1 return fact(n - 1) * n MC = [] for i in range(M + 1): MC.append(fact(M) / fact(i) / fact(M - i)) p_lst = [] P_val = [] P_sum = [] for i in range(N): P, T, V = list(map(int, input().split())) p_lst.append((T, V)) PP = [] for k in range(M + 1): PP.append(float(MC[k] * (P**k) * ((100 - P) ** (M - k))) / 100**M) P_val.append(list(PP)) for k in range(M, 0, -1): PP[k - 1] += PP[k] P_sum.append(PP) def comp(p1, p2, k1, k2): T1, V1 = p1 T2, V2 = p2 return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1) for i in range(N): ans = 0 index_lst = [0 for j in range(N)] for k1 in range(M + 1): ret = P_val[i][k1] for j in range(N): if i == j: continue while True: k2 = index_lst[j] if k2 > M: ret *= 0 break if comp(p_lst[i], p_lst[j], k1, k2): ret *= P_sum[j][k2] break index_lst[j] += 1 ans += ret print("%.10f" % ans)
false
1.694915
[ "- flag = True" ]
false
0.04066
0.049205
0.826327
[ "s903468425", "s797580721" ]
u094191970
p02691
python
s424790652
s373700255
268
246
63,228
63,552
Accepted
Accepted
8.21
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) i_l=[] j_l=[] for i in range(n): i_l.append(i+a[i]) j_l.append(i-a[i]) ci=Counter(i_l) cl=Counter(j_l) ans=0 for k,v in list(ci.items()): ans+=v*cl[k] print(ans)
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) from collections import Counter n=int(eval(input())) a=lnii() l1=[i+a[i] for i in range(n)] l2=[i-a[i] for i in range(n)] c1=Counter(l1) c2=Counter(l2) ans=0 for i in c1: ans+=c1[i]*c2[i] print(ans)
19
19
264
336
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) i_l = [] j_l = [] for i in range(n): i_l.append(i + a[i]) j_l.append(i - a[i]) ci = Counter(i_l) cl = Counter(j_l) ans = 0 for k, v in list(ci.items()): ans += v * cl[k] print(ans)
from sys import stdin nii = lambda: list(map(int, stdin.readline().split())) lnii = lambda: list(map(int, stdin.readline().split())) from collections import Counter n = int(eval(input())) a = lnii() l1 = [i + a[i] for i in range(n)] l2 = [i - a[i] for i in range(n)] c1 = Counter(l1) c2 = Counter(l2) ans = 0 for i in c1: ans += c1[i] * c2[i] print(ans)
false
0
[ "+from sys import stdin", "+", "+nii = lambda: list(map(int, stdin.readline().split()))", "+lnii = lambda: list(map(int, stdin.readline().split()))", "-a = list(map(int, input().split()))", "-i_l = []", "-j_l = []", "-for i in range(n):", "- i_l.append(i + a[i])", "- j_l.append(i - a[i])", "-ci = Counter(i_l)", "-cl = Counter(j_l)", "+a = lnii()", "+l1 = [i + a[i] for i in range(n)]", "+l2 = [i - a[i] for i in range(n)]", "+c1 = Counter(l1)", "+c2 = Counter(l2)", "-for k, v in list(ci.items()):", "- ans += v * cl[k]", "+for i in c1:", "+ ans += c1[i] * c2[i]" ]
false
0.046876
0.155426
0.301598
[ "s424790652", "s373700255" ]
u127499732
p03013
python
s825781258
s612020867
452
210
460,020
13,192
Accepted
Accepted
53.54
n,m=list(map(int,input().split())) x=set([int(eval(input())) for _ in range(m)]) f=[0]*(n+1) f[0]=1 for i in range(1,n+1): f[i]=f[i-1]+f[i-2] if i in x: f[i]=0 print((f[n]%(10**9+7)))
n,m=list(map(int,input().split())) x=set([int(eval(input())) for _ in range(m)]) f=[0]*(n+1) f[0]=1 for i in range(1,n+1): f[i]=(f[i-1]+f[i-2])%(10**9+7) if i in x: f[i]=0 print((f[n]%(10**9+7)))
9
9
185
197
n, m = list(map(int, input().split())) x = set([int(eval(input())) for _ in range(m)]) f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = f[i - 1] + f[i - 2] if i in x: f[i] = 0 print((f[n] % (10**9 + 7)))
n, m = list(map(int, input().split())) x = set([int(eval(input())) for _ in range(m)]) f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = (f[i - 1] + f[i - 2]) % (10**9 + 7) if i in x: f[i] = 0 print((f[n] % (10**9 + 7)))
false
0
[ "- f[i] = f[i - 1] + f[i - 2]", "+ f[i] = (f[i - 1] + f[i - 2]) % (10**9 + 7)" ]
false
0.132861
0.079084
1.68
[ "s825781258", "s612020867" ]
u298297089
p03337
python
s593643168
s846237852
171
17
38,384
2,940
Accepted
Accepted
90.06
A,B = list(map(int, input().split())) print((max(A+B,A-B,A*B)))
a,b = list(map(int, input().split())) print((max([a + b, a-b, a*b])))
2
2
56
62
A, B = list(map(int, input().split())) print((max(A + B, A - B, A * B)))
a, b = list(map(int, input().split())) print((max([a + b, a - b, a * b])))
false
0
[ "-A, B = list(map(int, input().split()))", "-print((max(A + B, A - B, A * B)))", "+a, b = list(map(int, input().split()))", "+print((max([a + b, a - b, a * b])))" ]
false
0.031739
0.034916
0.908997
[ "s593643168", "s846237852" ]
u972591645
p02578
python
s091979093
s210094489
158
98
32,372
32,352
Accepted
Accepted
37.97
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(1, n): if a[i-1] > a[i]: ans += a[i-1] - a[i] a[i] = a[i-1] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) tmp = a[0] ans = 0 for i in a: if i < tmp: ans += tmp-i else: tmp = i print(ans)
9
11
175
169
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(1, n): if a[i - 1] > a[i]: ans += a[i - 1] - a[i] a[i] = a[i - 1] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) tmp = a[0] ans = 0 for i in a: if i < tmp: ans += tmp - i else: tmp = i print(ans)
false
18.181818
[ "+tmp = a[0]", "-for i in range(1, n):", "- if a[i - 1] > a[i]:", "- ans += a[i - 1] - a[i]", "- a[i] = a[i - 1]", "+for i in a:", "+ if i < tmp:", "+ ans += tmp - i", "+ else:", "+ tmp = i" ]
false
0.060097
0.059488
1.010237
[ "s091979093", "s210094489" ]
u228496478
p03161
python
s319868173
s276413879
1,948
431
13,980
52,592
Accepted
Accepted
77.87
def main(): n,k=list(map(int,input().split())) c=list(map(int,input().split())) dp=[0]*n dp[0]=0 for i in range(1,n): dp[i]=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)]) print((dp[-1])) if __name__=='__main__': main()
n,k=list(map(int,input().split())) c=list(map(int,input().split())) dp=[0]*n dp[0]=0 for i in range(1,n): dp[i]=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)]) print((dp[-1]))
10
7
265
186
def main(): n, k = list(map(int, input().split())) c = list(map(int, input().split())) dp = [0] * n dp[0] = 0 for i in range(1, n): dp[i] = min([dp[j] + abs(c[i] - c[j]) for j in range(max(0, i - k), i)]) print((dp[-1])) if __name__ == "__main__": main()
n, k = list(map(int, input().split())) c = list(map(int, input().split())) dp = [0] * n dp[0] = 0 for i in range(1, n): dp[i] = min([dp[j] + abs(c[i] - c[j]) for j in range(max(0, i - k), i)]) print((dp[-1]))
false
30
[ "-def main():", "- n, k = list(map(int, input().split()))", "- c = list(map(int, input().split()))", "- dp = [0] * n", "- dp[0] = 0", "- for i in range(1, n):", "- dp[i] = min([dp[j] + abs(c[i] - c[j]) for j in range(max(0, i - k), i)])", "- print((dp[-1]))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n, k = list(map(int, input().split()))", "+c = list(map(int, input().split()))", "+dp = [0] * n", "+dp[0] = 0", "+for i in range(1, n):", "+ dp[i] = min([dp[j] + abs(c[i] - c[j]) for j in range(max(0, i - k), i)])", "+print((dp[-1]))" ]
false
0.076086
0.03544
2.146866
[ "s319868173", "s276413879" ]
u729133443
p03088
python
s609660993
s216160397
168
21
4,688
4,724
Accepted
Accepted
87.5
import re,functools as f;d=f.lru_cache(999)(lambda n,b:n<1or sum(d(n-1,b[1:]+s)for s in'ACGT'if not re.match('.AGC|.ACG|.GAC|A.GC|AG.C',b+s))%(10**9+7));print((d(int(eval(input())),'TTT')))
a=b=c=d=e=f=0;g=1;exec('a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,(g*4-b-c-d-a*3)%(10**9+7);'*int(eval(input())));print(g)
1
1
181
104
import re, functools as f d = f.lru_cache(999)( lambda n, b: n < 1 or sum( d(n - 1, b[1:] + s) for s in "ACGT" if not re.match(".AGC|.ACG|.GAC|A.GC|AG.C", b + s) ) % (10**9 + 7) ) print((d(int(eval(input())), "TTT")))
a = b = c = d = e = f = 0 g = 1 exec("a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,(g*4-b-c-d-a*3)%(10**9+7);" * int(eval(input()))) print(g)
false
0
[ "-import re, functools as f", "-", "-d = f.lru_cache(999)(", "- lambda n, b: n < 1", "- or sum(", "- d(n - 1, b[1:] + s)", "- for s in \"ACGT\"", "- if not re.match(\".AGC|.ACG|.GAC|A.GC|AG.C\", b + s)", "- )", "- % (10**9 + 7)", "-)", "-print((d(int(eval(input())), \"TTT\")))", "+a = b = c = d = e = f = 0", "+g = 1", "+exec(\"a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,(g*4-b-c-d-a*3)%(10**9+7);\" * int(eval(input())))", "+print(g)" ]
false
0.08781
0.03519
2.495319
[ "s609660993", "s216160397" ]
u313111801
p03308
python
s867336987
s490783934
37
27
9,124
9,156
Accepted
Accepted
27.03
N=int(eval(input())) A=[int(x) for x in input().split()] ans=0 for i in range(N): for j in range(N): ans=max(ans,abs(A[i]-A[j])) print(ans)
N=int(eval(input())) A=[int(x) for x in input().split()] print((max(A)-min(A)))
7
3
151
73
N = int(eval(input())) A = [int(x) for x in input().split()] ans = 0 for i in range(N): for j in range(N): ans = max(ans, abs(A[i] - A[j])) print(ans)
N = int(eval(input())) A = [int(x) for x in input().split()] print((max(A) - min(A)))
false
57.142857
[ "-ans = 0", "-for i in range(N):", "- for j in range(N):", "- ans = max(ans, abs(A[i] - A[j]))", "-print(ans)", "+print((max(A) - min(A)))" ]
false
0.050465
0.076842
0.656731
[ "s867336987", "s490783934" ]
u088552457
p02660
python
s238198444
s610246922
117
99
71,140
77,348
Accepted
Accepted
15.38
from functools import reduce from decimal import * from operator import mul def main(): n = int(eval(input())) p = prime_factorize(n) sa = list(sorted(p)) pp = [] num = 1 for i, v in enumerate(sa): if i > 0 and sa[i-1] != v: num = 1 num *= v if num not in pp and n % num == 0: pp.append(num) num = 1 print((len(pp))) def input_list(): return list(map(int, input().split())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a if __name__ == '__main__': main()
# import sys # input = sys.stdin.readline import itertools import collections from decimal import Decimal # ๆŒใฃใฆใ„ใ‚‹ใƒ“ใ‚นใ‚ฑใƒƒใƒˆใ‚’ๅฉใใ€1ๆžšๅข—ใ‚„ใ™ # ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Aๆžšใ‚’ 1ๅ††ใซไบคๆ›ใ™ใ‚‹ # 1ๅ††ใ‚’ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Bๆžšใซไบคๆ›ใ™ใ‚‹ def main(): n = int(eval(input())) p = prime_factorize(n) cp = collections.Counter(p) ans = 0 for c, num in list(cp.items()): count = 0 jou = 1 for _ in range(num): count += 1 if count == jou: count = 0 jou += 1 ans += 1 print(ans) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def bfs(H, W, black_cells, dist): d = 0 while black_cells: 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)) return d def input_list(): return list(map(Decimal, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
40
68
812
1,504
from functools import reduce from decimal import * from operator import mul def main(): n = int(eval(input())) p = prime_factorize(n) sa = list(sorted(p)) pp = [] num = 1 for i, v in enumerate(sa): if i > 0 and sa[i - 1] != v: num = 1 num *= v if num not in pp and n % num == 0: pp.append(num) num = 1 print((len(pp))) def input_list(): return list(map(int, input().split())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a if __name__ == "__main__": main()
# import sys # input = sys.stdin.readline import itertools import collections from decimal import Decimal # ๆŒใฃใฆใ„ใ‚‹ใƒ“ใ‚นใ‚ฑใƒƒใƒˆใ‚’ๅฉใใ€1ๆžšๅข—ใ‚„ใ™ # ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Aๆžšใ‚’ 1ๅ††ใซไบคๆ›ใ™ใ‚‹ # 1ๅ††ใ‚’ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Bๆžšใซไบคๆ›ใ™ใ‚‹ def main(): n = int(eval(input())) p = prime_factorize(n) cp = collections.Counter(p) ans = 0 for c, num in list(cp.items()): count = 0 jou = 1 for _ in range(num): count += 1 if count == jou: count = 0 jou += 1 ans += 1 print(ans) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def bfs(H, W, black_cells, dist): d = 0 while black_cells: 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)) return d def input_list(): return list(map(Decimal, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
false
41.176471
[ "-from functools import reduce", "-from decimal import *", "-from operator import mul", "+# import sys", "+# input = sys.stdin.readline", "+import itertools", "+import collections", "+from decimal import Decimal", "-", "+# ๆŒใฃใฆใ„ใ‚‹ใƒ“ใ‚นใ‚ฑใƒƒใƒˆใ‚’ๅฉใใ€1ๆžšๅข—ใ‚„ใ™", "+# ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Aๆžšใ‚’ 1ๅ††ใซไบคๆ›ใ™ใ‚‹", "+# 1ๅ††ใ‚’ใƒ“ใ‚นใ‚ฑใƒƒใƒˆ Bๆžšใซไบคๆ›ใ™ใ‚‹", "- sa = list(sorted(p))", "- pp = []", "- num = 1", "- for i, v in enumerate(sa):", "- if i > 0 and sa[i - 1] != v:", "- num = 1", "- num *= v", "- if num not in pp and n % num == 0:", "- pp.append(num)", "- num = 1", "- print((len(pp)))", "-", "-", "-def input_list():", "- return list(map(int, input().split()))", "+ cp = collections.Counter(p)", "+ ans = 0", "+ for c, num in list(cp.items()):", "+ count = 0", "+ jou = 1", "+ for _ in range(num):", "+ count += 1", "+ if count == jou:", "+ count = 0", "+ jou += 1", "+ ans += 1", "+ print(ans)", "+def bfs(H, W, black_cells, dist):", "+ d = 0", "+ while black_cells:", "+ 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))", "+ return d", "+", "+", "+def input_list():", "+ return list(map(Decimal, input().split()))", "+", "+", "+def input_list_str():", "+ return list(map(str, input().split()))", "+", "+" ]
false
0.039548
0.10303
0.383853
[ "s238198444", "s610246922" ]
u730769327
p03164
python
s525117774
s545493361
441
123
218,120
71,664
Accepted
Accepted
72.11
n,W=list(map(int,input().split())) w=[] v=[] for i in range(n): a,b=list(map(int,input().split())) w.append(a) v.append(b) V=sum(v) INF=10**18 dp=[[INF for _ in range(V+1)] for _ in range(n+1)] dp[0][0]=0 for i in range(n): for j in range(V+1): if j<v[i]:dp[i+1][j]=dp[i][j] else:dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]) for i in range(V+1): if dp[n][i]<=W:ans=i print(ans)
INF=10**18 n,m=list(map(int,input().split())) w=[0]*n v=[0]*n for i in range(n): w[i],v[i]=list(map(int,input().split())) k=sum(v) dp=[INF]*(k+1) dp[0]=0 for i in range(n): for j in range(k,-1,-1): if j>=v[i] and dp[j-v[i]]!=INF:dp[j]=min(dp[j],dp[j-v[i]]+w[i]) for i,x in enumerate(dp): if x<=m:ans=i print(ans)
18
15
399
324
n, W = list(map(int, input().split())) w = [] v = [] for i in range(n): a, b = list(map(int, input().split())) w.append(a) v.append(b) V = sum(v) INF = 10**18 dp = [[INF for _ in range(V + 1)] for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(V + 1): if j < v[i]: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]) for i in range(V + 1): if dp[n][i] <= W: ans = i print(ans)
INF = 10**18 n, m = list(map(int, input().split())) w = [0] * n v = [0] * n for i in range(n): w[i], v[i] = list(map(int, input().split())) k = sum(v) dp = [INF] * (k + 1) dp[0] = 0 for i in range(n): for j in range(k, -1, -1): if j >= v[i] and dp[j - v[i]] != INF: dp[j] = min(dp[j], dp[j - v[i]] + w[i]) for i, x in enumerate(dp): if x <= m: ans = i print(ans)
false
16.666667
[ "-n, W = list(map(int, input().split()))", "-w = []", "-v = []", "+INF = 10**18", "+n, m = list(map(int, input().split()))", "+w = [0] * n", "+v = [0] * n", "- a, b = list(map(int, input().split()))", "- w.append(a)", "- v.append(b)", "-V = sum(v)", "-INF = 10**18", "-dp = [[INF for _ in range(V + 1)] for _ in range(n + 1)]", "-dp[0][0] = 0", "+ w[i], v[i] = list(map(int, input().split()))", "+k = sum(v)", "+dp = [INF] * (k + 1)", "+dp[0] = 0", "- for j in range(V + 1):", "- if j < v[i]:", "- dp[i + 1][j] = dp[i][j]", "- else:", "- dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])", "-for i in range(V + 1):", "- if dp[n][i] <= W:", "+ for j in range(k, -1, -1):", "+ if j >= v[i] and dp[j - v[i]] != INF:", "+ dp[j] = min(dp[j], dp[j - v[i]] + w[i])", "+for i, x in enumerate(dp):", "+ if x <= m:" ]
false
0.03699
0.03623
1.020977
[ "s525117774", "s545493361" ]
u638456847
p02702
python
s107258444
s748572049
310
98
16,612
10,916
Accepted
Accepted
68.39
from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): S = readline().strip()[::-1] N = len(S) a = [0] s = 0 for i in range(N): s += int(S[i]) * pow(10, i, 2019) a.append(s % 2019) t = Counter(a) ans = 0 for _, v in list(t.items()): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): S = [int(i) for i in readline().strip()[::-1]] a = {} a[0] = 1 t = 0 x = 1 for s in S: t += s * x t %= 2019 if t in a: a[t] += 1 else: a[t] = 1 x *= 10 x %= 2019 ans = 0 for v in list(a.values()): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
27
33
487
545
from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): S = readline().strip()[::-1] N = len(S) a = [0] s = 0 for i in range(N): s += int(S[i]) * pow(10, i, 2019) a.append(s % 2019) t = Counter(a) ans = 0 for _, v in list(t.items()): ans += v * (v - 1) // 2 print(ans) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): S = [int(i) for i in readline().strip()[::-1]] a = {} a[0] = 1 t = 0 x = 1 for s in S: t += s * x t %= 2019 if t in a: a[t] += 1 else: a[t] = 1 x *= 10 x %= 2019 ans = 0 for v in list(a.values()): ans += v * (v - 1) // 2 print(ans) if __name__ == "__main__": main()
false
18.181818
[ "-from collections import Counter", "- S = readline().strip()[::-1]", "- N = len(S)", "- a = [0]", "- s = 0", "- for i in range(N):", "- s += int(S[i]) * pow(10, i, 2019)", "- a.append(s % 2019)", "- t = Counter(a)", "+ S = [int(i) for i in readline().strip()[::-1]]", "+ a = {}", "+ a[0] = 1", "+ t = 0", "+ x = 1", "+ for s in S:", "+ t += s * x", "+ t %= 2019", "+ if t in a:", "+ a[t] += 1", "+ else:", "+ a[t] = 1", "+ x *= 10", "+ x %= 2019", "- for _, v in list(t.items()):", "+ for v in list(a.values()):" ]
false
0.041048
0.077376
0.530495
[ "s107258444", "s748572049" ]
u057109575
p02761
python
s751251247
s190115737
166
75
38,256
61,972
Accepted
Accepted
54.82
from collections import defaultdict N, M = list(map(int, input().split())) SC = [list(map(int, input().split())) for _ in range(M)] d = defaultdict(list) for s, c in SC: d[s].append(c) if any(len(set(v)) > 1 for v in list(d.values())): print((-1)) elif d[1] == [0] and N > 1: print((-1)) elif N == 1 and M == 0: print((0)) else: ans = [0] * N ans[0] = 1 for i in range(N): if d[i + 1]: ans[i] = d[i + 1].pop() print(("".join(list(map(str, ans)))))
N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] cand = [-1] * N flag = False for s, c in X: s -= 1 if cand[s] == -1: cand[s] = c elif cand[s] != c: flag = True if flag or (N > 1 and cand[0] == 0): print((-1)) else: ans = 0 for i in range(N): if cand[i] == -1: if i == 0 and N > 1: cand[i] = 1 else: cand[i] = 0 ans += cand[i] * 10 ** (N - i - 1) print(ans)
24
25
520
539
from collections import defaultdict N, M = list(map(int, input().split())) SC = [list(map(int, input().split())) for _ in range(M)] d = defaultdict(list) for s, c in SC: d[s].append(c) if any(len(set(v)) > 1 for v in list(d.values())): print((-1)) elif d[1] == [0] and N > 1: print((-1)) elif N == 1 and M == 0: print((0)) else: ans = [0] * N ans[0] = 1 for i in range(N): if d[i + 1]: ans[i] = d[i + 1].pop() print(("".join(list(map(str, ans)))))
N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] cand = [-1] * N flag = False for s, c in X: s -= 1 if cand[s] == -1: cand[s] = c elif cand[s] != c: flag = True if flag or (N > 1 and cand[0] == 0): print((-1)) else: ans = 0 for i in range(N): if cand[i] == -1: if i == 0 and N > 1: cand[i] = 1 else: cand[i] = 0 ans += cand[i] * 10 ** (N - i - 1) print(ans)
false
4
[ "-from collections import defaultdict", "-", "-SC = [list(map(int, input().split())) for _ in range(M)]", "-d = defaultdict(list)", "-for s, c in SC:", "- d[s].append(c)", "-if any(len(set(v)) > 1 for v in list(d.values())):", "+X = [list(map(int, input().split())) for _ in range(M)]", "+cand = [-1] * N", "+flag = False", "+for s, c in X:", "+ s -= 1", "+ if cand[s] == -1:", "+ cand[s] = c", "+ elif cand[s] != c:", "+ flag = True", "+if flag or (N > 1 and cand[0] == 0):", "-elif d[1] == [0] and N > 1:", "- print((-1))", "-elif N == 1 and M == 0:", "- print((0))", "- ans = [0] * N", "- ans[0] = 1", "+ ans = 0", "- if d[i + 1]:", "- ans[i] = d[i + 1].pop()", "- print((\"\".join(list(map(str, ans)))))", "+ if cand[i] == -1:", "+ if i == 0 and N > 1:", "+ cand[i] = 1", "+ else:", "+ cand[i] = 0", "+ ans += cand[i] * 10 ** (N - i - 1)", "+ print(ans)" ]
false
0.057666
0.102006
0.56532
[ "s751251247", "s190115737" ]
u392319141
p03425
python
s551543023
s832509452
171
50
3,064
3,316
Accepted
Accepted
70.76
N = int(eval(input())) count = { 'M' : 0, 'A' : 0, 'R' : 0, 'C' : 0, 'H' : 0, } for _ in range(N): s = eval(input()) if s[0] in count: count[s[0]] += 1 ans = 0 count = list(count.items()) for i in range(len(count)): for j in range(i + 1, len(count)): for k in range(j + 1, len(count)): ans += count[i][1] * count[j][1] * count[k][1] print(ans)
from itertools import combinations from collections import defaultdict import sys input = sys.stdin.readline N = int(eval(input())) cnt = defaultdict(int) for _ in range(N): s = eval(input()) cnt[s[0]] += 1 ans = 0 for h in combinations(['M', 'A', 'R', 'C', 'H'], r=3): prd = 1 for s in h: prd *= cnt[s] ans += prd print(ans)
23
18
417
361
N = int(eval(input())) count = { "M": 0, "A": 0, "R": 0, "C": 0, "H": 0, } for _ in range(N): s = eval(input()) if s[0] in count: count[s[0]] += 1 ans = 0 count = list(count.items()) for i in range(len(count)): for j in range(i + 1, len(count)): for k in range(j + 1, len(count)): ans += count[i][1] * count[j][1] * count[k][1] print(ans)
from itertools import combinations from collections import defaultdict import sys input = sys.stdin.readline N = int(eval(input())) cnt = defaultdict(int) for _ in range(N): s = eval(input()) cnt[s[0]] += 1 ans = 0 for h in combinations(["M", "A", "R", "C", "H"], r=3): prd = 1 for s in h: prd *= cnt[s] ans += prd print(ans)
false
21.73913
[ "+from itertools import combinations", "+from collections import defaultdict", "+import sys", "+", "+input = sys.stdin.readline", "-count = {", "- \"M\": 0,", "- \"A\": 0,", "- \"R\": 0,", "- \"C\": 0,", "- \"H\": 0,", "-}", "+cnt = defaultdict(int)", "- if s[0] in count:", "- count[s[0]] += 1", "+ cnt[s[0]] += 1", "-count = list(count.items())", "-for i in range(len(count)):", "- for j in range(i + 1, len(count)):", "- for k in range(j + 1, len(count)):", "- ans += count[i][1] * count[j][1] * count[k][1]", "+for h in combinations([\"M\", \"A\", \"R\", \"C\", \"H\"], r=3):", "+ prd = 1", "+ for s in h:", "+ prd *= cnt[s]", "+ ans += prd" ]
false
0.039439
0.037393
1.054709
[ "s551543023", "s832509452" ]
u952467214
p03160
python
s105517406
s176654846
132
122
13,708
13,928
Accepted
Accepted
7.58
N = int(eval(input())) h = [int(i) for i in input().split()] dp = [0]*N dp[1] = abs(h[1] - h[0]) for i in range(N-2): dp[i+2]=min(dp[i+1]+ abs(h[i+2]-h[i+1]), dp[i]+ abs(h[i+2]-h[i])) print((dp[N-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0]*n dp[1] = abs(h[0]-h[1]) for i in range(2,n): dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2])) print((dp[-1]))
9
10
204
205
N = int(eval(input())) h = [int(i) for i in input().split()] dp = [0] * N dp[1] = abs(h[1] - h[0]) for i in range(N - 2): dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i])) print((dp[N - 1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[1] = abs(h[0] - h[1]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
false
10
[ "-N = int(eval(input()))", "-h = [int(i) for i in input().split()]", "-dp = [0] * N", "-dp[1] = abs(h[1] - h[0])", "-for i in range(N - 2):", "- dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))", "-print((dp[N - 1]))", "+n = int(eval(input()))", "+h = list(map(int, input().split()))", "+dp = [0] * n", "+dp[1] = abs(h[0] - h[1])", "+for i in range(2, n):", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))", "+print((dp[-1]))" ]
false
0.039278
0.048109
0.816438
[ "s105517406", "s176654846" ]