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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u254871849 | p02844 | python | s666786500 | s482631693 | 327 | 212 | 50,672 | 49,652 | Accepted | Accepted | 35.17 | import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
place = dict((i, set()) for i in digits)
for i in range(n):
place[s[i]].add(i)
l = [None] * n
l[0] = set()
for i in range(1, n):
l[i] = l[i-1] | set([s[i-1]])
r = [None] * n
r[n-1] = set()
for i in range(n-2, -1, -1):
r[i] = r[i+1] | set([s[i+1]])
res = set()
for j in digits:
for i in digits:
for k in digits:
for c in place[j]:
if not i in l[c]:
continue
if not k in r[c]:
continue
res.add((i, j, k))
break
print((len(res)))
if __name__ == '__main__':
main() | import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
place = dict((i, list()) for i in digits)
for i in range(n):
place[s[i]].append(i)
l = [None] * n
l[0] = set()
for i in range(1, n):
l[i] = l[i-1] | set([s[i-1]])
r = [None] * n
r[n-1] = set()
for i in range(n-2, -1, -1):
r[i] = r[i+1] | set([s[i+1]])
res = set()
for j in digits:
p = place[j]
if not p:
continue
for i in digits:
for k in digits:
for c in p:
if not k in r[c]:
break
if not i in l[c]:
continue
res.add((i, j, k))
break
print((len(res)))
if __name__ == '__main__':
main() | 37 | 39 | 841 | 896 | import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
place = dict((i, set()) for i in digits)
for i in range(n):
place[s[i]].add(i)
l = [None] * n
l[0] = set()
for i in range(1, n):
l[i] = l[i - 1] | set([s[i - 1]])
r = [None] * n
r[n - 1] = set()
for i in range(n - 2, -1, -1):
r[i] = r[i + 1] | set([s[i + 1]])
res = set()
for j in digits:
for i in digits:
for k in digits:
for c in place[j]:
if not i in l[c]:
continue
if not k in r[c]:
continue
res.add((i, j, k))
break
print((len(res)))
if __name__ == "__main__":
main()
| import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
place = dict((i, list()) for i in digits)
for i in range(n):
place[s[i]].append(i)
l = [None] * n
l[0] = set()
for i in range(1, n):
l[i] = l[i - 1] | set([s[i - 1]])
r = [None] * n
r[n - 1] = set()
for i in range(n - 2, -1, -1):
r[i] = r[i + 1] | set([s[i + 1]])
res = set()
for j in digits:
p = place[j]
if not p:
continue
for i in digits:
for k in digits:
for c in p:
if not k in r[c]:
break
if not i in l[c]:
continue
res.add((i, j, k))
break
print((len(res)))
if __name__ == "__main__":
main()
| false | 5.128205 | [
"- place = dict((i, set()) for i in digits)",
"+ place = dict((i, list()) for i in digits)",
"- place[s[i]].add(i)",
"+ place[s[i]].append(i)",
"+ p = place[j]",
"+ if not p:",
"+ continue",
"- for c in place[j]:",
"+ for c in p:",
"+ if not k in r[c]:",
"+ break",
"- continue",
"- if not k in r[c]:"
] | false | 0.041363 | 0.042497 | 0.973326 | [
"s666786500",
"s482631693"
] |
u814387366 | p02388 | python | s247540129 | s814445341 | 20 | 10 | 4,176 | 4,176 | Accepted | Accepted | 50 | x=eval(input())
print(x*x*x) | print(input()**3) | 2 | 1 | 22 | 16 | x = eval(input())
print(x * x * x)
| print(input() ** 3)
| false | 50 | [
"-x = eval(input())",
"-print(x * x * x)",
"+print(input() ** 3)"
] | false | 0.032076 | 0.03739 | 0.857884 | [
"s247540129",
"s814445341"
] |
u945181840 | p02851 | python | s855812793 | s631257162 | 332 | 245 | 42,124 | 41,760 | Accepted | Accepted | 26.2 | import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
def cmb(x):
return x * (x - 1) // 2
answer = 0
if N < K:
for i in list(Counter(a).values()):
answer += cmb(i)
else:
dic = Counter(a[:K])
for i in list(dic.values()):
answer += cmb(i)
here = K
for i, x in enumerate(a[K:]):
dic[a[i]] -= 1
answer += dic[x]
dic[x] += 1
print(answer) | import sys
from collections import defaultdict
from itertools import accumulate
read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
answer = 0
dic = defaultdict(int)
for i, x in enumerate(a):
answer += dic[x]
dic[x] += 1
if i >= K - 1:
dic[a[i - K + 1]] -= 1
print(answer) | 29 | 19 | 572 | 393 | import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
def cmb(x):
return x * (x - 1) // 2
answer = 0
if N < K:
for i in list(Counter(a).values()):
answer += cmb(i)
else:
dic = Counter(a[:K])
for i in list(dic.values()):
answer += cmb(i)
here = K
for i, x in enumerate(a[K:]):
dic[a[i]] -= 1
answer += dic[x]
dic[x] += 1
print(answer)
| import sys
from collections import defaultdict
from itertools import accumulate
read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
answer = 0
dic = defaultdict(int)
for i, x in enumerate(a):
answer += dic[x]
dic[x] += 1
if i >= K - 1:
dic[a[i - K + 1]] -= 1
print(answer)
| false | 34.482759 | [
"-from collections import Counter",
"+from collections import defaultdict",
"-",
"-",
"-def cmb(x):",
"- return x * (x - 1) // 2",
"-",
"-",
"-if N < K:",
"- for i in list(Counter(a).values()):",
"- answer += cmb(i)",
"-else:",
"- dic = Counter(a[:K])",
"- for i in list(dic.values()):",
"- answer += cmb(i)",
"- here = K",
"- for i, x in enumerate(a[K:]):",
"- dic[a[i]] -= 1",
"- answer += dic[x]",
"- dic[x] += 1",
"+dic = defaultdict(int)",
"+for i, x in enumerate(a):",
"+ answer += dic[x]",
"+ dic[x] += 1",
"+ if i >= K - 1:",
"+ dic[a[i - K + 1]] -= 1"
] | false | 0.040716 | 0.040872 | 0.996193 | [
"s855812793",
"s631257162"
] |
u077291787 | p03438 | python | s817350588 | s085592894 | 26 | 24 | 4,596 | 5,236 | Accepted | Accepted | 7.69 | # APC001B - Two Arrays
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt += a - b
else:
cnt -= (b - a) // 2
print(("Yes" if cnt <= 0 else "No"))
if __name__ == "__main__":
main() | # APC001B - Two Arrays
def main():
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt += a - b
else:
cnt -= (b - a) // 2
print(("Yes" if cnt <= 0 else "No"))
if __name__ == "__main__":
main() | 21 | 15 | 405 | 327 | # APC001B - Two Arrays
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt += a - b
else:
cnt -= (b - a) // 2
print(("Yes" if cnt <= 0 else "No"))
if __name__ == "__main__":
main()
| # APC001B - Two Arrays
def main():
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt += a - b
else:
cnt -= (b - a) // 2
print(("Yes" if cnt <= 0 else "No"))
if __name__ == "__main__":
main()
| false | 28.571429 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"- n = int(eval(input()))",
"- A = tuple(map(int, input().split()))",
"- B = tuple(map(int, input().split()))",
"+ N, *AB = list(map(int, open(0).read().split()))",
"+ A, B = AB[:N], AB[N:]"
] | false | 0.067063 | 0.058001 | 1.156238 | [
"s817350588",
"s085592894"
] |
u046187684 | p03339 | python | s801148484 | s124842656 | 281 | 162 | 21,572 | 21,572 | Accepted | Accepted | 42.35 | def solve(string):
n, s = string.split()
n = int(n)
es = {i for i, _s in enumerate(s) if _s == "E"}
num_e = len(es)
num_w = n - num_e
count_e = 0
count_w = 0
ans = n
for i, _s in enumerate(s):
tmp = [count_e, count_w]
if i in es:
count_e += 1
else:
count_w += 1
tmp += [num_e - count_e, num_w - count_w]
ans = min(ans, tmp[1] + tmp[2])
return str(ans)
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| def solve(string):
n, s = string.split()
n = int(n)
es = {i for i, _s in enumerate(s) if _s == "E"}
num_e = len(es)
count_e = 0
count_w = 0
ans = n
for i, _s in enumerate(s):
tmp = count_w
if i in es:
count_e += 1
else:
count_w += 1
tmp += num_e - count_e
ans = min(ans, tmp)
return str(ans)
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| 23 | 22 | 556 | 491 | def solve(string):
n, s = string.split()
n = int(n)
es = {i for i, _s in enumerate(s) if _s == "E"}
num_e = len(es)
num_w = n - num_e
count_e = 0
count_w = 0
ans = n
for i, _s in enumerate(s):
tmp = [count_e, count_w]
if i in es:
count_e += 1
else:
count_w += 1
tmp += [num_e - count_e, num_w - count_w]
ans = min(ans, tmp[1] + tmp[2])
return str(ans)
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| def solve(string):
n, s = string.split()
n = int(n)
es = {i for i, _s in enumerate(s) if _s == "E"}
num_e = len(es)
count_e = 0
count_w = 0
ans = n
for i, _s in enumerate(s):
tmp = count_w
if i in es:
count_e += 1
else:
count_w += 1
tmp += num_e - count_e
ans = min(ans, tmp)
return str(ans)
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| false | 4.347826 | [
"- num_w = n - num_e",
"- tmp = [count_e, count_w]",
"+ tmp = count_w",
"- tmp += [num_e - count_e, num_w - count_w]",
"- ans = min(ans, tmp[1] + tmp[2])",
"+ tmp += num_e - count_e",
"+ ans = min(ans, tmp)"
] | false | 0.038238 | 0.060991 | 0.626945 | [
"s801148484",
"s124842656"
] |
u685263709 | p03108 | python | s407126723 | s605197934 | 1,665 | 879 | 148,088 | 38,116 | Accepted | Accepted | 47.21 | import collections
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
class UnitDict(dict):
def __init__(self, iterable=None, wrapper=lambda x: x):
super().__init__(self)
self.wrapper = wrapper
if iterable is not None:
self.update(iterable)
def __missing__(self, key):
self[key] = self.wrapper(key)
return self[key]
class UnionFind(object):
def __init__(self, nodes=None):
self.par = UnitDict(wrapper=lambda x: x)
self.rank = collections.defaultdict(int)
self.groups = UnitDict(wrapper=lambda x: {x})
if nodes is not None:
for node in nodes:
_, _, _ = self.par[node], self.rank[node], self.groups[node]
def root(self, node):
if self.par[node] == node:
return node
else:
r = self.root(self.par[node])
self.par[node] = r
return r
def are_same(self, node1, node2):
return self.root(node1) == self.root(node2)
def elements(self, node):
return self.groups[self.root(node)]
def size(self, node):
return len(self.elements(node))
def unite(self, node1, node2):
x = self.root(node1)
y = self.root(node2)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
self.groups[x].update(self.groups[y])
self.groups[y].clear()
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def grouper(self):
roots = [x for x in list(self.par.keys())]
groups = []
for root in roots:
if list(self.elements(root)) not in groups:
groups.append(list(self.elements(root)))
return groups
islands = UnionFind(list(range(1, N)))
ans_list = []
last = int(N * (N-1) / 2)
ans_list.append(last)
for i in range(1, M):
if islands.are_same(AB[-i][0], AB[-i][1]):
ans_list.append(ans_list[-1])
else:
ans_list.append(ans_list[-1]-islands.size(AB[-i][0])*islands.size(AB[-i][1]))
islands.unite(AB[-i][0], AB[-i][1])
for i in range(1, len(ans_list)+1):
print((ans_list[-i])) | N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
class UnionFind():
def __init__(self, N):
self.rank = [0] * N
self.par = [i for i in range(N)]
self.counter = [1] * N
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
z = self.counter[x] + self.counter[y]
self.counter[x], self.counter[y] = z, z
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def size(self, x):
x = self.find(x)
return self.counter[x]
def same(self, x, y):
return self.find(x) == self.find(y)
ans_list = []
graph = UnionFind(N)
last = N * (N-1) // 2
ans_list.append(last)
for i in range(M-1, -1, -1):
a, b = AB[i]
if graph.same(a-1, b-1):
ans_list.append(ans_list[-1])
else:
ans_list.append(ans_list[-1] - graph.size(a-1) * graph.size(b-1))
graph.unite(a-1, b-1)
for i in range(M-1, -1, -1):
print((ans_list[i])) | 80 | 52 | 2,308 | 1,352 | import collections
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
class UnitDict(dict):
def __init__(self, iterable=None, wrapper=lambda x: x):
super().__init__(self)
self.wrapper = wrapper
if iterable is not None:
self.update(iterable)
def __missing__(self, key):
self[key] = self.wrapper(key)
return self[key]
class UnionFind(object):
def __init__(self, nodes=None):
self.par = UnitDict(wrapper=lambda x: x)
self.rank = collections.defaultdict(int)
self.groups = UnitDict(wrapper=lambda x: {x})
if nodes is not None:
for node in nodes:
_, _, _ = self.par[node], self.rank[node], self.groups[node]
def root(self, node):
if self.par[node] == node:
return node
else:
r = self.root(self.par[node])
self.par[node] = r
return r
def are_same(self, node1, node2):
return self.root(node1) == self.root(node2)
def elements(self, node):
return self.groups[self.root(node)]
def size(self, node):
return len(self.elements(node))
def unite(self, node1, node2):
x = self.root(node1)
y = self.root(node2)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
self.groups[x].update(self.groups[y])
self.groups[y].clear()
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def grouper(self):
roots = [x for x in list(self.par.keys())]
groups = []
for root in roots:
if list(self.elements(root)) not in groups:
groups.append(list(self.elements(root)))
return groups
islands = UnionFind(list(range(1, N)))
ans_list = []
last = int(N * (N - 1) / 2)
ans_list.append(last)
for i in range(1, M):
if islands.are_same(AB[-i][0], AB[-i][1]):
ans_list.append(ans_list[-1])
else:
ans_list.append(
ans_list[-1] - islands.size(AB[-i][0]) * islands.size(AB[-i][1])
)
islands.unite(AB[-i][0], AB[-i][1])
for i in range(1, len(ans_list) + 1):
print((ans_list[-i]))
| N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
class UnionFind:
def __init__(self, N):
self.rank = [0] * N
self.par = [i for i in range(N)]
self.counter = [1] * N
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
z = self.counter[x] + self.counter[y]
self.counter[x], self.counter[y] = z, z
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def size(self, x):
x = self.find(x)
return self.counter[x]
def same(self, x, y):
return self.find(x) == self.find(y)
ans_list = []
graph = UnionFind(N)
last = N * (N - 1) // 2
ans_list.append(last)
for i in range(M - 1, -1, -1):
a, b = AB[i]
if graph.same(a - 1, b - 1):
ans_list.append(ans_list[-1])
else:
ans_list.append(ans_list[-1] - graph.size(a - 1) * graph.size(b - 1))
graph.unite(a - 1, b - 1)
for i in range(M - 1, -1, -1):
print((ans_list[i]))
| false | 35 | [
"-import collections",
"-",
"-class UnitDict(dict):",
"- def __init__(self, iterable=None, wrapper=lambda x: x):",
"- super().__init__(self)",
"- self.wrapper = wrapper",
"- if iterable is not None:",
"- self.update(iterable)",
"+class UnionFind:",
"+ def __init__(self, N):",
"+ self.rank = [0] * N",
"+ self.par = [i for i in range(N)]",
"+ self.counter = [1] * N",
"- def __missing__(self, key):",
"- self[key] = self.wrapper(key)",
"- return self[key]",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"+ return x",
"+ else:",
"+ self.par[x] = self.find(self.par[x])",
"+ return self.par[x]",
"-",
"-class UnionFind(object):",
"- def __init__(self, nodes=None):",
"- self.par = UnitDict(wrapper=lambda x: x)",
"- self.rank = collections.defaultdict(int)",
"- self.groups = UnitDict(wrapper=lambda x: {x})",
"- if nodes is not None:",
"- for node in nodes:",
"- _, _, _ = self.par[node], self.rank[node], self.groups[node]",
"-",
"- def root(self, node):",
"- if self.par[node] == node:",
"- return node",
"+ def unite(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"+ if x != y:",
"+ z = self.counter[x] + self.counter[y]",
"+ self.counter[x], self.counter[y] = z, z",
"+ if self.rank[x] < self.rank[y]:",
"+ self.par[x] = y",
"- r = self.root(self.par[node])",
"- self.par[node] = r",
"- return r",
"-",
"- def are_same(self, node1, node2):",
"- return self.root(node1) == self.root(node2)",
"-",
"- def elements(self, node):",
"- return self.groups[self.root(node)]",
"-",
"- def size(self, node):",
"- return len(self.elements(node))",
"-",
"- def unite(self, node1, node2):",
"- x = self.root(node1)",
"- y = self.root(node2)",
"- if x != y:",
"- if self.rank[x] < self.rank[y]:",
"- x, y = y, x",
"- self.groups[x].update(self.groups[y])",
"- self.groups[y].clear()",
"- def grouper(self):",
"- roots = [x for x in list(self.par.keys())]",
"- groups = []",
"- for root in roots:",
"- if list(self.elements(root)) not in groups:",
"- groups.append(list(self.elements(root)))",
"- return groups",
"+ def size(self, x):",
"+ x = self.find(x)",
"+ return self.counter[x]",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"-islands = UnionFind(list(range(1, N)))",
"-last = int(N * (N - 1) / 2)",
"+graph = UnionFind(N)",
"+last = N * (N - 1) // 2",
"-for i in range(1, M):",
"- if islands.are_same(AB[-i][0], AB[-i][1]):",
"+for i in range(M - 1, -1, -1):",
"+ a, b = AB[i]",
"+ if graph.same(a - 1, b - 1):",
"- ans_list.append(",
"- ans_list[-1] - islands.size(AB[-i][0]) * islands.size(AB[-i][1])",
"- )",
"- islands.unite(AB[-i][0], AB[-i][1])",
"-for i in range(1, len(ans_list) + 1):",
"- print((ans_list[-i]))",
"+ ans_list.append(ans_list[-1] - graph.size(a - 1) * graph.size(b - 1))",
"+ graph.unite(a - 1, b - 1)",
"+for i in range(M - 1, -1, -1):",
"+ print((ans_list[i]))"
] | false | 0.041477 | 0.036481 | 1.136929 | [
"s407126723",
"s605197934"
] |
u066455063 | p02570 | python | s680931969 | s142275991 | 28 | 25 | 9,132 | 9,084 | Accepted | Accepted | 10.71 | d, t, s = list(map(int, input().split()))
print(("Yes" if d / s <= t else "No"))
| d, t, s = list(map(int, input().split()))
print(("Yes" if t * s >= d else "No")) | 3 | 3 | 76 | 75 | d, t, s = list(map(int, input().split()))
print(("Yes" if d / s <= t else "No"))
| d, t, s = list(map(int, input().split()))
print(("Yes" if t * s >= d else "No"))
| false | 0 | [
"-print((\"Yes\" if d / s <= t else \"No\"))",
"+print((\"Yes\" if t * s >= d else \"No\"))"
] | false | 0.033919 | 0.059313 | 0.571859 | [
"s680931969",
"s142275991"
] |
u579015878 | p02624 | python | s906853797 | s667772923 | 2,997 | 2,352 | 9,152 | 9,080 | Accepted | Accepted | 21.52 | n=int(eval(input()))
ans=0
for i in range(1,n+1):
key=n//i
ans+=int(key*(key+1)*i/2)
print(ans) | n=int(eval(input()))
ans=0
for i in range(1,n+1):
key=n//i
ans+=(key*(key+1)*i//2)
print(ans) | 6 | 6 | 98 | 96 | n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
key = n // i
ans += int(key * (key + 1) * i / 2)
print(ans)
| n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
key = n // i
ans += key * (key + 1) * i // 2
print(ans)
| false | 0 | [
"- ans += int(key * (key + 1) * i / 2)",
"+ ans += key * (key + 1) * i // 2"
] | false | 1.039537 | 0.777972 | 1.336214 | [
"s906853797",
"s667772923"
] |
u987170100 | p03147 | python | s618230754 | s630719661 | 328 | 19 | 21,540 | 3,064 | Accepted | Accepted | 94.21 | import numpy as np
N = int(eval(input()))
lst = [int(x) for x in input().split()]
lst2 = np.zeros((max(lst), N))
for idx, n in enumerate(lst):
lst2[:n,idx] = 1
ret = 0
for x in lst2:
flg = True
for y in x:
if flg and y == 1:
ret += 1
flg = False
elif y == 0:
flg = True
print(ret) | N = int(eval(input()))
lst = [int(x) for x in input().split()]
n = max(lst)
h = 1
ret = 0
while n >= h:
flg = True
for x in lst:
if x >= h and flg:
ret += 1
flg = False
elif h > x:
flg = True
h += 1
print(ret) | 18 | 16 | 357 | 283 | import numpy as np
N = int(eval(input()))
lst = [int(x) for x in input().split()]
lst2 = np.zeros((max(lst), N))
for idx, n in enumerate(lst):
lst2[:n, idx] = 1
ret = 0
for x in lst2:
flg = True
for y in x:
if flg and y == 1:
ret += 1
flg = False
elif y == 0:
flg = True
print(ret)
| N = int(eval(input()))
lst = [int(x) for x in input().split()]
n = max(lst)
h = 1
ret = 0
while n >= h:
flg = True
for x in lst:
if x >= h and flg:
ret += 1
flg = False
elif h > x:
flg = True
h += 1
print(ret)
| false | 11.111111 | [
"-import numpy as np",
"-",
"-lst2 = np.zeros((max(lst), N))",
"-for idx, n in enumerate(lst):",
"- lst2[:n, idx] = 1",
"+n = max(lst)",
"+h = 1",
"-for x in lst2:",
"+while n >= h:",
"- for y in x:",
"- if flg and y == 1:",
"+ for x in lst:",
"+ if x >= h and flg:",
"- elif y == 0:",
"+ elif h > x:",
"+ h += 1"
] | false | 0.644213 | 0.03577 | 18.010005 | [
"s618230754",
"s630719661"
] |
u806976856 | p02678 | python | s001167152 | s003188993 | 435 | 370 | 113,404 | 113,200 | Accepted | Accepted | 14.94 | from collections import deque
import sys
input = sys.stdin.readline
n,m=list(map(int,input().split()))
r=[[] for i in range(n+1)]
R=[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
p=data.popleft()
for i in r[p]:
if dep[i]==-1:
dep[i]=dep[p]+1
data.append(i)
r[p]=[]
if not all(dep[i+1]>=0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2,n+1):
for j in R[i]:
if dep[j]==dep[i]-1:
print(j)
break
| from collections import deque
import sys
input = sys.stdin.readline
n,m=list(map(int,input().split()))
k=[0]*(n+1)
r=[[] for i in range(n+1)]
R=[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
p=data.popleft()
for i in r[p]:
if dep[i]==-1:
dep[i]=dep[p]+1
k[i]=p
data.append(i)
r[p]=[]
if not all(dep[i+1]>=0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2,n+1):
print((k[i]))
| 34 | 32 | 727 | 672 | from collections import deque
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
r = [[] for i in range(n + 1)]
R = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep = [-1] * (n + 1)
dep[0] = 0
dep[1] = 0
data = deque([1])
d = 0
while len(data) > 0:
p = data.popleft()
for i in r[p]:
if dep[i] == -1:
dep[i] = dep[p] + 1
data.append(i)
r[p] = []
if not all(dep[i + 1] >= 0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2, n + 1):
for j in R[i]:
if dep[j] == dep[i] - 1:
print(j)
break
| from collections import deque
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
k = [0] * (n + 1)
r = [[] for i in range(n + 1)]
R = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep = [-1] * (n + 1)
dep[0] = 0
dep[1] = 0
data = deque([1])
d = 0
while len(data) > 0:
p = data.popleft()
for i in r[p]:
if dep[i] == -1:
dep[i] = dep[p] + 1
k[i] = p
data.append(i)
r[p] = []
if not all(dep[i + 1] >= 0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2, n + 1):
print((k[i]))
| false | 5.882353 | [
"+k = [0] * (n + 1)",
"+ k[i] = p",
"- for j in R[i]:",
"- if dep[j] == dep[i] - 1:",
"- print(j)",
"- break",
"+ print((k[i]))"
] | false | 0.044765 | 0.044301 | 1.010481 | [
"s001167152",
"s003188993"
] |
u112629957 | p02642 | python | s510123166 | s773830699 | 1,071 | 434 | 32,208 | 94,136 | Accepted | Accepted | 59.48 | N=int(eval(input()))
ls=list(map(int,input().split()))
ls.sort()
#定数倍のやつに+1する
M=max(ls)
A=[0]*(M+1)
for i in range(len(ls)):
a=1
while ls[i]*a<=M:
b=ls[i]*a
if A[b]<=1:
A[b]+=1
a+=1
ans=0
for i in range(len(ls)):
if A[ls[i]]==1:
ans+=1
print(ans)
| N=int(eval(input()))
ls=list(map(int,input().split()))
ls.sort()
#定数倍のやつに+1する
M=max(ls)
A=[0]*(M+1)
for i in range(N):
a=M//ls[i]
for j in range(1,a+1):
A[j*ls[i]]+=1
ans=0
for i in range(len(ls)):
if A[ls[i]]==1:
ans+=1
print(ans) | 20 | 17 | 299 | 266 | N = int(eval(input()))
ls = list(map(int, input().split()))
ls.sort()
# 定数倍のやつに+1する
M = max(ls)
A = [0] * (M + 1)
for i in range(len(ls)):
a = 1
while ls[i] * a <= M:
b = ls[i] * a
if A[b] <= 1:
A[b] += 1
a += 1
ans = 0
for i in range(len(ls)):
if A[ls[i]] == 1:
ans += 1
print(ans)
| N = int(eval(input()))
ls = list(map(int, input().split()))
ls.sort()
# 定数倍のやつに+1する
M = max(ls)
A = [0] * (M + 1)
for i in range(N):
a = M // ls[i]
for j in range(1, a + 1):
A[j * ls[i]] += 1
ans = 0
for i in range(len(ls)):
if A[ls[i]] == 1:
ans += 1
print(ans)
| false | 15 | [
"-for i in range(len(ls)):",
"- a = 1",
"- while ls[i] * a <= M:",
"- b = ls[i] * a",
"- if A[b] <= 1:",
"- A[b] += 1",
"- a += 1",
"+for i in range(N):",
"+ a = M // ls[i]",
"+ for j in range(1, a + 1):",
"+ A[j * ls[i]] += 1"
] | false | 0.037117 | 0.08591 | 0.432042 | [
"s510123166",
"s773830699"
] |
u186838327 | p02838 | python | s511200843 | s888961329 | 1,416 | 685 | 125,624 | 124,628 | Accepted | Accepted | 51.62 | n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
kmax = len(format(l[0], 'b'))
l0 = [0]*kmax
l1 = [0]*kmax
for i in range(n):
a = format(l[i], 'b')
a = ''.join(list(reversed(a)))
for j in range(kmax):
if j > len(a)-1:
l0[j] += 1
elif a[j] == '0':
l0[j] += 1
else:
l1[j] += 1
ans = 0
for k in range(kmax):
ans += l0[k]*l1[k]*(2**k)
ans %= 10**9+7
print(ans) | n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9+7
X = [0]*62
for i in range(n):
a = A[i]
b = format(a, 'b')
b = list(b)
b.reverse()
for j in range(len(b)):
if b[j] == '1':
X[j] += 1
ans = 0
for i in range(62):
x = X[i]
y = n-X[i]
#print(i, x, y)
ans += x*y*pow(2, i, mod)
ans %= mod
print(ans)
| 25 | 21 | 449 | 388 | n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
kmax = len(format(l[0], "b"))
l0 = [0] * kmax
l1 = [0] * kmax
for i in range(n):
a = format(l[i], "b")
a = "".join(list(reversed(a)))
for j in range(kmax):
if j > len(a) - 1:
l0[j] += 1
elif a[j] == "0":
l0[j] += 1
else:
l1[j] += 1
ans = 0
for k in range(kmax):
ans += l0[k] * l1[k] * (2**k)
ans %= 10**9 + 7
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
X = [0] * 62
for i in range(n):
a = A[i]
b = format(a, "b")
b = list(b)
b.reverse()
for j in range(len(b)):
if b[j] == "1":
X[j] += 1
ans = 0
for i in range(62):
x = X[i]
y = n - X[i]
# print(i, x, y)
ans += x * y * pow(2, i, mod)
ans %= mod
print(ans)
| false | 16 | [
"-l = list(map(int, input().split()))",
"-l.sort(reverse=True)",
"-kmax = len(format(l[0], \"b\"))",
"-l0 = [0] * kmax",
"-l1 = [0] * kmax",
"+A = list(map(int, input().split()))",
"+mod = 10**9 + 7",
"+X = [0] * 62",
"- a = format(l[i], \"b\")",
"- a = \"\".join(list(reversed(a)))",
"- for j in range(kmax):",
"- if j > len(a) - 1:",
"- l0[j] += 1",
"- elif a[j] == \"0\":",
"- l0[j] += 1",
"- else:",
"- l1[j] += 1",
"+ a = A[i]",
"+ b = format(a, \"b\")",
"+ b = list(b)",
"+ b.reverse()",
"+ for j in range(len(b)):",
"+ if b[j] == \"1\":",
"+ X[j] += 1",
"-for k in range(kmax):",
"- ans += l0[k] * l1[k] * (2**k)",
"- ans %= 10**9 + 7",
"+for i in range(62):",
"+ x = X[i]",
"+ y = n - X[i]",
"+ # print(i, x, y)",
"+ ans += x * y * pow(2, i, mod)",
"+ans %= mod"
] | false | 0.062438 | 0.038852 | 1.607072 | [
"s511200843",
"s888961329"
] |
u712822150 | p03017 | python | s853040261 | s080853850 | 493 | 180 | 15,740 | 18,476 | Accepted | Accepted | 63.49 | import sys
import numpy as np
def main():
n, a, b, c, d = [int(x) for x in input().split()]
a -= 1
b -= 1
c -= 1
d -= 1
nv = np.insert(np.array([1 if char == '#' else 0 for char in eval(input())]).cumsum(), 0, 0)
for i in range(a, max(c, d)):
if nv[i + 2] - nv[i] == 2:
print("No")
sys.exit()
if c < d:
print("Yes")
sys.exit()
for i in range(b, d + 1):
if nv[i + 2] - nv[i - 1] == 0:
print("Yes")
sys.exit()
print("No")
main()
| import sys
import numpy as np
def main():
n, a, b, c, d = [int(x) for x in input().split()]
nv = np.insert(np.array([1 if char == '#' else 0 for char in eval(input())]), 0, 0)
nv1 = nv[1:] + nv[:-1]
nv2 = nv[2:] + nv[1:-1] + nv[:-2]
if np.any(nv1[a:max(c, d)] == 2):
print("No")
elif c < d:
print("Yes")
elif np.any(nv2[b-1:d] == 0):
print("Yes")
else:
print("No")
main()
| 26 | 20 | 570 | 453 | import sys
import numpy as np
def main():
n, a, b, c, d = [int(x) for x in input().split()]
a -= 1
b -= 1
c -= 1
d -= 1
nv = np.insert(
np.array([1 if char == "#" else 0 for char in eval(input())]).cumsum(), 0, 0
)
for i in range(a, max(c, d)):
if nv[i + 2] - nv[i] == 2:
print("No")
sys.exit()
if c < d:
print("Yes")
sys.exit()
for i in range(b, d + 1):
if nv[i + 2] - nv[i - 1] == 0:
print("Yes")
sys.exit()
print("No")
main()
| import sys
import numpy as np
def main():
n, a, b, c, d = [int(x) for x in input().split()]
nv = np.insert(np.array([1 if char == "#" else 0 for char in eval(input())]), 0, 0)
nv1 = nv[1:] + nv[:-1]
nv2 = nv[2:] + nv[1:-1] + nv[:-2]
if np.any(nv1[a : max(c, d)] == 2):
print("No")
elif c < d:
print("Yes")
elif np.any(nv2[b - 1 : d] == 0):
print("Yes")
else:
print("No")
main()
| false | 23.076923 | [
"- a -= 1",
"- b -= 1",
"- c -= 1",
"- d -= 1",
"- nv = np.insert(",
"- np.array([1 if char == \"#\" else 0 for char in eval(input())]).cumsum(), 0, 0",
"- )",
"- for i in range(a, max(c, d)):",
"- if nv[i + 2] - nv[i] == 2:",
"- print(\"No\")",
"- sys.exit()",
"- if c < d:",
"+ nv = np.insert(np.array([1 if char == \"#\" else 0 for char in eval(input())]), 0, 0)",
"+ nv1 = nv[1:] + nv[:-1]",
"+ nv2 = nv[2:] + nv[1:-1] + nv[:-2]",
"+ if np.any(nv1[a : max(c, d)] == 2):",
"+ print(\"No\")",
"+ elif c < d:",
"- sys.exit()",
"- for i in range(b, d + 1):",
"- if nv[i + 2] - nv[i - 1] == 0:",
"- print(\"Yes\")",
"- sys.exit()",
"- print(\"No\")",
"+ elif np.any(nv2[b - 1 : d] == 0):",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")"
] | false | 0.247807 | 0.382456 | 0.647935 | [
"s853040261",
"s080853850"
] |
u729133443 | p03294 | python | s010420463 | s786848962 | 180 | 18 | 43,120 | 3,188 | Accepted | Accepted | 90 | eval(input());print((eval(input().replace(' ','-1+'))-1)) | n,a=open(0);print((sum(map(int,a.split()))-int(n))) | 1 | 1 | 49 | 49 | eval(input())
print((eval(input().replace(" ", "-1+")) - 1))
| n, a = open(0)
print((sum(map(int, a.split())) - int(n)))
| false | 0 | [
"-eval(input())",
"-print((eval(input().replace(\" \", \"-1+\")) - 1))",
"+n, a = open(0)",
"+print((sum(map(int, a.split())) - int(n)))"
] | false | 0.070706 | 0.037072 | 1.907291 | [
"s010420463",
"s786848962"
] |
u141610915 | p03600 | python | s513052893 | s248104815 | 1,139 | 636 | 56,924 | 76,516 | Accepted | Accepted | 44.16 | import sys
from copy import deepcopy as dc
input = sys.stdin.buffer.readline
N = int(eval(input()))
d = [list(map(int, input().split())) for _ in range(N)]
d2 = dc(d)
for k in range(N):
for i in range(N):
for j in range(N):
d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
f = 0
for i in range(N):
for j in range(N):
if d[i][j] != d2[i][j]:
f = 1
if f:
print((-1))
else:
res = 0
for i in range(N):
for j in range(N):
x = 1
for k in range(N):
if k != i and k != j:
if d[i][j] == d[i][k] + d[k][j]: x = 0
res += x * d[i][j]
print((res // 2)) | N = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(N)]
b = [a[i][: ] for i in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
b[i][j] = min(b[i][j], b[i][k] + b[k][j])
inf = 10 ** 10
if a == b:
dp = [[inf] * N for _ in range(N)]
for i in range(N):
for j in range(N):
mn = i
for k in range(N):
if k == j: continue
if a[i][k] + a[k][j] == a[i][j]:
if a[mn][j] > a[k][j]:
mn = k
if dp[mn][j] == inf:
dp[mn][j] = a[mn][j]
elif dp[mn][j] != a[mn][j]:
print((-1))
exit(0)
for i in range(N):
for j in range(N):
if dp[i][j] == inf: dp[i][j] = 0
print((sum([sum(dp[i]) for i in range(N)]) // 2))
else: print((-1)) | 28 | 28 | 636 | 722 | import sys
from copy import deepcopy as dc
input = sys.stdin.buffer.readline
N = int(eval(input()))
d = [list(map(int, input().split())) for _ in range(N)]
d2 = dc(d)
for k in range(N):
for i in range(N):
for j in range(N):
d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
f = 0
for i in range(N):
for j in range(N):
if d[i][j] != d2[i][j]:
f = 1
if f:
print((-1))
else:
res = 0
for i in range(N):
for j in range(N):
x = 1
for k in range(N):
if k != i and k != j:
if d[i][j] == d[i][k] + d[k][j]:
x = 0
res += x * d[i][j]
print((res // 2))
| N = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(N)]
b = [a[i][:] for i in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
b[i][j] = min(b[i][j], b[i][k] + b[k][j])
inf = 10**10
if a == b:
dp = [[inf] * N for _ in range(N)]
for i in range(N):
for j in range(N):
mn = i
for k in range(N):
if k == j:
continue
if a[i][k] + a[k][j] == a[i][j]:
if a[mn][j] > a[k][j]:
mn = k
if dp[mn][j] == inf:
dp[mn][j] = a[mn][j]
elif dp[mn][j] != a[mn][j]:
print((-1))
exit(0)
for i in range(N):
for j in range(N):
if dp[i][j] == inf:
dp[i][j] = 0
print((sum([sum(dp[i]) for i in range(N)]) // 2))
else:
print((-1))
| false | 0 | [
"-import sys",
"-from copy import deepcopy as dc",
"-",
"-input = sys.stdin.buffer.readline",
"-d = [list(map(int, input().split())) for _ in range(N)]",
"-d2 = dc(d)",
"+a = [list(map(int, input().split())) for _ in range(N)]",
"+b = [a[i][:] for i in range(N)]",
"- d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])",
"-f = 0",
"-for i in range(N):",
"- for j in range(N):",
"- if d[i][j] != d2[i][j]:",
"- f = 1",
"-if f:",
"- print((-1))",
"-else:",
"- res = 0",
"+ b[i][j] = min(b[i][j], b[i][k] + b[k][j])",
"+inf = 10**10",
"+if a == b:",
"+ dp = [[inf] * N for _ in range(N)]",
"- x = 1",
"+ mn = i",
"- if k != i and k != j:",
"- if d[i][j] == d[i][k] + d[k][j]:",
"- x = 0",
"- res += x * d[i][j]",
"- print((res // 2))",
"+ if k == j:",
"+ continue",
"+ if a[i][k] + a[k][j] == a[i][j]:",
"+ if a[mn][j] > a[k][j]:",
"+ mn = k",
"+ if dp[mn][j] == inf:",
"+ dp[mn][j] = a[mn][j]",
"+ elif dp[mn][j] != a[mn][j]:",
"+ print((-1))",
"+ exit(0)",
"+ for i in range(N):",
"+ for j in range(N):",
"+ if dp[i][j] == inf:",
"+ dp[i][j] = 0",
"+ print((sum([sum(dp[i]) for i in range(N)]) // 2))",
"+else:",
"+ print((-1))"
] | false | 0.035742 | 0.061658 | 0.579682 | [
"s513052893",
"s248104815"
] |
u780962115 | p02862 | python | s309667629 | s858896090 | 645 | 319 | 82,228 | 112,176 | Accepted | Accepted | 50.54 | mod=10**9+7
##mod,nについての制約は自分でいかに記入する
def pow_cal(x,n,mod):
if n==0:
return 1
elif n==1:
return x%mod
elif n>=2:
if n%2==0:
return (pow_cal(x,n//2,mod)**2)%mod
else:
return (x*pow_cal(x,n//2,mod)**2)%mod
def find_power(n,mod):
# 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである)
powlist=[0]*(n+1)
powlist[0]=1
powlist[1]=1
for i in range(2,n+1):
powlist[i]=powlist[i-1]*i%(mod)
return powlist
def find_inv_power(n,mod):
#0!からn!までの逆元を素数modで割ったあまりリストを作る関数
c=1
uselist=[0 for i in range(n+1)]
for i in range(1,n+1):
c*=i
c%=mod
first=pow_cal(c,mod-2,mod)
uselist[n]=first
for i in range(n,0,-1):
uselist[i-1]=(uselist[i]*i)%(mod)
return uselist
A=find_power(10**6,mod)
B=find_inv_power(10**6,mod)
def combi(n,r,mod):
if n<r:
return 0
elif n>=r:
return (A[n]*B[r]*B[n-r])%(mod)
x,y=list(map(int,input().split()))
if (x+y)%3!=0:
print((0))
else:
J=(2*y-x)//3
K=(2*x-y)//3
if J>=0 and K>=0:
print((combi(J+K,J,mod)))
else:
print((0)) | def find_power(n):
# 0!からn!までのびっくりを出してくれる関数
powlist=[0]*(n+1)
powlist[0]=1
powlist[1]=1
for i in range(2,n+1):
powlist[i]=powlist[i-1]*i%(10**9+7)
return powlist
def find_inv_power(n):
#0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
powlist=find_power(n)
check=powlist[-1]
first=1
uselist=[0]*(n+1)
secondlist=[0]*30
secondlist[0]=check
secondlist[1]=check**2
for i in range(28):
secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
a=format(10**9+5,"b")
for j in range(30):
if a[29-j]=="1":
first=(first*secondlist[j])%(10**9+7)
uselist[n]=first
for i in range(n,0,-1):
uselist[i-1]=(uselist[i]*i)%(10**9+7)
return uselist
def combi(a,b,n,r,mod):
if n<r:
return 0
elif n>=r:
return (a[n]*b[r]*b[n-r])%(mod)
x,y=list(map(int,input().split()))
power=find_power(666670)
invpower=find_inv_power(666670)
if (2*x-y)%3==0 and (2*y-x)%3==0:
if (2*x-y)>=0 and (2*y-x)>=0:
a=(2*y-x)//3
b=(2*x-y)//3
print((combi(power,invpower,a+b,b,10**9+7)))
else:
print((0))
else:
print((0))
| 53 | 46 | 1,190 | 1,191 | mod = 10**9 + 7
##mod,nについての制約は自分でいかに記入する
def pow_cal(x, n, mod):
if n == 0:
return 1
elif n == 1:
return x % mod
elif n >= 2:
if n % 2 == 0:
return (pow_cal(x, n // 2, mod) ** 2) % mod
else:
return (x * pow_cal(x, n // 2, mod) ** 2) % mod
def find_power(n, mod):
# 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである)
powlist = [0] * (n + 1)
powlist[0] = 1
powlist[1] = 1
for i in range(2, n + 1):
powlist[i] = powlist[i - 1] * i % (mod)
return powlist
def find_inv_power(n, mod):
# 0!からn!までの逆元を素数modで割ったあまりリストを作る関数
c = 1
uselist = [0 for i in range(n + 1)]
for i in range(1, n + 1):
c *= i
c %= mod
first = pow_cal(c, mod - 2, mod)
uselist[n] = first
for i in range(n, 0, -1):
uselist[i - 1] = (uselist[i] * i) % (mod)
return uselist
A = find_power(10**6, mod)
B = find_inv_power(10**6, mod)
def combi(n, r, mod):
if n < r:
return 0
elif n >= r:
return (A[n] * B[r] * B[n - r]) % (mod)
x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
print((0))
else:
J = (2 * y - x) // 3
K = (2 * x - y) // 3
if J >= 0 and K >= 0:
print((combi(J + K, J, mod)))
else:
print((0))
| def find_power(n):
# 0!からn!までのびっくりを出してくれる関数
powlist = [0] * (n + 1)
powlist[0] = 1
powlist[1] = 1
for i in range(2, n + 1):
powlist[i] = powlist[i - 1] * i % (10**9 + 7)
return powlist
def find_inv_power(n):
# 0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
powlist = find_power(n)
check = powlist[-1]
first = 1
uselist = [0] * (n + 1)
secondlist = [0] * 30
secondlist[0] = check
secondlist[1] = check**2
for i in range(28):
secondlist[i + 2] = (secondlist[i + 1] ** 2) % (10**9 + 7)
a = format(10**9 + 5, "b")
for j in range(30):
if a[29 - j] == "1":
first = (first * secondlist[j]) % (10**9 + 7)
uselist[n] = first
for i in range(n, 0, -1):
uselist[i - 1] = (uselist[i] * i) % (10**9 + 7)
return uselist
def combi(a, b, n, r, mod):
if n < r:
return 0
elif n >= r:
return (a[n] * b[r] * b[n - r]) % (mod)
x, y = list(map(int, input().split()))
power = find_power(666670)
invpower = find_inv_power(666670)
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0:
if (2 * x - y) >= 0 and (2 * y - x) >= 0:
a = (2 * y - x) // 3
b = (2 * x - y) // 3
print((combi(power, invpower, a + b, b, 10**9 + 7)))
else:
print((0))
else:
print((0))
| false | 13.207547 | [
"-mod = 10**9 + 7",
"-##mod,nについての制約は自分でいかに記入する",
"-def pow_cal(x, n, mod):",
"- if n == 0:",
"- return 1",
"- elif n == 1:",
"- return x % mod",
"- elif n >= 2:",
"- if n % 2 == 0:",
"- return (pow_cal(x, n // 2, mod) ** 2) % mod",
"- else:",
"- return (x * pow_cal(x, n // 2, mod) ** 2) % mod",
"-",
"-",
"-def find_power(n, mod):",
"- # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである)",
"+def find_power(n):",
"+ # 0!からn!までのびっくりを出してくれる関数",
"- powlist[i] = powlist[i - 1] * i % (mod)",
"+ powlist[i] = powlist[i - 1] * i % (10**9 + 7)",
"-def find_inv_power(n, mod):",
"- # 0!からn!までの逆元を素数modで割ったあまりリストを作る関数",
"- c = 1",
"- uselist = [0 for i in range(n + 1)]",
"- for i in range(1, n + 1):",
"- c *= i",
"- c %= mod",
"- first = pow_cal(c, mod - 2, mod)",
"+def find_inv_power(n):",
"+ # 0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数",
"+ powlist = find_power(n)",
"+ check = powlist[-1]",
"+ first = 1",
"+ uselist = [0] * (n + 1)",
"+ secondlist = [0] * 30",
"+ secondlist[0] = check",
"+ secondlist[1] = check**2",
"+ for i in range(28):",
"+ secondlist[i + 2] = (secondlist[i + 1] ** 2) % (10**9 + 7)",
"+ a = format(10**9 + 5, \"b\")",
"+ for j in range(30):",
"+ if a[29 - j] == \"1\":",
"+ first = (first * secondlist[j]) % (10**9 + 7)",
"- uselist[i - 1] = (uselist[i] * i) % (mod)",
"+ uselist[i - 1] = (uselist[i] * i) % (10**9 + 7)",
"-A = find_power(10**6, mod)",
"-B = find_inv_power(10**6, mod)",
"-",
"-",
"-def combi(n, r, mod):",
"+def combi(a, b, n, r, mod):",
"- return (A[n] * B[r] * B[n - r]) % (mod)",
"+ return (a[n] * b[r] * b[n - r]) % (mod)",
"-if (x + y) % 3 != 0:",
"- print((0))",
"-else:",
"- J = (2 * y - x) // 3",
"- K = (2 * x - y) // 3",
"- if J >= 0 and K >= 0:",
"- print((combi(J + K, J, mod)))",
"+power = find_power(666670)",
"+invpower = find_inv_power(666670)",
"+if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0:",
"+ if (2 * x - y) >= 0 and (2 * y - x) >= 0:",
"+ a = (2 * y - x) // 3",
"+ b = (2 * x - y) // 3",
"+ print((combi(power, invpower, a + b, b, 10**9 + 7)))",
"+else:",
"+ print((0))"
] | false | 1.506988 | 1.709866 | 0.881348 | [
"s309667629",
"s858896090"
] |
u011621222 | p00481 | python | s063866022 | s580699179 | 14,580 | 10,680 | 87,232 | 33,656 | Accepted | Accepted | 26.75 | from collections import deque
h, w, n = list(map(int, input().split()))
g = ['0'] * h
sx, sy = -1, -1
pos = -1
for i in range(h):
g[i] = eval(input())
if pos == -1:
pos = g[i].find('S')
if pos != -1:
sx = i
sy = pos
book = set()
queue = deque()
ans = 0
Next = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for a in range(1, n + 1):
book.clear()
queue.clear()
queue.append((sx, sy, 0))
aim = str(a)
while len(queue):
t = queue.popleft()
if (t[0], t[1]) in book:
continue
if g[t[0]][t[1]] == aim:
ans += t[2]
# print(t[0], ' ', t[1], ' ', aim, ' ', ans)
sx, sy = t[0], t[1]
break
book.add((t[0], t[1]))
for i in range(4):
tx = t[0] + Next[i][0]
ty = t[1] + Next[i][1]
if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != 'X':
queue.append((tx, ty, t[2] + 1))
print(ans)
| from collections import deque, defaultdict
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
H, W, N = list(map(int, input().split()))
G = []
sx = sy = 0
for i in range(H):
G.append(eval(input()))
for j, c in enumerate(G[i]):
if c == 'S':
sx, sy = i, j
Q = deque()
Q.append((sx, sy, 0))
visited = defaultdict(lambda: defaultdict(int))
visited[sx][sy] = 1
target = '1'
while len(Q):
x, y, step = Q.popleft()
if G[x][y] == target:
visited.clear()
Q.clear()
target = str(int(target) + 1)
if target == str(N + 1):
print(step)
break
for dx, dy in d:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and G[nx][ny] != 'X':
if not visited[nx][ny]:
visited[nx][ny] = 1
Q.append((nx, ny, step + 1))
| 50 | 38 | 1,022 | 873 | from collections import deque
h, w, n = list(map(int, input().split()))
g = ["0"] * h
sx, sy = -1, -1
pos = -1
for i in range(h):
g[i] = eval(input())
if pos == -1:
pos = g[i].find("S")
if pos != -1:
sx = i
sy = pos
book = set()
queue = deque()
ans = 0
Next = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for a in range(1, n + 1):
book.clear()
queue.clear()
queue.append((sx, sy, 0))
aim = str(a)
while len(queue):
t = queue.popleft()
if (t[0], t[1]) in book:
continue
if g[t[0]][t[1]] == aim:
ans += t[2]
# print(t[0], ' ', t[1], ' ', aim, ' ', ans)
sx, sy = t[0], t[1]
break
book.add((t[0], t[1]))
for i in range(4):
tx = t[0] + Next[i][0]
ty = t[1] + Next[i][1]
if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != "X":
queue.append((tx, ty, t[2] + 1))
print(ans)
| from collections import deque, defaultdict
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
H, W, N = list(map(int, input().split()))
G = []
sx = sy = 0
for i in range(H):
G.append(eval(input()))
for j, c in enumerate(G[i]):
if c == "S":
sx, sy = i, j
Q = deque()
Q.append((sx, sy, 0))
visited = defaultdict(lambda: defaultdict(int))
visited[sx][sy] = 1
target = "1"
while len(Q):
x, y, step = Q.popleft()
if G[x][y] == target:
visited.clear()
Q.clear()
target = str(int(target) + 1)
if target == str(N + 1):
print(step)
break
for dx, dy in d:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and G[nx][ny] != "X":
if not visited[nx][ny]:
visited[nx][ny] = 1
Q.append((nx, ny, step + 1))
| false | 24 | [
"-from collections import deque",
"+from collections import deque, defaultdict",
"-h, w, n = list(map(int, input().split()))",
"-g = [\"0\"] * h",
"-sx, sy = -1, -1",
"-pos = -1",
"-for i in range(h):",
"- g[i] = eval(input())",
"- if pos == -1:",
"- pos = g[i].find(\"S\")",
"- if pos != -1:",
"- sx = i",
"- sy = pos",
"-book = set()",
"-queue = deque()",
"-ans = 0",
"-Next = [[-1, 0], [1, 0], [0, -1], [0, 1]]",
"-for a in range(1, n + 1):",
"- book.clear()",
"- queue.clear()",
"- queue.append((sx, sy, 0))",
"- aim = str(a)",
"- while len(queue):",
"- t = queue.popleft()",
"- if (t[0], t[1]) in book:",
"- continue",
"- if g[t[0]][t[1]] == aim:",
"- ans += t[2]",
"- # print(t[0], ' ', t[1], ' ', aim, ' ', ans)",
"- sx, sy = t[0], t[1]",
"+d = [[1, 0], [-1, 0], [0, 1], [0, -1]]",
"+H, W, N = list(map(int, input().split()))",
"+G = []",
"+sx = sy = 0",
"+for i in range(H):",
"+ G.append(eval(input()))",
"+ for j, c in enumerate(G[i]):",
"+ if c == \"S\":",
"+ sx, sy = i, j",
"+Q = deque()",
"+Q.append((sx, sy, 0))",
"+visited = defaultdict(lambda: defaultdict(int))",
"+visited[sx][sy] = 1",
"+target = \"1\"",
"+while len(Q):",
"+ x, y, step = Q.popleft()",
"+ if G[x][y] == target:",
"+ visited.clear()",
"+ Q.clear()",
"+ target = str(int(target) + 1)",
"+ if target == str(N + 1):",
"+ print(step)",
"- book.add((t[0], t[1]))",
"- for i in range(4):",
"- tx = t[0] + Next[i][0]",
"- ty = t[1] + Next[i][1]",
"- if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != \"X\":",
"- queue.append((tx, ty, t[2] + 1))",
"-print(ans)",
"+ for dx, dy in d:",
"+ nx, ny = x + dx, y + dy",
"+ if 0 <= nx < H and 0 <= ny < W and G[nx][ny] != \"X\":",
"+ if not visited[nx][ny]:",
"+ visited[nx][ny] = 1",
"+ Q.append((nx, ny, step + 1))"
] | false | 0.034937 | 0.035342 | 0.988551 | [
"s063866022",
"s580699179"
] |
u696444274 | p03030 | python | s791443045 | s356112998 | 36 | 18 | 5,148 | 3,060 | Accepted | Accepted | 50 |
import math
import itertools
import statistics
#import collections
#n = list(map(int, input().split()))
n = int(eval(input()))
data = []
for i in range(n):
s, p = input().split()
data.append((i+1, s, int(p)))
data.sort(key=lambda x:(x[1], -x[2]))
for i in range(n):
print((data[i][0]))
| n = int(eval(input()))
s = []
for i in range(n):
x, y = list(input().split())
s.append([x, int(y), i+1])
ans = sorted(s, key=lambda x: (x[0], -x[1]))
for x, y, a in ans:
print(a)
| 17 | 9 | 311 | 194 | import math
import itertools
import statistics
# import collections
# n = list(map(int, input().split()))
n = int(eval(input()))
data = []
for i in range(n):
s, p = input().split()
data.append((i + 1, s, int(p)))
data.sort(key=lambda x: (x[1], -x[2]))
for i in range(n):
print((data[i][0]))
| n = int(eval(input()))
s = []
for i in range(n):
x, y = list(input().split())
s.append([x, int(y), i + 1])
ans = sorted(s, key=lambda x: (x[0], -x[1]))
for x, y, a in ans:
print(a)
| false | 47.058824 | [
"-import math",
"-import itertools",
"-import statistics",
"-",
"-# import collections",
"-# n = list(map(int, input().split()))",
"-data = []",
"+s = []",
"- s, p = input().split()",
"- data.append((i + 1, s, int(p)))",
"-data.sort(key=lambda x: (x[1], -x[2]))",
"-for i in range(n):",
"- print((data[i][0]))",
"+ x, y = list(input().split())",
"+ s.append([x, int(y), i + 1])",
"+ans = sorted(s, key=lambda x: (x[0], -x[1]))",
"+for x, y, a in ans:",
"+ print(a)"
] | false | 0.036334 | 0.036866 | 0.985563 | [
"s791443045",
"s356112998"
] |
u576917603 | p03262 | python | s927840889 | s055730527 | 197 | 154 | 14,252 | 14,224 | Accepted | Accepted | 21.83 | n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(x)
a.sort(reverse=True)
b=[]
for i in range(n):
b.append(a[i]-a[i+1])
import fractions as f
maxi=float('inf')
if len(b)==1:
print((b[0]))
exit()
for i in range(n-1):
tmp=f.gcd(b[i],b[i+1])
maxi=min(maxi,tmp)
print(maxi)
| n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(x)
a=sorted(a)
distance=[0]*n
for i in range(n):
distance[i]=a[i+1]-a[i]
tmp=0
import fractions
for i in range(n):
tmp=fractions.gcd(distance[i],tmp)
print(tmp)
| 16 | 13 | 324 | 256 | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort(reverse=True)
b = []
for i in range(n):
b.append(a[i] - a[i + 1])
import fractions as f
maxi = float("inf")
if len(b) == 1:
print((b[0]))
exit()
for i in range(n - 1):
tmp = f.gcd(b[i], b[i + 1])
maxi = min(maxi, tmp)
print(maxi)
| n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a = sorted(a)
distance = [0] * n
for i in range(n):
distance[i] = a[i + 1] - a[i]
tmp = 0
import fractions
for i in range(n):
tmp = fractions.gcd(distance[i], tmp)
print(tmp)
| false | 18.75 | [
"-a.sort(reverse=True)",
"-b = []",
"+a = sorted(a)",
"+distance = [0] * n",
"- b.append(a[i] - a[i + 1])",
"-import fractions as f",
"+ distance[i] = a[i + 1] - a[i]",
"+tmp = 0",
"+import fractions",
"-maxi = float(\"inf\")",
"-if len(b) == 1:",
"- print((b[0]))",
"- exit()",
"-for i in range(n - 1):",
"- tmp = f.gcd(b[i], b[i + 1])",
"- maxi = min(maxi, tmp)",
"-print(maxi)",
"+for i in range(n):",
"+ tmp = fractions.gcd(distance[i], tmp)",
"+print(tmp)"
] | false | 0.160179 | 0.059356 | 2.698609 | [
"s927840889",
"s055730527"
] |
u393253137 | p02658 | python | s913875712 | s768107671 | 69 | 60 | 22,464 | 21,456 | Accepted | Accepted | 13.04 | import math
n = int(eval(input()))
A = list(map(int, input().split()))
lg = 0
for a in A:
if a == 0:
print((0))
exit()
lg += math.log10(a)
if lg > 18:
print((-1))
else:
ans = 1
for a in A:
ans *= a
if ans > 10**18:
print((-1))
else:
print(ans) | n = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
if 0 in set(A):
print((0))
exit()
for a in A:
ans *= a
if ans > 10**18:
print((-1))
exit()
print(ans) | 19 | 12 | 317 | 201 | import math
n = int(eval(input()))
A = list(map(int, input().split()))
lg = 0
for a in A:
if a == 0:
print((0))
exit()
lg += math.log10(a)
if lg > 18:
print((-1))
else:
ans = 1
for a in A:
ans *= a
if ans > 10**18:
print((-1))
else:
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
if 0 in set(A):
print((0))
exit()
for a in A:
ans *= a
if ans > 10**18:
print((-1))
exit()
print(ans)
| false | 36.842105 | [
"-import math",
"-",
"-lg = 0",
"+ans = 1",
"+if 0 in set(A):",
"+ print((0))",
"+ exit()",
"- if a == 0:",
"- print((0))",
"- exit()",
"- lg += math.log10(a)",
"-if lg > 18:",
"- print((-1))",
"-else:",
"- ans = 1",
"- for a in A:",
"- ans *= a",
"+ ans *= a",
"- else:",
"- print(ans)",
"+ exit()",
"+print(ans)"
] | false | 0.096519 | 0.039329 | 2.454135 | [
"s913875712",
"s768107671"
] |
u353797797 | p02850 | python | s478041424 | s049927023 | 862 | 767 | 96,572 | 93,148 | Accepted | Accepted | 11.02 | import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
def dfs(u,pu=-1,pc=-1):
c=0
for cu in to[u]:
if cu==pu:continue
c+=1
if c==pc:c+=1
ei=etoi[(u,cu)]
e_color[ei]=c
dfs(cu,u,c)
to=defaultdict(list)
n=int(input())
etoi={}
for i in range(n-1):
a,b=map(int1,input().split())
to[a].append(b)
to[b].append(a)
etoi[(a,b)]=etoi[(b,a)]=i
#print(etoi)
e_color=[-1]*(n-1)
max_deg_u=max(to.items(),key=lambda x:len(x[1]))[0]
dfs(max_deg_u)
print(max(e_color))
print(*e_color,sep="\n")
main()
| from collections import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
def dfs(u=0,pu=-1,pc=-1):
c=1
for i,cu in to[u]:
if cu==pu:continue
if c==pc:c+=1
ans[i]=c
dfs(cu,u,c)
c+=1
to=defaultdict(list)
n=int(input())
for i in range(n-1):
a,b=map(int1,input().split())
to[a].append([i,b])
to[b].append([i, a])
ans=[-1]*(n-1)
dfs()
print(max(ans))
print(*ans,sep="\n")
main()
| 37 | 32 | 968 | 793 | import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def main():
def dfs(u, pu=-1, pc=-1):
c = 0
for cu in to[u]:
if cu == pu:
continue
c += 1
if c == pc:
c += 1
ei = etoi[(u, cu)]
e_color[ei] = c
dfs(cu, u, c)
to = defaultdict(list)
n = int(input())
etoi = {}
for i in range(n - 1):
a, b = map(int1, input().split())
to[a].append(b)
to[b].append(a)
etoi[(a, b)] = etoi[(b, a)] = i
# print(etoi)
e_color = [-1] * (n - 1)
max_deg_u = max(to.items(), key=lambda x: len(x[1]))[0]
dfs(max_deg_u)
print(max(e_color))
print(*e_color, sep="\n")
main()
| from collections import *
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def main():
def dfs(u=0, pu=-1, pc=-1):
c = 1
for i, cu in to[u]:
if cu == pu:
continue
if c == pc:
c += 1
ans[i] = c
dfs(cu, u, c)
c += 1
to = defaultdict(list)
n = int(input())
for i in range(n - 1):
a, b = map(int1, input().split())
to[a].append([i, b])
to[b].append([i, a])
ans = [-1] * (n - 1)
dfs()
print(max(ans))
print(*ans, sep="\n")
main()
| false | 13.513514 | [
"+from collections import *",
"-from collections import defaultdict",
"- def dfs(u, pu=-1, pc=-1):",
"- c = 0",
"- for cu in to[u]:",
"+ def dfs(u=0, pu=-1, pc=-1):",
"+ c = 1",
"+ for i, cu in to[u]:",
"- c += 1",
"- ei = etoi[(u, cu)]",
"- e_color[ei] = c",
"+ ans[i] = c",
"+ c += 1",
"- etoi = {}",
"- to[a].append(b)",
"- to[b].append(a)",
"- etoi[(a, b)] = etoi[(b, a)] = i",
"- # print(etoi)",
"- e_color = [-1] * (n - 1)",
"- max_deg_u = max(to.items(), key=lambda x: len(x[1]))[0]",
"- dfs(max_deg_u)",
"- print(max(e_color))",
"- print(*e_color, sep=\"\\n\")",
"+ to[a].append([i, b])",
"+ to[b].append([i, a])",
"+ ans = [-1] * (n - 1)",
"+ dfs()",
"+ print(max(ans))",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.044269 | 0.103962 | 0.425814 | [
"s478041424",
"s049927023"
] |
u480138356 | p03835 | python | s974182548 | s657442640 | 1,601 | 535 | 2,940 | 3,060 | Accepted | Accepted | 66.58 | k, s = list(map(int, input().split()))
count = 0
for x in range(k+1):
for y in range(min(s-x+1, k+1)):
z = s - x - y
if 0 <= z and z <=k:
count += 1
print(count)
| import sys
input = sys.stdin.readline
def main():
K, S = list(map(int, input().split()))
ans = 0
for x in range(min(S, K), -1, -1):
for y in range(min(S - x, K), -1, -1):
if S - x - y <= K:
# print(x, y, S-x-y)
ans += 1
else:
break
print(ans)
if __name__ == "__main__":
main() | 9 | 20 | 197 | 394 | k, s = list(map(int, input().split()))
count = 0
for x in range(k + 1):
for y in range(min(s - x + 1, k + 1)):
z = s - x - y
if 0 <= z and z <= k:
count += 1
print(count)
| import sys
input = sys.stdin.readline
def main():
K, S = list(map(int, input().split()))
ans = 0
for x in range(min(S, K), -1, -1):
for y in range(min(S - x, K), -1, -1):
if S - x - y <= K:
# print(x, y, S-x-y)
ans += 1
else:
break
print(ans)
if __name__ == "__main__":
main()
| false | 55 | [
"-k, s = list(map(int, input().split()))",
"-count = 0",
"-for x in range(k + 1):",
"- for y in range(min(s - x + 1, k + 1)):",
"- z = s - x - y",
"- if 0 <= z and z <= k:",
"- count += 1",
"-print(count)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ K, S = list(map(int, input().split()))",
"+ ans = 0",
"+ for x in range(min(S, K), -1, -1):",
"+ for y in range(min(S - x, K), -1, -1):",
"+ if S - x - y <= K:",
"+ # print(x, y, S-x-y)",
"+ ans += 1",
"+ else:",
"+ break",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.034311 | 0.034492 | 0.994755 | [
"s974182548",
"s657442640"
] |
u260980560 | p02299 | python | s196276761 | s051002298 | 120 | 70 | 6,808 | 5,620 | Accepted | Accepted | 41.67 | from math import atan2
n = eval(input())
p = [list(map(int, input().split())) for i in range(n)]
for t in range(eval(input())):
x, y = list(map(int, input().split()))
inline = 0
theta = 0.
for i in range(n):
x0 = p[i-1][0] - x
y0 = p[i-1][1] - y
x1 = p[i][0] - x
y1 = p[i][1] - y
if x0*y1 == y0*x1 and x0*x1+y0*y1 <= 0:
inline = 1
break
theta += atan2(x0*y1-y0*x1, x0*x1+y0*y1)
if inline:
print(1)
elif theta > 1:
print(2)
else:
print(0) | def inside_polygon(p0, qs):
cnt = 0
L = len(qs)
x, y = p0
for i in range(L):
x0, y0 = qs[i-1]; x1, y1 = qs[i]
x0 -= x; y0 -= y
x1 -= x; y1 -= y
cv = x0*x1 + y0*y1
sv = x0*y1 - x1*y0
if sv == 0 and cv <= 0:
return 1
if not y0 < y1:
x0, x1 = x1, x0
y0, y1 = y1, y0
if y0 <= 0 < y1 and x0*(y1 - y0) > y0*(x1 - x0):
cnt += 1
return 2 if cnt % 2 == 1 else 0
def solve():
N = int(eval(input()))
qs = [list(map(int, input().split())) for i in range(N)]
Q = int(eval(input()))
for i in range(Q):
*p0, = list(map(int, input().split()))
print((inside_polygon(p0, qs)))
solve()
| 24 | 31 | 570 | 746 | from math import atan2
n = eval(input())
p = [list(map(int, input().split())) for i in range(n)]
for t in range(eval(input())):
x, y = list(map(int, input().split()))
inline = 0
theta = 0.0
for i in range(n):
x0 = p[i - 1][0] - x
y0 = p[i - 1][1] - y
x1 = p[i][0] - x
y1 = p[i][1] - y
if x0 * y1 == y0 * x1 and x0 * x1 + y0 * y1 <= 0:
inline = 1
break
theta += atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1)
if inline:
print(1)
elif theta > 1:
print(2)
else:
print(0)
| def inside_polygon(p0, qs):
cnt = 0
L = len(qs)
x, y = p0
for i in range(L):
x0, y0 = qs[i - 1]
x1, y1 = qs[i]
x0 -= x
y0 -= y
x1 -= x
y1 -= y
cv = x0 * x1 + y0 * y1
sv = x0 * y1 - x1 * y0
if sv == 0 and cv <= 0:
return 1
if not y0 < y1:
x0, x1 = x1, x0
y0, y1 = y1, y0
if y0 <= 0 < y1 and x0 * (y1 - y0) > y0 * (x1 - x0):
cnt += 1
return 2 if cnt % 2 == 1 else 0
def solve():
N = int(eval(input()))
qs = [list(map(int, input().split())) for i in range(N)]
Q = int(eval(input()))
for i in range(Q):
(*p0,) = list(map(int, input().split()))
print((inside_polygon(p0, qs)))
solve()
| false | 22.580645 | [
"-from math import atan2",
"+def inside_polygon(p0, qs):",
"+ cnt = 0",
"+ L = len(qs)",
"+ x, y = p0",
"+ for i in range(L):",
"+ x0, y0 = qs[i - 1]",
"+ x1, y1 = qs[i]",
"+ x0 -= x",
"+ y0 -= y",
"+ x1 -= x",
"+ y1 -= y",
"+ cv = x0 * x1 + y0 * y1",
"+ sv = x0 * y1 - x1 * y0",
"+ if sv == 0 and cv <= 0:",
"+ return 1",
"+ if not y0 < y1:",
"+ x0, x1 = x1, x0",
"+ y0, y1 = y1, y0",
"+ if y0 <= 0 < y1 and x0 * (y1 - y0) > y0 * (x1 - x0):",
"+ cnt += 1",
"+ return 2 if cnt % 2 == 1 else 0",
"-n = eval(input())",
"-p = [list(map(int, input().split())) for i in range(n)]",
"-for t in range(eval(input())):",
"- x, y = list(map(int, input().split()))",
"- inline = 0",
"- theta = 0.0",
"- for i in range(n):",
"- x0 = p[i - 1][0] - x",
"- y0 = p[i - 1][1] - y",
"- x1 = p[i][0] - x",
"- y1 = p[i][1] - y",
"- if x0 * y1 == y0 * x1 and x0 * x1 + y0 * y1 <= 0:",
"- inline = 1",
"- break",
"- theta += atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1)",
"- if inline:",
"- print(1)",
"- elif theta > 1:",
"- print(2)",
"- else:",
"- print(0)",
"+",
"+def solve():",
"+ N = int(eval(input()))",
"+ qs = [list(map(int, input().split())) for i in range(N)]",
"+ Q = int(eval(input()))",
"+ for i in range(Q):",
"+ (*p0,) = list(map(int, input().split()))",
"+ print((inside_polygon(p0, qs)))",
"+",
"+",
"+solve()"
] | false | 0.043786 | 0.044083 | 0.993264 | [
"s196276761",
"s051002298"
] |
u707187541 | p02621 | python | s345911778 | s279812060 | 33 | 27 | 9,148 | 9,060 | Accepted | Accepted | 18.18 | a=int(eval(input()))
b=a+a**2+a**3
print((int(b))) | a=int(eval(input()))
b=a+a**2+a**3
print(b) | 3 | 3 | 44 | 39 | a = int(eval(input()))
b = a + a**2 + a**3
print((int(b)))
| a = int(eval(input()))
b = a + a**2 + a**3
print(b)
| false | 0 | [
"-print((int(b)))",
"+print(b)"
] | false | 0.047977 | 0.04595 | 1.044098 | [
"s345911778",
"s279812060"
] |
u489959379 | p03659 | python | s713942645 | s340604845 | 197 | 162 | 24,832 | 23,800 | Accepted | Accepted | 17.77 | n = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
arai = 0
f_inf = float("inf")
res = f_inf
for i in range(n - 1):
arai += A[i]
sunuke -= A[i]
res = min(res, abs(sunuke - arai))
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()))
A = list(map(int, input().split()))[::-1]
snuke = sum(A)
arai = 0
res = f_inf
for i in range(n - 1):
snuke -= A[i]
arai += A[i]
res = min(res, abs(snuke - arai))
print(res)
if __name__ == '__main__':
resolve()
| 12 | 26 | 232 | 439 | n = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
arai = 0
f_inf = float("inf")
res = f_inf
for i in range(n - 1):
arai += A[i]
sunuke -= A[i]
res = min(res, abs(sunuke - arai))
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()))
A = list(map(int, input().split()))[::-1]
snuke = sum(A)
arai = 0
res = f_inf
for i in range(n - 1):
snuke -= A[i]
arai += A[i]
res = min(res, abs(snuke - arai))
print(res)
if __name__ == "__main__":
resolve()
| false | 53.846154 | [
"-n = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-sunuke = sum(A)",
"-arai = 0",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"-res = f_inf",
"-for i in range(n - 1):",
"- arai += A[i]",
"- sunuke -= A[i]",
"- res = min(res, abs(sunuke - arai))",
"-print(res)",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ n = int(eval(input()))",
"+ A = list(map(int, input().split()))[::-1]",
"+ snuke = sum(A)",
"+ arai = 0",
"+ res = f_inf",
"+ for i in range(n - 1):",
"+ snuke -= A[i]",
"+ arai += A[i]",
"+ res = min(res, abs(snuke - arai))",
"+ print(res)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.064425 | 0.068134 | 0.945569 | [
"s713942645",
"s340604845"
] |
u790812284 | p03478 | python | s630999668 | s144052978 | 60 | 46 | 3,404 | 3,060 | Accepted | Accepted | 23.33 | n,a,b=list(map(int,input().split()))
l=[]
for i in range(1,n+1):
tmp=0
tmp_l=[]
for j in range(len(str(i))):#各桁の和を算出
tmp_l.append(int(str(i)[j]))
tmp=sum(tmp_l)
if a<= tmp <=b:
l.append(i)
ans=sum(l)
print(ans) | n,a,b=list(map(int, input().split()))
ans = 0
for i in range(1,n+1):
wa = 0
for j in range(len(str(i))):
wa += int(str(i)[j])
if wa>= a and wa<=b:
ans+=i
print(ans) | 13 | 9 | 265 | 194 | n, a, b = list(map(int, input().split()))
l = []
for i in range(1, n + 1):
tmp = 0
tmp_l = []
for j in range(len(str(i))): # 各桁の和を算出
tmp_l.append(int(str(i)[j]))
tmp = sum(tmp_l)
if a <= tmp <= b:
l.append(i)
ans = sum(l)
print(ans)
| n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
wa = 0
for j in range(len(str(i))):
wa += int(str(i)[j])
if wa >= a and wa <= b:
ans += i
print(ans)
| false | 30.769231 | [
"-l = []",
"+ans = 0",
"- tmp = 0",
"- tmp_l = []",
"- for j in range(len(str(i))): # 各桁の和を算出",
"- tmp_l.append(int(str(i)[j]))",
"- tmp = sum(tmp_l)",
"- if a <= tmp <= b:",
"- l.append(i)",
"-ans = sum(l)",
"+ wa = 0",
"+ for j in range(len(str(i))):",
"+ wa += int(str(i)[j])",
"+ if wa >= a and wa <= b:",
"+ ans += i"
] | false | 0.090832 | 0.036728 | 2.473098 | [
"s630999668",
"s144052978"
] |
u476604182 | p02781 | python | s448332281 | s491011279 | 28 | 18 | 3,936 | 3,064 | Accepted | Accepted | 35.71 | from functools import lru_cache
N = int(eval(input()))
K = int(eval(input()))
@lru_cache(None)
def f(n,k):
if k<0:
return 0
if n<10:
if k>1:
return 0
elif k==1:
return n
elif k==0:
return 1
a, b = divmod(n,10)
m = 9*f(a-1,k-1)+f(a,k)+b*(f(a,k-1)-f(a-1,k-1))
return m
print((f(N,K))) | N = eval(input())
K = int(eval(input()))
L = len(N)
dp0 = [[0]*(K+1) for i in range(L+1)]
dp1 = [[0]*(K+1) for i in range(L+1)]
dp0[0][0] = 1
for i in range(1,L+1):
c = int(N[i-1])
for j in range(K+1):
if j==0:
if c>0:
dp1[i][j] = dp1[i-1][j]+dp0[i-1][j]
dp0[i][j] = 0
else:
dp1[i][j] = dp1[i-1][j]
dp0[i][j] = dp0[i-1][j]
else:
if c>0:
dp1[i][j] = dp0[i-1][j-1]*(c-1)+dp1[i-1][j-1]*9+dp1[i-1][j]+dp0[i-1][j]
dp0[i][j] = dp0[i-1][j-1]
else:
dp1[i][j] = dp1[i-1][j-1]*9+dp1[i-1][j]
dp0[i][j] = dp0[i-1][j]
print((dp0[-1][-1]+dp1[-1][-1])) | 18 | 24 | 329 | 646 | from functools import lru_cache
N = int(eval(input()))
K = int(eval(input()))
@lru_cache(None)
def f(n, k):
if k < 0:
return 0
if n < 10:
if k > 1:
return 0
elif k == 1:
return n
elif k == 0:
return 1
a, b = divmod(n, 10)
m = 9 * f(a - 1, k - 1) + f(a, k) + b * (f(a, k - 1) - f(a - 1, k - 1))
return m
print((f(N, K)))
| N = eval(input())
K = int(eval(input()))
L = len(N)
dp0 = [[0] * (K + 1) for i in range(L + 1)]
dp1 = [[0] * (K + 1) for i in range(L + 1)]
dp0[0][0] = 1
for i in range(1, L + 1):
c = int(N[i - 1])
for j in range(K + 1):
if j == 0:
if c > 0:
dp1[i][j] = dp1[i - 1][j] + dp0[i - 1][j]
dp0[i][j] = 0
else:
dp1[i][j] = dp1[i - 1][j]
dp0[i][j] = dp0[i - 1][j]
else:
if c > 0:
dp1[i][j] = (
dp0[i - 1][j - 1] * (c - 1)
+ dp1[i - 1][j - 1] * 9
+ dp1[i - 1][j]
+ dp0[i - 1][j]
)
dp0[i][j] = dp0[i - 1][j - 1]
else:
dp1[i][j] = dp1[i - 1][j - 1] * 9 + dp1[i - 1][j]
dp0[i][j] = dp0[i - 1][j]
print((dp0[-1][-1] + dp1[-1][-1]))
| false | 25 | [
"-from functools import lru_cache",
"-",
"-N = int(eval(input()))",
"+N = eval(input())",
"-",
"-",
"-@lru_cache(None)",
"-def f(n, k):",
"- if k < 0:",
"- return 0",
"- if n < 10:",
"- if k > 1:",
"- return 0",
"- elif k == 1:",
"- return n",
"- elif k == 0:",
"- return 1",
"- a, b = divmod(n, 10)",
"- m = 9 * f(a - 1, k - 1) + f(a, k) + b * (f(a, k - 1) - f(a - 1, k - 1))",
"- return m",
"-",
"-",
"-print((f(N, K)))",
"+L = len(N)",
"+dp0 = [[0] * (K + 1) for i in range(L + 1)]",
"+dp1 = [[0] * (K + 1) for i in range(L + 1)]",
"+dp0[0][0] = 1",
"+for i in range(1, L + 1):",
"+ c = int(N[i - 1])",
"+ for j in range(K + 1):",
"+ if j == 0:",
"+ if c > 0:",
"+ dp1[i][j] = dp1[i - 1][j] + dp0[i - 1][j]",
"+ dp0[i][j] = 0",
"+ else:",
"+ dp1[i][j] = dp1[i - 1][j]",
"+ dp0[i][j] = dp0[i - 1][j]",
"+ else:",
"+ if c > 0:",
"+ dp1[i][j] = (",
"+ dp0[i - 1][j - 1] * (c - 1)",
"+ + dp1[i - 1][j - 1] * 9",
"+ + dp1[i - 1][j]",
"+ + dp0[i - 1][j]",
"+ )",
"+ dp0[i][j] = dp0[i - 1][j - 1]",
"+ else:",
"+ dp1[i][j] = dp1[i - 1][j - 1] * 9 + dp1[i - 1][j]",
"+ dp0[i][j] = dp0[i - 1][j]",
"+print((dp0[-1][-1] + dp1[-1][-1]))"
] | false | 0.06012 | 0.062623 | 0.960031 | [
"s448332281",
"s491011279"
] |
u604839890 | p02659 | python | s758774572 | s616825592 | 102 | 33 | 61,488 | 9,180 | Accepted | Accepted | 67.65 | a, b = input().split()
a = int(a)
b = 100*int(b[0])+10*int(b[2])+int(b[3])
print((a*b//100))
| a, b = input().split()
a = int(a)
b = int(b[0])*100 + int(b[2])*10 + int(b[3])
print((a*b//100)) | 4 | 4 | 94 | 97 | a, b = input().split()
a = int(a)
b = 100 * int(b[0]) + 10 * int(b[2]) + int(b[3])
print((a * b // 100))
| a, b = input().split()
a = int(a)
b = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3])
print((a * b // 100))
| false | 0 | [
"-b = 100 * int(b[0]) + 10 * int(b[2]) + int(b[3])",
"+b = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3])"
] | false | 0.03539 | 0.093667 | 0.377826 | [
"s758774572",
"s616825592"
] |
u392319141 | p03111 | python | s601662751 | s352498423 | 1,087 | 406 | 3,188 | 3,064 | Accepted | Accepted | 62.65 | N, A, B, C = list(map(int, input().split()))
L = []
for _ in range(N):
L.append(int(eval(input())))
ans = float('inf')
for mask in range(pow(4, N)):
cost = 0
for i, l in enumerate([A, B, C]):
grp = []
for digit in range(N):
if mask // pow(4, digit) % 4 == i:
grp.append(L[digit])
if not grp:
cost = float('inf')
cost += (len(grp) - 1) * 10
cost += abs(l - sum(grp))
ans = min(ans, cost)
print(ans) | from itertools import product
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 10**18
for state in product(list(range(4)), repeat=N):
K = [[] for _ in range(4)]
for i, l in enumerate(L):
K[state[i]].append(l)
cost = 0
for d, D in zip((A, B, C), K):
if len(D) == 0:
cost += 10**18
cost += (len(D) - 1) * 10
cost += abs(d - sum(D))
ans = min(ans, cost)
print(ans)
| 22 | 20 | 506 | 476 | N, A, B, C = list(map(int, input().split()))
L = []
for _ in range(N):
L.append(int(eval(input())))
ans = float("inf")
for mask in range(pow(4, N)):
cost = 0
for i, l in enumerate([A, B, C]):
grp = []
for digit in range(N):
if mask // pow(4, digit) % 4 == i:
grp.append(L[digit])
if not grp:
cost = float("inf")
cost += (len(grp) - 1) * 10
cost += abs(l - sum(grp))
ans = min(ans, cost)
print(ans)
| from itertools import product
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 10**18
for state in product(list(range(4)), repeat=N):
K = [[] for _ in range(4)]
for i, l in enumerate(L):
K[state[i]].append(l)
cost = 0
for d, D in zip((A, B, C), K):
if len(D) == 0:
cost += 10**18
cost += (len(D) - 1) * 10
cost += abs(d - sum(D))
ans = min(ans, cost)
print(ans)
| false | 9.090909 | [
"+from itertools import product",
"+",
"-L = []",
"-for _ in range(N):",
"- L.append(int(eval(input())))",
"-ans = float(\"inf\")",
"-for mask in range(pow(4, N)):",
"+L = [int(eval(input())) for _ in range(N)]",
"+ans = 10**18",
"+for state in product(list(range(4)), repeat=N):",
"+ K = [[] for _ in range(4)]",
"+ for i, l in enumerate(L):",
"+ K[state[i]].append(l)",
"- for i, l in enumerate([A, B, C]):",
"- grp = []",
"- for digit in range(N):",
"- if mask // pow(4, digit) % 4 == i:",
"- grp.append(L[digit])",
"- if not grp:",
"- cost = float(\"inf\")",
"- cost += (len(grp) - 1) * 10",
"- cost += abs(l - sum(grp))",
"+ for d, D in zip((A, B, C), K):",
"+ if len(D) == 0:",
"+ cost += 10**18",
"+ cost += (len(D) - 1) * 10",
"+ cost += abs(d - sum(D))"
] | false | 1.80809 | 0.364875 | 4.955374 | [
"s601662751",
"s352498423"
] |
u334712262 | p03008 | python | s423780932 | s885867161 | 1,165 | 844 | 823,160 | 432,412 | Accepted | Accepted | 27.55 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, GSB):
def f(N, gsb):
dp = [[0] * (N+1) for _ in range(4)]
for i in range(3):
v = gsb[1][i] - gsb[0][i]
a = gsb[0][i]
if v > 0:
for w in range(N+1):
dp[i+1][w] = dp[i][w]
if w >= a:
dp[i+1][w] = max(dp[i][w], dp[i+1][w-a] + v)
else:
dp[i+1] = dp[i]
return dp[3][N] + N
tmp = f(N, GSB)
# print(tmp)
GSB[0], GSB[1] = GSB[1], GSB[0]
return f(tmp, GSB)
def main():
N = read_int()
GSB = [read_int_n() for _ in range(2)]
print(slv(N, GSB))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
import copy
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, GSB):
def f(N, gsb):
dp0 = [0] * (N+1)
dp1 = [0] * (N+1)
for i in range(3):
v = gsb[1][i] - gsb[0][i]
a = gsb[0][i]
if v > 0:
for w in range(N+1):
if w >= a:
dp1[w] = max(dp0[w], dp1[w-a] + v)
else:
dp1 = dp0
dp0 = dp1
dp1 = copy.copy(dp0)
return dp0[N] + N
tmp = f(N, GSB)
# print(tmp)
GSB[0], GSB[1] = GSB[1], GSB[0]
return f(tmp, GSB)
def main():
N = read_int()
GSB = [read_int_n() for _ in range(2)]
print(slv(N, GSB))
if __name__ == '__main__':
main()
| 87 | 90 | 1,797 | 1,814 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, GSB):
def f(N, gsb):
dp = [[0] * (N + 1) for _ in range(4)]
for i in range(3):
v = gsb[1][i] - gsb[0][i]
a = gsb[0][i]
if v > 0:
for w in range(N + 1):
dp[i + 1][w] = dp[i][w]
if w >= a:
dp[i + 1][w] = max(dp[i][w], dp[i + 1][w - a] + v)
else:
dp[i + 1] = dp[i]
return dp[3][N] + N
tmp = f(N, GSB)
# print(tmp)
GSB[0], GSB[1] = GSB[1], GSB[0]
return f(tmp, GSB)
def main():
N = read_int()
GSB = [read_int_n() for _ in range(2)]
print(slv(N, GSB))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
import copy
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, GSB):
def f(N, gsb):
dp0 = [0] * (N + 1)
dp1 = [0] * (N + 1)
for i in range(3):
v = gsb[1][i] - gsb[0][i]
a = gsb[0][i]
if v > 0:
for w in range(N + 1):
if w >= a:
dp1[w] = max(dp0[w], dp1[w - a] + v)
else:
dp1 = dp0
dp0 = dp1
dp1 = copy.copy(dp0)
return dp0[N] + N
tmp = f(N, GSB)
# print(tmp)
GSB[0], GSB[1] = GSB[1], GSB[0]
return f(tmp, GSB)
def main():
N = read_int()
GSB = [read_int_n() for _ in range(2)]
print(slv(N, GSB))
if __name__ == "__main__":
main()
| false | 3.333333 | [
"+import copy",
"- dp = [[0] * (N + 1) for _ in range(4)]",
"+ dp0 = [0] * (N + 1)",
"+ dp1 = [0] * (N + 1)",
"- dp[i + 1][w] = dp[i][w]",
"- dp[i + 1][w] = max(dp[i][w], dp[i + 1][w - a] + v)",
"+ dp1[w] = max(dp0[w], dp1[w - a] + v)",
"- dp[i + 1] = dp[i]",
"- return dp[3][N] + N",
"+ dp1 = dp0",
"+ dp0 = dp1",
"+ dp1 = copy.copy(dp0)",
"+ return dp0[N] + N"
] | false | 0.040103 | 0.087678 | 0.457387 | [
"s423780932",
"s885867161"
] |
u779455925 | p03734 | python | s928448293 | s249905006 | 77 | 59 | 5,240 | 3,700 | Accepted | Accepted | 23.38 | from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()
N,W=list(map(int,input().split()))
WV=[list(map(int,input().split())) for i in range(N)]
lst=deque([])
for w,v in WV:
nlst=deque([[w,v]])
for i in range(len(lst)):
w1,v1=lst[i]
if w1+w<=W:
if w1:
nlst.append([w1+w,v1+v])
if not lst:
lst=copy.copy(nlst)
continue
Xlst=lst
lst=deque()
if Xlst or nlst:
w1,v1=nlst[0]
w2,v2=Xlst[0]
if w1<w2:
lst.append(nlst.popleft())
else:
lst.append(Xlst.popleft())
while Xlst or nlst:
w,v=lst[-1]
if Xlst and nlst:
w1,v1=nlst[0]
w2,v2=Xlst[0]
if w==w1:
if v>=v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
elif w==w2:
if v>=v2:
Xlst.popleft()
else:
lst.pop()
lst.append(Xlst.popleft())
else:
if w1<w2:
if v>=v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
else:
if v>=v2:
Xlst.popleft()
else:
lst.append(Xlst.popleft())
elif nlst:
w1,v1=nlst[0]
if w==w1:
if v>=v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
else:
if v>=v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
elif Xlst:
nlst=Xlst
Xlst=deque()
lst.append([0,0])
print((max([v for w,v in lst if w<=W])))
| import sys
from collections import *
import copy
input=lambda :sys.stdin.readline().rstrip()
N,W=list(map(int,input().split()))
WV=[list(map(int,input().split())) for i in range(N)]
lst=deque([])
for w,v in WV:
nlst=deque([[w,v]])
for i in range(len(lst)):
w1,v1=lst[i]
if w1+w<=W:
if w1:
nlst.append([w1+w,v1+v])
if not lst:
lst=copy.copy(nlst)
continue
Xlst=lst
lst=deque()
if Xlst or nlst:
w1,v1=nlst[0]
w2,v2=Xlst[0]
if w1<w2:
lst.append(nlst.popleft())
else:
lst.append(Xlst.popleft())
while Xlst or nlst:
w,v=lst[-1]
if Xlst and nlst:
w1,v1=nlst[0]
w2,v2=Xlst[0]
if w==w1:
if v>=v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
elif w==w2:
if v>=v2:
Xlst.popleft()
else:
lst.pop()
lst.append(Xlst.popleft())
else:
if w1<w2:
if v>=v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
else:
if v>=v2:
Xlst.popleft()
else:
lst.append(Xlst.popleft())
elif nlst:
w1,v1=nlst[0]
if w==w1:
if v>=v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
else:
if v>=v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
elif Xlst:
nlst=Xlst
Xlst=deque()
lst.append([0,0])
print((max([v for w,v in lst if w<=W])))
| 83 | 78 | 2,170 | 2,052 | from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input = lambda: sys.stdin.readline().rstrip()
N, W = list(map(int, input().split()))
WV = [list(map(int, input().split())) for i in range(N)]
lst = deque([])
for w, v in WV:
nlst = deque([[w, v]])
for i in range(len(lst)):
w1, v1 = lst[i]
if w1 + w <= W:
if w1:
nlst.append([w1 + w, v1 + v])
if not lst:
lst = copy.copy(nlst)
continue
Xlst = lst
lst = deque()
if Xlst or nlst:
w1, v1 = nlst[0]
w2, v2 = Xlst[0]
if w1 < w2:
lst.append(nlst.popleft())
else:
lst.append(Xlst.popleft())
while Xlst or nlst:
w, v = lst[-1]
if Xlst and nlst:
w1, v1 = nlst[0]
w2, v2 = Xlst[0]
if w == w1:
if v >= v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
elif w == w2:
if v >= v2:
Xlst.popleft()
else:
lst.pop()
lst.append(Xlst.popleft())
else:
if w1 < w2:
if v >= v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
else:
if v >= v2:
Xlst.popleft()
else:
lst.append(Xlst.popleft())
elif nlst:
w1, v1 = nlst[0]
if w == w1:
if v >= v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
else:
if v >= v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
elif Xlst:
nlst = Xlst
Xlst = deque()
lst.append([0, 0])
print((max([v for w, v in lst if w <= W])))
| import sys
from collections import *
import copy
input = lambda: sys.stdin.readline().rstrip()
N, W = list(map(int, input().split()))
WV = [list(map(int, input().split())) for i in range(N)]
lst = deque([])
for w, v in WV:
nlst = deque([[w, v]])
for i in range(len(lst)):
w1, v1 = lst[i]
if w1 + w <= W:
if w1:
nlst.append([w1 + w, v1 + v])
if not lst:
lst = copy.copy(nlst)
continue
Xlst = lst
lst = deque()
if Xlst or nlst:
w1, v1 = nlst[0]
w2, v2 = Xlst[0]
if w1 < w2:
lst.append(nlst.popleft())
else:
lst.append(Xlst.popleft())
while Xlst or nlst:
w, v = lst[-1]
if Xlst and nlst:
w1, v1 = nlst[0]
w2, v2 = Xlst[0]
if w == w1:
if v >= v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
elif w == w2:
if v >= v2:
Xlst.popleft()
else:
lst.pop()
lst.append(Xlst.popleft())
else:
if w1 < w2:
if v >= v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
else:
if v >= v2:
Xlst.popleft()
else:
lst.append(Xlst.popleft())
elif nlst:
w1, v1 = nlst[0]
if w == w1:
if v >= v1:
nlst.popleft()
else:
lst.pop()
lst.append(nlst.popleft())
else:
if v >= v1:
nlst.popleft()
else:
lst.append(nlst.popleft())
elif Xlst:
nlst = Xlst
Xlst = deque()
lst.append([0, 0])
print((max([v for w, v in lst if w <= W])))
| false | 6.024096 | [
"+import sys",
"-from heapq import *",
"-from itertools import *",
"-from fractions import gcd",
"-import sys",
"-from decimal import *",
"-from bisect import *"
] | false | 0.160445 | 0.039261 | 4.086628 | [
"s928448293",
"s249905006"
] |
u580093517 | p03447 | python | s387923770 | s366789550 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | x,a,b = [int(eval(input())) for i in range(3)]
print(((x-a)%b)) | print(((int(eval(input()))-int(eval(input())))%int(eval(input())))) | 2 | 1 | 56 | 47 | x, a, b = [int(eval(input())) for i in range(3)]
print(((x - a) % b))
| print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))
| false | 50 | [
"-x, a, b = [int(eval(input())) for i in range(3)]",
"-print(((x - a) % b))",
"+print(((int(eval(input())) - int(eval(input()))) % int(eval(input()))))"
] | false | 0.039303 | 0.038226 | 1.028157 | [
"s387923770",
"s366789550"
] |
u272525952 | p02819 | python | s210310288 | s588700658 | 182 | 29 | 38,896 | 9,428 | Accepted | Accepted | 84.07 | x=int(eval(input()))
if x==2 or x==3:
print(x)
else:
i=x
flag=True
while i<=100003 and flag==True:
flag=False
for j in range(2,int(i**(1/2)//1+1)):
if i%j==0:
flag=True
break
i+=1
print((i-1)) | x=int(eval(input()))
flag=True
while flag:
i=2
fla=True
while i<=x**0.5:
if x%i==0:
fla=False
break
else:
if i==2:
i+=1
else:
i+=2
if fla==False:
x+=1
else:
print(x)
flag=False | 16 | 19 | 289 | 328 | x = int(eval(input()))
if x == 2 or x == 3:
print(x)
else:
i = x
flag = True
while i <= 100003 and flag == True:
flag = False
for j in range(2, int(i ** (1 / 2) // 1 + 1)):
if i % j == 0:
flag = True
break
i += 1
print((i - 1))
| x = int(eval(input()))
flag = True
while flag:
i = 2
fla = True
while i <= x**0.5:
if x % i == 0:
fla = False
break
else:
if i == 2:
i += 1
else:
i += 2
if fla == False:
x += 1
else:
print(x)
flag = False
| false | 15.789474 | [
"-if x == 2 or x == 3:",
"- print(x)",
"-else:",
"- i = x",
"- flag = True",
"- while i <= 100003 and flag == True:",
"+flag = True",
"+while flag:",
"+ i = 2",
"+ fla = True",
"+ while i <= x**0.5:",
"+ if x % i == 0:",
"+ fla = False",
"+ break",
"+ else:",
"+ if i == 2:",
"+ i += 1",
"+ else:",
"+ i += 2",
"+ if fla == False:",
"+ x += 1",
"+ else:",
"+ print(x)",
"- for j in range(2, int(i ** (1 / 2) // 1 + 1)):",
"- if i % j == 0:",
"- flag = True",
"- break",
"- i += 1",
"- print((i - 1))"
] | false | 0.038633 | 0.046897 | 0.823784 | [
"s210310288",
"s588700658"
] |
u191874006 | p02834 | python | s505247967 | s229060861 | 499 | 446 | 65,312 | 65,312 | Accepted | Accepted | 10.62 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,V,U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = LI()
edges[a-1].append(b-1)
edges[b-1].append(a-1)
if n == 2:
print((0))
else:
depth_v = [None]*n
depth_v[V] = 0
que = deque()
que.append(V)
while que:
v = que.popleft()
for u in edges[v]:
if depth_v[u] == None:
depth_v[u] = depth_v[v]+1
que.append(u)
depth_u = [None]*n
depth_u[U] = 0
que = deque()
que.append(U)
while que:
u = que.popleft()
for v in edges[u]:
if depth_u[v] == None:
depth_u[v] = depth_u[u] + 1
que.append(v)
ans = 0
for v in range(n):
if depth_v[v] < depth_u[v]:
ans = max(ans,depth_u[v]-1)
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
"""
[考察]
高橋君が最も遠くに逃げる場合
:= (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点)
⇒高橋君が先に行ける頂点
高橋君からの各頂点の距離(高橋君を根としたときの木の深さ),
青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、
高橋君からの距離と青木君からの距離を比較
⇒青木君から最も遠い頂点
青木君からの各頂点の距離の最大値
"""
n,V,U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = LI()
edges[a-1].append(b-1)
edges[b-1].append(a-1)
if n == 2:
print((0))
else:
depth_v = [None]*n
depth_v[V] = 0
que = deque()
que.append(V)
while que:
v = que.popleft()
for u in edges[v]:
if depth_v[u] == None:
depth_v[u] = depth_v[v]+1
que.append(u)
depth_u = [None]*n
depth_u[U] = 0
que = deque()
que.append(U)
while que:
u = que.popleft()
for v in edges[u]:
if depth_u[v] == None:
depth_u[v] = depth_u[u] + 1
que.append(v)
ans = 0
for v in range(n):
if depth_v[v] < depth_u[v]:
ans = max(ans,depth_u[v]-1)
print(ans) | 61 | 72 | 1,423 | 1,629 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n, V, U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = LI()
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
if n == 2:
print((0))
else:
depth_v = [None] * n
depth_v[V] = 0
que = deque()
que.append(V)
while que:
v = que.popleft()
for u in edges[v]:
if depth_v[u] == None:
depth_v[u] = depth_v[v] + 1
que.append(u)
depth_u = [None] * n
depth_u[U] = 0
que = deque()
que.append(U)
while que:
u = que.popleft()
for v in edges[u]:
if depth_u[v] == None:
depth_u[v] = depth_u[u] + 1
que.append(v)
ans = 0
for v in range(n):
if depth_v[v] < depth_u[v]:
ans = max(ans, depth_u[v] - 1)
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
"""
[考察]
高橋君が最も遠くに逃げる場合
:= (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点)
⇒高橋君が先に行ける頂点
高橋君からの各頂点の距離(高橋君を根としたときの木の深さ),
青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、
高橋君からの距離と青木君からの距離を比較
⇒青木君から最も遠い頂点
青木君からの各頂点の距離の最大値
"""
n, V, U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = LI()
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
if n == 2:
print((0))
else:
depth_v = [None] * n
depth_v[V] = 0
que = deque()
que.append(V)
while que:
v = que.popleft()
for u in edges[v]:
if depth_v[u] == None:
depth_v[u] = depth_v[v] + 1
que.append(u)
depth_u = [None] * n
depth_u[U] = 0
que = deque()
que.append(U)
while que:
u = que.popleft()
for v in edges[u]:
if depth_u[v] == None:
depth_u[v] = depth_u[u] + 1
que.append(v)
ans = 0
for v in range(n):
if depth_v[v] < depth_u[v]:
ans = max(ans, depth_u[v] - 1)
print(ans)
| false | 15.277778 | [
"+\"\"\"",
"+[考察]",
"+ 高橋君が最も遠くに逃げる場合",
"+ := (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点)",
"+⇒高橋君が先に行ける頂点",
"+ 高橋君からの各頂点の距離(高橋君を根としたときの木の深さ),",
"+ 青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、",
"+ 高橋君からの距離と青木君からの距離を比較",
"+⇒青木君から最も遠い頂点",
"+ 青木君からの各頂点の距離の最大値",
"+\"\"\""
] | false | 0.087779 | 0.041226 | 2.129217 | [
"s505247967",
"s229060861"
] |
u268210555 | p03147 | python | s627769737 | s240381969 | 325 | 18 | 21,532 | 2,940 | Accepted | Accepted | 94.46 | import numpy as np
n = int(eval(input()))
h = np.array([0] + list(map(int, input().split())))
r = 0
while np.any(h>0):
r += np.sum(np.logical_and(h[1:]>0, h[:-1]<=0))
h -= 1
print(r) | n = int(eval(input()))
h = list(map(int, input().split()))
print((sum(max(0, h[i-1]-h[i]) for i in range(1, n)) + h[-1])) | 8 | 3 | 191 | 115 | import numpy as np
n = int(eval(input()))
h = np.array([0] + list(map(int, input().split())))
r = 0
while np.any(h > 0):
r += np.sum(np.logical_and(h[1:] > 0, h[:-1] <= 0))
h -= 1
print(r)
| n = int(eval(input()))
h = list(map(int, input().split()))
print((sum(max(0, h[i - 1] - h[i]) for i in range(1, n)) + h[-1]))
| false | 62.5 | [
"-import numpy as np",
"-",
"-h = np.array([0] + list(map(int, input().split())))",
"-r = 0",
"-while np.any(h > 0):",
"- r += np.sum(np.logical_and(h[1:] > 0, h[:-1] <= 0))",
"- h -= 1",
"-print(r)",
"+h = list(map(int, input().split()))",
"+print((sum(max(0, h[i - 1] - h[i]) for i in range(1, n)) + h[-1]))"
] | false | 0.369619 | 0.036101 | 10.238361 | [
"s627769737",
"s240381969"
] |
u019685451 | p02584 | python | s805161560 | s368297586 | 63 | 31 | 61,964 | 9,184 | Accepted | Accepted | 50.79 | def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub)
t = round(-X / D)
ans = abs(X)
for i in [-2, -1, 0, +1, +2]:
tt = t + i
tt = min(tt, ub)
tt = max(tt, lb)
y = X + tt * D
ans = min(ans, abs(y))
return ans
X, K, D = list(map(int, input().split()))
y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
print((min(abs(y1), abs(y2))))
else:
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| from math import floor
def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
ts = [
lb,
ub,
max(min(floor(-X / D), ub), lb),
max(min(floor(-X / D) + 1, ub), lb),
]
return min([abs(X + t * D) for t in ts])
X, K, D = list(map(int, input().split()))
y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
print((min(abs(y1), abs(y2))))
else:
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| 27 | 27 | 734 | 742 | def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub)
t = round(-X / D)
ans = abs(X)
for i in [-2, -1, 0, +1, +2]:
tt = t + i
tt = min(tt, ub)
tt = max(tt, lb)
y = X + tt * D
ans = min(ans, abs(y))
return ans
X, K, D = list(map(int, input().split()))
y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
print((min(abs(y1), abs(y2))))
else:
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| from math import floor
def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
ts = [
lb,
ub,
max(min(floor(-X / D), ub), lb),
max(min(floor(-X / D) + 1, ub), lb),
]
return min([abs(X + t * D) for t in ts])
X, K, D = list(map(int, input().split()))
y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
print((min(abs(y1), abs(y2))))
else:
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| false | 0 | [
"+from math import floor",
"+",
"+",
"- # min abs(X + t * D) (lb <= t <= ub)",
"- t = round(-X / D)",
"- ans = abs(X)",
"- for i in [-2, -1, 0, +1, +2]:",
"- tt = t + i",
"- tt = min(tt, ub)",
"- tt = max(tt, lb)",
"- y = X + tt * D",
"- ans = min(ans, abs(y))",
"- return ans",
"+ # min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)",
"+ ts = [",
"+ lb,",
"+ ub,",
"+ max(min(floor(-X / D), ub), lb),",
"+ max(min(floor(-X / D) + 1, ub), lb),",
"+ ]",
"+ return min([abs(X + t * D) for t in ts])"
] | false | 0.045355 | 0.037632 | 1.205247 | [
"s805161560",
"s368297586"
] |
u046592970 | p02773 | python | s522072258 | s435617994 | 980 | 649 | 101,968 | 35,572 | Accepted | Accepted | 33.78 | from collections import Counter
n = int(eval(input()))
s = Counter([eval(input()) for _ in range(n)])
mx = max(s.values())
ans = []
for k,v in list(s.items()):
if v==mx:
ans.append(k)
for i in sorted(ans):
print(i) | from collections import defaultdict
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
dd = defaultdict(int)
for x in s:
dd[x] += 1
mx = max(dd.values())
for k in sorted(j for j,y in list(dd.items()) if y == mx):
print(k) | 11 | 11 | 223 | 233 | from collections import Counter
n = int(eval(input()))
s = Counter([eval(input()) for _ in range(n)])
mx = max(s.values())
ans = []
for k, v in list(s.items()):
if v == mx:
ans.append(k)
for i in sorted(ans):
print(i)
| from collections import defaultdict
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
dd = defaultdict(int)
for x in s:
dd[x] += 1
mx = max(dd.values())
for k in sorted(j for j, y in list(dd.items()) if y == mx):
print(k)
| false | 0 | [
"-from collections import Counter",
"+from collections import defaultdict",
"-s = Counter([eval(input()) for _ in range(n)])",
"-mx = max(s.values())",
"-ans = []",
"-for k, v in list(s.items()):",
"- if v == mx:",
"- ans.append(k)",
"-for i in sorted(ans):",
"- print(i)",
"+s = [eval(input()) for _ in range(n)]",
"+dd = defaultdict(int)",
"+for x in s:",
"+ dd[x] += 1",
"+mx = max(dd.values())",
"+for k in sorted(j for j, y in list(dd.items()) if y == mx):",
"+ print(k)"
] | false | 0.176817 | 0.042845 | 4.126909 | [
"s522072258",
"s435617994"
] |
u394721319 | p03068 | python | s761695050 | s677376027 | 170 | 28 | 38,384 | 9,052 | Accepted | Accepted | 83.53 | N = int(eval(input()))
S = eval(input())
K = int(eval(input()))
k = S[K-1]
ans = ''
for i in S:
if i != k:
ans += '*'
else:
ans += i
print(ans)
| N = int(eval(input()))
S = list(eval(input()))
K = int(eval(input()))-1
ans = ''
p = S[K]
for i in range(N):
if p == S[i]:
ans += S[i]
else:
ans += '*'
print(ans)
| 14 | 13 | 166 | 183 | N = int(eval(input()))
S = eval(input())
K = int(eval(input()))
k = S[K - 1]
ans = ""
for i in S:
if i != k:
ans += "*"
else:
ans += i
print(ans)
| N = int(eval(input()))
S = list(eval(input()))
K = int(eval(input())) - 1
ans = ""
p = S[K]
for i in range(N):
if p == S[i]:
ans += S[i]
else:
ans += "*"
print(ans)
| false | 7.142857 | [
"-S = eval(input())",
"-K = int(eval(input()))",
"-k = S[K - 1]",
"+S = list(eval(input()))",
"+K = int(eval(input())) - 1",
"-for i in S:",
"- if i != k:",
"+p = S[K]",
"+for i in range(N):",
"+ if p == S[i]:",
"+ ans += S[i]",
"+ else:",
"- else:",
"- ans += i"
] | false | 0.040243 | 0.037786 | 1.065025 | [
"s761695050",
"s677376027"
] |
u348805958 | p02632 | python | s881046031 | s119657705 | 1,784 | 916 | 106,824 | 106,176 | Accepted | Accepted | 48.65 | #!python3
import sys
iim = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
def _cmb(N, mod):
N1 = N + 1
fact = [0] * N1
inv = [0] * N1
fact[0] = fact[1] = inv[0] = inv[1] = 1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[i] = pow(fact[i], mod-2, mod)
def cmb(a, b):
return fact[a] * inv[b] * inv[a-b] % mod
return cmb
def resolve():
K = int(eval(input()))
s = eval(input())
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
for i in range(K+1):
ans += cmb(ls+i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| #!python3
import sys
iim = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N-1, 1, -1):
inv[i] = inv[i+1]*(i+1) % mod
def cmb(a, b):
return fact[a] * inv[b] * inv[a-b] % mod
return cmb
def resolve():
K = int(eval(input()))
s = eval(input())
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
for i in range(K+1):
ans += cmb(ls+i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| 35 | 37 | 728 | 753 | #!python3
import sys
iim = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
def _cmb(N, mod):
N1 = N + 1
fact = [0] * N1
inv = [0] * N1
fact[0] = fact[1] = inv[0] = inv[1] = 1
for i in range(2, N1):
fact[i] = fact[i - 1] * i % mod
inv[i] = pow(fact[i], mod - 2, mod)
def cmb(a, b):
return fact[a] * inv[b] * inv[a - b] % mod
return cmb
def resolve():
K = int(eval(input()))
s = eval(input())
ls = len(s) - 1
mod = 10**9 + 7
cmb = _cmb(ls + K, mod)
ans = 0
for i in range(K + 1):
ans += cmb(ls + i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| #!python3
import sys
iim = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i - 1] * i % mod
inv[N] = pow(fact[N], mod - 2, mod)
for i in range(N - 1, 1, -1):
inv[i] = inv[i + 1] * (i + 1) % mod
def cmb(a, b):
return fact[a] * inv[b] * inv[a - b] % mod
return cmb
def resolve():
K = int(eval(input()))
s = eval(input())
ls = len(s) - 1
mod = 10**9 + 7
cmb = _cmb(ls + K, mod)
ans = 0
for i in range(K + 1):
ans += cmb(ls + i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| false | 5.405405 | [
"- fact = [0] * N1",
"- inv = [0] * N1",
"- fact[0] = fact[1] = inv[0] = inv[1] = 1",
"+ fact = [1] * N1",
"+ inv = [1] * N1",
"- inv[i] = pow(fact[i], mod - 2, mod)",
"+ inv[N] = pow(fact[N], mod - 2, mod)",
"+ for i in range(N - 1, 1, -1):",
"+ inv[i] = inv[i + 1] * (i + 1) % mod"
] | false | 0.046916 | 0.134479 | 0.348872 | [
"s881046031",
"s119657705"
] |
u894258749 | p03061 | python | s567957233 | s413321233 | 1,506 | 839 | 97,640 | 16,140 | Accepted | Accepted | 44.29 | from fractions import gcd
inpl = lambda: list(map(int,input().split()))
class SegAccumCalc:
def __init__(self, value, N=0, calc=lambda x,y: x+y):
M = max(len(value),N)
N = 2**(len(bin(M))-3)
if N < M: N *= 2
self.N = N
self.node = [None] * (2*N-1)
for i, v in enumerate(value):
self.node[i+N-1] = v
self.calc = lambda x, y: x if y is None else y if x is None else calc(x,y)
for i in range(N-2,-1,-1):
left, right = self.node[2*i+1], self.node[2*i+2]
self.node[i] = self.calc(left, right)
def set_value(self, n, v):
i = (self.N-1) + n
self.node[i] = v
while i > 0:
i = (i-1)//2
left, right = self.node[2*i+1], self.node[2*i+2]
new = self.calc(left,right)
if self.node[i] == new:
break
else:
self.node[i] = new
def get(self,
a=0, b=-1,
k=0, l=0, r=-1):
if b < 0:
b = self.N
if r < 0:
r = self.N
if a <= l and r <= b:
return self.node[k]
elif r <= a or b <= l:
return None
else:
left = self.get(a,b,2*k+1,l,(l+r)//2)
right = self.get(a,b,2*k+2,(l+r)//2,r)
return self.calc(left,right)
N = int(eval(input()))
A = inpl()
sac = SegAccumCalc(A,calc=gcd)
ans = 0
for i in range(N):
if i == 0:
c = sac.get(1,N)
elif i == N-1:
c = sac.get(0,N-1)
else:
c = gcd(sac.get(0,i),sac.get(i+1,N))
if c > ans:
ans = c
print(ans) | from fractions import gcd
inpl = lambda: list(map(int,input().split()))
class SegAccumCalc:
def __init__(self, value, N=0, calc=lambda x,y: x+y):
M = max(len(value),N)
N = 2**(len(bin(M))-3)
if N < M: N *= 2
self.N = N
self.node = [None] * (2*N-1)
for i, v in enumerate(value):
self.node[i+N-1] = v
self.calc = lambda x, y: x if y is None else y if x is None else calc(x,y)
for i in range(N-2,-1,-1):
left, right = self.node[2*i+1], self.node[2*i+2]
self.node[i] = self.calc(left, right)
def set_input(self, n, v):
i = (self.N-1) + n
self.node[i] = v
while i > 0:
i = (i-1)//2
left, right = self.node[2*i+1], self.node[2*i+2]
new = self.calc(left,right)
if self.node[i] == new:
break
else:
self.node[i] = new
def get_input(self, n):
return self.node[(self.N-1)+n]
def get_output(self,
a=0, b=-1,
k=0, l=0, r=-1):
if b < 0:
b = self.N
if r < 0:
r = self.N
if a <= l and r <= b:
return self.node[k]
elif r <= a or b <= l:
return None
else:
left = self.get_output(a,b,2*k+1,l,(l+r)//2)
right = self.get_output(a,b,2*k+2,(l+r)//2,r)
return self.calc(left,right)
N = int(eval(input()))
A = inpl()
sac = SegAccumCalc(A,calc=gcd)
ans = 0
for i in range(N):
sac.set_input(i,0)
g = sac.get_output()
if g > ans:
ans = g
sac.set_input(i,A[i])
print(ans) | 59 | 59 | 1,689 | 1,729 | from fractions import gcd
inpl = lambda: list(map(int, input().split()))
class SegAccumCalc:
def __init__(self, value, N=0, calc=lambda x, y: x + y):
M = max(len(value), N)
N = 2 ** (len(bin(M)) - 3)
if N < M:
N *= 2
self.N = N
self.node = [None] * (2 * N - 1)
for i, v in enumerate(value):
self.node[i + N - 1] = v
self.calc = lambda x, y: x if y is None else y if x is None else calc(x, y)
for i in range(N - 2, -1, -1):
left, right = self.node[2 * i + 1], self.node[2 * i + 2]
self.node[i] = self.calc(left, right)
def set_value(self, n, v):
i = (self.N - 1) + n
self.node[i] = v
while i > 0:
i = (i - 1) // 2
left, right = self.node[2 * i + 1], self.node[2 * i + 2]
new = self.calc(left, right)
if self.node[i] == new:
break
else:
self.node[i] = new
def get(self, a=0, b=-1, k=0, l=0, r=-1):
if b < 0:
b = self.N
if r < 0:
r = self.N
if a <= l and r <= b:
return self.node[k]
elif r <= a or b <= l:
return None
else:
left = self.get(a, b, 2 * k + 1, l, (l + r) // 2)
right = self.get(a, b, 2 * k + 2, (l + r) // 2, r)
return self.calc(left, right)
N = int(eval(input()))
A = inpl()
sac = SegAccumCalc(A, calc=gcd)
ans = 0
for i in range(N):
if i == 0:
c = sac.get(1, N)
elif i == N - 1:
c = sac.get(0, N - 1)
else:
c = gcd(sac.get(0, i), sac.get(i + 1, N))
if c > ans:
ans = c
print(ans)
| from fractions import gcd
inpl = lambda: list(map(int, input().split()))
class SegAccumCalc:
def __init__(self, value, N=0, calc=lambda x, y: x + y):
M = max(len(value), N)
N = 2 ** (len(bin(M)) - 3)
if N < M:
N *= 2
self.N = N
self.node = [None] * (2 * N - 1)
for i, v in enumerate(value):
self.node[i + N - 1] = v
self.calc = lambda x, y: x if y is None else y if x is None else calc(x, y)
for i in range(N - 2, -1, -1):
left, right = self.node[2 * i + 1], self.node[2 * i + 2]
self.node[i] = self.calc(left, right)
def set_input(self, n, v):
i = (self.N - 1) + n
self.node[i] = v
while i > 0:
i = (i - 1) // 2
left, right = self.node[2 * i + 1], self.node[2 * i + 2]
new = self.calc(left, right)
if self.node[i] == new:
break
else:
self.node[i] = new
def get_input(self, n):
return self.node[(self.N - 1) + n]
def get_output(self, a=0, b=-1, k=0, l=0, r=-1):
if b < 0:
b = self.N
if r < 0:
r = self.N
if a <= l and r <= b:
return self.node[k]
elif r <= a or b <= l:
return None
else:
left = self.get_output(a, b, 2 * k + 1, l, (l + r) // 2)
right = self.get_output(a, b, 2 * k + 2, (l + r) // 2, r)
return self.calc(left, right)
N = int(eval(input()))
A = inpl()
sac = SegAccumCalc(A, calc=gcd)
ans = 0
for i in range(N):
sac.set_input(i, 0)
g = sac.get_output()
if g > ans:
ans = g
sac.set_input(i, A[i])
print(ans)
| false | 0 | [
"- def set_value(self, n, v):",
"+ def set_input(self, n, v):",
"- def get(self, a=0, b=-1, k=0, l=0, r=-1):",
"+ def get_input(self, n):",
"+ return self.node[(self.N - 1) + n]",
"+",
"+ def get_output(self, a=0, b=-1, k=0, l=0, r=-1):",
"- left = self.get(a, b, 2 * k + 1, l, (l + r) // 2)",
"- right = self.get(a, b, 2 * k + 2, (l + r) // 2, r)",
"+ left = self.get_output(a, b, 2 * k + 1, l, (l + r) // 2)",
"+ right = self.get_output(a, b, 2 * k + 2, (l + r) // 2, r)",
"- if i == 0:",
"- c = sac.get(1, N)",
"- elif i == N - 1:",
"- c = sac.get(0, N - 1)",
"- else:",
"- c = gcd(sac.get(0, i), sac.get(i + 1, N))",
"- if c > ans:",
"- ans = c",
"+ sac.set_input(i, 0)",
"+ g = sac.get_output()",
"+ if g > ans:",
"+ ans = g",
"+ sac.set_input(i, A[i])"
] | false | 0.053805 | 0.110957 | 0.484922 | [
"s567957233",
"s413321233"
] |
u520276780 | p02642 | python | s100082008 | s911731049 | 1,829 | 162 | 133,924 | 135,972 | Accepted | Accepted | 91.14 | from collections import Counter
n=int(eval(input()))
*a,=list(map(int, input().split()))
sa=Counter(a)
if 1 in sa:
if sa[1]>1:
print((0))
else:
print((1))
exit()
# def fct(x):
# f1=[1]
# f2=[]
# for i in range(2,min(int(x**(1/2)+7),x)):
# if x%i==0:
# f1.append(i)
# f2.append(x//i)
# return (set(f1+f2))
ans=0
for ai in sa:
if sa[ai]>1:
continue
ans+=1
if ai%2==0:
for i in range(2,min(int(ai**(1/2)+7),ai)):
if ai%i==0:
if i in sa or ai//i in sa:
ans-=1
break
else:
for i in range(3,min(int(ai**(1/2)+7),ai),2):
if ai%i==0:
if i in sa or ai//i in sa:
ans-=1
break
print(ans)
| ##想定解
n=int(eval(input()))
*a,=list(map(int, input().split( )))
from collections import Counter
ca=Counter(a)
nn=[0]*(10**6+1)
for ai in ca:
nn[ai]=ca[ai]
ans=0
for i in range(10**6+1):
if nn[i]==1:
ans+=1
if nn[i]:
for j in range(2*i,10**6+1,i):
nn[j]=0
print(ans)
| 39 | 23 | 858 | 323 | from collections import Counter
n = int(eval(input()))
(*a,) = list(map(int, input().split()))
sa = Counter(a)
if 1 in sa:
if sa[1] > 1:
print((0))
else:
print((1))
exit()
# def fct(x):
# f1=[1]
# f2=[]
# for i in range(2,min(int(x**(1/2)+7),x)):
# if x%i==0:
# f1.append(i)
# f2.append(x//i)
# return (set(f1+f2))
ans = 0
for ai in sa:
if sa[ai] > 1:
continue
ans += 1
if ai % 2 == 0:
for i in range(2, min(int(ai ** (1 / 2) + 7), ai)):
if ai % i == 0:
if i in sa or ai // i in sa:
ans -= 1
break
else:
for i in range(3, min(int(ai ** (1 / 2) + 7), ai), 2):
if ai % i == 0:
if i in sa or ai // i in sa:
ans -= 1
break
print(ans)
| ##想定解
n = int(eval(input()))
(*a,) = list(map(int, input().split()))
from collections import Counter
ca = Counter(a)
nn = [0] * (10**6 + 1)
for ai in ca:
nn[ai] = ca[ai]
ans = 0
for i in range(10**6 + 1):
if nn[i] == 1:
ans += 1
if nn[i]:
for j in range(2 * i, 10**6 + 1, i):
nn[j] = 0
print(ans)
| false | 41.025641 | [
"+##想定解",
"+n = int(eval(input()))",
"+(*a,) = list(map(int, input().split()))",
"-n = int(eval(input()))",
"-(*a,) = list(map(int, input().split()))",
"-sa = Counter(a)",
"-if 1 in sa:",
"- if sa[1] > 1:",
"- print((0))",
"- else:",
"- print((1))",
"- exit()",
"-# def fct(x):",
"-# f1=[1]",
"-# f2=[]",
"-# for i in range(2,min(int(x**(1/2)+7),x)):",
"-# if x%i==0:",
"-# f1.append(i)",
"-# f2.append(x//i)",
"-# return (set(f1+f2))",
"+ca = Counter(a)",
"+nn = [0] * (10**6 + 1)",
"+for ai in ca:",
"+ nn[ai] = ca[ai]",
"-for ai in sa:",
"- if sa[ai] > 1:",
"- continue",
"- ans += 1",
"- if ai % 2 == 0:",
"- for i in range(2, min(int(ai ** (1 / 2) + 7), ai)):",
"- if ai % i == 0:",
"- if i in sa or ai // i in sa:",
"- ans -= 1",
"- break",
"- else:",
"- for i in range(3, min(int(ai ** (1 / 2) + 7), ai), 2):",
"- if ai % i == 0:",
"- if i in sa or ai // i in sa:",
"- ans -= 1",
"- break",
"+for i in range(10**6 + 1):",
"+ if nn[i] == 1:",
"+ ans += 1",
"+ if nn[i]:",
"+ for j in range(2 * i, 10**6 + 1, i):",
"+ nn[j] = 0"
] | false | 0.095006 | 0.558762 | 0.170029 | [
"s100082008",
"s911731049"
] |
u697559326 | p02613 | python | s523467464 | s617468769 | 186 | 171 | 70,012 | 69,960 | Accepted | Accepted | 8.06 | N = int(input())
out = ["AC","WA","TLE","RE"]
output = [0]*4
for _ in range(N):
S = input()
if S == out[0]:
output[0] += 1
elif S == out[1]:
output[1] += 1
elif S == out[2]:
output[2] += 1
else:
output[3] += 1
print(out[0],"x",output[0])
print(out[1],"x",output[1])
print(out[2],"x",output[2])
print(out[3],"x",output[3],end="")
| N = int(eval(input()))
out = ["AC","WA","TLE","RE"]
output = [0]*4
for _ in range(N):
S = eval(input())
if S == out[0]:
output[0] += 1
elif S == out[1]:
output[1] += 1
elif S == out[2]:
output[2] += 1
else:
output[3] += 1
for i in range(4):
print((out[i],"x",output[i])) | 19 | 17 | 400 | 330 | N = int(input())
out = ["AC", "WA", "TLE", "RE"]
output = [0] * 4
for _ in range(N):
S = input()
if S == out[0]:
output[0] += 1
elif S == out[1]:
output[1] += 1
elif S == out[2]:
output[2] += 1
else:
output[3] += 1
print(out[0], "x", output[0])
print(out[1], "x", output[1])
print(out[2], "x", output[2])
print(out[3], "x", output[3], end="")
| N = int(eval(input()))
out = ["AC", "WA", "TLE", "RE"]
output = [0] * 4
for _ in range(N):
S = eval(input())
if S == out[0]:
output[0] += 1
elif S == out[1]:
output[1] += 1
elif S == out[2]:
output[2] += 1
else:
output[3] += 1
for i in range(4):
print((out[i], "x", output[i]))
| false | 10.526316 | [
"-N = int(input())",
"+N = int(eval(input()))",
"- S = input()",
"+ S = eval(input())",
"-print(out[0], \"x\", output[0])",
"-print(out[1], \"x\", output[1])",
"-print(out[2], \"x\", output[2])",
"-print(out[3], \"x\", output[3], end=\"\")",
"+for i in range(4):",
"+ print((out[i], \"x\", output[i]))"
] | false | 0.039891 | 0.034016 | 1.172738 | [
"s523467464",
"s617468769"
] |
u981931040 | p02802 | python | s126835937 | s749465722 | 266 | 202 | 4,596 | 10,360 | Accepted | Accepted | 24.06 | N , M = list(map(int,input().split()))
lst = []
AC_list = [False] * N
WA_cnt_list = [0] * N
for _ in range(M):
r , judge = input().split()
question_num = int(r) - 1
if AC_list[question_num]:
continue
elif judge == "WA":
WA_cnt_list[question_num] += 1
elif judge == "AC":
AC_list[question_num] = True
wa_cnt = 0
for i in range(N):
if AC_list[i]:
wa_cnt += WA_cnt_list[i]
print((sum(AC_list) , wa_cnt))
| N, M = list(map(int, input().split()))
AC_flags = [False] * N
WA_counter = [0] * N
for _ in range(M):
p, s = input().split()
p = int(p) - 1
if AC_flags[p]:
continue
elif s == 'WA':
WA_counter[p] += 1
else:
AC_flags[p] = True
penalty = 0
for i in range(N):
penalty += AC_flags[i] * WA_counter[i]
print((sum(AC_flags), penalty))
| 18 | 17 | 466 | 384 | N, M = list(map(int, input().split()))
lst = []
AC_list = [False] * N
WA_cnt_list = [0] * N
for _ in range(M):
r, judge = input().split()
question_num = int(r) - 1
if AC_list[question_num]:
continue
elif judge == "WA":
WA_cnt_list[question_num] += 1
elif judge == "AC":
AC_list[question_num] = True
wa_cnt = 0
for i in range(N):
if AC_list[i]:
wa_cnt += WA_cnt_list[i]
print((sum(AC_list), wa_cnt))
| N, M = list(map(int, input().split()))
AC_flags = [False] * N
WA_counter = [0] * N
for _ in range(M):
p, s = input().split()
p = int(p) - 1
if AC_flags[p]:
continue
elif s == "WA":
WA_counter[p] += 1
else:
AC_flags[p] = True
penalty = 0
for i in range(N):
penalty += AC_flags[i] * WA_counter[i]
print((sum(AC_flags), penalty))
| false | 5.555556 | [
"-lst = []",
"-AC_list = [False] * N",
"-WA_cnt_list = [0] * N",
"+AC_flags = [False] * N",
"+WA_counter = [0] * N",
"- r, judge = input().split()",
"- question_num = int(r) - 1",
"- if AC_list[question_num]:",
"+ p, s = input().split()",
"+ p = int(p) - 1",
"+ if AC_flags[p]:",
"- elif judge == \"WA\":",
"- WA_cnt_list[question_num] += 1",
"- elif judge == \"AC\":",
"- AC_list[question_num] = True",
"-wa_cnt = 0",
"+ elif s == \"WA\":",
"+ WA_counter[p] += 1",
"+ else:",
"+ AC_flags[p] = True",
"+penalty = 0",
"- if AC_list[i]:",
"- wa_cnt += WA_cnt_list[i]",
"-print((sum(AC_list), wa_cnt))",
"+ penalty += AC_flags[i] * WA_counter[i]",
"+print((sum(AC_flags), penalty))"
] | false | 0.059205 | 0.037613 | 1.574081 | [
"s126835937",
"s749465722"
] |
u367701763 | p02560 | python | s400257601 | s155930657 | 218 | 195 | 70,716 | 74,432 | Accepted | Accepted | 10.55 | def floor_sum(n, m, a, b):
res = 0
if b >= m:
res += n * (b // m)
b %= m
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
y_max = (a * n + b) // m
if y_max == 0: break
x_max = b - y_max * m
res += (n + x_max // a) * y_max
n, m, a, b = y_max, a, m, x_max % a
return res
import sys
input = sys.stdin.readline
for i in range(int(eval(input()))):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b))) | # 一番早いのを写経したものを弄ってアルゴリズム勉強のための試し打ち中
def floor_sum(n, m, a, b):
res = 0
if b >= m:
res += n * (b // m)
b %= m
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
y_max = (a * n + b) // m
if y_max == 0: break
x_max = b - y_max * m
res += (n + x_max // a) * y_max
n, m, a, b = y_max, a, m, x_max % a
return res
import sys
input = sys.stdin.buffer.readline
T = int(eval(input()))
res = [''] * T
for i in range(T):
n, m, a, b = list(map(int, input().split()))
res[i] = str(floor_sum(n, m, a, b))
print(('\n'.join(res)))
| 23 | 30 | 557 | 661 | def floor_sum(n, m, a, b):
res = 0
if b >= m:
res += n * (b // m)
b %= m
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
y_max = (a * n + b) // m
if y_max == 0:
break
x_max = b - y_max * m
res += (n + x_max // a) * y_max
n, m, a, b = y_max, a, m, x_max % a
return res
import sys
input = sys.stdin.readline
for i in range(int(eval(input()))):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b)))
| # 一番早いのを写経したものを弄ってアルゴリズム勉強のための試し打ち中
def floor_sum(n, m, a, b):
res = 0
if b >= m:
res += n * (b // m)
b %= m
while True:
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
y_max = (a * n + b) // m
if y_max == 0:
break
x_max = b - y_max * m
res += (n + x_max // a) * y_max
n, m, a, b = y_max, a, m, x_max % a
return res
import sys
input = sys.stdin.buffer.readline
T = int(eval(input()))
res = [""] * T
for i in range(T):
n, m, a, b = list(map(int, input().split()))
res[i] = str(floor_sum(n, m, a, b))
print(("\n".join(res)))
| false | 23.333333 | [
"+# 一番早いのを写経したものを弄ってアルゴリズム勉強のための試し打ち中",
"-input = sys.stdin.readline",
"-for i in range(int(eval(input()))):",
"+input = sys.stdin.buffer.readline",
"+T = int(eval(input()))",
"+res = [\"\"] * T",
"+for i in range(T):",
"- print((floor_sum(n, m, a, b)))",
"+ res[i] = str(floor_sum(n, m, a, b))",
"+print((\"\\n\".join(res)))"
] | false | 0.045535 | 0.040791 | 1.116294 | [
"s400257601",
"s155930657"
] |
u764215612 | p02690 | python | s878178313 | s579099712 | 25 | 23 | 9,424 | 9,476 | Accepted | Accepted | 8 | import math
x=int(eval(input()))
for i in range(120):
for j in range(-54,i):
if math.pow(i,5)-math.pow(j,5)==x:print((i,j));exit() | import math
X = int(eval(input()))
a1 = math.ceil(X**(1/5))
N = int(1e10)
c = 0
b = 0
while c <= N:
if b**5 < -X:
b2 = b + 1
break
b -= 1
c = 0
while c <= N:
c += 1
b1 = math.floor((a1**5-X)**(1/5))
a2 = math.floor((X+b2**5)**(1/5))
if a1**5 - b1**5 == X:
print((a1, b1))
break
elif a2**5 - b2**5 == X:
print((a2, b2))
break
a1 += 1
b2 += 1 | 5 | 24 | 129 | 437 | import math
x = int(eval(input()))
for i in range(120):
for j in range(-54, i):
if math.pow(i, 5) - math.pow(j, 5) == x:
print((i, j))
exit()
| import math
X = int(eval(input()))
a1 = math.ceil(X ** (1 / 5))
N = int(1e10)
c = 0
b = 0
while c <= N:
if b**5 < -X:
b2 = b + 1
break
b -= 1
c = 0
while c <= N:
c += 1
b1 = math.floor((a1**5 - X) ** (1 / 5))
a2 = math.floor((X + b2**5) ** (1 / 5))
if a1**5 - b1**5 == X:
print((a1, b1))
break
elif a2**5 - b2**5 == X:
print((a2, b2))
break
a1 += 1
b2 += 1
| false | 79.166667 | [
"-x = int(eval(input()))",
"-for i in range(120):",
"- for j in range(-54, i):",
"- if math.pow(i, 5) - math.pow(j, 5) == x:",
"- print((i, j))",
"- exit()",
"+X = int(eval(input()))",
"+a1 = math.ceil(X ** (1 / 5))",
"+N = int(1e10)",
"+c = 0",
"+b = 0",
"+while c <= N:",
"+ if b**5 < -X:",
"+ b2 = b + 1",
"+ break",
"+ b -= 1",
"+c = 0",
"+while c <= N:",
"+ c += 1",
"+ b1 = math.floor((a1**5 - X) ** (1 / 5))",
"+ a2 = math.floor((X + b2**5) ** (1 / 5))",
"+ if a1**5 - b1**5 == X:",
"+ print((a1, b1))",
"+ break",
"+ elif a2**5 - b2**5 == X:",
"+ print((a2, b2))",
"+ break",
"+ a1 += 1",
"+ b2 += 1"
] | false | 0.114631 | 0.074389 | 1.540969 | [
"s878178313",
"s579099712"
] |
u069868839 | p03478 | python | s508754372 | s760734984 | 1,077 | 34 | 3,060 | 3,064 | Accepted | Accepted | 96.84 | def FindSumOfDigits(n):
Sum=0
while(n>0):
Sum+=(int(n%10))
n=n/10
return Sum
N,A,B=list(map(int,input().split()))
ans=0
#ans_list=[]
#sumlist=[]
for i in range(1,N+1):
#sumlist.append(FindSumOfDigits(i))
if A<=FindSumOfDigits(i)<=B:
ans+=i
#ans_list.append(i)
print(ans)
#print(ans_list)
#print(sum_list) | N,A,B=list(map(int,input().split()))
cnt=0
for n in range(1,N+1):
total=0
total+=n%10
total+=int(n/10)%10
total+=int((n/10)/10)%10
total+=int(((n/10)/10)/10)%10
total+=int((((n/10)/10)/10)/10)%10
if A<=total<=B:
cnt+=n
print(cnt) | 19 | 12 | 369 | 270 | def FindSumOfDigits(n):
Sum = 0
while n > 0:
Sum += int(n % 10)
n = n / 10
return Sum
N, A, B = list(map(int, input().split()))
ans = 0
# ans_list=[]
# sumlist=[]
for i in range(1, N + 1):
# sumlist.append(FindSumOfDigits(i))
if A <= FindSumOfDigits(i) <= B:
ans += i
# ans_list.append(i)
print(ans)
# print(ans_list)
# print(sum_list)
| N, A, B = list(map(int, input().split()))
cnt = 0
for n in range(1, N + 1):
total = 0
total += n % 10
total += int(n / 10) % 10
total += int((n / 10) / 10) % 10
total += int(((n / 10) / 10) / 10) % 10
total += int((((n / 10) / 10) / 10) / 10) % 10
if A <= total <= B:
cnt += n
print(cnt)
| false | 36.842105 | [
"-def FindSumOfDigits(n):",
"- Sum = 0",
"- while n > 0:",
"- Sum += int(n % 10)",
"- n = n / 10",
"- return Sum",
"-",
"-",
"-ans = 0",
"-# ans_list=[]",
"-# sumlist=[]",
"-for i in range(1, N + 1):",
"- # sumlist.append(FindSumOfDigits(i))",
"- if A <= FindSumOfDigits(i) <= B:",
"- ans += i",
"- # ans_list.append(i)",
"-print(ans)",
"-# print(ans_list)",
"-# print(sum_list)",
"+cnt = 0",
"+for n in range(1, N + 1):",
"+ total = 0",
"+ total += n % 10",
"+ total += int(n / 10) % 10",
"+ total += int((n / 10) / 10) % 10",
"+ total += int(((n / 10) / 10) / 10) % 10",
"+ total += int((((n / 10) / 10) / 10) / 10) % 10",
"+ if A <= total <= B:",
"+ cnt += n",
"+print(cnt)"
] | false | 0.083601 | 0.036035 | 2.319976 | [
"s508754372",
"s760734984"
] |
u426534722 | p02238 | python | s383372197 | s245896837 | 30 | 20 | 7,840 | 5,628 | Accepted | Accepted | 33.33 | from sys import stdin
n = int(stdin.readline())
M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
global tt
sndf[u][0] = True
tt += 1
sndf[u].append(tt)
for v in M[u]:
v -= 1
if not sndf[v][0]:
dfs(v)
tt += 1
sndf[u].append(tt)
for i in range(0, n):
if not sndf[i][0]:
dfs(i)
print((*sndf[i][1:])) | def MAIN():
n = int(eval(input()))
ans = [[i, 0, 0] for i in range((n + 1))]
G = [[] for _ in range((n + 1))]
for _ in range(n):
u, k, *v = list(map(int, input().split()))
G[u] = v
cnt = 1
def dfs(u):
nonlocal ans
if ans[u][1] != 0:
return
nonlocal cnt
ans[u][1] = cnt
cnt += 1
for v in G[u]:
dfs(v)
ans[u][2] = cnt
cnt += 1
for i in range(1, n + 1):
if ans[i][1] == 0:
dfs(i)
for i in range(1, n + 1):
print((" ".join(map(str, ans[i]))))
MAIN()
| 20 | 26 | 469 | 622 | from sys import stdin
n = int(stdin.readline())
M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
global tt
sndf[u][0] = True
tt += 1
sndf[u].append(tt)
for v in M[u]:
v -= 1
if not sndf[v][0]:
dfs(v)
tt += 1
sndf[u].append(tt)
for i in range(0, n):
if not sndf[i][0]:
dfs(i)
print((*sndf[i][1:]))
| def MAIN():
n = int(eval(input()))
ans = [[i, 0, 0] for i in range((n + 1))]
G = [[] for _ in range((n + 1))]
for _ in range(n):
u, k, *v = list(map(int, input().split()))
G[u] = v
cnt = 1
def dfs(u):
nonlocal ans
if ans[u][1] != 0:
return
nonlocal cnt
ans[u][1] = cnt
cnt += 1
for v in G[u]:
dfs(v)
ans[u][2] = cnt
cnt += 1
for i in range(1, n + 1):
if ans[i][1] == 0:
dfs(i)
for i in range(1, n + 1):
print((" ".join(map(str, ans[i]))))
MAIN()
| false | 23.076923 | [
"-from sys import stdin",
"+def MAIN():",
"+ n = int(eval(input()))",
"+ ans = [[i, 0, 0] for i in range((n + 1))]",
"+ G = [[] for _ in range((n + 1))]",
"+ for _ in range(n):",
"+ u, k, *v = list(map(int, input().split()))",
"+ G[u] = v",
"+ cnt = 1",
"-n = int(stdin.readline())",
"-M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]",
"-sndf = [[False, i] for i in range(1, n + 1)]",
"-tt = 0",
"+ def dfs(u):",
"+ nonlocal ans",
"+ if ans[u][1] != 0:",
"+ return",
"+ nonlocal cnt",
"+ ans[u][1] = cnt",
"+ cnt += 1",
"+ for v in G[u]:",
"+ dfs(v)",
"+ ans[u][2] = cnt",
"+ cnt += 1",
"+",
"+ for i in range(1, n + 1):",
"+ if ans[i][1] == 0:",
"+ dfs(i)",
"+ for i in range(1, n + 1):",
"+ print((\" \".join(map(str, ans[i]))))",
"-def dfs(u):",
"- global tt",
"- sndf[u][0] = True",
"- tt += 1",
"- sndf[u].append(tt)",
"- for v in M[u]:",
"- v -= 1",
"- if not sndf[v][0]:",
"- dfs(v)",
"- tt += 1",
"- sndf[u].append(tt)",
"-",
"-",
"-for i in range(0, n):",
"- if not sndf[i][0]:",
"- dfs(i)",
"- print((*sndf[i][1:]))",
"+MAIN()"
] | false | 0.033273 | 0.034086 | 0.976147 | [
"s383372197",
"s245896837"
] |
u126232616 | p03495 | python | s827974299 | s085235066 | 190 | 127 | 39,348 | 32,540 | Accepted | Accepted | 33.16 | from collections import Counter
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
cnt = Counter(a)
mo = cnt.most_common()[::-1]
#print(mo)
ans = 0
for i in range(max(0,len(mo)-k)):
ans += mo[i][1]
print(ans)
| from collections import Counter
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
cnt = Counter(a)
mo = sorted(cnt.values())
#print(mo)
ans = 0
for i in range(max(0,len(mo)-k)):
ans += mo[i]
print(ans)
| 10 | 10 | 237 | 231 | from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = Counter(a)
mo = cnt.most_common()[::-1]
# print(mo)
ans = 0
for i in range(max(0, len(mo) - k)):
ans += mo[i][1]
print(ans)
| from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = Counter(a)
mo = sorted(cnt.values())
# print(mo)
ans = 0
for i in range(max(0, len(mo) - k)):
ans += mo[i]
print(ans)
| false | 0 | [
"-mo = cnt.most_common()[::-1]",
"+mo = sorted(cnt.values())",
"- ans += mo[i][1]",
"+ ans += mo[i]"
] | false | 0.046696 | 0.049655 | 0.940409 | [
"s827974299",
"s085235066"
] |
u919633157 | p03761 | python | s037700638 | s442874171 | 75 | 20 | 3,064 | 3,064 | Accepted | Accepted | 73.33 | # 2019/07/19
# LCSっぽい?
n=int(eval(input()))
s=[sorted(eval(input())) for _ in range(n)]
def lcs(s1,s2):
dp=[[0]*(len(s2)+1) for _ in range(len(s1)+1)]
for i in range(len(s1)):
for j in range(len(s2)):
if s1[i]==s2[j]:
dp[i+1][j+1]=dp[i][j]+1
else:
dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
# 復元
ans=''
i,j=len(s1),len(s2)
while i>=0 and j>=0:
if dp[i-1][j]==dp[i][j]:i-=1
elif dp[i][j-1]==dp[i][j]:j-=1
else:
ans=s1[i-1]+ans
i,j=i-1,j-1
return sorted(ans)
s1=s[0]
for i in range(1,n):
s2=s[i]
s1=lcs(s1,s2)
print((''.join(s1)))
| # https://atcoder.jp/contests/abc058/tasks/arc071_a
n=int(input())
s=[sorted(input()) for _ in range(n)]
alfa=[float('inf')]*26
for e in s:
for i in range(26):
cnt=e.count(chr(97+i))
alfa[i]=min(alfa[i],cnt)
ans=[]
for i in range(26):
ans.append(chr(97+i)*alfa[i])
print(*ans,sep='')
| 35 | 14 | 706 | 322 | # 2019/07/19
# LCSっぽい?
n = int(eval(input()))
s = [sorted(eval(input())) for _ in range(n)]
def lcs(s1, s2):
dp = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)]
for i in range(len(s1)):
for j in range(len(s2)):
if s1[i] == s2[j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
# 復元
ans = ""
i, j = len(s1), len(s2)
while i >= 0 and j >= 0:
if dp[i - 1][j] == dp[i][j]:
i -= 1
elif dp[i][j - 1] == dp[i][j]:
j -= 1
else:
ans = s1[i - 1] + ans
i, j = i - 1, j - 1
return sorted(ans)
s1 = s[0]
for i in range(1, n):
s2 = s[i]
s1 = lcs(s1, s2)
print(("".join(s1)))
| # https://atcoder.jp/contests/abc058/tasks/arc071_a
n = int(input())
s = [sorted(input()) for _ in range(n)]
alfa = [float("inf")] * 26
for e in s:
for i in range(26):
cnt = e.count(chr(97 + i))
alfa[i] = min(alfa[i], cnt)
ans = []
for i in range(26):
ans.append(chr(97 + i) * alfa[i])
print(*ans, sep="")
| false | 60 | [
"-# 2019/07/19",
"-# LCSっぽい?",
"-n = int(eval(input()))",
"-s = [sorted(eval(input())) for _ in range(n)]",
"-",
"-",
"-def lcs(s1, s2):",
"- dp = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)]",
"- for i in range(len(s1)):",
"- for j in range(len(s2)):",
"- if s1[i] == s2[j]:",
"- dp[i + 1][j + 1] = dp[i][j] + 1",
"- else:",
"- dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])",
"- # 復元",
"- ans = \"\"",
"- i, j = len(s1), len(s2)",
"- while i >= 0 and j >= 0:",
"- if dp[i - 1][j] == dp[i][j]:",
"- i -= 1",
"- elif dp[i][j - 1] == dp[i][j]:",
"- j -= 1",
"- else:",
"- ans = s1[i - 1] + ans",
"- i, j = i - 1, j - 1",
"- return sorted(ans)",
"-",
"-",
"-s1 = s[0]",
"-for i in range(1, n):",
"- s2 = s[i]",
"- s1 = lcs(s1, s2)",
"-print((\"\".join(s1)))",
"+# https://atcoder.jp/contests/abc058/tasks/arc071_a",
"+n = int(input())",
"+s = [sorted(input()) for _ in range(n)]",
"+alfa = [float(\"inf\")] * 26",
"+for e in s:",
"+ for i in range(26):",
"+ cnt = e.count(chr(97 + i))",
"+ alfa[i] = min(alfa[i], cnt)",
"+ans = []",
"+for i in range(26):",
"+ ans.append(chr(97 + i) * alfa[i])",
"+print(*ans, sep=\"\")"
] | false | 0.040033 | 0.037676 | 1.062564 | [
"s037700638",
"s442874171"
] |
u260980560 | p00097 | python | s108458329 | s059878684 | 1,490 | 220 | 6,576 | 6,516 | Accepted | Accepted | 85.23 | while 1:
n, s = list(map(int, input().split()))
if n==0:
exit(0)
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(min(s+1, 101)):
si1 = s-i+1
for k in range(n, 0, -1):
dp_k = dp[k]; dp_k1 = dp[k-1]
for j in range(si1):
dp_k[i+j] += dp_k1[j]
print(dp[n][s]) | dp = [[0]*(1001) for _ in range(10)]
dp[0][0] = 1
for i in range(101):
si1 = 1001-i
for k in range(9, 0, -1):
dp_k = dp[k]; dp_k1 = dp[k-1]
for j in range(si1):
dp_k[i+j] += dp_k1[j]
while 1:
n, s = list(map(int, input().split()))
if n==0:
exit(0)
print(dp[n][s]) | 13 | 13 | 373 | 332 | while 1:
n, s = list(map(int, input().split()))
if n == 0:
exit(0)
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(min(s + 1, 101)):
si1 = s - i + 1
for k in range(n, 0, -1):
dp_k = dp[k]
dp_k1 = dp[k - 1]
for j in range(si1):
dp_k[i + j] += dp_k1[j]
print(dp[n][s])
| dp = [[0] * (1001) for _ in range(10)]
dp[0][0] = 1
for i in range(101):
si1 = 1001 - i
for k in range(9, 0, -1):
dp_k = dp[k]
dp_k1 = dp[k - 1]
for j in range(si1):
dp_k[i + j] += dp_k1[j]
while 1:
n, s = list(map(int, input().split()))
if n == 0:
exit(0)
print(dp[n][s])
| false | 0 | [
"+dp = [[0] * (1001) for _ in range(10)]",
"+dp[0][0] = 1",
"+for i in range(101):",
"+ si1 = 1001 - i",
"+ for k in range(9, 0, -1):",
"+ dp_k = dp[k]",
"+ dp_k1 = dp[k - 1]",
"+ for j in range(si1):",
"+ dp_k[i + j] += dp_k1[j]",
"- dp = [[0] * (s + 1) for _ in range(n + 1)]",
"- dp[0][0] = 1",
"- for i in range(min(s + 1, 101)):",
"- si1 = s - i + 1",
"- for k in range(n, 0, -1):",
"- dp_k = dp[k]",
"- dp_k1 = dp[k - 1]",
"- for j in range(si1):",
"- dp_k[i + j] += dp_k1[j]"
] | false | 0.090702 | 0.356415 | 0.254484 | [
"s108458329",
"s059878684"
] |
u111365362 | p02900 | python | s444348913 | s954160853 | 434 | 136 | 3,064 | 3,064 | Accepted | Accepted | 68.66 | a,b = list(map(int,input().split()))
while b != 0:
a,b = b,a%b
pr = set()
i = 2
while i ** 2 <= a:
while a % i == 0:
a //= i
pr.add(i)
i += 1
pr.add(a)
pr.add(1)
print((len(pr))) | #16:44
a,b = list(map(int,input().split()))
while b > 0:
a,b = b,a%b
prime = []
for i in range(2,int(a**.5)+1):
if a % i == 0:
p,q = i,0
while a % i == 0:
a //= i
q += 1
prime.append([p,q])
if a != 1:
prime.append([a,1])
print((len(prime)+1)) | 13 | 15 | 196 | 278 | a, b = list(map(int, input().split()))
while b != 0:
a, b = b, a % b
pr = set()
i = 2
while i**2 <= a:
while a % i == 0:
a //= i
pr.add(i)
i += 1
pr.add(a)
pr.add(1)
print((len(pr)))
| # 16:44
a, b = list(map(int, input().split()))
while b > 0:
a, b = b, a % b
prime = []
for i in range(2, int(a**0.5) + 1):
if a % i == 0:
p, q = i, 0
while a % i == 0:
a //= i
q += 1
prime.append([p, q])
if a != 1:
prime.append([a, 1])
print((len(prime) + 1))
| false | 13.333333 | [
"+# 16:44",
"-while b != 0:",
"+while b > 0:",
"-pr = set()",
"-i = 2",
"-while i**2 <= a:",
"- while a % i == 0:",
"- a //= i",
"- pr.add(i)",
"- i += 1",
"-pr.add(a)",
"-pr.add(1)",
"-print((len(pr)))",
"+prime = []",
"+for i in range(2, int(a**0.5) + 1):",
"+ if a % i == 0:",
"+ p, q = i, 0",
"+ while a % i == 0:",
"+ a //= i",
"+ q += 1",
"+ prime.append([p, q])",
"+if a != 1:",
"+ prime.append([a, 1])",
"+print((len(prime) + 1))"
] | false | 0.0408 | 0.040096 | 1.017554 | [
"s444348913",
"s954160853"
] |
u047796752 | p02820 | python | s588182472 | s861829933 | 200 | 177 | 49,264 | 90,164 | Accepted | Accepted | 11.5 | import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(N):
if i<K:
ans += score[T[i]]
else:
if T[i]!=T[i-K]:
ans += score[T[i]]
else:
T[i] = '?'
print(ans) | import sys
input = sys.stdin.readline
from collections import *
def calc(l):
dp = [[0]*3 for _ in range(len(l)+1)]
for i in range(len(l)):
dp[i+1][0] = max(dp[i][1], dp[i][2])+(R if l[i]=='s' else 0)
dp[i+1][1] = max(dp[i][2], dp[i][0])+(S if l[i]=='p' else 0)
dp[i+1][2] = max(dp[i][0], dp[i][1])+(P if l[i]=='r' else 0)
return max(dp[-1])
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()[:-1]
d = defaultdict(list)
for i in range(N):
d[i%K].append(T[i])
ans = 0
for i in range(K):
ans += calc(d[i])
print(ans) | 19 | 28 | 370 | 630 | import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {"r": P, "s": R, "p": S}
ans = 0
for i in range(N):
if i < K:
ans += score[T[i]]
else:
if T[i] != T[i - K]:
ans += score[T[i]]
else:
T[i] = "?"
print(ans)
| import sys
input = sys.stdin.readline
from collections import *
def calc(l):
dp = [[0] * 3 for _ in range(len(l) + 1)]
for i in range(len(l)):
dp[i + 1][0] = max(dp[i][1], dp[i][2]) + (R if l[i] == "s" else 0)
dp[i + 1][1] = max(dp[i][2], dp[i][0]) + (S if l[i] == "p" else 0)
dp[i + 1][2] = max(dp[i][0], dp[i][1]) + (P if l[i] == "r" else 0)
return max(dp[-1])
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()[:-1]
d = defaultdict(list)
for i in range(N):
d[i % K].append(T[i])
ans = 0
for i in range(K):
ans += calc(d[i])
print(ans)
| false | 32.142857 | [
"+from collections import *",
"+",
"+",
"+def calc(l):",
"+ dp = [[0] * 3 for _ in range(len(l) + 1)]",
"+ for i in range(len(l)):",
"+ dp[i + 1][0] = max(dp[i][1], dp[i][2]) + (R if l[i] == \"s\" else 0)",
"+ dp[i + 1][1] = max(dp[i][2], dp[i][0]) + (S if l[i] == \"p\" else 0)",
"+ dp[i + 1][2] = max(dp[i][0], dp[i][1]) + (P if l[i] == \"r\" else 0)",
"+ return max(dp[-1])",
"+",
"+",
"-T = list(eval(input()))",
"-score = {\"r\": P, \"s\": R, \"p\": S}",
"+T = input()[:-1]",
"+d = defaultdict(list)",
"+for i in range(N):",
"+ d[i % K].append(T[i])",
"-for i in range(N):",
"- if i < K:",
"- ans += score[T[i]]",
"- else:",
"- if T[i] != T[i - K]:",
"- ans += score[T[i]]",
"- else:",
"- T[i] = \"?\"",
"+for i in range(K):",
"+ ans += calc(d[i])"
] | false | 0.092844 | 0.046291 | 2.005666 | [
"s588182472",
"s861829933"
] |
u125545880 | p03559 | python | s326360222 | s288350843 | 1,554 | 352 | 22,720 | 22,720 | Accepted | Accepted | 77.35 | import sys
import bisect
readline = sys.stdin.readline
bileft = bisect.bisect_left
biright = bisect.bisect_right
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort(); C.sort()
minA = min(A); maxA = max(A)
minC = min(C); maxC = max(C)
ans = 0
for b in B:
L = minA; R = maxA + 1
mid = (L + R) // 2
if b >= R:
L = R
else:
while L + 1 < R:
if mid <= b:
L = mid
else:
R = mid
mid = (L + R) // 2
#print('L:{}, b:{}, R:{}'.format(L, b, R))
a = bileft(A, L)
#print(a, A)
L = minC; R = maxC + 1
mid = (L + R) // 2
if b <= L-1:
L = L-1
else:
while L + 1 < R:
if mid <= b:
L = mid
else:
R = mid
mid = (L + R) // 2
#print('L:{}, b:{}, R:{}'.format(L, b, R))
c = len(C) - biright(C, L)
#print(c, C)
#print('------')
ans += a*c
print(ans)
if __name__ == "__main__":
main()
| import sys
import bisect
readline = sys.stdin.readline
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort()
C.sort()
ans = 0
for b in B:
tmpa = bisect.bisect_left(A, b)
tmpc = N - bisect.bisect_right(C, b)
ans += tmpa*tmpc
print(ans)
if __name__ == "__main__":
main()
| 54 | 24 | 1,322 | 466 | import sys
import bisect
readline = sys.stdin.readline
bileft = bisect.bisect_left
biright = bisect.bisect_right
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort()
C.sort()
minA = min(A)
maxA = max(A)
minC = min(C)
maxC = max(C)
ans = 0
for b in B:
L = minA
R = maxA + 1
mid = (L + R) // 2
if b >= R:
L = R
else:
while L + 1 < R:
if mid <= b:
L = mid
else:
R = mid
mid = (L + R) // 2
# print('L:{}, b:{}, R:{}'.format(L, b, R))
a = bileft(A, L)
# print(a, A)
L = minC
R = maxC + 1
mid = (L + R) // 2
if b <= L - 1:
L = L - 1
else:
while L + 1 < R:
if mid <= b:
L = mid
else:
R = mid
mid = (L + R) // 2
# print('L:{}, b:{}, R:{}'.format(L, b, R))
c = len(C) - biright(C, L)
# print(c, C)
# print('------')
ans += a * c
print(ans)
if __name__ == "__main__":
main()
| import sys
import bisect
readline = sys.stdin.readline
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort()
C.sort()
ans = 0
for b in B:
tmpa = bisect.bisect_left(A, b)
tmpc = N - bisect.bisect_right(C, b)
ans += tmpa * tmpc
print(ans)
if __name__ == "__main__":
main()
| false | 55.555556 | [
"-bileft = bisect.bisect_left",
"-biright = bisect.bisect_right",
"- minA = min(A)",
"- maxA = max(A)",
"- minC = min(C)",
"- maxC = max(C)",
"- L = minA",
"- R = maxA + 1",
"- mid = (L + R) // 2",
"- if b >= R:",
"- L = R",
"- else:",
"- while L + 1 < R:",
"- if mid <= b:",
"- L = mid",
"- else:",
"- R = mid",
"- mid = (L + R) // 2",
"- # print('L:{}, b:{}, R:{}'.format(L, b, R))",
"- a = bileft(A, L)",
"- # print(a, A)",
"- L = minC",
"- R = maxC + 1",
"- mid = (L + R) // 2",
"- if b <= L - 1:",
"- L = L - 1",
"- else:",
"- while L + 1 < R:",
"- if mid <= b:",
"- L = mid",
"- else:",
"- R = mid",
"- mid = (L + R) // 2",
"- # print('L:{}, b:{}, R:{}'.format(L, b, R))",
"- c = len(C) - biright(C, L)",
"- # print(c, C)",
"- ans += a * c",
"+ tmpa = bisect.bisect_left(A, b)",
"+ tmpc = N - bisect.bisect_right(C, b)",
"+ ans += tmpa * tmpc"
] | false | 0.060464 | 0.056451 | 1.071078 | [
"s326360222",
"s288350843"
] |
u759412327 | p02897 | python | s920307736 | s940586473 | 29 | 26 | 8,920 | 9,092 | Accepted | Accepted | 10.34 | N = int(eval(input()))
print(((N-N//2)/N)) | N = int(eval(input()))
print((1-N//2/N)) | 2 | 2 | 35 | 33 | N = int(eval(input()))
print(((N - N // 2) / N))
| N = int(eval(input()))
print((1 - N // 2 / N))
| false | 0 | [
"-print(((N - N // 2) / N))",
"+print((1 - N // 2 / N))"
] | false | 0.040658 | 0.116576 | 0.348771 | [
"s920307736",
"s940586473"
] |
u163703551 | p03816 | python | s950007025 | s978444432 | 67 | 46 | 14,248 | 14,564 | Accepted | Accepted | 31.34 | n = eval(input())
n = int(n)
a = input().split()
a = [int(x) for x in a]
b = set(a)
res = len(b)
if n % 2 != res % 2:
res -= 1
print(res) | import sys
# sys.stdin = open('d1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
n = read_int()
a = read_int_list()
b = set(a)
res = len(b)
if res % 2 != 1:
res -= 1
print(res)
| 10 | 28 | 145 | 364 | n = eval(input())
n = int(n)
a = input().split()
a = [int(x) for x in a]
b = set(a)
res = len(b)
if n % 2 != res % 2:
res -= 1
print(res)
| import sys
# sys.stdin = open('d1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
n = read_int()
a = read_int_list()
b = set(a)
res = len(b)
if res % 2 != 1:
res -= 1
print(res)
| false | 64.285714 | [
"-n = eval(input())",
"-n = int(n)",
"-a = input().split()",
"-a = [int(x) for x in a]",
"+import sys",
"+",
"+# sys.stdin = open('d1.in')",
"+def read_int_list():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def read_str_list():",
"+ return input().split()",
"+",
"+",
"+def read_int():",
"+ return int(eval(input()))",
"+",
"+",
"+def read_str():",
"+ return eval(input())",
"+",
"+",
"+n = read_int()",
"+a = read_int_list()",
"-if n % 2 != res % 2:",
"+if res % 2 != 1:"
] | false | 0.054249 | 0.037294 | 1.454626 | [
"s950007025",
"s978444432"
] |
u185424824 | p03592 | python | s276364736 | s167365329 | 74 | 67 | 64,904 | 61,988 | Accepted | Accepted | 9.46 | N,M,K = list(map(int,input().split()))
ans = "No"
for k in range(N+1):
for l in range(M+1):
if k*(M-l) + l*(N-k) == K:
ans = "Yes"
print(ans) | N,M,K = list(map(int,input().split()))
ans = "No"
for a in range(N+1):
if N - 2*a != 0:
if (K - a*M) % (N - 2*a) == 0:
if M >= (K - a*M) / (N - 2*a) >= 0:
ans = "Yes"
print(ans) | 8 | 9 | 155 | 200 | N, M, K = list(map(int, input().split()))
ans = "No"
for k in range(N + 1):
for l in range(M + 1):
if k * (M - l) + l * (N - k) == K:
ans = "Yes"
print(ans)
| N, M, K = list(map(int, input().split()))
ans = "No"
for a in range(N + 1):
if N - 2 * a != 0:
if (K - a * M) % (N - 2 * a) == 0:
if M >= (K - a * M) / (N - 2 * a) >= 0:
ans = "Yes"
print(ans)
| false | 11.111111 | [
"-for k in range(N + 1):",
"- for l in range(M + 1):",
"- if k * (M - l) + l * (N - k) == K:",
"- ans = \"Yes\"",
"+for a in range(N + 1):",
"+ if N - 2 * a != 0:",
"+ if (K - a * M) % (N - 2 * a) == 0:",
"+ if M >= (K - a * M) / (N - 2 * a) >= 0:",
"+ ans = \"Yes\""
] | false | 0.047327 | 0.049486 | 0.956357 | [
"s276364736",
"s167365329"
] |
u790905630 | p03241 | python | s052128101 | s090512268 | 25 | 20 | 3,316 | 3,060 | Accepted | Accepted | 20 | from math import *
def main():
N, M = list(map(int, input().split()))
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print((int(max([i for i in divisor_set if special_value >= i]))))
return
main() | from math import *
def main():
N, M = list(map(int, input().split()))
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print((int(max(divisor_set, key=lambda x: x if special_value >= x else -1))))
return
main()
| 11 | 12 | 332 | 347 | from math import *
def main():
N, M = list(map(int, input().split()))
special_value = M // N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M // j for j in divisor_set)
print((int(max([i for i in divisor_set if special_value >= i]))))
return
main()
| from math import *
def main():
N, M = list(map(int, input().split()))
special_value = M // N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M // j for j in divisor_set)
print((int(max(divisor_set, key=lambda x: x if special_value >= x else -1))))
return
main()
| false | 8.333333 | [
"- print((int(max([i for i in divisor_set if special_value >= i]))))",
"+ print((int(max(divisor_set, key=lambda x: x if special_value >= x else -1))))"
] | false | 0.046151 | 0.046459 | 0.993363 | [
"s052128101",
"s090512268"
] |
u353919145 | p02724 | python | s353154509 | s739967207 | 167 | 17 | 38,512 | 2,940 | Accepted | Accepted | 89.82 | def resolve():
x=int(eval(input()))
ans=0
while x>=500:
x-=500
ans+=1000
while x>=5:
x-=5
ans+=5
print(ans)
resolve() | n=int(eval(input()))
gg=0
gg+=(n//500)*1000
n=n-(n//500)*500
gg+=(n//5)*5
print(gg)
| 11 | 6 | 173 | 83 | def resolve():
x = int(eval(input()))
ans = 0
while x >= 500:
x -= 500
ans += 1000
while x >= 5:
x -= 5
ans += 5
print(ans)
resolve()
| n = int(eval(input()))
gg = 0
gg += (n // 500) * 1000
n = n - (n // 500) * 500
gg += (n // 5) * 5
print(gg)
| false | 45.454545 | [
"-def resolve():",
"- x = int(eval(input()))",
"- ans = 0",
"- while x >= 500:",
"- x -= 500",
"- ans += 1000",
"- while x >= 5:",
"- x -= 5",
"- ans += 5",
"- print(ans)",
"-",
"-",
"-resolve()",
"+n = int(eval(input()))",
"+gg = 0",
"+gg += (n // 500) * 1000",
"+n = n - (n // 500) * 500",
"+gg += (n // 5) * 5",
"+print(gg)"
] | false | 0.219124 | 0.03597 | 6.091903 | [
"s353154509",
"s739967207"
] |
u312025627 | p03625 | python | s694310199 | s818457734 | 333 | 98 | 68,760 | 18,216 | Accepted | Accepted | 70.57 | def main():
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in c.items() if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
return print(li[0][0] * li[0][0])
elif len(li) <= 1:
return print(0)
else:
return print(li[0][0] * li[1][0])
if __name__ == '__main__':
main()
| def main():
_ = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in list(c.items()) if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
print((li[0][0] * li[0][0]))
elif len(li) <= 1:
print((0))
else:
print((li[0][0] * li[1][0]))
if __name__ == '__main__':
main()
| 17 | 17 | 432 | 411 | def main():
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in c.items() if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
return print(li[0][0] * li[0][0])
elif len(li) <= 1:
return print(0)
else:
return print(li[0][0] * li[1][0])
if __name__ == "__main__":
main()
| def main():
_ = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in list(c.items()) if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
print((li[0][0] * li[0][0]))
elif len(li) <= 1:
print((0))
else:
print((li[0][0] * li[1][0]))
if __name__ == "__main__":
main()
| false | 0 | [
"- N = int(input())",
"+ _ = int(eval(input()))",
"- li = [(k, v) for k, v in c.items() if v >= 2]",
"+ li = [(k, v) for k, v in list(c.items()) if v >= 2]",
"- return print(li[0][0] * li[0][0])",
"+ print((li[0][0] * li[0][0]))",
"- return print(0)",
"+ print((0))",
"- return print(li[0][0] * li[1][0])",
"+ print((li[0][0] * li[1][0]))"
] | false | 0.039596 | 0.040466 | 0.978493 | [
"s694310199",
"s818457734"
] |
u809819902 | p02993 | python | s410109565 | s754786251 | 35 | 28 | 9,040 | 9,088 | Accepted | Accepted | 20 | s = eval(input())
res = "Good"
for i in range(3):
if s[i]==s[i+1]:
res = "Bad"
print(res) | s=eval(input())
ans="Good"
for i in range(3):
if s[i]==s[i+1]:
ans="Bad"
print(ans) | 6 | 6 | 100 | 94 | s = eval(input())
res = "Good"
for i in range(3):
if s[i] == s[i + 1]:
res = "Bad"
print(res)
| s = eval(input())
ans = "Good"
for i in range(3):
if s[i] == s[i + 1]:
ans = "Bad"
print(ans)
| false | 0 | [
"-res = \"Good\"",
"+ans = \"Good\"",
"- res = \"Bad\"",
"-print(res)",
"+ ans = \"Bad\"",
"+print(ans)"
] | false | 0.035206 | 0.07719 | 0.456088 | [
"s410109565",
"s754786251"
] |
u294922877 | p02394 | python | s820723639 | s128883124 | 30 | 20 | 5,600 | 5,596 | Accepted | Accepted | 33.33 | def judge(w, h, x, y, r):
within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h)
return 'Yes' if within_range else 'No'
if __name__ == '__main__':
w, h, x, y, r = list(map(int, input().split(' ')))
print((judge(w, h, x, y, r)))
| w,h,x,y,r=list(map(int, input().split()))
if 0 <= x-r and x+r <= w and 0 <= y-r and y+r <= h:
print("Yes")
else:
print("No")
| 8 | 5 | 265 | 131 | def judge(w, h, x, y, r):
within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h)
return "Yes" if within_range else "No"
if __name__ == "__main__":
w, h, x, y, r = list(map(int, input().split(" ")))
print((judge(w, h, x, y, r)))
| w, h, x, y, r = list(map(int, input().split()))
if 0 <= x - r and x + r <= w and 0 <= y - r and y + r <= h:
print("Yes")
else:
print("No")
| false | 37.5 | [
"-def judge(w, h, x, y, r):",
"- within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h)",
"- return \"Yes\" if within_range else \"No\"",
"-",
"-",
"-if __name__ == \"__main__\":",
"- w, h, x, y, r = list(map(int, input().split(\" \")))",
"- print((judge(w, h, x, y, r)))",
"+w, h, x, y, r = list(map(int, input().split()))",
"+if 0 <= x - r and x + r <= w and 0 <= y - r and y + r <= h:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.077512 | 0.112398 | 0.689624 | [
"s820723639",
"s128883124"
] |
u675844759 | p02396 | python | s759823705 | s466411945 | 140 | 50 | 7,620 | 7,436 | Accepted | Accepted | 64.29 | cnt = 0
num = int(eval(input()))
while num != 0:
cnt+=1
print(('Case {0}: {1}'.format(cnt, num)))
num = int(eval(input())) | import sys
cnt = 1
num = sys.stdin.readline().strip()
while num != "0":
print(("Case "+ str(cnt) + ": " + num))
cnt+=1
num = sys.stdin.readline().strip() | 6 | 7 | 119 | 170 | cnt = 0
num = int(eval(input()))
while num != 0:
cnt += 1
print(("Case {0}: {1}".format(cnt, num)))
num = int(eval(input()))
| import sys
cnt = 1
num = sys.stdin.readline().strip()
while num != "0":
print(("Case " + str(cnt) + ": " + num))
cnt += 1
num = sys.stdin.readline().strip()
| false | 14.285714 | [
"-cnt = 0",
"-num = int(eval(input()))",
"-while num != 0:",
"+import sys",
"+",
"+cnt = 1",
"+num = sys.stdin.readline().strip()",
"+while num != \"0\":",
"+ print((\"Case \" + str(cnt) + \": \" + num))",
"- print((\"Case {0}: {1}\".format(cnt, num)))",
"- num = int(eval(input()))",
"+ num = sys.stdin.readline().strip()"
] | false | 0.064525 | 0.035437 | 1.820833 | [
"s759823705",
"s466411945"
] |
u467736898 | p02710 | python | s402951359 | s239073893 | 887 | 816 | 155,500 | 167,280 | Accepted | Accepted | 8 | def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def dfs1(v, G, Siz):
siz = 1
for u in G[v]:
G[u].remove(v)
siz += dfs1(u, G, Siz)
Siz[v] = siz
return siz
def dfs(v, N, C, G, Cnt, Siz, Ans):
color = C[v]
cnt_old = Cnt[color]
siz = 1
siz_up = N
for u in G[v]:
Cnt[color] = N - Siz[u] # 上を塞ぐ
s = dfs(u, N, C, G, Cnt, Siz, Ans)
siz += s
siz_up -= s
Ans[color] += s * (siz_up - cnt_old)
Ans[color] += siz_up - cnt_old
Cnt[color] = cnt_old + siz
return siz
def solve(N, C, AB):
G = [[0]*0 for _ in range(N)]
for i in range(N-1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
Cnt = np.zeros(N, dtype=np.int64)
Ans = np.zeros(N, dtype=np.int64)
Siz = np.zeros(N, dtype=np.int64)
dfs1(0, G, Siz)
dfs(0, N, C, G, Cnt, Siz, Ans)
return Ans
numba_compile([
[dfs1, "i8(i8,List(List(i8)),i8[:])"],
[dfs, "i8(i8,i8,i8[:],List(List(i8)),i8[:],i8[:],i8[:])"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
])
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(input().split(), dtype=np.int64) - 1
AB = np.array([list(map(int, input().split())) for _ in range(N-1)], dtype=np.int64) - 1
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))
| # オイラーツアーのテスト
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
first = np.full(n, -100, dtype=np.int64)
last = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if first[v] >= 0:
last[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
first[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, first, last
def dfs1(v, G, Siz):
tour, first, last = eular_tour(G, 0)
Siz[:] = last - first + 1 >> 1
return 0
# def dfs1(v, G, Siz):
# siz = 1
# for u in G[v]:
# G[u].remove(v)
# siz += dfs1(u, G, Siz)
# Siz[v] = siz
# return siz
def dfs(v, N, C, G, Cnt, Siz, Ans):
color = C[v]
cnt_old = Cnt[color]
siz = 1
siz_up = N
for u in G[v]:
Cnt[color] = N - Siz[u] # 上を塞ぐ
s = dfs(u, N, C, G, Cnt, Siz, Ans)
siz += s
siz_up -= s
Ans[color] += s * (siz_up - cnt_old)
Ans[color] += siz_up - cnt_old
Cnt[color] = cnt_old + siz
return siz
def solve(N, C, AB):
G = [[0]*0 for _ in range(N)]
for i in range(N-1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
Cnt = np.zeros(N, dtype=np.int64)
Ans = np.zeros(N, dtype=np.int64)
Siz = np.zeros(N, dtype=np.int64)
dfs1(0, G, Siz)
dfs(0, N, C, G, Cnt, Siz, Ans)
return Ans
numba_compile([
[eular_tour, "Tuple((i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[dfs1, "i8(i8,List(List(i8)),i8[:])"],
[dfs, "i8(i8,i8,i8[:],List(List(i8)),i8[:],i8[:],i8[:])"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
])
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(input().split(), dtype=np.int64) - 1
AB = np.array([list(map(int, input().split())) for _ in range(N-1)], dtype=np.int64) - 1
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))
| 73 | 104 | 2,190 | 3,047 | def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(
f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
)
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def dfs1(v, G, Siz):
siz = 1
for u in G[v]:
G[u].remove(v)
siz += dfs1(u, G, Siz)
Siz[v] = siz
return siz
def dfs(v, N, C, G, Cnt, Siz, Ans):
color = C[v]
cnt_old = Cnt[color]
siz = 1
siz_up = N
for u in G[v]:
Cnt[color] = N - Siz[u] # 上を塞ぐ
s = dfs(u, N, C, G, Cnt, Siz, Ans)
siz += s
siz_up -= s
Ans[color] += s * (siz_up - cnt_old)
Ans[color] += siz_up - cnt_old
Cnt[color] = cnt_old + siz
return siz
def solve(N, C, AB):
G = [[0] * 0 for _ in range(N)]
for i in range(N - 1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
Cnt = np.zeros(N, dtype=np.int64)
Ans = np.zeros(N, dtype=np.int64)
Siz = np.zeros(N, dtype=np.int64)
dfs1(0, G, Siz)
dfs(0, N, C, G, Cnt, Siz, Ans)
return Ans
numba_compile(
[
[dfs1, "i8(i8,List(List(i8)),i8[:])"],
[dfs, "i8(i8,i8,i8[:],List(List(i8)),i8[:],i8[:],i8[:])"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
]
)
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(input().split(), dtype=np.int64) - 1
AB = (
np.array([list(map(int, input().split())) for _ in range(N - 1)], dtype=np.int64)
- 1
)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))
| # オイラーツアーのテスト
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(
f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
)
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
first = np.full(n, -100, dtype=np.int64)
last = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if first[v] >= 0:
last[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
first[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, first, last
def dfs1(v, G, Siz):
tour, first, last = eular_tour(G, 0)
Siz[:] = last - first + 1 >> 1
return 0
# def dfs1(v, G, Siz):
# siz = 1
# for u in G[v]:
# G[u].remove(v)
# siz += dfs1(u, G, Siz)
# Siz[v] = siz
# return siz
def dfs(v, N, C, G, Cnt, Siz, Ans):
color = C[v]
cnt_old = Cnt[color]
siz = 1
siz_up = N
for u in G[v]:
Cnt[color] = N - Siz[u] # 上を塞ぐ
s = dfs(u, N, C, G, Cnt, Siz, Ans)
siz += s
siz_up -= s
Ans[color] += s * (siz_up - cnt_old)
Ans[color] += siz_up - cnt_old
Cnt[color] = cnt_old + siz
return siz
def solve(N, C, AB):
G = [[0] * 0 for _ in range(N)]
for i in range(N - 1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
Cnt = np.zeros(N, dtype=np.int64)
Ans = np.zeros(N, dtype=np.int64)
Siz = np.zeros(N, dtype=np.int64)
dfs1(0, G, Siz)
dfs(0, N, C, G, Cnt, Siz, Ans)
return Ans
numba_compile(
[
[eular_tour, "Tuple((i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[dfs1, "i8(i8,List(List(i8)),i8[:])"],
[dfs, "i8(i8,i8,i8[:],List(List(i8)),i8[:],i8[:],i8[:])"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
]
)
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(input().split(), dtype=np.int64) - 1
AB = (
np.array([list(map(int, input().split())) for _ in range(N - 1)], dtype=np.int64)
- 1
)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))
| false | 29.807692 | [
"+# オイラーツアーのテスト",
"-def dfs1(v, G, Siz):",
"- siz = 1",
"- for u in G[v]:",
"- G[u].remove(v)",
"- siz += dfs1(u, G, Siz)",
"- Siz[v] = siz",
"- return siz",
"+def eular_tour(G, root):",
"+ # G は破壊的に有向木にされる",
"+ # グラフは 1-indexed が良い",
"+ n = len(G)",
"+ stack = [root]",
"+ tour = [0] * 0",
"+ first = np.full(n, -100, dtype=np.int64)",
"+ last = np.full(n, -100, dtype=np.int64)",
"+ while stack:",
"+ v = stack.pop()",
"+ if first[v] >= 0:",
"+ last[v] = len(tour)",
"+ tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える",
"+ continue",
"+ first[v] = len(tour)",
"+ tour.append(v)",
"+ stack.append(v)",
"+ for u in G[v]:",
"+ G[u].remove(v)",
"+ stack.append(u)",
"+ tour = np.array(tour, dtype=np.int64)",
"+ return tour, first, last",
"+def dfs1(v, G, Siz):",
"+ tour, first, last = eular_tour(G, 0)",
"+ Siz[:] = last - first + 1 >> 1",
"+ return 0",
"+",
"+",
"+# def dfs1(v, G, Siz):",
"+# siz = 1",
"+# for u in G[v]:",
"+# G[u].remove(v)",
"+# siz += dfs1(u, G, Siz)",
"+# Siz[v] = siz",
"+# return siz",
"+ [eular_tour, \"Tuple((i8[:],i8[:],i8[:]))(List(List(i8)),i8)\"],"
] | false | 0.531069 | 0.366963 | 1.447199 | [
"s402951359",
"s239073893"
] |
u075012704 | p02702 | python | s068922756 | s074730092 | 365 | 325 | 9,756 | 20,224 | Accepted | Accepted | 10.96 | from collections import Counter
S = eval(input())
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
s = int(s)
n += pow(10, i, MOD) * s % MOD
C[n % MOD] += 1
C[0] += 1
ans = 0
for v in list(C.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
S = list(map(int, list(eval(input()))))
A = [0]
for i, s in enumerate(S[::-1]):
A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))
| 16 | 6 | 272 | 223 | from collections import Counter
S = eval(input())
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
s = int(s)
n += pow(10, i, MOD) * s % MOD
C[n % MOD] += 1
C[0] += 1
ans = 0
for v in list(C.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
S = list(map(int, list(eval(input()))))
A = [0]
for i, s in enumerate(S[::-1]):
A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))
| false | 62.5 | [
"-S = eval(input())",
"-C = Counter()",
"-MOD = 2019",
"-n = 0",
"+S = list(map(int, list(eval(input()))))",
"+A = [0]",
"- s = int(s)",
"- n += pow(10, i, MOD) * s % MOD",
"- C[n % MOD] += 1",
"-C[0] += 1",
"-ans = 0",
"-for v in list(C.values()):",
"- ans += v * (v - 1) // 2",
"-print(ans)",
"+ A.append((A[-1] + s * pow(10, i, 2019)) % 2019)",
"+print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))"
] | false | 0.034076 | 0.043935 | 0.775599 | [
"s068922756",
"s074730092"
] |
u652057333 | p02756 | python | s849514100 | s803498063 | 996 | 435 | 73,832 | 8,676 | Accepted | Accepted | 56.33 | from collections import deque
s = str(input().rstrip())
ans = deque(list(s))
f = True
q = int(eval(input()))
for i in range(q):
q = list(map(str, input().split()))
if int(q[0]) == 1:
if f:
f = False
else:
f = True
else:
f_i = int(q[1])
if f_i == 1:
if f:
ans.appendleft(q[2])
else:
ans.append(q[2])
else:
if f:
ans.append(q[2])
else:
ans.appendleft(q[2])
ans = list(ans)
if f:
print(("".join(ans)))
else:
print(("".join(ans[::-1])))
| from collections import deque
import sys
input = sys.stdin.readline
s = str(input().rstrip())
ans = deque(list(s))
f = True
q = int(eval(input()))
for i in range(q):
q = list(map(str, input().split()))
if int(q[0]) == 1:
f = not f
else:
f_i = int(q[1])
if (f_i == 1) ^ f:
ans.append(q[2])
else:
ans.appendleft(q[2])
ans = "".join(list(ans))
if not f:
ans = ans[::-1]
print(ans)
| 32 | 22 | 653 | 466 | from collections import deque
s = str(input().rstrip())
ans = deque(list(s))
f = True
q = int(eval(input()))
for i in range(q):
q = list(map(str, input().split()))
if int(q[0]) == 1:
if f:
f = False
else:
f = True
else:
f_i = int(q[1])
if f_i == 1:
if f:
ans.appendleft(q[2])
else:
ans.append(q[2])
else:
if f:
ans.append(q[2])
else:
ans.appendleft(q[2])
ans = list(ans)
if f:
print(("".join(ans)))
else:
print(("".join(ans[::-1])))
| from collections import deque
import sys
input = sys.stdin.readline
s = str(input().rstrip())
ans = deque(list(s))
f = True
q = int(eval(input()))
for i in range(q):
q = list(map(str, input().split()))
if int(q[0]) == 1:
f = not f
else:
f_i = int(q[1])
if (f_i == 1) ^ f:
ans.append(q[2])
else:
ans.appendleft(q[2])
ans = "".join(list(ans))
if not f:
ans = ans[::-1]
print(ans)
| false | 31.25 | [
"+import sys",
"+input = sys.stdin.readline",
"- if f:",
"- f = False",
"- else:",
"- f = True",
"+ f = not f",
"- if f_i == 1:",
"- if f:",
"- ans.appendleft(q[2])",
"- else:",
"- ans.append(q[2])",
"+ if (f_i == 1) ^ f:",
"+ ans.append(q[2])",
"- if f:",
"- ans.append(q[2])",
"- else:",
"- ans.appendleft(q[2])",
"-ans = list(ans)",
"-if f:",
"- print((\"\".join(ans)))",
"-else:",
"- print((\"\".join(ans[::-1])))",
"+ ans.appendleft(q[2])",
"+ans = \"\".join(list(ans))",
"+if not f:",
"+ ans = ans[::-1]",
"+print(ans)"
] | false | 0.051486 | 0.070792 | 0.727295 | [
"s849514100",
"s803498063"
] |
u936985471 | p02850 | python | s500950914 | s640048034 | 651 | 465 | 46,760 | 48,980 | Accepted | Accepted | 28.57 | # ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく
# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す
# グラフ構築の際に、辺の番号を持っておく
import sys
readline = sys.stdin.readline
N = int(readline())
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,i])
G[b-1].append([a-1,i])
ans = [0 for i in range(N - 1)]
from collections import deque
# 頂点、親から来た色、親
q = deque([[0, 0, -1]])
while q:
v,pcol,parent = q.popleft()
cnt = 1
for child in G[v]:
if child[0] == parent:
continue
if cnt == pcol:
cnt += 1
ans[child[1]] = cnt
q.append([child[0],cnt,v])
cnt += 1
print((max(ans)))
for a in ans:
print(a) | import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
from collections import defaultdict
E = defaultdict(int)
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)
E[(a - 1, b - 1)] = i
from collections import deque
q = deque([])
ans = [None] * (N - 1)
q.append([0, -1, 0])
maxcol = 0
while q:
v, parent, color = q.popleft()
if color > maxcol:
maxcol = color
if (v, parent) in E:
ans[E[(v, parent)]] = color
elif (parent, v) in E:
ans[E[(parent, v)]] = color
next_col = 0
for child in G[v]:
if child == parent:
continue
next_col += 1
if next_col == color:
next_col += 1
q.append([child, v, next_col])
print(maxcol)
for a in ans:
print(a) | 33 | 41 | 691 | 833 | # ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく
# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す
# グラフ構築の際に、辺の番号を持っておく
import sys
readline = sys.stdin.readline
N = int(readline())
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, i])
G[b - 1].append([a - 1, i])
ans = [0 for i in range(N - 1)]
from collections import deque
# 頂点、親から来た色、親
q = deque([[0, 0, -1]])
while q:
v, pcol, parent = q.popleft()
cnt = 1
for child in G[v]:
if child[0] == parent:
continue
if cnt == pcol:
cnt += 1
ans[child[1]] = cnt
q.append([child[0], cnt, v])
cnt += 1
print((max(ans)))
for a in ans:
print(a)
| import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
from collections import defaultdict
E = defaultdict(int)
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)
E[(a - 1, b - 1)] = i
from collections import deque
q = deque([])
ans = [None] * (N - 1)
q.append([0, -1, 0])
maxcol = 0
while q:
v, parent, color = q.popleft()
if color > maxcol:
maxcol = color
if (v, parent) in E:
ans[E[(v, parent)]] = color
elif (parent, v) in E:
ans[E[(parent, v)]] = color
next_col = 0
for child in G[v]:
if child == parent:
continue
next_col += 1
if next_col == color:
next_col += 1
q.append([child, v, next_col])
print(maxcol)
for a in ans:
print(a)
| false | 19.512195 | [
"-# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく",
"-# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す",
"-# グラフ構築の際に、辺の番号を持っておく",
"+from collections import defaultdict",
"+",
"+E = defaultdict(int)",
"- G[a - 1].append([b - 1, i])",
"- G[b - 1].append([a - 1, i])",
"-ans = [0 for i in range(N - 1)]",
"+ G[a - 1].append(b - 1)",
"+ G[b - 1].append(a - 1)",
"+ E[(a - 1, b - 1)] = i",
"-# 頂点、親から来た色、親",
"-q = deque([[0, 0, -1]])",
"+q = deque([])",
"+ans = [None] * (N - 1)",
"+q.append([0, -1, 0])",
"+maxcol = 0",
"- v, pcol, parent = q.popleft()",
"- cnt = 1",
"+ v, parent, color = q.popleft()",
"+ if color > maxcol:",
"+ maxcol = color",
"+ if (v, parent) in E:",
"+ ans[E[(v, parent)]] = color",
"+ elif (parent, v) in E:",
"+ ans[E[(parent, v)]] = color",
"+ next_col = 0",
"- if child[0] == parent:",
"+ if child == parent:",
"- if cnt == pcol:",
"- cnt += 1",
"- ans[child[1]] = cnt",
"- q.append([child[0], cnt, v])",
"- cnt += 1",
"-print((max(ans)))",
"+ next_col += 1",
"+ if next_col == color:",
"+ next_col += 1",
"+ q.append([child, v, next_col])",
"+print(maxcol)"
] | false | 0.043166 | 0.08829 | 0.488917 | [
"s500950914",
"s640048034"
] |
u844789719 | p03785 | python | s449995727 | s178371621 | 1,734 | 260 | 8,280 | 8,280 | Accepted | Accepted | 85.01 | N, C, K = [int(_) for _ in input().split()]
times = sorted([int(eval(input())) for _ in range(N)])
count = 0
while times:
t = times.pop(0)
count += 1
num = 1
while times:
if times[0] <= t + K and num < C:
times.pop(0)
num += 1
else:
break
print(count)
| N, C, K = [int(_) for _ in input().split()]
times = sorted([int(eval(input())) for _ in range(N)], reverse=True)
count = 0
while times:
t = times.pop()
count += 1
num = 1
while times:
if times[-1] <= t + K and num < C:
times.pop()
num += 1
else:
break
print(count)
| 14 | 14 | 327 | 340 | N, C, K = [int(_) for _ in input().split()]
times = sorted([int(eval(input())) for _ in range(N)])
count = 0
while times:
t = times.pop(0)
count += 1
num = 1
while times:
if times[0] <= t + K and num < C:
times.pop(0)
num += 1
else:
break
print(count)
| N, C, K = [int(_) for _ in input().split()]
times = sorted([int(eval(input())) for _ in range(N)], reverse=True)
count = 0
while times:
t = times.pop()
count += 1
num = 1
while times:
if times[-1] <= t + K and num < C:
times.pop()
num += 1
else:
break
print(count)
| false | 0 | [
"-times = sorted([int(eval(input())) for _ in range(N)])",
"+times = sorted([int(eval(input())) for _ in range(N)], reverse=True)",
"- t = times.pop(0)",
"+ t = times.pop()",
"- if times[0] <= t + K and num < C:",
"- times.pop(0)",
"+ if times[-1] <= t + K and num < C:",
"+ times.pop()"
] | false | 0.086508 | 0.061382 | 1.409327 | [
"s449995727",
"s178371621"
] |
u219015402 | p03112 | python | s448725060 | s227519515 | 1,179 | 1,040 | 17,808 | 16,144 | Accepted | Accepted | 11.79 | import bisect
A, B, Q = list(map(int,input().split()))
INF = 10**18
s_list = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t_list = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
x_list = [int(eval(input())) for i in range(Q)]
for x in x_list:
b, d = bisect.bisect_right(s_list, x), bisect.bisect_right(t_list, x)
a = b - 1
c = d - 1
ans = INF
for s in [s_list[a], s_list[b]]:
for t in [t_list[c], t_list[d]]:
dist1 = abs(s-x) + abs(t-s)
dist2 = abs(t-x) + abs(t-s)
ans = min(ans, dist1,dist2)
print(ans)
| import bisect
A, B, Q = list(map(int,input().split()))
INF = 10**18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
x_list = [int(eval(input())) for i in range(Q)]
for x in x_list:
b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
a = b - 1
c = d - 1
ans = min(abs(s[a]-x) + min(abs(t[c]-s[a]), abs(t[d]-s[a])),
abs(s[b]-x) + min(abs(t[c]-s[b]), abs(t[d]-s[b])),
abs(t[c]-x) + min(abs(s[a]-t[c]), abs(s[b]-t[c])),
abs(t[d]-x) + min(abs(s[a]-t[d]), abs(s[b]-t[d])))
# for s in [s_list[a], s_list[b]]:
# for t in [t_list[c], t_list[d]]:
# dist1 = abs(s-x) + abs(t-s)
# dist2 = abs(t-x) + abs(t-s)
# ans = min(ans, dist1,dist2)
print(ans)
| 20 | 24 | 596 | 837 | import bisect
A, B, Q = list(map(int, input().split()))
INF = 10**18
s_list = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t_list = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
x_list = [int(eval(input())) for i in range(Q)]
for x in x_list:
b, d = bisect.bisect_right(s_list, x), bisect.bisect_right(t_list, x)
a = b - 1
c = d - 1
ans = INF
for s in [s_list[a], s_list[b]]:
for t in [t_list[c], t_list[d]]:
dist1 = abs(s - x) + abs(t - s)
dist2 = abs(t - x) + abs(t - s)
ans = min(ans, dist1, dist2)
print(ans)
| import bisect
A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
x_list = [int(eval(input())) for i in range(Q)]
for x in x_list:
b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
a = b - 1
c = d - 1
ans = min(
abs(s[a] - x) + min(abs(t[c] - s[a]), abs(t[d] - s[a])),
abs(s[b] - x) + min(abs(t[c] - s[b]), abs(t[d] - s[b])),
abs(t[c] - x) + min(abs(s[a] - t[c]), abs(s[b] - t[c])),
abs(t[d] - x) + min(abs(s[a] - t[d]), abs(s[b] - t[d])),
)
# for s in [s_list[a], s_list[b]]:
# for t in [t_list[c], t_list[d]]:
# dist1 = abs(s-x) + abs(t-s)
# dist2 = abs(t-x) + abs(t-s)
# ans = min(ans, dist1,dist2)
print(ans)
| false | 16.666667 | [
"-s_list = [-INF] + [int(eval(input())) for i in range(A)] + [INF]",
"-t_list = [-INF] + [int(eval(input())) for i in range(B)] + [INF]",
"+s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]",
"+t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]",
"- b, d = bisect.bisect_right(s_list, x), bisect.bisect_right(t_list, x)",
"+ b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)",
"- ans = INF",
"- for s in [s_list[a], s_list[b]]:",
"- for t in [t_list[c], t_list[d]]:",
"- dist1 = abs(s - x) + abs(t - s)",
"- dist2 = abs(t - x) + abs(t - s)",
"- ans = min(ans, dist1, dist2)",
"+ ans = min(",
"+ abs(s[a] - x) + min(abs(t[c] - s[a]), abs(t[d] - s[a])),",
"+ abs(s[b] - x) + min(abs(t[c] - s[b]), abs(t[d] - s[b])),",
"+ abs(t[c] - x) + min(abs(s[a] - t[c]), abs(s[b] - t[c])),",
"+ abs(t[d] - x) + min(abs(s[a] - t[d]), abs(s[b] - t[d])),",
"+ )",
"+ # for s in [s_list[a], s_list[b]]:",
"+ # for t in [t_list[c], t_list[d]]:",
"+ # dist1 = abs(s-x) + abs(t-s)",
"+ # dist2 = abs(t-x) + abs(t-s)",
"+ # ans = min(ans, dist1,dist2)"
] | false | 0.151146 | 0.203254 | 0.743629 | [
"s448725060",
"s227519515"
] |
u562935282 | p03837 | python | s461259603 | s216743736 | 363 | 215 | 6,256 | 3,444 | Accepted | Accepted | 40.77 | def main():
from itertools import combinations
import sys
input = sys.stdin.readline
inf = 1000 * 100 + 10
N, M = list(map(int, input().split()))
dist = [[[inf, 0] for _ in range(N)] for _ in range(N)]
for j in range(N):
dist[j][j] = [0, 0]
for idx in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
dist[a][b][0] = dist[b][a][0] = c
dist[a][b][1] = dist[b][a][1] = 1 << idx # weight,edge_idx
for k in range(N):
for i in range(N):
for j in range(N):
nd = dist[i][k][0] + dist[k][j][0]
if dist[i][j][0] > nd:
dist[i][j][0] = nd
dist[i][j][1] = dist[i][k][1] | dist[k][j][1]
elif dist[i][j][0] == nd:
dist[i][j][1] |= dist[i][k][1] | dist[k][j][1]
used_edge = 0
for frm, to in combinations(list(range(N)), r=2):
used_edge |= dist[frm][to][1]
print((M - bin(used_edge).count('1')))
if __name__ == '__main__':
main()
| # https://atcoder.jp/contests/abc051/submissions/1055446
def main():
import sys
input = sys.stdin.readline
inf = 1000 * 100 + 10
N, M = list(map(int, input().split()))
dist = [[inf for _ in range(N)] for _ in range(N)]
for j in range(N):
dist[j][j] = 0
es = []
for _ in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
es.append((a, b, c))
dist[a][b] = dist[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
d = dist[i][k] + dist[k][j]
if dist[i][j] > d:
dist[i][j] = d
ans = 0
for a, b, c in es:
if dist[a][b] == c: continue
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 39 | 38 | 1,095 | 836 | def main():
from itertools import combinations
import sys
input = sys.stdin.readline
inf = 1000 * 100 + 10
N, M = list(map(int, input().split()))
dist = [[[inf, 0] for _ in range(N)] for _ in range(N)]
for j in range(N):
dist[j][j] = [0, 0]
for idx in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
dist[a][b][0] = dist[b][a][0] = c
dist[a][b][1] = dist[b][a][1] = 1 << idx # weight,edge_idx
for k in range(N):
for i in range(N):
for j in range(N):
nd = dist[i][k][0] + dist[k][j][0]
if dist[i][j][0] > nd:
dist[i][j][0] = nd
dist[i][j][1] = dist[i][k][1] | dist[k][j][1]
elif dist[i][j][0] == nd:
dist[i][j][1] |= dist[i][k][1] | dist[k][j][1]
used_edge = 0
for frm, to in combinations(list(range(N)), r=2):
used_edge |= dist[frm][to][1]
print((M - bin(used_edge).count("1")))
if __name__ == "__main__":
main()
| # https://atcoder.jp/contests/abc051/submissions/1055446
def main():
import sys
input = sys.stdin.readline
inf = 1000 * 100 + 10
N, M = list(map(int, input().split()))
dist = [[inf for _ in range(N)] for _ in range(N)]
for j in range(N):
dist[j][j] = 0
es = []
for _ in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
es.append((a, b, c))
dist[a][b] = dist[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
d = dist[i][k] + dist[k][j]
if dist[i][j] > d:
dist[i][j] = d
ans = 0
for a, b, c in es:
if dist[a][b] == c:
continue
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 2.564103 | [
"+# https://atcoder.jp/contests/abc051/submissions/1055446",
"- from itertools import combinations",
"- dist = [[[inf, 0] for _ in range(N)] for _ in range(N)]",
"+ dist = [[inf for _ in range(N)] for _ in range(N)]",
"- dist[j][j] = [0, 0]",
"- for idx in range(M):",
"+ dist[j][j] = 0",
"+ es = []",
"+ for _ in range(M):",
"- dist[a][b][0] = dist[b][a][0] = c",
"- dist[a][b][1] = dist[b][a][1] = 1 << idx # weight,edge_idx",
"+ es.append((a, b, c))",
"+ dist[a][b] = dist[b][a] = c",
"- nd = dist[i][k][0] + dist[k][j][0]",
"- if dist[i][j][0] > nd:",
"- dist[i][j][0] = nd",
"- dist[i][j][1] = dist[i][k][1] | dist[k][j][1]",
"- elif dist[i][j][0] == nd:",
"- dist[i][j][1] |= dist[i][k][1] | dist[k][j][1]",
"- used_edge = 0",
"- for frm, to in combinations(list(range(N)), r=2):",
"- used_edge |= dist[frm][to][1]",
"- print((M - bin(used_edge).count(\"1\")))",
"+ d = dist[i][k] + dist[k][j]",
"+ if dist[i][j] > d:",
"+ dist[i][j] = d",
"+ ans = 0",
"+ for a, b, c in es:",
"+ if dist[a][b] == c:",
"+ continue",
"+ ans += 1",
"+ print(ans)"
] | false | 0.036645 | 0.056481 | 0.648812 | [
"s461259603",
"s216743736"
] |
u836939578 | p03042 | python | s386297318 | s057426098 | 74 | 65 | 62,008 | 61,508 | Accepted | Accepted | 12.16 | import sys
input = lambda: sys.stdin.readline().rstrip()
S = eval(input())
f = int(S[:2])
s = int(S[2:])
if (f <= 0 and s > 12) or (f > 12 and s <= 0) or (f <= 0 and s <= 0) or (f > 12 and s > 12):
print("NA")
elif (f > 12 and 0 < s <= 12) or (f <= 0 and 0 < s <= 12):
print("YYMM")
elif (0 < f <= 12 and s > 12) or (0 < f <= 12 and s <= 0):
print("MMYY")
elif 0 < f <= 12 and 0 < s <= 12:
print("AMBIGUOUS") | S = eval(input())
front = int(S[:2])
rear = int(S[2:])
if (front > 12 and rear > 12) or (front > 12 and rear == 0) or (rear > 12 and front == 0) or (front == 0 and rear == 0):
print("NA")
exit()
elif 0 < rear <= 12 and (front > 12 or front == 0):
print("YYMM")
exit()
elif 0 < front <= 12 and (rear > 12 or rear == 0):
print("MMYY")
elif 0 < front <= 12 and 0 < rear <= 12:
print("AMBIGUOUS")
| 16 | 15 | 439 | 427 | import sys
input = lambda: sys.stdin.readline().rstrip()
S = eval(input())
f = int(S[:2])
s = int(S[2:])
if (
(f <= 0 and s > 12)
or (f > 12 and s <= 0)
or (f <= 0 and s <= 0)
or (f > 12 and s > 12)
):
print("NA")
elif (f > 12 and 0 < s <= 12) or (f <= 0 and 0 < s <= 12):
print("YYMM")
elif (0 < f <= 12 and s > 12) or (0 < f <= 12 and s <= 0):
print("MMYY")
elif 0 < f <= 12 and 0 < s <= 12:
print("AMBIGUOUS")
| S = eval(input())
front = int(S[:2])
rear = int(S[2:])
if (
(front > 12 and rear > 12)
or (front > 12 and rear == 0)
or (rear > 12 and front == 0)
or (front == 0 and rear == 0)
):
print("NA")
exit()
elif 0 < rear <= 12 and (front > 12 or front == 0):
print("YYMM")
exit()
elif 0 < front <= 12 and (rear > 12 or rear == 0):
print("MMYY")
elif 0 < front <= 12 and 0 < rear <= 12:
print("AMBIGUOUS")
| false | 6.25 | [
"-import sys",
"-",
"-input = lambda: sys.stdin.readline().rstrip()",
"-f = int(S[:2])",
"-s = int(S[2:])",
"+front = int(S[:2])",
"+rear = int(S[2:])",
"- (f <= 0 and s > 12)",
"- or (f > 12 and s <= 0)",
"- or (f <= 0 and s <= 0)",
"- or (f > 12 and s > 12)",
"+ (front > 12 and rear > 12)",
"+ or (front > 12 and rear == 0)",
"+ or (rear > 12 and front == 0)",
"+ or (front == 0 and rear == 0)",
"-elif (f > 12 and 0 < s <= 12) or (f <= 0 and 0 < s <= 12):",
"+ exit()",
"+elif 0 < rear <= 12 and (front > 12 or front == 0):",
"-elif (0 < f <= 12 and s > 12) or (0 < f <= 12 and s <= 0):",
"+ exit()",
"+elif 0 < front <= 12 and (rear > 12 or rear == 0):",
"-elif 0 < f <= 12 and 0 < s <= 12:",
"+elif 0 < front <= 12 and 0 < rear <= 12:"
] | false | 0.067635 | 0.068485 | 0.987583 | [
"s386297318",
"s057426098"
] |
u759412327 | p04045 | python | s261093003 | s936786148 | 125 | 86 | 2,940 | 2,940 | Accepted | Accepted | 31.2 | N,K = list(map(int,input().split()))
D = list(input().split())
while True:
f = True
for s in str(N):
if s in D:
f = False
if f:
print((str(N)))
break
else:
N+=1 | N,K = list(map(int,input().split()))
D = set(input().split())
while len(set(str(N))&D)>0:
N+=1
print(N) | 13 | 7 | 195 | 107 | N, K = list(map(int, input().split()))
D = list(input().split())
while True:
f = True
for s in str(N):
if s in D:
f = False
if f:
print((str(N)))
break
else:
N += 1
| N, K = list(map(int, input().split()))
D = set(input().split())
while len(set(str(N)) & D) > 0:
N += 1
print(N)
| false | 46.153846 | [
"-D = list(input().split())",
"-while True:",
"- f = True",
"- for s in str(N):",
"- if s in D:",
"- f = False",
"- if f:",
"- print((str(N)))",
"- break",
"- else:",
"- N += 1",
"+D = set(input().split())",
"+while len(set(str(N)) & D) > 0:",
"+ N += 1",
"+print(N)"
] | false | 0.077507 | 0.036015 | 2.152043 | [
"s261093003",
"s936786148"
] |
u377989038 | p02720 | python | s514868440 | s370945622 | 1,644 | 556 | 31,956 | 12,856 | Accepted | Accepted | 66.18 | def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(0, str(i))
print((sorted(l)[k - 1])) | def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(1, str(i))
print((sorted(l)[k - 1])) | 16 | 16 | 305 | 305 | def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(0, str(i))
print((sorted(l)[k - 1]))
| def dfs(d, r):
global l
if d == 11:
return
l.append(int(r))
for i in range(-1, 2):
tmp = int(r[-1]) + i
if 0 <= tmp <= 9:
dfs(d + 1, r + str(tmp))
k = int(eval(input()))
l = []
for i in range(1, 10):
dfs(1, str(i))
print((sorted(l)[k - 1]))
| false | 0 | [
"- dfs(0, str(i))",
"+ dfs(1, str(i))"
] | false | 2.695545 | 1.126183 | 2.393522 | [
"s514868440",
"s370945622"
] |
u079022693 | p03387 | python | s050132688 | s039488581 | 20 | 17 | 3,188 | 3,064 | Accepted | Accepted | 15 | from sys import stdin
def main():
#入力
readline=stdin.readline
a,b,c=list(map(int,readline().split()))
count=0
li=[a,b,c]
li.sort()
count+=li[2]-li[1]
li[0]+=li[2]-li[1]
li[1]+=li[2]-li[1]
count+=(li[2]-li[0])//2
li[0]+=((li[2]-li[0])//2)*2
if li[0]==li[2]:
print(count)
else:
print((count+2))
if __name__=="__main__":
main() | from sys import stdin
def main():
#入力
readline=stdin.readline
a,b,c=list(map(int,readline().split()))
li=[a,b,c]
li.sort()
x=li[0]
y=li[1]
z=li[2]
cnt=0
cnt+=z-y
x+=z-y
y+=z-y
if (z-x)%2==0:
cnt+=(z-x)//2
else:
cnt+=(z-x+1)//2+1
print(cnt)
if __name__=="__main__":
main() | 24 | 24 | 424 | 371 | from sys import stdin
def main():
# 入力
readline = stdin.readline
a, b, c = list(map(int, readline().split()))
count = 0
li = [a, b, c]
li.sort()
count += li[2] - li[1]
li[0] += li[2] - li[1]
li[1] += li[2] - li[1]
count += (li[2] - li[0]) // 2
li[0] += ((li[2] - li[0]) // 2) * 2
if li[0] == li[2]:
print(count)
else:
print((count + 2))
if __name__ == "__main__":
main()
| from sys import stdin
def main():
# 入力
readline = stdin.readline
a, b, c = list(map(int, readline().split()))
li = [a, b, c]
li.sort()
x = li[0]
y = li[1]
z = li[2]
cnt = 0
cnt += z - y
x += z - y
y += z - y
if (z - x) % 2 == 0:
cnt += (z - x) // 2
else:
cnt += (z - x + 1) // 2 + 1
print(cnt)
if __name__ == "__main__":
main()
| false | 0 | [
"- count = 0",
"- count += li[2] - li[1]",
"- li[0] += li[2] - li[1]",
"- li[1] += li[2] - li[1]",
"- count += (li[2] - li[0]) // 2",
"- li[0] += ((li[2] - li[0]) // 2) * 2",
"- if li[0] == li[2]:",
"- print(count)",
"+ x = li[0]",
"+ y = li[1]",
"+ z = li[2]",
"+ cnt = 0",
"+ cnt += z - y",
"+ x += z - y",
"+ y += z - y",
"+ if (z - x) % 2 == 0:",
"+ cnt += (z - x) // 2",
"- print((count + 2))",
"+ cnt += (z - x + 1) // 2 + 1",
"+ print(cnt)"
] | false | 0.047638 | 0.08701 | 0.547496 | [
"s050132688",
"s039488581"
] |
u075012704 | p04020 | python | s990966061 | s933344310 | 550 | 217 | 51,420 | 7,072 | Accepted | Accepted | 60.55 | from collections import OrderedDict, deque
N = int(eval(input()))
A = OrderedDict({i: int(eval(input())) for i in range(1, N+1)})
ans = 0
for key in range(1, N):
ans += A[key] // 2
A[key] %= 2
if (A[key] == 1) & (A[key+1] > 0):
ans += 1
A[key+1] -= 1
print((ans + A[N]//2)) | N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
ans = 0
for i in range(N-1):
ans += A[i] // 2
if A[i] % 2 and A[i+1]:
ans += 1
A[i+1] -= 1
print((ans + A[-1]//2)) | 14 | 11 | 303 | 202 | from collections import OrderedDict, deque
N = int(eval(input()))
A = OrderedDict({i: int(eval(input())) for i in range(1, N + 1)})
ans = 0
for key in range(1, N):
ans += A[key] // 2
A[key] %= 2
if (A[key] == 1) & (A[key + 1] > 0):
ans += 1
A[key + 1] -= 1
print((ans + A[N] // 2))
| N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
ans = 0
for i in range(N - 1):
ans += A[i] // 2
if A[i] % 2 and A[i + 1]:
ans += 1
A[i + 1] -= 1
print((ans + A[-1] // 2))
| false | 21.428571 | [
"-from collections import OrderedDict, deque",
"-",
"-A = OrderedDict({i: int(eval(input())) for i in range(1, N + 1)})",
"+A = [int(eval(input())) for i in range(N)]",
"-for key in range(1, N):",
"- ans += A[key] // 2",
"- A[key] %= 2",
"- if (A[key] == 1) & (A[key + 1] > 0):",
"+for i in range(N - 1):",
"+ ans += A[i] // 2",
"+ if A[i] % 2 and A[i + 1]:",
"- A[key + 1] -= 1",
"-print((ans + A[N] // 2))",
"+ A[i + 1] -= 1",
"+print((ans + A[-1] // 2))"
] | false | 0.034286 | 0.035913 | 0.954687 | [
"s990966061",
"s933344310"
] |
u619458041 | p02991 | python | s810206659 | s149862990 | 735 | 461 | 19,160 | 50,628 | Accepted | Accepted | 37.28 | import sys
from collections import deque
sys.setrecursionlimit(10**6)
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
u, v = list(map(int, input().split()))
G[u-1].append(v-1)
S, T = list(map(int, input().split()))
S, T = S-1, T-1
q = deque()
q.append(S)
cnt = 0
cnt_k = 0
visited = [False] * N
visited[S] = True
while len(q) > 0:
cnt += 1
if cnt % 3 == 0:
cnt_k += 1
next_ = set()
while len(q) > 0:
n0 = q.pop()
for n1 in G[n0]:
if cnt % 3 == 0:
if n1 == T:
return cnt_k
if visited[n1]:
continue
visited[n1] = True
next_.add(n1)
q = deque()
q.extend(list(next_))
return -1
if __name__ == '__main__':
print((main()))
| import sys
from collections import deque
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
G = [[] for _ in range(3*N)]
for _ in range(M):
u, v = list(map(int, input().split()))
u, v = u-1, v-1
G[3*u].append(3*v+1)
G[3*u+1].append(3*v+2)
G[3*u+2].append(3*v)
S, T = list(map(int, input().split()))
S, T = 3*(S-1), 3*(T-1)
cnt = 0
q = deque()
q.append(S)
visited = [False] * (3*N)
visited[S] = True
while len(q) > 0:
q_ = deque()
cnt += 1
while len(q) > 0:
n = q.pop()
for m in G[n]:
if visited[m]:
continue
if m == T:
return cnt // 3
visited[m] = True
q_.append(m)
q = q_
return -1
if __name__ == '__main__':
print((main()))
| 48 | 45 | 1,030 | 943 | import sys
from collections import deque
sys.setrecursionlimit(10**6)
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
u, v = list(map(int, input().split()))
G[u - 1].append(v - 1)
S, T = list(map(int, input().split()))
S, T = S - 1, T - 1
q = deque()
q.append(S)
cnt = 0
cnt_k = 0
visited = [False] * N
visited[S] = True
while len(q) > 0:
cnt += 1
if cnt % 3 == 0:
cnt_k += 1
next_ = set()
while len(q) > 0:
n0 = q.pop()
for n1 in G[n0]:
if cnt % 3 == 0:
if n1 == T:
return cnt_k
if visited[n1]:
continue
visited[n1] = True
next_.add(n1)
q = deque()
q.extend(list(next_))
return -1
if __name__ == "__main__":
print((main()))
| import sys
from collections import deque
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
G = [[] for _ in range(3 * N)]
for _ in range(M):
u, v = list(map(int, input().split()))
u, v = u - 1, v - 1
G[3 * u].append(3 * v + 1)
G[3 * u + 1].append(3 * v + 2)
G[3 * u + 2].append(3 * v)
S, T = list(map(int, input().split()))
S, T = 3 * (S - 1), 3 * (T - 1)
cnt = 0
q = deque()
q.append(S)
visited = [False] * (3 * N)
visited[S] = True
while len(q) > 0:
q_ = deque()
cnt += 1
while len(q) > 0:
n = q.pop()
for m in G[n]:
if visited[m]:
continue
if m == T:
return cnt // 3
visited[m] = True
q_.append(m)
q = q_
return -1
if __name__ == "__main__":
print((main()))
| false | 6.25 | [
"-",
"-sys.setrecursionlimit(10**6)",
"- G = [[] for _ in range(N)]",
"+ G = [[] for _ in range(3 * N)]",
"- G[u - 1].append(v - 1)",
"+ u, v = u - 1, v - 1",
"+ G[3 * u].append(3 * v + 1)",
"+ G[3 * u + 1].append(3 * v + 2)",
"+ G[3 * u + 2].append(3 * v)",
"- S, T = S - 1, T - 1",
"+ S, T = 3 * (S - 1), 3 * (T - 1)",
"+ cnt = 0",
"- cnt = 0",
"- cnt_k = 0",
"- visited = [False] * N",
"+ visited = [False] * (3 * N)",
"+ q_ = deque()",
"- if cnt % 3 == 0:",
"- cnt_k += 1",
"- next_ = set()",
"- n0 = q.pop()",
"- for n1 in G[n0]:",
"- if cnt % 3 == 0:",
"- if n1 == T:",
"- return cnt_k",
"- if visited[n1]:",
"- continue",
"- visited[n1] = True",
"- next_.add(n1)",
"- q = deque()",
"- q.extend(list(next_))",
"+ n = q.pop()",
"+ for m in G[n]:",
"+ if visited[m]:",
"+ continue",
"+ if m == T:",
"+ return cnt // 3",
"+ visited[m] = True",
"+ q_.append(m)",
"+ q = q_"
] | false | 0.042119 | 0.12633 | 0.333404 | [
"s810206659",
"s149862990"
] |
u816631826 | p02676 | python | s220595753 | s632657470 | 31 | 28 | 9,028 | 9,200 | Accepted | Accepted | 9.68 | K=int(eval(input()))
S=eval(input())
if len(S)<K or len(S)==K:
print (S)
elif len(S)>K:
print((S[0:K]+"...")) | k=int(eval(input()))
s=eval(input())
characters=len(s)
empty=""
if characters<=k:
print(s)
else:
i=0
while i<=k-1:
empty+=s[i]
i=i+1
print(f"{empty}...") | 6 | 12 | 109 | 179 | K = int(eval(input()))
S = eval(input())
if len(S) < K or len(S) == K:
print(S)
elif len(S) > K:
print((S[0:K] + "..."))
| k = int(eval(input()))
s = eval(input())
characters = len(s)
empty = ""
if characters <= k:
print(s)
else:
i = 0
while i <= k - 1:
empty += s[i]
i = i + 1
print(f"{empty}...")
| false | 50 | [
"-K = int(eval(input()))",
"-S = eval(input())",
"-if len(S) < K or len(S) == K:",
"- print(S)",
"-elif len(S) > K:",
"- print((S[0:K] + \"...\"))",
"+k = int(eval(input()))",
"+s = eval(input())",
"+characters = len(s)",
"+empty = \"\"",
"+if characters <= k:",
"+ print(s)",
"+else:",
"+ i = 0",
"+ while i <= k - 1:",
"+ empty += s[i]",
"+ i = i + 1",
"+ print(f\"{empty}...\")"
] | false | 0.038954 | 0.035899 | 1.08508 | [
"s220595753",
"s632657470"
] |
u360116509 | p03163 | python | s601120954 | s329282968 | 403 | 368 | 118,512 | 118,512 | Accepted | Accepted | 8.68 | def main():
N, W = list(map(int, input().split()))
WV = []
for _ in range(N):
w, v = list(map(int, input().split()))
WV.append((w, v))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(W + 1):
if j >= WV[i][0]:
dp[i + 1][j] = max(
dp[i][j],
dp[i][j - WV[i][0]] + WV[i][1]
)
else:
dp[i + 1][j] = dp[i][j]
print((dp[-1][-1]))
main()
| def main():
N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if j >= w:
dp[i + 1][j] = max(
dp[i][j],
dp[i][j - w] + v
)
else:
dp[i + 1][j] = dp[i][j]
print((dp[-1][-1]))
main()
| 20 | 17 | 525 | 440 | def main():
N, W = list(map(int, input().split()))
WV = []
for _ in range(N):
w, v = list(map(int, input().split()))
WV.append((w, v))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(W + 1):
if j >= WV[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - WV[i][0]] + WV[i][1])
else:
dp[i + 1][j] = dp[i][j]
print((dp[-1][-1]))
main()
| def main():
N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if j >= w:
dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)
else:
dp[i + 1][j] = dp[i][j]
print((dp[-1][-1]))
main()
| false | 15 | [
"- WV = []",
"- for _ in range(N):",
"- w, v = list(map(int, input().split()))",
"- WV.append((w, v))",
"+ w, v = list(map(int, input().split()))",
"- if j >= WV[i][0]:",
"- dp[i + 1][j] = max(dp[i][j], dp[i][j - WV[i][0]] + WV[i][1])",
"+ if j >= w:",
"+ dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)"
] | false | 0.04737 | 0.044474 | 1.065113 | [
"s601120954",
"s329282968"
] |
u901582103 | p02707 | python | s751148265 | s708683633 | 192 | 158 | 33,992 | 32,372 | Accepted | Accepted | 17.71 | from collections import Counter
n=int(eval(input()))
A=list(map(int,input().split()))
AC=Counter(A)
for i in range(n):
if (i+1) in list(AC.keys()):
print((AC[i+1]))
else:
print((0)) | n=int(eval(input()))
A=list(map(int,input().split()))
L=[0]*n
for i in range(n-1):
L[A[i]-1]+=1
for i in range(n):
print((L[i])) | 9 | 7 | 197 | 134 | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
AC = Counter(A)
for i in range(n):
if (i + 1) in list(AC.keys()):
print((AC[i + 1]))
else:
print((0))
| n = int(eval(input()))
A = list(map(int, input().split()))
L = [0] * n
for i in range(n - 1):
L[A[i] - 1] += 1
for i in range(n):
print((L[i]))
| false | 22.222222 | [
"-from collections import Counter",
"-",
"-AC = Counter(A)",
"+L = [0] * n",
"+for i in range(n - 1):",
"+ L[A[i] - 1] += 1",
"- if (i + 1) in list(AC.keys()):",
"- print((AC[i + 1]))",
"- else:",
"- print((0))",
"+ print((L[i]))"
] | false | 0.049107 | 0.04882 | 1.005871 | [
"s751148265",
"s708683633"
] |
u633068244 | p00068 | python | s875293937 | s053234145 | 20 | 10 | 4,308 | 4,300 | Accepted | Accepted | 50 | def a(v1,v2):
if v1[0] != v2[0]:
return (v2[1]-v1[1])/(v2[0]-v1[0])
else:
return (v2[1]-v1[1])*(10**10)
def convex(v,n):
k = 0
d = []
u = []
for i in range(n):
d.append(i)
u.append(i)
while len(d) > 2:
if a(v[d[-3]],v[d[-2]]) < a(v[d[-2]],v[d[-1]]):
del d[-2]
else:
break
while len(u) > 2:
if a(v[u[-3]],v[u[-2]]) > a(v[u[-2]],v[u[-1]]):
del u[-2]
else:
break
return n - len(set(d+u))
while 1:
n = eval(input())
if n == 0: break
v = [list(map(float,input().split(","))) for i in range(n)]
v = sorted(sorted(v, key = lambda x:x[1]))
print(convex(v,n)) | def a(v1,v2):
if v1[0] != v2[0]:
return (v2[1]-v1[1])/(v2[0]-v1[0])
else:
return (v2[1]-v1[1])*(10**10)
def dlt(p,v,sign):
while len(p) > 2:
if sign*(a(v[p[-3]],v[p[-2]]) - a(v[p[-2]],v[p[-1]])) < 0:
del p[-2]
else:
break
return p
def convex(v,n):
d,u = [],[]
for i in range(n):
d = dlt(d+[i],v,1)
u = dlt(u+[i],v,-1)
return n - len(set(d+u))
while 1:
n = eval(input())
if n == 0: break
v = [list(map(float,input().split(","))) for i in range(n)]
v = sorted(sorted(v, key = lambda x:x[1]))
print(convex(v,n)) | 31 | 24 | 628 | 552 | def a(v1, v2):
if v1[0] != v2[0]:
return (v2[1] - v1[1]) / (v2[0] - v1[0])
else:
return (v2[1] - v1[1]) * (10**10)
def convex(v, n):
k = 0
d = []
u = []
for i in range(n):
d.append(i)
u.append(i)
while len(d) > 2:
if a(v[d[-3]], v[d[-2]]) < a(v[d[-2]], v[d[-1]]):
del d[-2]
else:
break
while len(u) > 2:
if a(v[u[-3]], v[u[-2]]) > a(v[u[-2]], v[u[-1]]):
del u[-2]
else:
break
return n - len(set(d + u))
while 1:
n = eval(input())
if n == 0:
break
v = [list(map(float, input().split(","))) for i in range(n)]
v = sorted(sorted(v, key=lambda x: x[1]))
print(convex(v, n))
| def a(v1, v2):
if v1[0] != v2[0]:
return (v2[1] - v1[1]) / (v2[0] - v1[0])
else:
return (v2[1] - v1[1]) * (10**10)
def dlt(p, v, sign):
while len(p) > 2:
if sign * (a(v[p[-3]], v[p[-2]]) - a(v[p[-2]], v[p[-1]])) < 0:
del p[-2]
else:
break
return p
def convex(v, n):
d, u = [], []
for i in range(n):
d = dlt(d + [i], v, 1)
u = dlt(u + [i], v, -1)
return n - len(set(d + u))
while 1:
n = eval(input())
if n == 0:
break
v = [list(map(float, input().split(","))) for i in range(n)]
v = sorted(sorted(v, key=lambda x: x[1]))
print(convex(v, n))
| false | 22.580645 | [
"+def dlt(p, v, sign):",
"+ while len(p) > 2:",
"+ if sign * (a(v[p[-3]], v[p[-2]]) - a(v[p[-2]], v[p[-1]])) < 0:",
"+ del p[-2]",
"+ else:",
"+ break",
"+ return p",
"+",
"+",
"- k = 0",
"- d = []",
"- u = []",
"+ d, u = [], []",
"- d.append(i)",
"- u.append(i)",
"- while len(d) > 2:",
"- if a(v[d[-3]], v[d[-2]]) < a(v[d[-2]], v[d[-1]]):",
"- del d[-2]",
"- else:",
"- break",
"- while len(u) > 2:",
"- if a(v[u[-3]], v[u[-2]]) > a(v[u[-2]], v[u[-1]]):",
"- del u[-2]",
"- else:",
"- break",
"+ d = dlt(d + [i], v, 1)",
"+ u = dlt(u + [i], v, -1)"
] | false | 0.043562 | 0.044433 | 0.980401 | [
"s875293937",
"s053234145"
] |
u549056918 | p02412 | python | s491020087 | s314033777 | 440 | 70 | 5,644 | 5,644 | Accepted | Accepted | 84.09 | from itertools import combinations as comb
def get_ans(m, n):
ans = sum(1 for nums in comb(list(range(1, min(m+1,n-2))), 3) if sum(nums)==n)
return ans
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
ans = get_ans(m, n)
print(ans)
| from itertools import combinations as comb
def get_ans(m, n):
ans = sum(1 for nums in comb(list(range(1, min(m+1,n-2))), 2) if ((n-sum(nums)>0) and (n-sum(nums) > max(nums)) and (n-sum(nums)<=m)))
return ans
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
ans = get_ans(m, n)
print(ans)
| 11 | 11 | 304 | 360 | from itertools import combinations as comb
def get_ans(m, n):
ans = sum(
1 for nums in comb(list(range(1, min(m + 1, n - 2))), 3) if sum(nums) == n
)
return ans
while True:
m, n = (int(x) for x in input().split())
if m == 0 and n == 0:
quit()
ans = get_ans(m, n)
print(ans)
| from itertools import combinations as comb
def get_ans(m, n):
ans = sum(
1
for nums in comb(list(range(1, min(m + 1, n - 2))), 2)
if (
(n - sum(nums) > 0) and (n - sum(nums) > max(nums)) and (n - sum(nums) <= m)
)
)
return ans
while True:
m, n = (int(x) for x in input().split())
if m == 0 and n == 0:
quit()
ans = get_ans(m, n)
print(ans)
| false | 0 | [
"- 1 for nums in comb(list(range(1, min(m + 1, n - 2))), 3) if sum(nums) == n",
"+ 1",
"+ for nums in comb(list(range(1, min(m + 1, n - 2))), 2)",
"+ if (",
"+ (n - sum(nums) > 0) and (n - sum(nums) > max(nums)) and (n - sum(nums) <= m)",
"+ )"
] | false | 0.034747 | 0.052813 | 0.657932 | [
"s491020087",
"s314033777"
] |
u652583512 | p03078 | python | s419229986 | s506898448 | 257 | 40 | 47,220 | 4,832 | Accepted | Accepted | 84.44 | X, Y, Z, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
D = []
for i in range(min(K, X)):
for j in range(min(K, Y)):
if (i + 1) * (j + 1) > K:
break
for k in range(min(K, Z)):
if (i + 1) * (j + 1) * (k + 1) > K:
break
else:
D.append(A[i] + B[j] + C[k])
D.sort(reverse=True)
for i in range(K):
print((D[i])) | import heapq
X, Y, Z, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
Q = []
dic = {}
heapq.heappush(Q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
i = 0
while i < K and len(Q) > 0:
t = heapq.heappop(Q)
print((-t[0]))
a, b, c = t[1:]
if a + 1 < X and (a + 2) * (b + 1) * (c + 1) <= K and not (a + 1, b, c) in list(dic.keys()):
heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
dic[(a + 1, b, c)] = 1
if b + 1 < Y and (a + 1) * (b + 2) * (c + 1) <= K and not (a, b + 1, c) in list(dic.keys()):
heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
dic[(a, b + 1, c)] = 1
if c + 1 < Z and (a + 1) * (b + 1) * (c + 2) <= K and not (a, b, c + 1) in list(dic.keys()):
heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
dic[(a, b, c + 1)] = 1
i += 1
| 19 | 25 | 579 | 1,003 | X, Y, Z, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
D = []
for i in range(min(K, X)):
for j in range(min(K, Y)):
if (i + 1) * (j + 1) > K:
break
for k in range(min(K, Z)):
if (i + 1) * (j + 1) * (k + 1) > K:
break
else:
D.append(A[i] + B[j] + C[k])
D.sort(reverse=True)
for i in range(K):
print((D[i]))
| import heapq
X, Y, Z, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
Q = []
dic = {}
heapq.heappush(Q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
i = 0
while i < K and len(Q) > 0:
t = heapq.heappop(Q)
print((-t[0]))
a, b, c = t[1:]
if (
a + 1 < X
and (a + 2) * (b + 1) * (c + 1) <= K
and not (a + 1, b, c) in list(dic.keys())
):
heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
dic[(a + 1, b, c)] = 1
if (
b + 1 < Y
and (a + 1) * (b + 2) * (c + 1) <= K
and not (a, b + 1, c) in list(dic.keys())
):
heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
dic[(a, b + 1, c)] = 1
if (
c + 1 < Z
and (a + 1) * (b + 1) * (c + 2) <= K
and not (a, b, c + 1) in list(dic.keys())
):
heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
dic[(a, b, c + 1)] = 1
i += 1
| false | 24 | [
"+import heapq",
"+",
"-D = []",
"-for i in range(min(K, X)):",
"- for j in range(min(K, Y)):",
"- if (i + 1) * (j + 1) > K:",
"- break",
"- for k in range(min(K, Z)):",
"- if (i + 1) * (j + 1) * (k + 1) > K:",
"- break",
"- else:",
"- D.append(A[i] + B[j] + C[k])",
"-D.sort(reverse=True)",
"-for i in range(K):",
"- print((D[i]))",
"+Q = []",
"+dic = {}",
"+heapq.heappush(Q, (-(A[0] + B[0] + C[0]), 0, 0, 0))",
"+i = 0",
"+while i < K and len(Q) > 0:",
"+ t = heapq.heappop(Q)",
"+ print((-t[0]))",
"+ a, b, c = t[1:]",
"+ if (",
"+ a + 1 < X",
"+ and (a + 2) * (b + 1) * (c + 1) <= K",
"+ and not (a + 1, b, c) in list(dic.keys())",
"+ ):",
"+ heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))",
"+ dic[(a + 1, b, c)] = 1",
"+ if (",
"+ b + 1 < Y",
"+ and (a + 1) * (b + 2) * (c + 1) <= K",
"+ and not (a, b + 1, c) in list(dic.keys())",
"+ ):",
"+ heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))",
"+ dic[(a, b + 1, c)] = 1",
"+ if (",
"+ c + 1 < Z",
"+ and (a + 1) * (b + 1) * (c + 2) <= K",
"+ and not (a, b, c + 1) in list(dic.keys())",
"+ ):",
"+ heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))",
"+ dic[(a, b, c + 1)] = 1",
"+ i += 1"
] | false | 0.088665 | 0.03728 | 2.378374 | [
"s419229986",
"s506898448"
] |
u325264482 | p03127 | python | s026675157 | s363675483 | 140 | 98 | 14,484 | 16,244 | Accepted | Accepted | 30 | N = int(eval(input()))
A = list(map(int, input().split()))
As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)
def judge(tmp_one, tmp_two):
flg = 1
while flg:
if tmp_two%tmp_one == 0:
tmp_two = tmp_one
else:
tmp_two = tmp_two%tmp_one
if tmp_one%tmp_two == 0:
tmp_one = tmp_two
else:
tmp_one = tmp_one%tmp_two
if tmp_one == tmp_two:
flg = 0
return tmp_one
tmp_one = As[0]
for i in range(1, N):
if i == N - 1:
tmp_two = As[i]
elif As[i] != As[0]:
tmp_two = As[i]
break
tmp = judge(tmp_one, tmp_two)
print(tmp)
| import fractions
N = int(eval(input()))
A = list(map(int, input().split()))
ans = fractions.gcd(A[0], A[1])
for i in range(2, N):
ans = fractions.gcd(ans, A[i])
print(ans)
| 35 | 13 | 720 | 189 | N = int(eval(input()))
A = list(map(int, input().split()))
As = sorted(A)
As = [a % As[0] if a % As[0] != 0 else As[0] for a in As]
As = sorted(As)
def judge(tmp_one, tmp_two):
flg = 1
while flg:
if tmp_two % tmp_one == 0:
tmp_two = tmp_one
else:
tmp_two = tmp_two % tmp_one
if tmp_one % tmp_two == 0:
tmp_one = tmp_two
else:
tmp_one = tmp_one % tmp_two
if tmp_one == tmp_two:
flg = 0
return tmp_one
tmp_one = As[0]
for i in range(1, N):
if i == N - 1:
tmp_two = As[i]
elif As[i] != As[0]:
tmp_two = As[i]
break
tmp = judge(tmp_one, tmp_two)
print(tmp)
| import fractions
N = int(eval(input()))
A = list(map(int, input().split()))
ans = fractions.gcd(A[0], A[1])
for i in range(2, N):
ans = fractions.gcd(ans, A[i])
print(ans)
| false | 62.857143 | [
"+import fractions",
"+",
"-As = sorted(A)",
"-As = [a % As[0] if a % As[0] != 0 else As[0] for a in As]",
"-As = sorted(As)",
"-",
"-",
"-def judge(tmp_one, tmp_two):",
"- flg = 1",
"- while flg:",
"- if tmp_two % tmp_one == 0:",
"- tmp_two = tmp_one",
"- else:",
"- tmp_two = tmp_two % tmp_one",
"- if tmp_one % tmp_two == 0:",
"- tmp_one = tmp_two",
"- else:",
"- tmp_one = tmp_one % tmp_two",
"- if tmp_one == tmp_two:",
"- flg = 0",
"- return tmp_one",
"-",
"-",
"-tmp_one = As[0]",
"-for i in range(1, N):",
"- if i == N - 1:",
"- tmp_two = As[i]",
"- elif As[i] != As[0]:",
"- tmp_two = As[i]",
"- break",
"-tmp = judge(tmp_one, tmp_two)",
"-print(tmp)",
"+ans = fractions.gcd(A[0], A[1])",
"+for i in range(2, N):",
"+ ans = fractions.gcd(ans, A[i])",
"+print(ans)"
] | false | 0.036617 | 0.007188 | 5.093824 | [
"s026675157",
"s363675483"
] |
u869919400 | p02861 | python | s881167082 | s949978579 | 209 | 95 | 43,756 | 74,428 | Accepted | Accepted | 54.55 | from math import sqrt
from itertools import permutations as per
N = int(eval(input()))
xy = [list(map(int, input().split())) for i in range(N)]
kumi = per(list(range(N)))
ans = []
leng = 0
for p in kumi:
cnt = 0
for i in range(1, len(p)):
cnt += sqrt((xy[p[i-1]][0] - xy[p[i]][0])**2 + (xy[p[i-1]][1] - xy[p[i]][1])**2)
ans.append(cnt)
leng += 1
print((sum(ans) / leng)) | N = int(eval(input()))
xy = [list(map(int, input().split())) for i in range(N)]
from itertools import permutations
from math import sqrt
paths = list(permutations(list(range(N)), N))
l = len(paths)
total = 0
for path in paths:
tmp = 0
x, y = xy[path[0]][0], xy[path[0]][1]
for p in path[1:]:
px, py = xy[p][0], xy[p][1]
tmp += sqrt((px-x)**2 + (py-y)**2)
total += tmp
print((total / l)) | 14 | 17 | 393 | 422 | from math import sqrt
from itertools import permutations as per
N = int(eval(input()))
xy = [list(map(int, input().split())) for i in range(N)]
kumi = per(list(range(N)))
ans = []
leng = 0
for p in kumi:
cnt = 0
for i in range(1, len(p)):
cnt += sqrt(
(xy[p[i - 1]][0] - xy[p[i]][0]) ** 2 + (xy[p[i - 1]][1] - xy[p[i]][1]) ** 2
)
ans.append(cnt)
leng += 1
print((sum(ans) / leng))
| N = int(eval(input()))
xy = [list(map(int, input().split())) for i in range(N)]
from itertools import permutations
from math import sqrt
paths = list(permutations(list(range(N)), N))
l = len(paths)
total = 0
for path in paths:
tmp = 0
x, y = xy[path[0]][0], xy[path[0]][1]
for p in path[1:]:
px, py = xy[p][0], xy[p][1]
tmp += sqrt((px - x) ** 2 + (py - y) ** 2)
total += tmp
print((total / l))
| false | 17.647059 | [
"-from math import sqrt",
"-from itertools import permutations as per",
"-",
"-kumi = per(list(range(N)))",
"-ans = []",
"-leng = 0",
"-for p in kumi:",
"- cnt = 0",
"- for i in range(1, len(p)):",
"- cnt += sqrt(",
"- (xy[p[i - 1]][0] - xy[p[i]][0]) ** 2 + (xy[p[i - 1]][1] - xy[p[i]][1]) ** 2",
"- )",
"- ans.append(cnt)",
"- leng += 1",
"-print((sum(ans) / leng))",
"+from itertools import permutations",
"+from math import sqrt",
"+",
"+paths = list(permutations(list(range(N)), N))",
"+l = len(paths)",
"+total = 0",
"+for path in paths:",
"+ tmp = 0",
"+ x, y = xy[path[0]][0], xy[path[0]][1]",
"+ for p in path[1:]:",
"+ px, py = xy[p][0], xy[p][1]",
"+ tmp += sqrt((px - x) ** 2 + (py - y) ** 2)",
"+ total += tmp",
"+print((total / l))"
] | false | 0.167306 | 0.046771 | 3.577139 | [
"s881167082",
"s949978579"
] |
u327466606 | p03634 | python | s039570302 | s014565117 | 1,760 | 1,425 | 61,260 | 43,312 | Accepted | Accepted | 19.03 | from collections import defaultdict
N = int(eval(input()))
E = defaultdict(list)
W = dict()
for i in range(N-1):
a,b,c = list(map(int,input().split()))
E[a].append(b)
E[b].append(a)
W[(a,b)] = c
W[(b,a)] = c
Q,K = list(map(int,input().split()))
costs = [float('inf')]*(N+1)
costs[K] = 0
stack = [K]
while stack:
s = stack.pop()
for t in E[s]:
if costs[t] > costs[s] + W[(s,t)]:
costs[t] = costs[s] + W[(s,t)]
stack.append(t)
for i in range(Q):
x,y = list(map(int,input().split()))
print((costs[x]+costs[y])) |
N = int(eval(input()))
E = [[] for _ in range(N)]
for i in range(N-1):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
E[a].append((b,c))
E[b].append((a,c))
Q,K = list(map(int,input().split()))
K -= 1
costs = [None]*N
costs[K] = 0
stack = [K]
while stack:
s = stack.pop()
c = costs[s]
for t,d in E[s]:
if costs[t] is None:
costs[t] = c + d
stack.append(t)
for i in range(Q):
x,y = list(map(int,input().split()))
print((costs[x-1]+costs[y-1])) | 30 | 29 | 551 | 491 | from collections import defaultdict
N = int(eval(input()))
E = defaultdict(list)
W = dict()
for i in range(N - 1):
a, b, c = list(map(int, input().split()))
E[a].append(b)
E[b].append(a)
W[(a, b)] = c
W[(b, a)] = c
Q, K = list(map(int, input().split()))
costs = [float("inf")] * (N + 1)
costs[K] = 0
stack = [K]
while stack:
s = stack.pop()
for t in E[s]:
if costs[t] > costs[s] + W[(s, t)]:
costs[t] = costs[s] + W[(s, t)]
stack.append(t)
for i in range(Q):
x, y = list(map(int, input().split()))
print((costs[x] + costs[y]))
| N = int(eval(input()))
E = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
E[a].append((b, c))
E[b].append((a, c))
Q, K = list(map(int, input().split()))
K -= 1
costs = [None] * N
costs[K] = 0
stack = [K]
while stack:
s = stack.pop()
c = costs[s]
for t, d in E[s]:
if costs[t] is None:
costs[t] = c + d
stack.append(t)
for i in range(Q):
x, y = list(map(int, input().split()))
print((costs[x - 1] + costs[y - 1]))
| false | 3.333333 | [
"-from collections import defaultdict",
"-",
"-E = defaultdict(list)",
"-W = dict()",
"+E = [[] for _ in range(N)]",
"- E[a].append(b)",
"- E[b].append(a)",
"- W[(a, b)] = c",
"- W[(b, a)] = c",
"+ a -= 1",
"+ b -= 1",
"+ E[a].append((b, c))",
"+ E[b].append((a, c))",
"-costs = [float(\"inf\")] * (N + 1)",
"+K -= 1",
"+costs = [None] * N",
"- for t in E[s]:",
"- if costs[t] > costs[s] + W[(s, t)]:",
"- costs[t] = costs[s] + W[(s, t)]",
"+ c = costs[s]",
"+ for t, d in E[s]:",
"+ if costs[t] is None:",
"+ costs[t] = c + d",
"- print((costs[x] + costs[y]))",
"+ print((costs[x - 1] + costs[y - 1]))"
] | false | 0.152311 | 0.045264 | 3.364971 | [
"s039570302",
"s014565117"
] |
u391589398 | p02761 | python | s831902977 | s490358104 | 32 | 28 | 9,184 | 9,180 | Accepted | Accepted | 12.5 | n, m = list(map(int, input().split()))
digits = [-1]*n
for _ in range(m):
s, c = list(map(int, input().split()))
s -= 1
if digits[s] == -1 or digits[s] == c:
digits[s] = c
else:
print((-1))
break
else:
if n == 1:
print((0 if digits[0] == -1 else digits[0]))
else:
if digits[0] == 0:
print((-1))
else:
ans = ''
for i, d in enumerate(digits):
if i == 0 and d == -1:
ans += '1'
elif i > 0 and d == -1:
ans += '0'
else:
ans += str(d)
print(ans)
| n, m = list(map(int, input().split()))
sc = []
for _ in range(m):
s, c = list(map(int, input().split()))
s -= 1
sc.append((s, c))
for nn in range(10**n):
sn = str(nn)
if len(sn) != n:
continue
for s, c in sc:
if int(sn[s]) != c:
break
else:
print(nn)
break
else:
print((-1)) | 26 | 19 | 676 | 355 | n, m = list(map(int, input().split()))
digits = [-1] * n
for _ in range(m):
s, c = list(map(int, input().split()))
s -= 1
if digits[s] == -1 or digits[s] == c:
digits[s] = c
else:
print((-1))
break
else:
if n == 1:
print((0 if digits[0] == -1 else digits[0]))
else:
if digits[0] == 0:
print((-1))
else:
ans = ""
for i, d in enumerate(digits):
if i == 0 and d == -1:
ans += "1"
elif i > 0 and d == -1:
ans += "0"
else:
ans += str(d)
print(ans)
| n, m = list(map(int, input().split()))
sc = []
for _ in range(m):
s, c = list(map(int, input().split()))
s -= 1
sc.append((s, c))
for nn in range(10**n):
sn = str(nn)
if len(sn) != n:
continue
for s, c in sc:
if int(sn[s]) != c:
break
else:
print(nn)
break
else:
print((-1))
| false | 26.923077 | [
"-digits = [-1] * n",
"+sc = []",
"- if digits[s] == -1 or digits[s] == c:",
"- digits[s] = c",
"+ sc.append((s, c))",
"+for nn in range(10**n):",
"+ sn = str(nn)",
"+ if len(sn) != n:",
"+ continue",
"+ for s, c in sc:",
"+ if int(sn[s]) != c:",
"+ break",
"- print((-1))",
"+ print(nn)",
"- if n == 1:",
"- print((0 if digits[0] == -1 else digits[0]))",
"- else:",
"- if digits[0] == 0:",
"- print((-1))",
"- else:",
"- ans = \"\"",
"- for i, d in enumerate(digits):",
"- if i == 0 and d == -1:",
"- ans += \"1\"",
"- elif i > 0 and d == -1:",
"- ans += \"0\"",
"- else:",
"- ans += str(d)",
"- print(ans)",
"+ print((-1))"
] | false | 0.084935 | 0.135034 | 0.628988 | [
"s831902977",
"s490358104"
] |
u674588203 | p02582 | python | s990559266 | s743810805 | 36 | 31 | 9,032 | 8,948 | Accepted | Accepted | 13.89 | # AtCoder Beginner Contest 175
S=eval(input())
if S=="SSS":
print((0))
exit()
if S=="SRR" or S=="RRS":
print((2))
exit()
if S=="RRR":
print((3))
exit()
else:
print((1)) | # AtCoder Beginner Contest 175
# A - Rainy Season
S=eval(input())
if S=="RRR":
print((3))
exit()
if S=="SRR" or S=="RRS":
print((2))
exit()
if S=="SSS":
print((0))
exit()
else:
print((1)) | 14 | 15 | 196 | 216 | # AtCoder Beginner Contest 175
S = eval(input())
if S == "SSS":
print((0))
exit()
if S == "SRR" or S == "RRS":
print((2))
exit()
if S == "RRR":
print((3))
exit()
else:
print((1))
| # AtCoder Beginner Contest 175
# A - Rainy Season
S = eval(input())
if S == "RRR":
print((3))
exit()
if S == "SRR" or S == "RRS":
print((2))
exit()
if S == "SSS":
print((0))
exit()
else:
print((1))
| false | 6.666667 | [
"+# A - Rainy Season",
"-if S == \"SSS\":",
"- print((0))",
"+if S == \"RRR\":",
"+ print((3))",
"-if S == \"RRR\":",
"- print((3))",
"+if S == \"SSS\":",
"+ print((0))"
] | false | 0.085977 | 0.102831 | 0.836102 | [
"s990559266",
"s743810805"
] |
u197300773 | p03221 | python | s287833850 | s909038602 | 1,111 | 993 | 81,240 | 81,056 | Accepted | Accepted | 10.62 | _,m=list(map(int,input().split()))
ta=[list(map(int,input().split()))+[i] for i in range(m)]
a=sorted(ta)
ans=[-1]*m
j=0
for i in range(m):
if j!=a[i][0]:
j=a[i][0]
k=1
p=str(a[i][0]).zfill(6)+str(k).zfill(6)
ans[a[i][2]]=p
k+=1
a.sort()
for i in range(m):
print((ans[i]))
| n,m=list(map(int,input().split()))
x=[[] for _ in range(n+1)]
ans=[-1]*m
for i in range(m):
p,y=list(map(int,input().split()))
x[p].append([y,i])
for p in range(1,n+1):
x[p].sort()
for j in range(len(x[p])):
ans[x[p][j][1]]=str(p).zfill(6)+str(j+1).zfill(6)
for i in range(m):
print((ans[i])) | 16 | 14 | 317 | 321 | _, m = list(map(int, input().split()))
ta = [list(map(int, input().split())) + [i] for i in range(m)]
a = sorted(ta)
ans = [-1] * m
j = 0
for i in range(m):
if j != a[i][0]:
j = a[i][0]
k = 1
p = str(a[i][0]).zfill(6) + str(k).zfill(6)
ans[a[i][2]] = p
k += 1
a.sort()
for i in range(m):
print((ans[i]))
| n, m = list(map(int, input().split()))
x = [[] for _ in range(n + 1)]
ans = [-1] * m
for i in range(m):
p, y = list(map(int, input().split()))
x[p].append([y, i])
for p in range(1, n + 1):
x[p].sort()
for j in range(len(x[p])):
ans[x[p][j][1]] = str(p).zfill(6) + str(j + 1).zfill(6)
for i in range(m):
print((ans[i]))
| false | 12.5 | [
"-_, m = list(map(int, input().split()))",
"-ta = [list(map(int, input().split())) + [i] for i in range(m)]",
"-a = sorted(ta)",
"+n, m = list(map(int, input().split()))",
"+x = [[] for _ in range(n + 1)]",
"-j = 0",
"- if j != a[i][0]:",
"- j = a[i][0]",
"- k = 1",
"- p = str(a[i][0]).zfill(6) + str(k).zfill(6)",
"- ans[a[i][2]] = p",
"- k += 1",
"-a.sort()",
"+ p, y = list(map(int, input().split()))",
"+ x[p].append([y, i])",
"+for p in range(1, n + 1):",
"+ x[p].sort()",
"+ for j in range(len(x[p])):",
"+ ans[x[p][j][1]] = str(p).zfill(6) + str(j + 1).zfill(6)"
] | false | 0.047027 | 0.038524 | 1.220707 | [
"s287833850",
"s909038602"
] |
u057109575 | p02820 | python | s602329668 | s717722311 | 223 | 79 | 41,200 | 73,476 | Accepted | Accepted | 64.57 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
dp = [False] * N
for i in range(N):
if i >= K and dp[i - K] and T[i] == T[i - K]:
continue
dp[i] = True
ans = 0
for i in range(N):
if not dp[i]:
continue
if T[i] == "r":
ans += P
elif T[i] == "s":
ans += R
else:
ans += S
print(ans)
| N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
ok = [True] * N
d = {"r": P, "s": R, "p": S}
ans = 0
for i in range(N):
if i >= K and T[i - K] == T[i] and ok[i - K]:
ok[i] = False
if ok[i]:
ans += d[T[i]]
print(ans)
| 24 | 14 | 425 | 288 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
dp = [False] * N
for i in range(N):
if i >= K and dp[i - K] and T[i] == T[i - K]:
continue
dp[i] = True
ans = 0
for i in range(N):
if not dp[i]:
continue
if T[i] == "r":
ans += P
elif T[i] == "s":
ans += R
else:
ans += S
print(ans)
| N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
ok = [True] * N
d = {"r": P, "s": R, "p": S}
ans = 0
for i in range(N):
if i >= K and T[i - K] == T[i] and ok[i - K]:
ok[i] = False
if ok[i]:
ans += d[T[i]]
print(ans)
| false | 41.666667 | [
"-dp = [False] * N",
"-for i in range(N):",
"- if i >= K and dp[i - K] and T[i] == T[i - K]:",
"- continue",
"- dp[i] = True",
"+ok = [True] * N",
"+d = {\"r\": P, \"s\": R, \"p\": S}",
"- if not dp[i]:",
"- continue",
"- if T[i] == \"r\":",
"- ans += P",
"- elif T[i] == \"s\":",
"- ans += R",
"- else:",
"- ans += S",
"+ if i >= K and T[i - K] == T[i] and ok[i - K]:",
"+ ok[i] = False",
"+ if ok[i]:",
"+ ans += d[T[i]]"
] | false | 0.044646 | 0.036592 | 1.220123 | [
"s602329668",
"s717722311"
] |
u078349616 | p02720 | python | s568840547 | s580228731 | 295 | 131 | 10,584 | 6,096 | Accepted | Accepted | 55.59 | from collections import deque
K = int(eval(input()))
q = deque([0])
cnt = 0
ans = []
while q:
a = q.popleft()
r = a % 10
a *= 10
for i in range(10):
if abs(r - i) <= 1 or a == 0:
if cnt < K and a + i != 0:
q.append(a + i)
ans.append(a + i)
cnt += 1
print((ans[-1])) | from collections import deque
K = int(eval(input()))
q = deque([0])
cnt = 0
while q:
n = q.popleft()
r = n % 10; n *= 10;
for i in range(10):
if abs(r - i) <= 1 or n == 0:
if n + i != 0:
q.append(n + i)
cnt += 1
if cnt == K:
print((n+i))
exit() | 18 | 16 | 318 | 312 | from collections import deque
K = int(eval(input()))
q = deque([0])
cnt = 0
ans = []
while q:
a = q.popleft()
r = a % 10
a *= 10
for i in range(10):
if abs(r - i) <= 1 or a == 0:
if cnt < K and a + i != 0:
q.append(a + i)
ans.append(a + i)
cnt += 1
print((ans[-1]))
| from collections import deque
K = int(eval(input()))
q = deque([0])
cnt = 0
while q:
n = q.popleft()
r = n % 10
n *= 10
for i in range(10):
if abs(r - i) <= 1 or n == 0:
if n + i != 0:
q.append(n + i)
cnt += 1
if cnt == K:
print((n + i))
exit()
| false | 11.111111 | [
"-ans = []",
"- a = q.popleft()",
"- r = a % 10",
"- a *= 10",
"+ n = q.popleft()",
"+ r = n % 10",
"+ n *= 10",
"- if abs(r - i) <= 1 or a == 0:",
"- if cnt < K and a + i != 0:",
"- q.append(a + i)",
"- ans.append(a + i)",
"+ if abs(r - i) <= 1 or n == 0:",
"+ if n + i != 0:",
"+ q.append(n + i)",
"-print((ans[-1]))",
"+ if cnt == K:",
"+ print((n + i))",
"+ exit()"
] | false | 0.102338 | 0.048962 | 2.090152 | [
"s568840547",
"s580228731"
] |
u523130469 | p02813 | python | s051695383 | s346848636 | 262 | 193 | 46,448 | 38,896 | Accepted | Accepted | 26.34 | import itertools
n = int(input().strip())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
p_cnt = 0
q_cnt = 0
for i, e in enumerate(sorted(list(itertools.permutations(p)))):
if p == e:
p_cnt = i
if q == e:
q_cnt = i
print((abs(p_cnt - q_cnt)))
| from itertools import permutations as perms
n = int(input().strip())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
lis = [(i + 1) for i in range(n)]
a = -1
b = -1
cnt = 0
for elem in perms(lis, n):
cnt += 1
if elem == p:
a = cnt
if elem == q:
b = cnt
if a != -1 and b != -1:
break
print((abs(a - b)))
| 13 | 18 | 305 | 385 | import itertools
n = int(input().strip())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
p_cnt = 0
q_cnt = 0
for i, e in enumerate(sorted(list(itertools.permutations(p)))):
if p == e:
p_cnt = i
if q == e:
q_cnt = i
print((abs(p_cnt - q_cnt)))
| from itertools import permutations as perms
n = int(input().strip())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
lis = [(i + 1) for i in range(n)]
a = -1
b = -1
cnt = 0
for elem in perms(lis, n):
cnt += 1
if elem == p:
a = cnt
if elem == q:
b = cnt
if a != -1 and b != -1:
break
print((abs(a - b)))
| false | 27.777778 | [
"-import itertools",
"+from itertools import permutations as perms",
"-p_cnt = 0",
"-q_cnt = 0",
"-for i, e in enumerate(sorted(list(itertools.permutations(p)))):",
"- if p == e:",
"- p_cnt = i",
"- if q == e:",
"- q_cnt = i",
"-print((abs(p_cnt - q_cnt)))",
"+lis = [(i + 1) for i in range(n)]",
"+a = -1",
"+b = -1",
"+cnt = 0",
"+for elem in perms(lis, n):",
"+ cnt += 1",
"+ if elem == p:",
"+ a = cnt",
"+ if elem == q:",
"+ b = cnt",
"+ if a != -1 and b != -1:",
"+ break",
"+print((abs(a - b)))"
] | false | 0.045584 | 0.251798 | 0.181036 | [
"s051695383",
"s346848636"
] |
u340781749 | p03033 | python | s804087666 | s988694759 | 1,409 | 1,168 | 131,248 | 99,400 | Accepted | Accepted | 17.1 | import sys
from heapq import heappop, heappush
n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
events = []
kkk = []
for line in lines[:n]:
s, t, x = list(map(int, line.split()))
events.append((s - x, 2, x))
events.append((t - x, 1, x))
for line in lines[n:]:
events.append((int(line), 3))
events.sort()
constructing = []
available = set()
buf = []
for ev in events:
if ev[1] == 2:
heappush(constructing, ev[2])
available.add(ev[2])
elif ev[1] == 1:
available.remove(ev[2])
else:
if not available:
buf.append(-1)
else:
while constructing[0] not in available:
heappop(constructing)
buf.append(constructing[0])
print(('\n'.join(map(str, buf))))
| import sys
from bisect import bisect_left
n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
s, t, x = list(map(int, line.split()))
kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[n:]))
ans = [-1] * q
skip = [-1] * q
for x, s, t in kkk:
ss = bisect_left(ddd, s - x)
tt = bisect_left(ddd, t - x)
while ss < tt:
sk = skip[ss]
if sk == -1:
ans[ss] = x
skip[ss] = tt
ss += 1
else:
skip[ss] = max(sk, tt)
ss = sk
print(('\n'.join(map(str, ans))))
| 32 | 27 | 802 | 621 | import sys
from heapq import heappop, heappush
n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
events = []
kkk = []
for line in lines[:n]:
s, t, x = list(map(int, line.split()))
events.append((s - x, 2, x))
events.append((t - x, 1, x))
for line in lines[n:]:
events.append((int(line), 3))
events.sort()
constructing = []
available = set()
buf = []
for ev in events:
if ev[1] == 2:
heappush(constructing, ev[2])
available.add(ev[2])
elif ev[1] == 1:
available.remove(ev[2])
else:
if not available:
buf.append(-1)
else:
while constructing[0] not in available:
heappop(constructing)
buf.append(constructing[0])
print(("\n".join(map(str, buf))))
| import sys
from bisect import bisect_left
n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
s, t, x = list(map(int, line.split()))
kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[n:]))
ans = [-1] * q
skip = [-1] * q
for x, s, t in kkk:
ss = bisect_left(ddd, s - x)
tt = bisect_left(ddd, t - x)
while ss < tt:
sk = skip[ss]
if sk == -1:
ans[ss] = x
skip[ss] = tt
ss += 1
else:
skip[ss] = max(sk, tt)
ss = sk
print(("\n".join(map(str, ans))))
| false | 15.625 | [
"-from heapq import heappop, heappush",
"+from bisect import bisect_left",
"-events = []",
"- events.append((s - x, 2, x))",
"- events.append((t - x, 1, x))",
"-for line in lines[n:]:",
"- events.append((int(line), 3))",
"-events.sort()",
"-constructing = []",
"-available = set()",
"-buf = []",
"-for ev in events:",
"- if ev[1] == 2:",
"- heappush(constructing, ev[2])",
"- available.add(ev[2])",
"- elif ev[1] == 1:",
"- available.remove(ev[2])",
"- else:",
"- if not available:",
"- buf.append(-1)",
"+ kkk.append((x, s, t))",
"+kkk.sort()",
"+ddd = list(map(int, lines[n:]))",
"+ans = [-1] * q",
"+skip = [-1] * q",
"+for x, s, t in kkk:",
"+ ss = bisect_left(ddd, s - x)",
"+ tt = bisect_left(ddd, t - x)",
"+ while ss < tt:",
"+ sk = skip[ss]",
"+ if sk == -1:",
"+ ans[ss] = x",
"+ skip[ss] = tt",
"+ ss += 1",
"- while constructing[0] not in available:",
"- heappop(constructing)",
"- buf.append(constructing[0])",
"-print((\"\\n\".join(map(str, buf))))",
"+ skip[ss] = max(sk, tt)",
"+ ss = sk",
"+print((\"\\n\".join(map(str, ans))))"
] | false | 0.039291 | 0.101053 | 0.388817 | [
"s804087666",
"s988694759"
] |
u684241248 | p02265 | python | s074255160 | s668756960 | 2,190 | 1,770 | 69,812 | 69,812 | Accepted | Accepted | 19.18 | import sys
from collections import deque
n = int(eval(input()))
ary = deque([])
for line in sys.stdin:
op = line.strip().split()
cmd = op[0]
if cmd[0] == 'i':
x = op[1]
ary.appendleft(x)
elif len(cmd) == 6:
x = op[1]
if x in ary:
ary.remove(x)
elif len(cmd) == 10:
ary.pop()
else:
ary.popleft()
print((*ary))
| import sys
from collections import deque
n = int(eval(input()))
ary = deque([])
for line in sys.stdin:
op = line.strip().split()
cmd = op[0]
if cmd == 'insert':
x = op[1]
ary.appendleft(x)
elif cmd == 'delete':
x = op[1]
if x in ary:
ary.remove(x)
elif cmd == 'deleteLast':
ary.pop()
else:
ary.popleft()
print((*ary))
| 27 | 27 | 419 | 428 | import sys
from collections import deque
n = int(eval(input()))
ary = deque([])
for line in sys.stdin:
op = line.strip().split()
cmd = op[0]
if cmd[0] == "i":
x = op[1]
ary.appendleft(x)
elif len(cmd) == 6:
x = op[1]
if x in ary:
ary.remove(x)
elif len(cmd) == 10:
ary.pop()
else:
ary.popleft()
print((*ary))
| import sys
from collections import deque
n = int(eval(input()))
ary = deque([])
for line in sys.stdin:
op = line.strip().split()
cmd = op[0]
if cmd == "insert":
x = op[1]
ary.appendleft(x)
elif cmd == "delete":
x = op[1]
if x in ary:
ary.remove(x)
elif cmd == "deleteLast":
ary.pop()
else:
ary.popleft()
print((*ary))
| false | 0 | [
"- if cmd[0] == \"i\":",
"+ if cmd == \"insert\":",
"- elif len(cmd) == 6:",
"+ elif cmd == \"delete\":",
"- elif len(cmd) == 10:",
"+ elif cmd == \"deleteLast\":"
] | false | 0.035533 | 0.037236 | 0.954274 | [
"s074255160",
"s668756960"
] |
u943057856 | p02813 | python | s405807485 | s080935370 | 49 | 30 | 8,308 | 8,308 | Accepted | Accepted | 38.78 | import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
n_list = [i for i in range(1,N+1)]
n_perm = sorted(list(itertools.permutations(n_list, N)))
a = 0
b = 0
for i in range(len(n_perm)):
if list(n_perm[i]) == P:
a = i
break
for k in range(len(n_perm)):
if list(n_perm[k]) == Q:
b = k
break
print((abs(a-b))) | import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=sorted(list(itertools.permutations(list(range(1,n+1)))))
print((abs(l.index(p)-l.index(q))))
| 20 | 6 | 429 | 192 | import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
n_list = [i for i in range(1, N + 1)]
n_perm = sorted(list(itertools.permutations(n_list, N)))
a = 0
b = 0
for i in range(len(n_perm)):
if list(n_perm[i]) == P:
a = i
break
for k in range(len(n_perm)):
if list(n_perm[k]) == Q:
b = k
break
print((abs(a - b)))
| import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = sorted(list(itertools.permutations(list(range(1, n + 1)))))
print((abs(l.index(p) - l.index(q))))
| false | 70 | [
"-N = int(eval(input()))",
"-P = list(map(int, input().split()))",
"-Q = list(map(int, input().split()))",
"-n_list = [i for i in range(1, N + 1)]",
"-n_perm = sorted(list(itertools.permutations(n_list, N)))",
"-a = 0",
"-b = 0",
"-for i in range(len(n_perm)):",
"- if list(n_perm[i]) == P:",
"- a = i",
"- break",
"-for k in range(len(n_perm)):",
"- if list(n_perm[k]) == Q:",
"- b = k",
"- break",
"-print((abs(a - b)))",
"+n = int(eval(input()))",
"+p = tuple(map(int, input().split()))",
"+q = tuple(map(int, input().split()))",
"+l = sorted(list(itertools.permutations(list(range(1, n + 1)))))",
"+print((abs(l.index(p) - l.index(q))))"
] | false | 0.04854 | 0.039243 | 1.2369 | [
"s405807485",
"s080935370"
] |
u439396449 | p03488 | python | s417722837 | s170505553 | 1,957 | 384 | 3,936 | 48,860 | Accepted | Accepted | 80.38 | from collections import defaultdict
s = eval(input())
x, y = list(map(int, input().split()))
d = [len(x) for x in s.split('T')]
dx = d[0::2]
n_dx = len(dx)
dp = {0}
for i in range(n_dx):
tmp = set()
for j in dp:
if i == 0:
tmp.add(j + dx[i])
else:
tmp.add(j - dx[i])
tmp.add(j + dx[i])
dp = tmp
x_flag = x in dp
dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
tmp = set()
for j in dp:
tmp.add(j - dy[i])
tmp.add(j + dy[i])
dp = tmp
y_flag = y in dp
if x_flag and y_flag:
print('Yes')
else:
print('No') | from collections import defaultdict
s = eval(input())
x, y = list(map(int, input().split()))
d = [len(x) for x in s.split('T')]
dx = d[2::2]
n_dx = len(dx)
dp = {d[0]}
for i in range(n_dx):
tmp = set()
for j in dp:
tmp.add(j - dx[i])
tmp.add(j + dx[i])
dp = tmp
x_flag = x in dp
dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
tmp = set()
for j in dp:
tmp.add(j - dy[i])
tmp.add(j + dy[i])
dp = tmp
y_flag = y in dp
if x_flag and y_flag:
print('Yes')
else:
print('No')
| 36 | 33 | 640 | 569 | from collections import defaultdict
s = eval(input())
x, y = list(map(int, input().split()))
d = [len(x) for x in s.split("T")]
dx = d[0::2]
n_dx = len(dx)
dp = {0}
for i in range(n_dx):
tmp = set()
for j in dp:
if i == 0:
tmp.add(j + dx[i])
else:
tmp.add(j - dx[i])
tmp.add(j + dx[i])
dp = tmp
x_flag = x in dp
dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
tmp = set()
for j in dp:
tmp.add(j - dy[i])
tmp.add(j + dy[i])
dp = tmp
y_flag = y in dp
if x_flag and y_flag:
print("Yes")
else:
print("No")
| from collections import defaultdict
s = eval(input())
x, y = list(map(int, input().split()))
d = [len(x) for x in s.split("T")]
dx = d[2::2]
n_dx = len(dx)
dp = {d[0]}
for i in range(n_dx):
tmp = set()
for j in dp:
tmp.add(j - dx[i])
tmp.add(j + dx[i])
dp = tmp
x_flag = x in dp
dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
tmp = set()
for j in dp:
tmp.add(j - dy[i])
tmp.add(j + dy[i])
dp = tmp
y_flag = y in dp
if x_flag and y_flag:
print("Yes")
else:
print("No")
| false | 8.333333 | [
"-dx = d[0::2]",
"+dx = d[2::2]",
"-dp = {0}",
"+dp = {d[0]}",
"- if i == 0:",
"- tmp.add(j + dx[i])",
"- else:",
"- tmp.add(j - dx[i])",
"- tmp.add(j + dx[i])",
"+ tmp.add(j - dx[i])",
"+ tmp.add(j + dx[i])"
] | false | 0.082683 | 0.08702 | 0.950158 | [
"s417722837",
"s170505553"
] |
u489959379 | p02588 | python | s136274637 | s936679389 | 1,172 | 170 | 9,172 | 95,404 | Accepted | Accepted | 85.49 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
MAX = 50
def resolve():
n = int(eval(input()))
D = [[0] * MAX for _ in range(MAX)]
for _ in range(n):
a = int(round(float(eval(input())) * 10 ** 9))
t = a
x = 0
while t % 2 == 0:
t //= 2
x += 1
t = a
y = 0
while t % 5 == 0:
t //= 5
y += 1
D[x][y] += 1
res = 0
for x1 in range(MAX):
for y1 in range(MAX):
for x2 in range(max(0, 18 - x1), MAX):
for y2 in range(max(0, 18 - y1), MAX):
if x1 == x2 and y1 == y2:
res += D[x1][y1] * (D[x1][y1] - 1)
else:
res += D[x1][y1] * D[x2][y2]
print((res // 2))
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 998244353
def resolve():
n = int(eval(input()))
A = []
for _ in range(n):
a = float(eval(input()))
a = round(a * 10 ** 9 + 0.1)
A.append(a)
L = [[0] * 25 for _ in range(45)]
D = []
for a in A:
tmp = a
ex2 = ex5 = 0
while tmp % 2 == 0:
tmp //= 2
ex2 += 1
tmp = a
while tmp % 5 == 0:
tmp //= 5
ex5 += 1
L[ex2][ex5] += 1
D.append((ex2, ex5))
res = 0
check = [[False] * 25 for _ in range(45)]
for i in range(45):
for j in range(25):
if L[i][j] == 0:
check[i][j] = True
continue
for k in range(18 - i, 45):
for l in range(18 - j, 25):
if check[k][l]:
continue
if k == i and l == j:
res += L[i][j] * (L[k][l] - 1) // 2
else:
res += L[i][j] * L[k][l]
check[i][j] = True
print(res)
if __name__ == '__main__':
resolve()
| 41 | 52 | 938 | 1,249 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
MAX = 50
def resolve():
n = int(eval(input()))
D = [[0] * MAX for _ in range(MAX)]
for _ in range(n):
a = int(round(float(eval(input())) * 10**9))
t = a
x = 0
while t % 2 == 0:
t //= 2
x += 1
t = a
y = 0
while t % 5 == 0:
t //= 5
y += 1
D[x][y] += 1
res = 0
for x1 in range(MAX):
for y1 in range(MAX):
for x2 in range(max(0, 18 - x1), MAX):
for y2 in range(max(0, 18 - y1), MAX):
if x1 == x2 and y1 == y2:
res += D[x1][y1] * (D[x1][y1] - 1)
else:
res += D[x1][y1] * D[x2][y2]
print((res // 2))
if __name__ == "__main__":
resolve()
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 998244353
def resolve():
n = int(eval(input()))
A = []
for _ in range(n):
a = float(eval(input()))
a = round(a * 10**9 + 0.1)
A.append(a)
L = [[0] * 25 for _ in range(45)]
D = []
for a in A:
tmp = a
ex2 = ex5 = 0
while tmp % 2 == 0:
tmp //= 2
ex2 += 1
tmp = a
while tmp % 5 == 0:
tmp //= 5
ex5 += 1
L[ex2][ex5] += 1
D.append((ex2, ex5))
res = 0
check = [[False] * 25 for _ in range(45)]
for i in range(45):
for j in range(25):
if L[i][j] == 0:
check[i][j] = True
continue
for k in range(18 - i, 45):
for l in range(18 - j, 25):
if check[k][l]:
continue
if k == i and l == j:
res += L[i][j] * (L[k][l] - 1) // 2
else:
res += L[i][j] * L[k][l]
check[i][j] = True
print(res)
if __name__ == "__main__":
resolve()
| false | 21.153846 | [
"-mod = 10**9 + 7",
"-MAX = 50",
"+mod = 998244353",
"- D = [[0] * MAX for _ in range(MAX)]",
"+ A = []",
"- a = int(round(float(eval(input())) * 10**9))",
"- t = a",
"- x = 0",
"- while t % 2 == 0:",
"- t //= 2",
"- x += 1",
"- t = a",
"- y = 0",
"- while t % 5 == 0:",
"- t //= 5",
"- y += 1",
"- D[x][y] += 1",
"+ a = float(eval(input()))",
"+ a = round(a * 10**9 + 0.1)",
"+ A.append(a)",
"+ L = [[0] * 25 for _ in range(45)]",
"+ D = []",
"+ for a in A:",
"+ tmp = a",
"+ ex2 = ex5 = 0",
"+ while tmp % 2 == 0:",
"+ tmp //= 2",
"+ ex2 += 1",
"+ tmp = a",
"+ while tmp % 5 == 0:",
"+ tmp //= 5",
"+ ex5 += 1",
"+ L[ex2][ex5] += 1",
"+ D.append((ex2, ex5))",
"- for x1 in range(MAX):",
"- for y1 in range(MAX):",
"- for x2 in range(max(0, 18 - x1), MAX):",
"- for y2 in range(max(0, 18 - y1), MAX):",
"- if x1 == x2 and y1 == y2:",
"- res += D[x1][y1] * (D[x1][y1] - 1)",
"+ check = [[False] * 25 for _ in range(45)]",
"+ for i in range(45):",
"+ for j in range(25):",
"+ if L[i][j] == 0:",
"+ check[i][j] = True",
"+ continue",
"+ for k in range(18 - i, 45):",
"+ for l in range(18 - j, 25):",
"+ if check[k][l]:",
"+ continue",
"+ if k == i and l == j:",
"+ res += L[i][j] * (L[k][l] - 1) // 2",
"- res += D[x1][y1] * D[x2][y2]",
"- print((res // 2))",
"+ res += L[i][j] * L[k][l]",
"+ check[i][j] = True",
"+ print(res)"
] | false | 0.999847 | 0.091032 | 10.9835 | [
"s136274637",
"s936679389"
] |
u244416763 | p03592 | python | s953247326 | s350822920 | 286 | 255 | 17,908 | 9,188 | Accepted | Accepted | 10.84 | n, m, k = list(map(int, input().split()))
s = [[0 for i in range(n)]for j in range(m)]
for i in range(n+1):
for j in range(m+1):
if (i*m + j*n - 2*i*j) == k:
print("Yes")
exit()
print("No") | n, m, k = list(map(int, input().split()))
for i in range(n+1):
for j in range(m+1):
if (i*m + j*n - 2*i*j) == k:
print("Yes")
exit()
print("No") | 8 | 7 | 226 | 180 | n, m, k = list(map(int, input().split()))
s = [[0 for i in range(n)] for j in range(m)]
for i in range(n + 1):
for j in range(m + 1):
if (i * m + j * n - 2 * i * j) == k:
print("Yes")
exit()
print("No")
| n, m, k = list(map(int, input().split()))
for i in range(n + 1):
for j in range(m + 1):
if (i * m + j * n - 2 * i * j) == k:
print("Yes")
exit()
print("No")
| false | 12.5 | [
"-s = [[0 for i in range(n)] for j in range(m)]"
] | false | 0.045273 | 0.044343 | 1.020958 | [
"s953247326",
"s350822920"
] |
u780698286 | p02658 | python | s287067586 | s454652369 | 805 | 59 | 21,648 | 21,476 | Accepted | Accepted | 92.67 | # coding: utf-8
a = int(eval(input()))
b = list(map(int, input().split()))
c = 1
if 0 in b:
print((0))
else:
while c < 10 ** 18 and len(b) != 0:
c = c * b[0]
del b[0]
if c > 10 ** 18:
print((-1))
else:
print(c) | import sys
num = int(eval(input()))
a = list(map(int, input().split()))
b = 1
if 0 in a:
print((0))
sys.exit()
for i in a:
if b * i > 10 ** 18:
print((-1))
sys.exit()
else:
b *= i
print(b) | 14 | 15 | 239 | 217 | # coding: utf-8
a = int(eval(input()))
b = list(map(int, input().split()))
c = 1
if 0 in b:
print((0))
else:
while c < 10**18 and len(b) != 0:
c = c * b[0]
del b[0]
if c > 10**18:
print((-1))
else:
print(c)
| import sys
num = int(eval(input()))
a = list(map(int, input().split()))
b = 1
if 0 in a:
print((0))
sys.exit()
for i in a:
if b * i > 10**18:
print((-1))
sys.exit()
else:
b *= i
print(b)
| false | 6.666667 | [
"-# coding: utf-8",
"-a = int(eval(input()))",
"-b = list(map(int, input().split()))",
"-c = 1",
"-if 0 in b:",
"+import sys",
"+",
"+num = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+b = 1",
"+if 0 in a:",
"-else:",
"- while c < 10**18 and len(b) != 0:",
"- c = c * b[0]",
"- del b[0]",
"- if c > 10**18:",
"+ sys.exit()",
"+for i in a:",
"+ if b * i > 10**18:",
"+ sys.exit()",
"- print(c)",
"+ b *= i",
"+print(b)"
] | false | 0.108255 | 0.036748 | 2.945864 | [
"s287067586",
"s454652369"
] |
u614181788 | p02657 | python | s534974797 | s293195683 | 23 | 20 | 9,156 | 8,944 | Accepted | Accepted | 13.04 | a,b = list(map(int,input().split()))
print((a*b)) | a,b = list(map(float,input().split()))
b = 100*b + 0.0000001
print((round((a*b)/100))) | 2 | 3 | 42 | 80 | a, b = list(map(int, input().split()))
print((a * b))
| a, b = list(map(float, input().split()))
b = 100 * b + 0.0000001
print((round((a * b) / 100)))
| false | 33.333333 | [
"-a, b = list(map(int, input().split()))",
"-print((a * b))",
"+a, b = list(map(float, input().split()))",
"+b = 100 * b + 0.0000001",
"+print((round((a * b) / 100)))"
] | false | 0.08097 | 0.038083 | 2.126137 | [
"s534974797",
"s293195683"
] |
u261260430 | p02955 | python | s197221708 | s833103055 | 271 | 146 | 3,188 | 3,188 | Accepted | Accepted | 46.13 | import sys
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
def ok(x):
b = []
for an in a:
b.append(an % x)
b.sort(reverse=True)
print(x, a, b, file=sys.stderr)
t = int(sum(b) / x)
print(t, sum(b[t:]), file=sys.stderr)
if t == 0:
return True
return True if sum(b[t:]) <= k else False
s = 0
for an in a:
s += an
ans = 1
for x in range(1, int(math.sqrt(s)) + 1):
if s % x != 0:
continue
if ok(x):
ans = max(ans, x)
if ok(int(s / x)):
ans = max(ans, int(s / x))
print(ans)
| import sys
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def ok(x):
b = [i % x for i in a]
b.sort(reverse=True)
t = int(sum(b) / x)
if t == 0:
return True
return True if sum(b[t:]) <= k else False
s = sum(a)
sqs = int(math.sqrt(s))
ans = 1
for x in range(1, sqs + 1):
if s % x != 0:
continue
if ok(x):
ans = max(ans, x)
if ok(int(s / x)):
ans = max(ans, int(s / x))
print(ans)
| 34 | 28 | 630 | 509 | import sys
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
def ok(x):
b = []
for an in a:
b.append(an % x)
b.sort(reverse=True)
print(x, a, b, file=sys.stderr)
t = int(sum(b) / x)
print(t, sum(b[t:]), file=sys.stderr)
if t == 0:
return True
return True if sum(b[t:]) <= k else False
s = 0
for an in a:
s += an
ans = 1
for x in range(1, int(math.sqrt(s)) + 1):
if s % x != 0:
continue
if ok(x):
ans = max(ans, x)
if ok(int(s / x)):
ans = max(ans, int(s / x))
print(ans)
| import sys
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def ok(x):
b = [i % x for i in a]
b.sort(reverse=True)
t = int(sum(b) / x)
if t == 0:
return True
return True if sum(b[t:]) <= k else False
s = sum(a)
sqs = int(math.sqrt(s))
ans = 1
for x in range(1, sqs + 1):
if s % x != 0:
continue
if ok(x):
ans = max(ans, x)
if ok(int(s / x)):
ans = max(ans, int(s / x))
print(ans)
| false | 17.647059 | [
"-n, k = map(int, input().split())",
"+n, k = list(map(int, input().split()))",
"- b = []",
"- for an in a:",
"- b.append(an % x)",
"+ b = [i % x for i in a]",
"- print(x, a, b, file=sys.stderr)",
"- print(t, sum(b[t:]), file=sys.stderr)",
"-s = 0",
"-for an in a:",
"- s += an",
"+s = sum(a)",
"+sqs = int(math.sqrt(s))",
"-for x in range(1, int(math.sqrt(s)) + 1):",
"+for x in range(1, sqs + 1):"
] | false | 0.041282 | 0.040748 | 1.013115 | [
"s197221708",
"s833103055"
] |
u241159583 | p03319 | python | s364103173 | s309101166 | 44 | 40 | 13,880 | 13,812 | Accepted | Accepted | 9.09 | N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
n = N - K
if n % (K - 1) == 0:
ans = 1 + n // (K - 1)
else:
ans = 2 + n // (K - 1)
print(ans) | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
n = N - K
if n % (K - 1) == 0:
ans = 1 + n // (K - 1)
else:
ans = 2 + n // (K - 1)
print(ans) | 9 | 8 | 177 | 173 | N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
n = N - K
if n % (K - 1) == 0:
ans = 1 + n // (K - 1)
else:
ans = 2 + n // (K - 1)
print(ans)
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
n = N - K
if n % (K - 1) == 0:
ans = 1 + n // (K - 1)
else:
ans = 2 + n // (K - 1)
print(ans)
| false | 11.111111 | [
"-A = [int(x) for x in input().split()]",
"+A = list(map(int, input().split()))"
] | false | 0.104277 | 0.031969 | 3.261793 | [
"s364103173",
"s309101166"
] |