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
u106971015
p02768
python
s479452625
s028664288
832
141
11,052
3,064
Accepted
Accepted
83.05
n,a,b = list(map(int,input().split())) mod = 10 ** 9 + 7 k = max(a,b) com = [1] for i in range(1,k+1): com.append((com[i-1]*(n-i+1)*pow(i,mod-2,mod))%mod) print(((pow(2,n,mod)-1-com[a]-com[b])%mod))
n,a,b = list(map(int,input().split())) mod = 10 ** 9 + 7 def nCr(n,r): if r*2>n: return nCr(n,n-r) else: a = b = 1 for i in range(r): a = a * (n - i) % mod b = b * (r - i) % mod return (a * pow(b,mod-2,mod)) % mod ans = pow(2,n,mod) - 1 - nCr(n,a) - nCr(n,b) print((ans%mod))
10
15
206
347
n, a, b = list(map(int, input().split())) mod = 10**9 + 7 k = max(a, b) com = [1] for i in range(1, k + 1): com.append((com[i - 1] * (n - i + 1) * pow(i, mod - 2, mod)) % mod) print(((pow(2, n, mod) - 1 - com[a] - com[b]) % mod))
n, a, b = list(map(int, input().split())) mod = 10**9 + 7 def nCr(n, r): if r * 2 > n: return nCr(n, n - r) else: a = b = 1 for i in range(r): a = a * (n - i) % mod b = b * (r - i) % mod return (a * pow(b, mod - 2, mod)) % mod ans = pow(2, n, mod) - 1 - nCr(n, a) - nCr(n, b) print((ans % mod))
false
33.333333
[ "-k = max(a, b)", "-com = [1]", "-for i in range(1, k + 1):", "- com.append((com[i - 1] * (n - i + 1) * pow(i, mod - 2, mod)) % mod)", "-print(((pow(2, n, mod) - 1 - com[a] - com[b]) % mod))", "+", "+", "+def nCr(n, r):", "+ if r * 2 > n:", "+ return nCr(n, n - r)", "+ else:", "+ a = b = 1", "+ for i in range(r):", "+ a = a * (n - i) % mod", "+ b = b * (r - i) % mod", "+ return (a * pow(b, mod - 2, mod)) % mod", "+", "+", "+ans = pow(2, n, mod) - 1 - nCr(n, a) - nCr(n, b)", "+print((ans % mod))" ]
false
1.021985
0.192626
5.305536
[ "s479452625", "s028664288" ]
u681444474
p03958
python
s016395646
s008082257
88
28
68,768
8,992
Accepted
Accepted
68.18
# coding: utf-8 import math from collections import deque import copy import bisect k, n = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() m=max(A) s=k-m print((max(m-1-s, 0)))
# coding: utf-8 k, t = list(map(int,input().split())) A=list(map(int,input().split())) m=max(A) s=k-m print((max(m-1-s, 0)))
11
6
205
121
# coding: utf-8 import math from collections import deque import copy import bisect k, n = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() m = max(A) s = k - m print((max(m - 1 - s, 0)))
# coding: utf-8 k, t = list(map(int, input().split())) A = list(map(int, input().split())) m = max(A) s = k - m print((max(m - 1 - s, 0)))
false
45.454545
[ "-import math", "-from collections import deque", "-import copy", "-import bisect", "-", "-k, n = list(map(int, input().split()))", "+k, t = list(map(int, input().split()))", "-A.sort()" ]
false
0.044761
0.038053
1.176261
[ "s016395646", "s008082257" ]
u466143662
p03049
python
s605800717
s799329305
53
39
3,064
3,064
Accepted
Accepted
26.42
N=int(eval(input())) lasta=0 headb=0 spec=0 cnt=0 for _ in range(N): s=str(eval(input())) for i in range(len(s)-1): if s[i:i+2]=="AB": cnt+=1 if s[0]=="B" and s[-1]=="A": spec+=1 elif s[-1]=="A": lasta+=1 elif s[0]=="B": headb+=1 if abs(headb-lasta)>=spec: print((min(headb,lasta)+spec+cnt)) elif lasta==0 and headb==0 and spec>0: print((spec-1+cnt)) elif lasta==0 and headb==0 and spec==0: print(cnt) else: print((spec-abs(headb-lasta)+max(headb,lasta)+cnt))
N=int(eval(input())) lasta=0 headb=0 spec=0 cnt=0 for _ in range(N): s=str(eval(input())) cnt+=s.count("AB") if s[0]=="B" and s[-1]=="A": spec+=1 elif s[-1]=="A": lasta+=1 elif s[0]=="B": headb+=1 if abs(headb-lasta)>=spec: print((min(headb,lasta)+spec+cnt)) elif lasta==0 and headb==0 and spec>0: print((spec-1+cnt)) elif lasta==0 and headb==0 and spec==0: print(cnt) else: print((spec-abs(headb-lasta)+max(headb,lasta)+cnt))
25
23
557
502
N = int(eval(input())) lasta = 0 headb = 0 spec = 0 cnt = 0 for _ in range(N): s = str(eval(input())) for i in range(len(s) - 1): if s[i : i + 2] == "AB": cnt += 1 if s[0] == "B" and s[-1] == "A": spec += 1 elif s[-1] == "A": lasta += 1 elif s[0] == "B": headb += 1 if abs(headb - lasta) >= spec: print((min(headb, lasta) + spec + cnt)) elif lasta == 0 and headb == 0 and spec > 0: print((spec - 1 + cnt)) elif lasta == 0 and headb == 0 and spec == 0: print(cnt) else: print((spec - abs(headb - lasta) + max(headb, lasta) + cnt))
N = int(eval(input())) lasta = 0 headb = 0 spec = 0 cnt = 0 for _ in range(N): s = str(eval(input())) cnt += s.count("AB") if s[0] == "B" and s[-1] == "A": spec += 1 elif s[-1] == "A": lasta += 1 elif s[0] == "B": headb += 1 if abs(headb - lasta) >= spec: print((min(headb, lasta) + spec + cnt)) elif lasta == 0 and headb == 0 and spec > 0: print((spec - 1 + cnt)) elif lasta == 0 and headb == 0 and spec == 0: print(cnt) else: print((spec - abs(headb - lasta) + max(headb, lasta) + cnt))
false
8
[ "- for i in range(len(s) - 1):", "- if s[i : i + 2] == \"AB\":", "- cnt += 1", "+ cnt += s.count(\"AB\")" ]
false
0.036731
0.075319
0.487665
[ "s605800717", "s799329305" ]
u977389981
p03036
python
s587124997
s686233758
170
18
38,384
2,940
Accepted
Accepted
89.41
r, d, x = list(map(int, input().split())) tmp = x for i in range(10): ans = r * tmp - d print(ans) tmp = ans
r, D, x = list(map(int, input().split())) for i in range(10): ans = r * x - D print(ans) x = ans
7
6
121
108
r, d, x = list(map(int, input().split())) tmp = x for i in range(10): ans = r * tmp - d print(ans) tmp = ans
r, D, x = list(map(int, input().split())) for i in range(10): ans = r * x - D print(ans) x = ans
false
14.285714
[ "-r, d, x = list(map(int, input().split()))", "-tmp = x", "+r, D, x = list(map(int, input().split()))", "- ans = r * tmp - d", "+ ans = r * x - D", "- tmp = ans", "+ x = ans" ]
false
0.037518
0.036867
1.017656
[ "s587124997", "s686233758" ]
u832039789
p03076
python
s307837629
s763503565
36
17
5,072
3,060
Accepted
Accepted
52.78
import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) l = [i for i in range(5)] p = [int(eval(input())) for _ in range(5)] res = 10**100 for ll in perm(l): now = 0 for ii,i in enumerate(ll): now += p[i] if now % 10 != 0 and ii!=4: now //= 10 now += 1 now *= 10 res = min(res, now) print(res)
lst = [] for i in range(5): n = int(eval(input())) lst.append([(n - 1) % 10, n]) lst = sorted(lst) res = 0 for i in range(5): if i == 0: res += lst[i][1] else: res += (lst[i][1] + 9) // 10 * 10 print(res)
22
13
543
228
import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) l = [i for i in range(5)] p = [int(eval(input())) for _ in range(5)] res = 10**100 for ll in perm(l): now = 0 for ii, i in enumerate(ll): now += p[i] if now % 10 != 0 and ii != 4: now //= 10 now += 1 now *= 10 res = min(res, now) print(res)
lst = [] for i in range(5): n = int(eval(input())) lst.append([(n - 1) % 10, n]) lst = sorted(lst) res = 0 for i in range(5): if i == 0: res += lst[i][1] else: res += (lst[i][1] + 9) // 10 * 10 print(res)
false
40.909091
[ "-import sys", "-from fractions import gcd", "-from itertools import groupby as gb", "-from itertools import permutations as perm", "-from collections import Counter as C", "-from collections import defaultdict as dd", "-", "-sys.setrecursionlimit(10**5)", "-l = [i for i in range(5)]", "-p = [int(eval(input())) for _ in range(5)]", "-res = 10**100", "-for ll in perm(l):", "- now = 0", "- for ii, i in enumerate(ll):", "- now += p[i]", "- if now % 10 != 0 and ii != 4:", "- now //= 10", "- now += 1", "- now *= 10", "- res = min(res, now)", "+lst = []", "+for i in range(5):", "+ n = int(eval(input()))", "+ lst.append([(n - 1) % 10, n])", "+lst = sorted(lst)", "+res = 0", "+for i in range(5):", "+ if i == 0:", "+ res += lst[i][1]", "+ else:", "+ res += (lst[i][1] + 9) // 10 * 10" ]
false
0.059871
0.06331
0.945679
[ "s307837629", "s763503565" ]
u525065967
p02684
python
s983161287
s384410804
193
169
32,372
32,372
Accepted
Accepted
12.44
N,K = list(map(int, input().split())) A = [*[int(x)-1 for x in input().split()]] pre = 0 index = [-1]*N path_cnt = 0 for i in range(N): if index[pre] >= 0: break else: index[pre] = i path_cnt += 1 pre = A[pre] loops = path_cnt - index[pre] one = path_cnt - loops k = max(0, K-one) % loops + min(K, one) pre = 0 for _ in range(k): pre = A[pre] print((pre + 1))
N,K = list(map(int, input().split())) A = [*[int(x)-1 for x in input().split()]] index = [-1]*N pre, path_cnt = 0, 0 for i in range(N): if index[pre] >= 0: break else: index[pre] = i path_cnt += 1 pre = A[pre] loops = path_cnt - index[pre] one = index[pre] k = max(0, K-one) % loops + min(K, one) pre = 0 for _ in range(k): pre = A[pre] print((pre + 1))
21
19
415
399
N, K = list(map(int, input().split())) A = [*[int(x) - 1 for x in input().split()]] pre = 0 index = [-1] * N path_cnt = 0 for i in range(N): if index[pre] >= 0: break else: index[pre] = i path_cnt += 1 pre = A[pre] loops = path_cnt - index[pre] one = path_cnt - loops k = max(0, K - one) % loops + min(K, one) pre = 0 for _ in range(k): pre = A[pre] print((pre + 1))
N, K = list(map(int, input().split())) A = [*[int(x) - 1 for x in input().split()]] index = [-1] * N pre, path_cnt = 0, 0 for i in range(N): if index[pre] >= 0: break else: index[pre] = i path_cnt += 1 pre = A[pre] loops = path_cnt - index[pre] one = index[pre] k = max(0, K - one) % loops + min(K, one) pre = 0 for _ in range(k): pre = A[pre] print((pre + 1))
false
9.52381
[ "-pre = 0", "-path_cnt = 0", "+pre, path_cnt = 0, 0", "-one = path_cnt - loops", "+one = index[pre]" ]
false
0.045663
0.046419
0.98371
[ "s983161287", "s384410804" ]
u074220993
p03475
python
s883508612
s341320948
568
69
27,412
9,220
Accepted
Accepted
87.85
N = int(eval(input())) C, S, F = [], [], [] for _ in range(N-1): c, s, f = list(map(int, input().split())) C.append(c) S.append(s) F.append(f) S.append(0) import numpy as np def theta(x): #ヘヴィサイドの段差関数 return x if x > 0 else 0 def DptTimeAtNextSt(i, T): #時刻Tに駅iを出発した時、駅i+1を出発する時間 global C, S, F arrT = T + C[i] if i == N-2: return arrT return S[i+1] + np.ceil(theta(arrT-S[i+1])/F[i+1]) * F[i+1] def solve(i, S): #駅iに対する解を再帰的に解く関数 if i == N-1: return int(S) else: return solve(i+1, DptTimeAtNextSt(i,S)) for i in range(N): print((solve(i,S[i])))
def main(): with open(0) as f: N = int(f.readline()) train = [tuple(map(int, line.split())) for line in f.readlines()] ans = [] for start in range(N-1): arrive = 0 for station in range(start, N-1): c, s, f = train[station] #出発時間:区間[arrive,)の下限 departure = lambda arrive:(arrive+f-1)//f*f if arrive >= s else s arrive = departure(arrive) + c ans.append(arrive) ans.append(0) for x in ans: print(x) main()
27
19
625
542
N = int(eval(input())) C, S, F = [], [], [] for _ in range(N - 1): c, s, f = list(map(int, input().split())) C.append(c) S.append(s) F.append(f) S.append(0) import numpy as np def theta(x): # ヘヴィサイドの段差関数 return x if x > 0 else 0 def DptTimeAtNextSt(i, T): # 時刻Tに駅iを出発した時、駅i+1を出発する時間 global C, S, F arrT = T + C[i] if i == N - 2: return arrT return S[i + 1] + np.ceil(theta(arrT - S[i + 1]) / F[i + 1]) * F[i + 1] def solve(i, S): # 駅iに対する解を再帰的に解く関数 if i == N - 1: return int(S) else: return solve(i + 1, DptTimeAtNextSt(i, S)) for i in range(N): print((solve(i, S[i])))
def main(): with open(0) as f: N = int(f.readline()) train = [tuple(map(int, line.split())) for line in f.readlines()] ans = [] for start in range(N - 1): arrive = 0 for station in range(start, N - 1): c, s, f = train[station] # 出発時間:区間[arrive,)の下限 departure = lambda arrive: (arrive + f - 1) // f * f if arrive >= s else s arrive = departure(arrive) + c ans.append(arrive) ans.append(0) for x in ans: print(x) main()
false
29.62963
[ "-N = int(eval(input()))", "-C, S, F = [], [], []", "-for _ in range(N - 1):", "- c, s, f = list(map(int, input().split()))", "- C.append(c)", "- S.append(s)", "- F.append(f)", "-S.append(0)", "-import numpy as np", "+def main():", "+ with open(0) as f:", "+ N = int(f.readline())", "+ train = [tuple(map(int, line.split())) for line in f.readlines()]", "+ ans = []", "+ for start in range(N - 1):", "+ arrive = 0", "+ for station in range(start, N - 1):", "+ c, s, f = train[station]", "+ # 出発時間:区間[arrive,)の下限", "+ departure = lambda arrive: (arrive + f - 1) // f * f if arrive >= s else s", "+ arrive = departure(arrive) + c", "+ ans.append(arrive)", "+ ans.append(0)", "+ for x in ans:", "+ print(x)", "-def theta(x): # ヘヴィサイドの段差関数", "- return x if x > 0 else 0", "-", "-", "-def DptTimeAtNextSt(i, T): # 時刻Tに駅iを出発した時、駅i+1を出発する時間", "- global C, S, F", "- arrT = T + C[i]", "- if i == N - 2:", "- return arrT", "- return S[i + 1] + np.ceil(theta(arrT - S[i + 1]) / F[i + 1]) * F[i + 1]", "-", "-", "-def solve(i, S): # 駅iに対する解を再帰的に解く関数", "- if i == N - 1:", "- return int(S)", "- else:", "- return solve(i + 1, DptTimeAtNextSt(i, S))", "-", "-", "-for i in range(N):", "- print((solve(i, S[i])))", "+main()" ]
false
0.190679
0.035875
5.315111
[ "s883508612", "s341320948" ]
u894258749
p03078
python
s655060090
s807611096
411
63
5,088
5,280
Accepted
Accepted
84.67
from collections import defaultdict inpl = lambda: list(map(int,input().split())) X, Y, Z, K = inpl() A = [ sorted(inpl(), key=lambda x: -x) for _ in range(3) ] N = [X, Y, Z] mem = defaultdict(int) ans = sum([A[i][0] for i in range(3)]) mem[(0,0,0)] = 1 cand = [(ans,0,0,0)] for i in range(K): cand.sort() c = cand[-1] print((c[0])) n = [c[1],c[2],c[3]] cand.pop(-1) for p in range(3): if n[p] < N[p]-1: n[p] += 1 if mem[(n[0],n[1],n[2])] == 0: mem[(n[0],n[1],n[2])] = 1 cand.append((sum([A[j][n[j]] for j in range(3)]),n[0],n[1],n[2])) n[p] -= 1
from collections import defaultdict import heapq inpl = lambda: list(map(int,input().split())) X, Y, Z, K = inpl() A = [ sorted(inpl(), reverse=True) for _ in range(3) ] N = [X, Y, Z] mem = defaultdict(int) score = sum([A[i][0] for i in range(3)]) mem[(0,0,0)] = 1 candidates = [] heapq.heappush(candidates, (-score,(0,0,0))) for i in range(K): c = heapq.heappop(candidates) print((-c[0])) n = list(c[1]) for p in range(3): if n[p] < N[p]-1: n[p] += 1 if mem[tuple(n)] == 0: mem[tuple(n)] = 1 score = sum([A[j][n[j]] for j in range(3)]) heapq.heappush(candidates, (-score,tuple(n))) n[p] -= 1
26
27
677
732
from collections import defaultdict inpl = lambda: list(map(int, input().split())) X, Y, Z, K = inpl() A = [sorted(inpl(), key=lambda x: -x) for _ in range(3)] N = [X, Y, Z] mem = defaultdict(int) ans = sum([A[i][0] for i in range(3)]) mem[(0, 0, 0)] = 1 cand = [(ans, 0, 0, 0)] for i in range(K): cand.sort() c = cand[-1] print((c[0])) n = [c[1], c[2], c[3]] cand.pop(-1) for p in range(3): if n[p] < N[p] - 1: n[p] += 1 if mem[(n[0], n[1], n[2])] == 0: mem[(n[0], n[1], n[2])] = 1 cand.append((sum([A[j][n[j]] for j in range(3)]), n[0], n[1], n[2])) n[p] -= 1
from collections import defaultdict import heapq inpl = lambda: list(map(int, input().split())) X, Y, Z, K = inpl() A = [sorted(inpl(), reverse=True) for _ in range(3)] N = [X, Y, Z] mem = defaultdict(int) score = sum([A[i][0] for i in range(3)]) mem[(0, 0, 0)] = 1 candidates = [] heapq.heappush(candidates, (-score, (0, 0, 0))) for i in range(K): c = heapq.heappop(candidates) print((-c[0])) n = list(c[1]) for p in range(3): if n[p] < N[p] - 1: n[p] += 1 if mem[tuple(n)] == 0: mem[tuple(n)] = 1 score = sum([A[j][n[j]] for j in range(3)]) heapq.heappush(candidates, (-score, tuple(n))) n[p] -= 1
false
3.703704
[ "+import heapq", "-A = [sorted(inpl(), key=lambda x: -x) for _ in range(3)]", "+A = [sorted(inpl(), reverse=True) for _ in range(3)]", "-ans = sum([A[i][0] for i in range(3)])", "+score = sum([A[i][0] for i in range(3)])", "-cand = [(ans, 0, 0, 0)]", "+candidates = []", "+heapq.heappush(candidates, (-score, (0, 0, 0)))", "- cand.sort()", "- c = cand[-1]", "- print((c[0]))", "- n = [c[1], c[2], c[3]]", "- cand.pop(-1)", "+ c = heapq.heappop(candidates)", "+ print((-c[0]))", "+ n = list(c[1])", "- if mem[(n[0], n[1], n[2])] == 0:", "- mem[(n[0], n[1], n[2])] = 1", "- cand.append((sum([A[j][n[j]] for j in range(3)]), n[0], n[1], n[2]))", "+ if mem[tuple(n)] == 0:", "+ mem[tuple(n)] = 1", "+ score = sum([A[j][n[j]] for j in range(3)])", "+ heapq.heappush(candidates, (-score, tuple(n)))" ]
false
0.085833
0.040032
2.144117
[ "s655060090", "s807611096" ]
u821588465
p02898
python
s837011294
s075184973
143
61
37,288
18,576
Accepted
Accepted
57.34
import numpy as np N, K = list(map(int, input().split())) H = list(map(int, input().split())) H = np.array(H) print((np.count_nonzero(H >= K)))
N, K = list(map(int, input().split())) H = list(map(int, input().split())) cnt = 0 for h in H: if h >= K: cnt += 1 print(cnt)
9
8
149
140
import numpy as np N, K = list(map(int, input().split())) H = list(map(int, input().split())) H = np.array(H) print((np.count_nonzero(H >= K)))
N, K = list(map(int, input().split())) H = list(map(int, input().split())) cnt = 0 for h in H: if h >= K: cnt += 1 print(cnt)
false
11.111111
[ "-import numpy as np", "-", "-H = np.array(H)", "-print((np.count_nonzero(H >= K)))", "+cnt = 0", "+for h in H:", "+ if h >= K:", "+ cnt += 1", "+print(cnt)" ]
false
0.20661
0.036457
5.667266
[ "s837011294", "s075184973" ]
u573754721
p02837
python
s418799791
s197432218
400
273
3,064
46,828
Accepted
Accepted
31.75
n=int(eval(input())) a=[] b=[] for i in range(n): aa=int(eval(input())) a.append(aa) d=[] for j in range(aa): x,y=list(map(int,input().split())) d.append((x,y)) b.append(d) cc=0 for i in range(2**n): L=[0]*n for j in range(n): if ((i>>j)&1): L[j]=1 if 1 in L: flag=True for k in range(n): if L[k]==1: for m in range(a[k]): if L[b[k][m][0]-1]!=b[k][m][1]: flag=False break if flag: cc=max(sum(L),cc) print(cc)
n=int(eval(input())) A=[] B=[] for i in range(n): a=int(eval(input())) A.append(a) d=[] for j in range(a): x,y=list(map(int,input().split())) d.append((x,y)) B.append(d) ans=0 for i in range(2**n): L=[0]*n for j in range(n): if i>>j&1: L[j]=1 if 1 in L: flag=True for k in range(n): if L[k]==1: for m in range(A[k]): if L[B[k][m][0]-1]!=B[k][m][1]: flag=False break if flag: ans=max(sum(L),ans) print(ans)
29
28
719
564
n = int(eval(input())) a = [] b = [] for i in range(n): aa = int(eval(input())) a.append(aa) d = [] for j in range(aa): x, y = list(map(int, input().split())) d.append((x, y)) b.append(d) cc = 0 for i in range(2**n): L = [0] * n for j in range(n): if (i >> j) & 1: L[j] = 1 if 1 in L: flag = True for k in range(n): if L[k] == 1: for m in range(a[k]): if L[b[k][m][0] - 1] != b[k][m][1]: flag = False break if flag: cc = max(sum(L), cc) print(cc)
n = int(eval(input())) A = [] B = [] for i in range(n): a = int(eval(input())) A.append(a) d = [] for j in range(a): x, y = list(map(int, input().split())) d.append((x, y)) B.append(d) ans = 0 for i in range(2**n): L = [0] * n for j in range(n): if i >> j & 1: L[j] = 1 if 1 in L: flag = True for k in range(n): if L[k] == 1: for m in range(A[k]): if L[B[k][m][0] - 1] != B[k][m][1]: flag = False break if flag: ans = max(sum(L), ans) print(ans)
false
3.448276
[ "-a = []", "-b = []", "+A = []", "+B = []", "- aa = int(eval(input()))", "- a.append(aa)", "+ a = int(eval(input()))", "+ A.append(a)", "- for j in range(aa):", "+ for j in range(a):", "- b.append(d)", "-cc = 0", "+ B.append(d)", "+ans = 0", "- if (i >> j) & 1:", "+ if i >> j & 1:", "- for m in range(a[k]):", "- if L[b[k][m][0] - 1] != b[k][m][1]:", "+ for m in range(A[k]):", "+ if L[B[k][m][0] - 1] != B[k][m][1]:", "- cc = max(sum(L), cc)", "-print(cc)", "+ ans = max(sum(L), ans)", "+print(ans)" ]
false
0.045713
0.038918
1.174595
[ "s418799791", "s197432218" ]
u952164537
p02887
python
s587390623
s533363801
1,539
72
4,664
5,416
Accepted
Accepted
95.32
length = int(eval(input())) li = list(eval(input())) i = 0 for n in li[:]: if i + 1 == len(li): print((len(li))) break if li[i] == li[i + 1]: del (li[i + 1]) else: i = 1 + i continue
length = int(eval(input())) li = list(eval(input())) li2 = [] i = -1 for str in li[:]: i = 1 + i if i + 1 == len(li): li2.append(li[i]) print((len(li2))) break if li[i] != li[i + 1]: li2.append(li[i]) continue
12
13
230
259
length = int(eval(input())) li = list(eval(input())) i = 0 for n in li[:]: if i + 1 == len(li): print((len(li))) break if li[i] == li[i + 1]: del li[i + 1] else: i = 1 + i continue
length = int(eval(input())) li = list(eval(input())) li2 = [] i = -1 for str in li[:]: i = 1 + i if i + 1 == len(li): li2.append(li[i]) print((len(li2))) break if li[i] != li[i + 1]: li2.append(li[i]) continue
false
7.692308
[ "-i = 0", "-for n in li[:]:", "+li2 = []", "+i = -1", "+for str in li[:]:", "+ i = 1 + i", "- print((len(li)))", "+ li2.append(li[i])", "+ print((len(li2)))", "- if li[i] == li[i + 1]:", "- del li[i + 1]", "- else:", "- i = 1 + i", "+ if li[i] != li[i + 1]:", "+ li2.append(li[i])" ]
false
0.093083
0.036714
2.535392
[ "s587390623", "s533363801" ]
u801359367
p03478
python
s923250543
s175402177
37
30
3,060
3,060
Accepted
Accepted
18.92
N,a,b = list(map(int,input().split())) Sum_0 = 0 for i in range(N+1): i = str(i) Sum_1 = 0 for t in i: Sum_1 += int(t) if a <= Sum_1 <=b: Sum_0+=int(i) print (Sum_0)
N,a,b = list(map(int,input().split())) Sum_0 = 0 for i in range(1,N+1): Sum_1 = 0 t = i while t != 0: Sum_1+=t%10 t = t//10 if a <= Sum_1 <= b: Sum_0+=i print(Sum_0)
11
13
208
227
N, a, b = list(map(int, input().split())) Sum_0 = 0 for i in range(N + 1): i = str(i) Sum_1 = 0 for t in i: Sum_1 += int(t) if a <= Sum_1 <= b: Sum_0 += int(i) print(Sum_0)
N, a, b = list(map(int, input().split())) Sum_0 = 0 for i in range(1, N + 1): Sum_1 = 0 t = i while t != 0: Sum_1 += t % 10 t = t // 10 if a <= Sum_1 <= b: Sum_0 += i print(Sum_0)
false
15.384615
[ "-for i in range(N + 1):", "- i = str(i)", "+for i in range(1, N + 1):", "- for t in i:", "- Sum_1 += int(t)", "+ t = i", "+ while t != 0:", "+ Sum_1 += t % 10", "+ t = t // 10", "- Sum_0 += int(i)", "+ Sum_0 += i" ]
false
0.04061
0.045893
0.884888
[ "s923250543", "s175402177" ]
u678167152
p03625
python
s431295457
s450011337
244
105
68,760
18,600
Accepted
Accepted
56.97
N = int(eval(input())) A = list(map(int, input().split())) import collections ans = 0 c = collections.Counter(A) lis = [] for k,v in list(c.items()): if v>=2: lis.append(k) if v>=4: lis.append(k) if len(lis)>=2: lis.sort() ans = lis[-1]*lis[-2] print(ans) #print(*ans, sep='\n')
from collections import Counter def solve(): ans = 0 N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) D = [[0,0],[0,0]] for k,v in list(C.items()): if v>=2: D.append([k,v]) D.sort(reverse=True) if D[0][1]>=4: return D[0][0]**2 return D[0][0]*D[1][0] print((solve()))
18
15
302
355
N = int(eval(input())) A = list(map(int, input().split())) import collections ans = 0 c = collections.Counter(A) lis = [] for k, v in list(c.items()): if v >= 2: lis.append(k) if v >= 4: lis.append(k) if len(lis) >= 2: lis.sort() ans = lis[-1] * lis[-2] print(ans) # print(*ans, sep='\n')
from collections import Counter def solve(): ans = 0 N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) D = [[0, 0], [0, 0]] for k, v in list(C.items()): if v >= 2: D.append([k, v]) D.sort(reverse=True) if D[0][1] >= 4: return D[0][0] ** 2 return D[0][0] * D[1][0] print((solve()))
false
16.666667
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-import collections", "+from collections import Counter", "-ans = 0", "-c = collections.Counter(A)", "-lis = []", "-for k, v in list(c.items()):", "- if v >= 2:", "- lis.append(k)", "- if v >= 4:", "- lis.append(k)", "-if len(lis) >= 2:", "- lis.sort()", "- ans = lis[-1] * lis[-2]", "-print(ans)", "-# print(*ans, sep='\\n')", "+", "+def solve():", "+ ans = 0", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ C = Counter(A)", "+ D = [[0, 0], [0, 0]]", "+ for k, v in list(C.items()):", "+ if v >= 2:", "+ D.append([k, v])", "+ D.sort(reverse=True)", "+ if D[0][1] >= 4:", "+ return D[0][0] ** 2", "+ return D[0][0] * D[1][0]", "+", "+", "+print((solve()))" ]
false
0.08491
0.114579
0.741061
[ "s431295457", "s450011337" ]
u437727817
p02768
python
s739045137
s220905152
1,505
120
3,060
3,064
Accepted
Accepted
92.03
import itertools import math n,a,b = list(map(int,input().split())) mod = 10**9+7 def comb(n, r): ans = 1 for i in range(r): ans = ans * (n-i) * pow(i+1, mod-2, mod) % mod return ans print(((pow(2, n, mod)-1-comb(n,a)-comb(n,b)) % mod))
n,a,b = list(map(int,input().split())) mod = 10**9+7 def comb(n,r): u = 1 d = 1 for i in range(n-r+1,n+1): u = u*i%mod for i in range(1,r+1): d = d*i%mod D = pow(d,mod-2,mod) return u*D%mod ans = pow(2,n,mod)-1-comb(n,a)-comb(n,b) print((ans%mod))
14
20
266
275
import itertools import math n, a, b = list(map(int, input().split())) mod = 10**9 + 7 def comb(n, r): ans = 1 for i in range(r): ans = ans * (n - i) * pow(i + 1, mod - 2, mod) % mod return ans print(((pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)) % mod))
n, a, b = list(map(int, input().split())) mod = 10**9 + 7 def comb(n, r): u = 1 d = 1 for i in range(n - r + 1, n + 1): u = u * i % mod for i in range(1, r + 1): d = d * i % mod D = pow(d, mod - 2, mod) return u * D % mod ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b) print((ans % mod))
false
30
[ "-import itertools", "-import math", "-", "- ans = 1", "- for i in range(r):", "- ans = ans * (n - i) * pow(i + 1, mod - 2, mod) % mod", "- return ans", "+ u = 1", "+ d = 1", "+ for i in range(n - r + 1, n + 1):", "+ u = u * i % mod", "+ for i in range(1, r + 1):", "+ d = d * i % mod", "+ D = pow(d, mod - 2, mod)", "+ return u * D % mod", "-print(((pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)) % mod))", "+ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)", "+print((ans % mod))" ]
false
0.78661
0.091984
8.551641
[ "s739045137", "s220905152" ]
u348805958
p02610
python
s574922684
s102346702
610
348
124,604
143,528
Accepted
Accepted
42.95
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from heapq import heappush, heappushpop def resolve(): it = map(int, sys.stdin.read().split()) T = next(it) ans = [] for i in range(T): N = next(it) val = 0; a1 = []; a2 = [] for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)): diff = v1 - v2 if diff == 0: val += v1 elif diff > 0: a1.append((i, diff)) val += v2 else: a2.append((N-i, -diff)) val += v1 a1.sort(); a2.sort() for aa in (a1, a2): dq = [] for i, diff in aa: ld = len(dq) if ld < i: heappush(dq, diff) else: diff = heappushpop(dq, diff) val += sum(dq) ans.append(val) print(*ans, sep="\n") if __name__ == "__main__": resolve()
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from heapq import heappush, heappushpop def resolve(): it = map(int, sys.stdin.read().split()) T = next(it) ans = [] for i in range(T): N = next(it) val = 0 a1 = [[] for i in range(N)]; a2 = [[] for i in range(N)]; for i, v1, v2 in ((next(it)-1, next(it), next(it)) for i in range(N)): diff = v1 - v2 if diff == 0 or i == N-1: val += v1 elif diff > 0: a1[i].append(diff) val += v2 else: i = N-1-i-1 a2[i].append(-diff) val += v1 for ax in (a1, a2): dq = [] for i, aa in enumerate(ax): if not aa: continue for diff in aa: ld = len(dq) if ld <= i: heappush(dq, diff) else: diff = heappushpop(dq, diff) val += sum(dq) ans.append(val) print(*ans, sep="\n") if __name__ == "__main__": resolve()
47
51
1,070
1,235
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from heapq import heappush, heappushpop def resolve(): it = map(int, sys.stdin.read().split()) T = next(it) ans = [] for i in range(T): N = next(it) val = 0 a1 = [] a2 = [] for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)): diff = v1 - v2 if diff == 0: val += v1 elif diff > 0: a1.append((i, diff)) val += v2 else: a2.append((N - i, -diff)) val += v1 a1.sort() a2.sort() for aa in (a1, a2): dq = [] for i, diff in aa: ld = len(dq) if ld < i: heappush(dq, diff) else: diff = heappushpop(dq, diff) val += sum(dq) ans.append(val) print(*ans, sep="\n") if __name__ == "__main__": resolve()
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from heapq import heappush, heappushpop def resolve(): it = map(int, sys.stdin.read().split()) T = next(it) ans = [] for i in range(T): N = next(it) val = 0 a1 = [[] for i in range(N)] a2 = [[] for i in range(N)] for i, v1, v2 in ((next(it) - 1, next(it), next(it)) for i in range(N)): diff = v1 - v2 if diff == 0 or i == N - 1: val += v1 elif diff > 0: a1[i].append(diff) val += v2 else: i = N - 1 - i - 1 a2[i].append(-diff) val += v1 for ax in (a1, a2): dq = [] for i, aa in enumerate(ax): if not aa: continue for diff in aa: ld = len(dq) if ld <= i: heappush(dq, diff) else: diff = heappushpop(dq, diff) val += sum(dq) ans.append(val) print(*ans, sep="\n") if __name__ == "__main__": resolve()
false
7.843137
[ "- a1 = []", "- a2 = []", "- for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)):", "+ a1 = [[] for i in range(N)]", "+ a2 = [[] for i in range(N)]", "+ for i, v1, v2 in ((next(it) - 1, next(it), next(it)) for i in range(N)):", "- if diff == 0:", "+ if diff == 0 or i == N - 1:", "- a1.append((i, diff))", "+ a1[i].append(diff)", "- a2.append((N - i, -diff))", "+ i = N - 1 - i - 1", "+ a2[i].append(-diff)", "- a1.sort()", "- a2.sort()", "- for aa in (a1, a2):", "+ for ax in (a1, a2):", "- for i, diff in aa:", "- ld = len(dq)", "- if ld < i:", "- heappush(dq, diff)", "- else:", "- diff = heappushpop(dq, diff)", "+ for i, aa in enumerate(ax):", "+ if not aa:", "+ continue", "+ for diff in aa:", "+ ld = len(dq)", "+ if ld <= i:", "+ heappush(dq, diff)", "+ else:", "+ diff = heappushpop(dq, diff)" ]
false
0.105011
0.038132
2.753911
[ "s574922684", "s102346702" ]
u790710233
p03283
python
s647052812
s688530679
1,373
1,020
112,628
66,296
Accepted
Accepted
25.71
import numpy as np import sys input = sys.stdin.readline n, m, q = map(int, input().split()) cnt = np.zeros((n+1, n+1), dtype=np.int32) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(m)])) np.add.at(cnt, (L, R), 1) S = np.cumsum(cnt, axis=0).cumsum(axis=1) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(q)])) ans = S[R, R]-S[R, L-1]-S[L-1, R]+S[L-1, L-1] print(*ans, sep='\n')
import numpy as np import sys input = sys.stdin.readline n, m, q = map(int, input().split()) cnt = [[0]*(n+1)for _ in range(n+1)] for _ in range(m): L, R = map(int, input().split()) cnt[L][R] += 1 S = np.cumsum(cnt, axis=0).cumsum(axis=1) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(q)])) ans = S[R, R]-S[R, L-1]-S[L-1, R]+S[L-1, L-1] print(*ans, sep='\n')
13
14
433
403
import numpy as np import sys input = sys.stdin.readline n, m, q = map(int, input().split()) cnt = np.zeros((n + 1, n + 1), dtype=np.int32) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(m)])) np.add.at(cnt, (L, R), 1) S = np.cumsum(cnt, axis=0).cumsum(axis=1) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(q)])) ans = S[R, R] - S[R, L - 1] - S[L - 1, R] + S[L - 1, L - 1] print(*ans, sep="\n")
import numpy as np import sys input = sys.stdin.readline n, m, q = map(int, input().split()) cnt = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): L, R = map(int, input().split()) cnt[L][R] += 1 S = np.cumsum(cnt, axis=0).cumsum(axis=1) L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(q)])) ans = S[R, R] - S[R, L - 1] - S[L - 1, R] + S[L - 1, L - 1] print(*ans, sep="\n")
false
7.142857
[ "-cnt = np.zeros((n + 1, n + 1), dtype=np.int32)", "-L, R = map(np.array, zip(*[map(int, input().split()) for _ in range(m)]))", "-np.add.at(cnt, (L, R), 1)", "+cnt = [[0] * (n + 1) for _ in range(n + 1)]", "+for _ in range(m):", "+ L, R = map(int, input().split())", "+ cnt[L][R] += 1" ]
false
0.187559
0.221301
0.84753
[ "s647052812", "s688530679" ]
u072053884
p00277
python
s821125996
s938636003
2,940
2,380
105,996
89,508
Accepted
Accepted
19.05
import sys from heapq import heappush, heappop def solve(): file_input = sys.stdin N, R, L = list(map(int, file_input.readline().split())) hq = [] m = {} for i in range(1, N + 1): team = [0, i, 0] heappush(hq, team) m[i] = team time = 0 for line in file_input: d, t, x = list(map(int, line.split())) hq[0][2] += t - time time = t scored_team = m[d][:] scored_team[0] -= x heappush(hq, scored_team) m[d][2] = -1 m[d] = scored_team while hq[0][2] == -1: heappop(hq) hq[0][2] += L - time ans_team = max(hq, key = lambda x: (x[2], -x[1])) print((ans_team[1])) solve()
import sys from heapq import heappush, heappop, heapreplace def solve(): file_input = sys.stdin N, R, L = list(map(int, file_input.readline().split())) pq = [[0, i, 0] for i in range(1, N + 1)] m = dict(list(zip(list(range(1, N + 1)), pq))) pre_t = 0 for line in file_input: d, t, x = list(map(int, line.split())) team = pq[0] team[2] += t - pre_t pre_t = t if team[1] == d: team[0] -= x if x < 0: heapreplace(pq, team) else: scored_team = m[d][:] scored_team[0] -= x heappush(pq, scored_team) m[d][2] = -1 m[d] = scored_team while pq[0][2] == -1: heappop(pq) pq[0][2] += L - pre_t ans_team = max(pq, key = lambda x: (x[2], -x[1])) print((ans_team[1])) solve()
33
35
760
903
import sys from heapq import heappush, heappop def solve(): file_input = sys.stdin N, R, L = list(map(int, file_input.readline().split())) hq = [] m = {} for i in range(1, N + 1): team = [0, i, 0] heappush(hq, team) m[i] = team time = 0 for line in file_input: d, t, x = list(map(int, line.split())) hq[0][2] += t - time time = t scored_team = m[d][:] scored_team[0] -= x heappush(hq, scored_team) m[d][2] = -1 m[d] = scored_team while hq[0][2] == -1: heappop(hq) hq[0][2] += L - time ans_team = max(hq, key=lambda x: (x[2], -x[1])) print((ans_team[1])) solve()
import sys from heapq import heappush, heappop, heapreplace def solve(): file_input = sys.stdin N, R, L = list(map(int, file_input.readline().split())) pq = [[0, i, 0] for i in range(1, N + 1)] m = dict(list(zip(list(range(1, N + 1)), pq))) pre_t = 0 for line in file_input: d, t, x = list(map(int, line.split())) team = pq[0] team[2] += t - pre_t pre_t = t if team[1] == d: team[0] -= x if x < 0: heapreplace(pq, team) else: scored_team = m[d][:] scored_team[0] -= x heappush(pq, scored_team) m[d][2] = -1 m[d] = scored_team while pq[0][2] == -1: heappop(pq) pq[0][2] += L - pre_t ans_team = max(pq, key=lambda x: (x[2], -x[1])) print((ans_team[1])) solve()
false
5.714286
[ "-from heapq import heappush, heappop", "+from heapq import heappush, heappop, heapreplace", "- hq = []", "- m = {}", "- for i in range(1, N + 1):", "- team = [0, i, 0]", "- heappush(hq, team)", "- m[i] = team", "- time = 0", "+ pq = [[0, i, 0] for i in range(1, N + 1)]", "+ m = dict(list(zip(list(range(1, N + 1)), pq)))", "+ pre_t = 0", "- hq[0][2] += t - time", "- time = t", "- scored_team = m[d][:]", "- scored_team[0] -= x", "- heappush(hq, scored_team)", "- m[d][2] = -1", "- m[d] = scored_team", "- while hq[0][2] == -1:", "- heappop(hq)", "- hq[0][2] += L - time", "- ans_team = max(hq, key=lambda x: (x[2], -x[1]))", "+ team = pq[0]", "+ team[2] += t - pre_t", "+ pre_t = t", "+ if team[1] == d:", "+ team[0] -= x", "+ if x < 0:", "+ heapreplace(pq, team)", "+ else:", "+ scored_team = m[d][:]", "+ scored_team[0] -= x", "+ heappush(pq, scored_team)", "+ m[d][2] = -1", "+ m[d] = scored_team", "+ while pq[0][2] == -1:", "+ heappop(pq)", "+ pq[0][2] += L - pre_t", "+ ans_team = max(pq, key=lambda x: (x[2], -x[1]))" ]
false
0.04233
0.044457
0.952138
[ "s821125996", "s938636003" ]
u440566786
p03684
python
s218824191
s790300580
1,660
1,389
128,588
124,828
Accepted
Accepted
16.33
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # input=lambda :sys.stdin.readline().rstrip() def resolve(): class UnionFind(object): """ query: O(Ack^-1(n,n)) (amortize) """ def __init__(self,n): """ param n: number of nodes """ self.__par=list(range(n)) self.__rank=[0]*n self.__size=[1]*n def __root(self,k): if self.__par[k]==k: return k else: self.__par[k]=self.__root(self.__par[k]) return self.__par[k] def is_same(self,i,j): return self.__root(i)==self.__root(j) def unite(self,i,j): i=self.__root(i) j=self.__root(j) if i==j: return if self.__rank[i]>self.__rank[j]: self.__par[j]=i else: self.__par[i]=j if self.__rank[i]==self.__rank[j]: self.__rank[j]+=1 # 候補となるedgesは2N-2個しかないため、全列挙 # Kruskal's algorithmでuniteしていく from operator import itemgetter n=int(eval(input())) P=[0]*n edges=[0]*(2*n-2) for i in range(n): x,y=list(map(int,input().split())) P[i]=(x,y,i) # xでsort P.sort(key=itemgetter(0)) for k in range(n-1): x0,y0,i=P[k] x1,y1,j=P[k+1] edges[k]=(i,j,min(abs(x0-x1),abs(y0-y1))) # yでsort P.sort(key=itemgetter(1)) for k in range(n-1): x0,y0,i=P[k] x1,y1,j=P[k+1] edges[k+n-1]=(i,j,min(abs(x0-x1),abs(y0-y1))) # edgesをcostでsort edges.sort(key=itemgetter(2)) # union findに突っ込んでいく tree=UnionFind(n) ans=0 for i,j,cost in edges: if tree.is_same(i,j): continue tree.unite(i,j) ans+=cost print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): class UnionFind(object): """ query: O(Ack^-1(n,n)) (amortize) """ def __init__(self,n): """ param n: number of nodes """ self.__par=list(range(n)) self.__rank=[0]*n self.__size=[1]*n def __root(self,k): if self.__par[k]==k: return k else: self.__par[k]=self.__root(self.__par[k]) return self.__par[k] def is_same(self,i,j): return self.__root(i)==self.__root(j) def unite(self,i,j): i=self.__root(i) j=self.__root(j) if i==j: return if self.__rank[i]>self.__rank[j]: self.__par[j]=i else: self.__par[i]=j if self.__rank[i]==self.__rank[j]: self.__rank[j]+=1 # Kruskal's algorithm from operator import itemgetter n=int(eval(input())) P=[0]*n edges=[0]*(2*n-2) for i in range(n): x,y=list(map(int,input().split())) P[i]=(x,y,i) # xでsort P.sort(key=itemgetter(0)) for k in range(n-1): x0,y0,i=P[k] x1,y1,j=P[k+1] edges[k]=(i,j,min(abs(x0-x1),abs(y0-y1))) # yでsort P.sort(key=itemgetter(1)) for k in range(n-1): x0,y0,i=P[k] x1,y1,j=P[k+1] edges[k+n-1]=(i,j,min(abs(x0-x1),abs(y0-y1))) # edgesをcostでsort edges.sort(key=itemgetter(2)) # union findに突っ込んでいく tree=UnionFind(n) ans=0 for i,j,cost in edges: if tree.is_same(i,j): continue tree.unite(i,j) ans+=cost print(ans) resolve()
70
68
1,887
1,839
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 # input=lambda :sys.stdin.readline().rstrip() def resolve(): class UnionFind(object): """ query: O(Ack^-1(n,n)) (amortize) """ def __init__(self, n): """ param n: number of nodes """ self.__par = list(range(n)) self.__rank = [0] * n self.__size = [1] * n def __root(self, k): if self.__par[k] == k: return k else: self.__par[k] = self.__root(self.__par[k]) return self.__par[k] def is_same(self, i, j): return self.__root(i) == self.__root(j) def unite(self, i, j): i = self.__root(i) j = self.__root(j) if i == j: return if self.__rank[i] > self.__rank[j]: self.__par[j] = i else: self.__par[i] = j if self.__rank[i] == self.__rank[j]: self.__rank[j] += 1 # 候補となるedgesは2N-2個しかないため、全列挙 # Kruskal's algorithmでuniteしていく from operator import itemgetter n = int(eval(input())) P = [0] * n edges = [0] * (2 * n - 2) for i in range(n): x, y = list(map(int, input().split())) P[i] = (x, y, i) # xでsort P.sort(key=itemgetter(0)) for k in range(n - 1): x0, y0, i = P[k] x1, y1, j = P[k + 1] edges[k] = (i, j, min(abs(x0 - x1), abs(y0 - y1))) # yでsort P.sort(key=itemgetter(1)) for k in range(n - 1): x0, y0, i = P[k] x1, y1, j = P[k + 1] edges[k + n - 1] = (i, j, min(abs(x0 - x1), abs(y0 - y1))) # edgesをcostでsort edges.sort(key=itemgetter(2)) # union findに突っ込んでいく tree = UnionFind(n) ans = 0 for i, j, cost in edges: if tree.is_same(i, j): continue tree.unite(i, j) ans += cost print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): class UnionFind(object): """ query: O(Ack^-1(n,n)) (amortize) """ def __init__(self, n): """ param n: number of nodes """ self.__par = list(range(n)) self.__rank = [0] * n self.__size = [1] * n def __root(self, k): if self.__par[k] == k: return k else: self.__par[k] = self.__root(self.__par[k]) return self.__par[k] def is_same(self, i, j): return self.__root(i) == self.__root(j) def unite(self, i, j): i = self.__root(i) j = self.__root(j) if i == j: return if self.__rank[i] > self.__rank[j]: self.__par[j] = i else: self.__par[i] = j if self.__rank[i] == self.__rank[j]: self.__rank[j] += 1 # Kruskal's algorithm from operator import itemgetter n = int(eval(input())) P = [0] * n edges = [0] * (2 * n - 2) for i in range(n): x, y = list(map(int, input().split())) P[i] = (x, y, i) # xでsort P.sort(key=itemgetter(0)) for k in range(n - 1): x0, y0, i = P[k] x1, y1, j = P[k + 1] edges[k] = (i, j, min(abs(x0 - x1), abs(y0 - y1))) # yでsort P.sort(key=itemgetter(1)) for k in range(n - 1): x0, y0, i = P[k] x1, y1, j = P[k + 1] edges[k + n - 1] = (i, j, min(abs(x0 - x1), abs(y0 - y1))) # edgesをcostでsort edges.sort(key=itemgetter(2)) # union findに突っ込んでいく tree = UnionFind(n) ans = 0 for i, j, cost in edges: if tree.is_same(i, j): continue tree.unite(i, j) ans += cost print(ans) resolve()
false
2.857143
[ "-# input=lambda :sys.stdin.readline().rstrip()", "+input = lambda: sys.stdin.readline().rstrip()", "+", "+", "- # 候補となるedgesは2N-2個しかないため、全列挙", "- # Kruskal's algorithmでuniteしていく", "+ # Kruskal's algorithm" ]
false
0.127917
0.087016
1.470049
[ "s218824191", "s790300580" ]
u133936772
p02918
python
s901138054
s162296291
55
19
15,988
3,316
Accepted
Accepted
65.45
n,k=list(map(int,input().split())) from itertools import* print((n-max(len(list(groupby(eval(input()))))-k*2,1)))
n,k=list(map(int,input().split())) s=eval(input()) c=s.count print((n-1-max(c('LR')+c('RL')-k*2,0)))
3
4
101
89
n, k = list(map(int, input().split())) from itertools import * print((n - max(len(list(groupby(eval(input())))) - k * 2, 1)))
n, k = list(map(int, input().split())) s = eval(input()) c = s.count print((n - 1 - max(c("LR") + c("RL") - k * 2, 0)))
false
25
[ "-from itertools import *", "-", "-print((n - max(len(list(groupby(eval(input())))) - k * 2, 1)))", "+s = eval(input())", "+c = s.count", "+print((n - 1 - max(c(\"LR\") + c(\"RL\") - k * 2, 0)))" ]
false
0.040261
0.03884
1.036585
[ "s901138054", "s162296291" ]
u416758623
p03370
python
s730474548
s747552331
39
17
3,064
3,060
Accepted
Accepted
56.41
n,x = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] total = x - sum(ls) minNum = min(ls) ans = n - 1 while total >= 0: total -= minNum ans += 1 print(ans)
n, x = list(map(int, input().split())) minNum = float('inf') for i in range(n): m = int(eval(input())) minNum = min(m, minNum) x -= m print((x // minNum + n))
10
7
190
162
n, x = list(map(int, input().split())) ls = [int(eval(input())) for _ in range(n)] total = x - sum(ls) minNum = min(ls) ans = n - 1 while total >= 0: total -= minNum ans += 1 print(ans)
n, x = list(map(int, input().split())) minNum = float("inf") for i in range(n): m = int(eval(input())) minNum = min(m, minNum) x -= m print((x // minNum + n))
false
30
[ "-ls = [int(eval(input())) for _ in range(n)]", "-total = x - sum(ls)", "-minNum = min(ls)", "-ans = n - 1", "-while total >= 0:", "- total -= minNum", "- ans += 1", "-print(ans)", "+minNum = float(\"inf\")", "+for i in range(n):", "+ m = int(eval(input()))", "+ minNum = min(m, minNum)", "+ x -= m", "+print((x // minNum + n))" ]
false
0.044633
0.037502
1.190168
[ "s730474548", "s747552331" ]
u927357863
p02995
python
s795494617
s589479884
164
17
38,256
3,064
Accepted
Accepted
89.63
# -*- coding: utf-8 -*- A, B, C, D = list(map(int, input().split())) ans = 0 Am = 0 Bm = 0 df = 0 t = 0 def lcm(x, y): return (x * y) // gcd(x, y) def gcd(a, b): while b: a, b = b, a % b return a t = B - A + 1 Am = B // C - (A - 1) // C Bm = B // D - (A - 1) // D df = B // lcm(C, D) - (A - 1)//lcm(C, D) ans = t - (Am + Bm) + df print(ans)
# -*- coding: utf-8 -*- A, B, C, D = list(map(int, input().split())) ans = 0 Am = 0 Bm = 0 df = 0 t = 0 def lcm(x, y): return (x * y) // gcd(x, y) def gcd(a, b): while b: a, b = b, a % b return a t = B - A + 1 Am = (A - 1) // C + (A - 1) // D - (A - 1)//lcm(C, D) Bm = B // C + B // D - B // lcm(C, D) ans = t - (Bm - Am) print(ans)
22
22
363
356
# -*- coding: utf-8 -*- A, B, C, D = list(map(int, input().split())) ans = 0 Am = 0 Bm = 0 df = 0 t = 0 def lcm(x, y): return (x * y) // gcd(x, y) def gcd(a, b): while b: a, b = b, a % b return a t = B - A + 1 Am = B // C - (A - 1) // C Bm = B // D - (A - 1) // D df = B // lcm(C, D) - (A - 1) // lcm(C, D) ans = t - (Am + Bm) + df print(ans)
# -*- coding: utf-8 -*- A, B, C, D = list(map(int, input().split())) ans = 0 Am = 0 Bm = 0 df = 0 t = 0 def lcm(x, y): return (x * y) // gcd(x, y) def gcd(a, b): while b: a, b = b, a % b return a t = B - A + 1 Am = (A - 1) // C + (A - 1) // D - (A - 1) // lcm(C, D) Bm = B // C + B // D - B // lcm(C, D) ans = t - (Bm - Am) print(ans)
false
0
[ "-Am = B // C - (A - 1) // C", "-Bm = B // D - (A - 1) // D", "-df = B // lcm(C, D) - (A - 1) // lcm(C, D)", "-ans = t - (Am + Bm) + df", "+Am = (A - 1) // C + (A - 1) // D - (A - 1) // lcm(C, D)", "+Bm = B // C + B // D - B // lcm(C, D)", "+ans = t - (Bm - Am)" ]
false
0.039231
0.046797
0.838326
[ "s795494617", "s589479884" ]
u247211039
p02989
python
s708037231
s513960713
475
105
20,592
20,600
Accepted
Accepted
77.89
N=int(eval(input())) d=list(map(int, input().split())) d=sorted(d) ans=0 for i in range(10**6): if d[int(N/2-1)] < i and i <= d[int(N/2)]: ans +=1 print(ans)
N=int(eval(input())) d=list(map(int, input().split())) d=sorted(d) ans=0 for i in range(1+10**5): if d[int(N/2-1)] < i and i <= d[int(N/2)]: ans +=1 print(ans)
11
11
179
181
N = int(eval(input())) d = list(map(int, input().split())) d = sorted(d) ans = 0 for i in range(10**6): if d[int(N / 2 - 1)] < i and i <= d[int(N / 2)]: ans += 1 print(ans)
N = int(eval(input())) d = list(map(int, input().split())) d = sorted(d) ans = 0 for i in range(1 + 10**5): if d[int(N / 2 - 1)] < i and i <= d[int(N / 2)]: ans += 1 print(ans)
false
0
[ "-for i in range(10**6):", "+for i in range(1 + 10**5):" ]
false
1.329083
0.139414
9.533384
[ "s708037231", "s513960713" ]
u156815136
p04034
python
s650248863
s229224288
356
244
4,596
12,620
Accepted
Accepted
31.46
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from itertools import combinations # (string,3) 3回 #from collections import deque #import collections.defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): n,m = readInts() # 数が入っているのと、 # 箱の中が0かどうかを判別するものを定義する # 全部まず1個入ってる # 赤は最初だけ!!!!!!!! nums = [1] * n In = [False] * n In[0] = True for i in range(m): a,b = [int(x) - 1 for x in input().split()] nums[a] -=1 nums[b] +=1 if In[a]: In[b] = True if nums[a] == 0: In[a] = False cnt = 0 #print(In) for i in range(n): if In[i]: cnt += 1 print(cnt) if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) n,m = readInts() box = [1] * n nya = [True] + [False]*(n-1) for i in range(m): x,y = [int(x)-1 for x in input().split()] # if box[x] < 2: # if nya[x] == True: # if box[x]-1 == 0: # nya[x] = False # nya[y] = True # else: # nya[y] = False # box[x] -= 1 # box[y] += 1 # else: # nya[y] = True # box[x] -= 1 # box[y] += 1 box[x] -= 1 box[y] += 1 if nya[x]: nya[y] = True if box[x] == 0: nya[x] = False print((nya.count(True)))
48
53
1,072
1,266
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from itertools import combinations # (string,3) 3回 # from collections import deque # import collections.defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): n, m = readInts() # 数が入っているのと、 # 箱の中が0かどうかを判別するものを定義する # 全部まず1個入ってる # 赤は最初だけ!!!!!!!! nums = [1] * n In = [False] * n In[0] = True for i in range(m): a, b = [int(x) - 1 for x in input().split()] nums[a] -= 1 nums[b] += 1 if In[a]: In[b] = True if nums[a] == 0: In[a] = False cnt = 0 # print(In) for i in range(n): if In[i]: cnt += 1 print(cnt) if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) n, m = readInts() box = [1] * n nya = [True] + [False] * (n - 1) for i in range(m): x, y = [int(x) - 1 for x in input().split()] # if box[x] < 2: # if nya[x] == True: # if box[x]-1 == 0: # nya[x] = False # nya[y] = True # else: # nya[y] = False # box[x] -= 1 # box[y] += 1 # else: # nya[y] = True # box[x] -= 1 # box[y] += 1 box[x] -= 1 box[y] += 1 if nya[x]: nya[y] = True if box[x] == 0: nya[x] = False print((nya.count(True)))
false
9.433962
[ "-# from itertools import combinations # (string,3) 3回", "+from fractions import gcd", "+from itertools import combinations, permutations, accumulate # (string,3) 3回", "+", "-# import collections.defaultdict", "+from collections import deque, defaultdict, Counter", "+import decimal", "+import re", "+", "-", "-", "+# mod = 9982443453", "-def main():", "- n, m = readInts()", "- # 数が入っているのと、", "- # 箱の中が0かどうかを判別するものを定義する", "- # 全部まず1個入ってる", "- # 赤は最初だけ!!!!!!!!", "- nums = [1] * n", "- In = [False] * n", "- In[0] = True", "- for i in range(m):", "- a, b = [int(x) - 1 for x in input().split()]", "- nums[a] -= 1", "- nums[b] += 1", "- if In[a]:", "- In[b] = True", "- if nums[a] == 0:", "- In[a] = False", "- cnt = 0", "- # print(In)", "- for i in range(n):", "- if In[i]:", "- cnt += 1", "- print(cnt)", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+n, m = readInts()", "+box = [1] * n", "+nya = [True] + [False] * (n - 1)", "+for i in range(m):", "+ x, y = [int(x) - 1 for x in input().split()]", "+ # if box[x] < 2:", "+ # if nya[x] == True:", "+ # if box[x]-1 == 0:", "+ # nya[x] = False", "+ # nya[y] = True", "+ # else:", "+ # nya[y] = False", "+ # box[x] -= 1", "+ # box[y] += 1", "+ # else:", "+ # nya[y] = True", "+ # box[x] -= 1", "+ # box[y] += 1", "+ box[x] -= 1", "+ box[y] += 1", "+ if nya[x]:", "+ nya[y] = True", "+ if box[x] == 0:", "+ nya[x] = False", "+print((nya.count(True)))" ]
false
0.036489
0.035785
1.019687
[ "s650248863", "s229224288" ]
u499381410
p03600
python
s787934732
s516361342
777
541
50,652
44,252
Accepted
Accepted
30.37
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 def warshall_floyd(graph): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): if graph[i][j] > graph[i][k] + graph[k][j]: return 1 n = I() graph = [[INF] * n for _ in range(n)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(n): edges = LI() for j in range(n): graph[i][j] = edges[j] graph[j][i] = edges[j] if warshall_floyd(graph): print((-1)) else: ret = 0 for i in range(n): for j in range(i + 1, n): if i == j: continue for k in range(n): if k != i and k != j and graph[i][k] + graph[k][j] == graph[i][j]: break else: ret += graph[i][j] print(ret)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, atan2 from operator import mul from functools import reduce sys.setrecursionlimit(10 ** 9) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 n = I() G = [] for _ in range(n): G += [LI()] ret = 0 for i in range(n): for j in range(i + 1, n): flag = 1 for k in range(n): if i == k or j == k: continue if G[i][j] > G[i][k] + G[k][j]: print((-1)) exit() elif G[i][j] == G[i][k] + G[k][j]: flag = 0 if flag: ret += G[i][j] print(ret)
63
51
1,646
1,481
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float("inf") def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 def warshall_floyd(graph): # d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): if graph[i][j] > graph[i][k] + graph[k][j]: return 1 n = I() graph = [[INF] * n for _ in range(n)] # d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(n): edges = LI() for j in range(n): graph[i][j] = edges[j] graph[j][i] = edges[j] if warshall_floyd(graph): print((-1)) else: ret = 0 for i in range(n): for j in range(i + 1, n): if i == j: continue for k in range(n): if k != i and k != j and graph[i][k] + graph[k][j] == graph[i][j]: break else: ret += graph[i][j] print(ret)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, atan2 from operator import mul from functools import reduce sys.setrecursionlimit(10**9) INF = 10**20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 n = I() G = [] for _ in range(n): G += [LI()] ret = 0 for i in range(n): for j in range(i + 1, n): flag = 1 for k in range(n): if i == k or j == k: continue if G[i][j] > G[i][k] + G[k][j]: print((-1)) exit() elif G[i][j] == G[i][k] + G[k][j]: flag = 0 if flag: ret += G[i][j] print(ret)
false
19.047619
[ "-from bisect import bisect_left, bisect_right", "+import bisect", "-from itertools import permutations, accumulate, combinations", "+from itertools import permutations, accumulate, combinations, product", "+from bisect import bisect_left, bisect_right", "+from math import factorial, ceil, floor, atan2", "+from operator import mul", "+from functools import reduce", "-INF = float(\"inf\")", "+sys.setrecursionlimit(10**9)", "+INF = 10**20", "- return list(map(int, sys.stdin.readline().split()))", "+ return list(map(int, sys.stdin.buffer.readline().split()))", "- return int(sys.stdin.readline())", "+ return int(sys.stdin.buffer.readline())", "- return sys.stdin.readline().split()", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()", "- return sys.stdin.readline().strip()", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "-", "-", "-def warshall_floyd(graph):", "- # d[i][j]: iからjへの最短距離", "- for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- if graph[i][j] > graph[i][k] + graph[k][j]:", "- return 1", "-", "-", "-graph = [[INF] * n for _ in range(n)]", "-# d[u][v] : 辺uvのコスト(存在しないときはinf)", "+G = []", "+for _ in range(n):", "+ G += [LI()]", "+ret = 0", "- edges = LI()", "- for j in range(n):", "- graph[i][j] = edges[j]", "- graph[j][i] = edges[j]", "-if warshall_floyd(graph):", "- print((-1))", "-else:", "- ret = 0", "- for i in range(n):", "- for j in range(i + 1, n):", "- if i == j:", "+ for j in range(i + 1, n):", "+ flag = 1", "+ for k in range(n):", "+ if i == k or j == k:", "- for k in range(n):", "- if k != i and k != j and graph[i][k] + graph[k][j] == graph[i][j]:", "- break", "- else:", "- ret += graph[i][j]", "- print(ret)", "+ if G[i][j] > G[i][k] + G[k][j]:", "+ print((-1))", "+ exit()", "+ elif G[i][j] == G[i][k] + G[k][j]:", "+ flag = 0", "+ if flag:", "+ ret += G[i][j]", "+print(ret)" ]
false
0.038036
0.037342
1.018601
[ "s787934732", "s516361342" ]
u120106384
p03107
python
s694580451
s540833353
198
183
46,448
39,152
Accepted
Accepted
7.58
def compute(): from sys import stdin S = stdin.readline().strip() wew = [] for x in S: if len(wew)>0 and wew[-1]!=x: wew.pop() else: wew.append(x) print((len(S) - len(wew))) if __name__ == "__main__": compute()
def compute(): from sys import stdin S = stdin.readline().strip() l = len(S) x = S.count("1") y = min(x, l-x) print((y<<1)) if __name__ == "__main__": compute()
15
11
290
199
def compute(): from sys import stdin S = stdin.readline().strip() wew = [] for x in S: if len(wew) > 0 and wew[-1] != x: wew.pop() else: wew.append(x) print((len(S) - len(wew))) if __name__ == "__main__": compute()
def compute(): from sys import stdin S = stdin.readline().strip() l = len(S) x = S.count("1") y = min(x, l - x) print((y << 1)) if __name__ == "__main__": compute()
false
26.666667
[ "- wew = []", "- for x in S:", "- if len(wew) > 0 and wew[-1] != x:", "- wew.pop()", "- else:", "- wew.append(x)", "- print((len(S) - len(wew)))", "+ l = len(S)", "+ x = S.count(\"1\")", "+ y = min(x, l - x)", "+ print((y << 1))" ]
false
0.044161
0.04443
0.99396
[ "s694580451", "s540833353" ]
u046187684
p03339
python
s124842656
s592629042
162
111
21,572
3,672
Accepted
Accepted
31.48
def solve(string): n, s = string.split() n = int(n) es = {i for i, _s in enumerate(s) if _s == "E"} num_e = len(es) count_e = 0 count_w = 0 ans = n for i, _s in enumerate(s): tmp = count_w if i in es: count_e += 1 else: count_w += 1 tmp += num_e - count_e ans = min(ans, tmp) return str(ans) if __name__ == '__main__': print((solve('\n'.join([eval(input()), eval(input())]))))
def solve(string): n, s = string.split() num_e = s.count("E") count_e = 0 count_w = 0 ans = int(n) for _s in s: tmp = count_w if _s == "E": count_e += 1 else: count_w += 1 tmp += num_e - count_e ans = min(ans, tmp) return str(ans) if __name__ == '__main__': print((solve('\n'.join([eval(input()), eval(input())]))))
22
19
491
418
def solve(string): n, s = string.split() n = int(n) es = {i for i, _s in enumerate(s) if _s == "E"} num_e = len(es) count_e = 0 count_w = 0 ans = n for i, _s in enumerate(s): tmp = count_w if i in es: count_e += 1 else: count_w += 1 tmp += num_e - count_e ans = min(ans, tmp) return str(ans) if __name__ == "__main__": print((solve("\n".join([eval(input()), eval(input())]))))
def solve(string): n, s = string.split() num_e = s.count("E") count_e = 0 count_w = 0 ans = int(n) for _s in s: tmp = count_w if _s == "E": count_e += 1 else: count_w += 1 tmp += num_e - count_e ans = min(ans, tmp) return str(ans) if __name__ == "__main__": print((solve("\n".join([eval(input()), eval(input())]))))
false
13.636364
[ "- n = int(n)", "- es = {i for i, _s in enumerate(s) if _s == \"E\"}", "- num_e = len(es)", "+ num_e = s.count(\"E\")", "- ans = n", "- for i, _s in enumerate(s):", "+ ans = int(n)", "+ for _s in s:", "- if i in es:", "+ if _s == \"E\":" ]
false
0.060991
0.044517
1.370084
[ "s124842656", "s592629042" ]
u285436211
p02639
python
s163680163
s308348376
25
22
9,016
9,080
Accepted
Accepted
12
A=[int(_) for _ in input().split()] B=sum(A) S=15-B print(S)
A=[int(_) for _ in input().split()] print((15-sum(A)))
4
2
63
53
A = [int(_) for _ in input().split()] B = sum(A) S = 15 - B print(S)
A = [int(_) for _ in input().split()] print((15 - sum(A)))
false
50
[ "-B = sum(A)", "-S = 15 - B", "-print(S)", "+print((15 - sum(A)))" ]
false
0.041515
0.038496
1.078416
[ "s163680163", "s308348376" ]
u339851548
p02629
python
s478672137
s372546689
162
63
61,604
61,896
Accepted
Accepted
61.11
n = int(eval(input())) eigo = 'abcdefghijklmnopqrstuvwxyz' keta = 1 j = 1 while n > 26**j: n -= 26**j keta += 1 j += 1 n = n-1 ans ='' while keta != 0: a = n //(26**(keta-1)) if a != 0: n = n -(26**(keta-1)*a) ans += eigo[a] else: ans+= eigo[0] keta -= 1 print(ans)
n = int(eval(input())) eigo = 'abcdefghijklmnopqrstuvwxyz' keta = 1 while n > 26**keta: n -= 26**keta keta += 1 ans ='' n = n-1 for i in range(keta): a =n // 26**(keta-1-i) ans += eigo[a] n = n % (26**(keta-1-i)) print(ans)
23
15
337
254
n = int(eval(input())) eigo = "abcdefghijklmnopqrstuvwxyz" keta = 1 j = 1 while n > 26**j: n -= 26**j keta += 1 j += 1 n = n - 1 ans = "" while keta != 0: a = n // (26 ** (keta - 1)) if a != 0: n = n - (26 ** (keta - 1) * a) ans += eigo[a] else: ans += eigo[0] keta -= 1 print(ans)
n = int(eval(input())) eigo = "abcdefghijklmnopqrstuvwxyz" keta = 1 while n > 26**keta: n -= 26**keta keta += 1 ans = "" n = n - 1 for i in range(keta): a = n // 26 ** (keta - 1 - i) ans += eigo[a] n = n % (26 ** (keta - 1 - i)) print(ans)
false
34.782609
[ "-j = 1", "-while n > 26**j:", "- n -= 26**j", "+while n > 26**keta:", "+ n -= 26**keta", "- j += 1", "+ans = \"\"", "-ans = \"\"", "-while keta != 0:", "- a = n // (26 ** (keta - 1))", "- if a != 0:", "- n = n - (26 ** (keta - 1) * a)", "- ans += eigo[a]", "- else:", "- ans += eigo[0]", "- keta -= 1", "+for i in range(keta):", "+ a = n // 26 ** (keta - 1 - i)", "+ ans += eigo[a]", "+ n = n % (26 ** (keta - 1 - i))" ]
false
0.039534
0.111931
0.353201
[ "s478672137", "s372546689" ]
u552176911
p02714
python
s875056784
s887210031
177
135
73,772
73,640
Accepted
Accepted
23.73
import math n = int(eval(input())) s = eval(input()) R, G, B = s.count("R"), s.count("G"), s.count("B") ans = R * G * B for i in range(n): for j in range(n): c1 = i c2 = i + j c3 = i + j * 2 if c3 >= n: continue if c1 == c2 == c3: continue if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]: ans -= 1 print(ans) # 012 024 036 048 # 123 135 147 159
import math n = int(eval(input())) s = eval(input()) R, G, B = s.count("R"), s.count("G"), s.count("B") ans = R * G * B for i in range(n): for j in range(n): c1 = i c2 = i + j c3 = i + j * 2 if c3 >= n: break if c1 == c2 == c3: continue if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]: ans -= 1 print(ans) # 012 024 036 048 # 123 135 147 159
21
21
428
425
import math n = int(eval(input())) s = eval(input()) R, G, B = s.count("R"), s.count("G"), s.count("B") ans = R * G * B for i in range(n): for j in range(n): c1 = i c2 = i + j c3 = i + j * 2 if c3 >= n: continue if c1 == c2 == c3: continue if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]: ans -= 1 print(ans) # 012 024 036 048 # 123 135 147 159
import math n = int(eval(input())) s = eval(input()) R, G, B = s.count("R"), s.count("G"), s.count("B") ans = R * G * B for i in range(n): for j in range(n): c1 = i c2 = i + j c3 = i + j * 2 if c3 >= n: break if c1 == c2 == c3: continue if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]: ans -= 1 print(ans) # 012 024 036 048 # 123 135 147 159
false
0
[ "- continue", "+ break" ]
false
0.109421
0.044834
2.44059
[ "s875056784", "s887210031" ]
u107077660
p04011
python
s377016813
s740556639
37
24
3,064
3,064
Accepted
Accepted
35.14
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N > K: a = X * K + Y * (N - K) else: a = X * N print(a)
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N <= K: print((X*N)) else: ans = X*K + Y*(N-K) print(ans)
9
9
136
137
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N > K: a = X * K + Y * (N - K) else: a = X * N print(a)
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N <= K: print((X * N)) else: ans = X * K + Y * (N - K) print(ans)
false
0
[ "-if N > K:", "- a = X * K + Y * (N - K)", "+if N <= K:", "+ print((X * N))", "- a = X * N", "-print(a)", "+ ans = X * K + Y * (N - K)", "+ print(ans)" ]
false
0.037653
0.04256
0.8847
[ "s377016813", "s740556639" ]
u111473084
p02781
python
s736757052
s959169896
24
19
3,572
3,064
Accepted
Accepted
20.83
def main(): import sys input = sys.stdin.readline N = list(map(int, list(input()[:-1]))) K = int(eval(input())) L = len(N) # dp[i][j][k] # i 桁目まで決めて # j 個の非0を使って # k = 0 : そこまでの桁はNと一致 # k = 1 : そこまでの桁でN未満であることが確定 dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)] dp[0][0][0] = 1 from pprint import pprint for i, x in enumerate(N): for k in range(K + 1): # 桁ごと数え上げ if x == 0: # x == 0 dp[i + 1][k][0] += dp[i][k][0] else: # x == 0 dp[i + 1][k][1] += dp[i][k][0] # 0 < n < x dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1) # n == x dp[i + 1][k + 1][0] += dp[i][k][0] # N未満で次の桁に1~9を入れる dp[i + 1][k + 1][1] += dp[i][k][1] * 9 # N未満で次の桁に0を入れる dp[i + 1][k][1] += dp[i][k][1] print((sum(dp[L][K]))) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.readline N = list(map(int, list(input()[:-1]))) K = int(eval(input())) L = len(N) # dp[i][j][k] # i 桁目まで決めて # j 個の非0を使って # k = 0 : そこまでの桁はNと一致 # k = 1 : そこまでの桁でN未満であることが確定 dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)] dp[0][0][0] = 1 for i, x in enumerate(N): for k in range(K + 1): # 桁ごと数え上げ if x == 0: # x == 0 dp[i + 1][k][0] += dp[i][k][0] else: # x == 0 dp[i + 1][k][1] += dp[i][k][0] # 0 < n < x dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1) # n == x dp[i + 1][k + 1][0] += dp[i][k][0] # N未満で次の桁に1~9を入れる dp[i + 1][k + 1][1] += dp[i][k][1] * 9 # N未満で次の桁に0を入れる dp[i + 1][k][1] += dp[i][k][1] print((sum(dp[L][K]))) if __name__ == '__main__': main()
39
38
1,055
1,024
def main(): import sys input = sys.stdin.readline N = list(map(int, list(input()[:-1]))) K = int(eval(input())) L = len(N) # dp[i][j][k] # i 桁目まで決めて # j 個の非0を使って # k = 0 : そこまでの桁はNと一致 # k = 1 : そこまでの桁でN未満であることが確定 dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)] dp[0][0][0] = 1 from pprint import pprint for i, x in enumerate(N): for k in range(K + 1): # 桁ごと数え上げ if x == 0: # x == 0 dp[i + 1][k][0] += dp[i][k][0] else: # x == 0 dp[i + 1][k][1] += dp[i][k][0] # 0 < n < x dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1) # n == x dp[i + 1][k + 1][0] += dp[i][k][0] # N未満で次の桁に1~9を入れる dp[i + 1][k + 1][1] += dp[i][k][1] * 9 # N未満で次の桁に0を入れる dp[i + 1][k][1] += dp[i][k][1] print((sum(dp[L][K]))) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.readline N = list(map(int, list(input()[:-1]))) K = int(eval(input())) L = len(N) # dp[i][j][k] # i 桁目まで決めて # j 個の非0を使って # k = 0 : そこまでの桁はNと一致 # k = 1 : そこまでの桁でN未満であることが確定 dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)] dp[0][0][0] = 1 for i, x in enumerate(N): for k in range(K + 1): # 桁ごと数え上げ if x == 0: # x == 0 dp[i + 1][k][0] += dp[i][k][0] else: # x == 0 dp[i + 1][k][1] += dp[i][k][0] # 0 < n < x dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1) # n == x dp[i + 1][k + 1][0] += dp[i][k][0] # N未満で次の桁に1~9を入れる dp[i + 1][k + 1][1] += dp[i][k][1] * 9 # N未満で次の桁に0を入れる dp[i + 1][k][1] += dp[i][k][1] print((sum(dp[L][K]))) if __name__ == "__main__": main()
false
2.564103
[ "- from pprint import pprint", "-" ]
false
0.037621
0.035598
1.056827
[ "s736757052", "s959169896" ]
u528470578
p03103
python
s122389344
s393413616
452
286
29,024
29,180
Accepted
Accepted
36.73
N, M = list(map(int, input().split())) AB = [] for i in range(N): AB.append(list(map(int, input().split()))) AB.sort(key=lambda x:x[0]) kane = 0 hon = 0 for i in range(N): if hon + AB[i][1] < M: hon += AB[i][1] kane += AB[i][0] * AB[i][1] continue elif hon + AB[i][1] == M: hon += AB[i][1] kane += AB[i][0] * AB[i][1] print(kane) break else: kane += (M - hon) * AB[i][0] print(kane) break
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB = sorted(AB, key=lambda x:x[0]) ans = 0 for a, b in AB: if b <= M: ans += a * b M -= b else: ans += a * M break if M == 0: break print(ans)
23
14
506
295
N, M = list(map(int, input().split())) AB = [] for i in range(N): AB.append(list(map(int, input().split()))) AB.sort(key=lambda x: x[0]) kane = 0 hon = 0 for i in range(N): if hon + AB[i][1] < M: hon += AB[i][1] kane += AB[i][0] * AB[i][1] continue elif hon + AB[i][1] == M: hon += AB[i][1] kane += AB[i][0] * AB[i][1] print(kane) break else: kane += (M - hon) * AB[i][0] print(kane) break
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB = sorted(AB, key=lambda x: x[0]) ans = 0 for a, b in AB: if b <= M: ans += a * b M -= b else: ans += a * M break if M == 0: break print(ans)
false
39.130435
[ "-AB = []", "-for i in range(N):", "- AB.append(list(map(int, input().split())))", "-AB.sort(key=lambda x: x[0])", "-kane = 0", "-hon = 0", "-for i in range(N):", "- if hon + AB[i][1] < M:", "- hon += AB[i][1]", "- kane += AB[i][0] * AB[i][1]", "- continue", "- elif hon + AB[i][1] == M:", "- hon += AB[i][1]", "- kane += AB[i][0] * AB[i][1]", "- print(kane)", "+AB = [list(map(int, input().split())) for _ in range(N)]", "+AB = sorted(AB, key=lambda x: x[0])", "+ans = 0", "+for a, b in AB:", "+ if b <= M:", "+ ans += a * b", "+ M -= b", "+ else:", "+ ans += a * M", "- else:", "- kane += (M - hon) * AB[i][0]", "- print(kane)", "+ if M == 0:", "+print(ans)" ]
false
0.067861
0.068039
0.997385
[ "s122389344", "s393413616" ]
u562935282
p03171
python
s502940325
s593480389
614
532
162,952
179,804
Accepted
Accepted
13.36
n = int(eval(input())) a = tuple(int(x) for x in input().split()) memo = tuple([None] * n for _ in range(n)) for i in range(n): memo[i][i] = a[i] for l in range(n - 2, -1, -1): for r in range(l + 1, n): memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1]) print((memo[0][n - 1])) # [l,r]を # l:=配列aの右端から左にシフト # r:=lと一致する位置からn-1まで右にシフト # と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい # 漸化式で使う値は、 # lがより右にいるときの計算結果(前のループで計算済み)と # rがより左にいるときの計算結果(一番左でもl==rなので計算済み) # なので、参照する値がNoneになることはなく、Noneのチェックは不要になる # if __name__ == '__main__':を辞めた
def main(): n = int(eval(input())) a = tuple(int(x) for x in input().split()) memo = tuple([None] * n for _ in range(n)) for i in range(n): memo[i][i] = a[i] for l in range(n - 2, -1, -1): for r in range(l + 1, n): memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1]) print((memo[0][n - 1])) if __name__ == '__main__': main() # [l,r]を # l:=配列aの右端から左にシフト # r:=lと一致する位置からn-1まで右にシフト # と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい # 漸化式で使う値は、 # lがより右にいるときの計算結果(前のループで計算済み)と # rがより左にいるときの計算結果(一番左でもl==rなので計算済み) # なので、参照する値がNoneになることはなく、Noneのチェックは不要になる # 関数名は関係あるのか?
23
28
579
653
n = int(eval(input())) a = tuple(int(x) for x in input().split()) memo = tuple([None] * n for _ in range(n)) for i in range(n): memo[i][i] = a[i] for l in range(n - 2, -1, -1): for r in range(l + 1, n): memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1]) print((memo[0][n - 1])) # [l,r]を # l:=配列aの右端から左にシフト # r:=lと一致する位置からn-1まで右にシフト # と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい # 漸化式で使う値は、 # lがより右にいるときの計算結果(前のループで計算済み)と # rがより左にいるときの計算結果(一番左でもl==rなので計算済み) # なので、参照する値がNoneになることはなく、Noneのチェックは不要になる # if __name__ == '__main__':を辞めた
def main(): n = int(eval(input())) a = tuple(int(x) for x in input().split()) memo = tuple([None] * n for _ in range(n)) for i in range(n): memo[i][i] = a[i] for l in range(n - 2, -1, -1): for r in range(l + 1, n): memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1]) print((memo[0][n - 1])) if __name__ == "__main__": main() # [l,r]を # l:=配列aの右端から左にシフト # r:=lと一致する位置からn-1まで右にシフト # と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい # 漸化式で使う値は、 # lがより右にいるときの計算結果(前のループで計算済み)と # rがより左にいるときの計算結果(一番左でもl==rなので計算済み) # なので、参照する値がNoneになることはなく、Noneのチェックは不要になる # 関数名は関係あるのか?
false
17.857143
[ "-n = int(eval(input()))", "-a = tuple(int(x) for x in input().split())", "-memo = tuple([None] * n for _ in range(n))", "-for i in range(n):", "- memo[i][i] = a[i]", "-for l in range(n - 2, -1, -1):", "- for r in range(l + 1, n):", "- memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1])", "-print((memo[0][n - 1]))", "+def main():", "+ n = int(eval(input()))", "+ a = tuple(int(x) for x in input().split())", "+ memo = tuple([None] * n for _ in range(n))", "+ for i in range(n):", "+ memo[i][i] = a[i]", "+ for l in range(n - 2, -1, -1):", "+ for r in range(l + 1, n):", "+ memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1])", "+ print((memo[0][n - 1]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()", "-# if __name__ == '__main__':を辞めた", "+# 関数名は関係あるのか?" ]
false
0.038448
0.034947
1.100173
[ "s502940325", "s593480389" ]
u673361376
p03417
python
s174126859
s374851537
176
17
38,384
2,940
Accepted
Accepted
90.34
N,M = list(map(int,input().split())) if N == 1 and M == 1: print((1)) elif N == 1: print((M-2)) elif M == 1: print((N-2)) else: print(((M-2)*(N-2)))
N, M = list(map(int, input().split())) if N == 1 and M == 1: print((1)) elif N == 1 and M != 1: print((M - 2)) elif M == 1 and N != 1: print((N - 2)) else: print(((N - 2) * (M - 2)))
5
9
138
193
N, M = list(map(int, input().split())) if N == 1 and M == 1: print((1)) elif N == 1: print((M - 2)) elif M == 1: print((N - 2)) else: print(((M - 2) * (N - 2)))
N, M = list(map(int, input().split())) if N == 1 and M == 1: print((1)) elif N == 1 and M != 1: print((M - 2)) elif M == 1 and N != 1: print((N - 2)) else: print(((N - 2) * (M - 2)))
false
44.444444
[ "-elif N == 1:", "+elif N == 1 and M != 1:", "-elif M == 1:", "+elif M == 1 and N != 1:", "- print(((M - 2) * (N - 2)))", "+ print(((N - 2) * (M - 2)))" ]
false
0.084086
0.038483
2.185014
[ "s174126859", "s374851537" ]
u732412551
p03221
python
s048375123
s906831428
763
616
43,060
32,892
Accepted
Accepted
19.27
from operator import itemgetter N, M = map(int, input().split()) PY = sorted(((i, tuple(map(int, input().split()))) for i in range(M)), key=itemgetter(1)) L = [] prev, x = 0, 1 for i, (p, _y) in PY: if p == prev: x += 1 else: prev = p x = 1 L.append((i, "{:06d}{:06d}".format(p, x))) L.sort() print(*[l for _, l in L], sep="\n")
N,M=list(map(int, input().split())) PY=[tuple(map(int, input().split()))for _ in range(M)] ans=[None]*M I=sorted(list(range(M)),key=lambda i: PY[i][1]) C=[0]*(N+1) for i in I: p=PY[i][0] C[p]+=1 ans[i]=(p,C[p]) def f(x): s=str(x) return "0"*(6-len(s))+s for p,c in ans: print((f(p)+f(c)))
14
14
377
311
from operator import itemgetter N, M = map(int, input().split()) PY = sorted( ((i, tuple(map(int, input().split()))) for i in range(M)), key=itemgetter(1) ) L = [] prev, x = 0, 1 for i, (p, _y) in PY: if p == prev: x += 1 else: prev = p x = 1 L.append((i, "{:06d}{:06d}".format(p, x))) L.sort() print(*[l for _, l in L], sep="\n")
N, M = list(map(int, input().split())) PY = [tuple(map(int, input().split())) for _ in range(M)] ans = [None] * M I = sorted(list(range(M)), key=lambda i: PY[i][1]) C = [0] * (N + 1) for i in I: p = PY[i][0] C[p] += 1 ans[i] = (p, C[p]) def f(x): s = str(x) return "0" * (6 - len(s)) + s for p, c in ans: print((f(p) + f(c)))
false
0
[ "-from operator import itemgetter", "+N, M = list(map(int, input().split()))", "+PY = [tuple(map(int, input().split())) for _ in range(M)]", "+ans = [None] * M", "+I = sorted(list(range(M)), key=lambda i: PY[i][1])", "+C = [0] * (N + 1)", "+for i in I:", "+ p = PY[i][0]", "+ C[p] += 1", "+ ans[i] = (p, C[p])", "-N, M = map(int, input().split())", "-PY = sorted(", "- ((i, tuple(map(int, input().split()))) for i in range(M)), key=itemgetter(1)", "-)", "-L = []", "-prev, x = 0, 1", "-for i, (p, _y) in PY:", "- if p == prev:", "- x += 1", "- else:", "- prev = p", "- x = 1", "- L.append((i, \"{:06d}{:06d}\".format(p, x)))", "-L.sort()", "-print(*[l for _, l in L], sep=\"\\n\")", "+", "+def f(x):", "+ s = str(x)", "+ return \"0\" * (6 - len(s)) + s", "+", "+", "+for p, c in ans:", "+ print((f(p) + f(c)))" ]
false
0.044297
0.083725
0.52908
[ "s048375123", "s906831428" ]
u325282913
p02936
python
s443360668
s092539129
1,552
1,397
230,960
228,020
Accepted
Accepted
9.99
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] point = [0]*N for i in range(N-1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for i in range(Q): p, x = list(map(int, input().split())) point[p-1] += x def dfs(s,parent): for i in graph[s]: if i == parent: continue point[i] += point[s] dfs(i,s) dfs(0,-1) print((*point))
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) edges = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) Query = [0]*N for _ in range(Q): p, x = list(map(int, input().split())) Query[p-1] += x ans = [0]*N past = [0]*N def dfs(start,point): past[start] = 1 point = point + Query[start] ans[start] = point for target in edges[start]: if past[target] == 0: dfs(target,point) dfs(0,0) print((*ans))
23
23
525
571
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] point = [0] * N for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) for i in range(Q): p, x = list(map(int, input().split())) point[p - 1] += x def dfs(s, parent): for i in graph[s]: if i == parent: continue point[i] += point[s] dfs(i, s) dfs(0, -1) print((*point))
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) edges = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) Query = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) Query[p - 1] += x ans = [0] * N past = [0] * N def dfs(start, point): past[start] = 1 point = point + Query[start] ans[start] = point for target in edges[start]: if past[target] == 0: dfs(target, point) dfs(0, 0) print((*ans))
false
0
[ "-input = sys.stdin.readline", "-graph = [[] for _ in range(N)]", "-point = [0] * N", "-for i in range(N - 1):", "+edges = [[] for _ in range(N)]", "+for _ in range(N - 1):", "- a -= 1", "- b -= 1", "- graph[a].append(b)", "- graph[b].append(a)", "-for i in range(Q):", "+ edges[a - 1].append(b - 1)", "+ edges[b - 1].append(a - 1)", "+Query = [0] * N", "+for _ in range(Q):", "- point[p - 1] += x", "+ Query[p - 1] += x", "+ans = [0] * N", "+past = [0] * N", "-def dfs(s, parent):", "- for i in graph[s]:", "- if i == parent:", "- continue", "- point[i] += point[s]", "- dfs(i, s)", "+def dfs(start, point):", "+ past[start] = 1", "+ point = point + Query[start]", "+ ans[start] = point", "+ for target in edges[start]:", "+ if past[target] == 0:", "+ dfs(target, point)", "-dfs(0, -1)", "-print((*point))", "+dfs(0, 0)", "+print((*ans))" ]
false
0.048978
0.047591
1.029132
[ "s443360668", "s092539129" ]
u729133443
p03032
python
s093172084
s480554125
213
31
41,324
3,060
Accepted
Accepted
85.45
n,k,*v=list(map(int,open(0).read().split())) m=0 r=range for i in r(n+1): for j in r(min(k-i+1,n-i+1)): t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j while t and c and t[-1]<0:t.pop();c-=1 m=max(m,sum(t)) print(m)
n,k,*v=list(map(int,open(0).read().split())) m=0 r=range for i in r(n+1): for j in r(min(k-i+1,n-i+1)): t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j while t and c*t[-1]<0:t.pop();c-=1 m=max(m,sum(t)) print(m)
9
9
219
215
n, k, *v = list(map(int, open(0).read().split())) m = 0 r = range for i in r(n + 1): for j in r(min(k - i + 1, n - i + 1)): t = sorted(v[:i] + v[-j:] * (j > 0))[::-1] c = k - i - j while t and c and t[-1] < 0: t.pop() c -= 1 m = max(m, sum(t)) print(m)
n, k, *v = list(map(int, open(0).read().split())) m = 0 r = range for i in r(n + 1): for j in r(min(k - i + 1, n - i + 1)): t = sorted(v[:i] + v[-j:] * (j > 0))[::-1] c = k - i - j while t and c * t[-1] < 0: t.pop() c -= 1 m = max(m, sum(t)) print(m)
false
0
[ "- while t and c and t[-1] < 0:", "+ while t and c * t[-1] < 0:" ]
false
0.040807
0.036052
1.131879
[ "s093172084", "s480554125" ]
u046187684
p03148
python
s591373001
s251770460
336
300
26,784
26,876
Accepted
Accepted
10.71
def solve(string): n, k, *td = list(map(int, string.split())) td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True) max_variety = len(set([c[0] for c in td])) choice = td[:k] count = [0] * n for _c in choice: count[_c[0] - 1] += 1 variety = set([c[0] for c in choice]) ans = [len(variety)**2 + sum([c[1] for c in choice])] i_remove, i_append = k - 1, k while len(variety) < min(max_variety, k): while td[i_append][0] in variety: i_append += 1 while count[td[i_remove][0] - 1] == 1: i_remove -= 1 variety.add(td[i_append][0]) count[td[i_remove][0] - 1] -= 1 ans.append(ans[-1] - td[i_remove][1] + td[i_append][1] + 2 * len(variety) - 1) i_remove -= 1 i_append += 1 return str(max(ans)) if __name__ == '__main__': n, m = list(map(int, input().split())) print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
def solve(string): n, k, *td = list(map(int, string.split())) td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True) max_variety = len(set([c[0] for c in td])) choice = td[:k] r = [] variety = set([]) base = 0 for _c in choice: base += _c[1] if _c[0] in variety: r.append(_c[1]) else: variety.add(_c[0]) base += len(variety)**2 i = k ans = [base] while len(variety) < min(max_variety, k): while td[i][0] in variety: i += 1 variety.add(td[i][0]) ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(variety) - 1) return str(max(ans)) if __name__ == '__main__': n, m = list(map(int, input().split())) print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
27
28
1,022
871
def solve(string): n, k, *td = list(map(int, string.split())) td = sorted( [(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True ) max_variety = len(set([c[0] for c in td])) choice = td[:k] count = [0] * n for _c in choice: count[_c[0] - 1] += 1 variety = set([c[0] for c in choice]) ans = [len(variety) ** 2 + sum([c[1] for c in choice])] i_remove, i_append = k - 1, k while len(variety) < min(max_variety, k): while td[i_append][0] in variety: i_append += 1 while count[td[i_remove][0] - 1] == 1: i_remove -= 1 variety.add(td[i_append][0]) count[td[i_remove][0] - 1] -= 1 ans.append(ans[-1] - td[i_remove][1] + td[i_append][1] + 2 * len(variety) - 1) i_remove -= 1 i_append += 1 return str(max(ans)) if __name__ == "__main__": n, m = list(map(int, input().split())) print( (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) )
def solve(string): n, k, *td = list(map(int, string.split())) td = sorted( [(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True ) max_variety = len(set([c[0] for c in td])) choice = td[:k] r = [] variety = set([]) base = 0 for _c in choice: base += _c[1] if _c[0] in variety: r.append(_c[1]) else: variety.add(_c[0]) base += len(variety) ** 2 i = k ans = [base] while len(variety) < min(max_variety, k): while td[i][0] in variety: i += 1 variety.add(td[i][0]) ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(variety) - 1) return str(max(ans)) if __name__ == "__main__": n, m = list(map(int, input().split())) print( (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) )
false
3.571429
[ "- count = [0] * n", "+ r = []", "+ variety = set([])", "+ base = 0", "- count[_c[0] - 1] += 1", "- variety = set([c[0] for c in choice])", "- ans = [len(variety) ** 2 + sum([c[1] for c in choice])]", "- i_remove, i_append = k - 1, k", "+ base += _c[1]", "+ if _c[0] in variety:", "+ r.append(_c[1])", "+ else:", "+ variety.add(_c[0])", "+ base += len(variety) ** 2", "+ i = k", "+ ans = [base]", "- while td[i_append][0] in variety:", "- i_append += 1", "- while count[td[i_remove][0] - 1] == 1:", "- i_remove -= 1", "- variety.add(td[i_append][0])", "- count[td[i_remove][0] - 1] -= 1", "- ans.append(ans[-1] - td[i_remove][1] + td[i_append][1] + 2 * len(variety) - 1)", "- i_remove -= 1", "- i_append += 1", "+ while td[i][0] in variety:", "+ i += 1", "+ variety.add(td[i][0])", "+ ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(variety) - 1)" ]
false
0.045074
0.044804
1.006017
[ "s591373001", "s251770460" ]
u410269178
p03044
python
s520355324
s737491620
914
783
45,368
46,512
Accepted
Accepted
14.33
from collections import deque n = int(eval(input())) to = [[] for _ in range(n)] for i in range(n-1): u, v, w = list(map(int, input().split())) u , v = u-1, v-1 to[u].append([v, w]) to[v].append([u, w]) color = [-1] * n color[0] = False q = deque([0]) while q: v = q.popleft() for u, w in to[v]: if color[u] != -1: continue if w % 2 != 0: color[u] = color[v] ^ 1 else: color[u] = color[v] q.append(u) for c in color: print((int(c)))
from collections import deque n = int(eval(input())) to = [[] for _ in range(n)] for i in range(n-1): u, v, w = list(map(int, input().split())) u , v = u-1, v-1 to[u].append([v, w]) to[v].append([u, w]) color = [-1] * n color[0] = 0 q = deque([0]) while q: v = q.popleft() for u, w in to[v]: if color[u] != -1: continue if w % 2 != 0: color[u] = color[v] ^ 1 else: color[u] = color[v] q.append(u) for c in color: print(c)
23
23
536
527
from collections import deque n = int(eval(input())) to = [[] for _ in range(n)] for i in range(n - 1): u, v, w = list(map(int, input().split())) u, v = u - 1, v - 1 to[u].append([v, w]) to[v].append([u, w]) color = [-1] * n color[0] = False q = deque([0]) while q: v = q.popleft() for u, w in to[v]: if color[u] != -1: continue if w % 2 != 0: color[u] = color[v] ^ 1 else: color[u] = color[v] q.append(u) for c in color: print((int(c)))
from collections import deque n = int(eval(input())) to = [[] for _ in range(n)] for i in range(n - 1): u, v, w = list(map(int, input().split())) u, v = u - 1, v - 1 to[u].append([v, w]) to[v].append([u, w]) color = [-1] * n color[0] = 0 q = deque([0]) while q: v = q.popleft() for u, w in to[v]: if color[u] != -1: continue if w % 2 != 0: color[u] = color[v] ^ 1 else: color[u] = color[v] q.append(u) for c in color: print(c)
false
0
[ "-color[0] = False", "+color[0] = 0", "- print((int(c)))", "+ print(c)" ]
false
0.048461
0.107963
0.448868
[ "s520355324", "s737491620" ]
u197955752
p02983
python
s502566423
s857213923
736
61
2,940
3,060
Accepted
Accepted
91.71
L, R = [int(x) for x in input().split()] if R - L >= 2018: ans = 0 else: ans = 2018 for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, i * j % 2019) print(ans)
L, R = [int(x) for x in input().split()] if R - L >= 2018: ans = 0 else: ans = 2018 for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, i * j % 2019) if ans == 0: break else: continue break print(ans)
11
15
219
304
L, R = [int(x) for x in input().split()] if R - L >= 2018: ans = 0 else: ans = 2018 for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, i * j % 2019) print(ans)
L, R = [int(x) for x in input().split()] if R - L >= 2018: ans = 0 else: ans = 2018 for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, i * j % 2019) if ans == 0: break else: continue break print(ans)
false
26.666667
[ "+ if ans == 0:", "+ break", "+ else:", "+ continue", "+ break" ]
false
0.053299
0.037516
1.420715
[ "s502566423", "s857213923" ]
u761320129
p03739
python
s976656543
s254938361
117
100
14,468
19,960
Accepted
Accepted
14.53
N = int(eval(input())) A = list(map(int,input().split())) ans1 = c = 0 for i,a in enumerate(A): c += a if i%2: if c < 1: ans1 += 1-c c = 1 else: if c > -1: ans1 += c+1 c = -1 ans2 = c = 0 for i,a in enumerate(A): c += a if i%2==0: if c < 1: ans2 += 1-c c = 1 else: if c > -1: ans2 += c+1 c = -1 print((min(ans1,ans2)))
N = int(eval(input())) A = list(map(int,input().split())) ans1 = 0 s = 0 for i,a in enumerate(A): s += a if i%2: if s > -1: ans1 += s+1 s = -1 else: if s < 1: ans1 += 1-s s = 1 ans2 = 0 s = 0 for i,a in enumerate(A): s += a if i%2==0: if s > -1: ans2 += s+1 s = -1 else: if s < 1: ans2 += 1-s s = 1 print((min(ans1, ans2)))
28
30
492
499
N = int(eval(input())) A = list(map(int, input().split())) ans1 = c = 0 for i, a in enumerate(A): c += a if i % 2: if c < 1: ans1 += 1 - c c = 1 else: if c > -1: ans1 += c + 1 c = -1 ans2 = c = 0 for i, a in enumerate(A): c += a if i % 2 == 0: if c < 1: ans2 += 1 - c c = 1 else: if c > -1: ans2 += c + 1 c = -1 print((min(ans1, ans2)))
N = int(eval(input())) A = list(map(int, input().split())) ans1 = 0 s = 0 for i, a in enumerate(A): s += a if i % 2: if s > -1: ans1 += s + 1 s = -1 else: if s < 1: ans1 += 1 - s s = 1 ans2 = 0 s = 0 for i, a in enumerate(A): s += a if i % 2 == 0: if s > -1: ans2 += s + 1 s = -1 else: if s < 1: ans2 += 1 - s s = 1 print((min(ans1, ans2)))
false
6.666667
[ "-ans1 = c = 0", "+ans1 = 0", "+s = 0", "- c += a", "+ s += a", "- if c < 1:", "- ans1 += 1 - c", "- c = 1", "+ if s > -1:", "+ ans1 += s + 1", "+ s = -1", "- if c > -1:", "- ans1 += c + 1", "- c = -1", "-ans2 = c = 0", "+ if s < 1:", "+ ans1 += 1 - s", "+ s = 1", "+ans2 = 0", "+s = 0", "- c += a", "+ s += a", "- if c < 1:", "- ans2 += 1 - c", "- c = 1", "+ if s > -1:", "+ ans2 += s + 1", "+ s = -1", "- if c > -1:", "- ans2 += c + 1", "- c = -1", "+ if s < 1:", "+ ans2 += 1 - s", "+ s = 1" ]
false
0.036475
0.082942
0.439766
[ "s976656543", "s254938361" ]
u297089927
p02548
python
s874028292
s665231921
1,318
162
16,700
8,980
Accepted
Accepted
87.71
def num_divisors_table(n): table = [0] * (n + 1) for i in range(1, n + 1): for j in range(i, n + 1, i): table[j] += 1 return table n=int(eval(input())) print((sum(num_divisors_table(n-1))))
n=int(eval(input())) ans=0 for i in range(1,n): ans+=(n-1)//i print(ans)
10
5
233
72
def num_divisors_table(n): table = [0] * (n + 1) for i in range(1, n + 1): for j in range(i, n + 1, i): table[j] += 1 return table n = int(eval(input())) print((sum(num_divisors_table(n - 1))))
n = int(eval(input())) ans = 0 for i in range(1, n): ans += (n - 1) // i print(ans)
false
50
[ "-def num_divisors_table(n):", "- table = [0] * (n + 1)", "- for i in range(1, n + 1):", "- for j in range(i, n + 1, i):", "- table[j] += 1", "- return table", "-", "-", "-print((sum(num_divisors_table(n - 1))))", "+ans = 0", "+for i in range(1, n):", "+ ans += (n - 1) // i", "+print(ans)" ]
false
0.306871
0.079296
3.86996
[ "s874028292", "s665231921" ]
u847467233
p00267
python
s937118897
s009821304
800
660
13,480
14,260
Accepted
Accepted
17.5
# AOJ 0272: The Lonely Girl's Lie # Python3 2018.6.26 bal4u while True: n = int(eval(input())) if n == 0: break a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) ans, i = n, -1 for k in range(0, n, 2): i += 1 if a[k] > b[i]: ans = k + 1 break print(("NA" if ans == n else ans))
# AOJ 0272: The Lonely Girl's Lie # Python3 2018.6.26 bal4u def counting_sort(nmax, la): # nmax:最大値, n:len(la), a:データリスト f = [0]*(nmax+1) nmax = 0 for a in la: f[a] += 1 if a > nmax: nmax = a k, i = len(la), nmax la = [] while k: if f[i]: la += [i]*f[i] k -= f[i] i -= 1 return la while True: n = int(eval(input())) if n == 0: break a = list(map(int, input().split())) b = list(map(int, input().split())) a = counting_sort(100000, a) b = counting_sort(100000, b) ans, i = n, -1 for k in range(0, n, 2): i += 1 if a[k] > b[i]: ans = k + 1 break print(("NA" if ans == n else ans))
17
33
370
648
# AOJ 0272: The Lonely Girl's Lie # Python3 2018.6.26 bal4u while True: n = int(eval(input())) if n == 0: break a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) ans, i = n, -1 for k in range(0, n, 2): i += 1 if a[k] > b[i]: ans = k + 1 break print(("NA" if ans == n else ans))
# AOJ 0272: The Lonely Girl's Lie # Python3 2018.6.26 bal4u def counting_sort(nmax, la): # nmax:最大値, n:len(la), a:データリスト f = [0] * (nmax + 1) nmax = 0 for a in la: f[a] += 1 if a > nmax: nmax = a k, i = len(la), nmax la = [] while k: if f[i]: la += [i] * f[i] k -= f[i] i -= 1 return la while True: n = int(eval(input())) if n == 0: break a = list(map(int, input().split())) b = list(map(int, input().split())) a = counting_sort(100000, a) b = counting_sort(100000, b) ans, i = n, -1 for k in range(0, n, 2): i += 1 if a[k] > b[i]: ans = k + 1 break print(("NA" if ans == n else ans))
false
48.484848
[ "+def counting_sort(nmax, la): # nmax:最大値, n:len(la), a:データリスト", "+ f = [0] * (nmax + 1)", "+ nmax = 0", "+ for a in la:", "+ f[a] += 1", "+ if a > nmax:", "+ nmax = a", "+ k, i = len(la), nmax", "+ la = []", "+ while k:", "+ if f[i]:", "+ la += [i] * f[i]", "+ k -= f[i]", "+ i -= 1", "+ return la", "+", "+", "- a.sort(reverse=True)", "- b.sort(reverse=True)", "+ a = counting_sort(100000, a)", "+ b = counting_sort(100000, b)" ]
false
0.043285
0.037603
1.151108
[ "s937118897", "s009821304" ]
u585482323
p03568
python
s432131331
s476734766
202
181
39,408
39,920
Accepted
Accepted
10.4
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() s = [2 if i&1 else 1 for i in a] ans = 0 for b in range((1<<n)-1): res = 1 for i in range(n): res *= (s[i]<<(b>>i))%3 ans += res print(ans) return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() s = [2 if i&1 else 1 for i in a] ans = 0 for b in range(1,1<<n): res = 1 c = 0 for i in range(n): if b&(1<<i): res *= s[i] c ^= 1 else: res *= 3 ans += (2*c-1)*res print(ans) return #Solve if __name__ == "__main__": solve()
43
48
1,046
1,154
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() s = [2 if i & 1 else 1 for i in a] ans = 0 for b in range((1 << n) - 1): res = 1 for i in range(n): res *= (s[i] << (b >> i)) % 3 ans += res print(ans) return # Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() s = [2 if i & 1 else 1 for i in a] ans = 0 for b in range(1, 1 << n): res = 1 c = 0 for i in range(n): if b & (1 << i): res *= s[i] c ^= 1 else: res *= 3 ans += (2 * c - 1) * res print(ans) return # Solve if __name__ == "__main__": solve()
false
10.416667
[ "- for b in range((1 << n) - 1):", "+ for b in range(1, 1 << n):", "+ c = 0", "- res *= (s[i] << (b >> i)) % 3", "- ans += res", "+ if b & (1 << i):", "+ res *= s[i]", "+ c ^= 1", "+ else:", "+ res *= 3", "+ ans += (2 * c - 1) * res" ]
false
0.04859
0.047526
1.022392
[ "s432131331", "s476734766" ]
u619274787
p03456
python
s748972009
s282551170
28
17
2,940
3,060
Accepted
Accepted
39.29
x = int(input().replace(' ', '')) for i in range(x): if i*i == x: print('Yes') exit() print('No')
x = int(input().replace(' ', '')) print(('Yes' if x in [i*i for i in range(1000)] else 'No'))
6
2
122
92
x = int(input().replace(" ", "")) for i in range(x): if i * i == x: print("Yes") exit() print("No")
x = int(input().replace(" ", "")) print(("Yes" if x in [i * i for i in range(1000)] else "No"))
false
66.666667
[ "-for i in range(x):", "- if i * i == x:", "- print(\"Yes\")", "- exit()", "-print(\"No\")", "+print((\"Yes\" if x in [i * i for i in range(1000)] else \"No\"))" ]
false
0.044094
0.039228
1.124047
[ "s748972009", "s282551170" ]
u857428111
p03048
python
s919561094
s654682851
347
292
40,812
39,408
Accepted
Accepted
15.85
#入力(後でいじる) def pin(type=int): return list(map(type,input().split())) #どっかで最悪計算量の入力データを用意する関数を作ろう? """ O(N^2) """ #solution: #潜 影 蛇 手 ! ! *c,N=pin() ans=0 I=(N//c[0])+1 J=N//c[1]+1 for i in range(I): for j in range(J): remain=(N-i*c[0]-j*c[1]) if remain>=0 and remain%c[2]==0: ans+=1 print(ans) #print(["NO","YES"][1-cond]) #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#print#!/usr/bin/env python3 #%% for atcoder uniittest use import sys input= lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int):return list(map(type,input().split())) def tupin(t=int):return tuple(pin(t)) def lispin(t=int):return list(pin(t)) #%%code def resolve(): R,G,B,N=pin() cnt=0 for r in range(N+1): for g in range(N+1): t=(R*r+G*g) if N<t:continue if (N-t)%B==0: #print(r,g,t) cnt+=1 print(cnt) #%%submit! resolve()
28
23
476
571
# 入力(後でいじる) def pin(type=int): return list(map(type, input().split())) # どっかで最悪計算量の入力データを用意する関数を作ろう? """ O(N^2) """ # solution: # 潜 影 蛇 手 ! ! *c, N = pin() ans = 0 I = (N // c[0]) + 1 J = N // c[1] + 1 for i in range(I): for j in range(J): remain = N - i * c[0] - j * c[1] if remain >= 0 and remain % c[2] == 0: ans += 1 print(ans) # print(["NO","YES"][1-cond]) # print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
# print#!/usr/bin/env python3 #%% for atcoder uniittest use import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int): return list(map(type, input().split())) def tupin(t=int): return tuple(pin(t)) def lispin(t=int): return list(pin(t)) #%%code def resolve(): R, G, B, N = pin() cnt = 0 for r in range(N + 1): for g in range(N + 1): t = R * r + G * g if N < t: continue if (N - t) % B == 0: # print(r,g,t) cnt += 1 print(cnt) #%%submit! resolve()
false
17.857143
[ "-# 入力(後でいじる)", "+# print#!/usr/bin/env python3", "+#%% for atcoder uniittest use", "+import sys", "+", "+input = lambda: sys.stdin.readline().rstrip()", "+sys.setrecursionlimit(10**9)", "+", "+", "-# どっかで最悪計算量の入力データを用意する関数を作ろう?", "-\"\"\"", "-O(N^2)", "-\"\"\"", "-# solution:", "-# 潜 影 蛇 手 ! !", "-*c, N = pin()", "-ans = 0", "-I = (N // c[0]) + 1", "-J = N // c[1] + 1", "-for i in range(I):", "- for j in range(J):", "- remain = N - i * c[0] - j * c[1]", "- if remain >= 0 and remain % c[2] == 0:", "- ans += 1", "-print(ans)", "-# print([\"NO\",\"YES\"][1-cond])", "-# print([[\"NA\",\"YYMM\"],[\"MMYY\",\"AMBIGUOUS\"]][cMMYY][cYYMM])", "+def tupin(t=int):", "+ return tuple(pin(t))", "+", "+", "+def lispin(t=int):", "+ return list(pin(t))", "+", "+", "+#%%code", "+def resolve():", "+ R, G, B, N = pin()", "+ cnt = 0", "+ for r in range(N + 1):", "+ for g in range(N + 1):", "+ t = R * r + G * g", "+ if N < t:", "+ continue", "+ if (N - t) % B == 0:", "+ # print(r,g,t)", "+ cnt += 1", "+ print(cnt)", "+", "+", "+#%%submit!", "+resolve()" ]
false
0.265805
0.896417
0.296519
[ "s919561094", "s654682851" ]
u230717961
p03495
python
s792372419
s469632184
270
191
40,956
32,532
Accepted
Accepted
29.26
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 key_num = len(list(counter.keys())) if key_num > k: tmp = sorted(list(counter.items()), key=lambda x: x[1]) ans = sum([v for k, v in tmp[: key_num - k]]) else: ans = 0 return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 tmp = sorted(list(counter.values()), reverse=True) ans = n - sum(tmp[:k]) return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
21
17
507
390
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 key_num = len(list(counter.keys())) if key_num > k: tmp = sorted(list(counter.items()), key=lambda x: x[1]) ans = sum([v for k, v in tmp[: key_num - k]]) else: ans = 0 return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 tmp = sorted(list(counter.values()), reverse=True) ans = n - sum(tmp[:k]) return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
false
19.047619
[ "- key_num = len(list(counter.keys()))", "- if key_num > k:", "- tmp = sorted(list(counter.items()), key=lambda x: x[1])", "- ans = sum([v for k, v in tmp[: key_num - k]])", "- else:", "- ans = 0", "+ tmp = sorted(list(counter.values()), reverse=True)", "+ ans = n - sum(tmp[:k])" ]
false
0.129078
0.038371
3.363914
[ "s792372419", "s469632184" ]
u843768197
p04043
python
s180143803
s666507632
31
22
8,860
9,060
Accepted
Accepted
29.03
l = list(map(int, input().split())) l.sort(reverse=True) if l[0] == 7 and l[1] == 5 and l[2] == 5: print('YES') else: print('NO')
a = list(map(int, input().split())) cnt_5 = 0 cnt_7 = 0 for i in a: if i == 5: cnt_5 += 1 if i == 7: cnt_7 += 1 if cnt_5 == 2 and cnt_7 == 1: print('YES') else: print('NO')
6
14
138
209
l = list(map(int, input().split())) l.sort(reverse=True) if l[0] == 7 and l[1] == 5 and l[2] == 5: print("YES") else: print("NO")
a = list(map(int, input().split())) cnt_5 = 0 cnt_7 = 0 for i in a: if i == 5: cnt_5 += 1 if i == 7: cnt_7 += 1 if cnt_5 == 2 and cnt_7 == 1: print("YES") else: print("NO")
false
57.142857
[ "-l = list(map(int, input().split()))", "-l.sort(reverse=True)", "-if l[0] == 7 and l[1] == 5 and l[2] == 5:", "+a = list(map(int, input().split()))", "+cnt_5 = 0", "+cnt_7 = 0", "+for i in a:", "+ if i == 5:", "+ cnt_5 += 1", "+ if i == 7:", "+ cnt_7 += 1", "+if cnt_5 == 2 and cnt_7 == 1:" ]
false
0.037393
0.036394
1.027443
[ "s180143803", "s666507632" ]
u898967808
p03162
python
s252209138
s689946554
657
581
58,968
52,340
Accepted
Accepted
11.57
n = int(eval(input())) abc=[[0,0,0]]*n dp = [[0]*n for _ in range(3)] for i in range(n): abc[i] = list(map(int,input().split())) for i in range(3): dp[i][0] = abc[0][i] for i in range(1,n): for j in range(3): for k in range(3): if j==k: pass else: dp[j][i] = max(dp[j][i], dp[k][i-1]+abc[i][j]) print((max([row[-1] for row in dp])))
n = int(eval(input())) abc=[[]]*n dp = [[0]*3 for _ in range(n)] for i in range(n): abc[i] = list(map(int,input().split())) for i in range(3): dp[0][i] = abc[0][i] for i in range(1,n): dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + abc[i][0] dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + abc[i][1] dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + abc[i][2] print((max(dp[-1])))
19
16
406
396
n = int(eval(input())) abc = [[0, 0, 0]] * n dp = [[0] * n for _ in range(3)] for i in range(n): abc[i] = list(map(int, input().split())) for i in range(3): dp[i][0] = abc[0][i] for i in range(1, n): for j in range(3): for k in range(3): if j == k: pass else: dp[j][i] = max(dp[j][i], dp[k][i - 1] + abc[i][j]) print((max([row[-1] for row in dp])))
n = int(eval(input())) abc = [[]] * n dp = [[0] * 3 for _ in range(n)] for i in range(n): abc[i] = list(map(int, input().split())) for i in range(3): dp[0][i] = abc[0][i] for i in range(1, n): dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + abc[i][0] dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + abc[i][1] dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + abc[i][2] print((max(dp[-1])))
false
15.789474
[ "-abc = [[0, 0, 0]] * n", "-dp = [[0] * n for _ in range(3)]", "+abc = [[]] * n", "+dp = [[0] * 3 for _ in range(n)]", "- dp[i][0] = abc[0][i]", "+ dp[0][i] = abc[0][i]", "- for j in range(3):", "- for k in range(3):", "- if j == k:", "- pass", "- else:", "- dp[j][i] = max(dp[j][i], dp[k][i - 1] + abc[i][j])", "-print((max([row[-1] for row in dp])))", "+ dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + abc[i][0]", "+ dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + abc[i][1]", "+ dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + abc[i][2]", "+print((max(dp[-1])))" ]
false
0.040431
0.038329
1.054846
[ "s252209138", "s689946554" ]
u506858457
p03673
python
s563809029
s831021917
181
163
26,020
26,020
Accepted
Accepted
9.94
n = int(eval(input())) A = list(map(int,input().split())) answer = A[1::2][::-1]+A[::2] if n%2==1: answer=answer[::-1] print((*answer))
N=int(input()) A=list(map(int,input().split())) print(*A[::-2],end=' ') print(*A[N%2::2])
6
4
137
92
n = int(eval(input())) A = list(map(int, input().split())) answer = A[1::2][::-1] + A[::2] if n % 2 == 1: answer = answer[::-1] print((*answer))
N = int(input()) A = list(map(int, input().split())) print(*A[::-2], end=" ") print(*A[N % 2 :: 2])
false
33.333333
[ "-n = int(eval(input()))", "+N = int(input())", "-answer = A[1::2][::-1] + A[::2]", "-if n % 2 == 1:", "- answer = answer[::-1]", "-print((*answer))", "+print(*A[::-2], end=\" \")", "+print(*A[N % 2 :: 2])" ]
false
0.049287
0.048513
1.015949
[ "s563809029", "s831021917" ]
u271934630
p02713
python
s229346362
s127139156
1,756
1,325
71,520
9,236
Accepted
Accepted
24.54
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) import math i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() K = i_i() res = sum([math.gcd(math.gcd(a, b), c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1)]) print(res)
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) import math i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() K = i_i() ans = 0 ab = [] for a in range(1, K+1): for b in range(1, K+1): ab.append(math.gcd(a,b)) for c in range(1, K+1): for x in ab: ans += math.gcd(c,x) print(ans)
13
20
334
406
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) import math i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() K = i_i() res = sum( [ math.gcd(math.gcd(a, b), c) for a in range(1, K + 1) for b in range(1, K + 1) for c in range(1, K + 1) ] ) print(res)
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) import math i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() K = i_i() ans = 0 ab = [] for a in range(1, K + 1): for b in range(1, K + 1): ab.append(math.gcd(a, b)) for c in range(1, K + 1): for x in ab: ans += math.gcd(c, x) print(ans)
false
35
[ "-res = sum(", "- [", "- math.gcd(math.gcd(a, b), c)", "- for a in range(1, K + 1)", "- for b in range(1, K + 1)", "- for c in range(1, K + 1)", "- ]", "-)", "-print(res)", "+ans = 0", "+ab = []", "+for a in range(1, K + 1):", "+ for b in range(1, K + 1):", "+ ab.append(math.gcd(a, b))", "+for c in range(1, K + 1):", "+ for x in ab:", "+ ans += math.gcd(c, x)", "+print(ans)" ]
false
0.042019
0.12652
0.332117
[ "s229346362", "s127139156" ]
u130900604
p02690
python
s977325376
s506826852
64
58
64,576
63,820
Accepted
Accepted
9.38
x=int(eval(input())) for a in range(-200,200): for b in range(-200,200): if a**5-b**5==x: print((a,b)) exit()
x=int(eval(input())) for a in range(200): for b in range(-200,a): if a**5-b**5==x: print((a,b)) exit()
6
6
124
118
x = int(eval(input())) for a in range(-200, 200): for b in range(-200, 200): if a**5 - b**5 == x: print((a, b)) exit()
x = int(eval(input())) for a in range(200): for b in range(-200, a): if a**5 - b**5 == x: print((a, b)) exit()
false
0
[ "-for a in range(-200, 200):", "- for b in range(-200, 200):", "+for a in range(200):", "+ for b in range(-200, a):" ]
false
0.115469
0.044296
2.606787
[ "s977325376", "s506826852" ]
u445624660
p02831
python
s189491970
s941822310
305
26
66,028
9,092
Accepted
Accepted
91.48
# 最小公倍数 import fractions a, b = list(map(int, input().split())) def lcm(x, y): return (x * y) // fractions.gcd(x, y) print((lcm(a, b)))
a, b = list(map(int, input().split())) def gcd(a, b): if a > b: a, b = b, a while a > 0: a, b = b % a, a return b def lcm(a, b): return (a * b) // gcd(a, b) print((lcm(a, b)))
11
16
147
221
# 最小公倍数 import fractions a, b = list(map(int, input().split())) def lcm(x, y): return (x * y) // fractions.gcd(x, y) print((lcm(a, b)))
a, b = list(map(int, input().split())) def gcd(a, b): if a > b: a, b = b, a while a > 0: a, b = b % a, a return b def lcm(a, b): return (a * b) // gcd(a, b) print((lcm(a, b)))
false
31.25
[ "-# 最小公倍数", "-import fractions", "-", "-def lcm(x, y):", "- return (x * y) // fractions.gcd(x, y)", "+def gcd(a, b):", "+ if a > b:", "+ a, b = b, a", "+ while a > 0:", "+ a, b = b % a, a", "+ return b", "+", "+", "+def lcm(a, b):", "+ return (a * b) // gcd(a, b)" ]
false
0.088621
0.034045
2.603052
[ "s189491970", "s941822310" ]
u556594202
p02629
python
s919343667
s401373800
29
26
9,172
9,068
Accepted
Accepted
10.34
import math # one = 1000000000000001 dict={1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i",10:"j", 11:"k",12:"l",13:"m",14:"n",15:"o",16:"p",17:"q",18:"r",19:"s",20:"t", 21:"u",22:"v",23:"w",24:"x",25:"y",26:"z"} n=int(eval(input())) ans = str(dict[(n-1)%26+1]) n=(n-1)//26 while n: ans = str(dict[(n-1)%26+1]) + ans n=(n-1)//26 print(ans)
import math # one = 1000000000000001 dict={1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i",10:"j", 11:"k",12:"l",13:"m",14:"n",15:"o",16:"p",17:"q",18:"r",19:"s",20:"t", 21:"u",22:"v",23:"w",24:"x",25:"y",26:"z"} n=int(eval(input())) ans = "" while n: ans = str(dict[(n-1)%26+1]) + ans n=(n-1)//26 print(ans)
17
15
385
351
import math # one = 1000000000000001 dict = { 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h", 9: "i", 10: "j", 11: "k", 12: "l", 13: "m", 14: "n", 15: "o", 16: "p", 17: "q", 18: "r", 19: "s", 20: "t", 21: "u", 22: "v", 23: "w", 24: "x", 25: "y", 26: "z", } n = int(eval(input())) ans = str(dict[(n - 1) % 26 + 1]) n = (n - 1) // 26 while n: ans = str(dict[(n - 1) % 26 + 1]) + ans n = (n - 1) // 26 print(ans)
import math # one = 1000000000000001 dict = { 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h", 9: "i", 10: "j", 11: "k", 12: "l", 13: "m", 14: "n", 15: "o", 16: "p", 17: "q", 18: "r", 19: "s", 20: "t", 21: "u", 22: "v", 23: "w", 24: "x", 25: "y", 26: "z", } n = int(eval(input())) ans = "" while n: ans = str(dict[(n - 1) % 26 + 1]) + ans n = (n - 1) // 26 print(ans)
false
11.764706
[ "-ans = str(dict[(n - 1) % 26 + 1])", "-n = (n - 1) // 26", "+ans = \"\"" ]
false
0.036476
0.043699
0.834712
[ "s919343667", "s401373800" ]
u288944922
p03160
python
s031355129
s956967457
170
122
95,492
20,528
Accepted
Accepted
28.24
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) h = list(map(int, input().split())) dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト dp[N-1] = 0 def rec_memo(i): if dp[i] >= 0: return dp[i] if i == N-2: dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i]) return dp[i] else: dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i])) return dp[i] print((rec_memo(0)))
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) h = list(map(int, input().split())) dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト dp[N-1] = 0 for i in reversed(list(range(N - 1))): if i == N - 2: dp[i] = dp[i + 1] + abs(h[i + 1] - h[i]) else: dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i])) print((dp[0]))
21
16
470
384
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) h = list(map(int, input().split())) dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト dp[N - 1] = 0 def rec_memo(i): if dp[i] >= 0: return dp[i] if i == N - 2: dp[i] = rec_memo(i + 1) + abs(h[i + 1] - h[i]) return dp[i] else: dp[i] = min( rec_memo(i + 1) + abs(h[i + 1] - h[i]), rec_memo(i + 2) + abs(h[i + 2] - h[i]), ) return dp[i] print((rec_memo(0)))
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) h = list(map(int, input().split())) dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト dp[N - 1] = 0 for i in reversed(list(range(N - 1))): if i == N - 2: dp[i] = dp[i + 1] + abs(h[i + 1] - h[i]) else: dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i])) print((dp[0]))
false
23.809524
[ "-", "-", "-def rec_memo(i):", "- if dp[i] >= 0:", "- return dp[i]", "+for i in reversed(list(range(N - 1))):", "- dp[i] = rec_memo(i + 1) + abs(h[i + 1] - h[i])", "- return dp[i]", "+ dp[i] = dp[i + 1] + abs(h[i + 1] - h[i])", "- dp[i] = min(", "- rec_memo(i + 1) + abs(h[i + 1] - h[i]),", "- rec_memo(i + 2) + abs(h[i + 2] - h[i]),", "- )", "- return dp[i]", "-", "-", "-print((rec_memo(0)))", "+ dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i]))", "+print((dp[0]))" ]
false
0.048965
0.047947
1.021233
[ "s031355129", "s956967457" ]
u806403461
p02639
python
s785179407
s626892611
24
20
9,180
9,088
Accepted
Accepted
16.67
x = list(map(int, input().split())) for a in range(5): if x[a] == 0: print((a+1)) break
x = list(map(int, input().split())) print((15 - sum(x)))
6
2
112
56
x = list(map(int, input().split())) for a in range(5): if x[a] == 0: print((a + 1)) break
x = list(map(int, input().split())) print((15 - sum(x)))
false
66.666667
[ "-for a in range(5):", "- if x[a] == 0:", "- print((a + 1))", "- break", "+print((15 - sum(x)))" ]
false
0.138121
0.040243
3.432151
[ "s785179407", "s626892611" ]
u698176039
p03425
python
s570145853
s330881378
198
166
9,772
10,132
Accepted
Accepted
16.16
N = int(eval(input())) S = [eval(input()) for _ in range(N)] MARCH = [0] * 5 for i in range(N): if S[i][0] == 'M' : MARCH[0] += 1 if S[i][0] == 'A' : MARCH[1] += 1 if S[i][0] == 'R' : MARCH[2] += 1 if S[i][0] == 'C' : MARCH[3] += 1 if S[i][0] == 'H' : MARCH[4] += 1 ans = 0 for i in range(3): for j in range(i+1,4): for k in range(j+1,5): ans += MARCH[i] * MARCH[j] * MARCH[k] print(ans)
N = int(eval(input())) S = [eval(input()) for _ in range(N)] mydict = {'M':1,'A':2,'R':3,'C':4,'H':5} count = [0] * 6 for i in range(N): s = S[i][0] if s in mydict: count[mydict[s]] += 1 ans = 0 for i in range(1,6): for j in range(i+1,6): if i==j:continue for k in range(j+1,6): if i==k or j == k:continue ans += count[i] * count[j] * count[k] print(ans)
19
22
462
477
N = int(eval(input())) S = [eval(input()) for _ in range(N)] MARCH = [0] * 5 for i in range(N): if S[i][0] == "M": MARCH[0] += 1 if S[i][0] == "A": MARCH[1] += 1 if S[i][0] == "R": MARCH[2] += 1 if S[i][0] == "C": MARCH[3] += 1 if S[i][0] == "H": MARCH[4] += 1 ans = 0 for i in range(3): for j in range(i + 1, 4): for k in range(j + 1, 5): ans += MARCH[i] * MARCH[j] * MARCH[k] print(ans)
N = int(eval(input())) S = [eval(input()) for _ in range(N)] mydict = {"M": 1, "A": 2, "R": 3, "C": 4, "H": 5} count = [0] * 6 for i in range(N): s = S[i][0] if s in mydict: count[mydict[s]] += 1 ans = 0 for i in range(1, 6): for j in range(i + 1, 6): if i == j: continue for k in range(j + 1, 6): if i == k or j == k: continue ans += count[i] * count[j] * count[k] print(ans)
false
13.636364
[ "-MARCH = [0] * 5", "+mydict = {\"M\": 1, \"A\": 2, \"R\": 3, \"C\": 4, \"H\": 5}", "+count = [0] * 6", "- if S[i][0] == \"M\":", "- MARCH[0] += 1", "- if S[i][0] == \"A\":", "- MARCH[1] += 1", "- if S[i][0] == \"R\":", "- MARCH[2] += 1", "- if S[i][0] == \"C\":", "- MARCH[3] += 1", "- if S[i][0] == \"H\":", "- MARCH[4] += 1", "+ s = S[i][0]", "+ if s in mydict:", "+ count[mydict[s]] += 1", "-for i in range(3):", "- for j in range(i + 1, 4):", "- for k in range(j + 1, 5):", "- ans += MARCH[i] * MARCH[j] * MARCH[k]", "+for i in range(1, 6):", "+ for j in range(i + 1, 6):", "+ if i == j:", "+ continue", "+ for k in range(j + 1, 6):", "+ if i == k or j == k:", "+ continue", "+ ans += count[i] * count[j] * count[k]" ]
false
0.053496
0.062912
0.850321
[ "s570145853", "s330881378" ]
u110580875
p02571
python
s664522184
s422994580
65
47
9,056
9,120
Accepted
Accepted
27.69
s = eval(input()) t = eval(input()) fans = 100000000 for i in range(len(s) - len(t) + 1): ans = 0 for j in range(len(t)): if (s[i+j] == t[j]): pass else: ans += 1 fans = min(fans, ans) print(fans)
s=eval(input()) t=eval(input()) lent=len(t) num=lent ls=[] count=0 for i in range(len(s)-lent+1): st=s[i:i+num] num+=1 for j in range(lent): if st[j]!=t[j]: count+=1 ls.append(count) count=0 print((min(ls)))
14
19
251
245
s = eval(input()) t = eval(input()) fans = 100000000 for i in range(len(s) - len(t) + 1): ans = 0 for j in range(len(t)): if s[i + j] == t[j]: pass else: ans += 1 fans = min(fans, ans) print(fans)
s = eval(input()) t = eval(input()) lent = len(t) num = lent ls = [] count = 0 for i in range(len(s) - lent + 1): st = s[i : i + num] num += 1 for j in range(lent): if st[j] != t[j]: count += 1 ls.append(count) count = 0 print((min(ls)))
false
26.315789
[ "-fans = 100000000", "-for i in range(len(s) - len(t) + 1):", "- ans = 0", "- for j in range(len(t)):", "- if s[i + j] == t[j]:", "- pass", "- else:", "- ans += 1", "- fans = min(fans, ans)", "-print(fans)", "+lent = len(t)", "+num = lent", "+ls = []", "+count = 0", "+for i in range(len(s) - lent + 1):", "+ st = s[i : i + num]", "+ num += 1", "+ for j in range(lent):", "+ if st[j] != t[j]:", "+ count += 1", "+ ls.append(count)", "+ count = 0", "+print((min(ls)))" ]
false
0.041911
0.038625
1.085083
[ "s664522184", "s422994580" ]
u644907318
p03426
python
s023434437
s826785706
1,141
508
75,996
111,296
Accepted
Accepted
55.48
def dist(x,y): return abs(x[0]-y[0])+abs(x[1]-y[1]) H,W,D = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(H)] G = {} for i in range(H): for j in range(W): G[A[i][j]] = (i,j) C = {} for j in range(1,D+1): k = 1 C[j] = 0 while j+k*D<=H*W: C[j+k*D] = C[j+(k-1)*D]+dist(G[j+(k-1)*D],G[j+k*D]) k += 1 Q = int(eval(input())) for _ in range(Q): L,R = list(map(int,input().split())) print((C[R]-C[L]))
H,W,D = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(H)] C = {i:0 for i in range(1,H*W+1)} for i in range(H): for j in range(W): C[A[i][j]] = (i,j) dist = {i:[] for i in range(1,D+1)} for i in range(1,D+1): dist[i].append(0) y0,x0 = C[i] for j in range(1,(H*W-i)//D+1): y1,x1 = C[i+j*D] dist[i].append(dist[i][-1]+abs(y1-y0)+abs(x1-x0)) y0 = y1 x0 = x1 Q = int(eval(input())) for _ in range(Q): L,R = list(map(int,input().split())) i = L%D if i==0: i = D j1 = (L-i)//D j2 = (R-i)//D print((dist[i][j2]-dist[i][j1]))
19
24
479
643
def dist(x, y): return abs(x[0] - y[0]) + abs(x[1] - y[1]) H, W, D = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(H)] G = {} for i in range(H): for j in range(W): G[A[i][j]] = (i, j) C = {} for j in range(1, D + 1): k = 1 C[j] = 0 while j + k * D <= H * W: C[j + k * D] = C[j + (k - 1) * D] + dist(G[j + (k - 1) * D], G[j + k * D]) k += 1 Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) print((C[R] - C[L]))
H, W, D = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(H)] C = {i: 0 for i in range(1, H * W + 1)} for i in range(H): for j in range(W): C[A[i][j]] = (i, j) dist = {i: [] for i in range(1, D + 1)} for i in range(1, D + 1): dist[i].append(0) y0, x0 = C[i] for j in range(1, (H * W - i) // D + 1): y1, x1 = C[i + j * D] dist[i].append(dist[i][-1] + abs(y1 - y0) + abs(x1 - x0)) y0 = y1 x0 = x1 Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) i = L % D if i == 0: i = D j1 = (L - i) // D j2 = (R - i) // D print((dist[i][j2] - dist[i][j1]))
false
20.833333
[ "-def dist(x, y):", "- return abs(x[0] - y[0]) + abs(x[1] - y[1])", "-", "-", "-G = {}", "+C = {i: 0 for i in range(1, H * W + 1)}", "- G[A[i][j]] = (i, j)", "-C = {}", "-for j in range(1, D + 1):", "- k = 1", "- C[j] = 0", "- while j + k * D <= H * W:", "- C[j + k * D] = C[j + (k - 1) * D] + dist(G[j + (k - 1) * D], G[j + k * D])", "- k += 1", "+ C[A[i][j]] = (i, j)", "+dist = {i: [] for i in range(1, D + 1)}", "+for i in range(1, D + 1):", "+ dist[i].append(0)", "+ y0, x0 = C[i]", "+ for j in range(1, (H * W - i) // D + 1):", "+ y1, x1 = C[i + j * D]", "+ dist[i].append(dist[i][-1] + abs(y1 - y0) + abs(x1 - x0))", "+ y0 = y1", "+ x0 = x1", "- print((C[R] - C[L]))", "+ i = L % D", "+ if i == 0:", "+ i = D", "+ j1 = (L - i) // D", "+ j2 = (R - i) // D", "+ print((dist[i][j2] - dist[i][j1]))" ]
false
0.035455
0.042846
0.827514
[ "s023434437", "s826785706" ]
u811817592
p02756
python
s048636034
s924045205
449
408
4,596
4,596
Accepted
Accepted
9.13
# -*- coding: utf-8 -*- S = str(eval(input())) Q = int(eval(input())) rev_flag = 1 head_str = "" tail_str = "" for _ in range(Q): query = str(eval(input())) # contains spaces if query[0] == "1": rev_flag *= -1 else: h_or_t_flag = 1 if query[2] == "1" else -1 h_or_t_flag *= rev_flag if h_or_t_flag == 1: head_str += query[4] else: tail_str += query[4] ans = head_str[::-1] + S + tail_str print((ans if rev_flag == 1 else ans[::-1]))
# -*- coding: utf-8 -*- S = str(eval(input())) Q = int(eval(input())) rev_flag = 1 head_str = "" tail_str = "" for _ in range(Q): query = eval(input()) # contains spaces if query[0] == "1": rev_flag *= -1 else: h_or_t_flag = 1 if query[2] == "1" else -1 h_or_t_flag *= rev_flag if h_or_t_flag == 1: head_str += query[4] else: tail_str += query[4] ans = head_str[::-1] + S + tail_str print((ans if rev_flag == 1 else ans[::-1]))
22
22
520
515
# -*- coding: utf-8 -*- S = str(eval(input())) Q = int(eval(input())) rev_flag = 1 head_str = "" tail_str = "" for _ in range(Q): query = str(eval(input())) # contains spaces if query[0] == "1": rev_flag *= -1 else: h_or_t_flag = 1 if query[2] == "1" else -1 h_or_t_flag *= rev_flag if h_or_t_flag == 1: head_str += query[4] else: tail_str += query[4] ans = head_str[::-1] + S + tail_str print((ans if rev_flag == 1 else ans[::-1]))
# -*- coding: utf-8 -*- S = str(eval(input())) Q = int(eval(input())) rev_flag = 1 head_str = "" tail_str = "" for _ in range(Q): query = eval(input()) # contains spaces if query[0] == "1": rev_flag *= -1 else: h_or_t_flag = 1 if query[2] == "1" else -1 h_or_t_flag *= rev_flag if h_or_t_flag == 1: head_str += query[4] else: tail_str += query[4] ans = head_str[::-1] + S + tail_str print((ans if rev_flag == 1 else ans[::-1]))
false
0
[ "- query = str(eval(input())) # contains spaces", "+ query = eval(input()) # contains spaces" ]
false
0.035257
0.044035
0.800663
[ "s048636034", "s924045205" ]
u072717685
p02683
python
s925587962
s106882726
84
66
11,780
11,340
Accepted
Accepted
21.43
from itertools import combinations from copy import deepcopy def main(): n, m, x = list(map(int, input().split())) books = [] for _ in range(n): books.append(list(map(int, input().split()))) books_pattern = [] books_num = [i for i in range(n)] for i1 in range(1, n + 1): books_pattern += list(combinations(books_num, i1)) skill_set = [] for ebp in books_pattern: skill_pattern = [0] * (m + 1) for ebpe in ebp: book_e = books[ebpe] for i2 in range(m + 1): skill_pattern[i2] += book_e[i2] skill_set.append(skill_pattern) skill_set_ok = [] for ess in skill_set: tess = deepcopy(ess[1:]) tessc = [i for i in tess if i >= x] if len(tessc) == m: skill_set_ok.append(ess[0]) if len(skill_set_ok) > 0: print((min(skill_set_ok))) else: print((-1)) if __name__ == '__main__': main()
def main(): n, m, x = list(map(int, input().split())) books = [] for _ in range(n): books.append(tuple(map(int, input().split()))) books_set_all = [] for bit in range(1<<n): books_set = [0] * (m + 1) for i in range(n): mask = 1 << i if bit & mask: for i2 in range(m + 1): books_set[i2] += books[i][i2] books_set_all.append(books_set) price_all = [] for ebs in books_set_all: price = ebs[0] ebs[0] = x if len([j for j in ebs if j >= x]) == m + 1: price_all.append(price) if len(price_all) > 0: print((min(price_all))) else: print((-1)) if __name__ == '__main__': main()
39
30
993
776
from itertools import combinations from copy import deepcopy def main(): n, m, x = list(map(int, input().split())) books = [] for _ in range(n): books.append(list(map(int, input().split()))) books_pattern = [] books_num = [i for i in range(n)] for i1 in range(1, n + 1): books_pattern += list(combinations(books_num, i1)) skill_set = [] for ebp in books_pattern: skill_pattern = [0] * (m + 1) for ebpe in ebp: book_e = books[ebpe] for i2 in range(m + 1): skill_pattern[i2] += book_e[i2] skill_set.append(skill_pattern) skill_set_ok = [] for ess in skill_set: tess = deepcopy(ess[1:]) tessc = [i for i in tess if i >= x] if len(tessc) == m: skill_set_ok.append(ess[0]) if len(skill_set_ok) > 0: print((min(skill_set_ok))) else: print((-1)) if __name__ == "__main__": main()
def main(): n, m, x = list(map(int, input().split())) books = [] for _ in range(n): books.append(tuple(map(int, input().split()))) books_set_all = [] for bit in range(1 << n): books_set = [0] * (m + 1) for i in range(n): mask = 1 << i if bit & mask: for i2 in range(m + 1): books_set[i2] += books[i][i2] books_set_all.append(books_set) price_all = [] for ebs in books_set_all: price = ebs[0] ebs[0] = x if len([j for j in ebs if j >= x]) == m + 1: price_all.append(price) if len(price_all) > 0: print((min(price_all))) else: print((-1)) if __name__ == "__main__": main()
false
23.076923
[ "-from itertools import combinations", "-from copy import deepcopy", "-", "-", "- books.append(list(map(int, input().split())))", "- books_pattern = []", "- books_num = [i for i in range(n)]", "- for i1 in range(1, n + 1):", "- books_pattern += list(combinations(books_num, i1))", "- skill_set = []", "- for ebp in books_pattern:", "- skill_pattern = [0] * (m + 1)", "- for ebpe in ebp:", "- book_e = books[ebpe]", "- for i2 in range(m + 1):", "- skill_pattern[i2] += book_e[i2]", "- skill_set.append(skill_pattern)", "- skill_set_ok = []", "- for ess in skill_set:", "- tess = deepcopy(ess[1:])", "- tessc = [i for i in tess if i >= x]", "- if len(tessc) == m:", "- skill_set_ok.append(ess[0])", "- if len(skill_set_ok) > 0:", "- print((min(skill_set_ok)))", "+ books.append(tuple(map(int, input().split())))", "+ books_set_all = []", "+ for bit in range(1 << n):", "+ books_set = [0] * (m + 1)", "+ for i in range(n):", "+ mask = 1 << i", "+ if bit & mask:", "+ for i2 in range(m + 1):", "+ books_set[i2] += books[i][i2]", "+ books_set_all.append(books_set)", "+ price_all = []", "+ for ebs in books_set_all:", "+ price = ebs[0]", "+ ebs[0] = x", "+ if len([j for j in ebs if j >= x]) == m + 1:", "+ price_all.append(price)", "+ if len(price_all) > 0:", "+ print((min(price_all)))" ]
false
0.04185
0.040052
1.0449
[ "s925587962", "s106882726" ]
u941407962
p02883
python
s976572967
s396668479
1,614
704
123,340
123,384
Accepted
Accepted
56.38
import math N,K=list(map(int,input().split())) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] m,M,i=0,10**12,1 exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);"*50) print(M)
N,K=list(map(int,input().split())) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] m,M,i=0,2**40,1 exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);"*50) print(M)
6
5
282
260
import math N, K = list(map(int, input().split())) X = [ (b, a * b) for a, b in zip( sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1], ) ] m, M, i = 0, 10**12, 1 exec( "i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);" * 50 ) print(M)
N, K = list(map(int, input().split())) X = [ (b, a * b) for a, b in zip( sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1], ) ] m, M, i = 0, 2**40, 1 exec( "i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);" * 50 ) print(M)
false
16.666667
[ "-import math", "-", "-m, M, i = 0, 10**12, 1", "+m, M, i = 0, 2**40, 1", "- \"i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);\"", "+ \"i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);\"" ]
false
0.083951
0.039824
2.108041
[ "s976572967", "s396668479" ]
u888092736
p03331
python
s777430695
s161122017
260
150
9,072
9,000
Accepted
Accepted
42.31
def digits_sum(n): return sum(int(c) for c in str(n)) N = int(eval(input())) ans = float("inf") for i in range(1, N): A = i B = N - i ans = min(ans, digits_sum(A) + digits_sum(B)) print(ans)
def digit_sum(x): res = 0 while x > 0: res += x % 10 x //= 10 return res N = int(eval(input())) ans = N for i in range(1, N): A = i B = N - i ans = min(ans, digit_sum(A) + digit_sum(B)) print(ans)
11
15
213
247
def digits_sum(n): return sum(int(c) for c in str(n)) N = int(eval(input())) ans = float("inf") for i in range(1, N): A = i B = N - i ans = min(ans, digits_sum(A) + digits_sum(B)) print(ans)
def digit_sum(x): res = 0 while x > 0: res += x % 10 x //= 10 return res N = int(eval(input())) ans = N for i in range(1, N): A = i B = N - i ans = min(ans, digit_sum(A) + digit_sum(B)) print(ans)
false
26.666667
[ "-def digits_sum(n):", "- return sum(int(c) for c in str(n))", "+def digit_sum(x):", "+ res = 0", "+ while x > 0:", "+ res += x % 10", "+ x //= 10", "+ return res", "-ans = float(\"inf\")", "+ans = N", "- ans = min(ans, digits_sum(A) + digits_sum(B))", "+ ans = min(ans, digit_sum(A) + digit_sum(B))" ]
false
0.260383
0.170172
1.530114
[ "s777430695", "s161122017" ]
u260036763
p03470
python
s353097506
s542039462
19
17
3,060
2,940
Accepted
Accepted
10.53
n = int(eval(input())) d = [eval(input()) for i in range(n)] print((len(set(d))))
N = int(eval(input())) d = [eval(input()) for i in range(N)] print((len(set(d))))
3
3
69
69
n = int(eval(input())) d = [eval(input()) for i in range(n)] print((len(set(d))))
N = int(eval(input())) d = [eval(input()) for i in range(N)] print((len(set(d))))
false
0
[ "-n = int(eval(input()))", "-d = [eval(input()) for i in range(n)]", "+N = int(eval(input()))", "+d = [eval(input()) for i in range(N)]" ]
false
0.036372
0.036077
1.008185
[ "s353097506", "s542039462" ]
u832039789
p03416
python
s458017156
s047133521
67
51
2,940
2,940
Accepted
Accepted
23.88
a,b=list(map(int,input().split())) res=0 for i in range(a,b+1): s=str(i) res += s==s[::-1] print(res)
a,b = list(map(int,input().split())) res = 0 for i in range(a,b+1): s = str(i) if s == s[::-1]: res += 1 print(res)
6
7
109
132
a, b = list(map(int, input().split())) res = 0 for i in range(a, b + 1): s = str(i) res += s == s[::-1] print(res)
a, b = list(map(int, input().split())) res = 0 for i in range(a, b + 1): s = str(i) if s == s[::-1]: res += 1 print(res)
false
14.285714
[ "- res += s == s[::-1]", "+ if s == s[::-1]:", "+ res += 1" ]
false
0.061863
0.0595
1.039715
[ "s458017156", "s047133521" ]
u077291787
p03645
python
s858686442
s064267600
325
266
19,016
19,004
Accepted
Accepted
18.15
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) ans = len(s & d) print(("POSSIBLE" if ans else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
19
18
458
426
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) ans = len(s & d) print(("POSSIBLE" if ans else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ARC079C - Cat Snuke and a Voyage (ABC068C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) s, d = set(), set() for _ in range(m): a, b = list(map(int, input().rstrip().split())) if a == 1: s.add(b) elif b == n: d.add(a) print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
false
5.263158
[ "- ans = len(s & d)", "- print((\"POSSIBLE\" if ans else \"IMPOSSIBLE\"))", "+ print((\"POSSIBLE\" if s & d else \"IMPOSSIBLE\"))" ]
false
0.235077
0.185639
1.266314
[ "s858686442", "s064267600" ]
u606045429
p03703
python
s824984786
s615416816
1,334
1,072
54,684
54,688
Accepted
Accepted
19.64
from itertools import accumulate def main(): class BIT: def __init__(self, N): self.size = N self.tree = [0] * (N + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, K, *A = list(map(int, open(0).read().split())) B = [0] + list(accumulate(a - K for a in A)) memo = {n: i for i, n in enumerate(sorted(set(B)), 1)} bit = BIT(N + 1) ans = 0 for b in map(memo.get, B): ans += bit.sum(b) bit.add(b, 1) print(ans) if __name__ == '__main__': main()
from itertools import accumulate def main(): N, K, *A = list(map(int, open(0).read().split())) B = [0] + list(accumulate(a - K for a in A)) memo = {n: i for i, n in enumerate(sorted(set(B)), 1)} N += 1 tree = [0] * (N + 1) def bit_sum(i): s = 0 while i > 0: s += tree[i] i -= i & -i return s def bit_add(i, x): while i <= N: tree[i] += x i += i & -i ans = 0 for b in map(memo.get, B): ans += bit_sum(b) bit_add(b, 1) print(ans) if __name__ == '__main__': main()
36
33
797
637
from itertools import accumulate def main(): class BIT: def __init__(self, N): self.size = N self.tree = [0] * (N + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, K, *A = list(map(int, open(0).read().split())) B = [0] + list(accumulate(a - K for a in A)) memo = {n: i for i, n in enumerate(sorted(set(B)), 1)} bit = BIT(N + 1) ans = 0 for b in map(memo.get, B): ans += bit.sum(b) bit.add(b, 1) print(ans) if __name__ == "__main__": main()
from itertools import accumulate def main(): N, K, *A = list(map(int, open(0).read().split())) B = [0] + list(accumulate(a - K for a in A)) memo = {n: i for i, n in enumerate(sorted(set(B)), 1)} N += 1 tree = [0] * (N + 1) def bit_sum(i): s = 0 while i > 0: s += tree[i] i -= i & -i return s def bit_add(i, x): while i <= N: tree[i] += x i += i & -i ans = 0 for b in map(memo.get, B): ans += bit_sum(b) bit_add(b, 1) print(ans) if __name__ == "__main__": main()
false
8.333333
[ "- class BIT:", "- def __init__(self, N):", "- self.size = N", "- self.tree = [0] * (N + 1)", "-", "- def sum(self, i):", "- s = 0", "- while i > 0:", "- s += self.tree[i]", "- i -= i & -i", "- return s", "-", "- def add(self, i, x):", "- while i <= self.size:", "- self.tree[i] += x", "- i += i & -i", "-", "- bit = BIT(N + 1)", "+ N += 1", "+ tree = [0] * (N + 1)", "+", "+ def bit_sum(i):", "+ s = 0", "+ while i > 0:", "+ s += tree[i]", "+ i -= i & -i", "+ return s", "+", "+ def bit_add(i, x):", "+ while i <= N:", "+ tree[i] += x", "+ i += i & -i", "+", "- ans += bit.sum(b)", "- bit.add(b, 1)", "+ ans += bit_sum(b)", "+ bit_add(b, 1)" ]
false
0.0455
0.086724
0.524658
[ "s824984786", "s615416816" ]
u691018832
p03487
python
s383460926
s364653505
100
79
20,880
18,392
Accepted
Accepted
21
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import Counter n = int(readline()) a = tuple(map(int, readline().split())) memo = tuple(Counter(a).items()) ans = 0 for x, y in memo: if x <= y: ans += y - x else: ans += y print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import Counter n, *a = list(map(int, read().split())) ans = 0 for k, v in list(Counter(a).items()): if k > v: ans += v elif k < v: ans += v - k print(ans)
18
16
391
347
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import Counter n = int(readline()) a = tuple(map(int, readline().split())) memo = tuple(Counter(a).items()) ans = 0 for x, y in memo: if x <= y: ans += y - x else: ans += y print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import Counter n, *a = list(map(int, read().split())) ans = 0 for k, v in list(Counter(a).items()): if k > v: ans += v elif k < v: ans += v - k print(ans)
false
11.111111
[ "-n = int(readline())", "-a = tuple(map(int, readline().split()))", "-memo = tuple(Counter(a).items())", "+n, *a = list(map(int, read().split()))", "-for x, y in memo:", "- if x <= y:", "- ans += y - x", "- else:", "- ans += y", "+for k, v in list(Counter(a).items()):", "+ if k > v:", "+ ans += v", "+ elif k < v:", "+ ans += v - k" ]
false
0.034528
0.045241
0.763208
[ "s383460926", "s364653505" ]
u076917070
p03687
python
s539758311
s799752704
39
26
3,316
3,064
Accepted
Accepted
33.33
import sys input=sys.stdin.readline import collections def main(): S = input().strip() mi = len(S) for c in list(collections.Counter(S).keys()): s = list(S) n = 0 while len(list(collections.Counter(s).keys())) > 1: for i in range(len(s)-1): if s[i+1] == c: s[i] = c s.pop() n += 1 mi = min(mi, n) print(mi) if __name__ == '__main__': main()
import sys input=sys.stdin.readline def main(): S = input().strip() mi = len(S) for c in set(S): s = list(S) n = 0 while len(set(s)) > 1: for i in range(len(s)-1): if s[i+1] == c: s[i] = c s.pop() n += 1 mi = min(mi, n) print(mi) if __name__ == '__main__': main()
21
20
475
409
import sys input = sys.stdin.readline import collections def main(): S = input().strip() mi = len(S) for c in list(collections.Counter(S).keys()): s = list(S) n = 0 while len(list(collections.Counter(s).keys())) > 1: for i in range(len(s) - 1): if s[i + 1] == c: s[i] = c s.pop() n += 1 mi = min(mi, n) print(mi) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): S = input().strip() mi = len(S) for c in set(S): s = list(S) n = 0 while len(set(s)) > 1: for i in range(len(s) - 1): if s[i + 1] == c: s[i] = c s.pop() n += 1 mi = min(mi, n) print(mi) if __name__ == "__main__": main()
false
4.761905
[ "-import collections", "- for c in list(collections.Counter(S).keys()):", "+ for c in set(S):", "- while len(list(collections.Counter(s).keys())) > 1:", "+ while len(set(s)) > 1:" ]
false
0.039417
0.04207
0.93695
[ "s539758311", "s799752704" ]
u395202850
p02689
python
s886731975
s925459452
232
136
20,108
20,092
Accepted
Accepted
41.38
def main(): n, m = list(map(int, input().split())) hList = list(map(int, input().split())) hAns = [1] * n for i in range(m): a, b = list(map(int, input().split())) if hList[a - 1] > hList[b - 1]: hAns[b - 1] = 0 continue if hList[a - 1] < hList[b - 1]: hAns[a - 1] = 0 continue hAns[a - 1] = 0 hAns[b - 1] = 0 print((sum(hAns))) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline def main(): n, m = list(map(int, readline().rstrip().split())) hList = list(map(int, readline().rstrip().split())) hAns = [1] * n for i in range(m): a, b = list(map(int, readline().rstrip().split())) if hList[a - 1] > hList[b - 1]: hAns[b - 1] = 0 continue if hList[a - 1] < hList[b - 1]: hAns[a - 1] = 0 continue hAns[a - 1] = 0 hAns[b - 1] = 0 print((sum(hAns))) if __name__ == '__main__': main()
19
23
481
564
def main(): n, m = list(map(int, input().split())) hList = list(map(int, input().split())) hAns = [1] * n for i in range(m): a, b = list(map(int, input().split())) if hList[a - 1] > hList[b - 1]: hAns[b - 1] = 0 continue if hList[a - 1] < hList[b - 1]: hAns[a - 1] = 0 continue hAns[a - 1] = 0 hAns[b - 1] = 0 print((sum(hAns))) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline def main(): n, m = list(map(int, readline().rstrip().split())) hList = list(map(int, readline().rstrip().split())) hAns = [1] * n for i in range(m): a, b = list(map(int, readline().rstrip().split())) if hList[a - 1] > hList[b - 1]: hAns[b - 1] = 0 continue if hList[a - 1] < hList[b - 1]: hAns[a - 1] = 0 continue hAns[a - 1] = 0 hAns[b - 1] = 0 print((sum(hAns))) if __name__ == "__main__": main()
false
17.391304
[ "+import sys", "+", "+readline = sys.stdin.readline", "+", "+", "- n, m = list(map(int, input().split()))", "- hList = list(map(int, input().split()))", "+ n, m = list(map(int, readline().rstrip().split()))", "+ hList = list(map(int, readline().rstrip().split()))", "- a, b = list(map(int, input().split()))", "+ a, b = list(map(int, readline().rstrip().split()))" ]
false
0.037773
0.038182
0.989294
[ "s886731975", "s925459452" ]
u358919705
p00008
python
s542545460
s239306531
230
190
7,672
7,720
Accepted
Accepted
17.39
import itertools while True: try: n = int(eval(input())) ans = 0 for a in itertools.product(list(range(10)), repeat=4): if n == sum(a): ans += 1 print(ans) except: break
import itertools while True: try:print(([sum(a)for a in itertools.product(list(range(10)),repeat=4)].count(int(eval(input()))))) except:break
11
4
243
132
import itertools while True: try: n = int(eval(input())) ans = 0 for a in itertools.product(list(range(10)), repeat=4): if n == sum(a): ans += 1 print(ans) except: break
import itertools while True: try: print( ( [sum(a) for a in itertools.product(list(range(10)), repeat=4)].count( int(eval(input())) ) ) ) except: break
false
63.636364
[ "- n = int(eval(input()))", "- ans = 0", "- for a in itertools.product(list(range(10)), repeat=4):", "- if n == sum(a):", "- ans += 1", "- print(ans)", "+ print(", "+ (", "+ [sum(a) for a in itertools.product(list(range(10)), repeat=4)].count(", "+ int(eval(input()))", "+ )", "+ )", "+ )" ]
false
0.050956
0.046683
1.091527
[ "s542545460", "s239306531" ]
u475065881
p03283
python
s600925083
s875248144
1,506
1,006
8,456
18,856
Accepted
Accepted
33.2
N, M , Q = list(map(int, input().split())) LR = [[0 for _ in range(N+2-i)] for i in range(N+2)] for i in range(M): L, R = list(map(int, input().split())) LR[L][R-L+1] += 1 for i in range(2,N+2): for j in range(1,N-i+2): LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2] for i in range(Q): p, q = list(map(int, input().split())) print((LR[p][q-p+1]-LR[q+1][0]))
N, M , Q = list(map(int, input().split())) LR = [[0 for _ in range(N+2-i)] for i in range(N+2)] for i in range(M): L, R = list(map(int, input().split())) LR[L][R-L+1] += 1 for i in range(2,N+2): for j in range(1,N-i+2): LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2] A = [] for i in range(Q): p, q = list(map(int, input().split())) A.append(LR[p][q-p+1]-LR[q+1][0]) print(("\n".join(map(str,A))))
15
18
382
422
N, M, Q = list(map(int, input().split())) LR = [[0 for _ in range(N + 2 - i)] for i in range(N + 2)] for i in range(M): L, R = list(map(int, input().split())) LR[L][R - L + 1] += 1 for i in range(2, N + 2): for j in range(1, N - i + 2): LR[j][i] += LR[j][i - 1] + LR[j + 1][i - 1] - LR[j + 1][i - 2] for i in range(Q): p, q = list(map(int, input().split())) print((LR[p][q - p + 1] - LR[q + 1][0]))
N, M, Q = list(map(int, input().split())) LR = [[0 for _ in range(N + 2 - i)] for i in range(N + 2)] for i in range(M): L, R = list(map(int, input().split())) LR[L][R - L + 1] += 1 for i in range(2, N + 2): for j in range(1, N - i + 2): LR[j][i] += LR[j][i - 1] + LR[j + 1][i - 1] - LR[j + 1][i - 2] A = [] for i in range(Q): p, q = list(map(int, input().split())) A.append(LR[p][q - p + 1] - LR[q + 1][0]) print(("\n".join(map(str, A))))
false
16.666667
[ "+A = []", "- print((LR[p][q - p + 1] - LR[q + 1][0]))", "+ A.append(LR[p][q - p + 1] - LR[q + 1][0])", "+print((\"\\n\".join(map(str, A))))" ]
false
0.042722
0.042467
1.005999
[ "s600925083", "s875248144" ]
u737298927
p02696
python
s531203351
s451216258
22
20
9,196
9,068
Accepted
Accepted
9.09
#!/usr/bin/env python # -*- coding: utf-8 -*- a, b, n = list(map(int, input().split())) def f(x): return a*x//b-a*(x//b) high = n low = 0 while high - low >= 1: mid_left = high/3+low*2/3 mid_right = high*2/3+low/3 if f(mid_left) <= f(mid_right): low = mid_left else: high = mid_right print((max(f(int(low)),f(int(high)))))
#!/usr/bin/env python # -*- coding: utf-8 -*- a, b, n = list(map(int, input().split())) if n >= b: x = b-1 else: x = n print((a*x//b-a*(x//b)))
19
11
373
159
#!/usr/bin/env python # -*- coding: utf-8 -*- a, b, n = list(map(int, input().split())) def f(x): return a * x // b - a * (x // b) high = n low = 0 while high - low >= 1: mid_left = high / 3 + low * 2 / 3 mid_right = high * 2 / 3 + low / 3 if f(mid_left) <= f(mid_right): low = mid_left else: high = mid_right print((max(f(int(low)), f(int(high)))))
#!/usr/bin/env python # -*- coding: utf-8 -*- a, b, n = list(map(int, input().split())) if n >= b: x = b - 1 else: x = n print((a * x // b - a * (x // b)))
false
42.105263
[ "-", "-", "-def f(x):", "- return a * x // b - a * (x // b)", "-", "-", "-high = n", "-low = 0", "-while high - low >= 1:", "- mid_left = high / 3 + low * 2 / 3", "- mid_right = high * 2 / 3 + low / 3", "- if f(mid_left) <= f(mid_right):", "- low = mid_left", "- else:", "- high = mid_right", "-print((max(f(int(low)), f(int(high)))))", "+if n >= b:", "+ x = b - 1", "+else:", "+ x = n", "+print((a * x // b - a * (x // b)))" ]
false
0.034095
0.03595
0.948415
[ "s531203351", "s451216258" ]
u562935282
p02586
python
s683665676
s467202731
1,392
400
223,224
145,528
Accepted
Accepted
71.26
def main(): import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) G = [[0] * W for _ in range(H)] for _ in range(K): r, c, v = list(map(int, input().split())) G[r - 1][c - 1] = v pdp = [[0] * 4 for _ in range(W)] for r in range(H): dp = [[0] * 4 for _ in range(W)] left = [0] * 4 for c in range(W): cell = dp[c] for k in range(4): cell[k] = left[k] up = max(pdp[c]) if cell[0] < up: cell[0] = up for k in range(2, -1, -1): cell[k + 1] = max( cell[k + 1], cell[k] + G[r][c]) left = cell pdp = dp # for k in range(4): # for row in range(H): # for col in range(W): # print(dp[row][col][k], end=' ') # print() # print() # print(*G, sep='\n') ans = max(dp[-1]) print(ans) if __name__ == '__main__': main()
# https://atcoder.jp/contests/abc175/submissions/15965930 def main(): import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) G = [[0] * W for _ in range(H)] for _ in range(K): r, c, v = list(map(int, input().split())) G[r - 1][c - 1] = v dp0 = [0] * (W + 1) dp1 = [0] * (W + 1) dp2 = [0] * (W + 1) dp3 = [0] * (W + 1) # dpx:=行内取得x個以下の最大値 # <cは更新済の同じ行の値 # c<=は前の行の値 for r in range(H): for c in range(W): v = G[r][c] dp0[c] = max(dp0[c], dp3[c]) up = dp0[c] + v dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up) dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up) dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up) # 左から来て取らない # 左から来て取る # 上から来て取らない:=dp0 # 上から来て取る:=dpx(x>0) # print(f'{dp0=}') # print(f'{dp1=}') # print(f'{dp2=}') # print(f'{dp3=}') # print('*******************') print((dp3[-2])) if __name__ == '__main__': main()
47
47
1,084
1,144
def main(): import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) G = [[0] * W for _ in range(H)] for _ in range(K): r, c, v = list(map(int, input().split())) G[r - 1][c - 1] = v pdp = [[0] * 4 for _ in range(W)] for r in range(H): dp = [[0] * 4 for _ in range(W)] left = [0] * 4 for c in range(W): cell = dp[c] for k in range(4): cell[k] = left[k] up = max(pdp[c]) if cell[0] < up: cell[0] = up for k in range(2, -1, -1): cell[k + 1] = max(cell[k + 1], cell[k] + G[r][c]) left = cell pdp = dp # for k in range(4): # for row in range(H): # for col in range(W): # print(dp[row][col][k], end=' ') # print() # print() # print(*G, sep='\n') ans = max(dp[-1]) print(ans) if __name__ == "__main__": main()
# https://atcoder.jp/contests/abc175/submissions/15965930 def main(): import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) G = [[0] * W for _ in range(H)] for _ in range(K): r, c, v = list(map(int, input().split())) G[r - 1][c - 1] = v dp0 = [0] * (W + 1) dp1 = [0] * (W + 1) dp2 = [0] * (W + 1) dp3 = [0] * (W + 1) # dpx:=行内取得x個以下の最大値 # <cは更新済の同じ行の値 # c<=は前の行の値 for r in range(H): for c in range(W): v = G[r][c] dp0[c] = max(dp0[c], dp3[c]) up = dp0[c] + v dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up) dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up) dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up) # 左から来て取らない # 左から来て取る # 上から来て取らない:=dp0 # 上から来て取る:=dpx(x>0) # print(f'{dp0=}') # print(f'{dp1=}') # print(f'{dp2=}') # print(f'{dp3=}') # print('*******************') print((dp3[-2])) if __name__ == "__main__": main()
false
0
[ "+# https://atcoder.jp/contests/abc175/submissions/15965930", "- pdp = [[0] * 4 for _ in range(W)]", "+ dp0 = [0] * (W + 1)", "+ dp1 = [0] * (W + 1)", "+ dp2 = [0] * (W + 1)", "+ dp3 = [0] * (W + 1)", "+ # dpx:=行内取得x個以下の最大値", "+ # <cは更新済の同じ行の値", "+ # c<=は前の行の値", "- dp = [[0] * 4 for _ in range(W)]", "- left = [0] * 4", "- cell = dp[c]", "- for k in range(4):", "- cell[k] = left[k]", "- up = max(pdp[c])", "- if cell[0] < up:", "- cell[0] = up", "- for k in range(2, -1, -1):", "- cell[k + 1] = max(cell[k + 1], cell[k] + G[r][c])", "- left = cell", "- pdp = dp", "- # for k in range(4):", "- # for row in range(H):", "- # for col in range(W):", "- # print(dp[row][col][k], end=' ')", "- # print()", "- # print()", "- # print(*G, sep='\\n')", "- ans = max(dp[-1])", "- print(ans)", "+ v = G[r][c]", "+ dp0[c] = max(dp0[c], dp3[c])", "+ up = dp0[c] + v", "+ dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up)", "+ dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up)", "+ dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up)", "+ # 左から来て取らない", "+ # 左から来て取る", "+ # 上から来て取らない:=dp0", "+ # 上から来て取る:=dpx(x>0)", "+ # print(f'{dp0=}')", "+ # print(f'{dp1=}')", "+ # print(f'{dp2=}')", "+ # print(f'{dp3=}')", "+ # print('*******************')", "+ print((dp3[-2]))" ]
false
0.036526
0.035547
1.02755
[ "s683665676", "s467202731" ]
u057109575
p02925
python
s990899573
s731903273
1,175
689
153,788
197,748
Accepted
Accepted
41.36
from collections import deque N = int(eval(input())) A = [list(map(int, input().split())) for _ in range(N)] graph = [[] for _ in range(N * N)] ins = [0] * (N * N) for i, nodes in enumerate(A): for j1, j2 in zip(nodes[:-1], nodes[1:]): n1 = max(i, j1 - 1) * N + min(i, j1 - 1) n2 = max(i, j2 - 1) * N + min(i, j2 - 1) graph[n1].append(n2) ins[n2] += 1 visited = [False] * (N * N) for i in range(N): visited[N * i + i] = True que = deque() for i, v in enumerate(ins): if v == 0: que.append((i, 1)) dist = [0] * (N * N) while que: cur, d = que.popleft() visited[cur] = True dist[cur] = d for v in graph[cur]: if visited[v]: continue ins[v] -= 1 if ins[v] == 0: que.append((v, d + 1)) print((max(dist) if all(visited) else -1))
from collections import deque N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] graph = [[] for _ in range(N * N)] ins = [0] * (N * N) for i, nodes in enumerate(X): for j1, j2 in zip(nodes[:-1], nodes[1:]): n1 = max(i, j1 - 1) * N + min(i, j1 - 1) n2 = max(i, j2 - 1) * N + min(i, j2 - 1) graph[n1].append(n2) ins[n2] += 1 dist = [0] * (N * N) visited = [False] * (N * N) q = deque() for i in range(N): visited[N * i + i] = True for i, v in enumerate(ins): if v == 0: q.append((i, 1)) while q: u, d = q.popleft() visited[u] = True dist[u] = d for v in graph[u]: if visited[v]: continue ins[v] -= 1 if ins[v] == 0: q.append((v, d + 1)) print((max(dist) if all(visited) else -1))
39
40
896
888
from collections import deque N = int(eval(input())) A = [list(map(int, input().split())) for _ in range(N)] graph = [[] for _ in range(N * N)] ins = [0] * (N * N) for i, nodes in enumerate(A): for j1, j2 in zip(nodes[:-1], nodes[1:]): n1 = max(i, j1 - 1) * N + min(i, j1 - 1) n2 = max(i, j2 - 1) * N + min(i, j2 - 1) graph[n1].append(n2) ins[n2] += 1 visited = [False] * (N * N) for i in range(N): visited[N * i + i] = True que = deque() for i, v in enumerate(ins): if v == 0: que.append((i, 1)) dist = [0] * (N * N) while que: cur, d = que.popleft() visited[cur] = True dist[cur] = d for v in graph[cur]: if visited[v]: continue ins[v] -= 1 if ins[v] == 0: que.append((v, d + 1)) print((max(dist) if all(visited) else -1))
from collections import deque N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] graph = [[] for _ in range(N * N)] ins = [0] * (N * N) for i, nodes in enumerate(X): for j1, j2 in zip(nodes[:-1], nodes[1:]): n1 = max(i, j1 - 1) * N + min(i, j1 - 1) n2 = max(i, j2 - 1) * N + min(i, j2 - 1) graph[n1].append(n2) ins[n2] += 1 dist = [0] * (N * N) visited = [False] * (N * N) q = deque() for i in range(N): visited[N * i + i] = True for i, v in enumerate(ins): if v == 0: q.append((i, 1)) while q: u, d = q.popleft() visited[u] = True dist[u] = d for v in graph[u]: if visited[v]: continue ins[v] -= 1 if ins[v] == 0: q.append((v, d + 1)) print((max(dist) if all(visited) else -1))
false
2.5
[ "-A = [list(map(int, input().split())) for _ in range(N)]", "+X = [list(map(int, input().split())) for _ in range(N)]", "-for i, nodes in enumerate(A):", "+for i, nodes in enumerate(X):", "+dist = [0] * (N * N)", "+q = deque()", "-que = deque()", "- que.append((i, 1))", "-dist = [0] * (N * N)", "-while que:", "- cur, d = que.popleft()", "- visited[cur] = True", "- dist[cur] = d", "- for v in graph[cur]:", "+ q.append((i, 1))", "+while q:", "+ u, d = q.popleft()", "+ visited[u] = True", "+ dist[u] = d", "+ for v in graph[u]:", "- que.append((v, d + 1))", "+ q.append((v, d + 1))" ]
false
0.039188
0.038394
1.020688
[ "s990899573", "s731903273" ]
u784022244
p02983
python
s833871999
s828097267
735
134
3,060
65,124
Accepted
Accepted
81.77
L,R=list(map(int, input().split())) #2019の倍数が入っていれば0→R-Lが2019以上 if R-L>=2019: print((0)) exit() ans=2019 for i in range(L,R): for j in range(i+1,R+1): ans=min(ans, (i*j)%2019) print(ans)
L, R=list(map(int, input().split())) if R - L >= 2019: print((0)) else: ans=float("INF") for i in range(L, R): for j in range(i+1,R+1): ans=min(ans, (i*j)%2019) print(ans)
11
11
209
215
L, R = list(map(int, input().split())) # 2019の倍数が入っていれば0→R-Lが2019以上 if R - L >= 2019: print((0)) exit() ans = 2019 for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, (i * j) % 2019) print(ans)
L, R = list(map(int, input().split())) if R - L >= 2019: print((0)) else: ans = float("INF") for i in range(L, R): for j in range(i + 1, R + 1): ans = min(ans, (i * j) % 2019) print(ans)
false
0
[ "-# 2019の倍数が入っていれば0→R-Lが2019以上", "- exit()", "-ans = 2019", "-for i in range(L, R):", "- for j in range(i + 1, R + 1):", "- ans = min(ans, (i * j) % 2019)", "-print(ans)", "+else:", "+ ans = float(\"INF\")", "+ for i in range(L, R):", "+ for j in range(i + 1, R + 1):", "+ ans = min(ans, (i * j) % 2019)", "+ print(ans)" ]
false
0.006863
0.063537
0.108017
[ "s833871999", "s828097267" ]
u361826811
p02881
python
s862137978
s230455497
290
156
12,516
3,188
Accepted
Accepted
46.21
""" author : halo2halo date : 4, Feb, 2020 """ import sys import itertools # import math import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10 ** 13 N = int(readline()) temp = INF a = 0 b = 0 for i in range(1, int(N**.5)+1): if N % i == 0: if temp >= abs(i - N // i): temp = abs(i - N // i) a = i b = N // i print((a+b-2))
""" author : halo2halo date : 4, Feb, 2020 """ import sys import itertools # import math # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10 ** 13 N = int(readline()) temp = INF a = 0 b = 0 for i in range(1, int(N**.5)+1): if N % i == 0: if temp >= abs(i - N // i): temp = abs(i - N // i) a = i b = N // i print((a+b-2))
28
31
479
488
""" author : halo2halo date : 4, Feb, 2020 """ import sys import itertools # import math import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10**13 N = int(readline()) temp = INF a = 0 b = 0 for i in range(1, int(N**0.5) + 1): if N % i == 0: if temp >= abs(i - N // i): temp = abs(i - N // i) a = i b = N // i print((a + b - 2))
""" author : halo2halo date : 4, Feb, 2020 """ import sys import itertools # import math # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10**13 N = int(readline()) temp = INF a = 0 b = 0 for i in range(1, int(N**0.5) + 1): if N % i == 0: if temp >= abs(i - N // i): temp = abs(i - N // i) a = i b = N // i print((a + b - 2))
false
9.677419
[ "-import numpy as np", "-", "+# import numpy as np" ]
false
0.03802
0.03754
1.012788
[ "s862137978", "s230455497" ]
u347640436
p02819
python
s404048032
s822902325
255
192
48,540
48,572
Accepted
Accepted
24.71
# エラトステネスの篩 def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(2, int(n ** 0.5) + 1): if sieve[i] != i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve X = int(eval(input())) N = 10 ** 6 prime_table = make_prime_table(N) for i in range(X, N + 1): if prime_table[i] == i: print(i) break
def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(4, n + 1, 2): sieve[i] = 2 for i in range(3, int(n ** 0.5) + 1, 2): if sieve[i] != i: continue for j in range(i * i, n + 1, i * 2): if sieve[j] == j: sieve[j] = i return sieve X = int(eval(input())) N = 10 ** 6 prime_table = make_prime_table(N) for i in range(X, N + 1): if prime_table[i] == i: print(i) break
22
22
482
530
# エラトステネスの篩 def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(2, int(n**0.5) + 1): if sieve[i] != i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve X = int(eval(input())) N = 10**6 prime_table = make_prime_table(N) for i in range(X, N + 1): if prime_table[i] == i: print(i) break
def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(4, n + 1, 2): sieve[i] = 2 for i in range(3, int(n**0.5) + 1, 2): if sieve[i] != i: continue for j in range(i * i, n + 1, i * 2): if sieve[j] == j: sieve[j] = i return sieve X = int(eval(input())) N = 10**6 prime_table = make_prime_table(N) for i in range(X, N + 1): if prime_table[i] == i: print(i) break
false
0
[ "-# エラトステネスの篩", "- for i in range(2, int(n**0.5) + 1):", "+ for i in range(4, n + 1, 2):", "+ sieve[i] = 2", "+ for i in range(3, int(n**0.5) + 1, 2):", "- for j in range(i * i, n + 1, i):", "+ for j in range(i * i, n + 1, i * 2):" ]
false
0.624793
0.45929
1.360345
[ "s404048032", "s822902325" ]
u033606236
p03266
python
s903386351
s172592627
99
85
10,996
11,032
Accepted
Accepted
14.14
N,K = list(map(int,input().split())) odd = [] even1 = [] even2 = [] if K % 2 == 1: for i in range(1,N+1): if i % K == 0: odd += [i] ans = len(odd) ** 3 else: for i in range(1,N+1): if i % K == 0: even1 += [i] elif i % (K/2) == 0: even2 += [i] ans = len(even1) ** 3 + len(even2) ** 3 print(ans)
N,K = list(map(int,input().split())) ary1 = [] ary2 = [] if K % 2 == 1: for i in range(K,N+1,K): ary1 += [i] print((len(ary1)**3)) else: for i in range(1,N+1): if i % K == 0: ary1 += [i] elif i % (K//2) == 0: ary2 += [i] print(((len(ary1) ** 3) + (len(ary2) ** 3)))
17
14
379
333
N, K = list(map(int, input().split())) odd = [] even1 = [] even2 = [] if K % 2 == 1: for i in range(1, N + 1): if i % K == 0: odd += [i] ans = len(odd) ** 3 else: for i in range(1, N + 1): if i % K == 0: even1 += [i] elif i % (K / 2) == 0: even2 += [i] ans = len(even1) ** 3 + len(even2) ** 3 print(ans)
N, K = list(map(int, input().split())) ary1 = [] ary2 = [] if K % 2 == 1: for i in range(K, N + 1, K): ary1 += [i] print((len(ary1) ** 3)) else: for i in range(1, N + 1): if i % K == 0: ary1 += [i] elif i % (K // 2) == 0: ary2 += [i] print(((len(ary1) ** 3) + (len(ary2) ** 3)))
false
17.647059
[ "-odd = []", "-even1 = []", "-even2 = []", "+ary1 = []", "+ary2 = []", "- for i in range(1, N + 1):", "- if i % K == 0:", "- odd += [i]", "- ans = len(odd) ** 3", "+ for i in range(K, N + 1, K):", "+ ary1 += [i]", "+ print((len(ary1) ** 3))", "- even1 += [i]", "- elif i % (K / 2) == 0:", "- even2 += [i]", "- ans = len(even1) ** 3 + len(even2) ** 3", "-print(ans)", "+ ary1 += [i]", "+ elif i % (K // 2) == 0:", "+ ary2 += [i]", "+ print(((len(ary1) ** 3) + (len(ary2) ** 3)))" ]
false
0.105899
0.09364
1.13092
[ "s903386351", "s172592627" ]
u695811449
p03017
python
s548031229
s823461940
236
138
41,480
6,392
Accepted
Accepted
41.53
import sys input = sys.stdin.readline N,A,B,C,D=list(map(int,input().split())) S=input().strip() S+="#####" A-=1 B-=1 C-=1 D-=1 if C<D: while B!=D or A!=C: #print(A,B) if B!=D and S[B+1]==".": B+=1 elif B!=D and S[B+2]==".": B+=2 elif B!=D and S[B+1]=="#" and S[B+2]=="#": print("No") sys.exit() if A!=C and S[A+1]==".": A+=1 elif A!=C and S[A+2]==".": A+=2 elif A!=C and S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() print("Yes") else: while A<B: if S[A+1]=="." and A+1!=B: A+=1 elif S[A+2]=="." and A+2!=B: A+=2 elif S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() if A+1==B or (A+2==B and S[A+1]=="#"): break while True: if A+1==B and S[B+1]==".": A+=2 break if S[B+1]==".": B+=1 elif S[B+2]==".": B+=2 else: print("No") sys.exit() if S[A+1]==".": A+=1 elif S[A+2]==".": A+=2 if B>D: print("No") sys.exit() while B!=D or A!=C: if A!=C and S[A+1]==".": A+=1 elif A!=C and S[A+2]==".": A+=2 elif A!=C and S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() if B!=D and S[B+1]==".": B+=1 elif B!=D and S[B+2]==".": B+=2 elif B!=D and S[B+1]=="#" and S[B+2]=="#": print("No") sys.exit() print("Yes")
import sys input = sys.stdin.readline N,A,B,C,D=list(map(int,input().split())) S=input().strip() BLOCK=[0]*N OPEN=[0]*N for i in range(1,N): if S[i]=="#" and S[i-1]=="#": BLOCK[i]=1 for i in range(2,N): if S[i]==S[i-1]==S[i-2]==".": OPEN[i]=1 RIGHT_A=N-1 for i in range(A,N): if BLOCK[i]==1: RIGHT_A=i break RIGHT_B=N-1 for i in range(B,N): if BLOCK[i]==1: RIGHT_B=i break if C<=RIGHT_A+1 and D<=RIGHT_B+1: if C<D: print("Yes") sys.exit() if RIGHT_A==RIGHT_B: for j in range(B,D+1): if OPEN[j]==1: print("Yes") sys.exit() else: print("No") else: print("Yes") else: print("No")
98
46
1,884
815
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) S = input().strip() S += "#####" A -= 1 B -= 1 C -= 1 D -= 1 if C < D: while B != D or A != C: # print(A,B) if B != D and S[B + 1] == ".": B += 1 elif B != D and S[B + 2] == ".": B += 2 elif B != D and S[B + 1] == "#" and S[B + 2] == "#": print("No") sys.exit() if A != C and S[A + 1] == ".": A += 1 elif A != C and S[A + 2] == ".": A += 2 elif A != C and S[A + 1] == "#" and S[A + 2] == "#": print("No") sys.exit() print("Yes") else: while A < B: if S[A + 1] == "." and A + 1 != B: A += 1 elif S[A + 2] == "." and A + 2 != B: A += 2 elif S[A + 1] == "#" and S[A + 2] == "#": print("No") sys.exit() if A + 1 == B or (A + 2 == B and S[A + 1] == "#"): break while True: if A + 1 == B and S[B + 1] == ".": A += 2 break if S[B + 1] == ".": B += 1 elif S[B + 2] == ".": B += 2 else: print("No") sys.exit() if S[A + 1] == ".": A += 1 elif S[A + 2] == ".": A += 2 if B > D: print("No") sys.exit() while B != D or A != C: if A != C and S[A + 1] == ".": A += 1 elif A != C and S[A + 2] == ".": A += 2 elif A != C and S[A + 1] == "#" and S[A + 2] == "#": print("No") sys.exit() if B != D and S[B + 1] == ".": B += 1 elif B != D and S[B + 2] == ".": B += 2 elif B != D and S[B + 1] == "#" and S[B + 2] == "#": print("No") sys.exit() print("Yes")
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) S = input().strip() BLOCK = [0] * N OPEN = [0] * N for i in range(1, N): if S[i] == "#" and S[i - 1] == "#": BLOCK[i] = 1 for i in range(2, N): if S[i] == S[i - 1] == S[i - 2] == ".": OPEN[i] = 1 RIGHT_A = N - 1 for i in range(A, N): if BLOCK[i] == 1: RIGHT_A = i break RIGHT_B = N - 1 for i in range(B, N): if BLOCK[i] == 1: RIGHT_B = i break if C <= RIGHT_A + 1 and D <= RIGHT_B + 1: if C < D: print("Yes") sys.exit() if RIGHT_A == RIGHT_B: for j in range(B, D + 1): if OPEN[j] == 1: print("Yes") sys.exit() else: print("No") else: print("Yes") else: print("No")
false
53.061224
[ "-S += \"#####\"", "-A -= 1", "-B -= 1", "-C -= 1", "-D -= 1", "-if C < D:", "- while B != D or A != C:", "- # print(A,B)", "- if B != D and S[B + 1] == \".\":", "- B += 1", "- elif B != D and S[B + 2] == \".\":", "- B += 2", "- elif B != D and S[B + 1] == \"#\" and S[B + 2] == \"#\":", "- print(\"No\")", "- sys.exit()", "- if A != C and S[A + 1] == \".\":", "- A += 1", "- elif A != C and S[A + 2] == \".\":", "- A += 2", "- elif A != C and S[A + 1] == \"#\" and S[A + 2] == \"#\":", "- print(\"No\")", "- sys.exit()", "- print(\"Yes\")", "-else:", "- while A < B:", "- if S[A + 1] == \".\" and A + 1 != B:", "- A += 1", "- elif S[A + 2] == \".\" and A + 2 != B:", "- A += 2", "- elif S[A + 1] == \"#\" and S[A + 2] == \"#\":", "- print(\"No\")", "- sys.exit()", "- if A + 1 == B or (A + 2 == B and S[A + 1] == \"#\"):", "- break", "- while True:", "- if A + 1 == B and S[B + 1] == \".\":", "- A += 2", "- break", "- if S[B + 1] == \".\":", "- B += 1", "- elif S[B + 2] == \".\":", "- B += 2", "+BLOCK = [0] * N", "+OPEN = [0] * N", "+for i in range(1, N):", "+ if S[i] == \"#\" and S[i - 1] == \"#\":", "+ BLOCK[i] = 1", "+for i in range(2, N):", "+ if S[i] == S[i - 1] == S[i - 2] == \".\":", "+ OPEN[i] = 1", "+RIGHT_A = N - 1", "+for i in range(A, N):", "+ if BLOCK[i] == 1:", "+ RIGHT_A = i", "+ break", "+RIGHT_B = N - 1", "+for i in range(B, N):", "+ if BLOCK[i] == 1:", "+ RIGHT_B = i", "+ break", "+if C <= RIGHT_A + 1 and D <= RIGHT_B + 1:", "+ if C < D:", "+ print(\"Yes\")", "+ sys.exit()", "+ if RIGHT_A == RIGHT_B:", "+ for j in range(B, D + 1):", "+ if OPEN[j] == 1:", "+ print(\"Yes\")", "+ sys.exit()", "- sys.exit()", "- if S[A + 1] == \".\":", "- A += 1", "- elif S[A + 2] == \".\":", "- A += 2", "- if B > D:", "- print(\"No\")", "- sys.exit()", "- while B != D or A != C:", "- if A != C and S[A + 1] == \".\":", "- A += 1", "- elif A != C and S[A + 2] == \".\":", "- A += 2", "- elif A != C and S[A + 1] == \"#\" and S[A + 2] == \"#\":", "- print(\"No\")", "- sys.exit()", "- if B != D and S[B + 1] == \".\":", "- B += 1", "- elif B != D and S[B + 2] == \".\":", "- B += 2", "- elif B != D and S[B + 1] == \"#\" and S[B + 2] == \"#\":", "- print(\"No\")", "- sys.exit()", "- print(\"Yes\")", "+ else:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.074848
0.007211
10.379744
[ "s548031229", "s823461940" ]
u416758623
p03493
python
s499009951
s105915829
20
17
2,940
2,940
Accepted
Accepted
15
sentence = eval(input()) count = 0 for i in range(len(sentence)): if sentence[i] == "1": count+=1 print(count)
s = eval(input()) print((s.count("1")))
7
2
124
32
sentence = eval(input()) count = 0 for i in range(len(sentence)): if sentence[i] == "1": count += 1 print(count)
s = eval(input()) print((s.count("1")))
false
71.428571
[ "-sentence = eval(input())", "-count = 0", "-for i in range(len(sentence)):", "- if sentence[i] == \"1\":", "- count += 1", "-print(count)", "+s = eval(input())", "+print((s.count(\"1\")))" ]
false
0.086733
0.088695
0.977879
[ "s499009951", "s105915829" ]
u571969099
p02632
python
s474674633
s748872887
1,216
1,053
164,672
163,368
Accepted
Accepted
13.4
mod = 10 ** 9 + 7 max_kai = 5*10**6 kai = [1] for i in range(1, max_kai): kai.append(kai[-1] * i % mod) kkai = [0] * max_kai kkai[-1] = pow(kai[-1], mod - 2, mod) for i in reversed(list(range(1, max_kai))): kkai[i - 1] = kkai[i] * i % mod def comb(a, b): if a < 0 or b < 0: return 0 elif a < b: return 0 c = 1 c *= kai[a] c *= kkai[b] c *= kkai[a - b] return c % mod k = int(eval(input())) s = eval(input()) ans = 0 for i in range(len(s), len(s) + k + 1): ans += pow(25, i - len(s), mod) * pow(26, len(s) + k - i, mod) * comb(i-1,len(s)-1) ans %= mod print(ans)
mod = 10 ** 9 + 7 max_kai = 2*10**6 kai = [1] for i in range(1, max_kai): kai.append(kai[-1] * i % mod) kkai = [0] * max_kai kkai[-1] = pow(kai[-1], mod - 2, mod) for i in reversed(list(range(1, max_kai))): kkai[i - 1] = kkai[i] * i % mod def comb(a, b): if a < 0 or b < 0: return 0 elif a < b: return 0 c = 1 c *= kai[a] c *= kkai[b] c *= kkai[a - b] return c % mod k = int(eval(input())) s = eval(input()) ans = 0 for i in range(k + 1): ans += pow(25, i, mod) * pow(26, k - i, mod) * comb(i + len(s) - 1, len(s) - 1) ans %= mod print(ans)
31
31
639
618
mod = 10**9 + 7 max_kai = 5 * 10**6 kai = [1] for i in range(1, max_kai): kai.append(kai[-1] * i % mod) kkai = [0] * max_kai kkai[-1] = pow(kai[-1], mod - 2, mod) for i in reversed(list(range(1, max_kai))): kkai[i - 1] = kkai[i] * i % mod def comb(a, b): if a < 0 or b < 0: return 0 elif a < b: return 0 c = 1 c *= kai[a] c *= kkai[b] c *= kkai[a - b] return c % mod k = int(eval(input())) s = eval(input()) ans = 0 for i in range(len(s), len(s) + k + 1): ans += ( pow(25, i - len(s), mod) * pow(26, len(s) + k - i, mod) * comb(i - 1, len(s) - 1) ) ans %= mod print(ans)
mod = 10**9 + 7 max_kai = 2 * 10**6 kai = [1] for i in range(1, max_kai): kai.append(kai[-1] * i % mod) kkai = [0] * max_kai kkai[-1] = pow(kai[-1], mod - 2, mod) for i in reversed(list(range(1, max_kai))): kkai[i - 1] = kkai[i] * i % mod def comb(a, b): if a < 0 or b < 0: return 0 elif a < b: return 0 c = 1 c *= kai[a] c *= kkai[b] c *= kkai[a - b] return c % mod k = int(eval(input())) s = eval(input()) ans = 0 for i in range(k + 1): ans += pow(25, i, mod) * pow(26, k - i, mod) * comb(i + len(s) - 1, len(s) - 1) ans %= mod print(ans)
false
0
[ "-max_kai = 5 * 10**6", "+max_kai = 2 * 10**6", "-for i in range(len(s), len(s) + k + 1):", "- ans += (", "- pow(25, i - len(s), mod)", "- * pow(26, len(s) + k - i, mod)", "- * comb(i - 1, len(s) - 1)", "- )", "+for i in range(k + 1):", "+ ans += pow(25, i, mod) * pow(26, k - i, mod) * comb(i + len(s) - 1, len(s) - 1)" ]
false
2.9647
1.967182
1.507079
[ "s474674633", "s748872887" ]
u367701763
p03053
python
s009381530
s695011177
986
314
248,320
149,464
Accepted
Accepted
68.15
# https://atcoder.jp/contests/agc033/tasks/agc033_a from collections import deque import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline move = [(1, 0), (-1, 0), (0, 1), (0, -1)] # 動ける場所の候補 def debug(start, goal, p, t): player = p debug_grid = list(list(grid[h]) for h in range(H)) if start != (None, None): debug_grid[start[0]][start[1]] = "S" if goal != (None, None): debug_grid[goal[0]][goal[1]] = "G" debug_grid[player[0]][player[1]] = "P" print(("~~~~~~~~~ t = " + str(t+1) + " ~~~~~~~~")) for debug_h in range(H): print(("".join(str(debug_grid[debug_h][debug_w]) for debug_w in range(W)))) def search(grid, next_set, goal=(None,None), visit=set()): visit.add(start) # スタート地点はすでに訪れている while next_set: # p = [] になったら止める p, t = next_set.popleft() # 要素を消去して、消去した要素を出力 h, w = p for dh, dw in move: # 頂点 p から進める経路の候補から一つ選ぶ q = (h + dh, w + dw) if q[0] < 0 or q[0] >= H or q[1] < 0 or q[1] >= W: continue if grid[q[0]][q[1]] == wall: # 壁があったら進まない continue if q in visit: # 一度訪れていた場合は進まない continue #### (debug code) ###### # debug(start, goal, q, t) ######################## if q == goal: # ゴールがあるならば、ここで判定 return t + 1 # 経路の長さは t + 1 で与えられる visit.add(q) # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある) next_set.append((q, t + 1)) # p から q へと移動。時刻を 1 進める return t road, wall = ".", "#" # (進行可能を意味する記号, 進行不可を意味する記号) H,W = list(map(int,input().split())) # 左上は(h,w)=(0,0)、右下は(h,w)=(H-1,W-1) grid = [] next_set = deque() visit = set() for h in range(H): grid.append(eval(input())) for w, a in enumerate(grid[-1]): if a == "#": start = (h, w) next_set.append((start,0)) visit.add(start) print((search(grid, next_set, goal=(None,None), visit=visit)))
# https://atcoder.jp/contests/agc033/tasks/agc033_a from collections import deque import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline move = [(1, 0), (-1, 0), (0, 1), (0, -1)] # 動ける場所の候補 def debug(start, goal, p, t): player = p debug_grid = list(list(grid[h]) for h in range(H)) if start != (None, None): debug_grid[start[0]][start[1]] = "S" if goal != (None, None): debug_grid[goal[0]][goal[1]] = "G" debug_grid[player[0]][player[1]] = "P" print(("~~~~~~~~~ t = " + str(t+1) + " ~~~~~~~~")) for debug_h in range(H): print(("".join(str(debug_grid[debug_h][debug_w]) for debug_w in range(W)))) def bfs(grid, next_set, goal, visit): visit[start[0]][start[1]] = 1 # スタート地点はすでに訪れている while next_set: # p = [] になったら止める p, t = next_set.popleft() # 要素を消去して、消去した要素を出力 h, w = p for dh, dw in move: # 頂点 p から進める経路の候補から一つ選ぶ q = (h + dh, w + dw) if q[0] < 0 or q[0] >= H or q[1] < 0 or q[1] >= W: continue if grid[q[0]][q[1]] == wall: # 壁があったら進まない continue if visit[q[0]][q[1]] == 1: # 一度訪れていた場合は進まない continue #### (debug code) ###### # debug(start, goal, q, t) ######################## if q == goal: # ゴールがあるならば、ここで判定 return t + 1 # 経路の長さは t + 1 で与えられる visit[q[0]][q[1]] = 1 # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある) next_set.append((q, t + 1)) # p から q へと移動。時刻を 1 進める return t road, wall = ".", "#" # (進行可能を意味する記号, 進行不可を意味する記号) H,W = list(map(int,input().split())) # 左上は(h,w)=(0,0)、右下は(h,w)=(H-1,W-1) grid = [] next_set = deque() visit = [[0]*W for _ in range(H)] for h in range(H): grid.append(eval(input())) for w, a in enumerate(grid[-1]): if a == "#": start = (h, w) next_set.append((start,0)) visit[start[0]][start[1]] = 1 print((bfs(grid, next_set, (None,None), visit)))
62
61
2,304
2,301
# https://atcoder.jp/contests/agc033/tasks/agc033_a from collections import deque import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline move = [(1, 0), (-1, 0), (0, 1), (0, -1)] # 動ける場所の候補 def debug(start, goal, p, t): player = p debug_grid = list(list(grid[h]) for h in range(H)) if start != (None, None): debug_grid[start[0]][start[1]] = "S" if goal != (None, None): debug_grid[goal[0]][goal[1]] = "G" debug_grid[player[0]][player[1]] = "P" print(("~~~~~~~~~ t = " + str(t + 1) + " ~~~~~~~~")) for debug_h in range(H): print(("".join(str(debug_grid[debug_h][debug_w]) for debug_w in range(W)))) def search(grid, next_set, goal=(None, None), visit=set()): visit.add(start) # スタート地点はすでに訪れている while next_set: # p = [] になったら止める p, t = next_set.popleft() # 要素を消去して、消去した要素を出力 h, w = p for dh, dw in move: # 頂点 p から進める経路の候補から一つ選ぶ q = (h + dh, w + dw) if q[0] < 0 or q[0] >= H or q[1] < 0 or q[1] >= W: continue if grid[q[0]][q[1]] == wall: # 壁があったら進まない continue if q in visit: # 一度訪れていた場合は進まない continue #### (debug code) ###### # debug(start, goal, q, t) ######################## if q == goal: # ゴールがあるならば、ここで判定 return t + 1 # 経路の長さは t + 1 で与えられる visit.add( q ) # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある) next_set.append((q, t + 1)) # p から q へと移動。時刻を 1 進める return t road, wall = ".", "#" # (進行可能を意味する記号, 進行不可を意味する記号) H, W = list(map(int, input().split())) # 左上は(h,w)=(0,0)、右下は(h,w)=(H-1,W-1) grid = [] next_set = deque() visit = set() for h in range(H): grid.append(eval(input())) for w, a in enumerate(grid[-1]): if a == "#": start = (h, w) next_set.append((start, 0)) visit.add(start) print((search(grid, next_set, goal=(None, None), visit=visit)))
# https://atcoder.jp/contests/agc033/tasks/agc033_a from collections import deque import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline move = [(1, 0), (-1, 0), (0, 1), (0, -1)] # 動ける場所の候補 def debug(start, goal, p, t): player = p debug_grid = list(list(grid[h]) for h in range(H)) if start != (None, None): debug_grid[start[0]][start[1]] = "S" if goal != (None, None): debug_grid[goal[0]][goal[1]] = "G" debug_grid[player[0]][player[1]] = "P" print(("~~~~~~~~~ t = " + str(t + 1) + " ~~~~~~~~")) for debug_h in range(H): print(("".join(str(debug_grid[debug_h][debug_w]) for debug_w in range(W)))) def bfs(grid, next_set, goal, visit): visit[start[0]][start[1]] = 1 # スタート地点はすでに訪れている while next_set: # p = [] になったら止める p, t = next_set.popleft() # 要素を消去して、消去した要素を出力 h, w = p for dh, dw in move: # 頂点 p から進める経路の候補から一つ選ぶ q = (h + dh, w + dw) if q[0] < 0 or q[0] >= H or q[1] < 0 or q[1] >= W: continue if grid[q[0]][q[1]] == wall: # 壁があったら進まない continue if visit[q[0]][q[1]] == 1: # 一度訪れていた場合は進まない continue #### (debug code) ###### # debug(start, goal, q, t) ######################## if q == goal: # ゴールがあるならば、ここで判定 return t + 1 # 経路の長さは t + 1 で与えられる visit[q[0]][ q[1] ] = 1 # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある) next_set.append((q, t + 1)) # p から q へと移動。時刻を 1 進める return t road, wall = ".", "#" # (進行可能を意味する記号, 進行不可を意味する記号) H, W = list(map(int, input().split())) # 左上は(h,w)=(0,0)、右下は(h,w)=(H-1,W-1) grid = [] next_set = deque() visit = [[0] * W for _ in range(H)] for h in range(H): grid.append(eval(input())) for w, a in enumerate(grid[-1]): if a == "#": start = (h, w) next_set.append((start, 0)) visit[start[0]][start[1]] = 1 print((bfs(grid, next_set, (None, None), visit)))
false
1.612903
[ "-def search(grid, next_set, goal=(None, None), visit=set()):", "- visit.add(start) # スタート地点はすでに訪れている", "+def bfs(grid, next_set, goal, visit):", "+ visit[start[0]][start[1]] = 1 # スタート地点はすでに訪れている", "- if q in visit: # 一度訪れていた場合は進まない", "+ if visit[q[0]][q[1]] == 1: # 一度訪れていた場合は進まない", "- visit.add(", "- q", "- ) # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある)", "+ visit[q[0]][", "+ q[1]", "+ ] = 1 # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある)", "-visit = set()", "+visit = [[0] * W for _ in range(H)]", "- visit.add(start)", "-print((search(grid, next_set, goal=(None, None), visit=visit)))", "+ visit[start[0]][start[1]] = 1", "+print((bfs(grid, next_set, (None, None), visit)))" ]
false
0.08761
0.048648
1.800892
[ "s009381530", "s695011177" ]
u816631826
p04039
python
s500785182
s774051850
183
75
40,412
9,192
Accepted
Accepted
59.02
n, k = list(map(int, input().split())) d = list(input().split()) from itertools import count for i in count(n): s = str(i) for bit in s: if bit in d: break else: print(i) break
n,k = list(map(int, input().split())) d = list(map(int, input().split())) def v(n): for c in map(int, str(n)): if (c in d): return False return True while (v(n) == False): n += 1 print(n)
14
10
235
222
n, k = list(map(int, input().split())) d = list(input().split()) from itertools import count for i in count(n): s = str(i) for bit in s: if bit in d: break else: print(i) break
n, k = list(map(int, input().split())) d = list(map(int, input().split())) def v(n): for c in map(int, str(n)): if c in d: return False return True while v(n) == False: n += 1 print(n)
false
28.571429
[ "-d = list(input().split())", "-from itertools import count", "+d = list(map(int, input().split()))", "-for i in count(n):", "- s = str(i)", "- for bit in s:", "- if bit in d:", "- break", "- else:", "- print(i)", "- break", "+", "+def v(n):", "+ for c in map(int, str(n)):", "+ if c in d:", "+ return False", "+ return True", "+", "+", "+while v(n) == False:", "+ n += 1", "+print(n)" ]
false
0.072611
0.083091
0.873871
[ "s500785182", "s774051850" ]
u334712262
p02679
python
s449719819
s355109736
762
521
223,304
168,104
Accepted
Accepted
31.63
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def f(a, b): if a == 0 and b == 0: return (1, 0, 0) if b == 0: return (1, 1, 0) g = math.gcd(a, b) a //= g b //= g if a == 0 and b < 0: s = 1 else: s = 1 if a * b >= 0 else -1 a = abs(a) b = abs(b) return s, a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m-2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: s, a, b = f(a, b) adb[(s*a, b)] += 1 error_print(adb) M = Mod(1000000007) ans = 1 done = set() for k, v in adb.items(): if k in done: continue if k == (0, 0): continue a, b = k if a < 0: s = 1 a = abs(a) elif a == 0: s = 1 else: s = -1 n = adb[(s*b, a)] done.add(k) done.add((s*b, a)) t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) return M.add(M.sub(ans, 1), adb[(0, 0)]) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def f(a, b): if a == 0 and b == 0: return (1, 0, 0) if b == 0: return (1, 1, 0) g = math.gcd(a, b) a //= g b //= g if a == 0 and b < 0: s = 1 else: s = 1 if a * b >= 0 else -1 a = abs(a) b = abs(b) return s, a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m-2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: s, a, b = f(a, b) adb[(s*a, b)] += 1 M = Mod(1000000007) ans = 1 done = set() for k, v in adb.items(): if k in done: continue if k == (0, 0): continue a, b = k if a < 0: s = 1 a = abs(a) elif a == 0: s = 1 else: s = -1 n = adb[(s*b, a)] done.add(k) done.add((s*b, a)) t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) return M.add(M.sub(ans, 1), adb[(0, 0)]) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == '__main__': main()
131
130
2,479
2,457
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def f(a, b): if a == 0 and b == 0: return (1, 0, 0) if b == 0: return (1, 1, 0) g = math.gcd(a, b) a //= g b //= g if a == 0 and b < 0: s = 1 else: s = 1 if a * b >= 0 else -1 a = abs(a) b = abs(b) return s, a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m - 2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: s, a, b = f(a, b) adb[(s * a, b)] += 1 error_print(adb) M = Mod(1000000007) ans = 1 done = set() for k, v in adb.items(): if k in done: continue if k == (0, 0): continue a, b = k if a < 0: s = 1 a = abs(a) elif a == 0: s = 1 else: s = -1 n = adb[(s * b, a)] done.add(k) done.add((s * b, a)) t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) return M.add(M.sub(ans, 1), adb[(0, 0)]) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import math import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def f(a, b): if a == 0 and b == 0: return (1, 0, 0) if b == 0: return (1, 1, 0) g = math.gcd(a, b) a //= g b //= g if a == 0 and b < 0: s = 1 else: s = 1 if a * b >= 0 else -1 a = abs(a) b = abs(b) return s, a, b class Mod: def __init__(self, m): self.m = m def add(self, a, b): return (a + b) % self.m def sub(self, a, b): return (a - b) % self.m def mul(self, a, b): return ((a % self.m) * (b % self.m)) % self.m def div(self, a, b): return self.mul(a, pow(b, self.m - 2, self.m)) def pow(self, a, b): return pow(a, b, self.m) @mt def slv(N, AB): adb = Counter() for a, b in AB: s, a, b = f(a, b) adb[(s * a, b)] += 1 M = Mod(1000000007) ans = 1 done = set() for k, v in adb.items(): if k in done: continue if k == (0, 0): continue a, b = k if a < 0: s = 1 a = abs(a) elif a == 0: s = 1 else: s = -1 n = adb[(s * b, a)] done.add(k) done.add((s * b, a)) t = M.sub(M.pow(2, v) + M.pow(2, n), 1) ans = M.mul(ans, t) return M.add(M.sub(ans, 1), adb[(0, 0)]) def main(): N = read_int() AB = [read_int_n() for _ in range(N)] print(slv(N, AB)) if __name__ == "__main__": main()
false
0.763359
[ "- error_print(adb)" ]
false
0.143035
0.108275
1.321031
[ "s449719819", "s355109736" ]
u185249212
p02690
python
s381066377
s319294315
499
201
78,340
78,232
Accepted
Accepted
59.72
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def check(a,b,x): a=round(a) return a**5 - b**5 == x def fifthroot(n): for i in range(int(n**(1/5)+1)) : if i**5==n: return i return -1 def main(): x = int(input().strip()) # b>=0 のとき # # # a=(x + b**5)**(1/5) # eprint('a ',end=':\n') # eprint(a) # if check(a,b,x): # eprint("b>=0") # print(int(a),b) # return # # if a.is_integer(): # eprint("b>=0") # print(a,b) # return # b<0の場合 for a in range(1,10**9): if x - a**5 < 0: break # b=(x - a**5) ** (1/5) b=fifthroot(x - a**5) if b!=-1: eprint("b<0") print(a,-int(b)) return for b in range(1,10**9): if fifthroot(x + b**5)!=-1: eprint("b>=0") a=fifthroot(x + b**5) print(a,b) return if __name__ == '__main__': main()
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def main(): x = int(input().strip()) for a in range(0,2000): for b in range(-100,2000): if a**5 - b**5 == x: print(a,b) return if __name__ == '__main__': main()
118
82
2,350
1,531
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def check(a, b, x): a = round(a) return a**5 - b**5 == x def fifthroot(n): for i in range(int(n ** (1 / 5) + 1)): if i**5 == n: return i return -1 def main(): x = int(input().strip()) # b>=0 のとき # # # a=(x + b**5)**(1/5) # eprint('a ',end=':\n') # eprint(a) # if check(a,b,x): # eprint("b>=0") # print(int(a),b) # return # # if a.is_integer(): # eprint("b>=0") # print(a,b) # return # b<0の場合 for a in range(1, 10**9): if x - a**5 < 0: break # b=(x - a**5) ** (1/5) b = fifthroot(x - a**5) if b != -1: eprint("b<0") print(a, -int(b)) return for b in range(1, 10**9): if fifthroot(x + b**5) != -1: eprint("b>=0") a = fifthroot(x + b**5) print(a, b) return if __name__ == "__main__": main()
import sys sys.setrecursionlimit(500000) import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return # from fractions import gcd # from math import gcd # def lcm(n, m): # return int(n * m / gcd(n, m)) # def coprimize(p, q): # common = gcd(p, q) # return (p // common, q // common) # def find_gcd(list_l): # x = reduce(gcd, list_l) # return x def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, list(range(n, n - r, -1)), 1) denom = reduce(mul, list(range(1, r + 1)), 1) return numer // denom def main(): x = int(input().strip()) for a in range(0, 2000): for b in range(-100, 2000): if a**5 - b**5 == x: print(a, b) return if __name__ == "__main__": main()
false
30.508475
[ "-def check(a, b, x):", "- a = round(a)", "- return a**5 - b**5 == x", "-", "-", "-def fifthroot(n):", "- for i in range(int(n ** (1 / 5) + 1)):", "- if i**5 == n:", "- return i", "- return -1", "-", "-", "- # b>=0 のとき", "- # #", "- # a=(x + b**5)**(1/5)", "- # eprint('a ',end=':\\n')", "- # eprint(a)", "- # if check(a,b,x):", "- # eprint(\"b>=0\")", "- # print(int(a),b)", "- # return", "- #", "- # if a.is_integer():", "- # eprint(\"b>=0\")", "- # print(a,b)", "- # return", "- # b<0の場合", "- for a in range(1, 10**9):", "- if x - a**5 < 0:", "- break", "- # b=(x - a**5) ** (1/5)", "- b = fifthroot(x - a**5)", "- if b != -1:", "- eprint(\"b<0\")", "- print(a, -int(b))", "- return", "- for b in range(1, 10**9):", "- if fifthroot(x + b**5) != -1:", "- eprint(\"b>=0\")", "- a = fifthroot(x + b**5)", "- print(a, b)", "- return", "+ for a in range(0, 2000):", "+ for b in range(-100, 2000):", "+ if a**5 - b**5 == x:", "+ print(a, b)", "+ return" ]
false
0.038912
0.085681
0.454156
[ "s381066377", "s319294315" ]
u539895865
p03455
python
s103483660
s528683168
28
23
9,008
9,108
Accepted
Accepted
17.86
a,b=list(map(int,input().split())) m=a*b if m%2==1: print('Odd') else: print('Even')
a,b=list(map(int,input().split(' '))) m=a*b if m%2==1: print('Odd') else: print('Even')
6
6
87
90
a, b = list(map(int, input().split())) m = a * b if m % 2 == 1: print("Odd") else: print("Even")
a, b = list(map(int, input().split(" "))) m = a * b if m % 2 == 1: print("Odd") else: print("Even")
false
0
[ "-a, b = list(map(int, input().split()))", "+a, b = list(map(int, input().split(\" \")))" ]
false
0.049118
0.172227
0.285195
[ "s103483660", "s528683168" ]
u440566786
p02860
python
s353352598
s706235612
189
168
38,384
38,256
Accepted
Accepted
11.11
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n=int(eval(input())) if(n&1): print("No") return S=eval(input()) a=S[:n//2] b=S[n//2:] print(("Yes" if(a==b) else "No")) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n=int(eval(input())) if(n&1): print("No") return S=eval(input()) print(("Yes" if(S[:n//2]==S[n//2:]) else "No")) resolve()
15
14
303
286
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n = int(eval(input())) if n & 1: print("No") return S = eval(input()) a = S[: n // 2] b = S[n // 2 :] print(("Yes" if (a == b) else "No")) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n = int(eval(input())) if n & 1: print("No") return S = eval(input()) print(("Yes" if (S[: n // 2] == S[n // 2 :]) else "No")) resolve()
false
6.666667
[ "- a = S[: n // 2]", "- b = S[n // 2 :]", "- print((\"Yes\" if (a == b) else \"No\"))", "+ print((\"Yes\" if (S[: n // 2] == S[n // 2 :]) else \"No\"))" ]
false
0.033642
0.031162
1.079578
[ "s353352598", "s706235612" ]
u221301671
p02713
python
s013462481
s739030667
833
680
9,212
9,096
Accepted
Accepted
18.37
k = int(eval(input())) s = 0 for i1 in range(1, k+1): for i2 in range(1, i1+1): x1, x2 = i1, i2 while x2 != 0: x1, x2 = x2, x1 % x2 gcd1 = x1 s2 = i1 == i2 for i3 in range(i1, k+1): x1, x2 = gcd1, i3 while x2 != 0: x1, x2 = x2, x1 % x2 gcd2 = x1 s3 = i2 == i3 or i1 == i3 if s2 and s3: s = s + gcd2 elif s2 or s3: s = s + gcd2*3 else: s = s + gcd2*6 print(s)
k = int(eval(input())) s = 0 # 3つ違う for i1 in range(1, k+1): s = s + i1 for i2 in range(1, i1): x1, x2 = i1, i2 while x2 != 0: x1, x2 = x2, x1 % x2 gcd1 = x1 s = s + gcd1 * 6 for i3 in range(i1+1, k+1): x1, x2 = gcd1, i3 while x2 != 0: x1, x2 = x2, x1 % x2 gcd2 = x1 s = s + gcd2 * 6 print(s)
24
20
582
432
k = int(eval(input())) s = 0 for i1 in range(1, k + 1): for i2 in range(1, i1 + 1): x1, x2 = i1, i2 while x2 != 0: x1, x2 = x2, x1 % x2 gcd1 = x1 s2 = i1 == i2 for i3 in range(i1, k + 1): x1, x2 = gcd1, i3 while x2 != 0: x1, x2 = x2, x1 % x2 gcd2 = x1 s3 = i2 == i3 or i1 == i3 if s2 and s3: s = s + gcd2 elif s2 or s3: s = s + gcd2 * 3 else: s = s + gcd2 * 6 print(s)
k = int(eval(input())) s = 0 # 3つ違う for i1 in range(1, k + 1): s = s + i1 for i2 in range(1, i1): x1, x2 = i1, i2 while x2 != 0: x1, x2 = x2, x1 % x2 gcd1 = x1 s = s + gcd1 * 6 for i3 in range(i1 + 1, k + 1): x1, x2 = gcd1, i3 while x2 != 0: x1, x2 = x2, x1 % x2 gcd2 = x1 s = s + gcd2 * 6 print(s)
false
16.666667
[ "+# 3つ違う", "- for i2 in range(1, i1 + 1):", "+ s = s + i1", "+ for i2 in range(1, i1):", "- s2 = i1 == i2", "- for i3 in range(i1, k + 1):", "+ s = s + gcd1 * 6", "+ for i3 in range(i1 + 1, k + 1):", "- s3 = i2 == i3 or i1 == i3", "- if s2 and s3:", "- s = s + gcd2", "- elif s2 or s3:", "- s = s + gcd2 * 3", "- else:", "- s = s + gcd2 * 6", "+ s = s + gcd2 * 6" ]
false
0.076965
0.079244
0.971248
[ "s013462481", "s739030667" ]
u687574784
p02983
python
s459659567
s183246513
1,226
54
3,188
10,696
Accepted
Accepted
95.6
def mod2019(x, y): return (x%2019 * y%2019 ) % 2019 L,R = list(map(int, input().split())) ans=2019 s=set() for i in range(L,R+1): if i%2019 in s: break s.add(i%2019) l = list(s) for i in range(len(l)): for j in range(i+1, len(l)): # print(i, j, l[i], l[j], mod2019(l[i], l[j])) ans=min(ans, mod2019(l[i], l[j])) print(ans)
L,R = list(map(int, input().split())) if R-L >= 2019: print((0)) exit() s=set() for i in range(L,R+1): if i%2019 in s: break s.add(i%2019) l = list(s) if 3 in l and 673 in l: print((0)) exit() print((min([(i*j)%2019 for i in l for j in l if i != j])))
17
17
383
304
def mod2019(x, y): return (x % 2019 * y % 2019) % 2019 L, R = list(map(int, input().split())) ans = 2019 s = set() for i in range(L, R + 1): if i % 2019 in s: break s.add(i % 2019) l = list(s) for i in range(len(l)): for j in range(i + 1, len(l)): # print(i, j, l[i], l[j], mod2019(l[i], l[j])) ans = min(ans, mod2019(l[i], l[j])) print(ans)
L, R = list(map(int, input().split())) if R - L >= 2019: print((0)) exit() s = set() for i in range(L, R + 1): if i % 2019 in s: break s.add(i % 2019) l = list(s) if 3 in l and 673 in l: print((0)) exit() print((min([(i * j) % 2019 for i in l for j in l if i != j])))
false
0
[ "-def mod2019(x, y):", "- return (x % 2019 * y % 2019) % 2019", "-", "-", "-ans = 2019", "+if R - L >= 2019:", "+ print((0))", "+ exit()", "-for i in range(len(l)):", "- for j in range(i + 1, len(l)):", "- # print(i, j, l[i], l[j], mod2019(l[i], l[j]))", "- ans = min(ans, mod2019(l[i], l[j]))", "-print(ans)", "+if 3 in l and 673 in l:", "+ print((0))", "+ exit()", "+print((min([(i * j) % 2019 for i in l for j in l if i != j])))" ]
false
0.178849
0.041772
4.281547
[ "s459659567", "s183246513" ]
u020390084
p02971
python
s020788463
s363473219
549
350
14,108
14,104
Accepted
Accepted
36.25
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] sortA = sorted(a, reverse=True) maxA = sortA[0] semiMaxA = sortA[1] for i in range(n): if a[i] == maxA: print(semiMaxA) else: print(maxA)
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[int]"): B = sorted(A) max_A = B[-1] submax_A = B[-2] for i in range(N): if A[i] == max_A: print(submax_A) else: print(max_A) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
12
28
216
609
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] sortA = sorted(a, reverse=True) maxA = sortA[0] semiMaxA = sortA[1] for i in range(n): if a[i] == maxA: print(semiMaxA) else: print(maxA)
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[int]"): B = sorted(A) max_A = B[-1] submax_A = B[-2] for i in range(N): if A[i] == max_A: print(submax_A) else: print(max_A) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == "__main__": main()
false
57.142857
[ "-n = int(eval(input()))", "-a = [int(eval(input())) for _ in range(n)]", "-sortA = sorted(a, reverse=True)", "-maxA = sortA[0]", "-semiMaxA = sortA[1]", "-for i in range(n):", "- if a[i] == maxA:", "- print(semiMaxA)", "- else:", "- print(maxA)", "+#!/usr/bin/env python3", "+import sys", "+", "+", "+def solve(N: int, A: \"List[int]\"):", "+ B = sorted(A)", "+ max_A = B[-1]", "+ submax_A = B[-2]", "+ for i in range(N):", "+ if A[i] == max_A:", "+ print(submax_A)", "+ else:", "+ print(max_A)", "+ return", "+", "+", "+def main():", "+ def iterate_tokens():", "+ for line in sys.stdin:", "+ for word in line.split():", "+ yield word", "+", "+ tokens = iterate_tokens()", "+ N = int(next(tokens)) # type: int", "+ A = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"", "+ solve(N, A)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.04113
0.042523
0.967236
[ "s020788463", "s363473219" ]
u729133443
p04003
python
s014781845
s150736330
2,574
2,257
178,068
182,140
Accepted
Accepted
12.32
def main(): from heapq import heappush,heappop,heapify inf=2**31-1 n,m,*t=list(map(int,open(0).read().split())) z=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): z.extend([a,b,a+n*c,b+n*c]) z={i:v for v,i in enumerate(sorted(set(z)))} try: z[1] except: print((-1)) exit() edge=[[]for _ in range(len(z))] d={} l=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): if b<a:a,b=b,a i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c] if b==n: l.append(y) edge[i].append((1,x)) edge[j].append((1,y)) edge[x].extend([(0,i),(0,y)]) edge[y].extend([(0,j),(0,x)]) used=[False]+[True]*~-len(z) d=[0]+[inf]*~-len(z) edgelist=edge[0] heapify(edgelist) while edgelist: m=heappop(edgelist) if not used[m[1]]: continue d[m[1]]=m[0] used[m[1]]=False for e in edge[m[1]]: if used[e[1]]: heappush(edgelist,(e[0]+m[0],e[1])) a=min([d[i]for i in l]or[inf]) print(([a,-1][a==inf])) if __name__=='__main__': main()
from subprocess import* call(('pypy3','-c',""" def main(): from heapq import heappush,heappop,heapify inf=2**31-1 n,m,*t=map(int,open(0).read().split()) z=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): z.extend([a,b,a+n*c,b+n*c]) z={i:v for v,i in enumerate(sorted(set(z)))} try: z[1] except: print(-1) exit() edge=[[]for _ in range(len(z))] d={} l=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): if b<a:a,b=b,a i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c] if b==n: l.append(y) edge[i].append((1,x)) edge[j].append((1,y)) edge[x].extend([(0,i),(0,y)]) edge[y].extend([(0,j),(0,x)]) used=[False]+[True]*~-len(z) d=[0]+[inf]*~-len(z) edgelist=edge[0] heapify(edgelist) while edgelist: m=heappop(edgelist) if not used[m[1]]: continue d[m[1]]=m[0] used[m[1]]=False for e in edge[m[1]]: if used[e[1]]: heappush(edgelist,(e[0]+m[0],e[1])) a=min([d[i]for i in l]or[inf]) print([a,-1][a==inf]) if __name__=='__main__': main() """))
42
45
1,027
1,083
def main(): from heapq import heappush, heappop, heapify inf = 2**31 - 1 n, m, *t = list(map(int, open(0).read().split())) z = [] for a, b, c in zip(t[::3], t[1::3], t[2::3]): z.extend([a, b, a + n * c, b + n * c]) z = {i: v for v, i in enumerate(sorted(set(z)))} try: z[1] except: print((-1)) exit() edge = [[] for _ in range(len(z))] d = {} l = [] for a, b, c in zip(t[::3], t[1::3], t[2::3]): if b < a: a, b = b, a i, j, x, y = z[a], z[b], z[a + n * c], z[b + n * c] if b == n: l.append(y) edge[i].append((1, x)) edge[j].append((1, y)) edge[x].extend([(0, i), (0, y)]) edge[y].extend([(0, j), (0, x)]) used = [False] + [True] * ~-len(z) d = [0] + [inf] * ~-len(z) edgelist = edge[0] heapify(edgelist) while edgelist: m = heappop(edgelist) if not used[m[1]]: continue d[m[1]] = m[0] used[m[1]] = False for e in edge[m[1]]: if used[e[1]]: heappush(edgelist, (e[0] + m[0], e[1])) a = min([d[i] for i in l] or [inf]) print(([a, -1][a == inf])) if __name__ == "__main__": main()
from subprocess import * call( ( "pypy3", "-c", """ def main(): from heapq import heappush,heappop,heapify inf=2**31-1 n,m,*t=map(int,open(0).read().split()) z=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): z.extend([a,b,a+n*c,b+n*c]) z={i:v for v,i in enumerate(sorted(set(z)))} try: z[1] except: print(-1) exit() edge=[[]for _ in range(len(z))] d={} l=[] for a,b,c in zip(t[::3],t[1::3],t[2::3]): if b<a:a,b=b,a i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c] if b==n: l.append(y) edge[i].append((1,x)) edge[j].append((1,y)) edge[x].extend([(0,i),(0,y)]) edge[y].extend([(0,j),(0,x)]) used=[False]+[True]*~-len(z) d=[0]+[inf]*~-len(z) edgelist=edge[0] heapify(edgelist) while edgelist: m=heappop(edgelist) if not used[m[1]]: continue d[m[1]]=m[0] used[m[1]]=False for e in edge[m[1]]: if used[e[1]]: heappush(edgelist,(e[0]+m[0],e[1])) a=min([d[i]for i in l]or[inf]) print([a,-1][a==inf]) if __name__=='__main__': main() """, ) )
false
6.666667
[ "+from subprocess import *", "+", "+call(", "+ (", "+ \"pypy3\",", "+ \"-c\",", "+ \"\"\"", "- from heapq import heappush, heappop, heapify", "-", "- inf = 2**31 - 1", "- n, m, *t = list(map(int, open(0).read().split()))", "- z = []", "- for a, b, c in zip(t[::3], t[1::3], t[2::3]):", "- z.extend([a, b, a + n * c, b + n * c])", "- z = {i: v for v, i in enumerate(sorted(set(z)))}", "- try:", "- z[1]", "- except:", "- print((-1))", "- exit()", "- edge = [[] for _ in range(len(z))]", "- d = {}", "- l = []", "- for a, b, c in zip(t[::3], t[1::3], t[2::3]):", "- if b < a:", "- a, b = b, a", "- i, j, x, y = z[a], z[b], z[a + n * c], z[b + n * c]", "- if b == n:", "- l.append(y)", "- edge[i].append((1, x))", "- edge[j].append((1, y))", "- edge[x].extend([(0, i), (0, y)])", "- edge[y].extend([(0, j), (0, x)])", "- used = [False] + [True] * ~-len(z)", "- d = [0] + [inf] * ~-len(z)", "- edgelist = edge[0]", "- heapify(edgelist)", "- while edgelist:", "- m = heappop(edgelist)", "- if not used[m[1]]:", "- continue", "- d[m[1]] = m[0]", "- used[m[1]] = False", "- for e in edge[m[1]]:", "- if used[e[1]]:", "- heappush(edgelist, (e[0] + m[0], e[1]))", "- a = min([d[i] for i in l] or [inf])", "- print(([a, -1][a == inf]))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+ from heapq import heappush,heappop,heapify", "+ inf=2**31-1", "+ n,m,*t=map(int,open(0).read().split())", "+ z=[]", "+ for a,b,c in zip(t[::3],t[1::3],t[2::3]):", "+ z.extend([a,b,a+n*c,b+n*c])", "+ z={i:v for v,i in enumerate(sorted(set(z)))}", "+ try:", "+ z[1]", "+ except:", "+ print(-1)", "+ exit()", "+ edge=[[]for _ in range(len(z))]", "+ d={}", "+ l=[]", "+ for a,b,c in zip(t[::3],t[1::3],t[2::3]):", "+ if b<a:a,b=b,a", "+ i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c]", "+ if b==n:", "+ l.append(y)", "+ edge[i].append((1,x))", "+ edge[j].append((1,y))", "+ edge[x].extend([(0,i),(0,y)])", "+ edge[y].extend([(0,j),(0,x)])", "+ used=[False]+[True]*~-len(z)", "+ d=[0]+[inf]*~-len(z)", "+ edgelist=edge[0]", "+ heapify(edgelist)", "+ while edgelist:", "+ m=heappop(edgelist)", "+ if not used[m[1]]:", "+ continue", "+ d[m[1]]=m[0]", "+ used[m[1]]=False", "+ for e in edge[m[1]]:", "+ if used[e[1]]:", "+ heappush(edgelist,(e[0]+m[0],e[1]))", "+ a=min([d[i]for i in l]or[inf])", "+ print([a,-1][a==inf])", "+if __name__=='__main__':", "+ main()", "+\"\"\",", "+ )", "+)" ]
false
0.039313
0.048013
0.818806
[ "s014781845", "s150736330" ]
u059210959
p02601
python
s380402172
s735814787
47
39
10,924
10,760
Accepted
Accepted
17.02
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) A, B, C = LI() K = int(eval(input())) for k in range(K): if A < B: C *= 2 else: B *= 2 if A < B and B < C: print("Yes") else: print("No")
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) # A, B, C = LI() # K = int(input()) # for k in range(K): # if A < B: # C *= 2 # else: # B *= 2 # if A < B and B < C: # print("Yes") # else: # print("No") A, B, C = LI() K = int(eval(input())) for k in range(K): if A >= B: B *= 2 else: C *= 2 if A < B < C: print("Yes") else: print("No")
30
43
569
765
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) A, B, C = LI() K = int(eval(input())) for k in range(K): if A < B: C *= 2 else: B *= 2 if A < B and B < C: print("Yes") else: print("No")
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) # A, B, C = LI() # K = int(input()) # for k in range(K): # if A < B: # C *= 2 # else: # B *= 2 # if A < B and B < C: # print("Yes") # else: # print("No") A, B, C = LI() K = int(eval(input())) for k in range(K): if A >= B: B *= 2 else: C *= 2 if A < B < C: print("Yes") else: print("No")
false
30.232558
[ "+# A, B, C = LI()", "+# K = int(input())", "+# for k in range(K):", "+# if A < B:", "+# C *= 2", "+# else:", "+# B *= 2", "+# if A < B and B < C:", "+# print(\"Yes\")", "+# else:", "+# print(\"No\")", "- if A < B:", "+ if A >= B:", "+ B *= 2", "+ else:", "- else:", "- B *= 2", "-if A < B and B < C:", "+if A < B < C:" ]
false
0.045427
0.045451
0.99947
[ "s380402172", "s735814787" ]
u730769327
p03546
python
s025394133
s799942147
82
47
74,012
9,420
Accepted
Accepted
42.68
h,w=list(map(int,input().split())) n=10 dis=[list(map(int,input().split())) for _ in range(n)] a=[list(map(int,input().split())) for _ in range(h)] for k in range(n): for i in range(n): for j in range(n): dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]) ans=0 for i in range(h): for j in range(w): if a[i][j]!=-1:ans+=dis[a[i][j]][1] print(ans)
INF=10**18 n=10 h,w=list(map(int,input().split())) dist=[list(map(int,input().split())) for _ in range(n)] a=[list(map(int,input().split())) for _ in range(h)] for k in range(n): for i in range(n): for j in range(n): dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]) ans=0 for i in range(h): for j in range(w): if a[i][j]==-1:continue ans+=dist[a[i][j]][1] print(ans)
13
15
364
396
h, w = list(map(int, input().split())) n = 10 dis = [list(map(int, input().split())) for _ in range(n)] a = [list(map(int, input().split())) for _ in range(h)] for k in range(n): for i in range(n): for j in range(n): dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) ans = 0 for i in range(h): for j in range(w): if a[i][j] != -1: ans += dis[a[i][j]][1] print(ans)
INF = 10**18 n = 10 h, w = list(map(int, input().split())) dist = [list(map(int, input().split())) for _ in range(n)] a = [list(map(int, input().split())) for _ in range(h)] for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) ans = 0 for i in range(h): for j in range(w): if a[i][j] == -1: continue ans += dist[a[i][j]][1] print(ans)
false
13.333333
[ "+INF = 10**18", "+n = 10", "-n = 10", "-dis = [list(map(int, input().split())) for _ in range(n)]", "+dist = [list(map(int, input().split())) for _ in range(n)]", "- dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])", "+ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "- if a[i][j] != -1:", "- ans += dis[a[i][j]][1]", "+ if a[i][j] == -1:", "+ continue", "+ ans += dist[a[i][j]][1]" ]
false
0.085865
0.048011
1.788451
[ "s025394133", "s799942147" ]
u690536347
p03765
python
s610837537
s473295997
1,239
1,089
121,312
53,848
Accepted
Accepted
12.11
from operator import add import sys input=sys.stdin.readline class SegTree(): def __init__(self, N, e, operator_func=add): self.e = e # 単位元 self.size = N self.node = [self.e] * (2*N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i+self.size-1] = l[i] for i in range(self.size-1)[::-1]: self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2]) def update(self, k, x): k += self.size-1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2]) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l<r: if l&1: x = self.operator_func(x, self.node[l-1]) l += 1 if r&1: r -= 1 x = self.operator_func(x, self.node[r-1]) l >>= 1 r >>= 1 return x def main(): S = eval(input()) T = eval(input()) treeS = SegTree(len(S), 0) treeT = SegTree(len(T), 0) treeS.set_list([1 if s=="A" else 0 for s in S]) treeT.set_list([1 if s=="A" else 0 for s in T]) q = int(eval(input())) for _ in range(q): a, b, c, d = list(map(int, input().split())) sa = treeS.get(a-1, b) sb = b-a+1-sa ta = treeT.get(c-1, d) tb = d-c+1-ta if (2*(sb-sa)+tb-ta)%3 or (sb-sa+2*(tb-ta))%3: print("NO") else: print("YES") main()
S, T = eval(input()), eval(input()) q = int(eval(input())) ls, lt = len(S), len(T) acs, act = [0]*(ls+1), [0]*(lt+1) for i in range(1, ls+1): acs[i] = acs[i-1] + (S[i-1]=="A") for i in range(1, lt+1): act[i] = act[i-1] + (T[i-1]=="A") for _ in range(q): a, b, c, d = list(map(int, input().split())) sa = acs[b]-acs[a-1] sb = b-a+1-sa ta = act[d]-act[c-1] tb = d-c+1-ta print(("YES" if (2*sa+sb)%3==(2*ta+tb)%3 else "NO"))
65
18
1,733
448
from operator import add import sys input = sys.stdin.readline class SegTree: def __init__(self, N, e, operator_func=add): self.e = e # 単位元 self.size = N self.node = [self.e] * (2 * N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i + self.size - 1] = l[i] for i in range(self.size - 1)[::-1]: self.node[i] = self.operator_func( self.node[2 * i + 1], self.node[2 * i + 2] ) def update(self, k, x): k += self.size - 1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func( self.node[2 * k + 1], self.node[2 * k + 2] ) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l < r: if l & 1: x = self.operator_func(x, self.node[l - 1]) l += 1 if r & 1: r -= 1 x = self.operator_func(x, self.node[r - 1]) l >>= 1 r >>= 1 return x def main(): S = eval(input()) T = eval(input()) treeS = SegTree(len(S), 0) treeT = SegTree(len(T), 0) treeS.set_list([1 if s == "A" else 0 for s in S]) treeT.set_list([1 if s == "A" else 0 for s in T]) q = int(eval(input())) for _ in range(q): a, b, c, d = list(map(int, input().split())) sa = treeS.get(a - 1, b) sb = b - a + 1 - sa ta = treeT.get(c - 1, d) tb = d - c + 1 - ta if (2 * (sb - sa) + tb - ta) % 3 or (sb - sa + 2 * (tb - ta)) % 3: print("NO") else: print("YES") main()
S, T = eval(input()), eval(input()) q = int(eval(input())) ls, lt = len(S), len(T) acs, act = [0] * (ls + 1), [0] * (lt + 1) for i in range(1, ls + 1): acs[i] = acs[i - 1] + (S[i - 1] == "A") for i in range(1, lt + 1): act[i] = act[i - 1] + (T[i - 1] == "A") for _ in range(q): a, b, c, d = list(map(int, input().split())) sa = acs[b] - acs[a - 1] sb = b - a + 1 - sa ta = act[d] - act[c - 1] tb = d - c + 1 - ta print(("YES" if (2 * sa + sb) % 3 == (2 * ta + tb) % 3 else "NO"))
false
72.307692
[ "-from operator import add", "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "-class SegTree:", "- def __init__(self, N, e, operator_func=add):", "- self.e = e # 単位元", "- self.size = N", "- self.node = [self.e] * (2 * N)", "- self.operator_func = operator_func # 処理(add or xor max minなど)", "-", "- def set_list(self, l):", "- for i in range(self.size):", "- self.node[i + self.size - 1] = l[i]", "- for i in range(self.size - 1)[::-1]:", "- self.node[i] = self.operator_func(", "- self.node[2 * i + 1], self.node[2 * i + 2]", "- )", "-", "- def update(self, k, x):", "- k += self.size - 1", "- self.node[k] = x", "- while k >= 0:", "- k = (k - 1) // 2", "- self.node[k] = self.operator_func(", "- self.node[2 * k + 1], self.node[2 * k + 2]", "- )", "-", "- def get(self, l, r):", "- # [l, r) についてqueryを求める", "- x = self.e", "- l += self.size", "- r += self.size", "- while l < r:", "- if l & 1:", "- x = self.operator_func(x, self.node[l - 1])", "- l += 1", "- if r & 1:", "- r -= 1", "- x = self.operator_func(x, self.node[r - 1])", "- l >>= 1", "- r >>= 1", "- return x", "-", "-", "-def main():", "- S = eval(input())", "- T = eval(input())", "- treeS = SegTree(len(S), 0)", "- treeT = SegTree(len(T), 0)", "- treeS.set_list([1 if s == \"A\" else 0 for s in S])", "- treeT.set_list([1 if s == \"A\" else 0 for s in T])", "- q = int(eval(input()))", "- for _ in range(q):", "- a, b, c, d = list(map(int, input().split()))", "- sa = treeS.get(a - 1, b)", "- sb = b - a + 1 - sa", "- ta = treeT.get(c - 1, d)", "- tb = d - c + 1 - ta", "- if (2 * (sb - sa) + tb - ta) % 3 or (sb - sa + 2 * (tb - ta)) % 3:", "- print(\"NO\")", "- else:", "- print(\"YES\")", "-", "-", "-main()", "+S, T = eval(input()), eval(input())", "+q = int(eval(input()))", "+ls, lt = len(S), len(T)", "+acs, act = [0] * (ls + 1), [0] * (lt + 1)", "+for i in range(1, ls + 1):", "+ acs[i] = acs[i - 1] + (S[i - 1] == \"A\")", "+for i in range(1, lt + 1):", "+ act[i] = act[i - 1] + (T[i - 1] == \"A\")", "+for _ in range(q):", "+ a, b, c, d = list(map(int, input().split()))", "+ sa = acs[b] - acs[a - 1]", "+ sb = b - a + 1 - sa", "+ ta = act[d] - act[c - 1]", "+ tb = d - c + 1 - ta", "+ print((\"YES\" if (2 * sa + sb) % 3 == (2 * ta + tb) % 3 else \"NO\"))" ]
false
0.039597
0.04432
0.89344
[ "s610837537", "s473295997" ]
u242890210
p02700
python
s623333294
s858026146
23
20
9,172
9,172
Accepted
Accepted
13.04
[A, B, C, D] = list(map(int, input().split())) while A > 0: C -= B if C <= 0: print('Yes') break A -= D if A <= 0: print('No') break
import math [A, B, C, D] = list(map(int, input().split())) X = math.ceil(A / D) Y = math.ceil(C / B) if Y > X: print('No') else: print('Yes')
10
8
189
156
[A, B, C, D] = list(map(int, input().split())) while A > 0: C -= B if C <= 0: print("Yes") break A -= D if A <= 0: print("No") break
import math [A, B, C, D] = list(map(int, input().split())) X = math.ceil(A / D) Y = math.ceil(C / B) if Y > X: print("No") else: print("Yes")
false
20
[ "+import math", "+", "-while A > 0:", "- C -= B", "- if C <= 0:", "- print(\"Yes\")", "- break", "- A -= D", "- if A <= 0:", "- print(\"No\")", "- break", "+X = math.ceil(A / D)", "+Y = math.ceil(C / B)", "+if Y > X:", "+ print(\"No\")", "+else:", "+ print(\"Yes\")" ]
false
0.077259
0.04215
1.832937
[ "s623333294", "s858026146" ]
u076917070
p02868
python
s705531356
s114626285
722
630
89,648
79,024
Accepted
Accepted
12.74
import sys import heapq input = sys.stdin.readline def dijkstra(s, E): inf = float('inf') d = [inf for i in range(len(E))] d[s] = 0 q = [(0, s)] heapq.heapify(q) while q: c, p = heapq.heappop(q) if d[p] < c: continue for cost, to in E[p]: if d[to] > d[p] + cost: d[to] = d[p] + cost heapq.heappush(q, (d[to], to)) return d def main(): N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): s, t, c = list(map(int, input().split())) E[s-1].append([c, t-1]) for i in range(N-1): E[i+1].append([0, i]) A = dijkstra(0, E) ans = A[N-1] if ans == float("inf"): print((-1)) else: print(ans) if __name__ == '__main__': main()
import sys import heapq input = sys.stdin.readline def dijkstra(s, E): inf = float('inf') d = [inf for i in range(len(E))] d[s] = 0 q = [(0, s)] while q: c, p = heapq.heappop(q) if d[p] < c: continue for cost, to in E[p]: if d[to] > d[p] + cost: d[to] = d[p] + cost heapq.heappush(q, (d[to], to)) return d def main(): N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): s, t, c = list(map(int, input().split())) E[s-1].append((c, t-1)) for i in range(N-1): E[i+1].append((0, i)) A = dijkstra(0, E) ans = A[N-1] if ans == float("inf"): print((-1)) else: print(ans) if __name__ == '__main__': main()
42
41
867
845
import sys import heapq input = sys.stdin.readline def dijkstra(s, E): inf = float("inf") d = [inf for i in range(len(E))] d[s] = 0 q = [(0, s)] heapq.heapify(q) while q: c, p = heapq.heappop(q) if d[p] < c: continue for cost, to in E[p]: if d[to] > d[p] + cost: d[to] = d[p] + cost heapq.heappush(q, (d[to], to)) return d def main(): N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): s, t, c = list(map(int, input().split())) E[s - 1].append([c, t - 1]) for i in range(N - 1): E[i + 1].append([0, i]) A = dijkstra(0, E) ans = A[N - 1] if ans == float("inf"): print((-1)) else: print(ans) if __name__ == "__main__": main()
import sys import heapq input = sys.stdin.readline def dijkstra(s, E): inf = float("inf") d = [inf for i in range(len(E))] d[s] = 0 q = [(0, s)] while q: c, p = heapq.heappop(q) if d[p] < c: continue for cost, to in E[p]: if d[to] > d[p] + cost: d[to] = d[p] + cost heapq.heappush(q, (d[to], to)) return d def main(): N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): s, t, c = list(map(int, input().split())) E[s - 1].append((c, t - 1)) for i in range(N - 1): E[i + 1].append((0, i)) A = dijkstra(0, E) ans = A[N - 1] if ans == float("inf"): print((-1)) else: print(ans) if __name__ == "__main__": main()
false
2.380952
[ "- heapq.heapify(q)", "- E[s - 1].append([c, t - 1])", "+ E[s - 1].append((c, t - 1))", "- E[i + 1].append([0, i])", "+ E[i + 1].append((0, i))" ]
false
0.039287
0.047612
0.825147
[ "s705531356", "s114626285" ]
u130900604
p03240
python
s231861944
s171775720
405
261
9,048
70,616
Accepted
Accepted
35.56
n=int(eval(input())) x=[-1]*n y=[-1]*n h=[-1]*n for i in range(n): x[i],y[i],h[i]=list(map(int,input().split())) cnt=0 now=0 for i in range(n): if h[i]>0: cnt+=1 now=i if cnt==1: print((x[now],y[now],h[now])) exit() for cx in range(0,101): for cy in range(0,101): H=[] for i in range(n): if h[i]>0: H.append(h[i]+abs(cx-x[i])+abs(cy-y[i])) if len(set(H))==1: print((cx,cy,H[0])) exit()
n=int(eval(input())) x=[-1]*n y=[-1]*n h=[-1]*n for i in range(n): x[i],y[i],h[i]=list(map(int,input().split())) mh=max(h) for cx in range(0,101): for cy in range(0,101): for H in range(mh,mh+216): if all(h[j]==max(H-abs(cx-x[j])-abs(cy-y[j]),0) for j in range(n)): print((cx,cy,H)) exit()
26
14
455
320
n = int(eval(input())) x = [-1] * n y = [-1] * n h = [-1] * n for i in range(n): x[i], y[i], h[i] = list(map(int, input().split())) cnt = 0 now = 0 for i in range(n): if h[i] > 0: cnt += 1 now = i if cnt == 1: print((x[now], y[now], h[now])) exit() for cx in range(0, 101): for cy in range(0, 101): H = [] for i in range(n): if h[i] > 0: H.append(h[i] + abs(cx - x[i]) + abs(cy - y[i])) if len(set(H)) == 1: print((cx, cy, H[0])) exit()
n = int(eval(input())) x = [-1] * n y = [-1] * n h = [-1] * n for i in range(n): x[i], y[i], h[i] = list(map(int, input().split())) mh = max(h) for cx in range(0, 101): for cy in range(0, 101): for H in range(mh, mh + 216): if all( h[j] == max(H - abs(cx - x[j]) - abs(cy - y[j]), 0) for j in range(n) ): print((cx, cy, H)) exit()
false
46.153846
[ "-cnt = 0", "-now = 0", "-for i in range(n):", "- if h[i] > 0:", "- cnt += 1", "- now = i", "-if cnt == 1:", "- print((x[now], y[now], h[now]))", "- exit()", "+mh = max(h)", "- H = []", "- for i in range(n):", "- if h[i] > 0:", "- H.append(h[i] + abs(cx - x[i]) + abs(cy - y[i]))", "- if len(set(H)) == 1:", "- print((cx, cy, H[0]))", "- exit()", "+ for H in range(mh, mh + 216):", "+ if all(", "+ h[j] == max(H - abs(cx - x[j]) - abs(cy - y[j]), 0) for j in range(n)", "+ ):", "+ print((cx, cy, H))", "+ exit()" ]
false
0.102005
1.236209
0.082514
[ "s231861944", "s171775720" ]
u360038884
p03448
python
s622206745
s376372516
52
19
3,060
3,060
Accepted
Accepted
63.46
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if X == i * 500 + j * 100 + k * 50: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for i in range(A + 1): for j in range(B + 1): y = X - i * 500 - j * 100 if y % 50 == 0 and 0 <= y <=50*C: cnt += 1 print(cnt)
13
13
242
241
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): if X == i * 500 + j * 100 + k * 50: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for i in range(A + 1): for j in range(B + 1): y = X - i * 500 - j * 100 if y % 50 == 0 and 0 <= y <= 50 * C: cnt += 1 print(cnt)
false
0
[ "- for k in range(C + 1):", "- if X == i * 500 + j * 100 + k * 50:", "- cnt += 1", "+ y = X - i * 500 - j * 100", "+ if y % 50 == 0 and 0 <= y <= 50 * C:", "+ cnt += 1" ]
false
0.066519
0.034435
1.931707
[ "s622206745", "s376372516" ]
u312025627
p03038
python
s856454003
s770026733
619
415
82,104
101,044
Accepted
Accepted
32.96
def main(): import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop, heapify N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] BC = [[int(i) for i in input().split()] for j in range(M)] heapify(A) BC.sort(key=lambda p: p[1], reverse=True) j = 0 while j < M: a = heappop(A) c = BC[j][1] if c <= a: heappush(A, a) break else: heappush(A, c) BC[j][0] -= 1 if BC[j][0] == 0: j += 1 # print(A) print((sum(A))) if __name__ == '__main__': main()
def main(): from heapq import heapify, heappushpop _, M = (int(i) for i in input().split()) A = ([int(i) for i in input().split()]) BC = [[int(i) for i in input().split()] for j in range(M)] heapify(A) BC.sort(lambda p: p[1], reverse=True) for b, c in BC: if A[0] >= c: break for _ in range(b): if A[0] >= c: break heappushpop(A, c) print((sum(A))) if __name__ == '__main__': main()
27
20
679
507
def main(): import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop, heapify N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] BC = [[int(i) for i in input().split()] for j in range(M)] heapify(A) BC.sort(key=lambda p: p[1], reverse=True) j = 0 while j < M: a = heappop(A) c = BC[j][1] if c <= a: heappush(A, a) break else: heappush(A, c) BC[j][0] -= 1 if BC[j][0] == 0: j += 1 # print(A) print((sum(A))) if __name__ == "__main__": main()
def main(): from heapq import heapify, heappushpop _, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] BC = [[int(i) for i in input().split()] for j in range(M)] heapify(A) BC.sort(lambda p: p[1], reverse=True) for b, c in BC: if A[0] >= c: break for _ in range(b): if A[0] >= c: break heappushpop(A, c) print((sum(A))) if __name__ == "__main__": main()
false
25.925926
[ "- import sys", "+ from heapq import heapify, heappushpop", "- input = sys.stdin.buffer.readline", "- from heapq import heappush, heappop, heapify", "-", "- N, M = (int(i) for i in input().split())", "+ _, M = (int(i) for i in input().split())", "- BC.sort(key=lambda p: p[1], reverse=True)", "- j = 0", "- while j < M:", "- a = heappop(A)", "- c = BC[j][1]", "- if c <= a:", "- heappush(A, a)", "+ BC.sort(lambda p: p[1], reverse=True)", "+ for b, c in BC:", "+ if A[0] >= c:", "- else:", "- heappush(A, c)", "- BC[j][0] -= 1", "- if BC[j][0] == 0:", "- j += 1", "- # print(A)", "+ for _ in range(b):", "+ if A[0] >= c:", "+ break", "+ heappushpop(A, c)" ]
false
0.05
0.037447
1.3352
[ "s856454003", "s770026733" ]