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
sequence
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
sequence
u875541136
p02689
python
s442494595
s225612469
330
255
25,452
20,084
Accepted
Accepted
22.73
N, M = list(map(int, input().split())) H = list(map(int, input().split())) better = [[] for _ in H] for _ in range(M): A, B = list(map(int, input().split())) A -= 1 B -= 1 if H[A] >= H[B]: better[B].append(A) if H[A] <= H[B]: better[A].append(B) print((sum([1 for b in better if not b])))
N, M = list(map(int, input().split())) H = list(map(int, input().split())) good = [True] * N for _ in range(M): A, B = list(map(int, input().split())) A -= 1 B -= 1 if H[A] >= H[B]: good[B] = False if H[A] <= H[B]: good[A] = False print((sum(good)))
15
15
309
270
N, M = list(map(int, input().split())) H = list(map(int, input().split())) better = [[] for _ in H] for _ in range(M): A, B = list(map(int, input().split())) A -= 1 B -= 1 if H[A] >= H[B]: better[B].append(A) if H[A] <= H[B]: better[A].append(B) print((sum([1 for b in better if not b])))
N, M = list(map(int, input().split())) H = list(map(int, input().split())) good = [True] * N for _ in range(M): A, B = list(map(int, input().split())) A -= 1 B -= 1 if H[A] >= H[B]: good[B] = False if H[A] <= H[B]: good[A] = False print((sum(good)))
false
0
[ "-better = [[] for _ in H]", "+good = [True] * N", "- better[B].append(A)", "+ good[B] = False", "- better[A].append(B)", "-print((sum([1 for b in better if not b])))", "+ good[A] = False", "+print((sum(good)))" ]
false
0.04616
0.150081
0.307564
[ "s442494595", "s225612469" ]
u533039576
p02936
python
s040176907
s709546087
1,835
761
124,748
117,452
Accepted
Accepted
58.53
from collections import deque n, q = list(map(int, input().split())) edge = [[] for _ in range(n)] for i in range(n-1): a, b = list(map(int, input().split())) a, b = a-1, b-1 edge[a].append(b) edge[b].append(a) imos = [0] * n for i in range(q): p, x = list(map(int, input().split())) p -= 1 imos[p] += x q = deque([(0, -1)]) while q: v, p = q.pop() for u in edge[v]: if u == p: continue imos[u] += imos[v] q.append((u, v)) print((' '.join([str(x) for x in imos])))
import sys from collections import deque input = sys.stdin.readline n, q = list(map(int, input().split())) edge = [[] for _ in range(n)] for i in range(n-1): a, b = list(map(int, input().split())) a, b = a-1, b-1 edge[a].append(b) edge[b].append(a) imos = [0] * n for i in range(q): p, x = list(map(int, input().split())) p -= 1 imos[p] += x q = deque([(0, -1)]) while q: v, p = q.pop() for u in edge[v]: if u == p: continue imos[u] += imos[v] q.append((u, v)) print((' '.join([str(x) for x in imos])))
26
28
546
586
from collections import deque n, q = list(map(int, input().split())) edge = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 edge[a].append(b) edge[b].append(a) imos = [0] * n for i in range(q): p, x = list(map(int, input().split())) p -= 1 imos[p] += x q = deque([(0, -1)]) while q: v, p = q.pop() for u in edge[v]: if u == p: continue imos[u] += imos[v] q.append((u, v)) print((" ".join([str(x) for x in imos])))
import sys from collections import deque input = sys.stdin.readline n, q = list(map(int, input().split())) edge = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 edge[a].append(b) edge[b].append(a) imos = [0] * n for i in range(q): p, x = list(map(int, input().split())) p -= 1 imos[p] += x q = deque([(0, -1)]) while q: v, p = q.pop() for u in edge[v]: if u == p: continue imos[u] += imos[v] q.append((u, v)) print((" ".join([str(x) for x in imos])))
false
7.142857
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.038668
0.037949
1.01896
[ "s040176907", "s709546087" ]
u966508131
p03494
python
s956717581
s644807285
190
19
39,920
3,060
Accepted
Accepted
90
eval(input()) A=list(map(int,input().split())) ans=0 while all(a%2==0 for a in A): A=[a/2 for a in A] ans+=1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = 100000 for i in range(len(A)): cnt = 0 while A[i] % 2 == 0: A[i] /= 2 cnt += 1 # print(cnt) ans = min(ans, cnt) print(ans)
7
11
127
224
eval(input()) A = list(map(int, input().split())) ans = 0 while all(a % 2 == 0 for a in A): A = [a / 2 for a in A] ans += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = 100000 for i in range(len(A)): cnt = 0 while A[i] % 2 == 0: A[i] /= 2 cnt += 1 # print(cnt) ans = min(ans, cnt) print(ans)
false
36.363636
[ "-eval(input())", "+N = int(eval(input()))", "-ans = 0", "-while all(a % 2 == 0 for a in A):", "- A = [a / 2 for a in A]", "- ans += 1", "+ans = 100000", "+for i in range(len(A)):", "+ cnt = 0", "+ while A[i] % 2 == 0:", "+ A[i] /= 2", "+ cnt += 1", "+ # print(cnt)", "+ ans = min(ans, cnt)" ]
false
0.033479
0.071472
0.46842
[ "s956717581", "s644807285" ]
u046187684
p02641
python
s218691798
s384382555
33
26
9,460
9,112
Accepted
Accepted
21.21
import bisect import collections x, n = list(map(int, input().split())) p = list(map(int, input().split())) def calc(a): return abs(a - x) if not n: print(x) exit() l = [i for i in range(102) if i not in set(p)] print((min(l, key=calc)))
x, n = list(map(int, input().split())) p = list(map(int, input().split())) def calc(a): return abs(a - x) if not n: print(x) exit() l = [i for i in range(102) if i not in set(p)] print((min(l, key=calc)))
15
12
259
223
import bisect import collections x, n = list(map(int, input().split())) p = list(map(int, input().split())) def calc(a): return abs(a - x) if not n: print(x) exit() l = [i for i in range(102) if i not in set(p)] print((min(l, key=calc)))
x, n = list(map(int, input().split())) p = list(map(int, input().split())) def calc(a): return abs(a - x) if not n: print(x) exit() l = [i for i in range(102) if i not in set(p)] print((min(l, key=calc)))
false
20
[ "-import bisect", "-import collections", "-" ]
false
0.04241
0.104519
0.405767
[ "s218691798", "s384382555" ]
u912237403
p00004
python
s525547073
s139495287
20
10
4,232
4,232
Accepted
Accepted
50
import sys for s in sys.stdin: a,b,c,d,e,f=list(map(float,s.split())) x=c*e-b*f y=a*f-c*d z=a*e-b*d def f(x,z): if x==0: return 0 else: return x/z print("%.3f %.3f" %(f(x,z),f(y,z)))
import sys for s in sys.stdin: a,b,c,d,e,f=list(map(int,s.split())) x=c*e-b*f y=a*f-c*d z=a*e-b*d def f(x,z): if x==0: return 0 else: return 1.0*x/z print("%.3f %.3f" %(f(x,z),f(y,z)))
10
10
224
226
import sys for s in sys.stdin: a, b, c, d, e, f = list(map(float, s.split())) x = c * e - b * f y = a * f - c * d z = a * e - b * d def f(x, z): if x == 0: return 0 else: return x / z print("%.3f %.3f" % (f(x, z), f(y, z)))
import sys for s in sys.stdin: a, b, c, d, e, f = list(map(int, s.split())) x = c * e - b * f y = a * f - c * d z = a * e - b * d def f(x, z): if x == 0: return 0 else: return 1.0 * x / z print("%.3f %.3f" % (f(x, z), f(y, z)))
false
0
[ "- a, b, c, d, e, f = list(map(float, s.split()))", "+ a, b, c, d, e, f = list(map(int, s.split()))", "- return x / z", "+ return 1.0 * x / z" ]
false
0.08911
0.036747
2.424938
[ "s525547073", "s139495287" ]
u344959886
p02786
python
s246819354
s714383037
173
17
38,384
3,060
Accepted
Accepted
90.17
import sys h=int(eval(input())) n=0 while h>1: h=h // 2 n+=1 a=1 for i in range(n): a=a*2+1 print(a)
h=int(eval(input())) def aaa(i): if i == 1: return(1) else: return 2*aaa(i//2)+1 print((aaa(h)))
12
8
123
120
import sys h = int(eval(input())) n = 0 while h > 1: h = h // 2 n += 1 a = 1 for i in range(n): a = a * 2 + 1 print(a)
h = int(eval(input())) def aaa(i): if i == 1: return 1 else: return 2 * aaa(i // 2) + 1 print((aaa(h)))
false
33.333333
[ "-import sys", "+h = int(eval(input()))", "-h = int(eval(input()))", "-n = 0", "-while h > 1:", "- h = h // 2", "- n += 1", "-a = 1", "-for i in range(n):", "- a = a * 2 + 1", "-print(a)", "+", "+def aaa(i):", "+ if i == 1:", "+ return 1", "+ else:", "+ return 2 * aaa(i // 2) + 1", "+", "+", "+print((aaa(h)))" ]
false
0.039149
0.036368
1.076469
[ "s246819354", "s714383037" ]
u254871849
p03078
python
s805563618
s496494572
753
313
90,668
19,892
Accepted
Accepted
58.43
import sys import numpy as np def main(): x, y, z, K = list(map(int, sys.stdin.readline().split())) abc = np.array(sys.stdin.read().split(), dtype=np.int64) a = abc[:x] b = abc[x:x + y] c = abc[x + y:x + y+ z] ab = np.sort(np.array([a[i] + b for i in range(x)]).reshape(-1))[::-1][:K] res = np.sort(np.array([c[i] + ab for i in range(z)]).reshape(-1))[::-1][:K] print(('\n'.join(map(str, res)))) if __name__ == "__main__": main()
import sys import numpy as np INF = 10 ** 18 def main(): x, y, z, K = list(map(int, sys.stdin.readline().split())) abc = np.array(sys.stdin.read().split(), dtype=np.int64) a = np.append(abc[:x], INF) b = np.append(abc[x:x + y], INF) c = np.append(abc[x + y:x + y+ z], INF) a = np.sort(a)[::-1] b = np.sort(b)[::-1] c = np.sort(c)[::-1] res = [] for i in range(1, min(K, x) + 1): for j in range(1, min(y, K // i) + 1): for k in range(1, min(z, K // (i * j)) + 1): res.append(a[i] + b[j] + c[k]) res = sorted(res, reverse=True)[:K] print(('\n'.join(map(str, res)))) if __name__ == "__main__": main()
17
26
477
708
import sys import numpy as np def main(): x, y, z, K = list(map(int, sys.stdin.readline().split())) abc = np.array(sys.stdin.read().split(), dtype=np.int64) a = abc[:x] b = abc[x : x + y] c = abc[x + y : x + y + z] ab = np.sort(np.array([a[i] + b for i in range(x)]).reshape(-1))[::-1][:K] res = np.sort(np.array([c[i] + ab for i in range(z)]).reshape(-1))[::-1][:K] print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
import sys import numpy as np INF = 10**18 def main(): x, y, z, K = list(map(int, sys.stdin.readline().split())) abc = np.array(sys.stdin.read().split(), dtype=np.int64) a = np.append(abc[:x], INF) b = np.append(abc[x : x + y], INF) c = np.append(abc[x + y : x + y + z], INF) a = np.sort(a)[::-1] b = np.sort(b)[::-1] c = np.sort(c)[::-1] res = [] for i in range(1, min(K, x) + 1): for j in range(1, min(y, K // i) + 1): for k in range(1, min(z, K // (i * j)) + 1): res.append(a[i] + b[j] + c[k]) res = sorted(res, reverse=True)[:K] print(("\n".join(map(str, res)))) if __name__ == "__main__": main()
false
34.615385
[ "+", "+INF = 10**18", "- a = abc[:x]", "- b = abc[x : x + y]", "- c = abc[x + y : x + y + z]", "- ab = np.sort(np.array([a[i] + b for i in range(x)]).reshape(-1))[::-1][:K]", "- res = np.sort(np.array([c[i] + ab for i in range(z)]).reshape(-1))[::-1][:K]", "+ a = np.append(abc[:x], INF)", "+ b = np.append(abc[x : x + y], INF)", "+ c = np.append(abc[x + y : x + y + z], INF)", "+ a = np.sort(a)[::-1]", "+ b = np.sort(b)[::-1]", "+ c = np.sort(c)[::-1]", "+ res = []", "+ for i in range(1, min(K, x) + 1):", "+ for j in range(1, min(y, K // i) + 1):", "+ for k in range(1, min(z, K // (i * j)) + 1):", "+ res.append(a[i] + b[j] + c[k])", "+ res = sorted(res, reverse=True)[:K]" ]
false
0.29759
0.284033
1.047731
[ "s805563618", "s496494572" ]
u941753895
p03478
python
s591582769
s349108904
44
37
2,940
2,940
Accepted
Accepted
15.91
n,a,b=list(map(int,input().split())) c=0 for i in range(1,n+1): x=0 y=list(str(i)) for j in range(len(y)): x+=int(y[j]) if a<=x and x<=b: c+=i print(c)
# 入力 N,A,B=list(map(int,input().split())) c=0 for x in range(1,N+1): y=list(str(x)) # 各桁の和を求める z=sum([int(a) for a in y]) # 各桁の和がA以上B以下なら加算 if A<=z and z<=B: c+=x # 出力 print(c)
10
16
170
203
n, a, b = list(map(int, input().split())) c = 0 for i in range(1, n + 1): x = 0 y = list(str(i)) for j in range(len(y)): x += int(y[j]) if a <= x and x <= b: c += i print(c)
# 入力 N, A, B = list(map(int, input().split())) c = 0 for x in range(1, N + 1): y = list(str(x)) # 各桁の和を求める z = sum([int(a) for a in y]) # 各桁の和がA以上B以下なら加算 if A <= z and z <= B: c += x # 出力 print(c)
false
37.5
[ "-n, a, b = list(map(int, input().split()))", "+# 入力", "+N, A, B = list(map(int, input().split()))", "-for i in range(1, n + 1):", "- x = 0", "- y = list(str(i))", "- for j in range(len(y)):", "- x += int(y[j])", "- if a <= x and x <= b:", "- c += i", "+for x in range(1, N + 1):", "+ y = list(str(x))", "+ # 各桁の和を求める", "+ z = sum([int(a) for a in y])", "+ # 各桁の和がA以上B以下なら加算", "+ if A <= z and z <= B:", "+ c += x", "+# 出力" ]
false
0.04534
0.045086
1.005631
[ "s591582769", "s349108904" ]
u761320129
p03659
python
s086144488
s154747833
197
178
24,816
24,172
Accepted
Accepted
9.64
N = int(eval(input())) src = list(map(int,input().split())) s = sum(src) ans = float('inf') tmp = 0 for i in range(N-1): tmp += src[i] rem = s - tmp ans = min(ans, abs(tmp - rem)) print(ans)
from itertools import accumulate as ac N = int(eval(input())) src = list(map(int,input().split())) acum = list(ac(src)) ans = float('inf') for i in range(N-1): ans = min(ans, abs(acum[i] - (acum[-1]-acum[i]))) print(ans)
10
8
206
225
N = int(eval(input())) src = list(map(int, input().split())) s = sum(src) ans = float("inf") tmp = 0 for i in range(N - 1): tmp += src[i] rem = s - tmp ans = min(ans, abs(tmp - rem)) print(ans)
from itertools import accumulate as ac N = int(eval(input())) src = list(map(int, input().split())) acum = list(ac(src)) ans = float("inf") for i in range(N - 1): ans = min(ans, abs(acum[i] - (acum[-1] - acum[i]))) print(ans)
false
20
[ "+from itertools import accumulate as ac", "+", "-s = sum(src)", "+acum = list(ac(src))", "-tmp = 0", "- tmp += src[i]", "- rem = s - tmp", "- ans = min(ans, abs(tmp - rem))", "+ ans = min(ans, abs(acum[i] - (acum[-1] - acum[i])))" ]
false
0.046025
0.050016
0.920203
[ "s086144488", "s154747833" ]
u678167152
p03761
python
s392065030
s695003661
21
19
3,316
3,060
Accepted
Accepted
9.52
from itertools import groupby, accumulate, product, permutations, combinations from collections import Counter def solve(): N = int(eval(input())) dics = [[0]*N for _ in range(26)] S = [eval(input()) for _ in range(N)] for i in range(N): for s in S[i]: dics[ord(s)-ord('a')][i]+=1 ans = '' for i in range(26): ans += chr(i+ord('a'))*min(dics[i]) return ans print((solve()))
from itertools import groupby, accumulate, product, permutations, combinations N = int(eval(input())) dics = [[0]*N for _ in range(26)] for i in range(N): S = eval(input()) for s in S: dics[ord(s)-ord('a')][i]+=1 ans = '' for i in range(26): ans += chr(i+ord('a'))*min(dics[i]) print(ans)
14
11
429
306
from itertools import groupby, accumulate, product, permutations, combinations from collections import Counter def solve(): N = int(eval(input())) dics = [[0] * N for _ in range(26)] S = [eval(input()) for _ in range(N)] for i in range(N): for s in S[i]: dics[ord(s) - ord("a")][i] += 1 ans = "" for i in range(26): ans += chr(i + ord("a")) * min(dics[i]) return ans print((solve()))
from itertools import groupby, accumulate, product, permutations, combinations N = int(eval(input())) dics = [[0] * N for _ in range(26)] for i in range(N): S = eval(input()) for s in S: dics[ord(s) - ord("a")][i] += 1 ans = "" for i in range(26): ans += chr(i + ord("a")) * min(dics[i]) print(ans)
false
21.428571
[ "-from collections import Counter", "-", "-def solve():", "- N = int(eval(input()))", "- dics = [[0] * N for _ in range(26)]", "- S = [eval(input()) for _ in range(N)]", "- for i in range(N):", "- for s in S[i]:", "- dics[ord(s) - ord(\"a\")][i] += 1", "- ans = \"\"", "- for i in range(26):", "- ans += chr(i + ord(\"a\")) * min(dics[i])", "- return ans", "-", "-", "-print((solve()))", "+N = int(eval(input()))", "+dics = [[0] * N for _ in range(26)]", "+for i in range(N):", "+ S = eval(input())", "+ for s in S:", "+ dics[ord(s) - ord(\"a\")][i] += 1", "+ans = \"\"", "+for i in range(26):", "+ ans += chr(i + ord(\"a\")) * min(dics[i])", "+print(ans)" ]
false
0.036809
0.03419
1.076593
[ "s392065030", "s695003661" ]
u426649993
p03013
python
s690412898
s992542174
198
146
7,852
14,448
Accepted
Accepted
26.26
if __name__ == "__main__": mod = 10 ** 9 + 7 n, m = list(map(int, input().split())) a = list() for i in range(m): a.append(int(eval(input()))) dp = [0] * (n + 1) for aa in a: dp[aa] = -1 if dp[1] != -1: dp[1] = 1 else: dp[1] = 0 if n > 1: if dp[2] != -1: dp[2] = 1 + dp[1] else: dp[2] = 0 for i in range(3, n+1): if dp[i] != -1: dp[i] = (dp[i-2] + dp[i-1]) % mod else: dp[i] = 0 print((dp[n]))
def solve(N, a): mod = 10**9 + 7 dp = [0] * (N+1) step = [0] * (N+1) for aa in a: step[aa] = 1 dp[0] = 1 if step[1] == 0: dp[1] = 1 for i in range(2, N+1): if step[i] == 0: dp[i] = dp[i-1] + dp[i-2] dp[i] %= mod return dp[N] if __name__ == "__main__": N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] print((solve(N, a)))
30
24
591
462
if __name__ == "__main__": mod = 10**9 + 7 n, m = list(map(int, input().split())) a = list() for i in range(m): a.append(int(eval(input()))) dp = [0] * (n + 1) for aa in a: dp[aa] = -1 if dp[1] != -1: dp[1] = 1 else: dp[1] = 0 if n > 1: if dp[2] != -1: dp[2] = 1 + dp[1] else: dp[2] = 0 for i in range(3, n + 1): if dp[i] != -1: dp[i] = (dp[i - 2] + dp[i - 1]) % mod else: dp[i] = 0 print((dp[n]))
def solve(N, a): mod = 10**9 + 7 dp = [0] * (N + 1) step = [0] * (N + 1) for aa in a: step[aa] = 1 dp[0] = 1 if step[1] == 0: dp[1] = 1 for i in range(2, N + 1): if step[i] == 0: dp[i] = dp[i - 1] + dp[i - 2] dp[i] %= mod return dp[N] if __name__ == "__main__": N, M = list(map(int, input().split())) a = [int(eval(input())) for _ in range(M)] print((solve(N, a)))
false
20
[ "+def solve(N, a):", "+ mod = 10**9 + 7", "+ dp = [0] * (N + 1)", "+ step = [0] * (N + 1)", "+ for aa in a:", "+ step[aa] = 1", "+ dp[0] = 1", "+ if step[1] == 0:", "+ dp[1] = 1", "+ for i in range(2, N + 1):", "+ if step[i] == 0:", "+ dp[i] = dp[i - 1] + dp[i - 2]", "+ dp[i] %= mod", "+ return dp[N]", "+", "+", "- mod = 10**9 + 7", "- n, m = list(map(int, input().split()))", "- a = list()", "- for i in range(m):", "- a.append(int(eval(input())))", "- dp = [0] * (n + 1)", "- for aa in a:", "- dp[aa] = -1", "- if dp[1] != -1:", "- dp[1] = 1", "- else:", "- dp[1] = 0", "- if n > 1:", "- if dp[2] != -1:", "- dp[2] = 1 + dp[1]", "- else:", "- dp[2] = 0", "- for i in range(3, n + 1):", "- if dp[i] != -1:", "- dp[i] = (dp[i - 2] + dp[i - 1]) % mod", "- else:", "- dp[i] = 0", "- print((dp[n]))", "+ N, M = list(map(int, input().split()))", "+ a = [int(eval(input())) for _ in range(M)]", "+ print((solve(N, a)))" ]
false
0.076116
0.040945
1.858975
[ "s690412898", "s992542174" ]
u747602774
p03806
python
s470458930
s793926844
618
395
4,872
59,356
Accepted
Accepted
36.08
N,Ma,Mb = list(map(int,input().split())) INF = float('inf') dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 sa = 0 sb = 0 for i in range(1,N+1): ai,bi,ci = list(map(int,input().split())) sa += ai sb += bi for a in range(sa+1,-1,-1): for b in range(sb+1,-1,-1): if a-ai >= 0 and b-bi >= 0: dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci) ans = INF for j in range(1,401): if Ma*j > 400 or Mb*j > 400: break ans = min(ans,dp[Ma*j][Mb*j]) print((ans if ans != INF else -1))
N,Ma,Mb = list(map(int,input().split())) INF = float('inf') dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 for i in range(1,N+1): ai,bi,ci = list(map(int,input().split())) for a in range(400,-1,-1): for b in range(400,-1,-1): if a-ai >= 0 and b-bi >= 0: dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci) ans = INF for j in range(1,401): if Ma*j > 400 or Mb*j > 400: break ans = min(ans,dp[Ma*j][Mb*j]) print((ans if ans != INF else -1))
28
22
572
527
N, Ma, Mb = list(map(int, input().split())) INF = float("inf") dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 sa = 0 sb = 0 for i in range(1, N + 1): ai, bi, ci = list(map(int, input().split())) sa += ai sb += bi for a in range(sa + 1, -1, -1): for b in range(sb + 1, -1, -1): if a - ai >= 0 and b - bi >= 0: dp[a][b] = min(dp[a][b], dp[a - ai][b - bi] + ci) ans = INF for j in range(1, 401): if Ma * j > 400 or Mb * j > 400: break ans = min(ans, dp[Ma * j][Mb * j]) print((ans if ans != INF else -1))
N, Ma, Mb = list(map(int, input().split())) INF = float("inf") dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 for i in range(1, N + 1): ai, bi, ci = list(map(int, input().split())) for a in range(400, -1, -1): for b in range(400, -1, -1): if a - ai >= 0 and b - bi >= 0: dp[a][b] = min(dp[a][b], dp[a - ai][b - bi] + ci) ans = INF for j in range(1, 401): if Ma * j > 400 or Mb * j > 400: break ans = min(ans, dp[Ma * j][Mb * j]) print((ans if ans != INF else -1))
false
21.428571
[ "-sa = 0", "-sb = 0", "- sa += ai", "- sb += bi", "- for a in range(sa + 1, -1, -1):", "- for b in range(sb + 1, -1, -1):", "+ for a in range(400, -1, -1):", "+ for b in range(400, -1, -1):" ]
false
0.119499
1.030154
0.116001
[ "s470458930", "s793926844" ]
u374802266
p02615
python
s215279951
s625246577
146
134
31,588
31,660
Accepted
Accepted
8.22
n=int(eval(input())) a=sorted(list(map(int,input().split())),reverse=True) ans=0 for i in range(n-1): ans+=a[(i+1)//2] print(ans)
n=int(eval(input())) a=sorted(list(map(int,input().split())),reverse=1) b=0 for i in range(n-1): b+=a[(i+1)//2] print(b)
6
6
132
123
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(n - 1): ans += a[(i + 1) // 2] print(ans)
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=1) b = 0 for i in range(n - 1): b += a[(i + 1) // 2] print(b)
false
0
[ "-a = sorted(list(map(int, input().split())), reverse=True)", "-ans = 0", "+a = sorted(list(map(int, input().split())), reverse=1)", "+b = 0", "- ans += a[(i + 1) // 2]", "-print(ans)", "+ b += a[(i + 1) // 2]", "+print(b)" ]
false
0.034453
0.035944
0.95852
[ "s215279951", "s625246577" ]
u758738963
p03108
python
s567889899
s642022231
645
398
40,028
85,268
Accepted
Accepted
38.29
import numpy as np class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N,M = list( map(int, input().split()) ) uf = UnionFind(N) A = [0]*M B = [0]*M for i in range(M): a,b = list( map(int, input().split()) ) A[i]=a-1 B[i]=b-1 #print(A) #print(B) cmax = int(N*(N-1)/2) FD = [cmax]*(M+1) #print(FD) for i in range(M): #print(uf) if uf.same(A[M-i-1],B[M-i-1]): FD[M-i-1] = FD[M-i] else: cless = uf.size(A[M-i-1])*uf.size(B[M-i-1]) FD[M-i-1] = FD[M-i] - cless if FD[M-i-1]<0: FD[M-i-1]=0 uf.union(A[M-1-i],B[M-1-i]) #print(uf) #print(FD[1:]) for fd in FD[1:]: print(fd)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N,M = list( map(int, input().split()) ) uf = UnionFind(N) A = [0]*M B = [0]*M for i in range(M): a,b = list( map(int, input().split()) ) A[i]=a-1 B[i]=b-1 #print(A) #print(B) cmax = int(N*(N-1)/2) FD = [cmax]*(M+1) #print(FD) for i in range(M): #print(uf) if uf.same(A[M-i-1],B[M-i-1]): FD[M-i-1] = FD[M-i] else: cless = uf.size(A[M-i-1])*uf.size(B[M-i-1]) FD[M-i-1] = FD[M-i] - cless if FD[M-i-1]<0: FD[M-i-1]=0 uf.union(A[M-1-i],B[M-1-i]) #print(uf) #print(FD[1:]) for fd in FD[1:]: print(fd)
82
80
1,814
1,792
import numpy as np class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) N, M = list(map(int, input().split())) uf = UnionFind(N) A = [0] * M B = [0] * M for i in range(M): a, b = list(map(int, input().split())) A[i] = a - 1 B[i] = b - 1 # print(A) # print(B) cmax = int(N * (N - 1) / 2) FD = [cmax] * (M + 1) # print(FD) for i in range(M): # print(uf) if uf.same(A[M - i - 1], B[M - i - 1]): FD[M - i - 1] = FD[M - i] else: cless = uf.size(A[M - i - 1]) * uf.size(B[M - i - 1]) FD[M - i - 1] = FD[M - i] - cless if FD[M - i - 1] < 0: FD[M - i - 1] = 0 uf.union(A[M - 1 - i], B[M - 1 - i]) # print(uf) # print(FD[1:]) for fd in FD[1:]: print(fd)
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) N, M = list(map(int, input().split())) uf = UnionFind(N) A = [0] * M B = [0] * M for i in range(M): a, b = list(map(int, input().split())) A[i] = a - 1 B[i] = b - 1 # print(A) # print(B) cmax = int(N * (N - 1) / 2) FD = [cmax] * (M + 1) # print(FD) for i in range(M): # print(uf) if uf.same(A[M - i - 1], B[M - i - 1]): FD[M - i - 1] = FD[M - i] else: cless = uf.size(A[M - i - 1]) * uf.size(B[M - i - 1]) FD[M - i - 1] = FD[M - i] - cless if FD[M - i - 1] < 0: FD[M - i - 1] = 0 uf.union(A[M - 1 - i], B[M - 1 - i]) # print(uf) # print(FD[1:]) for fd in FD[1:]: print(fd)
false
2.439024
[ "-import numpy as np", "-", "-" ]
false
0.03462
0.038167
0.907082
[ "s567889899", "s642022231" ]
u562935282
p03294
python
s222069577
s405937414
95
19
3,316
3,316
Accepted
Accepted
80
n = int(eval(input())) a = list(map(int, input().split())) x = 1 for i in a: x *= i ans = 0 for i in a: ans += (x - 1) % i print(ans)
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a) - len(a)))
12
4
149
79
n = int(eval(input())) a = list(map(int, input().split())) x = 1 for i in a: x *= i ans = 0 for i in a: ans += (x - 1) % i print(ans)
n = int(eval(input())) a = list(map(int, input().split())) print((sum(a) - len(a)))
false
66.666667
[ "-x = 1", "-for i in a:", "- x *= i", "-ans = 0", "-for i in a:", "- ans += (x - 1) % i", "-print(ans)", "+print((sum(a) - len(a)))" ]
false
0.047222
0.047022
1.004247
[ "s222069577", "s405937414" ]
u440566786
p02868
python
s887732752
s475376325
1,599
1,315
263,108
271,424
Accepted
Accepted
17.76
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, now = N * 2, N * 3 E = [[] for _ in range(N * 3 + m)] ref = lambda v : v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) # add range-edge for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 # lower l, r = u + N, v + N while l < r: if l & 1: E[ref(l + N2)].append((now, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((now, w)) l >>= 1 r >>= 1 # upper l, r = u + N, v + N while l < r: if l & 1: E[now].append((l, 0)) l += 1 if r & 1: r -= 1 E[now].append((r, 0)) l >>= 1 r >>= 1 now += 1 # Dijkstra (source : N, termination : N + n - 1) dist = [INF] * now dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N * 3 + m)] ref = lambda v : v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) # add range-edge for i in range(m): u, v, w = list(map(int, input().split())) u -= 1 # lower l, r = u + N, v + N while l < r: if l & 1: E[ref(l + N2)].append((N3 + i, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((N3 + i, w)) l >>= 1 r >>= 1 # upper l, r = u + N, v + N while l < r: if l & 1: E[N3 + i].append((l, 0)) l += 1 if r & 1: r -= 1 E[N3 + i].append((r, 0)) l >>= 1 r >>= 1 # Dijkstra (source : N, termination : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
67
66
1,801
1,799
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, now = N * 2, N * 3 E = [[] for _ in range(N * 3 + m)] ref = lambda v: v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) # add range-edge for _ in range(m): u, v, w = list(map(int, input().split())) u -= 1 # lower l, r = u + N, v + N while l < r: if l & 1: E[ref(l + N2)].append((now, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((now, w)) l >>= 1 r >>= 1 # upper l, r = u + N, v + N while l < r: if l & 1: E[now].append((l, 0)) l += 1 if r & 1: r -= 1 E[now].append((r, 0)) l >>= 1 r >>= 1 now += 1 # Dijkstra (source : N, termination : N + n - 1) dist = [INF] * now dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) N = 1 << (n - 1).bit_length() N2, N3 = N * 2, N * 3 E = [[] for _ in range(N * 3 + m)] ref = lambda v: v if v < 3 * N else v - N2 # build range-edge graph for i in range(N - 1, 0, -1): cl, cr = i << 1, i << 1 | 1 E[i].append((cl, 0)) E[i].append((cr, 0)) E[ref(cl + N2)].append((ref(i + N2), 0)) E[ref(cr + N2)].append((ref(i + N2), 0)) # add range-edge for i in range(m): u, v, w = list(map(int, input().split())) u -= 1 # lower l, r = u + N, v + N while l < r: if l & 1: E[ref(l + N2)].append((N3 + i, w)) l += 1 if r & 1: r -= 1 E[ref(r + N2)].append((N3 + i, w)) l >>= 1 r >>= 1 # upper l, r = u + N, v + N while l < r: if l & 1: E[N3 + i].append((l, 0)) l += 1 if r & 1: r -= 1 E[N3 + i].append((r, 0)) l >>= 1 r >>= 1 # Dijkstra (source : N, termination : N + n - 1) dist = [INF] * (N3 + m) dist[N] = 0 heap = [(0, N)] while heap: d, v = heappop(heap) if dist[v] != d: continue for nv, w in E[v]: if dist[nv] > d + w: dist[nv] = d + w heappush(heap, (d + w, nv)) ans = dist[N + n - 1] if ans == INF: ans = -1 print(ans) resolve()
false
1.492537
[ "- N2, now = N * 2, N * 3", "+ N2, N3 = N * 2, N * 3", "- for _ in range(m):", "+ for i in range(m):", "- E[ref(l + N2)].append((now, w))", "+ E[ref(l + N2)].append((N3 + i, w))", "- E[ref(r + N2)].append((now, w))", "+ E[ref(r + N2)].append((N3 + i, w))", "- E[now].append((l, 0))", "+ E[N3 + i].append((l, 0))", "- E[now].append((r, 0))", "+ E[N3 + i].append((r, 0))", "- now += 1", "- dist = [INF] * now", "+ dist = [INF] * (N3 + m)" ]
false
0.039437
0.037979
1.038408
[ "s887732752", "s475376325" ]
u375695365
p02996
python
s605668546
s782867514
1,748
824
91,412
67,444
Accepted
Accepted
52.86
n=int(eval(input())) ab=[list(map(int,input().split())) for _ in range(n)] sort_ab = sorted(ab, key=lambda x:(x[1], x[0])) #print(sort_ab) count=0 for i in range(n): count+=sort_ab[i][0] if sort_ab[i][1]<count: print("No") break else: print("Yes")
n = int(eval(input())) ab = [list(map(int,input().split())) for i in range(n)] ab = sorted(ab, key=lambda x:(x[1], -x[0])) count = 0 for i in range(n): count += ab[i][0] if count > ab[i][1]: print("No") break else: print("Yes")
15
12
286
265
n = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] sort_ab = sorted(ab, key=lambda x: (x[1], x[0])) # print(sort_ab) count = 0 for i in range(n): count += sort_ab[i][0] if sort_ab[i][1] < count: print("No") break else: print("Yes")
n = int(eval(input())) ab = [list(map(int, input().split())) for i in range(n)] ab = sorted(ab, key=lambda x: (x[1], -x[0])) count = 0 for i in range(n): count += ab[i][0] if count > ab[i][1]: print("No") break else: print("Yes")
false
20
[ "-ab = [list(map(int, input().split())) for _ in range(n)]", "-sort_ab = sorted(ab, key=lambda x: (x[1], x[0]))", "-# print(sort_ab)", "+ab = [list(map(int, input().split())) for i in range(n)]", "+ab = sorted(ab, key=lambda x: (x[1], -x[0]))", "- count += sort_ab[i][0]", "- if sort_ab[i][1] < count:", "+ count += ab[i][0]", "+ if count > ab[i][1]:" ]
false
0.082646
0.044628
1.851876
[ "s605668546", "s782867514" ]
u747602774
p03611
python
s817168194
s230743278
305
178
68,800
14,564
Accepted
Accepted
41.64
import collections N=int(eval(input())) li=list(map(int,input().split())) for n in range(N): plus=li[n]+1 minus=li[n]-1 li.append(plus) li.append(minus) ans=collections.Counter(li) print((ans.most_common()[0][1]))
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) ac = Counter(a) ans = 0 for i in range(1,10**5): ans = max(ans, ac[i-1]+ac[i]+ac[i+1]) print(ans)
12
11
227
198
import collections N = int(eval(input())) li = list(map(int, input().split())) for n in range(N): plus = li[n] + 1 minus = li[n] - 1 li.append(plus) li.append(minus) ans = collections.Counter(li) print((ans.most_common()[0][1]))
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) ac = Counter(a) ans = 0 for i in range(1, 10**5): ans = max(ans, ac[i - 1] + ac[i] + ac[i + 1]) print(ans)
false
8.333333
[ "-import collections", "+from collections import Counter", "-N = int(eval(input()))", "-li = list(map(int, input().split()))", "-for n in range(N):", "- plus = li[n] + 1", "- minus = li[n] - 1", "- li.append(plus)", "- li.append(minus)", "-ans = collections.Counter(li)", "-print((ans.most_common()[0][1]))", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+ac = Counter(a)", "+ans = 0", "+for i in range(1, 10**5):", "+ ans = max(ans, ac[i - 1] + ac[i] + ac[i + 1])", "+print(ans)" ]
false
0.039618
0.140382
0.282214
[ "s817168194", "s230743278" ]
u318427318
p02881
python
s596574453
s620951244
425
298
3,512
9,172
Accepted
Accepted
29.88
import math def dictcheck(dict): min = 0 for k,v in list(dict.items()): if k == 1: min = v break elif min == 0: min=(int(k)-1)+(int(v)-1) elif min > (int(k)-1)+(int(v)-1): min = (int(k)-1)+(int(v)-1) else: continue print(min) def main(): N = int(eval(input())) i = 2 tmpdict= {} while i <= math.sqrt(N): if N % i == 0: tmpdata = {i:N/i} tmpdict.update(tmpdata) i+=1 else: i+=1 if len(tmpdict)==0: tmpdata = {1:N-1} tmpdict.update(tmpdata) # print(tmpdict) dictcheck(tmpdict) if __name__ == "__main__": main()
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): n = int(eval(input())) ans=10**12 for a in range(1,10**6+1): if n%a==0: b=n//a ans=min(ans,a+b-2) print(ans) if __name__=="__main__": main()
35
15
748
266
import math def dictcheck(dict): min = 0 for k, v in list(dict.items()): if k == 1: min = v break elif min == 0: min = (int(k) - 1) + (int(v) - 1) elif min > (int(k) - 1) + (int(v) - 1): min = (int(k) - 1) + (int(v) - 1) else: continue print(min) def main(): N = int(eval(input())) i = 2 tmpdict = {} while i <= math.sqrt(N): if N % i == 0: tmpdata = {i: N / i} tmpdict.update(tmpdata) i += 1 else: i += 1 if len(tmpdict) == 0: tmpdata = {1: N - 1} tmpdict.update(tmpdata) # print(tmpdict) dictcheck(tmpdict) if __name__ == "__main__": main()
# -*-coding:utf-8-*- import sys input = sys.stdin.readline def main(): n = int(eval(input())) ans = 10**12 for a in range(1, 10**6 + 1): if n % a == 0: b = n // a ans = min(ans, a + b - 2) print(ans) if __name__ == "__main__": main()
false
57.142857
[ "-import math", "+# -*-coding:utf-8-*-", "+import sys", "-", "-def dictcheck(dict):", "- min = 0", "- for k, v in list(dict.items()):", "- if k == 1:", "- min = v", "- break", "- elif min == 0:", "- min = (int(k) - 1) + (int(v) - 1)", "- elif min > (int(k) - 1) + (int(v) - 1):", "- min = (int(k) - 1) + (int(v) - 1)", "- else:", "- continue", "- print(min)", "+input = sys.stdin.readline", "- N = int(eval(input()))", "- i = 2", "- tmpdict = {}", "- while i <= math.sqrt(N):", "- if N % i == 0:", "- tmpdata = {i: N / i}", "- tmpdict.update(tmpdata)", "- i += 1", "- else:", "- i += 1", "- if len(tmpdict) == 0:", "- tmpdata = {1: N - 1}", "- tmpdict.update(tmpdata)", "- # print(tmpdict)", "- dictcheck(tmpdict)", "+ n = int(eval(input()))", "+ ans = 10**12", "+ for a in range(1, 10**6 + 1):", "+ if n % a == 0:", "+ b = n // a", "+ ans = min(ans, a + b - 2)", "+ print(ans)" ]
false
0.007348
0.9246
0.007947
[ "s596574453", "s620951244" ]
u226108478
p02861
python
s120887159
s208352332
420
199
8,052
13,708
Accepted
Accepted
52.62
# -*- coding: utf-8 -*- def calc_dist(x1, x2, y1, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def main(): from itertools import permutations n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] total = 0 m = len(list(permutations(list(range(n))))) for p in permutations(list(range(n))): for i in range(len(p) - 1): a = p[i] b = p[i + 1] total += calc_dist(xy[a][0], xy[b][0], xy[a][1], xy[b][1]) print((total / m)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- def main(): from itertools import permutations from math import sqrt n = int(eval(input())) x = [0 for _ in range(n)] y = [0 for _ in range(n)] for i in range(n): xi, yi = list(map(int, input().split())) x[i] = xi y[i] = yi path = list(permutations(list(range(n)))) path_count = len(path) length = 0 for p in path: for i, j in zip(p, p[1:]): length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) print((length / path_count)) if __name__ == '__main__': main()
27
29
581
594
# -*- coding: utf-8 -*- def calc_dist(x1, x2, y1, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def main(): from itertools import permutations n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] total = 0 m = len(list(permutations(list(range(n))))) for p in permutations(list(range(n))): for i in range(len(p) - 1): a = p[i] b = p[i + 1] total += calc_dist(xy[a][0], xy[b][0], xy[a][1], xy[b][1]) print((total / m)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): from itertools import permutations from math import sqrt n = int(eval(input())) x = [0 for _ in range(n)] y = [0 for _ in range(n)] for i in range(n): xi, yi = list(map(int, input().split())) x[i] = xi y[i] = yi path = list(permutations(list(range(n)))) path_count = len(path) length = 0 for p in path: for i, j in zip(p, p[1:]): length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) print((length / path_count)) if __name__ == "__main__": main()
false
6.896552
[ "-def calc_dist(x1, x2, y1, y2):", "- return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5", "-", "-", "+ from math import sqrt", "- xy = [list(map(int, input().split())) for _ in range(n)]", "- total = 0", "- m = len(list(permutations(list(range(n)))))", "- for p in permutations(list(range(n))):", "- for i in range(len(p) - 1):", "- a = p[i]", "- b = p[i + 1]", "- total += calc_dist(xy[a][0], xy[b][0], xy[a][1], xy[b][1])", "- print((total / m))", "+ x = [0 for _ in range(n)]", "+ y = [0 for _ in range(n)]", "+ for i in range(n):", "+ xi, yi = list(map(int, input().split()))", "+ x[i] = xi", "+ y[i] = yi", "+ path = list(permutations(list(range(n))))", "+ path_count = len(path)", "+ length = 0", "+ for p in path:", "+ for i, j in zip(p, p[1:]):", "+ length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)", "+ print((length / path_count))" ]
false
0.074944
0.07775
0.963902
[ "s120887159", "s208352332" ]
u079022693
p02900
python
s635444366
s791890179
322
200
5,180
16,140
Accepted
Accepted
37.89
from fractions import gcd A,B=list(map(int,input().split())) C=gcd(A,B) if C==1: print((1)) else: count=1 C_copy=C n=2 while n**2<=C: flag=False while C_copy%n==0: C_copy//=n flag=True if flag: count+=1 n=n+1 if n==2 else n+2 else: n=n+1 if n==2 else n+2 if C_copy!=1: count+=1 print(count)
def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] from fractions import gcd import math A,B=list(map(int,input().split())) C=gcd(A,B) prime_numbers=primes(int(math.sqrt(C))+1) if C==1: print((1)) else: count=1 for p in prime_numbers: if C==1: break flag=False while C%p==0: C//=p flag=True if flag: count+=1 p=p+1 if p==2 else p+2 else: p=p+1 if p==2 else p+2 if C!=1: count+=1 print(count)
25
40
408
785
from fractions import gcd A, B = list(map(int, input().split())) C = gcd(A, B) if C == 1: print((1)) else: count = 1 C_copy = C n = 2 while n**2 <= C: flag = False while C_copy % n == 0: C_copy //= n flag = True if flag: count += 1 n = n + 1 if n == 2 else n + 2 else: n = n + 1 if n == 2 else n + 2 if C_copy != 1: count += 1 print(count)
def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] from fractions import gcd import math A, B = list(map(int, input().split())) C = gcd(A, B) prime_numbers = primes(int(math.sqrt(C)) + 1) if C == 1: print((1)) else: count = 1 for p in prime_numbers: if C == 1: break flag = False while C % p == 0: C //= p flag = True if flag: count += 1 p = p + 1 if p == 2 else p + 2 else: p = p + 1 if p == 2 else p + 2 if C != 1: count += 1 print(count)
false
37.5
[ "+def primes(n):", "+ is_prime = [True] * (n + 1)", "+ is_prime[0] = False", "+ is_prime[1] = False", "+ for i in range(2, int(n**0.5) + 1):", "+ if not is_prime[i]:", "+ continue", "+ for j in range(i * 2, n + 1, i):", "+ is_prime[j] = False", "+ return [i for i in range(n + 1) if is_prime[i]]", "+", "+", "+import math", "+prime_numbers = primes(int(math.sqrt(C)) + 1)", "- C_copy = C", "- n = 2", "- while n**2 <= C:", "+ for p in prime_numbers:", "+ if C == 1:", "+ break", "- while C_copy % n == 0:", "- C_copy //= n", "+ while C % p == 0:", "+ C //= p", "- n = n + 1 if n == 2 else n + 2", "+ p = p + 1 if p == 2 else p + 2", "- n = n + 1 if n == 2 else n + 2", "- if C_copy != 1:", "+ p = p + 1 if p == 2 else p + 2", "+ if C != 1:" ]
false
0.224651
0.053788
4.176644
[ "s635444366", "s791890179" ]
u873190923
p03244
python
s213659512
s373378256
348
234
80,216
57,324
Accepted
Accepted
32.76
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) import itertools import math import fractions import functools l = [0]*(10**5+1) r = [0]*(10**5+1) n = int(eval(input())) v = list(map(int, input().split())) for i in range(n): if i % 2 == 0: l[v[i]] += 1 else: r[v[i]] += 1 max_l = l.index(max(l)) max_r = r.index(max(r)) count = 0 if max_l == max_r: for i in range(len(r)): if r[i] == r[max_r]: r[i] = 0 if l[i] == l[max_l]: l[i] = 0 if max(l) > max(r): max_l = l.index(max(l)) else: max_r = r.index(max(r)) for i in range(n): if i % 2 == 0 and v[i] != max_l: count += 1 if i % 2 != 0 and v[i] != max_r: count += 1 print(count)
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) import math import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) inf = 10 ** 15 mod = 10 ** 9 + 7 n = int(eval(input())) v = list(map(int, input().split())) # 偶数番目の要素において、iの数が何個あったか even = [0 for i in range(100001)] # 奇数番目の要素において、iの数が何個あったか odd = [0 for i in range(100001)] # 偶数番目、奇数番目の要素、それぞれ数える for i in range(0, n-1, 2): even[v[i]] += 1 odd[v[i+1]] += 1 # 偶数番目の要素のうち最も多かった数値 maxeveni = -1 # 偶数番目の要素のうち最も多かった数値の個数 maxeven = 0 # 偶数番目の要素のうち2番目に多かった数値の個数 preeven = 0 # 奇数番目の要素のうち最も多かった数値 maxoddi = -1 # 奇数番目の要素のうち最も多かった数値の個数 maxodd = 0 # 奇数番目の要素のうち2番目に多かった数値の個数 preodd = 0 # 偶数番目の要素を走査 for i in range(1, 100001): num = even[i] if maxeven <= num: maxeveni = i preeven = maxeven maxeven = num elif preeven <= num: preeven = num # 奇数番目の要素を走査 for i in range(1, 100001): num = odd[i] if maxodd <= num: maxoddi = i preodd = maxodd maxodd = num elif preodd <= num: preodd = num ans = 0 # 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合 if maxeveni != maxoddi: ans = n - maxeven - maxodd # 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合 else: ans = min(n - preeven - maxodd, n - maxeven - preodd) print(ans)
41
67
809
1,338
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) import itertools import math import fractions import functools l = [0] * (10**5 + 1) r = [0] * (10**5 + 1) n = int(eval(input())) v = list(map(int, input().split())) for i in range(n): if i % 2 == 0: l[v[i]] += 1 else: r[v[i]] += 1 max_l = l.index(max(l)) max_r = r.index(max(r)) count = 0 if max_l == max_r: for i in range(len(r)): if r[i] == r[max_r]: r[i] = 0 if l[i] == l[max_l]: l[i] = 0 if max(l) > max(r): max_l = l.index(max(l)) else: max_r = r.index(max(r)) for i in range(n): if i % 2 == 0 and v[i] != max_l: count += 1 if i % 2 != 0 and v[i] != max_r: count += 1 print(count)
# input() # int(input()) # map(int, input().split()) # list(map(int, input().split())) import math import sys import bisect import heapq # 優先度付きキュー(最小値取り出し) inf = 10**15 mod = 10**9 + 7 n = int(eval(input())) v = list(map(int, input().split())) # 偶数番目の要素において、iの数が何個あったか even = [0 for i in range(100001)] # 奇数番目の要素において、iの数が何個あったか odd = [0 for i in range(100001)] # 偶数番目、奇数番目の要素、それぞれ数える for i in range(0, n - 1, 2): even[v[i]] += 1 odd[v[i + 1]] += 1 # 偶数番目の要素のうち最も多かった数値 maxeveni = -1 # 偶数番目の要素のうち最も多かった数値の個数 maxeven = 0 # 偶数番目の要素のうち2番目に多かった数値の個数 preeven = 0 # 奇数番目の要素のうち最も多かった数値 maxoddi = -1 # 奇数番目の要素のうち最も多かった数値の個数 maxodd = 0 # 奇数番目の要素のうち2番目に多かった数値の個数 preodd = 0 # 偶数番目の要素を走査 for i in range(1, 100001): num = even[i] if maxeven <= num: maxeveni = i preeven = maxeven maxeven = num elif preeven <= num: preeven = num # 奇数番目の要素を走査 for i in range(1, 100001): num = odd[i] if maxodd <= num: maxoddi = i preodd = maxodd maxodd = num elif preodd <= num: preodd = num ans = 0 # 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合 if maxeveni != maxoddi: ans = n - maxeven - maxodd # 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合 else: ans = min(n - preeven - maxodd, n - maxeven - preodd) print(ans)
false
38.80597
[ "-import itertools", "-import fractions", "-import functools", "+import sys", "+import bisect", "+import heapq # 優先度付きキュー(最小値取り出し)", "-l = [0] * (10**5 + 1)", "-r = [0] * (10**5 + 1)", "+inf = 10**15", "+mod = 10**9 + 7", "-for i in range(n):", "- if i % 2 == 0:", "- l[v[i]] += 1", "- else:", "- r[v[i]] += 1", "-max_l = l.index(max(l))", "-max_r = r.index(max(r))", "-count = 0", "-if max_l == max_r:", "- for i in range(len(r)):", "- if r[i] == r[max_r]:", "- r[i] = 0", "- if l[i] == l[max_l]:", "- l[i] = 0", "-if max(l) > max(r):", "- max_l = l.index(max(l))", "+# 偶数番目の要素において、iの数が何個あったか", "+even = [0 for i in range(100001)]", "+# 奇数番目の要素において、iの数が何個あったか", "+odd = [0 for i in range(100001)]", "+# 偶数番目、奇数番目の要素、それぞれ数える", "+for i in range(0, n - 1, 2):", "+ even[v[i]] += 1", "+ odd[v[i + 1]] += 1", "+# 偶数番目の要素のうち最も多かった数値", "+maxeveni = -1", "+# 偶数番目の要素のうち最も多かった数値の個数", "+maxeven = 0", "+# 偶数番目の要素のうち2番目に多かった数値の個数", "+preeven = 0", "+# 奇数番目の要素のうち最も多かった数値", "+maxoddi = -1", "+# 奇数番目の要素のうち最も多かった数値の個数", "+maxodd = 0", "+# 奇数番目の要素のうち2番目に多かった数値の個数", "+preodd = 0", "+# 偶数番目の要素を走査", "+for i in range(1, 100001):", "+ num = even[i]", "+ if maxeven <= num:", "+ maxeveni = i", "+ preeven = maxeven", "+ maxeven = num", "+ elif preeven <= num:", "+ preeven = num", "+# 奇数番目の要素を走査", "+for i in range(1, 100001):", "+ num = odd[i]", "+ if maxodd <= num:", "+ maxoddi = i", "+ preodd = maxodd", "+ maxodd = num", "+ elif preodd <= num:", "+ preodd = num", "+ans = 0", "+# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合", "+if maxeveni != maxoddi:", "+ ans = n - maxeven - maxodd", "+# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合", "- max_r = r.index(max(r))", "-for i in range(n):", "- if i % 2 == 0 and v[i] != max_l:", "- count += 1", "- if i % 2 != 0 and v[i] != max_r:", "- count += 1", "-print(count)", "+ ans = min(n - preeven - maxodd, n - maxeven - preodd)", "+print(ans)" ]
false
0.055925
0.103621
0.539704
[ "s213659512", "s373378256" ]
u171366497
p03574
python
s310752504
s164503330
35
24
3,700
3,188
Accepted
Accepted
31.43
h,w=list(map(int,input().split())) from collections import defaultdict data=defaultdict(int) for y in range(h): line=eval(input()) for x in range(w): if line[x]=='#': data[(y,x)]=-1 for i in range(-1,2): for j in range(-1,2): if data[(y+i,x+j)]!=-1: data[(y+i,x+j)]+=1 for y in range(h): s='' for x in range(w): if data[(y,x)]==-1:s+='#' else:s+=str(data[(y,x)]) print(s)
H,W=list(map(int,input().split())) Map=['.'*(W+2)] for i in range(H): line='.'+eval(input())+'.' x=[] for j in range(W+2): x.append(line[j]) Map.append(x) Map.append('.'*(W+2)) for h in range(1,1+H): for w in range(1,1+W): if Map[h][w]=='.': cnt=0 for i,j in [(-1,-1),(-1,0),(0,-1),(1,-1),(-1,1),(1,0),(0,1),(1,1)]: if Map[h+i][w+j]=='#':cnt+=1 Map[h][w]=str(cnt) for h in range(1,1+H): print((''.join(Map[h][1:-1])))
18
18
504
512
h, w = list(map(int, input().split())) from collections import defaultdict data = defaultdict(int) for y in range(h): line = eval(input()) for x in range(w): if line[x] == "#": data[(y, x)] = -1 for i in range(-1, 2): for j in range(-1, 2): if data[(y + i, x + j)] != -1: data[(y + i, x + j)] += 1 for y in range(h): s = "" for x in range(w): if data[(y, x)] == -1: s += "#" else: s += str(data[(y, x)]) print(s)
H, W = list(map(int, input().split())) Map = ["." * (W + 2)] for i in range(H): line = "." + eval(input()) + "." x = [] for j in range(W + 2): x.append(line[j]) Map.append(x) Map.append("." * (W + 2)) for h in range(1, 1 + H): for w in range(1, 1 + W): if Map[h][w] == ".": cnt = 0 for i, j in [ (-1, -1), (-1, 0), (0, -1), (1, -1), (-1, 1), (1, 0), (0, 1), (1, 1), ]: if Map[h + i][w + j] == "#": cnt += 1 Map[h][w] = str(cnt) for h in range(1, 1 + H): print(("".join(Map[h][1:-1])))
false
0
[ "-h, w = list(map(int, input().split()))", "-from collections import defaultdict", "-", "-data = defaultdict(int)", "-for y in range(h):", "- line = eval(input())", "- for x in range(w):", "- if line[x] == \"#\":", "- data[(y, x)] = -1", "- for i in range(-1, 2):", "- for j in range(-1, 2):", "- if data[(y + i, x + j)] != -1:", "- data[(y + i, x + j)] += 1", "-for y in range(h):", "- s = \"\"", "- for x in range(w):", "- if data[(y, x)] == -1:", "- s += \"#\"", "- else:", "- s += str(data[(y, x)])", "- print(s)", "+H, W = list(map(int, input().split()))", "+Map = [\".\" * (W + 2)]", "+for i in range(H):", "+ line = \".\" + eval(input()) + \".\"", "+ x = []", "+ for j in range(W + 2):", "+ x.append(line[j])", "+ Map.append(x)", "+Map.append(\".\" * (W + 2))", "+for h in range(1, 1 + H):", "+ for w in range(1, 1 + W):", "+ if Map[h][w] == \".\":", "+ cnt = 0", "+ for i, j in [", "+ (-1, -1),", "+ (-1, 0),", "+ (0, -1),", "+ (1, -1),", "+ (-1, 1),", "+ (1, 0),", "+ (0, 1),", "+ (1, 1),", "+ ]:", "+ if Map[h + i][w + j] == \"#\":", "+ cnt += 1", "+ Map[h][w] = str(cnt)", "+for h in range(1, 1 + H):", "+ print((\"\".join(Map[h][1:-1])))" ]
false
0.040635
0.040317
1.007878
[ "s310752504", "s164503330" ]
u691018832
p02681
python
s435733520
s002890425
64
22
61,616
9,100
Accepted
Accepted
65.62
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) s = readline().rstrip().decode() t = readline().rstrip().decode() if s == t[:len(t) - 1]: print('Yes') else: print('No')
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) s = readline().rstrip().decode() t = read().rstrip().decode() print(('Yes' if s == t[:-1] else 'No'))
12
9
288
256
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) s = readline().rstrip().decode() t = readline().rstrip().decode() if s == t[: len(t) - 1]: print("Yes") else: print("No")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) s = readline().rstrip().decode() t = read().rstrip().decode() print(("Yes" if s == t[:-1] else "No"))
false
25
[ "-t = readline().rstrip().decode()", "-if s == t[: len(t) - 1]:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+t = read().rstrip().decode()", "+print((\"Yes\" if s == t[:-1] else \"No\"))" ]
false
0.125354
0.047934
2.615151
[ "s435733520", "s002890425" ]
u047796752
p02711
python
s666176497
s465065460
73
65
64,612
61,856
Accepted
Accepted
10.96
from collections import * N = eval(input()) if '7' in N: print('Yes') else: print('No')
N = eval(input()) if '7' in N: print('Yes') else: print('No')
8
6
98
69
from collections import * N = eval(input()) if "7" in N: print("Yes") else: print("No")
N = eval(input()) if "7" in N: print("Yes") else: print("No")
false
25
[ "-from collections import *", "-" ]
false
0.039231
0.065052
0.603074
[ "s666176497", "s465065460" ]
u636683284
p03546
python
s273197359
s137821377
429
82
76,968
73,908
Accepted
Accepted
80.89
import heapq def dijkstra(s): hq = [(0, s)] heapq.heapify(hq) # リストを優先度付きキューに変換 cost = [float('inf')] * 10 # 行ったことのないところはinf cost[s] = 0 # 開始地点は0 while hq: c, v = heapq.heappop(hq) if c > cost[v]: # コストが現在のコストよりも高ければスルー continue for d, u in e[v]: tmp = d + cost[v] if tmp < cost[u]: cost[u] = tmp heapq.heappush(hq, (tmp, u)) return cost h,w = list(map(int,input().split())) e = [[] for _ in range(10)] for i in range(10): alist = list(map(int,input().split())) for j in range(10): if i != j: e[i].append((alist[j], j)) l = [] for i in range(h): for a in list(map(int,input().split())): if a != -1: l.append(a) ans = 0 for i in l: ans += dijkstra(i)[1] print(ans)
def floyd_warshall(dist): v = len(dist) for k in range(v): for i in range(v): for j in range(v): dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) h,w = list(map(int,input().split())) c = [list(map(int,input().split())) for _ in range(10)] floyd_warshall(c) A = [list(map(int,input().split())) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if A[i][j] != -1: ans += c[A[i][j]][1] print(ans)
37
17
870
488
import heapq def dijkstra(s): hq = [(0, s)] heapq.heapify(hq) # リストを優先度付きキューに変換 cost = [float("inf")] * 10 # 行ったことのないところはinf cost[s] = 0 # 開始地点は0 while hq: c, v = heapq.heappop(hq) if c > cost[v]: # コストが現在のコストよりも高ければスルー continue for d, u in e[v]: tmp = d + cost[v] if tmp < cost[u]: cost[u] = tmp heapq.heappush(hq, (tmp, u)) return cost h, w = list(map(int, input().split())) e = [[] for _ in range(10)] for i in range(10): alist = list(map(int, input().split())) for j in range(10): if i != j: e[i].append((alist[j], j)) l = [] for i in range(h): for a in list(map(int, input().split())): if a != -1: l.append(a) ans = 0 for i in l: ans += dijkstra(i)[1] print(ans)
def floyd_warshall(dist): v = len(dist) for k in range(v): for i in range(v): for j in range(v): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) h, w = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] floyd_warshall(c) A = [list(map(int, input().split())) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if A[i][j] != -1: ans += c[A[i][j]][1] print(ans)
false
54.054054
[ "-import heapq", "-", "-", "-def dijkstra(s):", "- hq = [(0, s)]", "- heapq.heapify(hq) # リストを優先度付きキューに変換", "- cost = [float(\"inf\")] * 10 # 行ったことのないところはinf", "- cost[s] = 0 # 開始地点は0", "- while hq:", "- c, v = heapq.heappop(hq)", "- if c > cost[v]: # コストが現在のコストよりも高ければスルー", "- continue", "- for d, u in e[v]:", "- tmp = d + cost[v]", "- if tmp < cost[u]:", "- cost[u] = tmp", "- heapq.heappush(hq, (tmp, u))", "- return cost", "+def floyd_warshall(dist):", "+ v = len(dist)", "+ for k in range(v):", "+ for i in range(v):", "+ for j in range(v):", "+ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "-e = [[] for _ in range(10)]", "-for i in range(10):", "- alist = list(map(int, input().split()))", "- for j in range(10):", "- if i != j:", "- e[i].append((alist[j], j))", "-l = []", "+c = [list(map(int, input().split())) for _ in range(10)]", "+floyd_warshall(c)", "+A = [list(map(int, input().split())) for _ in range(h)]", "+ans = 0", "- for a in list(map(int, input().split())):", "- if a != -1:", "- l.append(a)", "-ans = 0", "-for i in l:", "- ans += dijkstra(i)[1]", "+ for j in range(w):", "+ if A[i][j] != -1:", "+ ans += c[A[i][j]][1]" ]
false
0.055664
0.04819
1.155082
[ "s273197359", "s137821377" ]
u077291787
p02925
python
s334218393
s729281713
906
698
80,220
146,352
Accepted
Accepted
22.96
# ABC139E - League from collections import deque def main(): N = int(eval(input())) A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N)) cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1) q = deque(list(range(1, N + 1))) while q: x = q.popleft() if not A[x]: # player x has finished all games continue y = A[x].popleft() # the opponent of x if cur[y] == x: # player y's next game is against x and vice versa cnt += 1 days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game cur[x], cur[y] = 0, 0 # no next game is currently planned q.append(x), q.append(y) else: # the opponent will do another game before playing against x cur[x] = y flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not print((max(days) if flg else -1)) if __name__ == "__main__": main()
# ABC139E - League from collections import deque def main(): N, *A = list(map(int, open(0).read().split())) B = {} for i in range(N): x = i * (N - 1) B[i + 1] = deque(A[x : x + N - 1]) cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1) q = deque(list(range(1, N + 1))) while q: x = q.popleft() if not B[x]: # player x has finished all games continue y = B[x].popleft() if cur[y] == x: # player y's next game is against x and vice versa cnt += 1 days[x] = days[y] = max(days[x], days[y]) + 1 cur[x], cur[y] = 0, 0 q.append(x), q.append(y) else: # the opponent will do another game before playing against x cur[x] = y flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not print((max(days) if flg else -1)) if __name__ == "__main__": main()
27
30
970
943
# ABC139E - League from collections import deque def main(): N = int(eval(input())) A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N)) cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1) q = deque(list(range(1, N + 1))) while q: x = q.popleft() if not A[x]: # player x has finished all games continue y = A[x].popleft() # the opponent of x if cur[y] == x: # player y's next game is against x and vice versa cnt += 1 days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game cur[x], cur[y] = 0, 0 # no next game is currently planned q.append(x), q.append(y) else: # the opponent will do another game before playing against x cur[x] = y flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not print((max(days) if flg else -1)) if __name__ == "__main__": main()
# ABC139E - League from collections import deque def main(): N, *A = list(map(int, open(0).read().split())) B = {} for i in range(N): x = i * (N - 1) B[i + 1] = deque(A[x : x + N - 1]) cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1) q = deque(list(range(1, N + 1))) while q: x = q.popleft() if not B[x]: # player x has finished all games continue y = B[x].popleft() if cur[y] == x: # player y's next game is against x and vice versa cnt += 1 days[x] = days[y] = max(days[x], days[y]) + 1 cur[x], cur[y] = 0, 0 q.append(x), q.append(y) else: # the opponent will do another game before playing against x cur[x] = y flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not print((max(days) if flg else -1)) if __name__ == "__main__": main()
false
10
[ "- N = int(eval(input()))", "- A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N))", "+ N, *A = list(map(int, open(0).read().split()))", "+ B = {}", "+ for i in range(N):", "+ x = i * (N - 1)", "+ B[i + 1] = deque(A[x : x + N - 1])", "- if not A[x]: # player x has finished all games", "+ if not B[x]: # player x has finished all games", "- y = A[x].popleft() # the opponent of x", "+ y = B[x].popleft()", "- days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game", "- cur[x], cur[y] = 0, 0 # no next game is currently planned", "+ days[x] = days[y] = max(days[x], days[y]) + 1", "+ cur[x], cur[y] = 0, 0" ]
false
0.037534
0.033509
1.120121
[ "s334218393", "s729281713" ]
u759934006
p00114
python
s652401934
s911909158
560
300
6,740
6,744
Accepted
Accepted
46.43
# 0114 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) while True: try: x, y, z = 1, 1, 1 c1, c2 ,c3 = 0, 0, 0 a1, m1, a2, m2, a3, m3 = list(map(int, input().split())) if sum([a1, m1, a2, m2, a3, m3]) == 0: break while True: x = a1 * x % m1 c1 += 1 if x == 1: break while True: y = a2 * y % m2 c2 += 1 if y == 1: break while True: z = a3 * z % m3 c3 += 1 if z == 1: break print((int(lcm(c1, lcm(c2, c3))))) except EOFError: break
# 0114 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) def times(a, m): c = 1 x = a * 1 % m while x != 1: x = a * x % m c += 1 return c while True: try: x, y, z = 1, 1, 1 c1, c2 ,c3 = 0, 0, 0 a1, m1, a2, m2, a3, m3 = list(map(int, input().split())) if sum([a1, m1, a2, m2, a3, m3]) == 0: break c1 = times(a1, m1) c2 = times(a2, m2) c3 = times(a3, m3) print((int(lcm(c1, lcm(c2, c3))))) except EOFError: break
40
34
584
525
# 0114 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) while True: try: x, y, z = 1, 1, 1 c1, c2, c3 = 0, 0, 0 a1, m1, a2, m2, a3, m3 = list(map(int, input().split())) if sum([a1, m1, a2, m2, a3, m3]) == 0: break while True: x = a1 * x % m1 c1 += 1 if x == 1: break while True: y = a2 * y % m2 c2 += 1 if y == 1: break while True: z = a3 * z % m3 c3 += 1 if z == 1: break print((int(lcm(c1, lcm(c2, c3))))) except EOFError: break
# 0114 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) def times(a, m): c = 1 x = a * 1 % m while x != 1: x = a * x % m c += 1 return c while True: try: x, y, z = 1, 1, 1 c1, c2, c3 = 0, 0, 0 a1, m1, a2, m2, a3, m3 = list(map(int, input().split())) if sum([a1, m1, a2, m2, a3, m3]) == 0: break c1 = times(a1, m1) c2 = times(a2, m2) c3 = times(a3, m3) print((int(lcm(c1, lcm(c2, c3))))) except EOFError: break
false
15
[ "+def times(a, m):", "+ c = 1", "+ x = a * 1 % m", "+ while x != 1:", "+ x = a * x % m", "+ c += 1", "+ return c", "+", "+", "- while True:", "- x = a1 * x % m1", "- c1 += 1", "- if x == 1:", "- break", "- while True:", "- y = a2 * y % m2", "- c2 += 1", "- if y == 1:", "- break", "- while True:", "- z = a3 * z % m3", "- c3 += 1", "- if z == 1:", "- break", "+ c1 = times(a1, m1)", "+ c2 = times(a2, m2)", "+ c3 = times(a3, m3)" ]
false
0.085938
0.038854
2.21182
[ "s652401934", "s911909158" ]
u931636178
p03448
python
s058785516
s101146388
57
51
3,060
3,060
Accepted
Accepted
10.53
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) ans = 0 for count_500 in range(A+1): for count_100 in range(B+1): for count_50 in range(C+1): sum_money = 500*count_500 + 100*count_100 + 50*count_50 if sum_money == X: ans += 1 print(ans)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) count = 0 for i1 in range(A+1): for i2 in range(B+1): for i3 in range(C+1): if (i1*500 + i2*100 + i3 *50) == X: count += 1 print(count)
13
11
321
253
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) ans = 0 for count_500 in range(A + 1): for count_100 in range(B + 1): for count_50 in range(C + 1): sum_money = 500 * count_500 + 100 * count_100 + 50 * count_50 if sum_money == X: ans += 1 print(ans)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) count = 0 for i1 in range(A + 1): for i2 in range(B + 1): for i3 in range(C + 1): if (i1 * 500 + i2 * 100 + i3 * 50) == X: count += 1 print(count)
false
15.384615
[ "-ans = 0", "-for count_500 in range(A + 1):", "- for count_100 in range(B + 1):", "- for count_50 in range(C + 1):", "- sum_money = 500 * count_500 + 100 * count_100 + 50 * count_50", "- if sum_money == X:", "- ans += 1", "-print(ans)", "+count = 0", "+for i1 in range(A + 1):", "+ for i2 in range(B + 1):", "+ for i3 in range(C + 1):", "+ if (i1 * 500 + i2 * 100 + i3 * 50) == X:", "+ count += 1", "+print(count)" ]
false
0.139624
0.121641
1.147834
[ "s058785516", "s101146388" ]
u325282913
p03476
python
s982446981
s319415554
836
721
4,980
94,380
Accepted
Accepted
13.76
def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime Q = int(eval(input())) ans = [0] * (10**5+1) prime = primes(10**5) for i in range(1,10**5+1): if prime[i] == 1 and prime[(i+1)//2] == 1: ans[i] = ans[i-1] + 1 continue ans[i] = ans[i-1] for i in range(Q): l, r = list(map(int, input().split())) print((ans[r]-ans[l-1]))
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True Q = int(eval(input())) cnt = [0]*(10**5+1) for i in range(1,10**5+1): if i % 2 == 0: cnt[i] = cnt[i-1] continue if is_prime(i) and is_prime((i+1)//2): cnt[i] = cnt[i-1] + 1 else: cnt[i] = cnt[i-1] for _ in range(Q): l, r = list(map(int, input().split())) print((cnt[r]-cnt[l-1]))
21
20
583
503
def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime Q = int(eval(input())) ans = [0] * (10**5 + 1) prime = primes(10**5) for i in range(1, 10**5 + 1): if prime[i] == 1 and prime[(i + 1) // 2] == 1: ans[i] = ans[i - 1] + 1 continue ans[i] = ans[i - 1] for i in range(Q): l, r = list(map(int, input().split())) print((ans[r] - ans[l - 1]))
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True Q = int(eval(input())) cnt = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): if i % 2 == 0: cnt[i] = cnt[i - 1] continue if is_prime(i) and is_prime((i + 1) // 2): cnt[i] = cnt[i - 1] + 1 else: cnt[i] = cnt[i - 1] for _ in range(Q): l, r = list(map(int, input().split())) print((cnt[r] - cnt[l - 1]))
false
4.761905
[ "-def primes(n):", "- is_prime = [True] * (n + 1)", "- is_prime[0] = False", "- is_prime[1] = False", "- for i in range(2, int(n**0.5) + 1):", "- if not is_prime[i]:", "- continue", "- for j in range(i * 2, n + 1, i):", "- is_prime[j] = False", "- return is_prime", "+import math", "+", "+", "+def is_prime(n):", "+ if n == 1:", "+ return False", "+ for k in range(2, int(math.sqrt(n)) + 1):", "+ if n % k == 0:", "+ return False", "+ return True", "-ans = [0] * (10**5 + 1)", "-prime = primes(10**5)", "+cnt = [0] * (10**5 + 1)", "- if prime[i] == 1 and prime[(i + 1) // 2] == 1:", "- ans[i] = ans[i - 1] + 1", "+ if i % 2 == 0:", "+ cnt[i] = cnt[i - 1]", "- ans[i] = ans[i - 1]", "-for i in range(Q):", "+ if is_prime(i) and is_prime((i + 1) // 2):", "+ cnt[i] = cnt[i - 1] + 1", "+ else:", "+ cnt[i] = cnt[i - 1]", "+for _ in range(Q):", "- print((ans[r] - ans[l - 1]))", "+ print((cnt[r] - cnt[l - 1]))" ]
false
0.132478
0.488168
0.271378
[ "s982446981", "s319415554" ]
u802234509
p02824
python
s044417257
s954825517
312
241
62,576
62,576
Accepted
Accepted
22.76
import bisect n, m, v, p = list(map(int, input().split())) ls = list(map(int, input().split())) ls.sort() total=m*v for i in range(min(v-1,p-1)): ls[-i-1]+=m total-=m ac = [0]*n for i in range(n-1): ac[i+1] = ac[i]+(ls[i+1]-ls[i])*(i+1) ans=p for i in range(n-p): idx=bisect.bisect_right(ls,ls[i]+m) if n-idx>=p: continue totalnow=total-m*(i+1) if totalnow <= 0: ans += 1 continue ok=ac[-p]-ac[i]-(ls[-p]-ls[i])*(i+1)+(ls[i]+m-ls[-p])*(n-p-i) if ok< totalnow: continue ans += 1 print(ans)
import bisect n, m, v, p = list(map(int, input().split())) ls = list(map(int, input().split())) ls.sort() total=m*v for i in range(min(v-1,p-1)): ls[-i-1]+=m total-=m ac = [0]*n for i in range(n-1): ac[i+1] = ac[i]+(ls[i+1]-ls[i])*(i+1) l=-1 r=n while l+1<r: i=(l+r)//2 idx=bisect.bisect_right(ls,ls[i]+m) if n-idx>=p: l=i continue totalnow=total-m*(i+1) if totalnow <= 0: r=i continue ok=ac[-p]-ac[i]-(ls[-p]-ls[i])*(i+1)+(ls[i]+m-ls[-p])*(n-p-i) if ok< totalnow: l=i continue r=i print((n-r))
30
34
589
617
import bisect n, m, v, p = list(map(int, input().split())) ls = list(map(int, input().split())) ls.sort() total = m * v for i in range(min(v - 1, p - 1)): ls[-i - 1] += m total -= m ac = [0] * n for i in range(n - 1): ac[i + 1] = ac[i] + (ls[i + 1] - ls[i]) * (i + 1) ans = p for i in range(n - p): idx = bisect.bisect_right(ls, ls[i] + m) if n - idx >= p: continue totalnow = total - m * (i + 1) if totalnow <= 0: ans += 1 continue ok = ( ac[-p] - ac[i] - (ls[-p] - ls[i]) * (i + 1) + (ls[i] + m - ls[-p]) * (n - p - i) ) if ok < totalnow: continue ans += 1 print(ans)
import bisect n, m, v, p = list(map(int, input().split())) ls = list(map(int, input().split())) ls.sort() total = m * v for i in range(min(v - 1, p - 1)): ls[-i - 1] += m total -= m ac = [0] * n for i in range(n - 1): ac[i + 1] = ac[i] + (ls[i + 1] - ls[i]) * (i + 1) l = -1 r = n while l + 1 < r: i = (l + r) // 2 idx = bisect.bisect_right(ls, ls[i] + m) if n - idx >= p: l = i continue totalnow = total - m * (i + 1) if totalnow <= 0: r = i continue ok = ( ac[-p] - ac[i] - (ls[-p] - ls[i]) * (i + 1) + (ls[i] + m - ls[-p]) * (n - p - i) ) if ok < totalnow: l = i continue r = i print((n - r))
false
11.764706
[ "-ans = p", "-for i in range(n - p):", "+l = -1", "+r = n", "+while l + 1 < r:", "+ i = (l + r) // 2", "+ l = i", "- ans += 1", "+ r = i", "+ l = i", "- ans += 1", "-print(ans)", "+ r = i", "+print((n - r))" ]
false
0.047522
0.040536
1.172343
[ "s044417257", "s954825517" ]
u761320129
p03998
python
s904479124
s391902035
27
17
3,060
3,064
Accepted
Accepted
37.04
sa = eval(input()) sb = eval(input()) sc = eval(input()) ai = bi = ci = -1 turn = 'a' while True: exec(turn + 'i += 1') turn = eval('s' + turn + '[' + turn + 'i-1]') if eval(turn + 'i == len(s' + turn + ')'): print((turn.upper())) exit()
A = eval(input()) B = eval(input()) C = eval(input()) ai = bi = ci = 0 turn = 'a' while 1: if turn == 'a': if ai >= len(A): print('A') exit() turn = A[ai] ai += 1 elif turn == 'b': if bi >= len(B): print('B') exit() turn = B[bi] bi += 1 else: if ci >= len(C): print('C') exit() turn = C[ci] ci += 1
12
25
257
461
sa = eval(input()) sb = eval(input()) sc = eval(input()) ai = bi = ci = -1 turn = "a" while True: exec(turn + "i += 1") turn = eval("s" + turn + "[" + turn + "i-1]") if eval(turn + "i == len(s" + turn + ")"): print((turn.upper())) exit()
A = eval(input()) B = eval(input()) C = eval(input()) ai = bi = ci = 0 turn = "a" while 1: if turn == "a": if ai >= len(A): print("A") exit() turn = A[ai] ai += 1 elif turn == "b": if bi >= len(B): print("B") exit() turn = B[bi] bi += 1 else: if ci >= len(C): print("C") exit() turn = C[ci] ci += 1
false
52
[ "-sa = eval(input())", "-sb = eval(input())", "-sc = eval(input())", "-ai = bi = ci = -1", "+A = eval(input())", "+B = eval(input())", "+C = eval(input())", "+ai = bi = ci = 0", "-while True:", "- exec(turn + \"i += 1\")", "- turn = eval(\"s\" + turn + \"[\" + turn + \"i-1]\")", "- if eval(turn + \"i == len(s\" + turn + \")\"):", "- print((turn.upper()))", "- exit()", "+while 1:", "+ if turn == \"a\":", "+ if ai >= len(A):", "+ print(\"A\")", "+ exit()", "+ turn = A[ai]", "+ ai += 1", "+ elif turn == \"b\":", "+ if bi >= len(B):", "+ print(\"B\")", "+ exit()", "+ turn = B[bi]", "+ bi += 1", "+ else:", "+ if ci >= len(C):", "+ print(\"C\")", "+ exit()", "+ turn = C[ci]", "+ ci += 1" ]
false
0.07829
0.0648
1.208174
[ "s904479124", "s391902035" ]
u332385682
p03805
python
s153977246
s160774470
26
21
3,192
3,064
Accepted
Accepted
19.23
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2**(N-1) - 1 dp = [[0]*(N-1) for i in range(univ + 1)] for u in range(N - 1): if Adj[0][u+1]: dp[1<<u][u] = 1 for S in range(univ + 1): for v in range(N - 1): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u+1][v+1]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(N - 1)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0]*N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == '__main__': solve()
def bit_dp(N, Adj): dp = [[0]*N for i in range(1 << N)] # dp({0], 0) = 1 と初期化する dp[1][0] = 1 for S in range(1 << N): for v in range(N): # v が S に含まれていないときはパスする if (S & (1 << v)) == 0: continue # sub = S - {v} sub = S ^ (1 << v) for u in range(N): # sub に u が含まれており、かつ u と v が辺で結ばれている if (sub & (1 << u)) and (Adj[u][v]): dp[S][v] += dp[sub][u] ans = sum(dp[(1 << N) - 1][u] for u in range(1, N)) return ans def main(): N, M = list(map(int, input().split())) Adj = [[0]*N for i in range(N)] for _ in range(M): a, b = list(map(int, input().split())) Adj[a-1][b-1] = 1 Adj[b-1][a-1] = 1 ans = bit_dp(N, Adj) print(ans) if __name__ == '__main__': main()
45
39
1,025
895
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2 ** (N - 1) - 1 dp = [[0] * (N - 1) for i in range(univ + 1)] for u in range(N - 1): if Adj[0][u + 1]: dp[1 << u][u] = 1 for S in range(univ + 1): for v in range(N - 1): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u + 1][v + 1]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(N - 1)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0] * N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == "__main__": solve()
def bit_dp(N, Adj): dp = [[0] * N for i in range(1 << N)] # dp({0], 0) = 1 と初期化する dp[1][0] = 1 for S in range(1 << N): for v in range(N): # v が S に含まれていないときはパスする if (S & (1 << v)) == 0: continue # sub = S - {v} sub = S ^ (1 << v) for u in range(N): # sub に u が含まれており、かつ u と v が辺で結ばれている if (sub & (1 << u)) and (Adj[u][v]): dp[S][v] += dp[sub][u] ans = sum(dp[(1 << N) - 1][u] for u in range(1, N)) return ans def main(): N, M = list(map(int, input().split())) Adj = [[0] * N for i in range(N)] for _ in range(M): a, b = list(map(int, input().split())) Adj[a - 1][b - 1] = 1 Adj[b - 1][a - 1] = 1 ans = bit_dp(N, Adj) print(ans) if __name__ == "__main__": main()
false
13.333333
[ "-import sys", "-", "-", "-def debug(x, table):", "- for name, val in table.items():", "- if x is val:", "- print(\"DEBUG:{} -> {}\".format(name, val), file=sys.stderr)", "- return None", "-", "-", "-def do_dp(N, Adj):", "- univ = 2 ** (N - 1) - 1", "- dp = [[0] * (N - 1) for i in range(univ + 1)]", "- for u in range(N - 1):", "- if Adj[0][u + 1]:", "- dp[1 << u][u] = 1", "- for S in range(univ + 1):", "- for v in range(N - 1):", "- S2 = S & (univ ^ (1 << v))", "+def bit_dp(N, Adj):", "+ dp = [[0] * N for i in range(1 << N)]", "+ # dp({0], 0) = 1 と初期化する", "+ dp[1][0] = 1", "+ for S in range(1 << N):", "+ for v in range(N):", "+ # v が S に含まれていないときはパスする", "+ if (S & (1 << v)) == 0:", "+ continue", "+ # sub = S - {v}", "+ sub = S ^ (1 << v)", "- if ((1 << u) & S2) and Adj[u + 1][v + 1]:", "- dp[S][v] += dp[S2][u]", "- # debug(dp, locals())", "- ans = sum(dp[univ][u] for u in range(N - 1))", "+ # sub に u が含まれており、かつ u と v が辺で結ばれている", "+ if (sub & (1 << u)) and (Adj[u][v]):", "+ dp[S][v] += dp[sub][u]", "+ ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))", "-def solve():", "- N, M = map(int, input().split())", "+def main():", "+ N, M = list(map(int, input().split()))", "- for i in range(M):", "- a, b = map(int, input().split())", "- a -= 1", "- b -= 1", "- Adj[a][b] = 1", "- Adj[b][a] = 1", "- ans = do_dp(N, Adj)", "+ for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ Adj[a - 1][b - 1] = 1", "+ Adj[b - 1][a - 1] = 1", "+ ans = bit_dp(N, Adj)", "- solve()", "+ main()" ]
false
0.105329
0.168737
0.624218
[ "s153977246", "s160774470" ]
u047023156
p02862
python
s658312625
s579991650
180
166
38,640
3,696
Accepted
Accepted
7.78
import math, sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from copy import deepcopy from functools import lru_cache from heapq import heapify, heappop, heappush from itertools import accumulate, combinations, permutations input = sys.stdin.readline mod = 10**9 + 7 ns = lambda: input().strip() ni = lambda: int(input().strip()) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def main(): def fur(n,r): p,q = 1,1 for i in range(r): p = p*(n-i)%mod q = q*(i+1)%mod return p * pow(q,mod-2,mod) % mod x, y = nm() if (x + y) % 3 != 0: print((0)) exit() n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) if n < 0 or m < 0: print((0)) exit() print((fur(n+m, n))) if __name__ == '__main__': main()
import math, sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from copy import deepcopy from functools import lru_cache from heapq import heapify, heappop, heappush from itertools import accumulate, combinations, permutations input = sys.stdin.readline mod = 10**9 + 7 ns = lambda: input().strip() ni = lambda: int(input().strip()) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def fur(n,r): p,q = 1,1 for i in range(r): p = p*(n-i)%mod q = q*(i+1)%mod return p * pow(q,mod-2,mod) % mod x, y = nm() if (x + y) % 3 != 0: print((0)) exit() n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) if n < 0 or m < 0: print((0)) exit() print((fur(n+m, n)))
40
37
974
854
import math, sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from copy import deepcopy from functools import lru_cache from heapq import heapify, heappop, heappush from itertools import accumulate, combinations, permutations input = sys.stdin.readline mod = 10**9 + 7 ns = lambda: input().strip() ni = lambda: int(input().strip()) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def main(): def fur(n, r): p, q = 1, 1 for i in range(r): p = p * (n - i) % mod q = q * (i + 1) % mod return p * pow(q, mod - 2, mod) % mod x, y = nm() if (x + y) % 3 != 0: print((0)) exit() n = (2 * y - x) // 3 # (X, Y) -> (X+1, Y+2) m = (2 * x - y) // 3 # (X, Y) -> (X+2, Y+1) if n < 0 or m < 0: print((0)) exit() print((fur(n + m, n))) if __name__ == "__main__": main()
import math, sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from copy import deepcopy from functools import lru_cache from heapq import heapify, heappop, heappush from itertools import accumulate, combinations, permutations input = sys.stdin.readline mod = 10**9 + 7 ns = lambda: input().strip() ni = lambda: int(input().strip()) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) def fur(n, r): p, q = 1, 1 for i in range(r): p = p * (n - i) % mod q = q * (i + 1) % mod return p * pow(q, mod - 2, mod) % mod x, y = nm() if (x + y) % 3 != 0: print((0)) exit() n = (2 * y - x) // 3 # (X, Y) -> (X+1, Y+2) m = (2 * x - y) // 3 # (X, Y) -> (X+2, Y+1) if n < 0 or m < 0: print((0)) exit() print((fur(n + m, n)))
false
7.5
[ "-def main():", "- def fur(n, r):", "- p, q = 1, 1", "- for i in range(r):", "- p = p * (n - i) % mod", "- q = q * (i + 1) % mod", "- return p * pow(q, mod - 2, mod) % mod", "-", "- x, y = nm()", "- if (x + y) % 3 != 0:", "- print((0))", "- exit()", "- n = (2 * y - x) // 3 # (X, Y) -> (X+1, Y+2)", "- m = (2 * x - y) // 3 # (X, Y) -> (X+2, Y+1)", "- if n < 0 or m < 0:", "- print((0))", "- exit()", "- print((fur(n + m, n)))", "+def fur(n, r):", "+ p, q = 1, 1", "+ for i in range(r):", "+ p = p * (n - i) % mod", "+ q = q * (i + 1) % mod", "+ return p * pow(q, mod - 2, mod) % mod", "-if __name__ == \"__main__\":", "- main()", "+x, y = nm()", "+if (x + y) % 3 != 0:", "+ print((0))", "+ exit()", "+n = (2 * y - x) // 3 # (X, Y) -> (X+1, Y+2)", "+m = (2 * x - y) // 3 # (X, Y) -> (X+2, Y+1)", "+if n < 0 or m < 0:", "+ print((0))", "+ exit()", "+print((fur(n + m, n)))" ]
false
0.074435
0.086378
0.861745
[ "s658312625", "s579991650" ]
u454524105
p03147
python
s387782526
s480774136
485
264
3,060
3,060
Accepted
Accepted
45.57
n = int(eval(input())) h = [int(i) for i in input().split()] r = i = 0 while max(h) != 0: if h[i] == 0: i += 1 else: r += 1 while i < n and h[i] > 0: h[i] -= 1 i += 1 i = 0 print(r)
n = int(eval(input())) h = [int(i) for i in input().split()] r = i = 0 while sum(h) != 0: if h[i] == 0: i += 1 else: r += 1 while i < n and h[i] > 0: h[i] -= 1 i += 1 i = 0 print(r)
13
13
251
251
n = int(eval(input())) h = [int(i) for i in input().split()] r = i = 0 while max(h) != 0: if h[i] == 0: i += 1 else: r += 1 while i < n and h[i] > 0: h[i] -= 1 i += 1 i = 0 print(r)
n = int(eval(input())) h = [int(i) for i in input().split()] r = i = 0 while sum(h) != 0: if h[i] == 0: i += 1 else: r += 1 while i < n and h[i] > 0: h[i] -= 1 i += 1 i = 0 print(r)
false
0
[ "-while max(h) != 0:", "+while sum(h) != 0:" ]
false
0.044962
0.082352
0.545977
[ "s387782526", "s480774136" ]
u435480265
p02727
python
s173486227
s693592139
345
237
23,328
23,328
Accepted
Accepted
31.3
x,y,a,b,c = list(map(int,input().split())) lst_r = list(map(int,input().split())) lst_g = list(map(int,input().split())) lst_n = list([int(x)*(-1) for x in input().split()]) from heapq import * heapify(lst_r) for i in range(a-x): _ = heappop(lst_r) heapify(lst_g) for i in range(b-y): _ = heappop(lst_g) heapify(lst_n) while len(lst_n)>0: flg = lst_r > lst_g cur = -1 * heappop(lst_n) if flg and cur > lst_g[0]: _ = heappushpop(lst_g,cur) elif (not flg) and cur > lst_r[0]: _ = heappushpop(lst_r,cur) else: break print((sum(lst_g)+sum(lst_r)))
x,y,a,b,c = list(map(int,input().split())) lst_r = list(map(int,input().split())) lst_g = list(map(int,input().split())) lst_n = list(map(int,input().split())) lst_r = sorted(lst_r, reverse=True)[:x] lst_g = sorted(lst_g, reverse=True)[:y] lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[:x+y] print((sum(lst_all)))
26
8
623
320
x, y, a, b, c = list(map(int, input().split())) lst_r = list(map(int, input().split())) lst_g = list(map(int, input().split())) lst_n = list([int(x) * (-1) for x in input().split()]) from heapq import * heapify(lst_r) for i in range(a - x): _ = heappop(lst_r) heapify(lst_g) for i in range(b - y): _ = heappop(lst_g) heapify(lst_n) while len(lst_n) > 0: flg = lst_r > lst_g cur = -1 * heappop(lst_n) if flg and cur > lst_g[0]: _ = heappushpop(lst_g, cur) elif (not flg) and cur > lst_r[0]: _ = heappushpop(lst_r, cur) else: break print((sum(lst_g) + sum(lst_r)))
x, y, a, b, c = list(map(int, input().split())) lst_r = list(map(int, input().split())) lst_g = list(map(int, input().split())) lst_n = list(map(int, input().split())) lst_r = sorted(lst_r, reverse=True)[:x] lst_g = sorted(lst_g, reverse=True)[:y] lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[: x + y] print((sum(lst_all)))
false
69.230769
[ "-lst_n = list([int(x) * (-1) for x in input().split()])", "-from heapq import *", "-", "-heapify(lst_r)", "-for i in range(a - x):", "- _ = heappop(lst_r)", "-heapify(lst_g)", "-for i in range(b - y):", "- _ = heappop(lst_g)", "-heapify(lst_n)", "-while len(lst_n) > 0:", "- flg = lst_r > lst_g", "- cur = -1 * heappop(lst_n)", "- if flg and cur > lst_g[0]:", "- _ = heappushpop(lst_g, cur)", "- elif (not flg) and cur > lst_r[0]:", "- _ = heappushpop(lst_r, cur)", "- else:", "- break", "-print((sum(lst_g) + sum(lst_r)))", "+lst_n = list(map(int, input().split()))", "+lst_r = sorted(lst_r, reverse=True)[:x]", "+lst_g = sorted(lst_g, reverse=True)[:y]", "+lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[: x + y]", "+print((sum(lst_all)))" ]
false
0.037707
0.037055
1.017585
[ "s173486227", "s693592139" ]
u047796752
p02665
python
s453749322
s235603483
132
81
89,740
82,892
Accepted
Accepted
38.64
import sys input = sys.stdin.readline from collections import * N = int(eval(input())) A = list(map(int, input().split())) low = [0]*(N+1) high = [0]*(N+1) low[N] = A[N] high[N] = A[N] if A[N]>2**N: print((-1)) exit() for i in range(N-1, -1, -1): low[i] = (low[i+1]+1)//2+A[i] high[i] = high[i+1]+A[i] lim = 2**i if low[i]>lim: print((-1)) exit() high[i] = min(high[i], lim) now = 1 ans = now #print(low) #print(high) for i in range(N): now = min(high[i+1], 2*now) ans += now now -= A[i+1] print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) low = [0]*(N+1) high = [0]*(N+1) low[N] = A[N] high[N] = A[N] for i in range(N-1, -1, -1): low[i] = (low[i+1]+1)//2+A[i] high[i] = high[i+1]+A[i] if not low[0]<=1<=high[0]: print((-1)) exit() ans = 1 now = 1 for i in range(N): now = min(2*(now-A[i]), high[i+1]) ans += now print(ans)
38
26
604
427
import sys input = sys.stdin.readline from collections import * N = int(eval(input())) A = list(map(int, input().split())) low = [0] * (N + 1) high = [0] * (N + 1) low[N] = A[N] high[N] = A[N] if A[N] > 2**N: print((-1)) exit() for i in range(N - 1, -1, -1): low[i] = (low[i + 1] + 1) // 2 + A[i] high[i] = high[i + 1] + A[i] lim = 2**i if low[i] > lim: print((-1)) exit() high[i] = min(high[i], lim) now = 1 ans = now # print(low) # print(high) for i in range(N): now = min(high[i + 1], 2 * now) ans += now now -= A[i + 1] print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) low = [0] * (N + 1) high = [0] * (N + 1) low[N] = A[N] high[N] = A[N] for i in range(N - 1, -1, -1): low[i] = (low[i + 1] + 1) // 2 + A[i] high[i] = high[i + 1] + A[i] if not low[0] <= 1 <= high[0]: print((-1)) exit() ans = 1 now = 1 for i in range(N): now = min(2 * (now - A[i]), high[i + 1]) ans += now print(ans)
false
31.578947
[ "-from collections import *", "-", "-if A[N] > 2**N:", "- print((-1))", "- exit()", "- lim = 2**i", "- if low[i] > lim:", "- print((-1))", "- exit()", "- high[i] = min(high[i], lim)", "+if not low[0] <= 1 <= high[0]:", "+ print((-1))", "+ exit()", "+ans = 1", "-ans = now", "-# print(low)", "-# print(high)", "- now = min(high[i + 1], 2 * now)", "+ now = min(2 * (now - A[i]), high[i + 1])", "- now -= A[i + 1]" ]
false
0.039559
0.03964
0.997967
[ "s453749322", "s235603483" ]
u761320129
p04046
python
s320667884
s875460692
1,130
440
18,564
28,376
Accepted
Accepted
61.06
MOD = 10**9+7 def add(a,b): return (a+b) % MOD def mul(a,b): return (a*b) % MOD def pow(a,n): ans = 1 mag = a for b in reversed(str(bin(n))): if b == 'b': break if b == '1': ans = mul(ans, mag) mag = mul(mag, mag) return ans def inv(a): return pow(a, MOD-2) H,W,A,B = list(map(int,input().split())) factorical = [1] factorical_inv = [1] for n in range (1,H+W+1): f = mul(factorical[n-1], n) factorical.append(f) if(n <= max(H,W)): factorical_inv.append(inv(f)) def ncr(n,r): return mul(mul(factorical[n], factorical_inv[n-r]), factorical_inv[r]) def paths(w,h): return ncr(w+h,w) ans = 0 for i in range(W-B): p = mul(paths(H-A-1, B+i), paths(A-1, W-B-1-i)) ans = add(ans, p) print(ans)
H,W,A,B = list(map(int,input().split())) N = H+W+10 MOD = 10**9+7 fac = [1,1] + [0]*N finv = [1,1] + [0]*N inv = [0,1] + [0]*N for i in range(2,N+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def ncr(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD ans = 0 for i in range(W-B): ans += ncr(H-1-A+B+i, H-1-A) * ncr(A-1+W-1-B-i, A-1) ans %= MOD print(ans)
42
23
782
519
MOD = 10**9 + 7 def add(a, b): return (a + b) % MOD def mul(a, b): return (a * b) % MOD def pow(a, n): ans = 1 mag = a for b in reversed(str(bin(n))): if b == "b": break if b == "1": ans = mul(ans, mag) mag = mul(mag, mag) return ans def inv(a): return pow(a, MOD - 2) H, W, A, B = list(map(int, input().split())) factorical = [1] factorical_inv = [1] for n in range(1, H + W + 1): f = mul(factorical[n - 1], n) factorical.append(f) if n <= max(H, W): factorical_inv.append(inv(f)) def ncr(n, r): return mul(mul(factorical[n], factorical_inv[n - r]), factorical_inv[r]) def paths(w, h): return ncr(w + h, w) ans = 0 for i in range(W - B): p = mul(paths(H - A - 1, B + i), paths(A - 1, W - B - 1 - i)) ans = add(ans, p) print(ans)
H, W, A, B = list(map(int, input().split())) N = H + W + 10 MOD = 10**9 + 7 fac = [1, 1] + [0] * N finv = [1, 1] + [0] * N inv = [0, 1] + [0] * N for i in range(2, N + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def ncr(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD ans = 0 for i in range(W - B): ans += ncr(H - 1 - A + B + i, H - 1 - A) * ncr(A - 1 + W - 1 - B - i, A - 1) ans %= MOD print(ans)
false
45.238095
[ "+H, W, A, B = list(map(int, input().split()))", "+N = H + W + 10", "-", "-", "-def add(a, b):", "- return (a + b) % MOD", "-", "-", "-def mul(a, b):", "- return (a * b) % MOD", "-", "-", "-def pow(a, n):", "- ans = 1", "- mag = a", "- for b in reversed(str(bin(n))):", "- if b == \"b\":", "- break", "- if b == \"1\":", "- ans = mul(ans, mag)", "- mag = mul(mag, mag)", "- return ans", "-", "-", "-def inv(a):", "- return pow(a, MOD - 2)", "-", "-", "-H, W, A, B = list(map(int, input().split()))", "-factorical = [1]", "-factorical_inv = [1]", "-for n in range(1, H + W + 1):", "- f = mul(factorical[n - 1], n)", "- factorical.append(f)", "- if n <= max(H, W):", "- factorical_inv.append(inv(f))", "+fac = [1, 1] + [0] * N", "+finv = [1, 1] + [0] * N", "+inv = [0, 1] + [0] * N", "+for i in range(2, N + 2):", "+ fac[i] = fac[i - 1] * i % MOD", "+ inv[i] = -inv[MOD % i] * (MOD // i) % MOD", "+ finv[i] = finv[i - 1] * inv[i] % MOD", "- return mul(mul(factorical[n], factorical_inv[n - r]), factorical_inv[r])", "-", "-", "-def paths(w, h):", "- return ncr(w + h, w)", "+ if n < r:", "+ return 0", "+ if n < 0 or r < 0:", "+ return 0", "+ return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD", "- p = mul(paths(H - A - 1, B + i), paths(A - 1, W - B - 1 - i))", "- ans = add(ans, p)", "+ ans += ncr(H - 1 - A + B + i, H - 1 - A) * ncr(A - 1 + W - 1 - B - i, A - 1)", "+ ans %= MOD" ]
false
0.044049
0.044225
0.996041
[ "s320667884", "s875460692" ]
u644907318
p02834
python
s347127992
s768820313
742
380
76,260
103,724
Accepted
Accepted
48.79
from collections import deque INFTY = 10**6 N,u,v = list(map(int,input().split())) G = {i:[] for i in range(1,N+1)} for _ in range(N-1): a,b = list(map(int,input().split())) G[a].append(b) G[b].append(a) du = [INFTY for _ in range(N+1)] du[u] = 0 que = deque([(0,u)]) hist = [0 for _ in range(N+1)] hist[u] = 1 while que: c,i = que.popleft() for j in G[i]: if hist[j]==0: que.append((c+1,j)) du[j] = c+1 hist[j] = 1 dv = [INFTY for _ in range(N+1)] dv[v] = 0 que = deque([(0,v)]) hist = [0 for _ in range(N+1)] hist[v] = 1 while que: c,i = que.popleft() for j in G[i]: if hist[j]==0: que.append((c+1,j)) dv[j] = c+1 hist[j] = 1 cmax = 0 for i in range(1,N+1): if du[i]<dv[i]: cmax = max(cmax,dv[i]) print((cmax-1))
from collections import deque N,u,v = list(map(int,input().split())) G = {i:[] for i in range(1,N+1)} for _ in range(N-1): a,b = list(map(int,input().split())) G[a].append(b) G[b].append(a) distT = [0 for _ in range(N+1)] heap = deque([(u,0)]) distT[u] = 0 hist = [0 for _ in range(N+1)] hist[u] = 1 while heap: x,d = heap.popleft() for y in G[x]: if hist[y]==0: distT[y] = d+1 heap.append((y,d+1)) hist[y]=1 heap = deque([(v,0)]) distA = [0 for _ in range(N+1)] heap = deque([(v,0)]) distA[v] = 0 hist = [0 for _ in range(N+1)] hist[v] = 1 while heap: x,d = heap.popleft() for y in G[x]: if hist[y]==0: distA[y]=d+1 heap.append((y,d+1)) hist[y] = 1 cmax = 0 for i in range(1,N+1): if distT[i]<=distA[i] and distA[i]>cmax: cmax = distA[i] print((cmax-1))
37
37
864
904
from collections import deque INFTY = 10**6 N, u, v = list(map(int, input().split())) G = {i: [] for i in range(1, N + 1)} for _ in range(N - 1): a, b = list(map(int, input().split())) G[a].append(b) G[b].append(a) du = [INFTY for _ in range(N + 1)] du[u] = 0 que = deque([(0, u)]) hist = [0 for _ in range(N + 1)] hist[u] = 1 while que: c, i = que.popleft() for j in G[i]: if hist[j] == 0: que.append((c + 1, j)) du[j] = c + 1 hist[j] = 1 dv = [INFTY for _ in range(N + 1)] dv[v] = 0 que = deque([(0, v)]) hist = [0 for _ in range(N + 1)] hist[v] = 1 while que: c, i = que.popleft() for j in G[i]: if hist[j] == 0: que.append((c + 1, j)) dv[j] = c + 1 hist[j] = 1 cmax = 0 for i in range(1, N + 1): if du[i] < dv[i]: cmax = max(cmax, dv[i]) print((cmax - 1))
from collections import deque N, u, v = list(map(int, input().split())) G = {i: [] for i in range(1, N + 1)} for _ in range(N - 1): a, b = list(map(int, input().split())) G[a].append(b) G[b].append(a) distT = [0 for _ in range(N + 1)] heap = deque([(u, 0)]) distT[u] = 0 hist = [0 for _ in range(N + 1)] hist[u] = 1 while heap: x, d = heap.popleft() for y in G[x]: if hist[y] == 0: distT[y] = d + 1 heap.append((y, d + 1)) hist[y] = 1 heap = deque([(v, 0)]) distA = [0 for _ in range(N + 1)] heap = deque([(v, 0)]) distA[v] = 0 hist = [0 for _ in range(N + 1)] hist[v] = 1 while heap: x, d = heap.popleft() for y in G[x]: if hist[y] == 0: distA[y] = d + 1 heap.append((y, d + 1)) hist[y] = 1 cmax = 0 for i in range(1, N + 1): if distT[i] <= distA[i] and distA[i] > cmax: cmax = distA[i] print((cmax - 1))
false
0
[ "-INFTY = 10**6", "-du = [INFTY for _ in range(N + 1)]", "-du[u] = 0", "-que = deque([(0, u)])", "+distT = [0 for _ in range(N + 1)]", "+heap = deque([(u, 0)])", "+distT[u] = 0", "-while que:", "- c, i = que.popleft()", "- for j in G[i]:", "- if hist[j] == 0:", "- que.append((c + 1, j))", "- du[j] = c + 1", "- hist[j] = 1", "-dv = [INFTY for _ in range(N + 1)]", "-dv[v] = 0", "-que = deque([(0, v)])", "+while heap:", "+ x, d = heap.popleft()", "+ for y in G[x]:", "+ if hist[y] == 0:", "+ distT[y] = d + 1", "+ heap.append((y, d + 1))", "+ hist[y] = 1", "+heap = deque([(v, 0)])", "+distA = [0 for _ in range(N + 1)]", "+heap = deque([(v, 0)])", "+distA[v] = 0", "-while que:", "- c, i = que.popleft()", "- for j in G[i]:", "- if hist[j] == 0:", "- que.append((c + 1, j))", "- dv[j] = c + 1", "- hist[j] = 1", "+while heap:", "+ x, d = heap.popleft()", "+ for y in G[x]:", "+ if hist[y] == 0:", "+ distA[y] = d + 1", "+ heap.append((y, d + 1))", "+ hist[y] = 1", "- if du[i] < dv[i]:", "- cmax = max(cmax, dv[i])", "+ if distT[i] <= distA[i] and distA[i] > cmax:", "+ cmax = distA[i]" ]
false
0.036516
0.03268
1.117379
[ "s347127992", "s768820313" ]
u145035045
p03354
python
s892372555
s386524614
549
496
38,240
14,008
Accepted
Accepted
9.65
def solve(): n, m = list(map(int,input().split())) plst = list(map(int,input().split())) pare_inds = [i for i in range(n)] belongs = [[] for i in range(n)] def get_root(x): p = pare_inds[x] if p == x: return x a = get_root(p) pare_inds[x] = a return a for i in range(m): x, y = list(map(int,input().split())) x, y = x - 1, y - 1 r_x, r_y = get_root(x), get_root(y) if r_x < r_y: pare_inds[y] = r_x pare_inds[r_y] = r_x else: pare_inds[x] = r_y pare_inds[r_x] = r_y for i in range(n): belongs[get_root(i)].append(i) ans = 0 for lst in belongs: lst2 = [plst[i] - 1 for i in lst] set1 = set(lst) set2 = set(lst2) ans += len(set1 & set2) # lst.sort() # lst2.sort() # ind1 = 0 # ind2 = 0 # end = len(lst) # while ind1 < end and ind2 < end: # if lst[ind1] == lst2[ind2]: # ans += 1 # ind1 += 1 # ind2 += 1 # elif lst[ind1] < lst2[ind2]: # ind1 += 1 # else: # ind2 += 1 print(ans) solve()
def solve(): n, m = list(map(int,input().split())) plst = list(map(int,input().split())) pare_inds = [i for i in range(n)] def find(x): p = pare_inds[x] if p == x: return x a = find(p) pare_inds[x] = a return a for i in range(m): x, y = list(map(int,input().split())) x, y = x - 1, y - 1 r_x, r_y = find(x), find(y) pare_inds[y] = r_x pare_inds[r_y] = r_x ans = 0 for i in range(n): if find(i) == find(plst[i] - 1): ans += 1 print(ans) solve()
52
27
1,113
540
def solve(): n, m = list(map(int, input().split())) plst = list(map(int, input().split())) pare_inds = [i for i in range(n)] belongs = [[] for i in range(n)] def get_root(x): p = pare_inds[x] if p == x: return x a = get_root(p) pare_inds[x] = a return a for i in range(m): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 r_x, r_y = get_root(x), get_root(y) if r_x < r_y: pare_inds[y] = r_x pare_inds[r_y] = r_x else: pare_inds[x] = r_y pare_inds[r_x] = r_y for i in range(n): belongs[get_root(i)].append(i) ans = 0 for lst in belongs: lst2 = [plst[i] - 1 for i in lst] set1 = set(lst) set2 = set(lst2) ans += len(set1 & set2) # lst.sort() # lst2.sort() # ind1 = 0 # ind2 = 0 # end = len(lst) # while ind1 < end and ind2 < end: # if lst[ind1] == lst2[ind2]: # ans += 1 # ind1 += 1 # ind2 += 1 # elif lst[ind1] < lst2[ind2]: # ind1 += 1 # else: # ind2 += 1 print(ans) solve()
def solve(): n, m = list(map(int, input().split())) plst = list(map(int, input().split())) pare_inds = [i for i in range(n)] def find(x): p = pare_inds[x] if p == x: return x a = find(p) pare_inds[x] = a return a for i in range(m): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 r_x, r_y = find(x), find(y) pare_inds[y] = r_x pare_inds[r_y] = r_x ans = 0 for i in range(n): if find(i) == find(plst[i] - 1): ans += 1 print(ans) solve()
false
48.076923
[ "- belongs = [[] for i in range(n)]", "- def get_root(x):", "+ def find(x):", "- a = get_root(p)", "+ a = find(p)", "- r_x, r_y = get_root(x), get_root(y)", "- if r_x < r_y:", "- pare_inds[y] = r_x", "- pare_inds[r_y] = r_x", "- else:", "- pare_inds[x] = r_y", "- pare_inds[r_x] = r_y", "+ r_x, r_y = find(x), find(y)", "+ pare_inds[y] = r_x", "+ pare_inds[r_y] = r_x", "+ ans = 0", "- belongs[get_root(i)].append(i)", "- ans = 0", "- for lst in belongs:", "- lst2 = [plst[i] - 1 for i in lst]", "- set1 = set(lst)", "- set2 = set(lst2)", "- ans += len(set1 & set2)", "- # lst.sort()", "- # lst2.sort()", "- # ind1 = 0", "- # ind2 = 0", "- # end = len(lst)", "- # while ind1 < end and ind2 < end:", "- # if lst[ind1] == lst2[ind2]:", "- # ans += 1", "- # ind1 += 1", "- # ind2 += 1", "- # elif lst[ind1] < lst2[ind2]:", "- # ind1 += 1", "- # else:", "- # ind2 += 1", "+ if find(i) == find(plst[i] - 1):", "+ ans += 1" ]
false
0.042546
0.03772
1.127951
[ "s892372555", "s386524614" ]
u576432509
p03779
python
s032259035
s640545734
28
17
3,060
2,940
Accepted
Accepted
39.29
x=int(eval(input())) i=0 isum=0 while isum<x: i=i+1 isum=isum+i print(i)
x=int(eval(input())) t=int(((-1+(8*x+1)**0.5)-10**(-10))/2)+1 print(t)
9
4
84
69
x = int(eval(input())) i = 0 isum = 0 while isum < x: i = i + 1 isum = isum + i print(i)
x = int(eval(input())) t = int(((-1 + (8 * x + 1) ** 0.5) - 10 ** (-10)) / 2) + 1 print(t)
false
55.555556
[ "-i = 0", "-isum = 0", "-while isum < x:", "- i = i + 1", "- isum = isum + i", "-print(i)", "+t = int(((-1 + (8 * x + 1) ** 0.5) - 10 ** (-10)) / 2) + 1", "+print(t)" ]
false
0.053128
0.039699
1.33827
[ "s032259035", "s640545734" ]
u986014912
p02787
python
s504424073
s112081737
346
306
16,092
33,004
Accepted
Accepted
11.56
import sys import numpy as np h, n = list(map(int, input().split())) ab = np.array(sys.stdin.read().split(), dtype=np.int64) aaa = ab[0::2] bbb = ab[1::2] dp = np.zeros(10001, dtype=np.int64) for i in range(1, h + 1): dp[i] = (dp[i - aaa] + bbb).min() print((dp[h])) # https://atcoder.jp/contests/abc153/submissions/9776226
# coding=utf-8 # Date: 2020-01-08 # Author: lee215 get = lambda: int(input().strip()) getl = lambda: input().strip() gets = lambda: list(map(int, input().strip().split())) getss = lambda n: [gets() for _ in range(n)] h, N = gets() AB = getss(N) dp = [0] + [float('inf')] * h for a, b in AB: for i in range(h): j = min(i + a, h) dp[j] = min(dp[j], dp[i] + b) print((dp[h]))
15
18
342
422
import sys import numpy as np h, n = list(map(int, input().split())) ab = np.array(sys.stdin.read().split(), dtype=np.int64) aaa = ab[0::2] bbb = ab[1::2] dp = np.zeros(10001, dtype=np.int64) for i in range(1, h + 1): dp[i] = (dp[i - aaa] + bbb).min() print((dp[h])) # https://atcoder.jp/contests/abc153/submissions/9776226
# coding=utf-8 # Date: 2020-01-08 # Author: lee215 get = lambda: int(input().strip()) getl = lambda: input().strip() gets = lambda: list(map(int, input().strip().split())) getss = lambda n: [gets() for _ in range(n)] h, N = gets() AB = getss(N) dp = [0] + [float("inf")] * h for a, b in AB: for i in range(h): j = min(i + a, h) dp[j] = min(dp[j], dp[i] + b) print((dp[h]))
false
16.666667
[ "-import sys", "-import numpy as np", "-", "-h, n = list(map(int, input().split()))", "-ab = np.array(sys.stdin.read().split(), dtype=np.int64)", "-aaa = ab[0::2]", "-bbb = ab[1::2]", "-dp = np.zeros(10001, dtype=np.int64)", "-for i in range(1, h + 1):", "- dp[i] = (dp[i - aaa] + bbb).min()", "+# coding=utf-8", "+# Date: 2020-01-08", "+# Author: lee215", "+get = lambda: int(input().strip())", "+getl = lambda: input().strip()", "+gets = lambda: list(map(int, input().strip().split()))", "+getss = lambda n: [gets() for _ in range(n)]", "+h, N = gets()", "+AB = getss(N)", "+dp = [0] + [float(\"inf\")] * h", "+for a, b in AB:", "+ for i in range(h):", "+ j = min(i + a, h)", "+ dp[j] = min(dp[j], dp[i] + b)", "-# https://atcoder.jp/contests/abc153/submissions/9776226" ]
false
0.296169
0.124308
2.382539
[ "s504424073", "s112081737" ]
u262597910
p02936
python
s727046810
s072257957
1,989
1,421
74,756
73,732
Accepted
Accepted
28.56
n,q = list(map(int, input().split())) way = [[] for _ in range(n)] for i in range(n-1): a,b = list(map(int, input().split())) way[a-1].append(b-1) way[b-1].append(a-1) add = [0]*n for i in range(q): a,b = list(map(int, input().split())) add[a-1] += b ans = [-1]*n ans[0] = add[0] stack = [(0,add[0])] while stack: a,b = stack.pop() for i in range(len(way[a])): if (ans[way[a][i]]==-1): stack.append((way[a][i],b+add[way[a][i]])) ans[way[a][i]] = b+add[way[a][i]] print((*ans))
import sys input = sys.stdin.readline n,q = list(map(int, input().split())) way = [[] for _ in range(n)] for i in range(n-1): a,b = list(map(int, input().split())) way[a-1].append(b-1) way[b-1].append(a-1) add = [0]*n for i in range(q): a,b = list(map(int, input().split())) add[a-1] += b ans = [-1]*n ans[0] = add[0] stack = [(0,add[0])] while stack: a,b = stack.pop() for i in range(len(way[a])): if (ans[way[a][i]]==-1): stack.append((way[a][i],b+add[way[a][i]])) ans[way[a][i]] = b+add[way[a][i]] print((*ans))
21
25
541
589
n, q = list(map(int, input().split())) way = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) way[a - 1].append(b - 1) way[b - 1].append(a - 1) add = [0] * n for i in range(q): a, b = list(map(int, input().split())) add[a - 1] += b ans = [-1] * n ans[0] = add[0] stack = [(0, add[0])] while stack: a, b = stack.pop() for i in range(len(way[a])): if ans[way[a][i]] == -1: stack.append((way[a][i], b + add[way[a][i]])) ans[way[a][i]] = b + add[way[a][i]] print((*ans))
import sys input = sys.stdin.readline n, q = list(map(int, input().split())) way = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) way[a - 1].append(b - 1) way[b - 1].append(a - 1) add = [0] * n for i in range(q): a, b = list(map(int, input().split())) add[a - 1] += b ans = [-1] * n ans[0] = add[0] stack = [(0, add[0])] while stack: a, b = stack.pop() for i in range(len(way[a])): if ans[way[a][i]] == -1: stack.append((way[a][i], b + add[way[a][i]])) ans[way[a][i]] = b + add[way[a][i]] print((*ans))
false
16
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.050867
0.077302
0.658036
[ "s727046810", "s072257957" ]
u912237403
p00096
python
s347870681
s871361941
1,150
170
4,492
4,316
Accepted
Accepted
85.22
import sys a=[0]*2001 b=[0]*4001 n=1001 for i in range(n): for j in range(n): a[i+j]+=1 n=2001 for i in range(n): for j in range(n): b[i+j]+=a[i]*a[j] for i in sys.stdin: print(b[int(i)])
import sys n=1001 a=[0]*2001 for i in range(n): for j in range(n): a[i+j]+=1 for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
13
12
212
205
import sys a = [0] * 2001 b = [0] * 4001 n = 1001 for i in range(n): for j in range(n): a[i + j] += 1 n = 2001 for i in range(n): for j in range(n): b[i + j] += a[i] * a[j] for i in sys.stdin: print(b[int(i)])
import sys n = 1001 a = [0] * 2001 for i in range(n): for j in range(n): a[i + j] += 1 for n in map(int, sys.stdin): x = 0 for i in range(max(0, n - 2000), min(n, 2000) + 1): x += a[i] * a[n - i] print(x)
false
7.692308
[ "+n = 1001", "-b = [0] * 4001", "-n = 1001", "-n = 2001", "-for i in range(n):", "- for j in range(n):", "- b[i + j] += a[i] * a[j]", "-for i in sys.stdin:", "- print(b[int(i)])", "+for n in map(int, sys.stdin):", "+ x = 0", "+ for i in range(max(0, n - 2000), min(n, 2000) + 1):", "+ x += a[i] * a[n - i]", "+ print(x)" ]
false
3.181013
0.326481
9.743321
[ "s347870681", "s871361941" ]
u780475861
p02803
python
s515235307
s977262527
1,962
327
12,420
3,064
Accepted
Accepted
83.33
import sys import numpy as np from heapq import heappop, heappush read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H,W = list(map(int,readline().split())) grid = np.full((H+2,W+2),b'#',dtype='S1') grid[1:-1,1:-1] = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W] INF = 400 def shortest(grid, start, cost=0): dist = np.array([[INF for _ in range(W+2)] for _ in range(H+2)]) dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] st = [(cost, start)] dist[start[0]][start[1]]=0 while(st): c, [sx, sy] = heappop(st) for a, b in zip(dx, dy): x = sx + a y = sy + b if grid[x][y]==b'#': continue dxy = dist[sx][sy] + 1 if dist[x][y] <= dxy: continue dist[x][y] = dxy heappush(st, (dist[x][y], [x, y])) return np.max(dist[dist<INF]) m=0 for i in range(1,H+1): for j in range(1,W+1): if grid[i,j]==b'#': continue tm = shortest(grid, [i, j]) if m < tm: m=tm print(m)
import sys from heapq import heappop, heappush readline = sys.stdin.readline H, W = list(map(int, readline().split())) grid = '#' * (W + 2) + ''.join('#' + readline().strip() + '#' for _ in range(H)) + '#' * (W + 2) INF = 400 def shortest(grid, start, cost=0): dist = [INF] * (H + 2) * (W + 2) move = (-1, 1, W + 2, -W - 2) st = [start] dist[start] = 0 while(st): sx = heappop(st) c = dist[sx] for a in move: x = sx + a if grid[x] == '#': continue dx = dist[sx] + 1 if dist[x] <= dx: continue dist[x] = dx heappush(st, x) return max(x for x in dist if x < INF) m = 0 for i in range(W + 3, (H + 1) * (W + 2) - 1): if grid[i] == '#': continue tm = shortest(grid, i) if m < tm: m = tm print(m)
42
39
1,120
940
import sys import numpy as np from heapq import heappop, heappush read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H, W = list(map(int, readline().split())) grid = np.full((H + 2, W + 2), b"#", dtype="S1") grid[1:-1, 1:-1] = np.frombuffer(read(), "S1").reshape(H, -1)[:, :W] INF = 400 def shortest(grid, start, cost=0): dist = np.array([[INF for _ in range(W + 2)] for _ in range(H + 2)]) dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] st = [(cost, start)] dist[start[0]][start[1]] = 0 while st: c, [sx, sy] = heappop(st) for a, b in zip(dx, dy): x = sx + a y = sy + b if grid[x][y] == b"#": continue dxy = dist[sx][sy] + 1 if dist[x][y] <= dxy: continue dist[x][y] = dxy heappush(st, (dist[x][y], [x, y])) return np.max(dist[dist < INF]) m = 0 for i in range(1, H + 1): for j in range(1, W + 1): if grid[i, j] == b"#": continue tm = shortest(grid, [i, j]) if m < tm: m = tm print(m)
import sys from heapq import heappop, heappush readline = sys.stdin.readline H, W = list(map(int, readline().split())) grid = ( "#" * (W + 2) + "".join("#" + readline().strip() + "#" for _ in range(H)) + "#" * (W + 2) ) INF = 400 def shortest(grid, start, cost=0): dist = [INF] * (H + 2) * (W + 2) move = (-1, 1, W + 2, -W - 2) st = [start] dist[start] = 0 while st: sx = heappop(st) c = dist[sx] for a in move: x = sx + a if grid[x] == "#": continue dx = dist[sx] + 1 if dist[x] <= dx: continue dist[x] = dx heappush(st, x) return max(x for x in dist if x < INF) m = 0 for i in range(W + 3, (H + 1) * (W + 2) - 1): if grid[i] == "#": continue tm = shortest(grid, i) if m < tm: m = tm print(m)
false
7.142857
[ "-import numpy as np", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "+readline = sys.stdin.readline", "-grid = np.full((H + 2, W + 2), b\"#\", dtype=\"S1\")", "-grid[1:-1, 1:-1] = np.frombuffer(read(), \"S1\").reshape(H, -1)[:, :W]", "+grid = (", "+ \"#\" * (W + 2)", "+ + \"\".join(\"#\" + readline().strip() + \"#\" for _ in range(H))", "+ + \"#\" * (W + 2)", "+)", "- dist = np.array([[INF for _ in range(W + 2)] for _ in range(H + 2)])", "- dx = [-1, 0, 1, 0]", "- dy = [0, 1, 0, -1]", "- st = [(cost, start)]", "- dist[start[0]][start[1]] = 0", "+ dist = [INF] * (H + 2) * (W + 2)", "+ move = (-1, 1, W + 2, -W - 2)", "+ st = [start]", "+ dist[start] = 0", "- c, [sx, sy] = heappop(st)", "- for a, b in zip(dx, dy):", "+ sx = heappop(st)", "+ c = dist[sx]", "+ for a in move:", "- y = sy + b", "- if grid[x][y] == b\"#\":", "+ if grid[x] == \"#\":", "- dxy = dist[sx][sy] + 1", "- if dist[x][y] <= dxy:", "+ dx = dist[sx] + 1", "+ if dist[x] <= dx:", "- dist[x][y] = dxy", "- heappush(st, (dist[x][y], [x, y]))", "- return np.max(dist[dist < INF])", "+ dist[x] = dx", "+ heappush(st, x)", "+ return max(x for x in dist if x < INF)", "-for i in range(1, H + 1):", "- for j in range(1, W + 1):", "- if grid[i, j] == b\"#\":", "- continue", "- tm = shortest(grid, [i, j])", "- if m < tm:", "- m = tm", "+for i in range(W + 3, (H + 1) * (W + 2) - 1):", "+ if grid[i] == \"#\":", "+ continue", "+ tm = shortest(grid, i)", "+ if m < tm:", "+ m = tm" ]
false
0.192002
0.064731
2.966131
[ "s515235307", "s977262527" ]
u729133443
p03564
python
s625577165
s623426299
167
17
38,256
2,940
Accepted
Accepted
89.82
n=int(eval(input()));k=int(eval(input()));r=1 for _ in[0]*n:r+=min(r,k) print(r)
n,k=eval('int(input()),'*2);r=1 for _ in[0]*n:r+=min(r,k) print(r)
3
3
70
68
n = int(eval(input())) k = int(eval(input())) r = 1 for _ in [0] * n: r += min(r, k) print(r)
n, k = eval("int(input())," * 2) r = 1 for _ in [0] * n: r += min(r, k) print(r)
false
0
[ "-n = int(eval(input()))", "-k = int(eval(input()))", "+n, k = eval(\"int(input()),\" * 2)" ]
false
0.13665
0.04455
3.067311
[ "s625577165", "s623426299" ]
u163320134
p02949
python
s721634035
s390285762
1,489
962
52,696
64,472
Accepted
Accepted
35.39
def BF(edges,n,s): inf=float("inf") d=[inf for i in range(n+1)] d[s]=0 flag=False for i in range(n+1): for v,u,cost in edges: if d[v]!=inf and d[u]>d[v]+cost: d[u]=d[v]+cost ans1=d[-1] for i in range(n+1): for v,u,cost in edges: if d[v]!=inf and d[u]>d[v]+cost: d[u]=d[v]+cost ans2=d[-1] if ans2<ans1: return -1 else: return max(-ans1,0) n,m,p=list(map(int,input().split())) g=[] for _ in range(m): a,b,c=list(map(int,input().split())) g.append([a,b,-(c-p)]) ans=BF(g,n,1) print(ans)
import sys sys.setrecursionlimit(10**9) def BF(edges,n,s): inf=float("inf") d=[inf for i in range(n+1)] d[s]=0 update=True cnt=0 while 1: update=False for v,u,cost in edges: if cand[v]!=1 or cand[u]!=1: continue if d[v]!=inf and d[u]>d[v]+cost: d[u]=d[v]+cost update=True if update==False: break cnt+=1 if cnt>n: return inf return -d[-1] def DFS_1toN(v): for u in to[v]: if toflag[u]==0: toflag[u]=1 DFS_1toN(u) def DFS_Nto1(v): for u in ot[v]: if otflag[u]==0: otflag[u]=1 DFS_Nto1(u) n,m,p=list(map(int,input().split())) g=[] to=[[] for _ in range(n+1)] ot=[[] for _ in range(n+1)] for _ in range(m): a,b,c=list(map(int,input().split())) g.append([a,b,-(c-p)]) to[a].append(b) ot[b].append(a) toflag=[0]*(n+1) toflag[1]=1 DFS_1toN(1) otflag=[0]*(n+1) otflag[n]=1 DFS_Nto1(n) cand=[0]*(n+1) for i in range(1,n+1): cand[i]=toflag[i]*otflag[i] ans=BF(g,n,1) if ans==float('inf'): print((-1)) else: print((max(ans,0)))
27
59
602
1,142
def BF(edges, n, s): inf = float("inf") d = [inf for i in range(n + 1)] d[s] = 0 flag = False for i in range(n + 1): for v, u, cost in edges: if d[v] != inf and d[u] > d[v] + cost: d[u] = d[v] + cost ans1 = d[-1] for i in range(n + 1): for v, u, cost in edges: if d[v] != inf and d[u] > d[v] + cost: d[u] = d[v] + cost ans2 = d[-1] if ans2 < ans1: return -1 else: return max(-ans1, 0) n, m, p = list(map(int, input().split())) g = [] for _ in range(m): a, b, c = list(map(int, input().split())) g.append([a, b, -(c - p)]) ans = BF(g, n, 1) print(ans)
import sys sys.setrecursionlimit(10**9) def BF(edges, n, s): inf = float("inf") d = [inf for i in range(n + 1)] d[s] = 0 update = True cnt = 0 while 1: update = False for v, u, cost in edges: if cand[v] != 1 or cand[u] != 1: continue if d[v] != inf and d[u] > d[v] + cost: d[u] = d[v] + cost update = True if update == False: break cnt += 1 if cnt > n: return inf return -d[-1] def DFS_1toN(v): for u in to[v]: if toflag[u] == 0: toflag[u] = 1 DFS_1toN(u) def DFS_Nto1(v): for u in ot[v]: if otflag[u] == 0: otflag[u] = 1 DFS_Nto1(u) n, m, p = list(map(int, input().split())) g = [] to = [[] for _ in range(n + 1)] ot = [[] for _ in range(n + 1)] for _ in range(m): a, b, c = list(map(int, input().split())) g.append([a, b, -(c - p)]) to[a].append(b) ot[b].append(a) toflag = [0] * (n + 1) toflag[1] = 1 DFS_1toN(1) otflag = [0] * (n + 1) otflag[n] = 1 DFS_Nto1(n) cand = [0] * (n + 1) for i in range(1, n + 1): cand[i] = toflag[i] * otflag[i] ans = BF(g, n, 1) if ans == float("inf"): print((-1)) else: print((max(ans, 0)))
false
54.237288
[ "+import sys", "+", "+sys.setrecursionlimit(10**9)", "+", "+", "- flag = False", "- for i in range(n + 1):", "+ update = True", "+ cnt = 0", "+ while 1:", "+ update = False", "+ if cand[v] != 1 or cand[u] != 1:", "+ continue", "- ans1 = d[-1]", "- for i in range(n + 1):", "- for v, u, cost in edges:", "- if d[v] != inf and d[u] > d[v] + cost:", "- d[u] = d[v] + cost", "- ans2 = d[-1]", "- if ans2 < ans1:", "- return -1", "- else:", "- return max(-ans1, 0)", "+ update = True", "+ if update == False:", "+ break", "+ cnt += 1", "+ if cnt > n:", "+ return inf", "+ return -d[-1]", "+", "+", "+def DFS_1toN(v):", "+ for u in to[v]:", "+ if toflag[u] == 0:", "+ toflag[u] = 1", "+ DFS_1toN(u)", "+", "+", "+def DFS_Nto1(v):", "+ for u in ot[v]:", "+ if otflag[u] == 0:", "+ otflag[u] = 1", "+ DFS_Nto1(u)", "+to = [[] for _ in range(n + 1)]", "+ot = [[] for _ in range(n + 1)]", "+ to[a].append(b)", "+ ot[b].append(a)", "+toflag = [0] * (n + 1)", "+toflag[1] = 1", "+DFS_1toN(1)", "+otflag = [0] * (n + 1)", "+otflag[n] = 1", "+DFS_Nto1(n)", "+cand = [0] * (n + 1)", "+for i in range(1, n + 1):", "+ cand[i] = toflag[i] * otflag[i]", "-print(ans)", "+if ans == float(\"inf\"):", "+ print((-1))", "+else:", "+ print((max(ans, 0)))" ]
false
0.043433
0.035924
1.209035
[ "s721634035", "s390285762" ]
u119148115
p02804
python
s147519623
s144767484
304
152
64,168
91,388
Accepted
Accepted
50
N,K = list(map(int,input().split())) A = list(map(int,input().split())) A = sorted(A) mod = 10**9+7 def p(m,n): a = 1 for i in range(n): a = a*(m-i) return a def p_mod(m,n,mod): a = 1 for i in range(n): a = a*(m-i) % mod return a def c(m,n): return p(m,n) // p(n,n) def c_mod(m,n,mod): return (p_mod(m,n,mod)*pow(p_mod(n,n,mod),mod-2,mod)) % mod C = [0]*(N-K+1) #C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく for i in range(N-K+1): if i == 0: C[i] = c_mod(N-1,K-1,mod) else: C[i] = (C[i-1]*(N-K-i+1)*pow(N-i,mod-2,mod)) % mod #各Aの元が何回max,minに採用されるかを考える ans = 0 for i in range(N-K+1): ans -= (A[i]*C[i]) % mod A.reverse() for i in range(N-K+1): ans += (A[i]*C[i]) % mod print((ans % mod))
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = [-10**10] + LI() A.sort() mod = 10**9+7 B = [0]*(K-1) + [1] # B[i] = i_C_(K-1) for i in range(K,N): B.append((B[-1]*i*pow(i-(K-1),mod-2,mod)) % mod) ans = 0 for i in range(1,N+1): ans += (B[i-1]-B[N-i])*A[i] ans %= mod print(ans)
43
19
803
432
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A) mod = 10**9 + 7 def p(m, n): a = 1 for i in range(n): a = a * (m - i) return a def p_mod(m, n, mod): a = 1 for i in range(n): a = a * (m - i) % mod return a def c(m, n): return p(m, n) // p(n, n) def c_mod(m, n, mod): return (p_mod(m, n, mod) * pow(p_mod(n, n, mod), mod - 2, mod)) % mod C = [0] * (N - K + 1) # C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく for i in range(N - K + 1): if i == 0: C[i] = c_mod(N - 1, K - 1, mod) else: C[i] = (C[i - 1] * (N - K - i + 1) * pow(N - i, mod - 2, mod)) % mod # 各Aの元が何回max,minに採用されるかを考える ans = 0 for i in range(N - K + 1): ans -= (A[i] * C[i]) % mod A.reverse() for i in range(N - K + 1): ans += (A[i] * C[i]) % mod print((ans % mod))
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = [-(10**10)] + LI() A.sort() mod = 10**9 + 7 B = [0] * (K - 1) + [1] # B[i] = i_C_(K-1) for i in range(K, N): B.append((B[-1] * i * pow(i - (K - 1), mod - 2, mod)) % mod) ans = 0 for i in range(1, N + 1): ans += (B[i - 1] - B[N - i]) * A[i] ans %= mod print(ans)
false
55.813953
[ "-N, K = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-A = sorted(A)", "-mod = 10**9 + 7", "+import sys", "-def p(m, n):", "- a = 1", "- for i in range(n):", "- a = a * (m - i)", "- return a", "+def MI():", "+ return list(map(int, sys.stdin.readline().rstrip().split()))", "-def p_mod(m, n, mod):", "- a = 1", "- for i in range(n):", "- a = a * (m - i) % mod", "- return a", "+def LI():", "+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "-def c(m, n):", "- return p(m, n) // p(n, n)", "-", "-", "-def c_mod(m, n, mod):", "- return (p_mod(m, n, mod) * pow(p_mod(n, n, mod), mod - 2, mod)) % mod", "-", "-", "-C = [0] * (N - K + 1) # C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく", "-for i in range(N - K + 1):", "- if i == 0:", "- C[i] = c_mod(N - 1, K - 1, mod)", "- else:", "- C[i] = (C[i - 1] * (N - K - i + 1) * pow(N - i, mod - 2, mod)) % mod", "-# 各Aの元が何回max,minに採用されるかを考える", "+N, K = MI()", "+A = [-(10**10)] + LI()", "+A.sort()", "+mod = 10**9 + 7", "+B = [0] * (K - 1) + [1] # B[i] = i_C_(K-1)", "+for i in range(K, N):", "+ B.append((B[-1] * i * pow(i - (K - 1), mod - 2, mod)) % mod)", "-for i in range(N - K + 1):", "- ans -= (A[i] * C[i]) % mod", "-A.reverse()", "-for i in range(N - K + 1):", "- ans += (A[i] * C[i]) % mod", "-print((ans % mod))", "+for i in range(1, N + 1):", "+ ans += (B[i - 1] - B[N - i]) * A[i]", "+ ans %= mod", "+print(ans)" ]
false
0.177546
0.04161
4.266879
[ "s147519623", "s144767484" ]
u670180528
p03006
python
s576156366
s785940767
196
105
3,316
3,188
Accepted
Accepted
46.43
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(n): if i==j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = 1e9 if n>1 else 1 for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in xy: pass else: cost += 1 ans = min(ans, cost) print(ans)
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(i+1,n): if i==j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = n for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in xy: pass else: cost += 1 ans = min(ans, cost) print(ans)
20
20
386
373
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(n): if i == j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = 1e9 if n > 1 else 1 for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in xy: pass else: cost += 1 ans = min(ans, cost) print(ans)
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for i in range(n): for j in range(i + 1, n): if i == j: continue xi, yi = xy[i] xj, yj = xy[j] pq.append((xi - xj, yi - yj)) ans = n for p, q in pq: cost = 0 for x, y in xy: if (x + p, y + q) in xy: pass else: cost += 1 ans = min(ans, cost) print(ans)
false
0
[ "- for j in range(n):", "+ for j in range(i + 1, n):", "-ans = 1e9 if n > 1 else 1", "+ans = n" ]
false
0.063639
0.064515
0.986421
[ "s576156366", "s785940767" ]
u037430802
p02973
python
s346260183
s297405371
550
241
56,536
8,604
Accepted
Accepted
56.18
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] colors = [] #後ろから見ていく for i,n in enumerate(list(reversed(A))): # 一つ目はとりあえずなんか一色ぬる if i == 0: colors.append(n) else: #二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える #ここをbisect_leftにすると、colorsの中で同じ最小値があるときにinsertが必要なので遅い # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加 idx = bisect.bisect_right(colors, n) if idx == len(colors): colors.append(n) else: colors[idx] = n print((len(colors)))
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] colors = [] #後ろから見ていく for i,n in enumerate(list(reversed(A))): # 一つ目はとりあえずなんか一色ぬる if i == 0: colors.append(n) else: #二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加 idx = bisect.bisect_right(colors, n) #if idx == len(colors): if colors[-1] <= n: colors.append(n) else: colors[idx] = n print((len(colors)))
24
24
572
538
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] colors = [] # 後ろから見ていく for i, n in enumerate(list(reversed(A))): # 一つ目はとりあえずなんか一色ぬる if i == 0: colors.append(n) else: # 二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える # ここをbisect_leftにすると、colorsの中で同じ最小値があるときにinsertが必要なので遅い # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加 idx = bisect.bisect_right(colors, n) if idx == len(colors): colors.append(n) else: colors[idx] = n print((len(colors)))
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] colors = [] # 後ろから見ていく for i, n in enumerate(list(reversed(A))): # 一つ目はとりあえずなんか一色ぬる if i == 0: colors.append(n) else: # 二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加 idx = bisect.bisect_right(colors, n) # if idx == len(colors): if colors[-1] <= n: colors.append(n) else: colors[idx] = n print((len(colors)))
false
0
[ "- # ここをbisect_leftにすると、colorsの中で同じ最小値があるときにinsertが必要なので遅い", "- if idx == len(colors):", "+ # if idx == len(colors):", "+ if colors[-1] <= n:" ]
false
0.06782
0.037364
1.815125
[ "s346260183", "s297405371" ]
u654470292
p03161
python
s929571442
s432902085
490
207
55,392
81,012
Accepted
Accepted
57.76
import sys def input(): return sys.stdin.readline()[:-1] n,k=list(map(int,input().split())) h=list(map(int,input().split())) cost=[float("inf")]*n cost[0]=0 for i in range(n-1): now=h[i] for j in range(k): if i+j+1>=n: break cost[i+j+1]=min(abs(now-h[i+j+1])+cost[i],cost[i+j+1]) # print(cost) print((cost[-1]))
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) sys.setrecursionlimit(500000) mod=10007 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n,k=list(map(int,input().split())) h=list(map(int,input().split())) dp=[float('inf')]*n dp[0]=0 for i in range(n): for j in range(k): # nex=i+j+1 if i+j+1<n: dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(h[i]-h[i+j+1])) # print(dp) print((dp[-1]))
17
29
369
708
import sys def input(): return sys.stdin.readline()[:-1] n, k = list(map(int, input().split())) h = list(map(int, input().split())) cost = [float("inf")] * n cost[0] = 0 for i in range(n - 1): now = h[i] for j in range(k): if i + j + 1 >= n: break cost[i + j + 1] = min(abs(now - h[i + j + 1]) + cost[i], cost[i + j + 1]) # print(cost) print((cost[-1]))
import bisect import copy import heapq import math import sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) sys.setrecursionlimit(500000) mod = 10007 al = [chr(ord("a") + i) for i in range(26)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] n, k = list(map(int, input().split())) h = list(map(int, input().split())) dp = [float("inf")] * n dp[0] = 0 for i in range(n): for j in range(k): # nex=i+j+1 if i + j + 1 < n: dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1])) # print(dp) print((dp[-1]))
false
41.37931
[ "+import bisect", "+import copy", "+import heapq", "+import math", "+from collections import *", "+from functools import lru_cache", "+from itertools import accumulate, combinations, permutations, product", "+def ruiseki(lst):", "+ return [0] + list(accumulate(lst))", "+", "+", "+sys.setrecursionlimit(500000)", "+mod = 10007", "+al = [chr(ord(\"a\") + i) for i in range(26)]", "+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-cost = [float(\"inf\")] * n", "-cost[0] = 0", "-for i in range(n - 1):", "- now = h[i]", "+dp = [float(\"inf\")] * n", "+dp[0] = 0", "+for i in range(n):", "- if i + j + 1 >= n:", "- break", "- cost[i + j + 1] = min(abs(now - h[i + j + 1]) + cost[i], cost[i + j + 1])", "- # print(cost)", "-print((cost[-1]))", "+ # nex=i+j+1", "+ if i + j + 1 < n:", "+ dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1]))", "+ # print(dp)", "+print((dp[-1]))" ]
false
0.093774
0.040758
2.30074
[ "s929571442", "s432902085" ]
u392319141
p03346
python
s246215614
s594127705
218
167
35,312
21,224
Accepted
Accepted
23.39
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10**9 + 7 INF = float('inf') def sol(): N = int(eval(input())) P = [0] * N for i in range(N): P[i] = int(eval(input())) pToIndex = {p : i for i, p in enumerate(P)} maxLeng = 1 length = 1 for n in range(1, N): if pToIndex[n] < pToIndex[n + 1]: length += 1 maxLeng = max(maxLeng, length) else: length = 1 print((N - maxLeng)) sol()
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10**9 + 7 INF = float('inf') def sol(): N = int(eval(input())) P = [0] * N index = [0] * (N + 1) for i in range(N): P[i] = int(eval(input())) index[P[i]] = i length = 1 seq = 1 for i in range(1, N): if index[i] < index[i + 1]: seq += 1 else: length = max(length, seq) seq = 1 length = max(length, seq) print((N - length)) sol()
31
33
660
685
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") def sol(): N = int(eval(input())) P = [0] * N for i in range(N): P[i] = int(eval(input())) pToIndex = {p: i for i, p in enumerate(P)} maxLeng = 1 length = 1 for n in range(1, N): if pToIndex[n] < pToIndex[n + 1]: length += 1 maxLeng = max(maxLeng, length) else: length = 1 print((N - maxLeng)) sol()
import sys import heapq from operator import itemgetter from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") def sol(): N = int(eval(input())) P = [0] * N index = [0] * (N + 1) for i in range(N): P[i] = int(eval(input())) index[P[i]] = i length = 1 seq = 1 for i in range(1, N): if index[i] < index[i + 1]: seq += 1 else: length = max(length, seq) seq = 1 length = max(length, seq) print((N - length)) sol()
false
6.060606
[ "+ index = [0] * (N + 1)", "- pToIndex = {p: i for i, p in enumerate(P)}", "- maxLeng = 1", "+ index[P[i]] = i", "- for n in range(1, N):", "- if pToIndex[n] < pToIndex[n + 1]:", "- length += 1", "- maxLeng = max(maxLeng, length)", "+ seq = 1", "+ for i in range(1, N):", "+ if index[i] < index[i + 1]:", "+ seq += 1", "- length = 1", "- print((N - maxLeng))", "+ length = max(length, seq)", "+ seq = 1", "+ length = max(length, seq)", "+ print((N - length))" ]
false
0.037314
0.079939
0.466778
[ "s246215614", "s594127705" ]
u787562674
p03487
python
s730273464
s598730290
99
85
18,168
18,676
Accepted
Accepted
14.14
N = int(eval(input())) S = list(int(i) for i in input().split()) dict = {} count = 0 for i in range(N): if S[i] not in dict: dict[S[i]] = 1 else: dict[S[i]] += 1 for key, value in list(dict.items()): if key < value: count += (value-key) elif key > value: count += value print(count)
from collections import Counter as C N = int(eval(input())) S = list(int(i) for i in input().split()) count = 0 for key, value in list(C(S).items()): if key < value: count += (value-key) elif key > value: count += value print(count)
18
13
340
259
N = int(eval(input())) S = list(int(i) for i in input().split()) dict = {} count = 0 for i in range(N): if S[i] not in dict: dict[S[i]] = 1 else: dict[S[i]] += 1 for key, value in list(dict.items()): if key < value: count += value - key elif key > value: count += value print(count)
from collections import Counter as C N = int(eval(input())) S = list(int(i) for i in input().split()) count = 0 for key, value in list(C(S).items()): if key < value: count += value - key elif key > value: count += value print(count)
false
27.777778
[ "+from collections import Counter as C", "+", "-dict = {}", "-for i in range(N):", "- if S[i] not in dict:", "- dict[S[i]] = 1", "- else:", "- dict[S[i]] += 1", "-for key, value in list(dict.items()):", "+for key, value in list(C(S).items()):" ]
false
0.043243
0.040464
1.068687
[ "s730273464", "s598730290" ]
u279266699
p02820
python
s586933116
s319702781
158
47
4,340
9,868
Accepted
Accepted
70.25
from collections import Counter, deque n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) con = Counter(t) ans = con['r'] * p + con['s'] * r + con['p'] * s dic = {'r': p, 's': r, 'p': s} for i in range(k): target = list(t[i::k]) hp = 0 count = 1 for j in range(len(target)): hn = target[j] if hn == hp: count += 1 elif count > 1: ans -= count // 2 * dic[hp] count = 1 hp = hn else: ans -= count // 2 * dic[hp] print(ans)
def main(): n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) hand = ['r', 's', 'p'] score = [p, r, s] dic_score = dict(list(zip(hand, score))) win = [0] * n ans = 0 for i in range(k): ans += dic_score[t[i]] win[i] = 1 for i in range(k, n): if t[i] == t[i - k] and win[i - k]: continue ans += dic_score[t[i]] win[i] = 1 print(ans) if __name__ == '__main__': main()
23
22
570
513
from collections import Counter, deque n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) con = Counter(t) ans = con["r"] * p + con["s"] * r + con["p"] * s dic = {"r": p, "s": r, "p": s} for i in range(k): target = list(t[i::k]) hp = 0 count = 1 for j in range(len(target)): hn = target[j] if hn == hp: count += 1 elif count > 1: ans -= count // 2 * dic[hp] count = 1 hp = hn else: ans -= count // 2 * dic[hp] print(ans)
def main(): n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = eval(input()) hand = ["r", "s", "p"] score = [p, r, s] dic_score = dict(list(zip(hand, score))) win = [0] * n ans = 0 for i in range(k): ans += dic_score[t[i]] win[i] = 1 for i in range(k, n): if t[i] == t[i - k] and win[i - k]: continue ans += dic_score[t[i]] win[i] = 1 print(ans) if __name__ == "__main__": main()
false
4.347826
[ "-from collections import Counter, deque", "+def main():", "+ n, k = list(map(int, input().split()))", "+ r, s, p = list(map(int, input().split()))", "+ t = eval(input())", "+ hand = [\"r\", \"s\", \"p\"]", "+ score = [p, r, s]", "+ dic_score = dict(list(zip(hand, score)))", "+ win = [0] * n", "+ ans = 0", "+ for i in range(k):", "+ ans += dic_score[t[i]]", "+ win[i] = 1", "+ for i in range(k, n):", "+ if t[i] == t[i - k] and win[i - k]:", "+ continue", "+ ans += dic_score[t[i]]", "+ win[i] = 1", "+ print(ans)", "-n, k = list(map(int, input().split()))", "-r, s, p = list(map(int, input().split()))", "-t = eval(input())", "-con = Counter(t)", "-ans = con[\"r\"] * p + con[\"s\"] * r + con[\"p\"] * s", "-dic = {\"r\": p, \"s\": r, \"p\": s}", "-for i in range(k):", "- target = list(t[i::k])", "- hp = 0", "- count = 1", "- for j in range(len(target)):", "- hn = target[j]", "- if hn == hp:", "- count += 1", "- elif count > 1:", "- ans -= count // 2 * dic[hp]", "- count = 1", "- hp = hn", "- else:", "- ans -= count // 2 * dic[hp]", "-print(ans)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.063524
0.064628
0.98292
[ "s586933116", "s319702781" ]
u145950990
p03672
python
s380657572
s053749083
174
17
38,384
2,940
Accepted
Accepted
90.23
s = input()[:-1] for i in range(len(s)): x = s[:i] n = len(s[:i]) if n%2==0 and x[:i//2]==x[i//2:]: ans = n print(ans)
s = input()[:-1] while s[:len(s)//2]*2 != s: s = s[:-1] print((len(s)))
7
6
144
80
s = input()[:-1] for i in range(len(s)): x = s[:i] n = len(s[:i]) if n % 2 == 0 and x[: i // 2] == x[i // 2 :]: ans = n print(ans)
s = input()[:-1] while s[: len(s) // 2] * 2 != s: s = s[:-1] print((len(s)))
false
14.285714
[ "-for i in range(len(s)):", "- x = s[:i]", "- n = len(s[:i])", "- if n % 2 == 0 and x[: i // 2] == x[i // 2 :]:", "- ans = n", "-print(ans)", "+while s[: len(s) // 2] * 2 != s:", "+ s = s[:-1]", "+print((len(s)))" ]
false
0.042732
0.040749
1.048657
[ "s380657572", "s053749083" ]
u352394527
p00481
python
s979908485
s680559711
3,890
3,370
18,152
22,960
Accepted
Accepted
13.37
from collections import deque h,w,n = list(map(int,input().split())) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] append = ss.append for i in range(h): s = "X" + eval(input()) + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(len(s)): if s[j] != 'S' and s[j] != '.' and s[j] != 'X': factrys[int(s[j])] = (i + 1, j) append(s) append("X" * (w + 2)) def bfs(i): mp = [[-1] * (w + 2) for j in range(h + 2)] x,y = factrys[i] que = deque() append = que.append popleft = que.popleft append((x, y)) for count in range(10000000): sz = len(que) for loop in range(sz): (x,y) = popleft() if ss[x][y] == 'X' or not mp[x][y] is -1: continue if (x,y) == factrys[i + 1]: return count mp[x][y] = count append((x + 1, y)) append((x - 1, y)) append((x, y + 1)) append((x, y - 1)) ans = 0 for i in range(n): ret = bfs(i) if ret is None: ans += 0 else: ans += (ret) print(ans)
from collections import deque def main(): h, w, n = list(map(int, input().split())) mp = ["X" + eval(input()) + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, y) elif "1" <= mp[y][x] <= "9": poss[int(mp[y][x])] = (x, y) ans = 0 vec = ((1, 0), (0, -1), (-1, 0), (0, 1)) for i in range(n): sx, sy = poss[i] gx, gy = poss[i + 1] used = [[False] * (w + 2) for _ in range(h + 2)] used[sy][sx] = True que = deque() push = que.append pop = que.popleft push((0, sx, sy)) while que: cnt, x, y = pop() if (x, y) == (gx, gy): ans += cnt break for dx, dy in vec: nx, ny = x + dx, y + dy if used[ny][nx] or mp[ny][nx] == "X":continue used[ny][nx] = True push((cnt + 1, nx, ny)) print(ans) main()
44
42
1,033
1,023
from collections import deque h, w, n = list(map(int, input().split())) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] append = ss.append for i in range(h): s = "X" + eval(input()) + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(len(s)): if s[j] != "S" and s[j] != "." and s[j] != "X": factrys[int(s[j])] = (i + 1, j) append(s) append("X" * (w + 2)) def bfs(i): mp = [[-1] * (w + 2) for j in range(h + 2)] x, y = factrys[i] que = deque() append = que.append popleft = que.popleft append((x, y)) for count in range(10000000): sz = len(que) for loop in range(sz): (x, y) = popleft() if ss[x][y] == "X" or not mp[x][y] is -1: continue if (x, y) == factrys[i + 1]: return count mp[x][y] = count append((x + 1, y)) append((x - 1, y)) append((x, y + 1)) append((x, y - 1)) ans = 0 for i in range(n): ret = bfs(i) if ret is None: ans += 0 else: ans += ret print(ans)
from collections import deque def main(): h, w, n = list(map(int, input().split())) mp = ["X" + eval(input()) + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, y) elif "1" <= mp[y][x] <= "9": poss[int(mp[y][x])] = (x, y) ans = 0 vec = ((1, 0), (0, -1), (-1, 0), (0, 1)) for i in range(n): sx, sy = poss[i] gx, gy = poss[i + 1] used = [[False] * (w + 2) for _ in range(h + 2)] used[sy][sx] = True que = deque() push = que.append pop = que.popleft push((0, sx, sy)) while que: cnt, x, y = pop() if (x, y) == (gx, gy): ans += cnt break for dx, dy in vec: nx, ny = x + dx, y + dy if used[ny][nx] or mp[ny][nx] == "X": continue used[ny][nx] = True push((cnt + 1, nx, ny)) print(ans) main()
false
4.545455
[ "-h, w, n = list(map(int, input().split()))", "-factrys = [None] * (n + 1)", "-ss = [\"X\" * (w + 2)]", "-append = ss.append", "-for i in range(h):", "- s = \"X\" + eval(input()) + \"X\"", "- if \"S\" in s:", "- factrys[0] = (i + 1, s.index(\"S\"))", "- for j in range(len(s)):", "- if s[j] != \"S\" and s[j] != \".\" and s[j] != \"X\":", "- factrys[int(s[j])] = (i + 1, j)", "- append(s)", "-append(\"X\" * (w + 2))", "+", "+def main():", "+ h, w, n = list(map(int, input().split()))", "+ mp = [\"X\" + eval(input()) + \"X\" for _ in range(h)]", "+ mp.insert(0, \"X\" * (w + 2))", "+ mp.append(\"X\" * (w + 2))", "+ poss = [None] * (n + 1)", "+ for y in range(1, h + 1):", "+ for x in range(1, w + 1):", "+ if mp[y][x] == \"S\":", "+ poss[0] = (x, y)", "+ elif \"1\" <= mp[y][x] <= \"9\":", "+ poss[int(mp[y][x])] = (x, y)", "+ ans = 0", "+ vec = ((1, 0), (0, -1), (-1, 0), (0, 1))", "+ for i in range(n):", "+ sx, sy = poss[i]", "+ gx, gy = poss[i + 1]", "+ used = [[False] * (w + 2) for _ in range(h + 2)]", "+ used[sy][sx] = True", "+ que = deque()", "+ push = que.append", "+ pop = que.popleft", "+ push((0, sx, sy))", "+ while que:", "+ cnt, x, y = pop()", "+ if (x, y) == (gx, gy):", "+ ans += cnt", "+ break", "+ for dx, dy in vec:", "+ nx, ny = x + dx, y + dy", "+ if used[ny][nx] or mp[ny][nx] == \"X\":", "+ continue", "+ used[ny][nx] = True", "+ push((cnt + 1, nx, ny))", "+ print(ans)", "-def bfs(i):", "- mp = [[-1] * (w + 2) for j in range(h + 2)]", "- x, y = factrys[i]", "- que = deque()", "- append = que.append", "- popleft = que.popleft", "- append((x, y))", "- for count in range(10000000):", "- sz = len(que)", "- for loop in range(sz):", "- (x, y) = popleft()", "- if ss[x][y] == \"X\" or not mp[x][y] is -1:", "- continue", "- if (x, y) == factrys[i + 1]:", "- return count", "- mp[x][y] = count", "- append((x + 1, y))", "- append((x - 1, y))", "- append((x, y + 1))", "- append((x, y - 1))", "-", "-", "-ans = 0", "-for i in range(n):", "- ret = bfs(i)", "- if ret is None:", "- ans += 0", "- else:", "- ans += ret", "-print(ans)", "+main()" ]
false
0.125589
0.042217
2.974863
[ "s979908485", "s680559711" ]
u179169725
p02959
python
s992255106
s194175804
281
196
82,020
18,476
Accepted
Accepted
30.25
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 l = A[0] for i in range(N): r = A[i + 1] cur = B[i] # print(l, r, cur) ans += min(l + r, cur) l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる print(ans)
# https://atcoder.jp/contests/abc135/tasks/abc135_c N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 l = A[0] for i in range(N): r = A[i + 1] cur = B[i] # print(l, r, cur) # ans += min(l + r, cur) # l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる # わかりやすくかきなおす ans += min(l, cur) rest_power = max(cur - l, 0) ans += min(rest_power, r) l = max(r - rest_power, 0) # next l print(ans)
12
21
287
501
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 l = A[0] for i in range(N): r = A[i + 1] cur = B[i] # print(l, r, cur) ans += min(l + r, cur) l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる print(ans)
# https://atcoder.jp/contests/abc135/tasks/abc135_c N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 l = A[0] for i in range(N): r = A[i + 1] cur = B[i] # print(l, r, cur) # ans += min(l + r, cur) # l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる # わかりやすくかきなおす ans += min(l, cur) rest_power = max(cur - l, 0) ans += min(rest_power, r) l = max(r - rest_power, 0) # next l print(ans)
false
42.857143
[ "+# https://atcoder.jp/contests/abc135/tasks/abc135_c", "- ans += min(l + r, cur)", "- l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる", "+ # ans += min(l + r, cur)", "+ # l = max(r - max(cur - l, 0), 0) # めちゃくちゃ整理するとこの形の式になる", "+ # わかりやすくかきなおす", "+ ans += min(l, cur)", "+ rest_power = max(cur - l, 0)", "+ ans += min(rest_power, r)", "+ l = max(r - rest_power, 0) # next l" ]
false
0.036832
0.082936
0.444101
[ "s992255106", "s194175804" ]
u773265208
p02785
python
s251150981
s182036770
173
154
26,180
26,764
Accepted
Accepted
10.98
n,k = list(map(int,input().split())) h = list(map(int,input().split())) if n <= k: print((0)) else: h.sort() ans = 0 for i in range(n-k): ans += h[i] print(ans)
import sys n,k = list(map(int,input().split())) h = list(map(int,input().split())) h.sort() if k >= n: print((0)) sys.exit() h = h[:n-k] print((sum(h)))
11
15
178
167
n, k = list(map(int, input().split())) h = list(map(int, input().split())) if n <= k: print((0)) else: h.sort() ans = 0 for i in range(n - k): ans += h[i] print(ans)
import sys n, k = list(map(int, input().split())) h = list(map(int, input().split())) h.sort() if k >= n: print((0)) sys.exit() h = h[: n - k] print((sum(h)))
false
26.666667
[ "+import sys", "+", "-if n <= k:", "+h.sort()", "+if k >= n:", "-else:", "- h.sort()", "- ans = 0", "- for i in range(n - k):", "- ans += h[i]", "- print(ans)", "+ sys.exit()", "+h = h[: n - k]", "+print((sum(h)))" ]
false
0.039506
0.046025
0.858355
[ "s251150981", "s182036770" ]
u893307213
p03329
python
s108577452
s231367987
610
212
15,072
27,744
Accepted
Accepted
65.25
N = int(eval(input())) dp = dict() dp[0] = 0 # 貰う DP --- dp[n] に遷移を集める for n in range(1, N+1): dp[n] = dp[n-1] + 1 # メモ化 x = 6 while x <= n: dp[n] = min(dp[n], dp[n-x]+1) x *= 6 x = 9 while x <= n: dp[n] = min(dp[n], dp[n-x]+1) x *= 9 # dp[n] = ans print((dp[N]))
n = int(eval(input())) max_N = 1000000 memo = [False]*max_N import sys import threading sys.setrecursionlimit(100000) threading.stack_size(128*1024*1024) # 貰う DPではなく、再帰を使ったメモ化再帰 from functools import lru_cache lru_cache(maxsize=100000) def f(n): if n < 6: return n if memo[n]: # print(f"at n: {n}, memo[n]:", memo[n]) return memo[n] ans = n # メモ化 x = 6 while x <= n: ans = min(ans, f(n-x)+1) x *= 6 x = 9 while x <= n: ans = min(ans, f(n-x)+1) x *= 9 memo[n] = ans return ans def main(): print((f(n))) threading.Thread(target=main).start()
22
40
321
608
N = int(eval(input())) dp = dict() dp[0] = 0 # 貰う DP --- dp[n] に遷移を集める for n in range(1, N + 1): dp[n] = dp[n - 1] + 1 # メモ化 x = 6 while x <= n: dp[n] = min(dp[n], dp[n - x] + 1) x *= 6 x = 9 while x <= n: dp[n] = min(dp[n], dp[n - x] + 1) x *= 9 # dp[n] = ans print((dp[N]))
n = int(eval(input())) max_N = 1000000 memo = [False] * max_N import sys import threading sys.setrecursionlimit(100000) threading.stack_size(128 * 1024 * 1024) # 貰う DPではなく、再帰を使ったメモ化再帰 from functools import lru_cache lru_cache(maxsize=100000) def f(n): if n < 6: return n if memo[n]: # print(f"at n: {n}, memo[n]:", memo[n]) return memo[n] ans = n # メモ化 x = 6 while x <= n: ans = min(ans, f(n - x) + 1) x *= 6 x = 9 while x <= n: ans = min(ans, f(n - x) + 1) x *= 9 memo[n] = ans return ans def main(): print((f(n))) threading.Thread(target=main).start()
false
45
[ "-N = int(eval(input()))", "-dp = dict()", "-dp[0] = 0", "-for n in range(1, N + 1):", "- dp[n] = dp[n - 1] + 1", "+n = int(eval(input()))", "+max_N = 1000000", "+memo = [False] * max_N", "+import sys", "+import threading", "+", "+sys.setrecursionlimit(100000)", "+threading.stack_size(128 * 1024 * 1024)", "+# 貰う DPではなく、再帰を使ったメモ化再帰", "+from functools import lru_cache", "+", "+lru_cache(maxsize=100000)", "+", "+", "+def f(n):", "+ if n < 6:", "+ return n", "+ if memo[n]:", "+ # print(f\"at n: {n}, memo[n]:\", memo[n])", "+ return memo[n]", "+ ans = n", "- dp[n] = min(dp[n], dp[n - x] + 1)", "+ ans = min(ans, f(n - x) + 1)", "- dp[n] = min(dp[n], dp[n - x] + 1)", "+ ans = min(ans, f(n - x) + 1)", "- # dp[n] = ans", "-print((dp[N]))", "+ memo[n] = ans", "+ return ans", "+", "+", "+def main():", "+ print((f(n)))", "+", "+", "+threading.Thread(target=main).start()" ]
false
0.094177
0.169012
0.557222
[ "s108577452", "s231367987" ]
u102461423
p03037
python
s295583664
s464903585
317
188
3,060
23,212
Accepted
Accepted
40.69
N,M = list(map(int,input().split())) l = -1 r = N+1 for _ in range(M): L,R = list(map(int,input().split())) l = max(l,L) r = min(r,R) answer = max(0,r - l + 1) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N,M = list(map(int,readline().split())) LR = np.array(read().split(),np.int32) L = LR[::2]; R = LR[1::2] x = R.min() - L.max() + 1 if x < 0: x = 0 print(x)
11
15
179
302
N, M = list(map(int, input().split())) l = -1 r = N + 1 for _ in range(M): L, R = list(map(int, input().split())) l = max(l, L) r = min(r, R) answer = max(0, r - l + 1) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, M = list(map(int, readline().split())) LR = np.array(read().split(), np.int32) L = LR[::2] R = LR[1::2] x = R.min() - L.max() + 1 if x < 0: x = 0 print(x)
false
26.666667
[ "-N, M = list(map(int, input().split()))", "-l = -1", "-r = N + 1", "-for _ in range(M):", "- L, R = list(map(int, input().split()))", "- l = max(l, L)", "- r = min(r, R)", "-answer = max(0, r - l + 1)", "-print(answer)", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+import numpy as np", "+", "+N, M = list(map(int, readline().split()))", "+LR = np.array(read().split(), np.int32)", "+L = LR[::2]", "+R = LR[1::2]", "+x = R.min() - L.max() + 1", "+if x < 0:", "+ x = 0", "+print(x)" ]
false
0.036673
0.225436
0.162676
[ "s295583664", "s464903585" ]
u535803878
p03822
python
s193564335
s408734462
368
239
156,072
115,712
Accepted
Accepted
35.05
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(eval(input())) a = [None]*(n-1) from collections import defaultdict c = defaultdict(list) for i in range(n-1): num = int(eval(input())) c[num].append(i+2) def sub(winner): l = len(c[winner]) vs = [] for p in c[winner]: vs.append(sub(p)) vs.sort() ans = max([l] + [(l-i+v) for i,v in enumerate(vs)]) return ans ans = sub(1) print(ans)
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(eval(input())) a = [None]*(n-1) from collections import defaultdict c = defaultdict(list) for i in range(n-1): num = int(eval(input())) c[num].append(i+2) ### 行きがけ順DFS def dfs(start): q = [start] # now, prev us = [] seen = set([start]) while q: u = q.pop() us.append(u) for v in c[u]: if v in seen: continue q.append(v) seen.add(v) return us us = dfs(1) val = {} for winner in us[::-1]: l = len(c[winner]) vs = [] for p in c[winner]: vs.append(val[p]) vs.sort() ans = max([l] + [(l-i+v) for i,v in enumerate(vs)]) val[winner] = ans ans = val[1] print(ans)
24
40
536
870
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") n = int(eval(input())) a = [None] * (n - 1) from collections import defaultdict c = defaultdict(list) for i in range(n - 1): num = int(eval(input())) c[num].append(i + 2) def sub(winner): l = len(c[winner]) vs = [] for p in c[winner]: vs.append(sub(p)) vs.sort() ans = max([l] + [(l - i + v) for i, v in enumerate(vs)]) return ans ans = sub(1) print(ans)
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") n = int(eval(input())) a = [None] * (n - 1) from collections import defaultdict c = defaultdict(list) for i in range(n - 1): num = int(eval(input())) c[num].append(i + 2) ### 行きがけ順DFS def dfs(start): q = [start] # now, prev us = [] seen = set([start]) while q: u = q.pop() us.append(u) for v in c[u]: if v in seen: continue q.append(v) seen.add(v) return us us = dfs(1) val = {} for winner in us[::-1]: l = len(c[winner]) vs = [] for p in c[winner]: vs.append(val[p]) vs.sort() ans = max([l] + [(l - i + v) for i, v in enumerate(vs)]) val[winner] = ans ans = val[1] print(ans)
false
40
[ "+### 行きがけ順DFS", "+def dfs(start):", "+ q = [start] # now, prev", "+ us = []", "+ seen = set([start])", "+ while q:", "+ u = q.pop()", "+ us.append(u)", "+ for v in c[u]:", "+ if v in seen:", "+ continue", "+ q.append(v)", "+ seen.add(v)", "+ return us", "-def sub(winner):", "+us = dfs(1)", "+val = {}", "+for winner in us[::-1]:", "- vs.append(sub(p))", "+ vs.append(val[p])", "- return ans", "-", "-", "-ans = sub(1)", "+ val[winner] = ans", "+ans = val[1]" ]
false
0.043483
0.072603
0.598913
[ "s193564335", "s408734462" ]
u761320129
p03216
python
s100975117
s281816639
2,491
1,498
54,364
74,840
Accepted
Accepted
39.86
import sys rl = sys.stdin.readline N = int(rl()) S = rl() Q = int(rl()) ks = list(map(int,rl().split())) ans = [] for k in ks: d = m = 0 dm = dmc = 0 for i in range(N): if i >= k: if S[i-k] == 'D': d -= 1 dm -= m elif S[i-k] == 'M': m -= 1 if S[i] == 'D': d += 1 elif S[i] == 'M': m += 1 dm += d elif S[i] == 'C': dmc += dm ans.append(dmc) print(*ans,sep='\n')
import sys input = sys.stdin.readline N = int(input()) S = input() Q = int(input()) K = list(map(int,input().split())) ans = [] for k in K: d = m = dm = dmc = 0 for i in range(N): if i >= k: if S[i-k] == 'D': d -= 1 dm -= m elif S[i-k] == 'M': m -= 1 if S[i] == 'D': d += 1 elif S[i] == 'M': m += 1 dm += d elif S[i] == 'C': dmc += dm ans.append(dmc) print(*ans, sep='\n')
28
26
557
562
import sys rl = sys.stdin.readline N = int(rl()) S = rl() Q = int(rl()) ks = list(map(int, rl().split())) ans = [] for k in ks: d = m = 0 dm = dmc = 0 for i in range(N): if i >= k: if S[i - k] == "D": d -= 1 dm -= m elif S[i - k] == "M": m -= 1 if S[i] == "D": d += 1 elif S[i] == "M": m += 1 dm += d elif S[i] == "C": dmc += dm ans.append(dmc) print(*ans, sep="\n")
import sys input = sys.stdin.readline N = int(input()) S = input() Q = int(input()) K = list(map(int, input().split())) ans = [] for k in K: d = m = dm = dmc = 0 for i in range(N): if i >= k: if S[i - k] == "D": d -= 1 dm -= m elif S[i - k] == "M": m -= 1 if S[i] == "D": d += 1 elif S[i] == "M": m += 1 dm += d elif S[i] == "C": dmc += dm ans.append(dmc) print(*ans, sep="\n")
false
7.142857
[ "-rl = sys.stdin.readline", "-N = int(rl())", "-S = rl()", "-Q = int(rl())", "-ks = list(map(int, rl().split()))", "+input = sys.stdin.readline", "+N = int(input())", "+S = input()", "+Q = int(input())", "+K = list(map(int, input().split()))", "-for k in ks:", "- d = m = 0", "- dm = dmc = 0", "+for k in K:", "+ d = m = dm = dmc = 0" ]
false
0.04155
0.040964
1.014303
[ "s100975117", "s281816639" ]
u887207211
p03266
python
s646038481
s069576169
85
17
3,060
2,940
Accepted
Accepted
80
N, K = list(map(int,input().split())) a, b = 0, 0 for i in range(1, N+1): if(i%K == 0): a += 1 if(K%2 == 0): for i in range(1, N+1): if(i%K == K//2): b += 1 print((a**3 + b**3))
N, K = list(map(int,input().split())) k = N//K ans = k**3 if(K%2 == 0): if(K*k+K//2 <= N): ans += (k+1)**3 else: ans *= 2 print(ans)
10
9
196
146
N, K = list(map(int, input().split())) a, b = 0, 0 for i in range(1, N + 1): if i % K == 0: a += 1 if K % 2 == 0: for i in range(1, N + 1): if i % K == K // 2: b += 1 print((a**3 + b**3))
N, K = list(map(int, input().split())) k = N // K ans = k**3 if K % 2 == 0: if K * k + K // 2 <= N: ans += (k + 1) ** 3 else: ans *= 2 print(ans)
false
10
[ "-a, b = 0, 0", "-for i in range(1, N + 1):", "- if i % K == 0:", "- a += 1", "+k = N // K", "+ans = k**3", "- for i in range(1, N + 1):", "- if i % K == K // 2:", "- b += 1", "-print((a**3 + b**3))", "+ if K * k + K // 2 <= N:", "+ ans += (k + 1) ** 3", "+ else:", "+ ans *= 2", "+print(ans)" ]
false
0.045988
0.126148
0.364558
[ "s646038481", "s069576169" ]
u785989355
p03715
python
s126049618
s661659063
208
189
3,188
40,304
Accepted
Accepted
9.13
H,W = list(map(int,input().split())) min_score = 10**27 for i in range(1,H): if W%2==0: S1 = i*W/2 S2 = (H-i)*W min_score = min(abs(S1-S2),min_score) else: S1 = i*(W-1)/2 S2 = i*(W+1)/2 S3 = (H-i)*W S4 = max(S1,S2,S3) S5 = min(S1,S2,S3) min_score = min(S4-S5,min_score) for i in range(1,W): if H%2==0: S1 = i*H/2 S2 = (W-i)*H min_score = min(abs(S1-S2),min_score) else: S1 = i*(H-1)/2 S2 = i*(H+1)/2 S3 = (W-i)*H S4 = max(S1,S2,S3) S5 = min(S1,S2,S3) min_score = min(S4-S5,min_score) s1=int(H/3) s2=int((H-s1)/2) s3=H-s1-s2 S1 = max(s1*W,s2*W,s3*W) S2 = min(s1*W,s2*W,s3*W) min_score = min(S1-S2,min_score) s1=int(W/3) s2=int((W-s1)/2) s3=W-s1-s2 S1 = max(s1*H,s2*H,s3*H) S2 = min(s1*H,s2*H,s3*H) min_score = min(S1-S2,min_score) print((int(min_score)))
H,W=list(map(int,input().split())) min_d=10**27 if H%3==0 or W%3==0: print((0)) else: min_d=min(H,W) for i in range(H+1): a=i*W b=(H-i)*(W//2) c=(H-i)*W - b min_d = min(max(a,b,c)-min(a,b,c),min_d) for i in range(W+1): a=i*H b=(W-i)*(H//2) c=(W-i)*H - b min_d = min(max(a,b,c)-min(a,b,c),min_d) print(min_d)
46
19
963
409
H, W = list(map(int, input().split())) min_score = 10**27 for i in range(1, H): if W % 2 == 0: S1 = i * W / 2 S2 = (H - i) * W min_score = min(abs(S1 - S2), min_score) else: S1 = i * (W - 1) / 2 S2 = i * (W + 1) / 2 S3 = (H - i) * W S4 = max(S1, S2, S3) S5 = min(S1, S2, S3) min_score = min(S4 - S5, min_score) for i in range(1, W): if H % 2 == 0: S1 = i * H / 2 S2 = (W - i) * H min_score = min(abs(S1 - S2), min_score) else: S1 = i * (H - 1) / 2 S2 = i * (H + 1) / 2 S3 = (W - i) * H S4 = max(S1, S2, S3) S5 = min(S1, S2, S3) min_score = min(S4 - S5, min_score) s1 = int(H / 3) s2 = int((H - s1) / 2) s3 = H - s1 - s2 S1 = max(s1 * W, s2 * W, s3 * W) S2 = min(s1 * W, s2 * W, s3 * W) min_score = min(S1 - S2, min_score) s1 = int(W / 3) s2 = int((W - s1) / 2) s3 = W - s1 - s2 S1 = max(s1 * H, s2 * H, s3 * H) S2 = min(s1 * H, s2 * H, s3 * H) min_score = min(S1 - S2, min_score) print((int(min_score)))
H, W = list(map(int, input().split())) min_d = 10**27 if H % 3 == 0 or W % 3 == 0: print((0)) else: min_d = min(H, W) for i in range(H + 1): a = i * W b = (H - i) * (W // 2) c = (H - i) * W - b min_d = min(max(a, b, c) - min(a, b, c), min_d) for i in range(W + 1): a = i * H b = (W - i) * (H // 2) c = (W - i) * H - b min_d = min(max(a, b, c) - min(a, b, c), min_d) print(min_d)
false
58.695652
[ "-min_score = 10**27", "-for i in range(1, H):", "- if W % 2 == 0:", "- S1 = i * W / 2", "- S2 = (H - i) * W", "- min_score = min(abs(S1 - S2), min_score)", "- else:", "- S1 = i * (W - 1) / 2", "- S2 = i * (W + 1) / 2", "- S3 = (H - i) * W", "- S4 = max(S1, S2, S3)", "- S5 = min(S1, S2, S3)", "- min_score = min(S4 - S5, min_score)", "-for i in range(1, W):", "- if H % 2 == 0:", "- S1 = i * H / 2", "- S2 = (W - i) * H", "- min_score = min(abs(S1 - S2), min_score)", "- else:", "- S1 = i * (H - 1) / 2", "- S2 = i * (H + 1) / 2", "- S3 = (W - i) * H", "- S4 = max(S1, S2, S3)", "- S5 = min(S1, S2, S3)", "- min_score = min(S4 - S5, min_score)", "-s1 = int(H / 3)", "-s2 = int((H - s1) / 2)", "-s3 = H - s1 - s2", "-S1 = max(s1 * W, s2 * W, s3 * W)", "-S2 = min(s1 * W, s2 * W, s3 * W)", "-min_score = min(S1 - S2, min_score)", "-s1 = int(W / 3)", "-s2 = int((W - s1) / 2)", "-s3 = W - s1 - s2", "-S1 = max(s1 * H, s2 * H, s3 * H)", "-S2 = min(s1 * H, s2 * H, s3 * H)", "-min_score = min(S1 - S2, min_score)", "-print((int(min_score)))", "+min_d = 10**27", "+if H % 3 == 0 or W % 3 == 0:", "+ print((0))", "+else:", "+ min_d = min(H, W)", "+ for i in range(H + 1):", "+ a = i * W", "+ b = (H - i) * (W // 2)", "+ c = (H - i) * W - b", "+ min_d = min(max(a, b, c) - min(a, b, c), min_d)", "+ for i in range(W + 1):", "+ a = i * H", "+ b = (W - i) * (H // 2)", "+ c = (W - i) * H - b", "+ min_d = min(max(a, b, c) - min(a, b, c), min_d)", "+ print(min_d)" ]
false
0.047842
0.047162
1.014414
[ "s126049618", "s661659063" ]
u263753244
p02777
python
s199518380
s388718060
171
27
38,384
9,156
Accepted
Accepted
84.21
s,t=input().split() a,b=list(map(int,input().split())) u=eval(input()) if u==s: a-=1 else: b-=1 print((a,b))
s,t=input().split() a,b=list(map(int,input().split())) u=eval(input()) if u==s: print((a-1,b)) else: print((a,b-1))
8
7
109
113
s, t = input().split() a, b = list(map(int, input().split())) u = eval(input()) if u == s: a -= 1 else: b -= 1 print((a, b))
s, t = input().split() a, b = list(map(int, input().split())) u = eval(input()) if u == s: print((a - 1, b)) else: print((a, b - 1))
false
12.5
[ "- a -= 1", "+ print((a - 1, b))", "- b -= 1", "-print((a, b))", "+ print((a, b - 1))" ]
false
0.03562
0.040097
0.888336
[ "s199518380", "s388718060" ]
u184817817
p03160
python
s806333046
s784820161
184
140
50,960
13,928
Accepted
Accepted
23.91
import sys sys.setrecursionlimit(100000) n = int(eval(input())) h = list(map(int,input().split())) dp_ = [-1]*n def dp(i): if dp_[i]!=-1: return dp_[i] if i == 0: dp_[i] = 0 elif i == 1: dp_[i] = abs(h[1]-h[0]) else: dp_[i] = min(dp(i-2)+abs(h[i]-h[i-2]),dp(i-1)+abs(h[i]-h[i-1])) return dp_[i] print((dp(n-1)))
#A n = int(eval(input())) h = list(map(int,input().split())) cost = [0]*n for i in range(n): if i == 0: continue if i == 1: cost[i] = abs(h[i]-h[i-1]) continue cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2])) print((cost[n-1]))
19
13
377
288
import sys sys.setrecursionlimit(100000) n = int(eval(input())) h = list(map(int, input().split())) dp_ = [-1] * n def dp(i): if dp_[i] != -1: return dp_[i] if i == 0: dp_[i] = 0 elif i == 1: dp_[i] = abs(h[1] - h[0]) else: dp_[i] = min(dp(i - 2) + abs(h[i] - h[i - 2]), dp(i - 1) + abs(h[i] - h[i - 1])) return dp_[i] print((dp(n - 1)))
# A n = int(eval(input())) h = list(map(int, input().split())) cost = [0] * n for i in range(n): if i == 0: continue if i == 1: cost[i] = abs(h[i] - h[i - 1]) continue cost[i] = min( cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]) ) print((cost[n - 1]))
false
31.578947
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "+# A", "-dp_ = [-1] * n", "-", "-", "-def dp(i):", "- if dp_[i] != -1:", "- return dp_[i]", "+cost = [0] * n", "+for i in range(n):", "- dp_[i] = 0", "- elif i == 1:", "- dp_[i] = abs(h[1] - h[0])", "- else:", "- dp_[i] = min(dp(i - 2) + abs(h[i] - h[i - 2]), dp(i - 1) + abs(h[i] - h[i - 1]))", "- return dp_[i]", "-", "-", "-print((dp(n - 1)))", "+ continue", "+ if i == 1:", "+ cost[i] = abs(h[i] - h[i - 1])", "+ continue", "+ cost[i] = min(", "+ cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2])", "+ )", "+print((cost[n - 1]))" ]
false
0.046778
0.046399
1.008177
[ "s806333046", "s784820161" ]
u729133443
p02913
python
s670167160
s451546894
49
39
4,196
4,092
Accepted
Accepted
20.41
def main(): import sys input=sys.stdin.buffer.readline n=int(eval(input())) b=129 M=2**61-1 x,y=1,0 f=[x]*(n+2) h=[y]*(n+2) for i,c in enumerate(eval(input())): f[i+1]=x=x*b%M h[i+1]=y=(y*b+c)%M ok,ng=0,n//2+1 while ng-ok>1: mid=ok+ng>>1 d={} for i in range(0,n-mid+1): k=(h[i+mid]-h[i]*f[mid])%M if k in d: if d[k]+mid<=i: ok=mid break else: d[k]=i else: ng=mid print(ok) main()
def main(): import sys input=sys.stdin.buffer.readline n=int(eval(input())) b=37 M=998244353 x,y=1,0 f=[x]*(n+2) h=[y]*(n+2) for i,c in enumerate(eval(input())): f[i+1]=x=x*b%M h[i+1]=y=(y*b+c)%M ok,ng=0,n//2+1 while ng-ok>1: mid=ok+ng>>1 d={} for i in range(0,n-mid+1): k=(h[i+mid]-h[i]*f[mid])%M if k in d: if d[k]+mid<=i: ok=mid break else: d[k]=i else: ng=mid print(ok) main()
28
28
610
611
def main(): import sys input = sys.stdin.buffer.readline n = int(eval(input())) b = 129 M = 2**61 - 1 x, y = 1, 0 f = [x] * (n + 2) h = [y] * (n + 2) for i, c in enumerate(eval(input())): f[i + 1] = x = x * b % M h[i + 1] = y = (y * b + c) % M ok, ng = 0, n // 2 + 1 while ng - ok > 1: mid = ok + ng >> 1 d = {} for i in range(0, n - mid + 1): k = (h[i + mid] - h[i] * f[mid]) % M if k in d: if d[k] + mid <= i: ok = mid break else: d[k] = i else: ng = mid print(ok) main()
def main(): import sys input = sys.stdin.buffer.readline n = int(eval(input())) b = 37 M = 998244353 x, y = 1, 0 f = [x] * (n + 2) h = [y] * (n + 2) for i, c in enumerate(eval(input())): f[i + 1] = x = x * b % M h[i + 1] = y = (y * b + c) % M ok, ng = 0, n // 2 + 1 while ng - ok > 1: mid = ok + ng >> 1 d = {} for i in range(0, n - mid + 1): k = (h[i + mid] - h[i] * f[mid]) % M if k in d: if d[k] + mid <= i: ok = mid break else: d[k] = i else: ng = mid print(ok) main()
false
0
[ "- b = 129", "- M = 2**61 - 1", "+ b = 37", "+ M = 998244353" ]
false
0.114268
0.0418
2.733675
[ "s670167160", "s451546894" ]
u072717685
p03162
python
s333845569
s159538953
481
201
40,224
3,060
Accepted
Accepted
58.21
def main(): n = int(eval(input())) abc = [] for _ in range(n): abc.append(tuple(map(int, input().split()))) dp = [[0,0,0] for _ in range(n)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] 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[n-1]))) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): n = int(eval(input())) colA, colB, colC = list(map(int, input().split())) for i1 in range(1, n): a, b, c = list(map(int, input().split())) colA, colB, colC = a + max(colB, colC), b + max(colA, colC), c + max(colA, colB) print((max(colA, colB, colC))) if __name__ == '__main__': main()
18
13
529
365
def main(): n = int(eval(input())) abc = [] for _ in range(n): abc.append(tuple(map(int, input().split()))) dp = [[0, 0, 0] for _ in range(n)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] 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[n - 1]))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): n = int(eval(input())) colA, colB, colC = list(map(int, input().split())) for i1 in range(1, n): a, b, c = list(map(int, input().split())) colA, colB, colC = a + max(colB, colC), b + max(colA, colC), c + max(colA, colB) print((max(colA, colB, colC))) if __name__ == "__main__": main()
false
27.777778
[ "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "- abc = []", "- for _ in range(n):", "- abc.append(tuple(map(int, input().split())))", "- dp = [[0, 0, 0] for _ in range(n)]", "- dp[0][0] = abc[0][0]", "- dp[0][1] = abc[0][1]", "- dp[0][2] = abc[0][2]", "- 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[n - 1])))", "+ colA, colB, colC = list(map(int, input().split()))", "+ for i1 in range(1, n):", "+ a, b, c = list(map(int, input().split()))", "+ colA, colB, colC = a + max(colB, colC), b + max(colA, colC), c + max(colA, colB)", "+ print((max(colA, colB, colC)))" ]
false
0.06377
0.03411
1.869539
[ "s333845569", "s159538953" ]
u926678805
p03856
python
s605668330
s015948965
82
75
3,188
3,188
Accepted
Accepted
8.54
s=input()[::-1] d=['maerd','remaerd','esare','resare'] while s: for i in range(4): if s.startswith(d[i]): s=s[len(d[i]):] break else: print('NO') exit() print('YES')
s=eval(input()) d=['dream','dreamer','erase','eraser'] while s: for m in d: if s.endswith(m): s=s[:-len(m)] break else: print('NO') exit() print('YES')
11
11
232
212
s = input()[::-1] d = ["maerd", "remaerd", "esare", "resare"] while s: for i in range(4): if s.startswith(d[i]): s = s[len(d[i]) :] break else: print("NO") exit() print("YES")
s = eval(input()) d = ["dream", "dreamer", "erase", "eraser"] while s: for m in d: if s.endswith(m): s = s[: -len(m)] break else: print("NO") exit() print("YES")
false
0
[ "-s = input()[::-1]", "-d = [\"maerd\", \"remaerd\", \"esare\", \"resare\"]", "+s = eval(input())", "+d = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]", "- for i in range(4):", "- if s.startswith(d[i]):", "- s = s[len(d[i]) :]", "+ for m in d:", "+ if s.endswith(m):", "+ s = s[: -len(m)]" ]
false
0.06967
0.042737
1.630218
[ "s605668330", "s015948965" ]
u326609687
p02574
python
s686965304
s016048345
626
240
119,728
42,584
Accepted
Accepted
61.66
import numpy as np from numba import njit i4 = np.int32 i8 = np.int64 u4 = np.uint32 @njit def get_factorization(n): """ nまでの割り切れる最小の素数を返す。 """ sieve_size = (n - 1) // 2 sieve = np.zeros(sieve_size, u4) for i in range(sieve_size): if sieve[i] == 0: value_at_i = i*2 + 3 for j in range(i, sieve_size, value_at_i): if sieve[j] == 0: sieve[j] = value_at_i return sieve @njit('(u4[::-1],)', cache=True) def solve(A): a = np.sort(A) p_max = a[-1] p = get_factorization(p_max) primes_num = 1 for i in range(p.shape[0]): if i*2 + 3 == p[i]: primes_num += 1 a_start = 0 while a[a_start] == 1: a_start += 1 if a_start == a.shape[0]: return 0 a = a[a_start:] if len(a) > primes_num: return 1 check = np.zeros(p_max + 1, u4) for d in a: if d & 1 == 0: check[2] += 1 d //= 2 while d & 1 == 0: d //= 2 prev = 2 while d > 1: i = (d - 3) // 2 f = p[i] if f > prev: check[f] += 1 prev = f d //= f if check.max() > 1: return 1 else: return 0 def main(in_file): stdin = open(in_file) stdin.readline() A = np.fromstring(stdin.readline(), u4, sep=' ') ans = solve(A) if ans: g = np.gcd.reduce(A) if g > 1: ans = 2 else: ans = 1 p = ['pairwise coprime', 'setwise coprime', 'not coprime'] print((p[ans])) if __name__ == '__main__': main('/dev/stdin')
import sys import numpy as np i4 = np.int32 i8 = np.int64 u4 = np.uint32 if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC from numba import njit from numba.types import Array, int32, int64, uint32 cc = CC('my_module') @njit def get_factorization(n): """ nまでの割り切れる最小の素数を返す。 """ sieve_size = (n - 1) // 2 sieve = np.zeros(sieve_size, u4) for i in range(sieve_size): if sieve[i] == 0: value_at_i = i*2 + 3 for j in range(i, sieve_size, value_at_i): if sieve[j] == 0: sieve[j] = value_at_i return sieve @cc.export('solve', (Array(uint32, 1, 'C'),)) @njit('(u4[::-1],)', cache=True) def solve(A): a = np.sort(A) p_max = a[-1] p = get_factorization(p_max) primes_num = 1 for i in range(p.shape[0]): if i*2 + 3 == p[i]: primes_num += 1 a_start = 0 while a[a_start] == 1: a_start += 1 if a_start == a.shape[0]: return 0 a = a[a_start:] if len(a) > primes_num: return 1 check = np.zeros(p_max + 1, u4) for d in a: if d & 1 == 0: check[2] += 1 d //= 2 while d & 1 == 0: d //= 2 prev = 2 while d > 1: i = (d - 3) // 2 f = p[i] if f > prev: check[f] += 1 prev = f d //= f if check.max() > 1: return 1 else: return 0 cc.compile() exit(0) else: from my_module import solve def main(in_file): stdin = open(in_file) stdin.readline() A = np.fromstring(stdin.readline(), u4, sep=' ') ans = solve(A) if ans: g = np.gcd.reduce(A) if g > 1: ans = 2 else: ans = 1 p = ['pairwise coprime', 'setwise coprime', 'not coprime'] print((p[ans])) main(0)
79
90
1,770
2,219
import numpy as np from numba import njit i4 = np.int32 i8 = np.int64 u4 = np.uint32 @njit def get_factorization(n): """ nまでの割り切れる最小の素数を返す。 """ sieve_size = (n - 1) // 2 sieve = np.zeros(sieve_size, u4) for i in range(sieve_size): if sieve[i] == 0: value_at_i = i * 2 + 3 for j in range(i, sieve_size, value_at_i): if sieve[j] == 0: sieve[j] = value_at_i return sieve @njit("(u4[::-1],)", cache=True) def solve(A): a = np.sort(A) p_max = a[-1] p = get_factorization(p_max) primes_num = 1 for i in range(p.shape[0]): if i * 2 + 3 == p[i]: primes_num += 1 a_start = 0 while a[a_start] == 1: a_start += 1 if a_start == a.shape[0]: return 0 a = a[a_start:] if len(a) > primes_num: return 1 check = np.zeros(p_max + 1, u4) for d in a: if d & 1 == 0: check[2] += 1 d //= 2 while d & 1 == 0: d //= 2 prev = 2 while d > 1: i = (d - 3) // 2 f = p[i] if f > prev: check[f] += 1 prev = f d //= f if check.max() > 1: return 1 else: return 0 def main(in_file): stdin = open(in_file) stdin.readline() A = np.fromstring(stdin.readline(), u4, sep=" ") ans = solve(A) if ans: g = np.gcd.reduce(A) if g > 1: ans = 2 else: ans = 1 p = ["pairwise coprime", "setwise coprime", "not coprime"] print((p[ans])) if __name__ == "__main__": main("/dev/stdin")
import sys import numpy as np i4 = np.int32 i8 = np.int64 u4 = np.uint32 if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC from numba import njit from numba.types import Array, int32, int64, uint32 cc = CC("my_module") @njit def get_factorization(n): """ nまでの割り切れる最小の素数を返す。 """ sieve_size = (n - 1) // 2 sieve = np.zeros(sieve_size, u4) for i in range(sieve_size): if sieve[i] == 0: value_at_i = i * 2 + 3 for j in range(i, sieve_size, value_at_i): if sieve[j] == 0: sieve[j] = value_at_i return sieve @cc.export("solve", (Array(uint32, 1, "C"),)) @njit("(u4[::-1],)", cache=True) def solve(A): a = np.sort(A) p_max = a[-1] p = get_factorization(p_max) primes_num = 1 for i in range(p.shape[0]): if i * 2 + 3 == p[i]: primes_num += 1 a_start = 0 while a[a_start] == 1: a_start += 1 if a_start == a.shape[0]: return 0 a = a[a_start:] if len(a) > primes_num: return 1 check = np.zeros(p_max + 1, u4) for d in a: if d & 1 == 0: check[2] += 1 d //= 2 while d & 1 == 0: d //= 2 prev = 2 while d > 1: i = (d - 3) // 2 f = p[i] if f > prev: check[f] += 1 prev = f d //= f if check.max() > 1: return 1 else: return 0 cc.compile() exit(0) else: from my_module import solve def main(in_file): stdin = open(in_file) stdin.readline() A = np.fromstring(stdin.readline(), u4, sep=" ") ans = solve(A) if ans: g = np.gcd.reduce(A) if g > 1: ans = 2 else: ans = 1 p = ["pairwise coprime", "setwise coprime", "not coprime"] print((p[ans])) main(0)
false
12.222222
[ "+import sys", "-from numba import njit", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "+ from numba import njit", "+ from numba.types import Array, int32, int64, uint32", "+ cc = CC(\"my_module\")", "-@njit", "-def get_factorization(n):", "- \"\"\"", "- nまでの割り切れる最小の素数を返す。", "- \"\"\"", "- sieve_size = (n - 1) // 2", "- sieve = np.zeros(sieve_size, u4)", "- for i in range(sieve_size):", "- if sieve[i] == 0:", "- value_at_i = i * 2 + 3", "- for j in range(i, sieve_size, value_at_i):", "- if sieve[j] == 0:", "- sieve[j] = value_at_i", "- return sieve", "+ @njit", "+ def get_factorization(n):", "+ \"\"\"", "+ nまでの割り切れる最小の素数を返す。", "+ \"\"\"", "+ sieve_size = (n - 1) // 2", "+ sieve = np.zeros(sieve_size, u4)", "+ for i in range(sieve_size):", "+ if sieve[i] == 0:", "+ value_at_i = i * 2 + 3", "+ for j in range(i, sieve_size, value_at_i):", "+ if sieve[j] == 0:", "+ sieve[j] = value_at_i", "+ return sieve", "+ @cc.export(\"solve\", (Array(uint32, 1, \"C\"),))", "+ @njit(\"(u4[::-1],)\", cache=True)", "+ def solve(A):", "+ a = np.sort(A)", "+ p_max = a[-1]", "+ p = get_factorization(p_max)", "+ primes_num = 1", "+ for i in range(p.shape[0]):", "+ if i * 2 + 3 == p[i]:", "+ primes_num += 1", "+ a_start = 0", "+ while a[a_start] == 1:", "+ a_start += 1", "+ if a_start == a.shape[0]:", "+ return 0", "+ a = a[a_start:]", "+ if len(a) > primes_num:", "+ return 1", "+ check = np.zeros(p_max + 1, u4)", "+ for d in a:", "+ if d & 1 == 0:", "+ check[2] += 1", "+ d //= 2", "+ while d & 1 == 0:", "+ d //= 2", "+ prev = 2", "+ while d > 1:", "+ i = (d - 3) // 2", "+ f = p[i]", "+ if f > prev:", "+ check[f] += 1", "+ prev = f", "+ d //= f", "+ if check.max() > 1:", "+ return 1", "+ else:", "+ return 0", "-@njit(\"(u4[::-1],)\", cache=True)", "-def solve(A):", "- a = np.sort(A)", "- p_max = a[-1]", "- p = get_factorization(p_max)", "- primes_num = 1", "- for i in range(p.shape[0]):", "- if i * 2 + 3 == p[i]:", "- primes_num += 1", "- a_start = 0", "- while a[a_start] == 1:", "- a_start += 1", "- if a_start == a.shape[0]:", "- return 0", "- a = a[a_start:]", "- if len(a) > primes_num:", "- return 1", "- check = np.zeros(p_max + 1, u4)", "- for d in a:", "- if d & 1 == 0:", "- check[2] += 1", "- d //= 2", "- while d & 1 == 0:", "- d //= 2", "- prev = 2", "- while d > 1:", "- i = (d - 3) // 2", "- f = p[i]", "- if f > prev:", "- check[f] += 1", "- prev = f", "- d //= f", "- if check.max() > 1:", "- return 1", "- else:", "- return 0", "+ cc.compile()", "+ exit(0)", "+else:", "+ from my_module import solve", "-if __name__ == \"__main__\":", "- main(\"/dev/stdin\")", "+main(0)" ]
false
0.172163
0.197752
0.870602
[ "s686965304", "s016048345" ]
u102461423
p03248
python
s336734346
s249142210
171
91
16,592
14,232
Accepted
Accepted
46.78
import sys input = sys.stdin.readline S = '-' + input().rstrip() N = len(S) - 1 def solve(S): if S[1] == '0': return None if S[N] == '1': return None prev = 1 graph = [] for n in range(1,N//2 + 1): if S[n] != S[N-n]: return None if S[n] == '0': continue for i in range(prev,n): graph.append((i,n)) prev = n for i in range(prev,N): graph.append((i,N)) return graph graph = solve(S) if graph is None: print((-1)) else: for x,y in graph: print((x,y))
import sys input = sys.stdin.readline S = '-' + input().rstrip() N = len(S) - 1 def solve(S): if S[1] == '0': return None if S[N] == '1': return None prev = 1 graph = [] for n in range(1,N//2 + 1): if S[n] != S[N-n]: return None if S[n] == '0': continue for i in range(prev,n): graph.append('{} {}'.format(i,n)) prev = n for i in range(prev,N): graph.append('{} {}'.format(i,N)) return graph graph = solve(S) if graph is None: print((-1)) else: print(('\n'.join(graph)))
32
31
614
629
import sys input = sys.stdin.readline S = "-" + input().rstrip() N = len(S) - 1 def solve(S): if S[1] == "0": return None if S[N] == "1": return None prev = 1 graph = [] for n in range(1, N // 2 + 1): if S[n] != S[N - n]: return None if S[n] == "0": continue for i in range(prev, n): graph.append((i, n)) prev = n for i in range(prev, N): graph.append((i, N)) return graph graph = solve(S) if graph is None: print((-1)) else: for x, y in graph: print((x, y))
import sys input = sys.stdin.readline S = "-" + input().rstrip() N = len(S) - 1 def solve(S): if S[1] == "0": return None if S[N] == "1": return None prev = 1 graph = [] for n in range(1, N // 2 + 1): if S[n] != S[N - n]: return None if S[n] == "0": continue for i in range(prev, n): graph.append("{} {}".format(i, n)) prev = n for i in range(prev, N): graph.append("{} {}".format(i, N)) return graph graph = solve(S) if graph is None: print((-1)) else: print(("\n".join(graph)))
false
3.125
[ "- graph.append((i, n))", "+ graph.append(\"{} {}\".format(i, n))", "- graph.append((i, N))", "+ graph.append(\"{} {}\".format(i, N))", "- for x, y in graph:", "- print((x, y))", "+ print((\"\\n\".join(graph)))" ]
false
0.036177
0.035935
1.006745
[ "s336734346", "s249142210" ]
u134302690
p03308
python
s827363892
s320630441
166
18
38,512
2,940
Accepted
Accepted
89.16
n = int(eval(input())) a = list(map(int,input().split())) a.sort(reverse=True) print((a[0]-a[-1]))
N = int(eval(input())) A = list(map(int,input().split())) A.sort() print((A[-1]-A[0]))
4
4
93
81
n = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse=True) print((a[0] - a[-1]))
N = int(eval(input())) A = list(map(int, input().split())) A.sort() print((A[-1] - A[0]))
false
0
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-a.sort(reverse=True)", "-print((a[0] - a[-1]))", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+A.sort()", "+print((A[-1] - A[0]))" ]
false
0.039377
0.038414
1.025056
[ "s827363892", "s320630441" ]
u636683284
p02837
python
s147650733
s524104905
166
134
74,892
74,436
Accepted
Accepted
19.28
from collections import defaultdict,deque n = int(eval(input())) d = defaultdict(list) for i in range(n): a = int(eval(input())) for j in range(a): x,y = list(map(int,input().split())) d[i].append((x-1,bool(y))) maxi = 0 for i in range(2 ** n): honest = [-1]*n que = deque([]) for j in range(n): if ((i >> j) & 1): que.append(n-1-j) honest[n-1-j] = True flag = True while que and flag: v = que.popleft() for x,y in d[v]: if honest[x] == -1: honest[x] = y if y: que.append(x) elif honest[x] != y: flag = False break if flag: maxi = max(maxi,str(bin(i)).count('1')) print(maxi)
def judge(bit): global l for i in range(n): if (bit>>i)&1 == 0: continue for x,y in l[i]: if y==1 and (bit>>x)&1==0: return False if y==0 and (bit>>x)&1==1: return False return True n = int(eval(input())) l = [[] for _ in range(n)] for i in range(n): a = int(eval(input())) for j in range(a): x,y = list(map(int,input().split())) l[i].append((x-1,y)) maxi = 0 for bit in range(2**n): if judge(bit): maxi = max(maxi,str(bin(bit)).count('1')) print(maxi)
31
24
808
590
from collections import defaultdict, deque n = int(eval(input())) d = defaultdict(list) for i in range(n): a = int(eval(input())) for j in range(a): x, y = list(map(int, input().split())) d[i].append((x - 1, bool(y))) maxi = 0 for i in range(2**n): honest = [-1] * n que = deque([]) for j in range(n): if (i >> j) & 1: que.append(n - 1 - j) honest[n - 1 - j] = True flag = True while que and flag: v = que.popleft() for x, y in d[v]: if honest[x] == -1: honest[x] = y if y: que.append(x) elif honest[x] != y: flag = False break if flag: maxi = max(maxi, str(bin(i)).count("1")) print(maxi)
def judge(bit): global l for i in range(n): if (bit >> i) & 1 == 0: continue for x, y in l[i]: if y == 1 and (bit >> x) & 1 == 0: return False if y == 0 and (bit >> x) & 1 == 1: return False return True n = int(eval(input())) l = [[] for _ in range(n)] for i in range(n): a = int(eval(input())) for j in range(a): x, y = list(map(int, input().split())) l[i].append((x - 1, y)) maxi = 0 for bit in range(2**n): if judge(bit): maxi = max(maxi, str(bin(bit)).count("1")) print(maxi)
false
22.580645
[ "-from collections import defaultdict, deque", "+def judge(bit):", "+ global l", "+ for i in range(n):", "+ if (bit >> i) & 1 == 0:", "+ continue", "+ for x, y in l[i]:", "+ if y == 1 and (bit >> x) & 1 == 0:", "+ return False", "+ if y == 0 and (bit >> x) & 1 == 1:", "+ return False", "+ return True", "+", "-d = defaultdict(list)", "+l = [[] for _ in range(n)]", "- d[i].append((x - 1, bool(y)))", "+ l[i].append((x - 1, y))", "-for i in range(2**n):", "- honest = [-1] * n", "- que = deque([])", "- for j in range(n):", "- if (i >> j) & 1:", "- que.append(n - 1 - j)", "- honest[n - 1 - j] = True", "- flag = True", "- while que and flag:", "- v = que.popleft()", "- for x, y in d[v]:", "- if honest[x] == -1:", "- honest[x] = y", "- if y:", "- que.append(x)", "- elif honest[x] != y:", "- flag = False", "- break", "- if flag:", "- maxi = max(maxi, str(bin(i)).count(\"1\"))", "+for bit in range(2**n):", "+ if judge(bit):", "+ maxi = max(maxi, str(bin(bit)).count(\"1\"))" ]
false
0.105589
0.036927
2.859386
[ "s147650733", "s524104905" ]
u684120680
p02948
python
s997081043
s256147643
1,697
191
26,692
31,508
Accepted
Accepted
88.74
from bisect import bisect_left as bisect def main(): n, m, *ab = list(map(int, open(0).read().split())) rate = [] for a, b in zip(*[iter(ab)] * 2): if a > m: continue rate.append([a, b]) rate = sorted(rate, key=lambda x: -x[1]) day = list(range(1, m + 1)) day_len = m ans = 0 for term, money in rate: work_day = bisect(day, term) if work_day == day_len: continue else: del day[work_day] day_len -= 1 ans += money print(ans) return() if __name__ == '__main__': main()
import heapq def main(): n, m, *ab = list(map(int, open(0).read().split())) ab_dict = {} for a, b in zip(*[iter(ab)] * 2): if a > m: continue if a in ab_dict: ab_dict[a].append(-b) else: ab_dict[a] = [-b] cand = [] ans = 0 for day in range(1, m+1): if day in ab_dict: for cand_b in ab_dict[day]: heapq.heappush(cand, cand_b) if cand: ans += -heapq.heappop(cand) print(ans) return() if __name__ == '__main__': main()
30
28
640
594
from bisect import bisect_left as bisect def main(): n, m, *ab = list(map(int, open(0).read().split())) rate = [] for a, b in zip(*[iter(ab)] * 2): if a > m: continue rate.append([a, b]) rate = sorted(rate, key=lambda x: -x[1]) day = list(range(1, m + 1)) day_len = m ans = 0 for term, money in rate: work_day = bisect(day, term) if work_day == day_len: continue else: del day[work_day] day_len -= 1 ans += money print(ans) return () if __name__ == "__main__": main()
import heapq def main(): n, m, *ab = list(map(int, open(0).read().split())) ab_dict = {} for a, b in zip(*[iter(ab)] * 2): if a > m: continue if a in ab_dict: ab_dict[a].append(-b) else: ab_dict[a] = [-b] cand = [] ans = 0 for day in range(1, m + 1): if day in ab_dict: for cand_b in ab_dict[day]: heapq.heappush(cand, cand_b) if cand: ans += -heapq.heappop(cand) print(ans) return () if __name__ == "__main__": main()
false
6.666667
[ "-from bisect import bisect_left as bisect", "+import heapq", "- rate = []", "+ ab_dict = {}", "- rate.append([a, b])", "- rate = sorted(rate, key=lambda x: -x[1])", "- day = list(range(1, m + 1))", "- day_len = m", "+ if a in ab_dict:", "+ ab_dict[a].append(-b)", "+ else:", "+ ab_dict[a] = [-b]", "+ cand = []", "- for term, money in rate:", "- work_day = bisect(day, term)", "- if work_day == day_len:", "- continue", "- else:", "- del day[work_day]", "- day_len -= 1", "- ans += money", "+ for day in range(1, m + 1):", "+ if day in ab_dict:", "+ for cand_b in ab_dict[day]:", "+ heapq.heappush(cand, cand_b)", "+ if cand:", "+ ans += -heapq.heappop(cand)" ]
false
0.03845
0.084496
0.455054
[ "s997081043", "s256147643" ]
u555767343
p02786
python
s730326600
s767421888
164
66
38,256
61,772
Accepted
Accepted
59.76
h = int(eval(input())) def attack(h): count = 0 if h == 1: count += 1 return count else: count += 1 count += 2*attack(h//2) return count print((attack(h)))
h = int(eval(input())) num = 1 count = 0 while h > 0: h = h//2 count += num num = num*2 print(count)
12
9
211
115
h = int(eval(input())) def attack(h): count = 0 if h == 1: count += 1 return count else: count += 1 count += 2 * attack(h // 2) return count print((attack(h)))
h = int(eval(input())) num = 1 count = 0 while h > 0: h = h // 2 count += num num = num * 2 print(count)
false
25
[ "-", "-", "-def attack(h):", "- count = 0", "- if h == 1:", "- count += 1", "- return count", "- else:", "- count += 1", "- count += 2 * attack(h // 2)", "- return count", "-", "-", "-print((attack(h)))", "+num = 1", "+count = 0", "+while h > 0:", "+ h = h // 2", "+ count += num", "+ num = num * 2", "+print(count)" ]
false
0.069372
0.069357
1.000214
[ "s730326600", "s767421888" ]
u971811058
p03502
python
s986651017
s007526651
31
25
9,104
9,112
Accepted
Accepted
19.35
n = int(eval(input())) s = str(n) sum = 0 for i in range(len(s)): sum+=(ord(s[i])-ord('0')) if n%sum == 0: print("Yes") else: print("No")
s = eval(input()) sum = 0 for i in s: sum+=int(i) if int(s)%sum == 0: print("Yes") else: print("No")
9
6
151
103
n = int(eval(input())) s = str(n) sum = 0 for i in range(len(s)): sum += ord(s[i]) - ord("0") if n % sum == 0: print("Yes") else: print("No")
s = eval(input()) sum = 0 for i in s: sum += int(i) if int(s) % sum == 0: print("Yes") else: print("No")
false
33.333333
[ "-n = int(eval(input()))", "-s = str(n)", "+s = eval(input())", "-for i in range(len(s)):", "- sum += ord(s[i]) - ord(\"0\")", "-if n % sum == 0:", "+for i in s:", "+ sum += int(i)", "+if int(s) % sum == 0:" ]
false
0.038215
0.101535
0.376375
[ "s986651017", "s007526651" ]
u972658925
p02572
python
s093829731
s502539661
276
242
50,036
49,740
Accepted
Accepted
12.32
import numpy as np n = int(eval(input())) a = list(map(int,input().split())) a_sum = sum(a) aa = np.array(np.cumsum(a),dtype="object") all_a = sum(a) mod = 1000000007 ans = 0 for i in range(n-1): ans += (a[i]%mod * (all_a - aa[i])%mod) print((ans%mod))
import numpy as np n = int(eval(input())) a = list(map(int,input().split())) a_sum = sum(a) aa = np.array(np.cumsum(a),dtype="object") all_a = sum(a) mod = 1000000007 ans = 0 for i in range(n-1): ans += (a[i] * (all_a - aa[i])) print((ans%mod))
14
14
264
256
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) a_sum = sum(a) aa = np.array(np.cumsum(a), dtype="object") all_a = sum(a) mod = 1000000007 ans = 0 for i in range(n - 1): ans += a[i] % mod * (all_a - aa[i]) % mod print((ans % mod))
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) a_sum = sum(a) aa = np.array(np.cumsum(a), dtype="object") all_a = sum(a) mod = 1000000007 ans = 0 for i in range(n - 1): ans += a[i] * (all_a - aa[i]) print((ans % mod))
false
0
[ "- ans += a[i] % mod * (all_a - aa[i]) % mod", "+ ans += a[i] * (all_a - aa[i])" ]
false
0.236717
0.231004
1.024731
[ "s093829731", "s502539661" ]
u525065967
p02658
python
s034433713
s532485109
87
72
21,640
21,420
Accepted
Accepted
17.24
n = int(eval(input())) A = [*list(map(int,input().split()))] A.sort() ans = 1 for a in A: ans *= a if ans > 10**18: ans = -1 break print(ans)
n = int(eval(input())) A = [*list(map(int,input().split()))] inf = 10**18 + 1 ans = 1 for a in A: ans = min(ans*a, inf) if ans == inf: ans = -1 print(ans)
10
7
163
149
n = int(eval(input())) A = [*list(map(int, input().split()))] A.sort() ans = 1 for a in A: ans *= a if ans > 10**18: ans = -1 break print(ans)
n = int(eval(input())) A = [*list(map(int, input().split()))] inf = 10**18 + 1 ans = 1 for a in A: ans = min(ans * a, inf) if ans == inf: ans = -1 print(ans)
false
30
[ "-A.sort()", "+inf = 10**18 + 1", "- ans *= a", "- if ans > 10**18:", "- ans = -1", "- break", "+ ans = min(ans * a, inf)", "+if ans == inf:", "+ ans = -1" ]
false
0.103593
0.10522
0.984536
[ "s034433713", "s532485109" ]
u309120194
p02829
python
s420633921
s012439445
28
25
9,168
9,128
Accepted
Accepted
10.71
A = int(eval(input())) B = int(eval(input())) l = [1,2,3] l.remove(A) l.remove(B) print((l[0]))
A = int(eval(input())) B = int(eval(input())) # 頭いい方法! print((6-A-B))
8
5
92
61
A = int(eval(input())) B = int(eval(input())) l = [1, 2, 3] l.remove(A) l.remove(B) print((l[0]))
A = int(eval(input())) B = int(eval(input())) # 頭いい方法! print((6 - A - B))
false
37.5
[ "-l = [1, 2, 3]", "-l.remove(A)", "-l.remove(B)", "-print((l[0]))", "+# 頭いい方法!", "+print((6 - A - B))" ]
false
0.081599
0.044331
1.840687
[ "s420633921", "s012439445" ]
u189487046
p03273
python
s827112964
s851058332
23
20
3,188
3,316
Accepted
Accepted
13.04
H, W = list(map(int, input().split())) a = [] for i in range(H): tmp = list(eval(input())) if "#" in tmp: a.append(tmp) w_check = [True] * W for i in range(len(a)): for j in range(W): if a[i][j] == "#": w_check[j] = False ans = [[] for i in range(len(a))] for i in range(len(a)): for j in range(W): if not w_check[j]: ans[i].append(a[i][j]) for i in ans: output = "" for j in i: output += j print(output)
# zipを使用する版 H, W = list(map(int, input().split())) a = [] for _ in range(H): tmp = list(eval(input())) if "#" in tmp: a.append(tmp) a_reverse = list(map(list, list(zip(*a)))) ans = [] for tmp in a_reverse: if "#" in tmp: ans.append(tmp) ans_list = list(map(list, list(zip(*ans)))) for tmp_list in ans_list: tmp = "" for tmp_val in tmp_list: tmp += tmp_val print(tmp)
24
22
503
416
H, W = list(map(int, input().split())) a = [] for i in range(H): tmp = list(eval(input())) if "#" in tmp: a.append(tmp) w_check = [True] * W for i in range(len(a)): for j in range(W): if a[i][j] == "#": w_check[j] = False ans = [[] for i in range(len(a))] for i in range(len(a)): for j in range(W): if not w_check[j]: ans[i].append(a[i][j]) for i in ans: output = "" for j in i: output += j print(output)
# zipを使用する版 H, W = list(map(int, input().split())) a = [] for _ in range(H): tmp = list(eval(input())) if "#" in tmp: a.append(tmp) a_reverse = list(map(list, list(zip(*a)))) ans = [] for tmp in a_reverse: if "#" in tmp: ans.append(tmp) ans_list = list(map(list, list(zip(*ans)))) for tmp_list in ans_list: tmp = "" for tmp_val in tmp_list: tmp += tmp_val print(tmp)
false
8.333333
[ "+# zipを使用する版", "-for i in range(H):", "+for _ in range(H):", "-w_check = [True] * W", "-for i in range(len(a)):", "- for j in range(W):", "- if a[i][j] == \"#\":", "- w_check[j] = False", "-ans = [[] for i in range(len(a))]", "-for i in range(len(a)):", "- for j in range(W):", "- if not w_check[j]:", "- ans[i].append(a[i][j])", "-for i in ans:", "- output = \"\"", "- for j in i:", "- output += j", "- print(output)", "+a_reverse = list(map(list, list(zip(*a))))", "+ans = []", "+for tmp in a_reverse:", "+ if \"#\" in tmp:", "+ ans.append(tmp)", "+ans_list = list(map(list, list(zip(*ans))))", "+for tmp_list in ans_list:", "+ tmp = \"\"", "+ for tmp_val in tmp_list:", "+ tmp += tmp_val", "+ print(tmp)" ]
false
0.035195
0.037191
0.946329
[ "s827112964", "s851058332" ]
u581187895
p02888
python
s846156040
s804134227
1,402
817
3,188
3,316
Accepted
Accepted
41.73
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 # a と b を固定 for a in range(N): for b in range((a+1), N): # c の動ける範囲の右端を求める c = L[a]+L[b] k = bisect.bisect_left(L, c) # c の動ける範囲は、[j+1, k) ans += k - b - 1 print(ans)
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1, 1, -1): a = 0 b = i-1 while a<b: if L[a]+L[b] > L[i]: ans += b-a b -= 1 else: a += 1 print(ans)
17
19
313
285
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 # a と b を固定 for a in range(N): for b in range((a + 1), N): # c の動ける範囲の右端を求める c = L[a] + L[b] k = bisect.bisect_left(L, c) # c の動ける範囲は、[j+1, k) ans += k - b - 1 print(ans)
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 1, 1, -1): a = 0 b = i - 1 while a < b: if L[a] + L[b] > L[i]: ans += b - a b -= 1 else: a += 1 print(ans)
false
10.526316
[ "-# a と b を固定", "-for a in range(N):", "- for b in range((a + 1), N):", "- # c の動ける範囲の右端を求める", "- c = L[a] + L[b]", "- k = bisect.bisect_left(L, c)", "- # c の動ける範囲は、[j+1, k)", "- ans += k - b - 1", "+for i in range(N - 1, 1, -1):", "+ a = 0", "+ b = i - 1", "+ while a < b:", "+ if L[a] + L[b] > L[i]:", "+ ans += b - a", "+ b -= 1", "+ else:", "+ a += 1" ]
false
0.039461
0.04661
0.846631
[ "s846156040", "s804134227" ]
u678167152
p02844
python
s244817804
s620181490
405
18
71,132
3,060
Accepted
Accepted
95.56
from collections import deque,defaultdict def solve(): N = int(eval(input())) S = list(eval(input())) dic = defaultdict(lambda: False) ans = 0 d = deque() for s in S: for _ in range(len(d)): t = d.popleft() d.append(t) if len(t)==1: u = t+s if dic[u]==False: dic[u] = True d.append(u) if len(t)==2: u = t+s if dic[u]==False: dic[u] = True ans += 1 if dic[s]==False: dic[s] = True d.append(s) return ans print((solve()))
n=int(eval(input())) s=eval(input()) ans=0 for i in range(10): x=s.find(str(i)) if x!=-1: for j in range(10): y=s.find(str(j),x+1) if y!=-1: for k in range(10): z=s.find(str(k),y+1) if z!=-1: ans+=1 print(ans)
26
15
690
334
from collections import deque, defaultdict def solve(): N = int(eval(input())) S = list(eval(input())) dic = defaultdict(lambda: False) ans = 0 d = deque() for s in S: for _ in range(len(d)): t = d.popleft() d.append(t) if len(t) == 1: u = t + s if dic[u] == False: dic[u] = True d.append(u) if len(t) == 2: u = t + s if dic[u] == False: dic[u] = True ans += 1 if dic[s] == False: dic[s] = True d.append(s) return ans print((solve()))
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(10): x = s.find(str(i)) if x != -1: for j in range(10): y = s.find(str(j), x + 1) if y != -1: for k in range(10): z = s.find(str(k), y + 1) if z != -1: ans += 1 print(ans)
false
42.307692
[ "-from collections import deque, defaultdict", "-", "-", "-def solve():", "- N = int(eval(input()))", "- S = list(eval(input()))", "- dic = defaultdict(lambda: False)", "- ans = 0", "- d = deque()", "- for s in S:", "- for _ in range(len(d)):", "- t = d.popleft()", "- d.append(t)", "- if len(t) == 1:", "- u = t + s", "- if dic[u] == False:", "- dic[u] = True", "- d.append(u)", "- if len(t) == 2:", "- u = t + s", "- if dic[u] == False:", "- dic[u] = True", "- ans += 1", "- if dic[s] == False:", "- dic[s] = True", "- d.append(s)", "- return ans", "-", "-", "-print((solve()))", "+n = int(eval(input()))", "+s = eval(input())", "+ans = 0", "+for i in range(10):", "+ x = s.find(str(i))", "+ if x != -1:", "+ for j in range(10):", "+ y = s.find(str(j), x + 1)", "+ if y != -1:", "+ for k in range(10):", "+ z = s.find(str(k), y + 1)", "+ if z != -1:", "+ ans += 1", "+print(ans)" ]
false
0.083311
0.035161
2.369405
[ "s244817804", "s620181490" ]
u183200783
p02785
python
s091235035
s023672763
213
186
26,180
26,024
Accepted
Accepted
12.68
N, K = list(map(int, input().split())) H = sorted(list(map(int, input().split())), reverse=True) cnt = 0 atk = 0 while True: for i in range(N): if H[i] <= 0: continue else: if K > 0: K -= 1 H[i] = 0 cnt += 1 else: atk += H[i] cnt += 1 if cnt == N: break print(atk)
N, K = list(map(int, input().split())) H = sorted(list(map(int, input().split())), reverse=True) atk = 0 for i in range(N): if K > 0: K -= 1 else: atk += H[i] print(atk)
22
11
430
199
N, K = list(map(int, input().split())) H = sorted(list(map(int, input().split())), reverse=True) cnt = 0 atk = 0 while True: for i in range(N): if H[i] <= 0: continue else: if K > 0: K -= 1 H[i] = 0 cnt += 1 else: atk += H[i] cnt += 1 if cnt == N: break print(atk)
N, K = list(map(int, input().split())) H = sorted(list(map(int, input().split())), reverse=True) atk = 0 for i in range(N): if K > 0: K -= 1 else: atk += H[i] print(atk)
false
50
[ "-cnt = 0", "-while True:", "- for i in range(N):", "- if H[i] <= 0:", "- continue", "- else:", "- if K > 0:", "- K -= 1", "- H[i] = 0", "- cnt += 1", "- else:", "- atk += H[i]", "- cnt += 1", "- if cnt == N:", "- break", "+for i in range(N):", "+ if K > 0:", "+ K -= 1", "+ else:", "+ atk += H[i]" ]
false
0.039298
0.037495
1.048072
[ "s091235035", "s023672763" ]
u948524308
p03013
python
s933373515
s249567187
357
154
460,020
3,064
Accepted
Accepted
56.86
def fib(n): if n==1: ans=[1] return ans ans=[1,1] cnt=2 while cnt <n: ans.append(ans[-2]+ans[-1]) cnt+=1 return ans N,M=list(map(int,input().split())) mod=10**9+7 if N==1: print((1)) exit() a0=-1 ans=1 for i in range(M): a=int(eval(input())) n=(a-1)-(a0+1) if a-a0==1: print((0)) exit() c=fib(n+1)[-1] ans=(ans*c)%mod a0=a a = N+1 n = (a - 1) - (a0 + 1) c = fib(n+1)[-1] ans=(ans*c)%mod print(ans)
def fib(n): if n==1: a=1 return a if n==2: a=1 return a a0=1 a1=1 cnt=2 while cnt <n: a=a0+a1 cnt+=1 a0=a1 a1=a return a N,M=list(map(int,input().split())) mod=10**9+7 if N==1: print((1)) exit() a0=-1 ans=1 for i in range(M): a=int(eval(input())) n=(a-1)-(a0+1) if a-a0==1: print((0)) exit() c=fib(n+1) ans=(ans*c)%mod a0=a a = N+1 n = (a - 1) - (a0 + 1) c = fib(n+1) ans=(ans*c)%mod print(ans)
40
46
530
573
def fib(n): if n == 1: ans = [1] return ans ans = [1, 1] cnt = 2 while cnt < n: ans.append(ans[-2] + ans[-1]) cnt += 1 return ans N, M = list(map(int, input().split())) mod = 10**9 + 7 if N == 1: print((1)) exit() a0 = -1 ans = 1 for i in range(M): a = int(eval(input())) n = (a - 1) - (a0 + 1) if a - a0 == 1: print((0)) exit() c = fib(n + 1)[-1] ans = (ans * c) % mod a0 = a a = N + 1 n = (a - 1) - (a0 + 1) c = fib(n + 1)[-1] ans = (ans * c) % mod print(ans)
def fib(n): if n == 1: a = 1 return a if n == 2: a = 1 return a a0 = 1 a1 = 1 cnt = 2 while cnt < n: a = a0 + a1 cnt += 1 a0 = a1 a1 = a return a N, M = list(map(int, input().split())) mod = 10**9 + 7 if N == 1: print((1)) exit() a0 = -1 ans = 1 for i in range(M): a = int(eval(input())) n = (a - 1) - (a0 + 1) if a - a0 == 1: print((0)) exit() c = fib(n + 1) ans = (ans * c) % mod a0 = a a = N + 1 n = (a - 1) - (a0 + 1) c = fib(n + 1) ans = (ans * c) % mod print(ans)
false
13.043478
[ "- ans = [1]", "- return ans", "- ans = [1, 1]", "+ a = 1", "+ return a", "+ if n == 2:", "+ a = 1", "+ return a", "+ a0 = 1", "+ a1 = 1", "- ans.append(ans[-2] + ans[-1])", "+ a = a0 + a1", "- return ans", "+ a0 = a1", "+ a1 = a", "+ return a", "- c = fib(n + 1)[-1]", "+ c = fib(n + 1)", "-c = fib(n + 1)[-1]", "+c = fib(n + 1)" ]
false
0.052728
0.041976
1.256153
[ "s933373515", "s249567187" ]
u727717182
p02713
python
s607559181
s808074269
929
509
9,636
67,720
Accepted
Accepted
45.21
from sys import stdin import math from functools import reduce def main(): input = stdin.readline K = int(eval(input())) ans_sum = 0 for i in range(1,K+1): for j in range(i,K+1): for k in range(j,K+1): check = [i,j,k] sum_type = len(set(check)) if sum_type == 1: ans_sum += gcd(i,j,k) elif sum_type == 2: ans_sum += gcd(i,j,k) * 3 else: ans_sum += gcd(i,j,k) * 6 print(ans_sum) def gcd(*numbers): return reduce(math.gcd, numbers) if __name__ == "__main__": main()
import math K = int(eval(input())) ans = 0 for a in range(1,K+1): for b in range(1,K+1): for c in range(1,K+1): ans += math.gcd(math.gcd(a,b),c) print(ans)
34
9
689
183
from sys import stdin import math from functools import reduce def main(): input = stdin.readline K = int(eval(input())) ans_sum = 0 for i in range(1, K + 1): for j in range(i, K + 1): for k in range(j, K + 1): check = [i, j, k] sum_type = len(set(check)) if sum_type == 1: ans_sum += gcd(i, j, k) elif sum_type == 2: ans_sum += gcd(i, j, k) * 3 else: ans_sum += gcd(i, j, k) * 6 print(ans_sum) def gcd(*numbers): return reduce(math.gcd, numbers) if __name__ == "__main__": main()
import math K = int(eval(input())) ans = 0 for a in range(1, K + 1): for b in range(1, K + 1): for c in range(1, K + 1): ans += math.gcd(math.gcd(a, b), c) print(ans)
false
73.529412
[ "-from sys import stdin", "-from functools import reduce", "-", "-def main():", "- input = stdin.readline", "- K = int(eval(input()))", "- ans_sum = 0", "- for i in range(1, K + 1):", "- for j in range(i, K + 1):", "- for k in range(j, K + 1):", "- check = [i, j, k]", "- sum_type = len(set(check))", "- if sum_type == 1:", "- ans_sum += gcd(i, j, k)", "- elif sum_type == 2:", "- ans_sum += gcd(i, j, k) * 3", "- else:", "- ans_sum += gcd(i, j, k) * 6", "- print(ans_sum)", "-", "-", "-def gcd(*numbers):", "- return reduce(math.gcd, numbers)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+K = int(eval(input()))", "+ans = 0", "+for a in range(1, K + 1):", "+ for b in range(1, K + 1):", "+ for c in range(1, K + 1):", "+ ans += math.gcd(math.gcd(a, b), c)", "+print(ans)" ]
false
0.16054
0.041718
3.848186
[ "s607559181", "s808074269" ]
u634079249
p03352
python
s603009630
s543579821
1,333
35
2,940
10,248
Accepted
Accepted
97.37
import sys import os def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = int(sys.stdin.readline().rstrip()) ret = 1 for b in range(1, N): for p in range(2, N//2): if b ** p <= N: ret = max(ret, b ** p) print(ret) if __name__ == '__main__': main()
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() if N == 1: print((1)) exit() b, p = 2, 1 ret = [] while b ** p <= N: if b ** (p + 1) <= N: p += 1 ret.append(b ** p) else: b += 1 p = 1 ret.sort(reverse=True) print((ret[0])) if __name__ == '__main__': main()
20
50
362
1,337
import sys import os def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = int(sys.stdin.readline().rstrip()) ret = 1 for b in range(1, N): for p in range(2, N // 2): if b**p <= N: ret = max(ret, b**p) print(ret) if __name__ == "__main__": main()
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() if N == 1: print((1)) exit() b, p = 2, 1 ret = [] while b**p <= N: if b ** (p + 1) <= N: p += 1 ret.append(b**p) else: b += 1 p = 1 ret.sort(reverse=True) print((ret[0])) if __name__ == "__main__": main()
false
60
[ "-import sys", "-import os", "+import sys, os, math, bisect, itertools, collections, heapq, queue", "+", "+# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall", "+from decimal import Decimal", "+from collections import defaultdict", "+", "+# import fractions", "+sys.setrecursionlimit(10000000)", "+ii = lambda: int(sys.stdin.buffer.readline().rstrip())", "+il = lambda: list(map(int, sys.stdin.buffer.readline().split()))", "+fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))", "+iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]", "+iss = lambda: sys.stdin.buffer.readline().decode().rstrip()", "+sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))", "+isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]", "+lcm = lambda x, y: (x * y) // math.gcd(x, y)", "+# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)", "+MOD = 10**9 + 7", "+MAX = float(\"inf\")", "- N = int(sys.stdin.readline().rstrip())", "- ret = 1", "- for b in range(1, N):", "- for p in range(2, N // 2):", "- if b**p <= N:", "- ret = max(ret, b**p)", "- print(ret)", "+ N = ii()", "+ if N == 1:", "+ print((1))", "+ exit()", "+ b, p = 2, 1", "+ ret = []", "+ while b**p <= N:", "+ if b ** (p + 1) <= N:", "+ p += 1", "+ ret.append(b**p)", "+ else:", "+ b += 1", "+ p = 1", "+ ret.sort(reverse=True)", "+ print((ret[0]))" ]
false
0.665237
0.006788
98.00178
[ "s603009630", "s543579821" ]
u030090262
p03495
python
s877901405
s839834860
221
102
39,344
32,568
Accepted
Accepted
53.85
from collections import Counter N,K=list(map(int,input().split())) a = list(map(int,input().split())) d=Counter(a) d=sorted(list(d.items()),key=lambda x:x[1]) ans=0 for i in range(len(d)-K): ans+=d[i][1] print(ans)
from collections import Counter N,K=list(map(int,input().split())) a = list(map(int,input().split())) d=Counter(a) ans=sum(sorted(list(d.values()),reverse=1)[:K]) print((N-ans))
9
6
218
168
from collections import Counter N, K = list(map(int, input().split())) a = list(map(int, input().split())) d = Counter(a) d = sorted(list(d.items()), key=lambda x: x[1]) ans = 0 for i in range(len(d) - K): ans += d[i][1] print(ans)
from collections import Counter N, K = list(map(int, input().split())) a = list(map(int, input().split())) d = Counter(a) ans = sum(sorted(list(d.values()), reverse=1)[:K]) print((N - ans))
false
33.333333
[ "-d = sorted(list(d.items()), key=lambda x: x[1])", "-ans = 0", "-for i in range(len(d) - K):", "- ans += d[i][1]", "-print(ans)", "+ans = sum(sorted(list(d.values()), reverse=1)[:K])", "+print((N - ans))" ]
false
0.033622
0.042034
0.79989
[ "s877901405", "s839834860" ]
u993435350
p03147
python
s537462678
s465929643
59
19
3,188
3,060
Accepted
Accepted
67.8
N = int(eval(input())) H = list(map(int,input().split())) flowers = [0] * N start = 0 end = 0 con = 0 while flowers != H: for i in range(0,N): if H[i] > flowers[i]: start = i for j in range(i,N): if H[j] == flowers[j]: end = j break else: end = N break for k in range(start,end): flowers[k] += 1 con += 1 start = 0 end = 0 print(con)
N = int(eval(input())) L = list(map(int,input().split())) s = L[0] ans = s for i in range(0,N): if s <= L[i]: ans += L[i] - s s = L[i] print(ans)
34
10
414
157
N = int(eval(input())) H = list(map(int, input().split())) flowers = [0] * N start = 0 end = 0 con = 0 while flowers != H: for i in range(0, N): if H[i] > flowers[i]: start = i for j in range(i, N): if H[j] == flowers[j]: end = j break else: end = N break for k in range(start, end): flowers[k] += 1 con += 1 start = 0 end = 0 print(con)
N = int(eval(input())) L = list(map(int, input().split())) s = L[0] ans = s for i in range(0, N): if s <= L[i]: ans += L[i] - s s = L[i] print(ans)
false
70.588235
[ "-H = list(map(int, input().split()))", "-flowers = [0] * N", "-start = 0", "-end = 0", "-con = 0", "-while flowers != H:", "- for i in range(0, N):", "- if H[i] > flowers[i]:", "- start = i", "- for j in range(i, N):", "- if H[j] == flowers[j]:", "- end = j", "- break", "- else:", "- end = N", "- break", "- for k in range(start, end):", "- flowers[k] += 1", "- con += 1", "- start = 0", "- end = 0", "-print(con)", "+L = list(map(int, input().split()))", "+s = L[0]", "+ans = s", "+for i in range(0, N):", "+ if s <= L[i]:", "+ ans += L[i] - s", "+ s = L[i]", "+print(ans)" ]
false
0.076832
0.036834
2.085917
[ "s537462678", "s465929643" ]
u345389118
p02571
python
s632183244
s537519365
72
65
9,104
9,148
Accepted
Accepted
9.72
S = eval(input()) T = eval(input()) res = 0 for i in range(len(S) - len(T) + 1): tmp = 0 for j in range(len(T)): if S[i+j] == T[j]: tmp += 1 res = max(res, tmp) print((len(T) - res))
S = eval(input()) T = eval(input()) if len(S) == 1: if S == T: print((0)) else: print((1)) else: l = [] for i in range(len(S) - len(T) + 1): A = S[i:i + (len(T))] # print(A) count = 0 for j in range(len(A)): if A[j] == T[j]: count += 1 # print(count) l.append(count) # print(l) if len(l) > 0: a = len(T) - max(l) print(a) else: a = 1 print(a)
12
28
214
517
S = eval(input()) T = eval(input()) res = 0 for i in range(len(S) - len(T) + 1): tmp = 0 for j in range(len(T)): if S[i + j] == T[j]: tmp += 1 res = max(res, tmp) print((len(T) - res))
S = eval(input()) T = eval(input()) if len(S) == 1: if S == T: print((0)) else: print((1)) else: l = [] for i in range(len(S) - len(T) + 1): A = S[i : i + (len(T))] # print(A) count = 0 for j in range(len(A)): if A[j] == T[j]: count += 1 # print(count) l.append(count) # print(l) if len(l) > 0: a = len(T) - max(l) print(a) else: a = 1 print(a)
false
57.142857
[ "-res = 0", "-for i in range(len(S) - len(T) + 1):", "- tmp = 0", "- for j in range(len(T)):", "- if S[i + j] == T[j]:", "- tmp += 1", "- res = max(res, tmp)", "-print((len(T) - res))", "+if len(S) == 1:", "+ if S == T:", "+ print((0))", "+ else:", "+ print((1))", "+else:", "+ l = []", "+ for i in range(len(S) - len(T) + 1):", "+ A = S[i : i + (len(T))]", "+ # print(A)", "+ count = 0", "+ for j in range(len(A)):", "+ if A[j] == T[j]:", "+ count += 1", "+ # print(count)", "+ l.append(count)", "+ # print(l)", "+ if len(l) > 0:", "+ a = len(T) - max(l)", "+ print(a)", "+ else:", "+ a = 1", "+ print(a)" ]
false
0.037487
0.04951
0.757155
[ "s632183244", "s537519365" ]
u427344224
p03713
python
s713634872
s576275340
455
235
18,968
11,032
Accepted
Accepted
48.35
H, W = list(map(int, input().split())) result = [] for h in range(1, H): Sa = W * h remain = H - h h2 = (remain + 1) // 2 Sb1 = W * h2 Sc1 = W * (remain - h2) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) w = (W + 1) // 2 Sb2 = w * remain Sc2 = (W - w) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) for w in range(1, W): Sa = H * w remain = W - w w3 = (remain + 1) // 2 Sb1 = H * w3 Sc1 = H * (remain - w3) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) h = (H + 1) // 2 Sb2 = h * remain Sc2 = (H - h) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) print((min(result)))
H, W = list(map(int, input().split())) result = [] for h in range(1, H//2+1): Sa = W * h remain = H - h h2 = (remain + 1) // 2 Sb1 = W * h2 Sc1 = W * (remain - h2) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) w = (W + 1) // 2 Sb2 = w * remain Sc2 = (W - w) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) for w in range(1, W//2+1): Sa = H * w remain = W - w w3 = (remain + 1) // 2 Sb1 = H * w3 Sc1 = H * (remain - w3) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) h = (H + 1) // 2 Sb2 = h * remain Sc2 = (H - h) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) print((min(result)))
32
32
724
734
H, W = list(map(int, input().split())) result = [] for h in range(1, H): Sa = W * h remain = H - h h2 = (remain + 1) // 2 Sb1 = W * h2 Sc1 = W * (remain - h2) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) w = (W + 1) // 2 Sb2 = w * remain Sc2 = (W - w) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) for w in range(1, W): Sa = H * w remain = W - w w3 = (remain + 1) // 2 Sb1 = H * w3 Sc1 = H * (remain - w3) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) h = (H + 1) // 2 Sb2 = h * remain Sc2 = (H - h) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) print((min(result)))
H, W = list(map(int, input().split())) result = [] for h in range(1, H // 2 + 1): Sa = W * h remain = H - h h2 = (remain + 1) // 2 Sb1 = W * h2 Sc1 = W * (remain - h2) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) w = (W + 1) // 2 Sb2 = w * remain Sc2 = (W - w) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) for w in range(1, W // 2 + 1): Sa = H * w remain = W - w w3 = (remain + 1) // 2 Sb1 = H * w3 Sc1 = H * (remain - w3) result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1)) h = (H + 1) // 2 Sb2 = h * remain Sc2 = (H - h) * remain result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2)) print((min(result)))
false
0
[ "-for h in range(1, H):", "+for h in range(1, H // 2 + 1):", "-for w in range(1, W):", "+for w in range(1, W // 2 + 1):" ]
false
0.896158
0.286843
3.124216
[ "s713634872", "s576275340" ]
u577170763
p02923
python
s209985194
s747794476
199
66
58,224
12,776
Accepted
Accepted
66.83
import sys from math import pi, cos, sqrt from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n = gete(int) h = tuple(geta(int)) ans = 0 cur = 0 for i in range(n - 1): if h[i] >= h[i + 1]: cur += 1 if cur > ans: ans = cur else: cur = 0 print(ans) if __name__ == "__main__": main()
import sys from math import pi, cos, sqrt from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n = gete(int) h = list(geta(int)) h += [10**10] cur = 0 ans, tmp = 0, 0 while cur < n: if h[cur] >= h[cur + 1]: tmp += 1 else: if tmp > ans: ans = tmp tmp = 0 cur += 1 print(ans) if __name__ == "__main__": main()
35
35
628
664
import sys from math import pi, cos, sqrt from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n = gete(int) h = tuple(geta(int)) ans = 0 cur = 0 for i in range(n - 1): if h[i] >= h[i + 1]: cur += 1 if cur > ans: ans = cur else: cur = 0 print(ans) if __name__ == "__main__": main()
import sys from math import pi, cos, sqrt from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n = gete(int) h = list(geta(int)) h += [10**10] cur = 0 ans, tmp = 0, 0 while cur < n: if h[cur] >= h[cur + 1]: tmp += 1 else: if tmp > ans: ans = tmp tmp = 0 cur += 1 print(ans) if __name__ == "__main__": main()
false
0
[ "- h = tuple(geta(int))", "- ans = 0", "+ h = list(geta(int))", "+ h += [10**10]", "- for i in range(n - 1):", "- if h[i] >= h[i + 1]:", "- cur += 1", "- if cur > ans:", "- ans = cur", "+ ans, tmp = 0, 0", "+ while cur < n:", "+ if h[cur] >= h[cur + 1]:", "+ tmp += 1", "- cur = 0", "+ if tmp > ans:", "+ ans = tmp", "+ tmp = 0", "+ cur += 1" ]
false
0.034387
0.037079
0.927408
[ "s209985194", "s747794476" ]
u368780724
p03662
python
s995516323
s319322510
903
808
35,544
34,776
Accepted
Accepted
10.52
from collections import defaultdict def inpl(): return [int(i) for i in input().split()] path = defaultdict(lambda: []) N = int(eval(input())) for _ in range(N-1): a, b = inpl() path[a].append(b) path[b].append(a) inf = float('inf') ctr = 1 now = {1} distF = [inf for _ in range(N+1)] distF[1] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 1 now = {N} distS = [inf for _ in range(N+1)] distS[N] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distS[nb] > distS[na] + 1: distS[nb] = distS[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break D = distF[N] for i in range(1,N+1): if distF[i] == D//2 and distF[i]+distS[i] == D: St = i if distF[i] == D//2 + 1 and distF[i]+distS[i] == D: En = i path[St].remove(En) path[En].remove(St) ctr = 1 now = {1} distF = [inf for _ in range(N+1)] distF[1] = 0 ctr1 = 0 while ctr1 != ctr: ctr1 = ctr for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if 2*ctr > N: print('Fennec') else: print('Snuke')
from collections import defaultdict def inpl(): return [int(i) for i in input().split()] path = defaultdict(lambda: []) N = int(eval(input())) for _ in range(N-1): a, b = inpl() path[a].append(b) path[b].append(a) inf = float('inf') ctr = 1 now = {1} distF = [inf for _ in range(N+1)] distF[1] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 1 now = {N} distS = [inf for _ in range(N+1)] distS[N] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distS[nb] > distS[na] + 1: distS[nb] = distS[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 0 for i in range(1,N+1): if distF[i] <= distS[i]: ctr += 1 if 2*ctr > N: print('Fennec') else: print('Snuke')
66
47
1,553
1,073
from collections import defaultdict def inpl(): return [int(i) for i in input().split()] path = defaultdict(lambda: []) N = int(eval(input())) for _ in range(N - 1): a, b = inpl() path[a].append(b) path[b].append(a) inf = float("inf") ctr = 1 now = {1} distF = [inf for _ in range(N + 1)] distF[1] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 1 now = {N} distS = [inf for _ in range(N + 1)] distS[N] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distS[nb] > distS[na] + 1: distS[nb] = distS[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break D = distF[N] for i in range(1, N + 1): if distF[i] == D // 2 and distF[i] + distS[i] == D: St = i if distF[i] == D // 2 + 1 and distF[i] + distS[i] == D: En = i path[St].remove(En) path[En].remove(St) ctr = 1 now = {1} distF = [inf for _ in range(N + 1)] distF[1] = 0 ctr1 = 0 while ctr1 != ctr: ctr1 = ctr for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if 2 * ctr > N: print("Fennec") else: print("Snuke")
from collections import defaultdict def inpl(): return [int(i) for i in input().split()] path = defaultdict(lambda: []) N = int(eval(input())) for _ in range(N - 1): a, b = inpl() path[a].append(b) path[b].append(a) inf = float("inf") ctr = 1 now = {1} distF = [inf for _ in range(N + 1)] distF[1] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distF[nb] > distF[na] + 1: distF[nb] = distF[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 1 now = {N} distS = [inf for _ in range(N + 1)] distS[N] = 0 while True: for na in now.copy(): na = now.pop() for nb in path[na]: if distS[nb] > distS[na] + 1: distS[nb] = distS[na] + 1 now.add(nb) ctr += 1 if ctr >= N: break ctr = 0 for i in range(1, N + 1): if distF[i] <= distS[i]: ctr += 1 if 2 * ctr > N: print("Fennec") else: print("Snuke")
false
28.787879
[ "-D = distF[N]", "+ctr = 0", "- if distF[i] == D // 2 and distF[i] + distS[i] == D:", "- St = i", "- if distF[i] == D // 2 + 1 and distF[i] + distS[i] == D:", "- En = i", "-path[St].remove(En)", "-path[En].remove(St)", "-ctr = 1", "-now = {1}", "-distF = [inf for _ in range(N + 1)]", "-distF[1] = 0", "-ctr1 = 0", "-while ctr1 != ctr:", "- ctr1 = ctr", "- for na in now.copy():", "- na = now.pop()", "- for nb in path[na]:", "- if distF[nb] > distF[na] + 1:", "- distF[nb] = distF[na] + 1", "- now.add(nb)", "- ctr += 1", "+ if distF[i] <= distS[i]:", "+ ctr += 1" ]
false
0.091896
0.085609
1.073437
[ "s995516323", "s319322510" ]
u706330549
p02754
python
s905585905
s519947502
19
17
3,060
3,060
Accepted
Accepted
10.53
n, a, b = [int(x) for x in input().split()] if a == 0 and b == 0: print("0") elif a >= n: print(n) else: x = n // (a + b) if x == 0: print(a) else: if (n - ((a + b) * x)) >= a: print((a * x + a)) else: print((a * x + (n - (a + b) * x)))
n, a, b = [int(x) for x in input().split()] if a == 0 and b == 0: print("0") elif a >= n: print(n) else: x = n // (a + b) if x == 0: print(a) else: if (n - ((a + b) * x)) >= a: print((a * x + a)) else: print((n - b * x))
15
15
318
300
n, a, b = [int(x) for x in input().split()] if a == 0 and b == 0: print("0") elif a >= n: print(n) else: x = n // (a + b) if x == 0: print(a) else: if (n - ((a + b) * x)) >= a: print((a * x + a)) else: print((a * x + (n - (a + b) * x)))
n, a, b = [int(x) for x in input().split()] if a == 0 and b == 0: print("0") elif a >= n: print(n) else: x = n // (a + b) if x == 0: print(a) else: if (n - ((a + b) * x)) >= a: print((a * x + a)) else: print((n - b * x))
false
0
[ "- print((a * x + (n - (a + b) * x)))", "+ print((n - b * x))" ]
false
0.042877
0.041465
1.034065
[ "s905585905", "s519947502" ]
u497596438
p03681
python
s523609463
s683379842
206
99
41,968
14,816
Accepted
Accepted
51.94
N,M=list(map(int,input().split())) if abs(N-M)>1: print((0)) quit() if abs(N-M)==1: a=1 else: a=2 MOD=10**9+7 def factorials(M):#M!までのリストxと其の逆元のリストyを返すmod INF INF=int(1e9+7) fac=[0]*(M+1) finv=[0]*(M+1) inv=[0]*(M+1) fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,M+1): fac[i]=(fac[i-1]*i)%INF inv[i]=INF-(inv[INF%i]*(INF//i))%INF finv[i]=finv[i-1]*inv[i]%INF return fac,finv def nCr(n,r): INF=int(1e9+7) if n<r or r<0 or n<0 : return 0 return fac[n]*(finv[r]*finv[n-r]%INF)%INF fac,finv=factorials(max(N,M)) print(((a*fac[N]*fac[M])%MOD))
N,M=list(map(int,input().split())) MOD=10**9+7 if abs(N-M)>=2: print((0)) quit() if abs(N-M)==1: a=1 else: a=2 def factorials(M):#M!までのリストxと其の逆元のリストyを返すmod INF INF=int(1e9+7) fac=[0]*(M+1) finv=[0]*(M+1) inv=[0]*(M+1) fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,M+1): fac[i]=(fac[i-1]*i)%INF inv[i]=INF-(inv[INF%i]*(INF//i))%INF finv[i]=finv[i-1]*inv[i]%INF return fac,finv fac,finv=factorials(max(N,M)) print(((a*fac[N]*fac[M])%MOD))
31
24
671
540
N, M = list(map(int, input().split())) if abs(N - M) > 1: print((0)) quit() if abs(N - M) == 1: a = 1 else: a = 2 MOD = 10**9 + 7 def factorials(M): # M!までのリストxと其の逆元のリストyを返すmod INF INF = int(1e9 + 7) fac = [0] * (M + 1) finv = [0] * (M + 1) inv = [0] * (M + 1) fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, M + 1): fac[i] = (fac[i - 1] * i) % INF inv[i] = INF - (inv[INF % i] * (INF // i)) % INF finv[i] = finv[i - 1] * inv[i] % INF return fac, finv def nCr(n, r): INF = int(1e9 + 7) if n < r or r < 0 or n < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % INF) % INF fac, finv = factorials(max(N, M)) print(((a * fac[N] * fac[M]) % MOD))
N, M = list(map(int, input().split())) MOD = 10**9 + 7 if abs(N - M) >= 2: print((0)) quit() if abs(N - M) == 1: a = 1 else: a = 2 def factorials(M): # M!までのリストxと其の逆元のリストyを返すmod INF INF = int(1e9 + 7) fac = [0] * (M + 1) finv = [0] * (M + 1) inv = [0] * (M + 1) fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, M + 1): fac[i] = (fac[i - 1] * i) % INF inv[i] = INF - (inv[INF % i] * (INF // i)) % INF finv[i] = finv[i - 1] * inv[i] % INF return fac, finv fac, finv = factorials(max(N, M)) print(((a * fac[N] * fac[M]) % MOD))
false
22.580645
[ "-if abs(N - M) > 1:", "+MOD = 10**9 + 7", "+if abs(N - M) >= 2:", "-MOD = 10**9 + 7", "-def nCr(n, r):", "- INF = int(1e9 + 7)", "- if n < r or r < 0 or n < 0:", "- return 0", "- return fac[n] * (finv[r] * finv[n - r] % INF) % INF", "-", "-" ]
false
0.04112
0.200348
0.205244
[ "s523609463", "s683379842" ]
u747602774
p02659
python
s401326721
s442955833
27
22
9,880
9,060
Accepted
Accepted
18.52
A,B = input().split() from decimal import Decimal,ROUND_DOWN A = Decimal(A) B = Decimal(B) N = A*B print((N.quantize(Decimal('1'),rounding=ROUND_DOWN)))
A,B = input().split() A = int(A) B = B.replace('.','') B = int(B) print((A*B//100))
6
7
155
91
A, B = input().split() from decimal import Decimal, ROUND_DOWN A = Decimal(A) B = Decimal(B) N = A * B print((N.quantize(Decimal("1"), rounding=ROUND_DOWN)))
A, B = input().split() A = int(A) B = B.replace(".", "") B = int(B) print((A * B // 100))
false
14.285714
[ "-from decimal import Decimal, ROUND_DOWN", "-", "-A = Decimal(A)", "-B = Decimal(B)", "-N = A * B", "-print((N.quantize(Decimal(\"1\"), rounding=ROUND_DOWN)))", "+A = int(A)", "+B = B.replace(\".\", \"\")", "+B = int(B)", "+print((A * B // 100))" ]
false
0.052058
0.046853
1.111082
[ "s401326721", "s442955833" ]
u046187684
p03472
python
s377776590
s709017728
363
229
36,256
27,268
Accepted
Accepted
36.91
from math import ceil from numpy import cumsum def solve(string): n, h, *ab = list(map(int, string.split())) max_a = max(ab[::2]) cnt = 0 b = sorted([b for b in ab[1::2] if b > max_a], reverse=True) if sum(b) < h: cnt = len(b) + ceil((h - sum(b)) / max_a) else: cnt = (cumsum(b) >= h).argmax() + 1 """ for _b in b: cnt += 1 h -= _b if h <= 0: break """ return str(cnt) if __name__ == '__main__': n, m = list(map(int, input().split())) print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
from math import ceil def solve(string): n, h, *ab = list(map(int, string.split())) max_a = max(ab[::2]) b = sorted([b for b in ab[1::2] if b > max_a], reverse=True) if sum(b) < h: cnt = len(b) + ceil((h - sum(b)) / max_a) else: for i, _b in enumerate(b): cnt = i + 1 h -= _b if h <= 0: break return str(cnt) 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
21
660
565
from math import ceil from numpy import cumsum def solve(string): n, h, *ab = list(map(int, string.split())) max_a = max(ab[::2]) cnt = 0 b = sorted([b for b in ab[1::2] if b > max_a], reverse=True) if sum(b) < h: cnt = len(b) + ceil((h - sum(b)) / max_a) else: cnt = (cumsum(b) >= h).argmax() + 1 """ for _b in b: cnt += 1 h -= _b if h <= 0: break """ return str(cnt) if __name__ == "__main__": n, m = list(map(int, input().split())) print( (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) )
from math import ceil def solve(string): n, h, *ab = list(map(int, string.split())) max_a = max(ab[::2]) b = sorted([b for b in ab[1::2] if b > max_a], reverse=True) if sum(b) < h: cnt = len(b) + ceil((h - sum(b)) / max_a) else: for i, _b in enumerate(b): cnt = i + 1 h -= _b if h <= 0: break return str(cnt) 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
22.222222
[ "-from numpy import cumsum", "- cnt = 0", "- cnt = (cumsum(b) >= h).argmax() + 1", "- \"\"\"", "- for _b in b:", "- cnt += 1", "+ for i, _b in enumerate(b):", "+ cnt = i + 1", "- \"\"\"" ]
false
0.42521
0.040333
10.542587
[ "s377776590", "s709017728" ]
u151005508
p03665
python
s184517530
s880658752
185
17
39,408
2,940
Accepted
Accepted
90.81
import math N, P = map(int, input().split()) A = list(map(int, input().split())) odd = list(filter(lambda x:(x % 2 == 1), A)) even = list(filter(lambda x:(x % 2 == 0), A)) #print(odd) #print(even) odd_num = len(odd) even_num = len(even) ans = 0 def comb(n, r ): return math.factorial(n) //\ (math.factorial(r) * math.factorial(n - r)) ans = 0 for o in range(0, odd_num + 1): for e in range(0, even_num + 1): #print(o, e) if P == 0: if o % 2 == 0: #print(o,e, comb(odd_num, o) * comb(even_num, e)) ans += comb(odd_num, o) * comb(even_num, e) else: if o % 2 == 1: ans += comb(odd_num, o) * comb(even_num, e) print(ans)
N, P = list(map(int, input().split())) A = list(map(int, input().split())) if list([x for x in A if (x % 2 == 1)]): print((2 ** (N -1))) else: if P == 0: print((2 ** N)) else: print((0))
32
10
769
214
import math N, P = map(int, input().split()) A = list(map(int, input().split())) odd = list(filter(lambda x: (x % 2 == 1), A)) even = list(filter(lambda x: (x % 2 == 0), A)) # print(odd) # print(even) odd_num = len(odd) even_num = len(even) ans = 0 def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n - r)) ans = 0 for o in range(0, odd_num + 1): for e in range(0, even_num + 1): # print(o, e) if P == 0: if o % 2 == 0: # print(o,e, comb(odd_num, o) * comb(even_num, e)) ans += comb(odd_num, o) * comb(even_num, e) else: if o % 2 == 1: ans += comb(odd_num, o) * comb(even_num, e) print(ans)
N, P = list(map(int, input().split())) A = list(map(int, input().split())) if list([x for x in A if (x % 2 == 1)]): print((2 ** (N - 1))) else: if P == 0: print((2**N)) else: print((0))
false
68.75
[ "-import math", "-", "-N, P = map(int, input().split())", "+N, P = list(map(int, input().split()))", "-odd = list(filter(lambda x: (x % 2 == 1), A))", "-even = list(filter(lambda x: (x % 2 == 0), A))", "-# print(odd)", "-# print(even)", "-odd_num = len(odd)", "-even_num = len(even)", "-ans = 0", "-", "-", "-def comb(n, r):", "- return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))", "-", "-", "-ans = 0", "-for o in range(0, odd_num + 1):", "- for e in range(0, even_num + 1):", "- # print(o, e)", "- if P == 0:", "- if o % 2 == 0:", "- # print(o,e, comb(odd_num, o) * comb(even_num, e))", "- ans += comb(odd_num, o) * comb(even_num, e)", "- else:", "- if o % 2 == 1:", "- ans += comb(odd_num, o) * comb(even_num, e)", "-print(ans)", "+if list([x for x in A if (x % 2 == 1)]):", "+ print((2 ** (N - 1)))", "+else:", "+ if P == 0:", "+ print((2**N))", "+ else:", "+ print((0))" ]
false
0.08294
0.035848
2.313655
[ "s184517530", "s880658752" ]
u200887663
p02754
python
s379256293
s483662257
24
17
3,060
2,940
Accepted
Accepted
29.17
#n=int(input()) n,a,b=list(map(int,input().split())) #l=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] v=n//(a+b) ans=v*a mod=n%(a+b) temp=min(mod,a) ans+=temp print(ans)
#k=int(input()) n,a,b=list(map(int,input().split())) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] total=a+b ans=(n//total)*a print((ans+min(a,n%total)))
12
9
217
199
# n=int(input()) n, a, b = list(map(int, input().split())) # l=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] v = n // (a + b) ans = v * a mod = n % (a + b) temp = min(mod, a) ans += temp print(ans)
# k=int(input()) n, a, b = list(map(int, input().split())) # hl=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] total = a + b ans = (n // total) * a print((ans + min(a, n % total)))
false
25
[ "-# n=int(input())", "+# k=int(input())", "-# l=list(map(int,input().split()))", "+# hl=list(map(int,input().split()))", "-v = n // (a + b)", "-ans = v * a", "-mod = n % (a + b)", "-temp = min(mod, a)", "-ans += temp", "-print(ans)", "+total = a + b", "+ans = (n // total) * a", "+print((ans + min(a, n % total)))" ]
false
0.037752
0.036128
1.044934
[ "s379256293", "s483662257" ]
u497952650
p02793
python
s528114389
s628030308
1,874
1,573
4,084
75,188
Accepted
Accepted
16.06
def gcd(a,b): while b!=0: a,b=b,a%b return a def lcm(a, b): return (a * b)//gcd(a,b) N = int(eval(input())) A = list(map(int,input().split())) lcm_a = 1 for i in A: lcm_a = lcm(lcm_a,i) ans = 0 for i in A: ans +=lcm_a//i print((ans%int(1e9+7)))
N = int(eval(input())) A = list(map(int,input().split())) def gcd(a,b): while b!=0: a,b=b,a%b return a def lcm(a, b): return (a * b)//gcd(a,b) lcm_a = 1 for i in range(N): lcm_a = lcm(lcm_a,A[i]) ans = 0 for i in range(N): ans += lcm_a//A[i] mod = int(1e9+7) print((ans%mod))
21
23
295
331
def gcd(a, b): while b != 0: a, b = b, a % b return a def lcm(a, b): return (a * b) // gcd(a, b) N = int(eval(input())) A = list(map(int, input().split())) lcm_a = 1 for i in A: lcm_a = lcm(lcm_a, i) ans = 0 for i in A: ans += lcm_a // i print((ans % int(1e9 + 7)))
N = int(eval(input())) A = list(map(int, input().split())) def gcd(a, b): while b != 0: a, b = b, a % b return a def lcm(a, b): return (a * b) // gcd(a, b) lcm_a = 1 for i in range(N): lcm_a = lcm(lcm_a, A[i]) ans = 0 for i in range(N): ans += lcm_a // A[i] mod = int(1e9 + 7) print((ans % mod))
false
8.695652
[ "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+", "+", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-for i in A:", "- lcm_a = lcm(lcm_a, i)", "+for i in range(N):", "+ lcm_a = lcm(lcm_a, A[i])", "-for i in A:", "- ans += lcm_a // i", "-print((ans % int(1e9 + 7)))", "+for i in range(N):", "+ ans += lcm_a // A[i]", "+mod = int(1e9 + 7)", "+print((ans % mod))" ]
false
0.105355
0.035567
2.962173
[ "s528114389", "s628030308" ]
u475503988
p02623
python
s886495034
s802199061
842
186
44,616
44,624
Accepted
Accepted
77.91
import numpy as np import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) cumA = np.zeros(N+1, dtype=np.int64) cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum() cumB = np.zeros(M+1, dtype=np.int64) cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum() # print(cumA) # print(cumB) ans = 0 for i in range(N, -1, -1): if cumA[i] > K: continue j = np.searchsorted(cumB, K-cumA[i], side='right') ans = max(ans, i+j-1) print(ans)
import numpy as np import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) cumA = np.zeros(N+1, dtype=np.int64) cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum() cumB = np.zeros(M+1, dtype=np.int64) cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum() # print(cumA) # print(cumB) cumA = cumA[cumA <= K] cumB = cumB[cumB <= K] ans = np.searchsorted(cumA, K - cumB, side='right') - 1 ans += np.arange(len(cumB)) print((ans.max()))
18
17
500
490
import numpy as np import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) cumA = np.zeros(N + 1, dtype=np.int64) cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum() cumB = np.zeros(M + 1, dtype=np.int64) cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum() # print(cumA) # print(cumB) ans = 0 for i in range(N, -1, -1): if cumA[i] > K: continue j = np.searchsorted(cumB, K - cumA[i], side="right") ans = max(ans, i + j - 1) print(ans)
import numpy as np import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) cumA = np.zeros(N + 1, dtype=np.int64) cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum() cumB = np.zeros(M + 1, dtype=np.int64) cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum() # print(cumA) # print(cumB) cumA = cumA[cumA <= K] cumB = cumB[cumB <= K] ans = np.searchsorted(cumA, K - cumB, side="right") - 1 ans += np.arange(len(cumB)) print((ans.max()))
false
5.555556
[ "-ans = 0", "-for i in range(N, -1, -1):", "- if cumA[i] > K:", "- continue", "- j = np.searchsorted(cumB, K - cumA[i], side=\"right\")", "- ans = max(ans, i + j - 1)", "-print(ans)", "+cumA = cumA[cumA <= K]", "+cumB = cumB[cumB <= K]", "+ans = np.searchsorted(cumA, K - cumB, side=\"right\") - 1", "+ans += np.arange(len(cumB))", "+print((ans.max()))" ]
false
0.404396
0.34614
1.168299
[ "s886495034", "s802199061" ]