user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u910288980
p03361
python
s127158358
s867411217
22
20
3,064
3,064
Accepted
Accepted
9.09
h,w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] def check(): for i in range(h): for j in range(w): if s[i][j] == '.': continue def ok(x,y): return x>=0 and x<h and y>=0 and y<w and s[x][y]=='#' if all([not ok(x,y) for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) : return False return True print(("Yes" if check() else "No"))
h,w = list(map(int, input().split())) B = '.'*(w+2) s = [B] s.extend(['.' + eval(input()) + '.' for _ in range(h)]) s.append(B) def check(): for i in range(1,h+1): for j in range(1,w+1): if s[i][j] == '.': continue if all([s[x][y]=='.' for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) : return False return True print(("Yes" if check() else "No"))
18
16
463
424
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] def check(): for i in range(h): for j in range(w): if s[i][j] == ".": continue def ok(x, y): return x >= 0 and x < h and y >= 0 and y < w and s[x][y] == "#" if all( [ not ok(x, y) for x, y in [(i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1)] ] ): return False return True print(("Yes" if check() else "No"))
h, w = list(map(int, input().split())) B = "." * (w + 2) s = [B] s.extend(["." + eval(input()) + "." for _ in range(h)]) s.append(B) def check(): for i in range(1, h + 1): for j in range(1, w + 1): if s[i][j] == ".": continue if all( [ s[x][y] == "." for x, y in [(i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1)] ] ): return False return True print(("Yes" if check() else "No"))
false
11.111111
[ "-s = [eval(input()) for _ in range(h)]", "+B = \".\" * (w + 2)", "+s = [B]", "+s.extend([\".\" + eval(input()) + \".\" for _ in range(h)])", "+s.append(B)", "- for i in range(h):", "- for j in range(w):", "+ for i in range(1, h + 1):", "+ for j in range(1, w + 1):", "-", "- def ok(x, y):", "- return x >= 0 and x < h and y >= 0 and y < w and s[x][y] == \"#\"", "-", "- not ok(x, y)", "+ s[x][y] == \".\"" ]
false
0.049741
0.046553
1.068481
[ "s127158358", "s867411217" ]
u046187684
p02911
python
s338763530
s605177537
188
172
15,036
14,552
Accepted
Accepted
8.51
from collections import Counter def solve(string): n, k, q, *a = list(map(int, string.split())) a = Counter(a) return "\n".join(["Yes" if a.get(i + 1, 0) > q - k else "No" for i in range(n)]) if __name__ == '__main__': n, m, q = list(map(int, input().split())) print((solve('{} {} {}\n'.format(n, m, q) + '\n'.join([eval(input()) for _ in range(q)]))))
def solve(string): n, k, q, *a = list(map(int, string.split())) t, b = [0] * n, q - k for _a in a: t[_a - 1] += 1 return "\n".join(["Yes" if _t > b else "No" for _t in t]) if __name__ == '__main__': n, m, q = list(map(int, input().split())) print((solve('{} {} {}\n'.format(n, m, q) + '\n'.join([eval(input()) for _ in range(q)]))))
12
11
368
357
from collections import Counter def solve(string): n, k, q, *a = list(map(int, string.split())) a = Counter(a) return "\n".join(["Yes" if a.get(i + 1, 0) > q - k else "No" for i in range(n)]) if __name__ == "__main__": n, m, q = list(map(int, input().split())) print( ( solve( "{} {} {}\n".format(n, m, q) + "\n".join([eval(input()) for _ in range(q)]) ) ) )
def solve(string): n, k, q, *a = list(map(int, string.split())) t, b = [0] * n, q - k for _a in a: t[_a - 1] += 1 return "\n".join(["Yes" if _t > b else "No" for _t in t]) if __name__ == "__main__": n, m, q = list(map(int, input().split())) print( ( solve( "{} {} {}\n".format(n, m, q) + "\n".join([eval(input()) for _ in range(q)]) ) ) )
false
8.333333
[ "-from collections import Counter", "-", "-", "- a = Counter(a)", "- return \"\\n\".join([\"Yes\" if a.get(i + 1, 0) > q - k else \"No\" for i in range(n)])", "+ t, b = [0] * n, q - k", "+ for _a in a:", "+ t[_a - 1] += 1", "+ return \"\\n\".join([\"Yes\" if _t > b else \"No\" for _t in t])" ]
false
0.035795
0.036852
0.971307
[ "s338763530", "s605177537" ]
u941407962
p02904
python
s904059995
s592485487
420
386
101,372
106,020
Accepted
Accepted
8.1
n, k = list(map(int, input().split())) xs = list(map(int, input().split())) from collections import deque def slide_max(k, l): rs = [] dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x < l[lxi]: dq.append(i) break dq.pop() if i+1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs def slide_min(k, l): rs = [] dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > l[lxi]: dq.append(i) break dq.pop() if i+1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs maxs, mins = slide_max(k, xs), slide_min(k, xs) aa, bb = xs[:k], xs[k:] b, nb, bx = aa[0], aa[1], aa[-1] ba = None c = 1 for a in aa: if ba == None: ba = a continue if a > ba: c += 1 else: c = 1 ba = a rok = False if c == k: rok = True r = 1 bs = xs[0] for i, (s, x) in enumerate(zip(xs[1:], bb)): if x > bx: c = min(c+1, k) else: c = 1 bx = x if c == k: if not rok: r += 1 rok = True continue if x != maxs[i+1]: r+=1 elif bs != mins[i]: r+=1 bs = s print(r)
n, k = list(map(int, input().split())) xs = list(map(int, input().split())) from collections import deque def slide_max(k, l): rs, rrs = [], set() dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x < l[lxi]: dq.append(i) break dq.pop() if i+1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs def slide_min(k, l): rs = [] rrs = set() dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > l[lxi]: dq.append(i) break dq.pop() if i+1 < k: continue if len(dq) == k: rrs.add(i+1-k) sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs, rrs maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs) r = 1 for i, (s, x) in enumerate(zip(xs, xs[k:])): if (x != maxs[i+1] or s != mins[i]) and (i+1 not in ns): r+=1 if (0 not in ns) and (len(ns) > 0): r += 1 print(r)
89
56
1,732
1,404
n, k = list(map(int, input().split())) xs = list(map(int, input().split())) from collections import deque def slide_max(k, l): rs = [] dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x < l[lxi]: dq.append(i) break dq.pop() if i + 1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs def slide_min(k, l): rs = [] dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > l[lxi]: dq.append(i) break dq.pop() if i + 1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs maxs, mins = slide_max(k, xs), slide_min(k, xs) aa, bb = xs[:k], xs[k:] b, nb, bx = aa[0], aa[1], aa[-1] ba = None c = 1 for a in aa: if ba == None: ba = a continue if a > ba: c += 1 else: c = 1 ba = a rok = False if c == k: rok = True r = 1 bs = xs[0] for i, (s, x) in enumerate(zip(xs[1:], bb)): if x > bx: c = min(c + 1, k) else: c = 1 bx = x if c == k: if not rok: r += 1 rok = True continue if x != maxs[i + 1]: r += 1 elif bs != mins[i]: r += 1 bs = s print(r)
n, k = list(map(int, input().split())) xs = list(map(int, input().split())) from collections import deque def slide_max(k, l): rs, rrs = [], set() dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x < l[lxi]: dq.append(i) break dq.pop() if i + 1 < k: continue sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs def slide_min(k, l): rs = [] rrs = set() dq = deque() for i, x in enumerate(l): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > l[lxi]: dq.append(i) break dq.pop() if i + 1 < k: continue if len(dq) == k: rrs.add(i + 1 - k) sxi = dq[0] rs.append(l[sxi]) if sxi == (i + 1 - k): dq.popleft() return rs, rrs maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs) r = 1 for i, (s, x) in enumerate(zip(xs, xs[k:])): if (x != maxs[i + 1] or s != mins[i]) and (i + 1 not in ns): r += 1 if (0 not in ns) and (len(ns) > 0): r += 1 print(r)
false
37.078652
[ "- rs = []", "+ rs, rrs = [], set()", "+ rrs = set()", "+ if len(dq) == k:", "+ rrs.add(i + 1 - k)", "- return rs", "+ return rs, rrs", "-maxs, mins = slide_max(k, xs), slide_min(k, xs)", "-aa, bb = xs[:k], xs[k:]", "-b, nb, bx = aa[0], aa[1], aa[-1]", "-ba = None", "-c = 1", "-for a in aa:", "- if ba == None:", "- ba = a", "- continue", "- if a > ba:", "- c += 1", "- else:", "- c = 1", "- ba = a", "-rok = False", "-if c == k:", "- rok = True", "+maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs)", "-bs = xs[0]", "-for i, (s, x) in enumerate(zip(xs[1:], bb)):", "- if x > bx:", "- c = min(c + 1, k)", "- else:", "- c = 1", "- bx = x", "- if c == k:", "- if not rok:", "- r += 1", "- rok = True", "- continue", "- if x != maxs[i + 1]:", "+for i, (s, x) in enumerate(zip(xs, xs[k:])):", "+ if (x != maxs[i + 1] or s != mins[i]) and (i + 1 not in ns):", "- elif bs != mins[i]:", "- r += 1", "- bs = s", "+if (0 not in ns) and (len(ns) > 0):", "+ r += 1" ]
false
0.061793
0.03731
1.656216
[ "s904059995", "s592485487" ]
u966695411
p03948
python
s336603857
s361995482
139
112
14,680
15,020
Accepted
Accepted
19.42
#! /usr/bin/env python3 N, T = list(map(int, input().split())) A = list(map(int, input().split())) pu = -1 SPU = set([]) SPD = [] b = 0 c = 0 for i in A[:-1][::-1]: if i > A[pu]: pu = -c-2 elif i < A[pu] and A[pu]-i >= b: SPU.add(pu) b = A[pu]-i SPD += [b] c += 1 print((min(len(SPU), SPD.count(b))))
#! /usr/bin/env python3 N, T = list(map(int, input().split())) A = list(map(int, input().split())) p = -1 dif = h = hc = lc = c = 0 for i in A[-2::-1]: a, b = A[p], A[p]-i if i > a: p = -c-2 elif b >= dif: if a != h : h, hc = a, hc+1 if b > dif : dif, lc = b, 0 lc += 1 c += 1 print((min(hc, lc)))
19
16
356
353
#! /usr/bin/env python3 N, T = list(map(int, input().split())) A = list(map(int, input().split())) pu = -1 SPU = set([]) SPD = [] b = 0 c = 0 for i in A[:-1][::-1]: if i > A[pu]: pu = -c - 2 elif i < A[pu] and A[pu] - i >= b: SPU.add(pu) b = A[pu] - i SPD += [b] c += 1 print((min(len(SPU), SPD.count(b))))
#! /usr/bin/env python3 N, T = list(map(int, input().split())) A = list(map(int, input().split())) p = -1 dif = h = hc = lc = c = 0 for i in A[-2::-1]: a, b = A[p], A[p] - i if i > a: p = -c - 2 elif b >= dif: if a != h: h, hc = a, hc + 1 if b > dif: dif, lc = b, 0 lc += 1 c += 1 print((min(hc, lc)))
false
15.789474
[ "-pu = -1", "-SPU = set([])", "-SPD = []", "-b = 0", "-c = 0", "-for i in A[:-1][::-1]:", "- if i > A[pu]:", "- pu = -c - 2", "- elif i < A[pu] and A[pu] - i >= b:", "- SPU.add(pu)", "- b = A[pu] - i", "- SPD += [b]", "+p = -1", "+dif = h = hc = lc = c = 0", "+for i in A[-2::-1]:", "+ a, b = A[p], A[p] - i", "+ if i > a:", "+ p = -c - 2", "+ elif b >= dif:", "+ if a != h:", "+ h, hc = a, hc + 1", "+ if b > dif:", "+ dif, lc = b, 0", "+ lc += 1", "-print((min(len(SPU), SPD.count(b))))", "+print((min(hc, lc)))" ]
false
0.037741
0.035719
1.056615
[ "s336603857", "s361995482" ]
u840310460
p03610
python
s326808488
s859914344
180
21
41,840
3,572
Accepted
Accepted
88.33
s = eval(input()) FF = lambda x: [x[i] for i in range(len(x)) if (i+1) % 2 != 0] BA = FF(s) BA print(("".join(BA)))
S = eval(input()) ans = [S[i] for i in range(0, len(S), 2)] print(("".join(ans)))
5
3
111
80
s = eval(input()) FF = lambda x: [x[i] for i in range(len(x)) if (i + 1) % 2 != 0] BA = FF(s) BA print(("".join(BA)))
S = eval(input()) ans = [S[i] for i in range(0, len(S), 2)] print(("".join(ans)))
false
40
[ "-s = eval(input())", "-FF = lambda x: [x[i] for i in range(len(x)) if (i + 1) % 2 != 0]", "-BA = FF(s)", "-BA", "-print((\"\".join(BA)))", "+S = eval(input())", "+ans = [S[i] for i in range(0, len(S), 2)]", "+print((\"\".join(ans)))" ]
false
0.078693
0.041145
1.912587
[ "s326808488", "s859914344" ]
u190405389
p03495
python
s445372139
s570039578
130
110
26,012
92,272
Accepted
Accepted
15.38
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0]*200000 c = [] ans = 0 for x in a: b[x-1] += 1 for x in b: if x > 0: c.append(x) c.sort() y = len(c) - k if y > 0: ans = sum(c[:y]) print(ans)
n,k = list(map(int,input().split())) a = list(map(int,input().split())) b = [0]*(n+1) for x in a: b[x]+=1 b.sort(reverse=1) print((sum(b[k:])))
22
10
266
152
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0] * 200000 c = [] ans = 0 for x in a: b[x - 1] += 1 for x in b: if x > 0: c.append(x) c.sort() y = len(c) - k if y > 0: ans = sum(c[:y]) print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0] * (n + 1) for x in a: b[x] += 1 b.sort(reverse=1) print((sum(b[k:])))
false
54.545455
[ "-b = [0] * 200000", "-c = []", "-ans = 0", "+b = [0] * (n + 1)", "- b[x - 1] += 1", "-for x in b:", "- if x > 0:", "- c.append(x)", "-c.sort()", "-y = len(c) - k", "-if y > 0:", "- ans = sum(c[:y])", "-print(ans)", "+ b[x] += 1", "+b.sort(reverse=1)", "+print((sum(b[k:])))" ]
false
0.05659
0.043284
1.307413
[ "s445372139", "s570039578" ]
u579699847
p02983
python
s344199723
s549767971
659
51
3,060
3,060
Accepted
Accepted
92.26
L, R = list(map(int, input().split())) modL = L % 2019 modR = R % 2019 min2019 = 2019 if R - L >= 2018: print((0)) else: for j in range(modL, modR+1): for k in range(j+1 , modR+1): min2019 = min(min2019, j * k % 2019) print(min2019)
L, R = list(map(int, input().split())) modL = L % 2019 modR = R % 2019 min2019 = 2019 if R - L >= 2018: print((0)) elif modL <=3 and modR >=673: print((0)) else: for j in range(modL, modR+1): for k in range(j+1, modR+1): min2019 = min(min2019, j * k % 2019) print(min2019)
12
15
268
315
L, R = list(map(int, input().split())) modL = L % 2019 modR = R % 2019 min2019 = 2019 if R - L >= 2018: print((0)) else: for j in range(modL, modR + 1): for k in range(j + 1, modR + 1): min2019 = min(min2019, j * k % 2019) print(min2019)
L, R = list(map(int, input().split())) modL = L % 2019 modR = R % 2019 min2019 = 2019 if R - L >= 2018: print((0)) elif modL <= 3 and modR >= 673: print((0)) else: for j in range(modL, modR + 1): for k in range(j + 1, modR + 1): min2019 = min(min2019, j * k % 2019) print(min2019)
false
20
[ "+elif modL <= 3 and modR >= 673:", "+ print((0))" ]
false
0.215895
0.062942
3.43005
[ "s344199723", "s549767971" ]
u671060652
p02946
python
s033585454
s965256579
179
65
38,384
62,536
Accepted
Accepted
63.69
k, x = list(map(int, input().split())) nums = [] for i in range(x - k+1, k+x): nums.append(str(i)) print((" ".join(nums)))
k, x = map(int, input().split()) for i in range(x-k+1,x+k): print(i,end=" ") print("")
6
5
124
95
k, x = list(map(int, input().split())) nums = [] for i in range(x - k + 1, k + x): nums.append(str(i)) print((" ".join(nums)))
k, x = map(int, input().split()) for i in range(x - k + 1, x + k): print(i, end=" ") print("")
false
16.666667
[ "-k, x = list(map(int, input().split()))", "-nums = []", "-for i in range(x - k + 1, k + x):", "- nums.append(str(i))", "-print((\" \".join(nums)))", "+k, x = map(int, input().split())", "+for i in range(x - k + 1, x + k):", "+ print(i, end=\" \")", "+print(\"\")" ]
false
0.063084
0.065447
0.963894
[ "s033585454", "s965256579" ]
u627803856
p03476
python
s024280066
s884499994
987
473
53,464
80,864
Accepted
Accepted
52.08
# O(nloglogn) https://mathtrain.jp/eratosthenes def sieve(n): s = [True] * n s[0] = s[1] = False for x in range(2, int(n ** 0.5) + 1): if s[x]: for i in range(2 * x, n, x): s[i] = False return s is_prime = sieve(10 ** 5 + 1) is_like2017 = [False] * (10 ** 5 + 1) for i in range(10**5 + 1): if is_prime[i] and is_prime[(i + 1) // 2]: is_like2017[i] = True # 区間内のlike2017を求める # 累積和を用いて高速化 c = [0] * (10 ** 5 + 1) for i in range(1, 10 ** 5 + 1): if is_like2017[i]: c[i] = c[i - 1] + 1 else: c[i] = c[i-1] # 出力 q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((c[r] - c[l-1]))
q = int(eval(input())) def is_prime(n): for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return n != 1 def main(n): return 1 if is_prime(n) and is_prime((n + 1) // 2) else 0 MAX = 10 ** 5 + 100 A = [main(i) for i in range(MAX)] # 累積和 acc = [0] * (MAX + 1) for i in range(MAX): acc[i + 1] = acc[i] + A[i] for i in range(q): l, r = list(map(int, input().split())) # [l, r] なので r + 1 にする print((acc[r + 1] - acc[l]))
31
22
655
489
# O(nloglogn) https://mathtrain.jp/eratosthenes def sieve(n): s = [True] * n s[0] = s[1] = False for x in range(2, int(n**0.5) + 1): if s[x]: for i in range(2 * x, n, x): s[i] = False return s is_prime = sieve(10**5 + 1) is_like2017 = [False] * (10**5 + 1) for i in range(10**5 + 1): if is_prime[i] and is_prime[(i + 1) // 2]: is_like2017[i] = True # 区間内のlike2017を求める # 累積和を用いて高速化 c = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): if is_like2017[i]: c[i] = c[i - 1] + 1 else: c[i] = c[i - 1] # 出力 q = int(eval(input())) for i in range(q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
q = int(eval(input())) def is_prime(n): for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return n != 1 def main(n): return 1 if is_prime(n) and is_prime((n + 1) // 2) else 0 MAX = 10**5 + 100 A = [main(i) for i in range(MAX)] # 累積和 acc = [0] * (MAX + 1) for i in range(MAX): acc[i + 1] = acc[i] + A[i] for i in range(q): l, r = list(map(int, input().split())) # [l, r] なので r + 1 にする print((acc[r + 1] - acc[l]))
false
29.032258
[ "-# O(nloglogn) https://mathtrain.jp/eratosthenes", "-def sieve(n):", "- s = [True] * n", "- s[0] = s[1] = False", "- for x in range(2, int(n**0.5) + 1):", "- if s[x]:", "- for i in range(2 * x, n, x):", "- s[i] = False", "- return s", "+q = int(eval(input()))", "-is_prime = sieve(10**5 + 1)", "-is_like2017 = [False] * (10**5 + 1)", "-for i in range(10**5 + 1):", "- if is_prime[i] and is_prime[(i + 1) // 2]:", "- is_like2017[i] = True", "-# 区間内のlike2017を求める", "-# 累積和を用いて高速化", "-c = [0] * (10**5 + 1)", "-for i in range(1, 10**5 + 1):", "- if is_like2017[i]:", "- c[i] = c[i - 1] + 1", "- else:", "- c[i] = c[i - 1]", "-# 出力", "-q = int(eval(input()))", "+def is_prime(n):", "+ for i in range(2, int(n**0.5) + 1):", "+ if n % i == 0:", "+ return False", "+ return n != 1", "+", "+", "+def main(n):", "+ return 1 if is_prime(n) and is_prime((n + 1) // 2) else 0", "+", "+", "+MAX = 10**5 + 100", "+A = [main(i) for i in range(MAX)]", "+# 累積和", "+acc = [0] * (MAX + 1)", "+for i in range(MAX):", "+ acc[i + 1] = acc[i] + A[i]", "- print((c[r] - c[l - 1]))", "+ # [l, r] なので r + 1 にする", "+ print((acc[r + 1] - acc[l]))" ]
false
0.111838
0.58061
0.192622
[ "s024280066", "s884499994" ]
u258073778
p03370
python
s018766024
s422432046
525
17
3,064
2,940
Accepted
Accepted
96.76
N, X = list(map(int, input().split())) mn = [0]*N for i in range(N): mn[i] = int(eval(input())) ans = N x = X - sum(mn) while(x >= min(mn)): if x // min(mn) == 0: mn[mn.index(min(mn))] = 1000000 else: x -= min(mn) ans += 1 print(ans)
N, X = list(map(int, input().split())) mn = [int(eval(input())) for i in range(N)] print(((X - sum(mn))//min(mn) + len(mn)))
17
5
267
116
N, X = list(map(int, input().split())) mn = [0] * N for i in range(N): mn[i] = int(eval(input())) ans = N x = X - sum(mn) while x >= min(mn): if x // min(mn) == 0: mn[mn.index(min(mn))] = 1000000 else: x -= min(mn) ans += 1 print(ans)
N, X = list(map(int, input().split())) mn = [int(eval(input())) for i in range(N)] print(((X - sum(mn)) // min(mn) + len(mn)))
false
70.588235
[ "-mn = [0] * N", "-for i in range(N):", "- mn[i] = int(eval(input()))", "-ans = N", "-x = X - sum(mn)", "-while x >= min(mn):", "- if x // min(mn) == 0:", "- mn[mn.index(min(mn))] = 1000000", "- else:", "- x -= min(mn)", "- ans += 1", "-print(ans)", "+mn = [int(eval(input())) for i in range(N)]", "+print(((X - sum(mn)) // min(mn) + len(mn)))" ]
false
0.088051
0.035801
2.459443
[ "s018766024", "s422432046" ]
u411203878
p02724
python
s435679812
s428467254
162
62
38,384
61,836
Accepted
Accepted
61.73
n=int(eval(input())) x=n//500 y=(n-x*500)//5 print((x*1000+y*5))
n = int(eval(input())) shou500 = n//500 shou5 = (n-shou500*500)//5 print((shou500*1000+shou5*5))
7
7
65
97
n = int(eval(input())) x = n // 500 y = (n - x * 500) // 5 print((x * 1000 + y * 5))
n = int(eval(input())) shou500 = n // 500 shou5 = (n - shou500 * 500) // 5 print((shou500 * 1000 + shou5 * 5))
false
0
[ "-x = n // 500", "-y = (n - x * 500) // 5", "-print((x * 1000 + y * 5))", "+shou500 = n // 500", "+shou5 = (n - shou500 * 500) // 5", "+print((shou500 * 1000 + shou5 * 5))" ]
false
0.035049
0.12269
0.285671
[ "s435679812", "s428467254" ]
u577244731
p02577
python
s665608373
s545837038
750
203
11,176
9,108
Accepted
Accepted
72.93
N = int(eval(input())) N_sum = sum(list(map(int, str(N)))) if N % 9 == 0 and N_sum % 9 == 0: print('Yes') else: print('No')
N = int(eval(input())) if N % 9 == 0: print('Yes') else: print('No')
8
6
134
77
N = int(eval(input())) N_sum = sum(list(map(int, str(N)))) if N % 9 == 0 and N_sum % 9 == 0: print("Yes") else: print("No")
N = int(eval(input())) if N % 9 == 0: print("Yes") else: print("No")
false
25
[ "-N_sum = sum(list(map(int, str(N))))", "-if N % 9 == 0 and N_sum % 9 == 0:", "+if N % 9 == 0:" ]
false
0.102651
0.036893
2.782409
[ "s665608373", "s545837038" ]
u945181840
p02856
python
s737147822
s947271486
168
139
21,316
24,132
Accepted
Accepted
17.26
import sys read = sys.stdin.read M = int(eval(input())) dc = list(map(int, read().split())) dig_sum = 0 dig = 0 for d, c in zip(*[iter(dc)] * 2): dig_sum += d * c dig += c answer = (dig_sum - 1) // 9 + dig - 1 print(answer)
import sys read = sys.stdin.read M = int(eval(input())) dc = list(map(int, read().split())) dig = [0] * 10 cnt = 0 answer = 0 for d, c in zip(*[iter(dc)] * 2): dig[d] += c trans = dict() for i in range(10): if i < 5: trans[i] = i + i elif i == 5: trans[i] = 1 else: trans[i] = trans[i - 1] + 2 while True: tmp = [0] * 10 for i, x in enumerate(dig): q, r = divmod(x, 2) if x >= 2: if i < 5: answer += q tmp[trans[i]] += q tmp[i] += r else: answer += q * 2 tmp[trans[i]] += q tmp[i] += r else: tmp[i] += x dig = tmp.copy() for i in dig: if i > 1: break else: break last = [i for i in range(10) if dig[i] == 1] while len(last) > 1: a = last.pop() b = last.pop() c = a + b if c >= 10: answer += 2 last.append(c // 10 + c % 10) else: answer += 1 last.append(c) print(answer)
13
56
233
1,114
import sys read = sys.stdin.read M = int(eval(input())) dc = list(map(int, read().split())) dig_sum = 0 dig = 0 for d, c in zip(*[iter(dc)] * 2): dig_sum += d * c dig += c answer = (dig_sum - 1) // 9 + dig - 1 print(answer)
import sys read = sys.stdin.read M = int(eval(input())) dc = list(map(int, read().split())) dig = [0] * 10 cnt = 0 answer = 0 for d, c in zip(*[iter(dc)] * 2): dig[d] += c trans = dict() for i in range(10): if i < 5: trans[i] = i + i elif i == 5: trans[i] = 1 else: trans[i] = trans[i - 1] + 2 while True: tmp = [0] * 10 for i, x in enumerate(dig): q, r = divmod(x, 2) if x >= 2: if i < 5: answer += q tmp[trans[i]] += q tmp[i] += r else: answer += q * 2 tmp[trans[i]] += q tmp[i] += r else: tmp[i] += x dig = tmp.copy() for i in dig: if i > 1: break else: break last = [i for i in range(10) if dig[i] == 1] while len(last) > 1: a = last.pop() b = last.pop() c = a + b if c >= 10: answer += 2 last.append(c // 10 + c % 10) else: answer += 1 last.append(c) print(answer)
false
76.785714
[ "-dig_sum = 0", "-dig = 0", "+dig = [0] * 10", "+cnt = 0", "+answer = 0", "- dig_sum += d * c", "- dig += c", "-answer = (dig_sum - 1) // 9 + dig - 1", "+ dig[d] += c", "+trans = dict()", "+for i in range(10):", "+ if i < 5:", "+ trans[i] = i + i", "+ elif i == 5:", "+ trans[i] = 1", "+ else:", "+ trans[i] = trans[i - 1] + 2", "+while True:", "+ tmp = [0] * 10", "+ for i, x in enumerate(dig):", "+ q, r = divmod(x, 2)", "+ if x >= 2:", "+ if i < 5:", "+ answer += q", "+ tmp[trans[i]] += q", "+ tmp[i] += r", "+ else:", "+ answer += q * 2", "+ tmp[trans[i]] += q", "+ tmp[i] += r", "+ else:", "+ tmp[i] += x", "+ dig = tmp.copy()", "+ for i in dig:", "+ if i > 1:", "+ break", "+ else:", "+ break", "+last = [i for i in range(10) if dig[i] == 1]", "+while len(last) > 1:", "+ a = last.pop()", "+ b = last.pop()", "+ c = a + b", "+ if c >= 10:", "+ answer += 2", "+ last.append(c // 10 + c % 10)", "+ else:", "+ answer += 1", "+ last.append(c)" ]
false
0.034984
0.048542
0.7207
[ "s737147822", "s947271486" ]
u688587139
p02984
python
s052898977
s175304233
128
109
117,684
95,720
Accepted
Accepted
14.84
N = int(eval(input())) A = list(map(int, input().split())) R = [] '''プラススタート、マイナススタートの累積和を取る''' plus_start = [] minus_start = [] '''後ろからの累積和''' plus_start_rev = [] minus_start_rev = [] tmp = 0 pm = -1 for i in range(N): pm *= -1 tmp += A[i] * pm plus_start.append(tmp) tmp = 0 pm = -1 for i in range(-1, -N-1, -1): pm *= -1 tmp += A[i] * pm plus_start_rev.append(tmp) tmp = 0 pm = 1 for i in range(N): pm *= -1 tmp += A[i] * pm minus_start.append(tmp) tmp = 0 pm = 1 for i in range(-1, -N-1, -1): pm *= -1 tmp += A[i] * pm minus_start_rev.append(tmp) '''各山の降水量を計算する''' for i in range(N): if i == 0: tmp = plus_start[-1] R.append(tmp) continue if i % 2 == 0: tmp = minus_start[i-1] + plus_start_rev[N-i-1] else: tmp = plus_start[i-1] + minus_start_rev[N-i-1] R.append(tmp) print((*R))
N = int(eval(input())) A = list(map(int, input().split())) R = [] tmp = 0 pm = -1 for i in range(N): pm *= -1 tmp += A[i] * pm R.append(tmp) for i in range(1, N): tmp = 2 * A[i-1] - R[i-1] R.append(tmp) print((*R))
51
16
936
240
N = int(eval(input())) A = list(map(int, input().split())) R = [] """プラススタート、マイナススタートの累積和を取る""" plus_start = [] minus_start = [] """後ろからの累積和""" plus_start_rev = [] minus_start_rev = [] tmp = 0 pm = -1 for i in range(N): pm *= -1 tmp += A[i] * pm plus_start.append(tmp) tmp = 0 pm = -1 for i in range(-1, -N - 1, -1): pm *= -1 tmp += A[i] * pm plus_start_rev.append(tmp) tmp = 0 pm = 1 for i in range(N): pm *= -1 tmp += A[i] * pm minus_start.append(tmp) tmp = 0 pm = 1 for i in range(-1, -N - 1, -1): pm *= -1 tmp += A[i] * pm minus_start_rev.append(tmp) """各山の降水量を計算する""" for i in range(N): if i == 0: tmp = plus_start[-1] R.append(tmp) continue if i % 2 == 0: tmp = minus_start[i - 1] + plus_start_rev[N - i - 1] else: tmp = plus_start[i - 1] + minus_start_rev[N - i - 1] R.append(tmp) print((*R))
N = int(eval(input())) A = list(map(int, input().split())) R = [] tmp = 0 pm = -1 for i in range(N): pm *= -1 tmp += A[i] * pm R.append(tmp) for i in range(1, N): tmp = 2 * A[i - 1] - R[i - 1] R.append(tmp) print((*R))
false
68.627451
[ "-\"\"\"プラススタート、マイナススタートの累積和を取る\"\"\"", "-plus_start = []", "-minus_start = []", "-\"\"\"後ろからの累積和\"\"\"", "-plus_start_rev = []", "-minus_start_rev = []", "- plus_start.append(tmp)", "-tmp = 0", "-pm = -1", "-for i in range(-1, -N - 1, -1):", "- pm *= -1", "- tmp += A[i] * pm", "- plus_start_rev.append(tmp)", "-tmp = 0", "-pm = 1", "-for i in range(N):", "- pm *= -1", "- tmp += A[i] * pm", "- minus_start.append(tmp)", "-tmp = 0", "-pm = 1", "-for i in range(-1, -N - 1, -1):", "- pm *= -1", "- tmp += A[i] * pm", "- minus_start_rev.append(tmp)", "-\"\"\"各山の降水量を計算する\"\"\"", "-for i in range(N):", "- if i == 0:", "- tmp = plus_start[-1]", "- R.append(tmp)", "- continue", "- if i % 2 == 0:", "- tmp = minus_start[i - 1] + plus_start_rev[N - i - 1]", "- else:", "- tmp = plus_start[i - 1] + minus_start_rev[N - i - 1]", "+R.append(tmp)", "+for i in range(1, N):", "+ tmp = 2 * A[i - 1] - R[i - 1]" ]
false
0.036899
0.040329
0.914948
[ "s052898977", "s175304233" ]
u074230519
p02971
python
s147960212
s746682565
665
565
18,648
12,508
Accepted
Accepted
15.04
# -*- coding: utf-8 -*- N = int(eval(input())) values = [0]*N value_count_map = {} max_value = 0 next_max_value = max_value for i in range(N): in_value = int(eval(input())) values[i] = in_value value_count = 0 if in_value in value_count_map: value_count = value_count_map[in_value] value_count_map[in_value] = value_count + 1 if in_value > max_value: next_max_value = max_value max_value = in_value elif in_value > next_max_value: next_max_value = in_value max_value_count = value_count_map[max_value] for row in range(N): if values[row] == max_value and max_value_count == 1: print(next_max_value) else: print(max_value)
# -*- coding: utf-8 -*- N = int(eval(input())) values = [0]*N max_value_count = 0 max_value = 0 next_max_value = max_value for i in range(N): in_value = int(eval(input())) values[i] = in_value if in_value == max_value: max_value_count = max_value_count + 1 elif in_value > max_value: next_max_value = max_value max_value = in_value max_value_count = 1 elif in_value > next_max_value: next_max_value = in_value for row in range(N): if values[row] == max_value and max_value_count == 1: print(next_max_value) else: print(max_value)
30
27
729
633
# -*- coding: utf-8 -*- N = int(eval(input())) values = [0] * N value_count_map = {} max_value = 0 next_max_value = max_value for i in range(N): in_value = int(eval(input())) values[i] = in_value value_count = 0 if in_value in value_count_map: value_count = value_count_map[in_value] value_count_map[in_value] = value_count + 1 if in_value > max_value: next_max_value = max_value max_value = in_value elif in_value > next_max_value: next_max_value = in_value max_value_count = value_count_map[max_value] for row in range(N): if values[row] == max_value and max_value_count == 1: print(next_max_value) else: print(max_value)
# -*- coding: utf-8 -*- N = int(eval(input())) values = [0] * N max_value_count = 0 max_value = 0 next_max_value = max_value for i in range(N): in_value = int(eval(input())) values[i] = in_value if in_value == max_value: max_value_count = max_value_count + 1 elif in_value > max_value: next_max_value = max_value max_value = in_value max_value_count = 1 elif in_value > next_max_value: next_max_value = in_value for row in range(N): if values[row] == max_value and max_value_count == 1: print(next_max_value) else: print(max_value)
false
10
[ "-value_count_map = {}", "+max_value_count = 0", "- value_count = 0", "- if in_value in value_count_map:", "- value_count = value_count_map[in_value]", "- value_count_map[in_value] = value_count + 1", "- if in_value > max_value:", "+ if in_value == max_value:", "+ max_value_count = max_value_count + 1", "+ elif in_value > max_value:", "+ max_value_count = 1", "-max_value_count = value_count_map[max_value]" ]
false
0.077118
0.129255
0.59664
[ "s147960212", "s746682565" ]
u836737505
p03455
python
s439178753
s586245413
21
17
3,316
2,940
Accepted
Accepted
19.05
a,b = list(map(int, input().split())) print(("Odd" if (a*b)%2 else "Even"))
a,b = list(map(int, input().split())) print(("Odd" if a*b%2 else "Even"))
2
2
68
66
a, b = list(map(int, input().split())) print(("Odd" if (a * b) % 2 else "Even"))
a, b = list(map(int, input().split())) print(("Odd" if a * b % 2 else "Even"))
false
0
[ "-print((\"Odd\" if (a * b) % 2 else \"Even\"))", "+print((\"Odd\" if a * b % 2 else \"Even\"))" ]
false
0.044844
0.045508
0.985418
[ "s439178753", "s586245413" ]
u974792613
p02813
python
s733332903
s426143188
89
43
8,052
3,060
Accepted
Accepted
51.69
import itertools def checkArrays(arr1, arr2): if len(arr1) != len(arr2): return False for i in range(len(arr1)): if arr1[i] != arr2[i]: return False return True n = int(eval(input())) arrays = list(itertools.permutations([i for i in range(1, n + 1)])) p = list(map(int, input().split())) q = list(map(int, input().split())) a = b = 1 for i in range(len(arrays)): ar = list(arrays[i]) if checkArrays(ar, p): a = i + 1 if checkArrays(ar, q): b = i + 1 print((abs(a - b)))
import itertools n = int(eval(input())) array = [i for i in range(1, n + 1)] gen_array = itertools.permutations(array, n) a = list(map(int, input().split())) b = list(map(int, input().split())) idx = 1 for lis in gen_array: if list(lis) == a: num_a = idx if list(lis) == b: num_b = idx idx += 1 print((abs(num_a - num_b)))
31
19
571
366
import itertools def checkArrays(arr1, arr2): if len(arr1) != len(arr2): return False for i in range(len(arr1)): if arr1[i] != arr2[i]: return False return True n = int(eval(input())) arrays = list(itertools.permutations([i for i in range(1, n + 1)])) p = list(map(int, input().split())) q = list(map(int, input().split())) a = b = 1 for i in range(len(arrays)): ar = list(arrays[i]) if checkArrays(ar, p): a = i + 1 if checkArrays(ar, q): b = i + 1 print((abs(a - b)))
import itertools n = int(eval(input())) array = [i for i in range(1, n + 1)] gen_array = itertools.permutations(array, n) a = list(map(int, input().split())) b = list(map(int, input().split())) idx = 1 for lis in gen_array: if list(lis) == a: num_a = idx if list(lis) == b: num_b = idx idx += 1 print((abs(num_a - num_b)))
false
38.709677
[ "-", "-def checkArrays(arr1, arr2):", "- if len(arr1) != len(arr2):", "- return False", "- for i in range(len(arr1)):", "- if arr1[i] != arr2[i]:", "- return False", "- return True", "-", "-", "-arrays = list(itertools.permutations([i for i in range(1, n + 1)]))", "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-a = b = 1", "-for i in range(len(arrays)):", "- ar = list(arrays[i])", "- if checkArrays(ar, p):", "- a = i + 1", "- if checkArrays(ar, q):", "- b = i + 1", "-print((abs(a - b)))", "+array = [i for i in range(1, n + 1)]", "+gen_array = itertools.permutations(array, n)", "+a = list(map(int, input().split()))", "+b = list(map(int, input().split()))", "+idx = 1", "+for lis in gen_array:", "+ if list(lis) == a:", "+ num_a = idx", "+ if list(lis) == b:", "+ num_b = idx", "+ idx += 1", "+print((abs(num_a - num_b)))" ]
false
0.040084
0.040526
0.989092
[ "s733332903", "s426143188" ]
u163783894
p02605
python
s368115572
s162495743
1,828
1,666
274,340
276,236
Accepted
Accepted
8.86
import sys from collections import defaultdict import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_s = lambda: readline().rstrip().decode('utf-8') in_nl = lambda: list(map(int, readline().split())) in_nl2 = lambda H: [in_nl() for _ in range(H)] in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')] in_map2 = lambda H: [in_map() for _ in range(H)] in_all = lambda: list(map(int, read().split())) def main(): N = in_n() X = defaultdict(lambda: [[] for _ in range(4)]) Y = defaultdict(lambda: [[] for _ in range(4)]) XYp = defaultdict(lambda: [[] for _ in range(4)]) XYm = defaultdict(lambda: [[] for _ in range(4)]) urdl = ['U', 'R', 'D', 'L'] for i in range(N): x, y, u = in_s().split() x, y = int(x), int(y) u = urdl.index(u) X[y][u].append(x) Y[x][u].append(y) XYp[x + y][u].append(x) XYm[x - y][u].append(x) INF = 10**18 ans = INF for k in list(X.keys()): for i in range(4): X[k][i].sort() for k in list(X.keys()): for i in range(len(X[k][1])): now = X[k][1][i] j = bisect.bisect_left(X[k][3], now) if j < len(X[k][3]): next = X[k][3][j] ans = min(ans, (next - now) * 10 // 2) for k in list(Y.keys()): for i in range(4): Y[k][i].sort() for k in list(Y.keys()): for i in range(len(Y[k][0])): now = Y[k][0][i] j = bisect.bisect_left(Y[k][2], now) if j < len(Y[k][2]): next = Y[k][2][j] ans = min(ans, (next - now) * 10 // 2) for k in list(XYp.keys()): for i in range(4): XYp[k][i].sort() for k in list(XYp.keys()): # if len(XYp[k][1]) > 0 and len(XYp[k][0]) > 0: # print(k, XYp[k]) # if len(XYp[k][2]) > 0 and len(XYp[k][3]) > 0: # print(k, XYp[k]) for i in range(len(XYp[k][1])): now = XYp[k][1][i] j = bisect.bisect_left(XYp[k][0], now) if j < len(XYp[k][0]): next = XYp[k][0][j] ans = min(ans, (next - now) * 10) for i in range(len(XYp[k][2])): now = XYp[k][2][i] j = bisect.bisect_left(XYp[k][3], now) if j < len(XYp[k][3]): next = XYp[k][3][j] ans = min(ans, (next - now) * 10) for k in list(XYm.keys()): for i in range(4): XYm[k][i].sort() for k in list(XYm.keys()): # if len(XYm[k][1]) > 0 and len(XYm[k][2]) > 0: # print(k, XYm[k]) # if len(XYm[k][0]) > 0 and len(XYm[k][3]) > 0: # print(k, XYm[k]) for i in range(len(XYm[k][1])): now = XYm[k][1][i] j = bisect.bisect_left(XYm[k][2], now) if j < len(XYm[k][2]): next = XYm[k][2][j] ans = min(ans, (next - now) * 10) for i in range(len(XYm[k][0])): now = XYm[k][0][i] j = bisect.bisect_left(XYm[k][3], now) if j < len(XYm[k][3]): next = XYm[k][3][j] ans = min(ans, (next - now) * 10) # print(X) # print(Y) # print(XYp) # print(XYm) if ans == INF: print('SAFE') else: print(ans) if __name__ == '__main__': main()
from collections import defaultdict from bisect import bisect_left INF = 10**18 def calc(data, p, q): ret = INF for k in list(data.keys()): for i in range(len(data[k][p])): now = data[k][p][i] j = bisect_left(data[k][q], now) if j < len(data[k][q]): next = data[k][q][j] ret = min(ret, (next - now) * 10) return ret def main(): N = int(eval(input())) X = defaultdict(lambda: [[] for _ in range(4)]) Y = defaultdict(lambda: [[] for _ in range(4)]) XY_plus = defaultdict(lambda: [[] for _ in range(4)]) XY_minus = defaultdict(lambda: [[] for _ in range(4)]) URDL = ['U', 'R', 'D', 'L'] for i in range(N): x, y, u = input().split() x, y = int(x), int(y) u = URDL.index(u) X[y][u].append(x) Y[x][u].append(y) XY_plus[x + y][u].append(x) XY_minus[x - y][u].append(x) for s in (X, Y, XY_plus, XY_minus): for k in list(s.keys()): for i in range(4): s[k][i].sort() ans = INF ans = min(ans, calc(X, 1, 3) // 2) ans = min(ans, calc(Y, 0, 2) // 2) ans = min(ans, calc(XY_plus, 1, 0)) ans = min(ans, calc(XY_plus, 2, 3)) ans = min(ans, calc(XY_minus, 1, 2)) ans = min(ans, calc(XY_minus, 0, 3)) if ans >= 5000000: print('SAFE') else: print(ans) if __name__ == '__main__': main()
130
62
3,621
1,495
import sys from collections import defaultdict import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_s = lambda: readline().rstrip().decode("utf-8") in_nl = lambda: list(map(int, readline().split())) in_nl2 = lambda H: [in_nl() for _ in range(H)] in_map = lambda: [s == ord(".") for s in readline() if s != ord("\n")] in_map2 = lambda H: [in_map() for _ in range(H)] in_all = lambda: list(map(int, read().split())) def main(): N = in_n() X = defaultdict(lambda: [[] for _ in range(4)]) Y = defaultdict(lambda: [[] for _ in range(4)]) XYp = defaultdict(lambda: [[] for _ in range(4)]) XYm = defaultdict(lambda: [[] for _ in range(4)]) urdl = ["U", "R", "D", "L"] for i in range(N): x, y, u = in_s().split() x, y = int(x), int(y) u = urdl.index(u) X[y][u].append(x) Y[x][u].append(y) XYp[x + y][u].append(x) XYm[x - y][u].append(x) INF = 10**18 ans = INF for k in list(X.keys()): for i in range(4): X[k][i].sort() for k in list(X.keys()): for i in range(len(X[k][1])): now = X[k][1][i] j = bisect.bisect_left(X[k][3], now) if j < len(X[k][3]): next = X[k][3][j] ans = min(ans, (next - now) * 10 // 2) for k in list(Y.keys()): for i in range(4): Y[k][i].sort() for k in list(Y.keys()): for i in range(len(Y[k][0])): now = Y[k][0][i] j = bisect.bisect_left(Y[k][2], now) if j < len(Y[k][2]): next = Y[k][2][j] ans = min(ans, (next - now) * 10 // 2) for k in list(XYp.keys()): for i in range(4): XYp[k][i].sort() for k in list(XYp.keys()): # if len(XYp[k][1]) > 0 and len(XYp[k][0]) > 0: # print(k, XYp[k]) # if len(XYp[k][2]) > 0 and len(XYp[k][3]) > 0: # print(k, XYp[k]) for i in range(len(XYp[k][1])): now = XYp[k][1][i] j = bisect.bisect_left(XYp[k][0], now) if j < len(XYp[k][0]): next = XYp[k][0][j] ans = min(ans, (next - now) * 10) for i in range(len(XYp[k][2])): now = XYp[k][2][i] j = bisect.bisect_left(XYp[k][3], now) if j < len(XYp[k][3]): next = XYp[k][3][j] ans = min(ans, (next - now) * 10) for k in list(XYm.keys()): for i in range(4): XYm[k][i].sort() for k in list(XYm.keys()): # if len(XYm[k][1]) > 0 and len(XYm[k][2]) > 0: # print(k, XYm[k]) # if len(XYm[k][0]) > 0 and len(XYm[k][3]) > 0: # print(k, XYm[k]) for i in range(len(XYm[k][1])): now = XYm[k][1][i] j = bisect.bisect_left(XYm[k][2], now) if j < len(XYm[k][2]): next = XYm[k][2][j] ans = min(ans, (next - now) * 10) for i in range(len(XYm[k][0])): now = XYm[k][0][i] j = bisect.bisect_left(XYm[k][3], now) if j < len(XYm[k][3]): next = XYm[k][3][j] ans = min(ans, (next - now) * 10) # print(X) # print(Y) # print(XYp) # print(XYm) if ans == INF: print("SAFE") else: print(ans) if __name__ == "__main__": main()
from collections import defaultdict from bisect import bisect_left INF = 10**18 def calc(data, p, q): ret = INF for k in list(data.keys()): for i in range(len(data[k][p])): now = data[k][p][i] j = bisect_left(data[k][q], now) if j < len(data[k][q]): next = data[k][q][j] ret = min(ret, (next - now) * 10) return ret def main(): N = int(eval(input())) X = defaultdict(lambda: [[] for _ in range(4)]) Y = defaultdict(lambda: [[] for _ in range(4)]) XY_plus = defaultdict(lambda: [[] for _ in range(4)]) XY_minus = defaultdict(lambda: [[] for _ in range(4)]) URDL = ["U", "R", "D", "L"] for i in range(N): x, y, u = input().split() x, y = int(x), int(y) u = URDL.index(u) X[y][u].append(x) Y[x][u].append(y) XY_plus[x + y][u].append(x) XY_minus[x - y][u].append(x) for s in (X, Y, XY_plus, XY_minus): for k in list(s.keys()): for i in range(4): s[k][i].sort() ans = INF ans = min(ans, calc(X, 1, 3) // 2) ans = min(ans, calc(Y, 0, 2) // 2) ans = min(ans, calc(XY_plus, 1, 0)) ans = min(ans, calc(XY_plus, 2, 3)) ans = min(ans, calc(XY_minus, 1, 2)) ans = min(ans, calc(XY_minus, 0, 3)) if ans >= 5000000: print("SAFE") else: print(ans) if __name__ == "__main__": main()
false
52.307692
[ "-import sys", "-import bisect", "+from bisect import bisect_left", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "-in_n = lambda: int(readline())", "-in_nn = lambda: list(map(int, readline().split()))", "-in_s = lambda: readline().rstrip().decode(\"utf-8\")", "-in_nl = lambda: list(map(int, readline().split()))", "-in_nl2 = lambda H: [in_nl() for _ in range(H)]", "-in_map = lambda: [s == ord(\".\") for s in readline() if s != ord(\"\\n\")]", "-in_map2 = lambda H: [in_map() for _ in range(H)]", "-in_all = lambda: list(map(int, read().split()))", "+INF = 10**18", "+", "+", "+def calc(data, p, q):", "+ ret = INF", "+ for k in list(data.keys()):", "+ for i in range(len(data[k][p])):", "+ now = data[k][p][i]", "+ j = bisect_left(data[k][q], now)", "+ if j < len(data[k][q]):", "+ next = data[k][q][j]", "+ ret = min(ret, (next - now) * 10)", "+ return ret", "- N = in_n()", "+ N = int(eval(input()))", "- XYp = defaultdict(lambda: [[] for _ in range(4)])", "- XYm = defaultdict(lambda: [[] for _ in range(4)])", "- urdl = [\"U\", \"R\", \"D\", \"L\"]", "+ XY_plus = defaultdict(lambda: [[] for _ in range(4)])", "+ XY_minus = defaultdict(lambda: [[] for _ in range(4)])", "+ URDL = [\"U\", \"R\", \"D\", \"L\"]", "- x, y, u = in_s().split()", "+ x, y, u = input().split()", "- u = urdl.index(u)", "+ u = URDL.index(u)", "- XYp[x + y][u].append(x)", "- XYm[x - y][u].append(x)", "- INF = 10**18", "+ XY_plus[x + y][u].append(x)", "+ XY_minus[x - y][u].append(x)", "+ for s in (X, Y, XY_plus, XY_minus):", "+ for k in list(s.keys()):", "+ for i in range(4):", "+ s[k][i].sort()", "- for k in list(X.keys()):", "- for i in range(4):", "- X[k][i].sort()", "- for k in list(X.keys()):", "- for i in range(len(X[k][1])):", "- now = X[k][1][i]", "- j = bisect.bisect_left(X[k][3], now)", "- if j < len(X[k][3]):", "- next = X[k][3][j]", "- ans = min(ans, (next - now) * 10 // 2)", "- for k in list(Y.keys()):", "- for i in range(4):", "- Y[k][i].sort()", "- for k in list(Y.keys()):", "- for i in range(len(Y[k][0])):", "- now = Y[k][0][i]", "- j = bisect.bisect_left(Y[k][2], now)", "- if j < len(Y[k][2]):", "- next = Y[k][2][j]", "- ans = min(ans, (next - now) * 10 // 2)", "- for k in list(XYp.keys()):", "- for i in range(4):", "- XYp[k][i].sort()", "- for k in list(XYp.keys()):", "- # if len(XYp[k][1]) > 0 and len(XYp[k][0]) > 0:", "- # print(k, XYp[k])", "- # if len(XYp[k][2]) > 0 and len(XYp[k][3]) > 0:", "- # print(k, XYp[k])", "- for i in range(len(XYp[k][1])):", "- now = XYp[k][1][i]", "- j = bisect.bisect_left(XYp[k][0], now)", "- if j < len(XYp[k][0]):", "- next = XYp[k][0][j]", "- ans = min(ans, (next - now) * 10)", "- for i in range(len(XYp[k][2])):", "- now = XYp[k][2][i]", "- j = bisect.bisect_left(XYp[k][3], now)", "- if j < len(XYp[k][3]):", "- next = XYp[k][3][j]", "- ans = min(ans, (next - now) * 10)", "- for k in list(XYm.keys()):", "- for i in range(4):", "- XYm[k][i].sort()", "- for k in list(XYm.keys()):", "- # if len(XYm[k][1]) > 0 and len(XYm[k][2]) > 0:", "- # print(k, XYm[k])", "- # if len(XYm[k][0]) > 0 and len(XYm[k][3]) > 0:", "- # print(k, XYm[k])", "- for i in range(len(XYm[k][1])):", "- now = XYm[k][1][i]", "- j = bisect.bisect_left(XYm[k][2], now)", "- if j < len(XYm[k][2]):", "- next = XYm[k][2][j]", "- ans = min(ans, (next - now) * 10)", "- for i in range(len(XYm[k][0])):", "- now = XYm[k][0][i]", "- j = bisect.bisect_left(XYm[k][3], now)", "- if j < len(XYm[k][3]):", "- next = XYm[k][3][j]", "- ans = min(ans, (next - now) * 10)", "- # print(X)", "- # print(Y)", "- # print(XYp)", "- # print(XYm)", "- if ans == INF:", "+ ans = min(ans, calc(X, 1, 3) // 2)", "+ ans = min(ans, calc(Y, 0, 2) // 2)", "+ ans = min(ans, calc(XY_plus, 1, 0))", "+ ans = min(ans, calc(XY_plus, 2, 3))", "+ ans = min(ans, calc(XY_minus, 1, 2))", "+ ans = min(ans, calc(XY_minus, 0, 3))", "+ if ans >= 5000000:" ]
false
0.045313
0.049349
0.918223
[ "s368115572", "s162495743" ]
u282228874
p03029
python
s912554354
s515169951
21
17
3,316
2,940
Accepted
Accepted
19.05
a,p = list(map(int,input().split())) print(((3*a+p)//2))
a,b = list(map(int,input().split())) print(((3*a+b)//2))
2
2
49
49
a, p = list(map(int, input().split())) print(((3 * a + p) // 2))
a, b = list(map(int, input().split())) print(((3 * a + b) // 2))
false
0
[ "-a, p = list(map(int, input().split()))", "-print(((3 * a + p) // 2))", "+a, b = list(map(int, input().split()))", "+print(((3 * a + b) // 2))" ]
false
0.094507
0.101357
0.932419
[ "s912554354", "s515169951" ]
u794173881
p02768
python
s476512195
s535567403
348
197
54,260
54,256
Accepted
Accepted
43.39
class Combination: '''MOD上の 計算量:階乗・逆元テーブルの作成O(N) nCkを求めるO(1)''' def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)] self.MOD = MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD def combination2(self, k, r): """kCrを求める O(r) kが大きいときに使える """ if k < r: return 0 res = 1 for l in range(r): res *= (k - l) res %= self.MOD return (res * self.inv_fact[r]) % self.MOD n, a, b = list(map(int, input().split())) MOD = 10 ** 9 + 7 comb = Combination(2 * 10 ** 5 + 10, MOD) ptn_a = comb.combination2(n, a) ptn_b = comb.combination2(n, b) ptn_n = pow(2, n, MOD) - 1 print(((ptn_n - ptn_a - ptn_b) % MOD))
class Combination: """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う""" def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [0] * (n + 1) self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD) for i in reversed(list(range(n))): self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD self.MOD = MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD def combination2(self, k, r): """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用""" if k < r: return 0 res = 1 for l in range(r): res *= (k - l) res %= self.MOD return (res * self.inv_fact[r]) % self.MOD n, a, b = list(map(int, input().split())) MOD = 10 ** 9 + 7 comb = Combination(2 * 10 ** 5 + 10, MOD) all_ptn =pow(2, n, MOD) a_ptn = comb.combination2(n, a) b_ptn = comb.combination2(n, b) ans = (all_ptn - (a_ptn + b_ptn) - 1) % MOD print(ans)
53
53
1,412
1,537
class Combination: """MOD上の 計算量:階乗・逆元テーブルの作成O(N) nCkを求めるO(1)""" def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)] self.MOD = MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD def combination2(self, k, r): """kCrを求める O(r) kが大きいときに使える """ if k < r: return 0 res = 1 for l in range(r): res *= k - l res %= self.MOD return (res * self.inv_fact[r]) % self.MOD n, a, b = list(map(int, input().split())) MOD = 10**9 + 7 comb = Combination(2 * 10**5 + 10, MOD) ptn_a = comb.combination2(n, a) ptn_b = comb.combination2(n, b) ptn_n = pow(2, n, MOD) - 1 print(((ptn_n - ptn_a - ptn_b) % MOD))
class Combination: """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う""" def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [0] * (n + 1) self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD) for i in reversed(list(range(n))): self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD self.MOD = MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD def combination2(self, k, r): """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用""" if k < r: return 0 res = 1 for l in range(r): res *= k - l res %= self.MOD return (res * self.inv_fact[r]) % self.MOD n, a, b = list(map(int, input().split())) MOD = 10**9 + 7 comb = Combination(2 * 10**5 + 10, MOD) all_ptn = pow(2, n, MOD) a_ptn = comb.combination2(n, a) b_ptn = comb.combination2(n, b) ans = (all_ptn - (a_ptn + b_ptn) - 1) % MOD print(ans)
false
0
[ "- \"\"\"MOD上の", "- 計算量:階乗・逆元テーブルの作成O(N)", "- nCkを求めるO(1)\"\"\"", "+ \"\"\"階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う\"\"\"", "- self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]", "+ self.inv_fact = [0] * (n + 1)", "+ self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)", "+ for i in reversed(list(range(n))):", "+ self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD", "- return (self.fact[k] * self.inv_fact[r]) % self.MOD", "+ return (self.fact[k] * self.inv_fact[k - r]) % self.MOD", "- \"\"\"kCrを求める O(r)", "- kが大きいときに使える", "- \"\"\"", "+ \"\"\"kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用\"\"\"", "-ptn_a = comb.combination2(n, a)", "-ptn_b = comb.combination2(n, b)", "-ptn_n = pow(2, n, MOD) - 1", "-print(((ptn_n - ptn_a - ptn_b) % MOD))", "+all_ptn = pow(2, n, MOD)", "+a_ptn = comb.combination2(n, a)", "+b_ptn = comb.combination2(n, b)", "+ans = (all_ptn - (a_ptn + b_ptn) - 1) % MOD", "+print(ans)" ]
false
1.471592
0.263942
5.575432
[ "s476512195", "s535567403" ]
u580977620
p02402
python
s866573324
s898812406
50
10
7,124
5,404
Accepted
Accepted
80
n = int(input()) a = list(map(int, input().split())) print(min(a), max(a), sum(a))
N = eval(input()) l = list(map(int, input().split())) print(('%d %d %d' % (min(l), max(l), sum(l))))
4
5
87
98
n = int(input()) a = list(map(int, input().split())) print(min(a), max(a), sum(a))
N = eval(input()) l = list(map(int, input().split())) print(("%d %d %d" % (min(l), max(l), sum(l))))
false
20
[ "-n = int(input())", "-a = list(map(int, input().split()))", "-print(min(a), max(a), sum(a))", "+N = eval(input())", "+l = list(map(int, input().split()))", "+print((\"%d %d %d\" % (min(l), max(l), sum(l))))" ]
false
0.036999
0.036286
1.01965
[ "s866573324", "s898812406" ]
u638456847
p02685
python
s749223274
s768055265
852
317
9,220
32,956
Accepted
Accepted
62.79
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines # 0^0 = 1 def main(): N,M,K = list(map(int, readline().split())) MOD = 998244353 if M == 1: if K == N - 1: print((1)) else: print((0)) exit() m = pow(M-1, N-1, MOD) m_1_inv = pow(M-1, MOD-2, MOD) comb = 1 ans = comb * m for k in range(1,K+1): m *= m_1_inv m %= MOD comb *= N - k comb %= MOD comb *= pow(k, MOD-2, MOD) ans += (m * comb) % MOD ans %= MOD print((ans * M % MOD)) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines fac = [1, 1] # 元テーブル f_inv = [1, 1] # 逆元テーブル inv = [0, 1] # 逆元テーブル計算用テーブル def prepare(n, mod): for i in range(2, n+1): fac.append((fac[-1] * i) % mod) inv.append((-inv[mod % i] * (mod//i)) % mod) f_inv.append((f_inv[-1] * inv[-1]) % mod) def cmb(n, r, mod): if n < 0 or r < 0: return 0 if r > n: return 0 return fac[n] * f_inv[r] * f_inv[n-r] % mod def main(): N,M,K = list(map(int, readline().split())) MOD = 998244353 if M == 1: if K == N - 1: print((1)) else: print((0)) exit() prepare(N + 10, MOD) m = pow(M-1, N-1, MOD) m_inv = pow(M-1, MOD-2, MOD) ans = 0 for k in range(K+1): ans += (cmb(N-1, k, MOD) * m) % MOD ans %= MOD m *= m_inv m %= MOD print((ans * M % MOD)) if __name__ == "__main__": main()
38
53
691
1,046
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines # 0^0 = 1 def main(): N, M, K = list(map(int, readline().split())) MOD = 998244353 if M == 1: if K == N - 1: print((1)) else: print((0)) exit() m = pow(M - 1, N - 1, MOD) m_1_inv = pow(M - 1, MOD - 2, MOD) comb = 1 ans = comb * m for k in range(1, K + 1): m *= m_1_inv m %= MOD comb *= N - k comb %= MOD comb *= pow(k, MOD - 2, MOD) ans += (m * comb) % MOD ans %= MOD print((ans * M % MOD)) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines fac = [1, 1] # 元テーブル f_inv = [1, 1] # 逆元テーブル inv = [0, 1] # 逆元テーブル計算用テーブル def prepare(n, mod): for i in range(2, n + 1): fac.append((fac[-1] * i) % mod) inv.append((-inv[mod % i] * (mod // i)) % mod) f_inv.append((f_inv[-1] * inv[-1]) % mod) def cmb(n, r, mod): if n < 0 or r < 0: return 0 if r > n: return 0 return fac[n] * f_inv[r] * f_inv[n - r] % mod def main(): N, M, K = list(map(int, readline().split())) MOD = 998244353 if M == 1: if K == N - 1: print((1)) else: print((0)) exit() prepare(N + 10, MOD) m = pow(M - 1, N - 1, MOD) m_inv = pow(M - 1, MOD - 2, MOD) ans = 0 for k in range(K + 1): ans += (cmb(N - 1, k, MOD) * m) % MOD ans %= MOD m *= m_inv m %= MOD print((ans * M % MOD)) if __name__ == "__main__": main()
false
28.301887
[ "-# 0^0 = 1", "+fac = [1, 1] # 元テーブル", "+f_inv = [1, 1] # 逆元テーブル", "+inv = [0, 1] # 逆元テーブル計算用テーブル", "+", "+", "+def prepare(n, mod):", "+ for i in range(2, n + 1):", "+ fac.append((fac[-1] * i) % mod)", "+ inv.append((-inv[mod % i] * (mod // i)) % mod)", "+ f_inv.append((f_inv[-1] * inv[-1]) % mod)", "+", "+", "+def cmb(n, r, mod):", "+ if n < 0 or r < 0:", "+ return 0", "+ if r > n:", "+ return 0", "+ return fac[n] * f_inv[r] * f_inv[n - r] % mod", "+", "+", "+ prepare(N + 10, MOD)", "- m_1_inv = pow(M - 1, MOD - 2, MOD)", "- comb = 1", "- ans = comb * m", "- for k in range(1, K + 1):", "- m *= m_1_inv", "+ m_inv = pow(M - 1, MOD - 2, MOD)", "+ ans = 0", "+ for k in range(K + 1):", "+ ans += (cmb(N - 1, k, MOD) * m) % MOD", "+ ans %= MOD", "+ m *= m_inv", "- comb *= N - k", "- comb %= MOD", "- comb *= pow(k, MOD - 2, MOD)", "- ans += (m * comb) % MOD", "- ans %= MOD" ]
false
0.066548
0.155516
0.427917
[ "s749223274", "s768055265" ]
u489959379
p02803
python
s706876570
s337413299
239
219
9,376
10,488
Accepted
Accepted
8.37
import sys from collections import deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] start = [] for h in range(H): for w in range(W): if S[h][w] != "#": start.append([h, w]) res = 0 for sh, sw in start: maze = [[f_inf] * W for _ in range(H)] maze[sh][sw] = 0 que = deque([[sh, sw]]) while que: h, w = que.popleft() for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]: next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W: continue elif S[next_h][next_w] == "#": continue else: if maze[next_h][next_w] > maze[h][w] + 1: maze[next_h][next_w] = maze[h][w] + 1 que.append([next_h, next_w]) ma = 0 for h in range(H): for w in range(W): if S[h][w] != "#": ma = max(ma, maze[h][w]) res = max(res, ma) print(res) if __name__ == '__main__': resolve()
import sys from collections import deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = list(map(int, input().split())) grid = [eval(input()) for _ in range(H)] res = [] for sh in range(H): for sw in range(W): if grid[sh][sw] == "#": continue maze = [[f_inf] * W for _ in range(H)] maze[sh][sw] = 0 que = deque([[sh, sw]]) while que: h, w = que.popleft() for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)): next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W or grid[next_h][ next_w] == "#": continue if maze[next_h][next_w] > maze[h][w] + 1: maze[next_h][next_w] = maze[h][w] + 1 que.append([next_h, next_w]) res.append(maze[next_h][next_w]) print((max(res))) if __name__ == '__main__': resolve()
46
36
1,308
1,126
import sys from collections import deque sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): H, W = list(map(int, input().split())) S = [list(eval(input())) for _ in range(H)] start = [] for h in range(H): for w in range(W): if S[h][w] != "#": start.append([h, w]) res = 0 for sh, sw in start: maze = [[f_inf] * W for _ in range(H)] maze[sh][sw] = 0 que = deque([[sh, sw]]) while que: h, w = que.popleft() for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]: next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W: continue elif S[next_h][next_w] == "#": continue else: if maze[next_h][next_w] > maze[h][w] + 1: maze[next_h][next_w] = maze[h][w] + 1 que.append([next_h, next_w]) ma = 0 for h in range(H): for w in range(W): if S[h][w] != "#": ma = max(ma, maze[h][w]) res = max(res, ma) print(res) if __name__ == "__main__": resolve()
import sys from collections import deque sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): H, W = list(map(int, input().split())) grid = [eval(input()) for _ in range(H)] res = [] for sh in range(H): for sw in range(W): if grid[sh][sw] == "#": continue maze = [[f_inf] * W for _ in range(H)] maze[sh][sw] = 0 que = deque([[sh, sw]]) while que: h, w = que.popleft() for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)): next_h, next_w = h + dh, w + dw if ( next_h < 0 or next_h >= H or next_w < 0 or next_w >= W or grid[next_h][next_w] == "#" ): continue if maze[next_h][next_w] > maze[h][w] + 1: maze[next_h][next_w] = maze[h][w] + 1 que.append([next_h, next_w]) res.append(maze[next_h][next_w]) print((max(res))) if __name__ == "__main__": resolve()
false
21.73913
[ "- S = [list(eval(input())) for _ in range(H)]", "- start = []", "- for h in range(H):", "- for w in range(W):", "- if S[h][w] != \"#\":", "- start.append([h, w])", "- res = 0", "- for sh, sw in start:", "- maze = [[f_inf] * W for _ in range(H)]", "- maze[sh][sw] = 0", "- que = deque([[sh, sw]])", "- while que:", "- h, w = que.popleft()", "- for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:", "- next_h, next_w = h + dh, w + dw", "- if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:", "- continue", "- elif S[next_h][next_w] == \"#\":", "- continue", "- else:", "+ grid = [eval(input()) for _ in range(H)]", "+ res = []", "+ for sh in range(H):", "+ for sw in range(W):", "+ if grid[sh][sw] == \"#\":", "+ continue", "+ maze = [[f_inf] * W for _ in range(H)]", "+ maze[sh][sw] = 0", "+ que = deque([[sh, sw]])", "+ while que:", "+ h, w = que.popleft()", "+ for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):", "+ next_h, next_w = h + dh, w + dw", "+ if (", "+ next_h < 0", "+ or next_h >= H", "+ or next_w < 0", "+ or next_w >= W", "+ or grid[next_h][next_w] == \"#\"", "+ ):", "+ continue", "- ma = 0", "- for h in range(H):", "- for w in range(W):", "- if S[h][w] != \"#\":", "- ma = max(ma, maze[h][w])", "- res = max(res, ma)", "- print(res)", "+ res.append(maze[next_h][next_w])", "+ print((max(res)))" ]
false
0.036092
0.035582
1.014314
[ "s706876570", "s337413299" ]
u222668979
p02579
python
s669365386
s173180534
1,228
1,083
98,356
96,700
Accepted
Accepted
11.81
from collections import deque from itertools import product def bfs(x, y): dist = [[10 ** 9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) while len(que) > 0: x, y = que.popleft() num = product([-2, -1, 0, 1, 2], repeat=2) near = [(x + dx, y + dy) for dx, dy in num] if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for i, j in near: cnt = (abs(x - i) + abs(y - j) >= 2) if (0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
from collections import deque from itertools import product def bfs(x, y): dist = [[10 ** 9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for i, j in product(list(range(-2, 3)), repeat=2): cnt = (abs(i) + abs(j) >= 2) i, j = x + i, y + j if (0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
34
33
986
933
from collections import deque from itertools import product def bfs(x, y): dist = [[10**9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) while len(que) > 0: x, y = que.popleft() num = product([-2, -1, 0, 1, 2], repeat=2) near = [(x + dx, y + dy) for dx, dy in num] if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for i, j in near: cnt = abs(x - i) + abs(y - j) >= 2 if ( 0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == "." ): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
from collections import deque from itertools import product def bfs(x, y): dist = [[10**9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for i, j in product(list(range(-2, 3)), repeat=2): cnt = abs(i) + abs(j) >= 2 i, j = x + i, y + j if ( 0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == "." ): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
false
2.941176
[ "- num = product([-2, -1, 0, 1, 2], repeat=2)", "- near = [(x + dx, y + dy) for dx, dy in num]", "- for i, j in near:", "- cnt = abs(x - i) + abs(y - j) >= 2", "+ for i, j in product(list(range(-2, 3)), repeat=2):", "+ cnt = abs(i) + abs(j) >= 2", "+ i, j = x + i, y + j" ]
false
0.097809
0.035844
2.728757
[ "s669365386", "s173180534" ]
u080364835
p03160
python
s462646077
s551774266
133
123
13,928
13,976
Accepted
Accepted
7.52
n = int(eval(input())) hl = list(map(int, input().split())) cost = [0] * n cost[0] = 0 cost[1] = abs(hl[0] - hl[1]) for i in range(2, n): cost[i] = (min(cost[i-1] + abs(hl[i] - hl[i-1]), (cost[i-2] + abs(hl[i] - hl[i-2])))) print((cost[-1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [1001001001] * n cost[0] = 0 cost[1] = abs(h[1] - h[0]) for i in range(2, n): cost[i] = min((cost[i-2] + abs(h[i] - h[i-2])), cost[i-1] + abs(h[i] - h[i-1])) print((cost[-1]))
13
12
276
269
n = int(eval(input())) hl = list(map(int, input().split())) cost = [0] * n cost[0] = 0 cost[1] = abs(hl[0] - hl[1]) for i in range(2, n): cost[i] = min( cost[i - 1] + abs(hl[i] - hl[i - 1]), (cost[i - 2] + abs(hl[i] - hl[i - 2])) ) print((cost[-1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [1001001001] * n cost[0] = 0 cost[1] = abs(h[1] - h[0]) for i in range(2, n): cost[i] = min( (cost[i - 2] + abs(h[i] - h[i - 2])), cost[i - 1] + abs(h[i] - h[i - 1]) ) print((cost[-1]))
false
7.692308
[ "-hl = list(map(int, input().split()))", "-cost = [0] * n", "+h = list(map(int, input().split()))", "+cost = [1001001001] * n", "-cost[1] = abs(hl[0] - hl[1])", "+cost[1] = abs(h[1] - h[0])", "- cost[i - 1] + abs(hl[i] - hl[i - 1]), (cost[i - 2] + abs(hl[i] - hl[i - 2]))", "+ (cost[i - 2] + abs(h[i] - h[i - 2])), cost[i - 1] + abs(h[i] - h[i - 1])" ]
false
0.044989
0.088904
0.506046
[ "s462646077", "s551774266" ]
u581187895
p03485
python
s162120438
s594668479
151
17
12,392
2,940
Accepted
Accepted
88.74
import math import numpy as np arr = list(map(int, input().split())) print((math.ceil(np.mean(arr))))
a, b = list(map(int, input().split())) print((-(-(a+b)//2)))
4
2
103
54
import math import numpy as np arr = list(map(int, input().split())) print((math.ceil(np.mean(arr))))
a, b = list(map(int, input().split())) print((-(-(a + b) // 2)))
false
50
[ "-import math", "-import numpy as np", "-", "-arr = list(map(int, input().split()))", "-print((math.ceil(np.mean(arr))))", "+a, b = list(map(int, input().split()))", "+print((-(-(a + b) // 2)))" ]
false
0.235674
0.045974
5.126249
[ "s162120438", "s594668479" ]
u662841603
p03808
python
s598634005
s426584874
177
104
11,348
11,348
Accepted
Accepted
41.24
import sys n = eval(input()) v = list(map(int, input().split(' '))) startHere = [0 for i in range(n)] if sum(v) % ((n * (n + 1)) / 2) != 0: print("NO") sys.exit() operations = sum(v) / ((n * (n + 1)) / 2) for i in range(n): diff = v[(i + 1) % n] - v[i] startHere[i] = (operations - diff) / n contribution = 0 gathered = 0 for i in range(n): v[i] -= contribution gathered += startHere[i % n] contribution += gathered for i in range(n): v[i] -= contribution gathered -= startHere[i % n] contribution -= startHere[i % n] * n contribution += gathered if min(startHere) >= 0 and sum(startHere) == operations and min(v) == 0 and max(v) == 0: print("YES") else: print("NO")
import sys n = eval(input()) v = list(map(int, input().split(' '))) startHere = [0 for i in range(n)] if sum(v) % ((n * (n + 1)) / 2) != 0: print("NO") sys.exit() operations = sum(v) / ((n * (n + 1)) / 2) operationsFound = 0 for i in range(n): diff = v[(i + 1) % n] - v[i] if (operations - diff) % n != 0 or operations - diff < 0: print("NO") sys.exit() else: operationsFound += (operations - diff) / n if operationsFound == operations: print("YES") else: print("NO")
35
26
712
500
import sys n = eval(input()) v = list(map(int, input().split(" "))) startHere = [0 for i in range(n)] if sum(v) % ((n * (n + 1)) / 2) != 0: print("NO") sys.exit() operations = sum(v) / ((n * (n + 1)) / 2) for i in range(n): diff = v[(i + 1) % n] - v[i] startHere[i] = (operations - diff) / n contribution = 0 gathered = 0 for i in range(n): v[i] -= contribution gathered += startHere[i % n] contribution += gathered for i in range(n): v[i] -= contribution gathered -= startHere[i % n] contribution -= startHere[i % n] * n contribution += gathered if min(startHere) >= 0 and sum(startHere) == operations and min(v) == 0 and max(v) == 0: print("YES") else: print("NO")
import sys n = eval(input()) v = list(map(int, input().split(" "))) startHere = [0 for i in range(n)] if sum(v) % ((n * (n + 1)) / 2) != 0: print("NO") sys.exit() operations = sum(v) / ((n * (n + 1)) / 2) operationsFound = 0 for i in range(n): diff = v[(i + 1) % n] - v[i] if (operations - diff) % n != 0 or operations - diff < 0: print("NO") sys.exit() else: operationsFound += (operations - diff) / n if operationsFound == operations: print("YES") else: print("NO")
false
25.714286
[ "+operationsFound = 0", "- startHere[i] = (operations - diff) / n", "-contribution = 0", "-gathered = 0", "-for i in range(n):", "- v[i] -= contribution", "- gathered += startHere[i % n]", "- contribution += gathered", "-for i in range(n):", "- v[i] -= contribution", "- gathered -= startHere[i % n]", "- contribution -= startHere[i % n] * n", "- contribution += gathered", "-if min(startHere) >= 0 and sum(startHere) == operations and min(v) == 0 and max(v) == 0:", "+ if (operations - diff) % n != 0 or operations - diff < 0:", "+ print(\"NO\")", "+ sys.exit()", "+ else:", "+ operationsFound += (operations - diff) / n", "+if operationsFound == operations:" ]
false
0.044215
0.058786
0.752129
[ "s598634005", "s426584874" ]
u375616706
p02845
python
s131840178
s575549372
251
224
52,952
52,908
Accepted
Accepted
10.76
N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9+7 ans = 1 dp = [0]*3 for a in A: cnt = 0 for i in range(3): if a == dp[i]: cnt += 1 for i in range(3): if a == dp[i]: dp[i] += 1 break ans = ans*cnt % MOD print(ans)
N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9+7 ans = 1 dp = [0]*3 for a in A: ans = ans*dp.count(a) % MOD try: dp[dp.index(a)] += 1 except ValueError: break print(ans)
17
13
316
229
N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9 + 7 ans = 1 dp = [0] * 3 for a in A: cnt = 0 for i in range(3): if a == dp[i]: cnt += 1 for i in range(3): if a == dp[i]: dp[i] += 1 break ans = ans * cnt % MOD print(ans)
N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9 + 7 ans = 1 dp = [0] * 3 for a in A: ans = ans * dp.count(a) % MOD try: dp[dp.index(a)] += 1 except ValueError: break print(ans)
false
23.529412
[ "- cnt = 0", "- for i in range(3):", "- if a == dp[i]:", "- cnt += 1", "- for i in range(3):", "- if a == dp[i]:", "- dp[i] += 1", "- break", "- ans = ans * cnt % MOD", "+ ans = ans * dp.count(a) % MOD", "+ try:", "+ dp[dp.index(a)] += 1", "+ except ValueError:", "+ break" ]
false
0.043901
0.044363
0.989573
[ "s131840178", "s575549372" ]
u604774382
p02417
python
s714833017
s459335202
30
10
6,724
4,236
Accepted
Accepted
66.67
import sys chash = {} for i in range( ord( 'a' ), ord( 'z' )+1 ): chash[ chr( i ) ] = 0 for line in sys.stdin: for i in range( len( line ) ): if line[i].isalpha(): chash[ line[i].lower() ] += 1 for i in range( ord( 'a' ), ord( 'z' )+1 ): print(( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) ))
import sys chash = {} for i in range( ord( 'a' ), ord( 'z' )+1 ): chash[ chr( i ) ] = 0 while True: line = sys.stdin.readline().rstrip() if not line: break for i in range( len( line ) ): if line[i].isalpha(): chash[ line[i].lower() ] += 1 for i in range( ord( 'a' ), ord( 'z' )+1 ): print(( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) ))
13
16
348
412
import sys chash = {} for i in range(ord("a"), ord("z") + 1): chash[chr(i)] = 0 for line in sys.stdin: for i in range(len(line)): if line[i].isalpha(): chash[line[i].lower()] += 1 for i in range(ord("a"), ord("z") + 1): print(("{:s} : {:d}".format(chr(i), chash[chr(i)])))
import sys chash = {} for i in range(ord("a"), ord("z") + 1): chash[chr(i)] = 0 while True: line = sys.stdin.readline().rstrip() if not line: break for i in range(len(line)): if line[i].isalpha(): chash[line[i].lower()] += 1 for i in range(ord("a"), ord("z") + 1): print(("{:s} : {:d}".format(chr(i), chash[chr(i)])))
false
18.75
[ "-for line in sys.stdin:", "+while True:", "+ line = sys.stdin.readline().rstrip()", "+ if not line:", "+ break" ]
false
0.036132
0.040919
0.883026
[ "s714833017", "s459335202" ]
u075595666
p03040
python
s704353227
s384022863
1,888
730
124,880
109,140
Accepted
Accepted
61.33
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline from bisect import insort class BIT(): def __init__(self, n): ''' n = 要素数 添字は i = 0 ~ n-1 となる ''' self.n = n self.bit = [0] * (n + 1) def add(self, i, x): '''i番目の要素にxを加算する''' i = i + 1 while i <= self.n: self.bit[i] += x i += i & -i def _sum(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def get(self, i, j): '''[i, j)の和を求める''' return self._sum(j) - self._sum(i) def compress(list1): list2 = sorted(set(list1)) memo = {value : index for index, value in enumerate(list2)} return memo, len(list2) q = int(readline()) info = [list(map(int, input().split())) for i in range(q)] #座圧する li1 = [] for i in range(q): if info[i][0] == 1: li1.append(info[i][1]) memo, len_memo = compress(li1) def median(): ok = len_memo ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if 2 * bit1.get(mid, len_memo) <= cnt : ok = mid else: ng = mid return memo_inv[ng] #値を管理するBIT bit = BIT(len_memo) #要素数を管理するBITに bit1 = BIT(len_memo) memo_inv = dict([(v,k) for k,v in list(memo.items())]) s = 0 cnt = 0 for i in range(q): que = info[i] if que[0] == 1: a,b,c = que s += c cnt += 1 bit.add(memo[b],b) bit1.add(memo[b], 1) else: d = median() sum1 = bit.get(0, memo[d]) num1 = bit1.get(0, memo[d]) sum2 = bit.get(memo[d], len_memo) num2 = bit1.get(memo[d], len_memo) print((d, abs(num1*d- sum1) + abs(num2*d - sum2) + s))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1 def compress(list1): list2 = sorted(set(list1)) memo = {value : index for index, value in enumerate(list2)} return memo, len(list2) q = int(readline()) L = [list(map(int,readline().split())) for i in range(q)] #座圧する chk = [] for i in range(q): if L[i][0] == 1: chk.append(L[i][1]) memo, len_memo = compress(chk) memo_inv = dict([(v,k) for k,v in list(memo.items())]) #値を管理するBIT bit = Bit(len_memo) #要素数を管理するBIT num = Bit(len_memo) s = 0 cnt = 0 for i in range(q): que = L[i] if que[0] == 1: a,b,c = que s += c cnt += 1 bit.add(memo[b]+1,b) num.add(memo[b]+1,1) else: d = num.lower_bound((cnt+1)//2) m = memo_inv[d-1] sum1 = bit.sum(d) num1 = num.sum(d) sum2 = bit.sum(len_memo)-bit.sum(d) num2 = num.sum(len_memo)-num.sum(d) print((m,abs(num1*m-sum1)+abs(num2*m-sum2)+s))
83
73
1,812
1,717
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline from bisect import insort class BIT: def __init__(self, n): """ n = 要素数 添字は i = 0 ~ n-1 となる """ self.n = n self.bit = [0] * (n + 1) def add(self, i, x): """i番目の要素にxを加算する""" i = i + 1 while i <= self.n: self.bit[i] += x i += i & -i def _sum(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def get(self, i, j): """[i, j)の和を求める""" return self._sum(j) - self._sum(i) def compress(list1): list2 = sorted(set(list1)) memo = {value: index for index, value in enumerate(list2)} return memo, len(list2) q = int(readline()) info = [list(map(int, input().split())) for i in range(q)] # 座圧する li1 = [] for i in range(q): if info[i][0] == 1: li1.append(info[i][1]) memo, len_memo = compress(li1) def median(): ok = len_memo ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if 2 * bit1.get(mid, len_memo) <= cnt: ok = mid else: ng = mid return memo_inv[ng] # 値を管理するBIT bit = BIT(len_memo) # 要素数を管理するBITに bit1 = BIT(len_memo) memo_inv = dict([(v, k) for k, v in list(memo.items())]) s = 0 cnt = 0 for i in range(q): que = info[i] if que[0] == 1: a, b, c = que s += c cnt += 1 bit.add(memo[b], b) bit1.add(memo[b], 1) else: d = median() sum1 = bit.get(0, memo[d]) num1 = bit1.get(0, memo[d]) sum2 = bit.get(memo[d], len_memo) num2 = bit1.get(memo[d], len_memo) print((d, abs(num1 * d - sum1) + abs(num2 * d - sum2) + s))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): """累積和がx以上になる最小のindexと、その直前までの累積和""" sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1 def compress(list1): list2 = sorted(set(list1)) memo = {value: index for index, value in enumerate(list2)} return memo, len(list2) q = int(readline()) L = [list(map(int, readline().split())) for i in range(q)] # 座圧する chk = [] for i in range(q): if L[i][0] == 1: chk.append(L[i][1]) memo, len_memo = compress(chk) memo_inv = dict([(v, k) for k, v in list(memo.items())]) # 値を管理するBIT bit = Bit(len_memo) # 要素数を管理するBIT num = Bit(len_memo) s = 0 cnt = 0 for i in range(q): que = L[i] if que[0] == 1: a, b, c = que s += c cnt += 1 bit.add(memo[b] + 1, b) num.add(memo[b] + 1, 1) else: d = num.lower_bound((cnt + 1) // 2) m = memo_inv[d - 1] sum1 = bit.sum(d) num1 = num.sum(d) sum2 = bit.sum(len_memo) - bit.sum(d) num2 = num.sum(len_memo) - num.sum(d) print((m, abs(num1 * m - sum1) + abs(num2 * m - sum2) + s))
false
12.048193
[ "-from bisect import insort", "-class BIT:", "+class Bit:", "- \"\"\"", "- n = 要素数", "- 添字は i = 0 ~ n-1 となる", "- \"\"\"", "- self.n = n", "- self.bit = [0] * (n + 1)", "+ self.size = n", "+ self.tree = [0] * (n + 1)", "+ self.depth = n.bit_length()", "- def add(self, i, x):", "- \"\"\"i番目の要素にxを加算する\"\"\"", "- i = i + 1", "- while i <= self.n:", "- self.bit[i] += x", "- i += i & -i", "-", "- def _sum(self, i):", "+ def sum(self, i):", "- s += self.bit[i]", "+ s += self.tree[i]", "- def get(self, i, j):", "- \"\"\"[i, j)の和を求める\"\"\"", "- return self._sum(j) - self._sum(i)", "+ def add(self, i, x):", "+ while i <= self.size:", "+ self.tree[i] += x", "+ i += i & -i", "+", "+ def lower_bound(self, x):", "+ \"\"\"累積和がx以上になる最小のindexと、その直前までの累積和\"\"\"", "+ sum_ = 0", "+ pos = 0", "+ for i in range(self.depth, -1, -1):", "+ k = pos + (1 << i)", "+ if k <= self.size and sum_ + self.tree[k] < x:", "+ sum_ += self.tree[k]", "+ pos += 1 << i", "+ return pos + 1", "-info = [list(map(int, input().split())) for i in range(q)]", "+L = [list(map(int, readline().split())) for i in range(q)]", "-li1 = []", "+chk = []", "- if info[i][0] == 1:", "- li1.append(info[i][1])", "-memo, len_memo = compress(li1)", "-", "-", "-def median():", "- ok = len_memo", "- ng = 0", "- while abs(ok - ng) > 1:", "- mid = (ok + ng) // 2", "- if 2 * bit1.get(mid, len_memo) <= cnt:", "- ok = mid", "- else:", "- ng = mid", "- return memo_inv[ng]", "-", "-", "+ if L[i][0] == 1:", "+ chk.append(L[i][1])", "+memo, len_memo = compress(chk)", "+memo_inv = dict([(v, k) for k, v in list(memo.items())])", "-bit = BIT(len_memo)", "-# 要素数を管理するBITに", "-bit1 = BIT(len_memo)", "-memo_inv = dict([(v, k) for k, v in list(memo.items())])", "+bit = Bit(len_memo)", "+# 要素数を管理するBIT", "+num = Bit(len_memo)", "- que = info[i]", "+ que = L[i]", "- bit.add(memo[b], b)", "- bit1.add(memo[b], 1)", "+ bit.add(memo[b] + 1, b)", "+ num.add(memo[b] + 1, 1)", "- d = median()", "- sum1 = bit.get(0, memo[d])", "- num1 = bit1.get(0, memo[d])", "- sum2 = bit.get(memo[d], len_memo)", "- num2 = bit1.get(memo[d], len_memo)", "- print((d, abs(num1 * d - sum1) + abs(num2 * d - sum2) + s))", "+ d = num.lower_bound((cnt + 1) // 2)", "+ m = memo_inv[d - 1]", "+ sum1 = bit.sum(d)", "+ num1 = num.sum(d)", "+ sum2 = bit.sum(len_memo) - bit.sum(d)", "+ num2 = num.sum(len_memo) - num.sum(d)", "+ print((m, abs(num1 * m - sum1) + abs(num2 * m - sum2) + s))" ]
false
0.08278
0.09225
0.897345
[ "s704353227", "s384022863" ]
u324314500
p03073
python
s978114328
s451738883
52
44
3,188
3,188
Accepted
Accepted
15.38
import sys def i2s(): return sys.stdin.readline() def ii2ss(n): return [sys.stdin.readline() for _ in range(n)] def sp2nn(sp, sep=' '): return [int(s) for s in sp.split(sep)] def ss2nn(ss): return [int(s) for s in list(ss)] def main(S): S = S.rstrip() c0 = 0 c1 = 0 for i, s in enumerate(S): if (i % 2) == int(s): c0 += 1 else: c1 += 1 cmin = min(c0, c1) print(cmin) main(i2s())
# AtCoder Beginner Contest 124 # https://atcoder.jp/contests/abc124 import sys s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)] ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(S): n1 = 0 n2 = 0 for i in range(len(S)): if i % 2 == 0: if S[i] == '0': n1 += 1 else: n2 += 1 if i % 2 == 1: if S[i] == '1': n1 += 1 else: n2 += 1 n = min(n1, n2) print(n) S = i2s() main(S)
27
32
490
794
import sys def i2s(): return sys.stdin.readline() def ii2ss(n): return [sys.stdin.readline() for _ in range(n)] def sp2nn(sp, sep=" "): return [int(s) for s in sp.split(sep)] def ss2nn(ss): return [int(s) for s in list(ss)] def main(S): S = S.rstrip() c0 = 0 c1 = 0 for i, s in enumerate(S): if (i % 2) == int(s): c0 += 1 else: c1 += 1 cmin = min(c0, c1) print(cmin) main(i2s())
# AtCoder Beginner Contest 124 # https://atcoder.jp/contests/abc124 import sys s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)] ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(S): n1 = 0 n2 = 0 for i in range(len(S)): if i % 2 == 0: if S[i] == "0": n1 += 1 else: n2 += 1 if i % 2 == 1: if S[i] == "1": n1 += 1 else: n2 += 1 n = min(n1, n2) print(n) S = i2s() main(S)
false
15.625
[ "+# AtCoder Beginner Contest 124", "+# https://atcoder.jp/contests/abc124", "-", "-def i2s():", "- return sys.stdin.readline()", "-", "-", "-def ii2ss(n):", "- return [sys.stdin.readline() for _ in range(n)]", "-", "-", "-def sp2nn(sp, sep=\" \"):", "- return [int(s) for s in sp.split(sep)]", "-", "-", "-def ss2nn(ss):", "- return [int(s) for s in list(ss)]", "+s2nn = lambda s: [int(c) for c in s.split(\" \")]", "+ss2nn = lambda ss: [int(s) for s in list(ss)]", "+ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]", "+i2s = lambda: sys.stdin.readline().rstrip()", "+i2n = lambda: int(i2s())", "+i2nn = lambda: s2nn(i2s())", "+ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]", "+ii2nnn = lambda n: ss2nnn(ii2ss(n))", "- S = S.rstrip()", "- c0 = 0", "- c1 = 0", "- for i, s in enumerate(S):", "- if (i % 2) == int(s):", "- c0 += 1", "- else:", "- c1 += 1", "- cmin = min(c0, c1)", "- print(cmin)", "+ n1 = 0", "+ n2 = 0", "+ for i in range(len(S)):", "+ if i % 2 == 0:", "+ if S[i] == \"0\":", "+ n1 += 1", "+ else:", "+ n2 += 1", "+ if i % 2 == 1:", "+ if S[i] == \"1\":", "+ n1 += 1", "+ else:", "+ n2 += 1", "+ n = min(n1, n2)", "+ print(n)", "-main(i2s())", "+S = i2s()", "+main(S)" ]
false
0.04484
0.106296
0.421838
[ "s978114328", "s451738883" ]
u968166680
p02630
python
s496361117
s848345904
226
148
113,532
36,420
Accepted
Accepted
34.51
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) A = list(map(int, readline().split())) Q, *BC = list(map(int, read().split())) total = sum(A) d = Counter(A) for b, c in zip(BC[::2], BC[1::2]): total -= b * d[b] total += c * d[b] d[c] += d[b] d[b] = 0 print(total) return if __name__ == '__main__': main()
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) A = list(map(int, readline().split())) Q, *BC = list(map(int, read().split())) total = sum(A) d = [0] * (10 ** 5 + 1) for a in A: d[a] += 1 for b, c in zip(BC[::2], BC[1::2]): total += (c - b) * d[b] d[c] += d[b] d[b] = 0 print(total) return if __name__ == '__main__': main()
30
32
580
606
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) A = list(map(int, readline().split())) Q, *BC = list(map(int, read().split())) total = sum(A) d = Counter(A) for b, c in zip(BC[::2], BC[1::2]): total -= b * d[b] total += c * d[b] d[c] += d[b] d[b] = 0 print(total) return if __name__ == "__main__": main()
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) A = list(map(int, readline().split())) Q, *BC = list(map(int, read().split())) total = sum(A) d = [0] * (10**5 + 1) for a in A: d[a] += 1 for b, c in zip(BC[::2], BC[1::2]): total += (c - b) * d[b] d[c] += d[b] d[b] = 0 print(total) return if __name__ == "__main__": main()
false
6.25
[ "- d = Counter(A)", "+ d = [0] * (10**5 + 1)", "+ for a in A:", "+ d[a] += 1", "- total -= b * d[b]", "- total += c * d[b]", "+ total += (c - b) * d[b]" ]
false
0.038346
0.044228
0.866999
[ "s496361117", "s848345904" ]
u072717685
p03944
python
s853199573
s387618524
60
18
3,064
3,064
Accepted
Accepted
70
W, H, N = list(map(int, input().split())) paint_dot = {} for _ in range(N): t1, t2, t3 = list(map(int,input().split())) paint_dot[(t1, t2)] = t3 mat = [[1]*W for i in range(H)] for key in paint_dot: x = paint_dot[key] if x == 1: for row in mat: for i in range(key[0]): row[i] = 0 elif x == 2: for row in mat: for i in range(key[0], W): row[i] = 0 elif x == 3: for i in range(key[1]): for j in range(W): mat[i][j] = 0 else: for i in range(key[1], H): for j in range(W): mat[i][j] = 0 #print(mat) print((sum(map(sum,mat))))
W, H, N = list(map(int, input().split())) paint_dot = {} for _ in range(N): t1, t2, t3 = list(map(int,input().split())) paint_dot[(t1, t2)] = t3 pattern_H = [1]*H pattern_W = [1]*W for key in paint_dot: if paint_dot[key] == 1: for i in range(key[0]): pattern_W[i] = 0 elif paint_dot[key] == 2: for i in range(key[0],W): pattern_W[i] = 0 elif paint_dot[key] == 3: for i in range(key[1]): pattern_H[i] = 0 else: for i in range(key[1],H): pattern_H[i] = 0 print((sum(pattern_W) * sum(pattern_H)))
30
25
640
567
W, H, N = list(map(int, input().split())) paint_dot = {} for _ in range(N): t1, t2, t3 = list(map(int, input().split())) paint_dot[(t1, t2)] = t3 mat = [[1] * W for i in range(H)] for key in paint_dot: x = paint_dot[key] if x == 1: for row in mat: for i in range(key[0]): row[i] = 0 elif x == 2: for row in mat: for i in range(key[0], W): row[i] = 0 elif x == 3: for i in range(key[1]): for j in range(W): mat[i][j] = 0 else: for i in range(key[1], H): for j in range(W): mat[i][j] = 0 # print(mat) print((sum(map(sum, mat))))
W, H, N = list(map(int, input().split())) paint_dot = {} for _ in range(N): t1, t2, t3 = list(map(int, input().split())) paint_dot[(t1, t2)] = t3 pattern_H = [1] * H pattern_W = [1] * W for key in paint_dot: if paint_dot[key] == 1: for i in range(key[0]): pattern_W[i] = 0 elif paint_dot[key] == 2: for i in range(key[0], W): pattern_W[i] = 0 elif paint_dot[key] == 3: for i in range(key[1]): pattern_H[i] = 0 else: for i in range(key[1], H): pattern_H[i] = 0 print((sum(pattern_W) * sum(pattern_H)))
false
16.666667
[ "-mat = [[1] * W for i in range(H)]", "+pattern_H = [1] * H", "+pattern_W = [1] * W", "- x = paint_dot[key]", "- if x == 1:", "- for row in mat:", "- for i in range(key[0]):", "- row[i] = 0", "- elif x == 2:", "- for row in mat:", "- for i in range(key[0], W):", "- row[i] = 0", "- elif x == 3:", "+ if paint_dot[key] == 1:", "+ for i in range(key[0]):", "+ pattern_W[i] = 0", "+ elif paint_dot[key] == 2:", "+ for i in range(key[0], W):", "+ pattern_W[i] = 0", "+ elif paint_dot[key] == 3:", "- for j in range(W):", "- mat[i][j] = 0", "+ pattern_H[i] = 0", "- for j in range(W):", "- mat[i][j] = 0", "-# print(mat)", "-print((sum(map(sum, mat))))", "+ pattern_H[i] = 0", "+print((sum(pattern_W) * sum(pattern_H)))" ]
false
0.053896
0.052363
1.02928
[ "s853199573", "s387618524" ]
u079022693
p02695
python
s197031517
s463313058
794
643
136,408
125,668
Accepted
Accepted
19.02
from sys import stdin import itertools import numpy as np from numba import njit @njit(cache=True) def f(): max_res=0 for i in range(l): res=0 for j in range(Q): if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]: res+=d[j] max_res=max(max_res,res) return max_res #入力 readline=stdin.readline N,M,Q=list(map(int,readline().split())) a=np.zeros(Q,dtype=np.int64) b=np.zeros(Q,dtype=np.int64) c=np.zeros(Q,dtype=np.int64) d=np.zeros(Q,dtype=np.int64) for i in range(Q): a[i],b[i],c[i],d[i]=list(map(int,readline().split())) arrays=np.array(list(itertools.combinations_with_replacement(list(range(1,M+1)),N)),dtype=np.int64) l=len(arrays) print((f()))
from sys import stdin import itertools import numpy as np from numba import njit @njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])",cache=True) def f(l,Q,a,b,c,d,arrays): max_res=0 for i in range(l): res=0 for j in range(Q): if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]: res+=d[j] max_res=max(max_res,res) return max_res def main(): #入力 readline=stdin.readline N,M,Q=list(map(int,readline().split())) a=np.zeros(Q,dtype=np.int64) b=np.zeros(Q,dtype=np.int64) c=np.zeros(Q,dtype=np.int64) d=np.zeros(Q,dtype=np.int64) for i in range(Q): a[i],b[i],c[i],d[i]=list(map(int,readline().split())) arrays=np.array(list(itertools.combinations_with_replacement(list(range(1,M+1)),N)),dtype=np.int64) l=len(arrays) print((f(l,Q,a,b,c,d,arrays))) if __name__=="__main__": main()
30
34
722
902
from sys import stdin import itertools import numpy as np from numba import njit @njit(cache=True) def f(): max_res = 0 for i in range(l): res = 0 for j in range(Q): if arrays[i][b[j] - 1] - arrays[i][a[j] - 1] == c[j]: res += d[j] max_res = max(max_res, res) return max_res # 入力 readline = stdin.readline N, M, Q = list(map(int, readline().split())) a = np.zeros(Q, dtype=np.int64) b = np.zeros(Q, dtype=np.int64) c = np.zeros(Q, dtype=np.int64) d = np.zeros(Q, dtype=np.int64) for i in range(Q): a[i], b[i], c[i], d[i] = list(map(int, readline().split())) arrays = np.array( list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)), dtype=np.int64, ) l = len(arrays) print((f()))
from sys import stdin import itertools import numpy as np from numba import njit @njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])", cache=True) def f(l, Q, a, b, c, d, arrays): max_res = 0 for i in range(l): res = 0 for j in range(Q): if arrays[i][b[j] - 1] - arrays[i][a[j] - 1] == c[j]: res += d[j] max_res = max(max_res, res) return max_res def main(): # 入力 readline = stdin.readline N, M, Q = list(map(int, readline().split())) a = np.zeros(Q, dtype=np.int64) b = np.zeros(Q, dtype=np.int64) c = np.zeros(Q, dtype=np.int64) d = np.zeros(Q, dtype=np.int64) for i in range(Q): a[i], b[i], c[i], d[i] = list(map(int, readline().split())) arrays = np.array( list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)), dtype=np.int64, ) l = len(arrays) print((f(l, Q, a, b, c, d, arrays))) if __name__ == "__main__": main()
false
11.764706
[ "-@njit(cache=True)", "-def f():", "+@njit(\"i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])\", cache=True)", "+def f(l, Q, a, b, c, d, arrays):", "-# 入力", "-readline = stdin.readline", "-N, M, Q = list(map(int, readline().split()))", "-a = np.zeros(Q, dtype=np.int64)", "-b = np.zeros(Q, dtype=np.int64)", "-c = np.zeros(Q, dtype=np.int64)", "-d = np.zeros(Q, dtype=np.int64)", "-for i in range(Q):", "- a[i], b[i], c[i], d[i] = list(map(int, readline().split()))", "-arrays = np.array(", "- list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)),", "- dtype=np.int64,", "-)", "-l = len(arrays)", "-print((f()))", "+def main():", "+ # 入力", "+ readline = stdin.readline", "+ N, M, Q = list(map(int, readline().split()))", "+ a = np.zeros(Q, dtype=np.int64)", "+ b = np.zeros(Q, dtype=np.int64)", "+ c = np.zeros(Q, dtype=np.int64)", "+ d = np.zeros(Q, dtype=np.int64)", "+ for i in range(Q):", "+ a[i], b[i], c[i], d[i] = list(map(int, readline().split()))", "+ arrays = np.array(", "+ list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)),", "+ dtype=np.int64,", "+ )", "+ l = len(arrays)", "+ print((f(l, Q, a, b, c, d, arrays)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.342299
0.329423
1.039086
[ "s197031517", "s463313058" ]
u113971909
p02984
python
s753395286
s879960737
192
129
24,776
14,028
Accepted
Accepted
32.81
N=int(eval(input())) k=N//2 D=list(map(int,input().split())) DD=D[:]+D[:] DS=[0]*(2*N+1) for i in range(0,2*N-2,2): DS[i+2]=DS[i]+DD[i] DS[i+3]=DS[i+1]+DD[i+1] T=sum(D) ret=[0]*N for i in range(N): ret[i]=T-2*(DS[i+1+2*k]-DS[i+1]) print((*ret))
N=int(eval(input())) D=list(map(int,input().split())) ret=[0]*N ret[0]=sum(D)-2*sum(D[1:N:2]) for i in range(1,N): ret[i]=2*D[i-1]-ret[i-1] print((*ret))
13
7
255
153
N = int(eval(input())) k = N // 2 D = list(map(int, input().split())) DD = D[:] + D[:] DS = [0] * (2 * N + 1) for i in range(0, 2 * N - 2, 2): DS[i + 2] = DS[i] + DD[i] DS[i + 3] = DS[i + 1] + DD[i + 1] T = sum(D) ret = [0] * N for i in range(N): ret[i] = T - 2 * (DS[i + 1 + 2 * k] - DS[i + 1]) print((*ret))
N = int(eval(input())) D = list(map(int, input().split())) ret = [0] * N ret[0] = sum(D) - 2 * sum(D[1:N:2]) for i in range(1, N): ret[i] = 2 * D[i - 1] - ret[i - 1] print((*ret))
false
46.153846
[ "-k = N // 2", "-DD = D[:] + D[:]", "-DS = [0] * (2 * N + 1)", "-for i in range(0, 2 * N - 2, 2):", "- DS[i + 2] = DS[i] + DD[i]", "- DS[i + 3] = DS[i + 1] + DD[i + 1]", "-T = sum(D)", "-for i in range(N):", "- ret[i] = T - 2 * (DS[i + 1 + 2 * k] - DS[i + 1])", "+ret[0] = sum(D) - 2 * sum(D[1:N:2])", "+for i in range(1, N):", "+ ret[i] = 2 * D[i - 1] - ret[i - 1]" ]
false
0.038657
0.066321
0.582873
[ "s753395286", "s879960737" ]
u707124227
p03274
python
s172717329
s151106128
117
94
14,780
14,380
Accepted
Accepted
19.66
n,k=list(map(int,input().split())) x=list(map(int,input().split())) xp=[xi for xi in x if xi>=0] xm=[xi for xi in x if xi<0] xm.sort(reverse=True) ans=3*10**8 for i in range(k+1): # xpからi個のろうそくをつける。xmからはk-i個火をつける if i>len(xp) or k-i>len(xm): continue a=xp[i-1] if len(xp)>0 and i>0 else 0 b=xm[k-i-1] if len(xm)>0 and k-i>0 else 0 ans=min(ans,2*a-b,a-2*b) print(ans)
def main(): import bisect n,k=list(map(int,input().split())) x=list(map(int,input().split())) ans=abs(x[0])*2+abs(x[-1])*2 if 0 in x: r=x.index(0) l=max(0,r-(k-1)) else: r=bisect.bisect_right(x,0) l=max(0,r-k) ans=2*abs(x[0])+2*abs(x[-1]) for i in range(l,min(n-k+1,r+1)): if x[i]*x[i+k-1]<=0: a=min(abs(x[i]),abs(x[i+k-1])) b=max(abs(x[i]),abs(x[i+k-1])) ans=min(ans,2*a+b) else: b=max(abs(x[i]),abs(x[i+k-1])) ans=min(ans,b) print(ans) if __name__=='__main__': main()
15
23
404
560
n, k = list(map(int, input().split())) x = list(map(int, input().split())) xp = [xi for xi in x if xi >= 0] xm = [xi for xi in x if xi < 0] xm.sort(reverse=True) ans = 3 * 10**8 for i in range(k + 1): # xpからi個のろうそくをつける。xmからはk-i個火をつける if i > len(xp) or k - i > len(xm): continue a = xp[i - 1] if len(xp) > 0 and i > 0 else 0 b = xm[k - i - 1] if len(xm) > 0 and k - i > 0 else 0 ans = min(ans, 2 * a - b, a - 2 * b) print(ans)
def main(): import bisect n, k = list(map(int, input().split())) x = list(map(int, input().split())) ans = abs(x[0]) * 2 + abs(x[-1]) * 2 if 0 in x: r = x.index(0) l = max(0, r - (k - 1)) else: r = bisect.bisect_right(x, 0) l = max(0, r - k) ans = 2 * abs(x[0]) + 2 * abs(x[-1]) for i in range(l, min(n - k + 1, r + 1)): if x[i] * x[i + k - 1] <= 0: a = min(abs(x[i]), abs(x[i + k - 1])) b = max(abs(x[i]), abs(x[i + k - 1])) ans = min(ans, 2 * a + b) else: b = max(abs(x[i]), abs(x[i + k - 1])) ans = min(ans, b) print(ans) if __name__ == "__main__": main()
false
34.782609
[ "-n, k = list(map(int, input().split()))", "-x = list(map(int, input().split()))", "-xp = [xi for xi in x if xi >= 0]", "-xm = [xi for xi in x if xi < 0]", "-xm.sort(reverse=True)", "-ans = 3 * 10**8", "-for i in range(k + 1):", "- # xpからi個のろうそくをつける。xmからはk-i個火をつける", "- if i > len(xp) or k - i > len(xm):", "- continue", "- a = xp[i - 1] if len(xp) > 0 and i > 0 else 0", "- b = xm[k - i - 1] if len(xm) > 0 and k - i > 0 else 0", "- ans = min(ans, 2 * a - b, a - 2 * b)", "-print(ans)", "+def main():", "+ import bisect", "+", "+ n, k = list(map(int, input().split()))", "+ x = list(map(int, input().split()))", "+ ans = abs(x[0]) * 2 + abs(x[-1]) * 2", "+ if 0 in x:", "+ r = x.index(0)", "+ l = max(0, r - (k - 1))", "+ else:", "+ r = bisect.bisect_right(x, 0)", "+ l = max(0, r - k)", "+ ans = 2 * abs(x[0]) + 2 * abs(x[-1])", "+ for i in range(l, min(n - k + 1, r + 1)):", "+ if x[i] * x[i + k - 1] <= 0:", "+ a = min(abs(x[i]), abs(x[i + k - 1]))", "+ b = max(abs(x[i]), abs(x[i + k - 1]))", "+ ans = min(ans, 2 * a + b)", "+ else:", "+ b = max(abs(x[i]), abs(x[i + k - 1]))", "+ ans = min(ans, b)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037986
0.039052
0.972704
[ "s172717329", "s151106128" ]
u633068244
p00707
python
s426828307
s631179510
430
300
4,360
4,324
Accepted
Accepted
30.23
while 1: W,H = list(map(int,input().split())) if W == 0: break C = [list(input()) for _ in range(H)] dp = [["0"]*W for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if C[h][w].isdigit(): dp[h][w] = str(max(int(dp[h][w]),int(C[h][w]))) if w > 0: dp[h][w] = str(max(int(dp[h][w]),int(dp[h][w-1]+C[h][w]))) if h > 0: dp[h][w] = str(max(int(dp[h][w]),int(dp[h-1][w]+C[h][w]))) ans = max(ans, int(dp[h][w])) print(ans)
while 1: W,H = list(map(int,input().split())) if W == 0: break C = [list(input()) for _ in range(H)] dp = [[0]*W for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if C[h][w].isdigit(): dp[h][w] = max(dp[h][w],int(C[h][w])) if w > 0: dp[h][w] = max(dp[h][w],int(str(dp[h][w-1])+C[h][w])) if h > 0: dp[h][w] = max(dp[h][w],int(str(dp[h-1][w])+C[h][w])) ans = max(ans,dp[h][w]) print(ans)
15
14
564
530
while 1: W, H = list(map(int, input().split())) if W == 0: break C = [list(input()) for _ in range(H)] dp = [["0"] * W for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if C[h][w].isdigit(): dp[h][w] = str(max(int(dp[h][w]), int(C[h][w]))) if w > 0: dp[h][w] = str(max(int(dp[h][w]), int(dp[h][w - 1] + C[h][w]))) if h > 0: dp[h][w] = str(max(int(dp[h][w]), int(dp[h - 1][w] + C[h][w]))) ans = max(ans, int(dp[h][w])) print(ans)
while 1: W, H = list(map(int, input().split())) if W == 0: break C = [list(input()) for _ in range(H)] dp = [[0] * W for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if C[h][w].isdigit(): dp[h][w] = max(dp[h][w], int(C[h][w])) if w > 0: dp[h][w] = max(dp[h][w], int(str(dp[h][w - 1]) + C[h][w])) if h > 0: dp[h][w] = max(dp[h][w], int(str(dp[h - 1][w]) + C[h][w])) ans = max(ans, dp[h][w]) print(ans)
false
6.666667
[ "- dp = [[\"0\"] * W for _ in range(H)]", "+ dp = [[0] * W for _ in range(H)]", "- dp[h][w] = str(max(int(dp[h][w]), int(C[h][w])))", "+ dp[h][w] = max(dp[h][w], int(C[h][w]))", "- dp[h][w] = str(max(int(dp[h][w]), int(dp[h][w - 1] + C[h][w])))", "+ dp[h][w] = max(dp[h][w], int(str(dp[h][w - 1]) + C[h][w]))", "- dp[h][w] = str(max(int(dp[h][w]), int(dp[h - 1][w] + C[h][w])))", "- ans = max(ans, int(dp[h][w]))", "+ dp[h][w] = max(dp[h][w], int(str(dp[h - 1][w]) + C[h][w]))", "+ ans = max(ans, dp[h][w])" ]
false
0.107687
0.071177
1.512937
[ "s426828307", "s631179510" ]
u796942881
p03137
python
s058180184
s307188289
94
72
13,964
15,116
Accepted
Accepted
23.4
def main(): N, M, *X = list(map(int, open(0).read().split())) X.sort() D = [j - i for i, j in zip(X, X[1:])] D.sort() print((0 if M <= N else sum(D[:M - N]))) return main()
def main(): N, M, *X = list(map(int, open(0).read().split())) X = sorted(set(X)) D = [j - i for i, j in zip(X, X[1:])] D.sort() print((0 if M <= N else sum(D[:M - N]))) return main()
10
10
200
210
def main(): N, M, *X = list(map(int, open(0).read().split())) X.sort() D = [j - i for i, j in zip(X, X[1:])] D.sort() print((0 if M <= N else sum(D[: M - N]))) return main()
def main(): N, M, *X = list(map(int, open(0).read().split())) X = sorted(set(X)) D = [j - i for i, j in zip(X, X[1:])] D.sort() print((0 if M <= N else sum(D[: M - N]))) return main()
false
0
[ "- X.sort()", "+ X = sorted(set(X))" ]
false
0.04008
0.040677
0.985334
[ "s058180184", "s307188289" ]
u941753895
p03658
python
s056030701
s229894482
22
18
3,316
2,940
Accepted
Accepted
18.18
n,k=list(map(int,input().split())) l=list(map(int,input().split())) l.sort() a=l[-k:] print((sum(a)))
# 入力 N,K=list(map(int,input().split())) l=list(map(int,input().split())) l.sort() l.reverse() # K個の和を出力 print((sum(l[:K])))
5
9
97
125
n, k = list(map(int, input().split())) l = list(map(int, input().split())) l.sort() a = l[-k:] print((sum(a)))
# 入力 N, K = list(map(int, input().split())) l = list(map(int, input().split())) l.sort() l.reverse() # K個の和を出力 print((sum(l[:K])))
false
44.444444
[ "-n, k = list(map(int, input().split()))", "+# 入力", "+N, K = list(map(int, input().split()))", "-a = l[-k:]", "-print((sum(a)))", "+l.reverse()", "+# K個の和を出力", "+print((sum(l[:K])))" ]
false
0.035974
0.034926
1.030002
[ "s056030701", "s229894482" ]
u546338822
p02912
python
s936071693
s805877704
164
129
14,180
20,464
Accepted
Accepted
21.34
def main(): import heapq n,m = list(map(int,input().split())) a = list(map(int,input().split())) heap = [] for i in range(n): heapq.heappush(heap,-1*a[i]) for i in range(m): a = int(heapq.heappop(heap)/2) heapq.heappush(heap,a) print((-1*sum(heap))) if __name__ == "__main__": main()
def main(): import heapq n,m = list(map(int,input().split())) a = list(map(int,input().split())) A = [] for i in range(n): heapq.heappush(A,-1*a[i]) for i in range(m): a = heapq.heappop(A) a = (-1*a)//2 heapq.heappush(A,-1*a) print((-1*sum(A))) if __name__ == "__main__": main()
16
15
349
350
def main(): import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) heap = [] for i in range(n): heapq.heappush(heap, -1 * a[i]) for i in range(m): a = int(heapq.heappop(heap) / 2) heapq.heappush(heap, a) print((-1 * sum(heap))) if __name__ == "__main__": main()
def main(): import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) A = [] for i in range(n): heapq.heappush(A, -1 * a[i]) for i in range(m): a = heapq.heappop(A) a = (-1 * a) // 2 heapq.heappush(A, -1 * a) print((-1 * sum(A))) if __name__ == "__main__": main()
false
6.25
[ "- heap = []", "+ A = []", "- heapq.heappush(heap, -1 * a[i])", "+ heapq.heappush(A, -1 * a[i])", "- a = int(heapq.heappop(heap) / 2)", "- heapq.heappush(heap, a)", "- print((-1 * sum(heap)))", "+ a = heapq.heappop(A)", "+ a = (-1 * a) // 2", "+ heapq.heappush(A, -1 * a)", "+ print((-1 * sum(A)))" ]
false
0.173302
0.047341
3.660706
[ "s936071693", "s805877704" ]
u360116509
p03722
python
s432457141
s472438773
1,372
580
3,304
3,420
Accepted
Accepted
57.73
def main(): N, M = list(map(int, input().split())) g = [] d = [float('INF')] * (N + 1) d[1] = 0 for _ in range(M): a, b, c = list(map(int, input().split())) g.append((a, b, -c)) for i in range(2 * N): for x, y, z in g: if d[x] != float('INF') and d[y] > d[x] + z: d[y] = d[x] + z if y == N and i > N: print("inf") exit() print((-d[-1])) main()
def main(): N, M = list(map(int, input().split())) g = [] INF = 10 ** 9 * 1000 d = [INF] * (N + 1) d[1] = 0 for _ in range(M): a, b, c = list(map(int, input().split())) g.append((a, b, -c)) for i in range(2 * N): for x, y, z in g: if d[x] != INF and d[y] > d[x] + z: d[y] = d[x] + z if y == N and i > N: print("inf") exit() print((-d[-1])) main()
20
21
488
496
def main(): N, M = list(map(int, input().split())) g = [] d = [float("INF")] * (N + 1) d[1] = 0 for _ in range(M): a, b, c = list(map(int, input().split())) g.append((a, b, -c)) for i in range(2 * N): for x, y, z in g: if d[x] != float("INF") and d[y] > d[x] + z: d[y] = d[x] + z if y == N and i > N: print("inf") exit() print((-d[-1])) main()
def main(): N, M = list(map(int, input().split())) g = [] INF = 10**9 * 1000 d = [INF] * (N + 1) d[1] = 0 for _ in range(M): a, b, c = list(map(int, input().split())) g.append((a, b, -c)) for i in range(2 * N): for x, y, z in g: if d[x] != INF and d[y] > d[x] + z: d[y] = d[x] + z if y == N and i > N: print("inf") exit() print((-d[-1])) main()
false
4.761905
[ "- d = [float(\"INF\")] * (N + 1)", "+ INF = 10**9 * 1000", "+ d = [INF] * (N + 1)", "- if d[x] != float(\"INF\") and d[y] > d[x] + z:", "+ if d[x] != INF and d[y] > d[x] + z:" ]
false
0.042243
0.103265
0.40907
[ "s432457141", "s472438773" ]
u794544096
p03352
python
s027001761
s135184049
70
61
61,520
62,236
Accepted
Accepted
12.86
x = int(eval(input())) r = 1 for b in range(1, int(x**0.5 + 1)): for p in range(2, 11): if b**p > x: break r = max(r, b**p) print(r)
x = int(eval(input())) cnt = [] for b in range(1, int(x**0.5)+1): for p in range(2, 11): if b**p <= x: cnt.append(b**p) print((max(cnt)))
10
8
177
173
x = int(eval(input())) r = 1 for b in range(1, int(x**0.5 + 1)): for p in range(2, 11): if b**p > x: break r = max(r, b**p) print(r)
x = int(eval(input())) cnt = [] for b in range(1, int(x**0.5) + 1): for p in range(2, 11): if b**p <= x: cnt.append(b**p) print((max(cnt)))
false
20
[ "-r = 1", "-for b in range(1, int(x**0.5 + 1)):", "+cnt = []", "+for b in range(1, int(x**0.5) + 1):", "- if b**p > x:", "- break", "- r = max(r, b**p)", "-print(r)", "+ if b**p <= x:", "+ cnt.append(b**p)", "+print((max(cnt)))" ]
false
0.036548
0.042628
0.857386
[ "s027001761", "s135184049" ]
u177040005
p03633
python
s307410796
s727809838
149
18
12,428
3,060
Accepted
Accepted
87.92
import numpy as np def gcd(a,b): while b: a,b = b,a%b return a def lcm_base(x, y): return x*y // gcd(x, y) N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] ans = 1 for t in T: ans = lcm_base(ans,t) print(ans)
N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] def gcd(a,b):#gcd :: greatest common divisor(最大公約数) :: G if b == 0: return a else: return gcd(b, a%b) def lcm(X,Y):#lcm :: least common multiple(最小公約数)) :: L return X*Y // gcd(X,Y) # XY = GL ans = 1 for t in T: ans = lcm(ans, t) print(ans)
18
16
260
344
import numpy as np def gcd(a, b): while b: a, b = b, a % b return a def lcm_base(x, y): return x * y // gcd(x, y) N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] ans = 1 for t in T: ans = lcm_base(ans, t) print(ans)
N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] def gcd(a, b): # gcd :: greatest common divisor(最大公約数) :: G if b == 0: return a else: return gcd(b, a % b) def lcm(X, Y): # lcm :: least common multiple(最小公約数)) :: L return X * Y // gcd(X, Y) # XY = GL ans = 1 for t in T: ans = lcm(ans, t) print(ans)
false
11.111111
[ "-import numpy as np", "+N = int(eval(input()))", "+T = [int(eval(input())) for _ in range(N)]", "-def gcd(a, b):", "- while b:", "- a, b = b, a % b", "- return a", "+def gcd(a, b): # gcd :: greatest common divisor(最大公約数) :: G", "+ if b == 0:", "+ return a", "+ else:", "+ return gcd(b, a % b)", "-def lcm_base(x, y):", "- return x * y // gcd(x, y)", "+def lcm(X, Y): # lcm :: least common multiple(最小公約数)) :: L", "+ return X * Y // gcd(X, Y) # XY = GL", "-N = int(eval(input()))", "-T = [int(eval(input())) for _ in range(N)]", "- ans = lcm_base(ans, t)", "+ ans = lcm(ans, t)" ]
false
0.036383
0.056353
0.645629
[ "s307410796", "s727809838" ]
u761320129
p03478
python
s548955418
s585648985
33
30
2,940
2,940
Accepted
Accepted
9.09
N,A,B = list(map(int,input().split())) ans = 0 for n in range(1,N+1): s = sum(map(int,list(str(n)))) if A <= s <= B: ans += n print(ans)
N,A,B = list(map(int,input().split())) ans = 0 for n in range(1,N+1): s = sum(map(int,str(n))) if A <= s <= B: ans += n print(ans)
7
6
153
137
N, A, B = list(map(int, input().split())) ans = 0 for n in range(1, N + 1): s = sum(map(int, list(str(n)))) if A <= s <= B: ans += n print(ans)
N, A, B = list(map(int, input().split())) ans = 0 for n in range(1, N + 1): s = sum(map(int, str(n))) if A <= s <= B: ans += n print(ans)
false
14.285714
[ "- s = sum(map(int, list(str(n))))", "+ s = sum(map(int, str(n)))" ]
false
0.104146
0.037894
2.748349
[ "s548955418", "s585648985" ]
u981931040
p02623
python
s040268244
s806981897
192
146
132,824
118,092
Accepted
Accepted
23.96
import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 A_cumulative_sum = [0] B_cumulative_sum = [B[0]] for i in range(N): A_cumulative_sum.append(A[i] + A_cumulative_sum[i]) for i in range(1, M): B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1]) for i in range(N + 1): if K < A_cumulative_sum[i]: remaining_time = K idx = bisect.bisect_right(B_cumulative_sum, remaining_time) ans = max(ans, idx) break else: remaining_time = K - A_cumulative_sum[i] idx = bisect.bisect_right(B_cumulative_sum, remaining_time) ans = max(ans, i + idx) print(ans) # 113897
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) ''' with open('./b09.txt') as f: N, M, K = map(int, f.readline().split()) A = list(map(int, f.readline().split())) B = list(map(int, f.readline().split())) ''' A_cnt = 0 B_cnt = 0 ans = 0 nowK = K for A_idx in range(N): if nowK < A[A_idx]: break ans += 1 nowK -= A[A_idx] A_cnt += 1 for B_idx in range(M): if nowK < B[B_idx]: break ans += 1 nowK -= B[B_idx] B_cnt += 1 tmp_ans = ans finish = False for i in range(A_cnt, 0, -1): nowK += A[i - 1] tmp_ans -= 1 for j in range(B_cnt, M): if finish or nowK < B[j]: break nowK -= B[j] tmp_ans += 1 B_cnt += 1 ans = max(tmp_ans, ans) print(ans)
25
41
732
859
import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 A_cumulative_sum = [0] B_cumulative_sum = [B[0]] for i in range(N): A_cumulative_sum.append(A[i] + A_cumulative_sum[i]) for i in range(1, M): B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1]) for i in range(N + 1): if K < A_cumulative_sum[i]: remaining_time = K idx = bisect.bisect_right(B_cumulative_sum, remaining_time) ans = max(ans, idx) break else: remaining_time = K - A_cumulative_sum[i] idx = bisect.bisect_right(B_cumulative_sum, remaining_time) ans = max(ans, i + idx) print(ans) # 113897
N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) """ with open('./b09.txt') as f: N, M, K = map(int, f.readline().split()) A = list(map(int, f.readline().split())) B = list(map(int, f.readline().split())) """ A_cnt = 0 B_cnt = 0 ans = 0 nowK = K for A_idx in range(N): if nowK < A[A_idx]: break ans += 1 nowK -= A[A_idx] A_cnt += 1 for B_idx in range(M): if nowK < B[B_idx]: break ans += 1 nowK -= B[B_idx] B_cnt += 1 tmp_ans = ans finish = False for i in range(A_cnt, 0, -1): nowK += A[i - 1] tmp_ans -= 1 for j in range(B_cnt, M): if finish or nowK < B[j]: break nowK -= B[j] tmp_ans += 1 B_cnt += 1 ans = max(tmp_ans, ans) print(ans)
false
39.02439
[ "-import bisect", "-", "+\"\"\"", "+with open('./b09.txt') as f:", "+ N, M, K = map(int, f.readline().split())", "+ A = list(map(int, f.readline().split()))", "+ B = list(map(int, f.readline().split()))", "+\"\"\"", "+A_cnt = 0", "+B_cnt = 0", "-A_cumulative_sum = [0]", "-B_cumulative_sum = [B[0]]", "-for i in range(N):", "- A_cumulative_sum.append(A[i] + A_cumulative_sum[i])", "-for i in range(1, M):", "- B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])", "-for i in range(N + 1):", "- if K < A_cumulative_sum[i]:", "- remaining_time = K", "- idx = bisect.bisect_right(B_cumulative_sum, remaining_time)", "- ans = max(ans, idx)", "+nowK = K", "+for A_idx in range(N):", "+ if nowK < A[A_idx]:", "- else:", "- remaining_time = K - A_cumulative_sum[i]", "- idx = bisect.bisect_right(B_cumulative_sum, remaining_time)", "- ans = max(ans, i + idx)", "+ ans += 1", "+ nowK -= A[A_idx]", "+ A_cnt += 1", "+for B_idx in range(M):", "+ if nowK < B[B_idx]:", "+ break", "+ ans += 1", "+ nowK -= B[B_idx]", "+ B_cnt += 1", "+tmp_ans = ans", "+finish = False", "+for i in range(A_cnt, 0, -1):", "+ nowK += A[i - 1]", "+ tmp_ans -= 1", "+ for j in range(B_cnt, M):", "+ if finish or nowK < B[j]:", "+ break", "+ nowK -= B[j]", "+ tmp_ans += 1", "+ B_cnt += 1", "+ ans = max(tmp_ans, ans)", "-# 113897" ]
false
0.042493
0.160842
0.264188
[ "s040268244", "s806981897" ]
u063596417
p04044
python
s292004095
s280848960
63
30
62,444
9,116
Accepted
Accepted
52.38
n, l = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print((''.join(s)))
def main(): n, _ = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print((''.join(s))) if __name__ == '__main__': main()
4
9
95
168
n, l = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print(("".join(s)))
def main(): n, _ = list(map(int, input().split())) s = [eval(input()) for _ in range(n)] s.sort() print(("".join(s))) if __name__ == "__main__": main()
false
55.555556
[ "-n, l = list(map(int, input().split()))", "-s = [eval(input()) for _ in range(n)]", "-s.sort()", "-print((\"\".join(s)))", "+def main():", "+ n, _ = list(map(int, input().split()))", "+ s = [eval(input()) for _ in range(n)]", "+ s.sort()", "+ print((\"\".join(s)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.072507
0.007094
10.220517
[ "s292004095", "s280848960" ]
u423966555
p03497
python
s938475082
s016994952
181
154
44,316
43,292
Accepted
Accepted
14.92
from collections import defaultdict N, K = list(map(int, input().split())) A = list(map(int ,input().split())) d = defaultdict(int) for i in A: d[i] += 1 d_ = sorted(list(d.items()), key=lambda x:x[1], reverse=True) n =len(d_) ans = 0 if n <= K: print((0)) exit() else: for i in range(K,n): ans += d_[i][1] print(ans)
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int ,input().split())) d = Counter(A) d_ = sorted(list(d.items()), key=lambda x:x[1], reverse=True) n =len(d_) ans = 0 if n <= K: print((0)) exit() else: for i in range(K,n): ans += d_[i][1] print(ans)
18
16
346
308
from collections import defaultdict N, K = list(map(int, input().split())) A = list(map(int, input().split())) d = defaultdict(int) for i in A: d[i] += 1 d_ = sorted(list(d.items()), key=lambda x: x[1], reverse=True) n = len(d_) ans = 0 if n <= K: print((0)) exit() else: for i in range(K, n): ans += d_[i][1] print(ans)
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) d = Counter(A) d_ = sorted(list(d.items()), key=lambda x: x[1], reverse=True) n = len(d_) ans = 0 if n <= K: print((0)) exit() else: for i in range(K, n): ans += d_[i][1] print(ans)
false
11.111111
[ "-from collections import defaultdict", "+from collections import Counter", "-d = defaultdict(int)", "-for i in A:", "- d[i] += 1", "+d = Counter(A)" ]
false
0.079806
0.076982
1.036688
[ "s938475082", "s016994952" ]
u673361376
p03252
python
s300079204
s902766632
223
198
68,088
42,460
Accepted
Accepted
11.21
from collections import Counter S,T = Counter([s for s in eval(input())]), Counter([s for s in eval(input())]) print(('Yes' if Counter(list(S.values())) == Counter(list(T.values())) else 'No'))
import collections cntS = collections.Counter(eval(input())) cntT = collections.Counter(eval(input())) if sorted(cntS.values()) == sorted(cntT.values()): print('Yes') else: print('No')
4
10
172
193
from collections import Counter S, T = Counter([s for s in eval(input())]), Counter([s for s in eval(input())]) print(("Yes" if Counter(list(S.values())) == Counter(list(T.values())) else "No"))
import collections cntS = collections.Counter(eval(input())) cntT = collections.Counter(eval(input())) if sorted(cntS.values()) == sorted(cntT.values()): print("Yes") else: print("No")
false
60
[ "-from collections import Counter", "+import collections", "-S, T = Counter([s for s in eval(input())]), Counter([s for s in eval(input())])", "-print((\"Yes\" if Counter(list(S.values())) == Counter(list(T.values())) else \"No\"))", "+cntS = collections.Counter(eval(input()))", "+cntT = collections.Counter(eval(input()))", "+if sorted(cntS.values()) == sorted(cntT.values()):", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.036896
0.036208
1.018987
[ "s300079204", "s902766632" ]
u723711163
p03031
python
s413521378
s426451902
220
40
43,740
9,184
Accepted
Accepted
81.82
N,M = list(map(int,input().split())) bulbs = [] for _ in range(M): bulbs.append(list(map(int,input().split()))) P = list(map(int,input().split())) res = 0 for i in range(1<<N): on = [] for j in range(N): if (i>>j)&1: on.append(j) ok = True for i,b in enumerate(bulbs): b = [ k-1 for k in b[1:] ] p = P[i] o = 0 for s in on: if s in b: o += 1 if o%2 != p: ok = False break if ok: res += 1 print(res)
# N switches, M bulbs N,M = list(map(int,input().split())) K = [] for i in range(M): lst = list(map(int,input().split())) K.append([i-1 for i in lst[1:] ]) P = list(map(int,input().split())) res = 0 for i in range(1<<N): on = [] for j in range(N): if (i>>j)&1: on.append(j) flg = True for m in range(M): k = K[m] tmp = 0 for s in k: if s in on: tmp += 1 p = P[m] if tmp % 2 != p: flg = False break if flg: res += 1 print(res)
27
32
486
529
N, M = list(map(int, input().split())) bulbs = [] for _ in range(M): bulbs.append(list(map(int, input().split()))) P = list(map(int, input().split())) res = 0 for i in range(1 << N): on = [] for j in range(N): if (i >> j) & 1: on.append(j) ok = True for i, b in enumerate(bulbs): b = [k - 1 for k in b[1:]] p = P[i] o = 0 for s in on: if s in b: o += 1 if o % 2 != p: ok = False break if ok: res += 1 print(res)
# N switches, M bulbs N, M = list(map(int, input().split())) K = [] for i in range(M): lst = list(map(int, input().split())) K.append([i - 1 for i in lst[1:]]) P = list(map(int, input().split())) res = 0 for i in range(1 << N): on = [] for j in range(N): if (i >> j) & 1: on.append(j) flg = True for m in range(M): k = K[m] tmp = 0 for s in k: if s in on: tmp += 1 p = P[m] if tmp % 2 != p: flg = False break if flg: res += 1 print(res)
false
15.625
[ "+# N switches, M bulbs", "-bulbs = []", "-for _ in range(M):", "- bulbs.append(list(map(int, input().split())))", "+K = []", "+for i in range(M):", "+ lst = list(map(int, input().split()))", "+ K.append([i - 1 for i in lst[1:]])", "- ok = True", "- for i, b in enumerate(bulbs):", "- b = [k - 1 for k in b[1:]]", "- p = P[i]", "- o = 0", "- for s in on:", "- if s in b:", "- o += 1", "- if o % 2 != p:", "- ok = False", "+ flg = True", "+ for m in range(M):", "+ k = K[m]", "+ tmp = 0", "+ for s in k:", "+ if s in on:", "+ tmp += 1", "+ p = P[m]", "+ if tmp % 2 != p:", "+ flg = False", "- if ok:", "+ if flg:" ]
false
0.040271
0.039262
1.025677
[ "s413521378", "s426451902" ]
u759412327
p03680
python
s510724514
s851766320
201
153
13,724
13,028
Accepted
Accepted
23.88
N = int(eval(input())) a = [0] + [int(eval(input())) for _ in range(N)] x = 1 visited = set([1]) answer = 0 while True: x = a[x] if x in visited: answer = -1 break visited.add(x) answer += 1 if x == 2: break print(answer)
N = int(eval(input())) A = [int(eval(input())) for n in range(N)] B = 0 for n in range(N): B = A[B]-1 if B==1: print((n+1)) exit() print((-1))
17
11
254
150
N = int(eval(input())) a = [0] + [int(eval(input())) for _ in range(N)] x = 1 visited = set([1]) answer = 0 while True: x = a[x] if x in visited: answer = -1 break visited.add(x) answer += 1 if x == 2: break print(answer)
N = int(eval(input())) A = [int(eval(input())) for n in range(N)] B = 0 for n in range(N): B = A[B] - 1 if B == 1: print((n + 1)) exit() print((-1))
false
35.294118
[ "-a = [0] + [int(eval(input())) for _ in range(N)]", "-x = 1", "-visited = set([1])", "-answer = 0", "-while True:", "- x = a[x]", "- if x in visited:", "- answer = -1", "- break", "- visited.add(x)", "- answer += 1", "- if x == 2:", "- break", "-print(answer)", "+A = [int(eval(input())) for n in range(N)]", "+B = 0", "+for n in range(N):", "+ B = A[B] - 1", "+ if B == 1:", "+ print((n + 1))", "+ exit()", "+print((-1))" ]
false
0.20818
0.102623
2.028588
[ "s510724514", "s851766320" ]
u638795007
p02930
python
s528790628
s619052245
153
96
13,684
11,468
Accepted
Accepted
37.25
def examA(): N = DI()/dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): N = I() n = (N-1).bit_length() V = [[-1]*(1<<n) for i in range(1<<n)] #print(V) for i in range(n): b1 = 1 << i b2 = 1 << (i + 1) for j in range(1<<i): for k in range(1<<(n-i)): for l in range(1<<(n-i)): #print(i,j,k,l,j+k*b2,j+b1+l*b2) if j+k*b2>=N or j+b1+l*b2>=N: continue u,v = sorted([j+k*b2,j+b1+l*b2]) #print(u,v) V[u][v-1] = i+1 ans = [[]for _ in range(N-1)] for i in range(N-1): for v in V[i]: if v>=0: ans[i].append(v) for v in ans: print((" ".join(map(str,v)))) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import getcontext,Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord('a') + i) for i in range(26)] alphabet_convert = {chr(ord('a') + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == '__main__': examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
def examA(): N = DI()/dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): N = I() n = (N-1).bit_length() V = [[-1]*(1<<n) for i in range(1<<n)] #print(V) for i in range(n): b1 = 1 << i b2 = 1 << (i + 1) for j in range(1<<i): for k in range(1<<(n-i)): for l in range(1<<(n-i)): #print(i,j,k,l,j+k*b2,j+b1+l*b2) if j+k*b2>=N or j+b1+l*b2>=N: continue u,v = sorted([j+k*b2,j+b1+l*b2]) #print(u,v) V[u][v-1] = i+1 ans = [[]for _ in range(N-1)] for i in range(N-1): for v in V[i]: if v>=0: ans[i].append(v) for v in ans: print((" ".join(map(str,v)))) return # 解説 def examD2(): N = I() ans = [[-1]*(N-1-i) for i in range(N-1)] n = N.bit_length() for i in range(N): for j in range(i+1,N): k = 0 while(True): if i&(1<<k) != j&(1<<k): break k += 1 #print(i,j,j-i) ans[i][j-i-1] = k+1 for v in ans: print((" ".join(map(str,v)))) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import getcontext,Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord('a') + i) for i in range(26)] alphabet_convert = {chr(ord('a') + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == '__main__': examD2() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
99
117
2,269
2,700
def examA(): N = DI() / dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): N = I() n = (N - 1).bit_length() V = [[-1] * (1 << n) for i in range(1 << n)] # print(V) for i in range(n): b1 = 1 << i b2 = 1 << (i + 1) for j in range(1 << i): for k in range(1 << (n - i)): for l in range(1 << (n - i)): # print(i,j,k,l,j+k*b2,j+b1+l*b2) if j + k * b2 >= N or j + b1 + l * b2 >= N: continue u, v = sorted([j + k * b2, j + b1 + l * b2]) # print(u,v) V[u][v - 1] = i + 1 ans = [[] for _ in range(N - 1)] for i in range(N - 1): for v in V[i]: if v >= 0: ans[i].append(v) for v in ans: print((" ".join(map(str, v)))) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
def examA(): N = DI() / dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): N = I() n = (N - 1).bit_length() V = [[-1] * (1 << n) for i in range(1 << n)] # print(V) for i in range(n): b1 = 1 << i b2 = 1 << (i + 1) for j in range(1 << i): for k in range(1 << (n - i)): for l in range(1 << (n - i)): # print(i,j,k,l,j+k*b2,j+b1+l*b2) if j + k * b2 >= N or j + b1 + l * b2 >= N: continue u, v = sorted([j + k * b2, j + b1 + l * b2]) # print(u,v) V[u][v - 1] = i + 1 ans = [[] for _ in range(N - 1)] for i in range(N - 1): for v in V[i]: if v >= 0: ans[i].append(v) for v in ans: print((" ".join(map(str, v)))) return # 解説 def examD2(): N = I() ans = [[-1] * (N - 1 - i) for i in range(N - 1)] n = N.bit_length() for i in range(N): for j in range(i + 1, N): k = 0 while True: if i & (1 << k) != j & (1 << k): break k += 1 # print(i,j,j-i) ans[i][j - i - 1] = k + 1 for v in ans: print((" ".join(map(str, v)))) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examD2() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
false
15.384615
[ "+ for v in ans:", "+ print((\" \".join(map(str, v))))", "+ return", "+", "+", "+# 解説", "+def examD2():", "+ N = I()", "+ ans = [[-1] * (N - 1 - i) for i in range(N - 1)]", "+ n = N.bit_length()", "+ for i in range(N):", "+ for j in range(i + 1, N):", "+ k = 0", "+ while True:", "+ if i & (1 << k) != j & (1 << k):", "+ break", "+ k += 1", "+ # print(i,j,j-i)", "+ ans[i][j - i - 1] = k + 1", "- examD()", "+ examD2()" ]
false
0.101749
0.04202
2.421449
[ "s528790628", "s619052245" ]
u102461423
p02632
python
s417616065
s769385426
1,403
817
185,240
163,172
Accepted
Accepted
41.77
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 @njit def fact_table(N, MOD): inv = np.empty(N, np.int64) inv[0] = 0 inv[1] = 1 for n in range(2, N): q, r = divmod(MOD, n) inv[n] = inv[r] * (-q) % MOD fact = np.empty(N, np.int64) fact[0] = 1 for n in range(1, N): fact[n] = n * fact[n - 1] % MOD fact_inv = np.empty(N, np.int64) fact_inv[0] = 1 for n in range(1, N): fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD return fact, fact_inv, inv @njit def main(K, N, MOD): fact, fact_inv, inv = fact_table(3_000_000, MOD) f = np.zeros(K + 1, np.int64) f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD x = 1 for i in range(1, K + 1): x = (x * 25) % MOD f[i] = f[i] * x % MOD for i in range(1, K + 1): f[i] += f[i - 1] * 26 f[i] %= MOD return f[-1] K = int(readline()) N = len(read().rstrip()) print((main(K, N, MOD)))
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 def main(K, N, MOD): def fact_table(N, MOD): inv = np.empty(N, np.int64) inv[0] = 0 inv[1] = 1 for n in range(2, N): q, r = divmod(MOD, n) inv[n] = inv[r] * (-q) % MOD fact = np.empty(N, np.int64) fact[0] = 1 for n in range(1, N): fact[n] = n * fact[n - 1] % MOD fact_inv = np.empty(N, np.int64) fact_inv[0] = 1 for n in range(1, N): fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD return fact, fact_inv, inv fact, fact_inv, inv = fact_table(3_000_000, MOD) f = np.zeros(K + 1, np.int64) f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD x = 1 for i in range(1, K + 1): x = (x * 25) % MOD f[i] = f[i] * x % MOD for i in range(1, K + 1): f[i] += f[i - 1] * 26 f[i] %= MOD return f[-1] if sys.argv[-1] == 'ONLINE_JUDGE': import numba from numba.pycc import CC i8 = numba.from_dtype(np.int64) signature = (i8, i8, i8) cc = CC('my_module') cc.export('main', signature)(main) cc.compile() from my_module import main K = int(readline()) N = len(read().rstrip()) print((main(K, N, MOD)))
46
56
1,143
1,463
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 @njit def fact_table(N, MOD): inv = np.empty(N, np.int64) inv[0] = 0 inv[1] = 1 for n in range(2, N): q, r = divmod(MOD, n) inv[n] = inv[r] * (-q) % MOD fact = np.empty(N, np.int64) fact[0] = 1 for n in range(1, N): fact[n] = n * fact[n - 1] % MOD fact_inv = np.empty(N, np.int64) fact_inv[0] = 1 for n in range(1, N): fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD return fact, fact_inv, inv @njit def main(K, N, MOD): fact, fact_inv, inv = fact_table(3_000_000, MOD) f = np.zeros(K + 1, np.int64) f = fact[N - 1 : K + N] * fact_inv[N - 1] % MOD * fact_inv[0 : K + 1] % MOD x = 1 for i in range(1, K + 1): x = (x * 25) % MOD f[i] = f[i] * x % MOD for i in range(1, K + 1): f[i] += f[i - 1] * 26 f[i] %= MOD return f[-1] K = int(readline()) N = len(read().rstrip()) print((main(K, N, MOD)))
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 def main(K, N, MOD): def fact_table(N, MOD): inv = np.empty(N, np.int64) inv[0] = 0 inv[1] = 1 for n in range(2, N): q, r = divmod(MOD, n) inv[n] = inv[r] * (-q) % MOD fact = np.empty(N, np.int64) fact[0] = 1 for n in range(1, N): fact[n] = n * fact[n - 1] % MOD fact_inv = np.empty(N, np.int64) fact_inv[0] = 1 for n in range(1, N): fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD return fact, fact_inv, inv fact, fact_inv, inv = fact_table(3_000_000, MOD) f = np.zeros(K + 1, np.int64) f = fact[N - 1 : K + N] * fact_inv[N - 1] % MOD * fact_inv[0 : K + 1] % MOD x = 1 for i in range(1, K + 1): x = (x * 25) % MOD f[i] = f[i] * x % MOD for i in range(1, K + 1): f[i] += f[i - 1] * 26 f[i] %= MOD return f[-1] if sys.argv[-1] == "ONLINE_JUDGE": import numba from numba.pycc import CC i8 = numba.from_dtype(np.int64) signature = (i8, i8, i8) cc = CC("my_module") cc.export("main", signature)(main) cc.compile() from my_module import main K = int(readline()) N = len(read().rstrip()) print((main(K, N, MOD)))
false
17.857143
[ "-@njit", "-def fact_table(N, MOD):", "- inv = np.empty(N, np.int64)", "- inv[0] = 0", "- inv[1] = 1", "- for n in range(2, N):", "- q, r = divmod(MOD, n)", "- inv[n] = inv[r] * (-q) % MOD", "- fact = np.empty(N, np.int64)", "- fact[0] = 1", "- for n in range(1, N):", "- fact[n] = n * fact[n - 1] % MOD", "- fact_inv = np.empty(N, np.int64)", "- fact_inv[0] = 1", "- for n in range(1, N):", "- fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD", "- return fact, fact_inv, inv", "+def main(K, N, MOD):", "+ def fact_table(N, MOD):", "+ inv = np.empty(N, np.int64)", "+ inv[0] = 0", "+ inv[1] = 1", "+ for n in range(2, N):", "+ q, r = divmod(MOD, n)", "+ inv[n] = inv[r] * (-q) % MOD", "+ fact = np.empty(N, np.int64)", "+ fact[0] = 1", "+ for n in range(1, N):", "+ fact[n] = n * fact[n - 1] % MOD", "+ fact_inv = np.empty(N, np.int64)", "+ fact_inv[0] = 1", "+ for n in range(1, N):", "+ fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD", "+ return fact, fact_inv, inv", "-", "-@njit", "-def main(K, N, MOD):", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ import numba", "+ from numba.pycc import CC", "+", "+ i8 = numba.from_dtype(np.int64)", "+ signature = (i8, i8, i8)", "+ cc = CC(\"my_module\")", "+ cc.export(\"main\", signature)(main)", "+ cc.compile()", "+from my_module import main", "+" ]
false
0.209699
0.740954
0.283012
[ "s417616065", "s769385426" ]
u151005508
p03575
python
s551313819
s162912327
180
22
39,664
3,316
Accepted
Accepted
87.78
# pythonでスタック、キューを実現するためにdequeをimport from collections import deque N, M = list(map(int, input().split())) # 辺集合EとグラフGの構築 G = [[] for _ in range(N)] E = [] for _ in range(M): a, b = list(map(int, input().split())) # 入力は1-indexedだがこれを扱いやすいように0-indexedに変更 a -= 1 b -= 1 E.append((a, b)) G[a].append(b) G[b].append(a) # print(G) # 橋を数えるための変数cntを用意 cnt = 0 for edge_to_remove in E: # 橋であるか判定したい辺を取り除いてみる i, j = edge_to_remove G[i].remove(j) G[j].remove(i) # 深さ優先探索 seen = [False] * N todo = deque() # 適当な頂点から深さ優先探索をスタート(ここでは頂点0をスタートに選んだ) todo.append(0) seen[0] = True seen_nodes_num = 0 while todo: here = todo.pop() seen_nodes_num += 1 for neighbor in G[here]: if seen[neighbor] == False: seen[neighbor] = True todo.append(neighbor) # print(seen) # もし訪問できていない頂点があれば連結でないというなので今着目している辺は橋であった! if seen_nodes_num != N: cnt += 1 # 次の辺について調べるために今取り除いた辺を再びGに戻しておく G[i].append(j) G[j].append(i) print(cnt)
# pythonでスタック、キューを実現するためにdequeをimport from collections import deque N, M = list(map(int, input().split())) # 辺集合EとグラフGの構築 G = [[] for _ in range(N)] E = [] for _ in range(M): a, b = list(map(int, input().split())) # 入力は1-indexedだがこれを扱いやすいように0-indexedに変更 a -= 1 b -= 1 E.append((a, b)) G[a].append(b) G[b].append(a) # print(G) # 橋を数えるための変数cntを用意 cnt = 0 for edge_to_remove in E: # 橋であるか判定したい辺を取り除いてみる i, j = edge_to_remove G[i].remove(j) G[j].remove(i) # 深さ優先探索 seen = set() todo = deque() # 適当な頂点から深さ優先探索をスタート(ここでは頂点0をスタートに選んだ) todo.append(0) seen.add(0) while todo: here = todo.pop() for neighbor in G[here]: if neighbor not in seen: seen.add(neighbor) todo.append(neighbor) # print(seen) # もし訪問できていない頂点があれば連結でないというなので今着目している辺は橋であった! if len(seen) < N: cnt += 1 # 次の辺について調べるために今取り除いた辺を再びGに戻しておく G[i].append(j) G[j].append(i) print(cnt)
49
47
1,113
1,039
# pythonでスタック、キューを実現するためにdequeをimport from collections import deque N, M = list(map(int, input().split())) # 辺集合EとグラフGの構築 G = [[] for _ in range(N)] E = [] for _ in range(M): a, b = list(map(int, input().split())) # 入力は1-indexedだがこれを扱いやすいように0-indexedに変更 a -= 1 b -= 1 E.append((a, b)) G[a].append(b) G[b].append(a) # print(G) # 橋を数えるための変数cntを用意 cnt = 0 for edge_to_remove in E: # 橋であるか判定したい辺を取り除いてみる i, j = edge_to_remove G[i].remove(j) G[j].remove(i) # 深さ優先探索 seen = [False] * N todo = deque() # 適当な頂点から深さ優先探索をスタート(ここでは頂点0をスタートに選んだ) todo.append(0) seen[0] = True seen_nodes_num = 0 while todo: here = todo.pop() seen_nodes_num += 1 for neighbor in G[here]: if seen[neighbor] == False: seen[neighbor] = True todo.append(neighbor) # print(seen) # もし訪問できていない頂点があれば連結でないというなので今着目している辺は橋であった! if seen_nodes_num != N: cnt += 1 # 次の辺について調べるために今取り除いた辺を再びGに戻しておく G[i].append(j) G[j].append(i) print(cnt)
# pythonでスタック、キューを実現するためにdequeをimport from collections import deque N, M = list(map(int, input().split())) # 辺集合EとグラフGの構築 G = [[] for _ in range(N)] E = [] for _ in range(M): a, b = list(map(int, input().split())) # 入力は1-indexedだがこれを扱いやすいように0-indexedに変更 a -= 1 b -= 1 E.append((a, b)) G[a].append(b) G[b].append(a) # print(G) # 橋を数えるための変数cntを用意 cnt = 0 for edge_to_remove in E: # 橋であるか判定したい辺を取り除いてみる i, j = edge_to_remove G[i].remove(j) G[j].remove(i) # 深さ優先探索 seen = set() todo = deque() # 適当な頂点から深さ優先探索をスタート(ここでは頂点0をスタートに選んだ) todo.append(0) seen.add(0) while todo: here = todo.pop() for neighbor in G[here]: if neighbor not in seen: seen.add(neighbor) todo.append(neighbor) # print(seen) # もし訪問できていない頂点があれば連結でないというなので今着目している辺は橋であった! if len(seen) < N: cnt += 1 # 次の辺について調べるために今取り除いた辺を再びGに戻しておく G[i].append(j) G[j].append(i) print(cnt)
false
4.081633
[ "- seen = [False] * N", "+ seen = set()", "- seen[0] = True", "- seen_nodes_num = 0", "+ seen.add(0)", "- seen_nodes_num += 1", "- if seen[neighbor] == False:", "- seen[neighbor] = True", "+ if neighbor not in seen:", "+ seen.add(neighbor)", "- if seen_nodes_num != N:", "+ if len(seen) < N:" ]
false
0.036382
0.034968
1.040422
[ "s551313819", "s162912327" ]
u844646164
p03073
python
s147587399
s399562767
109
94
5,536
3,956
Accepted
Accepted
13.76
s = list(map(int, eval(input()))) ideal1 = [0 for _ in range(len(s))] for i in range(len(s)): if i % 2 == 0: ideal1[i] = 1 else: ideal1[i] = 0 ideal2 = [0 for _ in range(len(s))] for i in range(len(s)): if i % 2 == 0: ideal2[i] = 0 else: ideal2[i] = 1 count1 = 0 count2 = 0 for i in range(len(s)): if s[i] != ideal1[i]: count1 += 1 elif s[i] != ideal2[i]: count2 += 1 print((min(count1, count2)))
S = list(eval(input())) ans1 = 0 ans2 = 0 # 10101010... for i in range(len(S)): if i % 2 == 0: if S[i] == '0': ans1 += 1 if i % 2 != 0: if S[i] == '1': ans1 += 1 # 01010101... for i in range(len(S)): if i % 2 == 0: if S[i] == '1': ans2 += 1 if i % 2 != 0: if S[i] == '0': ans2 += 1 print((min(ans1, ans2)))
27
21
457
367
s = list(map(int, eval(input()))) ideal1 = [0 for _ in range(len(s))] for i in range(len(s)): if i % 2 == 0: ideal1[i] = 1 else: ideal1[i] = 0 ideal2 = [0 for _ in range(len(s))] for i in range(len(s)): if i % 2 == 0: ideal2[i] = 0 else: ideal2[i] = 1 count1 = 0 count2 = 0 for i in range(len(s)): if s[i] != ideal1[i]: count1 += 1 elif s[i] != ideal2[i]: count2 += 1 print((min(count1, count2)))
S = list(eval(input())) ans1 = 0 ans2 = 0 # 10101010... for i in range(len(S)): if i % 2 == 0: if S[i] == "0": ans1 += 1 if i % 2 != 0: if S[i] == "1": ans1 += 1 # 01010101... for i in range(len(S)): if i % 2 == 0: if S[i] == "1": ans2 += 1 if i % 2 != 0: if S[i] == "0": ans2 += 1 print((min(ans1, ans2)))
false
22.222222
[ "-s = list(map(int, eval(input())))", "-ideal1 = [0 for _ in range(len(s))]", "-for i in range(len(s)):", "+S = list(eval(input()))", "+ans1 = 0", "+ans2 = 0", "+# 10101010...", "+for i in range(len(S)):", "- ideal1[i] = 1", "- else:", "- ideal1[i] = 0", "-ideal2 = [0 for _ in range(len(s))]", "-for i in range(len(s)):", "+ if S[i] == \"0\":", "+ ans1 += 1", "+ if i % 2 != 0:", "+ if S[i] == \"1\":", "+ ans1 += 1", "+# 01010101...", "+for i in range(len(S)):", "- ideal2[i] = 0", "- else:", "- ideal2[i] = 1", "-count1 = 0", "-count2 = 0", "-for i in range(len(s)):", "- if s[i] != ideal1[i]:", "- count1 += 1", "- elif s[i] != ideal2[i]:", "- count2 += 1", "-print((min(count1, count2)))", "+ if S[i] == \"1\":", "+ ans2 += 1", "+ if i % 2 != 0:", "+ if S[i] == \"0\":", "+ ans2 += 1", "+print((min(ans1, ans2)))" ]
false
0.048246
0.048448
0.995823
[ "s147587399", "s399562767" ]
u737758066
p02830
python
s524044646
s155679902
174
160
38,256
38,384
Accepted
Accepted
8.05
n = int(eval(input())) s, t = list(map(str, input().split())) u = "" for i in range(n): u += s[i] u += t[i] print(u)
n = int(eval(input())) s, t = input().split() ans = "" for i in range(n): ans += s[i] + t[i] print(ans)
7
7
119
109
n = int(eval(input())) s, t = list(map(str, input().split())) u = "" for i in range(n): u += s[i] u += t[i] print(u)
n = int(eval(input())) s, t = input().split() ans = "" for i in range(n): ans += s[i] + t[i] print(ans)
false
0
[ "-s, t = list(map(str, input().split()))", "-u = \"\"", "+s, t = input().split()", "+ans = \"\"", "- u += s[i]", "- u += t[i]", "-print(u)", "+ ans += s[i] + t[i]", "+print(ans)" ]
false
0.039004
0.06798
0.57376
[ "s524044646", "s155679902" ]
u366644013
p03251
python
s926037952
s651317356
19
17
3,064
3,064
Accepted
Accepted
10.53
il = lambda: list(map(int, input().split())) ils = lambda n, s="int(input())": [eval(s) for _ in range(n)] n, m, x, y = il() xs = il() ys = il() a = max(xs) b = min(ys) if x < a and b <= y and a < b: print("No War") else: print("War")
from sys import stdin il = lambda: list(map(int, input().split())) IL = lambda: list(map(int, stdin.readline().rstrip().split())) ils = lambda n, s="int(input())": [eval(s) for _ in range(n)] n, m, x, y = IL() xs = IL() ys = IL() a = max(xs) b = min(ys) if x < a and b <= y and a < b: print("No War") else: print("War")
12
14
254
341
il = lambda: list(map(int, input().split())) ils = lambda n, s="int(input())": [eval(s) for _ in range(n)] n, m, x, y = il() xs = il() ys = il() a = max(xs) b = min(ys) if x < a and b <= y and a < b: print("No War") else: print("War")
from sys import stdin il = lambda: list(map(int, input().split())) IL = lambda: list(map(int, stdin.readline().rstrip().split())) ils = lambda n, s="int(input())": [eval(s) for _ in range(n)] n, m, x, y = IL() xs = IL() ys = IL() a = max(xs) b = min(ys) if x < a and b <= y and a < b: print("No War") else: print("War")
false
14.285714
[ "+from sys import stdin", "+", "+IL = lambda: list(map(int, stdin.readline().rstrip().split()))", "-n, m, x, y = il()", "-xs = il()", "-ys = il()", "+n, m, x, y = IL()", "+xs = IL()", "+ys = IL()" ]
false
0.040578
0.041137
0.986412
[ "s926037952", "s651317356" ]
u490489966
p02582
python
s641157839
s828601648
28
25
9,044
9,100
Accepted
Accepted
10.71
#A stri=eval(input()) ans=0 s=0 for i in range(3): if stri[i]=="R": s+=1 else: if ans<s: ans=s s=0 if ans<s: ans=s print(ans)
# A s = eval(input()) count = 0 ans = 0 for i in range(len(s)): if s[i] == "R": count += 1 else: if ans < count: ans = count count = 0 if ans < count: ans = count print(ans)
14
14
180
229
# A stri = eval(input()) ans = 0 s = 0 for i in range(3): if stri[i] == "R": s += 1 else: if ans < s: ans = s s = 0 if ans < s: ans = s print(ans)
# A s = eval(input()) count = 0 ans = 0 for i in range(len(s)): if s[i] == "R": count += 1 else: if ans < count: ans = count count = 0 if ans < count: ans = count print(ans)
false
0
[ "-stri = eval(input())", "+s = eval(input())", "+count = 0", "-s = 0", "-for i in range(3):", "- if stri[i] == \"R\":", "- s += 1", "+for i in range(len(s)):", "+ if s[i] == \"R\":", "+ count += 1", "- if ans < s:", "- ans = s", "- s = 0", "-if ans < s:", "- ans = s", "+ if ans < count:", "+ ans = count", "+ count = 0", "+if ans < count:", "+ ans = count" ]
false
0.038521
0.038855
0.991399
[ "s641157839", "s828601648" ]
u888092736
p03967
python
s448137042
s171647407
45
36
9,108
9,396
Accepted
Accepted
20
S = eval(input()) cur = "g" acd = 0 tcd = 0 for c in S: if cur != c: if cur == "p": acd += 1 else: tcd += 1 cur = "p" if cur == "g" else "g" print((acd - tcd))
from collections import Counter S = Counter(eval(input())) print(((S["g"] - S["p"]) // 2))
13
4
213
87
S = eval(input()) cur = "g" acd = 0 tcd = 0 for c in S: if cur != c: if cur == "p": acd += 1 else: tcd += 1 cur = "p" if cur == "g" else "g" print((acd - tcd))
from collections import Counter S = Counter(eval(input())) print(((S["g"] - S["p"]) // 2))
false
69.230769
[ "-S = eval(input())", "-cur = \"g\"", "-acd = 0", "-tcd = 0", "-for c in S:", "- if cur != c:", "- if cur == \"p\":", "- acd += 1", "- else:", "- tcd += 1", "- cur = \"p\" if cur == \"g\" else \"g\"", "-print((acd - tcd))", "+from collections import Counter", "+", "+S = Counter(eval(input()))", "+print(((S[\"g\"] - S[\"p\"]) // 2))" ]
false
0.043217
0.080349
0.537868
[ "s448137042", "s171647407" ]
u899909022
p02912
python
s600497339
s662585820
257
161
15,020
14,224
Accepted
Accepted
37.35
n, m = list(map(int,input().split())) A = list(map(int,input().split())) A = [x * -1 for x in A] A.sort() import heapq import bisect heapq.heapify(A) for _ in range(m): min_ = heapq.heappop(A) tmp = min_ * -1 // 2 * -1 index = bisect.bisect_left(A, tmp) heapq.heappush(A,tmp) print((sum(A) * -1))
n, m = list(map(int,input().split())) A = [x * -1 for x in list(map(int,input().split()))] import heapq heapq.heapify(A) for _ in range(m): min_ = heapq.heappop(A) tmp = min_ * -1 // 2 * -1 heapq.heappush(A,tmp) print((sum(A) * -1))
13
9
317
245
n, m = list(map(int, input().split())) A = list(map(int, input().split())) A = [x * -1 for x in A] A.sort() import heapq import bisect heapq.heapify(A) for _ in range(m): min_ = heapq.heappop(A) tmp = min_ * -1 // 2 * -1 index = bisect.bisect_left(A, tmp) heapq.heappush(A, tmp) print((sum(A) * -1))
n, m = list(map(int, input().split())) A = [x * -1 for x in list(map(int, input().split()))] import heapq heapq.heapify(A) for _ in range(m): min_ = heapq.heappop(A) tmp = min_ * -1 // 2 * -1 heapq.heappush(A, tmp) print((sum(A) * -1))
false
30.769231
[ "-A = list(map(int, input().split()))", "-A = [x * -1 for x in A]", "-A.sort()", "+A = [x * -1 for x in list(map(int, input().split()))]", "-import bisect", "- index = bisect.bisect_left(A, tmp)" ]
false
0.041609
0.063134
0.65905
[ "s600497339", "s662585820" ]
u763968347
p03470
python
s155204765
s185949854
19
17
2,940
2,940
Accepted
Accepted
10.53
#coding : utf-8 n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d_uniq = list(set(d)) print((len(d_uniq)))
N = int(eval(input())) d = {} for _ in range(N): i = int(eval(input())) if i in list(d.keys()): d[i] += 1 else: d[i] = 1 print((len(d)))
8
11
134
156
# coding : utf-8 n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d_uniq = list(set(d)) print((len(d_uniq)))
N = int(eval(input())) d = {} for _ in range(N): i = int(eval(input())) if i in list(d.keys()): d[i] += 1 else: d[i] = 1 print((len(d)))
false
27.272727
[ "-# coding : utf-8", "-n = int(eval(input()))", "-d = []", "-for i in range(n):", "- d.append(int(eval(input())))", "-d_uniq = list(set(d))", "-print((len(d_uniq)))", "+N = int(eval(input()))", "+d = {}", "+for _ in range(N):", "+ i = int(eval(input()))", "+ if i in list(d.keys()):", "+ d[i] += 1", "+ else:", "+ d[i] = 1", "+print((len(d)))" ]
false
0.09881
0.035957
2.74801
[ "s155204765", "s185949854" ]
u078042885
p00322
python
s851878658
s422315783
1,480
730
7,728
7,804
Accepted
Accepted
50.68
import itertools u=[1,2,3,4,5,6,7,8,9] a=0 n=list(map(int,input().split())) for x in itertools.permutations(u): f=0 for i in range(9): if n[i]!=-1 and n[i]!=x[i]:f=1 if f:continue if x[0]+x[2]+x[5]-x[8]+(x[1]+x[4]-x[7])*10+(x[3]-x[6])*100==0:a+=1 print(a)
def f(n,x): for i in range(9): if n[i] != -1 and n[i] != x[i]: return 1 import itertools u=[1,2,3,4,5,6,7,8,9] a=0 n=list(map(int,input().split())) for x in itertools.permutations(u): if f(n,x):continue if x[0]+x[2]+x[5]-x[8]+(x[1]+x[4]-x[7])*10+(x[3]-x[6])*100==0:a+=1 print(a)
11
11
289
308
import itertools u = [1, 2, 3, 4, 5, 6, 7, 8, 9] a = 0 n = list(map(int, input().split())) for x in itertools.permutations(u): f = 0 for i in range(9): if n[i] != -1 and n[i] != x[i]: f = 1 if f: continue if x[0] + x[2] + x[5] - x[8] + (x[1] + x[4] - x[7]) * 10 + (x[3] - x[6]) * 100 == 0: a += 1 print(a)
def f(n, x): for i in range(9): if n[i] != -1 and n[i] != x[i]: return 1 import itertools u = [1, 2, 3, 4, 5, 6, 7, 8, 9] a = 0 n = list(map(int, input().split())) for x in itertools.permutations(u): if f(n, x): continue if x[0] + x[2] + x[5] - x[8] + (x[1] + x[4] - x[7]) * 10 + (x[3] - x[6]) * 100 == 0: a += 1 print(a)
false
0
[ "+def f(n, x):", "+ for i in range(9):", "+ if n[i] != -1 and n[i] != x[i]:", "+ return 1", "+", "+", "- f = 0", "- for i in range(9):", "- if n[i] != -1 and n[i] != x[i]:", "- f = 1", "- if f:", "+ if f(n, x):" ]
false
0.845074
0.727953
1.16089
[ "s851878658", "s422315783" ]
u983918956
p03212
python
s024320648
s259065320
144
42
7,540
3,060
Accepted
Accepted
70.83
from collections import deque N = int(eval(input())) ans = 0 option = ["7","5","3"] dq = deque() for s in option: dq.append(s) def judge(string): bit = [0]*3 chenge = {"7":0, "5":1, "3":2} for s in string: bit[chenge[s]] = 1 return all(bit) while dq: n = dq.popleft() if int(n) <= N and judge(n): ans += 1 if int(n) > N: continue for i,s in enumerate(option): dq.append(n+s) print(ans)
N = int(eval(input())) ans = 0 def dfs(n=0,a=0,b=0,c=0): if n > N: return if a*b*c > 0: global ans ans += 1 dfs(10*n+3,a+1,b,c) dfs(10*n+5,a,b+1,c) dfs(10*n+7,a,b,c+1) dfs() print(ans)
26
14
476
236
from collections import deque N = int(eval(input())) ans = 0 option = ["7", "5", "3"] dq = deque() for s in option: dq.append(s) def judge(string): bit = [0] * 3 chenge = {"7": 0, "5": 1, "3": 2} for s in string: bit[chenge[s]] = 1 return all(bit) while dq: n = dq.popleft() if int(n) <= N and judge(n): ans += 1 if int(n) > N: continue for i, s in enumerate(option): dq.append(n + s) print(ans)
N = int(eval(input())) ans = 0 def dfs(n=0, a=0, b=0, c=0): if n > N: return if a * b * c > 0: global ans ans += 1 dfs(10 * n + 3, a + 1, b, c) dfs(10 * n + 5, a, b + 1, c) dfs(10 * n + 7, a, b, c + 1) dfs() print(ans)
false
46.153846
[ "-from collections import deque", "-", "-option = [\"7\", \"5\", \"3\"]", "-dq = deque()", "-for s in option:", "- dq.append(s)", "-def judge(string):", "- bit = [0] * 3", "- chenge = {\"7\": 0, \"5\": 1, \"3\": 2}", "- for s in string:", "- bit[chenge[s]] = 1", "- return all(bit)", "+def dfs(n=0, a=0, b=0, c=0):", "+ if n > N:", "+ return", "+ if a * b * c > 0:", "+ global ans", "+ ans += 1", "+ dfs(10 * n + 3, a + 1, b, c)", "+ dfs(10 * n + 5, a, b + 1, c)", "+ dfs(10 * n + 7, a, b, c + 1)", "-while dq:", "- n = dq.popleft()", "- if int(n) <= N and judge(n):", "- ans += 1", "- if int(n) > N:", "- continue", "- for i, s in enumerate(option):", "- dq.append(n + s)", "+dfs()" ]
false
0.111259
0.040886
2.721209
[ "s024320648", "s259065320" ]
u116038906
p02683
python
s036161700
s132009187
182
166
27,376
27,100
Accepted
Accepted
8.79
from itertools import combinations import numpy as np import sys input = sys.stdin.readline #買う本 N, M, X = list(map(int, input().split())) C_np = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int) all_book= [i for i in range(N)] flag =False price_list =[] #C_np =np.array(C,dtype=int) price =C_np[:,0] understand =np.delete(C_np,0,1) for num in range(1,N+1): #1冊からN冊まで for t in combinations(all_book,num): #参考書を買う組合せ、全列挙 book_buy =np.array(t,dtype=int) understand_now = understand[book_buy] understand_sum = np.sum(understand_now, axis=0) if np.all(understand_sum >= X): price_now =price[book_buy] price_list.append(np.sum(price_now)) flag =True if flag ==True: print((min(price_list))) else: print((-1))
# 初期入力 from itertools import combinations from itertools import product import numpy as np import sys input = sys.stdin.readline N,M,X = (int(x) for x in input().split()) C = [list(map(int, input().split())) for i in range(N)] all_book= [i for i in range(N)] #買う本 price_list =[] flag =False C_np =np.array(C,dtype=int) price =C_np[:,0] understand =np.delete(C_np,0,1) for num in range(1,N+1): #1冊からN冊まで for t in combinations(all_book,num): #参考書を買う組合せ、全列挙 book_buy =np.array(t,dtype=int) #今回買った本 understand_now =understand[book_buy] #買ったうちの各本の知識 understand_sum =np.sum(understand_now,axis=0) #知識の合計 if np.all(X <= understand_sum ): #アルゴリズム理解度が全て目標値X以上か price_now =price[book_buy] price_list.append(np.sum(price_now)) flag =True if flag ==True: print((min(price_list))) else: print((-1))
26
30
865
958
from itertools import combinations import numpy as np import sys input = sys.stdin.readline # 買う本 N, M, X = list(map(int, input().split())) C_np = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int) all_book = [i for i in range(N)] flag = False price_list = [] # C_np =np.array(C,dtype=int) price = C_np[:, 0] understand = np.delete(C_np, 0, 1) for num in range(1, N + 1): # 1冊からN冊まで for t in combinations(all_book, num): # 参考書を買う組合せ、全列挙 book_buy = np.array(t, dtype=int) understand_now = understand[book_buy] understand_sum = np.sum(understand_now, axis=0) if np.all(understand_sum >= X): price_now = price[book_buy] price_list.append(np.sum(price_now)) flag = True if flag == True: print((min(price_list))) else: print((-1))
# 初期入力 from itertools import combinations from itertools import product import numpy as np import sys input = sys.stdin.readline N, M, X = (int(x) for x in input().split()) C = [list(map(int, input().split())) for i in range(N)] all_book = [i for i in range(N)] # 買う本 price_list = [] flag = False C_np = np.array(C, dtype=int) price = C_np[:, 0] understand = np.delete(C_np, 0, 1) for num in range(1, N + 1): # 1冊からN冊まで for t in combinations(all_book, num): # 参考書を買う組合せ、全列挙 book_buy = np.array(t, dtype=int) # 今回買った本 understand_now = understand[book_buy] # 買ったうちの各本の知識 understand_sum = np.sum(understand_now, axis=0) # 知識の合計 if np.all(X <= understand_sum): # アルゴリズム理解度が全て目標値X以上か price_now = price[book_buy] price_list.append(np.sum(price_now)) flag = True if flag == True: print((min(price_list))) else: print((-1))
false
13.333333
[ "+# 初期入力", "+from itertools import product", "-# 買う本", "-N, M, X = list(map(int, input().split()))", "-C_np = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int)", "-all_book = [i for i in range(N)]", "+N, M, X = (int(x) for x in input().split())", "+C = [list(map(int, input().split())) for i in range(N)]", "+all_book = [i for i in range(N)] # 買う本", "+price_list = []", "-price_list = []", "-# C_np =np.array(C,dtype=int)", "+C_np = np.array(C, dtype=int)", "- book_buy = np.array(t, dtype=int)", "- understand_now = understand[book_buy]", "- understand_sum = np.sum(understand_now, axis=0)", "- if np.all(understand_sum >= X):", "+ book_buy = np.array(t, dtype=int) # 今回買った本", "+ understand_now = understand[book_buy] # 買ったうちの各本の知識", "+ understand_sum = np.sum(understand_now, axis=0) # 知識の合計", "+ if np.all(X <= understand_sum): # アルゴリズム理解度が全て目標値X以上か" ]
false
0.232634
0.304409
0.764214
[ "s036161700", "s132009187" ]
u952708174
p03645
python
s566734558
s018031573
1,264
647
54,980
42,524
Accepted
Accepted
48.81
def Q3(N, M, *arg): import numpy as np route = np.reshape(np.array(*arg), (M, 2)) string = 'IMPOSSIBLE' p = [False] * N q = [False] * N for x in route: if x[0] == 1: p[x[1]] = True elif x[1] == N: q[x[0]] = True for i in range(N): if p[i] and q[i]: string = 'POSSIBLE' break return string N, M = list(map(int, input().split())) l = [list([int(x) for x in input().split()]) for i in range(M)] l = [flatten for inner in l for flatten in inner] print((Q3(N,M,l)))
def c_cat_snuke_and_a_voyage(N, M, I): p = [False] * N # 島1と島iに辺があるならTrue,なければFalse(0-indexed) q = [False] * N # 島iと島Nに辺があるならTrue,なければFalse(0-indexed) for a, b in I: if a == 1: # 出発地が島1なら p[b] = True elif b == N: # 目的地が島Nなら q[a] = True ans = 'IMPOSSIBLE' for i in range(N): if p[i] and q[i]: ans = 'POSSIBLE' break # 1つでもあればいい return ans N,M = [int(i) for i in input().split()] I = [[int(i) for i in input().split()] for j in range(M)] print((c_cat_snuke_and_a_voyage(N, M, I)))
21
18
582
595
def Q3(N, M, *arg): import numpy as np route = np.reshape(np.array(*arg), (M, 2)) string = "IMPOSSIBLE" p = [False] * N q = [False] * N for x in route: if x[0] == 1: p[x[1]] = True elif x[1] == N: q[x[0]] = True for i in range(N): if p[i] and q[i]: string = "POSSIBLE" break return string N, M = list(map(int, input().split())) l = [list([int(x) for x in input().split()]) for i in range(M)] l = [flatten for inner in l for flatten in inner] print((Q3(N, M, l)))
def c_cat_snuke_and_a_voyage(N, M, I): p = [False] * N # 島1と島iに辺があるならTrue,なければFalse(0-indexed) q = [False] * N # 島iと島Nに辺があるならTrue,なければFalse(0-indexed) for a, b in I: if a == 1: # 出発地が島1なら p[b] = True elif b == N: # 目的地が島Nなら q[a] = True ans = "IMPOSSIBLE" for i in range(N): if p[i] and q[i]: ans = "POSSIBLE" break # 1つでもあればいい return ans N, M = [int(i) for i in input().split()] I = [[int(i) for i in input().split()] for j in range(M)] print((c_cat_snuke_and_a_voyage(N, M, I)))
false
14.285714
[ "-def Q3(N, M, *arg):", "- import numpy as np", "-", "- route = np.reshape(np.array(*arg), (M, 2))", "- string = \"IMPOSSIBLE\"", "- p = [False] * N", "- q = [False] * N", "- for x in route:", "- if x[0] == 1:", "- p[x[1]] = True", "- elif x[1] == N:", "- q[x[0]] = True", "+def c_cat_snuke_and_a_voyage(N, M, I):", "+ p = [False] * N # 島1と島iに辺があるならTrue,なければFalse(0-indexed)", "+ q = [False] * N # 島iと島Nに辺があるならTrue,なければFalse(0-indexed)", "+ for a, b in I:", "+ if a == 1: # 出発地が島1なら", "+ p[b] = True", "+ elif b == N: # 目的地が島Nなら", "+ q[a] = True", "+ ans = \"IMPOSSIBLE\"", "- string = \"POSSIBLE\"", "- break", "- return string", "+ ans = \"POSSIBLE\"", "+ break # 1つでもあればいい", "+ return ans", "-N, M = list(map(int, input().split()))", "-l = [list([int(x) for x in input().split()]) for i in range(M)]", "-l = [flatten for inner in l for flatten in inner]", "-print((Q3(N, M, l)))", "+N, M = [int(i) for i in input().split()]", "+I = [[int(i) for i in input().split()] for j in range(M)]", "+print((c_cat_snuke_and_a_voyage(N, M, I)))" ]
false
0.192186
0.039879
4.819218
[ "s566734558", "s018031573" ]
u047796752
p02658
python
s203392741
s309905279
98
88
82,924
96,016
Accepted
Accepted
10.2
import sys input = sys.stdin.readline from collections import * N = int(eval(input())) A = list(map(int, input().split())) A.sort() ans = 1 for Ai in A: ans *= Ai if ans>10**18: print((-1)) exit() print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) s = set(A) if 0 in s: print((0)) exit() now = 1 for Ai in A: if now*Ai>10**18: print((-1)) exit() now *= Ai print(now)
17
21
255
267
import sys input = sys.stdin.readline from collections import * N = int(eval(input())) A = list(map(int, input().split())) A.sort() ans = 1 for Ai in A: ans *= Ai if ans > 10**18: print((-1)) exit() print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) s = set(A) if 0 in s: print((0)) exit() now = 1 for Ai in A: if now * Ai > 10**18: print((-1)) exit() now *= Ai print(now)
false
19.047619
[ "-from collections import *", "-", "-A.sort()", "-ans = 1", "+s = set(A)", "+if 0 in s:", "+ print((0))", "+ exit()", "+now = 1", "- ans *= Ai", "- if ans > 10**18:", "+ if now * Ai > 10**18:", "-print(ans)", "+ now *= Ai", "+print(now)" ]
false
0.080082
0.043705
1.832328
[ "s203392741", "s309905279" ]
u282228874
p03495
python
s059138402
s614325771
116
99
32,564
32,564
Accepted
Accepted
14.66
from collections import Counter n,k = list(map(int,input().split())) A = list(map(int,input().split())) D = Counter(A) V = [] for v in list(D.values()): V.append(v) V.sort(reverse=True) print((max(n-sum(V[:k]),0)))
from collections import Counter n,k = list(map(int,input().split())) A = list(map(int,input().split())) D = Counter(A) V = sorted(list(D.values()),reverse=True) print((max(n-sum(V[:k]),0)))
11
8
216
184
from collections import Counter n, k = list(map(int, input().split())) A = list(map(int, input().split())) D = Counter(A) V = [] for v in list(D.values()): V.append(v) V.sort(reverse=True) print((max(n - sum(V[:k]), 0)))
from collections import Counter n, k = list(map(int, input().split())) A = list(map(int, input().split())) D = Counter(A) V = sorted(list(D.values()), reverse=True) print((max(n - sum(V[:k]), 0)))
false
27.272727
[ "-V = []", "-for v in list(D.values()):", "- V.append(v)", "-V.sort(reverse=True)", "+V = sorted(list(D.values()), reverse=True)" ]
false
0.039817
0.05663
0.703108
[ "s059138402", "s614325771" ]
u201928947
p02936
python
s020543509
s127982227
1,702
828
65,652
159,120
Accepted
Accepted
51.35
from collections import deque n,q = list(map(int,input().split())) lst = [[]for i in range(n)] ans = [0 for i in range(n)] for i in range(n-1): a,b = list(map(int,input().split())) lst[a-1].append(b) lst[b-1].append(a) for i in range(q): p,x = list(map(int,input().split())) ans[p-1] += x q = deque([1]) while q: x = q.popleft() for i in lst[x-1]: q.append(i) lst[i-1].remove(x) ans[i-1] += ans[x-1] print((" ".join(map(str,ans))))
from collections import deque N,Q = list(map(int,input().split())) tree = [[] for _ in range(N+1)] counter = [0]*(N+1) for i in range(N-1): a,b = list(map(int,input().split())) tree[a].append(b) tree[b].append(a) for i in range(Q): p,x = list(map(int,input().split())) counter[p] += x already = set() d = deque([1]) while d: a = d.popleft() for b in tree[a]: if not b in already: counter[b] += counter[a] d.append(b) already.add(a) print((*counter[1:]))
19
23
482
521
from collections import deque n, q = list(map(int, input().split())) lst = [[] for i in range(n)] ans = [0 for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) lst[a - 1].append(b) lst[b - 1].append(a) for i in range(q): p, x = list(map(int, input().split())) ans[p - 1] += x q = deque([1]) while q: x = q.popleft() for i in lst[x - 1]: q.append(i) lst[i - 1].remove(x) ans[i - 1] += ans[x - 1] print((" ".join(map(str, ans))))
from collections import deque N, Q = list(map(int, input().split())) tree = [[] for _ in range(N + 1)] counter = [0] * (N + 1) for i in range(N - 1): a, b = list(map(int, input().split())) tree[a].append(b) tree[b].append(a) for i in range(Q): p, x = list(map(int, input().split())) counter[p] += x already = set() d = deque([1]) while d: a = d.popleft() for b in tree[a]: if not b in already: counter[b] += counter[a] d.append(b) already.add(a) print((*counter[1:]))
false
17.391304
[ "-n, q = list(map(int, input().split()))", "-lst = [[] for i in range(n)]", "-ans = [0 for i in range(n)]", "-for i in range(n - 1):", "+N, Q = list(map(int, input().split()))", "+tree = [[] for _ in range(N + 1)]", "+counter = [0] * (N + 1)", "+for i in range(N - 1):", "- lst[a - 1].append(b)", "- lst[b - 1].append(a)", "-for i in range(q):", "+ tree[a].append(b)", "+ tree[b].append(a)", "+for i in range(Q):", "- ans[p - 1] += x", "-q = deque([1])", "-while q:", "- x = q.popleft()", "- for i in lst[x - 1]:", "- q.append(i)", "- lst[i - 1].remove(x)", "- ans[i - 1] += ans[x - 1]", "-print((\" \".join(map(str, ans))))", "+ counter[p] += x", "+already = set()", "+d = deque([1])", "+while d:", "+ a = d.popleft()", "+ for b in tree[a]:", "+ if not b in already:", "+ counter[b] += counter[a]", "+ d.append(b)", "+ already.add(a)", "+print((*counter[1:]))" ]
false
0.104876
0.138803
0.755573
[ "s020543509", "s127982227" ]
u614314290
p03208
python
s484728569
s794865680
176
127
25,064
19,252
Accepted
Accepted
27.84
import sys from operator import itemgetter as ig from collections import defaultdict as dd # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def int1(n): return int(n) - 1 def input(): return next(args) def parse(*params): if len(params) == 1: return params[0](next(args)) return tuple(p(v) for p, v in zip(params, next(args).split())) def debug(*v): if __debug__: print(*v, file=sys.stderr) # エントリーポイント def main(): N, K = parse(int, int) H = [parse(int) for _ in range(N)] h = sorted(H) l, r = 0, K sum_h = [0] for n in range(1, N): sum_h += [sum_h[-1] + (h[n] - h[n - 1])] debug(sum_h) diff_h = tuple(sum_h[l + K - 1] - sum_h[l] for l in range(N - K + 1)) debug(diff_h) print(min(diff_h)) if __name__ == '__main__': args = iter(sys.stdin.read().split("\n")) main()
import sys from operator import itemgetter as ig from collections import defaultdict as dd # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def int1(n): return int(n) - 1 def input(): return next(args) def parse(*params): if len(params) == 1: return params[0](next(args)) return tuple(p(v) for p, v in zip(params, next(args).split())) def debug(*v): if __debug__: print(*v, file=sys.stderr) # エントリーポイント def main(): N, K = parse(int, int) H = [parse(int) for _ in range(N)] h = sorted(H) diff_h = tuple(h[l + K - 1] - h[l] for l in range(N - K + 1)) print(min(diff_h)) if __name__ == '__main__': args = iter(sys.stdin.read().split("\n")) main()
40
34
910
754
import sys from operator import itemgetter as ig from collections import defaultdict as dd # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def int1(n): return int(n) - 1 def input(): return next(args) def parse(*params): if len(params) == 1: return params[0](next(args)) return tuple(p(v) for p, v in zip(params, next(args).split())) def debug(*v): if __debug__: print(*v, file=sys.stderr) # エントリーポイント def main(): N, K = parse(int, int) H = [parse(int) for _ in range(N)] h = sorted(H) l, r = 0, K sum_h = [0] for n in range(1, N): sum_h += [sum_h[-1] + (h[n] - h[n - 1])] debug(sum_h) diff_h = tuple(sum_h[l + K - 1] - sum_h[l] for l in range(N - K + 1)) debug(diff_h) print(min(diff_h)) if __name__ == "__main__": args = iter(sys.stdin.read().split("\n")) main()
import sys from operator import itemgetter as ig from collections import defaultdict as dd # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def int1(n): return int(n) - 1 def input(): return next(args) def parse(*params): if len(params) == 1: return params[0](next(args)) return tuple(p(v) for p, v in zip(params, next(args).split())) def debug(*v): if __debug__: print(*v, file=sys.stderr) # エントリーポイント def main(): N, K = parse(int, int) H = [parse(int) for _ in range(N)] h = sorted(H) diff_h = tuple(h[l + K - 1] - h[l] for l in range(N - K + 1)) print(min(diff_h)) if __name__ == "__main__": args = iter(sys.stdin.read().split("\n")) main()
false
15
[ "- l, r = 0, K", "- sum_h = [0]", "- for n in range(1, N):", "- sum_h += [sum_h[-1] + (h[n] - h[n - 1])]", "- debug(sum_h)", "- diff_h = tuple(sum_h[l + K - 1] - sum_h[l] for l in range(N - K + 1))", "- debug(diff_h)", "+ diff_h = tuple(h[l + K - 1] - h[l] for l in range(N - K + 1))" ]
false
0.037801
0.007769
4.86541
[ "s484728569", "s794865680" ]
u657076895
p02389
python
s344222616
s674176006
30
20
6,276
5,684
Accepted
Accepted
33.33
import sys from functools import reduce for line in sys.stdin: nums = list([int(x) for x in line.split()]) menseki = reduce(lambda x, y: x * y, nums) syuu = reduce(lambda x, y: x + y, nums) * 2 print((str(menseki) + " " + str(syuu)))
import sys import operator for line in sys.stdin: nums = list(map(int, line.split())) strings = list(map(str, [operator.mul(*nums), operator.add(*nums) * 2])) print((" ".join(strings)))
9
9
263
224
import sys from functools import reduce for line in sys.stdin: nums = list([int(x) for x in line.split()]) menseki = reduce(lambda x, y: x * y, nums) syuu = reduce(lambda x, y: x + y, nums) * 2 print((str(menseki) + " " + str(syuu)))
import sys import operator for line in sys.stdin: nums = list(map(int, line.split())) strings = list(map(str, [operator.mul(*nums), operator.add(*nums) * 2])) print((" ".join(strings)))
false
0
[ "-from functools import reduce", "+import operator", "- nums = list([int(x) for x in line.split()])", "- menseki = reduce(lambda x, y: x * y, nums)", "- syuu = reduce(lambda x, y: x + y, nums) * 2", "- print((str(menseki) + \" \" + str(syuu)))", "+ nums = list(map(int, line.split()))", "+ strings = list(map(str, [operator.mul(*nums), operator.add(*nums) * 2]))", "+ print((\" \".join(strings)))" ]
false
0.048803
0.050008
0.97591
[ "s344222616", "s674176006" ]
u925406312
p03416
python
s436269815
s430817571
61
56
2,940
2,940
Accepted
Accepted
8.2
A,B = list(map(int,input().split())) count = 0 for i in range(A, B + 1): aa =str(i) rslt = aa[::-1] if aa == rslt: count += 1 print(count)
A,B = list(map(int,input().split())) su = abs(A -B) count = 0 for i in range(A, B + 1): aa =str(i) rslt = aa[::-1] if aa == rslt: count += 1 print(count)
9
9
161
175
A, B = list(map(int, input().split())) count = 0 for i in range(A, B + 1): aa = str(i) rslt = aa[::-1] if aa == rslt: count += 1 print(count)
A, B = list(map(int, input().split())) su = abs(A - B) count = 0 for i in range(A, B + 1): aa = str(i) rslt = aa[::-1] if aa == rslt: count += 1 print(count)
false
0
[ "+su = abs(A - B)" ]
false
0.04663
0.043687
1.067366
[ "s436269815", "s430817571" ]
u994521204
p02913
python
s157480318
s825086980
797
103
53,724
75,676
Accepted
Accepted
87.08
# suffix array # z-algorithm # rolling-hash # dp n = int(eval(input())) s = eval(input()) # z-algorithm # i左端 # j iからの距離 # k i-i+jの間を進みながら比較 ans = 0 for num in range(n - 1): S = s[num:] A = [0] * (n - num) A[0] = n - num i = 1 j = 0 while i < n - num: while i + j < n - num and S[j] == S[i + j]: j += 1 A[i] = j ans = max(ans, min(i, j)) if j == 0: i += 1 continue k = 1 while i + k < n - num and k + A[k] < j: A[i + k] = A[k] ans = max(ans, min(k, A[k])) k += 1 i += k j -= k print(ans)
# 32bitのMod一つでRollingHashを行った場合、 # 10**5個程度のHashを生成するだけでも # 半分以上の確率でどこかのHashが衝突していることが分かります # 小文字アルファベットの時のbese base = 27 # alphabet def getnum(x): return ord(x) - ord("a") + 1 # rolling hash実装 # 必要な定数 # mod = 1<<61-1としたときの高速余り計算 m30 = (1 << 30) - 1 m31 = (1 << 31) - 1 m61 = (1 << 61) - 1 mod = m61 positive_delta = m61 ** 4 # 高速化された計算 def mul(a, b): au = a >> 31 ad = a & m31 # 余りを取ることが&演算でできる bu = b >> 31 bd = b & m31 mid = ad * bu + au * bd midu = mid >> 30 midd = mid & m30 return calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd) def calcmod(a): au = a >> 61 ad = a & m61 res = au + ad if res >= m61: res -= m61 return res # s:string def rollinghash(s): num = len(s) res = [0] * (num + 1) pow_base = [1] * (num + 1) for i in range(num): res[i + 1] = calcmod(mul(res[i], base) + getnum(s[i])) pow_base[i + 1] = calcmod(mul(pow_base[i], base)) return res, pow_base def search(left, right, rh): return calcmod(rh[right] - mul(rh[left], pow_base[right - left]) + positive_delta) n = int(eval(input())) s = eval(input()) rh, pow_base = rollinghash(s) ng = n ok = 0 def hantei(x, rh): kumi = {} for i in range(n - x + 1): temp = search(i, i + x, rh) if temp in kumi: pre_idx = kumi[temp] if i - pre_idx >= x: # print("pair", i, pre_idx, "delta", x) return True else: kumi[temp] = i # print(x, kumi) return False while ng - ok > 1: mid = (ng + ok) // 2 if hantei(mid, rh): ok = mid else: ng = mid # print(ok, ng) print(ok)
34
91
670
1,772
# suffix array # z-algorithm # rolling-hash # dp n = int(eval(input())) s = eval(input()) # z-algorithm # i左端 # j iからの距離 # k i-i+jの間を進みながら比較 ans = 0 for num in range(n - 1): S = s[num:] A = [0] * (n - num) A[0] = n - num i = 1 j = 0 while i < n - num: while i + j < n - num and S[j] == S[i + j]: j += 1 A[i] = j ans = max(ans, min(i, j)) if j == 0: i += 1 continue k = 1 while i + k < n - num and k + A[k] < j: A[i + k] = A[k] ans = max(ans, min(k, A[k])) k += 1 i += k j -= k print(ans)
# 32bitのMod一つでRollingHashを行った場合、 # 10**5個程度のHashを生成するだけでも # 半分以上の確率でどこかのHashが衝突していることが分かります # 小文字アルファベットの時のbese base = 27 # alphabet def getnum(x): return ord(x) - ord("a") + 1 # rolling hash実装 # 必要な定数 # mod = 1<<61-1としたときの高速余り計算 m30 = (1 << 30) - 1 m31 = (1 << 31) - 1 m61 = (1 << 61) - 1 mod = m61 positive_delta = m61**4 # 高速化された計算 def mul(a, b): au = a >> 31 ad = a & m31 # 余りを取ることが&演算でできる bu = b >> 31 bd = b & m31 mid = ad * bu + au * bd midu = mid >> 30 midd = mid & m30 return calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd) def calcmod(a): au = a >> 61 ad = a & m61 res = au + ad if res >= m61: res -= m61 return res # s:string def rollinghash(s): num = len(s) res = [0] * (num + 1) pow_base = [1] * (num + 1) for i in range(num): res[i + 1] = calcmod(mul(res[i], base) + getnum(s[i])) pow_base[i + 1] = calcmod(mul(pow_base[i], base)) return res, pow_base def search(left, right, rh): return calcmod(rh[right] - mul(rh[left], pow_base[right - left]) + positive_delta) n = int(eval(input())) s = eval(input()) rh, pow_base = rollinghash(s) ng = n ok = 0 def hantei(x, rh): kumi = {} for i in range(n - x + 1): temp = search(i, i + x, rh) if temp in kumi: pre_idx = kumi[temp] if i - pre_idx >= x: # print("pair", i, pre_idx, "delta", x) return True else: kumi[temp] = i # print(x, kumi) return False while ng - ok > 1: mid = (ng + ok) // 2 if hantei(mid, rh): ok = mid else: ng = mid # print(ok, ng) print(ok)
false
62.637363
[ "-# suffix array", "-# z-algorithm", "-# rolling-hash", "-# dp", "+# 32bitのMod一つでRollingHashを行った場合、", "+# 10**5個程度のHashを生成するだけでも", "+# 半分以上の確率でどこかのHashが衝突していることが分かります", "+# 小文字アルファベットの時のbese", "+base = 27 # alphabet", "+", "+", "+def getnum(x):", "+ return ord(x) - ord(\"a\") + 1", "+", "+", "+# rolling hash実装", "+# 必要な定数", "+# mod = 1<<61-1としたときの高速余り計算", "+m30 = (1 << 30) - 1", "+m31 = (1 << 31) - 1", "+m61 = (1 << 61) - 1", "+mod = m61", "+positive_delta = m61**4", "+# 高速化された計算", "+def mul(a, b):", "+ au = a >> 31", "+ ad = a & m31 # 余りを取ることが&演算でできる", "+ bu = b >> 31", "+ bd = b & m31", "+ mid = ad * bu + au * bd", "+ midu = mid >> 30", "+ midd = mid & m30", "+ return calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd)", "+", "+", "+def calcmod(a):", "+ au = a >> 61", "+ ad = a & m61", "+ res = au + ad", "+ if res >= m61:", "+ res -= m61", "+ return res", "+", "+", "+# s:string", "+def rollinghash(s):", "+ num = len(s)", "+ res = [0] * (num + 1)", "+ pow_base = [1] * (num + 1)", "+ for i in range(num):", "+ res[i + 1] = calcmod(mul(res[i], base) + getnum(s[i]))", "+ pow_base[i + 1] = calcmod(mul(pow_base[i], base))", "+ return res, pow_base", "+", "+", "+def search(left, right, rh):", "+ return calcmod(rh[right] - mul(rh[left], pow_base[right - left]) + positive_delta)", "+", "+", "-# z-algorithm", "-# i左端", "-# j iからの距離", "-# k i-i+jの間を進みながら比較", "-ans = 0", "-for num in range(n - 1):", "- S = s[num:]", "- A = [0] * (n - num)", "- A[0] = n - num", "- i = 1", "- j = 0", "- while i < n - num:", "- while i + j < n - num and S[j] == S[i + j]:", "- j += 1", "- A[i] = j", "- ans = max(ans, min(i, j))", "- if j == 0:", "- i += 1", "- continue", "- k = 1", "- while i + k < n - num and k + A[k] < j:", "- A[i + k] = A[k]", "- ans = max(ans, min(k, A[k]))", "- k += 1", "- i += k", "- j -= k", "-print(ans)", "+rh, pow_base = rollinghash(s)", "+ng = n", "+ok = 0", "+", "+", "+def hantei(x, rh):", "+ kumi = {}", "+ for i in range(n - x + 1):", "+ temp = search(i, i + x, rh)", "+ if temp in kumi:", "+ pre_idx = kumi[temp]", "+ if i - pre_idx >= x:", "+ # print(\"pair\", i, pre_idx, \"delta\", x)", "+ return True", "+ else:", "+ kumi[temp] = i", "+ # print(x, kumi)", "+ return False", "+", "+", "+while ng - ok > 1:", "+ mid = (ng + ok) // 2", "+ if hantei(mid, rh):", "+ ok = mid", "+ else:", "+ ng = mid", "+ # print(ok, ng)", "+print(ok)" ]
false
0.040001
0.140465
0.284776
[ "s157480318", "s825086980" ]
u332385682
p04040
python
s909694836
s815005891
324
235
26,740
20,340
Accepted
Accepted
27.47
from sys import stdin, stdout, stderr mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = list(map(int, input().split())) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) inv = [1] * (h + w) for i in range(2, h + w): modfact[i] = (i * modfact[i - 1]) % mod inv[i] = (-(mod // i) * inv[mod % i]) % mod factinv[i] = (inv[i] * factinv[i - 1]) % mod for i in range(h - a): ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod ans %= mod print(ans) if __name__ == '__main__': solve()
from sys import stdin, stdout, stderr mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = list(map(int, input().split())) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) inv = [1] * (h + w) for i in range(2, h + w): modfact[i] = (i * modfact[i - 1]) % mod factinv[h + w - 1] = pow(modfact[h + w - 1], mod - 2, mod) for i in range(h + w - 2, 0, -1): factinv[i] = (factinv[i + 1] * (i + 1)) % mod for i in range(h - a): ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod ans %= mod print(ans) if __name__ == '__main__': solve()
29
32
729
784
from sys import stdin, stdout, stderr mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = list(map(int, input().split())) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) inv = [1] * (h + w) for i in range(2, h + w): modfact[i] = (i * modfact[i - 1]) % mod inv[i] = (-(mod // i) * inv[mod % i]) % mod factinv[i] = (inv[i] * factinv[i - 1]) % mod for i in range(h - a): ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod ans %= mod print(ans) if __name__ == "__main__": solve()
from sys import stdin, stdout, stderr mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = list(map(int, input().split())) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) inv = [1] * (h + w) for i in range(2, h + w): modfact[i] = (i * modfact[i - 1]) % mod factinv[h + w - 1] = pow(modfact[h + w - 1], mod - 2, mod) for i in range(h + w - 2, 0, -1): factinv[i] = (factinv[i + 1] * (i + 1)) % mod for i in range(h - a): ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod ans %= mod print(ans) if __name__ == "__main__": solve()
false
9.375
[ "- inv[i] = (-(mod // i) * inv[mod % i]) % mod", "- factinv[i] = (inv[i] * factinv[i - 1]) % mod", "+ factinv[h + w - 1] = pow(modfact[h + w - 1], mod - 2, mod)", "+ for i in range(h + w - 2, 0, -1):", "+ factinv[i] = (factinv[i + 1] * (i + 1)) % mod" ]
false
0.236988
0.128936
1.838025
[ "s909694836", "s815005891" ]
u681444474
p02887
python
s015916764
s439306019
274
181
75,256
49,392
Accepted
Accepted
33.94
import copy N = int(eval(input())) S = list(eval(input())) l = copy.deepcopy(S) for i in range(N-1): if S[i] == S[i+1]: l[i]=0 l_=[i for i in l if i!=0] print((len(l_)))
N = int(eval(input())) S=list(eval(input())) cnt=0 for i in range(N-1): if S[i]==S[i+1]: cnt+=1 print((len(S)-cnt))
12
8
177
119
import copy N = int(eval(input())) S = list(eval(input())) l = copy.deepcopy(S) for i in range(N - 1): if S[i] == S[i + 1]: l[i] = 0 l_ = [i for i in l if i != 0] print((len(l_)))
N = int(eval(input())) S = list(eval(input())) cnt = 0 for i in range(N - 1): if S[i] == S[i + 1]: cnt += 1 print((len(S) - cnt))
false
33.333333
[ "-import copy", "-", "-l = copy.deepcopy(S)", "+cnt = 0", "- l[i] = 0", "-l_ = [i for i in l if i != 0]", "-print((len(l_)))", "+ cnt += 1", "+print((len(S) - cnt))" ]
false
0.04504
0.077888
0.578271
[ "s015916764", "s439306019" ]
u734589227
p02971
python
s042958036
s993575196
1,236
355
38,356
13,404
Accepted
Accepted
71.28
import sys input = sys.stdin.readline import numpy as np n = int(eval(input())) num = [eval(input()) for _ in range(n)] num = np.array(num).astype("int64") #ma=max(num) #ind=num.index(ma) sorted_num=sorted(num) ma=sorted_num[-1] ma2=sorted_num[-2] for i in range(n): if ma != num[i]: print((str(ma).strip())) else: print((str(ma2).strip()))
import sys input = sys.stdin.readline n = int(eval(input())) num = [int(eval(input())) for _ in range(n)] ma=max(num) ind=num.index(ma) ma2=sorted(num)[-2] for i in range(n): if ind==i: print(ma2) else: print(ma)
16
13
365
239
import sys input = sys.stdin.readline import numpy as np n = int(eval(input())) num = [eval(input()) for _ in range(n)] num = np.array(num).astype("int64") # ma=max(num) # ind=num.index(ma) sorted_num = sorted(num) ma = sorted_num[-1] ma2 = sorted_num[-2] for i in range(n): if ma != num[i]: print((str(ma).strip())) else: print((str(ma2).strip()))
import sys input = sys.stdin.readline n = int(eval(input())) num = [int(eval(input())) for _ in range(n)] ma = max(num) ind = num.index(ma) ma2 = sorted(num)[-2] for i in range(n): if ind == i: print(ma2) else: print(ma)
false
18.75
[ "-import numpy as np", "-", "-num = [eval(input()) for _ in range(n)]", "-num = np.array(num).astype(\"int64\")", "-# ma=max(num)", "-# ind=num.index(ma)", "-sorted_num = sorted(num)", "-ma = sorted_num[-1]", "-ma2 = sorted_num[-2]", "+num = [int(eval(input())) for _ in range(n)]", "+ma = max(num)", "+ind = num.index(ma)", "+ma2 = sorted(num)[-2]", "- if ma != num[i]:", "- print((str(ma).strip()))", "+ if ind == i:", "+ print(ma2)", "- print((str(ma2).strip()))", "+ print(ma)" ]
false
0.85541
0.037843
22.604355
[ "s042958036", "s993575196" ]
u980322611
p02793
python
s037515975
s184827789
942
823
67,432
47,964
Accepted
Accepted
12.63
N = int(eval(input())) A = list(map(int,input().split())) mod = 10**9 + 7 from fractions import gcd def lcm(a,b): return a//gcd(a,b)*b AA = 1 for i in range(N): AA = lcm(AA,A[i]) AA %= mod ans = 0 for i in range(N): ans += AA*pow(A[i],mod-2,mod) print((ans%mod))
N = int(eval(input())) A = list(map(int,input().split())) mod = 10**9 + 7 def p_prime(n): prime = [2] for i in range(3,n+1): flag = 0 for j in prime: if i%j == 0: flag = 1 break if i**0.5 < j: break if flag == 0: prime.append(i) return prime prime = p_prime(int(mod**0.5+1)) def soinsuu(M): a = {} for p in prime: count = 0 while M%p ==0: count += 1 M //= p if count > 0: a[p] = count if M != 1: a[M] = 1 return a from collections import defaultdict AA = defaultdict(int) for i in range(N): tmp = soinsuu(A[i]) for j in tmp: AA[j] = max(AA[j], tmp[j]) L = 1 for i in AA: L *= pow(i,AA[i],mod) ans = 0 for i in range(N): ans += L*pow(A[i],mod-2,mod) print((ans%mod))
19
49
295
954
N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 from fractions import gcd def lcm(a, b): return a // gcd(a, b) * b AA = 1 for i in range(N): AA = lcm(AA, A[i]) AA %= mod ans = 0 for i in range(N): ans += AA * pow(A[i], mod - 2, mod) print((ans % mod))
N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 def p_prime(n): prime = [2] for i in range(3, n + 1): flag = 0 for j in prime: if i % j == 0: flag = 1 break if i**0.5 < j: break if flag == 0: prime.append(i) return prime prime = p_prime(int(mod**0.5 + 1)) def soinsuu(M): a = {} for p in prime: count = 0 while M % p == 0: count += 1 M //= p if count > 0: a[p] = count if M != 1: a[M] = 1 return a from collections import defaultdict AA = defaultdict(int) for i in range(N): tmp = soinsuu(A[i]) for j in tmp: AA[j] = max(AA[j], tmp[j]) L = 1 for i in AA: L *= pow(i, AA[i], mod) ans = 0 for i in range(N): ans += L * pow(A[i], mod - 2, mod) print((ans % mod))
false
61.22449
[ "-from fractions import gcd", "-def lcm(a, b):", "- return a // gcd(a, b) * b", "+def p_prime(n):", "+ prime = [2]", "+ for i in range(3, n + 1):", "+ flag = 0", "+ for j in prime:", "+ if i % j == 0:", "+ flag = 1", "+ break", "+ if i**0.5 < j:", "+ break", "+ if flag == 0:", "+ prime.append(i)", "+ return prime", "-AA = 1", "+prime = p_prime(int(mod**0.5 + 1))", "+", "+", "+def soinsuu(M):", "+ a = {}", "+ for p in prime:", "+ count = 0", "+ while M % p == 0:", "+ count += 1", "+ M //= p", "+ if count > 0:", "+ a[p] = count", "+ if M != 1:", "+ a[M] = 1", "+ return a", "+", "+", "+from collections import defaultdict", "+", "+AA = defaultdict(int)", "- AA = lcm(AA, A[i])", "-AA %= mod", "+ tmp = soinsuu(A[i])", "+ for j in tmp:", "+ AA[j] = max(AA[j], tmp[j])", "+L = 1", "+for i in AA:", "+ L *= pow(i, AA[i], mod)", "- ans += AA * pow(A[i], mod - 2, mod)", "+ ans += L * pow(A[i], mod - 2, mod)" ]
false
0.04105
0.080262
0.511454
[ "s037515975", "s184827789" ]
u022979415
p02691
python
s779432652
s882783011
228
180
65,152
46,156
Accepted
Accepted
21.05
from collections import Counter def main(): n = int(eval(input())) a = list(map(int, input().split())) b = [] c = [] for i in range(n): b.append(a[i] + i + 1) c.append(i + 1 - a[i]) b = list(Counter(b).items()) c = Counter(c) answer = 0 for i, n in b: if i in c: answer += n * c[i] print(answer) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = [] c = {} answer = 0 for i in range(n): b.append(a[i] + i + 1) tmp = -a[i] + i + 1 if tmp in c: c[tmp] += 1 else: c[tmp] = 1 for i in range(n): if b[i] in c: answer += c[b[i]] print(answer) if __name__ == '__main__': main()
23
22
431
429
from collections import Counter def main(): n = int(eval(input())) a = list(map(int, input().split())) b = [] c = [] for i in range(n): b.append(a[i] + i + 1) c.append(i + 1 - a[i]) b = list(Counter(b).items()) c = Counter(c) answer = 0 for i, n in b: if i in c: answer += n * c[i] print(answer) if __name__ == "__main__": main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = [] c = {} answer = 0 for i in range(n): b.append(a[i] + i + 1) tmp = -a[i] + i + 1 if tmp in c: c[tmp] += 1 else: c[tmp] = 1 for i in range(n): if b[i] in c: answer += c[b[i]] print(answer) if __name__ == "__main__": main()
false
4.347826
[ "-from collections import Counter", "-", "-", "- c = []", "+ c = {}", "+ answer = 0", "- c.append(i + 1 - a[i])", "- b = list(Counter(b).items())", "- c = Counter(c)", "- answer = 0", "- for i, n in b:", "- if i in c:", "- answer += n * c[i]", "+ tmp = -a[i] + i + 1", "+ if tmp in c:", "+ c[tmp] += 1", "+ else:", "+ c[tmp] = 1", "+ for i in range(n):", "+ if b[i] in c:", "+ answer += c[b[i]]" ]
false
0.039018
0.041301
0.944722
[ "s779432652", "s882783011" ]
u305366205
p02773
python
s548824627
s473813148
992
717
48,640
45,040
Accepted
Accepted
27.72
import collections n = int(input()) dd = collections.defaultdict(int) for _ in range(n): dd[input()] += 1 ans = [] for key in dd.keys(): ans.append((dd[key], key)) ans.sort(reverse=True) ans2 = [ans[0][1]] for i in range(1, len(ans)): if ans[i - 1][0] != ans[i][0]: break ans2.append(ans[i][1]) ans2.sort() print(*ans2, sep='\n')
import collections n = int(input()) s = [input() for _ in range(n)] s = collections.Counter(s).most_common() ans = [] for i in range(1, len(s) + 1): ans.append(s[i - 1][0]) if i == len(s): break if s[i - 1][1] != s[i][1]: break ans.sort() print(*ans, sep='\n')
16
13
368
300
import collections n = int(input()) dd = collections.defaultdict(int) for _ in range(n): dd[input()] += 1 ans = [] for key in dd.keys(): ans.append((dd[key], key)) ans.sort(reverse=True) ans2 = [ans[0][1]] for i in range(1, len(ans)): if ans[i - 1][0] != ans[i][0]: break ans2.append(ans[i][1]) ans2.sort() print(*ans2, sep="\n")
import collections n = int(input()) s = [input() for _ in range(n)] s = collections.Counter(s).most_common() ans = [] for i in range(1, len(s) + 1): ans.append(s[i - 1][0]) if i == len(s): break if s[i - 1][1] != s[i][1]: break ans.sort() print(*ans, sep="\n")
false
18.75
[ "-dd = collections.defaultdict(int)", "-for _ in range(n):", "- dd[input()] += 1", "+s = [input() for _ in range(n)]", "+s = collections.Counter(s).most_common()", "-for key in dd.keys():", "- ans.append((dd[key], key))", "-ans.sort(reverse=True)", "-ans2 = [ans[0][1]]", "-for i in range(1, len(ans)):", "- if ans[i - 1][0] != ans[i][0]:", "+for i in range(1, len(s) + 1):", "+ ans.append(s[i - 1][0])", "+ if i == len(s):", "- ans2.append(ans[i][1])", "-ans2.sort()", "-print(*ans2, sep=\"\\n\")", "+ if s[i - 1][1] != s[i][1]:", "+ break", "+ans.sort()", "+print(*ans, sep=\"\\n\")" ]
false
0.030871
0.031331
0.985316
[ "s548824627", "s473813148" ]
u994988729
p03062
python
s706324376
s273550867
387
312
23,292
24,804
Accepted
Accepted
19.38
from numpy import sign n=int(eval(input())) a=list(map(int,input().split())) a_abs=list(map(abs,a)) a_abs.sort() plmi=1 for i in a: plmi*=sign(i) if plmi==-1: ans=sum(a_abs[1:])-a_abs[0] elif plmi==1 or plmi==0: ans=sum(a_abs) print(ans)
import numpy as np N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) neg = np.count_nonzero(A[A < 0]) ans = np.abs(A).sum() if neg % 2 == 1: v = np.abs(A).min() ans -= 2 * v print(ans)
15
11
259
218
from numpy import sign n = int(eval(input())) a = list(map(int, input().split())) a_abs = list(map(abs, a)) a_abs.sort() plmi = 1 for i in a: plmi *= sign(i) if plmi == -1: ans = sum(a_abs[1:]) - a_abs[0] elif plmi == 1 or plmi == 0: ans = sum(a_abs) print(ans)
import numpy as np N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) neg = np.count_nonzero(A[A < 0]) ans = np.abs(A).sum() if neg % 2 == 1: v = np.abs(A).min() ans -= 2 * v print(ans)
false
26.666667
[ "-from numpy import sign", "+import numpy as np", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-a_abs = list(map(abs, a))", "-a_abs.sort()", "-plmi = 1", "-for i in a:", "- plmi *= sign(i)", "-if plmi == -1:", "- ans = sum(a_abs[1:]) - a_abs[0]", "-elif plmi == 1 or plmi == 0:", "- ans = sum(a_abs)", "+N = int(eval(input()))", "+A = np.array(input().split(), dtype=np.int64)", "+neg = np.count_nonzero(A[A < 0])", "+ans = np.abs(A).sum()", "+if neg % 2 == 1:", "+ v = np.abs(A).min()", "+ ans -= 2 * v" ]
false
0.230212
0.225964
1.018796
[ "s706324376", "s273550867" ]
u757117214
p02659
python
s074537622
s031003197
91
21
71,280
9,172
Accepted
Accepted
76.92
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))
6
4
101
82
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
33.333333
[ "-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.100167
0.091921
1.089712
[ "s074537622", "s031003197" ]
u563952871
p02676
python
s178615136
s516035144
28
25
9,160
9,152
Accepted
Accepted
10.71
K = int(eval(input())) S = eval(input()) if len(S) > K: print((S[:K] + '...')) else: print(S)
K = int(eval(input())) S = eval(input()) print((S[:K] + '...' if len(S) > K else S))
8
4
94
75
K = int(eval(input())) S = eval(input()) if len(S) > K: print((S[:K] + "...")) else: print(S)
K = int(eval(input())) S = eval(input()) print((S[:K] + "..." if len(S) > K else S))
false
50
[ "-if len(S) > K:", "- print((S[:K] + \"...\"))", "-else:", "- print(S)", "+print((S[:K] + \"...\" if len(S) > K else S))" ]
false
0.035425
0.037206
0.952121
[ "s178615136", "s516035144" ]
u074220993
p03426
python
s017489714
s787063192
921
659
129,316
48,664
Accepted
Accepted
28.45
H, W, D = list(map(int, input().split())) Aindex = [0] * (H*W) for h in range(H): w = 0 for A in input().split(): Aindex[int(A)-1] = (h,w) w += 1 import numpy as np v, h = int(np.ceil(H*W/D)), D Mp = np.zeros((v, h)) #MpをMod D別に計算する予定 mp = lambda X, Y: abs(X[0]-Y[0]) + abs(X[1]-Y[1]) #魔力計算する関数 for x in range(D,H*W): i, j = divmod(x, D) Mp[i,j] = mp(Aindex[x], Aindex[x-D]) #縦軸方向に累積和を取っておき、後のクエリにO(1)で対応 Mp = Mp.cumsum(axis=0) #クエリ処理 Q = int(eval(input())) Query = [(int(x) for x in input().split()) for _ in range(Q)] for l, r in Query: ans = Mp[divmod(r-1, D)] - Mp[divmod(l-1,D)] print((int(ans)))
H, W, D = list(map(int, input().split())) Aindex = [0] * (H*W) for h in range(H): w = 0 for A in input().split(): Aindex[int(A)-1] = (h,w) w += 1 import numpy as np v, h = int(np.ceil(H*W/D)), D Mp = np.zeros((v, h), dtype='int64') #MpをMod D別に計算する予定 mp = lambda X, Y: abs(X[0]-Y[0]) + abs(X[1]-Y[1]) #魔力計算する関数 for x in range(D,H*W): i, j = divmod(x, D) Mp[i,j] = mp(Aindex[x], Aindex[x-D]) #縦軸方向に累積和を取っておき、後のクエリにO(1)で対応 Mp = Mp.cumsum(axis=0) #クエリ処理 Q = int(eval(input())) Query = [tuple(map(int, input().split())) for _ in range(Q)] for l,r in Query: ans = Mp[divmod(r-1, D)] - Mp[divmod(l-1, D)] print(ans)
24
24
653
662
H, W, D = list(map(int, input().split())) Aindex = [0] * (H * W) for h in range(H): w = 0 for A in input().split(): Aindex[int(A) - 1] = (h, w) w += 1 import numpy as np v, h = int(np.ceil(H * W / D)), D Mp = np.zeros((v, h)) # MpをMod D別に計算する予定 mp = lambda X, Y: abs(X[0] - Y[0]) + abs(X[1] - Y[1]) # 魔力計算する関数 for x in range(D, H * W): i, j = divmod(x, D) Mp[i, j] = mp(Aindex[x], Aindex[x - D]) # 縦軸方向に累積和を取っておき、後のクエリにO(1)で対応 Mp = Mp.cumsum(axis=0) # クエリ処理 Q = int(eval(input())) Query = [(int(x) for x in input().split()) for _ in range(Q)] for l, r in Query: ans = Mp[divmod(r - 1, D)] - Mp[divmod(l - 1, D)] print((int(ans)))
H, W, D = list(map(int, input().split())) Aindex = [0] * (H * W) for h in range(H): w = 0 for A in input().split(): Aindex[int(A) - 1] = (h, w) w += 1 import numpy as np v, h = int(np.ceil(H * W / D)), D Mp = np.zeros((v, h), dtype="int64") # MpをMod D別に計算する予定 mp = lambda X, Y: abs(X[0] - Y[0]) + abs(X[1] - Y[1]) # 魔力計算する関数 for x in range(D, H * W): i, j = divmod(x, D) Mp[i, j] = mp(Aindex[x], Aindex[x - D]) # 縦軸方向に累積和を取っておき、後のクエリにO(1)で対応 Mp = Mp.cumsum(axis=0) # クエリ処理 Q = int(eval(input())) Query = [tuple(map(int, input().split())) for _ in range(Q)] for l, r in Query: ans = Mp[divmod(r - 1, D)] - Mp[divmod(l - 1, D)] print(ans)
false
0
[ "-Mp = np.zeros((v, h)) # MpをMod D別に計算する予定", "+Mp = np.zeros((v, h), dtype=\"int64\") # MpをMod D別に計算する予定", "-Query = [(int(x) for x in input().split()) for _ in range(Q)]", "+Query = [tuple(map(int, input().split())) for _ in range(Q)]", "- print((int(ans)))", "+ print(ans)" ]
false
0.332639
0.315465
1.05444
[ "s017489714", "s787063192" ]
u325282913
p03087
python
s167189755
s447469215
422
368
10,300
52,952
Accepted
Accepted
12.8
N, Q = list(map(int, input().split())) S = eval(input()) cnt_array = [0] * (N+1) ans = [0] * Q for i in range(N): if i != N-1 and S[i] == 'A' and S[i+1] == 'C': cnt_array[i+1] = 1 + cnt_array[i] else: cnt_array[i+1] = cnt_array[i] for i in range(Q): l, r = list(map(int, input().split())) ans[i] = cnt_array[r-1] - cnt_array[l-1] for i in ans: print(i)
import sys input = sys.stdin.readline N, Q = list(map(int,input().split())) S = eval(input()) S_array = [0] * N for i in range(N): S_array[i] = S_array[i-1] if S[i-1] == 'A' and S[i] == 'C': S_array[i] += 1 for _ in range(Q): l, r = list(map(int,input().split())) print((S_array[r-1]-S_array[l-1]))
14
12
383
313
N, Q = list(map(int, input().split())) S = eval(input()) cnt_array = [0] * (N + 1) ans = [0] * Q for i in range(N): if i != N - 1 and S[i] == "A" and S[i + 1] == "C": cnt_array[i + 1] = 1 + cnt_array[i] else: cnt_array[i + 1] = cnt_array[i] for i in range(Q): l, r = list(map(int, input().split())) ans[i] = cnt_array[r - 1] - cnt_array[l - 1] for i in ans: print(i)
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) S = eval(input()) S_array = [0] * N for i in range(N): S_array[i] = S_array[i - 1] if S[i - 1] == "A" and S[i] == "C": S_array[i] += 1 for _ in range(Q): l, r = list(map(int, input().split())) print((S_array[r - 1] - S_array[l - 1]))
false
14.285714
[ "+import sys", "+", "+input = sys.stdin.readline", "-cnt_array = [0] * (N + 1)", "-ans = [0] * Q", "+S_array = [0] * N", "- if i != N - 1 and S[i] == \"A\" and S[i + 1] == \"C\":", "- cnt_array[i + 1] = 1 + cnt_array[i]", "- else:", "- cnt_array[i + 1] = cnt_array[i]", "-for i in range(Q):", "+ S_array[i] = S_array[i - 1]", "+ if S[i - 1] == \"A\" and S[i] == \"C\":", "+ S_array[i] += 1", "+for _ in range(Q):", "- ans[i] = cnt_array[r - 1] - cnt_array[l - 1]", "-for i in ans:", "- print(i)", "+ print((S_array[r - 1] - S_array[l - 1]))" ]
false
0.038522
0.070213
0.548646
[ "s167189755", "s447469215" ]
u201234972
p03846
python
s753566104
s349959965
80
68
14,820
14,820
Accepted
Accepted
15
from collections import Counter N = int( eval(input())) A = Counter(list( map( int, input().split()))) Q = 10**9 + 7 ans = 1 for i in range(N-1, 0, -2): if A[i] == 2: ans *= 2 ans %= Q else: ans = 0 break if N%2 == 1: if A[0] != 1: ans = 0 print(ans)
from collections import Counter N = int( eval(input())) A = Counter(list( map( int, input().split()))) Q = 10**9 + 7 ans = 1 for i in range(N-1, 0, -2): if A[i] == 1: ans = 0 break if N%2 == 1: if A[0] != 1: ans = 0 print((ans*pow(2,N//2,Q)))
16
13
312
278
from collections import Counter N = int(eval(input())) A = Counter(list(map(int, input().split()))) Q = 10**9 + 7 ans = 1 for i in range(N - 1, 0, -2): if A[i] == 2: ans *= 2 ans %= Q else: ans = 0 break if N % 2 == 1: if A[0] != 1: ans = 0 print(ans)
from collections import Counter N = int(eval(input())) A = Counter(list(map(int, input().split()))) Q = 10**9 + 7 ans = 1 for i in range(N - 1, 0, -2): if A[i] == 1: ans = 0 break if N % 2 == 1: if A[0] != 1: ans = 0 print((ans * pow(2, N // 2, Q)))
false
18.75
[ "- if A[i] == 2:", "- ans *= 2", "- ans %= Q", "- else:", "+ if A[i] == 1:", "-print(ans)", "+print((ans * pow(2, N // 2, Q)))" ]
false
0.054801
0.052228
1.049264
[ "s753566104", "s349959965" ]
u334712262
p02642
python
s944846353
s877173304
1,902
661
124,520
219,824
Accepted
Accepted
65.25
# -*- coding: utf-8 -*- 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 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 eratosthenes(n): p = [] t = [True] * n for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2*i, n, i): t[j] = False for j in range(i+1, n): if t[j]: p.append(j) return p, t P, T = eratosthenes(int(math.sqrt(10**6))+1) def e(n): c = [] for p in P: while n % p == 0: # c[p] += 1 c.append(p) n //= p if n == 1: break if n != 1: # c[n] += 1 c.append(n) return c @mt def slv(N, A): ans = 0 A.sort() ac = Counter(A) for i in range(N): # print(i) a = A[i] if ac[a] >= 2: continue c = e(a) for j in range(len(c)): f = False for i in combinations(c, r=j): m = reduce(mul, i, 1) # error_print(a, m) if ac[m] >= 1: # error_print('b', a) break else: f = True if not f: break else: ans += 1 return ans def main(): N = read_int() A = read_int_n() print(slv(N, A)) # from random import randint # N = 2* (10**5) # A = [randint(1, 10**6) for _ in range(N)] # print(slv(N, A)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- 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 @mt def slv(N, A): from collections import Counter c = Counter() ma = max(A) for a in A: for i in range(ma//a + 1): c[a*i] += 1 ans = 0 for a in A: if c[a] == 1: ans += 1 return ans def main(): N = read_int() A = read_int_n() print(slv(N, A)) # from random import randint # N = 2* (10**5) # A = [randint(1, 10**6) for _ in range(N)] # print(slv(N, A)) if __name__ == '__main__': main()
137
81
2,704
1,393
# -*- coding: utf-8 -*- 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 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 eratosthenes(n): p = [] t = [True] * n for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2 * i, n, i): t[j] = False for j in range(i + 1, n): if t[j]: p.append(j) return p, t P, T = eratosthenes(int(math.sqrt(10**6)) + 1) def e(n): c = [] for p in P: while n % p == 0: # c[p] += 1 c.append(p) n //= p if n == 1: break if n != 1: # c[n] += 1 c.append(n) return c @mt def slv(N, A): ans = 0 A.sort() ac = Counter(A) for i in range(N): # print(i) a = A[i] if ac[a] >= 2: continue c = e(a) for j in range(len(c)): f = False for i in combinations(c, r=j): m = reduce(mul, i, 1) # error_print(a, m) if ac[m] >= 1: # error_print('b', a) break else: f = True if not f: break else: ans += 1 return ans def main(): N = read_int() A = read_int_n() print(slv(N, A)) # from random import randint # N = 2* (10**5) # A = [randint(1, 10**6) for _ in range(N)] # print(slv(N, A)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- 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 @mt def slv(N, A): from collections import Counter c = Counter() ma = max(A) for a in A: for i in range(ma // a + 1): c[a * i] += 1 ans = 0 for a in A: if c[a] == 1: ans += 1 return ans def main(): N = read_int() A = read_int_n() print(slv(N, A)) # from random import randint # N = 2* (10**5) # A = [randint(1, 10**6) for _ in range(N)] # print(slv(N, A)) if __name__ == "__main__": main()
false
40.875912
[ "-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", "-def eratosthenes(n):", "- p = []", "- t = [True] * n", "- for i in range(2, int(math.ceil(math.sqrt(n)))):", "- if t[i]:", "- p.append(i)", "- for j in range(2 * i, n, i):", "- t[j] = False", "- for j in range(i + 1, n):", "- if t[j]:", "- p.append(j)", "- return p, t", "-", "-", "-P, T = eratosthenes(int(math.sqrt(10**6)) + 1)", "-", "-", "-def e(n):", "- c = []", "- for p in P:", "- while n % p == 0:", "- # c[p] += 1", "- c.append(p)", "- n //= p", "- if n == 1:", "- break", "- if n != 1:", "- # c[n] += 1", "- c.append(n)", "- return c", "-", "-", "+ from collections import Counter", "+", "+ c = Counter()", "+ ma = max(A)", "+ for a in A:", "+ for i in range(ma // a + 1):", "+ c[a * i] += 1", "- A.sort()", "- ac = Counter(A)", "- for i in range(N):", "- # print(i)", "- a = A[i]", "- if ac[a] >= 2:", "- continue", "- c = e(a)", "- for j in range(len(c)):", "- f = False", "- for i in combinations(c, r=j):", "- m = reduce(mul, i, 1)", "- # error_print(a, m)", "- if ac[m] >= 1:", "- # error_print('b', a)", "- break", "- else:", "- f = True", "- if not f:", "- break", "- else:", "+ for a in A:", "+ if c[a] == 1:" ]
false
0.039727
0.006808
5.835463
[ "s944846353", "s877173304" ]
u811512248
p03045
python
s872205160
s616518464
1,256
460
143,464
7,156
Accepted
Accepted
63.38
import sys sys.setrecursionlimit(10**8) N, M = list(map(int, input().split())) num_edges = M edges = [list(map(int, input().split())) for i in range(num_edges)] adj = [[] for i in range(N+1)] for ed in edges: adj[ed[0]] += [[ed[1], ed[2]]] adj[ed[1]] += [[ed[0], ed[2]]] col_list = [-1 for i in range(N+1)] def recfun(v, col): col_list[v] = col #色を更新 for ed in adj[v]: #隣接する頂点をみる if col_list[ed[0]] == -1: #更新していない場合 recfun(ed[0], col) #同じ色でその先をみる count = 0 for i in range(1, N+1): if col_list[i] == -1: count +=1 recfun(i, count) print(count)
class UnionFind(): def __init__(self,size): self.table=[-1]*size def root(self,x): while self.table[x]>=0: x=self.table[x] return x def unite(self,x,y): s1=self.root(x) s2=self.root(y) if s1!=s2: if self.table[s1]>self.table[s2]: s1,s2=s2,s1 self.table[s1]+=self.table[s2] self.table[s2]=s1 return def same(self,x,y): return self.root(x)==self.root(y) def size(self,x): return -self.table[self.root(x)] ##### N, M = list(map(int, input().split())) uf = UnionFind(N+1) for i in range(M): ui, vi, wi = list(map(int, input().split())) uf.unite(ui, vi) print((sum([t < 0 for t in uf.table[1:]])))
22
28
615
774
import sys sys.setrecursionlimit(10**8) N, M = list(map(int, input().split())) num_edges = M edges = [list(map(int, input().split())) for i in range(num_edges)] adj = [[] for i in range(N + 1)] for ed in edges: adj[ed[0]] += [[ed[1], ed[2]]] adj[ed[1]] += [[ed[0], ed[2]]] col_list = [-1 for i in range(N + 1)] def recfun(v, col): col_list[v] = col # 色を更新 for ed in adj[v]: # 隣接する頂点をみる if col_list[ed[0]] == -1: # 更新していない場合 recfun(ed[0], col) # 同じ色でその先をみる count = 0 for i in range(1, N + 1): if col_list[i] == -1: count += 1 recfun(i, count) print(count)
class UnionFind: def __init__(self, size): self.table = [-1] * size def root(self, x): while self.table[x] >= 0: x = self.table[x] return x def unite(self, x, y): s1 = self.root(x) s2 = self.root(y) if s1 != s2: if self.table[s1] > self.table[s2]: s1, s2 = s2, s1 self.table[s1] += self.table[s2] self.table[s2] = s1 return def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.table[self.root(x)] ##### N, M = list(map(int, input().split())) uf = UnionFind(N + 1) for i in range(M): ui, vi, wi = list(map(int, input().split())) uf.unite(ui, vi) print((sum([t < 0 for t in uf.table[1:]])))
false
21.428571
[ "-import sys", "+class UnionFind:", "+ def __init__(self, size):", "+ self.table = [-1] * size", "-sys.setrecursionlimit(10**8)", "-N, M = list(map(int, input().split()))", "-num_edges = M", "-edges = [list(map(int, input().split())) for i in range(num_edges)]", "-adj = [[] for i in range(N + 1)]", "-for ed in edges:", "- adj[ed[0]] += [[ed[1], ed[2]]]", "- adj[ed[1]] += [[ed[0], ed[2]]]", "-col_list = [-1 for i in range(N + 1)]", "+ def root(self, x):", "+ while self.table[x] >= 0:", "+ x = self.table[x]", "+ return x", "+", "+ def unite(self, x, y):", "+ s1 = self.root(x)", "+ s2 = self.root(y)", "+ if s1 != s2:", "+ if self.table[s1] > self.table[s2]:", "+ s1, s2 = s2, s1", "+ self.table[s1] += self.table[s2]", "+ self.table[s2] = s1", "+ return", "+", "+ def same(self, x, y):", "+ return self.root(x) == self.root(y)", "+", "+ def size(self, x):", "+ return -self.table[self.root(x)]", "-def recfun(v, col):", "- col_list[v] = col # 色を更新", "- for ed in adj[v]: # 隣接する頂点をみる", "- if col_list[ed[0]] == -1: # 更新していない場合", "- recfun(ed[0], col) # 同じ色でその先をみる", "-", "-", "-count = 0", "-for i in range(1, N + 1):", "- if col_list[i] == -1:", "- count += 1", "- recfun(i, count)", "-print(count)", "+#####", "+N, M = list(map(int, input().split()))", "+uf = UnionFind(N + 1)", "+for i in range(M):", "+ ui, vi, wi = list(map(int, input().split()))", "+ uf.unite(ui, vi)", "+print((sum([t < 0 for t in uf.table[1:]])))" ]
false
0.073553
0.081413
0.903453
[ "s872205160", "s616518464" ]
u799691369
p02761
python
s870343590
s938260378
21
18
3,444
3,064
Accepted
Accepted
14.29
N, M = list(map(int, input().split())) A = [float('inf') for _ in range(N)] for i in range(M): s, c = list(map(int, input().split())) s -= 1 if A[s] != float('inf') and A[s] != c: print((-1)) exit() A[s] = min(A[s], c) #A[s] = c for i in range(1, N): if A[i] == float('inf'): A[i] = '0' A[i] = str(A[i]) #print(A) if A[0] == float('inf'): if len(A) == 1: A[0] = '0' else: A[0] = '1' else: A[0] = str(A[0]) ans = int(''.join(A)) if len(str(ans)) == N: print(ans) else: print((-1))
N, M = list(map(int, input().split())) SC = [[] for _ in range(N)] error = False for _ in range(M): s, c = list(map(int, input().split())) s -= 1 if SC[s] and SC[s] != c: error = True break else: SC[s] = c if error: print((-1)) elif SC[0] == 0 and len(SC) > 1: print((-1)) else: if not SC[0] and len(SC) == 1: SC[0] = 0 if not SC[0] and len(SC) > 1: SC[0] = 1 if len(SC) > 1 and not SC[1]: SC[1] = 0 if len(SC) > 2 and not SC[2]: SC[2] = 0 print((''.join(map(str,SC))))
31
27
571
580
N, M = list(map(int, input().split())) A = [float("inf") for _ in range(N)] for i in range(M): s, c = list(map(int, input().split())) s -= 1 if A[s] != float("inf") and A[s] != c: print((-1)) exit() A[s] = min(A[s], c) # A[s] = c for i in range(1, N): if A[i] == float("inf"): A[i] = "0" A[i] = str(A[i]) # print(A) if A[0] == float("inf"): if len(A) == 1: A[0] = "0" else: A[0] = "1" else: A[0] = str(A[0]) ans = int("".join(A)) if len(str(ans)) == N: print(ans) else: print((-1))
N, M = list(map(int, input().split())) SC = [[] for _ in range(N)] error = False for _ in range(M): s, c = list(map(int, input().split())) s -= 1 if SC[s] and SC[s] != c: error = True break else: SC[s] = c if error: print((-1)) elif SC[0] == 0 and len(SC) > 1: print((-1)) else: if not SC[0] and len(SC) == 1: SC[0] = 0 if not SC[0] and len(SC) > 1: SC[0] = 1 if len(SC) > 1 and not SC[1]: SC[1] = 0 if len(SC) > 2 and not SC[2]: SC[2] = 0 print(("".join(map(str, SC))))
false
12.903226
[ "-A = [float(\"inf\") for _ in range(N)]", "-for i in range(M):", "+SC = [[] for _ in range(N)]", "+error = False", "+for _ in range(M):", "- if A[s] != float(\"inf\") and A[s] != c:", "- print((-1))", "- exit()", "- A[s] = min(A[s], c)", "- # A[s] = c", "-for i in range(1, N):", "- if A[i] == float(\"inf\"):", "- A[i] = \"0\"", "- A[i] = str(A[i])", "-# print(A)", "-if A[0] == float(\"inf\"):", "- if len(A) == 1:", "- A[0] = \"0\"", "+ if SC[s] and SC[s] != c:", "+ error = True", "+ break", "- A[0] = \"1\"", "+ SC[s] = c", "+if error:", "+ print((-1))", "+elif SC[0] == 0 and len(SC) > 1:", "+ print((-1))", "- A[0] = str(A[0])", "-ans = int(\"\".join(A))", "-if len(str(ans)) == N:", "- print(ans)", "-else:", "- print((-1))", "+ if not SC[0] and len(SC) == 1:", "+ SC[0] = 0", "+ if not SC[0] and len(SC) > 1:", "+ SC[0] = 1", "+ if len(SC) > 1 and not SC[1]:", "+ SC[1] = 0", "+ if len(SC) > 2 and not SC[2]:", "+ SC[2] = 0", "+ print((\"\".join(map(str, SC))))" ]
false
0.113196
0.043958
2.575065
[ "s870343590", "s938260378" ]
u037430802
p03329
python
s280930574
s705126476
844
414
3,188
3,188
Accepted
Accepted
50.95
import bisect N = int(eval(input())) ans = N sixs = [1] i = 6 while i <= N: sixs.append(i) i *= 6 nines = [1] i = 9 while i <= N: nines.append(i) i *= 9 for i in range(N+1): #iの分だけ6**xで構成 cnt = 0 a = i b = N-i while a > 0: idx = bisect.bisect_right(sixs, a) cnt += a // sixs[idx-1] a -= (a // sixs[idx-1]) * sixs[idx-1] while b > 0: idx = bisect.bisect_right(nines, b) cnt += b // nines[idx-1] b -= (b // nines[idx-1]) * nines[idx-1] ans = min(ans, cnt) print(ans)
from bisect import bisect_right def main(): N = int(eval(input())) sixs = [1] i = 6 while i <= N: sixs.append(i) i *= 6 nines = [1] i = 9 while i <= N: nines.append(i) i *= 9 """ i円分を6**xxx で、 残りを9**yyyと1*zzzで構成する。これらを全通り試す """ ans = N for i in range(N+1): cnt = 0 sum_six = i sum_nine = N-i while sum_six > 0: idx = bisect_right(sixs, sum_six) - 1 tmp = sum_six // sixs[idx] cnt += tmp sum_six -= tmp * sixs[idx] while sum_nine > 0: idx = bisect_right(nines, sum_nine) - 1 tmp = sum_nine // nines[idx] cnt += tmp sum_nine -= tmp * nines[idx] ans = min(ans, cnt) print(ans) if __name__ == "__main__": main()
33
44
587
885
import bisect N = int(eval(input())) ans = N sixs = [1] i = 6 while i <= N: sixs.append(i) i *= 6 nines = [1] i = 9 while i <= N: nines.append(i) i *= 9 for i in range(N + 1): # iの分だけ6**xで構成 cnt = 0 a = i b = N - i while a > 0: idx = bisect.bisect_right(sixs, a) cnt += a // sixs[idx - 1] a -= (a // sixs[idx - 1]) * sixs[idx - 1] while b > 0: idx = bisect.bisect_right(nines, b) cnt += b // nines[idx - 1] b -= (b // nines[idx - 1]) * nines[idx - 1] ans = min(ans, cnt) print(ans)
from bisect import bisect_right def main(): N = int(eval(input())) sixs = [1] i = 6 while i <= N: sixs.append(i) i *= 6 nines = [1] i = 9 while i <= N: nines.append(i) i *= 9 """ i円分を6**xxx で、 残りを9**yyyと1*zzzで構成する。これらを全通り試す """ ans = N for i in range(N + 1): cnt = 0 sum_six = i sum_nine = N - i while sum_six > 0: idx = bisect_right(sixs, sum_six) - 1 tmp = sum_six // sixs[idx] cnt += tmp sum_six -= tmp * sixs[idx] while sum_nine > 0: idx = bisect_right(nines, sum_nine) - 1 tmp = sum_nine // nines[idx] cnt += tmp sum_nine -= tmp * nines[idx] ans = min(ans, cnt) print(ans) if __name__ == "__main__": main()
false
25
[ "-import bisect", "+from bisect import bisect_right", "-N = int(eval(input()))", "-ans = N", "-sixs = [1]", "-i = 6", "-while i <= N:", "- sixs.append(i)", "- i *= 6", "-nines = [1]", "-i = 9", "-while i <= N:", "- nines.append(i)", "- i *= 9", "-for i in range(N + 1):", "- # iの分だけ6**xで構成", "- cnt = 0", "- a = i", "- b = N - i", "- while a > 0:", "- idx = bisect.bisect_right(sixs, a)", "- cnt += a // sixs[idx - 1]", "- a -= (a // sixs[idx - 1]) * sixs[idx - 1]", "- while b > 0:", "- idx = bisect.bisect_right(nines, b)", "- cnt += b // nines[idx - 1]", "- b -= (b // nines[idx - 1]) * nines[idx - 1]", "- ans = min(ans, cnt)", "-print(ans)", "+", "+def main():", "+ N = int(eval(input()))", "+ sixs = [1]", "+ i = 6", "+ while i <= N:", "+ sixs.append(i)", "+ i *= 6", "+ nines = [1]", "+ i = 9", "+ while i <= N:", "+ nines.append(i)", "+ i *= 9", "+ \"\"\"", "+ i円分を6**xxx で、 残りを9**yyyと1*zzzで構成する。これらを全通り試す", "+ \"\"\"", "+ ans = N", "+ for i in range(N + 1):", "+ cnt = 0", "+ sum_six = i", "+ sum_nine = N - i", "+ while sum_six > 0:", "+ idx = bisect_right(sixs, sum_six) - 1", "+ tmp = sum_six // sixs[idx]", "+ cnt += tmp", "+ sum_six -= tmp * sixs[idx]", "+ while sum_nine > 0:", "+ idx = bisect_right(nines, sum_nine) - 1", "+ tmp = sum_nine // nines[idx]", "+ cnt += tmp", "+ sum_nine -= tmp * nines[idx]", "+ ans = min(ans, cnt)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.302807
0.071665
4.225293
[ "s280930574", "s705126476" ]
u077291787
p03073
python
s276279324
s062335089
44
39
3,188
3,188
Accepted
Accepted
11.36
# ABC124C - Coloring Colorfully import sys input = sys.stdin.readline s = input().rstrip() a = s[0] ans = 0 for i, j in enumerate(s): if i % 2 == 0: if j != a: ans += 1 else: if j == a: ans += 1 print(ans)
# ABC124C - Coloring Colorfully def main(): s = eval(input()) a, ans = s[0], 0 for i, j in enumerate(s): if (i % 2 and j == a) or (not i % 2 and j != a): ans += 1 print(ans) if __name__ == "__main__": main()
15
12
268
254
# ABC124C - Coloring Colorfully import sys input = sys.stdin.readline s = input().rstrip() a = s[0] ans = 0 for i, j in enumerate(s): if i % 2 == 0: if j != a: ans += 1 else: if j == a: ans += 1 print(ans)
# ABC124C - Coloring Colorfully def main(): s = eval(input()) a, ans = s[0], 0 for i, j in enumerate(s): if (i % 2 and j == a) or (not i % 2 and j != a): ans += 1 print(ans) if __name__ == "__main__": main()
false
20
[ "-import sys", "+def main():", "+ s = eval(input())", "+ a, ans = s[0], 0", "+ for i, j in enumerate(s):", "+ if (i % 2 and j == a) or (not i % 2 and j != a):", "+ ans += 1", "+ print(ans)", "-input = sys.stdin.readline", "-s = input().rstrip()", "-a = s[0]", "-ans = 0", "-for i, j in enumerate(s):", "- if i % 2 == 0:", "- if j != a:", "- ans += 1", "- else:", "- if j == a:", "- ans += 1", "-print(ans)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047929
0.047854
1.001553
[ "s276279324", "s062335089" ]
u815878613
p02630
python
s520475925
s040806945
316
287
40,428
40,280
Accepted
Accepted
9.18
from collections import Counter import sys readline = sys.stdin.buffer.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) BC = [list(map(int, readline().split())) for _ in range(Q)] d = Counter(A) sub_s = sum(A) for b, c in BC: sub_s += d[b] * (c - b) d[c] += d[b] d[b] = 0 print(sub_s)
from collections import Counter import sys readline = sys.stdin.buffer.readline N = int(readline()) A = tuple(map(int, readline().split())) Q = int(readline()) BC = [list(map(int, readline().split())) for _ in range(Q)] d = Counter(A) sub_s = sum(A) for b, c in BC: sub_s += d[b] * (c - b) d[c] += d[b] d[b] = 0 print(sub_s)
22
22
369
370
from collections import Counter import sys readline = sys.stdin.buffer.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) BC = [list(map(int, readline().split())) for _ in range(Q)] d = Counter(A) sub_s = sum(A) for b, c in BC: sub_s += d[b] * (c - b) d[c] += d[b] d[b] = 0 print(sub_s)
from collections import Counter import sys readline = sys.stdin.buffer.readline N = int(readline()) A = tuple(map(int, readline().split())) Q = int(readline()) BC = [list(map(int, readline().split())) for _ in range(Q)] d = Counter(A) sub_s = sum(A) for b, c in BC: sub_s += d[b] * (c - b) d[c] += d[b] d[b] = 0 print(sub_s)
false
0
[ "-A = list(map(int, readline().split()))", "+A = tuple(map(int, readline().split()))" ]
false
0.044748
0.049344
0.906844
[ "s520475925", "s040806945" ]
u870518235
p03457
python
s351154331
s958181747
528
320
59,028
3,060
Accepted
Accepted
39.39
N = int(eval(input())) D = [input().split() for i in range(N)] DD = [] for i in range(N): DD.append([int(D[i][0]),int(D[i][1]),int(D[i][2])]) diff = [[0,0,0],[DD[0][0]-0,DD[0][1]-0,DD[0][2]-0]] for i in range(N-1): diff.append([DD[i+1][0]-DD[i][0],DD[i+1][1]-DD[i][1],DD[i+1][2]-DD[i][2]]) def judge(t, x, y): if t < (abs(x) + abs(y)): return 1 else: if (t % 2) == ((abs(x) + abs(y)) % 2): return 0 else: return 1 count = 0 for i in range(N+1): count += judge(diff[i][0], diff[i][1], diff[i][2]) if count >= 1: print("No") else: print("Yes")
N = int(eval(input())) for _ in range(N): t, x, y = list(map(int, input().split())) if x + y > t or (t + x + y)%2 != 0: print("No") quit() print("Yes")
30
7
647
169
N = int(eval(input())) D = [input().split() for i in range(N)] DD = [] for i in range(N): DD.append([int(D[i][0]), int(D[i][1]), int(D[i][2])]) diff = [[0, 0, 0], [DD[0][0] - 0, DD[0][1] - 0, DD[0][2] - 0]] for i in range(N - 1): diff.append( [DD[i + 1][0] - DD[i][0], DD[i + 1][1] - DD[i][1], DD[i + 1][2] - DD[i][2]] ) def judge(t, x, y): if t < (abs(x) + abs(y)): return 1 else: if (t % 2) == ((abs(x) + abs(y)) % 2): return 0 else: return 1 count = 0 for i in range(N + 1): count += judge(diff[i][0], diff[i][1], diff[i][2]) if count >= 1: print("No") else: print("Yes")
N = int(eval(input())) for _ in range(N): t, x, y = list(map(int, input().split())) if x + y > t or (t + x + y) % 2 != 0: print("No") quit() print("Yes")
false
76.666667
[ "-D = [input().split() for i in range(N)]", "-DD = []", "-for i in range(N):", "- DD.append([int(D[i][0]), int(D[i][1]), int(D[i][2])])", "-diff = [[0, 0, 0], [DD[0][0] - 0, DD[0][1] - 0, DD[0][2] - 0]]", "-for i in range(N - 1):", "- diff.append(", "- [DD[i + 1][0] - DD[i][0], DD[i + 1][1] - DD[i][1], DD[i + 1][2] - DD[i][2]]", "- )", "-", "-", "-def judge(t, x, y):", "- if t < (abs(x) + abs(y)):", "- return 1", "- else:", "- if (t % 2) == ((abs(x) + abs(y)) % 2):", "- return 0", "- else:", "- return 1", "-", "-", "-count = 0", "-for i in range(N + 1):", "- count += judge(diff[i][0], diff[i][1], diff[i][2])", "-if count >= 1:", "- print(\"No\")", "-else:", "- print(\"Yes\")", "+for _ in range(N):", "+ t, x, y = list(map(int, input().split()))", "+ if x + y > t or (t + x + y) % 2 != 0:", "+ print(\"No\")", "+ quit()", "+print(\"Yes\")" ]
false
0.04118
0.054262
0.758913
[ "s351154331", "s958181747" ]
u158290747
p02586
python
s796950757
s035620367
1,310
1,204
156,636
156,244
Accepted
Accepted
8.09
R,C,K=list(map(int,input().split())) l=[[0] * C for i in range(R)] for i in range(K): a,b,c=list(map(int,input().split())) a-=1 b-=1 l[a][b]=c dp=[0]*C for i in range(R): ndp=[0]*C kdp=[0]*4 kdp[0]=dp[0] kdp[1]=l[i][0]+dp[0] ndp[0]=kdp[1] for j in range(1,C): kdp[0]=max(kdp[0],dp[j]) for k in range(2,-1,-1): kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j]) ndp[j]=max(kdp) dp=ndp print((dp[C-1]))
R,C,K=list(map(int,input().split())) l=[[0] * C for i in range(R)] for i in range(K): a,b,c=list(map(int,input().split())) a-=1 b-=1 l[a][b]=c dp=[0]*C for i in range(R): ndp=[0]*C kdp=[0]*4 for j in range(0,C): kdp[0]=max(kdp[0],dp[j]) for k in range(2,-1,-1): kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j]) ndp[j]=max(kdp) dp=ndp print((dp[C-1]))
21
18
433
376
R, C, K = list(map(int, input().split())) l = [[0] * C for i in range(R)] for i in range(K): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 l[a][b] = c dp = [0] * C for i in range(R): ndp = [0] * C kdp = [0] * 4 kdp[0] = dp[0] kdp[1] = l[i][0] + dp[0] ndp[0] = kdp[1] for j in range(1, C): kdp[0] = max(kdp[0], dp[j]) for k in range(2, -1, -1): kdp[k + 1] = max(kdp[k + 1], kdp[k] + l[i][j]) ndp[j] = max(kdp) dp = ndp print((dp[C - 1]))
R, C, K = list(map(int, input().split())) l = [[0] * C for i in range(R)] for i in range(K): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 l[a][b] = c dp = [0] * C for i in range(R): ndp = [0] * C kdp = [0] * 4 for j in range(0, C): kdp[0] = max(kdp[0], dp[j]) for k in range(2, -1, -1): kdp[k + 1] = max(kdp[k + 1], kdp[k] + l[i][j]) ndp[j] = max(kdp) dp = ndp print((dp[C - 1]))
false
14.285714
[ "- kdp[0] = dp[0]", "- kdp[1] = l[i][0] + dp[0]", "- ndp[0] = kdp[1]", "- for j in range(1, C):", "+ for j in range(0, C):" ]
false
0.102505
0.043093
2.378677
[ "s796950757", "s035620367" ]
u368780724
p03182
python
s546494788
s717345561
1,408
1,249
108,372
107,348
Accepted
Accepted
11.29
import sys class Lazysegtree: #RAQ def __init__(self, A, intv, initialize = True, segf = min): #区間は 1-indexed で管理 self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf self.lazy = [0]*(2*self.N0) if initialize: self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N) for i in range(self.N0-1, 0, -1): self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) else: self.data = [intv]*(2*self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \ + self.lazy[idx] def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c+1): idx = k >> (c - j) ax = self.lazy[idx] if not ax: continue self.lazy[idx] = 0 self.data[2*idx] += ax self.data[2*idx+1] += ax self.lazy[2*idx] += ax self.lazy[2*idx+1] += ax def update(self, k, x): k = k + self.N0 self.data[k] = x self._ascend(k) def query(self, l, r): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) self._descend(Li) self._descend(Ri - 1) s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def add(self, l, r, x): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) while L < R : if R & 1: R -= 1 self.data[R] += x self.lazy[R] += x if L & 1: self.data[L] += x self.lazy[L] += x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri-1) N, M = list(map(int, input().split())) LA = [[] for _ in range(N)] for _ in range(M): l, r, a = list(map(int, sys.stdin.readline().split())) LA[r-1].append((l-1, a)) dp = Lazysegtree([0]*(N+1), -10**16, True, max) for i in range(N): res = 0 t = dp.data[1] for l, a in LA[i]: res += a dp.add(l, i, a) dp.add(i,i+1, res + t) print((dp.data[1]))
import sys class Lazysegtree: #RAQ def __init__(self, A, intv, initialize = True, segf = min): #区間は 1-indexed で管理 self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf self.lazy = [0]*(2*self.N0) if initialize: self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N) for i in range(self.N0-1, 0, -1): self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) else: self.data = [intv]*(2*self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \ + self.lazy[idx] def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c+1): idx = k >> (c - j) ax = self.lazy[idx] if not ax: continue self.lazy[idx] = 0 self.data[2*idx] += ax self.data[2*idx+1] += ax self.lazy[2*idx] += ax self.lazy[2*idx+1] += ax def update(self, k, x): k = k + self.N0 self.data[k] = x self._ascend(k) def query(self, l, r): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) self._descend(Li) self._descend(Ri - 1) s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def add(self, l, r, x): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) while L < R : if R & 1: R -= 1 self.data[R] += x self.lazy[R] += x if L & 1: self.data[L] += x self.lazy[L] += x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri-1) N, M = list(map(int, input().split())) LA = [[] for _ in range(N)] for _ in range(M): l, r, a = list(map(int, sys.stdin.readline().split())) LA[r-1].append((l-1, a)) dp = Lazysegtree([0]*(N+1), -10**16, True, max) for i in range(N): res = 0 t = dp.data[1] for l, a in LA[i]: res += a dp.add(l, i, a) dp.update(i, res + t) print((dp.data[1]))
102
103
2,812
2,813
import sys class Lazysegtree: # RAQ def __init__(self, A, intv, initialize=True, segf=min): # 区間は 1-indexed で管理 self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf self.lazy = [0] * (2 * self.N0) if initialize: self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1]) else: self.data = [intv] * (2 * self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = ( self.segf(self.data[2 * idx], self.data[2 * idx + 1]) + self.lazy[idx] ) def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c + 1): idx = k >> (c - j) ax = self.lazy[idx] if not ax: continue self.lazy[idx] = 0 self.data[2 * idx] += ax self.data[2 * idx + 1] += ax self.lazy[2 * idx] += ax self.lazy[2 * idx + 1] += ax def update(self, k, x): k = k + self.N0 self.data[k] = x self._ascend(k) def query(self, l, r): L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) self._descend(Li) self._descend(Ri - 1) s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def add(self, l, r, x): L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) while L < R: if R & 1: R -= 1 self.data[R] += x self.lazy[R] += x if L & 1: self.data[L] += x self.lazy[L] += x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri - 1) N, M = list(map(int, input().split())) LA = [[] for _ in range(N)] for _ in range(M): l, r, a = list(map(int, sys.stdin.readline().split())) LA[r - 1].append((l - 1, a)) dp = Lazysegtree([0] * (N + 1), -(10**16), True, max) for i in range(N): res = 0 t = dp.data[1] for l, a in LA[i]: res += a dp.add(l, i, a) dp.add(i, i + 1, res + t) print((dp.data[1]))
import sys class Lazysegtree: # RAQ def __init__(self, A, intv, initialize=True, segf=min): # 区間は 1-indexed で管理 self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf self.lazy = [0] * (2 * self.N0) if initialize: self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1]) else: self.data = [intv] * (2 * self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = ( self.segf(self.data[2 * idx], self.data[2 * idx + 1]) + self.lazy[idx] ) def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c + 1): idx = k >> (c - j) ax = self.lazy[idx] if not ax: continue self.lazy[idx] = 0 self.data[2 * idx] += ax self.data[2 * idx + 1] += ax self.lazy[2 * idx] += ax self.lazy[2 * idx + 1] += ax def update(self, k, x): k = k + self.N0 self.data[k] = x self._ascend(k) def query(self, l, r): L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) self._descend(Li) self._descend(Ri - 1) s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def add(self, l, r, x): L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) while L < R: if R & 1: R -= 1 self.data[R] += x self.lazy[R] += x if L & 1: self.data[L] += x self.lazy[L] += x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri - 1) N, M = list(map(int, input().split())) LA = [[] for _ in range(N)] for _ in range(M): l, r, a = list(map(int, sys.stdin.readline().split())) LA[r - 1].append((l - 1, a)) dp = Lazysegtree([0] * (N + 1), -(10**16), True, max) for i in range(N): res = 0 t = dp.data[1] for l, a in LA[i]: res += a dp.add(l, i, a) dp.update(i, res + t) print((dp.data[1]))
false
0.970874
[ "- dp.add(i, i + 1, res + t)", "+ dp.update(i, res + t)" ]
false
0.031705
0.033817
0.937561
[ "s546494788", "s717345561" ]
u648868410
p02579
python
s202786178
s546511660
1,909
474
24,404
109,736
Accepted
Accepted
75.17
# import numpy as np from collections import deque def solve(): #H, W, CH, CW, DH, DW, S): H,W=list(map(int,input().split())) CH,CW=list(map(int,input().split())) DH,DW=list(map(int,input().split())) S=[eval(input()) for _ in range(H)] # 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む S = ['##{}##'.format(row) for row in S] S.insert(0, '##{}##'.format('#' * W)) S.insert(0, '##{}##'.format('#' * W)) S.append('##{}##'.format('#' * W)) S.append('##{}##'.format('#' * W)) MAX_COST = 10 ** 9 Cost=[ [ MAX_COST for _ in range(W+4)] for _ in range(H+4)] # Cost = np.full((H,W),MAX_COST) # print(S) ans = -1 cost0 = deque() cost0.append((CH+1,CW+1,0)) Cost[CH+1][CW+1] = 0; # used = set() walk=[(1,0),(0,1),(-1,0),(0,-1)] warp = [ (i,j) for i in range(-2,3) for j in range(-2,3) if (i, j) not in [(0, 0)] + walk ] # print(warp) cost1 = deque() while cost0: h,w,c=cost0.popleft() cost1.append((h,w,c)) for i,j in walk: dh = h+i dw = w+j if S[dh][dw] == '.' and c < Cost[dh][dw]: Cost[dh][dw] = c # print("updl ", i,j,dh,dw,c) cost0.appendleft((dh,dw,Cost[dh][dw])) if len(cost0) == 0: while cost1: h,w,c=cost1.popleft() # print(h,w,c) for i,j in warp: dh = h+i dw = w+j # print(i,j) if S[dh][dw] == '.' and c + 1 < Cost[dh][dw]: Cost[dh][dw] = c + 1 cost0.append((dh,dw,Cost[dh][dw])) if Cost[DH+1][DW+1] == MAX_COST: print((-1)) else: print((Cost[DH+1][DW+1])) if __name__ == "__main__": # S=[input() for _ in range(H)] solve() #H, W, CH, CW, DH, DW, S)
# import numpy as np from collections import deque # 関数化しただけで、実行速度が半分になった部分あり。。。 def solve(): #H, W, CH, CW, DH, DW, S): H,W=list(map(int,input().split())) CH,CW=list(map(int,input().split())) DH,DW=list(map(int,input().split())) S=[eval(input()) for _ in range(H)] # 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む S = ['##{}##'.format(row) for row in S] S.insert(0, '##{}##'.format('#' * W)) S.insert(0, '##{}##'.format('#' * W)) S.append('##{}##'.format('#' * W)) S.append('##{}##'.format('#' * W)) MAX_COST = 10 ** 9 Cost=[ [ MAX_COST for _ in range(W+4)] for _ in range(H+4)] # Cost = np.full((H,W),MAX_COST) # print(S) ans = -1 cost0 = deque() cost0.append((CH+1,CW+1,0)) Cost[CH+1][CW+1] = 0; # used = set() walk=[(1,0),(0,1),(-1,0),(0,-1)] warp = [ (i,j) for i in range(-2,3) for j in range(-2,3) if (i, j) not in [(0, 0)] + walk ] # print(warp) cost1 = deque() while cost0: h,w,c=cost0.popleft() cost1.append((h,w,c)) for i,j in walk: dh = h+i dw = w+j if S[dh][dw] == '.' and c < Cost[dh][dw]: Cost[dh][dw] = c # print("updl ", i,j,dh,dw,c) cost0.appendleft((dh,dw,Cost[dh][dw])) if len(cost0) == 0: while cost1: h,w,c=cost1.popleft() # print(h,w,c) for i,j in warp: dh = h+i dw = w+j # print(i,j) if S[dh][dw] == '.' and c + 1 < Cost[dh][dw]: Cost[dh][dw] = c + 1 cost0.append((dh,dw,Cost[dh][dw])) if Cost[DH+1][DW+1] == MAX_COST: print((-1)) else: print((Cost[DH+1][DW+1])) if __name__ == "__main__": # S=[input() for _ in range(H)] solve() #H, W, CH, CW, DH, DW, S)
74
75
1,610
1,641
# import numpy as np from collections import deque def solve(): # H, W, CH, CW, DH, DW, S): H, W = list(map(int, input().split())) CH, CW = list(map(int, input().split())) DH, DW = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] # 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む S = ["##{}##".format(row) for row in S] S.insert(0, "##{}##".format("#" * W)) S.insert(0, "##{}##".format("#" * W)) S.append("##{}##".format("#" * W)) S.append("##{}##".format("#" * W)) MAX_COST = 10**9 Cost = [[MAX_COST for _ in range(W + 4)] for _ in range(H + 4)] # Cost = np.full((H,W),MAX_COST) # print(S) ans = -1 cost0 = deque() cost0.append((CH + 1, CW + 1, 0)) Cost[CH + 1][CW + 1] = 0 # used = set() walk = [(1, 0), (0, 1), (-1, 0), (0, -1)] warp = [ (i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk ] # print(warp) cost1 = deque() while cost0: h, w, c = cost0.popleft() cost1.append((h, w, c)) for i, j in walk: dh = h + i dw = w + j if S[dh][dw] == "." and c < Cost[dh][dw]: Cost[dh][dw] = c # print("updl ", i,j,dh,dw,c) cost0.appendleft((dh, dw, Cost[dh][dw])) if len(cost0) == 0: while cost1: h, w, c = cost1.popleft() # print(h,w,c) for i, j in warp: dh = h + i dw = w + j # print(i,j) if S[dh][dw] == "." and c + 1 < Cost[dh][dw]: Cost[dh][dw] = c + 1 cost0.append((dh, dw, Cost[dh][dw])) if Cost[DH + 1][DW + 1] == MAX_COST: print((-1)) else: print((Cost[DH + 1][DW + 1])) if __name__ == "__main__": # S=[input() for _ in range(H)] solve() # H, W, CH, CW, DH, DW, S)
# import numpy as np from collections import deque # 関数化しただけで、実行速度が半分になった部分あり。。。 def solve(): # H, W, CH, CW, DH, DW, S): H, W = list(map(int, input().split())) CH, CW = list(map(int, input().split())) DH, DW = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] # 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む S = ["##{}##".format(row) for row in S] S.insert(0, "##{}##".format("#" * W)) S.insert(0, "##{}##".format("#" * W)) S.append("##{}##".format("#" * W)) S.append("##{}##".format("#" * W)) MAX_COST = 10**9 Cost = [[MAX_COST for _ in range(W + 4)] for _ in range(H + 4)] # Cost = np.full((H,W),MAX_COST) # print(S) ans = -1 cost0 = deque() cost0.append((CH + 1, CW + 1, 0)) Cost[CH + 1][CW + 1] = 0 # used = set() walk = [(1, 0), (0, 1), (-1, 0), (0, -1)] warp = [ (i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk ] # print(warp) cost1 = deque() while cost0: h, w, c = cost0.popleft() cost1.append((h, w, c)) for i, j in walk: dh = h + i dw = w + j if S[dh][dw] == "." and c < Cost[dh][dw]: Cost[dh][dw] = c # print("updl ", i,j,dh,dw,c) cost0.appendleft((dh, dw, Cost[dh][dw])) if len(cost0) == 0: while cost1: h, w, c = cost1.popleft() # print(h,w,c) for i, j in warp: dh = h + i dw = w + j # print(i,j) if S[dh][dw] == "." and c + 1 < Cost[dh][dw]: Cost[dh][dw] = c + 1 cost0.append((dh, dw, Cost[dh][dw])) if Cost[DH + 1][DW + 1] == MAX_COST: print((-1)) else: print((Cost[DH + 1][DW + 1])) if __name__ == "__main__": # S=[input() for _ in range(H)] solve() # H, W, CH, CW, DH, DW, S)
false
1.333333
[ "-", "+# 関数化しただけで、実行速度が半分になった部分あり。。。" ]
false
0.080295
0.035796
2.243135
[ "s202786178", "s546511660" ]
u277312083
p02791
python
s750939084
s201810754
137
110
24,744
24,744
Accepted
Accepted
19.71
n = int(eval(input())) p = list(map(int, input().split( ))) c = 1 m = p[0] for a in p[1:]: m = min(m, a) if m == a: c += 1 print(c)
n = int(eval(input())) p = list(map(int, input().split( ))) c = 0 m = p[0] for i in range(n): if m >= p[i]: c += 1 m = p[i] print(c)
9
9
149
154
n = int(eval(input())) p = list(map(int, input().split())) c = 1 m = p[0] for a in p[1:]: m = min(m, a) if m == a: c += 1 print(c)
n = int(eval(input())) p = list(map(int, input().split())) c = 0 m = p[0] for i in range(n): if m >= p[i]: c += 1 m = p[i] print(c)
false
0
[ "-c = 1", "+c = 0", "-for a in p[1:]:", "- m = min(m, a)", "- if m == a:", "+for i in range(n):", "+ if m >= p[i]:", "+ m = p[i]" ]
false
0.121629
0.101594
1.197207
[ "s750939084", "s201810754" ]
u630511239
p02633
python
s725624312
s939908544
32
29
9,128
9,112
Accepted
Accepted
9.38
X = int(eval(input())) import math A = X // math.gcd(360, X) ans = 360 * A // X print(ans)
X = int(eval(input())) import math ans = 360 // math.gcd(360, X) print(ans)
5
4
88
72
X = int(eval(input())) import math A = X // math.gcd(360, X) ans = 360 * A // X print(ans)
X = int(eval(input())) import math ans = 360 // math.gcd(360, X) print(ans)
false
20
[ "-A = X // math.gcd(360, X)", "-ans = 360 * A // X", "+ans = 360 // math.gcd(360, X)" ]
false
0.045511
0.045993
0.989515
[ "s725624312", "s939908544" ]
u577311000
p00118
python
s821518889
s948860740
120
110
15,568
15,644
Accepted
Accepted
8.33
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) def search(values,hp,vp,item): if not (0<=hp<len(values)): return if not (0<=vp<len(values[hp])): return if item!=values[hp][vp]: return values[hp][vp]=True # for dh,dv in [[0,1],[0,-1],[1,0],[-1,0]]: # search(values,hp+dh,vp+dv,item) search(values,hp-1,vp,item) search(values,hp+1,vp,item) search(values,hp,vp-1,item) search(values,hp,vp+1,item) def solve(values): count,valid_items=0,set(['@','#','*']) for i in range(len(values)): for j in range(len(values[i])): if values[i][j] in valid_items: search(values,i,j,values[i][j]) count+=1 return count def main(): line, values = input().strip(), list() while line!='0 0': H,W = list(map(int,line.split(' '))) value = list() for _ in range(H): value.append(list(x for x in input().strip())) # value.append(list(input().strip())) print((solve(value))) # values.append(value) line = input().strip() # for value in values: # print(solve(value)) if __name__=='__main__': main()
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) def search(values,hp,vp,item): if not (0<=hp<len(values)): return if not (0<=vp<len(values[hp])): return if item!=values[hp][vp]: return values[hp][vp]=True # for dh,dv in [[0,1],[0,-1],[1,0],[-1,0]]: # search(values,hp+dh,vp+dv,item) search(values,hp-1,vp,item) search(values,hp+1,vp,item) search(values,hp,vp-1,item) search(values,hp,vp+1,item) def solve(values): count,valid_items=0,set(['@','#','*']) for i in range(len(values)): for j in range(len(values[i])): if values[i][j] in valid_items: search(values,i,j,values[i][j]) count+=1 return count def main(): line = input().strip() while line!='0 0': H,W = list(map(int,line.split(' '))) values = list() for _ in range(H): values.append(list(input().strip())) print((solve(values))) line = input().strip() if __name__=='__main__': main()
42
38
1,075
937
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) def search(values, hp, vp, item): if not (0 <= hp < len(values)): return if not (0 <= vp < len(values[hp])): return if item != values[hp][vp]: return values[hp][vp] = True # for dh,dv in [[0,1],[0,-1],[1,0],[-1,0]]: # search(values,hp+dh,vp+dv,item) search(values, hp - 1, vp, item) search(values, hp + 1, vp, item) search(values, hp, vp - 1, item) search(values, hp, vp + 1, item) def solve(values): count, valid_items = 0, set(["@", "#", "*"]) for i in range(len(values)): for j in range(len(values[i])): if values[i][j] in valid_items: search(values, i, j, values[i][j]) count += 1 return count def main(): line, values = input().strip(), list() while line != "0 0": H, W = list(map(int, line.split(" "))) value = list() for _ in range(H): value.append(list(x for x in input().strip())) # value.append(list(input().strip())) print((solve(value))) # values.append(value) line = input().strip() # for value in values: # print(solve(value)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) def search(values, hp, vp, item): if not (0 <= hp < len(values)): return if not (0 <= vp < len(values[hp])): return if item != values[hp][vp]: return values[hp][vp] = True # for dh,dv in [[0,1],[0,-1],[1,0],[-1,0]]: # search(values,hp+dh,vp+dv,item) search(values, hp - 1, vp, item) search(values, hp + 1, vp, item) search(values, hp, vp - 1, item) search(values, hp, vp + 1, item) def solve(values): count, valid_items = 0, set(["@", "#", "*"]) for i in range(len(values)): for j in range(len(values[i])): if values[i][j] in valid_items: search(values, i, j, values[i][j]) count += 1 return count def main(): line = input().strip() while line != "0 0": H, W = list(map(int, line.split(" "))) values = list() for _ in range(H): values.append(list(input().strip())) print((solve(values))) line = input().strip() if __name__ == "__main__": main()
false
9.52381
[ "- line, values = input().strip(), list()", "+ line = input().strip()", "- value = list()", "+ values = list()", "- value.append(list(x for x in input().strip()))", "- # \t\t\tvalue.append(list(input().strip()))", "- print((solve(value)))", "- # \t\tvalues.append(value)", "+ values.append(list(input().strip()))", "+ print((solve(values)))", "-# \tfor value in values:", "-# \t\tprint(solve(value))" ]
false
0.114383
0.049315
2.319455
[ "s821518889", "s948860740" ]
u811733736
p00092
python
s758086083
s621143930
3,380
2,730
34,152
34,240
Accepted
Accepted
19.23
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092 """ import sys def find_square0(data): max_size = 0 lmap = [] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for row in data: temp = [] for c in row: if c == '.': temp.append(1) else: temp.append(0) lmap.append(temp) # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? for y in range(1, len(lmap)): for x in range(1, len(lmap[0])): if lmap[y][x] == 1: lmap[y][x] = min(lmap[y-1][x-1], min(lmap[y-1][x], lmap[y][x-1])) + 1 if lmap[y][x] > max_size: max_size = lmap[y][x] return max_size def find_square(data): max_size = 0 lmap = [] for row in data: temp = [] for c in row: if c == '.': temp.append(1) else: temp.append(0) lmap.append(temp) prev_row = lmap[0] for curr_row in lmap[1:]: for x in range(1, len(lmap[0])): if curr_row[x] == 1: if prev_row[x-1] != 0 and prev_row[x] != 0 and curr_row[x-1] != 0: # ???????????¶????????? curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1 if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def find_square2(data): max_size = 0 lmap = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == '.': lmap[y][x] = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = lmap[0] for curr_row in lmap[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1 if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def find_square3(data): from array import array max_size = 0 lmap = [array('I', [0]*len(data[0])) for _ in range(len(data))] # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == '.': lmap[y][x] = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = lmap[0] for curr_row in lmap[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1 if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def main(args): while True: n = int(eval(input())) if n == 0: break data = [eval(input()) for _ in range(n)] result = find_square2(data) print(result) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092 """ import sys def find_square2(data): max_size = 0 dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == '.': dp[y][x] = 1 max_size = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = dp[0] for curr_row in dp[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1 if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def main(args): while True: n = int(eval(input())) if n == 0: break data = [eval(input()) for _ in range(n)] result = find_square2(data) print(result) if __name__ == '__main__': main(sys.argv[1:])
111
42
3,689
1,287
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092 """ import sys def find_square0(data): max_size = 0 lmap = [] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for row in data: temp = [] for c in row: if c == ".": temp.append(1) else: temp.append(0) lmap.append(temp) # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? for y in range(1, len(lmap)): for x in range(1, len(lmap[0])): if lmap[y][x] == 1: lmap[y][x] = ( min(lmap[y - 1][x - 1], min(lmap[y - 1][x], lmap[y][x - 1])) + 1 ) if lmap[y][x] > max_size: max_size = lmap[y][x] return max_size def find_square(data): max_size = 0 lmap = [] for row in data: temp = [] for c in row: if c == ".": temp.append(1) else: temp.append(0) lmap.append(temp) prev_row = lmap[0] for curr_row in lmap[1:]: for x in range(1, len(lmap[0])): if curr_row[x] == 1: if ( prev_row[x - 1] != 0 and prev_row[x] != 0 and curr_row[x - 1] != 0 ): # ???????????¶????????? curr_row[x] = ( min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1 ) if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def find_square2(data): max_size = 0 lmap = [[0] * len(data[0]) for _ in range(len(data))] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == ".": lmap[y][x] = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = lmap[0] for curr_row in lmap[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = ( min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1 ) if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def find_square3(data): from array import array max_size = 0 lmap = [array("I", [0] * len(data[0])) for _ in range(len(data))] # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == ".": lmap[y][x] = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = lmap[0] for curr_row in lmap[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = ( min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1 ) if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def main(args): while True: n = int(eval(input())) if n == 0: break data = [eval(input()) for _ in range(n)] result = find_square2(data) print(result) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092 """ import sys def find_square2(data): max_size = 0 dp = [[0] * len(data[0]) for _ in range(len(data))] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for y, row in enumerate(data): for x, c in enumerate(row): if c == ".": dp[y][x] = 1 max_size = 1 # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§???????????? # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????) prev_row = dp[0] for curr_row in dp[1:]: for x, t in enumerate(curr_row[1:], start=1): if t == 1: curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1 if curr_row[x] > max_size: max_size = curr_row[x] prev_row = curr_row return max_size def main(args): while True: n = int(eval(input())) if n == 0: break data = [eval(input()) for _ in range(n)] result = find_square2(data) print(result) if __name__ == "__main__": main(sys.argv[1:])
false
62.162162
[ "-def find_square0(data):", "- max_size = 0", "- lmap = [] # dp??¨???2?¬??????????", "- # '.'????????????1??????'*'????????????0????????????", "- for row in data:", "- temp = []", "- for c in row:", "- if c == \".\":", "- temp.append(1)", "- else:", "- temp.append(0)", "- lmap.append(temp)", "- # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????", "- for y in range(1, len(lmap)):", "- for x in range(1, len(lmap[0])):", "- if lmap[y][x] == 1:", "- lmap[y][x] = (", "- min(lmap[y - 1][x - 1], min(lmap[y - 1][x], lmap[y][x - 1])) + 1", "- )", "- if lmap[y][x] > max_size:", "- max_size = lmap[y][x]", "- return max_size", "-", "-", "-def find_square(data):", "- max_size = 0", "- lmap = []", "- for row in data:", "- temp = []", "- for c in row:", "- if c == \".\":", "- temp.append(1)", "- else:", "- temp.append(0)", "- lmap.append(temp)", "- prev_row = lmap[0]", "- for curr_row in lmap[1:]:", "- for x in range(1, len(lmap[0])):", "- if curr_row[x] == 1:", "- if (", "- prev_row[x - 1] != 0 and prev_row[x] != 0 and curr_row[x - 1] != 0", "- ): # ???????????¶?????????", "- curr_row[x] = (", "- min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1", "- )", "- if curr_row[x] > max_size:", "- max_size = curr_row[x]", "- prev_row = curr_row", "- return max_size", "-", "-", "- lmap = [[0] * len(data[0]) for _ in range(len(data))] # dp??¨???2?¬??????????", "+ dp = [[0] * len(data[0]) for _ in range(len(data))] # dp??¨???2?¬??????????", "- lmap[y][x] = 1", "+ dp[y][x] = 1", "+ max_size = 1", "- prev_row = lmap[0]", "- for curr_row in lmap[1:]:", "+ prev_row = dp[0]", "+ for curr_row in dp[1:]:", "- curr_row[x] = (", "- min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1", "- )", "- if curr_row[x] > max_size:", "- max_size = curr_row[x]", "- prev_row = curr_row", "- return max_size", "-", "-", "-def find_square3(data):", "- from array import array", "-", "- max_size = 0", "- lmap = [array(\"I\", [0] * len(data[0])) for _ in range(len(data))]", "- # '.'????????????1??????'*'????????????0????????????", "- for y, row in enumerate(data):", "- for x, c in enumerate(row):", "- if c == \".\":", "- lmap[y][x] = 1", "- # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????", "- # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)", "- prev_row = lmap[0]", "- for curr_row in lmap[1:]:", "- for x, t in enumerate(curr_row[1:], start=1):", "- if t == 1:", "- curr_row[x] = (", "- min(prev_row[x - 1], min(prev_row[x], curr_row[x - 1])) + 1", "- )", "+ curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1" ]
false
0.036523
0.035969
1.015406
[ "s758086083", "s621143930" ]
u454022848
p02389
python
s168391200
s435383160
30
10
6,724
6,268
Accepted
Accepted
66.67
def prod(int_list): p = 1 for i in int_list: p *= i return p int_ary = [int(s) for s in input().split(" ")] print((prod(int_ary), 2 * sum(int_ary)))
# encoding:utf-8 input = list(map(int, input().split())) height = input[0] width = input[1] area = height * width circumference = (height + width) * 2 print((area), end=' ') print(circumference)
8
9
160
191
def prod(int_list): p = 1 for i in int_list: p *= i return p int_ary = [int(s) for s in input().split(" ")] print((prod(int_ary), 2 * sum(int_ary)))
# encoding:utf-8 input = list(map(int, input().split())) height = input[0] width = input[1] area = height * width circumference = (height + width) * 2 print((area), end=" ") print(circumference)
false
11.111111
[ "-def prod(int_list):", "- p = 1", "- for i in int_list:", "- p *= i", "- return p", "-", "-", "-int_ary = [int(s) for s in input().split(\" \")]", "-print((prod(int_ary), 2 * sum(int_ary)))", "+# encoding:utf-8", "+input = list(map(int, input().split()))", "+height = input[0]", "+width = input[1]", "+area = height * width", "+circumference = (height + width) * 2", "+print((area), end=\" \")", "+print(circumference)" ]
false
0.034207
0.033707
1.014824
[ "s168391200", "s435383160" ]
u062147869
p03553
python
s292730176
s991232408
200
29
42,716
3,444
Accepted
Accepted
85.5
N=int(eval(input())) P=[int(i) for i in input().split()] inf = 10**20 table=[[0]*(N+2) for i in range(N+2)] for i in range(1,N+1): if P[i-1]>0: table[i][N+1]=P[i-1] else: table[0][i]=-P[i-1] for j in range(2*i,N+1,i): table[i][j]=inf #print(table) def fk(x,t,f): #print(x) visit[x]=True if x==t: return f for i in range(N+2): if (not visit[i]) and table[x][i]>0: df=fk(i,t,min(f,table[x][i])) if df>0: table[x][i]-=df table[i][x]+=df return df return 0 ans=0 while True: visit=[False]*(N+2) df=fk(0,N+1,inf) if df>0: ans+=df else: break num=sum([p for p in P if p>0]) print((num-ans))
from collections import deque N=int(eval(input())) P=[int(i) for i in input().split()] inf = 10**20 table=[[0]*(N+2) for i in range(N+2)] for i in range(1,N+1): if P[i-1]>0: table[i][N+1]=P[i-1] else: table[0][i]=-P[i-1] for j in range(2*i,N+1,i): table[i][j]=inf def bfs(x): visit[x]=0 h=deque() h.append(x) while h: y=h.popleft() for i in range(N+2): if visit[i]==-1 and table[y][i]>0: visit[i]=visit[y]+1 h.append(i) return 0 def dinic(s,t,f): if s==t: return f for i in range(N+2): if visit[i]>visit[s] and table[s][i]>0: df = dinic(i,t,min(f,table[s][i])) if df>0: table[s][i]-=df table[i][s]+=df return df return 0 ans=0 while True: visit=[-1]*(N+2) bfs(0) #print(table,visit) if visit[N+1]==-1: break while True: df=dinic(0,N+1,inf) if df==0: break ans+=df #print(ans) num=sum([p for p in P if p>0]) print((num-ans))
36
52
788
1,166
N = int(eval(input())) P = [int(i) for i in input().split()] inf = 10**20 table = [[0] * (N + 2) for i in range(N + 2)] for i in range(1, N + 1): if P[i - 1] > 0: table[i][N + 1] = P[i - 1] else: table[0][i] = -P[i - 1] for j in range(2 * i, N + 1, i): table[i][j] = inf # print(table) def fk(x, t, f): # print(x) visit[x] = True if x == t: return f for i in range(N + 2): if (not visit[i]) and table[x][i] > 0: df = fk(i, t, min(f, table[x][i])) if df > 0: table[x][i] -= df table[i][x] += df return df return 0 ans = 0 while True: visit = [False] * (N + 2) df = fk(0, N + 1, inf) if df > 0: ans += df else: break num = sum([p for p in P if p > 0]) print((num - ans))
from collections import deque N = int(eval(input())) P = [int(i) for i in input().split()] inf = 10**20 table = [[0] * (N + 2) for i in range(N + 2)] for i in range(1, N + 1): if P[i - 1] > 0: table[i][N + 1] = P[i - 1] else: table[0][i] = -P[i - 1] for j in range(2 * i, N + 1, i): table[i][j] = inf def bfs(x): visit[x] = 0 h = deque() h.append(x) while h: y = h.popleft() for i in range(N + 2): if visit[i] == -1 and table[y][i] > 0: visit[i] = visit[y] + 1 h.append(i) return 0 def dinic(s, t, f): if s == t: return f for i in range(N + 2): if visit[i] > visit[s] and table[s][i] > 0: df = dinic(i, t, min(f, table[s][i])) if df > 0: table[s][i] -= df table[i][s] += df return df return 0 ans = 0 while True: visit = [-1] * (N + 2) bfs(0) # print(table,visit) if visit[N + 1] == -1: break while True: df = dinic(0, N + 1, inf) if df == 0: break ans += df # print(ans) num = sum([p for p in P if p > 0]) print((num - ans))
false
30.769231
[ "+from collections import deque", "+", "-# print(table)", "-def fk(x, t, f):", "- # print(x)", "- visit[x] = True", "- if x == t:", "+", "+", "+def bfs(x):", "+ visit[x] = 0", "+ h = deque()", "+ h.append(x)", "+ while h:", "+ y = h.popleft()", "+ for i in range(N + 2):", "+ if visit[i] == -1 and table[y][i] > 0:", "+ visit[i] = visit[y] + 1", "+ h.append(i)", "+ return 0", "+", "+", "+def dinic(s, t, f):", "+ if s == t:", "- if (not visit[i]) and table[x][i] > 0:", "- df = fk(i, t, min(f, table[x][i]))", "+ if visit[i] > visit[s] and table[s][i] > 0:", "+ df = dinic(i, t, min(f, table[s][i]))", "- table[x][i] -= df", "- table[i][x] += df", "+ table[s][i] -= df", "+ table[i][s] += df", "- visit = [False] * (N + 2)", "- df = fk(0, N + 1, inf)", "- if df > 0:", "+ visit = [-1] * (N + 2)", "+ bfs(0)", "+ # print(table,visit)", "+ if visit[N + 1] == -1:", "+ break", "+ while True:", "+ df = dinic(0, N + 1, inf)", "+ if df == 0:", "+ break", "- else:", "- break", "+ # print(ans)" ]
false
0.046007
0.042519
1.082031
[ "s292730176", "s991232408" ]
u345483150
p02791
python
s101311728
s522290816
117
108
24,744
24,744
Accepted
Accepted
7.69
n=int(eval(input())) p=list(map(int,input().split())) a=p[0] cnt=1 for i in range(n): if p[i]<a: cnt+=1 a=p[i] if p[i]==1: break print(cnt)
n=int(eval(input())) p=list(map(int,input().split())) a=p[0] cnt=1 for i in p: if i<a: cnt+=1 a=i if i==1: break print(cnt)
11
11
183
167
n = int(eval(input())) p = list(map(int, input().split())) a = p[0] cnt = 1 for i in range(n): if p[i] < a: cnt += 1 a = p[i] if p[i] == 1: break print(cnt)
n = int(eval(input())) p = list(map(int, input().split())) a = p[0] cnt = 1 for i in p: if i < a: cnt += 1 a = i if i == 1: break print(cnt)
false
0
[ "-for i in range(n):", "- if p[i] < a:", "+for i in p:", "+ if i < a:", "- a = p[i]", "- if p[i] == 1:", "+ a = i", "+ if i == 1:" ]
false
0.041704
0.040888
1.019959
[ "s101311728", "s522290816" ]