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
u133583235
p02994
python
s905146380
s546589376
19
17
3,064
3,060
Accepted
Accepted
10.53
N, L = list(map(int, input().split())) a = [] b = [] #ringo goto aji dasu for i in range(N): a.append(L+ i+1 -1) if max(a) < 0: print((sum(a)-max(a))) elif max(a) >= 0 and min(a) <= 0: print((sum(a))) else: print((sum(a)-min(a)))
N, L = list(map(int, input().split())) a = [] for i in range(N): a.append(L+i+1-1) if min(a) > 0: print((sum(a)-min(a))) elif min(a)<=0 and max(a)>=0: print((sum(a))) else: print((sum(a)-max(a)))
14
14
240
216
N, L = list(map(int, input().split())) a = [] b = [] # ringo goto aji dasu for i in range(N): a.append(L + i + 1 - 1) if max(a) < 0: print((sum(a) - max(a))) elif max(a) >= 0 and min(a) <= 0: print((sum(a))) else: print((sum(a) - min(a)))
N, L = list(map(int, input().split())) a = [] for i in range(N): a.append(L + i + 1 - 1) if min(a) > 0: print((sum(a) - min(a))) elif min(a) <= 0 and max(a) >= 0: print((sum(a))) else: print((sum(a) - max(a)))
false
0
[ "-b = []", "-# ringo goto aji dasu", "-if max(a) < 0:", "- print((sum(a) - max(a)))", "-elif max(a) >= 0 and min(a) <= 0:", "+if min(a) > 0:", "+ print((sum(a) - min(a)))", "+elif min(a) <= 0 and max(a) >= 0:", "- print((sum(a) - min(a)))", "+ print((sum(a) - max(a)))" ]
false
0.044499
0.044617
0.997358
[ "s905146380", "s546589376" ]
u528470578
p03162
python
s031429517
s674105423
639
250
51,416
97,664
Accepted
Accepted
60.88
N = int(eval(input())) dpa = [0] * N dpb = [0] * N dpc = [0] * N a, b, c = list(map(int, input().split())) dpa[0] = a dpb[0] = b dpc[0] = c for i in range(1, N): a, b, c = list(map(int, input().split())) dpa[i] = max(dpb[i-1] + a, dpc[i-1] + a) dpb[i] = max(dpa[i-1] + b, dpc[i-1] + b) dpc[i] = max(dpa[i-1] + c, dpb[i-1] + c) print((max(dpa[N-1], dpb[N-1], dpc[N-1])))
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] # dp dp_a = [0 for _ in range(N)] dp_b, dp_c = dp_a.copy(), dp_a.copy() dp_a[0] = abc[0][0] dp_b[0] = abc[0][1] dp_c[0] = abc[0][2] for i in range(N - 1): dp_a[i + 1] = max(dp_b[i], dp_c[i]) + abc[i + 1][0] dp_b[i + 1] = max(dp_a[i], dp_c[i]) + abc[i + 1][1] dp_c[i + 1] = max(dp_a[i], dp_b[i]) + abc[i + 1][2] print((max(dp_a[-1], dp_b[-1], dp_c[-1])))
16
15
382
454
N = int(eval(input())) dpa = [0] * N dpb = [0] * N dpc = [0] * N a, b, c = list(map(int, input().split())) dpa[0] = a dpb[0] = b dpc[0] = c for i in range(1, N): a, b, c = list(map(int, input().split())) dpa[i] = max(dpb[i - 1] + a, dpc[i - 1] + a) dpb[i] = max(dpa[i - 1] + b, dpc[i - 1] + b) dpc[i] = max(dpa[i - 1] + c, dpb[i - 1] + c) print((max(dpa[N - 1], dpb[N - 1], dpc[N - 1])))
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] # dp dp_a = [0 for _ in range(N)] dp_b, dp_c = dp_a.copy(), dp_a.copy() dp_a[0] = abc[0][0] dp_b[0] = abc[0][1] dp_c[0] = abc[0][2] for i in range(N - 1): dp_a[i + 1] = max(dp_b[i], dp_c[i]) + abc[i + 1][0] dp_b[i + 1] = max(dp_a[i], dp_c[i]) + abc[i + 1][1] dp_c[i + 1] = max(dp_a[i], dp_b[i]) + abc[i + 1][2] print((max(dp_a[-1], dp_b[-1], dp_c[-1])))
false
6.25
[ "-dpa = [0] * N", "-dpb = [0] * N", "-dpc = [0] * N", "-a, b, c = list(map(int, input().split()))", "-dpa[0] = a", "-dpb[0] = b", "-dpc[0] = c", "-for i in range(1, N):", "- a, b, c = list(map(int, input().split()))", "- dpa[i] = max(dpb[i - 1] + a, dpc[i - 1] + a)", "- dpb[i] = max(dpa[i - 1] + b, dpc[i - 1] + b)", "- dpc[i] = max(dpa[i - 1] + c, dpb[i - 1] + c)", "-print((max(dpa[N - 1], dpb[N - 1], dpc[N - 1])))", "+abc = [list(map(int, input().split())) for _ in range(N)]", "+# dp", "+dp_a = [0 for _ in range(N)]", "+dp_b, dp_c = dp_a.copy(), dp_a.copy()", "+dp_a[0] = abc[0][0]", "+dp_b[0] = abc[0][1]", "+dp_c[0] = abc[0][2]", "+for i in range(N - 1):", "+ dp_a[i + 1] = max(dp_b[i], dp_c[i]) + abc[i + 1][0]", "+ dp_b[i + 1] = max(dp_a[i], dp_c[i]) + abc[i + 1][1]", "+ dp_c[i + 1] = max(dp_a[i], dp_b[i]) + abc[i + 1][2]", "+print((max(dp_a[-1], dp_b[-1], dp_c[-1])))" ]
false
0.062313
0.063866
0.975695
[ "s031429517", "s674105423" ]
u729133443
p03434
python
s765246756
s192326848
170
18
38,384
2,940
Accepted
Accepted
89.41
eval(input());l=sorted(map(int,input().split()));print((sum(l[-1::-2])-sum(l[-2::-2])))
eval(input());c=0 for a in sorted(map(int,input().split())):c=a-c print(c)
1
4
79
72
eval(input()) l = sorted(map(int, input().split())) print((sum(l[-1::-2]) - sum(l[-2::-2])))
eval(input()) c = 0 for a in sorted(map(int, input().split())): c = a - c print(c)
false
75
[ "-l = sorted(map(int, input().split()))", "-print((sum(l[-1::-2]) - sum(l[-2::-2])))", "+c = 0", "+for a in sorted(map(int, input().split())):", "+ c = a - c", "+print(c)" ]
false
0.106952
0.151941
0.703903
[ "s765246756", "s192326848" ]
u950708010
p03193
python
s787209209
s114688372
22
20
3,188
3,060
Accepted
Accepted
9.09
n,h,w = (int(i) for i in input().split()) a = [] for i in range(n): tmp = list(int(i) for i in input().split()) a.append(tmp) ct = 0 for i in range(n): if a[i][0] >= h and a[i][1] >=w: ct += 1 print(ct)
def solve(): n,h,w = (int(i) for i in input().split()) ct = 0 for i in range(n): a,b = (int(i) for i in input().split()) if a>=h and b >= w: ct += 1 print(ct) solve()
9
9
216
196
n, h, w = (int(i) for i in input().split()) a = [] for i in range(n): tmp = list(int(i) for i in input().split()) a.append(tmp) ct = 0 for i in range(n): if a[i][0] >= h and a[i][1] >= w: ct += 1 print(ct)
def solve(): n, h, w = (int(i) for i in input().split()) ct = 0 for i in range(n): a, b = (int(i) for i in input().split()) if a >= h and b >= w: ct += 1 print(ct) solve()
false
0
[ "-n, h, w = (int(i) for i in input().split())", "-a = []", "-for i in range(n):", "- tmp = list(int(i) for i in input().split())", "- a.append(tmp)", "-ct = 0", "-for i in range(n):", "- if a[i][0] >= h and a[i][1] >= w:", "- ct += 1", "-print(ct)", "+def solve():", "+ n, h, w = (int(i) for i in input().split())", "+ ct = 0", "+ for i in range(n):", "+ a, b = (int(i) for i in input().split())", "+ if a >= h and b >= w:", "+ ct += 1", "+ print(ct)", "+", "+", "+solve()" ]
false
0.044581
0.037236
1.197265
[ "s787209209", "s114688372" ]
u542932305
p02982
python
s880582585
s070822833
20
17
3,064
3,064
Accepted
Accepted
15
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] count = 0 tmp = [] for i in range(N): r1 = X[i] for j in range(N): t = str(i)+str(j) if i == j or t in tmp or str(j)+str(i) in tmp: continue r2 = X[j] ls = [(r1[j] - r2[j])**2 for j in range(D)] res = math.sqrt(sum(ls)) if res % 1 == 0: count += 1 tmp.append(t) print(count)
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] count = 0 for i in range(N): r1 = X[i] for j in range(N-1, -1, -1): if i == j: break r2 = X[j] ls = [(r1[j] - r2[j])**2 for j in range(D)] res = math.sqrt(sum(ls)) if res % 1 == 0: count += 1 print(count)
23
17
490
395
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] count = 0 tmp = [] for i in range(N): r1 = X[i] for j in range(N): t = str(i) + str(j) if i == j or t in tmp or str(j) + str(i) in tmp: continue r2 = X[j] ls = [(r1[j] - r2[j]) ** 2 for j in range(D)] res = math.sqrt(sum(ls)) if res % 1 == 0: count += 1 tmp.append(t) print(count)
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] count = 0 for i in range(N): r1 = X[i] for j in range(N - 1, -1, -1): if i == j: break r2 = X[j] ls = [(r1[j] - r2[j]) ** 2 for j in range(D)] res = math.sqrt(sum(ls)) if res % 1 == 0: count += 1 print(count)
false
26.086957
[ "-tmp = []", "- for j in range(N):", "- t = str(i) + str(j)", "- if i == j or t in tmp or str(j) + str(i) in tmp:", "- continue", "+ for j in range(N - 1, -1, -1):", "+ if i == j:", "+ break", "- tmp.append(t)" ]
false
0.088114
0.088548
0.995106
[ "s880582585", "s070822833" ]
u325227960
p03078
python
s859860443
s880283381
779
688
167,528
135,996
Accepted
Accepted
11.68
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=1) B.sort(reverse=1) C.sort(reverse=1) D = [0] * (min(k, x) * min(k, y)) for i in range(min(k, x)): for j in range(min(k, y)): D.append(A[i] + B[j]) D.sort(reverse=1) E = [0] * (min(k, len(D)) * min(k, z)) for i in range(min(k, len(D))): for j in range(min(k, z)): E.append(D[i] + C[j]) E.sort(reverse=1) for i in range(k): print((E[i]))
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=1) B.sort(reverse=1) C.sort(reverse=1) D = [] for i in range(min(k, x)): for j in range(min(k, y)): for l in range(min(k, z)): if i*j*l <= k: D.append(A[i] + B[j] + C[l]) else: break D.sort(reverse=1) for i in range(k): print((D[i]))
26
23
553
488
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=1) B.sort(reverse=1) C.sort(reverse=1) D = [0] * (min(k, x) * min(k, y)) for i in range(min(k, x)): for j in range(min(k, y)): D.append(A[i] + B[j]) D.sort(reverse=1) E = [0] * (min(k, len(D)) * min(k, z)) for i in range(min(k, len(D))): for j in range(min(k, z)): E.append(D[i] + C[j]) E.sort(reverse=1) for i in range(k): print((E[i]))
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=1) B.sort(reverse=1) C.sort(reverse=1) D = [] for i in range(min(k, x)): for j in range(min(k, y)): for l in range(min(k, z)): if i * j * l <= k: D.append(A[i] + B[j] + C[l]) else: break D.sort(reverse=1) for i in range(k): print((D[i]))
false
11.538462
[ "-D = [0] * (min(k, x) * min(k, y))", "+D = []", "- D.append(A[i] + B[j])", "+ for l in range(min(k, z)):", "+ if i * j * l <= k:", "+ D.append(A[i] + B[j] + C[l])", "+ else:", "+ break", "-E = [0] * (min(k, len(D)) * min(k, z))", "-for i in range(min(k, len(D))):", "- for j in range(min(k, z)):", "- E.append(D[i] + C[j])", "-E.sort(reverse=1)", "- print((E[i]))", "+ print((D[i]))" ]
false
0.034872
0.034124
1.021898
[ "s859860443", "s880283381" ]
u408071652
p02616
python
s637815931
s129952077
207
144
118,048
32,392
Accepted
Accepted
30.43
import sys sys.setrecursionlimit(10 ** 7) # import bisect # import numpy as np # from collections import deque from collections import deque # map(int, sys.stdin.read().split()) import itertools import heapq def input(): return sys.stdin.readline().rstrip() def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 A.sort() A = deque(A) # print(A) A_minus = deque([s for s in A if s < 0]) A_plus = deque([s for s in A if s >= 0]) # print(A_plus) # print(A_minus) AA = [] if N == K: ans = 1 for i in A: ans *= i % mod ans %=mod print((ans % mod)) elif K % 2 == 0: while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() heapq.heappush(AA, -a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() heapq.heappush(AA, -a1 * a2) ans = 1 for i in range(K // 2): ans *= (-1 * heapq.heappop(AA)) ans %= mod print((ans % mod)) elif len(A_plus) == 0: ans = 1 for i in range(K): ans *= A_minus.pop() % mod ans %= mod print((ans % mod)) else: ans = A_plus.pop() while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() heapq.heappush(AA, -a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() heapq.heappush(AA, -a1 * a2) heapq.heapify(AA) for i in range(K // 2): ans *= (-1 * heapq.heappop(AA)) % mod ans %=mod print((ans% mod)) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10 ** 7) # import bisect # import numpy as np # from collections import deque from collections import deque # map(int, sys.stdin.read().split()) #import itertools #import heapq import bisect def input(): return sys.stdin.readline().rstrip() def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 A.sort() # print(A) pp = int(bisect.bisect_left(A,0)) A_minus = deque(A[:pp]) A_plus = deque(A[pp:]) # print(A_plus) # print(A_minus) AA = deque([]) AAm = deque([]) if N == K: ans = 1 for i in A: ans *= i % mod ans %=mod print((ans % mod)) elif K % 2 == 0: ans = 1 while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() AAm.append(a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() AA.append(a1 * a2) for i in range(K // 2): if len(AAm)==0: temp = AA.popleft() elif len(AA) ==0: temp = AAm.popleft() elif AAm[0] > AA[0]: temp = AAm.popleft() else: temp = AA.popleft() ans *= temp % mod ans %=mod print((ans % mod)) elif len(A_plus) == 0: ans = 1 for i in range(K): ans *= A_minus.pop() % mod ans %=mod print((ans % mod)) else: ans = A_plus.pop() while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() AAm.append(a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() AA.append(a1 * a2) for i in range(K // 2): if len(AAm) == 0: temp = AA.popleft() elif len(AA) == 0: temp = AAm.popleft() elif AAm[0] > AA[0]: temp = AAm.popleft() else: temp = AA.popleft() ans *= temp ans %=mod print((ans % mod)) if __name__ == "__main__": main()
81
100
1,891
2,349
import sys sys.setrecursionlimit(10**7) # import bisect # import numpy as np # from collections import deque from collections import deque # map(int, sys.stdin.read().split()) import itertools import heapq def input(): return sys.stdin.readline().rstrip() def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10**9 + 7 A.sort() A = deque(A) # print(A) A_minus = deque([s for s in A if s < 0]) A_plus = deque([s for s in A if s >= 0]) # print(A_plus) # print(A_minus) AA = [] if N == K: ans = 1 for i in A: ans *= i % mod ans %= mod print((ans % mod)) elif K % 2 == 0: while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() heapq.heappush(AA, -a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() heapq.heappush(AA, -a1 * a2) ans = 1 for i in range(K // 2): ans *= -1 * heapq.heappop(AA) ans %= mod print((ans % mod)) elif len(A_plus) == 0: ans = 1 for i in range(K): ans *= A_minus.pop() % mod ans %= mod print((ans % mod)) else: ans = A_plus.pop() while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() heapq.heappush(AA, -a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() heapq.heappush(AA, -a1 * a2) heapq.heapify(AA) for i in range(K // 2): ans *= (-1 * heapq.heappop(AA)) % mod ans %= mod print((ans % mod)) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**7) # import bisect # import numpy as np # from collections import deque from collections import deque # map(int, sys.stdin.read().split()) # import itertools # import heapq import bisect def input(): return sys.stdin.readline().rstrip() def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10**9 + 7 A.sort() # print(A) pp = int(bisect.bisect_left(A, 0)) A_minus = deque(A[:pp]) A_plus = deque(A[pp:]) # print(A_plus) # print(A_minus) AA = deque([]) AAm = deque([]) if N == K: ans = 1 for i in A: ans *= i % mod ans %= mod print((ans % mod)) elif K % 2 == 0: ans = 1 while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() AAm.append(a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() AA.append(a1 * a2) for i in range(K // 2): if len(AAm) == 0: temp = AA.popleft() elif len(AA) == 0: temp = AAm.popleft() elif AAm[0] > AA[0]: temp = AAm.popleft() else: temp = AA.popleft() ans *= temp % mod ans %= mod print((ans % mod)) elif len(A_plus) == 0: ans = 1 for i in range(K): ans *= A_minus.pop() % mod ans %= mod print((ans % mod)) else: ans = A_plus.pop() while len(A_minus) >= 2: a1 = A_minus.popleft() a2 = A_minus.popleft() AAm.append(a1 * a2) while len(A_plus) >= 2: a1 = A_plus.pop() a2 = A_plus.pop() AA.append(a1 * a2) for i in range(K // 2): if len(AAm) == 0: temp = AA.popleft() elif len(AA) == 0: temp = AAm.popleft() elif AAm[0] > AA[0]: temp = AAm.popleft() else: temp = AA.popleft() ans *= temp ans %= mod print((ans % mod)) if __name__ == "__main__": main()
false
19
[ "-import itertools", "-import heapq", "+# import itertools", "+# import heapq", "+import bisect", "- A = deque(A)", "- A_minus = deque([s for s in A if s < 0])", "- A_plus = deque([s for s in A if s >= 0])", "+ pp = int(bisect.bisect_left(A, 0))", "+ A_minus = deque(A[:pp])", "+ A_plus = deque(A[pp:])", "- AA = []", "+ AA = deque([])", "+ AAm = deque([])", "+ ans = 1", "- heapq.heappush(AA, -a1 * a2)", "+ AAm.append(a1 * a2)", "- heapq.heappush(AA, -a1 * a2)", "- ans = 1", "+ AA.append(a1 * a2)", "- ans *= -1 * heapq.heappop(AA)", "+ if len(AAm) == 0:", "+ temp = AA.popleft()", "+ elif len(AA) == 0:", "+ temp = AAm.popleft()", "+ elif AAm[0] > AA[0]:", "+ temp = AAm.popleft()", "+ else:", "+ temp = AA.popleft()", "+ ans *= temp % mod", "- heapq.heappush(AA, -a1 * a2)", "+ AAm.append(a1 * a2)", "- heapq.heappush(AA, -a1 * a2)", "- heapq.heapify(AA)", "+ AA.append(a1 * a2)", "- ans *= (-1 * heapq.heappop(AA)) % mod", "+ if len(AAm) == 0:", "+ temp = AA.popleft()", "+ elif len(AA) == 0:", "+ temp = AAm.popleft()", "+ elif AAm[0] > AA[0]:", "+ temp = AAm.popleft()", "+ else:", "+ temp = AA.popleft()", "+ ans *= temp" ]
false
0.037416
0.037767
0.990699
[ "s637815931", "s129952077" ]
u312814337
p02678
python
s790408952
s140600298
734
643
37,848
36,848
Accepted
Accepted
12.4
from collections import deque room_num, path_num = list(map(int, input().split(" "))) graph = [[] for _ in range(room_num)] dis = [-1] * room_num count = [0] * room_num count[0] = 1 for _ in range(path_num): a, b = list(map(int, input().split(" "))) graph[a-1].append(b-1) graph[b-1].append(a-1) dis[0] = 0 q = deque() q.append(0) while q: pop = q.popleft() for n in graph[pop]: if count[n] ==1: continue else: count[n] = 1 dis[n] = pop+1 q.append(n) if sum(dis) == room_num: print("No") else: del dis[0] print("Yes") for s in dis: print(s)
from collections import deque room_num, path_num = list(map(int, input().split(" "))) graph = [[] for _ in range(room_num)] dis = [-1] * room_num for _ in range(path_num): a, b = list(map(int, input().split(" "))) graph[a-1].append(b-1) graph[b-1].append(a-1) dis[0] = 0 q = deque() q.append(0) while q: pop = q.popleft() for n in graph[pop]: if dis[n] > 0: pass else: dis[n] = pop+1 q.append(n) if -1 in dis: print("No") else: del dis[0] print("Yes") for s in dis: print(s)
31
27
668
585
from collections import deque room_num, path_num = list(map(int, input().split(" "))) graph = [[] for _ in range(room_num)] dis = [-1] * room_num count = [0] * room_num count[0] = 1 for _ in range(path_num): a, b = list(map(int, input().split(" "))) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) dis[0] = 0 q = deque() q.append(0) while q: pop = q.popleft() for n in graph[pop]: if count[n] == 1: continue else: count[n] = 1 dis[n] = pop + 1 q.append(n) if sum(dis) == room_num: print("No") else: del dis[0] print("Yes") for s in dis: print(s)
from collections import deque room_num, path_num = list(map(int, input().split(" "))) graph = [[] for _ in range(room_num)] dis = [-1] * room_num for _ in range(path_num): a, b = list(map(int, input().split(" "))) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) dis[0] = 0 q = deque() q.append(0) while q: pop = q.popleft() for n in graph[pop]: if dis[n] > 0: pass else: dis[n] = pop + 1 q.append(n) if -1 in dis: print("No") else: del dis[0] print("Yes") for s in dis: print(s)
false
12.903226
[ "-count = [0] * room_num", "-count[0] = 1", "- if count[n] == 1:", "- continue", "+ if dis[n] > 0:", "+ pass", "- count[n] = 1", "-if sum(dis) == room_num:", "+if -1 in dis:" ]
false
0.00777
0.129717
0.059902
[ "s790408952", "s140600298" ]
u423585790
p02716
python
s941082953
s603544867
542
429
148,548
136,724
Accepted
Accepted
20.85
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x)-1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") #solve def solve(): n = II() a = LI() if n == 3: print((max(a))) return dp = [[-inf] * 3 for i in range(n + 1)] dp[0] = [0, 0, 0] dp[1][0] = a[0] dp[2][1] = a[1] for i in range(3, n+1): dp[i][0] = dp[i - 2][0] + a[i-1] dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i-1] dp[i][2] = max(dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]) + a[i-1] if n & 1: print((max(dp[-3][0], dp[-1][1], dp[-1][2]))) else: print((max(dp[-1][1], dp[-2][0]))) return #main if __name__ == '__main__': solve()
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x)-1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") #solve def solve(): n = II() a = LI() if n == 3: print((max(a))) return dp = [[-inf] * 3 for i in range(n + 1)] dp[0] = [0, 0, 0] dp[1][0] = a[0] dp[2][1] = a[1] for i in range(3, n+1): dp[i][0] = dp[i - 2][0] + a[i-1] dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i-1] dp[i][2] = max(dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]) + a[i-1] if n & 1: print((max(dp[-3][0], dp[-2][1], dp[-1][2]))) else: print((max(dp[-1][1], dp[-2][0]))) return #main if __name__ == '__main__': solve()
50
50
1,518
1,518
#!/usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # solve def solve(): n = II() a = LI() if n == 3: print((max(a))) return dp = [[-inf] * 3 for i in range(n + 1)] dp[0] = [0, 0, 0] dp[1][0] = a[0] dp[2][1] = a[1] for i in range(3, n + 1): dp[i][0] = dp[i - 2][0] + a[i - 1] dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i - 1] dp[i][2] = max(dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]) + a[i - 1] if n & 1: print((max(dp[-3][0], dp[-1][1], dp[-1][2]))) else: print((max(dp[-1][1], dp[-2][0]))) return # main if __name__ == "__main__": solve()
#!/usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # solve def solve(): n = II() a = LI() if n == 3: print((max(a))) return dp = [[-inf] * 3 for i in range(n + 1)] dp[0] = [0, 0, 0] dp[1][0] = a[0] dp[2][1] = a[1] for i in range(3, n + 1): dp[i][0] = dp[i - 2][0] + a[i - 1] dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i - 1] dp[i][2] = max(dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]) + a[i - 1] if n & 1: print((max(dp[-3][0], dp[-2][1], dp[-1][2]))) else: print((max(dp[-1][1], dp[-2][0]))) return # main if __name__ == "__main__": solve()
false
0
[ "- print((max(dp[-3][0], dp[-1][1], dp[-1][2])))", "+ print((max(dp[-3][0], dp[-2][1], dp[-1][2])))" ]
false
0.117282
0.043035
2.725269
[ "s941082953", "s603544867" ]
u983918956
p03326
python
s217314058
s449864650
30
27
3,700
3,380
Accepted
Accepted
10
import itertools N,M = list(map(int,input().split())) info = [list(map(int,input().split())) for i in range(N)] note = [] for x,y,z in info: X = [x,-x]; Y = [y,-y]; Z = [z,-z] tmp = [] for c in itertools.product(X,Y,Z): tmp.append(sum(c)) note.append(tmp) ans = -float('inf') for j in range(8): res = [] for i in range(N): res.append(note[i][j]) res = sorted(res,reverse=True) value = sum(res[:M]) if value > ans: ans = value print(ans)
import itertools N,M = list(map(int,input().split())) info = [list(map(int,input().split())) for i in range(N)] ans = -float('inf') for i,j,k in itertools.product([1,-1],repeat=3): tmp = [] for x,y,z in info: value = x*i + y*j + z*k tmp.append(value) tmp.sort(reverse=True) res = sum(tmp[:M]) if res > ans: ans = res print(ans)
21
14
511
378
import itertools N, M = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(N)] note = [] for x, y, z in info: X = [x, -x] Y = [y, -y] Z = [z, -z] tmp = [] for c in itertools.product(X, Y, Z): tmp.append(sum(c)) note.append(tmp) ans = -float("inf") for j in range(8): res = [] for i in range(N): res.append(note[i][j]) res = sorted(res, reverse=True) value = sum(res[:M]) if value > ans: ans = value print(ans)
import itertools N, M = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(N)] ans = -float("inf") for i, j, k in itertools.product([1, -1], repeat=3): tmp = [] for x, y, z in info: value = x * i + y * j + z * k tmp.append(value) tmp.sort(reverse=True) res = sum(tmp[:M]) if res > ans: ans = res print(ans)
false
33.333333
[ "-note = []", "-for x, y, z in info:", "- X = [x, -x]", "- Y = [y, -y]", "- Z = [z, -z]", "+ans = -float(\"inf\")", "+for i, j, k in itertools.product([1, -1], repeat=3):", "- for c in itertools.product(X, Y, Z):", "- tmp.append(sum(c))", "- note.append(tmp)", "-ans = -float(\"inf\")", "-for j in range(8):", "- res = []", "- for i in range(N):", "- res.append(note[i][j])", "- res = sorted(res, reverse=True)", "- value = sum(res[:M])", "- if value > ans:", "- ans = value", "+ for x, y, z in info:", "+ value = x * i + y * j + z * k", "+ tmp.append(value)", "+ tmp.sort(reverse=True)", "+ res = sum(tmp[:M])", "+ if res > ans:", "+ ans = res" ]
false
0.06673
0.04665
1.430437
[ "s217314058", "s449864650" ]
u076917070
p03575
python
s848062583
s987015990
24
21
3,444
3,064
Accepted
Accepted
12.5
import sys input=sys.stdin.readline import math def get_edges_include_node(i, Edges): # 頂点 i を含む辺のリストを返す es = [] for e in Edges: if i in e: es.append(e) return es def dfs(i, e0, goal, Edges): # 頂点 i から頂点 j にたどり着けるかどうか if e0 in Edges: Edges.remove(e0) for e1 in get_edges_include_node(i, Edges): if goal in e1: return True else: ni = e1[1] if e1[0] == i else e1[0] if dfs(ni, e1, goal, Edges): return True return False def main(): N,M = list(map(int, input().split())) Edges = [] for _ in range(M): a,b = list(map(int, input().split())) Edges.append((a,b)) ans = 0 for e in Edges: tmp = [] for e2 in Edges: tmp.append((e2[0], e2[1])) if not dfs(e[0], e, e[1], tmp): ans += 1 print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def main(): N, M = list(map(int, input().split())) E = [] for i in range(M): a, b = list(map(int, input().split())) E.append((a-1, b-1)) ans = 0 # i 番目の辺を取り除いても、全ての頂点が連結しているか? # Union-Find で連結グラフか判定する for i in range(M): uf = UnionFind(N) # 最初、全ての頂点が非連結の状態 for j in range(M): if i == j: pass # i 番目の辺を無視する else: # 要素が同じ集合にある=頂点が連結している uf.union(E[j][0], E[j][1]) # グラフ全体が連結なら、任意の頂点を含む集合のサイズが N のはず if uf.size(0) != N: ans += 1 print(ans) if __name__ == '__main__': main()
41
57
980
1,332
import sys input = sys.stdin.readline import math def get_edges_include_node(i, Edges): # 頂点 i を含む辺のリストを返す es = [] for e in Edges: if i in e: es.append(e) return es def dfs(i, e0, goal, Edges): # 頂点 i から頂点 j にたどり着けるかどうか if e0 in Edges: Edges.remove(e0) for e1 in get_edges_include_node(i, Edges): if goal in e1: return True else: ni = e1[1] if e1[0] == i else e1[0] if dfs(ni, e1, goal, Edges): return True return False def main(): N, M = list(map(int, input().split())) Edges = [] for _ in range(M): a, b = list(map(int, input().split())) Edges.append((a, b)) ans = 0 for e in Edges: tmp = [] for e2 in Edges: tmp.append((e2[0], e2[1])) if not dfs(e[0], e, e[1], tmp): ans += 1 print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def main(): N, M = list(map(int, input().split())) E = [] for i in range(M): a, b = list(map(int, input().split())) E.append((a - 1, b - 1)) ans = 0 # i 番目の辺を取り除いても、全ての頂点が連結しているか? # Union-Find で連結グラフか判定する for i in range(M): uf = UnionFind(N) # 最初、全ての頂点が非連結の状態 for j in range(M): if i == j: pass # i 番目の辺を無視する else: # 要素が同じ集合にある=頂点が連結している uf.union(E[j][0], E[j][1]) # グラフ全体が連結なら、任意の頂点を含む集合のサイズが N のはず if uf.size(0) != N: ans += 1 print(ans) if __name__ == "__main__": main()
false
28.070175
[ "-import math", "-def get_edges_include_node(i, Edges): # 頂点 i を含む辺のリストを返す", "- es = []", "- for e in Edges:", "- if i in e:", "- es.append(e)", "- return es", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.parents = [-1] * n", "+ def find(self, x):", "+ if self.parents[x] < 0:", "+ return x", "+ else:", "+ self.parents[x] = self.find(self.parents[x])", "+ return self.parents[x]", "-def dfs(i, e0, goal, Edges): # 頂点 i から頂点 j にたどり着けるかどうか", "- if e0 in Edges:", "- Edges.remove(e0)", "- for e1 in get_edges_include_node(i, Edges):", "- if goal in e1:", "- return True", "- else:", "- ni = e1[1] if e1[0] == i else e1[0]", "- if dfs(ni, e1, goal, Edges):", "- return True", "- return False", "+ def union(self, x, y):", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ if self.parents[x] > self.parents[y]:", "+ x, y = y, x", "+ self.parents[x] += self.parents[y]", "+ self.parents[y] = x", "+", "+ def size(self, x):", "+ return -self.parents[self.find(x)]", "- Edges = []", "- for _ in range(M):", "+ E = []", "+ for i in range(M):", "- Edges.append((a, b))", "+ E.append((a - 1, b - 1))", "- for e in Edges:", "- tmp = []", "- for e2 in Edges:", "- tmp.append((e2[0], e2[1]))", "- if not dfs(e[0], e, e[1], tmp):", "+ # i 番目の辺を取り除いても、全ての頂点が連結しているか?", "+ # Union-Find で連結グラフか判定する", "+ for i in range(M):", "+ uf = UnionFind(N) # 最初、全ての頂点が非連結の状態", "+ for j in range(M):", "+ if i == j:", "+ pass # i 番目の辺を無視する", "+ else:", "+ # 要素が同じ集合にある=頂点が連結している", "+ uf.union(E[j][0], E[j][1])", "+ # グラフ全体が連結なら、任意の頂点を含む集合のサイズが N のはず", "+ if uf.size(0) != N:" ]
false
0.049271
0.047596
1.0352
[ "s848062583", "s987015990" ]
u271934630
p03212
python
s345481829
s977433045
356
92
55,004
2,940
Accepted
Accepted
74.16
n = int(eval(input())) def dfs(s): if int(s) > n: return 0 ret = 1 if all(s.count(c) > 0 for c in '753') else 0 for c in '753': ret += dfs(s+c) return ret print((dfs('0')))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): N = int(eval(input())) def dfs(s): if int(s) > N: return 0 ret = 1 if all(s.count(c) for c in '357') else 0 for c in '357': ret += dfs(s+c) return ret print((dfs('0'))) if __name__ == '__main__': main()
11
21
208
374
n = int(eval(input())) def dfs(s): if int(s) > n: return 0 ret = 1 if all(s.count(c) > 0 for c in "753") else 0 for c in "753": ret += dfs(s + c) return ret print((dfs("0")))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def main(): N = int(eval(input())) def dfs(s): if int(s) > N: return 0 ret = 1 if all(s.count(c) for c in "357") else 0 for c in "357": ret += dfs(s + c) return ret print((dfs("0"))) if __name__ == "__main__": main()
false
47.619048
[ "-n = int(eval(input()))", "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)", "-def dfs(s):", "- if int(s) > n:", "- return 0", "- ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0", "- for c in \"753\":", "- ret += dfs(s + c)", "- return ret", "+def main():", "+ N = int(eval(input()))", "+", "+ def dfs(s):", "+ if int(s) > N:", "+ return 0", "+ ret = 1 if all(s.count(c) for c in \"357\") else 0", "+ for c in \"357\":", "+ ret += dfs(s + c)", "+ return ret", "+", "+ print((dfs(\"0\")))", "-print((dfs(\"0\")))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.288239
0.078585
3.667851
[ "s345481829", "s977433045" ]
u492910842
p03624
python
s199946151
s954469188
84
65
76,108
62,420
Accepted
Accepted
22.62
import string s = list(eval(input())) alpha = list(string.ascii_lowercase) n = len(alpha) ans = "None" for i in range(n): if alpha[i] not in s: ans = alpha[i] break print(ans)
import sys s=eval(input()) for i in range(ord("a"),ord("z")+1): if chr(i) not in s: print((chr(i))) sys.exit() print("None")
11
7
190
132
import string s = list(eval(input())) alpha = list(string.ascii_lowercase) n = len(alpha) ans = "None" for i in range(n): if alpha[i] not in s: ans = alpha[i] break print(ans)
import sys s = eval(input()) for i in range(ord("a"), ord("z") + 1): if chr(i) not in s: print((chr(i))) sys.exit() print("None")
false
36.363636
[ "-import string", "+import sys", "-s = list(eval(input()))", "-alpha = list(string.ascii_lowercase)", "-n = len(alpha)", "-ans = \"None\"", "-for i in range(n):", "- if alpha[i] not in s:", "- ans = alpha[i]", "- break", "-print(ans)", "+s = eval(input())", "+for i in range(ord(\"a\"), ord(\"z\") + 1):", "+ if chr(i) not in s:", "+ print((chr(i)))", "+ sys.exit()", "+print(\"None\")" ]
false
0.04979
0.041752
1.192514
[ "s199946151", "s954469188" ]
u150984829
p02315
python
s296928779
s597628251
370
340
5,928
5,916
Accepted
Accepted
8.11
import sys W=int(input().split()[1]) C=[0]*-~W for e in sys.stdin: v,w=list(map(int,e.split())) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[i]=t print((C[W]))
N,W=list(map(int,input().split())) C=[0]*-~W for _ in[0]*N: v,w=list(map(int,input().split())) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[i]=t print((C[W]))
9
8
170
162
import sys W = int(input().split()[1]) C = [0] * -~W for e in sys.stdin: v, w = list(map(int, e.split())) for i in range(W, w - 1, -1): t = v + C[i - w] if t > C[i]: C[i] = t print((C[W]))
N, W = list(map(int, input().split())) C = [0] * -~W for _ in [0] * N: v, w = list(map(int, input().split())) for i in range(W, w - 1, -1): t = v + C[i - w] if t > C[i]: C[i] = t print((C[W]))
false
11.111111
[ "-import sys", "-", "-W = int(input().split()[1])", "+N, W = list(map(int, input().split()))", "-for e in sys.stdin:", "- v, w = list(map(int, e.split()))", "+for _ in [0] * N:", "+ v, w = list(map(int, input().split()))" ]
false
0.040837
0.038971
1.047885
[ "s296928779", "s597628251" ]
u534308356
p02909
python
s303196790
s225813719
205
176
38,384
38,256
Accepted
Accepted
14.15
s = eval(input()) if s == "Sunny": print("Cloudy") elif s == "Cloudy": print("Rainy") elif s == "Rainy": print("Sunny")
data = ['Sunny', 'Cloudy', 'Rainy'] s = eval(input()) if s == data[0]: print((data[1])) elif s == data[1]: print((data[2])) else: print((data[0]))
7
8
125
147
s = eval(input()) if s == "Sunny": print("Cloudy") elif s == "Cloudy": print("Rainy") elif s == "Rainy": print("Sunny")
data = ["Sunny", "Cloudy", "Rainy"] s = eval(input()) if s == data[0]: print((data[1])) elif s == data[1]: print((data[2])) else: print((data[0]))
false
12.5
[ "+data = [\"Sunny\", \"Cloudy\", \"Rainy\"]", "-if s == \"Sunny\":", "- print(\"Cloudy\")", "-elif s == \"Cloudy\":", "- print(\"Rainy\")", "-elif s == \"Rainy\":", "- print(\"Sunny\")", "+if s == data[0]:", "+ print((data[1]))", "+elif s == data[1]:", "+ print((data[2]))", "+else:", "+ print((data[0]))" ]
false
0.042645
0.042781
0.996812
[ "s303196790", "s225813719" ]
u179169725
p03208
python
s153070613
s152905842
351
314
17,184
18,400
Accepted
Accepted
10.54
N,K=list(map(int,input().split())) H=[int(eval(input())) for _ in range(N)] H.sort() import numpy as np H=np.array(H) print(((H[K-1:]-H[:-K+1]).min()))
N,K=list(map(int,input().split())) import numpy as np H=np.array([int(eval(input())) for _ in range(N)]) H.sort() print(((H[K-1:]-H[:-K+1]).min()))
6
5
143
138
N, K = list(map(int, input().split())) H = [int(eval(input())) for _ in range(N)] H.sort() import numpy as np H = np.array(H) print(((H[K - 1 :] - H[: -K + 1]).min()))
N, K = list(map(int, input().split())) import numpy as np H = np.array([int(eval(input())) for _ in range(N)]) H.sort() print(((H[K - 1 :] - H[: -K + 1]).min()))
false
16.666667
[ "-H = [int(eval(input())) for _ in range(N)]", "-H.sort()", "-H = np.array(H)", "+H = np.array([int(eval(input())) for _ in range(N)])", "+H.sort()" ]
false
0.280911
0.4481
0.626893
[ "s153070613", "s152905842" ]
u643542669
p02397
python
s365894102
s068157449
60
50
5,608
5,612
Accepted
Accepted
16.67
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break if x > y: z = x x = y y = z print((x, y))
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break if x > y: x, y = y, x print((x, y))
12
10
175
151
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break if x > y: z = x x = y y = z print((x, y))
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break if x > y: x, y = y, x print((x, y))
false
16.666667
[ "- z = x", "- x = y", "- y = z", "+ x, y = y, x" ]
false
0.082842
0.00786
10.540214
[ "s365894102", "s068157449" ]
u096294926
p02767
python
s669248289
s877634283
35
21
5,084
3,060
Accepted
Accepted
40
import math from statistics import mean, median,variance,stdev N = int(eval(input())) X = list(map(int,input().split())) a = sum(X) ave = round(a/N) b = 0 for i in range(N): b +=(X[i]-ave)**2 print(b)
N = int(eval(input())) X = list(map(int,input().split())) ans = 10**8 c = int() for i in range(1,100): c = 0 for j in range(len(X)): c += (X[j]-i)**2 if c < ans: ans = c print(ans)
10
11
207
212
import math from statistics import mean, median, variance, stdev N = int(eval(input())) X = list(map(int, input().split())) a = sum(X) ave = round(a / N) b = 0 for i in range(N): b += (X[i] - ave) ** 2 print(b)
N = int(eval(input())) X = list(map(int, input().split())) ans = 10**8 c = int() for i in range(1, 100): c = 0 for j in range(len(X)): c += (X[j] - i) ** 2 if c < ans: ans = c print(ans)
false
9.090909
[ "-import math", "-from statistics import mean, median, variance, stdev", "-", "-a = sum(X)", "-ave = round(a / N)", "-b = 0", "-for i in range(N):", "- b += (X[i] - ave) ** 2", "-print(b)", "+ans = 10**8", "+c = int()", "+for i in range(1, 100):", "+ c = 0", "+ for j in range(len(X)):", "+ c += (X[j] - i) ** 2", "+ if c < ans:", "+ ans = c", "+print(ans)" ]
false
0.044926
0.04489
1.000817
[ "s669248289", "s877634283" ]
u366996583
p02658
python
s730073046
s475161881
59
54
21,592
21,660
Accepted
Accepted
8.47
n=int(eval(input())) a=list(map(int,input().split())) b=1 if 0 in a: print((0)) else: for i in range(n): b*=a[i] if b>10**18: print((-1)) exit() print(b)
n=int(eval(input())) a=list(map(int,input().split())) t=1 for i in range(n): t*=a[i] if t>10**18: if not(0 in a): print((-1)) exit() else: print((0)) exit() print(t)
12
13
180
203
n = int(eval(input())) a = list(map(int, input().split())) b = 1 if 0 in a: print((0)) else: for i in range(n): b *= a[i] if b > 10**18: print((-1)) exit() print(b)
n = int(eval(input())) a = list(map(int, input().split())) t = 1 for i in range(n): t *= a[i] if t > 10**18: if not (0 in a): print((-1)) exit() else: print((0)) exit() print(t)
false
7.692308
[ "-b = 1", "-if 0 in a:", "- print((0))", "-else:", "- for i in range(n):", "- b *= a[i]", "- if b > 10**18:", "+t = 1", "+for i in range(n):", "+ t *= a[i]", "+ if t > 10**18:", "+ if not (0 in a):", "- print(b)", "+ else:", "+ print((0))", "+ exit()", "+print(t)" ]
false
0.040618
0.056277
0.721759
[ "s730073046", "s475161881" ]
u893063840
p03796
python
s598651425
s346668544
231
35
4,028
2,940
Accepted
Accepted
84.85
n = int(eval(input())) from math import factorial power = factorial(n) mod = 10 ** 9 + 7 ans = power % mod print(ans)
n = int(eval(input())) mod = 10 ** 9 + 7 power = 1 for i in range(1, n + 1): power = i * power % mod print(power)
8
8
121
121
n = int(eval(input())) from math import factorial power = factorial(n) mod = 10**9 + 7 ans = power % mod print(ans)
n = int(eval(input())) mod = 10**9 + 7 power = 1 for i in range(1, n + 1): power = i * power % mod print(power)
false
0
[ "-from math import factorial", "-", "-power = factorial(n)", "-ans = power % mod", "-print(ans)", "+power = 1", "+for i in range(1, n + 1):", "+ power = i * power % mod", "+print(power)" ]
false
0.236122
0.067334
3.506744
[ "s598651425", "s346668544" ]
u721316601
p02959
python
s211874766
s343613745
238
174
18,624
18,476
Accepted
Accepted
26.89
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 for i in range(N): ans += min(A[i], B[i]) B[i] -= min(A[i], B[i]) ans += min(A[i+1], B[i]) A[i+1] -= min(A[i+1], B[i]) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = sum(A) for i in range(N): n = min(A[i], B[i]) A[i] -= n B[i] -= n if B[i] > 0: A[i+1] = max(0, A[i+1]-B[i]) print((ans - sum(A)))
11
14
253
259
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 for i in range(N): ans += min(A[i], B[i]) B[i] -= min(A[i], B[i]) ans += min(A[i + 1], B[i]) A[i + 1] -= min(A[i + 1], B[i]) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = sum(A) for i in range(N): n = min(A[i], B[i]) A[i] -= n B[i] -= n if B[i] > 0: A[i + 1] = max(0, A[i + 1] - B[i]) print((ans - sum(A)))
false
21.428571
[ "-ans = 0", "+ans = sum(A)", "- ans += min(A[i], B[i])", "- B[i] -= min(A[i], B[i])", "- ans += min(A[i + 1], B[i])", "- A[i + 1] -= min(A[i + 1], B[i])", "-print(ans)", "+ n = min(A[i], B[i])", "+ A[i] -= n", "+ B[i] -= n", "+ if B[i] > 0:", "+ A[i + 1] = max(0, A[i + 1] - B[i])", "+print((ans - sum(A)))" ]
false
0.150601
0.036292
4.149709
[ "s211874766", "s343613745" ]
u077291787
p02901
python
s152506096
s911879830
793
552
3,188
3,188
Accepted
Accepted
30.39
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 2 ** N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(2 ** (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 1 << N INF = 10 ** 10 dp = [INF] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != INF else -1 print(ans) if __name__ == "__main__": main()
21
22
529
531
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 2**N dp = [float("inf")] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(2 ** (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != float("inf") else -1 print(ans) if __name__ == "__main__": main()
# ABC142E - Get Everything import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) p = 1 << N INF = 10**10 dp = [INF] * p dp[0] = 0 for _ in range(M): a, _ = list(map(int, input().split())) x = sum(1 << (i - 1) for i in map(int, input().split())) for y in range(p): if dp[x | y] > dp[y] + a: dp[x | y] = dp[y] + a ans = dp[-1] if dp[-1] != INF else -1 print(ans) if __name__ == "__main__": main()
false
4.545455
[ "- p = 2**N", "- dp = [float(\"inf\")] * p", "+ p = 1 << N", "+ INF = 10**10", "+ dp = [INF] * p", "- x = sum(2 ** (i - 1) for i in map(int, input().split()))", "+ x = sum(1 << (i - 1) for i in map(int, input().split()))", "- ans = dp[-1] if dp[-1] != float(\"inf\") else -1", "+ ans = dp[-1] if dp[-1] != INF else -1" ]
false
0.046909
0.047231
0.99319
[ "s152506096", "s911879830" ]
u790905630
p03240
python
s836450509
s357974911
34
27
3,064
3,064
Accepted
Accepted
20.59
from math import * N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_input_list: if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)): break else: print(("%s %s %s" % (cx, cy, H))) exit()
from math import * import sys N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_input_list: if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)): break else: print(("%s %s %s" % (cx, cy, H))) sys.exit(0)
14
15
526
520
from math import * N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_input_list: if input_list[2] != max( H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0 ): break else: print(("%s %s %s" % (cx, cy, H))) exit()
from math import * import sys N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_input_list: if input_list[2] != max( H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0 ): break else: print(("%s %s %s" % (cx, cy, H))) sys.exit(0)
false
6.666667
[ "+import sys", "-x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]", "+x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1]", "- exit()", "+ sys.exit(0)" ]
false
0.121645
0.04769
2.550734
[ "s836450509", "s357974911" ]
u528470578
p03163
python
s886923817
s508742379
686
497
144,484
120,044
Accepted
Accepted
27.55
# Educational DP Contest D-knapsack def knapsack(N, W, wv): # initialize dp = [list(0 for _ in range(W+1)) for j in range(N+1)] # DP for i in range(N): for j in range(W+1): if j >= wv[i][0]: dp[i+1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1]) else: dp[i+1][j] = dp[i][j] return dp[N][W] if __name__ == "__main__": N, W = list(map(int, input().split())) wv = [] for _ in range(N): wv.append(list(map(int, input().split()))) print((knapsack(N, W, wv)))
N, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(N)] dp = [] for _ in range(N+1): dp.append([0] * (W+1)) for i in range(N): for j in range(W+1): if j >= wv[i][0]: dp[i+1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1]) else: dp[i+1][j] = dp[i][j] print((dp[N][W]))
21
14
584
365
# Educational DP Contest D-knapsack def knapsack(N, W, wv): # initialize dp = [list(0 for _ in range(W + 1)) for j in range(N + 1)] # DP for i in range(N): for j in range(W + 1): if j >= wv[i][0]: dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1]) else: dp[i + 1][j] = dp[i][j] return dp[N][W] if __name__ == "__main__": N, W = list(map(int, input().split())) wv = [] for _ in range(N): wv.append(list(map(int, input().split()))) print((knapsack(N, W, wv)))
N, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(N)] dp = [] for _ in range(N + 1): dp.append([0] * (W + 1)) for i in range(N): for j in range(W + 1): if j >= wv[i][0]: dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1]) else: dp[i + 1][j] = dp[i][j] print((dp[N][W]))
false
33.333333
[ "-# Educational DP Contest D-knapsack", "-def knapsack(N, W, wv):", "- # initialize", "- dp = [list(0 for _ in range(W + 1)) for j in range(N + 1)]", "- # DP", "- for i in range(N):", "- for j in range(W + 1):", "- if j >= wv[i][0]:", "- dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])", "- else:", "- dp[i + 1][j] = dp[i][j]", "- return dp[N][W]", "-", "-", "-if __name__ == \"__main__\":", "- N, W = list(map(int, input().split()))", "- wv = []", "- for _ in range(N):", "- wv.append(list(map(int, input().split())))", "- print((knapsack(N, W, wv)))", "+N, W = list(map(int, input().split()))", "+wv = [list(map(int, input().split())) for _ in range(N)]", "+dp = []", "+for _ in range(N + 1):", "+ dp.append([0] * (W + 1))", "+for i in range(N):", "+ for j in range(W + 1):", "+ if j >= wv[i][0]:", "+ dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])", "+ else:", "+ dp[i + 1][j] = dp[i][j]", "+print((dp[N][W]))" ]
false
0.045584
0.074727
0.610008
[ "s886923817", "s508742379" ]
u564902833
p02952
python
s997111587
s093925057
49
17
2,940
2,940
Accepted
Accepted
65.31
N = int(eval(input())) ans = sum(len(str(i)) % 2 == 1 for i in range(1, N + 1)) print(ans)
N = int(eval(input())) ans = min(9, N) + max(0, min(999, N) - 99) + max(0, min(99999, N) - 9999) print(ans)
5
5
91
108
N = int(eval(input())) ans = sum(len(str(i)) % 2 == 1 for i in range(1, N + 1)) print(ans)
N = int(eval(input())) ans = min(9, N) + max(0, min(999, N) - 99) + max(0, min(99999, N) - 9999) print(ans)
false
0
[ "-ans = sum(len(str(i)) % 2 == 1 for i in range(1, N + 1))", "+ans = min(9, N) + max(0, min(999, N) - 99) + max(0, min(99999, N) - 9999)" ]
false
0.038807
0.04247
0.913759
[ "s997111587", "s093925057" ]
u926080943
p02755
python
s585532999
s453235982
177
17
38,768
3,064
Accepted
Accepted
90.4
def main(): a, b = list(map(int, input().split())) eight = [i for i in range(0, 2000) if a == int(i * 0.08)] ten = [i for i in range(0, 2000) if b == int(i * 0.1)] for i in eight: for j in ten: if i == j: print(i) return print((-1)) if __name__ == '__main__': main()
def main(): a, b = list(map(int, input().split())) al = int(a / 0.08 + 0.5) bl = int(b / 0.1) au = al + 12 - a % 2 bu = bl + 9 if bu < al or au < bl: print((-1)) else: print((max(al, bl))) if __name__ == '__main__': main()
14
14
350
276
def main(): a, b = list(map(int, input().split())) eight = [i for i in range(0, 2000) if a == int(i * 0.08)] ten = [i for i in range(0, 2000) if b == int(i * 0.1)] for i in eight: for j in ten: if i == j: print(i) return print((-1)) if __name__ == "__main__": main()
def main(): a, b = list(map(int, input().split())) al = int(a / 0.08 + 0.5) bl = int(b / 0.1) au = al + 12 - a % 2 bu = bl + 9 if bu < al or au < bl: print((-1)) else: print((max(al, bl))) if __name__ == "__main__": main()
false
0
[ "- eight = [i for i in range(0, 2000) if a == int(i * 0.08)]", "- ten = [i for i in range(0, 2000) if b == int(i * 0.1)]", "- for i in eight:", "- for j in ten:", "- if i == j:", "- print(i)", "- return", "- print((-1))", "+ al = int(a / 0.08 + 0.5)", "+ bl = int(b / 0.1)", "+ au = al + 12 - a % 2", "+ bu = bl + 9", "+ if bu < al or au < bl:", "+ print((-1))", "+ else:", "+ print((max(al, bl)))" ]
false
0.047714
0.042513
1.122341
[ "s585532999", "s453235982" ]
u200887663
p03610
python
s709220548
s003407751
52
47
6,440
9,368
Accepted
Accepted
9.62
sl=list(input()) n=len(sl) li=[] for i in range(1,n+1) : if i % 2 != 0 : li.append(sl[i-1]) print(*li,sep="")
#n = int(input()) #a, b = map(int,input().split()) #l = list(map(int,input().split())) #l = [list(map(int,input().split())) for i in range(n)] s = list(eval(input())) ans = '' for i, si in enumerate(s): if (i+1) % 2 != 0: ans += si print(ans)
8
10
124
258
sl = list(input()) n = len(sl) li = [] for i in range(1, n + 1): if i % 2 != 0: li.append(sl[i - 1]) print(*li, sep="")
# n = int(input()) # a, b = map(int,input().split()) # l = list(map(int,input().split())) # l = [list(map(int,input().split())) for i in range(n)] s = list(eval(input())) ans = "" for i, si in enumerate(s): if (i + 1) % 2 != 0: ans += si print(ans)
false
20
[ "-sl = list(input())", "-n = len(sl)", "-li = []", "-for i in range(1, n + 1):", "- if i % 2 != 0:", "- li.append(sl[i - 1])", "-print(*li, sep=\"\")", "+# n = int(input())", "+# a, b = map(int,input().split())", "+# l = list(map(int,input().split()))", "+# l = [list(map(int,input().split())) for i in range(n)]", "+s = list(eval(input()))", "+ans = \"\"", "+for i, si in enumerate(s):", "+ if (i + 1) % 2 != 0:", "+ ans += si", "+print(ans)" ]
false
0.039249
0.039374
0.996811
[ "s709220548", "s003407751" ]
u002459665
p03575
python
s260929483
s558879104
26
22
3,064
3,064
Accepted
Accepted
15.38
""" 解説PDFを見ながら実装 https://img.atcoder.jp/abc075/editorial.pdf """ def dfs(v, graph, visited, n): # 出発点 visited[v] = True for i in range(n): # 辺がない if graph[v][i] == False: continue # 訪問済み if visited[i] == True: continue # 辺があったらそこから訪問する dfs(i, graph, visited, n) def main(): N, M = list(map(int, input().split())) graph = [] for _ in range(N): row = [False] * N graph.append(row) A = [] B = [] for _ in range(M): a, b = list(map(int, input().split())) a = a - 1 b = b - 1 A.append(a) B.append(b) graph[a][b] = True graph[b][a] = True # print(graph) ans = 0 for i in range(M): # 辺を削除 graph[A[i]][B[i]] = False graph[B[i]][A[i]] = False visited = [False] * N # 常に0番目の頂点から出発 dfs(0, graph, visited, N) bridge = False for j in range(N): if visited[j] == False: bridge = True if bridge: ans += 1 # 辺を戻す graph[A[i]][B[i]] = True graph[B[i]][A[i]] = True print(ans) if __name__ == "__main__": main()
def main(): N, M = list(map(int, input().split())) AB = [] for _ in range(M): a, b = list(map(int, input().split())) AB.append([a-1, b-1]) # グラフを表現する(辺のある・なし) graph = [] for _ in range(N): graph.append([False] * N) for a, b in AB: graph[a][b] = True graph[b][a] = True visited = [False] * N def dfs(v): """v(頂点)からスタートする""" # 到達済みだったらreturn if visited[v]: return # 到達した印 visited[v] = True # そのさきへ(vと繋がっている) edges = graph[v] for i, e in enumerate(edges): if e: dfs(i) return ans = 0 # 辺を一つずつ消してみて、橋かどうかを調べる for a, b in AB: graph[a][b] = False graph[b][a] = False visited = [False] * N dfs(0) # 全てTrueというわけではない(Falseが一つでもある場合) if not all(visited): ans += 1 graph[a][b] = True graph[b][a] = True print(ans) if __name__ == "__main__": main()
66
59
1,304
1,119
""" 解説PDFを見ながら実装 https://img.atcoder.jp/abc075/editorial.pdf """ def dfs(v, graph, visited, n): # 出発点 visited[v] = True for i in range(n): # 辺がない if graph[v][i] == False: continue # 訪問済み if visited[i] == True: continue # 辺があったらそこから訪問する dfs(i, graph, visited, n) def main(): N, M = list(map(int, input().split())) graph = [] for _ in range(N): row = [False] * N graph.append(row) A = [] B = [] for _ in range(M): a, b = list(map(int, input().split())) a = a - 1 b = b - 1 A.append(a) B.append(b) graph[a][b] = True graph[b][a] = True # print(graph) ans = 0 for i in range(M): # 辺を削除 graph[A[i]][B[i]] = False graph[B[i]][A[i]] = False visited = [False] * N # 常に0番目の頂点から出発 dfs(0, graph, visited, N) bridge = False for j in range(N): if visited[j] == False: bridge = True if bridge: ans += 1 # 辺を戻す graph[A[i]][B[i]] = True graph[B[i]][A[i]] = True print(ans) if __name__ == "__main__": main()
def main(): N, M = list(map(int, input().split())) AB = [] for _ in range(M): a, b = list(map(int, input().split())) AB.append([a - 1, b - 1]) # グラフを表現する(辺のある・なし) graph = [] for _ in range(N): graph.append([False] * N) for a, b in AB: graph[a][b] = True graph[b][a] = True visited = [False] * N def dfs(v): """v(頂点)からスタートする""" # 到達済みだったらreturn if visited[v]: return # 到達した印 visited[v] = True # そのさきへ(vと繋がっている) edges = graph[v] for i, e in enumerate(edges): if e: dfs(i) return ans = 0 # 辺を一つずつ消してみて、橋かどうかを調べる for a, b in AB: graph[a][b] = False graph[b][a] = False visited = [False] * N dfs(0) # 全てTrueというわけではない(Falseが一つでもある場合) if not all(visited): ans += 1 graph[a][b] = True graph[b][a] = True print(ans) if __name__ == "__main__": main()
false
10.606061
[ "-\"\"\"", "-解説PDFを見ながら実装", "-https://img.atcoder.jp/abc075/editorial.pdf", "-\"\"\"", "-", "-", "-def dfs(v, graph, visited, n):", "- # 出発点", "- visited[v] = True", "- for i in range(n):", "- # 辺がない", "- if graph[v][i] == False:", "- continue", "- # 訪問済み", "- if visited[i] == True:", "- continue", "- # 辺があったらそこから訪問する", "- dfs(i, graph, visited, n)", "-", "-", "+ AB = []", "+ for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ AB.append([a - 1, b - 1])", "+ # グラフを表現する(辺のある・なし)", "- row = [False] * N", "- graph.append(row)", "- A = []", "- B = []", "- for _ in range(M):", "- a, b = list(map(int, input().split()))", "- a = a - 1", "- b = b - 1", "- A.append(a)", "- B.append(b)", "+ graph.append([False] * N)", "+ for a, b in AB:", "- # print(graph)", "+ visited = [False] * N", "+", "+ def dfs(v):", "+ \"\"\"v(頂点)からスタートする\"\"\"", "+ # 到達済みだったらreturn", "+ if visited[v]:", "+ return", "+ # 到達した印", "+ visited[v] = True", "+ # そのさきへ(vと繋がっている)", "+ edges = graph[v]", "+ for i, e in enumerate(edges):", "+ if e:", "+ dfs(i)", "+ return", "+", "- for i in range(M):", "- # 辺を削除", "- graph[A[i]][B[i]] = False", "- graph[B[i]][A[i]] = False", "+ # 辺を一つずつ消してみて、橋かどうかを調べる", "+ for a, b in AB:", "+ graph[a][b] = False", "+ graph[b][a] = False", "- # 常に0番目の頂点から出発", "- dfs(0, graph, visited, N)", "- bridge = False", "- for j in range(N):", "- if visited[j] == False:", "- bridge = True", "- if bridge:", "+ dfs(0)", "+ # 全てTrueというわけではない(Falseが一つでもある場合)", "+ if not all(visited):", "- # 辺を戻す", "- graph[A[i]][B[i]] = True", "- graph[B[i]][A[i]] = True", "+ graph[a][b] = True", "+ graph[b][a] = True" ]
false
0.048625
0.04119
1.180512
[ "s260929483", "s558879104" ]
u021019433
p03038
python
s246316344
s216903484
864
797
24,168
20,872
Accepted
Accepted
7.75
import heapq from collections import Counter from itertools import starmap from operator import mul R = lambda: list(map(int, input().split())) n, m = R() a = list(Counter(R()).items()) heapq.heapify(a) for _ in range(m): b, c = R() i = b while i: x, y = a[0] if x >= c: break d = min(i, y) i -= d y -= d if y: heapq.heapreplace(a, (x, y)) else: heapq.heappop(a) heapq.heappush(a, (c, b - i)) print((sum(starmap(mul, a))))
import heapq from itertools import repeat, starmap from operator import mul R = lambda: list(map(int, input().split())) n, m = R() a = list(zip(R(), repeat(1))) heapq.heapify(a) for _ in range(m): b, c = R() i = b while i: x, y = a[0] if x >= c: break d = min(i, y) i -= d y -= d if y: heapq.heapreplace(a, (x, y)) else: heapq.heappop(a) heapq.heappush(a, (c, b - i)) print((sum(starmap(mul, a))))
25
24
548
522
import heapq from collections import Counter from itertools import starmap from operator import mul R = lambda: list(map(int, input().split())) n, m = R() a = list(Counter(R()).items()) heapq.heapify(a) for _ in range(m): b, c = R() i = b while i: x, y = a[0] if x >= c: break d = min(i, y) i -= d y -= d if y: heapq.heapreplace(a, (x, y)) else: heapq.heappop(a) heapq.heappush(a, (c, b - i)) print((sum(starmap(mul, a))))
import heapq from itertools import repeat, starmap from operator import mul R = lambda: list(map(int, input().split())) n, m = R() a = list(zip(R(), repeat(1))) heapq.heapify(a) for _ in range(m): b, c = R() i = b while i: x, y = a[0] if x >= c: break d = min(i, y) i -= d y -= d if y: heapq.heapreplace(a, (x, y)) else: heapq.heappop(a) heapq.heappush(a, (c, b - i)) print((sum(starmap(mul, a))))
false
4
[ "-from collections import Counter", "-from itertools import starmap", "+from itertools import repeat, starmap", "-a = list(Counter(R()).items())", "+a = list(zip(R(), repeat(1)))" ]
false
0.034177
0.066422
0.514552
[ "s246316344", "s216903484" ]
u347640436
p03274
python
s642554131
s458867878
121
95
14,660
14,564
Accepted
Accepted
21.49
n, k = list(map(int, input().split())) x = list(map(int, input().split())) p = n for i in range(n): if x[i] > 0: p = i break result = float('inf') for i in range(k + 1): if p - i < 0 or p + k - i > n: continue if i == 0: t = min(result, x[p + k - 1]) elif i == k: t = min(result, abs(x[p - k])) else: t = min(result, abs(x[p - i]) * 2 + x[p + (k - i) - 1], abs(x[p - i]) + x[p + (k - i) - 1] * 2) result = min(result, t) print(result)
n, k = list(map(int, input().split())) x = list(map(int, input().split())) p = n for i in range(n): if x[i] > 0: p = i break result = float('inf') for i in range(k + 1): if p - i < 0 or p + k - i > n: continue if i == 0: result = min(result, x[p + k - 1]) elif i == k: result = min(result, -x[p - k]) else: l = x[p - i] r = x[p + (k - i) - 1] result = min(result, r - 2 * l, r * 2 - l) print(result)
19
20
483
455
n, k = list(map(int, input().split())) x = list(map(int, input().split())) p = n for i in range(n): if x[i] > 0: p = i break result = float("inf") for i in range(k + 1): if p - i < 0 or p + k - i > n: continue if i == 0: t = min(result, x[p + k - 1]) elif i == k: t = min(result, abs(x[p - k])) else: t = min( result, abs(x[p - i]) * 2 + x[p + (k - i) - 1], abs(x[p - i]) + x[p + (k - i) - 1] * 2, ) result = min(result, t) print(result)
n, k = list(map(int, input().split())) x = list(map(int, input().split())) p = n for i in range(n): if x[i] > 0: p = i break result = float("inf") for i in range(k + 1): if p - i < 0 or p + k - i > n: continue if i == 0: result = min(result, x[p + k - 1]) elif i == k: result = min(result, -x[p - k]) else: l = x[p - i] r = x[p + (k - i) - 1] result = min(result, r - 2 * l, r * 2 - l) print(result)
false
5
[ "- t = min(result, x[p + k - 1])", "+ result = min(result, x[p + k - 1])", "- t = min(result, abs(x[p - k]))", "+ result = min(result, -x[p - k])", "- t = min(", "- result,", "- abs(x[p - i]) * 2 + x[p + (k - i) - 1],", "- abs(x[p - i]) + x[p + (k - i) - 1] * 2,", "- )", "- result = min(result, t)", "+ l = x[p - i]", "+ r = x[p + (k - i) - 1]", "+ result = min(result, r - 2 * l, r * 2 - l)" ]
false
0.037956
0.066106
0.574171
[ "s642554131", "s458867878" ]
u347640436
p02838
python
s690307777
s908420014
1,826
284
42,156
44,560
Accepted
Accepted
84.45
N = int(eval(input())) A = list(map(int, input().split())) result = 0 for bit in range(60): m = 1 << bit c = sum(a & m for a in A) >> bit result += (c * (N - c)) << bit result %= 1000000007 print(result)
import numpy as np N = int(eval(input())) A = np.fromiter(list(map(int, input().split())), np.int64) result = 0 for bit in range(60): c = int((A & 1).sum()) A >>= 1 result = (result + c * (N - c) * (1 << bit)) % 1000000007 print(result)
10
11
224
243
N = int(eval(input())) A = list(map(int, input().split())) result = 0 for bit in range(60): m = 1 << bit c = sum(a & m for a in A) >> bit result += (c * (N - c)) << bit result %= 1000000007 print(result)
import numpy as np N = int(eval(input())) A = np.fromiter(list(map(int, input().split())), np.int64) result = 0 for bit in range(60): c = int((A & 1).sum()) A >>= 1 result = (result + c * (N - c) * (1 << bit)) % 1000000007 print(result)
false
9.090909
[ "+import numpy as np", "+", "-A = list(map(int, input().split()))", "+A = np.fromiter(list(map(int, input().split())), np.int64)", "- m = 1 << bit", "- c = sum(a & m for a in A) >> bit", "- result += (c * (N - c)) << bit", "- result %= 1000000007", "+ c = int((A & 1).sum())", "+ A >>= 1", "+ result = (result + c * (N - c) * (1 << bit)) % 1000000007" ]
false
0.036979
1.061759
0.034828
[ "s690307777", "s908420014" ]
u263753244
p03854
python
s983008157
s343402864
382
253
65,516
78,096
Accepted
Accepted
33.77
import sys sys.setrecursionlimit(10**6) g=[] def jdream(l,i): if len(l)>=i+5: if l[i:i+5]=="dream": i=i+5 if i==len(l): g.append("Y") return else: jer(l,i) jdream(l,i) return else: return else: return def jerase(l,i): if len(l)>=i+5: if l[i:i+5]=="erase": i=i+5 if i==len(l): g.append("Y") return else: jr(l,i) jerase(l,i) jdream(l,i) return else: return else: return def jer(l,i): if len(l)>=i+2: if l[i:i+2]=="er": i=i+2 if i==len(l): g.append("Y") return else: jase(l,i) jerase(l,i) jdream(l,i) return else: return else: return def jase(l,i): if len(l)>=i+3: if l[i:i+3]=="ase": i=i+3 if i==len(l): g.append("Y") return else: jdream(l,i) jerase(l,i) jr(l,i) return else: return else: return def jr(l,i): if len(l)>=i+1: if l[i:i+1]=="r": i=i+1 if i==len(l): g.append("Y") return else: jdream(l,i) jerase(l,i) return else: return else: return s=eval(input()) n=0 jerase(s,n) n=0 jdream(s,n) if 'Y' in g: print("YES") else: print("NO")
s=eval(input()) n=len(s) dp=list('false'*n) dp[0]="true" if s[0:5]=="dream" or s[0:5]=="erase": for i in range(5): dp[i]="true" if s[0:6]=="eraser": for i in range(6): dp[i]="true" if s[0:7]=="dreamer": for i in range(7): dp[i]="true" for i in range(5,n): if dp[i-5]=="true" and (s[i-4:i+1]=="dream" or s[i-4:i+1]=="erase"): dp[i]="true" if dp[i-6]=="true" and s[i-5:i+1]=="eraser": dp[i]="true" if dp[i-7]=="true" and s[i-6:i+1]=="dreamer": dp[i]="true" if dp[n-1]=="true": print("YES") else: print("NO")
115
28
2,031
612
import sys sys.setrecursionlimit(10**6) g = [] def jdream(l, i): if len(l) >= i + 5: if l[i : i + 5] == "dream": i = i + 5 if i == len(l): g.append("Y") return else: jer(l, i) jdream(l, i) return else: return else: return def jerase(l, i): if len(l) >= i + 5: if l[i : i + 5] == "erase": i = i + 5 if i == len(l): g.append("Y") return else: jr(l, i) jerase(l, i) jdream(l, i) return else: return else: return def jer(l, i): if len(l) >= i + 2: if l[i : i + 2] == "er": i = i + 2 if i == len(l): g.append("Y") return else: jase(l, i) jerase(l, i) jdream(l, i) return else: return else: return def jase(l, i): if len(l) >= i + 3: if l[i : i + 3] == "ase": i = i + 3 if i == len(l): g.append("Y") return else: jdream(l, i) jerase(l, i) jr(l, i) return else: return else: return def jr(l, i): if len(l) >= i + 1: if l[i : i + 1] == "r": i = i + 1 if i == len(l): g.append("Y") return else: jdream(l, i) jerase(l, i) return else: return else: return s = eval(input()) n = 0 jerase(s, n) n = 0 jdream(s, n) if "Y" in g: print("YES") else: print("NO")
s = eval(input()) n = len(s) dp = list("false" * n) dp[0] = "true" if s[0:5] == "dream" or s[0:5] == "erase": for i in range(5): dp[i] = "true" if s[0:6] == "eraser": for i in range(6): dp[i] = "true" if s[0:7] == "dreamer": for i in range(7): dp[i] = "true" for i in range(5, n): if dp[i - 5] == "true" and ( s[i - 4 : i + 1] == "dream" or s[i - 4 : i + 1] == "erase" ): dp[i] = "true" if dp[i - 6] == "true" and s[i - 5 : i + 1] == "eraser": dp[i] = "true" if dp[i - 7] == "true" and s[i - 6 : i + 1] == "dreamer": dp[i] = "true" if dp[n - 1] == "true": print("YES") else: print("NO")
false
75.652174
[ "-import sys", "-", "-sys.setrecursionlimit(10**6)", "-g = []", "-", "-", "-def jdream(l, i):", "- if len(l) >= i + 5:", "- if l[i : i + 5] == \"dream\":", "- i = i + 5", "- if i == len(l):", "- g.append(\"Y\")", "- return", "- else:", "- jer(l, i)", "- jdream(l, i)", "- return", "- else:", "- return", "- else:", "- return", "-", "-", "-def jerase(l, i):", "- if len(l) >= i + 5:", "- if l[i : i + 5] == \"erase\":", "- i = i + 5", "- if i == len(l):", "- g.append(\"Y\")", "- return", "- else:", "- jr(l, i)", "- jerase(l, i)", "- jdream(l, i)", "- return", "- else:", "- return", "- else:", "- return", "-", "-", "-def jer(l, i):", "- if len(l) >= i + 2:", "- if l[i : i + 2] == \"er\":", "- i = i + 2", "- if i == len(l):", "- g.append(\"Y\")", "- return", "- else:", "- jase(l, i)", "- jerase(l, i)", "- jdream(l, i)", "- return", "- else:", "- return", "- else:", "- return", "-", "-", "-def jase(l, i):", "- if len(l) >= i + 3:", "- if l[i : i + 3] == \"ase\":", "- i = i + 3", "- if i == len(l):", "- g.append(\"Y\")", "- return", "- else:", "- jdream(l, i)", "- jerase(l, i)", "- jr(l, i)", "- return", "- else:", "- return", "- else:", "- return", "-", "-", "-def jr(l, i):", "- if len(l) >= i + 1:", "- if l[i : i + 1] == \"r\":", "- i = i + 1", "- if i == len(l):", "- g.append(\"Y\")", "- return", "- else:", "- jdream(l, i)", "- jerase(l, i)", "- return", "- else:", "- return", "- else:", "- return", "-", "-", "-n = 0", "-jerase(s, n)", "-n = 0", "-jdream(s, n)", "-if \"Y\" in g:", "+n = len(s)", "+dp = list(\"false\" * n)", "+dp[0] = \"true\"", "+if s[0:5] == \"dream\" or s[0:5] == \"erase\":", "+ for i in range(5):", "+ dp[i] = \"true\"", "+if s[0:6] == \"eraser\":", "+ for i in range(6):", "+ dp[i] = \"true\"", "+if s[0:7] == \"dreamer\":", "+ for i in range(7):", "+ dp[i] = \"true\"", "+for i in range(5, n):", "+ if dp[i - 5] == \"true\" and (", "+ s[i - 4 : i + 1] == \"dream\" or s[i - 4 : i + 1] == \"erase\"", "+ ):", "+ dp[i] = \"true\"", "+ if dp[i - 6] == \"true\" and s[i - 5 : i + 1] == \"eraser\":", "+ dp[i] = \"true\"", "+ if dp[i - 7] == \"true\" and s[i - 6 : i + 1] == \"dreamer\":", "+ dp[i] = \"true\"", "+if dp[n - 1] == \"true\":" ]
false
0.042476
0.037923
1.120058
[ "s983008157", "s343402864" ]
u726285999
p02632
python
s373926784
s364713326
1,374
1,152
49,300
49,396
Accepted
Accepted
16.16
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip('\n') # ## COMBINATION (MOD) ### N_MAX = 10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 inv = [0] * (N_MAX + 2) inv[0] = 0 # 逆元テーブル計算用テーブル inv[1] = 1 for i in range(2, N_MAX + 2): inv[i] = -inv[MOD % i] * (MOD // i) % MOD # K 文字追加 ans = 0 ln = len(S) p1 = 1 p2 = 1 s2 = pow(26, K, MOD) for i in range(1, K + 2): ans += (p1 * p2 * s2) % MOD ans %= MOD # print(p1, p2, s2) # pre p1 = (p1 * (ln + i - 1) * inv[i]) % MOD p2 = (p2 * 25) % MOD # suf s2 = (s2 * inv[26]) % MOD print(ans)
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip('\n') # ## COMBINATION (MOD) ### N_MAX = 10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 inv = [0] * (N_MAX + 2) inv[0] = 0 # 逆元テーブル計算用テーブル inv[1] = 1 for i in range(2, N_MAX + 2): q, r = divmod(MOD, i) inv[i] = -inv[r] * q % MOD # K 文字追加 ans = 0 ln = len(S) p = pow(26, K, MOD) for i in range(1, K + 2): ans += p % MOD ans %= MOD # pre p = p * (ln + i - 1) * inv[i] * 25 * inv[26] % MOD # suf # s2 = (s2 * inv[26]) % MOD print(ans)
40
37
637
581
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip("\n") # ## COMBINATION (MOD) ### N_MAX = 10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 inv = [0] * (N_MAX + 2) inv[0] = 0 # 逆元テーブル計算用テーブル inv[1] = 1 for i in range(2, N_MAX + 2): inv[i] = -inv[MOD % i] * (MOD // i) % MOD # K 文字追加 ans = 0 ln = len(S) p1 = 1 p2 = 1 s2 = pow(26, K, MOD) for i in range(1, K + 2): ans += (p1 * p2 * s2) % MOD ans %= MOD # print(p1, p2, s2) # pre p1 = (p1 * (ln + i - 1) * inv[i]) % MOD p2 = (p2 * 25) % MOD # suf s2 = (s2 * inv[26]) % MOD print(ans)
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip("\n") # ## COMBINATION (MOD) ### N_MAX = 10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 inv = [0] * (N_MAX + 2) inv[0] = 0 # 逆元テーブル計算用テーブル inv[1] = 1 for i in range(2, N_MAX + 2): q, r = divmod(MOD, i) inv[i] = -inv[r] * q % MOD # K 文字追加 ans = 0 ln = len(S) p = pow(26, K, MOD) for i in range(1, K + 2): ans += p % MOD ans %= MOD # pre p = p * (ln + i - 1) * inv[i] * 25 * inv[26] % MOD # suf # s2 = (s2 * inv[26]) % MOD print(ans)
false
7.5
[ "- inv[i] = -inv[MOD % i] * (MOD // i) % MOD", "+ q, r = divmod(MOD, i)", "+ inv[i] = -inv[r] * q % MOD", "-p1 = 1", "-p2 = 1", "-s2 = pow(26, K, MOD)", "+p = pow(26, K, MOD)", "- ans += (p1 * p2 * s2) % MOD", "+ ans += p % MOD", "- # print(p1, p2, s2)", "- p1 = (p1 * (ln + i - 1) * inv[i]) % MOD", "- p2 = (p2 * 25) % MOD", "+ p = p * (ln + i - 1) * inv[i] * 25 * inv[26] % MOD", "- s2 = (s2 * inv[26]) % MOD", "+ # s2 = (s2 * inv[26]) % MOD" ]
false
0.682421
1.065058
0.640736
[ "s373926784", "s364713326" ]
u933341648
p03775
python
s614530983
s765605788
33
30
2,940
2,940
Accepted
Accepted
9.09
from math import sqrt n = int(eval(input())) for a in range(int(sqrt(n))+1, 0, -1): if n % a == 0: b = n // a res = max(list(map(len, list(map(str, [a, b]))))) break print(res)
n = int(eval(input())) for a in range(int(n**0.5)+1, 0, -1): if n % a == 0: b = n // a res = max(list(map(len, list(map(str, [a, b]))))) break print(res)
11
9
200
174
from math import sqrt n = int(eval(input())) for a in range(int(sqrt(n)) + 1, 0, -1): if n % a == 0: b = n // a res = max(list(map(len, list(map(str, [a, b]))))) break print(res)
n = int(eval(input())) for a in range(int(n**0.5) + 1, 0, -1): if n % a == 0: b = n // a res = max(list(map(len, list(map(str, [a, b]))))) break print(res)
false
18.181818
[ "-from math import sqrt", "-", "-for a in range(int(sqrt(n)) + 1, 0, -1):", "+for a in range(int(n**0.5) + 1, 0, -1):" ]
false
0.007938
0.039327
0.201857
[ "s614530983", "s765605788" ]
u761320129
p03166
python
s934685235
s967580932
570
271
32,936
40,764
Accepted
Accepted
52.46
N,M = list(map(int,input().split())) es = [tuple([int(x)-1 for x in input().split()]) for i in range(M)] indeg = [0 for i in range(N)] outdeg = [[] for i in range(N)] for a,b in es: indeg[b] += 1 outdeg[a].append(b) heads = [] for i in range(N): if indeg[i]: continue heads.append(i) dp = [0] * N while heads: a = heads.pop() for b in outdeg[a]: indeg[b] -= 1 if indeg[b] == 0: heads.append(b) dp[b] = max(dp[b], dp[a] + 1) print((max(dp)))
import sys input = sys.stdin.readline N,M = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for i in range(M)] es = [[] for _ in range(N)] indeg = [0] * N for x,y in XY: x,y = x-1,y-1 es[x].append(y) indeg[y] += 1 from collections import deque q = deque() for i in range(N): if indeg[i] == 0: q.append(i) dp = [0] * N while q: v = q.popleft() for to in es[v]: indeg[to] -= 1 if indeg[to] == 0: q.append(to) dp[to] = max(dp[to], dp[v] + 1) print((max(dp)))
23
27
520
554
N, M = list(map(int, input().split())) es = [tuple([int(x) - 1 for x in input().split()]) for i in range(M)] indeg = [0 for i in range(N)] outdeg = [[] for i in range(N)] for a, b in es: indeg[b] += 1 outdeg[a].append(b) heads = [] for i in range(N): if indeg[i]: continue heads.append(i) dp = [0] * N while heads: a = heads.pop() for b in outdeg[a]: indeg[b] -= 1 if indeg[b] == 0: heads.append(b) dp[b] = max(dp[b], dp[a] + 1) print((max(dp)))
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) XY = [tuple(map(int, input().split())) for i in range(M)] es = [[] for _ in range(N)] indeg = [0] * N for x, y in XY: x, y = x - 1, y - 1 es[x].append(y) indeg[y] += 1 from collections import deque q = deque() for i in range(N): if indeg[i] == 0: q.append(i) dp = [0] * N while q: v = q.popleft() for to in es[v]: indeg[to] -= 1 if indeg[to] == 0: q.append(to) dp[to] = max(dp[to], dp[v] + 1) print((max(dp)))
false
14.814815
[ "+import sys", "+", "+input = sys.stdin.readline", "-es = [tuple([int(x) - 1 for x in input().split()]) for i in range(M)]", "-indeg = [0 for i in range(N)]", "-outdeg = [[] for i in range(N)]", "-for a, b in es:", "- indeg[b] += 1", "- outdeg[a].append(b)", "-heads = []", "+XY = [tuple(map(int, input().split())) for i in range(M)]", "+es = [[] for _ in range(N)]", "+indeg = [0] * N", "+for x, y in XY:", "+ x, y = x - 1, y - 1", "+ es[x].append(y)", "+ indeg[y] += 1", "+from collections import deque", "+", "+q = deque()", "- if indeg[i]:", "- continue", "- heads.append(i)", "+ if indeg[i] == 0:", "+ q.append(i)", "-while heads:", "- a = heads.pop()", "- for b in outdeg[a]:", "- indeg[b] -= 1", "- if indeg[b] == 0:", "- heads.append(b)", "- dp[b] = max(dp[b], dp[a] + 1)", "+while q:", "+ v = q.popleft()", "+ for to in es[v]:", "+ indeg[to] -= 1", "+ if indeg[to] == 0:", "+ q.append(to)", "+ dp[to] = max(dp[to], dp[v] + 1)" ]
false
0.065378
0.043015
1.519876
[ "s934685235", "s967580932" ]
u777283665
p03457
python
s457325757
s628563041
617
369
47,592
3,064
Accepted
Accepted
40.19
def validation(l1, l2): dif_t = abs(l2[0] - l1[0]) dif_x = abs(l2[1] - l1[1]) dif_y = l2[2] - l1[2] if dif_x + dif_y > dif_t: return False elif dif_t % 2 == 0: if (dif_x + dif_y) % 2 != 0: return False else: return True elif dif_t % 2 != 0: if (dif_x + dif_y) % 2 == 0: return False return True else: return True n = int(eval(input())) l1 = [0,0,0] ans = "Yes" for _ in range(n): l2 = list(map(int, input().split())) if validation(l1, l2): l1 = l2 else: ans = "No" print(ans)
n = int(eval(input())) current_time = 0 current_pos = 0 ans = True for _ in range(n): t, x, y = list(map(int, input().split())) time_dif = t - current_time # 3 pos_dif = (x+y) - current_pos # 3 if time_dif % 2 == 1 and pos_dif % 2 == 1 and pos_dif <= time_dif: current_time += time_dif current_pos += pos_dif elif time_dif % 2 == 0 and pos_dif % 2 == 0 and pos_dif <= time_dif: current_time += time_dif current_pos += pos_dif else: ans = False if ans: print("Yes") else: print("No")
30
21
572
564
def validation(l1, l2): dif_t = abs(l2[0] - l1[0]) dif_x = abs(l2[1] - l1[1]) dif_y = l2[2] - l1[2] if dif_x + dif_y > dif_t: return False elif dif_t % 2 == 0: if (dif_x + dif_y) % 2 != 0: return False else: return True elif dif_t % 2 != 0: if (dif_x + dif_y) % 2 == 0: return False return True else: return True n = int(eval(input())) l1 = [0, 0, 0] ans = "Yes" for _ in range(n): l2 = list(map(int, input().split())) if validation(l1, l2): l1 = l2 else: ans = "No" print(ans)
n = int(eval(input())) current_time = 0 current_pos = 0 ans = True for _ in range(n): t, x, y = list(map(int, input().split())) time_dif = t - current_time # 3 pos_dif = (x + y) - current_pos # 3 if time_dif % 2 == 1 and pos_dif % 2 == 1 and pos_dif <= time_dif: current_time += time_dif current_pos += pos_dif elif time_dif % 2 == 0 and pos_dif % 2 == 0 and pos_dif <= time_dif: current_time += time_dif current_pos += pos_dif else: ans = False if ans: print("Yes") else: print("No")
false
30
[ "-def validation(l1, l2):", "- dif_t = abs(l2[0] - l1[0])", "- dif_x = abs(l2[1] - l1[1])", "- dif_y = l2[2] - l1[2]", "- if dif_x + dif_y > dif_t:", "- return False", "- elif dif_t % 2 == 0:", "- if (dif_x + dif_y) % 2 != 0:", "- return False", "- else:", "- return True", "- elif dif_t % 2 != 0:", "- if (dif_x + dif_y) % 2 == 0:", "- return False", "- return True", "+n = int(eval(input()))", "+current_time = 0", "+current_pos = 0", "+ans = True", "+for _ in range(n):", "+ t, x, y = list(map(int, input().split()))", "+ time_dif = t - current_time # 3", "+ pos_dif = (x + y) - current_pos # 3", "+ if time_dif % 2 == 1 and pos_dif % 2 == 1 and pos_dif <= time_dif:", "+ current_time += time_dif", "+ current_pos += pos_dif", "+ elif time_dif % 2 == 0 and pos_dif % 2 == 0 and pos_dif <= time_dif:", "+ current_time += time_dif", "+ current_pos += pos_dif", "- return True", "-", "-", "-n = int(eval(input()))", "-l1 = [0, 0, 0]", "-ans = \"Yes\"", "-for _ in range(n):", "- l2 = list(map(int, input().split()))", "- if validation(l1, l2):", "- l1 = l2", "- else:", "- ans = \"No\"", "-print(ans)", "+ ans = False", "+if ans:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.036254
0.037619
0.963709
[ "s457325757", "s628563041" ]
u821624310
p02398
python
s600706365
s841507322
30
20
7,620
7,640
Accepted
Accepted
33.33
a, b, c = list(map(int, input().split())) cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
a, b, c = list(map(int, input().split())) divisor = 0 for n in range(a, b+1): if c % n == 0: divisor += 1 print(divisor)
6
6
119
131
a, b, c = list(map(int, input().split())) cnt = 0 for i in range(a, b + 1): if c % i == 0: cnt += 1 print(cnt)
a, b, c = list(map(int, input().split())) divisor = 0 for n in range(a, b + 1): if c % n == 0: divisor += 1 print(divisor)
false
0
[ "-cnt = 0", "-for i in range(a, b + 1):", "- if c % i == 0:", "- cnt += 1", "-print(cnt)", "+divisor = 0", "+for n in range(a, b + 1):", "+ if c % n == 0:", "+ divisor += 1", "+print(divisor)" ]
false
0.050741
0.047245
1.073984
[ "s600706365", "s841507322" ]
u556799364
p03290
python
s946482747
s850999768
214
34
42,588
9,144
Accepted
Accepted
84.11
D, G = list(map(int, input().split(' '))) p_c_pairs = [(i+1, list(map(int, input().split(' ')))) for i in range(D)] import itertools, math ans = float('inf') nums = list(range(D)) for n in range(D+1): for num in itertools.combinations(nums, n): probs, score = 0, 0 for i in num: j, (p, c) = p_c_pairs[i] probs += p score += 100 * j * p + c if G > score: i = max([i for i in nums if i not in num]) j, (p, c) = p_c_pairs[i] m = min(p, int(math.ceil((G - score) / (100 * j)))) probs += m score += 100 * j * m if m == p: score += c if G <= score: ans = min(ans, probs) print(ans)
# -*- coding: utf-8 -*- D, G = list(map(int, input().split(' '))) p_c_pairs = [((i+1) * 100, list(map(int, input().split(' ')))) for i in range(D)] import math ans = float('inf') p_c_pairs.sort(key=lambda x: -x[0]) for d in range(1<<D): # print(bin(d)) cnt = 0 g = G for i in range(D): if 1 & (d >> i): score, (p, c) = p_c_pairs[i] g -= score * p + c cnt += p if g > 0: for i in range(D): if not (1 & (d >> i)): score, (p, c) = p_c_pairs[i] n = min(p, int(math.ceil(g/score))) g -= score * n cnt += n break # print(bin(d), g) if g <= 0: ans = min(ans, cnt) print(ans)
28
32
773
777
D, G = list(map(int, input().split(" "))) p_c_pairs = [(i + 1, list(map(int, input().split(" ")))) for i in range(D)] import itertools, math ans = float("inf") nums = list(range(D)) for n in range(D + 1): for num in itertools.combinations(nums, n): probs, score = 0, 0 for i in num: j, (p, c) = p_c_pairs[i] probs += p score += 100 * j * p + c if G > score: i = max([i for i in nums if i not in num]) j, (p, c) = p_c_pairs[i] m = min(p, int(math.ceil((G - score) / (100 * j)))) probs += m score += 100 * j * m if m == p: score += c if G <= score: ans = min(ans, probs) print(ans)
# -*- coding: utf-8 -*- D, G = list(map(int, input().split(" "))) p_c_pairs = [((i + 1) * 100, list(map(int, input().split(" ")))) for i in range(D)] import math ans = float("inf") p_c_pairs.sort(key=lambda x: -x[0]) for d in range(1 << D): # print(bin(d)) cnt = 0 g = G for i in range(D): if 1 & (d >> i): score, (p, c) = p_c_pairs[i] g -= score * p + c cnt += p if g > 0: for i in range(D): if not (1 & (d >> i)): score, (p, c) = p_c_pairs[i] n = min(p, int(math.ceil(g / score))) g -= score * n cnt += n break # print(bin(d), g) if g <= 0: ans = min(ans, cnt) print(ans)
false
12.5
[ "+# -*- coding: utf-8 -*-", "-p_c_pairs = [(i + 1, list(map(int, input().split(\" \")))) for i in range(D)]", "-import itertools, math", "+p_c_pairs = [((i + 1) * 100, list(map(int, input().split(\" \")))) for i in range(D)]", "+import math", "-nums = list(range(D))", "-for n in range(D + 1):", "- for num in itertools.combinations(nums, n):", "- probs, score = 0, 0", "- for i in num:", "- j, (p, c) = p_c_pairs[i]", "- probs += p", "- score += 100 * j * p + c", "- if G > score:", "- i = max([i for i in nums if i not in num])", "- j, (p, c) = p_c_pairs[i]", "- m = min(p, int(math.ceil((G - score) / (100 * j))))", "- probs += m", "- score += 100 * j * m", "- if m == p:", "- score += c", "- if G <= score:", "- ans = min(ans, probs)", "+p_c_pairs.sort(key=lambda x: -x[0])", "+for d in range(1 << D):", "+ # print(bin(d))", "+ cnt = 0", "+ g = G", "+ for i in range(D):", "+ if 1 & (d >> i):", "+ score, (p, c) = p_c_pairs[i]", "+ g -= score * p + c", "+ cnt += p", "+ if g > 0:", "+ for i in range(D):", "+ if not (1 & (d >> i)):", "+ score, (p, c) = p_c_pairs[i]", "+ n = min(p, int(math.ceil(g / score)))", "+ g -= score * n", "+ cnt += n", "+ break", "+ # print(bin(d), g)", "+ if g <= 0:", "+ ans = min(ans, cnt)" ]
false
0.037027
0.036416
1.01677
[ "s946482747", "s850999768" ]
u007018214
p03457
python
s586586479
s109960968
408
342
3,064
3,060
Accepted
Accepted
16.18
now = {"t":0,"x":0,"y":0} can = True for i in range(int(eval(input()))): t,x,y = list(map(int,input().split())) dx = abs(x - now["x"]) #x距離 dy = abs(y - now["y"]) #y距離 d = dx + dy #距離合計 if d > t-now["t"] or d%2 != (t-now["t"])%2: print("No") can = False break now = {"t":t,"x":x,"y":y} if can: print("Yes")
N=int(eval(input())) count=0 for i in range(N): t,x,y=list(map(int,input().split())) if x+y<=t and t%2==(x+y)%2:count+=1 print(("Yes" if count==N else "No"))
14
6
359
156
now = {"t": 0, "x": 0, "y": 0} can = True for i in range(int(eval(input()))): t, x, y = list(map(int, input().split())) dx = abs(x - now["x"]) # x距離 dy = abs(y - now["y"]) # y距離 d = dx + dy # 距離合計 if d > t - now["t"] or d % 2 != (t - now["t"]) % 2: print("No") can = False break now = {"t": t, "x": x, "y": y} if can: print("Yes")
N = int(eval(input())) count = 0 for i in range(N): t, x, y = list(map(int, input().split())) if x + y <= t and t % 2 == (x + y) % 2: count += 1 print(("Yes" if count == N else "No"))
false
57.142857
[ "-now = {\"t\": 0, \"x\": 0, \"y\": 0}", "-can = True", "-for i in range(int(eval(input()))):", "+N = int(eval(input()))", "+count = 0", "+for i in range(N):", "- dx = abs(x - now[\"x\"]) # x距離", "- dy = abs(y - now[\"y\"]) # y距離", "- d = dx + dy # 距離合計", "- if d > t - now[\"t\"] or d % 2 != (t - now[\"t\"]) % 2:", "- print(\"No\")", "- can = False", "- break", "- now = {\"t\": t, \"x\": x, \"y\": y}", "-if can:", "- print(\"Yes\")", "+ if x + y <= t and t % 2 == (x + y) % 2:", "+ count += 1", "+print((\"Yes\" if count == N else \"No\"))" ]
false
0.048453
0.039636
1.222457
[ "s586586479", "s109960968" ]
u285891772
p03994
python
s640096951
s278975979
130
95
9,048
6,352
Accepted
Accepted
26.92
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * s = list(input()) K = INT() for i in range(len(s)): tmp = 26 - ascii_lowercase.index(s[i]) if tmp <= K and tmp < 26: K -= tmp s[i] = "a" idx = ascii_lowercase.index(s[-1]) s[-1] = ascii_lowercase[(idx+K)%26] print(*s, sep="")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * s = list(eval(input())) K = INT() def ctoi(c): return ord(c)-ord("a") for i in range(len(s)): x = ctoi(s[i]) if x == 0 or 26-x > K: continue K -= 26 - x s[i] = "a" if K: s[-1] = ascii_lowercase[(ctoi(s[-1])+K)%26] print(("".join(s)))
35
39
1,175
1,182
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2, log from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 from decimal import * s = list(input()) K = INT() for i in range(len(s)): tmp = 26 - ascii_lowercase.index(s[i]) if tmp <= K and tmp < 26: K -= tmp s[i] = "a" idx = ascii_lowercase.index(s[-1]) s[-1] = ascii_lowercase[(idx + K) % 26] print(*s, sep="")
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2, log from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 from decimal import * s = list(eval(input())) K = INT() def ctoi(c): return ord(c) - ord("a") for i in range(len(s)): x = ctoi(s[i]) if x == 0 or 26 - x > K: continue K -= 26 - x s[i] = "a" if K: s[-1] = ascii_lowercase[(ctoi(s[-1]) + K) % 26] print(("".join(s)))
false
10.25641
[ "- return int(input())", "+ return int(eval(input()))", "- return map(int, input().split())", "+ return list(map(int, input().split()))", "- return zip(*(MAP() for _ in range(n)))", "+ return list(zip(*(MAP() for _ in range(n))))", "-s = list(input())", "+s = list(eval(input()))", "+", "+", "+def ctoi(c):", "+ return ord(c) - ord(\"a\")", "+", "+", "- tmp = 26 - ascii_lowercase.index(s[i])", "- if tmp <= K and tmp < 26:", "- K -= tmp", "- s[i] = \"a\"", "-idx = ascii_lowercase.index(s[-1])", "-s[-1] = ascii_lowercase[(idx + K) % 26]", "-print(*s, sep=\"\")", "+ x = ctoi(s[i])", "+ if x == 0 or 26 - x > K:", "+ continue", "+ K -= 26 - x", "+ s[i] = \"a\"", "+if K:", "+ s[-1] = ascii_lowercase[(ctoi(s[-1]) + K) % 26]", "+print((\"\".join(s)))" ]
false
0.04787
0.040071
1.194646
[ "s640096951", "s278975979" ]
u905203728
p02837
python
s224735214
s180899947
236
197
3,188
3,188
Accepted
Accepted
16.53
import re n=int(eval(input())) A=[] for i in range(n): B=["."]*n for x,y in [list(map(int,input().split())) for k in range(int(eval(input())))]: B[x-1]=str(y) A.append("".join(B)) ans=0 for i in range(2**n): num=format(i,"b").zfill(n) cnt,flag=0,1 for k,j in enumerate(num): result=re.search(r"".join(A[k]),num) if result!=None and j=="1": cnt +=1 elif (result!=None and j=="0") or (result==None and j=="1"): flag=0 break if flag:ans=max(ans,cnt) print(ans)
import re n=int(eval(input())) A=[] for i in range(n): word=["."]*n for j in range(int(eval(input()))): x,y=list(map(int,input().split())) word[x-1]=str(y) A.append(word) ans=0 for i in range(2**n): num=format(i, "b").zfill(n) flag,cnt=1,0 for j,k in enumerate(num): search=re.search(r"".join(A[j]),num) if search!=None and k=="1": cnt +=1 elif (search==None and k=="1") or (search!=None and k=="0"): flag=0 break if flag:ans=max(ans,cnt) print(ans)
22
23
563
558
import re n = int(eval(input())) A = [] for i in range(n): B = ["."] * n for x, y in [list(map(int, input().split())) for k in range(int(eval(input())))]: B[x - 1] = str(y) A.append("".join(B)) ans = 0 for i in range(2**n): num = format(i, "b").zfill(n) cnt, flag = 0, 1 for k, j in enumerate(num): result = re.search(r"".join(A[k]), num) if result != None and j == "1": cnt += 1 elif (result != None and j == "0") or (result == None and j == "1"): flag = 0 break if flag: ans = max(ans, cnt) print(ans)
import re n = int(eval(input())) A = [] for i in range(n): word = ["."] * n for j in range(int(eval(input()))): x, y = list(map(int, input().split())) word[x - 1] = str(y) A.append(word) ans = 0 for i in range(2**n): num = format(i, "b").zfill(n) flag, cnt = 1, 0 for j, k in enumerate(num): search = re.search(r"".join(A[j]), num) if search != None and k == "1": cnt += 1 elif (search == None and k == "1") or (search != None and k == "0"): flag = 0 break if flag: ans = max(ans, cnt) print(ans)
false
4.347826
[ "- B = [\".\"] * n", "- for x, y in [list(map(int, input().split())) for k in range(int(eval(input())))]:", "- B[x - 1] = str(y)", "- A.append(\"\".join(B))", "+ word = [\".\"] * n", "+ for j in range(int(eval(input()))):", "+ x, y = list(map(int, input().split()))", "+ word[x - 1] = str(y)", "+ A.append(word)", "- cnt, flag = 0, 1", "- for k, j in enumerate(num):", "- result = re.search(r\"\".join(A[k]), num)", "- if result != None and j == \"1\":", "+ flag, cnt = 1, 0", "+ for j, k in enumerate(num):", "+ search = re.search(r\"\".join(A[j]), num)", "+ if search != None and k == \"1\":", "- elif (result != None and j == \"0\") or (result == None and j == \"1\"):", "+ elif (search == None and k == \"1\") or (search != None and k == \"0\"):" ]
false
0.051826
0.056537
0.91666
[ "s224735214", "s180899947" ]
u620084012
p02831
python
s889540119
s440607024
177
18
38,448
2,940
Accepted
Accepted
89.83
import math A, B = list(map(int,input().split())) # aとbの最大公約数 def gcd(a,b): if b == 0: return a return gcd(b,a%b) # aとbの最小公倍数 # a*b = lcm(a,b)*gcd(a,b) より def lcm(a,b): return a*b//gcd(a,b) print((lcm(A,B)))
A, B = list(map(int,input().split())) def gcd(a,b): if b == 0: return a return gcd(b,a%b) def lcm(a,b): return a*b//gcd(a,b) print((lcm(A,B)))
15
8
237
162
import math A, B = list(map(int, input().split())) # aとbの最大公約数 def gcd(a, b): if b == 0: return a return gcd(b, a % b) # aとbの最小公倍数 # a*b = lcm(a,b)*gcd(a,b) より def lcm(a, b): return a * b // gcd(a, b) print((lcm(A, B)))
A, B = list(map(int, input().split())) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) print((lcm(A, B)))
false
46.666667
[ "-import math", "+A, B = list(map(int, input().split()))", "-A, B = list(map(int, input().split()))", "-# aとbの最大公約数", "+", "-# aとbの最小公倍数", "-# a*b = lcm(a,b)*gcd(a,b) より" ]
false
0.035479
0.036055
0.984003
[ "s889540119", "s440607024" ]
u887207211
p03127
python
s508799774
s419499356
188
60
14,252
14,252
Accepted
Accepted
68.09
N = int(eval(input())) A = list(map(int,input().split())) def gcd(m, n): while n: m, n = n, m%n return m ans = A[0] tmp = [] for i in range(1,N): tmp.append(gcd(ans,A[i])) print((min(tmp)))
def gcd(m, n): while n: m, n = n, m%n return m def ans(): N = int(eval(input())) A = list(map(int,input().split())) tmp = A[0] for i in range(1,N): tmp = gcd(A[i], tmp) print(tmp) ans()
12
13
203
214
N = int(eval(input())) A = list(map(int, input().split())) def gcd(m, n): while n: m, n = n, m % n return m ans = A[0] tmp = [] for i in range(1, N): tmp.append(gcd(ans, A[i])) print((min(tmp)))
def gcd(m, n): while n: m, n = n, m % n return m def ans(): N = int(eval(input())) A = list(map(int, input().split())) tmp = A[0] for i in range(1, N): tmp = gcd(A[i], tmp) print(tmp) ans()
false
7.692308
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-", "-", "-ans = A[0]", "-tmp = []", "-for i in range(1, N):", "- tmp.append(gcd(ans, A[i]))", "-print((min(tmp)))", "+def ans():", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ tmp = A[0]", "+ for i in range(1, N):", "+ tmp = gcd(A[i], tmp)", "+ print(tmp)", "+", "+", "+ans()" ]
false
0.036485
0.037156
0.981921
[ "s508799774", "s419499356" ]
u796942881
p03731
python
s935213633
s567707938
131
89
27,196
27,324
Accepted
Accepted
32.06
from sys import stdin def main(): lines = stdin.readlines() T = int(lines[0].split()[1]) tn = [int(ti) for ti in lines[1].split()] ans = 0 for t1, t2 in zip(tn[0:], tn[1:]): ans += min(T, t2 - t1) ans += T print(ans) return main()
from sys import stdin def main(): lines = stdin.readlines() T = int(lines[0].split()[1]) tn = [int(ti) for ti in lines[1].split()] print((tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T))) return main()
16
12
290
266
from sys import stdin def main(): lines = stdin.readlines() T = int(lines[0].split()[1]) tn = [int(ti) for ti in lines[1].split()] ans = 0 for t1, t2 in zip(tn[0:], tn[1:]): ans += min(T, t2 - t1) ans += T print(ans) return main()
from sys import stdin def main(): lines = stdin.readlines() T = int(lines[0].split()[1]) tn = [int(ti) for ti in lines[1].split()] print( (tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T)) ) return main()
false
25
[ "- ans = 0", "- for t1, t2 in zip(tn[0:], tn[1:]):", "- ans += min(T, t2 - t1)", "- ans += T", "- print(ans)", "+ print(", "+ (tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T))", "+ )" ]
false
0.038905
0.039611
0.982175
[ "s935213633", "s567707938" ]
u038229929
p03108
python
s837449644
s365838400
553
442
49,996
50,008
Accepted
Accepted
20.07
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] data = [stdin.readline().rstrip().split() for _ in range(M)] island = list(range(N)) counts = [1] * N total = int((N * (N - 1)) / 2) result = [] for c in reversed(data): ref0 = int(c[0]) - 1 while island[ref0] != ref0: ref0 = island[ref0] ref1 = int(c[1]) - 1 while island[ref1] != ref1: ref1 = island[ref1] if ref0 == ref1: result.append(0); else: island[max(ref0,ref1)] = min(ref0, ref1) result.append(counts[ref0] * counts[ref1]); counts[min(ref0,ref1)] = counts[ref0] + counts[ref1] res = [total] for r in result: res.append((res[-1] - r)) print(('\n'.join(reversed([str(x) for x in res][:-1]))))
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] data = [stdin.readline().rstrip().split() for _ in range(M)] island = list(range(N)) counts = [1] * N total = int((N * (N - 1)) / 2) result = [] for c in reversed(data): ref0 = int(c[0]) - 1 while island[ref0] != ref0: ref0 = island[ref0] ref1 = int(c[1]) - 1 while island[ref1] != ref1: ref1 = island[ref1] if ref0 == ref1: root = min(ref0, ref1) pair = max(ref0, ref1) island[int(c[0]) - 1] = root island[int(c[1]) - 1] = root island[pair] = root result.append(0); else: root = min(ref0, ref1) pair = max(ref0, ref1) island[int(c[0]) - 1] = root island[int(c[1]) - 1] = root island[pair] = root result.append(counts[ref0] * counts[ref1]); counts[root] = counts[ref0] + counts[ref1] res = [total] for r in result: res.append((res[-1] - r)) print(('\n'.join(reversed([str(x) for x in res][:-1]))))
29
38
789
1,067
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] data = [stdin.readline().rstrip().split() for _ in range(M)] island = list(range(N)) counts = [1] * N total = int((N * (N - 1)) / 2) result = [] for c in reversed(data): ref0 = int(c[0]) - 1 while island[ref0] != ref0: ref0 = island[ref0] ref1 = int(c[1]) - 1 while island[ref1] != ref1: ref1 = island[ref1] if ref0 == ref1: result.append(0) else: island[max(ref0, ref1)] = min(ref0, ref1) result.append(counts[ref0] * counts[ref1]) counts[min(ref0, ref1)] = counts[ref0] + counts[ref1] res = [total] for r in result: res.append((res[-1] - r)) print(("\n".join(reversed([str(x) for x in res][:-1]))))
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] data = [stdin.readline().rstrip().split() for _ in range(M)] island = list(range(N)) counts = [1] * N total = int((N * (N - 1)) / 2) result = [] for c in reversed(data): ref0 = int(c[0]) - 1 while island[ref0] != ref0: ref0 = island[ref0] ref1 = int(c[1]) - 1 while island[ref1] != ref1: ref1 = island[ref1] if ref0 == ref1: root = min(ref0, ref1) pair = max(ref0, ref1) island[int(c[0]) - 1] = root island[int(c[1]) - 1] = root island[pair] = root result.append(0) else: root = min(ref0, ref1) pair = max(ref0, ref1) island[int(c[0]) - 1] = root island[int(c[1]) - 1] = root island[pair] = root result.append(counts[ref0] * counts[ref1]) counts[root] = counts[ref0] + counts[ref1] res = [total] for r in result: res.append((res[-1] - r)) print(("\n".join(reversed([str(x) for x in res][:-1]))))
false
23.684211
[ "+ root = min(ref0, ref1)", "+ pair = max(ref0, ref1)", "+ island[int(c[0]) - 1] = root", "+ island[int(c[1]) - 1] = root", "+ island[pair] = root", "- island[max(ref0, ref1)] = min(ref0, ref1)", "+ root = min(ref0, ref1)", "+ pair = max(ref0, ref1)", "+ island[int(c[0]) - 1] = root", "+ island[int(c[1]) - 1] = root", "+ island[pair] = root", "- counts[min(ref0, ref1)] = counts[ref0] + counts[ref1]", "+ counts[root] = counts[ref0] + counts[ref1]" ]
false
0.041598
0.104336
0.398696
[ "s837449644", "s365838400" ]
u855710796
p02937
python
s448069096
s071993573
325
203
193,684
133,376
Accepted
Accepted
37.54
s = eval(input()) t = eval(input()) l_s = len(s) l_t = len(t) s2 = s + s l_s2 = len(s2) next_idx_1 = [[l_s2] * 26 for i in range(l_s2+1)] for i in reversed(list(range(l_s2))): for j in range(26): next_idx_1[i][j] = next_idx_1[i+1][j] next_idx_1[i][ord(s2[i]) - ord("a")] = i next_idx_2 = [[l_s2] * 26 for i in range(l_s2)] for i in reversed(list(range(1, l_s2))): for j in range(26): next_idx_2[i-1][j] = next_idx_2[i][j] next_idx_2[i-1][ord(s2[i]) - ord("a")] = i cur_idx = 0 for i in range(l_t): if i == 0: idx = next_idx_1[cur_idx%l_s][ord(t[i]) - ord("a")] else: idx = next_idx_2[cur_idx%l_s][ord(t[i]) - ord("a")] if idx == l_s2: print("-1") exit() cur_idx += idx - (cur_idx % l_s) print((cur_idx+1))
s = eval(input()) t = eval(input()) l_s = len(s) l_t = len(t) s2 = s + s l_s2 = len(s2) next_idx = [[l_s2] * 26 for i in range(l_s2)] for i in reversed(list(range(1, l_s2))): for j in range(26): next_idx[i-1][j] = next_idx[i][j] next_idx[i-1][ord(s2[i]) - ord("a")] = i cur_idx = 0 for i in range(l_t): if i == 0: flg = False for j in range(l_s): if t[i] == s[j]: cur_idx += j flg = True break if flg: continue else: print("-1") exit() else: idx = next_idx[cur_idx%l_s][ord(t[i]) - ord("a")] if idx == l_s2: print("-1") exit() cur_idx += idx - (cur_idx % l_s) print((cur_idx+1))
37
40
809
793
s = eval(input()) t = eval(input()) l_s = len(s) l_t = len(t) s2 = s + s l_s2 = len(s2) next_idx_1 = [[l_s2] * 26 for i in range(l_s2 + 1)] for i in reversed(list(range(l_s2))): for j in range(26): next_idx_1[i][j] = next_idx_1[i + 1][j] next_idx_1[i][ord(s2[i]) - ord("a")] = i next_idx_2 = [[l_s2] * 26 for i in range(l_s2)] for i in reversed(list(range(1, l_s2))): for j in range(26): next_idx_2[i - 1][j] = next_idx_2[i][j] next_idx_2[i - 1][ord(s2[i]) - ord("a")] = i cur_idx = 0 for i in range(l_t): if i == 0: idx = next_idx_1[cur_idx % l_s][ord(t[i]) - ord("a")] else: idx = next_idx_2[cur_idx % l_s][ord(t[i]) - ord("a")] if idx == l_s2: print("-1") exit() cur_idx += idx - (cur_idx % l_s) print((cur_idx + 1))
s = eval(input()) t = eval(input()) l_s = len(s) l_t = len(t) s2 = s + s l_s2 = len(s2) next_idx = [[l_s2] * 26 for i in range(l_s2)] for i in reversed(list(range(1, l_s2))): for j in range(26): next_idx[i - 1][j] = next_idx[i][j] next_idx[i - 1][ord(s2[i]) - ord("a")] = i cur_idx = 0 for i in range(l_t): if i == 0: flg = False for j in range(l_s): if t[i] == s[j]: cur_idx += j flg = True break if flg: continue else: print("-1") exit() else: idx = next_idx[cur_idx % l_s][ord(t[i]) - ord("a")] if idx == l_s2: print("-1") exit() cur_idx += idx - (cur_idx % l_s) print((cur_idx + 1))
false
7.5
[ "-next_idx_1 = [[l_s2] * 26 for i in range(l_s2 + 1)]", "-for i in reversed(list(range(l_s2))):", "- for j in range(26):", "- next_idx_1[i][j] = next_idx_1[i + 1][j]", "- next_idx_1[i][ord(s2[i]) - ord(\"a\")] = i", "-next_idx_2 = [[l_s2] * 26 for i in range(l_s2)]", "+next_idx = [[l_s2] * 26 for i in range(l_s2)]", "- next_idx_2[i - 1][j] = next_idx_2[i][j]", "- next_idx_2[i - 1][ord(s2[i]) - ord(\"a\")] = i", "+ next_idx[i - 1][j] = next_idx[i][j]", "+ next_idx[i - 1][ord(s2[i]) - ord(\"a\")] = i", "- idx = next_idx_1[cur_idx % l_s][ord(t[i]) - ord(\"a\")]", "+ flg = False", "+ for j in range(l_s):", "+ if t[i] == s[j]:", "+ cur_idx += j", "+ flg = True", "+ break", "+ if flg:", "+ continue", "+ else:", "+ print(\"-1\")", "+ exit()", "- idx = next_idx_2[cur_idx % l_s][ord(t[i]) - ord(\"a\")]", "+ idx = next_idx[cur_idx % l_s][ord(t[i]) - ord(\"a\")]" ]
false
0.142701
0.097405
1.465025
[ "s448069096", "s071993573" ]
u994988729
p03946
python
s583531926
s084004538
86
70
14,252
15,020
Accepted
Accepted
18.6
n, t = list(map(int, input().split())) a = list(map(int, input().split())) profit = 0 prof_n = 0 mn = 0 for i in range(n): if i == 0: mn = a[i] continue if a[i] < mn: mn = a[i] else: if a[i] - mn > profit: profit = a[i] - mn prof_n = 1 elif a[i] - mn == profit: prof_n += 1 ans = prof_n print(ans)
N, T = list(map(int, input().split())) A = list(map(int, input().split())) pre = 10 ** 18 diff_max = 0 diff_cnt = 0 for a in A: if a < pre: pre = a continue if a - pre > diff_max: diff_max = a - pre diff_cnt = 1 elif a - pre == diff_max: diff_cnt += 1 # 高橋君はdiffmax*(T//2)の利益 # 取引できるのがdiffcnt箇所、これをつぶす print(diff_cnt)
22
21
404
387
n, t = list(map(int, input().split())) a = list(map(int, input().split())) profit = 0 prof_n = 0 mn = 0 for i in range(n): if i == 0: mn = a[i] continue if a[i] < mn: mn = a[i] else: if a[i] - mn > profit: profit = a[i] - mn prof_n = 1 elif a[i] - mn == profit: prof_n += 1 ans = prof_n print(ans)
N, T = list(map(int, input().split())) A = list(map(int, input().split())) pre = 10**18 diff_max = 0 diff_cnt = 0 for a in A: if a < pre: pre = a continue if a - pre > diff_max: diff_max = a - pre diff_cnt = 1 elif a - pre == diff_max: diff_cnt += 1 # 高橋君はdiffmax*(T//2)の利益 # 取引できるのがdiffcnt箇所、これをつぶす print(diff_cnt)
false
4.545455
[ "-n, t = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-profit = 0", "-prof_n = 0", "-mn = 0", "-for i in range(n):", "- if i == 0:", "- mn = a[i]", "+N, T = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "+pre = 10**18", "+diff_max = 0", "+diff_cnt = 0", "+for a in A:", "+ if a < pre:", "+ pre = a", "- if a[i] < mn:", "- mn = a[i]", "- else:", "- if a[i] - mn > profit:", "- profit = a[i] - mn", "- prof_n = 1", "- elif a[i] - mn == profit:", "- prof_n += 1", "-ans = prof_n", "-print(ans)", "+ if a - pre > diff_max:", "+ diff_max = a - pre", "+ diff_cnt = 1", "+ elif a - pre == diff_max:", "+ diff_cnt += 1", "+# 高橋君はdiffmax*(T//2)の利益", "+# 取引できるのがdiffcnt箇所、これをつぶす", "+print(diff_cnt)" ]
false
0.078042
0.042286
1.845571
[ "s583531926", "s084004538" ]
u133936772
p02596
python
s204985956
s038544357
281
212
9,036
9,172
Accepted
Accepted
24.56
k=int(input()) if (k%2)*(k%5)<1: exit(print(-1)) a,t,m=1,7,7 while m%k: a+=1 t=t*10%k m+=t print(a)
k=int(input()) t=7 for i in range(k): if t%k<1: exit(print(i+1)) t=(t*10+7)%k print(-1)
8
6
112
96
k = int(input()) if (k % 2) * (k % 5) < 1: exit(print(-1)) a, t, m = 1, 7, 7 while m % k: a += 1 t = t * 10 % k m += t print(a)
k = int(input()) t = 7 for i in range(k): if t % k < 1: exit(print(i + 1)) t = (t * 10 + 7) % k print(-1)
false
25
[ "-if (k % 2) * (k % 5) < 1:", "- exit(print(-1))", "-a, t, m = 1, 7, 7", "-while m % k:", "- a += 1", "- t = t * 10 % k", "- m += t", "-print(a)", "+t = 7", "+for i in range(k):", "+ if t % k < 1:", "+ exit(print(i + 1))", "+ t = (t * 10 + 7) % k", "+print(-1)" ]
false
0.424151
0.082745
5.126015
[ "s204985956", "s038544357" ]
u133936772
p02959
python
s515604776
s639593531
163
126
18,476
22,116
Accepted
Accepted
22.7
f=lambda:list(map(int,input().split())) n=f()[0];l=f();c=0;t=l.pop(0) for a,b in zip(l,f()): s=min(t+a,b);t=min(max(t+a-s,0),a);c+=s print(c)
f=lambda:list(map(int,input().split())) eval(input()) p,*A=f() B=f() s=0 for a,b in zip(A,B): t=min(b,a+p) p=a-max(0,t-p) s+=t print(s)
5
10
147
138
f = lambda: list(map(int, input().split())) n = f()[0] l = f() c = 0 t = l.pop(0) for a, b in zip(l, f()): s = min(t + a, b) t = min(max(t + a - s, 0), a) c += s print(c)
f = lambda: list(map(int, input().split())) eval(input()) p, *A = f() B = f() s = 0 for a, b in zip(A, B): t = min(b, a + p) p = a - max(0, t - p) s += t print(s)
false
50
[ "-n = f()[0]", "-l = f()", "-c = 0", "-t = l.pop(0)", "-for a, b in zip(l, f()):", "- s = min(t + a, b)", "- t = min(max(t + a - s, 0), a)", "- c += s", "-print(c)", "+eval(input())", "+p, *A = f()", "+B = f()", "+s = 0", "+for a, b in zip(A, B):", "+ t = min(b, a + p)", "+ p = a - max(0, t - p)", "+ s += t", "+print(s)" ]
false
0.039458
0.03983
0.990662
[ "s515604776", "s639593531" ]
u903005414
p03569
python
s067567672
s781684473
190
70
41,904
10,704
Accepted
Accepted
63.16
import numpy as np S = np.array(list(eval(input()))) num_x = np.count_nonzero(S == 'x') # print(f'{num_x=}') A = [s for s in S if s != 'x'] # print(f'{S=}, {A=}') if len(A) % 2 == 0: L = A[:len(A) // 2] R = A[len(A) // 2:][::-1] else: L = A[:len(A) // 2] R = A[len(A) // 2 + 1:][::-1] # print(f'{L=}, {R=}') if not np.all(L == R): print((-1)) exit() # x以外の文字でsplitをする?'x' '' 'x' '' T = [] subset = '' for s in S: # print(f'{subset=}') if s == 'x': subset += 'x' else: T.append(subset) subset = '' T.append(subset) len_T = np.array([len(t) for t in T]) # print(f'{T=}, {len_T=}, {len_T - len_T[::-1]}') ans = np.abs(len_T - len_T[::-1]).sum() // 2 print(ans)
from collections import deque S = deque(list(eval(input()))) ans = 0 while len(S) > 1: l = S.popleft() r = S.pop() if l == r: continue elif l == 'x': ans += 1 S.append(r) elif r == 'x': ans += 1 S.appendleft(l) else: print((-1)) exit() print(ans)
35
20
748
340
import numpy as np S = np.array(list(eval(input()))) num_x = np.count_nonzero(S == "x") # print(f'{num_x=}') A = [s for s in S if s != "x"] # print(f'{S=}, {A=}') if len(A) % 2 == 0: L = A[: len(A) // 2] R = A[len(A) // 2 :][::-1] else: L = A[: len(A) // 2] R = A[len(A) // 2 + 1 :][::-1] # print(f'{L=}, {R=}') if not np.all(L == R): print((-1)) exit() # x以外の文字でsplitをする?'x' '' 'x' '' T = [] subset = "" for s in S: # print(f'{subset=}') if s == "x": subset += "x" else: T.append(subset) subset = "" T.append(subset) len_T = np.array([len(t) for t in T]) # print(f'{T=}, {len_T=}, {len_T - len_T[::-1]}') ans = np.abs(len_T - len_T[::-1]).sum() // 2 print(ans)
from collections import deque S = deque(list(eval(input()))) ans = 0 while len(S) > 1: l = S.popleft() r = S.pop() if l == r: continue elif l == "x": ans += 1 S.append(r) elif r == "x": ans += 1 S.appendleft(l) else: print((-1)) exit() print(ans)
false
42.857143
[ "-import numpy as np", "+from collections import deque", "-S = np.array(list(eval(input())))", "-num_x = np.count_nonzero(S == \"x\")", "-# print(f'{num_x=}')", "-A = [s for s in S if s != \"x\"]", "-# print(f'{S=}, {A=}')", "-if len(A) % 2 == 0:", "- L = A[: len(A) // 2]", "- R = A[len(A) // 2 :][::-1]", "-else:", "- L = A[: len(A) // 2]", "- R = A[len(A) // 2 + 1 :][::-1]", "-# print(f'{L=}, {R=}')", "-if not np.all(L == R):", "- print((-1))", "- exit()", "-# x以外の文字でsplitをする?'x' '' 'x' ''", "-T = []", "-subset = \"\"", "-for s in S:", "- # print(f'{subset=}')", "- if s == \"x\":", "- subset += \"x\"", "+S = deque(list(eval(input())))", "+ans = 0", "+while len(S) > 1:", "+ l = S.popleft()", "+ r = S.pop()", "+ if l == r:", "+ continue", "+ elif l == \"x\":", "+ ans += 1", "+ S.append(r)", "+ elif r == \"x\":", "+ ans += 1", "+ S.appendleft(l)", "- T.append(subset)", "- subset = \"\"", "-T.append(subset)", "-len_T = np.array([len(t) for t in T])", "-# print(f'{T=}, {len_T=}, {len_T - len_T[::-1]}')", "-ans = np.abs(len_T - len_T[::-1]).sum() // 2", "+ print((-1))", "+ exit()" ]
false
0.308283
0.036884
8.35809
[ "s067567672", "s781684473" ]
u504836877
p03715
python
s124733664
s732735100
488
318
3,188
3,188
Accepted
Accepted
34.84
H,W = list(map(int, input().split())) ans = 10**10 for i in range(1, H): if (H-i)%2 == 0: smax = max(W*i, (H-i)*W//2) smin = min(W*i, (H-i)*W//2) else: smax = max(W*i, (H-i+1)*W//2) smin = min(W*i, (H-i-1)*W//2) ans = min(ans, smax-smin) if W%2 == 1: smax = max(W*i, (H-i)*(W+1)//2) smin = min(W*i, (H-i)*(W-1)//2) else: smax = max(W*i, (H-i)*W//2) smin = min(W*i, (H-i)*W//2) ans = min(ans, smax-smin) for i in range(1, W): if (W-i)%2 == 0: smax = max(H*i, (W-i)*H//2) smin = min(H*i, (W-i)*H//2) else: smax = max(H*i, (W-i+1)*H//2) smin = min(H*i, (W-i-1)*H//2) ans = min(ans, smax-smin) if H%2 == 1: smax = max(H*i, (W-i)*(H+1)//2) smin = min(H*i, (W-i)*(H-1)//2) else: smax = max(H*i, (W-i)*H//2) smin = min(H*i, (W-i)*H//2) ans = min(ans, smax-smin) print(ans)
H,W = list(map(int, input().split())) ans = [] if H > 2: ans.append(W*max(H//3, (H-H//3)//2, H-H//3-(H-H//3)//2)-W*min(H//3, (H-H//3)//2, H-H//3-(H-H//3)//2)) if W > 2: ans.append(H*max(W//3, (W-W//3)//2, W-W//3-(W-W//3)//2)-H*min(W//3, (W-W//3)//2, W-W//3-(W-W//3)//2)) num = 10**10 for x in range(1, W): num = min(num, max(H*x, (W-x)*(H//2), (W-x)*(H-H//2))-min(H*x, (W-x)*(H//2), (W-x)*(H-H//2))) ans.append(num) num = 10**10 for x in range(1, H): num = min(num, max(W*x, (H-x)*(W//2), (H-x)*(W-W//2))-min(W*x, (H-x)*(W//2), (H-x)*(W-W//2))) ans.append(num) print((min(ans)))
35
18
971
606
H, W = list(map(int, input().split())) ans = 10**10 for i in range(1, H): if (H - i) % 2 == 0: smax = max(W * i, (H - i) * W // 2) smin = min(W * i, (H - i) * W // 2) else: smax = max(W * i, (H - i + 1) * W // 2) smin = min(W * i, (H - i - 1) * W // 2) ans = min(ans, smax - smin) if W % 2 == 1: smax = max(W * i, (H - i) * (W + 1) // 2) smin = min(W * i, (H - i) * (W - 1) // 2) else: smax = max(W * i, (H - i) * W // 2) smin = min(W * i, (H - i) * W // 2) ans = min(ans, smax - smin) for i in range(1, W): if (W - i) % 2 == 0: smax = max(H * i, (W - i) * H // 2) smin = min(H * i, (W - i) * H // 2) else: smax = max(H * i, (W - i + 1) * H // 2) smin = min(H * i, (W - i - 1) * H // 2) ans = min(ans, smax - smin) if H % 2 == 1: smax = max(H * i, (W - i) * (H + 1) // 2) smin = min(H * i, (W - i) * (H - 1) // 2) else: smax = max(H * i, (W - i) * H // 2) smin = min(H * i, (W - i) * H // 2) ans = min(ans, smax - smin) print(ans)
H, W = list(map(int, input().split())) ans = [] if H > 2: ans.append( W * max(H // 3, (H - H // 3) // 2, H - H // 3 - (H - H // 3) // 2) - W * min(H // 3, (H - H // 3) // 2, H - H // 3 - (H - H // 3) // 2) ) if W > 2: ans.append( H * max(W // 3, (W - W // 3) // 2, W - W // 3 - (W - W // 3) // 2) - H * min(W // 3, (W - W // 3) // 2, W - W // 3 - (W - W // 3) // 2) ) num = 10**10 for x in range(1, W): num = min( num, max(H * x, (W - x) * (H // 2), (W - x) * (H - H // 2)) - min(H * x, (W - x) * (H // 2), (W - x) * (H - H // 2)), ) ans.append(num) num = 10**10 for x in range(1, H): num = min( num, max(W * x, (H - x) * (W // 2), (H - x) * (W - W // 2)) - min(W * x, (H - x) * (W // 2), (H - x) * (W - W // 2)), ) ans.append(num) print((min(ans)))
false
48.571429
[ "-ans = 10**10", "-for i in range(1, H):", "- if (H - i) % 2 == 0:", "- smax = max(W * i, (H - i) * W // 2)", "- smin = min(W * i, (H - i) * W // 2)", "- else:", "- smax = max(W * i, (H - i + 1) * W // 2)", "- smin = min(W * i, (H - i - 1) * W // 2)", "- ans = min(ans, smax - smin)", "- if W % 2 == 1:", "- smax = max(W * i, (H - i) * (W + 1) // 2)", "- smin = min(W * i, (H - i) * (W - 1) // 2)", "- else:", "- smax = max(W * i, (H - i) * W // 2)", "- smin = min(W * i, (H - i) * W // 2)", "- ans = min(ans, smax - smin)", "-for i in range(1, W):", "- if (W - i) % 2 == 0:", "- smax = max(H * i, (W - i) * H // 2)", "- smin = min(H * i, (W - i) * H // 2)", "- else:", "- smax = max(H * i, (W - i + 1) * H // 2)", "- smin = min(H * i, (W - i - 1) * H // 2)", "- ans = min(ans, smax - smin)", "- if H % 2 == 1:", "- smax = max(H * i, (W - i) * (H + 1) // 2)", "- smin = min(H * i, (W - i) * (H - 1) // 2)", "- else:", "- smax = max(H * i, (W - i) * H // 2)", "- smin = min(H * i, (W - i) * H // 2)", "- ans = min(ans, smax - smin)", "-print(ans)", "+ans = []", "+if H > 2:", "+ ans.append(", "+ W * max(H // 3, (H - H // 3) // 2, H - H // 3 - (H - H // 3) // 2)", "+ - W * min(H // 3, (H - H // 3) // 2, H - H // 3 - (H - H // 3) // 2)", "+ )", "+if W > 2:", "+ ans.append(", "+ H * max(W // 3, (W - W // 3) // 2, W - W // 3 - (W - W // 3) // 2)", "+ - H * min(W // 3, (W - W // 3) // 2, W - W // 3 - (W - W // 3) // 2)", "+ )", "+num = 10**10", "+for x in range(1, W):", "+ num = min(", "+ num,", "+ max(H * x, (W - x) * (H // 2), (W - x) * (H - H // 2))", "+ - min(H * x, (W - x) * (H // 2), (W - x) * (H - H // 2)),", "+ )", "+ans.append(num)", "+num = 10**10", "+for x in range(1, H):", "+ num = min(", "+ num,", "+ max(W * x, (H - x) * (W // 2), (H - x) * (W - W // 2))", "+ - min(W * x, (H - x) * (W // 2), (H - x) * (W - W // 2)),", "+ )", "+ans.append(num)", "+print((min(ans)))" ]
false
0.087391
0.055587
1.572147
[ "s124733664", "s732735100" ]
u894114233
p00557
python
s246365798
s152921142
8,820
6,930
821,780
821,724
Accepted
Accepted
21.43
def check(y,x): if 0<=y<=h-1 and 0<=x<=w-1: return True return False h,w=list(map(int,input().split())) g=[list(map(int,input().split())) for _ in range(h)] pos=[-1]*(h*w) for i in range(h): for j in range(w): pos[g[i][j]-1]=[i,j] dy=(1,0,-1,0) dx=(0,1,0,-1) stop=[set() for _ in range(h*w)] ans=0 for i in range(h*w): y,x=pos[i] for j in range(4): ny=y+dy[j];nx=x+dx[j] if check(ny,nx): if g[ny][nx]<g[y][x]: for k in list(stop[g[ny][nx]-1]): stop[i].add(k) cnt=len(stop[i]) if cnt>=2: ans+=1 elif cnt==0: stop[i].add(g[y][x]) print(ans)
def check(y,x): if 0<=y<=h-1 and 0<=x<=w-1: return True return False h,w=list(map(int,input().split())) g=[list(map(int,input().split())) for _ in range(h)] pos=[-1]*(h*w) for i in range(h): for j in range(w): pos[g[i][j]-1]=[i,j] dy=(1,0,-1,0) dx=(0,1,0,-1) stop=[set() for _ in range(h*w)] ans=0 for i in range(h*w): y,x=pos[i] for j in range(4): ny=y+dy[j];nx=x+dx[j] if check(ny,nx): if g[ny][nx]<g[y][x]: stop[i]=stop[i]|stop[g[ny][nx]-1] cnt=len(stop[i]) if cnt>=2: ans+=1 elif cnt==0: stop[i].add(g[y][x]) print(ans)
31
30
701
665
def check(y, x): if 0 <= y <= h - 1 and 0 <= x <= w - 1: return True return False h, w = list(map(int, input().split())) g = [list(map(int, input().split())) for _ in range(h)] pos = [-1] * (h * w) for i in range(h): for j in range(w): pos[g[i][j] - 1] = [i, j] dy = (1, 0, -1, 0) dx = (0, 1, 0, -1) stop = [set() for _ in range(h * w)] ans = 0 for i in range(h * w): y, x = pos[i] for j in range(4): ny = y + dy[j] nx = x + dx[j] if check(ny, nx): if g[ny][nx] < g[y][x]: for k in list(stop[g[ny][nx] - 1]): stop[i].add(k) cnt = len(stop[i]) if cnt >= 2: ans += 1 elif cnt == 0: stop[i].add(g[y][x]) print(ans)
def check(y, x): if 0 <= y <= h - 1 and 0 <= x <= w - 1: return True return False h, w = list(map(int, input().split())) g = [list(map(int, input().split())) for _ in range(h)] pos = [-1] * (h * w) for i in range(h): for j in range(w): pos[g[i][j] - 1] = [i, j] dy = (1, 0, -1, 0) dx = (0, 1, 0, -1) stop = [set() for _ in range(h * w)] ans = 0 for i in range(h * w): y, x = pos[i] for j in range(4): ny = y + dy[j] nx = x + dx[j] if check(ny, nx): if g[ny][nx] < g[y][x]: stop[i] = stop[i] | stop[g[ny][nx] - 1] cnt = len(stop[i]) if cnt >= 2: ans += 1 elif cnt == 0: stop[i].add(g[y][x]) print(ans)
false
3.225806
[ "- for k in list(stop[g[ny][nx] - 1]):", "- stop[i].add(k)", "+ stop[i] = stop[i] | stop[g[ny][nx] - 1]" ]
false
0.056189
0.054302
1.034743
[ "s246365798", "s152921142" ]
u210992699
p02315
python
s973641313
s432029110
1,100
870
25,948
25,940
Accepted
Accepted
20.91
INF = 10 ** 12 N, W = list(map(int, input().split())) items =[] * N for i in range(N): v, w = list(map(int, input().split())) items.append([v,w]) dp = [[INF for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i] = 0 for i in range(N+1): dp[i][0] = 0 for i in range(1,N+1): #1<= i <= N for j in range(1, W+1): # 1 <= j <= W if j - items[i-1][1] >= 0: dp[i][j] = max(dp[i-1][j], dp[i-1][j - items[i-1][1]] + items[i-1][0]) else: dp[i][j] = dp[i-1][j] print((dp[N][W]))
N, W =list(map(int,input().split())) INF = 10**10 #dp = [[INF]*100000]*(N*100)#余分に dp = [[0 for i in range(W+1)] for j in range(N+1)] for i in range (N): dp[i][0] =0 for j in range (W+1): dp[0][j] =0 for i in range (N): v, w = list(map(int,input().split())) for j in range (W+1): if j-w>=0: dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v) else: dp[i+1][j] = dp[i][j] print((dp[N][W]))
26
22
563
451
INF = 10**12 N, W = list(map(int, input().split())) items = [] * N for i in range(N): v, w = list(map(int, input().split())) items.append([v, w]) dp = [[INF for i in range(W + 1)] for j in range(N + 1)] for i in range(W + 1): dp[0][i] = 0 for i in range(N + 1): dp[i][0] = 0 for i in range(1, N + 1): # 1<= i <= N for j in range(1, W + 1): # 1 <= j <= W if j - items[i - 1][1] >= 0: dp[i][j] = max( dp[i - 1][j], dp[i - 1][j - items[i - 1][1]] + items[i - 1][0] ) else: dp[i][j] = dp[i - 1][j] print((dp[N][W]))
N, W = list(map(int, input().split())) INF = 10**10 # dp = [[INF]*100000]*(N*100)#余分に dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(N): dp[i][0] = 0 for j in range(W + 1): dp[0][j] = 0 for i in range(N): v, w = list(map(int, input().split())) for j in range(W + 1): if j - w >= 0: dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v) else: dp[i + 1][j] = dp[i][j] print((dp[N][W]))
false
15.384615
[ "-INF = 10**12", "-items = [] * N", "+INF = 10**10", "+# dp = [[INF]*100000]*(N*100)#余分に", "+dp = [[0 for i in range(W + 1)] for j in range(N + 1)]", "+for i in range(N):", "+ dp[i][0] = 0", "+for j in range(W + 1):", "+ dp[0][j] = 0", "- items.append([v, w])", "-dp = [[INF for i in range(W + 1)] for j in range(N + 1)]", "-for i in range(W + 1):", "- dp[0][i] = 0", "-for i in range(N + 1):", "- dp[i][0] = 0", "-for i in range(1, N + 1): # 1<= i <= N", "- for j in range(1, W + 1): # 1 <= j <= W", "- if j - items[i - 1][1] >= 0:", "- dp[i][j] = max(", "- dp[i - 1][j], dp[i - 1][j - items[i - 1][1]] + items[i - 1][0]", "- )", "+ for j in range(W + 1):", "+ if j - w >= 0:", "+ dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)", "- dp[i][j] = dp[i - 1][j]", "+ dp[i + 1][j] = dp[i][j]" ]
false
0.039635
0.041524
0.954519
[ "s973641313", "s432029110" ]
u350997995
p02859
python
s236085290
s884429566
21
17
3,316
2,940
Accepted
Accepted
19.05
print((int(eval(input()))**2))
r = int(eval(input())) print((r*r))
1
2
22
28
print((int(eval(input())) ** 2))
r = int(eval(input())) print((r * r))
false
50
[ "-print((int(eval(input())) ** 2))", "+r = int(eval(input()))", "+print((r * r))" ]
false
0.046825
0.048679
0.961908
[ "s236085290", "s884429566" ]
u379959788
p03624
python
s962209034
s119762969
33
20
3,188
3,956
Accepted
Accepted
39.39
# ABC072-B S = eval(input()) ss = set() for i in range(len(S)): ss.add(S[i]) alpha_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] ans = '' for k in range(len(alpha_list)): if alpha_list[k] not in ss: ans = alpha_list[k] break if len(ss) == 26: print('None') else: print(ans)
S = eval(input()) S = set(list(S)) alp = [chr(ord('a') + i) for i in range(26)] for al in alp: if al in S: pass else: print(al) exit() print("None")
17
10
432
183
# ABC072-B S = eval(input()) ss = set() for i in range(len(S)): ss.add(S[i]) alpha_list = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] ans = "" for k in range(len(alpha_list)): if alpha_list[k] not in ss: ans = alpha_list[k] break if len(ss) == 26: print("None") else: print(ans)
S = eval(input()) S = set(list(S)) alp = [chr(ord("a") + i) for i in range(26)] for al in alp: if al in S: pass else: print(al) exit() print("None")
false
41.176471
[ "-# ABC072-B", "-ss = set()", "-for i in range(len(S)):", "- ss.add(S[i])", "-alpha_list = [", "- \"a\",", "- \"b\",", "- \"c\",", "- \"d\",", "- \"e\",", "- \"f\",", "- \"g\",", "- \"h\",", "- \"i\",", "- \"j\",", "- \"k\",", "- \"l\",", "- \"m\",", "- \"n\",", "- \"o\",", "- \"p\",", "- \"q\",", "- \"r\",", "- \"s\",", "- \"t\",", "- \"u\",", "- \"v\",", "- \"w\",", "- \"x\",", "- \"y\",", "- \"z\",", "-]", "-ans = \"\"", "-for k in range(len(alpha_list)):", "- if alpha_list[k] not in ss:", "- ans = alpha_list[k]", "- break", "-if len(ss) == 26:", "- print(\"None\")", "-else:", "- print(ans)", "+S = set(list(S))", "+alp = [chr(ord(\"a\") + i) for i in range(26)]", "+for al in alp:", "+ if al in S:", "+ pass", "+ else:", "+ print(al)", "+ exit()", "+print(\"None\")" ]
false
0.039862
0.03968
1.004601
[ "s962209034", "s119762969" ]
u116233709
p03329
python
s911178316
s032333538
1,263
189
5,548
5,528
Accepted
Accepted
85.04
n=int(eval(input())) import math ansa=[0] ansb=[0] ans=[] cnt=0 x=0 y=0 for i in range(1,n+1): while 9**(x+1)<=i: x+=1 for j in range(x,-1,-1): z=(math.floor(i/(9**j))%9) i-=(9**j)*z cnt+=z ansa.append(cnt) cnt=0 for i in range(1,n+1): while 6**(y+1)<=i: y+=1 for j in range(y,-1,-1): z=(math.floor(i/(6**j))%6) i-=(6**j)*z cnt+=z ansb.append(cnt) cnt=0 for i in range(n+1): ans.append(ansa[i]+ansb[n-i]) print((min(ans)))
n=int(eval(input())) li6=[46656,7776,1296,216,36,6,1] li9=[59049,6561,729,81,9,1] dp6=[0]*(n+1) dp9=[0]*(n+1) dp6[1]=1 dp9[1]=1 ans=[] for i in range(2,n+1): for j in range(7): if i>=li6[j]: k=i-li6[j] break dp6[i]=1+dp6[k] for i in range(2,n+1): for j in range(6): if i>=li9[j]: k=i-li9[j] break dp9[i]=1+dp9[k] for i in range(n+1): ans.append(dp6[i]+dp9[n-i]) print((min(ans)))
33
24
570
503
n = int(eval(input())) import math ansa = [0] ansb = [0] ans = [] cnt = 0 x = 0 y = 0 for i in range(1, n + 1): while 9 ** (x + 1) <= i: x += 1 for j in range(x, -1, -1): z = math.floor(i / (9**j)) % 9 i -= (9**j) * z cnt += z ansa.append(cnt) cnt = 0 for i in range(1, n + 1): while 6 ** (y + 1) <= i: y += 1 for j in range(y, -1, -1): z = math.floor(i / (6**j)) % 6 i -= (6**j) * z cnt += z ansb.append(cnt) cnt = 0 for i in range(n + 1): ans.append(ansa[i] + ansb[n - i]) print((min(ans)))
n = int(eval(input())) li6 = [46656, 7776, 1296, 216, 36, 6, 1] li9 = [59049, 6561, 729, 81, 9, 1] dp6 = [0] * (n + 1) dp9 = [0] * (n + 1) dp6[1] = 1 dp9[1] = 1 ans = [] for i in range(2, n + 1): for j in range(7): if i >= li6[j]: k = i - li6[j] break dp6[i] = 1 + dp6[k] for i in range(2, n + 1): for j in range(6): if i >= li9[j]: k = i - li9[j] break dp9[i] = 1 + dp9[k] for i in range(n + 1): ans.append(dp6[i] + dp9[n - i]) print((min(ans)))
false
27.272727
[ "-import math", "-", "-ansa = [0]", "-ansb = [0]", "+li6 = [46656, 7776, 1296, 216, 36, 6, 1]", "+li9 = [59049, 6561, 729, 81, 9, 1]", "+dp6 = [0] * (n + 1)", "+dp9 = [0] * (n + 1)", "+dp6[1] = 1", "+dp9[1] = 1", "-cnt = 0", "-x = 0", "-y = 0", "-for i in range(1, n + 1):", "- while 9 ** (x + 1) <= i:", "- x += 1", "- for j in range(x, -1, -1):", "- z = math.floor(i / (9**j)) % 9", "- i -= (9**j) * z", "- cnt += z", "- ansa.append(cnt)", "- cnt = 0", "-for i in range(1, n + 1):", "- while 6 ** (y + 1) <= i:", "- y += 1", "- for j in range(y, -1, -1):", "- z = math.floor(i / (6**j)) % 6", "- i -= (6**j) * z", "- cnt += z", "- ansb.append(cnt)", "- cnt = 0", "+for i in range(2, n + 1):", "+ for j in range(7):", "+ if i >= li6[j]:", "+ k = i - li6[j]", "+ break", "+ dp6[i] = 1 + dp6[k]", "+for i in range(2, n + 1):", "+ for j in range(6):", "+ if i >= li9[j]:", "+ k = i - li9[j]", "+ break", "+ dp9[i] = 1 + dp9[k]", "- ans.append(ansa[i] + ansb[n - i])", "+ ans.append(dp6[i] + dp9[n - i])" ]
false
0.293375
0.052786
5.557859
[ "s911178316", "s032333538" ]
u389910364
p03293
python
s677957375
s383344840
326
164
22,332
13,436
Accepted
Accepted
49.69
import bisect import os from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") S = sys.stdin.readline().rstrip() T = sys.stdin.readline().rstrip() a = T + T ok = False for i in range(len(S)): ok |= a[i:len(S)+i] == S if ok: print('Yes') else: print('No')
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 S = list(sys.stdin.buffer.readline().decode().rstrip()) T = list(sys.stdin.buffer.readline().decode().rstrip()) S = np.array(S, dtype=str) T = np.array(T, dtype=str) ok=False for _ in range(len(S)): S = np.roll(S, 1) ok |= np.all(S == T) if ok: print('Yes') else: print('No')
32
46
586
877
import bisect import os from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") S = sys.stdin.readline().rstrip() T = sys.stdin.readline().rstrip() a = T + T ok = False for i in range(len(S)): ok |= a[i : len(S) + i] == S if ok: print("Yes") else: print("No")
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 S = list(sys.stdin.buffer.readline().decode().rstrip()) T = list(sys.stdin.buffer.readline().decode().rstrip()) S = np.array(S, dtype=str) T = np.array(T, dtype=str) ok = False for _ in range(len(S)): S = np.roll(S, 1) ok |= np.all(S == T) if ok: print("Yes") else: print("No")
false
30.434783
[ "-import os", "-from collections import Counter, deque", "-from fractions import gcd", "-from functools import lru_cache", "-from functools import reduce", "-import functools", "+import cmath", "+import operator", "+import os", "+import re", "+import string", "+import sys", "+from collections import Counter, deque, defaultdict", "+from copy import deepcopy", "+from decimal import Decimal", "+from fractions import gcd", "+from functools import lru_cache, reduce", "+from operator import itemgetter, mul, add, xor", "-import re", "-import sys", "-sys.setrecursionlimit(2147483647)", "+sys.setrecursionlimit(10**9)", "-S = sys.stdin.readline().rstrip()", "-T = sys.stdin.readline().rstrip()", "-a = T + T", "+IINF = 10**18", "+MOD = 10**9 + 7", "+# MOD = 998244353", "+S = list(sys.stdin.buffer.readline().decode().rstrip())", "+T = list(sys.stdin.buffer.readline().decode().rstrip())", "+S = np.array(S, dtype=str)", "+T = np.array(T, dtype=str)", "-for i in range(len(S)):", "- ok |= a[i : len(S) + i] == S", "+for _ in range(len(S)):", "+ S = np.roll(S, 1)", "+ ok |= np.all(S == T)" ]
false
0.068264
0.178609
0.382197
[ "s677957375", "s383344840" ]
u557523358
p04046
python
s837370264
s918501178
1,648
1,456
11,096
3,064
Accepted
Accepted
11.65
M=10**9+7;F=[pow(X,M-2,M)for X in range(2*10**5)];H,W,A,B=list(map(int,input().split()));Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F[I+1]%M for I in range(1,H-A):C=C*(B-1+I)*F[I]*(H-I)*F[W+H-B-1-I]%M;Z=(Z+C)%M print(Z)
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=list(map(int,input().split()));Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*(H-I)*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M print(Z)
4
4
217
200
M = 10**9 + 7 F = [pow(X, M - 2, M) for X in range(2 * 10**5)] H, W, A, B = list(map(int, input().split())) Z = C = 1 for I in range(H - 1): Z = C = C * (W + H - B - 2 - I) * F[I + 1] % M for I in range(1, H - A): C = C * (B - 1 + I) * F[I] * (H - I) * F[W + H - B - 1 - I] % M Z = (Z + C) % M print(Z)
M = 10**9 + 7 F = lambda X: pow(X, M - 2, M) H, W, A, B = list(map(int, input().split())) Z = C = 1 for I in range(H - 1): Z = C = C * (W + H - B - 2 - I) * F(I + 1) % M for I in range(1, H - A): C = C * (B - 1 + I) * (H - I) * F(I * (W + H - B - 1 - I)) % M Z = (Z + C) % M print(Z)
false
0
[ "-F = [pow(X, M - 2, M) for X in range(2 * 10**5)]", "+F = lambda X: pow(X, M - 2, M)", "- Z = C = C * (W + H - B - 2 - I) * F[I + 1] % M", "+ Z = C = C * (W + H - B - 2 - I) * F(I + 1) % M", "- C = C * (B - 1 + I) * F[I] * (H - I) * F[W + H - B - 1 - I] % M", "+ C = C * (B - 1 + I) * (H - I) * F(I * (W + H - B - 1 - I)) % M" ]
false
0.900778
0.03728
24.162284
[ "s837370264", "s918501178" ]
u753803401
p02900
python
s591605638
s948118710
293
269
64,364
64,620
Accepted
Accepted
8.19
def slove(): import sys import fractions input = sys.stdin.readline a, b = list(map(int, input().rstrip('\n').split())) gcd = fractions.gcd(a, b) cnt = 1 for i in range(2, int(gcd ** 0.5) + 1): if gcd % i == 0: cnt += 1 while True: if gcd % i == 0: gcd //= i else: break if gcd != 1: cnt += 1 print(cnt) if __name__ == '__main__': slove()
def slove(): import sys import fractions input = sys.stdin.readline a, b = list(map(int, input().rstrip('\n').split())) gcd = fractions.gcd(a, b) cnt = 1 s = 2 e = int(gcd ** 0.5) + 1 d = True while True: if d: d = False for i in range(s, e): if gcd % i == 0: d = True cnt += 1 while True: if gcd % i == 0: gcd //= i else: break s = i + 1 e = int(gcd ** 0.5) + 1 break else: break if gcd != 1: cnt += 1 print(cnt) if __name__ == '__main__': slove()
22
34
514
836
def slove(): import sys import fractions input = sys.stdin.readline a, b = list(map(int, input().rstrip("\n").split())) gcd = fractions.gcd(a, b) cnt = 1 for i in range(2, int(gcd**0.5) + 1): if gcd % i == 0: cnt += 1 while True: if gcd % i == 0: gcd //= i else: break if gcd != 1: cnt += 1 print(cnt) if __name__ == "__main__": slove()
def slove(): import sys import fractions input = sys.stdin.readline a, b = list(map(int, input().rstrip("\n").split())) gcd = fractions.gcd(a, b) cnt = 1 s = 2 e = int(gcd**0.5) + 1 d = True while True: if d: d = False for i in range(s, e): if gcd % i == 0: d = True cnt += 1 while True: if gcd % i == 0: gcd //= i else: break s = i + 1 e = int(gcd**0.5) + 1 break else: break if gcd != 1: cnt += 1 print(cnt) if __name__ == "__main__": slove()
false
35.294118
[ "- for i in range(2, int(gcd**0.5) + 1):", "- if gcd % i == 0:", "- cnt += 1", "- while True:", "+ s = 2", "+ e = int(gcd**0.5) + 1", "+ d = True", "+ while True:", "+ if d:", "+ d = False", "+ for i in range(s, e):", "- gcd //= i", "- else:", "+ d = True", "+ cnt += 1", "+ while True:", "+ if gcd % i == 0:", "+ gcd //= i", "+ else:", "+ break", "+ s = i + 1", "+ e = int(gcd**0.5) + 1", "+ else:", "+ break" ]
false
0.094954
0.093756
1.012771
[ "s591605638", "s948118710" ]
u160414758
p03721
python
s597433601
s836779222
342
193
15,072
14,940
Accepted
Accepted
43.57
N,K = list(map(int,input().split())) d = {} for i in range(N): a,b = list(map(int,input().split())) if a in d: d[a]=d[a]+b else: d.setdefault(a,b) d = sorted(list(d.items())) for i in range(len(d)): K = K - d[i][1] if K <= 0: print((d[i][0])) break
from collections import defaultdict as dd import sys input = sys.stdin.readline N,K = list(map(int,input().split())) d = dd(int) for i in range(N): a,b = list(map(int,input().split())) d[a] += b d = sorted(d.items()) for i,j in d: K -= j if K <= 0: print(i) break
16
17
303
302
N, K = list(map(int, input().split())) d = {} for i in range(N): a, b = list(map(int, input().split())) if a in d: d[a] = d[a] + b else: d.setdefault(a, b) d = sorted(list(d.items())) for i in range(len(d)): K = K - d[i][1] if K <= 0: print((d[i][0])) break
from collections import defaultdict as dd import sys input = sys.stdin.readline N, K = list(map(int, input().split())) d = dd(int) for i in range(N): a, b = list(map(int, input().split())) d[a] += b d = sorted(d.items()) for i, j in d: K -= j if K <= 0: print(i) break
false
5.882353
[ "+from collections import defaultdict as dd", "+import sys", "+", "+input = sys.stdin.readline", "-d = {}", "+d = dd(int)", "- if a in d:", "- d[a] = d[a] + b", "- else:", "- d.setdefault(a, b)", "-d = sorted(list(d.items()))", "-for i in range(len(d)):", "- K = K - d[i][1]", "+ d[a] += b", "+d = sorted(d.items())", "+for i, j in d:", "+ K -= j", "- print((d[i][0]))", "+ print(i)" ]
false
0.036416
0.058324
0.624376
[ "s597433601", "s836779222" ]
u102461423
p03161
python
s368212676
s714479907
1,954
1,776
21,760
12,444
Accepted
Accepted
9.11
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) import numpy as np N,K = list(map(int,input().split())) H = np.array(input().split(), dtype=np.int64) N,K,H dp = np.zeros(N,dtype=np.int64) for i in range(1,N): L = max(0,i-K) dp[i] = np.min(np.abs(H[i] - H[L:i]) + dp[L:i]) answer = dp[-1] print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,K,*H = list(map(int,read().split())) H = [H[0]]*K+H dp = [0]*(K+N) for n in range(K,N+K): h = H[n] dp[n] = min(x+abs(y-h) for x,y in zip(dp[n-K:n],H[n-K:n])) answer = dp[-1] print(answer)
18
17
346
328
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) import numpy as np N, K = list(map(int, input().split())) H = np.array(input().split(), dtype=np.int64) N, K, H dp = np.zeros(N, dtype=np.int64) for i in range(1, N): L = max(0, i - K) dp[i] = np.min(np.abs(H[i] - H[L:i]) + dp[L:i]) answer = dp[-1] print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K, *H = list(map(int, read().split())) H = [H[0]] * K + H dp = [0] * (K + N) for n in range(K, N + K): h = H[n] dp[n] = min(x + abs(y - h) for x, y in zip(dp[n - K : n], H[n - K : n])) answer = dp[-1] print(answer)
false
5.555556
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-import numpy as np", "-", "-N, K = list(map(int, input().split()))", "-H = np.array(input().split(), dtype=np.int64)", "-N, K, H", "-dp = np.zeros(N, dtype=np.int64)", "-for i in range(1, N):", "- L = max(0, i - K)", "- dp[i] = np.min(np.abs(H[i] - H[L:i]) + dp[L:i])", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, K, *H = list(map(int, read().split()))", "+H = [H[0]] * K + H", "+dp = [0] * (K + N)", "+for n in range(K, N + K):", "+ h = H[n]", "+ dp[n] = min(x + abs(y - h) for x, y in zip(dp[n - K : n], H[n - K : n]))" ]
false
0.290599
0.153812
1.889311
[ "s368212676", "s714479907" ]
u285891772
p02723
python
s950520175
s140533746
42
38
5,396
5,148
Accepted
Accepted
9.52
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 S = eval(input()) if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 S = eval(input()) print(("Yes" if S[2]==S[3] and S[4]==S[5] else "No"))
25
23
872
849
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 S = eval(input()) if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 S = eval(input()) print(("Yes" if S[2] == S[3] and S[4] == S[5] else "No"))
false
8
[ "-if S[2] == S[3] and S[4] == S[5]:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+print((\"Yes\" if S[2] == S[3] and S[4] == S[5] else \"No\"))" ]
false
0.047145
0.067265
0.70088
[ "s950520175", "s140533746" ]
u227082700
p03945
python
s620166991
s831278050
47
18
3,188
3,188
Accepted
Accepted
61.7
s,ans=eval(input()),0 for i in range(len(s)-1): if s[i]!=s[i+1]:ans+=1 print(ans)
s=eval(input()) n=len(s) ans=s.count("WB") anss=s.count("BW") print((ans+anss))
4
5
80
75
s, ans = eval(input()), 0 for i in range(len(s) - 1): if s[i] != s[i + 1]: ans += 1 print(ans)
s = eval(input()) n = len(s) ans = s.count("WB") anss = s.count("BW") print((ans + anss))
false
20
[ "-s, ans = eval(input()), 0", "-for i in range(len(s) - 1):", "- if s[i] != s[i + 1]:", "- ans += 1", "-print(ans)", "+s = eval(input())", "+n = len(s)", "+ans = s.count(\"WB\")", "+anss = s.count(\"BW\")", "+print((ans + anss))" ]
false
0.06552
0.068389
0.958043
[ "s620166991", "s831278050" ]
u271934630
p03086
python
s671230668
s977591380
182
17
38,256
3,064
Accepted
Accepted
90.66
S = eval(input()) ACGT = ['A', 'C', 'G', 'T'] cnt = 0 maximum = 0 for s in S: if s in ACGT: cnt += 1 maximum = max(maximum, cnt) else: maximum = max(maximum, cnt) cnt = 0 print(maximum)
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() S = i_s() cnt = 0 ans = 0 for s in S: if s in ['A', 'T', 'C', 'G']: cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans)
14
22
235
379
S = eval(input()) ACGT = ["A", "C", "G", "T"] cnt = 0 maximum = 0 for s in S: if s in ACGT: cnt += 1 maximum = max(maximum, cnt) else: maximum = max(maximum, cnt) cnt = 0 print(maximum)
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() S = i_s() cnt = 0 ans = 0 for s in S: if s in ["A", "T", "C", "G"]: cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) print(ans)
false
36.363636
[ "-S = eval(input())", "-ACGT = [\"A\", \"C\", \"G\", \"T\"]", "+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()", "+S = i_s()", "-maximum = 0", "+ans = 0", "- if s in ACGT:", "+ if s in [\"A\", \"T\", \"C\", \"G\"]:", "- maximum = max(maximum, cnt)", "- maximum = max(maximum, cnt)", "+ ans = max(ans, cnt)", "-print(maximum)", "+ans = max(ans, cnt)", "+print(ans)" ]
false
0.035346
0.037287
0.947936
[ "s671230668", "s977591380" ]
u761320129
p02574
python
s972954403
s193241661
1,986
834
127,344
132,124
Accepted
Accepted
58.01
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) g = 0 for a in A: g = gcd(g,a) if g > 1: print('not coprime') exit() sa = set() for a in A: if a==1: continue if a in sa: print('setwise coprime') exit() sa.add(a) MAXN = 10**6+10 sieve = [0,0] + [1]*MAXN p = 2 small_primes = [] while p*p <= MAXN: if sieve[p]: small_primes.append(p) for q in range(2*p,MAXN+1,p): sieve[q] = 0 p += 1 st = set() for a in A: for p in small_primes: found = False while a%p==0: a //= p found = True if found: if p in st: print('setwise coprime') exit() st.add(p) if a==1: break else: if a in st: print('setwise coprime') exit() st.add(a) print('pairwise coprime')
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) g = 0 for a in A: g = gcd(g,a) if g > 1: print('not coprime') exit() MAXN = 10**6+10 sieve = [i for i in range(MAXN+1)] p = 2 while p*p <= MAXN: if sieve[p] == p: for q in range(2*p,MAXN+1,p): if sieve[q] == q: sieve[q] = p p += 1 st = set() for a in A: tmp = set() while a > 1: tmp.add(sieve[a]) a //= sieve[a] for p in tmp: if p in st: print('setwise coprime') exit() st.add(p) print('pairwise coprime')
50
33
956
637
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) g = 0 for a in A: g = gcd(g, a) if g > 1: print("not coprime") exit() sa = set() for a in A: if a == 1: continue if a in sa: print("setwise coprime") exit() sa.add(a) MAXN = 10**6 + 10 sieve = [0, 0] + [1] * MAXN p = 2 small_primes = [] while p * p <= MAXN: if sieve[p]: small_primes.append(p) for q in range(2 * p, MAXN + 1, p): sieve[q] = 0 p += 1 st = set() for a in A: for p in small_primes: found = False while a % p == 0: a //= p found = True if found: if p in st: print("setwise coprime") exit() st.add(p) if a == 1: break else: if a in st: print("setwise coprime") exit() st.add(a) print("pairwise coprime")
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) g = 0 for a in A: g = gcd(g, a) if g > 1: print("not coprime") exit() MAXN = 10**6 + 10 sieve = [i for i in range(MAXN + 1)] p = 2 while p * p <= MAXN: if sieve[p] == p: for q in range(2 * p, MAXN + 1, p): if sieve[q] == q: sieve[q] = p p += 1 st = set() for a in A: tmp = set() while a > 1: tmp.add(sieve[a]) a //= sieve[a] for p in tmp: if p in st: print("setwise coprime") exit() st.add(p) print("pairwise coprime")
false
34
[ "-sa = set()", "-for a in A:", "- if a == 1:", "- continue", "- if a in sa:", "- print(\"setwise coprime\")", "- exit()", "- sa.add(a)", "-sieve = [0, 0] + [1] * MAXN", "+sieve = [i for i in range(MAXN + 1)]", "-small_primes = []", "- if sieve[p]:", "- small_primes.append(p)", "+ if sieve[p] == p:", "- sieve[q] = 0", "+ if sieve[q] == q:", "+ sieve[q] = p", "- for p in small_primes:", "- found = False", "- while a % p == 0:", "- a //= p", "- found = True", "- if found:", "- if p in st:", "- print(\"setwise coprime\")", "- exit()", "- st.add(p)", "- if a == 1:", "- break", "- else:", "- if a in st:", "+ tmp = set()", "+ while a > 1:", "+ tmp.add(sieve[a])", "+ a //= sieve[a]", "+ for p in tmp:", "+ if p in st:", "- st.add(a)", "+ st.add(p)" ]
false
0.383158
0.910442
0.420848
[ "s972954403", "s193241661" ]
u892251744
p02762
python
s468662905
s121979987
691
529
80,728
61,144
Accepted
Accepted
23.44
def main(): import sys from collections import defaultdict input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.find_root(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = list(map(int, input().split())) UF = UnionFind(N+1) fr_num = [0] * (N+1) for _ in range(M): a, b = list(map(int, input().split())) UF.unite(a, b) fr_num[a] += 1 fr_num[b] += 1 ans = [0] * (N+1) for i in range(1, N+1): ans[i] = UF.size(i) - 1 - fr_num[i] for _ in range(K): c, d = list(map(int, input().split())) if UF.isSameGroup(c, d): ans[c] -= 1 ans[d] -= 1 print((*ans[1:])) if __name__ == '__main__': main()
def main(): import sys from collections import defaultdict input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = list(map(int, input().split())) UF = UnionFind(N+1) fr_num = [0] * (N+1) for _ in range(M): a, b = list(map(int, input().split())) UF.unite(a, b) fr_num[a] += 1 fr_num[b] += 1 ans = [0] * (N+1) for i in range(1, N+1): ans[i] = UF.size(i) - 1 - fr_num[i] for _ in range(K): c, d = list(map(int, input().split())) if UF.isSameGroup(c, d): ans[c] -= 1 ans[d] -= 1 print((*ans[1:])) if __name__ == '__main__': main()
61
59
1,669
1,586
def main(): import sys from collections import defaultdict input = sys.stdin.buffer.readline class UnionFind: def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.find_root(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = list(map(int, input().split())) UF = UnionFind(N + 1) fr_num = [0] * (N + 1) for _ in range(M): a, b = list(map(int, input().split())) UF.unite(a, b) fr_num[a] += 1 fr_num[b] += 1 ans = [0] * (N + 1) for i in range(1, N + 1): ans[i] = UF.size(i) - 1 - fr_num[i] for _ in range(K): c, d = list(map(int, input().split())) if UF.isSameGroup(c, d): ans[c] -= 1 ans[d] -= 1 print((*ans[1:])) if __name__ == "__main__": main()
def main(): import sys from collections import defaultdict input = sys.stdin.buffer.readline class UnionFind: def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = list(map(int, input().split())) UF = UnionFind(N + 1) fr_num = [0] * (N + 1) for _ in range(M): a, b = list(map(int, input().split())) UF.unite(a, b) fr_num[a] += 1 fr_num[b] += 1 ans = [0] * (N + 1) for i in range(1, N + 1): ans[i] = UF.size(i) - 1 - fr_num[i] for _ in range(K): c, d = list(map(int, input().split())) if UF.isSameGroup(c, d): ans[c] -= 1 ans[d] -= 1 print((*ans[1:])) if __name__ == "__main__": main()
false
3.278689
[ "- if self.root[x] < 0:", "- return x", "- else:", "- self.root[x] = self.find_root(self.root[x])", "- return self.root[x]", "+ while self.root[x] >= 0:", "+ x = self.root[x]", "+ return x" ]
false
0.04187
0.042609
0.982659
[ "s468662905", "s121979987" ]
u987164499
p02936
python
s831399624
s808677699
1,976
1,378
300,156
253,160
Accepted
Accepted
30.26
from sys import stdin,setrecursionlimit from itertools import groupby setrecursionlimit(10**6) n,q = [int(x) for x in stdin.readline().rstrip().split()] li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n-1)] lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)] kazu = [[]for _ in range(n+1)] point = [0]*(n+1) for i in li: kazu[i[0]].append(i[1]) kazu[i[1]].append(i[0]) for i in lin: point[i[0]] += i[1] def dfs(now,before): for i in (kazu[now]): if i == before: continue point[i] += point[now] dfs(i,now) dfs(1,0) print((*point[1:]))
from collections import defaultdict from sys import setrecursionlimit setrecursionlimit(10 ** 7) n,q = list(map(int,input().split())) node = [[] for _ in range(n+1)] counter = [0 for _ in range(n+1)] visited = [0 for _ in range(n+1)] point_dic = defaultdict(int) for _ in range(n-1): a,b = list(map(int,input().split())) node[a].append(b) node[b].append(a) for _ in range(q): p,x = list(map(int,input().split())) point_dic[p] += x def dfs(now,before): global counter global visited if visited[now]: return if point_dic[now]: point = point_dic[now]+before else: point = before visited[now] = 1 counter[now] += point for i in node[now]: if visited[i]: continue dfs(i,point) dfs(1,0) print((' '.join(map(str, counter[1:]))))
21
44
649
868
from sys import stdin, setrecursionlimit from itertools import groupby setrecursionlimit(10**6) n, q = [int(x) for x in stdin.readline().rstrip().split()] li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n - 1)] lin = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)] kazu = [[] for _ in range(n + 1)] point = [0] * (n + 1) for i in li: kazu[i[0]].append(i[1]) kazu[i[1]].append(i[0]) for i in lin: point[i[0]] += i[1] def dfs(now, before): for i in kazu[now]: if i == before: continue point[i] += point[now] dfs(i, now) dfs(1, 0) print((*point[1:]))
from collections import defaultdict from sys import setrecursionlimit setrecursionlimit(10**7) n, q = list(map(int, input().split())) node = [[] for _ in range(n + 1)] counter = [0 for _ in range(n + 1)] visited = [0 for _ in range(n + 1)] point_dic = defaultdict(int) for _ in range(n - 1): a, b = list(map(int, input().split())) node[a].append(b) node[b].append(a) for _ in range(q): p, x = list(map(int, input().split())) point_dic[p] += x def dfs(now, before): global counter global visited if visited[now]: return if point_dic[now]: point = point_dic[now] + before else: point = before visited[now] = 1 counter[now] += point for i in node[now]: if visited[i]: continue dfs(i, point) dfs(1, 0) print((" ".join(map(str, counter[1:]))))
false
52.272727
[ "-from sys import stdin, setrecursionlimit", "-from itertools import groupby", "+from collections import defaultdict", "+from sys import setrecursionlimit", "-setrecursionlimit(10**6)", "-n, q = [int(x) for x in stdin.readline().rstrip().split()]", "-li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n - 1)]", "-lin = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]", "-kazu = [[] for _ in range(n + 1)]", "-point = [0] * (n + 1)", "-for i in li:", "- kazu[i[0]].append(i[1])", "- kazu[i[1]].append(i[0])", "-for i in lin:", "- point[i[0]] += i[1]", "+setrecursionlimit(10**7)", "+n, q = list(map(int, input().split()))", "+node = [[] for _ in range(n + 1)]", "+counter = [0 for _ in range(n + 1)]", "+visited = [0 for _ in range(n + 1)]", "+point_dic = defaultdict(int)", "+for _ in range(n - 1):", "+ a, b = list(map(int, input().split()))", "+ node[a].append(b)", "+ node[b].append(a)", "+for _ in range(q):", "+ p, x = list(map(int, input().split()))", "+ point_dic[p] += x", "- for i in kazu[now]:", "- if i == before:", "+ global counter", "+ global visited", "+ if visited[now]:", "+ return", "+ if point_dic[now]:", "+ point = point_dic[now] + before", "+ else:", "+ point = before", "+ visited[now] = 1", "+ counter[now] += point", "+ for i in node[now]:", "+ if visited[i]:", "- point[i] += point[now]", "- dfs(i, now)", "+ dfs(i, point)", "-print((*point[1:]))", "+print((\" \".join(map(str, counter[1:]))))" ]
false
0.03819
0.037977
1.005609
[ "s831399624", "s808677699" ]
u498487134
p02868
python
s944720052
s790196763
1,000
638
92,636
86,960
Accepted
Accepted
36.2
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N,M=MI() inf=10**16 class SegTree: def __init__(self,N,ide,segfunc=min): self.ide_ele = ide """ ex) 最小値のセグ木 → +inf 和のセグ木 → 0 積のセグ木 → 1 gcdのセグ木 → 0 """ self.segfunc=segfunc #num:N以上の最小の2のべき乗 self.num =2**(N-1).bit_length() self.seg=[self.ide_ele]*2*self.num #リストで初期化する def setL(self,init_val): #init_valは操作する数列 for i in range(N): self.seg[i+self.num-1]=init_val[i] #built for i in range(self.num-2,-1,-1) : self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) #k番目の値をxに更新 def update(self,k,x): k += self.num-1 self.seg[k] = x while k: k = (k-1)//2 self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2]) #[p,q)の区間に対するクエリへの応答 def query(self,p,q): if q<=p: return self.ide_ele p += self.num-1 q += self.num-2 res=self.ide_ele while q-p>1: if p&1 == 0: res = self.segfunc(res,self.seg[p]) if q&1 == 1: res = self.segfunc(res,self.seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = self.segfunc(res,self.seg[p]) else: res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]) return res seg=SegTree(N+1,inf,min) L=[0]*M R=[0]*M C=[0]*M for i in range(M): l,r,c=MI() l-=1 r-=1 L[i]=l R[i]=r C[i]=c R,C,L=list(zip(*sorted(zip(R,C,L)))) #rが小さいものから見て(rが同じならcが小さい)確定させていく now=0#確定させたとこと seg.update(0,0) for i in range(M): r=R[i] l=L[i] c=C[i] m=seg.query(l,now+1)#移動もとの範囲での最小値 #seg.update(r,m+c) now=r #このままだと入力例3みたいに,コストは低いけどl,rがちかいみたいなのを先に処理してしまう #とりあえず右端だけ更新しとけばokか? if m+c<seg.query(now,now+1): seg.update(now,m+c) #print((l+1,r+1,c),now+1,m,m+c) """ for ii in range(N): print(seg.query(ii,ii+1))""" ans=seg.query(N-1,N) if ans>=inf: print((-1)) else: print(ans) main()
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N,M=MI() inf=10**16 ########################################## import heapq class Dijkstra(): """ ・有向 / 無向は問わない(無向の場合は,逆向きの辺もたす) ・負のコストがない場合のみ ・計算量はO(E log|V|)  ・heapを使うことで頂点を走査する必要がなくなる(代わりに,距離更新したものは確定でなくともqueに入れておく) """ #最短のpathをたす class Edge(): #重み付き有向辺 def __init__(self, _to, _cost): self.to =_to self.cost = _cost def __init__(self, V): #引数Vは頂点数 self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺 self. _E = 0 #辺の数 self._V = V #頂点数 #proparty - 辺の数 def E(self): return self._E #proparty - 頂点数 def V(self): return self._V def add(self, _from, _to, _cost): #2頂点と辺のコストを追加 self.G[_from].append(self.Edge(_to,_cost)) self._E +=1 def add2(self, _from, _to, _cost): #2頂点と辺のコスト(無向)を追加 self.G[_from].append(self.Edge(_to, _cost)) self.G[_to].append(self.Edge(_from, _cost)) self._E +=2 def shortest_path(self,s):#,g): #始点sから頂点iまでの最短経路長のリストを返す que = [] #priority queue d = [inf] * self.V() prev = [None]*self.V() #prev[j]は,sからjへ最短経路で行くときのjの一つ前の場所 d[s] = 0 heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加 while len(que)!=0: #キューに格納されてある中で一番コストが小さい頂点を取り出す cost,v = heapq.heappop(que) #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ if d[v] < cost: continue #頂点vに隣接する各頂点iに対して,vを経由した場合の距離を計算して,これがd[i]よりも小さい場合に更新 for i in range(len(self.G[v])): e = self.G[v][i] #vのi個目の隣接辺 if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost #更新 prev[e.to] = v heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加 """#sからgまでの最短経路 path = [] pos = g #今いる場所,ゴールで初期化 for _ in range(self.V()+1): path.append(pos) if pos == s: break #print("pos:",format(pos)) pos = prev[pos] path.reverse() #print(path)""" return d#,path ######################## djk=Dijkstra(N) for i in range(M): l,r,c=MI() l-=1 r-=1 djk.add(l,r,c) for i in range(1,N): djk.add(i,i-1,0) d=djk.shortest_path(0) ans=d[-1] if ans>=inf: print((-1)) else: print(ans) main()
127
127
2,911
3,312
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N, M = MI() inf = 10**16 class SegTree: def __init__(self, N, ide, segfunc=min): self.ide_ele = ide """ ex) 最小値のセグ木 → +inf 和のセグ木 → 0 積のセグ木 → 1 gcdのセグ木 → 0 """ self.segfunc = segfunc # num:N以上の最小の2のべき乗 self.num = 2 ** (N - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num # リストで初期化する def setL(self, init_val): # init_valは操作する数列 for i in range(N): self.seg[i + self.num - 1] = init_val[i] # built for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) # k番目の値をxに更新 def update(self, k, x): k += self.num - 1 self.seg[k] = x while k: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) # [p,q)の区間に対するクエリへの応答 def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = self.segfunc(res, self.seg[p]) if q & 1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res seg = SegTree(N + 1, inf, min) L = [0] * M R = [0] * M C = [0] * M for i in range(M): l, r, c = MI() l -= 1 r -= 1 L[i] = l R[i] = r C[i] = c R, C, L = list(zip(*sorted(zip(R, C, L)))) # rが小さいものから見て(rが同じならcが小さい)確定させていく now = 0 # 確定させたとこと seg.update(0, 0) for i in range(M): r = R[i] l = L[i] c = C[i] m = seg.query(l, now + 1) # 移動もとの範囲での最小値 # seg.update(r,m+c) now = r # このままだと入力例3みたいに,コストは低いけどl,rがちかいみたいなのを先に処理してしまう # とりあえず右端だけ更新しとけばokか? if m + c < seg.query(now, now + 1): seg.update(now, m + c) # print((l+1,r+1,c),now+1,m,m+c) """ for ii in range(N): print(seg.query(ii,ii+1))""" ans = seg.query(N - 1, N) if ans >= inf: print((-1)) else: print(ans) main()
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N, M = MI() inf = 10**16 ########################################## import heapq class Dijkstra: """ ・有向 / 無向は問わない(無向の場合は,逆向きの辺もたす) ・負のコストがない場合のみ ・計算量はO(E log|V|) ・heapを使うことで頂点を走査する必要がなくなる(代わりに,距離更新したものは確定でなくともqueに入れておく) """ # 最短のpathをたす class Edge: # 重み付き有向辺 def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): # 引数Vは頂点数 self.G = [[] for _ in range(V)] # 隣接リストG[u][i]が頂点uのi番目の辺 self._E = 0 # 辺の数 self._V = V # 頂点数 # proparty - 辺の数 def E(self): return self._E # proparty - 頂点数 def V(self): return self._V def add(self, _from, _to, _cost): # 2頂点と辺のコストを追加 self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def add2(self, _from, _to, _cost): # 2頂点と辺のコスト(無向)を追加 self.G[_from].append(self.Edge(_to, _cost)) self.G[_to].append(self.Edge(_from, _cost)) self._E += 2 def shortest_path(self, s): # ,g): # 始点sから頂点iまでの最短経路長のリストを返す que = [] # priority queue d = [inf] * self.V() prev = [None] * self.V() # prev[j]は,sからjへ最短経路で行くときのjの一つ前の場所 d[s] = 0 heapq.heappush(que, (0, s)) # 始点の距離と頂点番号をヒープに追加 while len(que) != 0: # キューに格納されてある中で一番コストが小さい頂点を取り出す cost, v = heapq.heappop(que) # キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ if d[v] < cost: continue # 頂点vに隣接する各頂点iに対して,vを経由した場合の距離を計算して,これがd[i]よりも小さい場合に更新 for i in range(len(self.G[v])): e = self.G[v][i] # vのi個目の隣接辺 if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # 更新 prev[e.to] = v heapq.heappush(que, (d[e.to], e.to)) # queに新たな最短経路長候補を追加 """#sからgまでの最短経路 path = [] pos = g #今いる場所,ゴールで初期化 for _ in range(self.V()+1): path.append(pos) if pos == s: break #print("pos:",format(pos)) pos = prev[pos] path.reverse() #print(path)""" return d # ,path ######################## djk = Dijkstra(N) for i in range(M): l, r, c = MI() l -= 1 r -= 1 djk.add(l, r, c) for i in range(1, N): djk.add(i, i - 1, 0) d = djk.shortest_path(0) ans = d[-1] if ans >= inf: print((-1)) else: print(ans) main()
false
0
[ "+ ##########################################", "+ import heapq", "- class SegTree:", "- def __init__(self, N, ide, segfunc=min):", "- self.ide_ele = ide", "- \"\"\"", "- ex)", "- 最小値のセグ木 → +inf", "- 和のセグ木 → 0", "- 積のセグ木 → 1", "- gcdのセグ木 → 0", "- \"\"\"", "- self.segfunc = segfunc", "- # num:N以上の最小の2のべき乗", "- self.num = 2 ** (N - 1).bit_length()", "- self.seg = [self.ide_ele] * 2 * self.num", "+ class Dijkstra:", "+ \"\"\"", "+ ・有向 / 無向は問わない(無向の場合は,逆向きの辺もたす)", "+ ・負のコストがない場合のみ", "+ ・計算量はO(E log|V|)", "+ ・heapを使うことで頂点を走査する必要がなくなる(代わりに,距離更新したものは確定でなくともqueに入れておく)", "+ \"\"\"", "- # リストで初期化する", "- def setL(self, init_val):", "- # init_valは操作する数列", "- for i in range(N):", "- self.seg[i + self.num - 1] = init_val[i]", "- # built", "- for i in range(self.num - 2, -1, -1):", "- self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])", "+ # 最短のpathをたす", "+ class Edge:", "+ # 重み付き有向辺", "+ def __init__(self, _to, _cost):", "+ self.to = _to", "+ self.cost = _cost", "- # k番目の値をxに更新", "- def update(self, k, x):", "- k += self.num - 1", "- self.seg[k] = x", "- while k:", "- k = (k - 1) // 2", "- self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])", "+ def __init__(self, V):", "+ # 引数Vは頂点数", "+ self.G = [[] for _ in range(V)] # 隣接リストG[u][i]が頂点uのi番目の辺", "+ self._E = 0 # 辺の数", "+ self._V = V # 頂点数", "- # [p,q)の区間に対するクエリへの応答", "- def query(self, p, q):", "- if q <= p:", "- return self.ide_ele", "- p += self.num - 1", "- q += self.num - 2", "- res = self.ide_ele", "- while q - p > 1:", "- if p & 1 == 0:", "- res = self.segfunc(res, self.seg[p])", "- if q & 1 == 1:", "- res = self.segfunc(res, self.seg[q])", "- q -= 1", "- p = p // 2", "- q = (q - 1) // 2", "- if p == q:", "- res = self.segfunc(res, self.seg[p])", "- else:", "- res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])", "- return res", "+ # proparty - 辺の数", "+ def E(self):", "+ return self._E", "- seg = SegTree(N + 1, inf, min)", "- L = [0] * M", "- R = [0] * M", "- C = [0] * M", "+ # proparty - 頂点数", "+ def V(self):", "+ return self._V", "+", "+ def add(self, _from, _to, _cost):", "+ # 2頂点と辺のコストを追加", "+ self.G[_from].append(self.Edge(_to, _cost))", "+ self._E += 1", "+", "+ def add2(self, _from, _to, _cost):", "+ # 2頂点と辺のコスト(無向)を追加", "+ self.G[_from].append(self.Edge(_to, _cost))", "+ self.G[_to].append(self.Edge(_from, _cost))", "+ self._E += 2", "+", "+ def shortest_path(self, s): # ,g):", "+ # 始点sから頂点iまでの最短経路長のリストを返す", "+ que = [] # priority queue", "+ d = [inf] * self.V()", "+ prev = [None] * self.V() # prev[j]は,sからjへ最短経路で行くときのjの一つ前の場所", "+ d[s] = 0", "+ heapq.heappush(que, (0, s)) # 始点の距離と頂点番号をヒープに追加", "+ while len(que) != 0:", "+ # キューに格納されてある中で一番コストが小さい頂点を取り出す", "+ cost, v = heapq.heappop(que)", "+ # キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ", "+ if d[v] < cost:", "+ continue", "+ # 頂点vに隣接する各頂点iに対して,vを経由した場合の距離を計算して,これがd[i]よりも小さい場合に更新", "+ for i in range(len(self.G[v])):", "+ e = self.G[v][i] # vのi個目の隣接辺", "+ if d[e.to] > d[v] + e.cost:", "+ d[e.to] = d[v] + e.cost # 更新", "+ prev[e.to] = v", "+ heapq.heappush(que, (d[e.to], e.to)) # queに新たな最短経路長候補を追加", "+ \"\"\"#sからgまでの最短経路", "+ path = []", "+ pos = g #今いる場所,ゴールで初期化", "+ for _ in range(self.V()+1):", "+ path.append(pos)", "+ if pos == s:", "+ break", "+ #print(\"pos:\",format(pos))", "+ pos = prev[pos]", "+ path.reverse()", "+ #print(path)\"\"\"", "+ return d # ,path", "+", "+ ########################", "+ djk = Dijkstra(N)", "- L[i] = l", "- R[i] = r", "- C[i] = c", "- R, C, L = list(zip(*sorted(zip(R, C, L))))", "- # rが小さいものから見て(rが同じならcが小さい)確定させていく", "- now = 0 # 確定させたとこと", "- seg.update(0, 0)", "- for i in range(M):", "- r = R[i]", "- l = L[i]", "- c = C[i]", "- m = seg.query(l, now + 1) # 移動もとの範囲での最小値", "- # seg.update(r,m+c)", "- now = r", "- # このままだと入力例3みたいに,コストは低いけどl,rがちかいみたいなのを先に処理してしまう", "- # とりあえず右端だけ更新しとけばokか?", "- if m + c < seg.query(now, now + 1):", "- seg.update(now, m + c)", "- # print((l+1,r+1,c),now+1,m,m+c)", "- \"\"\"", "- for ii in range(N):", "- print(seg.query(ii,ii+1))\"\"\"", "- ans = seg.query(N - 1, N)", "+ djk.add(l, r, c)", "+ for i in range(1, N):", "+ djk.add(i, i - 1, 0)", "+ d = djk.shortest_path(0)", "+ ans = d[-1]" ]
false
0.069707
0.042204
1.651691
[ "s944720052", "s790196763" ]
u167647458
p02725
python
s862180153
s509899413
136
116
26,436
26,420
Accepted
Accepted
14.71
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + k) m = 0 for i in range(n): m = max(m, a[i+1] - a[i]) print((k - m))
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + k) m = [] for i in range(n): m.append(a[i+1] - a[i]) print((k - max(m)))
8
7
163
165
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + k) m = 0 for i in range(n): m = max(m, a[i + 1] - a[i]) print((k - m))
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + k) m = [] for i in range(n): m.append(a[i + 1] - a[i]) print((k - max(m)))
false
12.5
[ "-m = 0", "+m = []", "- m = max(m, a[i + 1] - a[i])", "-print((k - m))", "+ m.append(a[i + 1] - a[i])", "+print((k - max(m)))" ]
false
0.037512
0.048924
0.766731
[ "s862180153", "s509899413" ]
u201234972
p03673
python
s604704000
s565808409
353
156
25,412
30,660
Accepted
Accepted
55.81
from collections import deque n = int(input()) A = list( map( int, input().split())) B = deque() reverse = 0 for i in range(n): if reverse == 0: B.append(A[i]) reverse = 1 else: B.appendleft(A[i]) reverse = 0 B = list(B) if reverse == 1: B = B[::-1] for i in range(n-1): print(B[i], end = ' ') print(B[n-1])
from collections import deque n = int(eval(input())) A = list( map( int, input().split())) B = deque() reverse = 0 for i in range(n): if reverse == 0: B.append(A[i]) reverse = 1 else: B.appendleft(A[i]) reverse = 0 B = list(B) if reverse == 1: B = B[::-1] print(( ' '.join( list( map(str, B)))))
18
16
372
346
from collections import deque n = int(input()) A = list(map(int, input().split())) B = deque() reverse = 0 for i in range(n): if reverse == 0: B.append(A[i]) reverse = 1 else: B.appendleft(A[i]) reverse = 0 B = list(B) if reverse == 1: B = B[::-1] for i in range(n - 1): print(B[i], end=" ") print(B[n - 1])
from collections import deque n = int(eval(input())) A = list(map(int, input().split())) B = deque() reverse = 0 for i in range(n): if reverse == 0: B.append(A[i]) reverse = 1 else: B.appendleft(A[i]) reverse = 0 B = list(B) if reverse == 1: B = B[::-1] print((" ".join(list(map(str, B)))))
false
11.111111
[ "-n = int(input())", "+n = int(eval(input()))", "-for i in range(n - 1):", "- print(B[i], end=\" \")", "-print(B[n - 1])", "+print((\" \".join(list(map(str, B)))))" ]
false
0.04519
0.043577
1.037012
[ "s604704000", "s565808409" ]
u305366205
p03352
python
s385671179
s287268865
21
17
2,940
2,940
Accepted
Accepted
19.05
x = int(eval(input())) ans = 1 for b in range(1, 1001): for p in range(2, 11): now = b ** p if now <= x: ans = max(ans, now) print(ans)
X = int(eval(input())) ans = 0 for b in range(1, 32): for p in range(2, 10): exp = b ** p if exp <= X: ans = max(ans, exp) print(ans)
8
8
168
166
x = int(eval(input())) ans = 1 for b in range(1, 1001): for p in range(2, 11): now = b**p if now <= x: ans = max(ans, now) print(ans)
X = int(eval(input())) ans = 0 for b in range(1, 32): for p in range(2, 10): exp = b**p if exp <= X: ans = max(ans, exp) print(ans)
false
0
[ "-x = int(eval(input()))", "-ans = 1", "-for b in range(1, 1001):", "- for p in range(2, 11):", "- now = b**p", "- if now <= x:", "- ans = max(ans, now)", "+X = int(eval(input()))", "+ans = 0", "+for b in range(1, 32):", "+ for p in range(2, 10):", "+ exp = b**p", "+ if exp <= X:", "+ ans = max(ans, exp)" ]
false
0.041473
0.03716
1.116059
[ "s385671179", "s287268865" ]
u645250356
p02733
python
s499630686
s495687153
844
462
101,080
80,208
Accepted
Accepted
45.26
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions from decimal import Decimal sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,m,K = inpl() s = [eval(input()) for _ in range(n)] res = INF for pat in itertools.product([0,1], repeat=n-1): pat = list(pat) + [0] group = [] tmp = [] for i,j in enumerate(pat): tmp += [i] if j or i == n-1: group += [tmp] tmp = [] ln = len(group) white = [[0]*ln for _ in range(m)] ccc = set() cnt = pat.count(1) ok = True for i in range(m): for j,z in enumerate(group): for k in z: if s[k][i] == '1': white[i][j] += 1 if max(white[i]) > K: ok = False break if not ok: continue now = [0] * ln for i in range(m): ok = True for j in range(ln): if now[j] + white[i][j] > K: ok = False break if ok: for j in range(ln): now[j] += white[i][j] else: cnt += 1 for j in range(ln): now[j] = white[i][j] res = min(res, cnt) print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) h,w,k = inpl() s = [list(eval(input())) for _ in range(h)] res = INF for yoko in itertools.product([0,1], repeat=(h-1)): # 0:uncut 1:cut ln = sum(yoko) gr = [[] for _ in range(ln+1)] gr[0].append(0) ind = 0 for i in range(1,h): if yoko[i-1]: ind += 1 gr[ind].append(i) possible = True for x in range(w): for ind in range(ln+1): cnt = 0 for y in gr[ind]: if s[y][x] == '1': cnt += 1 if cnt > k: possible = False break if not possible: break else: cutcnt = 0 now = [0] * (ln+1) for x in range(w): for ind in range(ln+1): for y in gr[ind]: if s[y][x] == '1': now[ind] += 1 if max(now) > k: now = [0] * (ln+1) cutcnt += 1 for ind in range(ln+1): for y in gr[ind]: if s[y][x] == '1': now[ind] += 1 res = min(res, cutcnt + ln) print(res)
54
51
1,459
1,540
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions from decimal import Decimal sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n, m, K = inpl() s = [eval(input()) for _ in range(n)] res = INF for pat in itertools.product([0, 1], repeat=n - 1): pat = list(pat) + [0] group = [] tmp = [] for i, j in enumerate(pat): tmp += [i] if j or i == n - 1: group += [tmp] tmp = [] ln = len(group) white = [[0] * ln for _ in range(m)] ccc = set() cnt = pat.count(1) ok = True for i in range(m): for j, z in enumerate(group): for k in z: if s[k][i] == "1": white[i][j] += 1 if max(white[i]) > K: ok = False break if not ok: continue now = [0] * ln for i in range(m): ok = True for j in range(ln): if now[j] + white[i][j] > K: ok = False break if ok: for j in range(ln): now[j] += white[i][j] else: cnt += 1 for j in range(ln): now[j] = white[i][j] res = min(res, cnt) print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) h, w, k = inpl() s = [list(eval(input())) for _ in range(h)] res = INF for yoko in itertools.product([0, 1], repeat=(h - 1)): # 0:uncut 1:cut ln = sum(yoko) gr = [[] for _ in range(ln + 1)] gr[0].append(0) ind = 0 for i in range(1, h): if yoko[i - 1]: ind += 1 gr[ind].append(i) possible = True for x in range(w): for ind in range(ln + 1): cnt = 0 for y in gr[ind]: if s[y][x] == "1": cnt += 1 if cnt > k: possible = False break if not possible: break else: cutcnt = 0 now = [0] * (ln + 1) for x in range(w): for ind in range(ln + 1): for y in gr[ind]: if s[y][x] == "1": now[ind] += 1 if max(now) > k: now = [0] * (ln + 1) cutcnt += 1 for ind in range(ln + 1): for y in gr[ind]: if s[y][x] == "1": now[ind] += 1 res = min(res, cutcnt + ln) print(res)
false
5.555556
[ "-from heapq import heappop, heappush, heapify", "-import sys, bisect, math, itertools, fractions", "-from decimal import Decimal", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "-n, m, K = inpl()", "-s = [eval(input()) for _ in range(n)]", "+h, w, k = inpl()", "+s = [list(eval(input())) for _ in range(h)]", "-for pat in itertools.product([0, 1], repeat=n - 1):", "- pat = list(pat) + [0]", "- group = []", "- tmp = []", "- for i, j in enumerate(pat):", "- tmp += [i]", "- if j or i == n - 1:", "- group += [tmp]", "- tmp = []", "- ln = len(group)", "- white = [[0] * ln for _ in range(m)]", "- ccc = set()", "- cnt = pat.count(1)", "- ok = True", "- for i in range(m):", "- for j, z in enumerate(group):", "- for k in z:", "- if s[k][i] == \"1\":", "- white[i][j] += 1", "- if max(white[i]) > K:", "- ok = False", "+for yoko in itertools.product([0, 1], repeat=(h - 1)):", "+ # 0:uncut 1:cut", "+ ln = sum(yoko)", "+ gr = [[] for _ in range(ln + 1)]", "+ gr[0].append(0)", "+ ind = 0", "+ for i in range(1, h):", "+ if yoko[i - 1]:", "+ ind += 1", "+ gr[ind].append(i)", "+ possible = True", "+ for x in range(w):", "+ for ind in range(ln + 1):", "+ cnt = 0", "+ for y in gr[ind]:", "+ if s[y][x] == \"1\":", "+ cnt += 1", "+ if cnt > k:", "+ possible = False", "- if not ok:", "- continue", "- now = [0] * ln", "- for i in range(m):", "- ok = True", "- for j in range(ln):", "- if now[j] + white[i][j] > K:", "- ok = False", "- break", "- if ok:", "- for j in range(ln):", "- now[j] += white[i][j]", "- else:", "- cnt += 1", "- for j in range(ln):", "- now[j] = white[i][j]", "- res = min(res, cnt)", "+ if not possible:", "+ break", "+ else:", "+ cutcnt = 0", "+ now = [0] * (ln + 1)", "+ for x in range(w):", "+ for ind in range(ln + 1):", "+ for y in gr[ind]:", "+ if s[y][x] == \"1\":", "+ now[ind] += 1", "+ if max(now) > k:", "+ now = [0] * (ln + 1)", "+ cutcnt += 1", "+ for ind in range(ln + 1):", "+ for y in gr[ind]:", "+ if s[y][x] == \"1\":", "+ now[ind] += 1", "+ res = min(res, cutcnt + ln)" ]
false
0.038103
0.075779
0.50282
[ "s499630686", "s495687153" ]
u936985471
p03163
python
s947944985
s827380532
177
141
14,536
28,864
Accepted
Accepted
20.34
N,W=list(map(int,input().split())) import numpy as np dp=np.zeros(W+1,dtype=int) for i in range(N): w,v=list(map(int,input().split())) np.maximum(dp[:-w]+v,dp[w:],out=dp[w:]) print((dp.max()))
import sys readline = sys.stdin.readline import numpy as np N,W = list(map(int,readline().split())) dp = np.zeros(W + 1, dtype = int) for i in range(N): w,v = list(map(int,readline().split())) np.maximum(dp[:-w] + v,dp[w:],out = dp[w:]) print((max(dp)))
7
13
189
261
N, W = list(map(int, input().split())) import numpy as np dp = np.zeros(W + 1, dtype=int) for i in range(N): w, v = list(map(int, input().split())) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp.max()))
import sys readline = sys.stdin.readline import numpy as np N, W = list(map(int, readline().split())) dp = np.zeros(W + 1, dtype=int) for i in range(N): w, v = list(map(int, readline().split())) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((max(dp)))
false
46.153846
[ "-N, W = list(map(int, input().split()))", "+import sys", "+", "+readline = sys.stdin.readline", "+N, W = list(map(int, readline().split()))", "- w, v = list(map(int, input().split()))", "+ w, v = list(map(int, readline().split()))", "-print((dp.max()))", "+print((max(dp)))" ]
false
0.180313
0.575206
0.313476
[ "s947944985", "s827380532" ]
u414980766
p02889
python
s330489983
s369860564
1,577
345
19,144
36,868
Accepted
Accepted
78.12
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix INF = 10**12 N, M, L = list(map(int, input().split())) A = []; B = []; C = [] for i in range(M): a, b, c = list(map(int, input().split())) A.append(a - 1); B.append(b - 1); C.append(c) A = np.array(A); B = np.array(B); C = np.array(C) graph = csr_matrix((C, (A, B)), (N, N)) d = floyd_warshall(graph, directed=False) d[d <= L] = 1 d[d > L] = INF d = floyd_warshall(d, directed=False) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) if d[s - 1][t - 1] != INF: print((int(d[s - 1][t - 1]) - 1)) else: print((- 1))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix INF = 10**12 N, M, L = list(map(int, readline().split())) ABCQST = np.array(read().split(), dtype=np.int64) ABC = ABCQST[:3*M] A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3] Q = ABCQST[3*M] ST = ABCQST[3*M + 1:] S = ST[::2]; T = ST[1::2] graph = csr_matrix((C, (A, B)), (N + 1, N + 1)) d = floyd_warshall(graph, directed=False) d[d <= L] = 1 d[d > L] = INF d = floyd_warshall(d, directed=False).astype(int) d[d == INF] = 0 d -= 1 print(('\n'.join(d.astype(str)[S, T])))
27
32
686
717
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix INF = 10**12 N, M, L = list(map(int, input().split())) A = [] B = [] C = [] for i in range(M): a, b, c = list(map(int, input().split())) A.append(a - 1) B.append(b - 1) C.append(c) A = np.array(A) B = np.array(B) C = np.array(C) graph = csr_matrix((C, (A, B)), (N, N)) d = floyd_warshall(graph, directed=False) d[d <= L] = 1 d[d > L] = INF d = floyd_warshall(d, directed=False) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) if d[s - 1][t - 1] != INF: print((int(d[s - 1][t - 1]) - 1)) else: print((-1))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix INF = 10**12 N, M, L = list(map(int, readline().split())) ABCQST = np.array(read().split(), dtype=np.int64) ABC = ABCQST[: 3 * M] A = ABC[::3] B = ABC[1::3] C = ABC[2::3] Q = ABCQST[3 * M] ST = ABCQST[3 * M + 1 :] S = ST[::2] T = ST[1::2] graph = csr_matrix((C, (A, B)), (N + 1, N + 1)) d = floyd_warshall(graph, directed=False) d[d <= L] = 1 d[d > L] = INF d = floyd_warshall(d, directed=False).astype(int) d[d == INF] = 0 d -= 1 print(("\n".join(d.astype(str)[S, T])))
false
15.625
[ "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "-N, M, L = list(map(int, input().split()))", "-A = []", "-B = []", "-C = []", "-for i in range(M):", "- a, b, c = list(map(int, input().split()))", "- A.append(a - 1)", "- B.append(b - 1)", "- C.append(c)", "-A = np.array(A)", "-B = np.array(B)", "-C = np.array(C)", "-graph = csr_matrix((C, (A, B)), (N, N))", "+N, M, L = list(map(int, readline().split()))", "+ABCQST = np.array(read().split(), dtype=np.int64)", "+ABC = ABCQST[: 3 * M]", "+A = ABC[::3]", "+B = ABC[1::3]", "+C = ABC[2::3]", "+Q = ABCQST[3 * M]", "+ST = ABCQST[3 * M + 1 :]", "+S = ST[::2]", "+T = ST[1::2]", "+graph = csr_matrix((C, (A, B)), (N + 1, N + 1))", "-d = floyd_warshall(d, directed=False)", "-Q = int(eval(input()))", "-for i in range(Q):", "- s, t = list(map(int, input().split()))", "- if d[s - 1][t - 1] != INF:", "- print((int(d[s - 1][t - 1]) - 1))", "- else:", "- print((-1))", "+d = floyd_warshall(d, directed=False).astype(int)", "+d[d == INF] = 0", "+d -= 1", "+print((\"\\n\".join(d.astype(str)[S, T])))" ]
false
0.258669
0.330942
0.781616
[ "s330489983", "s369860564" ]
u729133443
p03485
python
s767611628
s339716465
164
26
38,384
9,108
Accepted
Accepted
84.15
print((eval(input().replace(' ','+1+'))//2))
print((eval(input().replace(*' +'))+1>>1))
1
1
42
40
print((eval(input().replace(" ", "+1+")) // 2))
print((eval(input().replace(*" +")) + 1 >> 1))
false
0
[ "-print((eval(input().replace(\" \", \"+1+\")) // 2))", "+print((eval(input().replace(*\" +\")) + 1 >> 1))" ]
false
0.084577
0.080703
1.048004
[ "s767611628", "s339716465" ]
u875291233
p03014
python
s303758303
s687199716
1,027
700
96,088
179,460
Accepted
Accepted
31.84
# coding: utf-8 # Your code here! #n = int(input()) #s = input() #a = [int(i) for i in input().split()] #m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行 h,w = [int(i) for i in input().split()] b = [eval(input()) for i in range(h)] ans = [[0]*w for i in range(h)] for i in range(h): res = 0 for j in range(w): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 #print(ans) for i in range(h): res = 0 for j in range(w-1,-1,-1): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 #print(ans) for j in range(w): res = 0 for i in range(h): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 #print(ans) for j in range(w): res = 0 for i in range(h-1,-1,-1): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 #print(ans) print((max(max(row) for row in ans) + 1))
# coding: utf-8 # Your code here! h,w = [int(i) for i in input().split()] b = [eval(input()) for i in range(h)] l = [[0]*w for _ in [0]*h] #左にある白マス(自分含む) r = [[0]*w for _ in [0]*h] u = [[0]*w for _ in [0]*h] #上にある白マス(自分含む) d = [[0]*w for _ in [0]*h] for hi in range(h): for wj in range(w): if b[hi][wj] == '.': l[hi][wj] = l[hi][wj-1]+1 u[hi][wj] = u[hi-1][wj]+1 if b[hi][w-wj-1] == '.': r[hi][w-wj-1] = r[hi][-wj]+1 if b[h-hi-1][wj] == '.': d[h-hi-1][wj] = d[-hi][wj]+1 ans = 0 for i in range(h): for j in range(w): ans = max(ans, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3) print(ans)
64
26
1,224
696
# coding: utf-8 # Your code here! # n = int(input()) # s = input() # a = [int(i) for i in input().split()] # m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行 h, w = [int(i) for i in input().split()] b = [eval(input()) for i in range(h)] ans = [[0] * w for i in range(h)] for i in range(h): res = 0 for j in range(w): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 # print(ans) for i in range(h): res = 0 for j in range(w - 1, -1, -1): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 # print(ans) for j in range(w): res = 0 for i in range(h): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 # print(ans) for j in range(w): res = 0 for i in range(h - 1, -1, -1): if b[i][j] == ".": ans[i][j] += res if b[i][j] == ".": res += 1 else: res = 0 # print(ans) print((max(max(row) for row in ans) + 1))
# coding: utf-8 # Your code here! h, w = [int(i) for i in input().split()] b = [eval(input()) for i in range(h)] l = [[0] * w for _ in [0] * h] # 左にある白マス(自分含む) r = [[0] * w for _ in [0] * h] u = [[0] * w for _ in [0] * h] # 上にある白マス(自分含む) d = [[0] * w for _ in [0] * h] for hi in range(h): for wj in range(w): if b[hi][wj] == ".": l[hi][wj] = l[hi][wj - 1] + 1 u[hi][wj] = u[hi - 1][wj] + 1 if b[hi][w - wj - 1] == ".": r[hi][w - wj - 1] = r[hi][-wj] + 1 if b[h - hi - 1][wj] == ".": d[h - hi - 1][wj] = d[-hi][wj] + 1 ans = 0 for i in range(h): for j in range(w): ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3) print(ans)
false
59.375
[ "-# n = int(input())", "-# s = input()", "-# a = [int(i) for i in input().split()]", "-# m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行", "-ans = [[0] * w for i in range(h)]", "+l = [[0] * w for _ in [0] * h] # 左にある白マス(自分含む)", "+r = [[0] * w for _ in [0] * h]", "+u = [[0] * w for _ in [0] * h] # 上にある白マス(自分含む)", "+d = [[0] * w for _ in [0] * h]", "+for hi in range(h):", "+ for wj in range(w):", "+ if b[hi][wj] == \".\":", "+ l[hi][wj] = l[hi][wj - 1] + 1", "+ u[hi][wj] = u[hi - 1][wj] + 1", "+ if b[hi][w - wj - 1] == \".\":", "+ r[hi][w - wj - 1] = r[hi][-wj] + 1", "+ if b[h - hi - 1][wj] == \".\":", "+ d[h - hi - 1][wj] = d[-hi][wj] + 1", "+ans = 0", "- res = 0", "- if b[i][j] == \".\":", "- ans[i][j] += res", "- if b[i][j] == \".\":", "- res += 1", "- else:", "- res = 0", "-# print(ans)", "-for i in range(h):", "- res = 0", "- for j in range(w - 1, -1, -1):", "- if b[i][j] == \".\":", "- ans[i][j] += res", "- if b[i][j] == \".\":", "- res += 1", "- else:", "- res = 0", "-# print(ans)", "-for j in range(w):", "- res = 0", "- for i in range(h):", "- if b[i][j] == \".\":", "- ans[i][j] += res", "- if b[i][j] == \".\":", "- res += 1", "- else:", "- res = 0", "-# print(ans)", "-for j in range(w):", "- res = 0", "- for i in range(h - 1, -1, -1):", "- if b[i][j] == \".\":", "- ans[i][j] += res", "- if b[i][j] == \".\":", "- res += 1", "- else:", "- res = 0", "-# print(ans)", "-print((max(max(row) for row in ans) + 1))", "+ ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)", "+print(ans)" ]
false
0.083541
0.037508
2.227317
[ "s303758303", "s687199716" ]
u064505481
p03178
python
s543575733
s156531047
1,217
743
45,464
92,892
Accepted
Accepted
38.95
from sys import stdin, stdout from collections import deque, defaultdict from functools import lru_cache rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def main(): MOD = 10**9 + 7 x = [] for c in rll()[0]: x.append(int(c)) d = int(rl()) ans = 0 dp = [[0 for __ in range(2)] for _ in range(d)] dp[0][1] = 1 for i in range(len(x)): ndp = [[0 for __ in range(2)] for _ in range(d)] for digsum in range(d): for tight in range(2): for nd in range(x[i]+1 if tight else 10): ns = (digsum + nd) % d ntight = 1 if tight and nd == x[i] else 0 ndp[ns][ntight] += dp[digsum][tight] ndp[ns][ntight] %= MOD dp = ndp ans = (dp[0][0] + dp[0][1] - 1) % MOD print(ans) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop from functools import lru_cache import math setrecursionlimit(10**6) rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) rlf = lambda: list(map(float, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') MOD = 10**9 + 7 def main(): K = rll()[0] D = int(rl()) lim = [] for c in K: lim.append(int(c)) n = len(lim) dp = [[[0]*D for j in range(2)] for i in range(n+1)] dp[0][1][0] = 1 for i in range(n): for tight in range(2): for ds in range(D): md = lim[i] if tight else 9 for d in range(md+1): nt = 1 if tight and lim[i] == d else 0 nds = (d + ds) % D dp[i+1][nt][nds] += dp[i][tight][ds] dp[i+1][nt][nds] %= MOD ans = (dp[n][0][0] + dp[n][1][0] - 1) % MOD print(ans) stdout.close() if __name__ == "__main__": main()
37
38
900
1,012
from sys import stdin, stdout from collections import deque, defaultdict from functools import lru_cache rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def main(): MOD = 10**9 + 7 x = [] for c in rll()[0]: x.append(int(c)) d = int(rl()) ans = 0 dp = [[0 for __ in range(2)] for _ in range(d)] dp[0][1] = 1 for i in range(len(x)): ndp = [[0 for __ in range(2)] for _ in range(d)] for digsum in range(d): for tight in range(2): for nd in range(x[i] + 1 if tight else 10): ns = (digsum + nd) % d ntight = 1 if tight and nd == x[i] else 0 ndp[ns][ntight] += dp[digsum][tight] ndp[ns][ntight] %= MOD dp = ndp ans = (dp[0][0] + dp[0][1] - 1) % MOD print(ans) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop from functools import lru_cache import math setrecursionlimit(10**6) rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) rlf = lambda: list(map(float, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") MOD = 10**9 + 7 def main(): K = rll()[0] D = int(rl()) lim = [] for c in K: lim.append(int(c)) n = len(lim) dp = [[[0] * D for j in range(2)] for i in range(n + 1)] dp[0][1][0] = 1 for i in range(n): for tight in range(2): for ds in range(D): md = lim[i] if tight else 9 for d in range(md + 1): nt = 1 if tight and lim[i] == d else 0 nds = (d + ds) % D dp[i + 1][nt][nds] += dp[i][tight][ds] dp[i + 1][nt][nds] %= MOD ans = (dp[n][0][0] + dp[n][1][0] - 1) % MOD print(ans) stdout.close() if __name__ == "__main__": main()
false
2.631579
[ "-from sys import stdin, stdout", "-from collections import deque, defaultdict", "+from sys import stdin, stdout, setrecursionlimit", "+from collections import deque, defaultdict, Counter", "+from heapq import heappush, heappop", "+import math", "+setrecursionlimit(10**6)", "+rlf = lambda: list(map(float, stdin.readline().split()))", "+MOD = 10**9 + 7", "- MOD = 10**9 + 7", "- x = []", "- for c in rll()[0]:", "- x.append(int(c))", "- d = int(rl())", "- ans = 0", "- dp = [[0 for __ in range(2)] for _ in range(d)]", "- dp[0][1] = 1", "- for i in range(len(x)):", "- ndp = [[0 for __ in range(2)] for _ in range(d)]", "- for digsum in range(d):", "- for tight in range(2):", "- for nd in range(x[i] + 1 if tight else 10):", "- ns = (digsum + nd) % d", "- ntight = 1 if tight and nd == x[i] else 0", "- ndp[ns][ntight] += dp[digsum][tight]", "- ndp[ns][ntight] %= MOD", "- dp = ndp", "- ans = (dp[0][0] + dp[0][1] - 1) % MOD", "+ K = rll()[0]", "+ D = int(rl())", "+ lim = []", "+ for c in K:", "+ lim.append(int(c))", "+ n = len(lim)", "+ dp = [[[0] * D for j in range(2)] for i in range(n + 1)]", "+ dp[0][1][0] = 1", "+ for i in range(n):", "+ for tight in range(2):", "+ for ds in range(D):", "+ md = lim[i] if tight else 9", "+ for d in range(md + 1):", "+ nt = 1 if tight and lim[i] == d else 0", "+ nds = (d + ds) % D", "+ dp[i + 1][nt][nds] += dp[i][tight][ds]", "+ dp[i + 1][nt][nds] %= MOD", "+ ans = (dp[n][0][0] + dp[n][1][0] - 1) % MOD" ]
false
0.038427
0.038296
1.003435
[ "s543575733", "s156531047" ]
u730769327
p03557
python
s601251439
s672643905
456
212
107,108
106,736
Accepted
Accepted
53.51
import bisect n=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) sm=0 for j in B: sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j)) print(sm)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) cnt=0 for i in b: cnt+=bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i)) print(cnt)
10
9
249
248
import bisect n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) sm = 0 for j in B: sm += bisect.bisect_left(A, j) * (n - bisect.bisect_right(C, j)) print(sm)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) cnt = 0 for i in b: cnt += bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i)) print(cnt)
false
10
[ "-A = sorted(list(map(int, input().split())))", "-B = sorted(list(map(int, input().split())))", "-C = sorted(list(map(int, input().split())))", "-sm = 0", "-for j in B:", "- sm += bisect.bisect_left(A, j) * (n - bisect.bisect_right(C, j))", "-print(sm)", "+a = sorted(list(map(int, input().split())))", "+b = sorted(list(map(int, input().split())))", "+c = sorted(list(map(int, input().split())))", "+cnt = 0", "+for i in b:", "+ cnt += bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i))", "+print(cnt)" ]
false
0.112454
0.274036
0.410361
[ "s601251439", "s672643905" ]
u020373088
p03294
python
s936566487
s883036123
20
18
3,316
3,316
Accepted
Accepted
10
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a)-len(a)))
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a)-n))
3
3
75
70
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a) - len(a)))
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a) - n))
false
0
[ "-print((sum(a) - len(a)))", "+print((sum(a) - n))" ]
false
0.008016
0.037889
0.211555
[ "s936566487", "s883036123" ]
u729133443
p02964
python
s031050848
s507345015
738
679
49,148
49,148
Accepted
Accepted
7.99
n,k,*a=list(map(int,open(0).read().split())) b=[[]for _ in range(max(a)+1)] l=[] for i,v in enumerate(a): b[v]+=i, l+=len(b[v]), s=a[0] i=c=0 while 1: t=b[s] m=len(t) j=l[i] c+=j==m i=t[j%m]+1 if i==n:break s=a[i] k%=c+1 s=a[0] i=c=0 r=[] while c<k-1or i<n: t=b[s] m=len(t) j=l[i] f=j==m if c>k-2and f: r+=s, i+=1 else:i=t[j%m]+1 c+=f s=a[i%n] print((*r))
n,k,*a=list(map(int,open(0).read().split())) b=[[]for _ in range(max(a)+1)] l=[] for i,v in enumerate(a): b[v]+=i, l+=len(b[v]), s=a[0] i=c=0 while 1: t=b[s] m=len(t) j=l[i] c+=j==m i=t[j%m]+1 if i==n:break s=a[i] k%=c+1 s=a[0] i=c=0 r=[] while 1: t=b[s] m=len(t) j=l[i] f=j==m if c>k-2and f: r+=s, i+=1 else:i=t[j%m]+1 c+=f if i==n:break s=a[i] print((*r))
32
33
420
425
n, k, *a = list(map(int, open(0).read().split())) b = [[] for _ in range(max(a) + 1)] l = [] for i, v in enumerate(a): b[v] += (i,) l += (len(b[v]),) s = a[0] i = c = 0 while 1: t = b[s] m = len(t) j = l[i] c += j == m i = t[j % m] + 1 if i == n: break s = a[i] k %= c + 1 s = a[0] i = c = 0 r = [] while c < k - 1 or i < n: t = b[s] m = len(t) j = l[i] f = j == m if c > k - 2 and f: r += (s,) i += 1 else: i = t[j % m] + 1 c += f s = a[i % n] print((*r))
n, k, *a = list(map(int, open(0).read().split())) b = [[] for _ in range(max(a) + 1)] l = [] for i, v in enumerate(a): b[v] += (i,) l += (len(b[v]),) s = a[0] i = c = 0 while 1: t = b[s] m = len(t) j = l[i] c += j == m i = t[j % m] + 1 if i == n: break s = a[i] k %= c + 1 s = a[0] i = c = 0 r = [] while 1: t = b[s] m = len(t) j = l[i] f = j == m if c > k - 2 and f: r += (s,) i += 1 else: i = t[j % m] + 1 c += f if i == n: break s = a[i] print((*r))
false
3.030303
[ "-while c < k - 1 or i < n:", "+while 1:", "- s = a[i % n]", "+ if i == n:", "+ break", "+ s = a[i]" ]
false
0.047736
0.008352
5.715683
[ "s031050848", "s507345015" ]
u983918956
p03986
python
s841013771
s852594578
71
62
5,096
5,096
Accepted
Accepted
12.68
X = eval(input()) stack = [] for e in X: if e == "S": stack.append(e) elif stack == []: stack.append(e) elif stack[-1] == "T": stack.append(e) elif stack[-1] == "S": stack.pop(-1) print((len(stack)))
from collections import deque X = eval(input()) dq = deque() for x in X: if not dq: dq.append(x) elif dq[-1] == "S" and x == "T": dq.pop() else: dq.append(x) ans = len(dq) print(ans)
12
16
250
235
X = eval(input()) stack = [] for e in X: if e == "S": stack.append(e) elif stack == []: stack.append(e) elif stack[-1] == "T": stack.append(e) elif stack[-1] == "S": stack.pop(-1) print((len(stack)))
from collections import deque X = eval(input()) dq = deque() for x in X: if not dq: dq.append(x) elif dq[-1] == "S" and x == "T": dq.pop() else: dq.append(x) ans = len(dq) print(ans)
false
25
[ "+from collections import deque", "+", "-stack = []", "-for e in X:", "- if e == \"S\":", "- stack.append(e)", "- elif stack == []:", "- stack.append(e)", "- elif stack[-1] == \"T\":", "- stack.append(e)", "- elif stack[-1] == \"S\":", "- stack.pop(-1)", "-print((len(stack)))", "+dq = deque()", "+for x in X:", "+ if not dq:", "+ dq.append(x)", "+ elif dq[-1] == \"S\" and x == \"T\":", "+ dq.pop()", "+ else:", "+ dq.append(x)", "+ans = len(dq)", "+print(ans)" ]
false
0.03798
0.037366
1.016418
[ "s841013771", "s852594578" ]
u667024514
p03315
python
s055328793
s574715150
142
18
3,444
2,940
Accepted
Accepted
87.32
from collections import Counter s = str(eval(input())) cou = 0 print((s.count("+") - s.count("-")))
s = list(str(eval(input()))) cou = 0 for i in range(len(s)): if s[i] == "-": cou -= 1 else: cou += 1 print(cou)
4
8
94
124
from collections import Counter s = str(eval(input())) cou = 0 print((s.count("+") - s.count("-")))
s = list(str(eval(input()))) cou = 0 for i in range(len(s)): if s[i] == "-": cou -= 1 else: cou += 1 print(cou)
false
50
[ "-from collections import Counter", "-", "-s = str(eval(input()))", "+s = list(str(eval(input())))", "-print((s.count(\"+\") - s.count(\"-\")))", "+for i in range(len(s)):", "+ if s[i] == \"-\":", "+ cou -= 1", "+ else:", "+ cou += 1", "+print(cou)" ]
false
0.037653
0.036912
1.020073
[ "s055328793", "s574715150" ]
u974100230
p03457
python
s956669894
s722261567
382
320
3,060
3,060
Accepted
Accepted
16.23
t, x, y = 0, 0, 0 for i in range(int(eval(input()))): next_t, next_x, next_y = list(map(int, input().split())) diff = abs(x - next_x) + abs(y - next_y) if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1: print("No") exit(0) t, x, y, = next_t, next_x, next_y print("Yes")
N = int(eval(input())) for __ in range(N): t, x, y = list(map(int, input().split())) if (x + y) > t or (x + y + t) % 2 == 1: print("No") exit(0) print("Yes")
9
8
304
177
t, x, y = 0, 0, 0 for i in range(int(eval(input()))): next_t, next_x, next_y = list(map(int, input().split())) diff = abs(x - next_x) + abs(y - next_y) if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1: print("No") exit(0) t, x, y, = ( next_t, next_x, next_y, ) print("Yes")
N = int(eval(input())) for __ in range(N): t, x, y = list(map(int, input().split())) if (x + y) > t or (x + y + t) % 2 == 1: print("No") exit(0) print("Yes")
false
11.111111
[ "-t, x, y = 0, 0, 0", "-for i in range(int(eval(input()))):", "- next_t, next_x, next_y = list(map(int, input().split()))", "- diff = abs(x - next_x) + abs(y - next_y)", "- if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1:", "+N = int(eval(input()))", "+for __ in range(N):", "+ t, x, y = list(map(int, input().split()))", "+ if (x + y) > t or (x + y + t) % 2 == 1:", "- t, x, y, = (", "- next_t,", "- next_x,", "- next_y,", "- )" ]
false
0.04352
0.072427
0.600882
[ "s956669894", "s722261567" ]
u557565572
p02762
python
s850756136
s482572840
1,545
1,302
47,112
46,760
Accepted
Accepted
15.73
# import bisect # # import heapq # # from copy import deepcopy from collections import deque # # from collections import Counter # # from itertools import accumulate # # from itertools import permutations # import numpy as np # # import math n, m, k = list(map(int, input().split())) # a = list(map(int, input().split())) # n = int(input()) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parents[self.find(x)] uf = UnionFind(n) friend =[[] for _ in range(n)] block = [[] for _ in range(n)] for i in range(m): a,b = list(map(int, input().split())) a,b = a-1,b-1 uf.union(a,b) friend[a].append(b); friend[b].append(a) for i in range(k): c,d = list(map(int, input().split())) c,d = c-1,d-1 if uf.same(c,d): block[c].append(d); block[d].append(c) w = [0] * n for i in range(n): w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1 print((*w))
# import bisect # import heapq # from copy import deepcopy # from collections import deque # from collections import Counter # from itertools import accumulate # from itertools import permutations # import numpy as np # import math n, m, k = list(map(int, input().split())) # a = list(map(int, input().split())) # n = int(input()) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parents[self.find(x)] uf = UnionFind(n) friend =[[] for _ in range(n)] block = [[] for _ in range(n)] for i in range(m): a,b = list(map(int, input().split())) a,b = a-1,b-1 uf.union(a,b) friend[a].append(b); friend[b].append(a) for i in range(k): c,d = list(map(int, input().split())) c,d = c-1,d-1 if uf.same(c,d): block[c].append(d); block[d].append(c) w = [0] * n for i in range(n): w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1 print((*w))
65
65
1,537
1,527
# import bisect # # import heapq # # from copy import deepcopy from collections import deque # # from collections import Counter # # from itertools import accumulate # # from itertools import permutations # import numpy as np # # import math n, m, k = list(map(int, input().split())) # a = list(map(int, input().split())) # n = int(input()) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parents[self.find(x)] uf = UnionFind(n) friend = [[] for _ in range(n)] block = [[] for _ in range(n)] for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 uf.union(a, b) friend[a].append(b) friend[b].append(a) for i in range(k): c, d = list(map(int, input().split())) c, d = c - 1, d - 1 if uf.same(c, d): block[c].append(d) block[d].append(c) w = [0] * n for i in range(n): w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1 print((*w))
# import bisect # import heapq # from copy import deepcopy # from collections import deque # from collections import Counter # from itertools import accumulate # from itertools import permutations # import numpy as np # import math n, m, k = list(map(int, input().split())) # a = list(map(int, input().split())) # n = int(input()) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parents[self.find(x)] uf = UnionFind(n) friend = [[] for _ in range(n)] block = [[] for _ in range(n)] for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 uf.union(a, b) friend[a].append(b) friend[b].append(a) for i in range(k): c, d = list(map(int, input().split())) c, d = c - 1, d - 1 if uf.same(c, d): block[c].append(d) block[d].append(c) w = [0] * n for i in range(n): w[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1 print((*w))
false
0
[ "-# # import heapq", "-# # from copy import deepcopy", "-from collections import deque", "-", "-# # from collections import Counter", "-# # from itertools import accumulate", "-# # from itertools import permutations", "+# import heapq", "+# from copy import deepcopy", "+# from collections import deque", "+# from collections import Counter", "+# from itertools import accumulate", "+# from itertools import permutations", "-# # import math", "+# import math" ]
false
0.086696
0.075637
1.146223
[ "s850756136", "s482572840" ]
u729133443
p02792
python
s668499192
s504790709
206
182
3,060
2,940
Accepted
Accepted
11.65
d=[0]*100 for i in range(int(eval(input()))): s=str(i+1) d[int(s[0])*10+int(s[-1])]+=1 print((sum(d[i]*d[i%10*10+i//10]for i in range(100))))
d=[0]*100 for i in range(int(eval(input()))):s=str(i+1);d[int(s[0]+s[-1])]+=1 print((sum(d[i]*d[i%10*10+i//10]for i in range(100))))
5
3
141
126
d = [0] * 100 for i in range(int(eval(input()))): s = str(i + 1) d[int(s[0]) * 10 + int(s[-1])] += 1 print((sum(d[i] * d[i % 10 * 10 + i // 10] for i in range(100))))
d = [0] * 100 for i in range(int(eval(input()))): s = str(i + 1) d[int(s[0] + s[-1])] += 1 print((sum(d[i] * d[i % 10 * 10 + i // 10] for i in range(100))))
false
40
[ "- d[int(s[0]) * 10 + int(s[-1])] += 1", "+ d[int(s[0] + s[-1])] += 1" ]
false
0.120032
0.152784
0.78563
[ "s668499192", "s504790709" ]
u389910364
p02659
python
s836891766
s921447175
102
25
27,212
9,236
Accepted
Accepted
75.49
import bisect import cmath import heapq import itertools import math import operator import os import random import re import string import sys from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from functools import lru_cache, reduce from math import gcd from operator import add, itemgetter, mul, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 a, b = sys.stdin.buffer.readline().decode().rstrip().split() ans = Decimal(a) * Decimal(b) print(( int(ans)))
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 a, b = sys.stdin.buffer.readline().decode().rstrip().split() a = int(a) b = round(float(b) * 100) print((a * b // 100))
32
17
682
321
import bisect import cmath import heapq import itertools import math import operator import os import random import re import string import sys from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from functools import lru_cache, reduce from math import gcd from operator import add, itemgetter, mul, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 a, b = sys.stdin.buffer.readline().decode().rstrip().split() ans = Decimal(a) * Decimal(b) print((int(ans)))
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 a, b = sys.stdin.buffer.readline().decode().rstrip().split() a = int(a) b = round(float(b) * 100) print((a * b // 100))
false
46.875
[ "-import bisect", "-import cmath", "-import heapq", "-import itertools", "-import math", "-import operator", "-import random", "-import re", "-import string", "-from collections import Counter, defaultdict, deque", "-from copy import deepcopy", "-from decimal import Decimal", "-from functools import lru_cache, reduce", "-from math import gcd", "-from operator import add, itemgetter, mul, xor", "-import numpy as np", "-ans = Decimal(a) * Decimal(b)", "-print((int(ans)))", "+a = int(a)", "+b = round(float(b) * 100)", "+print((a * b // 100))" ]
false
0.037166
0.036432
1.020162
[ "s836891766", "s921447175" ]
u109266345
p02898
python
s911939698
s249964502
53
48
11,908
11,908
Accepted
Accepted
9.43
n,k = list(map(int,input().split())) h = list(map(int,input().split())) ans = 0 for i in range(n): if h[i] >= k: ans += 1 print(ans)
n,k = list(map(int,input().split())) h = list(map(int,input().split())) print((sum(a>=k for a in h)))
7
3
144
95
n, k = list(map(int, input().split())) h = list(map(int, input().split())) ans = 0 for i in range(n): if h[i] >= k: ans += 1 print(ans)
n, k = list(map(int, input().split())) h = list(map(int, input().split())) print((sum(a >= k for a in h)))
false
57.142857
[ "-ans = 0", "-for i in range(n):", "- if h[i] >= k:", "- ans += 1", "-print(ans)", "+print((sum(a >= k for a in h)))" ]
false
0.048031
0.048198
0.996538
[ "s911939698", "s249964502" ]
u314050667
p03805
python
s368192756
s145906261
35
31
3,064
3,064
Accepted
Accepted
11.43
N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta-1].append(tb-1) E[tb-1].append(ta-1) def next_permutation(out, cnt, flg): if cnt == N: for i in range(N-1): if out[i+1] not in E[out[i]]: return 0 return 1 ans = 0 for i in range(N): if flg[i] == 0: out.append(i) flg[i] = 1 ans += next_permutation(out, cnt+1, flg) out.pop() flg[i] = 0 return ans perm = [0] cnt = 1 flg = [0 for _ in range(N)] flg[0] = 1 answer = next_permutation(perm, cnt, flg) print(answer)
import itertools N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta-1].append(tb-1) E[tb-1].append(ta-1) ans = 0 for p in itertools.permutations(list(range(1,N))): p = [0] + list(p) cond = 1 for i in range(N-1): if p[i+1] not in E[p[i]]: cond = 0 if cond: ans += 1 print(ans)
38
23
612
380
N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta - 1].append(tb - 1) E[tb - 1].append(ta - 1) def next_permutation(out, cnt, flg): if cnt == N: for i in range(N - 1): if out[i + 1] not in E[out[i]]: return 0 return 1 ans = 0 for i in range(N): if flg[i] == 0: out.append(i) flg[i] = 1 ans += next_permutation(out, cnt + 1, flg) out.pop() flg[i] = 0 return ans perm = [0] cnt = 1 flg = [0 for _ in range(N)] flg[0] = 1 answer = next_permutation(perm, cnt, flg) print(answer)
import itertools N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta - 1].append(tb - 1) E[tb - 1].append(ta - 1) ans = 0 for p in itertools.permutations(list(range(1, N))): p = [0] + list(p) cond = 1 for i in range(N - 1): if p[i + 1] not in E[p[i]]: cond = 0 if cond: ans += 1 print(ans)
false
39.473684
[ "+import itertools", "+", "-", "-", "-def next_permutation(out, cnt, flg):", "- if cnt == N:", "- for i in range(N - 1):", "- if out[i + 1] not in E[out[i]]:", "- return 0", "- return 1", "- ans = 0", "- for i in range(N):", "- if flg[i] == 0:", "- out.append(i)", "- flg[i] = 1", "- ans += next_permutation(out, cnt + 1, flg)", "- out.pop()", "- flg[i] = 0", "- return ans", "-", "-", "-perm = [0]", "-cnt = 1", "-flg = [0 for _ in range(N)]", "-flg[0] = 1", "-answer = next_permutation(perm, cnt, flg)", "-print(answer)", "+ans = 0", "+for p in itertools.permutations(list(range(1, N))):", "+ p = [0] + list(p)", "+ cond = 1", "+ for i in range(N - 1):", "+ if p[i + 1] not in E[p[i]]:", "+ cond = 0", "+ if cond:", "+ ans += 1", "+print(ans)" ]
false
0.043961
0.050415
0.871976
[ "s368192756", "s145906261" ]
u119148115
p02647
python
s244713902
s175965299
697
389
185,184
208,868
Accepted
Accepted
44.19
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() from itertools import accumulate for _ in range(min(K,100)): B = [0]*(N+1) for i in range(N): a = A[i] B[max(i-a,0)] += 1 B[min(N,i+a+1)] -= 1 C = list(accumulate(B)) A = C print((*[A[i] for i in range(N)]))
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() from itertools import accumulate for _ in range(min(K,41)): B = [0]*(N+1) for i in range(N): a = A[i] B[max(i-a,0)] += 1 B[min(N,i+a+1)] -= 1 C = list(accumulate(B)) A = C print((*[A[i] for i in range(N)]))
20
20
442
441
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = LI() from itertools import accumulate for _ in range(min(K, 100)): B = [0] * (N + 1) for i in range(N): a = A[i] B[max(i - a, 0)] += 1 B[min(N, i + a + 1)] -= 1 C = list(accumulate(B)) A = C print((*[A[i] for i in range(N)]))
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = LI() from itertools import accumulate for _ in range(min(K, 41)): B = [0] * (N + 1) for i in range(N): a = A[i] B[max(i - a, 0)] += 1 B[min(N, i + a + 1)] -= 1 C = list(accumulate(B)) A = C print((*[A[i] for i in range(N)]))
false
0
[ "-for _ in range(min(K, 100)):", "+for _ in range(min(K, 41)):" ]
false
0.041196
0.042637
0.966202
[ "s244713902", "s175965299" ]
u347640436
p03295
python
s901028856
s168450785
310
233
23,368
28,712
Accepted
Accepted
24.84
N, M = list(map(int, input().split())) ab = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) ab[a].append(b) dp = [0] * (N + 1) for i in range(1, N + 1): dp[i] = max(dp[i], dp[i - 1]) for j in ab[i]: dp[j] = max(dp[j], dp[i] + 1) print((dp[N]))
from sys import stdin readline = stdin.readline N, M = list(map(int, readline().split())) ab = [list(map(int, readline().split())) for _ in range(M)] ab.sort(key=lambda x: x[1]) result = 0 t = -1 for a, b in ab: a, b = a - 1, b - 1 if a <= t < b: continue result += 1 t = b - 1 print(result)
14
17
307
329
N, M = list(map(int, input().split())) ab = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) ab[a].append(b) dp = [0] * (N + 1) for i in range(1, N + 1): dp[i] = max(dp[i], dp[i - 1]) for j in ab[i]: dp[j] = max(dp[j], dp[i] + 1) print((dp[N]))
from sys import stdin readline = stdin.readline N, M = list(map(int, readline().split())) ab = [list(map(int, readline().split())) for _ in range(M)] ab.sort(key=lambda x: x[1]) result = 0 t = -1 for a, b in ab: a, b = a - 1, b - 1 if a <= t < b: continue result += 1 t = b - 1 print(result)
false
17.647059
[ "-N, M = list(map(int, input().split()))", "-ab = [[] for _ in range(N + 1)]", "-for _ in range(M):", "- a, b = list(map(int, input().split()))", "- ab[a].append(b)", "-dp = [0] * (N + 1)", "-for i in range(1, N + 1):", "- dp[i] = max(dp[i], dp[i - 1])", "- for j in ab[i]:", "- dp[j] = max(dp[j], dp[i] + 1)", "-print((dp[N]))", "+from sys import stdin", "+", "+readline = stdin.readline", "+N, M = list(map(int, readline().split()))", "+ab = [list(map(int, readline().split())) for _ in range(M)]", "+ab.sort(key=lambda x: x[1])", "+result = 0", "+t = -1", "+for a, b in ab:", "+ a, b = a - 1, b - 1", "+ if a <= t < b:", "+ continue", "+ result += 1", "+ t = b - 1", "+print(result)" ]
false
0.119762
0.034539
3.467499
[ "s901028856", "s168450785" ]
u671446913
p02843
python
s116880413
s475386301
330
22
21,276
3,316
Accepted
Accepted
93.33
import collections import itertools as it import math import numpy as np # A = input() # A = int(input()) # A = map(int, input().split()) # A = list(map(int, input().split())) # A = [int(input()) for i in range(N)] # # c = collections.Counter() X = int(eval(input())) nshohin = X // 100 amari = X % 100 print((0 if nshohin * 5 < amari else 1))
#!/usr/bin/env python3 import collections import itertools as it import math #import numpy as np # = input() x = int(eval(input())) # = map(int, input().split()) # = list(map(int, input().split())) # = [int(input()) for i in range(N)] # # c = collections.Counter() n = x // 100 mod = x % 100 print((0 if 5 * n < mod else 1))
18
18
355
343
import collections import itertools as it import math import numpy as np # A = input() # A = int(input()) # A = map(int, input().split()) # A = list(map(int, input().split())) # A = [int(input()) for i in range(N)] # # c = collections.Counter() X = int(eval(input())) nshohin = X // 100 amari = X % 100 print((0 if nshohin * 5 < amari else 1))
#!/usr/bin/env python3 import collections import itertools as it import math # import numpy as np # = input() x = int(eval(input())) # = map(int, input().split()) # = list(map(int, input().split())) # = [int(input()) for i in range(N)] # # c = collections.Counter() n = x // 100 mod = x % 100 print((0 if 5 * n < mod else 1))
false
0
[ "+#!/usr/bin/env python3", "-import numpy as np", "-# A = input()", "-# A = int(input())", "-# A = map(int, input().split())", "-# A = list(map(int, input().split()))", "-# A = [int(input()) for i in range(N)]", "+# import numpy as np", "+# = input()", "+x = int(eval(input()))", "+# = map(int, input().split())", "+# = list(map(int, input().split()))", "+# = [int(input()) for i in range(N)]", "-X = int(eval(input()))", "-nshohin = X // 100", "-amari = X % 100", "-print((0 if nshohin * 5 < amari else 1))", "+n = x // 100", "+mod = x % 100", "+print((0 if 5 * n < mod else 1))" ]
false
0.040254
0.035303
1.140232
[ "s116880413", "s475386301" ]
u991567869
p03624
python
s454541533
s395807570
21
19
3,188
3,188
Accepted
Accepted
9.52
s = sorted(list(set(eval(input())))) a = "abcdefghijklmnopqrstuvwxyz" if "".join(s) == a: print("None") exit() else: for i in s: a = a.replace(i, "") print((a[0]))
a = [chr(ord("a") + i) for i in range(26)] s = sorted(list(set(eval(input())))) for i in a: if i not in s: print(i) exit() print("None")
11
9
187
160
s = sorted(list(set(eval(input())))) a = "abcdefghijklmnopqrstuvwxyz" if "".join(s) == a: print("None") exit() else: for i in s: a = a.replace(i, "") print((a[0]))
a = [chr(ord("a") + i) for i in range(26)] s = sorted(list(set(eval(input())))) for i in a: if i not in s: print(i) exit() print("None")
false
18.181818
[ "+a = [chr(ord(\"a\") + i) for i in range(26)]", "-a = \"abcdefghijklmnopqrstuvwxyz\"", "-if \"\".join(s) == a:", "- print(\"None\")", "- exit()", "-else:", "- for i in s:", "- a = a.replace(i, \"\")", "-print((a[0]))", "+for i in a:", "+ if i not in s:", "+ print(i)", "+ exit()", "+print(\"None\")" ]
false
0.039663
0.042045
0.943352
[ "s454541533", "s395807570" ]
u998769995
p03162
python
s335847041
s214285829
290
134
91,552
85,992
Accepted
Accepted
53.79
import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: list(map(int,input().split())) alele = lambda: list(map(int, input().split())) 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)] MOD = 1000000000 + 7 def Y(c): print((["NO","YES"][c])) def y(c): print((["no","yes"][c])) def Yy(c): print((["No","Yes"][c])) x,y,z = 0,0,0 for _ in range(int(eval(input()))): a,b,c = ilele() if x == y == z == 0: x,y,z = a,b,c else: d = a + max(y,z) e = b + max(x,z) f = c + max(x,y) x,y,z = d,e,f print((max(x,y,z)))
import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: list(map(int,input().split())) alele = lambda: list(map(int, input().split())) 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)] MOD = 1000000000 + 7 def Y(c): print((["NO","YES"][c])) def y(c): print((["no","yes"][c])) def Yy(c): print((["No","Yes"][c])) x,y,z = 0,0,0 for _ in range(int(eval(input()))): a,b,c = ilele() d = a + max(y,z) e = b + max(x,z) f = c + max(x,y) x,y,z = d,e,f print((max(x,y,z)))
26
23
838
762
import math, sys, bisect, heapq from collections import defaultdict, Counter, deque from itertools import groupby, accumulate # sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: list(map(int, input().split())) alele = lambda: list(map(int, input().split())) 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)] MOD = 1000000000 + 7 def Y(c): print((["NO", "YES"][c])) def y(c): print((["no", "yes"][c])) def Yy(c): print((["No", "Yes"][c])) x, y, z = 0, 0, 0 for _ in range(int(eval(input()))): a, b, c = ilele() if x == y == z == 0: x, y, z = a, b, c else: d = a + max(y, z) e = b + max(x, z) f = c + max(x, y) x, y, z = d, e, f print((max(x, y, z)))
import math, sys, bisect, heapq from collections import defaultdict, Counter, deque from itertools import groupby, accumulate # sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: list(map(int, input().split())) alele = lambda: list(map(int, input().split())) 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)] MOD = 1000000000 + 7 def Y(c): print((["NO", "YES"][c])) def y(c): print((["no", "yes"][c])) def Yy(c): print((["No", "Yes"][c])) x, y, z = 0, 0, 0 for _ in range(int(eval(input()))): a, b, c = ilele() d = a + max(y, z) e = b + max(x, z) f = c + max(x, y) x, y, z = d, e, f print((max(x, y, z)))
false
11.538462
[ "- if x == y == z == 0:", "- x, y, z = a, b, c", "- else:", "- d = a + max(y, z)", "- e = b + max(x, z)", "- f = c + max(x, y)", "- x, y, z = d, e, f", "+ d = a + max(y, z)", "+ e = b + max(x, z)", "+ f = c + max(x, y)", "+ x, y, z = d, e, f" ]
false
0.047733
0.04468
1.068333
[ "s335847041", "s214285829" ]
u503227287
p02713
python
s767678975
s938746183
547
75
81,360
67,632
Accepted
Accepted
86.29
import sys import fractions def in_ctrl(): _input = [_.rstrip() for _ in sys.stdin.readlines()] # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv K = int(_input[0]) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ return K def out_ctrl(s): print(s) if __name__ == "__main__": K = in_ctrl() # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cnt = 0 dict_ = {} for a in range(1,K+1): cnt += a for b in range(a+1,K+1): if '{}_{}'.format(a,b) in dict_: ans = dict_['{}_{}'.format(a,b)] else: ans = fractions.gcd(a,b) dict_['{}_{}'.format(a,b)] = ans cnt += 6*ans for c in range(b+1,K+1): if '{}_{}'.format(ans,c) in dict_: _ans = dict_['{}_{}'.format(ans,c)] else: _ans = fractions.gcd(ans, c) dict_['{}_{}'.format(ans,c)] = _ans cnt += 6*_ans # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out_ctrl(cnt)
from sys import stdin from math import gcd if __name__ == "__main__": _in = [_.rstrip() for _ in stdin.readlines()] K = int(_in[0]) # type:int # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cnt = 0 for a in range(1,K+1): cnt += a for b in range(a+1,K+1): ab = gcd(a,b) cnt += 6*ab for c in range(b+1,K+1): cnt += 6*gcd(ab, c) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print(cnt)
38
19
1,134
519
import sys import fractions def in_ctrl(): _input = [_.rstrip() for _ in sys.stdin.readlines()] # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv K = int(_input[0]) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ return K def out_ctrl(s): print(s) if __name__ == "__main__": K = in_ctrl() # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cnt = 0 dict_ = {} for a in range(1, K + 1): cnt += a for b in range(a + 1, K + 1): if "{}_{}".format(a, b) in dict_: ans = dict_["{}_{}".format(a, b)] else: ans = fractions.gcd(a, b) dict_["{}_{}".format(a, b)] = ans cnt += 6 * ans for c in range(b + 1, K + 1): if "{}_{}".format(ans, c) in dict_: _ans = dict_["{}_{}".format(ans, c)] else: _ans = fractions.gcd(ans, c) dict_["{}_{}".format(ans, c)] = _ans cnt += 6 * _ans # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out_ctrl(cnt)
from sys import stdin from math import gcd if __name__ == "__main__": _in = [_.rstrip() for _ in stdin.readlines()] K = int(_in[0]) # type:int # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cnt = 0 for a in range(1, K + 1): cnt += a for b in range(a + 1, K + 1): ab = gcd(a, b) cnt += 6 * ab for c in range(b + 1, K + 1): cnt += 6 * gcd(ab, c) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print(cnt)
false
50
[ "-import sys", "-import fractions", "-", "-", "-def in_ctrl():", "- _input = [_.rstrip() for _ in sys.stdin.readlines()]", "- # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv", "- K = int(_input[0])", "- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", "- return K", "-", "-", "-def out_ctrl(s):", "- print(s)", "-", "+from sys import stdin", "+from math import gcd", "- K = in_ctrl()", "+ _in = [_.rstrip() for _ in stdin.readlines()]", "+ K = int(_in[0]) # type:int", "- dict_ = {}", "- if \"{}_{}\".format(a, b) in dict_:", "- ans = dict_[\"{}_{}\".format(a, b)]", "- else:", "- ans = fractions.gcd(a, b)", "- dict_[\"{}_{}\".format(a, b)] = ans", "- cnt += 6 * ans", "+ ab = gcd(a, b)", "+ cnt += 6 * ab", "- if \"{}_{}\".format(ans, c) in dict_:", "- _ans = dict_[\"{}_{}\".format(ans, c)]", "- else:", "- _ans = fractions.gcd(ans, c)", "- dict_[\"{}_{}\".format(ans, c)] = _ans", "- cnt += 6 * _ans", "+ cnt += 6 * gcd(ab, c)", "- out_ctrl(cnt)", "+ print(cnt)" ]
false
0.103652
0.047859
2.16577
[ "s767678975", "s938746183" ]
u227020436
p03290
python
s707155125
s618842708
21
19
3,064
3,064
Accepted
Accepted
9.52
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from math import ceil D, G = [int(t) for t in input().split()] p = [] c = [] for i in range(D): p_, c_ = [int(t) for t in input().split()] p.append(p_) c.append(c_) def minsolve(G, p, c, i): """100i点以下の問題だけでGを達成する最小問題数""" if i <= 0: return float('inf') n = min(ceil(G / (100 * i)), p[i-1]) s = 100 * i * n if n == p[i-1]: s += c[i-1] if s >= G: return min(n, minsolve(G, p, c, i-1)) else: return min(n + minsolve(G - s, p, c, i-1), minsolve(G, p, c, i-1)) m = min(minsolve(G, p, c, i) for i in range(1, D+1)) print(m)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from math import ceil D, G = [int(t) for t in input().split()] p = [] c = [] for i in range(D): p_, c_ = [int(t) for t in input().split()] p.append(p_) c.append(c_) cache = {} def minsolve(G, i): """100i点以下の問題だけでGを達成する最小問題数""" if i <= 0: return float('inf') n = min(ceil(G / (100 * i)), p[i-1]) s = 100 * i * n if n == p[i-1]: s += c[i-1] m = n if s >= G else n + minsolve(G - s, i-1) return min(m, minsolve(G, i-1)) print((minsolve(G, D)))
28
27
671
572
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from math import ceil D, G = [int(t) for t in input().split()] p = [] c = [] for i in range(D): p_, c_ = [int(t) for t in input().split()] p.append(p_) c.append(c_) def minsolve(G, p, c, i): """100i点以下の問題だけでGを達成する最小問題数""" if i <= 0: return float("inf") n = min(ceil(G / (100 * i)), p[i - 1]) s = 100 * i * n if n == p[i - 1]: s += c[i - 1] if s >= G: return min(n, minsolve(G, p, c, i - 1)) else: return min(n + minsolve(G - s, p, c, i - 1), minsolve(G, p, c, i - 1)) m = min(minsolve(G, p, c, i) for i in range(1, D + 1)) print(m)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from math import ceil D, G = [int(t) for t in input().split()] p = [] c = [] for i in range(D): p_, c_ = [int(t) for t in input().split()] p.append(p_) c.append(c_) cache = {} def minsolve(G, i): """100i点以下の問題だけでGを達成する最小問題数""" if i <= 0: return float("inf") n = min(ceil(G / (100 * i)), p[i - 1]) s = 100 * i * n if n == p[i - 1]: s += c[i - 1] m = n if s >= G else n + minsolve(G - s, i - 1) return min(m, minsolve(G, i - 1)) print((minsolve(G, D)))
false
3.571429
[ "+cache = {}", "-def minsolve(G, p, c, i):", "+def minsolve(G, i):", "- if s >= G:", "- return min(n, minsolve(G, p, c, i - 1))", "- else:", "- return min(n + minsolve(G - s, p, c, i - 1), minsolve(G, p, c, i - 1))", "+ m = n if s >= G else n + minsolve(G - s, i - 1)", "+ return min(m, minsolve(G, i - 1))", "-m = min(minsolve(G, p, c, i) for i in range(1, D + 1))", "-print(m)", "+print((minsolve(G, D)))" ]
false
0.049333
0.04049
1.218397
[ "s707155125", "s618842708" ]
u367130284
p03425
python
s708922090
s969276548
57
41
17,692
10,992
Accepted
Accepted
28.07
from itertools import*;print((sum(p*q*r for p,q,r in combinations(list(map(list(zip(*open(0).readlines()))[0].count,'MARCH')),3))))
from itertools import* n,*a=open(0).read().split() print((sum(p*q*r for p,q,r in combinations(list(map([i[0]for i in a].count,"MARCH")),3))))
1
3
123
135
from itertools import * print( ( sum( p * q * r for p, q, r in combinations( list(map(list(zip(*open(0).readlines()))[0].count, "MARCH")), 3 ) ) ) )
from itertools import * n, *a = open(0).read().split() print( ( sum( p * q * r for p, q, r in combinations(list(map([i[0] for i in a].count, "MARCH")), 3) ) ) )
false
66.666667
[ "+n, *a = open(0).read().split()", "- for p, q, r in combinations(", "- list(map(list(zip(*open(0).readlines()))[0].count, \"MARCH\")), 3", "- )", "+ for p, q, r in combinations(list(map([i[0] for i in a].count, \"MARCH\")), 3)" ]
false
0.045388
0.038067
1.192322
[ "s708922090", "s969276548" ]
u202570162
p03001
python
s603169762
s821112219
20
17
3,316
2,940
Accepted
Accepted
15
W,H,x,y=list(map(int,input().split())) ans = 1 if (W/2,H/2) == (x,y) else 0 print((H*W/2,ans))
W,H,x,y=list(map(int,input().split())) print((H*W/2,1 if (W/2,H/2) == (x,y) else 0))
3
2
88
77
W, H, x, y = list(map(int, input().split())) ans = 1 if (W / 2, H / 2) == (x, y) else 0 print((H * W / 2, ans))
W, H, x, y = list(map(int, input().split())) print((H * W / 2, 1 if (W / 2, H / 2) == (x, y) else 0))
false
33.333333
[ "-ans = 1 if (W / 2, H / 2) == (x, y) else 0", "-print((H * W / 2, ans))", "+print((H * W / 2, 1 if (W / 2, H / 2) == (x, y) else 0))" ]
false
0.04855
0.047968
1.012126
[ "s603169762", "s821112219" ]
u057109575
p03128
python
s738213742
s929603000
836
118
138,380
96,380
Accepted
Accepted
85.89
N, M, *A = map(int, open(0).read().split()) match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} dp = [[0] * M for _ in range(N + 1)] for i in range(N + 1): for j in range(M): for k in range(M): if (i - match[A[k]] == 0) or \ (i - match[A[k]] > 0 and dp[i - match[A[k]]][j] != 0): dp[i][k] = max(dp[i][k], dp[i - match[A[k]]][j] * 10 + A[k]) print(max(dp[-1]))
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort(reverse=True) count = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [-1] * (N + 1) dp[0] = 0 for a in X: n = count[a] for i in range(N - n + 1): if dp[i] == -1: continue dp[i + n] = max(dp[i + n], dp[i] * 10 + a) print((dp[-1]))
15
17
480
349
N, M, *A = map(int, open(0).read().split()) match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} dp = [[0] * M for _ in range(N + 1)] for i in range(N + 1): for j in range(M): for k in range(M): if (i - match[A[k]] == 0) or ( i - match[A[k]] > 0 and dp[i - match[A[k]]][j] != 0 ): dp[i][k] = max(dp[i][k], dp[i - match[A[k]]][j] * 10 + A[k]) print(max(dp[-1]))
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort(reverse=True) count = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [-1] * (N + 1) dp[0] = 0 for a in X: n = count[a] for i in range(N - n + 1): if dp[i] == -1: continue dp[i + n] = max(dp[i + n], dp[i] * 10 + a) print((dp[-1]))
false
11.764706
[ "-N, M, *A = map(int, open(0).read().split())", "-match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}", "-dp = [[0] * M for _ in range(N + 1)]", "-for i in range(N + 1):", "- for j in range(M):", "- for k in range(M):", "- if (i - match[A[k]] == 0) or (", "- i - match[A[k]] > 0 and dp[i - match[A[k]]][j] != 0", "- ):", "- dp[i][k] = max(dp[i][k], dp[i - match[A[k]]][j] * 10 + A[k])", "-print(max(dp[-1]))", "+N, M = list(map(int, input().split()))", "+X = list(map(int, input().split()))", "+X.sort(reverse=True)", "+count = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "+dp = [-1] * (N + 1)", "+dp[0] = 0", "+for a in X:", "+ n = count[a]", "+ for i in range(N - n + 1):", "+ if dp[i] == -1:", "+ continue", "+ dp[i + n] = max(dp[i + n], dp[i] * 10 + a)", "+print((dp[-1]))" ]
false
0.072321
0.04491
1.610367
[ "s738213742", "s929603000" ]
u724687935
p03565
python
s493151571
s611424922
20
17
3,188
3,064
Accepted
Accepted
15
import re S_ = eval(input()) T = eval(input()) S_ = S_[::-1] T = T[::-1] t = '' for c in T: t += '[?' + c + ']' regex = re.compile(t) S, cnt = regex.subn(T, S_, count=1) if cnt: S = S.replace('?', 'a') print((S[::-1])) else: print('UNRESTORABLE')
Sx = eval(input()) T = eval(input()) offset = len(Sx) - len(T) ans = 'UNRESTORABLE' if len(Sx) >= len(T): for d in range(offset, -1, -1): for j in range(len(T)): if Sx[d + j] not in ['?', T[j]]: break else: break else: print('UNRESTORABLE') exit() ans = '' for i in range(len(Sx)): if i < d or d + (len(T) - 1) < i: c = Sx[i] else: c = T[i - d] c = 'a' if c == '?' else c ans += c print(ans)
20
28
273
556
import re S_ = eval(input()) T = eval(input()) S_ = S_[::-1] T = T[::-1] t = "" for c in T: t += "[?" + c + "]" regex = re.compile(t) S, cnt = regex.subn(T, S_, count=1) if cnt: S = S.replace("?", "a") print((S[::-1])) else: print("UNRESTORABLE")
Sx = eval(input()) T = eval(input()) offset = len(Sx) - len(T) ans = "UNRESTORABLE" if len(Sx) >= len(T): for d in range(offset, -1, -1): for j in range(len(T)): if Sx[d + j] not in ["?", T[j]]: break else: break else: print("UNRESTORABLE") exit() ans = "" for i in range(len(Sx)): if i < d or d + (len(T) - 1) < i: c = Sx[i] else: c = T[i - d] c = "a" if c == "?" else c ans += c print(ans)
false
28.571429
[ "-import re", "-", "-S_ = eval(input())", "+Sx = eval(input())", "-S_ = S_[::-1]", "-T = T[::-1]", "-t = \"\"", "-for c in T:", "- t += \"[?\" + c + \"]\"", "-regex = re.compile(t)", "-S, cnt = regex.subn(T, S_, count=1)", "-if cnt:", "- S = S.replace(\"?\", \"a\")", "- print((S[::-1]))", "-else:", "- print(\"UNRESTORABLE\")", "+offset = len(Sx) - len(T)", "+ans = \"UNRESTORABLE\"", "+if len(Sx) >= len(T):", "+ for d in range(offset, -1, -1):", "+ for j in range(len(T)):", "+ if Sx[d + j] not in [\"?\", T[j]]:", "+ break", "+ else:", "+ break", "+ else:", "+ print(\"UNRESTORABLE\")", "+ exit()", "+ ans = \"\"", "+ for i in range(len(Sx)):", "+ if i < d or d + (len(T) - 1) < i:", "+ c = Sx[i]", "+ else:", "+ c = T[i - d]", "+ c = \"a\" if c == \"?\" else c", "+ ans += c", "+print(ans)" ]
false
0.045175
0.159944
0.282445
[ "s493151571", "s611424922" ]
u150984829
p02243
python
s122440408
s106372810
710
530
69,152
68,780
Accepted
Accepted
25.35
import sys from heapq import* e=sys.stdin.readline n=int(e()) A=[[]for _ in[0]*n] for _ in[0]*n: b=list(map(int,e().split())) for i in range(b[1]):k=2*-~i;A[b[0]]+=[(b[k],b[k+1])] H=[[0,0]] d=[0]+[1e6]*n c=[1]*n while H: f=heappop(H) u=f[1] c[u]=0 if d[u]>=f[0]: for s in A[u]: v=s[0] if c[v]and d[v]>d[u]+s[1]: d[v]=d[u]+s[1] heappush(H,[d[v],v]) for i in range(n):print((i,d[i]))
from heapq import* def m(): n=int(eval(input())) A=[[]for _ in[0]*n] for _ in[0]*n: e=list(map(int,input().split())) for i in range(e[1]):k=2*-~i;A[e[0]]+=[(e[k],e[k+1])] H=[[0,0]] d=[0]+[1e6]*n c=[1]*n while H: f=heappop(H) u=f[1] c[u]=0 if d[u]>=f[0]: for s in A[u]: v=s[0] if c[v]and d[v]>d[u]+s[1]: d[v]=d[u]+s[1] heappush(H,[d[v],v]) for i in range(n):print((i,d[i])) m()
22
22
423
431
import sys from heapq import * e = sys.stdin.readline n = int(e()) A = [[] for _ in [0] * n] for _ in [0] * n: b = list(map(int, e().split())) for i in range(b[1]): k = 2 * -~i A[b[0]] += [(b[k], b[k + 1])] H = [[0, 0]] d = [0] + [1e6] * n c = [1] * n while H: f = heappop(H) u = f[1] c[u] = 0 if d[u] >= f[0]: for s in A[u]: v = s[0] if c[v] and d[v] > d[u] + s[1]: d[v] = d[u] + s[1] heappush(H, [d[v], v]) for i in range(n): print((i, d[i]))
from heapq import * def m(): n = int(eval(input())) A = [[] for _ in [0] * n] for _ in [0] * n: e = list(map(int, input().split())) for i in range(e[1]): k = 2 * -~i A[e[0]] += [(e[k], e[k + 1])] H = [[0, 0]] d = [0] + [1e6] * n c = [1] * n while H: f = heappop(H) u = f[1] c[u] = 0 if d[u] >= f[0]: for s in A[u]: v = s[0] if c[v] and d[v] > d[u] + s[1]: d[v] = d[u] + s[1] heappush(H, [d[v], v]) for i in range(n): print((i, d[i])) m()
false
0
[ "-import sys", "-e = sys.stdin.readline", "-n = int(e())", "-A = [[] for _ in [0] * n]", "-for _ in [0] * n:", "- b = list(map(int, e().split()))", "- for i in range(b[1]):", "- k = 2 * -~i", "- A[b[0]] += [(b[k], b[k + 1])]", "-H = [[0, 0]]", "-d = [0] + [1e6] * n", "-c = [1] * n", "-while H:", "- f = heappop(H)", "- u = f[1]", "- c[u] = 0", "- if d[u] >= f[0]:", "- for s in A[u]:", "- v = s[0]", "- if c[v] and d[v] > d[u] + s[1]:", "- d[v] = d[u] + s[1]", "- heappush(H, [d[v], v])", "-for i in range(n):", "- print((i, d[i]))", "+", "+def m():", "+ n = int(eval(input()))", "+ A = [[] for _ in [0] * n]", "+ for _ in [0] * n:", "+ e = list(map(int, input().split()))", "+ for i in range(e[1]):", "+ k = 2 * -~i", "+ A[e[0]] += [(e[k], e[k + 1])]", "+ H = [[0, 0]]", "+ d = [0] + [1e6] * n", "+ c = [1] * n", "+ while H:", "+ f = heappop(H)", "+ u = f[1]", "+ c[u] = 0", "+ if d[u] >= f[0]:", "+ for s in A[u]:", "+ v = s[0]", "+ if c[v] and d[v] > d[u] + s[1]:", "+ d[v] = d[u] + s[1]", "+ heappush(H, [d[v], v])", "+ for i in range(n):", "+ print((i, d[i]))", "+", "+", "+m()" ]
false
0.046722
0.043723
1.068604
[ "s122440408", "s106372810" ]