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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u968166680 | p03030 | python | s922774134 | s452260626 | 25 | 18 | 3,564 | 3,064 | Accepted | Accepted | 28 | import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N = int(readline())
d = defaultdict(list)
for i in range(N):
s, p = readline().strip().split()
p = int(p)
d[s].append((p, i+1))
for city, points in sorted(d.items()):
points = sorted(points, reverse=True)
for _, i in points:
print(i)
return
if __name__ == '__main__':
main()
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N = int(readline())
A = [0] * N
for i in range(N):
s, p = readline().strip().split()
p = int(p)
A[i] = (s, p, i + 1)
A.sort(key=itemgetter(1), reverse=True)
A.sort(key=itemgetter(0))
for s, p, i in A:
print(i)
return
if __name__ == '__main__':
main()
| 28 | 28 | 573 | 533 | import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
N = int(readline())
d = defaultdict(list)
for i in range(N):
s, p = readline().strip().split()
p = int(p)
d[s].append((p, i + 1))
for city, points in sorted(d.items()):
points = sorted(points, reverse=True)
for _, i in points:
print(i)
return
if __name__ == "__main__":
main()
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
N = int(readline())
A = [0] * N
for i in range(N):
s, p = readline().strip().split()
p = int(p)
A[i] = (s, p, i + 1)
A.sort(key=itemgetter(1), reverse=True)
A.sort(key=itemgetter(0))
for s, p, i in A:
print(i)
return
if __name__ == "__main__":
main()
| false | 0 | [
"-from collections import defaultdict",
"+from operator import itemgetter",
"- d = defaultdict(list)",
"+ A = [0] * N",
"- d[s].append((p, i + 1))",
"- for city, points in sorted(d.items()):",
"- points = sorted(points, reverse=True)",
"- for _, i in points:",
"- ... | false | 0.065272 | 0.034918 | 1.869302 | [
"s922774134",
"s452260626"
] |
u094191970 | p02780 | python | s964170611 | s015703899 | 238 | 199 | 25,060 | 26,364 | Accepted | Accepted | 16.39 | n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
x=[]
for i in p:
x.append((i+1)/2)
b=[0]
for i in range(1,n+1):
b.append(b[i-1]+x[i-1])
ans=0
for i in range(n-k+1):
ans=max(ans,b[i+k]-b[i])
print(ans) | from itertools import accumulate
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
x=[]
for i in p:
x.append((i+1)/2)
b=[0]+list(accumulate(x))
'''
bb=[0]
for i in range(1,n+1):
bb.append(bb[i-1]+x[i-1])
print(b)
print(bb)
'''
ans=0
for i in range(n-k+1):
ans=max(ans,b[i+k]-b[i])
print(ans) | 16 | 25 | 236 | 337 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
x = []
for i in p:
x.append((i + 1) / 2)
b = [0]
for i in range(1, n + 1):
b.append(b[i - 1] + x[i - 1])
ans = 0
for i in range(n - k + 1):
ans = max(ans, b[i + k] - b[i])
print(ans)
| from itertools import accumulate
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
x = []
for i in p:
x.append((i + 1) / 2)
b = [0] + list(accumulate(x))
"""
bb=[0]
for i in range(1,n+1):
bb.append(bb[i-1]+x[i-1])
print(b)
print(bb)
"""
ans = 0
for i in range(n - k + 1):
ans = max(ans, b[i + k] - b[i])
print(ans)
| false | 36 | [
"+from itertools import accumulate",
"+",
"-b = [0]",
"-for i in range(1, n + 1):",
"- b.append(b[i - 1] + x[i - 1])",
"+b = [0] + list(accumulate(x))",
"+\"\"\"",
"+bb=[0]",
"+for i in range(1,n+1):",
"+ bb.append(bb[i-1]+x[i-1])",
"+print(b)",
"+print(bb)",
"+\"\"\""
] | false | 0.083057 | 0.044729 | 1.856864 | [
"s964170611",
"s015703899"
] |
u562935282 | p03569 | python | s047042957 | s934430518 | 46 | 39 | 3,316 | 3,316 | Accepted | Accepted | 15.22 | def solve():
s = eval(input())
n = len(s)
left = 0
right = n - 1
ret = 0
while left < right:
if s[left] == s[right]:
left += 1
right -= 1
elif s[left] == 'x':
ret += 1
left += 1
elif s[right] == 'x':
ret += 1
right -= 1
else:
return -1
return ret
print((solve()))
| def main():
s = eval(input())
l = 0
r = len(s) - 1
ret = 0
while l < r:
lc, rc = s[l], s[r]
if lc == rc:
l += 1
r -= 1
continue
if lc == 'x':
ret += 1
l += 1
continue
if rc == 'x':
ret += 1
r -= 1
continue
print((-1))
return
print(ret)
if __name__ == '__main__':
main()
| 24 | 33 | 427 | 487 | def solve():
s = eval(input())
n = len(s)
left = 0
right = n - 1
ret = 0
while left < right:
if s[left] == s[right]:
left += 1
right -= 1
elif s[left] == "x":
ret += 1
left += 1
elif s[right] == "x":
ret += 1
right -= 1
else:
return -1
return ret
print((solve()))
| def main():
s = eval(input())
l = 0
r = len(s) - 1
ret = 0
while l < r:
lc, rc = s[l], s[r]
if lc == rc:
l += 1
r -= 1
continue
if lc == "x":
ret += 1
l += 1
continue
if rc == "x":
ret += 1
r -= 1
continue
print((-1))
return
print(ret)
if __name__ == "__main__":
main()
| false | 27.272727 | [
"-def solve():",
"+def main():",
"- n = len(s)",
"- left = 0",
"- right = n - 1",
"+ l = 0",
"+ r = len(s) - 1",
"- while left < right:",
"- if s[left] == s[right]:",
"- left += 1",
"- right -= 1",
"- elif s[left] == \"x\":",
"+ while ... | false | 0.034102 | 0.039592 | 0.861323 | [
"s047042957",
"s934430518"
] |
u863370423 | p02771 | python | s960604990 | s623180330 | 180 | 17 | 38,256 | 3,060 | Accepted | Accepted | 90.56 | def main():
a, b, c = list(map(int, input().split()))
if (a == b and c != a) or (a == c and b != c) or (b == c and a != b):
print("Yes")
else:
print("No")
if __name__ == '__main__':
main() | n = list(map(int,input().split()))
n.sort()
a,b,c = n
flag = False
if a == b and c != a:
flag = True
elif a == c and b != c:
flag = True
elif b == c and a != b:
flag = True
print(("Yes" if flag else "No")) | 9 | 11 | 223 | 226 | def main():
a, b, c = list(map(int, input().split()))
if (a == b and c != a) or (a == c and b != c) or (b == c and a != b):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| n = list(map(int, input().split()))
n.sort()
a, b, c = n
flag = False
if a == b and c != a:
flag = True
elif a == c and b != c:
flag = True
elif b == c and a != b:
flag = True
print(("Yes" if flag else "No"))
| false | 18.181818 | [
"-def main():",
"- a, b, c = list(map(int, input().split()))",
"- if (a == b and c != a) or (a == c and b != c) or (b == c and a != b):",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n = list(map(int, input()... | false | 0.089466 | 0.083866 | 1.06677 | [
"s960604990",
"s623180330"
] |
u047796752 | p02708 | python | s899743085 | s291286032 | 66 | 56 | 68,064 | 65,000 | Accepted | Accepted | 15.15 | import sys
input = sys.stdin.readline
from collections import *
from math import *
N, K = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
for i in range(K, N+2):
c = ((2*N-i+1)*i)//2-i*(i-1)//2+1
ans += c
ans %= MOD
print(ans) | def f(s, e):
return (e-s+1)*(s+e)//2
N, K = list(map(int, input().split()))
ans = 0
MOD = 10**9+7
for i in range(K, N+2):
ans += f(N-i+1, N)-f(0, i-1)+1
ans %= MOD
print(ans) | 15 | 12 | 255 | 194 | import sys
input = sys.stdin.readline
from collections import *
from math import *
N, K = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0
for i in range(K, N + 2):
c = ((2 * N - i + 1) * i) // 2 - i * (i - 1) // 2 + 1
ans += c
ans %= MOD
print(ans)
| def f(s, e):
return (e - s + 1) * (s + e) // 2
N, K = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(K, N + 2):
ans += f(N - i + 1, N) - f(0, i - 1) + 1
ans %= MOD
print(ans)
| false | 20 | [
"-import sys",
"+def f(s, e):",
"+ return (e - s + 1) * (s + e) // 2",
"-input = sys.stdin.readline",
"-from collections import *",
"-from math import *",
"+ans = 0",
"-ans = 0",
"- c = ((2 * N - i + 1) * i) // 2 - i * (i - 1) // 2 + 1",
"- ans += c",
"+ ans += f(N - i + 1, N) - f(0,... | false | 0.137289 | 0.221426 | 0.620022 | [
"s899743085",
"s291286032"
] |
u009961299 | p02390 | python | s101298635 | s115676818 | 30 | 20 | 6,724 | 5,588 | Accepted | Accepted | 33.33 | a = int ( eval(input ( )) )
h = a // 3600
m = ( a // 60 ) % 60
d = a % 60
print(( "%s:%s:%s" % ( h, m, d ) )) | S = int(eval(input()))
h = S // 3600
m = (S // 60) % 60
s = S % 60
print(("%d:%d:%d" % (h, m, s)))
| 6 | 7 | 108 | 99 | a = int(eval(input()))
h = a // 3600
m = (a // 60) % 60
d = a % 60
print(("%s:%s:%s" % (h, m, d)))
| S = int(eval(input()))
h = S // 3600
m = (S // 60) % 60
s = S % 60
print(("%d:%d:%d" % (h, m, s)))
| false | 14.285714 | [
"-a = int(eval(input()))",
"-h = a // 3600",
"-m = (a // 60) % 60",
"-d = a % 60",
"-print((\"%s:%s:%s\" % (h, m, d)))",
"+S = int(eval(input()))",
"+h = S // 3600",
"+m = (S // 60) % 60",
"+s = S % 60",
"+print((\"%d:%d:%d\" % (h, m, s)))"
] | false | 0.049298 | 0.048774 | 1.010726 | [
"s101298635",
"s115676818"
] |
u627600101 | p02901 | python | s834532020 | s105721531 | 144 | 121 | 77,048 | 76,552 | Accepted | Accepted | 15.97 | N, M = list(map(int, input().split()))
newcount = [float('inf') for _ in range(2**N)]
newcount[0] = 0
for k in range(M):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
bit = 0
for k in range(b):
bit += 2**(c[k]-1)
count = tuple(newcount)
for k in range(2**N):
now = bit|k
newcount[now] = min(newcount[now], a+count[k])
count = newcount
if count[-1] < 10**6:
print((count[-1]))
else:
print((-1))
| N, M = list(map(int, input().split()))
newcount = [100000000 for _ in range(2**N)]
newcount[0] = 0
bi = [1,2,4,8,16,32,64,128,256,512,1024,2048]
for k in range(M):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
bit = 0
for k in range(b):
bit += bi[c[k]-1]
count = tuple(newcount)
for k in range(2**N):
now = bit|k
newcount[now] = min(newcount[now], a+count[k])
if newcount[-1] < 10**7:
print((newcount[-1]))
else:
print((-1)) | 20 | 18 | 456 | 482 | N, M = list(map(int, input().split()))
newcount = [float("inf") for _ in range(2**N)]
newcount[0] = 0
for k in range(M):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
bit = 0
for k in range(b):
bit += 2 ** (c[k] - 1)
count = tuple(newcount)
for k in range(2**N):
now = bit | k
newcount[now] = min(newcount[now], a + count[k])
count = newcount
if count[-1] < 10**6:
print((count[-1]))
else:
print((-1))
| N, M = list(map(int, input().split()))
newcount = [100000000 for _ in range(2**N)]
newcount[0] = 0
bi = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
for k in range(M):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
bit = 0
for k in range(b):
bit += bi[c[k] - 1]
count = tuple(newcount)
for k in range(2**N):
now = bit | k
newcount[now] = min(newcount[now], a + count[k])
if newcount[-1] < 10**7:
print((newcount[-1]))
else:
print((-1))
| false | 10 | [
"-newcount = [float(\"inf\") for _ in range(2**N)]",
"+newcount = [100000000 for _ in range(2**N)]",
"+bi = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]",
"- bit += 2 ** (c[k] - 1)",
"+ bit += bi[c[k] - 1]",
"-count = newcount",
"-if count[-1] < 10**6:",
"- print((count[-1]))",... | false | 0.037392 | 0.035435 | 1.055224 | [
"s834532020",
"s105721531"
] |
u860002137 | p03425 | python | s369644103 | s148346659 | 178 | 162 | 3,316 | 22,992 | Accepted | Accepted | 8.99 | from itertools import combinations
from collections import defaultdict
n = int(eval(input()))
d = defaultdict(int)
for _ in range(n):
tmp = eval(input())
if tmp[0] in ["M", "A", "R", "C", "H"]:
d[tmp[0]] += 1
li = list(combinations(list(d.keys()), 3))
ans = 0
for a, b, c in li:
ans += d[a] * d[b] * d[c]
print(ans) | from itertools import combinations
n = int(eval(input()))
arr = [eval(input()) for _ in range(n)]
li = ["M", "A", "R", "C", "H"]
result = []
for s in li:
result.append(len(set([x for x in arr if x[0] == s])))
ans = 0
for x, y, z in combinations(result, 3):
ans += x * y * z
print(ans) | 18 | 16 | 339 | 300 | from itertools import combinations
from collections import defaultdict
n = int(eval(input()))
d = defaultdict(int)
for _ in range(n):
tmp = eval(input())
if tmp[0] in ["M", "A", "R", "C", "H"]:
d[tmp[0]] += 1
li = list(combinations(list(d.keys()), 3))
ans = 0
for a, b, c in li:
ans += d[a] * d[b] * d[c]
print(ans)
| from itertools import combinations
n = int(eval(input()))
arr = [eval(input()) for _ in range(n)]
li = ["M", "A", "R", "C", "H"]
result = []
for s in li:
result.append(len(set([x for x in arr if x[0] == s])))
ans = 0
for x, y, z in combinations(result, 3):
ans += x * y * z
print(ans)
| false | 11.111111 | [
"-from collections import defaultdict",
"-d = defaultdict(int)",
"-for _ in range(n):",
"- tmp = eval(input())",
"- if tmp[0] in [\"M\", \"A\", \"R\", \"C\", \"H\"]:",
"- d[tmp[0]] += 1",
"-li = list(combinations(list(d.keys()), 3))",
"+arr = [eval(input()) for _ in range(n)]",
"+li = [... | false | 0.044631 | 0.046889 | 0.95185 | [
"s369644103",
"s148346659"
] |
u111365362 | p02862 | python | s650235809 | s606349123 | 1,541 | 407 | 3,064 | 40,812 | Accepted | Accepted | 73.59 | x,y = list(map(int,input().split()))
if (x+y) % 3 != 0:
print((0))
elif x < 0 or y < 0:
print((0))
elif x/y > 2 or y/x > 2:
print((0))
else:
n = (x+y) // 3
m = x - n
mod = 10**9 + 7
def inv(x):
y = 1
while x != 1:
y *= mod//x + 1
y %= mod
x -= mod%x
return y
#print(inv(5))
ans = 1
for i in range(m):
ans *= (n-i)
ans %= mod
ans *= inv(m-i)
ans %= mod
#print(n,m)
print(ans) | #17:23
x,y = list(map(int,input().split()))
if (x+y) % 3 != 0:
print((0))
elif x*2 < y or y*2 < x:
print((0))
else:
a = (x + y) // 3
b = y - a
mod = 10 ** 9 + 7
def inv(x):
y = 1
while x != 1:
y *= mod // x + 1
y %= mod
x -= mod % x
return y
ans = 1
for i in range(b):
ans *= a - i
ans %= mod
ans *= inv(b-i)
ans %= mod
print(ans) | 27 | 24 | 458 | 407 | x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
print((0))
elif x < 0 or y < 0:
print((0))
elif x / y > 2 or y / x > 2:
print((0))
else:
n = (x + y) // 3
m = x - n
mod = 10**9 + 7
def inv(x):
y = 1
while x != 1:
y *= mod // x + 1
y %= mod
x -= mod % x
return y
# print(inv(5))
ans = 1
for i in range(m):
ans *= n - i
ans %= mod
ans *= inv(m - i)
ans %= mod
# print(n,m)
print(ans)
| # 17:23
x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
print((0))
elif x * 2 < y or y * 2 < x:
print((0))
else:
a = (x + y) // 3
b = y - a
mod = 10**9 + 7
def inv(x):
y = 1
while x != 1:
y *= mod // x + 1
y %= mod
x -= mod % x
return y
ans = 1
for i in range(b):
ans *= a - i
ans %= mod
ans *= inv(b - i)
ans %= mod
print(ans)
| false | 11.111111 | [
"+# 17:23",
"-elif x < 0 or y < 0:",
"- print((0))",
"-elif x / y > 2 or y / x > 2:",
"+elif x * 2 < y or y * 2 < x:",
"- n = (x + y) // 3",
"- m = x - n",
"+ a = (x + y) // 3",
"+ b = y - a",
"- # print(inv(5))",
"- for i in range(m):",
"- ans *= n - i",
"+ fo... | false | 0.967094 | 1.142115 | 0.846757 | [
"s650235809",
"s606349123"
] |
u493491792 | p02935 | python | s119085559 | s752350518 | 313 | 18 | 24,048 | 3,060 | Accepted | Accepted | 94.25 | import numpy as np
n=int(eval(input()))
lista=list(map(int,input().split()))
lista.sort()
for i in range(n-1):
lista.append((lista[0]+lista[1])/2)
lista.pop(0)
lista.pop(0)
lista.sort()
print((lista[0])) | n=int(eval(input()))
lista=list(map(int,input().split()))
lista.sort()
for i in range(n-1):
lista.append((lista[0]+lista[1])/2)
lista.pop(0)
lista.pop(0)
lista.sort()
print((lista[0])) | 12 | 11 | 228 | 209 | import numpy as np
n = int(eval(input()))
lista = list(map(int, input().split()))
lista.sort()
for i in range(n - 1):
lista.append((lista[0] + lista[1]) / 2)
lista.pop(0)
lista.pop(0)
lista.sort()
print((lista[0]))
| n = int(eval(input()))
lista = list(map(int, input().split()))
lista.sort()
for i in range(n - 1):
lista.append((lista[0] + lista[1]) / 2)
lista.pop(0)
lista.pop(0)
lista.sort()
print((lista[0]))
| false | 8.333333 | [
"-import numpy as np",
"-"
] | false | 0.073526 | 0.035768 | 2.055645 | [
"s119085559",
"s752350518"
] |
u241159583 | p02784 | python | s664432204 | s023852140 | 89 | 43 | 13,964 | 13,836 | Accepted | Accepted | 51.69 | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(N):
H -= A[i]
print(("Yes" if H <= 0 else "No")) | H, N = list(map(int, input().split()))
A = [int(x) for x in input().split()]
print(("Yes" if H <= sum(A) else "No")) | 6 | 4 | 158 | 112 | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(N):
H -= A[i]
print(("Yes" if H <= 0 else "No"))
| H, N = list(map(int, input().split()))
A = [int(x) for x in input().split()]
print(("Yes" if H <= sum(A) else "No"))
| false | 33.333333 | [
"-A = list(map(int, input().split()))",
"-A.sort(reverse=True)",
"-for i in range(N):",
"- H -= A[i]",
"-print((\"Yes\" if H <= 0 else \"No\"))",
"+A = [int(x) for x in input().split()]",
"+print((\"Yes\" if H <= sum(A) else \"No\"))"
] | false | 0.040208 | 0.039172 | 1.026457 | [
"s664432204",
"s023852140"
] |
u830054172 | p03353 | python | s708693232 | s153953253 | 52 | 29 | 5,084 | 4,444 | Accepted | Accepted | 44.23 | s = eval(input())
l = int(eval(input()))
char = []
if len(s) == 1:
print(s)
else:
for i in range(len(s)):
char.append(s[i])
charset = set(char)
ans = []
for i in charset:
for j in range(len(s)):
if i == s[j]:
for k in range(1, 6):
ans.append(s[j:j+k])
ansset = sorted(list(set(ans)))
print((ansset[l-1])) | s = eval(input())
l = int(eval(input()))
char = []
if len(s) == 1:
print(s)
else:
for i in range(len(s)):
char.append(s[i])
charset = sorted(list(set(char)))
ans = []
for i in charset:
if len(set(ans)) > 5:
break
for j in range(len(s)):
if i == s[j]:
for k in range(1, 6):
ans.append(s[j:j+k])
ansset = sorted(list(set(ans)))
print((ansset[l-1])) | 17 | 19 | 398 | 462 | s = eval(input())
l = int(eval(input()))
char = []
if len(s) == 1:
print(s)
else:
for i in range(len(s)):
char.append(s[i])
charset = set(char)
ans = []
for i in charset:
for j in range(len(s)):
if i == s[j]:
for k in range(1, 6):
ans.append(s[j : j + k])
ansset = sorted(list(set(ans)))
print((ansset[l - 1]))
| s = eval(input())
l = int(eval(input()))
char = []
if len(s) == 1:
print(s)
else:
for i in range(len(s)):
char.append(s[i])
charset = sorted(list(set(char)))
ans = []
for i in charset:
if len(set(ans)) > 5:
break
for j in range(len(s)):
if i == s[j]:
for k in range(1, 6):
ans.append(s[j : j + k])
ansset = sorted(list(set(ans)))
print((ansset[l - 1]))
| false | 10.526316 | [
"- charset = set(char)",
"+ charset = sorted(list(set(char)))",
"+ if len(set(ans)) > 5:",
"+ break"
] | false | 0.121185 | 0.082486 | 1.469152 | [
"s708693232",
"s153953253"
] |
u962423738 | p03387 | python | s377351279 | s395998590 | 31 | 26 | 9,248 | 9,200 | Accepted | Accepted | 16.13 | a=list(map(int,input().split()))
a=sorted(a)
cnt=0
if a[0]==a[1] and a[1]==a[2]:
print((0))
elif a[0]==a[1]:
while True:
a[0]+=1
a[1]+=1
cnt+=1
if a[0]==a[2]:
print(cnt)
break
elif a[1]==a[2]:
while True:
a[0]+=2
cnt+=1
if a[0]==a[2]:
print(cnt)
break
elif a[0]>a[2]:
print((cnt+1))
break
else:
while True:
a[0]+=1
a[1]+=1
cnt+=1
if a[2]==a[1]:
break
while True:
a[0]+=2
cnt+=1
if a[0]==a[2]:
print(cnt)
break
elif a[0]>a[2]:
print((cnt+1))
break | a=list(map(int,input().split()))
a.sort()
b=a[2]-a[1]
c=a[2]-a[0]
if (b+c)%2==0:
print(((b+c)//2))
else:
print((((b+c)//2)+2)) | 39 | 8 | 548 | 131 | a = list(map(int, input().split()))
a = sorted(a)
cnt = 0
if a[0] == a[1] and a[1] == a[2]:
print((0))
elif a[0] == a[1]:
while True:
a[0] += 1
a[1] += 1
cnt += 1
if a[0] == a[2]:
print(cnt)
break
elif a[1] == a[2]:
while True:
a[0] += 2
cnt += 1
if a[0] == a[2]:
print(cnt)
break
elif a[0] > a[2]:
print((cnt + 1))
break
else:
while True:
a[0] += 1
a[1] += 1
cnt += 1
if a[2] == a[1]:
break
while True:
a[0] += 2
cnt += 1
if a[0] == a[2]:
print(cnt)
break
elif a[0] > a[2]:
print((cnt + 1))
break
| a = list(map(int, input().split()))
a.sort()
b = a[2] - a[1]
c = a[2] - a[0]
if (b + c) % 2 == 0:
print(((b + c) // 2))
else:
print((((b + c) // 2) + 2))
| false | 79.487179 | [
"-a = sorted(a)",
"-cnt = 0",
"-if a[0] == a[1] and a[1] == a[2]:",
"- print((0))",
"-elif a[0] == a[1]:",
"- while True:",
"- a[0] += 1",
"- a[1] += 1",
"- cnt += 1",
"- if a[0] == a[2]:",
"- print(cnt)",
"- break",
"-elif a[1] == a[2]... | false | 0.04185 | 0.04248 | 0.985164 | [
"s377351279",
"s395998590"
] |
u821588465 | p02861 | python | s343917001 | s564291266 | 126 | 25 | 27,136 | 9,020 | Accepted | Accepted | 80.16 | import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial
N = int(eval(input()))
xy = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in xy:
for j in xy:
cnt += np.linalg.norm(i - j)
print((cnt / N)) | N = int(eval(input()))
D = [list(map(int, input().split())) for _ in range(N)]
from math import hypot, factorial
distance = []
for i, j in D:
for k, l in D:
distance.append(hypot(i-k, j-l))
print((sum(distance)/N))
| 14 | 11 | 305 | 232 | import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial
N = int(eval(input()))
xy = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in xy:
for j in xy:
cnt += np.linalg.norm(i - j)
print((cnt / N))
| N = int(eval(input()))
D = [list(map(int, input().split())) for _ in range(N)]
from math import hypot, factorial
distance = []
for i, j in D:
for k, l in D:
distance.append(hypot(i - k, j - l))
print((sum(distance) / N))
| false | 21.428571 | [
"-import numpy as np",
"-from itertools import combinations",
"-from itertools import permutations",
"-from math import factorial",
"+N = int(eval(input()))",
"+D = [list(map(int, input().split())) for _ in range(N)]",
"+from math import hypot, factorial",
"-N = int(eval(input()))",
"-xy = np.array(... | false | 0.439217 | 0.056053 | 7.835763 | [
"s343917001",
"s564291266"
] |
u633068244 | p00129 | python | s345546294 | s799913946 | 40 | 30 | 4,400 | 4,400 | Accepted | Accepted | 25 | def inWall(x,y,x1,y1,r):
return True if ((x-x1)**2+(y-y1)**2)**0.5 <= r + 1e-9 else False
def isHide(x,y,r,a,b,c):
D = abs(a*x+b*y+c)/(a**2+b**2)**0.5
return True if D <= r + 1e-9 else False
def isBetween(x,y,tx,ty,sx,sy):
a,b,c = (x-tx)**2+(y-ty)**2,(x-sx)**2+(y-sy)**2,(sx-tx)**2+(sy-ty)**2
if c > b and c > a: return True
a,b,c = sorted([a,b,c])
return True if c-a-b <= 0 else False
while 1:
n = eval(input())
if n == 0: break
wall = [list(map(int,input().split())) for i in range(n)]
for i in range(eval(input())):
tx,ty,sx,sy = list(map(int,input().split()))
a,b,c = -(ty-sy),tx-sx,sx*ty-sy*tx
for x,y,r in wall:
t_in,s_in = inWall(x,y,tx,ty,r),inWall(x,y,sx,sy,r)
if t_in != s_in or (not t_in and isBetween(x,y,tx,ty,sx,sy) and isHide(x,y,r,a,b,c)):
print("Safe")
break
else:
print("Danger") | def inWall(x,y,x1,y1,r):
return True if ((x-x1)**2+(y-y1)**2)**0.5 <= r + 1e-9 else False
def isHide(x,y,r,a,b,c):
D = abs(a*x+b*y+c)/(a**2+b**2)**0.5
return True if D <= r + 1e-9 else False
def isBetween(x,y,tx,ty,sx,sy):
a,b,c = (x-tx)**2+(y-ty)**2,(x-sx)**2+(y-sy)**2,(sx-tx)**2+(sy-ty)**2
if c > b and c > a: return True
a,b,c = sorted([a,b,c])
return True if c-a-b <= 0 else False
while 1:
n = eval(input())
if n == 0: break
wall = [list(map(int,input().split())) for i in range(n)]
for i in range(eval(input())):
tx,ty,sx,sy = list(map(int,input().split()))
a,b,c = -(ty-sy),tx-sx,sx*ty-sy*tx
for x,y,r in wall:
t_in,s_in = inWall(x,y,tx,ty,r),inWall(x,y,sx,sy,r)
if t_in != s_in or (not t_in and isHide(x,y,r,a,b,c) and isBetween(x,y,tx,ty,sx,sy)):
print("Safe")
break
else:
print("Danger") | 27 | 27 | 844 | 844 | def inWall(x, y, x1, y1, r):
return True if ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 <= r + 1e-9 else False
def isHide(x, y, r, a, b, c):
D = abs(a * x + b * y + c) / (a**2 + b**2) ** 0.5
return True if D <= r + 1e-9 else False
def isBetween(x, y, tx, ty, sx, sy):
a, b, c = (
(x - tx) ** 2 + (y - ty) ** 2,
(x - sx) ** 2 + (y - sy) ** 2,
(sx - tx) ** 2 + (sy - ty) ** 2,
)
if c > b and c > a:
return True
a, b, c = sorted([a, b, c])
return True if c - a - b <= 0 else False
while 1:
n = eval(input())
if n == 0:
break
wall = [list(map(int, input().split())) for i in range(n)]
for i in range(eval(input())):
tx, ty, sx, sy = list(map(int, input().split()))
a, b, c = -(ty - sy), tx - sx, sx * ty - sy * tx
for x, y, r in wall:
t_in, s_in = inWall(x, y, tx, ty, r), inWall(x, y, sx, sy, r)
if t_in != s_in or (
not t_in
and isBetween(x, y, tx, ty, sx, sy)
and isHide(x, y, r, a, b, c)
):
print("Safe")
break
else:
print("Danger")
| def inWall(x, y, x1, y1, r):
return True if ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 <= r + 1e-9 else False
def isHide(x, y, r, a, b, c):
D = abs(a * x + b * y + c) / (a**2 + b**2) ** 0.5
return True if D <= r + 1e-9 else False
def isBetween(x, y, tx, ty, sx, sy):
a, b, c = (
(x - tx) ** 2 + (y - ty) ** 2,
(x - sx) ** 2 + (y - sy) ** 2,
(sx - tx) ** 2 + (sy - ty) ** 2,
)
if c > b and c > a:
return True
a, b, c = sorted([a, b, c])
return True if c - a - b <= 0 else False
while 1:
n = eval(input())
if n == 0:
break
wall = [list(map(int, input().split())) for i in range(n)]
for i in range(eval(input())):
tx, ty, sx, sy = list(map(int, input().split()))
a, b, c = -(ty - sy), tx - sx, sx * ty - sy * tx
for x, y, r in wall:
t_in, s_in = inWall(x, y, tx, ty, r), inWall(x, y, sx, sy, r)
if t_in != s_in or (
not t_in
and isHide(x, y, r, a, b, c)
and isBetween(x, y, tx, ty, sx, sy)
):
print("Safe")
break
else:
print("Danger")
| false | 0 | [
"+ and isHide(x, y, r, a, b, c)",
"- and isHide(x, y, r, a, b, c)"
] | false | 0.008337 | 0.123042 | 0.067758 | [
"s345546294",
"s799913946"
] |
u235210692 | p02695 | python | s502173360 | s494164556 | 1,119 | 286 | 21,724 | 93,892 | Accepted | Accepted | 74.44 | n,m,q=[int(i) for i in input().split()]
abcd=[]
import itertools
A=itertools.combinations_with_replacement(list(range(1,m+1)),n)
A=list(A)
for i in range(q):
abcd.append([int(i) for i in input().split()])
ans=0
for listA in A:
count=0
for kumi in abcd:
a,b,c,d=kumi
if listA[b-1]-listA[a-1]==c:
count+=d
ans=max(ans,count)
print(ans) | def return_d(A,abcds):
sum_d=0
for abcd in abcds:
a,b,c,d=abcd
if A[b]-A[a]==c:
sum_d+=d
return sum_d
n,m,q=[int(i) for i in input().split()]
abcds=[[int(i) for i in input().split()] for j in range(q)]
As=[]
for i_1 in range(1,m+1):
for i_2 in range(i_1, m + 1):
for i_3 in range(i_2, m + 1):
for i_4 in range(i_3, m + 1):
for i_5 in range(i_4, m + 1):
for i_6 in range(i_5, m + 1):
for i_7 in range(i_6, m + 1):
for i_8 in range(i_7, m + 1):
for i_9 in range(i_8, m + 1):
for i_10 in range(i_9, m + 1):
As.append([0,i_1,i_2,i_3,i_4,i_5,i_6,i_7,i_8,i_9,i_10])
ans=0
for A in As:
ans=max(ans,return_d(A,abcds))
print(ans) | 22 | 31 | 407 | 920 | n, m, q = [int(i) for i in input().split()]
abcd = []
import itertools
A = itertools.combinations_with_replacement(list(range(1, m + 1)), n)
A = list(A)
for i in range(q):
abcd.append([int(i) for i in input().split()])
ans = 0
for listA in A:
count = 0
for kumi in abcd:
a, b, c, d = kumi
if listA[b - 1] - listA[a - 1] == c:
count += d
ans = max(ans, count)
print(ans)
| def return_d(A, abcds):
sum_d = 0
for abcd in abcds:
a, b, c, d = abcd
if A[b] - A[a] == c:
sum_d += d
return sum_d
n, m, q = [int(i) for i in input().split()]
abcds = [[int(i) for i in input().split()] for j in range(q)]
As = []
for i_1 in range(1, m + 1):
for i_2 in range(i_1, m + 1):
for i_3 in range(i_2, m + 1):
for i_4 in range(i_3, m + 1):
for i_5 in range(i_4, m + 1):
for i_6 in range(i_5, m + 1):
for i_7 in range(i_6, m + 1):
for i_8 in range(i_7, m + 1):
for i_9 in range(i_8, m + 1):
for i_10 in range(i_9, m + 1):
As.append(
[
0,
i_1,
i_2,
i_3,
i_4,
i_5,
i_6,
i_7,
i_8,
i_9,
i_10,
]
)
ans = 0
for A in As:
ans = max(ans, return_d(A, abcds))
print(ans)
| false | 29.032258 | [
"+def return_d(A, abcds):",
"+ sum_d = 0",
"+ for abcd in abcds:",
"+ a, b, c, d = abcd",
"+ if A[b] - A[a] == c:",
"+ sum_d += d",
"+ return sum_d",
"+",
"+",
"-abcd = []",
"-import itertools",
"-",
"-A = itertools.combinations_with_replacement(list(range(1... | false | 0.180335 | 0.184119 | 0.979452 | [
"s502173360",
"s494164556"
] |
u604839890 | p02622 | python | s723518358 | s594800228 | 70 | 58 | 73,748 | 9,460 | Accepted | Accepted | 17.14 | s, t = [eval(input()) for i in range(2)]
ans = 0
for i in range(len(s)):
if s[i] != t[i]:
ans += 1
print(ans) | s = eval(input())
t = eval(input())
cnt = 0
for i, j in zip(s, t):
if i != j:
cnt += 1
print(cnt) | 6 | 8 | 114 | 105 | s, t = [eval(input()) for i in range(2)]
ans = 0
for i in range(len(s)):
if s[i] != t[i]:
ans += 1
print(ans)
| s = eval(input())
t = eval(input())
cnt = 0
for i, j in zip(s, t):
if i != j:
cnt += 1
print(cnt)
| false | 25 | [
"-s, t = [eval(input()) for i in range(2)]",
"-ans = 0",
"-for i in range(len(s)):",
"- if s[i] != t[i]:",
"- ans += 1",
"-print(ans)",
"+s = eval(input())",
"+t = eval(input())",
"+cnt = 0",
"+for i, j in zip(s, t):",
"+ if i != j:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.041909 | 0.040297 | 1.040014 | [
"s723518358",
"s594800228"
] |
u903005414 | p03476 | python | s439256539 | s669902305 | 1,885 | 976 | 46,784 | 38,160 | Accepted | Accepted | 48.22 | import numpy as np
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
is_prime = np.zeros(10**5 + 1, dtype='bool')
for i in range(2, 10**5 + 1):
if not is_prime[i]:
for j in range(2, int(np.sqrt(i) + 1)):
if i % j == 0:
break
else:
is_prime[i] = True
# is_prime[::i] = True
# print(is_prime[:10])
like_2017 = np.zeros(10**5 + 1, dtype='bool')
for i in range(1, 10**5 + 1):
if is_prime[i] and is_prime[(i + 1) // 2]:
like_2017[i] = True
# print(like_2017)
# print(like_2017.cumsum())
cumsum = like_2017.cumsum()
for l, r in lr:
print((cumsum[r] - cumsum[l - 1]))
| import numpy as np
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
U = 10**5 * 1
is_prime = np.ones(U, dtype='bool')
is_prime[0:2] = False
for i in range(2, U):
if i * i > 10**5:
break
if is_prime[i]:
is_prime[i * 2::i] = False
like_2017 = np.zeros(U, dtype='bool')
for i in range(1, U):
if 2 * i > U:
break
if is_prime[i] and is_prime[i * 2 - 1]:
like_2017[i * 2 - 1] = True
cumsum = like_2017.cumsum()
for l, r in lr:
print((cumsum[r] - cumsum[l - 1]))
| 25 | 23 | 698 | 556 | import numpy as np
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
is_prime = np.zeros(10**5 + 1, dtype="bool")
for i in range(2, 10**5 + 1):
if not is_prime[i]:
for j in range(2, int(np.sqrt(i) + 1)):
if i % j == 0:
break
else:
is_prime[i] = True
# is_prime[::i] = True
# print(is_prime[:10])
like_2017 = np.zeros(10**5 + 1, dtype="bool")
for i in range(1, 10**5 + 1):
if is_prime[i] and is_prime[(i + 1) // 2]:
like_2017[i] = True
# print(like_2017)
# print(like_2017.cumsum())
cumsum = like_2017.cumsum()
for l, r in lr:
print((cumsum[r] - cumsum[l - 1]))
| import numpy as np
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
U = 10**5 * 1
is_prime = np.ones(U, dtype="bool")
is_prime[0:2] = False
for i in range(2, U):
if i * i > 10**5:
break
if is_prime[i]:
is_prime[i * 2 :: i] = False
like_2017 = np.zeros(U, dtype="bool")
for i in range(1, U):
if 2 * i > U:
break
if is_prime[i] and is_prime[i * 2 - 1]:
like_2017[i * 2 - 1] = True
cumsum = like_2017.cumsum()
for l, r in lr:
print((cumsum[r] - cumsum[l - 1]))
| false | 8 | [
"-is_prime = np.zeros(10**5 + 1, dtype=\"bool\")",
"-for i in range(2, 10**5 + 1):",
"- if not is_prime[i]:",
"- for j in range(2, int(np.sqrt(i) + 1)):",
"- if i % j == 0:",
"- break",
"- else:",
"- is_prime[i] = True",
"- # is_prime[... | false | 2.096595 | 0.821475 | 2.552232 | [
"s439256539",
"s669902305"
] |
u102461423 | p02936 | python | s654446618 | s310203597 | 1,665 | 1,299 | 285,828 | 124,240 | Accepted | Accepted | 21.98 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
# 遅延評価で加えてあげるだけ
N,Q = list(map(int,input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
value = [0] * (N+1)
for p,x in PX:
value[p] += x
def dfs(v,parent,add):
value[v] += add
for x in graph[v]:
if x == parent:
continue
dfs(x,v,value[v])
dfs(1,0,0)
answer = ' '.join(map(str,value[1:]))
print(answer) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
# 遅延評価で加えてあげるだけ
N,Q = list(map(int,input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
value = [0] * (N+1)
for p,x in PX:
value[p] += x
q = [(1,0)]
while q:
x,parent = q.pop()
value[x] += value[parent]
for y in graph[x]:
if y == parent:
continue
q.append((y,x))
answer = ' '.join(map(str,value[1:]))
print(answer)
| 30 | 30 | 618 | 640 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
# 遅延評価で加えてあげるだけ
N, Q = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
value = [0] * (N + 1)
for p, x in PX:
value[p] += x
def dfs(v, parent, add):
value[v] += add
for x in graph[v]:
if x == parent:
continue
dfs(x, v, value[v])
dfs(1, 0, 0)
answer = " ".join(map(str, value[1:]))
print(answer)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
# 遅延評価で加えてあげるだけ
N, Q = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
value = [0] * (N + 1)
for p, x in PX:
value[p] += x
q = [(1, 0)]
while q:
x, parent = q.pop()
value[x] += value[parent]
for y in graph[x]:
if y == parent:
continue
q.append((y, x))
answer = " ".join(map(str, value[1:]))
print(answer)
| false | 0 | [
"-",
"-",
"-def dfs(v, parent, add):",
"- value[v] += add",
"- for x in graph[v]:",
"- if x == parent:",
"+q = [(1, 0)]",
"+while q:",
"+ x, parent = q.pop()",
"+ value[x] += value[parent]",
"+ for y in graph[x]:",
"+ if y == parent:",
"- dfs(x, v, value[v... | false | 0.038518 | 0.03854 | 0.999428 | [
"s654446618",
"s310203597"
] |
u994521204 | p03212 | python | s262309084 | s467834799 | 120 | 18 | 6,756 | 3,064 | Accepted | Accepted | 85 | from itertools import product
n=int(eval(input()))
cnt=0
kazu=[3,5,7]
for j in range(3,10):
kumiawase = list(product(kazu, repeat=j))
for kumi in kumiawase:
suuji=''
for moji in kumi:
suuji+=str(moji)
if '3' not in suuji:
continue
if '5' not in suuji:
continue
if '7' not in suuji:
continue
hantei=int(suuji)
if hantei <=n:
cnt+=1
print(cnt) | #桁DP
s = eval(input())
n = int(s)
keta = len(s)
# dp[i][j][k][l][smaller][other]
dp = [
[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
for _ in range(keta + 1)
]
dp[0][0][0][0][0] = 1
kazu = [0, 3, 5, 7]
for i in range(keta):
for j in range(2):
for k in range(2):
for l in range(2):
for smaller in range(2):
nd = int(s[i])
for d in range(10):
ni = i + 1
nj = j
nk = k
nl = l
nsmaller = smaller
if d not in kazu:
continue
if d == 3:
nj = 1
if d == 5:
nk = 1
if d == 7:
nl = 1
if smaller == 0:
if d > nd:
continue
if d < nd:
nsmaller = 1
if d == 0:
if nj + nk + nl != 0:
continue
dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]
print((dp[keta][1][1][1][0] + dp[keta][1][1][1][1]))
| 20 | 41 | 481 | 1,408 | from itertools import product
n = int(eval(input()))
cnt = 0
kazu = [3, 5, 7]
for j in range(3, 10):
kumiawase = list(product(kazu, repeat=j))
for kumi in kumiawase:
suuji = ""
for moji in kumi:
suuji += str(moji)
if "3" not in suuji:
continue
if "5" not in suuji:
continue
if "7" not in suuji:
continue
hantei = int(suuji)
if hantei <= n:
cnt += 1
print(cnt)
| # 桁DP
s = eval(input())
n = int(s)
keta = len(s)
# dp[i][j][k][l][smaller][other]
dp = [
[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
for _ in range(keta + 1)
]
dp[0][0][0][0][0] = 1
kazu = [0, 3, 5, 7]
for i in range(keta):
for j in range(2):
for k in range(2):
for l in range(2):
for smaller in range(2):
nd = int(s[i])
for d in range(10):
ni = i + 1
nj = j
nk = k
nl = l
nsmaller = smaller
if d not in kazu:
continue
if d == 3:
nj = 1
if d == 5:
nk = 1
if d == 7:
nl = 1
if smaller == 0:
if d > nd:
continue
if d < nd:
nsmaller = 1
if d == 0:
if nj + nk + nl != 0:
continue
dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]
print((dp[keta][1][1][1][0] + dp[keta][1][1][1][1]))
| false | 51.219512 | [
"-from itertools import product",
"-",
"-n = int(eval(input()))",
"-cnt = 0",
"-kazu = [3, 5, 7]",
"-for j in range(3, 10):",
"- kumiawase = list(product(kazu, repeat=j))",
"- for kumi in kumiawase:",
"- suuji = \"\"",
"- for moji in kumi:",
"- suuji += str(moji)",... | false | 0.771052 | 0.063602 | 12.123069 | [
"s262309084",
"s467834799"
] |
u645250356 | p02901 | python | s076243996 | s977682351 | 694 | 378 | 192,108 | 70,228 | Accepted | Accepted | 45.53 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n,m = inpl()
dp = [[INF]*(2**n) for i in range(m+5)]
for i in range(m+1):
dp[i][0] = 0
for i in range(m):
val,b = inpl()
c = inpl()
key = 0
for j in c:
key += 2**(j-1)
for j in range(2**n):
dp[i+1][j] = min(dp[i][j], dp[i][j&(~key)]+val)
res = dp[m][2**n-1]
print((res if res != INF else -1)) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
wv = []
for i in range(m):
a,b = inpl()
cnt = 0
c = inpl()
for i in c:
cnt += 1<<(i-1)
wv.append((a,cnt))
dp = [INF for _ in range(1<<n)]
dp[0] = 0
for i in range(m):
v,w = wv[i]
for j in range(1<<n):
dp[j|w] = min(dp[j|w], dp[j] + v)
print((dp[-1] if dp[-1] != INF else -1)) | 26 | 27 | 766 | 692 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n, m = inpl()
dp = [[INF] * (2**n) for i in range(m + 5)]
for i in range(m + 1):
dp[i][0] = 0
for i in range(m):
val, b = inpl()
c = inpl()
key = 0
for j in c:
key += 2 ** (j - 1)
for j in range(2**n):
dp[i + 1][j] = min(dp[i][j], dp[i][j & (~key)] + val)
res = dp[m][2**n - 1]
print((res if res != INF else -1))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, m = inpl()
wv = []
for i in range(m):
a, b = inpl()
cnt = 0
c = inpl()
for i in c:
cnt += 1 << (i - 1)
wv.append((a, cnt))
dp = [INF for _ in range(1 << n)]
dp[0] = 0
for i in range(m):
v, w = wv[i]
for j in range(1 << n):
dp[j | w] = min(dp[j | w], dp[j] + v)
print((dp[-1] if dp[-1] != INF else -1))
| false | 3.703704 | [
"-import sys, bisect, math, itertools, fractions, pprint",
"+import sys, bisect, math, itertools, fractions",
"+from decimal import Decimal",
"-mod2 = 998244353",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-dp = [[INF] * (2**n) for i in range(m + 5)... | false | 0.080272 | 0.046965 | 1.709193 | [
"s076243996",
"s977682351"
] |
u887207211 | p03774 | python | s907592395 | s130357577 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | N, M = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(M)]
result = []
for s in S:
a = s[0]
b = s[1]
for p in P:
c = p[0]
d = p[1]
direct = abs(a-c)+abs(b-d)
result.append(direct)
point = min(result)
print((result.index(point) + 1))
result = [] | N, M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(M)]
result = []
for a, b in AB:
tmp = []
for c, d in CD:
tmp.append(abs(a-c) + abs(b-d))
result.append(tmp.index(min(tmp))+1)
for r in result:
print(r) | 16 | 12 | 369 | 315 | N, M = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(M)]
result = []
for s in S:
a = s[0]
b = s[1]
for p in P:
c = p[0]
d = p[1]
direct = abs(a - c) + abs(b - d)
result.append(direct)
point = min(result)
print((result.index(point) + 1))
result = []
| N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]
result = []
for a, b in AB:
tmp = []
for c, d in CD:
tmp.append(abs(a - c) + abs(b - d))
result.append(tmp.index(min(tmp)) + 1)
for r in result:
print(r)
| false | 25 | [
"-S = [list(map(int, input().split())) for _ in range(N)]",
"-P = [list(map(int, input().split())) for _ in range(M)]",
"+AB = [list(map(int, input().split())) for _ in range(N)]",
"+CD = [list(map(int, input().split())) for _ in range(M)]",
"-for s in S:",
"- a = s[0]",
"- b = s[1]",
"- for ... | false | 0.035616 | 0.032721 | 1.088493 | [
"s907592395",
"s130357577"
] |
u137228327 | p03556 | python | s866055598 | s971647338 | 46 | 28 | 9,096 | 9,312 | Accepted | Accepted | 39.13 | import math
N = int(eval(input()))
mx = 0
for i in range(math.ceil(math.sqrt(N))+1):
if i**2 <= N and i**2 >= mx:
mx = i**2
print(mx) |
N = int(eval(input()))
sq = (int(N**(1/2))**2)
print(sq) | 8 | 4 | 155 | 54 | import math
N = int(eval(input()))
mx = 0
for i in range(math.ceil(math.sqrt(N)) + 1):
if i**2 <= N and i**2 >= mx:
mx = i**2
print(mx)
| N = int(eval(input()))
sq = int(N ** (1 / 2)) ** 2
print(sq)
| false | 50 | [
"-import math",
"-",
"-mx = 0",
"-for i in range(math.ceil(math.sqrt(N)) + 1):",
"- if i**2 <= N and i**2 >= mx:",
"- mx = i**2",
"-print(mx)",
"+sq = int(N ** (1 / 2)) ** 2",
"+print(sq)"
] | false | 0.098861 | 0.038091 | 2.595377 | [
"s866055598",
"s971647338"
] |
u604774382 | p02255 | python | s875656668 | s581921668 | 30 | 20 | 6,724 | 4,224 | Accepted | Accepted | 33.33 | def trace( nums ):
output = []
for num in nums:
output.append( str( num ) )
output.append( " " )
output.pop( )
print(( "".join( output ) ))
n = int( eval(input( )) )
nums = [ int( val ) for val in input( ).split( " " ) ]
trace( nums )
for i in range( 1, len( nums ) ):
key = nums[i]
j = i - 1
while 0 <= j and key < nums[j]:
nums[ j+1 ] = nums[j]
j -= 1
nums[ j+1 ] = key
trace( nums ) | n = int( input( ) )
nums = [ int( val ) for val in input( ).split( " " ) ]
print(( " ".join( map( str, nums ) ) ))
for i in range( 1, len( nums ) ):
key = nums[i]
j = i - 1
while 0 <= j and key < nums[j]:
nums[ j+1 ] = nums[j]
j -= 1
nums[ j+1 ] = key
print(( " ".join( map( str, nums ) ) )) | 20 | 12 | 416 | 316 | def trace(nums):
output = []
for num in nums:
output.append(str(num))
output.append(" ")
output.pop()
print(("".join(output)))
n = int(eval(input()))
nums = [int(val) for val in input().split(" ")]
trace(nums)
for i in range(1, len(nums)):
key = nums[i]
j = i - 1
while 0 <= j and key < nums[j]:
nums[j + 1] = nums[j]
j -= 1
nums[j + 1] = key
trace(nums)
| n = int(input())
nums = [int(val) for val in input().split(" ")]
print((" ".join(map(str, nums))))
for i in range(1, len(nums)):
key = nums[i]
j = i - 1
while 0 <= j and key < nums[j]:
nums[j + 1] = nums[j]
j -= 1
nums[j + 1] = key
print((" ".join(map(str, nums))))
| false | 40 | [
"-def trace(nums):",
"- output = []",
"- for num in nums:",
"- output.append(str(num))",
"- output.append(\" \")",
"- output.pop()",
"- print((\"\".join(output)))",
"-",
"-",
"-n = int(eval(input()))",
"+n = int(input())",
"-trace(nums)",
"+print((\" \".join(map(str... | false | 0.162146 | 0.056541 | 2.867771 | [
"s875656668",
"s581921668"
] |
u451012573 | p03805 | python | s015188324 | s995886331 | 31 | 25 | 3,064 | 3,064 | Accepted | Accepted | 19.35 | N, M = list(map(int, input().split()))
g = {}
n_path = 0
for i in range(N):
g[i] = []
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
g[a].append(b)
g[b].append(a)
def advance(v, passed):
global n_path
passed.append(v)
if len(passed) == N:
n_path += 1
for n in g[v]:
if n not in passed:
advance(n, passed)
passed.remove(v)
advance(0, [])
print(n_path)
| N, M = list(map(int, input().split()))
g = {}
n_path = 0
for i in range(N):
g[i] = set()
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
g[a].add(b)
g[b].add(a)
dp = [[0 for _ in range(N)] for _ in range(1 << N)]
dp[1][0] = 1
for bit in range(1 << N):
for v in range(N):
if bit & (1 << v) is False:
continue
sub = bit ^ (1 << v)
for u in range(N):
if (v in g[u]) and (sub & (1 << u)):
dp[bit][v] += dp[sub][u]
print((sum(dp[-1])))
| 29 | 28 | 470 | 565 | N, M = list(map(int, input().split()))
g = {}
n_path = 0
for i in range(N):
g[i] = []
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
g[a].append(b)
g[b].append(a)
def advance(v, passed):
global n_path
passed.append(v)
if len(passed) == N:
n_path += 1
for n in g[v]:
if n not in passed:
advance(n, passed)
passed.remove(v)
advance(0, [])
print(n_path)
| N, M = list(map(int, input().split()))
g = {}
n_path = 0
for i in range(N):
g[i] = set()
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
g[a].add(b)
g[b].add(a)
dp = [[0 for _ in range(N)] for _ in range(1 << N)]
dp[1][0] = 1
for bit in range(1 << N):
for v in range(N):
if bit & (1 << v) is False:
continue
sub = bit ^ (1 << v)
for u in range(N):
if (v in g[u]) and (sub & (1 << u)):
dp[bit][v] += dp[sub][u]
print((sum(dp[-1])))
| false | 3.448276 | [
"- g[i] = []",
"+ g[i] = set()",
"- g[a].append(b)",
"- g[b].append(a)",
"-",
"-",
"-def advance(v, passed):",
"- global n_path",
"- passed.append(v)",
"- if len(passed) == N:",
"- n_path += 1",
"- for n in g[v]:",
"- if n not in passed:",
"- ... | false | 0.055055 | 0.057901 | 0.950859 | [
"s015188324",
"s995886331"
] |
u868600519 | p03208 | python | s073280529 | s117088612 | 220 | 96 | 7,440 | 14,092 | Accepted | Accepted | 56.36 | N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m) | import sys
N, K, *h = list(map(int, sys.stdin.read().split()))
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m) | 6 | 7 | 148 | 137 | N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m)
| import sys
N, K, *h = list(map(int, sys.stdin.read().split()))
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m)
| false | 14.285714 | [
"-N, K = list(map(int, input().split()))",
"-h = [int(eval(input())) for _ in range(N)]",
"+import sys",
"+",
"+N, K, *h = list(map(int, sys.stdin.read().split()))"
] | false | 0.036444 | 0.046268 | 0.787663 | [
"s073280529",
"s117088612"
] |
u729133443 | p02735 | python | s261723999 | s691587837 | 22 | 20 | 3,192 | 3,064 | Accepted | Accepted | 9.09 | def main():
import sys
buf=sys.stdin.buffer
h,w=list(map(int,buf.readline().split()))
c,*s,_=buf.readline()
a=b=x=y=c==35
d=[(b,a)]
for c in s:
f=c==35
b+=a^f
a=f
d+=(b,a),
for c,*s in buf.read().split():
f=c==35
y+=x^f
b=y
a=x=f
p=[(b,a)]
for i,c in enumerate(s,1):
f=c==35
b+=a^f
c,g=d[i]
c+=f^g
if b>c:b=c
a=f
p+=(b,a),
d=p
print((b+1>>1))
main() | def main():
import sys
buf=sys.stdin.buffer
h,w=list(map(int,buf.readline().split()))
s=buf.readline()
a=b=x=y=s[0]==35
d=[b]
e=[a]
for i in range(1,w):
f=s[i]==35
b+=a^f
a=f
d+=b,
e+=a,
for s in buf.read().split():
f=s[0]==35
y+=x^f
b=y
a=x=f
p=[b]
q=[a]
for i in range(1,w):
f=s[i]==35
b+=a^f
c=d[i]+(f^e[i])
if b>c:b=c
a=f
p+=b,
q+=a,
d=p
e=q
print((b+1>>1))
main() | 29 | 33 | 473 | 510 | def main():
import sys
buf = sys.stdin.buffer
h, w = list(map(int, buf.readline().split()))
c, *s, _ = buf.readline()
a = b = x = y = c == 35
d = [(b, a)]
for c in s:
f = c == 35
b += a ^ f
a = f
d += ((b, a),)
for c, *s in buf.read().split():
f = c == 35
y += x ^ f
b = y
a = x = f
p = [(b, a)]
for i, c in enumerate(s, 1):
f = c == 35
b += a ^ f
c, g = d[i]
c += f ^ g
if b > c:
b = c
a = f
p += ((b, a),)
d = p
print((b + 1 >> 1))
main()
| def main():
import sys
buf = sys.stdin.buffer
h, w = list(map(int, buf.readline().split()))
s = buf.readline()
a = b = x = y = s[0] == 35
d = [b]
e = [a]
for i in range(1, w):
f = s[i] == 35
b += a ^ f
a = f
d += (b,)
e += (a,)
for s in buf.read().split():
f = s[0] == 35
y += x ^ f
b = y
a = x = f
p = [b]
q = [a]
for i in range(1, w):
f = s[i] == 35
b += a ^ f
c = d[i] + (f ^ e[i])
if b > c:
b = c
a = f
p += (b,)
q += (a,)
d = p
e = q
print((b + 1 >> 1))
main()
| false | 12.121212 | [
"- c, *s, _ = buf.readline()",
"- a = b = x = y = c == 35",
"- d = [(b, a)]",
"- for c in s:",
"- f = c == 35",
"+ s = buf.readline()",
"+ a = b = x = y = s[0] == 35",
"+ d = [b]",
"+ e = [a]",
"+ for i in range(1, w):",
"+ f = s[i] == 35",
"- d ... | false | 0.058172 | 0.067303 | 0.864334 | [
"s261723999",
"s691587837"
] |
u600402037 | p03244 | python | s734885509 | s581981065 | 152 | 100 | 22,096 | 21,944 | Accepted | Accepted | 34.21 | from collections import Counter
N = int(eval(input()))
V = list(map(int, input().split()))
s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
c1 = c2 = c3 = c4 = 0
Z1 = Counter(V1)
Z2 = Counter(V2)
x1, c1 = Z1.most_common(1)[0]
x2, c2 = Z2.most_common(1)[0]
if len(Z1) > 1:
x3, c3 = Counter(V1).most_common(2)[1]
if len(Z2) > 1:
x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
a = max(c1+c4, c2+c3)
print((N-a))
else:
print((N - c1 - c2)) | # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 奇数番目の最頻値と偶数番目の最頻値が同じ時に注意
N = ir()
V = lr()
odd = V[::2]
even = V[1::2]
cnt_odd = Counter(odd)
cnt_even = Counter(even)
cnt_odd_most = cnt_odd.most_common()
cnt_even_most = cnt_even.most_common()
if cnt_odd_most[0][0] == cnt_even_most[0][0]:
answer = N
if len(cnt_odd_most) > 1:
temp = N - cnt_odd_most[1][1] - cnt_even_most[0][1]
answer = min(answer, temp)
if len(cnt_even_most) > 1:
temp = N - cnt_odd_most[0][1] - cnt_even_most[1][1]
answer = min(answer, temp)
if answer == N:
answer = N // 2
else:
answer = N - cnt_odd_most[0][1] - cnt_even_most[0][1]
print(answer)
| 23 | 31 | 519 | 831 | from collections import Counter
N = int(eval(input()))
V = list(map(int, input().split()))
s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
c1 = c2 = c3 = c4 = 0
Z1 = Counter(V1)
Z2 = Counter(V2)
x1, c1 = Z1.most_common(1)[0]
x2, c2 = Z2.most_common(1)[0]
if len(Z1) > 1:
x3, c3 = Counter(V1).most_common(2)[1]
if len(Z2) > 1:
x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
a = max(c1 + c4, c2 + c3)
print((N - a))
else:
print((N - c1 - c2))
| # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 奇数番目の最頻値と偶数番目の最頻値が同じ時に注意
N = ir()
V = lr()
odd = V[::2]
even = V[1::2]
cnt_odd = Counter(odd)
cnt_even = Counter(even)
cnt_odd_most = cnt_odd.most_common()
cnt_even_most = cnt_even.most_common()
if cnt_odd_most[0][0] == cnt_even_most[0][0]:
answer = N
if len(cnt_odd_most) > 1:
temp = N - cnt_odd_most[1][1] - cnt_even_most[0][1]
answer = min(answer, temp)
if len(cnt_even_most) > 1:
temp = N - cnt_odd_most[0][1] - cnt_even_most[1][1]
answer = min(answer, temp)
if answer == N:
answer = N // 2
else:
answer = N - cnt_odd_most[0][1] - cnt_even_most[0][1]
print(answer)
| false | 25.806452 | [
"+# coding: utf-8",
"+import sys",
"-N = int(eval(input()))",
"-V = list(map(int, input().split()))",
"-s1 = Counter(V).most_common(2)[0]",
"-s2 = Counter(V).most_common(2)[0]",
"-V1 = V[0::2]",
"-V2 = V[1::2]",
"-c1 = c2 = c3 = c4 = 0",
"-Z1 = Counter(V1)",
"-Z2 = Counter(V2)",
"-x1, c1 = Z1.... | false | 0.064856 | 0.03646 | 1.778798 | [
"s734885509",
"s581981065"
] |
u433375322 | p02641 | python | s780383823 | s651444259 | 30 | 27 | 9,208 | 9,208 | Accepted | Accepted | 10 | x,n=list(map(int,input().split()))
l=list(map(int,input().split()))
a=0
for i in range(100):
if x-i not in l:
ans=x-i
a=i+1
break
for i in range(100):
if x+i not in l:
ansb=x+i
ab=i+1
break
if a>ab:
print(ansb)
else:
print(ans) | x,n=list(map(int,input().split()))
l=list(map(int,input().split()))
flag=0
i=0
while flag==0:
if x-i not in l:
flag=1
ansa=x-i
i+=1
flag=0
i=0
while flag==0:
if x+i not in l:
flag=1
ansb=x+i
i+=1
if abs(ansa-x)<=abs(ansb-x):
print(ansa)
else:
print(ansb) | 17 | 20 | 301 | 323 | x, n = list(map(int, input().split()))
l = list(map(int, input().split()))
a = 0
for i in range(100):
if x - i not in l:
ans = x - i
a = i + 1
break
for i in range(100):
if x + i not in l:
ansb = x + i
ab = i + 1
break
if a > ab:
print(ansb)
else:
print(ans)
| x, n = list(map(int, input().split()))
l = list(map(int, input().split()))
flag = 0
i = 0
while flag == 0:
if x - i not in l:
flag = 1
ansa = x - i
i += 1
flag = 0
i = 0
while flag == 0:
if x + i not in l:
flag = 1
ansb = x + i
i += 1
if abs(ansa - x) <= abs(ansb - x):
print(ansa)
else:
print(ansb)
| false | 15 | [
"-a = 0",
"-for i in range(100):",
"+flag = 0",
"+i = 0",
"+while flag == 0:",
"- ans = x - i",
"- a = i + 1",
"- break",
"-for i in range(100):",
"+ flag = 1",
"+ ansa = x - i",
"+ i += 1",
"+flag = 0",
"+i = 0",
"+while flag == 0:",
"+ fla... | false | 0.044378 | 0.044764 | 0.991378 | [
"s780383823",
"s651444259"
] |
u355726239 | p00445 | python | s122287362 | s865592515 | 40 | 30 | 6,748 | 7,352 | Accepted | Accepted | 25 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
try:
s = eval(input(''))
except:
break
n_joi = 0
n_ioi = 0
for i in range(len(s[:-2])):
cut_s = s[i:i+3]
if cut_s == 'JOI':
n_joi += 1
if cut_s == 'IOI':
n_ioi += 1
print(n_joi)
print(n_ioi) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
try:
input_s = eval(input())
except:
break
s_list = [input_s[i:i+3] for i in range(len(input_s[:-2]))]
n_joi = 0
n_ioi = 0
for s in s_list:
if s == 'JOI':
n_joi += 1
if s == 'IOI':
n_ioi += 1
print(n_joi)
print(n_ioi) | 20 | 21 | 356 | 381 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
try:
s = eval(input(""))
except:
break
n_joi = 0
n_ioi = 0
for i in range(len(s[:-2])):
cut_s = s[i : i + 3]
if cut_s == "JOI":
n_joi += 1
if cut_s == "IOI":
n_ioi += 1
print(n_joi)
print(n_ioi)
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
try:
input_s = eval(input())
except:
break
s_list = [input_s[i : i + 3] for i in range(len(input_s[:-2]))]
n_joi = 0
n_ioi = 0
for s in s_list:
if s == "JOI":
n_joi += 1
if s == "IOI":
n_ioi += 1
print(n_joi)
print(n_ioi)
| false | 4.761905 | [
"- s = eval(input(\"\"))",
"+ input_s = eval(input())",
"+ s_list = [input_s[i : i + 3] for i in range(len(input_s[:-2]))]",
"- for i in range(len(s[:-2])):",
"- cut_s = s[i : i + 3]",
"- if cut_s == \"JOI\":",
"+ for s in s_list:",
"+ if s == \"JOI\":",
"... | false | 0.043095 | 0.042808 | 1.006703 | [
"s122287362",
"s865592515"
] |
u241159583 | p02881 | python | s482634945 | s787984533 | 197 | 160 | 2,940 | 9,424 | Accepted | Accepted | 18.78 | n = int(eval(input()))
x = int(n**0.5)
while n%x!=0:
x-=1
x,y = x-1, n//x -1
print((x+y)) | n = int(eval(input()))
x = int(n**0.5)
while n%x!=0: x-= 1
y = n//x
print((x-1+y-1)) | 6 | 5 | 90 | 80 | n = int(eval(input()))
x = int(n**0.5)
while n % x != 0:
x -= 1
x, y = x - 1, n // x - 1
print((x + y))
| n = int(eval(input()))
x = int(n**0.5)
while n % x != 0:
x -= 1
y = n // x
print((x - 1 + y - 1))
| false | 16.666667 | [
"-x, y = x - 1, n // x - 1",
"-print((x + y))",
"+y = n // x",
"+print((x - 1 + y - 1))"
] | false | 0.036132 | 0.037002 | 0.97647 | [
"s482634945",
"s787984533"
] |
u814986259 | p03044 | python | s910020260 | s167133852 | 788 | 429 | 55,304 | 52,372 | Accepted | Accepted | 45.56 | import collections
N = int(eval(input()))
d = [0]*N
route = [set() for i in range(N)]
for i in range(N-1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
route[u].add((v, w))
route[v].add((u, w))
d[u] += 1
d[v] += 1
d = d.index(max(d))
q = collections.deque()
q.append((d, 0))
G = [0]*N
while(q):
x, l = q.popleft()
for v, w in route[x]:
G[v] = w + l
q.append((v, w+l))
route[v].remove((x, w))
ans = [0]*N
for i in range(N):
if i == d:
continue
if G[i] % 2 == 1:
ans[i] = 1
for i in range(N):
print((ans[i]))
| import collections
def main():
import sys
input = sys.stdin.readline
N = int(input())
color = [-1]*N
G = [set() for i in range(N)]
for i in range(N-1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
G[u].add((v, w))
G[v].add((u, w))
root = 0
color[0] = 0
q = collections.deque()
q.append((root, 0))
while(q):
x, W = q.popleft()
for y, w in G[x]:
if color[y] < 0:
if (W+w) % 2 == 0:
color[y] = 0
else:
color[y] = 1
q.append((y, W+w))
else:
continue
print(*color, sep="\n")
main()
| 33 | 35 | 627 | 753 | import collections
N = int(eval(input()))
d = [0] * N
route = [set() for i in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
route[u].add((v, w))
route[v].add((u, w))
d[u] += 1
d[v] += 1
d = d.index(max(d))
q = collections.deque()
q.append((d, 0))
G = [0] * N
while q:
x, l = q.popleft()
for v, w in route[x]:
G[v] = w + l
q.append((v, w + l))
route[v].remove((x, w))
ans = [0] * N
for i in range(N):
if i == d:
continue
if G[i] % 2 == 1:
ans[i] = 1
for i in range(N):
print((ans[i]))
| import collections
def main():
import sys
input = sys.stdin.readline
N = int(input())
color = [-1] * N
G = [set() for i in range(N)]
for i in range(N - 1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
G[u].add((v, w))
G[v].add((u, w))
root = 0
color[0] = 0
q = collections.deque()
q.append((root, 0))
while q:
x, W = q.popleft()
for y, w in G[x]:
if color[y] < 0:
if (W + w) % 2 == 0:
color[y] = 0
else:
color[y] = 1
q.append((y, W + w))
else:
continue
print(*color, sep="\n")
main()
| false | 5.714286 | [
"-N = int(eval(input()))",
"-d = [0] * N",
"-route = [set() for i in range(N)]",
"-for i in range(N - 1):",
"- u, v, w = list(map(int, input().split()))",
"- u -= 1",
"- v -= 1",
"- route[u].add((v, w))",
"- route[v].add((u, w))",
"- d[u] += 1",
"- d[v] += 1",
"-d = d.inde... | false | 0.042286 | 0.040012 | 1.056848 | [
"s910020260",
"s167133852"
] |
u476604182 | p03608 | python | s843045425 | s105926808 | 504 | 338 | 65,752 | 49,264 | Accepted | Accepted | 32.94 | from itertools import permutations
N, M, R = list(map(int, input().split()))
r = [int(c)-1 for c in input().split()]
cost = [[float('inf')]*N for i in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
cost[a-1][b-1] = c
cost[b-1][a-1] = c
def warshall_floyd(d,n):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
dist = warshall_floyd(cost,N)
ls = list(permutations(r))
ans = -1
for l in ls:
m = 0
p = l[0]
flag = False
for q in l[1:]:
m += dist[p][q]
p = q
if ans==-1 or ans>m:
ans = m
print(ans) | from itertools import permutations
N, M, R, *L = list(map(int, open(0).read().split()))
city = L[:R]
inf = L[R:]
dist = [[10**10]*N for i in range(N)]
for x,y,c in zip(*[iter(inf)]*3):
dist[x-1][y-1] = c
dist[y-1][x-1] = c
for i in range(N):
dist[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])
ans = 10**10
for m in permutations(city):
n = 0
for i in range(R-1):
n += dist[m[i]-1][m[i+1]-1]
ans = min(ans,n)
print(ans)
| 28 | 24 | 688 | 543 | from itertools import permutations
N, M, R = list(map(int, input().split()))
r = [int(c) - 1 for c in input().split()]
cost = [[float("inf")] * N for i in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
cost[a - 1][b - 1] = c
cost[b - 1][a - 1] = c
def warshall_floyd(d, n):
# d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
dist = warshall_floyd(cost, N)
ls = list(permutations(r))
ans = -1
for l in ls:
m = 0
p = l[0]
flag = False
for q in l[1:]:
m += dist[p][q]
p = q
if ans == -1 or ans > m:
ans = m
print(ans)
| from itertools import permutations
N, M, R, *L = list(map(int, open(0).read().split()))
city = L[:R]
inf = L[R:]
dist = [[10**10] * N for i in range(N)]
for x, y, c in zip(*[iter(inf)] * 3):
dist[x - 1][y - 1] = c
dist[y - 1][x - 1] = c
for i in range(N):
dist[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j])
ans = 10**10
for m in permutations(city):
n = 0
for i in range(R - 1):
n += dist[m[i] - 1][m[i + 1] - 1]
ans = min(ans, n)
print(ans)
| false | 14.285714 | [
"-N, M, R = list(map(int, input().split()))",
"-r = [int(c) - 1 for c in input().split()]",
"-cost = [[float(\"inf\")] * N for i in range(N)]",
"-for i in range(M):",
"- a, b, c = list(map(int, input().split()))",
"- cost[a - 1][b - 1] = c",
"- cost[b - 1][a - 1] = c",
"-",
"-",
"-def war... | false | 0.044099 | 0.038591 | 1.142715 | [
"s843045425",
"s105926808"
] |
u681773563 | p02707 | python | s625645505 | s285887925 | 135 | 118 | 40,236 | 40,228 | Accepted | Accepted | 12.59 | num = int(eval(input()))
boss = input().split()
ans_list = [0] * num
for i_boss in boss:
ans_list[int(i_boss)-1] += 1
a = list([str(x) for x in ans_list])
print(('\n'.join(a)))
| num = int(eval(input()))
boss = input().split()
ans_list = [0] * num
for i_boss in boss:
ans_list[int(i_boss)-1] += 1
print(('\n'.join(list(map(str, ans_list))))) | 9 | 6 | 189 | 163 | num = int(eval(input()))
boss = input().split()
ans_list = [0] * num
for i_boss in boss:
ans_list[int(i_boss) - 1] += 1
a = list([str(x) for x in ans_list])
print(("\n".join(a)))
| num = int(eval(input()))
boss = input().split()
ans_list = [0] * num
for i_boss in boss:
ans_list[int(i_boss) - 1] += 1
print(("\n".join(list(map(str, ans_list)))))
| false | 33.333333 | [
"-a = list([str(x) for x in ans_list])",
"-print((\"\\n\".join(a)))",
"+print((\"\\n\".join(list(map(str, ans_list)))))"
] | false | 0.081005 | 0.079366 | 1.020653 | [
"s625645505",
"s285887925"
] |
u197955752 | p02697 | python | s847013860 | s350554641 | 98 | 77 | 9,284 | 9,272 | Accepted | Accepted | 21.43 | import sys
N, M = [int(x) for x in input().split()]
s = []; e = [];
s.append(1)
e.append(2 * -(-M // 2)) # 2 * ceiling(M/2)
s.append(N - 2 * (M // 2))
e.append(N)
n = 0
while True:
for i in range(2):
if n >= M: sys.exit()
print((s[i], e[i]))
s[i] += 1
e[i] -= 1
n += 1 | import sys
N, M = [int(x) for x in input().split()]
s = 1
e = 2 * -(-M // 2)
for _ in range(M):
if s >= e:
s = N - 2 * (M // 2)
e = N
print((s, e))
s += 1
e -= 1 | 17 | 12 | 328 | 203 | import sys
N, M = [int(x) for x in input().split()]
s = []
e = []
s.append(1)
e.append(2 * -(-M // 2)) # 2 * ceiling(M/2)
s.append(N - 2 * (M // 2))
e.append(N)
n = 0
while True:
for i in range(2):
if n >= M:
sys.exit()
print((s[i], e[i]))
s[i] += 1
e[i] -= 1
n += 1
| import sys
N, M = [int(x) for x in input().split()]
s = 1
e = 2 * -(-M // 2)
for _ in range(M):
if s >= e:
s = N - 2 * (M // 2)
e = N
print((s, e))
s += 1
e -= 1
| false | 29.411765 | [
"-s = []",
"-e = []",
"-s.append(1)",
"-e.append(2 * -(-M // 2)) # 2 * ceiling(M/2)",
"-s.append(N - 2 * (M // 2))",
"-e.append(N)",
"-n = 0",
"-while True:",
"- for i in range(2):",
"- if n >= M:",
"- sys.exit()",
"- print((s[i], e[i]))",
"- s[i] += 1",
... | false | 0.037895 | 0.082479 | 0.459444 | [
"s847013860",
"s350554641"
] |
u063052907 | p03162 | python | s690611611 | s015353045 | 350 | 197 | 3,064 | 3,064 | Accepted | Accepted | 43.71 | # coding: utf-8
# import sys
# input = sys.stdin.readline
def dp_happiness(N):
yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
for _ in range(N):
a, b, c = list(map(int, input().split()))
today_a = a + max(yesterday_b, yesterday_c)
today_b = b + max(yesterday_c, yesterday_a)
today_c = c + max(yesterday_a, yesterday_b)
yesterday_a = today_a
yesterday_b = today_b
yesterday_c = today_c
return max(today_a, today_b, today_c)
N = int(eval(input()))
print((dp_happiness(N))) | # coding: utf-8
import sys
input = sys.stdin.readline
def dp_happiness(N):
yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
for _ in range(N):
a, b, c = list(map(int, input().split()))
today_a = a + max(yesterday_b, yesterday_c)
today_b = b + max(yesterday_c, yesterday_a)
today_c = c + max(yesterday_a, yesterday_b)
yesterday_a = today_a
yesterday_b = today_b
yesterday_c = today_c
return max(today_a, today_b, today_c)
N = int(eval(input()))
print((dp_happiness(N))) | 20 | 20 | 548 | 544 | # coding: utf-8
# import sys
# input = sys.stdin.readline
def dp_happiness(N):
yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
for _ in range(N):
a, b, c = list(map(int, input().split()))
today_a = a + max(yesterday_b, yesterday_c)
today_b = b + max(yesterday_c, yesterday_a)
today_c = c + max(yesterday_a, yesterday_b)
yesterday_a = today_a
yesterday_b = today_b
yesterday_c = today_c
return max(today_a, today_b, today_c)
N = int(eval(input()))
print((dp_happiness(N)))
| # coding: utf-8
import sys
input = sys.stdin.readline
def dp_happiness(N):
yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
for _ in range(N):
a, b, c = list(map(int, input().split()))
today_a = a + max(yesterday_b, yesterday_c)
today_b = b + max(yesterday_c, yesterday_a)
today_c = c + max(yesterday_a, yesterday_b)
yesterday_a = today_a
yesterday_b = today_b
yesterday_c = today_c
return max(today_a, today_b, today_c)
N = int(eval(input()))
print((dp_happiness(N)))
| false | 0 | [
"-# import sys",
"-# input = sys.stdin.readline",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+"
] | false | 0.036747 | 0.06864 | 0.535352 | [
"s690611611",
"s015353045"
] |
u347600233 | p02953 | python | s454296707 | s529947699 | 87 | 72 | 20,472 | 20,496 | Accepted | Accepted | 17.24 | n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = 'Yes'
for i in range(n - 1, 0, -1):
if h[i - 1] > h[i]:
h[i - 1] -= 1
if h[i - 1] > h[i]:
ans = 'No'
print(ans) | n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = 'Yes'
for i in range(n - 1, 0, -1):
d = h[i - 1] - h[i]
if d >= 2:
ans = 'No'
break
elif d == 1:
h[i - 1] -= 1
print(ans) | 9 | 11 | 204 | 228 | n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = "Yes"
for i in range(n - 1, 0, -1):
if h[i - 1] > h[i]:
h[i - 1] -= 1
if h[i - 1] > h[i]:
ans = "No"
print(ans)
| n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = "Yes"
for i in range(n - 1, 0, -1):
d = h[i - 1] - h[i]
if d >= 2:
ans = "No"
break
elif d == 1:
h[i - 1] -= 1
print(ans)
| false | 18.181818 | [
"- if h[i - 1] > h[i]:",
"+ d = h[i - 1] - h[i]",
"+ if d >= 2:",
"+ ans = \"No\"",
"+ break",
"+ elif d == 1:",
"- if h[i - 1] > h[i]:",
"- ans = \"No\""
] | false | 0.040672 | 0.044147 | 0.921284 | [
"s454296707",
"s529947699"
] |
u633068244 | p00009 | python | s599155594 | s195763521 | 400 | 330 | 35,064 | 37,128 | Accepted | Accepted | 17.5 | import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
for i in n:
print(sum(p[:i])) | import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print(sum(p[:i])) | 19 | 18 | 306 | 305 | import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n) + 1
sqrt = int(math.sqrt(r))
p = [1] * r
p[0] = 0
for i in range(1, sqrt):
if p[i]:
for j in range(2 * i + 1, r, i + 1):
p[j] = 0
for i in n:
print(sum(p[:i]))
| import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n) + 1
sqrt = int(math.sqrt(r))
p = [1] * r
p[0] = 0
for i in range(1, sqrt):
if p[i]:
p[2 * i + 1 :: i + 1] = [0 for x in range(2 * i + 1, r, i + 1)]
for i in n:
print(sum(p[:i]))
| false | 5.263158 | [
"- for j in range(2 * i + 1, r, i + 1):",
"- p[j] = 0",
"+ p[2 * i + 1 :: i + 1] = [0 for x in range(2 * i + 1, r, i + 1)]"
] | false | 0.049036 | 0.070656 | 0.694014 | [
"s599155594",
"s195763521"
] |
u319410662 | p03836 | python | s203506840 | s126254620 | 11 | 10 | 2,692 | 2,692 | Accepted | Accepted | 9.09 | sx, sy, tx, ty = list(map(int, input().split()))
dx = tx-sx
dy = ty-sy
s = ""
s += "L" + "U"*(dy+1) + "R"*(dx+1) + "D"
s += "R" + "D"*(dy+1) + "L"*(dx+1) + "U"
s += "U"*dy + "R"*dx
s += "D"*dy + "L"*dx
print(s) | sx,sy,tx,ty = list(map(int, input().split()))
r = ""
r += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
r += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
r += "U"*(ty-sy)+"R"*(tx-sx)
r += "D"*(ty-sy)+"L"*(tx-sx)
print(r) | 9 | 7 | 215 | 204 | sx, sy, tx, ty = list(map(int, input().split()))
dx = tx - sx
dy = ty - sy
s = ""
s += "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D"
s += "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"
s += "U" * dy + "R" * dx
s += "D" * dy + "L" * dx
print(s)
| sx, sy, tx, ty = list(map(int, input().split()))
r = ""
r += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
r += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"
r += "U" * (ty - sy) + "R" * (tx - sx)
r += "D" * (ty - sy) + "L" * (tx - sx)
print(r)
| false | 22.222222 | [
"-dx = tx - sx",
"-dy = ty - sy",
"-s = \"\"",
"-s += \"L\" + \"U\" * (dy + 1) + \"R\" * (dx + 1) + \"D\"",
"-s += \"R\" + \"D\" * (dy + 1) + \"L\" * (dx + 1) + \"U\"",
"-s += \"U\" * dy + \"R\" * dx",
"-s += \"D\" * dy + \"L\" * dx",
"-print(s)",
"+r = \"\"",
"+r += \"L\" + \"U\" * (ty - sy + 1) ... | false | 0.064271 | 0.046935 | 1.369365 | [
"s203506840",
"s126254620"
] |
u844789719 | p03108 | python | s901774544 | s034255936 | 794 | 674 | 31,088 | 31,124 | Accepted | Accepted | 15.11 | N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]
UF = list(range(N + 1))
SIZE = [0] + [1] * N # 1-indexed
def find(x):
if UF[x] != x:
UF[x] = find(UF[x])
return UF[x]
def unite(x, y):
m = min(find(x), find(y))
SIZE[m] = SIZE[find(x)] + SIZE[find(y)]
UF[find(x)] = m
UF[find(y)] = m
def is_same(x, y):
return find(x) == find(y)
def scan_uf():
for i in range(len(UF)):
find(i)
ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
if not is_same(a, b):
ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
unite(a, b)
else:
ans += [ans[-1]]
print(*ans[-2::-1], sep='\n')
| N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]
UF = list(range(N + 1))
SIZE = [0] + [1] * N # 1-indexed
def find(x):
if UF[x] != x:
UF[x] = find(UF[x])
return UF[x]
def unite(x, y):
X, Y = find(x), find(y)
SX,SY=SIZE[X],SIZE[Y]
m = min(X,Y)
SIZE[m] = SX + SY
SIZE[X+Y-m]=0
UF[X+Y-m] = m
def is_same(x, y):
return find(x) == find(y)
def scan_uf():
for i in range(len(UF)):
find(i)
ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
if not is_same(a, b):
ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
unite(a, b)
else:
ans += [ans[-1]]
print(*ans[-2::-1], sep='\n')
| 37 | 39 | 737 | 754 | N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]
UF = list(range(N + 1))
SIZE = [0] + [1] * N # 1-indexed
def find(x):
if UF[x] != x:
UF[x] = find(UF[x])
return UF[x]
def unite(x, y):
m = min(find(x), find(y))
SIZE[m] = SIZE[find(x)] + SIZE[find(y)]
UF[find(x)] = m
UF[find(y)] = m
def is_same(x, y):
return find(x) == find(y)
def scan_uf():
for i in range(len(UF)):
find(i)
ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
if not is_same(a, b):
ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
unite(a, b)
else:
ans += [ans[-1]]
print(*ans[-2::-1], sep="\n")
| N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]
UF = list(range(N + 1))
SIZE = [0] + [1] * N # 1-indexed
def find(x):
if UF[x] != x:
UF[x] = find(UF[x])
return UF[x]
def unite(x, y):
X, Y = find(x), find(y)
SX, SY = SIZE[X], SIZE[Y]
m = min(X, Y)
SIZE[m] = SX + SY
SIZE[X + Y - m] = 0
UF[X + Y - m] = m
def is_same(x, y):
return find(x) == find(y)
def scan_uf():
for i in range(len(UF)):
find(i)
ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
if not is_same(a, b):
ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
unite(a, b)
else:
ans += [ans[-1]]
print(*ans[-2::-1], sep="\n")
| false | 5.128205 | [
"- m = min(find(x), find(y))",
"- SIZE[m] = SIZE[find(x)] + SIZE[find(y)]",
"- UF[find(x)] = m",
"- UF[find(y)] = m",
"+ X, Y = find(x), find(y)",
"+ SX, SY = SIZE[X], SIZE[Y]",
"+ m = min(X, Y)",
"+ SIZE[m] = SX + SY",
"+ SIZE[X + Y - m] = 0",
"+ UF[X + Y - m] = m"
] | false | 0.036415 | 0.035954 | 1.012813 | [
"s901774544",
"s034255936"
] |
u393253137 | p03578 | python | s238018077 | s455921916 | 232 | 191 | 59,108 | 53,604 | Accepted | Accepted | 17.67 | def main():
n = int(eval(input()))
D = list(map(int, input().split()))
m = int(eval(input()))
T = list(map(int, input().split()))
dic = dict()
# 辞書はDだけで十分.Counterより速い.
for d in D:
if d in dic:
dic[d] += 1
else:
dic[d] = 1
for t in T:
if t not in dic or dic[t] == 0:
print('NO')
return
else:
dic[t] -= 1
print('YES')
main() | def main():
# D, Tは文字数カウントするだけだからint型にする必要なし.
n = int(eval(input()))
D = input().split()
m = int(eval(input()))
T = input().split()
dic = dict()
# 辞書はDだけで十分.Counterより速い.
for d in D:
# dic.get(d)と比べると, if in の方が速い.
if d in dic:
dic[d] += 1
else:
dic[d] = 1
for t in T:
if t not in dic or dic[t] == 0:
print('NO')
return
else:
dic[t] -= 1
print('YES')
main() | 22 | 24 | 465 | 525 | def main():
n = int(eval(input()))
D = list(map(int, input().split()))
m = int(eval(input()))
T = list(map(int, input().split()))
dic = dict()
# 辞書はDだけで十分.Counterより速い.
for d in D:
if d in dic:
dic[d] += 1
else:
dic[d] = 1
for t in T:
if t not in dic or dic[t] == 0:
print("NO")
return
else:
dic[t] -= 1
print("YES")
main()
| def main():
# D, Tは文字数カウントするだけだからint型にする必要なし.
n = int(eval(input()))
D = input().split()
m = int(eval(input()))
T = input().split()
dic = dict()
# 辞書はDだけで十分.Counterより速い.
for d in D:
# dic.get(d)と比べると, if in の方が速い.
if d in dic:
dic[d] += 1
else:
dic[d] = 1
for t in T:
if t not in dic or dic[t] == 0:
print("NO")
return
else:
dic[t] -= 1
print("YES")
main()
| false | 8.333333 | [
"+ # D, Tは文字数カウントするだけだからint型にする必要なし.",
"- D = list(map(int, input().split()))",
"+ D = input().split()",
"- T = list(map(int, input().split()))",
"+ T = input().split()",
"+ # dic.get(d)と比べると, if in の方が速い."
] | false | 0.045928 | 0.133252 | 0.34467 | [
"s238018077",
"s455921916"
] |
u823585596 | p03106 | python | s798054864 | s020857073 | 31 | 28 | 9,160 | 9,152 | Accepted | Accepted | 9.68 | A,B,K=list(map(int,input().split()))
count=0
for i in range(max(A,B),0,-1):
if A%i==0 and B%i==0:
count+=1
if count==K:
print(i) | A,B,K=list(map(int,input().split()))
count=0
i=min(A,B)+1
while count<K:
i-=1
if A%i==0 and B%i==0:
count+=1
print(i) | 7 | 8 | 160 | 134 | A, B, K = list(map(int, input().split()))
count = 0
for i in range(max(A, B), 0, -1):
if A % i == 0 and B % i == 0:
count += 1
if count == K:
print(i)
| A, B, K = list(map(int, input().split()))
count = 0
i = min(A, B) + 1
while count < K:
i -= 1
if A % i == 0 and B % i == 0:
count += 1
print(i)
| false | 12.5 | [
"-for i in range(max(A, B), 0, -1):",
"+i = min(A, B) + 1",
"+while count < K:",
"+ i -= 1",
"- if count == K:",
"- print(i)",
"+print(i)"
] | false | 0.042972 | 0.081893 | 0.524733 | [
"s798054864",
"s020857073"
] |
u119148115 | p02834 | python | s234093961 | s969054651 | 280 | 253 | 90,216 | 89,080 | Accepted | Accepted | 9.64 | import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N,u,v = LI()
Graph = [[] for i in range(N+1)]
for i in range(N-1):
a,b = LI()
Graph[a].append(b)
Graph[b].append(a)
from collections import deque
q1 = deque([u])
distance1 = [-1]*(N+1) # uから各頂点への最短距離
distance1[u] = 0
# bfs
while q1:
n = q1.pop()
for d in Graph[n]:
if distance1[d] != -1:
continue
else:
distance1[d] = distance1[n]+1
q1.appendleft(d)
q2 = deque([v])
distance2 = [-1]*(N+1) # vから各頂点への最短距離
distance2[v] = 0
# bfs
while q2:
n = q2.pop()
for d in Graph[n]:
if distance2[d] != -1:
continue
else:
distance2[d] = distance2[n]+1
q2.appendleft(d)
q3 = deque([u])
distance3 = [-1]*(N+1) # uから各頂点への最短距離、ただし青木君に追いつかれない
distance3[u] = 0
# bfs
while q3:
n = q3.pop()
for d in Graph[n]:
if distance3[d] != -1 or distance1[d] >= distance2[d]:
continue
else:
distance3[d] = distance3[n]+1
q3.appendleft(d)
# 青木君に追いつかれずに行ける頂点まで行き、うろうろする
ans = max(distance2[i]-1 for i in range(1,N+1) if distance3[i] >= 0)
print(ans) | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,u,v = MI()
Graph = [[] for _ in range(N+1)]
for i in range(N-1):
a,b = MI()
Graph[a].append(b)
Graph[b].append(a)
dist_T = [-1]*(N+1)
dist_A = [-1]*(N+1)
dist_T[u] = 0
dist_A[v] = 0
from collections import deque
q1 = deque([u])
q2 = deque([v])
while q1:
n = q1.pop()
for d in Graph[n]:
if dist_T[d] == -1:
dist_T[d] = dist_T[n] + 1
q1.appendleft(d)
while q2:
n = q2.pop()
for d in Graph[n]:
if dist_A[d] == -1:
dist_A[d] = dist_A[n] + 1
q2.appendleft(d)
ans = 0
for i in range(1,N+1):
if dist_T[i] < dist_A[i]:
ans = max(ans,dist_A[i]-1)
print(ans)
| 64 | 46 | 1,276 | 1,184 | import sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
N, u, v = LI()
Graph = [[] for i in range(N + 1)]
for i in range(N - 1):
a, b = LI()
Graph[a].append(b)
Graph[b].append(a)
from collections import deque
q1 = deque([u])
distance1 = [-1] * (N + 1) # uから各頂点への最短距離
distance1[u] = 0
# bfs
while q1:
n = q1.pop()
for d in Graph[n]:
if distance1[d] != -1:
continue
else:
distance1[d] = distance1[n] + 1
q1.appendleft(d)
q2 = deque([v])
distance2 = [-1] * (N + 1) # vから各頂点への最短距離
distance2[v] = 0
# bfs
while q2:
n = q2.pop()
for d in Graph[n]:
if distance2[d] != -1:
continue
else:
distance2[d] = distance2[n] + 1
q2.appendleft(d)
q3 = deque([u])
distance3 = [-1] * (N + 1) # uから各頂点への最短距離、ただし青木君に追いつかれない
distance3[u] = 0
# bfs
while q3:
n = q3.pop()
for d in Graph[n]:
if distance3[d] != -1 or distance1[d] >= distance2[d]:
continue
else:
distance3[d] = distance3[n] + 1
q3.appendleft(d)
# 青木君に追いつかれずに行ける頂点まで行き、うろうろする
ans = max(distance2[i] - 1 for i in range(1, N + 1) if distance3[i] >= 0)
print(ans)
| import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N, u, v = MI()
Graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
a, b = MI()
Graph[a].append(b)
Graph[b].append(a)
dist_T = [-1] * (N + 1)
dist_A = [-1] * (N + 1)
dist_T[u] = 0
dist_A[v] = 0
from collections import deque
q1 = deque([u])
q2 = deque([v])
while q1:
n = q1.pop()
for d in Graph[n]:
if dist_T[d] == -1:
dist_T[d] = dist_T[n] + 1
q1.appendleft(d)
while q2:
n = q2.pop()
for d in Graph[n]:
if dist_A[d] == -1:
dist_A[d] = dist_A[n] + 1
q2.appendleft(d)
ans = 0
for i in range(1, N + 1):
if dist_T[i] < dist_A[i]:
ans = max(ans, dist_A[i] - 1)
print(ans)
| false | 28.125 | [
"+",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline().rstrip())",
"+",
"+",
"+def MI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"-N, u, v = LI()",
"-Graph = [[] for i in range(N + 1)]",
"+def LI2():",
"+ return ... | false | 0.049216 | 0.049229 | 0.999739 | [
"s234093961",
"s969054651"
] |
u018679195 | p02711 | python | s812919837 | s800717087 | 72 | 27 | 61,836 | 8,992 | Accepted | Accepted | 62.5 | n = int(eval(input()))
while n!=0:
if n%10 == 7:
print("Yes")
break
n//=10
else:
print("No") | N = eval(input())
condition = False
for i in str(N):
if (i=='7'):
condition = True
if condition:
print("Yes")
else:
print("No")
| 8 | 10 | 121 | 148 | n = int(eval(input()))
while n != 0:
if n % 10 == 7:
print("Yes")
break
n //= 10
else:
print("No")
| N = eval(input())
condition = False
for i in str(N):
if i == "7":
condition = True
if condition:
print("Yes")
else:
print("No")
| false | 20 | [
"-n = int(eval(input()))",
"-while n != 0:",
"- if n % 10 == 7:",
"- print(\"Yes\")",
"- break",
"- n //= 10",
"+N = eval(input())",
"+condition = False",
"+for i in str(N):",
"+ if i == \"7\":",
"+ condition = True",
"+if condition:",
"+ print(\"Yes\")"
] | false | 0.034846 | 0.040426 | 0.861972 | [
"s812919837",
"s800717087"
] |
u879870653 | p03207 | python | s297452272 | s217485144 | 40 | 17 | 3,060 | 2,940 | Accepted | Accepted | 57.5 | N = int(eval(input()))
L = []
for i in range(N) :
l = int(eval(input()))
L.append(l)
L = sorted(L)
L[-1] //= 2
print((sum(L)))
| N = int(eval(input()))
L = sorted([int(eval(input())) for i in range(N)])
ans = sum(L[:-1])+L[-1]//2
print(ans)
| 8 | 4 | 128 | 103 | N = int(eval(input()))
L = []
for i in range(N):
l = int(eval(input()))
L.append(l)
L = sorted(L)
L[-1] //= 2
print((sum(L)))
| N = int(eval(input()))
L = sorted([int(eval(input())) for i in range(N)])
ans = sum(L[:-1]) + L[-1] // 2
print(ans)
| false | 50 | [
"-L = []",
"-for i in range(N):",
"- l = int(eval(input()))",
"- L.append(l)",
"-L = sorted(L)",
"-L[-1] //= 2",
"-print((sum(L)))",
"+L = sorted([int(eval(input())) for i in range(N)])",
"+ans = sum(L[:-1]) + L[-1] // 2",
"+print(ans)"
] | false | 0.042125 | 0.037144 | 1.134114 | [
"s297452272",
"s217485144"
] |
u368796742 | p03645 | python | s224895427 | s856604117 | 704 | 595 | 61,016 | 18,892 | Accepted | Accepted | 15.48 | n,m = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
a = []
b = []
for i in l:
if i[0] == 1:
a.append(i[1])
if i[1] == n:
b.append(i[0])
print(("POSSIBLE" if len(set(a)&set(b)) > 0 else "IMPOSSIBLE")) | n,m = list(map(int,input().split()))
a = set()
b = set()
for i in range(m):
a_,b_ = list(map(int,input().split()))
if a_ == 1:
a.add(b_)
if b_ == n:
b.add(a_)
print(("POSSIBLE" if a&b else "IMPOSSIBLE")) | 12 | 10 | 268 | 226 | n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
a = []
b = []
for i in l:
if i[0] == 1:
a.append(i[1])
if i[1] == n:
b.append(i[0])
print(("POSSIBLE" if len(set(a) & set(b)) > 0 else "IMPOSSIBLE"))
| n, m = list(map(int, input().split()))
a = set()
b = set()
for i in range(m):
a_, b_ = list(map(int, input().split()))
if a_ == 1:
a.add(b_)
if b_ == n:
b.add(a_)
print(("POSSIBLE" if a & b else "IMPOSSIBLE"))
| false | 16.666667 | [
"-l = [list(map(int, input().split())) for i in range(m)]",
"-a = []",
"-b = []",
"-for i in l:",
"- if i[0] == 1:",
"- a.append(i[1])",
"- if i[1] == n:",
"- b.append(i[0])",
"-print((\"POSSIBLE\" if len(set(a) & set(b)) > 0 else \"IMPOSSIBLE\"))",
"+a = set()",
"+b = set()"... | false | 0.047395 | 0.042696 | 1.110062 | [
"s224895427",
"s856604117"
] |
u814271993 | p02614 | python | s312955793 | s095915203 | 79 | 52 | 74,192 | 9,096 | Accepted | Accepted | 34.18 | import itertools
H,W,K=list(map(int,input().split()))
C=[]
for i in range(H):
C.append(eval(input()))
ans=0
for i in range(H+1):
for j in range(W+1):
for n in itertools.combinations(list(range(H)),i):
for m in itertools.combinations(list(range(W)),j):
count = 0
for a in n:
for b in m:
if(C[a][b]=="#"):
count+=1
if(count == K):
ans += 1
print(ans) | import itertools
h,w,n=list(map(int, input().split()))
l=[str(eval(input()))for _ in range(h)]
ans = 0
for i in list(itertools.product([0,1], repeat= h)):
for j in list(itertools.product([0,1], repeat= w)):
b = 0
for k in range(h):
for m in range(w):
if i[k] == 0 and j[m] == 0 and l[k][m] == '#':
b +=1
if b == n:
ans += 1
print(ans) | 21 | 15 | 448 | 425 | import itertools
H, W, K = list(map(int, input().split()))
C = []
for i in range(H):
C.append(eval(input()))
ans = 0
for i in range(H + 1):
for j in range(W + 1):
for n in itertools.combinations(list(range(H)), i):
for m in itertools.combinations(list(range(W)), j):
count = 0
for a in n:
for b in m:
if C[a][b] == "#":
count += 1
if count == K:
ans += 1
print(ans)
| import itertools
h, w, n = list(map(int, input().split()))
l = [str(eval(input())) for _ in range(h)]
ans = 0
for i in list(itertools.product([0, 1], repeat=h)):
for j in list(itertools.product([0, 1], repeat=w)):
b = 0
for k in range(h):
for m in range(w):
if i[k] == 0 and j[m] == 0 and l[k][m] == "#":
b += 1
if b == n:
ans += 1
print(ans)
| false | 28.571429 | [
"-H, W, K = list(map(int, input().split()))",
"-C = []",
"-for i in range(H):",
"- C.append(eval(input()))",
"+h, w, n = list(map(int, input().split()))",
"+l = [str(eval(input())) for _ in range(h)]",
"-for i in range(H + 1):",
"- for j in range(W + 1):",
"- for n in itertools.combinat... | false | 0.1112 | 0.049847 | 2.230841 | [
"s312955793",
"s095915203"
] |
u543954314 | p04028 | python | s895608807 | s467912282 | 964 | 632 | 229,640 | 229,640 | Accepted | Accepted | 34.44 | n = int(eval(input()))
s = len(eval(input()))
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
for j in range(1,n):
dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print((dp[n][s]*rev%mod))
| n = int(eval(input()))
s = len(eval(input()))
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
for j in range(1,min(n,i+1)):
dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print((dp[n][s]*rev%mod))
| 13 | 13 | 348 | 357 | n = int(eval(input()))
s = len(eval(input()))
mod = 10**9 + 7
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod
for j in range(1, n):
dp[i][j] = (dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1]) % mod
dp[i][n] = dp[i - 1][n - 1] * 2 % mod
s2 = pow(2, s, mod)
rev = pow(s2, mod - 2, mod)
print((dp[n][s] * rev % mod))
| n = int(eval(input()))
s = len(eval(input()))
mod = 10**9 + 7
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod
for j in range(1, min(n, i + 1)):
dp[i][j] = (dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1]) % mod
dp[i][n] = dp[i - 1][n - 1] * 2 % mod
s2 = pow(2, s, mod)
rev = pow(s2, mod - 2, mod)
print((dp[n][s] * rev % mod))
| false | 0 | [
"- for j in range(1, n):",
"+ for j in range(1, min(n, i + 1)):"
] | false | 0.100769 | 0.073195 | 1.376719 | [
"s895608807",
"s467912282"
] |
u435974296 | p02887 | python | s745154540 | s069772537 | 794 | 54 | 9,956 | 9,940 | Accepted | Accepted | 93.2 | N=int(eval(input()))
S=list(map(str,eval(input())))
i=0
while i!=(len(S)-1):
if S[i]==S[i+1]:
S.pop(i+1)
else:
i+=1
print((len(S))) | N=int(eval(input()))
S=list(map(str,eval(input())))
ans=1
for i in range(N-1):
if S[i]!=S[i+1]:
ans+=1
print(ans) | 9 | 7 | 149 | 119 | N = int(eval(input()))
S = list(map(str, eval(input())))
i = 0
while i != (len(S) - 1):
if S[i] == S[i + 1]:
S.pop(i + 1)
else:
i += 1
print((len(S)))
| N = int(eval(input()))
S = list(map(str, eval(input())))
ans = 1
for i in range(N - 1):
if S[i] != S[i + 1]:
ans += 1
print(ans)
| false | 22.222222 | [
"-i = 0",
"-while i != (len(S) - 1):",
"- if S[i] == S[i + 1]:",
"- S.pop(i + 1)",
"- else:",
"- i += 1",
"-print((len(S)))",
"+ans = 1",
"+for i in range(N - 1):",
"+ if S[i] != S[i + 1]:",
"+ ans += 1",
"+print(ans)"
] | false | 0.060153 | 0.037573 | 1.600943 | [
"s745154540",
"s069772537"
] |
u802963389 | p03556 | python | s017988940 | s428853560 | 166 | 28 | 38,256 | 2,940 | Accepted | Accepted | 83.13 | import math
n = int(eval(input()))
print((int(math.floor(n ** .5) ** 2))) | n = int(eval(input()))
ans = 1
for i in range(int(n ** .5) + 1):
sq = i ** 2
if sq <= n:
ans = sq
print(ans) | 3 | 7 | 67 | 116 | import math
n = int(eval(input()))
print((int(math.floor(n**0.5) ** 2)))
| n = int(eval(input()))
ans = 1
for i in range(int(n**0.5) + 1):
sq = i**2
if sq <= n:
ans = sq
print(ans)
| false | 57.142857 | [
"-import math",
"-",
"-print((int(math.floor(n**0.5) ** 2)))",
"+ans = 1",
"+for i in range(int(n**0.5) + 1):",
"+ sq = i**2",
"+ if sq <= n:",
"+ ans = sq",
"+print(ans)"
] | false | 0.083416 | 0.130132 | 0.641015 | [
"s017988940",
"s428853560"
] |
u347600233 | p02785 | python | s478861145 | s469651120 | 163 | 111 | 26,180 | 31,544 | Accepted | Accepted | 31.9 | n , k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
h.sort()
count = 0
if k >= n:
print((0))
else:
print((sum(h[0:n - k]))) | n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
print((sum(sorted(h)[:max(0, n - k)]))) | 8 | 3 | 154 | 108 | n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
h.sort()
count = 0
if k >= n:
print((0))
else:
print((sum(h[0 : n - k])))
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
print((sum(sorted(h)[: max(0, n - k)])))
| false | 62.5 | [
"-h = [int(i) for i in input().split()]",
"-h.sort()",
"-count = 0",
"-if k >= n:",
"- print((0))",
"-else:",
"- print((sum(h[0 : n - k])))",
"+h = list(map(int, input().split()))",
"+print((sum(sorted(h)[: max(0, n - k)])))"
] | false | 0.036137 | 0.035602 | 1.015019 | [
"s478861145",
"s469651120"
] |
u704437220 | p02918 | python | s429748834 | s450270620 | 169 | 18 | 39,152 | 3,188 | Accepted | Accepted | 89.35 | if __name__ == '__main__':
N, K = list(map(int, input().split()))
S = eval(input())
# ans = 0
# for i in range(N-1):
# if S[i] == S[i+1]:
# ans += 1
ans = N - 1 - S.count('LR') - S.count('RL')
ans = min(N-1, ans+K*2)
print(ans)
| import sys
if __name__ == '__main__':
N, K = list(map(int, sys.stdin.readline().split()))
S = sys.stdin.readline()
# ans = 0
# for i in range(N-1):
# if S[i] == S[i+1]:
# ans += 1
ans = N - 1 - S.count('LR') - S.count('RL')
ans = min(N-1, ans+K*2)
print(ans)
| 10 | 12 | 273 | 313 | if __name__ == "__main__":
N, K = list(map(int, input().split()))
S = eval(input())
# ans = 0
# for i in range(N-1):
# if S[i] == S[i+1]:
# ans += 1
ans = N - 1 - S.count("LR") - S.count("RL")
ans = min(N - 1, ans + K * 2)
print(ans)
| import sys
if __name__ == "__main__":
N, K = list(map(int, sys.stdin.readline().split()))
S = sys.stdin.readline()
# ans = 0
# for i in range(N-1):
# if S[i] == S[i+1]:
# ans += 1
ans = N - 1 - S.count("LR") - S.count("RL")
ans = min(N - 1, ans + K * 2)
print(ans)
| false | 16.666667 | [
"+import sys",
"+",
"- N, K = list(map(int, input().split()))",
"- S = eval(input())",
"+ N, K = list(map(int, sys.stdin.readline().split()))",
"+ S = sys.stdin.readline()"
] | false | 0.102724 | 0.160004 | 0.642011 | [
"s429748834",
"s450270620"
] |
u240096083 | p02695 | python | s843905596 | s358091497 | 223 | 153 | 95,592 | 91,768 | Accepted | Accepted | 31.39 | from pprint import pprint
n,m,q = list(map(int, input().split()))
ql = [list(map(int,input().split())) for _ in range(q)]
#print(n)
#print(m)
#print(q)
#pprint(ls)
masterlist = []
minilist = [0] * n
i = 0
def saiki(before_a,i,minilist):
if i > n-1:
masterlist.append([minilist[j] for j in range(n)])
return
for Ai in range(before_a,m+1):
minilist[i] = Ai
saiki(Ai,i+1,minilist)
#for before_a in range(1,m+1):
# saiki(before_a,where,minilist)
before_a = 1
saiki(before_a,i,minilist)
#pprint(masterlist)
#pprint(ql)
dmax = 0
for a_mini in masterlist:
dtemp = 0
for ql_mini in ql:
if a_mini[ql_mini[1]-1] - a_mini[ql_mini[0]-1] == ql_mini[2]:
dtemp += ql_mini[3]
else:
pass
if dtemp >= dmax:
dmax = dtemp
print(dmax) | from pprint import pprint
import itertools
n,m,q = list(map(int, input().split()))
ql = [list(map(int,input().split())) for _ in range(q)]
a_lists = list(itertools.combinations_with_replacement(list(range(m)), n))
#print(a_lists)
dmax = 0
for a_mini in a_lists:
dtemp = 0
for ql_mini in ql:
if a_mini[ql_mini[1]-1] - a_mini[ql_mini[0]-1] == ql_mini[2]:
dtemp += ql_mini[3]
else:
pass
if dtemp >= dmax:
dmax = dtemp
print(dmax) | 46 | 27 | 879 | 510 | from pprint import pprint
n, m, q = list(map(int, input().split()))
ql = [list(map(int, input().split())) for _ in range(q)]
# print(n)
# print(m)
# print(q)
# pprint(ls)
masterlist = []
minilist = [0] * n
i = 0
def saiki(before_a, i, minilist):
if i > n - 1:
masterlist.append([minilist[j] for j in range(n)])
return
for Ai in range(before_a, m + 1):
minilist[i] = Ai
saiki(Ai, i + 1, minilist)
# for before_a in range(1,m+1):
# saiki(before_a,where,minilist)
before_a = 1
saiki(before_a, i, minilist)
# pprint(masterlist)
# pprint(ql)
dmax = 0
for a_mini in masterlist:
dtemp = 0
for ql_mini in ql:
if a_mini[ql_mini[1] - 1] - a_mini[ql_mini[0] - 1] == ql_mini[2]:
dtemp += ql_mini[3]
else:
pass
if dtemp >= dmax:
dmax = dtemp
print(dmax)
| from pprint import pprint
import itertools
n, m, q = list(map(int, input().split()))
ql = [list(map(int, input().split())) for _ in range(q)]
a_lists = list(itertools.combinations_with_replacement(list(range(m)), n))
# print(a_lists)
dmax = 0
for a_mini in a_lists:
dtemp = 0
for ql_mini in ql:
if a_mini[ql_mini[1] - 1] - a_mini[ql_mini[0] - 1] == ql_mini[2]:
dtemp += ql_mini[3]
else:
pass
if dtemp >= dmax:
dmax = dtemp
print(dmax)
| false | 41.304348 | [
"+import itertools",
"-# print(n)",
"-# print(m)",
"-# print(q)",
"-# pprint(ls)",
"-masterlist = []",
"-minilist = [0] * n",
"-i = 0",
"-",
"-",
"-def saiki(before_a, i, minilist):",
"- if i > n - 1:",
"- masterlist.append([minilist[j] for j in range(n)])",
"- return",
... | false | 0.106285 | 0.049402 | 2.151411 | [
"s843905596",
"s358091497"
] |
u495903598 | p03290 | python | s349443652 | s635162578 | 36 | 29 | 3,444 | 3,064 | Accepted | Accepted | 19.44 | #!/usr/bin/env python
# coding: utf-8
# In[37]:
d, g = list(map(int, input().split()))
pcs = [list(map(int, input().split()))for _ in range(d)]
"""
2 700
3 500
5 800
2 2000
3 500
5 800
"""
# In[ ]:
"""
完全に解くか、全くとかないかを総当たり
完全に解く問題の総score
総scoreが目標scoreを上回っている
-> 手数を保存
scoreを下回っている
-> 全く解いていない問題の中から 一つ選び、中途半端に解く
scoreを上回る場合
-> 手数に数える
scoreを下回る場合
-> continue
"""
# In[35]:
import math
# In[68]:
temp_str = ''
min_nb = float('inf')
# 完全、完全じゃない、全探索
for i in range(2**d):
#print(i)
score = 0
solved_nb = 0
# j桁目が1の時、j番目のpをscoreに加算
for j in range(d):
if (i>>j) & 1:
score += (j+1) * 100 * pcs[j][0] + pcs[j][1]
temp_str += '{}ten {}mon {}perf : total {}\n'.format((j+1)*100, pcs[j][0], pcs[j][1], score)
solved_nb += pcs[j][0]
# この時点で目標scoreを超えていれば、solved_nbを保存してcontinue
if score >= g:
min_nb = min(min_nb, solved_nb)
#print(temp_str)
continue
# j桁目が0の中から一つ選び、
#temp_score = score
#temp_solved_nb = solved_nb
#print(i)
for j in range(d):
if bin(i>>j)[-1] == '0':
#print('a', j, score)
j_nb = math.ceil((g-score)/((j+1)*100))
score_judge = score + pcs[j][1]*j_nb
#print('b', j_nb, pcs[j][0])
if j_nb <= pcs[j][0]-1 and score_judge > score:
min_nb = min(min_nb, solved_nb+j_nb)
temp_str += '{}ten {}mon: total {}\n'.format((j+1)*100, j_nb, (j+1)*100*j_nb)
#print(temp_str)
#print(temp_str)
print(min_nb)
# In[ ]:
| #!/usr/bin/env python
# coding: utf-8
# In[37]:
d, g = list(map(int, input().split()))
pcs = [list(map(int, input().split()))for _ in range(d)]
"""
2 700
3 500
5 800
2 2000
3 500
5 800
"""
# In[ ]:
"""
完全に解くか、全くとかないかを総当たり
完全に解く問題の総score
総scoreが目標scoreを上回っている
-> 手数を保存
scoreを下回っている
-> 全く解いていない問題の中から 一つ選び、中途半端に解く
scoreを上回る場合
-> 手数に数える
scoreを下回る場合
-> continue
"""
# In[35]:
import math
# In[68]:
temp_str = ''
min_nb = float('inf')
# 完全、完全じゃない、全探索
for i in range(2**d):
#print(i)
score = 0
solved_nb = 0
# j桁目が1の時、j番目のpをscoreに加算
for j in range(d):
if (i>>j) & 1:
score += (j+1) * 100 * pcs[j][0] + pcs[j][1]
#temp_str += '{}ten {}mon {}perf : total {}\n'.format((j+1)*100, pcs[j][0], pcs[j][1], score)
solved_nb += pcs[j][0]
# この時点で目標scoreを超えていれば、solved_nbを保存してcontinue
if score >= g:
min_nb = min(min_nb, solved_nb)
#print(temp_str)
continue
# j桁目が0の中から一つ選び、
#temp_score = score
#temp_solved_nb = solved_nb
#print(i)
for j in range(d):
if bin(i>>j)[-1] == '0':
#print('a', j, score)
j_nb = math.ceil((g-score)/((j+1)*100))
#score_judge = score + pcs[j][1]*j_nb
#print('b', j_nb, pcs[j][0])
if j_nb <= pcs[j][0]-1:
min_nb = min(min_nb, solved_nb+j_nb)
#temp_str += '{}ten {}mon: total {}\n'.format((j+1)*100, j_nb, (j+1)*100*j_nb)
#print(temp_str)
#print(temp_str)
print(min_nb)
# In[ ]:
| 91 | 91 | 1,695 | 1,674 | #!/usr/bin/env python
# coding: utf-8
# In[37]:
d, g = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(d)]
"""
2 700
3 500
5 800
2 2000
3 500
5 800
"""
# In[ ]:
"""
完全に解くか、全くとかないかを総当たり
完全に解く問題の総score
総scoreが目標scoreを上回っている
-> 手数を保存
scoreを下回っている
-> 全く解いていない問題の中から 一つ選び、中途半端に解く
scoreを上回る場合
-> 手数に数える
scoreを下回る場合
-> continue
"""
# In[35]:
import math
# In[68]:
temp_str = ""
min_nb = float("inf")
# 完全、完全じゃない、全探索
for i in range(2**d):
# print(i)
score = 0
solved_nb = 0
# j桁目が1の時、j番目のpをscoreに加算
for j in range(d):
if (i >> j) & 1:
score += (j + 1) * 100 * pcs[j][0] + pcs[j][1]
temp_str += "{}ten {}mon {}perf : total {}\n".format(
(j + 1) * 100, pcs[j][0], pcs[j][1], score
)
solved_nb += pcs[j][0]
# この時点で目標scoreを超えていれば、solved_nbを保存してcontinue
if score >= g:
min_nb = min(min_nb, solved_nb)
# print(temp_str)
continue
# j桁目が0の中から一つ選び、
# temp_score = score
# temp_solved_nb = solved_nb
# print(i)
for j in range(d):
if bin(i >> j)[-1] == "0":
# print('a', j, score)
j_nb = math.ceil((g - score) / ((j + 1) * 100))
score_judge = score + pcs[j][1] * j_nb
# print('b', j_nb, pcs[j][0])
if j_nb <= pcs[j][0] - 1 and score_judge > score:
min_nb = min(min_nb, solved_nb + j_nb)
temp_str += "{}ten {}mon: total {}\n".format(
(j + 1) * 100, j_nb, (j + 1) * 100 * j_nb
)
# print(temp_str)
# print(temp_str)
print(min_nb)
# In[ ]:
| #!/usr/bin/env python
# coding: utf-8
# In[37]:
d, g = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(d)]
"""
2 700
3 500
5 800
2 2000
3 500
5 800
"""
# In[ ]:
"""
完全に解くか、全くとかないかを総当たり
完全に解く問題の総score
総scoreが目標scoreを上回っている
-> 手数を保存
scoreを下回っている
-> 全く解いていない問題の中から 一つ選び、中途半端に解く
scoreを上回る場合
-> 手数に数える
scoreを下回る場合
-> continue
"""
# In[35]:
import math
# In[68]:
temp_str = ""
min_nb = float("inf")
# 完全、完全じゃない、全探索
for i in range(2**d):
# print(i)
score = 0
solved_nb = 0
# j桁目が1の時、j番目のpをscoreに加算
for j in range(d):
if (i >> j) & 1:
score += (j + 1) * 100 * pcs[j][0] + pcs[j][1]
# temp_str += '{}ten {}mon {}perf : total {}\n'.format((j+1)*100, pcs[j][0], pcs[j][1], score)
solved_nb += pcs[j][0]
# この時点で目標scoreを超えていれば、solved_nbを保存してcontinue
if score >= g:
min_nb = min(min_nb, solved_nb)
# print(temp_str)
continue
# j桁目が0の中から一つ選び、
# temp_score = score
# temp_solved_nb = solved_nb
# print(i)
for j in range(d):
if bin(i >> j)[-1] == "0":
# print('a', j, score)
j_nb = math.ceil((g - score) / ((j + 1) * 100))
# score_judge = score + pcs[j][1]*j_nb
# print('b', j_nb, pcs[j][0])
if j_nb <= pcs[j][0] - 1:
min_nb = min(min_nb, solved_nb + j_nb)
# temp_str += '{}ten {}mon: total {}\n'.format((j+1)*100, j_nb, (j+1)*100*j_nb)
# print(temp_str)
# print(temp_str)
print(min_nb)
# In[ ]:
| false | 0 | [
"- temp_str += \"{}ten {}mon {}perf : total {}\\n\".format(",
"- (j + 1) * 100, pcs[j][0], pcs[j][1], score",
"- )",
"+ # temp_str += '{}ten {}mon {}perf : total {}\\n'.format((j+1)*100, pcs[j][0], pcs[j][1], score)",
"- score_judge = score + pcs[j]... | false | 0.035978 | 0.070198 | 0.51252 | [
"s349443652",
"s635162578"
] |
u544050502 | p03494 | python | s839051500 | s390642426 | 26 | 20 | 3,572 | 2,940 | Accepted | Accepted | 23.08 | ##いろいろやってみよう
import functools
def mod(a,b):
c=a%b
return c
N=int(eval(input()))
*A,=list(map(int,input().split()))
count=0
for j in range(len(bin(max(A)))-2):
if 1 in list(map(functools.partial(mod,b=2),A)):
break
else:
A=[A[i]//2 for i in range(N)]
count+=1
print(count) | a=int(eval(input()))
b=list(map(int,input().split()))
counter=0
exist_odd=False
while True:
count=0
while count<=a-1:
if b[count]%2==1:
exist_odd=True
break
else:
b[count]=b[count]//2
count+=1
if exist_odd:
break
else:
counter+=1
print(counter)
| 15 | 19 | 287 | 309 | ##いろいろやってみよう
import functools
def mod(a, b):
c = a % b
return c
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
count = 0
for j in range(len(bin(max(A))) - 2):
if 1 in list(map(functools.partial(mod, b=2), A)):
break
else:
A = [A[i] // 2 for i in range(N)]
count += 1
print(count)
| a = int(eval(input()))
b = list(map(int, input().split()))
counter = 0
exist_odd = False
while True:
count = 0
while count <= a - 1:
if b[count] % 2 == 1:
exist_odd = True
break
else:
b[count] = b[count] // 2
count += 1
if exist_odd:
break
else:
counter += 1
print(counter)
| false | 21.052632 | [
"-##いろいろやってみよう",
"-import functools",
"-",
"-",
"-def mod(a, b):",
"- c = a % b",
"- return c",
"-",
"-",
"-N = int(eval(input()))",
"-(*A,) = list(map(int, input().split()))",
"-count = 0",
"-for j in range(len(bin(max(A))) - 2):",
"- if 1 in list(map(functools.partial(mod, b=2),... | false | 0.042406 | 0.093289 | 0.454569 | [
"s839051500",
"s390642426"
] |
u098012509 | p03438 | python | s435136691 | s348228320 | 41 | 37 | 10,480 | 10,484 | Accepted | Accepted | 9.76 | import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def ceil(x, y):
return -(-x // y)
def main():
N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
sa = sum(B) - sum(A)
x = 0
y = 0
for i in range(N):
if A[i] == B[i]:
continue
elif A[i] > B[i]:
x += A[i] - B[i]
else:
y += ceil(B[i] - A[i], 2)
if x <= sa and y <= sa:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
acnt = 0
bcnt = 0
for i in range(N):
if A[i] == B[i]:
continue
elif A[i] > B[i]:
bcnt += A[i] - B[i]
else:
acnt += -(-(B[i] - A[i]) // 2)
bcnt += (B[i] - A[i]) % 2
if acnt < bcnt:
print("No")
else:
print("Yes")
if __name__ == '__main__':
main()
| 36 | 33 | 608 | 585 | import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def ceil(x, y):
return -(-x // y)
def main():
N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
sa = sum(B) - sum(A)
x = 0
y = 0
for i in range(N):
if A[i] == B[i]:
continue
elif A[i] > B[i]:
x += A[i] - B[i]
else:
y += ceil(B[i] - A[i], 2)
if x <= sa and y <= sa:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
acnt = 0
bcnt = 0
for i in range(N):
if A[i] == B[i]:
continue
elif A[i] > B[i]:
bcnt += A[i] - B[i]
else:
acnt += -(-(B[i] - A[i]) // 2)
bcnt += (B[i] - A[i]) % 2
if acnt < bcnt:
print("No")
else:
print("Yes")
if __name__ == "__main__":
main()
| false | 8.333333 | [
"-def ceil(x, y):",
"- return -(-x // y)",
"-",
"-",
"- sa = sum(B) - sum(A)",
"- x = 0",
"- y = 0",
"+ acnt = 0",
"+ bcnt = 0",
"- x += A[i] - B[i]",
"+ bcnt += A[i] - B[i]",
"- y += ceil(B[i] - A[i], 2)",
"- if x <= sa and y <= sa:",
... | false | 0.115409 | 0.047481 | 2.43064 | [
"s435136691",
"s348228320"
] |
u875291233 | p03164 | python | s365840601 | s934322677 | 397 | 328 | 45,916 | 68,172 | Accepted | Accepted | 17.38 | # coding: utf-8
# Your code here!
n,W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行
V=10**5
MAX=10**12
dp = [MAX]*(V+1)
dp[0]=0
newdp = [MAX]*(V+1)
for i in range(n):
w, v = wv[i]
for j in range(V+1):
newdp[j] = dp[j]
for j in range(V+1):
if j+v <= V:
newdp[j+v] = min(dp[j] + w, newdp[j+v])
newdp, dp = dp, newdp
# print(dp)
print((max([i for i,c in enumerate(dp) if c <= W])))
#print(dp) | # coding: utf-8
# Your code here!
n,W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行
V=10**5
MAX=10**12
dp = [MAX]*(V+1)
dp[0]=0
newdp = [MAX]*(V+1)
for i in range(n):
w, v = wv[i]
newdp = dp[:]
for j in range(V+1):
if j+v <= V:
newdp[j+v] = min(dp[j] + w, newdp[j+v])
newdp, dp = dp, newdp
# print(dp)
print((max([i for i,c in enumerate(dp) if c <= W])))
#print(dp)
| 23 | 23 | 516 | 486 | # coding: utf-8
# Your code here!
n, W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行
V = 10**5
MAX = 10**12
dp = [MAX] * (V + 1)
dp[0] = 0
newdp = [MAX] * (V + 1)
for i in range(n):
w, v = wv[i]
for j in range(V + 1):
newdp[j] = dp[j]
for j in range(V + 1):
if j + v <= V:
newdp[j + v] = min(dp[j] + w, newdp[j + v])
newdp, dp = dp, newdp
# print(dp)
print((max([i for i, c in enumerate(dp) if c <= W])))
# print(dp)
| # coding: utf-8
# Your code here!
n, W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行
V = 10**5
MAX = 10**12
dp = [MAX] * (V + 1)
dp[0] = 0
newdp = [MAX] * (V + 1)
for i in range(n):
w, v = wv[i]
newdp = dp[:]
for j in range(V + 1):
if j + v <= V:
newdp[j + v] = min(dp[j] + w, newdp[j + v])
newdp, dp = dp, newdp
# print(dp)
print((max([i for i, c in enumerate(dp) if c <= W])))
# print(dp)
| false | 0 | [
"- for j in range(V + 1):",
"- newdp[j] = dp[j]",
"+ newdp = dp[:]"
] | false | 0.634331 | 1.296324 | 0.489331 | [
"s365840601",
"s934322677"
] |
u102461423 | p02983 | python | s612266605 | s314039878 | 218 | 152 | 76,128 | 15,828 | Accepted | Accepted | 30.28 | import numpy as np
L,R = (int(x) for x in input().split())
if R - L > 3000:
print((0))
exit()
x = np.arange(L,R+1,dtype=np.int64)
y = x[:,None] * x[None,:] % 2019
for i in range(len(x)):
y[i,i] = 3000
answer = y.min()
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
L,R = list(map(int,read().split()))
if R-L > 1000:
print((0))
exit()
x = np.arange(L,R+1)
x = x[:,None] * x[None,:] % 2019
np.fill_diagonal(x,2019)
answer = x.min()
print(answer) | 13 | 17 | 251 | 332 | import numpy as np
L, R = (int(x) for x in input().split())
if R - L > 3000:
print((0))
exit()
x = np.arange(L, R + 1, dtype=np.int64)
y = x[:, None] * x[None, :] % 2019
for i in range(len(x)):
y[i, i] = 3000
answer = y.min()
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
L, R = list(map(int, read().split()))
if R - L > 1000:
print((0))
exit()
x = np.arange(L, R + 1)
x = x[:, None] * x[None, :] % 2019
np.fill_diagonal(x, 2019)
answer = x.min()
print(answer)
| false | 23.529412 | [
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"-L, R = (int(x) for x in input().split())",
"-if R - L > 3000:",
"+L, R = list(map(int, read().split()))",
"+if R - L > 1000:",
"-x = np.arange(L, R + 1, dtype=... | false | 0.590056 | 0.286923 | 2.056498 | [
"s612266605",
"s314039878"
] |
u814781830 | p02866 | python | s724424675 | s290450431 | 121 | 104 | 19,936 | 14,780 | Accepted | Accepted | 14.05 | from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
def calc():
if D[0] != 0:
return 0
if sum(D) < N-1:
return 0
c = Counter(D)
ret = 1
tmpkey = 0
tmpvalue = 0
for key in sorted(c.keys()):
if key - tmpkey >= 2:
return 0
if key == 0:
if c[key] >= 2:
return 0
else:
ret *= (tmpvalue ** c[key]) % MOD
ret %= MOD
tmpkey = key
tmpvalue = c[key]
return ret
print((calc()))
| from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく
count = [0] * N
for d in D:
count[d] += 1
def calc():
if D[0] != 0:
return 0
ret = 1
for i in range(N):
if i == 0:
if count[i] >= 2:
return 0
else:
ret *= (count[i-1] ** count[i]) % MOD
ret %= MOD
return ret
print((calc()))
| 29 | 24 | 601 | 483 | from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
def calc():
if D[0] != 0:
return 0
if sum(D) < N - 1:
return 0
c = Counter(D)
ret = 1
tmpkey = 0
tmpvalue = 0
for key in sorted(c.keys()):
if key - tmpkey >= 2:
return 0
if key == 0:
if c[key] >= 2:
return 0
else:
ret *= (tmpvalue ** c[key]) % MOD
ret %= MOD
tmpkey = key
tmpvalue = c[key]
return ret
print((calc()))
| from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく
count = [0] * N
for d in D:
count[d] += 1
def calc():
if D[0] != 0:
return 0
ret = 1
for i in range(N):
if i == 0:
if count[i] >= 2:
return 0
else:
ret *= (count[i - 1] ** count[i]) % MOD
ret %= MOD
return ret
print((calc()))
| false | 17.241379 | [
"+# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく",
"+count = [0] * N",
"+for d in D:",
"+ count[d] += 1",
"- if sum(D) < N - 1:",
"- return 0",
"- c = Counter(D)",
"- tmpkey = 0",
"- tmpvalue = 0",
"- for key in sorted(c.keys()):",
"- if key - tmpkey >= 2:",
"- ... | false | 0.121132 | 0.008668 | 13.97391 | [
"s724424675",
"s290450431"
] |
u905203728 | p02861 | python | s968553772 | s323255524 | 479 | 216 | 3,188 | 41,196 | Accepted | Accepted | 54.91 | from itertools import permutations
from math import factorial
n=int(eval(input()))
A=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in permutations(A,n):
for j in range(1,n):
cnt +=((i[j-1][0]-i[j][0])**2+(i[j-1][1]-i[j][1])**2)**0.5
print((cnt/factorial(n))) | from itertools import permutations
from math import factorial
n=int(eval(input()))
XY=[list(map(int,input().split())) for _ in range(n)]
ans=0
for A in permutations(XY,n):
cnt=0
for j in range(n-1):
cnt +=((A[j][0]-A[j+1][0])**2+(A[j][1]-A[j+1][1])**2)**0.5
ans +=cnt
print((ans/factorial(n))) | 10 | 12 | 289 | 317 | from itertools import permutations
from math import factorial
n = int(eval(input()))
A = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in permutations(A, n):
for j in range(1, n):
cnt += ((i[j - 1][0] - i[j][0]) ** 2 + (i[j - 1][1] - i[j][1]) ** 2) ** 0.5
print((cnt / factorial(n)))
| from itertools import permutations
from math import factorial
n = int(eval(input()))
XY = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for A in permutations(XY, n):
cnt = 0
for j in range(n - 1):
cnt += ((A[j][0] - A[j + 1][0]) ** 2 + (A[j][1] - A[j + 1][1]) ** 2) ** 0.5
ans += cnt
print((ans / factorial(n)))
| false | 16.666667 | [
"-A = [list(map(int, input().split())) for i in range(n)]",
"-cnt = 0",
"-for i in permutations(A, n):",
"- for j in range(1, n):",
"- cnt += ((i[j - 1][0] - i[j][0]) ** 2 + (i[j - 1][1] - i[j][1]) ** 2) ** 0.5",
"-print((cnt / factorial(n)))",
"+XY = [list(map(int, input().split())) for _ in ... | false | 0.03567 | 0.034758 | 1.026224 | [
"s968553772",
"s323255524"
] |
u745087332 | p03244 | python | s287629368 | s549458288 | 1,019 | 90 | 32,156 | 17,428 | Accepted | Accepted | 91.17 | # coding:utf-8
import numpy as np
INF = float('inf')
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
V = inpl()
A = [0 for _ in range(10**5+1)]
for i in range(0, N, 2):
A[V[i]] += 1
B = [0 for _ in range(10**5+1)]
for i in range(1, N, 2):
B[V[i]] += 1
A = np.array(A)
B = np.array(B)
if A.argmax() == B.argmax():
A.sort()
B.sort()
tmp = max(A[-1] + B[-2] , A[-2] + B[-1])
ans = N - tmp
else:
A.sort()
B.sort()
ans = N - A[-1] - B[-1]
print(ans)
| # coding:utf-8
import sys
from collections import Counter
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
def solve(N, V):
v_even = [V[i] for i in range(0, N, 2)]
v_odd = [V[i] for i in range(1, N, 2)]
# 出現回数の多い上位2つの要素と出現回数を取得
v_even_most = Counter(v_even).most_common()[:2]
v_odd_most = Counter(v_odd).most_common()[:2]
# 最頻値が被っていなければそのまま採用
if v_even_most[0][0] != v_odd_most[0][0]:
return N - v_even_most[0][1] - v_odd_most[0][1]
else:
# 数字が1種類しか登場しない場合は、0を追加
# list index out of range対策
if len(v_even_most) == 1 or len(v_odd_most) == 1:
v_even_most.append((0, 0))
v_odd_most.append((0, 0))
# 書き換え回数が少ない方を採用
return N - max(v_even_most[0][1] + v_odd_most[1][1],
v_even_most[1][1] + v_odd_most[0][1])
N = int(eval(input()))
V = inpl()
print((solve(N, V)))
| 36 | 38 | 548 | 954 | # coding:utf-8
import numpy as np
INF = float("inf")
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
V = inpl()
A = [0 for _ in range(10**5 + 1)]
for i in range(0, N, 2):
A[V[i]] += 1
B = [0 for _ in range(10**5 + 1)]
for i in range(1, N, 2):
B[V[i]] += 1
A = np.array(A)
B = np.array(B)
if A.argmax() == B.argmax():
A.sort()
B.sort()
tmp = max(A[-1] + B[-2], A[-2] + B[-1])
ans = N - tmp
else:
A.sort()
B.sort()
ans = N - A[-1] - B[-1]
print(ans)
| # coding:utf-8
import sys
from collections import Counter
input = sys.stdin.readline
def inpl():
return list(map(int, input().split()))
def solve(N, V):
v_even = [V[i] for i in range(0, N, 2)]
v_odd = [V[i] for i in range(1, N, 2)]
# 出現回数の多い上位2つの要素と出現回数を取得
v_even_most = Counter(v_even).most_common()[:2]
v_odd_most = Counter(v_odd).most_common()[:2]
# 最頻値が被っていなければそのまま採用
if v_even_most[0][0] != v_odd_most[0][0]:
return N - v_even_most[0][1] - v_odd_most[0][1]
else:
# 数字が1種類しか登場しない場合は、0を追加
# list index out of range対策
if len(v_even_most) == 1 or len(v_odd_most) == 1:
v_even_most.append((0, 0))
v_odd_most.append((0, 0))
# 書き換え回数が少ない方を採用
return N - max(
v_even_most[0][1] + v_odd_most[1][1], v_even_most[1][1] + v_odd_most[0][1]
)
N = int(eval(input()))
V = inpl()
print((solve(N, V)))
| false | 5.263158 | [
"-import numpy as np",
"+import sys",
"+from collections import Counter",
"-INF = float(\"inf\")",
"+input = sys.stdin.readline",
"+def solve(N, V):",
"+ v_even = [V[i] for i in range(0, N, 2)]",
"+ v_odd = [V[i] for i in range(1, N, 2)]",
"+ # 出現回数の多い上位2つの要素と出現回数を取得",
"+ v_even_most =... | false | 0.355807 | 0.0464 | 7.668297 | [
"s287629368",
"s549458288"
] |
u179070318 | p02398 | python | s122963362 | s460779053 | 70 | 20 | 5,716 | 5,604 | Accepted | Accepted | 71.43 | a,b,c = [int(x) for x in input().split( )]
div = []
for x in range(1,c+1):
if c % x == 0:
div.append(x)
r = []
for x in range(a,b+1):
r.append(x)
answer = 0
for x in div:
for y in r:
if x == y:
answer += 1
print(answer)
| a,b,c = [int(x) for x in input().split( )]
count = 0
for number in range(a,b+1):
if c % number == 0:
count += 1
print(count)
| 14 | 6 | 273 | 142 | a, b, c = [int(x) for x in input().split()]
div = []
for x in range(1, c + 1):
if c % x == 0:
div.append(x)
r = []
for x in range(a, b + 1):
r.append(x)
answer = 0
for x in div:
for y in r:
if x == y:
answer += 1
print(answer)
| a, b, c = [int(x) for x in input().split()]
count = 0
for number in range(a, b + 1):
if c % number == 0:
count += 1
print(count)
| false | 57.142857 | [
"-div = []",
"-for x in range(1, c + 1):",
"- if c % x == 0:",
"- div.append(x)",
"-r = []",
"-for x in range(a, b + 1):",
"- r.append(x)",
"-answer = 0",
"-for x in div:",
"- for y in r:",
"- if x == y:",
"- answer += 1",
"-print(answer)",
"+count = 0",
... | false | 0.037168 | 0.079811 | 0.465694 | [
"s122963362",
"s460779053"
] |
u227082700 | p02788 | python | s995268982 | s536050412 | 1,699 | 1,490 | 102,744 | 62,872 | Accepted | Accepted | 12.3 | from bisect import bisect_right
n,d,a=list(map(int,input().split()))
xh=[list(map(int,input().split()))for _ in range(n)]
xh.sort()
x=[]
h=[]
for xx,hh in xh:
x.append(xx)
h.append(hh)
not_imos=[0]*(n+1)
atk_n=0
ans=0
for i in range(n):
atk_n-=not_imos[i]
h[i]-=atk_n*a
if h[i]<0:h[i]=0
atk_i=0--h[i]//a
ans+=atk_i
atk_n+=atk_i
not_imos[bisect_right(x,x[i]+d*2)]+=atk_i
print(ans) | n,d,a=list(map(int,input().split()))
d*=2
xh=[list(map(int,input().split()))for _ in range(n)]
xh.sort()
x=[i for i,j in xh]+[10**20]
h=[j for i,j in xh]
notimos=[0]*(n+1)
c=0
ans=0
from bisect import bisect_right
for i in range(n):
c+=notimos[i]
xx,hh=xh[i]
hh=max(0,hh-c*a)
m=0--hh//a
ans+=m
c+=m
notimos[bisect_right(x,xx+d)]-=m
print(ans) | 22 | 19 | 414 | 368 | from bisect import bisect_right
n, d, a = list(map(int, input().split()))
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()
x = []
h = []
for xx, hh in xh:
x.append(xx)
h.append(hh)
not_imos = [0] * (n + 1)
atk_n = 0
ans = 0
for i in range(n):
atk_n -= not_imos[i]
h[i] -= atk_n * a
if h[i] < 0:
h[i] = 0
atk_i = 0 - -h[i] // a
ans += atk_i
atk_n += atk_i
not_imos[bisect_right(x, x[i] + d * 2)] += atk_i
print(ans)
| n, d, a = list(map(int, input().split()))
d *= 2
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()
x = [i for i, j in xh] + [10**20]
h = [j for i, j in xh]
notimos = [0] * (n + 1)
c = 0
ans = 0
from bisect import bisect_right
for i in range(n):
c += notimos[i]
xx, hh = xh[i]
hh = max(0, hh - c * a)
m = 0 - -hh // a
ans += m
c += m
notimos[bisect_right(x, xx + d)] -= m
print(ans)
| false | 13.636364 | [
"+n, d, a = list(map(int, input().split()))",
"+d *= 2",
"+xh = [list(map(int, input().split())) for _ in range(n)]",
"+xh.sort()",
"+x = [i for i, j in xh] + [10**20]",
"+h = [j for i, j in xh]",
"+notimos = [0] * (n + 1)",
"+c = 0",
"+ans = 0",
"-n, d, a = list(map(int, input().split()))",
"-x... | false | 0.045307 | 0.045825 | 0.988694 | [
"s995268982",
"s536050412"
] |
u922449550 | p02821 | python | s706848742 | s016056017 | 1,128 | 928 | 14,020 | 16,996 | Accepted | Accepted | 17.73 | import bisect
N, M = list(map(int, input().split()))
Al = list(map(int, input().split()))
Al.sort() # 左手で握手する人のリスト
Ar = Al.copy()[::-1] # 右手で握手する人のリスト
def count_large_2(L1, L2, x):
# L1.sort()
# L2.sort(reverse=True)
N1, N2 = len(L1), len(L2)
i = j = 0
c = 0
while i<N1 and j<N2:
if L1[i]+L2[j] >= x:
c += 1
j += 1
if j >= N2:
c += (N1-i-1) * N2
else:
i += 1
if i>=N1:
continue
c += j
return c
left = 0 # True
right = Al[-1]*2 + 1 # False
while left+1 < right:
mid = (left + right) // 2
if count_large_2(Al, Ar, mid) >= M:
left = mid
else:
right = mid
x = left
accum_A = [Ar[0]]
for i, a in enumerate(Ar):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2*10**5
for ai in Ar:
idx = bisect.bisect_left(Al, x-ai)
if idx == N:
break
ans += (N-idx)*ai + accum_A[N-idx-1]
count += N - idx
surplus = min(surplus, ai+Al[idx])
print((ans - (count-M)*surplus)) | import bisect
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# ある値以上のAiがいくつあるかの情報を累積和で保持
num_A_or_more = [0]*(10**5)
for a in A:
num_A_or_more[a-1] += 1
for i in range(1, 10**5):
j = 10**5 - i
num_A_or_more[j-1] += num_A_or_more[j]
# x以上となる手の組み合わせがM種類以上あるかどうかを判定
def check(x):
count = 0
for a in A:
idx = max(x-a-1, 0)
if idx >= 10**5:
continue
count += num_A_or_more[idx]
return count>=M
# 2分探索でM種類以上の手の組み合わせがある満足度の最大値を求める
left = 0
right = 2*10**5 + 1
mid = (left + right) // 2
while right - left > 1:
if check(mid):
left = mid
else:
right = mid
mid = (left + right)//2
# これがM種類以上の手の組み合わせがある満足度の最大値
x = left
# 降順に並べなおして累積和を求めておく
rev_A = A[::-1]
accum_A = [rev_A[0]]
for i, a in enumerate(rev_A):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2*10**5 # M種類を超えた場合は、一番小さくなる握手の組を最後に削る
for ai in rev_A:
idx = bisect.bisect_left(A, x-ai)
if idx == N:
break
ans += (N-idx)*ai + accum_A[N-idx-1]
count += N - idx
surplus = min(surplus, ai+A[idx])
print((ans - (count-M)*surplus)) | 58 | 66 | 1,054 | 1,188 | import bisect
N, M = list(map(int, input().split()))
Al = list(map(int, input().split()))
Al.sort() # 左手で握手する人のリスト
Ar = Al.copy()[::-1] # 右手で握手する人のリスト
def count_large_2(L1, L2, x):
# L1.sort()
# L2.sort(reverse=True)
N1, N2 = len(L1), len(L2)
i = j = 0
c = 0
while i < N1 and j < N2:
if L1[i] + L2[j] >= x:
c += 1
j += 1
if j >= N2:
c += (N1 - i - 1) * N2
else:
i += 1
if i >= N1:
continue
c += j
return c
left = 0 # True
right = Al[-1] * 2 + 1 # False
while left + 1 < right:
mid = (left + right) // 2
if count_large_2(Al, Ar, mid) >= M:
left = mid
else:
right = mid
x = left
accum_A = [Ar[0]]
for i, a in enumerate(Ar):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2 * 10**5
for ai in Ar:
idx = bisect.bisect_left(Al, x - ai)
if idx == N:
break
ans += (N - idx) * ai + accum_A[N - idx - 1]
count += N - idx
surplus = min(surplus, ai + Al[idx])
print((ans - (count - M) * surplus))
| import bisect
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# ある値以上のAiがいくつあるかの情報を累積和で保持
num_A_or_more = [0] * (10**5)
for a in A:
num_A_or_more[a - 1] += 1
for i in range(1, 10**5):
j = 10**5 - i
num_A_or_more[j - 1] += num_A_or_more[j]
# x以上となる手の組み合わせがM種類以上あるかどうかを判定
def check(x):
count = 0
for a in A:
idx = max(x - a - 1, 0)
if idx >= 10**5:
continue
count += num_A_or_more[idx]
return count >= M
# 2分探索でM種類以上の手の組み合わせがある満足度の最大値を求める
left = 0
right = 2 * 10**5 + 1
mid = (left + right) // 2
while right - left > 1:
if check(mid):
left = mid
else:
right = mid
mid = (left + right) // 2
# これがM種類以上の手の組み合わせがある満足度の最大値
x = left
# 降順に並べなおして累積和を求めておく
rev_A = A[::-1]
accum_A = [rev_A[0]]
for i, a in enumerate(rev_A):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2 * 10**5 # M種類を超えた場合は、一番小さくなる握手の組を最後に削る
for ai in rev_A:
idx = bisect.bisect_left(A, x - ai)
if idx == N:
break
ans += (N - idx) * ai + accum_A[N - idx - 1]
count += N - idx
surplus = min(surplus, ai + A[idx])
print((ans - (count - M) * surplus))
| false | 12.121212 | [
"-Al = list(map(int, input().split()))",
"-Al.sort() # 左手で握手する人のリスト",
"-Ar = Al.copy()[::-1] # 右手で握手する人のリスト",
"+A = list(map(int, input().split()))",
"+A.sort()",
"+# ある値以上のAiがいくつあるかの情報を累積和で保持",
"+num_A_or_more = [0] * (10**5)",
"+for a in A:",
"+ num_A_or_more[a - 1] += 1",
"+for i in range(... | false | 0.047231 | 0.111447 | 0.423793 | [
"s706848742",
"s016056017"
] |
u888092736 | p03487 | python | s142930522 | s537955035 | 84 | 72 | 18,676 | 22,124 | Accepted | Accepted | 14.29 | from collections import Counter
N = int(eval(input()))
cntr = Counter(list(map(int, input().split())))
ans = 0
for k, v in list(cntr.items()):
if k > v:
ans += v
else:
ans += v - k
print(ans)
| from collections import Counter
N, *A = list(map(int, open(0).read().split()))
cnt = Counter(A)
ans = 0
for k, v in list(cnt.items()):
if k > v:
ans += v
else:
ans += v - k
print(ans)
| 12 | 11 | 217 | 207 | from collections import Counter
N = int(eval(input()))
cntr = Counter(list(map(int, input().split())))
ans = 0
for k, v in list(cntr.items()):
if k > v:
ans += v
else:
ans += v - k
print(ans)
| from collections import Counter
N, *A = list(map(int, open(0).read().split()))
cnt = Counter(A)
ans = 0
for k, v in list(cnt.items()):
if k > v:
ans += v
else:
ans += v - k
print(ans)
| false | 8.333333 | [
"-N = int(eval(input()))",
"-cntr = Counter(list(map(int, input().split())))",
"+N, *A = list(map(int, open(0).read().split()))",
"+cnt = Counter(A)",
"-for k, v in list(cntr.items()):",
"+for k, v in list(cnt.items()):"
] | false | 0.039267 | 0.047944 | 0.819025 | [
"s142930522",
"s537955035"
] |
u536113865 | p03764 | python | s311705918 | s717957174 | 207 | 132 | 31,040 | 31,168 | Accepted | Accepted | 36.23 | ai = lambda: list(map(int, input().split()))
n,m = ai()
x = ai()
y = ai()
mod = 10**9+7
ans = 0
sx,ssx,sy,ssy = [x[0]], [x[-1]], [y[0]], [y[-1]]
for i in range(1, n):
sx.append(sx[-1] + x[i])
ssx.append(ssx[-1] + x[-i-1])
for i in range(1, m):
sy.append(sy[-1] + y[i])
ssy.append(ssy[-1] + y[-i-1])
a = sum(ssx[i] - sx[i] for i in range(n)) % mod
b = sum(ssy[i] - sy[i] for i in range(m)) % mod
ans = a*b % mod
print(ans) | ai = lambda: list(map(int, input().split()))
n,m = ai()
x = ai()
y = ai()
mod = 10**9+7
from itertools import accumulate as acc
sx = list(acc(x))
ssx = list(acc(x[::-1]))
sy = list(acc(y))
ssy = list(acc(y[::-1]))
a = sum(ssx[i] - sx[i] for i in range(n)) % mod
b = sum(ssy[i] - sy[i] for i in range(m)) % mod
print((a*b % mod)) | 21 | 18 | 461 | 352 | ai = lambda: list(map(int, input().split()))
n, m = ai()
x = ai()
y = ai()
mod = 10**9 + 7
ans = 0
sx, ssx, sy, ssy = [x[0]], [x[-1]], [y[0]], [y[-1]]
for i in range(1, n):
sx.append(sx[-1] + x[i])
ssx.append(ssx[-1] + x[-i - 1])
for i in range(1, m):
sy.append(sy[-1] + y[i])
ssy.append(ssy[-1] + y[-i - 1])
a = sum(ssx[i] - sx[i] for i in range(n)) % mod
b = sum(ssy[i] - sy[i] for i in range(m)) % mod
ans = a * b % mod
print(ans)
| ai = lambda: list(map(int, input().split()))
n, m = ai()
x = ai()
y = ai()
mod = 10**9 + 7
from itertools import accumulate as acc
sx = list(acc(x))
ssx = list(acc(x[::-1]))
sy = list(acc(y))
ssy = list(acc(y[::-1]))
a = sum(ssx[i] - sx[i] for i in range(n)) % mod
b = sum(ssy[i] - sy[i] for i in range(m)) % mod
print((a * b % mod))
| false | 14.285714 | [
"-ans = 0",
"-sx, ssx, sy, ssy = [x[0]], [x[-1]], [y[0]], [y[-1]]",
"-for i in range(1, n):",
"- sx.append(sx[-1] + x[i])",
"- ssx.append(ssx[-1] + x[-i - 1])",
"-for i in range(1, m):",
"- sy.append(sy[-1] + y[i])",
"- ssy.append(ssy[-1] + y[-i - 1])",
"+from itertools import accumulate... | false | 0.048575 | 0.123314 | 0.393916 | [
"s311705918",
"s717957174"
] |
u471078637 | p03163 | python | s719843361 | s001733422 | 651 | 596 | 171,528 | 171,400 | Accepted | Accepted | 8.45 | n,tw = list(map(int, input().split()))
wt = []; val = []
for i in range(n):
a,b = list(map(int, input().split()))
wt.append(a); val.append(b)
dp = [[0 for i in range(tw+1)] for j in range(n+1)]
for i in range(n):
for j in range(1,tw+1):
if j < wt[i]:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j], val[i]+dp[i][j-wt[i]])
print((dp[n][tw]))
| def ks(n, W, arr):
dp = [[0 for i in range(W+1)] for j in range(n+1)]
for i in range(1,n+1):
for j in range(1,W+1):
if arr[i-1][0] > j:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j], dp[i-1][j-arr[i-1][0]]+arr[i-1][1])
return dp[n][W]
if __name__ == "__main__":
n, W = list(map(int, input().split()))
arr = []
for i in range(n):
w,v = list(map(int, input().split()))
arr.append([w,v])
arr.sort(key = lambda x:x[0])
ans = ks(n,W,arr)
print(ans)
| 13 | 19 | 403 | 575 | n, tw = list(map(int, input().split()))
wt = []
val = []
for i in range(n):
a, b = list(map(int, input().split()))
wt.append(a)
val.append(b)
dp = [[0 for i in range(tw + 1)] for j in range(n + 1)]
for i in range(n):
for j in range(1, tw + 1):
if j < wt[i]:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], val[i] + dp[i][j - wt[i]])
print((dp[n][tw]))
| def ks(n, W, arr):
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, W + 1):
if arr[i - 1][0] > j:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = max(
dp[i - 1][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1]
)
return dp[n][W]
if __name__ == "__main__":
n, W = list(map(int, input().split()))
arr = []
for i in range(n):
w, v = list(map(int, input().split()))
arr.append([w, v])
arr.sort(key=lambda x: x[0])
ans = ks(n, W, arr)
print(ans)
| false | 31.578947 | [
"-n, tw = list(map(int, input().split()))",
"-wt = []",
"-val = []",
"-for i in range(n):",
"- a, b = list(map(int, input().split()))",
"- wt.append(a)",
"- val.append(b)",
"-dp = [[0 for i in range(tw + 1)] for j in range(n + 1)]",
"-for i in range(n):",
"- for j in range(1, tw + 1):"... | false | 0.127678 | 0.091289 | 1.39862 | [
"s719843361",
"s001733422"
] |
u832039789 | p03846 | python | s278806225 | s626833995 | 117 | 93 | 14,260 | 14,004 | Accepted | Accepted | 20.51 | import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
g = itertools.groupby(sorted(a))
for i,(k,v) in enumerate(g):
if n%2==1:
f1 = i==0 and k==0 and len(list(v))==1
f2 = i!=0 and k==i*2 and len(list(v))==2
if not (f1 or f2):
print((0))
exit()
else:
if k!=2*i+1 or len(list(v))!=2:
print((0))
exit()
print(((2**(n//2))%(10**9+7)))
| n = int(eval(input()))
a = list(map(int,input().split()))
MOD = 10**9+7
arr = []
if n%2==0:
for i in range(1,n,2):
arr += [i,i]
else:
arr += [0]
for i in range(2,n,2):
arr += [i,i]
if sorted(a)!=sorted(arr):
print((0))
exit()
print((pow(2,n//2,MOD)))
| 16 | 18 | 443 | 297 | import itertools
n = int(eval(input()))
a = list(map(int, input().split()))
g = itertools.groupby(sorted(a))
for i, (k, v) in enumerate(g):
if n % 2 == 1:
f1 = i == 0 and k == 0 and len(list(v)) == 1
f2 = i != 0 and k == i * 2 and len(list(v)) == 2
if not (f1 or f2):
print((0))
exit()
else:
if k != 2 * i + 1 or len(list(v)) != 2:
print((0))
exit()
print(((2 ** (n // 2)) % (10**9 + 7)))
| n = int(eval(input()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
arr = []
if n % 2 == 0:
for i in range(1, n, 2):
arr += [i, i]
else:
arr += [0]
for i in range(2, n, 2):
arr += [i, i]
if sorted(a) != sorted(arr):
print((0))
exit()
print((pow(2, n // 2, MOD)))
| false | 11.111111 | [
"-import itertools",
"-",
"-g = itertools.groupby(sorted(a))",
"-for i, (k, v) in enumerate(g):",
"- if n % 2 == 1:",
"- f1 = i == 0 and k == 0 and len(list(v)) == 1",
"- f2 = i != 0 and k == i * 2 and len(list(v)) == 2",
"- if not (f1 or f2):",
"- print((0))",
"... | false | 0.037385 | 0.079588 | 0.469727 | [
"s278806225",
"s626833995"
] |
u383828019 | p03240 | python | s830595334 | s859692548 | 676 | 37 | 3,956 | 3,064 | Accepted | Accepted | 94.53 | n = int(eval(input()))
points = []
center = True
centercount = 0
centers = []
for i in range(n):
points.append([int(x) for x in input().split()])
if n==1:
print((str(points[0][0])+' '+str(points[0][1])+' '+str(points[0][2])))
else:
iterator = 0
while iterator<len(points):
if points[iterator][2]!=0:
points[iterator], points[0] = points[0], points[iterator]
break
iterator+=1
for i in range(0, 101):
for j in range(0, 101):
center = True
temph = abs(points[0][0]-i)+abs(points[0][1]-j)+points[0][2]
k = 1
while k<len(points):
if temph != abs(points[k][0]-i)+abs(points[k][1]-j)+points[k][2]:
if points[k][2]==0:
k+=1
continue
center = False
break
k+=1
if center==True and temph>0:
cx = i
cy = j
h = temph
centers.append([cx, cy, h])
centercount+=1
#break
if centercount==1:
print((str(cx) + ' ' + str(cy) + ' ' + str(h)))
else:
print('32 68 1')
#print(0)
| n = int(eval(input()))
points = []
center = True
for i in range(n):
points.append([int(x) for x in input().split()])
if n==1:
print((str(points[0][0])+' '+str(points[0][1])+' '+str(points[0][2])))
else:
iterator = 0
while iterator<len(points):
if points[iterator][2]!=0:
points[iterator], points[0] = points[0], points[iterator]
break
iterator+=1
for i in range(0, 101):
for j in range(0, 101):
center = True
temph = abs(points[0][0]-i)+abs(points[0][1]-j)+points[0][2]
k = 1
while k<len(points):
if points[k][2]!=max(0, temph-abs(points[k][0]-i)-abs(points[k][1]-j)):
center = False
break
k+=1
if center==True:
cx = i
cy = j
h = temph
break
print((str(cx) + ' ' + str(cy) + ' ' + str(h)))
| 42 | 31 | 1,085 | 845 | n = int(eval(input()))
points = []
center = True
centercount = 0
centers = []
for i in range(n):
points.append([int(x) for x in input().split()])
if n == 1:
print((str(points[0][0]) + " " + str(points[0][1]) + " " + str(points[0][2])))
else:
iterator = 0
while iterator < len(points):
if points[iterator][2] != 0:
points[iterator], points[0] = points[0], points[iterator]
break
iterator += 1
for i in range(0, 101):
for j in range(0, 101):
center = True
temph = abs(points[0][0] - i) + abs(points[0][1] - j) + points[0][2]
k = 1
while k < len(points):
if (
temph
!= abs(points[k][0] - i) + abs(points[k][1] - j) + points[k][2]
):
if points[k][2] == 0:
k += 1
continue
center = False
break
k += 1
if center == True and temph > 0:
cx = i
cy = j
h = temph
centers.append([cx, cy, h])
centercount += 1
# break
if centercount == 1:
print((str(cx) + " " + str(cy) + " " + str(h)))
else:
print("32 68 1")
# print(0)
| n = int(eval(input()))
points = []
center = True
for i in range(n):
points.append([int(x) for x in input().split()])
if n == 1:
print((str(points[0][0]) + " " + str(points[0][1]) + " " + str(points[0][2])))
else:
iterator = 0
while iterator < len(points):
if points[iterator][2] != 0:
points[iterator], points[0] = points[0], points[iterator]
break
iterator += 1
for i in range(0, 101):
for j in range(0, 101):
center = True
temph = abs(points[0][0] - i) + abs(points[0][1] - j) + points[0][2]
k = 1
while k < len(points):
if points[k][2] != max(
0, temph - abs(points[k][0] - i) - abs(points[k][1] - j)
):
center = False
break
k += 1
if center == True:
cx = i
cy = j
h = temph
break
print((str(cx) + " " + str(cy) + " " + str(h)))
| false | 26.190476 | [
"-centercount = 0",
"-centers = []",
"- if (",
"- temph",
"- != abs(points[k][0] - i) + abs(points[k][1] - j) + points[k][2]",
"+ if points[k][2] != max(",
"+ 0, temph - abs(points[k][0] - i) - abs(points[k][1] - j)",... | false | 0.093662 | 0.007299 | 12.83278 | [
"s830595334",
"s859692548"
] |
u197955752 | p02744 | python | s491454822 | s199345990 | 548 | 191 | 166,636 | 22,772 | Accepted | Accepted | 65.15 | from collections import deque
N = int(eval(input()))
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
unvisited = deque(alphabet[0 : N])
visited = deque()
st = deque([["a", visited, unvisited]]) # stack
while len(st) > 0:
str, visited, unvisited = st.popleft()
if str[-1] not in visited:
visited.append(str[-1])
unvisited.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in visited:
st.append([str + x, deque(visited), deque(unvisited)])
# まだ使っていない文字を使う
if len(unvisited) > 0:
x = unvisited[0]
st.append([str + x, deque(visited), deque(unvisited)])
| from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0 : visited]:
st.append([str + x, visited])
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append([str + alphabet[visited], visited + 1])
| 25 | 19 | 708 | 459 | from collections import deque
N = int(eval(input()))
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
unvisited = deque(alphabet[0:N])
visited = deque()
st = deque([["a", visited, unvisited]]) # stack
while len(st) > 0:
str, visited, unvisited = st.popleft()
if str[-1] not in visited:
visited.append(str[-1])
unvisited.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in visited:
st.append([str + x, deque(visited), deque(unvisited)])
# まだ使っていない文字を使う
if len(unvisited) > 0:
x = unvisited[0]
st.append([str + x, deque(visited), deque(unvisited)])
| from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0:visited]:
st.append([str + x, visited])
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append([str + alphabet[visited], visited + 1])
| false | 24 | [
"-alphabet = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]",
"-unvisited = deque(alphabet[0:N])",
"-visited = deque()",
"-st = deque([[\"a\", visited, unvisited]]) # stack",
"+alphabet = \"abcdefghij\"",
"+visited = 1",
"+st = deque([[\"a\", visited]])",
"- str, visited, u... | false | 0.037435 | 0.044733 | 0.83686 | [
"s491454822",
"s199345990"
] |
u604774382 | p02388 | python | s912480254 | s512922599 | 30 | 20 | 6,720 | 4,188 | Accepted | Accepted | 33.33 | #coding:utf-8
x=int( eval(input()) )
x=x**3
print(x) | import sys
x = int( sys.stdin.readline() )
print(( "{}".format( x**3 ) )) | 4 | 4 | 49 | 75 | # coding:utf-8
x = int(eval(input()))
x = x**3
print(x)
| import sys
x = int(sys.stdin.readline())
print(("{}".format(x**3)))
| false | 0 | [
"-# coding:utf-8",
"-x = int(eval(input()))",
"-x = x**3",
"-print(x)",
"+import sys",
"+",
"+x = int(sys.stdin.readline())",
"+print((\"{}\".format(x**3)))"
] | false | 0.036949 | 0.042634 | 0.866658 | [
"s912480254",
"s512922599"
] |
u379142263 | p02630 | python | s116784781 | s531500487 | 503 | 443 | 21,336 | 21,416 | Accepted | Accepted | 11.93 | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int,input().split()))
q = int(eval(input()))
cnt = [0]*(10**5+7)
for i in range(n):
cnt[a[i]]+=1
ruiseki = sum(a)
for i in range(q):
b,c = list(map(int,input().split()))
d = cnt[b]
e = d*(c-b)
cnt[c] += d
cnt[b] -= d
ruiseki += e
print(ruiseki) | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
def main():
n = int(eval(input()))
a = list(map(int,input().split()))
q = int(eval(input()))
cnt = [0]*(10**5+7)
for i in range(n):
cnt[a[i]]+=1
p = sum(a)
for i in range(q):
b,c = list(map(int,input().split()))
d = cnt[b]
e = cnt[c]
diff = d*(c-b)
p += diff
cnt[c]+=d
cnt[b]-=d
print(p)
if __name__ == "__main__":
main() | 24 | 27 | 565 | 594 | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections
import copy
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
cnt = [0] * (10**5 + 7)
for i in range(n):
cnt[a[i]] += 1
ruiseki = sum(a)
for i in range(q):
b, c = list(map(int, input().split()))
d = cnt[b]
e = d * (c - b)
cnt[c] += d
cnt[b] -= d
ruiseki += e
print(ruiseki)
| import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections
import copy
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
cnt = [0] * (10**5 + 7)
for i in range(n):
cnt[a[i]] += 1
p = sum(a)
for i in range(q):
b, c = list(map(int, input().split()))
d = cnt[b]
e = cnt[c]
diff = d * (c - b)
p += diff
cnt[c] += d
cnt[b] -= d
print(p)
if __name__ == "__main__":
main()
| false | 11.111111 | [
"-if __name__ == \"__main__\":",
"+",
"+def main():",
"- ruiseki = sum(a)",
"+ p = sum(a)",
"- e = d * (c - b)",
"+ e = cnt[c]",
"+ diff = d * (c - b)",
"+ p += diff",
"- ruiseki += e",
"- print(ruiseki)",
"+ print(p)",
"+",
"+",
"+i... | false | 0.046985 | 0.049523 | 0.948752 | [
"s116784781",
"s531500487"
] |
u432780056 | p03212 | python | s072031527 | s393865631 | 65 | 50 | 6,256 | 6,384 | Accepted | Accepted | 23.08 | UP = int(1e9)
s = set()
full = set('357')
def dfs(n):
if n > UP:
return
if set(str(n)) == full:
s.add(n)
dfs(n * 10 + 3)
dfs(n * 10 + 5)
dfs(n * 10 + 7)
dfs(0)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
if i <= n:
ans += 1
else:
break
print(ans)
| UP = int(1e9)
s = set()
def dfs(n, f3, f5, f7):
if n > UP:
return
if f3 and f5 and f7:
s.add(n)
dfs(n * 10 + 3, True, f5, f7)
dfs(n * 10 + 5, f3, True, f7)
dfs(n * 10 + 7, f3, f5, True)
dfs(0, False, False, False)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
if i <= n:
ans += 1
else:
break
print(ans)
| 26 | 25 | 350 | 403 | UP = int(1e9)
s = set()
full = set("357")
def dfs(n):
if n > UP:
return
if set(str(n)) == full:
s.add(n)
dfs(n * 10 + 3)
dfs(n * 10 + 5)
dfs(n * 10 + 7)
dfs(0)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
if i <= n:
ans += 1
else:
break
print(ans)
| UP = int(1e9)
s = set()
def dfs(n, f3, f5, f7):
if n > UP:
return
if f3 and f5 and f7:
s.add(n)
dfs(n * 10 + 3, True, f5, f7)
dfs(n * 10 + 5, f3, True, f7)
dfs(n * 10 + 7, f3, f5, True)
dfs(0, False, False, False)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
if i <= n:
ans += 1
else:
break
print(ans)
| false | 3.846154 | [
"-full = set(\"357\")",
"-def dfs(n):",
"+def dfs(n, f3, f5, f7):",
"- if set(str(n)) == full:",
"+ if f3 and f5 and f7:",
"- dfs(n * 10 + 3)",
"- dfs(n * 10 + 5)",
"- dfs(n * 10 + 7)",
"+ dfs(n * 10 + 3, True, f5, f7)",
"+ dfs(n * 10 + 5, f3, True, f7)",
"+ dfs(n * 10 + ... | false | 0.124251 | 0.090623 | 1.371078 | [
"s072031527",
"s393865631"
] |
u652656291 | p02861 | python | s285327341 | s179032427 | 21 | 17 | 3,188 | 3,060 | Accepted | Accepted | 19.05 | N=int(eval(input()))
import math
XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]
ans=0
for i in range(N):
for j in range(N):
if i<j:
ans+=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
bb=1
for i in range(1,N+1):
bb*=i
print((2*ans/N))
| N=int(eval(input()))
import math
XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]
ans=0
for i in range(N):
for j in range(N):
if i<j:
ans+=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
print((2*ans/N))
| 15 | 13 | 287 | 250 | N = int(eval(input()))
import math
XY = [[int(x) for x in input().rstrip().split()] for i in range(N)]
ans = 0
for i in range(N):
for j in range(N):
if i < j:
ans += math.sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)
bb = 1
for i in range(1, N + 1):
bb *= i
print((2 * ans / N))
| N = int(eval(input()))
import math
XY = [[int(x) for x in input().rstrip().split()] for i in range(N)]
ans = 0
for i in range(N):
for j in range(N):
if i < j:
ans += math.sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)
print((2 * ans / N))
| false | 13.333333 | [
"-bb = 1",
"-for i in range(1, N + 1):",
"- bb *= i"
] | false | 0.044113 | 0.049607 | 0.889243 | [
"s285327341",
"s179032427"
] |
u355371431 | p03107 | python | s423095386 | s478462956 | 178 | 29 | 39,408 | 3,188 | Accepted | Accepted | 83.71 | S = eval(input())
one = 0
zero = 0
for i in S:
if i == "1":
one += 1
else:
zero += 1
print((min(one,zero)*2)) | S = eval(input())
cnt_0 = 0
cnt_1 = 0
for i in S:
if i == "0":
cnt_0 += 1
else:
cnt_1 +=1
print((min(cnt_0,cnt_1)*2)) | 9 | 9 | 133 | 141 | S = eval(input())
one = 0
zero = 0
for i in S:
if i == "1":
one += 1
else:
zero += 1
print((min(one, zero) * 2))
| S = eval(input())
cnt_0 = 0
cnt_1 = 0
for i in S:
if i == "0":
cnt_0 += 1
else:
cnt_1 += 1
print((min(cnt_0, cnt_1) * 2))
| false | 0 | [
"-one = 0",
"-zero = 0",
"+cnt_0 = 0",
"+cnt_1 = 0",
"- if i == \"1\":",
"- one += 1",
"+ if i == \"0\":",
"+ cnt_0 += 1",
"- zero += 1",
"-print((min(one, zero) * 2))",
"+ cnt_1 += 1",
"+print((min(cnt_0, cnt_1) * 2))"
] | false | 0.034505 | 0.034111 | 1.011549 | [
"s423095386",
"s478462956"
] |
u223646582 | p02727 | python | s797064991 | s720150297 | 342 | 254 | 23,456 | 23,200 | Accepted | Accepted | 25.73 | import heapq
X, Y, A, B, C = list(map(int, input().split()))
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()], reverse=True)
hq = P[:X]+Q[:Y]
ans = sum(hq)
heapq.heapify(hq) # リストhqのheap化
i = 0
while hq and i < len(R):
t = heapq.heappop(hq) # heap化されたリストhqから最小値を削除&その最小値を出力
if R[i] > t:
ans = ans - t + R[i]
i += 1
else:
break
print(ans)
| X, Y, A, B, C = list(map(int, input().split()))
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()])
S = sorted(P[:X]+Q[:Y]+R, reverse=True)
print((sum(S[:X+Y])))
| 20 | 8 | 508 | 277 | import heapq
X, Y, A, B, C = list(map(int, input().split()))
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()], reverse=True)
hq = P[:X] + Q[:Y]
ans = sum(hq)
heapq.heapify(hq) # リストhqのheap化
i = 0
while hq and i < len(R):
t = heapq.heappop(hq) # heap化されたリストhqから最小値を削除&その最小値を出力
if R[i] > t:
ans = ans - t + R[i]
i += 1
else:
break
print(ans)
| X, Y, A, B, C = list(map(int, input().split()))
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()])
S = sorted(P[:X] + Q[:Y] + R, reverse=True)
print((sum(S[: X + Y])))
| false | 60 | [
"-import heapq",
"-",
"-R = sorted([int(i) for i in input().split()], reverse=True)",
"-hq = P[:X] + Q[:Y]",
"-ans = sum(hq)",
"-heapq.heapify(hq) # リストhqのheap化",
"-i = 0",
"-while hq and i < len(R):",
"- t = heapq.heappop(hq) # heap化されたリストhqから最小値を削除&その最小値を出力",
"- if R[i] > t:",
"- ... | false | 0.040864 | 0.040585 | 1.006882 | [
"s797064991",
"s720150297"
] |
u514401521 | p02843 | python | s320049106 | s739301765 | 174 | 17 | 44,784 | 2,940 | Accepted | Accepted | 90.23 | X = int(input())
dp = [False for _ in range(100001)]
dp[0] = True
for i in range(100,106):
dp[i] = True
for i in range(107, X + 1):
if dp[i - 100] == True or dp[i - 101] == True or dp[i - 102] == True\
or dp[i - 103] == True or dp[i - 104] == True or dp[i - 105] == True:
dp[i] = True
if dp[X] == True:
print(1)
else:
print(0)
| import sys
x = int(eval(input()))
for i in range(1000):
if 100 * i <= x <= 105 * i:
print("1")
sys.exit(0)
print("0") | 14 | 8 | 372 | 139 | X = int(input())
dp = [False for _ in range(100001)]
dp[0] = True
for i in range(100, 106):
dp[i] = True
for i in range(107, X + 1):
if (
dp[i - 100] == True
or dp[i - 101] == True
or dp[i - 102] == True
or dp[i - 103] == True
or dp[i - 104] == True
or dp[i - 105] == True
):
dp[i] = True
if dp[X] == True:
print(1)
else:
print(0)
| import sys
x = int(eval(input()))
for i in range(1000):
if 100 * i <= x <= 105 * i:
print("1")
sys.exit(0)
print("0")
| false | 42.857143 | [
"-X = int(input())",
"-dp = [False for _ in range(100001)]",
"-dp[0] = True",
"-for i in range(100, 106):",
"- dp[i] = True",
"-for i in range(107, X + 1):",
"- if (",
"- dp[i - 100] == True",
"- or dp[i - 101] == True",
"- or dp[i - 102] == True",
"- or dp[i - ... | false | 0.039132 | 0.036559 | 1.070388 | [
"s320049106",
"s739301765"
] |
u222668979 | p03283 | python | s976516180 | s097892907 | 618 | 528 | 130,244 | 125,400 | Accepted | Accepted | 14.56 | from copy import deepcopy
n, m, q = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]
cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
cnt[l][r] += 1
acc = deepcopy(cnt)
for i in range(n):
for j in range(n):
tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
acc[i + 1][j + 1] += tmp
for p, q in pq:
p -= 1
ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
print(ans)
| n, m, q = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]
acc = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
acc[l][r] += 1
for i in range(n):
for j in range(n):
tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
acc[i + 1][j + 1] += tmp
for p, q in pq:
p -= 1
ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
print(ans)
| 20 | 16 | 527 | 475 | from copy import deepcopy
n, m, q = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]
cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
cnt[l][r] += 1
acc = deepcopy(cnt)
for i in range(n):
for j in range(n):
tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
acc[i + 1][j + 1] += tmp
for p, q in pq:
p -= 1
ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
print(ans)
| n, m, q = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]
acc = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
acc[l][r] += 1
for i in range(n):
for j in range(n):
tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
acc[i + 1][j + 1] += tmp
for p, q in pq:
p -= 1
ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
print(ans)
| false | 20 | [
"-from copy import deepcopy",
"-",
"-cnt = [[0] * (n + 1) for _ in range(n + 1)]",
"+acc = [[0] * (n + 1) for _ in range(n + 1)]",
"- cnt[l][r] += 1",
"-acc = deepcopy(cnt)",
"+ acc[l][r] += 1"
] | false | 0.039869 | 0.036126 | 1.103615 | [
"s976516180",
"s097892907"
] |
u358919705 | p00029 | python | s556061271 | s658873792 | 30 | 20 | 7,356 | 7,252 | Accepted | Accepted | 33.33 | words = input().split(' ')
print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1])) | words = input().split()
print((max(words, key=words.count), max(words, key=len))) | 2 | 2 | 97 | 80 | words = input().split(" ")
print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1]))
| words = input().split()
print((max(words, key=words.count), max(words, key=len)))
| false | 0 | [
"-words = input().split(\" \")",
"-print((sorted(words, key=words.count)[-1], sorted(words, key=len)[-1]))",
"+words = input().split()",
"+print((max(words, key=words.count), max(words, key=len)))"
] | false | 0.109378 | 0.040388 | 2.708191 | [
"s556061271",
"s658873792"
] |
u654470292 | p03274 | python | s006723254 | s797202728 | 222 | 114 | 62,576 | 95,840 | Accepted | Accepted | 48.65 | n,k=list(map(int,input().split()))
x=list(map(int,input().split()))
ans=10000000000
j=0
for i in range(n-k+1):
if ans>min(abs(x[i])+abs(x[i+k-1]-x[i]), abs(x[i+k-1])+abs(x[i+k-1]-x[i])):
ans=min(abs(x[i])+abs(x[i+k-1]-x[i]), abs(x[i+k-1])+abs(x[i+k-1]-x[i]))
print(ans) | import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n,k=list(map(int,input().split()))
x=list(map(int,input().split()))
rui=[0]
for i in range(n-1):
rui.append(x[i+1]-x[i]+rui[i])
# print(rui)
ans=float('inf')
for i in range(n-k+1):
tmp=rui[i+k-1]-rui[i]
ans=min(ans,tmp+min(abs(x[i]),abs(x[i+k-1])))
print(ans) | 12 | 28 | 290 | 728 | n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 10000000000
j = 0
for i in range(n - k + 1):
if ans > min(
abs(x[i]) + abs(x[i + k - 1] - x[i]),
abs(x[i + k - 1]) + abs(x[i + k - 1] - x[i]),
):
ans = min(
abs(x[i]) + abs(x[i + k - 1] - x[i]),
abs(x[i + k - 1]) + abs(x[i + k - 1] - x[i]),
)
print(ans)
| import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
def celi(a, b):
return -(-a // b)
sys.setrecursionlimit(5000000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
rui = [0]
for i in range(n - 1):
rui.append(x[i + 1] - x[i] + rui[i])
# print(rui)
ans = float("inf")
for i in range(n - k + 1):
tmp = rui[i + k - 1] - rui[i]
ans = min(ans, tmp + min(abs(x[i]), abs(x[i + k - 1])))
print(ans)
| false | 57.142857 | [
"+import bisect, copy, heapq, math, sys",
"+from collections import *",
"+from functools import lru_cache",
"+from itertools import accumulate, combinations, permutations, product",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+def ruiseki(lst):",
"+ return... | false | 0.108684 | 0.047434 | 2.291276 | [
"s006723254",
"s797202728"
] |
u933722792 | p03160 | python | s599626809 | s874581065 | 161 | 139 | 20,808 | 20,928 | Accepted | Accepted | 13.66 | import math
N = int(eval(input()))
h = list(map(int, input().split()))
h += [math.inf, math.inf]
dp = list([math.inf for i in range(N + 2)]) # dpテーブル
dp[0] = 0
for i in range(N):
if dp[i + 1] > (dp[i] + abs(h[i] - h[i + 1])):
dp[i + 1] = (dp[i] + abs(h[i] - h[i + 1]))
else:
dp[i + 1] = dp[i + 1]
if dp[i + 2] > dp[i] + abs(h[i] - h[i + 2]):
dp[i + 2] = dp[i] + abs(h[i] - h[i + 2])
else:
dp[i + 2] = dp[i + 2]
print((dp[N - 1]))
|
def chmin(a, b): return b if a > b else a
def chmax(a, b): return a if a > b else b
"""もらうDP"""
import math
N = int(eval(input()))
h = list(map(int, input().split()))
dp = list([math.inf for i in range(N)]) # dpテーブル
dp[0] = 0
for i in range(N):
dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[N-1]))
| 19 | 21 | 492 | 419 | import math
N = int(eval(input()))
h = list(map(int, input().split()))
h += [math.inf, math.inf]
dp = list([math.inf for i in range(N + 2)]) # dpテーブル
dp[0] = 0
for i in range(N):
if dp[i + 1] > (dp[i] + abs(h[i] - h[i + 1])):
dp[i + 1] = dp[i] + abs(h[i] - h[i + 1])
else:
dp[i + 1] = dp[i + 1]
if dp[i + 2] > dp[i] + abs(h[i] - h[i + 2]):
dp[i + 2] = dp[i] + abs(h[i] - h[i + 2])
else:
dp[i + 2] = dp[i + 2]
print((dp[N - 1]))
| def chmin(a, b):
return b if a > b else a
def chmax(a, b):
return a if a > b else b
"""もらうDP"""
import math
N = int(eval(input()))
h = list(map(int, input().split()))
dp = list([math.inf for i in range(N)]) # dpテーブル
dp[0] = 0
for i in range(N):
dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[N - 1]))
| false | 9.52381 | [
"+def chmin(a, b):",
"+ return b if a > b else a",
"+",
"+",
"+def chmax(a, b):",
"+ return a if a > b else b",
"+",
"+",
"+\"\"\"もらうDP\"\"\"",
"-h += [math.inf, math.inf]",
"-dp = list([math.inf for i in range(N + 2)]) # dpテーブル",
"+dp = list([math.inf for i in range(N)]) # dpテーブル",
... | false | 0.075867 | 0.039419 | 1.92463 | [
"s599626809",
"s874581065"
] |
u450956662 | p02971 | python | s864953901 | s028893481 | 467 | 359 | 15,604 | 19,076 | Accepted | Accepted | 23.13 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
count = A.count(max_a)
if count > 1:
for n in range(N):
print(max_a)
else:
for n in range(N):
if A[n] == max_a:
print((max(A[:n] + A[n+1:])))
continue
print(max_a) | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A, reverse=True)
for a in A:
if a == B[0]:
print((B[1]))
else:
print((B[0])) | 14 | 8 | 300 | 168 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
count = A.count(max_a)
if count > 1:
for n in range(N):
print(max_a)
else:
for n in range(N):
if A[n] == max_a:
print((max(A[:n] + A[n + 1 :])))
continue
print(max_a)
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A, reverse=True)
for a in A:
if a == B[0]:
print((B[1]))
else:
print((B[0]))
| false | 42.857143 | [
"-max_a = max(A)",
"-count = A.count(max_a)",
"-if count > 1:",
"- for n in range(N):",
"- print(max_a)",
"-else:",
"- for n in range(N):",
"- if A[n] == max_a:",
"- print((max(A[:n] + A[n + 1 :])))",
"- continue",
"- print(max_a)",
"+B = sorted... | false | 0.04185 | 0.007348 | 5.695431 | [
"s864953901",
"s028893481"
] |
u517447467 | p02713 | python | s283990630 | s626499101 | 1,943 | 1,693 | 71,632 | 71,320 | Accepted | Accepted | 12.87 | import math
N = int(eval(input()))
all_gcd = []
for i in range(1, N+1):
for j in range(1, N+1):
x = math.gcd(i, j) if i != j else i
for m in range(1, N+1):
y = math.gcd(x, m) if x != m else x
all_gcd.append(y)
print((sum(all_gcd)))
| import math
N = int(eval(input()))
all_gcd = [math.gcd(math.gcd(i, j), m) for i in range(1, N+1) for j in range(1, N+1) for m in range(1, N+1)]
print((sum(all_gcd)))
| 11 | 4 | 257 | 161 | import math
N = int(eval(input()))
all_gcd = []
for i in range(1, N + 1):
for j in range(1, N + 1):
x = math.gcd(i, j) if i != j else i
for m in range(1, N + 1):
y = math.gcd(x, m) if x != m else x
all_gcd.append(y)
print((sum(all_gcd)))
| import math
N = int(eval(input()))
all_gcd = [
math.gcd(math.gcd(i, j), m)
for i in range(1, N + 1)
for j in range(1, N + 1)
for m in range(1, N + 1)
]
print((sum(all_gcd)))
| false | 63.636364 | [
"-all_gcd = []",
"-for i in range(1, N + 1):",
"- for j in range(1, N + 1):",
"- x = math.gcd(i, j) if i != j else i",
"- for m in range(1, N + 1):",
"- y = math.gcd(x, m) if x != m else x",
"- all_gcd.append(y)",
"+all_gcd = [",
"+ math.gcd(math.gcd(i, j), ... | false | 0.046271 | 0.15196 | 0.304494 | [
"s283990630",
"s626499101"
] |
u188827677 | p02971 | python | s112404899 | s684693573 | 525 | 364 | 13,316 | 18,976 | Accepted | Accepted | 30.67 | n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
num = sorted(a, reverse=True)[:2]
for i in a:
if i != num[0]:
print((num[0]))
else:
print((num[1])) | n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
l = sorted(a, reverse=True)
x = l[0]
y = l[1]
for i in a:
if i != x: print(x)
else: print(y) | 9 | 9 | 170 | 159 | n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
num = sorted(a, reverse=True)[:2]
for i in a:
if i != num[0]:
print((num[0]))
else:
print((num[1]))
| n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
l = sorted(a, reverse=True)
x = l[0]
y = l[1]
for i in a:
if i != x:
print(x)
else:
print(y)
| false | 0 | [
"-num = sorted(a, reverse=True)[:2]",
"+l = sorted(a, reverse=True)",
"+x = l[0]",
"+y = l[1]",
"- if i != num[0]:",
"- print((num[0]))",
"+ if i != x:",
"+ print(x)",
"- print((num[1]))",
"+ print(y)"
] | false | 0.04129 | 0.036475 | 1.132018 | [
"s112404899",
"s684693573"
] |
u367130284 | p03032 | python | s267922975 | s536409149 | 64 | 59 | 5,356 | 5,200 | Accepted | Accepted | 7.81 | from heapq import*
n,k=list(map(int,input().split()))
*v,=list(map(int,input().split()))
motimono=[]
ans=[]
v*=2
for j in range(1,min(n,k)+1):
for i in range(n-j,n+1):
motimono=v[i:i+j]
ans.append(sum(motimono))
heapify(motimono)
for i in range(k-j):
if len(motimono)>0:
heappop(motimono)
ans.append(sum(motimono))
print((max(ans))) | n,k,*v=list(map(int,open(0).read().split()))
motimono=[]
ans=[]
v*=2
for j in range(1,min(n,k)+1):
for i in range(n-j,n+1):
motimono=v[i:i+j]
ans.append(sum(motimono))
motimono.sort()
for i in range(k-j):
if len(motimono)>0:
del motimono[0]
ans.append(sum(motimono))
print((max(ans))) | 16 | 14 | 409 | 365 | from heapq import *
n, k = list(map(int, input().split()))
(*v,) = list(map(int, input().split()))
motimono = []
ans = []
v *= 2
for j in range(1, min(n, k) + 1):
for i in range(n - j, n + 1):
motimono = v[i : i + j]
ans.append(sum(motimono))
heapify(motimono)
for i in range(k - j):
if len(motimono) > 0:
heappop(motimono)
ans.append(sum(motimono))
print((max(ans)))
| n, k, *v = list(map(int, open(0).read().split()))
motimono = []
ans = []
v *= 2
for j in range(1, min(n, k) + 1):
for i in range(n - j, n + 1):
motimono = v[i : i + j]
ans.append(sum(motimono))
motimono.sort()
for i in range(k - j):
if len(motimono) > 0:
del motimono[0]
ans.append(sum(motimono))
print((max(ans)))
| false | 12.5 | [
"-from heapq import *",
"-",
"-n, k = list(map(int, input().split()))",
"-(*v,) = list(map(int, input().split()))",
"+n, k, *v = list(map(int, open(0).read().split()))",
"- heapify(motimono)",
"+ motimono.sort()",
"- heappop(motimono)",
"+ del motimono[0]"... | false | 0.045189 | 0.007144 | 6.325266 | [
"s267922975",
"s536409149"
] |
u744920373 | p02658 | python | s375510066 | s858587268 | 101 | 63 | 23,392 | 23,516 | Accepted | Accepted | 37.62 | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
ans *= num
if ans > 10**18:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
'''
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
if ans <= inf / Decimal(str(num)):
ans *= num
else:
if 0 in A:
print((0))
else:
print((-1))
exit()
print(ans) | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
ans *= num
if ans > 10**18:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
'''
'''
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
if ans <= inf / Decimal(str(num)):
ans *= num
else:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
'''
N = ii()
A = li()
if 0 in A:
print((0))
exit()
ans = 1
for num in A:
if ans < (10**18+1) / num or ans == 10**18//num:
ans *= num
else:
print((-1))
exit()
print(ans) | 45 | 60 | 1,164 | 1,389 | import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
"""
N = ii()
A = li()
ans = 1
for num in A:
ans *= num
if ans > 10**18:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
"""
N = ii()
A = li()
ans = 1
inf = Decimal("1000000000000000000")
for num in A:
if ans <= inf / Decimal(str(num)):
ans *= num
else:
if 0 in A:
print((0))
else:
print((-1))
exit()
print(ans)
| import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
"""
N = ii()
A = li()
ans = 1
for num in A:
ans *= num
if ans > 10**18:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
"""
"""
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
if ans <= inf / Decimal(str(num)):
ans *= num
else:
if 0 in A:
print(0)
else:
print(-1)
exit()
print(ans)
"""
N = ii()
A = li()
if 0 in A:
print((0))
exit()
ans = 1
for num in A:
if ans < (10**18 + 1) / num or ans == 10**18 // num:
ans *= num
else:
print((-1))
exit()
print(ans)
| false | 25 | [
"+\"\"\"",
"-inf = Decimal(\"1000000000000000000\")",
"+inf = Decimal('1000000000000000000')",
"- print((0))",
"+ print(0)",
"- print((-1))",
"+ print(-1)",
"+\"\"\"",
"+N = ii()",
"+A = li()",
"+if 0 in A:",
"+ print((0))",
"+ exit()",
"+a... | false | 0.087751 | 0.039443 | 2.224755 | [
"s375510066",
"s858587268"
] |
u797673668 | p02246 | python | s583253717 | s776298988 | 11,050 | 10,040 | 163,220 | 163,400 | Accepted | Accepted | 9.14 | from heapq import heappop, heappush
manhattan = [[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)] for i in range(16)]
movables = [{1, 4}, {0, 2, 5}, {1, 3, 6}, {2, 7}, {0, 5, 8}, {1, 4, 6, 9}, {2, 5, 7, 10}, {3, 6, 11},
{4, 9, 12}, {5, 8, 10, 13}, {6, 9, 11, 14}, {7, 10, 15}, {8, 13}, {9, 12, 14}, {10, 13, 15}, {11, 14}]
swap_cache = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]
destination = 0xfedcba9876543210
def swap(board, move_from, move_to):
return board + swap_cache[move_from][move_to] * (15 - ((board >> (4 * move_from)) & 15))
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
for n in map(int, input().split()):
if n:
n -= 1
else:
n = 15
blank_init = i
board_init += n * 16 ** i
i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
estimation, board, blank = heappop(queue)
if board in visited:
continue
elif board == destination:
print(estimation)
break
visited.add(board)
for new_blank in movables[blank]:
new_board = swap(board, new_blank, blank)
if new_board in visited:
continue
num = (board >> (4 * new_blank)) & 15
new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
if new_estimation > 45:
continue
heappush(queue, (new_estimation, new_board, new_blank)) | from heapq import heappop, heappush
manhattan = [[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)] for i in range(16)]
movables = [{1, 4}, {0, 2, 5}, {1, 3, 6}, {2, 7}, {0, 5, 8}, {1, 4, 6, 9}, {2, 5, 7, 10}, {3, 6, 11},
{4, 9, 12}, {5, 8, 10, 13}, {6, 9, 11, 14}, {7, 10, 15}, {8, 13}, {9, 12, 14}, {10, 13, 15}, {11, 14}]
swap_mul = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
for n in map(int, input().split()):
if n:
n -= 1
else:
n = 15
blank_init = i
board_init += n * 16 ** i
i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
estimation, board, blank = heappop(queue)
if board in visited:
continue
elif board == destination:
print(estimation)
break
visited.add(board)
for new_blank in movables[blank]:
num = (board >> (4 * new_blank)) & 15
new_board = board + swap_mul[new_blank][blank] * (15 - num)
if new_board in visited:
continue
new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
if new_estimation > 45:
continue
heappush(queue, (new_estimation, new_board, new_blank)) | 48 | 43 | 1,667 | 1,545 | from heapq import heappop, heappush
manhattan = [
[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)]
for i in range(16)
]
movables = [
{1, 4},
{0, 2, 5},
{1, 3, 6},
{2, 7},
{0, 5, 8},
{1, 4, 6, 9},
{2, 5, 7, 10},
{3, 6, 11},
{4, 9, 12},
{5, 8, 10, 13},
{6, 9, 11, 14},
{7, 10, 15},
{8, 13},
{9, 12, 14},
{10, 13, 15},
{11, 14},
]
swap_cache = [
[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)
]
destination = 0xFEDCBA9876543210
def swap(board, move_from, move_to):
return board + swap_cache[move_from][move_to] * (
15 - ((board >> (4 * move_from)) & 15)
)
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
for n in map(int, input().split()):
if n:
n -= 1
else:
n = 15
blank_init = i
board_init += n * 16**i
i += 1
estimation_init = sum(
manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init
)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
estimation, board, blank = heappop(queue)
if board in visited:
continue
elif board == destination:
print(estimation)
break
visited.add(board)
for new_blank in movables[blank]:
new_board = swap(board, new_blank, blank)
if new_board in visited:
continue
num = (board >> (4 * new_blank)) & 15
new_estimation = (
estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
)
if new_estimation > 45:
continue
heappush(queue, (new_estimation, new_board, new_blank))
| from heapq import heappop, heappush
manhattan = [
[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)]
for i in range(16)
]
movables = [
{1, 4},
{0, 2, 5},
{1, 3, 6},
{2, 7},
{0, 5, 8},
{1, 4, 6, 9},
{2, 5, 7, 10},
{3, 6, 11},
{4, 9, 12},
{5, 8, 10, 13},
{6, 9, 11, 14},
{7, 10, 15},
{8, 13},
{9, 12, 14},
{10, 13, 15},
{11, 14},
]
swap_mul = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]
destination = 0xFEDCBA9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
for n in map(int, input().split()):
if n:
n -= 1
else:
n = 15
blank_init = i
board_init += n * 16**i
i += 1
estimation_init = sum(
manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init
)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
estimation, board, blank = heappop(queue)
if board in visited:
continue
elif board == destination:
print(estimation)
break
visited.add(board)
for new_blank in movables[blank]:
num = (board >> (4 * new_blank)) & 15
new_board = board + swap_mul[new_blank][blank] * (15 - num)
if new_board in visited:
continue
new_estimation = (
estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
)
if new_estimation > 45:
continue
heappush(queue, (new_estimation, new_board, new_blank))
| false | 10.416667 | [
"-swap_cache = [",
"- [(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)",
"-]",
"+swap_mul = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]",
"-",
"-",
"-def swap(board, move_from, move_to):",
"- return board + swap_cache[move_from][move_t... | false | 0.040858 | 0.042892 | 0.952563 | [
"s583253717",
"s776298988"
] |
u368249389 | p02725 | python | s868746642 | s168251419 | 286 | 262 | 78,796 | 77,388 | Accepted | Accepted | 8.39 | # Problem C - Traveling Salesman around Lake
K, N = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
min_cost = 10**8
a_len = len(a_list)
for i in range(len(a_list)):
a = a_list[i]
ushiro_i = 0
mae_i = 0
# 1つ後ろを取る
if i-1<0:
ushiro_i = a_len - 1
else:
ushiro_i = i - 1
# 1つ前を取る
if i+1>=a_len:
mae_i = 0
else:
mae_i = i + 1
# update
kouho_1 = 0
kouho_2 = 0
if a_list[mae_i]-a_list[i]<0:
kouho_1 = K - (a_list[mae_i] - a_list[i] + K)
else:
kouho_1 = K - (a_list[mae_i] - a_list[i])
if a_list[i]-a_list[ushiro_i]<0:
kouho_2 = K - (a_list[i] - a_list[ushiro_i] + K)
else:
kouho_2 = K - (a_list[i] - a_list[ushiro_i])
min_cost = min(min_cost, kouho_1, kouho_2)
# output
print(min_cost)
| # Problem C - Traveling Salesman around Lake
# input
K, N = list(map(int, input().split()))
A_list = list(map(int, input().split()))
list_len = len(A_list)
# initialization
min_ans = 10**18
# search
for i in range(list_len):
mae_i = 0
if i==list_len-1:
mae_i = 0
else:
mae_i = i + 1
kyori = 0
if A_list[mae_i]-A_list[i]<0:
kyori = K - (A_list[mae_i] - A_list[i] + K)
else:
kyori = K - (A_list[mae_i] - A_list[i])
min_ans = min(min_ans, kyori)
# output
print(min_ans)
| 41 | 27 | 902 | 552 | # Problem C - Traveling Salesman around Lake
K, N = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
min_cost = 10**8
a_len = len(a_list)
for i in range(len(a_list)):
a = a_list[i]
ushiro_i = 0
mae_i = 0
# 1つ後ろを取る
if i - 1 < 0:
ushiro_i = a_len - 1
else:
ushiro_i = i - 1
# 1つ前を取る
if i + 1 >= a_len:
mae_i = 0
else:
mae_i = i + 1
# update
kouho_1 = 0
kouho_2 = 0
if a_list[mae_i] - a_list[i] < 0:
kouho_1 = K - (a_list[mae_i] - a_list[i] + K)
else:
kouho_1 = K - (a_list[mae_i] - a_list[i])
if a_list[i] - a_list[ushiro_i] < 0:
kouho_2 = K - (a_list[i] - a_list[ushiro_i] + K)
else:
kouho_2 = K - (a_list[i] - a_list[ushiro_i])
min_cost = min(min_cost, kouho_1, kouho_2)
# output
print(min_cost)
| # Problem C - Traveling Salesman around Lake
# input
K, N = list(map(int, input().split()))
A_list = list(map(int, input().split()))
list_len = len(A_list)
# initialization
min_ans = 10**18
# search
for i in range(list_len):
mae_i = 0
if i == list_len - 1:
mae_i = 0
else:
mae_i = i + 1
kyori = 0
if A_list[mae_i] - A_list[i] < 0:
kyori = K - (A_list[mae_i] - A_list[i] + K)
else:
kyori = K - (A_list[mae_i] - A_list[i])
min_ans = min(min_ans, kyori)
# output
print(min_ans)
| false | 34.146341 | [
"+# input",
"-a_list = list(map(int, input().split()))",
"+A_list = list(map(int, input().split()))",
"+list_len = len(A_list)",
"-min_cost = 10**8",
"-a_len = len(a_list)",
"-for i in range(len(a_list)):",
"- a = a_list[i]",
"- ushiro_i = 0",
"+min_ans = 10**18",
"+# search",
"+for i in... | false | 0.043882 | 0.069582 | 0.630645 | [
"s868746642",
"s168251419"
] |
u394950523 | p02784 | python | s723669852 | s878861742 | 49 | 41 | 13,960 | 13,964 | Accepted | Accepted | 16.33 | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
T = 0
for a in A: #for i in A だとAの要素を繰り返す
T += a
if T >= H:
print("Yes")
else:
print("No") | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
if sum(A) >= H:
print("Yes")
else:
print("No") | 10 | 7 | 187 | 136 | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
T = 0
for a in A: # for i in A だとAの要素を繰り返す
T += a
if T >= H:
print("Yes")
else:
print("No")
| H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
if sum(A) >= H:
print("Yes")
else:
print("No")
| false | 30 | [
"-T = 0",
"-for a in A: # for i in A だとAの要素を繰り返す",
"- T += a",
"-if T >= H:",
"+if sum(A) >= H:"
] | false | 0.038525 | 0.042739 | 0.901404 | [
"s723669852",
"s878861742"
] |
u766684188 | p02793 | python | s264430969 | s182469184 | 1,090 | 359 | 71,896 | 44,912 | Accepted | Accepted | 67.06 | def gcd(x,y):
if x<y:
x,y=y,x
if y==0:
return x
return gcd(y,x%y)
def lcm(x,y):
return x*y//gcd(x,y)
def modinv(k,mod):
return pow(k,mod-2,mod)
def main():
mod=1000000007
n=int(eval(input()))
A=tuple(map(int,input().split()))
l=1
for a in A:
l=lcm(l,a)
l%=mod
ans=0
for a in A:
ans+=l*modinv(a,mod)
ans%=mod
print(ans)
if __name__=='__main__':
main() | from collections import defaultdict
def lcm_dict(A):
pf_d=defaultdict(int)
for num in A:
for k in range(2,int(num**0.5)+1):
cnt=0
while num%k==0:
cnt+=1
num//=k
if cnt:
pf_d[k]=max(pf_d[k],cnt)
if num!=1:
pf_d[num]=max(pf_d[num],1)
return pf_d
def modinv(k,mod):
return pow(k,mod-2,mod)
def main():
mod=1000000007
n=int(eval(input()))
A=tuple(map(int,input().split()))
lcm_d=lcm_dict(A)
l=1
for num in lcm_d:
cnt=lcm_d[num]
l*=pow(num,cnt,mod)
l%=mod
ans=0
for a in A:
ans+=l*modinv(a,mod)
ans%=mod
print(ans)
if __name__=='__main__':
main() | 27 | 37 | 476 | 783 | def gcd(x, y):
if x < y:
x, y = y, x
if y == 0:
return x
return gcd(y, x % y)
def lcm(x, y):
return x * y // gcd(x, y)
def modinv(k, mod):
return pow(k, mod - 2, mod)
def main():
mod = 1000000007
n = int(eval(input()))
A = tuple(map(int, input().split()))
l = 1
for a in A:
l = lcm(l, a)
l %= mod
ans = 0
for a in A:
ans += l * modinv(a, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
def lcm_dict(A):
pf_d = defaultdict(int)
for num in A:
for k in range(2, int(num**0.5) + 1):
cnt = 0
while num % k == 0:
cnt += 1
num //= k
if cnt:
pf_d[k] = max(pf_d[k], cnt)
if num != 1:
pf_d[num] = max(pf_d[num], 1)
return pf_d
def modinv(k, mod):
return pow(k, mod - 2, mod)
def main():
mod = 1000000007
n = int(eval(input()))
A = tuple(map(int, input().split()))
lcm_d = lcm_dict(A)
l = 1
for num in lcm_d:
cnt = lcm_d[num]
l *= pow(num, cnt, mod)
l %= mod
ans = 0
for a in A:
ans += l * modinv(a, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| false | 27.027027 | [
"-def gcd(x, y):",
"- if x < y:",
"- x, y = y, x",
"- if y == 0:",
"- return x",
"- return gcd(y, x % y)",
"+from collections import defaultdict",
"-def lcm(x, y):",
"- return x * y // gcd(x, y)",
"+def lcm_dict(A):",
"+ pf_d = defaultdict(int)",
"+ for num in A... | false | 0.0797 | 0.063789 | 1.249443 | [
"s264430969",
"s182469184"
] |
u644907318 | p02881 | python | s200354451 | s432220942 | 190 | 78 | 40,300 | 64,092 | Accepted | Accepted | 58.95 | N=int(eval(input()))
dmin = 10**12+10
for i in range(1,int(N**0.5)+1):
if N%i==0:
n = N//i
dmin = min(dmin,i-1+n-1)
print(dmin) | N = int(eval(input()))
dmin = N+N
for i in range(1,int(N**0.5)+1):
if N%i==0:
dmin = min(dmin,i+N//i-2)
print(dmin) | 7 | 6 | 147 | 126 | N = int(eval(input()))
dmin = 10**12 + 10
for i in range(1, int(N**0.5) + 1):
if N % i == 0:
n = N // i
dmin = min(dmin, i - 1 + n - 1)
print(dmin)
| N = int(eval(input()))
dmin = N + N
for i in range(1, int(N**0.5) + 1):
if N % i == 0:
dmin = min(dmin, i + N // i - 2)
print(dmin)
| false | 14.285714 | [
"-dmin = 10**12 + 10",
"+dmin = N + N",
"- n = N // i",
"- dmin = min(dmin, i - 1 + n - 1)",
"+ dmin = min(dmin, i + N // i - 2)"
] | false | 0.04486 | 0.036861 | 1.217011 | [
"s200354451",
"s432220942"
] |
u105124953 | p02854 | python | s748267282 | s286781940 | 317 | 290 | 100,300 | 96,972 | Accepted | Accepted | 8.52 | n = int(eval(input()))
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
for i,l in enumerate(li):
if i == 0:
sum_li.append(l)
continue
sum_li.append(sum_li[-1]+l)
all_li = []
for ii,ss in enumerate(sum_li):
if ii == len(sum_li)-1:
break
all_li.append(abs(s-2*ss))
#print(all_li)
print((min(all_li))) | n = int(eval(input()))
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
left = 0
right = s
for i,l in enumerate(li):
if i == len(li)-1:
break
left += l
right -= l
sum_li.append(abs(left-right))
print((min(sum_li))) | 16 | 13 | 357 | 253 | n = int(eval(input()))
li = list(map(int, input().split()))
s = sum(li)
sum_li = []
for i, l in enumerate(li):
if i == 0:
sum_li.append(l)
continue
sum_li.append(sum_li[-1] + l)
all_li = []
for ii, ss in enumerate(sum_li):
if ii == len(sum_li) - 1:
break
all_li.append(abs(s - 2 * ss))
# print(all_li)
print((min(all_li)))
| n = int(eval(input()))
li = list(map(int, input().split()))
s = sum(li)
sum_li = []
left = 0
right = s
for i, l in enumerate(li):
if i == len(li) - 1:
break
left += l
right -= l
sum_li.append(abs(left - right))
print((min(sum_li)))
| false | 18.75 | [
"+left = 0",
"+right = s",
"- if i == 0:",
"- sum_li.append(l)",
"- continue",
"- sum_li.append(sum_li[-1] + l)",
"-all_li = []",
"-for ii, ss in enumerate(sum_li):",
"- if ii == len(sum_li) - 1:",
"+ if i == len(li) - 1:",
"- all_li.append(abs(s - 2 * ss))",
"-# p... | false | 0.048964 | 0.147683 | 0.33155 | [
"s748267282",
"s286781940"
] |
u983918956 | p03213 | python | s682366019 | s440375774 | 22 | 18 | 3,436 | 3,064 | Accepted | Accepted | 18.18 | # 因数を昇順に全列挙
from collections import Counter
import math
def com(n,r):
return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
fac_list = []
def factoring(n):
for i in range(2,n+1):
if n % i == 0:
fac_list.append(i)
n = n // i
break
if n == 1:
return fac_list
else:
return factoring(n)
# (素因数,指数)
n = int(eval(input()))
c = list(Counter(factoring(math.factorial(n))).values())
# 指数 (2,4,4),(2,24),(4,14),(74) の場合の数
l = [0]*5 # [2,4,14,24,74]
for e in c:
if e >= 74:
index = 4
elif e >= 24:
index = 3
elif e >= 14:
index = 2
elif e >= 4:
index = 1
elif e >= 2:
index = 0
else:
continue
l[index] += 1
sum_l = sum(l)
num_74 = l[4]
if sum_l - l[0] - 1 > 0:
num_4_14 = (l[2] + l[3] + l[4])*(sum_l - l[0] - 1)
else:
num_4_14 = 0
if sum_l - 1 > 0:
num_2_24 = (l[3] + l[4])*(sum_l - 1)
else:
num_2_24 = 0
if sum_l - l[0] >= 2:
num_2_4_4 = com(sum_l-l[0],2)*(sum_l - 2)
else:
num_2_4_4 = 0
ans = num_74 + num_4_14 + num_2_24 + num_2_4_4
print(ans) | def factoring(n):
for i in range(2, n+1):
while n % i == 0:
n //= i
d[i] += 1
N = int(eval(input()))
d = [0]*(N+1)
for n in range(2,N+1):
factoring(n)
def num(n):
return len([e for e in d if e >= n])
ans = num(74) + num(14)*(num(4)-1) + num(24)*(num(2)-1) + num(4)*(num(4)-1)*(num(2)-2)//2
print(ans) | 51 | 18 | 1,171 | 360 | # 因数を昇順に全列挙
from collections import Counter
import math
def com(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
fac_list = []
def factoring(n):
for i in range(2, n + 1):
if n % i == 0:
fac_list.append(i)
n = n // i
break
if n == 1:
return fac_list
else:
return factoring(n)
# (素因数,指数)
n = int(eval(input()))
c = list(Counter(factoring(math.factorial(n))).values())
# 指数 (2,4,4),(2,24),(4,14),(74) の場合の数
l = [0] * 5 # [2,4,14,24,74]
for e in c:
if e >= 74:
index = 4
elif e >= 24:
index = 3
elif e >= 14:
index = 2
elif e >= 4:
index = 1
elif e >= 2:
index = 0
else:
continue
l[index] += 1
sum_l = sum(l)
num_74 = l[4]
if sum_l - l[0] - 1 > 0:
num_4_14 = (l[2] + l[3] + l[4]) * (sum_l - l[0] - 1)
else:
num_4_14 = 0
if sum_l - 1 > 0:
num_2_24 = (l[3] + l[4]) * (sum_l - 1)
else:
num_2_24 = 0
if sum_l - l[0] >= 2:
num_2_4_4 = com(sum_l - l[0], 2) * (sum_l - 2)
else:
num_2_4_4 = 0
ans = num_74 + num_4_14 + num_2_24 + num_2_4_4
print(ans)
| def factoring(n):
for i in range(2, n + 1):
while n % i == 0:
n //= i
d[i] += 1
N = int(eval(input()))
d = [0] * (N + 1)
for n in range(2, N + 1):
factoring(n)
def num(n):
return len([e for e in d if e >= n])
ans = (
num(74)
+ num(14) * (num(4) - 1)
+ num(24) * (num(2) - 1)
+ num(4) * (num(4) - 1) * (num(2) - 2) // 2
)
print(ans)
| false | 64.705882 | [
"-# 因数を昇順に全列挙",
"-from collections import Counter",
"-import math",
"+def factoring(n):",
"+ for i in range(2, n + 1):",
"+ while n % i == 0:",
"+ n //= i",
"+ d[i] += 1",
"-def com(n, r):",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r... | false | 0.047224 | 0.046737 | 1.010413 | [
"s682366019",
"s440375774"
] |
u069838609 | p03222 | python | s762886147 | s449551880 | 280 | 53 | 19,664 | 3,064 | Accepted | Accepted | 81.07 | import numpy as np
MOD = 10**9 + 7
def powmod(mat, n, mod):
result = np.eye(len(mat), dtype=np.int64)
while n > 0:
if n & 1:
result = np.dot(result, mat) % mod
mat = np.dot(mat, mat) % mod
n >>= 1
return result
H, W, K = [int(elem) for elem in input().split()]
trans_mat = np.zeros((W, W), dtype=np.int64)
initial_vec = np.zeros(W, dtype=np.int64)
initial_vec[0] = 1
for i in range(2**(W - 1)):
flag = False
for pos in range(W - 2):
if (i >> pos & 1) and (i >> (pos + 1) & 1):
flag = True
if flag:
continue
for pos in range(W):
if pos == 0:
if i & 1:
trans_mat[0, 1] += 1
else:
trans_mat[0, 0] += 1
elif pos == W - 1:
if (i >> W - 2) & 1:
trans_mat[W - 1, W - 2] += 1
else:
trans_mat[W - 1, W - 1] += 1
else:
if (i >> (pos - 1)) & 1:
trans_mat[pos, pos - 1] += 1
elif (i >> pos) & 1:
trans_mat[pos, pos + 1] += 1
else:
trans_mat[pos, pos] += 1
powed_mat = powmod(trans_mat, H, MOD)
print((np.dot(powed_mat, initial_vec)[K - 1] % MOD))
| # time complexity: O(HW2^W)
# space complexity: O(HW)
def violates(w_flags):
prev_flag = w_flags & 1
for shift in range(1, W - 1):
flag = w_flags >> shift & 1
if flag and prev_flag:
return True
prev_flag = flag
return False
H, W, K = [int(elem) for elem in input().split()]
MOD = 10**9 + 7
if W == 1:
print((1))
exit(0)
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for w_flags in range(2**(W - 1)):
if violates(w_flags):
continue
for w in range(W):
if w == 0:
if w_flags & 1:
dp[h][0] += dp[h - 1][1]
else:
dp[h][0] += dp[h - 1][0]
elif w == W - 1:
if w_flags >> W - 2 & 1:
dp[h][W - 1] += dp[h - 1][W - 2]
else:
dp[h][W - 1] += dp[h - 1][W - 1]
else:
if w_flags >> w - 1 & 1:
dp[h][w] += dp[h - 1][w - 1]
elif w_flags >> w & 1:
dp[h][w] += dp[h - 1][w + 1]
else:
dp[h][w] += dp[h - 1][w]
dp[h][w] %= MOD
print((dp[-1][K - 1]))
| 47 | 48 | 1,297 | 1,297 | import numpy as np
MOD = 10**9 + 7
def powmod(mat, n, mod):
result = np.eye(len(mat), dtype=np.int64)
while n > 0:
if n & 1:
result = np.dot(result, mat) % mod
mat = np.dot(mat, mat) % mod
n >>= 1
return result
H, W, K = [int(elem) for elem in input().split()]
trans_mat = np.zeros((W, W), dtype=np.int64)
initial_vec = np.zeros(W, dtype=np.int64)
initial_vec[0] = 1
for i in range(2 ** (W - 1)):
flag = False
for pos in range(W - 2):
if (i >> pos & 1) and (i >> (pos + 1) & 1):
flag = True
if flag:
continue
for pos in range(W):
if pos == 0:
if i & 1:
trans_mat[0, 1] += 1
else:
trans_mat[0, 0] += 1
elif pos == W - 1:
if (i >> W - 2) & 1:
trans_mat[W - 1, W - 2] += 1
else:
trans_mat[W - 1, W - 1] += 1
else:
if (i >> (pos - 1)) & 1:
trans_mat[pos, pos - 1] += 1
elif (i >> pos) & 1:
trans_mat[pos, pos + 1] += 1
else:
trans_mat[pos, pos] += 1
powed_mat = powmod(trans_mat, H, MOD)
print((np.dot(powed_mat, initial_vec)[K - 1] % MOD))
| # time complexity: O(HW2^W)
# space complexity: O(HW)
def violates(w_flags):
prev_flag = w_flags & 1
for shift in range(1, W - 1):
flag = w_flags >> shift & 1
if flag and prev_flag:
return True
prev_flag = flag
return False
H, W, K = [int(elem) for elem in input().split()]
MOD = 10**9 + 7
if W == 1:
print((1))
exit(0)
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for w_flags in range(2 ** (W - 1)):
if violates(w_flags):
continue
for w in range(W):
if w == 0:
if w_flags & 1:
dp[h][0] += dp[h - 1][1]
else:
dp[h][0] += dp[h - 1][0]
elif w == W - 1:
if w_flags >> W - 2 & 1:
dp[h][W - 1] += dp[h - 1][W - 2]
else:
dp[h][W - 1] += dp[h - 1][W - 1]
else:
if w_flags >> w - 1 & 1:
dp[h][w] += dp[h - 1][w - 1]
elif w_flags >> w & 1:
dp[h][w] += dp[h - 1][w + 1]
else:
dp[h][w] += dp[h - 1][w]
dp[h][w] %= MOD
print((dp[-1][K - 1]))
| false | 2.083333 | [
"-import numpy as np",
"-",
"-MOD = 10**9 + 7",
"-",
"-",
"-def powmod(mat, n, mod):",
"- result = np.eye(len(mat), dtype=np.int64)",
"- while n > 0:",
"- if n & 1:",
"- result = np.dot(result, mat) % mod",
"- mat = np.dot(mat, mat) % mod",
"- n >>= 1",
... | false | 0.412008 | 0.045719 | 9.011726 | [
"s762886147",
"s449551880"
] |
u493520238 | p03045 | python | s414588534 | s538212472 | 468 | 314 | 7,860 | 81,840 | Accepted | Accepted | 32.91 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N,M = list(map(int, input().split()))
uf = UnionFind(N)
for _ in range(M):
x, y, z = list(map(int, input().split()))
uf.union(x-1,y-1)
print((uf.group_count()))
if __name__ == "__main__":
main() | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n,m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
x,y,z = list(map(int, input().split()))
# if z%2 == 0:
uf.union(x-1, y-1)
print((uf.group_count()))
if __name__ == "__main__":
main() | 60 | 62 | 1,440 | 1,463 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
N, M = list(map(int, input().split()))
uf = UnionFind(N)
for _ in range(M):
x, y, z = list(map(int, input().split()))
uf.union(x - 1, y - 1)
print((uf.group_count()))
if __name__ == "__main__":
main()
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
# if z%2 == 0:
uf.union(x - 1, y - 1)
print((uf.group_count()))
if __name__ == "__main__":
main()
| false | 3.225806 | [
"- N, M = list(map(int, input().split()))",
"- uf = UnionFind(N)",
"- for _ in range(M):",
"+ n, m = list(map(int, input().split()))",
"+ uf = UnionFind(n)",
"+ for _ in range(m):",
"+ # if z%2 == 0:"
] | false | 0.103179 | 0.135764 | 0.75999 | [
"s414588534",
"s538212472"
] |
u102461423 | p02680 | python | s544218306 | s231927059 | 643 | 376 | 150,860 | 86,164 | Accepted | Accepted | 41.52 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
def cc_export():
from numba.pycc import CC
cc = CC('my_module')
signature = '(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])'
cc.export('solve', signature)(solve)
cc.compile()
if sys.argv[-1] == 'ONLINE_JUDGE':
cc_export()
exit()
from my_module import solve
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print('INF')
else:
print(x) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
def cc_export():
from numba.pycc import CC
cc = CC('my_module')
signature = '(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])'
cc.export('solve', signature)(solve)
cc.compile()
if sys.argv[-1] == 'ONLINE_JUDGE':
cc_export()
exit()
from my_module import solve
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print('INF')
else:
print(x) | 108 | 107 | 2,620 | 2,596 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
def cc_export():
from numba.pycc import CC
cc = CC("my_module")
signature = "(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])"
cc.export("solve", signature)(solve)
cc.compile()
if sys.argv[-1] == "ONLINE_JUDGE":
cc_export()
exit()
from my_module import solve
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print("INF")
else:
print(x)
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
def cc_export():
from numba.pycc import CC
cc = CC("my_module")
signature = "(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])"
cc.export("solve", signature)(solve)
cc.compile()
if sys.argv[-1] == "ONLINE_JUDGE":
cc_export()
exit()
from my_module import solve
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print("INF")
else:
print(x)
| false | 0.925926 | [
"-from numba import njit"
] | false | 0.215703 | 0.220755 | 0.977117 | [
"s544218306",
"s231927059"
] |
u298297089 | p03546 | python | s445946481 | s796870291 | 39 | 34 | 3,564 | 3,564 | Accepted | Accepted | 12.82 | # https://atcoder.jp/contests/abc079/tasks/abc079_d
from collections import Counter
from functools import reduce
def warshall(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][k] + d[k][j] < d[i][j]:
d[i][j] = d[i][k] + d[k][j]
h,w = list(map(int,input().split()))
magic = []
for i in range(10):
magic.append(list(map(int,input().split())))
counter = {i:0 for i in range(10)}
for _ in range(h):
for a in map(int, input().split()):
if a > -1:
counter[a] += 1
# counter.update(Counter(map(int, input().split())))
warshall(magic, 10)
ans = 0
for k,v in list(counter.items()):
ans += magic[k][1] * v
print(ans)
# print(reduce(lambda x,y:x+y, [magic[k][1] * v for k,v in counter.items() if k > -1]))
| # https://atcoder.jp/contests/abc079/tasks/abc079_d
from collections import Counter
from functools import reduce
def warshall(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][k] + d[k][j] < d[i][j]:
d[i][j] = d[i][k] + d[k][j]
h,w = list(map(int,input().split()))
magic = []
for i in range(10):
magic.append(list(map(int,input().split())))
counter = Counter()
for _ in range(h):
counter.update(Counter(list(map(int, input().split()))))
warshall(magic, 10)
print((reduce(lambda x,y:x+y, [magic[k][1] * v for k,v in list(counter.items()) if k > -1])))
| 30 | 22 | 835 | 646 | # https://atcoder.jp/contests/abc079/tasks/abc079_d
from collections import Counter
from functools import reduce
def warshall(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][k] + d[k][j] < d[i][j]:
d[i][j] = d[i][k] + d[k][j]
h, w = list(map(int, input().split()))
magic = []
for i in range(10):
magic.append(list(map(int, input().split())))
counter = {i: 0 for i in range(10)}
for _ in range(h):
for a in map(int, input().split()):
if a > -1:
counter[a] += 1
# counter.update(Counter(map(int, input().split())))
warshall(magic, 10)
ans = 0
for k, v in list(counter.items()):
ans += magic[k][1] * v
print(ans)
# print(reduce(lambda x,y:x+y, [magic[k][1] * v for k,v in counter.items() if k > -1]))
| # https://atcoder.jp/contests/abc079/tasks/abc079_d
from collections import Counter
from functools import reduce
def warshall(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][k] + d[k][j] < d[i][j]:
d[i][j] = d[i][k] + d[k][j]
h, w = list(map(int, input().split()))
magic = []
for i in range(10):
magic.append(list(map(int, input().split())))
counter = Counter()
for _ in range(h):
counter.update(Counter(list(map(int, input().split()))))
warshall(magic, 10)
print(
(
reduce(
lambda x, y: x + y,
[magic[k][1] * v for k, v in list(counter.items()) if k > -1],
)
)
)
| false | 26.666667 | [
"-counter = {i: 0 for i in range(10)}",
"+counter = Counter()",
"- for a in map(int, input().split()):",
"- if a > -1:",
"- counter[a] += 1",
"- # counter.update(Counter(map(int, input().split())))",
"+ counter.update(Counter(list(map(int, input().split()))))",
"-ans = 0",
... | false | 0.042094 | 0.039807 | 1.057447 | [
"s445946481",
"s796870291"
] |
u513081876 | p03659 | python | s133336120 | s823928344 | 226 | 174 | 24,832 | 31,348 | Accepted | Accepted | 23.01 | N = int(eval(input()))
a = [int(i) for i in input().split()]
sunuke = 0
arai = sum(a)
ans = float('inf')
for i in range(N-1):
sunuke += a[i]
arai -= a[i]
ans = min(ans, abs(arai-sunuke))
print(ans) | N = int(eval(input()))
a = [int(i) for i in input().split()]
sunuke = a[0]
arai = sum(a[1:])
if N == 2:
print((abs(a[0] - a[1])))
else:
ans = float('inf')
for i in range(1, N-1):
sunuke += a[i]
arai -= a[i]
ans = min(ans, abs(sunuke - arai))
print(ans) | 13 | 14 | 218 | 298 | N = int(eval(input()))
a = [int(i) for i in input().split()]
sunuke = 0
arai = sum(a)
ans = float("inf")
for i in range(N - 1):
sunuke += a[i]
arai -= a[i]
ans = min(ans, abs(arai - sunuke))
print(ans)
| N = int(eval(input()))
a = [int(i) for i in input().split()]
sunuke = a[0]
arai = sum(a[1:])
if N == 2:
print((abs(a[0] - a[1])))
else:
ans = float("inf")
for i in range(1, N - 1):
sunuke += a[i]
arai -= a[i]
ans = min(ans, abs(sunuke - arai))
print(ans)
| false | 7.142857 | [
"-sunuke = 0",
"-arai = sum(a)",
"-ans = float(\"inf\")",
"-for i in range(N - 1):",
"- sunuke += a[i]",
"- arai -= a[i]",
"- ans = min(ans, abs(arai - sunuke))",
"-print(ans)",
"+sunuke = a[0]",
"+arai = sum(a[1:])",
"+if N == 2:",
"+ print((abs(a[0] - a[1])))",
"+else:",
"+ ... | false | 0.038151 | 0.035667 | 1.069646 | [
"s133336120",
"s823928344"
] |
u022407960 | p02273 | python | s708121588 | s226303267 | 40 | 30 | 8,100 | 8,104 | Accepted | Accepted | 25 | # encoding: utf-8
import sys
import math
_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)
class Point(object):
def __init__(self, x=0.0, y=0.0):
"""
initialize the point
"""
self.x = float(x)
self.y = float(y)
def koch_curve(d, p1, p2):
if not d:
# print('end')
return None
# why can't it be like below?
# s, t, u = Point(), Point, Point()
s, t, u = (Point() for _ in range(3))
s.x = (2 * p1.x + p2.x) / 3
s.y = (2 * p1.y + p2.y) / 3
t.x = (p1.x + 2 * p2.x) / 3
t.y = (p1.y + 2 * p2.y) / 3
u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y
koch_curve(d - 1, p1, s)
print((format(s.x, '.8f'), format(s.y, '.8f')))
koch_curve(d - 1, s, u)
print((format(u.x, '.8f'), format(u.y, '.8f')))
koch_curve(d - 1, u, t)
print((format(t.x, '.8f'), format(t.y, '.8f')))
koch_curve(d - 1, t, p2)
if __name__ == '__main__':
p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
print((format(p1_start.x, '.8f'), '', format(p1_start.y, '.8f')))
koch_curve(depth, p1_start, p2_end)
print((format(p2_end.x, '.8f'), '', format(p2_end.y, '.8f'))) | # encoding: utf-8
import sys
import math
_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)
class Point(object):
def __init__(self, x=0.0, y=0.0):
"""
initialize the point
"""
self.x = float(x)
self.y = float(y)
def koch_curve(d, p1, p2):
if not d:
# print('end')
return None
# why can't it be like below?
# s, t, u = Point(), Point, Point()
s, t, u = (Point() for _ in range(3))
s.x = (2 * p1.x + p2.x) / 3
s.y = (2 * p1.y + p2.y) / 3
t.x = (p1.x + 2 * p2.x) / 3
t.y = (p1.y + 2 * p2.y) / 3
u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y
koch_curve(d - 1, p1, s)
print((format(s.x, '.8f'), format(s.y, '.8f')))
koch_curve(d - 1, s, u)
print((format(u.x, '.8f'), format(u.y, '.8f')))
koch_curve(d - 1, u, t)
print((format(t.x, '.8f'), format(t.y, '.8f')))
koch_curve(d - 1, t, p2)
if __name__ == '__main__':
p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
print((format(p1_start.x, '.8f'), format(p1_start.y, '.8f')))
koch_curve(depth, p1_start, p2_end)
print((format(p2_end.x, '.8f'), format(p2_end.y, '.8f'))) | 55 | 55 | 1,360 | 1,352 | # encoding: utf-8
import sys
import math
_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)
class Point(object):
def __init__(self, x=0.0, y=0.0):
"""
initialize the point
"""
self.x = float(x)
self.y = float(y)
def koch_curve(d, p1, p2):
if not d:
# print('end')
return None
# why can't it be like below?
# s, t, u = Point(), Point, Point()
s, t, u = (Point() for _ in range(3))
s.x = (2 * p1.x + p2.x) / 3
s.y = (2 * p1.y + p2.y) / 3
t.x = (p1.x + 2 * p2.x) / 3
t.y = (p1.y + 2 * p2.y) / 3
u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y
koch_curve(d - 1, p1, s)
print((format(s.x, ".8f"), format(s.y, ".8f")))
koch_curve(d - 1, s, u)
print((format(u.x, ".8f"), format(u.y, ".8f")))
koch_curve(d - 1, u, t)
print((format(t.x, ".8f"), format(t.y, ".8f")))
koch_curve(d - 1, t, p2)
if __name__ == "__main__":
p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
print((format(p1_start.x, ".8f"), "", format(p1_start.y, ".8f")))
koch_curve(depth, p1_start, p2_end)
print((format(p2_end.x, ".8f"), "", format(p2_end.y, ".8f")))
| # encoding: utf-8
import sys
import math
_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)
class Point(object):
def __init__(self, x=0.0, y=0.0):
"""
initialize the point
"""
self.x = float(x)
self.y = float(y)
def koch_curve(d, p1, p2):
if not d:
# print('end')
return None
# why can't it be like below?
# s, t, u = Point(), Point, Point()
s, t, u = (Point() for _ in range(3))
s.x = (2 * p1.x + p2.x) / 3
s.y = (2 * p1.y + p2.y) / 3
t.x = (p1.x + 2 * p2.x) / 3
t.y = (p1.y + 2 * p2.y) / 3
u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y
koch_curve(d - 1, p1, s)
print((format(s.x, ".8f"), format(s.y, ".8f")))
koch_curve(d - 1, s, u)
print((format(u.x, ".8f"), format(u.y, ".8f")))
koch_curve(d - 1, u, t)
print((format(t.x, ".8f"), format(t.y, ".8f")))
koch_curve(d - 1, t, p2)
if __name__ == "__main__":
p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
print((format(p1_start.x, ".8f"), format(p1_start.y, ".8f")))
koch_curve(depth, p1_start, p2_end)
print((format(p2_end.x, ".8f"), format(p2_end.y, ".8f")))
| false | 0 | [
"- print((format(p1_start.x, \".8f\"), \"\", format(p1_start.y, \".8f\")))",
"+ print((format(p1_start.x, \".8f\"), format(p1_start.y, \".8f\")))",
"- print((format(p2_end.x, \".8f\"), \"\", format(p2_end.y, \".8f\")))",
"+ print((format(p2_end.x, \".8f\"), format(p2_end.y, \".8f\")))"
] | false | 0.039734 | 0.045295 | 0.877238 | [
"s708121588",
"s226303267"
] |
u780342333 | p02421 | python | s070178118 | s792838851 | 30 | 20 | 7,660 | 5,600 | Accepted | Accepted | 33.33 | round = int(eval(input()))
points =[0, 0]
for r in range(round):
taro, hanako = input().split(" ")
if taro == hanako:
points[0] += 1
points[1] += 1
elif taro > hanako:
points[0] += 3
elif taro < hanako:
points[1] += 3
print((*points)) | def lexicographical_order(a, b):
if a > b:
return 0
elif a < b:
return 1
else:
return 2
if __name__ == "__main__":
n = int(eval(input()))
taro_point, hanako_point = 0, 0
for _ in range(n):
taro_hand, hanako_hand = input().split()
res = lexicographical_order(taro_hand, hanako_hand)
if res == 0:
taro_point += 3
elif res == 1:
hanako_point += 3
elif res == 2:
taro_point += 1
hanako_point += 1
print((taro_point, hanako_point))
| 13 | 24 | 287 | 586 | round = int(eval(input()))
points = [0, 0]
for r in range(round):
taro, hanako = input().split(" ")
if taro == hanako:
points[0] += 1
points[1] += 1
elif taro > hanako:
points[0] += 3
elif taro < hanako:
points[1] += 3
print((*points))
| def lexicographical_order(a, b):
if a > b:
return 0
elif a < b:
return 1
else:
return 2
if __name__ == "__main__":
n = int(eval(input()))
taro_point, hanako_point = 0, 0
for _ in range(n):
taro_hand, hanako_hand = input().split()
res = lexicographical_order(taro_hand, hanako_hand)
if res == 0:
taro_point += 3
elif res == 1:
hanako_point += 3
elif res == 2:
taro_point += 1
hanako_point += 1
print((taro_point, hanako_point))
| false | 45.833333 | [
"-round = int(eval(input()))",
"-points = [0, 0]",
"-for r in range(round):",
"- taro, hanako = input().split(\" \")",
"- if taro == hanako:",
"- points[0] += 1",
"- points[1] += 1",
"- elif taro > hanako:",
"- points[0] += 3",
"- elif taro < hanako:",
"- ... | false | 0.046093 | 0.047485 | 0.970675 | [
"s070178118",
"s792838851"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.