user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u926412290
p03013
python
s804277372
s606472914
241
168
6,884
82,332
Accepted
Accepted
30.29
N, M = list(map(int, input().split())) oks = [True] * (N+1) for _ in range(M): a = int(eval(input())) oks[a] = False dp = [1] + [0] * N for now in range(N): for nxt in range(now+1, min(N, now+2)+1): if oks[nxt]: dp[nxt] += dp[now] dp[nxt] %= 1e9 + 7 print((int(dp[N])))
MOD = 10**9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] + [N + 1] dp = [0] * (N + 1) dp[0] = 1 s = -1 for broken in a: for j in range(s + 1, broken): if j > s + 1: dp[j] += dp[j - 1] % MOD if j > 1: dp[j] += dp[j - 2] % MOD dp[j] %= MOD s = broken print((dp[-1]))
15
17
316
365
N, M = list(map(int, input().split())) oks = [True] * (N + 1) for _ in range(M): a = int(eval(input())) oks[a] = False dp = [1] + [0] * N for now in range(N): for nxt in range(now + 1, min(N, now + 2) + 1): if oks[nxt]: dp[nxt] += dp[now] dp[nxt] %= 1e9 + 7 print((int(dp[N])))
MOD = 10**9 + 7 N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] + [N + 1] dp = [0] * (N + 1) dp[0] = 1 s = -1 for broken in a: for j in range(s + 1, broken): if j > s + 1: dp[j] += dp[j - 1] % MOD if j > 1: dp[j] += dp[j - 2] % MOD dp[j] %= MOD s = broken print((dp[-1]))
false
11.764706
[ "+MOD = 10**9 + 7", "-oks = [True] * (N + 1)", "-for _ in range(M):", "- a = int(eval(input()))", "- oks[a] = False", "-dp = [1] + [0] * N", "-for now in range(N):", "- for nxt in range(now + 1, min(N, now + 2) + 1):", "- if oks[nxt]:", "- dp[nxt] += dp[now]", "- dp[nxt] %= 1e9 + 7", "-print((int(dp[N])))", "+a = [int(eval(input())) for _ in range(M)] + [N + 1]", "+dp = [0] * (N + 1)", "+dp[0] = 1", "+s = -1", "+for broken in a:", "+ for j in range(s + 1, broken):", "+ if j > s + 1:", "+ dp[j] += dp[j - 1] % MOD", "+ if j > 1:", "+ dp[j] += dp[j - 2] % MOD", "+ dp[j] %= MOD", "+ s = broken", "+print((dp[-1]))" ]
false
0.036194
0.038263
0.945928
[ "s804277372", "s606472914" ]
u883048396
p03965
python
s200341439
s754758366
40
28
3,316
3,316
Accepted
Accepted
30
#len(s)//2-s.count("p") iG = 0 iR = 0 for s in input().rstrip(): if s == "g" : if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -= 1 iG += 1 print(iR)
#len(s)//2-s.count("p") def 解(): iG = 0 iR = 0 for s in input().rstrip(): if s == "g" : if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -= 1 iG += 1 print(iR) 解()
17
19
305
384
# len(s)//2-s.count("p") iG = 0 iR = 0 for s in input().rstrip(): if s == "g": if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -= 1 iG += 1 print(iR)
# len(s)//2-s.count("p") def 解(): iG = 0 iR = 0 for s in input().rstrip(): if s == "g": if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -= 1 iG += 1 print(iR) 解()
false
10.526316
[ "-iG = 0", "-iR = 0", "-for s in input().rstrip():", "- if s == \"g\":", "- if 0 < iG:", "- iR += 1", "- iG -= 1", "+def 解():", "+ iG = 0", "+ iR = 0", "+ for s in input().rstrip():", "+ if s == \"g\":", "+ if 0 < iG:", "+ iR += 1", "+ iG -= 1", "+ else:", "+ iG += 1", "- iG += 1", "- else:", "- if 0 < iG:", "- iG -= 1", "- else:", "- iR -= 1", "- iG += 1", "-print(iR)", "+ if 0 < iG:", "+ iG -= 1", "+ else:", "+ iR -= 1", "+ iG += 1", "+ print(iR)", "+", "+", "+解()" ]
false
0.034276
0.088792
0.386026
[ "s200341439", "s754758366" ]
u888092736
p02743
python
s237111377
s271810424
171
28
38,424
9,048
Accepted
Accepted
83.63
a, b, c = list(map(int, input().split())) if c - a - b > 0 and (c - a - b) ** 2 > 4 * a * b: print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) d = c - a - b if d >= 0 and d * d > 4 * a * b: print("Yes") else: print("No")
5
6
129
127
a, b, c = list(map(int, input().split())) if c - a - b > 0 and (c - a - b) ** 2 > 4 * a * b: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) d = c - a - b if d >= 0 and d * d > 4 * a * b: print("Yes") else: print("No")
false
16.666667
[ "-if c - a - b > 0 and (c - a - b) ** 2 > 4 * a * b:", "+d = c - a - b", "+if d >= 0 and d * d > 4 * a * b:" ]
false
0.08478
0.063067
1.344277
[ "s237111377", "s271810424" ]
u977661421
p02881
python
s193607066
s117187904
290
149
2,940
3,060
Accepted
Accepted
48.62
# -*- coding: utf-8 -*- n = int(eval(input())) ans = pow(10, 30) for i in range(1, int(pow(n, 0.5)) + 1): if n / i == n // i: j = n // i if i + j - 2 < ans: ans = i + j - 2 print(ans)
# -*- coding: utf-8 -*- n = int(eval(input())) ans = [10 ** 14, 10 ** 14] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: tmp = n // i if tmp + i < sum(ans): ans = [i, tmp] print((sum(ans) - 2))
10
11
220
239
# -*- coding: utf-8 -*- n = int(eval(input())) ans = pow(10, 30) for i in range(1, int(pow(n, 0.5)) + 1): if n / i == n // i: j = n // i if i + j - 2 < ans: ans = i + j - 2 print(ans)
# -*- coding: utf-8 -*- n = int(eval(input())) ans = [10**14, 10**14] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: tmp = n // i if tmp + i < sum(ans): ans = [i, tmp] print((sum(ans) - 2))
false
9.090909
[ "-ans = pow(10, 30)", "+ans = [10**14, 10**14]", "- if n / i == n // i:", "- j = n // i", "- if i + j - 2 < ans:", "- ans = i + j - 2", "-print(ans)", "+ if n % i == 0:", "+ tmp = n // i", "+ if tmp + i < sum(ans):", "+ ans = [i, tmp]", "+print((sum(ans) - 2))" ]
false
0.058237
0.037492
1.553328
[ "s193607066", "s117187904" ]
u933140383
p02657
python
s157021841
s164424083
24
22
9,160
9,124
Accepted
Accepted
8.33
a,b=input().split(' ') print((int(a)*int(b)))
a,b=input().split(' ') if int(a)<=100 and int(b)<=100: print((int(a)*int(b))) else: pass
2
5
44
98
a, b = input().split(" ") print((int(a) * int(b)))
a, b = input().split(" ") if int(a) <= 100 and int(b) <= 100: print((int(a) * int(b))) else: pass
false
60
[ "-print((int(a) * int(b)))", "+if int(a) <= 100 and int(b) <= 100:", "+ print((int(a) * int(b)))", "+else:", "+ pass" ]
false
0.044286
0.117661
0.376385
[ "s157021841", "s164424083" ]
u815797488
p03408
python
s590456558
s051215075
19
17
3,188
3,060
Accepted
Accepted
10.53
dic = {} N = int(eval(input())) s = [eval(input()) for i in range(N)] for i in range(N): dic.setdefault(s[i],0) dic[s[i]] += 1 M = int(eval(input())) t = [eval(input()) for j in range(M)] for j in range(M): dic.setdefault(t[j],0) dic[t[j]] -= 1 if max(dic.values()) > 0: print((max(dic.values()))) else: print((0))
dic = {} N = int(eval(input())) for k in range(N): i = eval(input()) if i in dic: dic[i] += 1 else: dic[i] = 1 M = int(eval(input())) for j in range(M): i = eval(input()) if i in dic: dic[i] -= 1 print((max(max(dic.values()), 0)))
18
17
320
245
dic = {} N = int(eval(input())) s = [eval(input()) for i in range(N)] for i in range(N): dic.setdefault(s[i], 0) dic[s[i]] += 1 M = int(eval(input())) t = [eval(input()) for j in range(M)] for j in range(M): dic.setdefault(t[j], 0) dic[t[j]] -= 1 if max(dic.values()) > 0: print((max(dic.values()))) else: print((0))
dic = {} N = int(eval(input())) for k in range(N): i = eval(input()) if i in dic: dic[i] += 1 else: dic[i] = 1 M = int(eval(input())) for j in range(M): i = eval(input()) if i in dic: dic[i] -= 1 print((max(max(dic.values()), 0)))
false
5.555556
[ "-s = [eval(input()) for i in range(N)]", "-for i in range(N):", "- dic.setdefault(s[i], 0)", "- dic[s[i]] += 1", "+for k in range(N):", "+ i = eval(input())", "+ if i in dic:", "+ dic[i] += 1", "+ else:", "+ dic[i] = 1", "-t = [eval(input()) for j in range(M)]", "- dic.setdefault(t[j], 0)", "- dic[t[j]] -= 1", "-if max(dic.values()) > 0:", "- print((max(dic.values())))", "-else:", "- print((0))", "+ i = eval(input())", "+ if i in dic:", "+ dic[i] -= 1", "+print((max(max(dic.values()), 0)))" ]
false
0.038083
0.039362
0.967496
[ "s590456558", "s051215075" ]
u153729035
p02629
python
s876547006
s789702263
41
31
9,116
9,088
Accepted
Accepted
24.39
def f(n): alphabets = "abcdefghijklmnopqrstuvwxyz" s = "" while n > 0: n, mod = divmod(n, 26) if mod == 0: s += 'z' n -= 1 else: s += alphabets[mod - 1] return s[::-1] print((f(int(eval(input())))))
n = int(eval(input())) a = "abcdefghijklmnopqrstuvwxyz" s = "" while n > 0: n, m = divmod(n, 26) if not m: n -= 1 s = a[(m - 1) % 26] + s print(s)
15
12
287
174
def f(n): alphabets = "abcdefghijklmnopqrstuvwxyz" s = "" while n > 0: n, mod = divmod(n, 26) if mod == 0: s += "z" n -= 1 else: s += alphabets[mod - 1] return s[::-1] print((f(int(eval(input())))))
n = int(eval(input())) a = "abcdefghijklmnopqrstuvwxyz" s = "" while n > 0: n, m = divmod(n, 26) if not m: n -= 1 s = a[(m - 1) % 26] + s print(s)
false
20
[ "-def f(n):", "- alphabets = \"abcdefghijklmnopqrstuvwxyz\"", "- s = \"\"", "- while n > 0:", "- n, mod = divmod(n, 26)", "- if mod == 0:", "- s += \"z\"", "- n -= 1", "- else:", "- s += alphabets[mod - 1]", "- return s[::-1]", "-", "-", "-print((f(int(eval(input())))))", "+n = int(eval(input()))", "+a = \"abcdefghijklmnopqrstuvwxyz\"", "+s = \"\"", "+while n > 0:", "+ n, m = divmod(n, 26)", "+ if not m:", "+ n -= 1", "+ s = a[(m - 1) % 26] + s", "+print(s)" ]
false
0.035134
0.035329
0.994463
[ "s876547006", "s789702263" ]
u073549161
p03029
python
s247341133
s786455801
165
18
38,256
2,940
Accepted
Accepted
89.09
a,p = list(map(int, input().split())) p += a * 3 print((int(p/2)))
a, p = list(map(int, input().split())) p += a * 3 print((p//2))
3
3
60
57
a, p = list(map(int, input().split())) p += a * 3 print((int(p / 2)))
a, p = list(map(int, input().split())) p += a * 3 print((p // 2))
false
0
[ "-print((int(p / 2)))", "+print((p // 2))" ]
false
0.066617
0.036606
1.819824
[ "s247341133", "s786455801" ]
u746419473
p03408
python
s970269235
s659560817
20
17
2,940
3,060
Accepted
Accepted
15
n=[eval(input()) for _ in range(int(eval(input())))] m=[eval(input()) for _ in range(int(eval(input())))] l=list(set(n)) print((max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l))))))
ans = {} n = int(eval(input())) for _ in range(n): s = eval(input()) ans.setdefault(s, 0) ans[s] += 1 m = int(eval(input())) for _ in range(m): t = eval(input()) ans.setdefault(t, 0) ans[t] -= 1 ans = sorted(list(ans.items()), key=lambda x: x[1], reverse=True) print((max(0, ans[0][1])))
4
15
170
296
n = [eval(input()) for _ in range(int(eval(input())))] m = [eval(input()) for _ in range(int(eval(input())))] l = list(set(n)) print((max(0, max(n.count(l[i]) - m.count(l[i]) for i in range(len(l))))))
ans = {} n = int(eval(input())) for _ in range(n): s = eval(input()) ans.setdefault(s, 0) ans[s] += 1 m = int(eval(input())) for _ in range(m): t = eval(input()) ans.setdefault(t, 0) ans[t] -= 1 ans = sorted(list(ans.items()), key=lambda x: x[1], reverse=True) print((max(0, ans[0][1])))
false
73.333333
[ "-n = [eval(input()) for _ in range(int(eval(input())))]", "-m = [eval(input()) for _ in range(int(eval(input())))]", "-l = list(set(n))", "-print((max(0, max(n.count(l[i]) - m.count(l[i]) for i in range(len(l))))))", "+ans = {}", "+n = int(eval(input()))", "+for _ in range(n):", "+ s = eval(input())", "+ ans.setdefault(s, 0)", "+ ans[s] += 1", "+m = int(eval(input()))", "+for _ in range(m):", "+ t = eval(input())", "+ ans.setdefault(t, 0)", "+ ans[t] -= 1", "+ans = sorted(list(ans.items()), key=lambda x: x[1], reverse=True)", "+print((max(0, ans[0][1])))" ]
false
0.051963
0.083353
0.623403
[ "s970269235", "s659560817" ]
u840310460
p03486
python
s443119935
s503277985
179
17
38,384
3,064
Accepted
Accepted
90.5
S = sorted(eval(input())) T = sorted(eval(input()), reverse=True) if S < T: print("Yes") else: print("No")
s = sorted(eval(input())) t = sorted(eval(input()), reverse=True) if s<t: print("Yes") else: print("No")
7
6
109
105
S = sorted(eval(input())) T = sorted(eval(input()), reverse=True) if S < T: print("Yes") else: print("No")
s = sorted(eval(input())) t = sorted(eval(input()), reverse=True) if s < t: print("Yes") else: print("No")
false
14.285714
[ "-S = sorted(eval(input()))", "-T = sorted(eval(input()), reverse=True)", "-if S < T:", "+s = sorted(eval(input()))", "+t = sorted(eval(input()), reverse=True)", "+if s < t:" ]
false
0.040805
0.039949
1.02143
[ "s443119935", "s503277985" ]
u564902833
p03006
python
s612977338
s397162403
492
22
62,940
3,828
Accepted
Accepted
95.53
N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) class UnionFindTree: def __init__(self, n): self.p = [i for i in range(n + 1)] self.r = [0 for _ in range(n + 1)] def find(self, x): if self.p[x] != x: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): px = self.find(x) py = self.find(y) if px != py: if self.r[px] < self.r[py]: self.p[px] = py else: self.p[py] = px if self.r[px] == self.r[py]: self.r[px] += 1 def same(self, x, y): return self.find(x) == self.find(y) ans = 10**10 for i in range(N): for j in range(N): p, q = (x[i] - x[j], y[i] - y[j]) uft = UnionFindTree(N) for u in range(N - 1): for v in range(u + 1, N): if (x[u] - x[v], y[u] - y[v]) == (p, q) or (x[u] - x[v], y[u] - y[v]) == (-p, -q): uft.union(u, v) ans = min(ans, len({uft.find(z) for z in range(N)})) print(ans)
from collections import Counter from itertools import permutations N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) # (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように # p, qを定めればよい ans = ( 1 if N == 1 else N - max( Counter( (x[i] - x[j], y[i] - y[j]) for i, j in permutations(list(range(N)), 2) ).values() ) ) print(ans)
44
22
1,189
456
N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) class UnionFindTree: def __init__(self, n): self.p = [i for i in range(n + 1)] self.r = [0 for _ in range(n + 1)] def find(self, x): if self.p[x] != x: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): px = self.find(x) py = self.find(y) if px != py: if self.r[px] < self.r[py]: self.p[px] = py else: self.p[py] = px if self.r[px] == self.r[py]: self.r[px] += 1 def same(self, x, y): return self.find(x) == self.find(y) ans = 10**10 for i in range(N): for j in range(N): p, q = (x[i] - x[j], y[i] - y[j]) uft = UnionFindTree(N) for u in range(N - 1): for v in range(u + 1, N): if (x[u] - x[v], y[u] - y[v]) == (p, q) or ( x[u] - x[v], y[u] - y[v], ) == (-p, -q): uft.union(u, v) ans = min(ans, len({uft.find(z) for z in range(N)})) print(ans)
from collections import Counter from itertools import permutations N = int(eval(input())) x, y = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) # (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように # p, qを定めればよい ans = ( 1 if N == 1 else N - max( Counter( (x[i] - x[j], y[i] - y[j]) for i, j in permutations(list(range(N)), 2) ).values() ) ) print(ans)
false
50
[ "+from collections import Counter", "+from itertools import permutations", "+", "-", "-", "-class UnionFindTree:", "- def __init__(self, n):", "- self.p = [i for i in range(n + 1)]", "- self.r = [0 for _ in range(n + 1)]", "-", "- def find(self, x):", "- if self.p[x] != x:", "- self.p[x] = self.find(self.p[x])", "- return self.p[x]", "-", "- def union(self, x, y):", "- px = self.find(x)", "- py = self.find(y)", "- if px != py:", "- if self.r[px] < self.r[py]:", "- self.p[px] = py", "- else:", "- self.p[py] = px", "- if self.r[px] == self.r[py]:", "- self.r[px] += 1", "-", "- def same(self, x, y):", "- return self.find(x) == self.find(y)", "-", "-", "-ans = 10**10", "-for i in range(N):", "- for j in range(N):", "- p, q = (x[i] - x[j], y[i] - y[j])", "- uft = UnionFindTree(N)", "- for u in range(N - 1):", "- for v in range(u + 1, N):", "- if (x[u] - x[v], y[u] - y[v]) == (p, q) or (", "- x[u] - x[v],", "- y[u] - y[v],", "- ) == (-p, -q):", "- uft.union(u, v)", "- ans = min(ans, len({uft.find(z) for z in range(N)}))", "+# (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように", "+# p, qを定めればよい", "+ans = (", "+ 1", "+ if N == 1", "+ else N", "+ - max(", "+ Counter(", "+ (x[i] - x[j], y[i] - y[j]) for i, j in permutations(list(range(N)), 2)", "+ ).values()", "+ )", "+)" ]
false
0.042486
0.035436
1.198949
[ "s612977338", "s397162403" ]
u698176039
p03607
python
s965909519
s410517718
239
212
19,084
16,644
Accepted
Accepted
11.3
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] mydict = dict() cnt = 0 for i in range(N): if not (A[i] in mydict): mydict[A[i]] = i counter = [0] * N for a in A: counter[mydict[a]] += 1 ans = 0 for c in counter: if c%2 == 1: ans += 1 print(ans)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] import collections c = collections.Counter(A) ans = 0 for t in list(c.values()): if t%2 == 1: ans += 1 print(ans)
20
10
312
180
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] mydict = dict() cnt = 0 for i in range(N): if not (A[i] in mydict): mydict[A[i]] = i counter = [0] * N for a in A: counter[mydict[a]] += 1 ans = 0 for c in counter: if c % 2 == 1: ans += 1 print(ans)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] import collections c = collections.Counter(A) ans = 0 for t in list(c.values()): if t % 2 == 1: ans += 1 print(ans)
false
50
[ "-mydict = dict()", "-cnt = 0", "-for i in range(N):", "- if not (A[i] in mydict):", "- mydict[A[i]] = i", "-counter = [0] * N", "-for a in A:", "- counter[mydict[a]] += 1", "+import collections", "+", "+c = collections.Counter(A)", "-for c in counter:", "- if c % 2 == 1:", "+for t in list(c.values()):", "+ if t % 2 == 1:" ]
false
0.049021
0.049949
0.98142
[ "s965909519", "s410517718" ]
u620238824
p02712
python
s543191627
s445944723
195
155
33,860
9,068
Accepted
Accepted
20.51
N = int(eval(input())) #スペース抜きの複数行,1文字ずつ A = [] for i in range(1,N+1): if i % 3 == 0: A.append(0) elif i % 5 == 0: A.append(0) else: A.append(i) print((sum(A)))
N = int(eval(input())) sum = 0 for i in range(1, N + 1): if i % 3 == 0: continue elif i % 5 == 0: continue else: sum += i print(sum)
12
12
185
175
N = int(eval(input())) # スペース抜きの複数行,1文字ずつ A = [] for i in range(1, N + 1): if i % 3 == 0: A.append(0) elif i % 5 == 0: A.append(0) else: A.append(i) print((sum(A)))
N = int(eval(input())) sum = 0 for i in range(1, N + 1): if i % 3 == 0: continue elif i % 5 == 0: continue else: sum += i print(sum)
false
0
[ "-N = int(eval(input())) # スペース抜きの複数行,1文字ずつ", "-A = []", "+N = int(eval(input()))", "+sum = 0", "- A.append(0)", "+ continue", "- A.append(0)", "+ continue", "- A.append(i)", "-print((sum(A)))", "+ sum += i", "+print(sum)" ]
false
0.199935
0.136688
1.462719
[ "s543191627", "s445944723" ]
u021019433
p02732
python
s120288834
s025405940
327
282
26,780
26,780
Accepted
Accepted
13.76
from collections import Counter eval(input()) a = list(map(int, input().split())) c = Counter(a) s = sum(k * (k - 1) // 2 for k in list(c.values())) for x in a: print((s - c[x] + 1))
from collections import Counter eval(input()) a = list(map(int, input().split())) c = Counter(a) s = sum(k * (k - 1) // 2 for k in list(c.values())) + 1 for x in a: print((s - c[x]))
8
8
180
180
from collections import Counter eval(input()) a = list(map(int, input().split())) c = Counter(a) s = sum(k * (k - 1) // 2 for k in list(c.values())) for x in a: print((s - c[x] + 1))
from collections import Counter eval(input()) a = list(map(int, input().split())) c = Counter(a) s = sum(k * (k - 1) // 2 for k in list(c.values())) + 1 for x in a: print((s - c[x]))
false
0
[ "-s = sum(k * (k - 1) // 2 for k in list(c.values()))", "+s = sum(k * (k - 1) // 2 for k in list(c.values())) + 1", "- print((s - c[x] + 1))", "+ print((s - c[x]))" ]
false
0.045799
0.046963
0.975206
[ "s120288834", "s025405940" ]
u785989355
p02901
python
s260003436
s593292573
808
579
163,460
85,220
Accepted
Accepted
28.34
N,M = list(map(int,input().split())) A = [] C = [] for i in range(M): a,b = list(map(int,input().split())) c = list(map(int,input().split())) A.append(a) d = 0 for j in range(b): d += pow(2, c[j]-1) C.append(d) goal = pow(2, N)-1 e_list = [[] for i in range(goal+1)] for i in range(goal+1): for j in range(M): e_list[i].append((i|C[j],A[j])) #dijkstra #you need to prepare e_list = [[orient,dist]] import heapq vi = 0 min_d_list = [10**27 for i in range(goal+1)] min_d_list[vi] = 0 q = [] for i in range(N): heapq.heappush(q,[min_d_list[i],i]) while len(q)>0: d,v = heapq.heappop(q) for e in e_list[v]: v1,d1=e if min_d_list[v1]>d+d1: min_d_list[v1]=d+d1 heapq.heappush(q,[d+d1,v1]) if min_d_list[goal]>=10**27: print((-1)) else: print((min_d_list[goal]))
N,M = list(map(int,input().split())) a_list = [] c_list = [] for i in range(M): a,b = list(map(int,input().split())) a_list.append(a) c = list(map(int,input().split())) d = 0 for cc in c: d += 2**(cc-1) c_list.append(d) DP = [[10**27]*(2**N) for i in range(M+1)] DP[0][0]=0 for i in range(1,M+1): for j in range(2**N): #print(c_list[i-1] | j) DP[i][j] = min(DP[i][j],DP[i-1][j]) DP[i][c_list[i-1] | j] = min(DP[i][c_list[i-1] | j],DP[i-1][j] + a_list[i-1]) #print(DP) if DP[M][2**N-1]>=10**27: print((-1)) else: print((DP[M][2**N-1]))
41
27
900
628
N, M = list(map(int, input().split())) A = [] C = [] for i in range(M): a, b = list(map(int, input().split())) c = list(map(int, input().split())) A.append(a) d = 0 for j in range(b): d += pow(2, c[j] - 1) C.append(d) goal = pow(2, N) - 1 e_list = [[] for i in range(goal + 1)] for i in range(goal + 1): for j in range(M): e_list[i].append((i | C[j], A[j])) # dijkstra # you need to prepare e_list = [[orient,dist]] import heapq vi = 0 min_d_list = [10**27 for i in range(goal + 1)] min_d_list[vi] = 0 q = [] for i in range(N): heapq.heappush(q, [min_d_list[i], i]) while len(q) > 0: d, v = heapq.heappop(q) for e in e_list[v]: v1, d1 = e if min_d_list[v1] > d + d1: min_d_list[v1] = d + d1 heapq.heappush(q, [d + d1, v1]) if min_d_list[goal] >= 10**27: print((-1)) else: print((min_d_list[goal]))
N, M = list(map(int, input().split())) a_list = [] c_list = [] for i in range(M): a, b = list(map(int, input().split())) a_list.append(a) c = list(map(int, input().split())) d = 0 for cc in c: d += 2 ** (cc - 1) c_list.append(d) DP = [[10**27] * (2**N) for i in range(M + 1)] DP[0][0] = 0 for i in range(1, M + 1): for j in range(2**N): # print(c_list[i-1] | j) DP[i][j] = min(DP[i][j], DP[i - 1][j]) DP[i][c_list[i - 1] | j] = min( DP[i][c_list[i - 1] | j], DP[i - 1][j] + a_list[i - 1] ) # print(DP) if DP[M][2**N - 1] >= 10**27: print((-1)) else: print((DP[M][2**N - 1]))
false
34.146341
[ "-A = []", "-C = []", "+a_list = []", "+c_list = []", "+ a_list.append(a)", "- A.append(a)", "- for j in range(b):", "- d += pow(2, c[j] - 1)", "- C.append(d)", "-goal = pow(2, N) - 1", "-e_list = [[] for i in range(goal + 1)]", "-for i in range(goal + 1):", "- for j in range(M):", "- e_list[i].append((i | C[j], A[j]))", "-# dijkstra", "-# you need to prepare e_list = [[orient,dist]]", "-import heapq", "-", "-vi = 0", "-min_d_list = [10**27 for i in range(goal + 1)]", "-min_d_list[vi] = 0", "-q = []", "-for i in range(N):", "- heapq.heappush(q, [min_d_list[i], i])", "-while len(q) > 0:", "- d, v = heapq.heappop(q)", "- for e in e_list[v]:", "- v1, d1 = e", "- if min_d_list[v1] > d + d1:", "- min_d_list[v1] = d + d1", "- heapq.heappush(q, [d + d1, v1])", "-if min_d_list[goal] >= 10**27:", "+ for cc in c:", "+ d += 2 ** (cc - 1)", "+ c_list.append(d)", "+DP = [[10**27] * (2**N) for i in range(M + 1)]", "+DP[0][0] = 0", "+for i in range(1, M + 1):", "+ for j in range(2**N):", "+ # print(c_list[i-1] | j)", "+ DP[i][j] = min(DP[i][j], DP[i - 1][j])", "+ DP[i][c_list[i - 1] | j] = min(", "+ DP[i][c_list[i - 1] | j], DP[i - 1][j] + a_list[i - 1]", "+ )", "+# print(DP)", "+if DP[M][2**N - 1] >= 10**27:", "- print((min_d_list[goal]))", "+ print((DP[M][2**N - 1]))" ]
false
0.04899
0.082592
0.593157
[ "s260003436", "s593292573" ]
u620084012
p03611
python
s636015571
s012568991
113
86
14,564
84,768
Accepted
Accepted
23.89
from collections import Counter N = int(eval(input())) A = list(map(int,input().split())) C = Counter(A) ans = 0 for e in C: ans = max(ans,C[e]+C[e-1]+C[e+1]) print(ans)
N = int(eval(input())) a = list(map(int,input().split())) b = [0]*(10**5+10) for e in a: b[e+1] += 1 ans = 0 for k in range(10**5+2): ans = max(ans,b[k]+b[k+1]+b[k+2]) print(ans)
9
9
177
189
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) ans = 0 for e in C: ans = max(ans, C[e] + C[e - 1] + C[e + 1]) print(ans)
N = int(eval(input())) a = list(map(int, input().split())) b = [0] * (10**5 + 10) for e in a: b[e + 1] += 1 ans = 0 for k in range(10**5 + 2): ans = max(ans, b[k] + b[k + 1] + b[k + 2]) print(ans)
false
0
[ "-from collections import Counter", "-", "-A = list(map(int, input().split()))", "-C = Counter(A)", "+a = list(map(int, input().split()))", "+b = [0] * (10**5 + 10)", "+for e in a:", "+ b[e + 1] += 1", "-for e in C:", "- ans = max(ans, C[e] + C[e - 1] + C[e + 1])", "+for k in range(10**5 + 2):", "+ ans = max(ans, b[k] + b[k + 1] + b[k + 2])" ]
false
0.080753
0.095319
0.847186
[ "s636015571", "s012568991" ]
u989345508
p02696
python
s594594747
s076659012
22
19
9,120
8,936
Accepted
Accepted
13.64
a,b,n=list(map(int,input().split()));print((a*min(n,b-1)//b))
a,b,n=list(map(int,input().split()));print((a*min(b-1,n)//b))
1
1
53
53
a, b, n = list(map(int, input().split())) print((a * min(n, b - 1) // b))
a, b, n = list(map(int, input().split())) print((a * min(b - 1, n) // b))
false
0
[ "-print((a * min(n, b - 1) // b))", "+print((a * min(b - 1, n) // b))" ]
false
0.108144
0.10103
1.070412
[ "s594594747", "s076659012" ]
u334712262
p02679
python
s017717836
s240810239
1,683
691
133,484
172,908
Accepted
Accepted
58.94
# -*- coding: utf-8 -*- from fractions import Fraction from collections import Counter import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def fract(a, b): if a == 0 and b == 0: return (0, 0) if b == 0: return (1, 0) f = Fraction(a, b) a = f.numerator b = f.denominator return a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m-2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: k = fract(a, b) adb[k] += 1 M = Mod(1000000007) ans = 1 done = {(0, 0)} for k, v in adb.items(): if k in done: continue a, b = k kk = fract(-b, a) done.add(k) done.add(kk) n = adb[kk] t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) ans = M.add(ans, adb[(0, 0)]) return M.sub(ans, 1) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- from fractions import Fraction from collections import Counter import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m-2, self.m)) def pow(self, a, b): return pow(a, b, self.m) def fract(a, b): if a == 0 and b == 0: return (0, 0) if b == 0: return (1, 0) f = Fraction(a, b) return f.numerator, f.denominator @mt def slv(N, AB): adb = Counter() for a, b in AB: k = fract(a, b) adb[k] += 1 M = Mod(1000000007) ans = 1 done = {(0, 0)} for k, v in adb.items(): if k in done: continue a, b = k kk = fract(-b, a) done.add(k) done.add(kk) n = adb[kk] t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) ans = M.add(ans, adb[(0, 0)]) return M.sub(ans, 1) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == '__main__': main()
119
117
2,202
2,180
# -*- coding: utf-8 -*- from fractions import Fraction from collections import Counter import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def fract(a, b): if a == 0 and b == 0: return (0, 0) if b == 0: return (1, 0) f = Fraction(a, b) a = f.numerator b = f.denominator return a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m - 2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: k = fract(a, b) adb[k] += 1 M = Mod(1000000007) ans = 1 done = {(0, 0)} for k, v in adb.items(): if k in done: continue a, b = k kk = fract(-b, a) done.add(k) done.add(kk) n = adb[kk] t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) ans = M.add(ans, adb[(0, 0)]) return M.sub(ans, 1) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- from fractions import Fraction from collections import Counter import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m - 2, self.m)) def pow(self, a, b): return pow(a, b, self.m) def fract(a, b): if a == 0 and b == 0: return (0, 0) if b == 0: return (1, 0) f = Fraction(a, b) return f.numerator, f.denominator @mt def slv(N, AB): adb = Counter() for a, b in AB: k = fract(a, b) adb[k] += 1 M = Mod(1000000007) ans = 1 done = {(0, 0)} for k, v in adb.items(): if k in done: continue a, b = k kk = fract(-b, a) done.add(k) done.add(kk) n = adb[kk] t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) ans = M.add(ans, adb[(0, 0)]) return M.sub(ans, 1) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == "__main__": main()
false
1.680672
[ "-def fract(a, b):", "- if a == 0 and b == 0:", "- return (0, 0)", "- if b == 0:", "- return (1, 0)", "- f = Fraction(a, b)", "- a = f.numerator", "- b = f.denominator", "- return a, b", "-", "-", "+", "+", "+def fract(a, b):", "+ if a == 0 and b == 0:", "+ return (0, 0)", "+ if b == 0:", "+ return (1, 0)", "+ f = Fraction(a, b)", "+ return f.numerator, f.denominator" ]
false
0.051907
0.038317
1.354673
[ "s017717836", "s240810239" ]
u334712262
p02692
python
s514960455
s524052362
620
332
90,616
80,276
Accepted
Accepted
46.45
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(10**6) buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, A, B, C, S): D = [A, B, C] ans = [] def f(s): t = [] if 'A' in s: t.append(0) if 'B' in s: t.append(1) if 'C' in s: t.append(2) return t for i, s in enumerate(S): t = f(s) if D[t[0]] == 0 and D[t[1]] == 0: print('No') return else: if D[t[0]] == D[t[1]] == 1 and i != N-1: ns = S[i+1] if s == ns: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: n = set(t) & set(f(ns)) m = set(t) - n n = n.pop() m = m.pop() ans.append(n) D[n] += 1 D[m] -= 1 elif D[t[0]] > D[t[1]]: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: ans.append(t[0]) D[t[0]] += 1 D[t[1]] -= 1 print('Yes') for a in ans: if a == 0: print('A') elif a == 1: print('B') else: print('C') def main(): N, A, B, C = read_int_n() S = [read_str() for _ in range(N)] (slv(N, A, B, C, S)) # N = 10**5 # A = random.randint(1, 10**9) # B = random.randint(1, 10**9) # C = random.randint(1, 10**9) # S = random.choices(['AB', 'AC', 'BC'], k=N) # (slv(N, A, B, C, S)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import sys buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int_n(): return list(map(int, buff_readline().split())) def read_str(): return readline().strip() def slv(N, A, B, C, S): D = [A, B, C] ans = [] def f(s): t = [] if 'A' in s: t.append(0) if 'B' in s: t.append(1) if 'C' in s: t.append(2) return t for i, s in enumerate(S): t = f(s) if D[t[0]] == 0 and D[t[1]] == 0: print('No') return else: if D[t[0]] == D[t[1]] == 1 and i != N-1: ns = S[i+1] if s == ns: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: n = set(t) & set(f(ns)) m = set(t) - n n = n.pop() m = m.pop() ans.append(n) D[n] += 1 D[m] -= 1 elif D[t[0]] > D[t[1]]: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: ans.append(t[0]) D[t[0]] += 1 D[t[1]] -= 1 print('Yes') for a in ans: if a == 0: print('A') elif a == 1: print('B') else: print('C') def main(): N, A, B, C = read_int_n() S = [read_str() for _ in range(N)] (slv(N, A, B, C, S)) if __name__ == '__main__': main()
131
76
2,842
1,702
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(10**6) buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, A, B, C, S): D = [A, B, C] ans = [] def f(s): t = [] if "A" in s: t.append(0) if "B" in s: t.append(1) if "C" in s: t.append(2) return t for i, s in enumerate(S): t = f(s) if D[t[0]] == 0 and D[t[1]] == 0: print("No") return else: if D[t[0]] == D[t[1]] == 1 and i != N - 1: ns = S[i + 1] if s == ns: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: n = set(t) & set(f(ns)) m = set(t) - n n = n.pop() m = m.pop() ans.append(n) D[n] += 1 D[m] -= 1 elif D[t[0]] > D[t[1]]: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: ans.append(t[0]) D[t[0]] += 1 D[t[1]] -= 1 print("Yes") for a in ans: if a == 0: print("A") elif a == 1: print("B") else: print("C") def main(): N, A, B, C = read_int_n() S = [read_str() for _ in range(N)] (slv(N, A, B, C, S)) # N = 10**5 # A = random.randint(1, 10**9) # B = random.randint(1, 10**9) # C = random.randint(1, 10**9) # S = random.choices(['AB', 'AC', 'BC'], k=N) # (slv(N, A, B, C, S)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int_n(): return list(map(int, buff_readline().split())) def read_str(): return readline().strip() def slv(N, A, B, C, S): D = [A, B, C] ans = [] def f(s): t = [] if "A" in s: t.append(0) if "B" in s: t.append(1) if "C" in s: t.append(2) return t for i, s in enumerate(S): t = f(s) if D[t[0]] == 0 and D[t[1]] == 0: print("No") return else: if D[t[0]] == D[t[1]] == 1 and i != N - 1: ns = S[i + 1] if s == ns: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: n = set(t) & set(f(ns)) m = set(t) - n n = n.pop() m = m.pop() ans.append(n) D[n] += 1 D[m] -= 1 elif D[t[0]] > D[t[1]]: ans.append(t[1]) D[t[0]] -= 1 D[t[1]] += 1 else: ans.append(t[0]) D[t[0]] += 1 D[t[1]] -= 1 print("Yes") for a in ans: if a == 0: print("A") elif a == 1: print("B") else: print("C") def main(): N, A, B, C = read_int_n() S = [read_str() for _ in range(N)] (slv(N, A, B, C, S)) if __name__ == "__main__": main()
false
41.984733
[ "-import bisect", "-import heapq", "-import math", "-import random", "-from collections import Counter, defaultdict, deque", "-from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal", "-from functools import lru_cache, reduce", "-from itertools import combinations, combinations_with_replacement, product, permutations", "-from operator import add, mul, sub", "-sys.setrecursionlimit(10**6)", "-INF = 2**62 - 1", "-", "-", "-def read_int():", "- return int(buff_readline())", "-def read_float():", "- return float(buff_readline())", "-", "-", "-def read_float_n():", "- return list(map(float, buff_readline().split()))", "-", "-", "-def read_str_n():", "- return readline().strip().split()", "-", "-", "-def error_print(*args):", "- print(*args, file=sys.stderr)", "-", "-", "-def mt(f):", "- import time", "-", "- def wrap(*args, **kwargs):", "- s = time.time()", "- ret = f(*args, **kwargs)", "- e = time.time()", "- error_print(e - s, \"sec\")", "- return ret", "-", "- return wrap", "-", "-", "-@mt", "- # N = 10**5", "- # A = random.randint(1, 10**9)", "- # B = random.randint(1, 10**9)", "- # C = random.randint(1, 10**9)", "- # S = random.choices(['AB', 'AC', 'BC'], k=N)", "- # (slv(N, A, B, C, S))" ]
false
0.031664
0.036634
0.864337
[ "s514960455", "s524052362" ]
u922449550
p02564
python
s460846341
s822154396
4,098
917
179,268
202,812
Accepted
Accepted
77.62
class CSR: def __init__(self, n: int, edges: list): self.start = [0] * (n+1) self.elist = [0] * len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1, n+1): self.start[i] += self.start[i-1] counter = self.start[::] # copy for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class SccGraph: def __init__(self, n: int = 0): self.__n = n self.__edges = [] def __len__(self): return self.__n def add_edge(self, s: int, t: int): assert 0 <= s < self.__n and 0 <= t < self.__n self.__edges.append([s, t]) def __scc_ids(self): g = CSR(self.__n, self.__edges) now_ord = group_num = 0 visited = [] low = [0] * self.__n order = [-1] * self.__n ids = [0] * self.__n parent = [-1] * self.__n for root in range(self.__n): if order[root] == -1: stack = [root, root] while stack: v = stack.pop() if order[v] == -1: visited.append(v) low[v] = order[v] = now_ord now_ord += 1 for i in range(g.start[v], g.start[v+1]): t = g.elist[i] if order[t] == -1: stack += [t, t] parent[t] = v else: low[v] = min(low[v], order[t]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.__n ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.__scc_ids() counts = [0] * group_num for x in ids: counts[x] += 1 groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups N, M = list(map(int, input().split())) sg = SccGraph(N) for _ in range(M): a, b = list(map(int, input().split())) sg.add_edge(a, b) scc = sg.scc() print((len(scc))) for group in scc: print((*([len(group)] + group)))
class CSR: def __init__(self, n: int, edges: list): self.start = [0] * (n+1) self.elist = [0] * len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1, n+1): self.start[i] += self.start[i-1] counter = self.start[::] # copy for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class SccGraph: def __init__(self, n: int = 0): self.__n = n self.__edges = [] def __len__(self): return self.__n def add_edge(self, s: int, t: int): assert 0 <= s < self.__n and 0 <= t < self.__n self.__edges.append([s, t]) def __scc_ids(self): g = CSR(self.__n, self.__edges) now_ord = group_num = 0 visited = [] low = [0] * self.__n order = [-1] * self.__n ids = [0] * self.__n parent = [-1] * self.__n for root in range(self.__n): if order[root] == -1: stack = [root, root] while stack: v = stack.pop() if order[v] == -1: visited.append(v) low[v] = order[v] = now_ord now_ord += 1 for i in range(g.start[v], g.start[v+1]): t = g.elist[i] if order[t] == -1: stack += [t, t] parent[t] = v else: low[v] = min(low[v], order[t]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.__n ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.__scc_ids() counts = [0] * group_num for x in ids: counts[x] += 1 groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, M = list(map(int,readline().split())) data = list(map(int,read().split())) sg = SccGraph(N) it = iter(data) for a, b in zip(it, it): sg.add_edge(a,b) scc = sg.scc() print((len(scc))) for group in scc: print((*([len(group)] + group)))
96
102
2,975
3,121
class CSR: def __init__(self, n: int, edges: list): self.start = [0] * (n + 1) self.elist = [0] * len(edges) for e in edges: self.start[e[0] + 1] += 1 for i in range(1, n + 1): self.start[i] += self.start[i - 1] counter = self.start[::] # copy for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class SccGraph: def __init__(self, n: int = 0): self.__n = n self.__edges = [] def __len__(self): return self.__n def add_edge(self, s: int, t: int): assert 0 <= s < self.__n and 0 <= t < self.__n self.__edges.append([s, t]) def __scc_ids(self): g = CSR(self.__n, self.__edges) now_ord = group_num = 0 visited = [] low = [0] * self.__n order = [-1] * self.__n ids = [0] * self.__n parent = [-1] * self.__n for root in range(self.__n): if order[root] == -1: stack = [root, root] while stack: v = stack.pop() if order[v] == -1: visited.append(v) low[v] = order[v] = now_ord now_ord += 1 for i in range(g.start[v], g.start[v + 1]): t = g.elist[i] if order[t] == -1: stack += [t, t] parent[t] = v else: low[v] = min(low[v], order[t]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.__n ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.__scc_ids() counts = [0] * group_num for x in ids: counts[x] += 1 groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups N, M = list(map(int, input().split())) sg = SccGraph(N) for _ in range(M): a, b = list(map(int, input().split())) sg.add_edge(a, b) scc = sg.scc() print((len(scc))) for group in scc: print((*([len(group)] + group)))
class CSR: def __init__(self, n: int, edges: list): self.start = [0] * (n + 1) self.elist = [0] * len(edges) for e in edges: self.start[e[0] + 1] += 1 for i in range(1, n + 1): self.start[i] += self.start[i - 1] counter = self.start[::] # copy for e in edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 class SccGraph: def __init__(self, n: int = 0): self.__n = n self.__edges = [] def __len__(self): return self.__n def add_edge(self, s: int, t: int): assert 0 <= s < self.__n and 0 <= t < self.__n self.__edges.append([s, t]) def __scc_ids(self): g = CSR(self.__n, self.__edges) now_ord = group_num = 0 visited = [] low = [0] * self.__n order = [-1] * self.__n ids = [0] * self.__n parent = [-1] * self.__n for root in range(self.__n): if order[root] == -1: stack = [root, root] while stack: v = stack.pop() if order[v] == -1: visited.append(v) low[v] = order[v] = now_ord now_ord += 1 for i in range(g.start[v], g.start[v + 1]): t = g.elist[i] if order[t] == -1: stack += [t, t] parent[t] = v else: low[v] = min(low[v], order[t]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = self.__n ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids def scc(self): group_num, ids = self.__scc_ids() counts = [0] * group_num for x in ids: counts[x] += 1 groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, M = list(map(int, readline().split())) data = list(map(int, read().split())) sg = SccGraph(N) it = iter(data) for a, b in zip(it, it): sg.add_edge(a, b) scc = sg.scc() print((len(scc))) for group in scc: print((*([len(group)] + group)))
false
5.882353
[ "-N, M = list(map(int, input().split()))", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, M = list(map(int, readline().split()))", "+data = list(map(int, read().split()))", "-for _ in range(M):", "- a, b = list(map(int, input().split()))", "+it = iter(data)", "+for a, b in zip(it, it):" ]
false
0.050228
0.037274
1.347525
[ "s460846341", "s822154396" ]
u363407238
p03042
python
s804351765
s630310232
21
17
3,060
3,064
Accepted
Accepted
19.05
import sys input = sys.stdin.readline s = eval(input()) s1 = int(s[:2]) s2 = int(s[2:]) isS1MM = 1 <= s1 <= 12 isS2MM = 1 <= s2 <= 12 if isS1MM and isS2MM: print("AMBIGUOUS") elif not isS1MM and isS2MM: print("YYMM") elif isS1MM and not isS2MM: print("MMYY") else: print('NA')
import sys input = sys.stdin.readline s = eval(input()) s1 = int(s[:2]) s2 = int(s[2:]) isS1YYMM = 1 <= s1 <= 12 isS2MMYY = 1 <= s2 <= 12 if isS1YYMM: if isS2MMYY: print("AMBIGUOUS") else: print("MMYY") else: if isS2MMYY: print("YYMM") else: print('NA')
15
17
300
311
import sys input = sys.stdin.readline s = eval(input()) s1 = int(s[:2]) s2 = int(s[2:]) isS1MM = 1 <= s1 <= 12 isS2MM = 1 <= s2 <= 12 if isS1MM and isS2MM: print("AMBIGUOUS") elif not isS1MM and isS2MM: print("YYMM") elif isS1MM and not isS2MM: print("MMYY") else: print("NA")
import sys input = sys.stdin.readline s = eval(input()) s1 = int(s[:2]) s2 = int(s[2:]) isS1YYMM = 1 <= s1 <= 12 isS2MMYY = 1 <= s2 <= 12 if isS1YYMM: if isS2MMYY: print("AMBIGUOUS") else: print("MMYY") else: if isS2MMYY: print("YYMM") else: print("NA")
false
11.764706
[ "-isS1MM = 1 <= s1 <= 12", "-isS2MM = 1 <= s2 <= 12", "-if isS1MM and isS2MM:", "- print(\"AMBIGUOUS\")", "-elif not isS1MM and isS2MM:", "- print(\"YYMM\")", "-elif isS1MM and not isS2MM:", "- print(\"MMYY\")", "+isS1YYMM = 1 <= s1 <= 12", "+isS2MMYY = 1 <= s2 <= 12", "+if isS1YYMM:", "+ if isS2MMYY:", "+ print(\"AMBIGUOUS\")", "+ else:", "+ print(\"MMYY\")", "- print(\"NA\")", "+ if isS2MMYY:", "+ print(\"YYMM\")", "+ else:", "+ print(\"NA\")" ]
false
0.044313
0.063116
0.702085
[ "s804351765", "s630310232" ]
u813098295
p03776
python
s098556324
s628180170
16
11
2,820
2,692
Accepted
Accepted
31.25
from math import factorial def comb(n, k): f = factorial return f(n) / f(k) / f(n-k) N, A, B = list(map(int, input().split())) v = list(map(int, input().split())) v.sort(reverse = True) print(float(sum(v[0:A]))/A) X, Y = 0, 0 ans = 0 for i in range(N): if (v[i] == v[A-1]): X += 1 if (v[i] == v[A-1]) and (i < A): Y += 1 if (v[0] != v[A-1]): ans = comb(X, Y) else: for i in range(A, B+1): if(i <= X): ans += comb(X, i) print(ans)
from math import factorial def comb(n, k): f = factorial return f(n) / f(k) / f(n-k) N, A, B = list(map(int, input().split())) v = list(map(int, input().split())) v.sort(reverse = True) t = v[A-1] ans = 0 X, Y = v.count(t), v[:A].count(t) if (v[0] != v[A-1]): ans = comb(X, Y) else: for i in range(A, B+1): if(i <= X): ans += comb(X, i) print(float(sum(v[0:A]))/A) print(ans)
31
26
522
438
from math import factorial def comb(n, k): f = factorial return f(n) / f(k) / f(n - k) N, A, B = list(map(int, input().split())) v = list(map(int, input().split())) v.sort(reverse=True) print(float(sum(v[0:A])) / A) X, Y = 0, 0 ans = 0 for i in range(N): if v[i] == v[A - 1]: X += 1 if (v[i] == v[A - 1]) and (i < A): Y += 1 if v[0] != v[A - 1]: ans = comb(X, Y) else: for i in range(A, B + 1): if i <= X: ans += comb(X, i) print(ans)
from math import factorial def comb(n, k): f = factorial return f(n) / f(k) / f(n - k) N, A, B = list(map(int, input().split())) v = list(map(int, input().split())) v.sort(reverse=True) t = v[A - 1] ans = 0 X, Y = v.count(t), v[:A].count(t) if v[0] != v[A - 1]: ans = comb(X, Y) else: for i in range(A, B + 1): if i <= X: ans += comb(X, i) print(float(sum(v[0:A])) / A) print(ans)
false
16.129032
[ "-print(float(sum(v[0:A])) / A)", "-X, Y = 0, 0", "+t = v[A - 1]", "-for i in range(N):", "- if v[i] == v[A - 1]:", "- X += 1", "- if (v[i] == v[A - 1]) and (i < A):", "- Y += 1", "+X, Y = v.count(t), v[:A].count(t)", "+print(float(sum(v[0:A])) / A)" ]
false
0.040915
0.036499
1.12099
[ "s098556324", "s628180170" ]
u562935282
p03946
python
s789116982
s469896534
71
56
14,380
15,020
Accepted
Accepted
21.13
def main(): from heapq import heappush inf = 1 << 30 N, T = list(map(int, input().split())) *A, = list(map(int, input().split())) h = [inf] ma = -1 cnt = 0 for x in A: d = x - h[0] if ma < d: ma = d cnt = 1 elif ma == d: cnt += 1 heappush(h, x) print(cnt) if __name__ == '__main__': main()
def main(): N, T = list(map(int, input().split())) *A, = list(map(int, input().split())) mi = A[0] d_ma = -1 cnt = 0 for x in A: d = x - mi if d_ma < d: d_ma = d cnt = 1 elif d_ma == d: cnt += 1 if mi > x: mi = x print(cnt) if __name__ == '__main__': main()
25
22
416
383
def main(): from heapq import heappush inf = 1 << 30 N, T = list(map(int, input().split())) (*A,) = list(map(int, input().split())) h = [inf] ma = -1 cnt = 0 for x in A: d = x - h[0] if ma < d: ma = d cnt = 1 elif ma == d: cnt += 1 heappush(h, x) print(cnt) if __name__ == "__main__": main()
def main(): N, T = list(map(int, input().split())) (*A,) = list(map(int, input().split())) mi = A[0] d_ma = -1 cnt = 0 for x in A: d = x - mi if d_ma < d: d_ma = d cnt = 1 elif d_ma == d: cnt += 1 if mi > x: mi = x print(cnt) if __name__ == "__main__": main()
false
12
[ "- from heapq import heappush", "-", "- inf = 1 << 30", "- h = [inf]", "- ma = -1", "+ mi = A[0]", "+ d_ma = -1", "- d = x - h[0]", "- if ma < d:", "- ma = d", "+ d = x - mi", "+ if d_ma < d:", "+ d_ma = d", "- elif ma == d:", "+ elif d_ma == d:", "- heappush(h, x)", "+ if mi > x:", "+ mi = x" ]
false
0.04366
0.110484
0.395171
[ "s789116982", "s469896534" ]
u654470292
p03379
python
s689015110
s940733261
595
203
101,716
33,108
Accepted
Accepted
65.88
import bisect n=int(eval(input())) x=list(map(int,input().split())) y=[] for i in range(n): y.append(x[i]) x.sort() for i in range(n): if bisect.bisect_left(x,y[i])+1 <= len(x)/2: print((x[int(len(x)/2)])) else: print((x[int(len(x)/2)-1]))
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) sys.setrecursionlimit(500000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(eval(input())) x=list(map(int,input().split())) tmp=sorted(x) if n%2==0: heikin=(tmp[n//2]+tmp[n//2-1])/2 for i in range(n): if heikin<x[i]: print((tmp[n//2-1])) else: print((tmp[n//2]))
14
29
272
683
import bisect n = int(eval(input())) x = list(map(int, input().split())) y = [] for i in range(n): y.append(x[i]) x.sort() for i in range(n): if bisect.bisect_left(x, y[i]) + 1 <= len(x) / 2: print((x[int(len(x) / 2)])) else: print((x[int(len(x) / 2) - 1]))
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) sys.setrecursionlimit(500000) mod = pow(10, 9) + 7 al = [chr(ord("a") + i) for i in range(26)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] n = int(eval(input())) x = list(map(int, input().split())) tmp = sorted(x) if n % 2 == 0: heikin = (tmp[n // 2] + tmp[n // 2 - 1]) / 2 for i in range(n): if heikin < x[i]: print((tmp[n // 2 - 1])) else: print((tmp[n // 2]))
false
51.724138
[ "+import copy", "+import heapq", "+import math", "+import sys", "+from collections import *", "+from functools import lru_cache", "+from itertools import accumulate, combinations, permutations, product", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def ruiseki(lst):", "+ return [0] + list(accumulate(lst))", "+", "+", "+sys.setrecursionlimit(500000)", "+mod = pow(10, 9) + 7", "+al = [chr(ord(\"a\") + i) for i in range(26)]", "+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-y = []", "-for i in range(n):", "- y.append(x[i])", "-x.sort()", "-for i in range(n):", "- if bisect.bisect_left(x, y[i]) + 1 <= len(x) / 2:", "- print((x[int(len(x) / 2)]))", "- else:", "- print((x[int(len(x) / 2) - 1]))", "+tmp = sorted(x)", "+if n % 2 == 0:", "+ heikin = (tmp[n // 2] + tmp[n // 2 - 1]) / 2", "+ for i in range(n):", "+ if heikin < x[i]:", "+ print((tmp[n // 2 - 1]))", "+ else:", "+ print((tmp[n // 2]))" ]
false
0.051143
0.037129
1.377447
[ "s689015110", "s940733261" ]
u816631826
p03160
python
s980593438
s687708164
155
131
13,924
13,924
Accepted
Accepted
15.48
n = int(eval(input())) h = [int(x) for x in input().split()] def abs(x): if x >= 0: return x return -x c = [0] c.append(abs(h[1] - h[0])) for k in range(2, n): cnext = min(c[k-2] + abs(h[k]-h[k-2]), c[k-1] + abs(h[k] - h[k-1])) c.append(cnext) print((c[-1]))
n = int(eval(input())) h = input().split() h = [int(i) for i in h] aux = [10000000000 for i in range(n)] aux[0] = 0 aux[1] = abs(h[1] - h[0]) for i in range(2,n): aux[i] = min(aux[i - 2] + abs(h[i] - h[i - 2]), aux[i - 1] + abs(h[i] - h[i - 1])) print((aux[n-1]))
15
13
291
280
n = int(eval(input())) h = [int(x) for x in input().split()] def abs(x): if x >= 0: return x return -x c = [0] c.append(abs(h[1] - h[0])) for k in range(2, n): cnext = min(c[k - 2] + abs(h[k] - h[k - 2]), c[k - 1] + abs(h[k] - h[k - 1])) c.append(cnext) print((c[-1]))
n = int(eval(input())) h = input().split() h = [int(i) for i in h] aux = [10000000000 for i in range(n)] aux[0] = 0 aux[1] = abs(h[1] - h[0]) for i in range(2, n): aux[i] = min(aux[i - 2] + abs(h[i] - h[i - 2]), aux[i - 1] + abs(h[i] - h[i - 1])) print((aux[n - 1]))
false
13.333333
[ "-h = [int(x) for x in input().split()]", "-", "-", "-def abs(x):", "- if x >= 0:", "- return x", "- return -x", "-", "-", "-c = [0]", "-c.append(abs(h[1] - h[0]))", "-for k in range(2, n):", "- cnext = min(c[k - 2] + abs(h[k] - h[k - 2]), c[k - 1] + abs(h[k] - h[k - 1]))", "- c.append(cnext)", "-print((c[-1]))", "+h = input().split()", "+h = [int(i) for i in h]", "+aux = [10000000000 for i in range(n)]", "+aux[0] = 0", "+aux[1] = abs(h[1] - h[0])", "+for i in range(2, n):", "+ aux[i] = min(aux[i - 2] + abs(h[i] - h[i - 2]), aux[i - 1] + abs(h[i] - h[i - 1]))", "+print((aux[n - 1]))" ]
false
0.069717
0.039147
1.780904
[ "s980593438", "s687708164" ]
u836737505
p02947
python
s656908970
s489732174
383
342
19,764
19,764
Accepted
Accepted
10.7
from collections import Counter n = int(eval(input())) b = [] for i in range(n): a = "".join(sorted(eval(input()))) b.append(a) c = list(Counter(b).values()) ans = 0 for j in c: ans += int((j-1)*j/2) print(ans)
from collections import Counter n = int(eval(input())) s = list(Counter([''.join(sorted(eval(input()))) for _ in range(n)]).values()) print((sum([i*(i-1)//2 for i in s if i != 1])))
11
4
220
164
from collections import Counter n = int(eval(input())) b = [] for i in range(n): a = "".join(sorted(eval(input()))) b.append(a) c = list(Counter(b).values()) ans = 0 for j in c: ans += int((j - 1) * j / 2) print(ans)
from collections import Counter n = int(eval(input())) s = list(Counter(["".join(sorted(eval(input()))) for _ in range(n)]).values()) print((sum([i * (i - 1) // 2 for i in s if i != 1])))
false
63.636364
[ "-b = []", "-for i in range(n):", "- a = \"\".join(sorted(eval(input())))", "- b.append(a)", "-c = list(Counter(b).values())", "-ans = 0", "-for j in c:", "- ans += int((j - 1) * j / 2)", "-print(ans)", "+s = list(Counter([\"\".join(sorted(eval(input()))) for _ in range(n)]).values())", "+print((sum([i * (i - 1) // 2 for i in s if i != 1])))" ]
false
0.046805
0.04667
1.0029
[ "s656908970", "s489732174" ]
u876438858
p03290
python
s694321853
s926850692
26
21
3,064
3,064
Accepted
Accepted
19.23
import sys import math input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(MI()) inf = float("inf") def main(): d, g = MI() pc = [LI() for _ in range(d)] ans = inf for bit in range(2 << d): c = 0 score = 0 for i in range(d): if bit & (1 << i): c += pc[i][0] score += pc[i][0] * 100 * (i + 1) + pc[i][1] if score >= g: ans = min(ans, c) else: for i in reversed(list(range(d))): if bit & (1 << i): continue res = math.ceil((g - score) / (100 * (i + 1))) if res < pc[i][0]: ans = min(ans, c + res) break print(ans) if __name__ == "__main__": main()
import sys import math input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(MI()) inf = float("inf") def main(): d, g = MI() pc = [LI() for _ in range(d)] ans = inf for bit in range(1 << d): c = 0 score = 0 for i in range(d): if bit & (1 << i): c += pc[i][0] score += pc[i][0] * 100 * (i + 1) + pc[i][1] if score >= g: ans = min(ans, c) else: for i in reversed(list(range(d))): if bit & (1 << i): continue res = math.ceil((g - score) / (100 * (i + 1))) if res < pc[i][0]: ans = min(ans, c + res) break print(ans) if __name__ == "__main__": main()
50
50
922
922
import sys import math input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(MI()) inf = float("inf") def main(): d, g = MI() pc = [LI() for _ in range(d)] ans = inf for bit in range(2 << d): c = 0 score = 0 for i in range(d): if bit & (1 << i): c += pc[i][0] score += pc[i][0] * 100 * (i + 1) + pc[i][1] if score >= g: ans = min(ans, c) else: for i in reversed(list(range(d))): if bit & (1 << i): continue res = math.ceil((g - score) / (100 * (i + 1))) if res < pc[i][0]: ans = min(ans, c + res) break print(ans) if __name__ == "__main__": main()
import sys import math input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(MI()) inf = float("inf") def main(): d, g = MI() pc = [LI() for _ in range(d)] ans = inf for bit in range(1 << d): c = 0 score = 0 for i in range(d): if bit & (1 << i): c += pc[i][0] score += pc[i][0] * 100 * (i + 1) + pc[i][1] if score >= g: ans = min(ans, c) else: for i in reversed(list(range(d))): if bit & (1 << i): continue res = math.ceil((g - score) / (100 * (i + 1))) if res < pc[i][0]: ans = min(ans, c + res) break print(ans) if __name__ == "__main__": main()
false
0
[ "- for bit in range(2 << d):", "+ for bit in range(1 << d):" ]
false
0.043621
0.043777
0.996443
[ "s694321853", "s926850692" ]
u116002573
p02773
python
s276290919
s239166557
1,181
493
97,624
144,632
Accepted
Accepted
58.26
def main(): N = int(eval(input())) d = dict() for _ in range(N): s = eval(input()) d[s] = d.get(s, 0) + 1 max_c = 0 for s in d: max_c = max(max_c, d[s]) ans = [] for s in d: if d[s] == max_c: ans.append(s) ans.sort() for s in ans: print(s) if __name__ == '__main__': main()
def main(): N = int(eval(input())) d = dict() cnt = 0 for _ in range(N): s = eval(input()) d[s] = d.get(s, 0) + 1 cnt = max(cnt, d[s]) ans = [] for s in d: if d[s] == cnt: ans.append(s) ans = sorted(ans) for s in ans: print(s) # return " ".join(map(str, sorted(ans))) if __name__ == '__main__': main() # print(main())
21
21
377
413
def main(): N = int(eval(input())) d = dict() for _ in range(N): s = eval(input()) d[s] = d.get(s, 0) + 1 max_c = 0 for s in d: max_c = max(max_c, d[s]) ans = [] for s in d: if d[s] == max_c: ans.append(s) ans.sort() for s in ans: print(s) if __name__ == "__main__": main()
def main(): N = int(eval(input())) d = dict() cnt = 0 for _ in range(N): s = eval(input()) d[s] = d.get(s, 0) + 1 cnt = max(cnt, d[s]) ans = [] for s in d: if d[s] == cnt: ans.append(s) ans = sorted(ans) for s in ans: print(s) # return " ".join(map(str, sorted(ans))) if __name__ == "__main__": main() # print(main())
false
0
[ "+ cnt = 0", "- max_c = 0", "- for s in d:", "- max_c = max(max_c, d[s])", "+ cnt = max(cnt, d[s])", "- if d[s] == max_c:", "+ if d[s] == cnt:", "- ans.sort()", "+ ans = sorted(ans)", "+ # return \" \".join(map(str, sorted(ans)))", "+ # print(main())" ]
false
0.045297
0.035804
1.265136
[ "s276290919", "s239166557" ]
u057109575
p02983
python
s308240710
s460574436
225
69
40,812
65,440
Accepted
Accepted
69.33
L, R = list(map(int, input().split())) MOD = 2019 ub = max(R % MOD, L % MOD) lb = min(R % MOD, L % MOD) if ub == lb or R // MOD != L // MOD: print((0)) exit() ans = float('inf') for i in range(lb, ub + 1): for j in range(i + 1, ub + 1): ans = min(ans, i * j % MOD) print(ans)
L, R = list(map(int, open(0).read().split())) ans = 2020 m = min(L + 2020, R) + 1 for i in range(L, m): for j in range(i + 1, m): ans = min(ans, i * j % 2019) print(ans)
15
9
304
183
L, R = list(map(int, input().split())) MOD = 2019 ub = max(R % MOD, L % MOD) lb = min(R % MOD, L % MOD) if ub == lb or R // MOD != L // MOD: print((0)) exit() ans = float("inf") for i in range(lb, ub + 1): for j in range(i + 1, ub + 1): ans = min(ans, i * j % MOD) print(ans)
L, R = list(map(int, open(0).read().split())) ans = 2020 m = min(L + 2020, R) + 1 for i in range(L, m): for j in range(i + 1, m): ans = min(ans, i * j % 2019) print(ans)
false
40
[ "-L, R = list(map(int, input().split()))", "-MOD = 2019", "-ub = max(R % MOD, L % MOD)", "-lb = min(R % MOD, L % MOD)", "-if ub == lb or R // MOD != L // MOD:", "- print((0))", "- exit()", "-ans = float(\"inf\")", "-for i in range(lb, ub + 1):", "- for j in range(i + 1, ub + 1):", "- ans = min(ans, i * j % MOD)", "+L, R = list(map(int, open(0).read().split()))", "+ans = 2020", "+m = min(L + 2020, R) + 1", "+for i in range(L, m):", "+ for j in range(i + 1, m):", "+ ans = min(ans, i * j % 2019)" ]
false
0.068661
0.086407
0.794616
[ "s308240710", "s460574436" ]
u614314290
p03111
python
s121485123
s730261007
210
76
3,064
3,064
Accepted
Accepted
63.81
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] min_cost = 10 ** 18 def func(n, select): global min_cost if n == 0: if len(set(select) - {0}) < 3: return #print(select) cost = 0 a, b, c = 0, 0, 0 for i, t in enumerate(select): if t == 1: if a != 0: cost += 10 a += L[i] if t == 2: if b != 0: cost += 10 b += L[i] if t == 3: if c != 0: cost += 10 c += L[i] cost += abs(A - a) cost += abs(B - b) cost += abs(C - c) min_cost = min(min_cost, cost) return for i in range(4): func(n - 1, select + [i]) func(N, []) print(min_cost)
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] INF = 10 ** 12 def solve(n, cost, a, b, c): if n == N: if 0 == min(a, b, c): return INF return abs(a - A) + abs(b - B) + abs(c - C) + cost - 30 ret1 = solve(n + 1, cost, a, b, c) ret2 = solve(n + 1, cost + 10, a + L[n], b, c) ret3 = solve(n + 1, cost + 10, a, b + L[n], c) ret4 = solve(n + 1, cost + 10, a, b, c + L[n]) return min(ret1, ret2, ret3, ret4) print((solve(0, 0, 0, 0, 0)))
36
17
666
491
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] min_cost = 10**18 def func(n, select): global min_cost if n == 0: if len(set(select) - {0}) < 3: return # print(select) cost = 0 a, b, c = 0, 0, 0 for i, t in enumerate(select): if t == 1: if a != 0: cost += 10 a += L[i] if t == 2: if b != 0: cost += 10 b += L[i] if t == 3: if c != 0: cost += 10 c += L[i] cost += abs(A - a) cost += abs(B - b) cost += abs(C - c) min_cost = min(min_cost, cost) return for i in range(4): func(n - 1, select + [i]) func(N, []) print(min_cost)
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] INF = 10**12 def solve(n, cost, a, b, c): if n == N: if 0 == min(a, b, c): return INF return abs(a - A) + abs(b - B) + abs(c - C) + cost - 30 ret1 = solve(n + 1, cost, a, b, c) ret2 = solve(n + 1, cost + 10, a + L[n], b, c) ret3 = solve(n + 1, cost + 10, a, b + L[n], c) ret4 = solve(n + 1, cost + 10, a, b, c + L[n]) return min(ret1, ret2, ret3, ret4) print((solve(0, 0, 0, 0, 0)))
false
52.777778
[ "-min_cost = 10**18", "+INF = 10**12", "-def func(n, select):", "- global min_cost", "- if n == 0:", "- if len(set(select) - {0}) < 3:", "- return", "- # print(select)", "- cost = 0", "- a, b, c = 0, 0, 0", "- for i, t in enumerate(select):", "- if t == 1:", "- if a != 0:", "- cost += 10", "- a += L[i]", "- if t == 2:", "- if b != 0:", "- cost += 10", "- b += L[i]", "- if t == 3:", "- if c != 0:", "- cost += 10", "- c += L[i]", "- cost += abs(A - a)", "- cost += abs(B - b)", "- cost += abs(C - c)", "- min_cost = min(min_cost, cost)", "- return", "- for i in range(4):", "- func(n - 1, select + [i])", "+def solve(n, cost, a, b, c):", "+ if n == N:", "+ if 0 == min(a, b, c):", "+ return INF", "+ return abs(a - A) + abs(b - B) + abs(c - C) + cost - 30", "+ ret1 = solve(n + 1, cost, a, b, c)", "+ ret2 = solve(n + 1, cost + 10, a + L[n], b, c)", "+ ret3 = solve(n + 1, cost + 10, a, b + L[n], c)", "+ ret4 = solve(n + 1, cost + 10, a, b, c + L[n])", "+ return min(ret1, ret2, ret3, ret4)", "-func(N, [])", "-print(min_cost)", "+print((solve(0, 0, 0, 0, 0)))" ]
false
0.141085
0.14775
0.954889
[ "s121485123", "s730261007" ]
u562935282
p02770
python
s328466373
s375223270
1,890
1,535
121,180
114,396
Accepted
Accepted
18.78
# 解説放送 # tee, isliceをやめた def main(): k, q = list(map(int, input().split())) *d, = list(map(int, input().split())) for _ in range(q): n, x, m = list(map(int, input().split())) *g, = [x % m for x in d] rep, rest = divmod(n - 1, k) last = x + (sum(g) * rep) + sum(g[:rest]) eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0) ans = (n - 1) - eq - (last // m - x // m) print(ans) if __name__ == '__main__': main()
# 解説放送 def solve(): from itertools import islice, tee k, q = map(int, input().split()) *d, = map(int, input().split()) for g in tee(d, q): n, x, m = map(int, input().split()) g = map(lambda x: x % m, g) g1, g2, g3 = tee(g, 3) rep, rest = divmod(n - 1, k) last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest)) eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0) ans = (n - 1) - eq - (last // m - x // m) yield ans def main(): print(*solve(), sep='\n') if __name__ == '__main__': main()
18
24
513
627
# 解説放送 # tee, isliceをやめた def main(): k, q = list(map(int, input().split())) (*d,) = list(map(int, input().split())) for _ in range(q): n, x, m = list(map(int, input().split())) (*g,) = [x % m for x in d] rep, rest = divmod(n - 1, k) last = x + (sum(g) * rep) + sum(g[:rest]) eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0) ans = (n - 1) - eq - (last // m - x // m) print(ans) if __name__ == "__main__": main()
# 解説放送 def solve(): from itertools import islice, tee k, q = map(int, input().split()) (*d,) = map(int, input().split()) for g in tee(d, q): n, x, m = map(int, input().split()) g = map(lambda x: x % m, g) g1, g2, g3 = tee(g, 3) rep, rest = divmod(n - 1, k) last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest)) eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0) ans = (n - 1) - eq - (last // m - x // m) yield ans def main(): print(*solve(), sep="\n") if __name__ == "__main__": main()
false
25
[ "-# tee, isliceをやめた", "+def solve():", "+ from itertools import islice, tee", "+", "+ k, q = map(int, input().split())", "+ (*d,) = map(int, input().split())", "+ for g in tee(d, q):", "+ n, x, m = map(int, input().split())", "+ g = map(lambda x: x % m, g)", "+ g1, g2, g3 = tee(g, 3)", "+ rep, rest = divmod(n - 1, k)", "+ last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest))", "+ eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0)", "+ ans = (n - 1) - eq - (last // m - x // m)", "+ yield ans", "+", "+", "- k, q = list(map(int, input().split()))", "- (*d,) = list(map(int, input().split()))", "- for _ in range(q):", "- n, x, m = list(map(int, input().split()))", "- (*g,) = [x % m for x in d]", "- rep, rest = divmod(n - 1, k)", "- last = x + (sum(g) * rep) + sum(g[:rest])", "- eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0)", "- ans = (n - 1) - eq - (last // m - x // m)", "- print(ans)", "+ print(*solve(), sep=\"\\n\")" ]
false
0.036024
0.035387
1.018024
[ "s328466373", "s375223270" ]
u678167152
p02881
python
s598737004
s210716805
200
111
2,940
3,188
Accepted
Accepted
44.5
N = int(eval(input())) i = int(N**0.5) while N%i!=0: i -= 1 print((i+N//i-2))
def solve(): N = int(eval(input())) n = int(N**0.5)+1 for i in range(n,0,-1): if N%i==0: ans = i+N//i-2 break return ans print((solve()))
5
9
75
185
N = int(eval(input())) i = int(N**0.5) while N % i != 0: i -= 1 print((i + N // i - 2))
def solve(): N = int(eval(input())) n = int(N**0.5) + 1 for i in range(n, 0, -1): if N % i == 0: ans = i + N // i - 2 break return ans print((solve()))
false
44.444444
[ "-N = int(eval(input()))", "-i = int(N**0.5)", "-while N % i != 0:", "- i -= 1", "-print((i + N // i - 2))", "+def solve():", "+ N = int(eval(input()))", "+ n = int(N**0.5) + 1", "+ for i in range(n, 0, -1):", "+ if N % i == 0:", "+ ans = i + N // i - 2", "+ break", "+ return ans", "+", "+", "+print((solve()))" ]
false
0.038593
0.037725
1.022989
[ "s598737004", "s210716805" ]
u777283665
p03425
python
s846710982
s920410253
469
187
43,496
3,064
Accepted
Accepted
60.13
import itertools n = int(eval(input())) d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for _ in range(n): s = eval(input()) if s[0] in d: d[s[0]] += 1 l = list(d.keys()) comb = list(itertools.combinations(l, 3)) ans = 0 for i in comb: temp = 1 for j in i: temp *= d[j] ans += temp print(ans)
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)
23
26
342
432
import itertools n = int(eval(input())) d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for _ in range(n): s = eval(input()) if s[0] in d: d[s[0]] += 1 l = list(d.keys()) comb = list(itertools.combinations(l, 3)) ans = 0 for i in comb: temp = 1 for j in i: temp *= d[j] ans += temp print(ans)
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)
false
11.538462
[ "-import itertools", "+from itertools import combinations", "-d = {\"M\": 0, \"A\": 0, \"R\": 0, \"C\": 0, \"H\": 0}", "+d = [0] * 5", "- if s[0] in d:", "- d[s[0]] += 1", "-l = list(d.keys())", "-comb = list(itertools.combinations(l, 3))", "+ 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)", "-for i in comb:", "- temp = 1", "- for j in i:", "- temp *= d[j]", "- ans += temp", "+for c in comb:", "+ ans += c[0] * c[1] * c[2]" ]
false
0.07604
0.086883
0.875207
[ "s846710982", "s920410253" ]
u132687480
p03161
python
s862881540
s872338255
429
387
60,000
55,004
Accepted
Accepted
9.79
N, K = list(map(int, input().split())) *h, = list(map(int, input().split())) dp = [float("inf") for _ in range(N)] dp[0] = 0 for i in range(N - 1): for j in range(1, min(K + 1, N - i)): dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[N - 1]))
import sys input = sys.stdin.readline def Main(N, K, h): dp =[float('inf')]*N dp[0] = 0 for i in range(N): for j in range(1, min(N-i,K+1)): dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) return dp[N-1] def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) print((Main(N, K, h))) if __name__ == '__main__': main()
8
18
257
413
N, K = list(map(int, input().split())) (*h,) = list(map(int, input().split())) dp = [float("inf") for _ in range(N)] dp[0] = 0 for i in range(N - 1): for j in range(1, min(K + 1, N - i)): dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[N - 1]))
import sys input = sys.stdin.readline def Main(N, K, h): dp = [float("inf")] * N dp[0] = 0 for i in range(N): for j in range(1, min(N - i, K + 1)): dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j])) return dp[N - 1] def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) print((Main(N, K, h))) if __name__ == "__main__": main()
false
55.555556
[ "-N, K = list(map(int, input().split()))", "-(*h,) = list(map(int, input().split()))", "-dp = [float(\"inf\") for _ in range(N)]", "-dp[0] = 0", "-for i in range(N - 1):", "- for j in range(1, min(K + 1, N - i)):", "- dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))", "-print((dp[N - 1]))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def Main(N, K, h):", "+ dp = [float(\"inf\")] * N", "+ dp[0] = 0", "+ for i in range(N):", "+ for j in range(1, min(N - i, K + 1)):", "+ dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))", "+ return dp[N - 1]", "+", "+", "+def main():", "+ N, K = list(map(int, input().split()))", "+ h = list(map(int, input().split()))", "+ print((Main(N, K, h)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047674
0.068092
0.700135
[ "s862881540", "s872338255" ]
u139614630
p03013
python
s376011552
s356393358
61
52
6,976
11,884
Accepted
Accepted
14.75
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb = [1] * (n+1) for i in a: comb[i] = 0 for i in range(2, n+1): comb[i] *= (comb[i-1] + comb[i-2]) % P_NUM return comb[-1] if __name__ == '__main__': n, m = list(map(int, input().split())) if m: a = list(map(int, sys.stdin)) else: a = [] ans = solv(n, m, a) print(ans)
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 comb = 1 for i in range(2, n+1): if i in a: comb = 0 else: comb = (comb_m1 + comb_m2) % P_NUM comb_m1, comb_m2 = comb, comb_m1 return comb if __name__ == '__main__': n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
29
37
439
578
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb = [1] * (n + 1) for i in a: comb[i] = 0 for i in range(2, n + 1): comb[i] *= (comb[i - 1] + comb[i - 2]) % P_NUM return comb[-1] if __name__ == "__main__": n, m = list(map(int, input().split())) if m: a = list(map(int, sys.stdin)) else: a = [] ans = solv(n, m, a) print(ans)
#!/usr/bin/env python3 import sys P_NUM = 1000000007 def solv(n, m, a): comb_m2 = 1 if 1 in a: comb_m1 = 0 else: comb_m1 = 1 comb = 1 for i in range(2, n + 1): if i in a: comb = 0 else: comb = (comb_m1 + comb_m2) % P_NUM comb_m1, comb_m2 = comb, comb_m1 return comb if __name__ == "__main__": n, m = list(map(int, input().split())) if m: a = set(map(int, sys.stdin)) else: a = set() ans = solv(n, m, a) print(ans)
false
21.621622
[ "- comb = [1] * (n + 1)", "- for i in a:", "- comb[i] = 0", "+ comb_m2 = 1", "+ if 1 in a:", "+ comb_m1 = 0", "+ else:", "+ comb_m1 = 1", "+ comb = 1", "- comb[i] *= (comb[i - 1] + comb[i - 2]) % P_NUM", "- return comb[-1]", "+ if i in a:", "+ comb = 0", "+ else:", "+ comb = (comb_m1 + comb_m2) % P_NUM", "+ comb_m1, comb_m2 = comb, comb_m1", "+ return comb", "- a = list(map(int, sys.stdin))", "+ a = set(map(int, sys.stdin))", "- a = []", "+ a = set()" ]
false
0.035957
0.046413
0.774716
[ "s376011552", "s356393358" ]
u796942881
p03309
python
s092161809
s089685884
190
166
25,180
25,180
Accepted
Accepted
12.63
def main(): N, *A = list(map(int, open(0).read().split())) for i in range(N): A[i] -= i + 1 A.sort() b = A[N // 2] print((sum([abs(A[i] - b) for i in range(N)]))) return main()
def main(): N, *A = list(map(int, open(0).read().split())) for i in range(N): A[i] -= i + 1 A.sort() print((sum(A[N // 2 + N % 2:]) - sum(A[:N // 2]))) return main()
11
10
213
197
def main(): N, *A = list(map(int, open(0).read().split())) for i in range(N): A[i] -= i + 1 A.sort() b = A[N // 2] print((sum([abs(A[i] - b) for i in range(N)]))) return main()
def main(): N, *A = list(map(int, open(0).read().split())) for i in range(N): A[i] -= i + 1 A.sort() print((sum(A[N // 2 + N % 2 :]) - sum(A[: N // 2]))) return main()
false
9.090909
[ "- b = A[N // 2]", "- print((sum([abs(A[i] - b) for i in range(N)])))", "+ print((sum(A[N // 2 + N % 2 :]) - sum(A[: N // 2])))" ]
false
0.120931
0.036103
3.349579
[ "s092161809", "s089685884" ]
u583507988
p03633
python
s145228636
s623174464
35
29
9,540
9,152
Accepted
Accepted
17.14
import math from functools import reduce def lcm_base(x, y): return (x*y)//math.gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(umbers): return reduce(lcm_base, numbers, 1) n = int(eval(input())) t = [] for i in range(n): t_ = int(eval(input())) t.append(t_) print((lcm(*t)))
import math n=int(eval(input())) t=[int(eval(input())) for i in range(n)] res=t[0] for i in range(1,n): res=res*t[i]//math.gcd(res,t[i]) print(res)
19
7
326
143
import math from functools import reduce def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(umbers): return reduce(lcm_base, numbers, 1) n = int(eval(input())) t = [] for i in range(n): t_ = int(eval(input())) t.append(t_) print((lcm(*t)))
import math n = int(eval(input())) t = [int(eval(input())) for i in range(n)] res = t[0] for i in range(1, n): res = res * t[i] // math.gcd(res, t[i]) print(res)
false
63.157895
[ "-from functools import reduce", "-", "-", "-def lcm_base(x, y):", "- return (x * y) // math.gcd(x, y)", "-", "-", "-def lcm(*numbers):", "- return reduce(lcm_base, numbers, 1)", "-", "-", "-def lcm_list(umbers):", "- return reduce(lcm_base, numbers, 1)", "-", "-t = []", "-for i in range(n):", "- t_ = int(eval(input()))", "- t.append(t_)", "-print((lcm(*t)))", "+t = [int(eval(input())) for i in range(n)]", "+res = t[0]", "+for i in range(1, n):", "+ res = res * t[i] // math.gcd(res, t[i])", "+print(res)" ]
false
0.039175
0.036904
1.06154
[ "s145228636", "s623174464" ]
u790710233
p02892
python
s616250677
s272104853
322
228
3,828
43,100
Accepted
Accepted
29.19
from collections import deque import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) edges = [[]for _ in range(n)] for i in range(n): s = list(map(int, list(input().rstrip()))) for j in range(n): if s[j]: edges[i].append(j) def dfs(v): for v2 in edges[v]: if color[v2] != -1: if color[v] == color[v2]: global is_ok is_ok = 0 continue color[v2] = color[v] ^ 1 dfs(v2) color = [-1]*n color[0] = 0 is_ok = 1 dfs(0) def bfs(init_v): next_v = deque([init_v]) INF = 10**18 dist = [INF]*n dist[init_v] = 0 while next_v: v = next_v.popleft() for v2 in edges[v]: if dist[v2] <= dist[v]+1: continue dist[v2] = dist[v]+1 next_v.append(v2) return dist if is_ok: ans = 0 for i in range(n): dist = bfs(i) x = max(dist) if ans < x: ans = x print((ans+1)) else: print((-1))
from collections import deque import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) edges = [[]for _ in range(n)] for i in range(n): s = list(map(int, list(input().rstrip()))) for j in range(n): if s[j]: edges[i].append(j) def dfs(v, c=0): color[v] = c for v2 in edges[v]: if color[v2] != -1: if color[v] == color[v2]: global is_ok is_ok = 0 continue dfs(v2, color[v] ^ 1) color = [-1]*n is_ok = 1 dfs(0) def bfs(init_v): next_v = deque([init_v]) INF = 10**18 dist = [INF]*n dist[init_v] = 0 while next_v: v = next_v.popleft() for v2 in edges[v]: if dist[v2] <= dist[v]+1: continue dist[v2] = dist[v]+1 next_v.append(v2) return dist if is_ok: ans = 0 for i in range(n): dist = bfs(i) x = max(dist) if ans < x: ans = x print((ans+1)) else: print((-1))
55
53
1,112
1,087
from collections import deque import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) edges = [[] for _ in range(n)] for i in range(n): s = list(map(int, list(input().rstrip()))) for j in range(n): if s[j]: edges[i].append(j) def dfs(v): for v2 in edges[v]: if color[v2] != -1: if color[v] == color[v2]: global is_ok is_ok = 0 continue color[v2] = color[v] ^ 1 dfs(v2) color = [-1] * n color[0] = 0 is_ok = 1 dfs(0) def bfs(init_v): next_v = deque([init_v]) INF = 10**18 dist = [INF] * n dist[init_v] = 0 while next_v: v = next_v.popleft() for v2 in edges[v]: if dist[v2] <= dist[v] + 1: continue dist[v2] = dist[v] + 1 next_v.append(v2) return dist if is_ok: ans = 0 for i in range(n): dist = bfs(i) x = max(dist) if ans < x: ans = x print((ans + 1)) else: print((-1))
from collections import deque import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n = int(eval(input())) edges = [[] for _ in range(n)] for i in range(n): s = list(map(int, list(input().rstrip()))) for j in range(n): if s[j]: edges[i].append(j) def dfs(v, c=0): color[v] = c for v2 in edges[v]: if color[v2] != -1: if color[v] == color[v2]: global is_ok is_ok = 0 continue dfs(v2, color[v] ^ 1) color = [-1] * n is_ok = 1 dfs(0) def bfs(init_v): next_v = deque([init_v]) INF = 10**18 dist = [INF] * n dist[init_v] = 0 while next_v: v = next_v.popleft() for v2 in edges[v]: if dist[v2] <= dist[v] + 1: continue dist[v2] = dist[v] + 1 next_v.append(v2) return dist if is_ok: ans = 0 for i in range(n): dist = bfs(i) x = max(dist) if ans < x: ans = x print((ans + 1)) else: print((-1))
false
3.636364
[ "-def dfs(v):", "+def dfs(v, c=0):", "+ color[v] = c", "- color[v2] = color[v] ^ 1", "- dfs(v2)", "+ dfs(v2, color[v] ^ 1)", "-color[0] = 0" ]
false
0.041553
0.077271
0.537751
[ "s616250677", "s272104853" ]
u265506056
p02837
python
s973418436
s960498775
1,480
689
3,064
3,064
Accepted
Accepted
53.45
N=int(eval(input())) g=[[-1]*N for _ in range(N)] ans=0 for i in range(N): A=int(eval(input())) for _ in range(A): x,y=list(map(int,input().split())) g[i][x-1]=y for s in range(2**N): flag=1 for i in range(N): if (s>>i&1): for j in range(N): if g[i][j]!=-1 and (s>>j&1)!=g[i][j]: flag=0 if flag==1: t=0 x=s while x>0: t+=x%2 x//=2 ans=max(ans,t) print(ans)
N=int(eval(input())) g=[[-1]*N for _ in range(N)] ans=0 for i in range(N): A=int(eval(input())) for _ in range(A): x,y=list(map(int,input().split())) g[i][x-1]=y for s in range(2**N): flag=1 for i in range(N): if (s>>i&1): for j in range(N): if g[i][j]!=-1 and (s>>j&1)!=g[i][j]: flag=0 break if flag==0:break if flag==1: t=0 x=s while x>0: t+=x%2 x//=2 ans=max(ans,t) print(ans)
23
25
508
561
N = int(eval(input())) g = [[-1] * N for _ in range(N)] ans = 0 for i in range(N): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) g[i][x - 1] = y for s in range(2**N): flag = 1 for i in range(N): if s >> i & 1: for j in range(N): if g[i][j] != -1 and (s >> j & 1) != g[i][j]: flag = 0 if flag == 1: t = 0 x = s while x > 0: t += x % 2 x //= 2 ans = max(ans, t) print(ans)
N = int(eval(input())) g = [[-1] * N for _ in range(N)] ans = 0 for i in range(N): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) g[i][x - 1] = y for s in range(2**N): flag = 1 for i in range(N): if s >> i & 1: for j in range(N): if g[i][j] != -1 and (s >> j & 1) != g[i][j]: flag = 0 break if flag == 0: break if flag == 1: t = 0 x = s while x > 0: t += x % 2 x //= 2 ans = max(ans, t) print(ans)
false
8
[ "+ break", "+ if flag == 0:", "+ break" ]
false
0.035501
0.045748
0.776028
[ "s973418436", "s960498775" ]
u604839890
p02687
python
s579211096
s954451795
66
26
61,656
8,848
Accepted
Accepted
60.61
S = eval(input()) print(('ABC' if S == 'ARC' else 'ARC'))
s = eval(input()) print(('ABC' if s == 'ARC' else 'ARC'))
2
2
50
50
S = eval(input()) print(("ABC" if S == "ARC" else "ARC"))
s = eval(input()) print(("ABC" if s == "ARC" else "ARC"))
false
0
[ "-S = eval(input())", "-print((\"ABC\" if S == \"ARC\" else \"ARC\"))", "+s = eval(input())", "+print((\"ABC\" if s == \"ARC\" else \"ARC\"))" ]
false
0.03804
0.030433
1.249958
[ "s579211096", "s954451795" ]
u698176039
p02793
python
s811342921
s526307132
1,051
322
68,824
70,820
Accepted
Accepted
69.36
from fractions import gcd MOD = 10**9+7 N = int(eval(input())) A = list(map(int,input().split())) #%% def modinv(x,mod): return pow(x,mod-2,mod) B = [] for a in A: b = modinv(a,MOD) B.append(b) def lcm(a,b): return a//gcd(a,b)*b ans = 0 cur = 1 for a in A: cur = lcm(cur,a) for b in B: ans += cur*b ans %= MOD print(ans)
class PrimeNum: def __init__(self, N): self.N = N [self.is_prime, self.primes, self.min_factor] = self.Eratosthenes(N) def Eratosthenes(self, n): # 素数テーブル is_prime = [True] * (n+1) is_prime[0] = False is_prime[1] = False # nを割り切る最小の素数を記録 min_factor = [0] * (n+1) min_factor[1] = 1 primes = [] for i in range(2,n+1): if not is_prime[i]: continue primes.append(i) min_factor[i] = i for cur in range(i*2, n+1, i): is_prime[cur] = False if min_factor[cur] == 0: min_factor[cur] = i cur += i return [is_prime, primes, min_factor] def PrimeFactorization(self, K): # Kの素因数分解を返す number = [] exponent = [] while K>1: ex = 0 p = self.min_factor[K] while K%p==0: K //= p ex += 1 number.append(p) exponent.append(ex) return [number, exponent] N = int(eval(input())) A = list(map(int,input().split())) MOD = 10**9+7 # 素因数分解の形でLCMを求める Prime = PrimeNum(max(A)) lcm_e = [0]*(max(A)+1) for i in range(N): nums,exs = Prime.PrimeFactorization(A[i]) for n,e in zip(nums,exs): lcm_e[n] = max(lcm_e[n], e) LCM = 1 for i in range(len(lcm_e)): if lcm_e[i] != 0: LCM *= pow(i, lcm_e[i], MOD) LCM %= MOD ans = 0 for a in A: ans += LCM * pow(a, MOD-2, MOD) ans %= MOD print(ans)
30
70
378
1,662
from fractions import gcd MOD = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) #%% def modinv(x, mod): return pow(x, mod - 2, mod) B = [] for a in A: b = modinv(a, MOD) B.append(b) def lcm(a, b): return a // gcd(a, b) * b ans = 0 cur = 1 for a in A: cur = lcm(cur, a) for b in B: ans += cur * b ans %= MOD print(ans)
class PrimeNum: def __init__(self, N): self.N = N [self.is_prime, self.primes, self.min_factor] = self.Eratosthenes(N) def Eratosthenes(self, n): # 素数テーブル is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False # nを割り切る最小の素数を記録 min_factor = [0] * (n + 1) min_factor[1] = 1 primes = [] for i in range(2, n + 1): if not is_prime[i]: continue primes.append(i) min_factor[i] = i for cur in range(i * 2, n + 1, i): is_prime[cur] = False if min_factor[cur] == 0: min_factor[cur] = i cur += i return [is_prime, primes, min_factor] def PrimeFactorization(self, K): # Kの素因数分解を返す number = [] exponent = [] while K > 1: ex = 0 p = self.min_factor[K] while K % p == 0: K //= p ex += 1 number.append(p) exponent.append(ex) return [number, exponent] N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9 + 7 # 素因数分解の形でLCMを求める Prime = PrimeNum(max(A)) lcm_e = [0] * (max(A) + 1) for i in range(N): nums, exs = Prime.PrimeFactorization(A[i]) for n, e in zip(nums, exs): lcm_e[n] = max(lcm_e[n], e) LCM = 1 for i in range(len(lcm_e)): if lcm_e[i] != 0: LCM *= pow(i, lcm_e[i], MOD) LCM %= MOD ans = 0 for a in A: ans += LCM * pow(a, MOD - 2, MOD) ans %= MOD print(ans)
false
57.142857
[ "-from fractions import gcd", "+class PrimeNum:", "+ def __init__(self, N):", "+ self.N = N", "+ [self.is_prime, self.primes, self.min_factor] = self.Eratosthenes(N)", "-MOD = 10**9 + 7", "+ def Eratosthenes(self, n):", "+ # 素数テーブル", "+ is_prime = [True] * (n + 1)", "+ is_prime[0] = False", "+ is_prime[1] = False", "+ # nを割り切る最小の素数を記録", "+ min_factor = [0] * (n + 1)", "+ min_factor[1] = 1", "+ primes = []", "+ for i in range(2, n + 1):", "+ if not is_prime[i]:", "+ continue", "+ primes.append(i)", "+ min_factor[i] = i", "+ for cur in range(i * 2, n + 1, i):", "+ is_prime[cur] = False", "+ if min_factor[cur] == 0:", "+ min_factor[cur] = i", "+ cur += i", "+ return [is_prime, primes, min_factor]", "+", "+ def PrimeFactorization(self, K):", "+ # Kの素因数分解を返す", "+ number = []", "+ exponent = []", "+ while K > 1:", "+ ex = 0", "+ p = self.min_factor[K]", "+ while K % p == 0:", "+ K //= p", "+ ex += 1", "+ number.append(p)", "+ exponent.append(ex)", "+ return [number, exponent]", "+", "+", "-#%%", "-def modinv(x, mod):", "- return pow(x, mod - 2, mod)", "-", "-", "-B = []", "+MOD = 10**9 + 7", "+# 素因数分解の形でLCMを求める", "+Prime = PrimeNum(max(A))", "+lcm_e = [0] * (max(A) + 1)", "+for i in range(N):", "+ nums, exs = Prime.PrimeFactorization(A[i])", "+ for n, e in zip(nums, exs):", "+ lcm_e[n] = max(lcm_e[n], e)", "+LCM = 1", "+for i in range(len(lcm_e)):", "+ if lcm_e[i] != 0:", "+ LCM *= pow(i, lcm_e[i], MOD)", "+ LCM %= MOD", "+ans = 0", "- b = modinv(a, MOD)", "- B.append(b)", "-", "-", "-def lcm(a, b):", "- return a // gcd(a, b) * b", "-", "-", "-ans = 0", "-cur = 1", "-for a in A:", "- cur = lcm(cur, a)", "-for b in B:", "- ans += cur * b", "-ans %= MOD", "+ ans += LCM * pow(a, MOD - 2, MOD)", "+ ans %= MOD" ]
false
0.053571
0.229116
0.233817
[ "s811342921", "s526307132" ]
u647999897
p03964
python
s836877926
s404868169
90
78
72,676
67,760
Accepted
Accepted
13.33
from math import ceil def solve(): N = int(eval(input())) T = [] A = [] for _ in range(N): t, a = list(map(int,input().split())) T.append(t) A.append(a) now_t = T[0] now_a = A[0] for i in range(1,N): mul = f(now_t,now_a,T[i],A[i]) now_t = T[i] * mul now_a = A[i] * mul print((now_t + now_a)) def f(now_t, now_a, t, a): left = 0 right = 10 ** 18 while right - left > 1: mid = (right + left) // 2 if now_t > t * mid or now_a > a * mid: left = mid else: right = mid return right if __name__ == '__main__': solve()
def solve(): N = int(eval(input())) now_t, now_a = 1,1 for _ in range(N): t, a = list(map(int,input().split())) n = max(-(-now_t//t), -(-now_a//a)) now_t = t * n now_a = a * n print((now_t + now_a)) if __name__ == '__main__': solve()
34
14
695
295
from math import ceil def solve(): N = int(eval(input())) T = [] A = [] for _ in range(N): t, a = list(map(int, input().split())) T.append(t) A.append(a) now_t = T[0] now_a = A[0] for i in range(1, N): mul = f(now_t, now_a, T[i], A[i]) now_t = T[i] * mul now_a = A[i] * mul print((now_t + now_a)) def f(now_t, now_a, t, a): left = 0 right = 10**18 while right - left > 1: mid = (right + left) // 2 if now_t > t * mid or now_a > a * mid: left = mid else: right = mid return right if __name__ == "__main__": solve()
def solve(): N = int(eval(input())) now_t, now_a = 1, 1 for _ in range(N): t, a = list(map(int, input().split())) n = max(-(-now_t // t), -(-now_a // a)) now_t = t * n now_a = a * n print((now_t + now_a)) if __name__ == "__main__": solve()
false
58.823529
[ "-from math import ceil", "-", "-", "- T = []", "- A = []", "+ now_t, now_a = 1, 1", "- T.append(t)", "- A.append(a)", "- now_t = T[0]", "- now_a = A[0]", "- for i in range(1, N):", "- mul = f(now_t, now_a, T[i], A[i])", "- now_t = T[i] * mul", "- now_a = A[i] * mul", "+ n = max(-(-now_t // t), -(-now_a // a))", "+ now_t = t * n", "+ now_a = a * n", "-", "-", "-def f(now_t, now_a, t, a):", "- left = 0", "- right = 10**18", "- while right - left > 1:", "- mid = (right + left) // 2", "- if now_t > t * mid or now_a > a * mid:", "- left = mid", "- else:", "- right = mid", "- return right" ]
false
0.042821
0.04411
0.970774
[ "s836877926", "s404868169" ]
u736443076
p02693
python
s050227324
s665277145
24
22
9,200
9,152
Accepted
Accepted
8.33
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): K = int(rl()) A, B = list(map(int,rl().split())) for i in range(A, B + 1): if i % K == 0: print("OK") exit() print("NG") if __name__ == '__main__': solve()
def solve(): K = int(eval(input())) A, B = list(map(int,input().split())) k = B // K if k * K >= A: print("OK") else: print("NG") if __name__ == '__main__': solve()
18
12
303
210
import sys sys.setrecursionlimit(10**7) rl = sys.stdin.readline def solve(): K = int(rl()) A, B = list(map(int, rl().split())) for i in range(A, B + 1): if i % K == 0: print("OK") exit() print("NG") if __name__ == "__main__": solve()
def solve(): K = int(eval(input())) A, B = list(map(int, input().split())) k = B // K if k * K >= A: print("OK") else: print("NG") if __name__ == "__main__": solve()
false
33.333333
[ "-import sys", "-", "-sys.setrecursionlimit(10**7)", "-rl = sys.stdin.readline", "-", "-", "- K = int(rl())", "- A, B = list(map(int, rl().split()))", "- for i in range(A, B + 1):", "- if i % K == 0:", "- print(\"OK\")", "- exit()", "- print(\"NG\")", "+ K = int(eval(input()))", "+ A, B = list(map(int, input().split()))", "+ k = B // K", "+ if k * K >= A:", "+ print(\"OK\")", "+ else:", "+ print(\"NG\")" ]
false
0.032102
0.032272
0.994731
[ "s050227324", "s665277145" ]
u347600233
p02571
python
s270773283
s755002287
63
54
9,128
9,108
Accepted
Accepted
14.29
s = eval(input()) t = eval(input()) n = len(s) m = len(t) max_cnt = 0 for i in range(n - m + 1): cnt = 0 u = s[i:i + m] for j in range(m): if t[j] == u[j]: cnt += 1 max_cnt = max(max_cnt, cnt) print((m - max_cnt))
s, t = eval(input()), eval(input()) n, m = len(s), len(t) print((min(sum(t[j] != s[i + j] for j in range(m)) for i in range(n - m + 1))))
13
3
247
125
s = eval(input()) t = eval(input()) n = len(s) m = len(t) max_cnt = 0 for i in range(n - m + 1): cnt = 0 u = s[i : i + m] for j in range(m): if t[j] == u[j]: cnt += 1 max_cnt = max(max_cnt, cnt) print((m - max_cnt))
s, t = eval(input()), eval(input()) n, m = len(s), len(t) print((min(sum(t[j] != s[i + j] for j in range(m)) for i in range(n - m + 1))))
false
76.923077
[ "-s = eval(input())", "-t = eval(input())", "-n = len(s)", "-m = len(t)", "-max_cnt = 0", "-for i in range(n - m + 1):", "- cnt = 0", "- u = s[i : i + m]", "- for j in range(m):", "- if t[j] == u[j]:", "- cnt += 1", "- max_cnt = max(max_cnt, cnt)", "-print((m - max_cnt))", "+s, t = eval(input()), eval(input())", "+n, m = len(s), len(t)", "+print((min(sum(t[j] != s[i + j] for j in range(m)) for i in range(n - m + 1))))" ]
false
0.076968
0.080765
0.952984
[ "s270773283", "s755002287" ]
u604774382
p02408
python
s181818324
s545870261
20
10
4,248
4,232
Accepted
Accepted
50
import sys n = int( sys.stdin.readline() ) cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 } for i in range( n ): pattern, num = sys.stdin.readline().split( " " ) if "S" == pattern: cards[ 'S' ][ int( num )-1 ] = True elif "H" == pattern: cards[ 'H' ][ int( num )-1 ] = True elif "C" == pattern: cards[ 'C' ][ int( num )-1 ] = True elif "D" == pattern: cards[ 'D' ][ int( num )-1 ] = True for pattern in ( 'S', 'H', 'C', 'D' ): for i in range( 13 ): if not cards[ pattern ][ i ]: print(( "{:s} {:d}".format( pattern, i+1 ) ))
import sys n = int( sys.stdin.readline() ) cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 } for i in range( n ): pattern, num = sys.stdin.readline().split( " " ) cards[ pattern ][ int( num )-1 ] = True for pattern in ( 'S', 'H', 'C', 'D' ): for i in range( 13 ): if not cards[ pattern ][ i ]: print(( "{:s} {:d}".format( pattern, i+1 ) ))
19
12
607
403
import sys n = int(sys.stdin.readline()) cards = {"S": [False] * 13, "H": [False] * 13, "C": [False] * 13, "D": [False] * 13} for i in range(n): pattern, num = sys.stdin.readline().split(" ") if "S" == pattern: cards["S"][int(num) - 1] = True elif "H" == pattern: cards["H"][int(num) - 1] = True elif "C" == pattern: cards["C"][int(num) - 1] = True elif "D" == pattern: cards["D"][int(num) - 1] = True for pattern in ("S", "H", "C", "D"): for i in range(13): if not cards[pattern][i]: print(("{:s} {:d}".format(pattern, i + 1)))
import sys n = int(sys.stdin.readline()) cards = {"S": [False] * 13, "H": [False] * 13, "C": [False] * 13, "D": [False] * 13} for i in range(n): pattern, num = sys.stdin.readline().split(" ") cards[pattern][int(num) - 1] = True for pattern in ("S", "H", "C", "D"): for i in range(13): if not cards[pattern][i]: print(("{:s} {:d}".format(pattern, i + 1)))
false
36.842105
[ "- if \"S\" == pattern:", "- cards[\"S\"][int(num) - 1] = True", "- elif \"H\" == pattern:", "- cards[\"H\"][int(num) - 1] = True", "- elif \"C\" == pattern:", "- cards[\"C\"][int(num) - 1] = True", "- elif \"D\" == pattern:", "- cards[\"D\"][int(num) - 1] = True", "+ cards[pattern][int(num) - 1] = True" ]
false
0.086302
0.04693
1.83896
[ "s181818324", "s545870261" ]
u844646164
p03487
python
s793211130
s242339911
230
105
68,264
93,000
Accepted
Accepted
54.35
from collections import Counter n = int(eval(input())) l = list(map(int, input().split())) c = Counter(l) ans = 0 for k, v in list(c.items()): if k < v: ans += v - k elif k > v: ans += v print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ca = Counter(a) ans = 0 for k, v in list(ca.items()): if v < k: ans += v elif v > k: ans += v-k print(ans)
11
11
220
219
from collections import Counter n = int(eval(input())) l = list(map(int, input().split())) c = Counter(l) ans = 0 for k, v in list(c.items()): if k < v: ans += v - k elif k > v: ans += v print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ca = Counter(a) ans = 0 for k, v in list(ca.items()): if v < k: ans += v elif v > k: ans += v - k print(ans)
false
0
[ "-n = int(eval(input()))", "-l = list(map(int, input().split()))", "-c = Counter(l)", "+N = int(eval(input()))", "+a = list(map(int, input().split()))", "+ca = Counter(a)", "-for k, v in list(c.items()):", "- if k < v:", "+for k, v in list(ca.items()):", "+ if v < k:", "+ ans += v", "+ elif v > k:", "- elif k > v:", "- ans += v" ]
false
0.119125
0.046535
2.559903
[ "s793211130", "s242339911" ]
u201234972
p02900
python
s169106220
s652244994
285
111
3,316
3,064
Accepted
Accepted
61.05
def gcd(a, b): while b != 0: a, b = b, a % b return a def is_prime(n): if n == 1: return False for i in range(2, int(n**(1/2)) + 1): if n%i == 0: return False return True def factors(N): #約数を全て求める。ただし、順不同 from collections import deque ret = 0 middle = int( N**(1/2)) for i in range(1, middle): if N%i == 0: if is_prime(i): ret += 1 if is_prime(N//i): ret += 1 if N%middle == 0: if is_prime(middle): ret += 1 if middle != N//middle: if is_prime(N//middle): ret += 1 return ret def main(): a, b = list(map( int, input().split())) d = gcd(a,b) # print(2, is_prime(2)) if d == 1: print((1)) return if is_prime(d): print((2)) return print((factors(d)+1)) if __name__ == '__main__': main()
def gcd(a, b): while b != 0: a, b = b, a % b return a def factors(N): #約数を全て求める。ただし、順不同 ret = 1 middle = int( N**(1/2)) tmp = N # if tmp%2 == 0: # while tmp%2 == 0: # tmp //= 2 for i in range(2, middle+1): if tmp%i == 0: ret += 1 while tmp%i == 0: tmp //= i if tmp != 1: ret += 1 return ret def main(): a, b = list(map( int, input().split())) d = gcd(a,b) # print(2, is_prime(2)) if d == 1: print((1)) return print((factors(d))) if __name__ == '__main__': main()
48
34
1,000
654
def gcd(a, b): while b != 0: a, b = b, a % b return a def is_prime(n): if n == 1: return False for i in range(2, int(n ** (1 / 2)) + 1): if n % i == 0: return False return True def factors(N): # 約数を全て求める。ただし、順不同 from collections import deque ret = 0 middle = int(N ** (1 / 2)) for i in range(1, middle): if N % i == 0: if is_prime(i): ret += 1 if is_prime(N // i): ret += 1 if N % middle == 0: if is_prime(middle): ret += 1 if middle != N // middle: if is_prime(N // middle): ret += 1 return ret def main(): a, b = list(map(int, input().split())) d = gcd(a, b) # print(2, is_prime(2)) if d == 1: print((1)) return if is_prime(d): print((2)) return print((factors(d) + 1)) if __name__ == "__main__": main()
def gcd(a, b): while b != 0: a, b = b, a % b return a def factors(N): # 約数を全て求める。ただし、順不同 ret = 1 middle = int(N ** (1 / 2)) tmp = N # if tmp%2 == 0: # while tmp%2 == 0: # tmp //= 2 for i in range(2, middle + 1): if tmp % i == 0: ret += 1 while tmp % i == 0: tmp //= i if tmp != 1: ret += 1 return ret def main(): a, b = list(map(int, input().split())) d = gcd(a, b) # print(2, is_prime(2)) if d == 1: print((1)) return print((factors(d))) if __name__ == "__main__": main()
false
29.166667
[ "-def is_prime(n):", "- if n == 1:", "- return False", "- for i in range(2, int(n ** (1 / 2)) + 1):", "- if n % i == 0:", "- return False", "- return True", "-", "-", "- from collections import deque", "-", "- ret = 0", "+ ret = 1", "- for i in range(1, middle):", "- if N % i == 0:", "- if is_prime(i):", "- ret += 1", "- if is_prime(N // i):", "- ret += 1", "- if N % middle == 0:", "- if is_prime(middle):", "+ tmp = N", "+ # if tmp%2 == 0:", "+ # while tmp%2 == 0:", "+ # tmp //= 2", "+ for i in range(2, middle + 1):", "+ if tmp % i == 0:", "- if middle != N // middle:", "- if is_prime(N // middle):", "- ret += 1", "+ while tmp % i == 0:", "+ tmp //= i", "+ if tmp != 1:", "+ ret += 1", "- if is_prime(d):", "- print((2))", "- return", "- print((factors(d) + 1))", "+ print((factors(d)))" ]
false
0.059311
0.0576
1.029711
[ "s169106220", "s652244994" ]
u677121387
p02691
python
s880930291
s722967139
271
245
61,488
61,500
Accepted
Accepted
9.59
from collections import defaultdict n = int(eval(input())) a = [int(i) for i in input().split()] d = defaultdict(int) for i in range(n): d[i+1+a[i]] += 1 ans = 0 for j in range(n): ans += d[j+1-a[j]] print(ans)
from collections import defaultdict n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 d = defaultdict(int) for i in range(n): ans += d[i+1-a[i]] d[i+1+a[i]] += 1 print(ans)
8
9
211
201
from collections import defaultdict n = int(eval(input())) a = [int(i) for i in input().split()] d = defaultdict(int) for i in range(n): d[i + 1 + a[i]] += 1 ans = 0 for j in range(n): ans += d[j + 1 - a[j]] print(ans)
from collections import defaultdict n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 d = defaultdict(int) for i in range(n): ans += d[i + 1 - a[i]] d[i + 1 + a[i]] += 1 print(ans)
false
11.111111
[ "+ans = 0", "+ ans += d[i + 1 - a[i]]", "-ans = 0", "-for j in range(n):", "- ans += d[j + 1 - a[j]]" ]
false
0.008053
0.033092
0.243345
[ "s880930291", "s722967139" ]
u324197506
p02691
python
s804344221
s500210001
527
298
87,488
57,532
Accepted
Accepted
43.45
import sys input = sys.stdin.readline N = int(eval(input())) heights = list(map(int, input().split())) cnt_height_plus_ind = {} cnt_height_minus_ind = {} cnt_ind_minus_height = {} cnt_minus_height_minus_ind = {} for ind in range(N): height = heights[ind] if ind - height not in cnt_ind_minus_height: cnt_ind_minus_height[ind - height] = 0 cnt_ind_minus_height[ind - height] += 1 if ind + height not in cnt_height_plus_ind: cnt_height_plus_ind[ind + height] = 0 cnt_height_plus_ind[ind + height] += 1 if height - ind not in cnt_height_minus_ind: cnt_height_minus_ind[height - ind] = 0 cnt_height_minus_ind[height - ind] += 1 if - ind - height not in cnt_minus_height_minus_ind: cnt_minus_height_minus_ind[-ind-height] = 0 cnt_minus_height_minus_ind[-ind-height] += 1 ans = 0 #for val in cnt_height_minus_ind: # if val in cnt_minus_height_minus_ind: # ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val] for val in cnt_height_plus_ind: if val in cnt_ind_minus_height: ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val] print(ans)
N = int(eval(input())) heights = list(map(int, input().split())) cnt_height_plus_ind = {} cnt_ind_minus_height = {} for ind in range(N): height = heights[ind] if ind - height not in cnt_ind_minus_height: cnt_ind_minus_height[ind - height] = 0 cnt_ind_minus_height[ind - height] += 1 if ind + height not in cnt_height_plus_ind: cnt_height_plus_ind[ind + height] = 0 cnt_height_plus_ind[ind + height] += 1 ans = 0 for val in cnt_height_plus_ind: if val in cnt_ind_minus_height: ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val] print(ans)
43
25
1,194
620
import sys input = sys.stdin.readline N = int(eval(input())) heights = list(map(int, input().split())) cnt_height_plus_ind = {} cnt_height_minus_ind = {} cnt_ind_minus_height = {} cnt_minus_height_minus_ind = {} for ind in range(N): height = heights[ind] if ind - height not in cnt_ind_minus_height: cnt_ind_minus_height[ind - height] = 0 cnt_ind_minus_height[ind - height] += 1 if ind + height not in cnt_height_plus_ind: cnt_height_plus_ind[ind + height] = 0 cnt_height_plus_ind[ind + height] += 1 if height - ind not in cnt_height_minus_ind: cnt_height_minus_ind[height - ind] = 0 cnt_height_minus_ind[height - ind] += 1 if -ind - height not in cnt_minus_height_minus_ind: cnt_minus_height_minus_ind[-ind - height] = 0 cnt_minus_height_minus_ind[-ind - height] += 1 ans = 0 # for val in cnt_height_minus_ind: # if val in cnt_minus_height_minus_ind: # ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val] for val in cnt_height_plus_ind: if val in cnt_ind_minus_height: ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val] print(ans)
N = int(eval(input())) heights = list(map(int, input().split())) cnt_height_plus_ind = {} cnt_ind_minus_height = {} for ind in range(N): height = heights[ind] if ind - height not in cnt_ind_minus_height: cnt_ind_minus_height[ind - height] = 0 cnt_ind_minus_height[ind - height] += 1 if ind + height not in cnt_height_plus_ind: cnt_height_plus_ind[ind + height] = 0 cnt_height_plus_ind[ind + height] += 1 ans = 0 for val in cnt_height_plus_ind: if val in cnt_ind_minus_height: ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val] print(ans)
false
41.860465
[ "-import sys", "-", "-input = sys.stdin.readline", "-cnt_height_minus_ind = {}", "-cnt_minus_height_minus_ind = {}", "- if height - ind not in cnt_height_minus_ind:", "- cnt_height_minus_ind[height - ind] = 0", "- cnt_height_minus_ind[height - ind] += 1", "- if -ind - height not in cnt_minus_height_minus_ind:", "- cnt_minus_height_minus_ind[-ind - height] = 0", "- cnt_minus_height_minus_ind[-ind - height] += 1", "-# for val in cnt_height_minus_ind:", "-# if val in cnt_minus_height_minus_ind:", "-# ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]" ]
false
0.078406
0.085541
0.916596
[ "s804344221", "s500210001" ]
u879226672
p00593
python
s592159297
s666937352
20
10
4,264
4,268
Accepted
Accepted
50
case = 1 while True: N = int(input()) if N == 0: break mat = [[0 for i in range(N)] for j in range(N)] n = 1 for i in range(N): # upper half for j in range(i,-1,-1): if i%2==0: mat[j][i-j] = n n += 1 elif i%2==1: mat[i-j][j] = n n += 1 for i in range(N,2*N-1): # lower half for j in range(N-1,i-N,-1): if i%2==0: mat[j][i-j] = n n += 1 elif i%2==1: mat[i-j][j] = n n += 1 print('Case %d:'%(case)); case += 1 for s in mat: print(''.join(map(str,[str(st).rjust(3) for st in s])))
# coding: utf-8 # Here your code ! case = 1 while True: N = int(input()) if N == 0: break mat = [[0 for i in range(N)] for j in range(N)] n = 1 for i in range(N): # upper half for j in reversed(range(i+1)): if i%2==0: mat[j][i-j] = n n += 1 elif i%2==1: mat[i-j][j] = n n += 1 for i in range(N,2*N-1): # lower half for j in reversed(range(i-N+1,N)): if i%2==0: mat[j][i-j] = n n += 1 elif i%2==1: mat[i-j][j] = n n += 1 print('Case %d:'%(case)); case += 1 for s in mat: print(''.join(map(str,[str(st).rjust(3) for st in s])))
31
28
796
808
case = 1 while True: N = int(input()) if N == 0: break mat = [[0 for i in range(N)] for j in range(N)] n = 1 for i in range(N): # upper half for j in range(i, -1, -1): if i % 2 == 0: mat[j][i - j] = n n += 1 elif i % 2 == 1: mat[i - j][j] = n n += 1 for i in range(N, 2 * N - 1): # lower half for j in range(N - 1, i - N, -1): if i % 2 == 0: mat[j][i - j] = n n += 1 elif i % 2 == 1: mat[i - j][j] = n n += 1 print("Case %d:" % (case)) case += 1 for s in mat: print("".join(map(str, [str(st).rjust(3) for st in s])))
# coding: utf-8 # Here your code ! case = 1 while True: N = int(input()) if N == 0: break mat = [[0 for i in range(N)] for j in range(N)] n = 1 for i in range(N): # upper half for j in reversed(range(i + 1)): if i % 2 == 0: mat[j][i - j] = n n += 1 elif i % 2 == 1: mat[i - j][j] = n n += 1 for i in range(N, 2 * N - 1): # lower half for j in reversed(range(i - N + 1, N)): if i % 2 == 0: mat[j][i - j] = n n += 1 elif i % 2 == 1: mat[i - j][j] = n n += 1 print("Case %d:" % (case)) case += 1 for s in mat: print("".join(map(str, [str(st).rjust(3) for st in s])))
false
9.677419
[ "+# coding: utf-8", "+# Here your code !", "- for j in range(i, -1, -1):", "+ for j in reversed(range(i + 1)):", "- for j in range(N - 1, i - N, -1):", "+ for j in reversed(range(i - N + 1, N)):" ]
false
0.038573
0.037567
1.026786
[ "s592159297", "s666937352" ]
u057109575
p03078
python
s385725790
s065985582
829
153
217,756
79,232
Accepted
Accepted
81.54
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) res = [] for a in A: for b in B: res.append(a + b) res.sort(reverse=True) res2 = [] for v in res[:K]: for c in C: res2.append(v + c) res2.sort(reverse=True) for i in range(K): print((res2[i]))
from heapq import heappop, heappush X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) pq = [] heappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0)) appeared = set((0, 0, 0)) for _ in range(K): # Pop maximum value val, i, j, k = heappop(pq) print((-val)) # Add next value if i + 1 < X and (i + 1, j, k) not in appeared: heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k)) appeared.add((i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in appeared: heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k)) appeared.add((i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in appeared: heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1)) appeared.add((i, j, k + 1))
21
33
391
923
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) res = [] for a in A: for b in B: res.append(a + b) res.sort(reverse=True) res2 = [] for v in res[:K]: for c in C: res2.append(v + c) res2.sort(reverse=True) for i in range(K): print((res2[i]))
from heapq import heappop, heappush X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) pq = [] heappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0)) appeared = set((0, 0, 0)) for _ in range(K): # Pop maximum value val, i, j, k = heappop(pq) print((-val)) # Add next value if i + 1 < X and (i + 1, j, k) not in appeared: heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k)) appeared.add((i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in appeared: heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k)) appeared.add((i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in appeared: heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1)) appeared.add((i, j, k + 1))
false
36.363636
[ "+from heapq import heappop, heappush", "+", "-res = []", "-for a in A:", "- for b in B:", "- res.append(a + b)", "-res.sort(reverse=True)", "-res2 = []", "-for v in res[:K]:", "- for c in C:", "- res2.append(v + c)", "-res2.sort(reverse=True)", "-for i in range(K):", "- print((res2[i]))", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+pq = []", "+heappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0))", "+appeared = set((0, 0, 0))", "+for _ in range(K):", "+ # Pop maximum value", "+ val, i, j, k = heappop(pq)", "+ print((-val))", "+ # Add next value", "+ if i + 1 < X and (i + 1, j, k) not in appeared:", "+ heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k))", "+ appeared.add((i + 1, j, k))", "+ if j + 1 < Y and (i, j + 1, k) not in appeared:", "+ heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k))", "+ appeared.add((i, j + 1, k))", "+ if k + 1 < Z and (i, j, k + 1) not in appeared:", "+ heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1))", "+ appeared.add((i, j, k + 1))" ]
false
0.036958
0.031583
1.170156
[ "s385725790", "s065985582" ]
u712082626
p03102
python
s696032555
s447582152
301
151
21,076
12,428
Accepted
Accepted
49.83
import numpy as np from operator import mul from functools import reduce N, M, C = [int(x) for x in input().split()] B = np.array([int(x) for x in input().split()]) #A = np.array([[0]*M,N]) A = np.empty((N,M)) result = np.array([]) count = 0 for n in range(N): A[n] = [int(m) for m in input().split()] #result = A[n] * B if sum(A[n] * B)+C > 0: count +=1 print(count)
import numpy as np N, M, C = [int(x) for x in input().split()] B = np.array([int(x) for x in input().split()]) A = np.empty((N,M)) count = 0 for n in range(N): A[n] = [int(m) for m in input().split()] count = count + 1 if sum(A[n] * B)+C > 0 else count print(count)
18
11
408
287
import numpy as np from operator import mul from functools import reduce N, M, C = [int(x) for x in input().split()] B = np.array([int(x) for x in input().split()]) # A = np.array([[0]*M,N]) A = np.empty((N, M)) result = np.array([]) count = 0 for n in range(N): A[n] = [int(m) for m in input().split()] # result = A[n] * B if sum(A[n] * B) + C > 0: count += 1 print(count)
import numpy as np N, M, C = [int(x) for x in input().split()] B = np.array([int(x) for x in input().split()]) A = np.empty((N, M)) count = 0 for n in range(N): A[n] = [int(m) for m in input().split()] count = count + 1 if sum(A[n] * B) + C > 0 else count print(count)
false
38.888889
[ "-from operator import mul", "-from functools import reduce", "-# A = np.array([[0]*M,N])", "-result = np.array([])", "- # result = A[n] * B", "- if sum(A[n] * B) + C > 0:", "- count += 1", "+ count = count + 1 if sum(A[n] * B) + C > 0 else count" ]
false
0.308345
0.402546
0.765987
[ "s696032555", "s447582152" ]
u449108605
p02784
python
s727734296
s233356614
49
37
9,944
10,132
Accepted
Accepted
24.49
H,N = list(map(int,input().split())) A = list(map(int, input().split())) sum=0 for Ai in A: sum += Ai if sum >= H: print('Yes') else: print('No')
H,N = list(map(int,input().split())) Ai = list(map(int, input().split())) if sum(Ai) >= H: print('Yes') else: print('No')
11
7
151
121
H, N = list(map(int, input().split())) A = list(map(int, input().split())) sum = 0 for Ai in A: sum += Ai if sum >= H: print("Yes") else: print("No")
H, N = list(map(int, input().split())) Ai = list(map(int, input().split())) if sum(Ai) >= H: print("Yes") else: print("No")
false
36.363636
[ "-A = list(map(int, input().split()))", "-sum = 0", "-for Ai in A:", "- sum += Ai", "-if sum >= H:", "+Ai = list(map(int, input().split()))", "+if sum(Ai) >= H:" ]
false
0.0356
0.043595
0.816622
[ "s727734296", "s233356614" ]
u644907318
p03017
python
s001923684
s084963952
189
87
40,816
86,456
Accepted
Accepted
53.97
N,A,B,C,D = list(map(int,input().split())) S = input().strip() S = "."+S flag=0 if C<B: for i in range(A,C): if S[i:i+2]=="##": flag=1 break for i in range(B,D): if S[i:i+2]=="##": flag=1 break if flag==1: print("No") else: print("Yes") elif B<C<D: for i in range(A,D): if S[i:i+2]=="##": flag=1 break if flag==1: print("No") else: print("Yes") else: for i in range(A,C): if S[i:i+2]=="##": flag = 1 break if flag==1: print("No") else: flag = 1 for i in range(B+1,D): if S[i]=="#":continue if (S[i-1]=="#" and S[i+1]=="#") or (S[i-2:i]=="#." and S[i+1]=="#") or (S[i-1]=="#" and S[i+1:i+3]==".#"):continue else: flag=0 break if flag==1: if S[B+1]=="#" or (S[B-1]=="#" and S[B+1:B+3]==".#"): flag=1 else: flag=0 if flag==1: print("No") else: print("Yes")
N,A,B,C,D = list(map(int,input().split())) S = list(input().strip()) S.insert(0,0) if C<D: flag = 0 for i in range(A+1,C+1): if S[i-1]=="#" and S[i]=="#": flag = 1 break for i in range(B+1,D+1): if S[i-1]=="#" and S[i]=="#": flag = 1 break if flag==0: print("Yes") else: print("No") else: flag = 0 for i in range(A+1,C+1): if S[i]=="#" and S[i-1]=="#": flag = 1 break if flag == 0: flag1 = 1 for i in range(B,D+1): if i+1<=N and S[i-1]=="." and S[i]=="." and S[i+1]==".": flag1 = 0 break if flag1==1: flag = 1 if flag==0: print("Yes") else: print("No")
50
35
1,192
828
N, A, B, C, D = list(map(int, input().split())) S = input().strip() S = "." + S flag = 0 if C < B: for i in range(A, C): if S[i : i + 2] == "##": flag = 1 break for i in range(B, D): if S[i : i + 2] == "##": flag = 1 break if flag == 1: print("No") else: print("Yes") elif B < C < D: for i in range(A, D): if S[i : i + 2] == "##": flag = 1 break if flag == 1: print("No") else: print("Yes") else: for i in range(A, C): if S[i : i + 2] == "##": flag = 1 break if flag == 1: print("No") else: flag = 1 for i in range(B + 1, D): if S[i] == "#": continue if ( (S[i - 1] == "#" and S[i + 1] == "#") or (S[i - 2 : i] == "#." and S[i + 1] == "#") or (S[i - 1] == "#" and S[i + 1 : i + 3] == ".#") ): continue else: flag = 0 break if flag == 1: if S[B + 1] == "#" or (S[B - 1] == "#" and S[B + 1 : B + 3] == ".#"): flag = 1 else: flag = 0 if flag == 1: print("No") else: print("Yes")
N, A, B, C, D = list(map(int, input().split())) S = list(input().strip()) S.insert(0, 0) if C < D: flag = 0 for i in range(A + 1, C + 1): if S[i - 1] == "#" and S[i] == "#": flag = 1 break for i in range(B + 1, D + 1): if S[i - 1] == "#" and S[i] == "#": flag = 1 break if flag == 0: print("Yes") else: print("No") else: flag = 0 for i in range(A + 1, C + 1): if S[i] == "#" and S[i - 1] == "#": flag = 1 break if flag == 0: flag1 = 1 for i in range(B, D + 1): if i + 1 <= N and S[i - 1] == "." and S[i] == "." and S[i + 1] == ".": flag1 = 0 break if flag1 == 1: flag = 1 if flag == 0: print("Yes") else: print("No")
false
30
[ "-S = input().strip()", "-S = \".\" + S", "-flag = 0", "-if C < B:", "- for i in range(A, C):", "- if S[i : i + 2] == \"##\":", "+S = list(input().strip())", "+S.insert(0, 0)", "+if C < D:", "+ flag = 0", "+ for i in range(A + 1, C + 1):", "+ if S[i - 1] == \"#\" and S[i] == \"#\":", "- for i in range(B, D):", "- if S[i : i + 2] == \"##\":", "+ for i in range(B + 1, D + 1):", "+ if S[i - 1] == \"#\" and S[i] == \"#\":", "- if flag == 1:", "+ if flag == 0:", "+ print(\"Yes\")", "+ else:", "- else:", "- print(\"Yes\")", "-elif B < C < D:", "- for i in range(A, D):", "- if S[i : i + 2] == \"##\":", "+else:", "+ flag = 0", "+ for i in range(A + 1, C + 1):", "+ if S[i] == \"#\" and S[i - 1] == \"#\":", "- if flag == 1:", "+ if flag == 0:", "+ flag1 = 1", "+ for i in range(B, D + 1):", "+ if i + 1 <= N and S[i - 1] == \".\" and S[i] == \".\" and S[i + 1] == \".\":", "+ flag1 = 0", "+ break", "+ if flag1 == 1:", "+ flag = 1", "+ if flag == 0:", "+ print(\"Yes\")", "+ else:", "- else:", "- print(\"Yes\")", "-else:", "- for i in range(A, C):", "- if S[i : i + 2] == \"##\":", "- flag = 1", "- break", "- if flag == 1:", "- print(\"No\")", "- else:", "- flag = 1", "- for i in range(B + 1, D):", "- if S[i] == \"#\":", "- continue", "- if (", "- (S[i - 1] == \"#\" and S[i + 1] == \"#\")", "- or (S[i - 2 : i] == \"#.\" and S[i + 1] == \"#\")", "- or (S[i - 1] == \"#\" and S[i + 1 : i + 3] == \".#\")", "- ):", "- continue", "- else:", "- flag = 0", "- break", "- if flag == 1:", "- if S[B + 1] == \"#\" or (S[B - 1] == \"#\" and S[B + 1 : B + 3] == \".#\"):", "- flag = 1", "- else:", "- flag = 0", "- if flag == 1:", "- print(\"No\")", "- else:", "- print(\"Yes\")" ]
false
0.041604
0.092317
0.45067
[ "s001923684", "s084963952" ]
u794173881
p03150
python
s525612304
s724834013
137
27
4,212
3,828
Accepted
Accepted
80.29
import fnmatch S=[] S.append(eval(input())) if S == fnmatch.filter(S, "*keyence") or S == fnmatch.filter(S, "k*eyence") or S == fnmatch.filter(S, "ke*yence") or S == fnmatch.filter(S, "key*ence") or S == fnmatch.filter(S, "keye*nce") or S == fnmatch.filter(S, "keyen*ce") or S == fnmatch.filter(S, "keyenc*e") or S == fnmatch.filter(S, "keyence*"): print("YES") else: print("NO")
import fnmatch S=[] S.append(eval(input())) if S == fnmatch.filter(S, "k*eyence") or S == fnmatch.filter(S, "ke*yence") or S == fnmatch.filter(S, "key*ence") or S == fnmatch.filter(S, "keye*nce") or S == fnmatch.filter(S, "keyen*ce") or S == fnmatch.filter(S, "keyenc*e") : print("YES") else: print("NO")
7
7
383
308
import fnmatch S = [] S.append(eval(input())) if ( S == fnmatch.filter(S, "*keyence") or S == fnmatch.filter(S, "k*eyence") or S == fnmatch.filter(S, "ke*yence") or S == fnmatch.filter(S, "key*ence") or S == fnmatch.filter(S, "keye*nce") or S == fnmatch.filter(S, "keyen*ce") or S == fnmatch.filter(S, "keyenc*e") or S == fnmatch.filter(S, "keyence*") ): print("YES") else: print("NO")
import fnmatch S = [] S.append(eval(input())) if ( S == fnmatch.filter(S, "k*eyence") or S == fnmatch.filter(S, "ke*yence") or S == fnmatch.filter(S, "key*ence") or S == fnmatch.filter(S, "keye*nce") or S == fnmatch.filter(S, "keyen*ce") or S == fnmatch.filter(S, "keyenc*e") ): print("YES") else: print("NO")
false
0
[ "- S == fnmatch.filter(S, \"*keyence\")", "- or S == fnmatch.filter(S, \"k*eyence\")", "+ S == fnmatch.filter(S, \"k*eyence\")", "- or S == fnmatch.filter(S, \"keyence*\")" ]
false
0.064544
0.040069
1.610817
[ "s525612304", "s724834013" ]
u210987097
p02658
python
s797134329
s047100955
54
49
21,656
21,712
Accepted
Accepted
9.26
n = int(eval(input())) a =list(map(int, input().split())) if 0 in a: print((0)) else : prod = 1 for x in a: prod *= x if prod: if prod > 10**18: print((-1)) break else : print((0)) break else : print(prod)
n = int(eval(input())) a = list(map(int, input().split())) if 0 in a: print((0)) else : prod = 1 for x in a: prod *= x if prod > 10**18: print((-1)) break else : print(prod)
17
13
268
207
n = int(eval(input())) a = list(map(int, input().split())) if 0 in a: print((0)) else: prod = 1 for x in a: prod *= x if prod: if prod > 10**18: print((-1)) break else: print((0)) break else: print(prod)
n = int(eval(input())) a = list(map(int, input().split())) if 0 in a: print((0)) else: prod = 1 for x in a: prod *= x if prod > 10**18: print((-1)) break else: print(prod)
false
23.529412
[ "- if prod:", "- if prod > 10**18:", "- print((-1))", "- break", "- else:", "- print((0))", "+ if prod > 10**18:", "+ print((-1))" ]
false
0.046915
0.047209
0.993776
[ "s797134329", "s047100955" ]
u780565479
p03280
python
s859175013
s930244334
184
17
38,256
2,940
Accepted
Accepted
90.76
A,B=list(map(int,input().split())) print(((A-1) * (B-1)))
print((eval('('+input().replace(' ','-1)*(')+'-1)')))
2
1
50
51
A, B = list(map(int, input().split())) print(((A - 1) * (B - 1)))
print((eval("(" + input().replace(" ", "-1)*(") + "-1)")))
false
50
[ "-A, B = list(map(int, input().split()))", "-print(((A - 1) * (B - 1)))", "+print((eval(\"(\" + input().replace(\" \", \"-1)*(\") + \"-1)\")))" ]
false
0.137067
0.07549
1.815687
[ "s859175013", "s930244334" ]
u766684188
p02897
python
s377569240
s592410146
178
17
38,256
2,940
Accepted
Accepted
90.45
n=int(eval(input())) if n%2: print(((n//2+1)/n)) else: print((0.5))
n=int(eval(input())) print((1-n//2/n))
5
2
69
31
n = int(eval(input())) if n % 2: print(((n // 2 + 1) / n)) else: print((0.5))
n = int(eval(input())) print((1 - n // 2 / n))
false
60
[ "-if n % 2:", "- print(((n // 2 + 1) / n))", "-else:", "- print((0.5))", "+print((1 - n // 2 / n))" ]
false
0.080544
0.03459
2.328518
[ "s377569240", "s592410146" ]
u002459665
p04031
python
s236001546
s774343041
19
17
3,064
3,064
Accepted
Accepted
10.53
def main(): N = int(eval(input())) A = list(map(int, input().split())) avg = sum(A) // N ans = 10 ** 10 for i in [avg, avg+1]: tmp = 0 for ai in A: x = (i - ai) ** 2 tmp += x ans = min(ans, tmp) print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = list(map(int, input().split())) # avg = sum(A) // N avg = sum(A) / N avg = round(avg) # ans = 10 ** 10 # for i in [avg, avg+1]: # tmp = 0 # for ai in A: # x = (i - ai) ** 2 # tmp += x # ans = min(ans, tmp) ans = 0 for ai in A: x = (avg - ai) ** 2 ans += x print(ans) if __name__ == "__main__": main()
21
27
340
478
def main(): N = int(eval(input())) A = list(map(int, input().split())) avg = sum(A) // N ans = 10**10 for i in [avg, avg + 1]: tmp = 0 for ai in A: x = (i - ai) ** 2 tmp += x ans = min(ans, tmp) print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = list(map(int, input().split())) # avg = sum(A) // N avg = sum(A) / N avg = round(avg) # ans = 10 ** 10 # for i in [avg, avg+1]: # tmp = 0 # for ai in A: # x = (i - ai) ** 2 # tmp += x # ans = min(ans, tmp) ans = 0 for ai in A: x = (avg - ai) ** 2 ans += x print(ans) if __name__ == "__main__": main()
false
22.222222
[ "- avg = sum(A) // N", "- ans = 10**10", "- for i in [avg, avg + 1]:", "- tmp = 0", "- for ai in A:", "- x = (i - ai) ** 2", "- tmp += x", "- ans = min(ans, tmp)", "+ # avg = sum(A) // N", "+ avg = sum(A) / N", "+ avg = round(avg)", "+ # ans = 10 ** 10", "+ # for i in [avg, avg+1]:", "+ # tmp = 0", "+ # for ai in A:", "+ # x = (i - ai) ** 2", "+ # tmp += x", "+ # ans = min(ans, tmp)", "+ ans = 0", "+ for ai in A:", "+ x = (avg - ai) ** 2", "+ ans += x" ]
false
0.063431
0.062523
1.014531
[ "s236001546", "s774343041" ]
u633068244
p00687
python
s235917926
s119226523
1,900
1,130
43,756
43,784
Accepted
Accepted
40.53
while 1: n,a,b = list(map(int,input().split())) if n == 0: break dp = [0]*(n+1) if a < n+1: dp[a] = 1 if b < n+1: dp[b] = 1 for i in range(n+1): if dp[i]: if i+a < n+1: dp[i+a] = 1 if i+b < n+1: dp[i+b] = 1 print(n - sum(dp))
while 1: n,a,b = list(map(int,input().split())) if n == 0: break dp = [0]*(n+max(a,b)+1) dp[a] = dp[b] = 1 for i in range(n+1): if dp[i]: dp[i+a] = dp[i+b] = 1 print(n - sum(dp[:n+1]))
11
9
247
200
while 1: n, a, b = list(map(int, input().split())) if n == 0: break dp = [0] * (n + 1) if a < n + 1: dp[a] = 1 if b < n + 1: dp[b] = 1 for i in range(n + 1): if dp[i]: if i + a < n + 1: dp[i + a] = 1 if i + b < n + 1: dp[i + b] = 1 print(n - sum(dp))
while 1: n, a, b = list(map(int, input().split())) if n == 0: break dp = [0] * (n + max(a, b) + 1) dp[a] = dp[b] = 1 for i in range(n + 1): if dp[i]: dp[i + a] = dp[i + b] = 1 print(n - sum(dp[: n + 1]))
false
18.181818
[ "- dp = [0] * (n + 1)", "- if a < n + 1:", "- dp[a] = 1", "- if b < n + 1:", "- dp[b] = 1", "+ dp = [0] * (n + max(a, b) + 1)", "+ dp[a] = dp[b] = 1", "- if i + a < n + 1:", "- dp[i + a] = 1", "- if i + b < n + 1:", "- dp[i + b] = 1", "- print(n - sum(dp))", "+ dp[i + a] = dp[i + b] = 1", "+ print(n - sum(dp[: n + 1]))" ]
false
0.038292
0.036902
1.037662
[ "s235917926", "s119226523" ]
u374531474
p03805
python
s893838512
s450576824
28
24
3,064
3,444
Accepted
Accepted
14.29
N, M = list(map(int, input().split())) adjacent = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 adjacent[a].append(b) adjacent[b].append(a) def dfs(visited, v): if visited == (1 << N) - 1: return 1 ans = 0 for u in adjacent[v]: if visited >> u & 1 == 1: continue visited += 1 << u ans += dfs(visited, u) visited -= 1 << u return ans print((dfs(1, 0)))
from collections import defaultdict N, M = list(map(int, input().split())) adjacent = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 adjacent[a].append(b) adjacent[b].append(a) dp = defaultdict(int) dp[(1, 0)] = 1 for S in range(1 << N): for v in range(N): if S & (1 << v) == 0: continue sub = S ^ (1 << v) for u in adjacent[v]: if sub & (1 << u): dp[(S, v)] += dp[(sub, u)] print((sum(dp[((1 << N) - 1, u)] for u in range(1, N))))
25
22
504
577
N, M = list(map(int, input().split())) adjacent = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 adjacent[a].append(b) adjacent[b].append(a) def dfs(visited, v): if visited == (1 << N) - 1: return 1 ans = 0 for u in adjacent[v]: if visited >> u & 1 == 1: continue visited += 1 << u ans += dfs(visited, u) visited -= 1 << u return ans print((dfs(1, 0)))
from collections import defaultdict N, M = list(map(int, input().split())) adjacent = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 adjacent[a].append(b) adjacent[b].append(a) dp = defaultdict(int) dp[(1, 0)] = 1 for S in range(1 << N): for v in range(N): if S & (1 << v) == 0: continue sub = S ^ (1 << v) for u in adjacent[v]: if sub & (1 << u): dp[(S, v)] += dp[(sub, u)] print((sum(dp[((1 << N) - 1, u)] for u in range(1, N))))
false
12
[ "+from collections import defaultdict", "+", "-", "-", "-def dfs(visited, v):", "- if visited == (1 << N) - 1:", "- return 1", "- ans = 0", "- for u in adjacent[v]:", "- if visited >> u & 1 == 1:", "+dp = defaultdict(int)", "+dp[(1, 0)] = 1", "+for S in range(1 << N):", "+ for v in range(N):", "+ if S & (1 << v) == 0:", "- visited += 1 << u", "- ans += dfs(visited, u)", "- visited -= 1 << u", "- return ans", "-", "-", "-print((dfs(1, 0)))", "+ sub = S ^ (1 << v)", "+ for u in adjacent[v]:", "+ if sub & (1 << u):", "+ dp[(S, v)] += dp[(sub, u)]", "+print((sum(dp[((1 << N) - 1, u)] for u in range(1, N))))" ]
false
0.042963
0.041988
1.023228
[ "s893838512", "s450576824" ]
u620480037
p02889
python
s540856984
s332890893
1,823
1,483
19,420
56,924
Accepted
Accepted
18.65
from scipy.sparse.csgraph import floyd_warshall N,M,L=list(map(int,input().split())) A=[[10**12 for i in range(N+1)]for j in range(N+1)] B=[[10**12 for i in range(N+1)]for j in range(N+1)] for i in range(M): a,b,c=list(map(int,input().split())) if c<=L: A[a][b]=c A[b][a]=c B[a][b]=1 B[b][a]=1 #print(A) A= floyd_warshall(A,directed = False) #print(A) for i in range(N+1): for j in range(N+1): if A[i][j]<=L: B[i][j]=1 """for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): A[a][b]=min(A[a][b],A[a][c]+A[c][b]) if A[a][b]<=L: B[a][b]=1""" #print(B) B= floyd_warshall(B,directed = False) """for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): B[a][b]=min(B[a][b],B[a][c]+B[c][b])""" #print(B) Q=int(eval(input())) for i in range(Q): s,t=list(map(int,input().split())) if B[s][t]==10**12: print((-1)) else: print((int(B[s][t]-1)))
import sys input = sys.stdin.readline N,M,L=list(map(int,input().split())) A=[[10**12 for i in range(N+1)]for j in range(N+1)] B=[[10**12 for i in range(N+1)]for j in range(N+1)] for i in range(M): a,b,c=list(map(int,input().split())) if c<=L: A[a][b]=c A[b][a]=c B[a][b]=1 B[b][a]=1 for i in range(N+1): A[i][i]=0 B[i][i]=0 #print(A) for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): A[a][b]=min(A[a][b],A[a][c]+A[c][b]) if A[a][b]<=L: B[a][b]=1 #print(A) for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): B[a][b]=min(B[a][b],B[a][c]+B[c][b]) #print(B) Q=int(eval(input())) for i in range(Q): s,t=list(map(int,input().split())) if B[s][t]==10**12: print((-1)) else: print((B[s][t]-1))
45
38
1,053
891
from scipy.sparse.csgraph import floyd_warshall N, M, L = list(map(int, input().split())) A = [[10**12 for i in range(N + 1)] for j in range(N + 1)] B = [[10**12 for i in range(N + 1)] for j in range(N + 1)] for i in range(M): a, b, c = list(map(int, input().split())) if c <= L: A[a][b] = c A[b][a] = c B[a][b] = 1 B[b][a] = 1 # print(A) A = floyd_warshall(A, directed=False) # print(A) for i in range(N + 1): for j in range(N + 1): if A[i][j] <= L: B[i][j] = 1 """for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): A[a][b]=min(A[a][b],A[a][c]+A[c][b]) if A[a][b]<=L: B[a][b]=1""" # print(B) B = floyd_warshall(B, directed=False) """for c in range(1,N+1): for a in range(1,N+1): for b in range(1,N+1): B[a][b]=min(B[a][b],B[a][c]+B[c][b])""" # print(B) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) if B[s][t] == 10**12: print((-1)) else: print((int(B[s][t] - 1)))
import sys input = sys.stdin.readline N, M, L = list(map(int, input().split())) A = [[10**12 for i in range(N + 1)] for j in range(N + 1)] B = [[10**12 for i in range(N + 1)] for j in range(N + 1)] for i in range(M): a, b, c = list(map(int, input().split())) if c <= L: A[a][b] = c A[b][a] = c B[a][b] = 1 B[b][a] = 1 for i in range(N + 1): A[i][i] = 0 B[i][i] = 0 # print(A) for c in range(1, N + 1): for a in range(1, N + 1): for b in range(1, N + 1): A[a][b] = min(A[a][b], A[a][c] + A[c][b]) if A[a][b] <= L: B[a][b] = 1 # print(A) for c in range(1, N + 1): for a in range(1, N + 1): for b in range(1, N + 1): B[a][b] = min(B[a][b], B[a][c] + B[c][b]) # print(B) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) if B[s][t] == 10**12: print((-1)) else: print((B[s][t] - 1))
false
15.555556
[ "-from scipy.sparse.csgraph import floyd_warshall", "+import sys", "+input = sys.stdin.readline", "+for i in range(N + 1):", "+ A[i][i] = 0", "+ B[i][i] = 0", "-A = floyd_warshall(A, directed=False)", "+for c in range(1, N + 1):", "+ for a in range(1, N + 1):", "+ for b in range(1, N + 1):", "+ A[a][b] = min(A[a][b], A[a][c] + A[c][b])", "+ if A[a][b] <= L:", "+ B[a][b] = 1", "-for i in range(N + 1):", "- for j in range(N + 1):", "- if A[i][j] <= L:", "- B[i][j] = 1", "-\"\"\"for c in range(1,N+1):", "- for a in range(1,N+1):", "- for b in range(1,N+1):", "- A[a][b]=min(A[a][b],A[a][c]+A[c][b])", "- if A[a][b]<=L:", "- B[a][b]=1\"\"\"", "-# print(B)", "-B = floyd_warshall(B, directed=False)", "-\"\"\"for c in range(1,N+1):", "- for a in range(1,N+1):", "- for b in range(1,N+1):", "- B[a][b]=min(B[a][b],B[a][c]+B[c][b])\"\"\"", "+for c in range(1, N + 1):", "+ for a in range(1, N + 1):", "+ for b in range(1, N + 1):", "+ B[a][b] = min(B[a][b], B[a][c] + B[c][b])", "- print((int(B[s][t] - 1)))", "+ print((B[s][t] - 1))" ]
false
0.809762
0.110436
7.332413
[ "s540856984", "s332890893" ]
u631277801
p03457
python
s605130879
s103394138
417
268
17,348
17,360
Accepted
Accepted
35.73
N = int(input()) TXY = [(0,0,0)] for i in range(N): TXY.append(tuple(map(int, input().split()))) def judge(N:int, TXY:tuple) -> bool: for i in range(N): delta_t = TXY[i+1][0] - TXY[i][0] delta_x = abs(TXY[i+1][1] - TXY[i][1]) delta_y = abs(TXY[i+1][2] - TXY[i][2]) if (delta_t%2 != (delta_x+delta_y)%2)\ or (delta_t < (delta_x+delta_y)): return False return True if judge(N,TXY): print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n = ni() txy = [(0,0,0)] for _ in range(n): txy.append(tuple(li())) exist = True for i in range(n): tp,xp,yp = txy[i] tn,xn,yn = txy[i+1] dt = tn-tp dx = xn-xp dy = yn-yp if abs(dx) + abs(dy) > dt: exist = False break if (dx+dy)%2 != dt%2: exist = False break if exist: print("Yes") else: print("No")
21
42
525
868
N = int(input()) TXY = [(0, 0, 0)] for i in range(N): TXY.append(tuple(map(int, input().split()))) def judge(N: int, TXY: tuple) -> bool: for i in range(N): delta_t = TXY[i + 1][0] - TXY[i][0] delta_x = abs(TXY[i + 1][1] - TXY[i][1]) delta_y = abs(TXY[i + 1][2] - TXY[i][2]) if (delta_t % 2 != (delta_x + delta_y) % 2) or (delta_t < (delta_x + delta_y)): return False return True if judge(N, TXY): print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n = ni() txy = [(0, 0, 0)] for _ in range(n): txy.append(tuple(li())) exist = True for i in range(n): tp, xp, yp = txy[i] tn, xn, yn = txy[i + 1] dt = tn - tp dx = xn - xp dy = yn - yp if abs(dx) + abs(dy) > dt: exist = False break if (dx + dy) % 2 != dt % 2: exist = False break if exist: print("Yes") else: print("No")
false
50
[ "-N = int(input())", "-TXY = [(0, 0, 0)]", "-for i in range(N):", "- TXY.append(tuple(map(int, input().split())))", "+import sys", "+", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**5)", "-def judge(N: int, TXY: tuple) -> bool:", "- for i in range(N):", "- delta_t = TXY[i + 1][0] - TXY[i][0]", "- delta_x = abs(TXY[i + 1][1] - TXY[i][1])", "- delta_y = abs(TXY[i + 1][2] - TXY[i][2])", "- if (delta_t % 2 != (delta_x + delta_y) % 2) or (delta_t < (delta_x + delta_y)):", "- return False", "- return True", "+def li():", "+ return list(map(int, stdin.readline().split()))", "-if judge(N, TXY):", "+def li_():", "+ return [int(x) - 1 for x in stdin.readline().split()]", "+", "+", "+def lf():", "+ return list(map(float, stdin.readline().split()))", "+", "+", "+def ls():", "+ return stdin.readline().split()", "+", "+", "+def ns():", "+ return stdin.readline().rstrip()", "+", "+", "+def lc():", "+ return list(ns())", "+", "+", "+def ni():", "+ return int(stdin.readline())", "+", "+", "+def nf():", "+ return float(stdin.readline())", "+", "+", "+n = ni()", "+txy = [(0, 0, 0)]", "+for _ in range(n):", "+ txy.append(tuple(li()))", "+exist = True", "+for i in range(n):", "+ tp, xp, yp = txy[i]", "+ tn, xn, yn = txy[i + 1]", "+ dt = tn - tp", "+ dx = xn - xp", "+ dy = yn - yp", "+ if abs(dx) + abs(dy) > dt:", "+ exist = False", "+ break", "+ if (dx + dy) % 2 != dt % 2:", "+ exist = False", "+ break", "+if exist:" ]
false
0.036986
0.037388
0.989262
[ "s605130879", "s103394138" ]
u729939940
p02802
python
s663897120
s823164852
352
139
4,596
4,596
Accepted
Accepted
60.51
N, M = list(map(int, input().split())) ac = [False] * N # index means p wa = [0] * N # index means p wa_cnt = 0 for i in range(M): p, s = list(map(str, input().split())) p = int(p) - 1 # index starts from 0 if ac[p] is False and s == "AC": wa_cnt += wa[p] ac[p] = True elif s == "WA": wa[p] += 1 print((ac.count(True), wa_cnt))
from sys import stdin,setrecursionlimit setrecursionlimit(10 ** 6) input = stdin.readline N, M = list(map(int, input().split())) ac = [False] * N # index means p wa = [0] * N # index means p wa_cnt = 0 for i in range(M): p, s = input().split() p = int(p) - 1 # index starts from 0 if ac[p] is False and s == "AC": wa_cnt += wa[p] ac[p] = True elif s == "WA": wa[p] += 1 print((ac.count(True), wa_cnt))
13
16
345
428
N, M = list(map(int, input().split())) ac = [False] * N # index means p wa = [0] * N # index means p wa_cnt = 0 for i in range(M): p, s = list(map(str, input().split())) p = int(p) - 1 # index starts from 0 if ac[p] is False and s == "AC": wa_cnt += wa[p] ac[p] = True elif s == "WA": wa[p] += 1 print((ac.count(True), wa_cnt))
from sys import stdin, setrecursionlimit setrecursionlimit(10**6) input = stdin.readline N, M = list(map(int, input().split())) ac = [False] * N # index means p wa = [0] * N # index means p wa_cnt = 0 for i in range(M): p, s = input().split() p = int(p) - 1 # index starts from 0 if ac[p] is False and s == "AC": wa_cnt += wa[p] ac[p] = True elif s == "WA": wa[p] += 1 print((ac.count(True), wa_cnt))
false
18.75
[ "+from sys import stdin, setrecursionlimit", "+", "+setrecursionlimit(10**6)", "+input = stdin.readline", "- p, s = list(map(str, input().split()))", "+ p, s = input().split()" ]
false
0.037531
0.073606
0.509893
[ "s663897120", "s823164852" ]
u546285759
p00292
python
s417624072
s231772358
60
30
7,708
7,712
Accepted
Accepted
50
n = int(eval(input())) for _ in range(n): K, P = list(map(int, input().split())) a = K - (K // P) * P print((P * (a == 0) + (a) * (a != 0)))
n = int(eval(input())) for _ in range(n): K, P = list(map(int, input().split())) a = K % P print((P * (a == 0) + (a) * (a != 0)))
5
5
142
131
n = int(eval(input())) for _ in range(n): K, P = list(map(int, input().split())) a = K - (K // P) * P print((P * (a == 0) + (a) * (a != 0)))
n = int(eval(input())) for _ in range(n): K, P = list(map(int, input().split())) a = K % P print((P * (a == 0) + (a) * (a != 0)))
false
0
[ "- a = K - (K // P) * P", "+ a = K % P" ]
false
0.03963
0.037504
1.056693
[ "s417624072", "s231772358" ]
u117053676
p02390
python
s125645853
s814170833
30
20
7,656
5,588
Accepted
Accepted
33.33
in_sec = int(eval(input())) sec = in_sec % 60 min = (in_sec // 60) % 60 hour = (in_sec // 3600 ) print(("{}:{}:{}".format(hour,min,sec)))
time = int(input()) h = int(time/ 3600) m = int((time%3600)/60) s = int((time%3600)%60) print(h,m,s,sep=':')
7
7
137
117
in_sec = int(eval(input())) sec = in_sec % 60 min = (in_sec // 60) % 60 hour = in_sec // 3600 print(("{}:{}:{}".format(hour, min, sec)))
time = int(input()) h = int(time / 3600) m = int((time % 3600) / 60) s = int((time % 3600) % 60) print(h, m, s, sep=":")
false
0
[ "-in_sec = int(eval(input()))", "-sec = in_sec % 60", "-min = (in_sec // 60) % 60", "-hour = in_sec // 3600", "-print((\"{}:{}:{}\".format(hour, min, sec)))", "+time = int(input())", "+h = int(time / 3600)", "+m = int((time % 3600) / 60)", "+s = int((time % 3600) % 60)", "+print(h, m, s, sep=\":\")" ]
false
0.035998
0.036388
0.98928
[ "s125645853", "s814170833" ]
u183422236
p03775
python
s262966266
s958138288
437
62
68,388
63,496
Accepted
Accepted
85.81
from math import sqrt n = int(eval(input())) m = int(sqrt(n)) lst = [] for i in range(2, m + 1): if n % i == 0: j = 0 while True: if n % i == 0: n //= i j += 1 else: for k in range(j): lst.append(i) break lst.append(n) ans = float("INF") for i in range(2 ** len(lst)): num1 = 1 num2 = 1 for j in range(len(lst)): if (i >> j) & 1: num1 *= lst[j] else: num2 *= lst[j] ans = min(ans, max(len(str(num1)), len(str(num2)))) print(ans)
n = int(eval(input())) i = 1 ans = n lst = [] while i * i <= n: if n % i == 0: ans = n // i i += 1 print((len(str(ans))))
32
10
671
140
from math import sqrt n = int(eval(input())) m = int(sqrt(n)) lst = [] for i in range(2, m + 1): if n % i == 0: j = 0 while True: if n % i == 0: n //= i j += 1 else: for k in range(j): lst.append(i) break lst.append(n) ans = float("INF") for i in range(2 ** len(lst)): num1 = 1 num2 = 1 for j in range(len(lst)): if (i >> j) & 1: num1 *= lst[j] else: num2 *= lst[j] ans = min(ans, max(len(str(num1)), len(str(num2)))) print(ans)
n = int(eval(input())) i = 1 ans = n lst = [] while i * i <= n: if n % i == 0: ans = n // i i += 1 print((len(str(ans))))
false
68.75
[ "-from math import sqrt", "-", "-m = int(sqrt(n))", "+i = 1", "+ans = n", "-for i in range(2, m + 1):", "+while i * i <= n:", "- j = 0", "- while True:", "- if n % i == 0:", "- n //= i", "- j += 1", "- else:", "- for k in range(j):", "- lst.append(i)", "- break", "-lst.append(n)", "-ans = float(\"INF\")", "-for i in range(2 ** len(lst)):", "- num1 = 1", "- num2 = 1", "- for j in range(len(lst)):", "- if (i >> j) & 1:", "- num1 *= lst[j]", "- else:", "- num2 *= lst[j]", "- ans = min(ans, max(len(str(num1)), len(str(num2))))", "-print(ans)", "+ ans = n // i", "+ i += 1", "+print((len(str(ans))))" ]
false
0.041288
0.059338
0.695811
[ "s262966266", "s958138288" ]
u562935282
p03254
python
s673000316
s917622184
19
17
3,316
3,060
Accepted
Accepted
10.53
N, X = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(a) ans = 0 ttl = sum(a) if ttl < X: ans = N - 1 elif ttl == X: ans = N else: s = 0 for ax in a: if s + ax <= X: s += ax ans += 1 else: break print(ans)
N, x = list(map(int, input().split())) a = list(map(int, input().split())) a = list(sorted(a)) X = x ans = 0 for i, aa in enumerate(a, 0): if X >= aa: if i == N - 1: if X == aa: ans += 1 else: X -= aa ans += 1 else: break print(ans)
20
17
320
328
N, X = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(a) ans = 0 ttl = sum(a) if ttl < X: ans = N - 1 elif ttl == X: ans = N else: s = 0 for ax in a: if s + ax <= X: s += ax ans += 1 else: break print(ans)
N, x = list(map(int, input().split())) a = list(map(int, input().split())) a = list(sorted(a)) X = x ans = 0 for i, aa in enumerate(a, 0): if X >= aa: if i == N - 1: if X == aa: ans += 1 else: X -= aa ans += 1 else: break print(ans)
false
15
[ "-N, X = list(map(int, input().split()))", "+N, x = list(map(int, input().split()))", "-a = sorted(a)", "+a = list(sorted(a))", "+X = x", "-ttl = sum(a)", "-if ttl < X:", "- ans = N - 1", "-elif ttl == X:", "- ans = N", "-else:", "- s = 0", "- for ax in a:", "- if s + ax <= X:", "- s += ax", "+for i, aa in enumerate(a, 0):", "+ if X >= aa:", "+ if i == N - 1:", "+ if X == aa:", "+ ans += 1", "+ else:", "+ X -= aa", "- else:", "- break", "+ else:", "+ break" ]
false
0.049004
0.050951
0.961788
[ "s673000316", "s917622184" ]
u337626942
p02597
python
s181531010
s807113898
76
70
9,484
9,476
Accepted
Accepted
7.89
n=int(eval(input())) c=eval(input()) r=0 w=0 for i in range(n): if c[i]=="R": r+=1 else: w+=1 umeru=0 for j in range(r): if c[j]=="W": umeru+=1 if r>=umeru: print(umeru) else: print((umeru + (r-umeru)))
n=int(eval(input())) c=eval(input()) r=0 w=0 for i in range(n): if c[i]=="R": r+=1 else: w+=1 delete=0 for j in range(r): if c[j]=="W": delete+=1 if r>=delete: print(delete) else: print((delete + (r-delete)))
22
22
258
264
n = int(eval(input())) c = eval(input()) r = 0 w = 0 for i in range(n): if c[i] == "R": r += 1 else: w += 1 umeru = 0 for j in range(r): if c[j] == "W": umeru += 1 if r >= umeru: print(umeru) else: print((umeru + (r - umeru)))
n = int(eval(input())) c = eval(input()) r = 0 w = 0 for i in range(n): if c[i] == "R": r += 1 else: w += 1 delete = 0 for j in range(r): if c[j] == "W": delete += 1 if r >= delete: print(delete) else: print((delete + (r - delete)))
false
0
[ "-umeru = 0", "+delete = 0", "- umeru += 1", "-if r >= umeru:", "- print(umeru)", "+ delete += 1", "+if r >= delete:", "+ print(delete)", "- print((umeru + (r - umeru)))", "+ print((delete + (r - delete)))" ]
false
0.072645
0.046216
1.571849
[ "s181531010", "s807113898" ]
u069838609
p03111
python
s917141958
s314462221
515
316
69,904
48,856
Accepted
Accepted
38.64
import sys from itertools import combinations fin = sys.stdin.readline N, A, B, C = [int(elem) for elem in fin().split()] l_list = sorted([int(fin()) for _ in range(N)], reverse=True) min_mp = float('inf') for num_conc_A in range(1, N - 1): # mp = 0 rest_indices = set(range(N)) for A_indices in combinations(rest_indices, num_conc_A): mp_A = 10 * (num_conc_A - 1) + abs(sum(l_list[i] for i in A_indices) - A) rest_indices -= set(A_indices) for num_conc_B in range(1, N - num_conc_A): for B_indices in combinations(rest_indices, num_conc_B): mp_B = 10 * (num_conc_B - 1) + abs(sum(l_list[i] for i in B_indices) - B) rest_indices -= set(B_indices) for num_conc_C in range(1, N - num_conc_A - num_conc_B + 1): for C_indices in combinations(rest_indices, num_conc_C): mp_C = 10 * (num_conc_C - 1) + abs(sum(l_list[i] for i in C_indices) - C) min_mp = min(min_mp, mp_A + mp_B + mp_C) rest_indices.update(set(B_indices)) rest_indices.update(set(A_indices)) print(min_mp)
import sys from itertools import combinations, product fin = sys.stdin.readline N, A, B, C = [int(elem) for elem in fin().split()] l_list = [int(fin()) for _ in range(N)] min_mp = float('inf') for flags in product(list(range(4)), repeat=N): powers = [0] * 3 num_items = [0] * 3 for l, flag in zip(l_list, flags): if flag == 3: continue powers[flag] += l num_items[flag] += 1 if not all(powers): continue mp = sum( abs(power - necessary_power) for power, necessary_power in zip(powers, (A, B, C)) ) + 10 * (sum(num_items) - 3) min_mp = min(mp, min_mp) print(min_mp)
26
25
1,181
678
import sys from itertools import combinations fin = sys.stdin.readline N, A, B, C = [int(elem) for elem in fin().split()] l_list = sorted([int(fin()) for _ in range(N)], reverse=True) min_mp = float("inf") for num_conc_A in range(1, N - 1): # mp = 0 rest_indices = set(range(N)) for A_indices in combinations(rest_indices, num_conc_A): mp_A = 10 * (num_conc_A - 1) + abs(sum(l_list[i] for i in A_indices) - A) rest_indices -= set(A_indices) for num_conc_B in range(1, N - num_conc_A): for B_indices in combinations(rest_indices, num_conc_B): mp_B = 10 * (num_conc_B - 1) + abs( sum(l_list[i] for i in B_indices) - B ) rest_indices -= set(B_indices) for num_conc_C in range(1, N - num_conc_A - num_conc_B + 1): for C_indices in combinations(rest_indices, num_conc_C): mp_C = 10 * (num_conc_C - 1) + abs( sum(l_list[i] for i in C_indices) - C ) min_mp = min(min_mp, mp_A + mp_B + mp_C) rest_indices.update(set(B_indices)) rest_indices.update(set(A_indices)) print(min_mp)
import sys from itertools import combinations, product fin = sys.stdin.readline N, A, B, C = [int(elem) for elem in fin().split()] l_list = [int(fin()) for _ in range(N)] min_mp = float("inf") for flags in product(list(range(4)), repeat=N): powers = [0] * 3 num_items = [0] * 3 for l, flag in zip(l_list, flags): if flag == 3: continue powers[flag] += l num_items[flag] += 1 if not all(powers): continue mp = sum( abs(power - necessary_power) for power, necessary_power in zip(powers, (A, B, C)) ) + 10 * (sum(num_items) - 3) min_mp = min(mp, min_mp) print(min_mp)
false
3.846154
[ "-from itertools import combinations", "+from itertools import combinations, product", "-l_list = sorted([int(fin()) for _ in range(N)], reverse=True)", "+l_list = [int(fin()) for _ in range(N)]", "-for num_conc_A in range(1, N - 1):", "- # mp = 0", "- rest_indices = set(range(N))", "- for A_indices in combinations(rest_indices, num_conc_A):", "- mp_A = 10 * (num_conc_A - 1) + abs(sum(l_list[i] for i in A_indices) - A)", "- rest_indices -= set(A_indices)", "- for num_conc_B in range(1, N - num_conc_A):", "- for B_indices in combinations(rest_indices, num_conc_B):", "- mp_B = 10 * (num_conc_B - 1) + abs(", "- sum(l_list[i] for i in B_indices) - B", "- )", "- rest_indices -= set(B_indices)", "- for num_conc_C in range(1, N - num_conc_A - num_conc_B + 1):", "- for C_indices in combinations(rest_indices, num_conc_C):", "- mp_C = 10 * (num_conc_C - 1) + abs(", "- sum(l_list[i] for i in C_indices) - C", "- )", "- min_mp = min(min_mp, mp_A + mp_B + mp_C)", "- rest_indices.update(set(B_indices))", "- rest_indices.update(set(A_indices))", "+for flags in product(list(range(4)), repeat=N):", "+ powers = [0] * 3", "+ num_items = [0] * 3", "+ for l, flag in zip(l_list, flags):", "+ if flag == 3:", "+ continue", "+ powers[flag] += l", "+ num_items[flag] += 1", "+ if not all(powers):", "+ continue", "+ mp = sum(", "+ abs(power - necessary_power)", "+ for power, necessary_power in zip(powers, (A, B, C))", "+ ) + 10 * (sum(num_items) - 3)", "+ min_mp = min(mp, min_mp)" ]
false
0.316911
0.593979
0.533538
[ "s917141958", "s314462221" ]
u314050667
p02861
python
s661871171
s250447570
494
441
3,316
3,064
Accepted
Accepted
10.73
N = int(eval(input())) x,y = [],[] for _ in range(N): xt, yt = list(map(int, input().split())) x.append(xt) y.append(yt) def solve(ite): a = 0 for i in range(len(ite)-1): a += ((x[ite[i]] - x[ite[i+1]])**2 + (y[ite[i]] - y[ite[i+1]])**2) ** (1/2) return a def next_permutation(n, flg, perm): S = [] if flg.count(0) == 0: return solve(perm) a = 0 for i in range(n): if flg[i] != 0: continue flg[i] = 1 perm.append(i) a += next_permutation(n, flg, perm) flg[i] = 0 perm.pop() return a flg = [0] * N perm = [] A = next_permutation(N,flg,perm) for i in range(1,N+1): A /= i print(A)
import itertools N = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(N)] ans = 0 for trans in itertools.permutations(list(range(N))): distance = 0 for i in range(1,N): ind_2, ind_1 = trans[i], trans[i-1] x2,y2 = XY[ind_2] x1,y1 = XY[ind_1] distance += ((x2-x1)**2 + (y2-y1)**2)**(1/2) ans += distance for i in range(1,N+1): ans /= i print(ans)
44
21
654
394
N = int(eval(input())) x, y = [], [] for _ in range(N): xt, yt = list(map(int, input().split())) x.append(xt) y.append(yt) def solve(ite): a = 0 for i in range(len(ite) - 1): a += ((x[ite[i]] - x[ite[i + 1]]) ** 2 + (y[ite[i]] - y[ite[i + 1]]) ** 2) ** ( 1 / 2 ) return a def next_permutation(n, flg, perm): S = [] if flg.count(0) == 0: return solve(perm) a = 0 for i in range(n): if flg[i] != 0: continue flg[i] = 1 perm.append(i) a += next_permutation(n, flg, perm) flg[i] = 0 perm.pop() return a flg = [0] * N perm = [] A = next_permutation(N, flg, perm) for i in range(1, N + 1): A /= i print(A)
import itertools N = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(N)] ans = 0 for trans in itertools.permutations(list(range(N))): distance = 0 for i in range(1, N): ind_2, ind_1 = trans[i], trans[i - 1] x2, y2 = XY[ind_2] x1, y1 = XY[ind_1] distance += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** (1 / 2) ans += distance for i in range(1, N + 1): ans /= i print(ans)
false
52.272727
[ "+import itertools", "+", "-x, y = [], []", "-for _ in range(N):", "- xt, yt = list(map(int, input().split()))", "- x.append(xt)", "- y.append(yt)", "-", "-", "-def solve(ite):", "- a = 0", "- for i in range(len(ite) - 1):", "- a += ((x[ite[i]] - x[ite[i + 1]]) ** 2 + (y[ite[i]] - y[ite[i + 1]]) ** 2) ** (", "- 1 / 2", "- )", "- return a", "-", "-", "-def next_permutation(n, flg, perm):", "- S = []", "- if flg.count(0) == 0:", "- return solve(perm)", "- a = 0", "- for i in range(n):", "- if flg[i] != 0:", "- continue", "- flg[i] = 1", "- perm.append(i)", "- a += next_permutation(n, flg, perm)", "- flg[i] = 0", "- perm.pop()", "- return a", "-", "-", "-flg = [0] * N", "-perm = []", "-A = next_permutation(N, flg, perm)", "+XY = [list(map(int, input().split())) for _ in range(N)]", "+ans = 0", "+for trans in itertools.permutations(list(range(N))):", "+ distance = 0", "+ for i in range(1, N):", "+ ind_2, ind_1 = trans[i], trans[i - 1]", "+ x2, y2 = XY[ind_2]", "+ x1, y1 = XY[ind_1]", "+ distance += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** (1 / 2)", "+ ans += distance", "- A /= i", "-print(A)", "+ ans /= i", "+print(ans)" ]
false
0.111336
0.04225
2.635193
[ "s661871171", "s250447570" ]
u984276646
p03044
python
s083822168
s313205457
902
596
84,560
63,132
Accepted
Accepted
33.92
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) L = [-1 for i in range(N)] flg = [0 for i in range(N)] M = [[] for i in range(N)] for i in range(N-1): u, v, w = list(map(int, input().split())) M[u-1].append([v-1, w%2]) M[v-1].append([u-1, w%2]) L[0] = 0 def dist(m, d): L[m] = d % 2 for i in M[m]: if L[i[0]] == -1: dist(i[0], i[1] + d) dist(0, 0) for i in range(N): print((L[i]))
N = int(eval(input())) D = {i: [] for i in range(N)} distD = {} for i in range(N-1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 D[u].append(v) D[v].append(u) distD[u*N+v], distD[v*N+u] = w, w clr = [-1 for _ in range(N)] clr[0] = 0 s = [0] pnt = 0 cnt = 1 while pnt < cnt: n = cnt for i in range(pnt, cnt): L = D[s[i]] for j in L: if clr[j] == -1: clr[j] = (clr[s[i]] + distD[s[i]*N+j]) % 2 s.append(j) cnt += 1 pnt = n for i in range(N): print((clr[i]))
19
27
421
595
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) L = [-1 for i in range(N)] flg = [0 for i in range(N)] M = [[] for i in range(N)] for i in range(N - 1): u, v, w = list(map(int, input().split())) M[u - 1].append([v - 1, w % 2]) M[v - 1].append([u - 1, w % 2]) L[0] = 0 def dist(m, d): L[m] = d % 2 for i in M[m]: if L[i[0]] == -1: dist(i[0], i[1] + d) dist(0, 0) for i in range(N): print((L[i]))
N = int(eval(input())) D = {i: [] for i in range(N)} distD = {} for i in range(N - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 D[u].append(v) D[v].append(u) distD[u * N + v], distD[v * N + u] = w, w clr = [-1 for _ in range(N)] clr[0] = 0 s = [0] pnt = 0 cnt = 1 while pnt < cnt: n = cnt for i in range(pnt, cnt): L = D[s[i]] for j in L: if clr[j] == -1: clr[j] = (clr[s[i]] + distD[s[i] * N + j]) % 2 s.append(j) cnt += 1 pnt = n for i in range(N): print((clr[i]))
false
29.62963
[ "-import sys", "-", "-sys.setrecursionlimit(10**7)", "-L = [-1 for i in range(N)]", "-flg = [0 for i in range(N)]", "-M = [[] for i in range(N)]", "+D = {i: [] for i in range(N)}", "+distD = {}", "- M[u - 1].append([v - 1, w % 2])", "- M[v - 1].append([u - 1, w % 2])", "-L[0] = 0", "-", "-", "-def dist(m, d):", "- L[m] = d % 2", "- for i in M[m]:", "- if L[i[0]] == -1:", "- dist(i[0], i[1] + d)", "-", "-", "-dist(0, 0)", "+ u -= 1", "+ v -= 1", "+ D[u].append(v)", "+ D[v].append(u)", "+ distD[u * N + v], distD[v * N + u] = w, w", "+clr = [-1 for _ in range(N)]", "+clr[0] = 0", "+s = [0]", "+pnt = 0", "+cnt = 1", "+while pnt < cnt:", "+ n = cnt", "+ for i in range(pnt, cnt):", "+ L = D[s[i]]", "+ for j in L:", "+ if clr[j] == -1:", "+ clr[j] = (clr[s[i]] + distD[s[i] * N + j]) % 2", "+ s.append(j)", "+ cnt += 1", "+ pnt = n", "- print((L[i]))", "+ print((clr[i]))" ]
false
0.037446
0.038657
0.968686
[ "s083822168", "s313205457" ]
u408325839
p03045
python
s005158374
s111450410
479
435
109,616
13,792
Accepted
Accepted
9.19
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) paths = [[] for _ in range(N)] for _ in range(M): a, b, z = list(map(int, input().split())) paths[a-1].append(b-1) paths[b-1].append(a-1) visited = [False] * N def dfs(node, prev): if visited[node]: return visited[node] = True for n in paths[node]: if n != prev: dfs(n, node) count = 0 for i in range(N): if visited[i] == False: count += 1 dfs(i,-1) print(count)
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) class Union_Find: def __init__(self,n): self.parent = [i for i in range(n)] self.rank = [1 for i in range(n)] def find(self,x): if self.parent[x] == x: return x else: return self.find(self.parent[x]) def unite(self, x, y): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] == self.rank[py]: self.parent[py] = px self.rank[px] += 1 elif self.rank[px] > self.rank[py]: self.parent[py] = px else: self.parent[px] = py uftree = Union_Find(N+1) for i in range(M): x, y, _ = list(map(int, input().split())) uftree.unite(x, y) result = 0 for i in range(1, N+1): if uftree.find(i) == i: result += 1 print(result)
27
42
533
990
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) paths = [[] for _ in range(N)] for _ in range(M): a, b, z = list(map(int, input().split())) paths[a - 1].append(b - 1) paths[b - 1].append(a - 1) visited = [False] * N def dfs(node, prev): if visited[node]: return visited[node] = True for n in paths[node]: if n != prev: dfs(n, node) count = 0 for i in range(N): if visited[i] == False: count += 1 dfs(i, -1) print(count)
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) class Union_Find: def __init__(self, n): self.parent = [i for i in range(n)] self.rank = [1 for i in range(n)] def find(self, x): if self.parent[x] == x: return x else: return self.find(self.parent[x]) def unite(self, x, y): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] == self.rank[py]: self.parent[py] = px self.rank[px] += 1 elif self.rank[px] > self.rank[py]: self.parent[py] = px else: self.parent[px] = py uftree = Union_Find(N + 1) for i in range(M): x, y, _ = list(map(int, input().split())) uftree.unite(x, y) result = 0 for i in range(1, N + 1): if uftree.find(i) == i: result += 1 print(result)
false
35.714286
[ "-paths = [[] for _ in range(N)]", "-for _ in range(M):", "- a, b, z = list(map(int, input().split()))", "- paths[a - 1].append(b - 1)", "- paths[b - 1].append(a - 1)", "-visited = [False] * N", "-def dfs(node, prev):", "- if visited[node]:", "- return", "- visited[node] = True", "- for n in paths[node]:", "- if n != prev:", "- dfs(n, node)", "+class Union_Find:", "+ def __init__(self, n):", "+ self.parent = [i for i in range(n)]", "+ self.rank = [1 for i in range(n)]", "+", "+ def find(self, x):", "+ if self.parent[x] == x:", "+ return x", "+ else:", "+ return self.find(self.parent[x])", "+", "+ def unite(self, x, y):", "+ px = self.find(x)", "+ py = self.find(y)", "+ if px == py:", "+ return", "+ else:", "+ if self.rank[px] == self.rank[py]:", "+ self.parent[py] = px", "+ self.rank[px] += 1", "+ elif self.rank[px] > self.rank[py]:", "+ self.parent[py] = px", "+ else:", "+ self.parent[px] = py", "-count = 0", "-for i in range(N):", "- if visited[i] == False:", "- count += 1", "- dfs(i, -1)", "-print(count)", "+uftree = Union_Find(N + 1)", "+for i in range(M):", "+ x, y, _ = list(map(int, input().split()))", "+ uftree.unite(x, y)", "+result = 0", "+for i in range(1, N + 1):", "+ if uftree.find(i) == i:", "+ result += 1", "+print(result)" ]
false
0.050777
0.054686
0.928531
[ "s005158374", "s111450410" ]
u102461423
p04006
python
s130134121
s617792596
198
162
14,532
89,396
Accepted
Accepted
18.18
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・変色の回数を決め打つ ・どの色として捕獲しておくべきだったかが決まる ・左とのminをとることで遷移 """ import numpy as np N,X = list(map(int,readline().split())) A = np.array(read().split(),np.int64) INF = 10 ** 18 answer = INF for change in range(N+100): x = A.sum() + change * X if answer > x: answer = x x = min(A[0],A[-1]) A[1:] = np.minimum(A[:-1],A[1:]) A[0] = x print(answer)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, X = list(map(int, readline().split())) A = np.array(read().split(), np.int64) INF = 10**18 dp = np.full((N, N + N), INF, np.int64) dp[0] = np.concatenate((A, A)) for n in range(1, N): dp[n, 1:] = np.minimum(dp[n - 1, 1:], dp[n - 1, :-1]) dp = dp[:, N:] x = dp.sum(axis=1) + X * np.arange(N) print((x.min()))
27
19
508
463
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・変色の回数を決め打つ ・どの色として捕獲しておくべきだったかが決まる ・左とのminをとることで遷移 """ import numpy as np N, X = list(map(int, readline().split())) A = np.array(read().split(), np.int64) INF = 10**18 answer = INF for change in range(N + 100): x = A.sum() + change * X if answer > x: answer = x x = min(A[0], A[-1]) A[1:] = np.minimum(A[:-1], A[1:]) A[0] = x print(answer)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, X = list(map(int, readline().split())) A = np.array(read().split(), np.int64) INF = 10**18 dp = np.full((N, N + N), INF, np.int64) dp[0] = np.concatenate((A, A)) for n in range(1, N): dp[n, 1:] = np.minimum(dp[n - 1, 1:], dp[n - 1, :-1]) dp = dp[:, N:] x = dp.sum(axis=1) + X * np.arange(N) print((x.min()))
false
29.62963
[ "+import numpy as np", "-\"\"\"", "-・変色の回数を決め打つ", "-・どの色として捕獲しておくべきだったかが決まる", "-・左とのminをとることで遷移", "-\"\"\"", "-import numpy as np", "-", "-answer = INF", "-for change in range(N + 100):", "- x = A.sum() + change * X", "- if answer > x:", "- answer = x", "- x = min(A[0], A[-1])", "- A[1:] = np.minimum(A[:-1], A[1:])", "- A[0] = x", "-print(answer)", "+dp = np.full((N, N + N), INF, np.int64)", "+dp[0] = np.concatenate((A, A))", "+for n in range(1, N):", "+ dp[n, 1:] = np.minimum(dp[n - 1, 1:], dp[n - 1, :-1])", "+dp = dp[:, N:]", "+x = dp.sum(axis=1) + X * np.arange(N)", "+print((x.min()))" ]
false
0.324604
0.773438
0.419689
[ "s130134121", "s617792596" ]
u948911484
p03557
python
s803333964
s835220475
371
248
23,360
29,288
Accepted
Accepted
33.15
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() memo = [0]*(n+1) for i in range(n): memo[bisect.bisect_left(b,c[i])] += 1 for i in range(n-1,-1,-1): memo[i] += memo[i+1] for i in range(n-1,-1,-1): memo[i] += memo[i+1] memo = memo[1:]+[0] ans = 0 for i in range(n): ans += memo[bisect.bisect_right(b,a[i])] print(ans)
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(n): t = b[i] ci = bisect.bisect_right(c,t) ai = bisect.bisect_left(a,t) ans += ai*(n-ci) print(ans)
21
15
468
316
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() memo = [0] * (n + 1) for i in range(n): memo[bisect.bisect_left(b, c[i])] += 1 for i in range(n - 1, -1, -1): memo[i] += memo[i + 1] for i in range(n - 1, -1, -1): memo[i] += memo[i + 1] memo = memo[1:] + [0] ans = 0 for i in range(n): ans += memo[bisect.bisect_right(b, a[i])] print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(n): t = b[i] ci = bisect.bisect_right(c, t) ai = bisect.bisect_left(a, t) ans += ai * (n - ci) print(ans)
false
28.571429
[ "-memo = [0] * (n + 1)", "-for i in range(n):", "- memo[bisect.bisect_left(b, c[i])] += 1", "-for i in range(n - 1, -1, -1):", "- memo[i] += memo[i + 1]", "-for i in range(n - 1, -1, -1):", "- memo[i] += memo[i + 1]", "-memo = memo[1:] + [0]", "- ans += memo[bisect.bisect_right(b, a[i])]", "+ t = b[i]", "+ ci = bisect.bisect_right(c, t)", "+ ai = bisect.bisect_left(a, t)", "+ ans += ai * (n - ci)" ]
false
0.048482
0.048264
1.004497
[ "s803333964", "s835220475" ]
u592547545
p02850
python
s961163185
s609850139
443
386
35,336
35,468
Accepted
Accepted
12.87
from collections import deque def readinput(): n=int(eval(input())) nList=[] for _ in range(n+1): nList.append([]) edges=[] for _ in range(n-1): a,b=list(map(int,input().split())) edges.append((a,b)) nList[a].append(b) nList[b].append(a) return n,nList,edges def bfs(s,nList): #print(nList) WHITE=0 GRAY=1 BLACK=2 status=[WHITE]*(n+1) parent=[0]*(n+1) color=[0]*(n+1) maxcolor=0 Q=deque([]) Q.append(s) while(len(Q)>0): u=Q.popleft() usedcolor=color[u] col=1 for t in nList[u]: if status[t]==WHITE: status[t]=GRAY parent[t]=u if col==usedcolor: col+=1 color[t]=col Q.append(t) col+=1 maxcolor=max(maxcolor,col-1) status[u]=BLACK #print(u,usedcolor) return color, maxcolor def main(n,nList,edges): color, maxcolor=bfs(1,nList) print(maxcolor) for a,b in edges: print((color[b])) if __name__=='__main__': n,nList,edges=readinput() main(n,nList,edges)
from collections import deque def readinput(): n=int(eval(input())) nList=[] for _ in range(n+1): nList.append([]) edges=[] for _ in range(n-1): a,b=list(map(int,input().split())) edges.append((a,b)) nList[a].append(b) nList[b].append(a) return n,nList,edges def bfs(s,nList): #print(nList) WHITE=0 GRAY=1 BLACK=2 status=[WHITE]*(n+1) parent=[0]*(n+1) color=[0]*(n+1) maxcolor=0 Q=deque([]) Q.append(s) while(len(Q)>0): u=Q.popleft() usedcolor=color[u] col=1 for t in nList[u]: if status[t]==WHITE: status[t]=GRAY parent[t]=u if col==usedcolor: col+=1 color[t]=col Q.append(t) col+=1 maxcolor=max(maxcolor,col-1) status[u]=BLACK #print(u,usedcolor) return color, maxcolor def main(n,nList,edges): color, maxcolor=bfs(1,nList) print(maxcolor) for a,b in edges: print((color[b])) if __name__=='__main__': n,nList,edges=readinput() main(n,nList,edges)
53
53
1,215
1,223
from collections import deque def readinput(): n = int(eval(input())) nList = [] for _ in range(n + 1): nList.append([]) edges = [] for _ in range(n - 1): a, b = list(map(int, input().split())) edges.append((a, b)) nList[a].append(b) nList[b].append(a) return n, nList, edges def bfs(s, nList): # print(nList) WHITE = 0 GRAY = 1 BLACK = 2 status = [WHITE] * (n + 1) parent = [0] * (n + 1) color = [0] * (n + 1) maxcolor = 0 Q = deque([]) Q.append(s) while len(Q) > 0: u = Q.popleft() usedcolor = color[u] col = 1 for t in nList[u]: if status[t] == WHITE: status[t] = GRAY parent[t] = u if col == usedcolor: col += 1 color[t] = col Q.append(t) col += 1 maxcolor = max(maxcolor, col - 1) status[u] = BLACK # print(u,usedcolor) return color, maxcolor def main(n, nList, edges): color, maxcolor = bfs(1, nList) print(maxcolor) for a, b in edges: print((color[b])) if __name__ == "__main__": n, nList, edges = readinput() main(n, nList, edges)
from collections import deque def readinput(): n = int(eval(input())) nList = [] for _ in range(n + 1): nList.append([]) edges = [] for _ in range(n - 1): a, b = list(map(int, input().split())) edges.append((a, b)) nList[a].append(b) nList[b].append(a) return n, nList, edges def bfs(s, nList): # print(nList) WHITE = 0 GRAY = 1 BLACK = 2 status = [WHITE] * (n + 1) parent = [0] * (n + 1) color = [0] * (n + 1) maxcolor = 0 Q = deque([]) Q.append(s) while len(Q) > 0: u = Q.popleft() usedcolor = color[u] col = 1 for t in nList[u]: if status[t] == WHITE: status[t] = GRAY parent[t] = u if col == usedcolor: col += 1 color[t] = col Q.append(t) col += 1 maxcolor = max(maxcolor, col - 1) status[u] = BLACK # print(u,usedcolor) return color, maxcolor def main(n, nList, edges): color, maxcolor = bfs(1, nList) print(maxcolor) for a, b in edges: print((color[b])) if __name__ == "__main__": n, nList, edges = readinput() main(n, nList, edges)
false
0
[ "- maxcolor = max(maxcolor, col - 1)", "+ maxcolor = max(maxcolor, col - 1)" ]
false
0.048395
0.098572
0.49096
[ "s961163185", "s609850139" ]
u194225526
p02730
python
s305675928
s716816566
19
17
3,060
2,940
Accepted
Accepted
10.53
# 入力 s = eval(input()) # 処理 leftLen = len(s) // 2 # 文字列の長さの半分 left = s[:leftLen] # sの左半分 # leftの回文チェック leftLenHalf = leftLen // 2 isPalindromeLeft = True for i in range(0, leftLenHalf): if left[i] != left[leftLen - i - 1]: isPalindromeLeft = False # 全体の回文チェック right = s[leftLen * -1:] # sの右半分 isPalindrome = isPalindromeLeft and left == right # 結果 result = "Yes" if isPalindrome else "No" # 出力 print(result)
# 入力 s = eval(input()) # 処理 leftLen = len(s) // 2 # 文字列の長さの半分 left = s[:leftLen] # sの左半分 # leftの回文チェック leftReverse = left[::-1] isPalindromeLeft = left == leftReverse; # 全体の回文チェック right = s[leftLen * -1:] # sの右半分 isPalindrome = isPalindromeLeft and (left == right) # 結果 result = "Yes" if isPalindrome else "No" # 出力 print(result)
23
20
432
348
# 入力 s = eval(input()) # 処理 leftLen = len(s) // 2 # 文字列の長さの半分 left = s[:leftLen] # sの左半分 # leftの回文チェック leftLenHalf = leftLen // 2 isPalindromeLeft = True for i in range(0, leftLenHalf): if left[i] != left[leftLen - i - 1]: isPalindromeLeft = False # 全体の回文チェック right = s[leftLen * -1 :] # sの右半分 isPalindrome = isPalindromeLeft and left == right # 結果 result = "Yes" if isPalindrome else "No" # 出力 print(result)
# 入力 s = eval(input()) # 処理 leftLen = len(s) // 2 # 文字列の長さの半分 left = s[:leftLen] # sの左半分 # leftの回文チェック leftReverse = left[::-1] isPalindromeLeft = left == leftReverse # 全体の回文チェック right = s[leftLen * -1 :] # sの右半分 isPalindrome = isPalindromeLeft and (left == right) # 結果 result = "Yes" if isPalindrome else "No" # 出力 print(result)
false
13.043478
[ "-leftLenHalf = leftLen // 2", "-isPalindromeLeft = True", "-for i in range(0, leftLenHalf):", "- if left[i] != left[leftLen - i - 1]:", "- isPalindromeLeft = False", "+leftReverse = left[::-1]", "+isPalindromeLeft = left == leftReverse", "-isPalindrome = isPalindromeLeft and left == right", "+isPalindrome = isPalindromeLeft and (left == right)" ]
false
0.069687
0.008127
8.57435
[ "s305675928", "s716816566" ]
u983918956
p03043
python
s293496798
s965364035
77
56
3,060
2,940
Accepted
Accepted
27.27
from math import log2, ceil N,K = list(map(int,input().split())) ans = 0 def cal(n): l = ceil(log2(K/n)) if n >= K: return 1/N return pow(2,-l)/N for i in range(1,N+1): ans += cal(i) print(ans)
N,K = list(map(int,input().split())) ans = 0 for i in range(1,N+1): l = 0 while i < K: i *= 2 l += 1 ans += (1/N)*pow(2,-l) print(ans)
16
12
231
170
from math import log2, ceil N, K = list(map(int, input().split())) ans = 0 def cal(n): l = ceil(log2(K / n)) if n >= K: return 1 / N return pow(2, -l) / N for i in range(1, N + 1): ans += cal(i) print(ans)
N, K = list(map(int, input().split())) ans = 0 for i in range(1, N + 1): l = 0 while i < K: i *= 2 l += 1 ans += (1 / N) * pow(2, -l) print(ans)
false
25
[ "-from math import log2, ceil", "-", "-", "-", "-def cal(n):", "- l = ceil(log2(K / n))", "- if n >= K:", "- return 1 / N", "- return pow(2, -l) / N", "-", "-", "- ans += cal(i)", "+ l = 0", "+ while i < K:", "+ i *= 2", "+ l += 1", "+ ans += (1 / N) * pow(2, -l)" ]
false
0.191375
0.057038
3.355221
[ "s293496798", "s965364035" ]
u588341295
p03805
python
s826589840
s256336548
35
21
3,188
3,188
Accepted
Accepted
40
# -*- coding: utf-8 -*- import sys from itertools import permutations def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = MAP() edges = set() for i in range(M): a, b = MAP() a -= 1; b -= 1 edges.add((a, b)) edges.add((b, a)) cnt = 0 for perm in permutations(list(range(N))): if perm[0] != 0: continue for i in range(N-1): a = perm[i] b = perm[i+1] if (a, b) not in edges: break else: cnt += 1 print(cnt)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = MAP() G = list2d(N, N, 0) for i in range(M): a, b = MAP() a -= 1; b -= 1 G[a][b] = G[b][a] = 1 # dp[S][i] := 訪問済の頂点集合をSとして、最後に頂点iにいる場合の通り数 dp = list2d(1<<N, N, 0) # 最初は頂点1にいる状態から dp[1][0] = 1 for S in range(1, 1<<N): for i in range(N): # iが遷移元に含まれていない if not S & 1<<i: continue for j in range(N): # jが遷移元に含まれている(ので遷移先にはできない) if S & 1<<j: continue # 辺の張られた頂点間であれば遷移させる if G[i][j]: dp[S|1<<j][j] += dp[S][i] # 全頂点訪問できた通り数を合計する ans = sum(dp[(1<<N)-1]) print(ans)
41
46
1,116
1,322
# -*- coding: utf-8 -*- import sys from itertools import permutations def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, M = MAP() edges = set() for i in range(M): a, b = MAP() a -= 1 b -= 1 edges.add((a, b)) edges.add((b, a)) cnt = 0 for perm in permutations(list(range(N))): if perm[0] != 0: continue for i in range(N - 1): a = perm[i] b = perm[i + 1] if (a, b) not in edges: break else: cnt += 1 print(cnt)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, M = MAP() G = list2d(N, N, 0) for i in range(M): a, b = MAP() a -= 1 b -= 1 G[a][b] = G[b][a] = 1 # dp[S][i] := 訪問済の頂点集合をSとして、最後に頂点iにいる場合の通り数 dp = list2d(1 << N, N, 0) # 最初は頂点1にいる状態から dp[1][0] = 1 for S in range(1, 1 << N): for i in range(N): # iが遷移元に含まれていない if not S & 1 << i: continue for j in range(N): # jが遷移元に含まれている(ので遷移先にはできない) if S & 1 << j: continue # 辺の張られた頂点間であれば遷移させる if G[i][j]: dp[S | 1 << j][j] += dp[S][i] # 全頂点訪問できた通り数を合計する ans = sum(dp[(1 << N) - 1]) print(ans)
false
10.869565
[ "-from itertools import permutations", "-edges = set()", "+G = list2d(N, N, 0)", "- edges.add((a, b))", "- edges.add((b, a))", "-cnt = 0", "-for perm in permutations(list(range(N))):", "- if perm[0] != 0:", "- continue", "- for i in range(N - 1):", "- a = perm[i]", "- b = perm[i + 1]", "- if (a, b) not in edges:", "- break", "- else:", "- cnt += 1", "-print(cnt)", "+ G[a][b] = G[b][a] = 1", "+# dp[S][i] := 訪問済の頂点集合をSとして、最後に頂点iにいる場合の通り数", "+dp = list2d(1 << N, N, 0)", "+# 最初は頂点1にいる状態から", "+dp[1][0] = 1", "+for S in range(1, 1 << N):", "+ for i in range(N):", "+ # iが遷移元に含まれていない", "+ if not S & 1 << i:", "+ continue", "+ for j in range(N):", "+ # jが遷移元に含まれている(ので遷移先にはできない)", "+ if S & 1 << j:", "+ continue", "+ # 辺の張られた頂点間であれば遷移させる", "+ if G[i][j]:", "+ dp[S | 1 << j][j] += dp[S][i]", "+# 全頂点訪問できた通り数を合計する", "+ans = sum(dp[(1 << N) - 1])", "+print(ans)" ]
false
0.05451
0.040086
1.359819
[ "s826589840", "s256336548" ]
u895641117
p02793
python
s481557626
s050617778
1,881
1,497
4,084
4,084
Accepted
Accepted
20.41
def gcd(x, y): while y > 0: r = x%y x = y y = r return x def lcm(x, y): return x//gcd(x, y)*y n = int(eval(input())) a = list(map(int, input().split())) l = 1 for x in a: l = lcm(l, x) ans = 0 for x in a: ans += l//x print((ans%(10**9+7)))
def gcd(x, y): while y > 0: r = x%y x = y y = r return x def lcm(x, y): return x//gcd(y, x)*y n = int(eval(input())) a = list(map(int, input().split())) l = 1 for x in a: l = lcm(x, l) ans = 0 for x in a: ans += l//x print((ans%(10**9+7)))
22
22
301
301
def gcd(x, y): while y > 0: r = x % y x = y y = r return x def lcm(x, y): return x // gcd(x, y) * y n = int(eval(input())) a = list(map(int, input().split())) l = 1 for x in a: l = lcm(l, x) ans = 0 for x in a: ans += l // x print((ans % (10**9 + 7)))
def gcd(x, y): while y > 0: r = x % y x = y y = r return x def lcm(x, y): return x // gcd(y, x) * y n = int(eval(input())) a = list(map(int, input().split())) l = 1 for x in a: l = lcm(x, l) ans = 0 for x in a: ans += l // x print((ans % (10**9 + 7)))
false
0
[ "- return x // gcd(x, y) * y", "+ return x // gcd(y, x) * y", "- l = lcm(l, x)", "+ l = lcm(x, l)" ]
false
0.046049
0.040847
1.127359
[ "s481557626", "s050617778" ]
u644907318
p04034
python
s868411133
s734641844
630
291
51,932
84,796
Accepted
Accepted
53.81
N,M = list(map(int,input().split())) R = [0 for _ in range(N+1)] R[1] = 1 B = [1 for _ in range(N+1)] B[0] = 0 for _ in range(M): x,y = list(map(int,input().split())) if R[x]==1: R[y] = 1 B[x] -= 1 B[y] += 1 if B[x]==0: R[x] = 0 print((sum(R)))
N,M = list(map(int,input().split())) A = [0 for _ in range(N+1)] B = [1 for _ in range(N+1)] A[1] = 1 B[0] = 0 for _ in range(M): x,y = list(map(int,input().split())) if A[x]==1: A[y]=1 B[y] += 1 B[x] -= 1 if B[x]==0: A[x] = 0 print((sum(A)))
14
14
279
277
N, M = list(map(int, input().split())) R = [0 for _ in range(N + 1)] R[1] = 1 B = [1 for _ in range(N + 1)] B[0] = 0 for _ in range(M): x, y = list(map(int, input().split())) if R[x] == 1: R[y] = 1 B[x] -= 1 B[y] += 1 if B[x] == 0: R[x] = 0 print((sum(R)))
N, M = list(map(int, input().split())) A = [0 for _ in range(N + 1)] B = [1 for _ in range(N + 1)] A[1] = 1 B[0] = 0 for _ in range(M): x, y = list(map(int, input().split())) if A[x] == 1: A[y] = 1 B[y] += 1 B[x] -= 1 if B[x] == 0: A[x] = 0 print((sum(A)))
false
0
[ "-R = [0 for _ in range(N + 1)]", "-R[1] = 1", "+A = [0 for _ in range(N + 1)]", "+A[1] = 1", "- if R[x] == 1:", "- R[y] = 1", "+ if A[x] == 1:", "+ A[y] = 1", "+ B[y] += 1", "- B[y] += 1", "- R[x] = 0", "-print((sum(R)))", "+ A[x] = 0", "+print((sum(A)))" ]
false
0.033577
0.036292
0.925178
[ "s868411133", "s734641844" ]
u855710796
p02659
python
s112010981
s156088526
28
20
9,932
9,168
Accepted
Accepted
28.57
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) print((int(A*B)))
A, B = input().split() A = int(A) B = int(B.replace(".", "")) print((A*B//100))
8
6
106
84
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) print((int(A * B)))
A, B = input().split() A = int(A) B = int(B.replace(".", "")) print((A * B // 100))
false
25
[ "-from decimal import Decimal", "-", "-A = Decimal(A)", "-B = Decimal(B)", "-print((int(A * B)))", "+A = int(A)", "+B = int(B.replace(\".\", \"\"))", "+print((A * B // 100))" ]
false
0.084609
0.084504
1.001247
[ "s112010981", "s156088526" ]
u164727245
p02615
python
s354266534
s950291493
450
122
34,128
33,708
Accepted
Accepted
72.89
# coding: utf-8 from collections import deque def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) Q = deque() ret = 0 for i in range(-(-n//2)): if 0 < i: ret += min(Q[-1], Q[0]) if i % 2: Q.appendleft(A[i]) else: Q.append(A[i]) for i in range(n-len(Q)): ret += min(Q[i], Q[(i+1) % len(Q)]) return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) return str(sum([A[i//2] for i in range(1, n)])) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
27
11
559
265
# coding: utf-8 from collections import deque def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) Q = deque() ret = 0 for i in range(-(-n // 2)): if 0 < i: ret += min(Q[-1], Q[0]) if i % 2: Q.appendleft(A[i]) else: Q.append(A[i]) for i in range(n - len(Q)): ret += min(Q[i], Q[(i + 1) % len(Q)]) return str(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = sorted(map(int, args[1].split()), reverse=True) return str(sum([A[i // 2] for i in range(1, n)])) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
59.259259
[ "-from collections import deque", "-", "-", "- Q = deque()", "- ret = 0", "- for i in range(-(-n // 2)):", "- if 0 < i:", "- ret += min(Q[-1], Q[0])", "- if i % 2:", "- Q.appendleft(A[i])", "- else:", "- Q.append(A[i])", "- for i in range(n - len(Q)):", "- ret += min(Q[i], Q[(i + 1) % len(Q)])", "- return str(ret)", "+ return str(sum([A[i // 2] for i in range(1, n)]))" ]
false
0.036645
0.036006
1.017753
[ "s354266534", "s950291493" ]
u759412327
p02918
python
s128542495
s352434491
71
45
9,824
9,260
Accepted
Accepted
36.62
from itertools import * N,K = list(map(int,input().split())) S = eval(input()) A = [] for i,j in groupby(S): A+=[len(list(j))-1] print((min(N-1,sum(A)+2*K)))
N,K = list(map(int,input().split())) S = eval(input()) print((min(sum(S[n]==S[n+1] for n in range(N-1))+2*K,N-1)))
9
3
155
102
from itertools import * N, K = list(map(int, input().split())) S = eval(input()) A = [] for i, j in groupby(S): A += [len(list(j)) - 1] print((min(N - 1, sum(A) + 2 * K)))
N, K = list(map(int, input().split())) S = eval(input()) print((min(sum(S[n] == S[n + 1] for n in range(N - 1)) + 2 * K, N - 1)))
false
66.666667
[ "-from itertools import *", "-", "-A = []", "-for i, j in groupby(S):", "- A += [len(list(j)) - 1]", "-print((min(N - 1, sum(A) + 2 * K)))", "+print((min(sum(S[n] == S[n + 1] for n in range(N - 1)) + 2 * K, N - 1)))" ]
false
0.038428
0.078804
0.487635
[ "s128542495", "s352434491" ]
u754022296
p02623
python
s754337422
s441707919
297
178
42,608
119,584
Accepted
Accepted
40.07
import bisect from itertools import accumulate n, m, k = list(map(int, input().split())) A = list(accumulate([0]+list(map(int, input().split())))) B = list(accumulate([0]+list(map(int, input().split())))) ans = 0 for i, a in enumerate(A): if a > k: break j = bisect.bisect_right(B, k-a)-1 temp = i+j ans = max(ans, temp) print(ans)
from itertools import accumulate import bisect n, m, k = list(map(int, input().split())) A = [0] + list(accumulate(list(map(int, input().split())))) B = [0] + list(accumulate(list(map(int, input().split())))) ans = 0 for i, a in enumerate(A): if a > k: break temp = i + bisect.bisect_right(B, k-a)-1 ans = max(ans, temp) print(ans)
14
13
363
336
import bisect from itertools import accumulate n, m, k = list(map(int, input().split())) A = list(accumulate([0] + list(map(int, input().split())))) B = list(accumulate([0] + list(map(int, input().split())))) ans = 0 for i, a in enumerate(A): if a > k: break j = bisect.bisect_right(B, k - a) - 1 temp = i + j ans = max(ans, temp) print(ans)
from itertools import accumulate import bisect n, m, k = list(map(int, input().split())) A = [0] + list(accumulate(list(map(int, input().split())))) B = [0] + list(accumulate(list(map(int, input().split())))) ans = 0 for i, a in enumerate(A): if a > k: break temp = i + bisect.bisect_right(B, k - a) - 1 ans = max(ans, temp) print(ans)
false
7.142857
[ "+from itertools import accumulate", "-from itertools import accumulate", "-A = list(accumulate([0] + list(map(int, input().split()))))", "-B = list(accumulate([0] + list(map(int, input().split()))))", "+A = [0] + list(accumulate(list(map(int, input().split()))))", "+B = [0] + list(accumulate(list(map(int, input().split()))))", "- j = bisect.bisect_right(B, k - a) - 1", "- temp = i + j", "+ temp = i + bisect.bisect_right(B, k - a) - 1" ]
false
0.119046
0.121573
0.979213
[ "s754337422", "s441707919" ]
u847467233
p02268
python
s135535040
s514123155
50
40
16,848
18,456
Accepted
Accepted
20
# AOJ ALDS1_4_B Binary Search # Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline n = int(eval(input())) s = set(map(int, input().split())) q = int(eval(input())) t = set(map(int, input().split())) print((len(s & t)))
# AOJ ALDS1_4_B Binary Search # Python3 2018.7.3 bal4u n = eval(input()) s = set(input().split()) q = eval(input()) t = set(input().split()) print((len(s & t)))
12
8
246
155
# AOJ ALDS1_4_B Binary Search # Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline n = int(eval(input())) s = set(map(int, input().split())) q = int(eval(input())) t = set(map(int, input().split())) print((len(s & t)))
# AOJ ALDS1_4_B Binary Search # Python3 2018.7.3 bal4u n = eval(input()) s = set(input().split()) q = eval(input()) t = set(input().split()) print((len(s & t)))
false
33.333333
[ "-import sys", "-from sys import stdin", "-", "-input = stdin.readline", "-n = int(eval(input()))", "-s = set(map(int, input().split()))", "-q = int(eval(input()))", "-t = set(map(int, input().split()))", "+n = eval(input())", "+s = set(input().split())", "+q = eval(input())", "+t = set(input().split())" ]
false
0.088669
0.038886
2.280198
[ "s135535040", "s514123155" ]
u077291787
p02911
python
s048409109
s384623986
130
91
14,544
14,324
Accepted
Accepted
30
# ABC141 from collections import Counter def main(): N, K, Q, *A = map(int, open(0).read().split()) C = Counter(A) ans = [] for i in range(1, N + 1): x = "Yes" if K - Q + C[i] > 0 else "No" ans.append(x) print(*ans, sep="\n") if __name__ == "__main__": main()
# ABC141 from collections import Counter def main(): N, K, Q, *A = list(map(int, open(0).read().split())) C = Counter(A) ans = [] for i in range(1, N + 1): x = "Yes" if K - Q + C[i] > 0 else "No" ans.append(x) print(("\n".join(ans))) if __name__ == "__main__": main()
16
16
318
318
# ABC141 from collections import Counter def main(): N, K, Q, *A = map(int, open(0).read().split()) C = Counter(A) ans = [] for i in range(1, N + 1): x = "Yes" if K - Q + C[i] > 0 else "No" ans.append(x) print(*ans, sep="\n") if __name__ == "__main__": main()
# ABC141 from collections import Counter def main(): N, K, Q, *A = list(map(int, open(0).read().split())) C = Counter(A) ans = [] for i in range(1, N + 1): x = "Yes" if K - Q + C[i] > 0 else "No" ans.append(x) print(("\n".join(ans))) if __name__ == "__main__": main()
false
0
[ "- N, K, Q, *A = map(int, open(0).read().split())", "+ N, K, Q, *A = list(map(int, open(0).read().split()))", "- print(*ans, sep=\"\\n\")", "+ print((\"\\n\".join(ans)))" ]
false
0.041112
0.037537
1.095258
[ "s048409109", "s384623986" ]
u354916249
p02995
python
s783262088
s595678344
19
17
3,064
3,064
Accepted
Accepted
10.53
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) A, B, C, D = list(map(int, input().split())) CD = C*D//gcd(C, D) count1 = (B // C - A // C) count2 = (B // D - A // D) count3 = (B // CD - A // CD) if A % C == 0: count1 += 1 if A % D == 0: count2 += 1 if A % CD == 0: count3 += 1 print((B - A + 1 - ((count1 + count2) - count3)))
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) A, B, C, D = list(map(int, input().split())) CD = C*D//gcd(C, D) count1 = (B // C - (A - 1) // C) count2 = (B // D - (A - 1) // D) count3 = (B // CD - (A - 1) // CD) print((B - (A - 1) - ((count1 + count2) - count3)))
24
15
399
311
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) A, B, C, D = list(map(int, input().split())) CD = C * D // gcd(C, D) count1 = B // C - A // C count2 = B // D - A // D count3 = B // CD - A // CD if A % C == 0: count1 += 1 if A % D == 0: count2 += 1 if A % CD == 0: count3 += 1 print((B - A + 1 - ((count1 + count2) - count3)))
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) A, B, C, D = list(map(int, input().split())) CD = C * D // gcd(C, D) count1 = B // C - (A - 1) // C count2 = B // D - (A - 1) // D count3 = B // CD - (A - 1) // CD print((B - (A - 1) - ((count1 + count2) - count3)))
false
37.5
[ "-count1 = B // C - A // C", "-count2 = B // D - A // D", "-count3 = B // CD - A // CD", "-if A % C == 0:", "- count1 += 1", "-if A % D == 0:", "- count2 += 1", "-if A % CD == 0:", "- count3 += 1", "-print((B - A + 1 - ((count1 + count2) - count3)))", "+count1 = B // C - (A - 1) // C", "+count2 = B // D - (A - 1) // D", "+count3 = B // CD - (A - 1) // CD", "+print((B - (A - 1) - ((count1 + count2) - count3)))" ]
false
0.05283
0.070222
0.752331
[ "s783262088", "s595678344" ]
u647766105
p00008
python
s215619978
s242181077
130
10
5,068
5,068
Accepted
Accepted
92.31
import sys def dfs(a,b): if a==0:return 1 elif b==0 or a < 0:return 0 return sum([dfs(a-i,b-1) for i in range(10)]) for line in sys.stdin.readlines(): print(dfs(int(line.strip()),4))
import sys table={} def memorize(f): global table def func(*args): if not args in table: table[args]=f(*args) return table[args] return func @memorize def dfs(a,b): if a==0:return 1 elif b==0 or a < 0:return 0 return sum([dfs(a-i,b-1) for i in range(10)]) for i in sys.stdin.readlines(): print(dfs(int(i.strip()),4))
7
16
204
387
import sys def dfs(a, b): if a == 0: return 1 elif b == 0 or a < 0: return 0 return sum([dfs(a - i, b - 1) for i in range(10)]) for line in sys.stdin.readlines(): print(dfs(int(line.strip()), 4))
import sys table = {} def memorize(f): global table def func(*args): if not args in table: table[args] = f(*args) return table[args] return func @memorize def dfs(a, b): if a == 0: return 1 elif b == 0 or a < 0: return 0 return sum([dfs(a - i, b - 1) for i in range(10)]) for i in sys.stdin.readlines(): print(dfs(int(i.strip()), 4))
false
56.25
[ "+table = {}", "+", "+def memorize(f):", "+ global table", "+", "+ def func(*args):", "+ if not args in table:", "+ table[args] = f(*args)", "+ return table[args]", "+", "+ return func", "+", "+", "+@memorize", "-for line in sys.stdin.readlines():", "- print(dfs(int(line.strip()), 4))", "+for i in sys.stdin.readlines():", "+ print(dfs(int(i.strip()), 4))" ]
false
0.050258
0.041098
1.22289
[ "s215619978", "s242181077" ]
u008718882
p03160
python
s376562647
s074739985
515
123
22,840
13,980
Accepted
Accepted
76.12
import numpy as np N= int(eval(input())) H = list(map(int, input().split())) dp = np.zeros(N, dtype = int) for i in range(N - 1): if i == 0: dp[i + 1] = abs(H[0] - H[1]) else: dp[i + 1] = min(dp[i] + abs(H[i] - H[i + 1]), dp[i - 1] + abs(H[i - 1] - H[i + 1])) #print(dp) print((dp[N - 1]))
N= int(eval(input())) H = list(map(int, input().split())) rev, cur, tmp = 0, 0, 0 for i in range(N - 1): if i == 0: cur = abs(H[0] - H[1]) else: tmp = cur cur = min(cur + abs(H[i] - H[i + 1]), rev + abs(H[i - 1] - H[i + 1])) rev = tmp print(cur)
15
12
347
285
import numpy as np N = int(eval(input())) H = list(map(int, input().split())) dp = np.zeros(N, dtype=int) for i in range(N - 1): if i == 0: dp[i + 1] = abs(H[0] - H[1]) else: dp[i + 1] = min( dp[i] + abs(H[i] - H[i + 1]), dp[i - 1] + abs(H[i - 1] - H[i + 1]) ) # print(dp) print((dp[N - 1]))
N = int(eval(input())) H = list(map(int, input().split())) rev, cur, tmp = 0, 0, 0 for i in range(N - 1): if i == 0: cur = abs(H[0] - H[1]) else: tmp = cur cur = min(cur + abs(H[i] - H[i + 1]), rev + abs(H[i - 1] - H[i + 1])) rev = tmp print(cur)
false
20
[ "-import numpy as np", "-", "-dp = np.zeros(N, dtype=int)", "+rev, cur, tmp = 0, 0, 0", "- dp[i + 1] = abs(H[0] - H[1])", "+ cur = abs(H[0] - H[1])", "- dp[i + 1] = min(", "- dp[i] + abs(H[i] - H[i + 1]), dp[i - 1] + abs(H[i - 1] - H[i + 1])", "- )", "-# print(dp)", "-print((dp[N - 1]))", "+ tmp = cur", "+ cur = min(cur + abs(H[i] - H[i + 1]), rev + abs(H[i - 1] - H[i + 1]))", "+ rev = tmp", "+print(cur)" ]
false
0.202702
0.041136
4.927561
[ "s376562647", "s074739985" ]
u388927326
p03837
python
s388591701
s356744938
79
73
3,568
3,568
Accepted
Accepted
7.59
#!/usr/bin/env python3 from heapq import heappush, heappop HUGE = 10 ** 15 def main(): n, m = list(map(int, input().split())) dist_sets = [{} for i in range(n)] for i in range(m): a1, b1, c = list(map(int, input().split())) dist_sets[a1 - 1][b1 - 1] = c dist_sets[b1 - 1][a1 - 1] = c shortest_path_mat = [dijkstra(i, dist_sets) for i in range(n)] res = 0 for i in range(n): for j in list(dist_sets[i].keys()): if i > j: continue if dist_sets[i][j] != HUGE and shortest_path_mat[i][j] < dist_sets[i][j]: res += 1 print(res) def dijkstra(root, dist_sets): # rootからの距離のリストを返す (TLE本 p302) n = len(dist_sets) sp = [(0 if i == root else HUGE) for i in range(n)] # Shortest path from root color = [(2 if i == root else 0) for i in range(n)] # 0: unknown. 1: one path is found. 2: shortest path is found pq = [] heappush(pq, (sp[root], root)) while len(pq) > 0: sp_i_when_queued, i = heappop(pq) color[i] = 2 if sp[i] < sp_i_when_queued: continue for j in list(dist_sets[i].keys()): if color[j] != 2 and sp[i] + dist_sets[i][j] < sp[j]: sp[j] = sp[i] + dist_sets[i][j] color[j] = 1 heappush(pq, (sp[j], j)) return sp main()
#!/usr/bin/env python3 # 本スクリプトを通じて以下の意味で用いる # dist: 直接結ぶエッジの長さ # shortest path (sp): 他のノードを経由しうる最短経路 from heapq import heappush, heappop HUGE = 10 ** 15 def main(): n, m = list(map(int, input().split())) dist_sets = [{} for i in range(n)] for i in range(m): a1, b1, c = list(map(int, input().split())) dist_sets[a1 - 1][b1 - 1] = c dist_sets[b1 - 1][a1 - 1] = c shortest_path_mat = [get_shortest_path_dijkstra(i, dist_sets) for i in range(n)] res = 0 for i in range(n): for j in list(dist_sets[i].keys()): if i > j: continue if shortest_path_mat[i][j] < dist_sets[i][j]: res += 1 print(res) def get_shortest_path_dijkstra(root, dist_sets): n = len(dist_sets) known_sp = [HUGE for i in range(n)] known_sp[root] = 0 determined = [(i == root) for i in range(n)] pq = [(known_sp[root], root)] # 第一要素はキュー追加時の shortest path 候補 while len(pq) > 0: sp_cand, i = heappop(pq) determined[i] = True if known_sp[i] < sp_cand: continue for j, dist_ij in list(dist_sets[i].items()): if determined[j]: continue if known_sp[i] + dist_ij < known_sp[j]: known_sp[j] = known_sp[i] + dist_ij heappush(pq, (known_sp[j], j)) return known_sp main()
43
46
1,393
1,412
#!/usr/bin/env python3 from heapq import heappush, heappop HUGE = 10**15 def main(): n, m = list(map(int, input().split())) dist_sets = [{} for i in range(n)] for i in range(m): a1, b1, c = list(map(int, input().split())) dist_sets[a1 - 1][b1 - 1] = c dist_sets[b1 - 1][a1 - 1] = c shortest_path_mat = [dijkstra(i, dist_sets) for i in range(n)] res = 0 for i in range(n): for j in list(dist_sets[i].keys()): if i > j: continue if dist_sets[i][j] != HUGE and shortest_path_mat[i][j] < dist_sets[i][j]: res += 1 print(res) def dijkstra(root, dist_sets): # rootからの距離のリストを返す (TLE本 p302) n = len(dist_sets) sp = [(0 if i == root else HUGE) for i in range(n)] # Shortest path from root color = [ (2 if i == root else 0) for i in range(n) ] # 0: unknown. 1: one path is found. 2: shortest path is found pq = [] heappush(pq, (sp[root], root)) while len(pq) > 0: sp_i_when_queued, i = heappop(pq) color[i] = 2 if sp[i] < sp_i_when_queued: continue for j in list(dist_sets[i].keys()): if color[j] != 2 and sp[i] + dist_sets[i][j] < sp[j]: sp[j] = sp[i] + dist_sets[i][j] color[j] = 1 heappush(pq, (sp[j], j)) return sp main()
#!/usr/bin/env python3 # 本スクリプトを通じて以下の意味で用いる # dist: 直接結ぶエッジの長さ # shortest path (sp): 他のノードを経由しうる最短経路 from heapq import heappush, heappop HUGE = 10**15 def main(): n, m = list(map(int, input().split())) dist_sets = [{} for i in range(n)] for i in range(m): a1, b1, c = list(map(int, input().split())) dist_sets[a1 - 1][b1 - 1] = c dist_sets[b1 - 1][a1 - 1] = c shortest_path_mat = [get_shortest_path_dijkstra(i, dist_sets) for i in range(n)] res = 0 for i in range(n): for j in list(dist_sets[i].keys()): if i > j: continue if shortest_path_mat[i][j] < dist_sets[i][j]: res += 1 print(res) def get_shortest_path_dijkstra(root, dist_sets): n = len(dist_sets) known_sp = [HUGE for i in range(n)] known_sp[root] = 0 determined = [(i == root) for i in range(n)] pq = [(known_sp[root], root)] # 第一要素はキュー追加時の shortest path 候補 while len(pq) > 0: sp_cand, i = heappop(pq) determined[i] = True if known_sp[i] < sp_cand: continue for j, dist_ij in list(dist_sets[i].items()): if determined[j]: continue if known_sp[i] + dist_ij < known_sp[j]: known_sp[j] = known_sp[i] + dist_ij heappush(pq, (known_sp[j], j)) return known_sp main()
false
6.521739
[ "+# 本スクリプトを通じて以下の意味で用いる", "+# dist: 直接結ぶエッジの長さ", "+# shortest path (sp): 他のノードを経由しうる最短経路", "- shortest_path_mat = [dijkstra(i, dist_sets) for i in range(n)]", "+ shortest_path_mat = [get_shortest_path_dijkstra(i, dist_sets) for i in range(n)]", "- if dist_sets[i][j] != HUGE and shortest_path_mat[i][j] < dist_sets[i][j]:", "+ if shortest_path_mat[i][j] < dist_sets[i][j]:", "-def dijkstra(root, dist_sets):", "- # rootからの距離のリストを返す (TLE本 p302)", "+def get_shortest_path_dijkstra(root, dist_sets):", "- sp = [(0 if i == root else HUGE) for i in range(n)] # Shortest path from root", "- color = [", "- (2 if i == root else 0) for i in range(n)", "- ] # 0: unknown. 1: one path is found. 2: shortest path is found", "- pq = []", "- heappush(pq, (sp[root], root))", "+ known_sp = [HUGE for i in range(n)]", "+ known_sp[root] = 0", "+ determined = [(i == root) for i in range(n)]", "+ pq = [(known_sp[root], root)] # 第一要素はキュー追加時の shortest path 候補", "- sp_i_when_queued, i = heappop(pq)", "- color[i] = 2", "- if sp[i] < sp_i_when_queued:", "+ sp_cand, i = heappop(pq)", "+ determined[i] = True", "+ if known_sp[i] < sp_cand:", "- for j in list(dist_sets[i].keys()):", "- if color[j] != 2 and sp[i] + dist_sets[i][j] < sp[j]:", "- sp[j] = sp[i] + dist_sets[i][j]", "- color[j] = 1", "- heappush(pq, (sp[j], j))", "- return sp", "+ for j, dist_ij in list(dist_sets[i].items()):", "+ if determined[j]:", "+ continue", "+ if known_sp[i] + dist_ij < known_sp[j]:", "+ known_sp[j] = known_sp[i] + dist_ij", "+ heappush(pq, (known_sp[j], j))", "+ return known_sp" ]
false
0.147862
0.043512
3.39821
[ "s388591701", "s356744938" ]
u802963389
p02954
python
s606563837
s334053894
156
132
9,584
6,400
Accepted
Accepted
15.38
s = eval(input()) # RR...RL...LLとなる文字列ssに分割して考える import math # len(ss) % 2 == 0 の場合は、境界にlen(ss)/2ずつ # 奇数の場合は、ss[0]大、ss[1]小、→ss[偶数]大、ss[奇数]小 ans = [0] * len(s) ss = [] start = 0 for i in range(len(s) - 1): if (s[i]=="L" and s[i+1]=="R"): ss.append(s[start:i+1]) start = i+1 elif i == len(s) - 2: ss.append(s[start:i+2]) #print(ss) # rlposはr,lの位置 sumlenj = 0 for j in ss: rlpos = j.find("RL") if len(j) % 2 == 0: ans[sumlenj+rlpos] = int(len(j)/2) ans[sumlenj+rlpos+1] = int(len(j)/2) else: if rlpos % 2 == 0: ans[sumlenj+rlpos] = int(math.ceil(len(j)/2)) ans[sumlenj+rlpos+1] = int(math.floor(len(j)/2)) else: ans[sumlenj+rlpos] = int(math.floor(len(j)/2)) ans[sumlenj+rlpos+1] = int(math.ceil(len(j)/2)) sumlenj += len(j) print((*ans))
s = eval(input()) n = len(s) ans = [0] * n # 左と右からそれぞれR, Lを見ていく。 # cntが奇数の場合は開始点に近い側が+1(切り上げ)になる。 # 左からRを数える。Lまで cntr = 0 for itr, val in enumerate(s): if val == "R": cntr += 1 else: ans[itr - 1] += (cntr - 1) // 2 + 1 ans[itr] += cntr // 2 cntr = 0 # 右からLを数える。Rまで cntl = 0 for itr, val in enumerate(s[::-1]): if val == "L": cntl += 1 else: ans[n - 1 - itr] += cntl // 2 ans[n - 1 - itr + 1] += (cntl - 1) // 2 + 1 cntl = 0 print((*ans))
34
29
840
510
s = eval(input()) # RR...RL...LLとなる文字列ssに分割して考える import math # len(ss) % 2 == 0 の場合は、境界にlen(ss)/2ずつ # 奇数の場合は、ss[0]大、ss[1]小、→ss[偶数]大、ss[奇数]小 ans = [0] * len(s) ss = [] start = 0 for i in range(len(s) - 1): if s[i] == "L" and s[i + 1] == "R": ss.append(s[start : i + 1]) start = i + 1 elif i == len(s) - 2: ss.append(s[start : i + 2]) # print(ss) # rlposはr,lの位置 sumlenj = 0 for j in ss: rlpos = j.find("RL") if len(j) % 2 == 0: ans[sumlenj + rlpos] = int(len(j) / 2) ans[sumlenj + rlpos + 1] = int(len(j) / 2) else: if rlpos % 2 == 0: ans[sumlenj + rlpos] = int(math.ceil(len(j) / 2)) ans[sumlenj + rlpos + 1] = int(math.floor(len(j) / 2)) else: ans[sumlenj + rlpos] = int(math.floor(len(j) / 2)) ans[sumlenj + rlpos + 1] = int(math.ceil(len(j) / 2)) sumlenj += len(j) print((*ans))
s = eval(input()) n = len(s) ans = [0] * n # 左と右からそれぞれR, Lを見ていく。 # cntが奇数の場合は開始点に近い側が+1(切り上げ)になる。 # 左からRを数える。Lまで cntr = 0 for itr, val in enumerate(s): if val == "R": cntr += 1 else: ans[itr - 1] += (cntr - 1) // 2 + 1 ans[itr] += cntr // 2 cntr = 0 # 右からLを数える。Rまで cntl = 0 for itr, val in enumerate(s[::-1]): if val == "L": cntl += 1 else: ans[n - 1 - itr] += cntl // 2 ans[n - 1 - itr + 1] += (cntl - 1) // 2 + 1 cntl = 0 print((*ans))
false
14.705882
[ "-# RR...RL...LLとなる文字列ssに分割して考える", "-import math", "-", "-# len(ss) % 2 == 0 の場合は、境界にlen(ss)/2ずつ", "-# 奇数の場合は、ss[0]大、ss[1]小、→ss[偶数]大、ss[奇数]小", "-ans = [0] * len(s)", "-ss = []", "-start = 0", "-for i in range(len(s) - 1):", "- if s[i] == \"L\" and s[i + 1] == \"R\":", "- ss.append(s[start : i + 1])", "- start = i + 1", "- elif i == len(s) - 2:", "- ss.append(s[start : i + 2])", "-# print(ss)", "-# rlposはr,lの位置", "-sumlenj = 0", "-for j in ss:", "- rlpos = j.find(\"RL\")", "- if len(j) % 2 == 0:", "- ans[sumlenj + rlpos] = int(len(j) / 2)", "- ans[sumlenj + rlpos + 1] = int(len(j) / 2)", "+n = len(s)", "+ans = [0] * n", "+# 左と右からそれぞれR, Lを見ていく。", "+# cntが奇数の場合は開始点に近い側が+1(切り上げ)になる。", "+# 左からRを数える。Lまで", "+cntr = 0", "+for itr, val in enumerate(s):", "+ if val == \"R\":", "+ cntr += 1", "- if rlpos % 2 == 0:", "- ans[sumlenj + rlpos] = int(math.ceil(len(j) / 2))", "- ans[sumlenj + rlpos + 1] = int(math.floor(len(j) / 2))", "- else:", "- ans[sumlenj + rlpos] = int(math.floor(len(j) / 2))", "- ans[sumlenj + rlpos + 1] = int(math.ceil(len(j) / 2))", "- sumlenj += len(j)", "+ ans[itr - 1] += (cntr - 1) // 2 + 1", "+ ans[itr] += cntr // 2", "+ cntr = 0", "+# 右からLを数える。Rまで", "+cntl = 0", "+for itr, val in enumerate(s[::-1]):", "+ if val == \"L\":", "+ cntl += 1", "+ else:", "+ ans[n - 1 - itr] += cntl // 2", "+ ans[n - 1 - itr + 1] += (cntl - 1) // 2 + 1", "+ cntl = 0" ]
false
0.055774
0.102917
0.541935
[ "s606563837", "s334053894" ]
u141786930
p02625
python
s612432302
s063142375
1,004
869
68,500
68,700
Accepted
Accepted
13.45
# E - NEQ N, M = list(map(int, input().split())) MOD = 10 ** 9 + 7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, M+1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) fixed = (fac[N] * fac[M] * pow(finv[M-N], 2, MOD)) % MOD def f(k): return (fac[M-k] * finv[k] * finv[N-k]) % MOD ans = 0 for i in range(N+1): ans = (ans + fixed * f(i) * pow(-1, i)) % MOD print(ans)
# E - NEQ N, M = list(map(int, input().split())) MOD = 10 ** 9 + 7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, M+1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) fixed = (fac[N] * fac[M] * pow(finv[M-N], 2, MOD)) % MOD def f(k): return (fac[M-k] * finv[k] * finv[N-k]) % MOD ans = 0 for i in range(N+1): ans = (ans + f(i) * pow(-1, i)) % MOD print(((fixed * ans) % MOD))
24
24
487
495
# E - NEQ N, M = list(map(int, input().split())) MOD = 10**9 + 7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, M + 1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) fixed = (fac[N] * fac[M] * pow(finv[M - N], 2, MOD)) % MOD def f(k): return (fac[M - k] * finv[k] * finv[N - k]) % MOD ans = 0 for i in range(N + 1): ans = (ans + fixed * f(i) * pow(-1, i)) % MOD print(ans)
# E - NEQ N, M = list(map(int, input().split())) MOD = 10**9 + 7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, M + 1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) fixed = (fac[N] * fac[M] * pow(finv[M - N], 2, MOD)) % MOD def f(k): return (fac[M - k] * finv[k] * finv[N - k]) % MOD ans = 0 for i in range(N + 1): ans = (ans + f(i) * pow(-1, i)) % MOD print(((fixed * ans) % MOD))
false
0
[ "- ans = (ans + fixed * f(i) * pow(-1, i)) % MOD", "-print(ans)", "+ ans = (ans + f(i) * pow(-1, i)) % MOD", "+print(((fixed * ans) % MOD))" ]
false
0.303224
0.544991
0.556383
[ "s612432302", "s063142375" ]
u686036872
p03607
python
s327268857
s320746963
225
202
11,884
16,636
Accepted
Accepted
10.22
N = int(eval(input())) list=set() for i in range(N): list ^= {int(eval(input()))} print((len(list)))
from collections import Counter N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = Counter(A) ans = 0 for i, j in list(c.items()): if j%2 != 0: ans += 1 print(ans)
5
13
94
192
N = int(eval(input())) list = set() for i in range(N): list ^= {int(eval(input()))} print((len(list)))
from collections import Counter N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = Counter(A) ans = 0 for i, j in list(c.items()): if j % 2 != 0: ans += 1 print(ans)
false
61.538462
[ "+from collections import Counter", "+", "-list = set()", "-for i in range(N):", "- list ^= {int(eval(input()))}", "-print((len(list)))", "+A = [int(eval(input())) for i in range(N)]", "+c = Counter(A)", "+ans = 0", "+for i, j in list(c.items()):", "+ if j % 2 != 0:", "+ ans += 1", "+print(ans)" ]
false
0.043527
0.041544
1.047739
[ "s327268857", "s320746963" ]
u790048565
p02713
python
s774373750
s527675462
1,307
504
69,212
67,724
Accepted
Accepted
61.44
def euclid(a, b): division = a if (a > b) else b divider = b if (a > b) else a reminder = 0 while divider != 0: reminder = division % divider division = divider divider = reminder return division K = int(eval(input())) result = 0 for k in range(1, K + 1): for l in range(1, K + 1): for m in range(1, K + 1): gcd = euclid(euclid(k, l), m) result += gcd print(result)
from math import gcd K = int(eval(input())) result = 0 for k in range(1, K + 1): for l in range(1, K + 1): for m in range(1, K + 1): gcd_res = gcd(gcd(k, l), m) result += gcd_res print(result)
21
11
426
217
def euclid(a, b): division = a if (a > b) else b divider = b if (a > b) else a reminder = 0 while divider != 0: reminder = division % divider division = divider divider = reminder return division K = int(eval(input())) result = 0 for k in range(1, K + 1): for l in range(1, K + 1): for m in range(1, K + 1): gcd = euclid(euclid(k, l), m) result += gcd print(result)
from math import gcd K = int(eval(input())) result = 0 for k in range(1, K + 1): for l in range(1, K + 1): for m in range(1, K + 1): gcd_res = gcd(gcd(k, l), m) result += gcd_res print(result)
false
47.619048
[ "-def euclid(a, b):", "- division = a if (a > b) else b", "- divider = b if (a > b) else a", "- reminder = 0", "- while divider != 0:", "- reminder = division % divider", "- division = divider", "- divider = reminder", "- return division", "-", "+from math import gcd", "- gcd = euclid(euclid(k, l), m)", "- result += gcd", "+ gcd_res = gcd(gcd(k, l), m)", "+ result += gcd_res" ]
false
0.038026
0.039095
0.972663
[ "s774373750", "s527675462" ]
u879309973
p02862
python
s306471714
s150817453
262
128
12,516
3,064
Accepted
Accepted
51.15
import numpy as np MOD = 10**9 + 7 def extgcd(a, b): r = np.array([1,0,a], dtype=int) w = np.array([0,1,b], dtype=int) while w[2] != 1: q = r[2] // w[2] r, w = w, r - q*w return w[:2] def mod_inverse(a, m): x, y = extgcd(a, m) return (m + x % m) % m def solve(x, y): a = -y + 2*x b = 2*y - x if (a < 0) or (b < 0): return 0 if a % 3 + b % 3 != 0: return 0 a //= 3 b //= 3 n, k = a+b, a p, q = 1, 1 for i in range(k): p = p * (n-i) % MOD q = q * (i+1) % MOD return (p * mod_inverse(q, MOD)) % MOD x, y = list(map(int, input().split())) print((solve(x, y)))
MOD = 10**9 + 7 def mod_inverse(a, m): res = 1 n = m-2 while n > 0: if n & 1: res = (res * a) % m a = (a * a) % m n //= 2 return res def solve(x, y): a = -y + 2*x b = 2*y - x if (a < 0) or (b < 0): return 0 if a % 3 + b % 3 != 0: return 0 a //= 3 b //= 3 n, k = a+b, a p, q = 1, 1 for i in range(k): p = p * (n-i) % MOD q = q * (i+1) % MOD return (p * mod_inverse(q, MOD)) % MOD x, y = list(map(int, input().split())) print((solve(x, y)))
32
30
693
586
import numpy as np MOD = 10**9 + 7 def extgcd(a, b): r = np.array([1, 0, a], dtype=int) w = np.array([0, 1, b], dtype=int) while w[2] != 1: q = r[2] // w[2] r, w = w, r - q * w return w[:2] def mod_inverse(a, m): x, y = extgcd(a, m) return (m + x % m) % m def solve(x, y): a = -y + 2 * x b = 2 * y - x if (a < 0) or (b < 0): return 0 if a % 3 + b % 3 != 0: return 0 a //= 3 b //= 3 n, k = a + b, a p, q = 1, 1 for i in range(k): p = p * (n - i) % MOD q = q * (i + 1) % MOD return (p * mod_inverse(q, MOD)) % MOD x, y = list(map(int, input().split())) print((solve(x, y)))
MOD = 10**9 + 7 def mod_inverse(a, m): res = 1 n = m - 2 while n > 0: if n & 1: res = (res * a) % m a = (a * a) % m n //= 2 return res def solve(x, y): a = -y + 2 * x b = 2 * y - x if (a < 0) or (b < 0): return 0 if a % 3 + b % 3 != 0: return 0 a //= 3 b //= 3 n, k = a + b, a p, q = 1, 1 for i in range(k): p = p * (n - i) % MOD q = q * (i + 1) % MOD return (p * mod_inverse(q, MOD)) % MOD x, y = list(map(int, input().split())) print((solve(x, y)))
false
6.25
[ "-import numpy as np", "-", "-def extgcd(a, b):", "- r = np.array([1, 0, a], dtype=int)", "- w = np.array([0, 1, b], dtype=int)", "- while w[2] != 1:", "- q = r[2] // w[2]", "- r, w = w, r - q * w", "- return w[:2]", "-", "-", "- x, y = extgcd(a, m)", "- return (m + x % m) % m", "+ res = 1", "+ n = m - 2", "+ while n > 0:", "+ if n & 1:", "+ res = (res * a) % m", "+ a = (a * a) % m", "+ n //= 2", "+ return res" ]
false
0.793848
0.224596
3.534559
[ "s306471714", "s150817453" ]
u814265211
p02959
python
s167091450
s926984135
175
144
18,624
18,624
Accepted
Accepted
17.71
n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 for i in range(n): if a[i] <= b[i]: if a[i]+a[i+1] > b[i]: all_enemy = a[i] + a[i + 1] ans += b[i] a[i+1] = a[i]+a[i+1] - b[i] else: all_enemy = a[i] + a[i + 1] ans += all_enemy a[i+1] = 0 else: ans += b[i] print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 for i in range(n): if a[i] <= b[i]: all_enemy = a[i] + a[i + 1] if all_enemy > b[i]: ans += b[i] a[i+1] = all_enemy - b[i] else: ans += all_enemy a[i+1] = 0 else: ans += b[i] print(ans)
19
18
442
393
n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 for i in range(n): if a[i] <= b[i]: if a[i] + a[i + 1] > b[i]: all_enemy = a[i] + a[i + 1] ans += b[i] a[i + 1] = a[i] + a[i + 1] - b[i] else: all_enemy = a[i] + a[i + 1] ans += all_enemy a[i + 1] = 0 else: ans += b[i] print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 for i in range(n): if a[i] <= b[i]: all_enemy = a[i] + a[i + 1] if all_enemy > b[i]: ans += b[i] a[i + 1] = all_enemy - b[i] else: ans += all_enemy a[i + 1] = 0 else: ans += b[i] print(ans)
false
5.263158
[ "- if a[i] + a[i + 1] > b[i]:", "- all_enemy = a[i] + a[i + 1]", "+ all_enemy = a[i] + a[i + 1]", "+ if all_enemy > b[i]:", "- a[i + 1] = a[i] + a[i + 1] - b[i]", "+ a[i + 1] = all_enemy - b[i]", "- all_enemy = a[i] + a[i + 1]" ]
false
0.065038
0.068364
0.951351
[ "s167091450", "s926984135" ]
u550061714
p03168
python
s966758041
s423098980
933
251
257,800
82,740
Accepted
Accepted
73.1
N = int(eval(input())) P = tuple(map(float, input().split())) dp = [[0 for _ in range(N + 1)] for __ in range(N + 1)] dp[0][0] = 1 for i in range(N): for j in range(N): dp[i + 1][j + 1] += dp[i][j] * P[i] dp[i + 1][j] += dp[i][j] * (1 - P[i]) print((sum(dp[N][(N + 1) // 2:])))
import numpy as np N = int(eval(input())) P = tuple(map(float, input().split())) dp = np.zeros((N + 1, N + 1), dtype=float) dp[0][0] = 1 for i in range(N): dp[i + 1][1:] += dp[i][:-1] * P[i] dp[i + 1][:-1] += dp[i][:-1] * (1 - P[i]) print((sum(dp[N][(N + 1) // 2:])))
10
11
300
280
N = int(eval(input())) P = tuple(map(float, input().split())) dp = [[0 for _ in range(N + 1)] for __ in range(N + 1)] dp[0][0] = 1 for i in range(N): for j in range(N): dp[i + 1][j + 1] += dp[i][j] * P[i] dp[i + 1][j] += dp[i][j] * (1 - P[i]) print((sum(dp[N][(N + 1) // 2 :])))
import numpy as np N = int(eval(input())) P = tuple(map(float, input().split())) dp = np.zeros((N + 1, N + 1), dtype=float) dp[0][0] = 1 for i in range(N): dp[i + 1][1:] += dp[i][:-1] * P[i] dp[i + 1][:-1] += dp[i][:-1] * (1 - P[i]) print((sum(dp[N][(N + 1) // 2 :])))
false
9.090909
[ "+import numpy as np", "+", "-dp = [[0 for _ in range(N + 1)] for __ in range(N + 1)]", "+dp = np.zeros((N + 1, N + 1), dtype=float)", "- for j in range(N):", "- dp[i + 1][j + 1] += dp[i][j] * P[i]", "- dp[i + 1][j] += dp[i][j] * (1 - P[i])", "+ dp[i + 1][1:] += dp[i][:-1] * P[i]", "+ dp[i + 1][:-1] += dp[i][:-1] * (1 - P[i])" ]
false
0.040601
0.403606
0.100596
[ "s966758041", "s423098980" ]
u848535504
p03071
python
s263517708
s321831704
29
26
9,080
9,124
Accepted
Accepted
10.34
A,B = list(map(int,input().split())) ans = 0 for i in range(2): if A >= B: ans += A A -= 1 else: ans += B B -= 1 print(ans)
#if elseによる実装 A,B = list(map(int,input().split())) ans = 0 if A >= B: ans += A A -= 1 else: ans += B B -= 1 if A >= B: ans += A A -= 1 else: ans += B B -= 1 print(ans)
12
19
170
214
A, B = list(map(int, input().split())) ans = 0 for i in range(2): if A >= B: ans += A A -= 1 else: ans += B B -= 1 print(ans)
# if elseによる実装 A, B = list(map(int, input().split())) ans = 0 if A >= B: ans += A A -= 1 else: ans += B B -= 1 if A >= B: ans += A A -= 1 else: ans += B B -= 1 print(ans)
false
36.842105
[ "+# if elseによる実装", "-for i in range(2):", "- if A >= B:", "- ans += A", "- A -= 1", "- else:", "- ans += B", "- B -= 1", "+if A >= B:", "+ ans += A", "+ A -= 1", "+else:", "+ ans += B", "+ B -= 1", "+if A >= B:", "+ ans += A", "+ A -= 1", "+else:", "+ ans += B", "+ B -= 1" ]
false
0.075145
0.038967
1.928421
[ "s263517708", "s321831704" ]
u933341648
p03262
python
s988182126
s630404693
75
59
11,172
11,172
Accepted
Accepted
21.33
import sys input = sys.stdin.readline def gcd(a, b): while a > 0: if a < b: a, b = b, a a = a % b return b def main(): n, x = list(map(int, input().split())) distance = (abs(x - int(y)) for y in input().split()) res = next(distance) for d in distance: res = gcd(res, d) print(res) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def gcd(a, b): while a > 0: if a < b: a, b = b, a a = a % b return b def main(): n, x = list(map(int, input().split())) town = list(map(int, input().split())) distance = (abs(x-y) for y in town) res = next(distance) for d in distance: if d % res != 0: res = gcd(res, d) print(res) if __name__ == "__main__": main()
22
24
402
452
import sys input = sys.stdin.readline def gcd(a, b): while a > 0: if a < b: a, b = b, a a = a % b return b def main(): n, x = list(map(int, input().split())) distance = (abs(x - int(y)) for y in input().split()) res = next(distance) for d in distance: res = gcd(res, d) print(res) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def gcd(a, b): while a > 0: if a < b: a, b = b, a a = a % b return b def main(): n, x = list(map(int, input().split())) town = list(map(int, input().split())) distance = (abs(x - y) for y in town) res = next(distance) for d in distance: if d % res != 0: res = gcd(res, d) print(res) if __name__ == "__main__": main()
false
8.333333
[ "- distance = (abs(x - int(y)) for y in input().split())", "+ town = list(map(int, input().split()))", "+ distance = (abs(x - y) for y in town)", "- res = gcd(res, d)", "+ if d % res != 0:", "+ res = gcd(res, d)" ]
false
0.075778
0.045087
1.680691
[ "s988182126", "s630404693" ]