user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u896847891
p02659
python
s194791598
s215492066
25
22
9,164
9,168
Accepted
Accepted
12
from math import floor a, b = input().split() a = int(a) b = int(float(b)*100+0.0001) print((a*b//100))
a, b = input().split() a = int(a) b = round(float(b)*100) print((a*b//100))
7
5
109
78
from math import floor a, b = input().split() a = int(a) b = int(float(b) * 100 + 0.0001) print((a * b // 100))
a, b = input().split() a = int(a) b = round(float(b) * 100) print((a * b // 100))
false
28.571429
[ "-from math import floor", "-", "-b = int(float(b) * 100 + 0.0001)", "+b = round(float(b) * 100)" ]
false
0.047348
0.048631
0.973607
[ "s194791598", "s215492066" ]
u811841526
p02417
python
s442168678
s001715255
70
40
7,684
6,688
Accepted
Accepted
42.86
from collections import Counter counter = Counter() while True: try: s = eval(input()) for c in s: counter[c.lower()] += 1 except: break for c in range(ord('a'), ord('z')+1): print(('{} : {}'.format(chr(c), counter[chr(c)])))
from collections import Counter import string counter = Counter() while True: try: s = input().lower() counter += Counter(s) except EOFError: break for c in string.ascii_lowercase: count = counter[c] print(f'{c} : {count}')
15
15
283
281
from collections import Counter counter = Counter() while True: try: s = eval(input()) for c in s: counter[c.lower()] += 1 except: break for c in range(ord("a"), ord("z") + 1): print(("{} : {}".format(chr(c), counter[chr(c)])))
from collections import Counter import string counter = Counter() while True: try: s = input().lower() counter += Counter(s) except EOFError: break for c in string.ascii_lowercase: count = counter[c] print(f"{c} : {count}")
false
0
[ "+import string", "- s = eval(input())", "- for c in s:", "- counter[c.lower()] += 1", "- except:", "+ s = input().lower()", "+ counter += Counter(s)", "+ except EOFError:", "-for c in range(ord(\"a\"), ord(\"z\") + 1):", "- print((\"{} : {}\".format(chr(c), counter[chr(c)])))", "+for c in string.ascii_lowercase:", "+ count = counter[c]", "+ print(f\"{c} : {count}\")" ]
false
0.036362
0.041559
0.874961
[ "s442168678", "s001715255" ]
u075012704
p03127
python
s672341646
s057021951
133
78
14,252
20,388
Accepted
Accepted
41.35
N = int(eval(input())) A = sorted(list(map(int, input().split()))) # 最大公約数 def gcd(a, b): while b: a, b = b, a % b return a while len(A) > 1: A.append(gcd(A.pop(), A.pop())) print((A[0]))
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) while len(A) > 1: A.append(gcd(A.pop(), A.pop())) print((A[0]))
15
7
219
147
N = int(eval(input())) A = sorted(list(map(int, input().split()))) # 最大公約数 def gcd(a, b): while b: a, b = b, a % b return a while len(A) > 1: A.append(gcd(A.pop(), A.pop())) print((A[0]))
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) while len(A) > 1: A.append(gcd(A.pop(), A.pop())) print((A[0]))
false
53.333333
[ "+from math import gcd", "+", "-A = sorted(list(map(int, input().split())))", "-# 最大公約数", "-def gcd(a, b):", "- while b:", "- a, b = b, a % b", "- return a", "-", "-", "+A = list(map(int, input().split()))" ]
false
0.007309
0.071687
0.101954
[ "s672341646", "s057021951" ]
u816872429
p03000
python
s482054034
s040715689
181
19
38,384
3,064
Accepted
Accepted
89.5
n, x = list(map(int, input().split())) ls = list(map(int, input().split())) s = 0 c = 1 for l in ls: s += l if s > x: break c += 1 print(c)
n, x = list(map(int, input().split())) d = [0] for l in map(int, input().split()): d.append(d[-1] + l) print((sum(dx <= x for dx in d)))
10
5
163
136
n, x = list(map(int, input().split())) ls = list(map(int, input().split())) s = 0 c = 1 for l in ls: s += l if s > x: break c += 1 print(c)
n, x = list(map(int, input().split())) d = [0] for l in map(int, input().split()): d.append(d[-1] + l) print((sum(dx <= x for dx in d)))
false
50
[ "-ls = list(map(int, input().split()))", "-s = 0", "-c = 1", "-for l in ls:", "- s += l", "- if s > x:", "- break", "- c += 1", "-print(c)", "+d = [0]", "+for l in map(int, input().split()):", "+ d.append(d[-1] + l)", "+print((sum(dx <= x for dx in d)))" ]
false
0.044911
0.042347
1.060551
[ "s482054034", "s040715689" ]
u732412551
p03608
python
s509226972
s273810359
1,716
1,527
4,796
4,796
Accepted
Accepted
11.01
from itertools import permutations import sys input = sys.stdin.readline def main(): N, M, RR = list(map(int, input().split())) R = list(map(int, input().split())) INF = float("inf") T = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = tuple(map(int, input().split())) T[a-1][b-1] = c T[b-1][a-1] = c for k in range(N): for i in range(N): for j in range(N): if T[i][j] > T[i][k]+T[k][j]: T[i][j] = T[i][k]+T[k][j] ans = INF for rs in permutations(R): cost = 0 for i in range(RR-1): cost += T[rs[i]-1][rs[i+1]-1] ans = min(ans, cost) print(ans) if __name__ == "__main__": main()
from itertools import permutations import sys input = sys.stdin.readline def main(): N, M, RR = list(map(int, input().split())) R = list(map(int, input().split())) INF = float("inf") T = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = tuple(map(int, input().split())) T[a-1][b-1] = c T[b-1][a-1] = c for k in range(N): for i in range(N): for j in range(N): if T[i][j] > T[i][k]+T[k][j]: T[i][j] = T[i][k]+T[k][j] print((min(sum(T[rs[i]-1][rs[i+1]-1] for i in range(RR-1)) for rs in permutations(R)))) if __name__ == "__main__": main()
28
22
766
672
from itertools import permutations import sys input = sys.stdin.readline def main(): N, M, RR = list(map(int, input().split())) R = list(map(int, input().split())) INF = float("inf") T = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = tuple(map(int, input().split())) T[a - 1][b - 1] = c T[b - 1][a - 1] = c for k in range(N): for i in range(N): for j in range(N): if T[i][j] > T[i][k] + T[k][j]: T[i][j] = T[i][k] + T[k][j] ans = INF for rs in permutations(R): cost = 0 for i in range(RR - 1): cost += T[rs[i] - 1][rs[i + 1] - 1] ans = min(ans, cost) print(ans) if __name__ == "__main__": main()
from itertools import permutations import sys input = sys.stdin.readline def main(): N, M, RR = list(map(int, input().split())) R = list(map(int, input().split())) INF = float("inf") T = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = tuple(map(int, input().split())) T[a - 1][b - 1] = c T[b - 1][a - 1] = c for k in range(N): for i in range(N): for j in range(N): if T[i][j] > T[i][k] + T[k][j]: T[i][j] = T[i][k] + T[k][j] print( ( min( sum(T[rs[i] - 1][rs[i + 1] - 1] for i in range(RR - 1)) for rs in permutations(R) ) ) ) if __name__ == "__main__": main()
false
21.428571
[ "- ans = INF", "- for rs in permutations(R):", "- cost = 0", "- for i in range(RR - 1):", "- cost += T[rs[i] - 1][rs[i + 1] - 1]", "- ans = min(ans, cost)", "- print(ans)", "+ print(", "+ (", "+ min(", "+ sum(T[rs[i] - 1][rs[i + 1] - 1] for i in range(RR - 1))", "+ for rs in permutations(R)", "+ )", "+ )", "+ )" ]
false
0.043375
0.044065
0.984354
[ "s509226972", "s273810359" ]
u808585569
p02647
python
s827294837
s377149448
631
279
169,096
169,404
Accepted
Accepted
55.78
N, K= list(map(int,input().split())) A = list(map(int,input().split())) a=A[:] for _ in range(K): B=[0]*(N+1) for i in range(N): t = a[i] B[max(i-t,0)] +=1 B[min(i+t+1,N)] -=1 for i in range(N): B[i+1] += B[i] a=B[:N] if min(a)==N: break print((*a))
N, K= list(map(int,input().split())) a = list(map(int,input().split())) #a=A[:] for _ in range(K): B=[0]*(N+1) for i in range(N): t = a[i] B[max(i-t,0)] +=1 B[min(i+t+1,N)] -=1 for i in range(N): B[i+1] += B[i] a=B[:N] if min(a)==N: break print((*a))
15
15
293
294
N, K = list(map(int, input().split())) A = list(map(int, input().split())) a = A[:] for _ in range(K): B = [0] * (N + 1) for i in range(N): t = a[i] B[max(i - t, 0)] += 1 B[min(i + t + 1, N)] -= 1 for i in range(N): B[i + 1] += B[i] a = B[:N] if min(a) == N: break print((*a))
N, K = list(map(int, input().split())) a = list(map(int, input().split())) # a=A[:] for _ in range(K): B = [0] * (N + 1) for i in range(N): t = a[i] B[max(i - t, 0)] += 1 B[min(i + t + 1, N)] -= 1 for i in range(N): B[i + 1] += B[i] a = B[:N] if min(a) == N: break print((*a))
false
0
[ "-A = list(map(int, input().split()))", "-a = A[:]", "+a = list(map(int, input().split()))", "+# a=A[:]" ]
false
0.046031
0.046415
0.991723
[ "s827294837", "s377149448" ]
u440566786
p02948
python
s102334670
s257224018
866
714
96,944
60,380
Accepted
Accepted
17.55
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from heapq import heappop,heappush def resolve(): n,m=list(map(int,input().split())) V=[[] for _ in range(m)] for _ in range(n): a,b=list(map(int,input().split())) if(a>m): continue heappush(V[a-1],-b) ans=0 Q=[] for d in range(m): if(V[d]): heappush(Q,(heappop(V[d]),d)) if(Q): b,a=heappop(Q) ans+=-b if(V[a]): heappush(Q,(heappop(V[a]),a)) print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from heapq import heappop,heappush def resolve(): n,m=list(map(int,input().split())) AB=[None]*n for i in range(n): a,b=list(map(int,input().split())) a-=1 AB[i]=(a,b) AB.sort(reverse=1) Q=[] ans=0 for d in range(m): while(AB and AB[-1][0]<=d): a,b=AB.pop() heappush(Q,-b) if(Q): ans+=heappop(Q) print((-ans)) resolve()
28
26
629
557
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) V = [[] for _ in range(m)] for _ in range(n): a, b = list(map(int, input().split())) if a > m: continue heappush(V[a - 1], -b) ans = 0 Q = [] for d in range(m): if V[d]: heappush(Q, (heappop(V[d]), d)) if Q: b, a = heappop(Q) ans += -b if V[a]: heappush(Q, (heappop(V[a]), a)) print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() from heapq import heappop, heappush def resolve(): n, m = list(map(int, input().split())) AB = [None] * n for i in range(n): a, b = list(map(int, input().split())) a -= 1 AB[i] = (a, b) AB.sort(reverse=1) Q = [] ans = 0 for d in range(m): while AB and AB[-1][0] <= d: a, b = AB.pop() heappush(Q, -b) if Q: ans += heappop(Q) print((-ans)) resolve()
false
7.142857
[ "- V = [[] for _ in range(m)]", "- for _ in range(n):", "+ AB = [None] * n", "+ for i in range(n):", "- if a > m:", "- continue", "- heappush(V[a - 1], -b)", "+ a -= 1", "+ AB[i] = (a, b)", "+ AB.sort(reverse=1)", "+ Q = []", "- Q = []", "- if V[d]:", "- heappush(Q, (heappop(V[d]), d))", "+ while AB and AB[-1][0] <= d:", "+ a, b = AB.pop()", "+ heappush(Q, -b)", "- b, a = heappop(Q)", "- ans += -b", "- if V[a]:", "- heappush(Q, (heappop(V[a]), a))", "- print(ans)", "+ ans += heappop(Q)", "+ print((-ans))" ]
false
0.073419
0.040417
1.816532
[ "s102334670", "s257224018" ]
u996434204
p03147
python
s818338245
s088880906
24
20
3,064
3,064
Accepted
Accepted
16.67
n=int(eval(input())) h=[int(x) for x in input().split()] height=[] result=0 tmp=0 for i in range(max(h)): buf=[] for j in range(n): if h[j] > i: buf.append(1) else: buf.append(0) height.append(buf) for val in height: while(tmp < len(val)): if val[tmp]==0: tmp+=1 else: result+=1 while(tmp<len(val)): if(val[tmp]==0): break tmp+=1; tmp=0 #print(height) print(result)
n=int(eval(input())) h=[int(x) for x in input().split()] buf=[0 for i in range(n)] ans=0 flag=False for i in range(max(h)): for j in range(n): if h[j] >= i+1: flag=True if flag and h[j] <= i: ans+=1 flag=False if flag: ans+=1 flag=False print(ans)
31
20
558
340
n = int(eval(input())) h = [int(x) for x in input().split()] height = [] result = 0 tmp = 0 for i in range(max(h)): buf = [] for j in range(n): if h[j] > i: buf.append(1) else: buf.append(0) height.append(buf) for val in height: while tmp < len(val): if val[tmp] == 0: tmp += 1 else: result += 1 while tmp < len(val): if val[tmp] == 0: break tmp += 1 tmp = 0 # print(height) print(result)
n = int(eval(input())) h = [int(x) for x in input().split()] buf = [0 for i in range(n)] ans = 0 flag = False for i in range(max(h)): for j in range(n): if h[j] >= i + 1: flag = True if flag and h[j] <= i: ans += 1 flag = False if flag: ans += 1 flag = False print(ans)
false
35.483871
[ "-height = []", "-result = 0", "-tmp = 0", "+buf = [0 for i in range(n)]", "+ans = 0", "+flag = False", "- buf = []", "- if h[j] > i:", "- buf.append(1)", "- else:", "- buf.append(0)", "- height.append(buf)", "-for val in height:", "- while tmp < len(val):", "- if val[tmp] == 0:", "- tmp += 1", "- else:", "- result += 1", "- while tmp < len(val):", "- if val[tmp] == 0:", "- break", "- tmp += 1", "- tmp = 0", "-# print(height)", "-print(result)", "+ if h[j] >= i + 1:", "+ flag = True", "+ if flag and h[j] <= i:", "+ ans += 1", "+ flag = False", "+ if flag:", "+ ans += 1", "+ flag = False", "+print(ans)" ]
false
0.038201
0.041825
0.91335
[ "s818338245", "s088880906" ]
u580697892
p03087
python
s874213551
s600640196
845
443
6,100
30,704
Accepted
Accepted
47.57
#coding: utf-8 N, Q = list(map(int, input().split())) S = eval(input()) T = [0] for i in range(N-1): if S[i] == "A" and S[i+1] == "C": T.append(T[i] + 1) else: T.append(T[i]) for j in range(Q): l, r = list(map(int, input().split())) print((T[r-1] - T[l-1]))
# coding: utf-8 n, q = list(map(int, input().split())) s = eval(input()) lr = [list(map(int, input().split())) for _ in range(q)] T = [0] cnt = 0 for i in range(n-1): if s[i] == "A" and s[i+1] == "C": cnt += 1 T.append(cnt) for l, r in lr: print((T[r-1] - T[l-1]))
12
12
280
281
# coding: utf-8 N, Q = list(map(int, input().split())) S = eval(input()) T = [0] for i in range(N - 1): if S[i] == "A" and S[i + 1] == "C": T.append(T[i] + 1) else: T.append(T[i]) for j in range(Q): l, r = list(map(int, input().split())) print((T[r - 1] - T[l - 1]))
# coding: utf-8 n, q = list(map(int, input().split())) s = eval(input()) lr = [list(map(int, input().split())) for _ in range(q)] T = [0] cnt = 0 for i in range(n - 1): if s[i] == "A" and s[i + 1] == "C": cnt += 1 T.append(cnt) for l, r in lr: print((T[r - 1] - T[l - 1]))
false
0
[ "-N, Q = list(map(int, input().split()))", "-S = eval(input())", "+n, q = list(map(int, input().split()))", "+s = eval(input())", "+lr = [list(map(int, input().split())) for _ in range(q)]", "-for i in range(N - 1):", "- if S[i] == \"A\" and S[i + 1] == \"C\":", "- T.append(T[i] + 1)", "- else:", "- T.append(T[i])", "-for j in range(Q):", "- l, r = list(map(int, input().split()))", "+cnt = 0", "+for i in range(n - 1):", "+ if s[i] == \"A\" and s[i + 1] == \"C\":", "+ cnt += 1", "+ T.append(cnt)", "+for l, r in lr:" ]
false
0.058693
0.059328
0.989299
[ "s874213551", "s600640196" ]
u596276291
p03659
python
s581930418
s314119123
166
147
25,320
25,836
Accepted
Accepted
11.45
from collections import defaultdict from itertools import product, groupby from math import pi from collections import deque from bisect import bisect, bisect_left, bisect_right INF = 10 ** 20 def main(): N = int(eval(input())) a_list = list(map(int, input().split())) total = sum(a_list) dp1 = [0] * N dp1[0] = a_list[0] for i in range(1, N): dp1[i] = a_list[i] + dp1[i - 1] ans = INF for i in range(N - 1): ans = min(ans, abs(dp1[i] - (total - dp1[i]))) print(ans) if __name__ == '__main__': main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def main(): N = int(eval(input())) A = list(map(int, input().split())) ans = INF total = sum(A) now = 0 for i in range(N - 1): now += A[i] ans = min(ans, abs((total - now) - now)) print(ans) if __name__ == '__main__': main()
26
38
582
946
from collections import defaultdict from itertools import product, groupby from math import pi from collections import deque from bisect import bisect, bisect_left, bisect_right INF = 10**20 def main(): N = int(eval(input())) a_list = list(map(int, input().split())) total = sum(a_list) dp1 = [0] * N dp1[0] = a_list[0] for i in range(1, N): dp1[i] = a_list[i] + dp1[i - 1] ans = INF for i in range(N - 1): ans = min(ans, abs(dp1[i] - (total - dp1[i]))) print(ans) if __name__ == "__main__": main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def main(): N = int(eval(input())) A = list(map(int, input().split())) ans = INF total = sum(A) now = 0 for i in range(N - 1): now += A[i] ans = min(ans, abs((total - now) - now)) print(ans) if __name__ == "__main__": main()
false
31.578947
[ "-from collections import defaultdict", "-from itertools import product, groupby", "-from math import pi", "+from collections import defaultdict, Counter", "+from itertools import product, groupby, count, permutations, combinations", "+from math import pi, sqrt", "+from string import ascii_lowercase", "+from functools import lru_cache", "+import sys", "-INF = 10**20", "+sys.setrecursionlimit(10000)", "+INF = float(\"inf\")", "+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"", "+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]", "+dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]", "+", "+", "+def inside(y, x, H, W):", "+ return 0 <= y < H and 0 <= x < W", "+", "+", "+def ceil(a, b):", "+ return (a + b - 1) // b", "- a_list = list(map(int, input().split()))", "- total = sum(a_list)", "- dp1 = [0] * N", "- dp1[0] = a_list[0]", "- for i in range(1, N):", "- dp1[i] = a_list[i] + dp1[i - 1]", "+ A = list(map(int, input().split()))", "+ total = sum(A)", "+ now = 0", "- ans = min(ans, abs(dp1[i] - (total - dp1[i])))", "+ now += A[i]", "+ ans = min(ans, abs((total - now) - now))" ]
false
0.065322
0.064314
1.015668
[ "s581930418", "s314119123" ]
u785266893
p02622
python
s960109356
s412172111
65
57
9,416
9,404
Accepted
Accepted
12.31
s = eval(input()) t = eval(input()) count = 0 for i in range(len(s)): if s[i] != t[i]: count += 1 print(count)
s = eval(input()) t = eval(input()) count = 0 for i,j in zip(s,t): if i != j: count += 1 print(count)
8
8
119
110
s = eval(input()) t = eval(input()) count = 0 for i in range(len(s)): if s[i] != t[i]: count += 1 print(count)
s = eval(input()) t = eval(input()) count = 0 for i, j in zip(s, t): if i != j: count += 1 print(count)
false
0
[ "-for i in range(len(s)):", "- if s[i] != t[i]:", "+for i, j in zip(s, t):", "+ if i != j:" ]
false
0.039633
0.047416
0.835869
[ "s960109356", "s412172111" ]
u346812984
p02888
python
s020843851
s260144709
1,478
1,345
3,188
3,188
Accepted
Accepted
9
import bisect import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): ab = L[i] + L[j] idx = bisect.bisect_left(L, ab) ans += max(idx - j - 1, 0) print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): a = L[i] for j in range(i + 1, N): b = L[j] ans += max(bisect_left(L, a + b) - (j + 1), 0) print(ans) if __name__ == "__main__": main()
28
28
509
503
import bisect import sys sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): ab = L[i] + L[j] idx = bisect.bisect_left(L, ab) ans += max(idx - j - 1, 0) print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): a = L[i] for j in range(i + 1, N): b = L[j] ans += max(bisect_left(L, a + b) - (j + 1), 0) print(ans) if __name__ == "__main__": main()
false
0
[ "-import bisect", "+from bisect import bisect_left", "- for i in range(N - 2):", "- for j in range(i + 1, N - 1):", "- ab = L[i] + L[j]", "- idx = bisect.bisect_left(L, ab)", "- ans += max(idx - j - 1, 0)", "+ for i in range(N):", "+ a = L[i]", "+ for j in range(i + 1, N):", "+ b = L[j]", "+ ans += max(bisect_left(L, a + b) - (j + 1), 0)" ]
false
0.066951
0.040517
1.652389
[ "s020843851", "s260144709" ]
u581187895
p02861
python
s323944689
s890062041
371
149
8,180
12,448
Accepted
Accepted
59.84
import math from itertools import permutations N = int(eval(input())) A = [tuple(map(int, input().split())) for _ in range(N)] P = list(permutations(A)) ans = 0 count = 0 for p in P: count += 1 for i in range(1,len(p)): ans += math.sqrt((p[i-1][0]-p[i][0])**2 + (p[i-1][1]-p[i][1])**2) print((ans/count))
import numpy as np N = int(eval(input())) A = [input().split() for _ in range(N)] # sum(A, []) 次元をフラット化 XY = np.array(sum(A, []),np.int64) X = XY[::2] # x部分 Y = XY[1::2] # y部分 # Noneで次元を追加 X[:, None] shap(N,1) dx = X[:,None] - X[None,:] dy = Y[:,None] - Y[None,:] dist_mat = (dx*dx + dy*dy)**.5 ans = dist_mat.sum() / N print(ans)
13
16
332
344
import math from itertools import permutations N = int(eval(input())) A = [tuple(map(int, input().split())) for _ in range(N)] P = list(permutations(A)) ans = 0 count = 0 for p in P: count += 1 for i in range(1, len(p)): ans += math.sqrt((p[i - 1][0] - p[i][0]) ** 2 + (p[i - 1][1] - p[i][1]) ** 2) print((ans / count))
import numpy as np N = int(eval(input())) A = [input().split() for _ in range(N)] # sum(A, []) 次元をフラット化 XY = np.array(sum(A, []), np.int64) X = XY[::2] # x部分 Y = XY[1::2] # y部分 # Noneで次元を追加 X[:, None] shap(N,1) dx = X[:, None] - X[None, :] dy = Y[:, None] - Y[None, :] dist_mat = (dx * dx + dy * dy) ** 0.5 ans = dist_mat.sum() / N print(ans)
false
18.75
[ "-import math", "-from itertools import permutations", "+import numpy as np", "-A = [tuple(map(int, input().split())) for _ in range(N)]", "-P = list(permutations(A))", "-ans = 0", "-count = 0", "-for p in P:", "- count += 1", "- for i in range(1, len(p)):", "- ans += math.sqrt((p[i - 1][0] - p[i][0]) ** 2 + (p[i - 1][1] - p[i][1]) ** 2)", "-print((ans / count))", "+A = [input().split() for _ in range(N)]", "+# sum(A, []) 次元をフラット化", "+XY = np.array(sum(A, []), np.int64)", "+X = XY[::2] # x部分", "+Y = XY[1::2] # y部分", "+# Noneで次元を追加 X[:, None] shap(N,1)", "+dx = X[:, None] - X[None, :]", "+dy = Y[:, None] - Y[None, :]", "+dist_mat = (dx * dx + dy * dy) ** 0.5", "+ans = dist_mat.sum() / N", "+print(ans)" ]
false
0.035423
0.184906
0.191574
[ "s323944689", "s890062041" ]
u281303342
p03944
python
s260708750
s287557740
19
17
3,064
3,064
Accepted
Accepted
10.53
W,H,N = list(map(int,input().split())) X,Y,A = [],[],[] for i in range(N): x,y,a = list(map(int,input().split())) X.append(x) Y.append(y) A.append(a) x0,x1,y0,y1 = 0,W,0,H for i in range(N): if A[i]==1: x0 = max(x0,X[i]) elif A[i]==2: x1 = min(x1,X[i]) elif A[i]==3: y0 = max(y0,Y[i]) else: y1 = min(y1,Y[i]) print((max(0,(x1-x0))*max(0,(y1-y0))))
# python3 (3.4.3) import sys input = sys.stdin.readline # main W,H,N = list(map(int,input().split())) XYA = [list(map(int,input().split())) for _ in range(N)] x_lb,x_ub,y_lb,y_ub = 0,W,0,H for x,y,a in XYA: if a==1: x_lb = max(x_lb,x) elif a==2: x_ub = min(x_ub,x) elif a==3: y_lb = max(y_lb,y) else: y_ub = min(y_ub,y) x = max(0, x_ub - x_lb) y = max(0, y_ub - y_lb) print((x*y))
19
24
416
448
W, H, N = list(map(int, input().split())) X, Y, A = [], [], [] for i in range(N): x, y, a = list(map(int, input().split())) X.append(x) Y.append(y) A.append(a) x0, x1, y0, y1 = 0, W, 0, H for i in range(N): if A[i] == 1: x0 = max(x0, X[i]) elif A[i] == 2: x1 = min(x1, X[i]) elif A[i] == 3: y0 = max(y0, Y[i]) else: y1 = min(y1, Y[i]) print((max(0, (x1 - x0)) * max(0, (y1 - y0))))
# python3 (3.4.3) import sys input = sys.stdin.readline # main W, H, N = list(map(int, input().split())) XYA = [list(map(int, input().split())) for _ in range(N)] x_lb, x_ub, y_lb, y_ub = 0, W, 0, H for x, y, a in XYA: if a == 1: x_lb = max(x_lb, x) elif a == 2: x_ub = min(x_ub, x) elif a == 3: y_lb = max(y_lb, y) else: y_ub = min(y_ub, y) x = max(0, x_ub - x_lb) y = max(0, y_ub - y_lb) print((x * y))
false
20.833333
[ "+# python3 (3.4.3)", "+import sys", "+", "+input = sys.stdin.readline", "+# main", "-X, Y, A = [], [], []", "-for i in range(N):", "- x, y, a = list(map(int, input().split()))", "- X.append(x)", "- Y.append(y)", "- A.append(a)", "-x0, x1, y0, y1 = 0, W, 0, H", "-for i in range(N):", "- if A[i] == 1:", "- x0 = max(x0, X[i])", "- elif A[i] == 2:", "- x1 = min(x1, X[i])", "- elif A[i] == 3:", "- y0 = max(y0, Y[i])", "+XYA = [list(map(int, input().split())) for _ in range(N)]", "+x_lb, x_ub, y_lb, y_ub = 0, W, 0, H", "+for x, y, a in XYA:", "+ if a == 1:", "+ x_lb = max(x_lb, x)", "+ elif a == 2:", "+ x_ub = min(x_ub, x)", "+ elif a == 3:", "+ y_lb = max(y_lb, y)", "- y1 = min(y1, Y[i])", "-print((max(0, (x1 - x0)) * max(0, (y1 - y0))))", "+ y_ub = min(y_ub, y)", "+x = max(0, x_ub - x_lb)", "+y = max(0, y_ub - y_lb)", "+print((x * y))" ]
false
0.038582
0.045601
0.846077
[ "s260708750", "s287557740" ]
u771804983
p03013
python
s512834722
s523630687
206
184
7,668
8,612
Accepted
Accepted
10.68
N,M=list(map(int,input().split())) dp=[0]*(N+3) dp[0]=1 a=[0]*(N+3) for i in range(M): a[int(eval(input()))]=1 mod=10**9+7 for i in range(N+1): if a[i+1] != 1: dp[i+1]+=dp[i] dp[i+1]%=mod if a[i+2] != 1: dp[i+2]+=dp[i] dp[i+2]%=mod print((dp[N]))
N,M=list(map(int,input().split())) a=[int(eval(input())) for i in range(M)] tf=[0]*(N+1) for i in a: tf[i]=1 dp=[0]*(N+1) dp[0]=1 dp[1]=0 if 1 in a else 1 mod=10**9+7 for i in range(2,N+1): if tf[i] == 1: continue else: dp[i]=(dp[i-1]+dp[i-2])%mod print((dp[N]))
17
17
294
294
N, M = list(map(int, input().split())) dp = [0] * (N + 3) dp[0] = 1 a = [0] * (N + 3) for i in range(M): a[int(eval(input()))] = 1 mod = 10**9 + 7 for i in range(N + 1): if a[i + 1] != 1: dp[i + 1] += dp[i] dp[i + 1] %= mod if a[i + 2] != 1: dp[i + 2] += dp[i] dp[i + 2] %= mod print((dp[N]))
N, M = list(map(int, input().split())) a = [int(eval(input())) for i in range(M)] tf = [0] * (N + 1) for i in a: tf[i] = 1 dp = [0] * (N + 1) dp[0] = 1 dp[1] = 0 if 1 in a else 1 mod = 10**9 + 7 for i in range(2, N + 1): if tf[i] == 1: continue else: dp[i] = (dp[i - 1] + dp[i - 2]) % mod print((dp[N]))
false
0
[ "-dp = [0] * (N + 3)", "+a = [int(eval(input())) for i in range(M)]", "+tf = [0] * (N + 1)", "+for i in a:", "+ tf[i] = 1", "+dp = [0] * (N + 1)", "-a = [0] * (N + 3)", "-for i in range(M):", "- a[int(eval(input()))] = 1", "+dp[1] = 0 if 1 in a else 1", "-for i in range(N + 1):", "- if a[i + 1] != 1:", "- dp[i + 1] += dp[i]", "- dp[i + 1] %= mod", "- if a[i + 2] != 1:", "- dp[i + 2] += dp[i]", "- dp[i + 2] %= mod", "+for i in range(2, N + 1):", "+ if tf[i] == 1:", "+ continue", "+ else:", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod" ]
false
0.047537
0.047133
1.008576
[ "s512834722", "s523630687" ]
u498487134
p02899
python
s652405383
s050044131
509
283
74,988
102,188
Accepted
Accepted
44.4
N = int(eval(input())) A = list(map(int,input().split())) B = [[0,0] for _ in range(N)] ans = [0]*N for i in range(N): B[i][0]=A[i] B[i][1]=i+1 B.sort() for i in range(N): ans[i] = B[i][1] print((" ".join(map(str,ans))))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() A=LI() L=[] for i in range(N): L.append([A[i],i]) L.sort() ans=[] for i in range(N): ans.append(L[i][1]+1) print((' '.join(map(str, ans)))) main()
14
23
240
429
N = int(eval(input())) A = list(map(int, input().split())) B = [[0, 0] for _ in range(N)] ans = [0] * N for i in range(N): B[i][0] = A[i] B[i][1] = i + 1 B.sort() for i in range(N): ans[i] = B[i][1] print((" ".join(map(str, ans))))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() A = LI() L = [] for i in range(N): L.append([A[i], i]) L.sort() ans = [] for i in range(N): ans.append(L[i][1] + 1) print((" ".join(map(str, ans)))) main()
false
39.130435
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-B = [[0, 0] for _ in range(N)]", "-ans = [0] * N", "-for i in range(N):", "- B[i][0] = A[i]", "- B[i][1] = i + 1", "-B.sort()", "-for i in range(N):", "- ans[i] = B[i][1]", "-print((\" \".join(map(str, ans))))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N = I()", "+ A = LI()", "+ L = []", "+ for i in range(N):", "+ L.append([A[i], i])", "+ L.sort()", "+ ans = []", "+ for i in range(N):", "+ ans.append(L[i][1] + 1)", "+ print((\" \".join(map(str, ans))))", "+", "+", "+main()" ]
false
0.037715
0.040377
0.934068
[ "s652405383", "s050044131" ]
u022407960
p02272
python
s587660246
s760401451
4,320
3,740
67,748
67,856
Accepted
Accepted
13.43
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def merge(A, left, mid, right): global count L = A[left:mid] + [1e9] R = A[mid:right] + [1e9] i, j = 0, 0 for k in range(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return None def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(int, _input[1].split())) assert array_length == len(array) count = 0 merge_sort(A=array, left=0, right=array_length) print((*array)) print(count)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def merge(A, left, mid, right): global count L = A[left:mid] + [1e9] R = A[mid:right] + [1e9] i, j = 0, 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count += right - left return None def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) return A if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(int, _input[1].split())) assert array_length == len(array) count = 0 print((*merge_sort(A=array, left=0, right=array_length))) print(count)
43
42
898
906
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def merge(A, left, mid, right): global count L = A[left:mid] + [1e9] R = A[mid:right] + [1e9] i, j = 0, 0 for k in range(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return None def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(int, _input[1].split())) assert array_length == len(array) count = 0 merge_sort(A=array, left=0, right=array_length) print((*array)) print(count)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def merge(A, left, mid, right): global count L = A[left:mid] + [1e9] R = A[mid:right] + [1e9] i, j = 0, 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count += right - left return None def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) return A if __name__ == "__main__": _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(int, _input[1].split())) assert array_length == len(array) count = 0 print((*merge_sort(A=array, left=0, right=array_length))) print(count)
false
2.325581
[ "- count += 1", "+ count += right - left", "+ return A", "- merge_sort(A=array, left=0, right=array_length)", "- print((*array))", "+ print((*merge_sort(A=array, left=0, right=array_length)))" ]
false
0.048047
0.165412
0.290465
[ "s587660246", "s760401451" ]
u197955752
p03283
python
s107696943
s177577165
589
333
23,800
22,668
Accepted
Accepted
43.46
import sys input = sys.stdin.readline N, M, Q = [int(x) for x in input().split()] L = [0] * M R = [0] * M p = [0] * Q q = [0] * Q for i in range(M): L[i], R[i] = [int(x) for x in input().split()] for j in range(Q): p[j], q[j] = [int(x) for x in input().split()] train = [[0 for i in range(N + 1)] for _ in range(N + 2)] for i in range(M): # すべての列車について train[L[i]][R[i]] += 1 for col in range(1, N + 1): for row in range(col, 0, -1): train[row][col] += train[row][col - 1] + train[row + 1][col] - train[row + 1][col - 1] for j in range(Q): print((train[p[j]][q[j]]))
# 20-08-06再トライ import sys input = sys.stdin.readline from itertools import accumulate N, M, Q = [int(x) for x in input().split()] train = [[0 for _ in range(N + 1)] for _ in range(N + 1)] for i in range(M): L, R = [int(x) for x in input().split()] train[L][R] += 1 cum = [list(accumulate(train[i])) for i in range(N + 1)] del train cum = list(zip(*cum)) cum = [list(accumulate(cum[j])) for j in range(N + 1)] for _ in range(Q): p, q = [int(x) for x in input().split()] print((cum[q][N] - cum[q][p - 1]))
24
19
620
538
import sys input = sys.stdin.readline N, M, Q = [int(x) for x in input().split()] L = [0] * M R = [0] * M p = [0] * Q q = [0] * Q for i in range(M): L[i], R[i] = [int(x) for x in input().split()] for j in range(Q): p[j], q[j] = [int(x) for x in input().split()] train = [[0 for i in range(N + 1)] for _ in range(N + 2)] for i in range(M): # すべての列車について train[L[i]][R[i]] += 1 for col in range(1, N + 1): for row in range(col, 0, -1): train[row][col] += ( train[row][col - 1] + train[row + 1][col] - train[row + 1][col - 1] ) for j in range(Q): print((train[p[j]][q[j]]))
# 20-08-06再トライ import sys input = sys.stdin.readline from itertools import accumulate N, M, Q = [int(x) for x in input().split()] train = [[0 for _ in range(N + 1)] for _ in range(N + 1)] for i in range(M): L, R = [int(x) for x in input().split()] train[L][R] += 1 cum = [list(accumulate(train[i])) for i in range(N + 1)] del train cum = list(zip(*cum)) cum = [list(accumulate(cum[j])) for j in range(N + 1)] for _ in range(Q): p, q = [int(x) for x in input().split()] print((cum[q][N] - cum[q][p - 1]))
false
20.833333
[ "+# 20-08-06再トライ", "+from itertools import accumulate", "+", "-L = [0] * M", "-R = [0] * M", "-p = [0] * Q", "-q = [0] * Q", "+train = [[0 for _ in range(N + 1)] for _ in range(N + 1)]", "- L[i], R[i] = [int(x) for x in input().split()]", "-for j in range(Q):", "- p[j], q[j] = [int(x) for x in input().split()]", "-train = [[0 for i in range(N + 1)] for _ in range(N + 2)]", "-for i in range(M): # すべての列車について", "- train[L[i]][R[i]] += 1", "-for col in range(1, N + 1):", "- for row in range(col, 0, -1):", "- train[row][col] += (", "- train[row][col - 1] + train[row + 1][col] - train[row + 1][col - 1]", "- )", "-for j in range(Q):", "- print((train[p[j]][q[j]]))", "+ L, R = [int(x) for x in input().split()]", "+ train[L][R] += 1", "+cum = [list(accumulate(train[i])) for i in range(N + 1)]", "+del train", "+cum = list(zip(*cum))", "+cum = [list(accumulate(cum[j])) for j in range(N + 1)]", "+for _ in range(Q):", "+ p, q = [int(x) for x in input().split()]", "+ print((cum[q][N] - cum[q][p - 1]))" ]
false
0.03987
0.03695
1.079008
[ "s107696943", "s177577165" ]
u163703551
p03804
python
s431113981
s698786951
24
18
3,064
3,064
Accepted
Accepted
25
s = eval(input()) l = s.split() N = int(l[0]) M = int(l[1]) A = list() for i in range(N): s = eval(input()) A.append(s) B = list() for j in range(M): s = eval(input()) B.append(s) def g(n, m, a, b, i, j): for k in range(m): for l in range(m): if a[i + k][j + l] != b[k][l]: return False return True def f(N, M, A, B): for i in range(N - M + 1): for j in range(N - M + 1): if g(N, M, A, B, i, j): return 'Yes' return 'No' print((f(N, M, A, B)))
import sys # sys.stdin = open('b1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) N, M = read_int_list() A = [read_str() for i in range(N)] B = [read_str() for j in range(M)] def g(n, m, a, b, i, j): for k in range(m): for l in range(m): if a[i + k][j + l] != b[k][l]: return False return True def f(N, M, A, B): for i in range(0, N - M + 1): for j in range(0, N - M + 1): if g(N, M, A, B, i, j): return 'Yes' return 'No' print((f(N, M, A, B)))
33
42
568
732
s = eval(input()) l = s.split() N = int(l[0]) M = int(l[1]) A = list() for i in range(N): s = eval(input()) A.append(s) B = list() for j in range(M): s = eval(input()) B.append(s) def g(n, m, a, b, i, j): for k in range(m): for l in range(m): if a[i + k][j + l] != b[k][l]: return False return True def f(N, M, A, B): for i in range(N - M + 1): for j in range(N - M + 1): if g(N, M, A, B, i, j): return "Yes" return "No" print((f(N, M, A, B)))
import sys # sys.stdin = open('b1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) N, M = read_int_list() A = [read_str() for i in range(N)] B = [read_str() for j in range(M)] def g(n, m, a, b, i, j): for k in range(m): for l in range(m): if a[i + k][j + l] != b[k][l]: return False return True def f(N, M, A, B): for i in range(0, N - M + 1): for j in range(0, N - M + 1): if g(N, M, A, B, i, j): return "Yes" return "No" print((f(N, M, A, B)))
false
21.428571
[ "-s = eval(input())", "-l = s.split()", "-N = int(l[0])", "-M = int(l[1])", "-A = list()", "-for i in range(N):", "- s = eval(input())", "- A.append(s)", "-B = list()", "-for j in range(M):", "- s = eval(input())", "- B.append(s)", "+import sys", "+", "+# sys.stdin = open('b1.in')", "+def read_int_list():", "+ return list(map(int, input().split()))", "+", "+", "+def read_str_list():", "+ return input().split()", "+", "+", "+def read_int():", "+ return int(eval(input()))", "+", "+", "+def read_str():", "+ return eval(input())", "+", "+", "+N, M = read_int_list()", "+A = [read_str() for i in range(N)]", "+B = [read_str() for j in range(M)]", "- for i in range(N - M + 1):", "- for j in range(N - M + 1):", "+ for i in range(0, N - M + 1):", "+ for j in range(0, N - M + 1):" ]
false
0.036533
0.037409
0.976564
[ "s431113981", "s698786951" ]
u106118504
p02748
python
s281496596
s124171951
348
278
42,624
24,784
Accepted
Accepted
20.11
A, B, M = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(M)] ans = [min(a) + min(b)] for x in X: a_idx, b_index, c = x ans.append(a[a_idx - 1] + b[b_index - 1] - c) print((min(ans)))
a,b,m = list(map(int,input().split())) a_li = list(map(int,input().split())) b_li = list(map(int,input().split())) cost = min(a_li) + min(b_li) for i in range(m): x,y,c = list(map(int,input().split())) price = a_li[x-1] + b_li[y-1] - c if price < cost: cost = price print(cost)
11
10
309
285
A, B, M = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(M)] ans = [min(a) + min(b)] for x in X: a_idx, b_index, c = x ans.append(a[a_idx - 1] + b[b_index - 1] - c) print((min(ans)))
a, b, m = list(map(int, input().split())) a_li = list(map(int, input().split())) b_li = list(map(int, input().split())) cost = min(a_li) + min(b_li) for i in range(m): x, y, c = list(map(int, input().split())) price = a_li[x - 1] + b_li[y - 1] - c if price < cost: cost = price print(cost)
false
9.090909
[ "-A, B, M = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-X = [list(map(int, input().split())) for i in range(M)]", "-ans = [min(a) + min(b)]", "-for x in X:", "- a_idx, b_index, c = x", "- ans.append(a[a_idx - 1] + b[b_index - 1] - c)", "-print((min(ans)))", "+a, b, m = list(map(int, input().split()))", "+a_li = list(map(int, input().split()))", "+b_li = list(map(int, input().split()))", "+cost = min(a_li) + min(b_li)", "+for i in range(m):", "+ x, y, c = list(map(int, input().split()))", "+ price = a_li[x - 1] + b_li[y - 1] - c", "+ if price < cost:", "+ cost = price", "+print(cost)" ]
false
0.066464
0.04091
1.624647
[ "s281496596", "s124171951" ]
u510829608
p02315
python
s761355971
s840995380
1,100
980
26,084
26,848
Accepted
Accepted
10.91
N, W = list(map(int, input().split())) v = [0]* N w = [0]* N dp = [[-1 for i in range(W+1)] for j in range(N+1)] for i in range(N): v[i],w[i] = list(map(int, input().split())) def rec(i,j): if dp[i][j] != -1: return dp[i][j] if i == N: res = 0 elif j < w[i]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-w[i])+v[i]) dp[i][j] = res return dp[i][j] print((rec(0,W)))
N, W = list(map(int, input().split())) v = [0]* N w = [0]* N dp = [[0 for i in range(W+1)] for j in range(N+1)] for k in range(N): v[k], w[k] = list(map(int, input().split())) for i in range(N-1,-1,-1): for j in range(W+1): if j < w[i]: dp[i][j] = dp[i+1][j] else: dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]) print((dp[0][W]))
26
18
476
387
N, W = list(map(int, input().split())) v = [0] * N w = [0] * N dp = [[-1 for i in range(W + 1)] for j in range(N + 1)] for i in range(N): v[i], w[i] = list(map(int, input().split())) def rec(i, j): if dp[i][j] != -1: return dp[i][j] if i == N: res = 0 elif j < w[i]: res = rec(i + 1, j) else: res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) dp[i][j] = res return dp[i][j] print((rec(0, W)))
N, W = list(map(int, input().split())) v = [0] * N w = [0] * N dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for k in range(N): v[k], w[k] = list(map(int, input().split())) for i in range(N - 1, -1, -1): for j in range(W + 1): if j < w[i]: dp[i][j] = dp[i + 1][j] else: dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]) print((dp[0][W]))
false
30.769231
[ "-dp = [[-1 for i in range(W + 1)] for j in range(N + 1)]", "-for i in range(N):", "- v[i], w[i] = list(map(int, input().split()))", "-", "-", "-def rec(i, j):", "- if dp[i][j] != -1:", "- return dp[i][j]", "- if i == N:", "- res = 0", "- elif j < w[i]:", "- res = rec(i + 1, j)", "- else:", "- res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])", "- dp[i][j] = res", "- return dp[i][j]", "-", "-", "-print((rec(0, W)))", "+dp = [[0 for i in range(W + 1)] for j in range(N + 1)]", "+for k in range(N):", "+ v[k], w[k] = list(map(int, input().split()))", "+for i in range(N - 1, -1, -1):", "+ for j in range(W + 1):", "+ if j < w[i]:", "+ dp[i][j] = dp[i + 1][j]", "+ else:", "+ dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])", "+print((dp[0][W]))" ]
false
0.038059
0.042543
0.89459
[ "s761355971", "s840995380" ]
u706929073
p02947
python
s946105472
s919394186
535
473
25,420
10,988
Accepted
Accepted
11.59
n = int(eval(input())) s = [sorted(eval(input())) for _ in range(n)] sorted_s = sorted(s) num = 0 num_same = 1 prev = sorted_s[0] for i in range(1, len(sorted_s)): if prev != sorted_s[i]: num += int(num_same * (num_same - 1) / 2) num_same = 1 prev = sorted_s[i] else: num_same += 1 num += int(num_same * (num_same - 1) / 2) print(num)
n = int(eval(input())) s = ["".join(sorted(list(eval(input())))) for _ in range(n)] s.sort() def num_cmb(a, b): enum = 1 denom = 1 for i in range(b): enum *= (a - i) denom *= (b - i) return enum // denom sum = 0 count = 1 prev = s[0] for s_i in s[1::]: if prev == s_i: count += 1 else: sum += num_cmb(count, 2) count = 1 prev = s_i if 0 < count: sum += num_cmb(count, 2) print(sum)
16
27
379
476
n = int(eval(input())) s = [sorted(eval(input())) for _ in range(n)] sorted_s = sorted(s) num = 0 num_same = 1 prev = sorted_s[0] for i in range(1, len(sorted_s)): if prev != sorted_s[i]: num += int(num_same * (num_same - 1) / 2) num_same = 1 prev = sorted_s[i] else: num_same += 1 num += int(num_same * (num_same - 1) / 2) print(num)
n = int(eval(input())) s = ["".join(sorted(list(eval(input())))) for _ in range(n)] s.sort() def num_cmb(a, b): enum = 1 denom = 1 for i in range(b): enum *= a - i denom *= b - i return enum // denom sum = 0 count = 1 prev = s[0] for s_i in s[1::]: if prev == s_i: count += 1 else: sum += num_cmb(count, 2) count = 1 prev = s_i if 0 < count: sum += num_cmb(count, 2) print(sum)
false
40.740741
[ "-s = [sorted(eval(input())) for _ in range(n)]", "-sorted_s = sorted(s)", "-num = 0", "-num_same = 1", "-prev = sorted_s[0]", "-for i in range(1, len(sorted_s)):", "- if prev != sorted_s[i]:", "- num += int(num_same * (num_same - 1) / 2)", "- num_same = 1", "- prev = sorted_s[i]", "+s = [\"\".join(sorted(list(eval(input())))) for _ in range(n)]", "+s.sort()", "+", "+", "+def num_cmb(a, b):", "+ enum = 1", "+ denom = 1", "+ for i in range(b):", "+ enum *= a - i", "+ denom *= b - i", "+ return enum // denom", "+", "+", "+sum = 0", "+count = 1", "+prev = s[0]", "+for s_i in s[1::]:", "+ if prev == s_i:", "+ count += 1", "- num_same += 1", "-num += int(num_same * (num_same - 1) / 2)", "-print(num)", "+ sum += num_cmb(count, 2)", "+ count = 1", "+ prev = s_i", "+if 0 < count:", "+ sum += num_cmb(count, 2)", "+print(sum)" ]
false
0.037836
0.040456
0.935244
[ "s946105472", "s919394186" ]
u367130284
p03722
python
s381424165
s956879650
756
373
76,504
45,660
Accepted
Accepted
50.66
#import numpy as np #from numpy import* #from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall #from scipy.sparse import csr_matrix from collections import* #defaultdict Counter deque appendleft from fractions import gcd from functools import* #reduce from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate from operator import mul,itemgetter from bisect import* #bisect_left bisect_right from heapq import* #heapify heappop heappushpop from math import factorial,pi from copy import deepcopy import sys sys.setrecursionlimit(10**8) input=sys.stdin.readline #危険!基本オフにしろ! def BELLMANFORD(point,d,n): cost = {node:-float("inf")for node in range(1,n+1)} preference = {node:None for node in range(1,n+1)} #最適路のこと cost[point]= 0 for i in range(n-1): #経路の長さは最大n-1であるため for now,lis in list(d.copy().items()): for nex,c in lis: if cost[nex]<cost[now]+c: cost[nex]=cost[now]+c preference[nex]=now negative=[0]*n #負閉路の長さは最大nであるため for i in range(n): #閉路判定 for now,lis in list(d.copy().items()): for nex,c in lis: if negative[now-1]==1: negative[nex-1]=1 if cost[nex]<cost[now]+c: cost[nex]=cost[now]+c preference[nex]=now negative[now-1]=1 return cost,negative def main(): n,m=list(map(int,input().split())) d=defaultdict(list) for i in range(m): a,b,c=list(map(int,input().split())) d[a].append([b,c]) x,y=(BELLMANFORD(1,d,n)) if y[n-1]>0: print("inf") else: print((x[n])) if __name__ == '__main__': main()
import sys input=sys.stdin.readline #危険!基本オフにしろ! def BELLMANFORD(point,d,n): cost = [-float("inf")for node in range(n+1)] preference = [None for node in range(n+1)] #最適路のこと cost[point]= 0 for i in range(n-1): #経路の長さは最大n-1であるため for now,lis in list(d.items()): for nex,c in lis: if cost[nex]<cost[now]+c: cost[nex]=cost[now]+c preference[nex]=now negative=[0]*n #負閉路の長さは最大nであるため for i in range(n): #閉路判定 for now,lis in list(d.items()): for nex,c in lis: if negative[now-1]==1: negative[nex-1]=1 if cost[nex]<cost[now]+c: cost[nex]=cost[now]+c preference[nex]=now negative[now-1]=1 return cost,negative def main(): n,m=list(map(int,input().split())) d={} for s in range(m): a,b,c=list(map(int,input().split())) if a in d: d[a].append((b,c)) else: d[a]=[(b,c)] x,y=(BELLMANFORD(1,d,n)) if y[n-1]>0: print("inf") else: print((x[n])) if __name__ == '__main__': main()
59
50
1,953
1,352
# import numpy as np # from numpy import* # from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall # from scipy.sparse import csr_matrix from collections import * # defaultdict Counter deque appendleft from fractions import gcd from functools import * # reduce from itertools import * # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate from operator import mul, itemgetter from bisect import * # bisect_left bisect_right from heapq import * # heapify heappop heappushpop from math import factorial, pi from copy import deepcopy import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline # 危険!基本オフにしろ! def BELLMANFORD(point, d, n): cost = {node: -float("inf") for node in range(1, n + 1)} preference = {node: None for node in range(1, n + 1)} # 最適路のこと cost[point] = 0 for i in range(n - 1): # 経路の長さは最大n-1であるため for now, lis in list(d.copy().items()): for nex, c in lis: if cost[nex] < cost[now] + c: cost[nex] = cost[now] + c preference[nex] = now negative = [0] * n # 負閉路の長さは最大nであるため for i in range(n): # 閉路判定 for now, lis in list(d.copy().items()): for nex, c in lis: if negative[now - 1] == 1: negative[nex - 1] = 1 if cost[nex] < cost[now] + c: cost[nex] = cost[now] + c preference[nex] = now negative[now - 1] = 1 return cost, negative def main(): n, m = list(map(int, input().split())) d = defaultdict(list) for i in range(m): a, b, c = list(map(int, input().split())) d[a].append([b, c]) x, y = BELLMANFORD(1, d, n) if y[n - 1] > 0: print("inf") else: print((x[n])) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # 危険!基本オフにしろ! def BELLMANFORD(point, d, n): cost = [-float("inf") for node in range(n + 1)] preference = [None for node in range(n + 1)] # 最適路のこと cost[point] = 0 for i in range(n - 1): # 経路の長さは最大n-1であるため for now, lis in list(d.items()): for nex, c in lis: if cost[nex] < cost[now] + c: cost[nex] = cost[now] + c preference[nex] = now negative = [0] * n # 負閉路の長さは最大nであるため for i in range(n): # 閉路判定 for now, lis in list(d.items()): for nex, c in lis: if negative[now - 1] == 1: negative[nex - 1] = 1 if cost[nex] < cost[now] + c: cost[nex] = cost[now] + c preference[nex] = now negative[now - 1] = 1 return cost, negative def main(): n, m = list(map(int, input().split())) d = {} for s in range(m): a, b, c = list(map(int, input().split())) if a in d: d[a].append((b, c)) else: d[a] = [(b, c)] x, y = BELLMANFORD(1, d, n) if y[n - 1] > 0: print("inf") else: print((x[n])) if __name__ == "__main__": main()
false
15.254237
[ "-# import numpy as np", "-# from numpy import*", "-# from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall", "-# from scipy.sparse import csr_matrix", "-from collections import * # defaultdict Counter deque appendleft", "-from fractions import gcd", "-from functools import * # reduce", "-from itertools import * # permutations(\"AB\",repeat=2) combinations(\"AB\",2) product(\"AB\",2) groupby accumulate", "-from operator import mul, itemgetter", "-from bisect import * # bisect_left bisect_right", "-from heapq import * # heapify heappop heappushpop", "-from math import factorial, pi", "-from copy import deepcopy", "-sys.setrecursionlimit(10**8)", "- cost = {node: -float(\"inf\") for node in range(1, n + 1)}", "- preference = {node: None for node in range(1, n + 1)} # 最適路のこと", "+ cost = [-float(\"inf\") for node in range(n + 1)]", "+ preference = [None for node in range(n + 1)] # 最適路のこと", "- for now, lis in list(d.copy().items()):", "+ for now, lis in list(d.items()):", "- for now, lis in list(d.copy().items()):", "+ for now, lis in list(d.items()):", "- d = defaultdict(list)", "- for i in range(m):", "+ d = {}", "+ for s in range(m):", "- d[a].append([b, c])", "+ if a in d:", "+ d[a].append((b, c))", "+ else:", "+ d[a] = [(b, c)]" ]
false
0.038255
0.112925
0.33876
[ "s381424165", "s956879650" ]
u434329006
p03634
python
s903032114
s555243134
1,426
1,214
51,840
78,052
Accepted
Accepted
14.87
N = int(eval(input())) route = [{} for _ in range(N)] dist = [-1] * N for i in range(N - 1): a, b, d = list(map(int, input().split())) route[a-1][b-1] = d route[b-1][a-1] = d Q, K = list(map(int, input().split())) dist[K-1] = 0 dfs_stack = [K-1] while dfs_stack: s = dfs_stack.pop() for t, t_dist in list(route[s].items()): if dist[t] == -1: dist[t] = dist[s] + t_dist dfs_stack.append(t) for i in range(Q): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 print((dist[x] + dist[y]))
from collections import deque n = int(eval(input())) path = {} for i in range(n-1): a, b, c = list(map(int, input().split())) if not a in list(path.keys()): path[a] = [(b, c)] else: path[a].append((b, c)) if not b in list(path.keys()): path[b] = [(a, c)] else: path[b].append((a, c)) q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] dist = [None]*(n+1) dist[k] = 0 que = deque([(k, 0)]) while len(que) > 0: node, d = que.popleft() dist[node] = d for node_next, d_next in path[node]: if dist[node_next] is None: que.append((node_next, d+d_next)) # print(dist) for x, y in xy: print((dist[x]+dist[y]))
21
31
547
758
N = int(eval(input())) route = [{} for _ in range(N)] dist = [-1] * N for i in range(N - 1): a, b, d = list(map(int, input().split())) route[a - 1][b - 1] = d route[b - 1][a - 1] = d Q, K = list(map(int, input().split())) dist[K - 1] = 0 dfs_stack = [K - 1] while dfs_stack: s = dfs_stack.pop() for t, t_dist in list(route[s].items()): if dist[t] == -1: dist[t] = dist[s] + t_dist dfs_stack.append(t) for i in range(Q): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 print((dist[x] + dist[y]))
from collections import deque n = int(eval(input())) path = {} for i in range(n - 1): a, b, c = list(map(int, input().split())) if not a in list(path.keys()): path[a] = [(b, c)] else: path[a].append((b, c)) if not b in list(path.keys()): path[b] = [(a, c)] else: path[b].append((a, c)) q, k = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(q)] dist = [None] * (n + 1) dist[k] = 0 que = deque([(k, 0)]) while len(que) > 0: node, d = que.popleft() dist[node] = d for node_next, d_next in path[node]: if dist[node_next] is None: que.append((node_next, d + d_next)) # print(dist) for x, y in xy: print((dist[x] + dist[y]))
false
32.258065
[ "-N = int(eval(input()))", "-route = [{} for _ in range(N)]", "-dist = [-1] * N", "-for i in range(N - 1):", "- a, b, d = list(map(int, input().split()))", "- route[a - 1][b - 1] = d", "- route[b - 1][a - 1] = d", "-Q, K = list(map(int, input().split()))", "-dist[K - 1] = 0", "-dfs_stack = [K - 1]", "-while dfs_stack:", "- s = dfs_stack.pop()", "- for t, t_dist in list(route[s].items()):", "- if dist[t] == -1:", "- dist[t] = dist[s] + t_dist", "- dfs_stack.append(t)", "-for i in range(Q):", "- x, y = list(map(int, input().split()))", "- x, y = x - 1, y - 1", "+from collections import deque", "+", "+n = int(eval(input()))", "+path = {}", "+for i in range(n - 1):", "+ a, b, c = list(map(int, input().split()))", "+ if not a in list(path.keys()):", "+ path[a] = [(b, c)]", "+ else:", "+ path[a].append((b, c))", "+ if not b in list(path.keys()):", "+ path[b] = [(a, c)]", "+ else:", "+ path[b].append((a, c))", "+q, k = list(map(int, input().split()))", "+xy = [list(map(int, input().split())) for _ in range(q)]", "+dist = [None] * (n + 1)", "+dist[k] = 0", "+que = deque([(k, 0)])", "+while len(que) > 0:", "+ node, d = que.popleft()", "+ dist[node] = d", "+ for node_next, d_next in path[node]:", "+ if dist[node_next] is None:", "+ que.append((node_next, d + d_next))", "+# print(dist)", "+for x, y in xy:" ]
false
0.073933
0.074106
0.997668
[ "s903032114", "s555243134" ]
u913662443
p02813
python
s436428347
s308154165
134
17
4,728
3,064
Accepted
Accepted
87.31
from itertools import permutations stdin = open(0).read().split('\n') N = int(stdin[0]) P=int("".join(list(stdin[1].split()))) Q=int("".join(list(stdin[2].split()))) l = [] for pp in permutations(list(range(1, N+1))): ll = [] for _p in pp: ll.append(str(_p)) l.append(int("".join(ll))) a = l.index(P) b = l.index(Q) print((abs(a - b)))
def perm(N): if N==0:return 0 a=1 for i in range(1,N+1): a*=i return a def getposi(P): N=len(P) l=list(range(1,N+1)) a = 0 for i,num in enumerate(P): a+=perm(N-i-1)*l.index(num) l.remove(num) return a stdin = open(0).read().split('\n') N = int(stdin[0]) P = list(map(int,stdin[1].split())) Q = list(map(int,stdin[2].split())) a=getposi(P) b=getposi(Q) print((abs(a-b)))
16
25
364
455
from itertools import permutations stdin = open(0).read().split("\n") N = int(stdin[0]) P = int("".join(list(stdin[1].split()))) Q = int("".join(list(stdin[2].split()))) l = [] for pp in permutations(list(range(1, N + 1))): ll = [] for _p in pp: ll.append(str(_p)) l.append(int("".join(ll))) a = l.index(P) b = l.index(Q) print((abs(a - b)))
def perm(N): if N == 0: return 0 a = 1 for i in range(1, N + 1): a *= i return a def getposi(P): N = len(P) l = list(range(1, N + 1)) a = 0 for i, num in enumerate(P): a += perm(N - i - 1) * l.index(num) l.remove(num) return a stdin = open(0).read().split("\n") N = int(stdin[0]) P = list(map(int, stdin[1].split())) Q = list(map(int, stdin[2].split())) a = getposi(P) b = getposi(Q) print((abs(a - b)))
false
36
[ "-from itertools import permutations", "+def perm(N):", "+ if N == 0:", "+ return 0", "+ a = 1", "+ for i in range(1, N + 1):", "+ a *= i", "+ return a", "+", "+", "+def getposi(P):", "+ N = len(P)", "+ l = list(range(1, N + 1))", "+ a = 0", "+ for i, num in enumerate(P):", "+ a += perm(N - i - 1) * l.index(num)", "+ l.remove(num)", "+ return a", "+", "-P = int(\"\".join(list(stdin[1].split())))", "-Q = int(\"\".join(list(stdin[2].split())))", "-l = []", "-for pp in permutations(list(range(1, N + 1))):", "- ll = []", "- for _p in pp:", "- ll.append(str(_p))", "- l.append(int(\"\".join(ll)))", "-a = l.index(P)", "-b = l.index(Q)", "+P = list(map(int, stdin[1].split()))", "+Q = list(map(int, stdin[2].split()))", "+a = getposi(P)", "+b = getposi(Q)" ]
false
0.085156
0.084407
1.008873
[ "s436428347", "s308154165" ]
u969190727
p02744
python
s480983741
s719363921
459
153
56,668
12,976
Accepted
Accepted
66.67
import sys input=lambda: sys.stdin.readline().rstrip() n=int(eval(input())) def f(x): A=[] for _ in range(n): A.append(x%10) x//=10 return A[::-1] def g(X): cur=X[0] ret=-1 for i in range(1,n): if X[i]+1<=cur+1 and X[i]+1<=i: ret=i cur=max(cur,X[i]) return ret Ans=[0] a=f(0) b=g(a) while b>=0: next=0 for i in range(n): if i<b: next+=a[i]*(10**(n-1-i)) elif i==b: next+=(a[i]+1)*(10**(n-1-i)) Ans.append(next) a=f(next) b=g(a) for a in Ans: ans="" for x in f(a): ans+=chr(97+x) print(ans)
import sys input=lambda: sys.stdin.readline().rstrip() n=int(eval(input())) A=[chr(97+int(i)) for i in range(n)] Ans=["a"] if n>=2: for _ in range(n-1): Ans2=[] for a in Ans: s=set() for aa in a: s.add(aa) ss=len(s) for i in range(ss+1): Ans2.append(a+A[i]) Ans=Ans2 Ans.sort() for ans in Ans: print(ans)
43
20
610
374
import sys input = lambda: sys.stdin.readline().rstrip() n = int(eval(input())) def f(x): A = [] for _ in range(n): A.append(x % 10) x //= 10 return A[::-1] def g(X): cur = X[0] ret = -1 for i in range(1, n): if X[i] + 1 <= cur + 1 and X[i] + 1 <= i: ret = i cur = max(cur, X[i]) return ret Ans = [0] a = f(0) b = g(a) while b >= 0: next = 0 for i in range(n): if i < b: next += a[i] * (10 ** (n - 1 - i)) elif i == b: next += (a[i] + 1) * (10 ** (n - 1 - i)) Ans.append(next) a = f(next) b = g(a) for a in Ans: ans = "" for x in f(a): ans += chr(97 + x) print(ans)
import sys input = lambda: sys.stdin.readline().rstrip() n = int(eval(input())) A = [chr(97 + int(i)) for i in range(n)] Ans = ["a"] if n >= 2: for _ in range(n - 1): Ans2 = [] for a in Ans: s = set() for aa in a: s.add(aa) ss = len(s) for i in range(ss + 1): Ans2.append(a + A[i]) Ans = Ans2 Ans.sort() for ans in Ans: print(ans)
false
53.488372
[ "-", "-", "-def f(x):", "- A = []", "- for _ in range(n):", "- A.append(x % 10)", "- x //= 10", "- return A[::-1]", "-", "-", "-def g(X):", "- cur = X[0]", "- ret = -1", "- for i in range(1, n):", "- if X[i] + 1 <= cur + 1 and X[i] + 1 <= i:", "- ret = i", "- cur = max(cur, X[i])", "- return ret", "-", "-", "-Ans = [0]", "-a = f(0)", "-b = g(a)", "-while b >= 0:", "- next = 0", "- for i in range(n):", "- if i < b:", "- next += a[i] * (10 ** (n - 1 - i))", "- elif i == b:", "- next += (a[i] + 1) * (10 ** (n - 1 - i))", "- Ans.append(next)", "- a = f(next)", "- b = g(a)", "-for a in Ans:", "- ans = \"\"", "- for x in f(a):", "- ans += chr(97 + x)", "+A = [chr(97 + int(i)) for i in range(n)]", "+Ans = [\"a\"]", "+if n >= 2:", "+ for _ in range(n - 1):", "+ Ans2 = []", "+ for a in Ans:", "+ s = set()", "+ for aa in a:", "+ s.add(aa)", "+ ss = len(s)", "+ for i in range(ss + 1):", "+ Ans2.append(a + A[i])", "+ Ans = Ans2", "+Ans.sort()", "+for ans in Ans:" ]
false
0.102158
0.058957
1.732748
[ "s480983741", "s719363921" ]
u141610915
p03716
python
s832082719
s095910592
710
273
98,092
113,904
Accepted
Accepted
61.55
import sys import heapq input = sys.stdin.buffer.readline def minus(x): return -x N = int(eval(input())) a = list(map(int, input().split())) dpl = [0] * (N + 1) dpr = [0] * (N + 1) l = a[: N] m = a[N: 2 * N] r = list(map(minus, a[2 * N: ])) heapq.heapify(l) heapq.heapify(r) dpl[0] = sum(l) dpr[0] = sum(r) for i in range(N): heapq.heappush(l, m[i]) dpl[i + 1] = dpl[i] - heapq.heappop(l) + m[i] heapq.heappush(r, -m[-1 - i]) dpr[i + 1] = dpr[i] - heapq.heappop(r) - m[-1 - i] res = -float("inf") for i in range(N + 1): j = N - i res = max(res, dpl[i] + dpr[j]) print(res)
import sys import heapq hpush = heapq.heappush hpop = heapq.heappop input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) h = [] ltable = [0] * (N + 1) for i in range(N): ltable[0] += a[i] hpush(h, a[i]) for i in range(N): hpush(h, a[N + i]) ltable[i + 1] = ltable[i] + a[N + i] - hpop(h) a.reverse() h = [] rtable = [0] * (N + 1) for i in range(N): rtable[0] += a[i] hpush(h, -a[i]) for i in range(N): hpush(h, -a[N + i]) rtable[i + 1] = rtable[i] + a[N + i] + hpop(h) #print(ltable, rtable) res = -10 ** 15 for i in range(N + 1): res = max(res, ltable[i] - rtable[N - i]) print(res)
26
29
605
655
import sys import heapq input = sys.stdin.buffer.readline def minus(x): return -x N = int(eval(input())) a = list(map(int, input().split())) dpl = [0] * (N + 1) dpr = [0] * (N + 1) l = a[:N] m = a[N : 2 * N] r = list(map(minus, a[2 * N :])) heapq.heapify(l) heapq.heapify(r) dpl[0] = sum(l) dpr[0] = sum(r) for i in range(N): heapq.heappush(l, m[i]) dpl[i + 1] = dpl[i] - heapq.heappop(l) + m[i] heapq.heappush(r, -m[-1 - i]) dpr[i + 1] = dpr[i] - heapq.heappop(r) - m[-1 - i] res = -float("inf") for i in range(N + 1): j = N - i res = max(res, dpl[i] + dpr[j]) print(res)
import sys import heapq hpush = heapq.heappush hpop = heapq.heappop input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) h = [] ltable = [0] * (N + 1) for i in range(N): ltable[0] += a[i] hpush(h, a[i]) for i in range(N): hpush(h, a[N + i]) ltable[i + 1] = ltable[i] + a[N + i] - hpop(h) a.reverse() h = [] rtable = [0] * (N + 1) for i in range(N): rtable[0] += a[i] hpush(h, -a[i]) for i in range(N): hpush(h, -a[N + i]) rtable[i + 1] = rtable[i] + a[N + i] + hpop(h) # print(ltable, rtable) res = -(10**15) for i in range(N + 1): res = max(res, ltable[i] - rtable[N - i]) print(res)
false
10.344828
[ "-input = sys.stdin.buffer.readline", "-", "-", "-def minus(x):", "- return -x", "-", "-", "+hpush = heapq.heappush", "+hpop = heapq.heappop", "+input = sys.stdin.readline", "-dpl = [0] * (N + 1)", "-dpr = [0] * (N + 1)", "-l = a[:N]", "-m = a[N : 2 * N]", "-r = list(map(minus, a[2 * N :]))", "-heapq.heapify(l)", "-heapq.heapify(r)", "-dpl[0] = sum(l)", "-dpr[0] = sum(r)", "+h = []", "+ltable = [0] * (N + 1)", "- heapq.heappush(l, m[i])", "- dpl[i + 1] = dpl[i] - heapq.heappop(l) + m[i]", "- heapq.heappush(r, -m[-1 - i])", "- dpr[i + 1] = dpr[i] - heapq.heappop(r) - m[-1 - i]", "-res = -float(\"inf\")", "+ ltable[0] += a[i]", "+ hpush(h, a[i])", "+for i in range(N):", "+ hpush(h, a[N + i])", "+ ltable[i + 1] = ltable[i] + a[N + i] - hpop(h)", "+a.reverse()", "+h = []", "+rtable = [0] * (N + 1)", "+for i in range(N):", "+ rtable[0] += a[i]", "+ hpush(h, -a[i])", "+for i in range(N):", "+ hpush(h, -a[N + i])", "+ rtable[i + 1] = rtable[i] + a[N + i] + hpop(h)", "+# print(ltable, rtable)", "+res = -(10**15)", "- j = N - i", "- res = max(res, dpl[i] + dpr[j])", "+ res = max(res, ltable[i] - rtable[N - i])" ]
false
0.03894
0.085808
0.453799
[ "s832082719", "s095910592" ]
u745087332
p03287
python
s408220349
s067374321
115
91
16,300
17,284
Accepted
Accepted
20.87
# coding:utf-8 def inpl(): return list(map(int, input().split())) N, M = inpl() A = inpl() S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] D = dict() D[0] = 0 for i in range(N): if S[i] in D: D[S[i]] += 1 else: D[S[i]] = 1 ans = 0 for num in D: tmp = D[num] # cmb(x, 2)を計算 ans += tmp * (tmp - 1) // 2 # l, rが等しく(1箱で)分配できるパターンを最後に足す ans += D[0] print(ans)
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和(mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] # 各要素の個数を数える C = Counter(S) ans = 0 for num in C: if C[num] <= 1: continue # C[num]個から2つ選ぶ組み合わせ ans += C[num] * (C[num] - 1) // 2 # 1箱で条件を満たす(Si = 0, l=r)場合を加算 return ans + C[0] N, M = inpl() A = inpl() print((solve(N, M, A)))
31
37
450
634
# coding:utf-8 def inpl(): return list(map(int, input().split())) N, M = inpl() A = inpl() S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] D = dict() D[0] = 0 for i in range(N): if S[i] in D: D[S[i]] += 1 else: D[S[i]] = 1 ans = 0 for num in D: tmp = D[num] # cmb(x, 2)を計算 ans += tmp * (tmp - 1) // 2 # l, rが等しく(1箱で)分配できるパターンを最後に足す ans += D[0] print(ans)
# coding:utf-8 import sys from collections import Counter input = sys.stdin.readline def inpl(): return list(map(int, input().split())) # Counterを使ったD - Candy Distributionの解法 def solve(N, M, A): # 累積和(mod M)を求める S = [0] for i in range(N): S.append((S[-1] + A[i]) % M) del S[0] # 各要素の個数を数える C = Counter(S) ans = 0 for num in C: if C[num] <= 1: continue # C[num]個から2つ選ぶ組み合わせ ans += C[num] * (C[num] - 1) // 2 # 1箱で条件を満たす(Si = 0, l=r)場合を加算 return ans + C[0] N, M = inpl() A = inpl() print((solve(N, M, A)))
false
16.216216
[ "+import sys", "+from collections import Counter", "+", "+input = sys.stdin.readline", "+", "+", "+# Counterを使ったD - Candy Distributionの解法", "+def solve(N, M, A):", "+ # 累積和(mod M)を求める", "+ S = [0]", "+ for i in range(N):", "+ S.append((S[-1] + A[i]) % M)", "+ del S[0]", "+ # 各要素の個数を数える", "+ C = Counter(S)", "+ ans = 0", "+ for num in C:", "+ if C[num] <= 1:", "+ continue", "+ # C[num]個から2つ選ぶ組み合わせ", "+ ans += C[num] * (C[num] - 1) // 2", "+ # 1箱で条件を満たす(Si = 0, l=r)場合を加算", "+ return ans + C[0]", "+", "+", "-S = [0]", "-for i in range(N):", "- S.append((S[-1] + A[i]) % M)", "-del S[0]", "-D = dict()", "-D[0] = 0", "-for i in range(N):", "- if S[i] in D:", "- D[S[i]] += 1", "- else:", "- D[S[i]] = 1", "-ans = 0", "-for num in D:", "- tmp = D[num]", "- # cmb(x, 2)を計算", "- ans += tmp * (tmp - 1) // 2", "-# l, rが等しく(1箱で)分配できるパターンを最後に足す", "-ans += D[0]", "-print(ans)", "+print((solve(N, M, A)))" ]
false
0.085092
0.079439
1.071161
[ "s408220349", "s067374321" ]
u296518383
p02948
python
s386593554
s862011675
1,009
411
74,200
31,656
Accepted
Accepted
59.27
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() #print("AB:", AB) H = [] iab = 0 answer = 0 for i in range(M + 1): while iab <= N - 1 and AB[iab][0] <= i: heapq.heappush(H, -AB[iab][1]) iab += 1 if len(H): answer += heapq.heappop(H) print((-answer))
import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() h = [] index = 0 answer = 0 for i in range(1, M + 1): while index < N: a, b = AB[index] if a == i: heappush(h, -b) index += 1 else: break if h: answer += - heappop(h) print(answer)
18
24
348
430
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() # print("AB:", AB) H = [] iab = 0 answer = 0 for i in range(M + 1): while iab <= N - 1 and AB[iab][0] <= i: heapq.heappush(H, -AB[iab][1]) iab += 1 if len(H): answer += heapq.heappop(H) print((-answer))
import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() h = [] index = 0 answer = 0 for i in range(1, M + 1): while index < N: a, b = AB[index] if a == i: heappush(h, -b) index += 1 else: break if h: answer += -heappop(h) print(answer)
false
25
[ "-import heapq", "+import sys", "+", "+input = sys.stdin.buffer.readline", "+from heapq import heappush, heappop", "-# print(\"AB:\", AB)", "-H = []", "-iab = 0", "+h = []", "+index = 0", "-for i in range(M + 1):", "- while iab <= N - 1 and AB[iab][0] <= i:", "- heapq.heappush(H, -AB[iab][1])", "- iab += 1", "- if len(H):", "- answer += heapq.heappop(H)", "-print((-answer))", "+for i in range(1, M + 1):", "+ while index < N:", "+ a, b = AB[index]", "+ if a == i:", "+ heappush(h, -b)", "+ index += 1", "+ else:", "+ break", "+ if h:", "+ answer += -heappop(h)", "+print(answer)" ]
false
0.14007
0.147587
0.94907
[ "s386593554", "s862011675" ]
u934442292
p03031
python
s687697083
s251886312
49
28
3,064
3,064
Accepted
Accepted
42.86
N, M = list(map(int, input().split())) k = [0] * M s = [0] * M for i in range(M): l = [int(j) for j in input().split()] k[i], s[i] = l[0], l[1:] p = [int(i) for i in input().split()] res = 0 for bit in range(2**N): sw = [0] * N for i in range(N): sw[i] = (bit >> i) & 1 are_shining = True for i in range(M): cnt_on = 0 for j in range(k[i]): if sw[s[i][j]-1] == 1: cnt_on += 1 if cnt_on % 2 != p[i]: are_shining = False if are_shining: res += 1 print(res)
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) k = [None] * M s = [None] * M for i in range(M): line = tuple(map(int, input().split())) k[i], s[i] = line[0], line[1:] p = tuple(map(int, input().split())) ans = 0 for bit in range(2 ** N): light_all = True # on/off on switches sw = [None] * N for i in range(N): if bit & (1 << i): sw[i] = True else: sw[i] = False for i in range(M): n_on = 0 for j in s[i]: n_on += sw[j - 1] if n_on % 2 == p[i]: pass else: light_all = False ans += light_all print(ans) if __name__ == "__main__": main()
25
39
529
869
N, M = list(map(int, input().split())) k = [0] * M s = [0] * M for i in range(M): l = [int(j) for j in input().split()] k[i], s[i] = l[0], l[1:] p = [int(i) for i in input().split()] res = 0 for bit in range(2**N): sw = [0] * N for i in range(N): sw[i] = (bit >> i) & 1 are_shining = True for i in range(M): cnt_on = 0 for j in range(k[i]): if sw[s[i][j] - 1] == 1: cnt_on += 1 if cnt_on % 2 != p[i]: are_shining = False if are_shining: res += 1 print(res)
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) k = [None] * M s = [None] * M for i in range(M): line = tuple(map(int, input().split())) k[i], s[i] = line[0], line[1:] p = tuple(map(int, input().split())) ans = 0 for bit in range(2**N): light_all = True # on/off on switches sw = [None] * N for i in range(N): if bit & (1 << i): sw[i] = True else: sw[i] = False for i in range(M): n_on = 0 for j in s[i]: n_on += sw[j - 1] if n_on % 2 == p[i]: pass else: light_all = False ans += light_all print(ans) if __name__ == "__main__": main()
false
35.897436
[ "-N, M = list(map(int, input().split()))", "-k = [0] * M", "-s = [0] * M", "-for i in range(M):", "- l = [int(j) for j in input().split()]", "- k[i], s[i] = l[0], l[1:]", "-p = [int(i) for i in input().split()]", "-res = 0", "-for bit in range(2**N):", "- sw = [0] * N", "- for i in range(N):", "- sw[i] = (bit >> i) & 1", "- are_shining = True", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ N, M = list(map(int, input().split()))", "+ k = [None] * M", "+ s = [None] * M", "- cnt_on = 0", "- for j in range(k[i]):", "- if sw[s[i][j] - 1] == 1:", "- cnt_on += 1", "- if cnt_on % 2 != p[i]:", "- are_shining = False", "- if are_shining:", "- res += 1", "-print(res)", "+ line = tuple(map(int, input().split()))", "+ k[i], s[i] = line[0], line[1:]", "+ p = tuple(map(int, input().split()))", "+ ans = 0", "+ for bit in range(2**N):", "+ light_all = True", "+ # on/off on switches", "+ sw = [None] * N", "+ for i in range(N):", "+ if bit & (1 << i):", "+ sw[i] = True", "+ else:", "+ sw[i] = False", "+ for i in range(M):", "+ n_on = 0", "+ for j in s[i]:", "+ n_on += sw[j - 1]", "+ if n_on % 2 == p[i]:", "+ pass", "+ else:", "+ light_all = False", "+ ans += light_all", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.040042
0.081393
0.491965
[ "s687697083", "s251886312" ]
u380524497
p02762
python
s458510145
s213560781
669
575
34,240
40,168
Accepted
Accepted
14.05
def main(): import sys buf = sys.stdin.buffer class UnionFind: def __init__(self, size): self.parent = [-1] * size self.rank = [1] * size def get_root(self, node): parent = self.parent[node] if parent == -1: root = node else: root = self.get_root(parent) self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく return root def in_same_group(self, node1, node2): root1 = self.get_root(node1) root2 = self.get_root(node2) return root1 == root2 def unite(self, node1, node2): if self.in_same_group(node1, node2): return main_root = self.get_root(node1) sub_root = self.get_root(node2) if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする main_root, sub_root = sub_root, main_root self.parent[sub_root] = main_root self.rank[main_root] += self.rank[sub_root] n, m, k = list(map(int, buf.readline().split())) uf = UnionFind(n) minus_count = [1] * n def gen(): for num in buf.read().split(): yield int(num) generator = gen() for _ in range(m): a, b = generator.__next__(), generator.__next__() uf.unite(a-1, b-1) minus_count[a-1] += 1 minus_count[b-1] += 1 for i in range(k): a, b = generator.__next__(), generator.__next__() if uf.in_same_group(a-1, b-1): minus_count[a-1] += 1 minus_count[b-1] += 1 result = [] for i in range(n): parent = uf.get_root(i) count = uf.rank[parent] ans = count - minus_count[i] result.append(ans) print((*result)) if __name__ == '__main__': main()
def main(): import sys buf = sys.stdin.buffer class UnionFind: def __init__(self, size): self.parent = [-1] * size self.rank = [1] * size def get_root(self, node): parent = self.parent[node] if parent == -1: root = node else: root = self.get_root(parent) self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく return root def in_same_group(self, node1, node2): root1 = self.get_root(node1) root2 = self.get_root(node2) return root1 == root2 def unite(self, node1, node2): if self.in_same_group(node1, node2): return main_root = self.get_root(node1) sub_root = self.get_root(node2) if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする main_root, sub_root = sub_root, main_root self.parent[sub_root] = main_root self.rank[main_root] += self.rank[sub_root] n, m, k = list(map(int, buf.readline().split())) uf = UnionFind(n) minus_count = [1] * n query = list(map(int, buf.read().split())) follows = query[:2*m] blocks = query[2*m:] for a, b in zip(follows[0::2], follows[1::2]): uf.unite(a-1, b-1) minus_count[a-1] += 1 minus_count[b-1] += 1 for a, b in zip(blocks[0::2], blocks[1::2]): if uf.in_same_group(a-1, b-1): minus_count[a-1] += 1 minus_count[b-1] += 1 result = [uf.rank[uf.get_root(i)] - minus_count[i] for i in range(n)] print((*result)) if __name__ == '__main__': main()
66
58
1,950
1,782
def main(): import sys buf = sys.stdin.buffer class UnionFind: def __init__(self, size): self.parent = [-1] * size self.rank = [1] * size def get_root(self, node): parent = self.parent[node] if parent == -1: root = node else: root = self.get_root(parent) self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく return root def in_same_group(self, node1, node2): root1 = self.get_root(node1) root2 = self.get_root(node2) return root1 == root2 def unite(self, node1, node2): if self.in_same_group(node1, node2): return main_root = self.get_root(node1) sub_root = self.get_root(node2) if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする main_root, sub_root = sub_root, main_root self.parent[sub_root] = main_root self.rank[main_root] += self.rank[sub_root] n, m, k = list(map(int, buf.readline().split())) uf = UnionFind(n) minus_count = [1] * n def gen(): for num in buf.read().split(): yield int(num) generator = gen() for _ in range(m): a, b = generator.__next__(), generator.__next__() uf.unite(a - 1, b - 1) minus_count[a - 1] += 1 minus_count[b - 1] += 1 for i in range(k): a, b = generator.__next__(), generator.__next__() if uf.in_same_group(a - 1, b - 1): minus_count[a - 1] += 1 minus_count[b - 1] += 1 result = [] for i in range(n): parent = uf.get_root(i) count = uf.rank[parent] ans = count - minus_count[i] result.append(ans) print((*result)) if __name__ == "__main__": main()
def main(): import sys buf = sys.stdin.buffer class UnionFind: def __init__(self, size): self.parent = [-1] * size self.rank = [1] * size def get_root(self, node): parent = self.parent[node] if parent == -1: root = node else: root = self.get_root(parent) self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく return root def in_same_group(self, node1, node2): root1 = self.get_root(node1) root2 = self.get_root(node2) return root1 == root2 def unite(self, node1, node2): if self.in_same_group(node1, node2): return main_root = self.get_root(node1) sub_root = self.get_root(node2) if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする main_root, sub_root = sub_root, main_root self.parent[sub_root] = main_root self.rank[main_root] += self.rank[sub_root] n, m, k = list(map(int, buf.readline().split())) uf = UnionFind(n) minus_count = [1] * n query = list(map(int, buf.read().split())) follows = query[: 2 * m] blocks = query[2 * m :] for a, b in zip(follows[0::2], follows[1::2]): uf.unite(a - 1, b - 1) minus_count[a - 1] += 1 minus_count[b - 1] += 1 for a, b in zip(blocks[0::2], blocks[1::2]): if uf.in_same_group(a - 1, b - 1): minus_count[a - 1] += 1 minus_count[b - 1] += 1 result = [uf.rank[uf.get_root(i)] - minus_count[i] for i in range(n)] print((*result)) if __name__ == "__main__": main()
false
12.121212
[ "-", "- def gen():", "- for num in buf.read().split():", "- yield int(num)", "-", "- generator = gen()", "- for _ in range(m):", "- a, b = generator.__next__(), generator.__next__()", "+ query = list(map(int, buf.read().split()))", "+ follows = query[: 2 * m]", "+ blocks = query[2 * m :]", "+ for a, b in zip(follows[0::2], follows[1::2]):", "- for i in range(k):", "- a, b = generator.__next__(), generator.__next__()", "+ for a, b in zip(blocks[0::2], blocks[1::2]):", "- result = []", "- for i in range(n):", "- parent = uf.get_root(i)", "- count = uf.rank[parent]", "- ans = count - minus_count[i]", "- result.append(ans)", "+ result = [uf.rank[uf.get_root(i)] - minus_count[i] for i in range(n)]" ]
false
0.081974
0.049393
1.65963
[ "s458510145", "s213560781" ]
u690536347
p03209
python
s766870137
s699288409
24
17
3,572
3,064
Accepted
Accepted
29.17
from functools import lru_cache @lru_cache() def f(n): if n==0: return 1 return 2*f(n-1)+1 @lru_cache() def g(n): if n==0: return 1 return 2*g(n-1)+3 N, X = list(map(int, input().split())) total = [g(i) for i in range(N+1)] p = [f(i) for i in range(N+1)] ans = 0 def search(x, n): global ans if n==0: if x: ans += 1 return if x==0: return if x > total[n-1] + 2: ans += p[n-1] + 1 search(x-(2 + total[n-1]), n-1) elif x == total[n-1] + 2: ans += p[n-1] + 1 else: search(x-1, n-1) search(X, N) print(ans)
N, X = list(map(int, input().split())) q = [1]*(N+1) p = [1]*(N+1) for i in range(1, N+1): q[i] = 2*q[i-1]+3 p[i] = 2*p[i-1]+1 ans = 0 def search(x, n): global ans if n==0: if x: ans += 1 return if x==0: return a = q[n-1] + 2 b = p[n-1] + 1 if x > a: ans += b search(x-a, n-1) elif x == a: ans += b else: search(x-1, n-1) search(X, N) print(ans)
37
30
661
484
from functools import lru_cache @lru_cache() def f(n): if n == 0: return 1 return 2 * f(n - 1) + 1 @lru_cache() def g(n): if n == 0: return 1 return 2 * g(n - 1) + 3 N, X = list(map(int, input().split())) total = [g(i) for i in range(N + 1)] p = [f(i) for i in range(N + 1)] ans = 0 def search(x, n): global ans if n == 0: if x: ans += 1 return if x == 0: return if x > total[n - 1] + 2: ans += p[n - 1] + 1 search(x - (2 + total[n - 1]), n - 1) elif x == total[n - 1] + 2: ans += p[n - 1] + 1 else: search(x - 1, n - 1) search(X, N) print(ans)
N, X = list(map(int, input().split())) q = [1] * (N + 1) p = [1] * (N + 1) for i in range(1, N + 1): q[i] = 2 * q[i - 1] + 3 p[i] = 2 * p[i - 1] + 1 ans = 0 def search(x, n): global ans if n == 0: if x: ans += 1 return if x == 0: return a = q[n - 1] + 2 b = p[n - 1] + 1 if x > a: ans += b search(x - a, n - 1) elif x == a: ans += b else: search(x - 1, n - 1) search(X, N) print(ans)
false
18.918919
[ "-from functools import lru_cache", "-", "-", "-@lru_cache()", "-def f(n):", "- if n == 0:", "- return 1", "- return 2 * f(n - 1) + 1", "-", "-", "-@lru_cache()", "-def g(n):", "- if n == 0:", "- return 1", "- return 2 * g(n - 1) + 3", "-", "-", "-total = [g(i) for i in range(N + 1)]", "-p = [f(i) for i in range(N + 1)]", "+q = [1] * (N + 1)", "+p = [1] * (N + 1)", "+for i in range(1, N + 1):", "+ q[i] = 2 * q[i - 1] + 3", "+ p[i] = 2 * p[i - 1] + 1", "- if x > total[n - 1] + 2:", "- ans += p[n - 1] + 1", "- search(x - (2 + total[n - 1]), n - 1)", "- elif x == total[n - 1] + 2:", "- ans += p[n - 1] + 1", "+ a = q[n - 1] + 2", "+ b = p[n - 1] + 1", "+ if x > a:", "+ ans += b", "+ search(x - a, n - 1)", "+ elif x == a:", "+ ans += b" ]
false
0.082391
0.061192
1.346425
[ "s766870137", "s699288409" ]
u681444474
p02767
python
s657467493
s919972991
171
21
39,152
3,064
Accepted
Accepted
87.72
# coding: utf-8 N=int(eval(input())) X=list(map(int,input().split())) cost=0 for i in range(N): cost+=(X[i]-1)**2 for i in range(2,101): cost1=0 for j in range(N): cost1+=(X[j]-i)**2 if cost1<cost: cost=cost1 print(cost)
# coding: utf-8 N = int(eval(input())) X = list(map(int,input().split())) judge = float('inf') for i in range(1,101): p = i tmp = 0 for j in range(N): tmp += (X[j]-p)**2 if tmp < judge: judge = tmp ans = tmp print(ans)
14
15
264
276
# coding: utf-8 N = int(eval(input())) X = list(map(int, input().split())) cost = 0 for i in range(N): cost += (X[i] - 1) ** 2 for i in range(2, 101): cost1 = 0 for j in range(N): cost1 += (X[j] - i) ** 2 if cost1 < cost: cost = cost1 print(cost)
# coding: utf-8 N = int(eval(input())) X = list(map(int, input().split())) judge = float("inf") for i in range(1, 101): p = i tmp = 0 for j in range(N): tmp += (X[j] - p) ** 2 if tmp < judge: judge = tmp ans = tmp print(ans)
false
6.666667
[ "-cost = 0", "-for i in range(N):", "- cost += (X[i] - 1) ** 2", "-for i in range(2, 101):", "- cost1 = 0", "+judge = float(\"inf\")", "+for i in range(1, 101):", "+ p = i", "+ tmp = 0", "- cost1 += (X[j] - i) ** 2", "- if cost1 < cost:", "- cost = cost1", "-print(cost)", "+ tmp += (X[j] - p) ** 2", "+ if tmp < judge:", "+ judge = tmp", "+ ans = tmp", "+print(ans)" ]
false
0.144448
0.032359
4.463845
[ "s657467493", "s919972991" ]
u067299340
p00008
python
s451810015
s912704014
170
140
5,496
4,196
Accepted
Accepted
17.65
import sys,itertools k=list(range(10)) for l in sys.stdin:print([sum(x)for x in list(itertools.product(k,k,k,k))].count(int(l)))
import sys def f(s,d,g,c): if d>3:return c for n in range(10): if s+n==g:return c+1 elif s+n>g:return c else:c=f(s+n,d+1,g,c) return c for l in sys.stdin: print(f(0,0,int(l),0))
3
10
122
195
import sys, itertools k = list(range(10)) for l in sys.stdin: print([sum(x) for x in list(itertools.product(k, k, k, k))].count(int(l)))
import sys def f(s, d, g, c): if d > 3: return c for n in range(10): if s + n == g: return c + 1 elif s + n > g: return c else: c = f(s + n, d + 1, g, c) return c for l in sys.stdin: print(f(0, 0, int(l), 0))
false
70
[ "-import sys, itertools", "+import sys", "-k = list(range(10))", "+", "+def f(s, d, g, c):", "+ if d > 3:", "+ return c", "+ for n in range(10):", "+ if s + n == g:", "+ return c + 1", "+ elif s + n > g:", "+ return c", "+ else:", "+ c = f(s + n, d + 1, g, c)", "+ return c", "+", "+", "- print([sum(x) for x in list(itertools.product(k, k, k, k))].count(int(l)))", "+ print(f(0, 0, int(l), 0))" ]
false
0.038138
0.036528
1.04407
[ "s451810015", "s912704014" ]
u941753895
p04030
python
s920584535
s876004316
20
18
2,940
2,940
Accepted
Accepted
10
s=list(eval(input())) a='' for i in s: if i=='0' or i=='1': a+=i else: if len(a)!=0: a=a[:len(a)-1] print(a)
# 入力 s=eval(input()) a='' for x in s: if x=='0': a+='0' elif x=='1': a+='1' else: # 文字列が空でない場合、末尾を削除 if a!='': a=a[:-1] # 出力 print(a)
9
16
128
172
s = list(eval(input())) a = "" for i in s: if i == "0" or i == "1": a += i else: if len(a) != 0: a = a[: len(a) - 1] print(a)
# 入力 s = eval(input()) a = "" for x in s: if x == "0": a += "0" elif x == "1": a += "1" else: # 文字列が空でない場合、末尾を削除 if a != "": a = a[:-1] # 出力 print(a)
false
43.75
[ "-s = list(eval(input()))", "+# 入力", "+s = eval(input())", "-for i in s:", "- if i == \"0\" or i == \"1\":", "- a += i", "+for x in s:", "+ if x == \"0\":", "+ a += \"0\"", "+ elif x == \"1\":", "+ a += \"1\"", "- if len(a) != 0:", "- a = a[: len(a) - 1]", "+ # 文字列が空でない場合、末尾を削除", "+ if a != \"\":", "+ a = a[:-1]", "+# 出力" ]
false
0.045271
0.044342
1.020953
[ "s920584535", "s876004316" ]
u573754721
p02832
python
s637202930
s906026349
100
91
26,268
26,140
Accepted
Accepted
9
n=int(eval(input())) *A,=list(map(int,input().split())) if 1 not in A: print((-1)) exit() c=1 for i in range(n): if c==A[i]: c+=1 print((len(A)-(c-1)))
n=int(eval(input())) A=list(map(int,input().split())) if 1 not in A: print((-1)) exit() bef=1 ans=0 for i in A: if i==bef: bef+=1 else: ans+=1 print(ans)
12
15
178
201
n = int(eval(input())) (*A,) = list(map(int, input().split())) if 1 not in A: print((-1)) exit() c = 1 for i in range(n): if c == A[i]: c += 1 print((len(A) - (c - 1)))
n = int(eval(input())) A = list(map(int, input().split())) if 1 not in A: print((-1)) exit() bef = 1 ans = 0 for i in A: if i == bef: bef += 1 else: ans += 1 print(ans)
false
20
[ "-(*A,) = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "-c = 1", "-for i in range(n):", "- if c == A[i]:", "- c += 1", "-print((len(A) - (c - 1)))", "+bef = 1", "+ans = 0", "+for i in A:", "+ if i == bef:", "+ bef += 1", "+ else:", "+ ans += 1", "+print(ans)" ]
false
0.046386
0.04426
1.048044
[ "s637202930", "s906026349" ]
u761320129
p03714
python
s988546811
s242097207
1,462
346
45,172
37,212
Accepted
Accepted
76.33
import heapq def solve(): n = int(input()) ar = input().split(' ') iar = [int(s) for s in ar] early = iar[:n] mid = iar[n:-n] late = iar[-n:] heapq.heapify(early) tmpsum = sum(early) esums = [tmpsum] for i in range(n): heapq.heappush(early, mid[i]) emin = heapq.heappop(early) tmpsum += (mid[i] - emin) esums.append(tmpsum) #print esums lateinv = [-x for x in late] heapq.heapify(lateinv) tmpsum = sum(lateinv) lsums = [tmpsum] for i in range(1,n+1): heapq.heappush(lateinv, -mid[-i]) lmax = heapq.heappop(lateinv) tmpsum += (-mid[-i] - lmax) lsums.append(tmpsum) #print lsums best = float("-inf") for i in range(n+1): score = esums[i] + lsums[n-i] #print 'i=',i,',n-i=',n-i,',esums[i]=',esums[i],',lsums[n-i]=',lsums[n-i],'score=',score if(best < score) : best = score return best if __name__ == '__main__' : print(solve())
import heapq N = int(eval(input())) src = list(map(int,input().split())) lsum = sum(src[:N]) lmem = [lsum] lq = src[:N][:] heapq.heapify(lq) for a in src[N:2*N]: if a <= lq[0]: lmem.append(lmem[-1]) else: lsum += a - heapq.heappop(lq) heapq.heappush(lq, a) lmem.append(lsum) rq = [-a for a in src[-N:]] rsum = sum(rq) rmem = [rsum] heapq.heapify(rq) for a in reversed(src[N:2*N]): if -a <= rq[0]: rmem.append(rmem[-1]) else: rsum += -a - heapq.heappop(rq) heapq.heappush(rq, -a) rmem.append(rsum) ans = -float('inf') for l,r in zip(lmem, rmem[::-1]): ans = max(ans, l+r) print(ans)
41
32
968
693
import heapq def solve(): n = int(input()) ar = input().split(" ") iar = [int(s) for s in ar] early = iar[:n] mid = iar[n:-n] late = iar[-n:] heapq.heapify(early) tmpsum = sum(early) esums = [tmpsum] for i in range(n): heapq.heappush(early, mid[i]) emin = heapq.heappop(early) tmpsum += mid[i] - emin esums.append(tmpsum) # print esums lateinv = [-x for x in late] heapq.heapify(lateinv) tmpsum = sum(lateinv) lsums = [tmpsum] for i in range(1, n + 1): heapq.heappush(lateinv, -mid[-i]) lmax = heapq.heappop(lateinv) tmpsum += -mid[-i] - lmax lsums.append(tmpsum) # print lsums best = float("-inf") for i in range(n + 1): score = esums[i] + lsums[n - i] # print 'i=',i,',n-i=',n-i,',esums[i]=',esums[i],',lsums[n-i]=',lsums[n-i],'score=',score if best < score: best = score return best if __name__ == "__main__": print(solve())
import heapq N = int(eval(input())) src = list(map(int, input().split())) lsum = sum(src[:N]) lmem = [lsum] lq = src[:N][:] heapq.heapify(lq) for a in src[N : 2 * N]: if a <= lq[0]: lmem.append(lmem[-1]) else: lsum += a - heapq.heappop(lq) heapq.heappush(lq, a) lmem.append(lsum) rq = [-a for a in src[-N:]] rsum = sum(rq) rmem = [rsum] heapq.heapify(rq) for a in reversed(src[N : 2 * N]): if -a <= rq[0]: rmem.append(rmem[-1]) else: rsum += -a - heapq.heappop(rq) heapq.heappush(rq, -a) rmem.append(rsum) ans = -float("inf") for l, r in zip(lmem, rmem[::-1]): ans = max(ans, l + r) print(ans)
false
21.95122
[ "-", "-def solve():", "- n = int(input())", "- ar = input().split(\" \")", "- iar = [int(s) for s in ar]", "- early = iar[:n]", "- mid = iar[n:-n]", "- late = iar[-n:]", "- heapq.heapify(early)", "- tmpsum = sum(early)", "- esums = [tmpsum]", "- for i in range(n):", "- heapq.heappush(early, mid[i])", "- emin = heapq.heappop(early)", "- tmpsum += mid[i] - emin", "- esums.append(tmpsum)", "- # print esums", "- lateinv = [-x for x in late]", "- heapq.heapify(lateinv)", "- tmpsum = sum(lateinv)", "- lsums = [tmpsum]", "- for i in range(1, n + 1):", "- heapq.heappush(lateinv, -mid[-i])", "- lmax = heapq.heappop(lateinv)", "- tmpsum += -mid[-i] - lmax", "- lsums.append(tmpsum)", "- # print lsums", "- best = float(\"-inf\")", "- for i in range(n + 1):", "- score = esums[i] + lsums[n - i]", "- # print 'i=',i,',n-i=',n-i,',esums[i]=',esums[i],',lsums[n-i]=',lsums[n-i],'score=',score", "- if best < score:", "- best = score", "- return best", "-", "-", "-if __name__ == \"__main__\":", "- print(solve())", "+N = int(eval(input()))", "+src = list(map(int, input().split()))", "+lsum = sum(src[:N])", "+lmem = [lsum]", "+lq = src[:N][:]", "+heapq.heapify(lq)", "+for a in src[N : 2 * N]:", "+ if a <= lq[0]:", "+ lmem.append(lmem[-1])", "+ else:", "+ lsum += a - heapq.heappop(lq)", "+ heapq.heappush(lq, a)", "+ lmem.append(lsum)", "+rq = [-a for a in src[-N:]]", "+rsum = sum(rq)", "+rmem = [rsum]", "+heapq.heapify(rq)", "+for a in reversed(src[N : 2 * N]):", "+ if -a <= rq[0]:", "+ rmem.append(rmem[-1])", "+ else:", "+ rsum += -a - heapq.heappop(rq)", "+ heapq.heappush(rq, -a)", "+ rmem.append(rsum)", "+ans = -float(\"inf\")", "+for l, r in zip(lmem, rmem[::-1]):", "+ ans = max(ans, l + r)", "+print(ans)" ]
false
0.035091
0.127918
0.274323
[ "s988546811", "s242097207" ]
u796942881
p03457
python
s946944505
s594316376
223
197
21,080
21,080
Accepted
Accepted
11.66
from sys import stdin input = stdin.readline N = int(eval(input())) txy = [[int(j) for j in input().split()] for i in range(N)] def main(): pt = 0 px = 0 py = 0 flg = False for t, x, y in txy: # 到達 あるいは 通過 if abs(x - px) + abs(y - py) <= t - pt: # 距離と時間の偶奇が一致しない 戻れない if (abs(x - px) + abs(y - py)) % 2 != (t - pt) % 2: break else: pt = t px = x py = y # 到達しない else: break else: # break しなかった 完走 flg = True print(("Yes" if flg else "No")) return main()
from sys import stdin input = stdin.readline N = int(eval(input())) txy = [[int(j) for j in input().split()] for i in range(N)] def main(): pt = 0 px = 0 py = 0 flg = False for t, x, y in txy: d = abs(x - px) + abs(y - py) dt = t - pt # 到達 あるいは 通過 if d <= dt: # 距離と時間の偶奇が一致しない 戻れない if d % 2 != dt % 2: break else: pt = t px = x py = y # 到達しない else: break else: # break しなかった 完走 flg = True print(("Yes" if flg else "No")) return main()
38
40
684
684
from sys import stdin input = stdin.readline N = int(eval(input())) txy = [[int(j) for j in input().split()] for i in range(N)] def main(): pt = 0 px = 0 py = 0 flg = False for t, x, y in txy: # 到達 あるいは 通過 if abs(x - px) + abs(y - py) <= t - pt: # 距離と時間の偶奇が一致しない 戻れない if (abs(x - px) + abs(y - py)) % 2 != (t - pt) % 2: break else: pt = t px = x py = y # 到達しない else: break else: # break しなかった 完走 flg = True print(("Yes" if flg else "No")) return main()
from sys import stdin input = stdin.readline N = int(eval(input())) txy = [[int(j) for j in input().split()] for i in range(N)] def main(): pt = 0 px = 0 py = 0 flg = False for t, x, y in txy: d = abs(x - px) + abs(y - py) dt = t - pt # 到達 あるいは 通過 if d <= dt: # 距離と時間の偶奇が一致しない 戻れない if d % 2 != dt % 2: break else: pt = t px = x py = y # 到達しない else: break else: # break しなかった 完走 flg = True print(("Yes" if flg else "No")) return main()
false
5
[ "+ d = abs(x - px) + abs(y - py)", "+ dt = t - pt", "- if abs(x - px) + abs(y - py) <= t - pt:", "+ if d <= dt:", "- if (abs(x - px) + abs(y - py)) % 2 != (t - pt) % 2:", "+ if d % 2 != dt % 2:" ]
false
0.281672
0.045145
6.239331
[ "s946944505", "s594316376" ]
u952164537
p02887
python
s931288866
s538229622
33
28
3,956
3,956
Accepted
Accepted
15.15
N = int(eval(input())) r = 0 S = '' for s in list(eval(input())): if S != s: r += 1 S = s print(r)
def func(): N = int(eval(input())) r = 0 S = '' for s in list(eval(input())): if S != s: r += 1 S = s return r print((func()))
8
10
113
173
N = int(eval(input())) r = 0 S = "" for s in list(eval(input())): if S != s: r += 1 S = s print(r)
def func(): N = int(eval(input())) r = 0 S = "" for s in list(eval(input())): if S != s: r += 1 S = s return r print((func()))
false
20
[ "-N = int(eval(input()))", "-r = 0", "-S = \"\"", "-for s in list(eval(input())):", "- if S != s:", "- r += 1", "- S = s", "-print(r)", "+def func():", "+ N = int(eval(input()))", "+ r = 0", "+ S = \"\"", "+ for s in list(eval(input())):", "+ if S != s:", "+ r += 1", "+ S = s", "+ return r", "+", "+", "+print((func()))" ]
false
0.070919
0.119557
0.593181
[ "s931288866", "s538229622" ]
u216928054
p02574
python
s299015259
s786829973
870
801
177,876
188,584
Accepted
Accepted
7.93
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def debug(*x): print(*x, file=sys.stderr) def solve(N, AS): num_division = 0 maxAS = max(AS) eratree = [0] * (maxAS + 10) for p in range(2, maxAS + 1): if eratree[p]: continue # p is prime x = p while x <= maxAS: if not eratree[x]: eratree[x] = p x += p from collections import defaultdict count = defaultdict(int) for a in AS: factors = [] while a > 1: d = eratree[a] factors.append(d) a //= d num_division += 1 # debug(": ", factors) for f in set(factors): count[f] += 1 # debug(": num_division", num_division) if any(x == N for x in count.values()): return "not coprime" if any(x >= 2 for x in count.values()): return "setwise coprime" return "pairwise coprime" def main(): # parse input N = int(input()) AS = list(map(int, input().split())) print(solve(N, AS)) # tests T1 = """ 3 3 4 5 """ TEST_T1 = """ >>> as_input(T1) >>> main() pairwise coprime """ T2 = """ 3 6 10 15 """ TEST_T2 = """ >>> as_input(T2) >>> main() setwise coprime """ T3 = """ 3 6 10 16 """ TEST_T3 = """ >>> as_input(T3) >>> main() not coprime """ T4 = """ 3 100000 100001 100003 """ TEST_T4 = """ >>> as_input(T4) >>> main() pairwise coprime """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def debug(*x): print(*x, file=sys.stderr) def solve(N, AS): num_division = 0 maxAS = max(AS) eratree = [0] * (maxAS + 10) for p in range(2, maxAS + 1): if eratree[p]: continue # p is prime eratree[p] = p x = p * p while x <= maxAS: if not eratree[x]: eratree[x] = p x += p from collections import defaultdict count = defaultdict(int) for a in AS: factors = [] while a > 1: d = eratree[a] factors.append(d) a //= d num_division += 1 # debug(": ", factors) for f in set(factors): count[f] += 1 # debug(": num_division", num_division) if any(x == N for x in count.values()): return "not coprime" if any(x >= 2 for x in count.values()): return "setwise coprime" return "pairwise coprime" def main(): # parse input N = int(input()) AS = list(map(int, input().split())) print(solve(N, AS)) # tests T1 = """ 3 3 4 5 """ TEST_T1 = """ >>> as_input(T1) >>> main() pairwise coprime """ T2 = """ 3 6 10 15 """ TEST_T2 = """ >>> as_input(T2) >>> main() setwise coprime """ T3 = """ 3 6 10 16 """ TEST_T3 = """ >>> as_input(T3) >>> main() not coprime """ T4 = """ 3 100000 100001 100003 """ TEST_T4 = """ >>> as_input(T4) >>> main() pairwise coprime """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
122
123
2,215
2,243
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10**9 + 1 # sys.maxsize # float("inf") MOD = 10**9 + 7 def debug(*x): print(*x, file=sys.stderr) def solve(N, AS): num_division = 0 maxAS = max(AS) eratree = [0] * (maxAS + 10) for p in range(2, maxAS + 1): if eratree[p]: continue # p is prime x = p while x <= maxAS: if not eratree[x]: eratree[x] = p x += p from collections import defaultdict count = defaultdict(int) for a in AS: factors = [] while a > 1: d = eratree[a] factors.append(d) a //= d num_division += 1 # debug(": ", factors) for f in set(factors): count[f] += 1 # debug(": num_division", num_division) if any(x == N for x in count.values()): return "not coprime" if any(x >= 2 for x in count.values()): return "setwise coprime" return "pairwise coprime" def main(): # parse input N = int(input()) AS = list(map(int, input().split())) print(solve(N, AS)) # tests T1 = """ 3 3 4 5 """ TEST_T1 = """ >>> as_input(T1) >>> main() pairwise coprime """ T2 = """ 3 6 10 15 """ TEST_T2 = """ >>> as_input(T2) >>> main() setwise coprime """ T3 = """ 3 6 10 16 """ TEST_T3 = """ >>> as_input(T3) >>> main() not coprime """ T4 = """ 3 100000 100001 100003 """ TEST_T4 = """ >>> as_input(T4) >>> main() pairwise coprime """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10**9 + 1 # sys.maxsize # float("inf") MOD = 10**9 + 7 def debug(*x): print(*x, file=sys.stderr) def solve(N, AS): num_division = 0 maxAS = max(AS) eratree = [0] * (maxAS + 10) for p in range(2, maxAS + 1): if eratree[p]: continue # p is prime eratree[p] = p x = p * p while x <= maxAS: if not eratree[x]: eratree[x] = p x += p from collections import defaultdict count = defaultdict(int) for a in AS: factors = [] while a > 1: d = eratree[a] factors.append(d) a //= d num_division += 1 # debug(": ", factors) for f in set(factors): count[f] += 1 # debug(": num_division", num_division) if any(x == N for x in count.values()): return "not coprime" if any(x >= 2 for x in count.values()): return "setwise coprime" return "pairwise coprime" def main(): # parse input N = int(input()) AS = list(map(int, input().split())) print(solve(N, AS)) # tests T1 = """ 3 3 4 5 """ TEST_T1 = """ >>> as_input(T1) >>> main() pairwise coprime """ T2 = """ 3 6 10 15 """ TEST_T2 = """ >>> as_input(T2) >>> main() setwise coprime """ T3 = """ 3 6 10 16 """ TEST_T3 = """ >>> as_input(T3) >>> main() not coprime """ T4 = """ 3 100000 100001 100003 """ TEST_T4 = """ >>> as_input(T4) >>> main() pairwise coprime """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
false
0.813008
[ "- x = p", "+ eratree[p] = p", "+ x = p * p" ]
false
0.106395
0.036935
2.880608
[ "s299015259", "s786829973" ]
u729133443
p03697
python
s797054614
s952990179
161
17
38,256
2,940
Accepted
Accepted
89.44
a,b=list(map(int,input().split()));print(([a+b,'error'][(a+b)//10]))
v=sum(map(ord,eval(input())))&31;print(('error'*(9<v)or v))
1
1
60
51
a, b = list(map(int, input().split())) print(([a + b, "error"][(a + b) // 10]))
v = sum(map(ord, eval(input()))) & 31 print(("error" * (9 < v) or v))
false
0
[ "-a, b = list(map(int, input().split()))", "-print(([a + b, \"error\"][(a + b) // 10]))", "+v = sum(map(ord, eval(input()))) & 31", "+print((\"error\" * (9 < v) or v))" ]
false
0.036486
0.036779
0.992051
[ "s797054614", "s952990179" ]
u994988729
p03835
python
s097602529
s508979358
1,955
150
3,060
12,872
Accepted
Accepted
92.33
k, s=list(map(int, input().split())) ans=0 for x in range(0, k+1): if x>s: break for y in range(0, k+1): if x+y>s: break z=s-x-y if 0<=z and z<=k: ans+=1 continue print(ans)
import numpy as np K, S = list(map(int, input().split())) fft_len = 1 << (K * 3).bit_length() x = np.ones(K + 1) Fx = np.fft.rfft(x, fft_len) Fx3 = Fx * Fx * Fx conv = np.fft.irfft(Fx3, fft_len) ans = conv[S] ans = int(ans + 0.5) print(ans)
14
13
257
250
k, s = list(map(int, input().split())) ans = 0 for x in range(0, k + 1): if x > s: break for y in range(0, k + 1): if x + y > s: break z = s - x - y if 0 <= z and z <= k: ans += 1 continue print(ans)
import numpy as np K, S = list(map(int, input().split())) fft_len = 1 << (K * 3).bit_length() x = np.ones(K + 1) Fx = np.fft.rfft(x, fft_len) Fx3 = Fx * Fx * Fx conv = np.fft.irfft(Fx3, fft_len) ans = conv[S] ans = int(ans + 0.5) print(ans)
false
7.142857
[ "-k, s = list(map(int, input().split()))", "-ans = 0", "-for x in range(0, k + 1):", "- if x > s:", "- break", "- for y in range(0, k + 1):", "- if x + y > s:", "- break", "- z = s - x - y", "- if 0 <= z and z <= k:", "- ans += 1", "- continue", "+import numpy as np", "+", "+K, S = list(map(int, input().split()))", "+fft_len = 1 << (K * 3).bit_length()", "+x = np.ones(K + 1)", "+Fx = np.fft.rfft(x, fft_len)", "+Fx3 = Fx * Fx * Fx", "+conv = np.fft.irfft(Fx3, fft_len)", "+ans = conv[S]", "+ans = int(ans + 0.5)" ]
false
0.035236
0.170613
0.206526
[ "s097602529", "s508979358" ]
u638902622
p02708
python
s836200904
s170309962
113
79
39,760
39,628
Accepted
Accepted
30.09
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x-1 for x in MII()]) ## dp INIT_VAL = 0 DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)] DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)] from itertools import accumulate as acc MOD = 10**9+7 def main(): n, k = MII() cnt = 0 dd = [i for i in range(n+1)] # print(dd) dd_a = [0] for i in range(n+1): d = dd_a[i] + dd[i] dd_a.append(d) # print(dd_a) dd_b = [0] dd_r = dd[::-1] for i in range(n+1): d = dd_b[i] + dd_r[i] dd_b.append(d) # print(dd_b) for i in range(k,len(dd_a)): cnt += dd_b[i]-(dd_a[i]-1) print((cnt%MOD)) if __name__ == '__main__': main()
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x-1 for x in MII()]) ## dp INIT_VAL = 0 DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)] DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)] from itertools import accumulate as acc MOD = 10**9+7 def main(): n, k = MII() cnt = 0 dd = [i for i in range(n+1)] dd_a = list(acc(dd)) dd_b = list(acc(dd[::-1])) for i in range(k-1,len(dd_a)): cnt += dd_b[i]-(dd_a[i]-1) print((cnt%MOD)) if __name__ == '__main__': main()
35
25
874
666
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x - 1 for x in MII()]) ## dp INIT_VAL = 0 DP2 = lambda d1, d2: [[INIT_VAL] * d2 for _ in range(d1)] DP3 = lambda d1, d2, d3: [[[INIT_VAL] * d3 for _ in range(d2)] for _ in range(d1)] from itertools import accumulate as acc MOD = 10**9 + 7 def main(): n, k = MII() cnt = 0 dd = [i for i in range(n + 1)] # print(dd) dd_a = [0] for i in range(n + 1): d = dd_a[i] + dd[i] dd_a.append(d) # print(dd_a) dd_b = [0] dd_r = dd[::-1] for i in range(n + 1): d = dd_b[i] + dd_r[i] dd_b.append(d) # print(dd_b) for i in range(k, len(dd_a)): cnt += dd_b[i] - (dd_a[i] - 1) print((cnt % MOD)) if __name__ == "__main__": main()
import sys ## io IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) MIIZ = lambda: list([x - 1 for x in MII()]) ## dp INIT_VAL = 0 DP2 = lambda d1, d2: [[INIT_VAL] * d2 for _ in range(d1)] DP3 = lambda d1, d2, d3: [[[INIT_VAL] * d3 for _ in range(d2)] for _ in range(d1)] from itertools import accumulate as acc MOD = 10**9 + 7 def main(): n, k = MII() cnt = 0 dd = [i for i in range(n + 1)] dd_a = list(acc(dd)) dd_b = list(acc(dd[::-1])) for i in range(k - 1, len(dd_a)): cnt += dd_b[i] - (dd_a[i] - 1) print((cnt % MOD)) if __name__ == "__main__": main()
false
28.571429
[ "- # print(dd)", "- dd_a = [0]", "- for i in range(n + 1):", "- d = dd_a[i] + dd[i]", "- dd_a.append(d)", "- # print(dd_a)", "- dd_b = [0]", "- dd_r = dd[::-1]", "- for i in range(n + 1):", "- d = dd_b[i] + dd_r[i]", "- dd_b.append(d)", "- # print(dd_b)", "- for i in range(k, len(dd_a)):", "+ dd_a = list(acc(dd))", "+ dd_b = list(acc(dd[::-1]))", "+ for i in range(k - 1, len(dd_a)):" ]
false
0.138831
0.101242
1.371288
[ "s836200904", "s170309962" ]
u238510421
p02862
python
s226520479
s492441597
397
367
129,656
129,712
Accepted
Accepted
7.56
MAX_NUM = 10**6 + 1 MOD = 10**9+7 fac = [0 for _ in range(MAX_NUM)] finv = [0 for _ in range(MAX_NUM)] inv = [0 for _ in range(MAX_NUM)] fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2,MAX_NUM): fac[i] = fac[i-1] * i % MOD inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def combinations(n,k): if (n < k): return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD X,Y = list(map(int,input().split())) if (-Y + 2*X) % 3 == 0 and (2*Y - X) %3 == 0: x = (-Y + 2*X) // 3 y = (2*Y - X) // 3 result = combinations(x+y,min(x,y)) print((int(result % MOD))) else: print((0))
MAX_NUM = 10**6 + 1 MOD = 10**9+7 fac = [0 for _ in range(MAX_NUM)] finv = [0 for _ in range(MAX_NUM)] inv = [0 for _ in range(MAX_NUM)] fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2,MAX_NUM): fac[i] = fac[i-1] * i % MOD inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def combinations(n,k): if (n < k): return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD X,Y = list(map(int,input().split())) if (-Y + 2*X) % 3 != 0 or (2*Y - X) %3 != 0 or (-Y + 2*X) < 0 or (2*Y - X) <0: print((0)) else: x = (-Y + 2*X) // 3 y = (2*Y - X) // 3 result = combinations(x+y,min(x,y)) print((int(result % MOD)))
37
35
762
783
MAX_NUM = 10**6 + 1 MOD = 10**9 + 7 fac = [0 for _ in range(MAX_NUM)] finv = [0 for _ in range(MAX_NUM)] inv = [0 for _ in range(MAX_NUM)] fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX_NUM): fac[i] = fac[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def combinations(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD X, Y = list(map(int, input().split())) if (-Y + 2 * X) % 3 == 0 and (2 * Y - X) % 3 == 0: x = (-Y + 2 * X) // 3 y = (2 * Y - X) // 3 result = combinations(x + y, min(x, y)) print((int(result % MOD))) else: print((0))
MAX_NUM = 10**6 + 1 MOD = 10**9 + 7 fac = [0 for _ in range(MAX_NUM)] finv = [0 for _ in range(MAX_NUM)] inv = [0 for _ in range(MAX_NUM)] fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX_NUM): fac[i] = fac[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def combinations(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD X, Y = list(map(int, input().split())) if (-Y + 2 * X) % 3 != 0 or (2 * Y - X) % 3 != 0 or (-Y + 2 * X) < 0 or (2 * Y - X) < 0: print((0)) else: x = (-Y + 2 * X) // 3 y = (2 * Y - X) // 3 result = combinations(x + y, min(x, y)) print((int(result % MOD)))
false
5.405405
[ "-if (-Y + 2 * X) % 3 == 0 and (2 * Y - X) % 3 == 0:", "+if (-Y + 2 * X) % 3 != 0 or (2 * Y - X) % 3 != 0 or (-Y + 2 * X) < 0 or (2 * Y - X) < 0:", "+ print((0))", "+else:", "-else:", "- print((0))" ]
false
2.063694
1.928573
1.070062
[ "s226520479", "s492441597" ]
u585482323
p03222
python
s748315524
s154956854
184
166
40,048
38,256
Accepted
Accepted
9.78
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n,m = LI() v = LIR(m) for i in range(m): v[i] = [v[i][0],v[i][1],i] v.sort(key = lambda x:x[1]) f = [0 for i in range(n+1)] ans = [None for i in range(m)] for p,y,i in v: f[p] += 1 s = "{:0>6}".format(p) t = "{:0>6}".format(f[p]) ans[i] = s+t for i in ans: print(i) #D def D(): h,w,k = LI() dp = [[0 for i in range(w)] for j in range(h+1)] dp[0][0] = 1 p = [1 for i in range(w+1)] for i in range(w): p[i+1] = p[i]*2 l = [i for i in range(p[w-1])] i = 0 while i < len(l): a = l[i] for j in range(w): if a&p[j] and a&p[j+1]: l.pop(i) i -= 1 break i += 1 d = [[0 for i in range(3)] for j in range(w)] for j in range(w): for s in l: if 0 < j < w-1: if p[j]&s: d[j][2] += 1 elif p[j-1]&s: d[j][0] += 1 else: d[j][1] += 1 elif j == 0: if p[j]&s: d[j][2] += 1 else: d[j][1] += 1 else: if p[j-1]&s: d[j][0] += 1 else: d[j][1] += 1 for i in range(h): for j in range(w): dp[i+1][j] += d[j][1]*dp[i][j] dp[i+1][j] %= mod if j > 0: dp[i+1][j-1] += d[j][0]*dp[i][j] dp[i+1][j-1] %= mod if j < w-1: dp[i+1][j+1] += d[j][2]*dp[i][j] dp[i+1][j+1] %= mod print((dp[h][k-1])) #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": D()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): h,w,k = LI() dp = [[0]*w for _ in range(h+1)] dp[0][0] = 1 k -= 1 f = [1,1] for i in range(w): f.append(f[-1]+f[-2]) for i in range(h): ni = i+1 for j in range(w): dpj = dp[i][j] nj = j+1 if nj < w: l = f[j] r = f[w-1-nj] dp[ni][nj] += l*r*dpj%mod l = f[j] r = f[w-1-j] dp[ni][j] += l*r*dpj%mod nj = j-1 if nj >= 0: l = f[nj] r = f[w-1-j] dp[ni][nj] += l*r*dpj%mod print((dp[h][k]%mod)) return #Solve if __name__ == "__main__": solve()
122
59
2,782
1,465
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A def A(): return # B def B(): return # C def C(): n, m = LI() v = LIR(m) for i in range(m): v[i] = [v[i][0], v[i][1], i] v.sort(key=lambda x: x[1]) f = [0 for i in range(n + 1)] ans = [None for i in range(m)] for p, y, i in v: f[p] += 1 s = "{:0>6}".format(p) t = "{:0>6}".format(f[p]) ans[i] = s + t for i in ans: print(i) # D def D(): h, w, k = LI() dp = [[0 for i in range(w)] for j in range(h + 1)] dp[0][0] = 1 p = [1 for i in range(w + 1)] for i in range(w): p[i + 1] = p[i] * 2 l = [i for i in range(p[w - 1])] i = 0 while i < len(l): a = l[i] for j in range(w): if a & p[j] and a & p[j + 1]: l.pop(i) i -= 1 break i += 1 d = [[0 for i in range(3)] for j in range(w)] for j in range(w): for s in l: if 0 < j < w - 1: if p[j] & s: d[j][2] += 1 elif p[j - 1] & s: d[j][0] += 1 else: d[j][1] += 1 elif j == 0: if p[j] & s: d[j][2] += 1 else: d[j][1] += 1 else: if p[j - 1] & s: d[j][0] += 1 else: d[j][1] += 1 for i in range(h): for j in range(w): dp[i + 1][j] += d[j][1] * dp[i][j] dp[i + 1][j] %= mod if j > 0: dp[i + 1][j - 1] += d[j][0] * dp[i][j] dp[i + 1][j - 1] %= mod if j < w - 1: dp[i + 1][j + 1] += d[j][2] * dp[i][j] dp[i + 1][j + 1] %= mod print((dp[h][k - 1])) # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": D()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): h, w, k = LI() dp = [[0] * w for _ in range(h + 1)] dp[0][0] = 1 k -= 1 f = [1, 1] for i in range(w): f.append(f[-1] + f[-2]) for i in range(h): ni = i + 1 for j in range(w): dpj = dp[i][j] nj = j + 1 if nj < w: l = f[j] r = f[w - 1 - nj] dp[ni][nj] += l * r * dpj % mod l = f[j] r = f[w - 1 - j] dp[ni][j] += l * r * dpj % mod nj = j - 1 if nj >= 0: l = f[nj] r = f[w - 1 - j] dp[ni][nj] += l * r * dpj % mod print((dp[h][k] % mod)) return # Solve if __name__ == "__main__": solve()
false
51.639344
[ "-from collections import defaultdict", "-from collections import deque", "+from collections import defaultdict, deque", "+from itertools import permutations, accumulate", "-import random", "- return list(map(int, sys.stdin.readline().split()))", "+ return [int(x) for x in sys.stdin.readline().split()]", "- return list(map(list, sys.stdin.readline().split()))", "+ return [list(x) for x in sys.stdin.readline().split()]", "- return list(sys.stdin.readline())[:-1]", "+ res = list(sys.stdin.readline())", "+ if res[-1] == \"\\n\":", "+ return res[:-1]", "+ return res", "- l = [None for i in range(n)]", "- for i in range(n):", "- l[i] = I()", "- return l", "+ return [I() for i in range(n)]", "- l = [None for i in range(n)]", "- for i in range(n):", "- l[i] = LI()", "- return l", "+ return [LI() for i in range(n)]", "- l = [None for i in range(n)]", "- for i in range(n):", "- l[i] = S()", "- return l", "+ return [S() for i in range(n)]", "- l = [None for i in range(n)]", "- for i in range(n):", "- l[i] = SR()", "- return l", "+ return [LS() for i in range(n)]", "+sys.setrecursionlimit(1000000)", "-# A", "-def A():", "- return", "-# B", "-def B():", "- return", "-", "-", "-# C", "-def C():", "- n, m = LI()", "- v = LIR(m)", "- for i in range(m):", "- v[i] = [v[i][0], v[i][1], i]", "- v.sort(key=lambda x: x[1])", "- f = [0 for i in range(n + 1)]", "- ans = [None for i in range(m)]", "- for p, y, i in v:", "- f[p] += 1", "- s = \"{:0>6}\".format(p)", "- t = \"{:0>6}\".format(f[p])", "- ans[i] = s + t", "- for i in ans:", "- print(i)", "-", "-", "-# D", "-def D():", "+def solve():", "- dp = [[0 for i in range(w)] for j in range(h + 1)]", "+ dp = [[0] * w for _ in range(h + 1)]", "- p = [1 for i in range(w + 1)]", "+ k -= 1", "+ f = [1, 1]", "- p[i + 1] = p[i] * 2", "- l = [i for i in range(p[w - 1])]", "- i = 0", "- while i < len(l):", "- a = l[i]", "+ f.append(f[-1] + f[-2])", "+ for i in range(h):", "+ ni = i + 1", "- if a & p[j] and a & p[j + 1]:", "- l.pop(i)", "- i -= 1", "- break", "- i += 1", "- d = [[0 for i in range(3)] for j in range(w)]", "- for j in range(w):", "- for s in l:", "- if 0 < j < w - 1:", "- if p[j] & s:", "- d[j][2] += 1", "- elif p[j - 1] & s:", "- d[j][0] += 1", "- else:", "- d[j][1] += 1", "- elif j == 0:", "- if p[j] & s:", "- d[j][2] += 1", "- else:", "- d[j][1] += 1", "- else:", "- if p[j - 1] & s:", "- d[j][0] += 1", "- else:", "- d[j][1] += 1", "- for i in range(h):", "- for j in range(w):", "- dp[i + 1][j] += d[j][1] * dp[i][j]", "- dp[i + 1][j] %= mod", "- if j > 0:", "- dp[i + 1][j - 1] += d[j][0] * dp[i][j]", "- dp[i + 1][j - 1] %= mod", "- if j < w - 1:", "- dp[i + 1][j + 1] += d[j][2] * dp[i][j]", "- dp[i + 1][j + 1] %= mod", "- print((dp[h][k - 1]))", "-", "-", "-# E", "-def E():", "- return", "-", "-", "-# F", "-def F():", "- return", "-", "-", "-# G", "-def G():", "- return", "-", "-", "-# H", "-def H():", "+ dpj = dp[i][j]", "+ nj = j + 1", "+ if nj < w:", "+ l = f[j]", "+ r = f[w - 1 - nj]", "+ dp[ni][nj] += l * r * dpj % mod", "+ l = f[j]", "+ r = f[w - 1 - j]", "+ dp[ni][j] += l * r * dpj % mod", "+ nj = j - 1", "+ if nj >= 0:", "+ l = f[nj]", "+ r = f[w - 1 - j]", "+ dp[ni][nj] += l * r * dpj % mod", "+ print((dp[h][k] % mod))", "- D()", "+ solve()" ]
false
0.079748
0.043915
1.815955
[ "s748315524", "s154956854" ]
u917013605
p03673
python
s860195008
s869285088
380
171
98,872
107,292
Accepted
Accepted
55
import collections N = int(eval(input())) A = list(map(int, input().split())) ans = collections.deque() for i in range(N): if N % 2 == 0: if i % 2 == 0: ans.append(A[i]) else: ans.appendleft(A[i]) else: if i % 2 == 0: ans.appendleft(A[i]) else: ans.append(A[i]) print((*ans))
from collections import deque n = int(eval(input())) a_li = list(map(int, input().split())) b_li = deque() for i in range(len(a_li)): if i % 2 == 0: b_li.append(a_li[i]) else: b_li.appendleft(a_li[i]) if len(a_li) % 2 == 0: print((*b_li)) else: print((*list(b_li)[::-1]))
17
15
373
310
import collections N = int(eval(input())) A = list(map(int, input().split())) ans = collections.deque() for i in range(N): if N % 2 == 0: if i % 2 == 0: ans.append(A[i]) else: ans.appendleft(A[i]) else: if i % 2 == 0: ans.appendleft(A[i]) else: ans.append(A[i]) print((*ans))
from collections import deque n = int(eval(input())) a_li = list(map(int, input().split())) b_li = deque() for i in range(len(a_li)): if i % 2 == 0: b_li.append(a_li[i]) else: b_li.appendleft(a_li[i]) if len(a_li) % 2 == 0: print((*b_li)) else: print((*list(b_li)[::-1]))
false
11.764706
[ "-import collections", "+from collections import deque", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-ans = collections.deque()", "-for i in range(N):", "- if N % 2 == 0:", "- if i % 2 == 0:", "- ans.append(A[i])", "- else:", "- ans.appendleft(A[i])", "+n = int(eval(input()))", "+a_li = list(map(int, input().split()))", "+b_li = deque()", "+for i in range(len(a_li)):", "+ if i % 2 == 0:", "+ b_li.append(a_li[i])", "- if i % 2 == 0:", "- ans.appendleft(A[i])", "- else:", "- ans.append(A[i])", "-print((*ans))", "+ b_li.appendleft(a_li[i])", "+if len(a_li) % 2 == 0:", "+ print((*b_li))", "+else:", "+ print((*list(b_li)[::-1]))" ]
false
0.007712
0.030171
0.25561
[ "s860195008", "s869285088" ]
u545368057
p03128
python
s063149741
s856619139
684
112
30,452
29,684
Accepted
Accepted
83.63
## DP問題 N,M = list(map(int,input().split())) As = list(map(str,input().split())) match = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6} # test # N, M = 10000, 9 # As = [str(i) for i in range(1,10)] ws = {} #マッチの数に対しての、作れる数字の最大値を算出 for a in As: w = match[a] #数aに使うマッチの数 try: ws[str(w)] = max(a,ws[str(w)]) except: ws[str(w)] = a ks = list(map(int,list(ws.keys()))) ns = list(ws.values()) dp = ["0" for _ in range(N+1)] for i in range(1,min(ks)):#最小 dp[i] = "-1" for i in range(N+1): # print(i) for a,k in zip(ns,ks): if i+k <= N: if dp[i] == "-1": dp[i+k] = str(max(int(dp[i]+a),int(dp[i+k]))) elif dp[i] == "0": dp[i+k] = str(max(int(a),int(dp[i+k]))) elif len(dp[i+k]) < len(dp[i])+1: dp[i+k] = dp[i]+a elif len(dp[i+k]) == len(dp[i])+1: dp[i+k] = max(dp[i+k],dp[i]+a) else: dp[i+k] = str(max(int(dp[i+k]),int(dp[i]+a))) else: continue print((dp[N]))
## DP問題 N,M = list(map(int,input().split())) As = list(map(str,input().split())) match = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6} # test # N, M = 10000, 9 # As = [str(i) for i in range(1,10)] ws = {} #マッチの数に対しての、作れる数字の最大値を算出 for a in As: w = match[a] #数aに使うマッチの数 try: ws[str(w)] = max(a,ws[str(w)]) except: ws[str(w)] = a ks = list(map(int,list(ws.keys()))) ns = list(ws.values()) dp = ["0" for _ in range(N+1)] for i in range(1,min(ks)):#最小 dp[i] = "-1" for i in range(N+1): # print(i) for a,k in zip(ns,ks): if i+k <= N: if dp[i] == "-1": dp[i+k] = str(max(int(dp[i]+a),int(dp[i+k]))) elif dp[i] == "0": dp[i+k] = str(max(int(a),int(dp[i+k]))) elif len(dp[i+k]) < len(dp[i])+1: dp[i+k] = dp[i]+a elif len(dp[i+k]) == len(dp[i])+1: dp[i+k] = max(dp[i+k],dp[i]+a) # else: # dp[i+k] = str(max(int(dp[i+k]),int(dp[i]+a))) else: continue print((dp[N]))
45
45
1,142
1,146
## DP問題 N, M = list(map(int, input().split())) As = list(map(str, input().split())) match = {"1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6} # test # N, M = 10000, 9 # As = [str(i) for i in range(1,10)] ws = {} # マッチの数に対しての、作れる数字の最大値を算出 for a in As: w = match[a] # 数aに使うマッチの数 try: ws[str(w)] = max(a, ws[str(w)]) except: ws[str(w)] = a ks = list(map(int, list(ws.keys()))) ns = list(ws.values()) dp = ["0" for _ in range(N + 1)] for i in range(1, min(ks)): # 最小 dp[i] = "-1" for i in range(N + 1): # print(i) for a, k in zip(ns, ks): if i + k <= N: if dp[i] == "-1": dp[i + k] = str(max(int(dp[i] + a), int(dp[i + k]))) elif dp[i] == "0": dp[i + k] = str(max(int(a), int(dp[i + k]))) elif len(dp[i + k]) < len(dp[i]) + 1: dp[i + k] = dp[i] + a elif len(dp[i + k]) == len(dp[i]) + 1: dp[i + k] = max(dp[i + k], dp[i] + a) else: dp[i + k] = str(max(int(dp[i + k]), int(dp[i] + a))) else: continue print((dp[N]))
## DP問題 N, M = list(map(int, input().split())) As = list(map(str, input().split())) match = {"1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6} # test # N, M = 10000, 9 # As = [str(i) for i in range(1,10)] ws = {} # マッチの数に対しての、作れる数字の最大値を算出 for a in As: w = match[a] # 数aに使うマッチの数 try: ws[str(w)] = max(a, ws[str(w)]) except: ws[str(w)] = a ks = list(map(int, list(ws.keys()))) ns = list(ws.values()) dp = ["0" for _ in range(N + 1)] for i in range(1, min(ks)): # 最小 dp[i] = "-1" for i in range(N + 1): # print(i) for a, k in zip(ns, ks): if i + k <= N: if dp[i] == "-1": dp[i + k] = str(max(int(dp[i] + a), int(dp[i + k]))) elif dp[i] == "0": dp[i + k] = str(max(int(a), int(dp[i + k]))) elif len(dp[i + k]) < len(dp[i]) + 1: dp[i + k] = dp[i] + a elif len(dp[i + k]) == len(dp[i]) + 1: dp[i + k] = max(dp[i + k], dp[i] + a) # else: # dp[i+k] = str(max(int(dp[i+k]),int(dp[i]+a))) else: continue print((dp[N]))
false
0
[ "- else:", "- dp[i + k] = str(max(int(dp[i + k]), int(dp[i] + a)))", "+ # else:", "+ # dp[i+k] = str(max(int(dp[i+k]),int(dp[i]+a)))" ]
false
0.08838
0.077437
1.141311
[ "s063149741", "s856619139" ]
u835924161
p02732
python
s093480468
s420245310
519
341
26,140
26,268
Accepted
Accepted
34.3
n=int(eval(input())) A=list(map(int,input().split())) ma=int(200200) B=[0]*ma for i in range(n): now=A[i] B[now]+=1 ans=int(0) for i in range(ma): ans+=int((B[i]-1)*B[i]/2) for i in range(n): now=A[i] Ans=ans Ans-=int((B[now]-1)*B[now]/2) Ans+=int((B[now]-1)*(B[now]-2)/2) print(Ans)
n=int(eval(input())) A=list(map(int,input().split())) ma=int(200200) B=[0]*ma for i in range(n): B[A[i]]+=1 ans=int(0) for i in range(ma): ans+=int((B[i]-1)*B[i]/2) for i in range(n): print((ans-B[A[i]]+1))
19
14
330
226
n = int(eval(input())) A = list(map(int, input().split())) ma = int(200200) B = [0] * ma for i in range(n): now = A[i] B[now] += 1 ans = int(0) for i in range(ma): ans += int((B[i] - 1) * B[i] / 2) for i in range(n): now = A[i] Ans = ans Ans -= int((B[now] - 1) * B[now] / 2) Ans += int((B[now] - 1) * (B[now] - 2) / 2) print(Ans)
n = int(eval(input())) A = list(map(int, input().split())) ma = int(200200) B = [0] * ma for i in range(n): B[A[i]] += 1 ans = int(0) for i in range(ma): ans += int((B[i] - 1) * B[i] / 2) for i in range(n): print((ans - B[A[i]] + 1))
false
26.315789
[ "- now = A[i]", "- B[now] += 1", "+ B[A[i]] += 1", "- now = A[i]", "- Ans = ans", "- Ans -= int((B[now] - 1) * B[now] / 2)", "- Ans += int((B[now] - 1) * (B[now] - 2) / 2)", "- print(Ans)", "+ print((ans - B[A[i]] + 1))" ]
false
0.176727
0.175589
1.006479
[ "s093480468", "s420245310" ]
u352394527
p00442
python
s971153132
s302957812
430
360
13,288
13,308
Accepted
Accepted
16.28
import sys sys.setrecursionlimit(100000) def main(): V, E = int(eval(input())), int(eval(input())) L = [] app = L.append visited = [0 for i in range(V)] edges = [[] for i in range(V)] def visit(x): if not visited[x]: visited[x] = 1 for e in edges[x]: visit(e) app(x) for i in range(E): s, t = list(map(int,input().split())) edges[s - 1].append(t - 1) for i in range(V): if not visited[i]: visit(i) L.reverse() flag = 0 for i in range(V): print((L[i] + 1)) if not flag and i < V - 1 and (L[i + 1] not in edges[L[i]]): flag = 1 print(flag) main()
import sys sys.setrecursionlimit(100000) def main(): V, E = int(eval(input())), int(eval(input())) L = [] app = L.append visited = [0 for i in range(V)] edges = [[] for i in range(V)] def visit(x): if not visited[x]: visited[x] = 1 for e in edges[x]: visit(e) app(x) for i in range(E): s, t = list(map(int,input().split())) edges[s - 1].append(t - 1) for i in range(V): if not visited[i]: visit(i) L.reverse() flag = 0 temp = L[0] print((temp + 1)) for i in range(V - 1): v = L[i + 1] print((v + 1)) if not flag and i < V - 1 and (v not in edges[temp]): flag = 1 temp = v print(flag) main()
33
37
656
716
import sys sys.setrecursionlimit(100000) def main(): V, E = int(eval(input())), int(eval(input())) L = [] app = L.append visited = [0 for i in range(V)] edges = [[] for i in range(V)] def visit(x): if not visited[x]: visited[x] = 1 for e in edges[x]: visit(e) app(x) for i in range(E): s, t = list(map(int, input().split())) edges[s - 1].append(t - 1) for i in range(V): if not visited[i]: visit(i) L.reverse() flag = 0 for i in range(V): print((L[i] + 1)) if not flag and i < V - 1 and (L[i + 1] not in edges[L[i]]): flag = 1 print(flag) main()
import sys sys.setrecursionlimit(100000) def main(): V, E = int(eval(input())), int(eval(input())) L = [] app = L.append visited = [0 for i in range(V)] edges = [[] for i in range(V)] def visit(x): if not visited[x]: visited[x] = 1 for e in edges[x]: visit(e) app(x) for i in range(E): s, t = list(map(int, input().split())) edges[s - 1].append(t - 1) for i in range(V): if not visited[i]: visit(i) L.reverse() flag = 0 temp = L[0] print((temp + 1)) for i in range(V - 1): v = L[i + 1] print((v + 1)) if not flag and i < V - 1 and (v not in edges[temp]): flag = 1 temp = v print(flag) main()
false
10.810811
[ "- for i in range(V):", "- print((L[i] + 1))", "- if not flag and i < V - 1 and (L[i + 1] not in edges[L[i]]):", "+ temp = L[0]", "+ print((temp + 1))", "+ for i in range(V - 1):", "+ v = L[i + 1]", "+ print((v + 1))", "+ if not flag and i < V - 1 and (v not in edges[temp]):", "+ temp = v" ]
false
0.066315
0.070736
0.937495
[ "s971153132", "s302957812" ]
u816631826
p03813
python
s408485755
s733895357
19
17
2,940
2,940
Accepted
Accepted
10.53
rate = int(eval(input())) if rate < 1200: print("ABC") else: print("ARC")
a= eval(input()) if a<"1200": print("ABC") else: print("ARC")
6
6
81
74
rate = int(eval(input())) if rate < 1200: print("ABC") else: print("ARC")
a = eval(input()) if a < "1200": print("ABC") else: print("ARC")
false
0
[ "-rate = int(eval(input()))", "-if rate < 1200:", "+a = eval(input())", "+if a < \"1200\":" ]
false
0.066397
0.066537
0.997905
[ "s408485755", "s733895357" ]
u028973125
p02603
python
s333829848
s536739144
33
29
9,144
9,172
Accepted
Accepted
12.12
import sys N = int(sys.stdin.readline().strip()) A = list(map(int, sys.stdin.readline().split())) money = 1000 min_price = float("inf") for i in range(N): if min_price > A[i]: min_price = A[i] elif min_price < A[i]: num = money // min_price money = money - min_price * num + A[i] * num min_price = A[i] print(money)
import sys N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) yen = 1000 for i in range(1, N): if A[i-1] < A[i]: yen += (A[i] - A[i-1]) * (yen // A[i-1]) print(yen)
16
11
373
217
import sys N = int(sys.stdin.readline().strip()) A = list(map(int, sys.stdin.readline().split())) money = 1000 min_price = float("inf") for i in range(N): if min_price > A[i]: min_price = A[i] elif min_price < A[i]: num = money // min_price money = money - min_price * num + A[i] * num min_price = A[i] print(money)
import sys N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) yen = 1000 for i in range(1, N): if A[i - 1] < A[i]: yen += (A[i] - A[i - 1]) * (yen // A[i - 1]) print(yen)
false
31.25
[ "-N = int(sys.stdin.readline().strip())", "+N = int(sys.stdin.readline())", "-money = 1000", "-min_price = float(\"inf\")", "-for i in range(N):", "- if min_price > A[i]:", "- min_price = A[i]", "- elif min_price < A[i]:", "- num = money // min_price", "- money = money - min_price * num + A[i] * num", "- min_price = A[i]", "-print(money)", "+yen = 1000", "+for i in range(1, N):", "+ if A[i - 1] < A[i]:", "+ yen += (A[i] - A[i - 1]) * (yen // A[i - 1])", "+print(yen)" ]
false
0.044763
0.044481
1.00635
[ "s333829848", "s536739144" ]
u134712256
p04031
python
s140682400
s687798276
20
17
3,188
2,940
Accepted
Accepted
15
N = int(eval(input())) a = list(map(int,input().split())) ave = sum(a)/N ave = round(ave) sum = 0 for i in a: sum += (i-ave)**2 print(sum)
n=int(eval(input())) a=list(map(int,input().split())) ave = round(sum(a)/n) cost=0 for i in range(n): cost+=(a[i]-ave)**2 print(cost)
8
8
144
140
N = int(eval(input())) a = list(map(int, input().split())) ave = sum(a) / N ave = round(ave) sum = 0 for i in a: sum += (i - ave) ** 2 print(sum)
n = int(eval(input())) a = list(map(int, input().split())) ave = round(sum(a) / n) cost = 0 for i in range(n): cost += (a[i] - ave) ** 2 print(cost)
false
0
[ "-N = int(eval(input()))", "+n = int(eval(input()))", "-ave = sum(a) / N", "-ave = round(ave)", "-sum = 0", "-for i in a:", "- sum += (i - ave) ** 2", "-print(sum)", "+ave = round(sum(a) / n)", "+cost = 0", "+for i in range(n):", "+ cost += (a[i] - ave) ** 2", "+print(cost)" ]
false
0.048299
0.048857
0.988569
[ "s140682400", "s687798276" ]
u561083515
p02954
python
s704215165
s607886414
252
153
10,484
9,836
Accepted
Accepted
39.29
S = eval(input()) result = [1]*len(S) for i,x in enumerate(S): if x == "R": move_To = S.find("L", i)-1 result[i] -= 1 if (move_To - i) % 2 == 0: result[move_To] += 1 else: result[move_To+1] += 1 else: move_To = S.rfind("R", 0, i+1) + 1 result[i] -= 1 if (i - move_To) % 2 == 0: result[move_To] += 1 else: result[move_To-1] += 1 print((" ".join(map(str,result))))
""" 各人についての移動回数 偶数 -> 状態同じ 奇数 -> 一回移動 """ S = [False if s == "L" else True for s in eval(input())] N = len(S) from collections import deque F_idx = deque([idx for idx in range(N) if not S[idx]]) T_idx = deque([idx for idx in range(N) if S[idx]]) state = [0] * N # -> for i in range(N): if S[i]: if (F_idx[0] - i) % 2 == 0: state[F_idx[0]] += 1 else: state[F_idx[0] - 1] += 1 if i == F_idx[0]: F_idx.popleft() # <- for i in range(N-1,-1,-1): if not S[i]: if abs(T_idx[-1] - i) % 2 == 0: state[T_idx[-1]] += 1 else: state[T_idx[-1] + 1] += 1 if i == T_idx[-1]: T_idx.pop() print((*state))
20
35
497
729
S = eval(input()) result = [1] * len(S) for i, x in enumerate(S): if x == "R": move_To = S.find("L", i) - 1 result[i] -= 1 if (move_To - i) % 2 == 0: result[move_To] += 1 else: result[move_To + 1] += 1 else: move_To = S.rfind("R", 0, i + 1) + 1 result[i] -= 1 if (i - move_To) % 2 == 0: result[move_To] += 1 else: result[move_To - 1] += 1 print((" ".join(map(str, result))))
""" 各人についての移動回数 偶数 -> 状態同じ 奇数 -> 一回移動 """ S = [False if s == "L" else True for s in eval(input())] N = len(S) from collections import deque F_idx = deque([idx for idx in range(N) if not S[idx]]) T_idx = deque([idx for idx in range(N) if S[idx]]) state = [0] * N # -> for i in range(N): if S[i]: if (F_idx[0] - i) % 2 == 0: state[F_idx[0]] += 1 else: state[F_idx[0] - 1] += 1 if i == F_idx[0]: F_idx.popleft() # <- for i in range(N - 1, -1, -1): if not S[i]: if abs(T_idx[-1] - i) % 2 == 0: state[T_idx[-1]] += 1 else: state[T_idx[-1] + 1] += 1 if i == T_idx[-1]: T_idx.pop() print((*state))
false
42.857143
[ "-S = eval(input())", "-result = [1] * len(S)", "-for i, x in enumerate(S):", "- if x == \"R\":", "- move_To = S.find(\"L\", i) - 1", "- result[i] -= 1", "- if (move_To - i) % 2 == 0:", "- result[move_To] += 1", "+\"\"\"", "+各人についての移動回数", "+偶数 -> 状態同じ", "+奇数 -> 一回移動", "+\"\"\"", "+S = [False if s == \"L\" else True for s in eval(input())]", "+N = len(S)", "+from collections import deque", "+", "+F_idx = deque([idx for idx in range(N) if not S[idx]])", "+T_idx = deque([idx for idx in range(N) if S[idx]])", "+state = [0] * N", "+# ->", "+for i in range(N):", "+ if S[i]:", "+ if (F_idx[0] - i) % 2 == 0:", "+ state[F_idx[0]] += 1", "- result[move_To + 1] += 1", "- else:", "- move_To = S.rfind(\"R\", 0, i + 1) + 1", "- result[i] -= 1", "- if (i - move_To) % 2 == 0:", "- result[move_To] += 1", "+ state[F_idx[0] - 1] += 1", "+ if i == F_idx[0]:", "+ F_idx.popleft()", "+# <-", "+for i in range(N - 1, -1, -1):", "+ if not S[i]:", "+ if abs(T_idx[-1] - i) % 2 == 0:", "+ state[T_idx[-1]] += 1", "- result[move_To - 1] += 1", "-print((\" \".join(map(str, result))))", "+ state[T_idx[-1] + 1] += 1", "+ if i == T_idx[-1]:", "+ T_idx.pop()", "+print((*state))" ]
false
0.104932
0.04817
2.178365
[ "s704215165", "s607886414" ]
u336624604
p02899
python
s157796867
s406485476
251
106
26,596
13,880
Accepted
Accepted
57.77
n = int(eval(input())) a = list(map(int, input().split())) b=[] for i in range(1,n+1): b.append(i) a, b = list(zip(*sorted(zip(a,b)))) print((*b))
n = int(eval(input())) a = list(map(int, input().split())) b=[0]*n for i,a in enumerate(a): b[a-1]=i+1 print((*b))
8
6
144
115
n = int(eval(input())) a = list(map(int, input().split())) b = [] for i in range(1, n + 1): b.append(i) a, b = list(zip(*sorted(zip(a, b)))) print((*b))
n = int(eval(input())) a = list(map(int, input().split())) b = [0] * n for i, a in enumerate(a): b[a - 1] = i + 1 print((*b))
false
25
[ "-b = []", "-for i in range(1, n + 1):", "- b.append(i)", "-a, b = list(zip(*sorted(zip(a, b))))", "+b = [0] * n", "+for i, a in enumerate(a):", "+ b[a - 1] = i + 1" ]
false
0.055437
0.036985
1.498892
[ "s157796867", "s406485476" ]
u367130284
p03665
python
s461452399
s624763763
22
18
3,572
3,188
Accepted
Accepted
18.18
from operator import mul from functools import reduce from math import factorial def cmb(n,r): r=min(n-r,r) if r == 0: return 1 over=reduce(mul,list(range(n,n-r,-1))) under=reduce(mul,list(range(1,r+1))) return over//under n,p,*a=list(map(int,open(0).read().split())) b=[i for i in a if i%2==0] c=[i for i in a if i%2==1] ans=0 x=0 for s in range(len(b)+1): x+=cmb(len(b),s) if p==0: for s in range(0,len(c)+1,2): ans+=x*cmb(len(c),s) print(ans) else: for s in range(1,len(c)+1,2): ans+=x*cmb(len(c),s) print(ans)
from math import factorial def cmb(n,r): if n-r<0: return 0 else: return factorial(n) // factorial(r) // factorial(n - r) n,p,*a=list(map(int,open(0).read().split())) odd=sum(i%2 for i in a) even=n-odd x=sum(cmb(even,i)for i in range(even+1)) y=sum(cmb(odd,i)for i in range(p,odd+1,2)) print((x*y))
26
18
550
346
from operator import mul from functools import reduce from math import factorial def cmb(n, r): r = min(n - r, r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1, r + 1))) return over // under n, p, *a = list(map(int, open(0).read().split())) b = [i for i in a if i % 2 == 0] c = [i for i in a if i % 2 == 1] ans = 0 x = 0 for s in range(len(b) + 1): x += cmb(len(b), s) if p == 0: for s in range(0, len(c) + 1, 2): ans += x * cmb(len(c), s) print(ans) else: for s in range(1, len(c) + 1, 2): ans += x * cmb(len(c), s) print(ans)
from math import factorial def cmb(n, r): if n - r < 0: return 0 else: return factorial(n) // factorial(r) // factorial(n - r) n, p, *a = list(map(int, open(0).read().split())) odd = sum(i % 2 for i in a) even = n - odd x = sum(cmb(even, i) for i in range(even + 1)) y = sum(cmb(odd, i) for i in range(p, odd + 1, 2)) print((x * y))
false
30.769231
[ "-from operator import mul", "-from functools import reduce", "- r = min(n - r, r)", "- if r == 0:", "- return 1", "- over = reduce(mul, list(range(n, n - r, -1)))", "- under = reduce(mul, list(range(1, r + 1)))", "- return over // under", "+ if n - r < 0:", "+ return 0", "+ else:", "+ return factorial(n) // factorial(r) // factorial(n - r)", "-b = [i for i in a if i % 2 == 0]", "-c = [i for i in a if i % 2 == 1]", "-ans = 0", "-x = 0", "-for s in range(len(b) + 1):", "- x += cmb(len(b), s)", "-if p == 0:", "- for s in range(0, len(c) + 1, 2):", "- ans += x * cmb(len(c), s)", "- print(ans)", "-else:", "- for s in range(1, len(c) + 1, 2):", "- ans += x * cmb(len(c), s)", "- print(ans)", "+odd = sum(i % 2 for i in a)", "+even = n - odd", "+x = sum(cmb(even, i) for i in range(even + 1))", "+y = sum(cmb(odd, i) for i in range(p, odd + 1, 2))", "+print((x * y))" ]
false
0.033487
0.037354
0.89649
[ "s461452399", "s624763763" ]
u075012704
p02631
python
s934379324
s152451843
166
150
136,972
31,840
Accepted
Accepted
9.64
N = int(input()) A = list(map(int, input().split())) xor_left = [0] for a in A: xor_left.append(xor_left[-1] ^ a) xor_left.append(0) xor_right = [0] for a in A[::-1]: xor_right.append(xor_right[-1] ^ a) xor_right.append(0) xor_right = xor_right[::-1] ans = [] for i in range(1, N + 1): ans.append(xor_left[i - 1] ^ xor_right[i + 1]) print(*ans, sep=' ')
from functools import reduce N = int(input()) A = list(map(int, input().split())) ALL_XOR = reduce(lambda x, y: x ^ y, A) print(*[a ^ ALL_XOR for a in A], sep=' ')
18
6
386
170
N = int(input()) A = list(map(int, input().split())) xor_left = [0] for a in A: xor_left.append(xor_left[-1] ^ a) xor_left.append(0) xor_right = [0] for a in A[::-1]: xor_right.append(xor_right[-1] ^ a) xor_right.append(0) xor_right = xor_right[::-1] ans = [] for i in range(1, N + 1): ans.append(xor_left[i - 1] ^ xor_right[i + 1]) print(*ans, sep=" ")
from functools import reduce N = int(input()) A = list(map(int, input().split())) ALL_XOR = reduce(lambda x, y: x ^ y, A) print(*[a ^ ALL_XOR for a in A], sep=" ")
false
66.666667
[ "+from functools import reduce", "+", "-xor_left = [0]", "-for a in A:", "- xor_left.append(xor_left[-1] ^ a)", "-xor_left.append(0)", "-xor_right = [0]", "-for a in A[::-1]:", "- xor_right.append(xor_right[-1] ^ a)", "-xor_right.append(0)", "-xor_right = xor_right[::-1]", "-ans = []", "-for i in range(1, N + 1):", "- ans.append(xor_left[i - 1] ^ xor_right[i + 1])", "-print(*ans, sep=\" \")", "+ALL_XOR = reduce(lambda x, y: x ^ y, A)", "+print(*[a ^ ALL_XOR for a in A], sep=\" \")" ]
false
0.048245
0.046648
1.034229
[ "s934379324", "s152451843" ]
u106311097
p02642
python
s964962638
s021186223
991
610
96,764
35,900
Accepted
Accepted
38.45
#!python3.8 # -*- coding: utf-8 -*- # abc170/abc170_d from collections import Counter def main(): N = eval(input()) A = sorted(map(int, input().split(' '))) B = Counter(A) for a in A: if B[a] == 0: continue if B[a] > 1: B[a] = 0 for i in range(2, A[-1] // a + 1): B[a * i] = 0 print((Counter(list(B.values()))[1])) return main()
#!python3.8 # -*- coding: utf-8 -*- # abc170/abc170_d from collections import Counter def main(): N = eval(input()) A = sorted(map(int, input().split(' '))) B = Counter(A) for a in A: if B[a] == 0: continue if B[a] > 1: B[a] = 0 for i in range(2, A[-1] // a + 1): if B[a * i]: B[a * i] = 0 print((sum(B.values()))) return main()
20
21
420
443
#!python3.8 # -*- coding: utf-8 -*- # abc170/abc170_d from collections import Counter def main(): N = eval(input()) A = sorted(map(int, input().split(" "))) B = Counter(A) for a in A: if B[a] == 0: continue if B[a] > 1: B[a] = 0 for i in range(2, A[-1] // a + 1): B[a * i] = 0 print((Counter(list(B.values()))[1])) return main()
#!python3.8 # -*- coding: utf-8 -*- # abc170/abc170_d from collections import Counter def main(): N = eval(input()) A = sorted(map(int, input().split(" "))) B = Counter(A) for a in A: if B[a] == 0: continue if B[a] > 1: B[a] = 0 for i in range(2, A[-1] // a + 1): if B[a * i]: B[a * i] = 0 print((sum(B.values()))) return main()
false
4.761905
[ "- B[a * i] = 0", "- print((Counter(list(B.values()))[1]))", "+ if B[a * i]:", "+ B[a * i] = 0", "+ print((sum(B.values())))" ]
false
0.041669
0.04646
0.896863
[ "s964962638", "s021186223" ]
u271176141
p03803
python
s306575770
s280904706
27
24
9,160
8,968
Accepted
Accepted
11.11
# AliceのスコアAとBobのスコアBを整数で入力 A,B = list(map(int,input().split())) # AとBが同じならDrawを出力 if A == B: print("Draw") # Aが1がBより大きいならAliceを出力 elif A == 1 or A > B and B!= 1 : print("Alice") # Bの方が強ければBobを出力 else: print("Bob")
# AliceのスコアAとBobのスコアBを整数で入力 A,B = list(map(int,input().split())) # AとBが同じならDrawを出力 if A == B: print("Draw") # Aが1か、Bが1でなく且つAがBより大きいならAliceを出力 elif A == 1 or B!= 1 and A > B: print("Alice") # Bの方が強ければBobを出力 else: print("Bob")
11
11
230
242
# AliceのスコアAとBobのスコアBを整数で入力 A, B = list(map(int, input().split())) # AとBが同じならDrawを出力 if A == B: print("Draw") # Aが1がBより大きいならAliceを出力 elif A == 1 or A > B and B != 1: print("Alice") # Bの方が強ければBobを出力 else: print("Bob")
# AliceのスコアAとBobのスコアBを整数で入力 A, B = list(map(int, input().split())) # AとBが同じならDrawを出力 if A == B: print("Draw") # Aが1か、Bが1でなく且つAがBより大きいならAliceを出力 elif A == 1 or B != 1 and A > B: print("Alice") # Bの方が強ければBobを出力 else: print("Bob")
false
0
[ "-# Aが1がBより大きいならAliceを出力", "-elif A == 1 or A > B and B != 1:", "+# Aが1か、Bが1でなく且つAがBより大きいならAliceを出力", "+elif A == 1 or B != 1 and A > B:" ]
false
0.036636
0.036142
1.013692
[ "s306575770", "s280904706" ]
u250583425
p03078
python
s141690047
s576112412
1,937
32
185,812
4,976
Accepted
Accepted
98.35
import sys from itertools import product def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A, B, C = [sorted(map(int, input().split())) for _ in range(3)] AB = [a + b for a, b in product(A, B)] AB = sorted(AB, reverse=True)[:K] ABC = [ab + c for ab, c in product(AB, C)] ABC = sorted(ABC, reverse=True)[:K] for i in ABC: print(i) if __name__ == '__main__': main()
import sys import heapq def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A, B, C = [sorted(map(int, input().split()), reverse=True) for _ in range(3)] hp = [] heapq.heappush(hp, (- A[0] - B[0] - C[0], 0, 0, 0)) exists = set([(0, 0, 0)]) for _ in range(K): v, x, y, z = heapq.heappop(hp) print((-v)) if x + 1 < X and (x + 1, y, z) not in exists: heapq.heappush(hp, (v + A[x] - A[x+1], x + 1, y, z)) exists.add((x + 1, y, z)) if y + 1 < Y and (x, y + 1, z) not in exists: heapq.heappush(hp, (v + B[y] - B[y+1], x, y + 1, z)) exists.add((x, y + 1, z)) if z + 1 < Z and (x, y, z + 1) not in exists: heapq.heappush(hp, (v + C[z] - C[z+1], x, y, z + 1)) exists.add((x, y, z + 1)) if __name__ == '__main__': main()
18
26
476
926
import sys from itertools import product def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A, B, C = [sorted(map(int, input().split())) for _ in range(3)] AB = [a + b for a, b in product(A, B)] AB = sorted(AB, reverse=True)[:K] ABC = [ab + c for ab, c in product(AB, C)] ABC = sorted(ABC, reverse=True)[:K] for i in ABC: print(i) if __name__ == "__main__": main()
import sys import heapq def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A, B, C = [sorted(map(int, input().split()), reverse=True) for _ in range(3)] hp = [] heapq.heappush(hp, (-A[0] - B[0] - C[0], 0, 0, 0)) exists = set([(0, 0, 0)]) for _ in range(K): v, x, y, z = heapq.heappop(hp) print((-v)) if x + 1 < X and (x + 1, y, z) not in exists: heapq.heappush(hp, (v + A[x] - A[x + 1], x + 1, y, z)) exists.add((x + 1, y, z)) if y + 1 < Y and (x, y + 1, z) not in exists: heapq.heappush(hp, (v + B[y] - B[y + 1], x, y + 1, z)) exists.add((x, y + 1, z)) if z + 1 < Z and (x, y, z + 1) not in exists: heapq.heappush(hp, (v + C[z] - C[z + 1], x, y, z + 1)) exists.add((x, y, z + 1)) if __name__ == "__main__": main()
false
30.769231
[ "-from itertools import product", "+import heapq", "- A, B, C = [sorted(map(int, input().split())) for _ in range(3)]", "- AB = [a + b for a, b in product(A, B)]", "- AB = sorted(AB, reverse=True)[:K]", "- ABC = [ab + c for ab, c in product(AB, C)]", "- ABC = sorted(ABC, reverse=True)[:K]", "- for i in ABC:", "- print(i)", "+ A, B, C = [sorted(map(int, input().split()), reverse=True) for _ in range(3)]", "+ hp = []", "+ heapq.heappush(hp, (-A[0] - B[0] - C[0], 0, 0, 0))", "+ exists = set([(0, 0, 0)])", "+ for _ in range(K):", "+ v, x, y, z = heapq.heappop(hp)", "+ print((-v))", "+ if x + 1 < X and (x + 1, y, z) not in exists:", "+ heapq.heappush(hp, (v + A[x] - A[x + 1], x + 1, y, z))", "+ exists.add((x + 1, y, z))", "+ if y + 1 < Y and (x, y + 1, z) not in exists:", "+ heapq.heappush(hp, (v + B[y] - B[y + 1], x, y + 1, z))", "+ exists.add((x, y + 1, z))", "+ if z + 1 < Z and (x, y, z + 1) not in exists:", "+ heapq.heappush(hp, (v + C[z] - C[z + 1], x, y, z + 1))", "+ exists.add((x, y, z + 1))" ]
false
0.092791
0.050011
1.855393
[ "s141690047", "s576112412" ]
u309120194
p02847
python
s929060922
s538567292
26
22
9,092
8,928
Accepted
Accepted
15.38
S = eval(input()) if S == 'SUN': print((7)) elif S == 'MON': print((6)) elif S == 'TUE': print((5)) elif S == 'WED': print((4)) elif S == 'THU': print((3)) elif S == 'FRI': print((2)) elif S == 'SAT': print((1))
S = eval(input()) if S == 'SUN': print((7)) elif S == 'MON': print((6)) elif S == 'TUE': print((5)) elif S == 'WED': print((4)) elif S == 'THU': print((3)) elif S == 'FRI': print((2)) else: print((1))
8
8
199
188
S = eval(input()) if S == "SUN": print((7)) elif S == "MON": print((6)) elif S == "TUE": print((5)) elif S == "WED": print((4)) elif S == "THU": print((3)) elif S == "FRI": print((2)) elif S == "SAT": print((1))
S = eval(input()) if S == "SUN": print((7)) elif S == "MON": print((6)) elif S == "TUE": print((5)) elif S == "WED": print((4)) elif S == "THU": print((3)) elif S == "FRI": print((2)) else: print((1))
false
0
[ "-elif S == \"SAT\":", "+else:" ]
false
0.124758
0.049024
2.544847
[ "s929060922", "s538567292" ]
u556589653
p03262
python
s980699377
s683904205
102
91
16,280
20,376
Accepted
Accepted
10.78
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) N,X = list(map(int,input().split())) A = list(map(int,input().split())) k = [] for i in range(N): k.append(abs(A[i]-X)) print((gcd_list(k)))
import math N,X = list(map(int,input().split())) x = list(map(int,input().split())) ls = [] for i in range(N): ls.append(abs(x[i]-X)) now = ls[0] for i in range(1,N): now = math.gcd(ls[i],now) print(now)
10
10
252
214
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) N, X = list(map(int, input().split())) A = list(map(int, input().split())) k = [] for i in range(N): k.append(abs(A[i] - X)) print((gcd_list(k)))
import math N, X = list(map(int, input().split())) x = list(map(int, input().split())) ls = [] for i in range(N): ls.append(abs(x[i] - X)) now = ls[0] for i in range(1, N): now = math.gcd(ls[i], now) print(now)
false
0
[ "-import fractions", "-from functools import reduce", "-", "-", "-def gcd_list(numbers):", "- return reduce(fractions.gcd, numbers)", "-", "+import math", "-A = list(map(int, input().split()))", "-k = []", "+x = list(map(int, input().split()))", "+ls = []", "- k.append(abs(A[i] - X))", "-print((gcd_list(k)))", "+ ls.append(abs(x[i] - X))", "+now = ls[0]", "+for i in range(1, N):", "+ now = math.gcd(ls[i], now)", "+print(now)" ]
false
0.059527
0.0365
1.630881
[ "s980699377", "s683904205" ]
u634046173
p03730
python
s746265817
s563309412
67
59
63,044
61,812
Accepted
Accepted
11.94
A, B, C = list(map(int,input().split())) for i in range(1,10000): a = A*i if a % B == C: print('YES') exit() print('NO')
A, B, C = list(map(int,input().split())) for i in range(1,B+1): a = A*i if a % B == C: print('YES') exit() print('NO')
10
10
151
149
A, B, C = list(map(int, input().split())) for i in range(1, 10000): a = A * i if a % B == C: print("YES") exit() print("NO")
A, B, C = list(map(int, input().split())) for i in range(1, B + 1): a = A * i if a % B == C: print("YES") exit() print("NO")
false
0
[ "-for i in range(1, 10000):", "+for i in range(1, B + 1):" ]
false
0.039197
0.038802
1.010196
[ "s746265817", "s563309412" ]
u492910842
p02608
python
s657328680
s281520852
900
98
70,372
74,212
Accepted
Accepted
89.11
import math n=int(eval(input())) z=0 d=0 ans=0 for i in range(1,n+1): for x in range(1,int(math.sqrt(n)+1)): for y in range(1,int(math.sqrt(n)+1)): d=x*x+y*y+2*x*y-4*(x*x+y*y+x*y-i) if d<0: continue z=(math.sqrt(d)-(x+y))/2 if z.is_integer() and z>=1: ans+=1 else: continue print(ans) ans=0
n=int(eval(input())) v=[0]*10001 for x in range(1,101): for y in range(1,101): for z in range(1,101): d=x*x+y*y+z*z+x*y+x*z+y*z if d>10000: continue else: v[d]+=1 for i in range(n): print((v[i+1]))
19
12
371
242
import math n = int(eval(input())) z = 0 d = 0 ans = 0 for i in range(1, n + 1): for x in range(1, int(math.sqrt(n) + 1)): for y in range(1, int(math.sqrt(n) + 1)): d = x * x + y * y + 2 * x * y - 4 * (x * x + y * y + x * y - i) if d < 0: continue z = (math.sqrt(d) - (x + y)) / 2 if z.is_integer() and z >= 1: ans += 1 else: continue print(ans) ans = 0
n = int(eval(input())) v = [0] * 10001 for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): d = x * x + y * y + z * z + x * y + x * z + y * z if d > 10000: continue else: v[d] += 1 for i in range(n): print((v[i + 1]))
false
36.842105
[ "-import math", "-", "-z = 0", "-d = 0", "-ans = 0", "-for i in range(1, n + 1):", "- for x in range(1, int(math.sqrt(n) + 1)):", "- for y in range(1, int(math.sqrt(n) + 1)):", "- d = x * x + y * y + 2 * x * y - 4 * (x * x + y * y + x * y - i)", "- if d < 0:", "+v = [0] * 10001", "+for x in range(1, 101):", "+ for y in range(1, 101):", "+ for z in range(1, 101):", "+ d = x * x + y * y + z * z + x * y + x * z + y * z", "+ if d > 10000:", "- z = (math.sqrt(d) - (x + y)) / 2", "- if z.is_integer() and z >= 1:", "- ans += 1", "- continue", "- print(ans)", "- ans = 0", "+ v[d] += 1", "+for i in range(n):", "+ print((v[i + 1]))" ]
false
0.04516
0.57374
0.078711
[ "s657328680", "s281520852" ]
u086056891
p03240
python
s562313227
s274261780
129
37
3,064
3,188
Accepted
Accepted
71.32
n = int(eval(input())) p = [list(map(int, input().split())) for _ in range(n)] for cx in range(101): for cy in range(101): for xi, yi, hi in p: if hi > 0: h = abs(xi - cx) + abs(yi - cy) + hi break if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p): print((cx, cy, h)) exit()
n = int(eval(input())) p = [list(map(int, input().split())) for _ in range(n)] p.sort(key=lambda x: x[2], reverse=True) for cx in range(101): for cy in range(101): x0, y0, h0 = p[0] h = abs(x0 - cx) + abs(y0 - cy) + h0 if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p): print((cx, cy, h)) exit()
12
11
390
374
n = int(eval(input())) p = [list(map(int, input().split())) for _ in range(n)] for cx in range(101): for cy in range(101): for xi, yi, hi in p: if hi > 0: h = abs(xi - cx) + abs(yi - cy) + hi break if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p): print((cx, cy, h)) exit()
n = int(eval(input())) p = [list(map(int, input().split())) for _ in range(n)] p.sort(key=lambda x: x[2], reverse=True) for cx in range(101): for cy in range(101): x0, y0, h0 = p[0] h = abs(x0 - cx) + abs(y0 - cy) + h0 if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p): print((cx, cy, h)) exit()
false
8.333333
[ "+p.sort(key=lambda x: x[2], reverse=True)", "- for xi, yi, hi in p:", "- if hi > 0:", "- h = abs(xi - cx) + abs(yi - cy) + hi", "- break", "+ x0, y0, h0 = p[0]", "+ h = abs(x0 - cx) + abs(y0 - cy) + h0" ]
false
0.039859
0.040082
0.99444
[ "s562313227", "s274261780" ]
u591503175
p02796
python
s060039234
s934641538
480
436
39,464
40,312
Accepted
Accepted
9.17
N = int(eval(input())) num_list = [[int(item) for item in input().split()] for _ in range(N)] num_list2 = [] for x, l in num_list: num_list2.append([x-l, x+l]) num_list2.sort(key=lambda x: x[1]) # print(num_list2) temp_max = num_list2[0][1] cnt = 1 for l, h in num_list2: if l >= temp_max: cnt += 1 temp_max = h print(cnt)
def resolve(): ''' code here ''' N = int(eval(input())) robots = [[int(item) for item in input().split()] for _ in range(N)] arm_body_arm = [] for body, arm in robots: arm_body_arm.append([body - arm, body + arm]) arm_body_arm = sorted(arm_body_arm, key=lambda x:x[1]) res = 1 prev = arm_body_arm[0][1] for start, end in arm_body_arm: if prev <= start: res += 1 prev = end print(res) if __name__ == "__main__": resolve()
18
26
363
543
N = int(eval(input())) num_list = [[int(item) for item in input().split()] for _ in range(N)] num_list2 = [] for x, l in num_list: num_list2.append([x - l, x + l]) num_list2.sort(key=lambda x: x[1]) # print(num_list2) temp_max = num_list2[0][1] cnt = 1 for l, h in num_list2: if l >= temp_max: cnt += 1 temp_max = h print(cnt)
def resolve(): """ code here """ N = int(eval(input())) robots = [[int(item) for item in input().split()] for _ in range(N)] arm_body_arm = [] for body, arm in robots: arm_body_arm.append([body - arm, body + arm]) arm_body_arm = sorted(arm_body_arm, key=lambda x: x[1]) res = 1 prev = arm_body_arm[0][1] for start, end in arm_body_arm: if prev <= start: res += 1 prev = end print(res) if __name__ == "__main__": resolve()
false
30.769231
[ "-N = int(eval(input()))", "-num_list = [[int(item) for item in input().split()] for _ in range(N)]", "-num_list2 = []", "-for x, l in num_list:", "- num_list2.append([x - l, x + l])", "-num_list2.sort(key=lambda x: x[1])", "-# print(num_list2)", "-temp_max = num_list2[0][1]", "-cnt = 1", "-for l, h in num_list2:", "- if l >= temp_max:", "- cnt += 1", "- temp_max = h", "-print(cnt)", "+def resolve():", "+ \"\"\"", "+ code here", "+ \"\"\"", "+ N = int(eval(input()))", "+ robots = [[int(item) for item in input().split()] for _ in range(N)]", "+ arm_body_arm = []", "+ for body, arm in robots:", "+ arm_body_arm.append([body - arm, body + arm])", "+ arm_body_arm = sorted(arm_body_arm, key=lambda x: x[1])", "+ res = 1", "+ prev = arm_body_arm[0][1]", "+ for start, end in arm_body_arm:", "+ if prev <= start:", "+ res += 1", "+ prev = end", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.04346
0.04517
0.962151
[ "s060039234", "s934641538" ]
u843175622
p03352
python
s720893645
s132824573
32
24
9,164
9,108
Accepted
Accepted
25
x = int(eval(input())) print((max([pow(i, j) for i in range(1, 32) for j in range(2, 10) if pow(i, j) <= x])))
x = int(eval(input())) table = [False] * -~x table[1] = True for i in range(2, 32): j = i * i while j <= x: table[j] = True j *= i print((max(i for i in range(x + 1) if table[i])))
3
11
116
209
x = int(eval(input())) print((max([pow(i, j) for i in range(1, 32) for j in range(2, 10) if pow(i, j) <= x])))
x = int(eval(input())) table = [False] * -~x table[1] = True for i in range(2, 32): j = i * i while j <= x: table[j] = True j *= i print((max(i for i in range(x + 1) if table[i])))
false
72.727273
[ "-print((max([pow(i, j) for i in range(1, 32) for j in range(2, 10) if pow(i, j) <= x])))", "+table = [False] * -~x", "+table[1] = True", "+for i in range(2, 32):", "+ j = i * i", "+ while j <= x:", "+ table[j] = True", "+ j *= i", "+print((max(i for i in range(x + 1) if table[i])))" ]
false
0.04812
0.048049
1.001478
[ "s720893645", "s132824573" ]
u597374218
p03434
python
s487745050
s594740355
19
17
3,316
2,940
Accepted
Accepted
10.53
eval(input()) l=sorted(map(int,input().split()))[::-1] print((sum(l[::2])-sum(l[1::2])))
eval(input()) a=sorted(map(int,input().split()))[::-1] print((sum(a[::2])-sum(a[1::2])))
3
3
82
82
eval(input()) l = sorted(map(int, input().split()))[::-1] print((sum(l[::2]) - sum(l[1::2])))
eval(input()) a = sorted(map(int, input().split()))[::-1] print((sum(a[::2]) - sum(a[1::2])))
false
0
[ "-l = sorted(map(int, input().split()))[::-1]", "-print((sum(l[::2]) - sum(l[1::2])))", "+a = sorted(map(int, input().split()))[::-1]", "+print((sum(a[::2]) - sum(a[1::2])))" ]
false
0.036759
0.035105
1.0471
[ "s487745050", "s594740355" ]
u602677143
p02813
python
s165530017
s556988424
39
27
10,228
8,052
Accepted
Accepted
30.77
#ABC150C import itertools n = int(eval(input())) ls = [i+1 for i in range(n)] p = list(map(int,input().split())) q = list(map(int,input().split())) v = [ list(v) for v in itertools.permutations(ls, n)] a, b = v.index(p), v.index(q) print((abs(a-b)))
#ABC150C import itertools n = int(eval(input())) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) ls = list(itertools.permutations(list(range(1,n+1)))) print((abs(ls.index(p)-ls.index(q))))
9
7
249
204
# ABC150C import itertools n = int(eval(input())) ls = [i + 1 for i in range(n)] p = list(map(int, input().split())) q = list(map(int, input().split())) v = [list(v) for v in itertools.permutations(ls, n)] a, b = v.index(p), v.index(q) print((abs(a - b)))
# ABC150C import itertools n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) ls = list(itertools.permutations(list(range(1, n + 1)))) print((abs(ls.index(p) - ls.index(q))))
false
22.222222
[ "-ls = [i + 1 for i in range(n)]", "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-v = [list(v) for v in itertools.permutations(ls, n)]", "-a, b = v.index(p), v.index(q)", "-print((abs(a - b)))", "+p = tuple(map(int, input().split()))", "+q = tuple(map(int, input().split()))", "+ls = list(itertools.permutations(list(range(1, n + 1))))", "+print((abs(ls.index(p) - ls.index(q))))" ]
false
0.039472
0.061246
0.644479
[ "s165530017", "s556988424" ]
u888092736
p03786
python
s092496542
s340870612
312
91
14,432
14,432
Accepted
Accepted
70.83
from bisect import bisect_right from itertools import accumulate N = int(eval(input())) A = sorted(map(int, input().split())) acc_A = list(accumulate(A)) ans = 0 for i in range(N): prev = i while True: idx = bisect_right(A, 2 * acc_A[prev], lo=prev) - 1 if idx == N - 1: ans += 1 break if idx == prev: break prev = idx print(ans)
from bisect import bisect_right from itertools import accumulate def can_survive(prev): while True: idx = bisect_right(A, 2 * acc_A[prev]) - 1 if idx == N - 1: return True if idx == prev: return False prev = idx def binary_search(left, right): while right - left > 1: mid = (left + right) // 2 if can_survive(mid): right = mid else: left = mid return left if can_survive(left) else right N = int(eval(input())) A = sorted(map(int, input().split())) acc_A = list(accumulate(A)) print((N - binary_search(0, N)))
19
28
420
651
from bisect import bisect_right from itertools import accumulate N = int(eval(input())) A = sorted(map(int, input().split())) acc_A = list(accumulate(A)) ans = 0 for i in range(N): prev = i while True: idx = bisect_right(A, 2 * acc_A[prev], lo=prev) - 1 if idx == N - 1: ans += 1 break if idx == prev: break prev = idx print(ans)
from bisect import bisect_right from itertools import accumulate def can_survive(prev): while True: idx = bisect_right(A, 2 * acc_A[prev]) - 1 if idx == N - 1: return True if idx == prev: return False prev = idx def binary_search(left, right): while right - left > 1: mid = (left + right) // 2 if can_survive(mid): right = mid else: left = mid return left if can_survive(left) else right N = int(eval(input())) A = sorted(map(int, input().split())) acc_A = list(accumulate(A)) print((N - binary_search(0, N)))
false
32.142857
[ "+", "+", "+def can_survive(prev):", "+ while True:", "+ idx = bisect_right(A, 2 * acc_A[prev]) - 1", "+ if idx == N - 1:", "+ return True", "+ if idx == prev:", "+ return False", "+ prev = idx", "+", "+", "+def binary_search(left, right):", "+ while right - left > 1:", "+ mid = (left + right) // 2", "+ if can_survive(mid):", "+ right = mid", "+ else:", "+ left = mid", "+ return left if can_survive(left) else right", "+", "-ans = 0", "-for i in range(N):", "- prev = i", "- while True:", "- idx = bisect_right(A, 2 * acc_A[prev], lo=prev) - 1", "- if idx == N - 1:", "- ans += 1", "- break", "- if idx == prev:", "- break", "- prev = idx", "-print(ans)", "+print((N - binary_search(0, N)))" ]
false
0.183003
0.037643
4.861555
[ "s092496542", "s340870612" ]
u860657719
p02744
python
s797897716
s107084716
155
88
29,500
9,068
Accepted
Accepted
43.23
n = int(eval(input())) dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"} ans = [["a", 1]] for i in range(n-1): newans = [] for lis in ans: now = lis[0] count = lis[1] for j in range(1, count + 2): newans.append([now + dict[j], max(j, count)]) ans = newans for lis in ans: print((lis[0]))
n = int(eval(input())) dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"} dict2 = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10} #ans = [["a", 1]] #for i in range(n-1): # newans = [] # for lis in ans: # now = lis[0] # count = lis[1] # for j in range(1, count + 2): # newans.append([now + dict[j], max(j, count)]) # ans = newans #for lis in ans: # print(lis[0]) def dfs(s): if len(s) == n: print(s) return m = max(s) count = dict2[m] for i in range(1, count+2): dfs(s+dict[i]) dfs("a")
13
23
372
637
n = int(eval(input())) dict = {1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h", 9: "i", 10: "j"} ans = [["a", 1]] for i in range(n - 1): newans = [] for lis in ans: now = lis[0] count = lis[1] for j in range(1, count + 2): newans.append([now + dict[j], max(j, count)]) ans = newans for lis in ans: print((lis[0]))
n = int(eval(input())) dict = {1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h", 9: "i", 10: "j"} dict2 = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, } # ans = [["a", 1]] # for i in range(n-1): # newans = [] # for lis in ans: # now = lis[0] # count = lis[1] # for j in range(1, count + 2): # newans.append([now + dict[j], max(j, count)]) # ans = newans # for lis in ans: # print(lis[0]) def dfs(s): if len(s) == n: print(s) return m = max(s) count = dict2[m] for i in range(1, count + 2): dfs(s + dict[i]) dfs("a")
false
43.478261
[ "-ans = [[\"a\", 1]]", "-for i in range(n - 1):", "- newans = []", "- for lis in ans:", "- now = lis[0]", "- count = lis[1]", "- for j in range(1, count + 2):", "- newans.append([now + dict[j], max(j, count)])", "- ans = newans", "-for lis in ans:", "- print((lis[0]))", "+dict2 = {", "+ \"a\": 1,", "+ \"b\": 2,", "+ \"c\": 3,", "+ \"d\": 4,", "+ \"e\": 5,", "+ \"f\": 6,", "+ \"g\": 7,", "+ \"h\": 8,", "+ \"i\": 9,", "+ \"j\": 10,", "+}", "+# ans = [[\"a\", 1]]", "+# for i in range(n-1):", "+# newans = []", "+# for lis in ans:", "+# now = lis[0]", "+# count = lis[1]", "+# for j in range(1, count + 2):", "+# newans.append([now + dict[j], max(j, count)])", "+# ans = newans", "+# for lis in ans:", "+# print(lis[0])", "+def dfs(s):", "+ if len(s) == n:", "+ print(s)", "+ return", "+ m = max(s)", "+ count = dict2[m]", "+ for i in range(1, count + 2):", "+ dfs(s + dict[i])", "+", "+", "+dfs(\"a\")" ]
false
0.169536
0.126765
1.337402
[ "s797897716", "s107084716" ]
u586759271
p02912
python
s318437505
s188397712
655
402
94,232
72,088
Accepted
Accepted
38.63
import heapq n,m=list(map(int,input().split())) a=[-int(i) for i in input().split()] heapq.heapify(a) for i in range(m): b=-heapq.heappop(a) heapq.heappush(a,-b/2) print((int( sum(-i//1 for i in a)) ))
n,m=list(map(int,input().split())) a=[-int(aa) for aa in input().split() ] import heapq heapq.heapify(a) for _ in range(m): now = -heapq.heappop(a) heapq.heappush(a,- (now//2) ) print((-sum(a)))
8
10
208
205
import heapq n, m = list(map(int, input().split())) a = [-int(i) for i in input().split()] heapq.heapify(a) for i in range(m): b = -heapq.heappop(a) heapq.heappush(a, -b / 2) print((int(sum(-i // 1 for i in a))))
n, m = list(map(int, input().split())) a = [-int(aa) for aa in input().split()] import heapq heapq.heapify(a) for _ in range(m): now = -heapq.heappop(a) heapq.heappush(a, -(now // 2)) print((-sum(a)))
false
20
[ "+n, m = list(map(int, input().split()))", "+a = [-int(aa) for aa in input().split()]", "-n, m = list(map(int, input().split()))", "-a = [-int(i) for i in input().split()]", "-for i in range(m):", "- b = -heapq.heappop(a)", "- heapq.heappush(a, -b / 2)", "-print((int(sum(-i // 1 for i in a))))", "+for _ in range(m):", "+ now = -heapq.heappop(a)", "+ heapq.heappush(a, -(now // 2))", "+print((-sum(a)))" ]
false
0.040413
0.0597
0.676933
[ "s318437505", "s188397712" ]
u836737505
p03379
python
s591678858
s663596292
306
281
25,220
26,772
Accepted
Accepted
8.17
n = int(eval(input())) l = list(map(int,input().split())) lsort = sorted(l) l1 = lsort[n//2-1] l2 = lsort[n//2] for i in l: print((l1 if i>=l2 else l2))
n = int(eval(input())) x = list(map(int,input().split())) x_sort = sorted(x) mini = x_sort[n//2-1] maxi = x_sort[n//2] if mini == maxi: for _ in range(n): print(mini) else: for a in x: if a < maxi: print(maxi) else: print(mini)
7
14
154
290
n = int(eval(input())) l = list(map(int, input().split())) lsort = sorted(l) l1 = lsort[n // 2 - 1] l2 = lsort[n // 2] for i in l: print((l1 if i >= l2 else l2))
n = int(eval(input())) x = list(map(int, input().split())) x_sort = sorted(x) mini = x_sort[n // 2 - 1] maxi = x_sort[n // 2] if mini == maxi: for _ in range(n): print(mini) else: for a in x: if a < maxi: print(maxi) else: print(mini)
false
50
[ "-l = list(map(int, input().split()))", "-lsort = sorted(l)", "-l1 = lsort[n // 2 - 1]", "-l2 = lsort[n // 2]", "-for i in l:", "- print((l1 if i >= l2 else l2))", "+x = list(map(int, input().split()))", "+x_sort = sorted(x)", "+mini = x_sort[n // 2 - 1]", "+maxi = x_sort[n // 2]", "+if mini == maxi:", "+ for _ in range(n):", "+ print(mini)", "+else:", "+ for a in x:", "+ if a < maxi:", "+ print(maxi)", "+ else:", "+ print(mini)" ]
false
0.046432
0.046219
1.004611
[ "s591678858", "s663596292" ]
u647766105
p00190
python
s537275175
s055213504
3,050
450
6,464
5,152
Accepted
Accepted
85.25
from math import factorial from queue import PriorityQueue FACTORIAL=[factorial(i) for i in range(13)] LEFT,UP,RIGHT,DOWN=0,1,2,3 MOVE=[[0] for u in range(13)] MOVE[0] =[-1,-1,-1, 2] MOVE[1] =[-1,-1, 2, 5] MOVE[2] =[ 1, 0, 3, 6] MOVE[3] =[ 2,-1,-1, 7] MOVE[4] =[-1,-1, 5,-1] MOVE[5] =[ 4, 1, 6, 9] MOVE[6] =[ 5, 2, 7,10] MOVE[7] =[ 6, 3, 8,11] MOVE[8] =[ 7,-1,-1,-1] MOVE[9] =[-1, 5,10,-1] MOVE[10]=[ 9, 6,11,12] MOVE[11]=[10, 7,-1,-1] MOVE[12]=[-1,10,-1,-1] """ MOVE[0][LEFT]=MOVE[1][LEFT]=MOVE[4][LEFT]=MOVE[9][LEFT]=MOVE[12][LEFT]=False MOVE[0][UP]=MOVE[1][UP]=MOVE[3][UP]=MOVE[4][UP]=MOVE[8][UP]=False MOVE[0][RIGHT]=MOVE[3][RIGHT]=MOVE[8][RIGHT]=MOVE[11][RIGHT]=MOVE[12][RIGHT]=False MOVE[4][DOWN]=MOVE[8][DOWN]=MOVE[9][DOWN]=MOVE[11][DOWN]=MOVE[12][DOWN]=False """ def hash(cell): work = cell[:] hash = 0 for i in range(12): hash += work[i] * FACTORIAL[13-1-i] for ii in range(i+1,13): if work[ii]>work[i]: work[ii]-=1 return hash def dehash(key): cell=[] for i in range(13): cell.append(key/FACTORIAL[13-1-i]) key %= FACTORIAL[13-1-i] for i in range(13-1,-1,-1): for ii in range(i+1,13): if cell[i]<=cell[ii]: cell[ii]+=1 return cell def evaluate(cell): point=[[0,2], [1,1],[1,2],[1,3], [2,0],[2,1],[2,2],[2,3],[2,4], [3,1],[3,2],[3,3], [4,2]] eva=0 for i in range(0,13): if not (cell[i]==0 or cell[i]==12): eva+=abs(point[cell[i]][0]-point[i][0]) eva+=abs(point[cell[i]][1]-point[i][1]) return eva ANS_HASH=[hash([0,1,2,3,4,5,6,7,8,9,10,11,12]),hash([12,1,2,3,4,5,6,7,8,9,10,11,0])] while True: p=[eval(input())] if p==[-1]: break for u in range(4): for pp in map(int,input().split()): p.append(pp) p[p.index(0)]=12 pq = PriorityQueue() pq.put([evaluate(p),hash(p),0]) visited={} visited[hash(p)]=True ans=0 if hash(p) in ANS_HASH else "NA" #cur=[eva,hashkey,step] while not pq.empty(): unused,cur_hash,cur_step=pq.get() cur_cell=dehash(cur_hash) """ print "STEP",cur_step print [cur_cell[0]] print cur_cell[1:4] print cur_cell[4:9] print cur_cell[9:12] print [cur_cell[12]] print """ if not (cur_step<20 and ans=="NA"): break for i in range(13): if cur_cell[i]==0 or cur_cell[i]==12: #print cur_cell[i] for ii in [LEFT,UP,RIGHT,DOWN]: #print ii, if not MOVE[i][ii]==-1: #print "MOVE" cur_cell[i],cur_cell[MOVE[i][ii]]=cur_cell[MOVE[i][ii]],cur_cell[i] """ print "MOVING",ii print [cur_cell[0]] print cur_cell[1:4] print cur_cell[4:9] print cur_cell[9:12] print [cur_cell[12]] """ hashkey=hash(cur_cell) if not hashkey in visited: if hashkey in ANS_HASH: ans=cur_step+1 break pq.put([evaluate(cur_cell)+cur_step+1,hashkey,cur_step+1]) visited[hashkey]=True cur_cell[i],cur_cell[MOVE[i][ii]]=cur_cell[MOVE[i][ii]],cur_cell[i] else: pass #print print(ans)
from math import factorial from queue import PriorityQueue FACTORIAL=[factorial(i) for i in range(13)] LEFT,UP,RIGHT,DOWN=0,1,2,3 MOVE=[[0] for u in range(13)] MOVE[0] =[-1,-1,-1, 2] MOVE[1] =[-1,-1, 2, 5] MOVE[2] =[ 1, 0, 3, 6] MOVE[3] =[ 2,-1,-1, 7] MOVE[4] =[-1,-1, 5,-1] MOVE[5] =[ 4, 1, 6, 9] MOVE[6] =[ 5, 2, 7,10] MOVE[7] =[ 6, 3, 8,11] MOVE[8] =[ 7,-1,-1,-1] MOVE[9] =[-1, 5,10,-1] MOVE[10]=[ 9, 6,11,12] MOVE[11]=[10, 7,-1,-1] MOVE[12]=[-1,10,-1,-1] def hash(cell): work = cell[:] hash = 0 for i in range(12): hash += work[i] * FACTORIAL[13-1-i] for ii in range(i+1,13): if work[ii]>work[i]: work[ii]-=1 return hash def dehash(key): cell=[] for i in range(13): cell.append(key/FACTORIAL[13-1-i]) key %= FACTORIAL[13-1-i] for i in range(13-1,-1,-1): for ii in range(i+1,13): if cell[i]<=cell[ii]: cell[ii]+=1 return cell def evaluate(cell): point=[[0,2], [1,1],[1,2],[1,3], [2,0],[2,1],[2,2],[2,3],[2,4], [3,1],[3,2],[3,3], [4,2]] eva=0 for i in range(0,13): if not (cell[i]==0 or cell[i]==12): eva+=abs(point[cell[i]][0]-point[i][0]) eva+=abs(point[cell[i]][1]-point[i][1]) return eva ANS_HASH=[hash([0,1,2,3,4,5,6,7,8,9,10,11,12]),hash([12,1,2,3,4,5,6,7,8,9,10,11,0])] while True: p=[eval(input())] if p==[-1]: break for u in range(4): for pp in map(int,input().split()): p.append(pp) p[p.index(0)]=12 pq = PriorityQueue() pq.put([evaluate(p),hash(p),0]) visited={} visited[hash(p)]=True ans=0 if hash(p) in ANS_HASH else "NA" #cur=[eva,hashkey,step] while not pq.empty(): eva,cur_hash,cur_step=pq.get() cur_cell=dehash(cur_hash) if not (eva<=20 and ans=="NA"): break for i in range(13): if cur_cell[i]==0 or cur_cell[i]==12: for ii in [LEFT,UP,RIGHT,DOWN]: if not MOVE[i][ii]==-1: cur_cell[i],cur_cell[MOVE[i][ii]]=cur_cell[MOVE[i][ii]],cur_cell[i] hashkey=hash(cur_cell) if not hashkey in visited: if hashkey in ANS_HASH: ans=cur_step+1 break pq.put([evaluate(cur_cell)+cur_step+1,hashkey,cur_step+1]) visited[hashkey]=True cur_cell[i],cur_cell[MOVE[i][ii]]=cur_cell[MOVE[i][ii]],cur_cell[i] print(ans)
119
89
3,829
2,758
from math import factorial from queue import PriorityQueue FACTORIAL = [factorial(i) for i in range(13)] LEFT, UP, RIGHT, DOWN = 0, 1, 2, 3 MOVE = [[0] for u in range(13)] MOVE[0] = [-1, -1, -1, 2] MOVE[1] = [-1, -1, 2, 5] MOVE[2] = [1, 0, 3, 6] MOVE[3] = [2, -1, -1, 7] MOVE[4] = [-1, -1, 5, -1] MOVE[5] = [4, 1, 6, 9] MOVE[6] = [5, 2, 7, 10] MOVE[7] = [6, 3, 8, 11] MOVE[8] = [7, -1, -1, -1] MOVE[9] = [-1, 5, 10, -1] MOVE[10] = [9, 6, 11, 12] MOVE[11] = [10, 7, -1, -1] MOVE[12] = [-1, 10, -1, -1] """ MOVE[0][LEFT]=MOVE[1][LEFT]=MOVE[4][LEFT]=MOVE[9][LEFT]=MOVE[12][LEFT]=False MOVE[0][UP]=MOVE[1][UP]=MOVE[3][UP]=MOVE[4][UP]=MOVE[8][UP]=False MOVE[0][RIGHT]=MOVE[3][RIGHT]=MOVE[8][RIGHT]=MOVE[11][RIGHT]=MOVE[12][RIGHT]=False MOVE[4][DOWN]=MOVE[8][DOWN]=MOVE[9][DOWN]=MOVE[11][DOWN]=MOVE[12][DOWN]=False """ def hash(cell): work = cell[:] hash = 0 for i in range(12): hash += work[i] * FACTORIAL[13 - 1 - i] for ii in range(i + 1, 13): if work[ii] > work[i]: work[ii] -= 1 return hash def dehash(key): cell = [] for i in range(13): cell.append(key / FACTORIAL[13 - 1 - i]) key %= FACTORIAL[13 - 1 - i] for i in range(13 - 1, -1, -1): for ii in range(i + 1, 13): if cell[i] <= cell[ii]: cell[ii] += 1 return cell def evaluate(cell): point = [ [0, 2], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [4, 2], ] eva = 0 for i in range(0, 13): if not (cell[i] == 0 or cell[i] == 12): eva += abs(point[cell[i]][0] - point[i][0]) eva += abs(point[cell[i]][1] - point[i][1]) return eva ANS_HASH = [ hash([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), hash([12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]), ] while True: p = [eval(input())] if p == [-1]: break for u in range(4): for pp in map(int, input().split()): p.append(pp) p[p.index(0)] = 12 pq = PriorityQueue() pq.put([evaluate(p), hash(p), 0]) visited = {} visited[hash(p)] = True ans = 0 if hash(p) in ANS_HASH else "NA" # cur=[eva,hashkey,step] while not pq.empty(): unused, cur_hash, cur_step = pq.get() cur_cell = dehash(cur_hash) """ print "STEP",cur_step print [cur_cell[0]] print cur_cell[1:4] print cur_cell[4:9] print cur_cell[9:12] print [cur_cell[12]] print """ if not (cur_step < 20 and ans == "NA"): break for i in range(13): if cur_cell[i] == 0 or cur_cell[i] == 12: # print cur_cell[i] for ii in [LEFT, UP, RIGHT, DOWN]: # print ii, if not MOVE[i][ii] == -1: # print "MOVE" cur_cell[i], cur_cell[MOVE[i][ii]] = ( cur_cell[MOVE[i][ii]], cur_cell[i], ) """ print "MOVING",ii print [cur_cell[0]] print cur_cell[1:4] print cur_cell[4:9] print cur_cell[9:12] print [cur_cell[12]] """ hashkey = hash(cur_cell) if not hashkey in visited: if hashkey in ANS_HASH: ans = cur_step + 1 break pq.put( [ evaluate(cur_cell) + cur_step + 1, hashkey, cur_step + 1, ] ) visited[hashkey] = True cur_cell[i], cur_cell[MOVE[i][ii]] = ( cur_cell[MOVE[i][ii]], cur_cell[i], ) else: pass # print print(ans)
from math import factorial from queue import PriorityQueue FACTORIAL = [factorial(i) for i in range(13)] LEFT, UP, RIGHT, DOWN = 0, 1, 2, 3 MOVE = [[0] for u in range(13)] MOVE[0] = [-1, -1, -1, 2] MOVE[1] = [-1, -1, 2, 5] MOVE[2] = [1, 0, 3, 6] MOVE[3] = [2, -1, -1, 7] MOVE[4] = [-1, -1, 5, -1] MOVE[5] = [4, 1, 6, 9] MOVE[6] = [5, 2, 7, 10] MOVE[7] = [6, 3, 8, 11] MOVE[8] = [7, -1, -1, -1] MOVE[9] = [-1, 5, 10, -1] MOVE[10] = [9, 6, 11, 12] MOVE[11] = [10, 7, -1, -1] MOVE[12] = [-1, 10, -1, -1] def hash(cell): work = cell[:] hash = 0 for i in range(12): hash += work[i] * FACTORIAL[13 - 1 - i] for ii in range(i + 1, 13): if work[ii] > work[i]: work[ii] -= 1 return hash def dehash(key): cell = [] for i in range(13): cell.append(key / FACTORIAL[13 - 1 - i]) key %= FACTORIAL[13 - 1 - i] for i in range(13 - 1, -1, -1): for ii in range(i + 1, 13): if cell[i] <= cell[ii]: cell[ii] += 1 return cell def evaluate(cell): point = [ [0, 2], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [4, 2], ] eva = 0 for i in range(0, 13): if not (cell[i] == 0 or cell[i] == 12): eva += abs(point[cell[i]][0] - point[i][0]) eva += abs(point[cell[i]][1] - point[i][1]) return eva ANS_HASH = [ hash([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), hash([12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]), ] while True: p = [eval(input())] if p == [-1]: break for u in range(4): for pp in map(int, input().split()): p.append(pp) p[p.index(0)] = 12 pq = PriorityQueue() pq.put([evaluate(p), hash(p), 0]) visited = {} visited[hash(p)] = True ans = 0 if hash(p) in ANS_HASH else "NA" # cur=[eva,hashkey,step] while not pq.empty(): eva, cur_hash, cur_step = pq.get() cur_cell = dehash(cur_hash) if not (eva <= 20 and ans == "NA"): break for i in range(13): if cur_cell[i] == 0 or cur_cell[i] == 12: for ii in [LEFT, UP, RIGHT, DOWN]: if not MOVE[i][ii] == -1: cur_cell[i], cur_cell[MOVE[i][ii]] = ( cur_cell[MOVE[i][ii]], cur_cell[i], ) hashkey = hash(cur_cell) if not hashkey in visited: if hashkey in ANS_HASH: ans = cur_step + 1 break pq.put( [ evaluate(cur_cell) + cur_step + 1, hashkey, cur_step + 1, ] ) visited[hashkey] = True cur_cell[i], cur_cell[MOVE[i][ii]] = ( cur_cell[MOVE[i][ii]], cur_cell[i], ) print(ans)
false
25.210084
[ "-\"\"\"", "-MOVE[0][LEFT]=MOVE[1][LEFT]=MOVE[4][LEFT]=MOVE[9][LEFT]=MOVE[12][LEFT]=False", "-MOVE[0][UP]=MOVE[1][UP]=MOVE[3][UP]=MOVE[4][UP]=MOVE[8][UP]=False", "-MOVE[0][RIGHT]=MOVE[3][RIGHT]=MOVE[8][RIGHT]=MOVE[11][RIGHT]=MOVE[12][RIGHT]=False", "-MOVE[4][DOWN]=MOVE[8][DOWN]=MOVE[9][DOWN]=MOVE[11][DOWN]=MOVE[12][DOWN]=False", "-\"\"\"", "- unused, cur_hash, cur_step = pq.get()", "+ eva, cur_hash, cur_step = pq.get()", "- \"\"\"", "- print \"STEP\",cur_step", "- print [cur_cell[0]]", "- print cur_cell[1:4]", "- print cur_cell[4:9]", "- print cur_cell[9:12]", "- print [cur_cell[12]]", "- print", "- \"\"\"", "- if not (cur_step < 20 and ans == \"NA\"):", "+ if not (eva <= 20 and ans == \"NA\"):", "- # print cur_cell[i]", "- # print ii,", "- # print \"MOVE\"", "- \"\"\"", "- print \"MOVING\",ii", "- print [cur_cell[0]]", "- print cur_cell[1:4]", "- print cur_cell[4:9]", "- print cur_cell[9:12]", "- print [cur_cell[12]]", "- \"\"\"", "- else:", "- pass", "- # print" ]
false
0.118381
0.106132
1.115418
[ "s537275175", "s055213504" ]
u686036872
p02887
python
s574622293
s235533086
46
38
4,084
4,644
Accepted
Accepted
17.39
N = int(eval(input())) S=list(eval(input())) x = S[0] ans = 1 for i in range(1, N): if x != S[i]: ans += 1 x = S[i] print(ans)
import itertools N = int(eval(input())) S = list(eval(input())) s = itertools.groupby(S) ans = [] for key, group in s: ans.append(key) print((len(ans)))
9
10
139
154
N = int(eval(input())) S = list(eval(input())) x = S[0] ans = 1 for i in range(1, N): if x != S[i]: ans += 1 x = S[i] print(ans)
import itertools N = int(eval(input())) S = list(eval(input())) s = itertools.groupby(S) ans = [] for key, group in s: ans.append(key) print((len(ans)))
false
10
[ "+import itertools", "+", "-x = S[0]", "-ans = 1", "-for i in range(1, N):", "- if x != S[i]:", "- ans += 1", "- x = S[i]", "-print(ans)", "+s = itertools.groupby(S)", "+ans = []", "+for key, group in s:", "+ ans.append(key)", "+print((len(ans)))" ]
false
0.008095
0.037518
0.215755
[ "s574622293", "s235533086" ]
u745385679
p03478
python
s802236645
s242792110
33
26
2,940
2,940
Accepted
Accepted
21.21
N, A, B = list(map(int, input().split())) u = 0 for i in range(N+1): num = sum(map(int, list(str(i)))) if num >= A and num <= B: u += i print(u)
def find_sum_of_digits(n): sum = 0 while (n > 0): sum += n % 10 n //= 10 return sum N, A, B = list(map(int, input().split())) u = 0 for i in range(N+1): # num = sum(map(int, list(str(i)))) num = find_sum_of_digits(i) if num >= A and num <= B: u += i print(u)
7
15
161
316
N, A, B = list(map(int, input().split())) u = 0 for i in range(N + 1): num = sum(map(int, list(str(i)))) if num >= A and num <= B: u += i print(u)
def find_sum_of_digits(n): sum = 0 while n > 0: sum += n % 10 n //= 10 return sum N, A, B = list(map(int, input().split())) u = 0 for i in range(N + 1): # num = sum(map(int, list(str(i)))) num = find_sum_of_digits(i) if num >= A and num <= B: u += i print(u)
false
53.333333
[ "+def find_sum_of_digits(n):", "+ sum = 0", "+ while n > 0:", "+ sum += n % 10", "+ n //= 10", "+ return sum", "+", "+", "- num = sum(map(int, list(str(i))))", "+ # num = sum(map(int, list(str(i))))", "+ num = find_sum_of_digits(i)" ]
false
0.038165
0.040595
0.940159
[ "s802236645", "s242792110" ]
u875291233
p03053
python
s365998496
s302088272
662
432
141,148
87,900
Accepted
Accepted
34.74
# coding: utf-8 # Your code here! import collections h,w = [int(i) for i in input().split()] board = [eval(input()) for j in range(h)] # 縦「n」行 d4 = [[1,0],[0,1],[-1,0],[0,-1]] memo = [[-1]*w for j in range(h)] dist = [[100000]*w for j in range(h)] q = collections.deque() for i in range(h): for j in range(w): if board[i][j] == "#": memo[i][j] = 1 q.append((i,j,0)) while len(q) != 0: # print(memo) i,j,c = q.popleft() dist[i][j] = c for k in d4: # print(k) ii,jj = k if i+ii < 0 or i+ii>=h or j+jj <0 or j+jj>=w: # print("out",i+ii,j+jj) continue if memo[i+ii][j+jj] < 0: # print("put") q.append((i+ii,j+jj,c+1)) memo[i+ii][j+jj] = 1 ans = 0 for i in range(h): for j in range(w): ans = max(ans,dist[i][j]) print(ans) #print(dist)
import collections #deque h,w = [int(i) for i in input().split()] board = [eval(input()) for j in range(h)] # 縦「n」行 dx4=[0, 1, 0,-1] dy4=[1, 0,-1, 0] #dx8=[0, 1, 0,-1,1,-1,1,-1] #dy8=[1, 0,-1, 0,1,1,-1,-1] #memo: 負なら未確認、0以上なら最短距離 memo = [[-1]*w for _ in range(h)] q = collections.deque() #初期状態をキューに入れる----------------------------------------------------- #キューに入れる時点で使用したかどうかのmemoを更新----------------------------- for i in range(h): for j in range(w): if board[i][j] == "#": q.append((i,j)) #初期状態をキューに入れる memo[i][j] = 0 #初期状態を訪問済みにする while len(q) != 0: x,y = q.popleft() #キューから情報を取り出す #foreach (x,y)のお隣さん に対して処理------------------------------------- for i in range(4): nx = x + dx4[i] ny = y + dy4[i] #範囲外ならスキップ--------------------------------------------------- if nx < 0 or nx>=h or ny <0 or ny>=w: continue #壁ならスキップ------------------------------------------------------- #if board[nx][ny] == "#": continue #(nx,ny)が確認済みならスキップ---------------------------------------- if memo[nx][ny] >= 0: continue #(nx,ny)が未確認のとき、確認済みにしてキューに入れる------------------ memo[nx][ny] = memo[x][y]+1 q.append((nx,ny)) #経路復元が必要なとき------------------------------------------------- # prev[nx][ny] = [x,y] ans = 0 for i in range(h): for j in range(w): ans = max(ans,memo[i][j]) print(ans)
48
46
980
1,475
# coding: utf-8 # Your code here! import collections h, w = [int(i) for i in input().split()] board = [eval(input()) for j in range(h)] # 縦「n」行 d4 = [[1, 0], [0, 1], [-1, 0], [0, -1]] memo = [[-1] * w for j in range(h)] dist = [[100000] * w for j in range(h)] q = collections.deque() for i in range(h): for j in range(w): if board[i][j] == "#": memo[i][j] = 1 q.append((i, j, 0)) while len(q) != 0: # print(memo) i, j, c = q.popleft() dist[i][j] = c for k in d4: # print(k) ii, jj = k if i + ii < 0 or i + ii >= h or j + jj < 0 or j + jj >= w: # print("out",i+ii,j+jj) continue if memo[i + ii][j + jj] < 0: # print("put") q.append((i + ii, j + jj, c + 1)) memo[i + ii][j + jj] = 1 ans = 0 for i in range(h): for j in range(w): ans = max(ans, dist[i][j]) print(ans) # print(dist)
import collections # deque h, w = [int(i) for i in input().split()] board = [eval(input()) for j in range(h)] # 縦「n」行 dx4 = [0, 1, 0, -1] dy4 = [1, 0, -1, 0] # dx8=[0, 1, 0,-1,1,-1,1,-1] # dy8=[1, 0,-1, 0,1,1,-1,-1] # memo: 負なら未確認、0以上なら最短距離 memo = [[-1] * w for _ in range(h)] q = collections.deque() # 初期状態をキューに入れる----------------------------------------------------- # キューに入れる時点で使用したかどうかのmemoを更新----------------------------- for i in range(h): for j in range(w): if board[i][j] == "#": q.append((i, j)) # 初期状態をキューに入れる memo[i][j] = 0 # 初期状態を訪問済みにする while len(q) != 0: x, y = q.popleft() # キューから情報を取り出す # foreach (x,y)のお隣さん に対して処理------------------------------------- for i in range(4): nx = x + dx4[i] ny = y + dy4[i] # 範囲外ならスキップ--------------------------------------------------- if nx < 0 or nx >= h or ny < 0 or ny >= w: continue # 壁ならスキップ------------------------------------------------------- # if board[nx][ny] == "#": continue # (nx,ny)が確認済みならスキップ---------------------------------------- if memo[nx][ny] >= 0: continue # (nx,ny)が未確認のとき、確認済みにしてキューに入れる------------------ memo[nx][ny] = memo[x][y] + 1 q.append((nx, ny)) # 経路復元が必要なとき------------------------------------------------- # prev[nx][ny] = [x,y] ans = 0 for i in range(h): for j in range(w): ans = max(ans, memo[i][j]) print(ans)
false
4.166667
[ "-# coding: utf-8", "-# Your code here!", "-import collections", "+import collections # deque", "-d4 = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-memo = [[-1] * w for j in range(h)]", "-dist = [[100000] * w for j in range(h)]", "+dx4 = [0, 1, 0, -1]", "+dy4 = [1, 0, -1, 0]", "+# dx8=[0, 1, 0,-1,1,-1,1,-1]", "+# dy8=[1, 0,-1, 0,1,1,-1,-1]", "+# memo: 負なら未確認、0以上なら最短距離", "+memo = [[-1] * w for _ in range(h)]", "- memo[i][j] = 1", "- q.append((i, j, 0))", "+ q.append((i, j)) # 初期状態をキューに入れる", "+ memo[i][j] = 0 # 初期状態を訪問済みにする", "- # print(memo)", "- i, j, c = q.popleft()", "- dist[i][j] = c", "- for k in d4:", "- # print(k)", "- ii, jj = k", "- if i + ii < 0 or i + ii >= h or j + jj < 0 or j + jj >= w:", "- # print(\"out\",i+ii,j+jj)", "+ x, y = q.popleft() # キューから情報を取り出す", "+ for i in range(4):", "+ nx = x + dx4[i]", "+ ny = y + dy4[i]", "+ if nx < 0 or nx >= h or ny < 0 or ny >= w:", "- if memo[i + ii][j + jj] < 0:", "- # print(\"put\")", "- q.append((i + ii, j + jj, c + 1))", "- memo[i + ii][j + jj] = 1", "+ # if board[nx][ny] == \"#\": continue", "+ if memo[nx][ny] >= 0:", "+ continue", "+ memo[nx][ny] = memo[x][y] + 1", "+ q.append((nx, ny))", "+ # prev[nx][ny] = [x,y]", "- ans = max(ans, dist[i][j])", "+ ans = max(ans, memo[i][j])", "-# print(dist)" ]
false
0.037588
0.036527
1.029059
[ "s365998496", "s302088272" ]
u572122511
p02688
python
s267962038
s592663651
26
22
9,184
9,192
Accepted
Accepted
15.38
N, K = list(map(int, input().split())) haves = [False for _ in range(N)] def judge_Flag(flags): As = list(map(int, input().split())) for A in As: flags[A - 1] = True for _ in range(K): people_num = int(eval(input())) judge_Flag(haves) print((haves.count(False)))
N, K = list(map(int, input().split())) haves = [False for _ in range(N)] def judge_Flag(flags, num): As = list(map(int, input().split())) for i in range(num): flags[As[i] - 1] = True for _ in range(K): people_num = int(eval(input())) judge_Flag(haves, people_num) print((haves.count(False)))
12
12
291
329
N, K = list(map(int, input().split())) haves = [False for _ in range(N)] def judge_Flag(flags): As = list(map(int, input().split())) for A in As: flags[A - 1] = True for _ in range(K): people_num = int(eval(input())) judge_Flag(haves) print((haves.count(False)))
N, K = list(map(int, input().split())) haves = [False for _ in range(N)] def judge_Flag(flags, num): As = list(map(int, input().split())) for i in range(num): flags[As[i] - 1] = True for _ in range(K): people_num = int(eval(input())) judge_Flag(haves, people_num) print((haves.count(False)))
false
0
[ "-def judge_Flag(flags):", "+def judge_Flag(flags, num):", "- for A in As:", "- flags[A - 1] = True", "+ for i in range(num):", "+ flags[As[i] - 1] = True", "- judge_Flag(haves)", "+ judge_Flag(haves, people_num)" ]
false
0.036228
0.037374
0.969348
[ "s267962038", "s592663651" ]
u347640436
p02793
python
s019086375
s137131306
1,889
480
6,140
14,540
Accepted
Accepted
74.59
from sys import stdin from fractions import gcd from functools import reduce N = int(stdin.readline()) A = list(map(int, stdin.readline().split())) lcm = reduce(lambda a, b: a * b // gcd(a, b), A) print((sum(lcm // a for a in A) % 1000000007))
# エラトステネスの篩, フェルマーの小定理 max_A = 1000000 N = int(eval(input())) A = list(map(int, input().split())) sieve = [0] * (max_A + 1) sieve[0] = -1 sieve[1] = -1 for i in range(2, max_A + 1): if sieve[i] != 0: continue sieve[i] = i for j in range(i * i, max_A + 1, i): if sieve[j] == 0: sieve[j] = i lcm_factors = {} for i in range(N): t = [] a = A[i] while a != 1: if len(t) != 0 and t[-1][0] == sieve[a]: t[-1][1] += 1 else: t.append([sieve[a], 1]) a //= sieve[a] for k, v in t: if k not in lcm_factors or lcm_factors[k] < v: lcm_factors[k] = v lcm = 1 for k in lcm_factors: for i in range(lcm_factors[k]): lcm *= k lcm %= 1000000007 result = 0 for i in range(N): result += lcm * pow(A[i], 1000000007-2, 1000000007) result %= 1000000007 print(result)
9
42
252
935
from sys import stdin from fractions import gcd from functools import reduce N = int(stdin.readline()) A = list(map(int, stdin.readline().split())) lcm = reduce(lambda a, b: a * b // gcd(a, b), A) print((sum(lcm // a for a in A) % 1000000007))
# エラトステネスの篩, フェルマーの小定理 max_A = 1000000 N = int(eval(input())) A = list(map(int, input().split())) sieve = [0] * (max_A + 1) sieve[0] = -1 sieve[1] = -1 for i in range(2, max_A + 1): if sieve[i] != 0: continue sieve[i] = i for j in range(i * i, max_A + 1, i): if sieve[j] == 0: sieve[j] = i lcm_factors = {} for i in range(N): t = [] a = A[i] while a != 1: if len(t) != 0 and t[-1][0] == sieve[a]: t[-1][1] += 1 else: t.append([sieve[a], 1]) a //= sieve[a] for k, v in t: if k not in lcm_factors or lcm_factors[k] < v: lcm_factors[k] = v lcm = 1 for k in lcm_factors: for i in range(lcm_factors[k]): lcm *= k lcm %= 1000000007 result = 0 for i in range(N): result += lcm * pow(A[i], 1000000007 - 2, 1000000007) result %= 1000000007 print(result)
false
78.571429
[ "-from sys import stdin", "-from fractions import gcd", "-from functools import reduce", "-", "-N = int(stdin.readline())", "-A = list(map(int, stdin.readline().split()))", "-lcm = reduce(lambda a, b: a * b // gcd(a, b), A)", "-print((sum(lcm // a for a in A) % 1000000007))", "+# エラトステネスの篩, フェルマーの小定理", "+max_A = 1000000", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+sieve = [0] * (max_A + 1)", "+sieve[0] = -1", "+sieve[1] = -1", "+for i in range(2, max_A + 1):", "+ if sieve[i] != 0:", "+ continue", "+ sieve[i] = i", "+ for j in range(i * i, max_A + 1, i):", "+ if sieve[j] == 0:", "+ sieve[j] = i", "+lcm_factors = {}", "+for i in range(N):", "+ t = []", "+ a = A[i]", "+ while a != 1:", "+ if len(t) != 0 and t[-1][0] == sieve[a]:", "+ t[-1][1] += 1", "+ else:", "+ t.append([sieve[a], 1])", "+ a //= sieve[a]", "+ for k, v in t:", "+ if k not in lcm_factors or lcm_factors[k] < v:", "+ lcm_factors[k] = v", "+lcm = 1", "+for k in lcm_factors:", "+ for i in range(lcm_factors[k]):", "+ lcm *= k", "+ lcm %= 1000000007", "+result = 0", "+for i in range(N):", "+ result += lcm * pow(A[i], 1000000007 - 2, 1000000007)", "+ result %= 1000000007", "+print(result)" ]
false
0.230801
0.817618
0.282284
[ "s019086375", "s137131306" ]
u263352518
p03835
python
s908261139
s421823010
1,888
1,637
3,060
3,060
Accepted
Accepted
13.29
nyu = eval(input()) nyu = nyu.split() k = int(nyu[0]) s = int(nyu[1]) n = 0 for x in range(k+1): for y in range(k+1): if x+y > s or s - (x+y) > k: #print(str(x) + " " + str(y)) continue; else: n +=1; print(n)
nyu = eval(input()) nyu = nyu.split() k = int(nyu[0]) s = int(nyu[1]) n = 0 for x in range(k+1): for y in range(k+1): if x+y > s: break elif s - (x+y) > k: #print(str(x) + " " + str(y)) continue; else: n +=1; print(n)
16
18
248
269
nyu = eval(input()) nyu = nyu.split() k = int(nyu[0]) s = int(nyu[1]) n = 0 for x in range(k + 1): for y in range(k + 1): if x + y > s or s - (x + y) > k: # print(str(x) + " " + str(y)) continue else: n += 1 print(n)
nyu = eval(input()) nyu = nyu.split() k = int(nyu[0]) s = int(nyu[1]) n = 0 for x in range(k + 1): for y in range(k + 1): if x + y > s: break elif s - (x + y) > k: # print(str(x) + " " + str(y)) continue else: n += 1 print(n)
false
11.111111
[ "- if x + y > s or s - (x + y) > k:", "+ if x + y > s:", "+ break", "+ elif s - (x + y) > k:" ]
false
0.046843
0.15653
0.299259
[ "s908261139", "s421823010" ]
u060938295
p03170
python
s530428502
s262531692
1,394
775
13,540
14,308
Accepted
Accepted
44.4
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys import numpy as np sys.setrecursionlimit(10 ** 9) #def input(): # return sys.stdin.readline()[:-1] mod = 10**9+7 #N = int(input()) N, K = list(map(int,input().split())) A = np.array(list(map(int,input().split()))) dp = [True for i in range(K + 1)] for i in range(K, -1, -1): if dp[i]: for a in A: if i - a >= 0: dp[i - a] = False # print(i, dp[i],A+i,dp[A+i]) #print(dp) if dp[0]: ans = 'Second' else: ans = 'First' print(ans)
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys import numpy as np sys.setrecursionlimit(10 ** 9) #def input(): # return sys.stdin.readline()[:-1] mod = 10**9+7 #N = int(input()) N, K = list(map(int,input().split())) A = np.array(list(map(int,input().split()))) dp = [True for i in range(K + A[-1] + 1)] for i in range(K): if dp[i]: for a in A: dp[i + a] = False # print(i, dp[i],A+i,dp[A+i]) #print(dp) if dp[K]: ans = 'Second' else: ans = 'First' print(ans)
32
31
590
558
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys import numpy as np sys.setrecursionlimit(10**9) # def input(): # return sys.stdin.readline()[:-1] mod = 10**9 + 7 # N = int(input()) N, K = list(map(int, input().split())) A = np.array(list(map(int, input().split()))) dp = [True for i in range(K + 1)] for i in range(K, -1, -1): if dp[i]: for a in A: if i - a >= 0: dp[i - a] = False # print(i, dp[i],A+i,dp[A+i]) # print(dp) if dp[0]: ans = "Second" else: ans = "First" print(ans)
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys import numpy as np sys.setrecursionlimit(10**9) # def input(): # return sys.stdin.readline()[:-1] mod = 10**9 + 7 # N = int(input()) N, K = list(map(int, input().split())) A = np.array(list(map(int, input().split()))) dp = [True for i in range(K + A[-1] + 1)] for i in range(K): if dp[i]: for a in A: dp[i + a] = False # print(i, dp[i],A+i,dp[A+i]) # print(dp) if dp[K]: ans = "Second" else: ans = "First" print(ans)
false
3.125
[ "-dp = [True for i in range(K + 1)]", "-for i in range(K, -1, -1):", "+dp = [True for i in range(K + A[-1] + 1)]", "+for i in range(K):", "- if i - a >= 0:", "- dp[i - a] = False", "+ dp[i + a] = False", "-if dp[0]:", "+if dp[K]:" ]
false
0.259935
0.382552
0.679476
[ "s530428502", "s262531692" ]
u747602774
p02838
python
s475273566
s176207190
992
769
122,936
137,144
Accepted
Accepted
22.48
n = int(eval(input())) a = list(map(int,input().split())) x = [0 for i in range(62)] for i in range(n): b = bin(a[i]) for i in range(len(b)-2): if b[-1-i] == '1': x[-i-1] += 1 mod = 10**9+7 ans = 0 two = 1 for i in range(1,62): ans = (ans + x[-i]*(n-x[-i])*two)%mod two = two*2%mod print(ans)
n = int(eval(input())) a = list(map(int,input().split())) mod = 10**9+7 ans = 0 for i in range(60): c = sum([1 for ai in a if (ai >> i) & 1]) ans += (1 << i) * c * (n-c) ans %= mod print(ans)
15
10
337
207
n = int(eval(input())) a = list(map(int, input().split())) x = [0 for i in range(62)] for i in range(n): b = bin(a[i]) for i in range(len(b) - 2): if b[-1 - i] == "1": x[-i - 1] += 1 mod = 10**9 + 7 ans = 0 two = 1 for i in range(1, 62): ans = (ans + x[-i] * (n - x[-i]) * two) % mod two = two * 2 % mod print(ans)
n = int(eval(input())) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 0 for i in range(60): c = sum([1 for ai in a if (ai >> i) & 1]) ans += (1 << i) * c * (n - c) ans %= mod print(ans)
false
33.333333
[ "-x = [0 for i in range(62)]", "-for i in range(n):", "- b = bin(a[i])", "- for i in range(len(b) - 2):", "- if b[-1 - i] == \"1\":", "- x[-i - 1] += 1", "-two = 1", "-for i in range(1, 62):", "- ans = (ans + x[-i] * (n - x[-i]) * two) % mod", "- two = two * 2 % mod", "+for i in range(60):", "+ c = sum([1 for ai in a if (ai >> i) & 1])", "+ ans += (1 << i) * c * (n - c)", "+ ans %= mod" ]
false
0.04114
0.047115
0.873183
[ "s475273566", "s176207190" ]
u985076807
p03680
python
s375954191
s786592975
107
94
24,228
24,228
Accepted
Accepted
12.15
# https://beta.atcoder.jp/contests/abc065/tasks/abc065_b import sys def model(): e = list(map(int, sys.stdin)) cur = e[1] for i in range(e[0]): if cur == 2: print((i + 1)) break cur = e[cur] else: print((-1)) def input_lines(): """hell?""" lines = sys.stdin.readlines() for i in range(1, int(lines[0])+1): yield i, int(lines[i].strip()) def solve(): d = {i: button for i, button in input_lines()} count = 1 index = 1 while True: try: prev = index index = d[index] if index == 2: print(count) exit() elif index is None: print((-1)) exit() d[prev] = None count += 1 except KeyError: print((-1)) exit() if __name__ == '__main__': solve() # model()
# https://beta.atcoder.jp/contests/abc065/tasks/abc065_b import sys def model(): e = list(map(int, sys.stdin)) cur = e[1] for i in range(e[0]): if cur == 2: print((i + 1)) break cur = e[cur] else: print((-1)) def input_lines(): """hell?""" lines = sys.stdin.readlines() for i in range(1, int(lines[0])+1): yield i, int(lines[i].strip()) def solve(): d = {i: button for i, button in input_lines()} count = 1 index = 1 while True: try: prev = index index = d[index] if index is None: print((-1)) exit() elif index == 2: print(count) exit() d[prev] = None count += 1 except KeyError: print((-1)) exit() if __name__ == '__main__': solve() # model()
50
50
981
981
# https://beta.atcoder.jp/contests/abc065/tasks/abc065_b import sys def model(): e = list(map(int, sys.stdin)) cur = e[1] for i in range(e[0]): if cur == 2: print((i + 1)) break cur = e[cur] else: print((-1)) def input_lines(): """hell?""" lines = sys.stdin.readlines() for i in range(1, int(lines[0]) + 1): yield i, int(lines[i].strip()) def solve(): d = {i: button for i, button in input_lines()} count = 1 index = 1 while True: try: prev = index index = d[index] if index == 2: print(count) exit() elif index is None: print((-1)) exit() d[prev] = None count += 1 except KeyError: print((-1)) exit() if __name__ == "__main__": solve() # model()
# https://beta.atcoder.jp/contests/abc065/tasks/abc065_b import sys def model(): e = list(map(int, sys.stdin)) cur = e[1] for i in range(e[0]): if cur == 2: print((i + 1)) break cur = e[cur] else: print((-1)) def input_lines(): """hell?""" lines = sys.stdin.readlines() for i in range(1, int(lines[0]) + 1): yield i, int(lines[i].strip()) def solve(): d = {i: button for i, button in input_lines()} count = 1 index = 1 while True: try: prev = index index = d[index] if index is None: print((-1)) exit() elif index == 2: print(count) exit() d[prev] = None count += 1 except KeyError: print((-1)) exit() if __name__ == "__main__": solve() # model()
false
0
[ "- if index == 2:", "+ if index is None:", "+ print((-1))", "+ exit()", "+ elif index == 2:", "- exit()", "- elif index is None:", "- print((-1))" ]
false
0.04493
0.046349
0.969385
[ "s375954191", "s786592975" ]
u562935282
p03805
python
s567090309
s708402450
70
27
4,288
3,064
Accepted
Accepted
61.43
def ary(r, c, v): return [[v for _ in range(c)] for _ in range(r)] n, m = list(map(int, input().split())) e = ary(n, n, False) for i in range(m): a, b = list(map(int, input().split())) #頂点を0-indexedに変換 a -= 1 b -= 1 e[a][b] = True e[b][a] = True ps = set() ps.add('0') for cnt in range(1, n): t = set() for p in ps: for i in map(str, list(range(1, n))): if not(i in p): t.add(p + i) ps = t.copy() ans = 0 for p in ps: flg = True for i in range(n - 1): a = int(p[i]) b = int(p[i + 1]) if not e[a][b]: flg = False break if flg: ans += 1 print(ans)
def main(): import sys sys.setrecursionlimit(10 ** 7) N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) def dfs(v=0, visited=1 << 0): if visited == (1 << N) - 1: return 1 ret = 0 for u in g[v]: if (visited >> u) & 1: continue ret += dfs(u, visited | (1 << u)) return ret ans = dfs() print(ans) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
34
39
703
758
def ary(r, c, v): return [[v for _ in range(c)] for _ in range(r)] n, m = list(map(int, input().split())) e = ary(n, n, False) for i in range(m): a, b = list(map(int, input().split())) # 頂点を0-indexedに変換 a -= 1 b -= 1 e[a][b] = True e[b][a] = True ps = set() ps.add("0") for cnt in range(1, n): t = set() for p in ps: for i in map(str, list(range(1, n))): if not (i in p): t.add(p + i) ps = t.copy() ans = 0 for p in ps: flg = True for i in range(n - 1): a = int(p[i]) b = int(p[i + 1]) if not e[a][b]: flg = False break if flg: ans += 1 print(ans)
def main(): import sys sys.setrecursionlimit(10**7) N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): a, b = (int(x) - 1 for x in input().split()) g[a].add(b) g[b].add(a) def dfs(v=0, visited=1 << 0): if visited == (1 << N) - 1: return 1 ret = 0 for u in g[v]: if (visited >> u) & 1: continue ret += dfs(u, visited | (1 << u)) return ret ans = dfs() print(ans) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
false
12.820513
[ "-def ary(r, c, v):", "- return [[v for _ in range(c)] for _ in range(r)]", "+def main():", "+ import sys", "+", "+ sys.setrecursionlimit(10**7)", "+ N, M = list(map(int, input().split()))", "+ g = tuple(set() for _ in range(N))", "+ for _ in range(M):", "+ a, b = (int(x) - 1 for x in input().split())", "+ g[a].add(b)", "+ g[b].add(a)", "+", "+ def dfs(v=0, visited=1 << 0):", "+ if visited == (1 << N) - 1:", "+ return 1", "+ ret = 0", "+ for u in g[v]:", "+ if (visited >> u) & 1:", "+ continue", "+ ret += dfs(u, visited | (1 << u))", "+ return ret", "+", "+ ans = dfs()", "+ print(ans)", "-n, m = list(map(int, input().split()))", "-e = ary(n, n, False)", "-for i in range(m):", "- a, b = list(map(int, input().split()))", "- # 頂点を0-indexedに変換", "- a -= 1", "- b -= 1", "- e[a][b] = True", "- e[b][a] = True", "-ps = set()", "-ps.add(\"0\")", "-for cnt in range(1, n):", "- t = set()", "- for p in ps:", "- for i in map(str, list(range(1, n))):", "- if not (i in p):", "- t.add(p + i)", "- ps = t.copy()", "-ans = 0", "-for p in ps:", "- flg = True", "- for i in range(n - 1):", "- a = int(p[i])", "- b = int(p[i + 1])", "- if not e[a][b]:", "- flg = False", "- break", "- if flg:", "- ans += 1", "-print(ans)", "+if __name__ == \"__main__\":", "+ main()", "+# import sys", "+#", "+# sys.setrecursionlimit(10 ** 7)", "+#", "+# input = sys.stdin.readline", "+# rstrip()", "+# int(input())", "+# map(int, input().split())" ]
false
0.077351
0.037095
2.08521
[ "s567090309", "s708402450" ]
u028014940
p03043
python
s739802641
s302682873
303
51
21,384
7,832
Accepted
Accepted
83.17
import numpy as np n,k=list(map(int,input().split())) n_lis=[int(i) for i in range(1,n+1)] p=float(1/n) p_lis=[] for i in range(n): count=0 if n_lis[i]<k: atai=float(k/n_lis[i]) for j in range(10000): atai=float(atai/2) count+=1 if atai<=1: break p_lis.append((1/2)**(count)) else: p_lis.append(1) print((p*sum(p_lis)))
import math n,k=list(map(int,input().split())) n_lis=[int(i) for i in range(1,n+1)] p=float(1/n) p_lis=[] for i in range(n): if n_lis[i]<k: atai=float(k/n_lis[i]) kaisu=-(-math.log(atai,2)//1) # loop処理しなくてよいので記述が楽 p_lis.append((1/2)**(kaisu)) else: p_lis.append(1) print((p*sum(p_lis)))
28
14
460
332
import numpy as np n, k = list(map(int, input().split())) n_lis = [int(i) for i in range(1, n + 1)] p = float(1 / n) p_lis = [] for i in range(n): count = 0 if n_lis[i] < k: atai = float(k / n_lis[i]) for j in range(10000): atai = float(atai / 2) count += 1 if atai <= 1: break p_lis.append((1 / 2) ** (count)) else: p_lis.append(1) print((p * sum(p_lis)))
import math n, k = list(map(int, input().split())) n_lis = [int(i) for i in range(1, n + 1)] p = float(1 / n) p_lis = [] for i in range(n): if n_lis[i] < k: atai = float(k / n_lis[i]) kaisu = -(-math.log(atai, 2) // 1) # loop処理しなくてよいので記述が楽 p_lis.append((1 / 2) ** (kaisu)) else: p_lis.append(1) print((p * sum(p_lis)))
false
50
[ "-import numpy as np", "+import math", "- count = 0", "- for j in range(10000):", "- atai = float(atai / 2)", "- count += 1", "- if atai <= 1:", "- break", "- p_lis.append((1 / 2) ** (count))", "+ kaisu = -(-math.log(atai, 2) // 1) # loop処理しなくてよいので記述が楽", "+ p_lis.append((1 / 2) ** (kaisu))" ]
false
0.061376
0.053703
1.142874
[ "s739802641", "s302682873" ]
u724687935
p02632
python
s895704072
s403813901
865
241
122,836
138,400
Accepted
Accepted
72.14
def prepare(n): global MOD modFacts = [0] * (n + 1) modFacts[0] = 1 for i in range(n): modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD invs = [1] * (n + 1) invs[n] = pow(modFacts[n], MOD - 2, MOD) for i in range(n, 1, -1): invs[i - 1] = (invs[i] * i) % MOD return modFacts, invs MOD = 10 ** 9 + 7 K = int(eval(input())) S = eval(input()) L = len(S) modFacts, invs = prepare(K + L) ans = 0 for n in range(L, L + K + 1): nonSi = (pow(25, n - L, MOD) * pow(26, L + K - n, MOD)) % MOD Si = (modFacts[n - 1] * invs[L - 1] * invs[n - 1 - (L - 1)]) % MOD ans += nonSi * Si ans %= MOD print(ans)
def prepare(n): global MOD modFacts = [0] * (n + 1) modFacts[0] = 1 for i in range(n): modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD invs = [1] * (n + 1) invs[n] = pow(modFacts[n], MOD - 2, MOD) for i in range(n, 1, -1): invs[i - 1] = (invs[i] * i) % MOD return modFacts, invs MOD = 10 ** 9 + 7 K = int(eval(input())) S = eval(input()) L = len(S) modFacts, invs = prepare(K + L) pow25 = [1] * max(L + 1, K + 1) pow26 = [1] * max(L + 1, K + 1) for i in range(max(L, K)): pow25[i + 1] = (pow25[i] * 25) % MOD pow26[i + 1] = (pow26[i] * 26) % MOD ans = 0 for n in range(L, L + K + 1): nonSi = (pow25[n - L] * pow26[L + K - n]) % MOD Si = (modFacts[n - 1] * invs[L - 1] * invs[n - 1 - (L - 1)]) % MOD ans += nonSi * Si ans %= MOD print(ans)
29
35
674
840
def prepare(n): global MOD modFacts = [0] * (n + 1) modFacts[0] = 1 for i in range(n): modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD invs = [1] * (n + 1) invs[n] = pow(modFacts[n], MOD - 2, MOD) for i in range(n, 1, -1): invs[i - 1] = (invs[i] * i) % MOD return modFacts, invs MOD = 10**9 + 7 K = int(eval(input())) S = eval(input()) L = len(S) modFacts, invs = prepare(K + L) ans = 0 for n in range(L, L + K + 1): nonSi = (pow(25, n - L, MOD) * pow(26, L + K - n, MOD)) % MOD Si = (modFacts[n - 1] * invs[L - 1] * invs[n - 1 - (L - 1)]) % MOD ans += nonSi * Si ans %= MOD print(ans)
def prepare(n): global MOD modFacts = [0] * (n + 1) modFacts[0] = 1 for i in range(n): modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD invs = [1] * (n + 1) invs[n] = pow(modFacts[n], MOD - 2, MOD) for i in range(n, 1, -1): invs[i - 1] = (invs[i] * i) % MOD return modFacts, invs MOD = 10**9 + 7 K = int(eval(input())) S = eval(input()) L = len(S) modFacts, invs = prepare(K + L) pow25 = [1] * max(L + 1, K + 1) pow26 = [1] * max(L + 1, K + 1) for i in range(max(L, K)): pow25[i + 1] = (pow25[i] * 25) % MOD pow26[i + 1] = (pow26[i] * 26) % MOD ans = 0 for n in range(L, L + K + 1): nonSi = (pow25[n - L] * pow26[L + K - n]) % MOD Si = (modFacts[n - 1] * invs[L - 1] * invs[n - 1 - (L - 1)]) % MOD ans += nonSi * Si ans %= MOD print(ans)
false
17.142857
[ "+pow25 = [1] * max(L + 1, K + 1)", "+pow26 = [1] * max(L + 1, K + 1)", "+for i in range(max(L, K)):", "+ pow25[i + 1] = (pow25[i] * 25) % MOD", "+ pow26[i + 1] = (pow26[i] * 26) % MOD", "- nonSi = (pow(25, n - L, MOD) * pow(26, L + K - n, MOD)) % MOD", "+ nonSi = (pow25[n - L] * pow26[L + K - n]) % MOD" ]
false
0.104977
0.039263
2.673656
[ "s895704072", "s403813901" ]
u168578024
p03061
python
s429039297
s566941069
1,114
824
122,144
100,748
Accepted
Accepted
26.03
import copy class SegmentTree: def __init__(self, N, func, I): self.sz = N self.func = func self.I = copy.deepcopy(I) self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)] def assign(self, k, x): self.seg[k + self.sz] = copy.deepcopy(x) def build(self): for i in range(self.sz - 1, 0, -1): self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, x): k += self.sz self.seg[k] = copy.deepcopy(x) while k > 1: k //= 2 self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1]) def query(self, a, b): L = copy.deepcopy(self.I) R = copy.deepcopy(self.I) a += self.sz b += self.sz while a < b: if a % 2 == 1: L = self.func(L, self.seg[a]) a += 1 if b % 2 == 1: b -= 1 R = self.func(self.seg[b], R) a //= 2 b //= 2 return self.func(L, R) N = int(eval(input())) a = list(map(int,input().split())) from fractions import gcd seg = SegmentTree(N , gcd , 0) for i in range(N): seg.assign(i , a[i]) seg.build() ans = 1 for i in range(N): ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N))) print(ans)
import copy class SegmentTree: def __init__(self, N, func, I): self.sz = N self.func = func self.I = I self.seg = [I for i in range(self.sz * 2)] def assign(self, k, x): self.seg[k + self.sz] = x def build(self): for i in range(self.sz - 1, 0, -1): self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, x): k += self.sz self.seg[k] = x while k > 1: k //= 2 self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1]) def query(self, a, b): L = self.I R = self.I a += self.sz b += self.sz while a < b: if a % 2 == 1: L = self.func(L, self.seg[a]) a += 1 if b % 2 == 1: b -= 1 R = self.func(self.seg[b], R) a //= 2 b //= 2 return self.func(L, R) N = int(eval(input())) a = list(map(int,input().split())) from fractions import gcd seg = SegmentTree(N , gcd , 0) for i in range(N): seg.assign(i , a[i]) seg.build() ans = 1 for i in range(N): ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N))) print(ans)
49
49
1,369
1,279
import copy class SegmentTree: def __init__(self, N, func, I): self.sz = N self.func = func self.I = copy.deepcopy(I) self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)] def assign(self, k, x): self.seg[k + self.sz] = copy.deepcopy(x) def build(self): for i in range(self.sz - 1, 0, -1): self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, x): k += self.sz self.seg[k] = copy.deepcopy(x) while k > 1: k //= 2 self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1]) def query(self, a, b): L = copy.deepcopy(self.I) R = copy.deepcopy(self.I) a += self.sz b += self.sz while a < b: if a % 2 == 1: L = self.func(L, self.seg[a]) a += 1 if b % 2 == 1: b -= 1 R = self.func(self.seg[b], R) a //= 2 b //= 2 return self.func(L, R) N = int(eval(input())) a = list(map(int, input().split())) from fractions import gcd seg = SegmentTree(N, gcd, 0) for i in range(N): seg.assign(i, a[i]) seg.build() ans = 1 for i in range(N): ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, N))) print(ans)
import copy class SegmentTree: def __init__(self, N, func, I): self.sz = N self.func = func self.I = I self.seg = [I for i in range(self.sz * 2)] def assign(self, k, x): self.seg[k + self.sz] = x def build(self): for i in range(self.sz - 1, 0, -1): self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, x): k += self.sz self.seg[k] = x while k > 1: k //= 2 self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1]) def query(self, a, b): L = self.I R = self.I a += self.sz b += self.sz while a < b: if a % 2 == 1: L = self.func(L, self.seg[a]) a += 1 if b % 2 == 1: b -= 1 R = self.func(self.seg[b], R) a //= 2 b //= 2 return self.func(L, R) N = int(eval(input())) a = list(map(int, input().split())) from fractions import gcd seg = SegmentTree(N, gcd, 0) for i in range(N): seg.assign(i, a[i]) seg.build() ans = 1 for i in range(N): ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, N))) print(ans)
false
0
[ "- self.I = copy.deepcopy(I)", "- self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]", "+ self.I = I", "+ self.seg = [I for i in range(self.sz * 2)]", "- self.seg[k + self.sz] = copy.deepcopy(x)", "+ self.seg[k + self.sz] = x", "- self.seg[k] = copy.deepcopy(x)", "+ self.seg[k] = x", "- L = copy.deepcopy(self.I)", "- R = copy.deepcopy(self.I)", "+ L = self.I", "+ R = self.I" ]
false
0.15151
0.061742
2.453909
[ "s429039297", "s566941069" ]
u952708174
p03673
python
s909696241
s741253500
160
117
30,020
28,100
Accepted
Accepted
26.88
def c_pushpush(N, A): from collections import deque ans = deque([]) # リストの先頭への挿入はO(要素数)なので n_parity = N & 1 for i, a in enumerate(A, 1): if n_parity == i & 1: ans.appendleft(a) else: ans.append(a) return ' '.join(map(str, ans)) N = int(eval(input())) A = [int(i) for i in input().split()] print((c_pushpush(N, A)))
def c_pushpush(): # Aの奇数番目の要素と偶数番目の要素をそれぞれ一塊にすることは変わらない。 # ただし、どちらを左右にするかは N の偶奇によって変わる N = int(eval(input())) A = [int(i) for i in input().split()] return ' '.join(map(str, A[int(N % 2 == 0)::2][::-1] + A[int(not N % 2 == 0)::2])) print((c_pushpush()))
14
8
381
273
def c_pushpush(N, A): from collections import deque ans = deque([]) # リストの先頭への挿入はO(要素数)なので n_parity = N & 1 for i, a in enumerate(A, 1): if n_parity == i & 1: ans.appendleft(a) else: ans.append(a) return " ".join(map(str, ans)) N = int(eval(input())) A = [int(i) for i in input().split()] print((c_pushpush(N, A)))
def c_pushpush(): # Aの奇数番目の要素と偶数番目の要素をそれぞれ一塊にすることは変わらない。 # ただし、どちらを左右にするかは N の偶奇によって変わる N = int(eval(input())) A = [int(i) for i in input().split()] return " ".join( map(str, A[int(N % 2 == 0) :: 2][::-1] + A[int(not N % 2 == 0) :: 2]) ) print((c_pushpush()))
false
42.857143
[ "-def c_pushpush(N, A):", "- from collections import deque", "-", "- ans = deque([]) # リストの先頭への挿入はO(要素数)なので", "- n_parity = N & 1", "- for i, a in enumerate(A, 1):", "- if n_parity == i & 1:", "- ans.appendleft(a)", "- else:", "- ans.append(a)", "- return \" \".join(map(str, ans))", "+def c_pushpush():", "+ # Aの奇数番目の要素と偶数番目の要素をそれぞれ一塊にすることは変わらない。", "+ # ただし、どちらを左右にするかは N の偶奇によって変わる", "+ N = int(eval(input()))", "+ A = [int(i) for i in input().split()]", "+ return \" \".join(", "+ map(str, A[int(N % 2 == 0) :: 2][::-1] + A[int(not N % 2 == 0) :: 2])", "+ )", "-N = int(eval(input()))", "-A = [int(i) for i in input().split()]", "-print((c_pushpush(N, A)))", "+print((c_pushpush()))" ]
false
0.105853
0.127337
0.831279
[ "s909696241", "s741253500" ]
u280512618
p03244
python
s801106429
s980938787
118
105
20,144
20,564
Accepted
Accepted
11.02
from collections import Counter from collections import deque if __name__ == '__main__': n = int(eval(input())) vs0 = [] vs1 = [] for i,v in enumerate(map(int, input().split())): if i % 2 == 0: vs0.append(v) else: vs1.append(v) vs0 = deque(sorted(list(Counter(vs0).items()), key=lambda t: t[1])) vs1 = deque(sorted(list(Counter(vs1).items()), key=lambda t: t[1])) t0 = vs0.pop() t1 = vs1.pop() if t0[0] != t1[0]: vs0 = (t[1] for t in vs0) vs1 = (t[1] for t in vs1) print((sum(vs0) + sum(vs1))) else: if len(vs1) == 0: if len(vs0) == 0: print((t1[1])) else: vs0 = (t[1] for t in vs0) print((sum(vs0))) elif len(vs0) == 0: vs1 = (t[1] for t in vs1) print((sum(vs1))) else: t00 = vs0.pop() t11 = vs1.pop() a = t00[1] + t1[1] b = t11[1] + t0[1] vs0 = (t[1] for t in vs0) vs1 = (t[1] for t in vs1) print((sum(vs0) + sum(vs1) + (a if a < b else b)))
from collections import Counter if __name__ == '__main__': n = int(eval(input())) vs = [int(s) for s in input().split()] counter0 = list(Counter(vs[0::2]).items()) + [(100001, 0)] counter1 = list(Counter(vs[1::2]).items()) + [(100001, 0)] v0, c0 = max(counter0, key=lambda t: t[1]) v1, c1 = max(counter1, key=lambda t: t[1]) counter0.remove((v0, c0)) counter1.remove((v1, c1)) res = 0 if v0 != v1: res = n - c0 - c1 else: _, c02 = max(counter0, key=lambda t: t[1]) _, c12 = max(counter1, key=lambda t: t[1]) res = n - (c0 + c12 if c12 > c02 else c1 + c02) print(res)
40
19
1,166
660
from collections import Counter from collections import deque if __name__ == "__main__": n = int(eval(input())) vs0 = [] vs1 = [] for i, v in enumerate(map(int, input().split())): if i % 2 == 0: vs0.append(v) else: vs1.append(v) vs0 = deque(sorted(list(Counter(vs0).items()), key=lambda t: t[1])) vs1 = deque(sorted(list(Counter(vs1).items()), key=lambda t: t[1])) t0 = vs0.pop() t1 = vs1.pop() if t0[0] != t1[0]: vs0 = (t[1] for t in vs0) vs1 = (t[1] for t in vs1) print((sum(vs0) + sum(vs1))) else: if len(vs1) == 0: if len(vs0) == 0: print((t1[1])) else: vs0 = (t[1] for t in vs0) print((sum(vs0))) elif len(vs0) == 0: vs1 = (t[1] for t in vs1) print((sum(vs1))) else: t00 = vs0.pop() t11 = vs1.pop() a = t00[1] + t1[1] b = t11[1] + t0[1] vs0 = (t[1] for t in vs0) vs1 = (t[1] for t in vs1) print((sum(vs0) + sum(vs1) + (a if a < b else b)))
from collections import Counter if __name__ == "__main__": n = int(eval(input())) vs = [int(s) for s in input().split()] counter0 = list(Counter(vs[0::2]).items()) + [(100001, 0)] counter1 = list(Counter(vs[1::2]).items()) + [(100001, 0)] v0, c0 = max(counter0, key=lambda t: t[1]) v1, c1 = max(counter1, key=lambda t: t[1]) counter0.remove((v0, c0)) counter1.remove((v1, c1)) res = 0 if v0 != v1: res = n - c0 - c1 else: _, c02 = max(counter0, key=lambda t: t[1]) _, c12 = max(counter1, key=lambda t: t[1]) res = n - (c0 + c12 if c12 > c02 else c1 + c02) print(res)
false
52.5
[ "-from collections import deque", "- vs0 = []", "- vs1 = []", "- for i, v in enumerate(map(int, input().split())):", "- if i % 2 == 0:", "- vs0.append(v)", "- else:", "- vs1.append(v)", "- vs0 = deque(sorted(list(Counter(vs0).items()), key=lambda t: t[1]))", "- vs1 = deque(sorted(list(Counter(vs1).items()), key=lambda t: t[1]))", "- t0 = vs0.pop()", "- t1 = vs1.pop()", "- if t0[0] != t1[0]:", "- vs0 = (t[1] for t in vs0)", "- vs1 = (t[1] for t in vs1)", "- print((sum(vs0) + sum(vs1)))", "+ vs = [int(s) for s in input().split()]", "+ counter0 = list(Counter(vs[0::2]).items()) + [(100001, 0)]", "+ counter1 = list(Counter(vs[1::2]).items()) + [(100001, 0)]", "+ v0, c0 = max(counter0, key=lambda t: t[1])", "+ v1, c1 = max(counter1, key=lambda t: t[1])", "+ counter0.remove((v0, c0))", "+ counter1.remove((v1, c1))", "+ res = 0", "+ if v0 != v1:", "+ res = n - c0 - c1", "- if len(vs1) == 0:", "- if len(vs0) == 0:", "- print((t1[1]))", "- else:", "- vs0 = (t[1] for t in vs0)", "- print((sum(vs0)))", "- elif len(vs0) == 0:", "- vs1 = (t[1] for t in vs1)", "- print((sum(vs1)))", "- else:", "- t00 = vs0.pop()", "- t11 = vs1.pop()", "- a = t00[1] + t1[1]", "- b = t11[1] + t0[1]", "- vs0 = (t[1] for t in vs0)", "- vs1 = (t[1] for t in vs1)", "- print((sum(vs0) + sum(vs1) + (a if a < b else b)))", "+ _, c02 = max(counter0, key=lambda t: t[1])", "+ _, c12 = max(counter1, key=lambda t: t[1])", "+ res = n - (c0 + c12 if c12 > c02 else c1 + c02)", "+ print(res)" ]
false
0.036683
0.03759
0.975897
[ "s801106429", "s980938787" ]
u814986259
p02779
python
s813975517
s057783192
178
91
33,996
25,684
Accepted
Accepted
48.88
import collections N = int(eval(input())) A = list(map(int, input().split())) table = collections.defaultdict(int) for x in A: table[x] += 1 if table[x] > 1: print("NO") exit(0) print("YES")
N = int(eval(input())) A = set(list(map(int, input().split()))) if len(A) == N: print("YES") else: print("NO")
12
6
222
118
import collections N = int(eval(input())) A = list(map(int, input().split())) table = collections.defaultdict(int) for x in A: table[x] += 1 if table[x] > 1: print("NO") exit(0) print("YES")
N = int(eval(input())) A = set(list(map(int, input().split()))) if len(A) == N: print("YES") else: print("NO")
false
50
[ "-import collections", "-", "-A = list(map(int, input().split()))", "-table = collections.defaultdict(int)", "-for x in A:", "- table[x] += 1", "- if table[x] > 1:", "- print(\"NO\")", "- exit(0)", "-print(\"YES\")", "+A = set(list(map(int, input().split())))", "+if len(A) == N:", "+ print(\"YES\")", "+else:", "+ print(\"NO\")" ]
false
0.097036
0.087963
1.103143
[ "s813975517", "s057783192" ]
u498487134
p03038
python
s495669245
s547925628
902
649
73,752
68,588
Accepted
Accepted
28.05
N,M=list(map(int,input().split())) A=list(map(int,input().split())) CB=[[0,0] for _ in range(M)] for i in range(M): CB[i][1],CB[i][0]=list(map(int,input().split())) A.sort() CB.sort(reverse=True) #Aを小さい順に見る,Cが大きい順に変更操作をして確定していく cc=0 ans=0 for i in range(N): if cc<M: if A[i]<CB[cc][0]: A[i]=CB[cc][0] CB[cc][1]-=1 if CB[cc][1]==0: cc+=1 ans+=A[i] print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,M=MI() A=LI() CB=[[0,0]for _ in range(M)] A.sort() for i in range(M): CB[i][1],CB[i][0]=MI() CB.sort(reverse=True) now=0 for i in range(N): if CB[now][1]<=0: now+=1 if now>=M: break ch=CB[now][0] if A[i]<ch: A[i]=ch CB[now][1]-=1 else: break print((sum(A))) main()
23
37
455
685
N, M = list(map(int, input().split())) A = list(map(int, input().split())) CB = [[0, 0] for _ in range(M)] for i in range(M): CB[i][1], CB[i][0] = list(map(int, input().split())) A.sort() CB.sort(reverse=True) # Aを小さい順に見る,Cが大きい順に変更操作をして確定していく cc = 0 ans = 0 for i in range(N): if cc < M: if A[i] < CB[cc][0]: A[i] = CB[cc][0] CB[cc][1] -= 1 if CB[cc][1] == 0: cc += 1 ans += A[i] print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N, M = MI() A = LI() CB = [[0, 0] for _ in range(M)] A.sort() for i in range(M): CB[i][1], CB[i][0] = MI() CB.sort(reverse=True) now = 0 for i in range(N): if CB[now][1] <= 0: now += 1 if now >= M: break ch = CB[now][0] if A[i] < ch: A[i] = ch CB[now][1] -= 1 else: break print((sum(A))) main()
false
37.837838
[ "-N, M = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-CB = [[0, 0] for _ in range(M)]", "-for i in range(M):", "- CB[i][1], CB[i][0] = list(map(int, input().split()))", "-A.sort()", "-CB.sort(reverse=True)", "-# Aを小さい順に見る,Cが大きい順に変更操作をして確定していく", "-cc = 0", "-ans = 0", "-for i in range(N):", "- if cc < M:", "- if A[i] < CB[cc][0]:", "- A[i] = CB[cc][0]", "- CB[cc][1] -= 1", "- if CB[cc][1] == 0:", "- cc += 1", "- ans += A[i]", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N, M = MI()", "+ A = LI()", "+ CB = [[0, 0] for _ in range(M)]", "+ A.sort()", "+ for i in range(M):", "+ CB[i][1], CB[i][0] = MI()", "+ CB.sort(reverse=True)", "+ now = 0", "+ for i in range(N):", "+ if CB[now][1] <= 0:", "+ now += 1", "+ if now >= M:", "+ break", "+ ch = CB[now][0]", "+ if A[i] < ch:", "+ A[i] = ch", "+ CB[now][1] -= 1", "+ else:", "+ break", "+ print((sum(A)))", "+", "+", "+main()" ]
false
0.041557
0.035125
1.183111
[ "s495669245", "s547925628" ]
u790710233
p02583
python
s563135233
s447592245
132
119
9,168
9,188
Accepted
Accepted
9.85
from itertools import combinations n = int(eval(input())) L = list(map(int, input().split())) ans = 0 for subset in combinations(L, 3): subset = sorted(subset) if len(set(subset)) != 3: continue a, b, c = subset if c < a+b: ans += 1 print(ans)
n = int(eval(input())) L = list(map(int, input().split())) ans = 0 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): a, b, c = sorted([L[i], L[j], L[k]]) if a == b or b == c or c == a: continue if c < a+b: ans += 1 print(ans)
13
12
283
328
from itertools import combinations n = int(eval(input())) L = list(map(int, input().split())) ans = 0 for subset in combinations(L, 3): subset = sorted(subset) if len(set(subset)) != 3: continue a, b, c = subset if c < a + b: ans += 1 print(ans)
n = int(eval(input())) L = list(map(int, input().split())) ans = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): a, b, c = sorted([L[i], L[j], L[k]]) if a == b or b == c or c == a: continue if c < a + b: ans += 1 print(ans)
false
7.692308
[ "-from itertools import combinations", "-", "-for subset in combinations(L, 3):", "- subset = sorted(subset)", "- if len(set(subset)) != 3:", "- continue", "- a, b, c = subset", "- if c < a + b:", "- ans += 1", "+for i in range(n):", "+ for j in range(i + 1, n):", "+ for k in range(j + 1, n):", "+ a, b, c = sorted([L[i], L[j], L[k]])", "+ if a == b or b == c or c == a:", "+ continue", "+ if c < a + b:", "+ ans += 1" ]
false
0.075948
0.044116
1.721566
[ "s563135233", "s447592245" ]
u354638986
p03436
python
s555248130
s942577901
1,319
26
3,564
3,564
Accepted
Accepted
98.03
from collections import deque h, w = list(map(int, input().split())) grid = [] for i in range(h): grid.append([j for j in eval(input())]) parent = [[-1 for j in range(w)] for i in range(h)] def bfs(s): q = deque() check = [[0 for j in range(w)] for i in range(h)] q.append(s) check[s[0]][s[1]] = 1 while len(q) != 0: u = q.popleft() for i in range(h): for j in range(w): if grid[i][j] == '.' and check[i][j] == 0: dx, dy = abs(i-u[0]), abs(j-u[1]) if dx <= 1 and dy <= 1 and dx + dy < 2: check[i][j] = 1 parent[i][j] = u q.append((i, j)) check[u[0]][u[1]] = 2 def main(): bfs((0, 0)) if parent[h-1][w-1] != -1: x, y = h-1, w-1 while x != 0 or y != 0: grid[x][y] = "#" x, y = parent[x][y] grid[0][0] = "#" pt = 0 for i in range(h): for j in range(w): if grid[i][j] == ".": pt += 1 else: pt = -1 print(pt) if __name__ == '__main__': main()
from collections import deque h, w = list(map(int, input().split())) grid = [] for i in range(h): grid.append([j for j in eval(input())]) parent = [[-1 for j in range(w)] for i in range(h)] def bfs(s): q = deque() check = [[0 for j in range(w)] for i in range(h)] q.append(s) check[s[0]][s[1]] = 1 while len(q) != 0: u = q.popleft() x, y = u[0], u[1] if x > 0 and grid[x-1][y] == "." and check[x-1][y] == 0: check[x-1][y], parent[x-1][y] = 1, u q.append((x-1, y)) if y > 0 and grid[x][y-1] == "." and check[x][y-1] == 0: check[x][y-1], parent[x][y-1] = 1, u q.append((x, y-1)) if x < h-1 and grid[x+1][y] == "." and check[x+1][y] == 0: check[x+1][y], parent[x+1][y] = 1, u q.append((x+1, y)) if y < w-1 and grid[x][y+1] == "." and check[x][y+1] == 0: check[x][y+1], parent[x][y+1] = 1, u q.append((x, y+1)) check[x][y] = 2 def main(): bfs((0, 0)) if parent[h-1][w-1] != -1: x, y = h-1, w-1 while x != 0 or y != 0: grid[x][y] = "#" x, y = parent[x][y] grid[0][0] = "#" pt = 0 for i in range(h): for j in range(w): if grid[i][j] == ".": pt += 1 else: pt = -1 print(pt) if __name__ == '__main__': main()
53
59
1,219
1,477
from collections import deque h, w = list(map(int, input().split())) grid = [] for i in range(h): grid.append([j for j in eval(input())]) parent = [[-1 for j in range(w)] for i in range(h)] def bfs(s): q = deque() check = [[0 for j in range(w)] for i in range(h)] q.append(s) check[s[0]][s[1]] = 1 while len(q) != 0: u = q.popleft() for i in range(h): for j in range(w): if grid[i][j] == "." and check[i][j] == 0: dx, dy = abs(i - u[0]), abs(j - u[1]) if dx <= 1 and dy <= 1 and dx + dy < 2: check[i][j] = 1 parent[i][j] = u q.append((i, j)) check[u[0]][u[1]] = 2 def main(): bfs((0, 0)) if parent[h - 1][w - 1] != -1: x, y = h - 1, w - 1 while x != 0 or y != 0: grid[x][y] = "#" x, y = parent[x][y] grid[0][0] = "#" pt = 0 for i in range(h): for j in range(w): if grid[i][j] == ".": pt += 1 else: pt = -1 print(pt) if __name__ == "__main__": main()
from collections import deque h, w = list(map(int, input().split())) grid = [] for i in range(h): grid.append([j for j in eval(input())]) parent = [[-1 for j in range(w)] for i in range(h)] def bfs(s): q = deque() check = [[0 for j in range(w)] for i in range(h)] q.append(s) check[s[0]][s[1]] = 1 while len(q) != 0: u = q.popleft() x, y = u[0], u[1] if x > 0 and grid[x - 1][y] == "." and check[x - 1][y] == 0: check[x - 1][y], parent[x - 1][y] = 1, u q.append((x - 1, y)) if y > 0 and grid[x][y - 1] == "." and check[x][y - 1] == 0: check[x][y - 1], parent[x][y - 1] = 1, u q.append((x, y - 1)) if x < h - 1 and grid[x + 1][y] == "." and check[x + 1][y] == 0: check[x + 1][y], parent[x + 1][y] = 1, u q.append((x + 1, y)) if y < w - 1 and grid[x][y + 1] == "." and check[x][y + 1] == 0: check[x][y + 1], parent[x][y + 1] = 1, u q.append((x, y + 1)) check[x][y] = 2 def main(): bfs((0, 0)) if parent[h - 1][w - 1] != -1: x, y = h - 1, w - 1 while x != 0 or y != 0: grid[x][y] = "#" x, y = parent[x][y] grid[0][0] = "#" pt = 0 for i in range(h): for j in range(w): if grid[i][j] == ".": pt += 1 else: pt = -1 print(pt) if __name__ == "__main__": main()
false
10.169492
[ "- for i in range(h):", "- for j in range(w):", "- if grid[i][j] == \".\" and check[i][j] == 0:", "- dx, dy = abs(i - u[0]), abs(j - u[1])", "- if dx <= 1 and dy <= 1 and dx + dy < 2:", "- check[i][j] = 1", "- parent[i][j] = u", "- q.append((i, j))", "- check[u[0]][u[1]] = 2", "+ x, y = u[0], u[1]", "+ if x > 0 and grid[x - 1][y] == \".\" and check[x - 1][y] == 0:", "+ check[x - 1][y], parent[x - 1][y] = 1, u", "+ q.append((x - 1, y))", "+ if y > 0 and grid[x][y - 1] == \".\" and check[x][y - 1] == 0:", "+ check[x][y - 1], parent[x][y - 1] = 1, u", "+ q.append((x, y - 1))", "+ if x < h - 1 and grid[x + 1][y] == \".\" and check[x + 1][y] == 0:", "+ check[x + 1][y], parent[x + 1][y] = 1, u", "+ q.append((x + 1, y))", "+ if y < w - 1 and grid[x][y + 1] == \".\" and check[x][y + 1] == 0:", "+ check[x][y + 1], parent[x][y + 1] = 1, u", "+ q.append((x, y + 1))", "+ check[x][y] = 2" ]
false
0.036658
0.037724
0.971727
[ "s555248130", "s942577901" ]
u445624660
p03659
python
s306478732
s304207700
264
211
86,736
24,800
Accepted
Accepted
20.08
# 累積和をととっといて比較 n = int(eval(input())) arr = list(map(int, input().split())) ruiseki = [0 for _ in range(n)] ruiseki[0] = arr[0] for i in range(1, n): ruiseki[i] += ruiseki[i - 1] + arr[i] inf = 10 ** 20 ans = inf for i in range(n - 1): x = ruiseki[i] y = ruiseki[-1] - x ans = min(ans, abs(x - y)) print(ans)
# 累積和が見える n = int(eval(input())) a = list(map(int, input().split())) ruiseki = [0 for _ in range(n)] ruiseki[0] = a[0] for i in range(1, n): ruiseki[i] = ruiseki[i-1] + a[i] ans = 10 ** 16 for i in range(n-1): ans = min(ans, abs(ruiseki[-1] - ruiseki[i]*2)) print(ans)
18
13
340
283
# 累積和をととっといて比較 n = int(eval(input())) arr = list(map(int, input().split())) ruiseki = [0 for _ in range(n)] ruiseki[0] = arr[0] for i in range(1, n): ruiseki[i] += ruiseki[i - 1] + arr[i] inf = 10**20 ans = inf for i in range(n - 1): x = ruiseki[i] y = ruiseki[-1] - x ans = min(ans, abs(x - y)) print(ans)
# 累積和が見える n = int(eval(input())) a = list(map(int, input().split())) ruiseki = [0 for _ in range(n)] ruiseki[0] = a[0] for i in range(1, n): ruiseki[i] = ruiseki[i - 1] + a[i] ans = 10**16 for i in range(n - 1): ans = min(ans, abs(ruiseki[-1] - ruiseki[i] * 2)) print(ans)
false
27.777778
[ "-# 累積和をととっといて比較", "+# 累積和が見える", "-arr = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "-ruiseki[0] = arr[0]", "+ruiseki[0] = a[0]", "- ruiseki[i] += ruiseki[i - 1] + arr[i]", "-inf = 10**20", "-ans = inf", "+ ruiseki[i] = ruiseki[i - 1] + a[i]", "+ans = 10**16", "- x = ruiseki[i]", "- y = ruiseki[-1] - x", "- ans = min(ans, abs(x - y))", "+ ans = min(ans, abs(ruiseki[-1] - ruiseki[i] * 2))" ]
false
0.076421
0.041465
1.843051
[ "s306478732", "s304207700" ]
u227082700
p02813
python
s187212659
s701451569
43
29
3,060
3,060
Accepted
Accepted
32.56
n=int(eval(input())) p=list(map(int,input().split())) q=list(map(int,input().split())) from itertools import permutations for i,j in enumerate(permutations([i+1 for i in range(n)],n)): if p==list(j):a=i if q==list(j):b=i print((abs(a-b)))
n=int(eval(input())) p=tuple(map(int,input().split())) q=tuple(map(int,input().split())) from itertools import permutations for i,x in enumerate(permutations([i+1 for i in range(n)],n)): if x==p:a=i if x==q:b=i print((abs(a-b)))
8
8
241
231
n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) from itertools import permutations for i, j in enumerate(permutations([i + 1 for i in range(n)], n)): if p == list(j): a = i if q == list(j): b = i print((abs(a - b)))
n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) from itertools import permutations for i, x in enumerate(permutations([i + 1 for i in range(n)], n)): if x == p: a = i if x == q: b = i print((abs(a - b)))
false
0
[ "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "+p = tuple(map(int, input().split()))", "+q = tuple(map(int, input().split()))", "-for i, j in enumerate(permutations([i + 1 for i in range(n)], n)):", "- if p == list(j):", "+for i, x in enumerate(permutations([i + 1 for i in range(n)], n)):", "+ if x == p:", "- if q == list(j):", "+ if x == q:" ]
false
0.054592
0.032136
1.698761
[ "s187212659", "s701451569" ]
u649202997
p03073
python
s153532321
s037456782
45
35
3,188
3,188
Accepted
Accepted
22.22
def main(n): odd = "1" even= "0" if(n[0] =="0"): # zero mode odd = "0" even= "1" return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n))) print((main(eval(input()))))
def main(n): odd = "1" even= "0" if(n[0] =="0"): # zero mode odd = "0" even= "1" #return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n))) a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n),2)) b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n),2)) return a+b print((main(eval(input())))) #assert(1 == main("000")) #assert(3 == main("10010010")) #assert(0 == main("0"))
10
16
229
472
def main(n): odd = "1" even = "0" if n[0] == "0": # zero mode odd = "0" even = "1" return sum( (((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n)) ) print((main(eval(input()))))
def main(n): odd = "1" even = "0" if n[0] == "0": # zero mode odd = "0" even = "1" # return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n))) a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n), 2)) b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n), 2)) return a + b print((main(eval(input())))) # assert(1 == main("000")) # assert(3 == main("10010010")) # assert(0 == main("0"))
false
37.5
[ "- return sum(", "- (((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd))", "- for i in range(1, len(n))", "- )", "+ # return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n)))", "+ a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n), 2))", "+ b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n), 2))", "+ return a + b", "+# assert(1 == main(\"000\"))", "+# assert(3 == main(\"10010010\"))", "+# assert(0 == main(\"0\"))" ]
false
0.047053
0.04846
0.970959
[ "s153532321", "s037456782" ]
u006657459
p03816
python
s465287269
s290510089
48
40
14,564
16,168
Accepted
Accepted
16.67
N = int(eval(input())) A = [int(Ai) for Ai in input().split()] cards = len(set(A)) print((cards if cards % 2 == 1 else cards - 1))
eval(input()) cards = len(set([Ai for Ai in input().split()])) print((cards if cards % 2 == 1 else cards - 1))
4
3
125
104
N = int(eval(input())) A = [int(Ai) for Ai in input().split()] cards = len(set(A)) print((cards if cards % 2 == 1 else cards - 1))
eval(input()) cards = len(set([Ai for Ai in input().split()])) print((cards if cards % 2 == 1 else cards - 1))
false
25
[ "-N = int(eval(input()))", "-A = [int(Ai) for Ai in input().split()]", "-cards = len(set(A))", "+eval(input())", "+cards = len(set([Ai for Ai in input().split()]))" ]
false
0.077106
0.037924
2.033179
[ "s465287269", "s290510089" ]
u532955973
p02606
python
s290492839
s753744851
31
25
9,252
9,196
Accepted
Accepted
19.35
#!/usr/bin/env python3 # atcoder # Türkler var mı? # Herkese memnün oldum import sys iimr = lambda: map(int, sys.stdin.readline().rstrip().split()) readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) MOD = (10 ** 9) + 7 # operować sobie na typie int32_t def 関数(l,r,d): res = 0 for i in range(l, r+1): if i % d == 0: res += 1 return res def çözmek(): L, R, d = iimr() res = [] res.append(関数(L, R, d)) print(*res, sep="\n") if __name__ == "__main__": çözmek()
#!/usr/bin/env python3 # atcoder # Türkler var mı? # Herkese memnün oldum import sys iimr = lambda: map(int, sys.stdin.readline().rstrip().split()) readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) MOD = (10 ** 9) + 7 # operować sobie na typie int32_t def 関数(l,r,d): res = 0 for i in range(l, r+1): res += i % d == 0 return res def çözmek(): L, R, d = iimr() res = [] res.append(関数(L, R, d)) print(*res, sep="\n") if __name__ == "__main__": çözmek()
27
26
559
540
#!/usr/bin/env python3 # atcoder # Türkler var mı? # Herkese memnün oldum import sys iimr = lambda: map(int, sys.stdin.readline().rstrip().split()) readline = sys.stdin.buffer.readline sys.setrecursionlimit(10**8) MOD = (10**9) + 7 # operować sobie na typie int32_t def 関数(l, r, d): res = 0 for i in range(l, r + 1): if i % d == 0: res += 1 return res def çözmek(): L, R, d = iimr() res = [] res.append(関数(L, R, d)) print(*res, sep="\n") if __name__ == "__main__": çözmek()
#!/usr/bin/env python3 # atcoder # Türkler var mı? # Herkese memnün oldum import sys iimr = lambda: map(int, sys.stdin.readline().rstrip().split()) readline = sys.stdin.buffer.readline sys.setrecursionlimit(10**8) MOD = (10**9) + 7 # operować sobie na typie int32_t def 関数(l, r, d): res = 0 for i in range(l, r + 1): res += i % d == 0 return res def çözmek(): L, R, d = iimr() res = [] res.append(関数(L, R, d)) print(*res, sep="\n") if __name__ == "__main__": çözmek()
false
3.703704
[ "- if i % d == 0:", "- res += 1", "+ res += i % d == 0" ]
false
0.037186
0.037052
1.003596
[ "s290492839", "s753744851" ]
u844005364
p03331
python
s645200971
s053249625
24
17
3,316
2,940
Accepted
Accepted
29.17
n = int(eval(input())) print((10 if n in [10 ** x for x in range(6)] else sum(map(int,str(n)))))
n=sum(map(int,eval(input()))) print((10 if n==1 else n))
3
2
92
49
n = int(eval(input())) print((10 if n in [10**x for x in range(6)] else sum(map(int, str(n)))))
n = sum(map(int, eval(input()))) print((10 if n == 1 else n))
false
33.333333
[ "-n = int(eval(input()))", "-print((10 if n in [10**x for x in range(6)] else sum(map(int, str(n)))))", "+n = sum(map(int, eval(input())))", "+print((10 if n == 1 else n))" ]
false
0.044226
0.037127
1.191225
[ "s645200971", "s053249625" ]
u972658925
p03073
python
s678336258
s337970312
90
76
11,088
9,992
Accepted
Accepted
15.56
from distutils.util import strtobool s = eval(input()) ss = [int(s[0]) if x % 2 == 0 else int(s[0])^1 for x in range(len(s))] cnt = 0 for i in range(len(s)): if int(s[i]) != ss[i]: cnt += 1 print(cnt)
#from distutils.util import strtobool s = eval(input()) ss = [int(s[0]) if x % 2 == 0 else int(s[0])^1 for x in range(len(s))] cnt = 0 for i in range(len(s)): if int(s[i]) != ss[i]: cnt += 1 print(cnt)
10
10
217
218
from distutils.util import strtobool s = eval(input()) ss = [int(s[0]) if x % 2 == 0 else int(s[0]) ^ 1 for x in range(len(s))] cnt = 0 for i in range(len(s)): if int(s[i]) != ss[i]: cnt += 1 print(cnt)
# from distutils.util import strtobool s = eval(input()) ss = [int(s[0]) if x % 2 == 0 else int(s[0]) ^ 1 for x in range(len(s))] cnt = 0 for i in range(len(s)): if int(s[i]) != ss[i]: cnt += 1 print(cnt)
false
0
[ "-from distutils.util import strtobool", "-", "+# from distutils.util import strtobool" ]
false
0.040273
0.032058
1.256232
[ "s678336258", "s337970312" ]
u018771977
p02583
python
s051651515
s550313618
129
93
9,156
9,060
Accepted
Accepted
27.91
#! env/bin/local python3 # -*- coding: utf-8 -*- from itertools import combinations def is_tri(_a, _b, _c): if (_a + _b > _c) and (_b + _c > _a) and (_c + _a > _b): return True else: return False n = int(eval(input())) sticks = list(map(int, input().split())) h = combinations(sticks, 3) counter = 0 for a, b, c in h: if is_tri(a, b, c): a, b, c = sorted([a, b, c]) if (a != b) and (b != c): counter += 1 print(counter)
#! env/bin/local python3 # -*- coding: utf-8 -*- from itertools import combinations def is_tri(_a, _b, _c): if (_a + _b > _c) and (_b + _c > _a) and (_c + _a > _b): return True else: return False n = int(eval(input())) sticks = list(map(int, input().split())) h = combinations(sticks, 3) counter = 0 for a, b, c in h: if is_tri(a, b, c): # a, b, c = sorted([a, b, c]) if (a != b) and (b != c) and (c != a): counter += 1 print(counter)
26
26
503
518
#! env/bin/local python3 # -*- coding: utf-8 -*- from itertools import combinations def is_tri(_a, _b, _c): if (_a + _b > _c) and (_b + _c > _a) and (_c + _a > _b): return True else: return False n = int(eval(input())) sticks = list(map(int, input().split())) h = combinations(sticks, 3) counter = 0 for a, b, c in h: if is_tri(a, b, c): a, b, c = sorted([a, b, c]) if (a != b) and (b != c): counter += 1 print(counter)
#! env/bin/local python3 # -*- coding: utf-8 -*- from itertools import combinations def is_tri(_a, _b, _c): if (_a + _b > _c) and (_b + _c > _a) and (_c + _a > _b): return True else: return False n = int(eval(input())) sticks = list(map(int, input().split())) h = combinations(sticks, 3) counter = 0 for a, b, c in h: if is_tri(a, b, c): # a, b, c = sorted([a, b, c]) if (a != b) and (b != c) and (c != a): counter += 1 print(counter)
false
0
[ "- a, b, c = sorted([a, b, c])", "- if (a != b) and (b != c):", "+ # a, b, c = sorted([a, b, c])", "+ if (a != b) and (b != c) and (c != a):" ]
false
0.11733
0.047993
2.44475
[ "s051651515", "s550313618" ]