user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u844789719
p03222
python
s770210029
s429489179
64
23
3,064
3,436
Accepted
Accepted
64.06
H, W, K = [int(_) for _ in input().split()] if W == 1: print((1)) else: def fib(j): if j == 0 or j == 1: return 1 else: count = 0 for num in range(2 ** (j - 1)): bit = str(bin(num)) flag = 1 for i in range(2, len(bit) - 1): if bit[i] == '1' and bit[i + 1] == '1': flag = 0 count += flag return count dp = [[1] + [0] * (W - 1)] for j in range(1, H + 1): dp.append([0] * W) for i in range(W): if i == 0: dp[j][i] = (dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2)) % 1000000007 elif i == W - 1: dp[j][i] = (dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1)) % 1000000007 else: dp[j][i] = (dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2) + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1)) % 1000000007 print((dp[H][K - 1]))
import collections cd = collections.defaultdict memo = cd(lambda: cd(int)) memo[0][1] = 1 H, W, K = [int(_) for _ in input().split()] mod = 10**9 + 7 fib = [1, 1, 2, 3, 5, 8, 13, 21] + [1] * 8 def count(h, w): if memo[h][w]: return memo[h][w] elif h == 0 or w == 0 or w == W + 1: return 0 else: ret = count(h - 1, w) * fib[w - 1] * fib[W - w] ret += count(h - 1, w - 1) * fib[w - 2] * fib[W - w] ret += count(h - 1, w + 1) * fib[w - 1] * fib[W - w - 1] ret %= mod memo[h][w] = ret return ret print((count(H, K)))
29
26
1,146
618
H, W, K = [int(_) for _ in input().split()] if W == 1: print((1)) else: def fib(j): if j == 0 or j == 1: return 1 else: count = 0 for num in range(2 ** (j - 1)): bit = str(bin(num)) flag = 1 for i in range(2, len(bit) - 1): if bit[i] == "1" and bit[i + 1] == "1": flag = 0 count += flag return count dp = [[1] + [0] * (W - 1)] for j in range(1, H + 1): dp.append([0] * W) for i in range(W): if i == 0: dp[j][i] = ( dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2) ) % 1000000007 elif i == W - 1: dp[j][i] = ( dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1) ) % 1000000007 else: dp[j][i] = ( dp[j - 1][i] * fib(i) * fib(W - i - 1) + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2) + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1) ) % 1000000007 print((dp[H][K - 1]))
import collections cd = collections.defaultdict memo = cd(lambda: cd(int)) memo[0][1] = 1 H, W, K = [int(_) for _ in input().split()] mod = 10**9 + 7 fib = [1, 1, 2, 3, 5, 8, 13, 21] + [1] * 8 def count(h, w): if memo[h][w]: return memo[h][w] elif h == 0 or w == 0 or w == W + 1: return 0 else: ret = count(h - 1, w) * fib[w - 1] * fib[W - w] ret += count(h - 1, w - 1) * fib[w - 2] * fib[W - w] ret += count(h - 1, w + 1) * fib[w - 1] * fib[W - w - 1] ret %= mod memo[h][w] = ret return ret print((count(H, K)))
false
10.344828
[ "+import collections", "+", "+cd = collections.defaultdict", "+memo = cd(lambda: cd(int))", "+memo[0][1] = 1", "-if W == 1:", "- print((1))", "-else:", "+mod = 10**9 + 7", "+fib = [1, 1, 2, 3, 5, 8, 13, 21] + [1] * 8", "- def fib(j):", "- if j == 0 or j == 1:", "- return 1", "- else:", "- count = 0", "- for num in range(2 ** (j - 1)):", "- bit = str(bin(num))", "- flag = 1", "- for i in range(2, len(bit) - 1):", "- if bit[i] == \"1\" and bit[i + 1] == \"1\":", "- flag = 0", "- count += flag", "- return count", "- dp = [[1] + [0] * (W - 1)]", "- for j in range(1, H + 1):", "- dp.append([0] * W)", "- for i in range(W):", "- if i == 0:", "- dp[j][i] = (", "- dp[j - 1][i] * fib(i) * fib(W - i - 1)", "- + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2)", "- ) % 1000000007", "- elif i == W - 1:", "- dp[j][i] = (", "- dp[j - 1][i] * fib(i) * fib(W - i - 1)", "- + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1)", "- ) % 1000000007", "- else:", "- dp[j][i] = (", "- dp[j - 1][i] * fib(i) * fib(W - i - 1)", "- + dp[j - 1][i + 1] * fib(i) * fib(W - i - 2)", "- + dp[j - 1][i - 1] * fib(i - 1) * fib(W - i - 1)", "- ) % 1000000007", "- print((dp[H][K - 1]))", "+def count(h, w):", "+ if memo[h][w]:", "+ return memo[h][w]", "+ elif h == 0 or w == 0 or w == W + 1:", "+ return 0", "+ else:", "+ ret = count(h - 1, w) * fib[w - 1] * fib[W - w]", "+ ret += count(h - 1, w - 1) * fib[w - 2] * fib[W - w]", "+ ret += count(h - 1, w + 1) * fib[w - 1] * fib[W - w - 1]", "+ ret %= mod", "+ memo[h][w] = ret", "+ return ret", "+", "+", "+print((count(H, K)))" ]
false
0.041157
0.036665
1.122493
[ "s770210029", "s429489179" ]
u504836877
p03665
python
s779457236
s962521016
19
17
3,064
3,064
Accepted
Accepted
10.53
N,P = list(map(int, input().split())) A = [int(a) for a in input().split()] even = 0 odd = 0 for a in A: if a%2 == 0: even += 1 else: odd += 1 L = [1]*(N+1) for i in range(N): L[i+1] = L[i]*(i+1) def cmb(n, r): return L[n]//L[r]//L[n-r] ans = pow(2, N) for i in range(1, odd+1, 2): ans -= cmb(odd, i)*pow(2, even) if P == 1: ans = pow(2, N) - ans print(ans)
N,P = list(map(int, input().split())) A = [int(a) for a in input().split()] even = 0 odd = 0 for a in A: if a%2 == 0: even += 1 else: odd += 1 if odd == 0: if P == 0: ans = pow(2, N) else: ans = 0 else: ans = pow(2, N-1) print(ans)
25
20
428
299
N, P = list(map(int, input().split())) A = [int(a) for a in input().split()] even = 0 odd = 0 for a in A: if a % 2 == 0: even += 1 else: odd += 1 L = [1] * (N + 1) for i in range(N): L[i + 1] = L[i] * (i + 1) def cmb(n, r): return L[n] // L[r] // L[n - r] ans = pow(2, N) for i in range(1, odd + 1, 2): ans -= cmb(odd, i) * pow(2, even) if P == 1: ans = pow(2, N) - ans print(ans)
N, P = list(map(int, input().split())) A = [int(a) for a in input().split()] even = 0 odd = 0 for a in A: if a % 2 == 0: even += 1 else: odd += 1 if odd == 0: if P == 0: ans = pow(2, N) else: ans = 0 else: ans = pow(2, N - 1) print(ans)
false
20
[ "-L = [1] * (N + 1)", "-for i in range(N):", "- L[i + 1] = L[i] * (i + 1)", "-", "-", "-def cmb(n, r):", "- return L[n] // L[r] // L[n - r]", "-", "-", "-ans = pow(2, N)", "-for i in range(1, odd + 1, 2):", "- ans -= cmb(odd, i) * pow(2, even)", "-if P == 1:", "- ans = pow(2, N) - ans", "+if odd == 0:", "+ if P == 0:", "+ ans = pow(2, N)", "+ else:", "+ ans = 0", "+else:", "+ ans = pow(2, N - 1)" ]
false
0.125427
0.045267
2.770831
[ "s779457236", "s962521016" ]
u078349616
p03231
python
s596863727
s761389595
100
39
22,836
5,344
Accepted
Accepted
61
from collections import defaultdict from fractions import gcd N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = N * M // gcd(N, M) ds = L // N dt = L // M dict_s = defaultdict(str) dict_t = defaultdict(str) for i in range(N): dict_s[i*ds] = S[i] for i in range(M): dict_t[i*dt] = T[i] for key in list(dict_s.keys()): if key in list(dict_t.keys()): if dict_s[key] != dict_t[key]: print((-1)) exit() print(L)
from fractions import gcd N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = gcd(N, M) lcm = N * M // g for i in range(g): if S[i*N//g] != T[i*M//g]: print((-1)) exit() print(lcm)
23
11
452
207
from collections import defaultdict from fractions import gcd N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = N * M // gcd(N, M) ds = L // N dt = L // M dict_s = defaultdict(str) dict_t = defaultdict(str) for i in range(N): dict_s[i * ds] = S[i] for i in range(M): dict_t[i * dt] = T[i] for key in list(dict_s.keys()): if key in list(dict_t.keys()): if dict_s[key] != dict_t[key]: print((-1)) exit() print(L)
from fractions import gcd N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = gcd(N, M) lcm = N * M // g for i in range(g): if S[i * N // g] != T[i * M // g]: print((-1)) exit() print(lcm)
false
52.173913
[ "-from collections import defaultdict", "-L = N * M // gcd(N, M)", "-ds = L // N", "-dt = L // M", "-dict_s = defaultdict(str)", "-dict_t = defaultdict(str)", "-for i in range(N):", "- dict_s[i * ds] = S[i]", "-for i in range(M):", "- dict_t[i * dt] = T[i]", "-for key in list(dict_s.keys()):", "- if key in list(dict_t.keys()):", "- if dict_s[key] != dict_t[key]:", "- print((-1))", "- exit()", "-print(L)", "+g = gcd(N, M)", "+lcm = N * M // g", "+for i in range(g):", "+ if S[i * N // g] != T[i * M // g]:", "+ print((-1))", "+ exit()", "+print(lcm)" ]
false
0.051558
0.15991
0.322421
[ "s596863727", "s761389595" ]
u453055089
p02707
python
s553724317
s685841957
201
151
109,864
92,436
Accepted
Accepted
24.88
from collections import Counter, deque n = int(eval(input())) a = deque(list(map(int, input().split()))) c = Counter(a) for i in range(1, n+1): if i in list(c.keys()): print((c[i])) else: print((0))
n = int(eval(input())) a = list(map(int, input().split())) buka = [0]*n for i in range(n-1): buka[a[i]-1] += 1 for i in range(n): print((buka[i]))
9
7
215
152
from collections import Counter, deque n = int(eval(input())) a = deque(list(map(int, input().split()))) c = Counter(a) for i in range(1, n + 1): if i in list(c.keys()): print((c[i])) else: print((0))
n = int(eval(input())) a = list(map(int, input().split())) buka = [0] * n for i in range(n - 1): buka[a[i] - 1] += 1 for i in range(n): print((buka[i]))
false
22.222222
[ "-from collections import Counter, deque", "-", "-a = deque(list(map(int, input().split())))", "-c = Counter(a)", "-for i in range(1, n + 1):", "- if i in list(c.keys()):", "- print((c[i]))", "- else:", "- print((0))", "+a = list(map(int, input().split()))", "+buka = [0] * n", "+for i in range(n - 1):", "+ buka[a[i] - 1] += 1", "+for i in range(n):", "+ print((buka[i]))" ]
false
0.043861
0.047068
0.931862
[ "s553724317", "s685841957" ]
u729133443
p02995
python
s756959125
s051685019
275
35
63,980
5,048
Accepted
Accepted
87.27
from fractions import* a,b,c,d=list(map(int,input().split())) a-=1 e=c*d//gcd(c,d) print((b-a-b//c+a//c-b//d+a//d+b//e-a//e))
from fractions import* a,b,c,d=list(map(int,input().split())) f=lambda x:x-x//c-x//d+x//(c*d//gcd(c,d)) print((f(b)-f(a-1)))
5
4
121
119
from fractions import * a, b, c, d = list(map(int, input().split())) a -= 1 e = c * d // gcd(c, d) print((b - a - b // c + a // c - b // d + a // d + b // e - a // e))
from fractions import * a, b, c, d = list(map(int, input().split())) f = lambda x: x - x // c - x // d + x // (c * d // gcd(c, d)) print((f(b) - f(a - 1)))
false
20
[ "-a -= 1", "-e = c * d // gcd(c, d)", "-print((b - a - b // c + a // c - b // d + a // d + b // e - a // e))", "+f = lambda x: x - x // c - x // d + x // (c * d // gcd(c, d))", "+print((f(b) - f(a - 1)))" ]
false
0.107852
0.043416
2.48418
[ "s756959125", "s051685019" ]
u272075541
p02820
python
s324442913
s188031901
85
53
14,776
4,408
Accepted
Accepted
37.65
# -*- coding: utf-8 -*- ################ DANGER ################ test = "" #test = \ """ 5 2 8 7 6 rsrpr ans 27 """ """ 7 1 100 10 1 ssssppr ans 211 """ """ 30 5 325 234 123 rspsspspsrpspsppprpsprpssprpsr ans 4996 """ ######################################## test = list(reversed(test.strip().splitlines())) if test: def input2(): return test.pop() else: def input2(): return eval(input()) ######################################## n, k = list(map(int, input2().split())) r, s, p = list(map(int, input2().split())) t = list(input2()) rsp = {"r", "s", "p"} for i in range(k, n-1): if t[i] == t[i-k]: t[i] = rsp - {t[i], t[i+1]} if t[n-1] == t[n-1-k]: t[n-1] = rsp - {t[n-1]} ans = (t.count("r") * p + t.count("s") * r + t.count("p") * s) print(ans)
from array import array n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = array("u", list(eval(input()))) for i in range(k, n-1): if t[i] == t[i-k]: t[i] = "*" if t[n-1] == t[n-1-k]: t[n-1] = "*" ans = (t.count("r") * p + t.count("s") * r + t.count("p") * s) print(ans)
54
17
864
344
# -*- coding: utf-8 -*- ################ DANGER ################ test = "" # test = \ """ 5 2 8 7 6 rsrpr ans 27 """ """ 7 1 100 10 1 ssssppr ans 211 """ """ 30 5 325 234 123 rspsspspsrpspsppprpsprpssprpsr ans 4996 """ ######################################## test = list(reversed(test.strip().splitlines())) if test: def input2(): return test.pop() else: def input2(): return eval(input()) ######################################## n, k = list(map(int, input2().split())) r, s, p = list(map(int, input2().split())) t = list(input2()) rsp = {"r", "s", "p"} for i in range(k, n - 1): if t[i] == t[i - k]: t[i] = rsp - {t[i], t[i + 1]} if t[n - 1] == t[n - 1 - k]: t[n - 1] = rsp - {t[n - 1]} ans = t.count("r") * p + t.count("s") * r + t.count("p") * s print(ans)
from array import array n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = array("u", list(eval(input()))) for i in range(k, n - 1): if t[i] == t[i - k]: t[i] = "*" if t[n - 1] == t[n - 1 - k]: t[n - 1] = "*" ans = t.count("r") * p + t.count("s") * r + t.count("p") * s print(ans)
false
68.518519
[ "-# -*- coding: utf-8 -*-", "-################ DANGER ################", "-test = \"\"", "-# test = \\", "-\"\"\"", "-5 2", "-8 7 6", "-rsrpr", "-ans 27", "-\"\"\"", "-\"\"\"", "-7 1", "-100 10 1", "-ssssppr", "-ans 211", "-\"\"\"", "-\"\"\"", "-30 5", "-325 234 123", "-rspsspspsrpspsppprpsprpssprpsr", "-ans 4996", "-\"\"\"", "-########################################", "-test = list(reversed(test.strip().splitlines()))", "-if test:", "+from array import array", "- def input2():", "- return test.pop()", "-", "-else:", "-", "- def input2():", "- return eval(input())", "-", "-", "-########################################", "-n, k = list(map(int, input2().split()))", "-r, s, p = list(map(int, input2().split()))", "-t = list(input2())", "-rsp = {\"r\", \"s\", \"p\"}", "+n, k = list(map(int, input().split()))", "+r, s, p = list(map(int, input().split()))", "+t = array(\"u\", list(eval(input())))", "- t[i] = rsp - {t[i], t[i + 1]}", "+ t[i] = \"*\"", "- t[n - 1] = rsp - {t[n - 1]}", "+ t[n - 1] = \"*\"" ]
false
0.034091
0.090086
0.378425
[ "s324442913", "s188031901" ]
u680851063
p03111
python
s929255017
s898869339
311
262
14,836
3,188
Accepted
Accepted
15.76
# DFS, パターン列挙_各竹の使用パターンを列挙 n, a, b, c = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] stack = [[0],[1],[2],[-1]] # 初期化_ここでは竹の使用パターン4つを設置 ptns = [] # パターン候補の器_初期化 while stack: # stackが空になるまでループ tmp = stack.pop() # パターンの候補を pop if len(tmp) == n: # 条件に合えば append ptns.append(tmp) elif len(tmp) < n: # 条件に合わなければ... w = tmp + [0] # パターンの候補を作成して... x = tmp + [1] # 〃 y = tmp + [2] # 〃 z = tmp + [-1] stack += [w, x, y, z] # 積む ans = 10**9 for i in range(len(ptns)): if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]: continue abc = [0, 0, 0, -30] for j in range(n): tmp = ptns[i][j] if tmp >= 0: abc[tmp] += l[j] abc[3] += 10 mp = abc[3] mp += abs(abc[0] - a) mp += abs(abc[1] - b) mp += abs(abc[2] - c) ans = min(ans, mp) print(ans)
# DFS, パターン列挙_各竹の使用パターンを列挙 n, a, b, c = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] stack = [[0],[1],[2],[-1]] ans = 10**9 while stack: tmp = stack.pop() if len(tmp) == n: if 0 not in tmp or 1 not in tmp or 2 not in tmp: continue abc = [0, 0, 0, -30] for j in range(n): if tmp[j] >= 0: abc[tmp[j]] += l[j] abc[3] += 10 mp = abc[3] mp += abs(abc[0] - a) mp += abs(abc[1] - b) mp += abs(abc[2] - c) ans = min(ans, mp) elif len(tmp) < n: w = tmp + [0] x = tmp + [1] y = tmp + [2] z = tmp + [-1] stack += [w, x, y, z] print(ans)
36
32
937
752
# DFS, パターン列挙_各竹の使用パターンを列挙 n, a, b, c = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] stack = [[0], [1], [2], [-1]] # 初期化_ここでは竹の使用パターン4つを設置 ptns = [] # パターン候補の器_初期化 while stack: # stackが空になるまでループ tmp = stack.pop() # パターンの候補を pop if len(tmp) == n: # 条件に合えば append ptns.append(tmp) elif len(tmp) < n: # 条件に合わなければ... w = tmp + [0] # パターンの候補を作成して... x = tmp + [1] # 〃 y = tmp + [2] # 〃 z = tmp + [-1] stack += [w, x, y, z] # 積む ans = 10**9 for i in range(len(ptns)): if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]: continue abc = [0, 0, 0, -30] for j in range(n): tmp = ptns[i][j] if tmp >= 0: abc[tmp] += l[j] abc[3] += 10 mp = abc[3] mp += abs(abc[0] - a) mp += abs(abc[1] - b) mp += abs(abc[2] - c) ans = min(ans, mp) print(ans)
# DFS, パターン列挙_各竹の使用パターンを列挙 n, a, b, c = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] stack = [[0], [1], [2], [-1]] ans = 10**9 while stack: tmp = stack.pop() if len(tmp) == n: if 0 not in tmp or 1 not in tmp or 2 not in tmp: continue abc = [0, 0, 0, -30] for j in range(n): if tmp[j] >= 0: abc[tmp[j]] += l[j] abc[3] += 10 mp = abc[3] mp += abs(abc[0] - a) mp += abs(abc[1] - b) mp += abs(abc[2] - c) ans = min(ans, mp) elif len(tmp) < n: w = tmp + [0] x = tmp + [1] y = tmp + [2] z = tmp + [-1] stack += [w, x, y, z] print(ans)
false
11.111111
[ "-stack = [[0], [1], [2], [-1]] # 初期化_ここでは竹の使用パターン4つを設置", "-ptns = [] # パターン候補の器_初期化", "-while stack: # stackが空になるまでループ", "- tmp = stack.pop() # パターンの候補を pop", "- if len(tmp) == n: # 条件に合えば append", "- ptns.append(tmp)", "- elif len(tmp) < n: # 条件に合わなければ...", "- w = tmp + [0] # パターンの候補を作成して...", "- x = tmp + [1] # 〃", "- y = tmp + [2] # 〃", "+stack = [[0], [1], [2], [-1]]", "+ans = 10**9", "+while stack:", "+ tmp = stack.pop()", "+ if len(tmp) == n:", "+ if 0 not in tmp or 1 not in tmp or 2 not in tmp:", "+ continue", "+ abc = [0, 0, 0, -30]", "+ for j in range(n):", "+ if tmp[j] >= 0:", "+ abc[tmp[j]] += l[j]", "+ abc[3] += 10", "+ mp = abc[3]", "+ mp += abs(abc[0] - a)", "+ mp += abs(abc[1] - b)", "+ mp += abs(abc[2] - c)", "+ ans = min(ans, mp)", "+ elif len(tmp) < n:", "+ w = tmp + [0]", "+ x = tmp + [1]", "+ y = tmp + [2]", "- stack += [w, x, y, z] # 積む", "-ans = 10**9", "-for i in range(len(ptns)):", "- if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:", "- continue", "- abc = [0, 0, 0, -30]", "- for j in range(n):", "- tmp = ptns[i][j]", "- if tmp >= 0:", "- abc[tmp] += l[j]", "- abc[3] += 10", "- mp = abc[3]", "- mp += abs(abc[0] - a)", "- mp += abs(abc[1] - b)", "- mp += abs(abc[2] - c)", "- ans = min(ans, mp)", "+ stack += [w, x, y, z]" ]
false
0.187274
0.28577
0.65533
[ "s929255017", "s898869339" ]
u934442292
p02623
python
s862954682
s537945821
912
707
42,468
42,208
Accepted
Accepted
22.48
import sys from itertools import accumulate input = sys.stdin.readline def is_ok(a, key, idx): if a[idx] <= key: return True else: return False def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(a, key, mid): ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
50
43
919
808
import sys from itertools import accumulate input = sys.stdin.readline def is_ok(a, key, idx): if a[idx] <= key: return True else: return False def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(a, key, mid): ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
false
14
[ "-", "-", "-def is_ok(a, key, idx):", "- if a[idx] <= key:", "- return True", "- else:", "- return False", "- if is_ok(a, key, mid):", "+ if a[mid] <= key:" ]
false
0.043606
0.043719
0.997428
[ "s862954682", "s537945821" ]
u060736237
p03262
python
s996866868
s340302386
105
95
16,280
16,240
Accepted
Accepted
9.52
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) z = list([abs(X - i) for i in x]) ans = z[0] for i in range(1, N): ans = gcd(ans, z[i]) print(ans)
from fractions import gcd n, X = list(map(int, input().split())) x = list(map(int, input().split())) ans = abs(x[0]-X) for el in x[1:]: ans = gcd(ans, abs(el - X)) print(ans)
9
7
208
179
from fractions import gcd N, X = list(map(int, input().split())) x = list(map(int, input().split())) z = list([abs(X - i) for i in x]) ans = z[0] for i in range(1, N): ans = gcd(ans, z[i]) print(ans)
from fractions import gcd n, X = list(map(int, input().split())) x = list(map(int, input().split())) ans = abs(x[0] - X) for el in x[1:]: ans = gcd(ans, abs(el - X)) print(ans)
false
22.222222
[ "-N, X = list(map(int, input().split()))", "+n, X = list(map(int, input().split()))", "-z = list([abs(X - i) for i in x])", "-ans = z[0]", "-for i in range(1, N):", "- ans = gcd(ans, z[i])", "+ans = abs(x[0] - X)", "+for el in x[1:]:", "+ ans = gcd(ans, abs(el - X))" ]
false
0.050593
0.049373
1.024727
[ "s996866868", "s340302386" ]
u898967808
p02844
python
s950325037
s203116985
22
20
3,060
3,188
Accepted
Accepted
9.09
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = '{:03d}'.format(i) p1 = s.find(pin[0]) if p1>=0: p2 = s[p1+1:].find(pin[1]) if p2>=0: p3 = s[p1+p2+2:].find(pin[2]) if p3>=0: ans+=1 print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = '{:03d}'.format(i) p1 = s.find(pin[0]) if p1>=0: p2 = s.find(pin[1],p1+1) if p2>=0: p3 = s.find(pin[2],p2+1) if p3>=0: ans+=1 print(ans)
15
15
285
278
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = "{:03d}".format(i) p1 = s.find(pin[0]) if p1 >= 0: p2 = s[p1 + 1 :].find(pin[1]) if p2 >= 0: p3 = s[p1 + p2 + 2 :].find(pin[2]) if p3 >= 0: ans += 1 print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = "{:03d}".format(i) p1 = s.find(pin[0]) if p1 >= 0: p2 = s.find(pin[1], p1 + 1) if p2 >= 0: p3 = s.find(pin[2], p2 + 1) if p3 >= 0: ans += 1 print(ans)
false
0
[ "- p2 = s[p1 + 1 :].find(pin[1])", "+ p2 = s.find(pin[1], p1 + 1)", "- p3 = s[p1 + p2 + 2 :].find(pin[2])", "+ p3 = s.find(pin[2], p2 + 1)" ]
false
0.039281
0.042089
0.933266
[ "s950325037", "s203116985" ]
u183422236
p02696
python
s984821522
s433965452
22
19
9,164
9,104
Accepted
Accepted
13.64
a, b, n = list(map(int, input().split())) n = min(n, b-1) print((int((a * n) / b) - a * int(n / b)))
a, b, n = list(map(int, input().split())) syou = n // b if syou >= 1: n = b * 1 - 1 print((int((a * n) / b) - a * int(n / b)))
4
6
96
129
a, b, n = list(map(int, input().split())) n = min(n, b - 1) print((int((a * n) / b) - a * int(n / b)))
a, b, n = list(map(int, input().split())) syou = n // b if syou >= 1: n = b * 1 - 1 print((int((a * n) / b) - a * int(n / b)))
false
33.333333
[ "-n = min(n, b - 1)", "+syou = n // b", "+if syou >= 1:", "+ n = b * 1 - 1" ]
false
0.048438
0.047766
1.014069
[ "s984821522", "s433965452" ]
u598229387
p03162
python
s399079171
s370887533
890
562
24,308
47,008
Accepted
Accepted
36.85
n=int(eval(input())) abc=[[int(i) for i in input().split()] for j in range(n)] dp=[[abc[0][0],abc[0][1],abc[0][2]],[abc[0][0],abc[0][1],abc[0][2]]] for i in range(1,n): for j in range(3): for k in range(3): if j!=k: dp[1][k]=max(dp[1][k] ,dp[0][j]+abc[i][k]) dp[0][0]=dp[1][0] dp[0][1]=dp[1][1] dp[0][2]=dp[1][2] print((max(dp[1])))
n=int(eval(input())) abc=[[int(i) for i in input().split()] for j in range(n)] dp=[[0 for i in range(3)] for j in range(n+1)] for i in range(3): dp[1][i]=abc[0][i] for i in range(1,n): dp[i+1][0]=max(dp[i][1],dp[i][2])+abc[i][0] dp[i+1][1]=max(dp[i][2],dp[i][0])+abc[i][1] dp[i+1][2]=max(dp[i][1],dp[i][0])+abc[i][2] print((max(dp[-1])))
13
14
390
374
n = int(eval(input())) abc = [[int(i) for i in input().split()] for j in range(n)] dp = [[abc[0][0], abc[0][1], abc[0][2]], [abc[0][0], abc[0][1], abc[0][2]]] for i in range(1, n): for j in range(3): for k in range(3): if j != k: dp[1][k] = max(dp[1][k], dp[0][j] + abc[i][k]) dp[0][0] = dp[1][0] dp[0][1] = dp[1][1] dp[0][2] = dp[1][2] print((max(dp[1])))
n = int(eval(input())) abc = [[int(i) for i in input().split()] for j in range(n)] dp = [[0 for i in range(3)] for j in range(n + 1)] for i in range(3): dp[1][i] = abc[0][i] for i in range(1, n): dp[i + 1][0] = max(dp[i][1], dp[i][2]) + abc[i][0] dp[i + 1][1] = max(dp[i][2], dp[i][0]) + abc[i][1] dp[i + 1][2] = max(dp[i][1], dp[i][0]) + abc[i][2] print((max(dp[-1])))
false
7.142857
[ "-dp = [[abc[0][0], abc[0][1], abc[0][2]], [abc[0][0], abc[0][1], abc[0][2]]]", "+dp = [[0 for i in range(3)] for j in range(n + 1)]", "+for i in range(3):", "+ dp[1][i] = abc[0][i]", "- for j in range(3):", "- for k in range(3):", "- if j != k:", "- dp[1][k] = max(dp[1][k], dp[0][j] + abc[i][k])", "- dp[0][0] = dp[1][0]", "- dp[0][1] = dp[1][1]", "- dp[0][2] = dp[1][2]", "-print((max(dp[1])))", "+ dp[i + 1][0] = max(dp[i][1], dp[i][2]) + abc[i][0]", "+ dp[i + 1][1] = max(dp[i][2], dp[i][0]) + abc[i][1]", "+ dp[i + 1][2] = max(dp[i][1], dp[i][0]) + abc[i][2]", "+print((max(dp[-1])))" ]
false
0.048184
0.043369
1.111018
[ "s399079171", "s370887533" ]
u867826040
p02837
python
s870269222
s058544948
223
178
9,160
9,136
Accepted
Accepted
20.18
n = int(eval(input())) v = [[tuple(map(int, input().split()))for i in range(int(eval(input())))] for i in range(n)] ans = 0 for i in range(2**n): f = [0] * n xy = [] for j in range(n): if (i >> j) & 1: f[j] = 1 xy.append(v[j]) flag = True for xyi in xy: for x, y in xyi: #print(f,x,y,bin(i)) if (i>>(x-1))&1 != y: flag = False break if flag: ans = max(ans, len(xy)) print(ans)
n = int(eval(input())) v = [[tuple(map(int, input().split()))for i in range(int(eval(input())))] for i in range(n)] ans = 0 for i in range(2**n): f = True a = 0 for j in range(n): if (i >> j) & 1: if all(i >> (x - 1) & 1 == y for x, y in v[j]): a += 1 else: f = False break if f: ans = max(ans, a) print(ans)
22
18
520
424
n = int(eval(input())) v = [ [tuple(map(int, input().split())) for i in range(int(eval(input())))] for i in range(n) ] ans = 0 for i in range(2**n): f = [0] * n xy = [] for j in range(n): if (i >> j) & 1: f[j] = 1 xy.append(v[j]) flag = True for xyi in xy: for x, y in xyi: # print(f,x,y,bin(i)) if (i >> (x - 1)) & 1 != y: flag = False break if flag: ans = max(ans, len(xy)) print(ans)
n = int(eval(input())) v = [ [tuple(map(int, input().split())) for i in range(int(eval(input())))] for i in range(n) ] ans = 0 for i in range(2**n): f = True a = 0 for j in range(n): if (i >> j) & 1: if all(i >> (x - 1) & 1 == y for x, y in v[j]): a += 1 else: f = False break if f: ans = max(ans, a) print(ans)
false
18.181818
[ "- f = [0] * n", "- xy = []", "+ f = True", "+ a = 0", "- f[j] = 1", "- xy.append(v[j])", "- flag = True", "- for xyi in xy:", "- for x, y in xyi:", "- # print(f,x,y,bin(i))", "- if (i >> (x - 1)) & 1 != y:", "- flag = False", "+ if all(i >> (x - 1) & 1 == y for x, y in v[j]):", "+ a += 1", "+ else:", "+ f = False", "- if flag:", "- ans = max(ans, len(xy))", "+ if f:", "+ ans = max(ans, a)" ]
false
0.044647
0.038402
1.162611
[ "s870269222", "s058544948" ]
u729133443
p03719
python
s276739478
s743725816
167
26
38,512
8,968
Accepted
Accepted
84.43
a,b,c=list(map(int,input().split()));print(('YNeos'[c<a or c>b::2]))
a,b,c=list(map(int,input().split())) print(('NYoe s'[a<=c<=b::2]))
1
2
60
59
a, b, c = list(map(int, input().split())) print(("YNeos"[c < a or c > b :: 2]))
a, b, c = list(map(int, input().split())) print(("NYoe s"[a <= c <= b :: 2]))
false
50
[ "-print((\"YNeos\"[c < a or c > b :: 2]))", "+print((\"NYoe s\"[a <= c <= b :: 2]))" ]
false
0.069938
0.035941
1.945902
[ "s276739478", "s743725816" ]
u401452016
p02947
python
s597690627
s012026851
351
227
19,760
19,760
Accepted
Accepted
35.33
from collections import Counter n = int(eval(input())) L = [''.join(sorted(eval(input()))) for i in range(n)] c = Counter(L) cnt = 0 for ele in list(c.values()): cnt += ele*(ele-1)/2 print((int(cnt)))
from collections import Counter import sys n = int(sys.stdin.readline()) L = [''.join(sorted(sys.stdin.readline().strip())) for _ in range(n)] ans = 0 L = Counter(L) for num in list(L.values()): ans += num*(num-1)//2 print(ans)
8
9
191
233
from collections import Counter n = int(eval(input())) L = ["".join(sorted(eval(input()))) for i in range(n)] c = Counter(L) cnt = 0 for ele in list(c.values()): cnt += ele * (ele - 1) / 2 print((int(cnt)))
from collections import Counter import sys n = int(sys.stdin.readline()) L = ["".join(sorted(sys.stdin.readline().strip())) for _ in range(n)] ans = 0 L = Counter(L) for num in list(L.values()): ans += num * (num - 1) // 2 print(ans)
false
11.111111
[ "+import sys", "-n = int(eval(input()))", "-L = [\"\".join(sorted(eval(input()))) for i in range(n)]", "-c = Counter(L)", "-cnt = 0", "-for ele in list(c.values()):", "- cnt += ele * (ele - 1) / 2", "-print((int(cnt)))", "+n = int(sys.stdin.readline())", "+L = [\"\".join(sorted(sys.stdin.readline().strip())) for _ in range(n)]", "+ans = 0", "+L = Counter(L)", "+for num in list(L.values()):", "+ ans += num * (num - 1) // 2", "+print(ans)" ]
false
0.036966
0.036861
1.002842
[ "s597690627", "s012026851" ]
u644516473
p02695
python
s630025896
s778887430
1,052
516
9,108
9,228
Accepted
Accepted
50.95
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for x in combinations_with_replacement(list(range(1, M+1)), N): point = 0 for a, b, c, d in abcd: if x[b-1] - x[a-1] == c: point += d if ans < point: ans = point print(ans)
from itertools import combinations_with_replacement def main(): N, M, Q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for x in combinations_with_replacement(list(range(1, M+1)), N): point = 0 for a, b, c, d in abcd: if x[b-1] - x[a-1] == c: point += d if ans < point: ans = point print(ans) if __name__ == '__main__': main()
12
16
373
472
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for x in combinations_with_replacement(list(range(1, M + 1)), N): point = 0 for a, b, c, d in abcd: if x[b - 1] - x[a - 1] == c: point += d if ans < point: ans = point print(ans)
from itertools import combinations_with_replacement def main(): N, M, Q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for x in combinations_with_replacement(list(range(1, M + 1)), N): point = 0 for a, b, c, d in abcd: if x[b - 1] - x[a - 1] == c: point += d if ans < point: ans = point print(ans) if __name__ == "__main__": main()
false
25
[ "-N, M, Q = list(map(int, input().split()))", "-abcd = [list(map(int, input().split())) for _ in range(Q)]", "-ans = 0", "-for x in combinations_with_replacement(list(range(1, M + 1)), N):", "- point = 0", "- for a, b, c, d in abcd:", "- if x[b - 1] - x[a - 1] == c:", "- point += d", "- if ans < point:", "- ans = point", "-print(ans)", "+", "+def main():", "+ N, M, Q = list(map(int, input().split()))", "+ abcd = [list(map(int, input().split())) for _ in range(Q)]", "+ ans = 0", "+ for x in combinations_with_replacement(list(range(1, M + 1)), N):", "+ point = 0", "+ for a, b, c, d in abcd:", "+ if x[b - 1] - x[a - 1] == c:", "+ point += d", "+ if ans < point:", "+ ans = point", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.040041
0.038165
1.049152
[ "s630025896", "s778887430" ]
u814986259
p03221
python
s816062512
s597650177
1,103
680
30,692
31,304
Accepted
Accepted
38.35
N,M=list(map(int,input().split())) PY=[[0,0,0] for i in range(M)] for i in range(M): P,Y=list(map(int,input().split())) PY[i]=[P,Y,i] PY.sort(key=lambda x:x[1]) PY.sort(key=lambda x:x[0]) prev=0 for i in range(M): if PY[i][0] != prev: count = 1 else: count+=1 prev=PY[i][0] ans=["0" for i in range(6 - len(str(prev)))] temp=["0" for i in range(6 - len(str(count)))] ans+=list(str(prev))+temp+list(str(count)) PY[i][0]="".join(ans) PY.sort(key=lambda x:x[2]) for i in range(M): print((PY[i][0]))
N, M = map(int, input().split()) PY = [tuple(list(map(int, input().split()))+[i]) for i in range(M)] PY.sort(key=lambda x: x[1]) ans = ['']*M P = [0]*N for p, y, i in PY: ret = '' p -= 1 P[p] += 1 ret += '{:0=6}'.format(p+1) ret += '{:0=6}'.format(P[p]) ans[i] = ret print(*ans, sep='\n')
21
13
529
325
N, M = list(map(int, input().split())) PY = [[0, 0, 0] for i in range(M)] for i in range(M): P, Y = list(map(int, input().split())) PY[i] = [P, Y, i] PY.sort(key=lambda x: x[1]) PY.sort(key=lambda x: x[0]) prev = 0 for i in range(M): if PY[i][0] != prev: count = 1 else: count += 1 prev = PY[i][0] ans = ["0" for i in range(6 - len(str(prev)))] temp = ["0" for i in range(6 - len(str(count)))] ans += list(str(prev)) + temp + list(str(count)) PY[i][0] = "".join(ans) PY.sort(key=lambda x: x[2]) for i in range(M): print((PY[i][0]))
N, M = map(int, input().split()) PY = [tuple(list(map(int, input().split())) + [i]) for i in range(M)] PY.sort(key=lambda x: x[1]) ans = [""] * M P = [0] * N for p, y, i in PY: ret = "" p -= 1 P[p] += 1 ret += "{:0=6}".format(p + 1) ret += "{:0=6}".format(P[p]) ans[i] = ret print(*ans, sep="\n")
false
38.095238
[ "-N, M = list(map(int, input().split()))", "-PY = [[0, 0, 0] for i in range(M)]", "-for i in range(M):", "- P, Y = list(map(int, input().split()))", "- PY[i] = [P, Y, i]", "+N, M = map(int, input().split())", "+PY = [tuple(list(map(int, input().split())) + [i]) for i in range(M)]", "-PY.sort(key=lambda x: x[0])", "-prev = 0", "-for i in range(M):", "- if PY[i][0] != prev:", "- count = 1", "- else:", "- count += 1", "- prev = PY[i][0]", "- ans = [\"0\" for i in range(6 - len(str(prev)))]", "- temp = [\"0\" for i in range(6 - len(str(count)))]", "- ans += list(str(prev)) + temp + list(str(count))", "- PY[i][0] = \"\".join(ans)", "-PY.sort(key=lambda x: x[2])", "-for i in range(M):", "- print((PY[i][0]))", "+ans = [\"\"] * M", "+P = [0] * N", "+for p, y, i in PY:", "+ ret = \"\"", "+ p -= 1", "+ P[p] += 1", "+ ret += \"{:0=6}\".format(p + 1)", "+ ret += \"{:0=6}\".format(P[p])", "+ ans[i] = ret", "+print(*ans, sep=\"\\n\")" ]
false
0.036719
0.035535
1.033295
[ "s816062512", "s597650177" ]
u163320134
p02727
python
s127769529
s660332146
729
245
48,816
22,504
Accepted
Accepted
66.39
import heapq x,y,a,b,c=list(map(int,input().split())) arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) arr3=list(map(int,input().split())) q=[] for val in arr1: heapq.heappush(q,(-val,1)) for val in arr2: heapq.heappush(q,(-val,2)) for val in arr3: heapq.heappush(q,(-val,3)) ans=0 cnt1=0 cnt2=0 cnt3=0 while cnt1+cnt2+cnt3<x+y: tmp,flag=heapq.heappop(q) tmp*=-1 if flag==1: if cnt1<x: ans+=tmp cnt1+=1 elif flag==2: if cnt2<y: ans+=tmp cnt2+=1 elif flag==3: ans+=tmp cnt3+=1 print(ans)
x,y,a,b,c=list(map(int,input().split())) arr1=list(map(int,input().split())) arr1=sorted(arr1,reverse=True) arr1=arr1[:x] arr2=list(map(int,input().split())) arr2=sorted(arr2,reverse=True) arr2=arr2[:y] arr3=list(map(int,input().split())) ans=arr1+arr2+arr3 ans=sorted(ans,reverse=True) print((sum(ans[:x+y])))
32
11
591
312
import heapq x, y, a, b, c = list(map(int, input().split())) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) arr3 = list(map(int, input().split())) q = [] for val in arr1: heapq.heappush(q, (-val, 1)) for val in arr2: heapq.heappush(q, (-val, 2)) for val in arr3: heapq.heappush(q, (-val, 3)) ans = 0 cnt1 = 0 cnt2 = 0 cnt3 = 0 while cnt1 + cnt2 + cnt3 < x + y: tmp, flag = heapq.heappop(q) tmp *= -1 if flag == 1: if cnt1 < x: ans += tmp cnt1 += 1 elif flag == 2: if cnt2 < y: ans += tmp cnt2 += 1 elif flag == 3: ans += tmp cnt3 += 1 print(ans)
x, y, a, b, c = list(map(int, input().split())) arr1 = list(map(int, input().split())) arr1 = sorted(arr1, reverse=True) arr1 = arr1[:x] arr2 = list(map(int, input().split())) arr2 = sorted(arr2, reverse=True) arr2 = arr2[:y] arr3 = list(map(int, input().split())) ans = arr1 + arr2 + arr3 ans = sorted(ans, reverse=True) print((sum(ans[: x + y])))
false
65.625
[ "-import heapq", "-", "+arr1 = sorted(arr1, reverse=True)", "+arr1 = arr1[:x]", "+arr2 = sorted(arr2, reverse=True)", "+arr2 = arr2[:y]", "-q = []", "-for val in arr1:", "- heapq.heappush(q, (-val, 1))", "-for val in arr2:", "- heapq.heappush(q, (-val, 2))", "-for val in arr3:", "- heapq.heappush(q, (-val, 3))", "-ans = 0", "-cnt1 = 0", "-cnt2 = 0", "-cnt3 = 0", "-while cnt1 + cnt2 + cnt3 < x + y:", "- tmp, flag = heapq.heappop(q)", "- tmp *= -1", "- if flag == 1:", "- if cnt1 < x:", "- ans += tmp", "- cnt1 += 1", "- elif flag == 2:", "- if cnt2 < y:", "- ans += tmp", "- cnt2 += 1", "- elif flag == 3:", "- ans += tmp", "- cnt3 += 1", "-print(ans)", "+ans = arr1 + arr2 + arr3", "+ans = sorted(ans, reverse=True)", "+print((sum(ans[: x + y])))" ]
false
0.041858
0.040964
1.021838
[ "s127769529", "s660332146" ]
u098012509
p03164
python
s094378925
s705453615
1,230
484
311,552
120,300
Accepted
Accepted
60.65
import sys input = sys.stdin.readline def main(): N, W = [int(x) for x in input().split()] WV = [[int(x) for x in input().split()] for _ in range(N)] sumv = 0 for w, v in WV: sumv += v dp = [[float("inf")] * (sumv + 1) for j in range(N + 1)] for i in range(1, N + 1): for j in range(sumv + 1): w, v = WV[i - 1] if j <= v: dp[i][j] = min(w, dp[i - 1][j]) else: dp[i][j] = min(dp[i - 1][j], w + dp[i - 1][j - v]) ans = 0 for i in range(sumv + 1): if dp[N][i] > W: break else: ans = i print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N, W = [int(x) for x in input().split()] WV = [[int(x) for x in input().split()] for _ in range(N)] sumv = 0 for w, v in WV: sumv += v dp = [[10 ** 9 + 1] * (sumv + 1) for j in range(N + 1)] for i in range(1, N + 1): for j in range(sumv + 1): w, v = WV[i - 1] if j <= v: dp[i][j] = min(w, dp[i - 1][j]) else: dp[i][j] = min(dp[i - 1][j], w + dp[i - 1][j - v]) ans = 0 for i in range(sumv + 1): if dp[N][i] > W: break else: ans = i print(ans) if __name__ == '__main__': main()
35
35
735
734
import sys input = sys.stdin.readline def main(): N, W = [int(x) for x in input().split()] WV = [[int(x) for x in input().split()] for _ in range(N)] sumv = 0 for w, v in WV: sumv += v dp = [[float("inf")] * (sumv + 1) for j in range(N + 1)] for i in range(1, N + 1): for j in range(sumv + 1): w, v = WV[i - 1] if j <= v: dp[i][j] = min(w, dp[i - 1][j]) else: dp[i][j] = min(dp[i - 1][j], w + dp[i - 1][j - v]) ans = 0 for i in range(sumv + 1): if dp[N][i] > W: break else: ans = i print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N, W = [int(x) for x in input().split()] WV = [[int(x) for x in input().split()] for _ in range(N)] sumv = 0 for w, v in WV: sumv += v dp = [[10**9 + 1] * (sumv + 1) for j in range(N + 1)] for i in range(1, N + 1): for j in range(sumv + 1): w, v = WV[i - 1] if j <= v: dp[i][j] = min(w, dp[i - 1][j]) else: dp[i][j] = min(dp[i - 1][j], w + dp[i - 1][j - v]) ans = 0 for i in range(sumv + 1): if dp[N][i] > W: break else: ans = i print(ans) if __name__ == "__main__": main()
false
0
[ "- dp = [[float(\"inf\")] * (sumv + 1) for j in range(N + 1)]", "+ dp = [[10**9 + 1] * (sumv + 1) for j in range(N + 1)]" ]
false
0.174999
0.036115
4.845632
[ "s094378925", "s705453615" ]
u052221988
p02756
python
s109684761
s464075021
701
495
4,480
4,480
Accepted
Accepted
29.39
right = eval(input()) q = int(eval(input())) left = "" flag = 1 for i in range(q) : t = eval(input()) if t == "1" : flag ^= 1 continue t, f, c = t.split(" ") f = int(f) left += c*flag*(2-f) right += c*flag*(f-1) left += c*(1-flag)*(f-1) right += c*(1-flag)*(2-f) if flag == 1 : print((left[::-1]+right)) else : print((right[::-1]+left))
right = eval(input()) flag = 1 left = "" for i in range(int(eval(input()))): t = eval(input()) if t == "1": flag ^= 1 continue t, f, c = t.split(" ") if not ((f=="1")^flag): left += c else: right += c ans = left[::-1] + right if not flag: ans = ans[::-1] print(ans)
19
17
388
319
right = eval(input()) q = int(eval(input())) left = "" flag = 1 for i in range(q): t = eval(input()) if t == "1": flag ^= 1 continue t, f, c = t.split(" ") f = int(f) left += c * flag * (2 - f) right += c * flag * (f - 1) left += c * (1 - flag) * (f - 1) right += c * (1 - flag) * (2 - f) if flag == 1: print((left[::-1] + right)) else: print((right[::-1] + left))
right = eval(input()) flag = 1 left = "" for i in range(int(eval(input()))): t = eval(input()) if t == "1": flag ^= 1 continue t, f, c = t.split(" ") if not ((f == "1") ^ flag): left += c else: right += c ans = left[::-1] + right if not flag: ans = ans[::-1] print(ans)
false
10.526316
[ "-q = int(eval(input()))", "+flag = 1", "-flag = 1", "-for i in range(q):", "+for i in range(int(eval(input()))):", "- f = int(f)", "- left += c * flag * (2 - f)", "- right += c * flag * (f - 1)", "- left += c * (1 - flag) * (f - 1)", "- right += c * (1 - flag) * (2 - f)", "-if flag == 1:", "- print((left[::-1] + right))", "-else:", "- print((right[::-1] + left))", "+ if not ((f == \"1\") ^ flag):", "+ left += c", "+ else:", "+ right += c", "+ans = left[::-1] + right", "+if not flag:", "+ ans = ans[::-1]", "+print(ans)" ]
false
0.036363
0.036904
0.985337
[ "s109684761", "s464075021" ]
u729133443
p03078
python
s106915683
s198051806
1,812
802
160,844
90,980
Accepted
Accepted
55.74
I=lambda:list(map(int,input().split()));x,y,z,k=I();S=sorted;s=lambda a,b:S(i+j for i in a for j in b)[:-k-1:-1];print((*s(s(S(I()),S(I())),S(I()))))
from numpy import*;I=lambda:int64(input().split());x,y,z,k=I();s=lambda a,b:sort(ravel([b+i for i in a]))[:-k-1:-1];print((*s(s(I(),I()),I())))
1
1
147
141
I = lambda: list(map(int, input().split())) x, y, z, k = I() S = sorted s = lambda a, b: S(i + j for i in a for j in b)[: -k - 1 : -1] print((*s(s(S(I()), S(I())), S(I()))))
from numpy import * I = lambda: int64(input().split()) x, y, z, k = I() s = lambda a, b: sort(ravel([b + i for i in a]))[: -k - 1 : -1] print((*s(s(I(), I()), I())))
false
0
[ "-I = lambda: list(map(int, input().split()))", "+from numpy import *", "+", "+I = lambda: int64(input().split())", "-S = sorted", "-s = lambda a, b: S(i + j for i in a for j in b)[: -k - 1 : -1]", "-print((*s(s(S(I()), S(I())), S(I()))))", "+s = lambda a, b: sort(ravel([b + i for i in a]))[: -k - 1 : -1]", "+print((*s(s(I(), I()), I())))" ]
false
0.042038
0.194594
0.21603
[ "s106915683", "s198051806" ]
u677523557
p02822
python
s296587054
s947004522
1,858
1,707
198,304
69,700
Accepted
Accepted
8.13
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) mod = 10**9+7 N = int(eval(input())) graph = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) graph[a-1].append(b-1) graph[b-1].append(a-1) #互いに素なa,bについて、a*x+b*y=1の一つの解 def extgcd(a,b): r = [1,0,a] w = [0,1,b] while w[2]!=1: q = r[2]//w[2] r2 = w w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]] r = r2 w = w2 #[x,y] return [w[0],w[1]] # aの逆元(mod m)を求める。(aとmは互いに素であることが前提) def mod_inv(a,m=mod): x = extgcd(a,m)[0] return (m+x%m)%m N2 = [1] n = 1 for _ in range(N+1): n = n*2 % mod N2.append(n) Weight = [[] for _ in range(N)] checked = [False]*N def dfs(p): checked[p] = True downs = 0 for np in graph[p]: if not checked[np]: downscore = dfs(np) Weight[p].append(N-downscore) Weight[np].append(downscore) downs += N-downscore return N-(downs+1) dfs(0) a = 0 for n in range(N): if len(Weight[n]) == 1: continue c = N2[N-1] - 1 for w in Weight[n]: c = (c - N2[w] + 1) % mod a = (a + c) % mod ans = (a * mod_inv(N2[N])) % mod print(ans)
import sys input = sys.stdin.readline mod = 10**9+7 def dfs(graph, N): ans = 0 Par = [-1]*N Childs = [[] for _ in range(N)] stack = [0] while stack: p = stack.pop() if p >= 0: stack.append(~p) for np in graph[p]: if np != 0 and Par[np] == -1: stack.append(np) Par[np] = p else: p = ~p score = pow(2, N-1, mod) - 1 upper = N-1 for a in Childs[p]: upper -= a score = (score - pow(2, a, mod) + 1) % mod if p != 0: score = (score - pow(2, upper, mod) + 1) % mod ans = (ans + score) % mod Childs[Par[p]].append(N-1-upper+1) return ans * pow(2, N*(mod-2), mod) % mod def main(): N = int(eval(input())) graph = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) graph[a-1].append(b-1) graph[b-1].append(a-1) print((dfs(graph, N))) if __name__ == "__main__": main()
66
44
1,289
1,132
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) mod = 10**9 + 7 N = int(eval(input())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) # 互いに素なa,bについて、a*x+b*y=1の一つの解 def extgcd(a, b): r = [1, 0, a] w = [0, 1, b] while w[2] != 1: q = r[2] // w[2] r2 = w w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]] r = r2 w = w2 # [x,y] return [w[0], w[1]] # aの逆元(mod m)を求める。(aとmは互いに素であることが前提) def mod_inv(a, m=mod): x = extgcd(a, m)[0] return (m + x % m) % m N2 = [1] n = 1 for _ in range(N + 1): n = n * 2 % mod N2.append(n) Weight = [[] for _ in range(N)] checked = [False] * N def dfs(p): checked[p] = True downs = 0 for np in graph[p]: if not checked[np]: downscore = dfs(np) Weight[p].append(N - downscore) Weight[np].append(downscore) downs += N - downscore return N - (downs + 1) dfs(0) a = 0 for n in range(N): if len(Weight[n]) == 1: continue c = N2[N - 1] - 1 for w in Weight[n]: c = (c - N2[w] + 1) % mod a = (a + c) % mod ans = (a * mod_inv(N2[N])) % mod print(ans)
import sys input = sys.stdin.readline mod = 10**9 + 7 def dfs(graph, N): ans = 0 Par = [-1] * N Childs = [[] for _ in range(N)] stack = [0] while stack: p = stack.pop() if p >= 0: stack.append(~p) for np in graph[p]: if np != 0 and Par[np] == -1: stack.append(np) Par[np] = p else: p = ~p score = pow(2, N - 1, mod) - 1 upper = N - 1 for a in Childs[p]: upper -= a score = (score - pow(2, a, mod) + 1) % mod if p != 0: score = (score - pow(2, upper, mod) + 1) % mod ans = (ans + score) % mod Childs[Par[p]].append(N - 1 - upper + 1) return ans * pow(2, N * (mod - 2), mod) % mod def main(): N = int(eval(input())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) print((dfs(graph, N))) if __name__ == "__main__": main()
false
33.333333
[ "-sys.setrecursionlimit(10**7)", "-N = int(eval(input()))", "-graph = [[] for _ in range(N)]", "-for _ in range(N - 1):", "- a, b = list(map(int, input().split()))", "- graph[a - 1].append(b - 1)", "- graph[b - 1].append(a - 1)", "-# 互いに素なa,bについて、a*x+b*y=1の一つの解", "-def extgcd(a, b):", "- r = [1, 0, a]", "- w = [0, 1, b]", "- while w[2] != 1:", "- q = r[2] // w[2]", "- r2 = w", "- w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]", "- r = r2", "- w = w2", "- # [x,y]", "- return [w[0], w[1]]", "-# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)", "-def mod_inv(a, m=mod):", "- x = extgcd(a, m)[0]", "- return (m + x % m) % m", "+def dfs(graph, N):", "+ ans = 0", "+ Par = [-1] * N", "+ Childs = [[] for _ in range(N)]", "+ stack = [0]", "+ while stack:", "+ p = stack.pop()", "+ if p >= 0:", "+ stack.append(~p)", "+ for np in graph[p]:", "+ if np != 0 and Par[np] == -1:", "+ stack.append(np)", "+ Par[np] = p", "+ else:", "+ p = ~p", "+ score = pow(2, N - 1, mod) - 1", "+ upper = N - 1", "+ for a in Childs[p]:", "+ upper -= a", "+ score = (score - pow(2, a, mod) + 1) % mod", "+ if p != 0:", "+ score = (score - pow(2, upper, mod) + 1) % mod", "+ ans = (ans + score) % mod", "+ Childs[Par[p]].append(N - 1 - upper + 1)", "+ return ans * pow(2, N * (mod - 2), mod) % mod", "-N2 = [1]", "-n = 1", "-for _ in range(N + 1):", "- n = n * 2 % mod", "- N2.append(n)", "-Weight = [[] for _ in range(N)]", "-checked = [False] * N", "+def main():", "+ N = int(eval(input()))", "+ graph = [[] for _ in range(N)]", "+ for _ in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ graph[a - 1].append(b - 1)", "+ graph[b - 1].append(a - 1)", "+ print((dfs(graph, N)))", "-def dfs(p):", "- checked[p] = True", "- downs = 0", "- for np in graph[p]:", "- if not checked[np]:", "- downscore = dfs(np)", "- Weight[p].append(N - downscore)", "- Weight[np].append(downscore)", "- downs += N - downscore", "- return N - (downs + 1)", "-", "-", "-dfs(0)", "-a = 0", "-for n in range(N):", "- if len(Weight[n]) == 1:", "- continue", "- c = N2[N - 1] - 1", "- for w in Weight[n]:", "- c = (c - N2[w] + 1) % mod", "- a = (a + c) % mod", "-ans = (a * mod_inv(N2[N])) % mod", "-print(ans)", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.078393
0.080489
0.973961
[ "s296587054", "s947004522" ]
u103198430
p02726
python
s171744720
s743081143
1,692
1,197
3,444
3,444
Accepted
Accepted
29.26
import sys def input() -> str: return sys.stdin.readline().rstrip("\r\n") def main(): def min_dest(a, b): return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a)) n, x, y = list(map(int, input().split())) x, y = x-1, y-1 ans = [0] * (n-1) for i in range(n): for j in range(i+1, n): ans[min_dest(i, j)-1] += 1 for a in ans: print(a) if __name__ == "__main__": main()
import sys def input() -> str: return sys.stdin.readline().rstrip("\r\n") def main(): def min_dest(a, b): return min(b-a, abs(x-a)+1+abs(y-b)) n, x, y = list(map(int, input().split())) x, y = x-1, y-1 ans = [0] * (n-1) for i in range(n): for j in range(i+1, n): ans[min_dest(i, j)-1] += 1 for a in ans: print(a) if __name__ == "__main__": main()
25
25
462
441
import sys def input() -> str: return sys.stdin.readline().rstrip("\r\n") def main(): def min_dest(a, b): return min(b - a, abs(x - a) + 1 + abs(y - b), abs(x - b) + 1 + abs(y - a)) n, x, y = list(map(int, input().split())) x, y = x - 1, y - 1 ans = [0] * (n - 1) for i in range(n): for j in range(i + 1, n): ans[min_dest(i, j) - 1] += 1 for a in ans: print(a) if __name__ == "__main__": main()
import sys def input() -> str: return sys.stdin.readline().rstrip("\r\n") def main(): def min_dest(a, b): return min(b - a, abs(x - a) + 1 + abs(y - b)) n, x, y = list(map(int, input().split())) x, y = x - 1, y - 1 ans = [0] * (n - 1) for i in range(n): for j in range(i + 1, n): ans[min_dest(i, j) - 1] += 1 for a in ans: print(a) if __name__ == "__main__": main()
false
0
[ "- return min(b - a, abs(x - a) + 1 + abs(y - b), abs(x - b) + 1 + abs(y - a))", "+ return min(b - a, abs(x - a) + 1 + abs(y - b))" ]
false
0.04136
0.041559
0.995203
[ "s171744720", "s743081143" ]
u581187895
p02984
python
s732332647
s618990591
129
90
14,092
20,564
Accepted
Accepted
30.23
N = int(eval(input())) A = list(map(int, input().split())) X = [0]*N # 全体の和 - 偶数の和*2 = 一番目の値 # もしくは、(x/2)+(y/2)=A, ..B,..C -> x+y+z = A+B+C X[0] = sum(A) - sum(A[1::2])*2 #最初の値から順番にダムの値を引けば答え for i in range(1, N): X[i] = A[i-1]*2 - X[i-1] print((*X))
def resolve(): N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N ans[0] = sum(A) for i in range(1, N, 2): ans[0] -= 2 * A[i] for i in range(N - 1): ans[i + 1] = 2 * A[i] - ans[i] print((*ans)) if __name__ == "__main__": resolve()
13
19
263
317
N = int(eval(input())) A = list(map(int, input().split())) X = [0] * N # 全体の和 - 偶数の和*2 = 一番目の値 # もしくは、(x/2)+(y/2)=A, ..B,..C -> x+y+z = A+B+C X[0] = sum(A) - sum(A[1::2]) * 2 # 最初の値から順番にダムの値を引けば答え for i in range(1, N): X[i] = A[i - 1] * 2 - X[i - 1] print((*X))
def resolve(): N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N ans[0] = sum(A) for i in range(1, N, 2): ans[0] -= 2 * A[i] for i in range(N - 1): ans[i + 1] = 2 * A[i] - ans[i] print((*ans)) if __name__ == "__main__": resolve()
false
31.578947
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-X = [0] * N", "-# 全体の和 - 偶数の和*2 = 一番目の値", "-# もしくは、(x/2)+(y/2)=A, ..B,..C -> x+y+z = A+B+C", "-X[0] = sum(A) - sum(A[1::2]) * 2", "-# 最初の値から順番にダムの値を引けば答え", "-for i in range(1, N):", "- X[i] = A[i - 1] * 2 - X[i - 1]", "-print((*X))", "+def resolve():", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ ans = [0] * N", "+ ans[0] = sum(A)", "+ for i in range(1, N, 2):", "+ ans[0] -= 2 * A[i]", "+ for i in range(N - 1):", "+ ans[i + 1] = 2 * A[i] - ans[i]", "+ print((*ans))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.041079
0.045642
0.900025
[ "s732332647", "s618990591" ]
u057109575
p02913
python
s616584156
s901527679
610
502
229,896
79,864
Accepted
Accepted
17.7
N = int(eval(input())) S = eval(input()) res = 0 dp = [[0] * (N + 1) for _ in range(N + 1)] for i in reversed(list(range(N))): for j in reversed(list(range(i + 1, N))): if S[i] == S[j]: dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1) res = max(res, min(dp[i][j], j - i)) print(res)
N = int(eval(input())) S = eval(input()) def z_algorithm(s): n = len(s) res = [0] * n i = 1 j = 0 while i < n: while i + j < n and s[j] == s[i + j]: j += 1 res[i] = j if j == 0: i += 1 continue k = 1 while i + k < n and k + res[k] < j: res[i + k] = res[k] k += 1 i += k j -= k return res ans = 0 for i in range(N): lcp = z_algorithm(S[i:]) tmp = max(min(lcp[j], j) for j in range(N - i)) ans = max(ans, tmp) print(ans)
12
33
310
637
N = int(eval(input())) S = eval(input()) res = 0 dp = [[0] * (N + 1) for _ in range(N + 1)] for i in reversed(list(range(N))): for j in reversed(list(range(i + 1, N))): if S[i] == S[j]: dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1) res = max(res, min(dp[i][j], j - i)) print(res)
N = int(eval(input())) S = eval(input()) def z_algorithm(s): n = len(s) res = [0] * n i = 1 j = 0 while i < n: while i + j < n and s[j] == s[i + j]: j += 1 res[i] = j if j == 0: i += 1 continue k = 1 while i + k < n and k + res[k] < j: res[i + k] = res[k] k += 1 i += k j -= k return res ans = 0 for i in range(N): lcp = z_algorithm(S[i:]) tmp = max(min(lcp[j], j) for j in range(N - i)) ans = max(ans, tmp) print(ans)
false
63.636364
[ "-res = 0", "-dp = [[0] * (N + 1) for _ in range(N + 1)]", "-for i in reversed(list(range(N))):", "- for j in reversed(list(range(i + 1, N))):", "- if S[i] == S[j]:", "- dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)", "- res = max(res, min(dp[i][j], j - i))", "-print(res)", "+", "+", "+def z_algorithm(s):", "+ n = len(s)", "+ res = [0] * n", "+ i = 1", "+ j = 0", "+ while i < n:", "+ while i + j < n and s[j] == s[i + j]:", "+ j += 1", "+ res[i] = j", "+ if j == 0:", "+ i += 1", "+ continue", "+ k = 1", "+ while i + k < n and k + res[k] < j:", "+ res[i + k] = res[k]", "+ k += 1", "+ i += k", "+ j -= k", "+ return res", "+", "+", "+ans = 0", "+for i in range(N):", "+ lcp = z_algorithm(S[i:])", "+ tmp = max(min(lcp[j], j) for j in range(N - i))", "+ ans = max(ans, tmp)", "+print(ans)" ]
false
0.095654
0.041971
2.279012
[ "s616584156", "s901527679" ]
u317493066
p03846
python
s866353275
s489129744
101
86
14,820
14,820
Accepted
Accepted
14.85
# -*- coding:utf-8 -*- from collections import Counter def check(n, a): count = Counter(a) if n % 2 == 1 and (0 not in count or count[0] != 1): return False for i in range(1 + (n % 2), n+1, 2): if i not in count or count[i] !=2: return False return True if __name__ == "__main__": N = int(eval(input())) A = list(map(int, input().split())) if not check(N,A): print((0)) else: if N > 1: c = 2 for _ in range((N // 2) - 1): c = c * 2 % (int(1e9) + 7) print(c) else: print((1))
# -*- coding:utf-8 -*- from collections import Counter def check(n, a): count = Counter(a) if n % 2 == 1 and (0 not in count or count[0] != 1): return False for i in range(1 + (n % 2), n+1, 2): if i not in count or count[i] !=2: return False return True if __name__ == "__main__": N = int(eval(input())) A = list(map(int, input().split())) m = N // 2 if not check(N,A): print((0)) else: print(((2 ** m) % (10**9+7)))
26
21
641
510
# -*- coding:utf-8 -*- from collections import Counter def check(n, a): count = Counter(a) if n % 2 == 1 and (0 not in count or count[0] != 1): return False for i in range(1 + (n % 2), n + 1, 2): if i not in count or count[i] != 2: return False return True if __name__ == "__main__": N = int(eval(input())) A = list(map(int, input().split())) if not check(N, A): print((0)) else: if N > 1: c = 2 for _ in range((N // 2) - 1): c = c * 2 % (int(1e9) + 7) print(c) else: print((1))
# -*- coding:utf-8 -*- from collections import Counter def check(n, a): count = Counter(a) if n % 2 == 1 and (0 not in count or count[0] != 1): return False for i in range(1 + (n % 2), n + 1, 2): if i not in count or count[i] != 2: return False return True if __name__ == "__main__": N = int(eval(input())) A = list(map(int, input().split())) m = N // 2 if not check(N, A): print((0)) else: print(((2**m) % (10**9 + 7)))
false
19.230769
[ "+ m = N // 2", "- if N > 1:", "- c = 2", "- for _ in range((N // 2) - 1):", "- c = c * 2 % (int(1e9) + 7)", "- print(c)", "- else:", "- print((1))", "+ print(((2**m) % (10**9 + 7)))" ]
false
0.051045
0.051088
0.999157
[ "s866353275", "s489129744" ]
u167681750
p02780
python
s198112225
s151948708
209
193
24,036
23,912
Accepted
Accepted
7.66
from collections import deque n, k = list(map(int, input().split())) p = deque(list(map(int, input().split()))) adjacent = deque() for i in range(k): adjacent.append(p.popleft()) ans = sum(adjacent) count = ans while p: pp = p.popleft() count -= adjacent.popleft() count += pp adjacent.append(pp) ans = max(ans, count) print(((ans + k) / 2))
from collections import deque n, k = list(map(int, input().split())) p = deque(list(map(int, input().split()))) adjacent = deque() for i in range(k): adjacent.append(p.pop()) ans = sum(adjacent) count = ans while p: pp = p.pop() count -= adjacent.popleft() count += pp adjacent.append(pp) ans = max(ans, count) print(((ans + k) / 2))
19
19
373
365
from collections import deque n, k = list(map(int, input().split())) p = deque(list(map(int, input().split()))) adjacent = deque() for i in range(k): adjacent.append(p.popleft()) ans = sum(adjacent) count = ans while p: pp = p.popleft() count -= adjacent.popleft() count += pp adjacent.append(pp) ans = max(ans, count) print(((ans + k) / 2))
from collections import deque n, k = list(map(int, input().split())) p = deque(list(map(int, input().split()))) adjacent = deque() for i in range(k): adjacent.append(p.pop()) ans = sum(adjacent) count = ans while p: pp = p.pop() count -= adjacent.popleft() count += pp adjacent.append(pp) ans = max(ans, count) print(((ans + k) / 2))
false
0
[ "- adjacent.append(p.popleft())", "+ adjacent.append(p.pop())", "- pp = p.popleft()", "+ pp = p.pop()" ]
false
0.03804
0.054908
0.692798
[ "s198112225", "s151948708" ]
u716530146
p03033
python
s294620833
s820889198
1,945
1,789
120,128
120,000
Accepted
Accepted
8.02
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') # inf = float('inf') ;mod = 10**9+7 # mans = inf ;ans = 0 ;count = 0 ;pro = 1 from heapq import heappush,heappop n,q=list(map(int,input().split())) STX=[tuple(map(int,input().split())) for i in range(n)] D=[int(eval(input())) for i in range(q)] event=[] for si,ti,xi in STX: event.append((si-xi,0,xi)) event.append((ti-xi,-1,xi)) for di in D: event.append((di,1,di)) event.sort() hq=[]; S=set() for time, query, number in event: if query == 0: heappush(hq,number) S.add(number) elif query == -1: S.remove(number) else: while hq and hq[0] not in S: heappop(hq) if not hq: print((-1)) else: print((hq[0]))
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect, heapq input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n,q=list(map(int,input().split())) STX=[tuple(map(int,input().split())) for i in range(n)] D=[int(eval(input())) for i in range(q)] event=[] for si,ti,xi in STX: event.append((si-xi,0,xi)) event.append((ti-xi,-1,xi)) for di in D: event.append((di,1,di)) event.sort() hq=[]; S=set() for time, query, number in event: if query == 0: heapq.heappush(hq,number) S.add(number) elif query == -1: S.remove(number) else: while hq and hq[0] not in S: heapq.heappop(hq) if not hq: print((-1)) else: print((hq[0]))
33
32
818
797
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") # inf = float('inf') ;mod = 10**9+7 # mans = inf ;ans = 0 ;count = 0 ;pro = 1 from heapq import heappush, heappop n, q = list(map(int, input().split())) STX = [tuple(map(int, input().split())) for i in range(n)] D = [int(eval(input())) for i in range(q)] event = [] for si, ti, xi in STX: event.append((si - xi, 0, xi)) event.append((ti - xi, -1, xi)) for di in D: event.append((di, 1, di)) event.sort() hq = [] S = set() for time, query, number in event: if query == 0: heappush(hq, number) S.add(number) elif query == -1: S.remove(number) else: while hq and hq[0] not in S: heappop(hq) if not hq: print((-1)) else: print((hq[0]))
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect, heapq input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") inf = float("inf") mod = 10**9 + 7 mans = inf ans = 0 count = 0 pro = 1 n, q = list(map(int, input().split())) STX = [tuple(map(int, input().split())) for i in range(n)] D = [int(eval(input())) for i in range(q)] event = [] for si, ti, xi in STX: event.append((si - xi, 0, xi)) event.append((ti - xi, -1, xi)) for di in D: event.append((di, 1, di)) event.sort() hq = [] S = set() for time, query, number in event: if query == 0: heapq.heappush(hq, number) S.add(number) elif query == -1: S.remove(number) else: while hq and hq[0] not in S: heapq.heappop(hq) if not hq: print((-1)) else: print((hq[0]))
false
3.030303
[ "-import sys, math, itertools, collections, bisect", "+import sys, math, itertools, collections, bisect, heapq", "-# inf = float('inf') ;mod = 10**9+7", "-# mans = inf ;ans = 0 ;count = 0 ;pro = 1", "-from heapq import heappush, heappop", "-", "+inf = float(\"inf\")", "+mod = 10**9 + 7", "+mans = inf", "+ans = 0", "+count = 0", "+pro = 1", "- heappush(hq, number)", "+ heapq.heappush(hq, number)", "- heappop(hq)", "+ heapq.heappop(hq)" ]
false
0.037028
0.037312
0.99241
[ "s294620833", "s820889198" ]
u633068244
p01336
python
s951088646
s486300458
8,820
6,700
4,276
4,268
Accepted
Accepted
24.04
while 1: try: N,M = list(map(int,input().split())) dp = [[0]*(M+1) for i in range(3)] for _ in range(N): name = input() C,V,D,L = list(map(int,input().split())) VDL = [V,D,L] if C > M: continue for i in range(3): dp[i][C] = max(dp[i][C],VDL[i]) for j in range(M): if dp[i][j]: if j+C <= M: dp[i][j+C] = max(dp[i][j+C],dp[i][j]+VDL[i]) print(max(max(dp[0]),max(dp[1]),max(dp[2]))) except: break
while 1: try: N,M = list(map(int,input().split())) dp = [[0]*(M+1) for i in range(3)] for _ in range(N): name = input() C,V,D,L = list(map(int,input().split())) VDL = [V,D,L] if C > M: continue for i in range(3): dp[i][C] = max(dp[i][C],VDL[i]) for j in range(M-C+1): if dp[i][j]: dp[i][j+C] = max(dp[i][j+C],dp[i][j]+VDL[i]) print(max(max(dp[0]),max(dp[1]),max(dp[2]))) except: break
19
18
467
450
while 1: try: N, M = list(map(int, input().split())) dp = [[0] * (M + 1) for i in range(3)] for _ in range(N): name = input() C, V, D, L = list(map(int, input().split())) VDL = [V, D, L] if C > M: continue for i in range(3): dp[i][C] = max(dp[i][C], VDL[i]) for j in range(M): if dp[i][j]: if j + C <= M: dp[i][j + C] = max(dp[i][j + C], dp[i][j] + VDL[i]) print(max(max(dp[0]), max(dp[1]), max(dp[2]))) except: break
while 1: try: N, M = list(map(int, input().split())) dp = [[0] * (M + 1) for i in range(3)] for _ in range(N): name = input() C, V, D, L = list(map(int, input().split())) VDL = [V, D, L] if C > M: continue for i in range(3): dp[i][C] = max(dp[i][C], VDL[i]) for j in range(M - C + 1): if dp[i][j]: dp[i][j + C] = max(dp[i][j + C], dp[i][j] + VDL[i]) print(max(max(dp[0]), max(dp[1]), max(dp[2]))) except: break
false
5.263158
[ "- for j in range(M):", "+ for j in range(M - C + 1):", "- if j + C <= M:", "- dp[i][j + C] = max(dp[i][j + C], dp[i][j] + VDL[i])", "+ dp[i][j + C] = max(dp[i][j + C], dp[i][j] + VDL[i])" ]
false
0.041706
0.045602
0.914562
[ "s951088646", "s486300458" ]
u754022296
p03822
python
s425001416
s299449456
609
326
227,944
112,664
Accepted
Accepted
46.47
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) T = [[] for _ in range(n)] for i in range(1, n): a = int(eval(input())) a -= 1 T[a].append(i) def dfs(v): if not T[v]: return 0 L = [dfs(i)+1 for i in T[v]] L.sort() for i in range(len(T[v]) - 1): L[i+1] = max(L[i]+1, L[i+1]) return L[-1] ans = dfs(0) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) import heapq n = int(eval(input())) T = [[] for _ in range(n)] for i in range(1, n): a = int(eval(input())) a -= 1 T[a].append(i) def dfs(v): if not T[v]: return 0 L = [] for i in T[v]: heapq.heappush(L, dfs(i)+1) temp = heapq.heappop(L) while L: temp = max(temp+1, heapq.heappop(L)) return temp ans = dfs(0) print(ans)
22
26
388
433
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) T = [[] for _ in range(n)] for i in range(1, n): a = int(eval(input())) a -= 1 T[a].append(i) def dfs(v): if not T[v]: return 0 L = [dfs(i) + 1 for i in T[v]] L.sort() for i in range(len(T[v]) - 1): L[i + 1] = max(L[i] + 1, L[i + 1]) return L[-1] ans = dfs(0) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) import heapq n = int(eval(input())) T = [[] for _ in range(n)] for i in range(1, n): a = int(eval(input())) a -= 1 T[a].append(i) def dfs(v): if not T[v]: return 0 L = [] for i in T[v]: heapq.heappush(L, dfs(i) + 1) temp = heapq.heappop(L) while L: temp = max(temp + 1, heapq.heappop(L)) return temp ans = dfs(0) print(ans)
false
15.384615
[ "+import heapq", "+", "- L = [dfs(i) + 1 for i in T[v]]", "- L.sort()", "- for i in range(len(T[v]) - 1):", "- L[i + 1] = max(L[i] + 1, L[i + 1])", "- return L[-1]", "+ L = []", "+ for i in T[v]:", "+ heapq.heappush(L, dfs(i) + 1)", "+ temp = heapq.heappop(L)", "+ while L:", "+ temp = max(temp + 1, heapq.heappop(L))", "+ return temp" ]
false
0.038136
0.037699
1.0116
[ "s425001416", "s299449456" ]
u020390084
p03379
python
s401405833
s356044642
412
302
27,180
30,844
Accepted
Accepted
26.7
import statistics n = int(eval(input())) x = list(map(int,input().split())) median_left = statistics.median_low(x) median_right = statistics.median_high(x) for i in range(n): if x[i] >= median_right: print(median_left) else: print(median_right)
#!/usr/bin/env python3 import sys def solve(N: int, X: "List[int]"): Y = sorted(X) me1 = Y[N//2] me2 = Y[N//2-1] for i in range(N): if X[i]<=me2: print(me1) elif X[i]>=me1: print(me2) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, X) if __name__ == '__main__': main()
14
30
269
611
import statistics n = int(eval(input())) x = list(map(int, input().split())) median_left = statistics.median_low(x) median_right = statistics.median_high(x) for i in range(n): if x[i] >= median_right: print(median_left) else: print(median_right)
#!/usr/bin/env python3 import sys def solve(N: int, X: "List[int]"): Y = sorted(X) me1 = Y[N // 2] me2 = Y[N // 2 - 1] for i in range(N): if X[i] <= me2: print(me1) elif X[i] >= me1: print(me2) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, X) if __name__ == "__main__": main()
false
53.333333
[ "-import statistics", "+#!/usr/bin/env python3", "+import sys", "-n = int(eval(input()))", "-x = list(map(int, input().split()))", "-median_left = statistics.median_low(x)", "-median_right = statistics.median_high(x)", "-for i in range(n):", "- if x[i] >= median_right:", "- print(median_left)", "- else:", "- print(median_right)", "+", "+def solve(N: int, X: \"List[int]\"):", "+ Y = sorted(X)", "+ me1 = Y[N // 2]", "+ me2 = Y[N // 2 - 1]", "+ for i in range(N):", "+ if X[i] <= me2:", "+ print(me1)", "+ elif X[i] >= me1:", "+ print(me2)", "+ return", "+", "+", "+def main():", "+ def iterate_tokens():", "+ for line in sys.stdin:", "+ for word in line.split():", "+ yield word", "+", "+ tokens = iterate_tokens()", "+ N = int(next(tokens)) # type: int", "+ X = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"", "+ solve(N, X)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.169341
0.083066
2.03864
[ "s401405833", "s356044642" ]
u156815136
p03059
python
s337749265
s412113381
35
21
5,048
3,444
Accepted
Accepted
40
import itertools import fractions def main(): a,b,t = list(map(int,input().split())) print((b * (t//a))) if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) a,b,t = readInts() ans = 0 time = 0 while True: ans += b #print(time,t+0.5) if time + a > t + 0.5: break else: time += a print((ans - b))
8
37
146
782
import itertools import fractions def main(): a, b, t = list(map(int, input().split())) print((b * (t // a))) if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from fractions import gcd # from itertools import combinations # (string,3) 3回 # from collections import deque from collections import defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) a, b, t = readInts() ans = 0 time = 0 while True: ans += b # print(time,t+0.5) if time + a > t + 0.5: break else: time += a print((ans - b))
false
78.378378
[ "-import itertools", "-import fractions", "+# from statistics import median", "+# import collections", "+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "+# from fractions import gcd", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "+from collections import defaultdict", "+", "+# import bisect", "+#", "+# d = m - k[i] - k[j]", "+# if kk[bisect.bisect_right(kk,d) - 1] == d:", "+#", "+#", "+#", "+# pythonで無理なときは、pypyでやると正解するかも!!", "+#", "+#", "+import sys", "+", "+sys.setrecursionlimit(10000000)", "+mod = 10**9 + 7", "+# mod = 9982443453", "+def readInts():", "+ return list(map(int, input().split()))", "-def main():", "- a, b, t = list(map(int, input().split()))", "- print((b * (t // a)))", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+a, b, t = readInts()", "+ans = 0", "+time = 0", "+while True:", "+ ans += b", "+ # print(time,t+0.5)", "+ if time + a > t + 0.5:", "+ break", "+ else:", "+ time += a", "+print((ans - b))" ]
false
0.036778
0.039306
0.935693
[ "s337749265", "s412113381" ]
u982896977
p03317
python
s771566221
s718607539
40
17
13,880
3,060
Accepted
Accepted
57.5
n,k = list(map(int,input().split())) a_ = list(map(int,input().split())) if (n-1)%(k-1) == 0: print(((n-1)//(k-1))) else: print(((n-1)//(k-1)+1))
n,k = list(map(int,input().split())) A = n-1 B = k-1 print(((A+(B-1))//B))
6
4
148
69
n, k = list(map(int, input().split())) a_ = list(map(int, input().split())) if (n - 1) % (k - 1) == 0: print(((n - 1) // (k - 1))) else: print(((n - 1) // (k - 1) + 1))
n, k = list(map(int, input().split())) A = n - 1 B = k - 1 print(((A + (B - 1)) // B))
false
33.333333
[ "-a_ = list(map(int, input().split()))", "-if (n - 1) % (k - 1) == 0:", "- print(((n - 1) // (k - 1)))", "-else:", "- print(((n - 1) // (k - 1) + 1))", "+A = n - 1", "+B = k - 1", "+print(((A + (B - 1)) // B))" ]
false
0.041871
0.042133
0.993794
[ "s771566221", "s718607539" ]
u371385198
p03607
python
s748093252
s507385887
165
74
20,664
20,732
Accepted
Accepted
55.15
from collections import Counter N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) print((sum(tuple([x % 2 for x in list(c.values())]))))
import sys from collections import Counter input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) print((sum([x % 2 for x in list(c.values())])))
5
7
156
189
from collections import Counter N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) print((sum(tuple([x % 2 for x in list(c.values())]))))
import sys from collections import Counter input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) print((sum([x % 2 for x in list(c.values())])))
false
28.571429
[ "+import sys", "+input = sys.stdin.readline", "-print((sum(tuple([x % 2 for x in list(c.values())]))))", "+print((sum([x % 2 for x in list(c.values())])))" ]
false
0.046071
0.039012
1.18095
[ "s748093252", "s507385887" ]
u002459665
p02712
python
s938695822
s856326021
186
150
9,108
9,168
Accepted
Accepted
19.35
N = int(eval(input())) ans = 0 for i in range(1, N+1): if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: ans += i print(ans)
N = int(eval(input())) ans = 0 for i in range(1, N+1): if i % 3 != 0 and i % 5 != 0: ans += i print(ans)
15
9
218
121
N = int(eval(input())) ans = 0 for i in range(1, N + 1): if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: ans += i print(ans)
N = int(eval(input())) ans = 0 for i in range(1, N + 1): if i % 3 != 0 and i % 5 != 0: ans += i print(ans)
false
40
[ "- if i % 3 == 0 and i % 5 == 0:", "- pass", "- elif i % 3 == 0:", "- pass", "- elif i % 5 == 0:", "- pass", "- else:", "+ if i % 3 != 0 and i % 5 != 0:" ]
false
0.369
0.209618
1.760347
[ "s938695822", "s856326021" ]
u039355749
p02629
python
s609284390
s167734733
64
27
61,688
9,032
Accepted
Accepted
57.81
def num2alpha(num): if num<=26: return chr(64+num) elif num%26==0: return num2alpha(num//26-1)+chr(90) else: return num2alpha(num//26)+chr(64+num%26) n = int(eval(input())) print((num2alpha(n).lower()))
n = int(eval(input())) def num2alpha(num): if num<=26: return chr(64+num) elif num%26==0: return num2alpha(num//26-1)+chr(90) else: return num2alpha(num//26)+chr(64+num%26) print((num2alpha(n).lower()))
11
11
242
248
def num2alpha(num): if num <= 26: return chr(64 + num) elif num % 26 == 0: return num2alpha(num // 26 - 1) + chr(90) else: return num2alpha(num // 26) + chr(64 + num % 26) n = int(eval(input())) print((num2alpha(n).lower()))
n = int(eval(input())) def num2alpha(num): if num <= 26: return chr(64 + num) elif num % 26 == 0: return num2alpha(num // 26 - 1) + chr(90) else: return num2alpha(num // 26) + chr(64 + num % 26) print((num2alpha(n).lower()))
false
0
[ "+n = int(eval(input()))", "+", "+", "-n = int(eval(input()))" ]
false
0.046128
0.046312
0.996025
[ "s609284390", "s167734733" ]
u345966487
p02762
python
s471896060
s388123958
1,914
1,637
124,504
123,864
Accepted
Accepted
14.47
from collections import defaultdict N, M, K = list(map(int, input().split())) friends = defaultdict(list) blocked = defaultdict(list) for i in range(M): a, b = list(map(int, input().split())) friends[a - 1].append(b - 1) friends[b - 1].append(a - 1) for j in range(K): c, d = list(map(int, input().split())) blocked[c - 1].append(d - 1) blocked[d - 1].append(c - 1) groups = {} for i in range(N): if i in groups: continue group = {i} stack = [(i, None)] while stack: j, parent_id = stack.pop() group.add(j) groups[j] = group for k in friends[j]: if k != parent_id and k not in groups: stack.append((k, j)) ans = [] for i in range(N): g = groups[i] res = len(g) - len(friends[i]) - 1 for b in blocked[i]: if groups[b] is g: res -= 1 ans.append(res) print((*ans))
from collections import defaultdict N, M, K = list(map(int, input().split())) friends = defaultdict(list) blocked = defaultdict(list) for i in range(M): a, b = list(map(int, input().split())) friends[a - 1].append(b - 1) friends[b - 1].append(a - 1) for j in range(K): c, d = list(map(int, input().split())) blocked[c - 1].append(d - 1) blocked[d - 1].append(c - 1) class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) uf = UnionFind(N) for i in range(N): for j in friends[i]: uf.union(i, j) ans = [] for i in range(N): res = uf.size(i) - len(friends[i]) - 1 for b in blocked[i]: if uf.same(i, b): res -= 1 ans.append(res) print((*ans))
38
84
927
2,173
from collections import defaultdict N, M, K = list(map(int, input().split())) friends = defaultdict(list) blocked = defaultdict(list) for i in range(M): a, b = list(map(int, input().split())) friends[a - 1].append(b - 1) friends[b - 1].append(a - 1) for j in range(K): c, d = list(map(int, input().split())) blocked[c - 1].append(d - 1) blocked[d - 1].append(c - 1) groups = {} for i in range(N): if i in groups: continue group = {i} stack = [(i, None)] while stack: j, parent_id = stack.pop() group.add(j) groups[j] = group for k in friends[j]: if k != parent_id and k not in groups: stack.append((k, j)) ans = [] for i in range(N): g = groups[i] res = len(g) - len(friends[i]) - 1 for b in blocked[i]: if groups[b] is g: res -= 1 ans.append(res) print((*ans))
from collections import defaultdict N, M, K = list(map(int, input().split())) friends = defaultdict(list) blocked = defaultdict(list) for i in range(M): a, b = list(map(int, input().split())) friends[a - 1].append(b - 1) friends[b - 1].append(a - 1) for j in range(K): c, d = list(map(int, input().split())) blocked[c - 1].append(d - 1) blocked[d - 1].append(c - 1) class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) uf = UnionFind(N) for i in range(N): for j in friends[i]: uf.union(i, j) ans = [] for i in range(N): res = uf.size(i) - len(friends[i]) - 1 for b in blocked[i]: if uf.same(i, b): res -= 1 ans.append(res) print((*ans))
false
54.761905
[ "-groups = {}", "+", "+", "+class UnionFind:", "+ def __init__(self, n):", "+ # total number of nodes.", "+ self.n = n", "+ # node id -> root node id", "+ self._root_table = list(range(n))", "+ # root node id -> group size", "+ self._size_table = [1] * n", "+", "+ def find(self, x):", "+ \"\"\"Returns x's root node id.\"\"\"", "+ r = self._root_table[x]", "+ if r != x:", "+ # Update the cache on query.", "+ r = self._root_table[x] = self.find(r)", "+ return r", "+", "+ def union(self, x, y):", "+ \"\"\"Merges two groups.\"\"\"", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ # Ensure that x is the larger (or equal) group.", "+ if self._size_table[x] < self._size_table[y]:", "+ x, y = y, x", "+ self._size_table[x] += self._size_table[y]", "+ self._root_table[y] = x", "+", "+ def size(self, x):", "+ return self._size_table[self.find(x)]", "+", "+ def same(self, x, y):", "+ return self.find(x) == self.find(y)", "+", "+ def members(self, x):", "+ root = self.find(x)", "+ return [i for i in range(self.n) if self.find(i) == root]", "+", "+ def roots(self):", "+ return [i for i, x in enumerate(self._root_table) if x == i]", "+", "+ def group_count(self):", "+ return len(self.roots())", "+", "+ def all_group_members(self):", "+ return {r: self.members(r) for r in self.roots()}", "+", "+ def __str__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "+", "+", "+uf = UnionFind(N)", "- if i in groups:", "- continue", "- group = {i}", "- stack = [(i, None)]", "- while stack:", "- j, parent_id = stack.pop()", "- group.add(j)", "- groups[j] = group", "- for k in friends[j]:", "- if k != parent_id and k not in groups:", "- stack.append((k, j))", "+ for j in friends[i]:", "+ uf.union(i, j)", "- g = groups[i]", "- res = len(g) - len(friends[i]) - 1", "+ res = uf.size(i) - len(friends[i]) - 1", "- if groups[b] is g:", "+ if uf.same(i, b):" ]
false
0.049225
0.070832
0.694955
[ "s471896060", "s388123958" ]
u796942881
p03290
python
s834498929
s474190365
44
21
3,064
3,064
Accepted
Accepted
52.27
INF = 1000000007 D, G = list(map(int, input().split())) p = [] c = [] for i in range(D): pi, ci = list(map(int, input().split())) p.append(pi) c.append(ci) def main(): ans = INF # 2 ** D - 1 まで for b in range(2 ** D): num = 0 pnt = 0 # コンプリートしない MAX x = None # 得点が高い方から for i in range(D - 1, -1, -1): if b >> i & 1: num += p[i] # コンプリートする pnt += c[i] + 100 * (i + 1) * p[i] elif x is None: x = i # コンプリート オール if x is None: ans = min(ans, num) continue flg = True for i in range(p[x]): if G <= pnt: break pnt += 100 * (x + 1) num += 1 # コンプリートした # 無効 if i == p[x] - 1: flg = False if not flg: continue ans = min(ans, num) print(ans) return main()
import math INF = 1000000007 D, G = list(map(int, input().split())) p = [] c = [] for i in range(D): pi, ci = list(map(int, input().split())) p.append(pi) c.append(ci) def main(): ans = INF # 2 ** D - 1 まで for b in range(2 ** D): num = 0 pnt = 0 # コンプリートしない MAX x = None # 得点が高い方から for i in range(D - 1, -1, -1): # i 番目 の フラグ が 立っている if b >> i & 1: num += p[i] # コンプリートする pnt += c[i] + 100 * (i + 1) * p[i] elif x is None: x = i # コンプリート オール # または 既に 目標の 総合スコア に到達 if x is None or G <= pnt: ans = min(ans, num) # コンプリートしない elif math.ceil((G - pnt) / (100 * (x + 1))) < p[x]: ans = min(ans, num + math.ceil((G - pnt) / (100 * (x + 1)))) print(ans) return main()
63
51
1,071
958
INF = 1000000007 D, G = list(map(int, input().split())) p = [] c = [] for i in range(D): pi, ci = list(map(int, input().split())) p.append(pi) c.append(ci) def main(): ans = INF # 2 ** D - 1 まで for b in range(2**D): num = 0 pnt = 0 # コンプリートしない MAX x = None # 得点が高い方から for i in range(D - 1, -1, -1): if b >> i & 1: num += p[i] # コンプリートする pnt += c[i] + 100 * (i + 1) * p[i] elif x is None: x = i # コンプリート オール if x is None: ans = min(ans, num) continue flg = True for i in range(p[x]): if G <= pnt: break pnt += 100 * (x + 1) num += 1 # コンプリートした # 無効 if i == p[x] - 1: flg = False if not flg: continue ans = min(ans, num) print(ans) return main()
import math INF = 1000000007 D, G = list(map(int, input().split())) p = [] c = [] for i in range(D): pi, ci = list(map(int, input().split())) p.append(pi) c.append(ci) def main(): ans = INF # 2 ** D - 1 まで for b in range(2**D): num = 0 pnt = 0 # コンプリートしない MAX x = None # 得点が高い方から for i in range(D - 1, -1, -1): # i 番目 の フラグ が 立っている if b >> i & 1: num += p[i] # コンプリートする pnt += c[i] + 100 * (i + 1) * p[i] elif x is None: x = i # コンプリート オール # または 既に 目標の 総合スコア に到達 if x is None or G <= pnt: ans = min(ans, num) # コンプリートしない elif math.ceil((G - pnt) / (100 * (x + 1))) < p[x]: ans = min(ans, num + math.ceil((G - pnt) / (100 * (x + 1)))) print(ans) return main()
false
19.047619
[ "+import math", "+", "+ # i 番目 の フラグ が 立っている", "- if x is None:", "+ # または 既に 目標の 総合スコア に到達", "+ if x is None or G <= pnt:", "- continue", "- flg = True", "- for i in range(p[x]):", "- if G <= pnt:", "- break", "- pnt += 100 * (x + 1)", "- num += 1", "- # コンプリートした", "- # 無効", "- if i == p[x] - 1:", "- flg = False", "- if not flg:", "- continue", "- ans = min(ans, num)", "+ # コンプリートしない", "+ elif math.ceil((G - pnt) / (100 * (x + 1))) < p[x]:", "+ ans = min(ans, num + math.ceil((G - pnt) / (100 * (x + 1))))" ]
false
0.042563
0.102327
0.415951
[ "s834498929", "s474190365" ]
u038408819
p03761
python
s214333312
s582026865
24
22
3,064
3,060
Accepted
Accepted
8.33
N = int(eval(input())) s_cnt = [] for i in range(N): cnt = {} s = eval(input()) for si in s: if si in cnt: cnt[si] += 1 else: cnt[si] = 1 s_cnt.append(cnt) min_ = {} for i in s_cnt: for j in i: if any([j not in s_cnt[k] for k in range(N)]): continue if j not in min_: min_[j] = i[j] else: min_[j] = min(min_[j], i[j]) string = '' for i in min_: #list_.append(i * min_[i]) string += i * min_[i] s = sorted(string) print((''.join(s)))
N = int(eval(input())) s = [eval(input()) for i in range(N)] alpha = "abcdefghijklmnopqrstuvwxyz" ans = '' for i in alpha: min_ = float('Inf') for sj in s: cnt = 0 for elem in sj: if elem == i: cnt += 1 min_ = min(min_, cnt) ans += i * min_ print(ans)
26
14
574
316
N = int(eval(input())) s_cnt = [] for i in range(N): cnt = {} s = eval(input()) for si in s: if si in cnt: cnt[si] += 1 else: cnt[si] = 1 s_cnt.append(cnt) min_ = {} for i in s_cnt: for j in i: if any([j not in s_cnt[k] for k in range(N)]): continue if j not in min_: min_[j] = i[j] else: min_[j] = min(min_[j], i[j]) string = "" for i in min_: # list_.append(i * min_[i]) string += i * min_[i] s = sorted(string) print(("".join(s)))
N = int(eval(input())) s = [eval(input()) for i in range(N)] alpha = "abcdefghijklmnopqrstuvwxyz" ans = "" for i in alpha: min_ = float("Inf") for sj in s: cnt = 0 for elem in sj: if elem == i: cnt += 1 min_ = min(min_, cnt) ans += i * min_ print(ans)
false
46.153846
[ "-s_cnt = []", "-for i in range(N):", "- cnt = {}", "- s = eval(input())", "- for si in s:", "- if si in cnt:", "- cnt[si] += 1", "- else:", "- cnt[si] = 1", "- s_cnt.append(cnt)", "-min_ = {}", "-for i in s_cnt:", "- for j in i:", "- if any([j not in s_cnt[k] for k in range(N)]):", "- continue", "- if j not in min_:", "- min_[j] = i[j]", "- else:", "- min_[j] = min(min_[j], i[j])", "-string = \"\"", "-for i in min_:", "- # list_.append(i * min_[i])", "- string += i * min_[i]", "-s = sorted(string)", "-print((\"\".join(s)))", "+s = [eval(input()) for i in range(N)]", "+alpha = \"abcdefghijklmnopqrstuvwxyz\"", "+ans = \"\"", "+for i in alpha:", "+ min_ = float(\"Inf\")", "+ for sj in s:", "+ cnt = 0", "+ for elem in sj:", "+ if elem == i:", "+ cnt += 1", "+ min_ = min(min_, cnt)", "+ ans += i * min_", "+print(ans)" ]
false
0.192935
0.110935
1.739171
[ "s214333312", "s582026865" ]
u609061751
p02679
python
s963961533
s945293761
676
623
183,804
184,016
Accepted
Accepted
7.84
import sys input = sys.stdin.readline mod = 10**9 + 7 n = int(eval(input())) ab = [[int(x) for x in input().split()] for _ in range(n)] from collections import defaultdict, Counter import math double_zero_cnt = 0 # [0, 0]の個数 a_b = [] # a/bを、約分した形で保持(a/gcd(a, b), b/gcd(a, b), 符号) for a, b in ab: if a == 0 and b == 0: double_zero_cnt += 1 continue g = math.gcd(a, b) a //= g b //= g sign = 1 if a*b > 0 else -1 if a*b < 0 else 0 a_b.append((abs(a), abs(b), sign)) c = Counter(a_b) # ベクトルごとにグループ分け key_list = list(c.keys()) d = defaultdict(list) # [a, b] あるngなペアのそれぞれの要素の個数 for key in key_list: a, b, sign = key if d[(b, a, -sign)]: # ダブルカウントしないように continue if c[(b, a, -sign)] != 0: d[(a, b, sign)] = [c[(a, b, sign)], c[(b, a, -sign)]] ans = 1 # 積算の単位元 used_cnt = double_zero_cnt # 組めないものがあるイワシの個数 for key in list(d.keys()): if d[key] == []: # 前のループで調べると[]が生まれてしまう continue x, y = d[key] used_cnt += (x + y) mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod # このグループからは、片方ずつからしか出せない。何も選ばないがダブルカウントになる。 ans *= mul ans %= mod ans *= pow(2, n - (used_cnt), mod) # まだ使われていないイワシは好きな組み合わせ可能 ans += double_zero_cnt # 両方0のものは1つにつき自分のみの1通り ans -= 1 # 0匹は選べない ans %= mod print(ans)
import sys input = sys.stdin.readline mod = 10**9 + 7 n = int(eval(input())) ab = [[int(x) for x in input().split()] for _ in range(n)] from collections import defaultdict, Counter import math double_zero_cnt = 0 # [0, 0]の個数 a_b = [] # a/bを、約分した形で保持(a/gcd(a, b), b/gcd(a, b), 符号) for a, b in ab: if a == 0 and b == 0: double_zero_cnt += 1 continue g = math.gcd(a, b) a //= g b //= g sign = 1 if a*b > 0 else -1 if a*b < 0 else 0 a_b.append((abs(a), abs(b), sign)) c = Counter(a_b) # ベクトルごとにグループ分け key_list = list(c.keys()) d = defaultdict(list) # [a, b] あるngなペアのそれぞれの要素の個数 for key in key_list: a, b, sign = key if d[(b, a, -sign)]: # ダブルカウントしないように continue if c[(b, a, -sign)] != 0: d[(a, b, sign)] = [c[(a, b, sign)], c[(b, a, -sign)]] ans = 1 # 積算の単位元 used_cnt = double_zero_cnt # 組めないものがあるイワシの個数(計算で使用したらカウント) for key in list(d.keys()): if d[key] == []: # 前のループで調べると[]が生まれてしまう continue x, y = d[key] used_cnt += (x + y) mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod # このグループからは、片方ずつからしか出せない。何も選ばないがダブルカウントになる。 ans *= mul ans %= mod ans *= pow(2, n - (used_cnt), mod) # まだ使われていないイワシは好きな組み合わせ可能 ans += double_zero_cnt # 両方0のものは1つにつき自分のみの1通り ans -= 1 # 0匹は選べない ans %= mod print(ans)
52
47
1,324
1,327
import sys input = sys.stdin.readline mod = 10**9 + 7 n = int(eval(input())) ab = [[int(x) for x in input().split()] for _ in range(n)] from collections import defaultdict, Counter import math double_zero_cnt = 0 # [0, 0]の個数 a_b = [] # a/bを、約分した形で保持(a/gcd(a, b), b/gcd(a, b), 符号) for a, b in ab: if a == 0 and b == 0: double_zero_cnt += 1 continue g = math.gcd(a, b) a //= g b //= g sign = 1 if a * b > 0 else -1 if a * b < 0 else 0 a_b.append((abs(a), abs(b), sign)) c = Counter(a_b) # ベクトルごとにグループ分け key_list = list(c.keys()) d = defaultdict(list) # [a, b] あるngなペアのそれぞれの要素の個数 for key in key_list: a, b, sign = key if d[(b, a, -sign)]: # ダブルカウントしないように continue if c[(b, a, -sign)] != 0: d[(a, b, sign)] = [c[(a, b, sign)], c[(b, a, -sign)]] ans = 1 # 積算の単位元 used_cnt = double_zero_cnt # 組めないものがあるイワシの個数 for key in list(d.keys()): if d[key] == []: # 前のループで調べると[]が生まれてしまう continue x, y = d[key] used_cnt += x + y mul = ( pow(2, x, mod) + pow(2, y, mod) - 1 ) % mod # このグループからは、片方ずつからしか出せない。何も選ばないがダブルカウントになる。 ans *= mul ans %= mod ans *= pow(2, n - (used_cnt), mod) # まだ使われていないイワシは好きな組み合わせ可能 ans += double_zero_cnt # 両方0のものは1つにつき自分のみの1通り ans -= 1 # 0匹は選べない ans %= mod print(ans)
import sys input = sys.stdin.readline mod = 10**9 + 7 n = int(eval(input())) ab = [[int(x) for x in input().split()] for _ in range(n)] from collections import defaultdict, Counter import math double_zero_cnt = 0 # [0, 0]の個数 a_b = [] # a/bを、約分した形で保持(a/gcd(a, b), b/gcd(a, b), 符号) for a, b in ab: if a == 0 and b == 0: double_zero_cnt += 1 continue g = math.gcd(a, b) a //= g b //= g sign = 1 if a * b > 0 else -1 if a * b < 0 else 0 a_b.append((abs(a), abs(b), sign)) c = Counter(a_b) # ベクトルごとにグループ分け key_list = list(c.keys()) d = defaultdict(list) # [a, b] あるngなペアのそれぞれの要素の個数 for key in key_list: a, b, sign = key if d[(b, a, -sign)]: # ダブルカウントしないように continue if c[(b, a, -sign)] != 0: d[(a, b, sign)] = [c[(a, b, sign)], c[(b, a, -sign)]] ans = 1 # 積算の単位元 used_cnt = double_zero_cnt # 組めないものがあるイワシの個数(計算で使用したらカウント) for key in list(d.keys()): if d[key] == []: # 前のループで調べると[]が生まれてしまう continue x, y = d[key] used_cnt += x + y mul = ( pow(2, x, mod) + pow(2, y, mod) - 1 ) % mod # このグループからは、片方ずつからしか出せない。何も選ばないがダブルカウントになる。 ans *= mul ans %= mod ans *= pow(2, n - (used_cnt), mod) # まだ使われていないイワシは好きな組み合わせ可能 ans += double_zero_cnt # 両方0のものは1つにつき自分のみの1通り ans -= 1 # 0匹は選べない ans %= mod print(ans)
false
9.615385
[ "-used_cnt = double_zero_cnt # 組めないものがあるイワシの個数", "+used_cnt = double_zero_cnt # 組めないものがあるイワシの個数(計算で使用したらカウント)" ]
false
0.047494
0.048107
0.987272
[ "s963961533", "s945293761" ]
u066692421
p03221
python
s790821611
s479025995
818
669
36,020
37,480
Accepted
Accepted
18.22
list1 = input().split() n = int(list1[0]) m = int(list1[1]) pre = [[] for i in range(n)] for j in range(m): data = input().split() p = int(data[0]) y = int(data[1]) pre[p - 1].append((j, y)) inums = [0 for z in range(m)] for k in range(n): if len(pre[k]) == 0: pass else: sorted_y = sorted(pre[k], key = lambda x:x[1]) for l in range(len(sorted_y)): s1 = str(k + 1).zfill(6) s2 = str(l + 1).zfill(6) inums[sorted_y[l][0]] = s1 + s2 for h in range(m): print((inums[h]))
n, m = map(int, input().split()) pre = [[] for i in range(n)] for j in range(m): p, y = map(int, input().split()) pre[p - 1].append((y, j)) inums = [0] * m for k in range(n): if len(pre[k]) == 0: pass else: sorted_y = sorted(pre[k]) for l in range(len(sorted_y)): s1 = str(k + 1).zfill(6) s2 = str(l + 1).zfill(6) inums[sorted_y[l][1]] = s1 + s2 print(*inums, sep = "\n")
24
19
580
468
list1 = input().split() n = int(list1[0]) m = int(list1[1]) pre = [[] for i in range(n)] for j in range(m): data = input().split() p = int(data[0]) y = int(data[1]) pre[p - 1].append((j, y)) inums = [0 for z in range(m)] for k in range(n): if len(pre[k]) == 0: pass else: sorted_y = sorted(pre[k], key=lambda x: x[1]) for l in range(len(sorted_y)): s1 = str(k + 1).zfill(6) s2 = str(l + 1).zfill(6) inums[sorted_y[l][0]] = s1 + s2 for h in range(m): print((inums[h]))
n, m = map(int, input().split()) pre = [[] for i in range(n)] for j in range(m): p, y = map(int, input().split()) pre[p - 1].append((y, j)) inums = [0] * m for k in range(n): if len(pre[k]) == 0: pass else: sorted_y = sorted(pre[k]) for l in range(len(sorted_y)): s1 = str(k + 1).zfill(6) s2 = str(l + 1).zfill(6) inums[sorted_y[l][1]] = s1 + s2 print(*inums, sep="\n")
false
20.833333
[ "-list1 = input().split()", "-n = int(list1[0])", "-m = int(list1[1])", "+n, m = map(int, input().split())", "- data = input().split()", "- p = int(data[0])", "- y = int(data[1])", "- pre[p - 1].append((j, y))", "-inums = [0 for z in range(m)]", "+ p, y = map(int, input().split())", "+ pre[p - 1].append((y, j))", "+inums = [0] * m", "- sorted_y = sorted(pre[k], key=lambda x: x[1])", "+ sorted_y = sorted(pre[k])", "- inums[sorted_y[l][0]] = s1 + s2", "-for h in range(m):", "- print((inums[h]))", "+ inums[sorted_y[l][1]] = s1 + s2", "+print(*inums, sep=\"\\n\")" ]
false
0.037816
0.036073
1.048339
[ "s790821611", "s479025995" ]
u191874006
p03425
python
s600444973
s856045894
508
190
57,432
75,828
Accepted
Accepted
62.6
#!/usr/bin/env python3 #ABC89 C import math n = int(eval(input())) s = [eval(input()) for _ in range(n)] m,a,r,c,h = 0,0,0,0,0 for i in s: if i[0] == 'M':m += 1 elif i[0] == 'A':a+= 1 elif i[0] == 'R':r += 1 elif i[0] == 'C':c += 1 elif i[0] == 'H':h += 1 ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() m_cnt = 0 a_cnt = 0 r_cnt = 0 c_cnt = 0 h_cnt = 0 for _ in range(n): s = eval(input()) if s[0] == 'M': m_cnt += 1 elif s[0] == 'A': a_cnt += 1 elif s[0] == 'R': r_cnt += 1 elif s[0] == 'C': c_cnt += 1 elif s[0] == 'H': h_cnt += 1 lst = [m_cnt, a_cnt, r_cnt, c_cnt, h_cnt] ans = 0 for i in range(5): for j in range(i+1, 5): for k in range(j+1, 5): ans += lst[i] * lst[j] * lst[k] print(ans)
18
45
380
1,065
#!/usr/bin/env python3 # ABC89 C import math n = int(eval(input())) s = [eval(input()) for _ in range(n)] m, a, r, c, h = 0, 0, 0, 0, 0 for i in s: if i[0] == "M": m += 1 elif i[0] == "A": a += 1 elif i[0] == "R": r += 1 elif i[0] == "C": c += 1 elif i[0] == "H": h += 1 ans = ( m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h ) print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() m_cnt = 0 a_cnt = 0 r_cnt = 0 c_cnt = 0 h_cnt = 0 for _ in range(n): s = eval(input()) if s[0] == "M": m_cnt += 1 elif s[0] == "A": a_cnt += 1 elif s[0] == "R": r_cnt += 1 elif s[0] == "C": c_cnt += 1 elif s[0] == "H": h_cnt += 1 lst = [m_cnt, a_cnt, r_cnt, c_cnt, h_cnt] ans = 0 for i in range(5): for j in range(i + 1, 5): for k in range(j + 1, 5): ans += lst[i] * lst[j] * lst[k] print(ans)
false
60
[ "-# ABC89 C", "+import sys", "+from bisect import bisect_right as br", "+from bisect import bisect_left as bl", "-n = int(eval(input()))", "-s = [eval(input()) for _ in range(n)]", "-m, a, r, c, h = 0, 0, 0, 0, 0", "-for i in s:", "- if i[0] == \"M\":", "- m += 1", "- elif i[0] == \"A\":", "- a += 1", "- elif i[0] == \"R\":", "- r += 1", "- elif i[0] == \"C\":", "- c += 1", "- elif i[0] == \"H\":", "- h += 1", "-ans = (", "- m * a * r", "- + m * a * c", "- + m * a * h", "- + m * r * c", "- + m * r * h", "- + m * c * h", "- + a * r * c", "- + a * r * h", "- + a * c * h", "- + r * c * h", "-)", "+sys.setrecursionlimit(2147483647)", "+from heapq import heappush, heappop, heappushpop", "+from collections import defaultdict", "+from itertools import accumulate", "+from collections import Counter", "+from collections import deque", "+from operator import itemgetter", "+from itertools import permutations", "+", "+mod = 10**9 + 7", "+inf = float(\"inf\")", "+", "+", "+def I():", "+ return int(sys.stdin.readline())", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+n = I()", "+m_cnt = 0", "+a_cnt = 0", "+r_cnt = 0", "+c_cnt = 0", "+h_cnt = 0", "+for _ in range(n):", "+ s = eval(input())", "+ if s[0] == \"M\":", "+ m_cnt += 1", "+ elif s[0] == \"A\":", "+ a_cnt += 1", "+ elif s[0] == \"R\":", "+ r_cnt += 1", "+ elif s[0] == \"C\":", "+ c_cnt += 1", "+ elif s[0] == \"H\":", "+ h_cnt += 1", "+lst = [m_cnt, a_cnt, r_cnt, c_cnt, h_cnt]", "+ans = 0", "+for i in range(5):", "+ for j in range(i + 1, 5):", "+ for k in range(j + 1, 5):", "+ ans += lst[i] * lst[j] * lst[k]" ]
false
0.04497
0.043808
1.026528
[ "s600444973", "s856045894" ]
u013202780
p02552
python
s010307306
s537823514
29
26
9,016
9,148
Accepted
Accepted
10.34
print((0 if int(eval(input()))==1 else 1))
print((int(eval(input()))^1))
1
1
34
21
print((0 if int(eval(input())) == 1 else 1))
print((int(eval(input())) ^ 1))
false
0
[ "-print((0 if int(eval(input())) == 1 else 1))", "+print((int(eval(input())) ^ 1))" ]
false
0.040191
0.068184
0.589449
[ "s010307306", "s537823514" ]
u189487046
p03240
python
s549603690
s007045774
910
29
3,188
3,064
Accepted
Accepted
96.81
import sys def input(): return sys.stdin.readline()[:-1] N = int(eval(input())) P = [] for _ in range(N): x, y, h = list(map(int, input().split())) P.append([x, y, h]) for i in range(N): x, y, h = P[i] for cx in range(101): for cy in range(101): H = h + abs(x-cx)+abs(y-cy) if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P): print((cx, cy, H)) exit(0)
import sys def input(): return sys.stdin.readline()[:-1] N = int(eval(input())) P = [] for _ in range(N): x, y, h = list(map(int, input().split())) P.append([x, y, h]) if h != 0: tx, ty, th = x, y, h for cx in range(101): for cy in range(101): H = th + abs(tx-cx)+abs(ty-cy) if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P): print((cx, cy, H)) exit(0)
21
22
471
458
import sys def input(): return sys.stdin.readline()[:-1] N = int(eval(input())) P = [] for _ in range(N): x, y, h = list(map(int, input().split())) P.append([x, y, h]) for i in range(N): x, y, h = P[i] for cx in range(101): for cy in range(101): H = h + abs(x - cx) + abs(y - cy) if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P): print((cx, cy, H)) exit(0)
import sys def input(): return sys.stdin.readline()[:-1] N = int(eval(input())) P = [] for _ in range(N): x, y, h = list(map(int, input().split())) P.append([x, y, h]) if h != 0: tx, ty, th = x, y, h for cx in range(101): for cy in range(101): H = th + abs(tx - cx) + abs(ty - cy) if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P): print((cx, cy, H)) exit(0)
false
4.545455
[ "-for i in range(N):", "- x, y, h = P[i]", "- for cx in range(101):", "- for cy in range(101):", "- H = h + abs(x - cx) + abs(y - cy)", "- if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):", "- print((cx, cy, H))", "- exit(0)", "+ if h != 0:", "+ tx, ty, th = x, y, h", "+for cx in range(101):", "+ for cy in range(101):", "+ H = th + abs(tx - cx) + abs(ty - cy)", "+ if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):", "+ print((cx, cy, H))", "+ exit(0)" ]
false
0.10988
0.037373
2.940079
[ "s549603690", "s007045774" ]
u811841526
p02406
python
s117655273
s846718965
50
20
8,204
5,884
Accepted
Accepted
60
n = int(input()) for i in range(1,n+1): x = i if x % 3 == 0: print('', i, end='') else: while True: if x % 10 == 3: print('', i, end='') break x //= 10 if x == 0: break print()
n = int(input()) for i in range(1, n+1): if i % 3 == 0 or '3' in str(i): print(f' {i}', end='') print()
14
5
298
120
n = int(input()) for i in range(1, n + 1): x = i if x % 3 == 0: print("", i, end="") else: while True: if x % 10 == 3: print("", i, end="") break x //= 10 if x == 0: break print()
n = int(input()) for i in range(1, n + 1): if i % 3 == 0 or "3" in str(i): print(f" {i}", end="") print()
false
64.285714
[ "- x = i", "- if x % 3 == 0:", "- print(\"\", i, end=\"\")", "- else:", "- while True:", "- if x % 10 == 3:", "- print(\"\", i, end=\"\")", "- break", "- x //= 10", "- if x == 0:", "- break", "+ if i % 3 == 0 or \"3\" in str(i):", "+ print(f\" {i}\", end=\"\")" ]
false
0.038838
0.038705
1.003438
[ "s117655273", "s846718965" ]
u073852194
p02889
python
s540827237
s975947116
1,662
1,315
125,148
67,164
Accepted
Accepted
20.88
def main(): import sys input = sys.stdin.readline n,m,l = list(map(int,input().split())) Edge = [list(map(int,input().split())) for i in range(m)] q = int(eval(input())) Query = [list(map(int,input().split())) for i in range(q)] D2 = [[float("inf") for i in range(n)] for i in range(n)] for i in range(m): D2[Edge[i][0]-1][Edge[i][1]-1] = Edge[i][2] D2[Edge[i][1]-1][Edge[i][0]-1] = Edge[i][2] for i in range(n): D2[i][i] = 0 def warshall_floyd(d): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d D2 = warshall_floyd(D2) D = [[float("inf") for i in range(n)] for i in range(n)] for i in range(m): if Edge[i][2] <= l: D[Edge[i][0]-1][Edge[i][1]-1] = 1 D[Edge[i][1]-1][Edge[i][0]-1] = 1 for i in range(n): D[i][i] = 0 for i in range(n): for j in range(n): if D2[i][j] <= l: D[i][j] = 1 D = warshall_floyd(D) for query in Query: if D[query[0]-1][query[1]-1] != float('inf'): print((D[query[0]-1][query[1]-1]-1)) else: print((-1)) if __name__ == '__main__': main()
import sys input = sys.stdin.readline class Graph(): #non-directed def __init__(self, n, edge): self.n = n self.graph = [[] for _ in range(n)] for e in edge: self.graph[e[0] - 1].append((e[1] - 1, e[2])) self.graph[e[1] - 1].append((e[0] - 1, e[2])) def warshall_floyd(self, INF=10**18): dist = [[INF for j in range(self.n)] for i in range(self.n)] for i in range(self.n): dist[i][i] = 0 for i in range(self.n): for j, cost in self.graph[i]: dist[i][j] = cost for k in range(self.n): for i in range(self.n): for j in range(self.n): if dist[i][k] != INF and dist[k][j] != INF: dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) return dist INF = 10**18 N, M, L = list(map(int, input().split())) E = [tuple(map(int, input().split())) for _ in range(M)] G = Graph(N, E) D = G.warshall_floyd() for i in range(N): for j in range(N): if i == j: continue if D[i][j] > L: D[i][j] = INF else: D[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): if D[i][k] != INF and D[k][j] != INF: D[i][j] = min(D[i][j], D[i][k] + D[k][j]) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) if D[s - 1][t - 1] != INF: print((D[s - 1][t - 1] - 1)) else: print((-1))
47
56
1,334
1,573
def main(): import sys input = sys.stdin.readline n, m, l = list(map(int, input().split())) Edge = [list(map(int, input().split())) for i in range(m)] q = int(eval(input())) Query = [list(map(int, input().split())) for i in range(q)] D2 = [[float("inf") for i in range(n)] for i in range(n)] for i in range(m): D2[Edge[i][0] - 1][Edge[i][1] - 1] = Edge[i][2] D2[Edge[i][1] - 1][Edge[i][0] - 1] = Edge[i][2] for i in range(n): D2[i][i] = 0 def warshall_floyd(d): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d D2 = warshall_floyd(D2) D = [[float("inf") for i in range(n)] for i in range(n)] for i in range(m): if Edge[i][2] <= l: D[Edge[i][0] - 1][Edge[i][1] - 1] = 1 D[Edge[i][1] - 1][Edge[i][0] - 1] = 1 for i in range(n): D[i][i] = 0 for i in range(n): for j in range(n): if D2[i][j] <= l: D[i][j] = 1 D = warshall_floyd(D) for query in Query: if D[query[0] - 1][query[1] - 1] != float("inf"): print((D[query[0] - 1][query[1] - 1] - 1)) else: print((-1)) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class Graph: # non-directed def __init__(self, n, edge): self.n = n self.graph = [[] for _ in range(n)] for e in edge: self.graph[e[0] - 1].append((e[1] - 1, e[2])) self.graph[e[1] - 1].append((e[0] - 1, e[2])) def warshall_floyd(self, INF=10**18): dist = [[INF for j in range(self.n)] for i in range(self.n)] for i in range(self.n): dist[i][i] = 0 for i in range(self.n): for j, cost in self.graph[i]: dist[i][j] = cost for k in range(self.n): for i in range(self.n): for j in range(self.n): if dist[i][k] != INF and dist[k][j] != INF: dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) return dist INF = 10**18 N, M, L = list(map(int, input().split())) E = [tuple(map(int, input().split())) for _ in range(M)] G = Graph(N, E) D = G.warshall_floyd() for i in range(N): for j in range(N): if i == j: continue if D[i][j] > L: D[i][j] = INF else: D[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): if D[i][k] != INF and D[k][j] != INF: D[i][j] = min(D[i][j], D[i][k] + D[k][j]) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) if D[s - 1][t - 1] != INF: print((D[s - 1][t - 1] - 1)) else: print((-1))
false
16.071429
[ "-def main():", "- import sys", "+import sys", "- input = sys.stdin.readline", "- n, m, l = list(map(int, input().split()))", "- Edge = [list(map(int, input().split())) for i in range(m)]", "- q = int(eval(input()))", "- Query = [list(map(int, input().split())) for i in range(q)]", "- D2 = [[float(\"inf\") for i in range(n)] for i in range(n)]", "- for i in range(m):", "- D2[Edge[i][0] - 1][Edge[i][1] - 1] = Edge[i][2]", "- D2[Edge[i][1] - 1][Edge[i][0] - 1] = Edge[i][2]", "- for i in range(n):", "- D2[i][i] = 0", "-", "- def warshall_floyd(d):", "- for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- d[i][j] = min(d[i][j], d[i][k] + d[k][j])", "- return d", "-", "- D2 = warshall_floyd(D2)", "- D = [[float(\"inf\") for i in range(n)] for i in range(n)]", "- for i in range(m):", "- if Edge[i][2] <= l:", "- D[Edge[i][0] - 1][Edge[i][1] - 1] = 1", "- D[Edge[i][1] - 1][Edge[i][0] - 1] = 1", "- for i in range(n):", "- D[i][i] = 0", "- for i in range(n):", "- for j in range(n):", "- if D2[i][j] <= l:", "- D[i][j] = 1", "- D = warshall_floyd(D)", "- for query in Query:", "- if D[query[0] - 1][query[1] - 1] != float(\"inf\"):", "- print((D[query[0] - 1][query[1] - 1] - 1))", "- else:", "- print((-1))", "+input = sys.stdin.readline", "-if __name__ == \"__main__\":", "- main()", "+class Graph: # non-directed", "+ def __init__(self, n, edge):", "+ self.n = n", "+ self.graph = [[] for _ in range(n)]", "+ for e in edge:", "+ self.graph[e[0] - 1].append((e[1] - 1, e[2]))", "+ self.graph[e[1] - 1].append((e[0] - 1, e[2]))", "+", "+ def warshall_floyd(self, INF=10**18):", "+ dist = [[INF for j in range(self.n)] for i in range(self.n)]", "+ for i in range(self.n):", "+ dist[i][i] = 0", "+ for i in range(self.n):", "+ for j, cost in self.graph[i]:", "+ dist[i][j] = cost", "+ for k in range(self.n):", "+ for i in range(self.n):", "+ for j in range(self.n):", "+ if dist[i][k] != INF and dist[k][j] != INF:", "+ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "+ return dist", "+", "+", "+INF = 10**18", "+N, M, L = list(map(int, input().split()))", "+E = [tuple(map(int, input().split())) for _ in range(M)]", "+G = Graph(N, E)", "+D = G.warshall_floyd()", "+for i in range(N):", "+ for j in range(N):", "+ if i == j:", "+ continue", "+ if D[i][j] > L:", "+ D[i][j] = INF", "+ else:", "+ D[i][j] = 1", "+for k in range(N):", "+ for i in range(N):", "+ for j in range(N):", "+ if D[i][k] != INF and D[k][j] != INF:", "+ D[i][j] = min(D[i][j], D[i][k] + D[k][j])", "+Q = int(eval(input()))", "+for _ in range(Q):", "+ s, t = list(map(int, input().split()))", "+ if D[s - 1][t - 1] != INF:", "+ print((D[s - 1][t - 1] - 1))", "+ else:", "+ print((-1))" ]
false
0.079883
0.070995
1.125194
[ "s540827237", "s975947116" ]
u977389981
p03779
python
s972921568
s368339917
29
25
2,940
2,940
Accepted
Accepted
13.79
x = int(eval(input())) time = 0 leap = 0 while leap < x: time += 1 leap += time print(time)
x = int(eval(input())) acc = 0 for i in range(1, x + 1): acc += i if acc >= x: print(i) break
7
8
99
119
x = int(eval(input())) time = 0 leap = 0 while leap < x: time += 1 leap += time print(time)
x = int(eval(input())) acc = 0 for i in range(1, x + 1): acc += i if acc >= x: print(i) break
false
12.5
[ "-time = 0", "-leap = 0", "-while leap < x:", "- time += 1", "- leap += time", "-print(time)", "+acc = 0", "+for i in range(1, x + 1):", "+ acc += i", "+ if acc >= x:", "+ print(i)", "+ break" ]
false
0.082063
0.086292
0.950983
[ "s972921568", "s368339917" ]
u263830634
p03147
python
s603959588
s425396520
23
17
3,064
3,064
Accepted
Accepted
26.09
N = int(eval(input())) lst = list(map(int, input().split())) count = 0 #水をやる回数 def water(i, j): #lst[i:j]に水をやるとする count = 0 #print ('A') #print ('lst', lst[i:j]) #print ('i, j=', i, j) if i == j or lst[i:j] == [0]: #print ('X') return 0 elif min(lst[i:j]) == 0: #lst[i:j]内の最小値が0の時 a = lst[i:j].index(0) #print ('a=', a) #print ('B', count) count = water(i,i + a) + water(i + a+1, j) return count else: #lst[i:j]の最小値が0でない時 for x in range(i,j): lst[x] = lst[x] - 1 #print ('C', count) count += 1 + water(i, j) return count print((water(0, N)))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 N = int(eval(input())) H = list(map(int, input().split())) if N == 1: print((H[0])) exit() ans = 00 i = 1 for i in range(N - 1): if H[i] < H[i + 1]: continue else: ans += H[i] - H[i + 1] ans += H[N - 1] print (ans)
28
22
693
351
N = int(eval(input())) lst = list(map(int, input().split())) count = 0 # 水をやる回数 def water(i, j): # lst[i:j]に水をやるとする count = 0 # print ('A') # print ('lst', lst[i:j]) # print ('i, j=', i, j) if i == j or lst[i:j] == [0]: # print ('X') return 0 elif min(lst[i:j]) == 0: # lst[i:j]内の最小値が0の時 a = lst[i:j].index(0) # print ('a=', a) # print ('B', count) count = water(i, i + a) + water(i + a + 1, j) return count else: # lst[i:j]の最小値が0でない時 for x in range(i, j): lst[x] = lst[x] - 1 # print ('C', count) count += 1 + water(i, j) return count print((water(0, N)))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) MOD = 10**9 + 7 N = int(eval(input())) H = list(map(int, input().split())) if N == 1: print((H[0])) exit() ans = 00 i = 1 for i in range(N - 1): if H[i] < H[i + 1]: continue else: ans += H[i] - H[i + 1] ans += H[N - 1] print(ans)
false
21.428571
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**9)", "+MOD = 10**9 + 7", "-lst = list(map(int, input().split()))", "-count = 0 # 水をやる回数", "-", "-", "-def water(i, j): # lst[i:j]に水をやるとする", "- count = 0", "- # print ('A')", "- # print ('lst', lst[i:j])", "- # print ('i, j=', i, j)", "- if i == j or lst[i:j] == [0]:", "- # print ('X')", "- return 0", "- elif min(lst[i:j]) == 0: # lst[i:j]内の最小値が0の時", "- a = lst[i:j].index(0)", "- # print ('a=', a)", "- # print ('B', count)", "- count = water(i, i + a) + water(i + a + 1, j)", "- return count", "- else: # lst[i:j]の最小値が0でない時", "- for x in range(i, j):", "- lst[x] = lst[x] - 1", "- # print ('C', count)", "- count += 1 + water(i, j)", "- return count", "-", "-", "-print((water(0, N)))", "+H = list(map(int, input().split()))", "+if N == 1:", "+ print((H[0]))", "+ exit()", "+ans = 00", "+i = 1", "+for i in range(N - 1):", "+ if H[i] < H[i + 1]:", "+ continue", "+ else:", "+ ans += H[i] - H[i + 1]", "+ans += H[N - 1]", "+print(ans)" ]
false
0.035857
0.116722
0.307198
[ "s603959588", "s425396520" ]
u254871849
p03017
python
s098544293
s895402584
27
18
3,572
3,572
Accepted
Accepted
33.33
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = '#' + sys.stdin.readline().rstrip() if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]: ans = 'No' else: if c < d: ans = 'Yes' else: for i in range(b, d+1): if s[i-1] == s[i] == s[i+1] == '.': ans = 'Yes' break else: ans = 'No' print(ans) if __name__ == '__main__': main()
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = '#' + sys.stdin.readline().rstrip() if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]: ans = 'No' else: if c < d: ans = 'Yes' else: # for i in range(b, d+1): # if s[i-1] == s[i] == s[i+1] == '.': # ans = 'Yes' # break if '...' in s[b-1:d+2]: ans = 'Yes' else: ans = 'No' print(ans) if __name__ == '__main__': main()
25
27
576
650
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = "#" + sys.stdin.readline().rstrip() if "##" in s[a + 1 : c - 1] or "##" in s[b + 1 : d - 1]: ans = "No" else: if c < d: ans = "Yes" else: for i in range(b, d + 1): if s[i - 1] == s[i] == s[i + 1] == ".": ans = "Yes" break else: ans = "No" print(ans) if __name__ == "__main__": main()
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = "#" + sys.stdin.readline().rstrip() if "##" in s[a + 1 : c - 1] or "##" in s[b + 1 : d - 1]: ans = "No" else: if c < d: ans = "Yes" else: # for i in range(b, d+1): # if s[i-1] == s[i] == s[i+1] == '.': # ans = 'Yes' # break if "..." in s[b - 1 : d + 2]: ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()
false
7.407407
[ "- for i in range(b, d + 1):", "- if s[i - 1] == s[i] == s[i + 1] == \".\":", "- ans = \"Yes\"", "- break", "+ # for i in range(b, d+1):", "+ # if s[i-1] == s[i] == s[i+1] == '.':", "+ # ans = 'Yes'", "+ # break", "+ if \"...\" in s[b - 1 : d + 2]:", "+ ans = \"Yes\"" ]
false
0.052541
0.04716
1.114112
[ "s098544293", "s895402584" ]
u490642448
p02852
python
s047405821
s193255997
250
185
56,604
50,740
Accepted
Accepted
26
n,m = list(map(int,input().split())) s = eval(input()) s_0 = [] for i in range(n+1): if(s[i] == '0'): s_0.append(i) # 二分木 import bisect now = n ans_rev = [] while(now != 0): next_i = bisect.bisect_left(s_0, now-m) next = s_0[next_i] if(now == next): print((-1)) exit() ans_rev.append(now-next) now = next print((' '.join(map(str, ans_rev[::-1]))))
n,m = list(map(int,input().split())) s = eval(input()) now = n ans_rev = [] while(now != 0): for i in range( max(0,now-m),now+1): if(i == now): print((-1)) exit() if(s[i] == '1'): continue ans_rev.append(now - i) now = i break print((' '.join(map(str, ans_rev[::-1]))))
23
18
405
353
n, m = list(map(int, input().split())) s = eval(input()) s_0 = [] for i in range(n + 1): if s[i] == "0": s_0.append(i) # 二分木 import bisect now = n ans_rev = [] while now != 0: next_i = bisect.bisect_left(s_0, now - m) next = s_0[next_i] if now == next: print((-1)) exit() ans_rev.append(now - next) now = next print((" ".join(map(str, ans_rev[::-1]))))
n, m = list(map(int, input().split())) s = eval(input()) now = n ans_rev = [] while now != 0: for i in range(max(0, now - m), now + 1): if i == now: print((-1)) exit() if s[i] == "1": continue ans_rev.append(now - i) now = i break print((" ".join(map(str, ans_rev[::-1]))))
false
21.73913
[ "-s_0 = []", "-for i in range(n + 1):", "- if s[i] == \"0\":", "- s_0.append(i)", "-# 二分木", "-import bisect", "-", "- next_i = bisect.bisect_left(s_0, now - m)", "- next = s_0[next_i]", "- if now == next:", "- print((-1))", "- exit()", "- ans_rev.append(now - next)", "- now = next", "+ for i in range(max(0, now - m), now + 1):", "+ if i == now:", "+ print((-1))", "+ exit()", "+ if s[i] == \"1\":", "+ continue", "+ ans_rev.append(now - i)", "+ now = i", "+ break" ]
false
0.033601
0.039527
0.850095
[ "s047405821", "s193255997" ]
u883203948
p03127
python
s191184616
s095610386
142
91
14,252
14,224
Accepted
Accepted
35.92
N = int(eval(input())) data = [int(i) for i in input().split()] i = 0 def euq(x,y): a = max(x,y) b = min(x,y) if a % b == 0: return b else: return euq(b, a % b) while i < N-1: com = euq(data[i],data[i + 1]) data[i+1] = com i += 1 print(com)
n = int(eval(input())) data = [int(s) for s in input().split()] def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) x = gcd(data[0], data[1]) for i in range(2,n-1): x = gcd(x,data[i]) print(x)
23
14
294
237
N = int(eval(input())) data = [int(i) for i in input().split()] i = 0 def euq(x, y): a = max(x, y) b = min(x, y) if a % b == 0: return b else: return euq(b, a % b) while i < N - 1: com = euq(data[i], data[i + 1]) data[i + 1] = com i += 1 print(com)
n = int(eval(input())) data = [int(s) for s in input().split()] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) x = gcd(data[0], data[1]) for i in range(2, n - 1): x = gcd(x, data[i]) print(x)
false
39.130435
[ "-N = int(eval(input()))", "-data = [int(i) for i in input().split()]", "-i = 0", "+n = int(eval(input()))", "+data = [int(s) for s in input().split()]", "-def euq(x, y):", "- a = max(x, y)", "- b = min(x, y)", "- if a % b == 0:", "- return b", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "- return euq(b, a % b)", "+ return gcd(b, a % b)", "-while i < N - 1:", "- com = euq(data[i], data[i + 1])", "- data[i + 1] = com", "- i += 1", "-print(com)", "+x = gcd(data[0], data[1])", "+for i in range(2, n - 1):", "+ x = gcd(x, data[i])", "+print(x)" ]
false
0.069266
0.043383
1.596608
[ "s191184616", "s095610386" ]
u379142263
p02887
python
s012233680
s888121986
116
51
3,956
3,956
Accepted
Accepted
56.03
n = int(eval(input())) s = eval(input()) ans = [] i = 0 while i != n: cnt = 1 for j in range(i+1,n): if s[i] == s[j]: cnt+=1 else: break ans.append(s[i]) if cnt>=2: i+=cnt else: i+=1 print((len(ans)))
n = int(eval(input())) s = eval(input()) ans = [s[0]] for i in range(n-1): if s[i]!= s[i+1]: ans.append(s[i+1]) print((len(ans)))
20
7
292
133
n = int(eval(input())) s = eval(input()) ans = [] i = 0 while i != n: cnt = 1 for j in range(i + 1, n): if s[i] == s[j]: cnt += 1 else: break ans.append(s[i]) if cnt >= 2: i += cnt else: i += 1 print((len(ans)))
n = int(eval(input())) s = eval(input()) ans = [s[0]] for i in range(n - 1): if s[i] != s[i + 1]: ans.append(s[i + 1]) print((len(ans)))
false
65
[ "-ans = []", "-i = 0", "-while i != n:", "- cnt = 1", "- for j in range(i + 1, n):", "- if s[i] == s[j]:", "- cnt += 1", "- else:", "- break", "- ans.append(s[i])", "- if cnt >= 2:", "- i += cnt", "- else:", "- i += 1", "+ans = [s[0]]", "+for i in range(n - 1):", "+ if s[i] != s[i + 1]:", "+ ans.append(s[i + 1])" ]
false
0.05025
0.049725
1.010562
[ "s012233680", "s888121986" ]
u287341833
p03013
python
s859865263
s714380906
323
178
16,288
13,216
Accepted
Accepted
44.89
import sys import numpy as np MOD = 1000000007 def main(): n, m = [int(x) for x in input().split()] pattern = [1] broken = -1 brokencnt = 0 if brokencnt < m: broken = int(eval(input())) brokencnt += 1 for i in range(1, n + 1): if i == broken: pattern.append(0) if brokencnt < m: broken = int(eval(input())) brokencnt += 1 continue if i == 1: pattern.append(pattern[i - 1]) if i > 1: pattern.append((pattern[i - 1] + pattern[i - 2]) % MOD) print((pattern[n])) main()
# -*- coding: utf-8 -*- """ Created on Wed Jun 19 17:29:01 2019 @author: makigon """ mod = 10 ** 9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for i in range(M)] aset = set(a) f = [0 for i in range(N)] f[0] = 1 if 1 in a and N>=2 : f[1] = 0 elif 1 not in a and N>=2: f[1] = 1 for i in range(2,N): if i in aset: continue else: f[i] = f[i-1]+f[i-2] f[i] %= mod if N == 1: print((f[N-1])) else: print(((f[N-1]+f[N-2]) % mod))
24
31
634
525
import sys import numpy as np MOD = 1000000007 def main(): n, m = [int(x) for x in input().split()] pattern = [1] broken = -1 brokencnt = 0 if brokencnt < m: broken = int(eval(input())) brokencnt += 1 for i in range(1, n + 1): if i == broken: pattern.append(0) if brokencnt < m: broken = int(eval(input())) brokencnt += 1 continue if i == 1: pattern.append(pattern[i - 1]) if i > 1: pattern.append((pattern[i - 1] + pattern[i - 2]) % MOD) print((pattern[n])) main()
# -*- coding: utf-8 -*- """ Created on Wed Jun 19 17:29:01 2019 @author: makigon """ mod = 10**9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for i in range(M)] aset = set(a) f = [0 for i in range(N)] f[0] = 1 if 1 in a and N >= 2: f[1] = 0 elif 1 not in a and N >= 2: f[1] = 1 for i in range(2, N): if i in aset: continue else: f[i] = f[i - 1] + f[i - 2] f[i] %= mod if N == 1: print((f[N - 1])) else: print(((f[N - 1] + f[N - 2]) % mod))
false
22.580645
[ "-import sys", "-import numpy as np", "-", "-MOD = 1000000007", "-", "-", "-def main():", "- n, m = [int(x) for x in input().split()]", "- pattern = [1]", "- broken = -1", "- brokencnt = 0", "- if brokencnt < m:", "- broken = int(eval(input()))", "- brokencnt += 1", "- for i in range(1, n + 1):", "- if i == broken:", "- pattern.append(0)", "- if brokencnt < m:", "- broken = int(eval(input()))", "- brokencnt += 1", "- continue", "- if i == 1:", "- pattern.append(pattern[i - 1])", "- if i > 1:", "- pattern.append((pattern[i - 1] + pattern[i - 2]) % MOD)", "- print((pattern[n]))", "-", "-", "-main()", "+# -*- coding: utf-8 -*-", "+\"\"\"", "+Created on Wed Jun 19 17:29:01 2019", "+@author: makigon", "+\"\"\"", "+mod = 10**9 + 7", "+N, M = list(map(int, input().split()))", "+a = [int(eval(input())) for i in range(M)]", "+aset = set(a)", "+f = [0 for i in range(N)]", "+f[0] = 1", "+if 1 in a and N >= 2:", "+ f[1] = 0", "+elif 1 not in a and N >= 2:", "+ f[1] = 1", "+for i in range(2, N):", "+ if i in aset:", "+ continue", "+ else:", "+ f[i] = f[i - 1] + f[i - 2]", "+ f[i] %= mod", "+if N == 1:", "+ print((f[N - 1]))", "+else:", "+ print(((f[N - 1] + f[N - 2]) % mod))" ]
false
0.078995
0.058462
1.351214
[ "s859865263", "s714380906" ]
u674588203
p02582
python
s743810805
s570491149
31
27
8,948
8,908
Accepted
Accepted
12.9
# AtCoder Beginner Contest 175 # A - Rainy Season S=eval(input()) if S=="RRR": print((3)) exit() if S=="SRR" or S=="RRS": print((2)) exit() if S=="SSS": print((0)) exit() else: print((1))
# AtCoder Beginner Contest 175 # A - Rainy Season S=eval(input()) ans=0 for i in range (len(S)): if S[i]=="R": tempans=1 for j in range (i+1,len(S)): if S[i]==S[j]: tempans+=1 else: if tempans>ans: ans=tempans break else: if tempans>ans: ans=tempans print(ans)
15
21
216
425
# AtCoder Beginner Contest 175 # A - Rainy Season S = eval(input()) if S == "RRR": print((3)) exit() if S == "SRR" or S == "RRS": print((2)) exit() if S == "SSS": print((0)) exit() else: print((1))
# AtCoder Beginner Contest 175 # A - Rainy Season S = eval(input()) ans = 0 for i in range(len(S)): if S[i] == "R": tempans = 1 for j in range(i + 1, len(S)): if S[i] == S[j]: tempans += 1 else: if tempans > ans: ans = tempans break else: if tempans > ans: ans = tempans print(ans)
false
28.571429
[ "-if S == \"RRR\":", "- print((3))", "- exit()", "-if S == \"SRR\" or S == \"RRS\":", "- print((2))", "- exit()", "-if S == \"SSS\":", "- print((0))", "- exit()", "-else:", "- print((1))", "+ans = 0", "+for i in range(len(S)):", "+ if S[i] == \"R\":", "+ tempans = 1", "+ for j in range(i + 1, len(S)):", "+ if S[i] == S[j]:", "+ tempans += 1", "+ else:", "+ if tempans > ans:", "+ ans = tempans", "+ break", "+ else:", "+ if tempans > ans:", "+ ans = tempans", "+print(ans)" ]
false
0.102831
0.043477
2.365176
[ "s743810805", "s570491149" ]
u489959379
p03457
python
s169590746
s500441227
378
220
27,300
27,312
Accepted
Accepted
41.8
n = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(n)] flg = False for i in range(n): t, x, y = txy[i] if x + y > t: flg = False break if (x + y) % 2 == 0: if t % 2 == 0: flg = True else: flg = False break else: if t % 2 != 0: flg = True else: flg = False break if flg: print("Yes") else: print("No")
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(n)] px, py, pt = 0, 0, 0 for i in range(n): t, x, y = XY[i] if abs(x - px) + abs(y - py) > abs(t - pt): print("No") break else: if (abs(x - px) + abs(y - py) - abs(t - pt)) % 2 != 0: print("No") break px, py, pt = x, y, t else: print("Yes") if __name__ == '__main__': resolve()
26
28
491
639
n = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(n)] flg = False for i in range(n): t, x, y = txy[i] if x + y > t: flg = False break if (x + y) % 2 == 0: if t % 2 == 0: flg = True else: flg = False break else: if t % 2 != 0: flg = True else: flg = False break if flg: print("Yes") else: print("No")
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(n)] px, py, pt = 0, 0, 0 for i in range(n): t, x, y = XY[i] if abs(x - px) + abs(y - py) > abs(t - pt): print("No") break else: if (abs(x - px) + abs(y - py) - abs(t - pt)) % 2 != 0: print("No") break px, py, pt = x, y, t else: print("Yes") if __name__ == "__main__": resolve()
false
7.142857
[ "-n = int(eval(input()))", "-txy = [list(map(int, input().split())) for _ in range(n)]", "-flg = False", "-for i in range(n):", "- t, x, y = txy[i]", "- if x + y > t:", "- flg = False", "- break", "- if (x + y) % 2 == 0:", "- if t % 2 == 0:", "- flg = True", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ XY = [list(map(int, input().split())) for _ in range(n)]", "+ px, py, pt = 0, 0, 0", "+ for i in range(n):", "+ t, x, y = XY[i]", "+ if abs(x - px) + abs(y - py) > abs(t - pt):", "+ print(\"No\")", "+ break", "- flg = False", "- break", "+ if (abs(x - px) + abs(y - py) - abs(t - pt)) % 2 != 0:", "+ print(\"No\")", "+ break", "+ px, py, pt = x, y, t", "- if t % 2 != 0:", "- flg = True", "- else:", "- flg = False", "- break", "-if flg:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+ print(\"Yes\")", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.037692
0.037565
1.003364
[ "s169590746", "s500441227" ]
u191874006
p04021
python
s710740350
s328952571
367
325
49,756
49,884
Accepted
Accepted
11.44
#!/usr/bin/env python3 #AGC3 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() a = [I() for _ in range(n)] b = sorted(a) lst = [] for i in range(n): if a[i] != b[i]: r = bl(b,a[i]) if i % 2 ^ r % 2 == 0: continue lst.append(a[i]) lst.sort() m = len(lst) ans = m//2 print(ans)
#!/usr/bin/env python3 #AGC3 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() a = [I() for _ in range(n)] b = sorted(a) lst = [] for i in range(n): if a[i] != b[i]: r = bl(b,a[i]) if i % 2 ^ r % 2 == 0: continue lst.append(a[i]) m = len(lst) ans = m//2 print(ans)
34
33
827
815
#!/usr/bin/env python3 # AGC3 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() a = [I() for _ in range(n)] b = sorted(a) lst = [] for i in range(n): if a[i] != b[i]: r = bl(b, a[i]) if i % 2 ^ r % 2 == 0: continue lst.append(a[i]) lst.sort() m = len(lst) ans = m // 2 print(ans)
#!/usr/bin/env python3 # AGC3 C import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() a = [I() for _ in range(n)] b = sorted(a) lst = [] for i in range(n): if a[i] != b[i]: r = bl(b, a[i]) if i % 2 ^ r % 2 == 0: continue lst.append(a[i]) m = len(lst) ans = m // 2 print(ans)
false
2.941176
[ "-lst.sort()" ]
false
0.098884
0.115668
0.854891
[ "s710740350", "s328952571" ]
u604839890
p03254
python
s480054433
s993267671
29
25
9,176
9,124
Accepted
Accepted
13.79
n, x = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) cnt = 0 flag = False for i in a: if i <= x: x -= i cnt += 1 if x == 0: flag = True else: break else: if not flag: cnt -= 1 print(cnt)
n, x = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) cnt = 0 flag = False for i in a: if i <= x: x -= i cnt += 1 if x == 0: break else: break else: cnt -= 1 print(cnt)
17
16
291
263
n, x = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) cnt = 0 flag = False for i in a: if i <= x: x -= i cnt += 1 if x == 0: flag = True else: break else: if not flag: cnt -= 1 print(cnt)
n, x = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) cnt = 0 flag = False for i in a: if i <= x: x -= i cnt += 1 if x == 0: break else: break else: cnt -= 1 print(cnt)
false
5.882353
[ "- flag = True", "+ break", "- if not flag:", "- cnt -= 1", "+ cnt -= 1" ]
false
0.069759
0.036814
1.894879
[ "s480054433", "s993267671" ]
u157379742
p02949
python
s519164742
s015314187
809
744
49,028
47,704
Accepted
Accepted
8.03
import sys sys.setrecursionlimit(10**9) INF = float('inf') def main(): n, m, p = list(map(int,input().split())) es = [] for _ in range(m): e = list(map(int,input().split())) es.append([e[0]-1,e[1]-1,- e[2] + p]) v_cost = [INF]*n v_cost[0] = 0 for v in range(n*2): for e in es: frm = e[0] to = e[1] if v_cost[to] > v_cost[frm]+e[2]: v_cost[to] = v_cost[frm]+e[2] if v >= n: v_cost[to] = -INF if v == n-1: prev = v_cost[-1] if prev != v_cost[-1]: return -1 return max(0,-v_cost[-1]) if __name__ =="__main__": print((main()))
import sys sys.setrecursionlimit(10**9) INF = float('inf') def main(): n, m, p = list(map(int,input().split())) es = [] for _ in range(m): e = list(map(int,input().split())) es.append([e[0]-1,e[1]-1,- e[2] + p]) v_cost = [INF]*n v_cost[0] = 0 for v in range(n*2): for e in es: frm = e[0] to = e[1] if v_cost[to] > v_cost[frm]+e[2]: v_cost[to] = v_cost[frm]+e[2] if v >= n: v_cost[to] = -INF if v == n-1: prev = v_cost[-1] if prev != v_cost[-1]: return -1 return max(0,-v_cost[-1]) if __name__ =="__main__": print((main()))
32
32
756
732
import sys sys.setrecursionlimit(10**9) INF = float("inf") def main(): n, m, p = list(map(int, input().split())) es = [] for _ in range(m): e = list(map(int, input().split())) es.append([e[0] - 1, e[1] - 1, -e[2] + p]) v_cost = [INF] * n v_cost[0] = 0 for v in range(n * 2): for e in es: frm = e[0] to = e[1] if v_cost[to] > v_cost[frm] + e[2]: v_cost[to] = v_cost[frm] + e[2] if v >= n: v_cost[to] = -INF if v == n - 1: prev = v_cost[-1] if prev != v_cost[-1]: return -1 return max(0, -v_cost[-1]) if __name__ == "__main__": print((main()))
import sys sys.setrecursionlimit(10**9) INF = float("inf") def main(): n, m, p = list(map(int, input().split())) es = [] for _ in range(m): e = list(map(int, input().split())) es.append([e[0] - 1, e[1] - 1, -e[2] + p]) v_cost = [INF] * n v_cost[0] = 0 for v in range(n * 2): for e in es: frm = e[0] to = e[1] if v_cost[to] > v_cost[frm] + e[2]: v_cost[to] = v_cost[frm] + e[2] if v >= n: v_cost[to] = -INF if v == n - 1: prev = v_cost[-1] if prev != v_cost[-1]: return -1 return max(0, -v_cost[-1]) if __name__ == "__main__": print((main()))
false
0
[ "- if v == n - 1:", "- prev = v_cost[-1]", "+ if v == n - 1:", "+ prev = v_cost[-1]" ]
false
0.045785
0.106994
0.427923
[ "s519164742", "s015314187" ]
u761529120
p03436
python
s527006501
s925332852
205
84
41,072
74,144
Accepted
Accepted
59.02
from collections import deque def main(): H, W = list(map(int, input().split())) S = list(eval(input()) for _ in range(H)) Q = deque([(0, 0)]) d = [[float('inf')] * W for _ in range(H)] d[0][0] = 0 dx = [1,0,-1,0] dy = [0,1,0,-1] while Q: h, w = Q.popleft() if h == H - 1 and w == W - 1: break for i in range(4): nh = h + dy[i] nw = w + dx[i] if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.' and d[nh][nw] == float('inf'): d[nh][nw] = min(d[nh][nw], d[h][w] + 1) Q.append((nh,nw)) if d[H-1][W-1] == float('inf'): print((-1)) exit() cnt = 0 for h in range(H): for w in range(W): if S[h][w] == '.': cnt += 1 print((cnt - d[H-1][W-1] - 1)) if __name__ == "__main__": main()
from collections import deque def main(): H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] Q = deque([]) Q.append([0,0]) dh = [1,0,-1,0] dw = [0,1,0,-1] d = [[float('inf')] * W for _ in range(H)] d[0][0] = 0 while Q: h, w = Q.popleft() if h == H - 1 and w == w - 1: break for i in range(4): nh = h + dh[i] nw = w + dw[i] if 0 <= nh < H and 0 <= nw < W: if S[nh][nw] == '.' and d[nh][nw] == float('inf'): d[nh][nw] = min(d[nh][nw], d[h][w] + 1) Q.append([nh,nw]) if d[H-1][W-1] == float('inf'): print((-1)) exit() cnt = 0 for h in range(H): for w in range(W): if S[h][w] == '.': cnt += 1 print((cnt - d[H-1][W-1] - 1)) if __name__ == "__main__": main()
43
37
933
950
from collections import deque def main(): H, W = list(map(int, input().split())) S = list(eval(input()) for _ in range(H)) Q = deque([(0, 0)]) d = [[float("inf")] * W for _ in range(H)] d[0][0] = 0 dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while Q: h, w = Q.popleft() if h == H - 1 and w == W - 1: break for i in range(4): nh = h + dy[i] nw = w + dx[i] if ( 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and d[nh][nw] == float("inf") ): d[nh][nw] = min(d[nh][nw], d[h][w] + 1) Q.append((nh, nw)) if d[H - 1][W - 1] == float("inf"): print((-1)) exit() cnt = 0 for h in range(H): for w in range(W): if S[h][w] == ".": cnt += 1 print((cnt - d[H - 1][W - 1] - 1)) if __name__ == "__main__": main()
from collections import deque def main(): H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] Q = deque([]) Q.append([0, 0]) dh = [1, 0, -1, 0] dw = [0, 1, 0, -1] d = [[float("inf")] * W for _ in range(H)] d[0][0] = 0 while Q: h, w = Q.popleft() if h == H - 1 and w == w - 1: break for i in range(4): nh = h + dh[i] nw = w + dw[i] if 0 <= nh < H and 0 <= nw < W: if S[nh][nw] == "." and d[nh][nw] == float("inf"): d[nh][nw] = min(d[nh][nw], d[h][w] + 1) Q.append([nh, nw]) if d[H - 1][W - 1] == float("inf"): print((-1)) exit() cnt = 0 for h in range(H): for w in range(W): if S[h][w] == ".": cnt += 1 print((cnt - d[H - 1][W - 1] - 1)) if __name__ == "__main__": main()
false
13.953488
[ "- S = list(eval(input()) for _ in range(H))", "- Q = deque([(0, 0)])", "+ S = [list(eval(input())) for _ in range(H)]", "+ Q = deque([])", "+ Q.append([0, 0])", "+ dh = [1, 0, -1, 0]", "+ dw = [0, 1, 0, -1]", "- dx = [1, 0, -1, 0]", "- dy = [0, 1, 0, -1]", "- if h == H - 1 and w == W - 1:", "+ if h == H - 1 and w == w - 1:", "- nh = h + dy[i]", "- nw = w + dx[i]", "- if (", "- 0 <= nh < H", "- and 0 <= nw < W", "- and S[nh][nw] == \".\"", "- and d[nh][nw] == float(\"inf\")", "- ):", "- d[nh][nw] = min(d[nh][nw], d[h][w] + 1)", "- Q.append((nh, nw))", "+ nh = h + dh[i]", "+ nw = w + dw[i]", "+ if 0 <= nh < H and 0 <= nw < W:", "+ if S[nh][nw] == \".\" and d[nh][nw] == float(\"inf\"):", "+ d[nh][nw] = min(d[nh][nw], d[h][w] + 1)", "+ Q.append([nh, nw])" ]
false
0.136875
0.136852
1.000169
[ "s527006501", "s925332852" ]
u536034761
p03273
python
s633210096
s485605492
35
30
9,144
9,176
Accepted
Accepted
14.29
H, W = list(map(int, input().split())) L = [] brank = "." * W ban = [] for _ in range(H): s = eval(input()) if brank == s: continue L.append(list(map(str, s))) for i in range(W): for l in L: if l[i] != ".": break else: ban.append(i) continue for l in L: ans = "" for i in range(W): if i in ban: continue ans += l[i] print(ans)
H, W = list(map(int, input().split())) L = [] brank = "." * W for _ in range(H): S = eval(input()) if S == brank: continue L.append(list(map(str, S))) if L: L1 = list(zip(*L)) brank = tuple(["." for _ in range(len(L1[0]))]) ans = [] for l in L1: if l == brank: continue ans.append(l) for a in zip(*ans): print(("".join(a)))
25
22
394
372
H, W = list(map(int, input().split())) L = [] brank = "." * W ban = [] for _ in range(H): s = eval(input()) if brank == s: continue L.append(list(map(str, s))) for i in range(W): for l in L: if l[i] != ".": break else: ban.append(i) continue for l in L: ans = "" for i in range(W): if i in ban: continue ans += l[i] print(ans)
H, W = list(map(int, input().split())) L = [] brank = "." * W for _ in range(H): S = eval(input()) if S == brank: continue L.append(list(map(str, S))) if L: L1 = list(zip(*L)) brank = tuple(["." for _ in range(len(L1[0]))]) ans = [] for l in L1: if l == brank: continue ans.append(l) for a in zip(*ans): print(("".join(a)))
false
12
[ "-ban = []", "- s = eval(input())", "- if brank == s:", "+ S = eval(input())", "+ if S == brank:", "- L.append(list(map(str, s)))", "-for i in range(W):", "- for l in L:", "- if l[i] != \".\":", "- break", "- else:", "- ban.append(i)", "- continue", "-for l in L:", "- ans = \"\"", "- for i in range(W):", "- if i in ban:", "+ L.append(list(map(str, S)))", "+if L:", "+ L1 = list(zip(*L))", "+ brank = tuple([\".\" for _ in range(len(L1[0]))])", "+ ans = []", "+ for l in L1:", "+ if l == brank:", "- ans += l[i]", "- print(ans)", "+ ans.append(l)", "+ for a in zip(*ans):", "+ print((\"\".join(a)))" ]
false
0.039185
0.038633
1.014301
[ "s633210096", "s485605492" ]
u952708174
p03945
python
s453579852
s378562854
43
38
3,188
4,132
Accepted
Accepted
11.63
S = input().strip() stone = S[0] ans = 0 for i in range(1,len(S)): if stone != S[i]: ans += 1 stone = S[i] print(ans)
# ans = len(list(more_itertools.unique_justseen(S))) - 1 # としたいが、more_itertoolsは入っていないみたいなので、 # https://github.com/erikrose/more-itertools/blob/master/more_itertools/recipes.py # にある実装を流用している def c_1d_reversi(S): # 端の同じ色の石は1個の石を置けばひっくり返せる # 連続した石をひとまとめにしたとき、何個の石があるかが解を導く def unique_justseen(iterable, key=None): from itertools import groupby from operator import itemgetter return list(map(next, list(map(itemgetter(1), groupby(iterable, key))))) ans = len(list(unique_justseen(S))) - 1 return ans S = eval(input()) print((c_1d_reversi(S)))
8
19
134
587
S = input().strip() stone = S[0] ans = 0 for i in range(1, len(S)): if stone != S[i]: ans += 1 stone = S[i] print(ans)
# ans = len(list(more_itertools.unique_justseen(S))) - 1 # としたいが、more_itertoolsは入っていないみたいなので、 # https://github.com/erikrose/more-itertools/blob/master/more_itertools/recipes.py # にある実装を流用している def c_1d_reversi(S): # 端の同じ色の石は1個の石を置けばひっくり返せる # 連続した石をひとまとめにしたとき、何個の石があるかが解を導く def unique_justseen(iterable, key=None): from itertools import groupby from operator import itemgetter return list(map(next, list(map(itemgetter(1), groupby(iterable, key))))) ans = len(list(unique_justseen(S))) - 1 return ans S = eval(input()) print((c_1d_reversi(S)))
false
57.894737
[ "-S = input().strip()", "-stone = S[0]", "-ans = 0", "-for i in range(1, len(S)):", "- if stone != S[i]:", "- ans += 1", "- stone = S[i]", "-print(ans)", "+# ans = len(list(more_itertools.unique_justseen(S))) - 1", "+# としたいが、more_itertoolsは入っていないみたいなので、", "+# https://github.com/erikrose/more-itertools/blob/master/more_itertools/recipes.py", "+# にある実装を流用している", "+def c_1d_reversi(S):", "+ # 端の同じ色の石は1個の石を置けばひっくり返せる", "+ # 連続した石をひとまとめにしたとき、何個の石があるかが解を導く", "+ def unique_justseen(iterable, key=None):", "+ from itertools import groupby", "+ from operator import itemgetter", "+", "+ return list(map(next, list(map(itemgetter(1), groupby(iterable, key)))))", "+", "+ ans = len(list(unique_justseen(S))) - 1", "+ return ans", "+", "+", "+S = eval(input())", "+print((c_1d_reversi(S)))" ]
false
0.091596
0.082131
1.11524
[ "s453579852", "s378562854" ]
u733774002
p02971
python
s504901278
s535816912
1,032
894
68,568
68,568
Accepted
Accepted
13.37
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) a_max = max(a) ind_M = a.index(a_max) tmpl = a tmpl.pop(ind_M) for i in range(n): if i != ind_M: print(a_max) else: print((max(tmpl)))
def main(): n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) a_max = max(a) ind_M = a.index(a_max) tmpl = a tmpl.pop(ind_M) for i in range(n): if i != ind_M: print(a_max) else: print((max(tmpl))) if __name__ == "__main__": main()
13
18
238
348
n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) a_max = max(a) ind_M = a.index(a_max) tmpl = a tmpl.pop(ind_M) for i in range(n): if i != ind_M: print(a_max) else: print((max(tmpl)))
def main(): n = int(eval(input())) a = [] for i in range(n): a.append(int(eval(input()))) a_max = max(a) ind_M = a.index(a_max) tmpl = a tmpl.pop(ind_M) for i in range(n): if i != ind_M: print(a_max) else: print((max(tmpl))) if __name__ == "__main__": main()
false
27.777778
[ "-n = int(eval(input()))", "-a = []", "-for i in range(n):", "- a.append(int(eval(input())))", "-a_max = max(a)", "-ind_M = a.index(a_max)", "-tmpl = a", "-tmpl.pop(ind_M)", "-for i in range(n):", "- if i != ind_M:", "- print(a_max)", "- else:", "- print((max(tmpl)))", "+def main():", "+ n = int(eval(input()))", "+ a = []", "+ for i in range(n):", "+ a.append(int(eval(input())))", "+ a_max = max(a)", "+ ind_M = a.index(a_max)", "+ tmpl = a", "+ tmpl.pop(ind_M)", "+ for i in range(n):", "+ if i != ind_M:", "+ print(a_max)", "+ else:", "+ print((max(tmpl)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.071403
0.083437
0.855771
[ "s504901278", "s535816912" ]
u141610915
p03081
python
s068932133
s059984667
519
351
89,404
120,584
Accepted
Accepted
32.37
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) s = list(eval(input()))[: -1] t = [] res = 0 for _ in range(Q): u, v = input().split() t.append((u, v)) def check(x): for i in range(Q): u, v = t[i] if s[x] == u: x += (-1) ** (v == "L") if x < 0: return -1 if x >= N: return 1 return 0 ok = -1 ng = N while ng - ok > 1: m = (ok + ng) // 2 if check(m) < 0: ok = m else: ng = m res += ok + 1 ok = N ng = -1 while ok - ng > 1: m = (ok + ng) // 2 if check(m) > 0: ok = m else: ng = m res += N - ok print((N - res))
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) S = list(eval(input()))[: -1] qs = [input().split() for _ in range(Q)] def lcheck(x): i = x for t, d in qs: if S[i] == t: if d == "L": i -= 1 else: i += 1 if i in range(N): continue return i < 0 return False def rcheck(x): i = x for t, d in qs: if S[i] == t: if d == "L": i -= 1 else: i += 1 if i in range(N): continue return i >= N return False ok = -1 ng = N while ng - ok > 1: m = (ok + ng) // 2 if lcheck(m): ok = m else: ng = m res = N - ng ok = N ng = -1 while ok - ng > 1: m = (ok + ng) // 2 if rcheck(m): ok = m else: ng = m res -= N - ok print(res)
39
44
626
743
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) s = list(eval(input()))[:-1] t = [] res = 0 for _ in range(Q): u, v = input().split() t.append((u, v)) def check(x): for i in range(Q): u, v = t[i] if s[x] == u: x += (-1) ** (v == "L") if x < 0: return -1 if x >= N: return 1 return 0 ok = -1 ng = N while ng - ok > 1: m = (ok + ng) // 2 if check(m) < 0: ok = m else: ng = m res += ok + 1 ok = N ng = -1 while ok - ng > 1: m = (ok + ng) // 2 if check(m) > 0: ok = m else: ng = m res += N - ok print((N - res))
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) S = list(eval(input()))[:-1] qs = [input().split() for _ in range(Q)] def lcheck(x): i = x for t, d in qs: if S[i] == t: if d == "L": i -= 1 else: i += 1 if i in range(N): continue return i < 0 return False def rcheck(x): i = x for t, d in qs: if S[i] == t: if d == "L": i -= 1 else: i += 1 if i in range(N): continue return i >= N return False ok = -1 ng = N while ng - ok > 1: m = (ok + ng) // 2 if lcheck(m): ok = m else: ng = m res = N - ng ok = N ng = -1 while ok - ng > 1: m = (ok + ng) // 2 if rcheck(m): ok = m else: ng = m res -= N - ok print(res)
false
11.363636
[ "-s = list(eval(input()))[:-1]", "-t = []", "-res = 0", "-for _ in range(Q):", "- u, v = input().split()", "- t.append((u, v))", "+S = list(eval(input()))[:-1]", "+qs = [input().split() for _ in range(Q)]", "-def check(x):", "- for i in range(Q):", "- u, v = t[i]", "- if s[x] == u:", "- x += (-1) ** (v == \"L\")", "- if x < 0:", "- return -1", "- if x >= N:", "- return 1", "- return 0", "+def lcheck(x):", "+ i = x", "+ for t, d in qs:", "+ if S[i] == t:", "+ if d == \"L\":", "+ i -= 1", "+ else:", "+ i += 1", "+ if i in range(N):", "+ continue", "+ return i < 0", "+ return False", "+", "+", "+def rcheck(x):", "+ i = x", "+ for t, d in qs:", "+ if S[i] == t:", "+ if d == \"L\":", "+ i -= 1", "+ else:", "+ i += 1", "+ if i in range(N):", "+ continue", "+ return i >= N", "+ return False", "- if check(m) < 0:", "+ if lcheck(m):", "-res += ok + 1", "+res = N - ng", "- if check(m) > 0:", "+ if rcheck(m):", "-res += N - ok", "-print((N - res))", "+res -= N - ok", "+print(res)" ]
false
0.037368
0.066233
0.564186
[ "s068932133", "s059984667" ]
u327466606
p02579
python
s748833966
s677761869
425
322
89,580
82,392
Accepted
Accepted
24.24
max2 = lambda x,y: x if x > y else y min2 = lambda x,y: x if x < y else y import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline def solve(dist, start, goal): H,W = len(dist),len(dist[0]) q = [start] dist[start[0]][start[1]] = 0 cnt = 0 while q: nq = [] while q: x,y = q.pop() if (x,y) == goal: return cnt if dist[x][y] < cnt: continue for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)): nx,ny = x+dx,y+dy if 0<=ny<W and 0<=nx<H and dist[nx][ny] > cnt: dist[nx][ny] = cnt q.append((nx,ny)) for dx in range(-2,3): for dy in range(-2,3): nx,ny = x+dx,y+dy if 0<=ny<W and 0<=nx<H and dist[nx][ny] > cnt+1: dist[nx][ny] = cnt+1 nq.append((nx,ny)) q = nq cnt += 1 return -1 if __name__ == '__main__': H,W = list(map(int,readline().split())) start = tuple([int(i)-1 for i in readline().split()]) goal = tuple([int(i)-1 for i in readline().split()]) dist = [[10**7 if c=='.' else -1 for c in t.decode()] for t in read().split()] print((solve(dist,start,goal)))
max2 = lambda x,y: x if x > y else y min2 = lambda x,y: x if x < y else y import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2,-1),(2,0),(2,1),(2,2),(1,1)]), ((-1, 0),[(-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1)]), ((0, 1), [(1,2),(0,2),(-1,2),(-2,2),(-1,1)]), ((0, -1), [(1,-2),(0,-2),(-1,-2),(2,-2),(1,-1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d,l in CONVERTED_MOVES: nx = x+d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x+t if dist[p] > cnt+1: dist[p] = cnt+1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == '__main__': H,W = list(map(int,readline().split())) start = tuple([int(i)+1 for i in readline().split()]) goal = tuple([int(i)+1 for i in readline().split()]) H += 4 W += 4 dist = [-1]*(W*H) start = start[0]*W+start[1] goal = goal[0]*W+goal[1] for t,s in zip(count(2*W,W),read().split()): for i,c in zip(count(t+2),s.decode()): if c == '.': dist[i] = 10**7 convert = lambda x,y: x*W+y CONVERTED_MOVES = [] for d,l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d,l)) # print(CONVERTED_MOVES) print((solve(dist,start,goal)))
47
76
1,362
1,877
max2 = lambda x, y: x if x > y else y min2 = lambda x, y: x if x < y else y import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline def solve(dist, start, goal): H, W = len(dist), len(dist[0]) q = [start] dist[start[0]][start[1]] = 0 cnt = 0 while q: nq = [] while q: x, y = q.pop() if (x, y) == goal: return cnt if dist[x][y] < cnt: continue for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): nx, ny = x + dx, y + dy if 0 <= ny < W and 0 <= nx < H and dist[nx][ny] > cnt: dist[nx][ny] = cnt q.append((nx, ny)) for dx in range(-2, 3): for dy in range(-2, 3): nx, ny = x + dx, y + dy if 0 <= ny < W and 0 <= nx < H and dist[nx][ny] > cnt + 1: dist[nx][ny] = cnt + 1 nq.append((nx, ny)) q = nq cnt += 1 return -1 if __name__ == "__main__": H, W = list(map(int, readline().split())) start = tuple([int(i) - 1 for i in readline().split()]) goal = tuple([int(i) - 1 for i in readline().split()]) dist = [[10**7 if c == "." else -1 for c in t.decode()] for t in read().split()] print((solve(dist, start, goal)))
max2 = lambda x, y: x if x > y else y min2 = lambda x, y: x if x < y else y import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2, -1), (2, 0), (2, 1), (2, 2), (1, 1)]), ((-1, 0), [(-2, -1), (-2, 0), (-2, 1), (-2, -2), (-1, -1)]), ((0, 1), [(1, 2), (0, 2), (-1, 2), (-2, 2), (-1, 1)]), ((0, -1), [(1, -2), (0, -2), (-1, -2), (2, -2), (1, -1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d, l in CONVERTED_MOVES: nx = x + d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x + t if dist[p] > cnt + 1: dist[p] = cnt + 1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == "__main__": H, W = list(map(int, readline().split())) start = tuple([int(i) + 1 for i in readline().split()]) goal = tuple([int(i) + 1 for i in readline().split()]) H += 4 W += 4 dist = [-1] * (W * H) start = start[0] * W + start[1] goal = goal[0] * W + goal[1] for t, s in zip(count(2 * W, W), read().split()): for i, c in zip(count(t + 2), s.decode()): if c == ".": dist[i] = 10**7 convert = lambda x, y: x * W + y CONVERTED_MOVES = [] for d, l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d, l)) # print(CONVERTED_MOVES) print((solve(dist, start, goal)))
false
38.157895
[ "+from itertools import count", "+MOVES = [", "+ ((1, 0), [(2, -1), (2, 0), (2, 1), (2, 2), (1, 1)]),", "+ ((-1, 0), [(-2, -1), (-2, 0), (-2, 1), (-2, -2), (-1, -1)]),", "+ ((0, 1), [(1, 2), (0, 2), (-1, 2), (-2, 2), (-1, 1)]),", "+ ((0, -1), [(1, -2), (0, -2), (-1, -2), (2, -2), (1, -1)]),", "+]", "+CONVERTED_MOVES = None", "- H, W = len(dist), len(dist[0])", "- dist[start[0]][start[1]] = 0", "- x, y = q.pop()", "- if (x, y) == goal:", "+ x = q.pop()", "+ if x == goal:", "- if dist[x][y] < cnt:", "+ if dist[x] < cnt:", "- for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "- nx, ny = x + dx, y + dy", "- if 0 <= ny < W and 0 <= nx < H and dist[nx][ny] > cnt:", "- dist[nx][ny] = cnt", "- q.append((nx, ny))", "- for dx in range(-2, 3):", "- for dy in range(-2, 3):", "- nx, ny = x + dx, y + dy", "- if 0 <= ny < W and 0 <= nx < H and dist[nx][ny] > cnt + 1:", "- dist[nx][ny] = cnt + 1", "- nq.append((nx, ny))", "+ for d, l in CONVERTED_MOVES:", "+ nx = x + d", "+ if dist[nx] > cnt:", "+ dist[nx] = cnt", "+ q.append(nx)", "+ if dist[nx] < 0:", "+ for t in l:", "+ p = x + t", "+ if dist[p] > cnt + 1:", "+ dist[p] = cnt + 1", "+ nq.append(p)", "- start = tuple([int(i) - 1 for i in readline().split()])", "- goal = tuple([int(i) - 1 for i in readline().split()])", "- dist = [[10**7 if c == \".\" else -1 for c in t.decode()] for t in read().split()]", "+ start = tuple([int(i) + 1 for i in readline().split()])", "+ goal = tuple([int(i) + 1 for i in readline().split()])", "+ H += 4", "+ W += 4", "+ dist = [-1] * (W * H)", "+ start = start[0] * W + start[1]", "+ goal = goal[0] * W + goal[1]", "+ for t, s in zip(count(2 * W, W), read().split()):", "+ for i, c in zip(count(t + 2), s.decode()):", "+ if c == \".\":", "+ dist[i] = 10**7", "+ convert = lambda x, y: x * W + y", "+ CONVERTED_MOVES = []", "+ for d, l in MOVES:", "+ d = convert(*d)", "+ l = [convert(*d) for d in l]", "+ CONVERTED_MOVES.append((d, l))", "+ # print(CONVERTED_MOVES)" ]
false
0.136052
0.071
1.916216
[ "s748833966", "s677761869" ]
u777283665
p03425
python
s920410253
s200191930
187
144
3,064
4,232
Accepted
Accepted
22.99
from itertools import combinations n = int(eval(input())) d = [0] * 5 for _ in range(n): s = eval(input()) if s[0] == "M": d[0] += 1 if s[0] == "A": d[1] += 1 if s[0] == "R": d[2] += 1 if s[0] == "C": d[3] += 1 if s[0] == "H": d[4] += 1 d = [n for n in d if n !=0] comb = combinations(d, 3) ans = 0 for c in comb: ans += c[0]*c[1]*c[2] print(ans)
from itertools import combinations from collections import Counter n = int(eval(input())) s = [input()[0] for _ in range(n)] c =Counter(s) ans = 0 for x, y, z in combinations("MARCH", 3): ans += c[x] * c[y] * c[z] print(ans)
26
12
432
237
from itertools import combinations n = int(eval(input())) d = [0] * 5 for _ in range(n): s = eval(input()) if s[0] == "M": d[0] += 1 if s[0] == "A": d[1] += 1 if s[0] == "R": d[2] += 1 if s[0] == "C": d[3] += 1 if s[0] == "H": d[4] += 1 d = [n for n in d if n != 0] comb = combinations(d, 3) ans = 0 for c in comb: ans += c[0] * c[1] * c[2] print(ans)
from itertools import combinations from collections import Counter n = int(eval(input())) s = [input()[0] for _ in range(n)] c = Counter(s) ans = 0 for x, y, z in combinations("MARCH", 3): ans += c[x] * c[y] * c[z] print(ans)
false
53.846154
[ "+from collections import Counter", "-d = [0] * 5", "-for _ in range(n):", "- s = eval(input())", "- if s[0] == \"M\":", "- d[0] += 1", "- if s[0] == \"A\":", "- d[1] += 1", "- if s[0] == \"R\":", "- d[2] += 1", "- if s[0] == \"C\":", "- d[3] += 1", "- if s[0] == \"H\":", "- d[4] += 1", "-d = [n for n in d if n != 0]", "-comb = combinations(d, 3)", "+s = [input()[0] for _ in range(n)]", "+c = Counter(s)", "-for c in comb:", "- ans += c[0] * c[1] * c[2]", "+for x, y, z in combinations(\"MARCH\", 3):", "+ ans += c[x] * c[y] * c[z]" ]
false
0.086883
0.073019
1.189871
[ "s920410253", "s200191930" ]
u572142121
p03074
python
s299770914
s604417812
95
82
4,084
7,108
Accepted
Accepted
13.68
N,K=list(map(int,input().split())) S=list(eval(input())) j=0 ans=0 cnt=0 for i in range(N): if S[i]=="0": if i==0 or S[i-1]=="1": cnt+=1 if cnt>K: while S[j]=="1": j+=1 while S[j]=="0": j+=1 cnt-=1 ans=max(ans,i-j+1) print(ans)
N,K=list(map(int,input().split())) S=eval(input()) #Aは0の左端、Bは0の右端 A=[] B=[] for i in range(N-1): if S[i]=='0'and S[i+1]=='1': B.append(i) if S[-1]=='0': B.append(N-1) if S[0]=='0': A.append(0) for i in range(N-1): if S[i]=='1'and S[i+1]=='0': A.append(i+1) if len(A)<=K: print(N) else: y=A[K] z=N-B[-1*(K+1)]-1 l=0 ans=0 for i in range(len(A)-K-1): l=A[i+K+1]-B[i]-1 ans=max(l,ans) print((max(ans,y,z)))
18
27
273
454
N, K = list(map(int, input().split())) S = list(eval(input())) j = 0 ans = 0 cnt = 0 for i in range(N): if S[i] == "0": if i == 0 or S[i - 1] == "1": cnt += 1 if cnt > K: while S[j] == "1": j += 1 while S[j] == "0": j += 1 cnt -= 1 ans = max(ans, i - j + 1) print(ans)
N, K = list(map(int, input().split())) S = eval(input()) # Aは0の左端、Bは0の右端 A = [] B = [] for i in range(N - 1): if S[i] == "0" and S[i + 1] == "1": B.append(i) if S[-1] == "0": B.append(N - 1) if S[0] == "0": A.append(0) for i in range(N - 1): if S[i] == "1" and S[i + 1] == "0": A.append(i + 1) if len(A) <= K: print(N) else: y = A[K] z = N - B[-1 * (K + 1)] - 1 l = 0 ans = 0 for i in range(len(A) - K - 1): l = A[i + K + 1] - B[i] - 1 ans = max(l, ans) print((max(ans, y, z)))
false
33.333333
[ "-S = list(eval(input()))", "-j = 0", "-ans = 0", "-cnt = 0", "-for i in range(N):", "- if S[i] == \"0\":", "- if i == 0 or S[i - 1] == \"1\":", "- cnt += 1", "- if cnt > K:", "- while S[j] == \"1\":", "- j += 1", "- while S[j] == \"0\":", "- j += 1", "- cnt -= 1", "- ans = max(ans, i - j + 1)", "-print(ans)", "+S = eval(input())", "+# Aは0の左端、Bは0の右端", "+A = []", "+B = []", "+for i in range(N - 1):", "+ if S[i] == \"0\" and S[i + 1] == \"1\":", "+ B.append(i)", "+if S[-1] == \"0\":", "+ B.append(N - 1)", "+if S[0] == \"0\":", "+ A.append(0)", "+for i in range(N - 1):", "+ if S[i] == \"1\" and S[i + 1] == \"0\":", "+ A.append(i + 1)", "+if len(A) <= K:", "+ print(N)", "+else:", "+ y = A[K]", "+ z = N - B[-1 * (K + 1)] - 1", "+ l = 0", "+ ans = 0", "+ for i in range(len(A) - K - 1):", "+ l = A[i + K + 1] - B[i] - 1", "+ ans = max(l, ans)", "+ print((max(ans, y, z)))" ]
false
0.082281
0.095459
0.861957
[ "s299770914", "s604417812" ]
u647766105
p02346
python
s548252610
s693959996
2,250
1,920
8,732
8,724
Accepted
Accepted
14.67
class RangeSumQuery(object): def __init__(self, size): self.size = 1 while self.size <= size: self.size *= 2 self.data = [0] * (self.size*2+2) def add(self, idx, value): k = idx + self.size - 1 self.data[k] += value while k > 0: k = (k - 1) / 2 self.data[k] += value def get_sum(self, start, end): def query(k, left, right): if right <= start or end <= left: return 0 if start <= left and right <= end: return self.data[k] vl = query(k*2+1, left, (left+right)/2) vr = query(k*2+2, (left+right)/2, right) return sum([vl, vr]) return query(0, 0, self.size) def main(): n, q = list(map(int, input().split())) rsq = RangeSumQuery(n) for _ in range(q): com, x, y = list(map(int, input().split())) if com == 0: rsq.add(x, y) else: print(rsq.get_sum(x, y+1)) if __name__ == "__main__": main()
class RangeSumQuery(object): def __init__(self, size): self.size = 1 while self.size <= size: self.size *= 2 self.data = [0] * (self.size*2-1) def add(self, idx, value): k = idx + self.size - 1 self.data[k] += value while k > 0: k = (k - 1) / 2 self.data[k] += value def get_sum(self, start, end): def query(k, left, right): if right <= start or end <= left: return 0 if start <= left and right <= end: return self.data[k] vl = query(k*2+1, left, (left+right)/2) vr = query(k*2+2, (left+right)/2, right) return vl + vr return query(0, 0, self.size) def main(): n, q = list(map(int, input().split())) rsq = RangeSumQuery(n) for _ in range(q): com, x, y = list(map(int, input().split())) if com == 0: rsq.add(x, y) else: print(rsq.get_sum(x, y+1)) if __name__ == "__main__": main()
39
39
1,093
1,087
class RangeSumQuery(object): def __init__(self, size): self.size = 1 while self.size <= size: self.size *= 2 self.data = [0] * (self.size * 2 + 2) def add(self, idx, value): k = idx + self.size - 1 self.data[k] += value while k > 0: k = (k - 1) / 2 self.data[k] += value def get_sum(self, start, end): def query(k, left, right): if right <= start or end <= left: return 0 if start <= left and right <= end: return self.data[k] vl = query(k * 2 + 1, left, (left + right) / 2) vr = query(k * 2 + 2, (left + right) / 2, right) return sum([vl, vr]) return query(0, 0, self.size) def main(): n, q = list(map(int, input().split())) rsq = RangeSumQuery(n) for _ in range(q): com, x, y = list(map(int, input().split())) if com == 0: rsq.add(x, y) else: print(rsq.get_sum(x, y + 1)) if __name__ == "__main__": main()
class RangeSumQuery(object): def __init__(self, size): self.size = 1 while self.size <= size: self.size *= 2 self.data = [0] * (self.size * 2 - 1) def add(self, idx, value): k = idx + self.size - 1 self.data[k] += value while k > 0: k = (k - 1) / 2 self.data[k] += value def get_sum(self, start, end): def query(k, left, right): if right <= start or end <= left: return 0 if start <= left and right <= end: return self.data[k] vl = query(k * 2 + 1, left, (left + right) / 2) vr = query(k * 2 + 2, (left + right) / 2, right) return vl + vr return query(0, 0, self.size) def main(): n, q = list(map(int, input().split())) rsq = RangeSumQuery(n) for _ in range(q): com, x, y = list(map(int, input().split())) if com == 0: rsq.add(x, y) else: print(rsq.get_sum(x, y + 1)) if __name__ == "__main__": main()
false
0
[ "- self.data = [0] * (self.size * 2 + 2)", "+ self.data = [0] * (self.size * 2 - 1)", "- return sum([vl, vr])", "+ return vl + vr" ]
false
0.056462
0.03634
1.553692
[ "s548252610", "s693959996" ]
u411203878
p03050
python
s949450702
s972618978
205
72
40,172
65,440
Accepted
Accepted
64.88
n=int(eval(input())) ans = 0 for i in range(1,int(n**0.5)+2): if n%i == 0 and n//i>=i+2: ans += (n//i)-1 print(ans)
def prime(p): memo = [p] for i in range(2,(int(p**0.5)+1)): if p%i == 0: memo.append(i) memo.append(p//i) return memo x = int(eval(input())) if x== 1: print((0)) exit() memo = prime(x) ans = 0 for i in memo: if x%(i-1)==x//(i-1): ans += i-1 print(ans)
8
22
130
333
n = int(eval(input())) ans = 0 for i in range(1, int(n**0.5) + 2): if n % i == 0 and n // i >= i + 2: ans += (n // i) - 1 print(ans)
def prime(p): memo = [p] for i in range(2, (int(p**0.5) + 1)): if p % i == 0: memo.append(i) memo.append(p // i) return memo x = int(eval(input())) if x == 1: print((0)) exit() memo = prime(x) ans = 0 for i in memo: if x % (i - 1) == x // (i - 1): ans += i - 1 print(ans)
false
63.636364
[ "-n = int(eval(input()))", "+def prime(p):", "+ memo = [p]", "+ for i in range(2, (int(p**0.5) + 1)):", "+ if p % i == 0:", "+ memo.append(i)", "+ memo.append(p // i)", "+ return memo", "+", "+", "+x = int(eval(input()))", "+if x == 1:", "+ print((0))", "+ exit()", "+memo = prime(x)", "-for i in range(1, int(n**0.5) + 2):", "- if n % i == 0 and n // i >= i + 2:", "- ans += (n // i) - 1", "+for i in memo:", "+ if x % (i - 1) == x // (i - 1):", "+ ans += i - 1" ]
false
0.768454
0.39484
1.946242
[ "s949450702", "s972618978" ]
u261103969
p02780
python
s454882976
s537344320
124
96
25,188
99,496
Accepted
Accepted
22.58
n, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] sum_max = sum(p[0:k]) sum_temp = sum_max for i in range(n-k): sum_temp = sum_temp - p[i] + p[i+k] if sum_temp > sum_max: sum_max = sum_temp s_max = (sum_max + k) / 2 print(s_max)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N, K = list(map(int, readline().split())) P = [0] + list(map(int, readline().split())) cur = sum(P[:K]) s_max = 0 for i in range(N - K + 1): cur += P[K + i] cur -= P[i] s_max = max(s_max, cur) print(((s_max + K) / 2)) if __name__ == '__main__': main()
14
25
293
449
n, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] sum_max = sum(p[0:k]) sum_temp = sum_max for i in range(n - k): sum_temp = sum_temp - p[i] + p[i + k] if sum_temp > sum_max: sum_max = sum_temp s_max = (sum_max + k) / 2 print(s_max)
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N, K = list(map(int, readline().split())) P = [0] + list(map(int, readline().split())) cur = sum(P[:K]) s_max = 0 for i in range(N - K + 1): cur += P[K + i] cur -= P[i] s_max = max(s_max, cur) print(((s_max + K) / 2)) if __name__ == "__main__": main()
false
44
[ "-n, k = [int(i) for i in input().split()]", "-p = [int(i) for i in input().split()]", "-sum_max = sum(p[0:k])", "-sum_temp = sum_max", "-for i in range(n - k):", "- sum_temp = sum_temp - p[i] + p[i + k]", "- if sum_temp > sum_max:", "- sum_max = sum_temp", "-s_max = (sum_max + k) / 2", "-print(s_max)", "+import sys", "+", "+readline = sys.stdin.readline", "+MOD = 10**9 + 7", "+INF = float(\"INF\")", "+sys.setrecursionlimit(10**5)", "+", "+", "+def main():", "+ N, K = list(map(int, readline().split()))", "+ P = [0] + list(map(int, readline().split()))", "+ cur = sum(P[:K])", "+ s_max = 0", "+ for i in range(N - K + 1):", "+ cur += P[K + i]", "+ cur -= P[i]", "+ s_max = max(s_max, cur)", "+ print(((s_max + K) / 2))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.042719
0.040026
1.067273
[ "s454882976", "s537344320" ]
u202634017
p02695
python
s251652752
s477734950
256
214
90,644
88,988
Accepted
Accepted
16.41
n, m, q = list(map(int, input().split())) plist = [] for _ in range(q): plist.append(list(map(int, input().split()))) alist = [] def bfs(depth: int, l: list): global n, m, alist if depth == n: alist.append(l[1:]) return c = l[depth] cl = l.copy() cl.append(c) bfs(depth+1, cl.copy()) while c < m: c += 1 cl = l.copy() cl.append(c) bfs(depth + 1, cl.copy()) bfs(0, [1]) pmax = 0 for a in alist: point = 0 for p in plist: if (a[p[1]-1] - a[p[0]-1] == p[2]): point += p[3] pmax = max(pmax, point) print(pmax)
n, m, q = list(map(int, input().split())) plist = [] for _ in range(q): plist.append(list(map(int, input().split()))) alist = [] def bfs(depth: int, l: list): global n, m, alist if depth == n: alist.append(l[1:]) return c = l[depth] cl = l.copy() cl.append(c) bfs(depth+1, cl) while c < m: c += 1 cl = l.copy() cl.append(c) bfs(depth + 1, cl) bfs(0, [1]) pmax = 0 for a in alist: point = 0 for p in plist: if (a[p[1]-1] - a[p[0]-1] == p[2]): point += p[3] pmax = max(pmax, point) print(pmax)
34
34
651
637
n, m, q = list(map(int, input().split())) plist = [] for _ in range(q): plist.append(list(map(int, input().split()))) alist = [] def bfs(depth: int, l: list): global n, m, alist if depth == n: alist.append(l[1:]) return c = l[depth] cl = l.copy() cl.append(c) bfs(depth + 1, cl.copy()) while c < m: c += 1 cl = l.copy() cl.append(c) bfs(depth + 1, cl.copy()) bfs(0, [1]) pmax = 0 for a in alist: point = 0 for p in plist: if a[p[1] - 1] - a[p[0] - 1] == p[2]: point += p[3] pmax = max(pmax, point) print(pmax)
n, m, q = list(map(int, input().split())) plist = [] for _ in range(q): plist.append(list(map(int, input().split()))) alist = [] def bfs(depth: int, l: list): global n, m, alist if depth == n: alist.append(l[1:]) return c = l[depth] cl = l.copy() cl.append(c) bfs(depth + 1, cl) while c < m: c += 1 cl = l.copy() cl.append(c) bfs(depth + 1, cl) bfs(0, [1]) pmax = 0 for a in alist: point = 0 for p in plist: if a[p[1] - 1] - a[p[0] - 1] == p[2]: point += p[3] pmax = max(pmax, point) print(pmax)
false
0
[ "- bfs(depth + 1, cl.copy())", "+ bfs(depth + 1, cl)", "- bfs(depth + 1, cl.copy())", "+ bfs(depth + 1, cl)" ]
false
0.089243
0.251024
0.355514
[ "s251652752", "s477734950" ]
u633068244
p02269
python
s739563934
s186274424
4,020
3,690
271,868
124,308
Accepted
Accepted
8.21
dict = {"A":1,"C":2,"G":3,"T":4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]]*4**i return ans n = int(input()) ls = [0 for i in range(6710886)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
dict = {"A":1,"C":2,"G":3,"T":4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]]*4**i return ans n = int(input()) ls = [0 for i in range(3000000)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
16
16
351
351
dict = {"A": 1, "C": 2, "G": 3, "T": 4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]] * 4**i return ans n = int(input()) ls = [0 for i in range(6710886)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
dict = {"A": 1, "C": 2, "G": 3, "T": 4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]] * 4**i return ans n = int(input()) ls = [0 for i in range(3000000)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
false
0
[ "-ls = [0 for i in range(6710886)]", "+ls = [0 for i in range(3000000)]" ]
false
0.609721
0.203731
2.992777
[ "s739563934", "s186274424" ]
u600402037
p02842
python
s547924197
s848297764
1,593
18
21,608
3,060
Accepted
Accepted
98.87
import sys import numpy as np sys.setrecursionlimit(10 ** 9) stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces N = ri() x = N // 1.08 bool = True if int(x * 1.08) != N or x < 1: x += 1 if int(x * 1.08) != N: bool = False print((int(x) if bool else ':('))
import sys import math stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces N = ri() x = math.ceil(N / 1.08) bool = True if math.floor(x * 1.08) != N: bool = False print((int(x) if bool else ':('))
18
15
400
325
import sys import numpy as np sys.setrecursionlimit(10**9) stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces N = ri() x = N // 1.08 bool = True if int(x * 1.08) != N or x < 1: x += 1 if int(x * 1.08) != N: bool = False print((int(x) if bool else ":("))
import sys import math stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces N = ri() x = math.ceil(N / 1.08) bool = True if math.floor(x * 1.08) != N: bool = False print((int(x) if bool else ":("))
false
16.666667
[ "-import numpy as np", "+import math", "-sys.setrecursionlimit(10**9)", "-x = N // 1.08", "+x = math.ceil(N / 1.08)", "-if int(x * 1.08) != N or x < 1:", "- x += 1", "- if int(x * 1.08) != N:", "- bool = False", "+if math.floor(x * 1.08) != N:", "+ bool = False" ]
false
0.065696
0.067306
0.976082
[ "s547924197", "s848297764" ]
u499381410
p03674
python
s468124350
s311795167
406
347
65,440
65,568
Accepted
Accepted
14.53
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() + 1 A = LI() D = defaultdict(lambda:-1) for i in range(n): if D[A[i]] != -1: l = D[A[i]] r = n - i - 1 break else: D[A[i]] = i fac = [1] * (n + 1) inv = [1] * (n + 1) i = 1 for j in range(1, n + 1): i = i * j % mod fac[j] = i inv[j] = pow(i, mod - 2, mod) def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod for j in range(1, n + 1): print(((comb(n, j) - comb(r + l, j - 1)) % mod))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() + 1 A = LI() D = defaultdict(lambda:-1) for i in range(n): if D[A[i]] != -1: l = D[A[i]] r = n - i - 1 break else: D[A[i]] = i fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j-1] * j % mod inv[n] = pow(fac[n], mod-2, mod) for j in range(n-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod for j in range(1, n + 1): print(((comb(n, j) - comb(r + l, j - 1)) % mod))
58
59
1,462
1,520
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce INF = float("inf") def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() + 1 A = LI() D = defaultdict(lambda: -1) for i in range(n): if D[A[i]] != -1: l = D[A[i]] r = n - i - 1 break else: D[A[i]] = i fac = [1] * (n + 1) inv = [1] * (n + 1) i = 1 for j in range(1, n + 1): i = i * j % mod fac[j] = i inv[j] = pow(i, mod - 2, mod) def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod for j in range(1, n + 1): print(((comb(n, j) - comb(r + l, j - 1)) % mod))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce INF = float("inf") def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() + 1 A = LI() D = defaultdict(lambda: -1) for i in range(n): if D[A[i]] != -1: l = D[A[i]] r = n - i - 1 break else: D[A[i]] = i fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod for j in range(1, n + 1): print(((comb(n, j) - comb(r + l, j - 1)) % mod))
false
1.694915
[ "-i = 1", "- i = i * j % mod", "- fac[j] = i", "- inv[j] = pow(i, mod - 2, mod)", "+ fac[j] = fac[j - 1] * j % mod", "+inv[n] = pow(fac[n], mod - 2, mod)", "+for j in range(n - 1, -1, -1):", "+ inv[j] = inv[j + 1] * (j + 1) % mod" ]
false
0.047799
0.050114
0.953818
[ "s468124350", "s311795167" ]
u803848678
p03525
python
s490534460
s518707439
186
22
40,304
3,064
Accepted
Accepted
88.17
n = int(eval(input())) a = [0]*13 for i in map(int, input().split()): a[i] += 1 ans = 0 if any(i>2 for i in a) or a[0] or a[12]>1: pass else: s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si+[i]) nxt.append(si+[24-i]) else: for si in s: nxt.append(si+[i, 24-i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i]-si[i-1]) k = min(k, 24-k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
n = int(eval(input())) a = [0]*13 for i in map(int, input().split()): a[i] += 1 ans = 0 if not (any(i>2 for i in a) or a[0] or a[12]>1): s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si+[i]) nxt.append(si+[24-i]) else: for si in s: nxt.append(si+[i, 24-i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i]-si[i-1]) k = min(k, 24-k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
31
29
720
709
n = int(eval(input())) a = [0] * 13 for i in map(int, input().split()): a[i] += 1 ans = 0 if any(i > 2 for i in a) or a[0] or a[12] > 1: pass else: s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si + [i]) nxt.append(si + [24 - i]) else: for si in s: nxt.append(si + [i, 24 - i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i] - si[i - 1]) k = min(k, 24 - k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
n = int(eval(input())) a = [0] * 13 for i in map(int, input().split()): a[i] += 1 ans = 0 if not (any(i > 2 for i in a) or a[0] or a[12] > 1): s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si + [i]) nxt.append(si + [24 - i]) else: for si in s: nxt.append(si + [i, 24 - i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i] - si[i - 1]) k = min(k, 24 - k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
false
6.451613
[ "-if any(i > 2 for i in a) or a[0] or a[12] > 1:", "- pass", "-else:", "+if not (any(i > 2 for i in a) or a[0] or a[12] > 1):" ]
false
0.039069
0.037628
1.0383
[ "s490534460", "s518707439" ]
u185424824
p03779
python
s368696913
s557953746
29
17
2,940
2,940
Accepted
Accepted
41.38
X = int(eval(input())) total = 1 i = 1 while True: if total >= X: print(i) exit() else: i += 1 total += i
import math X = int(eval(input())) ans = (-1 + (1+8*X)**0.5)/2 print((math.ceil(ans)))
12
5
134
83
X = int(eval(input())) total = 1 i = 1 while True: if total >= X: print(i) exit() else: i += 1 total += i
import math X = int(eval(input())) ans = (-1 + (1 + 8 * X) ** 0.5) / 2 print((math.ceil(ans)))
false
58.333333
[ "+import math", "+", "-total = 1", "-i = 1", "-while True:", "- if total >= X:", "- print(i)", "- exit()", "- else:", "- i += 1", "- total += i", "+ans = (-1 + (1 + 8 * X) ** 0.5) / 2", "+print((math.ceil(ans)))" ]
false
0.082589
0.063321
1.304286
[ "s368696913", "s557953746" ]
u842054747
p02640
python
s435885515
s445658662
28
25
9,096
9,148
Accepted
Accepted
10.71
animals_num, legs_num = list(map(int, input().split())) answer = "No" for i in range(animals_num + 1): j = animals_num - i if j * 4 + i * 2 == legs_num: answer = "Yes" print(answer)
x, y = list(map(int, input().split())) answer = "No" for i in range(x + 1): j = x - i if i * 2 + j * 4 == y: answer = "Yes" print(answer)
9
10
194
152
animals_num, legs_num = list(map(int, input().split())) answer = "No" for i in range(animals_num + 1): j = animals_num - i if j * 4 + i * 2 == legs_num: answer = "Yes" print(answer)
x, y = list(map(int, input().split())) answer = "No" for i in range(x + 1): j = x - i if i * 2 + j * 4 == y: answer = "Yes" print(answer)
false
10
[ "-animals_num, legs_num = list(map(int, input().split()))", "+x, y = list(map(int, input().split()))", "-for i in range(animals_num + 1):", "- j = animals_num - i", "- if j * 4 + i * 2 == legs_num:", "+for i in range(x + 1):", "+ j = x - i", "+ if i * 2 + j * 4 == y:" ]
false
0.04742
0.046179
1.026881
[ "s435885515", "s445658662" ]
u889914341
p03111
python
s125247372
s648463458
93
76
3,064
3,064
Accepted
Accepted
18.28
n, *li = list(map(int, input().split())) L = list(map(int, (int(eval(input())) for _ in range(n)))) ans = int(1e9) def f(A, num, cnt): if num == n: if 0 in A: return global ans ans = min(ans, abs(A[0] - li[0]) + abs(A[1] - li[1]) + abs(A[2] - li[2]) + cnt) return for i in range(3): p = 0 if A[i] == 0 else 10 B = A[::] B[i] += L[num] f(B, num + 1, cnt + p) f(A, num + 1, cnt) f([0, 0, 0], 0, 0) print(ans)
INF = float("inf") n, A, B, C = list(map(int, input().split())) L = tuple(map(int, (int(eval(input())) for _ in range(n)))) def f(a, b, c, num): if num == n: if min(a, b, c) > 0: return abs(A - a) + abs(B - b) + abs(C - c) else: return INF return min( f(a + L[num], b, c, num + 1) + (10 if a else 0), f(a, b + L[num], c, num + 1) + (10 if b else 0), f(a, b, c + L[num], num + 1) + (10 if c else 0), f(a, b, c, num + 1) ) print((f(0, 0, 0, 0)))
18
16
500
529
n, *li = list(map(int, input().split())) L = list(map(int, (int(eval(input())) for _ in range(n)))) ans = int(1e9) def f(A, num, cnt): if num == n: if 0 in A: return global ans ans = min(ans, abs(A[0] - li[0]) + abs(A[1] - li[1]) + abs(A[2] - li[2]) + cnt) return for i in range(3): p = 0 if A[i] == 0 else 10 B = A[::] B[i] += L[num] f(B, num + 1, cnt + p) f(A, num + 1, cnt) f([0, 0, 0], 0, 0) print(ans)
INF = float("inf") n, A, B, C = list(map(int, input().split())) L = tuple(map(int, (int(eval(input())) for _ in range(n)))) def f(a, b, c, num): if num == n: if min(a, b, c) > 0: return abs(A - a) + abs(B - b) + abs(C - c) else: return INF return min( f(a + L[num], b, c, num + 1) + (10 if a else 0), f(a, b + L[num], c, num + 1) + (10 if b else 0), f(a, b, c + L[num], num + 1) + (10 if c else 0), f(a, b, c, num + 1), ) print((f(0, 0, 0, 0)))
false
11.111111
[ "-n, *li = list(map(int, input().split()))", "-L = list(map(int, (int(eval(input())) for _ in range(n))))", "-ans = int(1e9)", "+INF = float(\"inf\")", "+n, A, B, C = list(map(int, input().split()))", "+L = tuple(map(int, (int(eval(input())) for _ in range(n))))", "-def f(A, num, cnt):", "+def f(a, b, c, num):", "- if 0 in A:", "- return", "- global ans", "- ans = min(ans, abs(A[0] - li[0]) + abs(A[1] - li[1]) + abs(A[2] - li[2]) + cnt)", "- return", "- for i in range(3):", "- p = 0 if A[i] == 0 else 10", "- B = A[::]", "- B[i] += L[num]", "- f(B, num + 1, cnt + p)", "- f(A, num + 1, cnt)", "+ if min(a, b, c) > 0:", "+ return abs(A - a) + abs(B - b) + abs(C - c)", "+ else:", "+ return INF", "+ return min(", "+ f(a + L[num], b, c, num + 1) + (10 if a else 0),", "+ f(a, b + L[num], c, num + 1) + (10 if b else 0),", "+ f(a, b, c + L[num], num + 1) + (10 if c else 0),", "+ f(a, b, c, num + 1),", "+ )", "-f([0, 0, 0], 0, 0)", "-print(ans)", "+print((f(0, 0, 0, 0)))" ]
false
0.070999
0.060171
1.179944
[ "s125247372", "s648463458" ]
u091489347
p03835
python
s280163245
s078249357
1,760
1,374
2,940
2,940
Accepted
Accepted
21.93
k ,s = list(map(int, input().split())) count = 0 for x in range(k+1): for y in range(k +1): if ((x + y) <= s) and ((s - (x + y)) <= k): count += 1 print(count)
k, s = list(map(int,input().split())) count= 0 #全探索は時計が切れる for x in range(k+1): for y in range(k+1): if 0 <= s - (x +y) <= k: count += 1 print(count)
9
9
203
176
k, s = list(map(int, input().split())) count = 0 for x in range(k + 1): for y in range(k + 1): if ((x + y) <= s) and ((s - (x + y)) <= k): count += 1 print(count)
k, s = list(map(int, input().split())) count = 0 # 全探索は時計が切れる for x in range(k + 1): for y in range(k + 1): if 0 <= s - (x + y) <= k: count += 1 print(count)
false
0
[ "+# 全探索は時計が切れる", "- if ((x + y) <= s) and ((s - (x + y)) <= k):", "+ if 0 <= s - (x + y) <= k:" ]
false
0.060895
0.061532
0.989639
[ "s280163245", "s078249357" ]
u482157295
p02694
python
s227243892
s092551059
60
30
64,520
9,144
Accepted
Accepted
50
x = int(eval(input())) dum = 100 count = 0 while(1): if dum >= x: break dum = dum*1.01 dum = dum//1 count += 1 #print(dum) print(count)
import math x = int(eval(input())) a = 100 cnt = 0 while(1): cnt += 1 a += a//100 if a >= x: break print(cnt)
11
10
167
133
x = int(eval(input())) dum = 100 count = 0 while 1: if dum >= x: break dum = dum * 1.01 dum = dum // 1 count += 1 # print(dum) print(count)
import math x = int(eval(input())) a = 100 cnt = 0 while 1: cnt += 1 a += a // 100 if a >= x: break print(cnt)
false
9.090909
[ "+import math", "+", "-dum = 100", "-count = 0", "+a = 100", "+cnt = 0", "- if dum >= x:", "+ cnt += 1", "+ a += a // 100", "+ if a >= x:", "- dum = dum * 1.01", "- dum = dum // 1", "- count += 1", "- # print(dum)", "-print(count)", "+print(cnt)" ]
false
0.040055
0.041242
0.971224
[ "s227243892", "s092551059" ]
u917734688
p02707
python
s766997257
s999795573
342
206
50,772
38,924
Accepted
Accepted
39.77
import numpy as np N = int(eval(input())) A = list(map(int,input().split())) datas = np.zeros(N) for a in A: datas[a-1] += 1 for data in datas: print((int(data)))
N = int(eval(input())) A = list(map(int,input().split())) datas = {i:0 for i in range(1,N+1)} for a in A: datas[a] += 1 for data in list(datas.values()): print(data)
8
7
165
167
import numpy as np N = int(eval(input())) A = list(map(int, input().split())) datas = np.zeros(N) for a in A: datas[a - 1] += 1 for data in datas: print((int(data)))
N = int(eval(input())) A = list(map(int, input().split())) datas = {i: 0 for i in range(1, N + 1)} for a in A: datas[a] += 1 for data in list(datas.values()): print(data)
false
12.5
[ "-import numpy as np", "-", "-datas = np.zeros(N)", "+datas = {i: 0 for i in range(1, N + 1)}", "- datas[a - 1] += 1", "-for data in datas:", "- print((int(data)))", "+ datas[a] += 1", "+for data in list(datas.values()):", "+ print(data)" ]
false
0.353397
0.039789
8.881709
[ "s766997257", "s999795573" ]
u761320129
p03610
python
s596593659
s810055215
35
17
3,572
3,188
Accepted
Accepted
51.43
S = eval(input()) arr = [] for i in range(len(S)): if i%2 == 0: arr.append(S[i]) print((''.join(arr)))
S = eval(input()) print((S[::2]))
6
2
112
26
S = eval(input()) arr = [] for i in range(len(S)): if i % 2 == 0: arr.append(S[i]) print(("".join(arr)))
S = eval(input()) print((S[::2]))
false
66.666667
[ "-arr = []", "-for i in range(len(S)):", "- if i % 2 == 0:", "- arr.append(S[i])", "-print((\"\".join(arr)))", "+print((S[::2]))" ]
false
0.059468
0.058982
1.008243
[ "s596593659", "s810055215" ]
u992910889
p03986
python
s559599811
s511357753
185
168
40,048
40,048
Accepted
Accepted
9.19
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): X = str(eval(input())) stack = 0 pop = 0 for i in range(len(X)): if X[i] == 'S': stack += 1 elif X[i] == 'T' and stack > 0: pop += 1 stack -= 1 print((len(X)-pop*2)) resolve()
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C # https://atcoder.jp/contests/abc064/tasks/abc064_d X = str(eval(input())) N = len(X) stack_rem = 0 need_left = 0 pop_cnt = 0 for i in range(N): if X[i] == 'S': stack_rem += 1 elif stack_rem > 0: stack_rem -= 1 pop_cnt += 1 print((N-pop_cnt*2)) resolve()
21
28
376
594
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): X = str(eval(input())) stack = 0 pop = 0 for i in range(len(X)): if X[i] == "S": stack += 1 elif X[i] == "T" and stack > 0: pop += 1 stack -= 1 print((len(X) - pop * 2)) resolve()
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C # https://atcoder.jp/contests/abc064/tasks/abc064_d X = str(eval(input())) N = len(X) stack_rem = 0 need_left = 0 pop_cnt = 0 for i in range(N): if X[i] == "S": stack_rem += 1 elif stack_rem > 0: stack_rem -= 1 pop_cnt += 1 print((N - pop_cnt * 2)) resolve()
false
25
[ "+ # https://scrapbox.io/fukucchi/%E6%8B%AC%E5%BC%A7%E5%88%97%E3%81%AE%E6%95%B4%E5%90%88%E6%80%A7%E5%95%8F%E9%A1%8C", "+ # https://atcoder.jp/contests/abc064/tasks/abc064_d", "- stack = 0", "- pop = 0", "- for i in range(len(X)):", "+ N = len(X)", "+ stack_rem = 0", "+ need_left = 0", "+ pop_cnt = 0", "+ for i in range(N):", "- stack += 1", "- elif X[i] == \"T\" and stack > 0:", "- pop += 1", "- stack -= 1", "- print((len(X) - pop * 2))", "+ stack_rem += 1", "+ elif stack_rem > 0:", "+ stack_rem -= 1", "+ pop_cnt += 1", "+ print((N - pop_cnt * 2))" ]
false
0.04397
0.119301
0.368562
[ "s559599811", "s511357753" ]
u896451538
p03160
python
s241176207
s897799031
192
142
13,928
20,448
Accepted
Accepted
26.04
def MAP(): return list(map(int,input().split())) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) MOD = 10**9+7 n = INT() h = MAP() dp = [MOD]*n dp[0]=0 for i in range(n-1): dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1])) if i<n-2: 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 = [10**9]*n dp[0]=0 for i in range(1,n): dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1])) if i>1: dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2])) print((dp[n-1]))
17
11
343
235
def MAP(): return list(map(int, input().split())) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) MOD = 10**9 + 7 n = INT() h = MAP() dp = [MOD] * n dp[0] = 0 for i in range(n - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) if i < n - 2: 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 = [10**9] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[n - 1]))
false
35.294118
[ "-def MAP():", "- return list(map(int, input().split()))", "-", "-", "-def INT():", "- return int(eval(input()))", "-", "-", "-def FLOAT():", "- return float(eval(input()))", "-", "-", "-MOD = 10**9 + 7", "-n = INT()", "-h = MAP()", "-dp = [MOD] * n", "+n = int(eval(input()))", "+h = list(map(int, input().split()))", "+dp = [10**9] * n", "-for i in range(n - 1):", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))", "- if i < n - 2:", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))", "+for i in range(1, n):", "+ dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))", "+ if i > 1:", "+ dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.04354
0.044897
0.969792
[ "s241176207", "s897799031" ]
u429029348
p02659
python
s930439943
s597661928
28
23
10,064
9,156
Accepted
Accepted
17.86
from decimal import Decimal a,b=list(map(str,input().split())) ans=Decimal(a)*Decimal(b) print((int(ans)))
a,b=input().split() a=int(a) b=int(float(b)*100+0.5) ans=a*b//100 print(ans)
4
5
102
80
from decimal import Decimal a, b = list(map(str, input().split())) ans = Decimal(a) * Decimal(b) print((int(ans)))
a, b = input().split() a = int(a) b = int(float(b) * 100 + 0.5) ans = a * b // 100 print(ans)
false
20
[ "-from decimal import Decimal", "-", "-a, b = list(map(str, input().split()))", "-ans = Decimal(a) * Decimal(b)", "-print((int(ans)))", "+a, b = input().split()", "+a = int(a)", "+b = int(float(b) * 100 + 0.5)", "+ans = a * b // 100", "+print(ans)" ]
false
0.04026
0.051354
0.783974
[ "s930439943", "s597661928" ]
u278886389
p02762
python
s277671081
s088834720
1,441
1,303
96,984
84,568
Accepted
Accepted
9.58
from collections import defaultdict from collections import Counter N,M,K = map(int,input().split()) fn = defaultdict(lambda: 1) CD = [0]*K par = list(range(N)) def root(x): S = set() S.add(x) y = x while True: if par[y] == y: for s in S: par[s] = y return y S.add(y) y = par[y] def unite(x,y): rx = root(x) ry = root(y) par[rx] = ry for _ in range(M): A,B = map(int,input().split()) A -= 1 B -= 1 fn[A] += 1 fn[B] += 1 unite(A,B) for _ in range(K): C,D = map(int,input().split()) C -= 1 D -= 1 CD[_] = (C,D) par = [root(x) for x in range(N)] c = Counter(par) RESULT = [(c[par[x]] - fn[x]) for x in range(N)] for C,D in CD: if par[C] == par[D]: RESULT[C] -= 1 RESULT[D] -= 1 print(*RESULT,sep=" ")
from collections import defaultdict from collections import Counter N,M,K = map(int,input().split()) fn = [1]*N CD = [0]*K par = list(range(N)) def root(x): S = set() S.add(x) y = x while True: if par[y] == y: for s in S: par[s] = y return y S.add(y) y = par[y] def unite(x,y): rx = root(x) ry = root(y) par[rx] = ry for _ in range(M): A,B = map(int,input().split()) A -= 1 B -= 1 fn[A] += 1 fn[B] += 1 unite(A,B) for _ in range(K): C,D = map(int,input().split()) C -= 1 D -= 1 CD[_] = (C,D) par = [root(x) for x in range(N)] c = Counter(par) RESULT = [(c[par[x]] - fn[x]) for x in range(N)] for C,D in CD: if par[C] == par[D]: RESULT[C] -= 1 RESULT[D] -= 1 print(*RESULT,sep=" ")
52
52
915
898
from collections import defaultdict from collections import Counter N, M, K = map(int, input().split()) fn = defaultdict(lambda: 1) CD = [0] * K par = list(range(N)) def root(x): S = set() S.add(x) y = x while True: if par[y] == y: for s in S: par[s] = y return y S.add(y) y = par[y] def unite(x, y): rx = root(x) ry = root(y) par[rx] = ry for _ in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 fn[A] += 1 fn[B] += 1 unite(A, B) for _ in range(K): C, D = map(int, input().split()) C -= 1 D -= 1 CD[_] = (C, D) par = [root(x) for x in range(N)] c = Counter(par) RESULT = [(c[par[x]] - fn[x]) for x in range(N)] for C, D in CD: if par[C] == par[D]: RESULT[C] -= 1 RESULT[D] -= 1 print(*RESULT, sep=" ")
from collections import defaultdict from collections import Counter N, M, K = map(int, input().split()) fn = [1] * N CD = [0] * K par = list(range(N)) def root(x): S = set() S.add(x) y = x while True: if par[y] == y: for s in S: par[s] = y return y S.add(y) y = par[y] def unite(x, y): rx = root(x) ry = root(y) par[rx] = ry for _ in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 fn[A] += 1 fn[B] += 1 unite(A, B) for _ in range(K): C, D = map(int, input().split()) C -= 1 D -= 1 CD[_] = (C, D) par = [root(x) for x in range(N)] c = Counter(par) RESULT = [(c[par[x]] - fn[x]) for x in range(N)] for C, D in CD: if par[C] == par[D]: RESULT[C] -= 1 RESULT[D] -= 1 print(*RESULT, sep=" ")
false
0
[ "-fn = defaultdict(lambda: 1)", "+fn = [1] * N" ]
false
0.161212
0.04683
3.442509
[ "s277671081", "s088834720" ]
u189487046
p03738
python
s872287386
s097624455
22
17
2,940
2,940
Accepted
Accepted
22.73
a = int(eval(input())) b = int(eval(input())) if a == b: print("EQUAL") elif a > b: print("GREATER") else: print("LESS")
A = int(eval(input())) B = int(eval(input())) if A > B: print('GREATER') elif A < B: print('LESS') else: print('EQUAL')
9
9
130
129
a = int(eval(input())) b = int(eval(input())) if a == b: print("EQUAL") elif a > b: print("GREATER") else: print("LESS")
A = int(eval(input())) B = int(eval(input())) if A > B: print("GREATER") elif A < B: print("LESS") else: print("EQUAL")
false
0
[ "-a = int(eval(input()))", "-b = int(eval(input()))", "-if a == b:", "+A = int(eval(input()))", "+B = int(eval(input()))", "+if A > B:", "+ print(\"GREATER\")", "+elif A < B:", "+ print(\"LESS\")", "+else:", "-elif a > b:", "- print(\"GREATER\")", "-else:", "- print(\"LESS\")" ]
false
0.057913
0.034051
1.70076
[ "s872287386", "s097624455" ]
u788137651
p02684
python
s376133199
s369953084
658
172
100,016
99,912
Accepted
Accepted
73.86
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,sqrt,factorial,hypot,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a,b): return (a+b-1)//b inf=float('inf') mod = 10**9+7 def pprint(*A): for a in A: print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n:int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split() )) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') def main(): N,K=MI() A=LI_() dist = [inf]*N now = 0 flag = False start = 0 for i in range(N+2): if(dist[now] != inf): cycle = i - dist[now] # print(cycle) # print(i,dist[now]) if(K<dist[now]): flag = True else: K-=dist[now] ##出発点をnowにする start = now K%=cycle break dist[now] = i now = A[now] # print(K,start) for i in range(K): start = A[start] print(start+1) if __name__ == '__main__': main()
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,sqrt,factorial,hypot,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a,b): return (a+b-1)//b inf=float('inf') mod = 10**9+7 def pprint(*A): for a in A: print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n:int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split() )) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') def main(): N,K=MI() A=LI_() dist = [inf]*N now = 0 start = 0 for i in range(N+2): if(dist[now] != inf): cycle = i - dist[now] if(K>=dist[now]): K-=dist[now] ##出発点をnowにする start = now K%=cycle break dist[now] = i now = A[now] for i in range(K): start = A[start] print(start+1) if __name__ == '__main__': main()
70
64
1,934
1,785
# #    ⋀_⋀ #    (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float("inf") mod = 10**9 + 7 def pprint(*A): for a in A: print(*a, sep="\n") def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace("\n", "") def main(): N, K = MI() A = LI_() dist = [inf] * N now = 0 flag = False start = 0 for i in range(N + 2): if dist[now] != inf: cycle = i - dist[now] # print(cycle) # print(i,dist[now]) if K < dist[now]: flag = True else: K -= dist[now] ##出発点をnowにする start = now K %= cycle break dist[now] = i now = A[now] # print(K,start) for i in range(K): start = A[start] print(start + 1) if __name__ == "__main__": main()
# #    ⋀_⋀ #    (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float("inf") mod = 10**9 + 7 def pprint(*A): for a in A: print(*a, sep="\n") def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace("\n", "") def main(): N, K = MI() A = LI_() dist = [inf] * N now = 0 start = 0 for i in range(N + 2): if dist[now] != inf: cycle = i - dist[now] if K >= dist[now]: K -= dist[now] ##出発点をnowにする start = now K %= cycle break dist[now] = i now = A[now] for i in range(K): start = A[start] print(start + 1) if __name__ == "__main__": main()
false
8.571429
[ "- flag = False", "- # print(cycle)", "- # print(i,dist[now])", "- if K < dist[now]:", "- flag = True", "- else:", "+ if K >= dist[now]:", "- # print(K,start)" ]
false
0.048489
0.041092
1.180003
[ "s376133199", "s369953084" ]
u477319617
p02725
python
s362347504
s284076751
173
145
26,060
26,444
Accepted
Accepted
16.18
K, N = list(map(int,input().split())) #K: 湖1周の長さ, N:湖の周りにある家の数 A = list(map(int, input().split())) l = 0 A.append(A[0]+K) for i,aa in enumerate(A): if(i<len(A)-1): l = max(l, A[i+1]-aa) print((K-l))
k,n =list(map(int,input().split())) a = list(map(int,input().split())) a.append(a[0]+k) l = 0 for i in range(n): l = max(l,a[i+1]-a[i]) print((k-l))
11
7
219
151
K, N = list(map(int, input().split())) # K: 湖1周の長さ, N:湖の周りにある家の数 A = list(map(int, input().split())) l = 0 A.append(A[0] + K) for i, aa in enumerate(A): if i < len(A) - 1: l = max(l, A[i + 1] - aa) print((K - l))
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + k) l = 0 for i in range(n): l = max(l, a[i + 1] - a[i]) print((k - l))
false
36.363636
[ "-K, N = list(map(int, input().split()))", "-# K: 湖1周の長さ, N:湖の周りにある家の数", "-A = list(map(int, input().split()))", "+k, n = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+a.append(a[0] + k)", "-A.append(A[0] + K)", "-for i, aa in enumerate(A):", "- if i < len(A) - 1:", "- l = max(l, A[i + 1] - aa)", "-print((K - l))", "+for i in range(n):", "+ l = max(l, a[i + 1] - a[i])", "+print((k - l))" ]
false
0.037207
0.049358
0.753808
[ "s362347504", "s284076751" ]
u729133443
p03712
python
s727777096
s091916610
172
17
38,256
3,060
Accepted
Accepted
90.12
_,w,*s=open(0).read().split();t=['#'*(int(w)+2)];a=t+['#'+t+'#'for t in s]+t;print(*a,sep='\n')
_,w,*s=open(0).read().split();t=['#'*(int(w)+2)];a=t+['#'+t+'#'for t in s]+t;print((*a))
1
1
95
86
_, w, *s = open(0).read().split() t = ["#" * (int(w) + 2)] a = t + ["#" + t + "#" for t in s] + t print(*a, sep="\n")
_, w, *s = open(0).read().split() t = ["#" * (int(w) + 2)] a = t + ["#" + t + "#" for t in s] + t print((*a))
false
0
[ "-print(*a, sep=\"\\n\")", "+print((*a))" ]
false
0.03505
0.035744
0.980577
[ "s727777096", "s091916610" ]
u075012704
p03607
python
s597096716
s757429734
278
249
16,636
15,460
Accepted
Accepted
10.43
from collections import Counter N = int(eval(input())) numbers = [int(eval(input())) for i in range(N)] num_cnt = Counter(numbers) ans_box = list([x for x in list(num_cnt.values()) if x%2==1]) print((len(ans_box)))
from collections import defaultdict N = int(eval(input())) D = defaultdict(int) for i in range(N): D[int(eval(input()))] += 1 print((len(list([x for x in list(D.values()) if x%2==1]))))
8
7
206
180
from collections import Counter N = int(eval(input())) numbers = [int(eval(input())) for i in range(N)] num_cnt = Counter(numbers) ans_box = list([x for x in list(num_cnt.values()) if x % 2 == 1]) print((len(ans_box)))
from collections import defaultdict N = int(eval(input())) D = defaultdict(int) for i in range(N): D[int(eval(input()))] += 1 print((len(list([x for x in list(D.values()) if x % 2 == 1]))))
false
12.5
[ "-from collections import Counter", "+from collections import defaultdict", "-numbers = [int(eval(input())) for i in range(N)]", "-num_cnt = Counter(numbers)", "-ans_box = list([x for x in list(num_cnt.values()) if x % 2 == 1])", "-print((len(ans_box)))", "+D = defaultdict(int)", "+for i in range(N):", "+ D[int(eval(input()))] += 1", "+print((len(list([x for x in list(D.values()) if x % 2 == 1]))))" ]
false
0.054737
0.053569
1.021803
[ "s597096716", "s757429734" ]
u462329577
p02995
python
s519547898
s342893117
175
17
38,384
3,060
Accepted
Accepted
90.29
def gcd(i,j): if i > j: tmp = i i = j j = tmp while i != 0: tmp = i i = j%i j = tmp return j def lcm(i,j): return i*j//gcd(i,j) def main(): a,b,c,d = list(map(int,input().split())) ans = b-a+1 ans -= (b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//lcm(c,d) -(a-1)//lcm(c,d)) print(ans) main()
#!/usr/bin/env python3 a,b,c,d = list(map(int,input().split())) def my_gcd(i,j): if i > j: i,j = j,i while i != 0: if j % i != 0: i,j = j%i,i else: return i def not_div(n): return b//n - (a-1) //n print((not_div(1)-not_div(c)-not_div(d)+not_div(c*d//my_gcd(c,d))))
20
11
346
309
def gcd(i, j): if i > j: tmp = i i = j j = tmp while i != 0: tmp = i i = j % i j = tmp return j def lcm(i, j): return i * j // gcd(i, j) def main(): a, b, c, d = list(map(int, input().split())) ans = b - a + 1 ans -= ( (b // c - (a - 1) // c) + (b // d - (a - 1) // d) - (b // lcm(c, d) - (a - 1) // lcm(c, d)) ) print(ans) main()
#!/usr/bin/env python3 a, b, c, d = list(map(int, input().split())) def my_gcd(i, j): if i > j: i, j = j, i while i != 0: if j % i != 0: i, j = j % i, i else: return i def not_div(n): return b // n - (a - 1) // n print((not_div(1) - not_div(c) - not_div(d) + not_div(c * d // my_gcd(c, d))))
false
45
[ "-def gcd(i, j):", "- if i > j:", "- tmp = i", "- i = j", "- j = tmp", "- while i != 0:", "- tmp = i", "- i = j % i", "- j = tmp", "- return j", "+#!/usr/bin/env python3", "+a, b, c, d = list(map(int, input().split()))", "-def lcm(i, j):", "- return i * j // gcd(i, j)", "+def my_gcd(i, j):", "+ if i > j:", "+ i, j = j, i", "+ while i != 0:", "+ if j % i != 0:", "+ i, j = j % i, i", "+ else:", "+ return i", "-def main():", "- a, b, c, d = list(map(int, input().split()))", "- ans = b - a + 1", "- ans -= (", "- (b // c - (a - 1) // c)", "- + (b // d - (a - 1) // d)", "- - (b // lcm(c, d) - (a - 1) // lcm(c, d))", "- )", "- print(ans)", "+def not_div(n):", "+ return b // n - (a - 1) // n", "-main()", "+print((not_div(1) - not_div(c) - not_div(d) + not_div(c * d // my_gcd(c, d))))" ]
false
0.042935
0.04293
1.000117
[ "s519547898", "s342893117" ]
u422104747
p03963
python
s191491820
s933096636
23
19
3,064
3,060
Accepted
Accepted
17.39
n,k = list(map(int, input().split())) print(((k-1)**(n-1)*k))
s=input().split() N=int(s[0]) K=int(s[1]) print(((K-1)**(N-1)*K))
2
4
54
66
n, k = list(map(int, input().split())) print(((k - 1) ** (n - 1) * k))
s = input().split() N = int(s[0]) K = int(s[1]) print(((K - 1) ** (N - 1) * K))
false
50
[ "-n, k = list(map(int, input().split()))", "-print(((k - 1) ** (n - 1) * k))", "+s = input().split()", "+N = int(s[0])", "+K = int(s[1])", "+print(((K - 1) ** (N - 1) * K))" ]
false
0.037201
0.036878
1.00874
[ "s191491820", "s933096636" ]
u401686269
p02820
python
s138487760
s934681322
191
76
39,364
21,240
Accepted
Accepted
60.21
import numpy as np N,K=list(map(int,input().split())) R,S,P=list(map(int,input().split())) T1=eval(input()) T2=T1.replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1] T2=np.array(list(map(int, T2.split()))) for i in range(N): if i >=K and T1[i]==T1[i-K] and T2[i-K] != 0: T2[i]=0 print((T2.sum()))
N,K=list(map(int,input().split())) R,S,P=list(map(int,input().split())) T1=eval(input()) T2=T1.replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1] T2=list(map(int, T2.split())) for i in range(N): if i >=K and T1[i]==T1[i-K] and T2[i-K] != 0:T2[i]=0 print((sum(T2)))
13
8
323
280
import numpy as np N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T1 = eval(input()) T2 = ( T1.replace("r", str(P) + " ") .replace("s", str(R) + " ") .replace("p", str(S) + " ")[:-1] ) T2 = np.array(list(map(int, T2.split()))) for i in range(N): if i >= K and T1[i] == T1[i - K] and T2[i - K] != 0: T2[i] = 0 print((T2.sum()))
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T1 = eval(input()) T2 = ( T1.replace("r", str(P) + " ") .replace("s", str(R) + " ") .replace("p", str(S) + " ")[:-1] ) T2 = list(map(int, T2.split())) for i in range(N): if i >= K and T1[i] == T1[i - K] and T2[i - K] != 0: T2[i] = 0 print((sum(T2)))
false
38.461538
[ "-import numpy as np", "-", "-T2 = np.array(list(map(int, T2.split())))", "+T2 = list(map(int, T2.split()))", "-print((T2.sum()))", "+print((sum(T2)))" ]
false
0.511125
0.038621
13.234468
[ "s138487760", "s934681322" ]
u860002137
p02862
python
s339894956
s633609266
407
303
38,340
70,024
Accepted
Accepted
25.55
import numpy as np import sys x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x: print((0)) sys.exit() # 手数 n = (x + y) // 3 x -= n y -= n MOD = 10**9 + 7 # モジュラ逆数戦法 def prepare(n, MOD): f = 1 for m in range(1, n + 1): f *= m f %= MOD fn = f inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return fn, invs fact, invs = prepare(n, MOD) print((fact * invs[x] * invs[y] % MOD))
import numpy as np import sys x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x: print((0)) sys.exit() # 手数 n = (x + y) // 3 x -= n y -= n MOD = 10**9 + 7 def prepare(n, MOD): nrt = int(n ** 0.5) + 1 nsq = nrt * nrt facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt) facts[0, 0] = 1 for i in range(1, nrt): facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD for i in range(1, nrt): facts[i] = facts[i] * facts[i - 1, -1] % MOD facts = facts.ravel().tolist() invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt) invs[-1, -1] = pow(facts[-1], MOD - 2, MOD) for i in range(nrt - 2, -1, -1): invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD for i in range(nrt - 2, -1, -1): invs[i] = invs[i] * invs[i + 1, 0] % MOD invs = invs.ravel().tolist() return facts, invs facts, invs = prepare(n, MOD) print((facts[n] * invs[x] * invs[y] % MOD))
38
41
604
1,012
import numpy as np import sys x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x: print((0)) sys.exit() # 手数 n = (x + y) // 3 x -= n y -= n MOD = 10**9 + 7 # モジュラ逆数戦法 def prepare(n, MOD): f = 1 for m in range(1, n + 1): f *= m f %= MOD fn = f inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return fn, invs fact, invs = prepare(n, MOD) print((fact * invs[x] * invs[y] % MOD))
import numpy as np import sys x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x: print((0)) sys.exit() # 手数 n = (x + y) // 3 x -= n y -= n MOD = 10**9 + 7 def prepare(n, MOD): nrt = int(n**0.5) + 1 nsq = nrt * nrt facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt) facts[0, 0] = 1 for i in range(1, nrt): facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD for i in range(1, nrt): facts[i] = facts[i] * facts[i - 1, -1] % MOD facts = facts.ravel().tolist() invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt) invs[-1, -1] = pow(facts[-1], MOD - 2, MOD) for i in range(nrt - 2, -1, -1): invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD for i in range(nrt - 2, -1, -1): invs[i] = invs[i] * invs[i + 1, 0] % MOD invs = invs.ravel().tolist() return facts, invs facts, invs = prepare(n, MOD) print((facts[n] * invs[x] * invs[y] % MOD))
false
7.317073
[ "-# モジュラ逆数戦法", "-def prepare(n, MOD):", "- f = 1", "- for m in range(1, n + 1):", "- f *= m", "- f %= MOD", "- fn = f", "- inv = pow(f, MOD - 2, MOD)", "- invs = [1] * (n + 1)", "- invs[n] = inv", "- for m in range(n, 1, -1):", "- inv *= m", "- inv %= MOD", "- invs[m - 1] = inv", "- return fn, invs", "-fact, invs = prepare(n, MOD)", "-print((fact * invs[x] * invs[y] % MOD))", "+def prepare(n, MOD):", "+ nrt = int(n**0.5) + 1", "+ nsq = nrt * nrt", "+ facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt)", "+ facts[0, 0] = 1", "+ for i in range(1, nrt):", "+ facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD", "+ for i in range(1, nrt):", "+ facts[i] = facts[i] * facts[i - 1, -1] % MOD", "+ facts = facts.ravel().tolist()", "+ invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt)", "+ invs[-1, -1] = pow(facts[-1], MOD - 2, MOD)", "+ for i in range(nrt - 2, -1, -1):", "+ invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD", "+ for i in range(nrt - 2, -1, -1):", "+ invs[i] = invs[i] * invs[i + 1, 0] % MOD", "+ invs = invs.ravel().tolist()", "+ return facts, invs", "+", "+", "+facts, invs = prepare(n, MOD)", "+print((facts[n] * invs[x] * invs[y] % MOD))" ]
false
0.124027
0.586502
0.211468
[ "s339894956", "s633609266" ]
u499381410
p02728
python
s752375252
s437521403
2,811
1,632
86,684
186,456
Accepted
Accepted
41.94
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, gamma, log from operator import mul from functools import reduce from copy import deepcopy sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 n =I() G = [[] for _ in range(n)] for _ in range(n - 1): a, b = LI() G[a - 1] += [b - 1] G[b - 1] += [a - 1] fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j-1] * j % mod inv[n] = pow(fac[n], mod-2, mod) for j in range(n-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod v_num = [-1] * n par = [-1] * n def f(u): ret = 1 for v in G[u]: if v == par[u]: continue par[v] = u ret += f(v) v_num[u] = ret if u: return ret f(0) dp = [0] * n def tree_dp(x): c = 1 remain_v = v_num[x] - 1 for y in G[x]: if y == par[x]: continue c = c * tree_dp(y) * comb(remain_v, v_num[y]) % mod remain_v -= v_num[y] dp[x] = c if x: return c tree_dp(0) ans = [0] * n def dfs(d): e = 1 inv_e = pow(comb(n - 1, v_num[d]) * dp[d], mod - 2, mod) ans[d] = dp[d] * ans[par[d]] * comb(n - 1, v_num[d] - 1) * inv_e % mod q = deque([0]) ans[0] = dp[0] while q: g = q.pop() for h in G[g]: if h == par[g]: continue dfs(h) q += [h] for j in ans: print(j)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().rstrip().split() def S(): return sys.stdin.readline().rstrip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod=10**9+7 n=I() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j-1] * j % mod inv[n] = pow(fac[n], mod-2, mod) for j in range(n-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod G=[[]for _ in range(n)] for _ in range(n-1): a,b=LI() G[a-1]+=[b-1] G[b-1] += [a-1] cnt=[-1]*n par=[-1]*n def f(x): ret=1 for y in G[x]: if par[x]==y: continue par[y]=x ret+=f(y) cnt[x]=ret return ret f(0) D=[0]*n def tree_dp(x): c = 1 remain_v = cnt[x] - 1 for y in G[x]: if y == par[x]: continue c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod remain_v -= cnt[y] D[x] = c if x: return c tree_dp(0) ans=[0]*n ans[0]=D[0] q=deque([0]) while q: e=q.pop() for d in G[e]: if d==par[e]: continue ans[d]=pow(comb(n-1,cnt[d])*D[d],mod-2,mod)*ans[e]*comb(n-1,cnt[d]-1)*D[d]%mod q+=[d] print(*ans,sep="\n")
95
95
2,400
2,115
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, gamma, log from operator import mul from functools import reduce from copy import deepcopy sys.setrecursionlimit(2147483647) INF = 10**20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 n = I() G = [[] for _ in range(n)] for _ in range(n - 1): a, b = LI() G[a - 1] += [b - 1] G[b - 1] += [a - 1] fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod v_num = [-1] * n par = [-1] * n def f(u): ret = 1 for v in G[u]: if v == par[u]: continue par[v] = u ret += f(v) v_num[u] = ret if u: return ret f(0) dp = [0] * n def tree_dp(x): c = 1 remain_v = v_num[x] - 1 for y in G[x]: if y == par[x]: continue c = c * tree_dp(y) * comb(remain_v, v_num[y]) % mod remain_v -= v_num[y] dp[x] = c if x: return c tree_dp(0) ans = [0] * n def dfs(d): e = 1 inv_e = pow(comb(n - 1, v_num[d]) * dp[d], mod - 2, mod) ans[d] = dp[d] * ans[par[d]] * comb(n - 1, v_num[d] - 1) * inv_e % mod q = deque([0]) ans[0] = dp[0] while q: g = q.pop() for h in G[g]: if h == par[g]: continue dfs(h) q += [h] for j in ans: print(j)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10**13 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().rstrip().split() def S(): return sys.stdin.readline().rstrip() 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 n = I() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod G = [[] for _ in range(n)] for _ in range(n - 1): a, b = LI() G[a - 1] += [b - 1] G[b - 1] += [a - 1] cnt = [-1] * n par = [-1] * n def f(x): ret = 1 for y in G[x]: if par[x] == y: continue par[y] = x ret += f(y) cnt[x] = ret return ret f(0) D = [0] * n def tree_dp(x): c = 1 remain_v = cnt[x] - 1 for y in G[x]: if y == par[x]: continue c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod remain_v -= cnt[y] D[x] = c if x: return c tree_dp(0) ans = [0] * n ans[0] = D[0] q = deque([0]) while q: e = q.pop() for d in G[e]: if d == par[e]: continue ans[d] = ( pow(comb(n - 1, cnt[d]) * D[d], mod - 2, mod) * ans[e] * comb(n - 1, cnt[d] - 1) * D[d] % mod ) q += [d] print(*ans, sep="\n")
false
0
[ "-from bisect import bisect_right, bisect_left", "+import math", "+import bisect", "-from math import factorial, ceil, floor, gamma, log", "+from math import factorial, ceil, floor", "-from copy import deepcopy", "-INF = 10**20", "+INF = 10**13", "- return list(map(int, sys.stdin.buffer.readline().split()))", "+ return list(map(int, sys.stdin.readline().split()))", "- return int(sys.stdin.buffer.readline())", "+ return int(sys.stdin.readline())", "- return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()", "+ return sys.stdin.readline().rstrip().split()", "- return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "+ return sys.stdin.readline().rstrip()", "-G = [[] for _ in range(n)]", "-for _ in range(n - 1):", "- a, b = LI()", "- G[a - 1] += [b - 1]", "- G[b - 1] += [a - 1]", "-v_num = [-1] * n", "+G = [[] for _ in range(n)]", "+for _ in range(n - 1):", "+ a, b = LI()", "+ G[a - 1] += [b - 1]", "+ G[b - 1] += [a - 1]", "+cnt = [-1] * n", "-def f(u):", "+def f(x):", "- for v in G[u]:", "- if v == par[u]:", "+ for y in G[x]:", "+ if par[x] == y:", "- par[v] = u", "- ret += f(v)", "- v_num[u] = ret", "- if u:", "- return ret", "+ par[y] = x", "+ ret += f(y)", "+ cnt[x] = ret", "+ return ret", "-dp = [0] * n", "+D = [0] * n", "- remain_v = v_num[x] - 1", "+ remain_v = cnt[x] - 1", "- c = c * tree_dp(y) * comb(remain_v, v_num[y]) % mod", "- remain_v -= v_num[y]", "- dp[x] = c", "+ c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod", "+ remain_v -= cnt[y]", "+ D[x] = c", "-", "-", "-def dfs(d):", "- e = 1", "- inv_e = pow(comb(n - 1, v_num[d]) * dp[d], mod - 2, mod)", "- ans[d] = dp[d] * ans[par[d]] * comb(n - 1, v_num[d] - 1) * inv_e % mod", "-", "-", "+ans[0] = D[0]", "-ans[0] = dp[0]", "- g = q.pop()", "- for h in G[g]:", "- if h == par[g]:", "+ e = q.pop()", "+ for d in G[e]:", "+ if d == par[e]:", "- dfs(h)", "- q += [h]", "-for j in ans:", "- print(j)", "+ ans[d] = (", "+ pow(comb(n - 1, cnt[d]) * D[d], mod - 2, mod)", "+ * ans[e]", "+ * comb(n - 1, cnt[d] - 1)", "+ * D[d]", "+ % mod", "+ )", "+ q += [d]", "+print(*ans, sep=\"\\n\")" ]
false
0.03918
0.113264
0.345919
[ "s752375252", "s437521403" ]
u408760403
p03043
python
s699945437
s966013269
66
51
6,296
2,940
Accepted
Accepted
22.73
N,K=list(map(int,input().split())) l=[] for i in range(1,N+1): score=i while 1<=score<=(K-1): score*=2 prob=(1/N)*i/score l.append(prob) print((sum(l)))
N,K=list(map(int,input().split())) prob=0 for i in range(1,N+1): score=i omote=0 while 1<=score<=K-1: score=score*2 omote+=1 prob+=(1/N)*((1/2)**omote) print(prob)
9
10
164
182
N, K = list(map(int, input().split())) l = [] for i in range(1, N + 1): score = i while 1 <= score <= (K - 1): score *= 2 prob = (1 / N) * i / score l.append(prob) print((sum(l)))
N, K = list(map(int, input().split())) prob = 0 for i in range(1, N + 1): score = i omote = 0 while 1 <= score <= K - 1: score = score * 2 omote += 1 prob += (1 / N) * ((1 / 2) ** omote) print(prob)
false
10
[ "-l = []", "+prob = 0", "- while 1 <= score <= (K - 1):", "- score *= 2", "- prob = (1 / N) * i / score", "- l.append(prob)", "-print((sum(l)))", "+ omote = 0", "+ while 1 <= score <= K - 1:", "+ score = score * 2", "+ omote += 1", "+ prob += (1 / N) * ((1 / 2) ** omote)", "+print(prob)" ]
false
0.075603
0.082915
0.911815
[ "s699945437", "s966013269" ]
u995062424
p03607
python
s741282956
s633049038
247
197
8,280
16,592
Accepted
Accepted
20.24
N = int(eval(input())) A = [] for _ in range(N): A.append(int(eval(input()))) A = sorted(A) cnt = 1 ans = 0 for i in range(N-1): if(A[i] == A[i+1]): cnt += 1 continue ans += cnt % 2 cnt = 1 if(cnt % 2 == 1): ans += 1 print(ans)
import collections N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = collections.Counter(A) cnt = 0 for value in list(c.values()): if(value%2 != 0): cnt += 1 print(cnt)
19
11
272
194
N = int(eval(input())) A = [] for _ in range(N): A.append(int(eval(input()))) A = sorted(A) cnt = 1 ans = 0 for i in range(N - 1): if A[i] == A[i + 1]: cnt += 1 continue ans += cnt % 2 cnt = 1 if cnt % 2 == 1: ans += 1 print(ans)
import collections N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = collections.Counter(A) cnt = 0 for value in list(c.values()): if value % 2 != 0: cnt += 1 print(cnt)
false
42.105263
[ "+import collections", "+", "-A = []", "-for _ in range(N):", "- A.append(int(eval(input())))", "-A = sorted(A)", "-cnt = 1", "-ans = 0", "-for i in range(N - 1):", "- if A[i] == A[i + 1]:", "+A = [int(eval(input())) for _ in range(N)]", "+c = collections.Counter(A)", "+cnt = 0", "+for value in list(c.values()):", "+ if value % 2 != 0:", "- continue", "- ans += cnt % 2", "- cnt = 1", "-if cnt % 2 == 1:", "- ans += 1", "-print(ans)", "+print(cnt)" ]
false
0.111018
0.036928
3.006363
[ "s741282956", "s633049038" ]
u816872429
p02902
python
s105928553
s762417748
390
288
48,872
48,232
Accepted
Accepted
26.15
n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) ret = [0] * (n + 1) for start in range(n): parent = [-1] * n q = [start] while len(q) > 0: i = q.pop(0) for j in edges[i]: if j == start: loop = [i] while i != start: i = parent[i] loop.append(i) if len(ret) > len(loop): ret = loop break if parent[j] == -1: parent[j] = i q.append(j) if len(ret) > n: print((-1)) else: print((len(ret))) for i in reversed(ret): print((i + 1))
n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) def dfs(index, visited, cycle): visited[index] = True cycle.append(index) for i in edges[index]: if visited.get(i): return cycle[cycle.index(i):] ret = dfs(i, visited, cycle) if ret: return ret visited[index] = False cycle.pop(-1) return None def find_local_minimum(cycle): n = len(cycle) ind = {v: i for (i, v) in zip(list(range(n)), cycle)} ret = [] i = 0 while True: ret.append(i) nxt = 0 for j in [ind[v] for v in edges[cycle[i]] if v in ind]: if j < i: j += n nxt = max(nxt, j) if nxt >= n: ret = ret[ret.index(nxt % n):] break i += 1 while i < nxt: del ind[cycle[i]] i += 1 return [cycle[i % n] for i in ret] cycle = None visited = {} for start in range(n): if start not in visited: cycle = dfs(start, visited, []) if cycle: break if cycle: ret = find_local_minimum(cycle) print((len(ret))) for i in ret: print((i + 1)) else: print((-1))
32
56
783
1,331
n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) ret = [0] * (n + 1) for start in range(n): parent = [-1] * n q = [start] while len(q) > 0: i = q.pop(0) for j in edges[i]: if j == start: loop = [i] while i != start: i = parent[i] loop.append(i) if len(ret) > len(loop): ret = loop break if parent[j] == -1: parent[j] = i q.append(j) if len(ret) > n: print((-1)) else: print((len(ret))) for i in reversed(ret): print((i + 1))
n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) def dfs(index, visited, cycle): visited[index] = True cycle.append(index) for i in edges[index]: if visited.get(i): return cycle[cycle.index(i) :] ret = dfs(i, visited, cycle) if ret: return ret visited[index] = False cycle.pop(-1) return None def find_local_minimum(cycle): n = len(cycle) ind = {v: i for (i, v) in zip(list(range(n)), cycle)} ret = [] i = 0 while True: ret.append(i) nxt = 0 for j in [ind[v] for v in edges[cycle[i]] if v in ind]: if j < i: j += n nxt = max(nxt, j) if nxt >= n: ret = ret[ret.index(nxt % n) :] break i += 1 while i < nxt: del ind[cycle[i]] i += 1 return [cycle[i % n] for i in ret] cycle = None visited = {} for start in range(n): if start not in visited: cycle = dfs(start, visited, []) if cycle: break if cycle: ret = find_local_minimum(cycle) print((len(ret))) for i in ret: print((i + 1)) else: print((-1))
false
42.857143
[ "-ret = [0] * (n + 1)", "+", "+", "+def dfs(index, visited, cycle):", "+ visited[index] = True", "+ cycle.append(index)", "+ for i in edges[index]:", "+ if visited.get(i):", "+ return cycle[cycle.index(i) :]", "+ ret = dfs(i, visited, cycle)", "+ if ret:", "+ return ret", "+ visited[index] = False", "+ cycle.pop(-1)", "+ return None", "+", "+", "+def find_local_minimum(cycle):", "+ n = len(cycle)", "+ ind = {v: i for (i, v) in zip(list(range(n)), cycle)}", "+ ret = []", "+ i = 0", "+ while True:", "+ ret.append(i)", "+ nxt = 0", "+ for j in [ind[v] for v in edges[cycle[i]] if v in ind]:", "+ if j < i:", "+ j += n", "+ nxt = max(nxt, j)", "+ if nxt >= n:", "+ ret = ret[ret.index(nxt % n) :]", "+ break", "+ i += 1", "+ while i < nxt:", "+ del ind[cycle[i]]", "+ i += 1", "+ return [cycle[i % n] for i in ret]", "+", "+", "+cycle = None", "+visited = {}", "- parent = [-1] * n", "- q = [start]", "- while len(q) > 0:", "- i = q.pop(0)", "- for j in edges[i]:", "- if j == start:", "- loop = [i]", "- while i != start:", "- i = parent[i]", "- loop.append(i)", "- if len(ret) > len(loop):", "- ret = loop", "- break", "- if parent[j] == -1:", "- parent[j] = i", "- q.append(j)", "-if len(ret) > n:", "+ if start not in visited:", "+ cycle = dfs(start, visited, [])", "+ if cycle:", "+ break", "+if cycle:", "+ ret = find_local_minimum(cycle)", "+ print((len(ret)))", "+ for i in ret:", "+ print((i + 1))", "+else:", "-else:", "- print((len(ret)))", "- for i in reversed(ret):", "- print((i + 1))" ]
false
0.038353
0.038905
0.985827
[ "s105928553", "s762417748" ]
u965602776
p03031
python
s421815371
s760588610
67
33
3,064
3,064
Accepted
Accepted
50.75
n,m=list(map(int,input().split())) s=[] for _ in range(m): _,*t=list(map(int,input().split())) s.append(t) p=list(map(int,input().split())) a=0 for i in range(2**n): f=1 for j in range(m): g=1 g&=(sum([int(bin(i>>(u-1)),2) for u in s[j]])%2==p[j]) f&=g a+=f print(a)
n,m=list(map(int,input().split())) s=[] for _ in range(m):_,*t=list(map(int,input().split()));s.append(t) *p,=list(map(int,input().split())) print((sum([all([sum([i>>(u-1)for u in s[j]])%2==p[j]for j in range(m)])for i in range(2**n)])))
15
5
312
221
n, m = list(map(int, input().split())) s = [] for _ in range(m): _, *t = list(map(int, input().split())) s.append(t) p = list(map(int, input().split())) a = 0 for i in range(2**n): f = 1 for j in range(m): g = 1 g &= sum([int(bin(i >> (u - 1)), 2) for u in s[j]]) % 2 == p[j] f &= g a += f print(a)
n, m = list(map(int, input().split())) s = [] for _ in range(m): _, *t = list(map(int, input().split())) s.append(t) (*p,) = list(map(int, input().split())) print( ( sum( [ all([sum([i >> (u - 1) for u in s[j]]) % 2 == p[j] for j in range(m)]) for i in range(2**n) ] ) ) )
false
66.666667
[ "-p = list(map(int, input().split()))", "-a = 0", "-for i in range(2**n):", "- f = 1", "- for j in range(m):", "- g = 1", "- g &= sum([int(bin(i >> (u - 1)), 2) for u in s[j]]) % 2 == p[j]", "- f &= g", "- a += f", "-print(a)", "+(*p,) = list(map(int, input().split()))", "+print(", "+ (", "+ sum(", "+ [", "+ all([sum([i >> (u - 1) for u in s[j]]) % 2 == p[j] for j in range(m)])", "+ for i in range(2**n)", "+ ]", "+ )", "+ )", "+)" ]
false
0.044505
0.038548
1.154538
[ "s421815371", "s760588610" ]
u241159583
p03379
python
s216450330
s019628400
746
400
44,340
49,028
Accepted
Accepted
46.38
import statistics n = int(eval(input()))-1 a = list(map(int, input().split())) N = sorted([[x,y] for y, x in enumerate(a)]) ans = [0] * (n+1) for i in range(n+1): if i < n//2+1: ans[N[i][1]] = N[n//2+1][0] else: ans[N[i][1]] = N[n//2][0] for x in ans: print(x)
n = int(eval(input())) x = list(enumerate(map(int, input().split()))) x.sort(key=lambda x:x[1]) ans = [""]*n for i in range(n): if (n+1)//2 >= i+1: ans[x[i][0]] = x[(n+1)//2][1] else: ans[x[i][0]] = x[(n+1)//2-1][1] print(("\n".join(map(str, ans))))
11
9
282
254
import statistics n = int(eval(input())) - 1 a = list(map(int, input().split())) N = sorted([[x, y] for y, x in enumerate(a)]) ans = [0] * (n + 1) for i in range(n + 1): if i < n // 2 + 1: ans[N[i][1]] = N[n // 2 + 1][0] else: ans[N[i][1]] = N[n // 2][0] for x in ans: print(x)
n = int(eval(input())) x = list(enumerate(map(int, input().split()))) x.sort(key=lambda x: x[1]) ans = [""] * n for i in range(n): if (n + 1) // 2 >= i + 1: ans[x[i][0]] = x[(n + 1) // 2][1] else: ans[x[i][0]] = x[(n + 1) // 2 - 1][1] print(("\n".join(map(str, ans))))
false
18.181818
[ "-import statistics", "-", "-n = int(eval(input())) - 1", "-a = list(map(int, input().split()))", "-N = sorted([[x, y] for y, x in enumerate(a)])", "-ans = [0] * (n + 1)", "-for i in range(n + 1):", "- if i < n // 2 + 1:", "- ans[N[i][1]] = N[n // 2 + 1][0]", "+n = int(eval(input()))", "+x = list(enumerate(map(int, input().split())))", "+x.sort(key=lambda x: x[1])", "+ans = [\"\"] * n", "+for i in range(n):", "+ if (n + 1) // 2 >= i + 1:", "+ ans[x[i][0]] = x[(n + 1) // 2][1]", "- ans[N[i][1]] = N[n // 2][0]", "-for x in ans:", "- print(x)", "+ ans[x[i][0]] = x[(n + 1) // 2 - 1][1]", "+print((\"\\n\".join(map(str, ans))))" ]
false
0.162835
0.039001
4.175136
[ "s216450330", "s019628400" ]