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
u562935282
p02936
python
s171082962
s282095960
1,880
1,079
81,920
80,600
Accepted
Accepted
42.61
n, q = list(map(int, input().split())) g = [set() for _ in range(n)] for _ in range(n - 1): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) ctr = [0] * n for _ in range(q): it = list(map(int, input().split())) p = next(it) - 1 x = next(it) ctr[p] += x st = [0] used = [0] * n used[0] = 1 while st: v = st.pop() for u in g[v]: if used[u]: continue used[u] = 1 ctr[u] += ctr[v] st.append(u) print((*ctr))
def main(): import sys input = sys.stdin.readline n, q = list(map(int, input().split())) g = [set() for _ in range(n)] for _ in range(n - 1): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) ctr = [0] * n for _ in range(q): it = list(map(int, input().split())) p = next(it) - 1 x = next(it) ctr[p] += x st = [0] used = [0] * n used[0] = 1 while st: v = st.pop() for u in g[v]: if used[u]: continue used[u] = 1 ctr[u] += ctr[v] st.append(u) print((*ctr)) if __name__ == '__main__': main()
26
34
506
705
n, q = list(map(int, input().split())) g = [set() for _ in range(n)] for _ in range(n - 1): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) ctr = [0] * n for _ in range(q): it = list(map(int, input().split())) p = next(it) - 1 x = next(it) ctr[p] += x st = [0] used = [0] * n used[0] = 1 while st: v = st.pop() for u in g[v]: if used[u]: continue used[u] = 1 ctr[u] += ctr[v] st.append(u) print((*ctr))
def main(): import sys input = sys.stdin.readline n, q = list(map(int, input().split())) g = [set() for _ in range(n)] for _ in range(n - 1): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) ctr = [0] * n for _ in range(q): it = list(map(int, input().split())) p = next(it) - 1 x = next(it) ctr[p] += x st = [0] used = [0] * n used[0] = 1 while st: v = st.pop() for u in g[v]: if used[u]: continue used[u] = 1 ctr[u] += ctr[v] st.append(u) print((*ctr)) if __name__ == "__main__": main()
false
23.529412
[ "-n, q = list(map(int, input().split()))", "-g = [set() for _ in range(n)]", "-for _ in range(n - 1):", "- a, b = (int(x) - 1 for x in input().split())", "- g[a].add(b)", "- g[b].add(a)", "-ctr = [0] * n", "-for _ in range(q):", "- it = list(map(int, input().split()))", "- p = next(it) - 1", "- x = next(it)", "- ctr[p] += x", "-st = [0]", "-used = [0] * n", "-used[0] = 1", "-while st:", "- v = st.pop()", "- for u in g[v]:", "- if used[u]:", "- continue", "- used[u] = 1", "- ctr[u] += ctr[v]", "- st.append(u)", "-print((*ctr))", "+def main():", "+ import sys", "+", "+ input = sys.stdin.readline", "+ n, q = list(map(int, input().split()))", "+ g = [set() for _ in range(n)]", "+ for _ in range(n - 1):", "+ a, b = (int(x) - 1 for x in input().split())", "+ g[a].add(b)", "+ g[b].add(a)", "+ ctr = [0] * n", "+ for _ in range(q):", "+ it = list(map(int, input().split()))", "+ p = next(it) - 1", "+ x = next(it)", "+ ctr[p] += x", "+ st = [0]", "+ used = [0] * n", "+ used[0] = 1", "+ while st:", "+ v = st.pop()", "+ for u in g[v]:", "+ if used[u]:", "+ continue", "+ used[u] = 1", "+ ctr[u] += ctr[v]", "+ st.append(u)", "+ print((*ctr))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037728
0.075824
0.497576
[ "s171082962", "s282095960" ]
u074220993
p03457
python
s662292028
s920265773
263
170
23,868
24,056
Accepted
Accepted
35.36
N = int(eval(input())) P = [(0,0,0)] + [tuple(int(x) for x in input().split()) for _ in range(N)] def travelable(p,q): time = q[0] - p[0] dist = abs(q[1]-p[1]) + abs(q[2]-p[2]) if dist <= time and time%2 == dist%2: return True else: return False print(('Yes' if all(travelable(p,q) for p,q in zip(P[:N],P[1:])) else 'No'))
from collections import namedtuple plan = namedtuple('plan', ['time', 'x', 'y']) def main(): with open(0) as f: N = int(f.readline()) plans = [] for _ in range(N): t, x, y = list(map(int, f.readline().split())) plans.append(plan(t, x, y)) current = plan(0, 0, 0) for p in plans: t = p.time - current.time way = abs(p.x-current.x) + abs(p.y-current.y) if t < way: print('No') return None if (t - way) & 1: print('No') return None current = p else: print('Yes') main()
12
25
367
646
N = int(eval(input())) P = [(0, 0, 0)] + [tuple(int(x) for x in input().split()) for _ in range(N)] def travelable(p, q): time = q[0] - p[0] dist = abs(q[1] - p[1]) + abs(q[2] - p[2]) if dist <= time and time % 2 == dist % 2: return True else: return False print(("Yes" if all(travelable(p, q) for p, q in zip(P[:N], P[1:])) else "No"))
from collections import namedtuple plan = namedtuple("plan", ["time", "x", "y"]) def main(): with open(0) as f: N = int(f.readline()) plans = [] for _ in range(N): t, x, y = list(map(int, f.readline().split())) plans.append(plan(t, x, y)) current = plan(0, 0, 0) for p in plans: t = p.time - current.time way = abs(p.x - current.x) + abs(p.y - current.y) if t < way: print("No") return None if (t - way) & 1: print("No") return None current = p else: print("Yes") main()
false
52
[ "-N = int(eval(input()))", "-P = [(0, 0, 0)] + [tuple(int(x) for x in input().split()) for _ in range(N)]", "+from collections import namedtuple", "+", "+plan = namedtuple(\"plan\", [\"time\", \"x\", \"y\"])", "-def travelable(p, q):", "- time = q[0] - p[0]", "- dist = abs(q[1] - p[1]) + abs(q[2] - p[2])", "- if dist <= time and time % 2 == dist % 2:", "- return True", "+def main():", "+ with open(0) as f:", "+ N = int(f.readline())", "+ plans = []", "+ for _ in range(N):", "+ t, x, y = list(map(int, f.readline().split()))", "+ plans.append(plan(t, x, y))", "+ current = plan(0, 0, 0)", "+ for p in plans:", "+ t = p.time - current.time", "+ way = abs(p.x - current.x) + abs(p.y - current.y)", "+ if t < way:", "+ print(\"No\")", "+ return None", "+ if (t - way) & 1:", "+ print(\"No\")", "+ return None", "+ current = p", "- return False", "+ print(\"Yes\")", "-print((\"Yes\" if all(travelable(p, q) for p, q in zip(P[:N], P[1:])) else \"No\"))", "+main()" ]
false
0.04493
0.038496
1.167138
[ "s662292028", "s920265773" ]
u672475305
p03829
python
s918752070
s823413426
226
95
62,704
14,224
Accepted
Accepted
57.96
n,a,b = list(map(int,input().split())) lst = list(map(int,input().split())) ans = 0 for i in range(1,n): if (lst[i] - lst[i-1]) * a >= b: ans += b else: ans += (lst[i] - lst[i-1]) * a print(ans)
n,a,b = list(map(int,input().split())) X = list(map(int,input().split())) pos = X[0] ans = 0 for i in range(1, n): ans += min(b, (X[i] - pos)*a) pos = X[i] print(ans)
9
8
220
175
n, a, b = list(map(int, input().split())) lst = list(map(int, input().split())) ans = 0 for i in range(1, n): if (lst[i] - lst[i - 1]) * a >= b: ans += b else: ans += (lst[i] - lst[i - 1]) * a print(ans)
n, a, b = list(map(int, input().split())) X = list(map(int, input().split())) pos = X[0] ans = 0 for i in range(1, n): ans += min(b, (X[i] - pos) * a) pos = X[i] print(ans)
false
11.111111
[ "-lst = list(map(int, input().split()))", "+X = list(map(int, input().split()))", "+pos = X[0]", "- if (lst[i] - lst[i - 1]) * a >= b:", "- ans += b", "- else:", "- ans += (lst[i] - lst[i - 1]) * a", "+ ans += min(b, (X[i] - pos) * a)", "+ pos = X[i]" ]
false
0.160812
0.038652
4.160508
[ "s918752070", "s823413426" ]
u156383602
p02897
python
s920334165
s261665654
19
17
2,940
2,940
Accepted
Accepted
10.53
n=int(eval(input())) if n%2==0: print((0.5)) else: print(((n-1)/(2*n)+1/n))
a=int(eval(input())) print((-(-a//2)/a))
5
2
78
33
n = int(eval(input())) if n % 2 == 0: print((0.5)) else: print(((n - 1) / (2 * n) + 1 / n))
a = int(eval(input())) print((-(-a // 2) / a))
false
60
[ "-n = int(eval(input()))", "-if n % 2 == 0:", "- print((0.5))", "-else:", "- print(((n - 1) / (2 * n) + 1 / n))", "+a = int(eval(input()))", "+print((-(-a // 2) / a))" ]
false
0.050926
0.050967
0.999195
[ "s920334165", "s261665654" ]
u313111801
p02590
python
s032212518
s152657283
1,226
903
86,756
86,648
Accepted
Accepted
26.35
import sys import numpy as np def fft_convolve(f, g): """ 数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで, 30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える. """ fft = np.fft.rfft ifft = np.fft.irfft Lf = len(f) Lg = len(g) L = Lf + Lg - 1 fft_len = 1 << L.bit_length() fl = f & (1 << 15) - 1 fh = f >> 15 gl = g & (1 << 15) - 1 gh = g >> 15 def conv(f, g): return ifft(fft(f, fft_len) * fft(g, fft_len))[:L] x = conv(fl, gl) y = conv(fl + fh, gl + gh) z = conv(fh, gh) a, b, c = [(x + .5).astype(np.int64) for x in [x, y, z]] return (a + ((b - a - c) << 15) + (c << 30)) ROOT=2 P=200003 pw=[1]*(P-1) lg=[-1]*P for i in range(1,len(pw)): pw[i]=ROOT*pw[i-1]%P for i in range(len(pw)): lg[pw[i]]=i N=int(eval(input())) A=np.array([int(x) for x in input().split()],dtype=np.int64) B=[0]*P for a in A: if a==0: continue B[lg[a]]+=1 B=np.array(B,dtype=np.int64) C=fft_convolve(B,B) for i in range(P-1,len(C)): C[i%(P-1)]+=C[i] C=C[:P-1] ans=0 for i in range(len(B)): C[2*i%(P-1)]-=B[i]*B[i] ans+=B[i]*(B[i]-1)//2*pw[2*i%(P-1)] for i in range(len(C)): C[i]//=2 for i in range(len(C)): ans+=pw[i]*C[i] print(ans)
import sys import numpy as np def fft_convolve(f, g): """ 数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで, 30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える. """ fft = np.fft.rfft ifft = np.fft.irfft Lf = len(f) Lg = len(g) L = Lf + Lg - 1 fft_len = 1 << L.bit_length() fl = f & (1 << 15) - 1 fh = f >> 15 gl = g & (1 << 15) - 1 gh = g >> 15 def conv(f, g): return ifft(fft(f, fft_len) * fft(g, fft_len))[:L] x = conv(fl, gl) y = conv(fl + fh, gl + gh) z = conv(fh, gh) a, b, c = [(x + .5).astype(np.int64) for x in [x, y, z]] return (a + ((b - a - c) << 15) + (c << 30)) ROOT=2 P=200003 pw=[1]*(P-1) lg=[-1]*P for i in range(1,len(pw)): pw[i]=ROOT*pw[i-1]%P for i in range(len(pw)): lg[pw[i]]=i N=int(eval(input())) A=np.array([int(x) for x in input().split()],dtype=np.int64) B=[0]*P for a in A: if a==0: continue B[lg[a]]+=1 B=np.array(B,dtype=np.int64) C=fft_convolve(B,B) ans=0 for a in A: ans-=a*a%P for i in range(len(C)): ans+=C[i]*pw[i%(P-1)] ans//=2 print(ans)
63
55
1,294
1,137
import sys import numpy as np def fft_convolve(f, g): """ 数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで, 30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える. """ fft = np.fft.rfft ifft = np.fft.irfft Lf = len(f) Lg = len(g) L = Lf + Lg - 1 fft_len = 1 << L.bit_length() fl = f & (1 << 15) - 1 fh = f >> 15 gl = g & (1 << 15) - 1 gh = g >> 15 def conv(f, g): return ifft(fft(f, fft_len) * fft(g, fft_len))[:L] x = conv(fl, gl) y = conv(fl + fh, gl + gh) z = conv(fh, gh) a, b, c = [(x + 0.5).astype(np.int64) for x in [x, y, z]] return a + ((b - a - c) << 15) + (c << 30) ROOT = 2 P = 200003 pw = [1] * (P - 1) lg = [-1] * P for i in range(1, len(pw)): pw[i] = ROOT * pw[i - 1] % P for i in range(len(pw)): lg[pw[i]] = i N = int(eval(input())) A = np.array([int(x) for x in input().split()], dtype=np.int64) B = [0] * P for a in A: if a == 0: continue B[lg[a]] += 1 B = np.array(B, dtype=np.int64) C = fft_convolve(B, B) for i in range(P - 1, len(C)): C[i % (P - 1)] += C[i] C = C[: P - 1] ans = 0 for i in range(len(B)): C[2 * i % (P - 1)] -= B[i] * B[i] ans += B[i] * (B[i] - 1) // 2 * pw[2 * i % (P - 1)] for i in range(len(C)): C[i] //= 2 for i in range(len(C)): ans += pw[i] * C[i] print(ans)
import sys import numpy as np def fft_convolve(f, g): """ 数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで, 30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える. """ fft = np.fft.rfft ifft = np.fft.irfft Lf = len(f) Lg = len(g) L = Lf + Lg - 1 fft_len = 1 << L.bit_length() fl = f & (1 << 15) - 1 fh = f >> 15 gl = g & (1 << 15) - 1 gh = g >> 15 def conv(f, g): return ifft(fft(f, fft_len) * fft(g, fft_len))[:L] x = conv(fl, gl) y = conv(fl + fh, gl + gh) z = conv(fh, gh) a, b, c = [(x + 0.5).astype(np.int64) for x in [x, y, z]] return a + ((b - a - c) << 15) + (c << 30) ROOT = 2 P = 200003 pw = [1] * (P - 1) lg = [-1] * P for i in range(1, len(pw)): pw[i] = ROOT * pw[i - 1] % P for i in range(len(pw)): lg[pw[i]] = i N = int(eval(input())) A = np.array([int(x) for x in input().split()], dtype=np.int64) B = [0] * P for a in A: if a == 0: continue B[lg[a]] += 1 B = np.array(B, dtype=np.int64) C = fft_convolve(B, B) ans = 0 for a in A: ans -= a * a % P for i in range(len(C)): ans += C[i] * pw[i % (P - 1)] ans //= 2 print(ans)
false
12.698413
[ "-for i in range(P - 1, len(C)):", "- C[i % (P - 1)] += C[i]", "-C = C[: P - 1]", "-for i in range(len(B)):", "- C[2 * i % (P - 1)] -= B[i] * B[i]", "- ans += B[i] * (B[i] - 1) // 2 * pw[2 * i % (P - 1)]", "+for a in A:", "+ ans -= a * a % P", "- C[i] //= 2", "-for i in range(len(C)):", "- ans += pw[i] * C[i]", "+ ans += C[i] * pw[i % (P - 1)]", "+ans //= 2" ]
false
2.72074
0.972198
2.798546
[ "s032212518", "s152657283" ]
u934442292
p02642
python
s107600433
s250036126
766
618
136,780
132,020
Accepted
Accepted
19.32
import sys from collections import Counter import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8[:],i8[:])") def solve(keys, values): MAX_A = 10 ** 6 divisible = [False] * (MAX_A + 1) ans = 0 for k, v in zip(keys, values): if v == 1 and not divisible[k]: ans += 1 for i in range(k, MAX_A + 1, k): divisible[i] = True return ans def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() c = Counter(A) keys = np.array(tuple(c.keys()), dtype=np.int64) values = np.array(tuple(c.values()), dtype=np.int64) ans = solve(keys, values) print(ans) if __name__ == "__main__": main()
import sys from collections import Counter import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8[:],i8[:])", cache=True) def solve(keys, values): MAX_A = 10 ** 6 divisible = [False] * (MAX_A + 1) ans = 0 for k, v in zip(keys, values): if v == 1 and not divisible[k]: ans += 1 for i in range(k, MAX_A + 1, k): divisible[i] = True return ans def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() c = Counter(A) keys = np.array(tuple(c.keys()), dtype=np.int64) values = np.array(tuple(c.values()), dtype=np.int64) ans = solve(keys, values) print(ans) if __name__ == "__main__": main()
37
37
759
771
import sys from collections import Counter import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8[:],i8[:])") def solve(keys, values): MAX_A = 10**6 divisible = [False] * (MAX_A + 1) ans = 0 for k, v in zip(keys, values): if v == 1 and not divisible[k]: ans += 1 for i in range(k, MAX_A + 1, k): divisible[i] = True return ans def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() c = Counter(A) keys = np.array(tuple(c.keys()), dtype=np.int64) values = np.array(tuple(c.values()), dtype=np.int64) ans = solve(keys, values) print(ans) if __name__ == "__main__": main()
import sys from collections import Counter import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8[:],i8[:])", cache=True) def solve(keys, values): MAX_A = 10**6 divisible = [False] * (MAX_A + 1) ans = 0 for k, v in zip(keys, values): if v == 1 and not divisible[k]: ans += 1 for i in range(k, MAX_A + 1, k): divisible[i] = True return ans def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() c = Counter(A) keys = np.array(tuple(c.keys()), dtype=np.int64) values = np.array(tuple(c.values()), dtype=np.int64) ans = solve(keys, values) print(ans) if __name__ == "__main__": main()
false
0
[ "[email protected](\"i8(i8[:],i8[:])\")", "[email protected](\"i8(i8[:],i8[:])\", cache=True)" ]
false
0.042499
0.045313
0.937908
[ "s107600433", "s250036126" ]
u241159583
p02861
python
s803207641
s481164981
498
424
8,052
3,064
Accepted
Accepted
14.86
import itertools N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] route = list(itertools.permutations(list(range(N)))) ans = 0 for i in range(len(route)): for j in range(N-1): a = route[i][j] b = route[i][j + 1] X = (xy[a][0] - xy[b][0]) ** 2 Y = (xy[a][1] - xy[b][1]) ** 2 ans += (X + Y) ** 0.5 print((ans / len(route)))
import itertools N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] d = 0 c = 0 for x in itertools.permutations(xy): c += 1 D = 0 for i in range(N-1): D += ((x[i][0]-x[i+1][0]) ** 2 + (x[i][1]-x[i+1][1]) ** 2) ** 0.5 d += D ans = d / c print(ans)
15
14
383
295
import itertools N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] route = list(itertools.permutations(list(range(N)))) ans = 0 for i in range(len(route)): for j in range(N - 1): a = route[i][j] b = route[i][j + 1] X = (xy[a][0] - xy[b][0]) ** 2 Y = (xy[a][1] - xy[b][1]) ** 2 ans += (X + Y) ** 0.5 print((ans / len(route)))
import itertools N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] d = 0 c = 0 for x in itertools.permutations(xy): c += 1 D = 0 for i in range(N - 1): D += ((x[i][0] - x[i + 1][0]) ** 2 + (x[i][1] - x[i + 1][1]) ** 2) ** 0.5 d += D ans = d / c print(ans)
false
6.666667
[ "-route = list(itertools.permutations(list(range(N))))", "-ans = 0", "-for i in range(len(route)):", "- for j in range(N - 1):", "- a = route[i][j]", "- b = route[i][j + 1]", "- X = (xy[a][0] - xy[b][0]) ** 2", "- Y = (xy[a][1] - xy[b][1]) ** 2", "- ans += (X + Y) ** 0.5", "-print((ans / len(route)))", "+d = 0", "+c = 0", "+for x in itertools.permutations(xy):", "+ c += 1", "+ D = 0", "+ for i in range(N - 1):", "+ D += ((x[i][0] - x[i + 1][0]) ** 2 + (x[i][1] - x[i + 1][1]) ** 2) ** 0.5", "+ d += D", "+ans = d / c", "+print(ans)" ]
false
0.042055
0.040656
1.034406
[ "s803207641", "s481164981" ]
u429029348
p02658
python
s568897306
s410259238
53
49
21,712
21,448
Accepted
Accepted
7.55
n=int(eval(input())) a=list(map(int,input().split())) if 0 in a: ans=0 else: ans=1 for i in range(n): ans*=a[i] if ans<=10**18: continue else: ans=-1 break print(ans)
n=int(eval(input())) a=list(map(int,input().split())) ans=1 if 0 in a: ans=0 else: for i in range(n): ans*=a[i] if ans>10**18: ans=-1 break print(ans)
14
12
245
179
n = int(eval(input())) a = list(map(int, input().split())) if 0 in a: ans = 0 else: ans = 1 for i in range(n): ans *= a[i] if ans <= 10**18: continue else: ans = -1 break print(ans)
n = int(eval(input())) a = list(map(int, input().split())) ans = 1 if 0 in a: ans = 0 else: for i in range(n): ans *= a[i] if ans > 10**18: ans = -1 break print(ans)
false
14.285714
[ "+ans = 1", "- ans = 1", "- if ans <= 10**18:", "- continue", "- else:", "+ if ans > 10**18:" ]
false
0.104453
0.03818
2.735795
[ "s568897306", "s410259238" ]
u652150585
p03487
python
s030373326
s996787049
152
77
18,340
18,336
Accepted
Accepted
49.34
import sys import collections input=sys.stdin.readline n=int(eval(input())) l=list(map(int,input().split())) li=collections.Counter(l) #print(li) a=0 for k,v in list(li.items()): if k>v: a+=v else: a+=v-k print(a)
import sys import collections input=sys.stdin.readline n=int(eval(input())) l=list(map(int,input().split())) s=collections.Counter(l) #print(s) a=0 for k,v in list(s.items()): if k>v: a+=v else: a+=v-k print(a)
15
15
240
237
import sys import collections input = sys.stdin.readline n = int(eval(input())) l = list(map(int, input().split())) li = collections.Counter(l) # print(li) a = 0 for k, v in list(li.items()): if k > v: a += v else: a += v - k print(a)
import sys import collections input = sys.stdin.readline n = int(eval(input())) l = list(map(int, input().split())) s = collections.Counter(l) # print(s) a = 0 for k, v in list(s.items()): if k > v: a += v else: a += v - k print(a)
false
0
[ "-li = collections.Counter(l)", "-# print(li)", "+s = collections.Counter(l)", "+# print(s)", "-for k, v in list(li.items()):", "+for k, v in list(s.items()):" ]
false
0.038694
0.052726
0.733875
[ "s030373326", "s996787049" ]
u879870653
p03162
python
s852388905
s061732327
1,071
498
47,324
30,580
Accepted
Accepted
53.5
N = int(eval(input())) L = [] for i in range(N) : L.append(list(map(int,input().split()))) dp = [[0,0,0] for i in range(N+1)] for i in range(N) : for j in range(3) : for k in range(3) : if j == k : continue dp[i+1][k] = max(dp[i+1][k], dp[i][j] + L[i][k]) print((max(dp[-1])))
N = int(eval(input())) L = [list(map(int,input().split())) for i in range(N)] NOW = [0,0,0] NEXT = [None,None,None] for i in range(N) : NEXT[0] = max(NOW[1],NOW[2]) + L[i][0] NEXT[1] = max(NOW[2],NOW[0]) + L[i][1] NEXT[2] = max(NOW[0],NOW[1]) + L[i][2] NOW = NEXT.copy() print((max(NOW)))
14
12
341
314
N = int(eval(input())) L = [] for i in range(N): L.append(list(map(int, input().split()))) dp = [[0, 0, 0] for i in range(N + 1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + L[i][k]) print((max(dp[-1])))
N = int(eval(input())) L = [list(map(int, input().split())) for i in range(N)] NOW = [0, 0, 0] NEXT = [None, None, None] for i in range(N): NEXT[0] = max(NOW[1], NOW[2]) + L[i][0] NEXT[1] = max(NOW[2], NOW[0]) + L[i][1] NEXT[2] = max(NOW[0], NOW[1]) + L[i][2] NOW = NEXT.copy() print((max(NOW)))
false
14.285714
[ "-L = []", "+L = [list(map(int, input().split())) for i in range(N)]", "+NOW = [0, 0, 0]", "+NEXT = [None, None, None]", "- L.append(list(map(int, input().split())))", "-dp = [[0, 0, 0] for i in range(N + 1)]", "-for i in range(N):", "- for j in range(3):", "- for k in range(3):", "- if j == k:", "- continue", "- dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + L[i][k])", "-print((max(dp[-1])))", "+ NEXT[0] = max(NOW[1], NOW[2]) + L[i][0]", "+ NEXT[1] = max(NOW[2], NOW[0]) + L[i][1]", "+ NEXT[2] = max(NOW[0], NOW[1]) + L[i][2]", "+ NOW = NEXT.copy()", "+print((max(NOW)))" ]
false
0.037471
0.037095
1.01012
[ "s852388905", "s061732327" ]
u392319141
p03634
python
s114827522
s721579669
839
614
46,540
63,484
Accepted
Accepted
26.82
import sys import heapq from operator import itemgetter from collections import deque, defaultdict from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) class Heapq: def __init__(self, que=[], asc=True): if not asc: que = [-a for a in que] self.__que = que heapq.heapify(self.__que) self.__sign = 1 if asc else -1 def pop(self): return heapq.heappop(self.__que) * self.__sign def push(self, value): heapq.heappush(self.__que, value * self.__sign) def pushpop(self, value): return heapq.heappushpop(self.__que, value * self.__sign) * self.__sign def top(self): return self.__que[0] * self.__sign def size(self): return len(self.__que) def sol(): N = int(eval(input())) edges = [[] for _ in range(N)] for _ in range(N - 1): fr, to, cost = list(map(int, input().split())) fr -= 1 to -= 1 edges[fr].append((to, cost)) edges[to].append((fr, cost)) Q, K = list(map(int, input().split())) K -= 1 minDist = [float('inf')] * N que = Heapq([]) que.push((0, K)) while que.size(): dist, now = que.pop() if minDist[now] < dist: continue minDist[now] = dist for to, cost in edges[now]: if minDist[to] > dist + cost: que.push((dist + cost, to)) for _ in range(Q): fr, to = list(map(int, input().split())) print((minDist[fr - 1] + minDist[to - 1])) sol()
from collections import deque import sys input = sys.stdin.buffer.readline N = int(input()) edges = [[] for _ in range(N)] for _ in range(N - 1): fr, to, cost = map(int, input().split()) fr -= 1 to -= 1 edges[fr].append((to, cost)) edges[to].append((fr, cost)) Q, K = map(int, input().split()) K -= 1 XY = [tuple(map(int, input().split())) for _ in range(Q)] que = deque([(K, -1, 0)]) dist = [10**18] * N while que: now, pr, d = que.popleft() dist[now] = d for to, c in edges[now]: if to == pr: continue que.append((to, now, d + c)) ans = [dist[x - 1] + dist[y - 1] for x, y in XY] print(*ans, sep='\n')
67
30
1,620
698
import sys import heapq from operator import itemgetter from collections import deque, defaultdict from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10**7) class Heapq: def __init__(self, que=[], asc=True): if not asc: que = [-a for a in que] self.__que = que heapq.heapify(self.__que) self.__sign = 1 if asc else -1 def pop(self): return heapq.heappop(self.__que) * self.__sign def push(self, value): heapq.heappush(self.__que, value * self.__sign) def pushpop(self, value): return heapq.heappushpop(self.__que, value * self.__sign) * self.__sign def top(self): return self.__que[0] * self.__sign def size(self): return len(self.__que) def sol(): N = int(eval(input())) edges = [[] for _ in range(N)] for _ in range(N - 1): fr, to, cost = list(map(int, input().split())) fr -= 1 to -= 1 edges[fr].append((to, cost)) edges[to].append((fr, cost)) Q, K = list(map(int, input().split())) K -= 1 minDist = [float("inf")] * N que = Heapq([]) que.push((0, K)) while que.size(): dist, now = que.pop() if minDist[now] < dist: continue minDist[now] = dist for to, cost in edges[now]: if minDist[to] > dist + cost: que.push((dist + cost, to)) for _ in range(Q): fr, to = list(map(int, input().split())) print((minDist[fr - 1] + minDist[to - 1])) sol()
from collections import deque import sys input = sys.stdin.buffer.readline N = int(input()) edges = [[] for _ in range(N)] for _ in range(N - 1): fr, to, cost = map(int, input().split()) fr -= 1 to -= 1 edges[fr].append((to, cost)) edges[to].append((fr, cost)) Q, K = map(int, input().split()) K -= 1 XY = [tuple(map(int, input().split())) for _ in range(Q)] que = deque([(K, -1, 0)]) dist = [10**18] * N while que: now, pr, d = que.popleft() dist[now] = d for to, c in edges[now]: if to == pr: continue que.append((to, now, d + c)) ans = [dist[x - 1] + dist[y - 1] for x, y in XY] print(*ans, sep="\n")
false
55.223881
[ "+from collections import deque", "-import heapq", "-from operator import itemgetter", "-from collections import deque, defaultdict", "-from bisect import bisect_left, bisect_right", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-", "-", "-class Heapq:", "- def __init__(self, que=[], asc=True):", "- if not asc:", "- que = [-a for a in que]", "- self.__que = que", "- heapq.heapify(self.__que)", "- self.__sign = 1 if asc else -1", "-", "- def pop(self):", "- return heapq.heappop(self.__que) * self.__sign", "-", "- def push(self, value):", "- heapq.heappush(self.__que, value * self.__sign)", "-", "- def pushpop(self, value):", "- return heapq.heappushpop(self.__que, value * self.__sign) * self.__sign", "-", "- def top(self):", "- return self.__que[0] * self.__sign", "-", "- def size(self):", "- return len(self.__que)", "-", "-", "-def sol():", "- N = int(eval(input()))", "- edges = [[] for _ in range(N)]", "- for _ in range(N - 1):", "- fr, to, cost = list(map(int, input().split()))", "- fr -= 1", "- to -= 1", "- edges[fr].append((to, cost))", "- edges[to].append((fr, cost))", "- Q, K = list(map(int, input().split()))", "- K -= 1", "- minDist = [float(\"inf\")] * N", "- que = Heapq([])", "- que.push((0, K))", "- while que.size():", "- dist, now = que.pop()", "- if minDist[now] < dist:", "+input = sys.stdin.buffer.readline", "+N = int(input())", "+edges = [[] for _ in range(N)]", "+for _ in range(N - 1):", "+ fr, to, cost = map(int, input().split())", "+ fr -= 1", "+ to -= 1", "+ edges[fr].append((to, cost))", "+ edges[to].append((fr, cost))", "+Q, K = map(int, input().split())", "+K -= 1", "+XY = [tuple(map(int, input().split())) for _ in range(Q)]", "+que = deque([(K, -1, 0)])", "+dist = [10**18] * N", "+while que:", "+ now, pr, d = que.popleft()", "+ dist[now] = d", "+ for to, c in edges[now]:", "+ if to == pr:", "- minDist[now] = dist", "- for to, cost in edges[now]:", "- if minDist[to] > dist + cost:", "- que.push((dist + cost, to))", "- for _ in range(Q):", "- fr, to = list(map(int, input().split()))", "- print((minDist[fr - 1] + minDist[to - 1]))", "-", "-", "-sol()", "+ que.append((to, now, d + c))", "+ans = [dist[x - 1] + dist[y - 1] for x, y in XY]", "+print(*ans, sep=\"\\n\")" ]
false
0.043823
0.038341
1.142984
[ "s114827522", "s721579669" ]
u279493135
p02743
python
s727266254
s646456108
158
40
13,668
5,268
Accepted
Accepted
74.68
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 a, b, c = MAP() if c-a-b > 0 and 4*a*b < (c-a-b)**2: print("Yes") else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import * def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 a, b, c = MAP() if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
27
27
836
864
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 a, b, c = MAP() if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2: print("Yes") else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import * def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 a, b, c = MAP() if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
false
0
[ "-import numpy as np", "+from decimal import *", "-if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:", "+if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():" ]
false
0.046362
0.040364
1.148587
[ "s727266254", "s646456108" ]
u298297089
p03426
python
s566885244
s476684221
722
666
52,608
49,724
Accepted
Accepted
7.76
H,W,D = list(map(int, input().split())) grid_dict = {} for i in range(H): for j,s in enumerate(input().split()): grid_dict[int(s)] = [i,j] Q = int(eval(input())) exam = [] for i in range(Q): exam.append(list(map(int, input().split()))) man = lambda x,y: abs(x[0]-y[0])+abs(x[1]-y[1]) power = [[0] for i in range(D)] power[0].append(0) for i in range(1,H*W+1): if i + D not in grid_dict: break power[i%D].append(power[i%D][-1] + man(grid_dict[i], grid_dict[i+D])) # [print(i) for i in power] for l,r in exam: if r == l: print((0)) continue print((power[r%D][r//D]-power[r%D][l//D]))
H,W,D = list(map(int, input().split())) A = {} for i in range(H): for j, s in enumerate(input().split()): A[int(s)] = [i,j] Q = int(eval(input())) exam = [] for i in range(Q): exam.append(list(map(int, input().split()))) grid = [0] manta = lambda x,y:abs(x[0]-y[0])+abs(x[1]-y[1]) for i in range(1, H*W+1): if (i-1) // D == 0: grid.append(0) else: grid.append(manta(A[i], A[i-D]) + grid[i-D]) for l,r in exam: print((grid[r]-grid[l]))
26
19
651
484
H, W, D = list(map(int, input().split())) grid_dict = {} for i in range(H): for j, s in enumerate(input().split()): grid_dict[int(s)] = [i, j] Q = int(eval(input())) exam = [] for i in range(Q): exam.append(list(map(int, input().split()))) man = lambda x, y: abs(x[0] - y[0]) + abs(x[1] - y[1]) power = [[0] for i in range(D)] power[0].append(0) for i in range(1, H * W + 1): if i + D not in grid_dict: break power[i % D].append(power[i % D][-1] + man(grid_dict[i], grid_dict[i + D])) # [print(i) for i in power] for l, r in exam: if r == l: print((0)) continue print((power[r % D][r // D] - power[r % D][l // D]))
H, W, D = list(map(int, input().split())) A = {} for i in range(H): for j, s in enumerate(input().split()): A[int(s)] = [i, j] Q = int(eval(input())) exam = [] for i in range(Q): exam.append(list(map(int, input().split()))) grid = [0] manta = lambda x, y: abs(x[0] - y[0]) + abs(x[1] - y[1]) for i in range(1, H * W + 1): if (i - 1) // D == 0: grid.append(0) else: grid.append(manta(A[i], A[i - D]) + grid[i - D]) for l, r in exam: print((grid[r] - grid[l]))
false
26.923077
[ "-grid_dict = {}", "+A = {}", "- grid_dict[int(s)] = [i, j]", "+ A[int(s)] = [i, j]", "-man = lambda x, y: abs(x[0] - y[0]) + abs(x[1] - y[1])", "-power = [[0] for i in range(D)]", "-power[0].append(0)", "+grid = [0]", "+manta = lambda x, y: abs(x[0] - y[0]) + abs(x[1] - y[1])", "- if i + D not in grid_dict:", "- break", "- power[i % D].append(power[i % D][-1] + man(grid_dict[i], grid_dict[i + D]))", "-# [print(i) for i in power]", "+ if (i - 1) // D == 0:", "+ grid.append(0)", "+ else:", "+ grid.append(manta(A[i], A[i - D]) + grid[i - D])", "- if r == l:", "- print((0))", "- continue", "- print((power[r % D][r // D] - power[r % D][l // D]))", "+ print((grid[r] - grid[l]))" ]
false
0.130171
0.04965
2.621766
[ "s566885244", "s476684221" ]
u863370423
p02900
python
s260612400
s524590402
250
176
3,188
38,512
Accepted
Accepted
29.6
import math def primes(n): l= [] for i in range(2,math.floor(math.sqrt(n))): while n % i == 0: n = n//i l.append(i) if n == 1: break if n > 1: l.append(n) return l a,b=list(map(int,input().split())) sa=set(primes(a)) sb=set(primes(b)) sans=sa.intersection(sb) print((len(sans)+1))
def prime_factors(n): res = set() while n % 2 == 0: res.add(2) n //= 2 i = 3 while i * i <= n: if n % i == 0: res.add(i) n //= i else: i += 2 if n != 1: res.add(n) return res a, b = list(map(int, input().split())) a = prime_factors(a) b = prime_factors(b) print((len(a & b) + 1))
19
20
373
392
import math def primes(n): l = [] for i in range(2, math.floor(math.sqrt(n))): while n % i == 0: n = n // i l.append(i) if n == 1: break if n > 1: l.append(n) return l a, b = list(map(int, input().split())) sa = set(primes(a)) sb = set(primes(b)) sans = sa.intersection(sb) print((len(sans) + 1))
def prime_factors(n): res = set() while n % 2 == 0: res.add(2) n //= 2 i = 3 while i * i <= n: if n % i == 0: res.add(i) n //= i else: i += 2 if n != 1: res.add(n) return res a, b = list(map(int, input().split())) a = prime_factors(a) b = prime_factors(b) print((len(a & b) + 1))
false
5
[ "-import math", "-", "-", "-def primes(n):", "- l = []", "- for i in range(2, math.floor(math.sqrt(n))):", "- while n % i == 0:", "- n = n // i", "- l.append(i)", "- if n == 1:", "- break", "- if n > 1:", "- l.append(n)", "- return l", "+def prime_factors(n):", "+ res = set()", "+ while n % 2 == 0:", "+ res.add(2)", "+ n //= 2", "+ i = 3", "+ while i * i <= n:", "+ if n % i == 0:", "+ res.add(i)", "+ n //= i", "+ else:", "+ i += 2", "+ if n != 1:", "+ res.add(n)", "+ return res", "-sa = set(primes(a))", "-sb = set(primes(b))", "-sans = sa.intersection(sb)", "-print((len(sans) + 1))", "+a = prime_factors(a)", "+b = prime_factors(b)", "+print((len(a & b) + 1))" ]
false
0.064484
0.097862
0.658928
[ "s260612400", "s524590402" ]
u046187684
p02630
python
s959391585
s920638203
218
191
44,224
44,260
Accepted
Accepted
12.39
from collections import Counter def solve(string): n, *aqbc = list(map(int, string.split())) a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:] s = sum(a) t = Counter(a) ans = [] for b, c in zip(*[iter(bc)] * 2): s += (c - b) * t[b] t[c] += t[b] t[b] = 0 ans.append(s) return "\n".join(map(str, ans)) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
from collections import Counter def solve(string): n, *aqbc = list(map(int, string.split())) a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:] s = sum(a) t = Counter(a) ans = [] for b, c in zip(*[iter(bc)] * 2): if b not in list(t.keys()): ans.append(s) continue s += (c - b) * t[b] t[c] += t[b] t[b] = 0 ans.append(s) return "\n".join(map(str, ans)) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
20
23
455
535
from collections import Counter def solve(string): n, *aqbc = list(map(int, string.split())) a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1 :] s = sum(a) t = Counter(a) ans = [] for b, c in zip(*[iter(bc)] * 2): s += (c - b) * t[b] t[c] += t[b] t[b] = 0 ans.append(s) return "\n".join(map(str, ans)) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
from collections import Counter def solve(string): n, *aqbc = list(map(int, string.split())) a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1 :] s = sum(a) t = Counter(a) ans = [] for b, c in zip(*[iter(bc)] * 2): if b not in list(t.keys()): ans.append(s) continue s += (c - b) * t[b] t[c] += t[b] t[b] = 0 ans.append(s) return "\n".join(map(str, ans)) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
false
13.043478
[ "+ if b not in list(t.keys()):", "+ ans.append(s)", "+ continue" ]
false
0.060136
0.058104
1.034959
[ "s959391585", "s920638203" ]
u028973125
p02646
python
s206741321
s820368136
31
27
9,960
9,192
Accepted
Accepted
12.9
import sys from pprint import pprint A, V = list(map(int, sys.stdin.readline().strip().split())) B, W = list(map(int, sys.stdin.readline().strip().split())) T = int(sys.stdin.readline().strip()) d = abs(A - B) if d == 0: print("YES") elif V < W: print("NO") else: if d <= T * (V - W): print("YES") else: print("NO")
import sys A, V = list(map(int, sys.stdin.readline().split())) B, W = list(map(int, sys.stdin.readline().split())) T = int(sys.stdin.readline()) if W < V and abs(A - B) <= (V - W) * T: print("YES") else: print("NO")
17
10
353
222
import sys from pprint import pprint A, V = list(map(int, sys.stdin.readline().strip().split())) B, W = list(map(int, sys.stdin.readline().strip().split())) T = int(sys.stdin.readline().strip()) d = abs(A - B) if d == 0: print("YES") elif V < W: print("NO") else: if d <= T * (V - W): print("YES") else: print("NO")
import sys A, V = list(map(int, sys.stdin.readline().split())) B, W = list(map(int, sys.stdin.readline().split())) T = int(sys.stdin.readline()) if W < V and abs(A - B) <= (V - W) * T: print("YES") else: print("NO")
false
41.176471
[ "-from pprint import pprint", "-A, V = list(map(int, sys.stdin.readline().strip().split()))", "-B, W = list(map(int, sys.stdin.readline().strip().split()))", "-T = int(sys.stdin.readline().strip())", "-d = abs(A - B)", "-if d == 0:", "+A, V = list(map(int, sys.stdin.readline().split()))", "+B, W = list(map(int, sys.stdin.readline().split()))", "+T = int(sys.stdin.readline())", "+if W < V and abs(A - B) <= (V - W) * T:", "-elif V < W:", "+else:", "-else:", "- if d <= T * (V - W):", "- print(\"YES\")", "- else:", "- print(\"NO\")" ]
false
0.049094
0.072318
0.678865
[ "s206741321", "s820368136" ]
u644546699
p02693
python
s594003448
s770038535
21
19
9,172
9,200
Accepted
Accepted
9.52
def resolve(): K = int(eval(input())) A, B= list(map(int, input().split())) for i in range(A, B+1): if i % K == 0: print("OK") return print("NG") return if __name__ == "__main__": resolve()
import math def resolve(): K = int(eval(input())) A, B= list(map(int, input().split())) if A <= math.floor(B/K) * K: print("OK") else: print("NG") if __name__ == "__main__": resolve()
15
14
252
225
def resolve(): K = int(eval(input())) A, B = list(map(int, input().split())) for i in range(A, B + 1): if i % K == 0: print("OK") return print("NG") return if __name__ == "__main__": resolve()
import math def resolve(): K = int(eval(input())) A, B = list(map(int, input().split())) if A <= math.floor(B / K) * K: print("OK") else: print("NG") if __name__ == "__main__": resolve()
false
6.666667
[ "+import math", "+", "+", "- for i in range(A, B + 1):", "- if i % K == 0:", "- print(\"OK\")", "- return", "- print(\"NG\")", "- return", "+ if A <= math.floor(B / K) * K:", "+ print(\"OK\")", "+ else:", "+ print(\"NG\")" ]
false
0.042264
0.091633
0.461236
[ "s594003448", "s770038535" ]
u759412327
p03105
python
s983771787
s736654709
24
18
2,940
2,940
Accepted
Accepted
25
a,b,c=list(map(int,input().split())) print((min(c,b//a)))
A,B,C = list(map(int,input().split())) print((min(C,B//A)))
2
2
50
52
a, b, c = list(map(int, input().split())) print((min(c, b // a)))
A, B, C = list(map(int, input().split())) print((min(C, B // A)))
false
0
[ "-a, b, c = list(map(int, input().split()))", "-print((min(c, b // a)))", "+A, B, C = list(map(int, input().split()))", "+print((min(C, B // A)))" ]
false
0.086977
0.088841
0.979015
[ "s983771787", "s736654709" ]
u906769651
p02786
python
s800497983
s099594250
150
28
12,500
9,152
Accepted
Accepted
81.33
import numpy as np H=eval(input()) H=int(H) def count(H): count=1 while True: if int(H/2)==0: break else: H=int(H/2) count+=1 continue return count A=0 for i in range(int(count(H))): A+=2**i print(A)
# coding: utf-8 # Your code here! H=int(eval(input())) count=0 ans=0 while H>1: H=H//2 count+=1 for i in range(count+1): ans+=2**i print(ans)
20
12
238
159
import numpy as np H = eval(input()) H = int(H) def count(H): count = 1 while True: if int(H / 2) == 0: break else: H = int(H / 2) count += 1 continue return count A = 0 for i in range(int(count(H))): A += 2**i print(A)
# coding: utf-8 # Your code here! H = int(eval(input())) count = 0 ans = 0 while H > 1: H = H // 2 count += 1 for i in range(count + 1): ans += 2**i print(ans)
false
40
[ "-import numpy as np", "-", "-H = eval(input())", "-H = int(H)", "-", "-", "-def count(H):", "- count = 1", "- while True:", "- if int(H / 2) == 0:", "- break", "- else:", "- H = int(H / 2)", "- count += 1", "- continue", "- return count", "-", "-", "-A = 0", "-for i in range(int(count(H))):", "- A += 2**i", "-print(A)", "+# coding: utf-8", "+# Your code here!", "+H = int(eval(input()))", "+count = 0", "+ans = 0", "+while H > 1:", "+ H = H // 2", "+ count += 1", "+for i in range(count + 1):", "+ ans += 2**i", "+print(ans)" ]
false
0.0641
0.138299
0.463488
[ "s800497983", "s099594250" ]
u377989038
p03588
python
s537155503
s167083097
571
495
28,972
28,652
Accepted
Accepted
13.31
n = int(eval(input())) a = sorted([list(map(int, input().split())) for _ in range(n)]) cnt = a[0][0] - 1 + n + a[-1][1] for i in range(n - 1): cnt += min(a[i + 1][0] - a[i][0], a[i][1] - a[i + 1][1]) - 1 print(cnt)
n = int(eval(input())) a = sorted([list(map(int, input().split())) for _ in range(n)]) print((sum(a[-1])))
7
3
219
100
n = int(eval(input())) a = sorted([list(map(int, input().split())) for _ in range(n)]) cnt = a[0][0] - 1 + n + a[-1][1] for i in range(n - 1): cnt += min(a[i + 1][0] - a[i][0], a[i][1] - a[i + 1][1]) - 1 print(cnt)
n = int(eval(input())) a = sorted([list(map(int, input().split())) for _ in range(n)]) print((sum(a[-1])))
false
57.142857
[ "-cnt = a[0][0] - 1 + n + a[-1][1]", "-for i in range(n - 1):", "- cnt += min(a[i + 1][0] - a[i][0], a[i][1] - a[i + 1][1]) - 1", "-print(cnt)", "+print((sum(a[-1])))" ]
false
0.034186
0.045906
0.744691
[ "s537155503", "s167083097" ]
u983918956
p03805
python
s069651648
s127489344
30
25
3,064
3,064
Accepted
Accepted
16.67
N,M = list(map(int,input().split())) ad = [[0]*N for _ in range(N)] for _ in range(M): a,b = list(map(int,input().split())) a -= 1; b -= 1 ad[a][b] = 1 ad[b][a] = 1 ans = 0 def dfs(v=0,visited=[0]*N): visited[v] = 1 if all(visited): global ans ans += 1 return for nv, bit in enumerate(ad[v]): if bit == 0 or visited[nv] == 1: continue dfs(nv,visited[:]) dfs() print(ans)
N,M = list(map(int,input().split())) ad = [[] for _ in range(N)] for _ in range(M): a,b = list(map(int,input().split())) a -= 1; b -= 1 ad[a].append(b) ad[b].append(a) ans = 0 def dfs(v=0,visited=[0]*N): visited[v] = 1 if all(visited): global ans ans += 1 return for nv in ad[v]: if visited[nv] == 1: continue dfs(nv,visited[:]) dfs() print(ans)
22
22
450
425
N, M = list(map(int, input().split())) ad = [[0] * N for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 ad[a][b] = 1 ad[b][a] = 1 ans = 0 def dfs(v=0, visited=[0] * N): visited[v] = 1 if all(visited): global ans ans += 1 return for nv, bit in enumerate(ad[v]): if bit == 0 or visited[nv] == 1: continue dfs(nv, visited[:]) dfs() print(ans)
N, M = list(map(int, input().split())) ad = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 ad[a].append(b) ad[b].append(a) ans = 0 def dfs(v=0, visited=[0] * N): visited[v] = 1 if all(visited): global ans ans += 1 return for nv in ad[v]: if visited[nv] == 1: continue dfs(nv, visited[:]) dfs() print(ans)
false
0
[ "-ad = [[0] * N for _ in range(N)]", "+ad = [[] for _ in range(N)]", "- ad[a][b] = 1", "- ad[b][a] = 1", "+ ad[a].append(b)", "+ ad[b].append(a)", "- for nv, bit in enumerate(ad[v]):", "- if bit == 0 or visited[nv] == 1:", "+ for nv in ad[v]:", "+ if visited[nv] == 1:" ]
false
0.113722
0.041822
2.719177
[ "s069651648", "s127489344" ]
u367130284
p03338
python
s211616330
s722813548
19
17
2,940
2,940
Accepted
Accepted
10.53
n,a=open(0).read().split();a,l=list(a),[] for s in range(1,len(a)):l.append(len(set(a[:s])&set(a[s:]))) print((max(l)))
n,a=eval(input()),eval(input());print((max(len(set(a[:s])&set(a[s:]))for s in range(len(a)))))
3
1
119
80
n, a = open(0).read().split() a, l = list(a), [] for s in range(1, len(a)): l.append(len(set(a[:s]) & set(a[s:]))) print((max(l)))
n, a = eval(input()), eval(input()) print((max(len(set(a[:s]) & set(a[s:])) for s in range(len(a)))))
false
66.666667
[ "-n, a = open(0).read().split()", "-a, l = list(a), []", "-for s in range(1, len(a)):", "- l.append(len(set(a[:s]) & set(a[s:])))", "-print((max(l)))", "+n, a = eval(input()), eval(input())", "+print((max(len(set(a[:s]) & set(a[s:])) for s in range(len(a)))))" ]
false
0.050288
0.069383
0.724779
[ "s211616330", "s722813548" ]
u784022244
p02732
python
s005266337
s288581093
436
355
27,024
26,140
Accepted
Accepted
18.58
from operator import mul from functools import reduce def cmb(n): return n*(n-1)//2 N=int(eval(input())) A=list(map(int, input().split())) #インデックス0は除外 count=[0]*(N+1) for a in A: count[a]+=1 cmbs=[0]*N for i,c in enumerate(count): if i==0: continue cmbs[i-1]=cmb(c) SUM=sum(cmbs) for i in range(N): a=A[i] #print(cmbs[a-1]) ans=SUM-cmbs[a-1]+cmb(count[a]-1) print(ans) #print(count, cmbs)
N=int(eval(input())) A=list(map(int, input().split())) L=[0]*(max(A)+1) for a in A: L[a]+=1 #print(L) SUM=0 for l in L: SUM+=l*(l-1)//2 for a in A: l=L[a] print((SUM-l*(l-1)//2+(l-1)*(l-2)//2))
27
14
436
212
from operator import mul from functools import reduce def cmb(n): return n * (n - 1) // 2 N = int(eval(input())) A = list(map(int, input().split())) # インデックス0は除外 count = [0] * (N + 1) for a in A: count[a] += 1 cmbs = [0] * N for i, c in enumerate(count): if i == 0: continue cmbs[i - 1] = cmb(c) SUM = sum(cmbs) for i in range(N): a = A[i] # print(cmbs[a-1]) ans = SUM - cmbs[a - 1] + cmb(count[a] - 1) print(ans) # print(count, cmbs)
N = int(eval(input())) A = list(map(int, input().split())) L = [0] * (max(A) + 1) for a in A: L[a] += 1 # print(L) SUM = 0 for l in L: SUM += l * (l - 1) // 2 for a in A: l = L[a] print((SUM - l * (l - 1) // 2 + (l - 1) * (l - 2) // 2))
false
48.148148
[ "-from operator import mul", "-from functools import reduce", "-", "-", "-def cmb(n):", "- return n * (n - 1) // 2", "-", "-", "-# インデックス0は除外", "-count = [0] * (N + 1)", "+L = [0] * (max(A) + 1)", "- count[a] += 1", "-cmbs = [0] * N", "-for i, c in enumerate(count):", "- if i == 0:", "- continue", "- cmbs[i - 1] = cmb(c)", "-SUM = sum(cmbs)", "-for i in range(N):", "- a = A[i]", "- # print(cmbs[a-1])", "- ans = SUM - cmbs[a - 1] + cmb(count[a] - 1)", "- print(ans)", "-# print(count, cmbs)", "+ L[a] += 1", "+# print(L)", "+SUM = 0", "+for l in L:", "+ SUM += l * (l - 1) // 2", "+for a in A:", "+ l = L[a]", "+ print((SUM - l * (l - 1) // 2 + (l - 1) * (l - 2) // 2))" ]
false
0.050111
0.050459
0.993102
[ "s005266337", "s288581093" ]
u600402037
p03715
python
s521132956
s920365830
21
18
3,316
3,064
Accepted
Accepted
14.29
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) H, W = lr() if H%3==0 or W%3==0: answer = 0 else: answer = min(H, W) # さらに小さくするには縦と横で割る h = H // 3 area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)] answer = min(answer, max(area)-min(area)) h += 1 area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)] answer = min(answer, max(area)-min(area)) w = W // 3 area = [w * H, (W-w) * (H//2), (W-w) * ((H+1)//2)] answer = min(answer, max(area)-min(area)) w += 1 area = [w * H, (W-w) * (H//2), (W-w) * ((H+1)//2)] answer = min(answer, max(area)-min(area)) print(answer) # 13
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) H, W = lr() if H%3==0 or W%3==0: answer = 0 else: answer = min(H, W) # さらに小さくするには縦と横で割る def cal(H, W): global answer h = H // 3 area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)] answer = min(answer, max(area)-min(area)) h += 1 area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)] answer = min(answer, max(area)-min(area)) cal(H, W) cal(W, H) print(answer) # 13
27
25
670
541
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) H, W = lr() if H % 3 == 0 or W % 3 == 0: answer = 0 else: answer = min(H, W) # さらに小さくするには縦と横で割る h = H // 3 area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)] answer = min(answer, max(area) - min(area)) h += 1 area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)] answer = min(answer, max(area) - min(area)) w = W // 3 area = [w * H, (W - w) * (H // 2), (W - w) * ((H + 1) // 2)] answer = min(answer, max(area) - min(area)) w += 1 area = [w * H, (W - w) * (H // 2), (W - w) * ((H + 1) // 2)] answer = min(answer, max(area) - min(area)) print(answer) # 13
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) H, W = lr() if H % 3 == 0 or W % 3 == 0: answer = 0 else: answer = min(H, W) # さらに小さくするには縦と横で割る def cal(H, W): global answer h = H // 3 area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)] answer = min(answer, max(area) - min(area)) h += 1 area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)] answer = min(answer, max(area) - min(area)) cal(H, W) cal(W, H) print(answer) # 13
false
7.407407
[ "-h = H // 3", "-area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)]", "-answer = min(answer, max(area) - min(area))", "-h += 1", "-area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)]", "-answer = min(answer, max(area) - min(area))", "-w = W // 3", "-area = [w * H, (W - w) * (H // 2), (W - w) * ((H + 1) // 2)]", "-answer = min(answer, max(area) - min(area))", "-w += 1", "-area = [w * H, (W - w) * (H // 2), (W - w) * ((H + 1) // 2)]", "-answer = min(answer, max(area) - min(area))", "+def cal(H, W):", "+ global answer", "+ h = H // 3", "+ area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)]", "+ answer = min(answer, max(area) - min(area))", "+ h += 1", "+ area = [h * W, (H - h) * (W // 2), (H - h) * ((W + 1) // 2)]", "+ answer = min(answer, max(area) - min(area))", "+", "+", "+cal(H, W)", "+cal(W, H)" ]
false
0.048869
0.048976
0.997831
[ "s521132956", "s920365830" ]
u506858457
p03163
python
s972594167
s994157270
150
134
68,208
67,072
Accepted
Accepted
10.67
import sys input = sys.stdin.readline n,w = list(map(int,input().split())) wv = [tuple(map(int,input().split())) for i in range(n)] dp = [0]*(w+1) for i in range(n): for j in range(w,wv[i][0]-1,-1): dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1]) print((max(dp)))
def MI(): return list(map(int, input().split())) import sys input = sys.stdin.readline n,w = list(map(int,input().split())) #wv = [tuple(map(int,input().split())) for i in range(n)] W=[] V=[] for i in range(n): a,b=MI() W.append(a) V.append(b) dp = [0]*(w+1) for i in range(n): for j in range(w,W[i]-1,-1): dp[j] = max(dp[j],dp[j-W[i]]+V[i]) print((max(dp)))
11
16
274
377
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) wv = [tuple(map(int, input().split())) for i in range(n)] dp = [0] * (w + 1) for i in range(n): for j in range(w, wv[i][0] - 1, -1): dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1]) print((max(dp)))
def MI(): return list(map(int, input().split())) import sys input = sys.stdin.readline n, w = list(map(int, input().split())) # wv = [tuple(map(int,input().split())) for i in range(n)] W = [] V = [] for i in range(n): a, b = MI() W.append(a) V.append(b) dp = [0] * (w + 1) for i in range(n): for j in range(w, W[i] - 1, -1): dp[j] = max(dp[j], dp[j - W[i]] + V[i]) print((max(dp)))
false
31.25
[ "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "-wv = [tuple(map(int, input().split())) for i in range(n)]", "+# wv = [tuple(map(int,input().split())) for i in range(n)]", "+W = []", "+V = []", "+for i in range(n):", "+ a, b = MI()", "+ W.append(a)", "+ V.append(b)", "- for j in range(w, wv[i][0] - 1, -1):", "- dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1])", "+ for j in range(w, W[i] - 1, -1):", "+ dp[j] = max(dp[j], dp[j - W[i]] + V[i])" ]
false
0.046415
0.109268
0.424777
[ "s972594167", "s994157270" ]
u923662841
p02630
python
s796659580
s132265373
562
147
23,924
44,004
Accepted
Accepted
73.84
import collections N = int(eval(input())) A = list(map(int, input().split())) S = sum(A) Q = int(eval(input())) T = collections.Counter(A) for i in range(Q): b, c = list(map(int, input().split())) S += T[b]*(c-b) T[c] += T[b] T[b] = 0 print(S)
def main(): n, *i = list(map(int, open(0).read().split())) a = i[:n] _ = i[n] s = sum(a) m = [0] * (10 ** 5 + 1) for x in a: m[x] += 1 ans = [] for b, c in zip(*[iter(i[n + 1:])] * 2): m[c] += m[b] s += (c - b) * m[b] m[b] = 0 ans.append(s) print(("\n".join(map(str, ans)))) if __name__ == '__main__': main()
13
21
258
404
import collections N = int(eval(input())) A = list(map(int, input().split())) S = sum(A) Q = int(eval(input())) T = collections.Counter(A) for i in range(Q): b, c = list(map(int, input().split())) S += T[b] * (c - b) T[c] += T[b] T[b] = 0 print(S)
def main(): n, *i = list(map(int, open(0).read().split())) a = i[:n] _ = i[n] s = sum(a) m = [0] * (10**5 + 1) for x in a: m[x] += 1 ans = [] for b, c in zip(*[iter(i[n + 1 :])] * 2): m[c] += m[b] s += (c - b) * m[b] m[b] = 0 ans.append(s) print(("\n".join(map(str, ans)))) if __name__ == "__main__": main()
false
38.095238
[ "-import collections", "+def main():", "+ n, *i = list(map(int, open(0).read().split()))", "+ a = i[:n]", "+ _ = i[n]", "+ s = sum(a)", "+ m = [0] * (10**5 + 1)", "+ for x in a:", "+ m[x] += 1", "+ ans = []", "+ for b, c in zip(*[iter(i[n + 1 :])] * 2):", "+ m[c] += m[b]", "+ s += (c - b) * m[b]", "+ m[b] = 0", "+ ans.append(s)", "+ print((\"\\n\".join(map(str, ans))))", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-S = sum(A)", "-Q = int(eval(input()))", "-T = collections.Counter(A)", "-for i in range(Q):", "- b, c = list(map(int, input().split()))", "- S += T[b] * (c - b)", "- T[c] += T[b]", "- T[b] = 0", "- print(S)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.048005
0.037081
1.294615
[ "s796659580", "s132265373" ]
u386249594
p03073
python
s856297623
s710023474
62
43
4,060
5,408
Accepted
Accepted
30.65
S = eval(input()) l = "01" * (len(S)//2) + ("0" if len(S)%2 == 1 else "") l = [int(x) + int(y) for (x,y) in zip(S,l)] print((min(l.count(1),(l.count(0)+l.count(2)))))
S = list(map(int,eval(input()))) l =[0,1] * (len(S)//2) + ([0] if len(S)%2 == 1 else []) l = [x + y for (x,y) in zip(S,l)] print((min(l.count(1),(l.count(0)+l.count(2)))))
7
7
168
173
S = eval(input()) l = "01" * (len(S) // 2) + ("0" if len(S) % 2 == 1 else "") l = [int(x) + int(y) for (x, y) in zip(S, l)] print((min(l.count(1), (l.count(0) + l.count(2)))))
S = list(map(int, eval(input()))) l = [0, 1] * (len(S) // 2) + ([0] if len(S) % 2 == 1 else []) l = [x + y for (x, y) in zip(S, l)] print((min(l.count(1), (l.count(0) + l.count(2)))))
false
0
[ "-S = eval(input())", "-l = \"01\" * (len(S) // 2) + (\"0\" if len(S) % 2 == 1 else \"\")", "-l = [int(x) + int(y) for (x, y) in zip(S, l)]", "+S = list(map(int, eval(input())))", "+l = [0, 1] * (len(S) // 2) + ([0] if len(S) % 2 == 1 else [])", "+l = [x + y for (x, y) in zip(S, l)]" ]
false
0.034766
0.067413
0.515719
[ "s856297623", "s710023474" ]
u706414019
p02756
python
s601092647
s825569034
900
314
9,932
14,248
Accepted
Accepted
65.11
s = eval(input()) Q = int(eval(input())) rev_count = 0 sbf='' saf='' for i in range(Q): que = eval(input()) if que[0] == '1': rev_count +=1 elif que[0] == '2': if (rev_count + int(que[2]))%2 == 0: saf = saf + que[4] else: sbf = que[4] + sbf print((sbf+s+saf if rev_count %2 == 0 else (sbf+s+saf)[-1::-1]))
from collections import deque s = eval(input()) Q = int(eval(input())) SS =deque(list(s)) rev_count = 0 for i in range(Q): que = eval(input()) if que[0] == '1': rev_count +=1 elif que[0] == '2': if (rev_count + int(que[2]))%2 == 0: SS.append(que[4]) else: SS.appendleft(que[4]) print(("".join(SS) if rev_count %2 == 0 else ("".join(SS))[-1::-1]))
17
18
364
407
s = eval(input()) Q = int(eval(input())) rev_count = 0 sbf = "" saf = "" for i in range(Q): que = eval(input()) if que[0] == "1": rev_count += 1 elif que[0] == "2": if (rev_count + int(que[2])) % 2 == 0: saf = saf + que[4] else: sbf = que[4] + sbf print((sbf + s + saf if rev_count % 2 == 0 else (sbf + s + saf)[-1::-1]))
from collections import deque s = eval(input()) Q = int(eval(input())) SS = deque(list(s)) rev_count = 0 for i in range(Q): que = eval(input()) if que[0] == "1": rev_count += 1 elif que[0] == "2": if (rev_count + int(que[2])) % 2 == 0: SS.append(que[4]) else: SS.appendleft(que[4]) print(("".join(SS) if rev_count % 2 == 0 else ("".join(SS))[-1::-1]))
false
5.555556
[ "+from collections import deque", "+", "+SS = deque(list(s))", "-sbf = \"\"", "-saf = \"\"", "- saf = saf + que[4]", "+ SS.append(que[4])", "- sbf = que[4] + sbf", "-print((sbf + s + saf if rev_count % 2 == 0 else (sbf + s + saf)[-1::-1]))", "+ SS.appendleft(que[4])", "+print((\"\".join(SS) if rev_count % 2 == 0 else (\"\".join(SS))[-1::-1]))" ]
false
0.035646
0.050757
0.702286
[ "s601092647", "s825569034" ]
u875291233
p02564
python
s097131683
s708668677
1,535
1,405
237,316
232,608
Accepted
Accepted
8.47
def SCC_Tarjan(g): def dfs(v): nonlocal idx used[v] = 1 pre[v] = low[v] = idx idx += 1 S.append(v) onS[v] = 1 for c in g[v]: if not used[c]: dfs(c) low[v] = min(low[v], low[c]) elif onS[c]: low[v] = min(low[v], pre[c]) used[v] = 2 if low[v] == pre[v]: cc = [] while True: w = S.pop() onS[w] = 0 cc.append(w) if w==v: break scc.append(cc) n = len(g) used = [0]*n # 0 -> 1 -> 2 pre = [0]*n low = [0]*n onS = [0]*n idx = 0 S = [] scc = [] for i in range(n): if not used[i]: dfs(i) #print(g) #print("idx",pre) #print("low",low) #print(scc) return scc ########################################################################### ########################################################################### # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**6) #n,*w = [int(i) for i in read().split()] n,m = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for _ in range(m): a,b = list(map(int, readline().split())) g[a].append(b) gp = SCC_Tarjan(g) print((len(gp))) for lst in gp[::-1]: print((*([len(lst)]+lst)))
def SCC_Tarjan(g): def dfs(v): nonlocal idx pre[v] = low[v] = idx idx += 1 S.append(v) #onS[v] = 1 for c in g[v]: if pre[c] == -1: dfs(c) low[v] = min(low[v], low[c]) #elif onS[c]: else: low[v] = min(low[v], pre[c]) if low[v] == pre[v]: cc = [] while True: w = S.pop() #onS[w] = 0 pre[w] = n cc.append(w) if w==v: break scc.append(cc) n = len(g) pre = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited low = [0]*n onS = [0]*n idx = 0 S = [] scc = [] for i in range(n): if pre[i] == -1: dfs(i) #print(g) #print("idx",pre) #print("low",low) #print(scc) return scc ########################################################################### ########################################################################### # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**6) #n,*w = [int(i) for i in read().split()] n,m = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for _ in range(m): a,b = list(map(int, readline().split())) g[a].append(b) gp = SCC_Tarjan(g) print((len(gp))) for lst in gp[::-1]: print((*([len(lst)]+lst)))
67
66
1,557
1,581
def SCC_Tarjan(g): def dfs(v): nonlocal idx used[v] = 1 pre[v] = low[v] = idx idx += 1 S.append(v) onS[v] = 1 for c in g[v]: if not used[c]: dfs(c) low[v] = min(low[v], low[c]) elif onS[c]: low[v] = min(low[v], pre[c]) used[v] = 2 if low[v] == pre[v]: cc = [] while True: w = S.pop() onS[w] = 0 cc.append(w) if w == v: break scc.append(cc) n = len(g) used = [0] * n # 0 -> 1 -> 2 pre = [0] * n low = [0] * n onS = [0] * n idx = 0 S = [] scc = [] for i in range(n): if not used[i]: dfs(i) # print(g) # print("idx",pre) # print("low",low) # print(scc) return scc ########################################################################### ########################################################################### # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**6) # n,*w = [int(i) for i in read().split()] n, m = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, readline().split())) g[a].append(b) gp = SCC_Tarjan(g) print((len(gp))) for lst in gp[::-1]: print((*([len(lst)] + lst)))
def SCC_Tarjan(g): def dfs(v): nonlocal idx pre[v] = low[v] = idx idx += 1 S.append(v) # onS[v] = 1 for c in g[v]: if pre[c] == -1: dfs(c) low[v] = min(low[v], low[c]) # elif onS[c]: else: low[v] = min(low[v], pre[c]) if low[v] == pre[v]: cc = [] while True: w = S.pop() # onS[w] = 0 pre[w] = n cc.append(w) if w == v: break scc.append(cc) n = len(g) pre = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited low = [0] * n onS = [0] * n idx = 0 S = [] scc = [] for i in range(n): if pre[i] == -1: dfs(i) # print(g) # print("idx",pre) # print("low",low) # print(scc) return scc ########################################################################### ########################################################################### # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**6) # n,*w = [int(i) for i in read().split()] n, m = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, readline().split())) g[a].append(b) gp = SCC_Tarjan(g) print((len(gp))) for lst in gp[::-1]: print((*([len(lst)] + lst)))
false
1.492537
[ "- used[v] = 1", "- onS[v] = 1", "+ # onS[v] = 1", "- if not used[c]:", "+ if pre[c] == -1:", "- elif onS[c]:", "+ # elif onS[c]:", "+ else:", "- used[v] = 2", "- onS[w] = 0", "+ # onS[w] = 0", "+ pre[w] = n", "- used = [0] * n # 0 -> 1 -> 2", "- pre = [0] * n", "+ pre = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited", "- if not used[i]:", "+ if pre[i] == -1:" ]
false
0.048215
0.038054
1.267017
[ "s097131683", "s708668677" ]
u867320886
p03112
python
s132766103
s170210957
576
495
36,612
38,636
Accepted
Accepted
14.06
from bisect import bisect_left a,b,q,*stx = list(map(int,open(0).read().split())) s = [-1e10] + stx[:a] + [2*1e10] t = [-1e10] + stx[a:-q] + [2*1e10] x = stx[-q:] for i in x: pos_s = bisect_left(s,i) pos_t = bisect_left(t,i) sl = s[pos_s-1]; sr = s[pos_s] tl = t[pos_t-1]; tr = t[pos_t] ans = min( i-min(sl,tl), max(sr,tr)-i, (sr*2-i-tl), (tr*2-i-sl), (i+tr-sl*2), (i+sr-tl*2) ) print(ans)
from bisect import bisect def main(): a,b,q,*stx = list(map(int,open(0).read().split())) s = [-1e10] + stx[:a] + [2*1e10] t = [-1e10] + stx[a:a+b] + [2*1e10] x = stx[a+b:a+b+q] for i in x: pos_s = bisect(s,i) pos_t = bisect(t,i) sl = s[pos_s-1]; sr = s[pos_s] tl = t[pos_t-1]; tr = t[pos_t] ans = min( i-min(sl,tl), max(sr,tr)-i, (sr-i) + (sr-tl), (tr-i) + (tr-sl), (i-sl) + (tr-sl), (i-tl) + (sr-tl) ) print(ans) if __name__ == '__main__': main()
12
17
418
531
from bisect import bisect_left a, b, q, *stx = list(map(int, open(0).read().split())) s = [-1e10] + stx[:a] + [2 * 1e10] t = [-1e10] + stx[a:-q] + [2 * 1e10] x = stx[-q:] for i in x: pos_s = bisect_left(s, i) pos_t = bisect_left(t, i) sl = s[pos_s - 1] sr = s[pos_s] tl = t[pos_t - 1] tr = t[pos_t] ans = min( i - min(sl, tl), max(sr, tr) - i, (sr * 2 - i - tl), (tr * 2 - i - sl), (i + tr - sl * 2), (i + sr - tl * 2), ) print(ans)
from bisect import bisect def main(): a, b, q, *stx = list(map(int, open(0).read().split())) s = [-1e10] + stx[:a] + [2 * 1e10] t = [-1e10] + stx[a : a + b] + [2 * 1e10] x = stx[a + b : a + b + q] for i in x: pos_s = bisect(s, i) pos_t = bisect(t, i) sl = s[pos_s - 1] sr = s[pos_s] tl = t[pos_t - 1] tr = t[pos_t] ans = min( i - min(sl, tl), max(sr, tr) - i, (sr - i) + (sr - tl), (tr - i) + (tr - sl), (i - sl) + (tr - sl), (i - tl) + (sr - tl), ) print(ans) if __name__ == "__main__": main()
false
29.411765
[ "-from bisect import bisect_left", "+from bisect import bisect", "-a, b, q, *stx = list(map(int, open(0).read().split()))", "-s = [-1e10] + stx[:a] + [2 * 1e10]", "-t = [-1e10] + stx[a:-q] + [2 * 1e10]", "-x = stx[-q:]", "-for i in x:", "- pos_s = bisect_left(s, i)", "- pos_t = bisect_left(t, i)", "- sl = s[pos_s - 1]", "- sr = s[pos_s]", "- tl = t[pos_t - 1]", "- tr = t[pos_t]", "- ans = min(", "- i - min(sl, tl),", "- max(sr, tr) - i,", "- (sr * 2 - i - tl),", "- (tr * 2 - i - sl),", "- (i + tr - sl * 2),", "- (i + sr - tl * 2),", "- )", "- print(ans)", "+", "+def main():", "+ a, b, q, *stx = list(map(int, open(0).read().split()))", "+ s = [-1e10] + stx[:a] + [2 * 1e10]", "+ t = [-1e10] + stx[a : a + b] + [2 * 1e10]", "+ x = stx[a + b : a + b + q]", "+ for i in x:", "+ pos_s = bisect(s, i)", "+ pos_t = bisect(t, i)", "+ sl = s[pos_s - 1]", "+ sr = s[pos_s]", "+ tl = t[pos_t - 1]", "+ tr = t[pos_t]", "+ ans = min(", "+ i - min(sl, tl),", "+ max(sr, tr) - i,", "+ (sr - i) + (sr - tl),", "+ (tr - i) + (tr - sl),", "+ (i - sl) + (tr - sl),", "+ (i - tl) + (sr - tl),", "+ )", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.066326
0.06522
1.016956
[ "s132766103", "s170210957" ]
u585482323
p03128
python
s082647829
s649438597
1,860
990
236,680
476,168
Accepted
Accepted
46.77
#!usr/bin/env python3 from collections import defaultdict import math import bisect import random def LI(): return list(map(int, input().split())) def II(): return int(eval(input())) def LS(): return input().split() def S(): return list(eval(input())) def IIR(n): return [II() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] mod = 1000000007 #A """ a,b = LI() if b % a == 0: print(a+b) else: print(b-a) """ #B """ n,m = LI() lis = [0 for i in range(m)] for i in range(n): k = LI() for j in k[1:]: lis[j-1] += 1 ans = 0 for i in lis: if i == n:ans += 1 print(ans) """ #C """ def gcd(a,b): if a == 0: return b return gcd(b%a,a) n = II() a = LI() ans = a[0] for i in range(1,n): ans = gcd(ans,a[i]) print(ans) """ #D n,m = LI() a = LI() f = [0,2,5,5,4,5,6,3,7,6] for i in range(m): a[i] = [a[i],f[a[i]]] a.sort(key = lambda x:x[1]) dp = [[] for i in range(n+10)] for i in a: dp[i[1]] = [i[0]] for i in range(n+1): for j in a: if i-j[1] >= 0 and len(dp[i-j[1]]) > 0: if len(dp[i]) < len(dp[i-j[1]])+1: dp[i] = dp[i-j[1]]+[j[0]] dp[i].sort() dp[i] = dp[i][::-1] else: if len(dp[i]) == len(dp[i-j[1]])+1: d = sorted(dp[i-j[1]]+[j[0]]) d = d[::-1] k = [dp[i],d] k.sort() if k[1] == d: dp[i] = d ans = 0 k = 1 l = len(dp[n]) for i in range(l): ans += k*dp[n][l-i-1] k *= 10 print(ans) #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): a,b = LI() if b%a == 0: print((a+b)) else: print((b-a)) return #B def B(): n,m = LI() d = defaultdict(int) for i in range(n): l = LI() for j in range(1,len(l)): d[l[j]] += 1 ans = 0 for i in list(d.values()): if i == n: ans += 1 print(ans) return #C def C(): def gcd(a,b): if a == 0: return b return gcd(b%a,a) n = I() a = LI() g = a[0] for i in range(1,n): g = gcd(g,a[i]) print(g) return #D def D(): n,m = LI() a = LI() f = [0,2,5,5,4,5,6,3,7,6] dp = [None for i in range(n+1)] dp[0] = [] for j in a: for i in range(n+1): if i-f[j] >= 0 and dp[i-f[j]] != None: if dp[i] == None: dp[i] = dp[i-f[j]]+[j] dp[i].sort(reverse = True) elif len(dp[i]) < len(dp[i-f[j]])+1: dp[i] = dp[i-f[j]]+[j] dp[i].sort(reverse = True) elif len(dp[i]) == len(dp[i-f[j]])+1: d = dp[i-f[j]]+[j] d.sort(reverse = True) if dp[i] < d: dp[i] = d ans = 0 k = pow(10,len(dp[n])-1) for i in range(len(dp[n])): ans += k*dp[n][i] k //= 10 print(ans) return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": D()
115
117
1,792
2,454
#!usr/bin/env python3 from collections import defaultdict import math import bisect import random def LI(): return list(map(int, input().split())) def II(): return int(eval(input())) def LS(): return input().split() def S(): return list(eval(input())) def IIR(n): return [II() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] mod = 1000000007 # A """ a,b = LI() if b % a == 0: print(a+b) else: print(b-a) """ # B """ n,m = LI() lis = [0 for i in range(m)] for i in range(n): k = LI() for j in k[1:]: lis[j-1] += 1 ans = 0 for i in lis: if i == n:ans += 1 print(ans) """ # C """ def gcd(a,b): if a == 0: return b return gcd(b%a,a) n = II() a = LI() ans = a[0] for i in range(1,n): ans = gcd(ans,a[i]) print(ans) """ # D n, m = LI() a = LI() f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] for i in range(m): a[i] = [a[i], f[a[i]]] a.sort(key=lambda x: x[1]) dp = [[] for i in range(n + 10)] for i in a: dp[i[1]] = [i[0]] for i in range(n + 1): for j in a: if i - j[1] >= 0 and len(dp[i - j[1]]) > 0: if len(dp[i]) < len(dp[i - j[1]]) + 1: dp[i] = dp[i - j[1]] + [j[0]] dp[i].sort() dp[i] = dp[i][::-1] else: if len(dp[i]) == len(dp[i - j[1]]) + 1: d = sorted(dp[i - j[1]] + [j[0]]) d = d[::-1] k = [dp[i], d] k.sort() if k[1] == d: dp[i] = d ans = 0 k = 1 l = len(dp[n]) for i in range(l): ans += k * dp[n][l - i - 1] k *= 10 print(ans) # E # F # G # H # I # J # K # L # M # N # O # P # Q # R # S # T
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l sys.setrecursionlimit(1000000) mod = 1000000007 # A def A(): a, b = LI() if b % a == 0: print((a + b)) else: print((b - a)) return # B def B(): n, m = LI() d = defaultdict(int) for i in range(n): l = LI() for j in range(1, len(l)): d[l[j]] += 1 ans = 0 for i in list(d.values()): if i == n: ans += 1 print(ans) return # C def C(): def gcd(a, b): if a == 0: return b return gcd(b % a, a) n = I() a = LI() g = a[0] for i in range(1, n): g = gcd(g, a[i]) print(g) return # D def D(): n, m = LI() a = LI() f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [None for i in range(n + 1)] dp[0] = [] for j in a: for i in range(n + 1): if i - f[j] >= 0 and dp[i - f[j]] != None: if dp[i] == None: dp[i] = dp[i - f[j]] + [j] dp[i].sort(reverse=True) elif len(dp[i]) < len(dp[i - f[j]]) + 1: dp[i] = dp[i - f[j]] + [j] dp[i].sort(reverse=True) elif len(dp[i]) == len(dp[i - f[j]]) + 1: d = dp[i - f[j]] + [j] d.sort(reverse=True) if dp[i] < d: dp[i] = d ans = 0 k = pow(10, len(dp[n]) - 1) for i in range(len(dp[n])): ans += k * dp[n][i] k //= 10 print(ans) return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": D()
false
1.709402
[ "+from collections import deque", "+from heapq import heappush, heappop", "+import sys", "- return list(map(int, input().split()))", "+ return list(map(int, sys.stdin.readline().split()))", "-def II():", "- return int(eval(input()))", "+def I():", "+ return int(sys.stdin.readline())", "- return input().split()", "+ return list(map(list, sys.stdin.readline().split()))", "- return list(eval(input()))", "+ return list(sys.stdin.readline())[:-1]", "-def IIR(n):", "- return [II() for i in range(n)]", "+def IR(n):", "+ l = [None for i in range(n)]", "+ for i in range(n):", "+ l[i] = I()", "+ return l", "- return [LI() for i in range(n)]", "+ l = [None for i in range(n)]", "+ for i in range(n):", "+ l[i] = LI()", "+ return l", "- return [S() for i in range(n)]", "+ l = [None for i in range(n)]", "+ for i in range(n):", "+ l[i] = S()", "+ return l", "+def LSR(n):", "+ l = [None for i in range(n)]", "+ for i in range(n):", "+ l[i] = SR()", "+ return l", "+", "+", "+sys.setrecursionlimit(1000000)", "-\"\"\"", "-a,b = LI()", "-if b % a == 0:", "- print(a+b)", "-else:", "- print(b-a)", "-\"\"\"", "+def A():", "+ a, b = LI()", "+ if b % a == 0:", "+ print((a + b))", "+ else:", "+ print((b - a))", "+ return", "+", "+", "-\"\"\"", "-n,m = LI()", "-lis = [0 for i in range(m)]", "-for i in range(n):", "- k = LI()", "- for j in k[1:]:", "- lis[j-1] += 1", "-ans = 0", "-for i in lis:", "- if i == n:ans += 1", "-print(ans)", "-\"\"\"", "+def B():", "+ n, m = LI()", "+ d = defaultdict(int)", "+ for i in range(n):", "+ l = LI()", "+ for j in range(1, len(l)):", "+ d[l[j]] += 1", "+ ans = 0", "+ for i in list(d.values()):", "+ if i == n:", "+ ans += 1", "+ print(ans)", "+ return", "+", "+", "-\"\"\"", "-def gcd(a,b):", "- if a == 0:", "- return b", "- return gcd(b%a,a)", "-n = II()", "-a = LI()", "-ans = a[0]", "-for i in range(1,n):", "- ans = gcd(ans,a[i])", "-print(ans)", "-\"\"\"", "+def C():", "+ def gcd(a, b):", "+ if a == 0:", "+ return b", "+ return gcd(b % a, a)", "+", "+ n = I()", "+ a = LI()", "+ g = a[0]", "+ for i in range(1, n):", "+ g = gcd(g, a[i])", "+ print(g)", "+ return", "+", "+", "-n, m = LI()", "-a = LI()", "-f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "-for i in range(m):", "- a[i] = [a[i], f[a[i]]]", "-a.sort(key=lambda x: x[1])", "-dp = [[] for i in range(n + 10)]", "-for i in a:", "- dp[i[1]] = [i[0]]", "-for i in range(n + 1):", "+def D():", "+ n, m = LI()", "+ a = LI()", "+ f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "+ dp = [None for i in range(n + 1)]", "+ dp[0] = []", "- if i - j[1] >= 0 and len(dp[i - j[1]]) > 0:", "- if len(dp[i]) < len(dp[i - j[1]]) + 1:", "- dp[i] = dp[i - j[1]] + [j[0]]", "- dp[i].sort()", "- dp[i] = dp[i][::-1]", "- else:", "- if len(dp[i]) == len(dp[i - j[1]]) + 1:", "- d = sorted(dp[i - j[1]] + [j[0]])", "- d = d[::-1]", "- k = [dp[i], d]", "- k.sort()", "- if k[1] == d:", "+ for i in range(n + 1):", "+ if i - f[j] >= 0 and dp[i - f[j]] != None:", "+ if dp[i] == None:", "+ dp[i] = dp[i - f[j]] + [j]", "+ dp[i].sort(reverse=True)", "+ elif len(dp[i]) < len(dp[i - f[j]]) + 1:", "+ dp[i] = dp[i - f[j]] + [j]", "+ dp[i].sort(reverse=True)", "+ elif len(dp[i]) == len(dp[i - f[j]]) + 1:", "+ d = dp[i - f[j]] + [j]", "+ d.sort(reverse=True)", "+ if dp[i] < d:", "-ans = 0", "-k = 1", "-l = len(dp[n])", "-for i in range(l):", "- ans += k * dp[n][l - i - 1]", "- k *= 10", "-print(ans)", "+ ans = 0", "+ k = pow(10, len(dp[n]) - 1)", "+ for i in range(len(dp[n])):", "+ ans += k * dp[n][i]", "+ k //= 10", "+ print(ans)", "+ return", "+", "+", "+def E():", "+ return", "+", "+", "+def F():", "+ return", "+", "+", "+def G():", "+ return", "+", "+", "-# I", "-# J", "-# K", "-# L", "-# M", "-# N", "-# O", "-# P", "-# Q", "-# R", "-# S", "-# T", "+def H():", "+ return", "+", "+", "+# Solve", "+if __name__ == \"__main__\":", "+ D()" ]
false
0.063551
0.090456
0.702566
[ "s082647829", "s649438597" ]
u814986259
p03721
python
s122408559
s694815908
485
425
29,864
18,616
Accepted
Accepted
12.37
N,K=list(map(int,input().split())) ab=[[0]*2 for i in range(N)] for i in range(N): ab[i]=list(map(int,input().split())) ab=sorted(ab,key=lambda x:x[0]) i=-1 while(K > 0): i+=1 K -= ab[i][1] print((ab[i][0]))
N, K = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for i in range(N)] ab.sort() id = 0 for a, b in ab: if id + b >= K: print(a) break else: id += b
12
12
220
214
N, K = list(map(int, input().split())) ab = [[0] * 2 for i in range(N)] for i in range(N): ab[i] = list(map(int, input().split())) ab = sorted(ab, key=lambda x: x[0]) i = -1 while K > 0: i += 1 K -= ab[i][1] print((ab[i][0]))
N, K = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for i in range(N)] ab.sort() id = 0 for a, b in ab: if id + b >= K: print(a) break else: id += b
false
0
[ "-ab = [[0] * 2 for i in range(N)]", "-for i in range(N):", "- ab[i] = list(map(int, input().split()))", "-ab = sorted(ab, key=lambda x: x[0])", "-i = -1", "-while K > 0:", "- i += 1", "- K -= ab[i][1]", "-print((ab[i][0]))", "+ab = [tuple(map(int, input().split())) for i in range(N)]", "+ab.sort()", "+id = 0", "+for a, b in ab:", "+ if id + b >= K:", "+ print(a)", "+ break", "+ else:", "+ id += b" ]
false
0.132727
0.039931
3.323879
[ "s122408559", "s694815908" ]
u707960254
p02754
python
s103871223
s753709517
258
172
38,384
38,384
Accepted
Accepted
33.33
n, a, b = list(map(int, input().split())) if n%(a+b) >a: print((int(n//(a+b))*a +a)) else: print((int(n//(a+b))*a +n%(a+b)))
n, a, b = list(map(int, input().split())) print((n//(a+b)*a + min(a, n%(a+b))))
6
2
128
72
n, a, b = list(map(int, input().split())) if n % (a + b) > a: print((int(n // (a + b)) * a + a)) else: print((int(n // (a + b)) * a + n % (a + b)))
n, a, b = list(map(int, input().split())) print((n // (a + b) * a + min(a, n % (a + b))))
false
66.666667
[ "-if n % (a + b) > a:", "- print((int(n // (a + b)) * a + a))", "-else:", "- print((int(n // (a + b)) * a + n % (a + b)))", "+print((n // (a + b) * a + min(a, n % (a + b))))" ]
false
0.006932
0.084642
0.081897
[ "s103871223", "s753709517" ]
u149580849
p04029
python
s502739588
s845060677
39
28
3,064
2,568
Accepted
Accepted
28.21
n = int(eval(input())) sum = 0 for num in range(1,n + 1): sum += num print(sum)
n = int(eval(input())) print((sum(list(range(1,n+1)))))
5
2
81
48
n = int(eval(input())) sum = 0 for num in range(1, n + 1): sum += num print(sum)
n = int(eval(input())) print((sum(list(range(1, n + 1)))))
false
60
[ "-sum = 0", "-for num in range(1, n + 1):", "- sum += num", "-print(sum)", "+print((sum(list(range(1, n + 1)))))" ]
false
0.032658
0.04134
0.789984
[ "s502739588", "s845060677" ]
u562935282
p03482
python
s720026945
s160834282
720
73
4,768
4,084
Accepted
Accepted
89.86
def is_ok(k): imos = [0] * (len(s) + 2) for i, x in enumerate(s, 1): imos[i] ^= imos[i - 1] if i <= len(s) - (k - 1): # 連続kの区間をi起点に取ることができる if x ^ imos[i - 1]: imos[i] ^= 1 imos[i + k] ^= 1 else: if x ^ imos[i - 1]: return i > k return True def binary_search(): ok = 1 ng = len(s) + 1 while abs(ng - ok) > 1: mid = (ng + ok) // 2 if is_ok(mid): ok = mid else: ng = mid return ok s = tuple(map(int, eval(input()))) print((binary_search())) # Kで達成できるとき、K未満で達成できる # TTTTFFF # ^ # K # 二分探索する
s = tuple(map(int, eval(input()))) n = len(s) ret = n p = s[0] for i, x in enumerate(s): if x != p: ret = min(ret, max(i, n - i)) p = x print(ret)
36
10
711
167
def is_ok(k): imos = [0] * (len(s) + 2) for i, x in enumerate(s, 1): imos[i] ^= imos[i - 1] if i <= len(s) - (k - 1): # 連続kの区間をi起点に取ることができる if x ^ imos[i - 1]: imos[i] ^= 1 imos[i + k] ^= 1 else: if x ^ imos[i - 1]: return i > k return True def binary_search(): ok = 1 ng = len(s) + 1 while abs(ng - ok) > 1: mid = (ng + ok) // 2 if is_ok(mid): ok = mid else: ng = mid return ok s = tuple(map(int, eval(input()))) print((binary_search())) # Kで達成できるとき、K未満で達成できる # TTTTFFF # ^ # K # 二分探索する
s = tuple(map(int, eval(input()))) n = len(s) ret = n p = s[0] for i, x in enumerate(s): if x != p: ret = min(ret, max(i, n - i)) p = x print(ret)
false
72.222222
[ "-def is_ok(k):", "- imos = [0] * (len(s) + 2)", "- for i, x in enumerate(s, 1):", "- imos[i] ^= imos[i - 1]", "- if i <= len(s) - (k - 1):", "- # 連続kの区間をi起点に取ることができる", "- if x ^ imos[i - 1]:", "- imos[i] ^= 1", "- imos[i + k] ^= 1", "- else:", "- if x ^ imos[i - 1]:", "- return i > k", "- return True", "-", "-", "-def binary_search():", "- ok = 1", "- ng = len(s) + 1", "- while abs(ng - ok) > 1:", "- mid = (ng + ok) // 2", "- if is_ok(mid):", "- ok = mid", "- else:", "- ng = mid", "- return ok", "-", "-", "-print((binary_search()))", "-# Kで達成できるとき、K未満で達成できる", "-# TTTTFFF", "-# ^", "-# K", "-# 二分探索する", "+n = len(s)", "+ret = n", "+p = s[0]", "+for i, x in enumerate(s):", "+ if x != p:", "+ ret = min(ret, max(i, n - i))", "+ p = x", "+print(ret)" ]
false
0.044583
0.047007
0.948422
[ "s720026945", "s160834282" ]
u490489966
p02608
python
s499397071
s298165778
472
432
9,144
9,252
Accepted
Accepted
8.47
n = int(input()) ans=[0]*(n+1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): a = x * x + y * y + z * z + x * y + y * z + z * x if n >= a >= 1: ans[a] += 1 print(*ans[1:],sep="\n")
import math n = int(input()) ans = [0] * (n + 1) for x in range(1, int(math.sqrt(n))): for y in range(1, int(math.sqrt(n))): for z in range(1, int(math.sqrt(n))): a = x * x + y * y + z * z + x * y + y * z + z * x if n >= a >= 1: ans[a] += 1 print(*ans[1:],sep="\n")
9
10
265
326
n = int(input()) ans = [0] * (n + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): a = x * x + y * y + z * z + x * y + y * z + z * x if n >= a >= 1: ans[a] += 1 print(*ans[1:], sep="\n")
import math n = int(input()) ans = [0] * (n + 1) for x in range(1, int(math.sqrt(n))): for y in range(1, int(math.sqrt(n))): for z in range(1, int(math.sqrt(n))): a = x * x + y * y + z * z + x * y + y * z + z * x if n >= a >= 1: ans[a] += 1 print(*ans[1:], sep="\n")
false
10
[ "+import math", "+", "-for x in range(1, 101):", "- for y in range(1, 101):", "- for z in range(1, 101):", "+for x in range(1, int(math.sqrt(n))):", "+ for y in range(1, int(math.sqrt(n))):", "+ for z in range(1, int(math.sqrt(n))):" ]
false
1.261489
0.050103
25.17796
[ "s499397071", "s298165778" ]
u560867850
p03325
python
s529129652
s617734126
115
65
4,148
3,828
Accepted
Accepted
43.48
n = int(eval(input())) a = [int(c) for c in input().split()] count = 0 for n in a: x = n while x % 2 == 0: x /= 2 count += 1 print(count)
def main(): N = int(eval(input())) ans = 0 for a in [x for x in map(int, input().split()) if x % 2 == 0]: i = a while i % 2 == 0: i //= 2 ans += 1 print(ans) main()
11
12
167
230
n = int(eval(input())) a = [int(c) for c in input().split()] count = 0 for n in a: x = n while x % 2 == 0: x /= 2 count += 1 print(count)
def main(): N = int(eval(input())) ans = 0 for a in [x for x in map(int, input().split()) if x % 2 == 0]: i = a while i % 2 == 0: i //= 2 ans += 1 print(ans) main()
false
8.333333
[ "-n = int(eval(input()))", "-a = [int(c) for c in input().split()]", "-count = 0", "-for n in a:", "- x = n", "- while x % 2 == 0:", "- x /= 2", "- count += 1", "-print(count)", "+def main():", "+ N = int(eval(input()))", "+ ans = 0", "+ for a in [x for x in map(int, input().split()) if x % 2 == 0]:", "+ i = a", "+ while i % 2 == 0:", "+ i //= 2", "+ ans += 1", "+ print(ans)", "+", "+", "+main()" ]
false
0.037835
0.038173
0.991126
[ "s529129652", "s617734126" ]
u915355756
p03071
python
s681478682
s664963614
149
18
12,488
2,940
Accepted
Accepted
87.92
import numpy as np #input [A,B] = list(map(int,input().split())) #[A,B] = [5,5] ans = 0 if A == B: ans = 2*A else: ans = 2*max(A,B) - 1 print(ans)
#input #[A, B] = [5, 3] [A, B] = list(map(int,input().split())) if A == B: print((2*A)) else: print((2*max(A,B)-1))
10
17
163
162
import numpy as np # input [A, B] = list(map(int, input().split())) # [A,B] = [5,5] ans = 0 if A == B: ans = 2 * A else: ans = 2 * max(A, B) - 1 print(ans)
# input # [A, B] = [5, 3] [A, B] = list(map(int, input().split())) if A == B: print((2 * A)) else: print((2 * max(A, B) - 1))
false
41.176471
[ "-import numpy as np", "-", "+# [A, B] = [5, 3]", "-# [A,B] = [5,5]", "-ans = 0", "- ans = 2 * A", "+ print((2 * A))", "- ans = 2 * max(A, B) - 1", "-print(ans)", "+ print((2 * max(A, B) - 1))" ]
false
0.03778
0.059507
0.634878
[ "s681478682", "s664963614" ]
u580996582
p03478
python
s798995197
s885514252
1,443
33
3,060
3,060
Accepted
Accepted
97.71
n,a,b = list(map(int,input().split())) ans = 0; for i in range(1,n+1): sum = 0; x = i; while x: sum += int(x%10); x/=10; if a <= sum <= b: ans+=i; print(("%d" % (ans) ));
# n,a,b = map(int,input().split()) # ans = 0; # for i in range(1,n+1): # sum = 0; # x = i; # while x: # sum += int(x%10); # x/=10; # if a <= sum <= b: # ans+=i; # print("%d" % (ans) ); n,a,b = list(map(int,input().split())) ans = 0; for i in range(n+1): str_i = str(i) sum = 0; for x in str_i: sum += int(x) if a <= sum <= b: ans+=i; print(ans)
11
22
212
432
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): sum = 0 x = i while x: sum += int(x % 10) x /= 10 if a <= sum <= b: ans += i print(("%d" % (ans)))
# n,a,b = map(int,input().split()) # ans = 0; # for i in range(1,n+1): # sum = 0; # x = i; # while x: # sum += int(x%10); # x/=10; # if a <= sum <= b: # ans+=i; # print("%d" % (ans) ); n, a, b = list(map(int, input().split())) ans = 0 for i in range(n + 1): str_i = str(i) sum = 0 for x in str_i: sum += int(x) if a <= sum <= b: ans += i print(ans)
false
50
[ "+# n,a,b = map(int,input().split())", "+# ans = 0;", "+# for i in range(1,n+1):", "+# sum = 0;", "+# x = i;", "+# while x:", "+# sum += int(x%10);", "+# x/=10;", "+# if a <= sum <= b:", "+# ans+=i;", "+# print(\"%d\" % (ans) );", "-for i in range(1, n + 1):", "+for i in range(n + 1):", "+ str_i = str(i)", "- x = i", "- while x:", "- sum += int(x % 10)", "- x /= 10", "+ for x in str_i:", "+ sum += int(x)", "-print((\"%d\" % (ans)))", "+print(ans)" ]
false
0.053513
0.007073
7.565693
[ "s798995197", "s885514252" ]
u560867850
p03038
python
s004145290
s403596964
363
334
25,372
22,292
Accepted
Accepted
7.99
import heapq import sys input = sys.stdin.readline def readlines(n): for _ in range(n): b, c = list(map(int, input().split())) yield b, c def main(): _, M = list(map(int, input().split())) A = list(map(int, input().split())) total = sum(A) heapq.heapify(A) for b, c in sorted(readlines(M), key=lambda x: -x[1]): for _ in range(b): o = heapq.heappushpop(A, c) if o < c: total += c - o else: break print(total) main()
import heapq import sys input = sys.stdin.readline from operator import itemgetter def readlines(n): for _ in range(n): b, c = list(map(int, input().split())) yield b, c def main(): _, M = list(map(int, input().split())) A = list(map(int, input().split())) total = sum(A) heapq.heapify(A) for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True): for _ in range(b): o = heapq.heappushpop(A, c) if o < c: total += c - o else: break print(total) main()
26
27
565
610
import heapq import sys input = sys.stdin.readline def readlines(n): for _ in range(n): b, c = list(map(int, input().split())) yield b, c def main(): _, M = list(map(int, input().split())) A = list(map(int, input().split())) total = sum(A) heapq.heapify(A) for b, c in sorted(readlines(M), key=lambda x: -x[1]): for _ in range(b): o = heapq.heappushpop(A, c) if o < c: total += c - o else: break print(total) main()
import heapq import sys input = sys.stdin.readline from operator import itemgetter def readlines(n): for _ in range(n): b, c = list(map(int, input().split())) yield b, c def main(): _, M = list(map(int, input().split())) A = list(map(int, input().split())) total = sum(A) heapq.heapify(A) for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True): for _ in range(b): o = heapq.heappushpop(A, c) if o < c: total += c - o else: break print(total) main()
false
3.703704
[ "+from operator import itemgetter", "- for b, c in sorted(readlines(M), key=lambda x: -x[1]):", "+ for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):" ]
false
0.040661
0.10182
0.399341
[ "s004145290", "s403596964" ]
u392319141
p03658
python
s984895969
s920226727
181
18
38,384
2,940
Accepted
Accepted
90.06
N, K = list(map(int, input().split())) L = list(map(int, input().split())) L.sort(reverse=True) print((sum(L[:K])))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) print((sum(A[:K])))
5
4
113
110
N, K = list(map(int, input().split())) L = list(map(int, input().split())) L.sort(reverse=True) print((sum(L[:K])))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) print((sum(A[:K])))
false
20
[ "-L = list(map(int, input().split()))", "-L.sort(reverse=True)", "-print((sum(L[:K])))", "+A = list(map(int, input().split()))", "+A.sort(reverse=True)", "+print((sum(A[:K])))" ]
false
0.036331
0.036336
0.999857
[ "s984895969", "s920226727" ]
u489959379
p03524
python
s387982889
s042923119
25
18
3,956
3,188
Accepted
Accepted
28
S = list(eval(input())) ma = 0 for s in set(S): cnt = S.count(s) ma = max(ma, cnt) if len(S) - ma >= (ma - 1) * 2 or len(S) == 1: print("YES") else: print("NO")
# https://atcoder.jp/contests/cf17-final/submissions/12544627 # B - Palindrome-phobia import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): s = eval(input()) a = s.count("a") b = s.count("b") c = s.count("c") print(("YES" if max(a, b, c) <= min(a, b, c) + 1 else "NO")) if __name__ == '__main__': resolve()
11
21
171
392
S = list(eval(input())) ma = 0 for s in set(S): cnt = S.count(s) ma = max(ma, cnt) if len(S) - ma >= (ma - 1) * 2 or len(S) == 1: print("YES") else: print("NO")
# https://atcoder.jp/contests/cf17-final/submissions/12544627 # B - Palindrome-phobia import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): s = eval(input()) a = s.count("a") b = s.count("b") c = s.count("c") print(("YES" if max(a, b, c) <= min(a, b, c) + 1 else "NO")) if __name__ == "__main__": resolve()
false
47.619048
[ "-S = list(eval(input()))", "-ma = 0", "-for s in set(S):", "- cnt = S.count(s)", "- ma = max(ma, cnt)", "-if len(S) - ma >= (ma - 1) * 2 or len(S) == 1:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+# https://atcoder.jp/contests/cf17-final/submissions/12544627", "+# B - Palindrome-phobia", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ s = eval(input())", "+ a = s.count(\"a\")", "+ b = s.count(\"b\")", "+ c = s.count(\"c\")", "+ print((\"YES\" if max(a, b, c) <= min(a, b, c) + 1 else \"NO\"))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.044082
0.077851
0.566245
[ "s387982889", "s042923119" ]
u588341295
p03946
python
s759482629
s977149473
91
83
15,020
15,060
Accepted
Accepted
8.79
# -*- coding: utf-8 -*- """ 参考:https://atcoder.jp/contests/abc047/submissions/4077573 """ import sys import re from collections import deque, Counter, defaultdict from math import sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, product, combinations, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N, T = MAP() aN = LIST() mx = -INF l = aN[0] cnt = 0 for i in range(1,N): # 最低値更新なら始点を動かす if aN[i] < l: l = aN[i] else: # 最高値更新ならその場所が操作対象になる if aN[i] - l > mx: mx = aN[i] - l cnt = 1 # 同率最高値なら操作対象が1つ増える elif aN[i] - l == mx: cnt += 1 print(cnt)
# -*- coding: utf-8 -*- """ 参考:https://atcoder.jp/contests/abc047/submissions/4077573 """ import sys def input(): return sys.stdin.readline().strip() def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N, T = MAP() aN = LIST() mx = -INF l = aN[0] cnt = 0 for i in range(1,N): # 最低値更新なら始点を動かす if aN[i] < l: l = aN[i] else: # 最高値更新ならその場所が操作対象になる if aN[i] - l > mx: mx = aN[i] - l cnt = 1 # 同率最高値なら操作対象が1つ増える elif aN[i] - l == mx: cnt += 1 print(cnt)
44
33
1,173
683
# -*- coding: utf-8 -*- """ 参考:https://atcoder.jp/contests/abc047/submissions/4077573 """ import sys import re from collections import deque, Counter, defaultdict from math import sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, product, combinations, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, T = MAP() aN = LIST() mx = -INF l = aN[0] cnt = 0 for i in range(1, N): # 最低値更新なら始点を動かす if aN[i] < l: l = aN[i] else: # 最高値更新ならその場所が操作対象になる if aN[i] - l > mx: mx = aN[i] - l cnt = 1 # 同率最高値なら操作対象が1つ増える elif aN[i] - l == mx: cnt += 1 print(cnt)
# -*- coding: utf-8 -*- """ 参考:https://atcoder.jp/contests/abc047/submissions/4077573 """ import sys def input(): return sys.stdin.readline().strip() def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, T = MAP() aN = LIST() mx = -INF l = aN[0] cnt = 0 for i in range(1, N): # 最低値更新なら始点を動かす if aN[i] < l: l = aN[i] else: # 最高値更新ならその場所が操作対象になる if aN[i] - l > mx: mx = aN[i] - l cnt = 1 # 同率最高値なら操作対象が1つ増える elif aN[i] - l == mx: cnt += 1 print(cnt)
false
25
[ "-import re", "-from collections import deque, Counter, defaultdict", "-from math import sqrt, hypot, factorial, pi, sin, cos, radians", "-from heapq import heappop, heappush, heapify, heappushpop", "-from bisect import bisect_left, bisect_right", "-from itertools import permutations, product, combinations, combinations_with_replacement", "-from operator import itemgetter, mul", "-from copy import deepcopy", "-from functools import reduce, partial", "-from string import ascii_lowercase, ascii_uppercase, digits" ]
false
0.039283
0.166414
0.236058
[ "s759482629", "s977149473" ]
u864197622
p03198
python
s846784970
s375142912
811
552
28,432
30,484
Accepted
Accepted
31.94
from collections import deque q = deque([]) def ct(a,b): ans = 0 while abs(a)<abs(b): ans += 2 a *= 4 return ans N = int(eval(input())) A = [int(a) for a in input().split()] # A = [3, 1, 4, 1] # N = len(A) X = [0] * (N) Y = [0] * (N) a = -1 for i in range(N): b = a if i > 0: X[i] = X[i-1] else: X[i] = 0 a = A[i] t = 0 if a > 0: X[i] += 1 a *= -2 if i > 0: t = 0 r = b/a while r >= 4: q.append(i) r /= 4 while abs(a)>abs(b): if len(q) == 0: X[i] += 2 * i else: X[i] += 2 * (i - q.pop()) b *= 4 q = deque([]) a = -1 for i in range(N): b = a if i > 0: Y[i] = Y[i-1] else: Y[i] = 0 a = A[N-1-i] t = 0 if a < 0: Y[i] += 1 a *= -2 if i > 0: t = 0 r = b/a while r >= 4: q.append(i) r /= 4 while abs(a)>abs(b): if len(q) == 0: Y[i] += 2 * i else: Y[i] += 2 * (i - q.pop()) b *= 4 mi = min(X[-1], Y[-1]) for i in range(N-1): if X[i]+Y[-2-i] < mi: mi = X[i]+Y[-2-i] print(mi)
def f(A, s): X = [0] * N q = [] a = 0 for i in range(N): b = a X[i] = X[i-1] a = A[i] if a * s < 0: X[i] += 1 a *= -2 if i == 0: continue r = b/a while r >= 4: q.append(i) r /= 4 while r < 1: X[i] += 2 * (i - (0 if len(q) == 0 else q.pop())) r *= 4 return X N = int(eval(input())) A = [int(a) for a in input().split()] X = f(A,-1) Y = f(A[::-1],1) mi = min(X[-1], Y[-1]) for i in range(N-1): mi = min(mi, X[i] + Y[-2-i]) print(mi)
81
35
1,401
660
from collections import deque q = deque([]) def ct(a, b): ans = 0 while abs(a) < abs(b): ans += 2 a *= 4 return ans N = int(eval(input())) A = [int(a) for a in input().split()] # A = [3, 1, 4, 1] # N = len(A) X = [0] * (N) Y = [0] * (N) a = -1 for i in range(N): b = a if i > 0: X[i] = X[i - 1] else: X[i] = 0 a = A[i] t = 0 if a > 0: X[i] += 1 a *= -2 if i > 0: t = 0 r = b / a while r >= 4: q.append(i) r /= 4 while abs(a) > abs(b): if len(q) == 0: X[i] += 2 * i else: X[i] += 2 * (i - q.pop()) b *= 4 q = deque([]) a = -1 for i in range(N): b = a if i > 0: Y[i] = Y[i - 1] else: Y[i] = 0 a = A[N - 1 - i] t = 0 if a < 0: Y[i] += 1 a *= -2 if i > 0: t = 0 r = b / a while r >= 4: q.append(i) r /= 4 while abs(a) > abs(b): if len(q) == 0: Y[i] += 2 * i else: Y[i] += 2 * (i - q.pop()) b *= 4 mi = min(X[-1], Y[-1]) for i in range(N - 1): if X[i] + Y[-2 - i] < mi: mi = X[i] + Y[-2 - i] print(mi)
def f(A, s): X = [0] * N q = [] a = 0 for i in range(N): b = a X[i] = X[i - 1] a = A[i] if a * s < 0: X[i] += 1 a *= -2 if i == 0: continue r = b / a while r >= 4: q.append(i) r /= 4 while r < 1: X[i] += 2 * (i - (0 if len(q) == 0 else q.pop())) r *= 4 return X N = int(eval(input())) A = [int(a) for a in input().split()] X = f(A, -1) Y = f(A[::-1], 1) mi = min(X[-1], Y[-1]) for i in range(N - 1): mi = min(mi, X[i] + Y[-2 - i]) print(mi)
false
56.790123
[ "-from collections import deque", "-", "-q = deque([])", "-", "-", "-def ct(a, b):", "- ans = 0", "- while abs(a) < abs(b):", "- ans += 2", "- a *= 4", "- return ans", "+def f(A, s):", "+ X = [0] * N", "+ q = []", "+ a = 0", "+ for i in range(N):", "+ b = a", "+ X[i] = X[i - 1]", "+ a = A[i]", "+ if a * s < 0:", "+ X[i] += 1", "+ a *= -2", "+ if i == 0:", "+ continue", "+ r = b / a", "+ while r >= 4:", "+ q.append(i)", "+ r /= 4", "+ while r < 1:", "+ X[i] += 2 * (i - (0 if len(q) == 0 else q.pop()))", "+ r *= 4", "+ return X", "-# A = [3, 1, 4, 1]", "-# N = len(A)", "-X = [0] * (N)", "-Y = [0] * (N)", "-a = -1", "-for i in range(N):", "- b = a", "- if i > 0:", "- X[i] = X[i - 1]", "- else:", "- X[i] = 0", "- a = A[i]", "- t = 0", "- if a > 0:", "- X[i] += 1", "- a *= -2", "- if i > 0:", "- t = 0", "- r = b / a", "- while r >= 4:", "- q.append(i)", "- r /= 4", "- while abs(a) > abs(b):", "- if len(q) == 0:", "- X[i] += 2 * i", "- else:", "- X[i] += 2 * (i - q.pop())", "- b *= 4", "-q = deque([])", "-a = -1", "-for i in range(N):", "- b = a", "- if i > 0:", "- Y[i] = Y[i - 1]", "- else:", "- Y[i] = 0", "- a = A[N - 1 - i]", "- t = 0", "- if a < 0:", "- Y[i] += 1", "- a *= -2", "- if i > 0:", "- t = 0", "- r = b / a", "- while r >= 4:", "- q.append(i)", "- r /= 4", "- while abs(a) > abs(b):", "- if len(q) == 0:", "- Y[i] += 2 * i", "- else:", "- Y[i] += 2 * (i - q.pop())", "- b *= 4", "+X = f(A, -1)", "+Y = f(A[::-1], 1)", "- if X[i] + Y[-2 - i] < mi:", "- mi = X[i] + Y[-2 - i]", "+ mi = min(mi, X[i] + Y[-2 - i])" ]
false
0.037024
0.037808
0.979282
[ "s846784970", "s375142912" ]
u708890186
p02773
python
s149657818
s047100707
868
719
47,640
47,640
Accepted
Accepted
17.17
import collections N = int(eval(input())) s = [eval(input()) for i in range(N)] counter = collections.Counter(s) count = counter.most_common() most = count[0][1] c =[] for i in range(len(count)): if count[i][1] == most: c.append(count[i][0]) c.sort() for i in range(len(c)): print((c[i]))
import collections N = int(eval(input())) s = [eval(input()) for i in range(N)] counter = collections.Counter(s) count = counter.most_common() most = count[0][1] c =[] for i in range(len(counter)): if count[i][1] == most: c.append(count[i][0]) c.sort() for i in range(len(c)): print((c[i]))
18
18
317
319
import collections N = int(eval(input())) s = [eval(input()) for i in range(N)] counter = collections.Counter(s) count = counter.most_common() most = count[0][1] c = [] for i in range(len(count)): if count[i][1] == most: c.append(count[i][0]) c.sort() for i in range(len(c)): print((c[i]))
import collections N = int(eval(input())) s = [eval(input()) for i in range(N)] counter = collections.Counter(s) count = counter.most_common() most = count[0][1] c = [] for i in range(len(counter)): if count[i][1] == most: c.append(count[i][0]) c.sort() for i in range(len(c)): print((c[i]))
false
0
[ "-for i in range(len(count)):", "+for i in range(len(counter)):" ]
false
0.08123
0.040599
2.000774
[ "s149657818", "s047100707" ]
u368796742
p02726
python
s267203059
s808462083
1,378
950
3,444
135,560
Accepted
Accepted
31.06
n,x,y = list(map(int,input().split())) ans = [0]*(n) for i in range(1,n): for j in range(i+1,n+1): d = min(j-i,abs(x-i)+abs(y-j)+1) ans[d] += 1 for i in ans[1:]: print(i)
def main(): import sys input = sys.stdin.readline from collections import deque n,x,y = list(map(int,input().split())) ans = [0]*(n) E = [[] for i in range(n)] E[0].append(1) E[n-1].append(n-2) for i in range(1,n-1): E[i].append(i-1) E[i].append(i+1) E[x-1].append(y-1) E[y-1].append(x-1) ans = [0]*(n) d = [[float("INF")]*n for i in range(n)] def search(x): d[x][x] = 0 q = deque([]) q.append((x,0)) while q: bef,l = q.pop() for nex in E[bef]: if d[x][nex] > l+1: d[x][nex] = l+1 q.append((nex,l+1)) for i in range(n-1): search(i) for i in range(n-1): for j in range(i+1,n): if d[i][j] != float("INF"): ans[d[i][j]] += 1 for i in ans[1:]: print(i) if __name__ == "__main__": main()
9
41
197
990
n, x, y = list(map(int, input().split())) ans = [0] * (n) for i in range(1, n): for j in range(i + 1, n + 1): d = min(j - i, abs(x - i) + abs(y - j) + 1) ans[d] += 1 for i in ans[1:]: print(i)
def main(): import sys input = sys.stdin.readline from collections import deque n, x, y = list(map(int, input().split())) ans = [0] * (n) E = [[] for i in range(n)] E[0].append(1) E[n - 1].append(n - 2) for i in range(1, n - 1): E[i].append(i - 1) E[i].append(i + 1) E[x - 1].append(y - 1) E[y - 1].append(x - 1) ans = [0] * (n) d = [[float("INF")] * n for i in range(n)] def search(x): d[x][x] = 0 q = deque([]) q.append((x, 0)) while q: bef, l = q.pop() for nex in E[bef]: if d[x][nex] > l + 1: d[x][nex] = l + 1 q.append((nex, l + 1)) for i in range(n - 1): search(i) for i in range(n - 1): for j in range(i + 1, n): if d[i][j] != float("INF"): ans[d[i][j]] += 1 for i in ans[1:]: print(i) if __name__ == "__main__": main()
false
78.04878
[ "-n, x, y = list(map(int, input().split()))", "-ans = [0] * (n)", "-for i in range(1, n):", "- for j in range(i + 1, n + 1):", "- d = min(j - i, abs(x - i) + abs(y - j) + 1)", "- ans[d] += 1", "-for i in ans[1:]:", "- print(i)", "+def main():", "+ import sys", "+", "+ input = sys.stdin.readline", "+ from collections import deque", "+", "+ n, x, y = list(map(int, input().split()))", "+ ans = [0] * (n)", "+ E = [[] for i in range(n)]", "+ E[0].append(1)", "+ E[n - 1].append(n - 2)", "+ for i in range(1, n - 1):", "+ E[i].append(i - 1)", "+ E[i].append(i + 1)", "+ E[x - 1].append(y - 1)", "+ E[y - 1].append(x - 1)", "+ ans = [0] * (n)", "+ d = [[float(\"INF\")] * n for i in range(n)]", "+", "+ def search(x):", "+ d[x][x] = 0", "+ q = deque([])", "+ q.append((x, 0))", "+ while q:", "+ bef, l = q.pop()", "+ for nex in E[bef]:", "+ if d[x][nex] > l + 1:", "+ d[x][nex] = l + 1", "+ q.append((nex, l + 1))", "+", "+ for i in range(n - 1):", "+ search(i)", "+ for i in range(n - 1):", "+ for j in range(i + 1, n):", "+ if d[i][j] != float(\"INF\"):", "+ ans[d[i][j]] += 1", "+ for i in ans[1:]:", "+ print(i)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.130102
0.041388
3.143477
[ "s267203059", "s808462083" ]
u782685137
p03200
python
s905775357
s974745647
45
41
11,428
11,428
Accepted
Accepted
8.89
S=input()[::-1] n=len(S) l=list(i for i in range(n) if S[i]=='B') k=len(l)*(len(l)-1)//2 print((sum(l)-k))
l=[i for i,s in enumerate(input()[::-1])if s=='B'] m=len(l) print((sum(l)-m*~-m//2))
5
3
108
84
S = input()[::-1] n = len(S) l = list(i for i in range(n) if S[i] == "B") k = len(l) * (len(l) - 1) // 2 print((sum(l) - k))
l = [i for i, s in enumerate(input()[::-1]) if s == "B"] m = len(l) print((sum(l) - m * ~-m // 2))
false
40
[ "-S = input()[::-1]", "-n = len(S)", "-l = list(i for i in range(n) if S[i] == \"B\")", "-k = len(l) * (len(l) - 1) // 2", "-print((sum(l) - k))", "+l = [i for i, s in enumerate(input()[::-1]) if s == \"B\"]", "+m = len(l)", "+print((sum(l) - m * ~-m // 2))" ]
false
0.063191
0.04632
1.36422
[ "s905775357", "s974745647" ]
u475675023
p02843
python
s202431964
s784604441
29
24
2,940
2,940
Accepted
Accepted
17.24
x=int(eval(input())) for i in range(1,100000): if 100*i<=x<=105*i: print((1)) exit() print((0))
x=int(eval(input())) print((1 if x<=x//100*105 else 0))
6
2
100
48
x = int(eval(input())) for i in range(1, 100000): if 100 * i <= x <= 105 * i: print((1)) exit() print((0))
x = int(eval(input())) print((1 if x <= x // 100 * 105 else 0))
false
66.666667
[ "-for i in range(1, 100000):", "- if 100 * i <= x <= 105 * i:", "- print((1))", "- exit()", "-print((0))", "+print((1 if x <= x // 100 * 105 else 0))" ]
false
0.043455
0.080032
0.542979
[ "s202431964", "s784604441" ]
u357630630
p03556
python
s678617225
s356733033
73
67
8,548
5,864
Accepted
Accepted
8.22
N=int(input()) [exit(0) if i ** 2 > N else print(i ** 2) if (i+1) ** 2 > N else print("", end="") for i in range(1, N+1)]
N=int(input()) [exit(0)if i**2>N else print(i**2)if(i+1)**2>N else print(end="")for i in range(1,N+1)]
2
2
122
103
N = int(input()) [ exit(0) if i ** 2 > N else print(i**2) if (i + 1) ** 2 > N else print("", end="") for i in range(1, N + 1) ]
N = int(input()) [ exit(0) if i ** 2 > N else print(i**2) if (i + 1) ** 2 > N else print(end="") for i in range(1, N + 1) ]
false
0
[ "- exit(0) if i ** 2 > N else print(i**2) if (i + 1) ** 2 > N else print(\"\", end=\"\")", "+ exit(0) if i ** 2 > N else print(i**2) if (i + 1) ** 2 > N else print(end=\"\")" ]
false
0.041205
0.05183
0.795012
[ "s678617225", "s356733033" ]
u978313283
p03309
python
s596681009
s962676332
380
187
29,748
26,704
Accepted
Accepted
50.79
N=int(eval(input())) A=list(map(int,input().split())) A=[a-i for i,a in enumerate(A,1)] A.sort() A_posi=[0 for i in range(N)] A_posi[0]=A[0] for i in range(1,N): A_posi[i]=A_posi[i-1]+A[i] value=[0 for i in range(N)] value[0]=A_posi[N-1]-N*A[0] for i in range(1,N): value[i]=A_posi[N-1]-A_posi[i]-(N-i-1)*A[i]-A_posi[i-1]+(i)*A[i] print((min(value)))
N=int(eval(input())) A=list(map(int,input().split())) A=[a-i for i,a in enumerate(A,1)] A.sort() b=A[len(A)//2] A=[abs(a-b) for a in A] print((sum(A)))
13
7
363
150
N = int(eval(input())) A = list(map(int, input().split())) A = [a - i for i, a in enumerate(A, 1)] A.sort() A_posi = [0 for i in range(N)] A_posi[0] = A[0] for i in range(1, N): A_posi[i] = A_posi[i - 1] + A[i] value = [0 for i in range(N)] value[0] = A_posi[N - 1] - N * A[0] for i in range(1, N): value[i] = ( A_posi[N - 1] - A_posi[i] - (N - i - 1) * A[i] - A_posi[i - 1] + (i) * A[i] ) print((min(value)))
N = int(eval(input())) A = list(map(int, input().split())) A = [a - i for i, a in enumerate(A, 1)] A.sort() b = A[len(A) // 2] A = [abs(a - b) for a in A] print((sum(A)))
false
46.153846
[ "-A_posi = [0 for i in range(N)]", "-A_posi[0] = A[0]", "-for i in range(1, N):", "- A_posi[i] = A_posi[i - 1] + A[i]", "-value = [0 for i in range(N)]", "-value[0] = A_posi[N - 1] - N * A[0]", "-for i in range(1, N):", "- value[i] = (", "- A_posi[N - 1] - A_posi[i] - (N - i - 1) * A[i] - A_posi[i - 1] + (i) * A[i]", "- )", "-print((min(value)))", "+b = A[len(A) // 2]", "+A = [abs(a - b) for a in A]", "+print((sum(A)))" ]
false
0.035794
0.036046
0.993015
[ "s596681009", "s962676332" ]
u580404776
p03814
python
s237196783
s651779990
26
18
6,180
3,500
Accepted
Accepted
30.77
S=list(eval(input())) N=len(S) pos_Z=N-S[::-1].index("Z") pos_A=S.index("A") print((pos_Z-pos_A))
S=eval(input()) print((S.rfind("Z")-S.find("A")+1))
5
2
93
44
S = list(eval(input())) N = len(S) pos_Z = N - S[::-1].index("Z") pos_A = S.index("A") print((pos_Z - pos_A))
S = eval(input()) print((S.rfind("Z") - S.find("A") + 1))
false
60
[ "-S = list(eval(input()))", "-N = len(S)", "-pos_Z = N - S[::-1].index(\"Z\")", "-pos_A = S.index(\"A\")", "-print((pos_Z - pos_A))", "+S = eval(input())", "+print((S.rfind(\"Z\") - S.find(\"A\") + 1))" ]
false
0.036493
0.037032
0.985457
[ "s237196783", "s651779990" ]
u759412327
p03327
python
s284826229
s518533112
20
17
3,060
2,940
Accepted
Accepted
15
print("ABC") if int(input())<=999 else print("ABD")
if int(eval(input()))<1000: print("ABC") else: print("ABD")
1
4
51
60
print("ABC") if int(input()) <= 999 else print("ABD")
if int(eval(input())) < 1000: print("ABC") else: print("ABD")
false
75
[ "-print(\"ABC\") if int(input()) <= 999 else print(\"ABD\")", "+if int(eval(input())) < 1000:", "+ print(\"ABC\")", "+else:", "+ print(\"ABD\")" ]
false
0.045187
0.045266
0.998259
[ "s284826229", "s518533112" ]
u067694718
p03617
python
s157853000
s716499763
31
28
9,152
9,156
Accepted
Accepted
9.68
q, h, s, d = [int(i) for i in input().split()] n = int(eval(input())) d = min(min(d, s*2), min(h*4, q*8)) s = min(s, min(h*2, q*4)) h = min(h, q*2) ans = (n // 2) * d n %= 2 while n > 0: if n >= 1: n -= 1 ans += s elif n >= 0.5: n -= 0.5 ans += h else: n -= 0.25 ans += q print(ans)
q, h, s, d = [int(i) for i in input().split()] n = int(eval(input())) d = min(min(d, s*2), min(h*4, q*8)) s = min(s, min(h*2, q*4)) print(((n // 2) * d + (n % 2) * s))
19
5
355
163
q, h, s, d = [int(i) for i in input().split()] n = int(eval(input())) d = min(min(d, s * 2), min(h * 4, q * 8)) s = min(s, min(h * 2, q * 4)) h = min(h, q * 2) ans = (n // 2) * d n %= 2 while n > 0: if n >= 1: n -= 1 ans += s elif n >= 0.5: n -= 0.5 ans += h else: n -= 0.25 ans += q print(ans)
q, h, s, d = [int(i) for i in input().split()] n = int(eval(input())) d = min(min(d, s * 2), min(h * 4, q * 8)) s = min(s, min(h * 2, q * 4)) print(((n // 2) * d + (n % 2) * s))
false
73.684211
[ "-h = min(h, q * 2)", "-ans = (n // 2) * d", "-n %= 2", "-while n > 0:", "- if n >= 1:", "- n -= 1", "- ans += s", "- elif n >= 0.5:", "- n -= 0.5", "- ans += h", "- else:", "- n -= 0.25", "- ans += q", "-print(ans)", "+print(((n // 2) * d + (n % 2) * s))" ]
false
0.008053
0.067138
0.119941
[ "s157853000", "s716499763" ]
u077291787
p03503
python
s151421563
s258250295
227
195
3,316
3,316
Accepted
Accepted
14.1
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product((0, 1), repeat=10))[1:]: cnt = 0 for f, p in zip(F, P): opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10)) cnt += p[opening] ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product((0, 1), repeat=10))[1:]: cnt = 0 for f, p in zip(F, P): opening = sum(i & j for i, j in zip(b, f)) cnt += p[opening] ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
22
22
579
561
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product((0, 1), repeat=10))[1:]: cnt = 0 for f, p in zip(F, P): opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10)) cnt += p[opening] ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product((0, 1), repeat=10))[1:]: cnt = 0 for f, p in zip(F, P): opening = sum(i & j for i, j in zip(b, f)) cnt += p[opening] ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
false
0
[ "- opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10))", "+ opening = sum(i & j for i, j in zip(b, f))" ]
false
0.057153
0.051796
1.103429
[ "s151421563", "s258250295" ]
u338068977
p03069
python
s849020094
s868057058
761
108
36,096
3,500
Accepted
Accepted
85.81
import numpy N=int(eval(input())) S=list(map(str,eval(input()))) S_modify = [0 if i=="." else 1 for i in S] count_list = [] sum_list=numpy.cumsum(S_modify) sum_list_reverse=numpy.cumsum(S_modify[::-1]) for i in range(N): count = sum_list[i]+((N-i-1)-sum_list_reverse[N-i-1]) count_list.append(count) print((min(count_list)))
N = int(eval(input())) S = eval(input()) left_black=0 right_white=S.count(".") ans=left_black+right_white for i in S: if i==".": right_white-=1 ans=min(ans,left_black+right_white) else: left_black+=1 ans=min(ans,left_black+right_white) print(ans)
12
15
330
292
import numpy N = int(eval(input())) S = list(map(str, eval(input()))) S_modify = [0 if i == "." else 1 for i in S] count_list = [] sum_list = numpy.cumsum(S_modify) sum_list_reverse = numpy.cumsum(S_modify[::-1]) for i in range(N): count = sum_list[i] + ((N - i - 1) - sum_list_reverse[N - i - 1]) count_list.append(count) print((min(count_list)))
N = int(eval(input())) S = eval(input()) left_black = 0 right_white = S.count(".") ans = left_black + right_white for i in S: if i == ".": right_white -= 1 ans = min(ans, left_black + right_white) else: left_black += 1 ans = min(ans, left_black + right_white) print(ans)
false
20
[ "-import numpy", "-", "-S = list(map(str, eval(input())))", "-S_modify = [0 if i == \".\" else 1 for i in S]", "-count_list = []", "-sum_list = numpy.cumsum(S_modify)", "-sum_list_reverse = numpy.cumsum(S_modify[::-1])", "-for i in range(N):", "- count = sum_list[i] + ((N - i - 1) - sum_list_reverse[N - i - 1])", "- count_list.append(count)", "-print((min(count_list)))", "+S = eval(input())", "+left_black = 0", "+right_white = S.count(\".\")", "+ans = left_black + right_white", "+for i in S:", "+ if i == \".\":", "+ right_white -= 1", "+ ans = min(ans, left_black + right_white)", "+ else:", "+ left_black += 1", "+ ans = min(ans, left_black + right_white)", "+print(ans)" ]
false
0.172498
0.085237
2.023747
[ "s849020094", "s868057058" ]
u987170100
p03273
python
s647942208
s623926670
28
18
4,468
3,060
Accepted
Accepted
35.71
H, W = map(int, input().split()) lst = [] for _ in range(H): s = input() if s.find('#') >= 0: lst.append(s) lst2 = [] for w in range(W): skip = True for h in range(len(lst)): if lst[h][w] == '#': skip = False break lst2.append(skip) for x in lst: for idx, y in enumerate(x): if not lst2[idx]: print(y, end='') print()
H, W = list(map(int, input().split())) lst = [] for _ in range(H): s = eval(input()) if s.find('#') >= 0: lst.append(s) lst2 = [] for tpl in zip(*lst): if '#' in tpl: lst2.append(tpl) for tpl in zip(*lst2): print((''.join(tpl)))
21
14
427
261
H, W = map(int, input().split()) lst = [] for _ in range(H): s = input() if s.find("#") >= 0: lst.append(s) lst2 = [] for w in range(W): skip = True for h in range(len(lst)): if lst[h][w] == "#": skip = False break lst2.append(skip) for x in lst: for idx, y in enumerate(x): if not lst2[idx]: print(y, end="") print()
H, W = list(map(int, input().split())) lst = [] for _ in range(H): s = eval(input()) if s.find("#") >= 0: lst.append(s) lst2 = [] for tpl in zip(*lst): if "#" in tpl: lst2.append(tpl) for tpl in zip(*lst2): print(("".join(tpl)))
false
33.333333
[ "-H, W = map(int, input().split())", "+H, W = list(map(int, input().split()))", "- s = input()", "+ s = eval(input())", "-for w in range(W):", "- skip = True", "- for h in range(len(lst)):", "- if lst[h][w] == \"#\":", "- skip = False", "- break", "- lst2.append(skip)", "-for x in lst:", "- for idx, y in enumerate(x):", "- if not lst2[idx]:", "- print(y, end=\"\")", "- print()", "+for tpl in zip(*lst):", "+ if \"#\" in tpl:", "+ lst2.append(tpl)", "+for tpl in zip(*lst2):", "+ print((\"\".join(tpl)))" ]
false
0.074306
0.119411
0.62227
[ "s647942208", "s623926670" ]
u934442292
p04012
python
s521256635
s986245020
25
20
3,772
3,316
Accepted
Accepted
20
import string import sys input = sys.stdin.readline AL = string.ascii_lowercase def main(): w = input().rstrip() ans = "Yes" for s in AL: cnt = w.count(s) if cnt % 2 == 1: ans = "No" print(ans) if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): w = input().rstrip() c = Counter(w) ans = "Yes" for v in list(c.values()): if v % 2 != 0: ans = "No" print(ans) if __name__ == "__main__": main()
19
20
299
292
import string import sys input = sys.stdin.readline AL = string.ascii_lowercase def main(): w = input().rstrip() ans = "Yes" for s in AL: cnt = w.count(s) if cnt % 2 == 1: ans = "No" print(ans) if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): w = input().rstrip() c = Counter(w) ans = "Yes" for v in list(c.values()): if v % 2 != 0: ans = "No" print(ans) if __name__ == "__main__": main()
false
5
[ "-import string", "+from collections import Counter", "-AL = string.ascii_lowercase", "+ c = Counter(w)", "- for s in AL:", "- cnt = w.count(s)", "- if cnt % 2 == 1:", "+ for v in list(c.values()):", "+ if v % 2 != 0:" ]
false
0.047018
0.04462
1.053738
[ "s521256635", "s986245020" ]
u094191970
p02556
python
s812785366
s330187328
461
238
48,776
24,904
Accepted
Accepted
48.37
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:tuple(map(int,stdin.readline().split())) n=int(eval(input())) l=set(tuple([lnii() for i in range(n)])) if len(l)==1: print((0)) exit() x_max=0 x_min=10**10 y_max=0 y_min=10**10 for x,y in l: # s=abs(x-y) s=x-y x_max=max(x_max,s) x_min=min(x_min,s) # t=abs(x+y) t=x+y y_max=max(y_max,t) y_min=min(y_min,t) x_ans=x_max-x_min y_ans=y_max-y_min print((max(x_ans,y_ans)))
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) n=int(eval(input())) z=[] w=[] for i in range(n): x,y=nii() z.append(x-y) w.append(x+y) z_ans=max(z)-min(z) w_ans=max(w)-min(w) print((max(z_ans,w_ans)))
31
16
490
288
from sys import stdin nii = lambda: list(map(int, stdin.readline().split())) lnii = lambda: tuple(map(int, stdin.readline().split())) n = int(eval(input())) l = set(tuple([lnii() for i in range(n)])) if len(l) == 1: print((0)) exit() x_max = 0 x_min = 10**10 y_max = 0 y_min = 10**10 for x, y in l: # s=abs(x-y) s = x - y x_max = max(x_max, s) x_min = min(x_min, s) # t=abs(x+y) t = x + y y_max = max(y_max, t) y_min = min(y_min, t) x_ans = x_max - x_min y_ans = y_max - y_min print((max(x_ans, y_ans)))
from sys import stdin nii = lambda: list(map(int, stdin.readline().split())) lnii = lambda: list(map(int, stdin.readline().split())) n = int(eval(input())) z = [] w = [] for i in range(n): x, y = nii() z.append(x - y) w.append(x + y) z_ans = max(z) - min(z) w_ans = max(w) - min(w) print((max(z_ans, w_ans)))
false
48.387097
[ "-lnii = lambda: tuple(map(int, stdin.readline().split()))", "+lnii = lambda: list(map(int, stdin.readline().split()))", "-l = set(tuple([lnii() for i in range(n)]))", "-if len(l) == 1:", "- print((0))", "- exit()", "-x_max = 0", "-x_min = 10**10", "-y_max = 0", "-y_min = 10**10", "-for x, y in l:", "- # s=abs(x-y)", "- s = x - y", "- x_max = max(x_max, s)", "- x_min = min(x_min, s)", "- # t=abs(x+y)", "- t = x + y", "- y_max = max(y_max, t)", "- y_min = min(y_min, t)", "-x_ans = x_max - x_min", "-y_ans = y_max - y_min", "-print((max(x_ans, y_ans)))", "+z = []", "+w = []", "+for i in range(n):", "+ x, y = nii()", "+ z.append(x - y)", "+ w.append(x + y)", "+z_ans = max(z) - min(z)", "+w_ans = max(w) - min(w)", "+print((max(z_ans, w_ans)))" ]
false
0.041592
0.037654
1.104598
[ "s812785366", "s330187328" ]
u645250356
p02954
python
s493268975
s590399670
340
112
73,528
12,056
Accepted
Accepted
67.06
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) s = eval(input()) n = len(s) cnt = 0 res = [0] * n for i,t in enumerate(s): if t == 'R': cnt += 1 elif cnt > 0: res[i-1] += (cnt+1)//2 res[i] += cnt//2 cnt = 0 # print(*res) for i in reversed(list(range(n))): if s[i] == 'L': cnt += 1 elif cnt > 0: res[i+1] += (cnt+1)//2 res[i] += cnt//2 cnt = 0 print((*res))
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) s = eval(input()) n = len(s) res = [0] * n cnt = 0 now = [0,0] for i in range(n): if s[i] == 'R': now[cnt%2] += 1 cnt += 1 else: res[i-1] += now[0] res[i] += now[1] now = [0,0] cnt = 0 for i in range(n)[::-1]: if s[i] == 'L': now[cnt%2] += 1 cnt += 1 else: res[i+1] += now[0] res[i] += now[1] now = [0,0] cnt = 0 print((*res))
30
34
789
800
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) s = eval(input()) n = len(s) cnt = 0 res = [0] * n for i, t in enumerate(s): if t == "R": cnt += 1 elif cnt > 0: res[i - 1] += (cnt + 1) // 2 res[i] += cnt // 2 cnt = 0 # print(*res) for i in reversed(list(range(n))): if s[i] == "L": cnt += 1 elif cnt > 0: res[i + 1] += (cnt + 1) // 2 res[i] += cnt // 2 cnt = 0 print((*res))
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) s = eval(input()) n = len(s) res = [0] * n cnt = 0 now = [0, 0] for i in range(n): if s[i] == "R": now[cnt % 2] += 1 cnt += 1 else: res[i - 1] += now[0] res[i] += now[1] now = [0, 0] cnt = 0 for i in range(n)[::-1]: if s[i] == "L": now[cnt % 2] += 1 cnt += 1 else: res[i + 1] += now[0] res[i] += now[1] now = [0, 0] cnt = 0 print((*res))
false
11.764706
[ "-from heapq import heappop, heappush, heapify", "-import sys, bisect, math, itertools, fractions, pprint", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "+res = [0] * n", "-res = [0] * n", "-for i, t in enumerate(s):", "- if t == \"R\":", "+now = [0, 0]", "+for i in range(n):", "+ if s[i] == \"R\":", "+ now[cnt % 2] += 1", "- elif cnt > 0:", "- res[i - 1] += (cnt + 1) // 2", "- res[i] += cnt // 2", "+ else:", "+ res[i - 1] += now[0]", "+ res[i] += now[1]", "+ now = [0, 0]", "-# print(*res)", "-for i in reversed(list(range(n))):", "+for i in range(n)[::-1]:", "+ now[cnt % 2] += 1", "- elif cnt > 0:", "- res[i + 1] += (cnt + 1) // 2", "- res[i] += cnt // 2", "+ else:", "+ res[i + 1] += now[0]", "+ res[i] += now[1]", "+ now = [0, 0]" ]
false
0.042738
0.134101
0.318701
[ "s493268975", "s590399670" ]
u690536347
p02929
python
s197955005
s164995533
145
129
16,344
12,340
Accepted
Accepted
11.03
N = int(eval(input())) S = eval(input()) MOD = 10**9+7 if S[0]=="W" or S[-1]=="W": print((0)) else: l = [0]*(2*N) for i in range(1, 2*N): if S[i]==S[i-1]: l[i] = 1 if l[i-1]==0 else 0 else: l[i] = 0 if l[i-1]==0 else 1 pair = sum(l) fac = [None]*(N+1) fac[1] = 1 for i in range(2, N+1): fac[i] = fac[i-1] * i fac[i] %= MOD ans = 0 if pair==N: buf = 0 ans = 1 for i in l[::-1]: if i: buf += 1 else: ans *= buf ans %= MOD buf -= 1 ans *= fac[N] ans %= MOD print(ans)
N = int(eval(input())) S = eval(input()) MOD = 10**9+7 if S[0]=="W" or S[-1]=="W": print((0)) else: l = [0]*(2*N) for i in range(1, 2*N): if S[i]==S[i-1]: l[i] = 0 if l[i-1] else 1 else: l[i] = 1 if l[i-1] else 0 pair = sum(l) facN = 1 for i in range(2, N+1): facN *= i facN %= MOD ans = 0 if pair==N: buf = 0 ans = facN for i in l[::-1]: if i: buf += 1 else: ans *= buf ans %= MOD buf -= 1 print(ans)
36
32
722
626
N = int(eval(input())) S = eval(input()) MOD = 10**9 + 7 if S[0] == "W" or S[-1] == "W": print((0)) else: l = [0] * (2 * N) for i in range(1, 2 * N): if S[i] == S[i - 1]: l[i] = 1 if l[i - 1] == 0 else 0 else: l[i] = 0 if l[i - 1] == 0 else 1 pair = sum(l) fac = [None] * (N + 1) fac[1] = 1 for i in range(2, N + 1): fac[i] = fac[i - 1] * i fac[i] %= MOD ans = 0 if pair == N: buf = 0 ans = 1 for i in l[::-1]: if i: buf += 1 else: ans *= buf ans %= MOD buf -= 1 ans *= fac[N] ans %= MOD print(ans)
N = int(eval(input())) S = eval(input()) MOD = 10**9 + 7 if S[0] == "W" or S[-1] == "W": print((0)) else: l = [0] * (2 * N) for i in range(1, 2 * N): if S[i] == S[i - 1]: l[i] = 0 if l[i - 1] else 1 else: l[i] = 1 if l[i - 1] else 0 pair = sum(l) facN = 1 for i in range(2, N + 1): facN *= i facN %= MOD ans = 0 if pair == N: buf = 0 ans = facN for i in l[::-1]: if i: buf += 1 else: ans *= buf ans %= MOD buf -= 1 print(ans)
false
11.111111
[ "- l[i] = 1 if l[i - 1] == 0 else 0", "+ l[i] = 0 if l[i - 1] else 1", "- l[i] = 0 if l[i - 1] == 0 else 1", "+ l[i] = 1 if l[i - 1] else 0", "- fac = [None] * (N + 1)", "- fac[1] = 1", "+ facN = 1", "- fac[i] = fac[i - 1] * i", "- fac[i] %= MOD", "+ facN *= i", "+ facN %= MOD", "- ans = 1", "+ ans = facN", "- ans *= fac[N]", "- ans %= MOD" ]
false
0.13962
0.119366
1.169679
[ "s197955005", "s164995533" ]
u627600101
p02696
python
s093296447
s595954735
23
20
9,180
9,168
Accepted
Accepted
13.04
A, B, N = list(map(int,input().split())) import math x3 = min(N,B-1) def f(x): t = math.floor((A*x)/B) - A * math.floor(x/B) return int(t) print((f(x3)))
A, B, N = list(map(int,input().split())) import math x1 = N x2 = min(N,B-1) def f(x): return A*x//B - A*(x//B) print((max(f(x1),f(x2))))
8
7
162
139
A, B, N = list(map(int, input().split())) import math x3 = min(N, B - 1) def f(x): t = math.floor((A * x) / B) - A * math.floor(x / B) return int(t) print((f(x3)))
A, B, N = list(map(int, input().split())) import math x1 = N x2 = min(N, B - 1) def f(x): return A * x // B - A * (x // B) print((max(f(x1), f(x2))))
false
12.5
[ "-x3 = min(N, B - 1)", "+x1 = N", "+x2 = min(N, B - 1)", "- t = math.floor((A * x) / B) - A * math.floor(x / B)", "- return int(t)", "+ return A * x // B - A * (x // B)", "-print((f(x3)))", "+print((max(f(x1), f(x2))))" ]
false
0.098413
0.065628
1.499553
[ "s093296447", "s595954735" ]
u761320129
p04019
python
s532527685
s961546843
21
17
3,316
2,940
Accepted
Accepted
19.05
from collections import Counter S = input() c = Counter(S) if (c['N'] > 0 and c['S'] == 0) or (c['S'] > 0 and c['N'] == 0) or\ (c['W'] > 0 and c['E'] == 0) or (c['E'] > 0 and c['W'] == 0): print('No') else: print('Yes')
S = eval(input()) n = 'N' in S w = 'W' in S s = 'S' in S e = 'E' in S print(('No' if (n and not s) or (s and not n) or (w and not e) or (e and not w) else 'Yes'))
8
6
237
160
from collections import Counter S = input() c = Counter(S) if ( (c["N"] > 0 and c["S"] == 0) or (c["S"] > 0 and c["N"] == 0) or (c["W"] > 0 and c["E"] == 0) or (c["E"] > 0 and c["W"] == 0) ): print("No") else: print("Yes")
S = eval(input()) n = "N" in S w = "W" in S s = "S" in S e = "E" in S print( ( "No" if (n and not s) or (s and not n) or (w and not e) or (e and not w) else "Yes" ) )
false
25
[ "-from collections import Counter", "-", "-S = input()", "-c = Counter(S)", "-if (", "- (c[\"N\"] > 0 and c[\"S\"] == 0)", "- or (c[\"S\"] > 0 and c[\"N\"] == 0)", "- or (c[\"W\"] > 0 and c[\"E\"] == 0)", "- or (c[\"E\"] > 0 and c[\"W\"] == 0)", "-):", "- print(\"No\")", "-else:", "- print(\"Yes\")", "+S = eval(input())", "+n = \"N\" in S", "+w = \"W\" in S", "+s = \"S\" in S", "+e = \"E\" in S", "+print(", "+ (", "+ \"No\"", "+ if (n and not s) or (s and not n) or (w and not e) or (e and not w)", "+ else \"Yes\"", "+ )", "+)" ]
false
0.040164
0.037719
1.064807
[ "s532527685", "s961546843" ]
u407160848
p02945
python
s622684648
s798037610
177
17
38,384
2,940
Accepted
Accepted
90.4
import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def s(generator, splitter, mapper): return [ mapper(s) for s in generator().split(splitter) ] # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] # 改行区切りの入力をn行読み込んで数値リストにして返します。 def get_nums_n(n): return [ int(eval(input())) for _ in range(n)] a,b = get_nums_l() print((max(a+b, a-b, a*b)))
import sys def log(*args, **kwargs): print(*args, file=sys.stderr) log("hogehoge") a,b = map(int, input().split()) print(max(a*b, a+b, a-b))
19
11
470
159
import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def s(generator, splitter, mapper): return [mapper(s) for s in generator().split(splitter)] # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [int(s) for s in input().split(" ")] # 改行区切りの入力をn行読み込んで数値リストにして返します。 def get_nums_n(n): return [int(eval(input())) for _ in range(n)] a, b = get_nums_l() print((max(a + b, a - b, a * b)))
import sys def log(*args, **kwargs): print(*args, file=sys.stderr) log("hogehoge") a, b = map(int, input().split()) print(max(a * b, a + b, a - b))
false
42.105263
[ "-import math", "-from functools import reduce", "-from collections import deque", "-sys.setrecursionlimit(10**7)", "+", "+def log(*args, **kwargs):", "+ print(*args, file=sys.stderr)", "-def s(generator, splitter, mapper):", "- return [mapper(s) for s in generator().split(splitter)]", "-", "-", "-# スペース区切りの入力を読み込んで数値リストにして返します。", "-def get_nums_l():", "- return [int(s) for s in input().split(\" \")]", "-", "-", "-# 改行区切りの入力をn行読み込んで数値リストにして返します。", "-def get_nums_n(n):", "- return [int(eval(input())) for _ in range(n)]", "-", "-", "-a, b = get_nums_l()", "-print((max(a + b, a - b, a * b)))", "+log(\"hogehoge\")", "+a, b = map(int, input().split())", "+print(max(a * b, a + b, a - b))" ]
false
0.041453
0.040838
1.015059
[ "s622684648", "s798037610" ]
u210545407
p04043
python
s373453388
s578374161
27
23
8,972
9,040
Accepted
Accepted
14.81
A, B, C=list(map(int, input().split(" "))) if ([A, B, C].count(5)==2) and ([A, B, C].count(7)==1): print('YES') else: print('NO')
data=list(map(int, input().split(" "))) if (data.count(5)==2) and (data.count(7)==1): print('YES') else: print('NO')
5
5
138
124
A, B, C = list(map(int, input().split(" "))) if ([A, B, C].count(5) == 2) and ([A, B, C].count(7) == 1): print("YES") else: print("NO")
data = list(map(int, input().split(" "))) if (data.count(5) == 2) and (data.count(7) == 1): print("YES") else: print("NO")
false
0
[ "-A, B, C = list(map(int, input().split(\" \")))", "-if ([A, B, C].count(5) == 2) and ([A, B, C].count(7) == 1):", "+data = list(map(int, input().split(\" \")))", "+if (data.count(5) == 2) and (data.count(7) == 1):" ]
false
0.036996
0.038909
0.950822
[ "s373453388", "s578374161" ]
u254871849
p03449
python
s058468415
s403577723
277
17
20,360
3,064
Accepted
Accepted
93.86
import sys import numpy as np I = np.array(sys.stdin.read().split(), dtype=np.int64) n = I[0] l1, l2 = I[1:].reshape(2, n) def main(): res = 0 for i in range(n): res = max(res, np.sum(l1[:i+1]) + np.sum(l2[i:])) return res if __name__ == '__main__': ans = main() print(ans)
import sys n = int(sys.stdin.readline().rstrip()) a = [0] + [int(x) for x in sys.stdin.readline().split()] b = [0] + [int(x) for x in sys.stdin.readline().split()] def main(): for i in range(n): a[i+1] += a[i] b[i+1] += b[i] res = 0 for i in range(1, n + 1): res = max(res, a[i] + b[n] - b[i-1]) print(res) if __name__ == '__main__': main()
16
17
320
404
import sys import numpy as np I = np.array(sys.stdin.read().split(), dtype=np.int64) n = I[0] l1, l2 = I[1:].reshape(2, n) def main(): res = 0 for i in range(n): res = max(res, np.sum(l1[: i + 1]) + np.sum(l2[i:])) return res if __name__ == "__main__": ans = main() print(ans)
import sys n = int(sys.stdin.readline().rstrip()) a = [0] + [int(x) for x in sys.stdin.readline().split()] b = [0] + [int(x) for x in sys.stdin.readline().split()] def main(): for i in range(n): a[i + 1] += a[i] b[i + 1] += b[i] res = 0 for i in range(1, n + 1): res = max(res, a[i] + b[n] - b[i - 1]) print(res) if __name__ == "__main__": main()
false
5.882353
[ "-import numpy as np", "-I = np.array(sys.stdin.read().split(), dtype=np.int64)", "-n = I[0]", "-l1, l2 = I[1:].reshape(2, n)", "+n = int(sys.stdin.readline().rstrip())", "+a = [0] + [int(x) for x in sys.stdin.readline().split()]", "+b = [0] + [int(x) for x in sys.stdin.readline().split()]", "+ for i in range(n):", "+ a[i + 1] += a[i]", "+ b[i + 1] += b[i]", "- for i in range(n):", "- res = max(res, np.sum(l1[: i + 1]) + np.sum(l2[i:]))", "- return res", "+ for i in range(1, n + 1):", "+ res = max(res, a[i] + b[n] - b[i - 1])", "+ print(res)", "- ans = main()", "- print(ans)", "+ main()" ]
false
0.193508
0.036909
5.24289
[ "s058468415", "s403577723" ]
u103902792
p02922
python
s419128409
s232284268
173
17
38,256
2,940
Accepted
Accepted
90.17
a,b = list(map(int,input().split())) ans = 0 tap = 1 while tap < b: tap += a-1 ans += 1 print(ans)
a,b = list(map(int,input().split())) ans = 0 tap = 1 while tap < b: ans += 1 tap += a-1 print(ans)
9
7
108
102
a, b = list(map(int, input().split())) ans = 0 tap = 1 while tap < b: tap += a - 1 ans += 1 print(ans)
a, b = list(map(int, input().split())) ans = 0 tap = 1 while tap < b: ans += 1 tap += a - 1 print(ans)
false
22.222222
[ "+ ans += 1", "- ans += 1" ]
false
0.041583
0.081564
0.509817
[ "s419128409", "s232284268" ]
u340781749
p03216
python
s598159606
s441655277
2,057
1,896
147,172
107,252
Accepted
Accepted
7.83
from itertools import accumulate n = int(eval(input())) s = eval(input()) acc_cnt_a = [0] * (n + 1) acc_cnt_b = [0] * (n + 1) acc_cnt_ab = [0] * (n + 1) c_loc = [] cnt_a = 0 for i, c in enumerate(s): if c == 'D': acc_cnt_a[i] += 1 cnt_a += 1 elif c == 'M': acc_cnt_b[i] += 1 acc_cnt_ab[i] += cnt_a elif c == 'C': c_loc.append(i + 1) acc_cnt_a = [0] + list(accumulate(acc_cnt_a)) acc_cnt_b = [0] + list(accumulate(acc_cnt_b)) acc_cnt_ab = [0] + list(accumulate(acc_cnt_ab)) q = int(eval(input())) buf = [] for k in map(int, input().split()): ans = 0 for r in c_loc: l = r - k if l > 0: rejected_a = acc_cnt_a[l] cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l] cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l] ans += cnt_internal_ab - rejected_a * cnt_internal_b else: ans += acc_cnt_ab[r] buf.append(ans) print(('\n'.join(map(str, buf))))
n = int(eval(input())) s = eval(input()) acc_cnt_a = [0] * (n + 1) acc_cnt_b = [0] * (n + 1) acc_cnt_ab = [0] * (n + 1) c_loc = [] cnt_a = 0 cnt_b = 0 cnt_ab = 0 for i, c in enumerate(s): if c == 'D': cnt_a += 1 elif c == 'M': cnt_b += 1 cnt_ab += cnt_a elif c == 'C': c_loc.append(i + 1) acc_cnt_a[i + 1] = cnt_a acc_cnt_b[i + 1] = cnt_b acc_cnt_ab[i + 1] = cnt_ab q = int(eval(input())) buf = [] for k in map(int, input().split()): ans = 0 for r in c_loc: l = r - k if l > 0: rejected_a = acc_cnt_a[l] cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l] cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l] ans += cnt_internal_ab - rejected_a * cnt_internal_b else: ans += acc_cnt_ab[r] buf.append(ans) print(('\n'.join(map(str, buf))))
37
36
1,000
895
from itertools import accumulate n = int(eval(input())) s = eval(input()) acc_cnt_a = [0] * (n + 1) acc_cnt_b = [0] * (n + 1) acc_cnt_ab = [0] * (n + 1) c_loc = [] cnt_a = 0 for i, c in enumerate(s): if c == "D": acc_cnt_a[i] += 1 cnt_a += 1 elif c == "M": acc_cnt_b[i] += 1 acc_cnt_ab[i] += cnt_a elif c == "C": c_loc.append(i + 1) acc_cnt_a = [0] + list(accumulate(acc_cnt_a)) acc_cnt_b = [0] + list(accumulate(acc_cnt_b)) acc_cnt_ab = [0] + list(accumulate(acc_cnt_ab)) q = int(eval(input())) buf = [] for k in map(int, input().split()): ans = 0 for r in c_loc: l = r - k if l > 0: rejected_a = acc_cnt_a[l] cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l] cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l] ans += cnt_internal_ab - rejected_a * cnt_internal_b else: ans += acc_cnt_ab[r] buf.append(ans) print(("\n".join(map(str, buf))))
n = int(eval(input())) s = eval(input()) acc_cnt_a = [0] * (n + 1) acc_cnt_b = [0] * (n + 1) acc_cnt_ab = [0] * (n + 1) c_loc = [] cnt_a = 0 cnt_b = 0 cnt_ab = 0 for i, c in enumerate(s): if c == "D": cnt_a += 1 elif c == "M": cnt_b += 1 cnt_ab += cnt_a elif c == "C": c_loc.append(i + 1) acc_cnt_a[i + 1] = cnt_a acc_cnt_b[i + 1] = cnt_b acc_cnt_ab[i + 1] = cnt_ab q = int(eval(input())) buf = [] for k in map(int, input().split()): ans = 0 for r in c_loc: l = r - k if l > 0: rejected_a = acc_cnt_a[l] cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l] cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l] ans += cnt_internal_ab - rejected_a * cnt_internal_b else: ans += acc_cnt_ab[r] buf.append(ans) print(("\n".join(map(str, buf))))
false
2.702703
[ "-from itertools import accumulate", "-", "+cnt_b = 0", "+cnt_ab = 0", "- acc_cnt_a[i] += 1", "- acc_cnt_b[i] += 1", "- acc_cnt_ab[i] += cnt_a", "+ cnt_b += 1", "+ cnt_ab += cnt_a", "-acc_cnt_a = [0] + list(accumulate(acc_cnt_a))", "-acc_cnt_b = [0] + list(accumulate(acc_cnt_b))", "-acc_cnt_ab = [0] + list(accumulate(acc_cnt_ab))", "+ acc_cnt_a[i + 1] = cnt_a", "+ acc_cnt_b[i + 1] = cnt_b", "+ acc_cnt_ab[i + 1] = cnt_ab" ]
false
0.048457
0.049163
0.985635
[ "s598159606", "s441655277" ]
u644907318
p02861
python
s018159047
s438669038
208
98
40,812
74,508
Accepted
Accepted
52.88
from itertools import permutations def dist(x,y): return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5 N = int(eval(input())) X = [list(map(int,input().split())) for _ in range(N)] tot = 0 cnt = 0 for z in permutations(list(range(N))): cnt += 1 for i in range(1,N): tot += dist(X[z[i]],X[z[i-1]]) print((tot/cnt))
from itertools import permutations def dist(x,y): return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5 N = int(eval(input())) X = [list(map(int,input().split())) for _ in range(N)] cnt = 0 for z in permutations(list(range(N)),N): for i in range(1,N): cnt += dist(X[z[i]],X[z[i-1]]) k = 1 for i in range(2,N+1): k = k*i print((cnt/k))
12
13
321
342
from itertools import permutations def dist(x, y): return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5 N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] tot = 0 cnt = 0 for z in permutations(list(range(N))): cnt += 1 for i in range(1, N): tot += dist(X[z[i]], X[z[i - 1]]) print((tot / cnt))
from itertools import permutations def dist(x, y): return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5 N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] cnt = 0 for z in permutations(list(range(N)), N): for i in range(1, N): cnt += dist(X[z[i]], X[z[i - 1]]) k = 1 for i in range(2, N + 1): k = k * i print((cnt / k))
false
7.692308
[ "-tot = 0", "-for z in permutations(list(range(N))):", "- cnt += 1", "+for z in permutations(list(range(N)), N):", "- tot += dist(X[z[i]], X[z[i - 1]])", "-print((tot / cnt))", "+ cnt += dist(X[z[i]], X[z[i - 1]])", "+k = 1", "+for i in range(2, N + 1):", "+ k = k * i", "+print((cnt / k))" ]
false
0.05473
0.040338
1.356762
[ "s018159047", "s438669038" ]
u987164499
p02984
python
s549886507
s369173501
145
116
14,032
14,028
Accepted
Accepted
20
from sys import stdin n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) point = 0 for i in range(n): if i%2 == 0: point += li[i] else: point -= li[i] lin = [point] for i in range(n-1): lin.append((li[i]-lin[i]//2)*2) print((*lin))
n = int(eval(input())) a = list(map(int,input().split())) s = sum(a) start = s-2*sum(a[1::2]) li = [start] for i in range(1,n): li.append(2*a[i-1]-li[-1]) print((*li))
13
13
307
180
from sys import stdin n = int(stdin.readline().rstrip()) li = list(map(int, stdin.readline().rstrip().split())) point = 0 for i in range(n): if i % 2 == 0: point += li[i] else: point -= li[i] lin = [point] for i in range(n - 1): lin.append((li[i] - lin[i] // 2) * 2) print((*lin))
n = int(eval(input())) a = list(map(int, input().split())) s = sum(a) start = s - 2 * sum(a[1::2]) li = [start] for i in range(1, n): li.append(2 * a[i - 1] - li[-1]) print((*li))
false
0
[ "-from sys import stdin", "-", "-n = int(stdin.readline().rstrip())", "-li = list(map(int, stdin.readline().rstrip().split()))", "-point = 0", "-for i in range(n):", "- if i % 2 == 0:", "- point += li[i]", "- else:", "- point -= li[i]", "-lin = [point]", "-for i in range(n - 1):", "- lin.append((li[i] - lin[i] // 2) * 2)", "-print((*lin))", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+s = sum(a)", "+start = s - 2 * sum(a[1::2])", "+li = [start]", "+for i in range(1, n):", "+ li.append(2 * a[i - 1] - li[-1])", "+print((*li))" ]
false
0.041685
0.038637
1.078878
[ "s549886507", "s369173501" ]
u691018832
p03229
python
s982917258
s072111488
837
80
9,320
13,028
Accepted
Accepted
90.44
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import deque from math import ceil n = int(readline()) a = sorted([int(readline()) for i in range(n)]) c = deque(a[:ceil(n / 2)]) d = deque(a[ceil(n / 2):]) b = deque(a[n // 2:]) a = deque(a[:n // 2]) check_1 = deque([a.popleft()]) check_2 = deque([d.pop()]) for i in range(n // 2): if i % 2 == 0: check_1.appendleft(b.pop()) check_2.appendleft(c.popleft()) if len(b) == 0: if len(a) != 0: check_1.append(a.popleft()) check_2.append(d.pop()) break check_1.append(b.pop()) check_2.append(c.popleft()) else: check_1.appendleft(a.popleft()) check_2.appendleft(d.pop()) if len(a) == 0: if len(b) != 0: check_1.append(b.pop()) check_2.append(c.popleft()) break check_1.append(a.popleft()) check_2.append(d.pop()) cnt_1 = 0 cnt_2 = 0 for i in range(1, n): cnt_1 += abs(check_1[i - 1] - check_1[i]) cnt_2 += abs(check_2[i - 1] - check_2[i]) print((max(cnt_1, cnt_2)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, *a = list(map(int, read().split())) a.sort() a1 = 2 * (sum(a[(n + 1) // 2:]) - sum(a[:(n + 1) // 2])) a2 = 2 * (sum(a[n // 2:]) - sum(a[:n // 2])) if n % 2 == 0: v = a[n // 2] - a[n // 2 - 1] a1 -= v a2 -= v else: a1 += a[n // 2 - 1] + a[n // 2] a2 -= a[n // 2 + 1] + a[n // 2] print((max(a1, a2)))
44
18
1,276
479
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import deque from math import ceil n = int(readline()) a = sorted([int(readline()) for i in range(n)]) c = deque(a[: ceil(n / 2)]) d = deque(a[ceil(n / 2) :]) b = deque(a[n // 2 :]) a = deque(a[: n // 2]) check_1 = deque([a.popleft()]) check_2 = deque([d.pop()]) for i in range(n // 2): if i % 2 == 0: check_1.appendleft(b.pop()) check_2.appendleft(c.popleft()) if len(b) == 0: if len(a) != 0: check_1.append(a.popleft()) check_2.append(d.pop()) break check_1.append(b.pop()) check_2.append(c.popleft()) else: check_1.appendleft(a.popleft()) check_2.appendleft(d.pop()) if len(a) == 0: if len(b) != 0: check_1.append(b.pop()) check_2.append(c.popleft()) break check_1.append(a.popleft()) check_2.append(d.pop()) cnt_1 = 0 cnt_2 = 0 for i in range(1, n): cnt_1 += abs(check_1[i - 1] - check_1[i]) cnt_2 += abs(check_2[i - 1] - check_2[i]) print((max(cnt_1, cnt_2)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, *a = list(map(int, read().split())) a.sort() a1 = 2 * (sum(a[(n + 1) // 2 :]) - sum(a[: (n + 1) // 2])) a2 = 2 * (sum(a[n // 2 :]) - sum(a[: n // 2])) if n % 2 == 0: v = a[n // 2] - a[n // 2 - 1] a1 -= v a2 -= v else: a1 += a[n // 2 - 1] + a[n // 2] a2 -= a[n // 2 + 1] + a[n // 2] print((max(a1, a2)))
false
59.090909
[ "-from collections import deque", "-from math import ceil", "-", "-n = int(readline())", "-a = sorted([int(readline()) for i in range(n)])", "-c = deque(a[: ceil(n / 2)])", "-d = deque(a[ceil(n / 2) :])", "-b = deque(a[n // 2 :])", "-a = deque(a[: n // 2])", "-check_1 = deque([a.popleft()])", "-check_2 = deque([d.pop()])", "-for i in range(n // 2):", "- if i % 2 == 0:", "- check_1.appendleft(b.pop())", "- check_2.appendleft(c.popleft())", "- if len(b) == 0:", "- if len(a) != 0:", "- check_1.append(a.popleft())", "- check_2.append(d.pop())", "- break", "- check_1.append(b.pop())", "- check_2.append(c.popleft())", "- else:", "- check_1.appendleft(a.popleft())", "- check_2.appendleft(d.pop())", "- if len(a) == 0:", "- if len(b) != 0:", "- check_1.append(b.pop())", "- check_2.append(c.popleft())", "- break", "- check_1.append(a.popleft())", "- check_2.append(d.pop())", "-cnt_1 = 0", "-cnt_2 = 0", "-for i in range(1, n):", "- cnt_1 += abs(check_1[i - 1] - check_1[i])", "- cnt_2 += abs(check_2[i - 1] - check_2[i])", "-print((max(cnt_1, cnt_2)))", "+n, *a = list(map(int, read().split()))", "+a.sort()", "+a1 = 2 * (sum(a[(n + 1) // 2 :]) - sum(a[: (n + 1) // 2]))", "+a2 = 2 * (sum(a[n // 2 :]) - sum(a[: n // 2]))", "+if n % 2 == 0:", "+ v = a[n // 2] - a[n // 2 - 1]", "+ a1 -= v", "+ a2 -= v", "+else:", "+ a1 += a[n // 2 - 1] + a[n // 2]", "+ a2 -= a[n // 2 + 1] + a[n // 2]", "+print((max(a1, a2)))" ]
false
0.047501
0.043964
1.080444
[ "s982917258", "s072111488" ]
u811733736
p02329
python
s717837660
s515450781
3,630
3,070
102,904
102,524
Accepted
Accepted
15.43
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A TLE """ import sys from sys import stdin from bisect import bisect_right, bisect_left input = stdin.readline def main(args): N, V = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] D = [int(x) for x in input().split()] AB = [] for i in A: for j in B: AB.append(i+j) AB.sort() CD = [float('-inf'), float('inf')] for i in C: for j in D: CD.append(i+j) CD.sort() count = 0 for ab in AB: i = bisect_left(CD, V - ab) j = bisect_right(CD, V - ab) count += max((j-i), 0) print(count) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A AC """ import sys from sys import stdin from bisect import bisect_right, bisect_left input = stdin.readline def main(args): N, V = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] D = [int(x) for x in input().split()] #AB = [] #for i in A: # for j in B: # AB.append(i+j) AB = [a+b for a in A for b in B] #AB.sort() #CD = [float('-inf'), float('inf')] #for i in C: # for j in D: # CD.append(i+j) CD = [c+d for c in C for d in D] CD.append(float('-inf')) CD.append(float('inf')) CD.sort() count = 0 for ab in AB: i = bisect_left(CD, V - ab) j = bisect_right(CD, V - ab) count += max((j-i), 0) print(count) if __name__ == '__main__': main(sys.argv[1:])
41
45
884
1,019
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A TLE """ import sys from sys import stdin from bisect import bisect_right, bisect_left input = stdin.readline def main(args): N, V = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] D = [int(x) for x in input().split()] AB = [] for i in A: for j in B: AB.append(i + j) AB.sort() CD = [float("-inf"), float("inf")] for i in C: for j in D: CD.append(i + j) CD.sort() count = 0 for ab in AB: i = bisect_left(CD, V - ab) j = bisect_right(CD, V - ab) count += max((j - i), 0) print(count) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A AC """ import sys from sys import stdin from bisect import bisect_right, bisect_left input = stdin.readline def main(args): N, V = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] D = [int(x) for x in input().split()] # AB = [] # for i in A: # for j in B: # AB.append(i+j) AB = [a + b for a in A for b in B] # AB.sort() # CD = [float('-inf'), float('inf')] # for i in C: # for j in D: # CD.append(i+j) CD = [c + d for c in C for d in D] CD.append(float("-inf")) CD.append(float("inf")) CD.sort() count = 0 for ab in AB: i = bisect_left(CD, V - ab) j = bisect_right(CD, V - ab) count += max((j - i), 0) print(count) if __name__ == "__main__": main(sys.argv[1:])
false
8.888889
[ "-TLE", "+AC", "- AB = []", "- for i in A:", "- for j in B:", "- AB.append(i + j)", "- AB.sort()", "- CD = [float(\"-inf\"), float(\"inf\")]", "- for i in C:", "- for j in D:", "- CD.append(i + j)", "+ # AB = []", "+ # for i in A:", "+ # for j in B:", "+ # AB.append(i+j)", "+ AB = [a + b for a in A for b in B]", "+ # AB.sort()", "+ # CD = [float('-inf'), float('inf')]", "+ # for i in C:", "+ # for j in D:", "+ # CD.append(i+j)", "+ CD = [c + d for c in C for d in D]", "+ CD.append(float(\"-inf\"))", "+ CD.append(float(\"inf\"))" ]
false
0.045104
0.069154
0.65223
[ "s717837660", "s515450781" ]
u585482323
p02900
python
s383024667
s477988956
216
196
39,280
38,512
Accepted
Accepted
9.26
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n = I() print(((n-(n>>1))/n)) return #B def B(): n,k = LI() h = LI() ans = 0 for i in h: if i >= k: ans += 1 print(ans) return #C def C(): n = I() a = LI() b = [(a[i],i+1) for i in range(n)] b.sort() ans = [b[i][1] for i in range(n)] print((*ans)) return #D def D(): def divisor(n): if n < 4: return set([n]) res = set([1]) i = 2 m = n while i**2 <= n: if m%i == 0: while m%i == 0: m //= i res.add(i) i += 1 res.add(m) return res a,b = LI() if min(a,b) == 1: print((1)) return s = divisor(a) t = divisor(b) s &= t print((len(s))) return #E def E(): n,m = LI() return #F def F(): return #Solve if __name__ == "__main__": D()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def f(n): res = set([1]) i = 2 m = n while i**2 <= n: while m%i == 0: res.add(i) m //= i i += 1 res.add(m) return res a,b = LI() fa = f(a) fb = f(b) l = fa&fb print((len(l))) return #Solve if __name__ == "__main__": solve()
93
50
1,687
1,138
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 # A def A(): n = I() print(((n - (n >> 1)) / n)) return # B def B(): n, k = LI() h = LI() ans = 0 for i in h: if i >= k: ans += 1 print(ans) return # C def C(): n = I() a = LI() b = [(a[i], i + 1) for i in range(n)] b.sort() ans = [b[i][1] for i in range(n)] print((*ans)) return # D def D(): def divisor(n): if n < 4: return set([n]) res = set([1]) i = 2 m = n while i**2 <= n: if m % i == 0: while m % i == 0: m //= i res.add(i) i += 1 res.add(m) return res a, b = LI() if min(a, b) == 1: print((1)) return s = divisor(a) t = divisor(b) s &= t print((len(s))) return # E def E(): n, m = LI() return # F def F(): return # Solve if __name__ == "__main__": D()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def f(n): res = set([1]) i = 2 m = n while i**2 <= n: while m % i == 0: res.add(i) m //= i i += 1 res.add(m) return res a, b = LI() fa = f(a) fb = f(b) l = fa & fb print((len(l))) return # Solve if __name__ == "__main__": solve()
false
46.236559
[ "+from itertools import permutations, accumulate", "-import random", "- return [int(x) for x in sys.stdin.readline().split()]", "+ return [int(x) for x in sys.stdin.buffer.readline().split()]", "- return int(sys.stdin.readline())", "+ return int(sys.stdin.buffer.readline())", "-# A", "-def A():", "- n = I()", "- print(((n - (n >> 1)) / n))", "- return", "-# B", "-def B():", "- n, k = LI()", "- h = LI()", "- ans = 0", "- for i in h:", "- if i >= k:", "- ans += 1", "- print(ans)", "- return", "-", "-", "-# C", "-def C():", "- n = I()", "- a = LI()", "- b = [(a[i], i + 1) for i in range(n)]", "- b.sort()", "- ans = [b[i][1] for i in range(n)]", "- print((*ans))", "- return", "-", "-", "-# D", "-def D():", "- def divisor(n):", "- if n < 4:", "- return set([n])", "+def solve():", "+ def f(n):", "- if m % i == 0:", "- while m % i == 0:", "- m //= i", "+ while m % i == 0:", "+ m //= i", "- if min(a, b) == 1:", "- print((1))", "- return", "- s = divisor(a)", "- t = divisor(b)", "- s &= t", "- print((len(s)))", "- return", "-", "-", "-# E", "-def E():", "- n, m = LI()", "- return", "-", "-", "-# F", "-def F():", "+ fa = f(a)", "+ fb = f(b)", "+ l = fa & fb", "+ print((len(l)))", "- D()", "+ solve()" ]
false
0.040523
0.047119
0.86003
[ "s383024667", "s477988956" ]
u312025627
p03971
python
s092894409
s868768600
308
96
51,928
4,016
Accepted
Accepted
68.83
def main(): N, A, B = (int(i) for i in input().split()) S = eval(input()) b_cnt = 0 cnt = 0 for s in S: if s == 'a' and cnt < A + B: print("Yes") cnt += 1 elif s == 'b' and cnt < A + B and b_cnt < B: print("Yes") cnt += 1 b_cnt += 1 else: print("No") if __name__ == '__main__': main()
def main(): N, A, B = (int(i) for i in input().split()) S = eval(input()) cnt = 0 cnt_ob = 0 for s in S: if s == "a": if cnt < A+B: print("Yes") cnt += 1 else: print("No") elif s == "b": if cnt < A+B and cnt_ob < B: print("Yes") cnt += 1 cnt_ob += 1 else: print("No") else: print("No") if __name__ == '__main__': main()
19
25
419
560
def main(): N, A, B = (int(i) for i in input().split()) S = eval(input()) b_cnt = 0 cnt = 0 for s in S: if s == "a" and cnt < A + B: print("Yes") cnt += 1 elif s == "b" and cnt < A + B and b_cnt < B: print("Yes") cnt += 1 b_cnt += 1 else: print("No") if __name__ == "__main__": main()
def main(): N, A, B = (int(i) for i in input().split()) S = eval(input()) cnt = 0 cnt_ob = 0 for s in S: if s == "a": if cnt < A + B: print("Yes") cnt += 1 else: print("No") elif s == "b": if cnt < A + B and cnt_ob < B: print("Yes") cnt += 1 cnt_ob += 1 else: print("No") else: print("No") if __name__ == "__main__": main()
false
24
[ "- b_cnt = 0", "+ cnt_ob = 0", "- if s == \"a\" and cnt < A + B:", "- print(\"Yes\")", "- cnt += 1", "- elif s == \"b\" and cnt < A + B and b_cnt < B:", "- print(\"Yes\")", "- cnt += 1", "- b_cnt += 1", "+ if s == \"a\":", "+ if cnt < A + B:", "+ print(\"Yes\")", "+ cnt += 1", "+ else:", "+ print(\"No\")", "+ elif s == \"b\":", "+ if cnt < A + B and cnt_ob < B:", "+ print(\"Yes\")", "+ cnt += 1", "+ cnt_ob += 1", "+ else:", "+ print(\"No\")" ]
false
0.083111
0.089464
0.928988
[ "s092894409", "s868768600" ]
u285891772
p02804
python
s444603627
s444157327
418
203
49,344
29,644
Accepted
Accepted
51.44
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 #階乗# lim = 10**5 #必要そうな階乗の限界を入力 fact = [1] * (lim+1) for n in range(1, lim+1): fact[n] = n * fact[n-1] % mod #階乗の逆元# fact_inv = [1]*(lim+1) fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = n*fact_inv[n]%mod def C(n, r): if n < r: return 0 else: return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod N, K = MAP() A = LIST() A.sort() A_cnt = Counter(A) P = list(A_cnt.keys()) p = list(A_cnt.values()) #print("P={}".format(P)) #print("p={}".format(p)) p_acc = list(accumulate(p)) p_acc_rev = list(accumulate(p[::-1])) #print("p_acc={}".format(p_acc)) #print("p_acc_rev={}".format(p_acc_rev)) n = len(p) T = [[0]*4 for _ in range(n)] for i in range(n): T[i][0] = p_acc[i] for i in range(1, n): T[i][1] = p_acc[i-1] for i in range(n): T[(-i-1)][3] = p_acc_rev[i] for i in range(1, n): T[(-i-1)][2] = p_acc_rev[i-1] #for i in range(n): # print(T[i]) t = [0]*n for idx, x in enumerate(T): t[idx] = (C(x[0], K) - C(x[1], K) + C(x[2], K) - C(x[3], K))%mod ans = 0 for i in range(n): ans = (ans + P[i]*t[i]%mod)%mod print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 #階乗# lim = 10**5 #必要そうな階乗の限界を入力 fact = [1] * (lim+1) for n in range(1, lim+1): fact[n] = n * fact[n-1] % mod #階乗の逆元# fact_inv = [1]*(lim+1) fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = n*fact_inv[n]%mod def C(n, r): if n < r: return 0 else: return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod N, K = MAP() A = LIST() A.sort() max_sum = 0 for i in range(K-1, N): max_sum = (max_sum + A[i]*C(i, K-1)%mod)%mod A = A[::-1] min_sum = 0 for i in range(K-1, N): min_sum = (min_sum + A[i]*C(i, K-1)%mod)%mod print(((max_sum - min_sum)%mod))
90
57
2,104
1,573
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 # 階乗# lim = 10**5 # 必要そうな階乗の限界を入力 fact = [1] * (lim + 1) for n in range(1, lim + 1): fact[n] = n * fact[n - 1] % mod # 階乗の逆元# fact_inv = [1] * (lim + 1) fact_inv[lim] = pow(fact[lim], mod - 2, mod) for n in range(lim, 0, -1): fact_inv[n - 1] = n * fact_inv[n] % mod def C(n, r): if n < r: return 0 else: return (fact[n] * fact_inv[r] % mod) * fact_inv[n - r] % mod N, K = MAP() A = LIST() A.sort() A_cnt = Counter(A) P = list(A_cnt.keys()) p = list(A_cnt.values()) # print("P={}".format(P)) # print("p={}".format(p)) p_acc = list(accumulate(p)) p_acc_rev = list(accumulate(p[::-1])) # print("p_acc={}".format(p_acc)) # print("p_acc_rev={}".format(p_acc_rev)) n = len(p) T = [[0] * 4 for _ in range(n)] for i in range(n): T[i][0] = p_acc[i] for i in range(1, n): T[i][1] = p_acc[i - 1] for i in range(n): T[(-i - 1)][3] = p_acc_rev[i] for i in range(1, n): T[(-i - 1)][2] = p_acc_rev[i - 1] # for i in range(n): # print(T[i]) t = [0] * n for idx, x in enumerate(T): t[idx] = (C(x[0], K) - C(x[1], K) + C(x[2], K) - C(x[3], K)) % mod ans = 0 for i in range(n): ans = (ans + P[i] * t[i] % mod) % mod print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 # 階乗# lim = 10**5 # 必要そうな階乗の限界を入力 fact = [1] * (lim + 1) for n in range(1, lim + 1): fact[n] = n * fact[n - 1] % mod # 階乗の逆元# fact_inv = [1] * (lim + 1) fact_inv[lim] = pow(fact[lim], mod - 2, mod) for n in range(lim, 0, -1): fact_inv[n - 1] = n * fact_inv[n] % mod def C(n, r): if n < r: return 0 else: return (fact[n] * fact_inv[r] % mod) * fact_inv[n - r] % mod N, K = MAP() A = LIST() A.sort() max_sum = 0 for i in range(K - 1, N): max_sum = (max_sum + A[i] * C(i, K - 1) % mod) % mod A = A[::-1] min_sum = 0 for i in range(K - 1, N): min_sum = (min_sum + A[i] * C(i, K - 1) % mod) % mod print(((max_sum - min_sum) % mod))
false
36.666667
[ "-A_cnt = Counter(A)", "-P = list(A_cnt.keys())", "-p = list(A_cnt.values())", "-# print(\"P={}\".format(P))", "-# print(\"p={}\".format(p))", "-p_acc = list(accumulate(p))", "-p_acc_rev = list(accumulate(p[::-1]))", "-# print(\"p_acc={}\".format(p_acc))", "-# print(\"p_acc_rev={}\".format(p_acc_rev))", "-n = len(p)", "-T = [[0] * 4 for _ in range(n)]", "-for i in range(n):", "- T[i][0] = p_acc[i]", "-for i in range(1, n):", "- T[i][1] = p_acc[i - 1]", "-for i in range(n):", "- T[(-i - 1)][3] = p_acc_rev[i]", "-for i in range(1, n):", "- T[(-i - 1)][2] = p_acc_rev[i - 1]", "-# for i in range(n):", "-# \tprint(T[i])", "-t = [0] * n", "-for idx, x in enumerate(T):", "- t[idx] = (C(x[0], K) - C(x[1], K) + C(x[2], K) - C(x[3], K)) % mod", "-ans = 0", "-for i in range(n):", "- ans = (ans + P[i] * t[i] % mod) % mod", "-print(ans)", "+max_sum = 0", "+for i in range(K - 1, N):", "+ max_sum = (max_sum + A[i] * C(i, K - 1) % mod) % mod", "+A = A[::-1]", "+min_sum = 0", "+for i in range(K - 1, N):", "+ min_sum = (min_sum + A[i] * C(i, K - 1) % mod) % mod", "+print(((max_sum - min_sum) % mod))" ]
false
0.341344
0.417444
0.8177
[ "s444603627", "s444157327" ]
u224353074
p02720
python
s526739698
s766407118
275
222
45,300
56,376
Accepted
Accepted
19.27
from collections import deque K = int(eval(input())) q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]]) cnt = 0 while cnt != K: nums = q.popleft() last = nums[-1] if last == 9: tmp = nums.copy() tmp.append(8) q.append(tmp) tmp = nums.copy() tmp.append(9) q.append(tmp) elif last == 0: tmp = nums.copy() tmp.append(0) q.append(tmp) tmp = nums.copy() tmp.append(1) q.append(tmp) else: tmp = nums.copy() tmp.append(last-1) q.append(tmp) tmp = nums.copy() tmp.append(last) q.append(tmp) tmp = nums.copy() tmp.append(last+1) q.append(tmp) cnt += 1 ans = 0 l = len(nums) for i in range(l): ans += nums[i]*10**(l-i-1) print(ans)
K = int(eval(input())) lunlun = [1,2,3,4,5,6,7,8,9] p = 0 def lunlun_generator(now_lunlun): last = now_lunlun%10 if last-1>=0: yield 10*now_lunlun+last-1 yield 10*now_lunlun+last if last+1<=9: yield 10*now_lunlun+last+1 while 1: for new_lunlun in lunlun_generator(lunlun[p]): lunlun.append(new_lunlun) p += 1 if p == K: break print((lunlun[p-1]))
42
24
855
429
from collections import deque K = int(eval(input())) q = deque([[1], [2], [3], [4], [5], [6], [7], [8], [9]]) cnt = 0 while cnt != K: nums = q.popleft() last = nums[-1] if last == 9: tmp = nums.copy() tmp.append(8) q.append(tmp) tmp = nums.copy() tmp.append(9) q.append(tmp) elif last == 0: tmp = nums.copy() tmp.append(0) q.append(tmp) tmp = nums.copy() tmp.append(1) q.append(tmp) else: tmp = nums.copy() tmp.append(last - 1) q.append(tmp) tmp = nums.copy() tmp.append(last) q.append(tmp) tmp = nums.copy() tmp.append(last + 1) q.append(tmp) cnt += 1 ans = 0 l = len(nums) for i in range(l): ans += nums[i] * 10 ** (l - i - 1) print(ans)
K = int(eval(input())) lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] p = 0 def lunlun_generator(now_lunlun): last = now_lunlun % 10 if last - 1 >= 0: yield 10 * now_lunlun + last - 1 yield 10 * now_lunlun + last if last + 1 <= 9: yield 10 * now_lunlun + last + 1 while 1: for new_lunlun in lunlun_generator(lunlun[p]): lunlun.append(new_lunlun) p += 1 if p == K: break print((lunlun[p - 1]))
false
42.857143
[ "-from collections import deque", "+K = int(eval(input()))", "+lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]", "+p = 0", "-K = int(eval(input()))", "-q = deque([[1], [2], [3], [4], [5], [6], [7], [8], [9]])", "-cnt = 0", "-while cnt != K:", "- nums = q.popleft()", "- last = nums[-1]", "- if last == 9:", "- tmp = nums.copy()", "- tmp.append(8)", "- q.append(tmp)", "- tmp = nums.copy()", "- tmp.append(9)", "- q.append(tmp)", "- elif last == 0:", "- tmp = nums.copy()", "- tmp.append(0)", "- q.append(tmp)", "- tmp = nums.copy()", "- tmp.append(1)", "- q.append(tmp)", "- else:", "- tmp = nums.copy()", "- tmp.append(last - 1)", "- q.append(tmp)", "- tmp = nums.copy()", "- tmp.append(last)", "- q.append(tmp)", "- tmp = nums.copy()", "- tmp.append(last + 1)", "- q.append(tmp)", "- cnt += 1", "-ans = 0", "-l = len(nums)", "-for i in range(l):", "- ans += nums[i] * 10 ** (l - i - 1)", "-print(ans)", "+", "+def lunlun_generator(now_lunlun):", "+ last = now_lunlun % 10", "+ if last - 1 >= 0:", "+ yield 10 * now_lunlun + last - 1", "+ yield 10 * now_lunlun + last", "+ if last + 1 <= 9:", "+ yield 10 * now_lunlun + last + 1", "+", "+", "+while 1:", "+ for new_lunlun in lunlun_generator(lunlun[p]):", "+ lunlun.append(new_lunlun)", "+ p += 1", "+ if p == K:", "+ break", "+print((lunlun[p - 1]))" ]
false
0.070772
0.055002
1.286719
[ "s526739698", "s766407118" ]
u463655976
p02960
python
s439703180
s105400571
1,932
1,668
4,092
4,092
Accepted
Accepted
13.66
S = [int(x) if x != "?" else -1 for x in eval(input())] g = 10 ** 9 + 7 x = 1 DP = [[0] * 13 for _ in range(2)] DP[0][0] = 1 for i in range(len(S)): for j in range(13): DP[1][j] = DP[0][j] % g DP[0][j] = 0 for j in range(13): if S[i] == -1: s = (j*10)%13 e = (s+10)%13 else: s = (j*10+S[i])%13 e = (s+1)%13 DP[0][s] += DP[1][j] if s > e: DP[0][0] += DP[1][j] DP[0][e] -= DP[1][j] w = 0 for j in range(13): w += DP[0][j] DP[0][j] = w print((DP[0][5] % g))
S = [int(x) if x != "?" else -1 for x in eval(input())] g = 10 ** 9 + 7 x = 1 DP = [[0] * 13 for _ in range(2)] DP[0][0] = 1 for i in range(len(S)): DP[1], DP[0] = DP[0], DP[1] for j in range(13): DP[0][j] = 0 for j in range(13): if S[i] == -1: s = (j*10)%13 e = (s+10)%13 else: s = (j*10+S[i])%13 e = (s+1)%13 DP[0][s] += DP[1][j] if s > e: DP[0][0] += DP[1][j] DP[0][e] -= DP[1][j] w = 0 for j in range(13): w = (w + DP[0][j]) % g DP[0][j] = w print((DP[0][5] % g))
26
26
621
630
S = [int(x) if x != "?" else -1 for x in eval(input())] g = 10**9 + 7 x = 1 DP = [[0] * 13 for _ in range(2)] DP[0][0] = 1 for i in range(len(S)): for j in range(13): DP[1][j] = DP[0][j] % g DP[0][j] = 0 for j in range(13): if S[i] == -1: s = (j * 10) % 13 e = (s + 10) % 13 else: s = (j * 10 + S[i]) % 13 e = (s + 1) % 13 DP[0][s] += DP[1][j] if s > e: DP[0][0] += DP[1][j] DP[0][e] -= DP[1][j] w = 0 for j in range(13): w += DP[0][j] DP[0][j] = w print((DP[0][5] % g))
S = [int(x) if x != "?" else -1 for x in eval(input())] g = 10**9 + 7 x = 1 DP = [[0] * 13 for _ in range(2)] DP[0][0] = 1 for i in range(len(S)): DP[1], DP[0] = DP[0], DP[1] for j in range(13): DP[0][j] = 0 for j in range(13): if S[i] == -1: s = (j * 10) % 13 e = (s + 10) % 13 else: s = (j * 10 + S[i]) % 13 e = (s + 1) % 13 DP[0][s] += DP[1][j] if s > e: DP[0][0] += DP[1][j] DP[0][e] -= DP[1][j] w = 0 for j in range(13): w = (w + DP[0][j]) % g DP[0][j] = w print((DP[0][5] % g))
false
0
[ "+ DP[1], DP[0] = DP[0], DP[1]", "- DP[1][j] = DP[0][j] % g", "- w += DP[0][j]", "+ w = (w + DP[0][j]) % g" ]
false
0.042994
0.038619
1.113263
[ "s439703180", "s105400571" ]
u298633786
p03221
python
s648135682
s254270955
1,084
836
80,344
42,172
Accepted
Accepted
22.88
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() if __name__ == '__main__': N, M = list(map(int, input().split())) PY = [] for i in range(M): P, Y = list(map(int, input().split())) PY.append([Y, P, i + 1]) PY.sort() # cnt: key=県, value=すでに幾つの市がその県に属しているか # res: [市の番号, 県の番号, 順番] cnt = {} res = [] for y, p, i in PY: if p not in cnt: cnt[p] = 1 else: cnt[p] += 1 res.append([i, p, cnt[p]]) res.sort() for i, p, x in res: print(('{:06}{:06}'.format(p, x)))
import sys import math # noqa import bisect # noqa import queue # noqa if __name__ == '__main__': N, M = list(map(int, sys.stdin.readline().rstrip().split())) PY = [] for i in range(M): P, Y = list(map(int, sys.stdin.readline().rstrip().split())) PY.append([Y, P, i + 1]) PY.sort() # cnt: key=県, value=すでに幾つの市がその県に属しているか # res: [市の番号, 県の番号, 順番] cnt = {} res = [] for y, p, i in PY: if p not in cnt: cnt[p] = 1 else: cnt[p] += 1 res.append([i, p, cnt[p]]) res.sort() for i, p, x in res: print(('{:06}{:06}'.format(p, x)))
32
28
673
657
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() if __name__ == "__main__": N, M = list(map(int, input().split())) PY = [] for i in range(M): P, Y = list(map(int, input().split())) PY.append([Y, P, i + 1]) PY.sort() # cnt: key=県, value=すでに幾つの市がその県に属しているか # res: [市の番号, 県の番号, 順番] cnt = {} res = [] for y, p, i in PY: if p not in cnt: cnt[p] = 1 else: cnt[p] += 1 res.append([i, p, cnt[p]]) res.sort() for i, p, x in res: print(("{:06}{:06}".format(p, x)))
import sys import math # noqa import bisect # noqa import queue # noqa if __name__ == "__main__": N, M = list(map(int, sys.stdin.readline().rstrip().split())) PY = [] for i in range(M): P, Y = list(map(int, sys.stdin.readline().rstrip().split())) PY.append([Y, P, i + 1]) PY.sort() # cnt: key=県, value=すでに幾つの市がその県に属しているか # res: [市の番号, 県の番号, 順番] cnt = {} res = [] for y, p, i in PY: if p not in cnt: cnt[p] = 1 else: cnt[p] += 1 res.append([i, p, cnt[p]]) res.sort() for i, p, x in res: print(("{:06}{:06}".format(p, x)))
false
12.5
[ "-", "-def input():", "- return sys.stdin.readline().rstrip()", "-", "-", "- N, M = list(map(int, input().split()))", "+ N, M = list(map(int, sys.stdin.readline().rstrip().split()))", "- P, Y = list(map(int, input().split()))", "+ P, Y = list(map(int, sys.stdin.readline().rstrip().split()))" ]
false
0.041027
0.07741
0.530001
[ "s648135682", "s254270955" ]
u325282913
p03472
python
s701040588
s488844000
340
195
11,312
72,668
Accepted
Accepted
42.65
N, H = list(map(int, input().split())) A, B = [0]*N, [0]*N for i in range(N): A[i], B[i] = list(map(int, input().split())) target = max(A) ans = 0 B.sort(reverse=True) for i in B: if i >= target: H -= i ans += 1 if H <= 0: print(ans) exit() print((ans-(-H//target)))
N, H = list(map(int, input().split())) A = [0]*N B = [0]*N for i in range(N): A[i], B[i] = list(map(int, input().split())) a = max(A) B.sort() ans = 0 while len(B) > 0 and B[-1] >= a and H > 0: H -= B.pop() ans += 1 if H <= 0: print(ans) exit() print((ans+(-(-H//a))))
15
15
310
300
N, H = list(map(int, input().split())) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = list(map(int, input().split())) target = max(A) ans = 0 B.sort(reverse=True) for i in B: if i >= target: H -= i ans += 1 if H <= 0: print(ans) exit() print((ans - (-H // target)))
N, H = list(map(int, input().split())) A = [0] * N B = [0] * N for i in range(N): A[i], B[i] = list(map(int, input().split())) a = max(A) B.sort() ans = 0 while len(B) > 0 and B[-1] >= a and H > 0: H -= B.pop() ans += 1 if H <= 0: print(ans) exit() print((ans + (-(-H // a))))
false
0
[ "-A, B = [0] * N, [0] * N", "+A = [0] * N", "+B = [0] * N", "-target = max(A)", "+a = max(A)", "+B.sort()", "-B.sort(reverse=True)", "-for i in B:", "- if i >= target:", "- H -= i", "- ans += 1", "+while len(B) > 0 and B[-1] >= a and H > 0:", "+ H -= B.pop()", "+ ans += 1", "-print((ans - (-H // target)))", "+print((ans + (-(-H // a))))" ]
false
0.041542
0.058544
0.709595
[ "s701040588", "s488844000" ]
u102960641
p02868
python
s564814491
s507188561
990
653
93,660
60,508
Accepted
Accepted
34.04
import sys input = sys.stdin.readline n,m = list(map(int, input().split())) t = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x:(x[0], -x[1])) d=[0,0]+[1e18]*n for l,r,c in t: for i in range(r,l,-1): if d[l]+c<d[i]: d[i]=d[l]+c else: break print((d[-2]%10**18or-1))
import sys input = sys.stdin.readline n,m = list(map(int, input().split())) t = sorted([tuple(map(int, input().split())) for i in range(m)]) INF = 10 ** 18 dp = [0,0] + [INF] * (n-1) for l,r,c in t: for i in range(r,l,-1): if dp[l] + c < dp[i]: dp[i] = dp[l] + c else: break ans = dp[n] if ans == INF: print((-1)) else: print(ans)
13
18
319
366
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) t = sorted( [tuple(map(int, input().split())) for i in range(m)], key=lambda x: (x[0], -x[1]) ) d = [0, 0] + [1e18] * n for l, r, c in t: for i in range(r, l, -1): if d[l] + c < d[i]: d[i] = d[l] + c else: break print((d[-2] % 10**18 or -1))
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) t = sorted([tuple(map(int, input().split())) for i in range(m)]) INF = 10**18 dp = [0, 0] + [INF] * (n - 1) for l, r, c in t: for i in range(r, l, -1): if dp[l] + c < dp[i]: dp[i] = dp[l] + c else: break ans = dp[n] if ans == INF: print((-1)) else: print(ans)
false
27.777778
[ "-t = sorted(", "- [tuple(map(int, input().split())) for i in range(m)], key=lambda x: (x[0], -x[1])", "-)", "-d = [0, 0] + [1e18] * n", "+t = sorted([tuple(map(int, input().split())) for i in range(m)])", "+INF = 10**18", "+dp = [0, 0] + [INF] * (n - 1)", "- if d[l] + c < d[i]:", "- d[i] = d[l] + c", "+ if dp[l] + c < dp[i]:", "+ dp[i] = dp[l] + c", "-print((d[-2] % 10**18 or -1))", "+ans = dp[n]", "+if ans == INF:", "+ print((-1))", "+else:", "+ print(ans)" ]
false
0.078449
0.03633
2.159375
[ "s564814491", "s507188561" ]
u606045429
p03607
python
s380805912
s578463516
261
194
7,488
13,204
Accepted
Accepted
25.67
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A.sort() result = 0 cur = 0 while cur < N: a = A[cur] count = 0 while cur < N and A[cur] == a: cur += 1 count += 1 result += count % 2 print(result)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] paper = set() for a in A: paper ^= {a} print((len(paper)))
16
8
252
123
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A.sort() result = 0 cur = 0 while cur < N: a = A[cur] count = 0 while cur < N and A[cur] == a: cur += 1 count += 1 result += count % 2 print(result)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] paper = set() for a in A: paper ^= {a} print((len(paper)))
false
50
[ "-A.sort()", "-result = 0", "-cur = 0", "-while cur < N:", "- a = A[cur]", "- count = 0", "- while cur < N and A[cur] == a:", "- cur += 1", "- count += 1", "- result += count % 2", "-print(result)", "+paper = set()", "+for a in A:", "+ paper ^= {a}", "+print((len(paper)))" ]
false
0.040077
0.040385
0.992364
[ "s380805912", "s578463516" ]
u995109095
p02819
python
s238265400
s129625741
187
36
40,176
3,828
Accepted
Accepted
80.75
nn=int(eval(input())) n=10**5+100 ar=[0]*(n) ar[1]=0 ans=0 pre=1 for i in range(2,n): if ar[i]==0: for j in range(2*i,n,i): ar[j]=1 ans=1 if ar[nn]==0: print(nn) else: for i in range(nn,n): if ar[i]==0: print(i) break
nn=int(eval(input())) n=10**5+100 ar=[0]*(n) ar[1]=0 ans=0 pre=1 for i in range(2,int((n**0.5))+1): if ar[i]==0: for j in range(2*i,n,i): ar[j]=1 ans=1 if ar[nn]==0: print(nn) else: for i in range(nn,n): if ar[i]==0: print(i) break
23
23
326
340
nn = int(eval(input())) n = 10**5 + 100 ar = [0] * (n) ar[1] = 0 ans = 0 pre = 1 for i in range(2, n): if ar[i] == 0: for j in range(2 * i, n, i): ar[j] = 1 ans = 1 if ar[nn] == 0: print(nn) else: for i in range(nn, n): if ar[i] == 0: print(i) break
nn = int(eval(input())) n = 10**5 + 100 ar = [0] * (n) ar[1] = 0 ans = 0 pre = 1 for i in range(2, int((n**0.5)) + 1): if ar[i] == 0: for j in range(2 * i, n, i): ar[j] = 1 ans = 1 if ar[nn] == 0: print(nn) else: for i in range(nn, n): if ar[i] == 0: print(i) break
false
0
[ "-for i in range(2, n):", "+for i in range(2, int((n**0.5)) + 1):" ]
false
0.283794
0.052964
5.358215
[ "s238265400", "s129625741" ]
u647999897
p02787
python
s579640071
s294709463
1,666
657
409,884
249,584
Accepted
Accepted
60.56
def solve(): H,N = list(map(int,input().split())) attack = [] mp = [] for i in range(N): a,b = list(map(int,input().split())) attack.append(a) mp.append(b) max_attack = max(attack) dp = [[float('inf')] * (H+max_attack) for _ in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(N): for j in range(H+max_attack): if j - attack[i] >= 0: dp[i+1][j] = min(dp[i+1][j], dp[i][j-attack[i]]+mp[i], dp[i+1][j-attack[i]]+mp[i]) dp[i+1][j] = min(dp[i+1][j], dp[i][j]) ans = float('inf') for i in range(N+1): for j in range(H,H+max_attack): ans = min(ans, dp[i][j]) print(ans) if __name__ == '__main__': solve()
def solve(): H,N = list(map(int,input().split())) ap = [] mp = [] for _ in range(N): a,b = list(map(int,input().split())) ap.append(a) mp.append(b) ap_max = max(ap) dp = [[float('inf')] * (H+ap_max+1) for _ in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(N): for sum_h in range(H+ap_max+1): dp[i+1][sum_h] = min(dp[i][sum_h-ap[i]] + mp[i], dp[i][sum_h]) dp[i+1][sum_h] = min(dp[i+1][sum_h-ap[i]] + mp[i], dp[i][sum_h]) ans = float('inf') for sum_h in range(H, H+ap_max+1): ans = min(ans,dp[N][sum_h]) print(ans) if __name__ == '__main__': solve()
30
29
797
721
def solve(): H, N = list(map(int, input().split())) attack = [] mp = [] for i in range(N): a, b = list(map(int, input().split())) attack.append(a) mp.append(b) max_attack = max(attack) dp = [[float("inf")] * (H + max_attack) for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for i in range(N): for j in range(H + max_attack): if j - attack[i] >= 0: dp[i + 1][j] = min( dp[i + 1][j], dp[i][j - attack[i]] + mp[i], dp[i + 1][j - attack[i]] + mp[i], ) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]) ans = float("inf") for i in range(N + 1): for j in range(H, H + max_attack): ans = min(ans, dp[i][j]) print(ans) if __name__ == "__main__": solve()
def solve(): H, N = list(map(int, input().split())) ap = [] mp = [] for _ in range(N): a, b = list(map(int, input().split())) ap.append(a) mp.append(b) ap_max = max(ap) dp = [[float("inf")] * (H + ap_max + 1) for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for i in range(N): for sum_h in range(H + ap_max + 1): dp[i + 1][sum_h] = min(dp[i][sum_h - ap[i]] + mp[i], dp[i][sum_h]) dp[i + 1][sum_h] = min(dp[i + 1][sum_h - ap[i]] + mp[i], dp[i][sum_h]) ans = float("inf") for sum_h in range(H, H + ap_max + 1): ans = min(ans, dp[N][sum_h]) print(ans) if __name__ == "__main__": solve()
false
3.333333
[ "- attack = []", "+ ap = []", "- for i in range(N):", "+ for _ in range(N):", "- attack.append(a)", "+ ap.append(a)", "- max_attack = max(attack)", "- dp = [[float(\"inf\")] * (H + max_attack) for _ in range(N + 1)]", "+ ap_max = max(ap)", "+ dp = [[float(\"inf\")] * (H + ap_max + 1) for _ in range(N + 1)]", "- for j in range(H + max_attack):", "- if j - attack[i] >= 0:", "- dp[i + 1][j] = min(", "- dp[i + 1][j],", "- dp[i][j - attack[i]] + mp[i],", "- dp[i + 1][j - attack[i]] + mp[i],", "- )", "- dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])", "+ for sum_h in range(H + ap_max + 1):", "+ dp[i + 1][sum_h] = min(dp[i][sum_h - ap[i]] + mp[i], dp[i][sum_h])", "+ dp[i + 1][sum_h] = min(dp[i + 1][sum_h - ap[i]] + mp[i], dp[i][sum_h])", "- for i in range(N + 1):", "- for j in range(H, H + max_attack):", "- ans = min(ans, dp[i][j])", "+ for sum_h in range(H, H + ap_max + 1):", "+ ans = min(ans, dp[N][sum_h])" ]
false
0.103306
0.086858
1.189365
[ "s579640071", "s294709463" ]
u063346608
p02621
python
s973807456
s116569983
31
26
9,104
9,116
Accepted
Accepted
16.13
a = int(eval(input())) print((a + a * a + a * a * a))
a = int(eval(input())) print((a + a ** 2 + a ** 3))
3
3
49
46
a = int(eval(input())) print((a + a * a + a * a * a))
a = int(eval(input())) print((a + a**2 + a**3))
false
0
[ "-print((a + a * a + a * a * a))", "+print((a + a**2 + a**3))" ]
false
0.039135
0.048295
0.810346
[ "s973807456", "s116569983" ]
u015315385
p03309
python
s753441037
s489235201
236
206
27,244
27,200
Accepted
Accepted
12.71
from statistics import median n = eval(input()) a = input().split() a = list(map(int, a)) b = [] for i, v in enumerate(a): b.append(v - (i + 1)) median = int(median(b)) c = 0 for v in b: c = c + abs(v - median) print(c)
from statistics import median n = eval(input()) a = list(map(int, input().split())) b = [v - (i + 1) for i, v in enumerate(a)] median = int(median(b)) c = sum(abs(v - median) for v in b) print(c)
19
12
247
206
from statistics import median n = eval(input()) a = input().split() a = list(map(int, a)) b = [] for i, v in enumerate(a): b.append(v - (i + 1)) median = int(median(b)) c = 0 for v in b: c = c + abs(v - median) print(c)
from statistics import median n = eval(input()) a = list(map(int, input().split())) b = [v - (i + 1) for i, v in enumerate(a)] median = int(median(b)) c = sum(abs(v - median) for v in b) print(c)
false
36.842105
[ "-a = input().split()", "-a = list(map(int, a))", "-b = []", "-for i, v in enumerate(a):", "- b.append(v - (i + 1))", "+a = list(map(int, input().split()))", "+b = [v - (i + 1) for i, v in enumerate(a)]", "-c = 0", "-for v in b:", "- c = c + abs(v - median)", "+c = sum(abs(v - median) for v in b)" ]
false
0.044407
0.048779
0.910355
[ "s753441037", "s489235201" ]
u305366205
p03103
python
s863447717
s654989514
491
451
26,748
16,988
Accepted
Accepted
8.15
n, m = list(map(int, input().split())) a = [0] * (n + 1) b = [0] * (n + 1) total = [0] * (n + 1) ans = 0 # 安い店から選ぶ方法が最適 shop = [tuple(map(int, input().split())) for _ in range(n)] shop.sort() for i in range(1, n + 1): a_i, b_i = shop[i - 1] # 累積和を作っておく # b[i]: i番目の店まで利用した際に購入できる栄養ドリンクの最大本数 # total[i]: i番目の店まで利用した際に支払うお金の最大値 b[i] = b[i - 1] total[i] = total[i - 1] b[i] += b_i total[i] += a_i * b_i # a[i]: i番目の店の栄養ドリンクの単価 a[i] = a_i for i in range(1, n + 1): if m <= b[i]: m = m - b[i - 1] # 足りない分を追加で計算 ans = total[i - 1] + a[i] * m break print(ans)
n, m = list(map(int, input().split())) ans = 0 shop = [tuple(map(int, input().split())) for _ in range(n)] shop.sort() for price, num in shop: num = min(m, num) ans += price * num m -= num print(ans)
30
9
655
213
n, m = list(map(int, input().split())) a = [0] * (n + 1) b = [0] * (n + 1) total = [0] * (n + 1) ans = 0 # 安い店から選ぶ方法が最適 shop = [tuple(map(int, input().split())) for _ in range(n)] shop.sort() for i in range(1, n + 1): a_i, b_i = shop[i - 1] # 累積和を作っておく # b[i]: i番目の店まで利用した際に購入できる栄養ドリンクの最大本数 # total[i]: i番目の店まで利用した際に支払うお金の最大値 b[i] = b[i - 1] total[i] = total[i - 1] b[i] += b_i total[i] += a_i * b_i # a[i]: i番目の店の栄養ドリンクの単価 a[i] = a_i for i in range(1, n + 1): if m <= b[i]: m = m - b[i - 1] # 足りない分を追加で計算 ans = total[i - 1] + a[i] * m break print(ans)
n, m = list(map(int, input().split())) ans = 0 shop = [tuple(map(int, input().split())) for _ in range(n)] shop.sort() for price, num in shop: num = min(m, num) ans += price * num m -= num print(ans)
false
70
[ "-a = [0] * (n + 1)", "-b = [0] * (n + 1)", "-total = [0] * (n + 1)", "-# 安い店から選ぶ方法が最適", "-for i in range(1, n + 1):", "- a_i, b_i = shop[i - 1]", "- # 累積和を作っておく", "- # b[i]: i番目の店まで利用した際に購入できる栄養ドリンクの最大本数", "- # total[i]: i番目の店まで利用した際に支払うお金の最大値", "- b[i] = b[i - 1]", "- total[i] = total[i - 1]", "- b[i] += b_i", "- total[i] += a_i * b_i", "- # a[i]: i番目の店の栄養ドリンクの単価", "- a[i] = a_i", "-for i in range(1, n + 1):", "- if m <= b[i]:", "- m = m - b[i - 1]", "- # 足りない分を追加で計算", "- ans = total[i - 1] + a[i] * m", "- break", "+for price, num in shop:", "+ num = min(m, num)", "+ ans += price * num", "+ m -= num" ]
false
0.007368
0.060376
0.122037
[ "s863447717", "s654989514" ]
u827448139
p01713
python
s264147134
s557589301
4,630
330
88,360
21,584
Accepted
Accepted
92.87
from queue import PriorityQueue class State: def __init__(self,index,time): self.index=index self.time=time def __lt__(self,state): return self.time>state.time while 1: try: n=int(eval(input())) except: break a=list(map(int,input().split())) ts=[float("inf")]*n vis=[False]*n pq=PriorityQueue() for i in range(n): if a[i]==0: pq.put(State(i,int(1e9))) while pq.qsize(): cur=pq.get() if cur.index<0 or n<=cur.index or vis[cur.index] or cur.time<0: continue vis[cur.index]=True if a[cur.index]<0: cur.time=min(cur.time,-a[cur.index]-1) ts[cur.index]=cur.time pq.put(State(cur.index-1,cur.time-1)) pq.put(State(cur.index+1,cur.time-1)) res=0 for i in range(n): if a[i]>0 and vis[i]: res+=min(a[i],ts[i]+1) print(res)
n=int(eval(input())) a=list(map(int,input().split())) ts=[0]*n for indices in list(range(n)),reversed(list(range(n))): t=0 for i in indices: if a[i]==0: t=float("inf") if a[i]<0: t=min(t,-a[i]) if a[i]>0: ts[i]=max(ts[i],min(a[i],t)) t-=1 print((sum(ts)))
36
12
845
267
from queue import PriorityQueue class State: def __init__(self, index, time): self.index = index self.time = time def __lt__(self, state): return self.time > state.time while 1: try: n = int(eval(input())) except: break a = list(map(int, input().split())) ts = [float("inf")] * n vis = [False] * n pq = PriorityQueue() for i in range(n): if a[i] == 0: pq.put(State(i, int(1e9))) while pq.qsize(): cur = pq.get() if cur.index < 0 or n <= cur.index or vis[cur.index] or cur.time < 0: continue vis[cur.index] = True if a[cur.index] < 0: cur.time = min(cur.time, -a[cur.index] - 1) ts[cur.index] = cur.time pq.put(State(cur.index - 1, cur.time - 1)) pq.put(State(cur.index + 1, cur.time - 1)) res = 0 for i in range(n): if a[i] > 0 and vis[i]: res += min(a[i], ts[i] + 1) print(res)
n = int(eval(input())) a = list(map(int, input().split())) ts = [0] * n for indices in list(range(n)), reversed(list(range(n))): t = 0 for i in indices: if a[i] == 0: t = float("inf") if a[i] < 0: t = min(t, -a[i]) if a[i] > 0: ts[i] = max(ts[i], min(a[i], t)) t -= 1 print((sum(ts)))
false
66.666667
[ "-from queue import PriorityQueue", "-", "-", "-class State:", "- def __init__(self, index, time):", "- self.index = index", "- self.time = time", "-", "- def __lt__(self, state):", "- return self.time > state.time", "-", "-", "-while 1:", "- try:", "- n = int(eval(input()))", "- except:", "- break", "- a = list(map(int, input().split()))", "- ts = [float(\"inf\")] * n", "- vis = [False] * n", "- pq = PriorityQueue()", "- for i in range(n):", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+ts = [0] * n", "+for indices in list(range(n)), reversed(list(range(n))):", "+ t = 0", "+ for i in indices:", "- pq.put(State(i, int(1e9)))", "- while pq.qsize():", "- cur = pq.get()", "- if cur.index < 0 or n <= cur.index or vis[cur.index] or cur.time < 0:", "- continue", "- vis[cur.index] = True", "- if a[cur.index] < 0:", "- cur.time = min(cur.time, -a[cur.index] - 1)", "- ts[cur.index] = cur.time", "- pq.put(State(cur.index - 1, cur.time - 1))", "- pq.put(State(cur.index + 1, cur.time - 1))", "- res = 0", "- for i in range(n):", "- if a[i] > 0 and vis[i]:", "- res += min(a[i], ts[i] + 1)", "- print(res)", "+ t = float(\"inf\")", "+ if a[i] < 0:", "+ t = min(t, -a[i])", "+ if a[i] > 0:", "+ ts[i] = max(ts[i], min(a[i], t))", "+ t -= 1", "+print((sum(ts)))" ]
false
0.058516
0.04095
1.428959
[ "s264147134", "s557589301" ]
u940102677
p03745
python
s886904408
s236149256
576
485
23,128
23,096
Accepted
Accepted
15.8
from numpy import sign n = int(eval(input())) a = list(map(int,input().split())) b = [sign(a[i+1]-a[i]) for i in range(n-1)] c = 1 f = 0 for t in b: if f == 0: f = t elif f == 1 and t == -1: c += 1 f = 0 elif f == -1 and t == 1: c += 1 f = 0 print(c)
from numpy import sign n = int(eval(input())) a = list(map(int,input().split())) b = [sign(a[i+1]-a[i]) for i in range(n-1)] c = 1 f = 0 for t in b: if f == 0: f = t elif f*t == -1: c += 1 f = 0 print(c)
20
15
299
230
from numpy import sign n = int(eval(input())) a = list(map(int, input().split())) b = [sign(a[i + 1] - a[i]) for i in range(n - 1)] c = 1 f = 0 for t in b: if f == 0: f = t elif f == 1 and t == -1: c += 1 f = 0 elif f == -1 and t == 1: c += 1 f = 0 print(c)
from numpy import sign n = int(eval(input())) a = list(map(int, input().split())) b = [sign(a[i + 1] - a[i]) for i in range(n - 1)] c = 1 f = 0 for t in b: if f == 0: f = t elif f * t == -1: c += 1 f = 0 print(c)
false
25
[ "- elif f == 1 and t == -1:", "- c += 1", "- f = 0", "- elif f == -1 and t == 1:", "+ elif f * t == -1:" ]
false
0.225408
0.192665
1.169946
[ "s886904408", "s236149256" ]
u941047297
p03127
python
s465322660
s782706229
79
59
16,276
20,564
Accepted
Accepted
25.32
import fractions from functools import reduce def gcd_list(l): return reduce(fractions.gcd, l) n = int(eval(input())) A = list(map(int, input().split())) print((gcd_list(A)))
from functools import reduce import math def main(): n = int(eval(input())) A = list(map(int, input().split())) print((reduce(math.gcd, A))) if __name__ == '__main__': main()
7
9
176
192
import fractions from functools import reduce def gcd_list(l): return reduce(fractions.gcd, l) n = int(eval(input())) A = list(map(int, input().split())) print((gcd_list(A)))
from functools import reduce import math def main(): n = int(eval(input())) A = list(map(int, input().split())) print((reduce(math.gcd, A))) if __name__ == "__main__": main()
false
22.222222
[ "-import fractions", "+import math", "-def gcd_list(l):", "- return reduce(fractions.gcd, l)", "+def main():", "+ n = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ print((reduce(math.gcd, A)))", "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "-print((gcd_list(A)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.049775
0.156333
0.31839
[ "s465322660", "s782706229" ]
u243572357
p03860
python
s429474013
s333602992
24
17
2,940
2,940
Accepted
Accepted
29.17
n = input().split()[1] print(('A%sC'%n[0]))
a = input().split() print((a[0][0] + a[1][0] + a[2][0]))
2
2
42
55
n = input().split()[1] print(("A%sC" % n[0]))
a = input().split() print((a[0][0] + a[1][0] + a[2][0]))
false
0
[ "-n = input().split()[1]", "-print((\"A%sC\" % n[0]))", "+a = input().split()", "+print((a[0][0] + a[1][0] + a[2][0]))" ]
false
0.037369
0.037438
0.998161
[ "s429474013", "s333602992" ]
u416011173
p02687
python
s031772973
s958908516
24
21
9,088
9,052
Accepted
Accepted
12.5
# -*- coding: utf-8 -*- # 標準入力の取得 S = eval(input()) # 求解処理 result = "" if S == "ABC": result = "ARC" elif S == "ARC": result = "ABC" # 結果出力 print(result)
# -*- coding: utf-8 -*- # 標準入力の取得 S = eval(input()) def main() -> None: """Entry point """ # 求解処理 """ 先週"ABC"が開催された場合は"ARC"、 先週"ARC"が開催された場合は"ABC"を返す """ result = "" if S == "ABC": result = "ARC" elif S == "ARC": result = "ABC" # 結果出力 print(result) if __name__ == "__main__": main()
13
25
170
374
# -*- coding: utf-8 -*- # 標準入力の取得 S = eval(input()) # 求解処理 result = "" if S == "ABC": result = "ARC" elif S == "ARC": result = "ABC" # 結果出力 print(result)
# -*- coding: utf-8 -*- # 標準入力の取得 S = eval(input()) def main() -> None: """Entry point""" # 求解処理 """ 先週"ABC"が開催された場合は"ARC"、 先週"ARC"が開催された場合は"ABC"を返す """ result = "" if S == "ABC": result = "ARC" elif S == "ARC": result = "ABC" # 結果出力 print(result) if __name__ == "__main__": main()
false
48
[ "-# 求解処理", "-result = \"\"", "-if S == \"ABC\":", "- result = \"ARC\"", "-elif S == \"ARC\":", "- result = \"ABC\"", "-# 結果出力", "-print(result)", "+", "+", "+def main() -> None:", "+ \"\"\"Entry point\"\"\"", "+ # 求解処理", "+ \"\"\"", "+ 先週\"ABC\"が開催された場合は\"ARC\"、", "+ 先週\"ARC\"が開催された場合は\"ABC\"を返す", "+ \"\"\"", "+ result = \"\"", "+ if S == \"ABC\":", "+ result = \"ARC\"", "+ elif S == \"ARC\":", "+ result = \"ABC\"", "+ # 結果出力", "+ print(result)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047154
0.047655
0.989503
[ "s031772973", "s958908516" ]
u459697504
p04012
python
s973798315
s355023137
30
21
3,572
3,316
Accepted
Accepted
30
#! /usr/bin/python3 # ABC044_B # B - 美しい文字列 / Beautiful Strings """ collectionsを使わないタイプ 制約 1≤|w|≤100 w は英小文字 (a-z) のみからなる文字列である。 """ import collections test_mode = False use_Counter = False # collections.Counter を使うかどうか def judge_0(l): """ collections.Counter を使うタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ broken = False count_l = collections.Counter(l) # l の各要素の出現回数をカウント if test_mode: print(count_l) for i in count_l: if count_l[i] % 2 == 1: if test_mode: print('break') broken = True break return not broken def judge_1(l): """ collections.Counter を使わないタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ broken = False # break したら True になるフラグ for i in l: if test_mode: print(('{}:'.format(i), l.count(i))) if l.count(i) % 2 == 1: print('break') if l.count(i) % 2 == 1: broken = True break return not broken def main(): """ main関数 """ w = list(str(eval(input()))) # 文字列をリストに変換 if use_Counter: beautiful = judge_0(w) else: beautiful = judge_1(w) if beautiful: print('Yes') else: print('No') if __name__ == '__main__': main()
#! /usr/bin/python3 # ABC044_B # B - 美しい文字列 / Beautiful Strings """ collectionsを使わないタイプ 制約 1≤|w|≤100 w は英小文字 (a-z) のみからなる文字列である。 """ import collections test_mode = False use_Counter = True # collections.Counter を使うかどうか def judge_0(l): """ collections.Counter を使うタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ count_l = collections.Counter(l) # l の各要素の出現回数をカウント if test_mode: print(count_l) for i in count_l: if count_l[i] % 2 == 1: if test_mode: print('break') return False return True def judge_1(l): """ collections.Counter を使わないタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ for i in l: if test_mode: print(('{}:'.format(i), l.count(i))) if l.count(i) % 2 == 1: print('break') if l.count(i) % 2 == 1: return False return True def main(): """ main関数 """ w = list(str(eval(input()))) # 文字列をリストに変換 if use_Counter: beautiful = judge_0(w) else: beautiful = judge_1(w) if beautiful: print('Yes') else: print('No') if __name__ == '__main__': main()
78
74
1,439
1,321
#! /usr/bin/python3 # ABC044_B # B - 美しい文字列 / Beautiful Strings """ collectionsを使わないタイプ 制約 1≤|w|≤100 w は英小文字 (a-z) のみからなる文字列である。 """ import collections test_mode = False use_Counter = False # collections.Counter を使うかどうか def judge_0(l): """ collections.Counter を使うタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ broken = False count_l = collections.Counter(l) # l の各要素の出現回数をカウント if test_mode: print(count_l) for i in count_l: if count_l[i] % 2 == 1: if test_mode: print("break") broken = True break return not broken def judge_1(l): """ collections.Counter を使わないタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ broken = False # break したら True になるフラグ for i in l: if test_mode: print(("{}:".format(i), l.count(i))) if l.count(i) % 2 == 1: print("break") if l.count(i) % 2 == 1: broken = True break return not broken def main(): """ main関数 """ w = list(str(eval(input()))) # 文字列をリストに変換 if use_Counter: beautiful = judge_0(w) else: beautiful = judge_1(w) if beautiful: print("Yes") else: print("No") if __name__ == "__main__": main()
#! /usr/bin/python3 # ABC044_B # B - 美しい文字列 / Beautiful Strings """ collectionsを使わないタイプ 制約 1≤|w|≤100 w は英小文字 (a-z) のみからなる文字列である。 """ import collections test_mode = False use_Counter = True # collections.Counter を使うかどうか def judge_0(l): """ collections.Counter を使うタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ count_l = collections.Counter(l) # l の各要素の出現回数をカウント if test_mode: print(count_l) for i in count_l: if count_l[i] % 2 == 1: if test_mode: print("break") return False return True def judge_1(l): """ collections.Counter を使わないタイプ 奇数会出現する要素があると False を返し、 全ての要素が偶数回出現すると True を返す。 """ for i in l: if test_mode: print(("{}:".format(i), l.count(i))) if l.count(i) % 2 == 1: print("break") if l.count(i) % 2 == 1: return False return True def main(): """ main関数 """ w = list(str(eval(input()))) # 文字列をリストに変換 if use_Counter: beautiful = judge_0(w) else: beautiful = judge_1(w) if beautiful: print("Yes") else: print("No") if __name__ == "__main__": main()
false
5.128205
[ "-use_Counter = False # collections.Counter を使うかどうか", "+use_Counter = True # collections.Counter を使うかどうか", "- broken = False", "- broken = True", "- break", "- return not broken", "+ return False", "+ return True", "- broken = False # break したら True になるフラグ", "- broken = True", "- break", "- return not broken", "+ return False", "+ return True" ]
false
0.037516
0.05152
0.728181
[ "s973798315", "s355023137" ]
u891635666
p03078
python
s080013466
s156472812
774
39
4,716
5,264
Accepted
Accepted
94.96
import heapq x, y, z, k = map(int, input().split()) ls = [list(map(int, input().split())) for _ in range(3)] for i in range(3): ls[i].sort(reverse=True) q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)] res = [] used = [(0, 0, 0)] while len(res) < k: s, i, j, l = heapq.heappop(q) res.append(-s) if i + 1 < x and (i + 1, j, l) not in used: heapq.heappush(q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l)) used.append((i + 1, j, l)) if j + 1 < y and (i, j + 1, l) not in used: heapq.heappush(q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l)) used.append((i, j + 1, l)) if l + 1 < z and (i, j, l + 1) not in used: heapq.heappush(q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1)) used.append((i, j, l + 1)) print(*res, sep='\n')
import collections import heapq x, y, z, k = map(int, input().split()) ls = [list(map(int, input().split())) for _ in range(3)] for i in range(3): ls[i].sort(reverse=True) q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)] res = [] used = collections.defaultdict(lambda: False) while len(res) < k: s, i, j, l = heapq.heappop(q) res.append(-s) if i + 1 < x and not used[(i + 1, j, l)]: heapq.heappush(q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l)) used[(i + 1, j, l)] = True if j + 1 < y and not used[(i, j + 1, l)]: heapq.heappush(q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l)) used[(i, j + 1, l)] = True if l + 1 < z and not used[(i, j, l + 1)]: heapq.heappush(q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1)) used[(i, j, l + 1)] = True print(*res, sep='\n')
22
23
842
883
import heapq x, y, z, k = map(int, input().split()) ls = [list(map(int, input().split())) for _ in range(3)] for i in range(3): ls[i].sort(reverse=True) q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)] res = [] used = [(0, 0, 0)] while len(res) < k: s, i, j, l = heapq.heappop(q) res.append(-s) if i + 1 < x and (i + 1, j, l) not in used: heapq.heappush(q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l)) used.append((i + 1, j, l)) if j + 1 < y and (i, j + 1, l) not in used: heapq.heappush(q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l)) used.append((i, j + 1, l)) if l + 1 < z and (i, j, l + 1) not in used: heapq.heappush(q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1)) used.append((i, j, l + 1)) print(*res, sep="\n")
import collections import heapq x, y, z, k = map(int, input().split()) ls = [list(map(int, input().split())) for _ in range(3)] for i in range(3): ls[i].sort(reverse=True) q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)] res = [] used = collections.defaultdict(lambda: False) while len(res) < k: s, i, j, l = heapq.heappop(q) res.append(-s) if i + 1 < x and not used[(i + 1, j, l)]: heapq.heappush(q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l)) used[(i + 1, j, l)] = True if j + 1 < y and not used[(i, j + 1, l)]: heapq.heappush(q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l)) used[(i, j + 1, l)] = True if l + 1 < z and not used[(i, j, l + 1)]: heapq.heappush(q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1)) used[(i, j, l + 1)] = True print(*res, sep="\n")
false
4.347826
[ "+import collections", "-used = [(0, 0, 0)]", "+used = collections.defaultdict(lambda: False)", "- if i + 1 < x and (i + 1, j, l) not in used:", "+ if i + 1 < x and not used[(i + 1, j, l)]:", "- used.append((i + 1, j, l))", "- if j + 1 < y and (i, j + 1, l) not in used:", "+ used[(i + 1, j, l)] = True", "+ if j + 1 < y and not used[(i, j + 1, l)]:", "- used.append((i, j + 1, l))", "- if l + 1 < z and (i, j, l + 1) not in used:", "+ used[(i, j + 1, l)] = True", "+ if l + 1 < z and not used[(i, j, l + 1)]:", "- used.append((i, j, l + 1))", "+ used[(i, j, l + 1)] = True" ]
false
0.041062
0.032942
1.246479
[ "s080013466", "s156472812" ]
u426764965
p03229
python
s442544884
s896155967
268
215
8,292
7,764
Accepted
Accepted
19.78
def tenka18beg_c(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A_desc = sorted(A, reverse=True) if N % 2 == 1: tot1, tot2 = 0, 0 for i, a in enumerate(A_desc): if i < N//2 - 1: tot1 += 2*a tot2 += 2*a elif i == N//2 - 1: tot1 += a tot2 += 2*a elif i == N//2: tot1 += a tot2 -= a elif i == N//2 + 1: tot1 -= 2*a tot2 -= a elif N//2 + 1 < i: tot1 -= 2*a tot2 -= 2*a ans = max(tot1, tot2) else: tot = 0 for i, a in enumerate(A_desc): if i < N//2 - 1: tot += 2*a elif i == N//2 - 1: tot += a elif i == N//2: tot -= a elif N//2 < i: tot -= 2*a ans = tot print(ans) tenka18beg_c()
# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465 def tenka18beg_c(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A.sort() if N % 2 == 0: lower = A[:N//2] upper = A[N//2:] ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1]) else: lower = A[:N//2] upper = A[N//2 + 1:] mid = A[N//2] x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1] # 中央が +2* -1* -1* のパターン y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0] # 中央が +1* +1* -2* のパターン ans = max(x, y) print(ans) tenka18beg_c()
39
20
1,029
641
def tenka18beg_c(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A_desc = sorted(A, reverse=True) if N % 2 == 1: tot1, tot2 = 0, 0 for i, a in enumerate(A_desc): if i < N // 2 - 1: tot1 += 2 * a tot2 += 2 * a elif i == N // 2 - 1: tot1 += a tot2 += 2 * a elif i == N // 2: tot1 += a tot2 -= a elif i == N // 2 + 1: tot1 -= 2 * a tot2 -= a elif N // 2 + 1 < i: tot1 -= 2 * a tot2 -= 2 * a ans = max(tot1, tot2) else: tot = 0 for i, a in enumerate(A_desc): if i < N // 2 - 1: tot += 2 * a elif i == N // 2 - 1: tot += a elif i == N // 2: tot -= a elif N // 2 < i: tot -= 2 * a ans = tot print(ans) tenka18beg_c()
# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465 def tenka18beg_c(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A.sort() if N % 2 == 0: lower = A[: N // 2] upper = A[N // 2 :] ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1]) else: lower = A[: N // 2] upper = A[N // 2 + 1 :] mid = A[N // 2] x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1] # 中央が +2* -1* -1* のパターン y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0] # 中央が +1* +1* -2* のパターン ans = max(x, y) print(ans) tenka18beg_c()
false
48.717949
[ "+# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465", "- A_desc = sorted(A, reverse=True)", "- if N % 2 == 1:", "- tot1, tot2 = 0, 0", "- for i, a in enumerate(A_desc):", "- if i < N // 2 - 1:", "- tot1 += 2 * a", "- tot2 += 2 * a", "- elif i == N // 2 - 1:", "- tot1 += a", "- tot2 += 2 * a", "- elif i == N // 2:", "- tot1 += a", "- tot2 -= a", "- elif i == N // 2 + 1:", "- tot1 -= 2 * a", "- tot2 -= a", "- elif N // 2 + 1 < i:", "- tot1 -= 2 * a", "- tot2 -= 2 * a", "- ans = max(tot1, tot2)", "+ A.sort()", "+ if N % 2 == 0:", "+ lower = A[: N // 2]", "+ upper = A[N // 2 :]", "+ ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1])", "- tot = 0", "- for i, a in enumerate(A_desc):", "- if i < N // 2 - 1:", "- tot += 2 * a", "- elif i == N // 2 - 1:", "- tot += a", "- elif i == N // 2:", "- tot -= a", "- elif N // 2 < i:", "- tot -= 2 * a", "- ans = tot", "+ lower = A[: N // 2]", "+ upper = A[N // 2 + 1 :]", "+ mid = A[N // 2]", "+ x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1] # 中央が +2* -1* -1* のパターン", "+ y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0] # 中央が +1* +1* -2* のパターン", "+ ans = max(x, y)" ]
false
0.04109
0.044793
0.917328
[ "s442544884", "s896155967" ]
u703092276
p02657
python
s229243280
s306026736
30
25
9,136
8,988
Accepted
Accepted
16.67
a,b=list(map(int,input().split()));print((a*b))
x,y=input().split();x=int(x);y=float(y);print((int(x*y)))
1
1
39
55
a, b = list(map(int, input().split())) print((a * b))
x, y = input().split() x = int(x) y = float(y) print((int(x * y)))
false
0
[ "-a, b = list(map(int, input().split()))", "-print((a * b))", "+x, y = input().split()", "+x = int(x)", "+y = float(y)", "+print((int(x * y)))" ]
false
0.044681
0.047639
0.937908
[ "s229243280", "s306026736" ]
u638795007
p03037
python
s638440118
s521434261
324
188
10,996
4,720
Accepted
Accepted
41.98
N,M =list(map(int,input().split())) L = [0]*M R = [0]*M ans = int(0) for i in range(M): L[i],R[i] = list(map(int,input().split())) a1 = max(L) a2 = min(R) ans = a2-a1+1 if ans<0 : ans = int(0) print((int(ans)))
def examA(): N, M = LI() l = 1; r = N for _ in range(M): L, R = LI() l = max(L,l) r = min(R,r) ans = max(0,r-l+1) print(ans) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return 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(readline()) def LI(): return list(map(int,readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return read().rstrip().decode('utf-8') global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examA() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
16
66
227
1,277
N, M = list(map(int, input().split())) L = [0] * M R = [0] * M ans = int(0) for i in range(M): L[i], R[i] = list(map(int, input().split())) a1 = max(L) a2 = min(R) ans = a2 - a1 + 1 if ans < 0: ans = int(0) print((int(ans)))
def examA(): N, M = LI() l = 1 r = N for _ in range(M): L, R = LI() l = max(L, l) r = min(R, r) ans = max(0, r - l + 1) print(ans) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return 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(readline()) def LI(): return list(map(int, readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return read().rstrip().decode("utf-8") global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examA() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
false
75.757576
[ "-N, M = list(map(int, input().split()))", "-L = [0] * M", "-R = [0] * M", "-ans = int(0)", "-for i in range(M):", "- L[i], R[i] = list(map(int, input().split()))", "-a1 = max(L)", "-a2 = min(R)", "-ans = a2 - a1 + 1", "-if ans < 0:", "- ans = int(0)", "-print((int(ans)))", "+def examA():", "+ N, M = LI()", "+ l = 1", "+ r = N", "+ for _ in range(M):", "+ L, R = LI()", "+ l = max(L, l)", "+ r = min(R, r)", "+ ans = max(0, r - l + 1)", "+ print(ans)", "+ return", "+", "+", "+def examB():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examC():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examD():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examE():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+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(readline())", "+", "+", "+def LI():", "+ return list(map(int, readline().split()))", "+", "+", "+def LSI():", "+ return list(map(str, sys.stdin.readline().split()))", "+", "+", "+def LS():", "+ return sys.stdin.readline().split()", "+", "+", "+def SI():", "+ return read().rstrip().decode(\"utf-8\")", "+", "+", "+global mod, mod2, inf, alphabet, _ep", "+mod = 10**9 + 7", "+mod2 = 998244353", "+inf = 10**18", "+_ep = 10 ** (-12)", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+sys.setrecursionlimit(10**7)", "+if __name__ == \"__main__\":", "+ examA()", "+\"\"\"", "+142", "+12 9 1445 0 1", "+asd dfg hj o o", "+aidn", "+\"\"\"" ]
false
0.045035
0.045874
0.981692
[ "s638440118", "s521434261" ]
u201234972
p03295
python
s698008759
s675546613
1,994
494
23,284
22,432
Accepted
Accepted
75.23
N, M = list(map( int, input().split())) Q = [[int(s) for s in input().split()] for _ in range(M)] Q = sorted(Q) ans = 1 LQ = len(Q) while LQ != 0: stan = Q[0][1] k = 1 while LQ != 0: if Q[0][0] < stan: stan = min(stan,Q.pop(0)[1]) LQ -= 1 else: ans += 1 break print(ans)
N, M = list(map( int, input().split())) Q = [[int(s) for s in input().split()] for _ in range(M)] Q = sorted(Q) ans = 1 stan = Q[0][1] for i in range(M): if Q[i][0] < stan: stan = min(stan,Q[i][1]) else: ans += 1 if i == M-1: break else: stan = Q[i][1] print(ans)
16
15
355
335
N, M = list(map(int, input().split())) Q = [[int(s) for s in input().split()] for _ in range(M)] Q = sorted(Q) ans = 1 LQ = len(Q) while LQ != 0: stan = Q[0][1] k = 1 while LQ != 0: if Q[0][0] < stan: stan = min(stan, Q.pop(0)[1]) LQ -= 1 else: ans += 1 break print(ans)
N, M = list(map(int, input().split())) Q = [[int(s) for s in input().split()] for _ in range(M)] Q = sorted(Q) ans = 1 stan = Q[0][1] for i in range(M): if Q[i][0] < stan: stan = min(stan, Q[i][1]) else: ans += 1 if i == M - 1: break else: stan = Q[i][1] print(ans)
false
6.25
[ "-LQ = len(Q)", "-while LQ != 0:", "- stan = Q[0][1]", "- k = 1", "- while LQ != 0:", "- if Q[0][0] < stan:", "- stan = min(stan, Q.pop(0)[1])", "- LQ -= 1", "+stan = Q[0][1]", "+for i in range(M):", "+ if Q[i][0] < stan:", "+ stan = min(stan, Q[i][1])", "+ else:", "+ ans += 1", "+ if i == M - 1:", "+ break", "- ans += 1", "- break", "+ stan = Q[i][1]" ]
false
0.040127
0.041999
0.955421
[ "s698008759", "s675546613" ]
u047796752
p02744
python
s002178141
s316795286
175
137
79,212
75,904
Accepted
Accepted
21.71
from collections import * def dfs(l): if len(l)==N: print((''.join(l))) return for a in range(ord('a'), ord(max(l))+2): l.append(chr(a)) dfs(l) l.pop() N = int(eval(input())) dfs(deque(['a']))
from collections import * def dfs(q): if len(q)==N: print((''.join(q))) return M = 'a' for qi in q: M = max(M, qi) for i in range(ord(M)-ord('a')+2): q.append(alpha[i]) dfs(q) q.pop() N = int(eval(input())) alpha = 'abcdefghijklmnopqrstuvwxyz' dfs(deque(['a']))
14
20
256
358
from collections import * def dfs(l): if len(l) == N: print(("".join(l))) return for a in range(ord("a"), ord(max(l)) + 2): l.append(chr(a)) dfs(l) l.pop() N = int(eval(input())) dfs(deque(["a"]))
from collections import * def dfs(q): if len(q) == N: print(("".join(q))) return M = "a" for qi in q: M = max(M, qi) for i in range(ord(M) - ord("a") + 2): q.append(alpha[i]) dfs(q) q.pop() N = int(eval(input())) alpha = "abcdefghijklmnopqrstuvwxyz" dfs(deque(["a"]))
false
30
[ "-def dfs(l):", "- if len(l) == N:", "- print((\"\".join(l)))", "+def dfs(q):", "+ if len(q) == N:", "+ print((\"\".join(q)))", "- for a in range(ord(\"a\"), ord(max(l)) + 2):", "- l.append(chr(a))", "- dfs(l)", "- l.pop()", "+ M = \"a\"", "+ for qi in q:", "+ M = max(M, qi)", "+ for i in range(ord(M) - ord(\"a\") + 2):", "+ q.append(alpha[i])", "+ dfs(q)", "+ q.pop()", "+alpha = \"abcdefghijklmnopqrstuvwxyz\"" ]
false
0.04584
0.043952
1.042962
[ "s002178141", "s316795286" ]
u077337864
p04006
python
s697108822
s186176445
1,610
988
3,188
3,188
Accepted
Accepted
38.63
n, x = list(map(int, input().split())) alist = list(map(int, input().split())) blist = alist[:] ans = None for i in range(n): for j in range(n): blist[j] = min(blist[j], alist[j-i]) if ans is None: ans = i * x + sum(blist) else: ans = min(ans, i * x + sum(blist)) print(ans)
def main(): n, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 1100100100100100100 mina = [10000000000 for i in range(n)] for i in range(n): for j in range(n): mina[j] = min(mina[j], a[i - j]) sumb = sum(mina) ans = min(ans, sumb + i * x) print(ans) if __name__ == '__main__': main()
13
15
300
388
n, x = list(map(int, input().split())) alist = list(map(int, input().split())) blist = alist[:] ans = None for i in range(n): for j in range(n): blist[j] = min(blist[j], alist[j - i]) if ans is None: ans = i * x + sum(blist) else: ans = min(ans, i * x + sum(blist)) print(ans)
def main(): n, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 1100100100100100100 mina = [10000000000 for i in range(n)] for i in range(n): for j in range(n): mina[j] = min(mina[j], a[i - j]) sumb = sum(mina) ans = min(ans, sumb + i * x) print(ans) if __name__ == "__main__": main()
false
13.333333
[ "-n, x = list(map(int, input().split()))", "-alist = list(map(int, input().split()))", "-blist = alist[:]", "-ans = None", "-for i in range(n):", "- for j in range(n):", "- blist[j] = min(blist[j], alist[j - i])", "- if ans is None:", "- ans = i * x + sum(blist)", "- else:", "- ans = min(ans, i * x + sum(blist))", "-print(ans)", "+def main():", "+ n, x = list(map(int, input().split()))", "+ a = list(map(int, input().split()))", "+ ans = 1100100100100100100", "+ mina = [10000000000 for i in range(n)]", "+ for i in range(n):", "+ for j in range(n):", "+ mina[j] = min(mina[j], a[i - j])", "+ sumb = sum(mina)", "+ ans = min(ans, sumb + i * x)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.033955
0.03178
1.06845
[ "s697108822", "s186176445" ]
u588341295
p03987
python
s994207180
s424531152
1,395
1,268
80,080
77,648
Accepted
Accepted
9.1
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 class BIT: def __init__(self, n): # 0-indexed nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """ [0, i]を合計する """ s = 0 i += 1 while i > 0: s += self.tree[i-1] i -= i & -i return s def add(self, i, x): """ 値の追加:添字i, 値x """ i += 1 while i <= self.size: self.tree[i-1] += x i += i & -i def get(self, l, r=None): """ 区間和の取得 [l, r) """ # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r-1) if l: res -= self.sum(l-1) return res def bisearch_min(mn, mx, func): """ 条件を満たす最小値を見つける二分探索 """ ok = mx ng = mn while ng+1 < ok: mid = (ok+ng) // 2 if func(mid): # 下を探しに行く ok = mid else: # 上を探しに行く ng = mid return ok # 右から1番目の値の位置 def calc1(m): cnt = lend - bit.sum(m) return cnt < 1 # 左から1番目の値の位置 def calc2(m): cnt = bit.sum(m) - rstart return cnt >= 1 N = INT() A = LIST() # aの昇順に処理できるようにindexで並べておく idxs = [0] * (N+1) for i, a in enumerate(A): idxs[a] = i + 1 bit = BIT(N+2) # 先頭と末尾に番兵を仕込む bit.add(0, 1) bit.add(N+1, 1) ans = [0] * (N+1) for a in range(1, N+1): # a(1~N)が格納されているindex idx = idxs[a] # 左の終点と右の始点は各回固定なので先に取っておく lend = bit.sum(idx) rstart = bit.sum(idx) # 自分より小さいindexで最初に自分より小さい値がある直前の場所 l = bisearch_min(-1, idx, calc1) + 1 # 自分より大きいindexで最初に自分より小さい値がある直前の場所 r = bisearch_min(idx, N+1, calc2) - 1 # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a ans[a] = (idx-l+1) * (r-idx+1) * a # aを出現済とする bit.add(idx, 1) # 全てのaについての合計 print((sum(ans)))
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 class BIT: def __init__(self, n): # 0-indexed nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """ [0, i]を合計する """ s = 0 i += 1 while i > 0: s += self.tree[i-1] i -= i & -i return s def add(self, i, x): """ 値の追加:添字i, 値x """ i += 1 while i <= self.size: self.tree[i-1] += x i += i & -i def get(self, l, r=None): """ 区間和の取得 [l, r) """ # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r-1) if l: res -= self.sum(l-1) return res def bisearch_left(self, l, r, x): """ 区間l,rで左からx番目の値がある位置 """ l_val = self.sum(l) ok = r ng = l while ng+1 < ok: mid = (ok+ng) // 2 if self.sum(mid) - l_val >= x: ok = mid else: ng = mid return ok def bisearch_right(self, l, r, x): """ 区間l,rで右からx番目の値がある位置 """ r_val = self.sum(r) ok = r ng = l while ng+1 < ok: mid = (ok+ng) // 2 if r_val - self.sum(mid) < x: ok = mid else: ng = mid return ok N = INT() A = LIST() # aの昇順に処理できるようにindexで並べておく idxs = [0] * (N+1) for i, a in enumerate(A): idxs[a] = i + 1 bit = BIT(N+2) # 先頭と末尾に番兵を仕込む bit.add(0, 1) bit.add(N+1, 1) ans = [0] * (N+1) for a in range(1, N+1): # a(1~N)が格納されているindex idx = idxs[a] # 自分より小さいindexで最初に自分より小さい値がある直前の場所 l = bit.bisearch_right(-1, idx, 1) + 1 # 自分より大きいindexで最初に自分より小さい値がある直前の場所 r = bit.bisearch_left(idx, N+1, 1) - 1 # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a ans[a] = (idx-l+1) * (r-idx+1) * a # aを出現済とする bit.add(idx, 1) # 全てのaについての合計 print((sum(ans)))
107
106
2,559
2,693
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 class BIT: def __init__(self, n): # 0-indexed nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """[0, i]を合計する""" s = 0 i += 1 while i > 0: s += self.tree[i - 1] i -= i & -i return s def add(self, i, x): """値の追加:添字i, 値x""" i += 1 while i <= self.size: self.tree[i - 1] += x i += i & -i def get(self, l, r=None): """区間和の取得 [l, r)""" # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r - 1) if l: res -= self.sum(l - 1) return res def bisearch_min(mn, mx, func): """条件を満たす最小値を見つける二分探索""" ok = mx ng = mn while ng + 1 < ok: mid = (ok + ng) // 2 if func(mid): # 下を探しに行く ok = mid else: # 上を探しに行く ng = mid return ok # 右から1番目の値の位置 def calc1(m): cnt = lend - bit.sum(m) return cnt < 1 # 左から1番目の値の位置 def calc2(m): cnt = bit.sum(m) - rstart return cnt >= 1 N = INT() A = LIST() # aの昇順に処理できるようにindexで並べておく idxs = [0] * (N + 1) for i, a in enumerate(A): idxs[a] = i + 1 bit = BIT(N + 2) # 先頭と末尾に番兵を仕込む bit.add(0, 1) bit.add(N + 1, 1) ans = [0] * (N + 1) for a in range(1, N + 1): # a(1~N)が格納されているindex idx = idxs[a] # 左の終点と右の始点は各回固定なので先に取っておく lend = bit.sum(idx) rstart = bit.sum(idx) # 自分より小さいindexで最初に自分より小さい値がある直前の場所 l = bisearch_min(-1, idx, calc1) + 1 # 自分より大きいindexで最初に自分より小さい値がある直前の場所 r = bisearch_min(idx, N + 1, calc2) - 1 # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a ans[a] = (idx - l + 1) * (r - idx + 1) * a # aを出現済とする bit.add(idx, 1) # 全てのaについての合計 print((sum(ans)))
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 class BIT: def __init__(self, n): # 0-indexed nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """[0, i]を合計する""" s = 0 i += 1 while i > 0: s += self.tree[i - 1] i -= i & -i return s def add(self, i, x): """値の追加:添字i, 値x""" i += 1 while i <= self.size: self.tree[i - 1] += x i += i & -i def get(self, l, r=None): """区間和の取得 [l, r)""" # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r - 1) if l: res -= self.sum(l - 1) return res def bisearch_left(self, l, r, x): """区間l,rで左からx番目の値がある位置""" l_val = self.sum(l) ok = r ng = l while ng + 1 < ok: mid = (ok + ng) // 2 if self.sum(mid) - l_val >= x: ok = mid else: ng = mid return ok def bisearch_right(self, l, r, x): """区間l,rで右からx番目の値がある位置""" r_val = self.sum(r) ok = r ng = l while ng + 1 < ok: mid = (ok + ng) // 2 if r_val - self.sum(mid) < x: ok = mid else: ng = mid return ok N = INT() A = LIST() # aの昇順に処理できるようにindexで並べておく idxs = [0] * (N + 1) for i, a in enumerate(A): idxs[a] = i + 1 bit = BIT(N + 2) # 先頭と末尾に番兵を仕込む bit.add(0, 1) bit.add(N + 1, 1) ans = [0] * (N + 1) for a in range(1, N + 1): # a(1~N)が格納されているindex idx = idxs[a] # 自分より小さいindexで最初に自分より小さい値がある直前の場所 l = bit.bisearch_right(-1, idx, 1) + 1 # 自分より大きいindexで最初に自分より小さい値がある直前の場所 r = bit.bisearch_left(idx, N + 1, 1) - 1 # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a ans[a] = (idx - l + 1) * (r - idx + 1) * a # aを出現済とする bit.add(idx, 1) # 全てのaについての合計 print((sum(ans)))
false
0.934579
[ "+ def bisearch_left(self, l, r, x):", "+ \"\"\"区間l,rで左からx番目の値がある位置\"\"\"", "+ l_val = self.sum(l)", "+ ok = r", "+ ng = l", "+ while ng + 1 < ok:", "+ mid = (ok + ng) // 2", "+ if self.sum(mid) - l_val >= x:", "+ ok = mid", "+ else:", "+ ng = mid", "+ return ok", "-def bisearch_min(mn, mx, func):", "- \"\"\"条件を満たす最小値を見つける二分探索\"\"\"", "- ok = mx", "- ng = mn", "- while ng + 1 < ok:", "- mid = (ok + ng) // 2", "- if func(mid):", "- # 下を探しに行く", "- ok = mid", "- else:", "- # 上を探しに行く", "- ng = mid", "- return ok", "-", "-", "-# 右から1番目の値の位置", "-def calc1(m):", "- cnt = lend - bit.sum(m)", "- return cnt < 1", "-", "-", "-# 左から1番目の値の位置", "-def calc2(m):", "- cnt = bit.sum(m) - rstart", "- return cnt >= 1", "+ def bisearch_right(self, l, r, x):", "+ \"\"\"区間l,rで右からx番目の値がある位置\"\"\"", "+ r_val = self.sum(r)", "+ ok = r", "+ ng = l", "+ while ng + 1 < ok:", "+ mid = (ok + ng) // 2", "+ if r_val - self.sum(mid) < x:", "+ ok = mid", "+ else:", "+ ng = mid", "+ return ok", "- # 左の終点と右の始点は各回固定なので先に取っておく", "- lend = bit.sum(idx)", "- rstart = bit.sum(idx)", "- l = bisearch_min(-1, idx, calc1) + 1", "+ l = bit.bisearch_right(-1, idx, 1) + 1", "- r = bisearch_min(idx, N + 1, calc2) - 1", "+ r = bit.bisearch_left(idx, N + 1, 1) - 1" ]
false
0.038068
0.042702
0.891483
[ "s994207180", "s424531152" ]
u044952145
p03361
python
s968431650
s639394538
39
18
5,236
3,064
Accepted
Accepted
53.85
import sys sys.setrecursionlimit(100000) H, W = list(map(int, input().split())) s = [[c for c in eval(input())] for _ in range(H)] accept = True def dfs(x, y, count): if x < 0 or W <= x or y < 0 or H <= y: return count - 1 elif s[y][x] != "#": return count - 1 else: s[y][x] = "." return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1)) for y in range(H): for x in range(W): if s[y][x] != "#": continue elif dfs(x, y, 0) == 0: accept = False if accept: print("Yes") else: print("No")
H, W = list(map(int, input().split())) s = [[c for c in eval(input())] for _ in range(H)] accept = True s = [["."]*(W+2)] + s + [["."]*(W+2)] for i in range(1, H+1): s[i] = ["."] + s[i] + ["."] for y in range(1, H+1): for x in range(1, W+1): if s[y][x] == "#": if s[y-1][x] == "." and s[y+1][x] == "." and s[y][x-1] == "." and s[y][x+1] == ".": accept = False if accept: print("Yes") else: print("No")
27
18
647
467
import sys sys.setrecursionlimit(100000) H, W = list(map(int, input().split())) s = [[c for c in eval(input())] for _ in range(H)] accept = True def dfs(x, y, count): if x < 0 or W <= x or y < 0 or H <= y: return count - 1 elif s[y][x] != "#": return count - 1 else: s[y][x] = "." return max( dfs(x - 1, y, count + 1), dfs(x + 1, y, count + 1), dfs(x, y - 1, count + 1), dfs(x, y + 1, count + 1), ) for y in range(H): for x in range(W): if s[y][x] != "#": continue elif dfs(x, y, 0) == 0: accept = False if accept: print("Yes") else: print("No")
H, W = list(map(int, input().split())) s = [[c for c in eval(input())] for _ in range(H)] accept = True s = [["."] * (W + 2)] + s + [["."] * (W + 2)] for i in range(1, H + 1): s[i] = ["."] + s[i] + ["."] for y in range(1, H + 1): for x in range(1, W + 1): if s[y][x] == "#": if ( s[y - 1][x] == "." and s[y + 1][x] == "." and s[y][x - 1] == "." and s[y][x + 1] == "." ): accept = False if accept: print("Yes") else: print("No")
false
33.333333
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "-", "-", "-def dfs(x, y, count):", "- if x < 0 or W <= x or y < 0 or H <= y:", "- return count - 1", "- elif s[y][x] != \"#\":", "- return count - 1", "- else:", "- s[y][x] = \".\"", "- return max(", "- dfs(x - 1, y, count + 1),", "- dfs(x + 1, y, count + 1),", "- dfs(x, y - 1, count + 1),", "- dfs(x, y + 1, count + 1),", "- )", "-", "-", "-for y in range(H):", "- for x in range(W):", "- if s[y][x] != \"#\":", "- continue", "- elif dfs(x, y, 0) == 0:", "- accept = False", "+s = [[\".\"] * (W + 2)] + s + [[\".\"] * (W + 2)]", "+for i in range(1, H + 1):", "+ s[i] = [\".\"] + s[i] + [\".\"]", "+for y in range(1, H + 1):", "+ for x in range(1, W + 1):", "+ if s[y][x] == \"#\":", "+ if (", "+ s[y - 1][x] == \".\"", "+ and s[y + 1][x] == \".\"", "+ and s[y][x - 1] == \".\"", "+ and s[y][x + 1] == \".\"", "+ ):", "+ accept = False" ]
false
0.12097
0.059377
2.037336
[ "s968431650", "s639394538" ]