user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u764860452
p03048
python
s843584348
s890432945
1,957
1,732
3,060
2,940
Accepted
Accepted
11.5
def solve(): R,G,B,N=list(map(int,input().split())) ans=0 for i in range(N+1): for j in range(N+1): tmp=N-(R*i+G*j) if tmp>=0 and tmp%B==0: ans+=1 print(ans) solve()
def solve(): R,G,B,N=list(map(int,input().split())) ans=0 for i in range(N+1): for j in range(N+1): tmp=N-R*i-G*j if tmp>=0 and tmp%B==0: ans+=1 print(ans) solve()
11
11
234
232
def solve(): R, G, B, N = list(map(int, input().split())) ans = 0 for i in range(N + 1): for j in range(N + 1): tmp = N - (R * i + G * j) if tmp >= 0 and tmp % B == 0: ans += 1 print(ans) solve()
def solve(): R, G, B, N = list(map(int, input().split())) ans = 0 for i in range(N + 1): for j in range(N + 1): tmp = N - R * i - G * j if tmp >= 0 and tmp % B == 0: ans += 1 print(ans) solve()
false
0
[ "- tmp = N - (R * i + G * j)", "+ tmp = N - R * i - G * j" ]
false
0.379693
0.363875
1.043471
[ "s843584348", "s890432945" ]
u623819879
p03240
python
s346014755
s938801266
715
235
3,064
44,656
Accepted
Accepted
67.13
n=int(eval(input())) a=[] for i in range(n): x,y,h=list(map(int,input().split())) a.append([x,y,h]) def hight(inp): cx,cy,x,y,h=inp if h==0: return -1 else: return abs(x-cx)+abs(y-cy)+h for cx in range(101): for cy in range(101): H=set() for i in range(n): h=hight([cx,cy]+a[i]) if h!=-1: H.add(h) if len(H)==1: flg=True for i in H: d=i for i in range(n): x,y,h=a[i] if max(0,d-abs(x-cx)-abs(y-cy))!=h: flg=False if flg: ans=cx,cy,d print((*ans))
n=int(eval(input())) p=[] for i in range(n): p.append(tuple(map(int,input().split()))) p.sort(key=lambda x:-x[2]) for j in range(101): for k in range(101): H=None f=1 for x,y,h in p: if h>0 and H==None: H=h+abs(x-j)+abs(y-k) else: if max(0,H-abs(x-j)-abs(y-k))!=h: f=0 if f: print((j,k,H)) exit()
31
18
705
446
n = int(eval(input())) a = [] for i in range(n): x, y, h = list(map(int, input().split())) a.append([x, y, h]) def hight(inp): cx, cy, x, y, h = inp if h == 0: return -1 else: return abs(x - cx) + abs(y - cy) + h for cx in range(101): for cy in range(101): H = set() for i in range(n): h = hight([cx, cy] + a[i]) if h != -1: H.add(h) if len(H) == 1: flg = True for i in H: d = i for i in range(n): x, y, h = a[i] if max(0, d - abs(x - cx) - abs(y - cy)) != h: flg = False if flg: ans = cx, cy, d print((*ans))
n = int(eval(input())) p = [] for i in range(n): p.append(tuple(map(int, input().split()))) p.sort(key=lambda x: -x[2]) for j in range(101): for k in range(101): H = None f = 1 for x, y, h in p: if h > 0 and H == None: H = h + abs(x - j) + abs(y - k) else: if max(0, H - abs(x - j) - abs(y - k)) != h: f = 0 if f: print((j, k, H)) exit()
false
41.935484
[ "-a = []", "+p = []", "- x, y, h = list(map(int, input().split()))", "- a.append([x, y, h])", "-", "-", "-def hight(inp):", "- cx, cy, x, y, h = inp", "- if h == 0:", "- return -1", "- else:", "- return abs(x - cx) + abs(y - cy) + h", "-", "-", "-for cx in range(101):", "- for cy in range(101):", "- H = set()", "- for i in range(n):", "- h = hight([cx, cy] + a[i])", "- if h != -1:", "- H.add(h)", "- if len(H) == 1:", "- flg = True", "- for i in H:", "- d = i", "- for i in range(n):", "- x, y, h = a[i]", "- if max(0, d - abs(x - cx) - abs(y - cy)) != h:", "- flg = False", "- if flg:", "- ans = cx, cy, d", "-print((*ans))", "+ p.append(tuple(map(int, input().split())))", "+p.sort(key=lambda x: -x[2])", "+for j in range(101):", "+ for k in range(101):", "+ H = None", "+ f = 1", "+ for x, y, h in p:", "+ if h > 0 and H == None:", "+ H = h + abs(x - j) + abs(y - k)", "+ else:", "+ if max(0, H - abs(x - j) - abs(y - k)) != h:", "+ f = 0", "+ if f:", "+ print((j, k, H))", "+ exit()" ]
false
0.160626
0.107968
1.487722
[ "s346014755", "s938801266" ]
u072717685
p02713
python
s710433067
s926357683
1,548
1,429
9,216
9,160
Accepted
Accepted
7.69
from math import gcd def main(): k = int(eval(input())) r = 0 for ia in range(1, k + 1): for ib in range(1, k + 1): for ic in range(1, k + 1): t1 = gcd(ib, ic) r += gcd(t1,ia) print(r) if __name__ == '__main__': main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from math import gcd def main(): k = int(eval(input())) r = 0 for i1 in range(1, k + 1): for i2 in range(1, k + 1): for i3 in range(1, k + 1): t1 = gcd(i1, i2) r += gcd(t1, i3) print(r) if __name__ == '__main__': main()
13
16
297
366
from math import gcd def main(): k = int(eval(input())) r = 0 for ia in range(1, k + 1): for ib in range(1, k + 1): for ic in range(1, k + 1): t1 = gcd(ib, ic) r += gcd(t1, ia) print(r) if __name__ == "__main__": main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from math import gcd def main(): k = int(eval(input())) r = 0 for i1 in range(1, k + 1): for i2 in range(1, k + 1): for i3 in range(1, k + 1): t1 = gcd(i1, i2) r += gcd(t1, i3) print(r) if __name__ == "__main__": main()
false
18.75
[ "+import sys", "+", "+read = sys.stdin.read", "+readlines = sys.stdin.readlines", "- for ia in range(1, k + 1):", "- for ib in range(1, k + 1):", "- for ic in range(1, k + 1):", "- t1 = gcd(ib, ic)", "- r += gcd(t1, ia)", "+ for i1 in range(1, k + 1):", "+ for i2 in range(1, k + 1):", "+ for i3 in range(1, k + 1):", "+ t1 = gcd(i1, i2)", "+ r += gcd(t1, i3)" ]
false
0.207426
0.080565
2.57464
[ "s710433067", "s926357683" ]
u254871849
p03448
python
s643394586
s988670920
53
28
3,060
3,064
Accepted
Accepted
47.17
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = 500*i + 100*j + 50*k if total == x: count += 1 print(count)
# author: kagemeka # created: 2019-11-06 14:53:37(JST) import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): a, b, c, x = (int(i) for i in sys.stdin.read().split()) combination = 0 for i in range(a+1): ta = 500 * i if ta == x: combination += 1 continue elif ta> x: continue for j in range(b+1): tb = 100 * j if ta + tb == x: combination += 1 continue elif ta + tb > x: continue for k in range(c+1): total = ta + tb + 50 * k if total == x: combination += 1 print(combination) if __name__ == "__main__": # execute only if run as a script main()
12
39
245
966
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): total = 500 * i + 100 * j + 50 * k if total == x: count += 1 print(count)
# author: kagemeka # created: 2019-11-06 14:53:37(JST) import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): a, b, c, x = (int(i) for i in sys.stdin.read().split()) combination = 0 for i in range(a + 1): ta = 500 * i if ta == x: combination += 1 continue elif ta > x: continue for j in range(b + 1): tb = 100 * j if ta + tb == x: combination += 1 continue elif ta + tb > x: continue for k in range(c + 1): total = ta + tb + 50 * k if total == x: combination += 1 print(combination) if __name__ == "__main__": # execute only if run as a script main()
false
69.230769
[ "-a = int(eval(input()))", "-b = int(eval(input()))", "-c = int(eval(input()))", "-x = int(eval(input()))", "-count = 0", "-for i in range(a + 1):", "- for j in range(b + 1):", "- for k in range(c + 1):", "- total = 500 * i + 100 * j + 50 * k", "- if total == x:", "- count += 1", "-print(count)", "+# author: kagemeka", "+# created: 2019-11-06 14:53:37(JST)", "+import sys", "+", "+# import collections", "+# import math", "+# import string", "+# import bisect", "+# import re", "+# import itertools", "+# import statistics", "+def main():", "+ a, b, c, x = (int(i) for i in sys.stdin.read().split())", "+ combination = 0", "+ for i in range(a + 1):", "+ ta = 500 * i", "+ if ta == x:", "+ combination += 1", "+ continue", "+ elif ta > x:", "+ continue", "+ for j in range(b + 1):", "+ tb = 100 * j", "+ if ta + tb == x:", "+ combination += 1", "+ continue", "+ elif ta + tb > x:", "+ continue", "+ for k in range(c + 1):", "+ total = ta + tb + 50 * k", "+ if total == x:", "+ combination += 1", "+ print(combination)", "+", "+", "+if __name__ == \"__main__\":", "+ # execute only if run as a script", "+ main()" ]
false
0.140287
0.050765
2.76345
[ "s643394586", "s988670920" ]
u261103969
p02547
python
s750523908
s310825952
65
33
61,860
9,124
Accepted
Accepted
49.23
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) cur = 0 cnt = 0 for _ in range(N): x, y = list(map(int, readline().split())) if x == y: cur += 1 else: cur = 0 cnt = max(cnt, cur) if cnt >= 3: print("Yes") else: print("No") if __name__ == '__main__': main()
def judge(): cnt = 0 # 今何連続でゾロ目が出ているか記録しておきます for _ in range(N): x, y = list(map(int, input().split())) if x == y: # ゾロ目ストリークが1増えました cnt += 1 else: # ゾロ目ストリークが切れました cnt = 0 if cnt == 3: # 3連続になった瞬間、return True していいです return True # ダメでした return False N = int(eval(input())) if judge(): print("Yes") else: print("No")
29
25
479
465
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N = int(readline()) cur = 0 cnt = 0 for _ in range(N): x, y = list(map(int, readline().split())) if x == y: cur += 1 else: cur = 0 cnt = max(cnt, cur) if cnt >= 3: print("Yes") else: print("No") if __name__ == "__main__": main()
def judge(): cnt = 0 # 今何連続でゾロ目が出ているか記録しておきます for _ in range(N): x, y = list(map(int, input().split())) if x == y: # ゾロ目ストリークが1増えました cnt += 1 else: # ゾロ目ストリークが切れました cnt = 0 if cnt == 3: # 3連続になった瞬間、return True していいです return True # ダメでした return False N = int(eval(input())) if judge(): print("Yes") else: print("No")
false
13.793103
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "+def judge():", "+ cnt = 0 # 今何連続でゾロ目が出ているか記録しておきます", "+ for _ in range(N):", "+ x, y = list(map(int, input().split()))", "+ if x == y:", "+ # ゾロ目ストリークが1増えました", "+ cnt += 1", "+ else:", "+ # ゾロ目ストリークが切れました", "+ cnt = 0", "+ if cnt == 3:", "+ # 3連続になった瞬間、return True していいです", "+ return True", "+ # ダメでした", "+ return False", "-def main():", "- N = int(readline())", "- cur = 0", "- cnt = 0", "- for _ in range(N):", "- x, y = list(map(int, readline().split()))", "- if x == y:", "- cur += 1", "- else:", "- cur = 0", "- cnt = max(cnt, cur)", "- if cnt >= 3:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = int(eval(input()))", "+if judge():", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.047273
0.043542
1.085686
[ "s750523908", "s310825952" ]
u301461168
p02265
python
s473278924
s544912141
4,280
2,220
71,896
71,892
Accepted
Accepted
48.13
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): in_command = input().rstrip().split(" ") if in_command[0] == "insert": output_str.appendleft(in_command[1]) elif in_command[0] == "delete": try: output_str.remove(in_command[1]) except: pass elif in_command[0] == "deleteFirst": output_str.popleft() elif in_command[0] == "deleteLast": output_str.pop() print((" ".join(output_str)))
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): in_command = sys.stdin.readline().rstrip().split(" ") if in_command[0] == "insert": output_str.appendleft(in_command[1]) elif in_command[0] == "delete": if output_str.count(in_command[1]) > 0: output_str.remove(in_command[1]) elif in_command[0] == "deleteFirst": output_str.popleft() elif in_command[0] == "deleteLast": output_str.pop() print((" ".join(output_str)))
23
20
575
582
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): in_command = input().rstrip().split(" ") if in_command[0] == "insert": output_str.appendleft(in_command[1]) elif in_command[0] == "delete": try: output_str.remove(in_command[1]) except: pass elif in_command[0] == "deleteFirst": output_str.popleft() elif in_command[0] == "deleteLast": output_str.pop() print((" ".join(output_str)))
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): in_command = sys.stdin.readline().rstrip().split(" ") if in_command[0] == "insert": output_str.appendleft(in_command[1]) elif in_command[0] == "delete": if output_str.count(in_command[1]) > 0: output_str.remove(in_command[1]) elif in_command[0] == "deleteFirst": output_str.popleft() elif in_command[0] == "deleteLast": output_str.pop() print((" ".join(output_str)))
false
13.043478
[ "- in_command = input().rstrip().split(\" \")", "+ in_command = sys.stdin.readline().rstrip().split(\" \")", "- try:", "+ if output_str.count(in_command[1]) > 0:", "- except:", "- pass" ]
false
0.046498
0.087114
0.533764
[ "s473278924", "s544912141" ]
u645250356
p02714
python
s560441376
s901997195
393
181
74,300
73,264
Accepted
Accepted
53.94
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) ss = [0] * n for i,t in enumerate(s): if t == 'R': ss[i] = 0 elif t == 'G': ss[i] = 1 else: ss[i] = 2 color = [[0] * 3 for _ in range(n)] color[0][ss[0]] = 1 for i,t in enumerate(ss): if i == 0: continue for j in range(3): if t == j: color[i][j] = color[i-1][j] + 1 else: color[i][j] = color[i-1][j] res = 0 for i in range(n-1): for j in range(i+1,n): if ss[i] == ss[j]: continue c = j-i yet = -1 for _ in range(3): if ss[i] == _ or ss[j] == _ : continue yet = _ res += color[-1][yet] - color[j][yet] if j+c < n and ss[j+c] == yet: res -= 1 print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) r = s.count('R') g = s.count('G') b = s.count('B') res = r*g*b for i in range(n-1): for j in range(i+1,n): k = 2*j - i if k < n : if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: res -= 1 print(res)
44
22
1,140
606
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) ss = [0] * n for i, t in enumerate(s): if t == "R": ss[i] = 0 elif t == "G": ss[i] = 1 else: ss[i] = 2 color = [[0] * 3 for _ in range(n)] color[0][ss[0]] = 1 for i, t in enumerate(ss): if i == 0: continue for j in range(3): if t == j: color[i][j] = color[i - 1][j] + 1 else: color[i][j] = color[i - 1][j] res = 0 for i in range(n - 1): for j in range(i + 1, n): if ss[i] == ss[j]: continue c = j - i yet = -1 for _ in range(3): if ss[i] == _ or ss[j] == _: continue yet = _ res += color[-1][yet] - color[j][yet] if j + c < n and ss[j + c] == yet: res -= 1 print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) r = s.count("R") g = s.count("G") b = s.count("B") res = r * g * b for i in range(n - 1): for j in range(i + 1, n): k = 2 * j - i if k < n: if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: res -= 1 print(res)
false
50
[ "-ss = [0] * n", "-for i, t in enumerate(s):", "- if t == \"R\":", "- ss[i] = 0", "- elif t == \"G\":", "- ss[i] = 1", "- else:", "- ss[i] = 2", "-color = [[0] * 3 for _ in range(n)]", "-color[0][ss[0]] = 1", "-for i, t in enumerate(ss):", "- if i == 0:", "- continue", "- for j in range(3):", "- if t == j:", "- color[i][j] = color[i - 1][j] + 1", "- else:", "- color[i][j] = color[i - 1][j]", "-res = 0", "+r = s.count(\"R\")", "+g = s.count(\"G\")", "+b = s.count(\"B\")", "+res = r * g * b", "- if ss[i] == ss[j]:", "- continue", "- c = j - i", "- yet = -1", "- for _ in range(3):", "- if ss[i] == _ or ss[j] == _:", "- continue", "- yet = _", "- res += color[-1][yet] - color[j][yet]", "- if j + c < n and ss[j + c] == yet:", "- res -= 1", "+ k = 2 * j - i", "+ if k < n:", "+ if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:", "+ res -= 1" ]
false
0.036796
0.036515
1.00772
[ "s560441376", "s901997195" ]
u826929627
p02756
python
s530900870
s555000850
451
411
8,436
8,436
Accepted
Accepted
8.87
from collections import deque S = eval(input()) Q = int(eval(input())) S = deque(S) cnt_reverse = 0 for q in range(Q): _ = eval(input()) if _[0] == '1': cnt_reverse += 1 else: _T, _F, _C = _.split() ## リバース回数が奇数偶数のいずれかをチェック if _F == '1': if cnt_reverse % 2 == 0: S.appendleft(_C) else: S.append(_C) else: if cnt_reverse % 2 == 0: S.append(_C) else: S.appendleft(_C) S = list(S) # reverseの部分を対応 if cnt_reverse % 2 == 1: S.reverse() print((''.join(S)))
from collections import deque S = eval(input()) Q = int(eval(input())) S = deque(S) flg_reverse = False for q in range(Q): _ = eval(input()) if _[0] == '1': flg_reverse = flg_reverse ^ True else: _T, _F, _C = _.split() ## リバース回数が奇数偶数のいずれかをチェック if _F == '1': if flg_reverse: S.append(_C) else: S.appendleft(_C) else: if flg_reverse: S.appendleft(_C) else: S.append(_C) S = list(S) # reverseの部分を対応 if flg_reverse: S.reverse() print((''.join(S)))
32
32
550
556
from collections import deque S = eval(input()) Q = int(eval(input())) S = deque(S) cnt_reverse = 0 for q in range(Q): _ = eval(input()) if _[0] == "1": cnt_reverse += 1 else: _T, _F, _C = _.split() ## リバース回数が奇数偶数のいずれかをチェック if _F == "1": if cnt_reverse % 2 == 0: S.appendleft(_C) else: S.append(_C) else: if cnt_reverse % 2 == 0: S.append(_C) else: S.appendleft(_C) S = list(S) # reverseの部分を対応 if cnt_reverse % 2 == 1: S.reverse() print(("".join(S)))
from collections import deque S = eval(input()) Q = int(eval(input())) S = deque(S) flg_reverse = False for q in range(Q): _ = eval(input()) if _[0] == "1": flg_reverse = flg_reverse ^ True else: _T, _F, _C = _.split() ## リバース回数が奇数偶数のいずれかをチェック if _F == "1": if flg_reverse: S.append(_C) else: S.appendleft(_C) else: if flg_reverse: S.appendleft(_C) else: S.append(_C) S = list(S) # reverseの部分を対応 if flg_reverse: S.reverse() print(("".join(S)))
false
0
[ "-cnt_reverse = 0", "+flg_reverse = False", "- cnt_reverse += 1", "+ flg_reverse = flg_reverse ^ True", "- if cnt_reverse % 2 == 0:", "+ if flg_reverse:", "+ S.append(_C)", "+ else:", "+ S.appendleft(_C)", "+ else:", "+ if flg_reverse:", "- else:", "- if cnt_reverse % 2 == 0:", "- S.append(_C)", "- else:", "- S.appendleft(_C)", "-if cnt_reverse % 2 == 1:", "+if flg_reverse:" ]
false
0.040239
0.040412
0.9957
[ "s530900870", "s555000850" ]
u392319141
p03078
python
s350505167
s324409324
780
44
4,468
5,236
Accepted
Accepted
94.36
from heapq import heappop , heappush X , Y , Z , K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) # それぞれソート A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) # 処理済みフラグ confilm = [] q = [(-(A[0] + B[0] + C[0]) , 0,0,0)] for _ in range(K) : val , i , j , k = heappop(q) print((-val)) t = (i+1,j,k) if i + 1 < X and not t in confilm : heappush(q,(-(A[i+1] + B[j] + C[k]),) + t) confilm.append(t) t = (i,j+1,k) if j + 1 < Y and not t in confilm : heappush(q,(-(A[i] + B[j+1] + C[k]),) + t) confilm.append(t) t = (i,j,k+1) if k + 1 < Z and not t in confilm : heappush(q,(-(A[i] + B[j] + C[k+1]),) + t) confilm.append(t)
from heapq import heappush, heappop X, Y, Z, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) V = set() que = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] V.add((0, 0, 0)) ans = [] for _ in range(K): val, a, b, c = heappop(que) ans.append(-val) for x, y, z in [(0, 0, 1), (0, 1, 0), (1, 0, 0)]: x = min(a + x, X - 1) y = min(b + y, Y - 1) z = min(c + z, Z - 1) if not (x, y, z) in V: heappush(que, (-(A[x] + B[y] + C[z]), x, y, z)) V.add((x, y, z)) print(*ans, sep='\n')
39
28
841
712
from heapq import heappop, heappush X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # それぞれソート A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) # 処理済みフラグ confilm = [] q = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] for _ in range(K): val, i, j, k = heappop(q) print((-val)) t = (i + 1, j, k) if i + 1 < X and not t in confilm: heappush(q, (-(A[i + 1] + B[j] + C[k]),) + t) confilm.append(t) t = (i, j + 1, k) if j + 1 < Y and not t in confilm: heappush(q, (-(A[i] + B[j + 1] + C[k]),) + t) confilm.append(t) t = (i, j, k + 1) if k + 1 < Z and not t in confilm: heappush(q, (-(A[i] + B[j] + C[k + 1]),) + t) confilm.append(t)
from heapq import heappush, heappop X, Y, Z, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) V = set() que = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] V.add((0, 0, 0)) ans = [] for _ in range(K): val, a, b, c = heappop(que) ans.append(-val) for x, y, z in [(0, 0, 1), (0, 1, 0), (1, 0, 0)]: x = min(a + x, X - 1) y = min(b + y, Y - 1) z = min(c + z, Z - 1) if not (x, y, z) in V: heappush(que, (-(A[x] + B[y] + C[z]), x, y, z)) V.add((x, y, z)) print(*ans, sep="\n")
false
28.205128
[ "-from heapq import heappop, heappush", "+from heapq import heappush, heappop", "-X, Y, Z, K = list(map(int, input().split()))", "+X, Y, Z, K = map(int, input().split())", "-# それぞれソート", "-# 処理済みフラグ", "-confilm = []", "-q = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]", "+V = set()", "+que = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]", "+V.add((0, 0, 0))", "+ans = []", "- val, i, j, k = heappop(q)", "- print((-val))", "- t = (i + 1, j, k)", "- if i + 1 < X and not t in confilm:", "- heappush(q, (-(A[i + 1] + B[j] + C[k]),) + t)", "- confilm.append(t)", "- t = (i, j + 1, k)", "- if j + 1 < Y and not t in confilm:", "- heappush(q, (-(A[i] + B[j + 1] + C[k]),) + t)", "- confilm.append(t)", "- t = (i, j, k + 1)", "- if k + 1 < Z and not t in confilm:", "- heappush(q, (-(A[i] + B[j] + C[k + 1]),) + t)", "- confilm.append(t)", "+ val, a, b, c = heappop(que)", "+ ans.append(-val)", "+ for x, y, z in [(0, 0, 1), (0, 1, 0), (1, 0, 0)]:", "+ x = min(a + x, X - 1)", "+ y = min(b + y, Y - 1)", "+ z = min(c + z, Z - 1)", "+ if not (x, y, z) in V:", "+ heappush(que, (-(A[x] + B[y] + C[z]), x, y, z))", "+ V.add((x, y, z))", "+print(*ans, sep=\"\\n\")" ]
false
0.035316
0.035186
1.003711
[ "s350505167", "s324409324" ]
u508486691
p03634
python
s682940583
s780800662
897
814
124,252
115,420
Accepted
Accepted
9.25
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return list(map(list, list(zip(*read_all)))) ################# from heapq import heappop, heappush def dijkstra(E,s,n): d = [float('inf')]*n d[s] = 0 q = [] heappush(q,(0,s)) while q: du,u = heappop(q) if d[u] < du: continue for v,weight in list(E[u].items()): dnew = du + weight if d[v] > dnew: d[v] = dnew heappush(q,(dnew,v)) return d N = I() a,b,c = LIR(N-1,3) Q,K = LI() x,y = LIR(Q,2) E = [dict() for _ in range(N)] for i in range(N-1): E[a[i]-1][b[i]-1] = c[i] E[b[i]-1][a[i]-1] = c[i] d = dijkstra(E,K-1,N) for i in range(Q): print((d[x[i]-1]+d[y[i]-1]))
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return list(map(list, list(zip(*read_all)))) ################# from heapq import heappop, heappush def dijkstra(E,s,n,inf=float('inf')): d = [inf]*n d[s] = 0 q = [] heappush(q,(0,s)) while q: du,u = heappop(q) if d[u] < du: continue for v,dist in E[u]: dnew = du + dist if d[v] > dnew: d[v] = dnew heappush(q,(dnew,v)) return d N = I() a,b,c = LIR(N-1,3) Q,K = LI() x,y = LIR(Q,2) E = [[] for _ in range(N)] for i in range(N-1): E[a[i]-1].append((b[i]-1,c[i])) E[b[i]-1].append((a[i]-1,c[i])) d = dijkstra(E,K-1,N,inf=10**9*(N-1)+1) for i in range(Q): print((d[x[i]-1]+d[y[i]-1]))
55
55
1,209
1,233
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def LIR(row, col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return list(map(list, list(zip(*read_all)))) ################# from heapq import heappop, heappush def dijkstra(E, s, n): d = [float("inf")] * n d[s] = 0 q = [] heappush(q, (0, s)) while q: du, u = heappop(q) if d[u] < du: continue for v, weight in list(E[u].items()): dnew = du + weight if d[v] > dnew: d[v] = dnew heappush(q, (dnew, v)) return d N = I() a, b, c = LIR(N - 1, 3) Q, K = LI() x, y = LIR(Q, 2) E = [dict() for _ in range(N)] for i in range(N - 1): E[a[i] - 1][b[i] - 1] = c[i] E[b[i] - 1][a[i] - 1] = c[i] d = dijkstra(E, K - 1, N) for i in range(Q): print((d[x[i] - 1] + d[y[i] - 1]))
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def LIR(row, col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return list(map(list, list(zip(*read_all)))) ################# from heapq import heappop, heappush def dijkstra(E, s, n, inf=float("inf")): d = [inf] * n d[s] = 0 q = [] heappush(q, (0, s)) while q: du, u = heappop(q) if d[u] < du: continue for v, dist in E[u]: dnew = du + dist if d[v] > dnew: d[v] = dnew heappush(q, (dnew, v)) return d N = I() a, b, c = LIR(N - 1, 3) Q, K = LI() x, y = LIR(Q, 2) E = [[] for _ in range(N)] for i in range(N - 1): E[a[i] - 1].append((b[i] - 1, c[i])) E[b[i] - 1].append((a[i] - 1, c[i])) d = dijkstra(E, K - 1, N, inf=10**9 * (N - 1) + 1) for i in range(Q): print((d[x[i] - 1] + d[y[i] - 1]))
false
0
[ "-def dijkstra(E, s, n):", "- d = [float(\"inf\")] * n", "+def dijkstra(E, s, n, inf=float(\"inf\")):", "+ d = [inf] * n", "- for v, weight in list(E[u].items()):", "- dnew = du + weight", "+ for v, dist in E[u]:", "+ dnew = du + dist", "-E = [dict() for _ in range(N)]", "+E = [[] for _ in range(N)]", "- E[a[i] - 1][b[i] - 1] = c[i]", "- E[b[i] - 1][a[i] - 1] = c[i]", "-d = dijkstra(E, K - 1, N)", "+ E[a[i] - 1].append((b[i] - 1, c[i]))", "+ E[b[i] - 1].append((a[i] - 1, c[i]))", "+d = dijkstra(E, K - 1, N, inf=10**9 * (N - 1) + 1)" ]
false
0.036582
0.036545
1.000999
[ "s682940583", "s780800662" ]
u339199690
p02724
python
s535315973
s818273803
486
29
3,060
8,960
Accepted
Accepted
94.03
x = int(eval(input())) count = 0 count_2 = 0 while x > 0: if (x >= 500): x -= 500 count += 1 else: break while x > 0: if (x >= 5): x -= 5 count_2 += 1 else: break print((1000 * count + 5 * count_2))
X = int(eval(input())) res = X // 500 * 1000 X %= 500 res += X // 5 * 5 print(res)
18
7
273
85
x = int(eval(input())) count = 0 count_2 = 0 while x > 0: if x >= 500: x -= 500 count += 1 else: break while x > 0: if x >= 5: x -= 5 count_2 += 1 else: break print((1000 * count + 5 * count_2))
X = int(eval(input())) res = X // 500 * 1000 X %= 500 res += X // 5 * 5 print(res)
false
61.111111
[ "-x = int(eval(input()))", "-count = 0", "-count_2 = 0", "-while x > 0:", "- if x >= 500:", "- x -= 500", "- count += 1", "- else:", "- break", "-while x > 0:", "- if x >= 5:", "- x -= 5", "- count_2 += 1", "- else:", "- break", "-print((1000 * count + 5 * count_2))", "+X = int(eval(input()))", "+res = X // 500 * 1000", "+X %= 500", "+res += X // 5 * 5", "+print(res)" ]
false
0.415441
0.036584
11.355767
[ "s535315973", "s818273803" ]
u325282913
p03162
python
s322623229
s471843620
675
514
60,396
22,796
Accepted
Accepted
23.85
N = int(eval(input())) dp = [[0] * 3 for _ in range(N)] action = list(map(int, input().split())) dp[0][0] = action[0] dp[0][1] = action[1] dp[0][2] = action[2] for i in range(N-1): action = list(map(int, input().split())) dp[i+1][0] = max(dp[i][1]+action[0],dp[i][2]+action[0]) dp[i+1][1] = max(dp[i][0]+action[1],dp[i][2]+action[1]) dp[i+1][2] = max(dp[i][0]+action[2],dp[i][1]+action[2]) print((max(dp[N-1])))
N = int(eval(input())) dp = [[0] * 3 for _ in range(N)] dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split())) for i in range(1,N): a, b, c= list(map(int, input().split())) dp[i][0] = max(dp[i-1][1]+a,dp[i-1][2]+a) dp[i][1] = max(dp[i-1][0]+b,dp[i-1][2]+b) dp[i][2] = max(dp[i-1][1]+c,dp[i-1][0]+c) print((max(dp[N-1])))
12
9
430
332
N = int(eval(input())) dp = [[0] * 3 for _ in range(N)] action = list(map(int, input().split())) dp[0][0] = action[0] dp[0][1] = action[1] dp[0][2] = action[2] for i in range(N - 1): action = list(map(int, input().split())) dp[i + 1][0] = max(dp[i][1] + action[0], dp[i][2] + action[0]) dp[i + 1][1] = max(dp[i][0] + action[1], dp[i][2] + action[1]) dp[i + 1][2] = max(dp[i][0] + action[2], dp[i][1] + action[2]) print((max(dp[N - 1])))
N = int(eval(input())) dp = [[0] * 3 for _ in range(N)] dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split())) for i in range(1, N): a, b, c = list(map(int, input().split())) dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a) dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b) dp[i][2] = max(dp[i - 1][1] + c, dp[i - 1][0] + c) print((max(dp[N - 1])))
false
25
[ "-action = list(map(int, input().split()))", "-dp[0][0] = action[0]", "-dp[0][1] = action[1]", "-dp[0][2] = action[2]", "-for i in range(N - 1):", "- action = list(map(int, input().split()))", "- dp[i + 1][0] = max(dp[i][1] + action[0], dp[i][2] + action[0])", "- dp[i + 1][1] = max(dp[i][0] + action[1], dp[i][2] + action[1])", "- dp[i + 1][2] = max(dp[i][0] + action[2], dp[i][1] + action[2])", "+dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))", "+for i in range(1, N):", "+ a, b, c = list(map(int, input().split()))", "+ dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)", "+ dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)", "+ dp[i][2] = max(dp[i - 1][1] + c, dp[i - 1][0] + c)" ]
false
0.068489
0.035747
1.915908
[ "s322623229", "s471843620" ]
u186838327
p03575
python
s765747555
s977006641
198
73
40,304
62,316
Accepted
Accepted
63.13
n, m = list(map(int, input().split())) L = [[0, 0] for _ in range(m)] g = [[] for _ in range(n)] for j in range(m): a, b = list(map(int, input().split())) a, b = a-1, b-1 L[j][0] = a L[j][1] = b from collections import deque ans = 0 for i in range(m): g = [[] for _ in range(n)] for j in range(m): if j == i: continue a = L[j][0] b = L[j][1] g[a].append(b) g[b].append(a) #print(g) s = deque() s.append(0) visit = [-1]*n visit[0] = 0 while s: x = s.pop() for new_x in g[x]: if visit[new_x] == -1: visit[new_x] = visit[x] + 1 s.append(new_x) if min(visit) == -1: ans += 1 print(ans)
n, m = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(m): a, b = list(map(int, input().split())) a, b = a-1, b-1 g[a].append(b) g[b].append(a) def lowlink(g, root=0): n = len(g) order = [n]*n low = [n]*n s = [root] cnt = 1 par = [-1]*n seq = [] while s: v = s.pop() if order[v] != n: continue order[v] = cnt seq.append(v) low[v] = cnt cnt += 1 for u in g[v]: if order[u] < cnt: if par[v] != u: low[v] = min(low[v], order[u]) continue else: par[u] = v s.append(u) child = [[] for _ in range(n)] for v in range(n): if par[v] != -1: child[par[v]].append(v) seq.reverse() for v in seq: for u in child[v]: low[v] = min(low[v], low[u]) # bridge bridge = [] for p in range(n): for c in child[p]: if order[p] < low[c]: bridge.append((p, c)) # articulation points AP = [] for v in range(n): if v == root: if len(child[v]) >= 2: AP.append(v) else: for c in child[v]: if order[v] <= low[c]: AP.append(v) break return AP, bridge _, bridge = lowlink(g, 0) print((len(bridge)))
35
63
777
1,502
n, m = list(map(int, input().split())) L = [[0, 0] for _ in range(m)] g = [[] for _ in range(n)] for j in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 L[j][0] = a L[j][1] = b from collections import deque ans = 0 for i in range(m): g = [[] for _ in range(n)] for j in range(m): if j == i: continue a = L[j][0] b = L[j][1] g[a].append(b) g[b].append(a) # print(g) s = deque() s.append(0) visit = [-1] * n visit[0] = 0 while s: x = s.pop() for new_x in g[x]: if visit[new_x] == -1: visit[new_x] = visit[x] + 1 s.append(new_x) if min(visit) == -1: ans += 1 print(ans)
n, m = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 g[a].append(b) g[b].append(a) def lowlink(g, root=0): n = len(g) order = [n] * n low = [n] * n s = [root] cnt = 1 par = [-1] * n seq = [] while s: v = s.pop() if order[v] != n: continue order[v] = cnt seq.append(v) low[v] = cnt cnt += 1 for u in g[v]: if order[u] < cnt: if par[v] != u: low[v] = min(low[v], order[u]) continue else: par[u] = v s.append(u) child = [[] for _ in range(n)] for v in range(n): if par[v] != -1: child[par[v]].append(v) seq.reverse() for v in seq: for u in child[v]: low[v] = min(low[v], low[u]) # bridge bridge = [] for p in range(n): for c in child[p]: if order[p] < low[c]: bridge.append((p, c)) # articulation points AP = [] for v in range(n): if v == root: if len(child[v]) >= 2: AP.append(v) else: for c in child[v]: if order[v] <= low[c]: AP.append(v) break return AP, bridge _, bridge = lowlink(g, 0) print((len(bridge)))
false
44.444444
[ "-L = [[0, 0] for _ in range(m)]", "-for j in range(m):", "+for i in range(m):", "- L[j][0] = a", "- L[j][1] = b", "-from collections import deque", "+ g[a].append(b)", "+ g[b].append(a)", "-ans = 0", "-for i in range(m):", "- g = [[] for _ in range(n)]", "- for j in range(m):", "- if j == i:", "+", "+def lowlink(g, root=0):", "+ n = len(g)", "+ order = [n] * n", "+ low = [n] * n", "+ s = [root]", "+ cnt = 1", "+ par = [-1] * n", "+ seq = []", "+ while s:", "+ v = s.pop()", "+ if order[v] != n:", "- a = L[j][0]", "- b = L[j][1]", "- g[a].append(b)", "- g[b].append(a)", "- # print(g)", "- s = deque()", "- s.append(0)", "- visit = [-1] * n", "- visit[0] = 0", "- while s:", "- x = s.pop()", "- for new_x in g[x]:", "- if visit[new_x] == -1:", "- visit[new_x] = visit[x] + 1", "- s.append(new_x)", "- if min(visit) == -1:", "- ans += 1", "-print(ans)", "+ order[v] = cnt", "+ seq.append(v)", "+ low[v] = cnt", "+ cnt += 1", "+ for u in g[v]:", "+ if order[u] < cnt:", "+ if par[v] != u:", "+ low[v] = min(low[v], order[u])", "+ continue", "+ else:", "+ par[u] = v", "+ s.append(u)", "+ child = [[] for _ in range(n)]", "+ for v in range(n):", "+ if par[v] != -1:", "+ child[par[v]].append(v)", "+ seq.reverse()", "+ for v in seq:", "+ for u in child[v]:", "+ low[v] = min(low[v], low[u])", "+ # bridge", "+ bridge = []", "+ for p in range(n):", "+ for c in child[p]:", "+ if order[p] < low[c]:", "+ bridge.append((p, c))", "+ # articulation points", "+ AP = []", "+ for v in range(n):", "+ if v == root:", "+ if len(child[v]) >= 2:", "+ AP.append(v)", "+ else:", "+ for c in child[v]:", "+ if order[v] <= low[c]:", "+ AP.append(v)", "+ break", "+ return AP, bridge", "+", "+", "+_, bridge = lowlink(g, 0)", "+print((len(bridge)))" ]
false
0.057098
0.080498
0.709302
[ "s765747555", "s977006641" ]
u642874916
p02900
python
s509022256
s346772997
354
311
67,944
67,692
Accepted
Accepted
12.15
from fractions import gcd import itertools import sys input = sys.stdin.readline #nの素数判定 def is_prime(n): if n == 1: return False for i in range(2,int(n**0.5)+1): if n % i == 0: return False return True #nの約数列挙 def divisor(n): ass = [] for i in range(1,int(n**0.5)+1): if n%i == 0: ass.append(i) if i**2 == n: continue ass.append(n//i) return ass def coprime(a, b): return gcd(a, b) == 1 def main(): A, B = list(map(int, input().split())) # print(gcd(A, B)) da = sorted(divisor(A)) db = sorted(divisor(B)) cd = [] for i in da: if i in db: cd.append(i) # print(cd) li = [] # c = itertools.combinations(cd, 2) for i in cd: if i == 1: li.append(i) continue flg = True for c in li: if not coprime(i, c): flg = False if flg: li.append(i) # print(li) print((len(li))) if __name__ == '__main__': main()
from fractions import gcd import itertools import sys input = sys.stdin.readline # nの素数判定 def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5)+1): if n % i == 0: return False return True # nの約数列挙 def divisor(n): ass = [] for i in range(1, int(n**0.5)+1): if n % i == 0: ass.append(i) if i**2 == n: continue ass.append(n//i) return ass # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def coprime(a, b): return gcd(a, b) == 1 def main(): A, B = list(map(int, input().split())) gcdab = gcd(A, B) cd = divisor(gcdab) # print(factorization(gcdab)) # print(cd) # da = sorted(divisor(A)) # db = sorted(divisor(B)) # cd = [] # for i in da: # if i in db: # cd.append(i) ans = 0 for i in cd: if is_prime(i) or i == 1: ans += 1 print(ans) # print(cd) # li = [] # # c = itertools.combinations(cd, 2) # for i in cd: # if i == 1: # li.append(i) # continue # flg = True # for c in li: # if not coprime(i, c): # flg = False # if flg: # li.append(i) # # print(li) # print(len(li)) if __name__ == '__main__': main()
65
97
1,151
1,782
from fractions import gcd import itertools import sys input = sys.stdin.readline # nの素数判定 def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True # nの約数列挙 def divisor(n): ass = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: ass.append(i) if i**2 == n: continue ass.append(n // i) return ass def coprime(a, b): return gcd(a, b) == 1 def main(): A, B = list(map(int, input().split())) # print(gcd(A, B)) da = sorted(divisor(A)) db = sorted(divisor(B)) cd = [] for i in da: if i in db: cd.append(i) # print(cd) li = [] # c = itertools.combinations(cd, 2) for i in cd: if i == 1: li.append(i) continue flg = True for c in li: if not coprime(i, c): flg = False if flg: li.append(i) # print(li) print((len(li))) if __name__ == "__main__": main()
from fractions import gcd import itertools import sys input = sys.stdin.readline # nの素数判定 def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True # nの約数列挙 def divisor(n): ass = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: ass.append(i) if i**2 == n: continue ass.append(n // i) return ass # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def coprime(a, b): return gcd(a, b) == 1 def main(): A, B = list(map(int, input().split())) gcdab = gcd(A, B) cd = divisor(gcdab) # print(factorization(gcdab)) # print(cd) # da = sorted(divisor(A)) # db = sorted(divisor(B)) # cd = [] # for i in da: # if i in db: # cd.append(i) ans = 0 for i in cd: if is_prime(i) or i == 1: ans += 1 print(ans) # print(cd) # li = [] # # c = itertools.combinations(cd, 2) # for i in cd: # if i == 1: # li.append(i) # continue # flg = True # for c in li: # if not coprime(i, c): # flg = False # if flg: # li.append(i) # # print(li) # print(len(li)) if __name__ == "__main__": main()
false
32.989691
[ "+# 素因数分解", "+def factorization(n):", "+ arr = []", "+ temp = n", "+ for i in range(2, int(-(-(n**0.5) // 1)) + 1):", "+ if temp % i == 0:", "+ cnt = 0", "+ while temp % i == 0:", "+ cnt += 1", "+ temp //= i", "+ arr.append([i, cnt])", "+ if temp != 1:", "+ arr.append([temp, 1])", "+ if arr == []:", "+ arr.append([n, 1])", "+ return arr", "+", "+", "- # print(gcd(A, B))", "- da = sorted(divisor(A))", "- db = sorted(divisor(B))", "- cd = []", "- for i in da:", "- if i in db:", "- cd.append(i)", "+ gcdab = gcd(A, B)", "+ cd = divisor(gcdab)", "+ # print(factorization(gcdab))", "- li = []", "- # c = itertools.combinations(cd, 2)", "+ # da = sorted(divisor(A))", "+ # db = sorted(divisor(B))", "+ # cd = []", "+ # for i in da:", "+ # if i in db:", "+ # cd.append(i)", "+ ans = 0", "- if i == 1:", "- li.append(i)", "- continue", "- flg = True", "- for c in li:", "- if not coprime(i, c):", "- flg = False", "- if flg:", "- li.append(i)", "- # print(li)", "- print((len(li)))", "+ if is_prime(i) or i == 1:", "+ ans += 1", "+ print(ans)", "+ # print(cd)", "+ # li = []", "+ # # c = itertools.combinations(cd, 2)", "+ # for i in cd:", "+ # if i == 1:", "+ # li.append(i)", "+ # continue", "+ # flg = True", "+ # for c in li:", "+ # if not coprime(i, c):", "+ # flg = False", "+ # if flg:", "+ # li.append(i)", "+ # # print(li)", "+ # print(len(li))" ]
false
0.05803
0.056688
1.023668
[ "s509022256", "s346772997" ]
u057964173
p03380
python
s262834633
s259490338
252
100
62,704
14,436
Accepted
Accepted
60.32
import sys def input(): return sys.stdin.readline().strip() import math def resolve(): n=int(eval(input())) l=list(map(int,input().split())) l.sort(reverse=True) ans=0 jissitu=0 naka=l[0]//2 for i in range(1,n): if l[i]>naka and l[0]-i>jissitu: ans=l[i] jissitu=l[0]-l[i] elif l[i]<=naka and l[i]>jissitu: ans=l[i] jissitu=l[i] print((l[0],ans)) resolve()
import sys def input(): return sys.stdin.readline().strip() import math def resolve(): n=int(eval(input())) l=list(map(int,input().split())) l.sort(reverse=True) a=l[0] l.pop(0) bnum=0 bmax=0 for i in l: bb=min(i,a-i) if bmax<bb: bnum=i bmax=bb print((a,bnum)) resolve()
19
18
461
355
import sys def input(): return sys.stdin.readline().strip() import math def resolve(): n = int(eval(input())) l = list(map(int, input().split())) l.sort(reverse=True) ans = 0 jissitu = 0 naka = l[0] // 2 for i in range(1, n): if l[i] > naka and l[0] - i > jissitu: ans = l[i] jissitu = l[0] - l[i] elif l[i] <= naka and l[i] > jissitu: ans = l[i] jissitu = l[i] print((l[0], ans)) resolve()
import sys def input(): return sys.stdin.readline().strip() import math def resolve(): n = int(eval(input())) l = list(map(int, input().split())) l.sort(reverse=True) a = l[0] l.pop(0) bnum = 0 bmax = 0 for i in l: bb = min(i, a - i) if bmax < bb: bnum = i bmax = bb print((a, bnum)) resolve()
false
5.263158
[ "- ans = 0", "- jissitu = 0", "- naka = l[0] // 2", "- for i in range(1, n):", "- if l[i] > naka and l[0] - i > jissitu:", "- ans = l[i]", "- jissitu = l[0] - l[i]", "- elif l[i] <= naka and l[i] > jissitu:", "- ans = l[i]", "- jissitu = l[i]", "- print((l[0], ans))", "+ a = l[0]", "+ l.pop(0)", "+ bnum = 0", "+ bmax = 0", "+ for i in l:", "+ bb = min(i, a - i)", "+ if bmax < bb:", "+ bnum = i", "+ bmax = bb", "+ print((a, bnum))" ]
false
0.035639
0.035422
1.006129
[ "s262834633", "s259490338" ]
u879870653
p03837
python
s413441865
s129177983
392
179
26,612
14,080
Accepted
Accepted
54.34
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra n,m = list(map(int,input().split())) edges = [[int(x) for x in input().split()] for i in range(m)] graph = [[False]*n for i in range(n)] for a, b, c in edges : graph[a-1][b-1] = c graph = csgraph_from_dense(graph) dist = dijkstra(graph, directed=False).astype(int) ans = 0 for a, b, c in edges : if dist[a-1][b-1] != c : ans += 1 print(ans)
import sys input = sys.stdin.readline from scipy.sparse.csgraph import csgraph_from_dense, dijkstra n,m = list(map(int,input().split())) A = [0]*m B = [0]*m C = [0]*m for i in range(m) : a, b, c = list(map(int,input().split())) A[i] = a-1 B[i] = b-1 C[i] = c graph = [[0]*n for i in range(n)] for i in range(m) : graph[A[i]][B[i]] = C[i] graph[B[i]][A[i]] = C[i] graph = csgraph_from_dense(graph) dist = dijkstra(graph) ans = 0 for i in range(m) : if dist[A[i]][B[i]] != C[i] : ans += 1 print(ans)
17
29
433
556
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra n, m = list(map(int, input().split())) edges = [[int(x) for x in input().split()] for i in range(m)] graph = [[False] * n for i in range(n)] for a, b, c in edges: graph[a - 1][b - 1] = c graph = csgraph_from_dense(graph) dist = dijkstra(graph, directed=False).astype(int) ans = 0 for a, b, c in edges: if dist[a - 1][b - 1] != c: ans += 1 print(ans)
import sys input = sys.stdin.readline from scipy.sparse.csgraph import csgraph_from_dense, dijkstra n, m = list(map(int, input().split())) A = [0] * m B = [0] * m C = [0] * m for i in range(m): a, b, c = list(map(int, input().split())) A[i] = a - 1 B[i] = b - 1 C[i] = c graph = [[0] * n for i in range(n)] for i in range(m): graph[A[i]][B[i]] = C[i] graph[B[i]][A[i]] = C[i] graph = csgraph_from_dense(graph) dist = dijkstra(graph) ans = 0 for i in range(m): if dist[A[i]][B[i]] != C[i]: ans += 1 print(ans)
false
41.37931
[ "+import sys", "+", "+input = sys.stdin.readline", "-edges = [[int(x) for x in input().split()] for i in range(m)]", "-graph = [[False] * n for i in range(n)]", "-for a, b, c in edges:", "- graph[a - 1][b - 1] = c", "+A = [0] * m", "+B = [0] * m", "+C = [0] * m", "+for i in range(m):", "+ a, b, c = list(map(int, input().split()))", "+ A[i] = a - 1", "+ B[i] = b - 1", "+ C[i] = c", "+graph = [[0] * n for i in range(n)]", "+for i in range(m):", "+ graph[A[i]][B[i]] = C[i]", "+ graph[B[i]][A[i]] = C[i]", "-dist = dijkstra(graph, directed=False).astype(int)", "+dist = dijkstra(graph)", "-for a, b, c in edges:", "- if dist[a - 1][b - 1] != c:", "+for i in range(m):", "+ if dist[A[i]][B[i]] != C[i]:" ]
false
0.836591
1.374215
0.608777
[ "s413441865", "s129177983" ]
u339199690
p03546
python
s180346634
s662562727
47
39
9,528
9,420
Accepted
Accepted
17.02
import sys H, W = list(map(int, input().split())) C = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(10)] A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)] for k in range(10): for i in range(10): for j in range(10): if C[i][j] > C[i][k] + C[k][j]: C[i][j] = C[i][k] + C[k][j] res = 0 for i in range(H): for j in range(W): if A[i][j] >= 0: res += C[A[i][j]][1] print(res)
import sys def warshall_floyd(): for k in range(10): for i in range(10): for j in range(10): C[i][j] = min(C[i][j], C[i][k] + C[k][j]) H, W = list(map(int, input().split())) inf = float("inf") C = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(10)] A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)] warshall_floyd() res = 0 for row in A: for col in row: if col != -1: res += C[col][1] print(res)
18
20
484
511
import sys H, W = list(map(int, input().split())) C = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(10)] A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)] for k in range(10): for i in range(10): for j in range(10): if C[i][j] > C[i][k] + C[k][j]: C[i][j] = C[i][k] + C[k][j] res = 0 for i in range(H): for j in range(W): if A[i][j] >= 0: res += C[A[i][j]][1] print(res)
import sys def warshall_floyd(): for k in range(10): for i in range(10): for j in range(10): C[i][j] = min(C[i][j], C[i][k] + C[k][j]) H, W = list(map(int, input().split())) inf = float("inf") C = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(10)] A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)] warshall_floyd() res = 0 for row in A: for col in row: if col != -1: res += C[col][1] print(res)
false
10
[ "+", "+def warshall_floyd():", "+ for k in range(10):", "+ for i in range(10):", "+ for j in range(10):", "+ C[i][j] = min(C[i][j], C[i][k] + C[k][j])", "+", "+", "+inf = float(\"inf\")", "-for k in range(10):", "- for i in range(10):", "- for j in range(10):", "- if C[i][j] > C[i][k] + C[k][j]:", "- C[i][j] = C[i][k] + C[k][j]", "+warshall_floyd()", "-for i in range(H):", "- for j in range(W):", "- if A[i][j] >= 0:", "- res += C[A[i][j]][1]", "+for row in A:", "+ for col in row:", "+ if col != -1:", "+ res += C[col][1]" ]
false
0.074448
0.079346
0.938275
[ "s180346634", "s662562727" ]
u706330549
p02687
python
s316589574
s220919488
23
21
8,924
8,956
Accepted
Accepted
8.7
s = eval(input()) if s == "ABC": print("ARC") else: print("ABC")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines s = read().rstrip().decode() if s == "ABC": print("ARC") else: print("ABC")
6
11
73
212
s = eval(input()) if s == "ABC": print("ARC") else: print("ABC")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines s = read().rstrip().decode() if s == "ABC": print("ARC") else: print("ABC")
false
45.454545
[ "-s = eval(input())", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+s = read().rstrip().decode()" ]
false
0.080162
0.121864
0.6578
[ "s316589574", "s220919488" ]
u102461423
p02989
python
s323021880
s994368220
79
73
14,396
11,660
Accepted
Accepted
7.59
N = int(eval(input())) D = [int(x) for x in input().split()] D.sort() M = N//2 x,y = D[M-1:M+1] answer = y - x print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*D = list(map(int,read().split())) n = N//2 D.sort() answer = D[n] - D[n-1] print(answer)
9
11
128
213
N = int(eval(input())) D = [int(x) for x in input().split()] D.sort() M = N // 2 x, y = D[M - 1 : M + 1] answer = y - x print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *D = list(map(int, read().split())) n = N // 2 D.sort() answer = D[n] - D[n - 1] print(answer)
false
18.181818
[ "-N = int(eval(input()))", "-D = [int(x) for x in input().split()]", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, *D = list(map(int, read().split()))", "+n = N // 2", "-M = N // 2", "-x, y = D[M - 1 : M + 1]", "-answer = y - x", "+answer = D[n] - D[n - 1]" ]
false
0.051604
0.04676
1.103602
[ "s323021880", "s994368220" ]
u049420296
p03637
python
s001862404
s010854887
72
65
14,252
15,020
Accepted
Accepted
9.72
n = int(eval(input())) a = list(map(int, input().split())) cnt2 = 0 cnt4 = 0 for i in range(n): if a[i] % 2 == 0: if a[i] % 4 != 0: cnt2 += 1 else: cnt4 += 1 if cnt2: if ((n-cnt2+1)//2) <= cnt4: print('Yes') else: print('No') else: if (n-cnt2)//2 <= cnt4: print('Yes') else: print('No')
n = int(eval(input())) a = list(map(int, input().split())) cnt2 = cnt4 = 0 for i in a: if i % 2 == 0: if i % 4 != 0: cnt2 += 1 else: cnt4 += 1 if cnt2: if ((n-cnt2+1)//2) <= cnt4: print('Yes') else: print('No') else: if (n-cnt2)//2 <= cnt4: print('Yes') else: print('No')
22
21
396
380
n = int(eval(input())) a = list(map(int, input().split())) cnt2 = 0 cnt4 = 0 for i in range(n): if a[i] % 2 == 0: if a[i] % 4 != 0: cnt2 += 1 else: cnt4 += 1 if cnt2: if ((n - cnt2 + 1) // 2) <= cnt4: print("Yes") else: print("No") else: if (n - cnt2) // 2 <= cnt4: print("Yes") else: print("No")
n = int(eval(input())) a = list(map(int, input().split())) cnt2 = cnt4 = 0 for i in a: if i % 2 == 0: if i % 4 != 0: cnt2 += 1 else: cnt4 += 1 if cnt2: if ((n - cnt2 + 1) // 2) <= cnt4: print("Yes") else: print("No") else: if (n - cnt2) // 2 <= cnt4: print("Yes") else: print("No")
false
4.545455
[ "-cnt2 = 0", "-cnt4 = 0", "-for i in range(n):", "- if a[i] % 2 == 0:", "- if a[i] % 4 != 0:", "+cnt2 = cnt4 = 0", "+for i in a:", "+ if i % 2 == 0:", "+ if i % 4 != 0:" ]
false
0.044167
0.098367
0.448998
[ "s001862404", "s010854887" ]
u645250356
p03043
python
s398670105
s579552464
78
53
3,060
3,060
Accepted
Accepted
32.05
n,k = list(map(int,input().split())) ans = 0 def two(x,y): for i in range(0,10**9): if x >= y: return i x *= 2 for i in range(1,n+1): tmp = 1/n pro = two(i,k) if pro: tmp *= (1/2)**pro else: pass ans += tmp print(ans)
n,k = list(map(int,input().split())) ans = 0 for i in range(1,n+1): tmp = 1/n a = 0 while(i<k): i *= 2 a += 1 ans += (1/n) * ((1/2)**a) print(ans)
17
10
304
181
n, k = list(map(int, input().split())) ans = 0 def two(x, y): for i in range(0, 10**9): if x >= y: return i x *= 2 for i in range(1, n + 1): tmp = 1 / n pro = two(i, k) if pro: tmp *= (1 / 2) ** pro else: pass ans += tmp print(ans)
n, k = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): tmp = 1 / n a = 0 while i < k: i *= 2 a += 1 ans += (1 / n) * ((1 / 2) ** a) print(ans)
false
41.176471
[ "-", "-", "-def two(x, y):", "- for i in range(0, 10**9):", "- if x >= y:", "- return i", "- x *= 2", "-", "-", "- pro = two(i, k)", "- if pro:", "- tmp *= (1 / 2) ** pro", "- else:", "- pass", "- ans += tmp", "+ a = 0", "+ while i < k:", "+ i *= 2", "+ a += 1", "+ ans += (1 / n) * ((1 / 2) ** a)" ]
false
0.071445
0.124919
0.571932
[ "s398670105", "s579552464" ]
u047796752
p03158
python
s763797823
s649698996
1,499
1,369
84,332
83,948
Accepted
Accepted
8.67
import sys input = sys.stdin.readline from bisect import * def judge(x): a = N-x b = x-bisect_left(A, X-(A[x]-X))+1 return a<=b def binary_search(): l, r = bisect_left(A, X), N-1 while l<=r: m = (l+r)//2 if judge(m): r = m-1 else: l = m+1 return l N, Q = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0]*(N+1) eacc = [0]*(N+1) oacc = [0]*(N+1) for i in range(N): acc[i+1] = acc[i]+A[i] if i%2==0: eacc[i+1] = eacc[i]+A[i] oacc[i+1] = oacc[i] else: eacc[i+1] = eacc[i] oacc[i+1] = oacc[i]+A[i] for _ in range(Q): X = int(eval(input())) border = binary_search() ans = acc[N]-acc[border] if N-2*(N-border)>=0: if (N-2*(N-border))%2==0: ans += oacc[N-2*(N-border)] else: ans += eacc[N-2*(N-border)] print(ans)
import sys input = sys.stdin.readline from bisect import * def judge(x): a = N-x b = x-bisect_left(A, X-(A[x]-X))+1 return a<=b def binary_search(): l, r = bisect_left(A, X), N-1 while l<=r: m = (l+r)//2 if judge(m): r = m-1 else: l = m+1 return l N, Q = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0]*(N+1) eacc = [0]*(N+1) for i in range(N): acc[i+1] = acc[i]+A[i] eacc[i+1] = eacc[i]+(A[i] if i%2==0 else 0) for _ in range(Q): X = int(eval(input())) border = binary_search() ans = acc[N]-acc[border] if N-2*(N-border)>=0: if (N-2*(N-border))%2==0: ans += acc[N-2*(N-border)]-eacc[N-2*(N-border)] else: ans += eacc[N-2*(N-border)] print(ans)
51
45
992
890
import sys input = sys.stdin.readline from bisect import * def judge(x): a = N - x b = x - bisect_left(A, X - (A[x] - X)) + 1 return a <= b def binary_search(): l, r = bisect_left(A, X), N - 1 while l <= r: m = (l + r) // 2 if judge(m): r = m - 1 else: l = m + 1 return l N, Q = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) eacc = [0] * (N + 1) oacc = [0] * (N + 1) for i in range(N): acc[i + 1] = acc[i] + A[i] if i % 2 == 0: eacc[i + 1] = eacc[i] + A[i] oacc[i + 1] = oacc[i] else: eacc[i + 1] = eacc[i] oacc[i + 1] = oacc[i] + A[i] for _ in range(Q): X = int(eval(input())) border = binary_search() ans = acc[N] - acc[border] if N - 2 * (N - border) >= 0: if (N - 2 * (N - border)) % 2 == 0: ans += oacc[N - 2 * (N - border)] else: ans += eacc[N - 2 * (N - border)] print(ans)
import sys input = sys.stdin.readline from bisect import * def judge(x): a = N - x b = x - bisect_left(A, X - (A[x] - X)) + 1 return a <= b def binary_search(): l, r = bisect_left(A, X), N - 1 while l <= r: m = (l + r) // 2 if judge(m): r = m - 1 else: l = m + 1 return l N, Q = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) eacc = [0] * (N + 1) for i in range(N): acc[i + 1] = acc[i] + A[i] eacc[i + 1] = eacc[i] + (A[i] if i % 2 == 0 else 0) for _ in range(Q): X = int(eval(input())) border = binary_search() ans = acc[N] - acc[border] if N - 2 * (N - border) >= 0: if (N - 2 * (N - border)) % 2 == 0: ans += acc[N - 2 * (N - border)] - eacc[N - 2 * (N - border)] else: ans += eacc[N - 2 * (N - border)] print(ans)
false
11.764706
[ "-oacc = [0] * (N + 1)", "- if i % 2 == 0:", "- eacc[i + 1] = eacc[i] + A[i]", "- oacc[i + 1] = oacc[i]", "- else:", "- eacc[i + 1] = eacc[i]", "- oacc[i + 1] = oacc[i] + A[i]", "+ eacc[i + 1] = eacc[i] + (A[i] if i % 2 == 0 else 0)", "- ans += oacc[N - 2 * (N - border)]", "+ ans += acc[N - 2 * (N - border)] - eacc[N - 2 * (N - border)]" ]
false
0.048229
0.048664
0.991064
[ "s763797823", "s649698996" ]
u261646994
p02953
python
s724190465
s975905554
211
60
14,252
14,252
Accepted
Accepted
71.56
import sys input = sys.stdin.readline N = int(eval(input())) H = [int(item) for item in input().split()] cand = [] cand += [H[0], H[0] - 1] for i in range(1, N): new_cand = [] for c in cand: if c <= H[i] - 1: new_cand += [H[i], H[i] - 1] elif c == H[i]: new_cand += [H[i]] cand = list(set(new_cand)) if len(cand) == 0: print("No") break else: print("Yes")
import sys input = sys.stdin.readline N = int(eval(input())) H = [int(item) for item in input().split()] c_height = -1 for h in H: if h - 1 >= c_height: c_height = h - 1 elif h == c_height: pass else: print("No") break else: print("Yes")
21
17
448
298
import sys input = sys.stdin.readline N = int(eval(input())) H = [int(item) for item in input().split()] cand = [] cand += [H[0], H[0] - 1] for i in range(1, N): new_cand = [] for c in cand: if c <= H[i] - 1: new_cand += [H[i], H[i] - 1] elif c == H[i]: new_cand += [H[i]] cand = list(set(new_cand)) if len(cand) == 0: print("No") break else: print("Yes")
import sys input = sys.stdin.readline N = int(eval(input())) H = [int(item) for item in input().split()] c_height = -1 for h in H: if h - 1 >= c_height: c_height = h - 1 elif h == c_height: pass else: print("No") break else: print("Yes")
false
19.047619
[ "-cand = []", "-cand += [H[0], H[0] - 1]", "-for i in range(1, N):", "- new_cand = []", "- for c in cand:", "- if c <= H[i] - 1:", "- new_cand += [H[i], H[i] - 1]", "- elif c == H[i]:", "- new_cand += [H[i]]", "- cand = list(set(new_cand))", "- if len(cand) == 0:", "+c_height = -1", "+for h in H:", "+ if h - 1 >= c_height:", "+ c_height = h - 1", "+ elif h == c_height:", "+ pass", "+ else:" ]
false
0.037423
0.037098
1.008754
[ "s724190465", "s975905554" ]
u517447467
p03043
python
s613430923
s220945835
99
53
2,940
3,060
Accepted
Accepted
46.46
import math N, K = list(map(int, input().split())) result = 0 for i in range(1, N+1): result += (1/N) * 0.5 ** math.ceil(math.log(math.ceil(K/i), 2)) print(result)
import math N, K = list(map(int, input().split())) i = 1 result = 0 for i in range(1, N+1): p = 0 while i * (2 ** p) < K: p += 1 result += (1 /N) * (0.5 ** p) print(result)
6
12
170
195
import math N, K = list(map(int, input().split())) result = 0 for i in range(1, N + 1): result += (1 / N) * 0.5 ** math.ceil(math.log(math.ceil(K / i), 2)) print(result)
import math N, K = list(map(int, input().split())) i = 1 result = 0 for i in range(1, N + 1): p = 0 while i * (2**p) < K: p += 1 result += (1 / N) * (0.5**p) print(result)
false
50
[ "+i = 1", "- result += (1 / N) * 0.5 ** math.ceil(math.log(math.ceil(K / i), 2))", "+ p = 0", "+ while i * (2**p) < K:", "+ p += 1", "+ result += (1 / N) * (0.5**p)" ]
false
0.114253
0.161064
0.709362
[ "s613430923", "s220945835" ]
u325704929
p02883
python
s324950763
s001390300
570
403
43,572
37,176
Accepted
Accepted
29.3
import numpy as np def is_ok(mid, k): s = np.maximum(a - mid // f, 0).sum() if s <= k: return True else: return False n, k = list(map(int, input().split())) a = [int(i) for i in input().split()] f = [int(i) for i in input().split()] a.sort() f.sort(reverse=True) a = np.array(a) f = np.array(f) l, r = -1, np.max(a * f) # l:ng, r:ok while l + 1 < r: mid = (l + r) // 2 if is_ok(mid, k): r = mid else: l = mid print(r)
import numpy as np def is_ok(mid, k): s = np.maximum(a - mid // f, 0).sum() if s <= k: return True else: return False n, k = list(map(int, input().split())) a = np.array(list(map(int, input().split()))) f = np.array(list(map(int, input().split()))) a = np.sort(a) f = np.sort(f)[::-1] l, r = -1, np.max(a * f) # l:ng, r:ok while l + 1 < r: mid = (l + r) // 2 if is_ok(mid, k): r = mid else: l = mid print(r)
25
23
494
482
import numpy as np def is_ok(mid, k): s = np.maximum(a - mid // f, 0).sum() if s <= k: return True else: return False n, k = list(map(int, input().split())) a = [int(i) for i in input().split()] f = [int(i) for i in input().split()] a.sort() f.sort(reverse=True) a = np.array(a) f = np.array(f) l, r = -1, np.max(a * f) # l:ng, r:ok while l + 1 < r: mid = (l + r) // 2 if is_ok(mid, k): r = mid else: l = mid print(r)
import numpy as np def is_ok(mid, k): s = np.maximum(a - mid // f, 0).sum() if s <= k: return True else: return False n, k = list(map(int, input().split())) a = np.array(list(map(int, input().split()))) f = np.array(list(map(int, input().split()))) a = np.sort(a) f = np.sort(f)[::-1] l, r = -1, np.max(a * f) # l:ng, r:ok while l + 1 < r: mid = (l + r) // 2 if is_ok(mid, k): r = mid else: l = mid print(r)
false
8
[ "-a = [int(i) for i in input().split()]", "-f = [int(i) for i in input().split()]", "-a.sort()", "-f.sort(reverse=True)", "-a = np.array(a)", "-f = np.array(f)", "+a = np.array(list(map(int, input().split())))", "+f = np.array(list(map(int, input().split())))", "+a = np.sort(a)", "+f = np.sort(f)[::-1]" ]
false
0.243782
0.694738
0.350898
[ "s324950763", "s001390300" ]
u881590806
p02275
python
s889630123
s268911390
2,170
1,530
177,024
241,092
Accepted
Accepted
29.49
n = int(input()) S = list(map(int,input().strip().split(' '))) def counting_sort(S,k): C = [0]*(k+1) B = [0]*len(S) for v in S: C[v] += 1 for i in range(1,k+1): C[i] += C[i-1] for i in range(len(S)): B[C[S[i]]-1] = S[i] C[S[i]] -= 1 return B B = counting_sort(S,10000) for b in B: print(b, end=' ')
def counting_sort(a,k): C = [] for i in range(k): C.append(0) for ai in a: C[ai] += 1 s = 0 for i in range(k): s += C[i] C[i] = s b = [] for i in range(len(a)): b.append(None) p = 0 for i in range(k): while p < C[i]: b[p] = i p += 1 return b n = int(input()) a = list(map(int,input().split(' '))) print(' '.join(map(str,counting_sort(a,10000))))
18
24
370
483
n = int(input()) S = list(map(int, input().strip().split(" "))) def counting_sort(S, k): C = [0] * (k + 1) B = [0] * len(S) for v in S: C[v] += 1 for i in range(1, k + 1): C[i] += C[i - 1] for i in range(len(S)): B[C[S[i]] - 1] = S[i] C[S[i]] -= 1 return B B = counting_sort(S, 10000) for b in B: print(b, end=" ")
def counting_sort(a, k): C = [] for i in range(k): C.append(0) for ai in a: C[ai] += 1 s = 0 for i in range(k): s += C[i] C[i] = s b = [] for i in range(len(a)): b.append(None) p = 0 for i in range(k): while p < C[i]: b[p] = i p += 1 return b n = int(input()) a = list(map(int, input().split(" "))) print(" ".join(map(str, counting_sort(a, 10000))))
false
25
[ "-n = int(input())", "-S = list(map(int, input().strip().split(\" \")))", "+def counting_sort(a, k):", "+ C = []", "+ for i in range(k):", "+ C.append(0)", "+ for ai in a:", "+ C[ai] += 1", "+ s = 0", "+ for i in range(k):", "+ s += C[i]", "+ C[i] = s", "+ b = []", "+ for i in range(len(a)):", "+ b.append(None)", "+ p = 0", "+ for i in range(k):", "+ while p < C[i]:", "+ b[p] = i", "+ p += 1", "+ return b", "-def counting_sort(S, k):", "- C = [0] * (k + 1)", "- B = [0] * len(S)", "- for v in S:", "- C[v] += 1", "- for i in range(1, k + 1):", "- C[i] += C[i - 1]", "- for i in range(len(S)):", "- B[C[S[i]] - 1] = S[i]", "- C[S[i]] -= 1", "- return B", "-", "-", "-B = counting_sort(S, 10000)", "-for b in B:", "- print(b, end=\" \")", "+n = int(input())", "+a = list(map(int, input().split(\" \")))", "+print(\" \".join(map(str, counting_sort(a, 10000))))" ]
false
0.070626
0.082514
0.855932
[ "s889630123", "s268911390" ]
u935558307
p03356
python
s534909413
s348330343
715
582
105,168
72,404
Accepted
Accepted
18.6
import sys sys.setrecursionlimit(2000000) input = sys.stdin.readline class UnionFind(): def __init__(self,n): self.n=n self.parents = [i for i in range(n+1)] self.size = [1]*(n+1) 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): xRoot = self.find(x) yRoot = self.find(y) if xRoot == yRoot: return if self.size[xRoot]>self.size[yRoot]: self.parents[yRoot] = xRoot else: self.parents[xRoot] = yRoot if self.size[xRoot] == self.size[yRoot]: self.size[yRoot]+=1 N,M = list(map(int,input().split())) P = list(map(int,input().split())) dic = {} dic2 = {} for i in range(1,N+1): dic[P[i-1]]=i dic2[i]=P[i-1] tree = UnionFind(N) for _ in range(M): x,y = list(map(int,input().split())) tree.union(x,y) indexGroup = {} for i in range(1,N+1): root = tree.find(i) if root not in indexGroup: indexGroup[root]=set() indexGroup[root].add(i) for p,i in list(dic.items()): root = tree.find(i) if p in indexGroup[root]: n = dic2[p] dic[p] = p dic2[p] = p dic[n] = i dic2[i] = n count = 0 for p,i in list(dic.items()): if p==i: count += 1 print(count)
import sys sys.setrecursionlimit(2000000) input = sys.stdin.readline class UnionFind(): def __init__(self,n): self.n=n self.parents = [i for i in range(n+1)] self.size = [1]*(n+1) 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): xRoot = self.find(x) yRoot = self.find(y) if xRoot == yRoot: return if self.size[xRoot]>self.size[yRoot]: self.parents[yRoot] = xRoot else: self.parents[xRoot] = yRoot if self.size[xRoot] == self.size[yRoot]: self.size[yRoot]+=1 N,M = list(map(int,input().split())) tree = UnionFind(N) P = list(map(int,input().split())) for _ in range(M): x,y = list(map(int,input().split())) tree.union(x,y) indeces = {} indeces2 = {} for i in range(N): indeces[P[i]]=i+1 indeces2[i+1]=P[i] group = {} group2 = {} for i in range(1,N+1): r = tree.find(i) if r not in group: group[r]=set() group[r].add(i) group2[i]=r ans = 0 for n,index in list(indeces.items()): if n == index: ans += 1 else: groupNum = group2[index] if n in group[groupNum]: ans += 1 a = indeces2[n] #n番目に現在君臨している数字 indeces2[n] = n indeces2[index] = a indeces[a] = index indeces[n] = n print(ans)
63
67
1,461
1,565
import sys sys.setrecursionlimit(2000000) input = sys.stdin.readline class UnionFind: def __init__(self, n): self.n = n self.parents = [i for i in range(n + 1)] self.size = [1] * (n + 1) 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): xRoot = self.find(x) yRoot = self.find(y) if xRoot == yRoot: return if self.size[xRoot] > self.size[yRoot]: self.parents[yRoot] = xRoot else: self.parents[xRoot] = yRoot if self.size[xRoot] == self.size[yRoot]: self.size[yRoot] += 1 N, M = list(map(int, input().split())) P = list(map(int, input().split())) dic = {} dic2 = {} for i in range(1, N + 1): dic[P[i - 1]] = i dic2[i] = P[i - 1] tree = UnionFind(N) for _ in range(M): x, y = list(map(int, input().split())) tree.union(x, y) indexGroup = {} for i in range(1, N + 1): root = tree.find(i) if root not in indexGroup: indexGroup[root] = set() indexGroup[root].add(i) for p, i in list(dic.items()): root = tree.find(i) if p in indexGroup[root]: n = dic2[p] dic[p] = p dic2[p] = p dic[n] = i dic2[i] = n count = 0 for p, i in list(dic.items()): if p == i: count += 1 print(count)
import sys sys.setrecursionlimit(2000000) input = sys.stdin.readline class UnionFind: def __init__(self, n): self.n = n self.parents = [i for i in range(n + 1)] self.size = [1] * (n + 1) 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): xRoot = self.find(x) yRoot = self.find(y) if xRoot == yRoot: return if self.size[xRoot] > self.size[yRoot]: self.parents[yRoot] = xRoot else: self.parents[xRoot] = yRoot if self.size[xRoot] == self.size[yRoot]: self.size[yRoot] += 1 N, M = list(map(int, input().split())) tree = UnionFind(N) P = list(map(int, input().split())) for _ in range(M): x, y = list(map(int, input().split())) tree.union(x, y) indeces = {} indeces2 = {} for i in range(N): indeces[P[i]] = i + 1 indeces2[i + 1] = P[i] group = {} group2 = {} for i in range(1, N + 1): r = tree.find(i) if r not in group: group[r] = set() group[r].add(i) group2[i] = r ans = 0 for n, index in list(indeces.items()): if n == index: ans += 1 else: groupNum = group2[index] if n in group[groupNum]: ans += 1 a = indeces2[n] # n番目に現在君臨している数字 indeces2[n] = n indeces2[index] = a indeces[a] = index indeces[n] = n print(ans)
false
5.970149
[ "+tree = UnionFind(N)", "-dic = {}", "-dic2 = {}", "-for i in range(1, N + 1):", "- dic[P[i - 1]] = i", "- dic2[i] = P[i - 1]", "-tree = UnionFind(N)", "-indexGroup = {}", "+indeces = {}", "+indeces2 = {}", "+for i in range(N):", "+ indeces[P[i]] = i + 1", "+ indeces2[i + 1] = P[i]", "+group = {}", "+group2 = {}", "- root = tree.find(i)", "- if root not in indexGroup:", "- indexGroup[root] = set()", "- indexGroup[root].add(i)", "-for p, i in list(dic.items()):", "- root = tree.find(i)", "- if p in indexGroup[root]:", "- n = dic2[p]", "- dic[p] = p", "- dic2[p] = p", "- dic[n] = i", "- dic2[i] = n", "-count = 0", "-for p, i in list(dic.items()):", "- if p == i:", "- count += 1", "-print(count)", "+ r = tree.find(i)", "+ if r not in group:", "+ group[r] = set()", "+ group[r].add(i)", "+ group2[i] = r", "+ans = 0", "+for n, index in list(indeces.items()):", "+ if n == index:", "+ ans += 1", "+ else:", "+ groupNum = group2[index]", "+ if n in group[groupNum]:", "+ ans += 1", "+ a = indeces2[n] # n番目に現在君臨している数字", "+ indeces2[n] = n", "+ indeces2[index] = a", "+ indeces[a] = index", "+ indeces[n] = n", "+print(ans)" ]
false
0.040421
0.039051
1.035098
[ "s534909413", "s348330343" ]
u073852194
p03162
python
s204629183
s913558531
1,223
230
47,388
85,856
Accepted
Accepted
81.19
n = int(eval(input())) Act = [list(map(int,input().split())) for i in range(n)] dp = [[0,0,0] for i in range(n)] dp[0] = [Act[0][j] for j in range(3)] for i in range(1,n): for j in range(3): s = 0 for k in range(3): s = max(s,(dp[i-1][k]+Act[i][j])*int(j!=k)) dp[i][j] = s print((max(dp[n-1][0],dp[n-1][1],dp[n-1][2])))
N = int(eval(input())) dp = [[0, 0, 0] for _ in range(N + 1)] for i in range(1, N + 1): a = tuple(map(int, input().split())) for j in range(3): dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j]) print((max(dp[N])))
14
10
348
248
n = int(eval(input())) Act = [list(map(int, input().split())) for i in range(n)] dp = [[0, 0, 0] for i in range(n)] dp[0] = [Act[0][j] for j in range(3)] for i in range(1, n): for j in range(3): s = 0 for k in range(3): s = max(s, (dp[i - 1][k] + Act[i][j]) * int(j != k)) dp[i][j] = s print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))
N = int(eval(input())) dp = [[0, 0, 0] for _ in range(N + 1)] for i in range(1, N + 1): a = tuple(map(int, input().split())) for j in range(3): dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j]) print((max(dp[N])))
false
28.571429
[ "-n = int(eval(input()))", "-Act = [list(map(int, input().split())) for i in range(n)]", "-dp = [[0, 0, 0] for i in range(n)]", "-dp[0] = [Act[0][j] for j in range(3)]", "-for i in range(1, n):", "+N = int(eval(input()))", "+dp = [[0, 0, 0] for _ in range(N + 1)]", "+for i in range(1, N + 1):", "+ a = tuple(map(int, input().split()))", "- s = 0", "- for k in range(3):", "- s = max(s, (dp[i - 1][k] + Act[i][j]) * int(j != k))", "- dp[i][j] = s", "-print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))", "+ dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j])", "+print((max(dp[N])))" ]
false
0.041083
0.03846
1.06821
[ "s204629183", "s913558531" ]
u737758066
p02993
python
s065667681
s716202394
182
17
38,256
2,940
Accepted
Accepted
90.66
s = eval(input()) t = s[0] for i in range(1, len(s)): if s[i] == t: print('Bad') exit() t = s[i] print('Good')
s = eval(input()) t = s[0] for i in range(1, 4): if t == s[i]: print('Bad') exit(0) t = s[i] print('Good')
9
9
138
133
s = eval(input()) t = s[0] for i in range(1, len(s)): if s[i] == t: print("Bad") exit() t = s[i] print("Good")
s = eval(input()) t = s[0] for i in range(1, 4): if t == s[i]: print("Bad") exit(0) t = s[i] print("Good")
false
0
[ "-for i in range(1, len(s)):", "- if s[i] == t:", "+for i in range(1, 4):", "+ if t == s[i]:", "- exit()", "+ exit(0)" ]
false
0.047181
0.046787
1.008423
[ "s065667681", "s716202394" ]
u248424983
p02413
python
s386128404
s594301347
30
20
8,332
8,216
Accepted
Accepted
33.33
r,c = list(map(int,input().split())) rc = list([int(x) for x in input().split()] for _ in range(r)) [rc[i].append(sum(rc[i])) for i in range(r)] rc.append([sum(i) for i in zip(*rc)]) for col in rc: print((*col))
r,c = list(map(int,input().split())) rc=[] total=[] for _ in range(r): rc.append(list(map(int,input().split()))) for i in range(r): rc[i].append(sum(rc[i])) for i in zip(*rc): total.append(sum(i)) rc.append(total) for col in rc: print((*col))
6
8
209
241
r, c = list(map(int, input().split())) rc = list([int(x) for x in input().split()] for _ in range(r)) [rc[i].append(sum(rc[i])) for i in range(r)] rc.append([sum(i) for i in zip(*rc)]) for col in rc: print((*col))
r, c = list(map(int, input().split())) rc = [] total = [] for _ in range(r): rc.append(list(map(int, input().split()))) for i in range(r): rc[i].append(sum(rc[i])) for i in zip(*rc): total.append(sum(i)) rc.append(total) for col in rc: print((*col))
false
25
[ "-rc = list([int(x) for x in input().split()] for _ in range(r))", "-[rc[i].append(sum(rc[i])) for i in range(r)]", "-rc.append([sum(i) for i in zip(*rc)])", "+rc = []", "+total = []", "+for _ in range(r):", "+ rc.append(list(map(int, input().split())))", "+for i in range(r):", "+ rc[i].append(sum(rc[i]))", "+for i in zip(*rc):", "+ total.append(sum(i))", "+rc.append(total)" ]
false
0.049338
0.007993
6.172814
[ "s386128404", "s594301347" ]
u867848444
p03645
python
s664651112
s005355102
1,081
968
106,916
66,840
Accepted
Accepted
10.45
from collections import deque #グラフの連結成分を調べる def Graph(ab): G=[[] for i in range(n)] for a,b in ab: G[a-1].append(b) G[b-1].append(a) return G n, m = list(map(int,input().split())) ab = [list(map(int,input().split())) for i in range(m)] G = Graph(ab) for v in G[0]: if n in G[v - 1]: print('POSSIBLE') exit() print('IMPOSSIBLE')
#グラフの連結成分を調べる def Graph(ab): G=[[] for i in range(n)] for a,b in ab: G[a-1].append(b) G[b-1].append(a) return G n, m = list(map(int,input().split())) ab = [list(map(int,input().split())) for i in range(m)] G = Graph(ab) for new_v in G[0]: if n in G[new_v - 1]: print('POSSIBLE') exit() print('IMPOSSIBLE')
18
16
388
363
from collections import deque # グラフの連結成分を調べる def Graph(ab): G = [[] for i in range(n)] for a, b in ab: G[a - 1].append(b) G[b - 1].append(a) return G n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(m)] G = Graph(ab) for v in G[0]: if n in G[v - 1]: print("POSSIBLE") exit() print("IMPOSSIBLE")
# グラフの連結成分を調べる def Graph(ab): G = [[] for i in range(n)] for a, b in ab: G[a - 1].append(b) G[b - 1].append(a) return G n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(m)] G = Graph(ab) for new_v in G[0]: if n in G[new_v - 1]: print("POSSIBLE") exit() print("IMPOSSIBLE")
false
11.111111
[ "-from collections import deque", "-", "-for v in G[0]:", "- if n in G[v - 1]:", "+for new_v in G[0]:", "+ if n in G[new_v - 1]:" ]
false
0.076004
0.082513
0.921114
[ "s664651112", "s005355102" ]
u981931040
p03417
python
s988088515
s295969576
19
17
3,060
3,060
Accepted
Accepted
10.53
N , M = list(map(int,input().split())) if N == 1 and M == 1: print("1") elif N == 1: print((M - 2)) elif M == 1: print((N - 2)) else: print(((N - 2) * (M - 2)))
N, M = list(map(int, input().split())) if N == M == 1: print("1") elif N == 1: print((max(0, M - 2))) elif M == 1: print((max(0, N - 2))) else: print((max(N * M - (N - 1) * 2 - (M - 1) * 2, 0)))
9
9
172
206
N, M = list(map(int, input().split())) if N == 1 and M == 1: print("1") elif N == 1: print((M - 2)) elif M == 1: print((N - 2)) else: print(((N - 2) * (M - 2)))
N, M = list(map(int, input().split())) if N == M == 1: print("1") elif N == 1: print((max(0, M - 2))) elif M == 1: print((max(0, N - 2))) else: print((max(N * M - (N - 1) * 2 - (M - 1) * 2, 0)))
false
0
[ "-if N == 1 and M == 1:", "+if N == M == 1:", "- print((M - 2))", "+ print((max(0, M - 2)))", "- print((N - 2))", "+ print((max(0, N - 2)))", "- print(((N - 2) * (M - 2)))", "+ print((max(N * M - (N - 1) * 2 - (M - 1) * 2, 0)))" ]
false
0.172097
0.044211
3.892613
[ "s988088515", "s295969576" ]
u588794534
p02724
python
s380823577
s414342089
186
165
38,256
38,384
Accepted
Accepted
11.29
x=int(eval(input())) result=x//500*1000+x%500//5*5 print(result)
a=int(eval(input())) cnt=(a//500)*1000 cnt+=((a%500)//5)*5 print(cnt)
4
6
62
71
x = int(eval(input())) result = x // 500 * 1000 + x % 500 // 5 * 5 print(result)
a = int(eval(input())) cnt = (a // 500) * 1000 cnt += ((a % 500) // 5) * 5 print(cnt)
false
33.333333
[ "-x = int(eval(input()))", "-result = x // 500 * 1000 + x % 500 // 5 * 5", "-print(result)", "+a = int(eval(input()))", "+cnt = (a // 500) * 1000", "+cnt += ((a % 500) // 5) * 5", "+print(cnt)" ]
false
0.041349
0.041427
0.998102
[ "s380823577", "s414342089" ]
u775421443
p02588
python
s791010784
s561556062
351
205
26,008
9,492
Accepted
Accepted
41.6
from collections import defaultdict def conv(s): if "." not in s: s += '.' s = s.rstrip('0') t = len(s) - s.find('.') - 1 a = int(s.replace('.', '')) if a == 0: return (0, 0) x, y = -t, -t while a % 5 == 0: x += 1 a //= 5 y += len(bin(a&-a))-3 return (x, y) _, *A = open(0).read().split() d = defaultdict(int) for a in A: d[conv(a)] += 1 result = 0 d = list(d.items()) for i, ((x, y), cnt) in enumerate(d): if x >= 0 and y >= 0: result += cnt * (cnt - 1) // 2 for (m, n), cnt2 in d[i+1:]: if x + m >= 0 and y + n >= 0: result += cnt * cnt2 print(result)
import sys from collections import defaultdict from math import gcd def input(): return sys.stdin.readline().strip() K = 10**9 L = 10**18 D = defaultdict(int) for _ in range(int(eval(input()))): D[gcd(round(float(eval(input())) * K), L)] += 1 D = tuple(D.items()) ans = 0 for i, (k1, v1) in enumerate(D): if k1*k1 % L == 0: ans += v1*(v1-1) // 2 for k2, v2 in D[i+1:]: if k1*k2 % L == 0: ans += v1 * v2 print(ans)
32
21
697
465
from collections import defaultdict def conv(s): if "." not in s: s += "." s = s.rstrip("0") t = len(s) - s.find(".") - 1 a = int(s.replace(".", "")) if a == 0: return (0, 0) x, y = -t, -t while a % 5 == 0: x += 1 a //= 5 y += len(bin(a & -a)) - 3 return (x, y) _, *A = open(0).read().split() d = defaultdict(int) for a in A: d[conv(a)] += 1 result = 0 d = list(d.items()) for i, ((x, y), cnt) in enumerate(d): if x >= 0 and y >= 0: result += cnt * (cnt - 1) // 2 for (m, n), cnt2 in d[i + 1 :]: if x + m >= 0 and y + n >= 0: result += cnt * cnt2 print(result)
import sys from collections import defaultdict from math import gcd def input(): return sys.stdin.readline().strip() K = 10**9 L = 10**18 D = defaultdict(int) for _ in range(int(eval(input()))): D[gcd(round(float(eval(input())) * K), L)] += 1 D = tuple(D.items()) ans = 0 for i, (k1, v1) in enumerate(D): if k1 * k1 % L == 0: ans += v1 * (v1 - 1) // 2 for k2, v2 in D[i + 1 :]: if k1 * k2 % L == 0: ans += v1 * v2 print(ans)
false
34.375
[ "+import sys", "+from math import gcd", "-def conv(s):", "- if \".\" not in s:", "- s += \".\"", "- s = s.rstrip(\"0\")", "- t = len(s) - s.find(\".\") - 1", "- a = int(s.replace(\".\", \"\"))", "- if a == 0:", "- return (0, 0)", "- x, y = -t, -t", "- while a % 5 == 0:", "- x += 1", "- a //= 5", "- y += len(bin(a & -a)) - 3", "- return (x, y)", "+def input():", "+ return sys.stdin.readline().strip()", "-_, *A = open(0).read().split()", "-d = defaultdict(int)", "-for a in A:", "- d[conv(a)] += 1", "-result = 0", "-d = list(d.items())", "-for i, ((x, y), cnt) in enumerate(d):", "- if x >= 0 and y >= 0:", "- result += cnt * (cnt - 1) // 2", "- for (m, n), cnt2 in d[i + 1 :]:", "- if x + m >= 0 and y + n >= 0:", "- result += cnt * cnt2", "-print(result)", "+K = 10**9", "+L = 10**18", "+D = defaultdict(int)", "+for _ in range(int(eval(input()))):", "+ D[gcd(round(float(eval(input())) * K), L)] += 1", "+D = tuple(D.items())", "+ans = 0", "+for i, (k1, v1) in enumerate(D):", "+ if k1 * k1 % L == 0:", "+ ans += v1 * (v1 - 1) // 2", "+ for k2, v2 in D[i + 1 :]:", "+ if k1 * k2 % L == 0:", "+ ans += v1 * v2", "+print(ans)" ]
false
0.038024
0.045547
0.834836
[ "s791010784", "s561556062" ]
u318345739
p02683
python
s256692190
s928935675
108
83
73,724
74,024
Accepted
Accepted
23.15
from itertools import combinations def is_achievable(M, X, A): result = [0] * M for a_row in A: for i, a in enumerate(a_row): result[i] += a for n in result: if n < X: return False return True def main(): N, M, X = list(map(int, input().split())) C = [0] * N A = [] for i in range(N): query = list(map(int, input().split())) C[i] = query[0] A.append(query[1:]) if not is_achievable(M, X, A): print((-1)) return index_C = [ i for i in range(N) ] min_cost = 10 ** 10 for i in range(len(index_C)+1): for comb in combinations(index_C, i): cur_A = [] cur_cost = 0 for i in comb: cur_A.append(A[i]) cur_cost += C[i] if is_achievable(M, X, cur_A): min_cost = min(min_cost, cur_cost) print(min_cost) main()
from itertools import combinations class Solver: def __init__(self, N, M, X, C, A): self.N = N self.M = M self.X = X self.C = C self.A = A def is_achievable(self, A): result = [0] * self.M for a_row in A: for i, a in enumerate(a_row): result[i] += a for n in result: if n < self.X: return False return True def solve(self): if not self.is_achievable(self.A): print((-1)) return min_cost = 10 ** 10 index_C = [ i for i in range(N) ] for i in range(len(index_C)+1): for comb in combinations(index_C, i): cur_A = [] cur_cost = 0 for i in comb: cur_A.append(self.A[i]) cur_cost += C[i] if self.is_achievable(cur_A): min_cost = min(min_cost, cur_cost) print(min_cost) N, M, X = list(map(int, input().split())) C = [0] * N A = [] for i in range(N): query = list(map(int, input().split())) C[i] = query[0] A.append(query[1:]) solver = Solver(N, M, X, C, A) solver.solve()
43
53
982
1,272
from itertools import combinations def is_achievable(M, X, A): result = [0] * M for a_row in A: for i, a in enumerate(a_row): result[i] += a for n in result: if n < X: return False return True def main(): N, M, X = list(map(int, input().split())) C = [0] * N A = [] for i in range(N): query = list(map(int, input().split())) C[i] = query[0] A.append(query[1:]) if not is_achievable(M, X, A): print((-1)) return index_C = [i for i in range(N)] min_cost = 10**10 for i in range(len(index_C) + 1): for comb in combinations(index_C, i): cur_A = [] cur_cost = 0 for i in comb: cur_A.append(A[i]) cur_cost += C[i] if is_achievable(M, X, cur_A): min_cost = min(min_cost, cur_cost) print(min_cost) main()
from itertools import combinations class Solver: def __init__(self, N, M, X, C, A): self.N = N self.M = M self.X = X self.C = C self.A = A def is_achievable(self, A): result = [0] * self.M for a_row in A: for i, a in enumerate(a_row): result[i] += a for n in result: if n < self.X: return False return True def solve(self): if not self.is_achievable(self.A): print((-1)) return min_cost = 10**10 index_C = [i for i in range(N)] for i in range(len(index_C) + 1): for comb in combinations(index_C, i): cur_A = [] cur_cost = 0 for i in comb: cur_A.append(self.A[i]) cur_cost += C[i] if self.is_achievable(cur_A): min_cost = min(min_cost, cur_cost) print(min_cost) N, M, X = list(map(int, input().split())) C = [0] * N A = [] for i in range(N): query = list(map(int, input().split())) C[i] = query[0] A.append(query[1:]) solver = Solver(N, M, X, C, A) solver.solve()
false
18.867925
[ "-def is_achievable(M, X, A):", "- result = [0] * M", "- for a_row in A:", "- for i, a in enumerate(a_row):", "- result[i] += a", "- for n in result:", "- if n < X:", "- return False", "- return True", "+class Solver:", "+ def __init__(self, N, M, X, C, A):", "+ self.N = N", "+ self.M = M", "+ self.X = X", "+ self.C = C", "+ self.A = A", "+", "+ def is_achievable(self, A):", "+ result = [0] * self.M", "+ for a_row in A:", "+ for i, a in enumerate(a_row):", "+ result[i] += a", "+ for n in result:", "+ if n < self.X:", "+ return False", "+ return True", "+", "+ def solve(self):", "+ if not self.is_achievable(self.A):", "+ print((-1))", "+ return", "+ min_cost = 10**10", "+ index_C = [i for i in range(N)]", "+ for i in range(len(index_C) + 1):", "+ for comb in combinations(index_C, i):", "+ cur_A = []", "+ cur_cost = 0", "+ for i in comb:", "+ cur_A.append(self.A[i])", "+ cur_cost += C[i]", "+ if self.is_achievable(cur_A):", "+ min_cost = min(min_cost, cur_cost)", "+ print(min_cost)", "-def main():", "- N, M, X = list(map(int, input().split()))", "- C = [0] * N", "- A = []", "- for i in range(N):", "- query = list(map(int, input().split()))", "- C[i] = query[0]", "- A.append(query[1:])", "- if not is_achievable(M, X, A):", "- print((-1))", "- return", "- index_C = [i for i in range(N)]", "- min_cost = 10**10", "- for i in range(len(index_C) + 1):", "- for comb in combinations(index_C, i):", "- cur_A = []", "- cur_cost = 0", "- for i in comb:", "- cur_A.append(A[i])", "- cur_cost += C[i]", "- if is_achievable(M, X, cur_A):", "- min_cost = min(min_cost, cur_cost)", "- print(min_cost)", "-", "-", "-main()", "+N, M, X = list(map(int, input().split()))", "+C = [0] * N", "+A = []", "+for i in range(N):", "+ query = list(map(int, input().split()))", "+ C[i] = query[0]", "+ A.append(query[1:])", "+solver = Solver(N, M, X, C, A)", "+solver.solve()" ]
false
0.0384
0.039761
0.965766
[ "s256692190", "s928935675" ]
u606045429
p03274
python
s692924921
s796007741
93
63
14,224
14,388
Accepted
Accepted
32.26
N, K = [int(i) for i in input().split()] X = [int(i) for i in input().split()] mi = 1e10 for l in range(N - K + 1): r = l + K - 1 mi = min(mi, abs(X[l]) + abs(X[r] - X[l]), abs(X[r]) + abs(X[r] - X[l])) print(mi)
N, K = [int(i) for i in input().split()] X = [int(i) for i in input().split()] print((min(r - l + min(abs(l), abs(r)) for l, r in zip(X, X[K - 1:]))))
8
4
228
153
N, K = [int(i) for i in input().split()] X = [int(i) for i in input().split()] mi = 1e10 for l in range(N - K + 1): r = l + K - 1 mi = min(mi, abs(X[l]) + abs(X[r] - X[l]), abs(X[r]) + abs(X[r] - X[l])) print(mi)
N, K = [int(i) for i in input().split()] X = [int(i) for i in input().split()] print((min(r - l + min(abs(l), abs(r)) for l, r in zip(X, X[K - 1 :]))))
false
50
[ "-mi = 1e10", "-for l in range(N - K + 1):", "- r = l + K - 1", "- mi = min(mi, abs(X[l]) + abs(X[r] - X[l]), abs(X[r]) + abs(X[r] - X[l]))", "-print(mi)", "+print((min(r - l + min(abs(l), abs(r)) for l, r in zip(X, X[K - 1 :]))))" ]
false
0.084706
0.085376
0.992153
[ "s692924921", "s796007741" ]
u596276291
p02861
python
s013559681
s459917354
340
217
4,456
9,952
Accepted
Accepted
36.18
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): return def main(): N = int(eval(input())) points = [] for i in range(N): x, y = list(map(int, input().split())) points.append((x, y)) num = 0 ans = 0 l = list(range(N)) for p in permutations(l): num += 1 for i in range(1, len(p)): ans += sqrt((points[p[i - 1]][0] - points[p[i]][0]) ** 2 + (points[p[i - 1]][1] - points[p[i]][1]) ** 2) print((ans / num)) if __name__ == '__main__': main()
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(500000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def calc(p, P): ans = 0 for i in range(1, len(p)): x1, y1 = P[p[i - 1]] x2, y2 = P[p[i]] ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) return ans def solve(): N = int(eval(input())) P = [] for _ in range(N): X, Y = list(map(int, input().split())) P.append((X, Y)) ans = 0 num = 0 for p in permutations(list(range(N))): ans += calc(p, P) num += 1 print((ans / num)) def main(): solve() if __name__ == '__main__': main()
64
70
1,422
1,460
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): return def main(): N = int(eval(input())) points = [] for i in range(N): x, y = list(map(int, input().split())) points.append((x, y)) num = 0 ans = 0 l = list(range(N)) for p in permutations(l): num += 1 for i in range(1, len(p)): ans += sqrt( (points[p[i - 1]][0] - points[p[i]][0]) ** 2 + (points[p[i - 1]][1] - points[p[i]][1]) ** 2 ) print((ans / num)) if __name__ == "__main__": main()
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(500000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def calc(p, P): ans = 0 for i in range(1, len(p)): x1, y1 = P[p[i - 1]] x2, y2 = P[p[i]] ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) return ans def solve(): N = int(eval(input())) P = [] for _ in range(N): X, Y = list(map(int, input().split())) P.append((X, Y)) ans = 0 num = 0 for p in permutations(list(range(N))): ans += calc(p, P) num += 1 print((ans / num)) def main(): solve() if __name__ == "__main__": main()
false
8.571429
[ "-sys.setrecursionlimit(10000)", "+sys.setrecursionlimit(500000)", "+def calc(p, P):", "+ ans = 0", "+ for i in range(1, len(p)):", "+ x1, y1 = P[p[i - 1]]", "+ x2, y2 = P[p[i]]", "+ ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)", "+ return ans", "+", "+", "- return", "+ N = int(eval(input()))", "+ P = []", "+ for _ in range(N):", "+ X, Y = list(map(int, input().split()))", "+ P.append((X, Y))", "+ ans = 0", "+ num = 0", "+ for p in permutations(list(range(N))):", "+ ans += calc(p, P)", "+ num += 1", "+ print((ans / num))", "- N = int(eval(input()))", "- points = []", "- for i in range(N):", "- x, y = list(map(int, input().split()))", "- points.append((x, y))", "- num = 0", "- ans = 0", "- l = list(range(N))", "- for p in permutations(l):", "- num += 1", "- for i in range(1, len(p)):", "- ans += sqrt(", "- (points[p[i - 1]][0] - points[p[i]][0]) ** 2", "- + (points[p[i - 1]][1] - points[p[i]][1]) ** 2", "- )", "- print((ans / num))", "+ solve()" ]
false
0.047762
0.0909
0.525429
[ "s013559681", "s459917354" ]
u256464928
p03761
python
s600656765
s754337961
25
18
3,828
3,064
Accepted
Accepted
28
N = int(input()) S = [input() for _ in range(N)] import string letters=string.ascii_lowercase dic = {} def alpha(N,dic): for i in letters: dic[i] = [0] * N alpha(N,dic) for i in range(N): for j in range(len(S[i])): dic[S[i][j]][i] += 1 #print(dic) ans = [] for i in letters: ans.append(i * min(dic[i])) print(*ans,sep="")
N = int(input()) S = [input() for _ in range(N)] dic = {} X = sorted(list(set(S[0]))) for i in X: dic[i] = 51 for i in range(N): for x in X: dic[x] = min(dic[x],S[i].count(x)) for i in X: print(i * dic[i],end="")
19
11
356
232
N = int(input()) S = [input() for _ in range(N)] import string letters = string.ascii_lowercase dic = {} def alpha(N, dic): for i in letters: dic[i] = [0] * N alpha(N, dic) for i in range(N): for j in range(len(S[i])): dic[S[i][j]][i] += 1 # print(dic) ans = [] for i in letters: ans.append(i * min(dic[i])) print(*ans, sep="")
N = int(input()) S = [input() for _ in range(N)] dic = {} X = sorted(list(set(S[0]))) for i in X: dic[i] = 51 for i in range(N): for x in X: dic[x] = min(dic[x], S[i].count(x)) for i in X: print(i * dic[i], end="")
false
42.105263
[ "-import string", "-", "-letters = string.ascii_lowercase", "-", "-", "-def alpha(N, dic):", "- for i in letters:", "- dic[i] = [0] * N", "-", "-", "-alpha(N, dic)", "+X = sorted(list(set(S[0])))", "+for i in X:", "+ dic[i] = 51", "- for j in range(len(S[i])):", "- dic[S[i][j]][i] += 1", "-# print(dic)", "-ans = []", "-for i in letters:", "- ans.append(i * min(dic[i]))", "-print(*ans, sep=\"\")", "+ for x in X:", "+ dic[x] = min(dic[x], S[i].count(x))", "+for i in X:", "+ print(i * dic[i], end=\"\")" ]
false
0.043027
0.036589
1.175969
[ "s600656765", "s754337961" ]
u867069435
p03470
python
s727883972
s464940625
19
17
3,316
3,064
Accepted
Accepted
10.53
n = int(eval(input())) k = [] for i in range(n): k.append(int(eval(input()))) print((len(set(k))))
n = int(eval(input())) print((len(set(map(int, [eval(input()) for i in range(n)])))))
5
2
92
72
n = int(eval(input())) k = [] for i in range(n): k.append(int(eval(input()))) print((len(set(k))))
n = int(eval(input())) print((len(set(map(int, [eval(input()) for i in range(n)])))))
false
60
[ "-k = []", "-for i in range(n):", "- k.append(int(eval(input())))", "-print((len(set(k))))", "+print((len(set(map(int, [eval(input()) for i in range(n)])))))" ]
false
0.042118
0.039892
1.0558
[ "s727883972", "s464940625" ]
u910830417
p02995
python
s821542877
s902413280
54
38
5,816
5,048
Accepted
Accepted
29.63
import fractions a, b, c, d = list(map(int, input().split())) def wareruzu(x): if b < x: return 0 if b == x: return 1 start_a = a if a % x == 0 else a - (a % x) + x end_b = b - (b % x) # bより小さい最大の値。 m = end_b - start_a if m < 0: return 0 return int(m // x) + 1 all_n = b - a + 1 print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) // fractions.gcd(c,d))))
import fractions a, b, c, d = list(map(int, input().split())) def wareruzu(x): if b < x: return 0 if b == x: return 1 start_a = a if a % x == 0 else a - (a % x) + x end_b = b - (b % x) # bより小さい最大の値。 m = end_b - start_a return m // x + 1 all_n = b - a + 1 print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) // fractions.gcd(c,d))))
17
15
425
387
import fractions a, b, c, d = list(map(int, input().split())) def wareruzu(x): if b < x: return 0 if b == x: return 1 start_a = a if a % x == 0 else a - (a % x) + x end_b = b - (b % x) # bより小さい最大の値。 m = end_b - start_a if m < 0: return 0 return int(m // x) + 1 all_n = b - a + 1 print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c * d) // fractions.gcd(c, d))))
import fractions a, b, c, d = list(map(int, input().split())) def wareruzu(x): if b < x: return 0 if b == x: return 1 start_a = a if a % x == 0 else a - (a % x) + x end_b = b - (b % x) # bより小さい最大の値。 m = end_b - start_a return m // x + 1 all_n = b - a + 1 print((all_n - wareruzu(c) - wareruzu(d) + wareruzu((c * d) // fractions.gcd(c, d))))
false
11.764706
[ "- if m < 0:", "- return 0", "- return int(m // x) + 1", "+ return m // x + 1" ]
false
0.0526
0.05602
0.93895
[ "s821542877", "s902413280" ]
u405256066
p03194
python
s191701473
s293901064
290
206
40,300
40,300
Accepted
Accepted
28.97
import math from sys import stdin N,P=[int(x) for x in stdin.readline().rstrip().split()] for i in reversed(list(range(round(math.pow(P,(1/N)))+1))): tmp=math.pow(i,N) if P==1: ans=1 break if N==1: ans=P break if P%tmp==0: ans=i break print(ans)
import math from sys import stdin N,P=[int(x) for x in stdin.readline().rstrip().split()] po=math.pow(P,(1/N)) for i in reversed(list(range(int(round(po,0))+1))): tmp=math.pow(i,N) if P==1: ans=1 break if N==1: ans=P break if P%tmp==0: ans=i break print(ans)
15
16
317
331
import math from sys import stdin N, P = [int(x) for x in stdin.readline().rstrip().split()] for i in reversed(list(range(round(math.pow(P, (1 / N))) + 1))): tmp = math.pow(i, N) if P == 1: ans = 1 break if N == 1: ans = P break if P % tmp == 0: ans = i break print(ans)
import math from sys import stdin N, P = [int(x) for x in stdin.readline().rstrip().split()] po = math.pow(P, (1 / N)) for i in reversed(list(range(int(round(po, 0)) + 1))): tmp = math.pow(i, N) if P == 1: ans = 1 break if N == 1: ans = P break if P % tmp == 0: ans = i break print(ans)
false
6.25
[ "-for i in reversed(list(range(round(math.pow(P, (1 / N))) + 1))):", "+po = math.pow(P, (1 / N))", "+for i in reversed(list(range(int(round(po, 0)) + 1))):" ]
false
0.035864
0.038034
0.942932
[ "s191701473", "s293901064" ]
u077291787
p03262
python
s940256091
s429895127
71
52
14,224
14,052
Accepted
Accepted
26.76
# ABC109C - Skip def gcd(a, b): while a: a, b = b % a, a return b n, x = list(map(int, input().rstrip().split())) lst = list(map(int, input().rstrip().split())) d = abs(x - lst[0]) for i in range(n): dif = abs(x - lst[i]) if dif % d == 0: continue d = gcd(d, dif) print(d)
# ABC109C - Skip def gcd(a: int, b: int) -> int: while a: a, b = b % a, a return b def main(): N, X, *A = list(map(int, open(0).read().split())) ans = abs(X - A[0]) for i in A: dif = abs(X - i) if dif % ans: ans = gcd(ans, dif) print(ans) if __name__ == "__main__": main()
16
19
333
352
# ABC109C - Skip def gcd(a, b): while a: a, b = b % a, a return b n, x = list(map(int, input().rstrip().split())) lst = list(map(int, input().rstrip().split())) d = abs(x - lst[0]) for i in range(n): dif = abs(x - lst[i]) if dif % d == 0: continue d = gcd(d, dif) print(d)
# ABC109C - Skip def gcd(a: int, b: int) -> int: while a: a, b = b % a, a return b def main(): N, X, *A = list(map(int, open(0).read().split())) ans = abs(X - A[0]) for i in A: dif = abs(X - i) if dif % ans: ans = gcd(ans, dif) print(ans) if __name__ == "__main__": main()
false
15.789474
[ "-def gcd(a, b):", "+def gcd(a: int, b: int) -> int:", "-n, x = list(map(int, input().rstrip().split()))", "-lst = list(map(int, input().rstrip().split()))", "-d = abs(x - lst[0])", "-for i in range(n):", "- dif = abs(x - lst[i])", "- if dif % d == 0:", "- continue", "- d = gcd(d, dif)", "-print(d)", "+def main():", "+ N, X, *A = list(map(int, open(0).read().split()))", "+ ans = abs(X - A[0])", "+ for i in A:", "+ dif = abs(X - i)", "+ if dif % ans:", "+ ans = gcd(ans, dif)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.079923
0.077781
1.027541
[ "s940256091", "s429895127" ]
u018679195
p03860
python
s251711238
s894088350
19
17
2,940
2,940
Accepted
Accepted
10.53
ls=input().split() Ls=[] def fun(): print('111') print('222') print('333') print('ii') for i in ls: Ls.append(i[0]) print((''.join(Ls)))
def suma(a,b): return a+b def multi(a,b): return a*b def division(a,b): if a>0: division=a/b else: division="No se puede dividir" return division s=eval(input()) letra=s[8] print(("A{}C".format(letra)))
10
13
168
224
ls = input().split() Ls = [] def fun(): print("111") print("222") print("333") print("ii") for i in ls: Ls.append(i[0]) print(("".join(Ls)))
def suma(a, b): return a + b def multi(a, b): return a * b def division(a, b): if a > 0: division = a / b else: division = "No se puede dividir" return division s = eval(input()) letra = s[8] print(("A{}C".format(letra)))
false
23.076923
[ "-ls = input().split()", "-Ls = []", "+def suma(a, b):", "+ return a + b", "-def fun():", "- print(\"111\")", "- print(\"222\")", "- print(\"333\")", "- print(\"ii\")", "+def multi(a, b):", "+ return a * b", "-for i in ls:", "- Ls.append(i[0])", "-print((\"\".join(Ls)))", "+def division(a, b):", "+ if a > 0:", "+ division = a / b", "+ else:", "+ division = \"No se puede dividir\"", "+ return division", "+", "+", "+s = eval(input())", "+letra = s[8]", "+print((\"A{}C\".format(letra)))" ]
false
0.039399
0.038349
1.027367
[ "s251711238", "s894088350" ]
u391589398
p02585
python
s431747932
s175641683
981
636
298,592
79,916
Accepted
Accepted
35.17
n, k = list(map(int, input().split())) P = tuple([int(x)-1 for x in input().split()]) C = tuple(map(int, input().split())) CC = [[] for _ in range(n)] for idx, p in enumerate(P): CC[idx].append(C[p]) pp = P[p] for _ in range(n): CC[idx].append(C[pp]) pp = P[pp] if pp == p: break from itertools import accumulate ans = -2*(10**9) for cc in CC: cca = list(accumulate(cc)) if cca[-1] <= 0: # 1周分のうちの最大値 if k < len(cc): ans = max(ans, max(cca[:k])) else: ans = max(ans, max(cca)) else: # kk周したほうが良い kk, r = divmod(k, len(cc)) if r == 0: ans = max(ans, kk*cca[-1], (kk-1)*cca[-1]+max(cca)) else: ans = max(ans, kk*cca[-1] + max(cca[:r])) print(ans)
n, k = list(map(int, input().split())) P = tuple([int(x)-1 for x in input().split()]) C = tuple(map(int, input().split())) from collections import deque ans = -2*10**9 for idx, root in enumerate(P): scores = [C[root]] p = P[root] while True: scores.append(scores[-1] + C[p]) p = P[p] if p == root: break sc = scores[-1] if sc <= 0: if k < len(scores): ans = max(ans, max(scores[:k])) else: ans = max(ans, max(scores)) else: kk, r = divmod(k, len(scores)) if r == 0: ans = max(ans, kk*sc, (kk-1)*sc + max(scores)) else: ans = max(ans, kk*sc + max(scores[:r])) print(ans)
31
27
847
744
n, k = list(map(int, input().split())) P = tuple([int(x) - 1 for x in input().split()]) C = tuple(map(int, input().split())) CC = [[] for _ in range(n)] for idx, p in enumerate(P): CC[idx].append(C[p]) pp = P[p] for _ in range(n): CC[idx].append(C[pp]) pp = P[pp] if pp == p: break from itertools import accumulate ans = -2 * (10**9) for cc in CC: cca = list(accumulate(cc)) if cca[-1] <= 0: # 1周分のうちの最大値 if k < len(cc): ans = max(ans, max(cca[:k])) else: ans = max(ans, max(cca)) else: # kk周したほうが良い kk, r = divmod(k, len(cc)) if r == 0: ans = max(ans, kk * cca[-1], (kk - 1) * cca[-1] + max(cca)) else: ans = max(ans, kk * cca[-1] + max(cca[:r])) print(ans)
n, k = list(map(int, input().split())) P = tuple([int(x) - 1 for x in input().split()]) C = tuple(map(int, input().split())) from collections import deque ans = -2 * 10**9 for idx, root in enumerate(P): scores = [C[root]] p = P[root] while True: scores.append(scores[-1] + C[p]) p = P[p] if p == root: break sc = scores[-1] if sc <= 0: if k < len(scores): ans = max(ans, max(scores[:k])) else: ans = max(ans, max(scores)) else: kk, r = divmod(k, len(scores)) if r == 0: ans = max(ans, kk * sc, (kk - 1) * sc + max(scores)) else: ans = max(ans, kk * sc + max(scores[:r])) print(ans)
false
12.903226
[ "-CC = [[] for _ in range(n)]", "-for idx, p in enumerate(P):", "- CC[idx].append(C[p])", "- pp = P[p]", "- for _ in range(n):", "- CC[idx].append(C[pp])", "- pp = P[pp]", "- if pp == p:", "+from collections import deque", "+", "+ans = -2 * 10**9", "+for idx, root in enumerate(P):", "+ scores = [C[root]]", "+ p = P[root]", "+ while True:", "+ scores.append(scores[-1] + C[p])", "+ p = P[p]", "+ if p == root:", "-from itertools import accumulate", "-", "-ans = -2 * (10**9)", "-for cc in CC:", "- cca = list(accumulate(cc))", "- if cca[-1] <= 0:", "- # 1周分のうちの最大値", "- if k < len(cc):", "- ans = max(ans, max(cca[:k]))", "+ sc = scores[-1]", "+ if sc <= 0:", "+ if k < len(scores):", "+ ans = max(ans, max(scores[:k]))", "- ans = max(ans, max(cca))", "+ ans = max(ans, max(scores))", "- # kk周したほうが良い", "- kk, r = divmod(k, len(cc))", "+ kk, r = divmod(k, len(scores))", "- ans = max(ans, kk * cca[-1], (kk - 1) * cca[-1] + max(cca))", "+ ans = max(ans, kk * sc, (kk - 1) * sc + max(scores))", "- ans = max(ans, kk * cca[-1] + max(cca[:r]))", "+ ans = max(ans, kk * sc + max(scores[:r]))" ]
false
0.045005
0.045364
0.992078
[ "s431747932", "s175641683" ]
u520276780
p03031
python
s691545676
s419517031
202
46
40,816
3,064
Accepted
Accepted
77.23
""" n,m<=10 """ n,m = list(map(int, input().split( ))) s = [] for i in range(m): sij = list(map(int, input().split( ))) s.append(sij[1:]) p = list(map(int, input().split( ))) ans = 0 for i in range(2**n): flag = True for k in range(m): tst = 0 for sm in s[k]: tst ^= i>>(sm-1)&1 if tst^p[k]:### flag = False break if flag: ans += 1 print(ans)
n,m = list(map(int, input().split( ))) sw = [0 for _ in range(m)]#でんきゅがつながってるスイッチ for i in range(m): s = list(map(int, input().split( ))) s = [si-1 for si in s[1:]] bt = 0 for sj in s:#電球 bt += 1<<sj sw[i] = bt p = list(map(int, input().split( ))) #スイッチ bit = 1<<n ans = 0 for i in range(bit):#スイッチつけ方 flag = True for j in range(m):#電球 cnt = 0 for k in range(n):#スイッチチェック cnt += (i&sw[j])>>k if cnt%2!=p[j]: flag = False if flag: ans += 1 print(ans)
28
27
457
580
""" n,m<=10 """ n, m = list(map(int, input().split())) s = [] for i in range(m): sij = list(map(int, input().split())) s.append(sij[1:]) p = list(map(int, input().split())) ans = 0 for i in range(2**n): flag = True for k in range(m): tst = 0 for sm in s[k]: tst ^= i >> (sm - 1) & 1 if tst ^ p[k]: ### flag = False break if flag: ans += 1 print(ans)
n, m = list(map(int, input().split())) sw = [0 for _ in range(m)] # でんきゅがつながってるスイッチ for i in range(m): s = list(map(int, input().split())) s = [si - 1 for si in s[1:]] bt = 0 for sj in s: # 電球 bt += 1 << sj sw[i] = bt p = list(map(int, input().split())) # スイッチ bit = 1 << n ans = 0 for i in range(bit): # スイッチつけ方 flag = True for j in range(m): # 電球 cnt = 0 for k in range(n): # スイッチチェック cnt += (i & sw[j]) >> k if cnt % 2 != p[j]: flag = False if flag: ans += 1 print(ans)
false
3.571429
[ "-\"\"\"", "-n,m<=10", "-\"\"\"", "-s = []", "+sw = [0 for _ in range(m)] # でんきゅがつながってるスイッチ", "- sij = list(map(int, input().split()))", "- s.append(sij[1:])", "+ s = list(map(int, input().split()))", "+ s = [si - 1 for si in s[1:]]", "+ bt = 0", "+ for sj in s: # 電球", "+ bt += 1 << sj", "+ sw[i] = bt", "+# スイッチ", "+bit = 1 << n", "-for i in range(2**n):", "+for i in range(bit): # スイッチつけ方", "- for k in range(m):", "- tst = 0", "- for sm in s[k]:", "- tst ^= i >> (sm - 1) & 1", "- if tst ^ p[k]: ###", "+ for j in range(m): # 電球", "+ cnt = 0", "+ for k in range(n): # スイッチチェック", "+ cnt += (i & sw[j]) >> k", "+ if cnt % 2 != p[j]:", "- break" ]
false
0.057273
0.060535
0.946106
[ "s691545676", "s419517031" ]
u046158516
p03999
python
s593776868
s391975212
178
91
38,256
73,936
Accepted
Accepted
48.88
def convert(s): # initialization of string to "" new = "" # traverse in the string for x in s: new += x # return string return new n=eval(input()) ans=0 for i in range(len(n)): for j in range(len(n)-i): if j==len(n)-i-1: ans+=int(n[i])*(2**(len(n)-j-1))*(10**j) else: ans+=int(n[i])*(2**(len(n)-j-2))*(10**j) print(ans)
def base10toN(num, base): converted_string, modstring = "", "" currentnum = num if not num: return '0' while currentnum: mod = currentnum % base currentnum = currentnum // base converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string return converted_string s=eval(input()) n=len(s) ans=0 for i in range(2**(n-1)): t=base10toN(i,2) r=[] for j in range(n-1-len(t)): r.append('0') for j in range(len(t)): r.append(t[j]) k=[] k.append(s[0]) for j in range(n-1): if r[j]=='0': k.append(s[j+1]) else: ans+=int(''.join(k)) k=[] k.append(s[j+1]) ans+=int(''.join(k)) print(ans)
20
31
406
712
def convert(s): # initialization of string to "" new = "" # traverse in the string for x in s: new += x # return string return new n = eval(input()) ans = 0 for i in range(len(n)): for j in range(len(n) - i): if j == len(n) - i - 1: ans += int(n[i]) * (2 ** (len(n) - j - 1)) * (10**j) else: ans += int(n[i]) * (2 ** (len(n) - j - 2)) * (10**j) print(ans)
def base10toN(num, base): converted_string, modstring = "", "" currentnum = num if not num: return "0" while currentnum: mod = currentnum % base currentnum = currentnum // base converted_string = chr(48 + mod + 7 * (mod > 10)) + converted_string return converted_string s = eval(input()) n = len(s) ans = 0 for i in range(2 ** (n - 1)): t = base10toN(i, 2) r = [] for j in range(n - 1 - len(t)): r.append("0") for j in range(len(t)): r.append(t[j]) k = [] k.append(s[0]) for j in range(n - 1): if r[j] == "0": k.append(s[j + 1]) else: ans += int("".join(k)) k = [] k.append(s[j + 1]) ans += int("".join(k)) print(ans)
false
35.483871
[ "-def convert(s):", "- # initialization of string to \"\"", "- new = \"\"", "- # traverse in the string", "- for x in s:", "- new += x", "- # return string", "- return new", "+def base10toN(num, base):", "+ converted_string, modstring = \"\", \"\"", "+ currentnum = num", "+ if not num:", "+ return \"0\"", "+ while currentnum:", "+ mod = currentnum % base", "+ currentnum = currentnum // base", "+ converted_string = chr(48 + mod + 7 * (mod > 10)) + converted_string", "+ return converted_string", "-n = eval(input())", "+s = eval(input())", "+n = len(s)", "-for i in range(len(n)):", "- for j in range(len(n) - i):", "- if j == len(n) - i - 1:", "- ans += int(n[i]) * (2 ** (len(n) - j - 1)) * (10**j)", "+for i in range(2 ** (n - 1)):", "+ t = base10toN(i, 2)", "+ r = []", "+ for j in range(n - 1 - len(t)):", "+ r.append(\"0\")", "+ for j in range(len(t)):", "+ r.append(t[j])", "+ k = []", "+ k.append(s[0])", "+ for j in range(n - 1):", "+ if r[j] == \"0\":", "+ k.append(s[j + 1])", "- ans += int(n[i]) * (2 ** (len(n) - j - 2)) * (10**j)", "+ ans += int(\"\".join(k))", "+ k = []", "+ k.append(s[j + 1])", "+ ans += int(\"\".join(k))" ]
false
0.037983
0.066768
0.568883
[ "s593776868", "s391975212" ]
u223663729
p02787
python
s515969223
s291068316
340
120
42,220
71,800
Accepted
Accepted
64.71
# AtCoder Beginner Contest 153 # E - Crested Ibis vs Monster # https://atcoder.jp/contests/abc153/tasks/abc153_e H, N, *A = list(map(int, open(0).read().split())) *A, = list(zip(*[iter(A)]*2)) INF = 1 << 30 dp = [INF]*(H+1) dp[0] = 0 for i, (a, b) in enumerate(A): for h in range(H+1): mh = min(H, h+a) dp[mh] = min(dp[mh], dp[h] + b) print((dp[H]))
import sys input = sys.stdin.buffer.readline H, N = list(map(int, input().split())) A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()] INF = 1 << 30 dp = [INF]*(H+1) dp[H] = 0 for i in range(N): a, b = A[i] for h in range(H, -1, -1): x = h-a if h-a > 0 else 0 if dp[x] > dp[h]+b: dp[x] = dp[h]+b print((dp[0]))
14
14
370
378
# AtCoder Beginner Contest 153 # E - Crested Ibis vs Monster # https://atcoder.jp/contests/abc153/tasks/abc153_e H, N, *A = list(map(int, open(0).read().split())) (*A,) = list(zip(*[iter(A)] * 2)) INF = 1 << 30 dp = [INF] * (H + 1) dp[0] = 0 for i, (a, b) in enumerate(A): for h in range(H + 1): mh = min(H, h + a) dp[mh] = min(dp[mh], dp[h] + b) print((dp[H]))
import sys input = sys.stdin.buffer.readline H, N = list(map(int, input().split())) A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()] INF = 1 << 30 dp = [INF] * (H + 1) dp[H] = 0 for i in range(N): a, b = A[i] for h in range(H, -1, -1): x = h - a if h - a > 0 else 0 if dp[x] > dp[h] + b: dp[x] = dp[h] + b print((dp[0]))
false
0
[ "-# AtCoder Beginner Contest 153", "-# E - Crested Ibis vs Monster", "-# https://atcoder.jp/contests/abc153/tasks/abc153_e", "-H, N, *A = list(map(int, open(0).read().split()))", "-(*A,) = list(zip(*[iter(A)] * 2))", "+import sys", "+", "+input = sys.stdin.buffer.readline", "+H, N = list(map(int, input().split()))", "+A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]", "-dp[0] = 0", "-for i, (a, b) in enumerate(A):", "- for h in range(H + 1):", "- mh = min(H, h + a)", "- dp[mh] = min(dp[mh], dp[h] + b)", "-print((dp[H]))", "+dp[H] = 0", "+for i in range(N):", "+ a, b = A[i]", "+ for h in range(H, -1, -1):", "+ x = h - a if h - a > 0 else 0", "+ if dp[x] > dp[h] + b:", "+ dp[x] = dp[h] + b", "+print((dp[0]))" ]
false
0.174622
0.088813
1.96617
[ "s515969223", "s291068316" ]
u403301154
p03073
python
s146485295
s104978216
83
51
3,188
3,188
Accepted
Accepted
38.55
s = eval(input()) ans1 = 0 ans2 = 0 for i in range(len(s)): if i%2==0 and s[i]=="0": ans1 += 1 if i%2==1 and s[i]=="1": ans1 += 1 if i%2==0 and s[i]=="1": ans2 += 1 if i%2==1 and s[i]=="0": ans2 += 1 print((min(ans1, ans2)))
s = eval(input()) ans1, ans2 = 0, 0 for i, e in enumerate(s): if i%2: if e=="0": ans1 += 1 if e=="1": ans2 += 1 else: if e=="1": ans1 += 1 if e=="0": ans2 += 1 print((min(ans1, ans2)))
16
14
258
233
s = eval(input()) ans1 = 0 ans2 = 0 for i in range(len(s)): if i % 2 == 0 and s[i] == "0": ans1 += 1 if i % 2 == 1 and s[i] == "1": ans1 += 1 if i % 2 == 0 and s[i] == "1": ans2 += 1 if i % 2 == 1 and s[i] == "0": ans2 += 1 print((min(ans1, ans2)))
s = eval(input()) ans1, ans2 = 0, 0 for i, e in enumerate(s): if i % 2: if e == "0": ans1 += 1 if e == "1": ans2 += 1 else: if e == "1": ans1 += 1 if e == "0": ans2 += 1 print((min(ans1, ans2)))
false
12.5
[ "-ans1 = 0", "-ans2 = 0", "-for i in range(len(s)):", "- if i % 2 == 0 and s[i] == \"0\":", "- ans1 += 1", "- if i % 2 == 1 and s[i] == \"1\":", "- ans1 += 1", "- if i % 2 == 0 and s[i] == \"1\":", "- ans2 += 1", "- if i % 2 == 1 and s[i] == \"0\":", "- ans2 += 1", "+ans1, ans2 = 0, 0", "+for i, e in enumerate(s):", "+ if i % 2:", "+ if e == \"0\":", "+ ans1 += 1", "+ if e == \"1\":", "+ ans2 += 1", "+ else:", "+ if e == \"1\":", "+ ans1 += 1", "+ if e == \"0\":", "+ ans2 += 1" ]
false
0.036925
0.081043
0.455621
[ "s146485295", "s104978216" ]
u537976628
p03624
python
s340623729
s448600708
45
24
9,148
9,068
Accepted
Accepted
46.67
s = eval(input()) bkt = [0 for _ in range(26)] for i in range(len(s)): bkt[ord(s[i])-97] = 1 print(('None' if sum(bkt) == 26 else chr(bkt.index(0) + 97)))
S = set(eval(input())) for i in range(97, 123): c = chr(i) if c not in S: print(c) exit() print('None')
5
7
154
127
s = eval(input()) bkt = [0 for _ in range(26)] for i in range(len(s)): bkt[ord(s[i]) - 97] = 1 print(("None" if sum(bkt) == 26 else chr(bkt.index(0) + 97)))
S = set(eval(input())) for i in range(97, 123): c = chr(i) if c not in S: print(c) exit() print("None")
false
28.571429
[ "-s = eval(input())", "-bkt = [0 for _ in range(26)]", "-for i in range(len(s)):", "- bkt[ord(s[i]) - 97] = 1", "-print((\"None\" if sum(bkt) == 26 else chr(bkt.index(0) + 97)))", "+S = set(eval(input()))", "+for i in range(97, 123):", "+ c = chr(i)", "+ if c not in S:", "+ print(c)", "+ exit()", "+print(\"None\")" ]
false
0.038634
0.039519
0.977597
[ "s340623729", "s448600708" ]
u969190727
p02794
python
s086710241
s524545335
565
447
42,732
49,384
Accepted
Accepted
20.88
import sys input=sys.stdin.readline n=int(eval(input())) Edge=[[] for i in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) Edge[a-1].append((b-1,i)) Edge[b-1].append((a-1,i)) m=int(eval(input())) M=[] for i in range(m): M.append(tuple(map(int,input().split()))) inf=float("inf") path=[-1]*n #根から各点までのパスが通過する辺をbitで管理したもの path[0]=0 stack=[0] while stack: cur=stack.pop() for next,num in Edge[cur]: if path[next]==-1: path[next]=path[cur]|(1<<num) stack.append(next) def popcount(x): x=x-((x>>1)&0x5555555555555555) x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333) x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f x=x+(x>>8) x=x+(x>>16) x=x+(x>>32) return x&0x0000007f passing=[] #Mの各u,vについて、通過する辺をbitで持ったもの for u,v in M: passing.append((path[u-1]^path[v-1])) ans=2**(n-1) #Mのすべての部分集合について符号付で足し合わせる for i in range(1,2**m): i_ct=popcount(i)#満たすべき条件の数、これで符号を決める condition=0 for j in range(m): if i&(1<<j):#j番目の条件を満たす condition=condition|passing[j] cond_ct=popcount(condition) #iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数 ans+=pow((-1),i_ct)*pow(2,n-1-cond_ct) print(ans)
import sys input=sys.stdin.readline n=int(eval(input())) Edge=[[] for i in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) Edge[a-1].append((b-1,i)) Edge[b-1].append((a-1,i)) m=int(eval(input())) M=[] for i in range(m): M.append(tuple(map(int,input().split()))) inf=float("inf") path=[-1]*n #根から各点までのパスが通過する辺をbitで管理したもの path[0]=0 stack=[0] while stack: cur=stack.pop() for next,num in Edge[cur]: if path[next]==-1: path[next]=path[cur]|(1<<num) stack.append(next) def popcount(x): x=x-((x>>1)&0x5555555555555555) x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333) x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f x=x+(x>>8) x=x+(x>>16) x=x+(x>>32) return x&0x0000007f passing=[] #Mの各u,vについて、通過する辺をbitで持ったもの for u,v in M: passing.append((path[u-1]^path[v-1])) ans=2**(n-1) Cond=[0]*(2**m) #Mのすべての部分集合について符号付で足し合わせる for i in range(1,2**m): i_ct=popcount(i)#満たすべき条件の数、これで符号を決める Cond[i]=Cond[i^(i&(-i))]|passing[len(bin(i&(-i)))-3] cond_ct=popcount(Cond[i]) #iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数 ans+=pow((-1),i_ct)*pow(2,n-1-cond_ct) print(ans)
50
48
1,165
1,132
import sys input = sys.stdin.readline n = int(eval(input())) Edge = [[] for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) Edge[a - 1].append((b - 1, i)) Edge[b - 1].append((a - 1, i)) m = int(eval(input())) M = [] for i in range(m): M.append(tuple(map(int, input().split()))) inf = float("inf") path = [-1] * n # 根から各点までのパスが通過する辺をbitで管理したもの path[0] = 0 stack = [0] while stack: cur = stack.pop() for next, num in Edge[cur]: if path[next] == -1: path[next] = path[cur] | (1 << num) stack.append(next) def popcount(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F passing = [] # Mの各u,vについて、通過する辺をbitで持ったもの for u, v in M: passing.append((path[u - 1] ^ path[v - 1])) ans = 2 ** (n - 1) # Mのすべての部分集合について符号付で足し合わせる for i in range(1, 2**m): i_ct = popcount(i) # 満たすべき条件の数、これで符号を決める condition = 0 for j in range(m): if i & (1 << j): # j番目の条件を満たす condition = condition | passing[j] cond_ct = popcount(condition) # iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数 ans += pow((-1), i_ct) * pow(2, n - 1 - cond_ct) print(ans)
import sys input = sys.stdin.readline n = int(eval(input())) Edge = [[] for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) Edge[a - 1].append((b - 1, i)) Edge[b - 1].append((a - 1, i)) m = int(eval(input())) M = [] for i in range(m): M.append(tuple(map(int, input().split()))) inf = float("inf") path = [-1] * n # 根から各点までのパスが通過する辺をbitで管理したもの path[0] = 0 stack = [0] while stack: cur = stack.pop() for next, num in Edge[cur]: if path[next] == -1: path[next] = path[cur] | (1 << num) stack.append(next) def popcount(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F passing = [] # Mの各u,vについて、通過する辺をbitで持ったもの for u, v in M: passing.append((path[u - 1] ^ path[v - 1])) ans = 2 ** (n - 1) Cond = [0] * (2**m) # Mのすべての部分集合について符号付で足し合わせる for i in range(1, 2**m): i_ct = popcount(i) # 満たすべき条件の数、これで符号を決める Cond[i] = Cond[i ^ (i & (-i))] | passing[len(bin(i & (-i))) - 3] cond_ct = popcount(Cond[i]) # iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数 ans += pow((-1), i_ct) * pow(2, n - 1 - cond_ct) print(ans)
false
4
[ "+Cond = [0] * (2**m)", "- condition = 0", "- for j in range(m):", "- if i & (1 << j): # j番目の条件を満たす", "- condition = condition | passing[j]", "- cond_ct = popcount(condition) # iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数", "+ Cond[i] = Cond[i ^ (i & (-i))] | passing[len(bin(i & (-i))) - 3]", "+ cond_ct = popcount(Cond[i]) # iが表すMの部分集合の条件をすべて満たす場合にすべて白になる辺集合の要素数" ]
false
0.075824
0.042162
1.798399
[ "s086710241", "s524545335" ]
u059210959
p03378
python
s497813587
s969607043
163
40
13,420
10,648
Accepted
Accepted
75.46
# encoding:utf-8 import copy import numpy as np import random n,m,x = list(map(int,input().split())) a = [int(i) for i in input().split()] #migi cost_r = 0 for i in range(x,n): if i in a: cost_r += 1 cost_l = 0 for i in range(x): if i in a: cost_l += 1 print((min(cost_l,cost_r)))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, M, X = LI() A = LI() left = 0 right = 0 cs = [0 for i in range(N)] for a in A: cs[a] = 1 for i in range(X): if cs[i]: left += 1 for i in range(X, N): if cs[i]: right += 1 print((min(left, right)))
23
35
326
638
# encoding:utf-8 import copy import numpy as np import random n, m, x = list(map(int, input().split())) a = [int(i) for i in input().split()] # migi cost_r = 0 for i in range(x, n): if i in a: cost_r += 1 cost_l = 0 for i in range(x): if i in a: cost_l += 1 print((min(cost_l, cost_r)))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, M, X = LI() A = LI() left = 0 right = 0 cs = [0 for i in range(N)] for a in A: cs[a] = 1 for i in range(X): if cs[i]: left += 1 for i in range(X, N): if cs[i]: right += 1 print((min(left, right)))
false
34.285714
[ "+#!/usr/bin/env python3", "-import numpy as np", "+import bisect # bisect_left これで二部探索の大小検索が行える", "+import fractions # 最小公倍数などはこっち", "+import math", "+import sys", "+import collections", "+from decimal import Decimal # 10進数で考慮できる", "-n, m, x = list(map(int, input().split()))", "-a = [int(i) for i in input().split()]", "-# migi", "-cost_r = 0", "-for i in range(x, n):", "- if i in a:", "- cost_r += 1", "-cost_l = 0", "-for i in range(x):", "- if i in a:", "- cost_l += 1", "-print((min(cost_l, cost_r)))", "+mod = 10**9 + 7", "+sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000", "+d = collections.deque()", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+N, M, X = LI()", "+A = LI()", "+left = 0", "+right = 0", "+cs = [0 for i in range(N)]", "+for a in A:", "+ cs[a] = 1", "+for i in range(X):", "+ if cs[i]:", "+ left += 1", "+for i in range(X, N):", "+ if cs[i]:", "+ right += 1", "+print((min(left, right)))" ]
false
0.039645
0.1063
0.372958
[ "s497813587", "s969607043" ]
u968166680
p03033
python
s984475021
s819435087
1,244
792
136,036
66,000
Accepted
Accepted
36.33
import sys from heapq import heappush, heappop from operator import itemgetter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = map(int, readline().split()) work = [0] * N for i in range(N): s, t, x = map(int, readline().split()) work[i] = (x, s - x, t - x) query = list(map(int, read().split())) work.sort(key=itemgetter(1), reverse=True) hq = [] ans = [0] * Q for i, d in enumerate(query): while work and work[-1][1] <= d: heappush(hq, work[-1]) work.pop() while hq and hq[0][2] <= d: heappop(hq) if not hq: ans[i] = -1 else: ans[i] = hq[0][0] print(*ans, sep='\n') return if __name__ == '__main__': main()
import sys from heapq import heappush, heappop from operator import itemgetter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = map(int, readline().split()) work = [0] * N for i in range(N): s, t, x = map(int, readline().split()) work[i] = (x, s - x, t - x) query = list(map(int, read().split())) work.sort(key=itemgetter(1)) hq = [] ans = [0] * Q idx = 0 for i, d in enumerate(query): while idx < N and work[idx][1] <= d: heappush(hq, work[idx]) idx += 1 while hq and hq[0][2] <= d: heappop(hq) if not hq: ans[i] = -1 else: ans[i] = hq[0][0] print(*ans, sep='\n') return if __name__ == '__main__': main()
41
42
925
927
import sys from heapq import heappush, heappop from operator import itemgetter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = map(int, readline().split()) work = [0] * N for i in range(N): s, t, x = map(int, readline().split()) work[i] = (x, s - x, t - x) query = list(map(int, read().split())) work.sort(key=itemgetter(1), reverse=True) hq = [] ans = [0] * Q for i, d in enumerate(query): while work and work[-1][1] <= d: heappush(hq, work[-1]) work.pop() while hq and hq[0][2] <= d: heappop(hq) if not hq: ans[i] = -1 else: ans[i] = hq[0][0] print(*ans, sep="\n") return if __name__ == "__main__": main()
import sys from heapq import heappush, heappop from operator import itemgetter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = map(int, readline().split()) work = [0] * N for i in range(N): s, t, x = map(int, readline().split()) work[i] = (x, s - x, t - x) query = list(map(int, read().split())) work.sort(key=itemgetter(1)) hq = [] ans = [0] * Q idx = 0 for i, d in enumerate(query): while idx < N and work[idx][1] <= d: heappush(hq, work[idx]) idx += 1 while hq and hq[0][2] <= d: heappop(hq) if not hq: ans[i] = -1 else: ans[i] = hq[0][0] print(*ans, sep="\n") return if __name__ == "__main__": main()
false
2.380952
[ "- work.sort(key=itemgetter(1), reverse=True)", "+ work.sort(key=itemgetter(1))", "+ idx = 0", "- while work and work[-1][1] <= d:", "- heappush(hq, work[-1])", "- work.pop()", "+ while idx < N and work[idx][1] <= d:", "+ heappush(hq, work[idx])", "+ idx += 1" ]
false
0.043574
0.045845
0.950469
[ "s984475021", "s819435087" ]
u011621222
p00481
python
s999248880
s063866022
17,950
14,580
36,504
87,232
Accepted
Accepted
18.77
h,w,n = list(map(int, input().split())) stage = [eval(input()) for i in range(h)] starts = [str(i) for i in range(n)] goals = [str(i+1) for i in range(n)] starts_y = [0 for i in range(n)] starts_x = [0 for i in range(n)] goals_y = [0 for i in range(n)] goals_x = [0 for i in range(n)] starts[0] = "S" for y in range(h): for x in range(w): if stage[y][x] in starts: starts_y[starts.index(stage[y][x])] = y starts_x[starts.index(stage[y][x])] = x if stage[y][x] in goals: goals_y[goals.index(stage[y][x])] = y goals_x[goals.index(stage[y][x])] = x move_y = [1,-1,0,0] move_x = [0,0,1,-1] sum = 0 for start_y, start_x, goal_y, goal_x in zip(starts_y, starts_x, goals_y, goals_x): bfs_map = [[-1 for j in range(w)] for i in range(h)] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 0 goal = False while len(data_y) != 0 and not goal: y = data_y.pop(0) x = data_x.pop(0) goal = False for i in range(4): y += move_y[i] x += move_x[i] if y >= 0 and y < h and x >= 0 and x < w: if bfs_map[y][x] == -1 and stage[y][x] != "X": bfs_map[y][x] = bfs_map[y-move_y[i]][x-move_x[i]]+1 data_y.append(y) data_x.append(x) if bfs_map[goal_y][goal_x] != -1: sum += bfs_map[goal_y][goal_x] goal = True break y -= move_y[i] x -= move_x[i] print(sum)
from collections import deque h, w, n = list(map(int, input().split())) g = ['0'] * h sx, sy = -1, -1 pos = -1 for i in range(h): g[i] = eval(input()) if pos == -1: pos = g[i].find('S') if pos != -1: sx = i sy = pos book = set() queue = deque() ans = 0 Next = [[-1, 0], [1, 0], [0, -1], [0, 1]] for a in range(1, n + 1): book.clear() queue.clear() queue.append((sx, sy, 0)) aim = str(a) while len(queue): t = queue.popleft() if (t[0], t[1]) in book: continue if g[t[0]][t[1]] == aim: ans += t[2] # print(t[0], ' ', t[1], ' ', aim, ' ', ans) sx, sy = t[0], t[1] break book.add((t[0], t[1])) for i in range(4): tx = t[0] + Next[i][0] ty = t[1] + Next[i][1] if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != 'X': queue.append((tx, ty, t[2] + 1)) print(ans)
52
50
1,627
1,022
h, w, n = list(map(int, input().split())) stage = [eval(input()) for i in range(h)] starts = [str(i) for i in range(n)] goals = [str(i + 1) for i in range(n)] starts_y = [0 for i in range(n)] starts_x = [0 for i in range(n)] goals_y = [0 for i in range(n)] goals_x = [0 for i in range(n)] starts[0] = "S" for y in range(h): for x in range(w): if stage[y][x] in starts: starts_y[starts.index(stage[y][x])] = y starts_x[starts.index(stage[y][x])] = x if stage[y][x] in goals: goals_y[goals.index(stage[y][x])] = y goals_x[goals.index(stage[y][x])] = x move_y = [1, -1, 0, 0] move_x = [0, 0, 1, -1] sum = 0 for start_y, start_x, goal_y, goal_x in zip(starts_y, starts_x, goals_y, goals_x): bfs_map = [[-1 for j in range(w)] for i in range(h)] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 0 goal = False while len(data_y) != 0 and not goal: y = data_y.pop(0) x = data_x.pop(0) goal = False for i in range(4): y += move_y[i] x += move_x[i] if y >= 0 and y < h and x >= 0 and x < w: if bfs_map[y][x] == -1 and stage[y][x] != "X": bfs_map[y][x] = bfs_map[y - move_y[i]][x - move_x[i]] + 1 data_y.append(y) data_x.append(x) if bfs_map[goal_y][goal_x] != -1: sum += bfs_map[goal_y][goal_x] goal = True break y -= move_y[i] x -= move_x[i] print(sum)
from collections import deque h, w, n = list(map(int, input().split())) g = ["0"] * h sx, sy = -1, -1 pos = -1 for i in range(h): g[i] = eval(input()) if pos == -1: pos = g[i].find("S") if pos != -1: sx = i sy = pos book = set() queue = deque() ans = 0 Next = [[-1, 0], [1, 0], [0, -1], [0, 1]] for a in range(1, n + 1): book.clear() queue.clear() queue.append((sx, sy, 0)) aim = str(a) while len(queue): t = queue.popleft() if (t[0], t[1]) in book: continue if g[t[0]][t[1]] == aim: ans += t[2] # print(t[0], ' ', t[1], ' ', aim, ' ', ans) sx, sy = t[0], t[1] break book.add((t[0], t[1])) for i in range(4): tx = t[0] + Next[i][0] ty = t[1] + Next[i][1] if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != "X": queue.append((tx, ty, t[2] + 1)) print(ans)
false
3.846154
[ "+from collections import deque", "+", "-stage = [eval(input()) for i in range(h)]", "-starts = [str(i) for i in range(n)]", "-goals = [str(i + 1) for i in range(n)]", "-starts_y = [0 for i in range(n)]", "-starts_x = [0 for i in range(n)]", "-goals_y = [0 for i in range(n)]", "-goals_x = [0 for i in range(n)]", "-starts[0] = \"S\"", "-for y in range(h):", "- for x in range(w):", "- if stage[y][x] in starts:", "- starts_y[starts.index(stage[y][x])] = y", "- starts_x[starts.index(stage[y][x])] = x", "- if stage[y][x] in goals:", "- goals_y[goals.index(stage[y][x])] = y", "- goals_x[goals.index(stage[y][x])] = x", "-move_y = [1, -1, 0, 0]", "-move_x = [0, 0, 1, -1]", "-sum = 0", "-for start_y, start_x, goal_y, goal_x in zip(starts_y, starts_x, goals_y, goals_x):", "- bfs_map = [[-1 for j in range(w)] for i in range(h)]", "- data_y = [start_y]", "- data_x = [start_x]", "- bfs_map[start_y][start_x] = 0", "- goal = False", "- while len(data_y) != 0 and not goal:", "- y = data_y.pop(0)", "- x = data_x.pop(0)", "- goal = False", "+g = [\"0\"] * h", "+sx, sy = -1, -1", "+pos = -1", "+for i in range(h):", "+ g[i] = eval(input())", "+ if pos == -1:", "+ pos = g[i].find(\"S\")", "+ if pos != -1:", "+ sx = i", "+ sy = pos", "+book = set()", "+queue = deque()", "+ans = 0", "+Next = [[-1, 0], [1, 0], [0, -1], [0, 1]]", "+for a in range(1, n + 1):", "+ book.clear()", "+ queue.clear()", "+ queue.append((sx, sy, 0))", "+ aim = str(a)", "+ while len(queue):", "+ t = queue.popleft()", "+ if (t[0], t[1]) in book:", "+ continue", "+ if g[t[0]][t[1]] == aim:", "+ ans += t[2]", "+ # print(t[0], ' ', t[1], ' ', aim, ' ', ans)", "+ sx, sy = t[0], t[1]", "+ break", "+ book.add((t[0], t[1]))", "- y += move_y[i]", "- x += move_x[i]", "- if y >= 0 and y < h and x >= 0 and x < w:", "- if bfs_map[y][x] == -1 and stage[y][x] != \"X\":", "- bfs_map[y][x] = bfs_map[y - move_y[i]][x - move_x[i]] + 1", "- data_y.append(y)", "- data_x.append(x)", "- if bfs_map[goal_y][goal_x] != -1:", "- sum += bfs_map[goal_y][goal_x]", "- goal = True", "- break", "- y -= move_y[i]", "- x -= move_x[i]", "-print(sum)", "+ tx = t[0] + Next[i][0]", "+ ty = t[1] + Next[i][1]", "+ if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != \"X\":", "+ queue.append((tx, ty, t[2] + 1))", "+print(ans)" ]
false
0.091105
0.034937
2.607648
[ "s999248880", "s063866022" ]
u657913472
p03146
python
s687961753
s716059608
24
18
3,064
2,940
Accepted
Accepted
25
s=int(eval(input())) i=2 while s>1:s=[s//2,s*3+1][s%2];i+=1 print((max(i,4)))
s=int(eval(input())) i=4 while s>4or 3==s:s=[s//2,s*3+1][s%2];i+=1 print(i)
4
4
72
72
s = int(eval(input())) i = 2 while s > 1: s = [s // 2, s * 3 + 1][s % 2] i += 1 print((max(i, 4)))
s = int(eval(input())) i = 4 while s > 4 or 3 == s: s = [s // 2, s * 3 + 1][s % 2] i += 1 print(i)
false
0
[ "-i = 2", "-while s > 1:", "+i = 4", "+while s > 4 or 3 == s:", "-print((max(i, 4)))", "+print(i)" ]
false
0.040422
0.041023
0.98535
[ "s687961753", "s716059608" ]
u608007704
p02601
python
s861318184
s714128030
32
26
9,140
9,184
Accepted
Accepted
18.75
A,B,C=list(map(int,input().split())) K=int(eval(input())) for i in range(K): if A>=B: B*=2 elif B>=C: C*=2 if A<B and B<C: print("Yes") else: print("No")
import itertools A,B,C=list(map(int,input().split())) K=int(eval(input())) l=[0,1,2,3,4,5,6,7] for c in itertools.product(l, repeat=3): if sum(c) == K and A*2**c[0]<B*2**c[1] and B*2**c[1]<C*2**c[2]: print("Yes") exit(0) print("No")
14
11
177
250
A, B, C = list(map(int, input().split())) K = int(eval(input())) for i in range(K): if A >= B: B *= 2 elif B >= C: C *= 2 if A < B and B < C: print("Yes") else: print("No")
import itertools A, B, C = list(map(int, input().split())) K = int(eval(input())) l = [0, 1, 2, 3, 4, 5, 6, 7] for c in itertools.product(l, repeat=3): if sum(c) == K and A * 2 ** c[0] < B * 2 ** c[1] and B * 2 ** c[1] < C * 2 ** c[2]: print("Yes") exit(0) print("No")
false
21.428571
[ "+import itertools", "+", "-for i in range(K):", "- if A >= B:", "- B *= 2", "- elif B >= C:", "- C *= 2", "-if A < B and B < C:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+l = [0, 1, 2, 3, 4, 5, 6, 7]", "+for c in itertools.product(l, repeat=3):", "+ if sum(c) == K and A * 2 ** c[0] < B * 2 ** c[1] and B * 2 ** c[1] < C * 2 ** c[2]:", "+ print(\"Yes\")", "+ exit(0)", "+print(\"No\")" ]
false
0.03388
0.035134
0.964287
[ "s861318184", "s714128030" ]
u512212329
p02615
python
s683300069
s253145275
177
154
32,668
32,720
Accepted
Accepted
12.99
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.pop() edges.append(popped) edges.append(popped) print(ans) if __name__ == '__main__': main()
from collections import deque def main(): eval(input()) # n friendliness = deque(sorted(int(x) for x in input().split())) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.pop() edges.append(popped) edges.append(popped) print(ans) if __name__ == '__main__': main()
22
20
491
439
from collections import deque def main(): eval(input()) # n friendliness = [int(x) for x in input().split()] friendliness.sort() friendliness = deque(friendliness) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.pop() edges.append(popped) edges.append(popped) print(ans) if __name__ == "__main__": main()
from collections import deque def main(): eval(input()) # n friendliness = deque(sorted(int(x) for x in input().split())) edges = deque() popped = friendliness.pop() edges.append(popped) ans = 0 while friendliness: ans += edges.popleft() popped = friendliness.pop() edges.append(popped) edges.append(popped) print(ans) if __name__ == "__main__": main()
false
9.090909
[ "- friendliness = [int(x) for x in input().split()]", "- friendliness.sort()", "- friendliness = deque(friendliness)", "+ friendliness = deque(sorted(int(x) for x in input().split()))" ]
false
0.039212
0.048348
0.811029
[ "s683300069", "s253145275" ]
u014333473
p03360
python
s238666336
s568108786
32
25
8,928
9,060
Accepted
Accepted
21.88
a=sorted(map(int,input().split()));print((a[-1]*(2**(int(eval(input()))))+sum(a)-a[-1]))
a=sorted(map(int,input().split()))[::-1];print((a[0]*(2**(int(eval(input()))))+sum(a)-a[0]))
1
1
80
84
a = sorted(map(int, input().split())) print((a[-1] * (2 ** (int(eval(input())))) + sum(a) - a[-1]))
a = sorted(map(int, input().split()))[::-1] print((a[0] * (2 ** (int(eval(input())))) + sum(a) - a[0]))
false
0
[ "-a = sorted(map(int, input().split()))", "-print((a[-1] * (2 ** (int(eval(input())))) + sum(a) - a[-1]))", "+a = sorted(map(int, input().split()))[::-1]", "+print((a[0] * (2 ** (int(eval(input())))) + sum(a) - a[0]))" ]
false
0.040498
0.111903
0.361904
[ "s238666336", "s568108786" ]
u869790980
p03295
python
s958020659
s859283701
406
319
89,496
90,144
Accepted
Accepted
21.43
n,m = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(m)] c = 0 s.sort() cur = [] for u,v in s: if cur == []: cur = [u,v] if cur[1] <= u: cur = [u,v] c += 1 else: cur = [max(u, cur[0]),min(v, cur[1])] print(c + (1 if cur else 0)) """ ---- ------ 4 9 --- 5 6 ------? 5 5 ----- 10 """
n,m = list(map(int, input().split())) s,c = [list(map(int, input().split())) for _ in range(m)], 1 s.sort() cur = s[0] for u,v in s[1:]: if cur[1] <= u: cur,c = [u,v], c + 1 else: cur = [max(u, cur[0]),min(v, cur[1])] print(c)
24
9
393
234
n, m = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(m)] c = 0 s.sort() cur = [] for u, v in s: if cur == []: cur = [u, v] if cur[1] <= u: cur = [u, v] c += 1 else: cur = [max(u, cur[0]), min(v, cur[1])] print(c + (1 if cur else 0)) """ ---- ------ 4 9 --- 5 6 ------? 5 5 ----- 10 """
n, m = list(map(int, input().split())) s, c = [list(map(int, input().split())) for _ in range(m)], 1 s.sort() cur = s[0] for u, v in s[1:]: if cur[1] <= u: cur, c = [u, v], c + 1 else: cur = [max(u, cur[0]), min(v, cur[1])] print(c)
false
62.5
[ "-s = [list(map(int, input().split())) for _ in range(m)]", "-c = 0", "+s, c = [list(map(int, input().split())) for _ in range(m)], 1", "-cur = []", "-for u, v in s:", "- if cur == []:", "- cur = [u, v]", "+cur = s[0]", "+for u, v in s[1:]:", "- cur = [u, v]", "- c += 1", "+ cur, c = [u, v], c + 1", "-print(c + (1 if cur else 0))", "-\"\"\"", "- 4 9", "- 5 6", "- 5", "-\"\"\"", "+print(c)" ]
false
0.037397
0.082608
0.452709
[ "s958020659", "s859283701" ]
u524534026
p03071
python
s612518082
s597207160
28
17
3,064
2,940
Accepted
Accepted
39.29
a, b = list(map(int, input().split())) ans=0 for i in range(2): ans += max(a,b) if a>b: a -=1 else: b -=1 print(ans)
a, b = list(map(int, input().split())) preans = max(a*2-1,b*2-1) ans=max(preans,a+b) print(ans)
9
4
146
92
a, b = list(map(int, input().split())) ans = 0 for i in range(2): ans += max(a, b) if a > b: a -= 1 else: b -= 1 print(ans)
a, b = list(map(int, input().split())) preans = max(a * 2 - 1, b * 2 - 1) ans = max(preans, a + b) print(ans)
false
55.555556
[ "-ans = 0", "-for i in range(2):", "- ans += max(a, b)", "- if a > b:", "- a -= 1", "- else:", "- b -= 1", "+preans = max(a * 2 - 1, b * 2 - 1)", "+ans = max(preans, a + b)" ]
false
0.085826
0.068699
1.249308
[ "s612518082", "s597207160" ]
u440613652
p02725
python
s815406840
s421846945
143
117
32,204
32,292
Accepted
Accepted
18.18
k,n=list(map(int,input().split())) arr=list(map(int,input().split())) for i in range(n-1): arr.append(arr[i]+k) min_=99999999999 for i in range(n): if arr[i+n-1]-arr[i]<min_: min_=arr[i+n-1]-arr[i] print(min_)
k,n=list(map(int,input().split())) arr=list(map(int,input().split())) min_=99999999999 for i in range(n): if i==0: x=arr[-1]-arr[0] else: x=k-(arr[i]-arr[i-1]) if x<min_: min_=x print(min_)
14
16
225
212
k, n = list(map(int, input().split())) arr = list(map(int, input().split())) for i in range(n - 1): arr.append(arr[i] + k) min_ = 99999999999 for i in range(n): if arr[i + n - 1] - arr[i] < min_: min_ = arr[i + n - 1] - arr[i] print(min_)
k, n = list(map(int, input().split())) arr = list(map(int, input().split())) min_ = 99999999999 for i in range(n): if i == 0: x = arr[-1] - arr[0] else: x = k - (arr[i] - arr[i - 1]) if x < min_: min_ = x print(min_)
false
12.5
[ "-for i in range(n - 1):", "- arr.append(arr[i] + k)", "- if arr[i + n - 1] - arr[i] < min_:", "- min_ = arr[i + n - 1] - arr[i]", "+ if i == 0:", "+ x = arr[-1] - arr[0]", "+ else:", "+ x = k - (arr[i] - arr[i - 1])", "+ if x < min_:", "+ min_ = x" ]
false
0.040139
0.040763
0.984692
[ "s815406840", "s421846945" ]
u045953894
p02700
python
s848829508
s018963478
32
25
9,112
9,124
Accepted
Accepted
21.88
a,b,c,d = list(map(int,input().split())) for i in range(100): c -= b if c <= 0: print('Yes') break a -= d if a <= 0: print('No') break
import math a,b,c,d = list(map(int,input().split())) print(('Yes' if math.ceil(c/b) <= math.ceil(a/d) else 'No'))
10
3
185
107
a, b, c, d = list(map(int, input().split())) for i in range(100): c -= b if c <= 0: print("Yes") break a -= d if a <= 0: print("No") break
import math a, b, c, d = list(map(int, input().split())) print(("Yes" if math.ceil(c / b) <= math.ceil(a / d) else "No"))
false
70
[ "+import math", "+", "-for i in range(100):", "- c -= b", "- if c <= 0:", "- print(\"Yes\")", "- break", "- a -= d", "- if a <= 0:", "- print(\"No\")", "- break", "+print((\"Yes\" if math.ceil(c / b) <= math.ceil(a / d) else \"No\"))" ]
false
0.036145
0.093342
0.38723
[ "s848829508", "s018963478" ]
u952708174
p02713
python
s040711737
s483602871
509
217
67,804
89,148
Accepted
Accepted
57.37
def c_sum_of_gcd_of_tuples_easy(): 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) return ans print((c_sum_of_gcd_of_tuples_easy()))
def c_sum_of_gcd_of_tuples_easy(): import numpy as np K = int(eval(input())) r = np.arange(1, K + 1) return np.gcd.outer(np.gcd.outer(r, r), r).sum() print((c_sum_of_gcd_of_tuples_easy()))
12
8
300
205
def c_sum_of_gcd_of_tuples_easy(): 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) return ans print((c_sum_of_gcd_of_tuples_easy()))
def c_sum_of_gcd_of_tuples_easy(): import numpy as np K = int(eval(input())) r = np.arange(1, K + 1) return np.gcd.outer(np.gcd.outer(r, r), r).sum() print((c_sum_of_gcd_of_tuples_easy()))
false
33.333333
[ "- from math import gcd", "+ import numpy as np", "- 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)", "- return ans", "+ r = np.arange(1, K + 1)", "+ return np.gcd.outer(np.gcd.outer(r, r), r).sum()" ]
false
0.13529
0.185859
0.72792
[ "s040711737", "s483602871" ]
u040298438
p02573
python
s896961289
s359363567
617
502
47,156
47,132
Accepted
Accepted
18.64
# Union Find def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False else: if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True def same(x, y): return find(x) == find(y) def size(x): return -par[find(x)] import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = set() for _ in range(m): ab = sorted(map(int, input().split())) a.add((ab[0], ab[1])) par = [-1] * n for x, y in a: unite(x - 1, y - 1) d = {} for i in range(n): i = find(i) if i in d: d[i] += 1 else: d[i] = 1 print((max(d.values())))
# Union Find def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False else: if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True import sys input = sys.stdin.readline n, m = list(map(int, input().split())) par = [-1] * n a = set() for _ in range(m): ab = sorted(map(int, input().split())) a.add((ab[0], ab[1])) for x, y in a: unite(x - 1, y - 1) print((-min(par)))
52
37
829
618
# Union Find def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False else: if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True def same(x, y): return find(x) == find(y) def size(x): return -par[find(x)] import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = set() for _ in range(m): ab = sorted(map(int, input().split())) a.add((ab[0], ab[1])) par = [-1] * n for x, y in a: unite(x - 1, y - 1) d = {} for i in range(n): i = find(i) if i in d: d[i] += 1 else: d[i] = 1 print((max(d.values())))
# Union Find def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False else: if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True import sys input = sys.stdin.readline n, m = list(map(int, input().split())) par = [-1] * n a = set() for _ in range(m): ab = sorted(map(int, input().split())) a.add((ab[0], ab[1])) for x, y in a: unite(x - 1, y - 1) print((-min(par)))
false
28.846154
[ "-def same(x, y):", "- return find(x) == find(y)", "-", "-", "-def size(x):", "- return -par[find(x)]", "-", "-", "+par = [-1] * n", "-par = [-1] * n", "-d = {}", "-for i in range(n):", "- i = find(i)", "- if i in d:", "- d[i] += 1", "- else:", "- d[i] = 1", "-print((max(d.values())))", "+print((-min(par)))" ]
false
0.041283
0.036312
1.136891
[ "s896961289", "s359363567" ]
u562935282
p03078
python
s581906889
s968205818
502
234
105,612
46,192
Accepted
Accepted
53.39
def main(): import sys input = sys.stdin.readline x, y, z, k = 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) ret = [] for p, a in enumerate(A): for q, b in enumerate(B): if p * q > k: break for r, c in enumerate(C): if p * q * r > k: break ret.append(a + b + c) ret.sort(reverse=True) print(*ret[:k], sep='\n') main() # O(Klog^3K) # https://img.atcoder.jp/abc123/editorial.pdf
def main(): import sys input = sys.stdin.readline x, y, z, k = 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) ret = [] for p, a in enumerate(A, 1): for q, b in enumerate(B, 1): if p * q > k: break for r, c in enumerate(C, 1): if p * q * r > k: break ret.append(a + b + c) ret.sort(reverse=True) print(*ret[:k], sep='\n') main() # O(Klog^3K) # https://img.atcoder.jp/abc123/editorial.pdf # Enumerateのindex間違えていた
27
28
685
719
def main(): import sys input = sys.stdin.readline x, y, z, k = 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) ret = [] for p, a in enumerate(A): for q, b in enumerate(B): if p * q > k: break for r, c in enumerate(C): if p * q * r > k: break ret.append(a + b + c) ret.sort(reverse=True) print(*ret[:k], sep="\n") main() # O(Klog^3K) # https://img.atcoder.jp/abc123/editorial.pdf
def main(): import sys input = sys.stdin.readline x, y, z, k = 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) ret = [] for p, a in enumerate(A, 1): for q, b in enumerate(B, 1): if p * q > k: break for r, c in enumerate(C, 1): if p * q * r > k: break ret.append(a + b + c) ret.sort(reverse=True) print(*ret[:k], sep="\n") main() # O(Klog^3K) # https://img.atcoder.jp/abc123/editorial.pdf # Enumerateのindex間違えていた
false
3.571429
[ "- for p, a in enumerate(A):", "- for q, b in enumerate(B):", "+ for p, a in enumerate(A, 1):", "+ for q, b in enumerate(B, 1):", "- for r, c in enumerate(C):", "+ for r, c in enumerate(C, 1):", "+# Enumerateのindex間違えていた" ]
false
0.082903
0.082258
1.007832
[ "s581906889", "s968205818" ]
u083960235
p02947
python
s630698305
s438160120
309
240
25,716
31,664
Accepted
Accepted
22.33
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() S = [eval(input()) for i in range(N)] memo = defaultdict(int) L = [] for i in range(N): l = list(S[i]) l.sort() l = "".join(l) memo[str(l)] += 1 # print(memo) ans = 0 for m in list(memo.values()): ans += m * (m - 1)//2 print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect, bisect_left, bisect_right def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() S = [eval(input()) for i in range(N)] L = [] for s in S: c = "".join(sorted(s)) L.append(c) L.sort() S = set(L) # print(L) C = Counter(L) # print(C) cnt = 0 for s in S: cnt += C[s] * (C[s] - 1) // 2 print(cnt)
35
37
1,007
1,021
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() S = [eval(input()) for i in range(N)] memo = defaultdict(int) L = [] for i in range(N): l = list(S[i]) l.sort() l = "".join(l) memo[str(l)] += 1 # print(memo) ans = 0 for m in list(memo.values()): ans += m * (m - 1) // 2 print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect, bisect_left, bisect_right def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() S = [eval(input()) for i in range(N)] L = [] for s in S: c = "".join(sorted(s)) L.append(c) L.sort() S = set(L) # print(L) C = Counter(L) # print(C) cnt = 0 for s in S: cnt += C[s] * (C[s] - 1) // 2 print(cnt)
false
5.405405
[ "-from heapq import heapify, heappop, heappush", "+from fractions import gcd", "+from bisect import bisect, bisect_left, bisect_right", "-memo = defaultdict(int)", "-for i in range(N):", "- l = list(S[i])", "- l.sort()", "- l = \"\".join(l)", "- memo[str(l)] += 1", "-# print(memo)", "-ans = 0", "-for m in list(memo.values()):", "- ans += m * (m - 1) // 2", "-print(ans)", "+for s in S:", "+ c = \"\".join(sorted(s))", "+ L.append(c)", "+L.sort()", "+S = set(L)", "+# print(L)", "+C = Counter(L)", "+# print(C)", "+cnt = 0", "+for s in S:", "+ cnt += C[s] * (C[s] - 1) // 2", "+print(cnt)" ]
false
0.0464
0.04544
1.021129
[ "s630698305", "s438160120" ]
u883048396
p03775
python
s983277805
s758184922
30
27
3,060
3,444
Accepted
Accepted
10
iN = int(eval(input())) iLim = int(iN**0.5) + 1 iMinMax = len(str(iN)) for i in range(iLim+1,0,-1): if iN % i == 0: iMax = len(str(max(i,iN//i))) if iMinMax < iMax : print(iMinMax) exit() else: iMinMax = iMax print(iMinMax)
def 解(): iN = int(eval(input())) iLim = int(iN**0.5) + 1 iMinMax = len(str(iN)) for i in range(iLim+1,0,-1): if iN % i == 0: iMax = len(str(max(i,iN//i))) if iMinMax < iMax : print(iMinMax) exit() else: iMinMax = iMax print(iMinMax) 解()
14
15
297
358
iN = int(eval(input())) iLim = int(iN**0.5) + 1 iMinMax = len(str(iN)) for i in range(iLim + 1, 0, -1): if iN % i == 0: iMax = len(str(max(i, iN // i))) if iMinMax < iMax: print(iMinMax) exit() else: iMinMax = iMax print(iMinMax)
def 解(): iN = int(eval(input())) iLim = int(iN**0.5) + 1 iMinMax = len(str(iN)) for i in range(iLim + 1, 0, -1): if iN % i == 0: iMax = len(str(max(i, iN // i))) if iMinMax < iMax: print(iMinMax) exit() else: iMinMax = iMax print(iMinMax) 解()
false
6.666667
[ "-iN = int(eval(input()))", "-iLim = int(iN**0.5) + 1", "-iMinMax = len(str(iN))", "-for i in range(iLim + 1, 0, -1):", "- if iN % i == 0:", "- iMax = len(str(max(i, iN // i)))", "- if iMinMax < iMax:", "- print(iMinMax)", "- exit()", "- else:", "- iMinMax = iMax", "-print(iMinMax)", "+def 解():", "+ iN = int(eval(input()))", "+ iLim = int(iN**0.5) + 1", "+ iMinMax = len(str(iN))", "+ for i in range(iLim + 1, 0, -1):", "+ if iN % i == 0:", "+ iMax = len(str(max(i, iN // i)))", "+ if iMinMax < iMax:", "+ print(iMinMax)", "+ exit()", "+ else:", "+ iMinMax = iMax", "+ print(iMinMax)", "+", "+", "+解()" ]
false
0.043822
0.04302
1.018655
[ "s983277805", "s758184922" ]
u281303342
p03488
python
s378609160
s148413623
1,643
1,240
3,876
3,816
Accepted
Accepted
24.53
S = eval(input())+"T" X,Y = list(map(int,input().split())) dX0,dX,dY,dr,dc = 0,[],[],"x",0 for s in S: if s == "F": dc += 1 elif s == "T": if dr == "x": dr = "y" dX.append(dc) else: dr = "x" dY.append(dc) dc = 0 dX0,dX = dX[0],dX[1:] canX,canY = [dX0],[0] for dx in dX: t = [] for cx in canX: t.append(cx+dx) t.append(cx-dx) canX = list(set(t)) for dy in dY: t = [] for cy in canY: t.append(cy+dy) t.append(cy-dy) canY = list(set(t)) print(("Yes" if X in canX and Y in canY else "No"))
S = eval(input()) X,Y = list(map(int,input().split())) S = S+"T" d,cnt = 0,0 pos = [set([0]),set([0])] init = False for s in S: # 前進 if s=="F": cnt += 1 # 方向転換 else: # 移動先を全列挙 if cnt>0: temp = set([]) for p in pos[d]: temp.add(p+cnt) if init: temp.add(p-cnt) pos[d] = temp # 方向転換 d = (d+1)%2 cnt = 0 # 初回の方向転換を終えたかどうか init = True print(("Yes" if X in pos[0] and Y in pos[1] else "No"))
32
28
649
568
S = eval(input()) + "T" X, Y = list(map(int, input().split())) dX0, dX, dY, dr, dc = 0, [], [], "x", 0 for s in S: if s == "F": dc += 1 elif s == "T": if dr == "x": dr = "y" dX.append(dc) else: dr = "x" dY.append(dc) dc = 0 dX0, dX = dX[0], dX[1:] canX, canY = [dX0], [0] for dx in dX: t = [] for cx in canX: t.append(cx + dx) t.append(cx - dx) canX = list(set(t)) for dy in dY: t = [] for cy in canY: t.append(cy + dy) t.append(cy - dy) canY = list(set(t)) print(("Yes" if X in canX and Y in canY else "No"))
S = eval(input()) X, Y = list(map(int, input().split())) S = S + "T" d, cnt = 0, 0 pos = [set([0]), set([0])] init = False for s in S: # 前進 if s == "F": cnt += 1 # 方向転換 else: # 移動先を全列挙 if cnt > 0: temp = set([]) for p in pos[d]: temp.add(p + cnt) if init: temp.add(p - cnt) pos[d] = temp # 方向転換 d = (d + 1) % 2 cnt = 0 # 初回の方向転換を終えたかどうか init = True print(("Yes" if X in pos[0] and Y in pos[1] else "No"))
false
12.5
[ "-S = eval(input()) + \"T\"", "+S = eval(input())", "-dX0, dX, dY, dr, dc = 0, [], [], \"x\", 0", "+S = S + \"T\"", "+d, cnt = 0, 0", "+pos = [set([0]), set([0])]", "+init = False", "+ # 前進", "- dc += 1", "- elif s == \"T\":", "- if dr == \"x\":", "- dr = \"y\"", "- dX.append(dc)", "- else:", "- dr = \"x\"", "- dY.append(dc)", "- dc = 0", "-dX0, dX = dX[0], dX[1:]", "-canX, canY = [dX0], [0]", "-for dx in dX:", "- t = []", "- for cx in canX:", "- t.append(cx + dx)", "- t.append(cx - dx)", "- canX = list(set(t))", "-for dy in dY:", "- t = []", "- for cy in canY:", "- t.append(cy + dy)", "- t.append(cy - dy)", "- canY = list(set(t))", "-print((\"Yes\" if X in canX and Y in canY else \"No\"))", "+ cnt += 1", "+ # 方向転換", "+ else:", "+ # 移動先を全列挙", "+ if cnt > 0:", "+ temp = set([])", "+ for p in pos[d]:", "+ temp.add(p + cnt)", "+ if init:", "+ temp.add(p - cnt)", "+ pos[d] = temp", "+ # 方向転換", "+ d = (d + 1) % 2", "+ cnt = 0", "+ # 初回の方向転換を終えたかどうか", "+ init = True", "+print((\"Yes\" if X in pos[0] and Y in pos[1] else \"No\"))" ]
false
0.037068
0.07351
0.50426
[ "s378609160", "s148413623" ]
u661977789
p03457
python
s538127523
s471034526
413
326
3,316
3,316
Accepted
Accepted
21.07
N = int(eval(input())) T, X, Y = 0, 0, 0 cnt = 0 for _ in range(N): t, x, y = list(map(int,input().split())) dist = abs(x-X) + abs(y-Y) dt = t - T cnt += all([dist <= dt, (dist - dt) % 2 == 0]) T, X, Y = t, x, y print(("YNeos"[N!=cnt::2]))
for _ in range(int(eval(input()))): t, x, y = list(map(int,input().split())) if (t+x+y)%2 + (t<x+y): s = 1 break s = 0 print(("YNeos"[s::2]))
11
8
250
153
N = int(eval(input())) T, X, Y = 0, 0, 0 cnt = 0 for _ in range(N): t, x, y = list(map(int, input().split())) dist = abs(x - X) + abs(y - Y) dt = t - T cnt += all([dist <= dt, (dist - dt) % 2 == 0]) T, X, Y = t, x, y print(("YNeos"[N != cnt :: 2]))
for _ in range(int(eval(input()))): t, x, y = list(map(int, input().split())) if (t + x + y) % 2 + (t < x + y): s = 1 break s = 0 print(("YNeos"[s::2]))
false
27.272727
[ "-N = int(eval(input()))", "-T, X, Y = 0, 0, 0", "-cnt = 0", "-for _ in range(N):", "+for _ in range(int(eval(input()))):", "- dist = abs(x - X) + abs(y - Y)", "- dt = t - T", "- cnt += all([dist <= dt, (dist - dt) % 2 == 0])", "- T, X, Y = t, x, y", "-print((\"YNeos\"[N != cnt :: 2]))", "+ if (t + x + y) % 2 + (t < x + y):", "+ s = 1", "+ break", "+ s = 0", "+print((\"YNeos\"[s::2]))" ]
false
0.035355
0.035997
0.982168
[ "s538127523", "s471034526" ]
u186838327
p03371
python
s170642720
s127298979
178
66
39,696
67,728
Accepted
Accepted
62.92
a, b, c, x, y = list(map(int, input().split())) if a+b >= 2*c: if x >= y: ans = y*c*2 ans = ans+min((x-y)*a, (x-y)*2*c) else: ans = x*c*2 ans = ans+min((y-x)*b, (y-x)*2*c) else: ans = a*x + b*y print(ans)
a,b,c,x,y = list(map(int, input().split())) ans = 10**18 for k in range(2*10**5+1): if k%2 != 0: continue i = max(x-k//2, 0) j = max(y-k//2, 0) temp = a*i+b*j+c*k ans = min(ans, temp) print(ans)
13
11
257
228
a, b, c, x, y = list(map(int, input().split())) if a + b >= 2 * c: if x >= y: ans = y * c * 2 ans = ans + min((x - y) * a, (x - y) * 2 * c) else: ans = x * c * 2 ans = ans + min((y - x) * b, (y - x) * 2 * c) else: ans = a * x + b * y print(ans)
a, b, c, x, y = list(map(int, input().split())) ans = 10**18 for k in range(2 * 10**5 + 1): if k % 2 != 0: continue i = max(x - k // 2, 0) j = max(y - k // 2, 0) temp = a * i + b * j + c * k ans = min(ans, temp) print(ans)
false
15.384615
[ "-if a + b >= 2 * c:", "- if x >= y:", "- ans = y * c * 2", "- ans = ans + min((x - y) * a, (x - y) * 2 * c)", "- else:", "- ans = x * c * 2", "- ans = ans + min((y - x) * b, (y - x) * 2 * c)", "-else:", "- ans = a * x + b * y", "+ans = 10**18", "+for k in range(2 * 10**5 + 1):", "+ if k % 2 != 0:", "+ continue", "+ i = max(x - k // 2, 0)", "+ j = max(y - k // 2, 0)", "+ temp = a * i + b * j + c * k", "+ ans = min(ans, temp)" ]
false
0.063304
0.670173
0.094459
[ "s170642720", "s127298979" ]
u808427016
p03329
python
s016138039
s007917767
277
256
2,940
2,940
Accepted
Accepted
7.58
N = int(eval(input())) result = 100000000000 def calc(x, base): r = 0 while x: x, m = divmod(x, base) r += m return r for i in range(N + 1): result = min(result, calc(i, 6) + calc(N - i, 9)) print(result)
N = int(eval(input())) def calc(x, base): r = 0 while x: x, m = divmod(x, base) r += m return r result = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1)) print(result)
15
12
249
210
N = int(eval(input())) result = 100000000000 def calc(x, base): r = 0 while x: x, m = divmod(x, base) r += m return r for i in range(N + 1): result = min(result, calc(i, 6) + calc(N - i, 9)) print(result)
N = int(eval(input())) def calc(x, base): r = 0 while x: x, m = divmod(x, base) r += m return r result = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1)) print(result)
false
20
[ "-result = 100000000000", "-for i in range(N + 1):", "- result = min(result, calc(i, 6) + calc(N - i, 9))", "+result = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))" ]
false
0.059937
0.083558
0.717308
[ "s016138039", "s007917767" ]
u714642969
p02599
python
s558819263
s085979682
1,716
742
235,400
168,660
Accepted
Accepted
56.76
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple(map(int1,input().split())) lr=[() for i in range(Q)] for i in range(Q): l,r=map(int1,input().split()) lr[i]=(l,r,i) lr.sort(key=lambda t: t[1],reverse=1) class BIT: def __init__(self,n): self.num=n self.dat=[0]*(self.num+1) self.depth=n.bit_length() def add(self,i,x): i+=1 while i<=self.num: self.dat[i]+=x i+=i&-i def sum(self,i): i+=1 s=0 while i>0: s+=self.dat[i] i-=i&-i return s def lower_bound(self,x): sum_=0 pos=0 for i in range(self.depth,-1,-1): k=pos+(1<<i) if k<=self.num and sum_+self.dat[k]<x: sum_+=self.dat[k] pos+=1<<i return pos, sum_ b=BIT(N) lastap=[-1]*N ans=[-1]*Q l,r,j=lr.pop() for i,x in enumerate(a): if lastap[x]!=-1: b.add(lastap[x],-1) b.add(i,1) lastap[x]=i while r==i: ans[j]=b.sum(r)-b.sum(l-1) if lr: l,r,j=lr.pop() else: l,r,j=-1,-1,-1 print(*ans,sep='\n')
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple(map(int1,input().split())) lr=[0]*Q for i in range(Q): l,r=map(int1,input().split()) lr[i]=(r<<40)+(l<<20)+i lr.sort(reverse=1) class BIT: def __init__(self,n): self.num=n self.dat=[0]*(self.num+1) self.depth=n.bit_length() def add(self,i,x): i+=1 while i<=self.num: self.dat[i]+=x i+=i&-i def sum(self,i): i+=1 s=0 while i>0: s+=self.dat[i] i-=i&-i return s def lower_bound(self,x): sum_=0 pos=0 for i in range(self.depth,-1,-1): k=pos+(1<<i) if k<=self.num and sum_+self.dat[k]<x: sum_+=self.dat[k] pos+=1<<i return pos, sum_ b=BIT(N) lastap=[-1]*N ans=[-1]*Q mask=(1<<20)-1 lrj=lr.pop() j=lrj&mask lrj>>=20 l=lrj&mask r=lrj>>20 for i,x in enumerate(a): if lastap[x]!=-1: b.add(lastap[x],-1) b.add(i,1) lastap[x]=i while r==i: ans[j]=b.sum(r)-b.sum(l-1) if lr: lrj=lr.pop() j=lrj&mask lrj>>=20 l=lrj&mask r=lrj>>20 else: l,r,j=-1,-1,-1 print(*ans,sep='\n')
63
72
1,484
1,619
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() YesNo = lambda b: bool([print("Yes")] if b else print("No")) YESNO = lambda b: bool([print("YES")] if b else print("NO")) int1 = lambda x: int(x) - 1 N, Q = map(int, input().split()) a = tuple(map(int1, input().split())) lr = [() for i in range(Q)] for i in range(Q): l, r = map(int1, input().split()) lr[i] = (l, r, i) lr.sort(key=lambda t: t[1], reverse=1) class BIT: def __init__(self, n): self.num = n self.dat = [0] * (self.num + 1) self.depth = n.bit_length() def add(self, i, x): i += 1 while i <= self.num: self.dat[i] += x i += i & -i def sum(self, i): i += 1 s = 0 while i > 0: s += self.dat[i] i -= i & -i return s def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.num and sum_ + self.dat[k] < x: sum_ += self.dat[k] pos += 1 << i return pos, sum_ b = BIT(N) lastap = [-1] * N ans = [-1] * Q l, r, j = lr.pop() for i, x in enumerate(a): if lastap[x] != -1: b.add(lastap[x], -1) b.add(i, 1) lastap[x] = i while r == i: ans[j] = b.sum(r) - b.sum(l - 1) if lr: l, r, j = lr.pop() else: l, r, j = -1, -1, -1 print(*ans, sep="\n")
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() YesNo = lambda b: bool([print("Yes")] if b else print("No")) YESNO = lambda b: bool([print("YES")] if b else print("NO")) int1 = lambda x: int(x) - 1 N, Q = map(int, input().split()) a = tuple(map(int1, input().split())) lr = [0] * Q for i in range(Q): l, r = map(int1, input().split()) lr[i] = (r << 40) + (l << 20) + i lr.sort(reverse=1) class BIT: def __init__(self, n): self.num = n self.dat = [0] * (self.num + 1) self.depth = n.bit_length() def add(self, i, x): i += 1 while i <= self.num: self.dat[i] += x i += i & -i def sum(self, i): i += 1 s = 0 while i > 0: s += self.dat[i] i -= i & -i return s def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.num and sum_ + self.dat[k] < x: sum_ += self.dat[k] pos += 1 << i return pos, sum_ b = BIT(N) lastap = [-1] * N ans = [-1] * Q mask = (1 << 20) - 1 lrj = lr.pop() j = lrj & mask lrj >>= 20 l = lrj & mask r = lrj >> 20 for i, x in enumerate(a): if lastap[x] != -1: b.add(lastap[x], -1) b.add(i, 1) lastap[x] = i while r == i: ans[j] = b.sum(r) - b.sum(l - 1) if lr: lrj = lr.pop() j = lrj & mask lrj >>= 20 l = lrj & mask r = lrj >> 20 else: l, r, j = -1, -1, -1 print(*ans, sep="\n")
false
12.5
[ "-lr = [() for i in range(Q)]", "+lr = [0] * Q", "- lr[i] = (l, r, i)", "-lr.sort(key=lambda t: t[1], reverse=1)", "+ lr[i] = (r << 40) + (l << 20) + i", "+lr.sort(reverse=1)", "-l, r, j = lr.pop()", "+mask = (1 << 20) - 1", "+lrj = lr.pop()", "+j = lrj & mask", "+lrj >>= 20", "+l = lrj & mask", "+r = lrj >> 20", "- l, r, j = lr.pop()", "+ lrj = lr.pop()", "+ j = lrj & mask", "+ lrj >>= 20", "+ l = lrj & mask", "+ r = lrj >> 20" ]
false
0.035461
0.036344
0.975696
[ "s558819263", "s085979682" ]
u515740713
p02793
python
s035659870
s191063446
1,607
889
10,516
10,448
Accepted
Accepted
44.68
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10 ** 9 + 7 N = int(readline()) A = list(map(int,readline().split())) lcm = reduce(lambda x,y:x*y//gcd(x,y),A) ans = 0 ans = sum(lcm//x for x in A) print((ans%mod))
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10 ** 9 + 7 N = int(readline()) A = list(map(int,readline().split())) lcm = reduce(lambda x,y:x*y//gcd(x,y),A) ans = 0 coef = sum(pow(x,mod-2,mod) for x in A) ans = lcm * coef % mod print(ans)
13
14
347
378
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10**9 + 7 N = int(readline()) A = list(map(int, readline().split())) lcm = reduce(lambda x, y: x * y // gcd(x, y), A) ans = 0 ans = sum(lcm // x for x in A) print((ans % mod))
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10**9 + 7 N = int(readline()) A = list(map(int, readline().split())) lcm = reduce(lambda x, y: x * y // gcd(x, y), A) ans = 0 coef = sum(pow(x, mod - 2, mod) for x in A) ans = lcm * coef % mod print(ans)
false
7.142857
[ "-ans = sum(lcm // x for x in A)", "-print((ans % mod))", "+coef = sum(pow(x, mod - 2, mod) for x in A)", "+ans = lcm * coef % mod", "+print(ans)" ]
false
0.108931
0.036735
2.965333
[ "s035659870", "s191063446" ]
u654470292
p02844
python
s841742430
s460535231
486
353
41,964
41,180
Accepted
Accepted
27.37
import sys def input(): return sys.stdin.readline()[:-1] inf=float("inf") n=int(eval(input())) s=eval(input()) dp=[[0]*10,[0]*100,[0]*1000] for i in range(n): for j in range(100): if dp[1][j]>=1: # print(j*10+int(s[i])) dp[2][j*10+int(s[i])]+=1 for j in range(10): if dp[0][j]>=1: dp[1][j*10+int(s[i])]+=1 # print(j*10+int(s[i])) dp[0][int(s[i])]+=1 ans=0 # print(dp[0]) # print(dp[1]) for i in range(1000): if dp[2][i]>=1: ans+=1 print(ans)
n=int(eval(input())) s=eval(input()) ans=0 for i in range(1000): tmp=str(i) while len(tmp)<3: tmp="0"+tmp j=0 for k in range(n): if tmp[j]==s[k]: j+=1 if j==3: ans+=1 break print(ans)
24
16
544
225
import sys def input(): return sys.stdin.readline()[:-1] inf = float("inf") n = int(eval(input())) s = eval(input()) dp = [[0] * 10, [0] * 100, [0] * 1000] for i in range(n): for j in range(100): if dp[1][j] >= 1: # print(j*10+int(s[i])) dp[2][j * 10 + int(s[i])] += 1 for j in range(10): if dp[0][j] >= 1: dp[1][j * 10 + int(s[i])] += 1 # print(j*10+int(s[i])) dp[0][int(s[i])] += 1 ans = 0 # print(dp[0]) # print(dp[1]) for i in range(1000): if dp[2][i] >= 1: ans += 1 print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): tmp = str(i) while len(tmp) < 3: tmp = "0" + tmp j = 0 for k in range(n): if tmp[j] == s[k]: j += 1 if j == 3: ans += 1 break print(ans)
false
33.333333
[ "-import sys", "-", "-", "-def input():", "- return sys.stdin.readline()[:-1]", "-", "-", "-inf = float(\"inf\")", "-dp = [[0] * 10, [0] * 100, [0] * 1000]", "-for i in range(n):", "- for j in range(100):", "- if dp[1][j] >= 1:", "- # print(j*10+int(s[i]))", "- dp[2][j * 10 + int(s[i])] += 1", "- for j in range(10):", "- if dp[0][j] >= 1:", "- dp[1][j * 10 + int(s[i])] += 1", "- # print(j*10+int(s[i]))", "- dp[0][int(s[i])] += 1", "-# print(dp[0])", "-# print(dp[1])", "- if dp[2][i] >= 1:", "- ans += 1", "+ tmp = str(i)", "+ while len(tmp) < 3:", "+ tmp = \"0\" + tmp", "+ j = 0", "+ for k in range(n):", "+ if tmp[j] == s[k]:", "+ j += 1", "+ if j == 3:", "+ ans += 1", "+ break" ]
false
0.170041
0.069532
2.445503
[ "s841742430", "s460535231" ]
u111365362
p02841
python
s834124022
s276192194
19
17
3,316
2,940
Accepted
Accepted
10.53
a,b = list(map(int,input().split())) c,d = list(map(int,input().split())) if a == c: print((0)) else: print((1))
#22:04 a,b = list(map(int,input().split())) c,d = list(map(int,input().split())) print((int(a!=c)))
6
4
105
88
a, b = list(map(int, input().split())) c, d = list(map(int, input().split())) if a == c: print((0)) else: print((1))
# 22:04 a, b = list(map(int, input().split())) c, d = list(map(int, input().split())) print((int(a != c)))
false
33.333333
[ "+# 22:04", "-if a == c:", "- print((0))", "-else:", "- print((1))", "+print((int(a != c)))" ]
false
0.045394
0.048343
0.938994
[ "s834124022", "s276192194" ]
u133936772
p03816
python
s086198132
s614887680
52
46
20,208
22,540
Accepted
Accepted
11.54
_,*l=list(map(int,open(0).read().split())) c=len(set(l)) print((c-1+c%2))
eval(input()) c=len(set(input().split())) print((c-1+c%2))
3
3
67
52
_, *l = list(map(int, open(0).read().split())) c = len(set(l)) print((c - 1 + c % 2))
eval(input()) c = len(set(input().split())) print((c - 1 + c % 2))
false
0
[ "-_, *l = list(map(int, open(0).read().split()))", "-c = len(set(l))", "+eval(input())", "+c = len(set(input().split()))" ]
false
0.038659
0.041796
0.924944
[ "s086198132", "s614887680" ]
u312025627
p03606
python
s205783009
s829936136
217
186
39,152
45,936
Accepted
Accepted
14.29
n = int(eval(input())) ans = 0 for i in range(n): l, r = (int(i) for i in input().split()) ans += r - l + 1 print(ans)
def main(): import sys input = sys.stdin.buffer.readline N = int(eval(input())) seats = [0]*(10**5+2) LR = [[int(i) for i in input().split()] for j in range(N)] for li, ri in LR: seats[li] += 1 seats[ri+1] -= 1 from itertools import accumulate S = list(accumulate(seats)) print((sum(S))) if __name__ == '__main__': main()
6
16
125
387
n = int(eval(input())) ans = 0 for i in range(n): l, r = (int(i) for i in input().split()) ans += r - l + 1 print(ans)
def main(): import sys input = sys.stdin.buffer.readline N = int(eval(input())) seats = [0] * (10**5 + 2) LR = [[int(i) for i in input().split()] for j in range(N)] for li, ri in LR: seats[li] += 1 seats[ri + 1] -= 1 from itertools import accumulate S = list(accumulate(seats)) print((sum(S))) if __name__ == "__main__": main()
false
62.5
[ "-n = int(eval(input()))", "-ans = 0", "-for i in range(n):", "- l, r = (int(i) for i in input().split())", "- ans += r - l + 1", "-print(ans)", "+def main():", "+ import sys", "+", "+ input = sys.stdin.buffer.readline", "+ N = int(eval(input()))", "+ seats = [0] * (10**5 + 2)", "+ LR = [[int(i) for i in input().split()] for j in range(N)]", "+ for li, ri in LR:", "+ seats[li] += 1", "+ seats[ri + 1] -= 1", "+ from itertools import accumulate", "+", "+ S = list(accumulate(seats))", "+ print((sum(S)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.040663
0.050914
0.798666
[ "s205783009", "s829936136" ]
u102461423
p04003
python
s820265997
s660889294
2,693
1,712
196,696
187,292
Accepted
Accepted
36.43
import sys input = sys.stdin.readline from collections import defaultdict """ (駅、会社)を頂点にグラフを持つ。頂点数O(M)。 そのまま辺を貼ると辺が多くなりすぎる。 (駅、会社) -> (駅、無属性) -> (駅、会社) """ L = 32 mask = (1 << L) - 1 N,M = list(map(int,input().split())) graph = defaultdict(list) for _ in range(M): p,q,c = list(map(int,input().split())) p <<= L q <<= L graph[p].append(p+c) graph[p+c].append(p) graph[q].append(q+c) graph[q+c].append(q) graph[p+c].append(q+c) graph[q+c].append(p+c) INF = 10 ** 9 dist = defaultdict(lambda: INF) start = 1 << L goal = N << L q = [start] # 0 が会社に属していない状態 dist[start] = 0 d = 0 q0 = [] q1 = [] while q: for x in q: if x & mask == 0: for y in graph[x]: if dist[y] <= d + 1: continue dist[y] = d + 1 q1.append(y) else: for y in graph[x]: if dist[y] <= d: continue dist[y] = d q0.append(y) if q0: q = q0 q0 = [] continue q = q1 q1 = [] d += 1 answer = dist[goal] if answer == INF: answer = -1 print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque N,M = list(map(int,readline().split())) if M == 0: print((-1)) exit() m = list(map(int,read().split())) P,Q,C = list(zip(*list(zip(m,m,m)))) V = [] V += [p<<32 for p in range(1,N+1)] V += [(p<<32)+c for p,c in zip(P,C)] V += [(q<<32)+c for q,c in zip(Q,C)] V = set(V) label = {x:i for i,x in enumerate(V)} start = label[1<<32] goal = label[N<<32] N = len(V) graph = [[] for _ in range(N)] for p,q,c in zip(P,Q,C): v0 = label[p<<32]; v1 = label[(p<<32)+c] w0 = label[q<<32]; w1 = label[(q<<32)+c] graph[v0].append((v1,1)) graph[w0].append((w1,1)) graph[v1].append((v0,0)) graph[w1].append((w0,0)) graph[v1].append((w1,0)) graph[w1].append((v1,0)) INF = 10 ** 10 dist = [INF] * N dist[start] = 0 q = deque([(0,start)]) while q: dv,v = q.popleft() for w,cost in graph[v]: dw = dv + cost if dw >= dist[w]: continue dist[w] = dw if not cost: q.appendleft((dw,w)) else: q.append((dw,w)) answer = dist[goal] if answer == INF: answer = -1 print(answer)
62
55
1,216
1,252
import sys input = sys.stdin.readline from collections import defaultdict """ (駅、会社)を頂点にグラフを持つ。頂点数O(M)。 そのまま辺を貼ると辺が多くなりすぎる。 (駅、会社) -> (駅、無属性) -> (駅、会社) """ L = 32 mask = (1 << L) - 1 N, M = list(map(int, input().split())) graph = defaultdict(list) for _ in range(M): p, q, c = list(map(int, input().split())) p <<= L q <<= L graph[p].append(p + c) graph[p + c].append(p) graph[q].append(q + c) graph[q + c].append(q) graph[p + c].append(q + c) graph[q + c].append(p + c) INF = 10**9 dist = defaultdict(lambda: INF) start = 1 << L goal = N << L q = [start] # 0 が会社に属していない状態 dist[start] = 0 d = 0 q0 = [] q1 = [] while q: for x in q: if x & mask == 0: for y in graph[x]: if dist[y] <= d + 1: continue dist[y] = d + 1 q1.append(y) else: for y in graph[x]: if dist[y] <= d: continue dist[y] = d q0.append(y) if q0: q = q0 q0 = [] continue q = q1 q1 = [] d += 1 answer = dist[goal] if answer == INF: answer = -1 print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque N, M = list(map(int, readline().split())) if M == 0: print((-1)) exit() m = list(map(int, read().split())) P, Q, C = list(zip(*list(zip(m, m, m)))) V = [] V += [p << 32 for p in range(1, N + 1)] V += [(p << 32) + c for p, c in zip(P, C)] V += [(q << 32) + c for q, c in zip(Q, C)] V = set(V) label = {x: i for i, x in enumerate(V)} start = label[1 << 32] goal = label[N << 32] N = len(V) graph = [[] for _ in range(N)] for p, q, c in zip(P, Q, C): v0 = label[p << 32] v1 = label[(p << 32) + c] w0 = label[q << 32] w1 = label[(q << 32) + c] graph[v0].append((v1, 1)) graph[w0].append((w1, 1)) graph[v1].append((v0, 0)) graph[w1].append((w0, 0)) graph[v1].append((w1, 0)) graph[w1].append((v1, 0)) INF = 10**10 dist = [INF] * N dist[start] = 0 q = deque([(0, start)]) while q: dv, v = q.popleft() for w, cost in graph[v]: dw = dv + cost if dw >= dist[w]: continue dist[w] = dw if not cost: q.appendleft((dw, w)) else: q.append((dw, w)) answer = dist[goal] if answer == INF: answer = -1 print(answer)
false
11.290323
[ "-input = sys.stdin.readline", "-from collections import defaultdict", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+from collections import deque", "-\"\"\"", "-(駅、会社)を頂点にグラフを持つ。頂点数O(M)。", "-そのまま辺を貼ると辺が多くなりすぎる。", "-(駅、会社) -> (駅、無属性) -> (駅、会社)", "-\"\"\"", "-L = 32", "-mask = (1 << L) - 1", "-N, M = list(map(int, input().split()))", "-graph = defaultdict(list)", "-for _ in range(M):", "- p, q, c = list(map(int, input().split()))", "- p <<= L", "- q <<= L", "- graph[p].append(p + c)", "- graph[p + c].append(p)", "- graph[q].append(q + c)", "- graph[q + c].append(q)", "- graph[p + c].append(q + c)", "- graph[q + c].append(p + c)", "-INF = 10**9", "-dist = defaultdict(lambda: INF)", "-start = 1 << L", "-goal = N << L", "-q = [start] # 0 が会社に属していない状態", "+N, M = list(map(int, readline().split()))", "+if M == 0:", "+ print((-1))", "+ exit()", "+m = list(map(int, read().split()))", "+P, Q, C = list(zip(*list(zip(m, m, m))))", "+V = []", "+V += [p << 32 for p in range(1, N + 1)]", "+V += [(p << 32) + c for p, c in zip(P, C)]", "+V += [(q << 32) + c for q, c in zip(Q, C)]", "+V = set(V)", "+label = {x: i for i, x in enumerate(V)}", "+start = label[1 << 32]", "+goal = label[N << 32]", "+N = len(V)", "+graph = [[] for _ in range(N)]", "+for p, q, c in zip(P, Q, C):", "+ v0 = label[p << 32]", "+ v1 = label[(p << 32) + c]", "+ w0 = label[q << 32]", "+ w1 = label[(q << 32) + c]", "+ graph[v0].append((v1, 1))", "+ graph[w0].append((w1, 1))", "+ graph[v1].append((v0, 0))", "+ graph[w1].append((w0, 0))", "+ graph[v1].append((w1, 0))", "+ graph[w1].append((v1, 0))", "+INF = 10**10", "+dist = [INF] * N", "-d = 0", "-q0 = []", "-q1 = []", "+q = deque([(0, start)])", "- for x in q:", "- if x & mask == 0:", "- for y in graph[x]:", "- if dist[y] <= d + 1:", "- continue", "- dist[y] = d + 1", "- q1.append(y)", "+ dv, v = q.popleft()", "+ for w, cost in graph[v]:", "+ dw = dv + cost", "+ if dw >= dist[w]:", "+ continue", "+ dist[w] = dw", "+ if not cost:", "+ q.appendleft((dw, w))", "- for y in graph[x]:", "- if dist[y] <= d:", "- continue", "- dist[y] = d", "- q0.append(y)", "- if q0:", "- q = q0", "- q0 = []", "- continue", "- q = q1", "- q1 = []", "- d += 1", "+ q.append((dw, w))" ]
false
0.072108
0.062152
1.160195
[ "s820265997", "s660889294" ]
u875541136
p02707
python
s315017298
s213349750
235
184
32,240
34,052
Accepted
Accepted
21.7
N = int(eval(input())) A = list(map(int, input().split())) i = -1 A = sorted(A) + [0] for n in range(N): count = 0 while(A[i+1] == n+1): i += 1 count += 1 print(count)
import collections N = int(eval(input())) A = list(map(int, input().split())) count = collections.Counter(A) for n in range(N): print((count[n+1]))
10
6
184
146
N = int(eval(input())) A = list(map(int, input().split())) i = -1 A = sorted(A) + [0] for n in range(N): count = 0 while A[i + 1] == n + 1: i += 1 count += 1 print(count)
import collections N = int(eval(input())) A = list(map(int, input().split())) count = collections.Counter(A) for n in range(N): print((count[n + 1]))
false
40
[ "+import collections", "+", "-i = -1", "-A = sorted(A) + [0]", "+count = collections.Counter(A)", "- count = 0", "- while A[i + 1] == n + 1:", "- i += 1", "- count += 1", "- print(count)", "+ print((count[n + 1]))" ]
false
0.038763
0.06973
0.555897
[ "s315017298", "s213349750" ]
u164727245
p02669
python
s754382478
s846414914
1,639
1,180
11,220
10,960
Accepted
Accepted
28
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = ((2, a), (3, b), (5, c)) dp = defaultdict(lambda: n*d) stack = [(n, 0)] while stack: rem, cost = stack.pop() if min(dp[0], dp[rem]) <= cost: continue dp[rem] = cost dp[0] = min(dp[0], cost+rem*d) if 0 < rem: for x, y in ABC: l, h = rem//x, -(-rem//x) stack.append((l, d*abs(l*x-rem)+cost+y*(0 < l))) stack.append((h, d*abs(h*x-rem)+cost+y)) ret.append(str(dp[0])) return '\n'.join(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = ((2, a), (3, b), (5, c)) dp = defaultdict(lambda: n*d) stack = [(n, 0)] while stack: rem, cost = stack.pop() if min(dp[0], dp[rem]) <= cost: continue dp[rem] = cost dp[0] = min(dp[0], cost+rem*d) if 0 < rem: for x, y in ABC: div, m = divmod(rem, x) if div: stack.append((div, d*m+cost+y)) if m: stack.append((div+1, d*(x-m)+cost+y)) ret.append(str(dp[0])) return '\n'.join(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
34
36
921
963
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = ((2, a), (3, b), (5, c)) dp = defaultdict(lambda: n * d) stack = [(n, 0)] while stack: rem, cost = stack.pop() if min(dp[0], dp[rem]) <= cost: continue dp[rem] = cost dp[0] = min(dp[0], cost + rem * d) if 0 < rem: for x, y in ABC: l, h = rem // x, -(-rem // x) stack.append((l, d * abs(l * x - rem) + cost + y * (0 < l))) stack.append((h, d * abs(h * x - rem) + cost + y)) ret.append(str(dp[0])) return "\n".join(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = ((2, a), (3, b), (5, c)) dp = defaultdict(lambda: n * d) stack = [(n, 0)] while stack: rem, cost = stack.pop() if min(dp[0], dp[rem]) <= cost: continue dp[rem] = cost dp[0] = min(dp[0], cost + rem * d) if 0 < rem: for x, y in ABC: div, m = divmod(rem, x) if div: stack.append((div, d * m + cost + y)) if m: stack.append((div + 1, d * (x - m) + cost + y)) ret.append(str(dp[0])) return "\n".join(ret) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
5.555556
[ "- l, h = rem // x, -(-rem // x)", "- stack.append((l, d * abs(l * x - rem) + cost + y * (0 < l)))", "- stack.append((h, d * abs(h * x - rem) + cost + y))", "+ div, m = divmod(rem, x)", "+ if div:", "+ stack.append((div, d * m + cost + y))", "+ if m:", "+ stack.append((div + 1, d * (x - m) + cost + y))" ]
false
1.034231
0.961842
1.075261
[ "s754382478", "s846414914" ]
u064505481
p03163
python
s562917926
s108714580
879
253
278,488
45,296
Accepted
Accepted
71.22
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def main(): n, W = rli() weight = [0 for _ in range(n)] val = [0 for _ in range(n)] for i in range(n): w, v = rli() weight[i], val[i] = w, v #dp(i, j) = max val using items 1,...,i at # weight j dp = [[NINF for c in range(W+1)] for r in range(n+1)] for r in range(n+1): dp[r][0] = 0 for c in range(W+1): dp[0][c] = 0 for r in range(1, n+1): w, v = weight[r-1], val[r-1] for c in range(1, W+1): dp[r][c] = dp[r-1][c] if c - w >= 0: dp[r][c] = max(dp[r][c], dp[r-1][c], v + dp[r-1][c-w]) print((dp[-1][-1])) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout from collections import deque, defaultdict import math as m rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def main(): n, W = rli() items = [] for _ in range(n): w, v = rli() items.append((w, v)) dp = [0 for _ in range(W + 1)] for w, v in items: for i in range(W, -1, -1): if i - w >= 0: dp[i] = max(dp[i], dp[i-w] + v) print((dp[-1])) stdout.close() if __name__ == "__main__": main()
33
26
814
573
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def main(): n, W = rli() weight = [0 for _ in range(n)] val = [0 for _ in range(n)] for i in range(n): w, v = rli() weight[i], val[i] = w, v # dp(i, j) = max val using items 1,...,i at # weight j dp = [[NINF for c in range(W + 1)] for r in range(n + 1)] for r in range(n + 1): dp[r][0] = 0 for c in range(W + 1): dp[0][c] = 0 for r in range(1, n + 1): w, v = weight[r - 1], val[r - 1] for c in range(1, W + 1): dp[r][c] = dp[r - 1][c] if c - w >= 0: dp[r][c] = max(dp[r][c], dp[r - 1][c], v + dp[r - 1][c - w]) print((dp[-1][-1])) stdout.close() if __name__ == "__main__": main()
from sys import stdin, stdout from collections import deque, defaultdict import math as m rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def main(): n, W = rli() items = [] for _ in range(n): w, v = rli() items.append((w, v)) dp = [0 for _ in range(W + 1)] for w, v in items: for i in range(W, -1, -1): if i - w >= 0: dp[i] = max(dp[i], dp[i - w] + v) print((dp[-1])) stdout.close() if __name__ == "__main__": main()
false
21.212121
[ "+from collections import deque, defaultdict", "+import math as m", "- weight = [0 for _ in range(n)]", "- val = [0 for _ in range(n)]", "- for i in range(n):", "+ items = []", "+ for _ in range(n):", "- weight[i], val[i] = w, v", "- # dp(i, j) = max val using items 1,...,i at", "- # \t\t\tweight j", "- dp = [[NINF for c in range(W + 1)] for r in range(n + 1)]", "- for r in range(n + 1):", "- dp[r][0] = 0", "- for c in range(W + 1):", "- dp[0][c] = 0", "- for r in range(1, n + 1):", "- w, v = weight[r - 1], val[r - 1]", "- for c in range(1, W + 1):", "- dp[r][c] = dp[r - 1][c]", "- if c - w >= 0:", "- dp[r][c] = max(dp[r][c], dp[r - 1][c], v + dp[r - 1][c - w])", "- print((dp[-1][-1]))", "+ items.append((w, v))", "+ dp = [0 for _ in range(W + 1)]", "+ for w, v in items:", "+ for i in range(W, -1, -1):", "+ if i - w >= 0:", "+ dp[i] = max(dp[i], dp[i - w] + v)", "+ print((dp[-1]))" ]
false
0.040633
0.118194
0.343785
[ "s562917926", "s108714580" ]
u605880635
p02630
python
s137933304
s510647233
482
372
72,480
26,936
Accepted
Accepted
22.82
# 371 ms, 27032 KB n = int(eval(input())) a = list(map(int, input().split())) q = int(eval(input())) b = [] c = [] bc = [list(map(int, input().split())) for _ in range(q)] b, c = [list(i) for i in zip(*bc)] dic = {} for aa in a: dic[aa] = dic.get(aa, 0) + 1 s = sum(a) for i in range(q): if b[i] not in dic: print((str(s))) continue s += (c[i]-b[i]) * dic[b[i]] dic[c[i]] = dic.get(c[i], 0) + dic[b[i]] del dic[b[i]] print(s)
# 371 ms, 27032 KB n = int(eval(input())) a = list(map(int, input().split())) q = int(eval(input())) b = [] c = [] for _ in range(q): bi, ci = list(map(int, input().split())) b.append(bi) c.append(ci) #bc = [map(int, input().split()) for _ in range(q)] #b, c = [list(i) for i in zip(*bc)] dic = {} for aa in a: dic[aa] = dic.get(aa, 0) + 1 s = sum(a) for i in range(q): if b[i] not in dic: print((str(s))) continue s += (c[i]-b[i]) * dic[b[i]] dic[c[i]] = dic.get(c[i], 0) + dic[b[i]] del dic[b[i]] print(s)
23
27
474
578
# 371 ms, 27032 KB n = int(eval(input())) a = list(map(int, input().split())) q = int(eval(input())) b = [] c = [] bc = [list(map(int, input().split())) for _ in range(q)] b, c = [list(i) for i in zip(*bc)] dic = {} for aa in a: dic[aa] = dic.get(aa, 0) + 1 s = sum(a) for i in range(q): if b[i] not in dic: print((str(s))) continue s += (c[i] - b[i]) * dic[b[i]] dic[c[i]] = dic.get(c[i], 0) + dic[b[i]] del dic[b[i]] print(s)
# 371 ms, 27032 KB n = int(eval(input())) a = list(map(int, input().split())) q = int(eval(input())) b = [] c = [] for _ in range(q): bi, ci = list(map(int, input().split())) b.append(bi) c.append(ci) # bc = [map(int, input().split()) for _ in range(q)] # b, c = [list(i) for i in zip(*bc)] dic = {} for aa in a: dic[aa] = dic.get(aa, 0) + 1 s = sum(a) for i in range(q): if b[i] not in dic: print((str(s))) continue s += (c[i] - b[i]) * dic[b[i]] dic[c[i]] = dic.get(c[i], 0) + dic[b[i]] del dic[b[i]] print(s)
false
14.814815
[ "-bc = [list(map(int, input().split())) for _ in range(q)]", "-b, c = [list(i) for i in zip(*bc)]", "+for _ in range(q):", "+ bi, ci = list(map(int, input().split()))", "+ b.append(bi)", "+ c.append(ci)", "+# bc = [map(int, input().split()) for _ in range(q)]", "+# b, c = [list(i) for i in zip(*bc)]" ]
false
0.041013
0.183497
0.223508
[ "s137933304", "s510647233" ]
u775681539
p02838
python
s352147829
s442007280
1,997
484
35,852
89,712
Accepted
Accepted
75.76
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] P = int(1e9)+7 s = 0 for k in range(60): cnt = 0 for num in A: if (num>>k) & 1: cnt += 1 s += cnt*(N-cnt) * 2**k s %= P print(s) if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): n = int(readline()) a = [int(i) for i in readline().split()] s = 0 P = int(1e9)+7 for k in range(60): cnt = 0 for e in a: if (e>>k) & 1: cnt += 1 s += cnt*(n-cnt)*pow(2, k, P) s %= P print(s) if __name__ == '__main__': main()
20
20
461
467
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] P = int(1e9) + 7 s = 0 for k in range(60): cnt = 0 for num in A: if (num >> k) & 1: cnt += 1 s += cnt * (N - cnt) * 2**k s %= P print(s) if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): n = int(readline()) a = [int(i) for i in readline().split()] s = 0 P = int(1e9) + 7 for k in range(60): cnt = 0 for e in a: if (e >> k) & 1: cnt += 1 s += cnt * (n - cnt) * pow(2, k, P) s %= P print(s) if __name__ == "__main__": main()
false
0
[ "- N = int(readline())", "- A = [int(i) for i in readline().split()]", "+ n = int(readline())", "+ a = [int(i) for i in readline().split()]", "+ s = 0", "- s = 0", "- for num in A:", "- if (num >> k) & 1:", "+ for e in a:", "+ if (e >> k) & 1:", "- s += cnt * (N - cnt) * 2**k", "+ s += cnt * (n - cnt) * pow(2, k, P)" ]
false
0.042096
0.037262
1.129731
[ "s352147829", "s442007280" ]
u607155447
p02951
python
s785006313
s522891032
32
29
9,148
9,152
Accepted
Accepted
9.38
A, B, C = list(map(int, input().split())) D = B + C - A print((max(0, D)))
A, B, C = list(map(int, input().split())) print((max(0, B + C - A)))
3
2
68
61
A, B, C = list(map(int, input().split())) D = B + C - A print((max(0, D)))
A, B, C = list(map(int, input().split())) print((max(0, B + C - A)))
false
33.333333
[ "-D = B + C - A", "-print((max(0, D)))", "+print((max(0, B + C - A)))" ]
false
0.046269
0.046636
0.992142
[ "s785006313", "s522891032" ]
u934442292
p02960
python
s229394446
s426223748
336
173
96,168
96,036
Accepted
Accepted
48.51
import sys input = sys.stdin.readline P = 10 ** 9 + 7 Q = 13 def main(): S = input().rstrip() N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): base = pow(10, N - 1 - i, Q) D = S[i] if D == "?": for d in range(10): n = d * base for j in range(Q): next_j = (j + n) % Q dp[i + 1][next_j] += dp[i][j] dp[i + 1][next_j] %= P else: n = int(D) * base for j in range(Q): next_j = (j + n) % Q dp[i + 1][(j + n) % Q] += dp[i][j] dp[i + 1][(j + n) % Q] %= P ans = dp[N][5] print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline P = 10 ** 9 + 7 Q = 13 def main(): S = input().rstrip() N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): D = S[i] if D == "?": for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: d = int(D) for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P ans = dp[N][5] print(ans) if __name__ == "__main__": main()
37
34
822
654
import sys input = sys.stdin.readline P = 10**9 + 7 Q = 13 def main(): S = input().rstrip() N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): base = pow(10, N - 1 - i, Q) D = S[i] if D == "?": for d in range(10): n = d * base for j in range(Q): next_j = (j + n) % Q dp[i + 1][next_j] += dp[i][j] dp[i + 1][next_j] %= P else: n = int(D) * base for j in range(Q): next_j = (j + n) % Q dp[i + 1][(j + n) % Q] += dp[i][j] dp[i + 1][(j + n) % Q] %= P ans = dp[N][5] print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline P = 10**9 + 7 Q = 13 def main(): S = input().rstrip() N = len(S) dp = [[0] * Q for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): D = S[i] if D == "?": for d in range(10): for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] else: d = int(D) for j in range(Q): dp[i + 1][(10 * j + d) % Q] += dp[i][j] for j in range(Q): dp[i + 1][j] %= P ans = dp[N][5] print(ans) if __name__ == "__main__": main()
false
8.108108
[ "- base = pow(10, N - 1 - i, Q)", "- n = d * base", "- next_j = (j + n) % Q", "- dp[i + 1][next_j] += dp[i][j]", "- dp[i + 1][next_j] %= P", "+ dp[i + 1][(10 * j + d) % Q] += dp[i][j]", "- n = int(D) * base", "+ d = int(D)", "- next_j = (j + n) % Q", "- dp[i + 1][(j + n) % Q] += dp[i][j]", "- dp[i + 1][(j + n) % Q] %= P", "+ dp[i + 1][(10 * j + d) % Q] += dp[i][j]", "+ for j in range(Q):", "+ dp[i + 1][j] %= P" ]
false
0.038087
0.03807
1.000436
[ "s229394446", "s426223748" ]
u948524308
p03831
python
s086199805
s158086722
113
94
15,020
14,224
Accepted
Accepted
16.81
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans1 = 0 ans2 = 0 for i in range(1, N): D = X[i] - X[i - 1] ans1 += D * A ans2 += min(D * A, B) print((min(ans1, ans2)))
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 for i in range(1, N): D = X[i] - X[i - 1] ans += min(D * A, B) print(ans)
11
9
215
172
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans1 = 0 ans2 = 0 for i in range(1, N): D = X[i] - X[i - 1] ans1 += D * A ans2 += min(D * A, B) print((min(ans1, ans2)))
N, A, B = list(map(int, input().split())) X = list(map(int, input().split())) ans = 0 for i in range(1, N): D = X[i] - X[i - 1] ans += min(D * A, B) print(ans)
false
18.181818
[ "-ans1 = 0", "-ans2 = 0", "+ans = 0", "- ans1 += D * A", "- ans2 += min(D * A, B)", "-print((min(ans1, ans2)))", "+ ans += min(D * A, B)", "+print(ans)" ]
false
0.039162
0.042298
0.925864
[ "s086199805", "s158086722" ]
u631299617
p04045
python
s013126239
s746711703
199
19
3,060
3,060
Accepted
Accepted
90.45
n,k=list(map(int,input().split())) d=input().split() while 1: t=0 p=list(str(n)) q=len(p) for c in range(q): if t==1: break for b in range(k): if p[c]==d[b]: n=n+1 t=1 break if t==0: break print(n)
n,k=list(map(int,input().split())) d=input().split() while 1: t=0 p=list(str(n)) q=len(p) for c in range(q): if t==1: break for b in range(k): if p[c]==d[b]: r=10**(q-c-1) n=int(n/r+1)*r t=1 break if t==0: break print(n)
17
18
323
363
n, k = list(map(int, input().split())) d = input().split() while 1: t = 0 p = list(str(n)) q = len(p) for c in range(q): if t == 1: break for b in range(k): if p[c] == d[b]: n = n + 1 t = 1 break if t == 0: break print(n)
n, k = list(map(int, input().split())) d = input().split() while 1: t = 0 p = list(str(n)) q = len(p) for c in range(q): if t == 1: break for b in range(k): if p[c] == d[b]: r = 10 ** (q - c - 1) n = int(n / r + 1) * r t = 1 break if t == 0: break print(n)
false
5.555556
[ "- n = n + 1", "+ r = 10 ** (q - c - 1)", "+ n = int(n / r + 1) * r" ]
false
0.046281
0.043245
1.070211
[ "s013126239", "s746711703" ]
u877470159
p03634
python
s230376383
s886122592
1,606
559
81,312
72,276
Accepted
Accepted
65.19
n=int(eval(input())) G=[[] for i in range(n)] for i in range(n-1): a,b,c=[int(v)-1 for v in input().split()] c+=1 G[a].append((b,c)) G[b].append((a,c)) q,k=[int(v) for v in input().split()] k=k-1 stack=[k] dis=[-1]*n dis[k]=0 while stack!=[]: now=stack.pop() d=dis[now] for i in G[now]: if dis[i[0]]==-1: dis[i[0]]=d+i[1] stack.append(i[0]) for i in range(q): x,y=[int(v)-1 for v in input().split()] print((dis[x]+dis[y]))
import sys input=sys.stdin.readline n=int(eval(input())) G=[[] for i in range(n)] for i in range(n-1): a,b,c=[int(v)-1 for v in input().split()] c+=1 G[a].append((b,c)) G[b].append((a,c)) q,k=[int(v) for v in input().split()] k=k-1 stack=[k] dis=[-1]*n dis[k]=0 while stack!=[]: now=stack.pop() d=dis[now] for i in G[now]: if dis[i[0]]==-1: dis[i[0]]=d+i[1] stack.append(i[0]) for i in range(q): x,y=[int(v)-1 for v in input().split()] print((dis[x]+dis[y]))
23
25
506
544
n = int(eval(input())) G = [[] for i in range(n)] for i in range(n - 1): a, b, c = [int(v) - 1 for v in input().split()] c += 1 G[a].append((b, c)) G[b].append((a, c)) q, k = [int(v) for v in input().split()] k = k - 1 stack = [k] dis = [-1] * n dis[k] = 0 while stack != []: now = stack.pop() d = dis[now] for i in G[now]: if dis[i[0]] == -1: dis[i[0]] = d + i[1] stack.append(i[0]) for i in range(q): x, y = [int(v) - 1 for v in input().split()] print((dis[x] + dis[y]))
import sys input = sys.stdin.readline n = int(eval(input())) G = [[] for i in range(n)] for i in range(n - 1): a, b, c = [int(v) - 1 for v in input().split()] c += 1 G[a].append((b, c)) G[b].append((a, c)) q, k = [int(v) for v in input().split()] k = k - 1 stack = [k] dis = [-1] * n dis[k] = 0 while stack != []: now = stack.pop() d = dis[now] for i in G[now]: if dis[i[0]] == -1: dis[i[0]] = d + i[1] stack.append(i[0]) for i in range(q): x, y = [int(v) - 1 for v in input().split()] print((dis[x] + dis[y]))
false
8
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.036792
0.059868
0.61456
[ "s230376383", "s886122592" ]
u062691227
p04046
python
s240389758
s527216173
550
181
26,388
88,988
Accepted
Accepted
67.09
H, W, A, B = list(map(int, open(0).read().split())) MOD = 10**9+7 factorials = [1] * (H + W + 1) inv_factorials = [1] * (H + W + 1) for i in range(H + W): factorials[i+1] = factorials[i] * (i + 1) % MOD inv_factorials = list([pow(n, -1, MOD) for n in factorials]) def modcomb(m, n, mod): return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD total = modcomb(H + W - 2, W - 1, MOD) for i in range(B): total -= modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD total %= MOD print(total)
H, W, A, B = list(map(int, open(0).read().split())) MOD = 10**9+7 factorials = [1] * (H + W + 1) inv_factorials = [1] * (H + W + 1) for i in range(H + W): factorials[i+1] = factorials[i] * (i + 1) % MOD inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials]) def modcomb(m, n, mod): return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD # total = modcomb(H + W - 2, W - 1, MOD) total = 0 # for i in range(B): for i in range(B, W): total += modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD total %= MOD print(total)
21
23
584
627
H, W, A, B = list(map(int, open(0).read().split())) MOD = 10**9 + 7 factorials = [1] * (H + W + 1) inv_factorials = [1] * (H + W + 1) for i in range(H + W): factorials[i + 1] = factorials[i] * (i + 1) % MOD inv_factorials = list([pow(n, -1, MOD) for n in factorials]) def modcomb(m, n, mod): return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD total = modcomb(H + W - 2, W - 1, MOD) for i in range(B): total -= ( modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD ) total %= MOD print(total)
H, W, A, B = list(map(int, open(0).read().split())) MOD = 10**9 + 7 factorials = [1] * (H + W + 1) inv_factorials = [1] * (H + W + 1) for i in range(H + W): factorials[i + 1] = factorials[i] * (i + 1) % MOD inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials]) def modcomb(m, n, mod): return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD # total = modcomb(H + W - 2, W - 1, MOD) total = 0 # for i in range(B): for i in range(B, W): total += ( modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD ) total %= MOD print(total)
false
8.695652
[ "-inv_factorials = list([pow(n, -1, MOD) for n in factorials])", "+inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials])", "-total = modcomb(H + W - 2, W - 1, MOD)", "-for i in range(B):", "- total -= (", "+# total = modcomb(H + W - 2, W - 1, MOD)", "+total = 0", "+# for i in range(B):", "+for i in range(B, W):", "+ total += (" ]
false
0.061378
0.042261
1.452363
[ "s240389758", "s527216173" ]
u006493569
p03768
python
s116759145
s404694701
1,489
621
119,584
73,244
Accepted
Accepted
58.29
n, m = list(map(int, input().split())) g = [[i] for i in range(n)] for _ in range(m): u, v = [int(x) - 1 for x in input().split()] g[u].append(v) g[v].append(u) q = int(eval(input())) c = [None] * q dp = [[-1 for j in range(n)] for i in range(11)] for i in range(q): v, d, c[i] = list(map(int, input().split())) dp[d][v - 1] = i for i in reversed(list(range(1, 11))): dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)] for i in range(n): if dp[0][i] == -1: print('0') else: print((c[dp[0][i]]))
n, m = list(map(int, input().split())) g = [[i] for i in range(n)] for _ in range(m): u, v = [int(x) - 1 for x in input().split()] g[u].append(v) g[v].append(u) q = eval(input()) c = [None] * q dp = [[-1 for j in range(n)] for i in range(11)] for i in range(q): v, d, c[i] = list(map(int, input().split())) dp[d][v - 1] = i for i in reversed(list(range(1, 11))): dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)] for i in range(n): if dp[0][i] == -1: print('0') else: print((c[dp[0][i]]))
24
24
578
590
n, m = list(map(int, input().split())) g = [[i] for i in range(n)] for _ in range(m): u, v = [int(x) - 1 for x in input().split()] g[u].append(v) g[v].append(u) q = int(eval(input())) c = [None] * q dp = [[-1 for j in range(n)] for i in range(11)] for i in range(q): v, d, c[i] = list(map(int, input().split())) dp[d][v - 1] = i for i in reversed(list(range(1, 11))): dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)] for i in range(n): if dp[0][i] == -1: print("0") else: print((c[dp[0][i]]))
n, m = list(map(int, input().split())) g = [[i] for i in range(n)] for _ in range(m): u, v = [int(x) - 1 for x in input().split()] g[u].append(v) g[v].append(u) q = eval(input()) c = [None] * q dp = [[-1 for j in range(n)] for i in range(11)] for i in range(q): v, d, c[i] = list(map(int, input().split())) dp[d][v - 1] = i for i in reversed(list(range(1, 11))): dp[i - 1] = [max(dp[i - 1][u], max(dp[i][v] for v in g[u])) for u in range(n)] for i in range(n): if dp[0][i] == -1: print("0") else: print((c[dp[0][i]]))
false
0
[ "-q = int(eval(input()))", "+q = eval(input())" ]
false
0.188902
0.155641
1.213702
[ "s116759145", "s404694701" ]
u350909943
p03455
python
s655668186
s463391588
26
23
9,136
9,044
Accepted
Accepted
11.54
a,b = list(map(int,input().split())) num = a * b mod = num % 2 if mod == 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
114
84
a, b = list(map(int, input().split())) num = a * b mod = num % 2 if mod == 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
[ "-num = a * b", "-mod = num % 2", "-if mod == 0:", "+if a * b % 2 == 0:" ]
false
0.033587
0.033026
1.016992
[ "s655668186", "s463391588" ]
u788703383
p03557
python
s567649808
s107439518
418
321
24,264
23,092
Accepted
Accepted
23.21
import bisect n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) d = [-1] * n ansum = 0 def stat(array,par): return bisect.bisect(array,par) for i in range(n): indexC = stat(c,b[i]) d[i] = max(0,n-indexC) for i in range(n-1): d[n-i-2] += d[n-i-1] for A in a: index = stat(b,A) if index < n: ansum += d[index] print(ansum)
import bisect n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) ansum = 0 for B in b: index = bisect.bisect_left(a,B) index2= bisect.bisect_right(c,B) ansum += index*(n-index2) print(ansum)
20
11
470
308
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) d = [-1] * n ansum = 0 def stat(array, par): return bisect.bisect(array, par) for i in range(n): indexC = stat(c, b[i]) d[i] = max(0, n - indexC) for i in range(n - 1): d[n - i - 2] += d[n - i - 1] for A in a: index = stat(b, A) if index < n: ansum += d[index] print(ansum)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ansum = 0 for B in b: index = bisect.bisect_left(a, B) index2 = bisect.bisect_right(c, B) ansum += index * (n - index2) print(ansum)
false
45
[ "-d = [-1] * n", "-", "-", "-def stat(array, par):", "- return bisect.bisect(array, par)", "-", "-", "-for i in range(n):", "- indexC = stat(c, b[i])", "- d[i] = max(0, n - indexC)", "-for i in range(n - 1):", "- d[n - i - 2] += d[n - i - 1]", "-for A in a:", "- index = stat(b, A)", "- if index < n:", "- ansum += d[index]", "+for B in b:", "+ index = bisect.bisect_left(a, B)", "+ index2 = bisect.bisect_right(c, B)", "+ ansum += index * (n - index2)" ]
false
0.150776
0.042184
3.574284
[ "s567649808", "s107439518" ]
u899909022
p02924
python
s193570723
s686662428
34
17
5,076
2,940
Accepted
Accepted
50
from decimal import Decimal n = int(eval(input())) ans = int((n / Decimal(2)) * (n - 1)) print(ans)
n = int(eval(input())) ans = int(n * (n - 1) // 2) print(ans)
4
3
96
58
from decimal import Decimal n = int(eval(input())) ans = int((n / Decimal(2)) * (n - 1)) print(ans)
n = int(eval(input())) ans = int(n * (n - 1) // 2) print(ans)
false
25
[ "-from decimal import Decimal", "-", "-ans = int((n / Decimal(2)) * (n - 1))", "+ans = int(n * (n - 1) // 2)" ]
false
0.03798
0.060765
0.62503
[ "s193570723", "s686662428" ]
u809898133
p03722
python
s586680427
s790388379
1,272
896
3,316
3,316
Accepted
Accepted
29.56
n,m = list(map(int , input().split())) e = [] for i in range(m): a,b,c = list(map(int , input().split())) e.append((a-1,b-1,c)) maxdis = [-float('inf') for i in range(n)] maxdis[0] = 0 mugen = False for i in range(2*n): for j in e: st,gl,cost = j if (maxdis[gl] < maxdis[st]+cost): maxdis[gl] = maxdis[st]+cost if (i >= n-1 and (gl == n-1)): mugen = True break if mugen: print("inf") else: print((maxdis[n-1]))
n,m = list(map(int , input().split())) e = [] for i in range(m): a,b,c = list(map(int , input().split())) e.append((a-1,b-1,c)) maxdis = [-float('inf') for i in range(n)] maxdis[0] = 0 mugen = False for i in range(n): for j in e: st,gl,cost = j if (maxdis[gl] < maxdis[st]+cost): maxdis[gl] = maxdis[st]+cost if (i >= n-1 and (gl == n-1)): mugen = True break if mugen: print("inf") else: print((maxdis[n-1]))
26
26
522
520
n, m = list(map(int, input().split())) e = [] for i in range(m): a, b, c = list(map(int, input().split())) e.append((a - 1, b - 1, c)) maxdis = [-float("inf") for i in range(n)] maxdis[0] = 0 mugen = False for i in range(2 * n): for j in e: st, gl, cost = j if maxdis[gl] < maxdis[st] + cost: maxdis[gl] = maxdis[st] + cost if i >= n - 1 and (gl == n - 1): mugen = True break if mugen: print("inf") else: print((maxdis[n - 1]))
n, m = list(map(int, input().split())) e = [] for i in range(m): a, b, c = list(map(int, input().split())) e.append((a - 1, b - 1, c)) maxdis = [-float("inf") for i in range(n)] maxdis[0] = 0 mugen = False for i in range(n): for j in e: st, gl, cost = j if maxdis[gl] < maxdis[st] + cost: maxdis[gl] = maxdis[st] + cost if i >= n - 1 and (gl == n - 1): mugen = True break if mugen: print("inf") else: print((maxdis[n - 1]))
false
0
[ "-for i in range(2 * n):", "+for i in range(n):" ]
false
0.068871
0.114839
0.599716
[ "s586680427", "s790388379" ]
u823885866
p02891
python
s799008423
s082397347
148
17
12,500
3,064
Accepted
Accepted
88.51
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: list(map(str, sys.stdin.buffer.readline().split())) ri = lambda: int(sys.stdin.readline()) rm = lambda: list(map(int, sys.stdin.buffer.readline().split())) rl = lambda: list(map(int, sys.stdin.buffer.readline().split())) s = rr() k = ri() cnt = 0 i = 0 if len(set(s)) == 1: print((int(len(s)*k/2))) exit() while i < len(s)-1: if s[i] == s[i+1]: cnt += 1 i += 1 i += 1 cnt1 = 0 i1 = 0 s *= 2 while i1 < len(s)-1: if s[i1] == s[i1+1]: cnt1 += 1 i1 += 1 i1 += 1 print(((cnt1 - cnt)*(k-1) + cnt))
import sys rr = lambda: sys.stdin.readline().rstrip() ri = lambda: int(sys.stdin.readline()) s = rr() k = ri() cnt = 0 i = 0 if len(set(s)) == 1: print((int(len(s)*k/2))) exit() while i < len(s)-1: if s[i] == s[i+1]: cnt += 1 i += 1 i += 1 cnt1 = 0 i1 = 0 s *= 2 while i1 < len(s)-1: if s[i1] == s[i1+1]: cnt1 += 1 i1 += 1 i1 += 1 print(((cnt1 - cnt)*(k-1) + cnt))
36
27
700
418
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: list(map(str, sys.stdin.buffer.readline().split())) ri = lambda: int(sys.stdin.readline()) rm = lambda: list(map(int, sys.stdin.buffer.readline().split())) rl = lambda: list(map(int, sys.stdin.buffer.readline().split())) s = rr() k = ri() cnt = 0 i = 0 if len(set(s)) == 1: print((int(len(s) * k / 2))) exit() while i < len(s) - 1: if s[i] == s[i + 1]: cnt += 1 i += 1 i += 1 cnt1 = 0 i1 = 0 s *= 2 while i1 < len(s) - 1: if s[i1] == s[i1 + 1]: cnt1 += 1 i1 += 1 i1 += 1 print(((cnt1 - cnt) * (k - 1) + cnt))
import sys rr = lambda: sys.stdin.readline().rstrip() ri = lambda: int(sys.stdin.readline()) s = rr() k = ri() cnt = 0 i = 0 if len(set(s)) == 1: print((int(len(s) * k / 2))) exit() while i < len(s) - 1: if s[i] == s[i + 1]: cnt += 1 i += 1 i += 1 cnt1 = 0 i1 = 0 s *= 2 while i1 < len(s) - 1: if s[i1] == s[i1 + 1]: cnt1 += 1 i1 += 1 i1 += 1 print(((cnt1 - cnt) * (k - 1) + cnt))
false
25
[ "-import math", "-import itertools", "-import collections", "-import heapq", "-import re", "-import numpy as np", "-rs = lambda: list(map(str, sys.stdin.buffer.readline().split()))", "-rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))", "-rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))" ]
false
0.074625
0.053058
1.406494
[ "s799008423", "s082397347" ]
u279955105
p02399
python
s127722502
s450156507
40
20
7,660
7,676
Accepted
Accepted
50
a,b = list(map(int, input().split())) d = int(a / b) r = int(a % b) f = a / b print((str(d) + " " + str(r) + " " + str("{0:.10f}".format(f))))
a,b = list(map(int, input().split())) c = int(a / b) d = a % b e = a / b print((str(c) + " " + str(d) + " "+"{0:.8f}".format(e)))
5
6
144
133
a, b = list(map(int, input().split())) d = int(a / b) r = int(a % b) f = a / b print((str(d) + " " + str(r) + " " + str("{0:.10f}".format(f))))
a, b = list(map(int, input().split())) c = int(a / b) d = a % b e = a / b print((str(c) + " " + str(d) + " " + "{0:.8f}".format(e)))
false
16.666667
[ "-d = int(a / b)", "-r = int(a % b)", "-f = a / b", "-print((str(d) + \" \" + str(r) + \" \" + str(\"{0:.10f}\".format(f))))", "+c = int(a / b)", "+d = a % b", "+e = a / b", "+print((str(c) + \" \" + str(d) + \" \" + \"{0:.8f}\".format(e)))" ]
false
0.037258
0.042655
0.873472
[ "s127722502", "s450156507" ]
u970197315
p03476
python
s302163164
s689099503
1,145
164
4,980
81,600
Accepted
Accepted
85.68
def isPrime(x): for i in range(2,int(x**0.5)+1): if x%i==0: return False return True q=int(eval(input())) f=[1]*(10**5+1) f[0],f[1]=0,0 n=len(f) for i in range(2,n): if isPrime(i): for j in range(i*2,n,i): f[j]=0 c=[0]*(10**5+1) for i in range(2,10**5+1): if i%2==1: if f[i]==1 and f[(i+1)//2]==1: c[i]=c[i-1]+1 continue c[i]=c[i-1] else: c[i]=c[i-1] for i in range(q) : l,r=list(map(int,input().split())) print((c[r]-c[l-1]))
from itertools import accumulate import sys input = sys.stdin.buffer.readline def sieve(n): f = [] is_prime = [True]*(n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2, n+1, i): is_prime[j] = False for i in range(n+1): if is_prime[i]: f.append(i) return f s = sieve(10**5) s = set(s) number_2017 = [0]*(10**5+1) for i in range(1, 10**5+1): if i % 2 == 0: continue if i in s and (i+1)//2 in s: number_2017[i] = 1 acc = list(accumulate(number_2017)) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((acc[r]-acc[l-1]))
27
39
500
784
def isPrime(x): for i in range(2, int(x**0.5) + 1): if x % i == 0: return False return True q = int(eval(input())) f = [1] * (10**5 + 1) f[0], f[1] = 0, 0 n = len(f) for i in range(2, n): if isPrime(i): for j in range(i * 2, n, i): f[j] = 0 c = [0] * (10**5 + 1) for i in range(2, 10**5 + 1): if i % 2 == 1: if f[i] == 1 and f[(i + 1) // 2] == 1: c[i] = c[i - 1] + 1 continue c[i] = c[i - 1] else: c[i] = c[i - 1] for i in range(q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
from itertools import accumulate import sys input = sys.stdin.buffer.readline def sieve(n): f = [] is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False for i in range(n + 1): if is_prime[i]: f.append(i) return f s = sieve(10**5) s = set(s) number_2017 = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): if i % 2 == 0: continue if i in s and (i + 1) // 2 in s: number_2017[i] = 1 acc = list(accumulate(number_2017)) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((acc[r] - acc[l - 1]))
false
30.769231
[ "-def isPrime(x):", "- for i in range(2, int(x**0.5) + 1):", "- if x % i == 0:", "- return False", "- return True", "+from itertools import accumulate", "+import sys", "+", "+input = sys.stdin.buffer.readline", "-q = int(eval(input()))", "-f = [1] * (10**5 + 1)", "-f[0], f[1] = 0, 0", "-n = len(f)", "-for i in range(2, n):", "- if isPrime(i):", "- for j in range(i * 2, n, i):", "- f[j] = 0", "-c = [0] * (10**5 + 1)", "-for i in range(2, 10**5 + 1):", "- if i % 2 == 1:", "- if f[i] == 1 and f[(i + 1) // 2] == 1:", "- c[i] = c[i - 1] + 1", "+def sieve(n):", "+ f = []", "+ is_prime = [True] * (n + 1)", "+ is_prime[0] = False", "+ is_prime[1] = False", "+ for i in range(2, int(n**0.5) + 1):", "+ if not is_prime[i]:", "- c[i] = c[i - 1]", "- else:", "- c[i] = c[i - 1]", "-for i in range(q):", "+ for j in range(i * 2, n + 1, i):", "+ is_prime[j] = False", "+ for i in range(n + 1):", "+ if is_prime[i]:", "+ f.append(i)", "+ return f", "+", "+", "+s = sieve(10**5)", "+s = set(s)", "+number_2017 = [0] * (10**5 + 1)", "+for i in range(1, 10**5 + 1):", "+ if i % 2 == 0:", "+ continue", "+ if i in s and (i + 1) // 2 in s:", "+ number_2017[i] = 1", "+acc = list(accumulate(number_2017))", "+Q = int(eval(input()))", "+for _ in range(Q):", "- print((c[r] - c[l - 1]))", "+ print((acc[r] - acc[l - 1]))" ]
false
0.725763
0.091474
7.934052
[ "s302163164", "s689099503" ]
u445624660
p02780
python
s050849727
s683347790
274
227
24,804
24,804
Accepted
Accepted
17.15
# きりみんちゃんの配信をみてたので期待値は分かる # 素直にTLEくらったので累積和で加減する # え これでもだめなの # あほだった sumしてるし # 単純にみたら 0.5ずつ増えてるのでそうするか # 1WA... # N = 1の場合か? n, k = list(map(int, input().split())) arr = list(map(int, input().split())) table = {} ans = 0 for i in range(1, 1000 + 1): table[i] = (i + 1) * 0.5 if n == 1: print((table[arr[0]])) exit() lis = [0 for _ in range(n)] lis[0] = table[arr[0]] for i in range(n - 1): if i + 1 < k: lis[i + 1] = lis[i] + table[arr[i + 1]] else: lis[i + 1] = lis[i] + table[arr[i + 1]] - table[arr[i - k + 1]] ans = max(ans, lis[i + 1]) print(ans)
# 和の期待値は期待値の和 # それぞれ期待値を出したあとは大きさKの区間和の最大値 # n(n+1)/2 n, k = list(map(int, input().split())) p = [] for x in list(map(int, input().split())): p.append((x * (x + 1) // 2) / x) ans = 0 tmp = 0 for i in range(n): tmp += p[i] if i >= k: tmp -= p[i - k] ans = max(ans, tmp) print(ans)
27
17
613
315
# きりみんちゃんの配信をみてたので期待値は分かる # 素直にTLEくらったので累積和で加減する # え これでもだめなの # あほだった sumしてるし # 単純にみたら 0.5ずつ増えてるのでそうするか # 1WA... # N = 1の場合か? n, k = list(map(int, input().split())) arr = list(map(int, input().split())) table = {} ans = 0 for i in range(1, 1000 + 1): table[i] = (i + 1) * 0.5 if n == 1: print((table[arr[0]])) exit() lis = [0 for _ in range(n)] lis[0] = table[arr[0]] for i in range(n - 1): if i + 1 < k: lis[i + 1] = lis[i] + table[arr[i + 1]] else: lis[i + 1] = lis[i] + table[arr[i + 1]] - table[arr[i - k + 1]] ans = max(ans, lis[i + 1]) print(ans)
# 和の期待値は期待値の和 # それぞれ期待値を出したあとは大きさKの区間和の最大値 # n(n+1)/2 n, k = list(map(int, input().split())) p = [] for x in list(map(int, input().split())): p.append((x * (x + 1) // 2) / x) ans = 0 tmp = 0 for i in range(n): tmp += p[i] if i >= k: tmp -= p[i - k] ans = max(ans, tmp) print(ans)
false
37.037037
[ "-# きりみんちゃんの配信をみてたので期待値は分かる", "-# 素直にTLEくらったので累積和で加減する", "-# え これでもだめなの", "-# あほだった sumしてるし", "-# 単純にみたら 0.5ずつ増えてるのでそうするか", "-# 1WA...", "-# N = 1の場合か?", "+# 和の期待値は期待値の和", "+# それぞれ期待値を出したあとは大きさKの区間和の最大値", "+# n(n+1)/2", "-arr = list(map(int, input().split()))", "-table = {}", "+p = []", "+for x in list(map(int, input().split())):", "+ p.append((x * (x + 1) // 2) / x)", "-for i in range(1, 1000 + 1):", "- table[i] = (i + 1) * 0.5", "-if n == 1:", "- print((table[arr[0]]))", "- exit()", "-lis = [0 for _ in range(n)]", "-lis[0] = table[arr[0]]", "-for i in range(n - 1):", "- if i + 1 < k:", "- lis[i + 1] = lis[i] + table[arr[i + 1]]", "- else:", "- lis[i + 1] = lis[i] + table[arr[i + 1]] - table[arr[i - k + 1]]", "- ans = max(ans, lis[i + 1])", "+tmp = 0", "+for i in range(n):", "+ tmp += p[i]", "+ if i >= k:", "+ tmp -= p[i - k]", "+ ans = max(ans, tmp)" ]
false
0.082918
0.042897
1.932977
[ "s050849727", "s683347790" ]
u683956577
p03163
python
s019211366
s835681334
480
343
120,300
41,708
Accepted
Accepted
28.54
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, W = na() w = [] v = [] for i in range(n): x,y = list(map(int,input().split())) w.append(x) v.append(y) dp = [[0]*(W+1) for i in range(n+1)] for i in range(n): for j in range(W+1): if j < w[i]: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]) print((dp[n][W]))
import sys input = sys.stdin.readline n,w = list(map(int,input().split())) wv = [tuple(map(int,input().split())) for i in range(n)] dp = [0]*(w+1) for i in range(n): for j in range(w,wv[i][0]-1,-1): dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1]) print((max(dp)))
27
11
543
274
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, W = na() w = [] v = [] for i in range(n): x, y = list(map(int, input().split())) w.append(x) v.append(y) dp = [[0] * (W + 1) for i in range(n + 1)] for i in range(n): for j in range(W + 1): if j < w[i]: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]) print((dp[n][W]))
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) wv = [tuple(map(int, input().split())) for i in range(n)] dp = [0] * (w + 1) for i in range(n): for j in range(w, wv[i][0] - 1, -1): dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1]) print((max(dp)))
false
59.259259
[ "-stdin = sys.stdin", "-ni = lambda: int(ns())", "-na = lambda: list(map(int, stdin.readline().split()))", "-ns = lambda: stdin.readline().rstrip() # ignore trailing spaces", "-n, W = na()", "-w = []", "-v = []", "+input = sys.stdin.readline", "+n, w = list(map(int, input().split()))", "+wv = [tuple(map(int, input().split())) for i in range(n)]", "+dp = [0] * (w + 1)", "- x, y = list(map(int, input().split()))", "- w.append(x)", "- v.append(y)", "-dp = [[0] * (W + 1) for i in range(n + 1)]", "-for i in range(n):", "- for j in range(W + 1):", "- if j < w[i]:", "- dp[i + 1][j] = dp[i][j]", "- else:", "- dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])", "-print((dp[n][W]))", "+ for j in range(w, wv[i][0] - 1, -1):", "+ dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1])", "+print((max(dp)))" ]
false
0.040049
0.038872
1.030262
[ "s019211366", "s835681334" ]
u437351386
p02642
python
s535289321
s939597075
876
429
92,804
55,212
Accepted
Accepted
51.03
#エラストテネスのふるいを用いることを考える #出たものの倍数をいれるダメリストを準備しておく。 #各a[i]についてダメリストに入っていないものが求める個数である #同じものが複数回出てくるもの(Counterを使えばいい)に関してはダメリストにその数もいれれば良い from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) a.sort() min_a=a[0] max_a=a[n-1] #同じものが複数回出てくるもののcheck dic=Counter(a) #別リスト check=set() for i in range(n): if a[i] not in check: if dic[a[i]]>=2: check.add(a[i]) for j in range(2,int((max_a)/a[i])+1): check.add(a[i]*j) ans=0 for i in range(n): if a[i] not in check: ans=ans+1 print(ans)
n=int(eval(input())) a=list(map(int,input().split())) a.sort() k=max(a) num_list=set() prime_list=set() from collections import Counter dic=Counter(a) a=set(a) for i in dic: if dic[i]>=2: dic[i]=0 if i not in num_list: for j in range(i*2,k+1,i): if j in a: dic[j]=0 num_list.add(j) print((sum(dic.values())))
31
25
575
373
# エラストテネスのふるいを用いることを考える # 出たものの倍数をいれるダメリストを準備しておく。 # 各a[i]についてダメリストに入っていないものが求める個数である # 同じものが複数回出てくるもの(Counterを使えばいい)に関してはダメリストにその数もいれれば良い from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) a.sort() min_a = a[0] max_a = a[n - 1] # 同じものが複数回出てくるもののcheck dic = Counter(a) # 別リスト check = set() for i in range(n): if a[i] not in check: if dic[a[i]] >= 2: check.add(a[i]) for j in range(2, int((max_a) / a[i]) + 1): check.add(a[i] * j) ans = 0 for i in range(n): if a[i] not in check: ans = ans + 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) a.sort() k = max(a) num_list = set() prime_list = set() from collections import Counter dic = Counter(a) a = set(a) for i in dic: if dic[i] >= 2: dic[i] = 0 if i not in num_list: for j in range(i * 2, k + 1, i): if j in a: dic[j] = 0 num_list.add(j) print((sum(dic.values())))
false
19.354839
[ "-# エラストテネスのふるいを用いることを考える", "-# 出たものの倍数をいれるダメリストを準備しておく。", "-# 各a[i]についてダメリストに入っていないものが求める個数である", "-# 同じものが複数回出てくるもの(Counterを使えばいい)に関してはダメリストにその数もいれれば良い", "-from collections import Counter", "-", "-min_a = a[0]", "-max_a = a[n - 1]", "-# 同じものが複数回出てくるもののcheck", "+k = max(a)", "+num_list = set()", "+prime_list = set()", "+from collections import Counter", "+", "-# 別リスト", "-check = set()", "-for i in range(n):", "- if a[i] not in check:", "- if dic[a[i]] >= 2:", "- check.add(a[i])", "- for j in range(2, int((max_a) / a[i]) + 1):", "- check.add(a[i] * j)", "-ans = 0", "-for i in range(n):", "- if a[i] not in check:", "- ans = ans + 1", "-print(ans)", "+a = set(a)", "+for i in dic:", "+ if dic[i] >= 2:", "+ dic[i] = 0", "+ if i not in num_list:", "+ for j in range(i * 2, k + 1, i):", "+ if j in a:", "+ dic[j] = 0", "+ num_list.add(j)", "+print((sum(dic.values())))" ]
false
0.035425
0.058542
0.605119
[ "s535289321", "s939597075" ]
u627803856
p02623
python
s076990557
s165019156
190
146
111,300
118,304
Accepted
Accepted
23.16
n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) MAX = 10 ** 18 # 累積和 accA, accB = [0] * (n + 1), [0] * (m + 1) accA[1], accB[1] = A[0], B[0] for i in range(2, n + 1): accA[i] = accA[i - 1] + A[i - 1] for i in range(2, m + 1): accB[i] = accB[i - 1] + B[i - 1] accA.append(MAX) accB.append(MAX) from bisect import bisect_left, bisect_right res = 0 for i in range(n + 1): tmp = accA[i] idx = bisect_right(accB, k - tmp) - 1 if tmp + accB[idx] <= k: res = max(res, i + idx) print(res)
n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) t = sum(B) # しゃくとり法 res = 0 j = m for i in range(n + 1): while j > 0 and t > k: j -= 1 t -= B[j] if t > k: break res = max(res, i + j) if i == n: break t += A[i] print(res)
25
20
596
346
n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) MAX = 10**18 # 累積和 accA, accB = [0] * (n + 1), [0] * (m + 1) accA[1], accB[1] = A[0], B[0] for i in range(2, n + 1): accA[i] = accA[i - 1] + A[i - 1] for i in range(2, m + 1): accB[i] = accB[i - 1] + B[i - 1] accA.append(MAX) accB.append(MAX) from bisect import bisect_left, bisect_right res = 0 for i in range(n + 1): tmp = accA[i] idx = bisect_right(accB, k - tmp) - 1 if tmp + accB[idx] <= k: res = max(res, i + idx) print(res)
n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) t = sum(B) # しゃくとり法 res = 0 j = m for i in range(n + 1): while j > 0 and t > k: j -= 1 t -= B[j] if t > k: break res = max(res, i + j) if i == n: break t += A[i] print(res)
false
20
[ "-MAX = 10**18", "-# 累積和", "-accA, accB = [0] * (n + 1), [0] * (m + 1)", "-accA[1], accB[1] = A[0], B[0]", "-for i in range(2, n + 1):", "- accA[i] = accA[i - 1] + A[i - 1]", "-for i in range(2, m + 1):", "- accB[i] = accB[i - 1] + B[i - 1]", "-accA.append(MAX)", "-accB.append(MAX)", "-from bisect import bisect_left, bisect_right", "-", "+t = sum(B)", "+# しゃくとり法", "+j = m", "- tmp = accA[i]", "- idx = bisect_right(accB, k - tmp) - 1", "- if tmp + accB[idx] <= k:", "- res = max(res, i + idx)", "+ while j > 0 and t > k:", "+ j -= 1", "+ t -= B[j]", "+ if t > k:", "+ break", "+ res = max(res, i + j)", "+ if i == n:", "+ break", "+ t += A[i]" ]
false
0.044481
0.043298
1.027316
[ "s076990557", "s165019156" ]