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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u847923740 | p03161 | python | s899753349 | s393615264 | 345 | 178 | 52,448 | 84,720 | Accepted | Accepted | 48.41 | n,k=list(map(int,input().split()))
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
for i in range(1,n):
for j in range(1,min(k+1,i+1)):
dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print((dp[n-1])) | N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
for i in range(1, N):
for j in range(min(i, K) + 1):
dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print((dp[-1])) | 10 | 10 | 219 | 231 | n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10**9] * n
dp[0] = 0
for i in range(1, n):
for j in range(1, min(k + 1, i + 1)):
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[n - 1]))
| N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [10**9] * N
dp[0] = 0
for i in range(1, N):
for j in range(min(i, K) + 1):
dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print((dp[-1]))
| false | 0 | [
"-n, k = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-dp = [10**9] * n",
"+N, K = list(map(int, input().split()))",
"+H = list(map(int, input().split()))",
"+dp = [10**9] * N",
"-for i in range(1, n):",
"- for j in range(1, min(k + 1, i + 1)):",
"- dp[i] = mi... | false | 0.044697 | 0.046231 | 0.966809 | [
"s899753349",
"s393615264"
] |
u143509139 | p02901 | python | s294972175 | s834590128 | 1,067 | 388 | 135,696 | 78,424 | Accepted | Accepted | 63.64 | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
l = [None] * m
li = [None] * m
for i in range(m):
l[i] = list(map(int, input().split()))
li[i] = list(map(int, input().split()))
dp = [[float('inf')] * (2 ** n) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
for j in range(2 ** n):
if dp[i][j] == float('inf'):
continue
tmp = j
for x in li[i]:
tmp |= 2 ** (x - 1)
dp[i + 1][tmp] = min(dp[i + 1][j | tmp], dp[i][j] + l[i][0])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
res = dp[m][2 ** n - 1]
if res == float('inf'):
print((-1))
else:
print(res)
| INF = 10 ** 10
n, m = list(map(int, input().split()))
dp = [[INF] * (2 ** n) for _ in range(m + 1)]
a = [0] * m
c = [0] * m
for i in range(m):
a[i], b = list(map(int, input().split()))
t = 0
for k in list(map(int, input().split())):
t += 1 << (k - 1)
c[i] = t
dp[0][0] = 0
for i in range(m):
for j in range(2 ** n):
dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = dp[m][(1 << n) - 1]
if ans == INF:
print((-1))
else:
print(ans)
| 24 | 21 | 679 | 551 | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
l = [None] * m
li = [None] * m
for i in range(m):
l[i] = list(map(int, input().split()))
li[i] = list(map(int, input().split()))
dp = [[float("inf")] * (2**n) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
for j in range(2**n):
if dp[i][j] == float("inf"):
continue
tmp = j
for x in li[i]:
tmp |= 2 ** (x - 1)
dp[i + 1][tmp] = min(dp[i + 1][j | tmp], dp[i][j] + l[i][0])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
res = dp[m][2**n - 1]
if res == float("inf"):
print((-1))
else:
print(res)
| INF = 10**10
n, m = list(map(int, input().split()))
dp = [[INF] * (2**n) for _ in range(m + 1)]
a = [0] * m
c = [0] * m
for i in range(m):
a[i], b = list(map(int, input().split()))
t = 0
for k in list(map(int, input().split())):
t += 1 << (k - 1)
c[i] = t
dp[0][0] = 0
for i in range(m):
for j in range(2**n):
dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = dp[m][(1 << n) - 1]
if ans == INF:
print((-1))
else:
print(ans)
| false | 12.5 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"+INF = 10**10",
"-l = [None] * m",
"-li = [None] * m",
"+dp = [[INF] * (2**n) for _ in range(m + 1)]",
"+a = [0] * m",
"+c = [0] * m",
"- l[i] = list(map(int, input().split()))",
"- li[i] = list(map(int, input().split()))",
"-dp = [[flo... | false | 0.067055 | 0.037343 | 1.79564 | [
"s294972175",
"s834590128"
] |
u840310460 | p03478 | python | s620557119 | s995689448 | 34 | 29 | 2,940 | 2,940 | Accepted | Accepted | 14.71 | n,a,b = list(map(int, input().split()))
total = 0
for i in range(n+1):
num = [int(d) for d in str(i)]
if sum(num)>=a and sum(num)<=b:
total += i
print(total) | N, A, B = [int(i) for i in input().split()]
def func_de(n):
ans = 0
while n/10 != 0:
ans += n % 10
n //= 10
return ans
ANS = 0
for i in range(N+1):
if A <= func_de(i) <= B:
ANS += i
print(ANS) | 7 | 15 | 173 | 249 | n, a, b = list(map(int, input().split()))
total = 0
for i in range(n + 1):
num = [int(d) for d in str(i)]
if sum(num) >= a and sum(num) <= b:
total += i
print(total)
| N, A, B = [int(i) for i in input().split()]
def func_de(n):
ans = 0
while n / 10 != 0:
ans += n % 10
n //= 10
return ans
ANS = 0
for i in range(N + 1):
if A <= func_de(i) <= B:
ANS += i
print(ANS)
| false | 53.333333 | [
"-n, a, b = list(map(int, input().split()))",
"-total = 0",
"-for i in range(n + 1):",
"- num = [int(d) for d in str(i)]",
"- if sum(num) >= a and sum(num) <= b:",
"- total += i",
"-print(total)",
"+N, A, B = [int(i) for i in input().split()]",
"+",
"+",
"+def func_de(n):",
"+ ... | false | 0.038363 | 0.042946 | 0.893298 | [
"s620557119",
"s995689448"
] |
u556225812 | p03213 | python | s721674231 | s117404065 | 20 | 18 | 3,188 | 3,064 | Accepted | Accepted | 10 | import math
dic = {}
N = int(eval(input()))
for i in range(2, N+1):
fact = []
while i % 2 == 0:
fact.append(2)
i //= 2
f = 3
while f*f <= i:
if i%f == 0:
fact.append(f)
i //= f
else:
f += 2
if i != 1:
fact.append(i)
for j in fact:
if j in dic:
dic[j] += 1
else:
dic[j] = 1
cnt = 0
s1 = len([k for k, v in list(dic.items()) if v >= 2])
s2 = len([k for k, v in list(dic.items()) if v >= 4])
s3 = len([k for k, v in list(dic.items()) if v >= 14])
s4 = len([k for k, v in list(dic.items()) if v >= 24])
s5 = len([k for k, v in list(dic.items()) if v >= 74])
#3*5*5
if s2 >= 2 and s1 >= 3:
cnt += s2*(s2-1)/2*(s1-2)
#15*5
if s3 >= 1:
cnt += s3*(s2-1)
#25*3
if s4 >= 1:
cnt += s4*(s1-1)
#75
if s5 >= 1:
cnt += s5
print((int(cnt))) | N = int(eval(input()))
e = [0]*(N+1)
for i in range(2, N+1):
cur = i
for j in range(2, i+1):
while cur % j == 0:
e[j] += 1
cur //= j
def num(m):
return len(list([x for x in e if x >= m-1]))
print((num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)//2)) | 42 | 12 | 884 | 333 | import math
dic = {}
N = int(eval(input()))
for i in range(2, N + 1):
fact = []
while i % 2 == 0:
fact.append(2)
i //= 2
f = 3
while f * f <= i:
if i % f == 0:
fact.append(f)
i //= f
else:
f += 2
if i != 1:
fact.append(i)
for j in fact:
if j in dic:
dic[j] += 1
else:
dic[j] = 1
cnt = 0
s1 = len([k for k, v in list(dic.items()) if v >= 2])
s2 = len([k for k, v in list(dic.items()) if v >= 4])
s3 = len([k for k, v in list(dic.items()) if v >= 14])
s4 = len([k for k, v in list(dic.items()) if v >= 24])
s5 = len([k for k, v in list(dic.items()) if v >= 74])
# 3*5*5
if s2 >= 2 and s1 >= 3:
cnt += s2 * (s2 - 1) / 2 * (s1 - 2)
# 15*5
if s3 >= 1:
cnt += s3 * (s2 - 1)
# 25*3
if s4 >= 1:
cnt += s4 * (s1 - 1)
# 75
if s5 >= 1:
cnt += s5
print((int(cnt)))
| N = int(eval(input()))
e = [0] * (N + 1)
for i in range(2, N + 1):
cur = i
for j in range(2, i + 1):
while cur % j == 0:
e[j] += 1
cur //= j
def num(m):
return len(list([x for x in e if x >= m - 1]))
print(
(
num(75)
+ num(25) * (num(3) - 1)
+ num(15) * (num(5) - 1)
+ num(5) * (num(5) - 1) * (num(3) - 2) // 2
)
)
| false | 71.428571 | [
"-import math",
"+N = int(eval(input()))",
"+e = [0] * (N + 1)",
"+for i in range(2, N + 1):",
"+ cur = i",
"+ for j in range(2, i + 1):",
"+ while cur % j == 0:",
"+ e[j] += 1",
"+ cur //= j",
"-dic = {}",
"-N = int(eval(input()))",
"-for i in range(2, N + 1... | false | 0.046701 | 0.167491 | 0.278829 | [
"s721674231",
"s117404065"
] |
u077291787 | p03061 | python | s725744586 | s154961303 | 222 | 194 | 16,144 | 16,264 | Accepted | Accepted | 12.61 | # ABC125C - GCD on Blackboard
# Accumulative GCD
from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
left[i + 1] = gcd(left[i], a[i])
right[n - i - 1] = gcd(right[n - i], a[n - i - 1])
ans = 0
for i in range(n):
ans = max(ans, gcd(left[i], right[i + 1]))
print(ans) | # ABC125C - GCD on Blackboard
# Accumulative GCD
from fractions import gcd
def main():
n = int(eval(input()))
a = tuple(map(int, input().rstrip().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
left[i + 1] = gcd(left[i], a[i])
right[n - i - 1] = gcd(right[n - i], a[n - i - 1])
ans = 0
for i in range(n):
ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)
if __name__ == "__main__":
main() | 17 | 22 | 394 | 496 | # ABC125C - GCD on Blackboard
# Accumulative GCD
from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
left[i + 1] = gcd(left[i], a[i])
right[n - i - 1] = gcd(right[n - i], a[n - i - 1])
ans = 0
for i in range(n):
ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)
| # ABC125C - GCD on Blackboard
# Accumulative GCD
from fractions import gcd
def main():
n = int(eval(input()))
a = tuple(map(int, input().rstrip().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
left[i + 1] = gcd(left[i], a[i])
right[n - i - 1] = gcd(right[n - i], a[n - i - 1])
ans = 0
for i in range(n):
ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)
if __name__ == "__main__":
main()
| false | 22.727273 | [
"-n = int(eval(input()))",
"-a = list(map(int, input().rstrip().split()))",
"-left = [0] * (n + 1)",
"-right = [0] * (n + 1)",
"-for i in range(n):",
"- left[i + 1] = gcd(left[i], a[i])",
"- right[n - i - 1] = gcd(right[n - i], a[n - i - 1])",
"-ans = 0",
"-for i in range(n):",
"- ans = m... | false | 0.107091 | 0.109971 | 0.973807 | [
"s725744586",
"s154961303"
] |
u072717685 | p03086 | python | s134636280 | s546420891 | 74 | 67 | 62,140 | 61,612 | Accepted | Accepted | 9.46 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = tuple(eval(input()))
r = 0
s_len = len(s)
for i1 in range(s_len):
for i2 in range(1, s_len - i1 + 1):
if all([c in ('A', 'T', 'C', 'G') for c in s[i1:i1+i2]]):
r = max(r, i2)
print(r)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = tuple(eval(input()))
r = 0
s_len = len(s)
for i1 in range(s_len):
for i2 in range(i1 + 1, s_len + 1):
if all([c in ('A', 'T', 'C', 'G') for c in s[i1:i2]]):
r = max(r, i2 - i1)
print(r)
if __name__ == '__main__':
main() | 15 | 15 | 368 | 369 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = tuple(eval(input()))
r = 0
s_len = len(s)
for i1 in range(s_len):
for i2 in range(1, s_len - i1 + 1):
if all([c in ("A", "T", "C", "G") for c in s[i1 : i1 + i2]]):
r = max(r, i2)
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = tuple(eval(input()))
r = 0
s_len = len(s)
for i1 in range(s_len):
for i2 in range(i1 + 1, s_len + 1):
if all([c in ("A", "T", "C", "G") for c in s[i1:i2]]):
r = max(r, i2 - i1)
print(r)
if __name__ == "__main__":
main()
| false | 0 | [
"- for i2 in range(1, s_len - i1 + 1):",
"- if all([c in (\"A\", \"T\", \"C\", \"G\") for c in s[i1 : i1 + i2]]):",
"- r = max(r, i2)",
"+ for i2 in range(i1 + 1, s_len + 1):",
"+ if all([c in (\"A\", \"T\", \"C\", \"G\") for c in s[i1:i2]]):",
"+ ... | false | 0.049537 | 0.047502 | 1.042831 | [
"s134636280",
"s546420891"
] |
u496280557 | p03543 | python | s031377035 | s008114586 | 32 | 26 | 8,928 | 8,876 | Accepted | Accepted | 18.75 | N = eval(input(''))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3] or N[0] == N[1] == N[2] == N[3]:
print('Yes')
else:
print('No') | N = eval(input(''))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print('Yes')
else:
print('No') | 5 | 5 | 137 | 105 | N = eval(input(""))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3] or N[0] == N[1] == N[2] == N[3]:
print("Yes")
else:
print("No")
| N = eval(input(""))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print("Yes")
else:
print("No")
| false | 0 | [
"-if N[0] == N[1] == N[2] or N[1] == N[2] == N[3] or N[0] == N[1] == N[2] == N[3]:",
"+if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:"
] | false | 0.07767 | 0.079677 | 0.974813 | [
"s031377035",
"s008114586"
] |
u260980560 | p01224 | python | s378547918 | s851323413 | 130 | 40 | 4,384 | 4,228 | Accepted | Accepted | 69.23 | from math import sqrt
P = "perfect number"
D = "deficient number"
A = "abundant number"
while True:
n = eval(input())
if n==0:
break
if n==1:
print(D)
continue
su = 1
temp = n
for i in range(2, int(sqrt(n))+1):
cnt = 0
while temp%i==0:
temp /= i
cnt += 1
if cnt:
su *= (i**(cnt+1)-1)/(i-1)
if temp==1:
su -= n
break
if temp!=1:
su *= (temp**2-1)/(temp-1)
su -= n
print(P if n==su else (D if su<n else A)) | P = "perfect number"
D = "deficient number"
A = "abundant number"
while True:
n = int(input())
if n==0:
break
if n==1:
print(D)
continue
su = 1
t = n
i = 2
while i**2<=t:
if t%i==0:
cnt = 0
while t%i==0:
t /= i
cnt += 1
su *= (i**(cnt+1)-1)/(i-1)
i += 1
if t>1:
su *= (t**2-1)/(t-1)
su -= n
print(P if n==su else (D if su<n else A)) | 27 | 25 | 587 | 514 | from math import sqrt
P = "perfect number"
D = "deficient number"
A = "abundant number"
while True:
n = eval(input())
if n == 0:
break
if n == 1:
print(D)
continue
su = 1
temp = n
for i in range(2, int(sqrt(n)) + 1):
cnt = 0
while temp % i == 0:
temp /= i
cnt += 1
if cnt:
su *= (i ** (cnt + 1) - 1) / (i - 1)
if temp == 1:
su -= n
break
if temp != 1:
su *= (temp**2 - 1) / (temp - 1)
su -= n
print(P if n == su else (D if su < n else A))
| P = "perfect number"
D = "deficient number"
A = "abundant number"
while True:
n = int(input())
if n == 0:
break
if n == 1:
print(D)
continue
su = 1
t = n
i = 2
while i**2 <= t:
if t % i == 0:
cnt = 0
while t % i == 0:
t /= i
cnt += 1
su *= (i ** (cnt + 1) - 1) / (i - 1)
i += 1
if t > 1:
su *= (t**2 - 1) / (t - 1)
su -= n
print(P if n == su else (D if su < n else A))
| false | 7.407407 | [
"-from math import sqrt",
"-",
"- n = eval(input())",
"+ n = int(input())",
"- temp = n",
"- for i in range(2, int(sqrt(n)) + 1):",
"- cnt = 0",
"- while temp % i == 0:",
"- temp /= i",
"- cnt += 1",
"- if cnt:",
"+ t = n",
"+ i = ... | false | 0.074703 | 0.090011 | 0.829932 | [
"s378547918",
"s851323413"
] |
u606878291 | p02880 | python | s505495989 | s656155750 | 24 | 18 | 3,060 | 3,060 | Accepted | Accepted | 25 | def main(n):
list1 = list(range(1, 10))
list2 = list(range(1, 10))
qq = set()
for a in list1:
for b in list2:
qq.add(a * b)
if n in qq:
return 'Yes'
else:
return 'No'
if __name__ == '__main__':
N = int(eval(input()))
print((main(N)))
| from itertools import product
N = int(eval(input()))
for a, b in product(list(range(1, 9 + 1)), repeat=2):
if N == a * b:
print('Yes')
break
else:
print('No')
| 16 | 10 | 299 | 182 | def main(n):
list1 = list(range(1, 10))
list2 = list(range(1, 10))
qq = set()
for a in list1:
for b in list2:
qq.add(a * b)
if n in qq:
return "Yes"
else:
return "No"
if __name__ == "__main__":
N = int(eval(input()))
print((main(N)))
| from itertools import product
N = int(eval(input()))
for a, b in product(list(range(1, 9 + 1)), repeat=2):
if N == a * b:
print("Yes")
break
else:
print("No")
| false | 37.5 | [
"-def main(n):",
"- list1 = list(range(1, 10))",
"- list2 = list(range(1, 10))",
"- qq = set()",
"- for a in list1:",
"- for b in list2:",
"- qq.add(a * b)",
"- if n in qq:",
"- return \"Yes\"",
"- else:",
"- return \"No\"",
"+from itertools im... | false | 0.044807 | 0.046362 | 0.966477 | [
"s505495989",
"s656155750"
] |
u633068244 | p00133 | python | s000546102 | s773766736 | 20 | 10 | 4,208 | 4,216 | Accepted | Accepted | 50 | d=[list(input()) for i in range(8)]
p=[d,[],[],[]]
for r in range(3):
print(90*(r+1))
for j in range(8):
p[r+1].append([p[r][i][j] for i in range(7,-1,-1)])
print("".join(p[r+1][j])) | p=[[list(input()) for i in range(8)],[],[],[]]
for r in range(3):
print(90*(r+1))
for j in range(8):
p[r+1].append([p[r][i][j] for i in range(7,-1,-1)])
print("".join(p[r+1][j])) | 7 | 6 | 196 | 191 | d = [list(input()) for i in range(8)]
p = [d, [], [], []]
for r in range(3):
print(90 * (r + 1))
for j in range(8):
p[r + 1].append([p[r][i][j] for i in range(7, -1, -1)])
print("".join(p[r + 1][j]))
| p = [[list(input()) for i in range(8)], [], [], []]
for r in range(3):
print(90 * (r + 1))
for j in range(8):
p[r + 1].append([p[r][i][j] for i in range(7, -1, -1)])
print("".join(p[r + 1][j]))
| false | 14.285714 | [
"-d = [list(input()) for i in range(8)]",
"-p = [d, [], [], []]",
"+p = [[list(input()) for i in range(8)], [], [], []]"
] | false | 0.037991 | 0.038456 | 0.987915 | [
"s000546102",
"s773766736"
] |
u627803856 | p02948 | python | s244351362 | s313541938 | 927 | 808 | 84,056 | 72,480 | Accepted | Accepted | 12.84 | from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = []
for i in range(n):
a, b = list(map(int, input().split()))
jobs.append([a, b])
jobs = sorted(jobs, key=lambda x:x[0])
hq = []
res, j = 0, 0
for i in range(1, m + 1):
while j < n and jobs[j][0] <= i:
heappush(hq, -jobs[j][1])
j += 1
if len(hq) > 0:
res += -heappop(hq)
print(res) | from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = [[] for _ in range(10 ** 5 + 100)]
# 隣接リストっぽく
for i in range(n):
a, b = list(map(int, input().split()))
jobs[a].append(b)
hq = []
res, j = 0, 0
for i in range(1, m + 1):
for v in jobs[i]:
heappush(hq, -v)
if len(hq) > 0:
res += -heappop(hq)
print(res) | 19 | 17 | 411 | 371 | from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = []
for i in range(n):
a, b = list(map(int, input().split()))
jobs.append([a, b])
jobs = sorted(jobs, key=lambda x: x[0])
hq = []
res, j = 0, 0
for i in range(1, m + 1):
while j < n and jobs[j][0] <= i:
heappush(hq, -jobs[j][1])
j += 1
if len(hq) > 0:
res += -heappop(hq)
print(res)
| from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = [[] for _ in range(10**5 + 100)]
# 隣接リストっぽく
for i in range(n):
a, b = list(map(int, input().split()))
jobs[a].append(b)
hq = []
res, j = 0, 0
for i in range(1, m + 1):
for v in jobs[i]:
heappush(hq, -v)
if len(hq) > 0:
res += -heappop(hq)
print(res)
| false | 10.526316 | [
"-jobs = []",
"+jobs = [[] for _ in range(10**5 + 100)]",
"+# 隣接リストっぽく",
"- jobs.append([a, b])",
"-jobs = sorted(jobs, key=lambda x: x[0])",
"+ jobs[a].append(b)",
"- while j < n and jobs[j][0] <= i:",
"- heappush(hq, -jobs[j][1])",
"- j += 1",
"+ for v in jobs[i]:",
"... | false | 0.089599 | 0.264496 | 0.338754 | [
"s244351362",
"s313541938"
] |
u761320129 | p03200 | python | s392698054 | s853584490 | 122 | 47 | 12,800 | 3,500 | Accepted | Accepted | 61.48 | S = eval(input())
bs = [0]
for c in S:
bs.append(bs[-1] + int(c=='B'))
ans = 0
for b,c in zip(bs[1:],S):
if c == 'W':
ans += b
print(ans) | S = eval(input())
ans = b = 0
for c in S:
if c == 'B':
b += 1
else:
ans += b
print(ans) | 10 | 9 | 157 | 114 | S = eval(input())
bs = [0]
for c in S:
bs.append(bs[-1] + int(c == "B"))
ans = 0
for b, c in zip(bs[1:], S):
if c == "W":
ans += b
print(ans)
| S = eval(input())
ans = b = 0
for c in S:
if c == "B":
b += 1
else:
ans += b
print(ans)
| false | 10 | [
"-bs = [0]",
"+ans = b = 0",
"- bs.append(bs[-1] + int(c == \"B\"))",
"-ans = 0",
"-for b, c in zip(bs[1:], S):",
"- if c == \"W\":",
"+ if c == \"B\":",
"+ b += 1",
"+ else:"
] | false | 0.075263 | 0.042217 | 1.782783 | [
"s392698054",
"s853584490"
] |
u414980766 | p02882 | python | s284325398 | s224250433 | 152 | 17 | 13,536 | 3,060 | Accepted | Accepted | 88.82 | import numpy as np
a, b, x = list(map(int, input().split()))
if x >= a*a*b/2:
l = 2*b - 2*x/(a**2)
print((np.rad2deg(np.arctan(l/a))))
else:
l = 2*x/(a*b)
print((np.rad2deg(np.arctan(b/l)))) | import math
a, b, x = list(map(int, input().split()))
if x >= a*a*b/2:
l = 2*b - 2*x/(a**2)
print((math.degrees(math.atan(l/a))))
else:
l = 2*x/(a*b)
print((math.degrees(math.atan(b/l)))) | 8 | 8 | 203 | 200 | import numpy as np
a, b, x = list(map(int, input().split()))
if x >= a * a * b / 2:
l = 2 * b - 2 * x / (a**2)
print((np.rad2deg(np.arctan(l / a))))
else:
l = 2 * x / (a * b)
print((np.rad2deg(np.arctan(b / l))))
| import math
a, b, x = list(map(int, input().split()))
if x >= a * a * b / 2:
l = 2 * b - 2 * x / (a**2)
print((math.degrees(math.atan(l / a))))
else:
l = 2 * x / (a * b)
print((math.degrees(math.atan(b / l))))
| false | 0 | [
"-import numpy as np",
"+import math",
"- print((np.rad2deg(np.arctan(l / a))))",
"+ print((math.degrees(math.atan(l / a))))",
"- print((np.rad2deg(np.arctan(b / l))))",
"+ print((math.degrees(math.atan(b / l))))"
] | false | 0.307469 | 0.035779 | 8.593655 | [
"s284325398",
"s224250433"
] |
u507116804 | p03635 | python | s074908839 | s014042207 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | n,m=list(map(int, input().split()))
print((int((n-1)*(m-1)))) | n,m=list(map(int, input().split()))
print(((n-1)*(m-1))) | 3 | 3 | 56 | 51 | n, m = list(map(int, input().split()))
print((int((n - 1) * (m - 1))))
| n, m = list(map(int, input().split()))
print(((n - 1) * (m - 1)))
| false | 0 | [
"-print((int((n - 1) * (m - 1))))",
"+print(((n - 1) * (m - 1)))"
] | false | 0.045751 | 0.042937 | 1.065554 | [
"s074908839",
"s014042207"
] |
u537067968 | p02244 | python | s032516453 | s554248402 | 460 | 390 | 6,312 | 6,296 | Accepted | Accepted | 15.22 | from functools import lru_cache
cc = [["." for i in range(8)] for j in range(8)]
@lru_cache(maxsize=None)
def dia(s,a,b):
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(s[i][j])
if j - (a - i) == b:
d.append(s[i][j])
if j + (i - a) == b:
d.append(s[i][j])
if j - (i - a) == b:
d.append(s[i][j])
except IndexError: continue
print(d)
return d
def check(cc,a,b):
ss = list(zip(*cc))
if 'Q' in cc[a]: return False
if 'Q' in ss[b]: return False
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(cc[i][j])
if j - (a - i) == b:
d.append(cc[i][j])
if j + (i - a) == b:
d.append(cc[i][j])
if j - (i - a) == b:
d.append(cc[i][j])
except IndexError: continue
if 'Q' in d: return False
return True
def chess(s,queen):
if queen == 8:
return s
for i in range(8):
for j in range(8):
if check(s,i,j):
sol = s
sol[i][j] = 'Q'
if chess(sol,queen+1) != [[]]:
return sol
else: sol[i][j] = "."
return [[]]
k = int(eval(input()))
for i in range(k):
a, b = input().split()
cc[int(a)][int(b)] = 'Q'
ans = chess(cc,k)
print(('\n'.join(list([''.join(x) for x in ans])) ))
| from functools import lru_cache
cc = [["." for i in range(8)] for j in range(8)]
def check(cc,a,b):
ss = list(zip(*cc))
if 'Q' in cc[a]: return False
if 'Q' in ss[b]: return False
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(cc[i][j])
if j - (a - i) == b:
d.append(cc[i][j])
if j + (i - a) == b:
d.append(cc[i][j])
if j - (i - a) == b:
d.append(cc[i][j])
except IndexError: continue
if 'Q' in d: return False
return True
def chess(s,queen):
if queen == 8:
return s
for i in range(8):
for j in range(8):
if check(s,i,j):
sol = s
sol[i][j] = 'Q'
if chess(sol,queen+1) != [[]]:
return sol
else: sol[i][j] = "."
return [[]]
k = int(eval(input()))
for i in range(k):
a, b = input().split()
cc[int(a)][int(b)] = 'Q'
ans = chess(cc,k)
print(('\n'.join(list([''.join(x) for x in ans])) ))
| 62 | 43 | 1,713 | 1,198 | from functools import lru_cache
cc = [["." for i in range(8)] for j in range(8)]
@lru_cache(maxsize=None)
def dia(s, a, b):
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(s[i][j])
if j - (a - i) == b:
d.append(s[i][j])
if j + (i - a) == b:
d.append(s[i][j])
if j - (i - a) == b:
d.append(s[i][j])
except IndexError:
continue
print(d)
return d
def check(cc, a, b):
ss = list(zip(*cc))
if "Q" in cc[a]:
return False
if "Q" in ss[b]:
return False
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(cc[i][j])
if j - (a - i) == b:
d.append(cc[i][j])
if j + (i - a) == b:
d.append(cc[i][j])
if j - (i - a) == b:
d.append(cc[i][j])
except IndexError:
continue
if "Q" in d:
return False
return True
def chess(s, queen):
if queen == 8:
return s
for i in range(8):
for j in range(8):
if check(s, i, j):
sol = s
sol[i][j] = "Q"
if chess(sol, queen + 1) != [[]]:
return sol
else:
sol[i][j] = "."
return [[]]
k = int(eval(input()))
for i in range(k):
a, b = input().split()
cc[int(a)][int(b)] = "Q"
ans = chess(cc, k)
print(("\n".join(list(["".join(x) for x in ans]))))
| from functools import lru_cache
cc = [["." for i in range(8)] for j in range(8)]
def check(cc, a, b):
ss = list(zip(*cc))
if "Q" in cc[a]:
return False
if "Q" in ss[b]:
return False
d = []
for i in range(8):
for j in range(8):
try:
if j + (a - i) == b:
d.append(cc[i][j])
if j - (a - i) == b:
d.append(cc[i][j])
if j + (i - a) == b:
d.append(cc[i][j])
if j - (i - a) == b:
d.append(cc[i][j])
except IndexError:
continue
if "Q" in d:
return False
return True
def chess(s, queen):
if queen == 8:
return s
for i in range(8):
for j in range(8):
if check(s, i, j):
sol = s
sol[i][j] = "Q"
if chess(sol, queen + 1) != [[]]:
return sol
else:
sol[i][j] = "."
return [[]]
k = int(eval(input()))
for i in range(k):
a, b = input().split()
cc[int(a)][int(b)] = "Q"
ans = chess(cc, k)
print(("\n".join(list(["".join(x) for x in ans]))))
| false | 30.645161 | [
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def dia(s, a, b):",
"- d = []",
"- for i in range(8):",
"- for j in range(8):",
"- try:",
"- if j + (a - i) == b:",
"- d.append(s[i][j])",
"- if j - (a - i) == b:",
"- ... | false | 0.348495 | 0.968064 | 0.359992 | [
"s032516453",
"s554248402"
] |
u671060652 | p02785 | python | s780636571 | s233345172 | 408 | 294 | 113,616 | 87,372 | Accepted | Accepted | 27.94 | import itertools
import math
import fractions
import functools
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort(reverse=True)
if k < n:
for i in range(k):
h[i] = 0
else:
h = [0] * len(h)
print((sum(h)))
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort(reverse=True)
if n >= k:
for i in range(k):
h[i] = 0
print((sum(h)))
else: print((0)) | 14 | 10 | 258 | 184 | import itertools
import math
import fractions
import functools
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort(reverse=True)
if k < n:
for i in range(k):
h[i] = 0
else:
h = [0] * len(h)
print((sum(h)))
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort(reverse=True)
if n >= k:
for i in range(k):
h[i] = 0
print((sum(h)))
else:
print((0))
| false | 28.571429 | [
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-",
"-if k < n:",
"+if n >= k:",
"+ print((sum(h)))",
"- h = [0] * len(h)",
"-print((sum(h)))",
"+ print((0))"
] | false | 0.046957 | 0.042766 | 1.098002 | [
"s780636571",
"s233345172"
] |
u020390084 | p02983 | python | s999055701 | s243317987 | 844 | 676 | 3,060 | 3,064 | Accepted | Accepted | 19.91 | l, r = list(map(int, input().split()))
answer = 2018
if r-l >= 2018:
answer = 0
else:
l = [i%2019 for i in range(l, r+1)]
l.sort()
for i in range(len(l)):
for j in range(i+1, len(l)):
answer = min(answer, l[i]*l[j]%2019)
print(answer) | #!/usr/bin/env python3
import sys
MOD = 2019 # type: int
def solve(L: int, R: int):
if R-L >= 2018:
print((0))
return
lr_all = list(range(L,R+1))
answer = 2019
for i in range(R-L+1):
for j in range(i+1,R-L+1):
answer = min(lr_all[i]*lr_all[j]%MOD,answer)
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
L = int(next(tokens)) # type: int
R = int(next(tokens)) # type: int
solve(L, R)
if __name__ == '__main__':
main()
| 13 | 33 | 260 | 680 | l, r = list(map(int, input().split()))
answer = 2018
if r - l >= 2018:
answer = 0
else:
l = [i % 2019 for i in range(l, r + 1)]
l.sort()
for i in range(len(l)):
for j in range(i + 1, len(l)):
answer = min(answer, l[i] * l[j] % 2019)
print(answer)
| #!/usr/bin/env python3
import sys
MOD = 2019 # type: int
def solve(L: int, R: int):
if R - L >= 2018:
print((0))
return
lr_all = list(range(L, R + 1))
answer = 2019
for i in range(R - L + 1):
for j in range(i + 1, R - L + 1):
answer = min(lr_all[i] * lr_all[j] % MOD, answer)
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
L = int(next(tokens)) # type: int
R = int(next(tokens)) # type: int
solve(L, R)
if __name__ == "__main__":
main()
| false | 60.606061 | [
"-l, r = list(map(int, input().split()))",
"-answer = 2018",
"-if r - l >= 2018:",
"- answer = 0",
"-else:",
"- l = [i % 2019 for i in range(l, r + 1)]",
"- l.sort()",
"- for i in range(len(l)):",
"- for j in range(i + 1, len(l)):",
"- answer = min(answer, l[i] * l[j]... | false | 0.069788 | 0.058524 | 1.192482 | [
"s999055701",
"s243317987"
] |
u790012205 | p03574 | python | s459645772 | s916264598 | 232 | 24 | 44,396 | 3,444 | Accepted | Accepted | 89.66 | H, W = map(int, input().split())
S = []
for i in range(H):
S.append(input())
A = []
for i in range(H + 2):
A.append([0] * (W + 2))
for i in range(H):
for j in range(W):
if S[i][j] == '#':
for k in range(3):
for l in range(3):
A[i + k][j + l] += 1
for i in range(H):
for j in range(W):
if S[i][j] == '#':
A[i + 1][j + 1] = '#'
for i in range(1, H + 1):
for j in range(1, W + 1):
print(A[i][j], end='')
print('')
| H, W = map(int, input().split())
S = [input() for i in range(H)]
B = []
B.append('.' * (W + 2))
for i in range(H):
B.append('.' + S[i] + '.')
B.append('.' * (W + 2))
for i in range(1, H + 1):
for j in range(1, W + 1):
if B[i][j] == '#':
print('#', end='')
continue
c = 0
if B[i - 1][j - 1] == '#':
c += 1
if B[i - 1][j + 1] == '#':
c += 1
if B[i + 1][j - 1] == '#':
c += 1
if B[i + 1][j + 1] == '#':
c += 1
if B[i][j - 1] == '#':
c += 1
if B[i][j + 1] == '#':
c += 1
if B[i + 1][j] == '#':
c += 1
if B[i - 1][j] == '#':
c += 1
print(c, end='')
print('')
| 24 | 31 | 544 | 804 | H, W = map(int, input().split())
S = []
for i in range(H):
S.append(input())
A = []
for i in range(H + 2):
A.append([0] * (W + 2))
for i in range(H):
for j in range(W):
if S[i][j] == "#":
for k in range(3):
for l in range(3):
A[i + k][j + l] += 1
for i in range(H):
for j in range(W):
if S[i][j] == "#":
A[i + 1][j + 1] = "#"
for i in range(1, H + 1):
for j in range(1, W + 1):
print(A[i][j], end="")
print("")
| H, W = map(int, input().split())
S = [input() for i in range(H)]
B = []
B.append("." * (W + 2))
for i in range(H):
B.append("." + S[i] + ".")
B.append("." * (W + 2))
for i in range(1, H + 1):
for j in range(1, W + 1):
if B[i][j] == "#":
print("#", end="")
continue
c = 0
if B[i - 1][j - 1] == "#":
c += 1
if B[i - 1][j + 1] == "#":
c += 1
if B[i + 1][j - 1] == "#":
c += 1
if B[i + 1][j + 1] == "#":
c += 1
if B[i][j - 1] == "#":
c += 1
if B[i][j + 1] == "#":
c += 1
if B[i + 1][j] == "#":
c += 1
if B[i - 1][j] == "#":
c += 1
print(c, end="")
print("")
| false | 22.580645 | [
"-S = []",
"+S = [input() for i in range(H)]",
"+B = []",
"+B.append(\".\" * (W + 2))",
"- S.append(input())",
"-A = []",
"-for i in range(H + 2):",
"- A.append([0] * (W + 2))",
"-for i in range(H):",
"- for j in range(W):",
"- if S[i][j] == \"#\":",
"- for k in rang... | false | 0.175822 | 0.041126 | 4.275224 | [
"s459645772",
"s916264598"
] |
u130900604 | p02743 | python | s860587369 | s528405933 | 403 | 17 | 5,076 | 2,940 | Accepted | Accepted | 95.78 | def mi():return list(map(str,input().split()))
from decimal import *
a,b,c=mi()
getcontext().prec=1500
a=Decimal(a)**Decimal("0.50")
b=Decimal(b)**Decimal("0.50")
c=Decimal(c)**Decimal("0.50")
if c>a+b:
print("Yes")
else:
print("No")
| a,b,c=list(map(int,input().split()))
d=c-a-b
if d<0:print("No");exit()
if 4*a*b<d**2:
print("Yes")
else:
print("No") | 15 | 9 | 254 | 124 | def mi():
return list(map(str, input().split()))
from decimal import *
a, b, c = mi()
getcontext().prec = 1500
a = Decimal(a) ** Decimal("0.50")
b = Decimal(b) ** Decimal("0.50")
c = Decimal(c) ** Decimal("0.50")
if c > a + b:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
d = c - a - b
if d < 0:
print("No")
exit()
if 4 * a * b < d**2:
print("Yes")
else:
print("No")
| false | 40 | [
"-def mi():",
"- return list(map(str, input().split()))",
"-",
"-",
"-from decimal import *",
"-",
"-a, b, c = mi()",
"-getcontext().prec = 1500",
"-a = Decimal(a) ** Decimal(\"0.50\")",
"-b = Decimal(b) ** Decimal(\"0.50\")",
"-c = Decimal(c) ** Decimal(\"0.50\")",
"-if c > a + b:",
"+a,... | false | 2.098214 | 0.038205 | 54.920266 | [
"s860587369",
"s528405933"
] |
u634046173 | p04030 | python | s341830506 | s282137847 | 67 | 60 | 61,824 | 61,552 | Accepted | Accepted | 10.45 | S = eval(input())
es =''
for s in S:
if s == '1' or s == '0':
es+=s
else:
if es != '':
es=es[:-1]
print(es) | S = eval(input())
es =''
for s in S:
if s == '1' or s == '0':
es+=s
else:
#if es != '':
es=es[:-1]
print(es) | 9 | 9 | 145 | 142 | S = eval(input())
es = ""
for s in S:
if s == "1" or s == "0":
es += s
else:
if es != "":
es = es[:-1]
print(es)
| S = eval(input())
es = ""
for s in S:
if s == "1" or s == "0":
es += s
else:
# if es != '':
es = es[:-1]
print(es)
| false | 0 | [
"- if es != \"\":",
"- es = es[:-1]",
"+ # if es != '':",
"+ es = es[:-1]"
] | false | 0.050261 | 0.048601 | 1.034169 | [
"s341830506",
"s282137847"
] |
u790710233 | p03103 | python | s106652161 | s120311160 | 452 | 312 | 17,000 | 16,896 | Accepted | Accepted | 30.97 | n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
buy = [m, b][0 <= m-b]
m -= buy
ans += a*buy
print(ans)
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
buy = [m, b][0 <= m-b]
m -= buy
ans += a*buy
print(ans)
| 10 | 11 | 203 | 241 | n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
buy = [m, b][0 <= m - b]
m -= buy
ans += a * buy
print(ans)
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
buy = [m, b][0 <= m - b]
m -= buy
ans += a * buy
print(ans)
| false | 9.090909 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.035299 | 0.034567 | 1.021172 | [
"s106652161",
"s120311160"
] |
u694665829 | p02803 | python | s033812095 | s834275132 | 321 | 248 | 9,576 | 9,260 | Accepted | Accepted | 22.74 | from collections import *
from copy import *
H,W = list(map(int,input().split()))
S = [(W+2)*["#"]]+[["#"]+list(eval(input()))+["#"] for h in range(H)]+[(W+2)*["#"]]
D = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 0
P = deque([])
Q = deque([])
for h in range(1,H+1):
for w in range(1,W+1):
if S[h][w]==".":
P+=[[h,w]]
while P:
T = deepcopy(S)
sx,sy = P.popleft()
T[sx][sy] = 0
Q = deque([[sx,sy]])
while Q:
x,y = Q.popleft()
for dx,dy in D:
if T[x+dx][y+dy]==".":
T[x+dx][y+dy] = T[x][y]+1
Q+=[[x+dx,y+dy]]
ans = max(ans,T[x+dx][y+dy])
print(ans) | H, W = list(map(int,input().split()))
s = [list(eval(input())) for j in range(H)]
def bfs(h, w):
checked = [[False for i in range(W)] for j in range(H)]
q = [(h, w, 0)] if s[h][w] == '.' else []
checked[h][w] = True
g_n = 0
while q:
h_, w_, n = q.pop(0)
g_n = max(n, g_n)
for i, j in zip([0,0,-1,1],[-1,1,0,0]):
if (0 <= h_+i < H) and (0 <= w_+j < W):
if checked[h_+i][w_+j]: continue
checked[h_+i][w_+j] = True
if s[h_+i][w_+j] == '.': q.append((h_+i, w_+j, n+1))
return g_n
n = 0
for i in range(H):
for j in range(W):
n = max(n, bfs(i,j))
print(n) | 28 | 24 | 617 | 683 | from collections import *
from copy import *
H, W = list(map(int, input().split()))
S = (
[(W + 2) * ["#"]]
+ [["#"] + list(eval(input())) + ["#"] for h in range(H)]
+ [(W + 2) * ["#"]]
)
D = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0
P = deque([])
Q = deque([])
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == ".":
P += [[h, w]]
while P:
T = deepcopy(S)
sx, sy = P.popleft()
T[sx][sy] = 0
Q = deque([[sx, sy]])
while Q:
x, y = Q.popleft()
for dx, dy in D:
if T[x + dx][y + dy] == ".":
T[x + dx][y + dy] = T[x][y] + 1
Q += [[x + dx, y + dy]]
ans = max(ans, T[x + dx][y + dy])
print(ans)
| H, W = list(map(int, input().split()))
s = [list(eval(input())) for j in range(H)]
def bfs(h, w):
checked = [[False for i in range(W)] for j in range(H)]
q = [(h, w, 0)] if s[h][w] == "." else []
checked[h][w] = True
g_n = 0
while q:
h_, w_, n = q.pop(0)
g_n = max(n, g_n)
for i, j in zip([0, 0, -1, 1], [-1, 1, 0, 0]):
if (0 <= h_ + i < H) and (0 <= w_ + j < W):
if checked[h_ + i][w_ + j]:
continue
checked[h_ + i][w_ + j] = True
if s[h_ + i][w_ + j] == ".":
q.append((h_ + i, w_ + j, n + 1))
return g_n
n = 0
for i in range(H):
for j in range(W):
n = max(n, bfs(i, j))
print(n)
| false | 14.285714 | [
"-from collections import *",
"-from copy import *",
"+H, W = list(map(int, input().split()))",
"+s = [list(eval(input())) for j in range(H)]",
"-H, W = list(map(int, input().split()))",
"-S = (",
"- [(W + 2) * [\"#\"]]",
"- + [[\"#\"] + list(eval(input())) + [\"#\"] for h in range(H)]",
"- ... | false | 0.038393 | 0.036515 | 1.051409 | [
"s033812095",
"s834275132"
] |
u417743183 | p02996 | python | s316972118 | s027437757 | 635 | 518 | 48,604 | 38,948 | Accepted | Accepted | 18.43 | ABs = []
N = int(eval(input()))
for i in range(N):
ABs.append(list(map(int,input().split())))
ABs = sorted(ABs, key=lambda x: x[1])
sum = 0
for pair in ABs:
sum += pair[0]
if sum > pair[1]:
print('No')
exit()
print('Yes') | ABs = []
N = int(eval(input()))
for i in range(N):
ABs.append(tuple(map(int,input().split())))
ABs = sorted(ABs, key=lambda x: x[1])
sum = 0
for A, B in ABs:
sum += A
if sum > B:
print('No')
exit()
print('Yes') | 15 | 15 | 260 | 249 | ABs = []
N = int(eval(input()))
for i in range(N):
ABs.append(list(map(int, input().split())))
ABs = sorted(ABs, key=lambda x: x[1])
sum = 0
for pair in ABs:
sum += pair[0]
if sum > pair[1]:
print("No")
exit()
print("Yes")
| ABs = []
N = int(eval(input()))
for i in range(N):
ABs.append(tuple(map(int, input().split())))
ABs = sorted(ABs, key=lambda x: x[1])
sum = 0
for A, B in ABs:
sum += A
if sum > B:
print("No")
exit()
print("Yes")
| false | 0 | [
"- ABs.append(list(map(int, input().split())))",
"+ ABs.append(tuple(map(int, input().split())))",
"-for pair in ABs:",
"- sum += pair[0]",
"- if sum > pair[1]:",
"+for A, B in ABs:",
"+ sum += A",
"+ if sum > B:"
] | false | 0.042543 | 0.038173 | 1.114495 | [
"s316972118",
"s027437757"
] |
u678167152 | p03166 | python | s783221664 | s175678773 | 396 | 162 | 107,452 | 89,148 | Accepted | Accepted | 59.09 | N, M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
to = [False]*N
for i in range(M):
a,b = list(map(int, input().split()))
edge[a-1].append(b-1)
to[b-1] = True
import sys
sys.setrecursionlimit(10**8)
def dfs(v):
if lis[v]>=0:
return lis[v]
if len(edge[v])==0:
lis[v] = 1
return 1
ans = 0
for u in edge[v]:
ans = max(ans, dfs(u))
lis[v] = ans+1
return ans+1
ans = 0
lis = [-1]*N
for r in range(N):
if to[r]==False:
ans = max(ans, dfs(r)-1)
print(ans) | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(M):
a,b = list(map(int, input().split()))
edge[a-1].append(b-1)
def dfs(start):
stack = [start]
while stack:
v = stack[-1]
marker = 0
path_l[v] = 0
for u in edge[v]:
if path_l[u]==-1: #子へ降ろす
marker = 1
stack.append(u)
else: #子から吸い上げる
#吸い上げる際の個々の処理
path_l[v] = max(path_l[v], path_l[u]+1)
if marker==0:
stack.pop()
return
path_l = [-1]*N
for i in range(N):
if path_l[i]==-1:
dfs(i)
ans = max(path_l)
print(ans)
| 29 | 32 | 526 | 640 | N, M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
to = [False] * N
for i in range(M):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
to[b - 1] = True
import sys
sys.setrecursionlimit(10**8)
def dfs(v):
if lis[v] >= 0:
return lis[v]
if len(edge[v]) == 0:
lis[v] = 1
return 1
ans = 0
for u in edge[v]:
ans = max(ans, dfs(u))
lis[v] = ans + 1
return ans + 1
ans = 0
lis = [-1] * N
for r in range(N):
if to[r] == False:
ans = max(ans, dfs(r) - 1)
print(ans)
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
def dfs(start):
stack = [start]
while stack:
v = stack[-1]
marker = 0
path_l[v] = 0
for u in edge[v]:
if path_l[u] == -1: # 子へ降ろす
marker = 1
stack.append(u)
else: # 子から吸い上げる
# 吸い上げる際の個々の処理
path_l[v] = max(path_l[v], path_l[u] + 1)
if marker == 0:
stack.pop()
return
path_l = [-1] * N
for i in range(N):
if path_l[i] == -1:
dfs(i)
ans = max(path_l)
print(ans)
| false | 9.375 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-to = [False] * N",
"- to[b - 1] = True",
"-import sys",
"-",
"-sys.setrecursionlimit(10**8)",
"-def dfs(v):",
"- if lis[v] >= 0:",
"- return lis[v]",
"- if len(edge[v]) == 0:",
"- lis[v] = 1",
"- return 1",
... | false | 0.036749 | 0.054066 | 0.67971 | [
"s783221664",
"s175678773"
] |
u563838154 | p02756 | python | s837506757 | s120993417 | 1,341 | 455 | 40,616 | 40,436 | Accepted | Accepted | 66.07 | s = eval(input())
q = int(eval(input()))
a = []
# for j in range(q):
# a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
pre = ""
nex = ""
c = 1
TFC = [input().split() for _ in range(q)]
for i in TFC:
# for j in range(q):
# i = list(map(str,input().split()))
if i ==["1"]:
c *= -1
# s = s[::-1]
elif i[0]=="2" and i[1]=="1":
# s = i[2]+s
if c == 1:
pre=i[2]+pre
else:
nex = nex + i[2]
elif i[0]=="2" and i[1]=="2":
# s = s +i[2]
if c ==1:
nex = nex +i[2]
else:
pre = i[2]+pre
s = pre+s+nex
if c ==-1:
s = s[::-1]
print(s) | s = eval(input())
q = int(eval(input()))
a = []
# for j in range(q):
# a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
pre = ""
nex = ""
c = 1
TFC = [input().split() for _ in range(q)]
for i in TFC:
# for j in range(q):
# i = list(map(str,input().split()))
if i ==["1"]:
c *= -1
# s = s[::-1]
elif i[0]=="2" and i[1]=="1":
# s = i[2]+s
if c == 1:
pre=pre+i[2]
else:
nex = nex + i[2]
elif i[0]=="2" and i[1]=="2":
# s = s +i[2]
if c ==1:
nex = nex +i[2]
else:
pre = pre+i[2]
if c==-1:
print((nex[::-1]+s[::-1]+pre))
else:
print((pre[::-1]+s+nex)) | 33 | 33 | 697 | 723 | s = eval(input())
q = int(eval(input()))
a = []
# for j in range(q):
# a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
pre = ""
nex = ""
c = 1
TFC = [input().split() for _ in range(q)]
for i in TFC:
# for j in range(q):
# i = list(map(str,input().split()))
if i == ["1"]:
c *= -1
# s = s[::-1]
elif i[0] == "2" and i[1] == "1":
# s = i[2]+s
if c == 1:
pre = i[2] + pre
else:
nex = nex + i[2]
elif i[0] == "2" and i[1] == "2":
# s = s +i[2]
if c == 1:
nex = nex + i[2]
else:
pre = i[2] + pre
s = pre + s + nex
if c == -1:
s = s[::-1]
print(s)
| s = eval(input())
q = int(eval(input()))
a = []
# for j in range(q):
# a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
pre = ""
nex = ""
c = 1
TFC = [input().split() for _ in range(q)]
for i in TFC:
# for j in range(q):
# i = list(map(str,input().split()))
if i == ["1"]:
c *= -1
# s = s[::-1]
elif i[0] == "2" and i[1] == "1":
# s = i[2]+s
if c == 1:
pre = pre + i[2]
else:
nex = nex + i[2]
elif i[0] == "2" and i[1] == "2":
# s = s +i[2]
if c == 1:
nex = nex + i[2]
else:
pre = pre + i[2]
if c == -1:
print((nex[::-1] + s[::-1] + pre))
else:
print((pre[::-1] + s + nex))
| false | 0 | [
"- pre = i[2] + pre",
"+ pre = pre + i[2]",
"- pre = i[2] + pre",
"-s = pre + s + nex",
"+ pre = pre + i[2]",
"- s = s[::-1]",
"-print(s)",
"+ print((nex[::-1] + s[::-1] + pre))",
"+else:",
"+ print((pre[::-1] + s + nex))"
] | false | 0.036918 | 0.056291 | 0.655832 | [
"s837506757",
"s120993417"
] |
u670180528 | p03014 | python | s089137758 | s647275569 | 1,849 | 1,583 | 211,336 | 183,132 | Accepted | Accepted | 14.39 | t,*l=open(0)
h,w=list(map(int,t.split()))
grid = [[c=="."for c in C]for C in l]
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
for x in range(w):
L[y+1][x+1] = (L[y+1][x]+1)*grid[y][x]
R[y+1][w-x] = (R[y+1][w-x+1]+1)*grid[y][w-x-1]
for x in range(w):
for y in range(h):
U[y+1][x+1] = (U[y][x+1]+1)*grid[y][x]
D[h-y][x+1] = (D[h-y+1][x+1]+1)*grid[h-y-1][x]
print((max(L[y][x] + R[y][x] + U[y][x] + D[y][x] -3 for y in range(1,h+1) for x in range(1,w+1)))) | t,*grid = open(0)
h,w = list(map(int,t.split()))
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
for x in range(w):
if grid[y][x]==".":
L[y+1][x+1] = L[y+1][x]+1
if grid[y][w-x-1]==".":
R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
for y in range(h):
if grid[y][x]==".":
U[y+1][x+1] = U[y][x+1]+1
if grid[h-y-1][x]==".":
D[h-y][x+1] = D[h-y+1][x+1]+1
print((max(L[y][x] + R[y][x] + U[y][x] + D[y][x] -3 for y in range(1,h+1) for x in range(1,w+1)))) | 13 | 16 | 493 | 505 | t, *l = open(0)
h, w = list(map(int, t.split()))
grid = [[c == "." for c in C] for C in l]
L, R, U, D = eval("[[0]*(w+2) for _ in range(h+2)]," * 4)
for y in range(h):
for x in range(w):
L[y + 1][x + 1] = (L[y + 1][x] + 1) * grid[y][x]
R[y + 1][w - x] = (R[y + 1][w - x + 1] + 1) * grid[y][w - x - 1]
for x in range(w):
for y in range(h):
U[y + 1][x + 1] = (U[y][x + 1] + 1) * grid[y][x]
D[h - y][x + 1] = (D[h - y + 1][x + 1] + 1) * grid[h - y - 1][x]
print(
(
max(
L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
for y in range(1, h + 1)
for x in range(1, w + 1)
)
)
)
| t, *grid = open(0)
h, w = list(map(int, t.split()))
L, R, U, D = eval("[[0]*(w+2) for _ in range(h+2)]," * 4)
for y in range(h):
for x in range(w):
if grid[y][x] == ".":
L[y + 1][x + 1] = L[y + 1][x] + 1
if grid[y][w - x - 1] == ".":
R[y + 1][w - x] = R[y + 1][w - x + 1] + 1
for x in range(w):
for y in range(h):
if grid[y][x] == ".":
U[y + 1][x + 1] = U[y][x + 1] + 1
if grid[h - y - 1][x] == ".":
D[h - y][x + 1] = D[h - y + 1][x + 1] + 1
print(
(
max(
L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
for y in range(1, h + 1)
for x in range(1, w + 1)
)
)
)
| false | 18.75 | [
"-t, *l = open(0)",
"+t, *grid = open(0)",
"-grid = [[c == \".\" for c in C] for C in l]",
"- L[y + 1][x + 1] = (L[y + 1][x] + 1) * grid[y][x]",
"- R[y + 1][w - x] = (R[y + 1][w - x + 1] + 1) * grid[y][w - x - 1]",
"+ if grid[y][x] == \".\":",
"+ L[y + 1][x + 1] = L[y + 1... | false | 0.049099 | 0.044184 | 1.11125 | [
"s089137758",
"s647275569"
] |
u133347536 | p03329 | python | s743602761 | s653121343 | 785 | 615 | 3,828 | 3,828 | Accepted | Accepted | 21.66 | # 配るDP
n = int(eval(input()))
max_n = 110000
dp = [n] * max_n
# 初期化
dp[0] = 0
for i in range(n):
pow6, pow9 = 1, 1
while i + pow6 <= n:
dp[i + pow6] = min(dp[i + pow6], dp[i] + 1)
pow6 *= 6
while i + pow9 <= n:
dp[i + pow9] = min(dp[i + pow9], dp[i] + 1)
pow9 *= 9
print((dp[n]))
| # 貰うDP
n = int(eval(input()))
max_n = 110000
dp = [n] * max_n
# 初期化
dp[0] = 0
for i in range(1, n + 1):
pow6, pow9 = 1, 1
while pow6 <= i:
dp[i] = min(dp[i], dp[i - pow6] + 1)
pow6 *= 6
while pow9 <= i:
dp[i] = min(dp[i], dp[i - pow9] + 1)
pow9 *= 9
print((dp[n]))
| 20 | 21 | 340 | 327 | # 配るDP
n = int(eval(input()))
max_n = 110000
dp = [n] * max_n
# 初期化
dp[0] = 0
for i in range(n):
pow6, pow9 = 1, 1
while i + pow6 <= n:
dp[i + pow6] = min(dp[i + pow6], dp[i] + 1)
pow6 *= 6
while i + pow9 <= n:
dp[i + pow9] = min(dp[i + pow9], dp[i] + 1)
pow9 *= 9
print((dp[n]))
| # 貰うDP
n = int(eval(input()))
max_n = 110000
dp = [n] * max_n
# 初期化
dp[0] = 0
for i in range(1, n + 1):
pow6, pow9 = 1, 1
while pow6 <= i:
dp[i] = min(dp[i], dp[i - pow6] + 1)
pow6 *= 6
while pow9 <= i:
dp[i] = min(dp[i], dp[i - pow9] + 1)
pow9 *= 9
print((dp[n]))
| false | 4.761905 | [
"-# 配るDP",
"+# 貰うDP",
"-for i in range(n):",
"+for i in range(1, n + 1):",
"- while i + pow6 <= n:",
"- dp[i + pow6] = min(dp[i + pow6], dp[i] + 1)",
"+ while pow6 <= i:",
"+ dp[i] = min(dp[i], dp[i - pow6] + 1)",
"- while i + pow9 <= n:",
"- dp[i + pow9] = min(dp[i +... | false | 0.108275 | 0.206438 | 0.524491 | [
"s743602761",
"s653121343"
] |
u790710233 | p02748 | python | s286228263 | s574336493 | 504 | 417 | 18,736 | 18,648 | Accepted | Accepted | 17.26 | a, b, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = []
for _ in range(m):
x, y, c = list(map(int, input().split()))
x -= 1
y -= 1
AB.append(A[x]+B[y]-c)
AB.sort()
A.sort()
B.sort()
print((min(AB[0], A[0]+B[0])))
| a, b, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = min(A)+min(B)
for _ in range(m):
x, y, c = list(map(int, input().split()))
x -= 1
y -= 1
z = A[x]+B[y]-c
if z < ans:
ans = z
print(ans)
| 13 | 12 | 293 | 283 | a, b, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = []
for _ in range(m):
x, y, c = list(map(int, input().split()))
x -= 1
y -= 1
AB.append(A[x] + B[y] - c)
AB.sort()
A.sort()
B.sort()
print((min(AB[0], A[0] + B[0])))
| a, b, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = min(A) + min(B)
for _ in range(m):
x, y, c = list(map(int, input().split()))
x -= 1
y -= 1
z = A[x] + B[y] - c
if z < ans:
ans = z
print(ans)
| false | 7.692308 | [
"-AB = []",
"+ans = min(A) + min(B)",
"- AB.append(A[x] + B[y] - c)",
"-AB.sort()",
"-A.sort()",
"-B.sort()",
"-print((min(AB[0], A[0] + B[0])))",
"+ z = A[x] + B[y] - c",
"+ if z < ans:",
"+ ans = z",
"+print(ans)"
] | false | 0.038563 | 0.043811 | 0.880207 | [
"s286228263",
"s574336493"
] |
u932465688 | p03142 | python | s428362865 | s545963707 | 855 | 755 | 30,156 | 30,220 | Accepted | Accepted | 11.7 | from collections import deque
n,m = list(map(int,input().split()))
DAG = [[] for i in range(n)]
ins = [0]*n
ans = []
for i in range(n+m-1):
a,b = list(map(int,input().split()))
DAG[a-1].append(b-1)
ins[b-1] += 1
S = deque([])
for i in range(n):
if ins[i] == 0:
S.append([i,i])
while len(S) > 0:
cur = S.popleft()
ans.append(cur)
for e in DAG[cur[0]]:
ins[e] -= 1
if ins[e] == 0:
S.append([e,cur[0]])
ans.sort()
for i in range(n):
if ans[i][0] == ans[i][1]:
print((0))
else:
print((ans[i][1]+1)) | from collections import deque
n,m = list(map(int,input().split()))
outs = [[] for i in range(n)]
ins = [0]*n
ans = []
for i in range(n+m-1):
a,b = list(map(int,input().split()))
outs[a-1].append(b-1)
ins[b-1] += 1
S = deque([])
for i in range(n):
if ins[i] == 0:
S.append([i,i])
while len(S) > 0:
cur = S.popleft()
ans.append(cur)
for e in outs[cur[0]]:
ins[e] -= 1
if ins[e] == 0:
S.append([e,cur[0]])
ans.sort()
for i in range(n):
if ans[i][0] == ans[i][1]:
print((0))
else:
print((ans[i][1]+1)) | 27 | 27 | 581 | 584 | from collections import deque
n, m = list(map(int, input().split()))
DAG = [[] for i in range(n)]
ins = [0] * n
ans = []
for i in range(n + m - 1):
a, b = list(map(int, input().split()))
DAG[a - 1].append(b - 1)
ins[b - 1] += 1
S = deque([])
for i in range(n):
if ins[i] == 0:
S.append([i, i])
while len(S) > 0:
cur = S.popleft()
ans.append(cur)
for e in DAG[cur[0]]:
ins[e] -= 1
if ins[e] == 0:
S.append([e, cur[0]])
ans.sort()
for i in range(n):
if ans[i][0] == ans[i][1]:
print((0))
else:
print((ans[i][1] + 1))
| from collections import deque
n, m = list(map(int, input().split()))
outs = [[] for i in range(n)]
ins = [0] * n
ans = []
for i in range(n + m - 1):
a, b = list(map(int, input().split()))
outs[a - 1].append(b - 1)
ins[b - 1] += 1
S = deque([])
for i in range(n):
if ins[i] == 0:
S.append([i, i])
while len(S) > 0:
cur = S.popleft()
ans.append(cur)
for e in outs[cur[0]]:
ins[e] -= 1
if ins[e] == 0:
S.append([e, cur[0]])
ans.sort()
for i in range(n):
if ans[i][0] == ans[i][1]:
print((0))
else:
print((ans[i][1] + 1))
| false | 0 | [
"-DAG = [[] for i in range(n)]",
"+outs = [[] for i in range(n)]",
"- DAG[a - 1].append(b - 1)",
"+ outs[a - 1].append(b - 1)",
"- for e in DAG[cur[0]]:",
"+ for e in outs[cur[0]]:"
] | false | 0.032676 | 0.034851 | 0.937596 | [
"s428362865",
"s545963707"
] |
u754022296 | p02684 | python | s281758207 | s470118781 | 262 | 153 | 219,184 | 32,256 | Accepted | Accepted | 41.6 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
def f(i):
if i == 1:
return A
L = [-1]*(n+1)
if i & 1:
F = f(i-1)
for j in range(n+1):
L[j] = A[F[j]]
else:
F = f(i//2)
for j in range(n+1):
L[j] = F[F[j]]
return L
F = f(k)
ans = F[1]
print(ans) | n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
D = [1]
seen = [0]*n
seen[0] = 1
now = 0
while True:
now = A[now] - 1
D.append(now+1)
if seen[now]:
break
seen[now] = 1
f = D.index(D[-1])
if k < f:
print((D[k]))
else:
cycle = len(D) - f - 1
k -= f
print((D[f + k%(cycle)])) | 22 | 19 | 401 | 347 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
def f(i):
if i == 1:
return A
L = [-1] * (n + 1)
if i & 1:
F = f(i - 1)
for j in range(n + 1):
L[j] = A[F[j]]
else:
F = f(i // 2)
for j in range(n + 1):
L[j] = F[F[j]]
return L
F = f(k)
ans = F[1]
print(ans)
| n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
D = [1]
seen = [0] * n
seen[0] = 1
now = 0
while True:
now = A[now] - 1
D.append(now + 1)
if seen[now]:
break
seen[now] = 1
f = D.index(D[-1])
if k < f:
print((D[k]))
else:
cycle = len(D) - f - 1
k -= f
print((D[f + k % (cycle)]))
| false | 13.636364 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-A = [0] + list(map(int, input().split()))",
"-",
"-",
"-def f(i):",
"- if i == 1:",
"- return A",
"- L = [-1] * (n + 1)",
"- if i & 1:",
"- F = f(i - 1)",
"- for j in range(n... | false | 0.064292 | 0.036119 | 1.780033 | [
"s281758207",
"s470118781"
] |
u633068244 | p02269 | python | s186274424 | s326933205 | 3,690 | 1,300 | 124,308 | 62,708 | Accepted | Accepted | 64.77 | dict = {"A":1,"C":2,"G":3,"T":4}
def a2n(a):
ans = 0
for i in range(len(a)):
ans += dict[a[i]]*4**i
return ans
n = int(input())
ls = [0 for i in range(3000000)]
for i in range(n):
inp = input()
if inp[0] == "i":
ls[a2n(inp[7:])] = 1
else:
print("yes" if ls[a2n(inp[5:])] else "no")
| n = int(input())
ls = {}
for i in range(n):
inp = input()
if inp[0] == "i":
ls[inp[7:]] = 1
else:
try:
if ls[inp[5:]] == 1: print("yes")
except:
print("no")
| 16 | 12 | 351 | 240 | dict = {"A": 1, "C": 2, "G": 3, "T": 4}
def a2n(a):
ans = 0
for i in range(len(a)):
ans += dict[a[i]] * 4**i
return ans
n = int(input())
ls = [0 for i in range(3000000)]
for i in range(n):
inp = input()
if inp[0] == "i":
ls[a2n(inp[7:])] = 1
else:
print("yes" if ls[a2n(inp[5:])] else "no")
| n = int(input())
ls = {}
for i in range(n):
inp = input()
if inp[0] == "i":
ls[inp[7:]] = 1
else:
try:
if ls[inp[5:]] == 1:
print("yes")
except:
print("no")
| false | 25 | [
"-dict = {\"A\": 1, \"C\": 2, \"G\": 3, \"T\": 4}",
"-",
"-",
"-def a2n(a):",
"- ans = 0",
"- for i in range(len(a)):",
"- ans += dict[a[i]] * 4**i",
"- return ans",
"-",
"-",
"-ls = [0 for i in range(3000000)]",
"+ls = {}",
"- ls[a2n(inp[7:])] = 1",
"+ ls[inp... | false | 0.203731 | 0.036521 | 5.578397 | [
"s186274424",
"s326933205"
] |
u163313981 | p02783 | python | s368334894 | s664311667 | 29 | 26 | 9,128 | 9,156 | Accepted | Accepted | 10.34 | import math
def main():
hp, attack = (int(i) for i in input().rstrip().split(' '))
print((str(math.ceil(hp / attack))))
if __name__ == '__main__':
main()
| import math
def main():
hp, attack = (int(i) for i in input().rstrip().split(' '))
ans = str(math.ceil(hp / attack))
print(ans)
if __name__ == '__main__':
main()
| 11 | 11 | 179 | 192 | import math
def main():
hp, attack = (int(i) for i in input().rstrip().split(" "))
print((str(math.ceil(hp / attack))))
if __name__ == "__main__":
main()
| import math
def main():
hp, attack = (int(i) for i in input().rstrip().split(" "))
ans = str(math.ceil(hp / attack))
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- print((str(math.ceil(hp / attack))))",
"+ ans = str(math.ceil(hp / attack))",
"+ print(ans)"
] | false | 0.041926 | 0.042648 | 0.983069 | [
"s368334894",
"s664311667"
] |
u802963389 | p03317 | python | s568706880 | s449638131 | 40 | 17 | 13,812 | 3,060 | Accepted | Accepted | 57.5 | import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1))))
| N, K = list(map(int, input().split()))
print((-(-(N - 1) // (K - 1)))) | 4 | 2 | 120 | 63 | import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1))))
| N, K = list(map(int, input().split()))
print((-(-(N - 1) // (K - 1))))
| false | 50 | [
"-import math",
"-",
"-A = list(map(int, input().split()))",
"-print((math.ceil((N - 1) / (K - 1))))",
"+print((-(-(N - 1) // (K - 1))))"
] | false | 0.065979 | 0.036359 | 1.814678 | [
"s568706880",
"s449638131"
] |
u295294832 | p03317 | python | s235197026 | s889285170 | 40 | 17 | 13,880 | 2,940 | Accepted | Accepted | 57.5 | N,K = [int(i) for i in input().split()]
n = list(map(int, input().split()))
print(((N-K)//(K-1) + 1 if (N-K)%(K-1) ==0 else (N-K)//(K-1) + 2))
| N,K = [int(i) for i in input().split()]
print(((N-K)//(K-1) + 1 if (N-K)%(K-1) == 0 else (N-K)//(K-1) + 2))
| 3 | 2 | 143 | 107 | N, K = [int(i) for i in input().split()]
n = list(map(int, input().split()))
print(((N - K) // (K - 1) + 1 if (N - K) % (K - 1) == 0 else (N - K) // (K - 1) + 2))
| N, K = [int(i) for i in input().split()]
print(((N - K) // (K - 1) + 1 if (N - K) % (K - 1) == 0 else (N - K) // (K - 1) + 2))
| false | 33.333333 | [
"-n = list(map(int, input().split()))"
] | false | 0.093813 | 0.03551 | 2.641901 | [
"s235197026",
"s889285170"
] |
u488127128 | p03262 | python | s017765240 | s158122856 | 111 | 67 | 19,732 | 14,252 | Accepted | Accepted | 39.64 | N,X = list(map(int, input().split()))
r = {abs(X-i) for i in map(int, input().split())}
ans = r.pop()
for i in r:
while ans%i != 0:
ans,i = i,ans%i
ans = i
print(ans) | def solve():
N,X = list(map(int, input().split()))
r = [abs(X-i) for i in map(int, input().split())]
ans = r.pop()
for i in r:
while ans%i != 0:
ans,i = i,ans%i
ans = i
return ans
if __name__ == '__main__':
print((solve())) | 8 | 12 | 183 | 279 | N, X = list(map(int, input().split()))
r = {abs(X - i) for i in map(int, input().split())}
ans = r.pop()
for i in r:
while ans % i != 0:
ans, i = i, ans % i
ans = i
print(ans)
| def solve():
N, X = list(map(int, input().split()))
r = [abs(X - i) for i in map(int, input().split())]
ans = r.pop()
for i in r:
while ans % i != 0:
ans, i = i, ans % i
ans = i
return ans
if __name__ == "__main__":
print((solve()))
| false | 33.333333 | [
"-N, X = list(map(int, input().split()))",
"-r = {abs(X - i) for i in map(int, input().split())}",
"-ans = r.pop()",
"-for i in r:",
"- while ans % i != 0:",
"- ans, i = i, ans % i",
"- ans = i",
"-print(ans)",
"+def solve():",
"+ N, X = list(map(int, input().split()))",
"+ r ... | false | 0.03899 | 0.038915 | 1.001926 | [
"s017765240",
"s158122856"
] |
u832409298 | p03550 | python | s849183921 | s877977115 | 293 | 19 | 3,316 | 3,188 | Accepted | Accepted | 93.52 | import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7
def main():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
res2 = abs(a[-1] - a[-2])
# 最後から n 枚目を取るときの max, min
max_li = [0, res, res2] + [0 for _ in range(N)]
min_li = [INF, res, res2] + [INF for _ in range(N)]
for i in range(3, N+1):
take_all = abs(a[-i] - a[-1])
max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])
print((max(max_li)))
main() | import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7
def main_old():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
res2 = abs(a[-1] - a[-2])
# 最後から n 枚目を取るときの max, min
max_li = [0, res, res2] + [0 for _ in range(N)]
min_li = [INF, res, res2] + [INF for _ in range(N)]
for i in range(3, N+1):
take_all = abs(a[-i] - a[-1])
max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])
print((max(max_li)))
def main():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
# 初手でラスト1つ手前まで取るとき
res2 = abs(a[-1] - a[-2])
# res2 以上の結果を、カードをより少なく取ることで得ることはできない。
# なぜなら、たとえそのような選び方を見つけたような気がしても、Y にラスト1つ手前まで取られてしまったら結局結果は res2 になってしまうため。
# これ以上の結果を得ることはできないのでこれで満足するしかない。
print((max(res, res2)))
main() | 34 | 52 | 986 | 1,388 | import sys
sys.setrecursionlimit(10**7)
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return sys.stdin.readline().strip()
INF = 10**18
MOD = 10**9 + 7
def main():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
res2 = abs(a[-1] - a[-2])
# 最後から n 枚目を取るときの max, min
max_li = [0, res, res2] + [0 for _ in range(N)]
min_li = [INF, res, res2] + [INF for _ in range(N)]
for i in range(3, N + 1):
take_all = abs(a[-i] - a[-1])
max_li[i] = min([min_li[j] for j in range(2, i)] + [take_all])
min_li[i] = max([max_li[j] for j in range(2, i)] + [take_all])
print((max(max_li)))
main()
| import sys
sys.setrecursionlimit(10**7)
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return sys.stdin.readline().strip()
INF = 10**18
MOD = 10**9 + 7
def main_old():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
res2 = abs(a[-1] - a[-2])
# 最後から n 枚目を取るときの max, min
max_li = [0, res, res2] + [0 for _ in range(N)]
min_li = [INF, res, res2] + [INF for _ in range(N)]
for i in range(3, N + 1):
take_all = abs(a[-i] - a[-1])
max_li[i] = min([min_li[j] for j in range(2, i)] + [take_all])
min_li[i] = max([max_li[j] for j in range(2, i)] + [take_all])
print((max(max_li)))
def main():
N, _, W = LI()
a = LI()
# 初手でラストまで取るとき
res = abs(a[-1] - W)
if N == 1:
print(res)
return
# 初手でラスト1つ手前まで取るとき
res2 = abs(a[-1] - a[-2])
# res2 以上の結果を、カードをより少なく取ることで得ることはできない。
# なぜなら、たとえそのような選び方を見つけたような気がしても、Y にラスト1つ手前まで取られてしまったら結局結果は res2 になってしまうため。
# これ以上の結果を得ることはできないのでこれで満足するしかない。
print((max(res, res2)))
main()
| false | 34.615385 | [
"-def main():",
"+def main_old():",
"+def main():",
"+ N, _, W = LI()",
"+ a = LI()",
"+ # 初手でラストまで取るとき",
"+ res = abs(a[-1] - W)",
"+ if N == 1:",
"+ print(res)",
"+ return",
"+ # 初手でラスト1つ手前まで取るとき",
"+ res2 = abs(a[-1] - a[-2])",
"+ # res2 以上の結果を、カードをより... | false | 0.123271 | 0.041799 | 2.949154 | [
"s849183921",
"s877977115"
] |
u161164709 | p02573 | python | s434400429 | s368257564 | 1,070 | 790 | 109,808 | 49,736 | Accepted | Accepted | 26.17 | from collections import deque
n, m = list(map(int, input().split()))
ab_array = [list(map(int, input().split())) for _ in range(m)]
ad_sum_array = [0] * n
ad_array = [set() for _ in range(n)]
for ab in ab_array:
a, b = ab
ad_array[a - 1].add(b - 1)
ad_array[b - 1].add(a - 1)
check_array = [False] * n
def bfs(node_num):
queue = deque([node_num])
check_array[node_num] = True
num = 1
while queue:
node = queue.popleft()
for ad in ad_array[node]:
if not check_array[ad]:
check_array[ad] = True
queue.append(ad)
num += 1
return num
ans = 0
for i in range(n):
if not check_array[i]:
ans = max(ans, bfs(i))
print(ans) | class union_find:
def __init__(self, node_num):
self.root_array = [-1] * node_num
def root(self, x):
if self.root_array[x] < 0:
return x
else:
self.root_array[x] = self.root(self.root_array[x])
return self.root_array[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.root_array[x] > self.root_array[y]:
x, y = y, x
self.root_array[x] += self.root_array[y]
self.root_array[y] = x
def size(self, x):
return -self.root_array[self.root(x)]
def solve(n, m, ab_array):
uf = union_find(n)
for ab in ab_array:
a, b = ab
uf.unite(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, uf.size(i))
return ans
if __name__ == '__main__':
n, m = list(map(int, input().split()))
ab_array = [list(map(int, input().split())) for _ in range(m)]
ans = solve(n, m, ab_array)
print(ans) | 35 | 42 | 769 | 1,062 | from collections import deque
n, m = list(map(int, input().split()))
ab_array = [list(map(int, input().split())) for _ in range(m)]
ad_sum_array = [0] * n
ad_array = [set() for _ in range(n)]
for ab in ab_array:
a, b = ab
ad_array[a - 1].add(b - 1)
ad_array[b - 1].add(a - 1)
check_array = [False] * n
def bfs(node_num):
queue = deque([node_num])
check_array[node_num] = True
num = 1
while queue:
node = queue.popleft()
for ad in ad_array[node]:
if not check_array[ad]:
check_array[ad] = True
queue.append(ad)
num += 1
return num
ans = 0
for i in range(n):
if not check_array[i]:
ans = max(ans, bfs(i))
print(ans)
| class union_find:
def __init__(self, node_num):
self.root_array = [-1] * node_num
def root(self, x):
if self.root_array[x] < 0:
return x
else:
self.root_array[x] = self.root(self.root_array[x])
return self.root_array[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.root_array[x] > self.root_array[y]:
x, y = y, x
self.root_array[x] += self.root_array[y]
self.root_array[y] = x
def size(self, x):
return -self.root_array[self.root(x)]
def solve(n, m, ab_array):
uf = union_find(n)
for ab in ab_array:
a, b = ab
uf.unite(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, uf.size(i))
return ans
if __name__ == "__main__":
n, m = list(map(int, input().split()))
ab_array = [list(map(int, input().split())) for _ in range(m)]
ans = solve(n, m, ab_array)
print(ans)
| false | 16.666667 | [
"-from collections import deque",
"+class union_find:",
"+ def __init__(self, node_num):",
"+ self.root_array = [-1] * node_num",
"-n, m = list(map(int, input().split()))",
"-ab_array = [list(map(int, input().split())) for _ in range(m)]",
"-ad_sum_array = [0] * n",
"-ad_array = [set() for _... | false | 0.037025 | 0.050494 | 0.733253 | [
"s434400429",
"s368257564"
] |
u600402037 | p03221 | python | s589392737 | s273059815 | 701 | 549 | 41,024 | 32,540 | Accepted | Accepted | 21.68 | import bisect
import collections
N, M = list(map(int, input().split()))
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
A[x] += [y]
for x, y in PM:
z = bisect.bisect(A[x], y)
print(('%06d%06d'%(x,z))) | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
cur = [1] * (N+1) # 1-indexed
PY = [lr() + [i] for i in range(M)]
PY.sort(key=lambda x: x[1])
answer = [None] * M # 0-indexed
for p, y, i in PY:
x = str(p).zfill(6) + str(cur[p]).zfill(6)
answer[i] = x
cur[p] += 1
for a in answer:
print(a)
| 11 | 19 | 284 | 426 | import bisect
import collections
N, M = list(map(int, input().split()))
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
A[x] += [y]
for x, y in PM:
z = bisect.bisect(A[x], y)
print(("%06d%06d" % (x, z)))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
cur = [1] * (N + 1) # 1-indexed
PY = [lr() + [i] for i in range(M)]
PY.sort(key=lambda x: x[1])
answer = [None] * M # 0-indexed
for p, y, i in PY:
x = str(p).zfill(6) + str(cur[p]).zfill(6)
answer[i] = x
cur[p] += 1
for a in answer:
print(a)
| false | 42.105263 | [
"-import bisect",
"-import collections",
"+# coding: utf-8",
"+import sys",
"-N, M = list(map(int, input().split()))",
"-PM = [[int(j) for j in input().split()] for i in range(M)]",
"-A = collections.defaultdict(list)",
"-for x, y in sorted(PM):",
"- A[x] += [y]",
"-for x, y in PM:",
"- z ... | false | 0.038856 | 0.041712 | 0.93152 | [
"s589392737",
"s273059815"
] |
u020604402 | p03360 | python | s692815018 | s190668545 | 190 | 18 | 17,228 | 2,940 | Accepted | Accepted | 90.53 | L = [list(map(int,input().split()))]
K = int(eval(input()))
import copy
def peice_double(L):
l = []
for x in L:
tmp = copy.copy(x)
for i in range(3):
tmp[i] = tmp[i] * 2
l.append(copy.copy(tmp))
tmp[i] = tmp[i] // 2
return l
for i in range(K):
L = peice_double(L)
ans = 0
for x in L:
ans = max(ans, sum(x))
print(ans) | L = list(map(int,input().split()))
K = int(eval(input()))
m = max(L)
print((sum(L)-m + m* (2 ** K))) | 19 | 4 | 402 | 95 | L = [list(map(int, input().split()))]
K = int(eval(input()))
import copy
def peice_double(L):
l = []
for x in L:
tmp = copy.copy(x)
for i in range(3):
tmp[i] = tmp[i] * 2
l.append(copy.copy(tmp))
tmp[i] = tmp[i] // 2
return l
for i in range(K):
L = peice_double(L)
ans = 0
for x in L:
ans = max(ans, sum(x))
print(ans)
| L = list(map(int, input().split()))
K = int(eval(input()))
m = max(L)
print((sum(L) - m + m * (2**K)))
| false | 78.947368 | [
"-L = [list(map(int, input().split()))]",
"+L = list(map(int, input().split()))",
"-import copy",
"-",
"-",
"-def peice_double(L):",
"- l = []",
"- for x in L:",
"- tmp = copy.copy(x)",
"- for i in range(3):",
"- tmp[i] = tmp[i] * 2",
"- l.append(copy.... | false | 0.098455 | 0.039607 | 2.485788 | [
"s692815018",
"s190668545"
] |
u588829932 | p03295 | python | s763793794 | s293104507 | 1,271 | 291 | 128,776 | 36,828 | Accepted | Accepted | 77.1 | *D, = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x:x[1])
cnt = 0
while len(edges)>0:
cnt += 1
new_edges = []
bridge = edges[0][1]
for it in edges:
if it[0]>=bridge:
new_edges.append(it)
edges = new_edges
print(cnt) | *D, = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x:x[1])
bridge = edges[0][1]
cnt = 1
for a, b in edges[1:]:
if bridge <= a:
bridge = b
cnt += 1
print(cnt) | 16 | 12 | 364 | 268 | (*D,) = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x: x[1])
cnt = 0
while len(edges) > 0:
cnt += 1
new_edges = []
bridge = edges[0][1]
for it in edges:
if it[0] >= bridge:
new_edges.append(it)
edges = new_edges
print(cnt)
| (*D,) = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x: x[1])
bridge = edges[0][1]
cnt = 1
for a, b in edges[1:]:
if bridge <= a:
bridge = b
cnt += 1
print(cnt)
| false | 25 | [
"-cnt = 0",
"-while len(edges) > 0:",
"- cnt += 1",
"- new_edges = []",
"- bridge = edges[0][1]",
"- for it in edges:",
"- if it[0] >= bridge:",
"- new_edges.append(it)",
"- edges = new_edges",
"+bridge = edges[0][1]",
"+cnt = 1",
"+for a, b in edges[1:]:",
"... | false | 0.082912 | 0.084722 | 0.978638 | [
"s763793794",
"s293104507"
] |
u183284051 | p02690 | python | s215500992 | s929372232 | 65 | 59 | 64,440 | 65,964 | Accepted | Accepted | 9.23 | # coding: utf-8
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def main():
x = ni()
memo = [pow(i,5) for i in range(-125,125)]
xmod10 = x%10
for a in range(-125, 125):
for b in range(-125, 125):
if (a-b)%10 == xmod10:
if memo[a+125] - memo[b+125] == x:
print((a,b))
return
print("Erorr")
return
if __name__ == '__main__':
main() | # coding: utf-8
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def main():
x = ni()
memo = [0.1 for _ in range(-125, 125)]
xmod10 = x%10
for a in range(-125, 125):
for b in range(-125, 125):
if (a-b)%10 == xmod10:
if memo[a+125] == 0.1:
memo[a+125] = pow(a, 5)
if memo[b+125] == 0.1:
memo[b+125] = pow(b, 5)
if memo[a+125] - memo[b+125] == x:
print((a,b))
return
print("Erorr")
return
if __name__ == '__main__':
main() | 25 | 29 | 582 | 748 | # coding: utf-8
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def main():
x = ni()
memo = [pow(i, 5) for i in range(-125, 125)]
xmod10 = x % 10
for a in range(-125, 125):
for b in range(-125, 125):
if (a - b) % 10 == xmod10:
if memo[a + 125] - memo[b + 125] == x:
print((a, b))
return
print("Erorr")
return
if __name__ == "__main__":
main()
| # coding: utf-8
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def main():
x = ni()
memo = [0.1 for _ in range(-125, 125)]
xmod10 = x % 10
for a in range(-125, 125):
for b in range(-125, 125):
if (a - b) % 10 == xmod10:
if memo[a + 125] == 0.1:
memo[a + 125] = pow(a, 5)
if memo[b + 125] == 0.1:
memo[b + 125] = pow(b, 5)
if memo[a + 125] - memo[b + 125] == x:
print((a, b))
return
print("Erorr")
return
if __name__ == "__main__":
main()
| false | 13.793103 | [
"- memo = [pow(i, 5) for i in range(-125, 125)]",
"+ memo = [0.1 for _ in range(-125, 125)]",
"+ if memo[a + 125] == 0.1:",
"+ memo[a + 125] = pow(a, 5)",
"+ if memo[b + 125] == 0.1:",
"+ memo[b + 125] = pow(b, 5)"
] | false | 0.104375 | 0.045921 | 2.272909 | [
"s215500992",
"s929372232"
] |
u677267454 | p03014 | python | s974699827 | s819959648 | 1,747 | 876 | 231,332 | 266,508 | Accepted | Accepted | 49.86 | import numpy as np
h, w = list(map(int, input().split()))
grid = [[False for j in range(w)] for i in range(h)]
for i in range(h):
s = eval(input())
for j in range(w):
if s[j] == '.':
grid[i][j] = 1
else:
grid[i][j] = 0
grid = np.array(grid)
L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)
for j in range(w):
if j == 0:
L[:, j] = grid[:, j]
else:
L[:, j] = (L[:, j - 1] + 1) * grid[:, j]
for j in range(w - 1, -1, -1):
if j >= w - 1:
R[:, j] = grid[:, j]
else:
R[:, j] = (R[:, j + 1] + 1) * grid[:, j]
for i in range(h):
if i <= 0:
U[i, :] = grid[i, :]
else:
U[i, :] = (U[i - 1, :] + 1) * grid[i, :]
for i in range(h - 1, -1, -1):
if i >= h - 1:
D[i, :] = grid[i, :]
else:
D[i, :] = (D[i + 1, :] + 1) * grid[i, :]
print((np.max(L + R + U + D - 3)))
| import numpy as np
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
grid.append(list(eval(input())))
grid = (np.array(grid) == ".") * 1
L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)
for j in range(w):
if j == 0:
L[:, j] = grid[:, j]
else:
L[:, j] = (L[:, j - 1] + 1) * grid[:, j]
for j in range(w - 1, -1, -1):
if j >= w - 1:
R[:, j] = grid[:, j]
else:
R[:, j] = (R[:, j + 1] + 1) * grid[:, j]
for i in range(h):
if i <= 0:
U[i, :] = grid[i, :]
else:
U[i, :] = (U[i - 1, :] + 1) * grid[i, :]
for i in range(h - 1, -1, -1):
if i >= h - 1:
D[i, :] = grid[i, :]
else:
D[i, :] = (D[i + 1, :] + 1) * grid[i, :]
print((np.max(L + R + U + D - 3)))
| 47 | 41 | 1,015 | 878 | import numpy as np
h, w = list(map(int, input().split()))
grid = [[False for j in range(w)] for i in range(h)]
for i in range(h):
s = eval(input())
for j in range(w):
if s[j] == ".":
grid[i][j] = 1
else:
grid[i][j] = 0
grid = np.array(grid)
L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)
for j in range(w):
if j == 0:
L[:, j] = grid[:, j]
else:
L[:, j] = (L[:, j - 1] + 1) * grid[:, j]
for j in range(w - 1, -1, -1):
if j >= w - 1:
R[:, j] = grid[:, j]
else:
R[:, j] = (R[:, j + 1] + 1) * grid[:, j]
for i in range(h):
if i <= 0:
U[i, :] = grid[i, :]
else:
U[i, :] = (U[i - 1, :] + 1) * grid[i, :]
for i in range(h - 1, -1, -1):
if i >= h - 1:
D[i, :] = grid[i, :]
else:
D[i, :] = (D[i + 1, :] + 1) * grid[i, :]
print((np.max(L + R + U + D - 3)))
| import numpy as np
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
grid.append(list(eval(input())))
grid = (np.array(grid) == ".") * 1
L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)
for j in range(w):
if j == 0:
L[:, j] = grid[:, j]
else:
L[:, j] = (L[:, j - 1] + 1) * grid[:, j]
for j in range(w - 1, -1, -1):
if j >= w - 1:
R[:, j] = grid[:, j]
else:
R[:, j] = (R[:, j + 1] + 1) * grid[:, j]
for i in range(h):
if i <= 0:
U[i, :] = grid[i, :]
else:
U[i, :] = (U[i - 1, :] + 1) * grid[i, :]
for i in range(h - 1, -1, -1):
if i >= h - 1:
D[i, :] = grid[i, :]
else:
D[i, :] = (D[i + 1, :] + 1) * grid[i, :]
print((np.max(L + R + U + D - 3)))
| false | 12.765957 | [
"-grid = [[False for j in range(w)] for i in range(h)]",
"+grid = []",
"- s = eval(input())",
"- for j in range(w):",
"- if s[j] == \".\":",
"- grid[i][j] = 1",
"- else:",
"- grid[i][j] = 0",
"-grid = np.array(grid)",
"+ grid.append(list(eval(input())))... | false | 0.212965 | 0.236147 | 0.901834 | [
"s974699827",
"s819959648"
] |
u162612857 | p03818 | python | s145766679 | s121352980 | 96 | 45 | 14,396 | 14,564 | Accepted | Accepted | 53.12 | n = int(eval(input()))
nums = list(map(int, input().split()))
# これ直前に解いた
# 重複している=取り除かなきゃいけない枚数の2の倍数切り上げ。
nums.sort()
sequential = 1
before = nums[0]
dup = 0
for i in nums[1:]:
if i == before:
sequential += 1
else:
dup += sequential - 1
sequential = 1
before = i
dup += sequential - 1
print((n - (dup + 1) // 2 * 2))
| # カードの山に k 種類のカードがあったとして,k が奇数なら余っているカードは偶数枚あるの
# で答えは k であり,偶数ならばどこかで必ず 1 枚しかないカードを 1 回取り除く必要があるので
# 答えは k − 1 となります.
n = int(eval(input()))
nums = list(map(int, input().split()))
k = len(set(nums))
print((k if k % 2 == 1 else k-1))
| 21 | 9 | 369 | 236 | n = int(eval(input()))
nums = list(map(int, input().split()))
# これ直前に解いた
# 重複している=取り除かなきゃいけない枚数の2の倍数切り上げ。
nums.sort()
sequential = 1
before = nums[0]
dup = 0
for i in nums[1:]:
if i == before:
sequential += 1
else:
dup += sequential - 1
sequential = 1
before = i
dup += sequential - 1
print((n - (dup + 1) // 2 * 2))
| # カードの山に k 種類のカードがあったとして,k が奇数なら余っているカードは偶数枚あるの
# で答えは k であり,偶数ならばどこかで必ず 1 枚しかないカードを 1 回取り除く必要があるので
# 答えは k − 1 となります.
n = int(eval(input()))
nums = list(map(int, input().split()))
k = len(set(nums))
print((k if k % 2 == 1 else k - 1))
| false | 57.142857 | [
"+# カードの山に k 種類のカードがあったとして,k が奇数なら余っているカードは偶数枚あるの",
"+# で答えは k であり,偶数ならばどこかで必ず 1 枚しかないカードを 1 回取り除く必要があるので",
"+# 答えは k − 1 となります.",
"-# これ直前に解いた",
"-# 重複している=取り除かなきゃいけない枚数の2の倍数切り上げ。",
"-nums.sort()",
"-sequential = 1",
"-before = nums[0]",
"-dup = 0",
"-for i in nums[1:]:",
"- if i == before:"... | false | 0.051127 | 0.04122 | 1.240347 | [
"s145766679",
"s121352980"
] |
u075595666 | p03476 | python | s952868183 | s453000321 | 1,700 | 1,433 | 17,036 | 8,188 | Accepted | Accepted | 15.71 | import random
import numpy as np
def is_prime(q,k=50):
if q == 2: return 1
if q < 2 or q&1 == 0: return 0
d = (q-1)>>1
while d&1 == 0:
d >>= 1
for i in range(k):
a = random.randint(1,q-1)
t = d
y = pow(a,t,q)
while t != q-1 and y != 1 and y != q-1:
y = pow(y,2,q)
t <<= 1
if y != q-1 and t&1 == 0:
return 0
return 1
chk = np.array([0]*10**5)
for i in range(10**5):
chk[i] = is_prime(i+1,10)
ans = np.array([0]*10**5)
for i in range(2,10**5):
ans[i] = chk[i]&chk[(i+1)//2]
np.cumsum(ans,out=ans)
import sys
input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
l,s = list(map(int,input().split()))
print((ans[s-1]-ans[max(0,l-2)])) | import math
def eratosthenes(limit):
A = [i for i in range(2, limit+1)]
P = []
while True:
prime = min(A)
if prime > math.sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return list(P)
a = eratosthenes(100000)
b = set([2*i-1 for i in a])
a = set(a)
chk = sorted(list(a&b))
from bisect import bisect,bisect_left
import sys
input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
l,r = list(map(int,input().split()))
print((bisect(chk,r)-bisect_left(chk,l))) | 37 | 32 | 798 | 711 | import random
import numpy as np
def is_prime(q, k=50):
if q == 2:
return 1
if q < 2 or q & 1 == 0:
return 0
d = (q - 1) >> 1
while d & 1 == 0:
d >>= 1
for i in range(k):
a = random.randint(1, q - 1)
t = d
y = pow(a, t, q)
while t != q - 1 and y != 1 and y != q - 1:
y = pow(y, 2, q)
t <<= 1
if y != q - 1 and t & 1 == 0:
return 0
return 1
chk = np.array([0] * 10**5)
for i in range(10**5):
chk[i] = is_prime(i + 1, 10)
ans = np.array([0] * 10**5)
for i in range(2, 10**5):
ans[i] = chk[i] & chk[(i + 1) // 2]
np.cumsum(ans, out=ans)
import sys
input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
l, s = list(map(int, input().split()))
print((ans[s - 1] - ans[max(0, l - 2)]))
| import math
def eratosthenes(limit):
A = [i for i in range(2, limit + 1)]
P = []
while True:
prime = min(A)
if prime > math.sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return list(P)
a = eratosthenes(100000)
b = set([2 * i - 1 for i in a])
a = set(a)
chk = sorted(list(a & b))
from bisect import bisect, bisect_left
import sys
input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
l, r = list(map(int, input().split()))
print((bisect(chk, r) - bisect_left(chk, l)))
| false | 13.513514 | [
"-import random",
"-import numpy as np",
"+import math",
"-def is_prime(q, k=50):",
"- if q == 2:",
"- return 1",
"- if q < 2 or q & 1 == 0:",
"- return 0",
"- d = (q - 1) >> 1",
"- while d & 1 == 0:",
"- d >>= 1",
"- for i in range(k):",
"- a = ran... | false | 0.958416 | 1.642657 | 0.583455 | [
"s952868183",
"s453000321"
] |
u762420987 | p03208 | python | s429636510 | s636942316 | 264 | 244 | 11,272 | 8,280 | Accepted | Accepted | 7.58 | N,K = list(map(int,input().split()))
hlist = [int(eval(input())) for _ in range(N)]
hlist.sort(reverse=True)
sa = []
for _ in range(N-K+1):
num = hlist[_]-hlist[_+(K-1)]
sa.append(num)
sa.sort()
print((sa[0]))
| N, K = list(map(int, input().split()))
hlist = sorted([int(eval(input())) for _ in range(N)])
ans = 10**9 + 7
for i in range(N - K + 1):
ans = min(ans, hlist[i + K - 1] - hlist[i])
print(ans)
| 10 | 6 | 214 | 189 | N, K = list(map(int, input().split()))
hlist = [int(eval(input())) for _ in range(N)]
hlist.sort(reverse=True)
sa = []
for _ in range(N - K + 1):
num = hlist[_] - hlist[_ + (K - 1)]
sa.append(num)
sa.sort()
print((sa[0]))
| N, K = list(map(int, input().split()))
hlist = sorted([int(eval(input())) for _ in range(N)])
ans = 10**9 + 7
for i in range(N - K + 1):
ans = min(ans, hlist[i + K - 1] - hlist[i])
print(ans)
| false | 40 | [
"-hlist = [int(eval(input())) for _ in range(N)]",
"-hlist.sort(reverse=True)",
"-sa = []",
"-for _ in range(N - K + 1):",
"- num = hlist[_] - hlist[_ + (K - 1)]",
"- sa.append(num)",
"-sa.sort()",
"-print((sa[0]))",
"+hlist = sorted([int(eval(input())) for _ in range(N)])",
"+ans = 10**9 + ... | false | 0.047899 | 0.048989 | 0.977734 | [
"s429636510",
"s636942316"
] |
u186838327 | p03175 | python | s324134840 | s057801835 | 667 | 582 | 39,364 | 39,360 | Accepted | Accepted | 12.74 | import sys
input = sys.stdin.readline
n = int(eval(input()))
mod = 10**9+7
g = [[] for _ in range(n)]
for i in range(n-1):
x, y = list(map(int, input().split()))
x, y = x-1, y-1
g[x].append(y)
g[y].append(x)
dp = [[1, 1] for _ in range(n)]
# dp[v][0]: white
# dp[v][1]: black
s = []
order = []
par = [-1]*n
s.append(0)
while s:
v = s.pop()
order.append(v)
flag = True
for u in g[v]:
if u == par[v]:
continue
flag = False
par[u] = v
s.append(u)
order.reverse()
for v in order:
if par[v] == -1:
continue
dp[par[v]][0] *= (dp[v][0]+dp[v][1])%mod
dp[par[v]][1] *= dp[v][0]%mod
ans = dp[0][0]+dp[0][1]
#print(dp)
print((ans%mod)) | import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
mod = 10**9+7
g = [[] for _ in range(n)]
for i in range(n-1):
x, y = list(map(int, input().split()))
x, y = x-1, y-1
g[x].append(y)
g[y].append(x)
dp = [[1, 1] for _ in range(n)]
# dp[v][0]: white
# dp[v][1]: black
s = []
order = []
par = [-1]*n
s.append(0)
while s:
v = s.pop()
order.append(v)
for u in g[v]:
if u == par[v]:
continue
par[u] = v
s.append(u)
order.reverse()
for v in order:
if par[v] == -1:
continue
dp[par[v]][0] *= (dp[v][0]+dp[v][1])%mod
dp[par[v]][1] *= dp[v][0]%mod
ans = dp[0][0]+dp[0][1]
#print(dp)
print((ans%mod))
if __name__ == '__main__':
main()
| 40 | 42 | 749 | 894 | import sys
input = sys.stdin.readline
n = int(eval(input()))
mod = 10**9 + 7
g = [[] for _ in range(n)]
for i in range(n - 1):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
g[x].append(y)
g[y].append(x)
dp = [[1, 1] for _ in range(n)]
# dp[v][0]: white
# dp[v][1]: black
s = []
order = []
par = [-1] * n
s.append(0)
while s:
v = s.pop()
order.append(v)
flag = True
for u in g[v]:
if u == par[v]:
continue
flag = False
par[u] = v
s.append(u)
order.reverse()
for v in order:
if par[v] == -1:
continue
dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod
dp[par[v]][1] *= dp[v][0] % mod
ans = dp[0][0] + dp[0][1]
# print(dp)
print((ans % mod))
| import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
mod = 10**9 + 7
g = [[] for _ in range(n)]
for i in range(n - 1):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
g[x].append(y)
g[y].append(x)
dp = [[1, 1] for _ in range(n)]
# dp[v][0]: white
# dp[v][1]: black
s = []
order = []
par = [-1] * n
s.append(0)
while s:
v = s.pop()
order.append(v)
for u in g[v]:
if u == par[v]:
continue
par[u] = v
s.append(u)
order.reverse()
for v in order:
if par[v] == -1:
continue
dp[par[v]][0] *= (dp[v][0] + dp[v][1]) % mod
dp[par[v]][1] *= dp[v][0] % mod
ans = dp[0][0] + dp[0][1]
# print(dp)
print((ans % mod))
if __name__ == "__main__":
main()
| false | 4.761905 | [
"-n = int(eval(input()))",
"-mod = 10**9 + 7",
"-g = [[] for _ in range(n)]",
"-for i in range(n - 1):",
"- x, y = list(map(int, input().split()))",
"- x, y = x - 1, y - 1",
"- g[x].append(y)",
"- g[y].append(x)",
"-dp = [[1, 1] for _ in range(n)]",
"-# dp[v][0]: white",
"-# dp[v][1]... | false | 0.037544 | 0.042632 | 0.880654 | [
"s324134840",
"s057801835"
] |
u560988566 | p02996 | python | s112431141 | s082784206 | 1,837 | 800 | 104,796 | 43,004 | Accepted | Accepted | 56.45 | import heapq
def main():
n = int(eval(input()))
abs = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for ab in abs:
a,b = ab[0],ab[1]
heapq.heappush(pq, tuple([b,a]))
dl = 0
tc = 0
ans = "Yes"
for i in range(n):
ba = heapq.heappop(pq)
dl = ba[0]
tc += ba[1]
if dl < tc:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main() | import heapq
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
abs = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for ab in abs:
a,b = ab[0],ab[1]
heapq.heappush(pq, tuple([b,a]))
dl = 0
tc = 0
ans = "Yes"
for i in range(n):
ba = heapq.heappop(pq)
dl = ba[0]
tc += ba[1]
if dl < tc:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main() | 28 | 30 | 431 | 471 | import heapq
def main():
n = int(eval(input()))
abs = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for ab in abs:
a, b = ab[0], ab[1]
heapq.heappush(pq, tuple([b, a]))
dl = 0
tc = 0
ans = "Yes"
for i in range(n):
ba = heapq.heappop(pq)
dl = ba[0]
tc += ba[1]
if dl < tc:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main()
| import heapq
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
abs = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for ab in abs:
a, b = ab[0], ab[1]
heapq.heappush(pq, tuple([b, a]))
dl = 0
tc = 0
ans = "Yes"
for i in range(n):
ba = heapq.heappop(pq)
dl = ba[0]
tc += ba[1]
if dl < tc:
ans = "No"
break
print(ans)
if __name__ == "__main__":
main()
| false | 6.666667 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.041232 | 0.114279 | 0.360797 | [
"s112431141",
"s082784206"
] |
u303039933 | p02792 | python | s956780480 | s436190430 | 219 | 160 | 10,728 | 10,792 | Accepted | Accepted | 26.94 | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def solve():
N = Scanner.int()
memo = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
s = str(i)
memo[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, N + 1):
s = str(i)
t = memo[int(s[-1])][int(s[0])]
ans += t
print(ans)
def main():
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
def solve():
N = Scanner.int()
cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
front = int(str(i)[0])
back = int(str(i)[-1])
cnt[front][back] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += cnt[i][j] * cnt[j][i]
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| 142 | 81 | 3,078 | 1,811 | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N**0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007F
MOD = int(1e09) + 7
INF = int(1e15)
def solve():
N = Scanner.int()
memo = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
s = str(i)
memo[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, N + 1):
s = str(i)
t = memo[int(s[-1])][int(s[0])]
ans += t
print(ans)
def main():
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007F
def solve():
N = Scanner.int()
cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
front = int(str(i)[0])
back = int(str(i)[-1])
cnt[front][back] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += cnt[i][j] * cnt[j][i]
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| false | 42.957746 | [
"+import copy",
"-class Math:",
"- @staticmethod",
"- def gcd(a, b):",
"- if b == 0:",
"- return a",
"- return Math.gcd(b, a % b)",
"-",
"- @staticmethod",
"- def lcm(a, b):",
"- return (a * b) // Math.gcd(a, b)",
"-",
"- @staticmethod",
"- ... | false | 0.057704 | 0.048511 | 1.189502 | [
"s956780480",
"s436190430"
] |
u860657719 | p02623 | python | s093743567 | s686995062 | 210 | 153 | 131,708 | 134,144 | Accepted | Accepted | 27.14 | import bisect
n, m, k = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
sa.append(sa[-1] + a[i])
for i in range(m):
sb.append(sb[-1] + b[i])
ans = 0
for i in range(n+1):
if sa[i] > k:
continue
else:
j = bisect.bisect_right(sb, k-sa[i])
ans = max(ans, i+j-1)
print(ans) | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
sa.append(sa[i] + a[i])
for i in range(m):
sb.append(sb[i] + b[i])
ans = 0
j = m
for i in range(n+1):
if sa[i] > k:
break
while sa[i] + sb[j] > k:
j -= 1
ans = max(ans, i + j)
print(ans) | 18 | 18 | 411 | 384 | import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
sa.append(sa[-1] + a[i])
for i in range(m):
sb.append(sb[-1] + b[i])
ans = 0
for i in range(n + 1):
if sa[i] > k:
continue
else:
j = bisect.bisect_right(sb, k - sa[i])
ans = max(ans, i + j - 1)
print(ans)
| n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
sa.append(sa[i] + a[i])
for i in range(m):
sb.append(sb[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
if sa[i] > k:
break
while sa[i] + sb[j] > k:
j -= 1
ans = max(ans, i + j)
print(ans)
| false | 0 | [
"-import bisect",
"-",
"- sa.append(sa[-1] + a[i])",
"+ sa.append(sa[i] + a[i])",
"- sb.append(sb[-1] + b[i])",
"+ sb.append(sb[i] + b[i])",
"+j = m",
"- continue",
"- else:",
"- j = bisect.bisect_right(sb, k - sa[i])",
"- ans = max(ans, i + j - 1)",
"+ ... | false | 0.03254 | 0.068704 | 0.47363 | [
"s093743567",
"s686995062"
] |
u941047297 | p03775 | python | s419756691 | s015676026 | 186 | 39 | 39,664 | 9,092 | Accepted | Accepted | 79.03 | def main():
def f(a, b):
return max(len(str(a)), len(str(b)))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n = int(eval(input()))
divisors = make_divisors(n)
ans = float('inf')
for a in divisors:
b = n // a
ans = min(ans, f(a, b))
print(ans)
if __name__ == '__main__':
main()
| def f(a, b):
return len(str(max(a, b)))
def main():
n = int(eval(input()))
ans = 100
for i in range(1, int(n ** 0.5 + 0.5) + 1):
if n % i == 0:
ans = min(ans, f(i, n // i))
print(ans)
if __name__ == '__main__':
main()
| 22 | 12 | 550 | 268 | def main():
def f(a, b):
return max(len(str(a)), len(str(b)))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
n = int(eval(input()))
divisors = make_divisors(n)
ans = float("inf")
for a in divisors:
b = n // a
ans = min(ans, f(a, b))
print(ans)
if __name__ == "__main__":
main()
| def f(a, b):
return len(str(max(a, b)))
def main():
n = int(eval(input()))
ans = 100
for i in range(1, int(n**0.5 + 0.5) + 1):
if n % i == 0:
ans = min(ans, f(i, n // i))
print(ans)
if __name__ == "__main__":
main()
| false | 45.454545 | [
"+def f(a, b):",
"+ return len(str(max(a, b)))",
"+",
"+",
"- def f(a, b):",
"- return max(len(str(a)), len(str(b)))",
"-",
"- def make_divisors(n):",
"- divisors = []",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- divi... | false | 0.094823 | 0.092006 | 1.03061 | [
"s419756691",
"s015676026"
] |
u677121387 | p02659 | python | s242847022 | s455573185 | 30 | 27 | 9,936 | 9,788 | Accepted | Accepted | 10 | from decimal import Decimal
a,b = input().split()
d = Decimal(a)
c = Decimal(b)
print(((d*c)//1))
| from decimal import Decimal
a,b = list(map(Decimal,input().split()))
print(((a*b)//1)) | 5 | 3 | 100 | 80 | from decimal import Decimal
a, b = input().split()
d = Decimal(a)
c = Decimal(b)
print(((d * c) // 1))
| from decimal import Decimal
a, b = list(map(Decimal, input().split()))
print(((a * b) // 1))
| false | 40 | [
"-a, b = input().split()",
"-d = Decimal(a)",
"-c = Decimal(b)",
"-print(((d * c) // 1))",
"+a, b = list(map(Decimal, input().split()))",
"+print(((a * b) // 1))"
] | false | 0.038934 | 0.102498 | 0.379846 | [
"s242847022",
"s455573185"
] |
u901582103 | p03659 | python | s244781774 | s275878951 | 329 | 198 | 30,960 | 24,824 | Accepted | Accepted | 39.82 | n=int(eval(input()))
A=list(map(int,input().split()))
L=[A[0]]
R=[A[-1]]
for i in range(1,n-1):
l=L[i-1]+A[i]
L.append(l)
r=R[i-1]+A[-(i+1)]
R.append(r)
c=2*10**14
for i in range(n-1):
s=abs(L[i]-R[-(i+1)])
c=min(c,s)
print(c) | n=int(eval(input()))
A=list(map(int,input().split()))
X=sum(A)
x=0
c=2*10**14
for i in range(n-1):
x+=A[i]
s=abs(X-2*x)
c=min(c,s)
print(c) | 14 | 10 | 257 | 154 | n = int(eval(input()))
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(1, n - 1):
l = L[i - 1] + A[i]
L.append(l)
r = R[i - 1] + A[-(i + 1)]
R.append(r)
c = 2 * 10**14
for i in range(n - 1):
s = abs(L[i] - R[-(i + 1)])
c = min(c, s)
print(c)
| n = int(eval(input()))
A = list(map(int, input().split()))
X = sum(A)
x = 0
c = 2 * 10**14
for i in range(n - 1):
x += A[i]
s = abs(X - 2 * x)
c = min(c, s)
print(c)
| false | 28.571429 | [
"-L = [A[0]]",
"-R = [A[-1]]",
"-for i in range(1, n - 1):",
"- l = L[i - 1] + A[i]",
"- L.append(l)",
"- r = R[i - 1] + A[-(i + 1)]",
"- R.append(r)",
"+X = sum(A)",
"+x = 0",
"- s = abs(L[i] - R[-(i + 1)])",
"+ x += A[i]",
"+ s = abs(X - 2 * x)"
] | false | 0.042731 | 0.036767 | 1.162234 | [
"s244781774",
"s275878951"
] |
u307159845 | p03457 | python | s641496955 | s629133567 | 490 | 412 | 11,668 | 11,892 | Accepted | Accepted | 15.92 | N = int(eval(input()))
T = [0]*100000
X= [0]*100000
Y= [0]*100000
x = 0
y = 0
for n in range(N):
T[n],X[n],Y[n] = (list(map(int, input().split())))
flag = 1
for n in range(N):
#print(n)
if flag == 0:
continue
if n == 0:
count = T[n]
else:
count = T[n] - T[n-1]
x = X[n-1]
y = Y[n-1]
c = 0
end = 0
while True:
if end == 1:
break
s_x = X[n] - x
s_y = Y[n] - y
# print(str(s_x)+' '+str(s_y))
if ((s_x != 0 or s_y !=0) )and (c!=count):
if s_x >0:
x +=1
c += 1
elif s_x < 0:
x -= 1
c+=1
elif s_y > 0:
y +=1
c += 1
elif s_y < 0:
y -= 1
c+=1
elif ((s_x == 0 and s_y == 0) )and (c!=count):
x +=1
c +=1
elif c==count:
if (x == X[n] and y ==Y[n]):
flag = 1
end=1
else:
flag=0
end =1
if flag == 1:
print('Yes')
else:
print('No')
| N = int(eval(input()))
t = [0]*110000
x= [0]*110000
y= [0]*110000
for n in range(N):
t[n+1],x[n+1],y[n+1] = (list(map(int, input().split())))
can = True
for i in range(N):
dt = t[i+1] - t[i]
dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])
if dt < dist: #dt が大きければたどり着ける
can = False
if (dist % 2 != dt % 2):#動いていなければ偶数奇数がずれる
can = False
if can == True:
print('Yes')
else:
print('No')
| 62 | 23 | 1,223 | 446 | N = int(eval(input()))
T = [0] * 100000
X = [0] * 100000
Y = [0] * 100000
x = 0
y = 0
for n in range(N):
T[n], X[n], Y[n] = list(map(int, input().split()))
flag = 1
for n in range(N):
# print(n)
if flag == 0:
continue
if n == 0:
count = T[n]
else:
count = T[n] - T[n - 1]
x = X[n - 1]
y = Y[n - 1]
c = 0
end = 0
while True:
if end == 1:
break
s_x = X[n] - x
s_y = Y[n] - y
# print(str(s_x)+' '+str(s_y))
if ((s_x != 0 or s_y != 0)) and (c != count):
if s_x > 0:
x += 1
c += 1
elif s_x < 0:
x -= 1
c += 1
elif s_y > 0:
y += 1
c += 1
elif s_y < 0:
y -= 1
c += 1
elif ((s_x == 0 and s_y == 0)) and (c != count):
x += 1
c += 1
elif c == count:
if x == X[n] and y == Y[n]:
flag = 1
end = 1
else:
flag = 0
end = 1
if flag == 1:
print("Yes")
else:
print("No")
| N = int(eval(input()))
t = [0] * 110000
x = [0] * 110000
y = [0] * 110000
for n in range(N):
t[n + 1], x[n + 1], y[n + 1] = list(map(int, input().split()))
can = True
for i in range(N):
dt = t[i + 1] - t[i]
dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
if dt < dist: # dt が大きければたどり着ける
can = False
if dist % 2 != dt % 2: # 動いていなければ偶数奇数がずれる
can = False
if can == True:
print("Yes")
else:
print("No")
| false | 62.903226 | [
"-T = [0] * 100000",
"-X = [0] * 100000",
"-Y = [0] * 100000",
"-x = 0",
"-y = 0",
"+t = [0] * 110000",
"+x = [0] * 110000",
"+y = [0] * 110000",
"- T[n], X[n], Y[n] = list(map(int, input().split()))",
"-flag = 1",
"-for n in range(N):",
"- # print(n)",
"- if flag == 0:",
"- ... | false | 0.055138 | 0.052373 | 1.052791 | [
"s641496955",
"s629133567"
] |
u494871759 | p03846 | python | s694011157 | s202121226 | 102 | 91 | 14,004 | 14,008 | Accepted | Accepted | 10.78 | n = int(eval(input()))
a = list(map(int,input().split()))
sa = sorted(a)
if n % 2 == 0:
k = 1
l = 0
else:
k = 0
l = 1
a=1000000007
flag = True
for i,s in enumerate(sa):
if ((i+l)//2)*2+k != s:
flag = False
if flag:
print((2**(n//2) % a))
else:
print((0))
| n = int(eval(input()))
a = list(map(int,input().split()))
if n%2==0:
if sorted(a) != [(k//2)*2+1 for k in range(n)]:
print((0))
else:
ans = 2**(n//2)
print((ans % (10**9+7)))
else:
if sorted(a)!= [0]+[(k//2+1)*2 for k in range(n-1)]:
print((0))
else:
ans = 2**(n//2)
print((ans % (10**9+7))) | 20 | 15 | 290 | 356 | n = int(eval(input()))
a = list(map(int, input().split()))
sa = sorted(a)
if n % 2 == 0:
k = 1
l = 0
else:
k = 0
l = 1
a = 1000000007
flag = True
for i, s in enumerate(sa):
if ((i + l) // 2) * 2 + k != s:
flag = False
if flag:
print((2 ** (n // 2) % a))
else:
print((0))
| n = int(eval(input()))
a = list(map(int, input().split()))
if n % 2 == 0:
if sorted(a) != [(k // 2) * 2 + 1 for k in range(n)]:
print((0))
else:
ans = 2 ** (n // 2)
print((ans % (10**9 + 7)))
else:
if sorted(a) != [0] + [(k // 2 + 1) * 2 for k in range(n - 1)]:
print((0))
else:
ans = 2 ** (n // 2)
print((ans % (10**9 + 7)))
| false | 25 | [
"-sa = sorted(a)",
"- k = 1",
"- l = 0",
"+ if sorted(a) != [(k // 2) * 2 + 1 for k in range(n)]:",
"+ print((0))",
"+ else:",
"+ ans = 2 ** (n // 2)",
"+ print((ans % (10**9 + 7)))",
"- k = 0",
"- l = 1",
"-a = 1000000007",
"-flag = True",
"-for i, s i... | false | 0.142363 | 0.041003 | 3.47204 | [
"s694011157",
"s202121226"
] |
u987164499 | p03569 | python | s490881921 | s032309439 | 98 | 71 | 3,444 | 3,316 | Accepted | Accepted | 27.55 | from sys import stdin
s = stdin.readline().rstrip()
k = ""
for i in range(len(s)):
if s[i] != "x":
k += s[i]
if k != k[::-1]:
print((-1))
exit()
man = (len(k)+1)//2
point = 0
for i,j in enumerate(s):
if j != "x":
point += 1
if point == man:
kotae = i
break
a = s[:kotae+1]
b = s[kotae:][::-1]
A = len(a)
B = len(b)
point_a = 0
point_b = 0
total = 0
while point_a < A and point_b < B:
if a[point_a] == b[point_b]:
point_a += 1
point_b += 1
elif a[point_a] == "x" and b[point_b] != "x":
point_a += 1
total += 1
else:
point_b += 1
total += 1
print(total) | from sys import stdin
s = stdin.readline().rstrip()
r = len(s)-1
l = 0
count = 0
while r-l > 0:
if s[l] == s[r]:
r -= 1
l += 1
elif s[l] == "x" and s[r] != "x":
count += 1
l += 1
elif s[r] == "x" and s[l] != "x":
count += 1
r -= 1
else:
print((-1))
exit()
print(count) | 44 | 21 | 713 | 368 | from sys import stdin
s = stdin.readline().rstrip()
k = ""
for i in range(len(s)):
if s[i] != "x":
k += s[i]
if k != k[::-1]:
print((-1))
exit()
man = (len(k) + 1) // 2
point = 0
for i, j in enumerate(s):
if j != "x":
point += 1
if point == man:
kotae = i
break
a = s[: kotae + 1]
b = s[kotae:][::-1]
A = len(a)
B = len(b)
point_a = 0
point_b = 0
total = 0
while point_a < A and point_b < B:
if a[point_a] == b[point_b]:
point_a += 1
point_b += 1
elif a[point_a] == "x" and b[point_b] != "x":
point_a += 1
total += 1
else:
point_b += 1
total += 1
print(total)
| from sys import stdin
s = stdin.readline().rstrip()
r = len(s) - 1
l = 0
count = 0
while r - l > 0:
if s[l] == s[r]:
r -= 1
l += 1
elif s[l] == "x" and s[r] != "x":
count += 1
l += 1
elif s[r] == "x" and s[l] != "x":
count += 1
r -= 1
else:
print((-1))
exit()
print(count)
| false | 52.272727 | [
"-k = \"\"",
"-for i in range(len(s)):",
"- if s[i] != \"x\":",
"- k += s[i]",
"-if k != k[::-1]:",
"- print((-1))",
"- exit()",
"-man = (len(k) + 1) // 2",
"-point = 0",
"-for i, j in enumerate(s):",
"- if j != \"x\":",
"- point += 1",
"- if point == man:",
"-... | false | 0.00663 | 0.03844 | 0.172482 | [
"s490881921",
"s032309439"
] |
u667135132 | p02882 | python | s930751954 | s351516236 | 298 | 150 | 21,352 | 12,452 | Accepted | Accepted | 49.66 | import numpy as np
'''実はarctanは実装されていた...
def search_arctan(tan):
low = 0
high = np.radians(90)
while (high-low>=10**(-12)):
mid = (low+high)/2
if np.tan(mid)<=tan:
low = mid
else:
high = mid
return np.rad2deg(mid)
'''
a,b,x = list(map(int,input().split()))
l = x/(a*a)
if l<=b/2.0:
ans = np.rad2deg(np.arctan(b**2.0/(2.0*a*l)))
else:
ans = np.rad2deg(np.arctan(2.0*(b-l)/a))
print(ans) | import numpy as np
a,b,x = list(map(int,input().split()))
l = x/(a*a)
if l<=b/2.0:
ans = np.rad2deg(np.arctan(b**2.0/(2.0*a*l)))
else:
ans = np.rad2deg(np.arctan(2.0*(b-l)/a))
print(ans) | 25 | 13 | 488 | 211 | import numpy as np
"""実はarctanは実装されていた...
def search_arctan(tan):
low = 0
high = np.radians(90)
while (high-low>=10**(-12)):
mid = (low+high)/2
if np.tan(mid)<=tan:
low = mid
else:
high = mid
return np.rad2deg(mid)
"""
a, b, x = list(map(int, input().split()))
l = x / (a * a)
if l <= b / 2.0:
ans = np.rad2deg(np.arctan(b**2.0 / (2.0 * a * l)))
else:
ans = np.rad2deg(np.arctan(2.0 * (b - l) / a))
print(ans)
| import numpy as np
a, b, x = list(map(int, input().split()))
l = x / (a * a)
if l <= b / 2.0:
ans = np.rad2deg(np.arctan(b**2.0 / (2.0 * a * l)))
else:
ans = np.rad2deg(np.arctan(2.0 * (b - l) / a))
print(ans)
| false | 48 | [
"-\"\"\"実はarctanは実装されていた...",
"-def search_arctan(tan):",
"- low = 0",
"- high = np.radians(90)",
"- while (high-low>=10**(-12)):",
"- mid = (low+high)/2",
"- if np.tan(mid)<=tan:",
"- low = mid",
"- else:",
"- high = mid",
"- return np.rad2... | false | 0.271101 | 0.241872 | 1.120845 | [
"s930751954",
"s351516236"
] |
u792145349 | p02315 | python | s829813225 | s503661703 | 1,000 | 630 | 25,520 | 5,920 | Accepted | Accepted | 37 | N, W = list(map(int, input().split()))
VW = [list(map(int, input().split())) for i in range(N)]
# N番目までの品物からWを超えないように選んだ時の最大価値合計
dp = [[0] * (W+1) for i in range(N+1)]
for i in range(N):
for j in range(W+1):
if VW[i][1] > j:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j], dp[i][j-VW[i][1]]+VW[i][0])
print((dp[N][W]))
| N, W = list(map(int, input().split()))
v = []
w = []
for i in range(N):
vv, ww = list(map(int, input().split()))
v.append(vv)
w.append(ww)
# dp[i]:重さiを超えないように選んだ時の最大価値合計
dp = [0] * (W+1)
for i in range(N):
for j in range(W, w[i]-1, -1):
dp[j] = max(dp[j], dp[j-w[i]]+v[i])
print((dp[W]))
| 13 | 18 | 376 | 320 | N, W = list(map(int, input().split()))
VW = [list(map(int, input().split())) for i in range(N)]
# N番目までの品物からWを超えないように選んだ時の最大価値合計
dp = [[0] * (W + 1) for i in range(N + 1)]
for i in range(N):
for j in range(W + 1):
if VW[i][1] > j:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], dp[i][j - VW[i][1]] + VW[i][0])
print((dp[N][W]))
| N, W = list(map(int, input().split()))
v = []
w = []
for i in range(N):
vv, ww = list(map(int, input().split()))
v.append(vv)
w.append(ww)
# dp[i]:重さiを超えないように選んだ時の最大価値合計
dp = [0] * (W + 1)
for i in range(N):
for j in range(W, w[i] - 1, -1):
dp[j] = max(dp[j], dp[j - w[i]] + v[i])
print((dp[W]))
| false | 27.777778 | [
"-VW = [list(map(int, input().split())) for i in range(N)]",
"-# N番目までの品物からWを超えないように選んだ時の最大価値合計",
"-dp = [[0] * (W + 1) for i in range(N + 1)]",
"+v = []",
"+w = []",
"- for j in range(W + 1):",
"- if VW[i][1] > j:",
"- dp[i + 1][j] = dp[i][j]",
"- else:",
"- ... | false | 0.031436 | 0.034992 | 0.898369 | [
"s829813225",
"s503661703"
] |
u875291233 | p02925 | python | s244727704 | s148055223 | 1,607 | 930 | 183,384 | 134,492 | Accepted | Accepted | 42.13 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(eval(input()))
a = [[min(i,int(j)-1)+max(i,int(j)-1)*(max(i,int(j)-1)-1)//2 for j in readline().split()] for i in range(n)]
N =n*(n-1)//2
g = [[] for i in range(N)]
p = [[] for i in range(N)]
for i in range(n):
for j in range(n-2):
g[a[i][j]].append(a[i][j+1])
p[a[i][j+1]].append(a[i][j])
#print(g)
#print(p)
ans = [0]*(N)
indegree = [len(v) for v in p] # 流入辺の数を数えた配列
Source = [i for i, c in enumerate(indegree) if c == 0] #流入辺0の点の集合
#L = [] #ソート結果をためておく配列
num = 0
while Source:
node = Source.pop()
#L.append(node)
num += 1
for child in g[node]:
indegree[child] -= 1 #辺 node -> child を削除する
if ans[child] < ans[node]+1: ans[child] = ans[node]+1
if indegree[child] == 0:
Source.append(child)
#print(num)
if num != N:
print((-1))
else:
print((max(ans)+1))
#print(ans)
| # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(eval(input()))
N =n*(n-1)//2
a = [[int(j)-1 for j in readline().split()] for _ in range(n)]
g = [[] for i in range(N)]
indegree = [0]*N
def encode(x,y):
if x > y: x,y = y,x
return y*(y-1)//2 + x
for i in range(n):
for j in range(n-2):
p,q = encode(i,a[i][j]), encode(i,a[i][j+1])
g[p].append(q)
indegree[q] += 1
"""
トポロジカルソート
q をheapq にしたりすると、辞書順にとりだしたりとかができる。
返り値:DAG ならトポソのひとつを返す。ループがあれば-1を返す
"""
"""
g: グラフの隣接行列
indegree: 流入辺の数を数えた配列
"""
def topological_sort_queue(g,indegree):
q = [i for i,c in enumerate(indegree) if c == 0] #流入辺0の点の集合
L = [] #ソート結果をためておく配列
ans =[0]*len(g)
a = 0
while q:
v = q.pop()
L.append(v)
for c in g[v]: #配る
ans[c] = max(ans[c],ans[v]+1)
a = max(a,ans[c])
indegree[c] -= 1 #辺 node -> child を削除する
if indegree[c] == 0:
q.append(c)
if len(L) != N: #print("サイクル検出")
return -1
else: #return(L)
return(a+1)
print((topological_sort_queue(g,indegree)))
| 47 | 53 | 1,022 | 1,213 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(eval(input()))
a = [
[
min(i, int(j) - 1) + max(i, int(j) - 1) * (max(i, int(j) - 1) - 1) // 2
for j in readline().split()
]
for i in range(n)
]
N = n * (n - 1) // 2
g = [[] for i in range(N)]
p = [[] for i in range(N)]
for i in range(n):
for j in range(n - 2):
g[a[i][j]].append(a[i][j + 1])
p[a[i][j + 1]].append(a[i][j])
# print(g)
# print(p)
ans = [0] * (N)
indegree = [len(v) for v in p] # 流入辺の数を数えた配列
Source = [i for i, c in enumerate(indegree) if c == 0] # 流入辺0の点の集合
# L = [] #ソート結果をためておく配列
num = 0
while Source:
node = Source.pop()
# L.append(node)
num += 1
for child in g[node]:
indegree[child] -= 1 # 辺 node -> child を削除する
if ans[child] < ans[node] + 1:
ans[child] = ans[node] + 1
if indegree[child] == 0:
Source.append(child)
# print(num)
if num != N:
print((-1))
else:
print((max(ans) + 1))
# print(ans)
| # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(eval(input()))
N = n * (n - 1) // 2
a = [[int(j) - 1 for j in readline().split()] for _ in range(n)]
g = [[] for i in range(N)]
indegree = [0] * N
def encode(x, y):
if x > y:
x, y = y, x
return y * (y - 1) // 2 + x
for i in range(n):
for j in range(n - 2):
p, q = encode(i, a[i][j]), encode(i, a[i][j + 1])
g[p].append(q)
indegree[q] += 1
"""
トポロジカルソート
q をheapq にしたりすると、辞書順にとりだしたりとかができる。
返り値:DAG ならトポソのひとつを返す。ループがあれば-1を返す
"""
"""
g: グラフの隣接行列
indegree: 流入辺の数を数えた配列
"""
def topological_sort_queue(g, indegree):
q = [i for i, c in enumerate(indegree) if c == 0] # 流入辺0の点の集合
L = [] # ソート結果をためておく配列
ans = [0] * len(g)
a = 0
while q:
v = q.pop()
L.append(v)
for c in g[v]: # 配る
ans[c] = max(ans[c], ans[v] + 1)
a = max(a, ans[c])
indegree[c] -= 1 # 辺 node -> child を削除する
if indegree[c] == 0:
q.append(c)
if len(L) != N: # print("サイクル検出")
return -1
else: # return(L)
return a + 1
print((topological_sort_queue(g, indegree)))
| false | 11.320755 | [
"-a = [",
"- [",
"- min(i, int(j) - 1) + max(i, int(j) - 1) * (max(i, int(j) - 1) - 1) // 2",
"- for j in readline().split()",
"- ]",
"- for i in range(n)",
"-]",
"+a = [[int(j) - 1 for j in readline().split()] for _ in range(n)]",
"-p = [[] for i in range(N)]",
"+indegree =... | false | 0.109579 | 0.060998 | 1.796444 | [
"s244727704",
"s148055223"
] |
u165429863 | p02678 | python | s910218196 | s149259930 | 371 | 331 | 46,408 | 46,360 | Accepted | Accepted | 10.78 | import sys
from collections import deque
def main():
N, M, *AB = list(map(int, sys.stdin.buffer.read().split()))
g = [[] for _ in range(N + 1)]
for A, B in zip(*[iter(AB)] * 2):
g[A].append(B)
g[B].append(A)
queue = deque([1])
d = [0] * (N + 1)
d[0] = 1
d[1] = 1
while queue:
v = queue.popleft()
for i in g[v]:
if d[i] == 0:
d[i] = v
queue.append(i)
if all(d):
print("Yes")
print(("\n".join(map(str, d[2:]))))
else:
print("No")
if __name__ == '__main__':
main()
exit()
| import sys
from collections import deque
def main():
N, M, *AB = list(map(int, sys.stdin.buffer.read().split()))
g = [[] for _ in range(N + 1)]
for A, B in zip(*[iter(AB)] * 2):
g[A].append(B)
g[B].append(A)
queue = deque([1])
d = [0] * (N + 1)
d[0] = 1
d[1] = 1
while queue:
v = queue.popleft()
for i in g[v]:
if not d[i]:
d[i] = v
queue.append(i)
if all(d):
print("Yes")
print(("\n".join(map(str, d[2:]))))
else:
print("No")
if __name__ == '__main__':
main()
exit()
| 36 | 36 | 651 | 650 | import sys
from collections import deque
def main():
N, M, *AB = list(map(int, sys.stdin.buffer.read().split()))
g = [[] for _ in range(N + 1)]
for A, B in zip(*[iter(AB)] * 2):
g[A].append(B)
g[B].append(A)
queue = deque([1])
d = [0] * (N + 1)
d[0] = 1
d[1] = 1
while queue:
v = queue.popleft()
for i in g[v]:
if d[i] == 0:
d[i] = v
queue.append(i)
if all(d):
print("Yes")
print(("\n".join(map(str, d[2:]))))
else:
print("No")
if __name__ == "__main__":
main()
exit()
| import sys
from collections import deque
def main():
N, M, *AB = list(map(int, sys.stdin.buffer.read().split()))
g = [[] for _ in range(N + 1)]
for A, B in zip(*[iter(AB)] * 2):
g[A].append(B)
g[B].append(A)
queue = deque([1])
d = [0] * (N + 1)
d[0] = 1
d[1] = 1
while queue:
v = queue.popleft()
for i in g[v]:
if not d[i]:
d[i] = v
queue.append(i)
if all(d):
print("Yes")
print(("\n".join(map(str, d[2:]))))
else:
print("No")
if __name__ == "__main__":
main()
exit()
| false | 0 | [
"- if d[i] == 0:",
"+ if not d[i]:"
] | false | 0.036508 | 0.036088 | 1.011661 | [
"s910218196",
"s149259930"
] |
u439396449 | p03503 | python | s090315072 | s931859802 | 343 | 76 | 3,188 | 3,064 | Accepted | Accepted | 77.84 | import sys
from itertools import product
input = sys.stdin.readline
N = int(eval(input()))
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float('-inf')
for ptn in product([0, 1], repeat=10):
if sum(ptn) == 0:
continue
res = 0
for i in range(N):
cnt = 0
for j in range(10):
cnt += F[i][j] * ptn[j]
res += P[i][cnt]
ans = max(ans, res)
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float('-inf')
for i in range(1, 2**10):
res = 0
for f, p in zip(F, P):
cnt = bin(i & f).count('1')
res += p[cnt]
ans = max(ans, res)
print(ans) | 22 | 16 | 499 | 365 | import sys
from itertools import product
input = sys.stdin.readline
N = int(eval(input()))
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float("-inf")
for ptn in product([0, 1], repeat=10):
if sum(ptn) == 0:
continue
res = 0
for i in range(N):
cnt = 0
for j in range(10):
cnt += F[i][j] * ptn[j]
res += P[i][cnt]
ans = max(ans, res)
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
F = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float("-inf")
for i in range(1, 2**10):
res = 0
for f, p in zip(F, P):
cnt = bin(i & f).count("1")
res += p[cnt]
ans = max(ans, res)
print(ans)
| false | 27.272727 | [
"-from itertools import product",
"-F = [[int(x) for x in input().split()] for _ in range(N)]",
"+F = [int(input().replace(\" \", \"\"), 2) for _ in range(N)]",
"-for ptn in product([0, 1], repeat=10):",
"- if sum(ptn) == 0:",
"- continue",
"+for i in range(1, 2**10):",
"- for i in range(... | false | 0.053901 | 0.09606 | 0.561112 | [
"s090315072",
"s931859802"
] |
u785578220 | p03478 | python | s163394565 | s500293295 | 38 | 29 | 2,940 | 2,940 | Accepted | Accepted | 23.68 | n,a,b= list(map(int, input().split()))
r=0
for i in range(n+1):
s = 0
t = str(i)
k = len(t)
for j in range(k):
s +=int(t[j])
if a <= s <= b:
r+=int(t)
print(r) | N,a,b = list(map(int,input().split()))
R = 0
for i in range(N+1):
s = i
r = 0
while i !=0:
r+= i%10
i //=10
if a <= r <= b:
R+=s
print(R)
| 11 | 11 | 200 | 182 | n, a, b = list(map(int, input().split()))
r = 0
for i in range(n + 1):
s = 0
t = str(i)
k = len(t)
for j in range(k):
s += int(t[j])
if a <= s <= b:
r += int(t)
print(r)
| N, a, b = list(map(int, input().split()))
R = 0
for i in range(N + 1):
s = i
r = 0
while i != 0:
r += i % 10
i //= 10
if a <= r <= b:
R += s
print(R)
| false | 0 | [
"-n, a, b = list(map(int, input().split()))",
"-r = 0",
"-for i in range(n + 1):",
"- s = 0",
"- t = str(i)",
"- k = len(t)",
"- for j in range(k):",
"- s += int(t[j])",
"- if a <= s <= b:",
"- r += int(t)",
"-print(r)",
"+N, a, b = list(map(int, input().split()))"... | false | 0.037066 | 0.036322 | 1.020474 | [
"s163394565",
"s500293295"
] |
u936985471 | p02787 | python | s336396837 | s558343369 | 428 | 391 | 43,888 | 42,220 | Accepted | Accepted | 8.64 | H,N=list(map(int,input().split()))
A=[0]*N
B=[0]*N
for i in range(N):
A[i],B[i]=list(map(int,input().split()))
INF=10**9
dp=[INF]*(H+1)
# dp[x]:xダメージを与えるための最小魔力
dp[0]=0
for i in range(N):
for j in range(len(dp)):
if dp[j]!=INF:
if j+A[i]<len(dp):
if dp[j+A[i]]>dp[j]+B[i]:
dp[j+A[i]]=dp[j]+B[i]
else:
if dp[len(dp)-1]>dp[j]+B[i]:
dp[len(dp)-1]=dp[j]+B[i]
print((dp[-1])) | H,N=list(map(int,input().split()))
A=[0]*N
B=[0]*N
for i in range(N):
A[i],B[i]=list(map(int,input().split()))
INF=10**9
dp=[INF]*(H+max(A))
# dp[x]:xダメージを与えるための最小魔力
dp[0]=0
for i in range(N):
for j in range(H):
if dp[j]!=INF:
if dp[j+A[i]]>dp[j]+B[i]:
dp[j+A[i]]=dp[j]+B[i]
print((min(dp[H:])))
| 20 | 16 | 432 | 320 | H, N = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
INF = 10**9
dp = [INF] * (H + 1)
# dp[x]:xダメージを与えるための最小魔力
dp[0] = 0
for i in range(N):
for j in range(len(dp)):
if dp[j] != INF:
if j + A[i] < len(dp):
if dp[j + A[i]] > dp[j] + B[i]:
dp[j + A[i]] = dp[j] + B[i]
else:
if dp[len(dp) - 1] > dp[j] + B[i]:
dp[len(dp) - 1] = dp[j] + B[i]
print((dp[-1]))
| H, N = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
INF = 10**9
dp = [INF] * (H + max(A))
# dp[x]:xダメージを与えるための最小魔力
dp[0] = 0
for i in range(N):
for j in range(H):
if dp[j] != INF:
if dp[j + A[i]] > dp[j] + B[i]:
dp[j + A[i]] = dp[j] + B[i]
print((min(dp[H:])))
| false | 20 | [
"-dp = [INF] * (H + 1)",
"+dp = [INF] * (H + max(A))",
"- for j in range(len(dp)):",
"+ for j in range(H):",
"- if j + A[i] < len(dp):",
"- if dp[j + A[i]] > dp[j] + B[i]:",
"- dp[j + A[i]] = dp[j] + B[i]",
"- else:",
"- if... | false | 0.226987 | 0.245383 | 0.925028 | [
"s336396837",
"s558343369"
] |
u941407962 | p02670 | python | s406991951 | s865527354 | 1,984 | 1,215 | 169,568 | 158,600 | Accepted | Accepted | 38.76 | N, = list(map(int, input().split()))
R = [0] * (N**2+1)
V = [0] * (N**2+1)
X = list(map(int, input().split()))
for ai in range(N**2):
i, j = divmod(ai, N)
R[ai+1] = min([i, N-i-1, j, N-j-1])
r = 0
for a in X:
r += R[a]
V[a] = 1
stack=[a]
while stack:
v = stack.pop()
ccs = []
if v>N:
ccs.append(v-N)
if v<N**2+1-N:
ccs.append(v+N)
if v%N:
ccs.append(v+1)
if v%N!=1:
ccs.append(v-1)
for u in ccs:
if R[v]>=R[u] or ((1-V[v]) and R[v]+1 >= R[u]):
continue
R[u] -= 1
stack.append(u)
print(r)
| N, = list(map(int, input().split()))
R = [0] * (N**2+1)
V = [0] * (N**2+1)
X = list(map(int, input().split()))
for ai in range(N**2):
i, j = divmod(ai, N)
R[ai+1] = min([i, N-i-1, j, N-j-1])
r = 0
for a in X:
r += R[a]
V[a] = 1
stack=[a]
while stack:
v = stack.pop()
if v>N:
if not(R[v]>=R[v-N] or ((1-V[v]) and R[v]+1 >= R[v-N])):
R[v-N] -= 1
stack.append(v-N)
if v<N**2+1-N:
if not(R[v]>=R[v+N] or ((1-V[v]) and R[v]+1 >= R[v+N])):
R[v+N] -= 1
stack.append(v+N)
if v%N:
if not(R[v]>=R[v+1] or ((1-V[v]) and R[v]+1 >= R[v+1])):
R[v+1] -= 1
stack.append(v+1)
if v%N!=1:
if not(R[v]>=R[v-1] or ((1-V[v]) and R[v]+1 >= R[v-1])):
R[v-1] -= 1
stack.append(v-1)
print(r)
| 30 | 32 | 692 | 932 | (N,) = list(map(int, input().split()))
R = [0] * (N**2 + 1)
V = [0] * (N**2 + 1)
X = list(map(int, input().split()))
for ai in range(N**2):
i, j = divmod(ai, N)
R[ai + 1] = min([i, N - i - 1, j, N - j - 1])
r = 0
for a in X:
r += R[a]
V[a] = 1
stack = [a]
while stack:
v = stack.pop()
ccs = []
if v > N:
ccs.append(v - N)
if v < N**2 + 1 - N:
ccs.append(v + N)
if v % N:
ccs.append(v + 1)
if v % N != 1:
ccs.append(v - 1)
for u in ccs:
if R[v] >= R[u] or ((1 - V[v]) and R[v] + 1 >= R[u]):
continue
R[u] -= 1
stack.append(u)
print(r)
| (N,) = list(map(int, input().split()))
R = [0] * (N**2 + 1)
V = [0] * (N**2 + 1)
X = list(map(int, input().split()))
for ai in range(N**2):
i, j = divmod(ai, N)
R[ai + 1] = min([i, N - i - 1, j, N - j - 1])
r = 0
for a in X:
r += R[a]
V[a] = 1
stack = [a]
while stack:
v = stack.pop()
if v > N:
if not (R[v] >= R[v - N] or ((1 - V[v]) and R[v] + 1 >= R[v - N])):
R[v - N] -= 1
stack.append(v - N)
if v < N**2 + 1 - N:
if not (R[v] >= R[v + N] or ((1 - V[v]) and R[v] + 1 >= R[v + N])):
R[v + N] -= 1
stack.append(v + N)
if v % N:
if not (R[v] >= R[v + 1] or ((1 - V[v]) and R[v] + 1 >= R[v + 1])):
R[v + 1] -= 1
stack.append(v + 1)
if v % N != 1:
if not (R[v] >= R[v - 1] or ((1 - V[v]) and R[v] + 1 >= R[v - 1])):
R[v - 1] -= 1
stack.append(v - 1)
print(r)
| false | 6.25 | [
"- ccs = []",
"- ccs.append(v - N)",
"+ if not (R[v] >= R[v - N] or ((1 - V[v]) and R[v] + 1 >= R[v - N])):",
"+ R[v - N] -= 1",
"+ stack.append(v - N)",
"- ccs.append(v + N)",
"+ if not (R[v] >= R[v + N] or ((1 - V[v]) and... | false | 0.036165 | 0.037151 | 0.973461 | [
"s406991951",
"s865527354"
] |
u532966492 | p02949 | python | s422347189 | s555648760 | 1,140 | 1,018 | 58,072 | 57,048 | Accepted | Accepted | 10.7 | #入力
n,m,r=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
#グラフ
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]
#逆辺
g2=[[] for _ in [0]*n]
[g2[b-1].append([a-1,c]) for a,b,c in abc]
#ベルマンフォード
dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15
for k in range(n):
for p in range(n):
for i,j in g[p]:
dist[i]=max(dist[i],dist[p]+j-r)
if k==n-2:
d1=[t for t in dist]
if k==n-1:
d2=[t for t in dist]
#負の経路上の頂点の一覧
loop=set()
for i in range(n):
if d1[i]!=d2[i]:
loop.add(i)
ans=max(d2[n-1],0)
#1からの到達可能地点
q=[0]
memo=[True for _ in range(n)]
memo[0]=False
while q:
qq=q.pop()
for i,j in g[qq]:
if memo[i]:
q.append(i)
memo[i]=False
#nからの逆辺による到達可能地点
q=[n-1]
memo2=[True for _ in range(n)]
memo2[n-1]=False
while q:
qq=q.pop()
for i,j in g2[qq]:
if memo2[i]:
q.append(i)
memo2[i]=False
#1からでもnからでも行ける点でかつ負の閉路に入っているものがあるときは-1
for i in loop:
if memo[i]==False and memo2[i]==False:
ans=-1
print(ans) | #入力
n,m,r=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
#グラフ
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]
#逆辺
g2=[[] for _ in [0]*n]
[g2[b-1].append([a-1,c]) for a,b,c in abc]
#前処理用のDFS
def remove_edge(graph,start):
q=[start]
memo=[True for _ in range(n)]
memo[start]=False
while q:
qq=q.pop()
for i,j in graph[qq]:
if memo[i]:
q.append(i)
memo[i]=False
return {i for i,j in enumerate(memo) if j==True}
#前処理
rmv=remove_edge(g,0)|remove_edge(g2,n-1)
for i in rmv:
g[i]=[]
for i in range(n):
for j in g[i]:
if j[0] in rmv:
g[i].remove(j)
#ベルマンフォード
dist=[-10**15 for _ in [0]*n]
dist[0]=0
for k in range(n):
for p in range(n):
for i,j in g[p]:
dist[i]=max(dist[i],dist[p]+j-r)
if k==n-2:
d1=[t for t in dist]
if k==n-1:
d2=[t for t in dist]
#1からでもnの間に負の閉路があるときは-1
if d1==d2:
print((max(d1[-1],0)))
else:
print((-1)) | 59 | 51 | 1,196 | 1,086 | # 入力
n, m, r = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in [0] * m]
# グラフ
g = [[] for _ in [0] * n]
[g[a - 1].append([b - 1, c]) for a, b, c in abc]
# 逆辺
g2 = [[] for _ in [0] * n]
[g2[b - 1].append([a - 1, c]) for a, b, c in abc]
# ベルマンフォード
dist = [-(10**15) for _ in [0] * n]
dist[0] = 0
a, b = -(10**15), -(10**15)
for k in range(n):
for p in range(n):
for i, j in g[p]:
dist[i] = max(dist[i], dist[p] + j - r)
if k == n - 2:
d1 = [t for t in dist]
if k == n - 1:
d2 = [t for t in dist]
# 負の経路上の頂点の一覧
loop = set()
for i in range(n):
if d1[i] != d2[i]:
loop.add(i)
ans = max(d2[n - 1], 0)
# 1からの到達可能地点
q = [0]
memo = [True for _ in range(n)]
memo[0] = False
while q:
qq = q.pop()
for i, j in g[qq]:
if memo[i]:
q.append(i)
memo[i] = False
# nからの逆辺による到達可能地点
q = [n - 1]
memo2 = [True for _ in range(n)]
memo2[n - 1] = False
while q:
qq = q.pop()
for i, j in g2[qq]:
if memo2[i]:
q.append(i)
memo2[i] = False
# 1からでもnからでも行ける点でかつ負の閉路に入っているものがあるときは-1
for i in loop:
if memo[i] == False and memo2[i] == False:
ans = -1
print(ans)
| # 入力
n, m, r = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in [0] * m]
# グラフ
g = [[] for _ in [0] * n]
[g[a - 1].append([b - 1, c]) for a, b, c in abc]
# 逆辺
g2 = [[] for _ in [0] * n]
[g2[b - 1].append([a - 1, c]) for a, b, c in abc]
# 前処理用のDFS
def remove_edge(graph, start):
q = [start]
memo = [True for _ in range(n)]
memo[start] = False
while q:
qq = q.pop()
for i, j in graph[qq]:
if memo[i]:
q.append(i)
memo[i] = False
return {i for i, j in enumerate(memo) if j == True}
# 前処理
rmv = remove_edge(g, 0) | remove_edge(g2, n - 1)
for i in rmv:
g[i] = []
for i in range(n):
for j in g[i]:
if j[0] in rmv:
g[i].remove(j)
# ベルマンフォード
dist = [-(10**15) for _ in [0] * n]
dist[0] = 0
for k in range(n):
for p in range(n):
for i, j in g[p]:
dist[i] = max(dist[i], dist[p] + j - r)
if k == n - 2:
d1 = [t for t in dist]
if k == n - 1:
d2 = [t for t in dist]
# 1からでもnの間に負の閉路があるときは-1
if d1 == d2:
print((max(d1[-1], 0)))
else:
print((-1))
| false | 13.559322 | [
"+# 前処理用のDFS",
"+def remove_edge(graph, start):",
"+ q = [start]",
"+ memo = [True for _ in range(n)]",
"+ memo[start] = False",
"+ while q:",
"+ qq = q.pop()",
"+ for i, j in graph[qq]:",
"+ if memo[i]:",
"+ q.append(i)",
"+ mem... | false | 0.046476 | 0.048908 | 0.950262 | [
"s422347189",
"s555648760"
] |
u983918956 | p03804 | python | s734208395 | s418797076 | 164 | 24 | 3,064 | 3,064 | Accepted | Accepted | 85.37 | N,M = list(map(int,input().split()))
A = [eval(input()) for i in range(N)]
B = [eval(input()) for j in range(M)]
ans = "No"
for i in range(N-M+1):
for j in range(N-M+1):
count = 0
for k in range(M):
for l in range(M):
if B[k][l] == A[i+k][j+l]:
count += 1
if count == M*M:
ans = "Yes"
break
else:
continue
break
print(ans) | N,M = list(map(int,input().split()))
A = [list(eval(input())) for _ in range(N)]
B = [list(eval(input())) for _ in range(M)]
ans = "No"
for i in range(N-M+1):
for j in range(N-M+1):
C = []
for k in range(i,i+M):
C.append(A[k][j:j+M])
if B == C:
ans = "Yes"
print(ans) | 18 | 15 | 437 | 318 | N, M = list(map(int, input().split()))
A = [eval(input()) for i in range(N)]
B = [eval(input()) for j in range(M)]
ans = "No"
for i in range(N - M + 1):
for j in range(N - M + 1):
count = 0
for k in range(M):
for l in range(M):
if B[k][l] == A[i + k][j + l]:
count += 1
if count == M * M:
ans = "Yes"
break
else:
continue
break
print(ans)
| N, M = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(N)]
B = [list(eval(input())) for _ in range(M)]
ans = "No"
for i in range(N - M + 1):
for j in range(N - M + 1):
C = []
for k in range(i, i + M):
C.append(A[k][j : j + M])
if B == C:
ans = "Yes"
print(ans)
| false | 16.666667 | [
"-A = [eval(input()) for i in range(N)]",
"-B = [eval(input()) for j in range(M)]",
"+A = [list(eval(input())) for _ in range(N)]",
"+B = [list(eval(input())) for _ in range(M)]",
"- count = 0",
"- for k in range(M):",
"- for l in range(M):",
"- if B[k][l] == A[... | false | 0.03664 | 0.035914 | 1.020224 | [
"s734208395",
"s418797076"
] |
u912115033 | p03599 | python | s406745691 | s952003318 | 229 | 165 | 12,456 | 22,548 | Accepted | Accepted | 27.95 | a,b,c,d,e,f = list(map(int,input().split()))
w = []
for i in range(f//100//a+1):
for j in range(f//100//b+1):
if (i*a + j*b)*100 <= f:
w.append(i*100*a + j*100*b)
w = set(w)
w.remove(0)
s = []
for i in range(e*f//100//c+1):
for j in range(e*f//100//d+1):
if i*c + j*d <= e*f//100:
s.append(i*c + j*d)
s = sorted(set(s))
ans = []
for i in w:
for j in s:
if i != 0 and j <= e* i//100 and i+j <= f:
ans.append([j/(i+j), j+i, j])
ans.sort()
print((ans[-1][1], ans[-1][2])) | a,b,c,d,e,f = list(map(int,input().split()))
w = []
for i in range(f//100//a+1):
for j in range(f//100//b+1):
w.append(i*100*a + j*100*b)
w = set(w)
s = []
for i in range(f//c+1):
for j in range(f//d+1):
s.append(i*c + j*d)
s = set(s)
ans = []
for i in w:
for j in s:
if i != 0 and j/(i+j) <= e/(100+e) and i+j <= f:
ans.append([j/(i+j), j+i, j])
ans.sort()
print((ans[-1][1], ans[-1][2])) | 22 | 18 | 554 | 446 | a, b, c, d, e, f = list(map(int, input().split()))
w = []
for i in range(f // 100 // a + 1):
for j in range(f // 100 // b + 1):
if (i * a + j * b) * 100 <= f:
w.append(i * 100 * a + j * 100 * b)
w = set(w)
w.remove(0)
s = []
for i in range(e * f // 100 // c + 1):
for j in range(e * f // 100 // d + 1):
if i * c + j * d <= e * f // 100:
s.append(i * c + j * d)
s = sorted(set(s))
ans = []
for i in w:
for j in s:
if i != 0 and j <= e * i // 100 and i + j <= f:
ans.append([j / (i + j), j + i, j])
ans.sort()
print((ans[-1][1], ans[-1][2]))
| a, b, c, d, e, f = list(map(int, input().split()))
w = []
for i in range(f // 100 // a + 1):
for j in range(f // 100 // b + 1):
w.append(i * 100 * a + j * 100 * b)
w = set(w)
s = []
for i in range(f // c + 1):
for j in range(f // d + 1):
s.append(i * c + j * d)
s = set(s)
ans = []
for i in w:
for j in s:
if i != 0 and j / (i + j) <= e / (100 + e) and i + j <= f:
ans.append([j / (i + j), j + i, j])
ans.sort()
print((ans[-1][1], ans[-1][2]))
| false | 18.181818 | [
"- if (i * a + j * b) * 100 <= f:",
"- w.append(i * 100 * a + j * 100 * b)",
"+ w.append(i * 100 * a + j * 100 * b)",
"-w.remove(0)",
"-for i in range(e * f // 100 // c + 1):",
"- for j in range(e * f // 100 // d + 1):",
"- if i * c + j * d <= e * f // 100:",
"- ... | false | 0.094897 | 0.244661 | 0.387871 | [
"s406745691",
"s952003318"
] |
u754022296 | p03478 | python | s773142882 | s909332232 | 33 | 28 | 3,060 | 3,060 | Accepted | Accepted | 15.15 | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
c = 0
s = str(i)
for j in s:
c += int(j)
if a <= c <= b:
ans += i
print(ans) | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n):
t = i+1
cnt = 0
while t:
cnt += t%10
t //= 10
if a <= cnt <= b:
ans += i+1
print(ans) | 11 | 11 | 175 | 178 | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
c = 0
s = str(i)
for j in s:
c += int(j)
if a <= c <= b:
ans += i
print(ans)
| n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n):
t = i + 1
cnt = 0
while t:
cnt += t % 10
t //= 10
if a <= cnt <= b:
ans += i + 1
print(ans)
| false | 0 | [
"-for i in range(1, n + 1):",
"- c = 0",
"- s = str(i)",
"- for j in s:",
"- c += int(j)",
"- if a <= c <= b:",
"- ans += i",
"+for i in range(n):",
"+ t = i + 1",
"+ cnt = 0",
"+ while t:",
"+ cnt += t % 10",
"+ t //= 10",
"+ if a <= cnt... | false | 0.047938 | 0.042142 | 1.137539 | [
"s773142882",
"s909332232"
] |
u531631168 | p03835 | python | s132049468 | s549291687 | 1,184 | 27 | 9,180 | 9,160 | Accepted | Accepted | 97.72 | k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
for y in range(k+1):
z = s - x - y
if z >= 0 and z <=k:
ans += 1
print(ans) | k, s = list(map(int, input().split()))
def two_sum(k, s):
if s < 0:
return 0
elif k >= s:
return s + 1
elif s//2 > k:
return 0
else:
return s + 1 - 2 * (s - k)
ans = 0
for x in range(k+1):
ans += two_sum(k, s - x)
print(ans) | 8 | 15 | 176 | 285 | k, s = list(map(int, input().split()))
ans = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if z >= 0 and z <= k:
ans += 1
print(ans)
| k, s = list(map(int, input().split()))
def two_sum(k, s):
if s < 0:
return 0
elif k >= s:
return s + 1
elif s // 2 > k:
return 0
else:
return s + 1 - 2 * (s - k)
ans = 0
for x in range(k + 1):
ans += two_sum(k, s - x)
print(ans)
| false | 46.666667 | [
"+",
"+",
"+def two_sum(k, s):",
"+ if s < 0:",
"+ return 0",
"+ elif k >= s:",
"+ return s + 1",
"+ elif s // 2 > k:",
"+ return 0",
"+ else:",
"+ return s + 1 - 2 * (s - k)",
"+",
"+",
"- for y in range(k + 1):",
"- z = s - x - y",
"-... | false | 0.089994 | 0.042926 | 2.096464 | [
"s132049468",
"s549291687"
] |
u298297089 | p03962 | python | s554078939 | s231861341 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | from collections import Counter
a = list(input().split())
print((len(Counter(a)))) | a = list(map(int, input().split()))
print((len(set(a)))) | 3 | 2 | 82 | 55 | from collections import Counter
a = list(input().split())
print((len(Counter(a))))
| a = list(map(int, input().split()))
print((len(set(a))))
| false | 33.333333 | [
"-from collections import Counter",
"-",
"-a = list(input().split())",
"-print((len(Counter(a))))",
"+a = list(map(int, input().split()))",
"+print((len(set(a))))"
] | false | 0.04325 | 0.042046 | 1.028646 | [
"s554078939",
"s231861341"
] |
u562935282 | p03162 | python | s116444472 | s644695025 | 926 | 700 | 40,176 | 82,392 | Accepted | Accepted | 24.41 | n = int(eval(input()))
e = tuple(tuple(map(int, input().split())) for _ in range(n))
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(3):
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + e[i - 1][0]
dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + e[i - 1][1]
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + e[i - 1][2]
print((max(dp[n])))
| n = int(eval(input()))
v = tuple(tuple(map(int, input().split())) for _ in range(n))
e = tuple(zip(*v))
# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度
# print(e)
dp = tuple([0] * 3 for _ in range(n + 1))
# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度
# もらう
for i in range(n):
for j in range(3):
dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]
print((max(dp[n])))
| 12 | 14 | 392 | 384 | n = int(eval(input()))
e = tuple(tuple(map(int, input().split())) for _ in range(n))
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(3):
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + e[i - 1][0]
dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + e[i - 1][1]
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + e[i - 1][2]
print((max(dp[n])))
| n = int(eval(input()))
v = tuple(tuple(map(int, input().split())) for _ in range(n))
e = tuple(zip(*v))
# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度
# print(e)
dp = tuple([0] * 3 for _ in range(n + 1))
# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度
# もらう
for i in range(n):
for j in range(3):
dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]
print((max(dp[n])))
| false | 14.285714 | [
"-e = tuple(tuple(map(int, input().split())) for _ in range(n))",
"-dp = [[0] * 3 for _ in range(n + 1)]",
"-for i in range(1, n + 1):",
"+v = tuple(tuple(map(int, input().split())) for _ in range(n))",
"+e = tuple(zip(*v))",
"+# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度",
"+# print(e)",
"+dp = tuple([0] * 3... | false | 0.035598 | 0.05953 | 0.597986 | [
"s116444472",
"s644695025"
] |
u150664457 | p02936 | python | s504865746 | s317356480 | 1,960 | 1,094 | 113,532 | 282,840 | Accepted | Accepted | 44.18 | N, Q = list(map(int,input().split())) # 複数の数字を変数に格納
List_ab = [list(map(int,input().split())) for i in range(N-1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int,input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]
count_list = [0]*N
List_ab.sort()
for i in range(Q):
count_list[List_px[i][0]-1] += List_px[i][1]
for i in range(N-1):
count_list[List_ab[i][1]-1] += count_list[List_ab[i][0]-1]
print((*count_list)) | import sys
sys.setrecursionlimit(10 ** 6)
import sys
def input():
return sys.stdin.readline()[:-1]
N , Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
a , b = list(map(int,input().split()))
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
a , b = list(map(int,input().split()))
a = a - 1
point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
for next in graph[now]:
# 次のノードが前に参照した値の時はcontinue
if next == prev:
continue
# 現在の値を次のポイントに加算することで累積和をとる
point[next] += point[now]
# 次のノードと現在のノードを引数にdfsを継続する
dfs(next , now)
dfs(0)
print((*point)) | 15 | 31 | 449 | 771 | N, Q = list(map(int, input().split())) # 複数の数字を変数に格納
List_ab = [list(map(int, input().split())) for i in range(N - 1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int, input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]
count_list = [0] * N
List_ab.sort()
for i in range(Q):
count_list[List_px[i][0] - 1] += List_px[i][1]
for i in range(N - 1):
count_list[List_ab[i][1] - 1] += count_list[List_ab[i][0] - 1]
print((*count_list))
| import sys
sys.setrecursionlimit(10**6)
import sys
def input():
return sys.stdin.readline()[:-1]
N, Q = list(map(int, input().split()))
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
# print(graph)
for _ in range(Q):
a, b = list(map(int, input().split()))
a = a - 1
point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now, prev=-1):
for next in graph[now]:
# 次のノードが前に参照した値の時はcontinue
if next == prev:
continue
# 現在の値を次のポイントに加算することで累積和をとる
point[next] += point[now]
# 次のノードと現在のノードを引数にdfsを継続する
dfs(next, now)
dfs(0)
print((*point))
| false | 51.612903 | [
"-N, Q = list(map(int, input().split())) # 複数の数字を変数に格納",
"-List_ab = [list(map(int, input().split())) for i in range(N - 1)] # [[1,2],[3,4],[5,6]]",
"-List_px = [list(map(int, input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]",
"-count_list = [0] * N",
"-List_ab.sort()",
"-for i in range(Q):",... | false | 0.03943 | 0.102794 | 0.38358 | [
"s504865746",
"s317356480"
] |
u177040005 | p03317 | python | s250908346 | s012404967 | 39 | 17 | 13,880 | 2,940 | Accepted | Accepted | 56.41 | N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((1 + -( -(N-K)//(K-1) ) ))
| N,K = list(map(int, input().split()))
print((1 + -( -(N-K)//(K-1) ) ))
| 4 | 2 | 103 | 64 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((1 + -(-(N - K) // (K - 1))))
| N, K = list(map(int, input().split()))
print((1 + -(-(N - K) // (K - 1))))
| false | 50 | [
"-A = list(map(int, input().split()))"
] | false | 0.067177 | 0.045892 | 1.463796 | [
"s250908346",
"s012404967"
] |
u769870836 | p02732 | python | s329644915 | s953990062 | 451 | 332 | 25,644 | 26,268 | Accepted | Accepted | 26.39 | n=int(eval(input()))
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans=0
for v in list(c.values()):
ans+=v*(v-1)//2
for x in l:
print((ans-c[x]*(c[x]-1)//2+(c[x]-1)*(c[x]-2)//2)) | n=int(eval(input()))
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans=0
for v in list(c.values()):
ans+=v*(v-1)//2
for x in l:
print((ans-c[x]+1)) | 9 | 9 | 209 | 178 | n = int(eval(input()))
l = list(map(int, input().split()))
import collections
c = collections.Counter(l)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
for x in l:
print((ans - c[x] * (c[x] - 1) // 2 + (c[x] - 1) * (c[x] - 2) // 2))
| n = int(eval(input()))
l = list(map(int, input().split()))
import collections
c = collections.Counter(l)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
for x in l:
print((ans - c[x] + 1))
| false | 0 | [
"- print((ans - c[x] * (c[x] - 1) // 2 + (c[x] - 1) * (c[x] - 2) // 2))",
"+ print((ans - c[x] + 1))"
] | false | 0.044959 | 0.035881 | 1.252996 | [
"s329644915",
"s953990062"
] |
u467736898 | p02834 | python | s681258200 | s190092456 | 501 | 257 | 48,988 | 53,012 | Accepted | Accepted | 48.7 | import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[] for _ in range(N+1)]
for ab in AB:
a, b = ab
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N+1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l-2) // 2
c = path_u2v[half]
ng = path_u2v[half+1]
Depth = np.zeros(N+1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N+1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l-1-half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l%2
ans = max(Depth) + half + d
return ans
def main():
N, u, v = list(map(int, input().split()))
if N==2:
print((0))
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
| import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[0]*0 for _ in range(N+1)]
for idx_ab in range(len(AB)):
a, b = AB[idx_ab]
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N+1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l-2) // 2
c = path_u2v[half]
ng = path_u2v[half+1]
Depth = np.zeros(N+1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N+1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l-1-half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l%2
ans = max(Depth) + half + d
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8,i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
N, u, v = map(int, input().split())
if N==2:
print(0)
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
| 64 | 88 | 1,483 | 2,225 | import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[] for _ in range(N + 1)]
for ab in AB:
a, b = ab
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N + 1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l - 2) // 2
c = path_u2v[half]
ng = path_u2v[half + 1]
Depth = np.zeros(N + 1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N + 1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l - 1 - half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l % 2
ans = max(Depth) + half + d
return ans
def main():
N, u, v = list(map(int, input().split()))
if N == 2:
print((0))
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
| import os
import sys
import numpy as np
def solve(N, U, V, AB):
G = [[0] * 0 for _ in range(N + 1)]
for idx_ab in range(len(AB)):
a, b = AB[idx_ab]
G[a].append(b)
G[b].append(a)
P1 = np.zeros(N + 1, dtype=np.int64)
def dfs1(u):
st = [u]
while st:
v = st.pop()
p = P1[v]
for u in G[v]:
if p != u:
st.append(u)
P1[u] = v
dfs1(U)
path_u2v = [U]
v = V
while v != U:
v = P1[v]
path_u2v.append(v)
path_u2v.reverse()
l = len(path_u2v)
half = (l - 2) // 2
c = path_u2v[half]
ng = path_u2v[half + 1]
Depth = np.zeros(N + 1, dtype=np.int64)
def dfs2(c):
st = [c]
P = np.zeros(N + 1, dtype=np.int64)
while st:
v = st.pop()
p = P[v]
d = Depth[v]
for u in G[v]:
if p != u and u != ng:
st.append(u)
P[u] = v
Depth[u] = d + 1
dfs2(c)
c_ = path_u2v[l - 1 - half]
v = c_
while v != c:
Depth[v] = 0
v = P1[v]
d = l % 2
ans = max(Depth) + half + d
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8,i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
N, u, v = map(int, input().split())
if N == 2:
print(0)
return
AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, u, v, AB)
print(ans)
main()
| false | 27.272727 | [
"- G = [[] for _ in range(N + 1)]",
"- for ab in AB:",
"- a, b = ab",
"+ G = [[0] * 0 for _ in range(N + 1)]",
"+ for idx_ab in range(len(AB)):",
"+ a, b = AB[idx_ab]",
"+# >>> numba compile >>>",
"+numba_config = [",
"+ [solve, \"i8(i8,i8,i8,i8[:,:])\"],",
"+]",
"+i... | false | 0.256695 | 0.362233 | 0.708648 | [
"s681258200",
"s190092456"
] |
u729133443 | p03072 | python | s028074434 | s633946798 | 190 | 17 | 38,256 | 2,940 | Accepted | Accepted | 91.05 | n,*h=list(map(int,open(0).read().split()));print((sum(h[i]>=max(h[:i]+[0])for i in range(n)))) | _,t=open(0);m=a=0
for h in map(int,t.split()):a+=h>=m;m=max(m,h)
print(a) | 1 | 3 | 86 | 75 | n, *h = list(map(int, open(0).read().split()))
print((sum(h[i] >= max(h[:i] + [0]) for i in range(n))))
| _, t = open(0)
m = a = 0
for h in map(int, t.split()):
a += h >= m
m = max(m, h)
print(a)
| false | 66.666667 | [
"-n, *h = list(map(int, open(0).read().split()))",
"-print((sum(h[i] >= max(h[:i] + [0]) for i in range(n))))",
"+_, t = open(0)",
"+m = a = 0",
"+for h in map(int, t.split()):",
"+ a += h >= m",
"+ m = max(m, h)",
"+print(a)"
] | false | 0.046223 | 0.044689 | 1.034318 | [
"s028074434",
"s633946798"
] |
u276115223 | p03331 | python | s609715391 | s587600641 | 185 | 144 | 3,064 | 3,064 | Accepted | Accepted | 22.16 | # AGC 025: A – Digits Sum
n = int(eval(input()))
answer = 999999999
for i in range(1, n // 2 + 1):
num_A = str(i)
num_B = str(n - i)
sum_digits_A = sum([int(j) for j in num_A])
sum_digits_B = sum([int(j) for j in num_B])
answer = min(answer, sum_digits_A + sum_digits_B)
print(answer) | # AGC 025: A – Digits Sum
N = int(eval(input()))
n = N // 2 if N % 2 == 0 else N // 2 + 1
min_sum = 9999
for i in range(1, n + 1):
sum_digits = 0
A = i
B = N - i
while A != 0:
sum_digits += A % 10
A //= 10
while B != 0:
sum_digits += B % 10
B //= 10
min_sum = min(min_sum, sum_digits)
print(min_sum) | 14 | 21 | 315 | 386 | # AGC 025: A – Digits Sum
n = int(eval(input()))
answer = 999999999
for i in range(1, n // 2 + 1):
num_A = str(i)
num_B = str(n - i)
sum_digits_A = sum([int(j) for j in num_A])
sum_digits_B = sum([int(j) for j in num_B])
answer = min(answer, sum_digits_A + sum_digits_B)
print(answer)
| # AGC 025: A – Digits Sum
N = int(eval(input()))
n = N // 2 if N % 2 == 0 else N // 2 + 1
min_sum = 9999
for i in range(1, n + 1):
sum_digits = 0
A = i
B = N - i
while A != 0:
sum_digits += A % 10
A //= 10
while B != 0:
sum_digits += B % 10
B //= 10
min_sum = min(min_sum, sum_digits)
print(min_sum)
| false | 33.333333 | [
"-n = int(eval(input()))",
"-answer = 999999999",
"-for i in range(1, n // 2 + 1):",
"- num_A = str(i)",
"- num_B = str(n - i)",
"- sum_digits_A = sum([int(j) for j in num_A])",
"- sum_digits_B = sum([int(j) for j in num_B])",
"- answer = min(answer, sum_digits_A + sum_digits_B)",
"-p... | false | 0.139661 | 0.12 | 1.163838 | [
"s609715391",
"s587600641"
] |
u208216648 | p02900 | python | s823488286 | s879079533 | 522 | 186 | 5,628 | 3,064 | Accepted | Accepted | 64.37 | from fractions import gcd
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
a, b = list(map(int,input().split()))
a_d = make_divisors(a)
b_d = make_divisors(b)
yakusu = []
for i in a_d:
if i in b_d:
yakusu.append(i)
ans = [yakusu.pop(0)]
for i in yakusu:
flg=0
tmp = 0
for j,num in enumerate(ans):
if gcd(num,i) != 1:
ans[j] = min(i,num)
flg = 1
break
if flg == 0:
ans.append(i)
print((len(ans)))
| def gcd(x,y):
return x if y==0 else gcd(y, x%y)
def factorize(n):
pnum = []
for i in range(2,int(n**0.5)+1):
if n%i != 0:
continue
pnum.append([i,0])
while n%i == 0:
n /= i
pnum[-1][1] += 1
if n != 1:
pnum.append([int(n),1])
return pnum
a,b = list(map(int,input().split()))
n = gcd(a,b)
pnum = factorize(n)
print((len(pnum)+1)) | 37 | 20 | 711 | 432 | from fractions import gcd
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort()
return divisors
a, b = list(map(int, input().split()))
a_d = make_divisors(a)
b_d = make_divisors(b)
yakusu = []
for i in a_d:
if i in b_d:
yakusu.append(i)
ans = [yakusu.pop(0)]
for i in yakusu:
flg = 0
tmp = 0
for j, num in enumerate(ans):
if gcd(num, i) != 1:
ans[j] = min(i, num)
flg = 1
break
if flg == 0:
ans.append(i)
print((len(ans)))
| def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
def factorize(n):
pnum = []
for i in range(2, int(n**0.5) + 1):
if n % i != 0:
continue
pnum.append([i, 0])
while n % i == 0:
n /= i
pnum[-1][1] += 1
if n != 1:
pnum.append([int(n), 1])
return pnum
a, b = list(map(int, input().split()))
n = gcd(a, b)
pnum = factorize(n)
print((len(pnum) + 1))
| false | 45.945946 | [
"-from fractions import gcd",
"+def gcd(x, y):",
"+ return x if y == 0 else gcd(y, x % y)",
"-def make_divisors(n):",
"- divisors = []",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- divisors.append(i)",
"- if i != n // i:",
"- ... | false | 0.058391 | 0.085376 | 0.683927 | [
"s823488286",
"s879079533"
] |
u530383736 | p02605 | python | s229906926 | s084897872 | 1,337 | 1,179 | 179,580 | 99,824 | Accepted | Accepted | 11.82 | # -*- coding: utf-8 -*-
import sys
import io
def main():
N = int( sys.stdin.readline() )
XYU_list = []
for _ in range(N):
x,y,u = sys.stdin.readline().rstrip().split()
XYU_list.append( [int(x),int(y),u] )
check_UD = {}
check_LR = {}
check_UR = {}
check_DL = {}
check_UL = {}
check_DR = {}
for x,y,u in XYU_list:
if (u == "U") or (u == "D"):
check_UD.setdefault( x , [] )
check_UD[x].append( (y,u) )
if (u == "L") or (u == "R"):
check_LR.setdefault( y , [] )
check_LR[y].append( (x,u) )
if (u == "U") or (u == "R"):
check_UR.setdefault( (x+y) , [] )
check_UR[ (x+y) ].append( (x,u) )
if (u == "D") or (u == "L"):
check_DL.setdefault( (x+y) , [] )
check_DL[ (x+y) ].append( (x,u) )
if (u == "U") or (u == "L"):
check_UL.setdefault( (x-y) , [] )
check_UL[ (x-y) ].append( (x,u) )
if (u == "D") or (u == "R"):
check_DR.setdefault( (x-y) , [] )
check_DR[ (x-y) ].append( (x,u) )
for check_dic in [check_UD, check_LR, check_UR, check_DL, check_UL, check_DR]:
for key in check_dic:
check_dic[key].sort()
diff_min = float("inf")
for arr in list(check_UD.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i+1][1] == "D"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) / 2 )
for arr in list(check_LR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i+1][1] == "L"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) / 2 )
for arr in list(check_UR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i+1][1] == "U"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) )
for arr in list(check_DL.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "D") and (arr[i+1][1] == "L"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) )
for arr in list(check_UL.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i+1][1] == "L"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) )
for arr in list(check_DR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i+1][1] == "D"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) )
if diff_min != float("inf"):
print(( int(diff_min * 10) ))
else:
print("SAFE")
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
import io
def main():
N = int( sys.stdin.readline() )
XYU_list = []
for _ in range(N):
x,y,u = sys.stdin.readline().rstrip().split()
XYU_list.append( [int(x),int(y),u] )
diff = float("inf")
# check(1) rotate 0 degree
ret = checkSafety_UD(XYU_list)
diff = min(diff, ret)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(2) rotate 90 degree
rotate(XYU_list)
ret = checkSafety_UD(XYU_list)
diff = min(diff, ret)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(3) rotate 180 degree
rotate(XYU_list)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(4) rotate 270 degree
rotate(XYU_list)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
if diff != float("inf"):
print(( int(diff * 10) ))
else:
print("SAFE")
def rotate(XYU_list :list):
for i in range(len(XYU_list)):
x,y,u = XYU_list[i][0], XYU_list[i][1], XYU_list[i][2]
x2 = -y
y2 = x
if u == "U": u2 = "L"
if u == "D": u2 = "R"
if u == "L": u2 = "D"
if u == "R": u2 = "U"
XYU_list[i] = [x2,y2,u2]
def checkSafety_UD(XYU_list :list) -> int:
check_UD = {}
for x,y,u in XYU_list:
if (u == "U") or (u == "D"):
check_UD.setdefault( x , [] )
check_UD[x].append( (y,u) )
for key in check_UD:
check_UD[key].sort()
diff_min = float("inf")
for arr in list(check_UD.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i+1][1] == "D"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) / 2 )
return diff_min
def checkSafety_UR(XYU_list) -> int:
check_UR = {}
for x,y,u in XYU_list:
if (u == "U") or (u == "R"):
check_UR.setdefault( (x+y) , [] )
check_UR[ (x+y) ].append( (x,u) )
for key in check_UR:
check_UR[key].sort()
diff_min = float("inf")
for arr in list(check_UR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i+1][1] == "U"):
diff_min = min( diff_min, (arr[i+1][0] - arr[i][0]) )
return diff_min
if __name__ == "__main__":
main()
| 99 | 113 | 2,821 | 2,486 | # -*- coding: utf-8 -*-
import sys
import io
def main():
N = int(sys.stdin.readline())
XYU_list = []
for _ in range(N):
x, y, u = sys.stdin.readline().rstrip().split()
XYU_list.append([int(x), int(y), u])
check_UD = {}
check_LR = {}
check_UR = {}
check_DL = {}
check_UL = {}
check_DR = {}
for x, y, u in XYU_list:
if (u == "U") or (u == "D"):
check_UD.setdefault(x, [])
check_UD[x].append((y, u))
if (u == "L") or (u == "R"):
check_LR.setdefault(y, [])
check_LR[y].append((x, u))
if (u == "U") or (u == "R"):
check_UR.setdefault((x + y), [])
check_UR[(x + y)].append((x, u))
if (u == "D") or (u == "L"):
check_DL.setdefault((x + y), [])
check_DL[(x + y)].append((x, u))
if (u == "U") or (u == "L"):
check_UL.setdefault((x - y), [])
check_UL[(x - y)].append((x, u))
if (u == "D") or (u == "R"):
check_DR.setdefault((x - y), [])
check_DR[(x - y)].append((x, u))
for check_dic in [check_UD, check_LR, check_UR, check_DL, check_UL, check_DR]:
for key in check_dic:
check_dic[key].sort()
diff_min = float("inf")
for arr in list(check_UD.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i + 1][1] == "D"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]) / 2)
for arr in list(check_LR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i + 1][1] == "L"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]) / 2)
for arr in list(check_UR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i + 1][1] == "U"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]))
for arr in list(check_DL.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "D") and (arr[i + 1][1] == "L"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]))
for arr in list(check_UL.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i + 1][1] == "L"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]))
for arr in list(check_DR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i + 1][1] == "D"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]))
if diff_min != float("inf"):
print((int(diff_min * 10)))
else:
print("SAFE")
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
import io
def main():
N = int(sys.stdin.readline())
XYU_list = []
for _ in range(N):
x, y, u = sys.stdin.readline().rstrip().split()
XYU_list.append([int(x), int(y), u])
diff = float("inf")
# check(1) rotate 0 degree
ret = checkSafety_UD(XYU_list)
diff = min(diff, ret)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(2) rotate 90 degree
rotate(XYU_list)
ret = checkSafety_UD(XYU_list)
diff = min(diff, ret)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(3) rotate 180 degree
rotate(XYU_list)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
# check(4) rotate 270 degree
rotate(XYU_list)
ret = checkSafety_UR(XYU_list)
diff = min(diff, ret)
if diff != float("inf"):
print((int(diff * 10)))
else:
print("SAFE")
def rotate(XYU_list: list):
for i in range(len(XYU_list)):
x, y, u = XYU_list[i][0], XYU_list[i][1], XYU_list[i][2]
x2 = -y
y2 = x
if u == "U":
u2 = "L"
if u == "D":
u2 = "R"
if u == "L":
u2 = "D"
if u == "R":
u2 = "U"
XYU_list[i] = [x2, y2, u2]
def checkSafety_UD(XYU_list: list) -> int:
check_UD = {}
for x, y, u in XYU_list:
if (u == "U") or (u == "D"):
check_UD.setdefault(x, [])
check_UD[x].append((y, u))
for key in check_UD:
check_UD[key].sort()
diff_min = float("inf")
for arr in list(check_UD.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "U") and (arr[i + 1][1] == "D"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]) / 2)
return diff_min
def checkSafety_UR(XYU_list) -> int:
check_UR = {}
for x, y, u in XYU_list:
if (u == "U") or (u == "R"):
check_UR.setdefault((x + y), [])
check_UR[(x + y)].append((x, u))
for key in check_UR:
check_UR[key].sort()
diff_min = float("inf")
for arr in list(check_UR.values()):
for i in range(len(arr) - 1):
if (arr[i][1] == "R") and (arr[i + 1][1] == "U"):
diff_min = min(diff_min, (arr[i + 1][0] - arr[i][0]))
return diff_min
if __name__ == "__main__":
main()
| false | 12.389381 | [
"+ diff = float(\"inf\")",
"+ # check(1) rotate 0 degree",
"+ ret = checkSafety_UD(XYU_list)",
"+ diff = min(diff, ret)",
"+ ret = checkSafety_UR(XYU_list)",
"+ diff = min(diff, ret)",
"+ # check(2) rotate 90 degree",
"+ rotate(XYU_list)",
"+ ret = checkSafety_UD(XYU_list)... | false | 0.049479 | 0.048562 | 1.018895 | [
"s229906926",
"s084897872"
] |
u312025627 | p04044 | python | s795394802 | s544897845 | 167 | 17 | 38,256 | 3,060 | Accepted | Accepted | 89.82 | def main():
N, L = (int(i) for i in input().split())
A = [eval(input()) for i in range(N)]
A.sort()
print(("".join(A)))
if __name__ == '__main__':
main()
| def main():
N, K = (int(i) for i in input().split())
A = [eval(input()) for i in range(N)]
A.sort()
print(("".join(A)))
if __name__ == '__main__':
main()
| 9 | 9 | 176 | 176 | def main():
N, L = (int(i) for i in input().split())
A = [eval(input()) for i in range(N)]
A.sort()
print(("".join(A)))
if __name__ == "__main__":
main()
| def main():
N, K = (int(i) for i in input().split())
A = [eval(input()) for i in range(N)]
A.sort()
print(("".join(A)))
if __name__ == "__main__":
main()
| false | 0 | [
"- N, L = (int(i) for i in input().split())",
"+ N, K = (int(i) for i in input().split())"
] | false | 0.035738 | 0.036774 | 0.971838 | [
"s795394802",
"s544897845"
] |
u896741788 | p03800 | python | s794985486 | s017722091 | 421 | 339 | 5,476 | 5,476 | Accepted | Accepted | 19.48 | n=int(eval(input()))
s=eval(input())
for p in range(4):
l=[p//2,p%2]+[0]*(n-2)
for i in range(1,n):
l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**int(s[i]=="o")][l[i]]
for i in range(n):
if s[i]!="ox"[int(l[(i-1)%n]==l[(i+1)%n])-l[i]]:break
else:print(("".join("WS"[x] for x in l)));exit()
print((-1)) | n=int(eval(input()));s=eval(input())
for p in range(4):
l=[p//2,p%2]+[0]*(n-2)
for i in range(1,n):l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**(s[i]=="o")][l[i]]
for i in range(n):
if s[i]!="ox"[int(l[(i-1)%n]==l[(i+1)%n])-l[i]]:break
else:print(("".join("WS"[x]for x in l)));exit()
print((-1)) | 10 | 8 | 317 | 290 | n = int(eval(input()))
s = eval(input())
for p in range(4):
l = [p // 2, p % 2] + [0] * (n - 2)
for i in range(1, n):
l[(i + 1) % n] = [l[i - 1], 1 - l[i - 1]][:: (-1) ** int(s[i] == "o")][l[i]]
for i in range(n):
if s[i] != "ox"[int(l[(i - 1) % n] == l[(i + 1) % n]) - l[i]]:
break
else:
print(("".join("WS"[x] for x in l)))
exit()
print((-1))
| n = int(eval(input()))
s = eval(input())
for p in range(4):
l = [p // 2, p % 2] + [0] * (n - 2)
for i in range(1, n):
l[(i + 1) % n] = [l[i - 1], 1 - l[i - 1]][:: (-1) ** (s[i] == "o")][l[i]]
for i in range(n):
if s[i] != "ox"[int(l[(i - 1) % n] == l[(i + 1) % n]) - l[i]]:
break
else:
print(("".join("WS"[x] for x in l)))
exit()
print((-1))
| false | 20 | [
"- l[(i + 1) % n] = [l[i - 1], 1 - l[i - 1]][:: (-1) ** int(s[i] == \"o\")][l[i]]",
"+ l[(i + 1) % n] = [l[i - 1], 1 - l[i - 1]][:: (-1) ** (s[i] == \"o\")][l[i]]"
] | false | 0.045129 | 0.042803 | 1.054353 | [
"s794985486",
"s017722091"
] |
u532966492 | p02775 | python | s299226714 | s485998140 | 668 | 581 | 21,220 | 155,648 | Accepted | Accepted | 13.02 | def main():
a = list(map(int, list(eval(input()))))
a.reverse()
n = len(a)
a += [0]
b = [i for i in a]
cnt = 0
for i in range(len(a)):
if b[i] > 5 or (b[i] == 5 and b[i+1] >= 5):
b[i] = 0
b[i+1] += 1
cnt = sum(b)
for i in range(n):
if a[i] <= b[i]:
cnt += b[i]-a[i]
else:
b[i] += 10
b[i+1] -= 1
cnt += b[i]-a[i]
print(cnt)
main() | def main():
a = list(map(int, list(eval(input()))))
n = len(a)
dp = [[0, 0] for _ in [0]*(n+1)]
dp[0][1] = 1
for i in range(n):
dp[i+1][0] = min(dp[i][0]+a[i], dp[i][1]+10-a[i])
dp[i+1][1] = min(dp[i][0]+a[i]+1, dp[i][1]+9-a[i])
print((dp[n][0]))
main()
| 23 | 11 | 483 | 297 | def main():
a = list(map(int, list(eval(input()))))
a.reverse()
n = len(a)
a += [0]
b = [i for i in a]
cnt = 0
for i in range(len(a)):
if b[i] > 5 or (b[i] == 5 and b[i + 1] >= 5):
b[i] = 0
b[i + 1] += 1
cnt = sum(b)
for i in range(n):
if a[i] <= b[i]:
cnt += b[i] - a[i]
else:
b[i] += 10
b[i + 1] -= 1
cnt += b[i] - a[i]
print(cnt)
main()
| def main():
a = list(map(int, list(eval(input()))))
n = len(a)
dp = [[0, 0] for _ in [0] * (n + 1)]
dp[0][1] = 1
for i in range(n):
dp[i + 1][0] = min(dp[i][0] + a[i], dp[i][1] + 10 - a[i])
dp[i + 1][1] = min(dp[i][0] + a[i] + 1, dp[i][1] + 9 - a[i])
print((dp[n][0]))
main()
| false | 52.173913 | [
"- a.reverse()",
"- a += [0]",
"- b = [i for i in a]",
"- cnt = 0",
"- for i in range(len(a)):",
"- if b[i] > 5 or (b[i] == 5 and b[i + 1] >= 5):",
"- b[i] = 0",
"- b[i + 1] += 1",
"- cnt = sum(b)",
"+ dp = [[0, 0] for _ in [0] * (n + 1)]",
"+ ... | false | 0.110847 | 0.038337 | 2.891426 | [
"s299226714",
"s485998140"
] |
u475503988 | p03110 | python | s832314527 | s480590638 | 21 | 18 | 3,188 | 2,940 | Accepted | Accepted | 14.29 | N = int(eval(input()))
ans = 0
for _ in range(N):
x, u = input().split()
if u == 'JPY':
ans += float(x)
elif u == 'BTC':
ans += float(x) * 380000.0
print(ans) | N = int(eval(input()))
ans = 0.0
for _ in range(N):
x, u = input().split()
if u == 'JPY':
ans += float(x)
elif u == 'BTC':
ans += float(x) * 380000.0
print(ans) | 9 | 9 | 188 | 190 | N = int(eval(input()))
ans = 0
for _ in range(N):
x, u = input().split()
if u == "JPY":
ans += float(x)
elif u == "BTC":
ans += float(x) * 380000.0
print(ans)
| N = int(eval(input()))
ans = 0.0
for _ in range(N):
x, u = input().split()
if u == "JPY":
ans += float(x)
elif u == "BTC":
ans += float(x) * 380000.0
print(ans)
| false | 0 | [
"-ans = 0",
"+ans = 0.0"
] | false | 0.036739 | 0.035735 | 1.028092 | [
"s832314527",
"s480590638"
] |
u093607836 | p00001 | python | s996465284 | s126238356 | 20 | 10 | 4,204 | 4,188 | Accepted | Accepted | 50 | list = list()
for i in range(10):
list.append(eval(input()))
list.sort()
list.reverse()
for i in range(3):
print(list[i]) | import sys
l = sorted([int(s) for s in sys.stdin], reverse=True)[:3]
print('\n'.join([str(s) for s in l])) | 7 | 4 | 124 | 109 | list = list()
for i in range(10):
list.append(eval(input()))
list.sort()
list.reverse()
for i in range(3):
print(list[i])
| import sys
l = sorted([int(s) for s in sys.stdin], reverse=True)[:3]
print("\n".join([str(s) for s in l]))
| false | 42.857143 | [
"-list = list()",
"-for i in range(10):",
"- list.append(eval(input()))",
"-list.sort()",
"-list.reverse()",
"-for i in range(3):",
"- print(list[i])",
"+import sys",
"+",
"+l = sorted([int(s) for s in sys.stdin], reverse=True)[:3]",
"+print(\"\\n\".join([str(s) for s in l]))"
] | false | 0.07073 | 0.065488 | 1.080048 | [
"s996465284",
"s126238356"
] |
u340781749 | p02868 | python | s452047721 | s253161541 | 1,744 | 668 | 25,792 | 58,492 | Accepted | Accepted | 61.7 | import sys
class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n, INF):
"""
:param n: 要素数
:param INF: 初期値(入りうる要素より十分に大きな数)
"""
self.n = n
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [INF] * (n2 << 1)
self.INF = INF
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
i >>= 1
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
result = self.INF
l = a + self.n2
r = b + self.n2
while l < r:
if r & 1:
result = min(result, self.tree[r - 1])
if l & 1:
result = min(result, self.tree[l])
l += 1
l >>= 1
r >>= 1
return result
def debug_print(self):
a = 1
while a <= self.n2:
b = a << 1
print((self.tree[a:b]))
a = b
print()
INF = 10 ** 18
n, m = list(map(int, input().split()))
segments = [tuple(map(int, line.split())) for line in sys.stdin]
segments.sort()
sgt = SegTreeMin(n, INF)
sgt.update(0, 0)
for l, r, c in segments:
use_current = sgt.get_min(l - 1, r - 1) + c
not_current = sgt.get_min(r - 1, r)
if use_current < not_current:
sgt.update(r - 1, use_current)
ans = sgt.get_min(n - 1, n)
if ans == INF:
print((-1))
else:
print(ans)
| import sys
from heapq import heappop, heappush
def dijkstra(s, t, links):
q = [(0, s)]
visited = set()
while q:
cost, v = heappop(q)
if v in visited:
continue
if v == t:
return cost
visited.add(v)
for u, c in links[v]:
if u in visited:
continue
heappush(q, (cost + c, u))
return -1
n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
for v in range(n - 1):
links[v + 1].add((v, 0))
for line in sys.stdin:
l, r, c = list(map(int, line.split()))
links[l - 1].add((r - 1, c))
print((dijkstra(0, n - 1, links)))
| 85 | 29 | 1,871 | 685 | import sys
class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n, INF):
"""
:param n: 要素数
:param INF: 初期値(入りうる要素より十分に大きな数)
"""
self.n = n
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [INF] * (n2 << 1)
self.INF = INF
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
i >>= 1
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
result = self.INF
l = a + self.n2
r = b + self.n2
while l < r:
if r & 1:
result = min(result, self.tree[r - 1])
if l & 1:
result = min(result, self.tree[l])
l += 1
l >>= 1
r >>= 1
return result
def debug_print(self):
a = 1
while a <= self.n2:
b = a << 1
print((self.tree[a:b]))
a = b
print()
INF = 10**18
n, m = list(map(int, input().split()))
segments = [tuple(map(int, line.split())) for line in sys.stdin]
segments.sort()
sgt = SegTreeMin(n, INF)
sgt.update(0, 0)
for l, r, c in segments:
use_current = sgt.get_min(l - 1, r - 1) + c
not_current = sgt.get_min(r - 1, r)
if use_current < not_current:
sgt.update(r - 1, use_current)
ans = sgt.get_min(n - 1, n)
if ans == INF:
print((-1))
else:
print(ans)
| import sys
from heapq import heappop, heappush
def dijkstra(s, t, links):
q = [(0, s)]
visited = set()
while q:
cost, v = heappop(q)
if v in visited:
continue
if v == t:
return cost
visited.add(v)
for u, c in links[v]:
if u in visited:
continue
heappush(q, (cost + c, u))
return -1
n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
for v in range(n - 1):
links[v + 1].add((v, 0))
for line in sys.stdin:
l, r, c = list(map(int, line.split()))
links[l - 1].add((r - 1, c))
print((dijkstra(0, n - 1, links)))
| false | 65.882353 | [
"+from heapq import heappop, heappush",
"-class SegTreeMin:",
"- \"\"\"",
"- 以下のクエリを処理する",
"- 1.update: i番目の値をxに更新する",
"- 2.get_min: 区間[l, r)の最小値を得る",
"- \"\"\"",
"-",
"- def __init__(self, n, INF):",
"- \"\"\"",
"- :param n: 要素数",
"- :param INF: 初期値(入りう... | false | 0.034732 | 0.041069 | 0.84572 | [
"s452047721",
"s253161541"
] |
u599547273 | p03290 | python | s949316395 | s220001569 | 49 | 24 | 3,064 | 3,188 | Accepted | Accepted | 51.02 |
D, G = list(map(int, input().split(" ")))
PC = [list(map(int, input().split(" "))) for _ in range(D)]
min_count = 10**18
for i in range(1<<D):
# print(bin(i)[2:])
count = 0
point = 0
top_zero = None
for j, (p, c) in enumerate(PC):
if (i>>j)%2:
count += p
point += 100*(j+1)*p + c
else:
top_zero = j
if top_zero != None:
for j in range(PC[top_zero][0]-1):
# print(j, top_zero, point)
if point >= G:
break
point += 100*(top_zero+1)
count += 1
# print("count:", count)
if point >= G:
min_count = min(min_count, count)
print(min_count) | D, G = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]
p, c = list(zip(*PC))
min_count = 10**18
for i in range(1<<D):
h = -1
point = 0
count = 0
for j in range(D):
if (i>>j)%2:
point += 100*(j+1)*p[j] + c[j]
count += p[j]
else:
h = j
if h > -1 and G > point:
x = -(-(G-point)//(100*(h+1)))
if x > p[h]:
continue
count += x
min_count = min(min_count, count)
print(min_count) | 28 | 24 | 719 | 540 | D, G = list(map(int, input().split(" ")))
PC = [list(map(int, input().split(" "))) for _ in range(D)]
min_count = 10**18
for i in range(1 << D):
# print(bin(i)[2:])
count = 0
point = 0
top_zero = None
for j, (p, c) in enumerate(PC):
if (i >> j) % 2:
count += p
point += 100 * (j + 1) * p + c
else:
top_zero = j
if top_zero != None:
for j in range(PC[top_zero][0] - 1):
# print(j, top_zero, point)
if point >= G:
break
point += 100 * (top_zero + 1)
count += 1
# print("count:", count)
if point >= G:
min_count = min(min_count, count)
print(min_count)
| D, G = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]
p, c = list(zip(*PC))
min_count = 10**18
for i in range(1 << D):
h = -1
point = 0
count = 0
for j in range(D):
if (i >> j) % 2:
point += 100 * (j + 1) * p[j] + c[j]
count += p[j]
else:
h = j
if h > -1 and G > point:
x = -(-(G - point) // (100 * (h + 1)))
if x > p[h]:
continue
count += x
min_count = min(min_count, count)
print(min_count)
| false | 14.285714 | [
"-D, G = list(map(int, input().split(\" \")))",
"-PC = [list(map(int, input().split(\" \"))) for _ in range(D)]",
"+D, G = list(map(int, input().split()))",
"+PC = [list(map(int, input().split())) for _ in range(D)]",
"+p, c = list(zip(*PC))",
"- # print(bin(i)[2:])",
"+ h = -1",
"+ point = 0... | false | 0.045701 | 0.122484 | 0.373121 | [
"s949316395",
"s220001569"
] |
u991567869 | p02675 | python | s351406429 | s325266900 | 23 | 21 | 9,144 | 9,164 | Accepted | Accepted | 8.7 | n = eval(input())
if n[-1] == "3":
print("bon")
elif n[-1] == "0":
print("pon")
elif n[-1] == "1":
print("pon")
elif n[-1] == "6":
print("pon")
elif n[-1] == "8":
print("pon")
else:
print("hon") | n = int(eval(input()))%10
if n == 3:
ans = "bon"
elif n in [0, 1, 6, 8]:
ans = "pon"
else:
ans = "hon"
print(ans) | 14 | 10 | 226 | 130 | n = eval(input())
if n[-1] == "3":
print("bon")
elif n[-1] == "0":
print("pon")
elif n[-1] == "1":
print("pon")
elif n[-1] == "6":
print("pon")
elif n[-1] == "8":
print("pon")
else:
print("hon")
| n = int(eval(input())) % 10
if n == 3:
ans = "bon"
elif n in [0, 1, 6, 8]:
ans = "pon"
else:
ans = "hon"
print(ans)
| false | 28.571429 | [
"-n = eval(input())",
"-if n[-1] == \"3\":",
"- print(\"bon\")",
"-elif n[-1] == \"0\":",
"- print(\"pon\")",
"-elif n[-1] == \"1\":",
"- print(\"pon\")",
"-elif n[-1] == \"6\":",
"- print(\"pon\")",
"-elif n[-1] == \"8\":",
"- print(\"pon\")",
"+n = int(eval(input())) % 10",
... | false | 0.041335 | 0.037233 | 1.110185 | [
"s351406429",
"s325266900"
] |
u302789073 | p03373 | python | s743329017 | s645098155 | 85 | 76 | 12,868 | 12,836 | Accepted | Accepted | 10.59 | a,b,c,x,y=[int(i) for i in input().split()]
sum_list=[]
max_c=max(x,y)
#ABセットをi組頼む
for i in range(max_c+1):
#Cのみ
if i>=x and i>=y:
sum=2*c*i
#CとA
elif i<x and i>=y:
sum=2*c*i+a*(x-i)
#CとB
elif i>=x and i<y:
sum=2*c*i+b*(y-i)
#CとAとB
else:
sum=2*c*i+a*(x-i)+b*(y-i)
sum_list.append(sum)
print((min(sum_list))) | a,b,c,x,y=list(map(int, input().split()))
#cのセット数の最大値
cmax=max(x,y)
t_list=[]
#cを何セット買うか
for i in range(cmax+1):
if x>=i and y>=i:
total=c*2*i+a*(x-i)+b*(y-i)
elif x>=i and y<i:
total=c*2*i+a*(x-i)
else:
total=c*2*i+b*(y-i)
t_list.append(total)
print((min(t_list))) | 30 | 21 | 452 | 352 | a, b, c, x, y = [int(i) for i in input().split()]
sum_list = []
max_c = max(x, y)
# ABセットをi組頼む
for i in range(max_c + 1):
# Cのみ
if i >= x and i >= y:
sum = 2 * c * i
# CとA
elif i < x and i >= y:
sum = 2 * c * i + a * (x - i)
# CとB
elif i >= x and i < y:
sum = 2 * c * i + b * (y - i)
# CとAとB
else:
sum = 2 * c * i + a * (x - i) + b * (y - i)
sum_list.append(sum)
print((min(sum_list)))
| a, b, c, x, y = list(map(int, input().split()))
# cのセット数の最大値
cmax = max(x, y)
t_list = []
# cを何セット買うか
for i in range(cmax + 1):
if x >= i and y >= i:
total = c * 2 * i + a * (x - i) + b * (y - i)
elif x >= i and y < i:
total = c * 2 * i + a * (x - i)
else:
total = c * 2 * i + b * (y - i)
t_list.append(total)
print((min(t_list)))
| false | 30 | [
"-a, b, c, x, y = [int(i) for i in input().split()]",
"-sum_list = []",
"-max_c = max(x, y)",
"-# ABセットをi組頼む",
"-for i in range(max_c + 1):",
"- # Cのみ",
"- if i >= x and i >= y:",
"- sum = 2 * c * i",
"- # CとA",
"- elif i < x and i >= y:",
"- sum = 2 * c * i + a * (x - ... | false | 0.04268 | 0.078831 | 0.54141 | [
"s743329017",
"s645098155"
] |
u766566560 | p02707 | python | s901395614 | s414383270 | 176 | 157 | 34,104 | 33,764 | Accepted | Accepted | 10.8 | import collections
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = collections.Counter(A)
for i in range(1, N+1):
print((cnt[i])) | import collections
N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0] * (N+1)
for i in range(len(A)):
ans[A[i]] += 1
for i in range(1, N+1):
print((ans[i])) | 7 | 10 | 149 | 183 | import collections
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = collections.Counter(A)
for i in range(1, N + 1):
print((cnt[i]))
| import collections
N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0] * (N + 1)
for i in range(len(A)):
ans[A[i]] += 1
for i in range(1, N + 1):
print((ans[i]))
| false | 30 | [
"-cnt = collections.Counter(A)",
"+ans = [0] * (N + 1)",
"+for i in range(len(A)):",
"+ ans[A[i]] += 1",
"- print((cnt[i]))",
"+ print((ans[i]))"
] | false | 0.036531 | 0.102564 | 0.356181 | [
"s901395614",
"s414383270"
] |
u426683236 | p03095 | python | s652783615 | s218773416 | 210 | 20 | 49,904 | 3,188 | Accepted | Accepted | 90.48 | import collections
mod = 1000000007
def add(a, b):
return (a + b) % mod
def sub(a, b):
return (a + mod - b) % mod
def mul(a, b):
return ((a % mod) * (b % mod)) % mod
def power(x, y):
if y == 0 : return 1
elif y == 1 : return x % mod
elif y % 2 == 0 : return power(x, y//2)**2 % mod
else : return power(x, y//2)**2 * x % mod
def div(a, b):
return mul(a, power(b, mod-2))
def solve():
N=int(eval(input()))
S=list(eval(input()))
c=collections.Counter(S)
ans=1
for k in list(c.keys()):
ans = mul(ans,c[k]+1)
return sub(ans,1)
print((solve()))
| def solve():
n = int(eval(input()))
s = eval(input())
ans = 1
mod = 1000000007
for i in range(26):
c = chr(ord('a') + i)
a = s.count(c)
a = (a + 1) % mod
ans = (ans * a) % mod
ans = (ans + mod - 1) % mod
print(ans)
if __name__ == "__main__":
solve()
| 32 | 17 | 643 | 321 | import collections
mod = 1000000007
def add(a, b):
return (a + b) % mod
def sub(a, b):
return (a + mod - b) % mod
def mul(a, b):
return ((a % mod) * (b % mod)) % mod
def power(x, y):
if y == 0:
return 1
elif y == 1:
return x % mod
elif y % 2 == 0:
return power(x, y // 2) ** 2 % mod
else:
return power(x, y // 2) ** 2 * x % mod
def div(a, b):
return mul(a, power(b, mod - 2))
def solve():
N = int(eval(input()))
S = list(eval(input()))
c = collections.Counter(S)
ans = 1
for k in list(c.keys()):
ans = mul(ans, c[k] + 1)
return sub(ans, 1)
print((solve()))
| def solve():
n = int(eval(input()))
s = eval(input())
ans = 1
mod = 1000000007
for i in range(26):
c = chr(ord("a") + i)
a = s.count(c)
a = (a + 1) % mod
ans = (ans * a) % mod
ans = (ans + mod - 1) % mod
print(ans)
if __name__ == "__main__":
solve()
| false | 46.875 | [
"-import collections",
"-",
"-mod = 1000000007",
"+def solve():",
"+ n = int(eval(input()))",
"+ s = eval(input())",
"+ ans = 1",
"+ mod = 1000000007",
"+ for i in range(26):",
"+ c = chr(ord(\"a\") + i)",
"+ a = s.count(c)",
"+ a = (a + 1) % mod",
"+ ... | false | 0.057943 | 0.035096 | 1.651007 | [
"s652783615",
"s218773416"
] |
u312025627 | p04001 | python | s132660048 | s817225824 | 195 | 176 | 39,664 | 39,024 | Accepted | Accepted | 9.74 | def main():
S = eval(input())
N = len(S)
ans = 0
for bit in range(1<<(N-1)):
cur = []
for i in range(N-1):
if bit&(1<<i):
cur.append(i)
else:
cur.append(N-1)
pre = 0
for c in cur:
num = int(S[pre:c+1])
ans += num
pre = c+1
print(ans)
if __name__ == '__main__':
main() | def main():
S = eval(input())
N = len(S)
ans = 0
for bit in range(1<<(N-1)):
pre = 0
for i in range(N-1):
if bit&(1<<i):
ans += int(S[pre:i+1])
pre = i + 1
else:
ans += int(S[pre:])
print(ans)
if __name__ == '__main__':
main() | 20 | 16 | 421 | 340 | def main():
S = eval(input())
N = len(S)
ans = 0
for bit in range(1 << (N - 1)):
cur = []
for i in range(N - 1):
if bit & (1 << i):
cur.append(i)
else:
cur.append(N - 1)
pre = 0
for c in cur:
num = int(S[pre : c + 1])
ans += num
pre = c + 1
print(ans)
if __name__ == "__main__":
main()
| def main():
S = eval(input())
N = len(S)
ans = 0
for bit in range(1 << (N - 1)):
pre = 0
for i in range(N - 1):
if bit & (1 << i):
ans += int(S[pre : i + 1])
pre = i + 1
else:
ans += int(S[pre:])
print(ans)
if __name__ == "__main__":
main()
| false | 20 | [
"- cur = []",
"+ pre = 0",
"- cur.append(i)",
"+ ans += int(S[pre : i + 1])",
"+ pre = i + 1",
"- cur.append(N - 1)",
"- pre = 0",
"- for c in cur:",
"- num = int(S[pre : c + 1])",
"- ans += n... | false | 0.048974 | 0.049955 | 0.98035 | [
"s132660048",
"s817225824"
] |
u285022453 | p03281 | python | s509442526 | s676617746 | 37 | 29 | 5,048 | 9,228 | Accepted | Accepted | 21.62 | # https://atcoder.jp/contests/abc106/tasks/abc106_b
import fractions
N = int(eval(input()))
def is_8(num):
if num < 1:
return False
elif num == 1:
return False
else:
divisor_list = []
divisor_list.append(1)
for i in range(2, num // 2 + 1):
if num % i == 0:
divisor_list.append(i)
divisor_list.append(num)
if len(divisor_list) == 8:
return True
cnt = 0
for i in range(1, N + 1, 2):
if is_8(i):
cnt += 1
print(cnt)
| # https://atcoder.jp/contests/abc106/tasks/abc106_b
import math
N = int(eval(input()))
def is_8(num):
if num < 1:
return False
elif num == 1:
return False
else:
divisor_list = set()
divisor_list.add(1)
# root nまで見れば問題ない
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
divisor_list.add(num // i)
divisor_list.add(i)
# 元の数を入れる
divisor_list.add(num)
if len(divisor_list) == 8:
return True
cnt = 0
for i in range(1, N + 1, 2):
if is_8(i):
cnt += 1
print(cnt)
| 27 | 30 | 558 | 648 | # https://atcoder.jp/contests/abc106/tasks/abc106_b
import fractions
N = int(eval(input()))
def is_8(num):
if num < 1:
return False
elif num == 1:
return False
else:
divisor_list = []
divisor_list.append(1)
for i in range(2, num // 2 + 1):
if num % i == 0:
divisor_list.append(i)
divisor_list.append(num)
if len(divisor_list) == 8:
return True
cnt = 0
for i in range(1, N + 1, 2):
if is_8(i):
cnt += 1
print(cnt)
| # https://atcoder.jp/contests/abc106/tasks/abc106_b
import math
N = int(eval(input()))
def is_8(num):
if num < 1:
return False
elif num == 1:
return False
else:
divisor_list = set()
divisor_list.add(1)
# root nまで見れば問題ない
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
divisor_list.add(num // i)
divisor_list.add(i)
# 元の数を入れる
divisor_list.add(num)
if len(divisor_list) == 8:
return True
cnt = 0
for i in range(1, N + 1, 2):
if is_8(i):
cnt += 1
print(cnt)
| false | 10 | [
"-import fractions",
"+import math",
"- divisor_list = []",
"- divisor_list.append(1)",
"- for i in range(2, num // 2 + 1):",
"+ divisor_list = set()",
"+ divisor_list.add(1)",
"+ # root nまで見れば問題ない",
"+ for i in range(2, int(math.sqrt(num)) + 1):",
... | false | 0.071024 | 0.037846 | 1.876658 | [
"s509442526",
"s676617746"
] |
u243572357 | p03105 | python | s243264233 | s499490069 | 20 | 18 | 3,316 | 2,940 | Accepted | Accepted | 10 | a, b, c = list(map(int, input().split()))
print((c if b//a >= c else b//a)) | a, b, c = list(map(int, input().split()))
print((b // a if b//a <= c else c)) | 2 | 2 | 69 | 70 | a, b, c = list(map(int, input().split()))
print((c if b // a >= c else b // a))
| a, b, c = list(map(int, input().split()))
print((b // a if b // a <= c else c))
| false | 0 | [
"-print((c if b // a >= c else b // a))",
"+print((b // a if b // a <= c else c))"
] | false | 0.046302 | 0.04595 | 1.007674 | [
"s243264233",
"s499490069"
] |
u489959379 | p03611 | python | s081284776 | s762293155 | 223 | 117 | 30,576 | 26,080 | Accepted | Accepted | 47.53 | import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
if n == 1:
print((1))
else:
L = []
for i in range(n):
L.append(list(range(A[i] - 1, A[i] + 2)))
ma = L[-1][-1]
mi = L[0][0]
res = [0] * (ma - mi + 1)
for l in L:
for i in l:
res[i - mi] += 1
print((max(res)))
if __name__ == '__main__':
resolve()
| import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
A = list(map(int, input().split()))
for i in range(n):
A.append(A[i] - 1)
A.append(A[i] + 1)
D = Counter(A)
res = 0
for v in list(D.values()):
res = max(res, v)
print(res)
if __name__ == '__main__':
resolve()
| 30 | 24 | 560 | 433 | import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
if n == 1:
print((1))
else:
L = []
for i in range(n):
L.append(list(range(A[i] - 1, A[i] + 2)))
ma = L[-1][-1]
mi = L[0][0]
res = [0] * (ma - mi + 1)
for l in L:
for i in l:
res[i - mi] += 1
print((max(res)))
if __name__ == "__main__":
resolve()
| import sys
from collections import Counter
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
A = list(map(int, input().split()))
for i in range(n):
A.append(A[i] - 1)
A.append(A[i] + 1)
D = Counter(A)
res = 0
for v in list(D.values()):
res = max(res, v)
print(res)
if __name__ == "__main__":
resolve()
| false | 20 | [
"+from collections import Counter",
"- A = sorted(list(map(int, input().split())))",
"- if n == 1:",
"- print((1))",
"- else:",
"- L = []",
"- for i in range(n):",
"- L.append(list(range(A[i] - 1, A[i] + 2)))",
"- ma = L[-1][-1]",
"- mi = L[0]... | false | 0.08869 | 0.045575 | 1.946032 | [
"s081284776",
"s762293155"
] |
u045953894 | p03698 | python | s343554464 | s414718528 | 29 | 25 | 8,908 | 8,888 | Accepted | Accepted | 13.79 | s = eval(input())
for i in range(len(s)):
for j in range(i+1,len(s)):
if s[i] == s[j]:
print('no')
exit()
print('yes') | import sys
s = eval(input())
s = sorted(s)
for i in range(1,len(s)):
if s[i] == s[i-1]:
print('no')
sys.exit()
print('yes') | 8 | 9 | 160 | 146 | s = eval(input())
for i in range(len(s)):
for j in range(i + 1, len(s)):
if s[i] == s[j]:
print("no")
exit()
print("yes")
| import sys
s = eval(input())
s = sorted(s)
for i in range(1, len(s)):
if s[i] == s[i - 1]:
print("no")
sys.exit()
print("yes")
| false | 11.111111 | [
"+import sys",
"+",
"-for i in range(len(s)):",
"- for j in range(i + 1, len(s)):",
"- if s[i] == s[j]:",
"- print(\"no\")",
"- exit()",
"+s = sorted(s)",
"+for i in range(1, len(s)):",
"+ if s[i] == s[i - 1]:",
"+ print(\"no\")",
"+ sys.exit()"... | false | 0.036534 | 0.03755 | 0.972931 | [
"s343554464",
"s414718528"
] |
u595375942 | p03494 | python | s541151386 | s366388656 | 167 | 25 | 38,640 | 3,060 | Accepted | Accepted | 85.03 | n=int(eval(input()))
l=list(map(int,input().split()))
ans=0
c=True
while c == True:
for i in range(n):
if l[i]%2==1:
c = False
if c == False:
break
else:
for i in range(n):
l[i]/=2
ans+=1
print(ans) | n=int(eval(input()))
l=list(map(int,input().split()))
Flag=1
cnt=0
for i in range(10**9):
for j in range(n):
if l[j]%2==0:
l[j]//=2
else:
Flag=0
if Flag==0: break
cnt+=1
print(cnt) | 16 | 13 | 276 | 239 | n = int(eval(input()))
l = list(map(int, input().split()))
ans = 0
c = True
while c == True:
for i in range(n):
if l[i] % 2 == 1:
c = False
if c == False:
break
else:
for i in range(n):
l[i] /= 2
ans += 1
print(ans)
| n = int(eval(input()))
l = list(map(int, input().split()))
Flag = 1
cnt = 0
for i in range(10**9):
for j in range(n):
if l[j] % 2 == 0:
l[j] //= 2
else:
Flag = 0
if Flag == 0:
break
cnt += 1
print(cnt)
| false | 18.75 | [
"-ans = 0",
"-c = True",
"-while c == True:",
"- for i in range(n):",
"- if l[i] % 2 == 1:",
"- c = False",
"- if c == False:",
"+Flag = 1",
"+cnt = 0",
"+for i in range(10**9):",
"+ for j in range(n):",
"+ if l[j] % 2 == 0:",
"+ l[j] //= 2",
"+... | false | 0.086839 | 0.061189 | 1.419182 | [
"s541151386",
"s366388656"
] |
u167931717 | p03220 | python | s267311915 | s470245484 | 211 | 164 | 38,256 | 38,384 | Accepted | Accepted | 22.27 | n = int(eval(input()))
ta = input().split()
t = int(ta[0])
a = int(ta[1])
hlist = [int(h) for h in input().split()]
minsub = 999999999999999999999999999999999999999
minidx = None
for i, h in enumerate(hlist):
temp = t - h * 0.006
if abs(a - temp) < minsub:
minsub = abs(a - temp)
minidx = i
print((minidx + 1))
| def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return list(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
n = intin()
t, a = intin()
hlist = intina()
minsub = 999999999999999999999999999999999999999
minidx = None
for i, h in enumerate(hlist):
temp = t - h * 0.006
if abs(a - temp) < minsub:
minsub = abs(a - temp)
minidx = i
print((minidx + 1))
| 17 | 28 | 347 | 562 | n = int(eval(input()))
ta = input().split()
t = int(ta[0])
a = int(ta[1])
hlist = [int(h) for h in input().split()]
minsub = 999999999999999999999999999999999999999
minidx = None
for i, h in enumerate(hlist):
temp = t - h * 0.006
if abs(a - temp) < minsub:
minsub = abs(a - temp)
minidx = i
print((minidx + 1))
| def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return list(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
n = intin()
t, a = intin()
hlist = intina()
minsub = 999999999999999999999999999999999999999
minidx = None
for i, h in enumerate(hlist):
temp = t - h * 0.006
if abs(a - temp) < minsub:
minsub = abs(a - temp)
minidx = i
print((minidx + 1))
| false | 39.285714 | [
"-n = int(eval(input()))",
"-ta = input().split()",
"-t = int(ta[0])",
"-a = int(ta[1])",
"-hlist = [int(h) for h in input().split()]",
"+def intin():",
"+ input_tuple = input().split()",
"+ if len(input_tuple) <= 1:",
"+ return int(input_tuple[0])",
"+ return list(map(int, input_t... | false | 0.119605 | 0.123487 | 0.968565 | [
"s267311915",
"s470245484"
] |
u905203728 | p02744 | python | s327248834 | s455144613 | 139 | 128 | 4,340 | 4,412 | Accepted | Accepted | 7.91 | def DFS(word,n):
if len(word)==N:
return print(word)
else:
for i in range(n+1):
DFS(word+chr(97+i),n+1 if i==n else n)
N=int(input())
DFS("",0)
| def DFS(word,N):
if len(word)==n:
return print(word)
else:
for i in range(N+1):
DFS(word+chr(97+i),N+1 if i==N else N)
n=int(input())
DFS("",0)
| 10 | 10 | 190 | 190 | def DFS(word, n):
if len(word) == N:
return print(word)
else:
for i in range(n + 1):
DFS(word + chr(97 + i), n + 1 if i == n else n)
N = int(input())
DFS("", 0)
| def DFS(word, N):
if len(word) == n:
return print(word)
else:
for i in range(N + 1):
DFS(word + chr(97 + i), N + 1 if i == N else N)
n = int(input())
DFS("", 0)
| false | 0 | [
"-def DFS(word, n):",
"- if len(word) == N:",
"+def DFS(word, N):",
"+ if len(word) == n:",
"- for i in range(n + 1):",
"- DFS(word + chr(97 + i), n + 1 if i == n else n)",
"+ for i in range(N + 1):",
"+ DFS(word + chr(97 + i), N + 1 if i == N else N)",
"-N ... | false | 0.046206 | 0.045843 | 1.007936 | [
"s327248834",
"s455144613"
] |
u225528554 | p03546 | python | s305871737 | s713132206 | 44 | 31 | 3,444 | 3,064 | Accepted | Accepted | 29.55 | if __name__=="__main__":
sum = 0
x,y = list(map(int,input().split()))
c = [list(map(int,input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j]>c[i][k]+c[k][j]:
c[i][j] = c[i][k]+c[k][j]
m = [list(map(int,input().split())) for n in range(int(x))]
for i in range(x):
for j in range(y):
if m[i][j]!=-1:
sum+=int(c[m[i][j]][1])
print(sum)
| if __name__=="__main__":
sum = 0
x,y = list(map(int,input().split()))
c = [list(map(int,input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j]>c[i][k]+c[k][j]:
c[i][j] = c[i][k]+c[k][j]
for i in range(x):
a = list(map(int,input().split()))
for j in a:
if j!=-1:
sum+=c[j][1]
print(sum)
| 19 | 19 | 525 | 480 | if __name__ == "__main__":
sum = 0
x, y = list(map(int, input().split()))
c = [list(map(int, input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j] > c[i][k] + c[k][j]:
c[i][j] = c[i][k] + c[k][j]
m = [list(map(int, input().split())) for n in range(int(x))]
for i in range(x):
for j in range(y):
if m[i][j] != -1:
sum += int(c[m[i][j]][1])
print(sum)
| if __name__ == "__main__":
sum = 0
x, y = list(map(int, input().split()))
c = [list(map(int, input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j] > c[i][k] + c[k][j]:
c[i][j] = c[i][k] + c[k][j]
for i in range(x):
a = list(map(int, input().split()))
for j in a:
if j != -1:
sum += c[j][1]
print(sum)
| false | 0 | [
"- m = [list(map(int, input().split())) for n in range(int(x))]",
"- for j in range(y):",
"- if m[i][j] != -1:",
"- sum += int(c[m[i][j]][1])",
"+ a = list(map(int, input().split()))",
"+ for j in a:",
"+ if j != -1:",
"+ sum ... | false | 0.179664 | 0.039939 | 4.498509 | [
"s305871737",
"s713132206"
] |
u488127128 | p02983 | python | s004545547 | s614632372 | 398 | 58 | 75,332 | 6,808 | Accepted | Accepted | 85.43 | def solve():
l,r = list(map(int, input().split()))
if r-l<2019:
arr = [i*j%2019 for i in range(l,r) for j in range(i+1,r+1)]
return min(arr)
else:
return 0
if __name__ == '__main__':
print((solve())) | def solve():
l,r = list(map(int, input().split()))
if r-l<2019:
arr = []
for i in range(l,r):
for j in range(i+1,r+1):
if i*j%2019 == 0:
return 0
arr.append(i*j%2019)
return min(arr)
else:
return 0
if __name__ == '__main__':
print((solve())) | 11 | 16 | 243 | 362 | def solve():
l, r = list(map(int, input().split()))
if r - l < 2019:
arr = [i * j % 2019 for i in range(l, r) for j in range(i + 1, r + 1)]
return min(arr)
else:
return 0
if __name__ == "__main__":
print((solve()))
| def solve():
l, r = list(map(int, input().split()))
if r - l < 2019:
arr = []
for i in range(l, r):
for j in range(i + 1, r + 1):
if i * j % 2019 == 0:
return 0
arr.append(i * j % 2019)
return min(arr)
else:
return 0
if __name__ == "__main__":
print((solve()))
| false | 31.25 | [
"- arr = [i * j % 2019 for i in range(l, r) for j in range(i + 1, r + 1)]",
"+ arr = []",
"+ for i in range(l, r):",
"+ for j in range(i + 1, r + 1):",
"+ if i * j % 2019 == 0:",
"+ return 0",
"+ arr.append(i * j % 2019)"
] | false | 0.075788 | 0.037205 | 2.037042 | [
"s004545547",
"s614632372"
] |
u624475441 | p03346 | python | s717501224 | s815527595 | 431 | 129 | 32,608 | 10,868 | Accepted | Accepted | 70.07 | N = int(eval(input()))
idx = {int(eval(input())): i for i in range(N)}
res = N - 1
cnt = 1
for x in range(2, N + 1):
if idx[x - 1] < idx[x]:
cnt += 1
else:
res = min(res, N - cnt)
cnt = 1
print((min(res, N - cnt))) | import sys
N = int(eval(input()))
dp = [0] * (N + 1)
for x in map(int, sys.stdin):
dp[x] = dp[x - 1] + 1
print((N - max(dp))) | 11 | 6 | 242 | 126 | N = int(eval(input()))
idx = {int(eval(input())): i for i in range(N)}
res = N - 1
cnt = 1
for x in range(2, N + 1):
if idx[x - 1] < idx[x]:
cnt += 1
else:
res = min(res, N - cnt)
cnt = 1
print((min(res, N - cnt)))
| import sys
N = int(eval(input()))
dp = [0] * (N + 1)
for x in map(int, sys.stdin):
dp[x] = dp[x - 1] + 1
print((N - max(dp)))
| false | 45.454545 | [
"+import sys",
"+",
"-idx = {int(eval(input())): i for i in range(N)}",
"-res = N - 1",
"-cnt = 1",
"-for x in range(2, N + 1):",
"- if idx[x - 1] < idx[x]:",
"- cnt += 1",
"- else:",
"- res = min(res, N - cnt)",
"- cnt = 1",
"-print((min(res, N - cnt)))",
"+dp = [... | false | 0.037388 | 0.087513 | 0.427224 | [
"s717501224",
"s815527595"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.