user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u014333473
p03207
python
s438264335
s502577346
30
27
9,028
9,092
Accepted
Accepted
10
n=sorted([int(eval(input())) for _ in range(int(eval(input())))],reverse=True);print((max(n)//2+sum(n[1:])))
n=sorted([int(eval(input())) for _ in range(int(eval(input())))],reverse=True);print((sum(n)-max(n)//2))
1
1
94
90
n = sorted([int(eval(input())) for _ in range(int(eval(input())))], reverse=True) print((max(n) // 2 + sum(n[1:])))
n = sorted([int(eval(input())) for _ in range(int(eval(input())))], reverse=True) print((sum(n) - max(n) // 2))
false
0
[ "-print((max(n) // 2 + sum(n[1:])))", "+print((sum(n) - max(n) // 2))" ]
false
0.225871
0.097322
2.320861
[ "s438264335", "s502577346" ]
u037441960
p00084
python
s293971397
s472411017
40
30
6,512
6,528
Accepted
Accepted
25
import re s = re.split("[ .,]", input()) sl = len(s) ans = list() for i in range(sl) : if(2 < len(s[i]) and len(s[i]) < 7) : ans.append(s[i]) else : pass ansl = len(ans) for i in range(ansl) : if(i == ansl - 1) : print(ans[i]) else : print(ans[i], end = (" "))
import re I = input().split() S = [] for i in range(len(I)) : I[i] = re.split("[,.]", I[i]) if 2 < len(I[i][0]) and len(I[i][0]) < 7 : S.append(I[i][0]) for i in range(len(S)) : if i == len(S) - 1 : print(S[i]) else : print(S[i], " ", sep = "", end = "")
19
15
307
312
import re s = re.split("[ .,]", input()) sl = len(s) ans = list() for i in range(sl): if 2 < len(s[i]) and len(s[i]) < 7: ans.append(s[i]) else: pass ansl = len(ans) for i in range(ansl): if i == ansl - 1: print(ans[i]) else: print(ans[i], end=(" "))
import re I = input().split() S = [] for i in range(len(I)): I[i] = re.split("[,.]", I[i]) if 2 < len(I[i][0]) and len(I[i][0]) < 7: S.append(I[i][0]) for i in range(len(S)): if i == len(S) - 1: print(S[i]) else: print(S[i], " ", sep="", end="")
false
21.052632
[ "-s = re.split(\"[ .,]\", input())", "-sl = len(s)", "-ans = list()", "-for i in range(sl):", "- if 2 < len(s[i]) and len(s[i]) < 7:", "- ans.append(s[i])", "+I = input().split()", "+S = []", "+for i in range(len(I)):", "+ I[i] = re.split(\"[,.]\", I[i])", "+ if 2 < len(I[i][0]) and len(I[i][0]) < 7:", "+ S.append(I[i][0])", "+for i in range(len(S)):", "+ if i == len(S) - 1:", "+ print(S[i])", "- pass", "-ansl = len(ans)", "-for i in range(ansl):", "- if i == ansl - 1:", "- print(ans[i])", "- else:", "- print(ans[i], end=(\" \"))", "+ print(S[i], \" \", sep=\"\", end=\"\")" ]
false
0.069875
0.04777
1.462741
[ "s293971397", "s472411017" ]
u314050667
p03295
python
s104140246
s049884815
597
276
28,656
26,744
Accepted
Accepted
53.77
N, M = list(map(int,input().split())) E = sorted([list(map(int, input().split())) for _ in range(M)]) c = E[0] cnt = 0 for i in range(1,M): if c[0] <= E[i][0] < c[1]: c = [max(c[0],E[i][0]), min(c[1],E[i][1])] else: cnt += 1 c = E[i] print((cnt+1))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter N,M = list(map(int,readline().split())) m = list(map(int,read().split())) AB = sorted(zip(m,m)) AB.sort(key = lambda x: x[1]) c = AB[0][1] ans = 1 for i in range(1,M): if AB[i][0] < c: continue else: ans += 1 c = AB[i][1] print(ans)
13
23
262
405
N, M = list(map(int, input().split())) E = sorted([list(map(int, input().split())) for _ in range(M)]) c = E[0] cnt = 0 for i in range(1, M): if c[0] <= E[i][0] < c[1]: c = [max(c[0], E[i][0]), min(c[1], E[i][1])] else: cnt += 1 c = E[i] print((cnt + 1))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter N, M = list(map(int, readline().split())) m = list(map(int, read().split())) AB = sorted(zip(m, m)) AB.sort(key=lambda x: x[1]) c = AB[0][1] ans = 1 for i in range(1, M): if AB[i][0] < c: continue else: ans += 1 c = AB[i][1] print(ans)
false
43.478261
[ "-N, M = list(map(int, input().split()))", "-E = sorted([list(map(int, input().split())) for _ in range(M)])", "-c = E[0]", "-cnt = 0", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+from operator import itemgetter", "+", "+N, M = list(map(int, readline().split()))", "+m = list(map(int, read().split()))", "+AB = sorted(zip(m, m))", "+AB.sort(key=lambda x: x[1])", "+c = AB[0][1]", "+ans = 1", "- if c[0] <= E[i][0] < c[1]:", "- c = [max(c[0], E[i][0]), min(c[1], E[i][1])]", "+ if AB[i][0] < c:", "+ continue", "- cnt += 1", "- c = E[i]", "-print((cnt + 1))", "+ ans += 1", "+ c = AB[i][1]", "+print(ans)" ]
false
0.035836
0.03821
0.937879
[ "s104140246", "s049884815" ]
u933341648
p02695
python
s870051910
s135458692
1,126
589
22,944
9,196
Accepted
Accepted
47.69
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] arr = [] def f(p): if len(p) == n+1: arr.append(p[:-1]) return while p[-1] <= m: f(p + [p[-1]]) p[-1] += 1 f([1]) ans = 0 for p in arr: score = 0 for a, b, c, d in queries: if p[b-1] - p[a-1] == c: score += d ans = max(ans, score) print(ans)
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b-1] - p[a-1] == c: score += d return score def f(p): if len(p) == n+1: global ans ans = max(ans, calc_score(p)) return while p[-1] <= m: f(p + [p[-1]]) p[-1] += 1 f([1]) print(ans)
23
23
439
456
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] arr = [] def f(p): if len(p) == n + 1: arr.append(p[:-1]) return while p[-1] <= m: f(p + [p[-1]]) p[-1] += 1 f([1]) ans = 0 for p in arr: score = 0 for a, b, c, d in queries: if p[b - 1] - p[a - 1] == c: score += d ans = max(ans, score) print(ans)
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b - 1] - p[a - 1] == c: score += d return score def f(p): if len(p) == n + 1: global ans ans = max(ans, calc_score(p)) return while p[-1] <= m: f(p + [p[-1]]) p[-1] += 1 f([1]) print(ans)
false
0
[ "-arr = []", "+ans = 0", "+", "+", "+def calc_score(p):", "+ score = 0", "+ for a, b, c, d in queries:", "+ if p[b - 1] - p[a - 1] == c:", "+ score += d", "+ return score", "- arr.append(p[:-1])", "+ global ans", "+ ans = max(ans, calc_score(p))", "-ans = 0", "-for p in arr:", "- score = 0", "- for a, b, c, d in queries:", "- if p[b - 1] - p[a - 1] == c:", "- score += d", "- ans = max(ans, score)" ]
false
0.232573
0.14071
1.65286
[ "s870051910", "s135458692" ]
u634461820
p03556
python
s285747074
s057091370
194
153
13,264
12,484
Accepted
Accepted
21.13
import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N = I() ans = [pow(i,2) for i in range(100000) if pow(i,2)<=N] print((ans[-1]))
import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N = I() ans = int(math.sqrt(N)) print((ans**2))
16
17
392
373
import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N = I() ans = [pow(i, 2) for i in range(100000) if pow(i, 2) <= N] print((ans[-1]))
import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N = I() ans = int(math.sqrt(N)) print((ans**2))
false
5.882353
[ "+import math", "-ans = [pow(i, 2) for i in range(100000) if pow(i, 2) <= N]", "-print((ans[-1]))", "+ans = int(math.sqrt(N))", "+print((ans**2))" ]
false
0.105802
0.118854
0.890185
[ "s285747074", "s057091370" ]
u266113953
p02659
python
s701887323
s559000321
28
24
9,996
9,088
Accepted
Accepted
14.29
import math from decimal import * A, B = list(map(Decimal, input().split())) print((math.floor(A*B)))
sp = input().split() A = int(sp[0]) B = int(sp[1].replace(".","")) print((A*B//100))
4
4
102
85
import math from decimal import * A, B = list(map(Decimal, input().split())) print((math.floor(A * B)))
sp = input().split() A = int(sp[0]) B = int(sp[1].replace(".", "")) print((A * B // 100))
false
0
[ "-import math", "-from decimal import *", "-", "-A, B = list(map(Decimal, input().split()))", "-print((math.floor(A * B)))", "+sp = input().split()", "+A = int(sp[0])", "+B = int(sp[1].replace(\".\", \"\"))", "+print((A * B // 100))" ]
false
0.101283
0.039099
2.590427
[ "s701887323", "s559000321" ]
u133936772
p02834
python
s005855933
s260277829
896
662
117,048
28,464
Accepted
Accepted
26.12
import sys sys.setrecursionlimit(10**9) f=lambda:list(map(int,input().split())) n,st,sa=f() st-=1 sa-=1 g=[[] for _ in range(n)] for _ in range(n-1): a,b=f() g[a-1].append(b-1) g[b-1].append(a-1) def dfs(v,p=-1,d=0): l[v]=d for c in g[v]: if c==p: continue dfs(c,v,d+1) def dist(s): global l l=[0]*n dfs(s) return l lt=dist(st) la=dist(sa) m=0 for i in range(n): if lt[i]<la[i]: m=max(m,la[i]) print((m-1))
f=lambda:list(map(int,input().split())) n,st,sa=f() st-=1 sa-=1 g=[[] for _ in range(n)] for _ in range(n-1): a,b=f() g[a-1].append(b-1) g[b-1].append(a-1) def bfs(s): l=[-1]*n; l[s]=0; q=[s] while q: v=q.pop(); d=l[v]+1 for c in g[v]: if l[c]<0: l[c]=d; q+=[c] return l lt=bfs(st) la=bfs(sa) m=0 for i in range(n): if lt[i]<la[i]: m=max(m,la[i]) print((m-1))
27
22
452
400
import sys sys.setrecursionlimit(10**9) f = lambda: list(map(int, input().split())) n, st, sa = f() st -= 1 sa -= 1 g = [[] for _ in range(n)] for _ in range(n - 1): a, b = f() g[a - 1].append(b - 1) g[b - 1].append(a - 1) def dfs(v, p=-1, d=0): l[v] = d for c in g[v]: if c == p: continue dfs(c, v, d + 1) def dist(s): global l l = [0] * n dfs(s) return l lt = dist(st) la = dist(sa) m = 0 for i in range(n): if lt[i] < la[i]: m = max(m, la[i]) print((m - 1))
f = lambda: list(map(int, input().split())) n, st, sa = f() st -= 1 sa -= 1 g = [[] for _ in range(n)] for _ in range(n - 1): a, b = f() g[a - 1].append(b - 1) g[b - 1].append(a - 1) def bfs(s): l = [-1] * n l[s] = 0 q = [s] while q: v = q.pop() d = l[v] + 1 for c in g[v]: if l[c] < 0: l[c] = d q += [c] return l lt = bfs(st) la = bfs(sa) m = 0 for i in range(n): if lt[i] < la[i]: m = max(m, la[i]) print((m - 1))
false
18.518519
[ "-import sys", "-", "-sys.setrecursionlimit(10**9)", "-def dfs(v, p=-1, d=0):", "- l[v] = d", "- for c in g[v]:", "- if c == p:", "- continue", "- dfs(c, v, d + 1)", "-", "-", "-def dist(s):", "- global l", "- l = [0] * n", "- dfs(s)", "+def bfs(s):", "+ l = [-1] * n", "+ l[s] = 0", "+ q = [s]", "+ while q:", "+ v = q.pop()", "+ d = l[v] + 1", "+ for c in g[v]:", "+ if l[c] < 0:", "+ l[c] = d", "+ q += [c]", "-lt = dist(st)", "-la = dist(sa)", "+lt = bfs(st)", "+la = bfs(sa)" ]
false
0.043954
0.037078
1.185455
[ "s005855933", "s260277829" ]
u896741788
p04015
python
s730278526
s589395554
74
33
3,188
9,528
Accepted
Accepted
55.41
n,a=list(map(int,input().split())) l=list(map(int,input().split())) dp=[0]*5300 dp[l[0]-a]=1 for x in l[1:]: b=x-a if b>=0: for i in range(2500,-2501,-1): dp[i+b]+=dp[i] else: for i in range(-2500,2501): dp[i+b]+=dp[i] dp[b]+=1 print((dp[0]))
n,a=list(map(int,input().split())) from collections import defaultdict dp=defaultdict(int) dp[0]=1 for i in map(int,input().split()): i-=a for k in sorted(list(dp.keys()),reverse=(i>=0)): dp[k+i]+=dp[k] print((dp[0]-1))
15
10
277
231
n, a = list(map(int, input().split())) l = list(map(int, input().split())) dp = [0] * 5300 dp[l[0] - a] = 1 for x in l[1:]: b = x - a if b >= 0: for i in range(2500, -2501, -1): dp[i + b] += dp[i] else: for i in range(-2500, 2501): dp[i + b] += dp[i] dp[b] += 1 print((dp[0]))
n, a = list(map(int, input().split())) from collections import defaultdict dp = defaultdict(int) dp[0] = 1 for i in map(int, input().split()): i -= a for k in sorted(list(dp.keys()), reverse=(i >= 0)): dp[k + i] += dp[k] print((dp[0] - 1))
false
33.333333
[ "-l = list(map(int, input().split()))", "-dp = [0] * 5300", "-dp[l[0] - a] = 1", "-for x in l[1:]:", "- b = x - a", "- if b >= 0:", "- for i in range(2500, -2501, -1):", "- dp[i + b] += dp[i]", "- else:", "- for i in range(-2500, 2501):", "- dp[i + b] += dp[i]", "- dp[b] += 1", "-print((dp[0]))", "+from collections import defaultdict", "+", "+dp = defaultdict(int)", "+dp[0] = 1", "+for i in map(int, input().split()):", "+ i -= a", "+ for k in sorted(list(dp.keys()), reverse=(i >= 0)):", "+ dp[k + i] += dp[k]", "+print((dp[0] - 1))" ]
false
0.049809
0.036801
1.353485
[ "s730278526", "s589395554" ]
u562935282
p03999
python
s532405995
s145406636
28
24
3,060
2,940
Accepted
Accepted
14.29
from itertools import zip_longest s = eval(input()) s = list(s) cnt_pos = len(s) - 1#記号の入り得る位置の数 formula_cnt = 2 ** (cnt_pos)#式数 ans = 0 for i in range(formula_cnt): sgns = ['+' if (i & (2 ** x) != 0) else '' for x in range(cnt_pos)] formula = '' for c, sgn in zip_longest(s, sgns, fillvalue=''): formula += c + sgn #print(i, s, sgns, formula) ans += eval(formula) print(ans)
def main(): import sys sys.setrecursionlimit(10 ** 7) s = eval(input()) def calc(cur=1, t=s[0]): if cur == len(s): return eval(t) return calc(cur + 1, t + s[cur]) + calc(cur + 1, t + '+' + s[cur]) print((calc())) if __name__ == '__main__': main()
16
16
415
311
from itertools import zip_longest s = eval(input()) s = list(s) cnt_pos = len(s) - 1 # 記号の入り得る位置の数 formula_cnt = 2 ** (cnt_pos) # 式数 ans = 0 for i in range(formula_cnt): sgns = ["+" if (i & (2**x) != 0) else "" for x in range(cnt_pos)] formula = "" for c, sgn in zip_longest(s, sgns, fillvalue=""): formula += c + sgn # print(i, s, sgns, formula) ans += eval(formula) print(ans)
def main(): import sys sys.setrecursionlimit(10**7) s = eval(input()) def calc(cur=1, t=s[0]): if cur == len(s): return eval(t) return calc(cur + 1, t + s[cur]) + calc(cur + 1, t + "+" + s[cur]) print((calc())) if __name__ == "__main__": main()
false
0
[ "-from itertools import zip_longest", "+def main():", "+ import sys", "-s = eval(input())", "-s = list(s)", "-cnt_pos = len(s) - 1 # 記号の入り得る位置の数", "-formula_cnt = 2 ** (cnt_pos) # 式数", "-ans = 0", "-for i in range(formula_cnt):", "- sgns = [\"+\" if (i & (2**x) != 0) else \"\" for x in range(cnt_pos)]", "- formula = \"\"", "- for c, sgn in zip_longest(s, sgns, fillvalue=\"\"):", "- formula += c + sgn", "- # print(i, s, sgns, formula)", "- ans += eval(formula)", "-print(ans)", "+ sys.setrecursionlimit(10**7)", "+ s = eval(input())", "+", "+ def calc(cur=1, t=s[0]):", "+ if cur == len(s):", "+ return eval(t)", "+ return calc(cur + 1, t + s[cur]) + calc(cur + 1, t + \"+\" + s[cur])", "+", "+ print((calc()))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.142708
0.107185
1.331422
[ "s532405995", "s145406636" ]
u878849567
p02915
python
s916357012
s753710260
171
17
38,256
2,940
Accepted
Accepted
90.06
n = int(eval(input())) ans = 0 ans = n*n*n print(ans)
n = int(eval(input())) print((n ** 3))
4
2
50
32
n = int(eval(input())) ans = 0 ans = n * n * n print(ans)
n = int(eval(input())) print((n**3))
false
50
[ "-ans = 0", "-ans = n * n * n", "-print(ans)", "+print((n**3))" ]
false
0.041881
0.041848
1.000794
[ "s916357012", "s753710260" ]
u721316601
p02788
python
s622672471
s634672576
1,957
877
65,624
65,616
Accepted
Accepted
55.19
from math import * import sys input = sys.stdin.readline def main(): N, D, A = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 q = [] ans = 0 for X, H in XH: while q and q[0][0] < X-D: x, c = q.pop(0) t -= c H -= A * t if H <= 0: continue c = ceil(H/A) ans += c q.append((X+D, c)) t += c print(ans) if __name__ == '__main__': main()
from math import * import sys from collections import * input = sys.stdin.readline def main(): N, D, A = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 q = deque([]) ans = 0 for X, H in XH: while q and q[0][0] < X-D: x, c = q.popleft() t -= c H -= A * t if H <= 0: continue c = ceil(H/A) ans += c q.append((X+D, c)) t += c print(ans) if __name__ == '__main__': main()
26
29
542
599
from math import * import sys input = sys.stdin.readline def main(): N, D, A = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 q = [] ans = 0 for X, H in XH: while q and q[0][0] < X - D: x, c = q.pop(0) t -= c H -= A * t if H <= 0: continue c = ceil(H / A) ans += c q.append((X + D, c)) t += c print(ans) if __name__ == "__main__": main()
from math import * import sys from collections import * input = sys.stdin.readline def main(): N, D, A = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 q = deque([]) ans = 0 for X, H in XH: while q and q[0][0] < X - D: x, c = q.popleft() t -= c H -= A * t if H <= 0: continue c = ceil(H / A) ans += c q.append((X + D, c)) t += c print(ans) if __name__ == "__main__": main()
false
10.344828
[ "+from collections import *", "- q = []", "+ q = deque([])", "- x, c = q.pop(0)", "+ x, c = q.popleft()" ]
false
0.036501
0.036582
0.997793
[ "s622672471", "s634672576" ]
u540877546
p03371
python
s809398448
s779358611
163
63
38,256
65,684
Accepted
Accepted
61.35
a, b, c, x, y = list(map(int, input().split())) ans = 0 if a+b <= c*2: ans += min(x, y)*(a+b) else: ans += min(x, y)*c*2 if x > y: if a <= c*2: ans += (x-y)*a else: ans += (x-y)*c*2 else: if b <= c*2: ans += (y-x)*b else: ans += (y-x)*c*2 print(ans)
a, b, c, x, y = list(map(int, input().split())) INF = float("inf") ans = INF for ab in range(max(x, y)*2+1): if ab % 2 == 0: ans = min(ans, ab*c + max(x-ab//2, 0)*a + max(y-ab//2, 0)*b) print(ans)
20
7
322
215
a, b, c, x, y = list(map(int, input().split())) ans = 0 if a + b <= c * 2: ans += min(x, y) * (a + b) else: ans += min(x, y) * c * 2 if x > y: if a <= c * 2: ans += (x - y) * a else: ans += (x - y) * c * 2 else: if b <= c * 2: ans += (y - x) * b else: ans += (y - x) * c * 2 print(ans)
a, b, c, x, y = list(map(int, input().split())) INF = float("inf") ans = INF for ab in range(max(x, y) * 2 + 1): if ab % 2 == 0: ans = min(ans, ab * c + max(x - ab // 2, 0) * a + max(y - ab // 2, 0) * b) print(ans)
false
65
[ "-ans = 0", "-if a + b <= c * 2:", "- ans += min(x, y) * (a + b)", "-else:", "- ans += min(x, y) * c * 2", "-if x > y:", "- if a <= c * 2:", "- ans += (x - y) * a", "- else:", "- ans += (x - y) * c * 2", "-else:", "- if b <= c * 2:", "- ans += (y - x) * b", "- else:", "- ans += (y - x) * c * 2", "+INF = float(\"inf\")", "+ans = INF", "+for ab in range(max(x, y) * 2 + 1):", "+ if ab % 2 == 0:", "+ ans = min(ans, ab * c + max(x - ab // 2, 0) * a + max(y - ab // 2, 0) * b)" ]
false
0.03675
0.154469
0.23791
[ "s809398448", "s779358611" ]
u281610856
p03730
python
s602862074
s899140282
19
17
3,060
2,940
Accepted
Accepted
10.53
a, b, c = list(map(int, input().split())) num = a for i in range(b): if num % b == c: print('YES') break num += a else: print('NO')
a, b, c = list(map(int, input().split())) num = a for i in range(b): if num % b == c: print("YES") exit() num += a print("NO")
9
8
161
151
a, b, c = list(map(int, input().split())) num = a for i in range(b): if num % b == c: print("YES") break num += a else: print("NO")
a, b, c = list(map(int, input().split())) num = a for i in range(b): if num % b == c: print("YES") exit() num += a print("NO")
false
11.111111
[ "- break", "+ exit()", "-else:", "- print(\"NO\")", "+print(\"NO\")" ]
false
0.052172
0.052236
0.99876
[ "s602862074", "s899140282" ]
u968166680
p02973
python
s991925789
s445342529
253
77
55,796
14,092
Accepted
Accepted
69.57
def main(): import sys import bisect read = sys.stdin.buffer.read bisect_right = bisect.bisect_right N, *A = list(map(int, read().split())) dp = [A[-1]] for a in reversed(A[:-1]): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == '__main__': main()
import sys from bisect import bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *A = list(map(int, read().split())) vec = [A[-1]] for a in reversed(A[:-1]): if a >= vec[-1]: vec.append(a) else: vec[bisect_right(vec, a)] = a print((len(vec))) return if __name__ == '__main__': main()
22
26
400
478
def main(): import sys import bisect read = sys.stdin.buffer.read bisect_right = bisect.bisect_right N, *A = list(map(int, read().split())) dp = [A[-1]] for a in reversed(A[:-1]): if a >= dp[-1]: dp.append(a) else: dp[bisect_right(dp, a)] = a print((len(dp))) return if __name__ == "__main__": main()
import sys from bisect import bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): N, *A = list(map(int, read().split())) vec = [A[-1]] for a in reversed(A[:-1]): if a >= vec[-1]: vec.append(a) else: vec[bisect_right(vec, a)] = a print((len(vec))) return if __name__ == "__main__": main()
false
15.384615
[ "+import sys", "+from bisect import bisect_right", "+", "+read = sys.stdin.read", "+readline = sys.stdin.readline", "+readlines = sys.stdin.readlines", "+sys.setrecursionlimit(10**9)", "+INF = 1 << 60", "+", "+", "- import sys", "- import bisect", "-", "- read = sys.stdin.buffer.read", "- bisect_right = bisect.bisect_right", "- dp = [A[-1]]", "+ vec = [A[-1]]", "- if a >= dp[-1]:", "- dp.append(a)", "+ if a >= vec[-1]:", "+ vec.append(a)", "- dp[bisect_right(dp, a)] = a", "- print((len(dp)))", "+ vec[bisect_right(vec, a)] = a", "+ print((len(vec)))" ]
false
0.046877
0.037686
1.243881
[ "s991925789", "s445342529" ]
u875291233
p02670
python
s164448641
s596652215
1,984
939
170,280
148,520
Accepted
Accepted
52.67
# coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read n,*p = list(map(int,read().split())) N = n*n dist = [0]*N for a in range(n): for b in range(n): dist[a*n+b] = min(a,n-1-a,b,n-1-b) #print(dist) #ans = [0]*N ans = 0 iru = [1]*N for pi in p: pi -= 1 ans += dist[pi] iru[pi] = 0 q = [pi] #更新 while q: #print(q) v = q.pop() for i in [-n,-1,1,n]: if i==1 and v%n==n-1: continue if i==-1 and v%n==0: continue nv = v+i if 0 <= nv < N and dist[nv] > dist[v] + iru[v]: q.append(nv) dist[nv] = dist[v] + iru[v] #print(dist) print(ans)
import sys n,*p = list(map(int,sys.stdin.read().split())) dist = [min(a,n-1-a,b,n-1-b) for a in range(n) for b in range(n)] def update(v,nv): if dist[nv] > dist[v] + iru[v]: q.append(nv) dist[nv] = dist[v] + iru[v] ans = 0 iru = [1]*n*n for pi in p: pi -= 1 ans += dist[pi] iru[pi] = 0 q = [pi] while q: v = q.pop() if v%n != n-1: update(v,v+1) if v%n: update(v,v-1) if v >= n: update(v,v-n) if v+n < n*n: update(v,v+n) print(ans)
54
23
824
528
# coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read n, *p = list(map(int, read().split())) N = n * n dist = [0] * N for a in range(n): for b in range(n): dist[a * n + b] = min(a, n - 1 - a, b, n - 1 - b) # print(dist) # ans = [0]*N ans = 0 iru = [1] * N for pi in p: pi -= 1 ans += dist[pi] iru[pi] = 0 q = [pi] # 更新 while q: # print(q) v = q.pop() for i in [-n, -1, 1, n]: if i == 1 and v % n == n - 1: continue if i == -1 and v % n == 0: continue nv = v + i if 0 <= nv < N and dist[nv] > dist[v] + iru[v]: q.append(nv) dist[nv] = dist[v] + iru[v] # print(dist) print(ans)
import sys n, *p = list(map(int, sys.stdin.read().split())) dist = [min(a, n - 1 - a, b, n - 1 - b) for a in range(n) for b in range(n)] def update(v, nv): if dist[nv] > dist[v] + iru[v]: q.append(nv) dist[nv] = dist[v] + iru[v] ans = 0 iru = [1] * n * n for pi in p: pi -= 1 ans += dist[pi] iru[pi] = 0 q = [pi] while q: v = q.pop() if v % n != n - 1: update(v, v + 1) if v % n: update(v, v - 1) if v >= n: update(v, v - n) if v + n < n * n: update(v, v + n) print(ans)
false
57.407407
[ "-# coding: utf-8", "-# Your code here!", "-readline = sys.stdin.readline", "-read = sys.stdin.read", "-n, *p = list(map(int, read().split()))", "-N = n * n", "-dist = [0] * N", "-for a in range(n):", "- for b in range(n):", "- dist[a * n + b] = min(a, n - 1 - a, b, n - 1 - b)", "-# print(dist)", "-# ans = [0]*N", "+n, *p = list(map(int, sys.stdin.read().split()))", "+dist = [min(a, n - 1 - a, b, n - 1 - b) for a in range(n) for b in range(n)]", "+", "+", "+def update(v, nv):", "+ if dist[nv] > dist[v] + iru[v]:", "+ q.append(nv)", "+ dist[nv] = dist[v] + iru[v]", "+", "+", "-iru = [1] * N", "+iru = [1] * n * n", "- # 更新", "- # print(q)", "- for i in [-n, -1, 1, n]:", "- if i == 1 and v % n == n - 1:", "- continue", "- if i == -1 and v % n == 0:", "- continue", "- nv = v + i", "- if 0 <= nv < N and dist[nv] > dist[v] + iru[v]:", "- q.append(nv)", "- dist[nv] = dist[v] + iru[v]", "- # print(dist)", "+ if v % n != n - 1:", "+ update(v, v + 1)", "+ if v % n:", "+ update(v, v - 1)", "+ if v >= n:", "+ update(v, v - n)", "+ if v + n < n * n:", "+ update(v, v + n)" ]
false
0.117403
0.036093
3.252793
[ "s164448641", "s596652215" ]
u923668099
p02241
python
s166171600
s131406114
80
20
7,944
7,988
Accepted
Accepted
75
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): n = int(input()) a = [] for i in range(n): a.append([int(j) for j in input().split()]) checked = [False] * n tree = [0] checked[0] = True ans = 0 for i in range(n - 1): min_w = float('inf') for u in tree: for j in range(n): if a[u][j] != -1 and not checked[j]: if min_w > a[u][j]: min_w = a[u][j] min_n = j checked[min_n] = True tree.append(min_n) ans += min_w print(ans) if __name__ == '__main__': solve()
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): inf = float('inf') n = int(input()) a = [] for i in range(n): line = [int(i) for i in input().split()] line = [i if i != -1 else inf for i in line] a.append(line) checked = [False] * n d = [inf] * n checked[0] = True ans = 0 nxt = 0 for i in range(n - 1): for j in range(n): if a[nxt][j] < d[j]: d[j] = a[nxt][j] min_w = inf min_n = 0 for j in range(n): if not checked[j] and d[j] < min_w: min_n = j min_w = d[j] checked[min_n] = True nxt = min_n ans += min_w # debug(d, locals()) print(ans) if __name__ == '__main__': solve()
40
49
837
992
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def solve(): n = int(input()) a = [] for i in range(n): a.append([int(j) for j in input().split()]) checked = [False] * n tree = [0] checked[0] = True ans = 0 for i in range(n - 1): min_w = float("inf") for u in tree: for j in range(n): if a[u][j] != -1 and not checked[j]: if min_w > a[u][j]: min_w = a[u][j] min_n = j checked[min_n] = True tree.append(min_n) ans += min_w print(ans) if __name__ == "__main__": solve()
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def solve(): inf = float("inf") n = int(input()) a = [] for i in range(n): line = [int(i) for i in input().split()] line = [i if i != -1 else inf for i in line] a.append(line) checked = [False] * n d = [inf] * n checked[0] = True ans = 0 nxt = 0 for i in range(n - 1): for j in range(n): if a[nxt][j] < d[j]: d[j] = a[nxt][j] min_w = inf min_n = 0 for j in range(n): if not checked[j] and d[j] < min_w: min_n = j min_w = d[j] checked[min_n] = True nxt = min_n ans += min_w # debug(d, locals()) print(ans) if __name__ == "__main__": solve()
false
18.367347
[ "+ inf = float(\"inf\")", "- a.append([int(j) for j in input().split()])", "+ line = [int(i) for i in input().split()]", "+ line = [i if i != -1 else inf for i in line]", "+ a.append(line)", "- tree = [0]", "+ d = [inf] * n", "+ nxt = 0", "- min_w = float(\"inf\")", "- for u in tree:", "- for j in range(n):", "- if a[u][j] != -1 and not checked[j]:", "- if min_w > a[u][j]:", "- min_w = a[u][j]", "- min_n = j", "+ for j in range(n):", "+ if a[nxt][j] < d[j]:", "+ d[j] = a[nxt][j]", "+ min_w = inf", "+ min_n = 0", "+ for j in range(n):", "+ if not checked[j] and d[j] < min_w:", "+ min_n = j", "+ min_w = d[j]", "- tree.append(min_n)", "+ nxt = min_n", "+ # debug(d, locals())" ]
false
0.075779
0.15466
0.489971
[ "s166171600", "s131406114" ]
u190405389
p02920
python
s108257582
s838034999
1,969
438
113,608
120,768
Accepted
Accepted
77.76
import time start = time.time() n = int(eval(input())) s = list(map(int, input().split())) s.sort() s.reverse() flag = True for i in range(n): a = s[0:2 ** i] b = s[2 ** i:2 ** (i + 1)] for j in range(len(a)): if b[j] >= a[j]: flag = False break if flag: print('Yes') exit() s.reverse() a = [] a.append(s[-1]) s.pop(-1) for i in range(n): for j in range(len(a)): for k in range(len(s)): if a[j]>s[-1-k]: a.append(s[-1-k]) s.pop(-1-k) break if time.time() - start > 1.8: print('Yes') exit() if len(a)!=2**(i+1): print('No') exit() print('Yes')
n = int(eval(input())) s = list(map(int, input().split())) s.sort() a = [s[-1]] b = s[:-1] for i in range(n): a2 = [] b2 = [] for x in a: while b: y = b.pop() if x>y: a2.append(y) break else: b2.append(y) a = a + a2 b = b + b2 a.sort() a.reverse() b.sort() if len(a)!=2**(i+1): print('No') exit() print('Yes')
42
29
761
480
import time start = time.time() n = int(eval(input())) s = list(map(int, input().split())) s.sort() s.reverse() flag = True for i in range(n): a = s[0 : 2**i] b = s[2**i : 2 ** (i + 1)] for j in range(len(a)): if b[j] >= a[j]: flag = False break if flag: print("Yes") exit() s.reverse() a = [] a.append(s[-1]) s.pop(-1) for i in range(n): for j in range(len(a)): for k in range(len(s)): if a[j] > s[-1 - k]: a.append(s[-1 - k]) s.pop(-1 - k) break if time.time() - start > 1.8: print("Yes") exit() if len(a) != 2 ** (i + 1): print("No") exit() print("Yes")
n = int(eval(input())) s = list(map(int, input().split())) s.sort() a = [s[-1]] b = s[:-1] for i in range(n): a2 = [] b2 = [] for x in a: while b: y = b.pop() if x > y: a2.append(y) break else: b2.append(y) a = a + a2 b = b + b2 a.sort() a.reverse() b.sort() if len(a) != 2 ** (i + 1): print("No") exit() print("Yes")
false
30.952381
[ "-import time", "-", "-start = time.time()", "-s.reverse()", "-flag = True", "+a = [s[-1]]", "+b = s[:-1]", "- a = s[0 : 2**i]", "- b = s[2**i : 2 ** (i + 1)]", "- for j in range(len(a)):", "- if b[j] >= a[j]:", "- flag = False", "- break", "-if flag:", "- print(\"Yes\")", "- exit()", "-s.reverse()", "-a = []", "-a.append(s[-1])", "-s.pop(-1)", "-for i in range(n):", "- for j in range(len(a)):", "- for k in range(len(s)):", "- if a[j] > s[-1 - k]:", "- a.append(s[-1 - k])", "- s.pop(-1 - k)", "+ a2 = []", "+ b2 = []", "+ for x in a:", "+ while b:", "+ y = b.pop()", "+ if x > y:", "+ a2.append(y)", "- if time.time() - start > 1.8:", "- print(\"Yes\")", "- exit()", "+ else:", "+ b2.append(y)", "+ a = a + a2", "+ b = b + b2", "+ a.sort()", "+ a.reverse()", "+ b.sort()" ]
false
0.038265
0.03815
1.003009
[ "s108257582", "s838034999" ]
u391331433
p03806
python
s422222969
s577519975
1,807
747
13,348
4,592
Accepted
Accepted
58.66
import sys from collections import deque import copy def get_read_func(fileobject): if fileobject == None : return raw_input else: return fileobject.readline def bfs(X, Ma, Mb): #node_list = deque([0, 1]) drug_dict = {} drug_dict[(0, 0)] = 0 drug_dict[(X[0][0], X[0][1])] = X[0][2] ## drug_dict[0] = ((0, 0) ,0) ## drug_dict[1] = ((X[0][0], X[0][1]), X[0][2]) ## depth = 1 min_cost = sys.maxsize new_drug_dict = copy.deepcopy(drug_dict) for i in range(1, len(X)): for drug in drug_dict: cost = drug_dict[drug] new_drug = (drug[0] + X[i][0], drug[1] + X[i][1]) if new_drug not in drug_dict: new_drug_dict[new_drug] = cost + X[i][2] else: new_drug_dict[new_drug] = min(drug_dict[new_drug], cost + X[i][2]) if new_drug[1] * Ma == new_drug[0] * Mb: if new_drug_dict[new_drug] < min_cost: min_cost = new_drug_dict[new_drug] drug_dict = copy.deepcopy(new_drug_dict) return min_cost def main(): if len(sys.argv) > 1: f = open(sys.argv[1]) else: f = None read_func = get_read_func(f); input_raw = read_func().strip().split() [N, Ma, Mb] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X = [] for i in range(N): input_raw = read_func().strip().split() [a, b, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X.append((a, b, c)) cost = bfs(X, Ma, Mb) if cost < sys.maxsize: print(cost) else: print(-1) if __name__ == '__main__': main()
import sys from collections import deque import copy def get_read_func(fileobject): if fileobject == None : return raw_input else: return fileobject.readline def bfs(X, Ma, Mb): #node_list = deque([0, 1]) drug_dict = {} drug_dict[(0, 0)] = 0 drug_dict[(X[0][0], X[0][1])] = X[0][2] ## drug_dict[0] = ((0, 0) ,0) ## drug_dict[1] = ((X[0][0], X[0][1]), X[0][2]) ## depth = 1 min_cost = sys.maxsize new_drug_dict = copy.deepcopy(drug_dict) for i in range(1, len(X)): for drug in drug_dict: cost = drug_dict[drug] new_drug = (drug[0] + X[i][0], drug[1] + X[i][1]) if new_drug not in drug_dict: new_drug_dict[new_drug] = cost + X[i][2] else: new_drug_dict[new_drug] = min(drug_dict[new_drug], cost + X[i][2]) if new_drug[1] * Ma == new_drug[0] * Mb: if new_drug_dict[new_drug] < min_cost: min_cost = new_drug_dict[new_drug] drug_dict = copy.deepcopy(new_drug_dict) return min_cost def dp_search(X, Ma, Mb, AMax, BMax): dp = [[sys.maxsize for i in range(AMax + 1)] for j in range(BMax + 1)] dp[0][0] = 0 for i in range(len(X)): for a in range(AMax, -1, -1): for b in range(BMax, -1, -1): if dp[a][b] >= sys.maxsize: continue; if a + X[i][0] <= AMax and b + X[i][1] <= BMax: dp[a + X[i][0]][b + X[i][1]] = min(dp[a + X[i][0]][b + X[i][1]], dp[a][b] + X[i][2]) min_cost = sys.maxsize for a in range(0 , AMax): for b in range(0, BMax): if a * Mb == b * Ma and a != 0 and b != 0: if dp[a][b] < min_cost: min_cost = dp[a][b] return min_cost def main(): if len(sys.argv) > 1: f = open(sys.argv[1]) else: f = None read_func = get_read_func(f); input_raw = read_func().strip().split() [N, Ma, Mb] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X = [] for i in range(N): input_raw = read_func().strip().split() [a, b, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X.append((a, b, c)) #cost = bfs(X, Ma, Mb) cost = dp_search(X, Ma, Mb, N * 10, N * 10) if cost < sys.maxsize: print(cost) else: print(-1) if __name__ == '__main__': main()
59
79
1,722
2,516
import sys from collections import deque import copy def get_read_func(fileobject): if fileobject == None: return raw_input else: return fileobject.readline def bfs(X, Ma, Mb): # node_list = deque([0, 1]) drug_dict = {} drug_dict[(0, 0)] = 0 drug_dict[(X[0][0], X[0][1])] = X[0][2] ## drug_dict[0] = ((0, 0) ,0) ## drug_dict[1] = ((X[0][0], X[0][1]), X[0][2]) ## depth = 1 min_cost = sys.maxsize new_drug_dict = copy.deepcopy(drug_dict) for i in range(1, len(X)): for drug in drug_dict: cost = drug_dict[drug] new_drug = (drug[0] + X[i][0], drug[1] + X[i][1]) if new_drug not in drug_dict: new_drug_dict[new_drug] = cost + X[i][2] else: new_drug_dict[new_drug] = min(drug_dict[new_drug], cost + X[i][2]) if new_drug[1] * Ma == new_drug[0] * Mb: if new_drug_dict[new_drug] < min_cost: min_cost = new_drug_dict[new_drug] drug_dict = copy.deepcopy(new_drug_dict) return min_cost def main(): if len(sys.argv) > 1: f = open(sys.argv[1]) else: f = None read_func = get_read_func(f) input_raw = read_func().strip().split() [N, Ma, Mb] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X = [] for i in range(N): input_raw = read_func().strip().split() [a, b, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X.append((a, b, c)) cost = bfs(X, Ma, Mb) if cost < sys.maxsize: print(cost) else: print(-1) if __name__ == "__main__": main()
import sys from collections import deque import copy def get_read_func(fileobject): if fileobject == None: return raw_input else: return fileobject.readline def bfs(X, Ma, Mb): # node_list = deque([0, 1]) drug_dict = {} drug_dict[(0, 0)] = 0 drug_dict[(X[0][0], X[0][1])] = X[0][2] ## drug_dict[0] = ((0, 0) ,0) ## drug_dict[1] = ((X[0][0], X[0][1]), X[0][2]) ## depth = 1 min_cost = sys.maxsize new_drug_dict = copy.deepcopy(drug_dict) for i in range(1, len(X)): for drug in drug_dict: cost = drug_dict[drug] new_drug = (drug[0] + X[i][0], drug[1] + X[i][1]) if new_drug not in drug_dict: new_drug_dict[new_drug] = cost + X[i][2] else: new_drug_dict[new_drug] = min(drug_dict[new_drug], cost + X[i][2]) if new_drug[1] * Ma == new_drug[0] * Mb: if new_drug_dict[new_drug] < min_cost: min_cost = new_drug_dict[new_drug] drug_dict = copy.deepcopy(new_drug_dict) return min_cost def dp_search(X, Ma, Mb, AMax, BMax): dp = [[sys.maxsize for i in range(AMax + 1)] for j in range(BMax + 1)] dp[0][0] = 0 for i in range(len(X)): for a in range(AMax, -1, -1): for b in range(BMax, -1, -1): if dp[a][b] >= sys.maxsize: continue if a + X[i][0] <= AMax and b + X[i][1] <= BMax: dp[a + X[i][0]][b + X[i][1]] = min( dp[a + X[i][0]][b + X[i][1]], dp[a][b] + X[i][2] ) min_cost = sys.maxsize for a in range(0, AMax): for b in range(0, BMax): if a * Mb == b * Ma and a != 0 and b != 0: if dp[a][b] < min_cost: min_cost = dp[a][b] return min_cost def main(): if len(sys.argv) > 1: f = open(sys.argv[1]) else: f = None read_func = get_read_func(f) input_raw = read_func().strip().split() [N, Ma, Mb] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X = [] for i in range(N): input_raw = read_func().strip().split() [a, b, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])] X.append((a, b, c)) # cost = bfs(X, Ma, Mb) cost = dp_search(X, Ma, Mb, N * 10, N * 10) if cost < sys.maxsize: print(cost) else: print(-1) if __name__ == "__main__": main()
false
25.316456
[ "+def dp_search(X, Ma, Mb, AMax, BMax):", "+ dp = [[sys.maxsize for i in range(AMax + 1)] for j in range(BMax + 1)]", "+ dp[0][0] = 0", "+ for i in range(len(X)):", "+ for a in range(AMax, -1, -1):", "+ for b in range(BMax, -1, -1):", "+ if dp[a][b] >= sys.maxsize:", "+ continue", "+ if a + X[i][0] <= AMax and b + X[i][1] <= BMax:", "+ dp[a + X[i][0]][b + X[i][1]] = min(", "+ dp[a + X[i][0]][b + X[i][1]], dp[a][b] + X[i][2]", "+ )", "+ min_cost = sys.maxsize", "+ for a in range(0, AMax):", "+ for b in range(0, BMax):", "+ if a * Mb == b * Ma and a != 0 and b != 0:", "+ if dp[a][b] < min_cost:", "+ min_cost = dp[a][b]", "+ return min_cost", "+", "+", "- cost = bfs(X, Ma, Mb)", "+ # cost = bfs(X, Ma, Mb)", "+ cost = dp_search(X, Ma, Mb, N * 10, N * 10)" ]
false
0.044005
0.044287
0.993638
[ "s422222969", "s577519975" ]
u391731808
p03911
python
s060786164
s910624714
589
510
57,968
48,692
Accepted
Accepted
13.41
N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N ] E = [[[] for _ in [0]*N] , [[] for _ in [0]*M]] for i,kl in enumerate(KL): for l in kl[1:]: E[0][i].append(l-1) E[1][l-1].append(i) Check = [[False]*N,[False]*M] Check[0][0] = True q = [[0,0]] while q: cl,i = q.pop() for j in E[cl][i]: if Check[1-cl][j]:continue q.append([1-cl,j]) Check[1-cl][j] = True if sum(Check[0]) == N: print("YES") else: print("NO")
#二部グラフで連結判定 N,M = list(map(int,input().split())) KL = [list(map(int,input().split())) for _ in [0]*N] c = [False]*(N+M) #d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語 E = [[] for _ in [0]*(N+M)] for i,kl in enumerate(KL): for l in kl[1:]: E[i].append(N+l-1) E[N+l-1].append(i) start = 0 q = [start] c[start] = True while q: i = q.pop() for j in E[i]: if c[j]:continue c[j] = True q.append(j) ans = True for b in c[:N]: ans = ans and b print(("YES" if ans else "NO"))
23
25
527
531
N, M = list(map(int, input().split())) KL = [list(map(int, input().split())) for _ in [0] * N] E = [[[] for _ in [0] * N], [[] for _ in [0] * M]] for i, kl in enumerate(KL): for l in kl[1:]: E[0][i].append(l - 1) E[1][l - 1].append(i) Check = [[False] * N, [False] * M] Check[0][0] = True q = [[0, 0]] while q: cl, i = q.pop() for j in E[cl][i]: if Check[1 - cl][j]: continue q.append([1 - cl, j]) Check[1 - cl][j] = True if sum(Check[0]) == N: print("YES") else: print("NO")
# 二部グラフで連結判定 N, M = list(map(int, input().split())) KL = [list(map(int, input().split())) for _ in [0] * N] c = [False] * (N + M) # d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語 E = [[] for _ in [0] * (N + M)] for i, kl in enumerate(KL): for l in kl[1:]: E[i].append(N + l - 1) E[N + l - 1].append(i) start = 0 q = [start] c[start] = True while q: i = q.pop() for j in E[i]: if c[j]: continue c[j] = True q.append(j) ans = True for b in c[:N]: ans = ans and b print(("YES" if ans else "NO"))
false
8
[ "+# 二部グラフで連結判定", "-E = [[[] for _ in [0] * N], [[] for _ in [0] * M]]", "+c = [False] * (N + M) # d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語", "+E = [[] for _ in [0] * (N + M)]", "- E[0][i].append(l - 1)", "- E[1][l - 1].append(i)", "-Check = [[False] * N, [False] * M]", "-Check[0][0] = True", "-q = [[0, 0]]", "+ E[i].append(N + l - 1)", "+ E[N + l - 1].append(i)", "+start = 0", "+q = [start]", "+c[start] = True", "- cl, i = q.pop()", "- for j in E[cl][i]:", "- if Check[1 - cl][j]:", "+ i = q.pop()", "+ for j in E[i]:", "+ if c[j]:", "- q.append([1 - cl, j])", "- Check[1 - cl][j] = True", "-if sum(Check[0]) == N:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+ c[j] = True", "+ q.append(j)", "+ans = True", "+for b in c[:N]:", "+ ans = ans and b", "+print((\"YES\" if ans else \"NO\"))" ]
false
0.050325
0.049855
1.009437
[ "s060786164", "s910624714" ]
u620238824
p02695
python
s078629948
s304405815
1,973
1,793
86,784
73,924
Accepted
Accepted
9.12
N, M, Q = list(map(int, input().split())) #数字 Q = [list(map(int, input().split())) for i in range(Q)] #数字複数列、複数行 A = [] for i in range(1,M+1): A.append(i) B = [] import itertools for i in itertools.combinations_with_replacement(A,N): B.append(i) C = [] for i in range(len(B)): score = 0 for j in range(len(Q)): if B[i][Q[j][1]-1] - B[i][Q[j][0]-1] == Q[j][2]: score += Q[j][3] C.append(score) print((max(C)))
N, M, Q = list(map(int, input().split())) #数字 Q = [list(map(int, input().split())) for i in range(Q)] #数字複数列、複数行 import itertools A = [] for i in itertools.combinations_with_replacement(list(range(M)),N): score = 0 for j in range(len(Q)): if i[Q[j][1]-1] - i[Q[j][0]-1] == Q[j][2]: score += Q[j][3] A.append(score) print((max(A)))
21
13
470
368
N, M, Q = list(map(int, input().split())) # 数字 Q = [list(map(int, input().split())) for i in range(Q)] # 数字複数列、複数行 A = [] for i in range(1, M + 1): A.append(i) B = [] import itertools for i in itertools.combinations_with_replacement(A, N): B.append(i) C = [] for i in range(len(B)): score = 0 for j in range(len(Q)): if B[i][Q[j][1] - 1] - B[i][Q[j][0] - 1] == Q[j][2]: score += Q[j][3] C.append(score) print((max(C)))
N, M, Q = list(map(int, input().split())) # 数字 Q = [list(map(int, input().split())) for i in range(Q)] # 数字複数列、複数行 import itertools A = [] for i in itertools.combinations_with_replacement(list(range(M)), N): score = 0 for j in range(len(Q)): if i[Q[j][1] - 1] - i[Q[j][0] - 1] == Q[j][2]: score += Q[j][3] A.append(score) print((max(A)))
false
38.095238
[ "-A = []", "-for i in range(1, M + 1):", "- A.append(i)", "-B = []", "-for i in itertools.combinations_with_replacement(A, N):", "- B.append(i)", "-C = []", "-for i in range(len(B)):", "+A = []", "+for i in itertools.combinations_with_replacement(list(range(M)), N):", "- if B[i][Q[j][1] - 1] - B[i][Q[j][0] - 1] == Q[j][2]:", "+ if i[Q[j][1] - 1] - i[Q[j][0] - 1] == Q[j][2]:", "- C.append(score)", "-print((max(C)))", "+ A.append(score)", "+print((max(A)))" ]
false
0.126297
0.075073
1.682338
[ "s078629948", "s304405815" ]
u882370611
p02982
python
s615373486
s222009398
150
17
12,472
3,060
Accepted
Accepted
88.67
import numpy as np n,d=list(map(int,input().split())) v=[] for i in range(n): v.append(np.array(list(map(int,input().split())))) ans=0 for i in range(n-1): for j in range(i+1,n): dist=np.linalg.norm(v[i]-v[j], ord = 2) if int(dist) == dist: ans += 1 print(ans)
n, d = list(map(int, input().split())) v = [list(map(int, input().split())) for i in range(n)] ans = 0 for i in range(n): for j in range(i+1, n): dist = 0 for k in range(d): dist += (v[i][k]-v[j][k])**2 dist = dist**(1/2) if dist.is_integer(): ans += 1 print(ans)
14
12
289
305
import numpy as np n, d = list(map(int, input().split())) v = [] for i in range(n): v.append(np.array(list(map(int, input().split())))) ans = 0 for i in range(n - 1): for j in range(i + 1, n): dist = np.linalg.norm(v[i] - v[j], ord=2) if int(dist) == dist: ans += 1 print(ans)
n, d = list(map(int, input().split())) v = [list(map(int, input().split())) for i in range(n)] ans = 0 for i in range(n): for j in range(i + 1, n): dist = 0 for k in range(d): dist += (v[i][k] - v[j][k]) ** 2 dist = dist ** (1 / 2) if dist.is_integer(): ans += 1 print(ans)
false
14.285714
[ "-import numpy as np", "-", "-v = []", "+v = [list(map(int, input().split())) for i in range(n)]", "+ans = 0", "- v.append(np.array(list(map(int, input().split()))))", "-ans = 0", "-for i in range(n - 1):", "- dist = np.linalg.norm(v[i] - v[j], ord=2)", "- if int(dist) == dist:", "+ dist = 0", "+ for k in range(d):", "+ dist += (v[i][k] - v[j][k]) ** 2", "+ dist = dist ** (1 / 2)", "+ if dist.is_integer():" ]
false
0.252699
0.036315
6.958579
[ "s615373486", "s222009398" ]
u133936772
p03013
python
s649185802
s826282558
208
87
11,884
11,884
Accepted
Accepted
58.17
n,m=list(map(int,input().split())) l=set(int(eval(input()))-1 for _ in range(m)) s,t=0,1 for i in range(n): s,t=t,(s+t)%(10**9+7)*(1-(i in l)) print(t)
import sys f=sys.stdin.readline n,m=list(map(int,f().split())) l=set(int(f())-1 for _ in range(m)) s,t=0,1 for i in range(n): s,t=t,(s+t)%(10**9+7)*(1-(i in l)) print(t)
5
7
143
169
n, m = list(map(int, input().split())) l = set(int(eval(input())) - 1 for _ in range(m)) s, t = 0, 1 for i in range(n): s, t = t, (s + t) % (10**9 + 7) * (1 - (i in l)) print(t)
import sys f = sys.stdin.readline n, m = list(map(int, f().split())) l = set(int(f()) - 1 for _ in range(m)) s, t = 0, 1 for i in range(n): s, t = t, (s + t) % (10**9 + 7) * (1 - (i in l)) print(t)
false
28.571429
[ "-n, m = list(map(int, input().split()))", "-l = set(int(eval(input())) - 1 for _ in range(m))", "+import sys", "+", "+f = sys.stdin.readline", "+n, m = list(map(int, f().split()))", "+l = set(int(f()) - 1 for _ in range(m))" ]
false
0.040864
0.041697
0.98003
[ "s649185802", "s826282558" ]
u571281863
p02678
python
s289420932
s033146832
1,387
639
36,752
95,064
Accepted
Accepted
53.93
from collections import deque N,M=list(map(int,input().split())) to=[[] for _ in range(N)] for _ in range(M): a,b=list(map(int,input().split())) to[a-1].append(b-1) to[b-1].append(a-1) q=deque([0]) r=deque([None]*N) r[0]=0 while q: x=q.popleft() for i in to[x]: if r[i] is None: q.append(i) r[i]=x+1 print('Yes') r.popleft() for i in range(N-1): print((r.popleft()))
from collections import deque N,M=list(map(int,input().split())) to=[[] for _ in range(N)] for _ in range(M): a,b=list(map(int,input().split())) to[a-1].append(b-1) to[b-1].append(a-1) q=deque([0]) r=[None]*N r[0]=0 while q: x=q.popleft() for i in to[x]: if r[i] is None: q.append(i) r[i]=x+1 print('Yes') for i in range(N): if r[i]!=0: print((r[i]))
22
22
409
397
from collections import deque N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) to[a - 1].append(b - 1) to[b - 1].append(a - 1) q = deque([0]) r = deque([None] * N) r[0] = 0 while q: x = q.popleft() for i in to[x]: if r[i] is None: q.append(i) r[i] = x + 1 print("Yes") r.popleft() for i in range(N - 1): print((r.popleft()))
from collections import deque N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) to[a - 1].append(b - 1) to[b - 1].append(a - 1) q = deque([0]) r = [None] * N r[0] = 0 while q: x = q.popleft() for i in to[x]: if r[i] is None: q.append(i) r[i] = x + 1 print("Yes") for i in range(N): if r[i] != 0: print((r[i]))
false
0
[ "-r = deque([None] * N)", "+r = [None] * N", "-r.popleft()", "-for i in range(N - 1):", "- print((r.popleft()))", "+for i in range(N):", "+ if r[i] != 0:", "+ print((r[i]))" ]
false
0.054411
0.053579
1.015531
[ "s289420932", "s033146832" ]
u983918956
p03035
python
s396158548
s923210444
22
17
3,064
2,940
Accepted
Accepted
22.73
A,B = list(map(int,input().split())) if A <= 5: print((0)) elif 6 <= A <= 12: print((B//2)) else: print(B)
A,B = list(map(int,input().split())) if A >= 13: print(B) elif A >= 6: print((B//2)) else: print((0))
7
8
114
111
A, B = list(map(int, input().split())) if A <= 5: print((0)) elif 6 <= A <= 12: print((B // 2)) else: print(B)
A, B = list(map(int, input().split())) if A >= 13: print(B) elif A >= 6: print((B // 2)) else: print((0))
false
12.5
[ "-if A <= 5:", "- print((0))", "-elif 6 <= A <= 12:", "+if A >= 13:", "+ print(B)", "+elif A >= 6:", "- print(B)", "+ print((0))" ]
false
0.041281
0.04407
0.936719
[ "s396158548", "s923210444" ]
u815659544
p03208
python
s863947125
s698905720
854
245
8,212
7,384
Accepted
Accepted
71.31
import heapq import queue N, K = list(map(int, input().split())) trees = [] heapq.heapify(trees) for _ in range(N): heapq.heappush(trees, int(eval(input()))) ans = 1 + 10**9 q = queue.Queue(maxsize=K-1) for _ in range(K-1): q.put(heapq.heappop(trees)) for _ in range(N-K+1): curmin = q.get() nextmin = heapq.heappop(trees) ans = min(ans, nextmin-curmin) q.put(nextmin) print(ans)
import sys INPUT = sys.stdin.readline def SINGLE_INT(): return int(INPUT()) def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split())) def MULTIPLE_INT_MAP(): return list(map(int, INPUT().split())) def SINGLE_STRING(): return INPUT() def MULTIPLE_STRING(): return INPUT().split() N, K = MULTIPLE_INT_MAP() trees = [int(eval(input())) for _ in range(N)] trees.sort() ans = float('inf') for i in range(0, N-K+1): ans = min(ans, trees[i+K-1] - trees[i]) if ans == 0: break print(ans)
27
21
428
514
import heapq import queue N, K = list(map(int, input().split())) trees = [] heapq.heapify(trees) for _ in range(N): heapq.heappush(trees, int(eval(input()))) ans = 1 + 10**9 q = queue.Queue(maxsize=K - 1) for _ in range(K - 1): q.put(heapq.heappop(trees)) for _ in range(N - K + 1): curmin = q.get() nextmin = heapq.heappop(trees) ans = min(ans, nextmin - curmin) q.put(nextmin) print(ans)
import sys INPUT = sys.stdin.readline def SINGLE_INT(): return int(INPUT()) def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split())) def MULTIPLE_INT_MAP(): return list(map(int, INPUT().split())) def SINGLE_STRING(): return INPUT() def MULTIPLE_STRING(): return INPUT().split() N, K = MULTIPLE_INT_MAP() trees = [int(eval(input())) for _ in range(N)] trees.sort() ans = float("inf") for i in range(0, N - K + 1): ans = min(ans, trees[i + K - 1] - trees[i]) if ans == 0: break print(ans)
false
22.222222
[ "-import heapq", "-import queue", "+import sys", "-N, K = list(map(int, input().split()))", "-trees = []", "-heapq.heapify(trees)", "-for _ in range(N):", "- heapq.heappush(trees, int(eval(input())))", "-ans = 1 + 10**9", "-q = queue.Queue(maxsize=K - 1)", "-for _ in range(K - 1):", "- q.put(heapq.heappop(trees))", "-for _ in range(N - K + 1):", "- curmin = q.get()", "- nextmin = heapq.heappop(trees)", "- ans = min(ans, nextmin - curmin)", "- q.put(nextmin)", "+INPUT = sys.stdin.readline", "+", "+", "+def SINGLE_INT():", "+ return int(INPUT())", "+", "+", "+def MULTIPLE_INT_LIST():", "+ return list(map(int, INPUT().split()))", "+", "+", "+def MULTIPLE_INT_MAP():", "+ return list(map(int, INPUT().split()))", "+", "+", "+def SINGLE_STRING():", "+ return INPUT()", "+", "+", "+def MULTIPLE_STRING():", "+ return INPUT().split()", "+", "+", "+N, K = MULTIPLE_INT_MAP()", "+trees = [int(eval(input())) for _ in range(N)]", "+trees.sort()", "+ans = float(\"inf\")", "+for i in range(0, N - K + 1):", "+ ans = min(ans, trees[i + K - 1] - trees[i])", "+ if ans == 0:", "+ break" ]
false
0.041919
0.040755
1.028558
[ "s863947125", "s698905720" ]
u028973125
p02572
python
s637307842
s742275960
188
146
31,468
31,464
Accepted
Accepted
22.34
import sys N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) # N -> 1の累積和 acum = [0 for _ in range(N+1)] acum[0] = sum(A) for i in range(N): acum[i+1] = acum[i] - A[i] mod = 10**9 + 7 ans = 0 for i in range(N): ans += acum[i+1] * A[i] ans %= mod print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 ans = 0 sum_a = sum(A) for i in range(N): sum_a -= A[i] ans += A[i] * sum_a ans %= mod print(ans)
18
15
318
233
import sys N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) # N -> 1の累積和 acum = [0 for _ in range(N + 1)] acum[0] = sum(A) for i in range(N): acum[i + 1] = acum[i] - A[i] mod = 10**9 + 7 ans = 0 for i in range(N): ans += acum[i + 1] * A[i] ans %= mod print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 ans = 0 sum_a = sum(A) for i in range(N): sum_a -= A[i] ans += A[i] * sum_a ans %= mod print(ans)
false
16.666667
[ "-N = int(sys.stdin.readline())", "-A = list(map(int, sys.stdin.readline().split()))", "-# N -> 1の累積和", "-acum = [0 for _ in range(N + 1)]", "-acum[0] = sum(A)", "-for i in range(N):", "- acum[i + 1] = acum[i] - A[i]", "+input = sys.stdin.readline", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+sum_a = sum(A)", "- ans += acum[i + 1] * A[i]", "+ sum_a -= A[i]", "+ ans += A[i] * sum_a" ]
false
0.037558
0.041678
0.901155
[ "s637307842", "s742275960" ]
u150984829
p00489
python
s530607785
s180429324
50
40
5,664
5,664
Accepted
Accepted
20
N=int(input()) s=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) s[a-1]+=3*(c>d)+(c==d) s[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N): b[s[i]]+=[i] r=1 for x in b[::-1]: for y in x: s[y]=r if x:r+=len(x) print(*s,sep='\n')
def f(): N=int(input()) s=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) s[a-1]+=3*(c>d)+(c==d) s[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N):b[s[i]]+=[i] r=1 for x in b[::-1]: for y in x:s[y]=r if x:r+=len(x) print(*s,sep='\n') f()
15
15
277
298
N = int(input()) s = [0] * N for _ in [0] * (N * ~-N // 2): a, b, c, d = map(int, input().split()) s[a - 1] += 3 * (c > d) + (c == d) s[b - 1] += 3 * (d > c) + (d == c) b = [[] for _ in [0] * N * 3] for i in range(N): b[s[i]] += [i] r = 1 for x in b[::-1]: for y in x: s[y] = r if x: r += len(x) print(*s, sep="\n")
def f(): N = int(input()) s = [0] * N for _ in [0] * (N * ~-N // 2): a, b, c, d = map(int, input().split()) s[a - 1] += 3 * (c > d) + (c == d) s[b - 1] += 3 * (d > c) + (d == c) b = [[] for _ in [0] * N * 3] for i in range(N): b[s[i]] += [i] r = 1 for x in b[::-1]: for y in x: s[y] = r if x: r += len(x) print(*s, sep="\n") f()
false
0
[ "-N = int(input())", "-s = [0] * N", "-for _ in [0] * (N * ~-N // 2):", "- a, b, c, d = map(int, input().split())", "- s[a - 1] += 3 * (c > d) + (c == d)", "- s[b - 1] += 3 * (d > c) + (d == c)", "-b = [[] for _ in [0] * N * 3]", "-for i in range(N):", "- b[s[i]] += [i]", "-r = 1", "-for x in b[::-1]:", "- for y in x:", "- s[y] = r", "- if x:", "- r += len(x)", "-print(*s, sep=\"\\n\")", "+def f():", "+ N = int(input())", "+ s = [0] * N", "+ for _ in [0] * (N * ~-N // 2):", "+ a, b, c, d = map(int, input().split())", "+ s[a - 1] += 3 * (c > d) + (c == d)", "+ s[b - 1] += 3 * (d > c) + (d == c)", "+ b = [[] for _ in [0] * N * 3]", "+ for i in range(N):", "+ b[s[i]] += [i]", "+ r = 1", "+ for x in b[::-1]:", "+ for y in x:", "+ s[y] = r", "+ if x:", "+ r += len(x)", "+ print(*s, sep=\"\\n\")", "+", "+", "+f()" ]
false
0.091718
0.041431
2.213745
[ "s530607785", "s180429324" ]
u076917070
p02837
python
s423161264
s095519540
350
247
3,064
3,188
Accepted
Accepted
29.43
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [[set(), set()] for _ in range(N)] for i in range(N): m = int(eval(input())) for j in range(m): x, y = list(map(int, input().split())) A[i][y].add(x) ans = 0 for i in range(1 << N): h = set() u = set() for j in range(N): if (i >> j) & 1: h.add(j+1) else: u.add(j+1) b = True for k in list(h): k -= 1 h |= A[k][1] u |= A[k][0] if h & u: b = False if b: ans = max(ans, bin(i).count("1")) print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [[set(), set()] for _ in range(N)] for i in range(N): m = int(eval(input())) for j in range(m): x, y = list(map(int, input().split())) A[i][y].add(x) ans = 0 for i in range(1 << N): h = set() u = set() for j in range(N): if (i >> j) & 1: h.add(j+1) else: u.add(j+1) b = True for k in list(h): k -= 1 h |= A[k][1] u |= A[k][0] if h & u: b = False break if b: ans = max(ans, bin(i).count("1")) print(ans) if __name__ == '__main__': main()
36
37
778
801
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [[set(), set()] for _ in range(N)] for i in range(N): m = int(eval(input())) for j in range(m): x, y = list(map(int, input().split())) A[i][y].add(x) ans = 0 for i in range(1 << N): h = set() u = set() for j in range(N): if (i >> j) & 1: h.add(j + 1) else: u.add(j + 1) b = True for k in list(h): k -= 1 h |= A[k][1] u |= A[k][0] if h & u: b = False if b: ans = max(ans, bin(i).count("1")) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [[set(), set()] for _ in range(N)] for i in range(N): m = int(eval(input())) for j in range(m): x, y = list(map(int, input().split())) A[i][y].add(x) ans = 0 for i in range(1 << N): h = set() u = set() for j in range(N): if (i >> j) & 1: h.add(j + 1) else: u.add(j + 1) b = True for k in list(h): k -= 1 h |= A[k][1] u |= A[k][0] if h & u: b = False break if b: ans = max(ans, bin(i).count("1")) print(ans) if __name__ == "__main__": main()
false
2.702703
[ "+ break" ]
false
0.043097
0.044566
0.967042
[ "s423161264", "s095519540" ]
u489959379
p03911
python
s649907090
s173709216
718
194
65,624
39,624
Accepted
Accepted
72.98
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) uf = UnionFind(n + m) for i in range(n): k, *L = list(map(int, input().split())) for l in L: uf.union(l - 1, m + i) for i in range(n - 1): if not uf.same(m + i, m + i + 1): print("NO") break else: print("YES")
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): def dfs(v): for u in edge[v]: if visited[u]: continue else: visited[u] = True dfs(u) n, m = list(map(int, input().split())) edge = [[] for _ in range(n + m)] for i in range(n): _, *L = list(map(int, input().split())) for l in L: edge[i].append(n + l - 1) edge[n + l - 1].append(i) visited = [False] * (n + m) dfs(0) for i in range(n): if not visited[i]: print("NO") break else: print("YES") if __name__ == '__main__': resolve()
43
37
934
778
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) uf = UnionFind(n + m) for i in range(n): k, *L = list(map(int, input().split())) for l in L: uf.union(l - 1, m + i) for i in range(n - 1): if not uf.same(m + i, m + i + 1): print("NO") break else: print("YES")
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): def dfs(v): for u in edge[v]: if visited[u]: continue else: visited[u] = True dfs(u) n, m = list(map(int, input().split())) edge = [[] for _ in range(n + m)] for i in range(n): _, *L = list(map(int, input().split())) for l in L: edge[i].append(n + l - 1) edge[n + l - 1].append(i) visited = [False] * (n + m) dfs(0) for i in range(n): if not visited[i]: print("NO") break else: print("YES") if __name__ == "__main__": resolve()
false
13.953488
[ "-class UnionFind:", "- def __init__(self, n):", "- self.n = n", "- self.parents = [-1] * n", "+import sys", "- def find(self, x):", "- if self.parents[x] < 0:", "- return x", "- else:", "- self.parents[x] = self.find(self.parents[x])", "- return self.parents[x]", "-", "- def union(self, x, y):", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- if self.parents[x] > self.parents[y]:", "- x, y = y, x", "- self.parents[x] += self.parents[y]", "- self.parents[y] = x", "-", "- def same(self, x, y):", "- return self.find(x) == self.find(y)", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "-n, m = list(map(int, input().split()))", "-uf = UnionFind(n + m)", "-for i in range(n):", "- k, *L = list(map(int, input().split()))", "- for l in L:", "- uf.union(l - 1, m + i)", "-for i in range(n - 1):", "- if not uf.same(m + i, m + i + 1):", "- print(\"NO\")", "- break", "-else:", "- print(\"YES\")", "+def resolve():", "+ def dfs(v):", "+ for u in edge[v]:", "+ if visited[u]:", "+ continue", "+ else:", "+ visited[u] = True", "+ dfs(u)", "+", "+ n, m = list(map(int, input().split()))", "+ edge = [[] for _ in range(n + m)]", "+ for i in range(n):", "+ _, *L = list(map(int, input().split()))", "+ for l in L:", "+ edge[i].append(n + l - 1)", "+ edge[n + l - 1].append(i)", "+ visited = [False] * (n + m)", "+ dfs(0)", "+ for i in range(n):", "+ if not visited[i]:", "+ print(\"NO\")", "+ break", "+ else:", "+ print(\"YES\")", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.043523
0.040158
1.083782
[ "s649907090", "s173709216" ]
u600402037
p03494
python
s420041647
s310412946
20
18
3,060
3,060
Accepted
Accepted
10
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 while True: for i in range(N): if A[i] / 2 ** count % 2 !=0: break else: count += 1 continue break print(count)
n = int(eval(input())) a_list = list(map(int, input().split())) min_a = min(a_list) count = 0 while min_a % 2 == 0: min_a /= 2 count += 1 for a in a_list: if a % 2 ** count != 0: a_count = 0 while a % 2 == 0: a /= 2 a_count += 1 count = a_count print(count)
14
17
243
330
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 while True: for i in range(N): if A[i] / 2**count % 2 != 0: break else: count += 1 continue break print(count)
n = int(eval(input())) a_list = list(map(int, input().split())) min_a = min(a_list) count = 0 while min_a % 2 == 0: min_a /= 2 count += 1 for a in a_list: if a % 2**count != 0: a_count = 0 while a % 2 == 0: a /= 2 a_count += 1 count = a_count print(count)
false
17.647059
[ "-N = int(eval(input()))", "-A = [int(l) for l in input().split()]", "+n = int(eval(input()))", "+a_list = list(map(int, input().split()))", "+min_a = min(a_list)", "-while True:", "- for i in range(N):", "- if A[i] / 2**count % 2 != 0:", "- break", "- else:", "- count += 1", "- continue", "- break", "+while min_a % 2 == 0:", "+ min_a /= 2", "+ count += 1", "+for a in a_list:", "+ if a % 2**count != 0:", "+ a_count = 0", "+ while a % 2 == 0:", "+ a /= 2", "+ a_count += 1", "+ count = a_count" ]
false
0.038182
0.140722
0.271328
[ "s420041647", "s310412946" ]
u072053884
p02324
python
s497450967
s801889060
690
430
8,012
7,984
Accepted
Accepted
37.68
import sys f_i = sys.stdin V, E = list(map(int, f_i.readline().split())) # adjacency matrix no_edge = 14001 adj = [[no_edge] * V for i in range(V)] for i in range(V): adj[i][i] = 0 odd_b = 0 # bit DP to record odd vertex ans = 0 # acceptance of input for l_i in f_i: s, t, d = list(map(int, l_i.split())) t_d = min(d, adj[s][t]) adj[s][t] = t_d adj[t][s] = t_d odd_b ^= 1 << s odd_b ^= 1 << t ans += d import math if odd_b: # Warshall???Floyd Algorithm for k in range(V): for i in range(V): for j in range(V): adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]) # Minimum weighted matching mw = [no_edge] * (odd_b + 1) mw[0] = 0 digits = int(math.log2(odd_b)) + 1 for b in range(odd_b): for i in range(0, digits): if not (b & (1 << i)): for j in range(i + 1, digits): if not (b & (1 << j)): t_b = b + (1 << i) + (1 << j) if t_b == t_b & odd_b: t_w = mw[t_b] mw[t_b] = min(t_w, mw[b] + adj[i][j]) # Output ans += mw[odd_b] print(ans) else: print(ans)
#! /usr/bin/python # -*- coding: utf-8 -*- """Chinese Postman Problem.""" import sys f_i = sys.stdin V, E = list(map(int, f_i.readline().split())) # adjacency matrix no_edge = 14001 adj = [[no_edge] * V for i in range(V)] for i in range(V): adj[i][i] = 0 odd_b = 0 # bit DP to record odd vertex ans = 0 # acceptance of input for l_i in f_i: s, t, d = list(map(int, l_i.split())) t_d = min(d, adj[s][t]) adj[s][t] = t_d adj[t][s] = t_d odd_b ^= 1 << s odd_b ^= 1 << t ans += d # A function to check if the number of 1 is odd in binary notation def odd_one(n): ans = 0 while n: ans ^= (n & 1) n >>= 1 return ans import math if odd_b: # Warshall???Floyd Algorithm for k in range(V): for i in range(V): for j in range(V): adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]) # Minimum weighted matching mw = [no_edge] * (odd_b + 1) mw[0] = 0 digits = int(math.log2(odd_b)) + 1 for b in range(odd_b): if odd_one(b): continue for i in range(0, digits): if not (b & (1 << i)): for j in range(i + 1, digits): if not (b & (1 << j)): t_b = b + (1 << i) + (1 << j) if t_b == t_b & odd_b: t_w = mw[t_b] mw[t_b] = min(t_w, mw[b] + adj[i][j]) # Output ans += mw[odd_b] print(ans) else: print(ans)
57
72
1,292
1,590
import sys f_i = sys.stdin V, E = list(map(int, f_i.readline().split())) # adjacency matrix no_edge = 14001 adj = [[no_edge] * V for i in range(V)] for i in range(V): adj[i][i] = 0 odd_b = 0 # bit DP to record odd vertex ans = 0 # acceptance of input for l_i in f_i: s, t, d = list(map(int, l_i.split())) t_d = min(d, adj[s][t]) adj[s][t] = t_d adj[t][s] = t_d odd_b ^= 1 << s odd_b ^= 1 << t ans += d import math if odd_b: # Warshall???Floyd Algorithm for k in range(V): for i in range(V): for j in range(V): adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]) # Minimum weighted matching mw = [no_edge] * (odd_b + 1) mw[0] = 0 digits = int(math.log2(odd_b)) + 1 for b in range(odd_b): for i in range(0, digits): if not (b & (1 << i)): for j in range(i + 1, digits): if not (b & (1 << j)): t_b = b + (1 << i) + (1 << j) if t_b == t_b & odd_b: t_w = mw[t_b] mw[t_b] = min(t_w, mw[b] + adj[i][j]) # Output ans += mw[odd_b] print(ans) else: print(ans)
#! /usr/bin/python # -*- coding: utf-8 -*- """Chinese Postman Problem.""" import sys f_i = sys.stdin V, E = list(map(int, f_i.readline().split())) # adjacency matrix no_edge = 14001 adj = [[no_edge] * V for i in range(V)] for i in range(V): adj[i][i] = 0 odd_b = 0 # bit DP to record odd vertex ans = 0 # acceptance of input for l_i in f_i: s, t, d = list(map(int, l_i.split())) t_d = min(d, adj[s][t]) adj[s][t] = t_d adj[t][s] = t_d odd_b ^= 1 << s odd_b ^= 1 << t ans += d # A function to check if the number of 1 is odd in binary notation def odd_one(n): ans = 0 while n: ans ^= n & 1 n >>= 1 return ans import math if odd_b: # Warshall???Floyd Algorithm for k in range(V): for i in range(V): for j in range(V): adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]) # Minimum weighted matching mw = [no_edge] * (odd_b + 1) mw[0] = 0 digits = int(math.log2(odd_b)) + 1 for b in range(odd_b): if odd_one(b): continue for i in range(0, digits): if not (b & (1 << i)): for j in range(i + 1, digits): if not (b & (1 << j)): t_b = b + (1 << i) + (1 << j) if t_b == t_b & odd_b: t_w = mw[t_b] mw[t_b] = min(t_w, mw[b] + adj[i][j]) # Output ans += mw[odd_b] print(ans) else: print(ans)
false
20.833333
[ "+#! /usr/bin/python", "+# -*- coding: utf-8 -*-", "+\"\"\"Chinese Postman Problem.\"\"\"", "+# A function to check if the number of 1 is odd in binary notation", "+def odd_one(n):", "+ ans = 0", "+ while n:", "+ ans ^= n & 1", "+ n >>= 1", "+ return ans", "+", "+", "+ if odd_one(b):", "+ continue" ]
false
0.044944
0.139535
0.322099
[ "s497450967", "s801889060" ]
u014333473
p04012
python
s934877618
s425086677
31
28
9,100
9,100
Accepted
Accepted
9.68
s=[*eval(input())];print(('NYoe s'[all([1 if s.count(i)%2==0 else 0 for i in set(s)])::2]))
s=[*eval(input())];print(('NYoe s'[all([s.count(i)%2==0 for i in set(s)])::2]))
1
1
83
71
s = [*eval(input())] print(("NYoe s"[all([1 if s.count(i) % 2 == 0 else 0 for i in set(s)]) :: 2]))
s = [*eval(input())] print(("NYoe s"[all([s.count(i) % 2 == 0 for i in set(s)]) :: 2]))
false
0
[ "-print((\"NYoe s\"[all([1 if s.count(i) % 2 == 0 else 0 for i in set(s)]) :: 2]))", "+print((\"NYoe s\"[all([s.count(i) % 2 == 0 for i in set(s)]) :: 2]))" ]
false
0.045214
0.04697
0.962618
[ "s934877618", "s425086677" ]
u724687935
p03031
python
s401668135
s161272219
42
35
3,188
3,064
Accepted
Accepted
16.67
N, M = list(map(int, input().split())) switch = [list(map(int, input().split())) for _ in range(M)] B = [] for K, *S in switch: b = 0 for k in range(K): b += (1 << (S[k] - 1)) B.append(b) P = list(map(int, input().split())) ans = 0 for i in range(2 ** N): on = True for j, b in enumerate(B): cnt = 0 state = b & i while state > 0: cnt += state & 1 state >>= 1 on &= (cnt % 2 == P[j]) ans += on print(ans)
def cntBit(n): cnt = 0 while n > 0: cnt += (n & 1) n >>= 1 return cnt N, M = list(map(int, input().split())) switch = [list(map(int, input().split())) for _ in range(M)] B = [] for K, *S in switch: b = 0 for k in range(K): b += (1 << (S[k] - 1)) B.append(b) P = list(map(int, input().split())) ans = 0 for i in range(2 ** N): on = True B1 = list([x & i for x in B]) B2 = list(map(cntBit, B1)) B3 = list([x % 2 for x in B2]) if B3 == P: ans += 1 print(ans)
25
30
515
571
N, M = list(map(int, input().split())) switch = [list(map(int, input().split())) for _ in range(M)] B = [] for K, *S in switch: b = 0 for k in range(K): b += 1 << (S[k] - 1) B.append(b) P = list(map(int, input().split())) ans = 0 for i in range(2**N): on = True for j, b in enumerate(B): cnt = 0 state = b & i while state > 0: cnt += state & 1 state >>= 1 on &= cnt % 2 == P[j] ans += on print(ans)
def cntBit(n): cnt = 0 while n > 0: cnt += n & 1 n >>= 1 return cnt N, M = list(map(int, input().split())) switch = [list(map(int, input().split())) for _ in range(M)] B = [] for K, *S in switch: b = 0 for k in range(K): b += 1 << (S[k] - 1) B.append(b) P = list(map(int, input().split())) ans = 0 for i in range(2**N): on = True B1 = list([x & i for x in B]) B2 = list(map(cntBit, B1)) B3 = list([x % 2 for x in B2]) if B3 == P: ans += 1 print(ans)
false
16.666667
[ "+def cntBit(n):", "+ cnt = 0", "+ while n > 0:", "+ cnt += n & 1", "+ n >>= 1", "+ return cnt", "+", "+", "- for j, b in enumerate(B):", "- cnt = 0", "- state = b & i", "- while state > 0:", "- cnt += state & 1", "- state >>= 1", "- on &= cnt % 2 == P[j]", "- ans += on", "+ B1 = list([x & i for x in B])", "+ B2 = list(map(cntBit, B1))", "+ B3 = list([x % 2 for x in B2])", "+ if B3 == P:", "+ ans += 1" ]
false
0.035506
0.03681
0.964583
[ "s401668135", "s161272219" ]
u636683284
p03038
python
s197630912
s234372578
602
390
115,432
97,264
Accepted
Accepted
35.22
from collections import Counter import heapq n,m = list(map(int,input().split())) l = list(map(int,input().split())) hq = sorted(tuple(Counter(l).items()), key=lambda x:x[0]) heapq.heapify(hq) # print(hq) BC = [list(map(int, input().split())) for i in range(m)] BC = sorted(BC,key = lambda x:-x[1]) for b,c in BC: while b > 0: x,y = heapq.heappop(hq) if x < c: if b < y: heapq.heappush(hq,(c,b)) heapq.heappush(hq,(x,y-b)) b = 0 else: heapq.heappush(hq,(c,y)) b -= y else: heapq.heappush(hq,(x,y)) break # print(hq) ans = 0 for i in range(len(hq)): ans += hq[i][0]*hq[i][1] print(ans)
import sys import heapq input = sys.stdin.readline n,m = list(map(int,input().split())) A = list(map(int,input().split())) heapq.heapify(A) BC = [list(map(int, input().split())) for i in range(m)] BC = sorted(BC,key = lambda x:-x[1]) for b,c in BC: for i in range(b): a = heapq.heappop(A) if a < c: heapq.heappush(A,c) else: heapq.heappush(A,a) break print((sum(A)))
33
20
780
444
from collections import Counter import heapq n, m = list(map(int, input().split())) l = list(map(int, input().split())) hq = sorted(tuple(Counter(l).items()), key=lambda x: x[0]) heapq.heapify(hq) # print(hq) BC = [list(map(int, input().split())) for i in range(m)] BC = sorted(BC, key=lambda x: -x[1]) for b, c in BC: while b > 0: x, y = heapq.heappop(hq) if x < c: if b < y: heapq.heappush(hq, (c, b)) heapq.heappush(hq, (x, y - b)) b = 0 else: heapq.heappush(hq, (c, y)) b -= y else: heapq.heappush(hq, (x, y)) break # print(hq) ans = 0 for i in range(len(hq)): ans += hq[i][0] * hq[i][1] print(ans)
import sys import heapq input = sys.stdin.readline n, m = list(map(int, input().split())) A = list(map(int, input().split())) heapq.heapify(A) BC = [list(map(int, input().split())) for i in range(m)] BC = sorted(BC, key=lambda x: -x[1]) for b, c in BC: for i in range(b): a = heapq.heappop(A) if a < c: heapq.heappush(A, c) else: heapq.heappush(A, a) break print((sum(A)))
false
39.393939
[ "-from collections import Counter", "+import sys", "+input = sys.stdin.readline", "-l = list(map(int, input().split()))", "-hq = sorted(tuple(Counter(l).items()), key=lambda x: x[0])", "-heapq.heapify(hq)", "-# print(hq)", "+A = list(map(int, input().split()))", "+heapq.heapify(A)", "- while b > 0:", "- x, y = heapq.heappop(hq)", "- if x < c:", "- if b < y:", "- heapq.heappush(hq, (c, b))", "- heapq.heappush(hq, (x, y - b))", "- b = 0", "- else:", "- heapq.heappush(hq, (c, y))", "- b -= y", "+ for i in range(b):", "+ a = heapq.heappop(A)", "+ if a < c:", "+ heapq.heappush(A, c)", "- heapq.heappush(hq, (x, y))", "+ heapq.heappush(A, a)", "- # print(hq)", "-ans = 0", "-for i in range(len(hq)):", "- ans += hq[i][0] * hq[i][1]", "-print(ans)", "+print((sum(A)))" ]
false
0.036754
0.035333
1.040234
[ "s197630912", "s234372578" ]
u667135132
p02936
python
s635787690
s951508305
1,891
828
121,236
120,084
Accepted
Accepted
56.21
N,Q = list(map(int,input().split())) G=[] for i in range(N): G.append([]) for i in range(N-1): a,b = list(map(int,input().split())) a-=1 b-=1 G[a].append(b) G[b].append(a) p=[0]*Q x=[0]*Q c=[0]*N for i in range(Q): p,x = list(map(int,input().split())) p-=1 c[p] += x stack=[0] parent = [-1]*N while(stack): v = stack.pop() for u in G[v]: if u!=parent[v]: c[u]+=c[v] parent[u]=v stack.append(u) ans = ' '.join([str(x) for x in c]) print(ans)
import sys from collections import deque #N,Q = list(map(int,input().split())) N,Q = [int(i) for i in sys.stdin.readline().split()] G=[] for i in range(N): G.append([]) for i in range(N-1): #a,b = list(map(int,input().split())) a,b = [int(j) for j in sys.stdin.readline().split()] a-=1 b-=1 G[a].append(b) G[b].append(a) p=[0]*Q x=[0]*Q c=[0]*N for i in range(Q): #p,x = list(map(int,input().split())) p,x = [int(j) for j in sys.stdin.readline().split()] p-=1 c[p] += x stack=deque([0]) parent = [-1]*N while(stack): v = stack.pop() for u in G[v]: if u!=parent[v]: c[u]+=c[v] parent[u]=v stack.append(u) ans = ' '.join([str(x) for x in c]) print(ans)
35
41
569
794
N, Q = list(map(int, input().split())) G = [] for i in range(N): G.append([]) for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) p = [0] * Q x = [0] * Q c = [0] * N for i in range(Q): p, x = list(map(int, input().split())) p -= 1 c[p] += x stack = [0] parent = [-1] * N while stack: v = stack.pop() for u in G[v]: if u != parent[v]: c[u] += c[v] parent[u] = v stack.append(u) ans = " ".join([str(x) for x in c]) print(ans)
import sys from collections import deque # N,Q = list(map(int,input().split())) N, Q = [int(i) for i in sys.stdin.readline().split()] G = [] for i in range(N): G.append([]) for i in range(N - 1): # a,b = list(map(int,input().split())) a, b = [int(j) for j in sys.stdin.readline().split()] a -= 1 b -= 1 G[a].append(b) G[b].append(a) p = [0] * Q x = [0] * Q c = [0] * N for i in range(Q): # p,x = list(map(int,input().split())) p, x = [int(j) for j in sys.stdin.readline().split()] p -= 1 c[p] += x stack = deque([0]) parent = [-1] * N while stack: v = stack.pop() for u in G[v]: if u != parent[v]: c[u] += c[v] parent[u] = v stack.append(u) ans = " ".join([str(x) for x in c]) print(ans)
false
14.634146
[ "-N, Q = list(map(int, input().split()))", "+import sys", "+from collections import deque", "+", "+# N,Q = list(map(int,input().split()))", "+N, Q = [int(i) for i in sys.stdin.readline().split()]", "- a, b = list(map(int, input().split()))", "+ # a,b = list(map(int,input().split()))", "+ a, b = [int(j) for j in sys.stdin.readline().split()]", "- p, x = list(map(int, input().split()))", "+ # p,x = list(map(int,input().split()))", "+ p, x = [int(j) for j in sys.stdin.readline().split()]", "-stack = [0]", "+stack = deque([0])" ]
false
0.046187
0.097987
0.47136
[ "s635787690", "s951508305" ]
u135346354
p02802
python
s733799530
s138607987
382
311
3,828
4,596
Accepted
Accepted
18.59
N,M = [int(item) for item in input().split(" ")] result = [0]*N wa = 0 ac = 0 for i in range(M): p,s = [i for i in input().split(" ")] if result[int(p)-1] != -1: if s == 'AC': wa += result[int(p)-1] result[int(p)-1] = -1 ac += 1 else: result[int(p)-1] += 1 print(ac,wa,sep=' ')
N, M = list(map(int, input().split())) ans = 0 pen = 0 w = [0]*(N+1) ac = [False]*(N+1) for _ in range(M): p, s = input().split() if s == "AC" and not ac[int(p)]: pen += w[int(p)] ac[int(p)] = True ans += 1 elif s == "WA": w[int(p)] += 1 print((ans, pen))
19
14
392
304
N, M = [int(item) for item in input().split(" ")] result = [0] * N wa = 0 ac = 0 for i in range(M): p, s = [i for i in input().split(" ")] if result[int(p) - 1] != -1: if s == "AC": wa += result[int(p) - 1] result[int(p) - 1] = -1 ac += 1 else: result[int(p) - 1] += 1 print(ac, wa, sep=" ")
N, M = list(map(int, input().split())) ans = 0 pen = 0 w = [0] * (N + 1) ac = [False] * (N + 1) for _ in range(M): p, s = input().split() if s == "AC" and not ac[int(p)]: pen += w[int(p)] ac[int(p)] = True ans += 1 elif s == "WA": w[int(p)] += 1 print((ans, pen))
false
26.315789
[ "-N, M = [int(item) for item in input().split(\" \")]", "-result = [0] * N", "-wa = 0", "-ac = 0", "-for i in range(M):", "- p, s = [i for i in input().split(\" \")]", "- if result[int(p) - 1] != -1:", "- if s == \"AC\":", "- wa += result[int(p) - 1]", "- result[int(p) - 1] = -1", "- ac += 1", "- else:", "- result[int(p) - 1] += 1", "-print(ac, wa, sep=\" \")", "+N, M = list(map(int, input().split()))", "+ans = 0", "+pen = 0", "+w = [0] * (N + 1)", "+ac = [False] * (N + 1)", "+for _ in range(M):", "+ p, s = input().split()", "+ if s == \"AC\" and not ac[int(p)]:", "+ pen += w[int(p)]", "+ ac[int(p)] = True", "+ ans += 1", "+ elif s == \"WA\":", "+ w[int(p)] += 1", "+print((ans, pen))" ]
false
0.036567
0.040567
0.901399
[ "s733799530", "s138607987" ]
u596276291
p03804
python
s464688949
s465227811
720
98
3,316
3,316
Accepted
Accepted
86.39
from collections import defaultdict def main(): N, M = list(map(int, input().split())) A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for sy in range(N): for sx in range(N): ok = True for y in range(M): for x in range(M): if sy + y < N and sx + x < N: ok &= A[sy + y][sx + x] == B[y][x] else: ok = False if ok: print("Yes") return print("No") if __name__ == '__main__': main()
from collections import defaultdict def main(): N, M = list(map(int, input().split())) A, B = [], [] for _ in range(N): A.append(eval(input())) for _ in range(M): B.append(eval(input())) for y in range(N - M + 1): for x in range(N - M + 1): ok = True for by in range(M): for bx in range(M): if A[y + by][x + bx] != B[by][bx]: ok = False if ok: print("Yes") return print("No") if __name__ == '__main__': main()
27
25
625
600
from collections import defaultdict def main(): N, M = list(map(int, input().split())) A = [eval(input()) for _ in range(N)] B = [eval(input()) for _ in range(M)] for sy in range(N): for sx in range(N): ok = True for y in range(M): for x in range(M): if sy + y < N and sx + x < N: ok &= A[sy + y][sx + x] == B[y][x] else: ok = False if ok: print("Yes") return print("No") if __name__ == "__main__": main()
from collections import defaultdict def main(): N, M = list(map(int, input().split())) A, B = [], [] for _ in range(N): A.append(eval(input())) for _ in range(M): B.append(eval(input())) for y in range(N - M + 1): for x in range(N - M + 1): ok = True for by in range(M): for bx in range(M): if A[y + by][x + bx] != B[by][bx]: ok = False if ok: print("Yes") return print("No") if __name__ == "__main__": main()
false
7.407407
[ "- A = [eval(input()) for _ in range(N)]", "- B = [eval(input()) for _ in range(M)]", "- for sy in range(N):", "- for sx in range(N):", "+ A, B = [], []", "+ for _ in range(N):", "+ A.append(eval(input()))", "+ for _ in range(M):", "+ B.append(eval(input()))", "+ for y in range(N - M + 1):", "+ for x in range(N - M + 1):", "- for y in range(M):", "- for x in range(M):", "- if sy + y < N and sx + x < N:", "- ok &= A[sy + y][sx + x] == B[y][x]", "- else:", "+ for by in range(M):", "+ for bx in range(M):", "+ if A[y + by][x + bx] != B[by][bx]:" ]
false
0.041474
0.03487
1.189377
[ "s464688949", "s465227811" ]
u396181190
p03228
python
s394290101
s690876509
147
17
12,496
3,064
Accepted
Accepted
88.44
import numpy as np def process(src, dst): # 偶数:何もしない # 奇数:1枚ならべる(1枚減る) if src % 2 == 0: pass else: src -= 1 # 半分を相手に渡す # 自分:半分減 # 相手:半分の値増 src = src / 2 dst += src return src, dst # 入力 indata = input().split() A = int(indata[0]) B = int(indata[1]) K = int(indata[2]) # 初期所持枚数 takahashi = A aoki = B # 操作をK回繰り返す for i in range(K): if i % 2 == 0: # 高橋君のターン takahashi, aoki = process(takahashi, aoki) else: # 青木君のターン aoki, takahashi = process(aoki, takahashi) # 結果 print((int(takahashi), int(aoki)))
# coding: utf-8 def process(src, dst): # 偶数:何もしない # 奇数:1枚ならべる(1枚減る) if src % 2 == 0: pass else: src -= 1 # 半分を相手に渡す # 自分:半分減 # 相手:半分の値増 src = src / 2 dst += src return src, dst # 入力 indata = input().split() A = int(indata[0]) B = int(indata[1]) K = int(indata[2]) # 初期所持枚数 takahashi = A aoki = B # 操作をK回繰り返す for i in range(K): if i % 2 == 0: # 高橋君のターン takahashi, aoki = process(takahashi, aoki) else: # 青木君のターン aoki, takahashi = process(aoki, takahashi) # 結果 print((int(takahashi), int(aoki)))
40
39
637
632
import numpy as np def process(src, dst): # 偶数:何もしない # 奇数:1枚ならべる(1枚減る) if src % 2 == 0: pass else: src -= 1 # 半分を相手に渡す # 自分:半分減 # 相手:半分の値増 src = src / 2 dst += src return src, dst # 入力 indata = input().split() A = int(indata[0]) B = int(indata[1]) K = int(indata[2]) # 初期所持枚数 takahashi = A aoki = B # 操作をK回繰り返す for i in range(K): if i % 2 == 0: # 高橋君のターン takahashi, aoki = process(takahashi, aoki) else: # 青木君のターン aoki, takahashi = process(aoki, takahashi) # 結果 print((int(takahashi), int(aoki)))
# coding: utf-8 def process(src, dst): # 偶数:何もしない # 奇数:1枚ならべる(1枚減る) if src % 2 == 0: pass else: src -= 1 # 半分を相手に渡す # 自分:半分減 # 相手:半分の値増 src = src / 2 dst += src return src, dst # 入力 indata = input().split() A = int(indata[0]) B = int(indata[1]) K = int(indata[2]) # 初期所持枚数 takahashi = A aoki = B # 操作をK回繰り返す for i in range(K): if i % 2 == 0: # 高橋君のターン takahashi, aoki = process(takahashi, aoki) else: # 青木君のターン aoki, takahashi = process(aoki, takahashi) # 結果 print((int(takahashi), int(aoki)))
false
2.5
[ "-import numpy as np", "-", "-", "+# coding: utf-8" ]
false
0.038122
0.039546
0.963992
[ "s394290101", "s690876509" ]
u678167152
p03473
python
s227841949
s517534197
172
66
38,384
61,668
Accepted
Accepted
61.63
M = int(eval(input())) ans = 48-M print(ans)
def solve(): M = int(eval(input())) ans = 48-M return ans print((solve()))
4
5
42
82
M = int(eval(input())) ans = 48 - M print(ans)
def solve(): M = int(eval(input())) ans = 48 - M return ans print((solve()))
false
20
[ "-M = int(eval(input()))", "-ans = 48 - M", "-print(ans)", "+def solve():", "+ M = int(eval(input()))", "+ ans = 48 - M", "+ return ans", "+", "+", "+print((solve()))" ]
false
0.041328
0.076728
0.538625
[ "s227841949", "s517534197" ]
u352394527
p00465
python
s942916288
s340761941
2,270
1,940
58,420
61,844
Accepted
Accepted
14.54
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)] used1 = [[False] * w1 for _ in range(h1)] w2, h2, x2, y2 = list(map(int, input().split())) x2 -= 1 y2 -= 1 lst2 = [list(map(int, input().split())) for _ in range(h2)] used2 = [[False] * w2 for _ in range(h2)] def bfs(lst, used, que, w, h): v, y, x = pop(que) if y > 0 and not used[y - 1][x]: push(que, (lst[y - 1][x], y - 1, x)) used[y - 1][x] = True if h > y + 1 and not used[y + 1][x]: push(que, (lst[y + 1][x], y + 1, x)) used[y + 1][x] = True if x > 0 and not used[y][x - 1]: push(que, (lst[y][x - 1], y, x - 1)) used[y][x - 1] = True if w > x + 1 and not used[y][x + 1]: push(que, (lst[y][x + 1], y, x + 1)) used[y][x + 1] = True return v que = [(1, y1, x1)] used1[y1][x1] = True rec1 = [[0, 0]] Max = 0 acc = 0 while que: v = bfs(lst1, used1, que, w1, h1) acc += 1 if v > Max: rec1.append([v, acc]) Max = v else: rec1[-1][1] += 1 que = [(1, y2, x2)] used2[y2][x2] = True rec2 = [[0, 0]] Max = 0 acc = 0 while que: v = bfs(lst2, used2, que, w2, h2) acc += 1 if v > Max: rec2.append([v, acc]) Max = v else: rec2[-1][1] += 1 end1 = len(rec1) end2 = len(rec2) ind1 = 0 ind2 = end2 - 1 ans = INF # print(rec1) # print(rec2) while ind1 < end1 and ind2 > 0: r1, sum1 = rec1[ind1] r2, sum2 = rec2[ind2] if sum1 + sum2 < R: ind1 += 1 continue while ind2 > 0 and sum1 + sum2 >= R: ind2 -= 1 r2, sum2 = rec2[ind2] if ind2 == 0 and sum1 + sum2 >= R: ans = min(ans, r1 + r2) break else: if ind2 < end2 - 1: ind2 += 1 r2, sum2 = rec2[ind2] ans = min(ans, r1 + r2) ind1 += 1 print(ans)
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 def solve(): while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)] used1 = [[False] * w1 for _ in range(h1)] w2, h2, x2, y2 = list(map(int, input().split())) x2 -= 1 y2 -= 1 lst2 = [list(map(int, input().split())) for _ in range(h2)] used2 = [[False] * w2 for _ in range(h2)] def bfs(lst, used, que, w, h): v, y, x = pop(que) if y > 0 and not used[y - 1][x]: push(que, (lst[y - 1][x], y - 1, x)) used[y - 1][x] = True if h > y + 1 and not used[y + 1][x]: push(que, (lst[y + 1][x], y + 1, x)) used[y + 1][x] = True if x > 0 and not used[y][x - 1]: push(que, (lst[y][x - 1], y, x - 1)) used[y][x - 1] = True if w > x + 1 and not used[y][x + 1]: push(que, (lst[y][x + 1], y, x + 1)) used[y][x + 1] = True return v def make_dic(lst, w, h, x, y): que = [(1, y, x)] used = [[False] * w for _ in range(h)] used[y][x] = True dic = [[0, 0]] app = dic.append Max = 0 acc = 0 while que: v = bfs(lst, used, que, w, h) acc += 1 if v > Max: app([v, acc]) Max = v else: dic[-1][1] += 1 return dic dic1 = make_dic(lst1, w1, h1, x1, y1) dic2 = make_dic(lst2, w2, h2, x2, y2) end1 = len(dic1) end2 = len(dic2) ind1 = 0 ind2 = end2 - 1 ans = INF while ind1 < end1 and ind2 > 0: r1, sum1 = dic1[ind1] r2, sum2 = dic2[ind2] if sum1 + sum2 < R: ind1 += 1 continue while ind2 > 0 and sum1 + sum2 >= R: ind2 -= 1 r2, sum2 = dic2[ind2] if ind2 == 0 and sum1 + sum2 >= R: rs = r1 + r2 if rs < ans: ans = rs break else: if ind2 < end2 - 1: ind2 += 1 r2 = dic2[ind2][0] rs = r1 + r2 if rs < ans: ans = rs ind1 += 1 print(ans) solve()
91
95
2,123
2,308
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)] used1 = [[False] * w1 for _ in range(h1)] w2, h2, x2, y2 = list(map(int, input().split())) x2 -= 1 y2 -= 1 lst2 = [list(map(int, input().split())) for _ in range(h2)] used2 = [[False] * w2 for _ in range(h2)] def bfs(lst, used, que, w, h): v, y, x = pop(que) if y > 0 and not used[y - 1][x]: push(que, (lst[y - 1][x], y - 1, x)) used[y - 1][x] = True if h > y + 1 and not used[y + 1][x]: push(que, (lst[y + 1][x], y + 1, x)) used[y + 1][x] = True if x > 0 and not used[y][x - 1]: push(que, (lst[y][x - 1], y, x - 1)) used[y][x - 1] = True if w > x + 1 and not used[y][x + 1]: push(que, (lst[y][x + 1], y, x + 1)) used[y][x + 1] = True return v que = [(1, y1, x1)] used1[y1][x1] = True rec1 = [[0, 0]] Max = 0 acc = 0 while que: v = bfs(lst1, used1, que, w1, h1) acc += 1 if v > Max: rec1.append([v, acc]) Max = v else: rec1[-1][1] += 1 que = [(1, y2, x2)] used2[y2][x2] = True rec2 = [[0, 0]] Max = 0 acc = 0 while que: v = bfs(lst2, used2, que, w2, h2) acc += 1 if v > Max: rec2.append([v, acc]) Max = v else: rec2[-1][1] += 1 end1 = len(rec1) end2 = len(rec2) ind1 = 0 ind2 = end2 - 1 ans = INF # print(rec1) # print(rec2) while ind1 < end1 and ind2 > 0: r1, sum1 = rec1[ind1] r2, sum2 = rec2[ind2] if sum1 + sum2 < R: ind1 += 1 continue while ind2 > 0 and sum1 + sum2 >= R: ind2 -= 1 r2, sum2 = rec2[ind2] if ind2 == 0 and sum1 + sum2 >= R: ans = min(ans, r1 + r2) break else: if ind2 < end2 - 1: ind2 += 1 r2, sum2 = rec2[ind2] ans = min(ans, r1 + r2) ind1 += 1 print(ans)
from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 def solve(): while True: R = int(eval(input())) if not R: break w1, h1, x1, y1 = list(map(int, input().split())) x1 -= 1 y1 -= 1 lst1 = [list(map(int, input().split())) for _ in range(h1)] used1 = [[False] * w1 for _ in range(h1)] w2, h2, x2, y2 = list(map(int, input().split())) x2 -= 1 y2 -= 1 lst2 = [list(map(int, input().split())) for _ in range(h2)] used2 = [[False] * w2 for _ in range(h2)] def bfs(lst, used, que, w, h): v, y, x = pop(que) if y > 0 and not used[y - 1][x]: push(que, (lst[y - 1][x], y - 1, x)) used[y - 1][x] = True if h > y + 1 and not used[y + 1][x]: push(que, (lst[y + 1][x], y + 1, x)) used[y + 1][x] = True if x > 0 and not used[y][x - 1]: push(que, (lst[y][x - 1], y, x - 1)) used[y][x - 1] = True if w > x + 1 and not used[y][x + 1]: push(que, (lst[y][x + 1], y, x + 1)) used[y][x + 1] = True return v def make_dic(lst, w, h, x, y): que = [(1, y, x)] used = [[False] * w for _ in range(h)] used[y][x] = True dic = [[0, 0]] app = dic.append Max = 0 acc = 0 while que: v = bfs(lst, used, que, w, h) acc += 1 if v > Max: app([v, acc]) Max = v else: dic[-1][1] += 1 return dic dic1 = make_dic(lst1, w1, h1, x1, y1) dic2 = make_dic(lst2, w2, h2, x2, y2) end1 = len(dic1) end2 = len(dic2) ind1 = 0 ind2 = end2 - 1 ans = INF while ind1 < end1 and ind2 > 0: r1, sum1 = dic1[ind1] r2, sum2 = dic2[ind2] if sum1 + sum2 < R: ind1 += 1 continue while ind2 > 0 and sum1 + sum2 >= R: ind2 -= 1 r2, sum2 = dic2[ind2] if ind2 == 0 and sum1 + sum2 >= R: rs = r1 + r2 if rs < ans: ans = rs break else: if ind2 < end2 - 1: ind2 += 1 r2 = dic2[ind2][0] rs = r1 + r2 if rs < ans: ans = rs ind1 += 1 print(ans) solve()
false
4.210526
[ "-while True:", "- R = int(eval(input()))", "- if not R:", "- break", "- w1, h1, x1, y1 = list(map(int, input().split()))", "- x1 -= 1", "- y1 -= 1", "- lst1 = [list(map(int, input().split())) for _ in range(h1)]", "- used1 = [[False] * w1 for _ in range(h1)]", "- w2, h2, x2, y2 = list(map(int, input().split()))", "- x2 -= 1", "- y2 -= 1", "- lst2 = [list(map(int, input().split())) for _ in range(h2)]", "- used2 = [[False] * w2 for _ in range(h2)]", "- def bfs(lst, used, que, w, h):", "- v, y, x = pop(que)", "- if y > 0 and not used[y - 1][x]:", "- push(que, (lst[y - 1][x], y - 1, x))", "- used[y - 1][x] = True", "- if h > y + 1 and not used[y + 1][x]:", "- push(que, (lst[y + 1][x], y + 1, x))", "- used[y + 1][x] = True", "- if x > 0 and not used[y][x - 1]:", "- push(que, (lst[y][x - 1], y, x - 1))", "- used[y][x - 1] = True", "- if w > x + 1 and not used[y][x + 1]:", "- push(que, (lst[y][x + 1], y, x + 1))", "- used[y][x + 1] = True", "- return v", "- que = [(1, y1, x1)]", "- used1[y1][x1] = True", "- rec1 = [[0, 0]]", "- Max = 0", "- acc = 0", "- while que:", "- v = bfs(lst1, used1, que, w1, h1)", "- acc += 1", "- if v > Max:", "- rec1.append([v, acc])", "- Max = v", "- else:", "- rec1[-1][1] += 1", "- que = [(1, y2, x2)]", "- used2[y2][x2] = True", "- rec2 = [[0, 0]]", "- Max = 0", "- acc = 0", "- while que:", "- v = bfs(lst2, used2, que, w2, h2)", "- acc += 1", "- if v > Max:", "- rec2.append([v, acc])", "- Max = v", "- else:", "- rec2[-1][1] += 1", "- end1 = len(rec1)", "- end2 = len(rec2)", "- ind1 = 0", "- ind2 = end2 - 1", "- ans = INF", "- # print(rec1)", "- # print(rec2)", "- while ind1 < end1 and ind2 > 0:", "- r1, sum1 = rec1[ind1]", "- r2, sum2 = rec2[ind2]", "- if sum1 + sum2 < R:", "+def solve():", "+ while True:", "+ R = int(eval(input()))", "+ if not R:", "+ break", "+ w1, h1, x1, y1 = list(map(int, input().split()))", "+ x1 -= 1", "+ y1 -= 1", "+ lst1 = [list(map(int, input().split())) for _ in range(h1)]", "+ used1 = [[False] * w1 for _ in range(h1)]", "+ w2, h2, x2, y2 = list(map(int, input().split()))", "+ x2 -= 1", "+ y2 -= 1", "+ lst2 = [list(map(int, input().split())) for _ in range(h2)]", "+ used2 = [[False] * w2 for _ in range(h2)]", "+", "+ def bfs(lst, used, que, w, h):", "+ v, y, x = pop(que)", "+ if y > 0 and not used[y - 1][x]:", "+ push(que, (lst[y - 1][x], y - 1, x))", "+ used[y - 1][x] = True", "+ if h > y + 1 and not used[y + 1][x]:", "+ push(que, (lst[y + 1][x], y + 1, x))", "+ used[y + 1][x] = True", "+ if x > 0 and not used[y][x - 1]:", "+ push(que, (lst[y][x - 1], y, x - 1))", "+ used[y][x - 1] = True", "+ if w > x + 1 and not used[y][x + 1]:", "+ push(que, (lst[y][x + 1], y, x + 1))", "+ used[y][x + 1] = True", "+ return v", "+", "+ def make_dic(lst, w, h, x, y):", "+ que = [(1, y, x)]", "+ used = [[False] * w for _ in range(h)]", "+ used[y][x] = True", "+ dic = [[0, 0]]", "+ app = dic.append", "+ Max = 0", "+ acc = 0", "+ while que:", "+ v = bfs(lst, used, que, w, h)", "+ acc += 1", "+ if v > Max:", "+ app([v, acc])", "+ Max = v", "+ else:", "+ dic[-1][1] += 1", "+ return dic", "+", "+ dic1 = make_dic(lst1, w1, h1, x1, y1)", "+ dic2 = make_dic(lst2, w2, h2, x2, y2)", "+ end1 = len(dic1)", "+ end2 = len(dic2)", "+ ind1 = 0", "+ ind2 = end2 - 1", "+ ans = INF", "+ while ind1 < end1 and ind2 > 0:", "+ r1, sum1 = dic1[ind1]", "+ r2, sum2 = dic2[ind2]", "+ if sum1 + sum2 < R:", "+ ind1 += 1", "+ continue", "+ while ind2 > 0 and sum1 + sum2 >= R:", "+ ind2 -= 1", "+ r2, sum2 = dic2[ind2]", "+ if ind2 == 0 and sum1 + sum2 >= R:", "+ rs = r1 + r2", "+ if rs < ans:", "+ ans = rs", "+ break", "+ else:", "+ if ind2 < end2 - 1:", "+ ind2 += 1", "+ r2 = dic2[ind2][0]", "+ rs = r1 + r2", "+ if rs < ans:", "+ ans = rs", "- continue", "- while ind2 > 0 and sum1 + sum2 >= R:", "- ind2 -= 1", "- r2, sum2 = rec2[ind2]", "- if ind2 == 0 and sum1 + sum2 >= R:", "- ans = min(ans, r1 + r2)", "- break", "- else:", "- if ind2 < end2 - 1:", "- ind2 += 1", "- r2, sum2 = rec2[ind2]", "- ans = min(ans, r1 + r2)", "- ind1 += 1", "- print(ans)", "+ print(ans)", "+", "+", "+solve()" ]
false
0.051501
0.047821
1.076947
[ "s942916288", "s340761941" ]
u760831084
p03556
python
s122080464
s904048563
37
17
2,940
2,940
Accepted
Accepted
54.05
import math N = int(eval(input())) for i in reversed(list(range(N))): n = math.sqrt(N) if n.is_integer(): print((int(n ** 2))) exit() N -= 1
import math N = int(eval(input())) n = int(math.sqrt(N)) print((n ** 2))
9
5
163
69
import math N = int(eval(input())) for i in reversed(list(range(N))): n = math.sqrt(N) if n.is_integer(): print((int(n**2))) exit() N -= 1
import math N = int(eval(input())) n = int(math.sqrt(N)) print((n**2))
false
44.444444
[ "-for i in reversed(list(range(N))):", "- n = math.sqrt(N)", "- if n.is_integer():", "- print((int(n**2)))", "- exit()", "- N -= 1", "+n = int(math.sqrt(N))", "+print((n**2))" ]
false
0.091338
0.05986
1.52586
[ "s122080464", "s904048563" ]
u863370423
p02987
python
s559603973
s467128526
162
17
38,256
2,940
Accepted
Accepted
89.51
a = list(eval(input())) s= set(a) l = list(s) if len(a) == 4 and len(s) == 2 and a.count(l[0]) ==2 and a.count(l[1]) ==2: print('Yes') else: print('No')
let = set(eval(input())) print(({True: 'Yes', False: 'No'}[len(let) == 2]))
7
2
167
69
a = list(eval(input())) s = set(a) l = list(s) if len(a) == 4 and len(s) == 2 and a.count(l[0]) == 2 and a.count(l[1]) == 2: print("Yes") else: print("No")
let = set(eval(input())) print(({True: "Yes", False: "No"}[len(let) == 2]))
false
71.428571
[ "-a = list(eval(input()))", "-s = set(a)", "-l = list(s)", "-if len(a) == 4 and len(s) == 2 and a.count(l[0]) == 2 and a.count(l[1]) == 2:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+let = set(eval(input()))", "+print(({True: \"Yes\", False: \"No\"}[len(let) == 2]))" ]
false
0.082844
0.035698
2.320676
[ "s559603973", "s467128526" ]
u013629972
p03089
python
s594009969
s565547400
315
291
66,924
65,388
Accepted
Accepted
7.62
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b)+1): # print(i) if b[-i] == len(b)-i+1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b)+1): # print(i) if b[-i] == len(b)-i+1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
37
38
1,080
1,069
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b) + 1): # print(i) if b[-i] == len(b) - i + 1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b) + 1): # print(i) if b[-i] == len(b) - i + 1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
false
2.631579
[ "- return [int(x) for x in sys.stdin.readline().split()]", "+ return [int(x) for x in input().split()]" ]
false
0.042315
0.115274
0.367082
[ "s594009969", "s565547400" ]
u411203878
p03089
python
s315735426
s741459952
177
67
40,428
64,376
Accepted
Accepted
62.15
n=int(eval(input())) ball = list(map(int,input().split())) ans = [] count = 0 while len(ball)>0: count += 1 for i in range(len(ball)-1,-1,-1): #print(ball,i) if i+1 ==ball[i]: move = ball.pop(i) ans.insert(0,move) break if count ==100000: break if len(ans) == n: for i in ans: print(i) else: print((-1))
n = int(eval(input())) b = list(map(int,input().split())) Flag = True memo = [] while Flag: Flag = False index = -1 for i, v in enumerate(b): if i == v-1: Flag = True index = i if index != -1: m = b.pop(index) memo.append(m) if len(b): print((-1)) else: memo.reverse() for aa in memo: print(aa)
25
24
417
397
n = int(eval(input())) ball = list(map(int, input().split())) ans = [] count = 0 while len(ball) > 0: count += 1 for i in range(len(ball) - 1, -1, -1): # print(ball,i) if i + 1 == ball[i]: move = ball.pop(i) ans.insert(0, move) break if count == 100000: break if len(ans) == n: for i in ans: print(i) else: print((-1))
n = int(eval(input())) b = list(map(int, input().split())) Flag = True memo = [] while Flag: Flag = False index = -1 for i, v in enumerate(b): if i == v - 1: Flag = True index = i if index != -1: m = b.pop(index) memo.append(m) if len(b): print((-1)) else: memo.reverse() for aa in memo: print(aa)
false
4
[ "-ball = list(map(int, input().split()))", "-ans = []", "-count = 0", "-while len(ball) > 0:", "- count += 1", "- for i in range(len(ball) - 1, -1, -1):", "- # print(ball,i)", "- if i + 1 == ball[i]:", "- move = ball.pop(i)", "- ans.insert(0, move)", "- break", "- if count == 100000:", "- break", "-if len(ans) == n:", "- for i in ans:", "- print(i)", "+b = list(map(int, input().split()))", "+Flag = True", "+memo = []", "+while Flag:", "+ Flag = False", "+ index = -1", "+ for i, v in enumerate(b):", "+ if i == v - 1:", "+ Flag = True", "+ index = i", "+ if index != -1:", "+ m = b.pop(index)", "+ memo.append(m)", "+if len(b):", "+ print((-1))", "- print((-1))", "+ memo.reverse()", "+ for aa in memo:", "+ print(aa)" ]
false
0.309344
0.044859
6.89592
[ "s315735426", "s741459952" ]
u179169725
p02615
python
s423876543
s675589055
144
133
102,312
102,180
Accepted
Accepted
7.64
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b # 貪欲に大きい方だと思うんだけど違うのかな # 貪欲でない反例 (わからん) N = a_int() A = ints() A.sort() ans = A.pop() N -= 2 while N > 1: N -= 2 ans += 2 * A.pop() if N == 1: ans += A.pop() print(ans)
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b # https://atcoder.jp/contests/abc173/tasks/abc173_d # 大きい方から使いそう N = a_int() A = ints() A.sort(reverse=True) ans = A[0] cnt = 1 for a in A[1:]: if cnt == N - 1: break ans += a cnt += 1 if cnt == N - 1: break ans += a cnt += 1 print(ans)
80
85
1,679
1,781
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b # 貪欲に大きい方だと思うんだけど違うのかな # 貪欲でない反例 (わからん) N = a_int() A = ints() A.sort() ans = A.pop() N -= 2 while N > 1: N -= 2 ans += 2 * A.pop() if N == 1: ans += A.pop() print(ans)
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b # https://atcoder.jp/contests/abc173/tasks/abc173_d # 大きい方から使いそう N = a_int() A = ints() A.sort(reverse=True) ans = A[0] cnt = 1 for a in A[1:]: if cnt == N - 1: break ans += a cnt += 1 if cnt == N - 1: break ans += a cnt += 1 print(ans)
false
5.882353
[ "-# 貪欲に大きい方だと思うんだけど違うのかな", "-# 貪欲でない反例 (わからん)", "+# https://atcoder.jp/contests/abc173/tasks/abc173_d", "+# 大きい方から使いそう", "-A.sort()", "-ans = A.pop()", "-N -= 2", "-while N > 1:", "- N -= 2", "- ans += 2 * A.pop()", "-if N == 1:", "- ans += A.pop()", "+A.sort(reverse=True)", "+ans = A[0]", "+cnt = 1", "+for a in A[1:]:", "+ if cnt == N - 1:", "+ break", "+ ans += a", "+ cnt += 1", "+ if cnt == N - 1:", "+ break", "+ ans += a", "+ cnt += 1" ]
false
0.049339
0.047199
1.045329
[ "s423876543", "s675589055" ]
u392319141
p03564
python
s322945564
s696362147
20
17
2,940
2,940
Accepted
Accepted
15
N = int(eval(input())) K = int(eval(input())) ans = 10**18 for state in range(1 << N): now = 1 for d in range(N): if (state & (1 << d)) == 0: now *= 2 else: now += K ans = min(ans, now) print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 1 for _ in range(N): if ans < K: ans *= 2 else: ans += K print(ans)
13
10
250
142
N = int(eval(input())) K = int(eval(input())) ans = 10**18 for state in range(1 << N): now = 1 for d in range(N): if (state & (1 << d)) == 0: now *= 2 else: now += K ans = min(ans, now) print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 1 for _ in range(N): if ans < K: ans *= 2 else: ans += K print(ans)
false
23.076923
[ "-ans = 10**18", "-for state in range(1 << N):", "- now = 1", "- for d in range(N):", "- if (state & (1 << d)) == 0:", "- now *= 2", "- else:", "- now += K", "- ans = min(ans, now)", "+ans = 1", "+for _ in range(N):", "+ if ans < K:", "+ ans *= 2", "+ else:", "+ ans += K" ]
false
0.049104
0.0461
1.065162
[ "s322945564", "s696362147" ]
u969850098
p03208
python
s767603423
s968510608
229
138
8,280
8,256
Accepted
Accepted
39.74
N, K = list(map(int, input().split())) heights = sorted([int(eval(input())) for _ in range(N)]) ans = float('inf') for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
import sys input = sys.stdin.readline N, K = list(map(int, input().rstrip().split())) heights = sorted([int(input().rstrip()) for _ in range(N)]) ans = float('inf') for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
7
9
248
306
N, K = list(map(int, input().split())) heights = sorted([int(eval(input())) for _ in range(N)]) ans = float("inf") for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
import sys input = sys.stdin.readline N, K = list(map(int, input().rstrip().split())) heights = sorted([int(input().rstrip()) for _ in range(N)]) ans = float("inf") for i in range(N - K + 1): if abs(heights[i] - heights[i + K - 1]) < ans: ans = abs(heights[i] - heights[i + K - 1]) print(ans)
false
22.222222
[ "-N, K = list(map(int, input().split()))", "-heights = sorted([int(eval(input())) for _ in range(N)])", "+import sys", "+", "+input = sys.stdin.readline", "+N, K = list(map(int, input().rstrip().split()))", "+heights = sorted([int(input().rstrip()) for _ in range(N)])" ]
false
0.085209
0.040168
2.121324
[ "s767603423", "s968510608" ]
u465699806
p03401
python
s807964523
s307140091
409
320
66,848
59,168
Accepted
Accepted
21.76
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) args = sys.argv input = sys.stdin.readline def dump(*objects): if len(args) == 2 and args[1] == "DEBUG": print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): dump(i) B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, -1): dump(i) C[i] = C[i+1] + abs(A[i]-A[i+1]) dump(A, B, C) for i in range(1, N+1): dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1])) print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1])) exit(0)
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) args = sys.argv input = sys.stdin.readline def dump(*objects): if len(args) == 2 and args[1] == "DEBUG": print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = [0]*len(A) C = [0]*len(A) for i in range(1, len(A)): dump(i) B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, -1): dump(i) C[i] = C[i+1] + abs(A[i]-A[i+1]) dump(A, B, C) for i in range(1, N+1): dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1])) print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1])) exit(0)
32
32
746
738
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) args = sys.argv input = sys.stdin.readline def dump(*objects): if len(args) == 2 and args[1] == "DEBUG": print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): dump(i) B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, -1): dump(i) C[i] = C[i + 1] + abs(A[i] - A[i + 1]) dump(A, B, C) for i in range(1, N + 1): dump(i, B[i - 1] + B[N + 1] - B[i + 1] + abs(A[i - 1] - A[i + 1])) print(B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1])) exit(0)
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) args = sys.argv input = sys.stdin.readline def dump(*objects): if len(args) == 2 and args[1] == "DEBUG": print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = [0] * len(A) C = [0] * len(A) for i in range(1, len(A)): dump(i) B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, -1): dump(i) C[i] = C[i + 1] + abs(A[i] - A[i + 1]) dump(A, B, C) for i in range(1, N + 1): dump(i, B[i - 1] + B[N + 1] - B[i + 1] + abs(A[i - 1] - A[i + 1])) print(B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1])) exit(0)
false
0
[ "-B = cp.deepcopy(A)", "-C = cp.deepcopy(A)", "+B = [0] * len(A)", "+C = [0] * len(A)" ]
false
0.050674
0.048699
1.04055
[ "s807964523", "s307140091" ]
u853185302
p03160
python
s146669969
s025715490
549
201
22,744
13,924
Accepted
Accepted
63.39
import numpy as np N = int(eval(input())) h = list(map(int,input().split())) memo = np.zeros(N) memo[0] = 0 memo[1] = abs(h[0]-h[1]) for i in range(2,N): a = memo[i-1] + abs(h[i] - h[i-1]) b = memo[i-2] + abs(h[i] - h[i-2]) memo[i] = min(a,b) print((int(memo[N-1])))
n = int(eval(input())) h = list(map(int,input().split())) dp = [10**7]*n dp[0] = 0 for i in range(1,n): dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(3,i+1))]) print((dp[n-1]))
15
8
282
193
import numpy as np N = int(eval(input())) h = list(map(int, input().split())) memo = np.zeros(N) memo[0] = 0 memo[1] = abs(h[0] - h[1]) for i in range(2, N): a = memo[i - 1] + abs(h[i] - h[i - 1]) b = memo[i - 2] + abs(h[i] - h[i - 2]) memo[i] = min(a, b) print((int(memo[N - 1])))
n = int(eval(input())) h = list(map(int, input().split())) dp = [10**7] * n dp[0] = 0 for i in range(1, n): dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(3, i + 1))]) print((dp[n - 1]))
false
46.666667
[ "-import numpy as np", "-", "-N = int(eval(input()))", "+n = int(eval(input()))", "-memo = np.zeros(N)", "-memo[0] = 0", "-memo[1] = abs(h[0] - h[1])", "-for i in range(2, N):", "- a = memo[i - 1] + abs(h[i] - h[i - 1])", "- b = memo[i - 2] + abs(h[i] - h[i - 2])", "- memo[i] = min(a, b)", "-print((int(memo[N - 1])))", "+dp = [10**7] * n", "+dp[0] = 0", "+for i in range(1, n):", "+ dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(3, i + 1))])", "+print((dp[n - 1]))" ]
false
0.195226
0.036982
5.278979
[ "s146669969", "s025715490" ]
u463630127
p02924
python
s482036881
s293488360
17
10
2,940
2,568
Accepted
Accepted
41.18
n=int(eval(input())) ans=n*(n-1)//2 print((int(ans)))
n=int(eval(input())) ans=n*(n-1)/2 print((int(ans)))
3
3
48
48
n = int(eval(input())) ans = n * (n - 1) // 2 print((int(ans)))
n = int(eval(input())) ans = n * (n - 1) / 2 print((int(ans)))
false
0
[ "-ans = n * (n - 1) // 2", "+ans = n * (n - 1) / 2" ]
false
0.097198
0.086386
1.125157
[ "s482036881", "s293488360" ]
u123518636
p03277
python
s753162379
s540209863
744
626
139,508
110,324
Accepted
Accepted
15.86
#!/usr/bin/python # -*- coding: utf-8 -*- import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq # decimal.getcontext().prec = 50 # sys.setrecursionlimit(10000) # MOD = 10**9 + 7 def solve(f): n = f.read_int() a = f.read_int_list() if n == 1: return a[0] d = dict(list(zip(sorted(set(a)), list(range(len(a)))))) def check(num): a1 = [0]*(n+1) a2 = [0]*(n+1) for i, ai in enumerate(a): if ai < num: a1[i+1] = a1[i]+1 a2[i+1] = a2[i] else: a1[i+1] = a1[i] a2[i+1] = a2[i]+1 ad = [a2[i]-a1[i]+10**5+1 for i in range(n+1)] bit = BinaryIndexedTree(2*10**5+1) cnt = 0 for i in range(n+1): cnt += bit.sum(ad[i]) bit.add(ad[i], 1) # print num, cnt return n*(n+1)/2 - cnt <= cnt mi = 0 ma = 10**9+1 while ma - mi > 1: mid = (ma+mi)/2 if check(mid): mi = mid else: ma = mid return mi class BinaryIndexedTree(object): """Binary Indexed Tree (1-indexed)""" def __init__(self, size, default=0): self.bit = [default for _ in range(size + 1)] self.size = size def sum(self, i): """sum 1 to i""" s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): """add x to bit[i]""" while i <= self.size: self.bit[i] += x i += i & -i class Reader(object): def __init__(self, filename=None): self.file = open(filename) if filename is not None else None self.case = 1 def __readline(self): return self.file.next().strip() if self.file else input() def next_case(self): next(self.file) self.case += 1 def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return int(self.__readline()) def read_decimal(self): return decimal.Decimal(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return list(map(int, self.__readline().split())) def read_float_list(self): return list(map(float, self.__readline().split())) def read_long_list(self): return list(map(int, self.__readline().split())) def read_decimal_list(self): return list(map(decimal.Decimal, self.__readline().split())) def read_str_list(self): return self.__readline().split() if __name__ == '__main__': filename = sys.argv[1] if len(sys.argv) > 1 else None f = Reader(filename) if f.file: while True: print("Case #%d\n"%f.case, solve(f)) try: f.next_case() except StopIteration: break else: print(solve(f))
#!/usr/bin/python # -*- coding: utf-8 -*- import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq # decimal.getcontext().prec = 50 # sys.setrecursionlimit(10000) # MOD = 10**9 + 7 def solve(f): n = f.read_int() a = f.read_int_list() def check(num): aa = [10**5+1]*(n+1) for i, ai in enumerate(a): if ai < num: aa[i+1] = aa[i]-1 else: aa[i+1] = aa[i]+1 bit = BinaryIndexedTree(2*10**5+1) cnt = 0 for i in range(n+1): cnt += bit.sum(aa[i]) bit.add(aa[i], 1) return n*(n+1)/2 - cnt <= cnt mi = 0 ma = 10**9+1 while ma - mi > 1: mid = (ma+mi)/2 if check(mid): mi = mid else: ma = mid return mi class BinaryIndexedTree(object): """Binary Indexed Tree (1-indexed)""" def __init__(self, size, default=0): self.bit = [default for _ in range(size + 1)] self.size = size def sum(self, i): """sum 1 to i""" s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): """add x to bit[i]""" while i <= self.size: self.bit[i] += x i += i & -i class Reader(object): def __init__(self, filename=None): self.file = open(filename) if filename is not None else None self.case = 1 def __readline(self): return self.file.next().strip() if self.file else input() def next_case(self): next(self.file) self.case += 1 def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return int(self.__readline()) def read_decimal(self): return decimal.Decimal(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return list(map(int, self.__readline().split())) def read_float_list(self): return list(map(float, self.__readline().split())) def read_long_list(self): return list(map(int, self.__readline().split())) def read_decimal_list(self): return list(map(decimal.Decimal, self.__readline().split())) def read_str_list(self): return self.__readline().split() if __name__ == '__main__': filename = sys.argv[1] if len(sys.argv) > 1 else None f = Reader(filename) if f.file: while True: print("Case #%d\n"%f.case, solve(f)) try: f.next_case() except StopIteration: break else: print(solve(f))
107
98
2,983
2,734
#!/usr/bin/python # -*- coding: utf-8 -*- import sys, collections, itertools, re, math, fractions, decimal, random, array, bisect, heapq # decimal.getcontext().prec = 50 # sys.setrecursionlimit(10000) # MOD = 10**9 + 7 def solve(f): n = f.read_int() a = f.read_int_list() if n == 1: return a[0] d = dict(list(zip(sorted(set(a)), list(range(len(a)))))) def check(num): a1 = [0] * (n + 1) a2 = [0] * (n + 1) for i, ai in enumerate(a): if ai < num: a1[i + 1] = a1[i] + 1 a2[i + 1] = a2[i] else: a1[i + 1] = a1[i] a2[i + 1] = a2[i] + 1 ad = [a2[i] - a1[i] + 10**5 + 1 for i in range(n + 1)] bit = BinaryIndexedTree(2 * 10**5 + 1) cnt = 0 for i in range(n + 1): cnt += bit.sum(ad[i]) bit.add(ad[i], 1) # print num, cnt return n * (n + 1) / 2 - cnt <= cnt mi = 0 ma = 10**9 + 1 while ma - mi > 1: mid = (ma + mi) / 2 if check(mid): mi = mid else: ma = mid return mi class BinaryIndexedTree(object): """Binary Indexed Tree (1-indexed)""" def __init__(self, size, default=0): self.bit = [default for _ in range(size + 1)] self.size = size def sum(self, i): """sum 1 to i""" s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): """add x to bit[i]""" while i <= self.size: self.bit[i] += x i += i & -i class Reader(object): def __init__(self, filename=None): self.file = open(filename) if filename is not None else None self.case = 1 def __readline(self): return self.file.next().strip() if self.file else input() def next_case(self): next(self.file) self.case += 1 def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return int(self.__readline()) def read_decimal(self): return decimal.Decimal(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return list(map(int, self.__readline().split())) def read_float_list(self): return list(map(float, self.__readline().split())) def read_long_list(self): return list(map(int, self.__readline().split())) def read_decimal_list(self): return list(map(decimal.Decimal, self.__readline().split())) def read_str_list(self): return self.__readline().split() if __name__ == "__main__": filename = sys.argv[1] if len(sys.argv) > 1 else None f = Reader(filename) if f.file: while True: print("Case #%d\n" % f.case, solve(f)) try: f.next_case() except StopIteration: break else: print(solve(f))
#!/usr/bin/python # -*- coding: utf-8 -*- import sys, collections, itertools, re, math, fractions, decimal, random, array, bisect, heapq # decimal.getcontext().prec = 50 # sys.setrecursionlimit(10000) # MOD = 10**9 + 7 def solve(f): n = f.read_int() a = f.read_int_list() def check(num): aa = [10**5 + 1] * (n + 1) for i, ai in enumerate(a): if ai < num: aa[i + 1] = aa[i] - 1 else: aa[i + 1] = aa[i] + 1 bit = BinaryIndexedTree(2 * 10**5 + 1) cnt = 0 for i in range(n + 1): cnt += bit.sum(aa[i]) bit.add(aa[i], 1) return n * (n + 1) / 2 - cnt <= cnt mi = 0 ma = 10**9 + 1 while ma - mi > 1: mid = (ma + mi) / 2 if check(mid): mi = mid else: ma = mid return mi class BinaryIndexedTree(object): """Binary Indexed Tree (1-indexed)""" def __init__(self, size, default=0): self.bit = [default for _ in range(size + 1)] self.size = size def sum(self, i): """sum 1 to i""" s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): """add x to bit[i]""" while i <= self.size: self.bit[i] += x i += i & -i class Reader(object): def __init__(self, filename=None): self.file = open(filename) if filename is not None else None self.case = 1 def __readline(self): return self.file.next().strip() if self.file else input() def next_case(self): next(self.file) self.case += 1 def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return int(self.__readline()) def read_decimal(self): return decimal.Decimal(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return list(map(int, self.__readline().split())) def read_float_list(self): return list(map(float, self.__readline().split())) def read_long_list(self): return list(map(int, self.__readline().split())) def read_decimal_list(self): return list(map(decimal.Decimal, self.__readline().split())) def read_str_list(self): return self.__readline().split() if __name__ == "__main__": filename = sys.argv[1] if len(sys.argv) > 1 else None f = Reader(filename) if f.file: while True: print("Case #%d\n" % f.case, solve(f)) try: f.next_case() except StopIteration: break else: print(solve(f))
false
8.411215
[ "- if n == 1:", "- return a[0]", "- d = dict(list(zip(sorted(set(a)), list(range(len(a))))))", "- a1 = [0] * (n + 1)", "- a2 = [0] * (n + 1)", "+ aa = [10**5 + 1] * (n + 1)", "- a1[i + 1] = a1[i] + 1", "- a2[i + 1] = a2[i]", "+ aa[i + 1] = aa[i] - 1", "- a1[i + 1] = a1[i]", "- a2[i + 1] = a2[i] + 1", "- ad = [a2[i] - a1[i] + 10**5 + 1 for i in range(n + 1)]", "+ aa[i + 1] = aa[i] + 1", "- cnt += bit.sum(ad[i])", "- bit.add(ad[i], 1)", "- # print num, cnt", "+ cnt += bit.sum(aa[i])", "+ bit.add(aa[i], 1)" ]
false
1.269797
1.703776
0.745284
[ "s753162379", "s540209863" ]
u192154323
p03274
python
s115427043
s826913916
121
92
14,480
20,340
Accepted
Accepted
23.97
n,k = list(map(int,input().split())) x_ls = list(map(int, input().split())) ans = float('inf') for i in range(n-k+1): if x_ls[i+k-1] < 0: ans = min(ans, abs(x_ls[i])) elif x_ls[i] < 0 and x_ls[i+k-1] >= 0: near = min(abs(x_ls[i]),abs(x_ls[i+k-1])) far = max(abs(x_ls[i]),abs(x_ls[i+k-1])) ans = min(ans, 2 * near + far) elif x_ls[i] >= 0: ans = min(ans, x_ls[i+k-1]) print(ans)
import sys n,k = list(map(int,input().split())) x_ls = list(map(int, input().split())) x_ls.sort() if x_ls[0] >= 0: print((x_ls[k-1])) sys.exit() elif x_ls[-1] <= 0: x_ls.sort(reverse=True) print((abs(x_ls[k-1]))) sys.exit() l = 0 r = k - 1 ans = float('inf') while r < n: cost_1 = 2*abs(x_ls[l]) + abs(x_ls[r]) cost_2 = abs(x_ls[l]) + 2*abs(x_ls[r]) cost = min(cost_1,cost_2) ans = min(cost, ans) r += 1 l += 1 print(ans)
13
23
435
483
n, k = list(map(int, input().split())) x_ls = list(map(int, input().split())) ans = float("inf") for i in range(n - k + 1): if x_ls[i + k - 1] < 0: ans = min(ans, abs(x_ls[i])) elif x_ls[i] < 0 and x_ls[i + k - 1] >= 0: near = min(abs(x_ls[i]), abs(x_ls[i + k - 1])) far = max(abs(x_ls[i]), abs(x_ls[i + k - 1])) ans = min(ans, 2 * near + far) elif x_ls[i] >= 0: ans = min(ans, x_ls[i + k - 1]) print(ans)
import sys n, k = list(map(int, input().split())) x_ls = list(map(int, input().split())) x_ls.sort() if x_ls[0] >= 0: print((x_ls[k - 1])) sys.exit() elif x_ls[-1] <= 0: x_ls.sort(reverse=True) print((abs(x_ls[k - 1]))) sys.exit() l = 0 r = k - 1 ans = float("inf") while r < n: cost_1 = 2 * abs(x_ls[l]) + abs(x_ls[r]) cost_2 = abs(x_ls[l]) + 2 * abs(x_ls[r]) cost = min(cost_1, cost_2) ans = min(cost, ans) r += 1 l += 1 print(ans)
false
43.478261
[ "+import sys", "+", "+x_ls.sort()", "+if x_ls[0] >= 0:", "+ print((x_ls[k - 1]))", "+ sys.exit()", "+elif x_ls[-1] <= 0:", "+ x_ls.sort(reverse=True)", "+ print((abs(x_ls[k - 1])))", "+ sys.exit()", "+l = 0", "+r = k - 1", "-for i in range(n - k + 1):", "- if x_ls[i + k - 1] < 0:", "- ans = min(ans, abs(x_ls[i]))", "- elif x_ls[i] < 0 and x_ls[i + k - 1] >= 0:", "- near = min(abs(x_ls[i]), abs(x_ls[i + k - 1]))", "- far = max(abs(x_ls[i]), abs(x_ls[i + k - 1]))", "- ans = min(ans, 2 * near + far)", "- elif x_ls[i] >= 0:", "- ans = min(ans, x_ls[i + k - 1])", "+while r < n:", "+ cost_1 = 2 * abs(x_ls[l]) + abs(x_ls[r])", "+ cost_2 = abs(x_ls[l]) + 2 * abs(x_ls[r])", "+ cost = min(cost_1, cost_2)", "+ ans = min(cost, ans)", "+ r += 1", "+ l += 1" ]
false
0.066419
0.035055
1.894739
[ "s115427043", "s826913916" ]
u272028993
p03662
python
s650739022
s068676184
691
578
151,836
132,892
Accepted
Accepted
16.35
import sys sys.setrecursionlimit(10**8) def find_path(now, par): if now == n - 1: path.append(n - 1) return True for to in g[now]: if to == par: continue if find_path(to, now): path.append(now) return True return False def dfs1(now, par, color): color[now] = "b" for to in g[now]: if to == par: continue if color[to] == "w": continue dfs1(to, now, color) def dfs2(now, par, color): color[now] = "w" for to in g[now]: if to == par: continue if color[to] == "b": continue dfs2(to, now, color) n = int(input()) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a -= 1; b -=1 g[a].append(b) g[b].append(a) path = [] find_path(0, -1) path.reverse() color = ["bl"] * n color[0] = "b" color[n - 1] = "w" j = 1 k = len(path) - 2 for i in range(1, len(path) - 1): if i % 2 == 1: v = path[j] color[v] = "b" j += 1 else: v = path[k] color[v] = "w" k -= 1 dfs1(0, -1, color) dfs2(n - 1, -1, color) cntf = 0 cnts = 0 for i in range(n): if color[i] == "b": cntf += 1 else: cnts += 1 if cntf > cnts: print("Fennec") else: print("Snuke")
import sys sys.setrecursionlimit(10**8) def find_path(now, par): if now == n - 1: path.append(n - 1) return True for to in g[now]: if to == par: continue if find_path(to, now): path.append(now) return True return False def dfs(now, par, color): color[now] = 'b' for to in g[now]: if to == par: continue if color[to] == "w": continue dfs(to, now, color) n = int(input()) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a -= 1; b -=1 g[a].append(b) g[b].append(a) path = [] find_path(0, -1) path.reverse() color = ["bl"] * n color[0] = "b" color[n - 1] = "w" j = 1 k = len(path) - 2 for i in range(1, len(path) - 1): if i % 2 == 1: v = path[j] color[v] = "b" j += 1 else: v = path[k] color[v] = "w" k -= 1 dfs(0, -1, color) cnt = 0 for i in range(n): if color[i] == "b": cnt += 1 if cnt > n - cnt: print("Fennec") else: print("Snuke")
65
54
1,369
1,126
import sys sys.setrecursionlimit(10**8) def find_path(now, par): if now == n - 1: path.append(n - 1) return True for to in g[now]: if to == par: continue if find_path(to, now): path.append(now) return True return False def dfs1(now, par, color): color[now] = "b" for to in g[now]: if to == par: continue if color[to] == "w": continue dfs1(to, now, color) def dfs2(now, par, color): color[now] = "w" for to in g[now]: if to == par: continue if color[to] == "b": continue dfs2(to, now, color) n = int(input()) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 g[a].append(b) g[b].append(a) path = [] find_path(0, -1) path.reverse() color = ["bl"] * n color[0] = "b" color[n - 1] = "w" j = 1 k = len(path) - 2 for i in range(1, len(path) - 1): if i % 2 == 1: v = path[j] color[v] = "b" j += 1 else: v = path[k] color[v] = "w" k -= 1 dfs1(0, -1, color) dfs2(n - 1, -1, color) cntf = 0 cnts = 0 for i in range(n): if color[i] == "b": cntf += 1 else: cnts += 1 if cntf > cnts: print("Fennec") else: print("Snuke")
import sys sys.setrecursionlimit(10**8) def find_path(now, par): if now == n - 1: path.append(n - 1) return True for to in g[now]: if to == par: continue if find_path(to, now): path.append(now) return True return False def dfs(now, par, color): color[now] = "b" for to in g[now]: if to == par: continue if color[to] == "w": continue dfs(to, now, color) n = int(input()) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 g[a].append(b) g[b].append(a) path = [] find_path(0, -1) path.reverse() color = ["bl"] * n color[0] = "b" color[n - 1] = "w" j = 1 k = len(path) - 2 for i in range(1, len(path) - 1): if i % 2 == 1: v = path[j] color[v] = "b" j += 1 else: v = path[k] color[v] = "w" k -= 1 dfs(0, -1, color) cnt = 0 for i in range(n): if color[i] == "b": cnt += 1 if cnt > n - cnt: print("Fennec") else: print("Snuke")
false
16.923077
[ "-def dfs1(now, par, color):", "+def dfs(now, par, color):", "- dfs1(to, now, color)", "-", "-", "-def dfs2(now, par, color):", "- color[now] = \"w\"", "- for to in g[now]:", "- if to == par:", "- continue", "- if color[to] == \"b\":", "- continue", "- dfs2(to, now, color)", "+ dfs(to, now, color)", "-dfs1(0, -1, color)", "-dfs2(n - 1, -1, color)", "-cntf = 0", "-cnts = 0", "+dfs(0, -1, color)", "+cnt = 0", "- cntf += 1", "- else:", "- cnts += 1", "-if cntf > cnts:", "+ cnt += 1", "+if cnt > n - cnt:" ]
false
0.007867
0.035672
0.220542
[ "s650739022", "s068676184" ]
u133356863
p02987
python
s918233591
s756224510
21
17
3,316
2,940
Accepted
Accepted
19.05
import collections s=eval(input()) print(('Yes'if len(set(s))==2 and collections.Counter(s).most_common()[0][1]==2 else 'No'))
s=eval(input()) print(('Yes'if len(set(s))==2 and s.count(s[0])==2 else 'No'))
4
2
122
71
import collections s = eval(input()) print( ( "Yes" if len(set(s)) == 2 and collections.Counter(s).most_common()[0][1] == 2 else "No" ) )
s = eval(input()) print(("Yes" if len(set(s)) == 2 and s.count(s[0]) == 2 else "No"))
false
50
[ "-import collections", "-", "-print(", "- (", "- \"Yes\"", "- if len(set(s)) == 2 and collections.Counter(s).most_common()[0][1] == 2", "- else \"No\"", "- )", "-)", "+print((\"Yes\" if len(set(s)) == 2 and s.count(s[0]) == 2 else \"No\"))" ]
false
0.047304
0.046777
1.011263
[ "s918233591", "s756224510" ]
u226108478
p03681
python
s408145845
s297585087
57
29
3,060
3,064
Accepted
Accepted
49.12
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': n, m = list(map(int, input().split())) diff = abs(n - m) n_factorial = 1 m_factorial = 1 large_number = 10 ** 9 + 7 for i in range(1, n + 1): n_factorial = (n_factorial * i) % large_number for k in range(1, m + 1): m_factorial = (m_factorial * k) % large_number rate = 0 if diff == 1: rate = 1 elif diff == 0: rate = 2 print(((n_factorial * m_factorial * rate) % large_number))
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C large_number = 10 ** 9 + 7 def factorial(number: int) -> int: value = 1 for i in range(1, number + 1): value = (value * i) % large_number return value if __name__ == '__main__': n, m = list(map(int, input().split())) diff = abs(n - m) result = factorial(min(n, m)) # See: # https://beta.atcoder.jp/contests/abc065/submissions/1654425 if diff == 1: rate = 1 print(((result * result * max(n, m) * rate) % large_number)) elif diff == 0: rate = 2 print(((result * result * rate) % large_number)) else: print((0))
26
30
576
698
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == "__main__": n, m = list(map(int, input().split())) diff = abs(n - m) n_factorial = 1 m_factorial = 1 large_number = 10**9 + 7 for i in range(1, n + 1): n_factorial = (n_factorial * i) % large_number for k in range(1, m + 1): m_factorial = (m_factorial * k) % large_number rate = 0 if diff == 1: rate = 1 elif diff == 0: rate = 2 print(((n_factorial * m_factorial * rate) % large_number))
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C large_number = 10**9 + 7 def factorial(number: int) -> int: value = 1 for i in range(1, number + 1): value = (value * i) % large_number return value if __name__ == "__main__": n, m = list(map(int, input().split())) diff = abs(n - m) result = factorial(min(n, m)) # See: # https://beta.atcoder.jp/contests/abc065/submissions/1654425 if diff == 1: rate = 1 print(((result * result * max(n, m) * rate) % large_number)) elif diff == 0: rate = 2 print(((result * result * rate) % large_number)) else: print((0))
false
13.333333
[ "+large_number = 10**9 + 7", "+", "+", "+def factorial(number: int) -> int:", "+ value = 1", "+ for i in range(1, number + 1):", "+ value = (value * i) % large_number", "+ return value", "+", "+", "- n_factorial = 1", "- m_factorial = 1", "- large_number = 10**9 + 7", "- for i in range(1, n + 1):", "- n_factorial = (n_factorial * i) % large_number", "- for k in range(1, m + 1):", "- m_factorial = (m_factorial * k) % large_number", "- rate = 0", "+ result = factorial(min(n, m))", "+ # See:", "+ # https://beta.atcoder.jp/contests/abc065/submissions/1654425", "+ print(((result * result * max(n, m) * rate) % large_number))", "- print(((n_factorial * m_factorial * rate) % large_number))", "+ print(((result * result * rate) % large_number))", "+ else:", "+ print((0))" ]
false
0.03838
0.074014
0.518548
[ "s408145845", "s297585087" ]
u844789719
p03363
python
s399180067
s708515201
355
291
25,852
26,136
Accepted
Accepted
18.03
import heapq N = int(eval(input())) A = [int(_) for _ in input().split()] cumsum = [0] for a in A: cumsum += [cumsum[-1] + a] heapq.heapify(cumsum) before = 10 ** 10 count = 0 ans = 0 while cumsum: now = heapq.heappop(cumsum) count += before == now if not (before == now and cumsum): ans += count * (count + 1) // 2 count = 0 before = now print(ans)
N = int(eval(input())) A = [int(_) for _ in input().split()] cumsum = [0] for a in A: cumsum += [cumsum[-1] + a] cumsum.sort() ans = 0 count = 0 for i in range(N): if cumsum[i] == cumsum[i + 1]: count += 1 if cumsum[i] != cumsum[i + 1] or i == N - 1: ans += count * (count + 1) // 2 count = 0 print(ans)
18
15
397
348
import heapq N = int(eval(input())) A = [int(_) for _ in input().split()] cumsum = [0] for a in A: cumsum += [cumsum[-1] + a] heapq.heapify(cumsum) before = 10**10 count = 0 ans = 0 while cumsum: now = heapq.heappop(cumsum) count += before == now if not (before == now and cumsum): ans += count * (count + 1) // 2 count = 0 before = now print(ans)
N = int(eval(input())) A = [int(_) for _ in input().split()] cumsum = [0] for a in A: cumsum += [cumsum[-1] + a] cumsum.sort() ans = 0 count = 0 for i in range(N): if cumsum[i] == cumsum[i + 1]: count += 1 if cumsum[i] != cumsum[i + 1] or i == N - 1: ans += count * (count + 1) // 2 count = 0 print(ans)
false
16.666667
[ "-import heapq", "-", "-heapq.heapify(cumsum)", "-before = 10**10", "+cumsum.sort()", "+ans = 0", "-ans = 0", "-while cumsum:", "- now = heapq.heappop(cumsum)", "- count += before == now", "- if not (before == now and cumsum):", "+for i in range(N):", "+ if cumsum[i] == cumsum[i + 1]:", "+ count += 1", "+ if cumsum[i] != cumsum[i + 1] or i == N - 1:", "- before = now" ]
false
0.035266
0.034177
1.03186
[ "s399180067", "s708515201" ]
u579699847
p03497
python
s477518223
s634198986
125
113
32,564
32,540
Accepted
Accepted
9.6
import collections,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = collections.Counter(LI()) count_A = sorted([v for _,v in list(A.items())]) remainder = max(0,len(A)-K) print((sum(count_A[:remainder])))
import collections,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = collections.Counter(LI()) count_A = sorted([v for v in list(A.values())]) remainder = max(0,len(A)-K) print((sum(count_A[:remainder])))
7
7
243
242
import collections, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() A = collections.Counter(LI()) count_A = sorted([v for _, v in list(A.items())]) remainder = max(0, len(A) - K) print((sum(count_A[:remainder])))
import collections, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() A = collections.Counter(LI()) count_A = sorted([v for v in list(A.values())]) remainder = max(0, len(A) - K) print((sum(count_A[:remainder])))
false
0
[ "-count_A = sorted([v for _, v in list(A.items())])", "+count_A = sorted([v for v in list(A.values())])" ]
false
0.03316
0.041883
0.791734
[ "s477518223", "s634198986" ]
u086503932
p03682
python
s219762535
s196432100
1,895
1,742
61,676
119,592
Accepted
Accepted
8.07
from heapq import heappush, heappop class UnionFind(): def __init__(self, n): self.parents = list(range(n)) def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: self.parents[y] = x N = int(eval(input())) q = [] ans = 0 S = UnionFind(N) x = [] y = [] for i in range(N): p,r = list(map(int, input().split())) x.append([p,i]) y.append([r,i]) x.sort() y.sort() for i in range(N-1): x1, i1 = x[i] y1, j1 = y[i] x2, i2 = x[i+1] y2, j2 = y[i+1] heappush(q, (abs(x1-x2), i1, i2)) heappush(q, (abs(y1-y2), j1, j2)) heappush(q, (abs(x[N-1][0]-x[0][0]), x[N-1][1], x[0][1])) heappush(q, (abs(y[N-1][0]-y[0][0]), y[N-1][1], y[0][1])) # クラスカル法 while len(q) > 0: d, a, b = heappop(q) if S.find(a) != S.find(b): ans += d S.union(a, b) print(ans)
from heapq import heappop, heappush class UnionFind(): def __init__(self, n): self.parents = list(range(n)) self.size = [1] * n def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.size[x] < self.size[y]: x,y = y,x self.parents[y] = x self.size[x] += self.size[y] N = int(eval(input())) x = [None] * N y = [None] * N for i in range(N): a, b = list(map(int, input().split())) x[i] = (a,i) y[i] = (b,i) x.sort() y.sort() q = [] for i in range(N-1): heappush(q, (abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1])) heappush(q, (abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1])) uf = UnionFind(N) ans = 0 # クラスカル法 while len(q) > 0: w, s, t = heappop(q) if uf.find(s) != uf.find(t): ans += w uf.union(s,t) print(ans)
51
47
1,086
1,089
from heapq import heappush, heappop class UnionFind: def __init__(self, n): self.parents = list(range(n)) def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: self.parents[y] = x N = int(eval(input())) q = [] ans = 0 S = UnionFind(N) x = [] y = [] for i in range(N): p, r = list(map(int, input().split())) x.append([p, i]) y.append([r, i]) x.sort() y.sort() for i in range(N - 1): x1, i1 = x[i] y1, j1 = y[i] x2, i2 = x[i + 1] y2, j2 = y[i + 1] heappush(q, (abs(x1 - x2), i1, i2)) heappush(q, (abs(y1 - y2), j1, j2)) heappush(q, (abs(x[N - 1][0] - x[0][0]), x[N - 1][1], x[0][1])) heappush(q, (abs(y[N - 1][0] - y[0][0]), y[N - 1][1], y[0][1])) # クラスカル法 while len(q) > 0: d, a, b = heappop(q) if S.find(a) != S.find(b): ans += d S.union(a, b) print(ans)
from heapq import heappop, heappush class UnionFind: def __init__(self, n): self.parents = list(range(n)) self.size = [1] * n def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.size[x] < self.size[y]: x, y = y, x self.parents[y] = x self.size[x] += self.size[y] N = int(eval(input())) x = [None] * N y = [None] * N for i in range(N): a, b = list(map(int, input().split())) x[i] = (a, i) y[i] = (b, i) x.sort() y.sort() q = [] for i in range(N - 1): heappush(q, (abs(x[i][0] - x[i + 1][0]), x[i][1], x[i + 1][1])) heappush(q, (abs(y[i][0] - y[i + 1][0]), y[i][1], y[i + 1][1])) uf = UnionFind(N) ans = 0 # クラスカル法 while len(q) > 0: w, s, t = heappop(q) if uf.find(s) != uf.find(t): ans += w uf.union(s, t) print(ans)
false
7.843137
[ "-from heapq import heappush, heappop", "+from heapq import heappop, heappush", "+ self.size = [1] * n", "+ if self.size[x] < self.size[y]:", "+ x, y = y, x", "+ self.size[x] += self.size[y]", "-q = []", "-ans = 0", "-S = UnionFind(N)", "-x = []", "-y = []", "+x = [None] * N", "+y = [None] * N", "- p, r = list(map(int, input().split()))", "- x.append([p, i])", "- y.append([r, i])", "+ a, b = list(map(int, input().split()))", "+ x[i] = (a, i)", "+ y[i] = (b, i)", "+q = []", "- x1, i1 = x[i]", "- y1, j1 = y[i]", "- x2, i2 = x[i + 1]", "- y2, j2 = y[i + 1]", "- heappush(q, (abs(x1 - x2), i1, i2))", "- heappush(q, (abs(y1 - y2), j1, j2))", "-heappush(q, (abs(x[N - 1][0] - x[0][0]), x[N - 1][1], x[0][1]))", "-heappush(q, (abs(y[N - 1][0] - y[0][0]), y[N - 1][1], y[0][1]))", "+ heappush(q, (abs(x[i][0] - x[i + 1][0]), x[i][1], x[i + 1][1]))", "+ heappush(q, (abs(y[i][0] - y[i + 1][0]), y[i][1], y[i + 1][1]))", "+uf = UnionFind(N)", "+ans = 0", "- d, a, b = heappop(q)", "- if S.find(a) != S.find(b):", "- ans += d", "- S.union(a, b)", "+ w, s, t = heappop(q)", "+ if uf.find(s) != uf.find(t):", "+ ans += w", "+ uf.union(s, t)" ]
false
0.047761
0.045471
1.050363
[ "s219762535", "s196432100" ]
u118645446
p03455
python
s062228075
s889654243
30
18
3,700
2,940
Accepted
Accepted
40
import operator import functools number_list = list(map(int, input().split())) product = functools.reduce(operator.mul, number_list) if product % 2 == 0: print('Even') else: print('Odd')
a, b = list(map(int, input().split())) if (a * b % 2) == 0: print('Even') else: print('Odd')
8
5
201
98
import operator import functools number_list = list(map(int, input().split())) product = functools.reduce(operator.mul, number_list) if product % 2 == 0: print("Even") else: print("Odd")
a, b = list(map(int, input().split())) if (a * b % 2) == 0: print("Even") else: print("Odd")
false
37.5
[ "-import operator", "-import functools", "-", "-number_list = list(map(int, input().split()))", "-product = functools.reduce(operator.mul, number_list)", "-if product % 2 == 0:", "+a, b = list(map(int, input().split()))", "+if (a * b % 2) == 0:" ]
false
0.043212
0.085704
0.504202
[ "s062228075", "s889654243" ]
u706695185
p03493
python
s439194300
s469674344
176
19
38,256
2,940
Accepted
Accepted
89.2
s = eval(input()) print((s.count('1')))
abc = eval(input()) print((abc.count('1')))
2
2
32
36
s = eval(input()) print((s.count("1")))
abc = eval(input()) print((abc.count("1")))
false
0
[ "-s = eval(input())", "-print((s.count(\"1\")))", "+abc = eval(input())", "+print((abc.count(\"1\")))" ]
false
0.121653
0.007323
16.612975
[ "s439194300", "s469674344" ]
u912237403
p00092
python
s754013421
s597638832
3,160
2,450
32,980
32,992
Accepted
Accepted
22.47
import sys while 1: n=eval(input())+1 if n==1:break A=[''*n]+[' '+input() for i in range(1,n)] M=[[0]*n for i in range(n)] for i in range(1,n): for j in range(1,n): if A[i][j]=='.': M[i][j]=min(M[i-1][j-1],M[i-1][j],M[i][j-1])+1 print(max(list(map(max,M))))
import sys while 1: n=eval(input())+1 if n==1:break N=list(range(n)) N1=N[1:] A=[''*n]+[' '+input() for i in N1] M=[[0]*n for i in N] y=M[0] for i in N1: x=[0]*n B=A[i] for j in N1: if B[j]=='.': x[j]=min(y[j-1],y[j],x[j-1])+1 M[i]=x y=x print(max(list(map(max,M))))
11
18
281
313
import sys while 1: n = eval(input()) + 1 if n == 1: break A = ["" * n] + [" " + input() for i in range(1, n)] M = [[0] * n for i in range(n)] for i in range(1, n): for j in range(1, n): if A[i][j] == ".": M[i][j] = min(M[i - 1][j - 1], M[i - 1][j], M[i][j - 1]) + 1 print(max(list(map(max, M))))
import sys while 1: n = eval(input()) + 1 if n == 1: break N = list(range(n)) N1 = N[1:] A = ["" * n] + [" " + input() for i in N1] M = [[0] * n for i in N] y = M[0] for i in N1: x = [0] * n B = A[i] for j in N1: if B[j] == ".": x[j] = min(y[j - 1], y[j], x[j - 1]) + 1 M[i] = x y = x print(max(list(map(max, M))))
false
38.888889
[ "- A = [\"\" * n] + [\" \" + input() for i in range(1, n)]", "- M = [[0] * n for i in range(n)]", "- for i in range(1, n):", "- for j in range(1, n):", "- if A[i][j] == \".\":", "- M[i][j] = min(M[i - 1][j - 1], M[i - 1][j], M[i][j - 1]) + 1", "+ N = list(range(n))", "+ N1 = N[1:]", "+ A = [\"\" * n] + [\" \" + input() for i in N1]", "+ M = [[0] * n for i in N]", "+ y = M[0]", "+ for i in N1:", "+ x = [0] * n", "+ B = A[i]", "+ for j in N1:", "+ if B[j] == \".\":", "+ x[j] = min(y[j - 1], y[j], x[j - 1]) + 1", "+ M[i] = x", "+ y = x" ]
false
0.128771
0.044956
2.864384
[ "s754013421", "s597638832" ]
u773265208
p02780
python
s646768605
s980424379
254
159
71,816
25,604
Accepted
Accepted
37.4
n,k = list(map(int,input().split())) p = list(map(int,input().split())) iter_num = n - k + 1 num = sum(p[0:k]) ans = [(num+k)/2] for i in range(iter_num-1): num = num - p[i] + p[k+i] ans.append((num+k)/2) print((max(ans)))
n,k = list(map(int,input().split())) p = list(map(int,input().split())) tmp = sum(p[:k]) res = tmp start = 0 end = k-1 for i in range(n-k): tmp -= p[i] tmp += p[k+i] if res < tmp: res = tmp start = i+1 end = k+i ans = 0 for i in range(start,end+1): if p[i] % 2 == 0: ans += ((p[i]+1) * (p[i] // 2)) / p[i] else: ans += (1 + p[i]//2 + (p[i]+1) * (p[i] // 2)) / p[i] print(ans)
13
23
233
425
n, k = list(map(int, input().split())) p = list(map(int, input().split())) iter_num = n - k + 1 num = sum(p[0:k]) ans = [(num + k) / 2] for i in range(iter_num - 1): num = num - p[i] + p[k + i] ans.append((num + k) / 2) print((max(ans)))
n, k = list(map(int, input().split())) p = list(map(int, input().split())) tmp = sum(p[:k]) res = tmp start = 0 end = k - 1 for i in range(n - k): tmp -= p[i] tmp += p[k + i] if res < tmp: res = tmp start = i + 1 end = k + i ans = 0 for i in range(start, end + 1): if p[i] % 2 == 0: ans += ((p[i] + 1) * (p[i] // 2)) / p[i] else: ans += (1 + p[i] // 2 + (p[i] + 1) * (p[i] // 2)) / p[i] print(ans)
false
43.478261
[ "-iter_num = n - k + 1", "-num = sum(p[0:k])", "-ans = [(num + k) / 2]", "-for i in range(iter_num - 1):", "- num = num - p[i] + p[k + i]", "- ans.append((num + k) / 2)", "-print((max(ans)))", "+tmp = sum(p[:k])", "+res = tmp", "+start = 0", "+end = k - 1", "+for i in range(n - k):", "+ tmp -= p[i]", "+ tmp += p[k + i]", "+ if res < tmp:", "+ res = tmp", "+ start = i + 1", "+ end = k + i", "+ans = 0", "+for i in range(start, end + 1):", "+ if p[i] % 2 == 0:", "+ ans += ((p[i] + 1) * (p[i] // 2)) / p[i]", "+ else:", "+ ans += (1 + p[i] // 2 + (p[i] + 1) * (p[i] // 2)) / p[i]", "+print(ans)" ]
false
0.041764
0.135522
0.308175
[ "s646768605", "s980424379" ]
u618251217
p02706
python
s241469052
s054179233
29
26
9,856
9,796
Accepted
Accepted
10.34
N,M = list(map(int, input().split())) A = list(map(int, input().split())) ans = max(N - sum(A), -1) print(ans)
N,M = list(map(int, input().split())) A = list(map(int, input().split())) print((max(-1, N - sum(A))))
5
4
109
98
N, M = list(map(int, input().split())) A = list(map(int, input().split())) ans = max(N - sum(A), -1) print(ans)
N, M = list(map(int, input().split())) A = list(map(int, input().split())) print((max(-1, N - sum(A))))
false
20
[ "-ans = max(N - sum(A), -1)", "-print(ans)", "+print((max(-1, N - sum(A))))" ]
false
0.046894
0.046548
1.007441
[ "s241469052", "s054179233" ]
u823885866
p03795
python
s241139111
s416189720
28
22
9,080
8,988
Accepted
Accepted
21.43
a=int(eval(input())) print((a*800-200*(a//15)))
a=int(eval(input())) print((a*800-a//15*200))
2
2
40
39
a = int(eval(input())) print((a * 800 - 200 * (a // 15)))
a = int(eval(input())) print((a * 800 - a // 15 * 200))
false
0
[ "-print((a * 800 - 200 * (a // 15)))", "+print((a * 800 - a // 15 * 200))" ]
false
0.046613
0.044361
1.05075
[ "s241139111", "s416189720" ]
u606045429
p02679
python
s923447286
s530746109
510
441
73,048
73,036
Accepted
Accepted
13.53
from math import gcd from collections import Counter mod = 10 ** 9 + 7 N, *AB = list(map(int, open(0).read().split())) def std(a, b): if a == 0: return (0, int(b != 0)) g = gcd(a, b) a, b = a // g, b // g return (a, b) if a > 0 else (-a, -b) C = Counter() for a, b in zip(*[iter(AB)] * 2): C[std(a, b)] += 1 ans = 1 cnt = 0 for (a, b), v in list(C.items()): if b > 0: if (b, -a) in C: ans *= -1 + pow(2, v, mod) + pow(2, C[(b, -a)], mod) ans %= mod else: cnt += v elif (-b, a) not in C: cnt += v ans *= pow(2, cnt, mod) ans += C[(0, 0)] - 1 print((ans % mod))
from math import gcd from collections import Counter mod = 10 ** 9 + 7 N, *AB = list(map(int, open(0).read().split())) def std(a, b): if a == 0: return (0, int(b != 0)) g = gcd(a, b) a, b = a // g, b // g return (a, b) if a > 0 else (-a, -b) C = Counter(std(a, b) for a, b in zip(*[iter(AB)] * 2)) ans = 1 cnt = 0 for (a, b), v in list(C.items()): if b > 0: if (b, -a) in C: ans *= -1 + pow(2, v, mod) + pow(2, C[(b, -a)], mod) ans %= mod else: cnt += v elif (-b, a) not in C: cnt += v ans *= pow(2, cnt, mod) ans += C[(0, 0)] - 1 print((ans % mod))
35
33
683
667
from math import gcd from collections import Counter mod = 10**9 + 7 N, *AB = list(map(int, open(0).read().split())) def std(a, b): if a == 0: return (0, int(b != 0)) g = gcd(a, b) a, b = a // g, b // g return (a, b) if a > 0 else (-a, -b) C = Counter() for a, b in zip(*[iter(AB)] * 2): C[std(a, b)] += 1 ans = 1 cnt = 0 for (a, b), v in list(C.items()): if b > 0: if (b, -a) in C: ans *= -1 + pow(2, v, mod) + pow(2, C[(b, -a)], mod) ans %= mod else: cnt += v elif (-b, a) not in C: cnt += v ans *= pow(2, cnt, mod) ans += C[(0, 0)] - 1 print((ans % mod))
from math import gcd from collections import Counter mod = 10**9 + 7 N, *AB = list(map(int, open(0).read().split())) def std(a, b): if a == 0: return (0, int(b != 0)) g = gcd(a, b) a, b = a // g, b // g return (a, b) if a > 0 else (-a, -b) C = Counter(std(a, b) for a, b in zip(*[iter(AB)] * 2)) ans = 1 cnt = 0 for (a, b), v in list(C.items()): if b > 0: if (b, -a) in C: ans *= -1 + pow(2, v, mod) + pow(2, C[(b, -a)], mod) ans %= mod else: cnt += v elif (-b, a) not in C: cnt += v ans *= pow(2, cnt, mod) ans += C[(0, 0)] - 1 print((ans % mod))
false
5.714286
[ "-C = Counter()", "-for a, b in zip(*[iter(AB)] * 2):", "- C[std(a, b)] += 1", "+C = Counter(std(a, b) for a, b in zip(*[iter(AB)] * 2))" ]
false
0.045293
0.115592
0.391838
[ "s923447286", "s530746109" ]
u594956556
p03612
python
s393269514
s927605532
63
57
14,008
13,880
Accepted
Accepted
9.52
n=int(eval(input())) p=list(map(int,input().split())) sousa=0 flag=True for i in range(n): if i+1==p[i]: if flag: sousa+=1 flag=False else: flag=True else: flag=True print(sousa)
n=int(eval(input())) p=list(map(int,input().split())) sousa=0 flag=False for i in range(n): if flag: flag=False continue if i+1==p[i]: sousa+=1 flag=True print(sousa)
14
12
219
191
n = int(eval(input())) p = list(map(int, input().split())) sousa = 0 flag = True for i in range(n): if i + 1 == p[i]: if flag: sousa += 1 flag = False else: flag = True else: flag = True print(sousa)
n = int(eval(input())) p = list(map(int, input().split())) sousa = 0 flag = False for i in range(n): if flag: flag = False continue if i + 1 == p[i]: sousa += 1 flag = True print(sousa)
false
14.285714
[ "-flag = True", "+flag = False", "+ if flag:", "+ flag = False", "+ continue", "- if flag:", "- sousa += 1", "- flag = False", "- else:", "- flag = True", "- else:", "+ sousa += 1" ]
false
0.046659
0.046594
1.001396
[ "s393269514", "s927605532" ]
u808427016
p03460
python
s712051102
s550033693
1,316
1,140
102,560
67,232
Accepted
Accepted
13.37
def calc(K, xyc): K2 = K * 2 N = len(xyc) p = [[0] * K2 for i in range(K2)] for x, y, c in xyc: y += c * K p[x % K2][y % K2] += 1 p[(x + K) % K2][(y + K) % K2] += 1 def isum(xs): r = 0 yield r for x in xs: r += x yield r psum = [list(isum(row)) for row in p] pksum = [[b - a for a, b in zip(row, row[K:])] for row in psum] rmax = N / 2 for y in range(K): rcount = sum(row[y] for row in pksum[:K]) for x in range(K): rmax = max(rmax, rcount, N - rcount) rcount += -pksum[x][y] + pksum[x + K][y] return rmax if __name__ == '__main__': N, K = [int(e) for e in input().split()] xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]] print((calc(K, xyc)))
def calc(K, xyc): K2 = K * 2 N = len(xyc) p = [[0] * K2 for i in range(K2)] for x, y, c in xyc: y += c * K p[x % K2][y % K2] += 1 p[(x + K) % K2][(y + K) % K2] += 1 def calcsum(xs): r = sum(xs[:K]) yield r for a, b in zip(xs[:K], xs[K:]): r += -a + b yield r pksum = [list(calcsum(xs)) for xs in p] rmax = N / 2 for y in range(K): rcount = sum(row[y] for row in pksum[:K]) for x in range(K): rmax = max(rmax, rcount, N - rcount) rcount += -pksum[x][y] + pksum[x + K][y] return rmax if __name__ == '__main__': N, K = [int(e) for e in input().split()] xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]] print((calc(K, xyc)))
33
32
882
853
def calc(K, xyc): K2 = K * 2 N = len(xyc) p = [[0] * K2 for i in range(K2)] for x, y, c in xyc: y += c * K p[x % K2][y % K2] += 1 p[(x + K) % K2][(y + K) % K2] += 1 def isum(xs): r = 0 yield r for x in xs: r += x yield r psum = [list(isum(row)) for row in p] pksum = [[b - a for a, b in zip(row, row[K:])] for row in psum] rmax = N / 2 for y in range(K): rcount = sum(row[y] for row in pksum[:K]) for x in range(K): rmax = max(rmax, rcount, N - rcount) rcount += -pksum[x][y] + pksum[x + K][y] return rmax if __name__ == "__main__": N, K = [int(e) for e in input().split()] xyc = [ (int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)] ] print((calc(K, xyc)))
def calc(K, xyc): K2 = K * 2 N = len(xyc) p = [[0] * K2 for i in range(K2)] for x, y, c in xyc: y += c * K p[x % K2][y % K2] += 1 p[(x + K) % K2][(y + K) % K2] += 1 def calcsum(xs): r = sum(xs[:K]) yield r for a, b in zip(xs[:K], xs[K:]): r += -a + b yield r pksum = [list(calcsum(xs)) for xs in p] rmax = N / 2 for y in range(K): rcount = sum(row[y] for row in pksum[:K]) for x in range(K): rmax = max(rmax, rcount, N - rcount) rcount += -pksum[x][y] + pksum[x + K][y] return rmax if __name__ == "__main__": N, K = [int(e) for e in input().split()] xyc = [ (int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)] ] print((calc(K, xyc)))
false
3.030303
[ "- def isum(xs):", "- r = 0", "+ def calcsum(xs):", "+ r = sum(xs[:K])", "- for x in xs:", "- r += x", "+ for a, b in zip(xs[:K], xs[K:]):", "+ r += -a + b", "- psum = [list(isum(row)) for row in p]", "- pksum = [[b - a for a, b in zip(row, row[K:])] for row in psum]", "+ pksum = [list(calcsum(xs)) for xs in p]" ]
false
0.040387
0.0434
0.930567
[ "s712051102", "s550033693" ]
u757274384
p03352
python
s521663723
s017765010
19
17
2,940
3,064
Accepted
Accepted
10.53
import math x = int(eval(input())) L = [] for i in range(2,int(math.floor(math.sqrt(x)))+1): for j in range(x//i + 1): if i ** j <= x: L.append(i ** j) if L == []: print("1") else: print((max(L)))
import math x = int(eval(input())) if x == 1 or x== 2 or x==3: print((1)) exit() s = math.floor(math.sqrt(x)) def l(k,p): return(int(math.floor(math.log(p)/math.log(k)))) ans = 0 for i in range(2,s+1): if i ** (1 + l(i,x)) <= x: ans = max(ans, i ** (1+l(i,x))) else: ans = max(ans, i ** l(i,x)) if ans == x: print(x) exit() print(ans)
13
22
225
383
import math x = int(eval(input())) L = [] for i in range(2, int(math.floor(math.sqrt(x))) + 1): for j in range(x // i + 1): if i**j <= x: L.append(i**j) if L == []: print("1") else: print((max(L)))
import math x = int(eval(input())) if x == 1 or x == 2 or x == 3: print((1)) exit() s = math.floor(math.sqrt(x)) def l(k, p): return int(math.floor(math.log(p) / math.log(k))) ans = 0 for i in range(2, s + 1): if i ** (1 + l(i, x)) <= x: ans = max(ans, i ** (1 + l(i, x))) else: ans = max(ans, i ** l(i, x)) if ans == x: print(x) exit() print(ans)
false
40.909091
[ "-L = []", "-for i in range(2, int(math.floor(math.sqrt(x))) + 1):", "- for j in range(x // i + 1):", "- if i**j <= x:", "- L.append(i**j)", "-if L == []:", "- print(\"1\")", "-else:", "- print((max(L)))", "+if x == 1 or x == 2 or x == 3:", "+ print((1))", "+ exit()", "+s = math.floor(math.sqrt(x))", "+", "+", "+def l(k, p):", "+ return int(math.floor(math.log(p) / math.log(k)))", "+", "+", "+ans = 0", "+for i in range(2, s + 1):", "+ if i ** (1 + l(i, x)) <= x:", "+ ans = max(ans, i ** (1 + l(i, x)))", "+ else:", "+ ans = max(ans, i ** l(i, x))", "+ if ans == x:", "+ print(x)", "+ exit()", "+print(ans)" ]
false
0.073527
0.071542
1.027756
[ "s521663723", "s017765010" ]
u145231176
p02937
python
s727262146
s407097396
370
176
72,920
88,188
Accepted
Accepted
52.43
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# def rand_letter(size): ascii_original='programing' digits_original='01' digits='0123456789' ascii_lowercase='abcdefghijklmnopqrstuvwxyz' ascii_uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # 好きなものを使ってね psuedo = ascii_original return ''.join([random.choice(psuedo) for i in range(size)]) S = eval(input()) N_S = len(S) T = eval(input()) N_T = len(T) dict_s = defaultdict(int) dict_order = defaultdict(list) for i in range(N_S): dict_s[S[i]] += 1 dict_order[S[i]].append(i + 1) dict_t = defaultdict(int) for i in range(N_T): dict_t[T[i]] += 1 flag = True for i in dict_t: if dict_s[i] == 0: flag = False break if not flag: print((-1)) exit() now = dict_order[T[0]][0] ans = [dict_order[T[0]][0]] for i in range(1, N_T): index = bisect_right(dict_order[T[i]], now) if index == len(dict_order[T[i]]): now = dict_order[T[i]][0] else: now = dict_order[T[i]][index] ans.append(now) cnt = 0 for i in range(1, N_T): if ans[i] <= ans[i - 1]: cnt += 1 print((cnt * N_S + ans[-1]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# s = eval(input()) t = eval(input()) # 各文字について p = {c: [] for c in s} for i in range(len(s)): p[s[i]].append(i) z = 0 l = -1 for c in t: if c not in p: print((-1)) break # 文字cのうちもっとも近い未来にあるもの x = bisect_right(p[c], l) # 一周するなら if x == len(p[c]): x = 0 z += 1 l = p[c][x] else: print((z * len(s) + l + 1))
108
75
2,438
1,683
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# def rand_letter(size): ascii_original = "programing" digits_original = "01" digits = "0123456789" ascii_lowercase = "abcdefghijklmnopqrstuvwxyz" ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # 好きなものを使ってね psuedo = ascii_original return "".join([random.choice(psuedo) for i in range(size)]) S = eval(input()) N_S = len(S) T = eval(input()) N_T = len(T) dict_s = defaultdict(int) dict_order = defaultdict(list) for i in range(N_S): dict_s[S[i]] += 1 dict_order[S[i]].append(i + 1) dict_t = defaultdict(int) for i in range(N_T): dict_t[T[i]] += 1 flag = True for i in dict_t: if dict_s[i] == 0: flag = False break if not flag: print((-1)) exit() now = dict_order[T[0]][0] ans = [dict_order[T[0]][0]] for i in range(1, N_T): index = bisect_right(dict_order[T[i]], now) if index == len(dict_order[T[i]]): now = dict_order[T[i]][0] else: now = dict_order[T[i]][index] ans.append(now) cnt = 0 for i in range(1, N_T): if ans[i] <= ans[i - 1]: cnt += 1 print((cnt * N_S + ans[-1]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# s = eval(input()) t = eval(input()) # 各文字について p = {c: [] for c in s} for i in range(len(s)): p[s[i]].append(i) z = 0 l = -1 for c in t: if c not in p: print((-1)) break # 文字cのうちもっとも近い未来にあるもの x = bisect_right(p[c], l) # 一周するなら if x == len(p[c]): x = 0 z += 1 l = p[c][x] else: print((z * len(s) + l + 1))
false
30.555556
[ "-def rand_letter(size):", "- ascii_original = \"programing\"", "- digits_original = \"01\"", "- digits = \"0123456789\"", "- ascii_lowercase = \"abcdefghijklmnopqrstuvwxyz\"", "- ascii_uppercase = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"", "- # 好きなものを使ってね", "- psuedo = ascii_original", "- return \"\".join([random.choice(psuedo) for i in range(size)])", "-", "-", "-S = eval(input())", "-N_S = len(S)", "-T = eval(input())", "-N_T = len(T)", "-dict_s = defaultdict(int)", "-dict_order = defaultdict(list)", "-for i in range(N_S):", "- dict_s[S[i]] += 1", "- dict_order[S[i]].append(i + 1)", "-dict_t = defaultdict(int)", "-for i in range(N_T):", "- dict_t[T[i]] += 1", "-flag = True", "-for i in dict_t:", "- if dict_s[i] == 0:", "- flag = False", "+s = eval(input())", "+t = eval(input())", "+# 各文字について", "+p = {c: [] for c in s}", "+for i in range(len(s)):", "+ p[s[i]].append(i)", "+z = 0", "+l = -1", "+for c in t:", "+ if c not in p:", "+ print((-1))", "-if not flag:", "- print((-1))", "- exit()", "-now = dict_order[T[0]][0]", "-ans = [dict_order[T[0]][0]]", "-for i in range(1, N_T):", "- index = bisect_right(dict_order[T[i]], now)", "- if index == len(dict_order[T[i]]):", "- now = dict_order[T[i]][0]", "- else:", "- now = dict_order[T[i]][index]", "- ans.append(now)", "-cnt = 0", "-for i in range(1, N_T):", "- if ans[i] <= ans[i - 1]:", "- cnt += 1", "-print((cnt * N_S + ans[-1]))", "+ # 文字cのうちもっとも近い未来にあるもの", "+ x = bisect_right(p[c], l)", "+ # 一周するなら", "+ if x == len(p[c]):", "+ x = 0", "+ z += 1", "+ l = p[c][x]", "+else:", "+ print((z * len(s) + l + 1))" ]
false
0.042867
0.047239
0.907454
[ "s727262146", "s407097396" ]
u133936772
p03408
python
s300621871
s193059114
20
17
3,060
2,940
Accepted
Accepted
15
d = {'':0} for i in (1,-1): for _ in range(int(eval(input()))): s = eval(input()) d[s] = d.get(s,0)+i print((max(d.values())))
d={0:0} for i in (1,-1): for _ in [0]*int(eval(input())):s=eval(input());d[s]=d.get(s,0)+i print((max(d.values())))
6
4
127
106
d = {"": 0} for i in (1, -1): for _ in range(int(eval(input()))): s = eval(input()) d[s] = d.get(s, 0) + i print((max(d.values())))
d = {0: 0} for i in (1, -1): for _ in [0] * int(eval(input())): s = eval(input()) d[s] = d.get(s, 0) + i print((max(d.values())))
false
33.333333
[ "-d = {\"\": 0}", "+d = {0: 0}", "- for _ in range(int(eval(input()))):", "+ for _ in [0] * int(eval(input())):" ]
false
0.044107
0.043035
1.024892
[ "s300621871", "s193059114" ]
u652155485
p02792
python
s932978338
s799124551
71
64
32,668
32,668
Accepted
Accepted
9.86
mod = 1e9+7 def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): m = {} N = int(input()) for i in range(1, N+1): s = str(i) first = s[0] last = s[-1] key = first + last m[key] = m.get(key, 0) + 1 ans = 0 #print(m) for key1 in m: for key2 in m: #if key1 == key2: # continue if key1[0] == key2[1] and key1[1] == key2[0]: ans += m[key1] * m[key2] print(ans) main()
mod = 1e9+7 def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): m = {} N = int(input()) for i in range(1, N+1): s = str(i) first = s[0] last = s[-1] key = first + last m[key] = m.get(key, 0) + 1 ans = 0 #print(m) for k in m: if k[0] == k[1]: ans += m[k] * m[k] else: swap = k[1] + k[0] ans += m[k] * m.get(swap, 0) """ for key1 in m: for key2 in m: #if key1 == key2: # continue if key1[0] == key2[1] and key1[1] == key2[0]: ans += m[key1] * m[key2] """ print(ans) main()
35
42
607
783
mod = 1e9 + 7 def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): m = {} N = int(input()) for i in range(1, N + 1): s = str(i) first = s[0] last = s[-1] key = first + last m[key] = m.get(key, 0) + 1 ans = 0 # print(m) for key1 in m: for key2 in m: # if key1 == key2: # continue if key1[0] == key2[1] and key1[1] == key2[0]: ans += m[key1] * m[key2] print(ans) main()
mod = 1e9 + 7 def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): m = {} N = int(input()) for i in range(1, N + 1): s = str(i) first = s[0] last = s[-1] key = first + last m[key] = m.get(key, 0) + 1 ans = 0 # print(m) for k in m: if k[0] == k[1]: ans += m[k] * m[k] else: swap = k[1] + k[0] ans += m[k] * m.get(swap, 0) """ for key1 in m: for key2 in m: #if key1 == key2: # continue if key1[0] == key2[1] and key1[1] == key2[0]: ans += m[key1] * m[key2] """ print(ans) main()
false
16.666667
[ "+ for k in m:", "+ if k[0] == k[1]:", "+ ans += m[k] * m[k]", "+ else:", "+ swap = k[1] + k[0]", "+ ans += m[k] * m.get(swap, 0)", "+ \"\"\"", "- # if key1 == key2:", "+ #if key1 == key2:", "+ \"\"\"" ]
false
0.060335
0.044031
1.370272
[ "s932978338", "s799124551" ]
u143492911
p03721
python
s139731113
s239956188
479
442
27,872
29,144
Accepted
Accepted
7.72
n,k=list(map(int,input().split())) num=[list(map(int,input().split()))for _ in range(n)] p=0 num.sort() for i in range(n): p+=num[i][1] if k<=p: ans=num[i][0] print(ans) exit()
n,k=list(map(int,input().split())) a=[list(map(int,input().split()))for i in range(n)] a.sort(key=lambda x:x[0]) count=0 for i,j in a: count+=j if k<=count: print(i) exit()
10
9
212
198
n, k = list(map(int, input().split())) num = [list(map(int, input().split())) for _ in range(n)] p = 0 num.sort() for i in range(n): p += num[i][1] if k <= p: ans = num[i][0] print(ans) exit()
n, k = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(n)] a.sort(key=lambda x: x[0]) count = 0 for i, j in a: count += j if k <= count: print(i) exit()
false
10
[ "-num = [list(map(int, input().split())) for _ in range(n)]", "-p = 0", "-num.sort()", "-for i in range(n):", "- p += num[i][1]", "- if k <= p:", "- ans = num[i][0]", "- print(ans)", "+a = [list(map(int, input().split())) for i in range(n)]", "+a.sort(key=lambda x: x[0])", "+count = 0", "+for i, j in a:", "+ count += j", "+ if k <= count:", "+ print(i)" ]
false
0.106447
0.076579
1.390035
[ "s139731113", "s239956188" ]
u727801592
p03486
python
s777098523
s562147843
19
17
3,188
3,064
Accepted
Accepted
10.53
n=eval(input()) m=eval(input()) alphabet={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26} a=[] for i in range(len(n)): a.append(alphabet[n[i]]) a.sort() b=[] for i in range(len(m)): b.append(alphabet[m[i]]) b.sort(reverse=True) for i in range(min(len(n),len(m))): if a[i]<b[i]: print('Yes') exit() if len(n)<len(m): for i in range(len(n)): if a[i]>b[i]: print('No') exit() print('Yes') exit() print('No')
n=sorted(eval(input())) m=sorted(eval(input()),reverse=True) if n<m: print('Yes') else: print('No')
24
6
578
96
n = eval(input()) m = eval(input()) alphabet = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, } a = [] for i in range(len(n)): a.append(alphabet[n[i]]) a.sort() b = [] for i in range(len(m)): b.append(alphabet[m[i]]) b.sort(reverse=True) for i in range(min(len(n), len(m))): if a[i] < b[i]: print("Yes") exit() if len(n) < len(m): for i in range(len(n)): if a[i] > b[i]: print("No") exit() print("Yes") exit() print("No")
n = sorted(eval(input())) m = sorted(eval(input()), reverse=True) if n < m: print("Yes") else: print("No")
false
75
[ "-n = eval(input())", "-m = eval(input())", "-alphabet = {", "- \"a\": 1,", "- \"b\": 2,", "- \"c\": 3,", "- \"d\": 4,", "- \"e\": 5,", "- \"f\": 6,", "- \"g\": 7,", "- \"h\": 8,", "- \"i\": 9,", "- \"j\": 10,", "- \"k\": 11,", "- \"l\": 12,", "- \"m\": 13,", "- \"n\": 14,", "- \"o\": 15,", "- \"p\": 16,", "- \"q\": 17,", "- \"r\": 18,", "- \"s\": 19,", "- \"t\": 20,", "- \"u\": 21,", "- \"v\": 22,", "- \"w\": 23,", "- \"x\": 24,", "- \"y\": 25,", "- \"z\": 26,", "-}", "-a = []", "-for i in range(len(n)):", "- a.append(alphabet[n[i]])", "-a.sort()", "-b = []", "-for i in range(len(m)):", "- b.append(alphabet[m[i]])", "-b.sort(reverse=True)", "-for i in range(min(len(n), len(m))):", "- if a[i] < b[i]:", "- print(\"Yes\")", "- exit()", "-if len(n) < len(m):", "- for i in range(len(n)):", "- if a[i] > b[i]:", "- print(\"No\")", "- exit()", "+n = sorted(eval(input()))", "+m = sorted(eval(input()), reverse=True)", "+if n < m:", "- exit()", "-print(\"No\")", "+else:", "+ print(\"No\")" ]
false
0.040298
0.049121
0.820374
[ "s777098523", "s562147843" ]
u137228327
p03261
python
s727935577
s605892763
32
29
9,332
9,024
Accepted
Accepted
9.38
from collections import Counter import sys N = int(eval(input())) lst = [str(eval(input())) for _ in range(N)] #print(lst) c = Counter(lst) for i in c: if lst.count(i) > 1: print('No') sys.exit() for i in range(len(lst)-1): if lst[i][-1] != lst[i+1][0]: print('No') sys.exit() print('Yes')
import sys N = int(eval(input())) lst = [str(eval(input())) for _ in range(N)] if len(set(lst)) != N: print('No') sys.exit() for i in range(len(lst)-1): if lst[i][-1] != lst[i+1][0]: print('No') sys.exit() print('Yes')
16
14
333
250
from collections import Counter import sys N = int(eval(input())) lst = [str(eval(input())) for _ in range(N)] # print(lst) c = Counter(lst) for i in c: if lst.count(i) > 1: print("No") sys.exit() for i in range(len(lst) - 1): if lst[i][-1] != lst[i + 1][0]: print("No") sys.exit() print("Yes")
import sys N = int(eval(input())) lst = [str(eval(input())) for _ in range(N)] if len(set(lst)) != N: print("No") sys.exit() for i in range(len(lst) - 1): if lst[i][-1] != lst[i + 1][0]: print("No") sys.exit() print("Yes")
false
12.5
[ "-from collections import Counter", "-# print(lst)", "-c = Counter(lst)", "-for i in c:", "- if lst.count(i) > 1:", "- print(\"No\")", "- sys.exit()", "+if len(set(lst)) != N:", "+ print(\"No\")", "+ sys.exit()" ]
false
0.14551
0.098155
1.482442
[ "s727935577", "s605892763" ]
u179169725
p02609
python
s151672485
s066993514
401
370
97,068
125,776
Accepted
Accepted
7.73
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce # 各クエリO(1) # 求めたいのは0になるまでの回数 # 事前に1 - 2*10**5まで、になった回数を記録しておくとか? (小さい方の数は必ずわかっている) (あまりがbit超で10**5を超えないのはわかっている) # これがクリアされても 2**(2*10**5)の数字であまりが取れない問題がある # 一回割ってしまえばこっちのもんよ N = a_int() X = read()[:-1] px0 = X.count('1') px0p = px0 + 1 px0n = (px0 - 1) if px0 != 1 else -1 # 上から、px0-1, px0, px0+1で割ったもの x0n = 0 x0 = 0 x0p = 0 for i, bit in enu(reversed(X)): if bit == '1': x0n += pow(2, i, px0n) x0n %= px0n x0 += pow(2, i, px0) x0 %= px0 x0p += pow(2, i, px0p) x0p %= px0p x0 = [x0n, x0, x0p] # px0-1, px0, px0+1で割ったもの first_mod = [] # 後ろから順番に1回だけ操作を行ったときの数字(Xi % popcount(Xi)) for i, bit in enumerate(reversed(X)): if bit == '0': # 1に反転する first_mod.append((x0[2] + pow(2, i, px0p)) % (px0p)) elif bit == '1': if px0n != -1: first_mod.append((x0[0] - pow(2, i, px0n)) % (px0n)) else: first_mod.append(-1) # print(first_mod[::-1], sep='\n') # これが違うぞーなんでだ # これは必ずpx0+-1よりも小さいので、事前に対応表を作っておけばすぐに求められる(それとも求めなくてもいいか?)(logがつくからしなくても良さそう) ans = [] for x in reversed(first_mod): if x == -1: ans.append(0) continue cnt = 1 # すでに一回操作しているので while x != 0: x = x % bin(x).count('1') cnt += 1 ans.append(cnt) print(*ans, sep='\n')
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return list(map(int, readline().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b N = a_int() X = read()[:-1] tmp = X.count('1') # Xの1の数 X = list(map(int, list(X[::-1]))) # オリジナルをpop(X)+-1で割ったものを作っておく Xmodpop = [0, 0, 0] for i, x in enumerate(X): if x: Xmodpop[1] += pow(2, i, tmp + 1) if tmp != 1: Xmodpop[-1] += pow(2, i, tmp - 1) Xmodpop[1] %= tmp + 1 if tmp != 1: Xmodpop[-1] %= tmp - 1 X_nex = [] # 一度操作したあとの値 for i in range(N): if X[i] == 1: if tmp == 1: X_nex.append(-1) continue X_nex.append((Xmodpop[-1] - pow(2, i, tmp - 1)) % (tmp - 1)) else: X_nex.append((Xmodpop[1] + pow(2, i, tmp + 1)) % (tmp + 1)) # 愚直に操作 ans = [] for i in range(N): n = X_nex[i] if n == -1: ans.append(0) continue cnt = 1 while n: popc = bin(n).count('1') n %= popc cnt += 1 ans.append(cnt) print(*ans[::-1], sep='\n')
115
109
2,740
2,479
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_matrix(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce # 各クエリO(1) # 求めたいのは0になるまでの回数 # 事前に1 - 2*10**5まで、になった回数を記録しておくとか? (小さい方の数は必ずわかっている) (あまりがbit超で10**5を超えないのはわかっている) # これがクリアされても 2**(2*10**5)の数字であまりが取れない問題がある # 一回割ってしまえばこっちのもんよ N = a_int() X = read()[:-1] px0 = X.count("1") px0p = px0 + 1 px0n = (px0 - 1) if px0 != 1 else -1 # 上から、px0-1, px0, px0+1で割ったもの x0n = 0 x0 = 0 x0p = 0 for i, bit in enu(reversed(X)): if bit == "1": x0n += pow(2, i, px0n) x0n %= px0n x0 += pow(2, i, px0) x0 %= px0 x0p += pow(2, i, px0p) x0p %= px0p x0 = [x0n, x0, x0p] # px0-1, px0, px0+1で割ったもの first_mod = [] # 後ろから順番に1回だけ操作を行ったときの数字(Xi % popcount(Xi)) for i, bit in enumerate(reversed(X)): if bit == "0": # 1に反転する first_mod.append((x0[2] + pow(2, i, px0p)) % (px0p)) elif bit == "1": if px0n != -1: first_mod.append((x0[0] - pow(2, i, px0n)) % (px0n)) else: first_mod.append(-1) # print(first_mod[::-1], sep='\n') # これが違うぞーなんでだ # これは必ずpx0+-1よりも小さいので、事前に対応表を作っておけばすぐに求められる(それとも求めなくてもいいか?)(logがつくからしなくても良さそう) ans = [] for x in reversed(first_mod): if x == -1: ans.append(0) continue cnt = 1 # すでに一回操作しているので while x != 0: x = x % bin(x).count("1") cnt += 1 ans.append(cnt) print(*ans, sep="\n")
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return list(map(int, readline().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret def read_matrix(H): """H is number of rows""" ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b N = a_int() X = read()[:-1] tmp = X.count("1") # Xの1の数 X = list(map(int, list(X[::-1]))) # オリジナルをpop(X)+-1で割ったものを作っておく Xmodpop = [0, 0, 0] for i, x in enumerate(X): if x: Xmodpop[1] += pow(2, i, tmp + 1) if tmp != 1: Xmodpop[-1] += pow(2, i, tmp - 1) Xmodpop[1] %= tmp + 1 if tmp != 1: Xmodpop[-1] %= tmp - 1 X_nex = [] # 一度操作したあとの値 for i in range(N): if X[i] == 1: if tmp == 1: X_nex.append(-1) continue X_nex.append((Xmodpop[-1] - pow(2, i, tmp - 1)) % (tmp - 1)) else: X_nex.append((Xmodpop[1] + pow(2, i, tmp + 1)) % (tmp + 1)) # 愚直に操作 ans = [] for i in range(N): n = X_nex[i] if n == -1: ans.append(0) continue cnt = 1 while n: popc = bin(n).count("1") n %= popc cnt += 1 ans.append(cnt) print(*ans[::-1], sep="\n")
false
5.217391
[ "-read = sys.stdin.readline", "+readline = sys.stdin.buffer.readline", "+read = sys.stdin.readline # 文字列読み込む時はこっち", "- return int(read())", "+ return int(readline())", "- return list(map(int, read().split()))", "+ return list(map(int, readline().split()))", "- ret.append(list(map(int, read().split())))", "+ ret.append(list(map(int, readline().split())))", "- ret.append(tuple(map(int, read().split())))", "+ ret.append(tuple(map(int, readline().split())))", "- ret.append(list(map(int, read().split())))", "+ ret.append(list(map(int, readline().split())))", "+from math import gcd", "-# 各クエリO(1)", "-# 求めたいのは0になるまでの回数", "-# 事前に1 - 2*10**5まで、になった回数を記録しておくとか? (小さい方の数は必ずわかっている) (あまりがbit超で10**5を超えないのはわかっている)", "-# これがクリアされても 2**(2*10**5)の数字であまりが取れない問題がある", "-# 一回割ってしまえばこっちのもんよ", "+", "+def lcm(a, b):", "+ # 最小公倍数", "+ g = gcd(a, b)", "+ return a // g * b", "+", "+", "-px0 = X.count(\"1\")", "-px0p = px0 + 1", "-px0n = (px0 - 1) if px0 != 1 else -1", "-# 上から、px0-1, px0, px0+1で割ったもの", "-x0n = 0", "-x0 = 0", "-x0p = 0", "-for i, bit in enu(reversed(X)):", "- if bit == \"1\":", "- x0n += pow(2, i, px0n)", "- x0n %= px0n", "- x0 += pow(2, i, px0)", "- x0 %= px0", "- x0p += pow(2, i, px0p)", "- x0p %= px0p", "-x0 = [x0n, x0, x0p] # px0-1, px0, px0+1で割ったもの", "-first_mod = [] # 後ろから順番に1回だけ操作を行ったときの数字(Xi % popcount(Xi))", "-for i, bit in enumerate(reversed(X)):", "- if bit == \"0\":", "- # 1に反転する", "- first_mod.append((x0[2] + pow(2, i, px0p)) % (px0p))", "- elif bit == \"1\":", "- if px0n != -1:", "- first_mod.append((x0[0] - pow(2, i, px0n)) % (px0n))", "- else:", "- first_mod.append(-1)", "-# print(first_mod[::-1], sep='\\n') # これが違うぞーなんでだ", "-# これは必ずpx0+-1よりも小さいので、事前に対応表を作っておけばすぐに求められる(それとも求めなくてもいいか?)(logがつくからしなくても良さそう)", "+tmp = X.count(\"1\") # Xの1の数", "+X = list(map(int, list(X[::-1])))", "+# オリジナルをpop(X)+-1で割ったものを作っておく", "+Xmodpop = [0, 0, 0]", "+for i, x in enumerate(X):", "+ if x:", "+ Xmodpop[1] += pow(2, i, tmp + 1)", "+ if tmp != 1:", "+ Xmodpop[-1] += pow(2, i, tmp - 1)", "+Xmodpop[1] %= tmp + 1", "+if tmp != 1:", "+ Xmodpop[-1] %= tmp - 1", "+X_nex = [] # 一度操作したあとの値", "+for i in range(N):", "+ if X[i] == 1:", "+ if tmp == 1:", "+ X_nex.append(-1)", "+ continue", "+ X_nex.append((Xmodpop[-1] - pow(2, i, tmp - 1)) % (tmp - 1))", "+ else:", "+ X_nex.append((Xmodpop[1] + pow(2, i, tmp + 1)) % (tmp + 1))", "+# 愚直に操作", "-for x in reversed(first_mod):", "- if x == -1:", "+for i in range(N):", "+ n = X_nex[i]", "+ if n == -1:", "- cnt = 1 # すでに一回操作しているので", "- while x != 0:", "- x = x % bin(x).count(\"1\")", "+ cnt = 1", "+ while n:", "+ popc = bin(n).count(\"1\")", "+ n %= popc", "-print(*ans, sep=\"\\n\")", "+print(*ans[::-1], sep=\"\\n\")" ]
false
0.038997
0.047802
0.815792
[ "s151672485", "s066993514" ]
u476435125
p03818
python
s848478279
s619302212
70
57
18,272
17,396
Accepted
Accepted
18.57
N=int(eval(input())) la=list(map(int,input().split())) da={} for ll in la: if not ll in da: da[ll]=1 elif da[ll]==1: da[ll]=2 else: da[ll]=1 nev=0 for dd in da: if da[dd]==2: nev+=1 if nev%2==0: print((len(da))) else: print((len(da)-1))
N=int(eval(input())) la=list(map(int,input().split())) da={} for ll in la: if not ll in da: da[ll]=1 if (N-len(da))%2==0: print((len(da))) else: print((len(da)-1))
18
10
300
183
N = int(eval(input())) la = list(map(int, input().split())) da = {} for ll in la: if not ll in da: da[ll] = 1 elif da[ll] == 1: da[ll] = 2 else: da[ll] = 1 nev = 0 for dd in da: if da[dd] == 2: nev += 1 if nev % 2 == 0: print((len(da))) else: print((len(da) - 1))
N = int(eval(input())) la = list(map(int, input().split())) da = {} for ll in la: if not ll in da: da[ll] = 1 if (N - len(da)) % 2 == 0: print((len(da))) else: print((len(da) - 1))
false
44.444444
[ "- elif da[ll] == 1:", "- da[ll] = 2", "- else:", "- da[ll] = 1", "-nev = 0", "-for dd in da:", "- if da[dd] == 2:", "- nev += 1", "-if nev % 2 == 0:", "+if (N - len(da)) % 2 == 0:" ]
false
0.039029
0.040848
0.955457
[ "s848478279", "s619302212" ]
u345966487
p03160
python
s337827604
s917479813
234
210
50,288
51,696
Accepted
Accepted
10.26
import sys f = sys.stdin n = int(f.readline()) h = list(map(int, f.readline().split())) dp = [0]*n dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
import sys import io f = sys.stdin.buffer n = int(f.readline()) h = list(map(int, f.readline().split())) p0, p1 = 0, abs(h[1] - h[0]) for i in range(2, n): p2 = min(p1 + abs(h[i] - h[i - 1]), p0 + abs(h[i] - h[i - 2])) p0, p1 = p1, p2 print(p1)
9
11
252
264
import sys f = sys.stdin n = int(f.readline()) h = list(map(int, f.readline().split())) dp = [0] * n dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
import sys import io f = sys.stdin.buffer n = int(f.readline()) h = list(map(int, f.readline().split())) p0, p1 = 0, abs(h[1] - h[0]) for i in range(2, n): p2 = min(p1 + abs(h[i] - h[i - 1]), p0 + abs(h[i] - h[i - 2])) p0, p1 = p1, p2 print(p1)
false
18.181818
[ "+import io", "-f = sys.stdin", "+f = sys.stdin.buffer", "-dp = [0] * n", "-dp[1] = abs(h[1] - h[0])", "+p0, p1 = 0, abs(h[1] - h[0])", "- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))", "-print((dp[-1]))", "+ p2 = min(p1 + abs(h[i] - h[i - 1]), p0 + abs(h[i] - h[i - 2]))", "+ p0, p1 = p1, p2", "+print(p1)" ]
false
0.07204
0.038366
1.877698
[ "s337827604", "s917479813" ]
u130900604
p02713
python
s641765920
s675612452
493
82
68,240
71,936
Accepted
Accepted
83.37
from math import gcd k=int(eval(input())) ans=0 for a in range(1,k+1): for b in range(1,k+1): for c in range(1,k+1): ans+=gcd(gcd(a,b),c) print(ans)
from math import gcd from collections import Counter k=int(eval(input())) t=[] for a in range(1,k+1): for b in range(1,k+1): t.append(gcd(a,b)) t=Counter(t) ans=0 for d,e in list(t.items()): for c in range(1,k+1): g=gcd(c,d) ans+=g*e print(ans)
8
14
161
268
from math import gcd k = int(eval(input())) ans = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): ans += gcd(gcd(a, b), c) print(ans)
from math import gcd from collections import Counter k = int(eval(input())) t = [] for a in range(1, k + 1): for b in range(1, k + 1): t.append(gcd(a, b)) t = Counter(t) ans = 0 for d, e in list(t.items()): for c in range(1, k + 1): g = gcd(c, d) ans += g * e print(ans)
false
42.857143
[ "+from collections import Counter", "-ans = 0", "+t = []", "- for c in range(1, k + 1):", "- ans += gcd(gcd(a, b), c)", "+ t.append(gcd(a, b))", "+t = Counter(t)", "+ans = 0", "+for d, e in list(t.items()):", "+ for c in range(1, k + 1):", "+ g = gcd(c, d)", "+ ans += g * e" ]
false
0.169301
0.039621
4.27301
[ "s641765920", "s675612452" ]
u716530146
p03103
python
s960083746
s187180228
721
404
61,528
57,180
Accepted
Accepted
43.97
#!/anaconda3/bin/python n,m=list(map(int,input().split())) ab=[tuple(map(int,input().split())) for i in range(n)] money=0 ab.sort(key=lambda tup:tup[0]) for a,b in ab: if m-b>0: money+=a*b m-=b else: money+=a*m break print(money)
#!/usr/bin/env python3 import sys, math, itertools, heapq, collections, bisect, string input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.setrecursionlimit(10**7) inf = float('inf') mod = 10**9+7 ans = 0 ;count = 0 ;pro = 1 n,m=list(map(int,input().split())) AB=[tuple(map(int,input().split())) for i in range(n)] AB.sort(key=lambda tup:tup[0]) i=0 while count<m: ans+=min(m-count,AB[i][1])*AB[i][0] count += min(m-count, AB[i][1]) i+=1 print(ans)
14
20
286
503
#!/anaconda3/bin/python n, m = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for i in range(n)] money = 0 ab.sort(key=lambda tup: tup[0]) for a, b in ab: if m - b > 0: money += a * b m -= b else: money += a * m break print(money)
#!/usr/bin/env python3 import sys, math, itertools, heapq, collections, bisect, string input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") sys.setrecursionlimit(10**7) inf = float("inf") mod = 10**9 + 7 ans = 0 count = 0 pro = 1 n, m = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for i in range(n)] AB.sort(key=lambda tup: tup[0]) i = 0 while count < m: ans += min(m - count, AB[i][1]) * AB[i][0] count += min(m - count, AB[i][1]) i += 1 print(ans)
false
30
[ "-#!/anaconda3/bin/python", "+#!/usr/bin/env python3", "+import sys, math, itertools, heapq, collections, bisect, string", "+", "+input = lambda: sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "+sys.setrecursionlimit(10**7)", "+inf = float(\"inf\")", "+mod = 10**9 + 7", "+ans = 0", "+count = 0", "+pro = 1", "-ab = [tuple(map(int, input().split())) for i in range(n)]", "-money = 0", "-ab.sort(key=lambda tup: tup[0])", "-for a, b in ab:", "- if m - b > 0:", "- money += a * b", "- m -= b", "- else:", "- money += a * m", "- break", "-print(money)", "+AB = [tuple(map(int, input().split())) for i in range(n)]", "+AB.sort(key=lambda tup: tup[0])", "+i = 0", "+while count < m:", "+ ans += min(m - count, AB[i][1]) * AB[i][0]", "+ count += min(m - count, AB[i][1])", "+ i += 1", "+print(ans)" ]
false
0.056106
0.099358
0.564684
[ "s960083746", "s187180228" ]
u620084012
p03069
python
s551097168
s291280120
248
205
13,032
56,268
Accepted
Accepted
17.34
N = int(eval(input())) S = eval(input()) t = S.count(".") if t == N or t == 0: print((0)) exit(0) W = [0 for k in range(N+1)] B = [0 for k in range(N+1)] for k in range(N): if S[k] == "#": B[k] = B[k-1] + 1 else: B[k] = B[k-1] W[0] = t for k in range(N): if S[k] == ".": W[k+1] = W[k] - 1 else: W[k+1] = W[k] ans = N for k in range(N): ans = min(ans,W[k+1]+B[k]) print((min(ans,t,S.count("#"))))
n = int(eval(input())) s = eval(input()) b = [0 for k in range(n+1)] c = 0 for k in range(n): if s[k] == "#": c += 1 b[k+1] = c w = [0 for k in range(n+1)] c = 0 for k in range(n): if s[-k-1] == ".": c += 1 w[-k-2] = c ans = 10**9 for k in range(n+1): ans = min(ans,b[k]+w[k]) print(ans)
26
22
467
337
N = int(eval(input())) S = eval(input()) t = S.count(".") if t == N or t == 0: print((0)) exit(0) W = [0 for k in range(N + 1)] B = [0 for k in range(N + 1)] for k in range(N): if S[k] == "#": B[k] = B[k - 1] + 1 else: B[k] = B[k - 1] W[0] = t for k in range(N): if S[k] == ".": W[k + 1] = W[k] - 1 else: W[k + 1] = W[k] ans = N for k in range(N): ans = min(ans, W[k + 1] + B[k]) print((min(ans, t, S.count("#"))))
n = int(eval(input())) s = eval(input()) b = [0 for k in range(n + 1)] c = 0 for k in range(n): if s[k] == "#": c += 1 b[k + 1] = c w = [0 for k in range(n + 1)] c = 0 for k in range(n): if s[-k - 1] == ".": c += 1 w[-k - 2] = c ans = 10**9 for k in range(n + 1): ans = min(ans, b[k] + w[k]) print(ans)
false
15.384615
[ "-N = int(eval(input()))", "-S = eval(input())", "-t = S.count(\".\")", "-if t == N or t == 0:", "- print((0))", "- exit(0)", "-W = [0 for k in range(N + 1)]", "-B = [0 for k in range(N + 1)]", "-for k in range(N):", "- if S[k] == \"#\":", "- B[k] = B[k - 1] + 1", "- else:", "- B[k] = B[k - 1]", "-W[0] = t", "-for k in range(N):", "- if S[k] == \".\":", "- W[k + 1] = W[k] - 1", "- else:", "- W[k + 1] = W[k]", "-ans = N", "-for k in range(N):", "- ans = min(ans, W[k + 1] + B[k])", "-print((min(ans, t, S.count(\"#\"))))", "+n = int(eval(input()))", "+s = eval(input())", "+b = [0 for k in range(n + 1)]", "+c = 0", "+for k in range(n):", "+ if s[k] == \"#\":", "+ c += 1", "+ b[k + 1] = c", "+w = [0 for k in range(n + 1)]", "+c = 0", "+for k in range(n):", "+ if s[-k - 1] == \".\":", "+ c += 1", "+ w[-k - 2] = c", "+ans = 10**9", "+for k in range(n + 1):", "+ ans = min(ans, b[k] + w[k])", "+print(ans)" ]
false
0.113444
0.040039
2.833326
[ "s551097168", "s291280120" ]
u761320129
p02781
python
s198167995
s637669404
464
22
3,188
3,064
Accepted
Accepted
95.26
N = int(eval(input())) K = int(eval(input())) def solve(n,k): if k==0: return 1 if n < 10: return n if k==1 else 0 if n < 100 and k == 3: return 0 m,d = divmod(n,10) ret = d * solve(m,k-1) ret += (9-d)*solve(m-1,k-1) ret += solve(m,k) return ret print((solve(N,K)))
N = eval(input()) L = len(N) K = int(eval(input())) dp = [[[0]*2 for _ in range(K+1)] for _ in range(L+1)] dp[0][0][0] = 1 for i,c in enumerate(N): c = int(c) for k in range(K+1): for less in range(2): for d in range(10): nk = k + (d>0) if nk > K: continue if less == 0 and d > c: continue nxless = not(less==0 and d==c) dp[i+1][nk][nxless] += dp[i][k][less] print((sum(dp[-1][-1])))
16
17
316
494
N = int(eval(input())) K = int(eval(input())) def solve(n, k): if k == 0: return 1 if n < 10: return n if k == 1 else 0 if n < 100 and k == 3: return 0 m, d = divmod(n, 10) ret = d * solve(m, k - 1) ret += (9 - d) * solve(m - 1, k - 1) ret += solve(m, k) return ret print((solve(N, K)))
N = eval(input()) L = len(N) K = int(eval(input())) dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(L + 1)] dp[0][0][0] = 1 for i, c in enumerate(N): c = int(c) for k in range(K + 1): for less in range(2): for d in range(10): nk = k + (d > 0) if nk > K: continue if less == 0 and d > c: continue nxless = not (less == 0 and d == c) dp[i + 1][nk][nxless] += dp[i][k][less] print((sum(dp[-1][-1])))
false
5.882353
[ "-N = int(eval(input()))", "+N = eval(input())", "+L = len(N)", "-", "-", "-def solve(n, k):", "- if k == 0:", "- return 1", "- if n < 10:", "- return n if k == 1 else 0", "- if n < 100 and k == 3:", "- return 0", "- m, d = divmod(n, 10)", "- ret = d * solve(m, k - 1)", "- ret += (9 - d) * solve(m - 1, k - 1)", "- ret += solve(m, k)", "- return ret", "-", "-", "-print((solve(N, K)))", "+dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(L + 1)]", "+dp[0][0][0] = 1", "+for i, c in enumerate(N):", "+ c = int(c)", "+ for k in range(K + 1):", "+ for less in range(2):", "+ for d in range(10):", "+ nk = k + (d > 0)", "+ if nk > K:", "+ continue", "+ if less == 0 and d > c:", "+ continue", "+ nxless = not (less == 0 and d == c)", "+ dp[i + 1][nk][nxless] += dp[i][k][less]", "+print((sum(dp[-1][-1])))" ]
false
0.070384
0.034773
2.024072
[ "s198167995", "s637669404" ]
u814781830
p03273
python
s811139483
s340024708
234
42
44,760
9,316
Accepted
Accepted
82.05
H, W = map(int, input().split()) A = [list(input()) for _ in range(H)] hl = [] wl = [] for h in range(H): if sum([0 if i == "." else 1 for i in A[h]]) > 0: hl.append(h) for w in range(W): if sum([0 if A[i][w] == "." else 1 for i in range(H)]) > 0: wl.append(w) for h in hl: line = [] for w in wl: line.append(A[h][w]) print(*line, sep="")
H, W = map(int, input().split()) a = [list(input()) for _ in range(H)] resH = [True] * H resW = [True] * W for h in range(H): judge = False for w in range(W): if a[h][w] == "#": judge = True resH[h] = judge for w in range(W): judge = False for h in range(H): if a[h][w] == "#": judge = True resW[w] = judge for h, row in enumerate(a): tmp = [] for w, element in enumerate(row): if resH[h] and resW[w]: tmp.append(element) if tmp: print(*tmp, sep="")
18
26
403
582
H, W = map(int, input().split()) A = [list(input()) for _ in range(H)] hl = [] wl = [] for h in range(H): if sum([0 if i == "." else 1 for i in A[h]]) > 0: hl.append(h) for w in range(W): if sum([0 if A[i][w] == "." else 1 for i in range(H)]) > 0: wl.append(w) for h in hl: line = [] for w in wl: line.append(A[h][w]) print(*line, sep="")
H, W = map(int, input().split()) a = [list(input()) for _ in range(H)] resH = [True] * H resW = [True] * W for h in range(H): judge = False for w in range(W): if a[h][w] == "#": judge = True resH[h] = judge for w in range(W): judge = False for h in range(H): if a[h][w] == "#": judge = True resW[w] = judge for h, row in enumerate(a): tmp = [] for w, element in enumerate(row): if resH[h] and resW[w]: tmp.append(element) if tmp: print(*tmp, sep="")
false
30.769231
[ "-A = [list(input()) for _ in range(H)]", "-hl = []", "-wl = []", "+a = [list(input()) for _ in range(H)]", "+resH = [True] * H", "+resW = [True] * W", "- if sum([0 if i == \".\" else 1 for i in A[h]]) > 0:", "- hl.append(h)", "+ judge = False", "+ for w in range(W):", "+ if a[h][w] == \"#\":", "+ judge = True", "+ resH[h] = judge", "- if sum([0 if A[i][w] == \".\" else 1 for i in range(H)]) > 0:", "- wl.append(w)", "-for h in hl:", "- line = []", "- for w in wl:", "- line.append(A[h][w])", "- print(*line, sep=\"\")", "+ judge = False", "+ for h in range(H):", "+ if a[h][w] == \"#\":", "+ judge = True", "+ resW[w] = judge", "+for h, row in enumerate(a):", "+ tmp = []", "+ for w, element in enumerate(row):", "+ if resH[h] and resW[w]:", "+ tmp.append(element)", "+ if tmp:", "+ print(*tmp, sep=\"\")" ]
false
0.035978
0.040855
0.880619
[ "s811139483", "s340024708" ]
u073729602
p02534
python
s435497509
s070330346
30
25
9,128
9,040
Accepted
Accepted
16.67
n = int(eval(input())) print(("ACL"*n))
k = int(eval(input())) print(("ACL" * k))
2
2
33
34
n = int(eval(input())) print(("ACL" * n))
k = int(eval(input())) print(("ACL" * k))
false
0
[ "-n = int(eval(input()))", "-print((\"ACL\" * n))", "+k = int(eval(input()))", "+print((\"ACL\" * k))" ]
false
0.045958
0.047837
0.960715
[ "s435497509", "s070330346" ]
u057415180
p02989
python
s993733125
s030763311
98
76
14,396
14,396
Accepted
Accepted
22.45
n = int(eval(input())) d = list(map(int, input().split())) ans = 0 d.sort() k = d[int(n/2)] while k > d[int(n/2)-1]: k -= 1 ans += 1 print(ans)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((d[n//2] - d[n//2 - 1]))
9
6
151
97
n = int(eval(input())) d = list(map(int, input().split())) ans = 0 d.sort() k = d[int(n / 2)] while k > d[int(n / 2) - 1]: k -= 1 ans += 1 print(ans)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((d[n // 2] - d[n // 2 - 1]))
false
33.333333
[ "-ans = 0", "-k = d[int(n / 2)]", "-while k > d[int(n / 2) - 1]:", "- k -= 1", "- ans += 1", "-print(ans)", "+print((d[n // 2] - d[n // 2 - 1]))" ]
false
0.048208
0.045577
1.057733
[ "s993733125", "s030763311" ]
u790710233
p03078
python
s987685536
s267115687
1,441
649
144,240
8,708
Accepted
Accepted
54.96
from itertools import product x, y, z, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [sum(ab) for ab in product(A, B)] AB.sort(reverse=True) AB = AB[:k] ABC = [sum(abc) for abc in product(AB, C)] ABC.sort(reverse=True) for i in range(k): print((ABC[i]))
x, y, z, K = list(map(int, input().split())) A = sorted(map(int, input().split()), reverse=True) B = sorted(map(int, input().split()), reverse=True) C = sorted(map(int, input().split()), reverse=True) ans = [] for i in range(x): for j in range(y): for k in range(z): if (i+1)*(j+1)*(k+1) <= K: ans.append(A[i]+B[j]+C[k]) continue break ans.sort(reverse=True) for i in range(K): print((ans[i]))
12
16
346
474
from itertools import product x, y, z, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [sum(ab) for ab in product(A, B)] AB.sort(reverse=True) AB = AB[:k] ABC = [sum(abc) for abc in product(AB, C)] ABC.sort(reverse=True) for i in range(k): print((ABC[i]))
x, y, z, K = list(map(int, input().split())) A = sorted(map(int, input().split()), reverse=True) B = sorted(map(int, input().split()), reverse=True) C = sorted(map(int, input().split()), reverse=True) ans = [] for i in range(x): for j in range(y): for k in range(z): if (i + 1) * (j + 1) * (k + 1) <= K: ans.append(A[i] + B[j] + C[k]) continue break ans.sort(reverse=True) for i in range(K): print((ans[i]))
false
25
[ "-from itertools import product", "-", "-x, y, z, k = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-B = list(map(int, input().split()))", "-C = list(map(int, input().split()))", "-AB = [sum(ab) for ab in product(A, B)]", "-AB.sort(reverse=True)", "-AB = AB[:k]", "-ABC = [sum(abc) for abc in product(AB, C)]", "-ABC.sort(reverse=True)", "-for i in range(k):", "- print((ABC[i]))", "+x, y, z, K = list(map(int, input().split()))", "+A = sorted(map(int, input().split()), reverse=True)", "+B = sorted(map(int, input().split()), reverse=True)", "+C = sorted(map(int, input().split()), reverse=True)", "+ans = []", "+for i in range(x):", "+ for j in range(y):", "+ for k in range(z):", "+ if (i + 1) * (j + 1) * (k + 1) <= K:", "+ ans.append(A[i] + B[j] + C[k])", "+ continue", "+ break", "+ans.sort(reverse=True)", "+for i in range(K):", "+ print((ans[i]))" ]
false
0.035078
0.080832
0.433961
[ "s987685536", "s267115687" ]
u195054737
p03160
python
s776824873
s141122893
196
165
13,800
13,980
Accepted
Accepted
15.82
n = int(eval(input())) h = [int(i) for i in input().split()] dp = [1e9] * n dp[0] = 0 for i in range(1,n): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print((dp[-1]))
n = int(eval(input())) h = [int(i) for i in input().split()] dp = [float('inf')] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 0: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print((dp[-1]))
13
13
254
264
n = int(eval(input())) h = [int(i) for i in input().split()] dp = [1e9] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
n = int(eval(input())) h = [int(i) for i in input().split()] dp = [float("inf")] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) if i > 0: dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
false
0
[ "-dp = [1e9] * n", "+dp = [float(\"inf\")] * n", "- if i > 1:", "+ if i > 0:" ]
false
0.036803
0.036861
0.998438
[ "s776824873", "s141122893" ]
u107077660
p03994
python
s551621702
s618648419
1,236
115
3,508
3,444
Accepted
Accepted
90.7
s = eval(input()) s += " " K = int(eval(input())) alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] k = 0 k = K for i in range(len(s) - 1): gap = (26 - alphabet.index(s[i])) % 26 if K >= gap: K -= gap s = s[:i] + "a" + s[i+1:] s = s[:-1] if K: n = alphabet.index(s[-1]) n += K n %= 26 s = s[:-1] + alphabet[n] print(s)
S = eval(input()) K = int(eval(input())) ans = "" for i in range(len(S)): if(S[i] != 'a' and K >= (ord('a') - ord(S[i]))%26): ans += 'a' K -= (ord('a') - ord(S[i]))%26 else: ans += S[i] K %= 26 ans = ans[:-1] + chr(ord('a') + (ord(ans[-1])-ord('a') + K)%26) print(ans)
21
13
406
302
s = eval(input()) s += " " K = int(eval(input())) alphabet = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] k = 0 k = K for i in range(len(s) - 1): gap = (26 - alphabet.index(s[i])) % 26 if K >= gap: K -= gap s = s[:i] + "a" + s[i + 1 :] s = s[:-1] if K: n = alphabet.index(s[-1]) n += K n %= 26 s = s[:-1] + alphabet[n] print(s)
S = eval(input()) K = int(eval(input())) ans = "" for i in range(len(S)): if S[i] != "a" and K >= (ord("a") - ord(S[i])) % 26: ans += "a" K -= (ord("a") - ord(S[i])) % 26 else: ans += S[i] K %= 26 ans = ans[:-1] + chr(ord("a") + (ord(ans[-1]) - ord("a") + K) % 26) print(ans)
false
38.095238
[ "-s = eval(input())", "-s += \" \"", "+S = eval(input())", "-alphabet = [", "- \"a\",", "- \"b\",", "- \"c\",", "- \"d\",", "- \"e\",", "- \"f\",", "- \"g\",", "- \"h\",", "- \"i\",", "- \"j\",", "- \"k\",", "- \"l\",", "- \"m\",", "- \"n\",", "- \"o\",", "- \"p\",", "- \"q\",", "- \"r\",", "- \"s\",", "- \"t\",", "- \"u\",", "- \"v\",", "- \"w\",", "- \"x\",", "- \"y\",", "- \"z\",", "-]", "-k = 0", "-k = K", "-for i in range(len(s) - 1):", "- gap = (26 - alphabet.index(s[i])) % 26", "- if K >= gap:", "- K -= gap", "- s = s[:i] + \"a\" + s[i + 1 :]", "-s = s[:-1]", "-if K:", "- n = alphabet.index(s[-1])", "- n += K", "- n %= 26", "- s = s[:-1] + alphabet[n]", "-print(s)", "+ans = \"\"", "+for i in range(len(S)):", "+ if S[i] != \"a\" and K >= (ord(\"a\") - ord(S[i])) % 26:", "+ ans += \"a\"", "+ K -= (ord(\"a\") - ord(S[i])) % 26", "+ else:", "+ ans += S[i]", "+K %= 26", "+ans = ans[:-1] + chr(ord(\"a\") + (ord(ans[-1]) - ord(\"a\") + K) % 26)", "+print(ans)" ]
false
0.037064
0.036318
1.020521
[ "s551621702", "s618648419" ]
u038021590
p03862
python
s688530780
s747945418
156
87
14,052
84,760
Accepted
Accepted
44.23
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): s = A[i] + A[i-1] if s > x: y = s-x if A[i] > y: A[i] -= y A[i-1] -= y ans += y else: z = y - A[i] A[i] = 0 A[i-1] -= A[i] A[i-1] -= z if i >= 2: A[i-2] -= z ans += y print(ans)
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 now = A[0] if now > x: ans += now - x now = x for i in range(1, N): if now + A[i] > x: y = now + A[i] - x ans += y A[i] = max(0, A[i] - y) now = A[i] print(ans)
23
14
458
291
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): s = A[i] + A[i - 1] if s > x: y = s - x if A[i] > y: A[i] -= y A[i - 1] -= y ans += y else: z = y - A[i] A[i] = 0 A[i - 1] -= A[i] A[i - 1] -= z if i >= 2: A[i - 2] -= z ans += y print(ans)
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 now = A[0] if now > x: ans += now - x now = x for i in range(1, N): if now + A[i] > x: y = now + A[i] - x ans += y A[i] = max(0, A[i] - y) now = A[i] print(ans)
false
39.130435
[ "+now = A[0]", "+if now > x:", "+ ans += now - x", "+ now = x", "- s = A[i] + A[i - 1]", "- if s > x:", "- y = s - x", "- if A[i] > y:", "- A[i] -= y", "- A[i - 1] -= y", "- ans += y", "- else:", "- z = y - A[i]", "- A[i] = 0", "- A[i - 1] -= A[i]", "- A[i - 1] -= z", "- if i >= 2:", "- A[i - 2] -= z", "- ans += y", "+ if now + A[i] > x:", "+ y = now + A[i] - x", "+ ans += y", "+ A[i] = max(0, A[i] - y)", "+ now = A[i]" ]
false
0.080137
0.046124
1.737415
[ "s688530780", "s747945418" ]
u145231176
p02720
python
s210226439
s653580593
592
301
83,676
95,804
Accepted
Accepted
49.16
import collections m = int(eval(input())) n = 1000000000 ans = [] listnum = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9] ] def dfs(s): if len(str(n)) + 1 > len(s): ans.append(int(s)) lastnum = str(s)[-1] for i in listnum[int(lastnum)]: dfs(s + str(i)) for i in range(1, 10): dfs(str(i)) ans = sorted(ans) print((ans[m - 1]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N = getN() next = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9] ] ans = [] def dfs(s): global ans if len(s) >= 11: return # 上限を超えない範囲で実行 else: ans.append(int(s)) # dfs s_last = int(s[-1]) for i in next[s_last]: dfs(s + str(i)) # 始点は1~9 for i in range(1, 10): dfs(str(i)) ans.sort() print((ans[N - 1]))
26
88
576
1,756
import collections m = int(eval(input())) n = 1000000000 ans = [] listnum = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9], ] def dfs(s): if len(str(n)) + 1 > len(s): ans.append(int(s)) lastnum = str(s)[-1] for i in listnum[int(lastnum)]: dfs(s + str(i)) for i in range(1, 10): dfs(str(i)) ans = sorted(ans) print((ans[m - 1]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# N = getN() next = [ [0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9], ] ans = [] def dfs(s): global ans if len(s) >= 11: return # 上限を超えない範囲で実行 else: ans.append(int(s)) # dfs s_last = int(s[-1]) for i in next[s_last]: dfs(s + str(i)) # 始点は1~9 for i in range(1, 10): dfs(str(i)) ans.sort() print((ans[N - 1]))
false
70.454545
[ "-import collections", "+def getN():", "+ return int(eval(input()))", "-m = int(eval(input()))", "-n = 1000000000", "-ans = []", "-listnum = [", "+", "+def getNM():", "+ return list(map(int, input().split()))", "+", "+", "+def getList():", "+ return list(map(int, input().split()))", "+", "+", "+def getArray(intn):", "+ return [int(eval(input())) for i in range(intn)]", "+", "+", "+def input():", "+ return sys.stdin.readline().rstrip()", "+", "+", "+def rand_N(ran1, ran2):", "+ return random.randint(ran1, ran2)", "+", "+", "+def rand_List(ran1, ran2, rantime):", "+ return [random.randint(ran1, ran2) for i in range(rantime)]", "+", "+", "+def rand_ints_nodup(ran1, ran2, rantime):", "+ ns = []", "+ while len(ns) < rantime:", "+ n = random.randint(ran1, ran2)", "+ if not n in ns:", "+ ns.append(n)", "+ return sorted(ns)", "+", "+", "+def rand_query(ran1, ran2, rantime):", "+ r_query = []", "+ while len(r_query) < rantime:", "+ n_q = rand_ints_nodup(ran1, ran2, 2)", "+ if not n_q in r_query:", "+ r_query.append(n_q)", "+ return sorted(r_query)", "+", "+", "+from collections import defaultdict, deque, Counter", "+from sys import exit", "+from decimal import *", "+import heapq", "+import math", "+from fractions import gcd", "+import random", "+import string", "+import copy", "+from itertools import permutations", "+from operator import mul", "+from functools import reduce", "+from bisect import bisect_left, bisect_right", "+import sys", "+", "+sys.setrecursionlimit(1000000000)", "+mod = 10**9 + 7", "+#############", "+# Main Code #", "+#############", "+N = getN()", "+next = [", "+ans = []", "- if len(str(n)) + 1 > len(s):", "+ global ans", "+ if len(s) >= 11:", "+ return", "+ # 上限を超えない範囲で実行", "+ else:", "- lastnum = str(s)[-1]", "- for i in listnum[int(lastnum)]:", "+ # dfs", "+ s_last = int(s[-1])", "+ for i in next[s_last]:", "+# 始点は1~9", "-ans = sorted(ans)", "-print((ans[m - 1]))", "+ans.sort()", "+print((ans[N - 1]))" ]
false
0.704369
0.505439
1.393578
[ "s210226439", "s653580593" ]
u625729943
p03221
python
s881496602
s326580258
820
659
38,396
43,012
Accepted
Accepted
19.63
N, M = list(map(int, input().split())) PY = [[i,0] + list(map(int, input().split())) for i in range(M)] # [index, nth city, pref num, birth year] PY.sort(key=lambda x:(x[2],x[3])) p = -1 num = 1 for i,py in enumerate(PY): if p != py[2]: p = py[2] num = 1 PY[i][1] = num else: num += 1 PY[i][1] = num PY.sort(key=lambda x:x[0]) for py in PY: print(('{:0=6}{:0=6}'.format(py[2], py[1])))
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') N, M = map(int, input().split()) # PY = [list(map(int, input().split())) for _ in range(M)] PY = [] for i in range(M): P, Y = map(int, input().split()) PY.append((i, P, Y)) PYs = sorted(PY, key=lambda x:(x[1], x[2])) # print(PYs) d = defaultdict(int) ress = [] for py in PYs: i, p, y = py ress.append((i, p, d[p]+1)) d[p] += 1 ress.sort(key=lambda x: x[0]) for res in ress: i, p, o = res print(str(p).zfill(6)+str(o).zfill(6))
21
33
428
859
N, M = list(map(int, input().split())) PY = [[i, 0] + list(map(int, input().split())) for i in range(M)] # [index, nth city, pref num, birth year] PY.sort(key=lambda x: (x[2], x[3])) p = -1 num = 1 for i, py in enumerate(PY): if p != py[2]: p = py[2] num = 1 PY[i][1] = num else: num += 1 PY[i][1] = num PY.sort(key=lambda x: x[0]) for py in PY: print(("{:0=6}{:0=6}".format(py[2], py[1])))
# import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial # , gcd from bisect import bisect_left # bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9 + 7 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep="\n") N, M = map(int, input().split()) # PY = [list(map(int, input().split())) for _ in range(M)] PY = [] for i in range(M): P, Y = map(int, input().split()) PY.append((i, P, Y)) PYs = sorted(PY, key=lambda x: (x[1], x[2])) # print(PYs) d = defaultdict(int) ress = [] for py in PYs: i, p, y = py ress.append((i, p, d[p] + 1)) d[p] += 1 ress.sort(key=lambda x: x[0]) for res in ress: i, p, o = res print(str(p).zfill(6) + str(o).zfill(6))
false
36.363636
[ "-N, M = list(map(int, input().split()))", "-PY = [[i, 0] + list(map(int, input().split())) for i in range(M)]", "-# [index, nth city, pref num, birth year]", "-PY.sort(key=lambda x: (x[2], x[3]))", "-p = -1", "-num = 1", "-for i, py in enumerate(PY):", "- if p != py[2]:", "- p = py[2]", "- num = 1", "- PY[i][1] = num", "- else:", "- num += 1", "- PY[i][1] = num", "-PY.sort(key=lambda x: x[0])", "-for py in PY:", "- print((\"{:0=6}{:0=6}\".format(py[2], py[1])))", "+# import numpy as np", "+import sys, math", "+from itertools import permutations, combinations", "+from collections import defaultdict, Counter, deque", "+from math import factorial # , gcd", "+from bisect import bisect_left # bisect_left(list, value)", "+", "+sys.setrecursionlimit(10**7)", "+enu = enumerate", "+MOD = 10**9 + 7", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+pl = lambda x: print(*x, sep=\"\\n\")", "+N, M = map(int, input().split())", "+# PY = [list(map(int, input().split())) for _ in range(M)]", "+PY = []", "+for i in range(M):", "+ P, Y = map(int, input().split())", "+ PY.append((i, P, Y))", "+PYs = sorted(PY, key=lambda x: (x[1], x[2]))", "+# print(PYs)", "+d = defaultdict(int)", "+ress = []", "+for py in PYs:", "+ i, p, y = py", "+ ress.append((i, p, d[p] + 1))", "+ d[p] += 1", "+ress.sort(key=lambda x: x[0])", "+for res in ress:", "+ i, p, o = res", "+ print(str(p).zfill(6) + str(o).zfill(6))" ]
false
0.035576
0.042719
0.832776
[ "s881496602", "s326580258" ]
u225388820
p03177
python
s836190805
s033202077
1,591
496
69,724
41,904
Accepted
Accepted
68.82
# dp[n][i][j]=(頂点iから頂点jへ行く長さnのパスの個数) # dp[n][i][j]=sum(dp[n-1][i][k]*a[k][j])⇒DP[n]=DP[n-1]*A DP[0]=Eより DP[n]=A^n n,k=list(map(int,input().split())) a=[list(map(int,input().split())) for i in range(n)] dp=[[0]*n for i in range(n)] mod=10**9+7 for i in range(n): for j in range(n): dp[i][i]=1 def dot(A,B): C=[[0]*n for i in range(n)] for i in range(n): for j in range(n): for k in range(n): C[i][j]+=A[i][k]*B[k][j] C[i][j]%=mod return C while k: if k&1: dp=dot(dp,a) a=dot(a,a) k>>=1 ans=0 for i in dp: ans+=sum(i) print((ans%mod))
# dp[n][i][j]=(頂点iから頂点jへ行く長さnのパスの個数) # dp[n][i][j]=sum(dp[n-1][i][k]*a[k][j])⇒DP[n]=DP[n-1]*A DP[0]=Eより DP[n]=A^n import sys input = sys.stdin.readline def dot(A,B,MOD=1000000007): N,M,L = len(A),len(A[0]),len(B[0]) res = [[0]*L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k]*B[k][j]) % MOD res[i][j] = s return res def matPow(A,x,MOD=1000000007): N = len(A) res = [[0]*N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x>>i) & 1: res = dot(res,A) A = dot(A,A) return res def main(): n,k = list(map(int,input().split())) mod = 10**9+7 a = [list(map(int,input().split())) for i in range(n)] dp = matPow(a,k) ans = 0 for i in range(n): for j in range(n): ans += dp[i][j] print((ans%mod)) main()
26
39
646
998
# dp[n][i][j]=(頂点iから頂点jへ行く長さnのパスの個数) # dp[n][i][j]=sum(dp[n-1][i][k]*a[k][j])⇒DP[n]=DP[n-1]*A DP[0]=Eより DP[n]=A^n n, k = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(n)] dp = [[0] * n for i in range(n)] mod = 10**9 + 7 for i in range(n): for j in range(n): dp[i][i] = 1 def dot(A, B): C = [[0] * n for i in range(n)] for i in range(n): for j in range(n): for k in range(n): C[i][j] += A[i][k] * B[k][j] C[i][j] %= mod return C while k: if k & 1: dp = dot(dp, a) a = dot(a, a) k >>= 1 ans = 0 for i in dp: ans += sum(i) print((ans % mod))
# dp[n][i][j]=(頂点iから頂点jへ行く長さnのパスの個数) # dp[n][i][j]=sum(dp[n-1][i][k]*a[k][j])⇒DP[n]=DP[n-1]*A DP[0]=Eより DP[n]=A^n import sys input = sys.stdin.readline def dot(A, B, MOD=1000000007): N, M, L = len(A), len(A[0]), len(B[0]) res = [[0] * L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k] * B[k][j]) % MOD res[i][j] = s return res def matPow(A, x, MOD=1000000007): N = len(A) res = [[0] * N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x >> i) & 1: res = dot(res, A) A = dot(A, A) return res def main(): n, k = list(map(int, input().split())) mod = 10**9 + 7 a = [list(map(int, input().split())) for i in range(n)] dp = matPow(a, k) ans = 0 for i in range(n): for j in range(n): ans += dp[i][j] print((ans % mod)) main()
false
33.333333
[ "-n, k = list(map(int, input().split()))", "-a = [list(map(int, input().split())) for i in range(n)]", "-dp = [[0] * n for i in range(n)]", "-mod = 10**9 + 7", "-for i in range(n):", "- for j in range(n):", "- dp[i][i] = 1", "+import sys", "+", "+input = sys.stdin.readline", "-def dot(A, B):", "- C = [[0] * n for i in range(n)]", "+def dot(A, B, MOD=1000000007):", "+ N, M, L = len(A), len(A[0]), len(B[0])", "+ res = [[0] * L for i in range(N)]", "+ for i in range(N):", "+ for j in range(L):", "+ s = 0", "+ for k in range(M):", "+ s = (s + A[i][k] * B[k][j]) % MOD", "+ res[i][j] = s", "+ return res", "+", "+", "+def matPow(A, x, MOD=1000000007):", "+ N = len(A)", "+ res = [[0] * N for i in range(N)]", "+ for i in range(N):", "+ res[i][i] = 1", "+ for i in range(x.bit_length()):", "+ if (x >> i) & 1:", "+ res = dot(res, A)", "+ A = dot(A, A)", "+ return res", "+", "+", "+def main():", "+ n, k = list(map(int, input().split()))", "+ mod = 10**9 + 7", "+ a = [list(map(int, input().split())) for i in range(n)]", "+ dp = matPow(a, k)", "+ ans = 0", "- for k in range(n):", "- C[i][j] += A[i][k] * B[k][j]", "- C[i][j] %= mod", "- return C", "+ ans += dp[i][j]", "+ print((ans % mod))", "-while k:", "- if k & 1:", "- dp = dot(dp, a)", "- a = dot(a, a)", "- k >>= 1", "-ans = 0", "-for i in dp:", "- ans += sum(i)", "-print((ans % mod))", "+main()" ]
false
0.065007
0.063734
1.019983
[ "s836190805", "s033202077" ]
u690536347
p02874
python
s022480208
s719730057
551
438
97,352
98,768
Accepted
Accepted
20.51
from itertools import product from operator import add class SegTree(): def __init__(self, N, e, operator_func=add): self.e = e # 単位元 self.size = N self.node = [self.e] * (2*N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i+self.size-1] = l[i] for i in range(self.size-1)[::-1]: self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2]) def update(self, k, x): k += self.size-1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2]) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l<r: if l&1: x = self.operator_func(x, self.node[l-1]) l += 1 if r&1: r -= 1 x = self.operator_func(x, self.node[r-1]) l >>= 1 r >>= 1 return x N = int(eval(input())) l = [tuple(map(int, input().split())) for i in range(N)] l.sort(key=lambda x:(x[0], -x[1])) #1 [lmax, rmin] [*, *] #2 [lmax, *] [*, rmin] lmax = 0 rmin = 10**12 a, b = 0, 0 for i in range(N): if lmax < l[i][0]: lmax = l[i][0] a = i if rmin > l[i][1]: rmin = l[i][1] b = i #1 ans1 = 0 for i in range(N): if i==a or i==b: continue buf = max(l[b][1]-l[a][0]+1, 0)+max(l[i][1]-l[i][0]+1, 0) ans1 = max(ans1, buf) #2 ans2 = 0 tree = SegTree(N, 10**12, min) tree.set_list([i[1] for i in l]) for i in range(N-1): p1 = l[i][0] p2 = tree.get(i+1, N) buf = max(l[b][1]-p1+1, 0)+max(p2-l[a][0]+1, 0) ans2 = max(ans2, buf) ans = max(ans1, ans2) print(ans)
import sys input=sys.stdin.readline class SegTree(): def __init__(self, N, e, operator_func): self.e = e # 単位元 self.size = N self.node = [self.e] * (2*N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i+self.size-1] = l[i] for i in range(self.size-1)[::-1]: self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2]) def update(self, k, x): k += self.size-1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2]) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l<r: if l&1: x = self.operator_func(x, self.node[l-1]) l += 1 if r&1: r -= 1 x = self.operator_func(x, self.node[r-1]) l >>= 1 r >>= 1 return x def solve(): N = int(eval(input())) l = [tuple(map(int, input().split())) for i in range(N)] l.sort(key=lambda x:(x[0], -x[1])) #1 [lmax, rmin] [*, *] #2 [lmax, *] [*, rmin] lmax = 0 rmin = 10**12 a, b = 0, 0 for i in range(N): if lmax < l[i][0]: lmax = l[i][0] a = i if rmin > l[i][1]: rmin = l[i][1] b = i #1 ans1 = 0 for i in range(N): if i==a or i==b: continue ans1 = max(ans1, max(l[b][1]-l[a][0]+1, 0)+max(l[i][1]-l[i][0]+1, 0)) #2 ans2 = 0 tree = SegTree(N, 10**12, min) tree.set_list([i[1] for i in l]) for i in range(N-1): ans2 = max(ans2, max(l[b][1]-l[i][0]+1, 0)+max(tree.get(i+1, N)-l[a][0]+1, 0)) ans = max(ans1, ans2) print(ans) if __name__ == "__main__": solve()
82
82
1,953
2,047
from itertools import product from operator import add class SegTree: def __init__(self, N, e, operator_func=add): self.e = e # 単位元 self.size = N self.node = [self.e] * (2 * N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i + self.size - 1] = l[i] for i in range(self.size - 1)[::-1]: self.node[i] = self.operator_func( self.node[2 * i + 1], self.node[2 * i + 2] ) def update(self, k, x): k += self.size - 1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func( self.node[2 * k + 1], self.node[2 * k + 2] ) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l < r: if l & 1: x = self.operator_func(x, self.node[l - 1]) l += 1 if r & 1: r -= 1 x = self.operator_func(x, self.node[r - 1]) l >>= 1 r >>= 1 return x N = int(eval(input())) l = [tuple(map(int, input().split())) for i in range(N)] l.sort(key=lambda x: (x[0], -x[1])) # 1 [lmax, rmin] [*, *] # 2 [lmax, *] [*, rmin] lmax = 0 rmin = 10**12 a, b = 0, 0 for i in range(N): if lmax < l[i][0]: lmax = l[i][0] a = i if rmin > l[i][1]: rmin = l[i][1] b = i # 1 ans1 = 0 for i in range(N): if i == a or i == b: continue buf = max(l[b][1] - l[a][0] + 1, 0) + max(l[i][1] - l[i][0] + 1, 0) ans1 = max(ans1, buf) # 2 ans2 = 0 tree = SegTree(N, 10**12, min) tree.set_list([i[1] for i in l]) for i in range(N - 1): p1 = l[i][0] p2 = tree.get(i + 1, N) buf = max(l[b][1] - p1 + 1, 0) + max(p2 - l[a][0] + 1, 0) ans2 = max(ans2, buf) ans = max(ans1, ans2) print(ans)
import sys input = sys.stdin.readline class SegTree: def __init__(self, N, e, operator_func): self.e = e # 単位元 self.size = N self.node = [self.e] * (2 * N) self.operator_func = operator_func # 処理(add or xor max minなど) def set_list(self, l): for i in range(self.size): self.node[i + self.size - 1] = l[i] for i in range(self.size - 1)[::-1]: self.node[i] = self.operator_func( self.node[2 * i + 1], self.node[2 * i + 2] ) def update(self, k, x): k += self.size - 1 self.node[k] = x while k >= 0: k = (k - 1) // 2 self.node[k] = self.operator_func( self.node[2 * k + 1], self.node[2 * k + 2] ) def get(self, l, r): # [l, r) についてqueryを求める x = self.e l += self.size r += self.size while l < r: if l & 1: x = self.operator_func(x, self.node[l - 1]) l += 1 if r & 1: r -= 1 x = self.operator_func(x, self.node[r - 1]) l >>= 1 r >>= 1 return x def solve(): N = int(eval(input())) l = [tuple(map(int, input().split())) for i in range(N)] l.sort(key=lambda x: (x[0], -x[1])) # 1 [lmax, rmin] [*, *] # 2 [lmax, *] [*, rmin] lmax = 0 rmin = 10**12 a, b = 0, 0 for i in range(N): if lmax < l[i][0]: lmax = l[i][0] a = i if rmin > l[i][1]: rmin = l[i][1] b = i # 1 ans1 = 0 for i in range(N): if i == a or i == b: continue ans1 = max(ans1, max(l[b][1] - l[a][0] + 1, 0) + max(l[i][1] - l[i][0] + 1, 0)) # 2 ans2 = 0 tree = SegTree(N, 10**12, min) tree.set_list([i[1] for i in l]) for i in range(N - 1): ans2 = max( ans2, max(l[b][1] - l[i][0] + 1, 0) + max(tree.get(i + 1, N) - l[a][0] + 1, 0), ) ans = max(ans1, ans2) print(ans) if __name__ == "__main__": solve()
false
0
[ "-from itertools import product", "-from operator import add", "+import sys", "+", "+input = sys.stdin.readline", "- def __init__(self, N, e, operator_func=add):", "+ def __init__(self, N, e, operator_func):", "-N = int(eval(input()))", "-l = [tuple(map(int, input().split())) for i in range(N)]", "-l.sort(key=lambda x: (x[0], -x[1]))", "-# 1 [lmax, rmin] [*, *]", "-# 2 [lmax, *] [*, rmin]", "-lmax = 0", "-rmin = 10**12", "-a, b = 0, 0", "-for i in range(N):", "- if lmax < l[i][0]:", "- lmax = l[i][0]", "- a = i", "- if rmin > l[i][1]:", "- rmin = l[i][1]", "- b = i", "-# 1", "-ans1 = 0", "-for i in range(N):", "- if i == a or i == b:", "- continue", "- buf = max(l[b][1] - l[a][0] + 1, 0) + max(l[i][1] - l[i][0] + 1, 0)", "- ans1 = max(ans1, buf)", "-# 2", "-ans2 = 0", "-tree = SegTree(N, 10**12, min)", "-tree.set_list([i[1] for i in l])", "-for i in range(N - 1):", "- p1 = l[i][0]", "- p2 = tree.get(i + 1, N)", "- buf = max(l[b][1] - p1 + 1, 0) + max(p2 - l[a][0] + 1, 0)", "- ans2 = max(ans2, buf)", "-ans = max(ans1, ans2)", "-print(ans)", "+def solve():", "+ N = int(eval(input()))", "+ l = [tuple(map(int, input().split())) for i in range(N)]", "+ l.sort(key=lambda x: (x[0], -x[1]))", "+ # 1 [lmax, rmin] [*, *]", "+ # 2 [lmax, *] [*, rmin]", "+ lmax = 0", "+ rmin = 10**12", "+ a, b = 0, 0", "+ for i in range(N):", "+ if lmax < l[i][0]:", "+ lmax = l[i][0]", "+ a = i", "+ if rmin > l[i][1]:", "+ rmin = l[i][1]", "+ b = i", "+ # 1", "+ ans1 = 0", "+ for i in range(N):", "+ if i == a or i == b:", "+ continue", "+ ans1 = max(ans1, max(l[b][1] - l[a][0] + 1, 0) + max(l[i][1] - l[i][0] + 1, 0))", "+ # 2", "+ ans2 = 0", "+ tree = SegTree(N, 10**12, min)", "+ tree.set_list([i[1] for i in l])", "+ for i in range(N - 1):", "+ ans2 = max(", "+ ans2,", "+ max(l[b][1] - l[i][0] + 1, 0) + max(tree.get(i + 1, N) - l[a][0] + 1, 0),", "+ )", "+ ans = max(ans1, ans2)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.035355
0.035356
0.99996
[ "s022480208", "s719730057" ]
u577170763
p02616
python
s442504606
s038089845
178
161
106,228
119,904
Accepted
Accepted
9.55
from queue import PriorityQueue import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) mod = 10**9+7 def prod(l): ret = 1 for e in l: e %= mod ret = (ret*e) % mod return ret def main(): n, k = geta(int) a = list(geta(int)) p, n, z = [], [], 0 for ai in a: if ai > 0: p.append(ai) elif ai < 0: n.append(-ai) else: z += 1 ans = 1 p.sort() n.sort() if k & 1 == 1: if len(p) == 0: if z > 0: print((0)) exit() else: print((-prod(n[0:k]) % mod)) exit() else: k -= 1 ans = p.pop() % mod if len(p) + len(n) < k: print((0)) exit() if len(n) & 1 == 1 and (len(p) + len(n) == k): if z > 0: print((0)) exit() else: print((-prod(p) * prod(n) % mod)) exit() q = [] n = n[::-1] for i in range(len(n)//2): q.append(n[2*i]*n[2*i+1]) p = p[::-1] for i in range(len(p)//2): q.append(p[2*i]*p[2*i+1]) q.sort(reverse=True) ans = ans * (prod(q[:k//2])) % mod print((ans % mod)) if __name__ == "__main__": main()
from queue import PriorityQueue import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) mod = 10**9+7 def prod(l): ret = 1 for e in l: e %= mod ret = (ret*e) % mod return ret def main(): n, k = geta(int) a = list(geta(int)) p, n, z = [], [], 0 for ai in a: if ai > 0: p.append(ai) elif ai < 0: n.append(-ai) else: z += 1 ans = 1 p.sort() n.sort() if len(p) + len(n) < k: print((0)) exit() elif len(p) + len(n) == k: if len(n) & 1 == 0: print((prod(p) * prod(n) % mod)) exit() else: if z > 0: print((0)) exit() else: print((-prod(p)*prod(n) % mod)) exit() if k & 1 == 1: if len(p) == 0: if z > 0: print((0)) exit() else: print((-prod(n[0:k]) % mod)) exit() else: k -= 1 ans = p.pop() % mod q = [] n = n[::-1] for i in range(len(n)//2): q.append(n[2*i]*n[2*i+1]) p = p[::-1] for i in range(len(p)//2): q.append(p[2*i]*p[2*i+1]) q.sort(reverse=True) ans = ans * (prod(q[:k//2])) % mod print((ans % mod)) if __name__ == "__main__": main()
86
91
1,578
1,690
from queue import PriorityQueue import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) mod = 10**9 + 7 def prod(l): ret = 1 for e in l: e %= mod ret = (ret * e) % mod return ret def main(): n, k = geta(int) a = list(geta(int)) p, n, z = [], [], 0 for ai in a: if ai > 0: p.append(ai) elif ai < 0: n.append(-ai) else: z += 1 ans = 1 p.sort() n.sort() if k & 1 == 1: if len(p) == 0: if z > 0: print((0)) exit() else: print((-prod(n[0:k]) % mod)) exit() else: k -= 1 ans = p.pop() % mod if len(p) + len(n) < k: print((0)) exit() if len(n) & 1 == 1 and (len(p) + len(n) == k): if z > 0: print((0)) exit() else: print((-prod(p) * prod(n) % mod)) exit() q = [] n = n[::-1] for i in range(len(n) // 2): q.append(n[2 * i] * n[2 * i + 1]) p = p[::-1] for i in range(len(p) // 2): q.append(p[2 * i] * p[2 * i + 1]) q.sort(reverse=True) ans = ans * (prod(q[: k // 2])) % mod print((ans % mod)) if __name__ == "__main__": main()
from queue import PriorityQueue import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) mod = 10**9 + 7 def prod(l): ret = 1 for e in l: e %= mod ret = (ret * e) % mod return ret def main(): n, k = geta(int) a = list(geta(int)) p, n, z = [], [], 0 for ai in a: if ai > 0: p.append(ai) elif ai < 0: n.append(-ai) else: z += 1 ans = 1 p.sort() n.sort() if len(p) + len(n) < k: print((0)) exit() elif len(p) + len(n) == k: if len(n) & 1 == 0: print((prod(p) * prod(n) % mod)) exit() else: if z > 0: print((0)) exit() else: print((-prod(p) * prod(n) % mod)) exit() if k & 1 == 1: if len(p) == 0: if z > 0: print((0)) exit() else: print((-prod(n[0:k]) % mod)) exit() else: k -= 1 ans = p.pop() % mod q = [] n = n[::-1] for i in range(len(n) // 2): q.append(n[2 * i] * n[2 * i + 1]) p = p[::-1] for i in range(len(p) // 2): q.append(p[2 * i] * p[2 * i + 1]) q.sort(reverse=True) ans = ans * (prod(q[: k // 2])) % mod print((ans % mod)) if __name__ == "__main__": main()
false
5.494505
[ "+ if len(p) + len(n) < k:", "+ print((0))", "+ exit()", "+ elif len(p) + len(n) == k:", "+ if len(n) & 1 == 0:", "+ print((prod(p) * prod(n) % mod))", "+ exit()", "+ else:", "+ if z > 0:", "+ print((0))", "+ exit()", "+ else:", "+ print((-prod(p) * prod(n) % mod))", "+ exit()", "- if len(p) + len(n) < k:", "- print((0))", "- exit()", "- if len(n) & 1 == 1 and (len(p) + len(n) == k):", "- if z > 0:", "- print((0))", "- exit()", "- else:", "- print((-prod(p) * prod(n) % mod))", "- exit()" ]
false
0.038536
0.035899
1.073442
[ "s442504606", "s038089845" ]
u130900604
p02647
python
s209681474
s849127411
1,602
376
187,484
178,908
Accepted
Accepted
76.53
# coding: utf-8 # Your code here! import time t1=time.time() def LI():return list(map(int,input().split())) n,k=LI() a=LI() for _ in range(k): tab=[0]*(n) for i in range(n): q=a[i] if 0<=i-q: tab[i-q]+=1 else: tab[0]+=1 if i+q+1<=n-1: tab[i+q+1]-=1 else: pass b=[tab[0]] for i in range(n-1): b.append(tab[i+1]+b[-1]) a=b[:] if time.time()-t1>1.5: print((*a)) exit() print((*a))
# coding: utf-8 # Your code here! import time t1=time.time() def LI():return list(map(int,input().split())) n,k=LI() a=LI() for _ in range(k): tab=[0]*(n) for i in range(n): q=a[i] if 0<=i-q: tab[i-q]+=1 else: tab[0]+=1 if i+q+1<=n-1: tab[i+q+1]-=1 else: pass b=[tab[0]] for i in range(n-1): b.append(tab[i+1]+b[-1]) if a==b: print((*a)) exit() a=b[:] if time.time()-t1>1.5: print((*a)) exit() print((*a))
28
31
538
587
# coding: utf-8 # Your code here! import time t1 = time.time() def LI(): return list(map(int, input().split())) n, k = LI() a = LI() for _ in range(k): tab = [0] * (n) for i in range(n): q = a[i] if 0 <= i - q: tab[i - q] += 1 else: tab[0] += 1 if i + q + 1 <= n - 1: tab[i + q + 1] -= 1 else: pass b = [tab[0]] for i in range(n - 1): b.append(tab[i + 1] + b[-1]) a = b[:] if time.time() - t1 > 1.5: print((*a)) exit() print((*a))
# coding: utf-8 # Your code here! import time t1 = time.time() def LI(): return list(map(int, input().split())) n, k = LI() a = LI() for _ in range(k): tab = [0] * (n) for i in range(n): q = a[i] if 0 <= i - q: tab[i - q] += 1 else: tab[0] += 1 if i + q + 1 <= n - 1: tab[i + q + 1] -= 1 else: pass b = [tab[0]] for i in range(n - 1): b.append(tab[i + 1] + b[-1]) if a == b: print((*a)) exit() a = b[:] if time.time() - t1 > 1.5: print((*a)) exit() print((*a))
false
9.677419
[ "+ if a == b:", "+ print((*a))", "+ exit()" ]
false
0.068604
0.03536
1.940146
[ "s209681474", "s849127411" ]
u359007262
p03448
python
s866357730
s101268310
66
31
3,064
9,180
Accepted
Accepted
53.03
def check(a, b, c, x): test = 500 * a + 100 * b + 50 * c if test > x: return 0 elif test == x: return 1 else: return 0 def resolve(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) result = 0 #これは総当たり… for i in range(a, -1, -1): if 500 * i > x: continue for j in range(b, -1, -1): if 500 * i + 100 * j > x: continue for k in range(c, -1, -1): if 500 * i + 100 * j + 50 * k > x: continue result += check(i, j, k, x) print(result) resolve()
def resolve(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 n = 0 for i in range(a+1): ni = 500*i if ni > x: continue for j in range(b+1): nj = ni + 100*j if nj > x: continue for k in range(c+1): nk = nj + 50*k if nk != x: continue elif nk == x: count += 1 print(count) resolve()
29
23
685
542
def check(a, b, c, x): test = 500 * a + 100 * b + 50 * c if test > x: return 0 elif test == x: return 1 else: return 0 def resolve(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) result = 0 # これは総当たり… for i in range(a, -1, -1): if 500 * i > x: continue for j in range(b, -1, -1): if 500 * i + 100 * j > x: continue for k in range(c, -1, -1): if 500 * i + 100 * j + 50 * k > x: continue result += check(i, j, k, x) print(result) resolve()
def resolve(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 n = 0 for i in range(a + 1): ni = 500 * i if ni > x: continue for j in range(b + 1): nj = ni + 100 * j if nj > x: continue for k in range(c + 1): nk = nj + 50 * k if nk != x: continue elif nk == x: count += 1 print(count) resolve()
false
20.689655
[ "-def check(a, b, c, x):", "- test = 500 * a + 100 * b + 50 * c", "- if test > x:", "- return 0", "- elif test == x:", "- return 1", "- else:", "- return 0", "-", "-", "- result = 0", "- # これは総当たり…", "- for i in range(a, -1, -1):", "- if 500 * i > x:", "+ count = 0", "+ n = 0", "+ for i in range(a + 1):", "+ ni = 500 * i", "+ if ni > x:", "- for j in range(b, -1, -1):", "- if 500 * i + 100 * j > x:", "+ for j in range(b + 1):", "+ nj = ni + 100 * j", "+ if nj > x:", "- for k in range(c, -1, -1):", "- if 500 * i + 100 * j + 50 * k > x:", "+ for k in range(c + 1):", "+ nk = nj + 50 * k", "+ if nk != x:", "- result += check(i, j, k, x)", "- print(result)", "+ elif nk == x:", "+ count += 1", "+ print(count)" ]
false
0.049766
0.039353
1.26462
[ "s866357730", "s101268310" ]
u811841526
p02412
python
s314914682
s640428619
520
460
7,656
5,596
Accepted
Accepted
11.54
while True: n, x = list(map(int, input().split())) if n == 0: break count = 0 for n1 in range(1, n+1): for n2 in range(n1+1, n+1): for n3 in range(n2+1, n+1): if n1 + n2 + n3 == x: count += 1 print(count)
while True: n, x = list(map(int, input().split())) if n == 0 and x == 0: break count = 0 for i in range(1, n+1): for j in range(i+1, n+1): for k in range(j+1, n+1): if i + k + j == x: count += 1 print(count)
13
13
296
300
while True: n, x = list(map(int, input().split())) if n == 0: break count = 0 for n1 in range(1, n + 1): for n2 in range(n1 + 1, n + 1): for n3 in range(n2 + 1, n + 1): if n1 + n2 + n3 == x: count += 1 print(count)
while True: n, x = list(map(int, input().split())) if n == 0 and x == 0: break count = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): for k in range(j + 1, n + 1): if i + k + j == x: count += 1 print(count)
false
0
[ "- if n == 0:", "+ if n == 0 and x == 0:", "- for n1 in range(1, n + 1):", "- for n2 in range(n1 + 1, n + 1):", "- for n3 in range(n2 + 1, n + 1):", "- if n1 + n2 + n3 == x:", "+ for i in range(1, n + 1):", "+ for j in range(i + 1, n + 1):", "+ for k in range(j + 1, n + 1):", "+ if i + k + j == x:" ]
false
0.048332
0.04756
1.016222
[ "s314914682", "s640428619" ]
u699089116
p03611
python
s252684645
s991337035
226
84
56,900
20,808
Accepted
Accepted
62.83
from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) a = [i+1 for i in a] imos = [0] * (10**5 + 3) for i in a: imos[i-1] += 1 imos[i+2] -= 1 i = accumulate(imos) print((max(i)))
N = int(eval(input())) A = list(map(int, input().split())) A = [i + 1 for i in A] bucket = [0] * (10 ** 5 + 10) for a in A: bucket[a - 1] += 1 bucket[a] += 1 bucket[a+1] += 1 print((max(bucket)))
13
12
232
213
from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) a = [i + 1 for i in a] imos = [0] * (10**5 + 3) for i in a: imos[i - 1] += 1 imos[i + 2] -= 1 i = accumulate(imos) print((max(i)))
N = int(eval(input())) A = list(map(int, input().split())) A = [i + 1 for i in A] bucket = [0] * (10**5 + 10) for a in A: bucket[a - 1] += 1 bucket[a] += 1 bucket[a + 1] += 1 print((max(bucket)))
false
7.692308
[ "-from itertools import accumulate", "-", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-a = [i + 1 for i in a]", "-imos = [0] * (10**5 + 3)", "-for i in a:", "- imos[i - 1] += 1", "- imos[i + 2] -= 1", "-i = accumulate(imos)", "-print((max(i)))", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+A = [i + 1 for i in A]", "+bucket = [0] * (10**5 + 10)", "+for a in A:", "+ bucket[a - 1] += 1", "+ bucket[a] += 1", "+ bucket[a + 1] += 1", "+print((max(bucket)))" ]
false
0.090952
0.087058
1.044734
[ "s252684645", "s991337035" ]
u633068244
p00152
python
s434962540
s699659918
20
10
4,252
4,244
Accepted
Accepted
50
def bowling(game): game=list(map(int,game.split())) score,thrw=0,1 for flame in range(10): if game[thrw]==10: score+=sum(game[thrw:thrw+3]) thrw+=1 elif game[thrw]+game[thrw+1]==10: score+=10+game[thrw+2] thrw+=2 else: score+=game[thrw]+game[thrw+1] thrw+=2 return game[0],score while 1: n=eval(input()) if n==0:break ls=[bowling(input()) for i in range(n)] for k,s in sorted(sorted(ls),key=lambda x:x[1],reverse=True): print(k,s)
def bowling(game): game=list(map(int,game.split())) score,thrw=0,1 for flame in range(10): if game[thrw]==10: score+=sum(game[thrw:thrw+3]) thrw+=1 elif game[thrw]+game[thrw+1]==10: score+=10+game[thrw+2] thrw+=2 else: score+=sum(game[thrw:thrw+2]) thrw+=2 return game[0],score while 1: n=eval(input()) if n==0:break ls=[bowling(input()) for i in range(n)] for k,s in sorted(sorted(ls),key=lambda x:x[1],reverse=1): print(k,s)
21
21
477
473
def bowling(game): game = list(map(int, game.split())) score, thrw = 0, 1 for flame in range(10): if game[thrw] == 10: score += sum(game[thrw : thrw + 3]) thrw += 1 elif game[thrw] + game[thrw + 1] == 10: score += 10 + game[thrw + 2] thrw += 2 else: score += game[thrw] + game[thrw + 1] thrw += 2 return game[0], score while 1: n = eval(input()) if n == 0: break ls = [bowling(input()) for i in range(n)] for k, s in sorted(sorted(ls), key=lambda x: x[1], reverse=True): print(k, s)
def bowling(game): game = list(map(int, game.split())) score, thrw = 0, 1 for flame in range(10): if game[thrw] == 10: score += sum(game[thrw : thrw + 3]) thrw += 1 elif game[thrw] + game[thrw + 1] == 10: score += 10 + game[thrw + 2] thrw += 2 else: score += sum(game[thrw : thrw + 2]) thrw += 2 return game[0], score while 1: n = eval(input()) if n == 0: break ls = [bowling(input()) for i in range(n)] for k, s in sorted(sorted(ls), key=lambda x: x[1], reverse=1): print(k, s)
false
0
[ "- score += game[thrw] + game[thrw + 1]", "+ score += sum(game[thrw : thrw + 2])", "- for k, s in sorted(sorted(ls), key=lambda x: x[1], reverse=True):", "+ for k, s in sorted(sorted(ls), key=lambda x: x[1], reverse=1):" ]
false
0.11462
0.046365
2.472116
[ "s434962540", "s699659918" ]
u952656646
p02912
python
s749197653
s756645118
224
163
14,180
14,180
Accepted
Accepted
27.23
from heapq import heappush, heappop, heapify N,M = list(map(int, input().split())) A = list(map(int, input().split())) heap = [-a for a in A] heapify(heap) for i in range(M): hmax = heappop(heap) heappush(heap, hmax/2) print((sum([int(-x) for x in heap])))
from heapq import heapify, heappush, heappop N, M = list(map(int, input().split())) A = list(map(int, input().split())) A = list([-x for x in A]) heapify(A) for i in range(M): mx = heappop(A) heappush(A, (-1)*(-mx//2)) A = list([-x for x in A]) print((sum(A)))
9
10
269
279
from heapq import heappush, heappop, heapify N, M = list(map(int, input().split())) A = list(map(int, input().split())) heap = [-a for a in A] heapify(heap) for i in range(M): hmax = heappop(heap) heappush(heap, hmax / 2) print((sum([int(-x) for x in heap])))
from heapq import heapify, heappush, heappop N, M = list(map(int, input().split())) A = list(map(int, input().split())) A = list([-x for x in A]) heapify(A) for i in range(M): mx = heappop(A) heappush(A, (-1) * (-mx // 2)) A = list([-x for x in A]) print((sum(A)))
false
10
[ "-from heapq import heappush, heappop, heapify", "+from heapq import heapify, heappush, heappop", "-heap = [-a for a in A]", "-heapify(heap)", "+A = list([-x for x in A])", "+heapify(A)", "- hmax = heappop(heap)", "- heappush(heap, hmax / 2)", "-print((sum([int(-x) for x in heap])))", "+ mx = heappop(A)", "+ heappush(A, (-1) * (-mx // 2))", "+A = list([-x for x in A])", "+print((sum(A)))" ]
false
0.042419
0.060977
0.695649
[ "s749197653", "s756645118" ]
u708019102
p03161
python
s323969814
s269335990
380
350
52,704
52,320
Accepted
Accepted
7.89
N,k = [int(x) for x in input().split()] h = [int(x) for x in input().split()] DP = [1000000000]*N DP[0] = 0 def handan(i,x): if DP[i] > x: DP[i] = x for i in range(1,N): for j in range(min(i,k)): x = DP[i-j-1] + abs(h[i]-h[i-j-1]) handan(i,x) print((DP[N-1]))
N,K = [int(x) for x in input().split()] h = [int(x) for x in input().split()] DP=[100000000000]*(N+1) DP[0] = 0 DP[1] = 0 DP[2] = DP[1] + abs(h[0]-h[1]) for i in range(1,N): for j in range(i+1,min(i+K+1,N+1)): DP[j] = min(DP[j],DP[i]+abs(h[j-1]-h[i-1])) print((DP[N]))
12
10
300
287
N, k = [int(x) for x in input().split()] h = [int(x) for x in input().split()] DP = [1000000000] * N DP[0] = 0 def handan(i, x): if DP[i] > x: DP[i] = x for i in range(1, N): for j in range(min(i, k)): x = DP[i - j - 1] + abs(h[i] - h[i - j - 1]) handan(i, x) print((DP[N - 1]))
N, K = [int(x) for x in input().split()] h = [int(x) for x in input().split()] DP = [100000000000] * (N + 1) DP[0] = 0 DP[1] = 0 DP[2] = DP[1] + abs(h[0] - h[1]) for i in range(1, N): for j in range(i + 1, min(i + K + 1, N + 1)): DP[j] = min(DP[j], DP[i] + abs(h[j - 1] - h[i - 1])) print((DP[N]))
false
16.666667
[ "-N, k = [int(x) for x in input().split()]", "+N, K = [int(x) for x in input().split()]", "-DP = [1000000000] * N", "+DP = [100000000000] * (N + 1)", "-", "-", "-def handan(i, x):", "- if DP[i] > x:", "- DP[i] = x", "-", "-", "+DP[1] = 0", "+DP[2] = DP[1] + abs(h[0] - h[1])", "- for j in range(min(i, k)):", "- x = DP[i - j - 1] + abs(h[i] - h[i - j - 1])", "- handan(i, x)", "-print((DP[N - 1]))", "+ for j in range(i + 1, min(i + K + 1, N + 1)):", "+ DP[j] = min(DP[j], DP[i] + abs(h[j - 1] - h[i - 1]))", "+print((DP[N]))" ]
false
0.059546
0.036869
1.615083
[ "s323969814", "s269335990" ]