user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u057964173
p02947
python
s167232316
s743928714
395
247
24,652
19,760
Accepted
Accepted
37.47
import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(eval(input())) s=[sorted(list(eval(input()))) for i in range(n)] s.sort() ans=0 cnt=1 for i in range(n-1): if s[i]==s[i+1]: cnt+=1 if i ==n-2: ans+=cnt*(cnt-1)//2 else: if cnt>=2: ans += cnt * (cnt - 1) // 2 cnt=1 print(ans) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(eval(input())) # 文字列を一文字ずつのリストにして、辞書順にソートしたあと、文字列に戻す # ['aab','aab','aab','ccd','ccd']ってなってる l=[''.join(sorted(list(eval(input())))) for i in range(n)] from collections import Counter c=Counter(l)# ()にカウンターの対象のリストの変数名 # print(c)するとCounter({'aab': 3, 'ccd': 2})ってなってる # print(c.values())すると[3,2] ans=0 for j in list(c.values()): ans+=(j*(j-1))//2 print(ans) resolve()
20
18
463
500
import sys def input(): return sys.stdin.readline().strip() def resolve(): n = int(eval(input())) s = [sorted(list(eval(input()))) for i in range(n)] s.sort() ans = 0 cnt = 1 for i in range(n - 1): if s[i] == s[i + 1]: cnt += 1 if i == n - 2: ans += cnt * (cnt - 1) // 2 else: if cnt >= 2: ans += cnt * (cnt - 1) // 2 cnt = 1 print(ans) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): n = int(eval(input())) # 文字列を一文字ずつのリストにして、辞書順にソートしたあと、文字列に戻す # ['aab','aab','aab','ccd','ccd']ってなってる l = ["".join(sorted(list(eval(input())))) for i in range(n)] from collections import Counter c = Counter(l) # ()にカウンターの対象のリストの変数名 # print(c)するとCounter({'aab': 3, 'ccd': 2})ってなってる # print(c.values())すると[3,2] ans = 0 for j in list(c.values()): ans += (j * (j - 1)) // 2 print(ans) resolve()
false
10
[ "- s = [sorted(list(eval(input()))) for i in range(n)]", "- s.sort()", "+ # 文字列を一文字ずつのリストにして、辞書順にソートしたあと、文字列に戻す", "+ # ['aab','aab','aab','ccd','ccd']ってなってる", "+ l = [\"\".join(sorted(list(eval(input())))) for i in range(n)]", "+ from collections import Counter", "+", "+ c = Counter(l) # ()にカウンターの対象のリストの変数名", "+ # print(c)するとCounter({'aab': 3, 'ccd': 2})ってなってる", "+ # print(c.values())すると[3,2]", "- cnt = 1", "- for i in range(n - 1):", "- if s[i] == s[i + 1]:", "- cnt += 1", "- if i == n - 2:", "- ans += cnt * (cnt - 1) // 2", "- else:", "- if cnt >= 2:", "- ans += cnt * (cnt - 1) // 2", "- cnt = 1", "+ for j in list(c.values()):", "+ ans += (j * (j - 1)) // 2" ]
false
0.104136
0.081343
1.280201
[ "s167232316", "s743928714" ]
u130900604
p02773
python
s516450154
s098612198
774
505
60,048
45,264
Accepted
Accepted
34.75
n=int(eval(input())) sl=[] for i in range(n): s=eval(input()) sl.append(s) import collections c=collections.Counter(sl) # print(c) d=(c.most_common()) e=[d[0][0]] tmp=d[0][1] for i,j in d: if tmp==j: e.append(i) else: break e=list(set(e)) e.sort() for i in e: print(i)
n,*s=list(map(str,open(0).read().split())) from collections import* c=Counter(s).most_common() maxm=c[0][1] ans=[] for i,j in c: if maxm==j: ans+=i, for b in sorted(ans): print(b)
24
10
324
191
n = int(eval(input())) sl = [] for i in range(n): s = eval(input()) sl.append(s) import collections c = collections.Counter(sl) # print(c) d = c.most_common() e = [d[0][0]] tmp = d[0][1] for i, j in d: if tmp == j: e.append(i) else: break e = list(set(e)) e.sort() for i in e: print(i)
n, *s = list(map(str, open(0).read().split())) from collections import * c = Counter(s).most_common() maxm = c[0][1] ans = [] for i, j in c: if maxm == j: ans += (i,) for b in sorted(ans): print(b)
false
58.333333
[ "-n = int(eval(input()))", "-sl = []", "-for i in range(n):", "- s = eval(input())", "- sl.append(s)", "-import collections", "+n, *s = list(map(str, open(0).read().split()))", "+from collections import *", "-c = collections.Counter(sl)", "-# print(c)", "-d = c.most_common()", "-e = [d[0][0]]", "-tmp = d[0][1]", "-for i, j in d:", "- if tmp == j:", "- e.append(i)", "- else:", "- break", "-e = list(set(e))", "-e.sort()", "-for i in e:", "- print(i)", "+c = Counter(s).most_common()", "+maxm = c[0][1]", "+ans = []", "+for i, j in c:", "+ if maxm == j:", "+ ans += (i,)", "+for b in sorted(ans):", "+ print(b)" ]
false
0.119926
0.066075
1.814993
[ "s516450154", "s098612198" ]
u531813438
p02801
python
s560562823
s150135592
19
17
2,940
2,940
Accepted
Accepted
10.53
C = str(eval(input())) alpha= 'abcdefghijklmnopqrstuvwxyz' print((alpha[alpha.index(C)+1]))
#アスキーコードから文字 chr() #文字からアスキーコード ord() print((chr(ord(eval(input()))+1)))
3
3
85
66
C = str(eval(input())) alpha = "abcdefghijklmnopqrstuvwxyz" print((alpha[alpha.index(C) + 1]))
# アスキーコードから文字 chr() # 文字からアスキーコード ord() print((chr(ord(eval(input())) + 1)))
false
0
[ "-C = str(eval(input()))", "-alpha = \"abcdefghijklmnopqrstuvwxyz\"", "-print((alpha[alpha.index(C) + 1]))", "+# アスキーコードから文字 chr()", "+# 文字からアスキーコード ord()", "+print((chr(ord(eval(input())) + 1)))" ]
false
0.162126
0.157034
1.032422
[ "s560562823", "s150135592" ]
u327466606
p02803
python
s194339254
s210834292
1,737
210
45,276
3,064
Accepted
Accepted
87.91
from itertools import count, combinations, product H,W = list(map(int,input().split())) grid = [[False]*(W+2) for _ in range(H+2)] for i in range(1,H+1): S = eval(input()) for j,v in zip(list(range(1,W+1)),S): grid[i][j] = v == '.' visited = [[0 if v else float('inf') for v in row] for row in grid] cnt = 1 def dist(p1,p2): global cnt q = [p1] visited[p1[0]][p1[1]] = cnt for d in count(): if not q: break nq = [] for x,y in q: if (x,y) == p2: cnt += 1 return d else: for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)): if visited[x+dx][y+dy] < cnt: visited[x+dx][y+dy] = cnt nq.append((x+dx,y+dy)) q = nq cnt += 1 return float('inf') emp = [(i,j) for i,j in product(list(range(H+2)),list(range(W+2))) if grid[i][j]] print((max(dist(*p) for p in combinations(emp,2))))
from itertools import count, combinations, product H,W = list(map(int,input().split())) grid = [[False]*(W+2) for _ in range(H+2)] for i in range(1,H+1): S = eval(input()) for j,v in zip(list(range(1,W+1)),S): grid[i][j] = v == '.' visited = [[0 if v else float('inf') for v in row] for row in grid] cnt = 1 res = 0 for i,j in product(list(range(H+2)),list(range(W+2))): if not grid[i][j]: continue q = [(i,j)] visited[i][j] = cnt for d in count(): if not q: break nq = [] for x,y in q: for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)): if visited[x+dx][y+dy] < cnt: visited[x+dx][y+dy] = cnt nq.append((x+dx,y+dy)) q = nq cnt += 1 res = max(d-1, res) print(res)
37
33
994
822
from itertools import count, combinations, product H, W = list(map(int, input().split())) grid = [[False] * (W + 2) for _ in range(H + 2)] for i in range(1, H + 1): S = eval(input()) for j, v in zip(list(range(1, W + 1)), S): grid[i][j] = v == "." visited = [[0 if v else float("inf") for v in row] for row in grid] cnt = 1 def dist(p1, p2): global cnt q = [p1] visited[p1[0]][p1[1]] = cnt for d in count(): if not q: break nq = [] for x, y in q: if (x, y) == p2: cnt += 1 return d else: for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): if visited[x + dx][y + dy] < cnt: visited[x + dx][y + dy] = cnt nq.append((x + dx, y + dy)) q = nq cnt += 1 return float("inf") emp = [(i, j) for i, j in product(list(range(H + 2)), list(range(W + 2))) if grid[i][j]] print((max(dist(*p) for p in combinations(emp, 2))))
from itertools import count, combinations, product H, W = list(map(int, input().split())) grid = [[False] * (W + 2) for _ in range(H + 2)] for i in range(1, H + 1): S = eval(input()) for j, v in zip(list(range(1, W + 1)), S): grid[i][j] = v == "." visited = [[0 if v else float("inf") for v in row] for row in grid] cnt = 1 res = 0 for i, j in product(list(range(H + 2)), list(range(W + 2))): if not grid[i][j]: continue q = [(i, j)] visited[i][j] = cnt for d in count(): if not q: break nq = [] for x, y in q: for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): if visited[x + dx][y + dy] < cnt: visited[x + dx][y + dy] = cnt nq.append((x + dx, y + dy)) q = nq cnt += 1 res = max(d - 1, res) print(res)
false
10.810811
[ "-", "-", "-def dist(p1, p2):", "- global cnt", "- q = [p1]", "- visited[p1[0]][p1[1]] = cnt", "+res = 0", "+for i, j in product(list(range(H + 2)), list(range(W + 2))):", "+ if not grid[i][j]:", "+ continue", "+ q = [(i, j)]", "+ visited[i][j] = cnt", "- if (x, y) == p2:", "- cnt += 1", "- return d", "- else:", "- for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):", "- if visited[x + dx][y + dy] < cnt:", "- visited[x + dx][y + dy] = cnt", "- nq.append((x + dx, y + dy))", "+ for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):", "+ if visited[x + dx][y + dy] < cnt:", "+ visited[x + dx][y + dy] = cnt", "+ nq.append((x + dx, y + dy))", "- return float(\"inf\")", "-", "-", "-emp = [(i, j) for i, j in product(list(range(H + 2)), list(range(W + 2))) if grid[i][j]]", "-print((max(dist(*p) for p in combinations(emp, 2))))", "+ res = max(d - 1, res)", "+print(res)" ]
false
0.083349
0.037242
2.238047
[ "s194339254", "s210834292" ]
u009961299
p02389
python
s596285632
s681117340
30
20
6,724
5,592
Accepted
Accepted
33.33
[ a, b ] = list(map ( int, input ( ).split ( ) )) print(( "%s %s" % ( a * b, 2 * ( a + b ) ) ))
x = input().split() a, b = int(x[0]), int(x[1]) print(("%d %d" % (a * b, 2 * (a + b))))
2
5
89
92
[a, b] = list(map(int, input().split())) print(("%s %s" % (a * b, 2 * (a + b))))
x = input().split() a, b = int(x[0]), int(x[1]) print(("%d %d" % (a * b, 2 * (a + b))))
false
60
[ "-[a, b] = list(map(int, input().split()))", "-print((\"%s %s\" % (a * b, 2 * (a + b))))", "+x = input().split()", "+a, b = int(x[0]), int(x[1])", "+print((\"%d %d\" % (a * b, 2 * (a + b))))" ]
false
0.048781
0.048369
1.008521
[ "s596285632", "s681117340" ]
u197615397
p02346
python
s172642505
s527575795
2,400
680
18,596
10,740
Accepted
Accepted
71.67
import math class SegmentTree: __slots__ = ["elem_size", "tree_size", "tree"] def __init__(self, a: list, default: int): real_size = len(a) self.elem_size = 1 << math.ceil(math.log2(real_size)) self.tree_size = 2 * self.elem_size + 1 self.tree = [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) def get_range_index(self, x, y, k=0, l_end=0, r_end=None): '''[x, y], tree[k], [l_end, r_end)''' default, tree = 0, self.tree if r_end is None: r_end = self.elem_size if l_end == x and y == r_end-1: return tree[k] mid = (l_end + r_end) // 2 left_y = y if y < mid-1 else mid-1 right_x = x if x > mid else mid left = self.get_range_index(x, left_y, 2*k+1, l_end, mid) if x <= left_y else default right = self.get_range_index(right_x, y, 2*k+2, mid, r_end) if right_x <= y else default return left + right def get_value(self, x, y): tree = self.tree return self.get_range_index(x, y) # return sum(tree[n] for n in index_list) def update_tree(self, k: int): tree = self.tree while k > 0: k = (k-1) // 2 left, right = tree[2*k+1], tree[2*k+2] tree[k] = left + right def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0]*n, 0) ans = [] for _ in [0]*q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x-1, y, "+") else: ans.append(rsq.get_value(x-1, y-1)) print(("\n".join([str(n) for n in ans])))
import sys class BinaryIndexedTree(object): __slots__ = ["tree"] def __init__(self, size: int): self.tree = [0]*(size+1) def add(self, index: int, value: int) -> None: tree = self.tree next_index = index + 1 while next_index < len(tree): tree[next_index] += value next_index += next_index & -next_index def sum(self, index: int): tree, result = self.tree, 0 next_index = index + 1 while next_index: result += tree[next_index] next_index -= next_index & -next_index return result if __name__ == "__main__": n, q = map(int, input().split()) bit = BinaryIndexedTree(n) result = [] for com, x, y in (map(int, l.split()) for l in sys.stdin): if not com: bit.add(x-1, y) else: result.append(bit.sum(y-1) - bit.sum(x-2)) print(*result, sep="\n")
62
39
1,893
976
import math class SegmentTree: __slots__ = ["elem_size", "tree_size", "tree"] def __init__(self, a: list, default: int): real_size = len(a) self.elem_size = 1 << math.ceil(math.log2(real_size)) self.tree_size = 2 * self.elem_size + 1 self.tree = ( [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) ) def get_range_index(self, x, y, k=0, l_end=0, r_end=None): """[x, y], tree[k], [l_end, r_end)""" default, tree = 0, self.tree if r_end is None: r_end = self.elem_size if l_end == x and y == r_end - 1: return tree[k] mid = (l_end + r_end) // 2 left_y = y if y < mid - 1 else mid - 1 right_x = x if x > mid else mid left = ( self.get_range_index(x, left_y, 2 * k + 1, l_end, mid) if x <= left_y else default ) right = ( self.get_range_index(right_x, y, 2 * k + 2, mid, r_end) if right_x <= y else default ) return left + right def get_value(self, x, y): tree = self.tree return self.get_range_index(x, y) # return sum(tree[n] for n in index_list) def update_tree(self, k: int): tree = self.tree while k > 0: k = (k - 1) // 2 left, right = tree[2 * k + 1], tree[2 * k + 2] tree[k] = left + right def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0] * n, 0) ans = [] for _ in [0] * q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x - 1, y, "+") else: ans.append(rsq.get_value(x - 1, y - 1)) print(("\n".join([str(n) for n in ans])))
import sys class BinaryIndexedTree(object): __slots__ = ["tree"] def __init__(self, size: int): self.tree = [0] * (size + 1) def add(self, index: int, value: int) -> None: tree = self.tree next_index = index + 1 while next_index < len(tree): tree[next_index] += value next_index += next_index & -next_index def sum(self, index: int): tree, result = self.tree, 0 next_index = index + 1 while next_index: result += tree[next_index] next_index -= next_index & -next_index return result if __name__ == "__main__": n, q = map(int, input().split()) bit = BinaryIndexedTree(n) result = [] for com, x, y in (map(int, l.split()) for l in sys.stdin): if not com: bit.add(x - 1, y) else: result.append(bit.sum(y - 1) - bit.sum(x - 2)) print(*result, sep="\n")
false
37.096774
[ "-import math", "+import sys", "-class SegmentTree:", "- __slots__ = [\"elem_size\", \"tree_size\", \"tree\"]", "+class BinaryIndexedTree(object):", "+ __slots__ = [\"tree\"]", "- def __init__(self, a: list, default: int):", "- real_size = len(a)", "- self.elem_size = 1 << math.ceil(math.log2(real_size))", "- self.tree_size = 2 * self.elem_size + 1", "- self.tree = (", "- [default] * (self.elem_size - 1)", "- + a", "- + [default] * (self.elem_size - real_size)", "- )", "+ def __init__(self, size: int):", "+ self.tree = [0] * (size + 1)", "- def get_range_index(self, x, y, k=0, l_end=0, r_end=None):", "- \"\"\"[x, y], tree[k], [l_end, r_end)\"\"\"", "- default, tree = 0, self.tree", "- if r_end is None:", "- r_end = self.elem_size", "- if l_end == x and y == r_end - 1:", "- return tree[k]", "- mid = (l_end + r_end) // 2", "- left_y = y if y < mid - 1 else mid - 1", "- right_x = x if x > mid else mid", "- left = (", "- self.get_range_index(x, left_y, 2 * k + 1, l_end, mid)", "- if x <= left_y", "- else default", "- )", "- right = (", "- self.get_range_index(right_x, y, 2 * k + 2, mid, r_end)", "- if right_x <= y", "- else default", "- )", "- return left + right", "+ def add(self, index: int, value: int) -> None:", "+ tree = self.tree", "+ next_index = index + 1", "+ while next_index < len(tree):", "+ tree[next_index] += value", "+ next_index += next_index & -next_index", "- def get_value(self, x, y):", "- tree = self.tree", "- return self.get_range_index(x, y)", "- # return sum(tree[n] for n in index_list)", "-", "- def update_tree(self, k: int):", "- tree = self.tree", "- while k > 0:", "- k = (k - 1) // 2", "- left, right = tree[2 * k + 1], tree[2 * k + 2]", "- tree[k] = left + right", "-", "- def set_value(self, i: int, value: int, op: str):", "- k = self.elem_size - 1 + i", "- if op == \"=\":", "- self.tree[k] = value", "- elif op == \"+\":", "- self.tree[k] += value", "- self.update_tree(k)", "+ def sum(self, index: int):", "+ tree, result = self.tree, 0", "+ next_index = index + 1", "+ while next_index:", "+ result += tree[next_index]", "+ next_index -= next_index & -next_index", "+ return result", "-n, q = list(map(int, input().split()))", "-rsq = SegmentTree([0] * n, 0)", "-ans = []", "-for _ in [0] * q:", "- c, x, y = list(map(int, input().split()))", "- if c == 0:", "- rsq.set_value(x - 1, y, \"+\")", "- else:", "- ans.append(rsq.get_value(x - 1, y - 1))", "-print((\"\\n\".join([str(n) for n in ans])))", "+if __name__ == \"__main__\":", "+ n, q = map(int, input().split())", "+ bit = BinaryIndexedTree(n)", "+ result = []", "+ for com, x, y in (map(int, l.split()) for l in sys.stdin):", "+ if not com:", "+ bit.add(x - 1, y)", "+ else:", "+ result.append(bit.sum(y - 1) - bit.sum(x - 2))", "+ print(*result, sep=\"\\n\")" ]
false
0.05673
0.036516
1.553535
[ "s172642505", "s527575795" ]
u368796742
p03338
python
s715524163
s464614275
20
18
2,940
2,940
Accepted
Accepted
10
n = int(eval(input())) l = list(eval(input())) ans = 0 for i in range(n): l1 = l[i+1:] count = set() for j in range(i+1): if l[j] in l1: count.add(l[j]) ans = max(ans,len(count)) print(ans)
n = int(eval(input())) l = list(eval(input())) ans = 0 for i in range(n): count = len(set(l[:i])&set(l[i:])) ans = max(count,ans) print(ans)
13
7
214
142
n = int(eval(input())) l = list(eval(input())) ans = 0 for i in range(n): l1 = l[i + 1 :] count = set() for j in range(i + 1): if l[j] in l1: count.add(l[j]) ans = max(ans, len(count)) print(ans)
n = int(eval(input())) l = list(eval(input())) ans = 0 for i in range(n): count = len(set(l[:i]) & set(l[i:])) ans = max(count, ans) print(ans)
false
46.153846
[ "- l1 = l[i + 1 :]", "- count = set()", "- for j in range(i + 1):", "- if l[j] in l1:", "- count.add(l[j])", "- ans = max(ans, len(count))", "+ count = len(set(l[:i]) & set(l[i:]))", "+ ans = max(count, ans)" ]
false
0.037558
0.03976
0.944607
[ "s715524163", "s464614275" ]
u197615397
p02361
python
s482488498
s271729415
2,490
1,790
97,980
98,040
Accepted
Accepted
28.11
from heapq import heappush, heappop V, E, r = list(map(int, input().split())) inf = 10**10 edges = [[] for _ in [None]*V] vertices = [inf]*V vertices[r] = 0 for _ in [None]*E: s, t, d = list(map(int, input().split())) edges[s].append((t, d)) q = [(0, r)] rem = V-1 while q: cost, v = heappop(q) if vertices[v] < cost: continue for dest, _cost in edges[v]: newcost = cost + _cost if vertices[dest] > newcost: vertices[dest] = newcost heappush(q, (newcost, dest)) rem -= 1 if rem == 0: break print(("\n".join([str(n) if n!=inf else "INF" for n in vertices])))
import sys from heapq import heappush, heappop readline = sys.stdin.readline V, E, r = list(map(int, readline().split())) inf = 10**10 edges = [[] for _ in [None]*V] vertices = [inf]*V vertices[r] = 0 for _ in [None]*E: s, t, d = list(map(int, readline().split())) edges[s].append((t, d)) q = [(0, r)] rem = V-1 while q and rem: cost, v = heappop(q) if vertices[v] < cost: continue rem -= 1 for dest, _cost in edges[v]: newcost = cost + _cost if vertices[dest] > newcost: vertices[dest] = newcost heappush(q, (newcost, dest)) print(("\n".join([str(n) if n!=inf else "INF" for n in vertices])))
27
27
656
680
from heapq import heappush, heappop V, E, r = list(map(int, input().split())) inf = 10**10 edges = [[] for _ in [None] * V] vertices = [inf] * V vertices[r] = 0 for _ in [None] * E: s, t, d = list(map(int, input().split())) edges[s].append((t, d)) q = [(0, r)] rem = V - 1 while q: cost, v = heappop(q) if vertices[v] < cost: continue for dest, _cost in edges[v]: newcost = cost + _cost if vertices[dest] > newcost: vertices[dest] = newcost heappush(q, (newcost, dest)) rem -= 1 if rem == 0: break print(("\n".join([str(n) if n != inf else "INF" for n in vertices])))
import sys from heapq import heappush, heappop readline = sys.stdin.readline V, E, r = list(map(int, readline().split())) inf = 10**10 edges = [[] for _ in [None] * V] vertices = [inf] * V vertices[r] = 0 for _ in [None] * E: s, t, d = list(map(int, readline().split())) edges[s].append((t, d)) q = [(0, r)] rem = V - 1 while q and rem: cost, v = heappop(q) if vertices[v] < cost: continue rem -= 1 for dest, _cost in edges[v]: newcost = cost + _cost if vertices[dest] > newcost: vertices[dest] = newcost heappush(q, (newcost, dest)) print(("\n".join([str(n) if n != inf else "INF" for n in vertices])))
false
0
[ "+import sys", "-V, E, r = list(map(int, input().split()))", "+readline = sys.stdin.readline", "+V, E, r = list(map(int, readline().split()))", "- s, t, d = list(map(int, input().split()))", "+ s, t, d = list(map(int, readline().split()))", "-while q:", "+while q and rem:", "+ rem -= 1", "- rem -= 1", "- if rem == 0:", "- break" ]
false
0.03722
0.047518
0.783285
[ "s482488498", "s271729415" ]
u888092736
p04045
python
s045645659
s271523429
91
71
9,132
9,168
Accepted
Accepted
21.98
N, K = list(map(int, input().split())) D = {i for i in range(10)} - set(map(int, input().split())) for i in range(N, 100000): if all(j in D for j in map(int, str(i))): print(i) break
N, K, *D = list(map(int, open(0).read().split())) D = set(str(d) for d in D) for i in range(N, 100_000): if set(str(i)) & D: continue print(i) break
6
7
202
169
N, K = list(map(int, input().split())) D = {i for i in range(10)} - set(map(int, input().split())) for i in range(N, 100000): if all(j in D for j in map(int, str(i))): print(i) break
N, K, *D = list(map(int, open(0).read().split())) D = set(str(d) for d in D) for i in range(N, 100_000): if set(str(i)) & D: continue print(i) break
false
14.285714
[ "-N, K = list(map(int, input().split()))", "-D = {i for i in range(10)} - set(map(int, input().split()))", "-for i in range(N, 100000):", "- if all(j in D for j in map(int, str(i))):", "- print(i)", "- break", "+N, K, *D = list(map(int, open(0).read().split()))", "+D = set(str(d) for d in D)", "+for i in range(N, 100_000):", "+ if set(str(i)) & D:", "+ continue", "+ print(i)", "+ break" ]
false
0.044339
0.119403
0.371336
[ "s045645659", "s271523429" ]
u254871849
p03659
python
s077318846
s056132720
233
138
24,680
24,064
Accepted
Accepted
40.77
import sys input = sys.stdin.readline n = int(eval(input())) a = [int(a) for a in input().split()] s = [None] * n; s[0] = a[0] for i in range(n-1): s[i+1] = s[i] + a[i+1] mixi = abs(s[0] - (s[n-1] - s[0])) for i in range(1, n-1): mixi = min(mixi, abs(s[i] - (s[n-1] - s[i]))) # 全部取るのはダメ print(mixi)
import sys n, *a = list(map(int, sys.stdin.read().split())) def main(): x = 0 y = sum(a) res = [] for i in range(n-1): x += a[i] y -= a[i] res.append(abs(x - y)) return min(res) if __name__ == '__main__': ans = main() print(ans)
12
18
308
295
import sys input = sys.stdin.readline n = int(eval(input())) a = [int(a) for a in input().split()] s = [None] * n s[0] = a[0] for i in range(n - 1): s[i + 1] = s[i] + a[i + 1] mixi = abs(s[0] - (s[n - 1] - s[0])) for i in range(1, n - 1): mixi = min(mixi, abs(s[i] - (s[n - 1] - s[i]))) # 全部取るのはダメ print(mixi)
import sys n, *a = list(map(int, sys.stdin.read().split())) def main(): x = 0 y = sum(a) res = [] for i in range(n - 1): x += a[i] y -= a[i] res.append(abs(x - y)) return min(res) if __name__ == "__main__": ans = main() print(ans)
false
33.333333
[ "-input = sys.stdin.readline", "-n = int(eval(input()))", "-a = [int(a) for a in input().split()]", "-s = [None] * n", "-s[0] = a[0]", "-for i in range(n - 1):", "- s[i + 1] = s[i] + a[i + 1]", "-mixi = abs(s[0] - (s[n - 1] - s[0]))", "-for i in range(1, n - 1):", "- mixi = min(mixi, abs(s[i] - (s[n - 1] - s[i]))) # 全部取るのはダメ", "-print(mixi)", "+n, *a = list(map(int, sys.stdin.read().split()))", "+", "+", "+def main():", "+ x = 0", "+ y = sum(a)", "+ res = []", "+ for i in range(n - 1):", "+ x += a[i]", "+ y -= a[i]", "+ res.append(abs(x - y))", "+ return min(res)", "+", "+", "+if __name__ == \"__main__\":", "+ ans = main()", "+ print(ans)" ]
false
0.055806
0.055651
1.002784
[ "s077318846", "s056132720" ]
u329565519
p03599
python
s496471853
s802222231
104
64
3,828
3,188
Accepted
Accepted
38.46
A, B, C, D, E, F = list(map(int, input().split())) W = set() for a in range(0, F+1, 100*A): for b in range(0, F+1, 100*B): W.add(a+b) S = set() for c in range(0, F+1, C): for d in range(0, F+1, D): S.add(c+d) rate = -1 for w in W: for s in S: if 0 < w + s <= F and s * 100 <= E * w: if s / (s + w) > rate: rate = s / (s + w) ans = w + s, s print((ans[0], ans[1]))
A, B, C, D, E, F = list(map(int, input().split())) ws = set() ss = set() for a in range(0, F+1, A*100): for b in range(0, F+1-a, B*100): ws.add(a + b) for c in range(0, F+1, C): for d in range(0, F+1-c, D): ss.add(c + d) mx = -1 ans = 0, 0 for w in ws: if w == 0: continue for s in ss: x = s * 100 / w if w + s <= F and x <= E and mx < x: mx = x ans = s + w, s print((*ans))
18
24
453
474
A, B, C, D, E, F = list(map(int, input().split())) W = set() for a in range(0, F + 1, 100 * A): for b in range(0, F + 1, 100 * B): W.add(a + b) S = set() for c in range(0, F + 1, C): for d in range(0, F + 1, D): S.add(c + d) rate = -1 for w in W: for s in S: if 0 < w + s <= F and s * 100 <= E * w: if s / (s + w) > rate: rate = s / (s + w) ans = w + s, s print((ans[0], ans[1]))
A, B, C, D, E, F = list(map(int, input().split())) ws = set() ss = set() for a in range(0, F + 1, A * 100): for b in range(0, F + 1 - a, B * 100): ws.add(a + b) for c in range(0, F + 1, C): for d in range(0, F + 1 - c, D): ss.add(c + d) mx = -1 ans = 0, 0 for w in ws: if w == 0: continue for s in ss: x = s * 100 / w if w + s <= F and x <= E and mx < x: mx = x ans = s + w, s print((*ans))
false
25
[ "-W = set()", "-for a in range(0, F + 1, 100 * A):", "- for b in range(0, F + 1, 100 * B):", "- W.add(a + b)", "-S = set()", "+ws = set()", "+ss = set()", "+for a in range(0, F + 1, A * 100):", "+ for b in range(0, F + 1 - a, B * 100):", "+ ws.add(a + b)", "- for d in range(0, F + 1, D):", "- S.add(c + d)", "-rate = -1", "-for w in W:", "- for s in S:", "- if 0 < w + s <= F and s * 100 <= E * w:", "- if s / (s + w) > rate:", "- rate = s / (s + w)", "- ans = w + s, s", "-print((ans[0], ans[1]))", "+ for d in range(0, F + 1 - c, D):", "+ ss.add(c + d)", "+mx = -1", "+ans = 0, 0", "+for w in ws:", "+ if w == 0:", "+ continue", "+ for s in ss:", "+ x = s * 100 / w", "+ if w + s <= F and x <= E and mx < x:", "+ mx = x", "+ ans = s + w, s", "+print((*ans))" ]
false
0.088479
0.157028
0.563465
[ "s496471853", "s802222231" ]
u854931881
p02552
python
s095965172
s892730512
34
25
9,144
9,100
Accepted
Accepted
26.47
x=int(eval(input())) if x==1: print("0") elif x==0: print("1")
x=int(eval(input())) if x==1: print((0)) else: print((1))
5
5
64
59
x = int(eval(input())) if x == 1: print("0") elif x == 0: print("1")
x = int(eval(input())) if x == 1: print((0)) else: print((1))
false
0
[ "- print(\"0\")", "-elif x == 0:", "- print(\"1\")", "+ print((0))", "+else:", "+ print((1))" ]
false
0.043981
0.043107
1.020272
[ "s095965172", "s892730512" ]
u133936772
p02641
python
s845401208
s612323173
24
22
9,176
9,168
Accepted
Accepted
8.33
x,n,*p=list(map(int,open(0).read().split())) p=set(p) l=r=x while 1: if l not in p: print(l); break l-=1 if r not in p: print(r); break r+=1
x,n,*p=list(map(int,open(0).read().split())) l=r=x while 1: if l not in p: print(l); break l-=1 if r not in p: print(r); break r+=1
8
7
149
139
x, n, *p = list(map(int, open(0).read().split())) p = set(p) l = r = x while 1: if l not in p: print(l) break l -= 1 if r not in p: print(r) break r += 1
x, n, *p = list(map(int, open(0).read().split())) l = r = x while 1: if l not in p: print(l) break l -= 1 if r not in p: print(r) break r += 1
false
12.5
[ "-p = set(p)" ]
false
0.03578
0.036811
0.971988
[ "s845401208", "s612323173" ]
u225388820
p03171
python
s351396304
s378104162
301
263
77,148
41,580
Accepted
Accepted
12.62
# dp[j][i]=(区間[i,j]が残っているとき次の手番の得点-そうじゃない人の得点) import sys sys.setrecursionlimit(1000000000) input = sys.stdin.readline n=int(eval(input())) a=list(map(int,input().split())) INF=-10**14 dp=[[0]*(i+1) for i in range(n)] for i in range(n): dp[i][i]=a[i] for i in range(1,n): for j in range(i-1,-1,-1): dp[i][j]=max(a[i]-dp[i-1][j],a[j]-dp[i][j+1]) print((dp[-1][0]))
import sys input = sys.stdin.readline n=int(eval(input())) a=list(map(int,input().split())) dp=[0]*3000 for i in range(n): dp[i]=a[i] for i in range(1,n): for j in range(i-1,-1,-1): dp[j]=max(a[i]-dp[j],a[j]-dp[j+1]) print((dp[0]))
14
11
384
249
# dp[j][i]=(区間[i,j]が残っているとき次の手番の得点-そうじゃない人の得点) import sys sys.setrecursionlimit(1000000000) input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) INF = -(10**14) dp = [[0] * (i + 1) for i in range(n)] for i in range(n): dp[i][i] = a[i] for i in range(1, n): for j in range(i - 1, -1, -1): dp[i][j] = max(a[i] - dp[i - 1][j], a[j] - dp[i][j + 1]) print((dp[-1][0]))
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) dp = [0] * 3000 for i in range(n): dp[i] = a[i] for i in range(1, n): for j in range(i - 1, -1, -1): dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1]) print((dp[0]))
false
21.428571
[ "-# dp[j][i]=(区間[i,j]が残っているとき次の手番の得点-そうじゃない人の得点)", "-sys.setrecursionlimit(1000000000)", "-INF = -(10**14)", "-dp = [[0] * (i + 1) for i in range(n)]", "+dp = [0] * 3000", "- dp[i][i] = a[i]", "+ dp[i] = a[i]", "- dp[i][j] = max(a[i] - dp[i - 1][j], a[j] - dp[i][j + 1])", "-print((dp[-1][0]))", "+ dp[j] = max(a[i] - dp[j], a[j] - dp[j + 1])", "+print((dp[0]))" ]
false
0.122247
0.052376
2.334021
[ "s351396304", "s378104162" ]
u867826040
p02574
python
s992508474
s459090715
1,954
647
127,980
127,764
Accepted
Accepted
66.89
from functools import reduce from math import gcd, sqrt,ceil n = int(eval(input())) a = list(map(int,input().split())) m = 10**6 a_gcd = reduce(gcd,a) if a_gcd != 1: print("not coprime") exit(0) isset = a_gcd == 1 hurui = [i for i in range(m+1)] for i in range(2,ceil(sqrt(m))+1): for j in range(2,ceil(sqrt(i))+1): if i==2: continue if i%j == 0: break else: for k in range(i+i,m,i): if hurui[k] != k: continue hurui[k] = i continue s = set() p_f = True for ai in a: t = set() while(ai > 1): t.add(hurui[ai]) ai //= hurui[ai] for ti in t: if ti in s: p_f = False else: s.add(ti) if p_f: print("pairwise coprime") elif isset: print("setwise coprime")
from functools import reduce from math import gcd, sqrt,ceil n = int(eval(input())) a = list(map(int,input().split())) m = 10**6 a_gcd = reduce(gcd,a) if a_gcd != 1: print("not coprime") exit(0) isset = a_gcd == 1 hurui = [i for i in range(m+1)] for i in range(2,ceil(sqrt(m))+1): for j in range(2,ceil(sqrt(i))+1): if i==2: continue if i%j == 0: break else: for k in range(i+i,m,i): if hurui[k] != k: continue hurui[k] = i continue s = set() p_f = True for ai in a: t = set() while(ai > 1): t.add(hurui[ai]) ai //= hurui[ai] for ti in t: if ti in s: print("setwise coprime") exit(0) else: s.add(ti) print("pairwise coprime")
43
41
873
851
from functools import reduce from math import gcd, sqrt, ceil n = int(eval(input())) a = list(map(int, input().split())) m = 10**6 a_gcd = reduce(gcd, a) if a_gcd != 1: print("not coprime") exit(0) isset = a_gcd == 1 hurui = [i for i in range(m + 1)] for i in range(2, ceil(sqrt(m)) + 1): for j in range(2, ceil(sqrt(i)) + 1): if i == 2: continue if i % j == 0: break else: for k in range(i + i, m, i): if hurui[k] != k: continue hurui[k] = i continue s = set() p_f = True for ai in a: t = set() while ai > 1: t.add(hurui[ai]) ai //= hurui[ai] for ti in t: if ti in s: p_f = False else: s.add(ti) if p_f: print("pairwise coprime") elif isset: print("setwise coprime")
from functools import reduce from math import gcd, sqrt, ceil n = int(eval(input())) a = list(map(int, input().split())) m = 10**6 a_gcd = reduce(gcd, a) if a_gcd != 1: print("not coprime") exit(0) isset = a_gcd == 1 hurui = [i for i in range(m + 1)] for i in range(2, ceil(sqrt(m)) + 1): for j in range(2, ceil(sqrt(i)) + 1): if i == 2: continue if i % j == 0: break else: for k in range(i + i, m, i): if hurui[k] != k: continue hurui[k] = i continue s = set() p_f = True for ai in a: t = set() while ai > 1: t.add(hurui[ai]) ai //= hurui[ai] for ti in t: if ti in s: print("setwise coprime") exit(0) else: s.add(ti) print("pairwise coprime")
false
4.651163
[ "- p_f = False", "+ print(\"setwise coprime\")", "+ exit(0)", "-if p_f:", "- print(\"pairwise coprime\")", "-elif isset:", "- print(\"setwise coprime\")", "+print(\"pairwise coprime\")" ]
false
0.677842
1.041106
0.651079
[ "s992508474", "s459090715" ]
u392319141
p02716
python
s068987473
s478783629
272
152
50,652
31,684
Accepted
Accepted
44.12
N = int(eval(input())) A = list(map(int, input().split())) INF = 10**18 dp0 = [-INF] * (N + 2) dp1 = [-INF] * (N + 2) dp2 = [-INF] * (N + 2) dp0[0] = 0 dp0[1] = 0 dp1[0] = 0 dp1[1] = 0 for i, a in enumerate(A, start=2): dp0[i] = dp0[i - 2] + a dp1[i] = max(dp1[i - 2] + a, dp0[i - 1]) dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2]) if N % 2 == 1: print((dp2[-1])) else: print((max(dp1[-1], dp0[-1])))
N = int(eval(input())) A = list(map(int, input().split())) INF = 10**18 dp0 = 0 dp1 = -INF dp2 = -INF for i, a in enumerate(A): if i % 2 == 0: dp1 = max(dp1, dp0) dp0 += a dp2 += a else: dp2 = max(dp2, dp1) dp1 += a if N % 2 == 1: print((max(dp1, dp2))) else: print((max(dp0, dp1)))
21
21
440
352
N = int(eval(input())) A = list(map(int, input().split())) INF = 10**18 dp0 = [-INF] * (N + 2) dp1 = [-INF] * (N + 2) dp2 = [-INF] * (N + 2) dp0[0] = 0 dp0[1] = 0 dp1[0] = 0 dp1[1] = 0 for i, a in enumerate(A, start=2): dp0[i] = dp0[i - 2] + a dp1[i] = max(dp1[i - 2] + a, dp0[i - 1]) dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2]) if N % 2 == 1: print((dp2[-1])) else: print((max(dp1[-1], dp0[-1])))
N = int(eval(input())) A = list(map(int, input().split())) INF = 10**18 dp0 = 0 dp1 = -INF dp2 = -INF for i, a in enumerate(A): if i % 2 == 0: dp1 = max(dp1, dp0) dp0 += a dp2 += a else: dp2 = max(dp2, dp1) dp1 += a if N % 2 == 1: print((max(dp1, dp2))) else: print((max(dp0, dp1)))
false
0
[ "-dp0 = [-INF] * (N + 2)", "-dp1 = [-INF] * (N + 2)", "-dp2 = [-INF] * (N + 2)", "-dp0[0] = 0", "-dp0[1] = 0", "-dp1[0] = 0", "-dp1[1] = 0", "-for i, a in enumerate(A, start=2):", "- dp0[i] = dp0[i - 2] + a", "- dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])", "- dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2])", "+dp0 = 0", "+dp1 = -INF", "+dp2 = -INF", "+for i, a in enumerate(A):", "+ if i % 2 == 0:", "+ dp1 = max(dp1, dp0)", "+ dp0 += a", "+ dp2 += a", "+ else:", "+ dp2 = max(dp2, dp1)", "+ dp1 += a", "- print((dp2[-1]))", "+ print((max(dp1, dp2)))", "- print((max(dp1[-1], dp0[-1])))", "+ print((max(dp0, dp1)))" ]
false
0.06802
0.038818
1.752248
[ "s068987473", "s478783629" ]
u562935282
p03112
python
s769313714
s537650155
1,506
1,301
16,176
16,152
Accepted
Accepted
13.61
from bisect import bisect_left A, B, Q = list(map(int, input().split())) s = [int(eval(input())) for _ in range(A)] t = [int(eval(input())) for _ in range(B)] x = [int(eval(input())) for _ in range(Q)] for xx in x: # 神先 ps_r = 0 s_r = bisect_left(s, xx) if s_r < A: ps_r += s[s_r] - xx t_r = bisect_left(t, s[s_r]) t_l = t_r - 1 b = 0 if t_r < B: b = t[t_r] - s[s_r] if 0 <= t_l < B: if b == 0: b = s[s_r] - t[t_l] else: b = min(b, s[s_r] - t[t_l]) ps_r += b else: ps_r = 10 ** 12 ps_l = 0 s_l = s_r - 1 if 0 <= s_l < A: ps_l += xx - s[s_l] t_r = bisect_left(t, s[s_l]) t_l = t_r - 1 b = 0 if t_r < B: b = t[t_r] - s[s_l] if 0 <= t_l < B: if b == 0: b = s[s_l] - t[t_l] else: b = min(b, s[s_l] - t[t_l]) ps_l += b else: ps_l = 10 ** 12 # 寺前 pt_r = 0 t_r = bisect_left(t, xx) if t_r < B: pt_r += t[t_r] - xx s_r = bisect_left(s, t[t_r]) s_l = s_r - 1 b = 0 if s_r < A: b = s[s_r] - t[t_r] if 0 <= s_l < A: if b == 0: b = t[t_r] - s[s_l] else: b = min(b, t[t_r] - s[s_l]) pt_r += b else: pt_r = 10 ** 12 pt_l = 0 t_l = t_r - 1 if 0 <= t_l < B: pt_l += xx - t[t_l] s_r = bisect_left(s, t[t_l]) s_l = s_r - 1 b = 0 if s_r < A: b = s[s_r] - t[t_l] if 0 <= s_l < A: if b == 0: b = t[t_l] - s[s_l] else: b = min(b, t[t_l] - s[s_l]) pt_l += b else: pt_l = 10 ** 12 # print(ps_r, ps_l, pt_r, pt_l) print((min(ps_r, ps_l, pt_r, pt_l)))
from bisect import bisect_left from itertools import product inf = float('inf') a, b, q = list(map(int, input().split())) s = [-inf] + [int(eval(input())) for _ in range(a)] + [inf] t = [-inf] + [int(eval(input())) for _ in range(b)] + [inf] x = [int(eval(input())) for _ in range(q)] for xx in x: ret = inf sr = bisect_left(s, xx) # xx以上の最小値 sl = max(0, sr - 1) tr = bisect_left(t, xx) tl = max(0, tr - 1) for ss, tt in product(s[sl:sr + 1], t[tl:tr + 1]): ret = min( ret, abs(xx - ss) + abs(ss - tt), abs(xx - tt) + abs(tt - ss) ) print(ret)
88
26
2,005
632
from bisect import bisect_left A, B, Q = list(map(int, input().split())) s = [int(eval(input())) for _ in range(A)] t = [int(eval(input())) for _ in range(B)] x = [int(eval(input())) for _ in range(Q)] for xx in x: # 神先 ps_r = 0 s_r = bisect_left(s, xx) if s_r < A: ps_r += s[s_r] - xx t_r = bisect_left(t, s[s_r]) t_l = t_r - 1 b = 0 if t_r < B: b = t[t_r] - s[s_r] if 0 <= t_l < B: if b == 0: b = s[s_r] - t[t_l] else: b = min(b, s[s_r] - t[t_l]) ps_r += b else: ps_r = 10**12 ps_l = 0 s_l = s_r - 1 if 0 <= s_l < A: ps_l += xx - s[s_l] t_r = bisect_left(t, s[s_l]) t_l = t_r - 1 b = 0 if t_r < B: b = t[t_r] - s[s_l] if 0 <= t_l < B: if b == 0: b = s[s_l] - t[t_l] else: b = min(b, s[s_l] - t[t_l]) ps_l += b else: ps_l = 10**12 # 寺前 pt_r = 0 t_r = bisect_left(t, xx) if t_r < B: pt_r += t[t_r] - xx s_r = bisect_left(s, t[t_r]) s_l = s_r - 1 b = 0 if s_r < A: b = s[s_r] - t[t_r] if 0 <= s_l < A: if b == 0: b = t[t_r] - s[s_l] else: b = min(b, t[t_r] - s[s_l]) pt_r += b else: pt_r = 10**12 pt_l = 0 t_l = t_r - 1 if 0 <= t_l < B: pt_l += xx - t[t_l] s_r = bisect_left(s, t[t_l]) s_l = s_r - 1 b = 0 if s_r < A: b = s[s_r] - t[t_l] if 0 <= s_l < A: if b == 0: b = t[t_l] - s[s_l] else: b = min(b, t[t_l] - s[s_l]) pt_l += b else: pt_l = 10**12 # print(ps_r, ps_l, pt_r, pt_l) print((min(ps_r, ps_l, pt_r, pt_l)))
from bisect import bisect_left from itertools import product inf = float("inf") a, b, q = list(map(int, input().split())) s = [-inf] + [int(eval(input())) for _ in range(a)] + [inf] t = [-inf] + [int(eval(input())) for _ in range(b)] + [inf] x = [int(eval(input())) for _ in range(q)] for xx in x: ret = inf sr = bisect_left(s, xx) # xx以上の最小値 sl = max(0, sr - 1) tr = bisect_left(t, xx) tl = max(0, tr - 1) for ss, tt in product(s[sl : sr + 1], t[tl : tr + 1]): ret = min(ret, abs(xx - ss) + abs(ss - tt), abs(xx - tt) + abs(tt - ss)) print(ret)
false
70.454545
[ "+from itertools import product", "-A, B, Q = list(map(int, input().split()))", "-s = [int(eval(input())) for _ in range(A)]", "-t = [int(eval(input())) for _ in range(B)]", "-x = [int(eval(input())) for _ in range(Q)]", "+inf = float(\"inf\")", "+a, b, q = list(map(int, input().split()))", "+s = [-inf] + [int(eval(input())) for _ in range(a)] + [inf]", "+t = [-inf] + [int(eval(input())) for _ in range(b)] + [inf]", "+x = [int(eval(input())) for _ in range(q)]", "- # 神先", "- ps_r = 0", "- s_r = bisect_left(s, xx)", "- if s_r < A:", "- ps_r += s[s_r] - xx", "- t_r = bisect_left(t, s[s_r])", "- t_l = t_r - 1", "- b = 0", "- if t_r < B:", "- b = t[t_r] - s[s_r]", "- if 0 <= t_l < B:", "- if b == 0:", "- b = s[s_r] - t[t_l]", "- else:", "- b = min(b, s[s_r] - t[t_l])", "- ps_r += b", "- else:", "- ps_r = 10**12", "- ps_l = 0", "- s_l = s_r - 1", "- if 0 <= s_l < A:", "- ps_l += xx - s[s_l]", "- t_r = bisect_left(t, s[s_l])", "- t_l = t_r - 1", "- b = 0", "- if t_r < B:", "- b = t[t_r] - s[s_l]", "- if 0 <= t_l < B:", "- if b == 0:", "- b = s[s_l] - t[t_l]", "- else:", "- b = min(b, s[s_l] - t[t_l])", "- ps_l += b", "- else:", "- ps_l = 10**12", "- # 寺前", "- pt_r = 0", "- t_r = bisect_left(t, xx)", "- if t_r < B:", "- pt_r += t[t_r] - xx", "- s_r = bisect_left(s, t[t_r])", "- s_l = s_r - 1", "- b = 0", "- if s_r < A:", "- b = s[s_r] - t[t_r]", "- if 0 <= s_l < A:", "- if b == 0:", "- b = t[t_r] - s[s_l]", "- else:", "- b = min(b, t[t_r] - s[s_l])", "- pt_r += b", "- else:", "- pt_r = 10**12", "- pt_l = 0", "- t_l = t_r - 1", "- if 0 <= t_l < B:", "- pt_l += xx - t[t_l]", "- s_r = bisect_left(s, t[t_l])", "- s_l = s_r - 1", "- b = 0", "- if s_r < A:", "- b = s[s_r] - t[t_l]", "- if 0 <= s_l < A:", "- if b == 0:", "- b = t[t_l] - s[s_l]", "- else:", "- b = min(b, t[t_l] - s[s_l])", "- pt_l += b", "- else:", "- pt_l = 10**12", "- # print(ps_r, ps_l, pt_r, pt_l)", "- print((min(ps_r, ps_l, pt_r, pt_l)))", "+ ret = inf", "+ sr = bisect_left(s, xx) # xx以上の最小値", "+ sl = max(0, sr - 1)", "+ tr = bisect_left(t, xx)", "+ tl = max(0, tr - 1)", "+ for ss, tt in product(s[sl : sr + 1], t[tl : tr + 1]):", "+ ret = min(ret, abs(xx - ss) + abs(ss - tt), abs(xx - tt) + abs(tt - ss))", "+ print(ret)" ]
false
0.043776
0.03673
1.191831
[ "s769313714", "s537650155" ]
u596276291
p03424
python
s994708760
s688328713
284
26
4,420
3,960
Accepted
Accepted
90.85
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 INF = float("inf") import sys sys.setrecursionlimit(10000) def solve(N, S): if "Y" in S: return "Four" else: return "Three" def main(): N = int(eval(input())) S = list(input().split()) print((solve(N, S))) if __name__ == '__main__': main()
#!/usr/bin/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] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def main(): N = int(eval(input())) S = list(input().split()) if "Y" in S: print("Four") else: print("Three") if __name__ == '__main__': main()
27
31
599
750
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 INF = float("inf") import sys sys.setrecursionlimit(10000) def solve(N, S): if "Y" in S: return "Four" else: return "Three" def main(): N = int(eval(input())) S = list(input().split()) print((solve(N, S))) if __name__ == "__main__": main()
#!/usr/bin/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] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def main(): N = int(eval(input())) S = list(input().split()) if "Y" in S: print("Four") else: print("Three") if __name__ == "__main__": main()
false
12.903226
[ "+#!/usr/bin/python3", "-", "-INF = float(\"inf\")", "+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]", "-def solve(N, S):", "- if \"Y\" in S:", "- return \"Four\"", "- else:", "- return \"Three\"", "+def inside(y, x, H, W):", "+ return 0 <= y < H and 0 <= x < W", "- print((solve(N, S)))", "+ if \"Y\" in S:", "+ print(\"Four\")", "+ else:", "+ print(\"Three\")" ]
false
0.084963
0.036817
2.307701
[ "s994708760", "s688328713" ]
u644907318
p03644
python
s708428348
s670946734
166
64
38,256
61,860
Accepted
Accepted
61.45
N = int(eval(input())) k = 0 while 2**k<=N: k += 1 print((2**(k-1)))
N = int(eval(input())) if N==1: print((1)) else: k = 1 while 2**k<=N: k += 1 print((2**(k-1)))
5
8
68
115
N = int(eval(input())) k = 0 while 2**k <= N: k += 1 print((2 ** (k - 1)))
N = int(eval(input())) if N == 1: print((1)) else: k = 1 while 2**k <= N: k += 1 print((2 ** (k - 1)))
false
37.5
[ "-k = 0", "-while 2**k <= N:", "- k += 1", "-print((2 ** (k - 1)))", "+if N == 1:", "+ print((1))", "+else:", "+ k = 1", "+ while 2**k <= N:", "+ k += 1", "+ print((2 ** (k - 1)))" ]
false
0.037154
0.036193
1.026551
[ "s708428348", "s670946734" ]
u732870425
p02755
python
s854652925
s749597156
19
17
2,940
3,060
Accepted
Accepted
10.53
A, B = list(map(int, input().split())) ans = -1 for i in range(10000): if i * 8 // 100 == A: if i * 10 // 100 == B: ans = i break print(ans)
A, B = list(map(int, input().split())) x = max((A*100+7)//8, B*100//10) y = min((A+1)*100/8, (B+1)*100/10) if x < y: ans = x else: ans = -1 print(ans)
10
11
181
165
A, B = list(map(int, input().split())) ans = -1 for i in range(10000): if i * 8 // 100 == A: if i * 10 // 100 == B: ans = i break print(ans)
A, B = list(map(int, input().split())) x = max((A * 100 + 7) // 8, B * 100 // 10) y = min((A + 1) * 100 / 8, (B + 1) * 100 / 10) if x < y: ans = x else: ans = -1 print(ans)
false
9.090909
[ "-ans = -1", "-for i in range(10000):", "- if i * 8 // 100 == A:", "- if i * 10 // 100 == B:", "- ans = i", "- break", "+x = max((A * 100 + 7) // 8, B * 100 // 10)", "+y = min((A + 1) * 100 / 8, (B + 1) * 100 / 10)", "+if x < y:", "+ ans = x", "+else:", "+ ans = -1" ]
false
0.175488
0.168679
1.040368
[ "s854652925", "s749597156" ]
u119148115
p03284
python
s780366091
s000888355
198
72
61,812
61,184
Accepted
Accepted
63.64
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = LI() if N % K == 0: print((0)) else: print((1))
import sys N,K = list(map(int,sys.stdin.readline().rstrip().split())) print((0 if N % K == 0 else 1))
10
5
161
99
import sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = LI() if N % K == 0: print((0)) else: print((1))
import sys N, K = list(map(int, sys.stdin.readline().rstrip().split())) print((0 if N % K == 0 else 1))
false
50
[ "-", "-def LI():", "- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "-", "-", "-N, K = LI()", "-if N % K == 0:", "- print((0))", "-else:", "- print((1))", "+N, K = list(map(int, sys.stdin.readline().rstrip().split()))", "+print((0 if N % K == 0 else 1))" ]
false
0.03855
0.074208
0.519485
[ "s780366091", "s000888355" ]
u828455902
p02400
python
s493094448
s089291917
20
10
4,220
4,220
Accepted
Accepted
50
r=eval(input());p=3.1415926535897932;print("%.9f"%(p*r*r),r*2*p)
r=eval(input());p=3.141592653589793;print("%.9f"%(p*r*r),r*2*p)
1
1
57
56
r = eval(input()) p = 3.1415926535897932 print("%.9f" % (p * r * r), r * 2 * p)
r = eval(input()) p = 3.141592653589793 print("%.9f" % (p * r * r), r * 2 * p)
false
0
[ "-p = 3.1415926535897932", "+p = 3.141592653589793" ]
false
0.04551
0.042228
1.077711
[ "s493094448", "s089291917" ]
u852690916
p02821
python
s621735643
s772189540
1,699
1,063
56,836
56,600
Accepted
Accepted
37.43
import bisect N,M=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() #和がx以上になる組み合わせの総数を求める関数 def pattern_num_ge_x(x): p=0 for a in A: p+=(N-bisect.bisect_left(A, x-a)) return(p) #pattern_num_ge_x(x)がM未満になる最小のxを探す(=r) #lはM以上になる最大のx l=-1 r=10**10+1 while r-l>1: m=(r+l)//2 if pattern_num_ge_x(m)<M: r=m else: l=m #和がr以上になる組み合わせの総和を求める(累積和を使用) S=[0]+list(reversed(A[:])) for i in range(1,N+1): S[i]+=S[i-1] ans=0 for a in A: idx=bisect.bisect_left(A,r-a) ans+=a*(N-idx) + S[N-idx] M-=(N-idx) #回数のあまり分lを足す ans+=l*M print(ans)
import bisect N,M=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() #和がx以上になる組み合わせの総数を求める関数 def pattern_num_ge_x(x): p=0 for a in A: p+=(N-bisect.bisect_left(A, x-a)) return(p) #pattern_num_ge_x(x)がM未満になる最小のxを探す(=r) #lはM以上になる最大のx l=-1 r=10**5*2+1 while r-l>1: m=(r+l)//2 if pattern_num_ge_x(m)<M: r=m else: l=m #和がr以上になる組み合わせの総和を求める(累積和を使用) S=[0]+list(reversed(A[:])) for i in range(1,N+1): S[i]+=S[i-1] ans=0 for a in A: idx=bisect.bisect_left(A,r-a) ans+=a*(N-idx) + S[N-idx] M-=(N-idx) #回数のあまり分lを足す ans+=l*M print(ans)
37
37
642
643
import bisect N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # 和がx以上になる組み合わせの総数を求める関数 def pattern_num_ge_x(x): p = 0 for a in A: p += N - bisect.bisect_left(A, x - a) return p # pattern_num_ge_x(x)がM未満になる最小のxを探す(=r) # lはM以上になる最大のx l = -1 r = 10**10 + 1 while r - l > 1: m = (r + l) // 2 if pattern_num_ge_x(m) < M: r = m else: l = m # 和がr以上になる組み合わせの総和を求める(累積和を使用) S = [0] + list(reversed(A[:])) for i in range(1, N + 1): S[i] += S[i - 1] ans = 0 for a in A: idx = bisect.bisect_left(A, r - a) ans += a * (N - idx) + S[N - idx] M -= N - idx # 回数のあまり分lを足す ans += l * M print(ans)
import bisect N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # 和がx以上になる組み合わせの総数を求める関数 def pattern_num_ge_x(x): p = 0 for a in A: p += N - bisect.bisect_left(A, x - a) return p # pattern_num_ge_x(x)がM未満になる最小のxを探す(=r) # lはM以上になる最大のx l = -1 r = 10**5 * 2 + 1 while r - l > 1: m = (r + l) // 2 if pattern_num_ge_x(m) < M: r = m else: l = m # 和がr以上になる組み合わせの総和を求める(累積和を使用) S = [0] + list(reversed(A[:])) for i in range(1, N + 1): S[i] += S[i - 1] ans = 0 for a in A: idx = bisect.bisect_left(A, r - a) ans += a * (N - idx) + S[N - idx] M -= N - idx # 回数のあまり分lを足す ans += l * M print(ans)
false
0
[ "-r = 10**10 + 1", "+r = 10**5 * 2 + 1" ]
false
0.12928
0.058552
2.207952
[ "s621735643", "s772189540" ]
u761529120
p03162
python
s735617841
s948031612
629
331
75,608
103,736
Accepted
Accepted
47.38
def main(): N = int(eval(input())) work = [] for _ in range(N): a, b, c = list(map(int, input().split())) work.append((a,b,c)) dp = [[0] * 3 for _ in range(N)] for i in range(N): for j in range(3): if i == 0: dp[i][j] = work[i][j] continue if j == 0: dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + work[i][0] elif j == 1: dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + work[i][1] elif j == 2: dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + work[i][2] print((max(dp[N-1]))) if __name__ == "__main__": main()
def main(): N = int(eval(input())) acts = [] for _ in range(N): a, b, c = list(map(int, input().split())) acts.append([a,b,c]) dp = [[0] * 3 for _ in range(N + 5)] dp[0][0] = acts[0][0] dp[0][1] = acts[0][1] dp[0][2] = acts[0][2] for i in range(1,N): for j in range(3): if j == 0: score = max(dp[i-1][1], dp[i-1][2]) if j == 1: score = max(dp[i-1][0], dp[i-1][2]) if j == 2: score = max(dp[i-1][1], dp[i-1][0]) dp[i][j] = acts[i][j] + score print((max(dp[N-1]))) if __name__ == "__main__": main()
25
27
690
673
def main(): N = int(eval(input())) work = [] for _ in range(N): a, b, c = list(map(int, input().split())) work.append((a, b, c)) dp = [[0] * 3 for _ in range(N)] for i in range(N): for j in range(3): if i == 0: dp[i][j] = work[i][j] continue if j == 0: dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + work[i][0] elif j == 1: dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + work[i][1] elif j == 2: dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + work[i][2] print((max(dp[N - 1]))) if __name__ == "__main__": main()
def main(): N = int(eval(input())) acts = [] for _ in range(N): a, b, c = list(map(int, input().split())) acts.append([a, b, c]) dp = [[0] * 3 for _ in range(N + 5)] dp[0][0] = acts[0][0] dp[0][1] = acts[0][1] dp[0][2] = acts[0][2] for i in range(1, N): for j in range(3): if j == 0: score = max(dp[i - 1][1], dp[i - 1][2]) if j == 1: score = max(dp[i - 1][0], dp[i - 1][2]) if j == 2: score = max(dp[i - 1][1], dp[i - 1][0]) dp[i][j] = acts[i][j] + score print((max(dp[N - 1]))) if __name__ == "__main__": main()
false
7.407407
[ "- work = []", "+ acts = []", "- work.append((a, b, c))", "- dp = [[0] * 3 for _ in range(N)]", "- for i in range(N):", "+ acts.append([a, b, c])", "+ dp = [[0] * 3 for _ in range(N + 5)]", "+ dp[0][0] = acts[0][0]", "+ dp[0][1] = acts[0][1]", "+ dp[0][2] = acts[0][2]", "+ for i in range(1, N):", "- if i == 0:", "- dp[i][j] = work[i][j]", "- continue", "- dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + work[i][0]", "- elif j == 1:", "- dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + work[i][1]", "- elif j == 2:", "- dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + work[i][2]", "+ score = max(dp[i - 1][1], dp[i - 1][2])", "+ if j == 1:", "+ score = max(dp[i - 1][0], dp[i - 1][2])", "+ if j == 2:", "+ score = max(dp[i - 1][1], dp[i - 1][0])", "+ dp[i][j] = acts[i][j] + score" ]
false
0.092832
0.041669
2.227851
[ "s735617841", "s948031612" ]
u057109575
p03111
python
s446021933
s591951122
237
107
43,480
74,188
Accepted
Accepted
54.85
N, A, B, C, *X = list(map(int, open(0).read().split())) def dfs(i, a, b, c): if i == N: if a * b * c == 0: return 10 ** 9 + 7 return abs(A - a) + abs(B - b) + abs(C - c) v0 = dfs(i + 1, a, b, c) v1 = dfs(i + 1, a + X[i], b, c) + int(a > 0) * 10 v2 = dfs(i + 1, a, b + X[i], c) + int(b > 0) * 10 v3 = dfs(i + 1, a, b, c + X[i]) + int(c > 0) * 10 return min(v0, v1, v2, v3) print((dfs(0, 0, 0, 0)))
N, A, B, C = list(map(int, input().split())) X = [int(eval(input())) for _ in range(N)] def dfs(idx, a, b, c, cnt): if idx == N: if min(a, b, c) > 0: return abs(a - A) + abs(b - B) + abs(c - C) + cnt - 30 else: return 10 ** 9 res = 10 ** 9 res = min(res, dfs(idx + 1, a, b, c, cnt)) res = min(res, dfs(idx + 1, a + X[idx], b, c, cnt + 10)) res = min(res, dfs(idx + 1, a, b + X[idx], c, cnt + 10)) res = min(res, dfs(idx + 1, a, b, c + X[idx], cnt + 10)) return res print((dfs(0, 0, 0, 0, 0)))
17
21
462
573
N, A, B, C, *X = list(map(int, open(0).read().split())) def dfs(i, a, b, c): if i == N: if a * b * c == 0: return 10**9 + 7 return abs(A - a) + abs(B - b) + abs(C - c) v0 = dfs(i + 1, a, b, c) v1 = dfs(i + 1, a + X[i], b, c) + int(a > 0) * 10 v2 = dfs(i + 1, a, b + X[i], c) + int(b > 0) * 10 v3 = dfs(i + 1, a, b, c + X[i]) + int(c > 0) * 10 return min(v0, v1, v2, v3) print((dfs(0, 0, 0, 0)))
N, A, B, C = list(map(int, input().split())) X = [int(eval(input())) for _ in range(N)] def dfs(idx, a, b, c, cnt): if idx == N: if min(a, b, c) > 0: return abs(a - A) + abs(b - B) + abs(c - C) + cnt - 30 else: return 10**9 res = 10**9 res = min(res, dfs(idx + 1, a, b, c, cnt)) res = min(res, dfs(idx + 1, a + X[idx], b, c, cnt + 10)) res = min(res, dfs(idx + 1, a, b + X[idx], c, cnt + 10)) res = min(res, dfs(idx + 1, a, b, c + X[idx], cnt + 10)) return res print((dfs(0, 0, 0, 0, 0)))
false
19.047619
[ "-N, A, B, C, *X = list(map(int, open(0).read().split()))", "+N, A, B, C = list(map(int, input().split()))", "+X = [int(eval(input())) for _ in range(N)]", "-def dfs(i, a, b, c):", "- if i == N:", "- if a * b * c == 0:", "- return 10**9 + 7", "- return abs(A - a) + abs(B - b) + abs(C - c)", "- v0 = dfs(i + 1, a, b, c)", "- v1 = dfs(i + 1, a + X[i], b, c) + int(a > 0) * 10", "- v2 = dfs(i + 1, a, b + X[i], c) + int(b > 0) * 10", "- v3 = dfs(i + 1, a, b, c + X[i]) + int(c > 0) * 10", "- return min(v0, v1, v2, v3)", "+def dfs(idx, a, b, c, cnt):", "+ if idx == N:", "+ if min(a, b, c) > 0:", "+ return abs(a - A) + abs(b - B) + abs(c - C) + cnt - 30", "+ else:", "+ return 10**9", "+ res = 10**9", "+ res = min(res, dfs(idx + 1, a, b, c, cnt))", "+ res = min(res, dfs(idx + 1, a + X[idx], b, c, cnt + 10))", "+ res = min(res, dfs(idx + 1, a, b + X[idx], c, cnt + 10))", "+ res = min(res, dfs(idx + 1, a, b, c + X[idx], cnt + 10))", "+ return res", "-print((dfs(0, 0, 0, 0)))", "+print((dfs(0, 0, 0, 0, 0)))" ]
false
0.237702
0.270862
0.877575
[ "s446021933", "s591951122" ]
u729133443
p02782
python
s314732135
s285275763
717
344
161,268
82,164
Accepted
Accepted
52.02
def main(): M=10**9+7 a,b,c,d=list(map(int,input().split())) n=c+d+2 fac=[0]*(n+1) fac[0]=lt=1 for i in range(1,n+1):fac[i]=lt=lt*i%M inv=[0]*(n+1) inv[n]=lt=pow(fac[n],M-2,M) for i in range(n,0,-1):inv[i-1]=lt=lt*i%M comb=lambda n,k:fac[n]*inv[n-k]*inv[k] f=lambda r,c:fac[r+c+2]*inv[c+1]*inv[r+1]-c-r-2 print(((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M)) main()
def main(): M=10**9+7 a,b,c,d=list(map(int,input().split())) n=c+d+2 fac=[0]*(n+1) fac[0]=lt=1 for i in range(1,n+1):fac[i]=lt=lt*i%M inv=lambda n:pow(fac[n],M-2,M) f=lambda r,c:fac[r+c+2]*inv(c+1)*inv(r+1)-c-r-2 print(((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M)) main()
14
11
389
288
def main(): M = 10**9 + 7 a, b, c, d = list(map(int, input().split())) n = c + d + 2 fac = [0] * (n + 1) fac[0] = lt = 1 for i in range(1, n + 1): fac[i] = lt = lt * i % M inv = [0] * (n + 1) inv[n] = lt = pow(fac[n], M - 2, M) for i in range(n, 0, -1): inv[i - 1] = lt = lt * i % M comb = lambda n, k: fac[n] * inv[n - k] * inv[k] f = lambda r, c: fac[r + c + 2] * inv[c + 1] * inv[r + 1] - c - r - 2 print(((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M)) main()
def main(): M = 10**9 + 7 a, b, c, d = list(map(int, input().split())) n = c + d + 2 fac = [0] * (n + 1) fac[0] = lt = 1 for i in range(1, n + 1): fac[i] = lt = lt * i % M inv = lambda n: pow(fac[n], M - 2, M) f = lambda r, c: fac[r + c + 2] * inv(c + 1) * inv(r + 1) - c - r - 2 print(((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M)) main()
false
21.428571
[ "- inv = [0] * (n + 1)", "- inv[n] = lt = pow(fac[n], M - 2, M)", "- for i in range(n, 0, -1):", "- inv[i - 1] = lt = lt * i % M", "- comb = lambda n, k: fac[n] * inv[n - k] * inv[k]", "- f = lambda r, c: fac[r + c + 2] * inv[c + 1] * inv[r + 1] - c - r - 2", "+ inv = lambda n: pow(fac[n], M - 2, M)", "+ f = lambda r, c: fac[r + c + 2] * inv(c + 1) * inv(r + 1) - c - r - 2" ]
false
0.048781
0.039635
1.230765
[ "s314732135", "s285275763" ]
u633068244
p00009
python
s577234371
s308063482
330
280
36,984
37,044
Accepted
Accepted
15.15
n = [] while True: try:n.append(int(input())) except:break R = max(n)+1 p = [1]*R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4,R,2)] for i in range(3,int(R**0.5)+1,2): if p[i]: p[2*i::i] = [0 for j in range(2*i,R,i)] for i in n: print(sum(p[:i+1]))
R = 1000000 p = [1]*R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4,R,2)] for i in range(3,int(R**0.5)+1,2): if p[i]: p[2*i::i] = [0]*len(p[2*i::i]) while True: try:print(sum(p[:int(input())+1])) except:break
13
10
289
240
n = [] while True: try: n.append(int(input())) except: break R = max(n) + 1 p = [1] * R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4, R, 2)] for i in range(3, int(R**0.5) + 1, 2): if p[i]: p[2 * i :: i] = [0 for j in range(2 * i, R, i)] for i in n: print(sum(p[: i + 1]))
R = 1000000 p = [1] * R p[0] = p[1] = 0 p[4::2] = [0 for i in range(4, R, 2)] for i in range(3, int(R**0.5) + 1, 2): if p[i]: p[2 * i :: i] = [0] * len(p[2 * i :: i]) while True: try: print(sum(p[: int(input()) + 1])) except: break
false
23.076923
[ "-n = []", "-while True:", "- try:", "- n.append(int(input()))", "- except:", "- break", "-R = max(n) + 1", "+R = 1000000", "- p[2 * i :: i] = [0 for j in range(2 * i, R, i)]", "-for i in n:", "- print(sum(p[: i + 1]))", "+ p[2 * i :: i] = [0] * len(p[2 * i :: i])", "+while True:", "+ try:", "+ print(sum(p[: int(input()) + 1]))", "+ except:", "+ break" ]
false
0.036133
0.166112
0.217522
[ "s577234371", "s308063482" ]
u434846982
p02678
python
s448951489
s857078212
616
538
59,956
61,176
Accepted
Accepted
12.66
(n,m),*e=[[*list(map(int, t.split()))] for t in open(0)] t=[[]for _ in range(n+1)] for a,b in e:t[a]+=[b];t[b]+=[a] q=[1] a=[0]*-~n while q:q=[a[j]==0and(a.__setitem__(j,i)or j)for i in q for j in t[i]] print(('Yes',*a[2:]))
(n, m), *e = [[*list(map(int, t.split()))] for t in open(0)] q = [1] ans = [0] * -~n node = [[] for _ in range(-~n)] temp = set() for i, j in e: node[i].append(j) node[j].append(i) while q: for x in q: for y in node[x]: if ans[y] == 0: ans[y] = x temp.add(y) q = list(temp) temp.clear() if 0 in ans[2:]: print('No') else: print(('Yes', *ans[2:]))
7
23
223
444
(n, m), *e = [[*list(map(int, t.split()))] for t in open(0)] t = [[] for _ in range(n + 1)] for a, b in e: t[a] += [b] t[b] += [a] q = [1] a = [0] * -~n while q: q = [a[j] == 0 and (a.__setitem__(j, i) or j) for i in q for j in t[i]] print(("Yes", *a[2:]))
(n, m), *e = [[*list(map(int, t.split()))] for t in open(0)] q = [1] ans = [0] * -~n node = [[] for _ in range(-~n)] temp = set() for i, j in e: node[i].append(j) node[j].append(i) while q: for x in q: for y in node[x]: if ans[y] == 0: ans[y] = x temp.add(y) q = list(temp) temp.clear() if 0 in ans[2:]: print("No") else: print(("Yes", *ans[2:]))
false
69.565217
[ "-t = [[] for _ in range(n + 1)]", "-for a, b in e:", "- t[a] += [b]", "- t[b] += [a]", "-a = [0] * -~n", "+ans = [0] * -~n", "+node = [[] for _ in range(-~n)]", "+temp = set()", "+for i, j in e:", "+ node[i].append(j)", "+ node[j].append(i)", "- q = [a[j] == 0 and (a.__setitem__(j, i) or j) for i in q for j in t[i]]", "-print((\"Yes\", *a[2:]))", "+ for x in q:", "+ for y in node[x]:", "+ if ans[y] == 0:", "+ ans[y] = x", "+ temp.add(y)", "+ q = list(temp)", "+ temp.clear()", "+if 0 in ans[2:]:", "+ print(\"No\")", "+else:", "+ print((\"Yes\", *ans[2:]))" ]
false
0.039478
0.038978
1.012831
[ "s448951489", "s857078212" ]
u411203878
p03776
python
s751248872
s392632266
172
66
38,768
64,212
Accepted
Accepted
61.63
import math def combination(n, k): return math.factorial(n) // math.factorial(k) // math.factorial(n - k) import collections n,a,b = list(map(int,input().split())) t = list(map(int,input().split())) c = collections.Counter(t) c = sorted(list(c.items()), key=lambda x:-x[0]) memo = 0 for k,i in enumerate(c): #print(k,i[0],i[1]) memo += i[1] if a<=memo: ans = 0 memo2 = 0 for j in range(k+1): if j != k: memo2 += c[j][1] ans += c[j][0]*c[j][1] else: ans += c[j][0]*(a-memo2) print((ans/a)) break if c[0][1] <= a: print((combination(c[j][1],a-memo2))) else: ans1=0 for l in range(a,min(c[0][1],b)+1): ans1 += combination(c[j][1],l) print(ans1)
import math def combination(n, k): return math.factorial(n) // math.factorial(k) // math.factorial(n - k) N,A,B = list(map(int,input().split())) V = list(map(int,input().split())) v_count = {} for v in V: if v not in v_count: v_count[v] = 1 else: v_count[v] += 1 v_count = sorted(list(v_count.items()), key=lambda x:-x[0]) tmp_count = [0] ans = 0 for val,count in v_count: tmp_count.append(tmp_count[-1]+count) if tmp_count[-1] < A: ans += val*count else: ans += val*(A-tmp_count[-2]) print((ans/A)) break #print(tmp_count, ans) if v_count[0][1] < A: comb = A-tmp_count[-2] root = combination(v_count[len(tmp_count)-2][1],comb) else: root = 0 for i in range(A, min(v_count[0][1],B)+1): root += combination(v_count[0][1],i) print(root)
38
39
850
863
import math def combination(n, k): return math.factorial(n) // math.factorial(k) // math.factorial(n - k) import collections n, a, b = list(map(int, input().split())) t = list(map(int, input().split())) c = collections.Counter(t) c = sorted(list(c.items()), key=lambda x: -x[0]) memo = 0 for k, i in enumerate(c): # print(k,i[0],i[1]) memo += i[1] if a <= memo: ans = 0 memo2 = 0 for j in range(k + 1): if j != k: memo2 += c[j][1] ans += c[j][0] * c[j][1] else: ans += c[j][0] * (a - memo2) print((ans / a)) break if c[0][1] <= a: print((combination(c[j][1], a - memo2))) else: ans1 = 0 for l in range(a, min(c[0][1], b) + 1): ans1 += combination(c[j][1], l) print(ans1)
import math def combination(n, k): return math.factorial(n) // math.factorial(k) // math.factorial(n - k) N, A, B = list(map(int, input().split())) V = list(map(int, input().split())) v_count = {} for v in V: if v not in v_count: v_count[v] = 1 else: v_count[v] += 1 v_count = sorted(list(v_count.items()), key=lambda x: -x[0]) tmp_count = [0] ans = 0 for val, count in v_count: tmp_count.append(tmp_count[-1] + count) if tmp_count[-1] < A: ans += val * count else: ans += val * (A - tmp_count[-2]) print((ans / A)) break # print(tmp_count, ans) if v_count[0][1] < A: comb = A - tmp_count[-2] root = combination(v_count[len(tmp_count) - 2][1], comb) else: root = 0 for i in range(A, min(v_count[0][1], B) + 1): root += combination(v_count[0][1], i) print(root)
false
2.564103
[ "-import collections", "-", "-n, a, b = list(map(int, input().split()))", "-t = list(map(int, input().split()))", "-c = collections.Counter(t)", "-c = sorted(list(c.items()), key=lambda x: -x[0])", "-memo = 0", "-for k, i in enumerate(c):", "- # print(k,i[0],i[1])", "- memo += i[1]", "- if a <= memo:", "- ans = 0", "- memo2 = 0", "- for j in range(k + 1):", "- if j != k:", "- memo2 += c[j][1]", "- ans += c[j][0] * c[j][1]", "- else:", "- ans += c[j][0] * (a - memo2)", "- print((ans / a))", "+N, A, B = list(map(int, input().split()))", "+V = list(map(int, input().split()))", "+v_count = {}", "+for v in V:", "+ if v not in v_count:", "+ v_count[v] = 1", "+ else:", "+ v_count[v] += 1", "+v_count = sorted(list(v_count.items()), key=lambda x: -x[0])", "+tmp_count = [0]", "+ans = 0", "+for val, count in v_count:", "+ tmp_count.append(tmp_count[-1] + count)", "+ if tmp_count[-1] < A:", "+ ans += val * count", "+ else:", "+ ans += val * (A - tmp_count[-2])", "+ print((ans / A))", "-if c[0][1] <= a:", "- print((combination(c[j][1], a - memo2)))", "+# print(tmp_count, ans)", "+if v_count[0][1] < A:", "+ comb = A - tmp_count[-2]", "+ root = combination(v_count[len(tmp_count) - 2][1], comb)", "- ans1 = 0", "- for l in range(a, min(c[0][1], b) + 1):", "- ans1 += combination(c[j][1], l)", "- print(ans1)", "+ root = 0", "+ for i in range(A, min(v_count[0][1], B) + 1):", "+ root += combination(v_count[0][1], i)", "+print(root)" ]
false
0.037648
0.033447
1.125597
[ "s751248872", "s392632266" ]
u411203878
p03986
python
s313005388
s222331193
205
78
61,552
82,664
Accepted
Accepted
61.95
s=eval(input()) s=list(s) ans = ['G'] for i in s: if i == 'S': ans.append(i) else: if ans[-1] == 'S': ans.pop(-1) else: ans.append(i) print((len(ans)-1))
X=list(eval(input())) counter_s = 0 counter_t = 0 for i in range(len(X)): if counter_s == 0 and X[i] == 'T': counter_t += 1 elif 0 < counter_s and X[i] == 'T': counter_s -= 1 elif X[i] == 'S': counter_s += 1 print((counter_s+counter_t))
15
14
218
281
s = eval(input()) s = list(s) ans = ["G"] for i in s: if i == "S": ans.append(i) else: if ans[-1] == "S": ans.pop(-1) else: ans.append(i) print((len(ans) - 1))
X = list(eval(input())) counter_s = 0 counter_t = 0 for i in range(len(X)): if counter_s == 0 and X[i] == "T": counter_t += 1 elif 0 < counter_s and X[i] == "T": counter_s -= 1 elif X[i] == "S": counter_s += 1 print((counter_s + counter_t))
false
6.666667
[ "-s = eval(input())", "-s = list(s)", "-ans = [\"G\"]", "-for i in s:", "- if i == \"S\":", "- ans.append(i)", "- else:", "- if ans[-1] == \"S\":", "- ans.pop(-1)", "- else:", "- ans.append(i)", "-print((len(ans) - 1))", "+X = list(eval(input()))", "+counter_s = 0", "+counter_t = 0", "+for i in range(len(X)):", "+ if counter_s == 0 and X[i] == \"T\":", "+ counter_t += 1", "+ elif 0 < counter_s and X[i] == \"T\":", "+ counter_s -= 1", "+ elif X[i] == \"S\":", "+ counter_s += 1", "+print((counter_s + counter_t))" ]
false
0.036359
0.037941
0.958291
[ "s313005388", "s222331193" ]
u871980676
p02715
python
s845992546
s308285390
1,720
333
27,784
75,356
Accepted
Accepted
80.64
import numpy as np N,K = list(map(int,input().split())) res = np.zeros(K+1, dtype=np.int64) ans = 0 MOD = 10**9+7 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return np.array(divisors, dtype=np.int64) for k in range(K,0,-1): y = make_divisors(k) s = K//k tmp = pow(s, N, MOD) ans += k*(tmp-res[k]) # print(res[k], tmp, ans) res[y] += tmp-res[k] print((ans%MOD))
N,K = list(map(int,input().split())) res = [0]*(K+1) ans = 0 MOD = 10**9+7 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors for k in range(K,0,-1): y = make_divisors(k) s = K//k tmp = pow(s, N, MOD) val = tmp-res[k] ans += k*val for yy in y: res[yy] += val print((ans%MOD))
23
22
577
489
import numpy as np N, K = list(map(int, input().split())) res = np.zeros(K + 1, dtype=np.int64) ans = 0 MOD = 10**9 + 7 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return np.array(divisors, dtype=np.int64) for k in range(K, 0, -1): y = make_divisors(k) s = K // k tmp = pow(s, N, MOD) ans += k * (tmp - res[k]) # print(res[k], tmp, ans) res[y] += tmp - res[k] print((ans % MOD))
N, K = list(map(int, input().split())) res = [0] * (K + 1) ans = 0 MOD = 10**9 + 7 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors for k in range(K, 0, -1): y = make_divisors(k) s = K // k tmp = pow(s, N, MOD) val = tmp - res[k] ans += k * val for yy in y: res[yy] += val print((ans % MOD))
false
4.347826
[ "-import numpy as np", "-", "-res = np.zeros(K + 1, dtype=np.int64)", "+res = [0] * (K + 1)", "- divisors.sort()", "- return np.array(divisors, dtype=np.int64)", "+ return divisors", "- ans += k * (tmp - res[k])", "- # print(res[k], tmp, ans)", "- res[y] += tmp - res[k]", "+ val = tmp - res[k]", "+ ans += k * val", "+ for yy in y:", "+ res[yy] += val" ]
false
1.277728
0.882521
1.447817
[ "s845992546", "s308285390" ]
u857759499
p03420
python
s971798058
s351073149
74
60
12,760
12,592
Accepted
Accepted
18.92
n,k = list(map(int,input().split())) print((sum([(i-k)*(n//i)+max(0,n%i-max(0,k-1)) for i in range(k+1,n+1)])))
n,k = list(map(int,input().split())) print((n**2 if not k else sum([(i-k)*(n//i)+max(0,n%i-k+1) for i in range(k+1,n+1)])))
2
2
104
116
n, k = list(map(int, input().split())) print( ( sum( [ (i - k) * (n // i) + max(0, n % i - max(0, k - 1)) for i in range(k + 1, n + 1) ] ) ) )
n, k = list(map(int, input().split())) print( ( n**2 if not k else sum( [(i - k) * (n // i) + max(0, n % i - k + 1) for i in range(k + 1, n + 1)] ) ) )
false
0
[ "- sum(", "- [", "- (i - k) * (n // i) + max(0, n % i - max(0, k - 1))", "- for i in range(k + 1, n + 1)", "- ]", "+ n**2", "+ if not k", "+ else sum(", "+ [(i - k) * (n // i) + max(0, n % i - k + 1) for i in range(k + 1, n + 1)]" ]
false
0.049684
0.049706
0.999551
[ "s971798058", "s351073149" ]
u896741788
p03087
python
s462522508
s844708148
862
535
7,856
18,936
Accepted
Accepted
37.94
n,q=list(map(int,input().split())) l=[0 for i in range(n)] for i,v in enumerate(list(input().replace("AC","X!"))): l[i]=l[i-1]+(v=="!") for c in range(q): h,m=list(map(int,input().split())) print((l[m-1]-l[h-1]))
n,q=list(map(int,input().split())) t=eval(input()) a=[0]*n from collections import defaultdict tail=defaultdict(int) for i in range(n-1): if t[i]=="A"and t[i+1]=="C": a[i+1]+=1 tail[i]+=1 from itertools import accumulate a=list(accumulate(a)) for _ in range(q): l,r=list(map(int,input().split())) l,r=l-1,r-1 if l==0:print((a[r])) else: print((a[r]-a[l-1]-tail[l-1]))
7
18
216
407
n, q = list(map(int, input().split())) l = [0 for i in range(n)] for i, v in enumerate(list(input().replace("AC", "X!"))): l[i] = l[i - 1] + (v == "!") for c in range(q): h, m = list(map(int, input().split())) print((l[m - 1] - l[h - 1]))
n, q = list(map(int, input().split())) t = eval(input()) a = [0] * n from collections import defaultdict tail = defaultdict(int) for i in range(n - 1): if t[i] == "A" and t[i + 1] == "C": a[i + 1] += 1 tail[i] += 1 from itertools import accumulate a = list(accumulate(a)) for _ in range(q): l, r = list(map(int, input().split())) l, r = l - 1, r - 1 if l == 0: print((a[r])) else: print((a[r] - a[l - 1] - tail[l - 1]))
false
61.111111
[ "-l = [0 for i in range(n)]", "-for i, v in enumerate(list(input().replace(\"AC\", \"X!\"))):", "- l[i] = l[i - 1] + (v == \"!\")", "-for c in range(q):", "- h, m = list(map(int, input().split()))", "- print((l[m - 1] - l[h - 1]))", "+t = eval(input())", "+a = [0] * n", "+from collections import defaultdict", "+", "+tail = defaultdict(int)", "+for i in range(n - 1):", "+ if t[i] == \"A\" and t[i + 1] == \"C\":", "+ a[i + 1] += 1", "+ tail[i] += 1", "+from itertools import accumulate", "+", "+a = list(accumulate(a))", "+for _ in range(q):", "+ l, r = list(map(int, input().split()))", "+ l, r = l - 1, r - 1", "+ if l == 0:", "+ print((a[r]))", "+ else:", "+ print((a[r] - a[l - 1] - tail[l - 1]))" ]
false
0.040786
0.036364
1.121616
[ "s462522508", "s844708148" ]
u822961851
p03805
python
s721719592
s880000301
29
25
3,064
3,064
Accepted
Accepted
13.79
# サンプルコード計算量お試し import itertools N, M = list(map(int, input().split())) adj_matrix = [[0]* N for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) adj_matrix[a-1][b-1] = 1 adj_matrix[b-1][a-1] = 1 cnt = 0 for each in itertools.permutations(list(range(N))): if each[0] != 0: break factor = 1 for i in range(N-1): factor *= adj_matrix[each[i]][each[i+1]] cnt += factor print(cnt)
import itertools def resolve(): n, m = list(map(int, input().split())) S = [[0] * n for i in range(n)] for i in range(m): a, b = list(map(int, input().split())) S[a - 1][b - 1] = 1 S[b - 1][a - 1] = 1 ans = 0 for p in itertools.permutations(list(range(n))): if p[0] != 0: break tmp = 1 for i in range(n-1): tmp *= S[p[i]][p[i + 1]] ans += tmp print(ans) if __name__ == '__main__': resolve()
23
24
454
508
# サンプルコード計算量お試し import itertools N, M = list(map(int, input().split())) adj_matrix = [[0] * N for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) adj_matrix[a - 1][b - 1] = 1 adj_matrix[b - 1][a - 1] = 1 cnt = 0 for each in itertools.permutations(list(range(N))): if each[0] != 0: break factor = 1 for i in range(N - 1): factor *= adj_matrix[each[i]][each[i + 1]] cnt += factor print(cnt)
import itertools def resolve(): n, m = list(map(int, input().split())) S = [[0] * n for i in range(n)] for i in range(m): a, b = list(map(int, input().split())) S[a - 1][b - 1] = 1 S[b - 1][a - 1] = 1 ans = 0 for p in itertools.permutations(list(range(n))): if p[0] != 0: break tmp = 1 for i in range(n - 1): tmp *= S[p[i]][p[i + 1]] ans += tmp print(ans) if __name__ == "__main__": resolve()
false
4.166667
[ "-# サンプルコード計算量お試し", "-N, M = list(map(int, input().split()))", "-adj_matrix = [[0] * N for _ in range(N)]", "-for i in range(M):", "- a, b = list(map(int, input().split()))", "- adj_matrix[a - 1][b - 1] = 1", "- adj_matrix[b - 1][a - 1] = 1", "-cnt = 0", "-for each in itertools.permutations(list(range(N))):", "- if each[0] != 0:", "- break", "- factor = 1", "- for i in range(N - 1):", "- factor *= adj_matrix[each[i]][each[i + 1]]", "- cnt += factor", "-print(cnt)", "+", "+def resolve():", "+ n, m = list(map(int, input().split()))", "+ S = [[0] * n for i in range(n)]", "+ for i in range(m):", "+ a, b = list(map(int, input().split()))", "+ S[a - 1][b - 1] = 1", "+ S[b - 1][a - 1] = 1", "+ ans = 0", "+ for p in itertools.permutations(list(range(n))):", "+ if p[0] != 0:", "+ break", "+ tmp = 1", "+ for i in range(n - 1):", "+ tmp *= S[p[i]][p[i + 1]]", "+ ans += tmp", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.064357
0.045266
1.421755
[ "s721719592", "s880000301" ]
u656391577
p02761
python
s564997169
s199852668
20
18
3,064
3,064
Accepted
Accepted
10
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) Set = [] for i in range(M): Set.append(list(map(int, input().split()))) for i in range(10**N): num = str(i) if len(num) == N and all(num[s-1]==str(c) for s,c in Set): print(i) break else: print((-1)) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) Set = [list(map(int,input().split())) for i in range(M)] for i in range(10**N): num = str(i) if len(num) == N and all(num[s-1]==str(c) for s,c in Set): print(i) break else: print((-1)) if __name__ == '__main__': main()
21
19
419
390
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) Set = [] for i in range(M): Set.append(list(map(int, input().split()))) for i in range(10**N): num = str(i) if len(num) == N and all(num[s - 1] == str(c) for s, c in Set): print(i) break else: print((-1)) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) Set = [list(map(int, input().split())) for i in range(M)] for i in range(10**N): num = str(i) if len(num) == N and all(num[s - 1] == str(c) for s, c in Set): print(i) break else: print((-1)) if __name__ == "__main__": main()
false
9.52381
[ "- Set = []", "- for i in range(M):", "- Set.append(list(map(int, input().split())))", "+ Set = [list(map(int, input().split())) for i in range(M)]" ]
false
0.045605
0.045439
1.003663
[ "s564997169", "s199852668" ]
u514401521
p02708
python
s874943027
s276379772
152
116
9,200
9,184
Accepted
Accepted
23.68
N, K = list(map(int, input().split())) ans = 0 mod = 10**9+7 for i in range(K, N+2): _min = (i+1)*i//2 _max = ((N+1) + (N+1-i+1)) * i // 2 ans += (_max - _min + 1) % mod ans %= mod print(ans)
N, K = list(map(int, input().split())) M = 10**9 + 7 ans = 0 for i in range(K, N+2): _min = (i-1)*i//2 _max = (N + N-i+1) * i //2 ans += (_max - _min + 1) print((ans % M))
9
8
209
186
N, K = list(map(int, input().split())) ans = 0 mod = 10**9 + 7 for i in range(K, N + 2): _min = (i + 1) * i // 2 _max = ((N + 1) + (N + 1 - i + 1)) * i // 2 ans += (_max - _min + 1) % mod ans %= mod print(ans)
N, K = list(map(int, input().split())) M = 10**9 + 7 ans = 0 for i in range(K, N + 2): _min = (i - 1) * i // 2 _max = (N + N - i + 1) * i // 2 ans += _max - _min + 1 print((ans % M))
false
11.111111
[ "+M = 10**9 + 7", "-mod = 10**9 + 7", "- _min = (i + 1) * i // 2", "- _max = ((N + 1) + (N + 1 - i + 1)) * i // 2", "- ans += (_max - _min + 1) % mod", "- ans %= mod", "-print(ans)", "+ _min = (i - 1) * i // 2", "+ _max = (N + N - i + 1) * i // 2", "+ ans += _max - _min + 1", "+print((ans % M))" ]
false
0.322362
0.049543
6.506724
[ "s874943027", "s276379772" ]
u141610915
p03912
python
s475852678
s103731998
308
248
73,964
53,212
Accepted
Accepted
19.48
from collections import defaultdict as dd N, M = list(map(int, input().split())) c = list(map(int, input().split())) c.sort() m = dd(int) d = dd(int) for n in c: d[n] += 1 m[n % M] += 1 res = 0 for i in range(M): temp = min(m[i], m[(M - i) % M]) if i == (M - i) % M: temp = m[i] // 2 m[i] -= temp m[(M - i) % M] -= temp res += temp for i in range(N): n = c[i] if m[n % M] > 1: k = m[n % M] // 2 if d[n] > 1: temp = min(d[n] // 2, k) res += temp d[n] -= temp * 2 m[n % M] -= temp * 2 print(res)
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() m = [0] * M d = [0] * (max(a) + 1) for x in a: d[x] += 1 m[x % M] += 1 res = 0 for i in range(M): t = min(m[i], m[(M - i) % M]) if i == (M - i) % M: t = m[i] // 2 m[i] -= t m[(M - i) % M] -= t res += t for i in range(N): x = a[i] if m[x % M] > 1: k = m[x % M] // 2 if d[x] > 1: t = min(d[x] // 2, k) res += t d[x] -= t * 2 m[x % M] -= t * 2 print(res)
27
30
567
553
from collections import defaultdict as dd N, M = list(map(int, input().split())) c = list(map(int, input().split())) c.sort() m = dd(int) d = dd(int) for n in c: d[n] += 1 m[n % M] += 1 res = 0 for i in range(M): temp = min(m[i], m[(M - i) % M]) if i == (M - i) % M: temp = m[i] // 2 m[i] -= temp m[(M - i) % M] -= temp res += temp for i in range(N): n = c[i] if m[n % M] > 1: k = m[n % M] // 2 if d[n] > 1: temp = min(d[n] // 2, k) res += temp d[n] -= temp * 2 m[n % M] -= temp * 2 print(res)
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() m = [0] * M d = [0] * (max(a) + 1) for x in a: d[x] += 1 m[x % M] += 1 res = 0 for i in range(M): t = min(m[i], m[(M - i) % M]) if i == (M - i) % M: t = m[i] // 2 m[i] -= t m[(M - i) % M] -= t res += t for i in range(N): x = a[i] if m[x % M] > 1: k = m[x % M] // 2 if d[x] > 1: t = min(d[x] // 2, k) res += t d[x] -= t * 2 m[x % M] -= t * 2 print(res)
false
10
[ "-from collections import defaultdict as dd", "+import sys", "+input = sys.stdin.readline", "-c = list(map(int, input().split()))", "-c.sort()", "-m = dd(int)", "-d = dd(int)", "-for n in c:", "- d[n] += 1", "- m[n % M] += 1", "+a = list(map(int, input().split()))", "+a.sort()", "+m = [0] * M", "+d = [0] * (max(a) + 1)", "+for x in a:", "+ d[x] += 1", "+ m[x % M] += 1", "- temp = min(m[i], m[(M - i) % M])", "+ t = min(m[i], m[(M - i) % M])", "- temp = m[i] // 2", "- m[i] -= temp", "- m[(M - i) % M] -= temp", "- res += temp", "+ t = m[i] // 2", "+ m[i] -= t", "+ m[(M - i) % M] -= t", "+ res += t", "- n = c[i]", "- if m[n % M] > 1:", "- k = m[n % M] // 2", "- if d[n] > 1:", "- temp = min(d[n] // 2, k)", "- res += temp", "- d[n] -= temp * 2", "- m[n % M] -= temp * 2", "+ x = a[i]", "+ if m[x % M] > 1:", "+ k = m[x % M] // 2", "+ if d[x] > 1:", "+ t = min(d[x] // 2, k)", "+ res += t", "+ d[x] -= t * 2", "+ m[x % M] -= t * 2" ]
false
0.044489
0.151311
0.294026
[ "s475852678", "s103731998" ]
u548464743
p02844
python
s616478329
s013950905
562
166
9,324
10,264
Accepted
Accepted
70.46
n = int(eval(input())) num = eval(input()) password_list = [] initial_list = [] initial_list2 = [] initial_list3 = [] for i in range(len(num)-2): initial_list2 = [] if num[i] in initial_list: continue elif len(initial_list) == 10: break else: initial_list.append(num[i]) for j in range(i+1,len(num)-1): initial_list3 = [] if num[j] in initial_list2: continue elif len(initial_list2) == 10: break else: initial_list2.append(num[j]) for k in range(j+1,len(num)): if num[k] in initial_list3: continue elif len(initial_list3) == 10: break else: initial_list3.append(num[k]) target = num[i] + num[j] + num[k] if target not in password_list: password_list.append(target) print((len(password_list)))
n = int(eval(input())) num_list = list(map(int,eval(input()))) cnt = 0 for i in range(10): if i not in num_list: continue else: first_pwd = num_list.index(i) new_num_list = num_list[first_pwd + 1:] for j in range(10): if j not in new_num_list: continue else: second_pwd = new_num_list.index(j) new_new_num_list = new_num_list[second_pwd+1:] for k in range(10): if k not in new_new_num_list: continue else: cnt += 1 print(cnt)
36
24
1,114
655
n = int(eval(input())) num = eval(input()) password_list = [] initial_list = [] initial_list2 = [] initial_list3 = [] for i in range(len(num) - 2): initial_list2 = [] if num[i] in initial_list: continue elif len(initial_list) == 10: break else: initial_list.append(num[i]) for j in range(i + 1, len(num) - 1): initial_list3 = [] if num[j] in initial_list2: continue elif len(initial_list2) == 10: break else: initial_list2.append(num[j]) for k in range(j + 1, len(num)): if num[k] in initial_list3: continue elif len(initial_list3) == 10: break else: initial_list3.append(num[k]) target = num[i] + num[j] + num[k] if target not in password_list: password_list.append(target) print((len(password_list)))
n = int(eval(input())) num_list = list(map(int, eval(input()))) cnt = 0 for i in range(10): if i not in num_list: continue else: first_pwd = num_list.index(i) new_num_list = num_list[first_pwd + 1 :] for j in range(10): if j not in new_num_list: continue else: second_pwd = new_num_list.index(j) new_new_num_list = new_num_list[second_pwd + 1 :] for k in range(10): if k not in new_new_num_list: continue else: cnt += 1 print(cnt)
false
33.333333
[ "-num = eval(input())", "-password_list = []", "-initial_list = []", "-initial_list2 = []", "-initial_list3 = []", "-for i in range(len(num) - 2):", "- initial_list2 = []", "- if num[i] in initial_list:", "+num_list = list(map(int, eval(input())))", "+cnt = 0", "+for i in range(10):", "+ if i not in num_list:", "- elif len(initial_list) == 10:", "- break", "- initial_list.append(num[i])", "- for j in range(i + 1, len(num) - 1):", "- initial_list3 = []", "- if num[j] in initial_list2:", "+ first_pwd = num_list.index(i)", "+ new_num_list = num_list[first_pwd + 1 :]", "+ for j in range(10):", "+ if j not in new_num_list:", "- elif len(initial_list2) == 10:", "- break", "- initial_list2.append(num[j])", "- for k in range(j + 1, len(num)):", "- if num[k] in initial_list3:", "+ second_pwd = new_num_list.index(j)", "+ new_new_num_list = new_num_list[second_pwd + 1 :]", "+ for k in range(10):", "+ if k not in new_new_num_list:", "- elif len(initial_list3) == 10:", "- break", "- initial_list3.append(num[k])", "- target = num[i] + num[j] + num[k]", "- if target not in password_list:", "- password_list.append(target)", "-print((len(password_list)))", "+ cnt += 1", "+print(cnt)" ]
false
0.082636
0.046259
1.786379
[ "s616478329", "s013950905" ]
u950708010
p03472
python
s554355407
s694470728
1,932
221
12,784
12,892
Accepted
Accepted
88.56
from math import ceil n,h = (int(i) for i in input().split()) a = [] b = [0] for i in range(n): tmp1,tmp2= (int(i) for i in input().split()) a.append(tmp1) b.append(tmp2) a2 = sorted(a,reverse = True) b2 = sorted(b,reverse = True) count = 0 while h > 0: if a2[0] > b2[0]: tmp3 = ceil(h/a2[0]) count += tmp3 h -= tmp3*a2[0] else: count += 1 h -= b2[0] b2.pop(0) print(count)
import sys input = sys.stdin.readline from collections import deque import math def solve(): n,h = (int(i) for i in input().split()) a = [] b = [] for i in range(n): ta,tb = (int(i) for i in input().split()) a.append(ta) b.append(tb) amax = max(a) b = deque(sorted(b,reverse=True)) damage = 0 ct = 0 while damage < h: if len(b): throw = b[0] else: throw = -99 if throw > amax: throw = b.popleft() ct += 1 damage += throw continue else: sabun = h-damage ct += math.ceil(sabun/amax) damage += amax*math.ceil(sabun/amax) print(ct) solve()
22
34
427
680
from math import ceil n, h = (int(i) for i in input().split()) a = [] b = [0] for i in range(n): tmp1, tmp2 = (int(i) for i in input().split()) a.append(tmp1) b.append(tmp2) a2 = sorted(a, reverse=True) b2 = sorted(b, reverse=True) count = 0 while h > 0: if a2[0] > b2[0]: tmp3 = ceil(h / a2[0]) count += tmp3 h -= tmp3 * a2[0] else: count += 1 h -= b2[0] b2.pop(0) print(count)
import sys input = sys.stdin.readline from collections import deque import math def solve(): n, h = (int(i) for i in input().split()) a = [] b = [] for i in range(n): ta, tb = (int(i) for i in input().split()) a.append(ta) b.append(tb) amax = max(a) b = deque(sorted(b, reverse=True)) damage = 0 ct = 0 while damage < h: if len(b): throw = b[0] else: throw = -99 if throw > amax: throw = b.popleft() ct += 1 damage += throw continue else: sabun = h - damage ct += math.ceil(sabun / amax) damage += amax * math.ceil(sabun / amax) print(ct) solve()
false
35.294118
[ "-from math import ceil", "+import sys", "-n, h = (int(i) for i in input().split())", "-a = []", "-b = [0]", "-for i in range(n):", "- tmp1, tmp2 = (int(i) for i in input().split())", "- a.append(tmp1)", "- b.append(tmp2)", "-a2 = sorted(a, reverse=True)", "-b2 = sorted(b, reverse=True)", "-count = 0", "-while h > 0:", "- if a2[0] > b2[0]:", "- tmp3 = ceil(h / a2[0])", "- count += tmp3", "- h -= tmp3 * a2[0]", "- else:", "- count += 1", "- h -= b2[0]", "- b2.pop(0)", "-print(count)", "+input = sys.stdin.readline", "+from collections import deque", "+import math", "+", "+", "+def solve():", "+ n, h = (int(i) for i in input().split())", "+ a = []", "+ b = []", "+ for i in range(n):", "+ ta, tb = (int(i) for i in input().split())", "+ a.append(ta)", "+ b.append(tb)", "+ amax = max(a)", "+ b = deque(sorted(b, reverse=True))", "+ damage = 0", "+ ct = 0", "+ while damage < h:", "+ if len(b):", "+ throw = b[0]", "+ else:", "+ throw = -99", "+ if throw > amax:", "+ throw = b.popleft()", "+ ct += 1", "+ damage += throw", "+ continue", "+ else:", "+ sabun = h - damage", "+ ct += math.ceil(sabun / amax)", "+ damage += amax * math.ceil(sabun / amax)", "+ print(ct)", "+", "+", "+solve()" ]
false
0.085362
0.165826
0.514766
[ "s554355407", "s694470728" ]
u645250356
p03633
python
s646053736
s504526040
39
36
5,264
5,068
Accepted
Accepted
7.69
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,fractions mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def inpl_str(): return list(sys.stdin.readline().split()) def lcm(x, y): return (x * y) // fractions.gcd(x, y) n = inp() t = inpln(n) tmp = t[0] for i in range(n-1): tmp = lcm(tmp, t[i+1]) print(tmp)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,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() a = [inp() for _ in range(n)] now = a[0] for i in range(1,n): now = a[i]*now//fractions.gcd(a[i],now) print(now)
16
16
523
494
from collections import Counter, defaultdict import sys, heapq, bisect, math, itertools, string, queue, fractions mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def inpl_str(): return list(sys.stdin.readline().split()) def lcm(x, y): return (x * y) // fractions.gcd(x, y) n = inp() t = inpln(n) tmp = t[0] for i in range(n - 1): tmp = lcm(tmp, t[i + 1]) print(tmp)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify from bisect import bisect_left, bisect_right import sys, 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() a = [inp() for _ in range(n)] now = a[0] for i in range(1, n): now = a[i] * now // fractions.gcd(a[i], now) print(now)
false
0
[ "-from collections import Counter, defaultdict", "-import sys, heapq, bisect, math, itertools, string, queue, fractions", "+from collections import Counter, defaultdict, deque", "+from heapq import heappop, heappush, heapify", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "+sys.setrecursionlimit(10**8)", "+INF = float(\"inf\")", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def lcm(x, y):", "- return (x * y) // fractions.gcd(x, y)", "-", "-", "-t = inpln(n)", "-tmp = t[0]", "-for i in range(n - 1):", "- tmp = lcm(tmp, t[i + 1])", "-print(tmp)", "+a = [inp() for _ in range(n)]", "+now = a[0]", "+for i in range(1, n):", "+ now = a[i] * now // fractions.gcd(a[i], now)", "+print(now)" ]
false
0.103246
0.049484
2.086471
[ "s646053736", "s504526040" ]
u629614915
p02689
python
s498517427
s452770043
308
249
31,244
20,140
Accepted
Accepted
19.16
## import ## function definition ## main process if __name__ == '__main__': ## input N, M = list(map(int,input().split())) HEIGHT_LIST = list(map(int,input().split())) ROAD_LIST = [] for j in range(M): ROAD_LIST.append( tuple(map(int,input().split())) ) ## business logic ans = [1] * N for j in list(range(M)): point_a = ROAD_LIST[j][0] point_b = ROAD_LIST[j][1] point_a -= 1 point_b -= 1 height_a = HEIGHT_LIST[point_a] height_b = HEIGHT_LIST[point_b] if height_a < height_b: ans[point_a] = 0 elif height_a > height_b: ans[point_b] = 0 else: ans[point_a] = 0 ans[point_b] = 0 ## output print((sum(ans)))
## import ## function definition ## main process if __name__ == '__main__': N, M = list(map(int,input().split())) HEIGHT_LIST = list(map(int,input().split())) ans = [1] * N for j in range(M): a, b = list(map(int,input().split())) a -= 1 b -= 1 height_a = HEIGHT_LIST[a] height_b = HEIGHT_LIST[b] if height_a < height_b: ans[a] = 0 elif height_a > height_b: ans[b] = 0 else: ans[a] = 0 ans[b] = 0 print((sum(ans)))
38
27
840
573
## import ## function definition ## main process if __name__ == "__main__": ## input N, M = list(map(int, input().split())) HEIGHT_LIST = list(map(int, input().split())) ROAD_LIST = [] for j in range(M): ROAD_LIST.append(tuple(map(int, input().split()))) ## business logic ans = [1] * N for j in list(range(M)): point_a = ROAD_LIST[j][0] point_b = ROAD_LIST[j][1] point_a -= 1 point_b -= 1 height_a = HEIGHT_LIST[point_a] height_b = HEIGHT_LIST[point_b] if height_a < height_b: ans[point_a] = 0 elif height_a > height_b: ans[point_b] = 0 else: ans[point_a] = 0 ans[point_b] = 0 ## output print((sum(ans)))
## import ## function definition ## main process if __name__ == "__main__": N, M = list(map(int, input().split())) HEIGHT_LIST = list(map(int, input().split())) ans = [1] * N for j in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 height_a = HEIGHT_LIST[a] height_b = HEIGHT_LIST[b] if height_a < height_b: ans[a] = 0 elif height_a > height_b: ans[b] = 0 else: ans[a] = 0 ans[b] = 0 print((sum(ans)))
false
28.947368
[ "- ## input", "- ROAD_LIST = []", "+ ans = [1] * N", "- ROAD_LIST.append(tuple(map(int, input().split())))", "- ## business logic", "- ans = [1] * N", "- for j in list(range(M)):", "- point_a = ROAD_LIST[j][0]", "- point_b = ROAD_LIST[j][1]", "- point_a -= 1", "- point_b -= 1", "- height_a = HEIGHT_LIST[point_a]", "- height_b = HEIGHT_LIST[point_b]", "+ a, b = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ height_a = HEIGHT_LIST[a]", "+ height_b = HEIGHT_LIST[b]", "- ans[point_a] = 0", "+ ans[a] = 0", "- ans[point_b] = 0", "+ ans[b] = 0", "- ans[point_a] = 0", "- ans[point_b] = 0", "- ## output", "+ ans[a] = 0", "+ ans[b] = 0" ]
false
0.099976
0.114393
0.873968
[ "s498517427", "s452770043" ]
u167681750
p03006
python
s719133279
s900193938
159
34
3,060
3,064
Accepted
Accepted
78.62
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] count = 0 for i in range(n-1): for j in range(i+1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] count = max(count, sum((x-p,y-q) in set(xy) for x, y in xy)) print((n - count))
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] s_xy = set(xy) count = 0 for i in range(n-1): for j in range(i+1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] count = max(count, sum((x-p,y-q) in s_xy for x, y in s_xy)) print((n - count))
10
11
287
302
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] count = 0 for i in range(n - 1): for j in range(i + 1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] count = max(count, sum((x - p, y - q) in set(xy) for x, y in xy)) print((n - count))
n = int(eval(input())) xy = [tuple(map(int, input().split())) for _ in range(n)] s_xy = set(xy) count = 0 for i in range(n - 1): for j in range(i + 1, n): p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1] count = max(count, sum((x - p, y - q) in s_xy for x, y in s_xy)) print((n - count))
false
9.090909
[ "+s_xy = set(xy)", "- count = max(count, sum((x - p, y - q) in set(xy) for x, y in xy))", "+ count = max(count, sum((x - p, y - q) in s_xy for x, y in s_xy))" ]
false
0.052747
0.053029
0.994683
[ "s719133279", "s900193938" ]
u418149936
p02614
python
s740756347
s271545016
72
49
9,008
9,132
Accepted
Accepted
31.94
h, w, k = list(map(int, input().split(' '))) ls = [0] * h result = 0 for i in range(h): ls[i] = eval(input()) for i in range(1<<h): for j in range(1<<w): cnt = 0 for s in range(h): for t in range(w): if ((i>>s) & 1) & ((j>>t) & 1): if ls[s][t] == '#': cnt += 1 if cnt == k: result += 1 print(result)
H, W, K = list(map(int, input().split(' '))) ls = [] for i in range(H): ls.append(list(eval(input()))) rst = 0 for i in range(1 << H): for s in range(1 << W): cnt = 0 for j in range(H): if i>>j & 1: continue for t in range(W): if s>>t & 1: continue if ls[j][t] == '#': cnt += 1 if cnt == K: rst += 1 print(rst)
18
21
423
476
h, w, k = list(map(int, input().split(" "))) ls = [0] * h result = 0 for i in range(h): ls[i] = eval(input()) for i in range(1 << h): for j in range(1 << w): cnt = 0 for s in range(h): for t in range(w): if ((i >> s) & 1) & ((j >> t) & 1): if ls[s][t] == "#": cnt += 1 if cnt == k: result += 1 print(result)
H, W, K = list(map(int, input().split(" "))) ls = [] for i in range(H): ls.append(list(eval(input()))) rst = 0 for i in range(1 << H): for s in range(1 << W): cnt = 0 for j in range(H): if i >> j & 1: continue for t in range(W): if s >> t & 1: continue if ls[j][t] == "#": cnt += 1 if cnt == K: rst += 1 print(rst)
false
14.285714
[ "-h, w, k = list(map(int, input().split(\" \")))", "-ls = [0] * h", "-result = 0", "-for i in range(h):", "- ls[i] = eval(input())", "-for i in range(1 << h):", "- for j in range(1 << w):", "+H, W, K = list(map(int, input().split(\" \")))", "+ls = []", "+for i in range(H):", "+ ls.append(list(eval(input())))", "+rst = 0", "+for i in range(1 << H):", "+ for s in range(1 << W):", "- for s in range(h):", "- for t in range(w):", "- if ((i >> s) & 1) & ((j >> t) & 1):", "- if ls[s][t] == \"#\":", "- cnt += 1", "- if cnt == k:", "- result += 1", "-print(result)", "+ for j in range(H):", "+ if i >> j & 1:", "+ continue", "+ for t in range(W):", "+ if s >> t & 1:", "+ continue", "+ if ls[j][t] == \"#\":", "+ cnt += 1", "+ if cnt == K:", "+ rst += 1", "+print(rst)" ]
false
0.040815
0.041206
0.990505
[ "s740756347", "s271545016" ]
u606045429
p03659
python
s533109221
s592196338
173
124
23,800
24,168
Accepted
Accepted
28.32
N = int(eval(input())) A = [int(i) for i in input().split()] su = sum(A) x = 0 mi = 1e15 for a in A[:-1]: x += a mi = min(mi, abs(su - 2 * x)) print(mi)
from itertools import accumulate N = int(eval(input())) A = [int(i) for i in input().split()] *B, su = list(accumulate(A)) print((min(abs(su - 2 * b) for b in B)))
10
7
164
164
N = int(eval(input())) A = [int(i) for i in input().split()] su = sum(A) x = 0 mi = 1e15 for a in A[:-1]: x += a mi = min(mi, abs(su - 2 * x)) print(mi)
from itertools import accumulate N = int(eval(input())) A = [int(i) for i in input().split()] *B, su = list(accumulate(A)) print((min(abs(su - 2 * b) for b in B)))
false
30
[ "+from itertools import accumulate", "+", "-su = sum(A)", "-x = 0", "-mi = 1e15", "-for a in A[:-1]:", "- x += a", "- mi = min(mi, abs(su - 2 * x))", "-print(mi)", "+*B, su = list(accumulate(A))", "+print((min(abs(su - 2 * b) for b in B)))" ]
false
0.037682
0.036078
1.044447
[ "s533109221", "s592196338" ]
u086503932
p02984
python
s932303915
s250252043
163
126
23,556
23,620
Accepted
Accepted
22.7
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate def main(): N = int(eval(input())) A = list(map(int, input().split())) sumA = sum(A)//2 B = A odd = list(accumulate([0] + B[::2]+ B[1::2]))# 0+1, 2+3,... even = list(accumulate([0] + B[1::2]+ B[0::2]))# 1+2, 3+4,... # print(B,sumA) # print(odd) # print(even) ans = [None] * N for i in range(N): if i % 2 == 0:# evenから引く # print(even[N//2+i//2],even[i//2]) ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2])) else: ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2])) print((*ans)) if __name__ == "__main__": main()
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate def main(): N = int(eval(input())) A = list(map(int, input().split())) sumA = sum(A)//2 B = A odd = list(accumulate([0] + B[::2]+ B[1::2]))# 0+1, 2+3,... even = list(accumulate([0] + B[1::2]+ B[0::2]))# 1+2, 3+4,... # ans = [None] * N # for i in range(N): # if i % 2 == 0:# evenから引く # # print(even[N//2+i//2],even[i//2]) # ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2])) # else: # ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2])) # print(*ans) ## 別解 ## ans = [None] * N ans[0] = 2*(sumA - sum(A[1::2])) for i in range(N-1): ans[i+1] = 2*A[i] - ans[i] print((*ans)) if __name__ == "__main__": main()
28
32
800
913
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate def main(): N = int(eval(input())) A = list(map(int, input().split())) sumA = sum(A) // 2 B = A odd = list(accumulate([0] + B[::2] + B[1::2])) # 0+1, 2+3,... even = list(accumulate([0] + B[1::2] + B[0::2])) # 1+2, 3+4,... # print(B,sumA) # print(odd) # print(even) ans = [None] * N for i in range(N): if i % 2 == 0: # evenから引く # print(even[N//2+i//2],even[i//2]) ans[i] = 2 * (sumA - (even[N // 2 + i // 2] - even[i // 2])) else: ans[i] = 2 * (sumA - (odd[N // 2 + (i + 1) // 2] - odd[(i + 1) // 2])) print((*ans)) if __name__ == "__main__": main()
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate def main(): N = int(eval(input())) A = list(map(int, input().split())) sumA = sum(A) // 2 B = A odd = list(accumulate([0] + B[::2] + B[1::2])) # 0+1, 2+3,... even = list(accumulate([0] + B[1::2] + B[0::2])) # 1+2, 3+4,... # ans = [None] * N # for i in range(N): # if i % 2 == 0:# evenから引く # # print(even[N//2+i//2],even[i//2]) # ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2])) # else: # ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2])) # print(*ans) ## 別解 ## ans = [None] * N ans[0] = 2 * (sumA - sum(A[1::2])) for i in range(N - 1): ans[i + 1] = 2 * A[i] - ans[i] print((*ans)) if __name__ == "__main__": main()
false
12.5
[ "- # print(B,sumA)", "- # print(odd)", "- # print(even)", "+ # ans = [None] * N", "+ # for i in range(N):", "+ # if i % 2 == 0:# evenから引く", "+ # # print(even[N//2+i//2],even[i//2])", "+ # ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2]))", "+ # else:", "+ # ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2]))", "+ # print(*ans)", "+ ## 別解 ##", "- for i in range(N):", "- if i % 2 == 0: # evenから引く", "- # print(even[N//2+i//2],even[i//2])", "- ans[i] = 2 * (sumA - (even[N // 2 + i // 2] - even[i // 2]))", "- else:", "- ans[i] = 2 * (sumA - (odd[N // 2 + (i + 1) // 2] - odd[(i + 1) // 2]))", "+ ans[0] = 2 * (sumA - sum(A[1::2]))", "+ for i in range(N - 1):", "+ ans[i + 1] = 2 * A[i] - ans[i]" ]
false
0.043873
0.044089
0.995098
[ "s932303915", "s250252043" ]
u150984829
p02234
python
s122369231
s785902134
130
110
5,728
5,716
Accepted
Accepted
15.38
def s(): n=int(eval(input()))+1 e=[input().split()for _ in[0]*~-n] p=[int(e[0][0])]+list(int(x[1])for x in e) m=[[0]*n for _ in[0]*n] for l in range(2,n): for i in range(1,n-l+1): j=i+l-1;m[i][j]=1e6 for k in range(i,j):m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]) print((m[1][n-1])) if'__main__'==__name__:s()
def s(): n=int(eval(input()))+1 e=[input().split()for _ in[0]*~-n] p=[int(e[0][0])]+list(int(x[1])for x in e) m=[[0]*n for _ in[0]*n] for i in range(n): for r in range(n-i-1): c=r+i+1 for j in range(r+1,c): x=m[r][j]+m[j][c]+p[r]*p[j]*p[c] if 1>m[r][c]or m[r][c]>x:m[r][c]=x print((m[r][c])) if'__main__'==__name__:s()
11
13
339
346
def s(): n = int(eval(input())) + 1 e = [input().split() for _ in [0] * ~-n] p = [int(e[0][0])] + list(int(x[1]) for x in e) m = [[0] * n for _ in [0] * n] for l in range(2, n): for i in range(1, n - l + 1): j = i + l - 1 m[i][j] = 1e6 for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]) print((m[1][n - 1])) if "__main__" == __name__: s()
def s(): n = int(eval(input())) + 1 e = [input().split() for _ in [0] * ~-n] p = [int(e[0][0])] + list(int(x[1]) for x in e) m = [[0] * n for _ in [0] * n] for i in range(n): for r in range(n - i - 1): c = r + i + 1 for j in range(r + 1, c): x = m[r][j] + m[j][c] + p[r] * p[j] * p[c] if 1 > m[r][c] or m[r][c] > x: m[r][c] = x print((m[r][c])) if "__main__" == __name__: s()
false
15.384615
[ "- for l in range(2, n):", "- for i in range(1, n - l + 1):", "- j = i + l - 1", "- m[i][j] = 1e6", "- for k in range(i, j):", "- m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])", "- print((m[1][n - 1]))", "+ for i in range(n):", "+ for r in range(n - i - 1):", "+ c = r + i + 1", "+ for j in range(r + 1, c):", "+ x = m[r][j] + m[j][c] + p[r] * p[j] * p[c]", "+ if 1 > m[r][c] or m[r][c] > x:", "+ m[r][c] = x", "+ print((m[r][c]))" ]
false
0.039865
0.037157
1.072887
[ "s122369231", "s785902134" ]
u192154323
p03575
python
s856479413
s780619409
25
23
3,316
3,316
Accepted
Accepted
8
from collections import deque n,m = list(map(int,input().split())) edge_ls = [0] * m for i in range(m): a,b = list(map(int,input().split())) edge_ls[i] = [a,b] class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ''' xとyは-=1して使うのが基本 ''' x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) edge_q = deque(edge_ls) num_bridge = 0 for i in range(m): tar = edge_q.popleft() uf = UnionFind(n) for a,b in edge_q: a -= 1 b -= 1 uf.union(a,b) if not uf.group_count() == 1: num_bridge += 1 edge_q.append(tar) print(num_bridge)
from collections import deque num_ver, num_edge = list(map(int,input().split())) edges_ls = [0] * num_edge for i in range(num_edge): a,b = list(map(int,input().split())) a -= 1 b -= 1 edges_ls[i] = [a,b] num_bridge = 0 for ind_take_edge in range(num_edge): graph_ls = [[] for _ in range(num_ver)] # graph_lsを作る for ind_edge in range(num_edge): if ind_edge != ind_take_edge: a,b = edges_ls[ind_edge] graph_ls[a].append(b) graph_ls[b].append(a) # 0からdfsしてdone_lsを仕上げていく done_ls = [0] * num_ver queue = deque() queue.append(0) while queue: now = queue.pop() done_ls[now] = 1 for nex in graph_ls[now]: if done_ls[nex] != 1: queue.append(nex) if sum(done_ls) != num_ver: num_bridge += 1 print(num_bridge)
68
39
1,697
915
from collections import deque n, m = list(map(int, input().split())) edge_ls = [0] * m for i in range(m): a, b = list(map(int, input().split())) edge_ls[i] = [a, b] class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): """ xとyは-=1して使うのが基本 """ x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) edge_q = deque(edge_ls) num_bridge = 0 for i in range(m): tar = edge_q.popleft() uf = UnionFind(n) for a, b in edge_q: a -= 1 b -= 1 uf.union(a, b) if not uf.group_count() == 1: num_bridge += 1 edge_q.append(tar) print(num_bridge)
from collections import deque num_ver, num_edge = list(map(int, input().split())) edges_ls = [0] * num_edge for i in range(num_edge): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges_ls[i] = [a, b] num_bridge = 0 for ind_take_edge in range(num_edge): graph_ls = [[] for _ in range(num_ver)] # graph_lsを作る for ind_edge in range(num_edge): if ind_edge != ind_take_edge: a, b = edges_ls[ind_edge] graph_ls[a].append(b) graph_ls[b].append(a) # 0からdfsしてdone_lsを仕上げていく done_ls = [0] * num_ver queue = deque() queue.append(0) while queue: now = queue.pop() done_ls[now] = 1 for nex in graph_ls[now]: if done_ls[nex] != 1: queue.append(nex) if sum(done_ls) != num_ver: num_bridge += 1 print(num_bridge)
false
42.647059
[ "-n, m = list(map(int, input().split()))", "-edge_ls = [0] * m", "-for i in range(m):", "+num_ver, num_edge = list(map(int, input().split()))", "+edges_ls = [0] * num_edge", "+for i in range(num_edge):", "- edge_ls[i] = [a, b]", "-", "-", "-class UnionFind:", "- def __init__(self, n):", "- self.n = n", "- self.parents = [-1] * n", "-", "- def find(self, x):", "- if self.parents[x] < 0:", "- return x", "- else:", "- self.parents[x] = self.find(self.parents[x])", "- return self.parents[x]", "-", "- def union(self, x, y):", "- \"\"\"", "- xとyは-=1して使うのが基本", "- \"\"\"", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- if self.parents[x] > self.parents[y]:", "- x, y = y, x", "- self.parents[x] += self.parents[y]", "- self.parents[y] = x", "-", "- def size(self, x):", "- return -self.parents[self.find(x)]", "-", "- def same(self, x, y):", "- return self.find(x) == self.find(y)", "-", "- def members(self, x):", "- root = self.find(x)", "- return [i for i in range(self.n) if self.find(i) == root]", "-", "- def roots(self):", "- return [i for i, x in enumerate(self.parents) if x < 0]", "-", "- def group_count(self):", "- return len(self.roots())", "-", "- def all_group_members(self):", "- return {r: self.members(r) for r in self.roots()}", "-", "- def __str__(self):", "- return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "-", "-", "-edge_q = deque(edge_ls)", "+ a -= 1", "+ b -= 1", "+ edges_ls[i] = [a, b]", "-for i in range(m):", "- tar = edge_q.popleft()", "- uf = UnionFind(n)", "- for a, b in edge_q:", "- a -= 1", "- b -= 1", "- uf.union(a, b)", "- if not uf.group_count() == 1:", "+for ind_take_edge in range(num_edge):", "+ graph_ls = [[] for _ in range(num_ver)]", "+ # graph_lsを作る", "+ for ind_edge in range(num_edge):", "+ if ind_edge != ind_take_edge:", "+ a, b = edges_ls[ind_edge]", "+ graph_ls[a].append(b)", "+ graph_ls[b].append(a)", "+ # 0からdfsしてdone_lsを仕上げていく", "+ done_ls = [0] * num_ver", "+ queue = deque()", "+ queue.append(0)", "+ while queue:", "+ now = queue.pop()", "+ done_ls[now] = 1", "+ for nex in graph_ls[now]:", "+ if done_ls[nex] != 1:", "+ queue.append(nex)", "+ if sum(done_ls) != num_ver:", "- edge_q.append(tar)" ]
false
0.09754
0.060583
1.610027
[ "s856479413", "s780619409" ]
u301624971
p03427
python
s887834936
s016443179
22
18
3,064
3,064
Accepted
Accepted
18.18
def myAnswer(N:int)->int: K = len(str(N)) #桁数 if(K == 1):return N c = N // 10**(K-1) #最上位の桁の数 if((c*10**(K-1) + int("9"*(K-1)))<= N): return c + 9 *(K - 1) else: return c + 9 *(K - 1) -1 def modelAnswer(): tmp=1 def main(): N = int(eval(input())) print((myAnswer(N))) if __name__ == '__main__': main()
def myAnswer(N:int)->int: length = len(str(N)) if(length == 1): return N l = list(str(N)) tmp = 0 for n in l[1:]: tmp += int(n) total = length * 9 if(tmp == total - 9): return tmp + int(l[0]) else: total += -9 + int(l[0]) - 1 return total def modelAnswer(): tmp=1 def main(): N = int(eval(input())) print((myAnswer(N))) if __name__ == '__main__': main()
19
21
355
426
def myAnswer(N: int) -> int: K = len(str(N)) # 桁数 if K == 1: return N c = N // 10 ** (K - 1) # 最上位の桁の数 if (c * 10 ** (K - 1) + int("9" * (K - 1))) <= N: return c + 9 * (K - 1) else: return c + 9 * (K - 1) - 1 def modelAnswer(): tmp = 1 def main(): N = int(eval(input())) print((myAnswer(N))) if __name__ == "__main__": main()
def myAnswer(N: int) -> int: length = len(str(N)) if length == 1: return N l = list(str(N)) tmp = 0 for n in l[1:]: tmp += int(n) total = length * 9 if tmp == total - 9: return tmp + int(l[0]) else: total += -9 + int(l[0]) - 1 return total def modelAnswer(): tmp = 1 def main(): N = int(eval(input())) print((myAnswer(N))) if __name__ == "__main__": main()
false
9.52381
[ "- K = len(str(N)) # 桁数", "- if K == 1:", "+ length = len(str(N))", "+ if length == 1:", "- c = N // 10 ** (K - 1) # 最上位の桁の数", "- if (c * 10 ** (K - 1) + int(\"9\" * (K - 1))) <= N:", "- return c + 9 * (K - 1)", "+ l = list(str(N))", "+ tmp = 0", "+ for n in l[1:]:", "+ tmp += int(n)", "+ total = length * 9", "+ if tmp == total - 9:", "+ return tmp + int(l[0])", "- return c + 9 * (K - 1) - 1", "+ total += -9 + int(l[0]) - 1", "+ return total" ]
false
0.034591
0.034496
1.002752
[ "s887834936", "s016443179" ]
u721316601
p03045
python
s627281016
s240666204
611
518
7,088
27,368
Accepted
Accepted
15.22
def search(n): idx = n while A[n-1] != n: n = A[n-1] A[idx-1] = n return n N, M = list(map(int, input().split())) A = [i for i in range(1, N+1)] ans = 0 for i in range(M): X, Y, Z = list(map(int, input().split())) X_root, Y_root = search(X), search(Y) if X_root != Y_root: A[X_root-1] = Y_root ans += 1 print((N-ans))
import sys input = sys.stdin.readline def search(x, y): while root[x] != x: x = root[x] while root[y] != y: y = root[y] return x, y def rebuild(x, y, r): while root[x] != r: x, root[x] = root[x], r while root[y] != r: y, root[y] = root[y], r N, M = list(map(int, input().split())) root = {i:i for i in range(1, N+1)} size = {i:1 for i in range(1, N+1)} ans = 0 for i in range(M): x, y, z = list(map(int, input().split())) x_r, y_r = search(x, y) if x_r == y_r: continue root[y_r] = x_r size[x_r] += size[y_r] if size[x_r] > 10: rebuild(x, y, x_r) ans += 1 print((N-ans))
21
32
392
661
def search(n): idx = n while A[n - 1] != n: n = A[n - 1] A[idx - 1] = n return n N, M = list(map(int, input().split())) A = [i for i in range(1, N + 1)] ans = 0 for i in range(M): X, Y, Z = list(map(int, input().split())) X_root, Y_root = search(X), search(Y) if X_root != Y_root: A[X_root - 1] = Y_root ans += 1 print((N - ans))
import sys input = sys.stdin.readline def search(x, y): while root[x] != x: x = root[x] while root[y] != y: y = root[y] return x, y def rebuild(x, y, r): while root[x] != r: x, root[x] = root[x], r while root[y] != r: y, root[y] = root[y], r N, M = list(map(int, input().split())) root = {i: i for i in range(1, N + 1)} size = {i: 1 for i in range(1, N + 1)} ans = 0 for i in range(M): x, y, z = list(map(int, input().split())) x_r, y_r = search(x, y) if x_r == y_r: continue root[y_r] = x_r size[x_r] += size[y_r] if size[x_r] > 10: rebuild(x, y, x_r) ans += 1 print((N - ans))
false
34.375
[ "-def search(n):", "- idx = n", "- while A[n - 1] != n:", "- n = A[n - 1]", "- A[idx - 1] = n", "- return n", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def search(x, y):", "+ while root[x] != x:", "+ x = root[x]", "+ while root[y] != y:", "+ y = root[y]", "+ return x, y", "+", "+", "+def rebuild(x, y, r):", "+ while root[x] != r:", "+ x, root[x] = root[x], r", "+ while root[y] != r:", "+ y, root[y] = root[y], r", "-A = [i for i in range(1, N + 1)]", "+root = {i: i for i in range(1, N + 1)}", "+size = {i: 1 for i in range(1, N + 1)}", "- X, Y, Z = list(map(int, input().split()))", "- X_root, Y_root = search(X), search(Y)", "- if X_root != Y_root:", "- A[X_root - 1] = Y_root", "- ans += 1", "+ x, y, z = list(map(int, input().split()))", "+ x_r, y_r = search(x, y)", "+ if x_r == y_r:", "+ continue", "+ root[y_r] = x_r", "+ size[x_r] += size[y_r]", "+ if size[x_r] > 10:", "+ rebuild(x, y, x_r)", "+ ans += 1" ]
false
0.060395
0.069135
0.873577
[ "s627281016", "s240666204" ]
u235376569
p02983
python
s015180833
s482073238
77
66
3,060
9,176
Accepted
Accepted
14.29
import sys L,R=[int(x) for x in input().strip().split()] tmp=10**9+1 ans=10**9+1 for i in range(L,R,1): for j in range(L+1,R+1,1): if i<j: ans=min((i*j)%2019,ans) if ans==0: print((0)) sys.exit() print(ans) # 332701087 1753412895
l,r=list(map(int,input().split())) import sys mod=2019 ans=float('inf') for i in range(l,r+1): for j in range(i+1,r+1): ans=min((i*j)%mod,ans) if ans==0: print((0)) sys.exit() print(ans)
18
12
285
212
import sys L, R = [int(x) for x in input().strip().split()] tmp = 10**9 + 1 ans = 10**9 + 1 for i in range(L, R, 1): for j in range(L + 1, R + 1, 1): if i < j: ans = min((i * j) % 2019, ans) if ans == 0: print((0)) sys.exit() print(ans) # 332701087 1753412895
l, r = list(map(int, input().split())) import sys mod = 2019 ans = float("inf") for i in range(l, r + 1): for j in range(i + 1, r + 1): ans = min((i * j) % mod, ans) if ans == 0: print((0)) sys.exit() print(ans)
false
33.333333
[ "+l, r = list(map(int, input().split()))", "-L, R = [int(x) for x in input().strip().split()]", "-tmp = 10**9 + 1", "-ans = 10**9 + 1", "-for i in range(L, R, 1):", "- for j in range(L + 1, R + 1, 1):", "- if i < j:", "- ans = min((i * j) % 2019, ans)", "- if ans == 0:", "- print((0))", "- sys.exit()", "+mod = 2019", "+ans = float(\"inf\")", "+for i in range(l, r + 1):", "+ for j in range(i + 1, r + 1):", "+ ans = min((i * j) % mod, ans)", "+ if ans == 0:", "+ print((0))", "+ sys.exit()", "-# 332701087 1753412895" ]
false
0.036905
0.038655
0.954724
[ "s015180833", "s482073238" ]
u989345508
p03494
python
s597947812
s491602673
169
19
38,768
2,940
Accepted
Accepted
88.76
n=int(eval(input())) a=list(map(int,input().split())) ans=0 def check_all(): global a,n for i in range(n): if a[i]%2!=0: return False return True while check_all(): ans+=1 for i in range(n): a[i]//=2 print(ans)
n=int(eval(input())) a=list(map(int,input().split())) ans=0 while all(i%2==0 for i in a): ans+=1 for j in range(n): a[j]//=2 print(ans)
14
9
266
155
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 def check_all(): global a, n for i in range(n): if a[i] % 2 != 0: return False return True while check_all(): ans += 1 for i in range(n): a[i] //= 2 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 while all(i % 2 == 0 for i in a): ans += 1 for j in range(n): a[j] //= 2 print(ans)
false
35.714286
[ "-", "-", "-def check_all():", "- global a, n", "- for i in range(n):", "- if a[i] % 2 != 0:", "- return False", "- return True", "-", "-", "-while check_all():", "+while all(i % 2 == 0 for i in a):", "- for i in range(n):", "- a[i] //= 2", "+ for j in range(n):", "+ a[j] //= 2" ]
false
0.052485
0.034954
1.501564
[ "s597947812", "s491602673" ]
u912237403
p00028
python
s512049873
s703680107
20
10
4,216
4,212
Accepted
Accepted
50
d=[0 for i in range(101)] while True: try: n=eval(input()) d[n]+=1 except: break for e in [i for i,e in enumerate(d) if e==max(d)]: print(e)
d=[0]*101 while True: try: n=eval(input()) d[n]+=1 except: break tmp=max(d) for i in range(101): if d[i]==tmp: print(i)
11
12
181
161
d = [0 for i in range(101)] while True: try: n = eval(input()) d[n] += 1 except: break for e in [i for i, e in enumerate(d) if e == max(d)]: print(e)
d = [0] * 101 while True: try: n = eval(input()) d[n] += 1 except: break tmp = max(d) for i in range(101): if d[i] == tmp: print(i)
false
8.333333
[ "-d = [0 for i in range(101)]", "+d = [0] * 101", "-for e in [i for i, e in enumerate(d) if e == max(d)]:", "- print(e)", "+tmp = max(d)", "+for i in range(101):", "+ if d[i] == tmp:", "+ print(i)" ]
false
0.04446
0.00825
5.388823
[ "s512049873", "s703680107" ]
u761638117
p02887
python
s397459955
s312117389
50
43
3,956
3,956
Accepted
Accepted
14
n = int(eval(input())) colors = eval(input()) i = 0 leght = n result = list(colors[0]) for i in range(n-1): if colors[i] != colors[i+1]: result.append(colors[i+1]) print((len(result)))
n = int(eval(input())) str = eval(input()) slim = [str[0]] for i in range(n): if str[i] != slim[-1]: slim.append(str[i]) print((len(slim)))
12
8
193
141
n = int(eval(input())) colors = eval(input()) i = 0 leght = n result = list(colors[0]) for i in range(n - 1): if colors[i] != colors[i + 1]: result.append(colors[i + 1]) print((len(result)))
n = int(eval(input())) str = eval(input()) slim = [str[0]] for i in range(n): if str[i] != slim[-1]: slim.append(str[i]) print((len(slim)))
false
33.333333
[ "-colors = eval(input())", "-i = 0", "-leght = n", "-result = list(colors[0])", "-for i in range(n - 1):", "- if colors[i] != colors[i + 1]:", "- result.append(colors[i + 1])", "-print((len(result)))", "+str = eval(input())", "+slim = [str[0]]", "+for i in range(n):", "+ if str[i] != slim[-1]:", "+ slim.append(str[i])", "+print((len(slim)))" ]
false
0.074159
0.089432
0.829226
[ "s397459955", "s312117389" ]
u200887663
p02995
python
s155994964
s449458667
35
30
5,048
9,000
Accepted
Accepted
14.29
#n=int(input()) a,b,c,d=list(map(int,input().split())) #l=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] import fractions lcm=(c*d)//fractions.gcd(c,d)#最小公倍数 brng=b-(b//c+b//d)+b//lcm arng=(a-1)-((a-1)//c+(a-1)//d)+(a-1)//lcm ans=brng-arng print(ans)
#n=int(input()) a,b,c,d=list(map(int,input().split())) #t=int(input()) #al=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] import math lcm=(c//math.gcd(c,d))*d #最小公倍数 cnum=b//c-(a-1)//c dnum=b//d-(a-1)//d cdnum=b//lcm-(a-1)//lcm ans=b-a+1-(cnum+dnum)+cdnum print(ans)
11
15
293
316
# n=int(input()) a, b, c, d = list(map(int, input().split())) # l=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] import fractions lcm = (c * d) // fractions.gcd(c, d) # 最小公倍数 brng = b - (b // c + b // d) + b // lcm arng = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // lcm ans = brng - arng print(ans)
# n=int(input()) a, b, c, d = list(map(int, input().split())) # t=int(input()) # al=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] import math lcm = (c // math.gcd(c, d)) * d # 最小公倍数 cnum = b // c - (a - 1) // c dnum = b // d - (a - 1) // d cdnum = b // lcm - (a - 1) // lcm ans = b - a + 1 - (cnum + dnum) + cdnum print(ans)
false
26.666667
[ "-# l=list(map(int,input().split()))", "+# t=int(input())", "+# al=list(map(int,input().split()))", "-import fractions", "+import math", "-lcm = (c * d) // fractions.gcd(c, d) # 最小公倍数", "-brng = b - (b // c + b // d) + b // lcm", "-arng = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // lcm", "-ans = brng - arng", "+lcm = (c // math.gcd(c, d)) * d # 最小公倍数", "+cnum = b // c - (a - 1) // c", "+dnum = b // d - (a - 1) // d", "+cdnum = b // lcm - (a - 1) // lcm", "+ans = b - a + 1 - (cnum + dnum) + cdnum" ]
false
0.050342
0.036767
1.369206
[ "s155994964", "s449458667" ]
u407160848
p02698
python
s766684891
s689934525
1,409
1,201
366,540
350,892
Accepted
Accepted
14.76
from bisect import bisect_left import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) INF = 999999999999999999999999 n = int(input()) A = [-INF] + get_nums_l() log(n) log(A) edges = [ [] for _ in range(n+1) ] for _ in range(n-1): #for line in map(lambda s: s.strip(), sys.stdin.readlines()): line = input().strip() log(line) u,v = map(int, line.split()) edges[u].append(v) edges[v].append(u) def dfs(dp, u, p=None): # log(u) # log(dp) # dpの中でA[u]以上の値が入っている最小のindex i = bisect_left(dp, A[u]) old = dp[i] dp[i] = A[u] # 有効値(INF以外)が入っている最大のindex ans[u] = bisect_left(dp, INF) - 1 for v in edges[u]: if v == p: continue dfs(dp, v, u) # 巻き戻し dp[i] = old # ans[i] = ノード1からノードiへの経路中の最長増加部分列長 ans = [0] * (n+1) # dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小 # dp[0]は使用しないので負の無限大を入れておく dp = [INF] * (n+1) dp[0] = -INF dfs(dp, 1, None) for i in range(1, n+1): print(ans[i])
from bisect import bisect_left import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) INF = 999999999999999999999999 n = int(input()) A = [-INF] + get_nums_l() # log(n) # log(A) edges = [ [] for _ in range(n+1) ] for _ in range(n-1): #for line in map(lambda s: s.strip(), sys.stdin.readlines()): line = input().strip() # log(line) u,v = map(int, line.split()) edges[u].append(v) edges[v].append(u) def dfs(dp, u, p=None): # log(u) # log(dp) # dpの中でA[u]以上の値が入っている最小のindex i = bisect_left(dp, A[u]) old = dp[i] dp[i] = A[u] # 有効値(INF以外)が入っている最大のindex ans[u] = bisect_left(dp, INF) - 1 for v in edges[u]: if v == p: continue dfs(dp, v, u) # 巻き戻し dp[i] = old # ans[i] = ノード1からノードiへの経路中の最長増加部分列長 ans = [0] * (n+1) # dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小 # dp[0]は使用しないので負の無限大を入れておく dp = [INF] * (n+1) dp[0] = -INF dfs(dp, 1, None) for i in range(1, n+1): print(ans[i])
63
64
1,197
1,227
from bisect import bisect_left import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) INF = 999999999999999999999999 n = int(input()) A = [-INF] + get_nums_l() log(n) log(A) edges = [[] for _ in range(n + 1)] for _ in range(n - 1): # for line in map(lambda s: s.strip(), sys.stdin.readlines()): line = input().strip() log(line) u, v = map(int, line.split()) edges[u].append(v) edges[v].append(u) def dfs(dp, u, p=None): # log(u) # log(dp) # dpの中でA[u]以上の値が入っている最小のindex i = bisect_left(dp, A[u]) old = dp[i] dp[i] = A[u] # 有効値(INF以外)が入っている最大のindex ans[u] = bisect_left(dp, INF) - 1 for v in edges[u]: if v == p: continue dfs(dp, v, u) # 巻き戻し dp[i] = old # ans[i] = ノード1からノードiへの経路中の最長増加部分列長 ans = [0] * (n + 1) # dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小 # dp[0]は使用しないので負の無限大を入れておく dp = [INF] * (n + 1) dp[0] = -INF dfs(dp, 1, None) for i in range(1, n + 1): print(ans[i])
from bisect import bisect_left import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) INF = 999999999999999999999999 n = int(input()) A = [-INF] + get_nums_l() # log(n) # log(A) edges = [[] for _ in range(n + 1)] for _ in range(n - 1): # for line in map(lambda s: s.strip(), sys.stdin.readlines()): line = input().strip() # log(line) u, v = map(int, line.split()) edges[u].append(v) edges[v].append(u) def dfs(dp, u, p=None): # log(u) # log(dp) # dpの中でA[u]以上の値が入っている最小のindex i = bisect_left(dp, A[u]) old = dp[i] dp[i] = A[u] # 有効値(INF以外)が入っている最大のindex ans[u] = bisect_left(dp, INF) - 1 for v in edges[u]: if v == p: continue dfs(dp, v, u) # 巻き戻し dp[i] = old # ans[i] = ノード1からノードiへの経路中の最長増加部分列長 ans = [0] * (n + 1) # dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小 # dp[0]は使用しないので負の無限大を入れておく dp = [INF] * (n + 1) dp[0] = -INF dfs(dp, 1, None) for i in range(1, n + 1): print(ans[i])
false
1.5625
[ "-input = sys.stdin.readline", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "-log(n)", "-log(A)", "+# log(n)", "+# log(A)", "- log(line)", "+ # log(line)" ]
false
0.037833
0.041182
0.918685
[ "s766684891", "s689934525" ]
u685263709
p03038
python
s591978271
s861612914
967
576
103,832
33,784
Accepted
Accepted
40.43
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1], reverse=True) if N == 1: print((max(A[0], BC[0][1]))) quit() heapq.heapify(A) for b, c in BC: a = A[0] if a >= c: continue else: curPopped = 0 while curPopped < b: a = heapq.heappop(A) if a >= c: heapq.heappush(A, a) break curPopped += 1 for i in range(curPopped): heapq.heappush(A, c) print((sum(A))) """ import bisect N, M = map(int, input().split()) A = sorted(list(map(int, input().split()))) BC = [list(map(int, input().split())) for i in range(M)] if N == 1: print(max(A[0], BC[0][1])) quit() for b, c in BC: a = A[0] if a >= c: continue else: l = bisect.bisect_left(A, c) print(l) l = min(b, l) A = A[l:] + [c] * l print(l, A) print(sum(A)) """
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1], reverse=True) if N == 1: print((max(A[0], BC[0][1]))) quit() heapq.heapify(A) for b, c in BC: a = A[0] if a >= c: continue else: curPopped = 0 while curPopped < b: a = heapq.heappop(A) if a >= c: heapq.heappush(A, a) break curPopped += 1 for i in range(curPopped): heapq.heappush(A, c) print((sum(A)))
51
27
1,072
627
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = sorted( [list(map(int, input().split())) for i in range(M)], key=lambda x: x[1], reverse=True, ) if N == 1: print((max(A[0], BC[0][1]))) quit() heapq.heapify(A) for b, c in BC: a = A[0] if a >= c: continue else: curPopped = 0 while curPopped < b: a = heapq.heappop(A) if a >= c: heapq.heappush(A, a) break curPopped += 1 for i in range(curPopped): heapq.heappush(A, c) print((sum(A))) """ import bisect N, M = map(int, input().split()) A = sorted(list(map(int, input().split()))) BC = [list(map(int, input().split())) for i in range(M)] if N == 1: print(max(A[0], BC[0][1])) quit() for b, c in BC: a = A[0] if a >= c: continue else: l = bisect.bisect_left(A, c) print(l) l = min(b, l) A = A[l:] + [c] * l print(l, A) print(sum(A)) """
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = sorted( [list(map(int, input().split())) for i in range(M)], key=lambda x: x[1], reverse=True, ) if N == 1: print((max(A[0], BC[0][1]))) quit() heapq.heapify(A) for b, c in BC: a = A[0] if a >= c: continue else: curPopped = 0 while curPopped < b: a = heapq.heappop(A) if a >= c: heapq.heappush(A, a) break curPopped += 1 for i in range(curPopped): heapq.heappush(A, c) print((sum(A)))
false
47.058824
[ "-\"\"\"", "-import bisect", "-N, M = map(int, input().split())", "-A = sorted(list(map(int, input().split())))", "-BC = [list(map(int, input().split())) for i in range(M)]", "-if N == 1:", "- print(max(A[0], BC[0][1]))", "- quit()", "-for b, c in BC:", "- a = A[0]", "- if a >= c:", "- continue", "- else:", "- l = bisect.bisect_left(A, c)", "- print(l)", "- l = min(b, l)", "- A = A[l:] + [c] * l", "- print(l, A)", "-print(sum(A))", "-\"\"\"" ]
false
0.041061
0.040973
1.002142
[ "s591978271", "s861612914" ]
u936985471
p02936
python
s053934585
s746628106
856
782
65,932
67,328
Accepted
Accepted
8.64
import sys readline = sys.stdin.readline N,Q = list(map(int,readline().split())) G = [[] for i in range(N)] for i in range(N - 1): a,b = list(map(int,readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0 for i in range(N)] for i in range(Q): p,x = list(map(int,readline().split())) P[p - 1] += x stack = [[0, 0, -1]] while stack: v,point,parent = stack.pop() P[v] += point for child in G[v]: if child == parent: continue stack.append([child,P[v],v]) print((*P))
import sys readline = sys.stdin.readline N,Q = list(map(int,readline().split())) G = [[] for i in range(N)] for i in range(N - 1): a,b = list(map(int,readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N for i in range(Q): p,x = list(map(int,readline().split())) P[p - 1] += x ans = [0] * N stack = [] # 頂点, 親, そこまでの点数 stack.append([0, -1, 0]) while stack: v,parent,point = stack.pop() point += P[v] ans[v] = point for child in G[v]: if child == parent: continue stack.append([child, v, point]) print((*ans))
25
31
523
585
import sys readline = sys.stdin.readline N, Q = list(map(int, readline().split())) G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0 for i in range(N)] for i in range(Q): p, x = list(map(int, readline().split())) P[p - 1] += x stack = [[0, 0, -1]] while stack: v, point, parent = stack.pop() P[v] += point for child in G[v]: if child == parent: continue stack.append([child, P[v], v]) print((*P))
import sys readline = sys.stdin.readline N, Q = list(map(int, readline().split())) G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N for i in range(Q): p, x = list(map(int, readline().split())) P[p - 1] += x ans = [0] * N stack = [] # 頂点, 親, そこまでの点数 stack.append([0, -1, 0]) while stack: v, parent, point = stack.pop() point += P[v] ans[v] = point for child in G[v]: if child == parent: continue stack.append([child, v, point]) print((*ans))
false
19.354839
[ "-P = [0 for i in range(N)]", "+P = [0] * N", "-stack = [[0, 0, -1]]", "+ans = [0] * N", "+stack = []", "+# 頂点, 親, そこまでの点数", "+stack.append([0, -1, 0])", "- v, point, parent = stack.pop()", "- P[v] += point", "+ v, parent, point = stack.pop()", "+ point += P[v]", "+ ans[v] = point", "- stack.append([child, P[v], v])", "-print((*P))", "+ stack.append([child, v, point])", "+print((*ans))" ]
false
0.046424
0.038479
1.206486
[ "s053934585", "s746628106" ]
u597374218
p02711
python
s676498059
s810525464
23
21
9,068
9,036
Accepted
Accepted
8.7
print(("Yes" if input().count("7")>0 else "No"))
N = eval(input()) print(("Yes" if N.count("7") > 0 else "No"))
1
2
46
55
print(("Yes" if input().count("7") > 0 else "No"))
N = eval(input()) print(("Yes" if N.count("7") > 0 else "No"))
false
50
[ "-print((\"Yes\" if input().count(\"7\") > 0 else \"No\"))", "+N = eval(input())", "+print((\"Yes\" if N.count(\"7\") > 0 else \"No\"))" ]
false
0.036911
0.037507
0.984118
[ "s676498059", "s810525464" ]
u934246119
p03339
python
s825739995
s731804161
364
314
32,084
29,740
Accepted
Accepted
13.74
n = int(eval(input())) s = eval(input()) num = [0 for i in range(n)] w = [0 for i in range(n)] if s[0] == 'W': w[0] = 1 for i in range(1, n): if s[i] == 'W': w[i] = (w[i-1] + 1) else: w[i] = w[i-1] e = [0 for i in range(n)] if s[n-1] == 'E': e[n-1] = 1 for i in range(2, n+1): if s[n-i] == 'E': e[n-i] = (e[n-i+1] + 1) else: e[n-i] = e[n-i+1] sol = [0 for i in range(n)] sol[0] = e[0] sol[n-1] = w[n-2] for i in range(1, n-1): sol[i] = w[i-1] + e[i+1] print((min(sol)))
n = int(eval(input())) s = eval(input()) west = [0 for _ in range(n)] if s[0] == 'W': west[0] = 1 for _ in range(1, n): if s[_] == 'W': west[_] = west[_-1] + 1 else: west[_] = west[_-1] east = [0 for _ in range(n)] if s[n-1] == 'E': east[n-1] = 1 for _ in range(n-2, -1, -1): if s[_] == 'E': east[_] = east[_+1] + 1 else: east[_] = east[_+1] ans = [0 for _ in range(n)] ans[0] = east[1] for _ in range(1, n-1): ans[_] = west[_-1] + east[_+1] ans[n-1] = west[n-2] print((min(ans)))
25
25
540
552
n = int(eval(input())) s = eval(input()) num = [0 for i in range(n)] w = [0 for i in range(n)] if s[0] == "W": w[0] = 1 for i in range(1, n): if s[i] == "W": w[i] = w[i - 1] + 1 else: w[i] = w[i - 1] e = [0 for i in range(n)] if s[n - 1] == "E": e[n - 1] = 1 for i in range(2, n + 1): if s[n - i] == "E": e[n - i] = e[n - i + 1] + 1 else: e[n - i] = e[n - i + 1] sol = [0 for i in range(n)] sol[0] = e[0] sol[n - 1] = w[n - 2] for i in range(1, n - 1): sol[i] = w[i - 1] + e[i + 1] print((min(sol)))
n = int(eval(input())) s = eval(input()) west = [0 for _ in range(n)] if s[0] == "W": west[0] = 1 for _ in range(1, n): if s[_] == "W": west[_] = west[_ - 1] + 1 else: west[_] = west[_ - 1] east = [0 for _ in range(n)] if s[n - 1] == "E": east[n - 1] = 1 for _ in range(n - 2, -1, -1): if s[_] == "E": east[_] = east[_ + 1] + 1 else: east[_] = east[_ + 1] ans = [0 for _ in range(n)] ans[0] = east[1] for _ in range(1, n - 1): ans[_] = west[_ - 1] + east[_ + 1] ans[n - 1] = west[n - 2] print((min(ans)))
false
0
[ "-num = [0 for i in range(n)]", "-w = [0 for i in range(n)]", "+west = [0 for _ in range(n)]", "- w[0] = 1", "-for i in range(1, n):", "- if s[i] == \"W\":", "- w[i] = w[i - 1] + 1", "+ west[0] = 1", "+for _ in range(1, n):", "+ if s[_] == \"W\":", "+ west[_] = west[_ - 1] + 1", "- w[i] = w[i - 1]", "-e = [0 for i in range(n)]", "+ west[_] = west[_ - 1]", "+east = [0 for _ in range(n)]", "- e[n - 1] = 1", "-for i in range(2, n + 1):", "- if s[n - i] == \"E\":", "- e[n - i] = e[n - i + 1] + 1", "+ east[n - 1] = 1", "+for _ in range(n - 2, -1, -1):", "+ if s[_] == \"E\":", "+ east[_] = east[_ + 1] + 1", "- e[n - i] = e[n - i + 1]", "-sol = [0 for i in range(n)]", "-sol[0] = e[0]", "-sol[n - 1] = w[n - 2]", "-for i in range(1, n - 1):", "- sol[i] = w[i - 1] + e[i + 1]", "-print((min(sol)))", "+ east[_] = east[_ + 1]", "+ans = [0 for _ in range(n)]", "+ans[0] = east[1]", "+for _ in range(1, n - 1):", "+ ans[_] = west[_ - 1] + east[_ + 1]", "+ans[n - 1] = west[n - 2]", "+print((min(ans)))" ]
false
0.047125
0.043987
1.071343
[ "s825739995", "s731804161" ]
u102461423
p04004
python
s545596466
s285485376
543
411
131,224
90,576
Accepted
Accepted
24.31
import sys input = sys.stdin.readline import numpy as np MOD = 10**9 + 7 N,M,K = list(map(int,input().split())) def cumprod(arr): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] U = 10**6 x = np.full(U,2,dtype=np.int64); x[0] = 1 pow2 = cumprod(x) x = np.full(U,3,dtype=np.int64); x[0] = 1 pow3 = cumprod(x) x = np.full(U,pow(2,MOD-2,MOD),dtype=np.int64); x[0] = 1 pow2_inv = cumprod(x) x = np.full(U,pow(3,MOD-2,MOD),dtype=np.int64); x[0] = 1 pow3_inv = cumprod(x) x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x)[::-1] L = N+M A = np.zeros(N+M,dtype=np.int64) A[1:L] = (-1) * pow2[0:L-1] * pow3_inv[0:L-1] % MOD A[1:L] *= fact[K+1:K+L] * fact_inv[K] % MOD * fact_inv[1:L] % MOD; A %= MOD A[1:L] *= pow3_inv[K+1]; A %= MOD A[0] = 3 * (1 - pow3_inv[K+1]) % MOD * pow2_inv[1] % MOD np.cumsum(A,out=A); A %= MOD A *= pow3[:L]; A %= MOD A *= pow2_inv[:L]; A %= MOD comb = fact[N-1:N+M] * fact_inv[:M+1] % MOD * fact_inv[N-1] % MOD answer = (comb * pow3[K+M:K-1:-1] % MOD * A[N-1:N+M] % MOD).sum() % MOD print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N,M,K = list(map(int,read().split())) MOD = 10 ** 9 + 7 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv def make_power(a,L,MOD): B = L.bit_length() x = np.empty(1 + (1<<B),np.int64) x[0] = 1; x[1] = a for n in range(B): x[1<<n:1<<(n+1)] = x[:1<<n] * (a * x[(1<<n)-1] % MOD) % MOD return x[:L] U = 10 ** 6 power2 = make_power(2,U,MOD) power2_inv = make_power(pow(2,MOD-2,MOD),U,MOD) power3 = make_power(3,U,MOD) power3_inv = make_power(pow(3,MOD-2,MOD),U,MOD) fact,fact_inv = make_fact(U,MOD) x = np.zeros(N+M,np.int64) x[1:] = (-1) * power2[:N+M-1] * power3_inv[K+1:N+M+K] % MOD x[1:] *= fact[K+1:N+M+K] * fact_inv[K] % MOD * fact_inv[1:N+M] % MOD x %= MOD x[0] = 3 * (1 - power3_inv[K+1]) % MOD * power2_inv[1] % MOD np.cumsum(x, out=x); x %= MOD x *= power3[:N+M] * power2_inv[:N+M] % MOD; x %= MOD coef = fact[N-1:N+M] * fact_inv[:M+1] % MOD * fact_inv[N-1] % MOD coef *= power3[K:K+M+1][::-1]; coef %= MOD answer = (coef * x[N-1:N+M] % MOD).sum() % MOD print(answer)
45
54
1,377
1,656
import sys input = sys.stdin.readline import numpy as np MOD = 10**9 + 7 N, M, K = list(map(int, input().split())) def cumprod(arr): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] U = 10**6 x = np.full(U, 2, dtype=np.int64) x[0] = 1 pow2 = cumprod(x) x = np.full(U, 3, dtype=np.int64) x[0] = 1 pow3 = cumprod(x) x = np.full(U, pow(2, MOD - 2, MOD), dtype=np.int64) x[0] = 1 pow2_inv = cumprod(x) x = np.full(U, pow(3, MOD - 2, MOD), dtype=np.int64) x[0] = 1 pow3_inv = cumprod(x) x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x)[::-1] L = N + M A = np.zeros(N + M, dtype=np.int64) A[1:L] = (-1) * pow2[0 : L - 1] * pow3_inv[0 : L - 1] % MOD A[1:L] *= fact[K + 1 : K + L] * fact_inv[K] % MOD * fact_inv[1:L] % MOD A %= MOD A[1:L] *= pow3_inv[K + 1] A %= MOD A[0] = 3 * (1 - pow3_inv[K + 1]) % MOD * pow2_inv[1] % MOD np.cumsum(A, out=A) A %= MOD A *= pow3[:L] A %= MOD A *= pow2_inv[:L] A %= MOD comb = fact[N - 1 : N + M] * fact_inv[: M + 1] % MOD * fact_inv[N - 1] % MOD answer = (comb * pow3[K + M : K - 1 : -1] % MOD * A[N - 1 : N + M] % MOD).sum() % MOD print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, M, K = list(map(int, read().split())) MOD = 10**9 + 7 def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv def make_power(a, L, MOD): B = L.bit_length() x = np.empty(1 + (1 << B), np.int64) x[0] = 1 x[1] = a for n in range(B): x[1 << n : 1 << (n + 1)] = x[: 1 << n] * (a * x[(1 << n) - 1] % MOD) % MOD return x[:L] U = 10**6 power2 = make_power(2, U, MOD) power2_inv = make_power(pow(2, MOD - 2, MOD), U, MOD) power3 = make_power(3, U, MOD) power3_inv = make_power(pow(3, MOD - 2, MOD), U, MOD) fact, fact_inv = make_fact(U, MOD) x = np.zeros(N + M, np.int64) x[1:] = (-1) * power2[: N + M - 1] * power3_inv[K + 1 : N + M + K] % MOD x[1:] *= fact[K + 1 : N + M + K] * fact_inv[K] % MOD * fact_inv[1 : N + M] % MOD x %= MOD x[0] = 3 * (1 - power3_inv[K + 1]) % MOD * power2_inv[1] % MOD np.cumsum(x, out=x) x %= MOD x *= power3[: N + M] * power2_inv[: N + M] % MOD x %= MOD coef = fact[N - 1 : N + M] * fact_inv[: M + 1] % MOD * fact_inv[N - 1] % MOD coef *= power3[K : K + M + 1][::-1] coef %= MOD answer = (coef * x[N - 1 : N + M] % MOD).sum() % MOD print(answer)
false
16.666667
[ "-input = sys.stdin.readline", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, M, K = list(map(int, read().split()))", "-N, M, K = list(map(int, input().split()))", "-def cumprod(arr):", "+def cumprod(arr, MOD):", "+def make_fact(U, MOD):", "+ x = np.arange(U, dtype=np.int64)", "+ x[0] = 1", "+ fact = cumprod(x, MOD)", "+ x = np.arange(U, 0, -1, dtype=np.int64)", "+ x[0] = pow(int(fact[-1]), MOD - 2, MOD)", "+ fact_inv = cumprod(x, MOD)[::-1]", "+ return fact, fact_inv", "+", "+", "+def make_power(a, L, MOD):", "+ B = L.bit_length()", "+ x = np.empty(1 + (1 << B), np.int64)", "+ x[0] = 1", "+ x[1] = a", "+ for n in range(B):", "+ x[1 << n : 1 << (n + 1)] = x[: 1 << n] * (a * x[(1 << n) - 1] % MOD) % MOD", "+ return x[:L]", "+", "+", "-x = np.full(U, 2, dtype=np.int64)", "-x[0] = 1", "-pow2 = cumprod(x)", "-x = np.full(U, 3, dtype=np.int64)", "-x[0] = 1", "-pow3 = cumprod(x)", "-x = np.full(U, pow(2, MOD - 2, MOD), dtype=np.int64)", "-x[0] = 1", "-pow2_inv = cumprod(x)", "-x = np.full(U, pow(3, MOD - 2, MOD), dtype=np.int64)", "-x[0] = 1", "-pow3_inv = cumprod(x)", "-x = np.arange(U, dtype=np.int64)", "-x[0] = 1", "-fact = cumprod(x)", "-x = np.arange(U, 0, -1, dtype=np.int64)", "-x[0] = pow(int(fact[-1]), MOD - 2, MOD)", "-fact_inv = cumprod(x)[::-1]", "-L = N + M", "-A = np.zeros(N + M, dtype=np.int64)", "-A[1:L] = (-1) * pow2[0 : L - 1] * pow3_inv[0 : L - 1] % MOD", "-A[1:L] *= fact[K + 1 : K + L] * fact_inv[K] % MOD * fact_inv[1:L] % MOD", "-A %= MOD", "-A[1:L] *= pow3_inv[K + 1]", "-A %= MOD", "-A[0] = 3 * (1 - pow3_inv[K + 1]) % MOD * pow2_inv[1] % MOD", "-np.cumsum(A, out=A)", "-A %= MOD", "-A *= pow3[:L]", "-A %= MOD", "-A *= pow2_inv[:L]", "-A %= MOD", "-comb = fact[N - 1 : N + M] * fact_inv[: M + 1] % MOD * fact_inv[N - 1] % MOD", "-answer = (comb * pow3[K + M : K - 1 : -1] % MOD * A[N - 1 : N + M] % MOD).sum() % MOD", "+power2 = make_power(2, U, MOD)", "+power2_inv = make_power(pow(2, MOD - 2, MOD), U, MOD)", "+power3 = make_power(3, U, MOD)", "+power3_inv = make_power(pow(3, MOD - 2, MOD), U, MOD)", "+fact, fact_inv = make_fact(U, MOD)", "+x = np.zeros(N + M, np.int64)", "+x[1:] = (-1) * power2[: N + M - 1] * power3_inv[K + 1 : N + M + K] % MOD", "+x[1:] *= fact[K + 1 : N + M + K] * fact_inv[K] % MOD * fact_inv[1 : N + M] % MOD", "+x %= MOD", "+x[0] = 3 * (1 - power3_inv[K + 1]) % MOD * power2_inv[1] % MOD", "+np.cumsum(x, out=x)", "+x %= MOD", "+x *= power3[: N + M] * power2_inv[: N + M] % MOD", "+x %= MOD", "+coef = fact[N - 1 : N + M] * fact_inv[: M + 1] % MOD * fact_inv[N - 1] % MOD", "+coef *= power3[K : K + M + 1][::-1]", "+coef %= MOD", "+answer = (coef * x[N - 1 : N + M] % MOD).sum() % MOD" ]
false
0.792876
2.257506
0.351218
[ "s545596466", "s285485376" ]
u669240121
p03038
python
s063777488
s662091351
740
493
37,048
23,288
Accepted
Accepted
33.38
import heapq N, M = list(map(int, input().split())) nums = list(map(int, input().split())) n = len(nums) heap = [] for i in range(M): B, C = list(map(int, input().split())) heap.append([-C, B]) for num in nums: heap.append([-num, 1]) s = 0 heapq.heapify(heap) while n > 0: num, cnt = heapq.heappop(heap) num = num * -1 s += num * min(cnt, n) n -= min(cnt, n) print(s)
def getInput(): return [int(x) for x in input().split()] N, M = getInput() nums = getInput() nums = sorted(nums) rep = [] for i in range(M): b, c = getInput() rep.append((b, c)) rep = sorted(rep, key=lambda x: x[1], reverse=True) ans = 0 minIndex = 0 isFinished = False for b, c in rep: for _ in range(b): if minIndex < len(nums) and nums[minIndex] < c: ans += c minIndex += 1 else: isFinished = True break if isFinished: break if minIndex < len(nums): ans += sum(nums[minIndex:]) print(ans)
18
28
400
620
import heapq N, M = list(map(int, input().split())) nums = list(map(int, input().split())) n = len(nums) heap = [] for i in range(M): B, C = list(map(int, input().split())) heap.append([-C, B]) for num in nums: heap.append([-num, 1]) s = 0 heapq.heapify(heap) while n > 0: num, cnt = heapq.heappop(heap) num = num * -1 s += num * min(cnt, n) n -= min(cnt, n) print(s)
def getInput(): return [int(x) for x in input().split()] N, M = getInput() nums = getInput() nums = sorted(nums) rep = [] for i in range(M): b, c = getInput() rep.append((b, c)) rep = sorted(rep, key=lambda x: x[1], reverse=True) ans = 0 minIndex = 0 isFinished = False for b, c in rep: for _ in range(b): if minIndex < len(nums) and nums[minIndex] < c: ans += c minIndex += 1 else: isFinished = True break if isFinished: break if minIndex < len(nums): ans += sum(nums[minIndex:]) print(ans)
false
35.714286
[ "-import heapq", "+def getInput():", "+ return [int(x) for x in input().split()]", "-N, M = list(map(int, input().split()))", "-nums = list(map(int, input().split()))", "-n = len(nums)", "-heap = []", "+", "+N, M = getInput()", "+nums = getInput()", "+nums = sorted(nums)", "+rep = []", "- B, C = list(map(int, input().split()))", "- heap.append([-C, B])", "-for num in nums:", "- heap.append([-num, 1])", "-s = 0", "-heapq.heapify(heap)", "-while n > 0:", "- num, cnt = heapq.heappop(heap)", "- num = num * -1", "- s += num * min(cnt, n)", "- n -= min(cnt, n)", "-print(s)", "+ b, c = getInput()", "+ rep.append((b, c))", "+rep = sorted(rep, key=lambda x: x[1], reverse=True)", "+ans = 0", "+minIndex = 0", "+isFinished = False", "+for b, c in rep:", "+ for _ in range(b):", "+ if minIndex < len(nums) and nums[minIndex] < c:", "+ ans += c", "+ minIndex += 1", "+ else:", "+ isFinished = True", "+ break", "+ if isFinished:", "+ break", "+if minIndex < len(nums):", "+ ans += sum(nums[minIndex:])", "+print(ans)" ]
false
0.088696
0.036356
2.439692
[ "s063777488", "s662091351" ]
u107639613
p03546
python
s429294366
s457580307
141
88
73,884
74,084
Accepted
Accepted
37.59
import sys from collections import defaultdict from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def main(): H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] cost = [10**18] * 10 cost[1] = 0 q = [(0, 1)] while q: c, u = heappop(q) if c > cost[u]: continue for i in range(10): if i == u: continue if c + C[i][u] < cost[i]: cost[i] = cost[u] + C[i][u] heappush(q, (cost[i], i)) d = defaultdict(int) for _ in range(H): A = list(map(int, input().split())) for a in A: d[a] += 1 ans = 0 for i in range(10): ans += cost[i] * d[i] print(ans) if __name__ == "__main__": main()
import sys from collections import defaultdict from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def main(): H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] """ 備忘録としてワ―シャルフロイドによる実装も試してみる。 wikipediaの解説が意外とわかりやすい? """ 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]) d = defaultdict(int) for _ in range(H): A = list(map(int, input().split())) for a in A: d[a] += 1 ans = 0 for i in range(10): ans += C[i][1] * d[i] print(ans) if __name__ == "__main__": main()
33
29
831
730
import sys from collections import defaultdict from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def main(): H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] cost = [10**18] * 10 cost[1] = 0 q = [(0, 1)] while q: c, u = heappop(q) if c > cost[u]: continue for i in range(10): if i == u: continue if c + C[i][u] < cost[i]: cost[i] = cost[u] + C[i][u] heappush(q, (cost[i], i)) d = defaultdict(int) for _ in range(H): A = list(map(int, input().split())) for a in A: d[a] += 1 ans = 0 for i in range(10): ans += cost[i] * d[i] print(ans) if __name__ == "__main__": main()
import sys from collections import defaultdict from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def main(): H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] """ 備忘録としてワ―シャルフロイドによる実装も試してみる。 wikipediaの解説が意外とわかりやすい? """ 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]) d = defaultdict(int) for _ in range(H): A = list(map(int, input().split())) for a in A: d[a] += 1 ans = 0 for i in range(10): ans += C[i][1] * d[i] print(ans) if __name__ == "__main__": main()
false
12.121212
[ "- cost = [10**18] * 10", "- cost[1] = 0", "- q = [(0, 1)]", "- while q:", "- c, u = heappop(q)", "- if c > cost[u]:", "- continue", "+ \"\"\"", "+ 備忘録としてワ―シャルフロイドによる実装も試してみる。", "+ wikipediaの解説が意外とわかりやすい?", "+ \"\"\"", "+ for k in range(10):", "- if i == u:", "- continue", "- if c + C[i][u] < cost[i]:", "- cost[i] = cost[u] + C[i][u]", "- heappush(q, (cost[i], i))", "+ for j in range(10):", "+ C[i][j] = min(C[i][j], C[i][k] + C[k][j])", "- ans += cost[i] * d[i]", "+ ans += C[i][1] * d[i]" ]
false
0.040361
0.081422
0.495704
[ "s429294366", "s457580307" ]
u327172575
p02570
python
s810372916
s632155787
26
24
9,000
9,100
Accepted
Accepted
7.69
D,T,S = list(map(int,input().split())) if D/S <= T: print("Yes") else: print("No")
D,T,S = list(map(float,input().split())) if D/S <= T: print("Yes") else: print("No")
5
5
84
86
D, T, S = list(map(int, input().split())) if D / S <= T: print("Yes") else: print("No")
D, T, S = list(map(float, input().split())) if D / S <= T: print("Yes") else: print("No")
false
0
[ "-D, T, S = list(map(int, input().split()))", "+D, T, S = list(map(float, input().split()))" ]
false
0.084551
0.038801
2.179124
[ "s810372916", "s632155787" ]
u163320134
p03363
python
s405877713
s480530133
254
168
26,720
40,044
Accepted
Accepted
33.86
n=int(eval(input())) arr=list(map(int,input().split())) acum=[0]*(n+1) cnt=0 for i in range(1,n+1): acum[i]=acum[i-1]+arr[i-1] acum=sorted(acum) acum.append(10**10) tmp=1 for i in range(1,len(acum)): if acum[i]==acum[i-1]: tmp+=1 else: cnt+=tmp*(tmp-1)//2 tmp=1 print(cnt)
import collections n=int(eval(input())) arr=[0]+list(map(int,input().split())) for i in range(n): arr[i+1]+=arr[i] cnt=collections.Counter(arr) ans=0 for val in list(cnt.values()): ans+=val*(val-1)//2 print(ans)
16
11
300
214
n = int(eval(input())) arr = list(map(int, input().split())) acum = [0] * (n + 1) cnt = 0 for i in range(1, n + 1): acum[i] = acum[i - 1] + arr[i - 1] acum = sorted(acum) acum.append(10**10) tmp = 1 for i in range(1, len(acum)): if acum[i] == acum[i - 1]: tmp += 1 else: cnt += tmp * (tmp - 1) // 2 tmp = 1 print(cnt)
import collections n = int(eval(input())) arr = [0] + list(map(int, input().split())) for i in range(n): arr[i + 1] += arr[i] cnt = collections.Counter(arr) ans = 0 for val in list(cnt.values()): ans += val * (val - 1) // 2 print(ans)
false
31.25
[ "+import collections", "+", "-arr = list(map(int, input().split()))", "-acum = [0] * (n + 1)", "-cnt = 0", "-for i in range(1, n + 1):", "- acum[i] = acum[i - 1] + arr[i - 1]", "-acum = sorted(acum)", "-acum.append(10**10)", "-tmp = 1", "-for i in range(1, len(acum)):", "- if acum[i] == acum[i - 1]:", "- tmp += 1", "- else:", "- cnt += tmp * (tmp - 1) // 2", "- tmp = 1", "-print(cnt)", "+arr = [0] + list(map(int, input().split()))", "+for i in range(n):", "+ arr[i + 1] += arr[i]", "+cnt = collections.Counter(arr)", "+ans = 0", "+for val in list(cnt.values()):", "+ ans += val * (val - 1) // 2", "+print(ans)" ]
false
0.036132
0.034321
1.052784
[ "s405877713", "s480530133" ]
u366959492
p03162
python
s870892322
s198754417
648
333
65,880
54,636
Accepted
Accepted
48.61
n=int(eval(input())) dp=[[0]*(n) for _ in range(3)] l=[] for i in range(n): a,b,c=list(map(int,input().split())) l.append([a,b,c]) dp[0][0],dp[1][0],dp[2][0]=l[0][0],l[0][1],l[0][2] for i in range(0,n-1): dp[0][i+1]=max(dp[1][i]+l[i+1][0],dp[2][i]+l[i+1][0]) dp[1][i+1]=max(dp[0][i]+l[i+1][1],dp[2][i]+l[i+1][1]) dp[2][i+1]=max(dp[0][i]+l[i+1][2],dp[1][i]+l[i+1][2]) print((max([dp[0][n-1],dp[1][n-1],dp[2][n-1]])))
import sys input=sys.stdin.readline n=int(eval(input())) dp=[[0]*3 for _ in range(n)] a,b,c=list(map(int,input().split())) dp[0]=[a,b,c] for i in range(1,n): a,b,c=list(map(int,input().split())) dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c print((max(dp[n-1])))
12
13
433
341
n = int(eval(input())) dp = [[0] * (n) for _ in range(3)] l = [] for i in range(n): a, b, c = list(map(int, input().split())) l.append([a, b, c]) dp[0][0], dp[1][0], dp[2][0] = l[0][0], l[0][1], l[0][2] for i in range(0, n - 1): dp[0][i + 1] = max(dp[1][i] + l[i + 1][0], dp[2][i] + l[i + 1][0]) dp[1][i + 1] = max(dp[0][i] + l[i + 1][1], dp[2][i] + l[i + 1][1]) dp[2][i + 1] = max(dp[0][i] + l[i + 1][2], dp[1][i] + l[i + 1][2]) print((max([dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]])))
import sys input = sys.stdin.readline n = int(eval(input())) dp = [[0] * 3 for _ in range(n)] a, b, c = list(map(int, input().split())) dp[0] = [a, b, c] for i in range(1, n): a, b, c = list(map(int, input().split())) dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c print((max(dp[n - 1])))
false
7.692308
[ "+import sys", "+", "+input = sys.stdin.readline", "-dp = [[0] * (n) for _ in range(3)]", "-l = []", "-for i in range(n):", "+dp = [[0] * 3 for _ in range(n)]", "+a, b, c = list(map(int, input().split()))", "+dp[0] = [a, b, c]", "+for i in range(1, n):", "- l.append([a, b, c])", "-dp[0][0], dp[1][0], dp[2][0] = l[0][0], l[0][1], l[0][2]", "-for i in range(0, n - 1):", "- dp[0][i + 1] = max(dp[1][i] + l[i + 1][0], dp[2][i] + l[i + 1][0])", "- dp[1][i + 1] = max(dp[0][i] + l[i + 1][1], dp[2][i] + l[i + 1][1])", "- dp[2][i + 1] = max(dp[0][i] + l[i + 1][2], dp[1][i] + l[i + 1][2])", "-print((max([dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]])))", "+ dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a", "+ dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b", "+ dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c", "+print((max(dp[n - 1])))" ]
false
0.035683
0.036364
0.981295
[ "s870892322", "s198754417" ]
u832039789
p02783
python
s238114625
s291434139
21
19
3,316
3,064
Accepted
Accepted
9.52
h,a = list(map(int,input().split())) print(((h + a - 1) // a))
h,a = list(map(int,input().split())) cnt = 0 while h > 0: h -= a cnt += 1 print(cnt)
2
6
55
92
h, a = list(map(int, input().split())) print(((h + a - 1) // a))
h, a = list(map(int, input().split())) cnt = 0 while h > 0: h -= a cnt += 1 print(cnt)
false
66.666667
[ "-print(((h + a - 1) // a))", "+cnt = 0", "+while h > 0:", "+ h -= a", "+ cnt += 1", "+print(cnt)" ]
false
0.040861
0.041771
0.978225
[ "s238114625", "s291434139" ]
u645487439
p02761
python
s501250488
s990969611
19
17
3,064
3,064
Accepted
Accepted
10.53
n, m = list(map(int, input().split())) num_list = ['X'] * n def ans(): if n == 1 and m == 0: return 0 for i in range(m): set = list(map(str, input().split())) if set[0] == '1' and set[1] == '0' and n != 1: return -1 else: if num_list[int(set[0]) - 1] == 'X': num_list[int(set[0]) - 1] = set[1] elif num_list[int(set[0]) - 1] == set[1]: continue else: return -1 for i in range(n): if num_list[i] == 'X': if i == 0: num_list[i] = '1' else: num_list[i] = '0' return ''.join(num_list) print((ans()))
n, m = list(map(int, input().split())) num_list = ['X'] * n def ans(): if n == 1 and m == 0: return 0 for i in range(m): set = list(map(str, input().split())) if set[0] == '1' and set[1] == '0' and n != 1: return -1 else: if num_list[int(set[0]) - 1] == 'X': num_list[int(set[0]) - 1] = set[1] elif num_list[int(set[0]) - 1] == set[1]: continue else: return -1 for i in range(n): if num_list[i] == 'X': num_list[i] = '1' if i == 0 else '0' return ''.join(num_list) print((ans()))
28
25
727
664
n, m = list(map(int, input().split())) num_list = ["X"] * n def ans(): if n == 1 and m == 0: return 0 for i in range(m): set = list(map(str, input().split())) if set[0] == "1" and set[1] == "0" and n != 1: return -1 else: if num_list[int(set[0]) - 1] == "X": num_list[int(set[0]) - 1] = set[1] elif num_list[int(set[0]) - 1] == set[1]: continue else: return -1 for i in range(n): if num_list[i] == "X": if i == 0: num_list[i] = "1" else: num_list[i] = "0" return "".join(num_list) print((ans()))
n, m = list(map(int, input().split())) num_list = ["X"] * n def ans(): if n == 1 and m == 0: return 0 for i in range(m): set = list(map(str, input().split())) if set[0] == "1" and set[1] == "0" and n != 1: return -1 else: if num_list[int(set[0]) - 1] == "X": num_list[int(set[0]) - 1] = set[1] elif num_list[int(set[0]) - 1] == set[1]: continue else: return -1 for i in range(n): if num_list[i] == "X": num_list[i] = "1" if i == 0 else "0" return "".join(num_list) print((ans()))
false
10.714286
[ "- if i == 0:", "- num_list[i] = \"1\"", "- else:", "- num_list[i] = \"0\"", "+ num_list[i] = \"1\" if i == 0 else \"0\"" ]
false
0.047974
0.047127
1.017971
[ "s501250488", "s990969611" ]
u485716382
p03127
python
s577870847
s177532378
274
203
24,056
15,020
Accepted
Accepted
25.91
from fractions import gcd import numpy as np N = int(eval(input())) A = np.array([int(i) for i in input().split()]) a = A[0] for b in A[1:]: # print(a) a = gcd(a, b) print(a)
def gcd(a, b): if b == 0: return a return gcd(b, a%b) def main(): N = int(eval(input())) An = list(map(int, input().split(' '))) An = sorted(An) An = [gcd(a_n, An[0]) for a_n in An] print((min(An))) main()
12
15
186
251
from fractions import gcd import numpy as np N = int(eval(input())) A = np.array([int(i) for i in input().split()]) a = A[0] for b in A[1:]: # print(a) a = gcd(a, b) print(a)
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def main(): N = int(eval(input())) An = list(map(int, input().split(" "))) An = sorted(An) An = [gcd(a_n, An[0]) for a_n in An] print((min(An))) main()
false
20
[ "-from fractions import gcd", "-import numpy as np", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ return gcd(b, a % b)", "-N = int(eval(input()))", "-A = np.array([int(i) for i in input().split()])", "-a = A[0]", "-for b in A[1:]:", "- # print(a)", "- a = gcd(a, b)", "-print(a)", "+", "+def main():", "+ N = int(eval(input()))", "+ An = list(map(int, input().split(\" \")))", "+ An = sorted(An)", "+ An = [gcd(a_n, An[0]) for a_n in An]", "+ print((min(An)))", "+", "+", "+main()" ]
false
0.221035
0.037141
5.951172
[ "s577870847", "s177532378" ]
u368249389
p03712
python
s893214039
s102433364
30
21
4,468
3,064
Accepted
Accepted
30
H, W = map(int, input().split()) mark_list = [["#"]*(W+2) for i in range(H+2)] for i in range(1,H+1): w_list = input() for j in range(1,W+1): mark_list[i][j] = w_list[j-1] # output for i in mark_list[0]: print(i, end="") print("") for i in range(1,H+1): for j in range(W+2): print(mark_list[i][j], end="") print("") for i in mark_list[H+1]: print(i, end="")
# Problem B - Picture Frame # input H, W = list(map(int, input().split())) a_list = [['']*W for i in range(H)] for i in range(H): a_nums = list(eval(input())) for j in range(W): a_list[i][j] = a_nums[j] # output ans = "#"*(W+2) ans += "\n" for i in range(H): ans += "#" for j in range(W): ans += a_list[i][j] ans += "#\n" ans += "#"*(W+2) print(ans)
18
20
400
395
H, W = map(int, input().split()) mark_list = [["#"] * (W + 2) for i in range(H + 2)] for i in range(1, H + 1): w_list = input() for j in range(1, W + 1): mark_list[i][j] = w_list[j - 1] # output for i in mark_list[0]: print(i, end="") print("") for i in range(1, H + 1): for j in range(W + 2): print(mark_list[i][j], end="") print("") for i in mark_list[H + 1]: print(i, end="")
# Problem B - Picture Frame # input H, W = list(map(int, input().split())) a_list = [[""] * W for i in range(H)] for i in range(H): a_nums = list(eval(input())) for j in range(W): a_list[i][j] = a_nums[j] # output ans = "#" * (W + 2) ans += "\n" for i in range(H): ans += "#" for j in range(W): ans += a_list[i][j] ans += "#\n" ans += "#" * (W + 2) print(ans)
false
10
[ "-H, W = map(int, input().split())", "-mark_list = [[\"#\"] * (W + 2) for i in range(H + 2)]", "-for i in range(1, H + 1):", "- w_list = input()", "- for j in range(1, W + 1):", "- mark_list[i][j] = w_list[j - 1]", "+# Problem B - Picture Frame", "+# input", "+H, W = list(map(int, input().split()))", "+a_list = [[\"\"] * W for i in range(H)]", "+for i in range(H):", "+ a_nums = list(eval(input()))", "+ for j in range(W):", "+ a_list[i][j] = a_nums[j]", "-for i in mark_list[0]:", "- print(i, end=\"\")", "-print(\"\")", "-for i in range(1, H + 1):", "- for j in range(W + 2):", "- print(mark_list[i][j], end=\"\")", "- print(\"\")", "-for i in mark_list[H + 1]:", "- print(i, end=\"\")", "+ans = \"#\" * (W + 2)", "+ans += \"\\n\"", "+for i in range(H):", "+ ans += \"#\"", "+ for j in range(W):", "+ ans += a_list[i][j]", "+ ans += \"#\\n\"", "+ans += \"#\" * (W + 2)", "+print(ans)" ]
false
0.037028
0.078317
0.47279
[ "s893214039", "s102433364" ]
u600717568
p02959
python
s000563919
s524716795
158
146
18,476
18,476
Accepted
Accepted
7.59
N=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) x=0 for i in range(N): if A[i]+A[i+1]<=B[i]: x+=A[i]+A[i+1] A[i+1]=0 elif A[i]>=B[i]: x+=B[i] elif A[i]<B[i]: x+=B[i] A[i+1]=A[i+1]-(B[i]-A[i]) print(x)
N=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) count=0 for i in range(N): if A[i]+A[i+1]<=B[i]: count+=A[i]+A[i+1] A[i+1]=0 elif A[i]<=B[i]: count+=B[i] A[i+1]=A[i+1]-(B[i]-A[i]) else: count+=B[i] print(count)
14
16
272
304
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) x = 0 for i in range(N): if A[i] + A[i + 1] <= B[i]: x += A[i] + A[i + 1] A[i + 1] = 0 elif A[i] >= B[i]: x += B[i] elif A[i] < B[i]: x += B[i] A[i + 1] = A[i + 1] - (B[i] - A[i]) print(x)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) count = 0 for i in range(N): if A[i] + A[i + 1] <= B[i]: count += A[i] + A[i + 1] A[i + 1] = 0 elif A[i] <= B[i]: count += B[i] A[i + 1] = A[i + 1] - (B[i] - A[i]) else: count += B[i] print(count)
false
12.5
[ "-x = 0", "+count = 0", "- x += A[i] + A[i + 1]", "+ count += A[i] + A[i + 1]", "- elif A[i] >= B[i]:", "- x += B[i]", "- elif A[i] < B[i]:", "- x += B[i]", "+ elif A[i] <= B[i]:", "+ count += B[i]", "-print(x)", "+ else:", "+ count += B[i]", "+print(count)" ]
false
0.036276
0.03507
1.034406
[ "s000563919", "s524716795" ]
u533039576
p02821
python
s004363816
s401737538
1,170
448
14,428
17,940
Accepted
Accepted
61.71
from bisect import bisect_left, bisect_right n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() # print(a) a_cs = [0] * (n + 1) for i in range(n): a_cs[i + 1] = a_cs[i] + a[n - 1 - i] def check(x): # M回の握手の幸福度の最小値をx以上にできるか # つまり、M回の任意の握手の幸福度をx以上にできるか cnt = 0 for ai in a: idx = bisect_left(a, x - ai) cnt += n - idx return cnt >= m lb = 1 # True ub = 2 * 10**5 + 5 # False while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): lb = mid else: ub = mid # print(lb) ans = 0 cnt = 0 for ai in a: idx = bisect_left(a, lb - ai) ans += ai * (n - idx) + a_cs[n - idx] cnt += n - idx ans -= lb * (cnt - m) print(ans)
from bisect import bisect_left, bisect_right n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() # print(a) a_cnt = [0] * (2 * a[-1] + 5) for ai in a: a_cnt[ai] += 1 for i in reversed(list(range(len(a_cnt) - 1))): a_cnt[i] += a_cnt[i + 1] a_cs = [0] * (n + 1) for i in range(n): a_cs[i + 1] = a_cs[i] + a[n - 1 - i] def check(x): # M回の握手の幸福度の最小値をx以上にできるか # つまり、M回の任意の握手の幸福度をx以上にできるか cnt = 0 for ai in a: if x >= ai: cnt += a_cnt[x - ai] else: cnt += n return cnt >= m lb = 1 # True ub = 2 * a[-1] + 3 # False while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): lb = mid else: ub = mid # print(lb) ans = 0 cnt = 0 for ai in a: if lb >= ai: idx = a_cnt[lb - ai] else: idx = n ans += ai * idx + a_cs[idx] cnt += idx ans -= lb * (cnt - m) print(ans)
40
50
764
959
from bisect import bisect_left, bisect_right n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() # print(a) a_cs = [0] * (n + 1) for i in range(n): a_cs[i + 1] = a_cs[i] + a[n - 1 - i] def check(x): # M回の握手の幸福度の最小値をx以上にできるか # つまり、M回の任意の握手の幸福度をx以上にできるか cnt = 0 for ai in a: idx = bisect_left(a, x - ai) cnt += n - idx return cnt >= m lb = 1 # True ub = 2 * 10**5 + 5 # False while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): lb = mid else: ub = mid # print(lb) ans = 0 cnt = 0 for ai in a: idx = bisect_left(a, lb - ai) ans += ai * (n - idx) + a_cs[n - idx] cnt += n - idx ans -= lb * (cnt - m) print(ans)
from bisect import bisect_left, bisect_right n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() # print(a) a_cnt = [0] * (2 * a[-1] + 5) for ai in a: a_cnt[ai] += 1 for i in reversed(list(range(len(a_cnt) - 1))): a_cnt[i] += a_cnt[i + 1] a_cs = [0] * (n + 1) for i in range(n): a_cs[i + 1] = a_cs[i] + a[n - 1 - i] def check(x): # M回の握手の幸福度の最小値をx以上にできるか # つまり、M回の任意の握手の幸福度をx以上にできるか cnt = 0 for ai in a: if x >= ai: cnt += a_cnt[x - ai] else: cnt += n return cnt >= m lb = 1 # True ub = 2 * a[-1] + 3 # False while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): lb = mid else: ub = mid # print(lb) ans = 0 cnt = 0 for ai in a: if lb >= ai: idx = a_cnt[lb - ai] else: idx = n ans += ai * idx + a_cs[idx] cnt += idx ans -= lb * (cnt - m) print(ans)
false
20
[ "+a_cnt = [0] * (2 * a[-1] + 5)", "+for ai in a:", "+ a_cnt[ai] += 1", "+for i in reversed(list(range(len(a_cnt) - 1))):", "+ a_cnt[i] += a_cnt[i + 1]", "- idx = bisect_left(a, x - ai)", "- cnt += n - idx", "+ if x >= ai:", "+ cnt += a_cnt[x - ai]", "+ else:", "+ cnt += n", "-ub = 2 * 10**5 + 5 # False", "+ub = 2 * a[-1] + 3 # False", "- idx = bisect_left(a, lb - ai)", "- ans += ai * (n - idx) + a_cs[n - idx]", "- cnt += n - idx", "+ if lb >= ai:", "+ idx = a_cnt[lb - ai]", "+ else:", "+ idx = n", "+ ans += ai * idx + a_cs[idx]", "+ cnt += idx" ]
false
0.114269
0.148124
0.771442
[ "s004363816", "s401737538" ]
u461833298
p02947
python
s945878154
s067685107
534
290
31,792
20,196
Accepted
Accepted
45.69
import itertools import collections N = int(eval(input())) S = [[str(x) for x in eval(input())] for _ in range(N)] S = [''.join(sorted(x)) for x in S] cnt=0 reg = collections.defaultdict(int) for s in S: reg[s] += 1 if reg[s] > 1: cnt += reg[s] - 1 print(cnt)
import collections N = int(eval(input())) S = [eval(input()) for _ in range(N)] S = [''.join(sorted(x)) for x in S] S = collections.Counter(S) ans = [x*(x-1)//2 for x in list(S.values())] print((sum(ans)))
13
9
276
195
import itertools import collections N = int(eval(input())) S = [[str(x) for x in eval(input())] for _ in range(N)] S = ["".join(sorted(x)) for x in S] cnt = 0 reg = collections.defaultdict(int) for s in S: reg[s] += 1 if reg[s] > 1: cnt += reg[s] - 1 print(cnt)
import collections N = int(eval(input())) S = [eval(input()) for _ in range(N)] S = ["".join(sorted(x)) for x in S] S = collections.Counter(S) ans = [x * (x - 1) // 2 for x in list(S.values())] print((sum(ans)))
false
30.769231
[ "-import itertools", "-S = [[str(x) for x in eval(input())] for _ in range(N)]", "+S = [eval(input()) for _ in range(N)]", "-cnt = 0", "-reg = collections.defaultdict(int)", "-for s in S:", "- reg[s] += 1", "- if reg[s] > 1:", "- cnt += reg[s] - 1", "-print(cnt)", "+S = collections.Counter(S)", "+ans = [x * (x - 1) // 2 for x in list(S.values())]", "+print((sum(ans)))" ]
false
0.038094
0.08589
0.443522
[ "s945878154", "s067685107" ]
u767797498
p02597
python
s151491888
s410170707
109
59
11,328
9,344
Accepted
Accepted
45.87
# -*- coding: utf-8 -*- # template: v1.3.1 import io import sys import math ### DEBUG ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 200000 """+("R"*200000) _EXPECTED = """\ 2 """ if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") def logd(str): if _DEB: print(f"[deb] {str}") ### INPUT #### n = int(eval(input())) c = eval(input()) c=c.replace("R","0") c=c.replace("W","1") c=[int(x) for x in c] ### Solve #### def solve(): # Process ans=0 id1=0 for i in reversed(list(range(n))): if id1 > i: break id0=-1 if c[i] == 0: id0=i not_found=True for j in range(id1,id0): if c[j]==1: id1=j c[i]=1 c[j]=0 ans+=1 not_found=False break if not_found: break if[i]==0: c[i]=1 ans+=1 # OUPUT ans = str(ans) print(ans) return ans ### MAIN ### if __name__ == "__main__": ans = solve() # Checker if _DEB: if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!") else: print(f"\n!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
n=int(eval(input())) s=eval(input()) li=0 ri=len(s) cnt=0 while li<ri: if s[li] == "W": while li<ri: ri-=1 if s[ri] == "R": cnt+=1 break li+=1 print(cnt)
73
16
1,380
202
# -*- coding: utf-8 -*- # template: v1.3.1 import io import sys import math ### DEBUG ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 200000 """ + ( "R" * 200000 ) _EXPECTED = """\ 2 """ if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") def logd(str): if _DEB: print(f"[deb] {str}") ### INPUT #### n = int(eval(input())) c = eval(input()) c = c.replace("R", "0") c = c.replace("W", "1") c = [int(x) for x in c] ### Solve #### def solve(): # Process ans = 0 id1 = 0 for i in reversed(list(range(n))): if id1 > i: break id0 = -1 if c[i] == 0: id0 = i not_found = True for j in range(id1, id0): if c[j] == 1: id1 = j c[i] = 1 c[j] = 0 ans += 1 not_found = False break if not_found: break if [i] == 0: c[i] = 1 ans += 1 # OUPUT ans = str(ans) print(ans) return ans ### MAIN ### if __name__ == "__main__": ans = solve() # Checker if _DEB: if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!") else: print(f"\n!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
n = int(eval(input())) s = eval(input()) li = 0 ri = len(s) cnt = 0 while li < ri: if s[li] == "W": while li < ri: ri -= 1 if s[ri] == "R": cnt += 1 break li += 1 print(cnt)
false
78.082192
[ "-# -*- coding: utf-8 -*-", "-# template: v1.3.1", "-import io", "-import sys", "-import math", "-", "-### DEBUG ###", "-_DEB = 0 # 1:ON / 0:OFF", "-_INPUT = \"\"\"\\", "-200000", "-\"\"\" + (", "- \"R\" * 200000", "-)", "-_EXPECTED = \"\"\"\\", "-2", "-\"\"\"", "-if _DEB:", "- sys.stdin = io.StringIO(_INPUT)", "- print(\"!! Debug Mode !!\")", "-", "-", "-def logd(str):", "- if _DEB:", "- print(f\"[deb] {str}\")", "-", "-", "-### INPUT ####", "-c = eval(input())", "-c = c.replace(\"R\", \"0\")", "-c = c.replace(\"W\", \"1\")", "-c = [int(x) for x in c]", "-### Solve ####", "-def solve():", "- # Process", "- ans = 0", "- id1 = 0", "- for i in reversed(list(range(n))):", "- if id1 > i:", "- break", "- id0 = -1", "- if c[i] == 0:", "- id0 = i", "- not_found = True", "- for j in range(id1, id0):", "- if c[j] == 1:", "- id1 = j", "- c[i] = 1", "- c[j] = 0", "- ans += 1", "- not_found = False", "- break", "- if not_found:", "+s = eval(input())", "+li = 0", "+ri = len(s)", "+cnt = 0", "+while li < ri:", "+ if s[li] == \"W\":", "+ while li < ri:", "+ ri -= 1", "+ if s[ri] == \"R\":", "+ cnt += 1", "- if [i] == 0:", "- c[i] = 1", "- ans += 1", "- # OUPUT", "- ans = str(ans)", "- print(ans)", "- return ans", "-", "-", "-### MAIN ###", "-if __name__ == \"__main__\":", "- ans = solve()", "- # Checker", "- if _DEB:", "- if _EXPECTED.strip() == ans.strip():", "- print(\"\\n!! Success !!\")", "- else:", "- print(f\"\\n!! Failed... !!\\nANSWER: {ans}\\nExpected: {_EXPECTED}\")", "+ li += 1", "+print(cnt)" ]
false
0.038373
0.036507
1.051108
[ "s151491888", "s410170707" ]
u893063840
p03364
python
s651345947
s648313329
1,450
224
123,228
13,184
Accepted
Accepted
84.55
n = int(eval(input())) s = [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)] ans = 0 for b in range(n): t = [[-1] * n for _ in range(n)] for hi in range(n): for wi in range(n): nh = hi nw = (wi + b) % n t[nh][nw] = s[hi][wi] bl = True for i in range(n): for j in range(n): if t[i][j] != t[j][i]: bl = False ans += bl ans *= n print(ans)
import numpy as np n = int(eval(input())) s = np.array([list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)], np.int8) s = np.hstack((s, s)) ans = 0 for b in range(n): t = s[:, b:b+n] if (t == t.T).all(): ans += 1 ans *= n print(ans)
22
14
467
267
n = int(eval(input())) s = [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)] ans = 0 for b in range(n): t = [[-1] * n for _ in range(n)] for hi in range(n): for wi in range(n): nh = hi nw = (wi + b) % n t[nh][nw] = s[hi][wi] bl = True for i in range(n): for j in range(n): if t[i][j] != t[j][i]: bl = False ans += bl ans *= n print(ans)
import numpy as np n = int(eval(input())) s = np.array( [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)], np.int8 ) s = np.hstack((s, s)) ans = 0 for b in range(n): t = s[:, b : b + n] if (t == t.T).all(): ans += 1 ans *= n print(ans)
false
36.363636
[ "+import numpy as np", "+", "-s = [list(ord(e) - ord(\"a\") for e in eval(input())) for _ in range(n)]", "+s = np.array(", "+ [list(ord(e) - ord(\"a\") for e in eval(input())) for _ in range(n)], np.int8", "+)", "+s = np.hstack((s, s))", "- t = [[-1] * n for _ in range(n)]", "- for hi in range(n):", "- for wi in range(n):", "- nh = hi", "- nw = (wi + b) % n", "- t[nh][nw] = s[hi][wi]", "- bl = True", "- for i in range(n):", "- for j in range(n):", "- if t[i][j] != t[j][i]:", "- bl = False", "- ans += bl", "+ t = s[:, b : b + n]", "+ if (t == t.T).all():", "+ ans += 1" ]
false
0.037788
0.758664
0.049809
[ "s651345947", "s648313329" ]
u998741086
p03331
python
s763643733
s550978263
273
31
9,128
9,220
Accepted
Accepted
88.64
#!/usr/bin/env python n = int(eval(input())) def sumdigits(n): ret = 0 s = list(str(n)) for i in range(len(s)): ret += int(s[i]) return ret a = 1 ans = 1000000 while n-a > 0: tmp = sumdigits(a) + sumdigits(n-a) if ans >= tmp: ans = tmp a += 1 print(ans)
#!/usr/bin/env python import math n = int(eval(input())) m = math.log10(n) if int(m) == m: print((10)) exit() ans = sum(map(int, list(str(n)))) print(ans)
20
11
319
167
#!/usr/bin/env python n = int(eval(input())) def sumdigits(n): ret = 0 s = list(str(n)) for i in range(len(s)): ret += int(s[i]) return ret a = 1 ans = 1000000 while n - a > 0: tmp = sumdigits(a) + sumdigits(n - a) if ans >= tmp: ans = tmp a += 1 print(ans)
#!/usr/bin/env python import math n = int(eval(input())) m = math.log10(n) if int(m) == m: print((10)) exit() ans = sum(map(int, list(str(n)))) print(ans)
false
45
[ "+import math", "+", "-", "-", "-def sumdigits(n):", "- ret = 0", "- s = list(str(n))", "- for i in range(len(s)):", "- ret += int(s[i])", "- return ret", "-", "-", "-a = 1", "-ans = 1000000", "-while n - a > 0:", "- tmp = sumdigits(a) + sumdigits(n - a)", "- if ans >= tmp:", "- ans = tmp", "- a += 1", "+m = math.log10(n)", "+if int(m) == m:", "+ print((10))", "+ exit()", "+ans = sum(map(int, list(str(n))))" ]
false
0.157458
0.036144
4.356411
[ "s763643733", "s550978263" ]
u481187938
p02558
python
s050839875
s538599470
2,887
352
130,088
130,240
Accepted
Accepted
87.81
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, n): self._parent = [i for i in range(n)] self._rank = [0 for _ in range(n)] self._group_size = [1 for _ in range(n)] self.num_of_groups = n def find(self, x): # vs = [] while self._parent[x] != x: # vs.append(x) x = self._parent[x] # for v in vs: self._parent[v] = x return x def union(self, x, y): px, py = self.find(x), self.find(y) if px == py: return if self._rank[px] < self._rank[py]: self._parent[px] = py self._group_size[py] += self._group_size[px] else: self._parent[py] = px self._group_size[px] += self._group_size[py] if self._rank[px] == self._rank[py]: self._rank[py] += 1 self.num_of_groups -= 1 def is_same(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self._group_size[self.find(x)] def main(): N, Q = LI() TUV = LIR(Q) uf = UnionFind(N+1) for t, u, v in TUV: if t == 0: uf.union(u, v) else: print((int(uf.is_same(u, v)))) if __name__ == '__main__': main()
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, n): self._parent, self._rank, self._group_size = [i for i in range(n)], [0 for _ in range(n)], [1 for _ in range(n)] self.num_of_groups = n def find(self, x): vs = [] while self._parent[x] != x: vs.append(x) x = self._parent[x] for v in vs: self._parent[v] = x return x def union(self, x, y): px, py = self.find(x), self.find(y) if px == py: return if self._rank[px] < self._rank[py]: self._parent[px] = py self._group_size[py] += self._group_size[px] else: self._parent[py] = px self._group_size[px] += self._group_size[py] if self._rank[px] == self._rank[py]: self._rank[py] += 1 self.num_of_groups -= 1 def is_same(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self._group_size[self.find(x)] def main(): N, Q = LI() TUV = LIR(Q) uf = UnionFind(N+1) for t, u, v in TUV: if t == 0: uf.union(u, v) else: print((int(uf.is_same(u, v)))) if __name__ == '__main__': main()
84
81
2,830
2,793
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n - r)) def make_list(n, *args, default=0): return ( [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] ) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, n): self._parent = [i for i in range(n)] self._rank = [0 for _ in range(n)] self._group_size = [1 for _ in range(n)] self.num_of_groups = n def find(self, x): # vs = [] while self._parent[x] != x: # vs.append(x) x = self._parent[x] # for v in vs: self._parent[v] = x return x def union(self, x, y): px, py = self.find(x), self.find(y) if px == py: return if self._rank[px] < self._rank[py]: self._parent[px] = py self._group_size[py] += self._group_size[px] else: self._parent[py] = px self._group_size[px] += self._group_size[py] if self._rank[px] == self._rank[py]: self._rank[py] += 1 self.num_of_groups -= 1 def is_same(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self._group_size[self.find(x)] def main(): N, Q = LI() TUV = LIR(Q) uf = UnionFind(N + 1) for t, u, v in TUV: if t == 0: uf.union(u, v) else: print((int(uf.is_same(u, v)))) if __name__ == "__main__": main()
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def R(n): return [sys.stdin.readline().strip() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n - r)) def make_list(n, *args, default=0): return ( [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] ) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" MOD = 1000000007 INF = float("inf") sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, n): self._parent, self._rank, self._group_size = ( [i for i in range(n)], [0 for _ in range(n)], [1 for _ in range(n)], ) self.num_of_groups = n def find(self, x): vs = [] while self._parent[x] != x: vs.append(x) x = self._parent[x] for v in vs: self._parent[v] = x return x def union(self, x, y): px, py = self.find(x), self.find(y) if px == py: return if self._rank[px] < self._rank[py]: self._parent[px] = py self._group_size[py] += self._group_size[px] else: self._parent[py] = px self._group_size[px] += self._group_size[py] if self._rank[px] == self._rank[py]: self._rank[py] += 1 self.num_of_groups -= 1 def is_same(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self._group_size[self.find(x)] def main(): N, Q = LI() TUV = LIR(Q) uf = UnionFind(N + 1) for t, u, v in TUV: if t == 0: uf.union(u, v) else: print((int(uf.is_same(u, v)))) if __name__ == "__main__": main()
false
3.571429
[ "- self._parent = [i for i in range(n)]", "- self._rank = [0 for _ in range(n)]", "- self._group_size = [1 for _ in range(n)]", "+ self._parent, self._rank, self._group_size = (", "+ [i for i in range(n)],", "+ [0 for _ in range(n)],", "+ [1 for _ in range(n)],", "+ )", "- # vs = []", "+ vs = []", "- # vs.append(x)", "+ vs.append(x)", "- # for v in vs: self._parent[v] = x", "+ for v in vs:", "+ self._parent[v] = x" ]
false
0.038029
0.007414
5.129554
[ "s050839875", "s538599470" ]
u919633157
p03837
python
s422227729
s906294194
261
187
44,652
14,764
Accepted
Accepted
28.35
n,m=list(map(int,input().split())) d=[[float('inf') for i in range(n)] for i in range(n)] r=[list(map(int,input().split())) for i in range(m)] def wf(d): for k in range(n): for i in range(n): for j in range(n): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) return d for u,v,c in r: u,v=u-1,v-1 d[u][v]=d[v][u]=c wf(d) cnt=0 for u,v,c in r: u,v=u-1,v-1 if d[u][v]!=c: cnt+=1 print(cnt)
n,m=list(map(int,input().split())) d=[[float('inf') for i in range(n)] for i in range(n)] r=[list(map(int,input().split())) for i in range(m)] from scipy.sparse.csgraph import floyd_warshall for u,v,c in r: u,v=u-1,v-1 d[u][v]=d[v][u]=c d=floyd_warshall(d).tolist() cnt=0 for u,v,c in r: u,v=u-1,v-1 if d[u][v]!=c: cnt+=1 print(cnt)
24
18
465
371
n, m = list(map(int, input().split())) d = [[float("inf") for i in range(n)] for i in range(n)] r = [list(map(int, input().split())) for i in range(m)] def wf(d): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d for u, v, c in r: u, v = u - 1, v - 1 d[u][v] = d[v][u] = c wf(d) cnt = 0 for u, v, c in r: u, v = u - 1, v - 1 if d[u][v] != c: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) d = [[float("inf") for i in range(n)] for i in range(n)] r = [list(map(int, input().split())) for i in range(m)] from scipy.sparse.csgraph import floyd_warshall for u, v, c in r: u, v = u - 1, v - 1 d[u][v] = d[v][u] = c d = floyd_warshall(d).tolist() cnt = 0 for u, v, c in r: u, v = u - 1, v - 1 if d[u][v] != c: cnt += 1 print(cnt)
false
25
[ "-", "-", "-def wf(d):", "- for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- d[i][j] = min(d[i][j], d[i][k] + d[k][j])", "- return d", "-", "+from scipy.sparse.csgraph import floyd_warshall", "-wf(d)", "+d = floyd_warshall(d).tolist()" ]
false
0.046978
0.432689
0.108572
[ "s422227729", "s906294194" ]
u226108478
p02767
python
s253633838
s769991343
26
20
2,940
3,060
Accepted
Accepted
23.08
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) x = list(map(int, input().split())) ans = float('inf') for p in range(-100, 201): summed = 0 for xi in x: summed += (xi - p) ** 2 ans = min(ans, summed) print(ans) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) x = list(map(int, input().split())) ans = float('inf') # KeyInsight: # xの座標の最小値から最大値までを探索すればよい # See: https://img.atcoder.jp/abc156/editorial.pdf left = min(x) right = max(x) for p in range(left, right + 1): summed = 0 for xi in x: summed += (xi - p) ** 2 ans = min(ans, summed) print(ans) if __name__ == '__main__': main()
21
27
339
492
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) x = list(map(int, input().split())) ans = float("inf") for p in range(-100, 201): summed = 0 for xi in x: summed += (xi - p) ** 2 ans = min(ans, summed) print(ans) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): n = int(eval(input())) x = list(map(int, input().split())) ans = float("inf") # KeyInsight: # xの座標の最小値から最大値までを探索すればよい # See: https://img.atcoder.jp/abc156/editorial.pdf left = min(x) right = max(x) for p in range(left, right + 1): summed = 0 for xi in x: summed += (xi - p) ** 2 ans = min(ans, summed) print(ans) if __name__ == "__main__": main()
false
22.222222
[ "- for p in range(-100, 201):", "+ # KeyInsight:", "+ # xの座標の最小値から最大値までを探索すればよい", "+ # See: https://img.atcoder.jp/abc156/editorial.pdf", "+ left = min(x)", "+ right = max(x)", "+ for p in range(left, right + 1):" ]
false
0.043927
0.046169
0.951435
[ "s253633838", "s769991343" ]
u127499732
p03044
python
s268448741
s981345033
510
471
73,448
54,596
Accepted
Accepted
7.65
def main(): from collections import deque, defaultdict n, *uvw = list(map(int, open(0).read().split())) l = defaultdict(dict) g = [[] for _ in range(n + 1)] for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]): g[u].append(v) g[v].append(u) l[u].update({v: w % 2}) l[v].update({u: w % 2}) l[0].update({1: 0}) vis = [False] * (n + 1) col = [0] * (n + 1) q = deque() q.append([0, 1, 0]) while q: i, j, k = q.popleft() if vis[j]: continue vis[j] = True c = k if l[i][j] == 0 else 1 - k col[j] = c for x in g[j]: q.appendleft([j, x, c]) ans = '\n'.join(map(str, col[1:])) print(ans) if __name__ == '__main__': main()
def main(): from collections import deque, defaultdict n, *uvw = map(int, open(0).read().split()) l = defaultdict(dict) g = [[] for _ in range(n + 1)] for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]): g[u].append(v) g[v].append(u) l[u].update({v: w % 2}) l[0].update({1: 0}) vis = [False] * (n + 1) col = [0] * (n + 1) q = deque() q.append([0, 1, 0]) while q: i, j, k = q.popleft() if vis[j]: continue vis[j] = True c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k col[j] = c for x in g[j]: q.appendleft([j, x, c]) print(*col[1:], sep='\n') if __name__ == '__main__': main()
37
35
810
768
def main(): from collections import deque, defaultdict n, *uvw = list(map(int, open(0).read().split())) l = defaultdict(dict) g = [[] for _ in range(n + 1)] for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]): g[u].append(v) g[v].append(u) l[u].update({v: w % 2}) l[v].update({u: w % 2}) l[0].update({1: 0}) vis = [False] * (n + 1) col = [0] * (n + 1) q = deque() q.append([0, 1, 0]) while q: i, j, k = q.popleft() if vis[j]: continue vis[j] = True c = k if l[i][j] == 0 else 1 - k col[j] = c for x in g[j]: q.appendleft([j, x, c]) ans = "\n".join(map(str, col[1:])) print(ans) if __name__ == "__main__": main()
def main(): from collections import deque, defaultdict n, *uvw = map(int, open(0).read().split()) l = defaultdict(dict) g = [[] for _ in range(n + 1)] for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]): g[u].append(v) g[v].append(u) l[u].update({v: w % 2}) l[0].update({1: 0}) vis = [False] * (n + 1) col = [0] * (n + 1) q = deque() q.append([0, 1, 0]) while q: i, j, k = q.popleft() if vis[j]: continue vis[j] = True c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k col[j] = c for x in g[j]: q.appendleft([j, x, c]) print(*col[1:], sep="\n") if __name__ == "__main__": main()
false
5.405405
[ "- n, *uvw = list(map(int, open(0).read().split()))", "+ n, *uvw = map(int, open(0).read().split())", "- l[v].update({u: w % 2})", "- c = k if l[i][j] == 0 else 1 - k", "+ c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k", "- ans = \"\\n\".join(map(str, col[1:]))", "- print(ans)", "+ print(*col[1:], sep=\"\\n\")" ]
false
0.036411
0.03577
1.017927
[ "s268448741", "s981345033" ]
u396495667
p04012
python
s339736369
s399336579
20
17
2,940
2,940
Accepted
Accepted
15
w = eval(input()) ans =1 for i in w: if w.count(i) %2 !=0: ans =0 print(('Yes' if ans==1 else 'No'))
w = eval(input()) l = list(set(w)) ans =0 for i in range(len(l)): a = w.count(l[i]) if a %2 !=0: ans =1 print(('Yes' if ans ==0 else 'No'))
6
8
103
146
w = eval(input()) ans = 1 for i in w: if w.count(i) % 2 != 0: ans = 0 print(("Yes" if ans == 1 else "No"))
w = eval(input()) l = list(set(w)) ans = 0 for i in range(len(l)): a = w.count(l[i]) if a % 2 != 0: ans = 1 print(("Yes" if ans == 0 else "No"))
false
25
[ "-ans = 1", "-for i in w:", "- if w.count(i) % 2 != 0:", "- ans = 0", "-print((\"Yes\" if ans == 1 else \"No\"))", "+l = list(set(w))", "+ans = 0", "+for i in range(len(l)):", "+ a = w.count(l[i])", "+ if a % 2 != 0:", "+ ans = 1", "+print((\"Yes\" if ans == 0 else \"No\"))" ]
false
0.068647
0.067264
1.020557
[ "s339736369", "s399336579" ]
u941753895
p03416
python
s645083097
s045706909
76
53
2,940
2,940
Accepted
Accepted
30.26
a,b=list(map(int,input().split())) x=0 for i in range(a,b+1): if str(i)[:2]==str(i)[3:5][::-1]: x+=1 print(x)
# 入力 A,B=list(map(int,input().split())) c=0 for i in range(A,B+1): i=str(i) # 1桁目と5桁目が一致する # かつ2桁目と4桁目が一致する場合 if i[0]==i[4] and i[1]==i[3]: c+=1 # 出力 print(c)
6
14
111
180
a, b = list(map(int, input().split())) x = 0 for i in range(a, b + 1): if str(i)[:2] == str(i)[3:5][::-1]: x += 1 print(x)
# 入力 A, B = list(map(int, input().split())) c = 0 for i in range(A, B + 1): i = str(i) # 1桁目と5桁目が一致する # かつ2桁目と4桁目が一致する場合 if i[0] == i[4] and i[1] == i[3]: c += 1 # 出力 print(c)
false
57.142857
[ "-a, b = list(map(int, input().split()))", "-x = 0", "-for i in range(a, b + 1):", "- if str(i)[:2] == str(i)[3:5][::-1]:", "- x += 1", "-print(x)", "+# 入力", "+A, B = list(map(int, input().split()))", "+c = 0", "+for i in range(A, B + 1):", "+ i = str(i)", "+ # 1桁目と5桁目が一致する", "+ # かつ2桁目と4桁目が一致する場合", "+ if i[0] == i[4] and i[1] == i[3]:", "+ c += 1", "+# 出力", "+print(c)" ]
false
0.063786
0.052925
1.205222
[ "s645083097", "s045706909" ]
u216015528
p02861
python
s822392059
s982571953
204
29
9,132
9,136
Accepted
Accepted
85.78
#!/usr/bin/env python3 def main(): from itertools import permutations from math import sqrt N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] ans = 0 cnt = 0 for can_order in permutations(xy): cnt += 1 for k in range(1, N): xi, yi = can_order[k - 1] xj, yj = can_order[k] ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2) # print(ans / cnt) print(f'{ans / cnt:.10f}') if __name__ == '__main__': main()
#!/usr/bin/env python3 def main(): from itertools import combinations from math import sqrt N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] ans = 0 for can_move in combinations(xy, 2): xi, yi = can_move[0] xj, yj = can_move[1] ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2) print(f'{ans * 2 / N:.10f}') if __name__ == '__main__': main()
22
18
538
438
#!/usr/bin/env python3 def main(): from itertools import permutations from math import sqrt N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] ans = 0 cnt = 0 for can_order in permutations(xy): cnt += 1 for k in range(1, N): xi, yi = can_order[k - 1] xj, yj = can_order[k] ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2) # print(ans / cnt) print(f"{ans / cnt:.10f}") if __name__ == "__main__": main()
#!/usr/bin/env python3 def main(): from itertools import combinations from math import sqrt N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] ans = 0 for can_move in combinations(xy, 2): xi, yi = can_move[0] xj, yj = can_move[1] ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2) print(f"{ans * 2 / N:.10f}") if __name__ == "__main__": main()
false
18.181818
[ "- from itertools import permutations", "+ from itertools import combinations", "- cnt = 0", "- for can_order in permutations(xy):", "- cnt += 1", "- for k in range(1, N):", "- xi, yi = can_order[k - 1]", "- xj, yj = can_order[k]", "- ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)", "- # print(ans / cnt)", "- print(f\"{ans / cnt:.10f}\")", "+ for can_move in combinations(xy, 2):", "+ xi, yi = can_move[0]", "+ xj, yj = can_move[1]", "+ ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)", "+ print(f\"{ans * 2 / N:.10f}\")" ]
false
0.04141
0.039178
1.056954
[ "s822392059", "s982571953" ]
u019489252
p02610
python
s273003434
s202037434
951
876
50,744
51,340
Accepted
Accepted
7.89
from heapq import* i=input for s in[0]*int(i()): n,x,*y=int(i()),[] for _ in'_'*n:k,l,r=t=[*list(map(int,i().split()))];x+=[t]*(l>r);y+=[[n-k,r,l]]*(l<=r) for x in x,y: x.sort();h=[] for k,l,r in x: s+=r if k:s+=l-r;heappush(h,l-r) if len(h)>k:s-=heappop(h) print(s)
from heapq import* i=input for s in[0]*int(i()): n,*x=int(i()),[],[] for _ in'_'*n:k,l,r=t=[*list(map(int,i().split()))];x[l>r]+=[[[n-k,r,l],t][l>r]] for x in x: h=[] for k,l,r in sorted(x):heappush(h,l-r);s+=l-(k<len(h)and heappop(h)) print(s)
12
9
288
254
from heapq import * i = input for s in [0] * int(i()): n, x, *y = int(i()), [] for _ in "_" * n: k, l, r = t = [*list(map(int, i().split()))] x += [t] * (l > r) y += [[n - k, r, l]] * (l <= r) for x in x, y: x.sort() h = [] for k, l, r in x: s += r if k: s += l - r heappush(h, l - r) if len(h) > k: s -= heappop(h) print(s)
from heapq import * i = input for s in [0] * int(i()): n, *x = int(i()), [], [] for _ in "_" * n: k, l, r = t = [*list(map(int, i().split()))] x[l > r] += [[[n - k, r, l], t][l > r]] for x in x: h = [] for k, l, r in sorted(x): heappush(h, l - r) s += l - (k < len(h) and heappop(h)) print(s)
false
25
[ "- n, x, *y = int(i()), []", "+ n, *x = int(i()), [], []", "- x += [t] * (l > r)", "- y += [[n - k, r, l]] * (l <= r)", "- for x in x, y:", "- x.sort()", "+ x[l > r] += [[[n - k, r, l], t][l > r]]", "+ for x in x:", "- for k, l, r in x:", "- s += r", "- if k:", "- s += l - r", "- heappush(h, l - r)", "- if len(h) > k:", "- s -= heappop(h)", "+ for k, l, r in sorted(x):", "+ heappush(h, l - r)", "+ s += l - (k < len(h) and heappop(h))" ]
false
0.044153
0.042518
1.038467
[ "s273003434", "s202037434" ]
u869790980
p02959
python
s860344153
s638796348
139
107
50,004
49,128
Accepted
Accepted
23.02
import collections n = int(input()) cities = collections.deque(list(map(int, input().split(' ')))) q = collections.deque(list(map(int, input().split(' ')))) res = 0 p = 0 while(q): w = q.pop() if cities[-1]: m = min(w, cities[-1]) cities[-1]-=m w -= m res += m cities.pop() if cities[-1]: m = min(w, cities[-1]) cities[-1]-=m w -= m res += m print(res)
import collections n = int(input()) cities,q = collections.deque(list(map(int, input().split(' ')))), collections.deque(list(map(int, input().split(' ')))) res = 0 while(q): u = q.pop() for _ in range(2): c = cities.pop() m = min(u, c) c -=m u -= m res += m cities.append(c) print(res)
20
14
390
310
import collections n = int(input()) cities = collections.deque(list(map(int, input().split(" ")))) q = collections.deque(list(map(int, input().split(" ")))) res = 0 p = 0 while q: w = q.pop() if cities[-1]: m = min(w, cities[-1]) cities[-1] -= m w -= m res += m cities.pop() if cities[-1]: m = min(w, cities[-1]) cities[-1] -= m w -= m res += m print(res)
import collections n = int(input()) cities, q = collections.deque(list(map(int, input().split(" ")))), collections.deque( list(map(int, input().split(" "))) ) res = 0 while q: u = q.pop() for _ in range(2): c = cities.pop() m = min(u, c) c -= m u -= m res += m cities.append(c) print(res)
false
30
[ "-cities = collections.deque(list(map(int, input().split(\" \"))))", "-q = collections.deque(list(map(int, input().split(\" \"))))", "+cities, q = collections.deque(list(map(int, input().split(\" \")))), collections.deque(", "+ list(map(int, input().split(\" \")))", "+)", "-p = 0", "- w = q.pop()", "- if cities[-1]:", "- m = min(w, cities[-1])", "- cities[-1] -= m", "- w -= m", "+ u = q.pop()", "+ for _ in range(2):", "+ c = cities.pop()", "+ m = min(u, c)", "+ c -= m", "+ u -= m", "- cities.pop()", "- if cities[-1]:", "- m = min(w, cities[-1])", "- cities[-1] -= m", "- w -= m", "- res += m", "+ cities.append(c)" ]
false
0.072445
0.044452
1.629731
[ "s860344153", "s638796348" ]
u816631826
p02771
python
s988974630
s604598597
160
17
13,220
2,940
Accepted
Accepted
89.38
import numpy A,B,C = input().split() a = A b = B c = C if (a==b and a==c): print("No") elif (a==b or b==c or a==c): print("Yes") elif (a!=b or b!=c): print("No")
a, b, c = list (map (int, input ().split ())) k = a ^ b ^ c print(("Yes" if ((k == a) + (k == b) + (k == c) == 1) else "No"))
11
3
183
126
import numpy A, B, C = input().split() a = A b = B c = C if a == b and a == c: print("No") elif a == b or b == c or a == c: print("Yes") elif a != b or b != c: print("No")
a, b, c = list(map(int, input().split())) k = a ^ b ^ c print(("Yes" if ((k == a) + (k == b) + (k == c) == 1) else "No"))
false
72.727273
[ "-import numpy", "-", "-A, B, C = input().split()", "-a = A", "-b = B", "-c = C", "-if a == b and a == c:", "- print(\"No\")", "-elif a == b or b == c or a == c:", "- print(\"Yes\")", "-elif a != b or b != c:", "- print(\"No\")", "+a, b, c = list(map(int, input().split()))", "+k = a ^ b ^ c", "+print((\"Yes\" if ((k == a) + (k == b) + (k == c) == 1) else \"No\"))" ]
false
0.033149
0.030914
1.072292
[ "s988974630", "s604598597" ]
u404244809
p03043
python
s754528920
s946663909
226
52
5,548
5,548
Accepted
Accepted
76.99
import sys from itertools import combinations, permutations, product, combinations_with_replacement, accumulate from heapq import heapify, heappop, heappush, heappushpop from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd from fractions import gcd from operator import mul from functools import reduce sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') LINF = 2**63-1 NIL = -LINF MOD = 10**9+7 MGN = 4 def AST(exp: bool, msg: str = ""): assert exp, msg def TAST(exp: bool, msg = ""): if exp is False: print("TAssertionError:", msg) while exp is False: pass def EPR(msg = ""): print(msg, file=sys.stderr) def II(): return int(input()) def IF(): return float(input()) def IS(): return input().replace('\n', '') def ILCI(n: int): return [II() for _ in range(n)] def ILCF(n: int): return [IF() for _ in range(n)] def ILI(): return list(map(int, input().split())) def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)] def ILF(): return list(map(float, input().split())) def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)] def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst)) def DEC(lst: list): return list(map(lambda x: x-1, lst)) def INC(lst: list): return list(map(lambda x: x+1, lst)) def main(): N, K = ILI() ans = 0.0 for i in range(1,N+1): scr = i # 現在のスコア pb = 1.0 # 現在のスコアとなる確率 win = True # 勝ち続けているか while True: if K <= scr: # 勝ち EPR(scr) break elif 0 < scr < K: scr *= 2 pb *= 0.5 else: # 負け scr = 0 win = False break if win: ans += pb / N print("{:.12}".format(ans)) if __name__ == '__main__': main()
import sys from itertools import combinations, permutations, product, combinations_with_replacement, accumulate from heapq import heapify, heappop, heappush, heappushpop from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd from fractions import gcd from operator import mul from functools import reduce sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') LINF = 2**63-1 NIL = -LINF MOD = 10**9+7 MGN = 4 def AST(exp: bool, msg: str = ""): assert exp, msg def TAST(exp: bool, msg = ""): if exp is False: print("TAssertionError:", msg) while exp is False: pass def EPR(msg): print(msg, file=sys.stderr) def II(): return int(input()) def IF(): return float(input()) def IS(): return input().replace('\n', '') def ILCI(n: int): return [II() for _ in range(n)] def ILCF(n: int): return [IF() for _ in range(n)] def ILI(): return list(map(int, input().split())) def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)] def ILF(): return list(map(float, input().split())) def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)] def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst)) def DEC(lst: list): return list(map(lambda x: x-1, lst)) def INC(lst: list): return list(map(lambda x: x+1, lst)) def main(): N, K = ILI() ans = 0.0 for i in range(1,N+1): # サイコロの出た目 scr = i # 現在のスコア pb = 1.0 # 現在のスコアとなる確率 if K <= scr: # 最初から勝っていたら ans += pb/N continue # n 回コインを投げて勝ち続けると得点は # scr * 2**n # 勝ちとなるのは # scr * 2**n >= K n = ceil(log(K/scr, 2)) ans += pow(0.5, n) / N print("{:.12}".format(ans)) if __name__ == '__main__': main()
63
60
2,026
1,928
import sys from itertools import ( combinations, permutations, product, combinations_with_replacement, accumulate, ) from heapq import heapify, heappop, heappush, heappushpop from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from math import sqrt, log, floor, ceil, factorial, cos, sin, pi # , gcd from fractions import gcd from operator import mul from functools import reduce sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float("inf") LINF = 2**63 - 1 NIL = -LINF MOD = 10**9 + 7 MGN = 4 def AST(exp: bool, msg: str = ""): assert exp, msg def TAST(exp: bool, msg=""): if exp is False: print("TAssertionError:", msg) while exp is False: pass def EPR(msg=""): print(msg, file=sys.stderr) def II(): return int(input()) def IF(): return float(input()) def IS(): return input().replace("\n", "") def ILCI(n: int): return [II() for _ in range(n)] def ILCF(n: int): return [IF() for _ in range(n)] def ILI(): return list(map(int, input().split())) def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)] def ILF(): return list(map(float, input().split())) def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)] def LTOS(lst: list, sep: str = " "): return sep.join(map(str, lst)) def DEC(lst: list): return list(map(lambda x: x - 1, lst)) def INC(lst: list): return list(map(lambda x: x + 1, lst)) def main(): N, K = ILI() ans = 0.0 for i in range(1, N + 1): scr = i # 現在のスコア pb = 1.0 # 現在のスコアとなる確率 win = True # 勝ち続けているか while True: if K <= scr: # 勝ち EPR(scr) break elif 0 < scr < K: scr *= 2 pb *= 0.5 else: # 負け scr = 0 win = False break if win: ans += pb / N print("{:.12}".format(ans)) if __name__ == "__main__": main()
import sys from itertools import ( combinations, permutations, product, combinations_with_replacement, accumulate, ) from heapq import heapify, heappop, heappush, heappushpop from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from math import sqrt, log, floor, ceil, factorial, cos, sin, pi # , gcd from fractions import gcd from operator import mul from functools import reduce sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float("inf") LINF = 2**63 - 1 NIL = -LINF MOD = 10**9 + 7 MGN = 4 def AST(exp: bool, msg: str = ""): assert exp, msg def TAST(exp: bool, msg=""): if exp is False: print("TAssertionError:", msg) while exp is False: pass def EPR(msg): print(msg, file=sys.stderr) def II(): return int(input()) def IF(): return float(input()) def IS(): return input().replace("\n", "") def ILCI(n: int): return [II() for _ in range(n)] def ILCF(n: int): return [IF() for _ in range(n)] def ILI(): return list(map(int, input().split())) def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)] def ILF(): return list(map(float, input().split())) def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)] def LTOS(lst: list, sep: str = " "): return sep.join(map(str, lst)) def DEC(lst: list): return list(map(lambda x: x - 1, lst)) def INC(lst: list): return list(map(lambda x: x + 1, lst)) def main(): N, K = ILI() ans = 0.0 for i in range(1, N + 1): # サイコロの出た目 scr = i # 現在のスコア pb = 1.0 # 現在のスコアとなる確率 if K <= scr: # 最初から勝っていたら ans += pb / N continue # n 回コインを投げて勝ち続けると得点は # scr * 2**n # 勝ちとなるのは # scr * 2**n >= K n = ceil(log(K / scr, 2)) ans += pow(0.5, n) / N print("{:.12}".format(ans)) if __name__ == "__main__": main()
false
4.761905
[ "-def EPR(msg=\"\"):", "+def EPR(msg):", "- for i in range(1, N + 1):", "+ for i in range(1, N + 1): # サイコロの出た目", "- win = True # 勝ち続けているか", "- while True:", "- if K <= scr: # 勝ち", "- EPR(scr)", "- break", "- elif 0 < scr < K:", "- scr *= 2", "- pb *= 0.5", "- else: # 負け", "- scr = 0", "- win = False", "- break", "- if win:", "+ if K <= scr: # 最初から勝っていたら", "+ continue", "+ # n 回コインを投げて勝ち続けると得点は", "+ # scr * 2**n", "+ # 勝ちとなるのは", "+ # scr * 2**n >= K", "+ n = ceil(log(K / scr, 2))", "+ ans += pow(0.5, n) / N" ]
false
0.248317
0.046886
5.29621
[ "s754528920", "s946663909" ]
u545368057
p03108
python
s684423177
s078531637
900
703
23,312
44,684
Accepted
Accepted
21.89
class UnionFind: def __init__(self, n): self.par = [-1 for i in range(n+1)] self.size = [1 for i in range(n+1)] # 検索 def find(self, x): path = [] curr = x # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら) while self.par[curr] != -1: # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に) path.append(curr) curr = self.par[curr] for p in path: self.par[p] = curr return curr # 結合 def union(self, x, y): x = self.find(x) y = self.find(y) self.par[y] = x self.size[x] += self.size[y] self.size[y] = 1 # 判定 def judge(self,x,y): return self.find(x) == self.find(y) N, M = list(map(int,input().split())) pairs = [tuple(map(int,input().split())) for _ in range(M)] uf = UnionFind(N) p = N*(N-1)//2 ans = [p] for a,b in reversed(pairs[1:]): if not uf.judge(a,b): size_a = uf.size[uf.find(a)] size_b = uf.size[uf.find(b)] uf.union(a,b) size_a_update = uf.size[uf.find(a)] p = p + size_a*(size_a-1)//2 + size_b*(size_b-1)//2 - size_a_update*(size_a_update-1)//2 ans.append(p) for a in reversed(ans): print(a)
n, m = list(map(int, input().split())) # 逆順にunionfind from collections import defaultdict class UnionFind: def __init__(self, n): class KeyDict(dict): # 辞書にないときの対応 def __missing__(self,key): self[key] = key return key self.parent = KeyDict() self.rank = defaultdict(int) self.weight = defaultdict(lambda:1) # 根を探す def find(self, x): if self.parent[x] == x: return x else: # 経路圧縮 # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に) y = self.find(self.parent[x]) self.parent[x] = y #親の置き換え(圧縮) return self.parent[x] # 結合 def union(self, x, y): x = self.find(x) y = self.find(y) # 低い方を高い方につなげる(親のランクによる) if self.rank[x] < self.rank[y]: self.parent[x] = y self.weight[y] += self.weight[x] self.weight[x] = 0 else: self.parent[y] = x self.weight[x] += self.weight[y] self.weight[y] = 0 if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 判定 def judge(self, x, y): return self.find(x) == self.find(y) ps = [] for i in range(m): a,b = list(map(int, input().split())) a -= 1 b -= 1 ps.append((a,b)) uf = UnionFind(n) now = n*(n-1)//2 ans = [now] for a, b in ps[::-1]: if not uf.judge(a,b): n1 = uf.weight[uf.find(a)] n2 = uf.weight[uf.find(b)] now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2 uf.union(a,b) ans.append(now) for a in ans[::-1][1:]: print(a)
46
67
1,242
1,715
class UnionFind: def __init__(self, n): self.par = [-1 for i in range(n + 1)] self.size = [1 for i in range(n + 1)] # 検索 def find(self, x): path = [] curr = x # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら) while self.par[curr] != -1: # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に) path.append(curr) curr = self.par[curr] for p in path: self.par[p] = curr return curr # 結合 def union(self, x, y): x = self.find(x) y = self.find(y) self.par[y] = x self.size[x] += self.size[y] self.size[y] = 1 # 判定 def judge(self, x, y): return self.find(x) == self.find(y) N, M = list(map(int, input().split())) pairs = [tuple(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) p = N * (N - 1) // 2 ans = [p] for a, b in reversed(pairs[1:]): if not uf.judge(a, b): size_a = uf.size[uf.find(a)] size_b = uf.size[uf.find(b)] uf.union(a, b) size_a_update = uf.size[uf.find(a)] p = ( p + size_a * (size_a - 1) // 2 + size_b * (size_b - 1) // 2 - size_a_update * (size_a_update - 1) // 2 ) ans.append(p) for a in reversed(ans): print(a)
n, m = list(map(int, input().split())) # 逆順にunionfind from collections import defaultdict class UnionFind: def __init__(self, n): class KeyDict(dict): # 辞書にないときの対応 def __missing__(self, key): self[key] = key return key self.parent = KeyDict() self.rank = defaultdict(int) self.weight = defaultdict(lambda: 1) # 根を探す def find(self, x): if self.parent[x] == x: return x else: # 経路圧縮 # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に) y = self.find(self.parent[x]) self.parent[x] = y # 親の置き換え(圧縮) return self.parent[x] # 結合 def union(self, x, y): x = self.find(x) y = self.find(y) # 低い方を高い方につなげる(親のランクによる) if self.rank[x] < self.rank[y]: self.parent[x] = y self.weight[y] += self.weight[x] self.weight[x] = 0 else: self.parent[y] = x self.weight[x] += self.weight[y] self.weight[y] = 0 if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 判定 def judge(self, x, y): return self.find(x) == self.find(y) ps = [] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 ps.append((a, b)) uf = UnionFind(n) now = n * (n - 1) // 2 ans = [now] for a, b in ps[::-1]: if not uf.judge(a, b): n1 = uf.weight[uf.find(a)] n2 = uf.weight[uf.find(b)] now += n1 * (n1 - 1) // 2 + n2 * (n2 - 1) // 2 - (n1 + n2) * (n1 + n2 - 1) // 2 uf.union(a, b) ans.append(now) for a in ans[::-1][1:]: print(a)
false
31.343284
[ "+n, m = list(map(int, input().split()))", "+# 逆順にunionfind", "+from collections import defaultdict", "+", "+", "- self.par = [-1 for i in range(n + 1)]", "- self.size = [1 for i in range(n + 1)]", "+ class KeyDict(dict):", "+ # 辞書にないときの対応", "+ def __missing__(self, key):", "+ self[key] = key", "+ return key", "- # 検索", "+ self.parent = KeyDict()", "+ self.rank = defaultdict(int)", "+ self.weight = defaultdict(lambda: 1)", "+", "+ # 根を探す", "- path = []", "- curr = x", "- # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら)", "- while self.par[curr] != -1:", "+ if self.parent[x] == x:", "+ return x", "+ else:", "+ # 経路圧縮", "- path.append(curr)", "- curr = self.par[curr]", "- for p in path:", "- self.par[p] = curr", "- return curr", "+ y = self.find(self.parent[x])", "+ self.parent[x] = y # 親の置き換え(圧縮)", "+ return self.parent[x]", "- self.par[y] = x", "- self.size[x] += self.size[y]", "- self.size[y] = 1", "+ # 低い方を高い方につなげる(親のランクによる)", "+ if self.rank[x] < self.rank[y]:", "+ self.parent[x] = y", "+ self.weight[y] += self.weight[x]", "+ self.weight[x] = 0", "+ else:", "+ self.parent[y] = x", "+ self.weight[x] += self.weight[y]", "+ self.weight[y] = 0", "+ if self.rank[x] == self.rank[y]:", "+ self.rank[x] += 1", "-N, M = list(map(int, input().split()))", "-pairs = [tuple(map(int, input().split())) for _ in range(M)]", "-uf = UnionFind(N)", "-p = N * (N - 1) // 2", "-ans = [p]", "-for a, b in reversed(pairs[1:]):", "+ps = []", "+for i in range(m):", "+ a, b = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ ps.append((a, b))", "+uf = UnionFind(n)", "+now = n * (n - 1) // 2", "+ans = [now]", "+for a, b in ps[::-1]:", "- size_a = uf.size[uf.find(a)]", "- size_b = uf.size[uf.find(b)]", "+ n1 = uf.weight[uf.find(a)]", "+ n2 = uf.weight[uf.find(b)]", "+ now += n1 * (n1 - 1) // 2 + n2 * (n2 - 1) // 2 - (n1 + n2) * (n1 + n2 - 1) // 2", "- size_a_update = uf.size[uf.find(a)]", "- p = (", "- p", "- + size_a * (size_a - 1) // 2", "- + size_b * (size_b - 1) // 2", "- - size_a_update * (size_a_update - 1) // 2", "- )", "- ans.append(p)", "-for a in reversed(ans):", "+ ans.append(now)", "+for a in ans[::-1][1:]:" ]
false
0.043689
0.042926
1.017772
[ "s684423177", "s078531637" ]
u600402037
p02769
python
s268865969
s851423503
1,902
282
51,524
53,576
Accepted
Accepted
85.17
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 # K回の移動が終わった後、人がいる部屋の数はNからN-K def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD def cumprod(arr, MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10 ** 6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() answer = 0 for x in range(N, max(0, N-K-1), -1): # x個の家には1人以上いるのでこの人たちは除く can_move = N - x # x-1の壁をcan_move+1の場所に入れる answer += cmb(N, x) * cmb(x - 1 + can_move, can_move) answer %= MOD print((answer % MOD)) # 31
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD def cumprod(arr, MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10 ** 6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() K = min(K, N-1) x = fact[N] * fact_inv[0:K+1] % MOD * fact_inv[N-K:N+1][::-1] % MOD y = fact[N-1] * fact_inv[0:K+1] % MOD * fact_inv[N-K-1:N][::-1] % MOD answer = (x * y % MOD).sum() print((answer % MOD))
45
39
1,201
1,134
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10**9 + 7 # K回の移動が終わった後、人がいる部屋の数はNからN-K def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() answer = 0 for x in range(N, max(0, N - K - 1), -1): # x個の家には1人以上いるのでこの人たちは除く can_move = N - x # x-1の壁をcan_move+1の場所に入れる answer += cmb(N, x) * cmb(x - 1 + can_move, can_move) answer %= MOD print((answer % MOD)) # 31
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10**9 + 7 def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() K = min(K, N - 1) x = fact[N] * fact_inv[0 : K + 1] % MOD * fact_inv[N - K : N + 1][::-1] % MOD y = fact[N - 1] * fact_inv[0 : K + 1] % MOD * fact_inv[N - K - 1 : N][::-1] % MOD answer = (x * y % MOD).sum() print((answer % MOD))
false
13.333333
[ "-# K回の移動が終わった後、人がいる部屋の数はNからN-K", "+", "+", "-answer = 0", "-for x in range(N, max(0, N - K - 1), -1):", "- # x個の家には1人以上いるのでこの人たちは除く", "- can_move = N - x", "- # x-1の壁をcan_move+1の場所に入れる", "- answer += cmb(N, x) * cmb(x - 1 + can_move, can_move)", "- answer %= MOD", "+K = min(K, N - 1)", "+x = fact[N] * fact_inv[0 : K + 1] % MOD * fact_inv[N - K : N + 1][::-1] % MOD", "+y = fact[N - 1] * fact_inv[0 : K + 1] % MOD * fact_inv[N - K - 1 : N][::-1] % MOD", "+answer = (x * y % MOD).sum()", "-# 31" ]
false
0.432612
0.294689
1.46803
[ "s268865969", "s851423503" ]
u977389981
p03854
python
s464768427
s879043327
36
28
3,956
3,956
Accepted
Accepted
22.22
s = list(eval(input())) while len(s) > 0: if ''.join(s[-7:]) == 'dreamer': del s[-7:] elif ''.join(s[-6:]) == 'eraser': del s[-6:] elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase': del s[-5:] else: break print(('YES' if len(s) == 0 else 'NO'))
S = list(eval(input())) a = list('dream') b = list('dreamer') c = list('erase') d = list('eraser') while True: if S[-5:] == a: del S[-5:] elif S[-7:] == b: del S[-7:] elif S[-5:] == c: del S[-5:] elif S[-6:] == d: del S[-6:] else: break if len(S) == 0: print('YES') else: print('NO')
12
22
308
376
s = list(eval(input())) while len(s) > 0: if "".join(s[-7:]) == "dreamer": del s[-7:] elif "".join(s[-6:]) == "eraser": del s[-6:] elif "".join(s[-5:]) == "dream" or "".join(s[-5:]) == "erase": del s[-5:] else: break print(("YES" if len(s) == 0 else "NO"))
S = list(eval(input())) a = list("dream") b = list("dreamer") c = list("erase") d = list("eraser") while True: if S[-5:] == a: del S[-5:] elif S[-7:] == b: del S[-7:] elif S[-5:] == c: del S[-5:] elif S[-6:] == d: del S[-6:] else: break if len(S) == 0: print("YES") else: print("NO")
false
45.454545
[ "-s = list(eval(input()))", "-while len(s) > 0:", "- if \"\".join(s[-7:]) == \"dreamer\":", "- del s[-7:]", "- elif \"\".join(s[-6:]) == \"eraser\":", "- del s[-6:]", "- elif \"\".join(s[-5:]) == \"dream\" or \"\".join(s[-5:]) == \"erase\":", "- del s[-5:]", "+S = list(eval(input()))", "+a = list(\"dream\")", "+b = list(\"dreamer\")", "+c = list(\"erase\")", "+d = list(\"eraser\")", "+while True:", "+ if S[-5:] == a:", "+ del S[-5:]", "+ elif S[-7:] == b:", "+ del S[-7:]", "+ elif S[-5:] == c:", "+ del S[-5:]", "+ elif S[-6:] == d:", "+ del S[-6:]", "-print((\"YES\" if len(s) == 0 else \"NO\"))", "+if len(S) == 0:", "+ print(\"YES\")", "+else:", "+ print(\"NO\")" ]
false
0.034355
0.034072
1.008289
[ "s464768427", "s879043327" ]
u571281863
p02628
python
s768880397
s516930353
34
25
9,208
9,200
Accepted
Accepted
26.47
N,K=list(map(int,input().split())) P=sorted(map(int,input().split())) r=0 for i in range(K): r+=P[i] print(r)
N,K=list(map(int,input().split())) P=sorted(map(int,input().split())) print((sum(P[:K])))
6
3
110
83
N, K = list(map(int, input().split())) P = sorted(map(int, input().split())) r = 0 for i in range(K): r += P[i] print(r)
N, K = list(map(int, input().split())) P = sorted(map(int, input().split())) print((sum(P[:K])))
false
50
[ "-r = 0", "-for i in range(K):", "- r += P[i]", "-print(r)", "+print((sum(P[:K])))" ]
false
0.058382
0.037188
1.569906
[ "s768880397", "s516930353" ]
u670180528
p03674
python
s806015424
s075227631
340
260
21,468
16,228
Accepted
Accepted
23.53
from collections import Counter n,*a = list(map(int,open(0).read().split())) dbl = Counter(a).most_common()[0][0] l,r = [i for i,j in enumerate(a) if j==dbl] const = n+l-r m = n + 1 mod = 10**9+7 fac = [1]*(m+1) inv = [1]*(m+1) for i in range(1,m+1): fac[i] = fac[i-1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m-1, -1, -1): inv[i] = inv[i+1] * (i+1) % mod def cmb(n,r): if n<r:return 0 return fac[n] * inv[n-r] * inv[r] % mod for k in range(1,n+2): print(((cmb(n+1,k)-cmb(const,k-1)) % mod))
def main(): n,*a = list(map(int,open(0).read().split())) dbl = sum(a)-n*(n+1)//2 l,r = [i for i,j in enumerate(a) if j==dbl] const = n+l-r m = n + 1 mod = 10**9+7 fac = [1]*(m+1) inv = [1]*(m+1) for i in range(1,m+1): fac[i] = fac[i-1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m-1, -1, -1): inv[i] = inv[i+1] * (i+1) % mod def cmb(n,r): if n<r:return 0 return fac[n] * inv[n-r] * inv[r] % mod for k in range(1,n+2): print(((cmb(n+1,k)-cmb(const,k-1)) % mod)) if __name__=="__main__":main()
19
20
527
544
from collections import Counter n, *a = list(map(int, open(0).read().split())) dbl = Counter(a).most_common()[0][0] l, r = [i for i, j in enumerate(a) if j == dbl] const = n + l - r m = n + 1 mod = 10**9 + 7 fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod def cmb(n, r): if n < r: return 0 return fac[n] * inv[n - r] * inv[r] % mod for k in range(1, n + 2): print(((cmb(n + 1, k) - cmb(const, k - 1)) % mod))
def main(): n, *a = list(map(int, open(0).read().split())) dbl = sum(a) - n * (n + 1) // 2 l, r = [i for i, j in enumerate(a) if j == dbl] const = n + l - r m = n + 1 mod = 10**9 + 7 fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod def cmb(n, r): if n < r: return 0 return fac[n] * inv[n - r] * inv[r] % mod for k in range(1, n + 2): print(((cmb(n + 1, k) - cmb(const, k - 1)) % mod)) if __name__ == "__main__": main()
false
5
[ "-from collections import Counter", "+def main():", "+ n, *a = list(map(int, open(0).read().split()))", "+ dbl = sum(a) - n * (n + 1) // 2", "+ l, r = [i for i, j in enumerate(a) if j == dbl]", "+ const = n + l - r", "+ m = n + 1", "+ mod = 10**9 + 7", "+ fac = [1] * (m + 1)", "+ inv = [1] * (m + 1)", "+ for i in range(1, m + 1):", "+ fac[i] = fac[i - 1] * i % mod", "+ inv[-1] = pow(fac[-1], mod - 2, mod)", "+ for i in range(m - 1, -1, -1):", "+ inv[i] = inv[i + 1] * (i + 1) % mod", "-n, *a = list(map(int, open(0).read().split()))", "-dbl = Counter(a).most_common()[0][0]", "-l, r = [i for i, j in enumerate(a) if j == dbl]", "-const = n + l - r", "-m = n + 1", "-mod = 10**9 + 7", "-fac = [1] * (m + 1)", "-inv = [1] * (m + 1)", "-for i in range(1, m + 1):", "- fac[i] = fac[i - 1] * i % mod", "-inv[-1] = pow(fac[-1], mod - 2, mod)", "-for i in range(m - 1, -1, -1):", "- inv[i] = inv[i + 1] * (i + 1) % mod", "+ def cmb(n, r):", "+ if n < r:", "+ return 0", "+ return fac[n] * inv[n - r] * inv[r] % mod", "+", "+ for k in range(1, n + 2):", "+ print(((cmb(n + 1, k) - cmb(const, k - 1)) % mod))", "-def cmb(n, r):", "- if n < r:", "- return 0", "- return fac[n] * inv[n - r] * inv[r] % mod", "-", "-", "-for k in range(1, n + 2):", "- print(((cmb(n + 1, k) - cmb(const, k - 1)) % mod))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.132539
0.038777
3.417968
[ "s806015424", "s075227631" ]
u437860615
p02832
python
s304447956
s496123094
206
166
25,716
26,268
Accepted
Accepted
19.42
n = int(eval(input())) array = list(map(int, input().split())) bt = 0 #break times i = 0 j = 0 #iterator while i < n: while j < n: if array[j] == i+1: bt += 1 break else: if j == n-1: if i == 0: bt = -1 i = n+1 j = n+1 break else: i = n+1 j = n+1 break j += 1 i +=1 if bt != -1: bt = n - bt print(bt)
n = int(eval(input())) a = list(map(int, input().split())) i = 0 j = 0 bt = 0 while i < n: while j < n - i: if a[i+j] == i+1: bt += 1 break if j + i == n-1: if i == 0: bt = -1 j = n + 1 i = n + 1 j += 1 i += 1 if bt != -1: bt = n - bt print(bt)
32
25
476
333
n = int(eval(input())) array = list(map(int, input().split())) bt = 0 # break times i = 0 j = 0 # iterator while i < n: while j < n: if array[j] == i + 1: bt += 1 break else: if j == n - 1: if i == 0: bt = -1 i = n + 1 j = n + 1 break else: i = n + 1 j = n + 1 break j += 1 i += 1 if bt != -1: bt = n - bt print(bt)
n = int(eval(input())) a = list(map(int, input().split())) i = 0 j = 0 bt = 0 while i < n: while j < n - i: if a[i + j] == i + 1: bt += 1 break if j + i == n - 1: if i == 0: bt = -1 j = n + 1 i = n + 1 j += 1 i += 1 if bt != -1: bt = n - bt print(bt)
false
21.875
[ "-array = list(map(int, input().split()))", "-bt = 0 # break times", "+a = list(map(int, input().split()))", "-j = 0 # iterator", "+j = 0", "+bt = 0", "- while j < n:", "- if array[j] == i + 1:", "+ while j < n - i:", "+ if a[i + j] == i + 1:", "- else:", "- if j == n - 1:", "- if i == 0:", "- bt = -1", "- i = n + 1", "- j = n + 1", "- break", "- else:", "- i = n + 1", "- j = n + 1", "- break", "+ if j + i == n - 1:", "+ if i == 0:", "+ bt = -1", "+ j = n + 1", "+ i = n + 1" ]
false
0.0703
0.100225
0.701422
[ "s304447956", "s496123094" ]
u729133443
p02760
python
s647302514
s129256959
26
18
3,060
3,064
Accepted
Accepted
30.77
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2)) a=eval('list(map(int,input().split())),'*3) exec('b=int(input());a=[[u*(u!=b)for u in t]for t in a];'*int(eval(input()))) a=[[not u for u in t]for t in a] print(('NYoe s'[f(a)|f([t[::-1]for t in zip(*a)])::2]))
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2)) *t,=list(map(int,open(0).read().split())) a=t[:9] s=eval('[0]*3,'*3) for b in t[10:]: if b in a: i=a.index(b) s[i//3][i%3]=1 print(('NYoe s'[f(s)|f([t[::-1]for t in zip(*s)])::2]))
5
9
270
251
f = lambda a: any(all(b) for b in a) | all(a[i][i] for i in (0, 1, 2)) a = eval("list(map(int,input().split()))," * 3) exec("b=int(input());a=[[u*(u!=b)for u in t]for t in a];" * int(eval(input()))) a = [[not u for u in t] for t in a] print(("NYoe s"[f(a) | f([t[::-1] for t in zip(*a)]) :: 2]))
f = lambda a: any(all(b) for b in a) | all(a[i][i] for i in (0, 1, 2)) (*t,) = list(map(int, open(0).read().split())) a = t[:9] s = eval("[0]*3," * 3) for b in t[10:]: if b in a: i = a.index(b) s[i // 3][i % 3] = 1 print(("NYoe s"[f(s) | f([t[::-1] for t in zip(*s)]) :: 2]))
false
44.444444
[ "-a = eval(\"list(map(int,input().split())),\" * 3)", "-exec(\"b=int(input());a=[[u*(u!=b)for u in t]for t in a];\" * int(eval(input())))", "-a = [[not u for u in t] for t in a]", "-print((\"NYoe s\"[f(a) | f([t[::-1] for t in zip(*a)]) :: 2]))", "+(*t,) = list(map(int, open(0).read().split()))", "+a = t[:9]", "+s = eval(\"[0]*3,\" * 3)", "+for b in t[10:]:", "+ if b in a:", "+ i = a.index(b)", "+ s[i // 3][i % 3] = 1", "+print((\"NYoe s\"[f(s) | f([t[::-1] for t in zip(*s)]) :: 2]))" ]
false
0.03202
0.061629
0.519559
[ "s647302514", "s129256959" ]
u901582103
p02684
python
s745207459
s757471415
209
158
32,280
32,216
Accepted
Accepted
24.4
n,k=list(map(int,input().split())) A=list(map(int,input().split())) C=[0]+[-1]*(n-1) p=1 c=0 s=-1 e=-1 for i in range(n): p=A[p-1] c+=1 if C[p-1]==-1: C[p-1]=c else: s=C[p-1] e=c break P=1 if s!=-1 and e!=-1: if k<=s: while k>0: P=A[P-1] k-=1 print(P) else: l=(k-s)%(e-s) k=s+l+1 while k>1: P=A[P-1] k-=1 print(P) else: if k<=n: while k>0: P=A[P-1] k-=1 print(P) else: while n>0: P=A[P-1]
n,k=list(map(int,input().split())) A=list(map(int,input().split())) p=1 if k<=n: for i in range(k): p=A[p-1] print(p) else: D=[0]+[-1]*(n-1) for i in range(n): p=A[p-1] if D[p-1]==-1: D[p-1]=i+1 else: l=D[p-1] r=i+1-D[p-1] m=(k-l)%r+l break p=1 for i in range(m): p=A[p-1] print(p)
39
22
640
424
n, k = list(map(int, input().split())) A = list(map(int, input().split())) C = [0] + [-1] * (n - 1) p = 1 c = 0 s = -1 e = -1 for i in range(n): p = A[p - 1] c += 1 if C[p - 1] == -1: C[p - 1] = c else: s = C[p - 1] e = c break P = 1 if s != -1 and e != -1: if k <= s: while k > 0: P = A[P - 1] k -= 1 print(P) else: l = (k - s) % (e - s) k = s + l + 1 while k > 1: P = A[P - 1] k -= 1 print(P) else: if k <= n: while k > 0: P = A[P - 1] k -= 1 print(P) else: while n > 0: P = A[P - 1]
n, k = list(map(int, input().split())) A = list(map(int, input().split())) p = 1 if k <= n: for i in range(k): p = A[p - 1] print(p) else: D = [0] + [-1] * (n - 1) for i in range(n): p = A[p - 1] if D[p - 1] == -1: D[p - 1] = i + 1 else: l = D[p - 1] r = i + 1 - D[p - 1] m = (k - l) % r + l break p = 1 for i in range(m): p = A[p - 1] print(p)
false
43.589744
[ "-C = [0] + [-1] * (n - 1)", "-c = 0", "-s = -1", "-e = -1", "-for i in range(n):", "- p = A[p - 1]", "- c += 1", "- if C[p - 1] == -1:", "- C[p - 1] = c", "- else:", "- s = C[p - 1]", "- e = c", "- break", "-P = 1", "-if s != -1 and e != -1:", "- if k <= s:", "- while k > 0:", "- P = A[P - 1]", "- k -= 1", "- print(P)", "- else:", "- l = (k - s) % (e - s)", "- k = s + l + 1", "- while k > 1:", "- P = A[P - 1]", "- k -= 1", "- print(P)", "+if k <= n:", "+ for i in range(k):", "+ p = A[p - 1]", "+ print(p)", "- if k <= n:", "- while k > 0:", "- P = A[P - 1]", "- k -= 1", "- print(P)", "- else:", "- while n > 0:", "- P = A[P - 1]", "+ D = [0] + [-1] * (n - 1)", "+ for i in range(n):", "+ p = A[p - 1]", "+ if D[p - 1] == -1:", "+ D[p - 1] = i + 1", "+ else:", "+ l = D[p - 1]", "+ r = i + 1 - D[p - 1]", "+ m = (k - l) % r + l", "+ break", "+ p = 1", "+ for i in range(m):", "+ p = A[p - 1]", "+ print(p)" ]
false
0.046103
0.048513
0.95032
[ "s745207459", "s757471415" ]
u995062424
p03161
python
s038218428
s105187544
1,988
1,624
13,980
20,552
Accepted
Accepted
18.31
def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) DP = [0]*N DP[1] = abs(h[1]-h[0]) for i in range(2, N): DP[i] = min(abs(h[i]-h[j]) + DP[j] for j in range(max(0, i-K), i)) print((DP[-1])) main()
def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) DP = [10**10 for _ in range(N)] DP[0] = 0 DP[1] = abs(h[0]-h[1]) for i in range(2, N): DP[i] = min(DP[k]+abs(h[i]-h[k]) for k in range(max(0, i-K), i)) print((DP[N-1])) main()
12
12
274
311
def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) DP = [0] * N DP[1] = abs(h[1] - h[0]) for i in range(2, N): DP[i] = min(abs(h[i] - h[j]) + DP[j] for j in range(max(0, i - K), i)) print((DP[-1])) main()
def main(): N, K = list(map(int, input().split())) h = list(map(int, input().split())) DP = [10**10 for _ in range(N)] DP[0] = 0 DP[1] = abs(h[0] - h[1]) for i in range(2, N): DP[i] = min(DP[k] + abs(h[i] - h[k]) for k in range(max(0, i - K), i)) print((DP[N - 1])) main()
false
0
[ "- DP = [0] * N", "- DP[1] = abs(h[1] - h[0])", "+ DP = [10**10 for _ in range(N)]", "+ DP[0] = 0", "+ DP[1] = abs(h[0] - h[1])", "- DP[i] = min(abs(h[i] - h[j]) + DP[j] for j in range(max(0, i - K), i))", "- print((DP[-1]))", "+ DP[i] = min(DP[k] + abs(h[i] - h[k]) for k in range(max(0, i - K), i))", "+ print((DP[N - 1]))" ]
false
0.041678
0.037719
1.104959
[ "s038218428", "s105187544" ]
u587518324
p02676
python
s594134148
s678143297
24
22
9,136
9,028
Accepted
Accepted
8.33
#!/usr/bin/env python """AtCoder Beginner Contest 168: B - https://atcoder.jp/contests/abc168/tasks/abc168_b """ __author__ = 'bugttle <bugttle@gmail.com>' def main(): K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print(("{}...".format(S[0:K]))) if __name__ == '__main__': main()
#!/usr/bin/env python """AtCoder Beginner Contest 168: B - ... (Triple Dots) https://atcoder.jp/contests/abc168/tasks/abc168_b """ def main(): K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print(("{}...".format(S[0:K]))) if __name__ == '__main__': main()
19
18
352
325
#!/usr/bin/env python """AtCoder Beginner Contest 168: B - https://atcoder.jp/contests/abc168/tasks/abc168_b """ __author__ = "bugttle <bugttle@gmail.com>" def main(): K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print(("{}...".format(S[0:K]))) if __name__ == "__main__": main()
#!/usr/bin/env python """AtCoder Beginner Contest 168: B - ... (Triple Dots) https://atcoder.jp/contests/abc168/tasks/abc168_b """ def main(): K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print(("{}...".format(S[0:K]))) if __name__ == "__main__": main()
false
5.263158
[ "-\"\"\"AtCoder Beginner Contest 168: B -", "+\"\"\"AtCoder Beginner Contest 168: B - ... (Triple Dots)", "-__author__ = \"bugttle <bugttle@gmail.com>\"" ]
false
0.043845
0.044374
0.988092
[ "s594134148", "s678143297" ]
u489959379
p03147
python
s897038815
s048191111
255
232
3,060
3,064
Accepted
Accepted
9.02
n = int(eval(input())) h = list(map(int, input().split())) res = 0 i = 0 while sum(h) != 0: if h[i] != 0: while i < n and h[i] != 0: h[i] -= 1 i += 1 res += 1 i = 0 else: i += 1 print(res)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) H = list(map(int, input().split())) res = 0 i = 0 while sum(H) != 0: if H[i] != 0: while i < n and H[i] != 0: H[i] -= 1 i += 1 res += 1 i = 0 else: i += 1 print(res) if __name__ == '__main__': resolve()
16
29
264
502
n = int(eval(input())) h = list(map(int, input().split())) res = 0 i = 0 while sum(h) != 0: if h[i] != 0: while i < n and h[i] != 0: h[i] -= 1 i += 1 res += 1 i = 0 else: i += 1 print(res)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) H = list(map(int, input().split())) res = 0 i = 0 while sum(H) != 0: if H[i] != 0: while i < n and H[i] != 0: H[i] -= 1 i += 1 res += 1 i = 0 else: i += 1 print(res) if __name__ == "__main__": resolve()
false
44.827586
[ "-n = int(eval(input()))", "-h = list(map(int, input().split()))", "-res = 0", "-i = 0", "-while sum(h) != 0:", "- if h[i] != 0:", "- while i < n and h[i] != 0:", "- h[i] -= 1", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ H = list(map(int, input().split()))", "+ res = 0", "+ i = 0", "+ while sum(H) != 0:", "+ if H[i] != 0:", "+ while i < n and H[i] != 0:", "+ H[i] -= 1", "+ i += 1", "+ res += 1", "+ i = 0", "+ else:", "- res += 1", "- i = 0", "- else:", "- i += 1", "-print(res)", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.036996
0.035485
1.042584
[ "s897038815", "s048191111" ]
u350093546
p02678
python
s563573228
s642976415
1,400
480
34,728
98,628
Accepted
Accepted
65.71
n,m=list(map(int,input().split())) lst=[[] for i in range(n)] visited=[False for i in range(n)] ans=[0]*n for i in range(m): a,b=list(map(int,input().split())) lst[a-1].append(b-1) lst[b-1].append(a-1) Q=[0] visited[0]=True while Q: v=Q.pop(0) for i in lst[v]: if visited[i]==False: visited[i]=True ans[i]=v Q.append(i) print('Yes') for i in range(1,n): print((ans[i]+1))
#ABC168D from collections import deque n,m=list(map(int,input().split())) lst=[[] for i in range(n)] visited=[False for i in range(n)] ans=[0]*n for i in range(m): a,b=list(map(int,input().split())) lst[a-1].append(b-1) lst[b-1].append(a-1) Q=deque() Q.append((0)) visited[0]=True while Q: v=Q.popleft() for i in lst[v]: if visited[i]==False: visited[i]=True ans[i]=v Q.append((i)) print('Yes') for i in range(1,n): print((ans[i]+1))
25
29
464
531
n, m = list(map(int, input().split())) lst = [[] for i in range(n)] visited = [False for i in range(n)] ans = [0] * n for i in range(m): a, b = list(map(int, input().split())) lst[a - 1].append(b - 1) lst[b - 1].append(a - 1) Q = [0] visited[0] = True while Q: v = Q.pop(0) for i in lst[v]: if visited[i] == False: visited[i] = True ans[i] = v Q.append(i) print("Yes") for i in range(1, n): print((ans[i] + 1))
# ABC168D from collections import deque n, m = list(map(int, input().split())) lst = [[] for i in range(n)] visited = [False for i in range(n)] ans = [0] * n for i in range(m): a, b = list(map(int, input().split())) lst[a - 1].append(b - 1) lst[b - 1].append(a - 1) Q = deque() Q.append((0)) visited[0] = True while Q: v = Q.popleft() for i in lst[v]: if visited[i] == False: visited[i] = True ans[i] = v Q.append((i)) print("Yes") for i in range(1, n): print((ans[i] + 1))
false
13.793103
[ "+# ABC168D", "+from collections import deque", "+", "-Q = [0]", "+Q = deque()", "+Q.append((0))", "- v = Q.pop(0)", "+ v = Q.popleft()", "- Q.append(i)", "+ Q.append((i))" ]
false
0.077823
0.036272
2.145567
[ "s563573228", "s642976415" ]
u040298438
p03262
python
s243478978
s378943989
101
82
25,640
25,684
Accepted
Accepted
18.81
from math import gcd from functools import reduce _, X = list(map(int, input().split())) x = set(map(int, input().split())) x.add(X) x = sorted(x) print((reduce(gcd, (j - i for i, j in zip(x[:-1], x[1:])))))
from math import gcd from functools import reduce _, X = list(map(int, input().split())) print((reduce(gcd, (abs(i - X) for i in set(map(int, input().split()))))))
8
5
207
160
from math import gcd from functools import reduce _, X = list(map(int, input().split())) x = set(map(int, input().split())) x.add(X) x = sorted(x) print((reduce(gcd, (j - i for i, j in zip(x[:-1], x[1:])))))
from math import gcd from functools import reduce _, X = list(map(int, input().split())) print((reduce(gcd, (abs(i - X) for i in set(map(int, input().split()))))))
false
37.5
[ "-x = set(map(int, input().split()))", "-x.add(X)", "-x = sorted(x)", "-print((reduce(gcd, (j - i for i, j in zip(x[:-1], x[1:])))))", "+print((reduce(gcd, (abs(i - X) for i in set(map(int, input().split()))))))" ]
false
0.043575
0.040662
1.071632
[ "s243478978", "s378943989" ]
u729133443
p02999
python
s330745162
s372967819
165
17
38,256
2,940
Accepted
Accepted
89.7
x,_,a=eval(input());print((10*(x>=a)))
s=eval(input());print((10*(s>s[2])))
1
1
30
28
x, _, a = eval(input()) print((10 * (x >= a)))
s = eval(input()) print((10 * (s > s[2])))
false
0
[ "-x, _, a = eval(input())", "-print((10 * (x >= a)))", "+s = eval(input())", "+print((10 * (s > s[2])))" ]
false
0.037701
0.039676
0.950206
[ "s330745162", "s372967819" ]