user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u562935282 | p02953 | python | s484854769 | s509155782 | 87 | 48 | 14,252 | 14,396 | Accepted | Accepted | 44.83 | n = int(eval(input()))
h = list(map(int, input().split()))
cur = h[-1]
i = n - 2
flg = True
while i >= 0:
if h[i] <= cur + 1:
cur = min(cur, h[i])
else:
flg = False
break
i -= 1
print(('Yes' if flg else 'No'))
| def main():
N = int(eval(input()))
*H, = list(map(int, input().split()))
cond = True
p = H[0] - 1
for h in H[1:]:
if p < h:
p = h - 1
elif p == h:
pass
else:
cond = False
break
print(('Yes' if cond else 'No'))
if __name__ == '__main__':
main()
| 15 | 20 | 254 | 353 | n = int(eval(input()))
h = list(map(int, input().split()))
cur = h[-1]
i = n - 2
flg = True
while i >= 0:
if h[i] <= cur + 1:
cur = min(cur, h[i])
else:
flg = False
break
i -= 1
print(("Yes" if flg else "No"))
| def main():
N = int(eval(input()))
(*H,) = list(map(int, input().split()))
cond = True
p = H[0] - 1
for h in H[1:]:
if p < h:
p = h - 1
elif p == h:
pass
else:
cond = False
break
print(("Yes" if cond else "No"))
if __name__ == "__main__":
main()
| false | 25 | [
"-n = int(eval(input()))",
"-h = list(map(int, input().split()))",
"-cur = h[-1]",
"-i = n - 2",
"-flg = True",
"-while i >= 0:",
"- if h[i] <= cur + 1:",
"- cur = min(cur, h[i])",
"- else:",
"- flg = False",
"- break",
"- i -= 1",
"-print((\"Yes\" if flg else \"No\"))",
"+def main():",
"+ N = int(eval(input()))",
"+ (*H,) = list(map(int, input().split()))",
"+ cond = True",
"+ p = H[0] - 1",
"+ for h in H[1:]:",
"+ if p < h:",
"+ p = h - 1",
"+ elif p == h:",
"+ pass",
"+ else:",
"+ cond = False",
"+ break",
"+ print((\"Yes\" if cond else \"No\"))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.1014 | 0.082071 | 1.235525 | [
"s484854769",
"s509155782"
]
|
u724687935 | p02537 | python | s814855621 | s249850911 | 1,097 | 714 | 142,888 | 140,088 | Accepted | Accepted | 34.91 | class SegmentTree():
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while (l < r):
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([N] * (max_A + 1), min, N)
dp = [0] * (N + 1)
for i, a in enumerate(reversed(A)):
j = N - 1 - i
p1 = st.get(a, min(max_A + 1, a + K + 1))
dp[j] = max(dp[p1] + 1, dp[j])
p2 = st.get(max(0, a - K), a)
dp[j] = max(dp[p2] + 1, dp[j])
st.update(a, j)
print((max(dp)))
| class SegmentTree():
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while (l < r):
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([0] * (max_A + 1), max, 0)
for i, a in enumerate(A):
l = max(0, a - K)
r = min(max_A, a + K)
ns = st.get(l, r + 1)
st.update(a, ns + 1)
print((st.get(0, max_A + 1)))
| 75 | 72 | 1,850 | 1,742 | class SegmentTree:
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while l < r:
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([N] * (max_A + 1), min, N)
dp = [0] * (N + 1)
for i, a in enumerate(reversed(A)):
j = N - 1 - i
p1 = st.get(a, min(max_A + 1, a + K + 1))
dp[j] = max(dp[p1] + 1, dp[j])
p2 = st.get(max(0, a - K), a)
dp[j] = max(dp[p2] + 1, dp[j])
st.update(a, j)
print((max(dp)))
| class SegmentTree:
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while l < r:
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([0] * (max_A + 1), max, 0)
for i, a in enumerate(A):
l = max(0, a - K)
r = min(max_A, a + K)
ns = st.get(l, r + 1)
st.update(a, ns + 1)
print((st.get(0, max_A + 1)))
| false | 4 | [
"-st = SegmentTree([N] * (max_A + 1), min, N)",
"-dp = [0] * (N + 1)",
"-for i, a in enumerate(reversed(A)):",
"- j = N - 1 - i",
"- p1 = st.get(a, min(max_A + 1, a + K + 1))",
"- dp[j] = max(dp[p1] + 1, dp[j])",
"- p2 = st.get(max(0, a - K), a)",
"- dp[j] = max(dp[p2] + 1, dp[j])",
"- st.update(a, j)",
"-print((max(dp)))",
"+st = SegmentTree([0] * (max_A + 1), max, 0)",
"+for i, a in enumerate(A):",
"+ l = max(0, a - K)",
"+ r = min(max_A, a + K)",
"+ ns = st.get(l, r + 1)",
"+ st.update(a, ns + 1)",
"+print((st.get(0, max_A + 1)))"
]
| false | 0.036577 | 0.03692 | 0.990719 | [
"s814855621",
"s249850911"
]
|
u562935282 | p02861 | python | s051624200 | s778342314 | 294 | 21 | 3,572 | 3,444 | Accepted | Accepted | 92.86 | def main():
from collections import namedtuple
from itertools import permutations
from math import factorial
City = namedtuple('City', 'x y')
def dist(a: City, b: City) -> float:
dx = a.x - b.x
dy = a.y - b.y
return (dx * dx + dy * dy) ** 0.5
N = int(eval(input()))
cities = []
for _ in range(N):
x, y = list(map(int, input().split()))
c = City(x=x, y=y)
cities.append(c)
total = 0
for perm in permutations(cities):
it = iter(perm)
p = next(it)
for city in it:
total += dist(p, city)
p = city
ans = total / factorial(N)
print(ans)
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| def main():
from collections import namedtuple
from itertools import combinations
City = namedtuple('City', 'x y')
def dist(a: City, b: City) -> float:
dx = a.x - b.x
dy = a.y - b.y
return (dx * dx + dy * dy) ** 0.5
N = int(eval(input()))
cities = []
for _ in range(N):
x, y = list(map(int, input().split()))
c = City(x=x, y=y)
cities.append(c)
total = 0
for comb in combinations(cities, r=2):
total += dist(*comb)
ans = total * 2 / N
print(ans)
if __name__ == '__main__':
main()
# 特定の2点を固定し、それ以外を並べる + 固定順を逆にする
# [oo]ooo... これを4個の要素の並び替えを見なす
# (n-1)! * 2!
# この2点間の移動が含まれる並び順は、(n-1)! * 2!通り
# 各2点間の距離の総和*(n-1)! * 2!通り / n!
# 各2点間の距離の総和*2/n
| 44 | 36 | 887 | 776 | def main():
from collections import namedtuple
from itertools import permutations
from math import factorial
City = namedtuple("City", "x y")
def dist(a: City, b: City) -> float:
dx = a.x - b.x
dy = a.y - b.y
return (dx * dx + dy * dy) ** 0.5
N = int(eval(input()))
cities = []
for _ in range(N):
x, y = list(map(int, input().split()))
c = City(x=x, y=y)
cities.append(c)
total = 0
for perm in permutations(cities):
it = iter(perm)
p = next(it)
for city in it:
total += dist(p, city)
p = city
ans = total / factorial(N)
print(ans)
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| def main():
from collections import namedtuple
from itertools import combinations
City = namedtuple("City", "x y")
def dist(a: City, b: City) -> float:
dx = a.x - b.x
dy = a.y - b.y
return (dx * dx + dy * dy) ** 0.5
N = int(eval(input()))
cities = []
for _ in range(N):
x, y = list(map(int, input().split()))
c = City(x=x, y=y)
cities.append(c)
total = 0
for comb in combinations(cities, r=2):
total += dist(*comb)
ans = total * 2 / N
print(ans)
if __name__ == "__main__":
main()
# 特定の2点を固定し、それ以外を並べる + 固定順を逆にする
# [oo]ooo... これを4個の要素の並び替えを見なす
# (n-1)! * 2!
# この2点間の移動が含まれる並び順は、(n-1)! * 2!通り
# 各2点間の距離の総和*(n-1)! * 2!通り / n!
# 各2点間の距離の総和*2/n
| false | 18.181818 | [
"- from itertools import permutations",
"- from math import factorial",
"+ from itertools import combinations",
"- for perm in permutations(cities):",
"- it = iter(perm)",
"- p = next(it)",
"- for city in it:",
"- total += dist(p, city)",
"- p = city",
"- ans = total / factorial(N)",
"+ for comb in combinations(cities, r=2):",
"+ total += dist(*comb)",
"+ ans = total * 2 / N",
"-# import sys",
"-#",
"-# sys.setrecursionlimit(10 ** 7)",
"-#",
"-# input = sys.stdin.readline",
"-# rstrip()",
"-# int(input())",
"-# map(int, input().split())",
"+# 特定の2点を固定し、それ以外を並べる + 固定順を逆にする",
"+# [oo]ooo... これを4個の要素の並び替えを見なす",
"+# (n-1)! * 2!",
"+# この2点間の移動が含まれる並び順は、(n-1)! * 2!通り",
"+# 各2点間の距離の総和*(n-1)! * 2!通り / n!",
"+# 各2点間の距離の総和*2/n"
]
| false | 0.07196 | 0.040661 | 1.769773 | [
"s051624200",
"s778342314"
]
|
u848647227 | p04025 | python | s746820736 | s102608021 | 25 | 23 | 3,060 | 2,940 | Accepted | Accepted | 8 | a = int(eval(input()))
ar = list(map(int,input().split(" ")))
br = []
for i in range(min(ar),max(ar)+1):
count = 0
for r in ar:
count += (i - r) ** 2
br.append(count)
print((min(br))) | a = int(eval(input()))
ar = list(map(int,input().split(" ")))
b = 10 ** 9
for i in range(min(ar),max(ar) + 1):
count = 0
for r in ar:
count += (r - i) ** 2
if b > count:
b = count
print(b) | 9 | 10 | 203 | 219 | a = int(eval(input()))
ar = list(map(int, input().split(" ")))
br = []
for i in range(min(ar), max(ar) + 1):
count = 0
for r in ar:
count += (i - r) ** 2
br.append(count)
print((min(br)))
| a = int(eval(input()))
ar = list(map(int, input().split(" ")))
b = 10**9
for i in range(min(ar), max(ar) + 1):
count = 0
for r in ar:
count += (r - i) ** 2
if b > count:
b = count
print(b)
| false | 10 | [
"-br = []",
"+b = 10**9",
"- count += (i - r) ** 2",
"- br.append(count)",
"-print((min(br)))",
"+ count += (r - i) ** 2",
"+ if b > count:",
"+ b = count",
"+print(b)"
]
| false | 0.036224 | 0.035485 | 1.02083 | [
"s746820736",
"s102608021"
]
|
u743272507 | p02861 | python | s099096460 | s834806712 | 311 | 102 | 3,064 | 9,184 | Accepted | Accepted | 67.2 | import itertools
n = int(eval(input()))
point = []
for i in range(n):
a,b = list(map(float,input().split()))
point.append((a,b))
ans = 0.0
div = 0
for pm in itertools.permutations(point):
div += 1
for j in range(n-1):
ans += ((pm[j][0]-pm[j+1][0])**2 + (pm[j][1]-pm[j+1][1])**2) ** 0.5
print((ans / div)) | from itertools import permutations
from math import factorial
n = int(eval(input()))
town = [complex(*list(map(int,input().split()))) for _ in range(n)]
d = 0
for l in permutations(town):
for i in range(n-1):
d += abs(l[i]-l[i+1])
print((d/factorial(n))) | 13 | 9 | 314 | 254 | import itertools
n = int(eval(input()))
point = []
for i in range(n):
a, b = list(map(float, input().split()))
point.append((a, b))
ans = 0.0
div = 0
for pm in itertools.permutations(point):
div += 1
for j in range(n - 1):
ans += ((pm[j][0] - pm[j + 1][0]) ** 2 + (pm[j][1] - pm[j + 1][1]) ** 2) ** 0.5
print((ans / div))
| from itertools import permutations
from math import factorial
n = int(eval(input()))
town = [complex(*list(map(int, input().split()))) for _ in range(n)]
d = 0
for l in permutations(town):
for i in range(n - 1):
d += abs(l[i] - l[i + 1])
print((d / factorial(n)))
| false | 30.769231 | [
"-import itertools",
"+from itertools import permutations",
"+from math import factorial",
"-point = []",
"-for i in range(n):",
"- a, b = list(map(float, input().split()))",
"- point.append((a, b))",
"-ans = 0.0",
"-div = 0",
"-for pm in itertools.permutations(point):",
"- div += 1",
"- for j in range(n - 1):",
"- ans += ((pm[j][0] - pm[j + 1][0]) ** 2 + (pm[j][1] - pm[j + 1][1]) ** 2) ** 0.5",
"-print((ans / div))",
"+town = [complex(*list(map(int, input().split()))) for _ in range(n)]",
"+d = 0",
"+for l in permutations(town):",
"+ for i in range(n - 1):",
"+ d += abs(l[i] - l[i + 1])",
"+print((d / factorial(n)))"
]
| false | 0.038713 | 0.184734 | 0.209561 | [
"s099096460",
"s834806712"
]
|
u254871849 | p03325 | python | s830339629 | s696280742 | 73 | 65 | 4,084 | 4,212 | Accepted | Accepted | 10.96 | # author: kagemeka
# created: 2019-11-08 12:38:16(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special # if use comb function on AtCoder,
# import scipy.misc # select scipy.misc.comb (old version)
def main():
n, *a = (int(x) for x in sys.stdin.read().split())
total_count = 0
for i in range(n):
current = a[i]
count = 0
for _ in range(math.floor(math.log(10 ** 9, 2)) + 1):
if current % 2 == 0:
current //= 2
count += 1
else:
break
total_count += count
print(total_count)
if __name__ == "__main__":
# execute only if run as a script
main()
| # author: kagemeka
# created: 2019-11-08 12:38:16(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special # if use comb function on AtCoder,
# import scipy.misc # select scipy.misc.comb (old version)
def main():
n, *a = (int(x) for x in sys.stdin.read().split())
total_count = 0
atmost = math.floor(math.log(10 ** 9, 2))
for i in range(n):
current = a[i]
count = 0
for _ in range(atmost + 1):
if current % 2 == 0:
current //= 2
count += 1
else:
break
total_count += count
print(total_count)
if __name__ == "__main__":
# execute only if run as a script
main()
| 37 | 38 | 950 | 971 | # author: kagemeka
# created: 2019-11-08 12:38:16(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special # if use comb function on AtCoder,
# import scipy.misc # select scipy.misc.comb (old version)
def main():
n, *a = (int(x) for x in sys.stdin.read().split())
total_count = 0
for i in range(n):
current = a[i]
count = 0
for _ in range(math.floor(math.log(10**9, 2)) + 1):
if current % 2 == 0:
current //= 2
count += 1
else:
break
total_count += count
print(total_count)
if __name__ == "__main__":
# execute only if run as a script
main()
| # author: kagemeka
# created: 2019-11-08 12:38:16(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special # if use comb function on AtCoder,
# import scipy.misc # select scipy.misc.comb (old version)
def main():
n, *a = (int(x) for x in sys.stdin.read().split())
total_count = 0
atmost = math.floor(math.log(10**9, 2))
for i in range(n):
current = a[i]
count = 0
for _ in range(atmost + 1):
if current % 2 == 0:
current //= 2
count += 1
else:
break
total_count += count
print(total_count)
if __name__ == "__main__":
# execute only if run as a script
main()
| false | 2.631579 | [
"+ atmost = math.floor(math.log(10**9, 2))",
"- for _ in range(math.floor(math.log(10**9, 2)) + 1):",
"+ for _ in range(atmost + 1):"
]
| false | 0.061974 | 0.061872 | 1.001652 | [
"s830339629",
"s696280742"
]
|
u861141787 | p02784 | python | s547724131 | s847881321 | 64 | 41 | 13,964 | 13,964 | Accepted | Accepted | 35.94 | #import sys
h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
h -= a[i]
if h <= 0:
print("Yes")
exit()
#sys.exit(0)
print("No") | h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
if h <= sum(a):
print("Yes")
else:
print("No") | 12 | 7 | 211 | 124 | # import sys
h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
h -= a[i]
if h <= 0:
print("Yes")
exit()
# sys.exit(0)
print("No")
| h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
if h <= sum(a):
print("Yes")
else:
print("No")
| false | 41.666667 | [
"-# import sys",
"-for i in range(n):",
"- h -= a[i]",
"- if h <= 0:",
"- print(\"Yes\")",
"- exit()",
"- # sys.exit(0)",
"-print(\"No\")",
"+if h <= sum(a):",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
]
| false | 0.03618 | 0.036894 | 0.980648 | [
"s547724131",
"s847881321"
]
|
u310678820 | p03716 | python | s423630732 | s269665319 | 551 | 434 | 38,148 | 37,212 | Accepted | Accepted | 21.23 | import heapq
n= int(eval(input()))
a=[int(i) for i in input().split()]
heap1=[]
heap2=[]
a_max=[]
b_max=[]
s=0
for i in range(n):
heapq.heappush(heap1, a[i])
s+=a[i]
a_max.append(s)
for i in range(n):
heapq.heappush(heap1,a[n+i])
mini=heapq.heappop(heap1)
s=s+a[n+i]-mini
a_max.append(s)
s=0
for i in range(n):
heapq.heappush(heap2,-a[2*n+i])
s=s-a[2*n+i]
b_max.append(s)
for i in range(n):
heapq.heappush(heap2,-a[2*n-1-i])
mini=heapq.heappop(heap2)
s=s-a[2*n-1-i]-mini
b_max.append(s)
ans=a_max[0]+b_max[len(b_max)-1]
for i in range(n+1):
res=a_max[i]+b_max[-(i+1)]
ans=max(ans, res)
print(ans) | from heapq import heappush, heappop
n=int(eval(input()))
a=list(map(int, input().split()))
q1=[]
q2=[]
s1=[]
s2=[]
for i in range(n):
heappush(q1, a[i])
s1.append(sum(a[0:n]))
for ai in a[n:2*n]:
heappush(q1, ai)
m=heappop(q1)
s1.append(s1[-1]+ai-m)
a=a[::-1]
for i in range(n):
heappush(q2, -a[i])
s2.append(-sum(a[0:n]))
for ai in [-i for i in a[n:2*n]]:
heappush(q2, ai)
m=heappop(q2)
s2.append(s2[-1]+ai-m)
ans=s1[0]+s2[-1]
for i in range(n+1):
ans=max(s1[i]+s2[-i-1], ans)
print(ans) | 32 | 26 | 681 | 547 | import heapq
n = int(eval(input()))
a = [int(i) for i in input().split()]
heap1 = []
heap2 = []
a_max = []
b_max = []
s = 0
for i in range(n):
heapq.heappush(heap1, a[i])
s += a[i]
a_max.append(s)
for i in range(n):
heapq.heappush(heap1, a[n + i])
mini = heapq.heappop(heap1)
s = s + a[n + i] - mini
a_max.append(s)
s = 0
for i in range(n):
heapq.heappush(heap2, -a[2 * n + i])
s = s - a[2 * n + i]
b_max.append(s)
for i in range(n):
heapq.heappush(heap2, -a[2 * n - 1 - i])
mini = heapq.heappop(heap2)
s = s - a[2 * n - 1 - i] - mini
b_max.append(s)
ans = a_max[0] + b_max[len(b_max) - 1]
for i in range(n + 1):
res = a_max[i] + b_max[-(i + 1)]
ans = max(ans, res)
print(ans)
| from heapq import heappush, heappop
n = int(eval(input()))
a = list(map(int, input().split()))
q1 = []
q2 = []
s1 = []
s2 = []
for i in range(n):
heappush(q1, a[i])
s1.append(sum(a[0:n]))
for ai in a[n : 2 * n]:
heappush(q1, ai)
m = heappop(q1)
s1.append(s1[-1] + ai - m)
a = a[::-1]
for i in range(n):
heappush(q2, -a[i])
s2.append(-sum(a[0:n]))
for ai in [-i for i in a[n : 2 * n]]:
heappush(q2, ai)
m = heappop(q2)
s2.append(s2[-1] + ai - m)
ans = s1[0] + s2[-1]
for i in range(n + 1):
ans = max(s1[i] + s2[-i - 1], ans)
print(ans)
| false | 18.75 | [
"-import heapq",
"+from heapq import heappush, heappop",
"-a = [int(i) for i in input().split()]",
"-heap1 = []",
"-heap2 = []",
"-a_max = []",
"-b_max = []",
"-s = 0",
"+a = list(map(int, input().split()))",
"+q1 = []",
"+q2 = []",
"+s1 = []",
"+s2 = []",
"- heapq.heappush(heap1, a[i])",
"- s += a[i]",
"-a_max.append(s)",
"+ heappush(q1, a[i])",
"+s1.append(sum(a[0:n]))",
"+for ai in a[n : 2 * n]:",
"+ heappush(q1, ai)",
"+ m = heappop(q1)",
"+ s1.append(s1[-1] + ai - m)",
"+a = a[::-1]",
"- heapq.heappush(heap1, a[n + i])",
"- mini = heapq.heappop(heap1)",
"- s = s + a[n + i] - mini",
"- a_max.append(s)",
"-s = 0",
"-for i in range(n):",
"- heapq.heappush(heap2, -a[2 * n + i])",
"- s = s - a[2 * n + i]",
"-b_max.append(s)",
"-for i in range(n):",
"- heapq.heappush(heap2, -a[2 * n - 1 - i])",
"- mini = heapq.heappop(heap2)",
"- s = s - a[2 * n - 1 - i] - mini",
"- b_max.append(s)",
"-ans = a_max[0] + b_max[len(b_max) - 1]",
"+ heappush(q2, -a[i])",
"+s2.append(-sum(a[0:n]))",
"+for ai in [-i for i in a[n : 2 * n]]:",
"+ heappush(q2, ai)",
"+ m = heappop(q2)",
"+ s2.append(s2[-1] + ai - m)",
"+ans = s1[0] + s2[-1]",
"- res = a_max[i] + b_max[-(i + 1)]",
"- ans = max(ans, res)",
"+ ans = max(s1[i] + s2[-i - 1], ans)"
]
| false | 0.060146 | 0.042019 | 1.431381 | [
"s423630732",
"s269665319"
]
|
u941753895 | p02787 | python | s738720781 | s651309571 | 1,890 | 836 | 541,068 | 303,116 | Accepted | Accepted | 55.77 | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
p=20010
h,n=LI()
a=[]
b=[]
for _ in range(n):
x,y=LI()
a.append(x)
b.append(y)
dp=[[inf]*p for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(p-5):
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
if j+a[i]<p:
dp[i+1][j+a[i]]=min(dp[i+1][j+a[i]],dp[i+1][j]+b[i])
# print(dp)
ans=inf
for i in range(h,20010):
ans=min(ans,dp[n][i])
return ans
# main()
print((main()))
| import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
p=10005
h,n=LI()
a=[]
b=[]
for _ in range(n):
x,y=LI()
a.append(x)
b.append(y)
dp=[[inf]*(p+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(p):
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
if j+a[i]<p:
dp[i+1][j+a[i]]=min(dp[i+1][j+a[i]],dp[i+1][j]+b[i])
else:
dp[i+1][p]=min(dp[i+1][p],dp[i+1][j]+b[i])
# print(dp)
ans=inf
for i in range(h,p+1):
ans=min(ans,dp[n][i])
return ans
# main()
print((main()))
| 43 | 45 | 997 | 1,062 | import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
p = 20010
h, n = LI()
a = []
b = []
for _ in range(n):
x, y = LI()
a.append(x)
b.append(y)
dp = [[inf] * p for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(p - 5):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
if j + a[i] < p:
dp[i + 1][j + a[i]] = min(dp[i + 1][j + a[i]], dp[i + 1][j] + b[i])
# print(dp)
ans = inf
for i in range(h, 20010):
ans = min(ans, dp[n][i])
return ans
# main()
print((main()))
| import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
p = 10005
h, n = LI()
a = []
b = []
for _ in range(n):
x, y = LI()
a.append(x)
b.append(y)
dp = [[inf] * (p + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(p):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
if j + a[i] < p:
dp[i + 1][j + a[i]] = min(dp[i + 1][j + a[i]], dp[i + 1][j] + b[i])
else:
dp[i + 1][p] = min(dp[i + 1][p], dp[i + 1][j] + b[i])
# print(dp)
ans = inf
for i in range(h, p + 1):
ans = min(ans, dp[n][i])
return ans
# main()
print((main()))
| false | 4.444444 | [
"- p = 20010",
"+ p = 10005",
"- dp = [[inf] * p for _ in range(n + 1)]",
"+ dp = [[inf] * (p + 1) for _ in range(n + 1)]",
"- for j in range(p - 5):",
"+ for j in range(p):",
"+ else:",
"+ dp[i + 1][p] = min(dp[i + 1][p], dp[i + 1][j] + b[i])",
"- for i in range(h, 20010):",
"+ for i in range(h, p + 1):"
]
| false | 0.193811 | 0.379006 | 0.511366 | [
"s738720781",
"s651309571"
]
|
u191874006 | p03076 | python | s661164406 | s628884797 | 22 | 17 | 3,188 | 3,064 | Accepted | Accepted | 22.73 | #!/usr/bin/env python3
import re
a = []
b = []
for i in range(5):
x = int(eval(input()))
a.append(x)
x = x%10
b.append(x)
count = 0
min = 123
k = 0
for i in range(5):
if(b[i] != 0 and min > b[i]):
min = b[i]
k = i
for i in range(5):
if(i != k and b[i] != 0):
count += a[i] + 10 - b[i]
elif(i == k or b[i] == 0):
count += a[i]
print(count)
| #!/usr/bin/env python3
#ABC123 B
LI = [int(eval(input())) for _ in range(5)]
LI2 = [LI[i] % 10 for i in range(5)]
x = [(LI[i],LI2[i]) for i in range(5)]
#print(x)
ans = 0
x = sorted(x, key = lambda x:x[1],reverse = True)
for i in range(5):
if x[i][1] == 0:
t = x[i]
x.remove(t)
x.insert(0,t)
#print(x)
for i in range(4):
if x[i][1] != 0:
ans += x[i][0] + (10 - x[i][1])
else:
ans += x[i][0]
ans += x[4][0]
print(ans) | 25 | 25 | 420 | 490 | #!/usr/bin/env python3
import re
a = []
b = []
for i in range(5):
x = int(eval(input()))
a.append(x)
x = x % 10
b.append(x)
count = 0
min = 123
k = 0
for i in range(5):
if b[i] != 0 and min > b[i]:
min = b[i]
k = i
for i in range(5):
if i != k and b[i] != 0:
count += a[i] + 10 - b[i]
elif i == k or b[i] == 0:
count += a[i]
print(count)
| #!/usr/bin/env python3
# ABC123 B
LI = [int(eval(input())) for _ in range(5)]
LI2 = [LI[i] % 10 for i in range(5)]
x = [(LI[i], LI2[i]) for i in range(5)]
# print(x)
ans = 0
x = sorted(x, key=lambda x: x[1], reverse=True)
for i in range(5):
if x[i][1] == 0:
t = x[i]
x.remove(t)
x.insert(0, t)
# print(x)
for i in range(4):
if x[i][1] != 0:
ans += x[i][0] + (10 - x[i][1])
else:
ans += x[i][0]
ans += x[4][0]
print(ans)
| false | 0 | [
"-import re",
"-",
"-a = []",
"-b = []",
"+# ABC123 B",
"+LI = [int(eval(input())) for _ in range(5)]",
"+LI2 = [LI[i] % 10 for i in range(5)]",
"+x = [(LI[i], LI2[i]) for i in range(5)]",
"+# print(x)",
"+ans = 0",
"+x = sorted(x, key=lambda x: x[1], reverse=True)",
"- x = int(eval(input()))",
"- a.append(x)",
"- x = x % 10",
"- b.append(x)",
"-count = 0",
"-min = 123",
"-k = 0",
"-for i in range(5):",
"- if b[i] != 0 and min > b[i]:",
"- min = b[i]",
"- k = i",
"-for i in range(5):",
"- if i != k and b[i] != 0:",
"- count += a[i] + 10 - b[i]",
"- elif i == k or b[i] == 0:",
"- count += a[i]",
"-print(count)",
"+ if x[i][1] == 0:",
"+ t = x[i]",
"+ x.remove(t)",
"+ x.insert(0, t)",
"+# print(x)",
"+for i in range(4):",
"+ if x[i][1] != 0:",
"+ ans += x[i][0] + (10 - x[i][1])",
"+ else:",
"+ ans += x[i][0]",
"+ans += x[4][0]",
"+print(ans)"
]
| false | 0.047694 | 0.2033 | 0.234597 | [
"s661164406",
"s628884797"
]
|
u489124637 | p03012 | python | s780503461 | s611546412 | 169 | 18 | 38,512 | 3,064 | Accepted | Accepted | 89.35 | N = int(eval(input()))
W = list(map(int,input().split()))
ans = sum(W)
for i in range(1,N):
A = sum(W[0:i])
B = sum(W[i:])
ans = min(ans,abs(A-B))
print(ans) | import itertools
n = int(eval(input()))
w = list(map(int,input().split()))
acu = list(itertools.accumulate(w))
acu = [0] + acu
#print(acu)
ans = float("inf")
for i in range(1,n+1):
ans = min(ans, abs(acu[i]-(acu[n]-acu[i])))
#print(acu[i],acu[n]-acu[i])
print(ans) | 8 | 12 | 170 | 278 | N = int(eval(input()))
W = list(map(int, input().split()))
ans = sum(W)
for i in range(1, N):
A = sum(W[0:i])
B = sum(W[i:])
ans = min(ans, abs(A - B))
print(ans)
| import itertools
n = int(eval(input()))
w = list(map(int, input().split()))
acu = list(itertools.accumulate(w))
acu = [0] + acu
# print(acu)
ans = float("inf")
for i in range(1, n + 1):
ans = min(ans, abs(acu[i] - (acu[n] - acu[i])))
# print(acu[i],acu[n]-acu[i])
print(ans)
| false | 33.333333 | [
"-N = int(eval(input()))",
"-W = list(map(int, input().split()))",
"-ans = sum(W)",
"-for i in range(1, N):",
"- A = sum(W[0:i])",
"- B = sum(W[i:])",
"- ans = min(ans, abs(A - B))",
"+import itertools",
"+",
"+n = int(eval(input()))",
"+w = list(map(int, input().split()))",
"+acu = list(itertools.accumulate(w))",
"+acu = [0] + acu",
"+# print(acu)",
"+ans = float(\"inf\")",
"+for i in range(1, n + 1):",
"+ ans = min(ans, abs(acu[i] - (acu[n] - acu[i])))",
"+ # print(acu[i],acu[n]-acu[i])"
]
| false | 0.039932 | 0.039709 | 1.00562 | [
"s780503461",
"s611546412"
]
|
u947883560 | p02727 | python | s459603459 | s742917517 | 562 | 288 | 37,216 | 29,804 | Accepted | Accepted | 48.75 | #!/usr/bin/env python3
import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")
class MaxHeap(object):
def __init__(self, x, default=-INF):
self.heap = [-e for e in x]
self.default = default
heapq.heapify(self.heap)
def push(self, value):
heapq.heappush(self.heap, -value)
def pop(self):
if len(self.heap) == 0:
return self.default
else:
return -heapq.heappop(self.heap)
def argmax(a):
value, n = -(1 << 31), -1
for i, v in enumerate(a):
if value < v:
n, value = i, v
return n, value
def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
ABC = [MaxHeap(p), MaxHeap(q), MaxHeap(r)]
upper = [X, Y]
abc = [k.pop() for k in ABC]
xyz = [0, 0, 0]
tot = 0
for _ in range(X+Y):
i, m = argmax(abc)
tot += m
if (i < 2 and xyz[i] < upper[i]-1) or (i == 2):
abc[i] = ABC[i].pop()
else:
abc[i] = -INF
xyz[i] += 1
print(tot)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(A)] # type: "List[int]"
q = [int(next(tokens)) for _ in range(B)] # type: "List[int]"
r = [int(next(tokens)) for _ in range(C)] # type: "List[int]"
solve(X, Y, A, B, C, p, q, r)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")
class MaxHeap(object):
def __init__(self, x, default=-INF):
self.heap = [-e for e in x]
self.default = default
heapq.heapify(self.heap)
def push(self, value):
heapq.heappush(self.heap, -value)
def pop(self):
if len(self.heap) == 0:
return self.default
else:
return -heapq.heappop(self.heap)
def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
p.sort()
p = p[-X:]
q.sort()
q = q[-Y:]
h = sorted(p+q+r)
print((sum(h[-X-Y:])))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(A)] # type: "List[int]"
q = [int(next(tokens)) for _ in range(B)] # type: "List[int]"
r = [int(next(tokens)) for _ in range(C)] # type: "List[int]"
solve(X, Y, A, B, C, p, q, r)
if __name__ == '__main__':
main()
| 71 | 54 | 1,807 | 1,380 | #!/usr/bin/env python3
import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")
class MaxHeap(object):
def __init__(self, x, default=-INF):
self.heap = [-e for e in x]
self.default = default
heapq.heapify(self.heap)
def push(self, value):
heapq.heappush(self.heap, -value)
def pop(self):
if len(self.heap) == 0:
return self.default
else:
return -heapq.heappop(self.heap)
def argmax(a):
value, n = -(1 << 31), -1
for i, v in enumerate(a):
if value < v:
n, value = i, v
return n, value
def solve(
X: int,
Y: int,
A: int,
B: int,
C: int,
p: "List[int]",
q: "List[int]",
r: "List[int]",
):
ABC = [MaxHeap(p), MaxHeap(q), MaxHeap(r)]
upper = [X, Y]
abc = [k.pop() for k in ABC]
xyz = [0, 0, 0]
tot = 0
for _ in range(X + Y):
i, m = argmax(abc)
tot += m
if (i < 2 and xyz[i] < upper[i] - 1) or (i == 2):
abc[i] = ABC[i].pop()
else:
abc[i] = -INF
xyz[i] += 1
print(tot)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(A)] # type: "List[int]"
q = [int(next(tokens)) for _ in range(B)] # type: "List[int]"
r = [int(next(tokens)) for _ in range(C)] # type: "List[int]"
solve(X, Y, A, B, C, p, q, r)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
import heapq
sys.setrecursionlimit(10**8)
INF = float("inf")
class MaxHeap(object):
def __init__(self, x, default=-INF):
self.heap = [-e for e in x]
self.default = default
heapq.heapify(self.heap)
def push(self, value):
heapq.heappush(self.heap, -value)
def pop(self):
if len(self.heap) == 0:
return self.default
else:
return -heapq.heappop(self.heap)
def solve(
X: int,
Y: int,
A: int,
B: int,
C: int,
p: "List[int]",
q: "List[int]",
r: "List[int]",
):
p.sort()
p = p[-X:]
q.sort()
q = q[-Y:]
h = sorted(p + q + r)
print((sum(h[-X - Y :])))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(A)] # type: "List[int]"
q = [int(next(tokens)) for _ in range(B)] # type: "List[int]"
r = [int(next(tokens)) for _ in range(C)] # type: "List[int]"
solve(X, Y, A, B, C, p, q, r)
if __name__ == "__main__":
main()
| false | 23.943662 | [
"-def argmax(a):",
"- value, n = -(1 << 31), -1",
"- for i, v in enumerate(a):",
"- if value < v:",
"- n, value = i, v",
"- return n, value",
"-",
"-",
"- ABC = [MaxHeap(p), MaxHeap(q), MaxHeap(r)]",
"- upper = [X, Y]",
"- abc = [k.pop() for k in ABC]",
"- xyz = [0, 0, 0]",
"- tot = 0",
"- for _ in range(X + Y):",
"- i, m = argmax(abc)",
"- tot += m",
"- if (i < 2 and xyz[i] < upper[i] - 1) or (i == 2):",
"- abc[i] = ABC[i].pop()",
"- else:",
"- abc[i] = -INF",
"- xyz[i] += 1",
"- print(tot)",
"+ p.sort()",
"+ p = p[-X:]",
"+ q.sort()",
"+ q = q[-Y:]",
"+ h = sorted(p + q + r)",
"+ print((sum(h[-X - Y :])))"
]
| false | 0.08821 | 0.090375 | 0.976038 | [
"s459603459",
"s742917517"
]
|
u343675824 | p03740 | python | s150078713 | s016201018 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | X, Y = list(map(int, input().split()))
if abs(X-Y) > 1:
print('Alice')
else:
print('Brown') | X, Y = list(map(int, input().split()))
if abs(X-Y) <= 1:
print('Brown')
else:
print('Alice')
| 5 | 5 | 97 | 99 | X, Y = list(map(int, input().split()))
if abs(X - Y) > 1:
print("Alice")
else:
print("Brown")
| X, Y = list(map(int, input().split()))
if abs(X - Y) <= 1:
print("Brown")
else:
print("Alice")
| false | 0 | [
"-if abs(X - Y) > 1:",
"+if abs(X - Y) <= 1:",
"+ print(\"Brown\")",
"+else:",
"-else:",
"- print(\"Brown\")"
]
| false | 0.073093 | 0.072316 | 1.010739 | [
"s150078713",
"s016201018"
]
|
u062147869 | p03364 | python | s160756304 | s520945853 | 1,504 | 1,376 | 47,020 | 44,892 | Accepted | Accepted | 8.51 | N = int(eval(input()))
S=[]
for i in range(N):
s =list(eval(input()))
S.append(s)
num=0
for a in range(N):
t =1
#flag = True
for i in range(N):
#if not flag:
# break
for j in range(N):
if i==j:
continue
#x = (i+a)%N
#y=j
if S[(j+a)%N][i]!=S[(i+a)%N][j]:
t=0
#flag=False
#break
if t:
num+=1
print((N*num))
| N = int(eval(input()))
S=[]
for i in range(N):
s =list(eval(input()))
S.append(s)
num=0
for a in range(N):
t =1
flag = True
for i in range(N):
if not flag:
break
for j in range(N):
if i==j:
continue
#x = (i+a)%N
#y=j
if S[(j+a)%N][i]!=S[(i+a)%N][j]:
t=0
flag=False
break
if t:
num+=1
print((N*num))
| 25 | 25 | 487 | 482 | N = int(eval(input()))
S = []
for i in range(N):
s = list(eval(input()))
S.append(s)
num = 0
for a in range(N):
t = 1
# flag = True
for i in range(N):
# if not flag:
# break
for j in range(N):
if i == j:
continue
# x = (i+a)%N
# y=j
if S[(j + a) % N][i] != S[(i + a) % N][j]:
t = 0
# flag=False
# break
if t:
num += 1
print((N * num))
| N = int(eval(input()))
S = []
for i in range(N):
s = list(eval(input()))
S.append(s)
num = 0
for a in range(N):
t = 1
flag = True
for i in range(N):
if not flag:
break
for j in range(N):
if i == j:
continue
# x = (i+a)%N
# y=j
if S[(j + a) % N][i] != S[(i + a) % N][j]:
t = 0
flag = False
break
if t:
num += 1
print((N * num))
| false | 0 | [
"- # flag = True",
"+ flag = True",
"- # if not flag:",
"- # break",
"+ if not flag:",
"+ break",
"- # flag=False",
"- # break",
"+ flag = False",
"+ break"
]
| false | 0.047242 | 0.047767 | 0.989003 | [
"s160756304",
"s520945853"
]
|
u970308980 | p02780 | python | s734664165 | s062256987 | 221 | 177 | 25,152 | 26,368 | Accepted | Accepted | 19.91 | from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
d = {}
for i in range(1, 1001):
d[i] = (i + 1) * (i / 2) / i
E = []
for p in P:
E.append((p+1)/2)
cum = list(accumulate(E))
mx = 0
idx = 0
ans = 0
for i in range(N-K+1):
if i == 0:
mx = max(mx, cum[i+K-1])
else:
mx = max(mx, cum[i+K-1] - cum[i-1])
print(mx) | from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
E = [(p+1)/2 for p in P]
cum = [0]
cum.extend(list(accumulate(E)))
ans = 0
for i in range(N-K+1):
ans = max(ans, cum[i+K] - cum[i])
print(ans)
| 25 | 15 | 421 | 272 | from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
d = {}
for i in range(1, 1001):
d[i] = (i + 1) * (i / 2) / i
E = []
for p in P:
E.append((p + 1) / 2)
cum = list(accumulate(E))
mx = 0
idx = 0
ans = 0
for i in range(N - K + 1):
if i == 0:
mx = max(mx, cum[i + K - 1])
else:
mx = max(mx, cum[i + K - 1] - cum[i - 1])
print(mx)
| from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
E = [(p + 1) / 2 for p in P]
cum = [0]
cum.extend(list(accumulate(E)))
ans = 0
for i in range(N - K + 1):
ans = max(ans, cum[i + K] - cum[i])
print(ans)
| false | 40 | [
"-d = {}",
"-for i in range(1, 1001):",
"- d[i] = (i + 1) * (i / 2) / i",
"-E = []",
"-for p in P:",
"- E.append((p + 1) / 2)",
"-cum = list(accumulate(E))",
"-mx = 0",
"-idx = 0",
"+E = [(p + 1) / 2 for p in P]",
"+cum = [0]",
"+cum.extend(list(accumulate(E)))",
"- if i == 0:",
"- mx = max(mx, cum[i + K - 1])",
"- else:",
"- mx = max(mx, cum[i + K - 1] - cum[i - 1])",
"-print(mx)",
"+ ans = max(ans, cum[i + K] - cum[i])",
"+print(ans)"
]
| false | 0.049229 | 0.049155 | 1.001507 | [
"s734664165",
"s062256987"
]
|
u340781749 | p03208 | python | s374464399 | s092711202 | 251 | 224 | 7,384 | 7,928 | Accepted | Accepted | 10.76 | n, k = list(map(int, input().split()))
hhh = [int(eval(input())) for _ in range(n)]
hhh.sort()
ans = float('inf')
for i in range(n - k + 1):
ans = min(ans, hhh[i + k - 1] - hhh[i])
print(ans)
| from itertools import starmap
from operator import sub
n, k = list(map(int, input().split()))
hhh = sorted(int(eval(input())) for _ in range(n))
print((min(starmap(sub, list(zip(hhh[k - 1:], hhh))))))
| 7 | 6 | 190 | 187 | n, k = list(map(int, input().split()))
hhh = [int(eval(input())) for _ in range(n)]
hhh.sort()
ans = float("inf")
for i in range(n - k + 1):
ans = min(ans, hhh[i + k - 1] - hhh[i])
print(ans)
| from itertools import starmap
from operator import sub
n, k = list(map(int, input().split()))
hhh = sorted(int(eval(input())) for _ in range(n))
print((min(starmap(sub, list(zip(hhh[k - 1 :], hhh))))))
| false | 14.285714 | [
"+from itertools import starmap",
"+from operator import sub",
"+",
"-hhh = [int(eval(input())) for _ in range(n)]",
"-hhh.sort()",
"-ans = float(\"inf\")",
"-for i in range(n - k + 1):",
"- ans = min(ans, hhh[i + k - 1] - hhh[i])",
"-print(ans)",
"+hhh = sorted(int(eval(input())) for _ in range(n))",
"+print((min(starmap(sub, list(zip(hhh[k - 1 :], hhh))))))"
]
| false | 0.087321 | 0.047884 | 1.823598 | [
"s374464399",
"s092711202"
]
|
u653837719 | p03546 | python | s278610212 | s321821054 | 103 | 80 | 74,036 | 73,916 | Accepted | Accepted | 22.33 | from heapq import heappush, heappop
def dijkstra(s):
'''
始点sから各頂点への最短距離を求める
'''
d = [float("inf")] * 10
d[s] = 0
used = [False] * 10
used[s] = True
edgelist = []
for e in edge[s]:
heappush(edgelist, e)
while edgelist:
cost, v = heappop(edgelist)
if used[v]:
continue
d[v] = cost
used[v] = True
for e in edge[v]:
if not used[e[1]]:
heappush(edgelist, [e[0] + d[v], e[1]])
return d
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
edge = [[] for _ in range(10)]
for i in range(10):
for j in range(10):
edge[i].append([c[i][j], j])
edge[j].append([c[j][i], i])
dist = []
for i in range(10):
dist.append(dijkstra(i))
res = 0
for i in range(h):
for j in range(w):
if a[i][j] >= 0:
res += dist[a[i][j]][1]
print(res) | def warshall_floyd():
'''
すべての頂点間の最短距離を求める
'''
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
warshall_floyd()
res = 0
for i in range(h):
for j in range(w):
if a[i][j] >= 0:
res += c[a[i][j]][1]
print(res) | 50 | 23 | 1,048 | 509 | from heapq import heappush, heappop
def dijkstra(s):
"""
始点sから各頂点への最短距離を求める
"""
d = [float("inf")] * 10
d[s] = 0
used = [False] * 10
used[s] = True
edgelist = []
for e in edge[s]:
heappush(edgelist, e)
while edgelist:
cost, v = heappop(edgelist)
if used[v]:
continue
d[v] = cost
used[v] = True
for e in edge[v]:
if not used[e[1]]:
heappush(edgelist, [e[0] + d[v], e[1]])
return d
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
edge = [[] for _ in range(10)]
for i in range(10):
for j in range(10):
edge[i].append([c[i][j], j])
edge[j].append([c[j][i], i])
dist = []
for i in range(10):
dist.append(dijkstra(i))
res = 0
for i in range(h):
for j in range(w):
if a[i][j] >= 0:
res += dist[a[i][j]][1]
print(res)
| def warshall_floyd():
"""
すべての頂点間の最短距離を求める
"""
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
warshall_floyd()
res = 0
for i in range(h):
for j in range(w):
if a[i][j] >= 0:
res += c[a[i][j]][1]
print(res)
| false | 54 | [
"-from heapq import heappush, heappop",
"-",
"-",
"-def dijkstra(s):",
"+def warshall_floyd():",
"- 始点sから各頂点への最短距離を求める",
"+ すべての頂点間の最短距離を求める",
"- d = [float(\"inf\")] * 10",
"- d[s] = 0",
"- used = [False] * 10",
"- used[s] = True",
"- edgelist = []",
"- for e in edge[s]:",
"- heappush(edgelist, e)",
"- while edgelist:",
"- cost, v = heappop(edgelist)",
"- if used[v]:",
"- continue",
"- d[v] = cost",
"- used[v] = True",
"- for e in edge[v]:",
"- if not used[e[1]]:",
"- heappush(edgelist, [e[0] + d[v], e[1]])",
"- return d",
"+ for k in range(10):",
"+ for i in range(10):",
"+ for j in range(10):",
"+ c[i][j] = min(c[i][j], c[i][k] + c[k][j])",
"-edge = [[] for _ in range(10)]",
"-for i in range(10):",
"- for j in range(10):",
"- edge[i].append([c[i][j], j])",
"- edge[j].append([c[j][i], i])",
"-dist = []",
"-for i in range(10):",
"- dist.append(dijkstra(i))",
"+warshall_floyd()",
"- res += dist[a[i][j]][1]",
"+ res += c[a[i][j]][1]"
]
| false | 0.040814 | 0.145365 | 0.280769 | [
"s278610212",
"s321821054"
]
|
u156815136 | p03775 | python | s595112851 | s841629844 | 60 | 51 | 10,484 | 10,432 | Accepted | Accepted | 15 | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
mind = float('inf')
i = 1
while i*i <= n:
if n%i == 0:
if i == n//i:
mind = min(mind, len(str(i)))
else:
maxd = max(len(str(i)), len(str(n//i)))
mind = min(mind, maxd)
i += 1
print(mind)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
import math
root = int(math.sqrt(n))+1
ans = float('inf')
for i in range(1,root+1):
if n%i == 0:
left = i
right = n//i
ll = len(str(left))
lr = len(str(right))
lm = max(ll,lr)
ans = min(ans,lm)
print(ans)
| 41 | 75 | 989 | 1,805 | # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
mind = float("inf")
i = 1
while i * i <= n:
if n % i == 0:
if i == n // i:
mind = min(mind, len(str(i)))
else:
maxd = max(len(str(i)), len(str(n // i)))
mind = min(mind, maxd)
i += 1
print(mind)
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
# mod = 9982443453
mod = 998244353
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
import math
root = int(math.sqrt(n)) + 1
ans = float("inf")
for i in range(1, root + 1):
if n % i == 0:
left = i
right = n // i
ll = len(str(left))
lr = len(str(right))
lm = max(ll, lr)
ans = min(ans, lm)
print(ans)
| false | 45.333333 | [
"-from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"+import math",
"-# 四捨五入",
"+# 四捨五入g",
"+import sys",
"+",
"+sys.setrecursionlimit(10000000)",
"+# mod = 10**9 + 7",
"+# mod = 9982443453",
"+mod = 998244353",
"+",
"+",
"+def readInts():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+# from statistics import median",
"+# import collections",
"+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]",
"+from fractions import gcd",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"+",
"+# from collections import deque",
"+from collections import deque, defaultdict, Counter",
"+import decimal",
"+import re",
"+import math",
"+",
"+# import bisect",
"+#",
"+# d = m - k[i] - k[j]",
"+# if kk[bisect.bisect_right(kk,d) - 1] == d:",
"+#",
"+#",
"+#",
"+# pythonで無理なときは、pypyでやると正解するかも!!",
"+#",
"+#",
"+# my_round_int = lambda x:np.round((x*2 + 1)//2)",
"+# 四捨五入g",
"+# mod = 998244353",
"-mind = float(\"inf\")",
"-i = 1",
"-while i * i <= n:",
"+import math",
"+",
"+root = int(math.sqrt(n)) + 1",
"+ans = float(\"inf\")",
"+for i in range(1, root + 1):",
"- if i == n // i:",
"- mind = min(mind, len(str(i)))",
"- else:",
"- maxd = max(len(str(i)), len(str(n // i)))",
"- mind = min(mind, maxd)",
"- i += 1",
"-print(mind)",
"+ left = i",
"+ right = n // i",
"+ ll = len(str(left))",
"+ lr = len(str(right))",
"+ lm = max(ll, lr)",
"+ ans = min(ans, lm)",
"+print(ans)"
]
| false | 0.057195 | 0.052337 | 1.092818 | [
"s595112851",
"s841629844"
]
|
u509278866 | p01753 | python | s425449030 | s940752386 | 60 | 20 | 9,112 | 5,720 | Accepted | Accepted | 66.67 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,q = LI()
a = [LI() for _ in range(n)]
b = [LI() for _ in range(q)]
rr = []
def k(a,b):
return sum([(a[i]-b[i]) ** 2 for i in range(3)]) ** 0.5
def f(a,b,c,r):
ab = k(a,b)
ac = k(a,c)
bc = k(b,c)
if ac <= r or bc <= r:
return True
at = (ac ** 2 - r ** 2)
bt = (bc ** 2 - r ** 2)
t = max(at,0) ** 0.5 + max(bt,0) ** 0.5
return ab >= t - eps
for x1,y1,z1,x2,y2,z2 in b:
tr = 0
ta = (x1,y1,z1)
tb = (x2,y2,z2)
for x,y,z,r,l in a:
if f(ta,tb,(x,y,z),r):
tr += l
rr.append(tr)
return '\n'.join(map(str,rr))
print(main())
| eps = 1.0 / 10**10
def LI(): return [int(x) for x in input().split()]
def main():
n,q = LI()
na = [LI() for _ in range(n)]
qa = [LI() for _ in range(q)]
rr = []
def k(a,b):
return sum([(a[i]-b[i]) ** 2 for i in range(3)]) ** 0.5
def f(a,b,c,r):
ab = k(a,b)
ac = k(a,c)
bc = k(b,c)
if ac <= r or bc <= r:
return True
at = (ac ** 2 - r ** 2) ** 0.5
bt = (bc ** 2 - r ** 2) ** 0.5
return ab >= at + bt - eps
for x1,y1,z1,x2,y2,z2 in qa:
tr = 0
for x,y,z,r,l in na:
if f((x1,y1,z1),(x2,y2,z2),(x,y,z),r):
tr += l
rr.append(tr)
return '\n'.join(map(str,rr))
print((main()))
| 54 | 35 | 1,446 | 770 | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0, -1), (1, 0), (0, 1), (-1, 0)]
ddn = [(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, -1), (-1, 0), (-1, 1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return input()
def pf(s):
return print(s, flush=True)
def main():
n, q = LI()
a = [LI() for _ in range(n)]
b = [LI() for _ in range(q)]
rr = []
def k(a, b):
return sum([(a[i] - b[i]) ** 2 for i in range(3)]) ** 0.5
def f(a, b, c, r):
ab = k(a, b)
ac = k(a, c)
bc = k(b, c)
if ac <= r or bc <= r:
return True
at = ac**2 - r**2
bt = bc**2 - r**2
t = max(at, 0) ** 0.5 + max(bt, 0) ** 0.5
return ab >= t - eps
for x1, y1, z1, x2, y2, z2 in b:
tr = 0
ta = (x1, y1, z1)
tb = (x2, y2, z2)
for x, y, z, r, l in a:
if f(ta, tb, (x, y, z), r):
tr += l
rr.append(tr)
return "\n".join(map(str, rr))
print(main())
| eps = 1.0 / 10**10
def LI():
return [int(x) for x in input().split()]
def main():
n, q = LI()
na = [LI() for _ in range(n)]
qa = [LI() for _ in range(q)]
rr = []
def k(a, b):
return sum([(a[i] - b[i]) ** 2 for i in range(3)]) ** 0.5
def f(a, b, c, r):
ab = k(a, b)
ac = k(a, c)
bc = k(b, c)
if ac <= r or bc <= r:
return True
at = (ac**2 - r**2) ** 0.5
bt = (bc**2 - r**2) ** 0.5
return ab >= at + bt - eps
for x1, y1, z1, x2, y2, z2 in qa:
tr = 0
for x, y, z, r, l in na:
if f((x1, y1, z1), (x2, y2, z2), (x, y, z), r):
tr += l
rr.append(tr)
return "\n".join(map(str, rr))
print((main()))
| false | 35.185185 | [
"-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools",
"-",
"-sys.setrecursionlimit(10**7)",
"-inf = 10**20",
"-mod = 998244353",
"-dd = [(0, -1), (1, 0), (0, 1), (-1, 0)]",
"-ddn = [(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, -1), (-1, 0), (-1, 1)]",
"- return [int(x) for x in sys.stdin.readline().split()]",
"-",
"-",
"-def LI_():",
"- return [int(x) - 1 for x in sys.stdin.readline().split()]",
"-",
"-",
"-def LF():",
"- return [float(x) for x in sys.stdin.readline().split()]",
"-",
"-",
"-def LS():",
"- return sys.stdin.readline().split()",
"-",
"-",
"-def I():",
"- return int(sys.stdin.readline())",
"-",
"-",
"-def F():",
"- return float(sys.stdin.readline())",
"-",
"-",
"-def S():",
"- return input()",
"-",
"-",
"-def pf(s):",
"- return print(s, flush=True)",
"+ return [int(x) for x in input().split()]",
"- a = [LI() for _ in range(n)]",
"- b = [LI() for _ in range(q)]",
"+ na = [LI() for _ in range(n)]",
"+ qa = [LI() for _ in range(q)]",
"- at = ac**2 - r**2",
"- bt = bc**2 - r**2",
"- t = max(at, 0) ** 0.5 + max(bt, 0) ** 0.5",
"- return ab >= t - eps",
"+ at = (ac**2 - r**2) ** 0.5",
"+ bt = (bc**2 - r**2) ** 0.5",
"+ return ab >= at + bt - eps",
"- for x1, y1, z1, x2, y2, z2 in b:",
"+ for x1, y1, z1, x2, y2, z2 in qa:",
"- ta = (x1, y1, z1)",
"- tb = (x2, y2, z2)",
"- for x, y, z, r, l in a:",
"- if f(ta, tb, (x, y, z), r):",
"+ for x, y, z, r, l in na:",
"+ if f((x1, y1, z1), (x2, y2, z2), (x, y, z), r):",
"-print(main())",
"+print((main()))"
]
| false | 0.043533 | 0.10028 | 0.434115 | [
"s425449030",
"s940752386"
]
|
u079022693 | p02883 | python | s536158112 | s383829381 | 541 | 418 | 119,500 | 37,184 | Accepted | Accepted | 22.74 | def main():
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
l_score=-1
r_score=10**12
while l_score<r_score-1:
t_score=(l_score+r_score)//2
count=0
for i in range(N):
count+=max(0,A[i]-t_score//F[i])
if count<=K:
r_score=t_score
else:
l_score=t_score
print(r_score)
if __name__=="__main__":
main() | from sys import stdin
import numpy as np
def main():
#入力
readline=stdin.readline
n,k=list(map(int,readline().split()))
A=np.array(list(map(int,readline().split())),dtype=np.int64)
A=np.sort(A)[::-1]
F=np.array(list(map(int,readline().split())),dtype=np.int64)
F=np.sort(F)
l=-1
r=10**12
while l<r-1:
x=(l+r)//2
A_after=np.minimum(x//F,A)
cnt=(A-A_after).sum()
if cnt<=k: r=x
else: l=x
print(r)
if __name__=="__main__":
main() | 21 | 24 | 511 | 533 | def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
l_score = -1
r_score = 10**12
while l_score < r_score - 1:
t_score = (l_score + r_score) // 2
count = 0
for i in range(N):
count += max(0, A[i] - t_score // F[i])
if count <= K:
r_score = t_score
else:
l_score = t_score
print(r_score)
if __name__ == "__main__":
main()
| from sys import stdin
import numpy as np
def main():
# 入力
readline = stdin.readline
n, k = list(map(int, readline().split()))
A = np.array(list(map(int, readline().split())), dtype=np.int64)
A = np.sort(A)[::-1]
F = np.array(list(map(int, readline().split())), dtype=np.int64)
F = np.sort(F)
l = -1
r = 10**12
while l < r - 1:
x = (l + r) // 2
A_after = np.minimum(x // F, A)
cnt = (A - A_after).sum()
if cnt <= k:
r = x
else:
l = x
print(r)
if __name__ == "__main__":
main()
| false | 12.5 | [
"+from sys import stdin",
"+import numpy as np",
"+",
"+",
"- N, K = list(map(int, input().split()))",
"- A = list(map(int, input().split()))",
"- F = list(map(int, input().split()))",
"- A.sort(reverse=True)",
"- F.sort()",
"- l_score = -1",
"- r_score = 10**12",
"- while l_score < r_score - 1:",
"- t_score = (l_score + r_score) // 2",
"- count = 0",
"- for i in range(N):",
"- count += max(0, A[i] - t_score // F[i])",
"- if count <= K:",
"- r_score = t_score",
"+ # 入力",
"+ readline = stdin.readline",
"+ n, k = list(map(int, readline().split()))",
"+ A = np.array(list(map(int, readline().split())), dtype=np.int64)",
"+ A = np.sort(A)[::-1]",
"+ F = np.array(list(map(int, readline().split())), dtype=np.int64)",
"+ F = np.sort(F)",
"+ l = -1",
"+ r = 10**12",
"+ while l < r - 1:",
"+ x = (l + r) // 2",
"+ A_after = np.minimum(x // F, A)",
"+ cnt = (A - A_after).sum()",
"+ if cnt <= k:",
"+ r = x",
"- l_score = t_score",
"- print(r_score)",
"+ l = x",
"+ print(r)"
]
| false | 0.138358 | 0.189628 | 0.72963 | [
"s536158112",
"s383829381"
]
|
u807772568 | p03479 | python | s755654801 | s722686086 | 173 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.17 | a = list(map(int,input().split()))
k = a[1]
i = 2
l = a[0]
while True:
l *= 2
if k < l:
break
i += 1
print((i-1))
| a,b = list(map(int,input().split()))
k = 0
while a <= b:
k += 1
a *= 2
print(k) | 11 | 8 | 133 | 86 | a = list(map(int, input().split()))
k = a[1]
i = 2
l = a[0]
while True:
l *= 2
if k < l:
break
i += 1
print((i - 1))
| a, b = list(map(int, input().split()))
k = 0
while a <= b:
k += 1
a *= 2
print(k)
| false | 27.272727 | [
"-a = list(map(int, input().split()))",
"-k = a[1]",
"-i = 2",
"-l = a[0]",
"-while True:",
"- l *= 2",
"- if k < l:",
"- break",
"- i += 1",
"-print((i - 1))",
"+a, b = list(map(int, input().split()))",
"+k = 0",
"+while a <= b:",
"+ k += 1",
"+ a *= 2",
"+print(k)"
]
| false | 0.038212 | 0.037187 | 1.027561 | [
"s755654801",
"s722686086"
]
|
u078349616 | p02743 | python | s117062010 | s199613454 | 38 | 17 | 5,076 | 2,940 | Accepted | Accepted | 55.26 | from decimal import *
A, B, C = list(map(int,input().split()))
a = Decimal(A)
b = Decimal(B)
c = Decimal(C)
if a.sqrt() + b.sqrt() < c.sqrt():
print("Yes")
else:
print("No") | a, b, c = list(map(int, input().split()))
if 4*a*b < pow(c-a-b, 2) and c-a-b > 0:
print("Yes")
else:
print("No") | 9 | 5 | 179 | 114 | from decimal import *
A, B, C = list(map(int, input().split()))
a = Decimal(A)
b = Decimal(B)
c = Decimal(C)
if a.sqrt() + b.sqrt() < c.sqrt():
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if 4 * a * b < pow(c - a - b, 2) and c - a - b > 0:
print("Yes")
else:
print("No")
| false | 44.444444 | [
"-from decimal import *",
"-",
"-A, B, C = list(map(int, input().split()))",
"-a = Decimal(A)",
"-b = Decimal(B)",
"-c = Decimal(C)",
"-if a.sqrt() + b.sqrt() < c.sqrt():",
"+a, b, c = list(map(int, input().split()))",
"+if 4 * a * b < pow(c - a - b, 2) and c - a - b > 0:"
]
| false | 0.046726 | 0.128174 | 0.36455 | [
"s117062010",
"s199613454"
]
|
u477319617 | p02658 | python | s917807500 | s151170946 | 66 | 61 | 21,648 | 21,632 | Accepted | Accepted | 7.58 | n = int(eval(input()))
a = list(map(int,input().split()))
ans = 1
if 0 in a:
ans = 0
else:
a.sort(reverse=True)
for i in a:
if(i==0):
ans = 0;break
if ans>(10**18):
ans = -1;break
ans = ans*i
print((-1 if ans>(10**18) else ans)) | n = int(eval(input()))
a = list(map(int,input().split()))
ans = 1
if 0 in a:
ans = 0
# print(a)
else:
a.sort(reverse=True)
for i in a:
ans = ans*i
if ans>(10**18):
ans = -1;break
print(ans) | 14 | 13 | 293 | 239 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
if 0 in a:
ans = 0
else:
a.sort(reverse=True)
for i in a:
if i == 0:
ans = 0
break
if ans > (10**18):
ans = -1
break
ans = ans * i
print((-1 if ans > (10**18) else ans))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
if 0 in a:
ans = 0
# print(a)
else:
a.sort(reverse=True)
for i in a:
ans = ans * i
if ans > (10**18):
ans = -1
break
print(ans)
| false | 7.142857 | [
"+ # print(a)",
"- if i == 0:",
"- ans = 0",
"- break",
"+ ans = ans * i",
"- ans = ans * i",
"-print((-1 if ans > (10**18) else ans))",
"+print(ans)"
]
| false | 0.040583 | 0.039601 | 1.024786 | [
"s917807500",
"s151170946"
]
|
u506287026 | p02953 | python | s566264987 | s758296162 | 85 | 63 | 14,252 | 14,396 | Accepted | Accepted | 25.88 | N = int(eval(input()))
Hs = [int(i) for i in input().split()]
is_Yes = True
for i in range(1, N):
if Hs[i-1] == Hs[i]:
continue
elif Hs[i] > Hs[i-1]:
Hs[i] -= 1
else:
is_Yes = False
break
if is_Yes:
print('Yes')
else:
print('No')
| n = int(eval(input()))
nums = [int(num) for num in input().split()]
def solve(nums):
nums[0] -= 1
for i in range(1, n):
if nums[i] > nums[i-1]:
nums[i] -= 1
continue
if nums[i] < nums[i-1]:
return 'No'
return 'Yes'
print((solve(nums)))
| 17 | 16 | 294 | 311 | N = int(eval(input()))
Hs = [int(i) for i in input().split()]
is_Yes = True
for i in range(1, N):
if Hs[i - 1] == Hs[i]:
continue
elif Hs[i] > Hs[i - 1]:
Hs[i] -= 1
else:
is_Yes = False
break
if is_Yes:
print("Yes")
else:
print("No")
| n = int(eval(input()))
nums = [int(num) for num in input().split()]
def solve(nums):
nums[0] -= 1
for i in range(1, n):
if nums[i] > nums[i - 1]:
nums[i] -= 1
continue
if nums[i] < nums[i - 1]:
return "No"
return "Yes"
print((solve(nums)))
| false | 5.882353 | [
"-N = int(eval(input()))",
"-Hs = [int(i) for i in input().split()]",
"-is_Yes = True",
"-for i in range(1, N):",
"- if Hs[i - 1] == Hs[i]:",
"- continue",
"- elif Hs[i] > Hs[i - 1]:",
"- Hs[i] -= 1",
"- else:",
"- is_Yes = False",
"- break",
"-if is_Yes:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+n = int(eval(input()))",
"+nums = [int(num) for num in input().split()]",
"+",
"+",
"+def solve(nums):",
"+ nums[0] -= 1",
"+ for i in range(1, n):",
"+ if nums[i] > nums[i - 1]:",
"+ nums[i] -= 1",
"+ continue",
"+ if nums[i] < nums[i - 1]:",
"+ return \"No\"",
"+ return \"Yes\"",
"+",
"+",
"+print((solve(nums)))"
]
| false | 0.143848 | 0.151404 | 0.950092 | [
"s566264987",
"s758296162"
]
|
u761320129 | p03503 | python | s182117606 | s071299111 | 287 | 258 | 3,064 | 3,064 | Accepted | Accepted | 10.1 | N = int(eval(input()))
fs = [list(map(int,input().split())) for i in range(N)]
ps = [list(map(int,input().split())) for i in range(N)]
INF = float('inf')
ans = -INF
for b in range(1,2**10):
tmp = 0
for f,p in zip(fs,ps):
c = 0
for k in range(10):
if b&(1<<k)==0: continue
if f[k]: c += 1
tmp += p[c]
ans = max(ans, tmp)
print(ans) | N = int(eval(input()))
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
ans = -float('inf')
for k in range(1,1<<10):
tmp = 0
for fs,ps in zip(F,P):
cnt = 0
for b in range(10):
if (k>>b)&1 and fs[b]:
cnt += 1
tmp += ps[cnt]
ans = max(ans, tmp)
print(ans) | 16 | 15 | 400 | 387 | N = int(eval(input()))
fs = [list(map(int, input().split())) for i in range(N)]
ps = [list(map(int, input().split())) for i in range(N)]
INF = float("inf")
ans = -INF
for b in range(1, 2**10):
tmp = 0
for f, p in zip(fs, ps):
c = 0
for k in range(10):
if b & (1 << k) == 0:
continue
if f[k]:
c += 1
tmp += p[c]
ans = max(ans, tmp)
print(ans)
| N = int(eval(input()))
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = -float("inf")
for k in range(1, 1 << 10):
tmp = 0
for fs, ps in zip(F, P):
cnt = 0
for b in range(10):
if (k >> b) & 1 and fs[b]:
cnt += 1
tmp += ps[cnt]
ans = max(ans, tmp)
print(ans)
| false | 6.25 | [
"-fs = [list(map(int, input().split())) for i in range(N)]",
"-ps = [list(map(int, input().split())) for i in range(N)]",
"-INF = float(\"inf\")",
"-ans = -INF",
"-for b in range(1, 2**10):",
"+F = [list(map(int, input().split())) for i in range(N)]",
"+P = [list(map(int, input().split())) for i in range(N)]",
"+ans = -float(\"inf\")",
"+for k in range(1, 1 << 10):",
"- for f, p in zip(fs, ps):",
"- c = 0",
"- for k in range(10):",
"- if b & (1 << k) == 0:",
"- continue",
"- if f[k]:",
"- c += 1",
"- tmp += p[c]",
"+ for fs, ps in zip(F, P):",
"+ cnt = 0",
"+ for b in range(10):",
"+ if (k >> b) & 1 and fs[b]:",
"+ cnt += 1",
"+ tmp += ps[cnt]"
]
| false | 0.067258 | 0.097557 | 0.689427 | [
"s182117606",
"s071299111"
]
|
u391875425 | p03252 | python | s365354252 | s578696023 | 99 | 41 | 3,632 | 3,888 | Accepted | Accepted | 58.59 | S, T = eval(input()), eval(input())
cnt1, cnt2, r1, r2 =[], [], [], []
for c in S:
if not c in r1:
cnt1.append(S.count(c))
r1.append(c)
for c in T:
if not c in r2:
cnt2.append(T.count(c))
r2.append(c)
#cnt1.sort()
#cnt2.sort()
if cnt1 == cnt2:
print('Yes')
else:
print('No') | from collections import Counter
if sorted(Counter(eval(input())).values()) == sorted(Counter(eval(input())).values()):
print('Yes')
else:
print('No') | 16 | 5 | 325 | 149 | S, T = eval(input()), eval(input())
cnt1, cnt2, r1, r2 = [], [], [], []
for c in S:
if not c in r1:
cnt1.append(S.count(c))
r1.append(c)
for c in T:
if not c in r2:
cnt2.append(T.count(c))
r2.append(c)
# cnt1.sort()
# cnt2.sort()
if cnt1 == cnt2:
print("Yes")
else:
print("No")
| from collections import Counter
if sorted(Counter(eval(input())).values()) == sorted(Counter(eval(input())).values()):
print("Yes")
else:
print("No")
| false | 68.75 | [
"-S, T = eval(input()), eval(input())",
"-cnt1, cnt2, r1, r2 = [], [], [], []",
"-for c in S:",
"- if not c in r1:",
"- cnt1.append(S.count(c))",
"- r1.append(c)",
"-for c in T:",
"- if not c in r2:",
"- cnt2.append(T.count(c))",
"- r2.append(c)",
"-# cnt1.sort()",
"-# cnt2.sort()",
"-if cnt1 == cnt2:",
"+from collections import Counter",
"+",
"+if sorted(Counter(eval(input())).values()) == sorted(Counter(eval(input())).values()):"
]
| false | 0.032133 | 0.039282 | 0.818011 | [
"s365354252",
"s578696023"
]
|
u969708690 | p02603 | python | s076013909 | s186109846 | 36 | 33 | 9,188 | 9,152 | Accepted | Accepted | 8.33 | import sys
k=1000
N=int(eval(input()))
L=list(map(int,input().split()))
i=0
while i<N-1:
if L[i]<L[i+1]:
n=L[i]
break
i+=1
if i==N-1:
print((1000))
sys.exit()
n=0
for j in range(i,N):
if j==N-1 and n!=0:
m=max(L[s:])
c=k%n
k=((k//n)*m)+c
n=0
break
if j==N-1 and n==0:
break
if L[j]<L[j+1] and n==0:
n=L[j]
s=j
if L[j]>L[j+1] and n!=0:
m=L[j]
c=k%n
k=((k//n)*m)+c
n=0
print(k) | n = int(eval(input()))
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n-1):
if a[i] < a[i+1] and money != 0:
kabu += money // a[i]
money -= a[i] *(money // a[i])
elif a[i] > a[i+1] and kabu != 0:
money += a[i] * kabu
kabu = 0
print((money + a[-1] * kabu)) | 32 | 12 | 476 | 324 | import sys
k = 1000
N = int(eval(input()))
L = list(map(int, input().split()))
i = 0
while i < N - 1:
if L[i] < L[i + 1]:
n = L[i]
break
i += 1
if i == N - 1:
print((1000))
sys.exit()
n = 0
for j in range(i, N):
if j == N - 1 and n != 0:
m = max(L[s:])
c = k % n
k = ((k // n) * m) + c
n = 0
break
if j == N - 1 and n == 0:
break
if L[j] < L[j + 1] and n == 0:
n = L[j]
s = j
if L[j] > L[j + 1] and n != 0:
m = L[j]
c = k % n
k = ((k // n) * m) + c
n = 0
print(k)
| n = int(eval(input()))
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n - 1):
if a[i] < a[i + 1] and money != 0:
kabu += money // a[i]
money -= a[i] * (money // a[i])
elif a[i] > a[i + 1] and kabu != 0:
money += a[i] * kabu
kabu = 0
print((money + a[-1] * kabu))
| false | 62.5 | [
"-import sys",
"-",
"-k = 1000",
"-N = int(eval(input()))",
"-L = list(map(int, input().split()))",
"-i = 0",
"-while i < N - 1:",
"- if L[i] < L[i + 1]:",
"- n = L[i]",
"- break",
"- i += 1",
"- if i == N - 1:",
"- print((1000))",
"- sys.exit()",
"-n = 0",
"-for j in range(i, N):",
"- if j == N - 1 and n != 0:",
"- m = max(L[s:])",
"- c = k % n",
"- k = ((k // n) * m) + c",
"- n = 0",
"- break",
"- if j == N - 1 and n == 0:",
"- break",
"- if L[j] < L[j + 1] and n == 0:",
"- n = L[j]",
"- s = j",
"- if L[j] > L[j + 1] and n != 0:",
"- m = L[j]",
"- c = k % n",
"- k = ((k // n) * m) + c",
"- n = 0",
"-print(k)",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+money = 1000",
"+kabu = 0",
"+for i in range(n - 1):",
"+ if a[i] < a[i + 1] and money != 0:",
"+ kabu += money // a[i]",
"+ money -= a[i] * (money // a[i])",
"+ elif a[i] > a[i + 1] and kabu != 0:",
"+ money += a[i] * kabu",
"+ kabu = 0",
"+print((money + a[-1] * kabu))"
]
| false | 0.033583 | 0.033914 | 0.990235 | [
"s076013909",
"s186109846"
]
|
u971124021 | p02757 | python | s232994744 | s858043336 | 171 | 148 | 3,560 | 3,500 | Accepted | Accepted | 13.45 | n,p = list(map(int,input().split()))
S = eval(input())
if p == 2 or p == 5:
ans = 0
for i,s in enumerate(S):
if int(s)%p == 0:
ans += i+1
print(ans)
exit()
def MS(i,s,pre):
return (int(s)*i+pre)%p
M = [0]*p
M[0] = 1
i = 1
pre = 0
for s in S[::-1]:
#pre = MS(i,int(s),pre)
pre += int(s)*i
pre %= p
M[pre] += 1
i = i*10%p
ans = sum([(m*(m-1))//2 for m in M])
print(ans)
| n,p = list(map(int,input().split()))
S = eval(input())
if p == 2 or p == 5:
ans = 0
for i,s in enumerate(S):
if int(s)%p == 0:
ans += i+1
print(ans)
exit()
def MS(i,s,pre):
return (int(s)*i+pre)%p
M = [0]*p
M[0] = 1
i = 1
pre = 0
for s in S[::-1]:
#pre = MS(i,int(s),pre)
pre = pre + int(s)*i
pre = pre%p
M[pre] += 1
i = i*10%p
ans = sum([(m*(m-1))//2 for m in M])
print(ans)
| 28 | 28 | 429 | 437 | n, p = list(map(int, input().split()))
S = eval(input())
if p == 2 or p == 5:
ans = 0
for i, s in enumerate(S):
if int(s) % p == 0:
ans += i + 1
print(ans)
exit()
def MS(i, s, pre):
return (int(s) * i + pre) % p
M = [0] * p
M[0] = 1
i = 1
pre = 0
for s in S[::-1]:
# pre = MS(i,int(s),pre)
pre += int(s) * i
pre %= p
M[pre] += 1
i = i * 10 % p
ans = sum([(m * (m - 1)) // 2 for m in M])
print(ans)
| n, p = list(map(int, input().split()))
S = eval(input())
if p == 2 or p == 5:
ans = 0
for i, s in enumerate(S):
if int(s) % p == 0:
ans += i + 1
print(ans)
exit()
def MS(i, s, pre):
return (int(s) * i + pre) % p
M = [0] * p
M[0] = 1
i = 1
pre = 0
for s in S[::-1]:
# pre = MS(i,int(s),pre)
pre = pre + int(s) * i
pre = pre % p
M[pre] += 1
i = i * 10 % p
ans = sum([(m * (m - 1)) // 2 for m in M])
print(ans)
| false | 0 | [
"- pre += int(s) * i",
"- pre %= p",
"+ pre = pre + int(s) * i",
"+ pre = pre % p"
]
| false | 0.103036 | 0.046891 | 2.197353 | [
"s232994744",
"s858043336"
]
|
u678167152 | p03111 | python | s035925987 | s947960643 | 282 | 148 | 76,388 | 76,196 | Accepted | Accepted | 47.52 | from itertools import groupby, accumulate, product, permutations, combinations
def calc(x,X):
n = len(x)
ans = 10**10
for q in product([0,1],repeat=n):
point = 0
cnt = 0
for i in range(n):
if q[i]==1:
if cnt>0:
point += 10
cnt += x[i]
if cnt>0:
point += abs(cnt-X)
else:
point = 10**10
ans = min(point,ans)
return ans
def solve():
ans = 10**10
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
for p in product(['A','B','C','D'],repeat=N):
a,b,c = [],[],[]
cnt = 0
for i in range(N):
if p[i]=='A':
a.append(L[i])
elif p[i]=='B':
b.append(L[i])
elif p[i]=='C':
c.append(L[i])
cnt += calc(a,A)+calc(b,B)+calc(c,C)
ans = min(ans,cnt)
return ans
print((solve())) | from itertools import groupby, accumulate, product, permutations, combinations
def calc(x,X):
n = len(x)
if n==0:
return 10**10
ans = abs(sum(x)-X)+(n-1)*10
return ans
def solve():
ans = 10**10
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
for p in product(['A','B','C','D'],repeat=N):
a,b,c = [],[],[]
cnt = 0
for i in range(N):
if p[i]=='A':
a.append(L[i])
elif p[i]=='B':
b.append(L[i])
elif p[i]=='C':
c.append(L[i])
cnt += calc(a,A)+calc(b,B)+calc(c,C)
ans = min(ans,cnt)
return ans
print((solve())) | 37 | 26 | 867 | 642 | from itertools import groupby, accumulate, product, permutations, combinations
def calc(x, X):
n = len(x)
ans = 10**10
for q in product([0, 1], repeat=n):
point = 0
cnt = 0
for i in range(n):
if q[i] == 1:
if cnt > 0:
point += 10
cnt += x[i]
if cnt > 0:
point += abs(cnt - X)
else:
point = 10**10
ans = min(point, ans)
return ans
def solve():
ans = 10**10
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
for p in product(["A", "B", "C", "D"], repeat=N):
a, b, c = [], [], []
cnt = 0
for i in range(N):
if p[i] == "A":
a.append(L[i])
elif p[i] == "B":
b.append(L[i])
elif p[i] == "C":
c.append(L[i])
cnt += calc(a, A) + calc(b, B) + calc(c, C)
ans = min(ans, cnt)
return ans
print((solve()))
| from itertools import groupby, accumulate, product, permutations, combinations
def calc(x, X):
n = len(x)
if n == 0:
return 10**10
ans = abs(sum(x) - X) + (n - 1) * 10
return ans
def solve():
ans = 10**10
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
for p in product(["A", "B", "C", "D"], repeat=N):
a, b, c = [], [], []
cnt = 0
for i in range(N):
if p[i] == "A":
a.append(L[i])
elif p[i] == "B":
b.append(L[i])
elif p[i] == "C":
c.append(L[i])
cnt += calc(a, A) + calc(b, B) + calc(c, C)
ans = min(ans, cnt)
return ans
print((solve()))
| false | 29.72973 | [
"- ans = 10**10",
"- for q in product([0, 1], repeat=n):",
"- point = 0",
"- cnt = 0",
"- for i in range(n):",
"- if q[i] == 1:",
"- if cnt > 0:",
"- point += 10",
"- cnt += x[i]",
"- if cnt > 0:",
"- point += abs(cnt - X)",
"- else:",
"- point = 10**10",
"- ans = min(point, ans)",
"+ if n == 0:",
"+ return 10**10",
"+ ans = abs(sum(x) - X) + (n - 1) * 10"
]
| false | 1.954242 | 0.170059 | 11.491582 | [
"s035925987",
"s947960643"
]
|
u562935282 | p03680 | python | s541713701 | s362392151 | 206 | 78 | 13,448 | 11,048 | Accepted | Accepted | 62.14 | n = int(eval(input()))
a = list(map(int, list(eval(input()) for _ in range(n))))
visited = list(False for _ in range(n))
if (2 in a) == False:
print((-1))
exit()
idx = 1
cnt = 0
while True:
cnt += 1
if a[idx - 1] == 2:
print(cnt)
exit()
else:
if visited[idx - 1] == True:
print((-1))
exit()
else:
visited[idx - 1] = True
idx = a[idx - 1] ##次のボタン | def main():
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = [int(eval(input())) - 1 for _ in range(N)]
cur = 0
cnt = [-1] * N
cnt[0] = 0
while cur != 1:
c = cnt[cur]
cur = a[cur]
if ~cnt[cur]: break
cnt[cur] = c + 1
print((cnt[1] if ~cnt[1] else -1))
if __name__ == '__main__':
main()
| 22 | 22 | 456 | 387 | n = int(eval(input()))
a = list(map(int, list(eval(input()) for _ in range(n))))
visited = list(False for _ in range(n))
if (2 in a) == False:
print((-1))
exit()
idx = 1
cnt = 0
while True:
cnt += 1
if a[idx - 1] == 2:
print(cnt)
exit()
else:
if visited[idx - 1] == True:
print((-1))
exit()
else:
visited[idx - 1] = True
idx = a[idx - 1] ##次のボタン
| def main():
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = [int(eval(input())) - 1 for _ in range(N)]
cur = 0
cnt = [-1] * N
cnt[0] = 0
while cur != 1:
c = cnt[cur]
cur = a[cur]
if ~cnt[cur]:
break
cnt[cur] = c + 1
print((cnt[1] if ~cnt[1] else -1))
if __name__ == "__main__":
main()
| false | 0 | [
"-n = int(eval(input()))",
"-a = list(map(int, list(eval(input()) for _ in range(n))))",
"-visited = list(False for _ in range(n))",
"-if (2 in a) == False:",
"- print((-1))",
"- exit()",
"-idx = 1",
"-cnt = 0",
"-while True:",
"- cnt += 1",
"- if a[idx - 1] == 2:",
"- print(cnt)",
"- exit()",
"- else:",
"- if visited[idx - 1] == True:",
"- print((-1))",
"- exit()",
"- else:",
"- visited[idx - 1] = True",
"- idx = a[idx - 1] ##次のボタン",
"+def main():",
"+ import sys",
"+",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ a = [int(eval(input())) - 1 for _ in range(N)]",
"+ cur = 0",
"+ cnt = [-1] * N",
"+ cnt[0] = 0",
"+ while cur != 1:",
"+ c = cnt[cur]",
"+ cur = a[cur]",
"+ if ~cnt[cur]:",
"+ break",
"+ cnt[cur] = c + 1",
"+ print((cnt[1] if ~cnt[1] else -1))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.091379 | 0.035881 | 2.546764 | [
"s541713701",
"s362392151"
]
|
u931462344 | p03680 | python | s238525758 | s490100007 | 216 | 192 | 7,208 | 7,084 | Accepted | Accepted | 11.11 | import sys
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
cnt = 0
t = 1
for i in a:
t = a[t-1]
cnt += 1
if t == 2:
print(cnt)
sys.exit()
print("-1")
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
cnt = 0
tmp = 1
for i in A:
tmp = A[tmp-1]
cnt += 1
if tmp == 2:
print(cnt)
exit()
print("-1")
| 16 | 11 | 217 | 187 | import sys
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
cnt = 0
t = 1
for i in a:
t = a[t - 1]
cnt += 1
if t == 2:
print(cnt)
sys.exit()
print("-1")
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
cnt = 0
tmp = 1
for i in A:
tmp = A[tmp - 1]
cnt += 1
if tmp == 2:
print(cnt)
exit()
print("-1")
| false | 31.25 | [
"-import sys",
"-",
"-n = int(eval(input()))",
"-a = []",
"-for i in range(n):",
"- a.append(int(eval(input())))",
"+N = int(eval(input()))",
"+A = [int(eval(input())) for _ in range(N)]",
"-t = 1",
"-for i in a:",
"- t = a[t - 1]",
"+tmp = 1",
"+for i in A:",
"+ tmp = A[tmp - 1]",
"- if t == 2:",
"+ if tmp == 2:",
"- sys.exit()",
"+ exit()"
]
| false | 0.041143 | 0.043845 | 0.938363 | [
"s238525758",
"s490100007"
]
|
u547492399 | p02258 | python | s729406019 | s031258016 | 510 | 450 | 15,324 | 17,204 | Accepted | Accepted | 11.76 | debug = False
if debug:import time
if debug:start = time.time()
n = int(eval(input()))
R = [0]*n
R_min = 10**9
for i in range(n):
R[i] = int(eval(input()))
maximum_profit = -10**9
for i in range(1, n):
R_min = R[i-1] if R[i-1] < R_min else R_min
profit = R[i] - R_min
maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)
if debug:print((time.time() - start)) | debug = False
if debug:import time
if debug:start = time.time()
n = int(eval(input()))
R = [0]*n
R_min = 10**9
R = [int(eval(input())) for i in range(n)]
maximum_profit = -10**9
for i in range(1, n):
R_min = R[i-1] if R[i-1] < R_min else R_min
profit = R[i] - R_min
maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)
if debug:print((time.time() - start)) | 20 | 19 | 424 | 417 | debug = False
if debug:
import time
if debug:
start = time.time()
n = int(eval(input()))
R = [0] * n
R_min = 10**9
for i in range(n):
R[i] = int(eval(input()))
maximum_profit = -(10**9)
for i in range(1, n):
R_min = R[i - 1] if R[i - 1] < R_min else R_min
profit = R[i] - R_min
maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)
if debug:
print((time.time() - start))
| debug = False
if debug:
import time
if debug:
start = time.time()
n = int(eval(input()))
R = [0] * n
R_min = 10**9
R = [int(eval(input())) for i in range(n)]
maximum_profit = -(10**9)
for i in range(1, n):
R_min = R[i - 1] if R[i - 1] < R_min else R_min
profit = R[i] - R_min
maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)
if debug:
print((time.time() - start))
| false | 5 | [
"-for i in range(n):",
"- R[i] = int(eval(input()))",
"+R = [int(eval(input())) for i in range(n)]"
]
| false | 0.038097 | 0.043405 | 0.877713 | [
"s729406019",
"s031258016"
]
|
u145231176 | p02554 | python | s348237348 | s977152349 | 804 | 187 | 83,580 | 83,784 | Accepted | Accepted | 76.74 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
# 全て - 存在しない(1 ~ 8)まででできる
N = getN()
print(((pow(10, N, mod) - pow(9, N, mod) - pow(9, N, mod) + pow(8, N, mod)) % mod)) | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
logk = N.bit_length()
# 一般項が出ない場合でも
# 漸化式にできるなら行列計算に落とし込める
dp = [[[0, 0, 0, 0] for i in range(4)] for i in range(logk)]
dp[0] = [[8, 1, 1, 0], [0, 9, 0, 1], [0, 0, 9, 1], [0, 0, 0, 10]]
# 行列掛け算 O(n3)かかる
def array_cnt(ar1, ar2):
h = len(ar1)
w = len(ar2[0])
row = ar1
col = []
for j in range(w):
opt = []
for i in range(len(ar2)):
opt.append(ar2[i][j])
col.append(opt)
res = [[[0, 0] for i in range(w)] for i in range(h)]
for i in range(h):
for j in range(w):
cnt = 0
for x, y in zip(row[i], col[j]):
cnt += x * y
res[i][j] = cnt
res[i][j] %= mod
return res
for i in range(1, logk):
dp[i] = array_cnt(dp[i - 1], dp[i - 1])
ans = [[1, 0, 0, 0]]
for i in range(logk):
if N & (1 << i):
ans = array_cnt(ans, dp[i])
print((ans[0][-1] % mod)) | 54 | 90 | 1,459 | 2,291 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
# 全て - 存在しない(1 ~ 8)まででできる
N = getN()
print(((pow(10, N, mod) - pow(9, N, mod) - pow(9, N, mod) + pow(8, N, mod)) % mod))
| def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N = getN()
logk = N.bit_length()
# 一般項が出ない場合でも
# 漸化式にできるなら行列計算に落とし込める
dp = [[[0, 0, 0, 0] for i in range(4)] for i in range(logk)]
dp[0] = [[8, 1, 1, 0], [0, 9, 0, 1], [0, 0, 9, 1], [0, 0, 0, 10]]
# 行列掛け算 O(n3)かかる
def array_cnt(ar1, ar2):
h = len(ar1)
w = len(ar2[0])
row = ar1
col = []
for j in range(w):
opt = []
for i in range(len(ar2)):
opt.append(ar2[i][j])
col.append(opt)
res = [[[0, 0] for i in range(w)] for i in range(h)]
for i in range(h):
for j in range(w):
cnt = 0
for x, y in zip(row[i], col[j]):
cnt += x * y
res[i][j] = cnt
res[i][j] %= mod
return res
for i in range(1, logk):
dp[i] = array_cnt(dp[i - 1], dp[i - 1])
ans = [[1, 0, 0, 0]]
for i in range(logk):
if N & (1 << i):
ans = array_cnt(ans, dp[i])
print((ans[0][-1] % mod))
| false | 40 | [
"-# 全て - 存在しない(1 ~ 8)まででできる",
"-print(((pow(10, N, mod) - pow(9, N, mod) - pow(9, N, mod) + pow(8, N, mod)) % mod))",
"+logk = N.bit_length()",
"+# 一般項が出ない場合でも",
"+# 漸化式にできるなら行列計算に落とし込める",
"+dp = [[[0, 0, 0, 0] for i in range(4)] for i in range(logk)]",
"+dp[0] = [[8, 1, 1, 0], [0, 9, 0, 1], [0, 0, 9, 1], [0, 0, 0, 10]]",
"+# 行列掛け算 O(n3)かかる",
"+def array_cnt(ar1, ar2):",
"+ h = len(ar1)",
"+ w = len(ar2[0])",
"+ row = ar1",
"+ col = []",
"+ for j in range(w):",
"+ opt = []",
"+ for i in range(len(ar2)):",
"+ opt.append(ar2[i][j])",
"+ col.append(opt)",
"+ res = [[[0, 0] for i in range(w)] for i in range(h)]",
"+ for i in range(h):",
"+ for j in range(w):",
"+ cnt = 0",
"+ for x, y in zip(row[i], col[j]):",
"+ cnt += x * y",
"+ res[i][j] = cnt",
"+ res[i][j] %= mod",
"+ return res",
"+",
"+",
"+for i in range(1, logk):",
"+ dp[i] = array_cnt(dp[i - 1], dp[i - 1])",
"+ans = [[1, 0, 0, 0]]",
"+for i in range(logk):",
"+ if N & (1 << i):",
"+ ans = array_cnt(ans, dp[i])",
"+print((ans[0][-1] % mod))"
]
| false | 0.126342 | 0.11813 | 1.069519 | [
"s348237348",
"s977152349"
]
|
u496280557 | p03543 | python | s008114586 | s853610813 | 26 | 24 | 8,876 | 9,088 | Accepted | Accepted | 7.69 | N = eval(input(''))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print('Yes')
else:
print('No') | N = eval(input())
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3] :
print('Yes')
else:
print('No')
| 5 | 6 | 105 | 107 | N = eval(input(""))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print("Yes")
else:
print("No")
| N = eval(input())
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print("Yes")
else:
print("No")
| false | 16.666667 | [
"-N = eval(input(\"\"))",
"+N = eval(input())"
]
| false | 0.079677 | 0.04252 | 1.87389 | [
"s008114586",
"s853610813"
]
|
u588341295 | p02720 | python | s115393655 | s285575030 | 247 | 25 | 7,488 | 3,316 | Accepted | Accepted | 89.88 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
MAX = 3234566667
ans = []
def rec(x):
if int(x) > MAX:
return
ans.append(int(x))
last = int(x[-1])
rec(x+str(last))
if last != 0:
rec(x+str(last-1))
if last != 9:
rec(x+str(last+1))
return
K = INT()
for i in range(1, 10):
rec(str(i))
ans.sort()
print((ans[K-1]))
| # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_min(mn, mx, func):
ok = mx
ng = mn
while ng+1 < ok:
mid = (ok+ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def check(x):
x = str(x)
N = len(x)
dp0 = list2d(N+1, 10, 0)
dp1 = list2d(N+1, 10, 0)
a = int(x[0])
dp0[1][a] = 1
for j in range(1, a):
dp1[1][j] = 1
for i in range(2, N+1):
for j in range(1, 10):
dp1[i][j] = 1
for i, a in enumerate(x):
a = int(a)
for j in range(10):
for k in range(10):
if abs(j - k) >= 2:
continue
if k > a:
dp1[i+1][k] += dp1[i][j]
elif k == a:
dp0[i+1][k] += dp0[i][j]
dp1[i+1][k] += dp1[i][j]
else:
dp1[i+1][k] += dp0[i][j]
dp1[i+1][k] += dp1[i][j]
ans = sum(dp0[N]) + sum(dp1[N])
return ans >= K
K = INT()
res = bisearch_min(0, 10**10, check)
print(res)
| 42 | 65 | 1,071 | 1,834 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
MAX = 3234566667
ans = []
def rec(x):
if int(x) > MAX:
return
ans.append(int(x))
last = int(x[-1])
rec(x + str(last))
if last != 0:
rec(x + str(last - 1))
if last != 9:
rec(x + str(last + 1))
return
K = INT()
for i in range(1, 10):
rec(str(i))
ans.sort()
print((ans[K - 1]))
| # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def bisearch_min(mn, mx, func):
ok = mx
ng = mn
while ng + 1 < ok:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def check(x):
x = str(x)
N = len(x)
dp0 = list2d(N + 1, 10, 0)
dp1 = list2d(N + 1, 10, 0)
a = int(x[0])
dp0[1][a] = 1
for j in range(1, a):
dp1[1][j] = 1
for i in range(2, N + 1):
for j in range(1, 10):
dp1[i][j] = 1
for i, a in enumerate(x):
a = int(a)
for j in range(10):
for k in range(10):
if abs(j - k) >= 2:
continue
if k > a:
dp1[i + 1][k] += dp1[i][j]
elif k == a:
dp0[i + 1][k] += dp0[i][j]
dp1[i + 1][k] += dp1[i][j]
else:
dp1[i + 1][k] += dp0[i][j]
dp1[i + 1][k] += dp1[i][j]
ans = sum(dp0[N]) + sum(dp1[N])
return ans >= K
K = INT()
res = bisearch_min(0, 10**10, check)
print(res)
| false | 35.384615 | [
"-MAX = 3234566667",
"-ans = []",
"-def rec(x):",
"- if int(x) > MAX:",
"- return",
"- ans.append(int(x))",
"- last = int(x[-1])",
"- rec(x + str(last))",
"- if last != 0:",
"- rec(x + str(last - 1))",
"- if last != 9:",
"- rec(x + str(last + 1))",
"- return",
"+def bisearch_min(mn, mx, func):",
"+ ok = mx",
"+ ng = mn",
"+ while ng + 1 < ok:",
"+ mid = (ok + ng) // 2",
"+ if func(mid):",
"+ ok = mid",
"+ else:",
"+ ng = mid",
"+ return ok",
"+",
"+",
"+def check(x):",
"+ x = str(x)",
"+ N = len(x)",
"+ dp0 = list2d(N + 1, 10, 0)",
"+ dp1 = list2d(N + 1, 10, 0)",
"+ a = int(x[0])",
"+ dp0[1][a] = 1",
"+ for j in range(1, a):",
"+ dp1[1][j] = 1",
"+ for i in range(2, N + 1):",
"+ for j in range(1, 10):",
"+ dp1[i][j] = 1",
"+ for i, a in enumerate(x):",
"+ a = int(a)",
"+ for j in range(10):",
"+ for k in range(10):",
"+ if abs(j - k) >= 2:",
"+ continue",
"+ if k > a:",
"+ dp1[i + 1][k] += dp1[i][j]",
"+ elif k == a:",
"+ dp0[i + 1][k] += dp0[i][j]",
"+ dp1[i + 1][k] += dp1[i][j]",
"+ else:",
"+ dp1[i + 1][k] += dp0[i][j]",
"+ dp1[i + 1][k] += dp1[i][j]",
"+ ans = sum(dp0[N]) + sum(dp1[N])",
"+ return ans >= K",
"-for i in range(1, 10):",
"- rec(str(i))",
"-ans.sort()",
"-print((ans[K - 1]))",
"+res = bisearch_min(0, 10**10, check)",
"+print(res)"
]
| false | 0.954833 | 0.051413 | 18.571895 | [
"s115393655",
"s285575030"
]
|
u930705402 | p03111 | python | s718905300 | s373560759 | 388 | 108 | 3,444 | 3,064 | Accepted | Accepted | 72.16 | import itertools
n,a,b,c=list(map(int,input().split()))
x=[a,b,c]
l=[int(eval(input())) for i in range(n)]
ans=1000000
loop='012'
for i in range(2**n):
use=[]
for j in range(n):
if((i>>j)&1):
use.append(l[j])
if(len(use)>=3):
for j in (itertools.product(loop,repeat=len(use))):
A=[[] for i in range(3)]
for k in range(len(use)):
A[int(j[k])].append(use[k])
if(len(A[0])!=0 and len(A[1])!=0 and len(A[2])!=0):
res=0
for i in range(3):
res+=abs(sum(A[i])-x[i])+(len(A[i])-1)*10
ans=min(res,ans)
print(ans) | def check(s,e,t):
global ans
if(not s or not e or not t):
return
ans=min(ans,(len(s)-1)*10+abs(A-sum(s))+(len(e)-1)*10+abs(B-sum(e))+(len(t)-1)*10+abs(C-sum(t)))
def dfs(s,e,t,i):
if(i==N):
check(s,e,t)
return
dfs(s,e,t,i+1)
dfs(s+[l[i]],e,t,i+1)
dfs(s,e+[l[i]],t,i+1)
dfs(s,e,t+[l[i]],i+1)
N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for i in range(N)]
ans=10**18
dfs([],[],[],0)
print(ans) | 23 | 21 | 690 | 475 | import itertools
n, a, b, c = list(map(int, input().split()))
x = [a, b, c]
l = [int(eval(input())) for i in range(n)]
ans = 1000000
loop = "012"
for i in range(2**n):
use = []
for j in range(n):
if (i >> j) & 1:
use.append(l[j])
if len(use) >= 3:
for j in itertools.product(loop, repeat=len(use)):
A = [[] for i in range(3)]
for k in range(len(use)):
A[int(j[k])].append(use[k])
if len(A[0]) != 0 and len(A[1]) != 0 and len(A[2]) != 0:
res = 0
for i in range(3):
res += abs(sum(A[i]) - x[i]) + (len(A[i]) - 1) * 10
ans = min(res, ans)
print(ans)
| def check(s, e, t):
global ans
if not s or not e or not t:
return
ans = min(
ans,
(len(s) - 1) * 10
+ abs(A - sum(s))
+ (len(e) - 1) * 10
+ abs(B - sum(e))
+ (len(t) - 1) * 10
+ abs(C - sum(t)),
)
def dfs(s, e, t, i):
if i == N:
check(s, e, t)
return
dfs(s, e, t, i + 1)
dfs(s + [l[i]], e, t, i + 1)
dfs(s, e + [l[i]], t, i + 1)
dfs(s, e, t + [l[i]], i + 1)
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
ans = 10**18
dfs([], [], [], 0)
print(ans)
| false | 8.695652 | [
"-import itertools",
"+def check(s, e, t):",
"+ global ans",
"+ if not s or not e or not t:",
"+ return",
"+ ans = min(",
"+ ans,",
"+ (len(s) - 1) * 10",
"+ + abs(A - sum(s))",
"+ + (len(e) - 1) * 10",
"+ + abs(B - sum(e))",
"+ + (len(t) - 1) * 10",
"+ + abs(C - sum(t)),",
"+ )",
"-n, a, b, c = list(map(int, input().split()))",
"-x = [a, b, c]",
"-l = [int(eval(input())) for i in range(n)]",
"-ans = 1000000",
"-loop = \"012\"",
"-for i in range(2**n):",
"- use = []",
"- for j in range(n):",
"- if (i >> j) & 1:",
"- use.append(l[j])",
"- if len(use) >= 3:",
"- for j in itertools.product(loop, repeat=len(use)):",
"- A = [[] for i in range(3)]",
"- for k in range(len(use)):",
"- A[int(j[k])].append(use[k])",
"- if len(A[0]) != 0 and len(A[1]) != 0 and len(A[2]) != 0:",
"- res = 0",
"- for i in range(3):",
"- res += abs(sum(A[i]) - x[i]) + (len(A[i]) - 1) * 10",
"- ans = min(res, ans)",
"+",
"+def dfs(s, e, t, i):",
"+ if i == N:",
"+ check(s, e, t)",
"+ return",
"+ dfs(s, e, t, i + 1)",
"+ dfs(s + [l[i]], e, t, i + 1)",
"+ dfs(s, e + [l[i]], t, i + 1)",
"+ dfs(s, e, t + [l[i]], i + 1)",
"+",
"+",
"+N, A, B, C = list(map(int, input().split()))",
"+l = [int(eval(input())) for i in range(N)]",
"+ans = 10**18",
"+dfs([], [], [], 0)"
]
| false | 0.922315 | 0.081886 | 11.26336 | [
"s718905300",
"s373560759"
]
|
u606045429 | p02651 | python | s033446897 | s163759280 | 165 | 150 | 9,084 | 9,148 | Accepted | Accepted | 9.09 | T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = eval(input())
B = []
ans = 0
for a, s in zip(reversed(A), reversed(S)):
for b in B:
a = min(a, a ^ b)
if a:
if s == "1":
ans = 1
break
else:
B.append(a)
print(ans) | T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = eval(input())
B = []
ans = 0
for a, s in zip(reversed(A), reversed(S)):
for b in B:
a = min(a, a ^ b)
if a:
if s == "1":
ans = 1
break
B.append(a)
print(ans) | 20 | 19 | 402 | 379 | T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = eval(input())
B = []
ans = 0
for a, s in zip(reversed(A), reversed(S)):
for b in B:
a = min(a, a ^ b)
if a:
if s == "1":
ans = 1
break
else:
B.append(a)
print(ans)
| T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = eval(input())
B = []
ans = 0
for a, s in zip(reversed(A), reversed(S)):
for b in B:
a = min(a, a ^ b)
if a:
if s == "1":
ans = 1
break
B.append(a)
print(ans)
| false | 5 | [
"- else:",
"- B.append(a)",
"+ B.append(a)"
]
| false | 0.131939 | 0.049257 | 2.678614 | [
"s033446897",
"s163759280"
]
|
u144913062 | p02549 | python | s921688059 | s828784256 | 318 | 100 | 70,096 | 69,688 | Accepted | Accepted | 68.55 | import sys
input = sys.stdin.readline
class FenwickTree:
def __init__(self, size):
self.bit = [0] * (size + 1)
self.size = size
def sum(self, i):
i += 1
s = 0
while i > 0:
s += self.bit[i]
s %= mod
i -= i & -i
return s
def add(self, i, x):
i += 1
while i <= self.size:
self.bit[i] += x
self.bit[i] %= mod
i += i & -i
mod = 998244353
N, K = list(map(int, input().split()))
L, R = list(zip(*[list(map(int, input().split())) for _ in range(K)]))
dp = FenwickTree(N + 1)
dp.add(1, 1)
dp.add(2, -1)
for i in range(1, N):
x = dp.sum(i)
for j in range(K):
dp.add(i + L[j], x)
if i + R[j] + 1 <= N:
dp.add(i + R[j] + 1, -x)
print((dp.sum(N))) | import sys
input = sys.stdin.readline
mod = 998244353
N, K = list(map(int, input().split()))
L, R = list(zip(*[list(map(int, input().split())) for _ in range(K)]))
dp = [0] * (N + 1)
dp[1] = 1
dp[2] = -1
x = 0
for i in range(1, N):
x = (x + dp[i]) % mod
for j in range(K):
if i + L[j] > N:
continue
dp[i + L[j]] = (dp[i + L[j]] + x) % mod
if i + R[j] + 1 <= N:
dp[i + R[j] + 1] = (dp[i + R[j] + 1] - x) % mod
x = (x + dp[N]) % mod
print(x) | 37 | 20 | 844 | 503 | import sys
input = sys.stdin.readline
class FenwickTree:
def __init__(self, size):
self.bit = [0] * (size + 1)
self.size = size
def sum(self, i):
i += 1
s = 0
while i > 0:
s += self.bit[i]
s %= mod
i -= i & -i
return s
def add(self, i, x):
i += 1
while i <= self.size:
self.bit[i] += x
self.bit[i] %= mod
i += i & -i
mod = 998244353
N, K = list(map(int, input().split()))
L, R = list(zip(*[list(map(int, input().split())) for _ in range(K)]))
dp = FenwickTree(N + 1)
dp.add(1, 1)
dp.add(2, -1)
for i in range(1, N):
x = dp.sum(i)
for j in range(K):
dp.add(i + L[j], x)
if i + R[j] + 1 <= N:
dp.add(i + R[j] + 1, -x)
print((dp.sum(N)))
| import sys
input = sys.stdin.readline
mod = 998244353
N, K = list(map(int, input().split()))
L, R = list(zip(*[list(map(int, input().split())) for _ in range(K)]))
dp = [0] * (N + 1)
dp[1] = 1
dp[2] = -1
x = 0
for i in range(1, N):
x = (x + dp[i]) % mod
for j in range(K):
if i + L[j] > N:
continue
dp[i + L[j]] = (dp[i + L[j]] + x) % mod
if i + R[j] + 1 <= N:
dp[i + R[j] + 1] = (dp[i + R[j] + 1] - x) % mod
x = (x + dp[N]) % mod
print(x)
| false | 45.945946 | [
"-",
"-",
"-class FenwickTree:",
"- def __init__(self, size):",
"- self.bit = [0] * (size + 1)",
"- self.size = size",
"-",
"- def sum(self, i):",
"- i += 1",
"- s = 0",
"- while i > 0:",
"- s += self.bit[i]",
"- s %= mod",
"- i -= i & -i",
"- return s",
"-",
"- def add(self, i, x):",
"- i += 1",
"- while i <= self.size:",
"- self.bit[i] += x",
"- self.bit[i] %= mod",
"- i += i & -i",
"-",
"-",
"-dp = FenwickTree(N + 1)",
"-dp.add(1, 1)",
"-dp.add(2, -1)",
"+dp = [0] * (N + 1)",
"+dp[1] = 1",
"+dp[2] = -1",
"+x = 0",
"- x = dp.sum(i)",
"+ x = (x + dp[i]) % mod",
"- dp.add(i + L[j], x)",
"+ if i + L[j] > N:",
"+ continue",
"+ dp[i + L[j]] = (dp[i + L[j]] + x) % mod",
"- dp.add(i + R[j] + 1, -x)",
"-print((dp.sum(N)))",
"+ dp[i + R[j] + 1] = (dp[i + R[j] + 1] - x) % mod",
"+x = (x + dp[N]) % mod",
"+print(x)"
]
| false | 0.037064 | 0.036526 | 1.014734 | [
"s921688059",
"s828784256"
]
|
u926412290 | p03645 | python | s967688652 | s227516165 | 503 | 419 | 112,736 | 108,776 | Accepted | Accepted | 16.7 | from collections import deque
N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
to[a].append(b)
to[b].append(a)
que = deque()
que.append(0)
dist = [-1] * N
dist[0] = 0
while que:
island = que.popleft()
for nxt in to[island]:
if dist[nxt] != -1:
continue
que.append(nxt)
dist[nxt] = dist[island] + 1
print(('POSSIBLE' if dist[N - 1] == 2 else 'IMPOSSIBLE')) | N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
ans = 'IMPOSSIBLE'
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
to[a].append(b)
to[b].append(a)
for nxt in to[0]:
if N - 1 in to[nxt]:
ans = 'POSSIBLE'
break
print(ans) | 25 | 16 | 539 | 322 | from collections import deque
N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
to[a].append(b)
to[b].append(a)
que = deque()
que.append(0)
dist = [-1] * N
dist[0] = 0
while que:
island = que.popleft()
for nxt in to[island]:
if dist[nxt] != -1:
continue
que.append(nxt)
dist[nxt] = dist[island] + 1
print(("POSSIBLE" if dist[N - 1] == 2 else "IMPOSSIBLE"))
| N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
ans = "IMPOSSIBLE"
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
to[a].append(b)
to[b].append(a)
for nxt in to[0]:
if N - 1 in to[nxt]:
ans = "POSSIBLE"
break
print(ans)
| false | 36 | [
"-from collections import deque",
"-",
"+ans = \"IMPOSSIBLE\"",
"-que = deque()",
"-que.append(0)",
"-dist = [-1] * N",
"-dist[0] = 0",
"-while que:",
"- island = que.popleft()",
"- for nxt in to[island]:",
"- if dist[nxt] != -1:",
"- continue",
"- que.append(nxt)",
"- dist[nxt] = dist[island] + 1",
"-print((\"POSSIBLE\" if dist[N - 1] == 2 else \"IMPOSSIBLE\"))",
"+for nxt in to[0]:",
"+ if N - 1 in to[nxt]:",
"+ ans = \"POSSIBLE\"",
"+ break",
"+print(ans)"
]
| false | 0.038123 | 0.102899 | 0.370493 | [
"s967688652",
"s227516165"
]
|
u078042885 | p00062 | python | s364460417 | s272220179 | 30 | 20 | 7,656 | 7,648 | Accepted | Accepted | 33.33 | while 1:
try:n=eval(input())
except:break
n=list(map(int,n))
while len(n)>1:
n= [(i+j)%10 for i,j in zip(n[:-1],n[1:])]
print((*n)) | while 1:
try:n=eval(input())
except:break
while len(n)>1:
n= [(int(i)+int(j))%10 for i,j in zip(n[:-1],n[1:])]
print((*n)) | 7 | 6 | 157 | 143 | while 1:
try:
n = eval(input())
except:
break
n = list(map(int, n))
while len(n) > 1:
n = [(i + j) % 10 for i, j in zip(n[:-1], n[1:])]
print((*n))
| while 1:
try:
n = eval(input())
except:
break
while len(n) > 1:
n = [(int(i) + int(j)) % 10 for i, j in zip(n[:-1], n[1:])]
print((*n))
| false | 14.285714 | [
"- n = list(map(int, n))",
"- n = [(i + j) % 10 for i, j in zip(n[:-1], n[1:])]",
"+ n = [(int(i) + int(j)) % 10 for i, j in zip(n[:-1], n[1:])]"
]
| false | 0.033879 | 0.06453 | 0.525013 | [
"s364460417",
"s272220179"
]
|
u077291787 | p03274 | python | s822710845 | s390637067 | 91 | 60 | 14,352 | 14,768 | Accepted | Accepted | 34.07 | # ABC107C - Candles (ARC101C)
def main():
n, k = tuple(map(int, input().rstrip().split()))
x = tuple(map(int, input().rstrip().split()))
ans = float("inf")
for i in range(n - k + 1):
a, b = x[i], x[i + k - 1]
if a < b < 0 or 0 < a < b:
ans = min(ans, max(abs(a), abs(b)))
else:
ans = min(ans, max(abs(a), abs(b)) + min(abs(a), abs(b)) * 2)
print(ans)
if __name__ == "__main__":
main() | # ABC107C - Candles (ARC101C)
def main():
_, k = list(map(int, input().split()))
x = tuple(map(int, input().split()))
print((min(r - l + min(abs(l), abs(r)) for l, r in zip(x, x[k - 1 :]))))
if __name__ == "__main__":
main() | 16 | 9 | 473 | 242 | # ABC107C - Candles (ARC101C)
def main():
n, k = tuple(map(int, input().rstrip().split()))
x = tuple(map(int, input().rstrip().split()))
ans = float("inf")
for i in range(n - k + 1):
a, b = x[i], x[i + k - 1]
if a < b < 0 or 0 < a < b:
ans = min(ans, max(abs(a), abs(b)))
else:
ans = min(ans, max(abs(a), abs(b)) + min(abs(a), abs(b)) * 2)
print(ans)
if __name__ == "__main__":
main()
| # ABC107C - Candles (ARC101C)
def main():
_, k = list(map(int, input().split()))
x = tuple(map(int, input().split()))
print((min(r - l + min(abs(l), abs(r)) for l, r in zip(x, x[k - 1 :]))))
if __name__ == "__main__":
main()
| false | 43.75 | [
"- n, k = tuple(map(int, input().rstrip().split()))",
"- x = tuple(map(int, input().rstrip().split()))",
"- ans = float(\"inf\")",
"- for i in range(n - k + 1):",
"- a, b = x[i], x[i + k - 1]",
"- if a < b < 0 or 0 < a < b:",
"- ans = min(ans, max(abs(a), abs(b)))",
"- else:",
"- ans = min(ans, max(abs(a), abs(b)) + min(abs(a), abs(b)) * 2)",
"- print(ans)",
"+ _, k = list(map(int, input().split()))",
"+ x = tuple(map(int, input().split()))",
"+ print((min(r - l + min(abs(l), abs(r)) for l, r in zip(x, x[k - 1 :]))))"
]
| false | 0.044 | 0.081053 | 0.542855 | [
"s822710845",
"s390637067"
]
|
u966207392 | p02607 | python | s913803643 | s571390000 | 31 | 26 | 9,052 | 9,080 | Accepted | Accepted | 16.13 | N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N):
if (i+1) % 2 != 0 and a[i] % 2 != 0:
cnt += 1
print(cnt) | N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N, 2):
if a[i] % 2 != 0:
cnt += 1
print(cnt) | 7 | 7 | 157 | 141 | N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N):
if (i + 1) % 2 != 0 and a[i] % 2 != 0:
cnt += 1
print(cnt)
| N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N, 2):
if a[i] % 2 != 0:
cnt += 1
print(cnt)
| false | 0 | [
"-for i in range(0, N):",
"- if (i + 1) % 2 != 0 and a[i] % 2 != 0:",
"+for i in range(0, N, 2):",
"+ if a[i] % 2 != 0:"
]
| false | 0.040138 | 0.040586 | 0.988954 | [
"s913803643",
"s571390000"
]
|
u380524497 | p03416 | python | s399224869 | s975883981 | 63 | 44 | 2,940 | 2,940 | Accepted | Accepted | 30.16 | a, b = list(map(int, input().split()))
count = 0
for i in range(a, b+1):
if str(i) == str(i)[::-1]:
count += 1
print(count)
| a, b = list(map(int, input().split()))
ans = 0
for num in range(a, b+1):
s = str(num)
if s[0] == s[4] and s[1] == s[3]:
ans += 1
print(ans) | 8 | 9 | 139 | 159 | a, b = list(map(int, input().split()))
count = 0
for i in range(a, b + 1):
if str(i) == str(i)[::-1]:
count += 1
print(count)
| a, b = list(map(int, input().split()))
ans = 0
for num in range(a, b + 1):
s = str(num)
if s[0] == s[4] and s[1] == s[3]:
ans += 1
print(ans)
| false | 11.111111 | [
"-count = 0",
"-for i in range(a, b + 1):",
"- if str(i) == str(i)[::-1]:",
"- count += 1",
"-print(count)",
"+ans = 0",
"+for num in range(a, b + 1):",
"+ s = str(num)",
"+ if s[0] == s[4] and s[1] == s[3]:",
"+ ans += 1",
"+print(ans)"
]
| false | 0.060407 | 0.053112 | 1.137349 | [
"s399224869",
"s975883981"
]
|
u347600233 | p02952 | python | s426081507 | s290266892 | 58 | 52 | 2,940 | 9,100 | Accepted | Accepted | 10.34 | n = int(eval(input()))
cnt = 0
for i in range(1, n + 1):
if len(str(i)) % 2:
cnt += 1
print(cnt) | n = int(eval(input()))
print((sum(len(str(i + 1)) % 2 for i in range(n)))) | 6 | 2 | 107 | 67 | n = int(eval(input()))
cnt = 0
for i in range(1, n + 1):
if len(str(i)) % 2:
cnt += 1
print(cnt)
| n = int(eval(input()))
print((sum(len(str(i + 1)) % 2 for i in range(n))))
| false | 66.666667 | [
"-cnt = 0",
"-for i in range(1, n + 1):",
"- if len(str(i)) % 2:",
"- cnt += 1",
"-print(cnt)",
"+print((sum(len(str(i + 1)) % 2 for i in range(n))))"
]
| false | 0.053585 | 0.04474 | 1.19771 | [
"s426081507",
"s290266892"
]
|
u133936772 | p03013 | python | s951059349 | s323963688 | 1,668 | 187 | 7,080 | 3,828 | Accepted | Accepted | 88.79 | mod = 10**9+7
n, m = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(m)]
t2 = 0
t1 = 1
for i in range(1,n+1):
if l == [] or i != l[0]:
t0 = (t2+t1)%mod
else:
l.pop(0)
t0 = 0
t2 = t1
t1 = t0
print(t0) | mod = 10**9+7
n, m = list(map(int, input().split()))
l = [0]*n
for _ in range(m):
l[int(eval(input()))-1] = 1
s = 0
t = 1
for i in range(n):
if l[i] > 0:
t, s = 0, t
else:
t, s = (s+t)%mod, t
print(t) | 17 | 16 | 249 | 220 | mod = 10**9 + 7
n, m = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(m)]
t2 = 0
t1 = 1
for i in range(1, n + 1):
if l == [] or i != l[0]:
t0 = (t2 + t1) % mod
else:
l.pop(0)
t0 = 0
t2 = t1
t1 = t0
print(t0)
| mod = 10**9 + 7
n, m = list(map(int, input().split()))
l = [0] * n
for _ in range(m):
l[int(eval(input())) - 1] = 1
s = 0
t = 1
for i in range(n):
if l[i] > 0:
t, s = 0, t
else:
t, s = (s + t) % mod, t
print(t)
| false | 5.882353 | [
"-l = [int(eval(input())) for _ in range(m)]",
"-t2 = 0",
"-t1 = 1",
"-for i in range(1, n + 1):",
"- if l == [] or i != l[0]:",
"- t0 = (t2 + t1) % mod",
"+l = [0] * n",
"+for _ in range(m):",
"+ l[int(eval(input())) - 1] = 1",
"+s = 0",
"+t = 1",
"+for i in range(n):",
"+ if l[i] > 0:",
"+ t, s = 0, t",
"- l.pop(0)",
"- t0 = 0",
"- t2 = t1",
"- t1 = t0",
"-print(t0)",
"+ t, s = (s + t) % mod, t",
"+print(t)"
]
| false | 0.03659 | 0.03503 | 1.044525 | [
"s951059349",
"s323963688"
]
|
u975771310 | p02725 | python | s310849709 | s526981491 | 107 | 97 | 26,444 | 25,836 | Accepted | Accepted | 9.35 | def main():
K, N = list(map(int, input().split()))
A = list(map( int, input().split() ))
dist = []
for i in range(N):
if i!=N-1:
dist.append(A[i+1]-A[i])
else:
dist.append(K-A[i]+A[0])
ans = sum(dist)-max(dist)
print(("{}".format(ans)))
if __name__=="__main__":
main() | def main():
K, N = list(map(int, input().split()))
A = list(map( int, input().split() ))
dist = []
for i in range(N-1):
dist.append(A[i+1]-A[i])
dist.append(K-A[N-1]+A[0])
ans = sum(dist) - max(dist)
print(("{}".format(ans)))
if __name__=="__main__":
main() | 19 | 16 | 420 | 349 | def main():
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
dist = []
for i in range(N):
if i != N - 1:
dist.append(A[i + 1] - A[i])
else:
dist.append(K - A[i] + A[0])
ans = sum(dist) - max(dist)
print(("{}".format(ans)))
if __name__ == "__main__":
main()
| def main():
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
dist = []
for i in range(N - 1):
dist.append(A[i + 1] - A[i])
dist.append(K - A[N - 1] + A[0])
ans = sum(dist) - max(dist)
print(("{}".format(ans)))
if __name__ == "__main__":
main()
| false | 15.789474 | [
"- for i in range(N):",
"- if i != N - 1:",
"- dist.append(A[i + 1] - A[i])",
"- else:",
"- dist.append(K - A[i] + A[0])",
"+ for i in range(N - 1):",
"+ dist.append(A[i + 1] - A[i])",
"+ dist.append(K - A[N - 1] + A[0])"
]
| false | 0.048021 | 0.047904 | 1.002422 | [
"s310849709",
"s526981491"
]
|
u628335443 | p02695 | python | s603621567 | s212292742 | 1,102 | 664 | 9,212 | 9,236 | Accepted | Accepted | 39.75 | from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
ans = 0
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
for seq in combinations_with_replacement([i for i in range(1, m+1)], n):
now = 0
for j in range(q):
if seq[b[j] - 1] - seq[a[j] - 1] == c[j]:
now += d[j]
ans = max(ans, now)
print(ans)
| def dfs(A):
global ans
if len(A) == n + 1:
now = 0
for j in range(q):
if A[b[j]] - A[a[j]] == c[j]:
now += d[j]
ans = max(ans, now)
return
B = list(A)
B.append(A[-1])
while B[-1] <= m:
dfs(tuple(B))
B[-1] += 1
n, m, q = list(map(int, input().split()))
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
ans = 0
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
dfs(tuple([1]))
print(ans)
| 20 | 30 | 458 | 534 | from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
ans = 0
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
for seq in combinations_with_replacement([i for i in range(1, m + 1)], n):
now = 0
for j in range(q):
if seq[b[j] - 1] - seq[a[j] - 1] == c[j]:
now += d[j]
ans = max(ans, now)
print(ans)
| def dfs(A):
global ans
if len(A) == n + 1:
now = 0
for j in range(q):
if A[b[j]] - A[a[j]] == c[j]:
now += d[j]
ans = max(ans, now)
return
B = list(A)
B.append(A[-1])
while B[-1] <= m:
dfs(tuple(B))
B[-1] += 1
n, m, q = list(map(int, input().split()))
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
ans = 0
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
dfs(tuple([1]))
print(ans)
| false | 33.333333 | [
"-from itertools import combinations_with_replacement",
"+def dfs(A):",
"+ global ans",
"+ if len(A) == n + 1:",
"+ now = 0",
"+ for j in range(q):",
"+ if A[b[j]] - A[a[j]] == c[j]:",
"+ now += d[j]",
"+ ans = max(ans, now)",
"+ return",
"+ B = list(A)",
"+ B.append(A[-1])",
"+ while B[-1] <= m:",
"+ dfs(tuple(B))",
"+ B[-1] += 1",
"+",
"-for seq in combinations_with_replacement([i for i in range(1, m + 1)], n):",
"- now = 0",
"- for j in range(q):",
"- if seq[b[j] - 1] - seq[a[j] - 1] == c[j]:",
"- now += d[j]",
"- ans = max(ans, now)",
"+dfs(tuple([1]))"
]
| false | 0.149795 | 0.073064 | 2.050189 | [
"s603621567",
"s212292742"
]
|
u968166680 | p02814 | python | s586346696 | s882443062 | 404 | 113 | 96,824 | 16,148 | Accepted | Accepted | 72.03 | import sys
from fractions import gcd
from functools import reduce
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def lcm(x, y):
return x * y // gcd(x, y)
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
semi_lcm = reduce(lcm, A)
for a in A[1:]:
semi_lcm = lcm(semi_lcm, a)
if semi_lcm > M or semi_lcm // a % 2 == 0:
print((0))
return
print(((M // semi_lcm + 1) // 2))
return
if __name__ == '__main__':
main()
| import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def lcm(x, y):
return x * y // gcd(x, y)
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
semi_lcm = A[0]
for a in A[1:]:
semi_lcm = lcm(semi_lcm, a)
if semi_lcm > M or semi_lcm // a % 2 == 0:
print((0))
return
print(((M // semi_lcm + 1) // 2))
return
if __name__ == '__main__':
main()
| 32 | 31 | 622 | 582 | import sys
from fractions import gcd
from functools import reduce
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def lcm(x, y):
return x * y // gcd(x, y)
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
semi_lcm = reduce(lcm, A)
for a in A[1:]:
semi_lcm = lcm(semi_lcm, a)
if semi_lcm > M or semi_lcm // a % 2 == 0:
print((0))
return
print(((M // semi_lcm + 1) // 2))
return
if __name__ == "__main__":
main()
| import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def lcm(x, y):
return x * y // gcd(x, y)
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
semi_lcm = A[0]
for a in A[1:]:
semi_lcm = lcm(semi_lcm, a)
if semi_lcm > M or semi_lcm // a % 2 == 0:
print((0))
return
print(((M // semi_lcm + 1) // 2))
return
if __name__ == "__main__":
main()
| false | 3.125 | [
"-from functools import reduce",
"- semi_lcm = reduce(lcm, A)",
"+ semi_lcm = A[0]"
]
| false | 0.074044 | 0.0457 | 1.620237 | [
"s586346696",
"s882443062"
]
|
u836939578 | p03043 | python | s561227633 | s162175282 | 352 | 66 | 153,000 | 72,088 | Accepted | Accepted | 81.25 | import sys
input = lambda: sys.stdin.readline().rstrip()
from decimal import *
N, K = list(map(int, input().split()))
x = Decimal("0.5")
ans = 0
for i in range(1, N+1):
p = 1
while i < K:
i *= 2
p *= x
ans += p
ans /= N
print(ans) | N, K = list(map(int, input().split()))
ans = 0
def calc(x, goal):
res = 0
while x < goal:
x *= 2
res += 1
return res
for i in range(1, N+1):
cnt = calc(i, K)
ans += 1 / N * ((1 / 2) ** cnt)
print(ans) | 16 | 17 | 272 | 255 | import sys
input = lambda: sys.stdin.readline().rstrip()
from decimal import *
N, K = list(map(int, input().split()))
x = Decimal("0.5")
ans = 0
for i in range(1, N + 1):
p = 1
while i < K:
i *= 2
p *= x
ans += p
ans /= N
print(ans)
| N, K = list(map(int, input().split()))
ans = 0
def calc(x, goal):
res = 0
while x < goal:
x *= 2
res += 1
return res
for i in range(1, N + 1):
cnt = calc(i, K)
ans += 1 / N * ((1 / 2) ** cnt)
print(ans)
| false | 5.882353 | [
"-import sys",
"+N, K = list(map(int, input().split()))",
"+ans = 0",
"-input = lambda: sys.stdin.readline().rstrip()",
"-from decimal import *",
"-N, K = list(map(int, input().split()))",
"-x = Decimal(\"0.5\")",
"-ans = 0",
"+def calc(x, goal):",
"+ res = 0",
"+ while x < goal:",
"+ x *= 2",
"+ res += 1",
"+ return res",
"+",
"+",
"- p = 1",
"- while i < K:",
"- i *= 2",
"- p *= x",
"- ans += p",
"-ans /= N",
"+ cnt = calc(i, K)",
"+ ans += 1 / N * ((1 / 2) ** cnt)"
]
| false | 0.058049 | 0.057547 | 1.008724 | [
"s561227633",
"s162175282"
]
|
u133936772 | p02630 | python | s943160420 | s142773143 | 531 | 479 | 21,640 | 18,536 | Accepted | Accepted | 9.79 | f=lambda:[*list(map(int,input().split()))]
f()
s,*l=[0]*100002
for i in f(): s+=i; l[i]+=1
q=f()[0]
for _ in range(q): b,c=f(); s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s) | f=lambda:list(map(int,input().split()))
f()
s,*l=[0]*100002
for i in f(): s+=i; l[i]+=1
q,=f()
for _ in range(q): b,c=f(); s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s) | 6 | 6 | 170 | 165 | f = lambda: [*list(map(int, input().split()))]
f()
s, *l = [0] * 100002
for i in f():
s += i
l[i] += 1
q = f()[0]
for _ in range(q):
b, c = f()
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| f = lambda: list(map(int, input().split()))
f()
s, *l = [0] * 100002
for i in f():
s += i
l[i] += 1
(q,) = f()
for _ in range(q):
b, c = f()
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| false | 0 | [
"-f = lambda: [*list(map(int, input().split()))]",
"+f = lambda: list(map(int, input().split()))",
"-q = f()[0]",
"+(q,) = f()"
]
| false | 0.091857 | 0.085098 | 1.079423 | [
"s943160420",
"s142773143"
]
|
u102461423 | p02609 | python | s680336079 | s975869111 | 1,213 | 1,039 | 137,820 | 138,228 | Accepted | Accepted | 14.34 | import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
X = np.array(list(read().rstrip()), np.int64) - ord('0')
@njit((i8, ), cache=True)
def popcount(n):
ret = 0
while n:
ret += n & 1
n >>= 1
return ret
@njit((i8, ), cache=True)
def f(n):
t = 0
while n:
t += 1
n %= popcount(n)
return t
@njit(cache=True)
def main(X):
popX = X.sum()
MOD1 = popX + 1
MOD2 = popX - 1
if popX == 1:
MOD2 = 1
pow1 = np.ones_like(X)
pow2 = np.ones_like(X)
for n in range(1, len(X)):
pow1[n] = 2 * pow1[n - 1] % MOD1
pow2[n] = 2 * pow2[n - 1] % MOD2
X1, X2 = 0, 0
for x in X:
X1 = (2 * X1 + x) % MOD1
X2 = (2 * X2 + x) % MOD2
ans = np.empty(N, np.int64)
for i in range(N):
x = X[N - 1 - i]
if x == 0:
nxt = (X1 + pow1[i]) % (popX + 1)
ans[i] = 1 + f(nxt)
elif x == 1:
if popX == 1:
ans[i] = 0
else:
nxt = (X2 - pow2[i]) % (popX - 1)
ans[i] = 1 + f(nxt)
return ans[::-1]
ans = main(X)
print(('\n'.join(map(str, ans.tolist())))) | import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8, ), cache=True)
def popcount(n):
ret = 0
while n:
ret += n & 1
n >>= 1
return ret
@njit((i8, ), cache=True)
def f(n):
t = 0
while n:
t += 1
n %= popcount(n)
return t
@njit(cache=True)
def main(X):
popX = X.sum()
MOD1 = popX + 1
MOD2 = popX - 1
if popX == 1:
MOD2 = 1
pow1 = np.ones_like(X)
pow2 = np.ones_like(X)
for n in range(1, len(X)):
pow1[n] = 2 * pow1[n - 1] % MOD1
pow2[n] = 2 * pow2[n - 1] % MOD2
X1, X2 = 0, 0
for x in X:
X1 = (2 * X1 + x) % MOD1
X2 = (2 * X2 + x) % MOD2
ans = np.empty(N, np.int64)
for i in range(N):
x = X[N - 1 - i]
if x == 0:
nxt = (X1 + pow1[i]) % (popX + 1)
ans[i] = 1 + f(nxt)
elif x == 1:
if popX == 1:
ans[i] = 0
else:
nxt = (X2 - pow2[i]) % (popX - 1)
ans[i] = 1 + f(nxt)
return ans[::-1]
N = int(readline())
X = np.array(list(read().rstrip()), np.int64) - ord('0')
ans = main(X)
print(('\n'.join(map(str, ans.tolist()))))
| 65 | 64 | 1,393 | 1,392 | import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
X = np.array(list(read().rstrip()), np.int64) - ord("0")
@njit((i8,), cache=True)
def popcount(n):
ret = 0
while n:
ret += n & 1
n >>= 1
return ret
@njit((i8,), cache=True)
def f(n):
t = 0
while n:
t += 1
n %= popcount(n)
return t
@njit(cache=True)
def main(X):
popX = X.sum()
MOD1 = popX + 1
MOD2 = popX - 1
if popX == 1:
MOD2 = 1
pow1 = np.ones_like(X)
pow2 = np.ones_like(X)
for n in range(1, len(X)):
pow1[n] = 2 * pow1[n - 1] % MOD1
pow2[n] = 2 * pow2[n - 1] % MOD2
X1, X2 = 0, 0
for x in X:
X1 = (2 * X1 + x) % MOD1
X2 = (2 * X2 + x) % MOD2
ans = np.empty(N, np.int64)
for i in range(N):
x = X[N - 1 - i]
if x == 0:
nxt = (X1 + pow1[i]) % (popX + 1)
ans[i] = 1 + f(nxt)
elif x == 1:
if popX == 1:
ans[i] = 0
else:
nxt = (X2 - pow2[i]) % (popX - 1)
ans[i] = 1 + f(nxt)
return ans[::-1]
ans = main(X)
print(("\n".join(map(str, ans.tolist()))))
| import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8,), cache=True)
def popcount(n):
ret = 0
while n:
ret += n & 1
n >>= 1
return ret
@njit((i8,), cache=True)
def f(n):
t = 0
while n:
t += 1
n %= popcount(n)
return t
@njit(cache=True)
def main(X):
popX = X.sum()
MOD1 = popX + 1
MOD2 = popX - 1
if popX == 1:
MOD2 = 1
pow1 = np.ones_like(X)
pow2 = np.ones_like(X)
for n in range(1, len(X)):
pow1[n] = 2 * pow1[n - 1] % MOD1
pow2[n] = 2 * pow2[n - 1] % MOD2
X1, X2 = 0, 0
for x in X:
X1 = (2 * X1 + x) % MOD1
X2 = (2 * X2 + x) % MOD2
ans = np.empty(N, np.int64)
for i in range(N):
x = X[N - 1 - i]
if x == 0:
nxt = (X1 + pow1[i]) % (popX + 1)
ans[i] = 1 + f(nxt)
elif x == 1:
if popX == 1:
ans[i] = 0
else:
nxt = (X2 - pow2[i]) % (popX - 1)
ans[i] = 1 + f(nxt)
return ans[::-1]
N = int(readline())
X = np.array(list(read().rstrip()), np.int64) - ord("0")
ans = main(X)
print(("\n".join(map(str, ans.tolist()))))
| false | 1.538462 | [
"-N = int(readline())",
"-X = np.array(list(read().rstrip()), np.int64) - ord(\"0\")",
"+N = int(readline())",
"+X = np.array(list(read().rstrip()), np.int64) - ord(\"0\")"
]
| false | 0.31625 | 0.173881 | 1.818768 | [
"s680336079",
"s975869111"
]
|
u794173881 | p03165 | python | s996091657 | s723278533 | 450 | 315 | 113,372 | 144,424 | Accepted | Accepted | 30 | s = eval(input())
t = eval(input())
dp = [[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(len(s)):
for j in range(len(t)):
if s[i] == t[j]:
dp[i+1][j+1] = max(dp[i][j] + 1, dp[i+1][j], dp[i][j+1])
else:
dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
ans = []
i = len(s) - 1
j = len(t) - 1
while True:
if i < 0 or j < 0:
break
if dp[i+1][j+1] == dp[i+1][j]:
j -= 1
elif dp[i+1][j+1] == dp[i][j+1]:
i -= 1
elif dp[i+1][j+1] == dp[i][j] + 1:
ans.append(t[j])
i -= 1
j -= 1
print(("".join(ans)[::-1])) | def lcs(str1, str2):
"""文字列str1, str2の最長共通部分列(Longest Common Subsequence, LCS)を求める。
計算量 O(|str1||str2|)
"""
dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]
for i in range(len(str1)):
for j in range(len(str2)):
if str1[i] == str2[j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
# 復元
res = ''
i, j = len(str1), len(str2)
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
res = str1[i - 1] + res
i -= 1
j -= 1
return res
s = eval(input())
t = eval(input())
print((lcs(s, t))) | 28 | 31 | 626 | 789 | s = eval(input())
t = eval(input())
dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]
for i in range(len(s)):
for j in range(len(t)):
if s[i] == t[j]:
dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
else:
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
ans = []
i = len(s) - 1
j = len(t) - 1
while True:
if i < 0 or j < 0:
break
if dp[i + 1][j + 1] == dp[i + 1][j]:
j -= 1
elif dp[i + 1][j + 1] == dp[i][j + 1]:
i -= 1
elif dp[i + 1][j + 1] == dp[i][j] + 1:
ans.append(t[j])
i -= 1
j -= 1
print(("".join(ans)[::-1]))
| def lcs(str1, str2):
"""文字列str1, str2の最長共通部分列(Longest Common Subsequence, LCS)を求める。
計算量 O(|str1||str2|)
"""
dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]
for i in range(len(str1)):
for j in range(len(str2)):
if str1[i] == str2[j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
# 復元
res = ""
i, j = len(str1), len(str2)
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
res = str1[i - 1] + res
i -= 1
j -= 1
return res
s = eval(input())
t = eval(input())
print((lcs(s, t)))
| false | 9.677419 | [
"+def lcs(str1, str2):",
"+ \"\"\"文字列str1, str2の最長共通部分列(Longest Common Subsequence, LCS)を求める。",
"+ 計算量 O(|str1||str2|)",
"+ \"\"\"",
"+ dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]",
"+ for i in range(len(str1)):",
"+ for j in range(len(str2)):",
"+ if str1[i] == str2[j]:",
"+ dp[i + 1][j + 1] = dp[i][j] + 1",
"+ else:",
"+ dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])",
"+ # 復元",
"+ res = \"\"",
"+ i, j = len(str1), len(str2)",
"+ while i > 0 and j > 0:",
"+ if dp[i][j] == dp[i - 1][j]:",
"+ i -= 1",
"+ elif dp[i][j] == dp[i][j - 1]:",
"+ j -= 1",
"+ else:",
"+ res = str1[i - 1] + res",
"+ i -= 1",
"+ j -= 1",
"+ return res",
"+",
"+",
"-dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]",
"-for i in range(len(s)):",
"- for j in range(len(t)):",
"- if s[i] == t[j]:",
"- dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])",
"- else:",
"- dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])",
"-ans = []",
"-i = len(s) - 1",
"-j = len(t) - 1",
"-while True:",
"- if i < 0 or j < 0:",
"- break",
"- if dp[i + 1][j + 1] == dp[i + 1][j]:",
"- j -= 1",
"- elif dp[i + 1][j + 1] == dp[i][j + 1]:",
"- i -= 1",
"- elif dp[i + 1][j + 1] == dp[i][j] + 1:",
"- ans.append(t[j])",
"- i -= 1",
"- j -= 1",
"-print((\"\".join(ans)[::-1]))",
"+print((lcs(s, t)))"
]
| false | 0.040702 | 0.041546 | 0.979663 | [
"s996091657",
"s723278533"
]
|
u597374218 | p02819 | python | s663649923 | s614263696 | 29 | 17 | 2,940 | 3,060 | Accepted | Accepted | 41.38 | X=int(eval(input()))
while True:
for x in range(2,X):
if X%x==0:
break
else:
print(X)
break
X+=1 | X=int(eval(input()))
for x in range(X,2*X):
for i in range(2,int(x**.5)+1):
if x%i==0:
break
else:
print(x)
break | 9 | 8 | 146 | 158 | X = int(eval(input()))
while True:
for x in range(2, X):
if X % x == 0:
break
else:
print(X)
break
X += 1
| X = int(eval(input()))
for x in range(X, 2 * X):
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
break
else:
print(x)
break
| false | 11.111111 | [
"-while True:",
"- for x in range(2, X):",
"- if X % x == 0:",
"+for x in range(X, 2 * X):",
"+ for i in range(2, int(x**0.5) + 1):",
"+ if x % i == 0:",
"- print(X)",
"+ print(x)",
"- X += 1"
]
| false | 0.060823 | 0.044257 | 1.374314 | [
"s663649923",
"s614263696"
]
|
u384935968 | p03826 | python | s845733377 | s899538999 | 30 | 24 | 9,152 | 9,044 | Accepted | Accepted | 20 | a,b,c,d = list(map(int,input().split()))
ans = a*b, c*d
print((max(ans))) | A,B,C,D = list(map(int,input().split()))
if A * B > C * D:
print((A * B))
elif A * B < C * D:
print((C * D))
else:
print((A * B)) | 5 | 8 | 71 | 137 | a, b, c, d = list(map(int, input().split()))
ans = a * b, c * d
print((max(ans)))
| A, B, C, D = list(map(int, input().split()))
if A * B > C * D:
print((A * B))
elif A * B < C * D:
print((C * D))
else:
print((A * B))
| false | 37.5 | [
"-a, b, c, d = list(map(int, input().split()))",
"-ans = a * b, c * d",
"-print((max(ans)))",
"+A, B, C, D = list(map(int, input().split()))",
"+if A * B > C * D:",
"+ print((A * B))",
"+elif A * B < C * D:",
"+ print((C * D))",
"+else:",
"+ print((A * B))"
]
| false | 0.041791 | 0.10163 | 0.411204 | [
"s845733377",
"s899538999"
]
|
u112247039 | p02783 | python | s285355209 | s538376535 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | a, b = list(map(int,input().strip().split()))
print((a//b+1 if a%b else a//b)) | a, b = list(map(int,input().split()))
if a%b:
print((a//b+1))
else:
print((a//b)) | 2 | 5 | 77 | 84 | a, b = list(map(int, input().strip().split()))
print((a // b + 1 if a % b else a // b))
| a, b = list(map(int, input().split()))
if a % b:
print((a // b + 1))
else:
print((a // b))
| false | 60 | [
"-a, b = list(map(int, input().strip().split()))",
"-print((a // b + 1 if a % b else a // b))",
"+a, b = list(map(int, input().split()))",
"+if a % b:",
"+ print((a // b + 1))",
"+else:",
"+ print((a // b))"
]
| false | 0.045069 | 0.04577 | 0.984665 | [
"s285355209",
"s538376535"
]
|
u853619096 | p02418 | python | s207808848 | s710800688 | 30 | 20 | 7,460 | 7,472 | Accepted | Accepted | 33.33 | s = eval(input())
p = eval(input())
if p in (s * 2):
print("Yes")
else:
print("No") | z=eval(input())*2
x=eval(input())
a=z.count(x)
if a>=1:
print("Yes")
else:
print('No') | 7 | 8 | 88 | 90 | s = eval(input())
p = eval(input())
if p in (s * 2):
print("Yes")
else:
print("No")
| z = eval(input()) * 2
x = eval(input())
a = z.count(x)
if a >= 1:
print("Yes")
else:
print("No")
| false | 12.5 | [
"-s = eval(input())",
"-p = eval(input())",
"-if p in (s * 2):",
"+z = eval(input()) * 2",
"+x = eval(input())",
"+a = z.count(x)",
"+if a >= 1:"
]
| false | 0.007337 | 0.086097 | 0.085219 | [
"s207808848",
"s710800688"
]
|
u668503853 | p03095 | python | s601438640 | s707703590 | 28 | 22 | 3,820 | 3,188 | Accepted | Accepted | 21.43 | import collections
from functools import reduce
N=int(eval(input()))
S=eval(input())
c=collections.Counter(S)
d=[x+1 for x in list(c.values())]
print(((reduce(lambda x,y:x*y,d)-1)%1000000007)) | N=int(eval(input()))
S=eval(input())
C=set(S)
m=1
for c in C:
m*=S.count(c)+1
print(((m-1)%(10**9+7))) | 7 | 7 | 187 | 96 | import collections
from functools import reduce
N = int(eval(input()))
S = eval(input())
c = collections.Counter(S)
d = [x + 1 for x in list(c.values())]
print(((reduce(lambda x, y: x * y, d) - 1) % 1000000007))
| N = int(eval(input()))
S = eval(input())
C = set(S)
m = 1
for c in C:
m *= S.count(c) + 1
print(((m - 1) % (10**9 + 7)))
| false | 0 | [
"-import collections",
"-from functools import reduce",
"-",
"-c = collections.Counter(S)",
"-d = [x + 1 for x in list(c.values())]",
"-print(((reduce(lambda x, y: x * y, d) - 1) % 1000000007))",
"+C = set(S)",
"+m = 1",
"+for c in C:",
"+ m *= S.count(c) + 1",
"+print(((m - 1) % (10**9 + 7)))"
]
| false | 0.047903 | 0.039691 | 1.206891 | [
"s601438640",
"s707703590"
]
|
u477977638 | p02947 | python | s381154637 | s206959555 | 564 | 438 | 38,780 | 18,148 | Accepted | Accepted | 22.34 | from operator import itemgetter
n=int(eval(input()))
s=[]
li=[]
ans=0
cnt=1
for i in range(n):
s.append(sorted(eval(input())))
s.sort(key=itemgetter(9,8,7,6,5,4,3,2,1,0))
s=s+['']
for i in range(n):
if s[i]==s[i+1]:
cnt+=1
elif cnt>1:
li.append(int(cnt*(cnt-1)/2))
cnt=1
else:
cnt=1
print((int(sum(li)))) | from collections import defaultdict
n=int(eval(input()))
dct=defaultdict(int)
for i in range(n):
s=eval(input())
sort_s="".join(sorted(s))
dct[sort_s]+=1
ans=0
for k,v in list(dct.items()):
ans+= v*(v-1)//2
print(ans) | 22 | 13 | 338 | 221 | from operator import itemgetter
n = int(eval(input()))
s = []
li = []
ans = 0
cnt = 1
for i in range(n):
s.append(sorted(eval(input())))
s.sort(key=itemgetter(9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
s = s + [""]
for i in range(n):
if s[i] == s[i + 1]:
cnt += 1
elif cnt > 1:
li.append(int(cnt * (cnt - 1) / 2))
cnt = 1
else:
cnt = 1
print((int(sum(li))))
| from collections import defaultdict
n = int(eval(input()))
dct = defaultdict(int)
for i in range(n):
s = eval(input())
sort_s = "".join(sorted(s))
dct[sort_s] += 1
ans = 0
for k, v in list(dct.items()):
ans += v * (v - 1) // 2
print(ans)
| false | 40.909091 | [
"-from operator import itemgetter",
"+from collections import defaultdict",
"-s = []",
"-li = []",
"+dct = defaultdict(int)",
"+for i in range(n):",
"+ s = eval(input())",
"+ sort_s = \"\".join(sorted(s))",
"+ dct[sort_s] += 1",
"-cnt = 1",
"-for i in range(n):",
"- s.append(sorted(eval(input())))",
"-s.sort(key=itemgetter(9, 8, 7, 6, 5, 4, 3, 2, 1, 0))",
"-s = s + [\"\"]",
"-for i in range(n):",
"- if s[i] == s[i + 1]:",
"- cnt += 1",
"- elif cnt > 1:",
"- li.append(int(cnt * (cnt - 1) / 2))",
"- cnt = 1",
"- else:",
"- cnt = 1",
"-print((int(sum(li))))",
"+for k, v in list(dct.items()):",
"+ ans += v * (v - 1) // 2",
"+print(ans)"
]
| false | 0.036981 | 0.073628 | 0.502269 | [
"s381154637",
"s206959555"
]
|
u661977789 | p02848 | python | s739539107 | s158836494 | 201 | 29 | 40,540 | 4,468 | Accepted | Accepted | 85.57 | N = int(eval(input()))
S = eval(input())
alphabet = 'ZABCDEFGHIJKLMNOPQRSTUVWXY'
alphabet_num = {st: num for num, st in enumerate(alphabet)}
alphabet_list = [st for st in alphabet]
output = ''
for s in S:
num = (alphabet_num[s] + N) % 26
output += alphabet_list[num]
print(output) | N = int(input())
S = input()
alphabet = 'ZABCDEFGHIJKLMNOPQRSTUVWXY'
alphabet_num = {st: num for num, st in enumerate(alphabet)}
alphabet_list = [st for st in alphabet]
for s in S:
num = (alphabet_num[s] + N) % 26
print(alphabet_list[num], end='')
| 11 | 9 | 283 | 260 | N = int(eval(input()))
S = eval(input())
alphabet = "ZABCDEFGHIJKLMNOPQRSTUVWXY"
alphabet_num = {st: num for num, st in enumerate(alphabet)}
alphabet_list = [st for st in alphabet]
output = ""
for s in S:
num = (alphabet_num[s] + N) % 26
output += alphabet_list[num]
print(output)
| N = int(input())
S = input()
alphabet = "ZABCDEFGHIJKLMNOPQRSTUVWXY"
alphabet_num = {st: num for num, st in enumerate(alphabet)}
alphabet_list = [st for st in alphabet]
for s in S:
num = (alphabet_num[s] + N) % 26
print(alphabet_list[num], end="")
| false | 18.181818 | [
"-N = int(eval(input()))",
"-S = eval(input())",
"+N = int(input())",
"+S = input()",
"-output = \"\"",
"- output += alphabet_list[num]",
"-print(output)",
"+ print(alphabet_list[num], end=\"\")"
]
| false | 0.037348 | 0.037492 | 0.996151 | [
"s739539107",
"s158836494"
]
|
u887207211 | p03290 | python | s704742321 | s234474797 | 22 | 18 | 3,064 | 3,064 | Accepted | Accepted | 18.18 | D, G = list(map(int,input().split()))
PC = [list(map(int,input().split())) for _ in range(D)]
ans = 1e9
for i in range(1 << D):
point = 0
cnt = 0
for j in range(D):
if(((i >> j) & 1) == 1):
point += PC[j][0]*(j+1)*100 + PC[j][1]
cnt += PC[j][0]
else:
tmp = j
if(point < G):
x = G - point
if((PC[tmp][0]-1)*(tmp+1)*100 < x):
continue
cnt += -(-x//(100*(tmp+1)))
ans = min(ans, cnt)
print(ans) | D, G = list(map(int,input().split()))
PC = [0]+[list(map(int,input().split())) for _ in range(D)]
def dfs(d, g):
if(d == 0):
return 1e9
x = min(g//(100*d), PC[d][0])
point = x*100*d
if(x == PC[d][0]):
point += PC[d][1]
if(point < g):
x += dfs(d-1, g-point)
return min(x, dfs(d-1, g))
print((dfs(D, G))) | 20 | 18 | 459 | 344 | D, G = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]
ans = 1e9
for i in range(1 << D):
point = 0
cnt = 0
for j in range(D):
if ((i >> j) & 1) == 1:
point += PC[j][0] * (j + 1) * 100 + PC[j][1]
cnt += PC[j][0]
else:
tmp = j
if point < G:
x = G - point
if (PC[tmp][0] - 1) * (tmp + 1) * 100 < x:
continue
cnt += -(-x // (100 * (tmp + 1)))
ans = min(ans, cnt)
print(ans)
| D, G = list(map(int, input().split()))
PC = [0] + [list(map(int, input().split())) for _ in range(D)]
def dfs(d, g):
if d == 0:
return 1e9
x = min(g // (100 * d), PC[d][0])
point = x * 100 * d
if x == PC[d][0]:
point += PC[d][1]
if point < g:
x += dfs(d - 1, g - point)
return min(x, dfs(d - 1, g))
print((dfs(D, G)))
| false | 10 | [
"-PC = [list(map(int, input().split())) for _ in range(D)]",
"-ans = 1e9",
"-for i in range(1 << D):",
"- point = 0",
"- cnt = 0",
"- for j in range(D):",
"- if ((i >> j) & 1) == 1:",
"- point += PC[j][0] * (j + 1) * 100 + PC[j][1]",
"- cnt += PC[j][0]",
"- else:",
"- tmp = j",
"- if point < G:",
"- x = G - point",
"- if (PC[tmp][0] - 1) * (tmp + 1) * 100 < x:",
"- continue",
"- cnt += -(-x // (100 * (tmp + 1)))",
"- ans = min(ans, cnt)",
"-print(ans)",
"+PC = [0] + [list(map(int, input().split())) for _ in range(D)]",
"+",
"+",
"+def dfs(d, g):",
"+ if d == 0:",
"+ return 1e9",
"+ x = min(g // (100 * d), PC[d][0])",
"+ point = x * 100 * d",
"+ if x == PC[d][0]:",
"+ point += PC[d][1]",
"+ if point < g:",
"+ x += dfs(d - 1, g - point)",
"+ return min(x, dfs(d - 1, g))",
"+",
"+",
"+print((dfs(D, G)))"
]
| false | 0.034813 | 0.03648 | 0.954308 | [
"s704742321",
"s234474797"
]
|
u188827677 | p02695 | python | s845910465 | s345221427 | 1,049 | 923 | 21,548 | 9,128 | Accepted | Accepted | 12.01 | from itertools import combinations_with_replacement
n,m,q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
num = list(combinations_with_replacement(list(range(1,m+1)), n))
ans = 0
for i in num:
t = 0
for j in abcd:
if i[j[1]-1] - i[j[0]-1] == j[2]:
t += j[3]
ans = max(ans, t)
print(ans) | from itertools import combinations_with_replacement
n,m,q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i in combinations_with_replacement(list(range(1,m+1)),n):
t = 0
for j in abcd:
if i[j[1]-1] - i[j[0]-1] == j[2]:
t += j[3]
ans = max(ans, t)
print(ans) | 15 | 12 | 354 | 330 | from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
num = list(combinations_with_replacement(list(range(1, m + 1)), n))
ans = 0
for i in num:
t = 0
for j in abcd:
if i[j[1] - 1] - i[j[0] - 1] == j[2]:
t += j[3]
ans = max(ans, t)
print(ans)
| from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i in combinations_with_replacement(list(range(1, m + 1)), n):
t = 0
for j in abcd:
if i[j[1] - 1] - i[j[0] - 1] == j[2]:
t += j[3]
ans = max(ans, t)
print(ans)
| false | 20 | [
"-num = list(combinations_with_replacement(list(range(1, m + 1)), n))",
"-for i in num:",
"+for i in combinations_with_replacement(list(range(1, m + 1)), n):"
]
| false | 0.052902 | 0.047732 | 1.108301 | [
"s845910465",
"s345221427"
]
|
u627600101 | p02536 | python | s029106978 | s206514710 | 279 | 246 | 48,428 | 27,316 | Accepted | Accepted | 11.83 | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = list(map(int, input().split()))
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def dfs(cnt, city):
for item in nextcity[city]:
if sgn[item] == 0:
sgn[item] = cnt
dfs(cnt, item)
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
dfs(cnt, k)
print((cnt -1))
| import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = list(map(int, input().split()))
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print((cnt -1))
| 29 | 34 | 531 | 635 | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = list(map(int, input().split()))
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def dfs(cnt, city):
for item in nextcity[city]:
if sgn[item] == 0:
sgn[item] = cnt
dfs(cnt, item)
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
dfs(cnt, k)
print((cnt - 1))
| import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = list(map(int, input().split()))
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print((cnt - 1))
| false | 14.705882 | [
"-def dfs(cnt, city):",
"- for item in nextcity[city]:",
"- if sgn[item] == 0:",
"- sgn[item] = cnt",
"- dfs(cnt, item)",
"- return None",
"+def bfs(cnt, lis):",
"+ nextvisit = []",
"+ for j in lis:",
"+ for item in nextcity[j]:",
"+ if sgn[item] == 0:",
"+ nextvisit.append(item)",
"+ sgn[item] = cnt",
"+ if nextvisit:",
"+ bfs(cnt, nextvisit)",
"+ return None",
"+ else:",
"+ return None",
"- dfs(cnt, k)",
"+ bfs(cnt, [k])"
]
| false | 0.03619 | 0.041559 | 0.870819 | [
"s029106978",
"s206514710"
]
|
u729133443 | p03563 | python | s975039362 | s162659011 | 166 | 18 | 38,384 | 2,940 | Accepted | Accepted | 89.16 | r,g=int(eval(input())),int(eval(input()))
print((g+g-r)) | print((eval(eval(input())+'*-1+2*'+eval(input())))) | 2 | 1 | 43 | 37 | r, g = int(eval(input())), int(eval(input()))
print((g + g - r))
| print((eval(eval(input()) + "*-1+2*" + eval(input()))))
| false | 50 | [
"-r, g = int(eval(input())), int(eval(input()))",
"-print((g + g - r))",
"+print((eval(eval(input()) + \"*-1+2*\" + eval(input()))))"
]
| false | 0.076769 | 0.033696 | 2.278275 | [
"s975039362",
"s162659011"
]
|
u298297089 | p03212 | python | s762592924 | s475647119 | 40 | 36 | 3,060 | 3,060 | Accepted | Accepted | 10 | # https://atcoder.jp/contests/abc114/submissions/6262572
from itertools import product
N = int(eval(input()))
ans = 0
for i in range(3,10):
for s in product(["3","5","7"],repeat=i):
if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s:
ans += 1
print(ans)
| def dfs(start, n, len_n):
queue = [start]
cnt = 0
while queue:
parent = queue.pop()
for c in '357':
cc = parent+c
if int(cc) <= n and '3' in cc and '5' in cc and '7' in cc:
cnt += 1
if len(cc) < len_n:
queue.append(cc)
return cnt
n = eval(input())
len_n = len(n)
n = int(n)
print((dfs('', n, len_n)))
| 10 | 18 | 294 | 413 | # https://atcoder.jp/contests/abc114/submissions/6262572
from itertools import product
N = int(eval(input()))
ans = 0
for i in range(3, 10):
for s in product(["3", "5", "7"], repeat=i):
if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s:
ans += 1
print(ans)
| def dfs(start, n, len_n):
queue = [start]
cnt = 0
while queue:
parent = queue.pop()
for c in "357":
cc = parent + c
if int(cc) <= n and "3" in cc and "5" in cc and "7" in cc:
cnt += 1
if len(cc) < len_n:
queue.append(cc)
return cnt
n = eval(input())
len_n = len(n)
n = int(n)
print((dfs("", n, len_n)))
| false | 44.444444 | [
"-# https://atcoder.jp/contests/abc114/submissions/6262572",
"-from itertools import product",
"+def dfs(start, n, len_n):",
"+ queue = [start]",
"+ cnt = 0",
"+ while queue:",
"+ parent = queue.pop()",
"+ for c in \"357\":",
"+ cc = parent + c",
"+ if int(cc) <= n and \"3\" in cc and \"5\" in cc and \"7\" in cc:",
"+ cnt += 1",
"+ if len(cc) < len_n:",
"+ queue.append(cc)",
"+ return cnt",
"-N = int(eval(input()))",
"-ans = 0",
"-for i in range(3, 10):",
"- for s in product([\"3\", \"5\", \"7\"], repeat=i):",
"- if int(\"\".join(s)) <= N and \"3\" in s and \"5\" in s and \"7\" in s:",
"- ans += 1",
"-print(ans)",
"+",
"+n = eval(input())",
"+len_n = len(n)",
"+n = int(n)",
"+print((dfs(\"\", n, len_n)))"
]
| false | 0.058473 | 0.040726 | 1.435779 | [
"s762592924",
"s475647119"
]
|
u512212329 | p02608 | python | s702381469 | s731162033 | 159 | 142 | 9,292 | 9,272 | Accepted | Accepted | 10.69 | """
(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)
"""
def func(x, y, z): return (x + y + z) ** 2 - x * y - y * z - z * x
def main():
num = int(eval(input()))
counter = [0] * (num + 1)
# func(41, 41, 41) = 10086
# func(99, 1, 1) = 10002
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 123 - x - y + 1):
if (tmp := func(x, y, z)) <= num:
counter[tmp] += 1
for count in counter[1:]:
print(count)
if __name__ == '__main__':
main()
| def main():
num = int(eval(input()))
counter = [0] * (num + 1)
# func(41, 41, 41) = 10086
# func(99, 1, 1) = 10002
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 123 - x - y + 1):
tmp = (x + y + z) ** 2 - x * y - y * z - z * x
if tmp <= num:
counter[tmp] += 1
for count in counter[1:]:
print(count)
if __name__ == '__main__':
main()
| 22 | 17 | 550 | 472 | """
(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)
"""
def func(x, y, z):
return (x + y + z) ** 2 - x * y - y * z - z * x
def main():
num = int(eval(input()))
counter = [0] * (num + 1)
# func(41, 41, 41) = 10086
# func(99, 1, 1) = 10002
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 123 - x - y + 1):
if (tmp := func(x, y, z)) <= num:
counter[tmp] += 1
for count in counter[1:]:
print(count)
if __name__ == "__main__":
main()
| def main():
num = int(eval(input()))
counter = [0] * (num + 1)
# func(41, 41, 41) = 10086
# func(99, 1, 1) = 10002
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 123 - x - y + 1):
tmp = (x + y + z) ** 2 - x * y - y * z - z * x
if tmp <= num:
counter[tmp] += 1
for count in counter[1:]:
print(count)
if __name__ == "__main__":
main()
| false | 22.727273 | [
"-\"\"\"",
"-(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)",
"-\"\"\"",
"-",
"-",
"-def func(x, y, z):",
"- return (x + y + z) ** 2 - x * y - y * z - z * x",
"-",
"-",
"- if (tmp := func(x, y, z)) <= num:",
"+ tmp = (x + y + z) ** 2 - x * y - y * z - z * x",
"+ if tmp <= num:"
]
| false | 0.263039 | 0.229975 | 1.14377 | [
"s702381469",
"s731162033"
]
|
u597374218 | p02952 | python | s350706070 | s070375994 | 49 | 45 | 2,940 | 2,940 | Accepted | Accepted | 8.16 | N=int(eval(input()))
print((sum(len(str(i))%2==1 for i in range(1,N+1)))) | N=int(eval(input()))
print((sum(len(str(i))%2 for i in range(1,N+1)))) | 2 | 2 | 66 | 63 | N = int(eval(input()))
print((sum(len(str(i)) % 2 == 1 for i in range(1, N + 1))))
| N = int(eval(input()))
print((sum(len(str(i)) % 2 for i in range(1, N + 1))))
| false | 0 | [
"-print((sum(len(str(i)) % 2 == 1 for i in range(1, N + 1))))",
"+print((sum(len(str(i)) % 2 for i in range(1, N + 1))))"
]
| false | 0.047544 | 0.054353 | 0.874723 | [
"s350706070",
"s070375994"
]
|
u786020649 | p03634 | python | s382638611 | s403295241 | 792 | 609 | 83,456 | 83,260 | Accepted | Accepted | 23.11 | from collections import defaultdict,deque
n=int(eval(input()))
edges=[tuple(map(int,input().split())) for _ in range(n-1)]
q,k=list(map(int,input().split()))
xy=[tuple(map(int,input().split())) for _ in range(q)]
stack=[-1]*(n+1)
stack[k]=0
ed=defaultdict(list)
wt=defaultdict(int)
for e in edges:
ed[e[0]].append(e[1])
ed[e[1]].append(e[0])
wt[(e[0],e[1])]=e[2]
wt[(e[1],e[0])]=e[2]
ce=deque([(k,x) for x in ed[k]])
ne=deque()
while True:
while ce:
e=ce.pop()
stack[e[1]]=stack[e[0]]+wt[e]
for v in ed[e[1]]:
if stack[v]<0:
ne.append((e[1],v))
if not ne:
break
ce.extend(ne)
ne.clear()
for que in xy:
print((stack[que[0]]+stack[que[1]])) |
from collections import defaultdict,deque
import sys
finput=lambda: sys.stdin.readline().strip()
def main():
n=int(finput())
edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
q,k=list(map(int,finput().split()))
xy=[tuple(map(int,finput().split())) for _ in range(q)]
stack=[-1]*(n+1)
stack[k]=0
ed=defaultdict(list)
wt=defaultdict(int)
for e in edges:
ed[e[0]].append(e[1])
ed[e[1]].append(e[0])
wt[(e[0],e[1])]=e[2]
wt[(e[1],e[0])]=e[2]
ce=deque([(k,x) for x in ed[k]])
ne=deque()
while True:
while ce:
e=ce.pop()
stack[e[1]]=stack[e[0]]+wt[e]
for v in ed[e[1]]:
if stack[v]<0:
ne.append((e[1],v))
if not ne:
break
ce.extend(ne)
ne.clear()
for que in xy:
print((stack[que[0]]+stack[que[1]]))
if __name__=='__main__':
main()
| 31 | 39 | 704 | 883 | from collections import defaultdict, deque
n = int(eval(input()))
edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [tuple(map(int, input().split())) for _ in range(q)]
stack = [-1] * (n + 1)
stack[k] = 0
ed = defaultdict(list)
wt = defaultdict(int)
for e in edges:
ed[e[0]].append(e[1])
ed[e[1]].append(e[0])
wt[(e[0], e[1])] = e[2]
wt[(e[1], e[0])] = e[2]
ce = deque([(k, x) for x in ed[k]])
ne = deque()
while True:
while ce:
e = ce.pop()
stack[e[1]] = stack[e[0]] + wt[e]
for v in ed[e[1]]:
if stack[v] < 0:
ne.append((e[1], v))
if not ne:
break
ce.extend(ne)
ne.clear()
for que in xy:
print((stack[que[0]] + stack[que[1]]))
| from collections import defaultdict, deque
import sys
finput = lambda: sys.stdin.readline().strip()
def main():
n = int(finput())
edges = [tuple(map(int, finput().split())) for _ in range(n - 1)]
q, k = list(map(int, finput().split()))
xy = [tuple(map(int, finput().split())) for _ in range(q)]
stack = [-1] * (n + 1)
stack[k] = 0
ed = defaultdict(list)
wt = defaultdict(int)
for e in edges:
ed[e[0]].append(e[1])
ed[e[1]].append(e[0])
wt[(e[0], e[1])] = e[2]
wt[(e[1], e[0])] = e[2]
ce = deque([(k, x) for x in ed[k]])
ne = deque()
while True:
while ce:
e = ce.pop()
stack[e[1]] = stack[e[0]] + wt[e]
for v in ed[e[1]]:
if stack[v] < 0:
ne.append((e[1], v))
if not ne:
break
ce.extend(ne)
ne.clear()
for que in xy:
print((stack[que[0]] + stack[que[1]]))
if __name__ == "__main__":
main()
| false | 20.512821 | [
"+import sys",
"-n = int(eval(input()))",
"-edges = [tuple(map(int, input().split())) for _ in range(n - 1)]",
"-q, k = list(map(int, input().split()))",
"-xy = [tuple(map(int, input().split())) for _ in range(q)]",
"-stack = [-1] * (n + 1)",
"-stack[k] = 0",
"-ed = defaultdict(list)",
"-wt = defaultdict(int)",
"-for e in edges:",
"- ed[e[0]].append(e[1])",
"- ed[e[1]].append(e[0])",
"- wt[(e[0], e[1])] = e[2]",
"- wt[(e[1], e[0])] = e[2]",
"-ce = deque([(k, x) for x in ed[k]])",
"-ne = deque()",
"-while True:",
"- while ce:",
"- e = ce.pop()",
"- stack[e[1]] = stack[e[0]] + wt[e]",
"- for v in ed[e[1]]:",
"- if stack[v] < 0:",
"- ne.append((e[1], v))",
"- if not ne:",
"- break",
"- ce.extend(ne)",
"- ne.clear()",
"-for que in xy:",
"- print((stack[que[0]] + stack[que[1]]))",
"+finput = lambda: sys.stdin.readline().strip()",
"+",
"+",
"+def main():",
"+ n = int(finput())",
"+ edges = [tuple(map(int, finput().split())) for _ in range(n - 1)]",
"+ q, k = list(map(int, finput().split()))",
"+ xy = [tuple(map(int, finput().split())) for _ in range(q)]",
"+ stack = [-1] * (n + 1)",
"+ stack[k] = 0",
"+ ed = defaultdict(list)",
"+ wt = defaultdict(int)",
"+ for e in edges:",
"+ ed[e[0]].append(e[1])",
"+ ed[e[1]].append(e[0])",
"+ wt[(e[0], e[1])] = e[2]",
"+ wt[(e[1], e[0])] = e[2]",
"+ ce = deque([(k, x) for x in ed[k]])",
"+ ne = deque()",
"+ while True:",
"+ while ce:",
"+ e = ce.pop()",
"+ stack[e[1]] = stack[e[0]] + wt[e]",
"+ for v in ed[e[1]]:",
"+ if stack[v] < 0:",
"+ ne.append((e[1], v))",
"+ if not ne:",
"+ break",
"+ ce.extend(ne)",
"+ ne.clear()",
"+ for que in xy:",
"+ print((stack[que[0]] + stack[que[1]]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.044085 | 0.04227 | 1.042935 | [
"s382638611",
"s403295241"
]
|
u729133443 | p02555 | python | s017979379 | s039277419 | 170 | 66 | 9,764 | 29,052 | Accepted | Accepted | 61.18 | from functools import*
M=10**9+7
@lru_cache(None)
def f(s):
if s<3:return 0
return(sum(map(f,list(range(s-2))))+1)%M
print((f(int(eval(input()))))) | a,b,c=1,0,0
exec('a,b,c=b,c,(a+c)%(10**9+7);'*(int(eval(input()))-2))
print(c) | 7 | 3 | 147 | 74 | from functools import *
M = 10**9 + 7
@lru_cache(None)
def f(s):
if s < 3:
return 0
return (sum(map(f, list(range(s - 2)))) + 1) % M
print((f(int(eval(input())))))
| a, b, c = 1, 0, 0
exec("a,b,c=b,c,(a+c)%(10**9+7);" * (int(eval(input())) - 2))
print(c)
| false | 57.142857 | [
"-from functools import *",
"-",
"-M = 10**9 + 7",
"-",
"-",
"-@lru_cache(None)",
"-def f(s):",
"- if s < 3:",
"- return 0",
"- return (sum(map(f, list(range(s - 2)))) + 1) % M",
"-",
"-",
"-print((f(int(eval(input())))))",
"+a, b, c = 1, 0, 0",
"+exec(\"a,b,c=b,c,(a+c)%(10**9+7);\" * (int(eval(input())) - 2))",
"+print(c)"
]
| false | 0.04995 | 0.049647 | 1.006094 | [
"s017979379",
"s039277419"
]
|
u759412327 | p02984 | python | s373703522 | s522001812 | 121 | 96 | 20,500 | 20,700 | Accepted | Accepted | 20.66 | N = int(eval(input()))
A = list(map(int,input().split()))
B = N*[0]
for n in range(N):
if n%2==0:
B[0]+=A[n]
else:
B[0]-=A[n]
for n in range(N):
if n==0:
pass
elif 1<=n<=N-1:
B[n] = 2*A[n-1]-B[n-1]
else:
B[n] = 2*A[n]-B[0]
print((*B)) | N = int(eval(input()))
A = list(map(int,input().split()))
B = [2*sum(A[::2])-sum(A)]
for n in range(N-1):
B+=[2*A[n]-B[n]]
print((*B)) | 19 | 8 | 277 | 137 | N = int(eval(input()))
A = list(map(int, input().split()))
B = N * [0]
for n in range(N):
if n % 2 == 0:
B[0] += A[n]
else:
B[0] -= A[n]
for n in range(N):
if n == 0:
pass
elif 1 <= n <= N - 1:
B[n] = 2 * A[n - 1] - B[n - 1]
else:
B[n] = 2 * A[n] - B[0]
print((*B))
| N = int(eval(input()))
A = list(map(int, input().split()))
B = [2 * sum(A[::2]) - sum(A)]
for n in range(N - 1):
B += [2 * A[n] - B[n]]
print((*B))
| false | 57.894737 | [
"-B = N * [0]",
"-for n in range(N):",
"- if n % 2 == 0:",
"- B[0] += A[n]",
"- else:",
"- B[0] -= A[n]",
"-for n in range(N):",
"- if n == 0:",
"- pass",
"- elif 1 <= n <= N - 1:",
"- B[n] = 2 * A[n - 1] - B[n - 1]",
"- else:",
"- B[n] = 2 * A[n] - B[0]",
"+B = [2 * sum(A[::2]) - sum(A)]",
"+for n in range(N - 1):",
"+ B += [2 * A[n] - B[n]]"
]
| false | 0.035348 | 0.036657 | 0.964305 | [
"s373703522",
"s522001812"
]
|
u291628833 | p03160 | python | s753422109 | s939376135 | 228 | 96 | 52,208 | 84,744 | Accepted | Accepted | 57.89 | n = int(eval(input()))
h_L = list(map(int,input().split()))
#dp = [float("inf")] * (10**4 + 1)
dp = [10**9] * n
dp[0] = 0
dp[1] = abs(h_L[0]-h_L[1])
for i in range(2,n):
#dp[i]
# 1
tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
#dp[i] = min(dp[i],tmp1)
# 2
tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
dp[i] = min(dp[i],tmp1,tmp2)
#print(dp)
print((dp[n-1])) | n = int(eval(input()))
h_L = list(map(int,input().split()))
dp = [0] * (n+1)
dp[1] = abs(h_L[1]-h_L[0])
for i in range(n-2):
dp[i+2] = min(dp[i+1]+abs(h_L[i+2]-h_L[i+1]),dp[i] + abs(h_L[i+2]-h_L[i]))
print((dp[n-1])) | 19 | 10 | 387 | 224 | n = int(eval(input()))
h_L = list(map(int, input().split()))
# dp = [float("inf")] * (10**4 + 1)
dp = [10**9] * n
dp[0] = 0
dp[1] = abs(h_L[0] - h_L[1])
for i in range(2, n):
# dp[i]
# 1
tmp1 = dp[i - 1] + abs(h_L[i - 1] - h_L[i])
# dp[i] = min(dp[i],tmp1)
# 2
tmp2 = dp[i - 2] + abs(h_L[i - 2] - h_L[i])
dp[i] = min(dp[i], tmp1, tmp2)
# print(dp)
print((dp[n - 1]))
| n = int(eval(input()))
h_L = list(map(int, input().split()))
dp = [0] * (n + 1)
dp[1] = abs(h_L[1] - h_L[0])
for i in range(n - 2):
dp[i + 2] = min(
dp[i + 1] + abs(h_L[i + 2] - h_L[i + 1]), dp[i] + abs(h_L[i + 2] - h_L[i])
)
print((dp[n - 1]))
| false | 47.368421 | [
"-# dp = [float(\"inf\")] * (10**4 + 1)",
"-dp = [10**9] * n",
"-dp[0] = 0",
"-dp[1] = abs(h_L[0] - h_L[1])",
"-for i in range(2, n):",
"- # dp[i]",
"- # 1",
"- tmp1 = dp[i - 1] + abs(h_L[i - 1] - h_L[i])",
"- # dp[i] = min(dp[i],tmp1)",
"- # 2",
"- tmp2 = dp[i - 2] + abs(h_L[i - 2] - h_L[i])",
"- dp[i] = min(dp[i], tmp1, tmp2)",
"-# print(dp)",
"+dp = [0] * (n + 1)",
"+dp[1] = abs(h_L[1] - h_L[0])",
"+for i in range(n - 2):",
"+ dp[i + 2] = min(",
"+ dp[i + 1] + abs(h_L[i + 2] - h_L[i + 1]), dp[i] + abs(h_L[i + 2] - h_L[i])",
"+ )"
]
| false | 0.035974 | 0.035183 | 1.022469 | [
"s753422109",
"s939376135"
]
|
u230621983 | p03633 | python | s942454497 | s700339503 | 36 | 28 | 5,076 | 9,068 | Accepted | Accepted | 22.22 | from fractions import gcd
from functools import reduce
n = int(eval(input()))
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
t = set()
for _ in range(n):
t.add(int(eval(input())))
print((lcm_list(t))) | from math import gcd
n = int(eval(input()))
ans = 1
for _ in range(n):
t = int(eval(input()))
ans = t * ans // gcd(t, ans)
print(ans) | 16 | 8 | 278 | 137 | from fractions import gcd
from functools import reduce
n = int(eval(input()))
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
t = set()
for _ in range(n):
t.add(int(eval(input())))
print((lcm_list(t)))
| from math import gcd
n = int(eval(input()))
ans = 1
for _ in range(n):
t = int(eval(input()))
ans = t * ans // gcd(t, ans)
print(ans)
| false | 50 | [
"-from fractions import gcd",
"-from functools import reduce",
"+from math import gcd",
"-",
"-",
"-def lcm_base(x, y):",
"- return (x * y) // gcd(x, y)",
"-",
"-",
"-def lcm_list(numbers):",
"- return reduce(lcm_base, numbers, 1)",
"-",
"-",
"-t = set()",
"+ans = 1",
"- t.add(int(eval(input())))",
"-print((lcm_list(t)))",
"+ t = int(eval(input()))",
"+ ans = t * ans // gcd(t, ans)",
"+print(ans)"
]
| false | 0.074408 | 0.055511 | 1.340409 | [
"s942454497",
"s700339503"
]
|
u827202523 | p02929 | python | s885064079 | s888953096 | 205 | 86 | 41,580 | 80,460 | Accepted | Accepted | 58.05 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
MOD = 10**9 + 7
def factorial(n):
ans = 1
for i in range(1, n+1):
ans *= i
ans %= MOD
return ans % MOD
n = getN()
s = input().strip()
ans = 1
open = 0
for c in s:
# print(c, ans, open, cur)
if c == "B":
if open%2 == 0:
open += 1
else:
if open == 0:
print((0))
sys.exit()
ans *= open
ans %= MOD
open -= 1
else:
if open%2 == 1:
open += 1
else:
if open == 0:
print((0))
sys.exit()
ans *= open
ans %= MOD
open -= 1
if open != 0:
print((0))
sys.exit()
print(((ans * factorial(n)) % MOD)) | import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n-k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i)% MOD)
return ret
def solve():
n = getN()
S = getS()
rev = 0
ans = 1
for c in S:
if c == "W":
if rev == 0:
print((0))
return
if rev % 2 == 0:
ans *= rev
ans %= MOD
rev -= 1
else:
rev += 1
else:
if rev % 2 == 1:
ans *= rev
ans %= MOD
rev -= 1
else:
rev += 1
# print(ans)
if rev == 0:
print(((ans * kaijyo(n)[-1]) % MOD))
else:
print((0))
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve() | 63 | 77 | 993 | 1,578 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
MOD = 10**9 + 7
def factorial(n):
ans = 1
for i in range(1, n + 1):
ans *= i
ans %= MOD
return ans % MOD
n = getN()
s = input().strip()
ans = 1
open = 0
for c in s:
# print(c, ans, open, cur)
if c == "B":
if open % 2 == 0:
open += 1
else:
if open == 0:
print((0))
sys.exit()
ans *= open
ans %= MOD
open -= 1
else:
if open % 2 == 1:
open += 1
else:
if open == 0:
print((0))
sys.exit()
ans *= open
ans %= MOD
open -= 1
if open != 0:
print((0))
sys.exit()
print(((ans * factorial(n)) % MOD))
| import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n - k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i) % MOD)
return ret
def solve():
n = getN()
S = getS()
rev = 0
ans = 1
for c in S:
if c == "W":
if rev == 0:
print((0))
return
if rev % 2 == 0:
ans *= rev
ans %= MOD
rev -= 1
else:
rev += 1
else:
if rev % 2 == 1:
ans *= rev
ans %= MOD
rev -= 1
else:
rev += 1
# print(ans)
if rev == 0:
print(((ans * kaijyo(n)[-1]) % MOD))
else:
print((0))
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| false | 18.181818 | [
"+from collections import defaultdict, deque, Counter",
"+import math",
"+# import copy",
"+from bisect import bisect_left, bisect_right",
"+import heapq",
"+",
"+# sys.setrecursionlimit(1000000)",
"+# input aliases",
"-sys.setrecursionlimit(1000000)",
"+getS = lambda: input().strip()",
"+getN = lambda: int(eval(input()))",
"+getList = lambda: list(map(int, input().split()))",
"+getZList = lambda: [int(x) - 1 for x in input().split()]",
"+INF = 10**20",
"+MOD = 10**9 + 7",
"+divide = lambda x: pow(x, MOD - 2, MOD)",
"-def getN():",
"- return int(eval(input()))",
"+def nck(n, k, kaijyo):",
"+ return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD",
"-def getList():",
"- return list(map(int, input().split()))",
"+def npk(n, k, kaijyo):",
"+ if k == 0 or k == n:",
"+ return n % MOD",
"+ return (kaijyo[n] * divide(kaijyo[n - k])) % MOD",
"-import math",
"-",
"-MOD = 10**9 + 7",
"+def kaijyo(n):",
"+ ret = [1]",
"+ for i in range(1, n + 1):",
"+ ret.append((ret[-1] * i) % MOD)",
"+ return ret",
"-def factorial(n):",
"+def solve():",
"+ n = getN()",
"+ S = getS()",
"+ rev = 0",
"- for i in range(1, n + 1):",
"- ans *= i",
"- ans %= MOD",
"- return ans % MOD",
"+ for c in S:",
"+ if c == \"W\":",
"+ if rev == 0:",
"+ print((0))",
"+ return",
"+ if rev % 2 == 0:",
"+ ans *= rev",
"+ ans %= MOD",
"+ rev -= 1",
"+ else:",
"+ rev += 1",
"+ else:",
"+ if rev % 2 == 1:",
"+ ans *= rev",
"+ ans %= MOD",
"+ rev -= 1",
"+ else:",
"+ rev += 1",
"+ # print(ans)",
"+ if rev == 0:",
"+ print(((ans * kaijyo(n)[-1]) % MOD))",
"+ else:",
"+ print((0))",
"-n = getN()",
"-s = input().strip()",
"-ans = 1",
"-open = 0",
"-for c in s:",
"- # print(c, ans, open, cur)",
"- if c == \"B\":",
"- if open % 2 == 0:",
"- open += 1",
"- else:",
"- if open == 0:",
"- print((0))",
"- sys.exit()",
"- ans *= open",
"- ans %= MOD",
"- open -= 1",
"- else:",
"- if open % 2 == 1:",
"- open += 1",
"- else:",
"- if open == 0:",
"- print((0))",
"- sys.exit()",
"- ans *= open",
"- ans %= MOD",
"- open -= 1",
"-if open != 0:",
"- print((0))",
"- sys.exit()",
"-print(((ans * factorial(n)) % MOD))",
"+def main():",
"+ n = getN()",
"+ for _ in range(n):",
"+ solve()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ # main()",
"+ solve()"
]
| false | 0.034956 | 0.037213 | 0.939365 | [
"s885064079",
"s888953096"
]
|
u386819480 | p02860 | python | s378115011 | s194809888 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, S: str):
if N%2 == 0:
if S[:N//2] == S[N//2:]:
print(YES)
exit()
print(NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, S: str):
if S[:N//2] == S[N//2:]:
print(YES)
else:
print(NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == '__main__':
main()
| 31 | 30 | 606 | 567 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1 << 32
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, S: str):
if N % 2 == 0:
if S[: N // 2] == S[N // 2 :]:
print(YES)
exit()
print(NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1 << 32
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, S: str):
if S[: N // 2] == S[N // 2 :]:
print(YES)
else:
print(NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| false | 3.225806 | [
"- if N % 2 == 0:",
"- if S[: N // 2] == S[N // 2 :]:",
"- print(YES)",
"- exit()",
"- print(NO)",
"+ if S[: N // 2] == S[N // 2 :]:",
"+ print(YES)",
"+ else:",
"+ print(NO)"
]
| false | 0.043559 | 0.044101 | 0.987708 | [
"s378115011",
"s194809888"
]
|
u342869120 | p03165 | python | s130177240 | s263360110 | 942 | 756 | 112,732 | 112,476 | Accepted | Accepted | 19.75 | s = input().strip()
t = input().strip()
ls = len(s)
lt = len(t)
dp = [[0]*(lt+1) for i in range(ls+1)]
for i in range(ls):
for j in range(lt):
v = dp[i][j]+1 if s[i] == t[j] else 0
dp[i+1][j+1] = max([v, dp[i+1][j], dp[i][j+1]])
ans = ''
i, j = ls, lt
while i > 0 and j > 0:
if dp[i][j] == dp[i-1][j]:
i -= 1
elif dp[i][j] == dp[i][j-1]:
j -= 1
else:
ans = s[i-1]+ans
i -= 1
j -= 1
print(ans) |
s = input().strip()
t = input().strip()
ls = len(s)
lt = len(t)
dp = [[0]*(lt+1) for i in range(ls+1)]
for i in range(ls):
for j in range(lt):
if s[i] == t[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 = ls, lt
while i > 0 and j > 0:
if dp[i][j] == dp[i-1][j]:
i -= 1
elif dp[i][j] == dp[i][j-1]:
j -= 1
else:
ans = s[i-1]+ans
i -= 1
j -= 1
print(ans) | 25 | 28 | 492 | 528 | s = input().strip()
t = input().strip()
ls = len(s)
lt = len(t)
dp = [[0] * (lt + 1) for i in range(ls + 1)]
for i in range(ls):
for j in range(lt):
v = dp[i][j] + 1 if s[i] == t[j] else 0
dp[i + 1][j + 1] = max([v, dp[i + 1][j], dp[i][j + 1]])
ans = ""
i, j = ls, lt
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans = s[i - 1] + ans
i -= 1
j -= 1
print(ans)
| s = input().strip()
t = input().strip()
ls = len(s)
lt = len(t)
dp = [[0] * (lt + 1) for i in range(ls + 1)]
for i in range(ls):
for j in range(lt):
if s[i] == t[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 = ls, lt
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans = s[i - 1] + ans
i -= 1
j -= 1
print(ans)
| false | 10.714286 | [
"- v = dp[i][j] + 1 if s[i] == t[j] else 0",
"- dp[i + 1][j + 1] = max([v, dp[i + 1][j], dp[i][j + 1]])",
"+ if s[i] == t[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]])"
]
| false | 0.042323 | 0.041508 | 1.01963 | [
"s130177240",
"s263360110"
]
|
u432453907 | p03434 | python | s392806887 | s867242636 | 29 | 26 | 9,048 | 9,088 | Accepted | Accepted | 10.34 | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
a.append(0)
Ali,Bob=0,0
for i in range(0,n,2):
Ali +=a[i]
Bob +=a[i+1]
print((Ali-Bob)) | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
Ali,Bob=0,0
for i in range(n):
if i%2==0:
Ali +=a[i]
else:
Bob +=a[i]
print((Ali-Bob)) | 9 | 10 | 170 | 186 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
a.append(0)
Ali, Bob = 0, 0
for i in range(0, n, 2):
Ali += a[i]
Bob += a[i + 1]
print((Ali - Bob))
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
Ali, Bob = 0, 0
for i in range(n):
if i % 2 == 0:
Ali += a[i]
else:
Bob += a[i]
print((Ali - Bob))
| false | 10 | [
"-a.append(0)",
"-for i in range(0, n, 2):",
"- Ali += a[i]",
"- Bob += a[i + 1]",
"+for i in range(n):",
"+ if i % 2 == 0:",
"+ Ali += a[i]",
"+ else:",
"+ Bob += a[i]"
]
| false | 0.042489 | 0.0435 | 0.976772 | [
"s392806887",
"s867242636"
]
|
u729133443 | p03679 | python | s980951138 | s774245911 | 164 | 27 | 38,256 | 9,148 | Accepted | Accepted | 83.54 | x,a,b=list(map(int,input().split()));print((['delicious',['safe','dangerous'][b-a>x]][a-b<0])) | x,a,b=list(map(int,input().split()))
print((('delicious',('safe','dangerous')[b-a>x])[a<b])) | 1 | 2 | 86 | 85 | x, a, b = list(map(int, input().split()))
print((["delicious", ["safe", "dangerous"][b - a > x]][a - b < 0]))
| x, a, b = list(map(int, input().split()))
print((("delicious", ("safe", "dangerous")[b - a > x])[a < b]))
| false | 50 | [
"-print(([\"delicious\", [\"safe\", \"dangerous\"][b - a > x]][a - b < 0]))",
"+print(((\"delicious\", (\"safe\", \"dangerous\")[b - a > x])[a < b]))"
]
| false | 0.039065 | 0.034722 | 1.125085 | [
"s980951138",
"s774245911"
]
|
u366959492 | p02861 | python | s925920234 | s337295797 | 213 | 194 | 40,812 | 74,512 | Accepted | Accepted | 8.92 | n=int(eval(input()))
xy=[list(map(int,input().split())) for _ in range(n)]
import itertools as it
ans=0
for i in it.permutations(list(range(n)),n):
x=xy[i[0]][0]
y=xy[i[0]][1]
for k in range(1,n):
j=i[k]
ans+=((x-xy[j][0])**2+(y-xy[j][1])**2)**0.5
x=xy[j][0]
y=xy[j][1]
N=1
for i in range(1,n+1):
N*=i
print((ans/N))
| n=int(eval(input()))
xy=[list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
ans=0
for i in permutations(list(range(n)),n):
for j in range(1,n):
ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
for i in range(1,n+1):
ans/=i
print(ans)
| 16 | 12 | 366 | 318 | n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
import itertools as it
ans = 0
for i in it.permutations(list(range(n)), n):
x = xy[i[0]][0]
y = xy[i[0]][1]
for k in range(1, n):
j = i[k]
ans += ((x - xy[j][0]) ** 2 + (y - xy[j][1]) ** 2) ** 0.5
x = xy[j][0]
y = xy[j][1]
N = 1
for i in range(1, n + 1):
N *= i
print((ans / N))
| n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
from itertools import permutations
ans = 0
for i in permutations(list(range(n)), n):
for j in range(1, n):
ans += (
(xy[i[j]][0] - xy[i[j - 1]][0]) ** 2 + (xy[i[j]][1] - xy[i[j - 1]][1]) ** 2
) ** 0.5
for i in range(1, n + 1):
ans /= i
print(ans)
| false | 25 | [
"-import itertools as it",
"+from itertools import permutations",
"-for i in it.permutations(list(range(n)), n):",
"- x = xy[i[0]][0]",
"- y = xy[i[0]][1]",
"- for k in range(1, n):",
"- j = i[k]",
"- ans += ((x - xy[j][0]) ** 2 + (y - xy[j][1]) ** 2) ** 0.5",
"- x = xy[j][0]",
"- y = xy[j][1]",
"-N = 1",
"+for i in permutations(list(range(n)), n):",
"+ for j in range(1, n):",
"+ ans += (",
"+ (xy[i[j]][0] - xy[i[j - 1]][0]) ** 2 + (xy[i[j]][1] - xy[i[j - 1]][1]) ** 2",
"+ ) ** 0.5",
"- N *= i",
"-print((ans / N))",
"+ ans /= i",
"+print(ans)"
]
| false | 0.045499 | 0.045452 | 1.001034 | [
"s925920234",
"s337295797"
]
|
u072053884 | p02243 | python | s591350829 | s774683209 | 1,180 | 520 | 121,748 | 70,692 | Accepted | Accepted | 55.93 | import sys
f_i = sys.stdin
n = int(f_i.readline())
class VCost:
def __init__(self, v, cost):
self.v_n = v
self.cost = cost
def __lt__(self, other):
return self.cost < other.cost
def __gt__(self, other):
return self.cost > other.cost
adj = [[VCost(int(v), int(c)) for v, c in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]
import heapq
def dijkstra():
PQ = []
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
heapq.heappush(PQ, VCost(0, 0))
while PQ:
uc = heapq.heappop(PQ)
u = uc.v_n
if uc.cost > distance[uc.v_n]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc.v_n
if isVisited[v] == True:
continue
t_cost = distance[u] + vc.cost
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, VCost(v, t_cost))
for v, d in enumerate(distance):
print((v, d))
dijkstra() | import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [[(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]
import heapq
def dijkstra():
PQ = []
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
heapq.heappush(PQ, (0, 0))
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
if uc[0] > distance[u]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc[1]
if isVisited[v] == True:
continue
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra() | 50 | 41 | 1,103 | 851 | import sys
f_i = sys.stdin
n = int(f_i.readline())
class VCost:
def __init__(self, v, cost):
self.v_n = v
self.cost = cost
def __lt__(self, other):
return self.cost < other.cost
def __gt__(self, other):
return self.cost > other.cost
adj = [
[VCost(int(v), int(c)) for v, c in zip(x.split()[2::2], x.split()[3::2])]
for x in f_i
]
import heapq
def dijkstra():
PQ = []
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
heapq.heappush(PQ, VCost(0, 0))
while PQ:
uc = heapq.heappop(PQ)
u = uc.v_n
if uc.cost > distance[uc.v_n]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc.v_n
if isVisited[v] == True:
continue
t_cost = distance[u] + vc.cost
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, VCost(v, t_cost))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
| import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [
[(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])]
for x in f_i
]
import heapq
def dijkstra():
PQ = []
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
heapq.heappush(PQ, (0, 0))
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
if uc[0] > distance[u]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc[1]
if isVisited[v] == True:
continue
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
| false | 18 | [
"-",
"-",
"-class VCost:",
"- def __init__(self, v, cost):",
"- self.v_n = v",
"- self.cost = cost",
"-",
"- def __lt__(self, other):",
"- return self.cost < other.cost",
"-",
"- def __gt__(self, other):",
"- return self.cost > other.cost",
"-",
"-",
"- [VCost(int(v), int(c)) for v, c in zip(x.split()[2::2], x.split()[3::2])]",
"+ [(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])]",
"- heapq.heappush(PQ, VCost(0, 0))",
"+ heapq.heappush(PQ, (0, 0))",
"- u = uc.v_n",
"- if uc.cost > distance[uc.v_n]:",
"+ u = uc[1]",
"+ if uc[0] > distance[u]:",
"- v = vc.v_n",
"+ v = vc[1]",
"- t_cost = distance[u] + vc.cost",
"+ t_cost = distance[u] + vc[0]",
"- heapq.heappush(PQ, VCost(v, t_cost))",
"+ heapq.heappush(PQ, (t_cost, v))"
]
| false | 0.113489 | 0.040525 | 2.800498 | [
"s591350829",
"s774683209"
]
|
u564589929 | p03836 | python | s647154150 | s501583093 | 119 | 29 | 27,192 | 9,232 | Accepted | Accepted | 75.63 | import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(eval(input()))
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
sx, sy, tx, ty = MI()
ans = deque([])
# path1
ans.extend(['U']*abs(ty - sy))
ans.extend(['R']*abs(tx - sx))
# path2
ans.extend(['D']*abs(ty - sy))
ans.extend(['L']*abs(tx - sx))
# path3
ans.extend(['L'])
ans.extend(['U']*(abs(ty - sy)+1))
ans.extend(['R']*(abs(tx - sx)+1))
ans.extend(['D'])
# path4
ans.extend(['R'])
ans.extend(['D'] * (abs(ty - sy)+1))
ans.extend(['L'] * (abs(tx - sx)+1))
ans.extend(['U'])
# print(ans)
printlist(ans, '')
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(eval(input()))
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
sx, sy, tx, ty = MI()
ans = ''
# path1
ans += 'U' * abs(ty - sy) + 'R' * abs(tx - sx)
# path2
ans += 'D' * abs(ty - sy) + 'L' * abs(tx - sx)
# path3
ans += 'L' + 'U' * (abs(ty - sy) + 1) + 'R' * (abs(tx - sx) + 1) + 'D'
# path4
ans += 'R' + 'D' * (abs(ty - sy) + 1) + 'L' * (abs(tx - sx) + 1) + 'U'
print(ans)
if __name__ == '__main__':
solve()
| 52 | 42 | 1,547 | 1,372 | import sys
sys.setrecursionlimit(10**9)
# input = sys.stdin.readline ####
def int1(x):
return int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def MS():
return input().split()
def LS():
return list(eval(input()))
def LLS(rows_number):
return [LS() for _ in range(rows_number)]
def printlist(lst, k=" "):
print((k.join(list(map(str, lst)))))
INF = float("inf")
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
sx, sy, tx, ty = MI()
ans = deque([])
# path1
ans.extend(["U"] * abs(ty - sy))
ans.extend(["R"] * abs(tx - sx))
# path2
ans.extend(["D"] * abs(ty - sy))
ans.extend(["L"] * abs(tx - sx))
# path3
ans.extend(["L"])
ans.extend(["U"] * (abs(ty - sy) + 1))
ans.extend(["R"] * (abs(tx - sx) + 1))
ans.extend(["D"])
# path4
ans.extend(["R"])
ans.extend(["D"] * (abs(ty - sy) + 1))
ans.extend(["L"] * (abs(tx - sx) + 1))
ans.extend(["U"])
# print(ans)
printlist(ans, "")
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**9)
# input = sys.stdin.readline ####
def int1(x):
return int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def MS():
return input().split()
def LS():
return list(eval(input()))
def LLS(rows_number):
return [LS() for _ in range(rows_number)]
def printlist(lst, k=" "):
print((k.join(list(map(str, lst)))))
INF = float("inf")
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
sx, sy, tx, ty = MI()
ans = ""
# path1
ans += "U" * abs(ty - sy) + "R" * abs(tx - sx)
# path2
ans += "D" * abs(ty - sy) + "L" * abs(tx - sx)
# path3
ans += "L" + "U" * (abs(ty - sy) + 1) + "R" * (abs(tx - sx) + 1) + "D"
# path4
ans += "R" + "D" * (abs(ty - sy) + 1) + "L" * (abs(tx - sx) + 1) + "U"
print(ans)
if __name__ == "__main__":
solve()
| false | 19.230769 | [
"-from collections import deque",
"-",
"+# from collections import deque",
"-import numpy as np # cumsum",
"-",
"+# import numpy as np # cumsum",
"- ans = deque([])",
"+ ans = \"\"",
"- ans.extend([\"U\"] * abs(ty - sy))",
"- ans.extend([\"R\"] * abs(tx - sx))",
"+ ans += \"U\" * abs(ty - sy) + \"R\" * abs(tx - sx)",
"- ans.extend([\"D\"] * abs(ty - sy))",
"- ans.extend([\"L\"] * abs(tx - sx))",
"+ ans += \"D\" * abs(ty - sy) + \"L\" * abs(tx - sx)",
"- ans.extend([\"L\"])",
"- ans.extend([\"U\"] * (abs(ty - sy) + 1))",
"- ans.extend([\"R\"] * (abs(tx - sx) + 1))",
"- ans.extend([\"D\"])",
"+ ans += \"L\" + \"U\" * (abs(ty - sy) + 1) + \"R\" * (abs(tx - sx) + 1) + \"D\"",
"- ans.extend([\"R\"])",
"- ans.extend([\"D\"] * (abs(ty - sy) + 1))",
"- ans.extend([\"L\"] * (abs(tx - sx) + 1))",
"- ans.extend([\"U\"])",
"- # print(ans)",
"- printlist(ans, \"\")",
"+ ans += \"R\" + \"D\" * (abs(ty - sy) + 1) + \"L\" * (abs(tx - sx) + 1) + \"U\"",
"+ print(ans)"
]
| false | 0.263811 | 0.04579 | 5.761379 | [
"s647154150",
"s501583093"
]
|
u281610856 | p03274 | python | s719330872 | s129154158 | 98 | 76 | 14,384 | 14,168 | Accepted | Accepted | 22.45 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10 ** 10
for i in range(n-k+1):
l, r = a[i], a[i + k -1]
time = min(abs(l) + abs(l - r), abs(r) + abs(l - r))
ans = min(ans, time)
print(ans) | import sys
input = sys.stdin.readline
INF = float("inf")
def main():
n, k = list(map(int, input().split()))
X = list(map(int, input().split()))
if n == 1 and k == 1:
print((0))
exit()
ans = INF
for i in range(n - k + 1):
l, r = X[i], X[i + k - 1]
tmp = r - l
if l * r < 0:
tmp += min(abs(l), abs(r))
else:
tmp += min(abs(l), abs(r))
ans = min(tmp, ans)
print(ans)
if __name__ == '__main__':
main() | 8 | 25 | 235 | 525 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10**10
for i in range(n - k + 1):
l, r = a[i], a[i + k - 1]
time = min(abs(l) + abs(l - r), abs(r) + abs(l - r))
ans = min(ans, time)
print(ans)
| import sys
input = sys.stdin.readline
INF = float("inf")
def main():
n, k = list(map(int, input().split()))
X = list(map(int, input().split()))
if n == 1 and k == 1:
print((0))
exit()
ans = INF
for i in range(n - k + 1):
l, r = X[i], X[i + k - 1]
tmp = r - l
if l * r < 0:
tmp += min(abs(l), abs(r))
else:
tmp += min(abs(l), abs(r))
ans = min(tmp, ans)
print(ans)
if __name__ == "__main__":
main()
| false | 68 | [
"-n, k = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-ans = 10**10",
"-for i in range(n - k + 1):",
"- l, r = a[i], a[i + k - 1]",
"- time = min(abs(l) + abs(l - r), abs(r) + abs(l - r))",
"- ans = min(ans, time)",
"-print(ans)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+INF = float(\"inf\")",
"+",
"+",
"+def main():",
"+ n, k = list(map(int, input().split()))",
"+ X = list(map(int, input().split()))",
"+ if n == 1 and k == 1:",
"+ print((0))",
"+ exit()",
"+ ans = INF",
"+ for i in range(n - k + 1):",
"+ l, r = X[i], X[i + k - 1]",
"+ tmp = r - l",
"+ if l * r < 0:",
"+ tmp += min(abs(l), abs(r))",
"+ else:",
"+ tmp += min(abs(l), abs(r))",
"+ ans = min(tmp, ans)",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.093041 | 0.090803 | 1.02465 | [
"s719330872",
"s129154158"
]
|
u844789719 | p03343 | python | s863063247 | s286995150 | 1,847 | 1,323 | 3,444 | 67,164 | Accepted | Accepted | 28.37 | import heapq
N, K, Q = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
sA = sorted(set(A))
A += [-1]
ans = float('inf')
for amin in sA:
cand = []
fr = 0
to = -1
for i in range(N + 1):
a = A[i]
if a >= amin:
if fr == -1:
fr = i
elif a < amin and fr >= 0:
cand += sorted(A[fr:i])[:max(0, i - fr - K + 1)]
fr = -1
if len(cand) < Q:
break
ans = min(ans, sorted(cand)[Q - 1] - amin)
print(ans)
| import heapq
N, K, Q = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
sA = sorted(A)
A += [-1]
ans = float('inf')
for amin in sA:
cand = []
dp = []
for i in range(N + 1):
a = A[i]
if a >= amin:
heapq.heappush(dp, a)
if len(dp) and a < amin:
m = len(dp) - K + 1
for _ in range(m):
heapq.heappush(cand, heapq.heappop(dp))
dp = []
y = float('inf')
if len(cand) < Q:
break
for _ in range(Q - 1):
heapq.heappop(cand)
ans = min(ans, heapq.heappop(cand) - amin)
print(ans)
| 23 | 25 | 544 | 647 | import heapq
N, K, Q = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
sA = sorted(set(A))
A += [-1]
ans = float("inf")
for amin in sA:
cand = []
fr = 0
to = -1
for i in range(N + 1):
a = A[i]
if a >= amin:
if fr == -1:
fr = i
elif a < amin and fr >= 0:
cand += sorted(A[fr:i])[: max(0, i - fr - K + 1)]
fr = -1
if len(cand) < Q:
break
ans = min(ans, sorted(cand)[Q - 1] - amin)
print(ans)
| import heapq
N, K, Q = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
sA = sorted(A)
A += [-1]
ans = float("inf")
for amin in sA:
cand = []
dp = []
for i in range(N + 1):
a = A[i]
if a >= amin:
heapq.heappush(dp, a)
if len(dp) and a < amin:
m = len(dp) - K + 1
for _ in range(m):
heapq.heappush(cand, heapq.heappop(dp))
dp = []
y = float("inf")
if len(cand) < Q:
break
for _ in range(Q - 1):
heapq.heappop(cand)
ans = min(ans, heapq.heappop(cand) - amin)
print(ans)
| false | 8 | [
"-sA = sorted(set(A))",
"+sA = sorted(A)",
"- fr = 0",
"- to = -1",
"+ dp = []",
"- if fr == -1:",
"- fr = i",
"- elif a < amin and fr >= 0:",
"- cand += sorted(A[fr:i])[: max(0, i - fr - K + 1)]",
"- fr = -1",
"+ heapq.heappush(dp, a)",
"+ if len(dp) and a < amin:",
"+ m = len(dp) - K + 1",
"+ for _ in range(m):",
"+ heapq.heappush(cand, heapq.heappop(dp))",
"+ dp = []",
"+ y = float(\"inf\")",
"- ans = min(ans, sorted(cand)[Q - 1] - amin)",
"+ for _ in range(Q - 1):",
"+ heapq.heappop(cand)",
"+ ans = min(ans, heapq.heappop(cand) - amin)"
]
| false | 0.097971 | 0.079116 | 1.238324 | [
"s863063247",
"s286995150"
]
|
u876438858 | p02687 | python | s257558964 | s532241903 | 26 | 24 | 9,356 | 9,020 | Accepted | Accepted | 7.69 | import sys
from math import sqrt
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(MI())
def LIN(n: int):
return [I() for _ in range(n)]
inf = float("inf")
mod = 10 ** 9 + 7
def main():
s = input().rstrip()
if s == "ABC":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
def solve(S: str):
if S == "ABC":
print("ARC")
else:
print("ABC")
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
solve(S)
if __name__ == "__main__":
main()
| 38 | 26 | 542 | 584 | import sys
from math import sqrt
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(MI())
def LIN(n: int):
return [I() for _ in range(n)]
inf = float("inf")
mod = 10**9 + 7
def main():
s = input().rstrip()
if s == "ABC":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
def solve(S: str):
if S == "ABC":
print("ARC")
else:
print("ABC")
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
solve(S)
if __name__ == "__main__":
main()
| false | 31.578947 | [
"+#!/usr/bin/env python3",
"-from math import sqrt",
"-from collections import Counter, defaultdict, deque",
"-",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**6)",
"-def I():",
"- return int(eval(input()))",
"-",
"-",
"-def MI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def LI():",
"- return list(MI())",
"-",
"-",
"-def LIN(n: int):",
"- return [I() for _ in range(n)]",
"-",
"-",
"-inf = float(\"inf\")",
"-mod = 10**9 + 7",
"-",
"-",
"-def main():",
"- s = input().rstrip()",
"- if s == \"ABC\":",
"+def solve(S: str):",
"+ if S == \"ABC\":",
"+ return",
"+",
"+",
"+# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)",
"+def main():",
"+ def iterate_tokens():",
"+ for line in sys.stdin:",
"+ for word in line.split():",
"+ yield word",
"+",
"+ tokens = iterate_tokens()",
"+ S = next(tokens) # type: str",
"+ solve(S)"
]
| false | 0.127505 | 0.047294 | 2.696023 | [
"s257558964",
"s532241903"
]
|
u442346200 | p02396 | python | s292523112 | s618846123 | 140 | 110 | 6,724 | 6,720 | Accepted | Accepted | 21.43 | c = 0
while True:
x =int(eval(input()))
if x == 0:
break;
c += 1
print(('Case', str(c) + ':', x)) | count = 1
while True:
x = input().strip()
if x == '0':
break
print(('Case %s: %s' % (count, x)))
count = count + 1 | 8 | 7 | 121 | 142 | c = 0
while True:
x = int(eval(input()))
if x == 0:
break
c += 1
print(("Case", str(c) + ":", x))
| count = 1
while True:
x = input().strip()
if x == "0":
break
print(("Case %s: %s" % (count, x)))
count = count + 1
| false | 12.5 | [
"-c = 0",
"+count = 1",
"- x = int(eval(input()))",
"- if x == 0:",
"+ x = input().strip()",
"+ if x == \"0\":",
"- c += 1",
"- print((\"Case\", str(c) + \":\", x))",
"+ print((\"Case %s: %s\" % (count, x)))",
"+ count = count + 1"
]
| false | 0.115297 | 0.04621 | 2.495047 | [
"s292523112",
"s618846123"
]
|
u346812984 | p02762 | python | s038816831 | s429758103 | 1,627 | 1,072 | 56,496 | 46,848 | Accepted | Accepted | 34.11 | import sys
sys.setrecursionlimit(10 ** 6)
class UnionFind:
def __init__(self, n_nodes):
self.parent = [i for i in range(n_nodes)]
self.rank = [0] * n_nodes
self.size = [1] * n_nodes
def find(self, x):
if x == self.parent[x]:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.parent[y] = x
self.size[x] += self.size[y]
else:
self.parent[x] = y
self.size[y] += self.size[x]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
N, M, K = map(int, input().split())
tree = UnionFind(N)
exclusion = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
tree.unite(a, b)
exclusion[a].append(b)
exclusion[b].append(a)
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
if not tree.check(c, d):
continue
exclusion[c].append(d)
exclusion[d].append(c)
for i in range(N):
# 同一グループで自分以外の人数
n = tree.get_size(i) - 1
ans = n - len(exclusion[i])
print(ans, end=" ")
| import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
class UnionFind:
def __init__(self, n_nodes):
self.n_nodes = n_nodes
# self.parents[x] < 0 の時,xが根である.
# また,xが根の時,(-1) * (同一グループの要素数) が格納されるようになる.
self.parents = [-1] * n_nodes
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
# 常にxの方が要素数が多くなるように,スワップする
if self.parents[x] > self.parents[y]:
x, y = y, x
# 要素数の少ない方のグループを,要素数が多い方の木に貼る.
self.parents[x] += self.parents[y]
self.parents[y] = x
def get_size(self, x):
return -self.parents[self.find(x)]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_members(self, x):
parent = self.find(x)
return [i for i in range(self.n_nodes) if self.find(i) == parent]
def get_parent_list(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def get_n_groups(self):
return len(self.get_parent_list())
def get_members_dict(self):
return {par: self.get_members(par) for par in self.get_parent_list()}
def main():
N, M, K = map(int, input().split())
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
tree.unite(a, b)
friends[a].append(b)
friends[b].append(a)
ng = [[] for _ in range(N)]
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
ng[c].append(d)
ng[d].append(c)
ans = []
for i in range(N):
n_ng = 0
for j in ng[i]:
if tree.is_same(i, j):
n_ng += 1
n_member = tree.get_size(i)
n_friends = len(friends[i])
# 自分を引くのを忘れない
ans.append(n_member - n_friends - n_ng - 1)
print(*ans, sep=" ")
if __name__ == "__main__":
main()
| 66 | 99 | 1,543 | 2,344 | import sys
sys.setrecursionlimit(10**6)
class UnionFind:
def __init__(self, n_nodes):
self.parent = [i for i in range(n_nodes)]
self.rank = [0] * n_nodes
self.size = [1] * n_nodes
def find(self, x):
if x == self.parent[x]:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.parent[y] = x
self.size[x] += self.size[y]
else:
self.parent[x] = y
self.size[y] += self.size[x]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
N, M, K = map(int, input().split())
tree = UnionFind(N)
exclusion = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
tree.unite(a, b)
exclusion[a].append(b)
exclusion[b].append(a)
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
if not tree.check(c, d):
continue
exclusion[c].append(d)
exclusion[d].append(c)
for i in range(N):
# 同一グループで自分以外の人数
n = tree.get_size(i) - 1
ans = n - len(exclusion[i])
print(ans, end=" ")
| import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
class UnionFind:
def __init__(self, n_nodes):
self.n_nodes = n_nodes
# self.parents[x] < 0 の時,xが根である.
# また,xが根の時,(-1) * (同一グループの要素数) が格納されるようになる.
self.parents = [-1] * n_nodes
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
# 常にxの方が要素数が多くなるように,スワップする
if self.parents[x] > self.parents[y]:
x, y = y, x
# 要素数の少ない方のグループを,要素数が多い方の木に貼る.
self.parents[x] += self.parents[y]
self.parents[y] = x
def get_size(self, x):
return -self.parents[self.find(x)]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_members(self, x):
parent = self.find(x)
return [i for i in range(self.n_nodes) if self.find(i) == parent]
def get_parent_list(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def get_n_groups(self):
return len(self.get_parent_list())
def get_members_dict(self):
return {par: self.get_members(par) for par in self.get_parent_list()}
def main():
N, M, K = map(int, input().split())
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
tree.unite(a, b)
friends[a].append(b)
friends[b].append(a)
ng = [[] for _ in range(N)]
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
ng[c].append(d)
ng[d].append(c)
ans = []
for i in range(N):
n_ng = 0
for j in ng[i]:
if tree.is_same(i, j):
n_ng += 1
n_member = tree.get_size(i)
n_friends = len(friends[i])
# 自分を引くのを忘れない
ans.append(n_member - n_friends - n_ng - 1)
print(*ans, sep=" ")
if __name__ == "__main__":
main()
| false | 33.333333 | [
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"- self.parent = [i for i in range(n_nodes)]",
"- self.rank = [0] * n_nodes",
"- self.size = [1] * n_nodes",
"+ self.n_nodes = n_nodes",
"+ # self.parents[x] < 0 の時,xが根である.",
"+ # また,xが根の時,(-1) * (同一グループの要素数) が格納されるようになる.",
"+ self.parents = [-1] * n_nodes",
"- if x == self.parent[x]:",
"+ if self.parents[x] < 0:",
"- self.parent[x] = self.find(self.parent[x])",
"- return self.parent[x]",
"+ self.parents[x] = self.find(self.parents[x])",
"+ return self.parents[x]",
"- if self.rank[x] > self.rank[y]:",
"- self.parent[y] = x",
"- self.size[x] += self.size[y]",
"- else:",
"- self.parent[x] = y",
"- self.size[y] += self.size[x]",
"- if self.rank[x] == self.rank[y]:",
"- self.rank[x] += 1",
"+ # 常にxの方が要素数が多くなるように,スワップする",
"+ if self.parents[x] > self.parents[y]:",
"+ x, y = y, x",
"+ # 要素数の少ない方のグループを,要素数が多い方の木に貼る.",
"+ self.parents[x] += self.parents[y]",
"+ self.parents[y] = x",
"- def check(self, x, y):",
"+ def get_size(self, x):",
"+ return -self.parents[self.find(x)]",
"+",
"+ def is_same(self, x, y):",
"- def get_size(self, x):",
"- return self.size[self.find(x)]",
"+ def get_members(self, x):",
"+ parent = self.find(x)",
"+ return [i for i in range(self.n_nodes) if self.find(i) == parent]",
"+",
"+ def get_parent_list(self):",
"+ return [i for i, x in enumerate(self.parents) if x < 0]",
"+",
"+ def get_n_groups(self):",
"+ return len(self.get_parent_list())",
"+",
"+ def get_members_dict(self):",
"+ return {par: self.get_members(par) for par in self.get_parent_list()}",
"-N, M, K = map(int, input().split())",
"-tree = UnionFind(N)",
"-exclusion = [[] for _ in range(N)]",
"-for _ in range(M):",
"- a, b = map(int, input().split())",
"- a -= 1",
"- b -= 1",
"- tree.unite(a, b)",
"- exclusion[a].append(b)",
"- exclusion[b].append(a)",
"-for _ in range(K):",
"- c, d = map(int, input().split())",
"- c -= 1",
"- d -= 1",
"- if not tree.check(c, d):",
"- continue",
"- exclusion[c].append(d)",
"- exclusion[d].append(c)",
"-for i in range(N):",
"- # 同一グループで自分以外の人数",
"- n = tree.get_size(i) - 1",
"- ans = n - len(exclusion[i])",
"- print(ans, end=\" \")",
"+def main():",
"+ N, M, K = map(int, input().split())",
"+ tree = UnionFind(N)",
"+ friends = [[] for _ in range(N)]",
"+ for _ in range(M):",
"+ a, b = map(int, input().split())",
"+ a -= 1",
"+ b -= 1",
"+ tree.unite(a, b)",
"+ friends[a].append(b)",
"+ friends[b].append(a)",
"+ ng = [[] for _ in range(N)]",
"+ for _ in range(K):",
"+ c, d = map(int, input().split())",
"+ c -= 1",
"+ d -= 1",
"+ ng[c].append(d)",
"+ ng[d].append(c)",
"+ ans = []",
"+ for i in range(N):",
"+ n_ng = 0",
"+ for j in ng[i]:",
"+ if tree.is_same(i, j):",
"+ n_ng += 1",
"+ n_member = tree.get_size(i)",
"+ n_friends = len(friends[i])",
"+ # 自分を引くのを忘れない",
"+ ans.append(n_member - n_friends - n_ng - 1)",
"+ print(*ans, sep=\" \")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.04477 | 0.183014 | 0.244624 | [
"s038816831",
"s429758103"
]
|
u285891772 | p02947 | python | s648811419 | s649138734 | 383 | 309 | 26,320 | 21,612 | Accepted | Accepted | 19.32 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *
N = INT()
s = [str(sorted(list(eval(input())))) for _ in range(N)]
dic = Counter(s)
ans = 0
for v in list(dic.values()):
ans += v*(v-1)//2
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *
N = INT()
s = ["".join(sorted(list(eval(input())))) for _ in range(N)]
dic = defaultdict(int)
for x in s:
dic[x] += 1
ans = 0
for v in list(dic.values()):
ans += v*(v-1)//2
print(ans)
| 32 | 35 | 1,044 | 1,083 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
# from decimal import *
N = INT()
s = [str(sorted(list(eval(input())))) for _ in range(N)]
dic = Counter(s)
ans = 0
for v in list(dic.values()):
ans += v * (v - 1) // 2
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
# from decimal import *
N = INT()
s = ["".join(sorted(list(eval(input())))) for _ in range(N)]
dic = defaultdict(int)
for x in s:
dic[x] += 1
ans = 0
for v in list(dic.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 8.571429 | [
"-s = [str(sorted(list(eval(input())))) for _ in range(N)]",
"-dic = Counter(s)",
"+s = [\"\".join(sorted(list(eval(input())))) for _ in range(N)]",
"+dic = defaultdict(int)",
"+for x in s:",
"+ dic[x] += 1"
]
| false | 0.046927 | 0.043913 | 1.068645 | [
"s648811419",
"s649138734"
]
|
u588341295 | p03150 | python | s287335996 | s887634883 | 39 | 21 | 5,220 | 3,188 | Accepted | Accepted | 46.15 | # -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
S = eval(input())
target = 'keyence'
for i in range(len(target)+1):
a = target[:i]
b = target[i:]
if re.match('^' + a + '.*' + b + '$', S):
print('YES')
exit()
print('NO')
| import sys
import re
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
S = 'keyence'
N = len(S)
T = eval(input())
M = len(T)
for i in range(N+1):
S1 = S[:i]
S2 = S[i:]
exp = '^{0}(.*){1}$'.format(S1, S2)
if re.match(exp, T):
YES()
exit()
NO()
| 42 | 32 | 1,494 | 892 | # -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def round(x):
return int((x * 2 + 1) // 2)
def fermat(x, y, MOD):
return x * pow(y, MOD - 2, MOD) % MOD
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(nums):
return reduce(lcm, nums, 1)
def gcd_list(nums):
return reduce(gcd, nums, nums[0])
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
S = eval(input())
target = "keyence"
for i in range(len(target) + 1):
a = target[:i]
b = target[i:]
if re.match("^" + a + ".*" + b + "$", S):
print("YES")
exit()
print("NO")
| import sys
import re
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
S = "keyence"
N = len(S)
T = eval(input())
M = len(T)
for i in range(N + 1):
S1 = S[:i]
S2 = S[i:]
exp = "^{0}(.*){1}$".format(S1, S2)
if re.match(exp, T):
YES()
exit()
NO()
| false | 23.809524 | [
"-# -*- coding: utf-8 -*-",
"-import sys, re",
"-from collections import deque, defaultdict, Counter",
"-from math import sqrt, hypot, factorial, pi, sin, cos, radians",
"-",
"-if sys.version_info.minor >= 5:",
"- from math import gcd",
"-else:",
"- from fractions import gcd",
"-from heapq import heappop, heappush, heapify, heappushpop",
"-from bisect import bisect_left, bisect_right",
"-from itertools import permutations, combinations, product",
"-from operator import itemgetter, mul",
"-from copy import deepcopy",
"-from functools import reduce, partial",
"-from fractions import Fraction",
"-from string import ascii_lowercase, ascii_uppercase, digits",
"+import sys",
"+import re",
"+def list4d(a, b, c, d, e):",
"+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]",
"+",
"+",
"-",
"-",
"-def round(x):",
"- return int((x * 2 + 1) // 2)",
"-",
"-",
"-def fermat(x, y, MOD):",
"- return x * pow(y, MOD - 2, MOD) % MOD",
"-",
"-",
"-def lcm(x, y):",
"- return (x * y) // gcd(x, y)",
"-",
"-",
"-def lcm_list(nums):",
"- return reduce(lcm, nums, 1)",
"-",
"-",
"-def gcd_list(nums):",
"- return reduce(gcd, nums, nums[0])",
"-def LIST():",
"- return list(map(int, input().split()))",
"+def LIST(N=None):",
"+ return list(MAP()) if N is None else [INT() for i in range(N)]",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def NO():",
"+ print(\"NO\")",
"-INF = float(\"inf\")",
"+INF = 10**19",
"-S = eval(input())",
"-target = \"keyence\"",
"-for i in range(len(target) + 1):",
"- a = target[:i]",
"- b = target[i:]",
"- if re.match(\"^\" + a + \".*\" + b + \"$\", S):",
"- print(\"YES\")",
"+S = \"keyence\"",
"+N = len(S)",
"+T = eval(input())",
"+M = len(T)",
"+for i in range(N + 1):",
"+ S1 = S[:i]",
"+ S2 = S[i:]",
"+ exp = \"^{0}(.*){1}$\".format(S1, S2)",
"+ if re.match(exp, T):",
"+ YES()",
"-print(\"NO\")",
"+NO()"
]
| false | 0.121067 | 0.110555 | 1.095082 | [
"s287335996",
"s887634883"
]
|
u580697892 | p02975 | python | s996159534 | s636131884 | 90 | 78 | 14,212 | 14,212 | Accepted | Accepted | 13.33 | # coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
a = A[i]
if a not in list(d.keys()):
d[a] = 1
else:
d[a] += 1
if len(list(d.keys())) == 1:
if list(d.keys())[0] == 0:
print("Yes")
else:
print("No")
elif len(list(d.keys())) == 2:
keys = list(sorted(list(d.keys())))
if d[keys[0]] == N // 3:
print("Yes")
else:
print("No")
elif len(list(d.keys())) == 3:
keys = list(d.keys())
if keys[0] ^ keys[1] ^ keys[2] == 0:
if d[keys[0]] == d[keys[1]] == d[keys[2]]:
print("Yes")
else:
print("No")
else:
print("No")
else:
print("No") | # coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
# A.sort()
d = {}
for i in range(N):
a = A[i]
if a not in list(d.keys()):
d[a] = 1
else:
d[a] += 1
flag = True
if len(list(d.keys())) == 1:
if list(d.keys())[0] == 0:
flag = True
else:
flag = False
elif len(list(d.keys())) == 2:
keys = list(sorted(list(d.keys())))
if d[keys[0]] == N // 3:
flag = True
else:
flag = False
elif len(list(d.keys())) == 3:
keys = list(d.keys())
if keys[0] ^ keys[1] ^ keys[2] == 0:
if d[keys[0]] == d[keys[1]] == d[keys[2]]:
flag = True
else:
flag = False
else:
flag = False
else:
flag = False
print(("Yes" if flag else "No")) | 33 | 35 | 727 | 776 | # coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
a = A[i]
if a not in list(d.keys()):
d[a] = 1
else:
d[a] += 1
if len(list(d.keys())) == 1:
if list(d.keys())[0] == 0:
print("Yes")
else:
print("No")
elif len(list(d.keys())) == 2:
keys = list(sorted(list(d.keys())))
if d[keys[0]] == N // 3:
print("Yes")
else:
print("No")
elif len(list(d.keys())) == 3:
keys = list(d.keys())
if keys[0] ^ keys[1] ^ keys[2] == 0:
if d[keys[0]] == d[keys[1]] == d[keys[2]]:
print("Yes")
else:
print("No")
else:
print("No")
else:
print("No")
| # coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
# A.sort()
d = {}
for i in range(N):
a = A[i]
if a not in list(d.keys()):
d[a] = 1
else:
d[a] += 1
flag = True
if len(list(d.keys())) == 1:
if list(d.keys())[0] == 0:
flag = True
else:
flag = False
elif len(list(d.keys())) == 2:
keys = list(sorted(list(d.keys())))
if d[keys[0]] == N // 3:
flag = True
else:
flag = False
elif len(list(d.keys())) == 3:
keys = list(d.keys())
if keys[0] ^ keys[1] ^ keys[2] == 0:
if d[keys[0]] == d[keys[1]] == d[keys[2]]:
flag = True
else:
flag = False
else:
flag = False
else:
flag = False
print(("Yes" if flag else "No"))
| false | 5.714286 | [
"-A.sort()",
"+# A.sort()",
"+flag = True",
"- print(\"Yes\")",
"+ flag = True",
"- print(\"No\")",
"+ flag = False",
"- print(\"Yes\")",
"+ flag = True",
"- print(\"No\")",
"+ flag = False",
"- print(\"Yes\")",
"+ flag = True",
"- print(\"No\")",
"+ flag = False",
"- print(\"No\")",
"+ flag = False",
"- print(\"No\")",
"+ flag = False",
"+print((\"Yes\" if flag else \"No\"))"
]
| false | 0.037489 | 0.038554 | 0.972372 | [
"s996159534",
"s636131884"
]
|
u620755587 | p02713 | python | s722847499 | s741360827 | 1,306 | 741 | 9,900 | 9,960 | Accepted | Accepted | 43.26 | #!/usr/bin/env python3
import sys
import pprint
from math import gcd
sys.setrecursionlimit(10 ** 6)
class Logger:
def __init__(self, debug):
self.debug = debug
def print(self, *args):
if self.debug:
pprint.pprint(args)
def main():
log = Logger(1)
k = int(sys.stdin.readline())
s = 0
for a in range(1, k+1):
for b in range(1, k+1):
for c in range(1, k+1):
s += gcd(gcd(a, b), c)
print(s)
main()
| #!/usr/bin/env pypy3
import sys
import pprint
from math import gcd
sys.setrecursionlimit(10 ** 6)
class Logger:
def __init__(self, debug):
self.debug = debug
def print(self, *args):
if self.debug:
pprint.pprint(args)
def main():
log = Logger(1)
k = int(sys.stdin.readline())
s = 0
for a in range(1, k+1):
for b in range(1, k+1):
x = gcd(a, b)
for c in range(1, k+1):
s += gcd(x, c)
print(s)
main()
| 30 | 31 | 455 | 463 | #!/usr/bin/env python3
import sys
import pprint
from math import gcd
sys.setrecursionlimit(10**6)
class Logger:
def __init__(self, debug):
self.debug = debug
def print(self, *args):
if self.debug:
pprint.pprint(args)
def main():
log = Logger(1)
k = int(sys.stdin.readline())
s = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
s += gcd(gcd(a, b), c)
print(s)
main()
| #!/usr/bin/env pypy3
import sys
import pprint
from math import gcd
sys.setrecursionlimit(10**6)
class Logger:
def __init__(self, debug):
self.debug = debug
def print(self, *args):
if self.debug:
pprint.pprint(args)
def main():
log = Logger(1)
k = int(sys.stdin.readline())
s = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
x = gcd(a, b)
for c in range(1, k + 1):
s += gcd(x, c)
print(s)
main()
| false | 3.225806 | [
"-#!/usr/bin/env python3",
"+#!/usr/bin/env pypy3",
"+ x = gcd(a, b)",
"- s += gcd(gcd(a, b), c)",
"+ s += gcd(x, c)"
]
| false | 0.119452 | 0.071181 | 1.678157 | [
"s722847499",
"s741360827"
]
|
u123756661 | p03030 | python | s403385664 | s886639476 | 192 | 167 | 38,384 | 38,256 | Accepted | Accepted | 13.02 | n=int(eval(input()))
c,m=[],[]
d={}
t={}
for i in range(n):
s,p=list(map(str,input().split()))
m.append((s,int(p)))
if s not in c:
c.append(s)
d[s]=[int(p)]
else:
d[s].append(int(p))
t[(s,int(p))]=i+1
c.sort()
ans={}
cnt=1
for i in c:
d[i].sort(reverse=True)
for j in d[i]:
ans[cnt]=(i,j)
cnt+=1
for i in range(1,n+1):
print((t[ans[i]]))
| n=int(eval(input()))
ans=[]
for i in range(n):
s,p=list(map(str,input().split()))
ans.append((s,int(p)*-1,i+1))
ans.sort()
for i in ans: print((i[2])) | 23 | 7 | 418 | 150 | n = int(eval(input()))
c, m = [], []
d = {}
t = {}
for i in range(n):
s, p = list(map(str, input().split()))
m.append((s, int(p)))
if s not in c:
c.append(s)
d[s] = [int(p)]
else:
d[s].append(int(p))
t[(s, int(p))] = i + 1
c.sort()
ans = {}
cnt = 1
for i in c:
d[i].sort(reverse=True)
for j in d[i]:
ans[cnt] = (i, j)
cnt += 1
for i in range(1, n + 1):
print((t[ans[i]]))
| n = int(eval(input()))
ans = []
for i in range(n):
s, p = list(map(str, input().split()))
ans.append((s, int(p) * -1, i + 1))
ans.sort()
for i in ans:
print((i[2]))
| false | 69.565217 | [
"-c, m = [], []",
"-d = {}",
"-t = {}",
"+ans = []",
"- m.append((s, int(p)))",
"- if s not in c:",
"- c.append(s)",
"- d[s] = [int(p)]",
"- else:",
"- d[s].append(int(p))",
"- t[(s, int(p))] = i + 1",
"-c.sort()",
"-ans = {}",
"-cnt = 1",
"-for i in c:",
"- d[i].sort(reverse=True)",
"- for j in d[i]:",
"- ans[cnt] = (i, j)",
"- cnt += 1",
"-for i in range(1, n + 1):",
"- print((t[ans[i]]))",
"+ ans.append((s, int(p) * -1, i + 1))",
"+ans.sort()",
"+for i in ans:",
"+ print((i[2]))"
]
| false | 0.08227 | 0.089141 | 0.922921 | [
"s403385664",
"s886639476"
]
|
u186838327 | p03700 | python | s167208007 | s536886875 | 573 | 461 | 51,928 | 80,816 | Accepted | Accepted | 19.55 | n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for i in range(n)]
def ok(x):
t = 0
for i in range(n):
h = H[i]
res = h-b*x
if res <= 0:
continue
else:
if res%(a-b) == 0:
t += res//(a-b)
else:
t += res//(a-b)+1
if t <= x:
return True
else:
return False
l = 0
r = 10**10
while l+1 < r:
c = (l+r)//2
if ok(c):
r = c
else:
l = c
print(r) | n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(n)]
def is_ok(x):
cnt = 0
for i in range(n):
h = H[i]
if h <= x*b:
continue
else:
h -= x*b
cnt += (h+(a-b-1))//(a-b)
if cnt <= x:
return True
else:
return False
l = 0
r = 19**18
while l+1 < r:
c = (l+r)//2
if is_ok(c):
r = c
else:
l = c
print(r)
| 29 | 26 | 530 | 463 | n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for i in range(n)]
def ok(x):
t = 0
for i in range(n):
h = H[i]
res = h - b * x
if res <= 0:
continue
else:
if res % (a - b) == 0:
t += res // (a - b)
else:
t += res // (a - b) + 1
if t <= x:
return True
else:
return False
l = 0
r = 10**10
while l + 1 < r:
c = (l + r) // 2
if ok(c):
r = c
else:
l = c
print(r)
| n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(n)]
def is_ok(x):
cnt = 0
for i in range(n):
h = H[i]
if h <= x * b:
continue
else:
h -= x * b
cnt += (h + (a - b - 1)) // (a - b)
if cnt <= x:
return True
else:
return False
l = 0
r = 19**18
while l + 1 < r:
c = (l + r) // 2
if is_ok(c):
r = c
else:
l = c
print(r)
| false | 10.344828 | [
"-H = [int(eval(input())) for i in range(n)]",
"+H = [int(eval(input())) for _ in range(n)]",
"-def ok(x):",
"- t = 0",
"+def is_ok(x):",
"+ cnt = 0",
"- res = h - b * x",
"- if res <= 0:",
"+ if h <= x * b:",
"- if res % (a - b) == 0:",
"- t += res // (a - b)",
"- else:",
"- t += res // (a - b) + 1",
"- if t <= x:",
"+ h -= x * b",
"+ cnt += (h + (a - b - 1)) // (a - b)",
"+ if cnt <= x:",
"-r = 10**10",
"+r = 19**18",
"- if ok(c):",
"+ if is_ok(c):"
]
| false | 0.044273 | 0.043898 | 1.00854 | [
"s167208007",
"s536886875"
]
|
u752907799 | p02802 | python | s133347545 | s470031440 | 1,761 | 1,504 | 12,728 | 12,852 | Accepted | Accepted | 14.59 | import numpy as np
N, M = list(map(int, input().split()))
d = np.zeros(N+1, dtype = 'int32')
t = 0
f = 0
for i in range(M):
tmp = input().split()
p = int(tmp[0])
S = tmp[1]
dp = d[p]
if S == 'AC':
if dp != -1:
f += dp
d[p] = -1
t += 1
elif dp != -1:
d[p] += 1
print((t, f))
| import numpy as np
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
d = np.zeros(N+1, dtype = 'int32')
t = 0
f = 0
for i in range(M):
tmp = input().split()
p = int(tmp[0])
S = tmp[1]
dp = d[p]
if S == 'AC':
if dp != -1:
f += dp
d[p] = -1
t += 1
elif dp != -1:
d[p] += 1
print((t, f))
| 18 | 21 | 359 | 401 | import numpy as np
N, M = list(map(int, input().split()))
d = np.zeros(N + 1, dtype="int32")
t = 0
f = 0
for i in range(M):
tmp = input().split()
p = int(tmp[0])
S = tmp[1]
dp = d[p]
if S == "AC":
if dp != -1:
f += dp
d[p] = -1
t += 1
elif dp != -1:
d[p] += 1
print((t, f))
| import numpy as np
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
d = np.zeros(N + 1, dtype="int32")
t = 0
f = 0
for i in range(M):
tmp = input().split()
p = int(tmp[0])
S = tmp[1]
dp = d[p]
if S == "AC":
if dp != -1:
f += dp
d[p] = -1
t += 1
elif dp != -1:
d[p] += 1
print((t, f))
| false | 14.285714 | [
"+import sys",
"+input = sys.stdin.readline"
]
| false | 0.242723 | 0.245298 | 0.989503 | [
"s133347545",
"s470031440"
]
|
u227082700 | p02695 | python | s357198292 | s462618178 | 984 | 550 | 9,188 | 9,032 | Accepted | Accepted | 44.11 | import itertools
n,m,q=list(map(int,input().split()))
abcd=[list(map(int,input().split()))for _ in range(q)]
ans=0
for i in itertools.combinations_with_replacement(list(range(m)),n):
anss=0
for a,b,c,d in abcd:
if i[b-1]-i[a-1]==c:anss+=d
ans=max(ans,anss)
print(ans) | import itertools
n,m,q=list(map(int,input().split()))
abcd=[list(map(int,input().split()))for _ in range(q)]
print((max(sum(d for a,b,c,d in abcd if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(list(range(m)),n)))) | 10 | 4 | 274 | 224 | import itertools
n, m, q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(list(range(m)), n):
anss = 0
for a, b, c, d in abcd:
if i[b - 1] - i[a - 1] == c:
anss += d
ans = max(ans, anss)
print(ans)
| import itertools
n, m, q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for _ in range(q)]
print(
(
max(
sum(d for a, b, c, d in abcd if i[b - 1] - i[a - 1] == c)
for i in itertools.combinations_with_replacement(list(range(m)), n)
)
)
)
| false | 60 | [
"-ans = 0",
"-for i in itertools.combinations_with_replacement(list(range(m)), n):",
"- anss = 0",
"- for a, b, c, d in abcd:",
"- if i[b - 1] - i[a - 1] == c:",
"- anss += d",
"- ans = max(ans, anss)",
"-print(ans)",
"+print(",
"+ (",
"+ max(",
"+ sum(d for a, b, c, d in abcd if i[b - 1] - i[a - 1] == c)",
"+ for i in itertools.combinations_with_replacement(list(range(m)), n)",
"+ )",
"+ )",
"+)"
]
| false | 0.054986 | 0.089696 | 0.613026 | [
"s357198292",
"s462618178"
]
|
u500376440 | p02675 | python | s089400845 | s932931190 | 30 | 26 | 9,100 | 9,112 | Accepted | Accepted | 13.33 | N=int(eval(input()))
hon=[2,4,5,7,9]
pon=[0,1,6,8]
n=N%10
if n in hon:
print("hon")
elif n in pon:
print("pon")
else:
print("bon")
| N=eval(input())
if int(N[-1]) in (2,4,5,7,9):
print("hon")
elif int(N[-1]) in (0,1,6,8):
print("pon")
else:
print("bon")
| 10 | 7 | 140 | 127 | N = int(eval(input()))
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
n = N % 10
if n in hon:
print("hon")
elif n in pon:
print("pon")
else:
print("bon")
| N = eval(input())
if int(N[-1]) in (2, 4, 5, 7, 9):
print("hon")
elif int(N[-1]) in (0, 1, 6, 8):
print("pon")
else:
print("bon")
| false | 30 | [
"-N = int(eval(input()))",
"-hon = [2, 4, 5, 7, 9]",
"-pon = [0, 1, 6, 8]",
"-n = N % 10",
"-if n in hon:",
"+N = eval(input())",
"+if int(N[-1]) in (2, 4, 5, 7, 9):",
"-elif n in pon:",
"+elif int(N[-1]) in (0, 1, 6, 8):"
]
| false | 0.136025 | 0.095529 | 1.423911 | [
"s089400845",
"s932931190"
]
|
u120691615 | p03835 | python | s585163413 | s506308799 | 1,373 | 1,240 | 2,940 | 2,940 | Accepted | Accepted | 9.69 | K,S = list(map(int,input().split()))
cnt = 0
for i in range(K+1):
for j in range(K+1):
if 0 <= S - (i + j) <= K:
cnt += 1
print(cnt) | K,S = list(map(int,input().split()))
cnt = 0
for i in range(K+1):
for j in range(K+1):
if 0<= S-i-j <= K:
cnt += 1
print(cnt) | 7 | 8 | 156 | 151 | K, S = list(map(int, input().split()))
cnt = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - (i + j) <= K:
cnt += 1
print(cnt)
| K, S = list(map(int, input().split()))
cnt = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - i - j <= K:
cnt += 1
print(cnt)
| false | 12.5 | [
"- if 0 <= S - (i + j) <= K:",
"+ if 0 <= S - i - j <= K:"
]
| false | 0.035531 | 0.042915 | 0.82794 | [
"s585163413",
"s506308799"
]
|
u562935282 | p03252 | python | s581308905 | s963566005 | 130 | 84 | 3,632 | 3,632 | Accepted | Accepted | 35.38 | s = eval(input())
t = eval(input())
s2t = dict()
t2s = dict()
flg = True
for i, (ss, tt) in enumerate(zip(s, t)):
a = s2t.get(ss, None)
if a is None:
s2t[ss] = tt
else:
if a != tt:
flg = False
break
b = t2s.get(tt, None)
if b is None:
t2s[tt] = ss
else:
if b != ss:
flg = False
break
print(('Yes' if flg else 'No'))
| def solve():
s = eval(input())
t = eval(input())
d = dict()
for sc, tc in zip(s, t):
if d.get(sc, None) is None:
d[sc] = tc
else:
if d[sc] != tc:
return False
d = {value: key for key, value in list(d.items())}
for sc, tc in zip(s, t):
if d.get(tc, None) is None:
d[tc] = sc
else:
if d[tc] != sc:
return False
return True
if __name__ == '__main__':
print(('Yes' if solve() else 'No'))
| 24 | 23 | 432 | 533 | s = eval(input())
t = eval(input())
s2t = dict()
t2s = dict()
flg = True
for i, (ss, tt) in enumerate(zip(s, t)):
a = s2t.get(ss, None)
if a is None:
s2t[ss] = tt
else:
if a != tt:
flg = False
break
b = t2s.get(tt, None)
if b is None:
t2s[tt] = ss
else:
if b != ss:
flg = False
break
print(("Yes" if flg else "No"))
| def solve():
s = eval(input())
t = eval(input())
d = dict()
for sc, tc in zip(s, t):
if d.get(sc, None) is None:
d[sc] = tc
else:
if d[sc] != tc:
return False
d = {value: key for key, value in list(d.items())}
for sc, tc in zip(s, t):
if d.get(tc, None) is None:
d[tc] = sc
else:
if d[tc] != sc:
return False
return True
if __name__ == "__main__":
print(("Yes" if solve() else "No"))
| false | 4.166667 | [
"-s = eval(input())",
"-t = eval(input())",
"-s2t = dict()",
"-t2s = dict()",
"-flg = True",
"-for i, (ss, tt) in enumerate(zip(s, t)):",
"- a = s2t.get(ss, None)",
"- if a is None:",
"- s2t[ss] = tt",
"- else:",
"- if a != tt:",
"- flg = False",
"- break",
"- b = t2s.get(tt, None)",
"- if b is None:",
"- t2s[tt] = ss",
"- else:",
"- if b != ss:",
"- flg = False",
"- break",
"-print((\"Yes\" if flg else \"No\"))",
"+def solve():",
"+ s = eval(input())",
"+ t = eval(input())",
"+ d = dict()",
"+ for sc, tc in zip(s, t):",
"+ if d.get(sc, None) is None:",
"+ d[sc] = tc",
"+ else:",
"+ if d[sc] != tc:",
"+ return False",
"+ d = {value: key for key, value in list(d.items())}",
"+ for sc, tc in zip(s, t):",
"+ if d.get(tc, None) is None:",
"+ d[tc] = sc",
"+ else:",
"+ if d[tc] != sc:",
"+ return False",
"+ return True",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ print((\"Yes\" if solve() else \"No\"))"
]
| false | 0.038257 | 0.043122 | 0.887179 | [
"s581308905",
"s963566005"
]
|
u906501980 | p02901 | python | s536648395 | s399317370 | 767 | 543 | 3,188 | 3,188 | Accepted | Accepted | 29.2 | def main():
n, m = list(map(int, input().split()))
p = 2**n
inf = 10**7
dp = [inf]*p
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2**(int(i)-1) for i in input().split()])
for s in range(p):
t = s|c
new = dp[s] + a
if dp[t] > new:
dp[t] = new
ans = dp[-1]
if ans == inf:
ans = -1
print(ans)
if __name__ == '__main__':
main() | def main():
n, m = list(map(int, input().split()))
p = 2**n
inf = 10**7
dp = [inf]*p
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([1<<(int(i)-1) for i in input().split()])
for s in range(p):
if dp[s|c] > dp[s] + a:
dp[s|c] = dp[s] + a
ans = dp[-1]
if ans == inf:
ans = -1
print(ans)
if __name__ == '__main__':
main() | 21 | 19 | 504 | 462 | def main():
n, m = list(map(int, input().split()))
p = 2**n
inf = 10**7
dp = [inf] * p
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2 ** (int(i) - 1) for i in input().split()])
for s in range(p):
t = s | c
new = dp[s] + a
if dp[t] > new:
dp[t] = new
ans = dp[-1]
if ans == inf:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| def main():
n, m = list(map(int, input().split()))
p = 2**n
inf = 10**7
dp = [inf] * p
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([1 << (int(i) - 1) for i in input().split()])
for s in range(p):
if dp[s | c] > dp[s] + a:
dp[s | c] = dp[s] + a
ans = dp[-1]
if ans == inf:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| false | 9.52381 | [
"- c = sum([2 ** (int(i) - 1) for i in input().split()])",
"+ c = sum([1 << (int(i) - 1) for i in input().split()])",
"- t = s | c",
"- new = dp[s] + a",
"- if dp[t] > new:",
"- dp[t] = new",
"+ if dp[s | c] > dp[s] + a:",
"+ dp[s | c] = dp[s] + a"
]
| false | 0.038194 | 0.036911 | 1.034772 | [
"s536648395",
"s399317370"
]
|
u347640436 | p02862 | python | s894677966 | s671809416 | 164 | 132 | 35,188 | 9,176 | Accepted | Accepted | 19.51 | # フェルマーの小定理
X, Y = list(map(int, input().split()))
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
def mcomb(n, k):
if n == 0 and k == 0:
return 1
if n < k or k < 0:
return 0
return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m
if (X + Y) % 3 != 0:
print((0))
exit()
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
print((0))
exit()
n = a + b
fac = make_factorial_table(n)
print((mcomb(n, a)))
| # フェルマーの小定理
X, Y = list(map(int, input().split()))
m = 1000000007
def mcomb(n, k):
a = 1
b = 1
for i in range(k):
a *= n - i
a %= m
b *= i + 1
b %= m
return a * pow(b, m - 2, m) % m
if (X + Y) % 3 != 0:
print((0))
exit()
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
print((0))
exit()
n = a + b
print((mcomb(n, a)))
| 36 | 26 | 632 | 412 | # フェルマーの小定理
X, Y = list(map(int, input().split()))
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
def mcomb(n, k):
if n == 0 and k == 0:
return 1
if n < k or k < 0:
return 0
return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m
if (X + Y) % 3 != 0:
print((0))
exit()
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
print((0))
exit()
n = a + b
fac = make_factorial_table(n)
print((mcomb(n, a)))
| # フェルマーの小定理
X, Y = list(map(int, input().split()))
m = 1000000007
def mcomb(n, k):
a = 1
b = 1
for i in range(k):
a *= n - i
a %= m
b *= i + 1
b %= m
return a * pow(b, m - 2, m) % m
if (X + Y) % 3 != 0:
print((0))
exit()
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
print((0))
exit()
n = a + b
print((mcomb(n, a)))
| false | 27.777778 | [
"-def make_factorial_table(n):",
"- result = [0] * (n + 1)",
"- result[0] = 1",
"- for i in range(1, n + 1):",
"- result[i] = result[i - 1] * i % m",
"- return result",
"-",
"-",
"- if n == 0 and k == 0:",
"- return 1",
"- if n < k or k < 0:",
"- return 0",
"- return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m",
"+ a = 1",
"+ b = 1",
"+ for i in range(k):",
"+ a *= n - i",
"+ a %= m",
"+ b *= i + 1",
"+ b %= m",
"+ return a * pow(b, m - 2, m) % m",
"-fac = make_factorial_table(n)"
]
| false | 0.065479 | 0.157702 | 0.415207 | [
"s894677966",
"s671809416"
]
|
u788703383 | p03818 | python | s986384690 | s334351631 | 63 | 53 | 18,656 | 18,656 | Accepted | Accepted | 15.87 | import collections
n = int(eval(input()))
c = collections.Counter(list(map(int,input().split())))
z = list(c.values())
ans = 0
for c in z:
ans +=(1-c%2)
print((len(z)-ans%2))
| import collections
n = int(eval(input()))
c = len(collections.Counter(list(map(int,input().split()))))
print((c-(1-c%2)))
| 11 | 4 | 184 | 117 | import collections
n = int(eval(input()))
c = collections.Counter(list(map(int, input().split())))
z = list(c.values())
ans = 0
for c in z:
ans += 1 - c % 2
print((len(z) - ans % 2))
| import collections
n = int(eval(input()))
c = len(collections.Counter(list(map(int, input().split()))))
print((c - (1 - c % 2)))
| false | 63.636364 | [
"-c = collections.Counter(list(map(int, input().split())))",
"-z = list(c.values())",
"-ans = 0",
"-for c in z:",
"- ans += 1 - c % 2",
"-print((len(z) - ans % 2))",
"+c = len(collections.Counter(list(map(int, input().split()))))",
"+print((c - (1 - c % 2)))"
]
| false | 0.038208 | 0.039152 | 0.975876 | [
"s986384690",
"s334351631"
]
|
u977661421 | p03457 | python | s550720441 | s128435232 | 445 | 410 | 21,156 | 21,108 | Accepted | Accepted | 7.87 | # -*- coding: utf-8 -*-
n = int(eval(input()))
txy = []
for i in range(n):
txy.append([int(i) for i in input().split()])
ans = "Yes"
tmp_x = 0
tmp_y = 0
tmp_t = 0
for i in range(n):
#print((abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])))
if (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) % 2 != (txy[i][0] - tmp_t) % 2 or (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) > txy[i][0] - tmp_t:
ans = "No"
tmp_x = txy[i][1]
tmp_y = txy[i][2]
tmp_t = txy[i][0]
print(ans)
| # -*- coding: utf-8 -*-
n = int(eval(input()))
txy = []
for i in range(n):
txy.append([int(i) for i in input().split()])
ans = "Yes"
bx = 0
by = 0
bt = 0
for i in range(n):
tmp = ((txy[i][1] - bx) + (txy[i][2] - by))
if tmp % 2 != (txy[i][0] - bt) % 2 or tmp > (txy[i][0] - bt):
ans = "No"
bx = txy[i][1]
by = txy[i][2]
bt = txy[i][0]
print(ans)
| 18 | 18 | 518 | 390 | # -*- coding: utf-8 -*-
n = int(eval(input()))
txy = []
for i in range(n):
txy.append([int(i) for i in input().split()])
ans = "Yes"
tmp_x = 0
tmp_y = 0
tmp_t = 0
for i in range(n):
# print((abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])))
if (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) % 2 != (
txy[i][0] - tmp_t
) % 2 or (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) > txy[i][0] - tmp_t:
ans = "No"
tmp_x = txy[i][1]
tmp_y = txy[i][2]
tmp_t = txy[i][0]
print(ans)
| # -*- coding: utf-8 -*-
n = int(eval(input()))
txy = []
for i in range(n):
txy.append([int(i) for i in input().split()])
ans = "Yes"
bx = 0
by = 0
bt = 0
for i in range(n):
tmp = (txy[i][1] - bx) + (txy[i][2] - by)
if tmp % 2 != (txy[i][0] - bt) % 2 or tmp > (txy[i][0] - bt):
ans = "No"
bx = txy[i][1]
by = txy[i][2]
bt = txy[i][0]
print(ans)
| false | 0 | [
"-tmp_x = 0",
"-tmp_y = 0",
"-tmp_t = 0",
"+bx = 0",
"+by = 0",
"+bt = 0",
"- # print((abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])))",
"- if (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) % 2 != (",
"- txy[i][0] - tmp_t",
"- ) % 2 or (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) > txy[i][0] - tmp_t:",
"+ tmp = (txy[i][1] - bx) + (txy[i][2] - by)",
"+ if tmp % 2 != (txy[i][0] - bt) % 2 or tmp > (txy[i][0] - bt):",
"- tmp_x = txy[i][1]",
"- tmp_y = txy[i][2]",
"- tmp_t = txy[i][0]",
"+ bx = txy[i][1]",
"+ by = txy[i][2]",
"+ bt = txy[i][0]"
]
| false | 0.042078 | 0.044862 | 0.937942 | [
"s550720441",
"s128435232"
]
|
u222668979 | p02706 | python | s963096407 | s526894957 | 24 | 22 | 9,880 | 9,896 | Accepted | Accepted | 8.33 | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
if n < sum(a):
print((-1))
else:
print((n-sum(a)))
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
print((-1 if n < sum(a) else n - sum(a))) | 10 | 4 | 173 | 112 | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
if n < sum(a):
print((-1))
else:
print((n - sum(a)))
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
print((-1 if n < sum(a) else n - sum(a)))
| false | 60 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-if n < sum(a):",
"- print((-1))",
"-else:",
"- print((n - sum(a)))",
"+print((-1 if n < sum(a) else n - sum(a)))"
]
| false | 0.040486 | 0.043001 | 0.941516 | [
"s963096407",
"s526894957"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.