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
u440566786
p02868
python
s317034995
s836321136
1,718
1,533
261,920
262,740
Accepted
Accepted
10.77
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N3)] ref = lambda v : v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) def add_range_edge(l0, r0, l1, r1, w): E.append([]) v = len(E) - 1 _add_range_edge(l0 + N, r0 + N, v, w, to = True) _add_range_edge(l1 + N, r1 + N, v, 0, to = False) def _add_range_edge(l, r, v, w, to): while l < r: if l & 1: E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w)) l >>= 1 r >>= 1 for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 add_range_edge(u, v, u, v, w) # Dijkstra (start : N, terminal : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from heapq import heappop, heappush def build(): for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) def add_range_edge(l0, r0, l1, r1, w): E.append([]) v = len(E) - 1 _add_range_edge(l0 + N, r0 + N, v, w, to = True) _add_range_edge(l1 + N, r1 + N, v, 0, to = False) def _add_range_edge(l, r, v, w, to): while l < r: if l & 1: E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w)) l >>= 1 r >>= 1 def resolve(): global N, N2, E, ref n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N3)] ref = lambda v : v if v < 3 * N else v - N2 build() for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 add_range_edge(u, v, u, v, w) # Dijkstra (start : N, terminal : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
62
64
1,778
1,741
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N3)] ref = lambda v: v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) def add_range_edge(l0, r0, l1, r1, w): E.append([]) v = len(E) - 1 _add_range_edge(l0 + N, r0 + N, v, w, to=True) _add_range_edge(l1 + N, r1 + N, v, 0, to=False) def _add_range_edge(l, r, v, w, to): while l < r: if l & 1: E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w)) l >>= 1 r >>= 1 for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 add_range_edge(u, v, u, v, w) # Dijkstra (start : N, terminal : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def build(): for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) def add_range_edge(l0, r0, l1, r1, w): E.append([]) v = len(E) - 1 _add_range_edge(l0 + N, r0 + N, v, w, to=True) _add_range_edge(l1 + N, r1 + N, v, 0, to=False) def _add_range_edge(l, r, v, w, to): while l < r: if l & 1: E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w)) l >>= 1 r >>= 1 def resolve(): global N, N2, E, ref n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N3)] ref = lambda v: v if v < 3 * N else v - N2 build() for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 add_range_edge(u, v, u, v, w) # Dijkstra (start : N, terminal : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
false
3.125
[ "-def resolve():", "- n, m = list(map(int, input().split()))", "- N = 1 << (n - 1).bit_length()", "- N2, N3 = N * 2, N * 3", "- E = [[] for _ in range(N3)]", "- ref = lambda v: v if v < 3 * N else v - N2", "- # build range-edge graph", "+def build():", "- def add_range_edge(l0, r0, l1, r1, w):", "- E.append([])", "- v = len(E) - 1", "- _add_range_edge(l0 + N, r0 + N, v, w, to=True)", "- _add_range_edge(l1 + N, r1 + N, v, 0, to=False)", "- def _add_range_edge(l, r, v, w, to):", "- while l < r:", "- if l & 1:", "- E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w))", "- l += 1", "- if r & 1:", "- r -= 1", "- E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w))", "- l >>= 1", "- r >>= 1", "+def add_range_edge(l0, r0, l1, r1, w):", "+ E.append([])", "+ v = len(E) - 1", "+ _add_range_edge(l0 + N, r0 + N, v, w, to=True)", "+ _add_range_edge(l1 + N, r1 + N, v, 0, to=False)", "+", "+def _add_range_edge(l, r, v, w, to):", "+ while l < r:", "+ if l & 1:", "+ E[ref(l + N2)].append((v, w)) if to else E[v].append((l, w))", "+ l += 1", "+ if r & 1:", "+ r -= 1", "+ E[ref(r + N2)].append((v, w)) if to else E[v].append((r, w))", "+ l >>= 1", "+ r >>= 1", "+", "+", "+def resolve():", "+ global N, N2, E, ref", "+ n, m = list(map(int, input().split()))", "+ N = 1 << (n - 1).bit_length()", "+ N2, N3 = N * 2, N * 3", "+ E = [[] for _ in range(N3)]", "+ ref = lambda v: v if v < 3 * N else v - N2", "+ build()" ]
false
0.046907
0.039566
1.18553
[ "s317034995", "s836321136" ]
u969850098
p03853
python
s270985613
s584677777
24
18
3,316
3,060
Accepted
Accepted
25
H, W = list(map(int, input().split())) original = [list(eval(input())) for i in range(H)] converted = [[0 for j in range(W)] for i in range(2 * H)] for i in range(2 * H): for j in range(W): converted[i][j] = original[i // 2][j] for row in converted: print((''.join(row)))
H, W = list(map(int, input().split())) original = [list(eval(input())) for i in range(H)] for i in range(2 * H): print((''.join(original[i // 2][:])))
9
4
290
143
H, W = list(map(int, input().split())) original = [list(eval(input())) for i in range(H)] converted = [[0 for j in range(W)] for i in range(2 * H)] for i in range(2 * H): for j in range(W): converted[i][j] = original[i // 2][j] for row in converted: print(("".join(row)))
H, W = list(map(int, input().split())) original = [list(eval(input())) for i in range(H)] for i in range(2 * H): print(("".join(original[i // 2][:])))
false
55.555556
[ "-converted = [[0 for j in range(W)] for i in range(2 * H)]", "- for j in range(W):", "- converted[i][j] = original[i // 2][j]", "-for row in converted:", "- print((\"\".join(row)))", "+ print((\"\".join(original[i // 2][:])))" ]
false
0.038259
0.042733
0.895293
[ "s270985613", "s584677777" ]
u553987207
p03031
python
s523736691
s940381524
33
27
3,064
3,064
Accepted
Accepted
18.18
N, M = list(map(int, input().split())) s = [] for _ in range(M): kss = list(map(int, input().split())) s.append(set([x - 1 for x in kss[1:]])) p = list(map(int, input().split())) ans = 0 for bit in range(1 << N): on_counts = [0] * M for i in range(N): if bit & (1 << i): for m in range(M): if i in s[m]: on_counts[m] += 1 if [x % 2 for x in on_counts] == p: ans += 1 print(ans)
N, M = list(map(int, input().split())) B = [None] * M for i in range(M): ks = list(map(int, input().split())) B[i] = [s - 1 for s in ks[1:]] p = list(map(int, input().split())) ans = 0 bit = 0 for bit in range(1 << N): for i, b in enumerate(B): if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2): break else: ans += 1 print(ans)
18
16
473
386
N, M = list(map(int, input().split())) s = [] for _ in range(M): kss = list(map(int, input().split())) s.append(set([x - 1 for x in kss[1:]])) p = list(map(int, input().split())) ans = 0 for bit in range(1 << N): on_counts = [0] * M for i in range(N): if bit & (1 << i): for m in range(M): if i in s[m]: on_counts[m] += 1 if [x % 2 for x in on_counts] == p: ans += 1 print(ans)
N, M = list(map(int, input().split())) B = [None] * M for i in range(M): ks = list(map(int, input().split())) B[i] = [s - 1 for s in ks[1:]] p = list(map(int, input().split())) ans = 0 bit = 0 for bit in range(1 << N): for i, b in enumerate(B): if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2): break else: ans += 1 print(ans)
false
11.111111
[ "-s = []", "-for _ in range(M):", "- kss = list(map(int, input().split()))", "- s.append(set([x - 1 for x in kss[1:]]))", "+B = [None] * M", "+for i in range(M):", "+ ks = list(map(int, input().split()))", "+ B[i] = [s - 1 for s in ks[1:]]", "+bit = 0", "- on_counts = [0] * M", "- for i in range(N):", "- if bit & (1 << i):", "- for m in range(M):", "- if i in s[m]:", "- on_counts[m] += 1", "- if [x % 2 for x in on_counts] == p:", "+ for i, b in enumerate(B):", "+ if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2):", "+ break", "+ else:" ]
false
0.036777
0.035491
1.036238
[ "s523736691", "s940381524" ]
u729133443
p03037
python
s994420014
s086641808
297
68
82,800
25,076
Accepted
Accepted
77.1
n,m,*t=list(map(int,open(0).read().split()));a,c=[0]*-~n,0 for l,r in zip(t[::2],t[1::2]):a[l-1]+=1;a[r]-=1 for i in range(n):a[i+1]+=a[i];c+=a[i]==m print(c)
n,m,*t=list(map(int,open(0).read().split()));print((max(0,min(t[1::2])-max(t[::2])+1)))
4
1
155
79
n, m, *t = list(map(int, open(0).read().split())) a, c = [0] * -~n, 0 for l, r in zip(t[::2], t[1::2]): a[l - 1] += 1 a[r] -= 1 for i in range(n): a[i + 1] += a[i] c += a[i] == m print(c)
n, m, *t = list(map(int, open(0).read().split())) print((max(0, min(t[1::2]) - max(t[::2]) + 1)))
false
75
[ "-a, c = [0] * -~n, 0", "-for l, r in zip(t[::2], t[1::2]):", "- a[l - 1] += 1", "- a[r] -= 1", "-for i in range(n):", "- a[i + 1] += a[i]", "- c += a[i] == m", "-print(c)", "+print((max(0, min(t[1::2]) - max(t[::2]) + 1)))" ]
false
0.209115
0.043919
4.761374
[ "s994420014", "s086641808" ]
u852690916
p02861
python
s643729578
s634633053
194
18
40,684
3,064
Accepted
Accepted
90.72
N=int(eval(input())) XY=[tuple(map(int, input().split())) for _ in range(N)] from math import sqrt def dist(a,b): return sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2) from itertools import permutations a=b=0 for p in permutations(list(range(N))): b+=1 for i in range(N-1): a+=dist(XY[p[i]], XY[p[i+1]]) print((a/b))
import sys def main(): input = sys.stdin.readline N=int(eval(input())) A=[tuple(map(int, input().split())) for _ in range(N)] ans=0 for i in range(N): for j in range(N): if i==j: continue ans+=((A[i][0]-A[j][0])**2 + (A[i][1]-A[j][1])**2) ** 0.5 print((ans/N)) if __name__ == '__main__': main()
13
14
326
360
N = int(eval(input())) XY = [tuple(map(int, input().split())) for _ in range(N)] from math import sqrt def dist(a, b): return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) from itertools import permutations a = b = 0 for p in permutations(list(range(N))): b += 1 for i in range(N - 1): a += dist(XY[p[i]], XY[p[i + 1]]) print((a / b))
import sys def main(): input = sys.stdin.readline N = int(eval(input())) A = [tuple(map(int, input().split())) for _ in range(N)] ans = 0 for i in range(N): for j in range(N): if i == j: continue ans += ((A[i][0] - A[j][0]) ** 2 + (A[i][1] - A[j][1]) ** 2) ** 0.5 print((ans / N)) if __name__ == "__main__": main()
false
7.142857
[ "-N = int(eval(input()))", "-XY = [tuple(map(int, input().split())) for _ in range(N)]", "-from math import sqrt", "+import sys", "-def dist(a, b):", "- return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)", "+def main():", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ A = [tuple(map(int, input().split())) for _ in range(N)]", "+ ans = 0", "+ for i in range(N):", "+ for j in range(N):", "+ if i == j:", "+ continue", "+ ans += ((A[i][0] - A[j][0]) ** 2 + (A[i][1] - A[j][1]) ** 2) ** 0.5", "+ print((ans / N))", "-from itertools import permutations", "-", "-a = b = 0", "-for p in permutations(list(range(N))):", "- b += 1", "- for i in range(N - 1):", "- a += dist(XY[p[i]], XY[p[i + 1]])", "-print((a / b))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.132842
0.089422
1.485552
[ "s643729578", "s634633053" ]
u271934630
p03076
python
s742525392
s138462159
166
17
38,384
3,064
Accepted
Accepted
89.76
def round_up(i): if i % 10 == 0: return i return 10 - i % 10 + i minutes = [int(eval(input())) for i in range(5)] m = [round_up(i) for i in minutes] last = min((minutes[l] - 1) % 10 for l in range(5)) + 1 print((sum(m) + last - 10))
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() arr = [i_i() for _ in range(5)] arr.sort(key=lambda a: a%10) flag = True ans = 0 for x in arr: if flag and x % 10 >= 1: ans += x flag = False else: if x % 10 != 0: ans += (x + 10) // 10 * 10 else: ans += x // 10 * 10 print(ans)
11
24
254
498
def round_up(i): if i % 10 == 0: return i return 10 - i % 10 + i minutes = [int(eval(input())) for i in range(5)] m = [round_up(i) for i in minutes] last = min((minutes[l] - 1) % 10 for l in range(5)) + 1 print((sum(m) + last - 10))
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() arr = [i_i() for _ in range(5)] arr.sort(key=lambda a: a % 10) flag = True ans = 0 for x in arr: if flag and x % 10 >= 1: ans += x flag = False else: if x % 10 != 0: ans += (x + 10) // 10 * 10 else: ans += x // 10 * 10 print(ans)
false
54.166667
[ "-def round_up(i):", "- if i % 10 == 0:", "- return i", "- return 10 - i % 10 + i", "+import sys", "-", "-minutes = [int(eval(input())) for i in range(5)]", "-m = [round_up(i) for i in minutes]", "-last = min((minutes[l] - 1) % 10 for l in range(5)) + 1", "-print((sum(m) + last - 10))", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**7)", "+i_i = lambda: int(i_s())", "+i_l = lambda: list(map(int, stdin.readline().split()))", "+i_s = lambda: stdin.readline().rstrip()", "+arr = [i_i() for _ in range(5)]", "+arr.sort(key=lambda a: a % 10)", "+flag = True", "+ans = 0", "+for x in arr:", "+ if flag and x % 10 >= 1:", "+ ans += x", "+ flag = False", "+ else:", "+ if x % 10 != 0:", "+ ans += (x + 10) // 10 * 10", "+ else:", "+ ans += x // 10 * 10", "+print(ans)" ]
false
0.137245
0.043687
3.141576
[ "s742525392", "s138462159" ]
u877415670
p02947
python
s255609025
s671594339
534
357
17,804
20,592
Accepted
Accepted
33.15
N = int(eval(input())) dic = {} for i in range(N): s = eval(input()) s = ''.join(sorted(s)) if s in dic: dic[s] += int((-1+(1+8*(dic[s]))**0.5)/2)+1 else: dic[s] = 0 print((sum(dic.values())))
import collections n=int(eval(input())) s = [",".join(sorted(eval(input()))) for i in range(n)] c = collections.Counter(s) ans=0 for i in list(c.values()): ans+=i*(i-1)//2 print(ans)
12
12
200
180
N = int(eval(input())) dic = {} for i in range(N): s = eval(input()) s = "".join(sorted(s)) if s in dic: dic[s] += int((-1 + (1 + 8 * (dic[s])) ** 0.5) / 2) + 1 else: dic[s] = 0 print((sum(dic.values())))
import collections n = int(eval(input())) s = [",".join(sorted(eval(input()))) for i in range(n)] c = collections.Counter(s) ans = 0 for i in list(c.values()): ans += i * (i - 1) // 2 print(ans)
false
0
[ "-N = int(eval(input()))", "-dic = {}", "-for i in range(N):", "- s = eval(input())", "- s = \"\".join(sorted(s))", "- if s in dic:", "- dic[s] += int((-1 + (1 + 8 * (dic[s])) ** 0.5) / 2) + 1", "- else:", "- dic[s] = 0", "-print((sum(dic.values())))", "+import collections", "+", "+n = int(eval(input()))", "+s = [\",\".join(sorted(eval(input()))) for i in range(n)]", "+c = collections.Counter(s)", "+ans = 0", "+for i in list(c.values()):", "+ ans += i * (i - 1) // 2", "+print(ans)" ]
false
0.134151
0.04767
2.814173
[ "s255609025", "s671594339" ]
u347640436
p03201
python
s833627135
s350899577
590
371
44,560
44,592
Accepted
Accepted
37.12
from bisect import bisect_right n = int(eval(input())) d = {} amax = 0 for a in map(int, input().split()): if a in d: d[a] += 1 else: d[a] = 1 amax = max(d.keys()) t = 1 valids = [] while t < 2 * amax: t *= 2 valids.append(t) result = 0 while True: prev = result keys = list(sorted(list(d.keys()), reverse = True)) for x in keys: if x not in d: continue t = valids[bisect_right(valids, x)] - x while True: if t not in d: break if x == t and d[x] == 1: break result += 1 if d[x] == 1: del d[x] else: d[x] -= 1 if d[t] == 1: del d[t] else: d[t] -= 1 if x not in d: break if prev == result: break print(result)
from bisect import bisect_right n = int(eval(input())) d = {} for a in map(int, input().split()): if a in d: d[a] += 1 else: d[a] = 1 amax = max(d.keys()) t = 1 valids = [] while t < 2 * amax: t *= 2 valids.append(t) result = 0 keys = list(sorted(list(d.keys()), reverse = True)) for a in keys: if a not in d: continue t = valids[bisect_right(valids, a)] - a while True: if t not in d: break if a == t and d[a] == 1: break result += 1 if d[a] == 1: del d[a] else: d[a] -= 1 if d[t] == 1: del d[t] else: d[t] -= 1 if a not in d: break print(result)
42
37
786
672
from bisect import bisect_right n = int(eval(input())) d = {} amax = 0 for a in map(int, input().split()): if a in d: d[a] += 1 else: d[a] = 1 amax = max(d.keys()) t = 1 valids = [] while t < 2 * amax: t *= 2 valids.append(t) result = 0 while True: prev = result keys = list(sorted(list(d.keys()), reverse=True)) for x in keys: if x not in d: continue t = valids[bisect_right(valids, x)] - x while True: if t not in d: break if x == t and d[x] == 1: break result += 1 if d[x] == 1: del d[x] else: d[x] -= 1 if d[t] == 1: del d[t] else: d[t] -= 1 if x not in d: break if prev == result: break print(result)
from bisect import bisect_right n = int(eval(input())) d = {} for a in map(int, input().split()): if a in d: d[a] += 1 else: d[a] = 1 amax = max(d.keys()) t = 1 valids = [] while t < 2 * amax: t *= 2 valids.append(t) result = 0 keys = list(sorted(list(d.keys()), reverse=True)) for a in keys: if a not in d: continue t = valids[bisect_right(valids, a)] - a while True: if t not in d: break if a == t and d[a] == 1: break result += 1 if d[a] == 1: del d[a] else: d[a] -= 1 if d[t] == 1: del d[t] else: d[t] -= 1 if a not in d: break print(result)
false
11.904762
[ "-amax = 0", "-while True:", "- prev = result", "- keys = list(sorted(list(d.keys()), reverse=True))", "- for x in keys:", "- if x not in d:", "- continue", "- t = valids[bisect_right(valids, x)] - x", "- while True:", "- if t not in d:", "- break", "- if x == t and d[x] == 1:", "- break", "- result += 1", "- if d[x] == 1:", "- del d[x]", "- else:", "- d[x] -= 1", "- if d[t] == 1:", "- del d[t]", "- else:", "- d[t] -= 1", "- if x not in d:", "- break", "- if prev == result:", "- break", "+keys = list(sorted(list(d.keys()), reverse=True))", "+for a in keys:", "+ if a not in d:", "+ continue", "+ t = valids[bisect_right(valids, a)] - a", "+ while True:", "+ if t not in d:", "+ break", "+ if a == t and d[a] == 1:", "+ break", "+ result += 1", "+ if d[a] == 1:", "+ del d[a]", "+ else:", "+ d[a] -= 1", "+ if d[t] == 1:", "+ del d[t]", "+ else:", "+ d[t] -= 1", "+ if a not in d:", "+ break" ]
false
0.032807
0.037128
0.883637
[ "s833627135", "s350899577" ]
u066855390
p03107
python
s685466088
s449351479
47
31
4,648
3,956
Accepted
Accepted
34.04
S = list(eval(input())) last = S.pop(0) stack = [last] can_pop = True cnt = 0 for s in S: if last != s and can_pop: stack.pop() if len(stack) == 0: can_pop = False # stack.append(s) 読み捨て cnt += 2 else: stack.append(s) last = s can_pop = True print(cnt)
S = list(eval(input())) one = 0 zero = 0 for s in S: if s == "1": one += 1 else: zero += 1 print((min(one, zero) * 2))
19
10
343
144
S = list(eval(input())) last = S.pop(0) stack = [last] can_pop = True cnt = 0 for s in S: if last != s and can_pop: stack.pop() if len(stack) == 0: can_pop = False # stack.append(s) 読み捨て cnt += 2 else: stack.append(s) last = s can_pop = True print(cnt)
S = list(eval(input())) one = 0 zero = 0 for s in S: if s == "1": one += 1 else: zero += 1 print((min(one, zero) * 2))
false
47.368421
[ "-last = S.pop(0)", "-stack = [last]", "-can_pop = True", "-cnt = 0", "+one = 0", "+zero = 0", "- if last != s and can_pop:", "- stack.pop()", "- if len(stack) == 0:", "- can_pop = False", "- # stack.append(s) 読み捨て", "- cnt += 2", "+ if s == \"1\":", "+ one += 1", "- stack.append(s)", "- last = s", "- can_pop = True", "-print(cnt)", "+ zero += 1", "+print((min(one, zero) * 2))" ]
false
0.033883
0.037423
0.905401
[ "s685466088", "s449351479" ]
u686230543
p02796
python
s152058997
s204135423
513
449
16,660
17,364
Accepted
Accepted
12.48
from heapq import heappop, heappush n = int(eval(input())) robots = [] for _ in range(n): x, l = list(map(int, input().split())) heappush(robots, (x+l, x-l)) robot = heappop(robots) hand = robot[0] count = 1 while robots: robot = heappop(robots) if hand <= robot[1]: hand = robot[0] count += 1 print(count)
n = int(eval(input())) robots = [] for _ in range(n): x, l = list(map(int, input().split())) robots.append((x+l, x-l)) robots.sort() hand = robots[0][0] count = 1 for robot in robots[1:]: if hand <= robot[1]: hand = robot[0] count += 1 print(count)
17
14
328
264
from heapq import heappop, heappush n = int(eval(input())) robots = [] for _ in range(n): x, l = list(map(int, input().split())) heappush(robots, (x + l, x - l)) robot = heappop(robots) hand = robot[0] count = 1 while robots: robot = heappop(robots) if hand <= robot[1]: hand = robot[0] count += 1 print(count)
n = int(eval(input())) robots = [] for _ in range(n): x, l = list(map(int, input().split())) robots.append((x + l, x - l)) robots.sort() hand = robots[0][0] count = 1 for robot in robots[1:]: if hand <= robot[1]: hand = robot[0] count += 1 print(count)
false
17.647059
[ "-from heapq import heappop, heappush", "-", "- heappush(robots, (x + l, x - l))", "-robot = heappop(robots)", "-hand = robot[0]", "+ robots.append((x + l, x - l))", "+robots.sort()", "+hand = robots[0][0]", "-while robots:", "- robot = heappop(robots)", "+for robot in robots[1:]:" ]
false
0.098804
0.041473
2.382391
[ "s152058997", "s204135423" ]
u330661451
p02757
python
s085629257
s942709318
163
121
3,500
3,500
Accepted
Accepted
25.77
n,p = list(map(int,input().split())) s = eval(input()) l = [0 for i in range(p)] l[0] = 1 ten = 1 cnt = 0 ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i+1 else: for i in range(n): cnt = (cnt + int(s[-i-1]) * ten) % p l[cnt] += 1 ten = (ten * 10) % p for i in l: if i > 1: ans += i * (i - 1) // 2 print(ans)
def main(): n,p = list(map(int,input().split())) s = eval(input()) l = [0 for i in range(p)] l[0] = 1 ten = 1 cnt = 0 ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i+1 else: for i in range(n): cnt = (cnt + int(s[-i-1]) * ten) % p l[cnt] += 1 ten = (ten * 10) % p for i in l: if i > 1: ans += i * (i - 1) // 2 print(ans) if __name__ == "__main__": main()
22
26
426
561
n, p = list(map(int, input().split())) s = eval(input()) l = [0 for i in range(p)] l[0] = 1 ten = 1 cnt = 0 ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i + 1 else: for i in range(n): cnt = (cnt + int(s[-i - 1]) * ten) % p l[cnt] += 1 ten = (ten * 10) % p for i in l: if i > 1: ans += i * (i - 1) // 2 print(ans)
def main(): n, p = list(map(int, input().split())) s = eval(input()) l = [0 for i in range(p)] l[0] = 1 ten = 1 cnt = 0 ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i + 1 else: for i in range(n): cnt = (cnt + int(s[-i - 1]) * ten) % p l[cnt] += 1 ten = (ten * 10) % p for i in l: if i > 1: ans += i * (i - 1) // 2 print(ans) if __name__ == "__main__": main()
false
15.384615
[ "-n, p = list(map(int, input().split()))", "-s = eval(input())", "-l = [0 for i in range(p)]", "-l[0] = 1", "-ten = 1", "-cnt = 0", "-ans = 0", "-if p == 2 or p == 5:", "- for i in range(n):", "- if int(s[i]) % p == 0:", "- ans += i + 1", "-else:", "- for i in range(n):", "- cnt = (cnt + int(s[-i - 1]) * ten) % p", "- l[cnt] += 1", "- ten = (ten * 10) % p", "- for i in l:", "- if i > 1:", "- ans += i * (i - 1) // 2", "-print(ans)", "+def main():", "+ n, p = list(map(int, input().split()))", "+ s = eval(input())", "+ l = [0 for i in range(p)]", "+ l[0] = 1", "+ ten = 1", "+ cnt = 0", "+ ans = 0", "+ if p == 2 or p == 5:", "+ for i in range(n):", "+ if int(s[i]) % p == 0:", "+ ans += i + 1", "+ else:", "+ for i in range(n):", "+ cnt = (cnt + int(s[-i - 1]) * ten) % p", "+ l[cnt] += 1", "+ ten = (ten * 10) % p", "+ for i in l:", "+ if i > 1:", "+ ans += i * (i - 1) // 2", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.03608
0.036605
0.985668
[ "s085629257", "s942709318" ]
u821624310
p02388
python
s411743317
s262785623
30
20
7,608
7,612
Accepted
Accepted
33.33
x = int(eval(input())) print((x**3))
N = int(eval(input())) print((N ** 3))
2
2
29
31
x = int(eval(input())) print((x**3))
N = int(eval(input())) print((N**3))
false
0
[ "-x = int(eval(input()))", "-print((x**3))", "+N = int(eval(input()))", "+print((N**3))" ]
false
0.040165
0.040073
1.002293
[ "s411743317", "s262785623" ]
u734529045
p02713
python
s328595367
s657964667
1,927
1,003
9,156
80,244
Accepted
Accepted
47.95
from math import gcd K = int(eval(input())) res = 0 for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): res += gcd(gcd(i, j), k) print(res)
import time def gcd(a, b): return a if b == 0 else gcd(b, a%b) K = int(eval(input())) res = 0 for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): res += gcd(gcd(i, j), k) print(res)
8
11
184
234
from math import gcd K = int(eval(input())) res = 0 for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): res += gcd(gcd(i, j), k) print(res)
import time def gcd(a, b): return a if b == 0 else gcd(b, a % b) K = int(eval(input())) res = 0 for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): res += gcd(gcd(i, j), k) print(res)
false
27.272727
[ "-from math import gcd", "+import time", "+", "+", "+def gcd(a, b):", "+ return a if b == 0 else gcd(b, a % b)", "+" ]
false
0.052494
0.04061
1.292646
[ "s328595367", "s657964667" ]
u633068244
p00613
python
s631867100
s666067454
40
30
4,300
4,304
Accepted
Accepted
25
while 1: k = int(input()) if not k: break print(sum(map(int, input().split()))/(k-1))
while 1: k = eval(input()) if not k: break print(sum(map(int, input().split()))/(k-1))
4
4
98
89
while 1: k = int(input()) if not k: break print(sum(map(int, input().split())) / (k - 1))
while 1: k = eval(input()) if not k: break print(sum(map(int, input().split())) / (k - 1))
false
0
[ "- k = int(input())", "+ k = eval(input())" ]
false
0.037008
0.038609
0.958527
[ "s631867100", "s666067454" ]
u588341295
p02788
python
s270156520
s412309802
1,459
1,090
122,876
104,256
Accepted
Accepted
25.29
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class StarrySkyTree: """ Starry Sky Tree(区間加算・区間最小(大)値取得) """ def __init__(self, N, func, intv): self.intv = intv self.func = func LV = (N-1).bit_length() self.N0 = 2**LV self.data = [0]*(2*self.N0) self.lazy = [0]*(2*self.N0) # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator def gindex(self, l, r): L = l + self.N0; R = r + self.N0 lm = (L // (L & -L)) >> 1 rm = (R // (R & -R)) >> 1 while L < R: if R <= rm: yield R if L <= lm: yield L L >>= 1; R >>= 1 while L: yield L L >>= 1 # 遅延評価の伝搬処理 def propagates(self, *ids): # 1-indexedで単調増加のインデックスリスト for i in reversed(ids): v = self.lazy[i-1] if not v: continue self.lazy[2*i-1] += v; self.lazy[2*i] += v self.data[2*i-1] += v; self.data[2*i] += v self.lazy[i-1] = 0 def update(self, l, r, x): """ 区間[l,r)の値にxを加算 """ # 1. lazyの値は伝搬させない # 2. 区間[l,r)のdata, lazyの値を更新 L = self.N0 + l; R = self.N0 + r while L < R: if R & 1: R -= 1 self.lazy[R-1] += x; self.data[R-1] += x if L & 1: self.lazy[L-1] += x; self.data[L-1] += x L += 1 L >>= 1; R >>= 1 # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮) for i in self.gindex(l, r): self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i]) + self.lazy[i-1] def query(self, l, r): """ 区間[l,r)の最小(大)値を取得 """ # 1. トップダウンにlazyの値を伝搬 self.propagates(*self.gindex(l, r)) L = self.N0 + l; R = self.N0 + r # 2. 区間[l, r)の最小(大)値を求める s = self.intv while L < R: if R & 1: R -= 1 s = self.func(s, self.data[R-1]) if L & 1: s = self.func(s, self.data[L-1]) L += 1 L >>= 1; R >>= 1 return s N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = list(zip(*XH)) D = D * 2 sst = StarrySkyTree(N, max, 0) ans = 0 for i, (x, h) in enumerate(XH): h -= sst.query(i, i+1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x+D) - 1 sst.update(i, idx+1, cnt) ans += cnt print(ans)
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter 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(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class BIT2: """ 区間加算BIT(区間加算・区間合計取得) """ def __init__(self, N): # 添字0が使えないので、内部的には全て1-indexedとして扱う N += 1 self.N = N self.data0 = [0] * N self.data1 = [0] * N def _add(self, data, k, x): k += 1 while k < self.N: data[k] += x k += k & -k def _get(self, data, k): k += 1 s = 0 while k: s += data[k] k -= k & -k return s def add(self, l, r, x): """ 区間[l,r)に値xを追加 """ self._add(self.data0, l, -x*(l-1)) self._add(self.data0, r, x*(r-1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def query(self, l, r): """ 区間[l,r)の和を取得 """ return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \ - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = zip(*XH) D = D * 2 bit = BIT2(N) ans = 0 for i, (x, h) in enumerate(XH): h -= bit.query(i, i+1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x+D) - 1 bit.add(i, idx+1, cnt) ans += cnt print(ans)
118
82
3,342
2,096
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 class StarrySkyTree: """Starry Sky Tree(区間加算・区間最小(大)値取得)""" def __init__(self, N, func, intv): self.intv = intv self.func = func LV = (N - 1).bit_length() self.N0 = 2**LV self.data = [0] * (2 * self.N0) self.lazy = [0] * (2 * self.N0) # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator def gindex(self, l, r): L = l + self.N0 R = r + self.N0 lm = (L // (L & -L)) >> 1 rm = (R // (R & -R)) >> 1 while L < R: if R <= rm: yield R if L <= lm: yield L L >>= 1 R >>= 1 while L: yield L L >>= 1 # 遅延評価の伝搬処理 def propagates(self, *ids): # 1-indexedで単調増加のインデックスリスト for i in reversed(ids): v = self.lazy[i - 1] if not v: continue self.lazy[2 * i - 1] += v self.lazy[2 * i] += v self.data[2 * i - 1] += v self.data[2 * i] += v self.lazy[i - 1] = 0 def update(self, l, r, x): """区間[l,r)の値にxを加算""" # 1. lazyの値は伝搬させない # 2. 区間[l,r)のdata, lazyの値を更新 L = self.N0 + l R = self.N0 + r while L < R: if R & 1: R -= 1 self.lazy[R - 1] += x self.data[R - 1] += x if L & 1: self.lazy[L - 1] += x self.data[L - 1] += x L += 1 L >>= 1 R >>= 1 # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮) for i in self.gindex(l, r): self.data[i - 1] = ( self.func(self.data[2 * i - 1], self.data[2 * i]) + self.lazy[i - 1] ) def query(self, l, r): """区間[l,r)の最小(大)値を取得""" # 1. トップダウンにlazyの値を伝搬 self.propagates(*self.gindex(l, r)) L = self.N0 + l R = self.N0 + r # 2. 区間[l, r)の最小(大)値を求める s = self.intv while L < R: if R & 1: R -= 1 s = self.func(s, self.data[R - 1]) if L & 1: s = self.func(s, self.data[L - 1]) L += 1 L >>= 1 R >>= 1 return s N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = list(zip(*XH)) D = D * 2 sst = StarrySkyTree(N, max, 0) ans = 0 for i, (x, h) in enumerate(XH): h -= sst.query(i, i + 1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x + D) - 1 sst.update(i, idx + 1, cnt) ans += cnt print(ans)
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter 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(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 class BIT2: """区間加算BIT(区間加算・区間合計取得)""" def __init__(self, N): # 添字0が使えないので、内部的には全て1-indexedとして扱う N += 1 self.N = N self.data0 = [0] * N self.data1 = [0] * N def _add(self, data, k, x): k += 1 while k < self.N: data[k] += x k += k & -k def _get(self, data, k): k += 1 s = 0 while k: s += data[k] k -= k & -k return s def add(self, l, r, x): """区間[l,r)に値xを追加""" self._add(self.data0, l, -x * (l - 1)) self._add(self.data0, r, x * (r - 1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def query(self, l, r): """区間[l,r)の和を取得""" return ( self._get(self.data1, r - 1) * (r - 1) + self._get(self.data0, r - 1) - self._get(self.data1, l - 1) * (l - 1) - self._get(self.data0, l - 1) ) N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = zip(*XH) D = D * 2 bit = BIT2(N) ans = 0 for i, (x, h) in enumerate(XH): h -= bit.query(i, i + 1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x + D) - 1 bit.add(i, idx + 1, cnt) ans += cnt print(ans)
false
30.508475
[ "- return int(eval(input()))", "+ return int(input())", "- return list(map(int, input().split()))", "+ return map(int, input().split())", "-class StarrySkyTree:", "- \"\"\"Starry Sky Tree(区間加算・区間最小(大)値取得)\"\"\"", "+class BIT2:", "+ \"\"\"区間加算BIT(区間加算・区間合計取得)\"\"\"", "- def __init__(self, N, func, intv):", "- self.intv = intv", "- self.func = func", "- LV = (N - 1).bit_length()", "- self.N0 = 2**LV", "- self.data = [0] * (2 * self.N0)", "- self.lazy = [0] * (2 * self.N0)", "+ def __init__(self, N):", "+ # 添字0が使えないので、内部的には全て1-indexedとして扱う", "+ N += 1", "+ self.N = N", "+ self.data0 = [0] * N", "+ self.data1 = [0] * N", "- # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator", "- def gindex(self, l, r):", "- L = l + self.N0", "- R = r + self.N0", "- lm = (L // (L & -L)) >> 1", "- rm = (R // (R & -R)) >> 1", "- while L < R:", "- if R <= rm:", "- yield R", "- if L <= lm:", "- yield L", "- L >>= 1", "- R >>= 1", "- while L:", "- yield L", "- L >>= 1", "+ def _add(self, data, k, x):", "+ k += 1", "+ while k < self.N:", "+ data[k] += x", "+ k += k & -k", "- # 遅延評価の伝搬処理", "- def propagates(self, *ids):", "- # 1-indexedで単調増加のインデックスリスト", "- for i in reversed(ids):", "- v = self.lazy[i - 1]", "- if not v:", "- continue", "- self.lazy[2 * i - 1] += v", "- self.lazy[2 * i] += v", "- self.data[2 * i - 1] += v", "- self.data[2 * i] += v", "- self.lazy[i - 1] = 0", "+ def _get(self, data, k):", "+ k += 1", "+ s = 0", "+ while k:", "+ s += data[k]", "+ k -= k & -k", "+ return s", "- def update(self, l, r, x):", "- \"\"\"区間[l,r)の値にxを加算\"\"\"", "- # 1. lazyの値は伝搬させない", "- # 2. 区間[l,r)のdata, lazyの値を更新", "- L = self.N0 + l", "- R = self.N0 + r", "- while L < R:", "- if R & 1:", "- R -= 1", "- self.lazy[R - 1] += x", "- self.data[R - 1] += x", "- if L & 1:", "- self.lazy[L - 1] += x", "- self.data[L - 1] += x", "- L += 1", "- L >>= 1", "- R >>= 1", "- # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)", "- for i in self.gindex(l, r):", "- self.data[i - 1] = (", "- self.func(self.data[2 * i - 1], self.data[2 * i]) + self.lazy[i - 1]", "- )", "+ def add(self, l, r, x):", "+ \"\"\"区間[l,r)に値xを追加\"\"\"", "+ self._add(self.data0, l, -x * (l - 1))", "+ self._add(self.data0, r, x * (r - 1))", "+ self._add(self.data1, l, x)", "+ self._add(self.data1, r, -x)", "- \"\"\"区間[l,r)の最小(大)値を取得\"\"\"", "- # 1. トップダウンにlazyの値を伝搬", "- self.propagates(*self.gindex(l, r))", "- L = self.N0 + l", "- R = self.N0 + r", "- # 2. 区間[l, r)の最小(大)値を求める", "- s = self.intv", "- while L < R:", "- if R & 1:", "- R -= 1", "- s = self.func(s, self.data[R - 1])", "- if L & 1:", "- s = self.func(s, self.data[L - 1])", "- L += 1", "- L >>= 1", "- R >>= 1", "- return s", "+ \"\"\"区間[l,r)の和を取得\"\"\"", "+ return (", "+ self._get(self.data1, r - 1) * (r - 1)", "+ + self._get(self.data0, r - 1)", "+ - self._get(self.data1, l - 1) * (l - 1)", "+ - self._get(self.data0, l - 1)", "+ )", "-X, _ = list(zip(*XH))", "+X, _ = zip(*XH)", "-sst = StarrySkyTree(N, max, 0)", "+bit = BIT2(N)", "- h -= sst.query(i, i + 1) * K", "+ h -= bit.query(i, i + 1) * K", "- sst.update(i, idx + 1, cnt)", "+ bit.add(i, idx + 1, cnt)" ]
false
0.048023
0.045685
1.051182
[ "s270156520", "s412309802" ]
u221301671
p03163
python
s895919208
s076789740
1,275
421
159,060
17,952
Accepted
Accepted
66.98
n, w = [int(i) for i in input().split()] sv = {} for i in range(n): ww, vv = list(map(int, input().split())) if ww > w: continue added = {} for k, v in list(sv.items()): if (ww+k) <= w: added[ww+k] = vv+v for k, v in list(added.items()): sv[k] = max(v, sv.get(k, 0)) sv[ww] = max(vv, sv.get(ww, 0)) print((max(sv.values())))
import numpy as np n, ww = list(map(int, input().split())) s = np.zeros(ww+1, dtype=np.int64) for i in range(n): w, v = list(map(int, input().split())) s[w:] = np.maximum(s[w:], s[:-w] + v) print((s[ww]))
17
10
383
210
n, w = [int(i) for i in input().split()] sv = {} for i in range(n): ww, vv = list(map(int, input().split())) if ww > w: continue added = {} for k, v in list(sv.items()): if (ww + k) <= w: added[ww + k] = vv + v for k, v in list(added.items()): sv[k] = max(v, sv.get(k, 0)) sv[ww] = max(vv, sv.get(ww, 0)) print((max(sv.values())))
import numpy as np n, ww = list(map(int, input().split())) s = np.zeros(ww + 1, dtype=np.int64) for i in range(n): w, v = list(map(int, input().split())) s[w:] = np.maximum(s[w:], s[:-w] + v) print((s[ww]))
false
41.176471
[ "-n, w = [int(i) for i in input().split()]", "-sv = {}", "+import numpy as np", "+", "+n, ww = list(map(int, input().split()))", "+s = np.zeros(ww + 1, dtype=np.int64)", "- ww, vv = list(map(int, input().split()))", "- if ww > w:", "- continue", "- added = {}", "- for k, v in list(sv.items()):", "- if (ww + k) <= w:", "- added[ww + k] = vv + v", "- for k, v in list(added.items()):", "- sv[k] = max(v, sv.get(k, 0))", "- sv[ww] = max(vv, sv.get(ww, 0))", "-print((max(sv.values())))", "+ w, v = list(map(int, input().split()))", "+ s[w:] = np.maximum(s[w:], s[:-w] + v)", "+print((s[ww]))" ]
false
0.039995
0.182437
0.219225
[ "s895919208", "s076789740" ]
u815878613
p03127
python
s826568839
s986086714
165
143
14,252
12,496
Accepted
Accepted
13.33
def vs(A): A = sorted(A) pA = list([x % A[0] for x in A]) pA[0] = A[0] return list([x for x in pA if x != 0]) N = int(eval(input())) A = list(map(int, input().split())) spA = -1 sA = -2 while spA != sA: sA = sum(A) pA = vs(A) spA = sum(pA) A = pA print((sum(A)))
import sys readline = sys.stdin.buffer.readline def sss(A, N): A.sort() while A[0] == 0: A.remove(0) for i in range(1, len(A)): A[i] = A[i] % A[0] if A[0] == sum(A): print((sum(A))) else: return sss(A, N) def main(): N = int(readline()) A = list(map(int, readline().split())) sss(A, N) main()
20
25
319
387
def vs(A): A = sorted(A) pA = list([x % A[0] for x in A]) pA[0] = A[0] return list([x for x in pA if x != 0]) N = int(eval(input())) A = list(map(int, input().split())) spA = -1 sA = -2 while spA != sA: sA = sum(A) pA = vs(A) spA = sum(pA) A = pA print((sum(A)))
import sys readline = sys.stdin.buffer.readline def sss(A, N): A.sort() while A[0] == 0: A.remove(0) for i in range(1, len(A)): A[i] = A[i] % A[0] if A[0] == sum(A): print((sum(A))) else: return sss(A, N) def main(): N = int(readline()) A = list(map(int, readline().split())) sss(A, N) main()
false
20
[ "-def vs(A):", "- A = sorted(A)", "- pA = list([x % A[0] for x in A])", "- pA[0] = A[0]", "- return list([x for x in pA if x != 0])", "+import sys", "+", "+readline = sys.stdin.buffer.readline", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-spA = -1", "-sA = -2", "-while spA != sA:", "- sA = sum(A)", "- pA = vs(A)", "- spA = sum(pA)", "- A = pA", "-print((sum(A)))", "+def sss(A, N):", "+ A.sort()", "+ while A[0] == 0:", "+ A.remove(0)", "+ for i in range(1, len(A)):", "+ A[i] = A[i] % A[0]", "+ if A[0] == sum(A):", "+ print((sum(A)))", "+ else:", "+ return sss(A, N)", "+", "+", "+def main():", "+ N = int(readline())", "+ A = list(map(int, readline().split()))", "+ sss(A, N)", "+", "+", "+main()" ]
false
0.036346
0.034825
1.043694
[ "s826568839", "s986086714" ]
u156815136
p03150
python
s878570326
s393937624
52
21
5,724
3,316
Accepted
Accepted
59.62
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) ans = 'keyence' S = eval(input()) lenS = len(S) for i in range(1,7): #print(ans[i:],S[lenS-7 + i:]) #print(ans[:i], S[:i]) if ans[:i] == S[:i] and ans[i:] == S[lenS - 7 + i:]: print('YES') exit() print('NO')
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) s = list(eval(input())) nya = list("keyence") slen = len(s) for i in range(slen): #rint(s[:i],nya[:i],s[-7+i:],nya[-7+i:]) if s[:i] == nya[:i] and s[-7 + i:] == nya[-7 + i:]: print('YES') exit() print('NO')
36
35
821
837
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) ans = "keyence" S = eval(input()) lenS = len(S) for i in range(1, 7): # print(ans[i:],S[lenS-7 + i:]) # print(ans[:i], S[:i]) if ans[:i] == S[:i] and ans[i:] == S[lenS - 7 + i :]: print("YES") exit() print("NO")
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from fractions import gcd # from itertools import combinations # (string,3) 3回 # from collections import deque from collections import defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) s = list(eval(input())) nya = list("keyence") slen = len(s) for i in range(slen): # rint(s[:i],nya[:i],s[-7+i:],nya[-7+i:]) if s[:i] == nya[:i] and s[-7 + i :] == nya[-7 + i :]: print("YES") exit() print("NO")
false
2.777778
[ "-from statistics import median", "-", "+# from statistics import median", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "+# from fractions import gcd", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "-import bisect", "+# import bisect", "-", "-", "+# mod = 9982443453", "-ans = \"keyence\"", "-S = eval(input())", "-lenS = len(S)", "-for i in range(1, 7):", "- # print(ans[i:],S[lenS-7 + i:])", "- # print(ans[:i], S[:i])", "- if ans[:i] == S[:i] and ans[i:] == S[lenS - 7 + i :]:", "+s = list(eval(input()))", "+nya = list(\"keyence\")", "+slen = len(s)", "+for i in range(slen):", "+ # rint(s[:i],nya[:i],s[-7+i:],nya[-7+i:])", "+ if s[:i] == nya[:i] and s[-7 + i :] == nya[-7 + i :]:" ]
false
0.046962
0.094221
0.498421
[ "s878570326", "s393937624" ]
u706414019
p03472
python
s290216832
s488967531
322
269
35,136
33,116
Accepted
Accepted
16.46
import sys,math import numpy as np input = sys.stdin.readline b_max=0 a_max=0 a = [] b = [] N,H = list(map(int,input().split())) for i in range(N): an,bn = list(map(int,input().split())) a.append(an) b.append(bn) a_max = max(a_max,an) b_max = max(b_max,bn) a = np.array(a) b = np.array(b) b = sorted(list(b[b>=a_max])) cnt = 0 for i in range(len(b)): H -= b.pop() cnt += 1 if H <=0: print(cnt) exit() cnt += math.ceil(H/a_max) print(cnt)
import sys,math import numpy as np input = sys.stdin.readline a_max=0 a = [] b = [] N,H = list(map(int,input().split())) for i in range(N): an,bn = list(map(int,input().split())) b.append(bn) a_max = max(a_max,an) b = np.array(b) b = sorted(list(b[b>=a_max])) cnt = 0 for i in range(len(b)): H -= b.pop() cnt += 1 if H <=0: print(cnt) exit() cnt += math.ceil(H/a_max) print(cnt)
29
26
517
436
import sys, math import numpy as np input = sys.stdin.readline b_max = 0 a_max = 0 a = [] b = [] N, H = list(map(int, input().split())) for i in range(N): an, bn = list(map(int, input().split())) a.append(an) b.append(bn) a_max = max(a_max, an) b_max = max(b_max, bn) a = np.array(a) b = np.array(b) b = sorted(list(b[b >= a_max])) cnt = 0 for i in range(len(b)): H -= b.pop() cnt += 1 if H <= 0: print(cnt) exit() cnt += math.ceil(H / a_max) print(cnt)
import sys, math import numpy as np input = sys.stdin.readline a_max = 0 a = [] b = [] N, H = list(map(int, input().split())) for i in range(N): an, bn = list(map(int, input().split())) b.append(bn) a_max = max(a_max, an) b = np.array(b) b = sorted(list(b[b >= a_max])) cnt = 0 for i in range(len(b)): H -= b.pop() cnt += 1 if H <= 0: print(cnt) exit() cnt += math.ceil(H / a_max) print(cnt)
false
10.344828
[ "-b_max = 0", "- a.append(an)", "- b_max = max(b_max, bn)", "-a = np.array(a)" ]
false
0.308737
0.396853
0.777963
[ "s290216832", "s488967531" ]
u674052742
p02923
python
s318839361
s518046503
90
78
14,252
15,020
Accepted
Accepted
13.33
# -*- coding: utf-8 -*- """ Created on Wed Mar 25 10:13:10 2020 @author: Kanaru Sato """ N = int(eval(input())) H = list(map(int, input().split())) ans = 0 count = 0 for i in range(0,N-1): if H[i] >= H[i+1]: count += 1 ans = max(ans,count) else: count = 0 print(ans)
# -*- coding: utf-8 -*- """ Created on Wed Mar 25 10:13:10 2020 @author: Kanaru Sato """ N = int(eval(input())) H = list(map(int, input().split())) record = 0 count = 0 for i in range(0,N-1): if H[i] >= H[i+1]: count += 1 else: record = max(count,record) count = 0 ans = max(record,count) print(ans)
20
22
315
351
# -*- coding: utf-8 -*- """ Created on Wed Mar 25 10:13:10 2020 @author: Kanaru Sato """ N = int(eval(input())) H = list(map(int, input().split())) ans = 0 count = 0 for i in range(0, N - 1): if H[i] >= H[i + 1]: count += 1 ans = max(ans, count) else: count = 0 print(ans)
# -*- coding: utf-8 -*- """ Created on Wed Mar 25 10:13:10 2020 @author: Kanaru Sato """ N = int(eval(input())) H = list(map(int, input().split())) record = 0 count = 0 for i in range(0, N - 1): if H[i] >= H[i + 1]: count += 1 else: record = max(count, record) count = 0 ans = max(record, count) print(ans)
false
9.090909
[ "-ans = 0", "+record = 0", "- ans = max(ans, count)", "+ record = max(count, record)", "+ans = max(record, count)" ]
false
0.195976
0.162442
1.20644
[ "s318839361", "s518046503" ]
u353797797
p03170
python
s348693159
s365373544
522
126
3,828
3,828
Accepted
Accepted
75.86
def judge(i): for a in a_s: di = i - a if di < 0: return "Second" if dp[di] == "Second": return "First" return "Second" n, k = list(map(int, input().split())) a_s = list(map(int, input().split())) dp = [""] * (k + 1) dp[0] = "Second" for i in range(1, k + 1): dp[i] = judge(i) print((dp[-1]))
n, k = list(map(int, input().split())) a_s = list(map(int, input().split())) dp = ["Second"] * (k + 1) for i in range(k + 1): if dp[i] == "Second": for a in a_s: ii = i + a if ii <= k: dp[ii] = "First" print((dp[-1]))
17
10
363
271
def judge(i): for a in a_s: di = i - a if di < 0: return "Second" if dp[di] == "Second": return "First" return "Second" n, k = list(map(int, input().split())) a_s = list(map(int, input().split())) dp = [""] * (k + 1) dp[0] = "Second" for i in range(1, k + 1): dp[i] = judge(i) print((dp[-1]))
n, k = list(map(int, input().split())) a_s = list(map(int, input().split())) dp = ["Second"] * (k + 1) for i in range(k + 1): if dp[i] == "Second": for a in a_s: ii = i + a if ii <= k: dp[ii] = "First" print((dp[-1]))
false
41.176471
[ "-def judge(i):", "- for a in a_s:", "- di = i - a", "- if di < 0:", "- return \"Second\"", "- if dp[di] == \"Second\":", "- return \"First\"", "- return \"Second\"", "-", "-", "-dp = [\"\"] * (k + 1)", "-dp[0] = \"Second\"", "-for i in range(1, k + 1):", "- dp[i] = judge(i)", "+dp = [\"Second\"] * (k + 1)", "+for i in range(k + 1):", "+ if dp[i] == \"Second\":", "+ for a in a_s:", "+ ii = i + a", "+ if ii <= k:", "+ dp[ii] = \"First\"" ]
false
0.07219
0.03952
1.826665
[ "s348693159", "s365373544" ]
u223133214
p02844
python
s699314650
s894454601
1,148
875
59,868
50,300
Accepted
Accepted
23.78
import sys input = sys.stdin.buffer.readline N = int(eval(input())) S = eval(input()) ans = 0 for i in range(0, 1000): k = str(i).zfill(3) dic = {0: False, 1: False, 2: False} for t in str(S): if dic[0] is False: if t == k[0]: dic[0] = True else: if dic[1] is False: if t == k[1]: dic[1] = True else: if dic[2] is False: if t == k[2]: dic[2] = True ans += 1 break else: ans += 1 break print(ans)
import sys input = sys.stdin.buffer.readline def canMakeNumber(k, s): k = str(k).zfill(3) dic = {0: False, 1: False, 2: False} for t in s: if dic[0] is False: if t == k[0]: dic[0] = True else: if dic[1] is False: if t == k[1]: dic[1] = True else: if dic[2] is False: if t == k[2]: dic[2] = True return True else: return True return False N = int(eval(input())) S = eval(input()) ans = 0 for i in range(0, 1000): if canMakeNumber(i, str(S)): ans += 1 print(ans)
28
32
693
736
import sys input = sys.stdin.buffer.readline N = int(eval(input())) S = eval(input()) ans = 0 for i in range(0, 1000): k = str(i).zfill(3) dic = {0: False, 1: False, 2: False} for t in str(S): if dic[0] is False: if t == k[0]: dic[0] = True else: if dic[1] is False: if t == k[1]: dic[1] = True else: if dic[2] is False: if t == k[2]: dic[2] = True ans += 1 break else: ans += 1 break print(ans)
import sys input = sys.stdin.buffer.readline def canMakeNumber(k, s): k = str(k).zfill(3) dic = {0: False, 1: False, 2: False} for t in s: if dic[0] is False: if t == k[0]: dic[0] = True else: if dic[1] is False: if t == k[1]: dic[1] = True else: if dic[2] is False: if t == k[2]: dic[2] = True return True else: return True return False N = int(eval(input())) S = eval(input()) ans = 0 for i in range(0, 1000): if canMakeNumber(i, str(S)): ans += 1 print(ans)
false
12.5
[ "-N = int(eval(input()))", "-S = eval(input())", "-ans = 0", "-for i in range(0, 1000):", "- k = str(i).zfill(3)", "+", "+", "+def canMakeNumber(k, s):", "+ k = str(k).zfill(3)", "- for t in str(S):", "+ for t in s:", "- ans += 1", "- break", "+ return True", "- ans += 1", "- break", "+ return True", "+ return False", "+", "+", "+N = int(eval(input()))", "+S = eval(input())", "+ans = 0", "+for i in range(0, 1000):", "+ if canMakeNumber(i, str(S)):", "+ ans += 1" ]
false
0.096629
0.045596
2.119249
[ "s699314650", "s894454601" ]
u814781830
p03111
python
s715820752
s386584774
392
300
56,412
46,812
Accepted
Accepted
23.47
from itertools import product N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10 ** 9 t1 = set([0,1,2,3]) t2= set([1,2,3]) def calc(t): t3 = set(t) if not (t3 == t1 or t3 == t2): return INF a, b, c = 0, 0, 0 cnt = 0 for i, v in enumerate(t): if v != 0: cnt += 1 if v == 1: a += l[i] elif v == 2: b += l[i] elif v == 3: c += l[i] return abs(a-A) + abs(b-B) + abs(c-C) + (cnt-3) * 10 ans = 10 ** 9 # 4進数の配列を生成する # 0:未使用,1:aに使用,2:bに使用,3:cに使用 for p in product(list(range(4)), repeat=N): ans = min(ans, calc(p)) print(ans)
from itertools import product N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10 ** 9 ans = INF def calc(a, b, c): la, lb, lc = len(a), len(b), len(c) if la + lb + lc < 3 or 0 in (la, lb, lc): return INF sa, sb, sc = sum(a), sum(b), sum(c) t = 0 return abs(sa-A) + abs(sb-B) + abs(sc-C) + (la+lb+lc-3) * 10 def dfs(n, a, b, c): global ans if n == N: ans = min(ans, calc(a, b, c)) return dfs(n+1, a, b, c) dfs(n+1, a+[l[n]], b, c) dfs(n+1, a, b+[l[n]], c) dfs(n+1, a, b, c+[l[n]]) dfs(0, [], [], []) print(ans)
26
25
634
631
from itertools import product N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10**9 t1 = set([0, 1, 2, 3]) t2 = set([1, 2, 3]) def calc(t): t3 = set(t) if not (t3 == t1 or t3 == t2): return INF a, b, c = 0, 0, 0 cnt = 0 for i, v in enumerate(t): if v != 0: cnt += 1 if v == 1: a += l[i] elif v == 2: b += l[i] elif v == 3: c += l[i] return abs(a - A) + abs(b - B) + abs(c - C) + (cnt - 3) * 10 ans = 10**9 # 4進数の配列を生成する # 0:未使用,1:aに使用,2:bに使用,3:cに使用 for p in product(list(range(4)), repeat=N): ans = min(ans, calc(p)) print(ans)
from itertools import product N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10**9 ans = INF def calc(a, b, c): la, lb, lc = len(a), len(b), len(c) if la + lb + lc < 3 or 0 in (la, lb, lc): return INF sa, sb, sc = sum(a), sum(b), sum(c) t = 0 return abs(sa - A) + abs(sb - B) + abs(sc - C) + (la + lb + lc - 3) * 10 def dfs(n, a, b, c): global ans if n == N: ans = min(ans, calc(a, b, c)) return dfs(n + 1, a, b, c) dfs(n + 1, a + [l[n]], b, c) dfs(n + 1, a, b + [l[n]], c) dfs(n + 1, a, b, c + [l[n]]) dfs(0, [], [], []) print(ans)
false
3.846154
[ "-t1 = set([0, 1, 2, 3])", "-t2 = set([1, 2, 3])", "+ans = INF", "-def calc(t):", "- t3 = set(t)", "- if not (t3 == t1 or t3 == t2):", "+def calc(a, b, c):", "+ la, lb, lc = len(a), len(b), len(c)", "+ if la + lb + lc < 3 or 0 in (la, lb, lc):", "- a, b, c = 0, 0, 0", "- cnt = 0", "- for i, v in enumerate(t):", "- if v != 0:", "- cnt += 1", "- if v == 1:", "- a += l[i]", "- elif v == 2:", "- b += l[i]", "- elif v == 3:", "- c += l[i]", "- return abs(a - A) + abs(b - B) + abs(c - C) + (cnt - 3) * 10", "+ sa, sb, sc = sum(a), sum(b), sum(c)", "+ t = 0", "+ return abs(sa - A) + abs(sb - B) + abs(sc - C) + (la + lb + lc - 3) * 10", "-ans = 10**9", "-# 4進数の配列を生成する", "-# 0:未使用,1:aに使用,2:bに使用,3:cに使用", "-for p in product(list(range(4)), repeat=N):", "- ans = min(ans, calc(p))", "+def dfs(n, a, b, c):", "+ global ans", "+ if n == N:", "+ ans = min(ans, calc(a, b, c))", "+ return", "+ dfs(n + 1, a, b, c)", "+ dfs(n + 1, a + [l[n]], b, c)", "+ dfs(n + 1, a, b + [l[n]], c)", "+ dfs(n + 1, a, b, c + [l[n]])", "+", "+", "+dfs(0, [], [], [])" ]
false
0.118982
0.195473
0.608686
[ "s715820752", "s386584774" ]
u574922408
p03014
python
s760477867
s124415159
1,998
1,705
493,736
430,120
Accepted
Accepted
14.66
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): H, W = MI() room = [["" for j in range(W)] for i in range(H)] roomT = [["" for i in range(H)] for j in range(W)] num_yoko = [[0 for j in range(W)] for i in range(H)] num_tate = [[0 for j in range(W)] for i in range(H)] num_sum = [[0 for j in range(W)] for i in range(H)] for i in range(H): row = eval(input()) splited = list(map(len, row.split('#'))) tmp = 0 for j in range(W): roomT[j][i] = row[j] room[i][j] = row[j] if row[j] == "#": num_yoko[i][j] = 0 tmp += 1 else: num_yoko[i][j] = splited[tmp] ans = 0 for j in range(W): target = roomT[j] splited = list(map(len, "".join(target).split('#'))) tmp = 0 for i in range(H): if target[i] == "#": num_tate[i][j] == 0 tmp += 1 else: num_tate[i][j] = splited[tmp] num_sum[i][j] = num_tate[i][j] + num_yoko[i][j] - 1 ans = max(ans, num_sum[i][j]) print(ans) main()
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): H, W = MI() room = [["" for j in range(W)] for i in range(H)] roomT = [["" for i in range(H)] for j in range(W)] num_yoko = [[0 for j in range(W)] for i in range(H)] for i in range(H): row = eval(input()) splited = list(map(len, row.split('#'))) tmp = 0 for j in range(W): roomT[j][i] = row[j] room[i][j] = row[j] if row[j] == "#": num_yoko[i][j] = 0 tmp += 1 else: num_yoko[i][j] = splited[tmp] ans = 0 for j in range(W): target = roomT[j] splited = list(map(len, "".join(target).split('#'))) tmp = 0 for i in range(H): num_tate = 0 if target[i] == "#" else splited[tmp] ans = max(ans, num_tate + num_yoko[i][j] - 1) if target[i] == "#": tmp += 1 print(ans) main()
54
48
1,401
1,197
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): H, W = MI() room = [["" for j in range(W)] for i in range(H)] roomT = [["" for i in range(H)] for j in range(W)] num_yoko = [[0 for j in range(W)] for i in range(H)] num_tate = [[0 for j in range(W)] for i in range(H)] num_sum = [[0 for j in range(W)] for i in range(H)] for i in range(H): row = eval(input()) splited = list(map(len, row.split("#"))) tmp = 0 for j in range(W): roomT[j][i] = row[j] room[i][j] = row[j] if row[j] == "#": num_yoko[i][j] = 0 tmp += 1 else: num_yoko[i][j] = splited[tmp] ans = 0 for j in range(W): target = roomT[j] splited = list(map(len, "".join(target).split("#"))) tmp = 0 for i in range(H): if target[i] == "#": num_tate[i][j] == 0 tmp += 1 else: num_tate[i][j] = splited[tmp] num_sum[i][j] = num_tate[i][j] + num_yoko[i][j] - 1 ans = max(ans, num_sum[i][j]) print(ans) main()
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): H, W = MI() room = [["" for j in range(W)] for i in range(H)] roomT = [["" for i in range(H)] for j in range(W)] num_yoko = [[0 for j in range(W)] for i in range(H)] for i in range(H): row = eval(input()) splited = list(map(len, row.split("#"))) tmp = 0 for j in range(W): roomT[j][i] = row[j] room[i][j] = row[j] if row[j] == "#": num_yoko[i][j] = 0 tmp += 1 else: num_yoko[i][j] = splited[tmp] ans = 0 for j in range(W): target = roomT[j] splited = list(map(len, "".join(target).split("#"))) tmp = 0 for i in range(H): num_tate = 0 if target[i] == "#" else splited[tmp] ans = max(ans, num_tate + num_yoko[i][j] - 1) if target[i] == "#": tmp += 1 print(ans) main()
false
11.111111
[ "- num_tate = [[0 for j in range(W)] for i in range(H)]", "- num_sum = [[0 for j in range(W)] for i in range(H)]", "+ num_tate = 0 if target[i] == \"#\" else splited[tmp]", "+ ans = max(ans, num_tate + num_yoko[i][j] - 1)", "- num_tate[i][j] == 0", "- else:", "- num_tate[i][j] = splited[tmp]", "- num_sum[i][j] = num_tate[i][j] + num_yoko[i][j] - 1", "- ans = max(ans, num_sum[i][j])" ]
false
0.198536
0.036738
5.404097
[ "s760477867", "s124415159" ]
u930705402
p02834
python
s417567523
s317550144
1,032
928
98,348
97,840
Accepted
Accepted
10.08
import sys sys.setrecursionlimit(10**7) def dfs(v,p,d): dist[v]=d for nv in G[v]: if nv==p: continue dfs(nv,v,d+1) def getSP(v): p=v if dist[v]==lim: return p for nv in G[v]: if dist[nv]<dist[v]: p=getSP(nv) return p def depth(v,p,d): sdist[v]=d for nv in G[v]: if dist[nv]<dist[v]: continue depth(nv,v,d+1) N,u,v=list(map(int,input().split())) u,v=u-1,v-1 G=[[] for i in range(N)] for i in range(N-1): a,b=[int(x)-1 for x in input().split()] G[a].append(b) G[b].append(a) dist=[-1]*N dfs(v,-1,0) lim=dist[u]-(dist[u]-1)//2 SP=getSP(u) sdist=[-1]*N depth(SP,-1,0) D,tmp=-1,-1 for i in range(N): if sdist[i]>tmp: D=i tmp=sdist[i] print((dist[D]-1))
import sys sys.setrecursionlimit(10**7) def dfs(v,p,d): dist[v]=d for nv in G[v]: if nv==p: continue dfs(nv,v,d+1) def getSP(v): p=v if dist[v]==lim: return p for nv in G[v]: if dist[nv]<dist[v]: p=getSP(nv) return p def depth(v,p,d): global maxd maxd=max(maxd,dist[v]) for nv in G[v]: if dist[nv]<dist[v]: continue depth(nv,v,d+1) N,u,v=list(map(int,input().split()));u,v=u-1,v-1 G=[[] for i in range(N)] for i in range(N-1): a,b=[int(x)-1 for x in input().split()] G[a].append(b) G[b].append(a) dist=[-1]*N dfs(v,-1,0) lim=dist[u]-(dist[u]-1)//2 SP=getSP(u) maxd=-1 depth(SP,-1,0) print((maxd-1))
43
45
838
799
import sys sys.setrecursionlimit(10**7) def dfs(v, p, d): dist[v] = d for nv in G[v]: if nv == p: continue dfs(nv, v, d + 1) def getSP(v): p = v if dist[v] == lim: return p for nv in G[v]: if dist[nv] < dist[v]: p = getSP(nv) return p def depth(v, p, d): sdist[v] = d for nv in G[v]: if dist[nv] < dist[v]: continue depth(nv, v, d + 1) N, u, v = list(map(int, input().split())) u, v = u - 1, v - 1 G = [[] for i in range(N)] for i in range(N - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G[b].append(a) dist = [-1] * N dfs(v, -1, 0) lim = dist[u] - (dist[u] - 1) // 2 SP = getSP(u) sdist = [-1] * N depth(SP, -1, 0) D, tmp = -1, -1 for i in range(N): if sdist[i] > tmp: D = i tmp = sdist[i] print((dist[D] - 1))
import sys sys.setrecursionlimit(10**7) def dfs(v, p, d): dist[v] = d for nv in G[v]: if nv == p: continue dfs(nv, v, d + 1) def getSP(v): p = v if dist[v] == lim: return p for nv in G[v]: if dist[nv] < dist[v]: p = getSP(nv) return p def depth(v, p, d): global maxd maxd = max(maxd, dist[v]) for nv in G[v]: if dist[nv] < dist[v]: continue depth(nv, v, d + 1) N, u, v = list(map(int, input().split())) u, v = u - 1, v - 1 G = [[] for i in range(N)] for i in range(N - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G[b].append(a) dist = [-1] * N dfs(v, -1, 0) lim = dist[u] - (dist[u] - 1) // 2 SP = getSP(u) maxd = -1 depth(SP, -1, 0) print((maxd - 1))
false
4.444444
[ "- sdist[v] = d", "+ global maxd", "+ maxd = max(maxd, dist[v])", "-sdist = [-1] * N", "+maxd = -1", "-D, tmp = -1, -1", "-for i in range(N):", "- if sdist[i] > tmp:", "- D = i", "- tmp = sdist[i]", "-print((dist[D] - 1))", "+print((maxd - 1))" ]
false
0.036626
0.037761
0.969948
[ "s417567523", "s317550144" ]
u146816547
p02389
python
s810333827
s657581452
20
10
4,184
6,412
Accepted
Accepted
50
a, b=list(map(int,input().split())) print(a*b, 2*a+2*b)
a, b = list(map(int, input().split())) print(a*b, 2*(a+b))
2
2
53
56
a, b = list(map(int, input().split())) print(a * b, 2 * a + 2 * b)
a, b = list(map(int, input().split())) print(a * b, 2 * (a + b))
false
0
[ "-print(a * b, 2 * a + 2 * b)", "+print(a * b, 2 * (a + b))" ]
false
0.044542
0.047749
0.932832
[ "s810333827", "s657581452" ]
u119982001
p02725
python
s884768218
s621792295
166
134
26,444
26,420
Accepted
Accepted
19.28
N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 maxi = 0 for i in range(1, len(A)): ans += abs(A[i]-A[i-1]) if maxi < abs(A[i]-A[i-1]): maxi = abs(A[i]-A[i-1]) if A[0]==0: if maxi < N-A[-1]: maxi = N-A[-1] ans += N-A[-1] else : if maxi < N-A[-1]+A[0]: maxi = N-A[-1]+A[0] ans += N-A[-1]+A[0] print((ans-maxi))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.append(A[0]+N) l = 0 for i in range(1, K+1): l = max(l,A[i]-A[i-1]) print((N-l))
18
9
390
163
N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 maxi = 0 for i in range(1, len(A)): ans += abs(A[i] - A[i - 1]) if maxi < abs(A[i] - A[i - 1]): maxi = abs(A[i] - A[i - 1]) if A[0] == 0: if maxi < N - A[-1]: maxi = N - A[-1] ans += N - A[-1] else: if maxi < N - A[-1] + A[0]: maxi = N - A[-1] + A[0] ans += N - A[-1] + A[0] print((ans - maxi))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.append(A[0] + N) l = 0 for i in range(1, K + 1): l = max(l, A[i] - A[i - 1]) print((N - l))
false
50
[ "-ans = 0", "-maxi = 0", "-for i in range(1, len(A)):", "- ans += abs(A[i] - A[i - 1])", "- if maxi < abs(A[i] - A[i - 1]):", "- maxi = abs(A[i] - A[i - 1])", "-if A[0] == 0:", "- if maxi < N - A[-1]:", "- maxi = N - A[-1]", "- ans += N - A[-1]", "-else:", "- if maxi < N - A[-1] + A[0]:", "- maxi = N - A[-1] + A[0]", "- ans += N - A[-1] + A[0]", "-print((ans - maxi))", "+A.append(A[0] + N)", "+l = 0", "+for i in range(1, K + 1):", "+ l = max(l, A[i] - A[i - 1])", "+print((N - l))" ]
false
0.05302
0.038232
1.386771
[ "s884768218", "s621792295" ]
u562935282
p02937
python
s225772524
s909301724
154
106
7,668
7,628
Accepted
Accepted
31.17
from bisect import bisect_left import sys input = sys.stdin.readline s = input().strip() n = len(s) t = input().strip() d = [[] for _ in range(26)] base = ord('a') for i, c in enumerate(s): idx = ord(c) - base d[idx].append(i) string_count = 0 cur = -1 for tt in t: cur += 1 idx = ord(tt) - base pos_lst = d[idx] lst_len = len(pos_lst) if not lst_len: print((-1)) exit() pos = bisect_left(pos_lst, cur) # cur以降で文字ttが見つかる位置 if lst_len == pos: string_count += 1 cur = pos_lst[0] else: cur = pos_lst[pos] # print(cur, pos_lst, lst_len, string_count * n) print((string_count * n + cur + 1))
def main(): from bisect import bisect_left S = eval(input()) T = eval(input()) L = len(S) pos = tuple(list() for _ in range(26)) orda = ord('a') for i, c in enumerate(S): j = ord(c) - orda pos[j].append(i) rep = 0 curr = 0 for c in T: j = ord(c) - orda if not pos[j]: print((-1)) return i = bisect_left(pos[j], curr) if i == len(pos[j]): rep += 1 i = 0 # pos[j][0]文字目がc curr = pos[j][i] + 1 # pos[j][i]にしたら同じ文字が続くケースでWA print((rep * L + curr)) if __name__ == '__main__': main()
36
34
710
658
from bisect import bisect_left import sys input = sys.stdin.readline s = input().strip() n = len(s) t = input().strip() d = [[] for _ in range(26)] base = ord("a") for i, c in enumerate(s): idx = ord(c) - base d[idx].append(i) string_count = 0 cur = -1 for tt in t: cur += 1 idx = ord(tt) - base pos_lst = d[idx] lst_len = len(pos_lst) if not lst_len: print((-1)) exit() pos = bisect_left(pos_lst, cur) # cur以降で文字ttが見つかる位置 if lst_len == pos: string_count += 1 cur = pos_lst[0] else: cur = pos_lst[pos] # print(cur, pos_lst, lst_len, string_count * n) print((string_count * n + cur + 1))
def main(): from bisect import bisect_left S = eval(input()) T = eval(input()) L = len(S) pos = tuple(list() for _ in range(26)) orda = ord("a") for i, c in enumerate(S): j = ord(c) - orda pos[j].append(i) rep = 0 curr = 0 for c in T: j = ord(c) - orda if not pos[j]: print((-1)) return i = bisect_left(pos[j], curr) if i == len(pos[j]): rep += 1 i = 0 # pos[j][0]文字目がc curr = pos[j][i] + 1 # pos[j][i]にしたら同じ文字が続くケースでWA print((rep * L + curr)) if __name__ == "__main__": main()
false
5.555556
[ "-from bisect import bisect_left", "-import sys", "+def main():", "+ from bisect import bisect_left", "-input = sys.stdin.readline", "-s = input().strip()", "-n = len(s)", "-t = input().strip()", "-d = [[] for _ in range(26)]", "-base = ord(\"a\")", "-for i, c in enumerate(s):", "- idx = ord(c) - base", "- d[idx].append(i)", "-string_count = 0", "-cur = -1", "-for tt in t:", "- cur += 1", "- idx = ord(tt) - base", "- pos_lst = d[idx]", "- lst_len = len(pos_lst)", "- if not lst_len:", "- print((-1))", "- exit()", "- pos = bisect_left(pos_lst, cur) # cur以降で文字ttが見つかる位置", "- if lst_len == pos:", "- string_count += 1", "- cur = pos_lst[0]", "- else:", "- cur = pos_lst[pos]", "- # print(cur, pos_lst, lst_len, string_count * n)", "-print((string_count * n + cur + 1))", "+ S = eval(input())", "+ T = eval(input())", "+ L = len(S)", "+ pos = tuple(list() for _ in range(26))", "+ orda = ord(\"a\")", "+ for i, c in enumerate(S):", "+ j = ord(c) - orda", "+ pos[j].append(i)", "+ rep = 0", "+ curr = 0", "+ for c in T:", "+ j = ord(c) - orda", "+ if not pos[j]:", "+ print((-1))", "+ return", "+ i = bisect_left(pos[j], curr)", "+ if i == len(pos[j]):", "+ rep += 1", "+ i = 0 # pos[j][0]文字目がc", "+ curr = pos[j][i] + 1 # pos[j][i]にしたら同じ文字が続くケースでWA", "+ print((rep * L + curr))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.038521
0.03892
0.989738
[ "s225772524", "s909301724" ]
u126478680
p02343
python
s741267130
s390190303
6,570
920
9,684
6,048
Accepted
Accepted
86
#! python3 # disjoint_set_union_find_tree.py n, q = [int(x) for x in input().split(' ')] sets = [set([i]) for i in range(n)] def unite(Sx, Sy): return Sx | Sy def search(x): global sets flag = False for i in range(len(sets)): if x in sets[i]: flag = True break if flag: return i else: return None def same(x, y): global sets flag = 0 for set in sets: if x in set: if y in set: flag = 1 break return flag for i in range(q): query, x, y = input().split(' ') x, y = int(x), int(y) if query == '0': # unite i_x = search(x) i_y = search(y) if i_x != None and i_y != None and i_x != i_y: sets[i_x] = unite(sets[i_x], sets[i_y]) del sets[i_y] elif query == '1': # same print((same(x, y)))
#! python3 # disjoint_set_union_find_tree.py class UnionFindTree(): def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.find(self.par[x]) def unite(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same_check(self, x, y): return self.find(x) == self.find(y) n, q = [int(x) for x in input().split(' ')] uft = UnionFindTree(n-1) for i in range(q): com, x, y = [int(x) for x in input().split(' ')] if com == 0: uft.unite(x, y) elif com == 1: if uft.same_check(x, y): print((1)) else: print((0))
45
41
955
1,027
#! python3 # disjoint_set_union_find_tree.py n, q = [int(x) for x in input().split(" ")] sets = [set([i]) for i in range(n)] def unite(Sx, Sy): return Sx | Sy def search(x): global sets flag = False for i in range(len(sets)): if x in sets[i]: flag = True break if flag: return i else: return None def same(x, y): global sets flag = 0 for set in sets: if x in set: if y in set: flag = 1 break return flag for i in range(q): query, x, y = input().split(" ") x, y = int(x), int(y) if query == "0": # unite i_x = search(x) i_y = search(y) if i_x != None and i_y != None and i_x != i_y: sets[i_x] = unite(sets[i_x], sets[i_y]) del sets[i_y] elif query == "1": # same print((same(x, y)))
#! python3 # disjoint_set_union_find_tree.py class UnionFindTree: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.find(self.par[x]) def unite(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same_check(self, x, y): return self.find(x) == self.find(y) n, q = [int(x) for x in input().split(" ")] uft = UnionFindTree(n - 1) for i in range(q): com, x, y = [int(x) for x in input().split(" ")] if com == 0: uft.unite(x, y) elif com == 1: if uft.same_check(x, y): print((1)) else: print((0))
false
8.888889
[ "-n, q = [int(x) for x in input().split(\" \")]", "-sets = [set([i]) for i in range(n)]", "+class UnionFindTree:", "+ def __init__(self, n):", "+ self.par = [i for i in range(n + 1)]", "+ self.rank = [0] * (n + 1)", "+", "+ def find(self, x):", "+ if self.par[x] == x:", "+ return x", "+ else:", "+ self.par[x] = self.find(self.par[x])", "+ return self.find(self.par[x])", "+", "+ def unite(self, x, y):", "+ x = self.find(x)", "+ y = self.find(y)", "+ if self.rank[x] < self.rank[y]:", "+ self.par[x] = y", "+ else:", "+ self.par[y] = x", "+ if self.rank[x] == self.rank[y]:", "+ self.rank[x] += 1", "+", "+ def same_check(self, x, y):", "+ return self.find(x) == self.find(y)", "-def unite(Sx, Sy):", "- return Sx | Sy", "-", "-", "-def search(x):", "- global sets", "- flag = False", "- for i in range(len(sets)):", "- if x in sets[i]:", "- flag = True", "- break", "- if flag:", "- return i", "- else:", "- return None", "-", "-", "-def same(x, y):", "- global sets", "- flag = 0", "- for set in sets:", "- if x in set:", "- if y in set:", "- flag = 1", "- break", "- return flag", "-", "-", "+n, q = [int(x) for x in input().split(\" \")]", "+uft = UnionFindTree(n - 1)", "- query, x, y = input().split(\" \")", "- x, y = int(x), int(y)", "- if query == \"0\":", "- # unite", "- i_x = search(x)", "- i_y = search(y)", "- if i_x != None and i_y != None and i_x != i_y:", "- sets[i_x] = unite(sets[i_x], sets[i_y])", "- del sets[i_y]", "- elif query == \"1\":", "- # same", "- print((same(x, y)))", "+ com, x, y = [int(x) for x in input().split(\" \")]", "+ if com == 0:", "+ uft.unite(x, y)", "+ elif com == 1:", "+ if uft.same_check(x, y):", "+ print((1))", "+ else:", "+ print((0))" ]
false
0.036259
0.04208
0.861666
[ "s741267130", "s390190303" ]
u241159583
p03087
python
s775504253
s173046640
863
596
6,132
30,340
Accepted
Accepted
30.94
N, Q = list(map(int, input().split())) S = eval(input()) ans = [0] * N for i in range(N-1): if S[i] == "A" and S[i+1] == "C": ans[i+1] += (ans[i] + 1) else: ans[i+1] = ans[i] for _ in range(Q): l, r = list(map(int, input().split())) print((ans[r-1] - ans[l-1]))
from bisect import bisect_left, bisect_right n,q = list(map(int, input().split())) s = eval(input()) lr = [list(map(int, input().split())) for _ in range(q)] numbers = [] for i in range(n-1): if s[i]+s[i+1] == "AC": numbers.append(i+1) for l,r in lr: x,y = bisect_left(numbers, l), bisect_right(numbers, r) if x==y: print((0)) elif numbers[y-1]+1 <= r:print((y-x)) else: print((y-x-1))
13
14
287
409
N, Q = list(map(int, input().split())) S = eval(input()) ans = [0] * N for i in range(N - 1): if S[i] == "A" and S[i + 1] == "C": ans[i + 1] += ans[i] + 1 else: ans[i + 1] = ans[i] for _ in range(Q): l, r = list(map(int, input().split())) print((ans[r - 1] - ans[l - 1]))
from bisect import bisect_left, bisect_right n, q = list(map(int, input().split())) s = eval(input()) lr = [list(map(int, input().split())) for _ in range(q)] numbers = [] for i in range(n - 1): if s[i] + s[i + 1] == "AC": numbers.append(i + 1) for l, r in lr: x, y = bisect_left(numbers, l), bisect_right(numbers, r) if x == y: print((0)) elif numbers[y - 1] + 1 <= r: print((y - x)) else: print((y - x - 1))
false
7.142857
[ "-N, Q = list(map(int, input().split()))", "-S = eval(input())", "-ans = [0] * N", "-for i in range(N - 1):", "- if S[i] == \"A\" and S[i + 1] == \"C\":", "- ans[i + 1] += ans[i] + 1", "+from bisect import bisect_left, bisect_right", "+", "+n, q = list(map(int, input().split()))", "+s = eval(input())", "+lr = [list(map(int, input().split())) for _ in range(q)]", "+numbers = []", "+for i in range(n - 1):", "+ if s[i] + s[i + 1] == \"AC\":", "+ numbers.append(i + 1)", "+for l, r in lr:", "+ x, y = bisect_left(numbers, l), bisect_right(numbers, r)", "+ if x == y:", "+ print((0))", "+ elif numbers[y - 1] + 1 <= r:", "+ print((y - x))", "- ans[i + 1] = ans[i]", "-for _ in range(Q):", "- l, r = list(map(int, input().split()))", "- print((ans[r - 1] - ans[l - 1]))", "+ print((y - x - 1))" ]
false
0.036962
0.039117
0.944911
[ "s775504253", "s173046640" ]
u609061751
p03033
python
s460026560
s254876951
1,805
1,499
111,836
129,784
Accepted
Accepted
16.95
def main(): import sys input = lambda : sys.stdin.readline().rstrip() n, q = list(map(int, input().split())) stx = [] for _ in range(n): s, t, x = list(map(int, input().split())) stx.append([x, s - x, t - x]) stx.sort(reverse=True) d = [int(eval(input())) for _ in range(q)] N = q N0 = 2**(N-1).bit_length() data = [None]*(2*N0) INF = (-1, 10**9 + 1) def update(l, r, v): L = l + N0; R = r + N0 while L < R: if R & 1: R -= 1 data[R-1] = v if L & 1: data[L-1] = v L += 1 L >>= 1; R >>= 1 def _query(k): k += N0-1 s = INF while k >= 0: if data[k]: s = max(s, data[k]) k = (k - 1) // 2 return s def query(k): return _query(k)[1] import bisect for i, (x, start, last) in enumerate(stx): l = bisect.bisect_left(d, start) r = bisect.bisect_left(d, last) update(l, r, (i, x)) for i in range(q): res = query(i) if res == 10**9 + 1: print((-1)) else: print(res) if __name__ == '__main__': main()
import sys input = lambda : sys.stdin.readline().rstrip() def segfun(x, y): return min(x, y) ide_ele = float("inf") class SegmentTree: def __init__(self, n, ele, segfun): self.ide_ele = ele self.segfun = segfun self.n = n self.N0 = 1 << n.bit_length() self.data = [self.ide_ele] * (self.N0 * 2) def update(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] = self.segfun(self.data[l], val) l += 1 if r & 1: self.data[r - 1] = self.segfun(self.data[r - 1], val) r -= 1 l //= 2 r //= 2 def query(self, i): i += len(self.data) // 2 ret = self.data[i] while i > 0: i //= 2 ret = self.segfun(ret, self.data[i]) return ret n, q = list(map(int, input().split())) stx = [] for _ in range(n): s, t, x = list(map(int, input().split())) stx.append([x, s - x, t - x]) # stx.sort(reverse=True) d = [int(eval(input())) for _ in range(q)] import bisect seg = SegmentTree(q, ide_ele, segfun) for x, start, last in stx: l = bisect.bisect_left(d, start) r = bisect.bisect_left(d, last) seg.update(l, r, x) for i, j in enumerate(d): res = seg.query(i) if res == float("inf"): print((-1)) else: print(res)
57
63
1,293
1,472
def main(): import sys input = lambda: sys.stdin.readline().rstrip() n, q = list(map(int, input().split())) stx = [] for _ in range(n): s, t, x = list(map(int, input().split())) stx.append([x, s - x, t - x]) stx.sort(reverse=True) d = [int(eval(input())) for _ in range(q)] N = q N0 = 2 ** (N - 1).bit_length() data = [None] * (2 * N0) INF = (-1, 10**9 + 1) def update(l, r, v): L = l + N0 R = r + N0 while L < R: if R & 1: R -= 1 data[R - 1] = v if L & 1: data[L - 1] = v L += 1 L >>= 1 R >>= 1 def _query(k): k += N0 - 1 s = INF while k >= 0: if data[k]: s = max(s, data[k]) k = (k - 1) // 2 return s def query(k): return _query(k)[1] import bisect for i, (x, start, last) in enumerate(stx): l = bisect.bisect_left(d, start) r = bisect.bisect_left(d, last) update(l, r, (i, x)) for i in range(q): res = query(i) if res == 10**9 + 1: print((-1)) else: print(res) if __name__ == "__main__": main()
import sys input = lambda: sys.stdin.readline().rstrip() def segfun(x, y): return min(x, y) ide_ele = float("inf") class SegmentTree: def __init__(self, n, ele, segfun): self.ide_ele = ele self.segfun = segfun self.n = n self.N0 = 1 << n.bit_length() self.data = [self.ide_ele] * (self.N0 * 2) def update(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] = self.segfun(self.data[l], val) l += 1 if r & 1: self.data[r - 1] = self.segfun(self.data[r - 1], val) r -= 1 l //= 2 r //= 2 def query(self, i): i += len(self.data) // 2 ret = self.data[i] while i > 0: i //= 2 ret = self.segfun(ret, self.data[i]) return ret n, q = list(map(int, input().split())) stx = [] for _ in range(n): s, t, x = list(map(int, input().split())) stx.append([x, s - x, t - x]) # stx.sort(reverse=True) d = [int(eval(input())) for _ in range(q)] import bisect seg = SegmentTree(q, ide_ele, segfun) for x, start, last in stx: l = bisect.bisect_left(d, start) r = bisect.bisect_left(d, last) seg.update(l, r, x) for i, j in enumerate(d): res = seg.query(i) if res == float("inf"): print((-1)) else: print(res)
false
9.52381
[ "-def main():", "- import sys", "+import sys", "- input = lambda: sys.stdin.readline().rstrip()", "- n, q = list(map(int, input().split()))", "- stx = []", "- for _ in range(n):", "- s, t, x = list(map(int, input().split()))", "- stx.append([x, s - x, t - x])", "- stx.sort(reverse=True)", "- d = [int(eval(input())) for _ in range(q)]", "- N = q", "- N0 = 2 ** (N - 1).bit_length()", "- data = [None] * (2 * N0)", "- INF = (-1, 10**9 + 1)", "-", "- def update(l, r, v):", "- L = l + N0", "- R = r + N0", "- while L < R:", "- if R & 1:", "- R -= 1", "- data[R - 1] = v", "- if L & 1:", "- data[L - 1] = v", "- L += 1", "- L >>= 1", "- R >>= 1", "-", "- def _query(k):", "- k += N0 - 1", "- s = INF", "- while k >= 0:", "- if data[k]:", "- s = max(s, data[k])", "- k = (k - 1) // 2", "- return s", "-", "- def query(k):", "- return _query(k)[1]", "-", "- import bisect", "-", "- for i, (x, start, last) in enumerate(stx):", "- l = bisect.bisect_left(d, start)", "- r = bisect.bisect_left(d, last)", "- update(l, r, (i, x))", "- for i in range(q):", "- res = query(i)", "- if res == 10**9 + 1:", "- print((-1))", "- else:", "- print(res)", "+input = lambda: sys.stdin.readline().rstrip()", "-if __name__ == \"__main__\":", "- main()", "+def segfun(x, y):", "+ return min(x, y)", "+", "+", "+ide_ele = float(\"inf\")", "+", "+", "+class SegmentTree:", "+ def __init__(self, n, ele, segfun):", "+ self.ide_ele = ele", "+ self.segfun = segfun", "+ self.n = n", "+ self.N0 = 1 << n.bit_length()", "+ self.data = [self.ide_ele] * (self.N0 * 2)", "+", "+ def update(self, l, r, val):", "+ l += self.N0", "+ r += self.N0", "+ while l < r:", "+ if l & 1:", "+ self.data[l] = self.segfun(self.data[l], val)", "+ l += 1", "+ if r & 1:", "+ self.data[r - 1] = self.segfun(self.data[r - 1], val)", "+ r -= 1", "+ l //= 2", "+ r //= 2", "+", "+ def query(self, i):", "+ i += len(self.data) // 2", "+ ret = self.data[i]", "+ while i > 0:", "+ i //= 2", "+ ret = self.segfun(ret, self.data[i])", "+ return ret", "+", "+", "+n, q = list(map(int, input().split()))", "+stx = []", "+for _ in range(n):", "+ s, t, x = list(map(int, input().split()))", "+ stx.append([x, s - x, t - x])", "+# stx.sort(reverse=True)", "+d = [int(eval(input())) for _ in range(q)]", "+import bisect", "+", "+seg = SegmentTree(q, ide_ele, segfun)", "+for x, start, last in stx:", "+ l = bisect.bisect_left(d, start)", "+ r = bisect.bisect_left(d, last)", "+ seg.update(l, r, x)", "+for i, j in enumerate(d):", "+ res = seg.query(i)", "+ if res == float(\"inf\"):", "+ print((-1))", "+ else:", "+ print(res)" ]
false
0.039972
0.050664
0.788951
[ "s460026560", "s254876951" ]
u391731808
p03816
python
s744857256
s763532626
99
76
18,272
17,396
Accepted
Accepted
23.23
N=int(eval(input())) *A,=list(map(int,input().split())) cnt = {} for a in A: cnt[a] = cnt.get(a,0)+1 keys = sorted(cnt.keys()) i = 0 j = len(keys)-1 while i <= j: ki,kj = keys[i],keys[j] if cnt[ki]<=1: i+=1 continue if cnt[kj]<=1: j-=1 continue cnt[ki] -= 1 cnt[kj] -= 1 print((sum(cnt.values())))
N = int(eval(input())) *A, = list(map(int,input().split())) c = {} for a in A:c[a] = c.get(a,0)+1 print((len(c) - sum(v-1 for v in list(c.values()))%2))
19
5
357
136
N = int(eval(input())) (*A,) = list(map(int, input().split())) cnt = {} for a in A: cnt[a] = cnt.get(a, 0) + 1 keys = sorted(cnt.keys()) i = 0 j = len(keys) - 1 while i <= j: ki, kj = keys[i], keys[j] if cnt[ki] <= 1: i += 1 continue if cnt[kj] <= 1: j -= 1 continue cnt[ki] -= 1 cnt[kj] -= 1 print((sum(cnt.values())))
N = int(eval(input())) (*A,) = list(map(int, input().split())) c = {} for a in A: c[a] = c.get(a, 0) + 1 print((len(c) - sum(v - 1 for v in list(c.values())) % 2))
false
73.684211
[ "-cnt = {}", "+c = {}", "- cnt[a] = cnt.get(a, 0) + 1", "-keys = sorted(cnt.keys())", "-i = 0", "-j = len(keys) - 1", "-while i <= j:", "- ki, kj = keys[i], keys[j]", "- if cnt[ki] <= 1:", "- i += 1", "- continue", "- if cnt[kj] <= 1:", "- j -= 1", "- continue", "- cnt[ki] -= 1", "- cnt[kj] -= 1", "-print((sum(cnt.values())))", "+ c[a] = c.get(a, 0) + 1", "+print((len(c) - sum(v - 1 for v in list(c.values())) % 2))" ]
false
0.081741
0.079513
1.028015
[ "s744857256", "s763532626" ]
u695079172
p02699
python
s766096074
s623962291
24
21
9,152
9,136
Accepted
Accepted
12.5
def main(): s,w = list(map(int,input().split())) if s <= w: print("unsafe") else: print("safe") if __name__ == '__main__': main()
def main(): s,w = list(map(int,input().split())) answer = "unsafe" if w >= s else "safe" print(answer) if __name__ == '__main__': main()
10
6
167
152
def main(): s, w = list(map(int, input().split())) if s <= w: print("unsafe") else: print("safe") if __name__ == "__main__": main()
def main(): s, w = list(map(int, input().split())) answer = "unsafe" if w >= s else "safe" print(answer) if __name__ == "__main__": main()
false
40
[ "- if s <= w:", "- print(\"unsafe\")", "- else:", "- print(\"safe\")", "+ answer = \"unsafe\" if w >= s else \"safe\"", "+ print(answer)" ]
false
0.15191
0.046091
3.295879
[ "s766096074", "s623962291" ]
u716530146
p02833
python
s170882464
s506275319
21
17
3,440
2,940
Accepted
Accepted
19.05
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 minans = inf ;ans = 0 ;count = 0 ;pro = 1 n=int(eval(input())) if n%2==1: print((0)) exit() k=10 for i in range(1,100): count+=n//(k) k*=5 print(count)
count=0 k=5 n=int(eval(input())) if n%2==1: print((0)) else: n//=2 for i in range(1,100): count+=int(n//(k)) k*=5 print(count)
17
11
353
161
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") inf = float("inf") mod = 10**9 + 7 minans = inf ans = 0 count = 0 pro = 1 n = int(eval(input())) if n % 2 == 1: print((0)) exit() k = 10 for i in range(1, 100): count += n // (k) k *= 5 print(count)
count = 0 k = 5 n = int(eval(input())) if n % 2 == 1: print((0)) else: n //= 2 for i in range(1, 100): count += int(n // (k)) k *= 5 print(count)
false
35.294118
[ "-#!/usr/bin/env python3", "-import sys, math, itertools, collections, bisect", "-", "-input = lambda: sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "-inf = float(\"inf\")", "-mod = 10**9 + 7", "-minans = inf", "-ans = 0", "-pro = 1", "+k = 5", "- exit()", "-k = 10", "-for i in range(1, 100):", "- count += n // (k)", "- k *= 5", "-print(count)", "+else:", "+ n //= 2", "+ for i in range(1, 100):", "+ count += int(n // (k))", "+ k *= 5", "+ print(count)" ]
false
0.040439
0.040228
1.005245
[ "s170882464", "s506275319" ]
u653807637
p02995
python
s374884391
s409008636
38
35
5,048
5,048
Accepted
Accepted
7.89
from fractions import gcd from decimal import * a, b, c, d = list(map(Decimal, input().split())) e = c * d / gcd(c, d) print((int(b - a + 1 - ((b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e)))))
from fractions import gcd a, b, c, d = list(map(int, input().split())) e = c * d // gcd(c, d) print((int(b - a + 1 - ((b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e)))))
6
4
224
196
from fractions import gcd from decimal import * a, b, c, d = list(map(Decimal, input().split())) e = c * d / gcd(c, d) print( ( int( b - a + 1 - ( (b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e) ) ) ) )
from fractions import gcd a, b, c, d = list(map(int, input().split())) e = c * d // gcd(c, d) print( ( int( b - a + 1 - ( (b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e) ) ) ) )
false
33.333333
[ "-from decimal import *", "-a, b, c, d = list(map(Decimal, input().split()))", "-e = c * d / gcd(c, d)", "+a, b, c, d = list(map(int, input().split()))", "+e = c * d // gcd(c, d)" ]
false
0.131695
0.047952
2.74637
[ "s374884391", "s409008636" ]
u450339194
p03064
python
s796422989
s675296992
2,032
1,012
224,024
223,224
Accepted
Accepted
50.2
import numpy as np mod = 998244353 N = int(eval(input())) a = np.array([int(eval(input())) for i in range(N)]) sum_a = np.sum(a) dp = np.zeros((N+1, sum_a+1)) dp[0,0] = 1 for i in range(1, N+1): a_i = a[i-1] dp[i,a_i:] += dp[i-1,:-a_i] dp[i,:] += dp[i-1,:] * 2 dp[i,:] %= mod exc = np.sum(dp[N, (sum_a+1)//2:]) % mod res = 3**N % mod - exc * 3 if sum_a % 2 == 0: dp = np.zeros((N+1, sum_a+1)) dp[0,0] = 1 for i in range(1, N+1): a_i = a[i-1] dp[i,a_i:] += dp[i-1,:-a_i] dp[i,:] += dp[i-1,:] dp[i,:] %= mod res += dp[N, sum_a//2] * 3 print((int(res % mod)))
import numpy as np mod = 998244353 N = int(eval(input())) a = np.array([int(eval(input())) for i in range(N)]) sum_a = np.sum(a) dp = np.zeros((N+1, sum_a+1), dtype=np.int64) dp[0,0] = 1 for i in range(1, N+1): a_i = a[i-1] dp[i,a_i:] += dp[i-1,:-a_i] dp[i,:] += dp[i-1,:] * 2 dp[i,:] %= mod exc = np.sum(dp[N, (sum_a+1)//2:]) % mod res = 3**N % mod - exc * 3 if sum_a % 2 == 0: dp = np.zeros((N+1, sum_a+1), dtype=np.int64) dp[0,0] = 1 for i in range(1, N+1): a_i = a[i-1] dp[i,a_i:] += dp[i-1,:-a_i] dp[i,:] += dp[i-1,:] dp[i,:] %= mod res += dp[N, sum_a//2] * 3 print((res % mod))
29
29
639
666
import numpy as np mod = 998244353 N = int(eval(input())) a = np.array([int(eval(input())) for i in range(N)]) sum_a = np.sum(a) dp = np.zeros((N + 1, sum_a + 1)) dp[0, 0] = 1 for i in range(1, N + 1): a_i = a[i - 1] dp[i, a_i:] += dp[i - 1, :-a_i] dp[i, :] += dp[i - 1, :] * 2 dp[i, :] %= mod exc = np.sum(dp[N, (sum_a + 1) // 2 :]) % mod res = 3**N % mod - exc * 3 if sum_a % 2 == 0: dp = np.zeros((N + 1, sum_a + 1)) dp[0, 0] = 1 for i in range(1, N + 1): a_i = a[i - 1] dp[i, a_i:] += dp[i - 1, :-a_i] dp[i, :] += dp[i - 1, :] dp[i, :] %= mod res += dp[N, sum_a // 2] * 3 print((int(res % mod)))
import numpy as np mod = 998244353 N = int(eval(input())) a = np.array([int(eval(input())) for i in range(N)]) sum_a = np.sum(a) dp = np.zeros((N + 1, sum_a + 1), dtype=np.int64) dp[0, 0] = 1 for i in range(1, N + 1): a_i = a[i - 1] dp[i, a_i:] += dp[i - 1, :-a_i] dp[i, :] += dp[i - 1, :] * 2 dp[i, :] %= mod exc = np.sum(dp[N, (sum_a + 1) // 2 :]) % mod res = 3**N % mod - exc * 3 if sum_a % 2 == 0: dp = np.zeros((N + 1, sum_a + 1), dtype=np.int64) dp[0, 0] = 1 for i in range(1, N + 1): a_i = a[i - 1] dp[i, a_i:] += dp[i - 1, :-a_i] dp[i, :] += dp[i - 1, :] dp[i, :] %= mod res += dp[N, sum_a // 2] * 3 print((res % mod))
false
0
[ "-dp = np.zeros((N + 1, sum_a + 1))", "+dp = np.zeros((N + 1, sum_a + 1), dtype=np.int64)", "- dp = np.zeros((N + 1, sum_a + 1))", "+ dp = np.zeros((N + 1, sum_a + 1), dtype=np.int64)", "-print((int(res % mod)))", "+print((res % mod))" ]
false
0.399687
0.257472
1.552351
[ "s796422989", "s675296992" ]
u410118019
p02959
python
s553682249
s743019636
128
102
18,624
18,476
Accepted
Accepted
20.31
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = 0 for i in range(n): if a[i] >= b[i]: c += b[i] else: d = b[i] -a[i] if a[i+1] <= d: c += a[i] + a[i+1] a[i+1] = 0 else: a[i+1] -= d c += b[i] print(c)
def main(): n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = 0 for i in range(n): if a[i] >= b[i]: c += b[i] else: d = b[i] -a[i] if a[i+1] <= d: c += a[i] + a[i+1] a[i+1] = 0 else: a[i+1] -= d c += b[i] print(c) if __name__ == '__main__': main()
16
20
301
386
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = 0 for i in range(n): if a[i] >= b[i]: c += b[i] else: d = b[i] - a[i] if a[i + 1] <= d: c += a[i] + a[i + 1] a[i + 1] = 0 else: a[i + 1] -= d c += b[i] print(c)
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = 0 for i in range(n): if a[i] >= b[i]: c += b[i] else: d = b[i] - a[i] if a[i + 1] <= d: c += a[i] + a[i + 1] a[i + 1] = 0 else: a[i + 1] -= d c += b[i] print(c) if __name__ == "__main__": main()
false
20
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-c = 0", "-for i in range(n):", "- if a[i] >= b[i]:", "- c += b[i]", "- else:", "- d = b[i] - a[i]", "- if a[i + 1] <= d:", "- c += a[i] + a[i + 1]", "- a[i + 1] = 0", "+def main():", "+ n = int(eval(input()))", "+ a = list(map(int, input().split()))", "+ b = list(map(int, input().split()))", "+ c = 0", "+ for i in range(n):", "+ if a[i] >= b[i]:", "+ c += b[i]", "- a[i + 1] -= d", "- c += b[i]", "-print(c)", "+ d = b[i] - a[i]", "+ if a[i + 1] <= d:", "+ c += a[i] + a[i + 1]", "+ a[i + 1] = 0", "+ else:", "+ a[i + 1] -= d", "+ c += b[i]", "+ print(c)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045439
0.045186
1.005591
[ "s553682249", "s743019636" ]
u941644149
p02773
python
s157113708
s442792926
659
594
32,988
35,944
Accepted
Accepted
9.86
N = int(eval(input())) Dic = {} for n in range(N): S = eval(input()) if S in list(Dic.keys()): Dic[S] = Dic[S] + 1 else: Dic[S] = 1 max_val = max(Dic.values()) max_k_list = [kv[0] for kv in list(Dic.items()) if kv[1] == max_val] max_k_list = sorted(max_k_list) for t in max_k_list: print(t)
from collections import Counter N = int(input()) #L = [input() for _ in range(N)] L = [] for n in range(N): S = input() L.append(S) Dic = Counter(L) max_value = max(Dic.values()) max_k_list = [i for i, j in Dic.items() if j == max_value] max_k_list = sorted(max_k_list) print(*max_k_list , sep="\n")
14
13
312
320
N = int(eval(input())) Dic = {} for n in range(N): S = eval(input()) if S in list(Dic.keys()): Dic[S] = Dic[S] + 1 else: Dic[S] = 1 max_val = max(Dic.values()) max_k_list = [kv[0] for kv in list(Dic.items()) if kv[1] == max_val] max_k_list = sorted(max_k_list) for t in max_k_list: print(t)
from collections import Counter N = int(input()) # L = [input() for _ in range(N)] L = [] for n in range(N): S = input() L.append(S) Dic = Counter(L) max_value = max(Dic.values()) max_k_list = [i for i, j in Dic.items() if j == max_value] max_k_list = sorted(max_k_list) print(*max_k_list, sep="\n")
false
7.142857
[ "-N = int(eval(input()))", "-Dic = {}", "+from collections import Counter", "+", "+N = int(input())", "+# L = [input() for _ in range(N)]", "+L = []", "- S = eval(input())", "- if S in list(Dic.keys()):", "- Dic[S] = Dic[S] + 1", "- else:", "- Dic[S] = 1", "-max_val = max(Dic.values())", "-max_k_list = [kv[0] for kv in list(Dic.items()) if kv[1] == max_val]", "+ S = input()", "+ L.append(S)", "+Dic = Counter(L)", "+max_value = max(Dic.values())", "+max_k_list = [i for i, j in Dic.items() if j == max_value]", "-for t in max_k_list:", "- print(t)", "+print(*max_k_list, sep=\"\\n\")" ]
false
0.047743
0.04837
0.987039
[ "s157113708", "s442792926" ]
u802627598
p03030
python
s776749782
s803927140
24
22
3,444
3,444
Accepted
Accepted
8.33
import copy n = int(eval(input())) l = [input().split() for i in range(n)] index = copy.deepcopy(l) for i in range(n): l[i][1] = int(l[i][1]) index[i][1] = int(index[i][1]) l.sort(key=lambda x: x[1], reverse=True) l.sort(key=lambda x: x[0], reverse=False) for i in range(n): for j in range(n): if l[i] == index[j]: print((j+1)) break
import copy res_list = [] n = int(eval(input())) for i in range(n): name, score = input().split() score = int(score) res_list.append([name,score,i+1]) res_list.sort(key=lambda x: x[1],reverse=True) res_list.sort(key=lambda x: x[0],reverse=False) for i in res_list: print((i[2]))
18
16
391
307
import copy n = int(eval(input())) l = [input().split() for i in range(n)] index = copy.deepcopy(l) for i in range(n): l[i][1] = int(l[i][1]) index[i][1] = int(index[i][1]) l.sort(key=lambda x: x[1], reverse=True) l.sort(key=lambda x: x[0], reverse=False) for i in range(n): for j in range(n): if l[i] == index[j]: print((j + 1)) break
import copy res_list = [] n = int(eval(input())) for i in range(n): name, score = input().split() score = int(score) res_list.append([name, score, i + 1]) res_list.sort(key=lambda x: x[1], reverse=True) res_list.sort(key=lambda x: x[0], reverse=False) for i in res_list: print((i[2]))
false
11.111111
[ "+res_list = []", "-l = [input().split() for i in range(n)]", "-index = copy.deepcopy(l)", "- l[i][1] = int(l[i][1])", "- index[i][1] = int(index[i][1])", "-l.sort(key=lambda x: x[1], reverse=True)", "-l.sort(key=lambda x: x[0], reverse=False)", "-for i in range(n):", "- for j in range(n):", "- if l[i] == index[j]:", "- print((j + 1))", "- break", "+ name, score = input().split()", "+ score = int(score)", "+ res_list.append([name, score, i + 1])", "+res_list.sort(key=lambda x: x[1], reverse=True)", "+res_list.sort(key=lambda x: x[0], reverse=False)", "+for i in res_list:", "+ print((i[2]))" ]
false
0.060369
0.03743
1.612861
[ "s776749782", "s803927140" ]
u562935282
p04000
python
s782434608
s559646211
1,965
1,162
166,548
104,816
Accepted
Accepted
40.87
h, w, n = list(map(int, input().split())) c = dict() for _ in range(n): a, b = list(map(int, input().split())) for da in -1, 0, 1: for db in -1, 0, 1: if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1): c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1 #print(c) ans_cnt = [0 for _ in range(10)] for cnt in list(c.values()): ans_cnt[cnt] += 1 ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum((1 for cnt in list(c.values()) if cnt > 0)) for i in range(10): print((ans_cnt[i]))
def main(): from collections import defaultdict import sys input = sys.stdin.readline H, W, N = map(int, input().split()) g = defaultdict(int) for _ in range(N): a, b = (int(x) - 1 for x in input().split()) for i in range(3): if a - i < 0: continue if a - i + 3 > H: continue for j in range(3): if b - j < 0: continue if b - j + 3 > W: continue g[(a - i) * W + (b - j)] += 1 # (a,b)を塗ったとき影響される3x3マス目の左上の座標に加算する ctr = [0] * 10 tot = (H - 2) * (W - 2) for cnt in g.values(): ctr[cnt] += 1 tot -= 1 ctr[0] = tot print(*ctr, sep='\n') if __name__ == '__main__': main()
19
31
536
781
h, w, n = list(map(int, input().split())) c = dict() for _ in range(n): a, b = list(map(int, input().split())) for da in -1, 0, 1: for db in -1, 0, 1: if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1): c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1 # print(c) ans_cnt = [0 for _ in range(10)] for cnt in list(c.values()): ans_cnt[cnt] += 1 ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum( (1 for cnt in list(c.values()) if cnt > 0) ) for i in range(10): print((ans_cnt[i]))
def main(): from collections import defaultdict import sys input = sys.stdin.readline H, W, N = map(int, input().split()) g = defaultdict(int) for _ in range(N): a, b = (int(x) - 1 for x in input().split()) for i in range(3): if a - i < 0: continue if a - i + 3 > H: continue for j in range(3): if b - j < 0: continue if b - j + 3 > W: continue g[(a - i) * W + (b - j)] += 1 # (a,b)を塗ったとき影響される3x3マス目の左上の座標に加算する ctr = [0] * 10 tot = (H - 2) * (W - 2) for cnt in g.values(): ctr[cnt] += 1 tot -= 1 ctr[0] = tot print(*ctr, sep="\n") if __name__ == "__main__": main()
false
38.709677
[ "-h, w, n = list(map(int, input().split()))", "-c = dict()", "-for _ in range(n):", "- a, b = list(map(int, input().split()))", "- for da in -1, 0, 1:", "- for db in -1, 0, 1:", "- if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1):", "- c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1", "-# print(c)", "-ans_cnt = [0 for _ in range(10)]", "-for cnt in list(c.values()):", "- ans_cnt[cnt] += 1", "-ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum(", "- (1 for cnt in list(c.values()) if cnt > 0)", "-)", "-for i in range(10):", "- print((ans_cnt[i]))", "+def main():", "+ from collections import defaultdict", "+ import sys", "+", "+ input = sys.stdin.readline", "+ H, W, N = map(int, input().split())", "+ g = defaultdict(int)", "+ for _ in range(N):", "+ a, b = (int(x) - 1 for x in input().split())", "+ for i in range(3):", "+ if a - i < 0:", "+ continue", "+ if a - i + 3 > H:", "+ continue", "+ for j in range(3):", "+ if b - j < 0:", "+ continue", "+ if b - j + 3 > W:", "+ continue", "+ g[(a - i) * W + (b - j)] += 1", "+ # (a,b)を塗ったとき影響される3x3マス目の左上の座標に加算する", "+ ctr = [0] * 10", "+ tot = (H - 2) * (W - 2)", "+ for cnt in g.values():", "+ ctr[cnt] += 1", "+ tot -= 1", "+ ctr[0] = tot", "+ print(*ctr, sep=\"\\n\")", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.043677
0.040362
1.082127
[ "s782434608", "s559646211" ]
u968166680
p03476
python
s544628735
s713011955
148
122
29,000
29,000
Accepted
Accepted
17.57
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n ** 0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10 ** 5) A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10 ** 5 + 1)] A = tuple(accumulate(A)) Q, *LR = map(int, open(0).read().split()) ans = [] for l, r in zip(*[iter(LR)] * 2): ans.append(A[r] - A[l - 1]) print(*ans, sep='\n') return if __name__ == '__main__': main()
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n ** 0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10 ** 5) A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10 ** 5 + 1)] A = tuple(accumulate(A)) Q, *LR = list(map(int, open(0).read().split())) ans = [] for l, r in zip(*[iter(LR)] * 2): ans.append(A[r] - A[l - 1]) print(('\n'.join(map(str, ans)))) return if __name__ == '__main__': main()
39
39
915
925
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n**0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * ( ((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1 ) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10**5) A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10**5 + 1)] A = tuple(accumulate(A)) Q, *LR = map(int, open(0).read().split()) ans = [] for l, r in zip(*[iter(LR)] * 2): ans.append(A[r] - A[l - 1]) print(*ans, sep="\n") return if __name__ == "__main__": main()
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def prime_numbers(n): if n < 2: return [] m = (n + 1) // 2 p = [1] * m for i in range(1, int((n**0.5 - 1) / 2) + 1): if p[i]: p[2 * i * (i + 1) :: 2 * i + 1] = [0] * ( ((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1 ) return {2} | {2 * i + 1 for i in range(1, m) if p[i]} def main(): primes = prime_numbers(10**5) A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10**5 + 1)] A = tuple(accumulate(A)) Q, *LR = list(map(int, open(0).read().split())) ans = [] for l, r in zip(*[iter(LR)] * 2): ans.append(A[r] - A[l - 1]) print(("\n".join(map(str, ans)))) return if __name__ == "__main__": main()
false
0
[ "- Q, *LR = map(int, open(0).read().split())", "+ Q, *LR = list(map(int, open(0).read().split()))", "- print(*ans, sep=\"\\n\")", "+ print((\"\\n\".join(map(str, ans))))" ]
false
0.062424
0.066847
0.933839
[ "s544628735", "s713011955" ]
u103539599
p03545
python
s885705234
s470335726
19
17
3,188
3,064
Accepted
Accepted
10.53
S=eval(input()) T=[0]*4 for i in range(4): T[i]=int(S[i]) if T[0]+T[1]+T[2]+T[3]==7: print((S[0]+"+"+S[1]+"+"+S[2]+"+"+S[3]+"=7")) elif T[0]+T[1]+T[2]-T[3]==7: print((S[0]+"+"+S[1]+"+"+S[2]+"-"+S[3]+"=7")) elif T[0]+T[1]-T[2]-T[3]==7: print((S[0]+"+"+S[1]+"-"+S[2]+"-"+S[3]+"=7")) elif T[0]+T[1]-T[2]+T[3]==7: print((S[0]+"+"+S[1]+"-"+S[2]+"+"+S[3]+"=7")) elif T[0]-T[1]-T[2]-T[3]==7: print((S[0]+"-"+S[1]+"-"+S[2]+"-"+S[3]+"=7")) elif T[0]-T[1]-T[2]+T[3]==7: print((S[0]+"-"+S[1]+"-"+S[2]+"+"+S[3]+"=7")) elif T[0]-T[1]+T[2]+T[3]==7: print((S[0]+"-"+S[1]+"+"+S[2]+"+"+S[3]+"=7")) elif T[0]-T[1]+T[2]-T[3]==7: print((S[0]+"-"+S[1]+"+"+S[2]+"-"+S[3]+"=7"))
S = eval(input()) A = int(S[0]) B = int(S[1]) C = int(S[2]) D = int(S[3]) if A+B+C+D == 7: print(("{0}+{1}+{2}+{3}=7".format(A,B,C,D))) elif A-B+C+D == 7: print(("{0}-{1}+{2}+{3}=7".format(A,B,C,D))) elif A-B-C+D == 7: print(("{0}-{1}-{2}+{3}=7".format(A,B,C,D))) elif A-B-C-D == 7: print(("{0}-{1}-{2}-{3}=7".format(A,B,C,D))) elif A+B-C+D == 7: print(("{0}+{1}-{2}+{3}=7".format(A,B,C,D))) elif A+B+C-D == 7: print(("{0}+{1}+{2}-{3}=7".format(A,B,C,D))) elif A+B-C-D == 7: print(("{0}+{1}-{2}-{3}=7".format(A,B,C,D))) elif A-B+C-D == 7: print(("{0}-{1}+{2}-{3}=7".format(A,B,C,D)))
13
14
651
575
S = eval(input()) T = [0] * 4 for i in range(4): T[i] = int(S[i]) if T[0] + T[1] + T[2] + T[3] == 7: print((S[0] + "+" + S[1] + "+" + S[2] + "+" + S[3] + "=7")) elif T[0] + T[1] + T[2] - T[3] == 7: print((S[0] + "+" + S[1] + "+" + S[2] + "-" + S[3] + "=7")) elif T[0] + T[1] - T[2] - T[3] == 7: print((S[0] + "+" + S[1] + "-" + S[2] + "-" + S[3] + "=7")) elif T[0] + T[1] - T[2] + T[3] == 7: print((S[0] + "+" + S[1] + "-" + S[2] + "+" + S[3] + "=7")) elif T[0] - T[1] - T[2] - T[3] == 7: print((S[0] + "-" + S[1] + "-" + S[2] + "-" + S[3] + "=7")) elif T[0] - T[1] - T[2] + T[3] == 7: print((S[0] + "-" + S[1] + "-" + S[2] + "+" + S[3] + "=7")) elif T[0] - T[1] + T[2] + T[3] == 7: print((S[0] + "-" + S[1] + "+" + S[2] + "+" + S[3] + "=7")) elif T[0] - T[1] + T[2] - T[3] == 7: print((S[0] + "-" + S[1] + "+" + S[2] + "-" + S[3] + "=7"))
S = eval(input()) A = int(S[0]) B = int(S[1]) C = int(S[2]) D = int(S[3]) if A + B + C + D == 7: print(("{0}+{1}+{2}+{3}=7".format(A, B, C, D))) elif A - B + C + D == 7: print(("{0}-{1}+{2}+{3}=7".format(A, B, C, D))) elif A - B - C + D == 7: print(("{0}-{1}-{2}+{3}=7".format(A, B, C, D))) elif A - B - C - D == 7: print(("{0}-{1}-{2}-{3}=7".format(A, B, C, D))) elif A + B - C + D == 7: print(("{0}+{1}-{2}+{3}=7".format(A, B, C, D))) elif A + B + C - D == 7: print(("{0}+{1}+{2}-{3}=7".format(A, B, C, D))) elif A + B - C - D == 7: print(("{0}+{1}-{2}-{3}=7".format(A, B, C, D))) elif A - B + C - D == 7: print(("{0}-{1}+{2}-{3}=7".format(A, B, C, D)))
false
7.142857
[ "-T = [0] * 4", "-for i in range(4):", "- T[i] = int(S[i])", "-if T[0] + T[1] + T[2] + T[3] == 7:", "- print((S[0] + \"+\" + S[1] + \"+\" + S[2] + \"+\" + S[3] + \"=7\"))", "-elif T[0] + T[1] + T[2] - T[3] == 7:", "- print((S[0] + \"+\" + S[1] + \"+\" + S[2] + \"-\" + S[3] + \"=7\"))", "-elif T[0] + T[1] - T[2] - T[3] == 7:", "- print((S[0] + \"+\" + S[1] + \"-\" + S[2] + \"-\" + S[3] + \"=7\"))", "-elif T[0] + T[1] - T[2] + T[3] == 7:", "- print((S[0] + \"+\" + S[1] + \"-\" + S[2] + \"+\" + S[3] + \"=7\"))", "-elif T[0] - T[1] - T[2] - T[3] == 7:", "- print((S[0] + \"-\" + S[1] + \"-\" + S[2] + \"-\" + S[3] + \"=7\"))", "-elif T[0] - T[1] - T[2] + T[3] == 7:", "- print((S[0] + \"-\" + S[1] + \"-\" + S[2] + \"+\" + S[3] + \"=7\"))", "-elif T[0] - T[1] + T[2] + T[3] == 7:", "- print((S[0] + \"-\" + S[1] + \"+\" + S[2] + \"+\" + S[3] + \"=7\"))", "-elif T[0] - T[1] + T[2] - T[3] == 7:", "- print((S[0] + \"-\" + S[1] + \"+\" + S[2] + \"-\" + S[3] + \"=7\"))", "+A = int(S[0])", "+B = int(S[1])", "+C = int(S[2])", "+D = int(S[3])", "+if A + B + C + D == 7:", "+ print((\"{0}+{1}+{2}+{3}=7\".format(A, B, C, D)))", "+elif A - B + C + D == 7:", "+ print((\"{0}-{1}+{2}+{3}=7\".format(A, B, C, D)))", "+elif A - B - C + D == 7:", "+ print((\"{0}-{1}-{2}+{3}=7\".format(A, B, C, D)))", "+elif A - B - C - D == 7:", "+ print((\"{0}-{1}-{2}-{3}=7\".format(A, B, C, D)))", "+elif A + B - C + D == 7:", "+ print((\"{0}+{1}-{2}+{3}=7\".format(A, B, C, D)))", "+elif A + B + C - D == 7:", "+ print((\"{0}+{1}+{2}-{3}=7\".format(A, B, C, D)))", "+elif A + B - C - D == 7:", "+ print((\"{0}+{1}-{2}-{3}=7\".format(A, B, C, D)))", "+elif A - B + C - D == 7:", "+ print((\"{0}-{1}+{2}-{3}=7\".format(A, B, C, D)))" ]
false
0.057458
0.06871
0.836234
[ "s885705234", "s470335726" ]
u451017206
p03078
python
s252116596
s057598169
773
45
4,324
6,000
Accepted
Accepted
94.18
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in h: heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in h: heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k))) if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in h: heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1))) for a in ans: print((-a))
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] e = set() for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in e: heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) e.add((-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in e: heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k))) e.add((-(A[i] + B[j+1] + C[k]), (i, j+1, k))) if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in e: heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1))) e.add((-(A[i] + B[j] + C[k+1]), (i, j, k+1))) for a in ans: print((-a))
23
27
905
1,083
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if ( i + 1 < X and j < Y and k < Z and not (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)) in h ): heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k))) if ( i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)) in h ): heapq.heappush(h, (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k))) if ( i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)) in h ): heapq.heappush(h, (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1))) for a in ans: print((-a))
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] e = set() for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if ( i + 1 < X and j < Y and k < Z and not (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)) in e ): heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k))) e.add((-(A[i + 1] + B[j] + C[k]), (i + 1, j, k))) if ( i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)) in e ): heapq.heappush(h, (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k))) e.add((-(A[i] + B[j + 1] + C[k]), (i, j + 1, k))) if ( i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)) in e ): heapq.heappush(h, (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1))) e.add((-(A[i] + B[j] + C[k + 1]), (i, j, k + 1))) for a in ans: print((-a))
false
14.814815
[ "+e = set()", "- and not (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)) in h", "+ and not (-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)) in e", "+ e.add((-(A[i + 1] + B[j] + C[k]), (i + 1, j, k)))", "- and not (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)) in h", "+ and not (-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)) in e", "+ e.add((-(A[i] + B[j + 1] + C[k]), (i, j + 1, k)))", "- and not (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)) in h", "+ and not (-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)) in e", "+ e.add((-(A[i] + B[j] + C[k + 1]), (i, j, k + 1)))" ]
false
0.065128
0.037381
1.742288
[ "s252116596", "s057598169" ]
u462329577
p02765
python
s069229840
s821565636
163
17
38,256
2,940
Accepted
Accepted
89.57
#!/usr/bin/env python3 k,n = list(map(int,input().split())) if k >= 10: print(n) else: print((n+100*(10-k)))
#!/usr/bin/env python3 n,r = list(map(int,input().split())) print((r+100*max(0,10-n)))
6
3
113
80
#!/usr/bin/env python3 k, n = list(map(int, input().split())) if k >= 10: print(n) else: print((n + 100 * (10 - k)))
#!/usr/bin/env python3 n, r = list(map(int, input().split())) print((r + 100 * max(0, 10 - n)))
false
50
[ "-k, n = list(map(int, input().split()))", "-if k >= 10:", "- print(n)", "-else:", "- print((n + 100 * (10 - k)))", "+n, r = list(map(int, input().split()))", "+print((r + 100 * max(0, 10 - n)))" ]
false
0.120371
0.03659
3.289739
[ "s069229840", "s821565636" ]
u829859091
p02888
python
s218510131
s432477187
1,701
1,309
3,188
3,316
Accepted
Accepted
23.05
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() res = 0 for i in range(N): for j in range(i+1, N): idx = bisect_left(L, L[i]+L[j]) res += max(0,idx-(j+1)) print(res)
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() res = 0 for i in range(N-2): for j in range(i+1, N-1): idx = bisect_left(L, L[i]+L[j]) res += idx-(j+1) print(res)
10
13
239
242
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() res = 0 for i in range(N): for j in range(i + 1, N): idx = bisect_left(L, L[i] + L[j]) res += max(0, idx - (j + 1)) print(res)
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() res = 0 for i in range(N - 2): for j in range(i + 1, N - 1): idx = bisect_left(L, L[i] + L[j]) res += idx - (j + 1) print(res)
false
23.076923
[ "-for i in range(N):", "- for j in range(i + 1, N):", "+for i in range(N - 2):", "+ for j in range(i + 1, N - 1):", "- res += max(0, idx - (j + 1))", "+ res += idx - (j + 1)" ]
false
0.044639
0.085521
0.52196
[ "s218510131", "s432477187" ]
u718436793
p02899
python
s794597148
s369188702
174
126
20,704
25,068
Accepted
Accepted
27.59
[print(i,end=' ')for i in{m:i+1for i,m in zip(range(int(input())),list(map(int,input().split())))}.values()]
print((*[i for i inlist({m:i+1for i,m in zip(list(range(int(eval(input())))),list(map(int,input().split())))}.values())]))
1
1
108
96
[ print(i, end=" ") for i in { m: i + 1 for i, m in zip(range(int(input())), list(map(int, input().split()))) }.values() ]
print((*[i for i inlist({m:i+1for i,m in zip(list(range(int(eval(input())))),list(map(int,input().split())))}.values())]))
false
0
[ "-[", "- print(i, end=\" \")", "- for i in {", "- m: i + 1 for i, m in zip(range(int(input())), list(map(int, input().split())))", "- }.values()", "-]", "+print((*[i for i inlist({m:i+1for i,m in zip(list(range(int(eval(input())))),list(map(int,input().split())))}.values())]))" ]
false
0.037662
0.036046
1.04484
[ "s794597148", "s369188702" ]
u133936772
p03721
python
s449065360
s573523078
468
188
28,124
25,116
Accepted
Accepted
59.83
f=lambda:list(map(int,input().split()));n,k=f();c=0 for a,b in sorted(list(f())for _ in[0]*n): c+=b if c>=k:print(a);break
n,k,*l=list(map(int,open(0).read().split()));c=0 for a,b in sorted(zip(l[::2],l[1::2])): c+=b if c>=k:print(a);break
4
4
123
117
f = lambda: list(map(int, input().split())) n, k = f() c = 0 for a, b in sorted(list(f()) for _ in [0] * n): c += b if c >= k: print(a) break
n, k, *l = list(map(int, open(0).read().split())) c = 0 for a, b in sorted(zip(l[::2], l[1::2])): c += b if c >= k: print(a) break
false
0
[ "-f = lambda: list(map(int, input().split()))", "-n, k = f()", "+n, k, *l = list(map(int, open(0).read().split()))", "-for a, b in sorted(list(f()) for _ in [0] * n):", "+for a, b in sorted(zip(l[::2], l[1::2])):" ]
false
0.036503
0.072876
0.500901
[ "s449065360", "s573523078" ]
u887207211
p03487
python
s921672335
s936320231
97
83
17,780
17,784
Accepted
Accepted
14.43
N = int(eval(input())) A = list(map(int,input().split())) d = {} for i in range(N): if(A[i] not in d): d[A[i]] = 1 else: d[A[i]] += 1 cnt = 0 for k, v in list(d.items()): if(k != v): if(k > v): cnt += v else: cnt += v - k print(cnt)
N = int(eval(input())) A = list(map(int,input().split())) d = {} for a in A: if(a in d): d[a] += 1 else: d[a] = 1 cnt = 0 for k, v in list(d.items()): if(k > v): cnt += v elif(k < v): cnt += v - k print(cnt)
17
16
271
235
N = int(eval(input())) A = list(map(int, input().split())) d = {} for i in range(N): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 cnt = 0 for k, v in list(d.items()): if k != v: if k > v: cnt += v else: cnt += v - k print(cnt)
N = int(eval(input())) A = list(map(int, input().split())) d = {} for a in A: if a in d: d[a] += 1 else: d[a] = 1 cnt = 0 for k, v in list(d.items()): if k > v: cnt += v elif k < v: cnt += v - k print(cnt)
false
5.882353
[ "-for i in range(N):", "- if A[i] not in d:", "- d[A[i]] = 1", "+for a in A:", "+ if a in d:", "+ d[a] += 1", "- d[A[i]] += 1", "+ d[a] = 1", "- if k != v:", "- if k > v:", "- cnt += v", "- else:", "- cnt += v - k", "+ if k > v:", "+ cnt += v", "+ elif k < v:", "+ cnt += v - k" ]
false
0.040581
0.037565
1.080288
[ "s921672335", "s936320231" ]
u392319141
p02837
python
s188855189
s615352465
198
116
3,064
3,064
Accepted
Accepted
41.41
N = int(eval(input())) S = [] for _ in range(N): A = int(eval(input())) S.append([tuple(map(int, input().split())) for _ in range(A)]) def sol(state): for i, A in enumerate(S): if (state & (1 << i)) == 0: continue for j, s in A: if ((state & (1 << (j - 1))) != 0) != (s != 0): return 0 return sum(map(int, bin(state)[2:])) ans = 0 for state in range(1 << N): ans = max(ans, sol(state)) print(ans)
N = int(eval(input())) A = [] for _ in range(N): A.append([tuple(map(int, input().split())) for _ in range(int(eval(input())))]) def exists(state): ret = 0 for i in range(N): if ((1 << i) & state) == 0: continue ret += 1 for x, y in A[i]: if ((state & (1 << (x - 1))) > 0) != (y > 0): return 0 return ret ans = 0 for state in range(1 << N): ans = max(ans, exists(state)) print(ans)
20
21
483
477
N = int(eval(input())) S = [] for _ in range(N): A = int(eval(input())) S.append([tuple(map(int, input().split())) for _ in range(A)]) def sol(state): for i, A in enumerate(S): if (state & (1 << i)) == 0: continue for j, s in A: if ((state & (1 << (j - 1))) != 0) != (s != 0): return 0 return sum(map(int, bin(state)[2:])) ans = 0 for state in range(1 << N): ans = max(ans, sol(state)) print(ans)
N = int(eval(input())) A = [] for _ in range(N): A.append([tuple(map(int, input().split())) for _ in range(int(eval(input())))]) def exists(state): ret = 0 for i in range(N): if ((1 << i) & state) == 0: continue ret += 1 for x, y in A[i]: if ((state & (1 << (x - 1))) > 0) != (y > 0): return 0 return ret ans = 0 for state in range(1 << N): ans = max(ans, exists(state)) print(ans)
false
4.761905
[ "-S = []", "+A = []", "- A = int(eval(input()))", "- S.append([tuple(map(int, input().split())) for _ in range(A)])", "+ A.append([tuple(map(int, input().split())) for _ in range(int(eval(input())))])", "-def sol(state):", "- for i, A in enumerate(S):", "- if (state & (1 << i)) == 0:", "+def exists(state):", "+ ret = 0", "+ for i in range(N):", "+ if ((1 << i) & state) == 0:", "- for j, s in A:", "- if ((state & (1 << (j - 1))) != 0) != (s != 0):", "+ ret += 1", "+ for x, y in A[i]:", "+ if ((state & (1 << (x - 1))) > 0) != (y > 0):", "- return sum(map(int, bin(state)[2:]))", "+ return ret", "- ans = max(ans, sol(state))", "+ ans = max(ans, exists(state))" ]
false
0.043704
0.064122
0.681586
[ "s188855189", "s615352465" ]
u948524308
p03062
python
s476288348
s099963556
126
97
14,284
20,000
Accepted
Accepted
23.02
N=int(eval(input())) A=list(map(int,input().split())) cnt=0 S=0 mi=10000000000 C0=False for i in range(N): mi=min(mi,abs(A[i])) if A[i]>0: S+=A[i] elif A[i]==0: C0==True elif A[i]<0: cnt+=1 S+=(-A[i]) if cnt%2==0 or C0==True: print(S) else: print((S-mi*2))
N=int(eval(input())) A=list(map(int,input().split())) mi=10**9+1 S=0 cnt=0 for i in range(N): if A[i]<0: cnt+=1 a=abs(A[i]) S+=a mi=min(mi,a) if cnt%2==0: ans=S else: ans=S-2*mi print(ans)
22
18
329
233
N = int(eval(input())) A = list(map(int, input().split())) cnt = 0 S = 0 mi = 10000000000 C0 = False for i in range(N): mi = min(mi, abs(A[i])) if A[i] > 0: S += A[i] elif A[i] == 0: C0 == True elif A[i] < 0: cnt += 1 S += -A[i] if cnt % 2 == 0 or C0 == True: print(S) else: print((S - mi * 2))
N = int(eval(input())) A = list(map(int, input().split())) mi = 10**9 + 1 S = 0 cnt = 0 for i in range(N): if A[i] < 0: cnt += 1 a = abs(A[i]) S += a mi = min(mi, a) if cnt % 2 == 0: ans = S else: ans = S - 2 * mi print(ans)
false
18.181818
[ "+mi = 10**9 + 1", "+S = 0", "-S = 0", "-mi = 10000000000", "-C0 = False", "- mi = min(mi, abs(A[i]))", "- if A[i] > 0:", "- S += A[i]", "- elif A[i] == 0:", "- C0 == True", "- elif A[i] < 0:", "+ if A[i] < 0:", "- S += -A[i]", "-if cnt % 2 == 0 or C0 == True:", "- print(S)", "+ a = abs(A[i])", "+ S += a", "+ mi = min(mi, a)", "+if cnt % 2 == 0:", "+ ans = S", "- print((S - mi * 2))", "+ ans = S - 2 * mi", "+print(ans)" ]
false
0.073849
0.037439
1.972492
[ "s476288348", "s099963556" ]
u144540235
p02686
python
s493587877
s398311799
1,965
1,426
106,912
42,432
Accepted
Accepted
27.43
def process(tab, first, end): #print(tab) #print(first, end) total = first for i in tab: if (i[1] > total): return ("No") total += i[0] if (total < 0): return ("No") if (total == end): return ("Yes") return ("No") N = int(eval(input())) first = -1 last = -1 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if (j == '('): apres += 1 elif (j == ')'): if (apres > 0): apres -= 1 else: avant += 1 if (avant == 0 and apres > 0 and first == -1): first = apres elif (apres == 0 and avant > 0 and last == -1): last = avant elif (avant > 0 or apres > 0): tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if (first == -1 and clean > 0): first = 0 clean -= 1 if (last == -1 and clean > 0): last = 0 tab = sorted(tab) tab = tab[::-1] if (total == 0 and first > -1 and last > -1): res = process(tab, first, last) else: if (total == 0 and N == 1): res = "Yes" else: res = "No" print(res)
def process(tab, first, end): #print(tab) #print(first, end) total = first for i in tab: if (i[1] > total): return ("No") total += i[0] if (total < 0): return ("No") if (total == end): return ("Yes") return ("No") N = int(eval(input())) first = 0 last = 0 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if (j == '('): apres += 1 elif (j == ')'): if (apres > 0): apres -= 1 else: avant += 1 if (avant == 0 and apres > 0): first += apres elif (apres == 0 and avant > 0): last += avant elif (avant > 0 or apres > 0): tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if (first == -1 and clean > 0): first = 0 clean -= 1 if (last == -1 and clean > 0): last = 0 tab = sorted(tab) tab = tab[::-1] if (total == 0 and first > -1 and last > -1): res = process(tab, first, last) else: if (total == 0 and N == 1): res = "Yes" else: res = "No" print(res)
71
71
1,311
1,280
def process(tab, first, end): # print(tab) # print(first, end) total = first for i in tab: if i[1] > total: return "No" total += i[0] if total < 0: return "No" if total == end: return "Yes" return "No" N = int(eval(input())) first = -1 last = -1 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if j == "(": apres += 1 elif j == ")": if apres > 0: apres -= 1 else: avant += 1 if avant == 0 and apres > 0 and first == -1: first = apres elif apres == 0 and avant > 0 and last == -1: last = avant elif avant > 0 or apres > 0: tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if first == -1 and clean > 0: first = 0 clean -= 1 if last == -1 and clean > 0: last = 0 tab = sorted(tab) tab = tab[::-1] if total == 0 and first > -1 and last > -1: res = process(tab, first, last) else: if total == 0 and N == 1: res = "Yes" else: res = "No" print(res)
def process(tab, first, end): # print(tab) # print(first, end) total = first for i in tab: if i[1] > total: return "No" total += i[0] if total < 0: return "No" if total == end: return "Yes" return "No" N = int(eval(input())) first = 0 last = 0 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if j == "(": apres += 1 elif j == ")": if apres > 0: apres -= 1 else: avant += 1 if avant == 0 and apres > 0: first += apres elif apres == 0 and avant > 0: last += avant elif avant > 0 or apres > 0: tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if first == -1 and clean > 0: first = 0 clean -= 1 if last == -1 and clean > 0: last = 0 tab = sorted(tab) tab = tab[::-1] if total == 0 and first > -1 and last > -1: res = process(tab, first, last) else: if total == 0 and N == 1: res = "Yes" else: res = "No" print(res)
false
0
[ "-first = -1", "-last = -1", "+first = 0", "+last = 0", "- if avant == 0 and apres > 0 and first == -1:", "- first = apres", "- elif apres == 0 and avant > 0 and last == -1:", "- last = avant", "+ if avant == 0 and apres > 0:", "+ first += apres", "+ elif apres == 0 and avant > 0:", "+ last += avant" ]
false
0.037169
0.036929
1.00648
[ "s493587877", "s398311799" ]
u759412327
p03494
python
s186785642
s081586578
166
150
13,328
12,396
Accepted
Accepted
9.64
import numpy as np eval(input()) x = np.array(input().split(),dtype=np.int32) answer = 0 while (x%2==0).all(): x //= 2 answer += 1 print(answer)
import numpy as np N = int(eval(input())) a = np.array(input().split(),dtype=np.int32) z = 0 while (a%2==0).all(): a//=2 z+=1 print(z)
9
10
152
144
import numpy as np eval(input()) x = np.array(input().split(), dtype=np.int32) answer = 0 while (x % 2 == 0).all(): x //= 2 answer += 1 print(answer)
import numpy as np N = int(eval(input())) a = np.array(input().split(), dtype=np.int32) z = 0 while (a % 2 == 0).all(): a //= 2 z += 1 print(z)
false
10
[ "-eval(input())", "-x = np.array(input().split(), dtype=np.int32)", "-answer = 0", "-while (x % 2 == 0).all():", "- x //= 2", "- answer += 1", "-print(answer)", "+N = int(eval(input()))", "+a = np.array(input().split(), dtype=np.int32)", "+z = 0", "+while (a % 2 == 0).all():", "+ a //= 2", "+ z += 1", "+print(z)" ]
false
0.319219
0.848741
0.376108
[ "s186785642", "s081586578" ]
u762420987
p03137
python
s100074263
s955706715
226
108
57,640
13,960
Accepted
Accepted
52.21
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) sbn = [abs(Xlist[i] - Xlist[i + 1]) for i in range(M - 1)] sbn.sort(reverse=True) print((sum(sbn[N - 1:])))
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split())))[::-1] sbn = sorted([abs(Xlist[i] - Xlist[i+1]) for i in range(M-1)])[::-1] if N >= M: print((0)) else: print((sum(sbn[N-1:])))
5
7
190
217
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) sbn = [abs(Xlist[i] - Xlist[i + 1]) for i in range(M - 1)] sbn.sort(reverse=True) print((sum(sbn[N - 1 :])))
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split())))[::-1] sbn = sorted([abs(Xlist[i] - Xlist[i + 1]) for i in range(M - 1)])[::-1] if N >= M: print((0)) else: print((sum(sbn[N - 1 :])))
false
28.571429
[ "-Xlist = sorted(list(map(int, input().split())))", "-sbn = [abs(Xlist[i] - Xlist[i + 1]) for i in range(M - 1)]", "-sbn.sort(reverse=True)", "-print((sum(sbn[N - 1 :])))", "+Xlist = sorted(list(map(int, input().split())))[::-1]", "+sbn = sorted([abs(Xlist[i] - Xlist[i + 1]) for i in range(M - 1)])[::-1]", "+if N >= M:", "+ print((0))", "+else:", "+ print((sum(sbn[N - 1 :])))" ]
false
0.0861
0.085971
1.001509
[ "s100074263", "s955706715" ]
u535907456
p03078
python
s999403423
s900807138
1,779
37
3,700
5,232
Accepted
Accepted
97.92
X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) ABlist = [] ABClist = [] for x in A: for y in B: sumple = x + y ABlist.append(sumple) ABlist.sort(reverse=True) ABlist = ABlist[:K] for x in ABlist: for z in C: test = x + z ABClist.append(test) ABClist.sort(reverse=True) ABClist = ABClist[:K] for x in ABClist: print(x)
import heapq X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] item = (0,(0,0,0)) max_score = A[0] + B[0] + C[0] xyzset = set(item[1]) answer = [] heapq.heappush(heap,item) while len(answer) < K: score,(x,y,z) = heapq.heappop(heap) answer.append(max_score - score) if x != X-1 and (x+1,y,z) not in xyzset: heapq.heappush(heap,(max_score - A[x+1] - B[y] - C[z],(x+1,y,z))) xyzset.add((x+1,y,z)) if y != Y-1 and (x,y+1,z) not in xyzset: heapq.heappush(heap,(max_score - A[x] - B[y+1] - C[z],(x,y+1,z))) xyzset.add((x,y+1,z)) if z != Z-1 and (x,y,z+1) not in xyzset: heapq.heappush(heap,(max_score - A[x] - B[y] - C[z+1],(x,y,z+1))) xyzset.add((x,y,z+1)) for x in answer: print(x)
23
36
495
959
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) ABlist = [] ABClist = [] for x in A: for y in B: sumple = x + y ABlist.append(sumple) ABlist.sort(reverse=True) ABlist = ABlist[:K] for x in ABlist: for z in C: test = x + z ABClist.append(test) ABClist.sort(reverse=True) ABClist = ABClist[:K] for x in ABClist: print(x)
import heapq X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] item = (0, (0, 0, 0)) max_score = A[0] + B[0] + C[0] xyzset = set(item[1]) answer = [] heapq.heappush(heap, item) while len(answer) < K: score, (x, y, z) = heapq.heappop(heap) answer.append(max_score - score) if x != X - 1 and (x + 1, y, z) not in xyzset: heapq.heappush(heap, (max_score - A[x + 1] - B[y] - C[z], (x + 1, y, z))) xyzset.add((x + 1, y, z)) if y != Y - 1 and (x, y + 1, z) not in xyzset: heapq.heappush(heap, (max_score - A[x] - B[y + 1] - C[z], (x, y + 1, z))) xyzset.add((x, y + 1, z)) if z != Z - 1 and (x, y, z + 1) not in xyzset: heapq.heappush(heap, (max_score - A[x] - B[y] - C[z + 1], (x, y, z + 1))) xyzset.add((x, y, z + 1)) for x in answer: print(x)
false
36.111111
[ "+import heapq", "+", "-ABlist = []", "-ABClist = []", "-for x in A:", "- for y in B:", "- sumple = x + y", "- ABlist.append(sumple)", "- ABlist.sort(reverse=True)", "- ABlist = ABlist[:K]", "-for x in ABlist:", "- for z in C:", "- test = x + z", "- ABClist.append(test)", "- ABClist.sort(reverse=True)", "- ABClist = ABClist[:K]", "-for x in ABClist:", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+heap = []", "+item = (0, (0, 0, 0))", "+max_score = A[0] + B[0] + C[0]", "+xyzset = set(item[1])", "+answer = []", "+heapq.heappush(heap, item)", "+while len(answer) < K:", "+ score, (x, y, z) = heapq.heappop(heap)", "+ answer.append(max_score - score)", "+ if x != X - 1 and (x + 1, y, z) not in xyzset:", "+ heapq.heappush(heap, (max_score - A[x + 1] - B[y] - C[z], (x + 1, y, z)))", "+ xyzset.add((x + 1, y, z))", "+ if y != Y - 1 and (x, y + 1, z) not in xyzset:", "+ heapq.heappush(heap, (max_score - A[x] - B[y + 1] - C[z], (x, y + 1, z)))", "+ xyzset.add((x, y + 1, z))", "+ if z != Z - 1 and (x, y, z + 1) not in xyzset:", "+ heapq.heappush(heap, (max_score - A[x] - B[y] - C[z + 1], (x, y, z + 1)))", "+ xyzset.add((x, y, z + 1))", "+for x in answer:" ]
false
0.083489
0.043798
1.906208
[ "s999403423", "s900807138" ]
u678167152
p02768
python
s084827027
s316536800
1,212
606
9,132
9,188
Accepted
Accepted
50
def comb_mod(n,r): mod = 10**9+7 ans = 1 for i in range(r): ans *= n-i ans %= mod for i in range(1,r+1): ans *= pow(i,mod-2,mod) ans %= mod return ans def solve(): n, a, b = list(map(int, input().split())) mod = 10**9+7 ans = pow(2,n,mod)-comb_mod(n,a)-comb_mod(n,b)-1 ans %= mod return ans print((solve()))
def comb_mod(n,r): mod = 10**9+7 ans = 1 for i in range(r): ans *= n-i ans %= mod for i in range(1,r+1): ans *= pow(i,-1,mod) ans %= mod return ans def solve(): n, a, b = list(map(int, input().split())) mod = 10**9+7 ans = pow(2,n,mod)-comb_mod(n,a)-comb_mod(n,b)-1 ans %= mod return ans print((solve()))
18
18
390
386
def comb_mod(n, r): mod = 10**9 + 7 ans = 1 for i in range(r): ans *= n - i ans %= mod for i in range(1, r + 1): ans *= pow(i, mod - 2, mod) ans %= mod return ans def solve(): n, a, b = list(map(int, input().split())) mod = 10**9 + 7 ans = pow(2, n, mod) - comb_mod(n, a) - comb_mod(n, b) - 1 ans %= mod return ans print((solve()))
def comb_mod(n, r): mod = 10**9 + 7 ans = 1 for i in range(r): ans *= n - i ans %= mod for i in range(1, r + 1): ans *= pow(i, -1, mod) ans %= mod return ans def solve(): n, a, b = list(map(int, input().split())) mod = 10**9 + 7 ans = pow(2, n, mod) - comb_mod(n, a) - comb_mod(n, b) - 1 ans %= mod return ans print((solve()))
false
0
[ "- ans *= pow(i, mod - 2, mod)", "+ ans *= pow(i, -1, mod)" ]
false
1.250467
0.717198
1.743545
[ "s084827027", "s316536800" ]
u894258749
p02863
python
s451652460
s438468736
486
398
48,464
48,216
Accepted
Accepted
18.11
import sys input = lambda: sys.stdin.readline().rstrip() inpl = lambda: list(map(int,input().split())) N, T = inpl() A = [None]*N B = [None]*N for i in range(N): A[i], B[i] = inpl() dp_intime = [0]*T dp_total = [0]*T for n in range(N): dp_intime_prev, dp_intime = dp_intime, [0]*T dp_total_prev, dp_total = dp_total, [0]*T for t in range(T): if A[n] > t: dp_intime[t] = dp_intime_prev[t] dp_total[t] = max(B[n]+dp_intime_prev[t], dp_total_prev[t]) else: dp_intime[t] = max(dp_intime_prev[t], B[n]+dp_intime_prev[t-A[n]]) dp_total[t] = max(B[n]+dp_intime_prev[t], B[n]+dp_total_prev[t-A[n]], dp_total_prev[t]) print((dp_total[-1]))
inpl = lambda: list(map(int,input().split())) N, T = inpl() AB = sorted([inpl() for _ in range(N)]) ans = 0 dp_intime = [0]*T for n in range(N): dp_intime_prev = dp_intime dp_intime = [0]*T a, b = AB[n] for t in range(T): if t < a: dp_intime[t] = dp_intime_prev[t] else: dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t-a]+b) ans = max(ans, dp_intime_prev[-1]+b) print(ans)
24
17
792
456
import sys input = lambda: sys.stdin.readline().rstrip() inpl = lambda: list(map(int, input().split())) N, T = inpl() A = [None] * N B = [None] * N for i in range(N): A[i], B[i] = inpl() dp_intime = [0] * T dp_total = [0] * T for n in range(N): dp_intime_prev, dp_intime = dp_intime, [0] * T dp_total_prev, dp_total = dp_total, [0] * T for t in range(T): if A[n] > t: dp_intime[t] = dp_intime_prev[t] dp_total[t] = max(B[n] + dp_intime_prev[t], dp_total_prev[t]) else: dp_intime[t] = max(dp_intime_prev[t], B[n] + dp_intime_prev[t - A[n]]) dp_total[t] = max( B[n] + dp_intime_prev[t], B[n] + dp_total_prev[t - A[n]], dp_total_prev[t], ) print((dp_total[-1]))
inpl = lambda: list(map(int, input().split())) N, T = inpl() AB = sorted([inpl() for _ in range(N)]) ans = 0 dp_intime = [0] * T for n in range(N): dp_intime_prev = dp_intime dp_intime = [0] * T a, b = AB[n] for t in range(T): if t < a: dp_intime[t] = dp_intime_prev[t] else: dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t - a] + b) ans = max(ans, dp_intime_prev[-1] + b) print(ans)
false
29.166667
[ "-import sys", "-", "-input = lambda: sys.stdin.readline().rstrip()", "-A = [None] * N", "-B = [None] * N", "-for i in range(N):", "- A[i], B[i] = inpl()", "+AB = sorted([inpl() for _ in range(N)])", "+ans = 0", "-dp_total = [0] * T", "- dp_intime_prev, dp_intime = dp_intime, [0] * T", "- dp_total_prev, dp_total = dp_total, [0] * T", "+ dp_intime_prev = dp_intime", "+ dp_intime = [0] * T", "+ a, b = AB[n]", "- if A[n] > t:", "+ if t < a:", "- dp_total[t] = max(B[n] + dp_intime_prev[t], dp_total_prev[t])", "- dp_intime[t] = max(dp_intime_prev[t], B[n] + dp_intime_prev[t - A[n]])", "- dp_total[t] = max(", "- B[n] + dp_intime_prev[t],", "- B[n] + dp_total_prev[t - A[n]],", "- dp_total_prev[t],", "- )", "-print((dp_total[-1]))", "+ dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t - a] + b)", "+ ans = max(ans, dp_intime_prev[-1] + b)", "+print(ans)" ]
false
0.036494
0.041934
0.870287
[ "s451652460", "s438468736" ]
u609061751
p03086
python
s733941577
s603359544
167
63
38,532
61,988
Accepted
Accepted
62.28
S = input().rstrip() N = len(S) ans = 0 from collections import Counter for i in range(N): for j in range(i + 1, N + 1): flag = 1 s = S[i:j] c = Counter(s) for k in list(c.keys()): if k != "A" and k != "C" and k != "G" and k != "T": flag = 0 break if flag: ans = max(ans, len(s)) print(ans)
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") s = eval(input()) n = len(s) ans = 0 acgt = set(['A', 'C', 'G', 'T']) for i in range(n): for j in range(i + 1, n + 1): t = s[i:j] flag = 1 for k in t: if k not in acgt: flag = 0 break if flag: ans = max(ans, len(t)) print(ans)
17
19
408
411
S = input().rstrip() N = len(S) ans = 0 from collections import Counter for i in range(N): for j in range(i + 1, N + 1): flag = 1 s = S[i:j] c = Counter(s) for k in list(c.keys()): if k != "A" and k != "C" and k != "G" and k != "T": flag = 0 break if flag: ans = max(ans, len(s)) print(ans)
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") s = eval(input()) n = len(s) ans = 0 acgt = set(["A", "C", "G", "T"]) for i in range(n): for j in range(i + 1, n + 1): t = s[i:j] flag = 1 for k in t: if k not in acgt: flag = 0 break if flag: ans = max(ans, len(t)) print(ans)
false
10.526316
[ "-S = input().rstrip()", "-N = len(S)", "+import sys", "+", "+input = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")", "+s = eval(input())", "+n = len(s)", "-from collections import Counter", "-", "-for i in range(N):", "- for j in range(i + 1, N + 1):", "+acgt = set([\"A\", \"C\", \"G\", \"T\"])", "+for i in range(n):", "+ for j in range(i + 1, n + 1):", "+ t = s[i:j]", "- s = S[i:j]", "- c = Counter(s)", "- for k in list(c.keys()):", "- if k != \"A\" and k != \"C\" and k != \"G\" and k != \"T\":", "+ for k in t:", "+ if k not in acgt:", "- ans = max(ans, len(s))", "+ ans = max(ans, len(t))" ]
false
0.034525
0.03578
0.964922
[ "s733941577", "s603359544" ]
u731807761
p02660
python
s215389508
s589396541
1,677
214
27,140
27,168
Accepted
Accepted
87.24
import numpy as np import sys #import copy def xnxn(n=0): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp def sp_xnxn(n=0): """ args: int n: a number of lows to read example input 1 retrun [1] input 123 return [1,2,3] input 123 4 return [[1,2,3], [4]] """ if n == 0: return [int(k) for k in xsxs()] else: return [[int(k) for k in xsxs()] for _ in range(n)] def xsxs(n=0): """ args: int n: a number of lows to read example: input AA retrun AA input A BBB CC return ["A","BBB","CC"] input A BB CCC D return [["A","BBB","CC"], ["D"]] """ if n == 0: temp = list(input().split()) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: return [list(input().split()) for _ in range(n)] def sp_xsxs(n=0): """ args: int n: a number of lows to read example: input A retrun ["A"] input ABC return ["A","B","C"] input ABC D return [["A","B","C"], ["D"]] """ if n == 0: return [s for s in xsxs()] else: return [[s for s in xsxs()] for _ in range(n)] def p_num(a): if a == 1: return [[a, 1]] else: tmp = 2 ans = [] while tmp < np.sqrt(a) + 1: n = 0 p = [tmp] while a % tmp == 0: a = int(a / tmp) # p.append(tmp) n += 1 c = 1 if n != 0: p.append(n) ans.append(p) tmp += 1 c = 0 if c == 0 and a != 1: ans.append([a, 1]) return ans n = xnxn() if n == 1: print((0)) sys.exit() else: a = p_num(n) c = 0 for num in a: i = 1 while num[1] - i > -1: num[1] -= i i += 1 c += 1 print(c)
import numpy as np import sys #import copy def xnxn(n=0): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp def sp_xnxn(n=0): """ args: int n: a number of lows to read example input 1 retrun [1] input 123 return [1,2,3] input 123 4 return [[1,2,3], [4]] """ if n == 0: return [int(k) for k in xsxs()] else: return [[int(k) for k in xsxs()] for _ in range(n)] def xsxs(n=0): """ args: int n: a number of lows to read example: input AA retrun AA input A BBB CC return ["A","BBB","CC"] input A BB CCC D return [["A","BBB","CC"], ["D"]] """ if n == 0: temp = list(input().split()) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: return [list(input().split()) for _ in range(n)] def sp_xsxs(n=0): """ args: int n: a number of lows to read example: input A retrun ["A"] input ABC return ["A","B","C"] input ABC D return [["A","B","C"], ["D"]] """ if n == 0: return [s for s in xsxs()] else: return [[s for s in xsxs()] for _ in range(n)] def p_num(a): if a == 1: return [[a, 1]] else: tmp = 2 ans = [] while tmp < np.sqrt(a) + 1: n = 0 p = [tmp] while a % tmp == 0: a = int(a / tmp) # p.append(tmp) n += 1 c = 1 if n != 0: p.append(n) ans.append(p) tmp += 1 c = 0 if c == 0 and a != 1: ans.append([a, 1]) return ans def p_num_edit(n): tmp = n ans = [] for i in range(2, int(np.sqrt(n)) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp = int(tmp / i) if cnt > 0: ans.append([i, cnt]) if tmp != 1: ans.append([tmp, 1]) if ans == []: ans.append([n, 1]) return ans n = xnxn() if n == 1: print((0)) sys.exit() else: a = p_num_edit(n) c = 0 for num in a: i = 1 while num[1] - i > -1: num[1] -= i i += 1 c += 1 print(c)
142
159
2,804
3,171
import numpy as np import sys # import copy def xnxn(n=0): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp def sp_xnxn(n=0): """ args: int n: a number of lows to read example input 1 retrun [1] input 123 return [1,2,3] input 123 4 return [[1,2,3], [4]] """ if n == 0: return [int(k) for k in xsxs()] else: return [[int(k) for k in xsxs()] for _ in range(n)] def xsxs(n=0): """ args: int n: a number of lows to read example: input AA retrun AA input A BBB CC return ["A","BBB","CC"] input A BB CCC D return [["A","BBB","CC"], ["D"]] """ if n == 0: temp = list(input().split()) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: return [list(input().split()) for _ in range(n)] def sp_xsxs(n=0): """ args: int n: a number of lows to read example: input A retrun ["A"] input ABC return ["A","B","C"] input ABC D return [["A","B","C"], ["D"]] """ if n == 0: return [s for s in xsxs()] else: return [[s for s in xsxs()] for _ in range(n)] def p_num(a): if a == 1: return [[a, 1]] else: tmp = 2 ans = [] while tmp < np.sqrt(a) + 1: n = 0 p = [tmp] while a % tmp == 0: a = int(a / tmp) # p.append(tmp) n += 1 c = 1 if n != 0: p.append(n) ans.append(p) tmp += 1 c = 0 if c == 0 and a != 1: ans.append([a, 1]) return ans n = xnxn() if n == 1: print((0)) sys.exit() else: a = p_num(n) c = 0 for num in a: i = 1 while num[1] - i > -1: num[1] -= i i += 1 c += 1 print(c)
import numpy as np import sys # import copy def xnxn(n=0): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp def sp_xnxn(n=0): """ args: int n: a number of lows to read example input 1 retrun [1] input 123 return [1,2,3] input 123 4 return [[1,2,3], [4]] """ if n == 0: return [int(k) for k in xsxs()] else: return [[int(k) for k in xsxs()] for _ in range(n)] def xsxs(n=0): """ args: int n: a number of lows to read example: input AA retrun AA input A BBB CC return ["A","BBB","CC"] input A BB CCC D return [["A","BBB","CC"], ["D"]] """ if n == 0: temp = list(input().split()) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: return [list(input().split()) for _ in range(n)] def sp_xsxs(n=0): """ args: int n: a number of lows to read example: input A retrun ["A"] input ABC return ["A","B","C"] input ABC D return [["A","B","C"], ["D"]] """ if n == 0: return [s for s in xsxs()] else: return [[s for s in xsxs()] for _ in range(n)] def p_num(a): if a == 1: return [[a, 1]] else: tmp = 2 ans = [] while tmp < np.sqrt(a) + 1: n = 0 p = [tmp] while a % tmp == 0: a = int(a / tmp) # p.append(tmp) n += 1 c = 1 if n != 0: p.append(n) ans.append(p) tmp += 1 c = 0 if c == 0 and a != 1: ans.append([a, 1]) return ans def p_num_edit(n): tmp = n ans = [] for i in range(2, int(np.sqrt(n)) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp = int(tmp / i) if cnt > 0: ans.append([i, cnt]) if tmp != 1: ans.append([tmp, 1]) if ans == []: ans.append([n, 1]) return ans n = xnxn() if n == 1: print((0)) sys.exit() else: a = p_num_edit(n) c = 0 for num in a: i = 1 while num[1] - i > -1: num[1] -= i i += 1 c += 1 print(c)
false
10.691824
[ "+def p_num_edit(n):", "+ tmp = n", "+ ans = []", "+ for i in range(2, int(np.sqrt(n)) + 1):", "+ cnt = 0", "+ while tmp % i == 0:", "+ cnt += 1", "+ tmp = int(tmp / i)", "+ if cnt > 0:", "+ ans.append([i, cnt])", "+ if tmp != 1:", "+ ans.append([tmp, 1])", "+ if ans == []:", "+ ans.append([n, 1])", "+ return ans", "+", "+", "- a = p_num(n)", "+ a = p_num_edit(n)" ]
false
0.449966
0.007544
59.642242
[ "s215389508", "s589396541" ]
u036340997
p02879
python
s145293910
s795121893
161
17
38,256
2,940
Accepted
Accepted
89.44
a, b = list(map(int, input().split())) if a < 10 and b < 10: print((a*b)) else: print((-1))
a, b = list(map(int, input().split())) if a <= 9 and b <= 9: print((a*b)) else: print((-1))
5
5
89
89
a, b = list(map(int, input().split())) if a < 10 and b < 10: print((a * b)) else: print((-1))
a, b = list(map(int, input().split())) if a <= 9 and b <= 9: print((a * b)) else: print((-1))
false
0
[ "-if a < 10 and b < 10:", "+if a <= 9 and b <= 9:" ]
false
0.047948
0.043119
1.111998
[ "s145293910", "s795121893" ]
u547167033
p03740
python
s742441796
s347952307
161
17
38,384
2,940
Accepted
Accepted
89.44
x,y=list(map(int,input().split())) if abs(x-y)<=1: print('Brown') else: print('Alice')
x,y=list(map(int,input().split())) print(('Brown' if abs(x-y)<=1 else 'Alice'))
5
2
88
72
x, y = list(map(int, input().split())) if abs(x - y) <= 1: print("Brown") else: print("Alice")
x, y = list(map(int, input().split())) print(("Brown" if abs(x - y) <= 1 else "Alice"))
false
60
[ "-if abs(x - y) <= 1:", "- print(\"Brown\")", "-else:", "- print(\"Alice\")", "+print((\"Brown\" if abs(x - y) <= 1 else \"Alice\"))" ]
false
0.043249
0.041025
1.054194
[ "s742441796", "s347952307" ]
u310678820
p02913
python
s815359414
s410538150
1,104
220
3,060
44,496
Accepted
Accepted
80.07
N = int(eval(input())) S = eval(input()) ans = 0 for i in range(N): if N-i<ans: break if S[i+1:].find(S[i-ans:i+1])>=0: ans += 1 print(ans)
from collections import defaultdict N = int(eval(input())) S = list(map(ord, list(eval(input())))) mod = 10**9+7 base = 1234 power = [1]*(N+1) for i in range(1, N+1): power[i] = power[i-1]*base%mod def check(m): if N-m<m: return False res = 0 for i in range(m): res+=S[i]*power[m-i-1] res%=mod dic = defaultdict(lambda : -1) dic[res] = 0 for i in range(N-m): res = ((res-S[i]*power[m-1])*base +S[i+m])%mod if dic[res]>=0: index = dic[res] if index +m<=i+1: return True else: dic[res] = i+1 return False ok = 0 ng = N+1 while ng-ok>1: mid = (ok+ng)//2 if check(mid): ok = mid else: ng = mid print(ok)
9
38
159
828
N = int(eval(input())) S = eval(input()) ans = 0 for i in range(N): if N - i < ans: break if S[i + 1 :].find(S[i - ans : i + 1]) >= 0: ans += 1 print(ans)
from collections import defaultdict N = int(eval(input())) S = list(map(ord, list(eval(input())))) mod = 10**9 + 7 base = 1234 power = [1] * (N + 1) for i in range(1, N + 1): power[i] = power[i - 1] * base % mod def check(m): if N - m < m: return False res = 0 for i in range(m): res += S[i] * power[m - i - 1] res %= mod dic = defaultdict(lambda: -1) dic[res] = 0 for i in range(N - m): res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod if dic[res] >= 0: index = dic[res] if index + m <= i + 1: return True else: dic[res] = i + 1 return False ok = 0 ng = N + 1 while ng - ok > 1: mid = (ok + ng) // 2 if check(mid): ok = mid else: ng = mid print(ok)
false
76.315789
[ "+from collections import defaultdict", "+", "-S = eval(input())", "-ans = 0", "-for i in range(N):", "- if N - i < ans:", "- break", "- if S[i + 1 :].find(S[i - ans : i + 1]) >= 0:", "- ans += 1", "-print(ans)", "+S = list(map(ord, list(eval(input()))))", "+mod = 10**9 + 7", "+base = 1234", "+power = [1] * (N + 1)", "+for i in range(1, N + 1):", "+ power[i] = power[i - 1] * base % mod", "+", "+", "+def check(m):", "+ if N - m < m:", "+ return False", "+ res = 0", "+ for i in range(m):", "+ res += S[i] * power[m - i - 1]", "+ res %= mod", "+ dic = defaultdict(lambda: -1)", "+ dic[res] = 0", "+ for i in range(N - m):", "+ res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod", "+ if dic[res] >= 0:", "+ index = dic[res]", "+ if index + m <= i + 1:", "+ return True", "+ else:", "+ dic[res] = i + 1", "+ return False", "+", "+", "+ok = 0", "+ng = N + 1", "+while ng - ok > 1:", "+ mid = (ok + ng) // 2", "+ if check(mid):", "+ ok = mid", "+ else:", "+ ng = mid", "+print(ok)" ]
false
0.037804
0.045736
0.826553
[ "s815359414", "s410538150" ]
u072053884
p02268
python
s908029947
s597131514
480
340
18,976
19,100
Accepted
Accepted
29.17
n = int(eval(input())) S = tuple(map(int, input().split(' '))) q = eval(input()) T = tuple(map(int, input().split(' '))) cnt = 0 for i in T: left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == i: cnt += 1 break elif i < S[mid]: right = mid else: left = mid + 1 print(cnt)
def binarySearch(A, key, n): left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == i: return True elif i < S[mid]: right = mid else: left = mid + 1 return False n = int(eval(input())) S = tuple(map(int, input().split(' '))) q = eval(input()) T = tuple(map(int, input().split(' '))) cnt = 0 for i in T: if binarySearch(S, i, n): cnt += 1 print(cnt)
22
26
402
485
n = int(eval(input())) S = tuple(map(int, input().split(" "))) q = eval(input()) T = tuple(map(int, input().split(" "))) cnt = 0 for i in T: left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == i: cnt += 1 break elif i < S[mid]: right = mid else: left = mid + 1 print(cnt)
def binarySearch(A, key, n): left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == i: return True elif i < S[mid]: right = mid else: left = mid + 1 return False n = int(eval(input())) S = tuple(map(int, input().split(" "))) q = eval(input()) T = tuple(map(int, input().split(" "))) cnt = 0 for i in T: if binarySearch(S, i, n): cnt += 1 print(cnt)
false
15.384615
[ "+def binarySearch(A, key, n):", "+ left = 0", "+ right = n", "+ while left < right:", "+ mid = (left + right) // 2", "+ if S[mid] == i:", "+ return True", "+ elif i < S[mid]:", "+ right = mid", "+ else:", "+ left = mid + 1", "+ return False", "+", "+", "- left = 0", "- right = n", "- while left < right:", "- mid = (left + right) // 2", "- if S[mid] == i:", "- cnt += 1", "- break", "- elif i < S[mid]:", "- right = mid", "- else:", "- left = mid + 1", "+ if binarySearch(S, i, n):", "+ cnt += 1" ]
false
0.172599
0.035824
4.818012
[ "s908029947", "s597131514" ]
u413165887
p02948
python
s301230941
s526329499
622
542
23,880
23,880
Accepted
Accepted
12.86
import heapq n, m = list(map(int, input().split(' '))) df = [] for _ in range(n): x, y = list(map(int, input().split(' '))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m+1): while counter < len(df) and df[counter][0] <= i: heapq.heappush(h, (-1)*df[counter][1]) counter += 1 if len(h) == 0: continue else: result -= heapq.heappop(h) print(result)
def main(): import heapq n, m = list(map(int, input().split(' '))) df = [] for _ in range(n): x, y = list(map(int, input().split(' '))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m+1): while counter < len(df) and df[counter][0] <= i: heapq.heappush(h, (-1)*df[counter][1]) counter += 1 if len(h) == 0: continue else: result -= heapq.heappop(h) print(result) if __name__ == '__main__': main()
19
22
436
565
import heapq n, m = list(map(int, input().split(" "))) df = [] for _ in range(n): x, y = list(map(int, input().split(" "))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m + 1): while counter < len(df) and df[counter][0] <= i: heapq.heappush(h, (-1) * df[counter][1]) counter += 1 if len(h) == 0: continue else: result -= heapq.heappop(h) print(result)
def main(): import heapq n, m = list(map(int, input().split(" "))) df = [] for _ in range(n): x, y = list(map(int, input().split(" "))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m + 1): while counter < len(df) and df[counter][0] <= i: heapq.heappush(h, (-1) * df[counter][1]) counter += 1 if len(h) == 0: continue else: result -= heapq.heappop(h) print(result) if __name__ == "__main__": main()
false
13.636364
[ "-import heapq", "+def main():", "+ import heapq", "-n, m = list(map(int, input().split(\" \")))", "-df = []", "-for _ in range(n):", "- x, y = list(map(int, input().split(\" \")))", "- df.append([x, y])", "-df.sort()", "-h = []", "-result = 0", "-counter = 0", "-for i in range(1, m + 1):", "- while counter < len(df) and df[counter][0] <= i:", "- heapq.heappush(h, (-1) * df[counter][1])", "- counter += 1", "- if len(h) == 0:", "- continue", "- else:", "- result -= heapq.heappop(h)", "-print(result)", "+ n, m = list(map(int, input().split(\" \")))", "+ df = []", "+ for _ in range(n):", "+ x, y = list(map(int, input().split(\" \")))", "+ df.append([x, y])", "+ df.sort()", "+ h = []", "+ result = 0", "+ counter = 0", "+ for i in range(1, m + 1):", "+ while counter < len(df) and df[counter][0] <= i:", "+ heapq.heappush(h, (-1) * df[counter][1])", "+ counter += 1", "+ if len(h) == 0:", "+ continue", "+ else:", "+ result -= heapq.heappop(h)", "+ print(result)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037472
0.037539
0.998214
[ "s301230941", "s526329499" ]
u654470292
p03634
python
s475278228
s776551639
894
341
125,784
131,160
Accepted
Accepted
61.86
import sys from collections import * import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod=10**9+7 n=int(eval(input())) abc=[list(map(int,input().split())) for i in range(n-1)] q,k=list(map(int,input().split())) xy=[list(map(int,input().split())) for i in range(q)] lst=[[] for i in range(n+1)] # print(lst) for i in range(n-1): a,b,c=abc[i] lst[a].append([b,c]) lst[b].append([a,c]) dist=[float('inf')]*(n+1) # dist[k]=0 # print(lst) d=deque() d.append([[[k,0]],0]) while d: tmp=d.popleft() # print(tmp) for i in range(len(tmp[0])): # print(tmp[0][i]) if dist[tmp[0][i][0]]==float('inf'): dist[tmp[0][i][0]]=tmp[0][i][1]+tmp[-1] d.append([lst[tmp[0][i][0]],dist[tmp[0][i][0]]]) # print(dist) for i in range(q): x,y=xy[i] print((dist[x]+dist[y]))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(eval(input())) abc=[list(map(int,input().split())) for i in range(n-1)] q,k=list(map(int,input().split())) xy=[list(map(int,input().split())) for i in range(q)] itta=[0]*(n+1) dic=defaultdict(list) for a,b,c in abc: dic[a].append((b,c)) dic[b].append((a,c)) d=deque([(k,0)]) while d: now=d.popleft() if itta[now[0]]!=0: continue itta[now[0]]=now[1] for i,j in dic[now[0]]: d.append((i,j+now[1])) # print(itta) itta[k]=0 for x,y in xy: print((itta[x]+itta[y]))
39
38
976
968
import sys from collections import * import heapq import math import bisect from itertools import permutations, accumulate, combinations, product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 n = int(eval(input())) abc = [list(map(int, input().split())) for i in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for i in range(q)] lst = [[] for i in range(n + 1)] # print(lst) for i in range(n - 1): a, b, c = abc[i] lst[a].append([b, c]) lst[b].append([a, c]) dist = [float("inf")] * (n + 1) # dist[k]=0 # print(lst) d = deque() d.append([[[k, 0]], 0]) while d: tmp = d.popleft() # print(tmp) for i in range(len(tmp[0])): # print(tmp[0][i]) if dist[tmp[0][i][0]] == float("inf"): dist[tmp[0][i][0]] = tmp[0][i][1] + tmp[-1] d.append([lst[tmp[0][i][0]], dist[tmp[0][i][0]]]) # print(dist) for i in range(q): x, y = xy[i] print((dist[x] + dist[y]))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) def celi(a, b): return -(-a // b) sys.setrecursionlimit(5000000) mod = pow(10, 9) + 7 al = [chr(ord("a") + i) for i in range(26)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] n = int(eval(input())) abc = [list(map(int, input().split())) for i in range(n - 1)] q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for i in range(q)] itta = [0] * (n + 1) dic = defaultdict(list) for a, b, c in abc: dic[a].append((b, c)) dic[b].append((a, c)) d = deque([(k, 0)]) while d: now = d.popleft() if itta[now[0]] != 0: continue itta[now[0]] = now[1] for i, j in dic[now[0]]: d.append((i, j + now[1])) # print(itta) itta[k] = 0 for x, y in xy: print((itta[x] + itta[y]))
false
2.564103
[ "-import sys", "+import bisect, copy, heapq, math, sys", "-import heapq", "-import math", "-import bisect", "-from itertools import permutations, accumulate, combinations, product", "-from fractions import gcd", "+from functools import lru_cache", "+from itertools import accumulate, combinations, permutations, product", "-mod = 10**9 + 7", "+def ruiseki(lst):", "+ return [0] + list(accumulate(lst))", "+", "+", "+def celi(a, b):", "+ return -(-a // b)", "+", "+", "+sys.setrecursionlimit(5000000)", "+mod = pow(10, 9) + 7", "+al = [chr(ord(\"a\") + i) for i in range(26)]", "+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-lst = [[] for i in range(n + 1)]", "-# print(lst)", "-for i in range(n - 1):", "- a, b, c = abc[i]", "- lst[a].append([b, c])", "- lst[b].append([a, c])", "-dist = [float(\"inf\")] * (n + 1)", "-# dist[k]=0", "-# print(lst)", "-d = deque()", "-d.append([[[k, 0]], 0])", "+itta = [0] * (n + 1)", "+dic = defaultdict(list)", "+for a, b, c in abc:", "+ dic[a].append((b, c))", "+ dic[b].append((a, c))", "+d = deque([(k, 0)])", "- tmp = d.popleft()", "- # print(tmp)", "- for i in range(len(tmp[0])):", "- # print(tmp[0][i])", "- if dist[tmp[0][i][0]] == float(\"inf\"):", "- dist[tmp[0][i][0]] = tmp[0][i][1] + tmp[-1]", "- d.append([lst[tmp[0][i][0]], dist[tmp[0][i][0]]])", "-# print(dist)", "-for i in range(q):", "- x, y = xy[i]", "- print((dist[x] + dist[y]))", "+ now = d.popleft()", "+ if itta[now[0]] != 0:", "+ continue", "+ itta[now[0]] = now[1]", "+ for i, j in dic[now[0]]:", "+ d.append((i, j + now[1]))", "+# print(itta)", "+itta[k] = 0", "+for x, y in xy:", "+ print((itta[x] + itta[y]))" ]
false
0.077973
0.031596
2.467828
[ "s475278228", "s776551639" ]
u196579381
p03946
python
s963966503
s453084883
505
251
77,548
72,084
Accepted
Accepted
50.3
N, T = list(map(int, input().split())) A = [int(i) for i in input().split()] ml = [(A[-1], 1)] for a in A[-2:0:-1]: n = ml[-1] if n[0] == a: ml.append((a, n[1] + 1)) elif n[0] < a: ml.append((a, 1)) else: ml.append(n) ml.reverse() c = [(ml[i][0] - A[i], ml[i][0], ml[i][1]) for i in range(N - 1)] c.sort(reverse=True) max_num = c[0][0] d = {} cnt = 0 for m in c: if m[0] != max_num: break cnt += 1 if m[1] not in d: d[m[1]] = m[2] else: d[m[1]] = max(d[m[1]], m[2]) print((min(cnt, sum(d.values()))))
from collections import Counter N, T = list(map(int, input().split())) A = [int(i) for i in input().split()] m = A[0] B = [] for a in A[1:]: B.append(a - m) m = min(m, a) c = Counter(B) print((c[max(c.keys())]))
30
10
605
220
N, T = list(map(int, input().split())) A = [int(i) for i in input().split()] ml = [(A[-1], 1)] for a in A[-2:0:-1]: n = ml[-1] if n[0] == a: ml.append((a, n[1] + 1)) elif n[0] < a: ml.append((a, 1)) else: ml.append(n) ml.reverse() c = [(ml[i][0] - A[i], ml[i][0], ml[i][1]) for i in range(N - 1)] c.sort(reverse=True) max_num = c[0][0] d = {} cnt = 0 for m in c: if m[0] != max_num: break cnt += 1 if m[1] not in d: d[m[1]] = m[2] else: d[m[1]] = max(d[m[1]], m[2]) print((min(cnt, sum(d.values()))))
from collections import Counter N, T = list(map(int, input().split())) A = [int(i) for i in input().split()] m = A[0] B = [] for a in A[1:]: B.append(a - m) m = min(m, a) c = Counter(B) print((c[max(c.keys())]))
false
66.666667
[ "+from collections import Counter", "+", "-ml = [(A[-1], 1)]", "-for a in A[-2:0:-1]:", "- n = ml[-1]", "- if n[0] == a:", "- ml.append((a, n[1] + 1))", "- elif n[0] < a:", "- ml.append((a, 1))", "- else:", "- ml.append(n)", "-ml.reverse()", "-c = [(ml[i][0] - A[i], ml[i][0], ml[i][1]) for i in range(N - 1)]", "-c.sort(reverse=True)", "-max_num = c[0][0]", "-d = {}", "-cnt = 0", "-for m in c:", "- if m[0] != max_num:", "- break", "- cnt += 1", "- if m[1] not in d:", "- d[m[1]] = m[2]", "- else:", "- d[m[1]] = max(d[m[1]], m[2])", "-print((min(cnt, sum(d.values()))))", "+m = A[0]", "+B = []", "+for a in A[1:]:", "+ B.append(a - m)", "+ m = min(m, a)", "+c = Counter(B)", "+print((c[max(c.keys())]))" ]
false
0.059782
0.19796
0.30199
[ "s963966503", "s453084883" ]
u150984829
p02256
python
s051031063
s546624742
20
10
5,604
5,664
Accepted
Accepted
50
def g(n): x,y=n r=x%y if r>0:g((y,r)) else:print(y) g(sorted(list(map(int,input().split()))))
import math a,b=list(map(int,input().split())) print((math.gcd(a,b))) ''' # 09.98 sec 13492 KB 4 lines 99 bytes # Time Limit Exceeded n=int(input()) r=[int(input())for _ in range(n)] print(max([max(r[i+1:])-r[i]for i in range(n-1)])) '''
6
11
102
250
def g(n): x, y = n r = x % y if r > 0: g((y, r)) else: print(y) g(sorted(list(map(int, input().split()))))
import math a, b = list(map(int, input().split())) print((math.gcd(a, b))) """ # 09.98 sec 13492 KB 4 lines 99 bytes # Time Limit Exceeded n=int(input()) r=[int(input())for _ in range(n)] print(max([max(r[i+1:])-r[i]for i in range(n-1)])) """
false
45.454545
[ "-def g(n):", "- x, y = n", "- r = x % y", "- if r > 0:", "- g((y, r))", "- else:", "- print(y)", "+import math", "-", "-g(sorted(list(map(int, input().split()))))", "+a, b = list(map(int, input().split()))", "+print((math.gcd(a, b)))", "+\"\"\"", "+# 09.98 sec 13492 KB 4 lines 99 bytes", "+# Time Limit Exceeded", "+n=int(input())", "+r=[int(input())for _ in range(n)]", "+print(max([max(r[i+1:])-r[i]for i in range(n-1)]))", "+\"\"\"" ]
false
0.077534
0.03555
2.181013
[ "s051031063", "s546624742" ]
u839624727
p02838
python
s374949052
s059187617
297
223
53,560
29,148
Accepted
Accepted
24.92
import numpy as np def solve(string): n, *a = list(map(int, string.split())) # a = ["{:060b}".format(_a) for _a in a] a = np.asarray(a, dtype=np.int64) m = 10**9 + 7 ans = 0 for i in range(60): s = int((a & 1).sum()) a >>= 1 # ans += s * (n - s) * pow(2, 59 - i, m) ans += s * (n - s) * pow(2, i, m) % m ans %= m return str(ans) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
import numpy as np import math n = int(eval(input())) A = np.fromstring(eval(input()),dtype=np.int64,sep=" ") #rng = int(math.log2(np.max(A)))+1 sum = 0 d = 10**9+7 for bit in range(64): c = int((A & 1).sum()) sum += c *(n-c)*(1<<bit)%d A = A>>1 print((sum %(d)))
21
13
503
274
import numpy as np def solve(string): n, *a = list(map(int, string.split())) # a = ["{:060b}".format(_a) for _a in a] a = np.asarray(a, dtype=np.int64) m = 10**9 + 7 ans = 0 for i in range(60): s = int((a & 1).sum()) a >>= 1 # ans += s * (n - s) * pow(2, 59 - i, m) ans += s * (n - s) * pow(2, i, m) % m ans %= m return str(ans) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
import numpy as np import math n = int(eval(input())) A = np.fromstring(eval(input()), dtype=np.int64, sep=" ") # rng = int(math.log2(np.max(A)))+1 sum = 0 d = 10**9 + 7 for bit in range(64): c = int((A & 1).sum()) sum += c * (n - c) * (1 << bit) % d A = A >> 1 print((sum % (d)))
false
38.095238
[ "+import math", "-", "-def solve(string):", "- n, *a = list(map(int, string.split()))", "- # a = [\"{:060b}\".format(_a) for _a in a]", "- a = np.asarray(a, dtype=np.int64)", "- m = 10**9 + 7", "- ans = 0", "- for i in range(60):", "- s = int((a & 1).sum())", "- a >>= 1", "- # ans += s * (n - s) * pow(2, 59 - i, m)", "- ans += s * (n - s) * pow(2, i, m) % m", "- ans %= m", "- return str(ans)", "-", "-", "-if __name__ == \"__main__\":", "- import sys", "-", "- print((solve(sys.stdin.read().strip())))", "+n = int(eval(input()))", "+A = np.fromstring(eval(input()), dtype=np.int64, sep=\" \")", "+# rng = int(math.log2(np.max(A)))+1", "+sum = 0", "+d = 10**9 + 7", "+for bit in range(64):", "+ c = int((A & 1).sum())", "+ sum += c * (n - c) * (1 << bit) % d", "+ A = A >> 1", "+print((sum % (d)))" ]
false
0.587444
0.269284
2.181501
[ "s374949052", "s059187617" ]
u608088992
p03379
python
s611479832
s007483489
457
272
27,156
25,572
Accepted
Accepted
40.48
import copy N = int(eval(input())) X = [int(i) for i in input().split()] Y = copy.deepcopy(X) Y.sort() ML, MH = Y[N//2 - 1], Y[N//2] for i in range(N): if X[i] >= MH: print(ML) else: print(MH)
import sys def solve(): input = sys.stdin.readline N = int(input()) X = [int(x) for x in input().split()] Xsub = sorted(X) midl, midr = Xsub[(N - 1) // 2], Xsub[N // 2] ans = [0] * N for i, x in enumerate(X): if x <= midl: ans[i] = midr else: ans[i] = midl print(*ans, sep="\n") return 0 if __name__ == "__main__": solve()
12
18
222
398
import copy N = int(eval(input())) X = [int(i) for i in input().split()] Y = copy.deepcopy(X) Y.sort() ML, MH = Y[N // 2 - 1], Y[N // 2] for i in range(N): if X[i] >= MH: print(ML) else: print(MH)
import sys def solve(): input = sys.stdin.readline N = int(input()) X = [int(x) for x in input().split()] Xsub = sorted(X) midl, midr = Xsub[(N - 1) // 2], Xsub[N // 2] ans = [0] * N for i, x in enumerate(X): if x <= midl: ans[i] = midr else: ans[i] = midl print(*ans, sep="\n") return 0 if __name__ == "__main__": solve()
false
33.333333
[ "-import copy", "+import sys", "-N = int(eval(input()))", "-X = [int(i) for i in input().split()]", "-Y = copy.deepcopy(X)", "-Y.sort()", "-ML, MH = Y[N // 2 - 1], Y[N // 2]", "-for i in range(N):", "- if X[i] >= MH:", "- print(ML)", "- else:", "- print(MH)", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N = int(input())", "+ X = [int(x) for x in input().split()]", "+ Xsub = sorted(X)", "+ midl, midr = Xsub[(N - 1) // 2], Xsub[N // 2]", "+ ans = [0] * N", "+ for i, x in enumerate(X):", "+ if x <= midl:", "+ ans[i] = midr", "+ else:", "+ ans[i] = midl", "+ print(*ans, sep=\"\\n\")", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.044065
0.040653
1.083909
[ "s611479832", "s007483489" ]
u454022848
p02397
python
s042898086
s417838490
60
20
6,724
6,268
Accepted
Accepted
66.67
while True: ia=[int(i) for i in input().split(" ")] if ia[0]==ia[1]==0: break print((" ".join([str(i) for i in sorted(ia)])))
# encoding:utf-8 while True: input = list(map(int, input().split())) x, y = input if x == y == 0: break input.sort() print((" ".join(map(str, input))))
5
8
132
162
while True: ia = [int(i) for i in input().split(" ")] if ia[0] == ia[1] == 0: break print((" ".join([str(i) for i in sorted(ia)])))
# encoding:utf-8 while True: input = list(map(int, input().split())) x, y = input if x == y == 0: break input.sort() print((" ".join(map(str, input))))
false
37.5
[ "+# encoding:utf-8", "- ia = [int(i) for i in input().split(\" \")]", "- if ia[0] == ia[1] == 0:", "+ input = list(map(int, input().split()))", "+ x, y = input", "+ if x == y == 0:", "- print((\" \".join([str(i) for i in sorted(ia)])))", "+ input.sort()", "+ print((\" \".join(map(str, input))))" ]
false
0.034331
0.035564
0.96532
[ "s042898086", "s417838490" ]
u707124227
p02715
python
s318451772
s137079401
121
103
80,832
68,924
Accepted
Accepted
14.88
n,k=list(map(int,input().split())) # 1以上k以下の整数がn個 mod=int(1e+9 + 7) d=[0]*(k+1) ans=0 for i in range(k,0,-1): m=k//i d[i]=pow(m,n, mod) d[i]-=sum([d[j*i]for j in range(2,m+1)]) ans+=(d[i]*i)%mod print(((ans)%mod)) #print(d)
n,k=list(map(int,input().split())) mod=pow(10,9)+7 ans=[0]*(k+1) # gcdがkiとなる数列。すべてがkiの倍数でかつ少なくとも一つkiを含む for ki in range(k,0,-1): a=k//ki ans[ki]=pow(a,n,mod) i=2 while i*ki<=k: ans[ki]-=ans[i*ki] i+=1 b=0 for ki in range(1,k+1): b+=(ans[ki]*ki)%mod b%=mod print(b)
13
16
254
314
n, k = list(map(int, input().split())) # 1以上k以下の整数がn個 mod = int(1e9 + 7) d = [0] * (k + 1) ans = 0 for i in range(k, 0, -1): m = k // i d[i] = pow(m, n, mod) d[i] -= sum([d[j * i] for j in range(2, m + 1)]) ans += (d[i] * i) % mod print(((ans) % mod)) # print(d)
n, k = list(map(int, input().split())) mod = pow(10, 9) + 7 ans = [0] * (k + 1) # gcdがkiとなる数列。すべてがkiの倍数でかつ少なくとも一つkiを含む for ki in range(k, 0, -1): a = k // ki ans[ki] = pow(a, n, mod) i = 2 while i * ki <= k: ans[ki] -= ans[i * ki] i += 1 b = 0 for ki in range(1, k + 1): b += (ans[ki] * ki) % mod b %= mod print(b)
false
18.75
[ "-# 1以上k以下の整数がn個", "-mod = int(1e9 + 7)", "-d = [0] * (k + 1)", "-ans = 0", "-for i in range(k, 0, -1):", "- m = k // i", "- d[i] = pow(m, n, mod)", "- d[i] -= sum([d[j * i] for j in range(2, m + 1)])", "- ans += (d[i] * i) % mod", "-print(((ans) % mod))", "-# print(d)", "+mod = pow(10, 9) + 7", "+ans = [0] * (k + 1)", "+# gcdがkiとなる数列。すべてがkiの倍数でかつ少なくとも一つkiを含む", "+for ki in range(k, 0, -1):", "+ a = k // ki", "+ ans[ki] = pow(a, n, mod)", "+ i = 2", "+ while i * ki <= k:", "+ ans[ki] -= ans[i * ki]", "+ i += 1", "+b = 0", "+for ki in range(1, k + 1):", "+ b += (ans[ki] * ki) % mod", "+ b %= mod", "+print(b)" ]
false
0.466281
0.262404
1.776957
[ "s318451772", "s137079401" ]
u846150137
p03426
python
s084470300
s596155603
1,080
951
74,708
26,012
Accepted
Accepted
11.94
I=lambda:list(map(int,input().split())) h,w,d=I() H={} W={} for i in range(1,h+1): for j,k in enumerate(I(),1): H[k],W[k]=i,j x=1+h*w s=[0 for _ in range(x)] for i in range(d+1,x): s[i]=s[i-d]+abs(H[i]-H[i-d])+abs(W[i]-W[i-d]) for _ in range(int(eval(input()))): a,b=I() print((s[b]-s[a]))
I=lambda:list(map(int,input().split())) h,w,d=I() H={} W={} for i in range(1,h+1): for j,k in enumerate(I(),1): H[k],W[k]=i,j x=1+h*w s=[0 for _ in [0]*x] for i in range(d+1,x): s[i]=s[i-d]+abs(H[i]-H[i-d])+abs(W[i]-W[i-d]) for _ in [0]*int(eval(input())): a,b=I() print((s[b]-s[a]))
15
15
302
296
I = lambda: list(map(int, input().split())) h, w, d = I() H = {} W = {} for i in range(1, h + 1): for j, k in enumerate(I(), 1): H[k], W[k] = i, j x = 1 + h * w s = [0 for _ in range(x)] for i in range(d + 1, x): s[i] = s[i - d] + abs(H[i] - H[i - d]) + abs(W[i] - W[i - d]) for _ in range(int(eval(input()))): a, b = I() print((s[b] - s[a]))
I = lambda: list(map(int, input().split())) h, w, d = I() H = {} W = {} for i in range(1, h + 1): for j, k in enumerate(I(), 1): H[k], W[k] = i, j x = 1 + h * w s = [0 for _ in [0] * x] for i in range(d + 1, x): s[i] = s[i - d] + abs(H[i] - H[i - d]) + abs(W[i] - W[i - d]) for _ in [0] * int(eval(input())): a, b = I() print((s[b] - s[a]))
false
0
[ "-s = [0 for _ in range(x)]", "+s = [0 for _ in [0] * x]", "-for _ in range(int(eval(input()))):", "+for _ in [0] * int(eval(input())):" ]
false
0.090342
0.040881
2.20985
[ "s084470300", "s596155603" ]
u028973125
p03476
python
s520393714
s008885689
1,403
192
8,380
18,700
Accepted
Accepted
86.32
import sys import math def eratosthenes(limit): A = [i for i in range(2, limit+1)] P = [] time = 0 while True: prime = min(A) if prime > math.sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return set(P) max_n = 10**5 primes = eratosthenes(max_n) # print(primes) acum_like_n = [0] * (max_n+1) for i in range(1, max_n + 1): if i in primes and (i+1)//2 in primes: acum_like_n[i] = acum_like_n[i-1] + 1 else: acum_like_n[i] = acum_like_n[i-1] # print(acum_like_n) Q = int(sys.stdin.readline().strip()) for _ in range(Q): l, r = list(map(int, sys.stdin.readline().strip().split())) print((acum_like_n[r] - acum_like_n[l-1]))
import sys input = sys.stdin.readline Q = int(eval(input())) primes = set() not_p = set() for i in range(2, 10**5 + 1): # for i in range(2, 10 + 1): if i not in not_p: primes.add(i) for j in range(i+i, 10**5+1, i): # for j in range(i+i, 10+1, i): not_p.add(j) # print(primes) # print(not_p) acum = [0 for _ in range(10**5+1)] for i in range(3, 10**5+1, 2): # for i in range(3, 10, 2): if i in primes and ((i+1) // 2) in primes: # print(i, "like2017") acum[i] += 1 acum[i] += acum[i-2] # print(acum[:10]) for _ in range(Q): l, r = list(map(int, input().split())) print((acum[r] - acum[l - 2]))
45
30
921
684
import sys import math def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] time = 0 while True: prime = min(A) if prime > math.sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return set(P) max_n = 10**5 primes = eratosthenes(max_n) # print(primes) acum_like_n = [0] * (max_n + 1) for i in range(1, max_n + 1): if i in primes and (i + 1) // 2 in primes: acum_like_n[i] = acum_like_n[i - 1] + 1 else: acum_like_n[i] = acum_like_n[i - 1] # print(acum_like_n) Q = int(sys.stdin.readline().strip()) for _ in range(Q): l, r = list(map(int, sys.stdin.readline().strip().split())) print((acum_like_n[r] - acum_like_n[l - 1]))
import sys input = sys.stdin.readline Q = int(eval(input())) primes = set() not_p = set() for i in range(2, 10**5 + 1): # for i in range(2, 10 + 1): if i not in not_p: primes.add(i) for j in range(i + i, 10**5 + 1, i): # for j in range(i+i, 10+1, i): not_p.add(j) # print(primes) # print(not_p) acum = [0 for _ in range(10**5 + 1)] for i in range(3, 10**5 + 1, 2): # for i in range(3, 10, 2): if i in primes and ((i + 1) // 2) in primes: # print(i, "like2017") acum[i] += 1 acum[i] += acum[i - 2] # print(acum[:10]) for _ in range(Q): l, r = list(map(int, input().split())) print((acum[r] - acum[l - 2]))
false
33.333333
[ "-import math", "-", "-def eratosthenes(limit):", "- A = [i for i in range(2, limit + 1)]", "- P = []", "- time = 0", "- while True:", "- prime = min(A)", "- if prime > math.sqrt(limit):", "- break", "- P.append(prime)", "- i = 0", "- while i < len(A):", "- if A[i] % prime == 0:", "- A.pop(i)", "- continue", "- i += 1", "- for a in A:", "- P.append(a)", "- return set(P)", "-", "-", "-max_n = 10**5", "-primes = eratosthenes(max_n)", "+input = sys.stdin.readline", "+Q = int(eval(input()))", "+primes = set()", "+not_p = set()", "+for i in range(2, 10**5 + 1):", "+ # for i in range(2, 10 + 1):", "+ if i not in not_p:", "+ primes.add(i)", "+ for j in range(i + i, 10**5 + 1, i):", "+ # for j in range(i+i, 10+1, i):", "+ not_p.add(j)", "-acum_like_n = [0] * (max_n + 1)", "-for i in range(1, max_n + 1):", "- if i in primes and (i + 1) // 2 in primes:", "- acum_like_n[i] = acum_like_n[i - 1] + 1", "- else:", "- acum_like_n[i] = acum_like_n[i - 1]", "-# print(acum_like_n)", "-Q = int(sys.stdin.readline().strip())", "+# print(not_p)", "+acum = [0 for _ in range(10**5 + 1)]", "+for i in range(3, 10**5 + 1, 2):", "+ # for i in range(3, 10, 2):", "+ if i in primes and ((i + 1) // 2) in primes:", "+ # print(i, \"like2017\")", "+ acum[i] += 1", "+ acum[i] += acum[i - 2]", "+# print(acum[:10])", "- l, r = list(map(int, sys.stdin.readline().strip().split()))", "- print((acum_like_n[r] - acum_like_n[l - 1]))", "+ l, r = list(map(int, input().split()))", "+ print((acum[r] - acum[l - 2]))" ]
false
1.367667
0.120211
11.377241
[ "s520393714", "s008885689" ]
u757030836
p03814
python
s015106448
s958122528
101
41
3,512
3,516
Accepted
Accepted
59.41
s = eval(input()) id_a = len(s) id_z = 0 for i in range(len(s)): if s[i] == 'A': id_a = min(id_a, i) if s[i] == 'Z': id_z = max(id_z, i) print((id_z - id_a + 1))
s =eval(input()) A=0 Z=0 for i in range(len(s)): if s[i] =="A": A +=(i+1) break for j in range(len(s)): if s[-(j+1)] =="Z": Z +=len(s)-j break print((Z-A+1))
11
16
182
196
s = eval(input()) id_a = len(s) id_z = 0 for i in range(len(s)): if s[i] == "A": id_a = min(id_a, i) if s[i] == "Z": id_z = max(id_z, i) print((id_z - id_a + 1))
s = eval(input()) A = 0 Z = 0 for i in range(len(s)): if s[i] == "A": A += i + 1 break for j in range(len(s)): if s[-(j + 1)] == "Z": Z += len(s) - j break print((Z - A + 1))
false
31.25
[ "-id_a = len(s)", "-id_z = 0", "+A = 0", "+Z = 0", "- id_a = min(id_a, i)", "- if s[i] == \"Z\":", "- id_z = max(id_z, i)", "-print((id_z - id_a + 1))", "+ A += i + 1", "+ break", "+for j in range(len(s)):", "+ if s[-(j + 1)] == \"Z\":", "+ Z += len(s) - j", "+ break", "+print((Z - A + 1))" ]
false
0.035847
0.035823
1.000673
[ "s015106448", "s958122528" ]
u142415823
p03435
python
s620915881
s267167388
1,688
18
3,064
3,064
Accepted
Accepted
98.93
def confirm(a, b, c): for i in range(3): for j in range(3): if a[i] + b[j] != c[i][j]: return False return True def main(): c = [list(map(int, input().split())) for i in range(3)] for a1 in range(101): for a2 in range(101): for a3 in range(101): a = (a1, a2, a3) b = (c[0][0] - a1, c[0][1] - a1, c[0][2] - a1) if confirm(a, b, c): return 'Yes' return 'No' if __name__ == '__main__': ans = main() print(ans)
def main(): c = [list(map(int, input().split())) for i in range(3)] for x in range(101): b = (c[0][0] - x, c[0][1] - x, c[0][2] - x) a = (x, c[1][0] - b[0], c[2][0] - b[0]) flag = True for i in (1, 2): for j in (1, 2): if a[i] + b[j] != c[i][j]: flag = False if flag: return 'Yes' return 'No' if __name__ == "__main__": print((main()))
24
17
587
470
def confirm(a, b, c): for i in range(3): for j in range(3): if a[i] + b[j] != c[i][j]: return False return True def main(): c = [list(map(int, input().split())) for i in range(3)] for a1 in range(101): for a2 in range(101): for a3 in range(101): a = (a1, a2, a3) b = (c[0][0] - a1, c[0][1] - a1, c[0][2] - a1) if confirm(a, b, c): return "Yes" return "No" if __name__ == "__main__": ans = main() print(ans)
def main(): c = [list(map(int, input().split())) for i in range(3)] for x in range(101): b = (c[0][0] - x, c[0][1] - x, c[0][2] - x) a = (x, c[1][0] - b[0], c[2][0] - b[0]) flag = True for i in (1, 2): for j in (1, 2): if a[i] + b[j] != c[i][j]: flag = False if flag: return "Yes" return "No" if __name__ == "__main__": print((main()))
false
29.166667
[ "-def confirm(a, b, c):", "- for i in range(3):", "- for j in range(3):", "- if a[i] + b[j] != c[i][j]:", "- return False", "- return True", "-", "-", "- for a1 in range(101):", "- for a2 in range(101):", "- for a3 in range(101):", "- a = (a1, a2, a3)", "- b = (c[0][0] - a1, c[0][1] - a1, c[0][2] - a1)", "- if confirm(a, b, c):", "- return \"Yes\"", "+ for x in range(101):", "+ b = (c[0][0] - x, c[0][1] - x, c[0][2] - x)", "+ a = (x, c[1][0] - b[0], c[2][0] - b[0])", "+ flag = True", "+ for i in (1, 2):", "+ for j in (1, 2):", "+ if a[i] + b[j] != c[i][j]:", "+ flag = False", "+ if flag:", "+ return \"Yes\"", "- ans = main()", "- print(ans)", "+ print((main()))" ]
false
0.005982
0.048508
0.123318
[ "s620915881", "s267167388" ]
u270681687
p03370
python
s553373994
s582554251
36
19
3,060
3,060
Accepted
Accepted
47.22
n, x = list(map(int, input().split())) m = [] for i in range(n): m.append(int(eval(input()))) count = 0 a = min(m) s = sum(m) x -= s count += n while x >= a: x -= a count += 1 print(count)
n, x = list(map(int, input().split())) m = [int(eval(input())) for _ in range(n)] x -= sum(m) count = n mincost = 10**5 for i in range(n): mincost = min(mincost, m[i]) count += x // mincost print(count)
16
12
206
208
n, x = list(map(int, input().split())) m = [] for i in range(n): m.append(int(eval(input()))) count = 0 a = min(m) s = sum(m) x -= s count += n while x >= a: x -= a count += 1 print(count)
n, x = list(map(int, input().split())) m = [int(eval(input())) for _ in range(n)] x -= sum(m) count = n mincost = 10**5 for i in range(n): mincost = min(mincost, m[i]) count += x // mincost print(count)
false
25
[ "-m = []", "+m = [int(eval(input())) for _ in range(n)]", "+x -= sum(m)", "+count = n", "+mincost = 10**5", "- m.append(int(eval(input())))", "-count = 0", "-a = min(m)", "-s = sum(m)", "-x -= s", "-count += n", "-while x >= a:", "- x -= a", "- count += 1", "+ mincost = min(mincost, m[i])", "+count += x // mincost" ]
false
0.037397
0.055465
0.67425
[ "s553373994", "s582554251" ]
u227082700
p02616
python
s517077528
s689779685
490
163
109,500
31,732
Accepted
Accepted
66.73
mod=10**9+7 n,k=map(int,input().split()) a=list(map(int,input().split())) if max(a)<0: if k%2:a.sort(reverse=1) else:a.sort() ans=1 for i in a[:k]:ans=(ans*i)%mod exit(print(ans)) if n==k: ans=1 for i in a:ans=(ans*i)%mod exit(print(ans)) p=[(0,0)] m=[(0,0)] for i in a: if i<0:m.append((-i,1)) else:p.append((i,0)) pp=mm=None p.sort() m.sort() oe=0 ans=1 for i in range(k): if p[-1][0]>m[-1][0]: t,f=p.pop() pp=t else: t,f=m.pop() mm=t ans=(ans*t)%mod if ans==0:exit(print(0)) oe^=f if oe: if mm==None: ans=(ans*pow(pp,mod-2,mod)*m[-1][0])%mod elif pp==None: ans=(ans*pow(mm,mod-2,mod)*p[-1][0])%mod elif pp*p[-1][0]>mm*m[-1][0]: ans=(ans*pow(mm,mod-2,mod)*p[-1][0])%mod else: ans=(ans*pow(pp,mod-2,mod)*m[-1][0])%mod print(ans)
from itertools import combinations mod=10**9+7 def solve(n,k,a): if min(a)>0: ans=1 a.sort(reverse=1) for i in a[:k]: ans*=i ans%=mod return ans if max(a)<0: if k%2==0: a.sort() ans=1 for i in a[:k]: ans*=i ans%=mod return ans else: a.sort(reverse=1) ans=1 for i in a[:k]: ans*=i ans%=mod return ans if n==k: ans=1 for i in a: ans*=i ans%=mod return ans if k==1: return max(a) if n-k==1: ans=1 if a.count(0)>1:return 0 p=[] m=[] for i in a: if i>0:p.append(i) elif i<0:m.append(i) if 0 in a: if len(m)%2==0: for i in a: if i==0:continue ans=(ans*i)%mod else:ans=0 else: if len(m)%2==0: for i in sorted(p)[1:]+m:ans=(ans*i)%mod else: for i in p+sorted(m)[:-1]:ans=(ans*i)%mod return ans ans=1 p=[] m=[] for i in a: if i<0:m.append(i) elif i>=0:p.append(i) p.sort() m.sort(reverse=1) while k>1: if k<=5: if len(p)>=10:p=p[-10:] if len(m)>=10:m=m[-10:] ans*=solve2(len(p)+len(m),k,m+p) ans%=mod k=0 break if len(p)<2: ans*=m.pop()*m.pop() k-=2 elif len(m)<2: ans*=p.pop()*p.pop() k-=2 elif m[-1]*m[-2]>p[-1]*p[-2]: ans*=m.pop()*m.pop() k-=2 else: ans*=p.pop()*p.pop() k-=2 ans%=mod if k: ans*=p.pop() return ans def solve2(n,k,a): ans=-10**20 for c in combinations(list(range(n)),k): anss=1 for i in c:anss*=a[i] ans=max(ans,anss) return ans%mod n,k=list(map(int,input().split())) a=list(map(int,input().split())) print((solve(n,k,a)))
43
100
842
1,845
mod = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) if max(a) < 0: if k % 2: a.sort(reverse=1) else: a.sort() ans = 1 for i in a[:k]: ans = (ans * i) % mod exit(print(ans)) if n == k: ans = 1 for i in a: ans = (ans * i) % mod exit(print(ans)) p = [(0, 0)] m = [(0, 0)] for i in a: if i < 0: m.append((-i, 1)) else: p.append((i, 0)) pp = mm = None p.sort() m.sort() oe = 0 ans = 1 for i in range(k): if p[-1][0] > m[-1][0]: t, f = p.pop() pp = t else: t, f = m.pop() mm = t ans = (ans * t) % mod if ans == 0: exit(print(0)) oe ^= f if oe: if mm == None: ans = (ans * pow(pp, mod - 2, mod) * m[-1][0]) % mod elif pp == None: ans = (ans * pow(mm, mod - 2, mod) * p[-1][0]) % mod elif pp * p[-1][0] > mm * m[-1][0]: ans = (ans * pow(mm, mod - 2, mod) * p[-1][0]) % mod else: ans = (ans * pow(pp, mod - 2, mod) * m[-1][0]) % mod print(ans)
from itertools import combinations mod = 10**9 + 7 def solve(n, k, a): if min(a) > 0: ans = 1 a.sort(reverse=1) for i in a[:k]: ans *= i ans %= mod return ans if max(a) < 0: if k % 2 == 0: a.sort() ans = 1 for i in a[:k]: ans *= i ans %= mod return ans else: a.sort(reverse=1) ans = 1 for i in a[:k]: ans *= i ans %= mod return ans if n == k: ans = 1 for i in a: ans *= i ans %= mod return ans if k == 1: return max(a) if n - k == 1: ans = 1 if a.count(0) > 1: return 0 p = [] m = [] for i in a: if i > 0: p.append(i) elif i < 0: m.append(i) if 0 in a: if len(m) % 2 == 0: for i in a: if i == 0: continue ans = (ans * i) % mod else: ans = 0 else: if len(m) % 2 == 0: for i in sorted(p)[1:] + m: ans = (ans * i) % mod else: for i in p + sorted(m)[:-1]: ans = (ans * i) % mod return ans ans = 1 p = [] m = [] for i in a: if i < 0: m.append(i) elif i >= 0: p.append(i) p.sort() m.sort(reverse=1) while k > 1: if k <= 5: if len(p) >= 10: p = p[-10:] if len(m) >= 10: m = m[-10:] ans *= solve2(len(p) + len(m), k, m + p) ans %= mod k = 0 break if len(p) < 2: ans *= m.pop() * m.pop() k -= 2 elif len(m) < 2: ans *= p.pop() * p.pop() k -= 2 elif m[-1] * m[-2] > p[-1] * p[-2]: ans *= m.pop() * m.pop() k -= 2 else: ans *= p.pop() * p.pop() k -= 2 ans %= mod if k: ans *= p.pop() return ans def solve2(n, k, a): ans = -(10**20) for c in combinations(list(range(n)), k): anss = 1 for i in c: anss *= a[i] ans = max(ans, anss) return ans % mod n, k = list(map(int, input().split())) a = list(map(int, input().split())) print((solve(n, k, a)))
false
57
[ "+from itertools import combinations", "+", "-n, k = map(int, input().split())", "+", "+", "+def solve(n, k, a):", "+ if min(a) > 0:", "+ ans = 1", "+ a.sort(reverse=1)", "+ for i in a[:k]:", "+ ans *= i", "+ ans %= mod", "+ return ans", "+ if max(a) < 0:", "+ if k % 2 == 0:", "+ a.sort()", "+ ans = 1", "+ for i in a[:k]:", "+ ans *= i", "+ ans %= mod", "+ return ans", "+ else:", "+ a.sort(reverse=1)", "+ ans = 1", "+ for i in a[:k]:", "+ ans *= i", "+ ans %= mod", "+ return ans", "+ if n == k:", "+ ans = 1", "+ for i in a:", "+ ans *= i", "+ ans %= mod", "+ return ans", "+ if k == 1:", "+ return max(a)", "+ if n - k == 1:", "+ ans = 1", "+ if a.count(0) > 1:", "+ return 0", "+ p = []", "+ m = []", "+ for i in a:", "+ if i > 0:", "+ p.append(i)", "+ elif i < 0:", "+ m.append(i)", "+ if 0 in a:", "+ if len(m) % 2 == 0:", "+ for i in a:", "+ if i == 0:", "+ continue", "+ ans = (ans * i) % mod", "+ else:", "+ ans = 0", "+ else:", "+ if len(m) % 2 == 0:", "+ for i in sorted(p)[1:] + m:", "+ ans = (ans * i) % mod", "+ else:", "+ for i in p + sorted(m)[:-1]:", "+ ans = (ans * i) % mod", "+ return ans", "+ ans = 1", "+ p = []", "+ m = []", "+ for i in a:", "+ if i < 0:", "+ m.append(i)", "+ elif i >= 0:", "+ p.append(i)", "+ p.sort()", "+ m.sort(reverse=1)", "+ while k > 1:", "+ if k <= 5:", "+ if len(p) >= 10:", "+ p = p[-10:]", "+ if len(m) >= 10:", "+ m = m[-10:]", "+ ans *= solve2(len(p) + len(m), k, m + p)", "+ ans %= mod", "+ k = 0", "+ break", "+ if len(p) < 2:", "+ ans *= m.pop() * m.pop()", "+ k -= 2", "+ elif len(m) < 2:", "+ ans *= p.pop() * p.pop()", "+ k -= 2", "+ elif m[-1] * m[-2] > p[-1] * p[-2]:", "+ ans *= m.pop() * m.pop()", "+ k -= 2", "+ else:", "+ ans *= p.pop() * p.pop()", "+ k -= 2", "+ ans %= mod", "+ if k:", "+ ans *= p.pop()", "+ return ans", "+", "+", "+def solve2(n, k, a):", "+ ans = -(10**20)", "+ for c in combinations(list(range(n)), k):", "+ anss = 1", "+ for i in c:", "+ anss *= a[i]", "+ ans = max(ans, anss)", "+ return ans % mod", "+", "+", "+n, k = list(map(int, input().split()))", "-if max(a) < 0:", "- if k % 2:", "- a.sort(reverse=1)", "- else:", "- a.sort()", "- ans = 1", "- for i in a[:k]:", "- ans = (ans * i) % mod", "- exit(print(ans))", "-if n == k:", "- ans = 1", "- for i in a:", "- ans = (ans * i) % mod", "- exit(print(ans))", "-p = [(0, 0)]", "-m = [(0, 0)]", "-for i in a:", "- if i < 0:", "- m.append((-i, 1))", "- else:", "- p.append((i, 0))", "-pp = mm = None", "-p.sort()", "-m.sort()", "-oe = 0", "-ans = 1", "-for i in range(k):", "- if p[-1][0] > m[-1][0]:", "- t, f = p.pop()", "- pp = t", "- else:", "- t, f = m.pop()", "- mm = t", "- ans = (ans * t) % mod", "- if ans == 0:", "- exit(print(0))", "- oe ^= f", "-if oe:", "- if mm == None:", "- ans = (ans * pow(pp, mod - 2, mod) * m[-1][0]) % mod", "- elif pp == None:", "- ans = (ans * pow(mm, mod - 2, mod) * p[-1][0]) % mod", "- elif pp * p[-1][0] > mm * m[-1][0]:", "- ans = (ans * pow(mm, mod - 2, mod) * p[-1][0]) % mod", "- else:", "- ans = (ans * pow(pp, mod - 2, mod) * m[-1][0]) % mod", "-print(ans)", "+print((solve(n, k, a)))" ]
false
0.159617
0.045711
3.491837
[ "s517077528", "s689779685" ]
u143509139
p03196
python
s560154617
s170337298
324
94
3,316
3,316
Accepted
Accepted
70.99
n, p = list(map(int, input().split())) if n == 3 and p == 24: print((2)) exit() for i in range(int((p ** (1 / n)) // 1) + 1, 1, -1): if i == 2 and n ** 3 > p: print((1)) break if p % (i ** n) == 0: print(i) break else: print((1))
from collections import Counter def factorize(n): a = 2 fct = [] while a * a <= n: while n % a == 0: n //= a fct.append(a) a += 1 if n > 1: fct.append(n) return fct N, P = list(map(int, input().split())) f = factorize(P) c = Counter(f) ans = 1 for k, v in list(c.items()): ans *= k ** (v // N) print(ans)
13
23
282
390
n, p = list(map(int, input().split())) if n == 3 and p == 24: print((2)) exit() for i in range(int((p ** (1 / n)) // 1) + 1, 1, -1): if i == 2 and n**3 > p: print((1)) break if p % (i**n) == 0: print(i) break else: print((1))
from collections import Counter def factorize(n): a = 2 fct = [] while a * a <= n: while n % a == 0: n //= a fct.append(a) a += 1 if n > 1: fct.append(n) return fct N, P = list(map(int, input().split())) f = factorize(P) c = Counter(f) ans = 1 for k, v in list(c.items()): ans *= k ** (v // N) print(ans)
false
43.478261
[ "-n, p = list(map(int, input().split()))", "-if n == 3 and p == 24:", "- print((2))", "- exit()", "-for i in range(int((p ** (1 / n)) // 1) + 1, 1, -1):", "- if i == 2 and n**3 > p:", "- print((1))", "- break", "- if p % (i**n) == 0:", "- print(i)", "- break", "-else:", "- print((1))", "+from collections import Counter", "+", "+", "+def factorize(n):", "+ a = 2", "+ fct = []", "+ while a * a <= n:", "+ while n % a == 0:", "+ n //= a", "+ fct.append(a)", "+ a += 1", "+ if n > 1:", "+ fct.append(n)", "+ return fct", "+", "+", "+N, P = list(map(int, input().split()))", "+f = factorize(P)", "+c = Counter(f)", "+ans = 1", "+for k, v in list(c.items()):", "+ ans *= k ** (v // N)", "+print(ans)" ]
false
0.039542
0.044167
0.895299
[ "s560154617", "s170337298" ]
u595289165
p02831
python
s910167598
s767058696
37
18
5,088
2,940
Accepted
Accepted
51.35
import fractions a, b = list(map(int, input().split())) def lcm(x, y): return x*y//fractions.gcd(x, y) print((lcm(a, b)))
def gcd(x, y): if x == 0: return y else: return gcd(y % x, x) def lcm(x, y): return x * y // gcd(x, y) a, b = list(map(int, input().split())) print((lcm(a, b)))
9
15
129
201
import fractions a, b = list(map(int, input().split())) def lcm(x, y): return x * y // fractions.gcd(x, y) print((lcm(a, b)))
def gcd(x, y): if x == 0: return y else: return gcd(y % x, x) def lcm(x, y): return x * y // gcd(x, y) a, b = list(map(int, input().split())) print((lcm(a, b)))
false
40
[ "-import fractions", "-", "-a, b = list(map(int, input().split()))", "+def gcd(x, y):", "+ if x == 0:", "+ return y", "+ else:", "+ return gcd(y % x, x)", "- return x * y // fractions.gcd(x, y)", "+ return x * y // gcd(x, y)", "+a, b = list(map(int, input().split()))" ]
false
0.18801
0.040093
4.689388
[ "s910167598", "s767058696" ]
u332385682
p03806
python
s952826853
s531653404
183
108
5,752
3,188
Accepted
Accepted
40.98
def solve(): N, Ma, Mb = list(map(int, input().split())) a, b, c = [], [], [] for i in range(N): ai, bi, ci = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) nvals = 99 * N * 2 + 1 inf = 40 * 100 + 1 dp = [[inf] * nvals for i in range(N)] for i in range(N): v = Mb * a[i] - Ma * b[i] if i == 0: dp[i][v] = c[i] continue for j in range(-99 * N, 99 * N + 1): if -99 * N <= j - v <= 99 * N: dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i]) dp[i][v] = min(dp[i][v], c[i]) ans = dp[N - 1][0] if ans < inf: print(ans) else: print((-1)) if __name__ == '__main__': solve()
def solve(): N, Ma, Mb = list(map(int, input().split())) a, b, c = [], [], [] for i in range(N): ai, bi, ci = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) nvals = 99 * N * 2 + 1 inf = 40 * 100 + 1 dp = [inf] * nvals for i in range(N): v = Mb * a[i] - Ma * b[i] if i == 0: dp[v] = c[i] continue if v > 0: for j in range(99 * N, -99 * N + v - 1, -1): dp[j] = min(dp[j], dp[j - v] + c[i]) else: for j in range(-99 * N, 99 * N + v + 1): dp[j] = min(dp[j], dp[j - v] + c[i]) dp[v] = min(dp[v], c[i]) ans = dp[0] if ans < inf: print(ans) else: print((-1)) if __name__ == '__main__': solve()
37
40
800
857
def solve(): N, Ma, Mb = list(map(int, input().split())) a, b, c = [], [], [] for i in range(N): ai, bi, ci = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) nvals = 99 * N * 2 + 1 inf = 40 * 100 + 1 dp = [[inf] * nvals for i in range(N)] for i in range(N): v = Mb * a[i] - Ma * b[i] if i == 0: dp[i][v] = c[i] continue for j in range(-99 * N, 99 * N + 1): if -99 * N <= j - v <= 99 * N: dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i]) dp[i][v] = min(dp[i][v], c[i]) ans = dp[N - 1][0] if ans < inf: print(ans) else: print((-1)) if __name__ == "__main__": solve()
def solve(): N, Ma, Mb = list(map(int, input().split())) a, b, c = [], [], [] for i in range(N): ai, bi, ci = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) nvals = 99 * N * 2 + 1 inf = 40 * 100 + 1 dp = [inf] * nvals for i in range(N): v = Mb * a[i] - Ma * b[i] if i == 0: dp[v] = c[i] continue if v > 0: for j in range(99 * N, -99 * N + v - 1, -1): dp[j] = min(dp[j], dp[j - v] + c[i]) else: for j in range(-99 * N, 99 * N + v + 1): dp[j] = min(dp[j], dp[j - v] + c[i]) dp[v] = min(dp[v], c[i]) ans = dp[0] if ans < inf: print(ans) else: print((-1)) if __name__ == "__main__": solve()
false
7.5
[ "- dp = [[inf] * nvals for i in range(N)]", "+ dp = [inf] * nvals", "- dp[i][v] = c[i]", "+ dp[v] = c[i]", "- for j in range(-99 * N, 99 * N + 1):", "- if -99 * N <= j - v <= 99 * N:", "- dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i])", "- dp[i][v] = min(dp[i][v], c[i])", "- ans = dp[N - 1][0]", "+ if v > 0:", "+ for j in range(99 * N, -99 * N + v - 1, -1):", "+ dp[j] = min(dp[j], dp[j - v] + c[i])", "+ else:", "+ for j in range(-99 * N, 99 * N + v + 1):", "+ dp[j] = min(dp[j], dp[j - v] + c[i])", "+ dp[v] = min(dp[v], c[i])", "+ ans = dp[0]" ]
false
0.04935
0.048743
1.012466
[ "s952826853", "s531653404" ]
u488127128
p03574
python
s463068554
s604395464
28
24
3,064
3,444
Accepted
Accepted
14.29
h,w = list(map(int, input().split())) S = [eval(input()) for _ in range(h)] for r in range(h): l = '' for c in range(w): if S[r][c] == '#': l += '#' else: l += str(sum([x[max(0,c-1):min(c+2,w)].count('#') for x in S[max(0,r-1):min(r+2,h)]])) print(l)
h,w = map(int, input().split()) S = ['.' + input() + '.' for _ in range(h)] S.insert(0,'.'*(w+2)) S.append('.'*(w+2)) for r in range(1, h+1): for c in range(1, w+1): if S[r][c] == '#': print('#', end='') continue else: count = 0 count += S[r-1][c-1:c+2].count('#') count += S[r][c-1:c+2].count('#') count += S[r+1][c-1:c+2].count('#') print(count, end='') print()
10
17
299
488
h, w = list(map(int, input().split())) S = [eval(input()) for _ in range(h)] for r in range(h): l = "" for c in range(w): if S[r][c] == "#": l += "#" else: l += str( sum( [ x[max(0, c - 1) : min(c + 2, w)].count("#") for x in S[max(0, r - 1) : min(r + 2, h)] ] ) ) print(l)
h, w = map(int, input().split()) S = ["." + input() + "." for _ in range(h)] S.insert(0, "." * (w + 2)) S.append("." * (w + 2)) for r in range(1, h + 1): for c in range(1, w + 1): if S[r][c] == "#": print("#", end="") continue else: count = 0 count += S[r - 1][c - 1 : c + 2].count("#") count += S[r][c - 1 : c + 2].count("#") count += S[r + 1][c - 1 : c + 2].count("#") print(count, end="") print()
false
41.176471
[ "-h, w = list(map(int, input().split()))", "-S = [eval(input()) for _ in range(h)]", "-for r in range(h):", "- l = \"\"", "- for c in range(w):", "+h, w = map(int, input().split())", "+S = [\".\" + input() + \".\" for _ in range(h)]", "+S.insert(0, \".\" * (w + 2))", "+S.append(\".\" * (w + 2))", "+for r in range(1, h + 1):", "+ for c in range(1, w + 1):", "- l += \"#\"", "+ print(\"#\", end=\"\")", "+ continue", "- l += str(", "- sum(", "- [", "- x[max(0, c - 1) : min(c + 2, w)].count(\"#\")", "- for x in S[max(0, r - 1) : min(r + 2, h)]", "- ]", "- )", "- )", "- print(l)", "+ count = 0", "+ count += S[r - 1][c - 1 : c + 2].count(\"#\")", "+ count += S[r][c - 1 : c + 2].count(\"#\")", "+ count += S[r + 1][c - 1 : c + 2].count(\"#\")", "+ print(count, end=\"\")", "+ print()" ]
false
0.048272
0.084593
0.570636
[ "s463068554", "s604395464" ]
u504469481
p03999
python
s103930863
s879347696
174
21
39,024
4,136
Accepted
Accepted
87.93
def dfs(i, f): if i == n - 1: return sum(list(map(int, f.split("+")))) return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1]) s = eval(input()) n = len(s) print((dfs(0, s[0])))
# -*- coding: utf-8 -*- S = eval(input()) n = len(S) def dfs(i, f): # 文末?の最後まで行ったらreturn if i == n - 1: return f # +を入れるか入れないか return dfs(i + 1, f + S[i + 1]) + "+" + dfs(i + 1, f + "+" + S[i + 1]) def main(): print((eval(dfs(0,S[0])))) if __name__ == '__main__': main()
9
17
204
314
def dfs(i, f): if i == n - 1: return sum(list(map(int, f.split("+")))) return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1]) s = eval(input()) n = len(s) print((dfs(0, s[0])))
# -*- coding: utf-8 -*- S = eval(input()) n = len(S) def dfs(i, f): # 文末?の最後まで行ったらreturn if i == n - 1: return f # +を入れるか入れないか return dfs(i + 1, f + S[i + 1]) + "+" + dfs(i + 1, f + "+" + S[i + 1]) def main(): print((eval(dfs(0, S[0])))) if __name__ == "__main__": main()
false
47.058824
[ "-def dfs(i, f):", "- if i == n - 1:", "- return sum(list(map(int, f.split(\"+\"))))", "- return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + \"+\" + s[i + 1])", "+# -*- coding: utf-8 -*-", "+S = eval(input())", "+n = len(S)", "-s = eval(input())", "-n = len(s)", "-print((dfs(0, s[0])))", "+def dfs(i, f):", "+ # 文末?の最後まで行ったらreturn", "+ if i == n - 1:", "+ return f", "+ # +を入れるか入れないか", "+ return dfs(i + 1, f + S[i + 1]) + \"+\" + dfs(i + 1, f + \"+\" + S[i + 1])", "+", "+", "+def main():", "+ print((eval(dfs(0, S[0]))))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.042929
0.043075
0.9966
[ "s103930863", "s879347696" ]
u652656291
p03455
python
s791354667
s011103213
20
17
3,060
2,940
Accepted
Accepted
15
a,b = list(map(int,input().split())) if (a*b) % 2 == 0: print('Even') else: print('Odd')
a,b = list(map(int,input().split())) if a*b%2==0: print('Even') else: print('Odd')
5
5
90
85
a, b = list(map(int, input().split())) if (a * b) % 2 == 0: print("Even") else: print("Odd")
a, b = list(map(int, input().split())) if a * b % 2 == 0: print("Even") else: print("Odd")
false
0
[ "-if (a * b) % 2 == 0:", "+if a * b % 2 == 0:" ]
false
0.052598
0.051885
1.013747
[ "s791354667", "s011103213" ]
u867848444
p02726
python
s007894689
s075385466
1,645
1,187
3,444
9,296
Accepted
Accepted
27.84
n, x, y = map(int,input().split()) dis = [0] * (n - 1) for i in range(n - 1): for j in range(i + 1, n): d = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i) dis[d - 1] += 1 print(*dis, sep = '\n')
n, x, y = map(int,input().split()) cnt = [0] * (n - 1) for i in range(1, n): for j in range(i + 1, n + 1): temp1 = j - i temp2 = abs(i - x) + abs(j - y) + 1 dis = min(temp1, temp2) cnt[dis - 1] += 1 print(*cnt, sep='\n')
8
11
223
268
n, x, y = map(int, input().split()) dis = [0] * (n - 1) for i in range(n - 1): for j in range(i + 1, n): d = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i) dis[d - 1] += 1 print(*dis, sep="\n")
n, x, y = map(int, input().split()) cnt = [0] * (n - 1) for i in range(1, n): for j in range(i + 1, n + 1): temp1 = j - i temp2 = abs(i - x) + abs(j - y) + 1 dis = min(temp1, temp2) cnt[dis - 1] += 1 print(*cnt, sep="\n")
false
27.272727
[ "-dis = [0] * (n - 1)", "-for i in range(n - 1):", "- for j in range(i + 1, n):", "- d = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i)", "- dis[d - 1] += 1", "-print(*dis, sep=\"\\n\")", "+cnt = [0] * (n - 1)", "+for i in range(1, n):", "+ for j in range(i + 1, n + 1):", "+ temp1 = j - i", "+ temp2 = abs(i - x) + abs(j - y) + 1", "+ dis = min(temp1, temp2)", "+ cnt[dis - 1] += 1", "+print(*cnt, sep=\"\\n\")" ]
false
0.034645
0.035008
0.989638
[ "s007894689", "s075385466" ]
u588341295
p03651
python
s848808222
s728422605
96
88
16,336
16,844
Accepted
Accepted
8.33
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, initial=1) 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 N, K = MAP() aN =LIST() # Kがでかいのは論外 if max(aN) < K: print('IMPOSSIBLE') exit() # aN全部の最大公約数を取る base = aN[0] for i in range(1, N): base = gcd(base, aN[i]) if K % base == 0: print('POSSIBLE') else: print('IMPOSSIBLE')
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) 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 N, K = MAP() aN =LIST() # Kがでかいのは論外 if max(aN) < K: print('IMPOSSIBLE') exit() # aN全部の最大公約数を取る base = gcd_list(aN) if K % base == 0: print('POSSIBLE') else: print('IMPOSSIBLE')
45
44
1,359
1,361
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, initial=1) 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 N, K = MAP() aN = LIST() # Kがでかいのは論外 if max(aN) < K: print("IMPOSSIBLE") exit() # aN全部の最大公約数を取る base = aN[0] for i in range(1, N): base = gcd(base, aN[i]) if K % base == 0: print("POSSIBLE") else: print("IMPOSSIBLE")
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) 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 N, K = MAP() aN = LIST() # Kがでかいのは論外 if max(aN) < K: print("IMPOSSIBLE") exit() # aN全部の最大公約数を取る base = gcd_list(aN) if K % base == 0: print("POSSIBLE") else: print("IMPOSSIBLE")
false
2.222222
[ "- return reduce(lcm, nums, initial=1)", "+ return reduce(lcm, nums, 1)", "+", "+", "+def gcd_list(nums):", "+ return reduce(gcd, nums, nums[0])", "-base = aN[0]", "-for i in range(1, N):", "- base = gcd(base, aN[i])", "+base = gcd_list(aN)" ]
false
0.032262
0.037498
0.860377
[ "s848808222", "s728422605" ]
u906501980
p03359
python
s765983003
s309025306
20
18
2,940
2,940
Accepted
Accepted
10
a, b = list(map(int, input().split())) out = a if a<=b else a-1 print(out)
def main(): a, b = list(map(int, input().split())) print((a-(a>b))) if __name__ == "__main__": main()
3
6
70
115
a, b = list(map(int, input().split())) out = a if a <= b else a - 1 print(out)
def main(): a, b = list(map(int, input().split())) print((a - (a > b))) if __name__ == "__main__": main()
false
50
[ "-a, b = list(map(int, input().split()))", "-out = a if a <= b else a - 1", "-print(out)", "+def main():", "+ a, b = list(map(int, input().split()))", "+ print((a - (a > b)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045147
0.152566
0.295918
[ "s765983003", "s309025306" ]
u753803401
p04020
python
s427687527
s323756320
240
204
44,636
43,724
Accepted
Accepted
15
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip('\n')) a = [int(input().rstrip('\n')) for _ in range(n)] cnt = 0 t = 0 for v in a: if v == 0: cnt += (t // 2) t = 0 else: t += v cnt += (t // 2) print(cnt) if __name__ == '__main__': slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = int(readline()) a = [int(readline()) for _ in range(n)] c = ac = 0 for v in a: c += v if v == 0: ac += c // 2 c = 0 print((ac + c // 2)) if __name__ == '__main__': solve()
19
19
377
347
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip("\n")) a = [int(input().rstrip("\n")) for _ in range(n)] cnt = 0 t = 0 for v in a: if v == 0: cnt += t // 2 t = 0 else: t += v cnt += t // 2 print(cnt) if __name__ == "__main__": slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n = int(readline()) a = [int(readline()) for _ in range(n)] c = ac = 0 for v in a: c += v if v == 0: ac += c // 2 c = 0 print((ac + c // 2)) if __name__ == "__main__": solve()
false
0
[ "-def slove():", "- import sys", "+import sys", "- input = sys.stdin.readline", "- n = int(input().rstrip(\"\\n\"))", "- a = [int(input().rstrip(\"\\n\")) for _ in range(n)]", "- cnt = 0", "- t = 0", "+", "+def solve():", "+ readline = sys.stdin.buffer.readline", "+ mod = 10**9 + 7", "+ n = int(readline())", "+ a = [int(readline()) for _ in range(n)]", "+ c = ac = 0", "+ c += v", "- cnt += t // 2", "- t = 0", "- else:", "- t += v", "- cnt += t // 2", "- print(cnt)", "+ ac += c // 2", "+ c = 0", "+ print((ac + c // 2))", "- slove()", "+ solve()" ]
false
0.041224
0.039167
1.052515
[ "s427687527", "s323756320" ]
u281610856
p03575
python
s751805156
s712142608
343
21
19,896
3,064
Accepted
Accepted
93.88
from heapq import heappush, heappop from itertools import permutations, accumulate, combinations import math import bisect import numpy as np from collections import defaultdict, deque import sys input = sys.stdin.readline # sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # INF = float("inf") def bfs(s, n, g): que = deque([]) que.append(s) check = [-1] * n check[s] = 0 while que: u = que.popleft() for v in g[u]: if check[v] == -1: check[v] = check[u] + 1 que.append(v) if -1 in check: return True else: return False def main(): n, m = list(map(int, input().split())) g = [[] for _ in range(n)] gg = deque([]) for _ in range(m): a, b = [int(i) - 1 for i in input().split()] g[a].append(b) g[b].append(a) gg.append((a, b)) ans = 0 for i in range(m): a, b = gg.popleft() g[a].remove(b) g[b].remove(a) if bfs(0, n, g): ans += 1 g[a].append(b) g[b].append(a) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) # MOD = 10 ** 9 + 7 # INF = float("inf") def dfs(start, a, b, visited, n, graph): for node in graph[start]: if node not in visited: if (start, node) == (a, b) or (start, node) == (b, a): continue # (start, node)がなくなっている場合を考えるので,このケースはスルーする else: visited.append(node) dfs(node, a, b, visited, n, graph) if len(visited) == n: return 0 else: return 1 def main(): N, M = list(map(int, input().split())) graph = [[] for _ in range(N)] edge = [] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) edge.append((a, b)) cnt = 0 for a, b in edge: cnt += dfs(0, a, b, [], N, graph) print(cnt) if __name__ == '__main__': main()
53
39
1,185
968
from heapq import heappush, heappop from itertools import permutations, accumulate, combinations import math import bisect import numpy as np from collections import defaultdict, deque import sys input = sys.stdin.readline # sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # INF = float("inf") def bfs(s, n, g): que = deque([]) que.append(s) check = [-1] * n check[s] = 0 while que: u = que.popleft() for v in g[u]: if check[v] == -1: check[v] = check[u] + 1 que.append(v) if -1 in check: return True else: return False def main(): n, m = list(map(int, input().split())) g = [[] for _ in range(n)] gg = deque([]) for _ in range(m): a, b = [int(i) - 1 for i in input().split()] g[a].append(b) g[b].append(a) gg.append((a, b)) ans = 0 for i in range(m): a, b = gg.popleft() g[a].remove(b) g[b].remove(a) if bfs(0, n, g): ans += 1 g[a].append(b) g[b].append(a) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) # MOD = 10 ** 9 + 7 # INF = float("inf") def dfs(start, a, b, visited, n, graph): for node in graph[start]: if node not in visited: if (start, node) == (a, b) or (start, node) == (b, a): continue # (start, node)がなくなっている場合を考えるので,このケースはスルーする else: visited.append(node) dfs(node, a, b, visited, n, graph) if len(visited) == n: return 0 else: return 1 def main(): N, M = list(map(int, input().split())) graph = [[] for _ in range(N)] edge = [] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) edge.append((a, b)) cnt = 0 for a, b in edge: cnt += dfs(0, a, b, [], N, graph) print(cnt) if __name__ == "__main__": main()
false
26.415094
[ "-from heapq import heappush, heappop", "-from itertools import permutations, accumulate, combinations", "-import math", "-import bisect", "-import numpy as np", "-from collections import defaultdict, deque", "-# sys.setrecursionlimit(1000000)", "+sys.setrecursionlimit(10**6)", "-def bfs(s, n, g):", "- que = deque([])", "- que.append(s)", "- check = [-1] * n", "- check[s] = 0", "- while que:", "- u = que.popleft()", "- for v in g[u]:", "- if check[v] == -1:", "- check[v] = check[u] + 1", "- que.append(v)", "- if -1 in check:", "- return True", "+def dfs(start, a, b, visited, n, graph):", "+ for node in graph[start]:", "+ if node not in visited:", "+ if (start, node) == (a, b) or (start, node) == (b, a):", "+ continue # (start, node)がなくなっている場合を考えるので,このケースはスルーする", "+ else:", "+ visited.append(node)", "+ dfs(node, a, b, visited, n, graph)", "+ if len(visited) == n:", "+ return 0", "- return False", "+ return 1", "- n, m = list(map(int, input().split()))", "- g = [[] for _ in range(n)]", "- gg = deque([])", "- for _ in range(m):", "- a, b = [int(i) - 1 for i in input().split()]", "- g[a].append(b)", "- g[b].append(a)", "- gg.append((a, b))", "- ans = 0", "- for i in range(m):", "- a, b = gg.popleft()", "- g[a].remove(b)", "- g[b].remove(a)", "- if bfs(0, n, g):", "- ans += 1", "- g[a].append(b)", "- g[b].append(a)", "- print(ans)", "+ N, M = list(map(int, input().split()))", "+ graph = [[] for _ in range(N)]", "+ edge = []", "+ for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ graph[a].append(b)", "+ graph[b].append(a)", "+ edge.append((a, b))", "+ cnt = 0", "+ for a, b in edge:", "+ cnt += dfs(0, a, b, [], N, graph)", "+ print(cnt)" ]
false
0.068164
0.036658
1.859461
[ "s751805156", "s712142608" ]
u753803401
p03076
python
s655895292
s891516237
21
18
3,316
3,060
Accepted
Accepted
14.29
a = [] for i in range(5): b = int(eval(input())) c = b % 10 if b % 10 != 0 else 9 d = (b + 10 - 1) // 10 * 10 a.append([b, c, d]) a = sorted(a, key=lambda x: x[1], reverse=True) total = 0 for i in range(len(a)): total += a[i][2] print((total - a[i][2] + a[i][0]))
import itertools a = [int(eval(input())) for _ in range(5)] mi = 10 ** 10 for i in itertools.permutations(a, 5): t = 0 for j, v in enumerate(i): if j == 4: t += v else: t += ((v + 9) // 10 * 10) mi = min(t, mi) print(mi)
11
12
286
278
a = [] for i in range(5): b = int(eval(input())) c = b % 10 if b % 10 != 0 else 9 d = (b + 10 - 1) // 10 * 10 a.append([b, c, d]) a = sorted(a, key=lambda x: x[1], reverse=True) total = 0 for i in range(len(a)): total += a[i][2] print((total - a[i][2] + a[i][0]))
import itertools a = [int(eval(input())) for _ in range(5)] mi = 10**10 for i in itertools.permutations(a, 5): t = 0 for j, v in enumerate(i): if j == 4: t += v else: t += (v + 9) // 10 * 10 mi = min(t, mi) print(mi)
false
8.333333
[ "-a = []", "-for i in range(5):", "- b = int(eval(input()))", "- c = b % 10 if b % 10 != 0 else 9", "- d = (b + 10 - 1) // 10 * 10", "- a.append([b, c, d])", "-a = sorted(a, key=lambda x: x[1], reverse=True)", "-total = 0", "-for i in range(len(a)):", "- total += a[i][2]", "-print((total - a[i][2] + a[i][0]))", "+import itertools", "+", "+a = [int(eval(input())) for _ in range(5)]", "+mi = 10**10", "+for i in itertools.permutations(a, 5):", "+ t = 0", "+ for j, v in enumerate(i):", "+ if j == 4:", "+ t += v", "+ else:", "+ t += (v + 9) // 10 * 10", "+ mi = min(t, mi)", "+print(mi)" ]
false
0.138698
0.048624
2.852463
[ "s655895292", "s891516237" ]
u068750695
p02755
python
s077934556
s692978695
877
257
40,172
40,172
Accepted
Accepted
70.7
import math a,b=list(map(int,input().split())) flag=True for i in range(10**7): if math.floor(i*0.08)==a and math.floor(i*0.1)==b: print(i) flag=False exit() if flag: print((-1))
import math a,b=list(map(int,input().split())) flag=True for i in range(10**6): if math.floor(i*0.08)==a and math.floor(i*0.1)==b: print(i) flag=False exit() if flag: print((-1))
10
10
211
211
import math a, b = list(map(int, input().split())) flag = True for i in range(10**7): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: print(i) flag = False exit() if flag: print((-1))
import math a, b = list(map(int, input().split())) flag = True for i in range(10**6): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: print(i) flag = False exit() if flag: print((-1))
false
0
[ "-for i in range(10**7):", "+for i in range(10**6):" ]
false
0.708808
0.49857
1.421682
[ "s077934556", "s692978695" ]
u863442865
p02936
python
s109556839
s115032259
998
892
80,672
55,824
Accepted
Accepted
10.62
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) N, Q = list(map(int, input().split())) G = [set() for _ in range(N)] cnt = [0]*N visited = [0]*N for _ in range(N-1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].add(b) G[b].add(a) for _ in range(Q): node, x = list(map(int, input().split())) node -= 1 cnt[node] += x visited[0]=1 st = [0] while st: v = st.pop() for u in G[v]: if visited[u]: continue visited[u] = 1 cnt[u] += cnt[v] st.append(u) print((*cnt)) if __name__ == '__main__': main()
def main(): import sys sys.setrecursionlimit(500000) input = sys.stdin.readline N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] cnt = [0]*N visited = [0]*N for _ in range(N-1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) for i in range(Q): node, x = list(map(int, input().split())) node -= 1 cnt[node] += x visited[0]=1 st = [0] while st: v = st.pop() for u in G[v]: if visited[u]: continue visited[u] = 1 cnt[u] += cnt[v] st.append(u) print((*cnt)) if __name__ == '__main__': main()
38
36
768
709
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) N, Q = list(map(int, input().split())) G = [set() for _ in range(N)] cnt = [0] * N visited = [0] * N for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].add(b) G[b].add(a) for _ in range(Q): node, x = list(map(int, input().split())) node -= 1 cnt[node] += x visited[0] = 1 st = [0] while st: v = st.pop() for u in G[v]: if visited[u]: continue visited[u] = 1 cnt[u] += cnt[v] st.append(u) print((*cnt)) if __name__ == "__main__": main()
def main(): import sys sys.setrecursionlimit(500000) input = sys.stdin.readline N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] cnt = [0] * N visited = [0] * N for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) for i in range(Q): node, x = list(map(int, input().split())) node -= 1 cnt[node] += x visited[0] = 1 st = [0] while st: v = st.pop() for u in G[v]: if visited[u]: continue visited[u] = 1 cnt[u] += cnt[v] st.append(u) print((*cnt)) if __name__ == "__main__": main()
false
5.263158
[ "+ sys.setrecursionlimit(500000)", "- sys.setrecursionlimit(10000000)", "- G = [set() for _ in range(N)]", "+ G = [[] for _ in range(N)]", "- G[a].add(b)", "- G[b].add(a)", "- for _ in range(Q):", "+ G[a].append(b)", "+ G[b].append(a)", "+ for i in range(Q):" ]
false
0.037811
0.046751
0.808788
[ "s109556839", "s115032259" ]
u844646164
p03475
python
s598751526
s925661236
105
94
3,188
74,088
Accepted
Accepted
10.48
N = int(eval(input())) train = [list(map(int, input().split())) for _ in range(N-1)] for i in range(N-1): t = train[i][0] + train[i][1] for j in range(i+1, N-1): if train[j][1] >= t: t = train[j][1] + train[j][0] elif t % train[j][2] == 0: t += train[j][0] else: #print(t+train[j][2]-t%train[j][2]) t = t+train[j][2]-t%train[j][2] t += train[j][0] print(t) print((0))
N = int(eval(input())) csf = [list(map(int, input().split())) for _ in range(N-1)] for i in range(N-1): t = csf[i][1] t += csf[i][0] for j in range(i+1, N-1): st = csf[j][1] f = csf[j][2] t = max(st, ((t-1)//f+1)*f) t += csf[j][0] print(t) print((0))
16
16
472
310
N = int(eval(input())) train = [list(map(int, input().split())) for _ in range(N - 1)] for i in range(N - 1): t = train[i][0] + train[i][1] for j in range(i + 1, N - 1): if train[j][1] >= t: t = train[j][1] + train[j][0] elif t % train[j][2] == 0: t += train[j][0] else: # print(t+train[j][2]-t%train[j][2]) t = t + train[j][2] - t % train[j][2] t += train[j][0] print(t) print((0))
N = int(eval(input())) csf = [list(map(int, input().split())) for _ in range(N - 1)] for i in range(N - 1): t = csf[i][1] t += csf[i][0] for j in range(i + 1, N - 1): st = csf[j][1] f = csf[j][2] t = max(st, ((t - 1) // f + 1) * f) t += csf[j][0] print(t) print((0))
false
0
[ "-train = [list(map(int, input().split())) for _ in range(N - 1)]", "+csf = [list(map(int, input().split())) for _ in range(N - 1)]", "- t = train[i][0] + train[i][1]", "+ t = csf[i][1]", "+ t += csf[i][0]", "- if train[j][1] >= t:", "- t = train[j][1] + train[j][0]", "- elif t % train[j][2] == 0:", "- t += train[j][0]", "- else:", "- # print(t+train[j][2]-t%train[j][2])", "- t = t + train[j][2] - t % train[j][2]", "- t += train[j][0]", "+ st = csf[j][1]", "+ f = csf[j][2]", "+ t = max(st, ((t - 1) // f + 1) * f)", "+ t += csf[j][0]" ]
false
0.078139
0.066935
1.167388
[ "s598751526", "s925661236" ]
u621935300
p03480
python
s720651027
s617686058
45
28
5,892
4,228
Accepted
Accepted
37.78
S=input() N=len(S) TS=N for k in range(N-1): if S[k]!=S[k+1]: TS=min(TS, max(k+1, N-k-1)) print(TS)
S=input() N=len(S) c=len(S)/2 if N%2==1: cnt=c+1 for i in range(1,c+1): if S[c-i]==S[c+i]==S[c]: cnt+=1 pass else: break else: cnt=c if S[c]!=S[c-1]: print(cnt) quit() cnt+=1 for i in range(1,c): if S[c+i]==S[c-i-1]==S[c]: cnt+=1 else: break print(cnt)
8
26
113
316
S = input() N = len(S) TS = N for k in range(N - 1): if S[k] != S[k + 1]: TS = min(TS, max(k + 1, N - k - 1)) print(TS)
S = input() N = len(S) c = len(S) / 2 if N % 2 == 1: cnt = c + 1 for i in range(1, c + 1): if S[c - i] == S[c + i] == S[c]: cnt += 1 pass else: break else: cnt = c if S[c] != S[c - 1]: print(cnt) quit() cnt += 1 for i in range(1, c): if S[c + i] == S[c - i - 1] == S[c]: cnt += 1 else: break print(cnt)
false
69.230769
[ "-TS = N", "-for k in range(N - 1):", "- if S[k] != S[k + 1]:", "- TS = min(TS, max(k + 1, N - k - 1))", "-print(TS)", "+c = len(S) / 2", "+if N % 2 == 1:", "+ cnt = c + 1", "+ for i in range(1, c + 1):", "+ if S[c - i] == S[c + i] == S[c]:", "+ cnt += 1", "+ pass", "+ else:", "+ break", "+else:", "+ cnt = c", "+ if S[c] != S[c - 1]:", "+ print(cnt)", "+ quit()", "+ cnt += 1", "+ for i in range(1, c):", "+ if S[c + i] == S[c - i - 1] == S[c]:", "+ cnt += 1", "+ else:", "+ break", "+print(cnt)" ]
false
0.070272
0.043735
1.60676
[ "s720651027", "s617686058" ]
u842964692
p04045
python
s365591903
s833896221
81
51
5,692
2,940
Accepted
Accepted
37.04
from collections import deque N,K=list(map(int,input().split())) D=list(map(int,input().split())) like=list(range(1,10)) dislike0=False for s in D: if s==0: dislike0=True else: like.remove(s) like.sort() q=deque(like) if dislike0==False: like.insert(0,0) while q: num=q.popleft() if num>=N: print(num) exit() for i in range(len(like)): q.append((int(str(num)+str(like[i]))))
N,K=list(map(int,input().split())) D=list(input().split()) while True: for s in str(N): if s in D: N+=1 break else: print(N) exit()
27
11
464
192
from collections import deque N, K = list(map(int, input().split())) D = list(map(int, input().split())) like = list(range(1, 10)) dislike0 = False for s in D: if s == 0: dislike0 = True else: like.remove(s) like.sort() q = deque(like) if dislike0 == False: like.insert(0, 0) while q: num = q.popleft() if num >= N: print(num) exit() for i in range(len(like)): q.append((int(str(num) + str(like[i]))))
N, K = list(map(int, input().split())) D = list(input().split()) while True: for s in str(N): if s in D: N += 1 break else: print(N) exit()
false
59.259259
[ "-from collections import deque", "-", "-D = list(map(int, input().split()))", "-like = list(range(1, 10))", "-dislike0 = False", "-for s in D:", "- if s == 0:", "- dislike0 = True", "+D = list(input().split())", "+while True:", "+ for s in str(N):", "+ if s in D:", "+ N += 1", "+ break", "- like.remove(s)", "-like.sort()", "-q = deque(like)", "-if dislike0 == False:", "- like.insert(0, 0)", "-while q:", "- num = q.popleft()", "- if num >= N:", "- print(num)", "+ print(N)", "- for i in range(len(like)):", "- q.append((int(str(num) + str(like[i]))))" ]
false
0.039639
0.045687
0.867607
[ "s365591903", "s833896221" ]
u287132915
p02837
python
s240002654
s206588453
259
229
44,380
42,480
Accepted
Accepted
11.58
n = int(eval(input())) lst = [[-1 for _ in range(n)] for __ in range(n)] for i in range(n): ai = int(eval(input())) for j in range(ai): hito, which = list(map(int, input().split())) lst[i][hito-1] = which ans = 0 muri = 0 for i in range(2**n): kumi = list(format(i, '0'+str(n)+'b')) temp = 0 muri = 0 for j in range(n): if muri == 1: break elif kumi[j] == '1': for k in range(n): if (lst[k][j] == 0 and kumi[k] == '1') or (lst[j][k] == 1 and kumi[k] == '0'): muri = 1 break if muri == 0: temp += 1 if muri == 0: ans = max(ans, temp) print(ans)
import itertools n = int(eval(input())) lst = [] for i in range(n): ai = int(eval(input())) lsti = [] for j in range(ai): xj, yj = list(map(int, input().split())) xj -= 1 lsti.append([xj, yj]) lst.append(lsti) ans = 0 for v in itertools.product([0, 1], repeat=n): ok = 1 for i in range(n): if v[i] == 0: continue if ok == 0: break lsti = lst[i] for xj, yj in lsti: if v[xj] != yj: ok = 0 break if ok == 1: ans = max(ans, sum(v)) print(ans)
28
28
730
587
n = int(eval(input())) lst = [[-1 for _ in range(n)] for __ in range(n)] for i in range(n): ai = int(eval(input())) for j in range(ai): hito, which = list(map(int, input().split())) lst[i][hito - 1] = which ans = 0 muri = 0 for i in range(2**n): kumi = list(format(i, "0" + str(n) + "b")) temp = 0 muri = 0 for j in range(n): if muri == 1: break elif kumi[j] == "1": for k in range(n): if (lst[k][j] == 0 and kumi[k] == "1") or ( lst[j][k] == 1 and kumi[k] == "0" ): muri = 1 break if muri == 0: temp += 1 if muri == 0: ans = max(ans, temp) print(ans)
import itertools n = int(eval(input())) lst = [] for i in range(n): ai = int(eval(input())) lsti = [] for j in range(ai): xj, yj = list(map(int, input().split())) xj -= 1 lsti.append([xj, yj]) lst.append(lsti) ans = 0 for v in itertools.product([0, 1], repeat=n): ok = 1 for i in range(n): if v[i] == 0: continue if ok == 0: break lsti = lst[i] for xj, yj in lsti: if v[xj] != yj: ok = 0 break if ok == 1: ans = max(ans, sum(v)) print(ans)
false
0
[ "+import itertools", "+", "-lst = [[-1 for _ in range(n)] for __ in range(n)]", "+lst = []", "+ lsti = []", "- hito, which = list(map(int, input().split()))", "- lst[i][hito - 1] = which", "+ xj, yj = list(map(int, input().split()))", "+ xj -= 1", "+ lsti.append([xj, yj])", "+ lst.append(lsti)", "-muri = 0", "-for i in range(2**n):", "- kumi = list(format(i, \"0\" + str(n) + \"b\"))", "- temp = 0", "- muri = 0", "- for j in range(n):", "- if muri == 1:", "+for v in itertools.product([0, 1], repeat=n):", "+ ok = 1", "+ for i in range(n):", "+ if v[i] == 0:", "+ continue", "+ if ok == 0:", "- elif kumi[j] == \"1\":", "- for k in range(n):", "- if (lst[k][j] == 0 and kumi[k] == \"1\") or (", "- lst[j][k] == 1 and kumi[k] == \"0\"", "- ):", "- muri = 1", "- break", "- if muri == 0:", "- temp += 1", "- if muri == 0:", "- ans = max(ans, temp)", "+ lsti = lst[i]", "+ for xj, yj in lsti:", "+ if v[xj] != yj:", "+ ok = 0", "+ break", "+ if ok == 1:", "+ ans = max(ans, sum(v))" ]
false
0.037255
0.035061
1.062588
[ "s240002654", "s206588453" ]
u784022244
p03472
python
s882280912
s790161910
379
203
12,176
79,000
Accepted
Accepted
46.44
import bisect from math import ceil N,H=list(map(int, input().split())) A=[] B=[] for i in range(N): a,b=list(map(int, input().split())) A.append(a) B.append(b) A=sorted(A) B=sorted(B) idx=bisect.bisect_right(B,A[-1]) throw=sum(B[idx:]) if throw<=H: ans=N-idx res=H-throw ans+=ceil(res/A[-1]) #print(res/A[-1], throw) else: res=H ans=0 for i in range(N): ans+=1 res-=B[-(i+1)] if res<=0: break print(ans)
from math import ceil N,H=list(map(int, input().split())) A=[0]*N B=[0]*N for i in range(N): a,b=list(map(int, input().split())) A[i]=a B[i]=b A=sorted(A) B=sorted(B, reverse=True) amax=max(A) ans=0 for i in range(N): b=B[i] if b>amax: H-=b ans+=1 if H<=0: break else: break if H>0: ans+=ceil(H/amax) print(ans)
30
28
501
403
import bisect from math import ceil N, H = list(map(int, input().split())) A = [] B = [] for i in range(N): a, b = list(map(int, input().split())) A.append(a) B.append(b) A = sorted(A) B = sorted(B) idx = bisect.bisect_right(B, A[-1]) throw = sum(B[idx:]) if throw <= H: ans = N - idx res = H - throw ans += ceil(res / A[-1]) # print(res/A[-1], throw) else: res = H ans = 0 for i in range(N): ans += 1 res -= B[-(i + 1)] if res <= 0: break print(ans)
from math import ceil N, H = list(map(int, input().split())) A = [0] * N B = [0] * N for i in range(N): a, b = list(map(int, input().split())) A[i] = a B[i] = b A = sorted(A) B = sorted(B, reverse=True) amax = max(A) ans = 0 for i in range(N): b = B[i] if b > amax: H -= b ans += 1 if H <= 0: break else: break if H > 0: ans += ceil(H / amax) print(ans)
false
6.666667
[ "-import bisect", "-A = []", "-B = []", "+A = [0] * N", "+B = [0] * N", "- A.append(a)", "- B.append(b)", "+ A[i] = a", "+ B[i] = b", "-B = sorted(B)", "-idx = bisect.bisect_right(B, A[-1])", "-throw = sum(B[idx:])", "-if throw <= H:", "- ans = N - idx", "- res = H - throw", "- ans += ceil(res / A[-1])", "- # print(res/A[-1], throw)", "-else:", "- res = H", "- ans = 0", "- for i in range(N):", "+B = sorted(B, reverse=True)", "+amax = max(A)", "+ans = 0", "+for i in range(N):", "+ b = B[i]", "+ if b > amax:", "+ H -= b", "- res -= B[-(i + 1)]", "- if res <= 0:", "+ if H <= 0:", "+ else:", "+ break", "+if H > 0:", "+ ans += ceil(H / amax)" ]
false
0.035218
0.035188
1.000847
[ "s882280912", "s790161910" ]
u607884285
p03165
python
s808065138
s899435572
671
429
175,112
112,476
Accepted
Accepted
36.07
s,t=eval(input()),eval(input()) m,n=len(s),len(t) c=[[0]*(n+1) for _ in range(m+1)] fro=[['']*(n+1) for _ in range(m+1)] for i in range(1,m+1): for j in range(1,n+1): if s[i-1]==t[j-1]: c[i][j]=c[i-1][j-1]+1 fro[i][j]='upper_left' elif c[i-1][j]>=c[i][j-1]: c[i][j]=c[i-1][j] fro[i][j]='above' else: c[i][j]=c[i][j-1] fro[i][j]='left' x='' a,b=m,n while a>0 and b>0: if fro[a][b]=='upper_left': x+=s[a-1] a-=1;b-=1 elif fro[a][b]=='above': a-=1 else: b-=1 print((x[::-1]))
s,t=eval(input()),eval(input()) S,T=len(s),len(t) dp=[[0]*(T+1) for _ in range(S+1)] for i in range(1,S+1): for j in range(1,T+1): if s[i-1]==t[j-1]: dp[i][j]=dp[i-1][j-1]+1 else: dp[i][j]=max(dp[i-1][j],dp[i][j-1]) i,j=S,T ans='' while min(i,j)>0: if dp[i][j]==dp[i][j-1]: j-=1 elif dp[i][j]==dp[i-1][j]: i-=1 else: ans+=s[i-1] i-=1 ; j-=1 print((ans[::-1]))
26
21
627
482
s, t = eval(input()), eval(input()) m, n = len(s), len(t) c = [[0] * (n + 1) for _ in range(m + 1)] fro = [[""] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if s[i - 1] == t[j - 1]: c[i][j] = c[i - 1][j - 1] + 1 fro[i][j] = "upper_left" elif c[i - 1][j] >= c[i][j - 1]: c[i][j] = c[i - 1][j] fro[i][j] = "above" else: c[i][j] = c[i][j - 1] fro[i][j] = "left" x = "" a, b = m, n while a > 0 and b > 0: if fro[a][b] == "upper_left": x += s[a - 1] a -= 1 b -= 1 elif fro[a][b] == "above": a -= 1 else: b -= 1 print((x[::-1]))
s, t = eval(input()), eval(input()) S, T = len(s), len(t) dp = [[0] * (T + 1) for _ in range(S + 1)] for i in range(1, S + 1): for j in range(1, T + 1): if s[i - 1] == t[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) i, j = S, T ans = "" while min(i, j) > 0: if dp[i][j] == dp[i][j - 1]: j -= 1 elif dp[i][j] == dp[i - 1][j]: i -= 1 else: ans += s[i - 1] i -= 1 j -= 1 print((ans[::-1]))
false
19.230769
[ "-m, n = len(s), len(t)", "-c = [[0] * (n + 1) for _ in range(m + 1)]", "-fro = [[\"\"] * (n + 1) for _ in range(m + 1)]", "-for i in range(1, m + 1):", "- for j in range(1, n + 1):", "+S, T = len(s), len(t)", "+dp = [[0] * (T + 1) for _ in range(S + 1)]", "+for i in range(1, S + 1):", "+ for j in range(1, T + 1):", "- c[i][j] = c[i - 1][j - 1] + 1", "- fro[i][j] = \"upper_left\"", "- elif c[i - 1][j] >= c[i][j - 1]:", "- c[i][j] = c[i - 1][j]", "- fro[i][j] = \"above\"", "+ dp[i][j] = dp[i - 1][j - 1] + 1", "- c[i][j] = c[i][j - 1]", "- fro[i][j] = \"left\"", "-x = \"\"", "-a, b = m, n", "-while a > 0 and b > 0:", "- if fro[a][b] == \"upper_left\":", "- x += s[a - 1]", "- a -= 1", "- b -= 1", "- elif fro[a][b] == \"above\":", "- a -= 1", "+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])", "+i, j = S, T", "+ans = \"\"", "+while min(i, j) > 0:", "+ if dp[i][j] == dp[i][j - 1]:", "+ j -= 1", "+ elif dp[i][j] == dp[i - 1][j]:", "+ i -= 1", "- b -= 1", "-print((x[::-1]))", "+ ans += s[i - 1]", "+ i -= 1", "+ j -= 1", "+print((ans[::-1]))" ]
false
0.036458
0.036748
0.992123
[ "s808065138", "s899435572" ]
u361826811
p02959
python
s462883834
s310559192
179
127
23,432
23,432
Accepted
Accepted
29.05
import sys import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *AB = list(map(int, read().split())) A = AB[:N + 1] B = AB[N + 1:] ans = 0 cnt = 0 for i, j in zip(A, B): # print(f'A:{i} B:{j} cnt:{cnt}') ans += min(i, cnt) m = min(i-cnt, j) m=max(m,0) ans += m cnt = max(j - m, 0) ans += min(A[-1], cnt) print(ans)
import sys import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *AB = list(map(int, read().split())) A = AB[:N + 1] B = AB[N + 1:] B.append(0) ans = 0 rest = 0 for i, j in zip(A, B): x = min(rest, i) ans += x i -= x if i < j: ans += i rest = j - i else: ans += j rest = 0 print(ans)
25
27
454
452
import sys import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *AB = list(map(int, read().split())) A = AB[: N + 1] B = AB[N + 1 :] ans = 0 cnt = 0 for i, j in zip(A, B): # print(f'A:{i} B:{j} cnt:{cnt}') ans += min(i, cnt) m = min(i - cnt, j) m = max(m, 0) ans += m cnt = max(j - m, 0) ans += min(A[-1], cnt) print(ans)
import sys import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *AB = list(map(int, read().split())) A = AB[: N + 1] B = AB[N + 1 :] B.append(0) ans = 0 rest = 0 for i, j in zip(A, B): x = min(rest, i) ans += x i -= x if i < j: ans += i rest = j - i else: ans += j rest = 0 print(ans)
false
7.407407
[ "+B.append(0)", "-cnt = 0", "+rest = 0", "- # print(f'A:{i} B:{j} cnt:{cnt}')", "- ans += min(i, cnt)", "- m = min(i - cnt, j)", "- m = max(m, 0)", "- ans += m", "- cnt = max(j - m, 0)", "-ans += min(A[-1], cnt)", "+ x = min(rest, i)", "+ ans += x", "+ i -= x", "+ if i < j:", "+ ans += i", "+ rest = j - i", "+ else:", "+ ans += j", "+ rest = 0" ]
false
0.036983
0.038047
0.972035
[ "s462883834", "s310559192" ]
u597374218
p02712
python
s277094980
s890901111
103
92
9,168
9,160
Accepted
Accepted
10.68
print((sum(i for i in range(int(eval(input()))+1) if i%3!=0 and i%5!=0)))
print((sum(i for i in range(int(eval(input()))+1) if i%3 and i%5)))
1
1
65
59
print((sum(i for i in range(int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0)))
print((sum(i for i in range(int(eval(input())) + 1) if i % 3 and i % 5)))
false
0
[ "-print((sum(i for i in range(int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0)))", "+print((sum(i for i in range(int(eval(input())) + 1) if i % 3 and i % 5)))" ]
false
0.099116
0.247749
0.400066
[ "s277094980", "s890901111" ]
u347600233
p03611
python
s828361404
s074872528
95
85
13,964
13,964
Accepted
Accepted
10.53
n = int(eval(input())) a = [int(i) for i in input().split()] cnt_x = [0] * (10**5 + 2) for i in range(n): cnt_x[a[i] - 1] += 1 cnt_x[a[i]] += 1 cnt_x[a[i] + 1] += 1 print((max(cnt_x)))
n = int(eval(input())) A = [int(i) for i in input().split()] cnt_x = [0] * (10**5 + 2) for a in A: cnt_x[a - 1] += 1 cnt_x[a] += 1 cnt_x[a + 1] += 1 print((max(cnt_x)))
8
8
195
179
n = int(eval(input())) a = [int(i) for i in input().split()] cnt_x = [0] * (10**5 + 2) for i in range(n): cnt_x[a[i] - 1] += 1 cnt_x[a[i]] += 1 cnt_x[a[i] + 1] += 1 print((max(cnt_x)))
n = int(eval(input())) A = [int(i) for i in input().split()] cnt_x = [0] * (10**5 + 2) for a in A: cnt_x[a - 1] += 1 cnt_x[a] += 1 cnt_x[a + 1] += 1 print((max(cnt_x)))
false
0
[ "-a = [int(i) for i in input().split()]", "+A = [int(i) for i in input().split()]", "-for i in range(n):", "- cnt_x[a[i] - 1] += 1", "- cnt_x[a[i]] += 1", "- cnt_x[a[i] + 1] += 1", "+for a in A:", "+ cnt_x[a - 1] += 1", "+ cnt_x[a] += 1", "+ cnt_x[a + 1] += 1" ]
false
0.010119
0.050452
0.20057
[ "s828361404", "s074872528" ]
u397384480
p03137
python
s452095193
s140635615
252
227
56,872
57,384
Accepted
Accepted
9.92
N,M = list(map(int,(input().split()))) X = list(map(int,(input().split()))) if N >= M: print((0)) else: X.sort() gap = [] for i in range(1,M): gap.append(X[i]-X[i-1]) s = X[M-1] - X[0] gap.sort(reverse=True) d = 0 for i in range(N-1): d += gap[i] print((s-d))
N,M = list(map(int,(input().split()))) X = list(map(int,(input().split()))) if N >= M: print((0)) else: X.sort() gap = [] for i in range(1,M): gap.append(X[i]-X[i-1]) s = X[M-1] - X[0] gap.sort(reverse=True) print((s-sum(gap[0:N-1])))
15
12
315
271
N, M = list(map(int, (input().split()))) X = list(map(int, (input().split()))) if N >= M: print((0)) else: X.sort() gap = [] for i in range(1, M): gap.append(X[i] - X[i - 1]) s = X[M - 1] - X[0] gap.sort(reverse=True) d = 0 for i in range(N - 1): d += gap[i] print((s - d))
N, M = list(map(int, (input().split()))) X = list(map(int, (input().split()))) if N >= M: print((0)) else: X.sort() gap = [] for i in range(1, M): gap.append(X[i] - X[i - 1]) s = X[M - 1] - X[0] gap.sort(reverse=True) print((s - sum(gap[0 : N - 1])))
false
20
[ "- d = 0", "- for i in range(N - 1):", "- d += gap[i]", "- print((s - d))", "+ print((s - sum(gap[0 : N - 1])))" ]
false
0.047949
0.04555
1.052665
[ "s452095193", "s140635615" ]